Skip to content

Commit a761a67

Browse files
committed
timekeeping: Distangle resume and clock-was-set events
Resuming timekeeping is a clock-was-set event and uses the clock-was-set notification mechanism. This is in the way of making the clock-was-set update for hrtimers selective so unnecessary IPIs are avoided when a CPU base does not have timers queued which are affected by the clock setting. Distangle it by invoking hrtimer_resume() on each unfreezing CPU and invoke the new timerfd_resume() function from timekeeping_resume() which is the only place where this is needed. Rename hrtimer_resume() to hrtimer_resume_local() to reflect the change. With this the clock_was_set*() functions are not longer required to IPI all CPUs unconditionally and can get some smarts to avoid them. Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 66f7b0c commit a761a67

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

include/linux/hrtimer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ extern void timerfd_resume(void);
354354
static inline void timerfd_clock_was_set(void) { }
355355
static inline void timerfd_resume(void) { }
356356
#endif
357-
extern void hrtimers_resume(void);
358357

359358
DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
360359

kernel/time/hrtimer.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,27 +900,24 @@ static void clock_was_set_work(struct work_struct *work)
900900
static DECLARE_WORK(hrtimer_work, clock_was_set_work);
901901

902902
/*
903-
* Called from timekeeping and resume code to reprogram the hrtimer
904-
* interrupt device on all cpus and to notify timerfd.
903+
* Called from timekeeping code to reprogram the hrtimer interrupt device
904+
* on all cpus and to notify timerfd.
905905
*/
906906
void clock_was_set_delayed(void)
907907
{
908908
schedule_work(&hrtimer_work);
909909
}
910910

911911
/*
912-
* During resume we might have to reprogram the high resolution timer
913-
* interrupt on all online CPUs. However, all other CPUs will be
914-
* stopped with IRQs interrupts disabled so the clock_was_set() call
915-
* must be deferred.
912+
* Called during resume either directly from via timekeeping_resume()
913+
* or in the case of s2idle from tick_unfreeze() to ensure that the
914+
* hrtimers are up to date.
916915
*/
917-
void hrtimers_resume(void)
916+
void hrtimers_resume_local(void)
918917
{
919918
lockdep_assert_irqs_disabled();
920919
/* Retrigger on the local CPU */
921920
retrigger_next_event(NULL);
922-
/* And schedule a retrigger for all others */
923-
clock_was_set_delayed();
924921
}
925922

926923
/*

kernel/time/tick-common.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ void tick_resume_local(void)
470470
else
471471
tick_resume_oneshot();
472472
}
473+
474+
/*
475+
* Ensure that hrtimers are up to date and the clockevents device
476+
* is reprogrammed correctly when high resolution timers are
477+
* enabled.
478+
*/
479+
hrtimers_resume_local();
473480
}
474481

475482
/**

kernel/time/tick-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,5 @@ void timer_clear_idle(void);
168168

169169
void clock_was_set(void);
170170
void clock_was_set_delayed(void);
171+
172+
void hrtimers_resume_local(void);

kernel/time/timekeeping.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,8 +1810,10 @@ void timekeeping_resume(void)
18101810

18111811
touch_softlockup_watchdog();
18121812

1813+
/* Resume the clockevent device(s) and hrtimers */
18131814
tick_resume();
1814-
hrtimers_resume();
1815+
/* Notify timerfd as resume is equivalent to clock_was_set() */
1816+
timerfd_resume();
18151817
}
18161818

18171819
int timekeeping_suspend(void)

0 commit comments

Comments
 (0)