Skip to contentSkip to conversation

tick/nohz: Requeue kicks flushed outside hardirq context

PATCH In review Peng Wang 3 participants 7 messages Oct 17 – Oct 25

Subsystems (2)
lore
Share & tools
lore

Peng Wang

author
#0 lore raw

PATCH 1/1 tick/nohz: Requeue kicks flushed outside hardirq context

A remote nohz kick can be flushed from task context after idle exit has checked tick dependencies. If polling suppressed the IPI, the empty callback is consumed without an IRQ exit to reevaluate the tick. A newly set dependency can then leave the non-idle tick stopped until another interrupt arrives.

Requeue the work locally when it runs outside hardirq context on an online CPU. This raises the IRQ needed for the existing tick reevaluation path. Skip offline CPUs whose pending work is being drained during teardown.

Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")
---
 kernel/time/tick-sched.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +6 -1
index 6c3fea386713..87e2a7a87526 100644
@@ -402,7 +402,12 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)
 
 static void nohz_full_kick_func(struct irq_work *work)
 {
-	/* Empty, the tick restart happens on tick_nohz_irq_exit() */
+	/*
+	 * Remote irq_work may be flushed from task context. Force an IRQ
+	 * exit to reevaluate the tick unless this CPU is going offline.
+	 */
+	if (!in_hardirq() && cpu_online(smp_processor_id()))
+		irq_work_queue(work);
 }
 
 static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =

base-commit: 70dd4ee72eb2d5793c62e71c14e3aba78e5a4e56

Signature · 1 line
2.47.0
#1 lore raw
Quoted 25 lines · Peng Wang

A remote nohz kick can be flushed from task context after idle exit has checked tick dependencies. If polling suppressed the IPI, the empty callback is consumed without an IRQ exit to reevaluate the tick. A newly set dependency can then leave the non-idle tick stopped until another interrupt arrives.

Requeue the work locally when it runs outside hardirq context on an online CPU. This raises the IRQ needed for the existing tick reevaluation path. Skip offline CPUs whose pending work is being drained during teardown.

Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")
---
 kernel/time/tick-sched.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +0 -0
index 6c3fea386713..87e2a7a87526 100644

kernel/time/tick-sched.c static bool can_stop_full_tick(int cpu, struct tick_sched *ts) · line 410

Quoted 10 lines
kernel/time/tick-sched.c +6 -1
@@ -402,7 +402,12 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)
 
 static void nohz_full_kick_func(struct irq_work *work)
 {
-	/* Empty, the tick restart happens on tick_nohz_irq_exit() */
+	/*
+	 * Remote irq_work may be flushed from task context. Force an IRQ
+	 * exit to reevaluate the tick unless this CPU is going offline.
+	 */
+	if (!in_hardirq() && cpu_online(smp_processor_id()))
+		irq_work_queue(work);

Good catch but instead of requeuing, why not restarting the tick directly from here instead of from IRQ exit?

Thanks.

Quoted 8 lines
kernel/time/tick-sched.c +0 -0
 }
 
 static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =

base-commit: 70dd4ee72eb2d5793c62e71c14e3aba78e5a4e56

Signature · 1 line
2.47.0
Signature · 2 lines
Frederic Weisbecker
SUSE Labs
author
#2 lore raw

PATCH v2 1/1 tick/nohz: Reevaluate the tick for kicks flushed outside hardirq

The nohz full kick relies on IRQ exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an IRQ exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt.

Reevaluate the tick directly from the callback outside hardirq context. Keep the existing IRQ-exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ.

Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")

---
Changes in v2:
- Reevaluate the tick directly outside hardirq instead of requeueing, as suggested by Frederic.
- Use the full update for both dependencies and timer deadlines. Keep IRQ-exit handling for hardirq callbacks and the existing NOHZ guard for CPU teardown.

v1: https://lore.kernel.org/all/43668cf88d976084e2865ec07dea82b64ad402ba.1792240863.git.peng_wang@linux.alibaba.com/

 kernel/time/tick-sched.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +5 -1
index 6c3fea386713..ece2c21cec84 100644
@@ -400,9 +400,13 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)
 	return true;
 }
 
+static void tick_nohz_full_update_tick(struct tick_sched *ts);
+
 static void nohz_full_kick_func(struct irq_work *work)
 {
-	/* Empty, the tick restart happens on tick_nohz_irq_exit() */
+	/* Task-context flushes may not be followed by an IRQ exit. */
+	if (!in_hardirq())
+		tick_nohz_full_update_tick(this_cpu_ptr(&tick_cpu_sched));
 }
 
 static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =

base-commit: 70dd4ee72eb2d5793c62e71c14e3aba78e5a4e56

Signature · 1 line
2.47.3
#3 lore raw

Re: [PATCH v2] tick/nohz: Reevaluate the tick for kicks flushed outside hardirq

Quoted 36 lines · Peng Wang

The nohz full kick relies on IRQ exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an IRQ exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt.

Reevaluate the tick directly from the callback outside hardirq context. Keep the existing IRQ-exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ.

Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")

---
Changes in v2:
- Reevaluate the tick directly outside hardirq instead of requeueing, as suggested by Frederic.
- Use the full update for both dependencies and timer deadlines. Keep IRQ-exit handling for hardirq callbacks and the existing NOHZ guard for CPU teardown.

