Re: [PATCH v2] tracing/hwlat: Bind the sampler kthread instead of setting its affinity
From: Wenwu Hou
Date: Thu Nov 26 2026 - 04:17:26 EST
On Wed, Nov 25, 2026 at 05:24:34PM +0100, Frederic Weisbecker wrote:
> Le Wed, Nov 25, 2026 at 10:38:22AM -0500, Steven Rostedt a écrit :
> > On Wed, 25 Nov 2026 14:37:24 +0100
> > Frederic Weisbecker <frederic@xxxxxxxxxx> wrote:
> >
> > > > static int kthread_fn(void *data)
> > > > {
> > > > + unsigned long flags;
> > > > u64 interval;
> > > >
> > > > + /*
> > > > + * kthread_bind_mask() sets PF_NO_SETAFFINITY to keep the initial
> > > > + * affinity from being overridden by kthread_affine_node(). Clear it
> > > > + * now to allow userspace affinity changes and cgroup migration, but
> > > > + * keep per-CPU threads bound to their CPUs.
> > > > + */
> > > > + if (hwlat_data.thread_mode != MODE_PER_CPU) {
> > > > + raw_spin_lock_irqsave(¤t->pi_lock, flags);
> > > > + current->flags &= ~PF_NO_SETAFFINITY;
> > > > + raw_spin_unlock_irqrestore(¤t->pi_lock, flags);
> > >
> > > This is not pretty but moreover, is it a good idea to let the user override
> > > that affinity?
> >
> > No, but we used to. Perhaps we should make that not possible instead? :-/
>
> Right, the affinity should only be changed by the kernel if tracing_cpumask is
> written. Otherwise it doesn't seem to make sense to let the user play with the
> affinity.
I agree. Perhaps v1 is better.
> --
> Frederic Weisbecker
> SUSE Labs