Re: [PATCH v8 6/6] perf stat: Add no-affinity flag

From: Namhyung Kim

Date: Mon Feb 09 2026 - 20:18:13 EST


On Sat, Feb 07, 2026 at 07:54:05AM -0800, Ian Rogers wrote:
> On Sat, Feb 7, 2026 at 4:51 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
> >
> > On Fri, Feb 06, 2026 at 02:25:09PM -0800, Ian Rogers wrote:
> > > Add flag that disables affinity behavior. Using sched_setaffinity to
> > > place a perf thread on a CPU can avoid certain interprocessor
> > > interrupts but may introduce a delay due to the scheduling,
> > > particularly on loaded machines. Add a command line option to disable
> > > the behavior. This behavior is less present in other tools like `perf
> > > record`, as it uses a ring buffer and doesn't make repeated system
> > > calls.
> >
> > This is confusing:
> >
> > ⬢ [acme@toolbx perf-tools-next]$ perf stat -h affinity
> >
> > Usage: perf stat [<options>] [<command>]
> >
> > --affinity don't allow affinity optimizations aimed at reducing IPIs
> >
> > ⬢ [acme@toolbx perf-tools-next]$
> >
> > The way it is presented in the -h output it looks as if one has to use:
> >
> > perf stat --affinity
> >
> > To disable affinity setting, when used that way it looks as if the user
> > is asking for affinity to be used.
> >
> > We have things like:
> >
> > ⬢ [acme@toolbx perf-tools-next]$ grep -A2 OPT_.*no- tools/perf/builtin-record.c
> > OPT_BOOLEAN(0, "no-buffering", &record.opts.no_buffering,
> > "collect data without buffering"),
> > OPT_BOOLEAN('R', "raw-samples", &record.opts.raw_samples,
> > --
> > OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
> > &record.opts.no_inherit_set,
> > "child tasks do not inherit counters"),
> > --
> > OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "do not record bpf events"),
> > OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
> > "Fail if the specified frequency can't be used"),
> > --
> > OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples,
> > "don't sample"),
> > OPT_BOOLEAN_SET('N', "no-buildid-cache", &record.no_buildid_cache,
> > &record.no_buildid_cache_set,
> > "do not update the buildid cache"),
> > OPT_BOOLEAN_SET('B', "no-buildid", &record.no_buildid,
> > &record.no_buildid_set,
> > "do not collect buildids in perf.data"),
> > ⬢ [acme@toolbx perf-tools-next]$
> >
> > Probably this needs to be that way?
>
> So it was that way in the v4 patch set but Namhyung asked for it to be
> the other way around:
> https://lore.kernel.org/lkml/aRvcuMfbDRSBU87k@xxxxxxxxxx/
> The comment on the option didn't get changed and that's a mistake.
> Let me know what's preferred and I can send a patch.

Right, I still prefer positive option names so that "--no-" prefix can
be added.

Thanks,
Namhyung