v1: https://lore.kernel.org/all/43668cf88d976084e2865ec07dea82b64ad402ba.1792240863.git.peng_wang@linux.alibaba.com/

 kernel/time/tick-sched.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +0 -0
index 6c3fea386713..ece2c21cec84 100644
@@ -400,9 +400,13 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)
 	return true;

kernel/time/tick-sched.c static bool can_stop_full_tick(int cpu, struct tick_sched *ts) · line 409

Quoted 10 lines
kernel/time/tick-sched.c +5 -1
 }
 
+static void tick_nohz_full_update_tick(struct tick_sched *ts);
+
 static void nohz_full_kick_func(struct irq_work *work)
 {
-	/* Empty, the tick restart happens on tick_nohz_irq_exit() */
+	/* Task-context flushes may not be followed by an IRQ exit. */
+	if (!in_hardirq())
+		tick_nohz_full_update_tick(this_cpu_ptr(&tick_cpu_sched));

Just in case, even though it shouldn't happen, just have the following sanity checks to return early:

if (WARN_ON_ONCE(!tick_nohz_full_cpu(smp_processor_id())))

    return;
if (!in_hardirq()) {
    if (WARN_ON_ONCE(tick_sched_flag_test(ts, TS_FLAG_INIDLE)))
       return;
    tick_nohz_full_update_tick(this_cpu_ptr(&tick_cpu_sched));
}

Thanks!

Quoted 8 lines
kernel/time/tick-sched.c +0 -0
 }
 
 static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =

base-commit: 70dd4ee72eb2d5793c62e71c14e3aba78e5a4e56

Signature · 1 line
2.47.3
Signature · 2 lines
Frederic Weisbecker
SUSE Labs
author
#4 lore raw

PATCH v3 1/1 tick/nohz: Reevaluate the tick for kicks flushed outside hardirq

The nohz full kick relies on IRQ exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an IRQ exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt.

Reevaluate the tick directly from the callback outside hardirq context. Keep the existing IRQ-exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ.

Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")

---
Changes in v3:
- Add WARN_ON_ONCE() checks for a non-nohz_full CPU and for a task-context callback still marked idle, as requested by Frederic.

v2: https://lore.kernel.org/all/[email protected]/

 kernel/time/tick-sched.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +13 -1
index 6c3fea386713..baa3ac9b48f8 100644
@@ -400,9 +400,21 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)
 	return true;
 }
 
+static void tick_nohz_full_update_tick(struct tick_sched *ts);
+
 static void nohz_full_kick_func(struct irq_work *work)
 {
-	/* Empty, the tick restart happens on tick_nohz_irq_exit() */
+	struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
+
+	if (WARN_ON_ONCE(!tick_nohz_full_cpu(smp_processor_id())))
+		return;
+
+	/* Task-context flushes may not be followed by an IRQ exit. */
+	if (!in_hardirq()) {
+		if (WARN_ON_ONCE(tick_sched_flag_test(ts, TS_FLAG_INIDLE)))
+			return;
+		tick_nohz_full_update_tick(ts);
+	}
 }
 
 static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =

base-commit: 70dd4ee72eb2d5793c62e71c14e3aba78e5a4e56

Signature · 1 line
2.47.3
maintainer Reviewed-by on v3 1/1
#5 lore raw

Re: [PATCH v3] tick/nohz: Reevaluate the tick for kicks flushed outside hardirq

Quoted 11 lines · Peng Wang

The nohz full kick relies on IRQ exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an IRQ exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt.

Reevaluate the tick directly from the callback outside hardirq context. Keep the existing IRQ-exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ.

Quoted 6 lines
Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")

Thanks a lot!

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
merge bot Applied
#6 lore raw

[tip: timers/urgent] tick/nohz: Reevaluate the tick for kicks flushed outside hardirq

In reply to Peng Wang
The following commit has been merged into the timers/urgent branch of tip:

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     e389ae428847a2e6a3b698b5967df68ccf90361c
Gitweb:        https://git.kernel.org/tip/e389ae428847a2e6a3b698b5967df68ccf90361c
Author:        Peng Wang <[email protected]>
AuthorDate:    Fri, 23 Oct 2026 22:51:00 +08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 25 Oct 2026 22:43:19 +01:00

tick/nohz: Reevaluate the tick for kicks flushed outside hardirq

The nohz full kick relies on interrupt exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an interrupt exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt.

Reevaluate the tick directly from the callback outside hardirq context. Keep the existing interrupt exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ.

Fixes 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue")
Fixes a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit")
---
 kernel/time/tick-sched.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +13 -1
index 6c3fea3..baa3ac9 100644
@@ -400,9 +400,21 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)
 	return true;
 }
 
+static void tick_nohz_full_update_tick(struct tick_sched *ts);
+
 static void nohz_full_kick_func(struct irq_work *work)
 {
-	/* Empty, the tick restart happens on tick_nohz_irq_exit() */
+	struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
+
+	if (WARN_ON_ONCE(!tick_nohz_full_cpu(smp_processor_id())))
+		return;
+
+	/* Task-context flushes may not be followed by an IRQ exit. */
+	if (!in_hardirq()) {
+		if (WARN_ON_ONCE(tick_sched_flag_test(ts, TS_FLAG_INIDLE)))
+			return;
+		tick_nohz_full_update_tick(ts);
+	}
 }
 
 static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =