Re: [PATCH v2 1/4] tick/nohz: Re-evaluate the tick on return to user space

From: Marco Crivellari

Date: Thu Nov 12 2026 - 05:41:39 EST


On Wed, Nov 11, 2026 at 5:25 PM Frederic Weisbecker <frederic@xxxxxxxxxx> wrote:
> [...]
> > --- a/kernel/context_tracking.c
> > +++ b/kernel/context_tracking.c
> > @@ -24,6 +24,7 @@
> > #include <linux/export.h>
> > #include <linux/kprobes.h>
> > #include <trace/events/rcu.h>
> > +#include <linux/tick.h>
> >
> >
> > DEFINE_PER_CPU(struct context_tracking, context_tracking) = {
> > @@ -466,6 +467,13 @@ void noinstr __ct_user_enter(enum ctx_state state)
> > */
> > if (state == CT_STATE_USER) {
> > instrumentation_begin();
> > + /*
> > + * On nohz_full CPUs the tick may have been left running in the
> > + * kernel, e.g. kept by a tick dependency that is now gone.
> > + * Stop it now rather than let it interrupt userspace once
> > + * more before the next IRQ exit notices.
> > + */
> > + tick_nohz_user_enter();
>
> You can move that a little bit further, outside "state == CT_STATE_USER", right
> before rcu_irq_work_resched(). This will need a new pair of
> instrumentation_begin()/end().
>
> This way it also applies before switching to guest.
>
>
> > trace_user_enter(0);
> > vtime_user_enter(current);
> > instrumentation_end();
> > diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
> > index c6d86e4da8a9..645dba919386 100644
> > --- a/kernel/time/tick-sched.c
> > +++ b/kernel/time/tick-sched.c
> > @@ -1071,6 +1071,30 @@ static void tick_nohz_full_update_tick(struct tick_sched *ts)
> > __tick_nohz_full_update_tick(ts, ktime_get());
> > }
> >
> > +#ifdef CONFIG_NO_HZ_FULL
> > +void __tick_nohz_user_enter(void)
> > +{
> > + struct tick_sched *ts;
> > + int cpu;
> > +
> > + lockdep_assert_irqs_disabled();
> > +
> > + cpu = smp_processor_id();
> > + if (!tick_nohz_full_cpu(cpu))
> > + return;
> > +
> > + ts = this_cpu_ptr(&tick_cpu_sched);
> > + if (!tick_sched_flag_test(ts, TS_FLAG_NOHZ))
> > + return;
> > +
> > + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED))
> > + return;
> > +
> > + if (can_stop_full_tick(cpu, ts))
> > + tick_nohz_full_stop_tick(ts, cpu);
> > +}
> > +#endif
>
> Looks like this can move right below the definition of
> tick_nohz_full_stop_tick() to avoid more ifdef blocks.

Perfect, I will, thanks for your feedback!

--

Marco Crivellari

SUSE Labs