Re: [PATCH] clockevents: Prevent timer interrupt starvation

From: Peter Zijlstra

Date: Fri Apr 03 2026 - 17:05:11 EST


On Fri, Apr 03, 2026 at 06:17:15PM +0200, Thomas Gleixner wrote:

> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -1888,6 +1888,7 @@ void hrtimer_interrupt(struct clock_even
> BUG_ON(!cpu_base->hres_active);
> cpu_base->nr_events++;
> dev->next_event = KTIME_MAX;
> + dev->next_event_forced = 0;
>
> raw_spin_lock_irqsave(&cpu_base->lock, flags);
> entry_time = now = hrtimer_update_base(cpu_base);
> --- a/kernel/time/tick-common.c
> +++ b/kernel/time/tick-common.c
> @@ -110,6 +110,7 @@ void tick_handle_periodic(struct clock_e
> int cpu = smp_processor_id();
> ktime_t next = dev->next_event;
>
> + dev->next_event_forced = 0;
> tick_periodic(cpu);
>
> /*
> --- a/kernel/time/tick-sched.c
> +++ b/kernel/time/tick-sched.c
> @@ -1513,6 +1513,7 @@ static void tick_nohz_lowres_handler(str
> struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
>
> dev->next_event = KTIME_MAX;
> + dev->next_event_forced = 0;
>
> if (likely(tick_nohz_handler(&ts->sched_timer) == HRTIMER_RESTART))
> tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1);

Doesn't that want to be something like this instead?


---
virtual patch

@@
expression E;
struct clock_event_device *ptr;
@@

- if (E->event_handler)
- E->event_handler(E);
+ clockevent_handler(E);

@@
expression E;
struct clock_event_device *ptr;
@@

- E->event_handler(E);
+ clockevent_handler(E);

---
--- a/include/linux/clockchips.h
+++ b/include/linux/clockchips.h
@@ -159,6 +159,13 @@ static inline bool clockevent_state_ones
return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT_STOPPED;
}

+static inline void clockevent_handler(struct clock_event_device *dev)
+{
+ dev->next_event_forced = 0;
+ if (dev->event_handler)
+ dev->event_handler(dev);
+}
+
/*
* Calculate a multiplication factor for scaled math, which is used to convert
* nanoseconds based values to clock ticks: