tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer()
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/2 tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer()
From: Peng Liu <[email protected]>
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().
---
Changes in v2:
- Fix build warning: Function parameter or member 'mode' not described in 'tick_setup_sched_timer'
- Fix build error: use of undeclared identifier 'tick_nohz_highres_handler'
- Fix build error: use of undeclared identifier 'sched_skew_tick'
--- kernel/time/hrtimer.c | 2 +- kernel/time/tick-sched.c | 37 ++++++++++++++++++------------------- kernel/time/tick-sched.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-)
kernel/time/hrtimer.c +1 -1
@@ -746,7 +746,7 @@ static void hrtimer_switch_to_hres(void) base->hres_active =1 ; hrtimer_resolution =HIGH_RES_NSEC ; -tick_setup_sched_timer (); +tick_setup_sched_timer (NOHZ_MODE_HIGHRES );/* "Retrigger" the interrupt to get things going */ retrigger_next_event (NULL ); }
kernel/time/tick-sched.c +18 -19
@@ -1430,9 +1430,6 @@ static inline void tick_nohz_activate(struct tick_sched *ts, int mode)*/ static void tick_nohz_switch_to_nohz (void ) { -struct tick_sched *ts =this_cpu_ptr (&tick_cpu_sched); -ktime_t next; -if (!tick_nohz_enabled)return ;
@@ -1441,16 +1438,9 @@ static void tick_nohz_switch_to_nohz(void)/* * Recycle the hrtimer in 'ts', so we can share the -* hrtimer_forward_now() function with the highres code. +* highres code. */ -hrtimer_init (&ts->sched_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS_HARD ); -/* Get the next period */ - next =tick_init_jiffy_update (); - -hrtimer_set_expires (&ts->sched_timer, next); -hrtimer_forward_now (&ts->sched_timer,TICK_NSEC ); -tick_program_event (hrtimer_get_expires (&ts->sched_timer),1 ); -tick_nohz_activate (ts,NOHZ_MODE_LOWRES ); +tick_setup_sched_timer (NOHZ_MODE_LOWRES ); }static inline void tick_nohz_irq_enter (void )
@@ -1529,7 +1519,9 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) return HRTIMER_RESTART; } +#endif /* HIGH_RES_TIMERS */ +#if definedCONFIG_NO_HZ_COMMON || definedCONFIG_HIGH_RES_TIMERS static int sched_skew_tick;static int __init skew_tick (char *str)
@@ -1542,15 +1534,19 @@ early_param("skew_tick", skew_tick);/** * tick_setup_sched_timer - setup the tick emulation timer +* @mode: tick_nohz_mode to setup for */ -void tick_setup_sched_timer (void ) +void tick_setup_sched_timer (int mode) {struct tick_sched *ts =this_cpu_ptr (&tick_cpu_sched);ktime_t now =ktime_get ();/* Emulate tick processing via per-CPU hrtimers: */ hrtimer_init (&ts->sched_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS_HARD ); - ts->sched_timer.function = tick_nohz_highres_handler; +#ifdef CONFIG_HIGH_RES_TIMERS +if (mode ==NOHZ_MODE_HIGHRES ) + ts->sched_timer.function = tick_nohz_highres_handler; +#endif /* Get the next period (per-CPU) */ hrtimer_set_expires (&ts->sched_timer,tick_init_jiffy_update ());
@@ -1564,12 +1560,15 @@ void tick_setup_sched_timer(void) }hrtimer_forward (&ts->sched_timer, now,TICK_NSEC ); -hrtimer_start_expires (&ts->sched_timer,HRTIMER_MODE_ABS_PINNED_HARD ); -tick_nohz_activate (ts,NOHZ_MODE_HIGHRES ); +#ifdef CONFIG_HIGH_RES_TIMERS +if (mode ==NOHZ_MODE_HIGHRES ) +hrtimer_start_expires (&ts->sched_timer,HRTIMER_MODE_ABS_PINNED_HARD ); + else +#endif +tick_program_event (hrtimer_get_expires (&ts->sched_timer),1 ); +tick_nohz_activate (ts, mode); } -#endif /* HIGH_RES_TIMERS */ -#if definedCONFIG_NO_HZ_COMMON || definedCONFIG_HIGH_RES_TIMERS void tick_cancel_sched_timer (int cpu) {struct tick_sched *ts = &per_cpu (tick_cpu_sched, cpu);
@@ -1581,7 +1580,7 @@ void tick_cancel_sched_timer(int cpu) memset(ts, 0, sizeof(*ts)); } -#endif +#endif /* CONFIG_NO_HZ_COMMON || CONFIG_HIGH_RES_TIMERS */ /* * Async notification about clocksource changes
kernel/time/tick-sched.h +1 -1
@@ -102,7 +102,7 @@ struct tick_sched {extern struct tick_sched *tick_get_tick_sched (int cpu); -extern void tick_setup_sched_timer (void ); +extern void tick_setup_sched_timer (int mode);#if definedCONFIG_NO_HZ_COMMON || definedCONFIG_HIGH_RES_TIMERS extern void tick_cancel_sched_timer (int cpu);#else
Signature · 1 line
2.34.1
Frederic Weisbecker
maintainerkernel/time/tick-sched.c static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) · line 1524
Quoted 7 lines · Peng Liu
kernel/time/tick-sched.c +2
-0@@ -1529,7 +1519,9 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) return HRTIMER_RESTART; } +#endif /* HIGH_RES_TIMERS */ +#if definedCONFIG_NO_HZ_COMMON || definedCONFIG_HIGH_RES_TIMERS
tick-sched.c is only ever built if CONFIG_TICK_ONESHOT=y and CONFIG_TICK_ONESHOT is basically (CONFIG_NO_HZ_COMMON || CONFIG_HIGH_RES_TIMERS)
So probably the above is not needed and if you like you can even send a subsequent patch removing such ifdefs within this file :-)
Quoted 12 lines
kernel/time/tick-sched.c +2
-1static int sched_skew_tick;static int __init skew_tick (char *str)@@ -1542,15 +1534,19 @@ early_param("skew_tick", skew_tick);/** * tick_setup_sched_timer - setup the tick emulation timer +* @mode: tick_nohz_mode to setup for */ -void tick_setup_sched_timer (void ) +void tick_setup_sched_timer (int mode) {
kernel/time/tick-sched.c early_param("skew_tick", skew_tick); · line 1549
Quoted 10 lines
kernel/time/tick-sched.c +4
-1struct tick_sched *ts =this_cpu_ptr (&tick_cpu_sched);ktime_t now =ktime_get ();/* Emulate tick processing via per-CPU hrtimers: */ hrtimer_init (&ts->sched_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS_HARD ); - ts->sched_timer.function = tick_nohz_highres_handler; +#ifdef CONFIG_HIGH_RES_TIMERS +if (mode ==NOHZ_MODE_HIGHRES ) + ts->sched_timer.function = tick_nohz_highres_handler; +#endif
That ifdef could simply be removed.
kernel/time/tick-sched.c void tick_setup_sched_timer(void) · line 1560
Quoted 5 lines
kernel/time/tick-sched.c +0
-0/* Get the next period (per-CPU) */ hrtimer_set_expires (&ts->sched_timer,tick_init_jiffy_update ());@@ -1564,12 +1560,15 @@ void tick_setup_sched_timer(void) }
That invisible part above is the skew_tick thing, which can probably work on low-res mode so why not but please tell about that in the changelog.
kernel/time/tick-sched.c void tick_setup_sched_timer(void) · line 1562
Quoted 2 lines
kernel/time/tick-sched.c +0
-0hrtimer_forward (&ts->sched_timer, now,TICK_NSEC );
Looks like this can be hrtimer_forward_now() and you can remove the now.
kernel/time/tick-sched.c void tick_setup_sched_timer(void) · line 1567
Quoted 7 lines
kernel/time/tick-sched.c +5
-2-hrtimer_start_expires (&ts->sched_timer,HRTIMER_MODE_ABS_PINNED_HARD ); -tick_nohz_activate (ts,NOHZ_MODE_HIGHRES ); +#ifdef CONFIG_HIGH_RES_TIMERS +if (mode ==NOHZ_MODE_HIGHRES ) +hrtimer_start_expires (&ts->sched_timer,HRTIMER_MODE_ABS_PINNED_HARD ); + else +#endif
And probably that ifdef could simply be turned toIS_ENABLED(CONFIG_HIGH_RES_TIMERS).
Thanks!
Quoted 60 lines · Frederic Weisbecker
kernel/time/tick-sched.c static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) · line 1524
Quoted 7 lines · Peng Liu
kernel/time/tick-sched.c +2
-0@@ -1529,7 +1519,9 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) return HRTIMER_RESTART; } +#endif /* HIGH_RES_TIMERS */ +#if definedCONFIG_NO_HZ_COMMON || definedCONFIG_HIGH_RES_TIMERS
tick-sched.cis only ever built ifCONFIG_TICK_ONESHOT=yandCONFIG_TICK_ONESHOTis basically (CONFIG_NO_HZ_COMMON||CONFIG_HIGH_RES_TIMERS)So probably the above is not needed and if you like you can even send a subsequent patch removing such ifdefs within this file :-)
Quoted 12 lines
kernel/time/tick-sched.c +2
-1static int sched_skew_tick;static int __init skew_tick (char *str)@@ -1542,15 +1534,19 @@ early_param("skew_tick", skew_tick);/** * tick_setup_sched_timer - setup the tick emulation timer +* @mode: tick_nohz_mode to setup for */ -void tick_setup_sched_timer (void ) +void tick_setup_sched_timer (int mode) {kernel/time/tick-sched.c early_param("skew_tick", skew_tick); · line 1549
Quoted 10 lines
kernel/time/tick-sched.c +4
-1struct tick_sched *ts =this_cpu_ptr (&tick_cpu_sched);ktime_t now =ktime_get ();/* Emulate tick processing via per-CPU hrtimers: */ hrtimer_init (&ts->sched_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS_HARD ); - ts->sched_timer.function = tick_nohz_highres_handler; +#ifdef CONFIG_HIGH_RES_TIMERS +if (mode ==NOHZ_MODE_HIGHRES ) + ts->sched_timer.function = tick_nohz_highres_handler; +#endif That ifdef could simply be removed.
kernel/time/tick-sched.c void tick_setup_sched_timer(void) · line 1560
Quoted 5 lines
kernel/time/tick-sched.c +0
-0/* Get the next period (per-CPU) */ hrtimer_set_expires (&ts->sched_timer,tick_init_jiffy_update ());@@ -1564,12 +1560,15 @@ void tick_setup_sched_timer(void) }That invisible part above is the
skew_tickthing, which can probably work on low-res mode so why not but please tell about that in the changelog.kernel/time/tick-sched.c void tick_setup_sched_timer(void) · line 1562
Quoted 2 lines
kernel/time/tick-sched.c +0
-0hrtimer_forward (&ts->sched_timer, now,TICK_NSEC );Looks like this can be
hrtimer_forward_now()and you can remove the now.kernel/time/tick-sched.c void tick_setup_sched_timer(void) · line 1567
Quoted 7 lines
kernel/time/tick-sched.c +5
-2-hrtimer_start_expires (&ts->sched_timer,HRTIMER_MODE_ABS_PINNED_HARD ); -tick_nohz_activate (ts,NOHZ_MODE_HIGHRES ); +#ifdef CONFIG_HIGH_RES_TIMERS +if (mode ==NOHZ_MODE_HIGHRES ) +hrtimer_start_expires (&ts->sched_timer,HRTIMER_MODE_ABS_PINNED_HARD ); + else +#endif And probably that ifdef could simply be turned to
IS_ENABLED(CONFIG_HIGH_RES_TIMERS).
Quoted 1 line
Thanks!
Thanks for comments. I will update my patches, and also try removing (CONFIG_NO_HZ_COMMON || CONFIG_HIGH_RES_TIMERS) in another patch.
Regards,
Peng