Skip to content

Commit 90f5df6

Browse files
richardcochranKAGA-KOKO
authored andcommitted
timers: Restructure internal locking
Move the locking out from __run_timers() to the call sites, so the protected section can be extended at the call site. Preparatory work for changing the NOHZ timer placement to a pull at expiry time model. No functional change. Signed-off-by: Richard Cochran (linutronix GmbH) <richardcochran@gmail.com> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lore.kernel.org/r/20240221090548.36600-15-anna-maria@linutronix.de
1 parent f73d925 commit 90f5df6

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

kernel/time/timer.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,11 +2283,7 @@ static inline void __run_timers(struct timer_base *base)
22832283
struct hlist_head heads[LVL_DEPTH];
22842284
int levels;
22852285

2286-
if (time_before(jiffies, base->next_expiry))
2287-
return;
2288-
2289-
timer_base_lock_expiry(base);
2290-
raw_spin_lock_irq(&base->lock);
2286+
lockdep_assert_held(&base->lock);
22912287

22922288
while (time_after_eq(jiffies, base->clk) &&
22932289
time_after_eq(jiffies, base->next_expiry)) {
@@ -2311,21 +2307,36 @@ static inline void __run_timers(struct timer_base *base)
23112307
while (levels--)
23122308
expire_timers(base, heads + levels);
23132309
}
2310+
}
2311+
2312+
static void __run_timer_base(struct timer_base *base)
2313+
{
2314+
if (time_before(jiffies, base->next_expiry))
2315+
return;
2316+
2317+
timer_base_lock_expiry(base);
2318+
raw_spin_lock_irq(&base->lock);
2319+
__run_timers(base);
23142320
raw_spin_unlock_irq(&base->lock);
23152321
timer_base_unlock_expiry(base);
23162322
}
23172323

2324+
static void run_timer_base(int index)
2325+
{
2326+
struct timer_base *base = this_cpu_ptr(&timer_bases[index]);
2327+
2328+
__run_timer_base(base);
2329+
}
2330+
23182331
/*
23192332
* This function runs timers and the timer-tq in bottom half context.
23202333
*/
23212334
static __latent_entropy void run_timer_softirq(struct softirq_action *h)
23222335
{
2323-
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_LOCAL]);
2324-
2325-
__run_timers(base);
2336+
run_timer_base(BASE_LOCAL);
23262337
if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) {
2327-
__run_timers(this_cpu_ptr(&timer_bases[BASE_GLOBAL]));
2328-
__run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
2338+
run_timer_base(BASE_GLOBAL);
2339+
run_timer_base(BASE_DEF);
23292340
}
23302341
}
23312342

0 commit comments

Comments
 (0)