Skip to content

Commit ffb7e01

Browse files
liupeng17KAGA-KOKO
authored andcommitted
tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer()
The ts->sched_timer initialization work of tick_nohz_switch_to_nohz() is almost the same as that of tick_setup_sched_timer(), so adjust the latter to get it reused by tick_nohz_switch_to_nohz(). This also makes the low resolution mode sched_timer benefit from the tick skew boot option. Signed-off-by: Peng Liu <liupeng17@lenovo.com> Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240225225508.11587-2-frederic@kernel.org
1 parent 56c2cb1 commit ffb7e01

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

kernel/time/hrtimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ static void hrtimer_switch_to_hres(void)
747747
base->hres_active = 1;
748748
hrtimer_resolution = HIGH_RES_NSEC;
749749

750-
tick_setup_sched_timer();
750+
tick_setup_sched_timer(NOHZ_MODE_HIGHRES);
751751
/* "Retrigger" the interrupt to get things going */
752752
retrigger_next_event(NULL);
753753
}

kernel/time/tick-sched.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,9 +1471,6 @@ static inline void tick_nohz_activate(struct tick_sched *ts, int mode)
14711471
*/
14721472
static void tick_nohz_switch_to_nohz(void)
14731473
{
1474-
struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
1475-
ktime_t next;
1476-
14771474
if (!tick_nohz_enabled)
14781475
return;
14791476

@@ -1482,16 +1479,9 @@ static void tick_nohz_switch_to_nohz(void)
14821479

14831480
/*
14841481
* Recycle the hrtimer in 'ts', so we can share the
1485-
* hrtimer_forward_now() function with the highres code.
1482+
* highres code.
14861483
*/
1487-
hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD);
1488-
/* Get the next period */
1489-
next = tick_init_jiffy_update();
1490-
1491-
hrtimer_set_expires(&ts->sched_timer, next);
1492-
hrtimer_forward_now(&ts->sched_timer, TICK_NSEC);
1493-
tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1);
1494-
tick_nohz_activate(ts, NOHZ_MODE_LOWRES);
1484+
tick_setup_sched_timer(NOHZ_MODE_LOWRES);
14951485
}
14961486

14971487
static inline void tick_nohz_irq_enter(void)
@@ -1570,7 +1560,11 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer)
15701560

15711561
return HRTIMER_RESTART;
15721562
}
1563+
#else
1564+
#define tick_nohz_highres_handler NULL
1565+
#endif /* CONFIG_HIGH_RES_TIMERS */
15731566

1567+
#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
15741568
static int sched_skew_tick;
15751569

15761570
static int __init skew_tick(char *str)
@@ -1583,15 +1577,17 @@ early_param("skew_tick", skew_tick);
15831577

15841578
/**
15851579
* tick_setup_sched_timer - setup the tick emulation timer
1580+
* @mode: tick_nohz_mode to setup for
15861581
*/
1587-
void tick_setup_sched_timer(void)
1582+
void tick_setup_sched_timer(int mode)
15881583
{
15891584
struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
1590-
ktime_t now = ktime_get();
15911585

15921586
/* Emulate tick processing via per-CPU hrtimers: */
15931587
hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD);
1594-
ts->sched_timer.function = tick_nohz_highres_handler;
1588+
1589+
if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES)
1590+
ts->sched_timer.function = tick_nohz_highres_handler;
15951591

15961592
/* Get the next period (per-CPU) */
15971593
hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update());
@@ -1604,13 +1600,14 @@ void tick_setup_sched_timer(void)
16041600
hrtimer_add_expires_ns(&ts->sched_timer, offset);
16051601
}
16061602

1607-
hrtimer_forward(&ts->sched_timer, now, TICK_NSEC);
1608-
hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD);
1609-
tick_nohz_activate(ts, NOHZ_MODE_HIGHRES);
1603+
hrtimer_forward_now(&ts->sched_timer, TICK_NSEC);
1604+
if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES)
1605+
hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD);
1606+
else
1607+
tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1);
1608+
tick_nohz_activate(ts, mode);
16101609
}
1611-
#endif /* HIGH_RES_TIMERS */
16121610

1613-
#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
16141611
void tick_cancel_sched_timer(int cpu)
16151612
{
16161613
struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
@@ -1632,7 +1629,7 @@ void tick_cancel_sched_timer(int cpu)
16321629
ts->idle_calls = idle_calls;
16331630
ts->idle_sleeps = idle_sleeps;
16341631
}
1635-
#endif
1632+
#endif /* CONFIG_NO_HZ_COMMON || CONFIG_HIGH_RES_TIMERS */
16361633

16371634
/*
16381635
* Async notification about clocksource changes

kernel/time/tick-sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct tick_sched {
102102

103103
extern struct tick_sched *tick_get_tick_sched(int cpu);
104104

105-
extern void tick_setup_sched_timer(void);
105+
extern void tick_setup_sched_timer(int mode);
106106
#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
107107
extern void tick_cancel_sched_timer(int cpu);
108108
#else

0 commit comments

Comments
 (0)