tick: A few more cleanups
Subsystems (2)
Ingo,
Please pull the timers/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/core
HEAD: 8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1
----
Nothing very exiting, just a bunch of non-critical cleanups for the next merge window:
1) Make the IRQ tick APIs naming more symetric
2) Optimize a bit jiffies_lock code coverage
3) Whitespace fixes from Alex Shi
4) Fix overflow in scheduler tick max deferment calculation. Given the current 1 second max limitation, this bug shouldn't happen in mainline. It's rather to prepare for making this value tunable. Or simply in case we change the current constant.
Thanks,
Frederic
---
Frederic Weisbecker (2):
tick: Rename tick_check_idle() to tick_irq_enter()
nohz: Get timekeeping max deferment outside jiffies_lock
Alex Shi (1):
nohz_full: fix code style issue of tick_nohz_full_stop_tick
Kevin Hilman (1):
sched/nohz: Fix overflow error in scheduler_tick_max_deferment()
include/linux/jiffies.h | 6 ++++++ include/linux/tick.h | 6 +++--- kernel/sched/core.c | 2 +- kernel/softirq.c | 2 +- kernel/time/tick-sched.c | 27 ++++++++++++++------------- 5 files changed, 25 insertions(+), 18 deletions(-)
PATCH 1/4 tick: Rename tick_check_idle() to tick_irq_enter()
This makes the code more symetric against the existing tick functions called on irq exit: tick_irq_exit() and tick_nohz_irq_exit().
These function are also symetric as they mirror each other's action:
we start to account idle time on irq exit and we stop this accounting on irq entry. Also the tick is stopped on irq exit and timekeeping catches up with the tickless time elapsed until we reach irq entry.
This rename was suggested by Peter Zijlstra a long while ago but it got forgotten in the mass.
--- include/linux/tick.h | 6 +++--- kernel/softirq.c | 2 +- kernel/time/tick-sched.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-)
include/linux/tick.h +3 -3
@@ -104,7 +104,7 @@ extern struct cpumask *tick_get_broadcast_oneshot_mask(void);extern void tick_clock_notify (void );extern int tick_check_oneshot_change (int allow_nohz);extern struct tick_sched *tick_get_tick_sched (int cpu); -extern void tick_check_idle (void ); +extern void tick_irq_enter (void );extern int tick_oneshot_mode_active (void );# ifndef arch_needs_cpu# define arch_needs_cpu (cpu) (0)
@@ -112,7 +112,7 @@ extern int tick_oneshot_mode_active(void);# else static inline void tick_clock_notify (void ) { }static inline int tick_check_oneshot_change (int allow_nohz) {return 0 ; } -static inline void tick_check_idle (void ) { } +static inline void tick_irq_enter (void ) { }static inline int tick_oneshot_mode_active (void ) {return 0 ; }# endif
@@ -121,7 +121,7 @@ static inline void tick_init(void) { }static inline void tick_cancel_sched_timer (int cpu) { }static inline void tick_clock_notify (void ) { }static inline int tick_check_oneshot_change (int allow_nohz) {return 0 ; } -static inline void tick_check_idle (void ) { } +static inline void tick_irq_enter (void ) { }static inline int tick_oneshot_mode_active (void ) {return 0 ; }#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
kernel/softirq.c +1 -1
@@ -318,7 +318,7 @@ void irq_enter(void)* here, as softirq will be serviced on return from interrupt. */ local_bh_disable (); -tick_check_idle (); +tick_irq_enter ();_local_bh_enable (); }
kernel/time/tick-sched.c +4 -4
@@ -1023,7 +1023,7 @@ static void tick_nohz_kick_tick(struct tick_sched *ts, ktime_t now)#endif } -static inline void tick_check_nohz_this_cpu (void ) +static inline void tick_nohz_irq_enter (void ) {struct tick_sched *ts = &__get_cpu_var (tick_cpu_sched);ktime_t now;
@@ -1042,17 +1042,17 @@ static inline void tick_check_nohz_this_cpu(void)#else static inline void tick_nohz_switch_to_nohz (void ) { } -static inline void tick_check_nohz_this_cpu (void ) { } +static inline void tick_nohz_irq_enter (void ) { }#endif /* CONFIG_NO_HZ_COMMON */ /* * Called from irq_enter to notify about the possible interruption of idle() */ -void tick_check_idle (void ) +void tick_irq_enter (void ) {tick_check_oneshot_broadcast_this_cpu (); -tick_check_nohz_this_cpu (); +tick_nohz_irq_enter (); }/*
Signature · 1 line
1.8.3.1
PATCH 2/4 nohz: Get timekeeping max deferment outside jiffies_lock
In reply to Frederic WeisbeckerWe don't need to fetch the timekeeping max deferment under the jiffies_lock seqlock.
If the clocksource is updated concurrently while we stop the tick, stop machine is called and the tick will be reevaluated again along with uptodate jiffies and its related values.
--- kernel/time/tick-sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +2 -1
@@ -533,12 +533,13 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts,struct clock_event_device *dev =__get_cpu_var (tick_cpu_device).evtdev;u64 time_delta; + time_delta =timekeeping_max_deferment (); +/* Read jiffies and the time when jiffies were updated last */ do { seq =read_seqbegin (&jiffies_lock); last_update = last_jiffies_update; last_jiffies = jiffies; - time_delta =timekeeping_max_deferment (); }while (read_seqretry (&jiffies_lock, seq)); if (rcu_needs_cpu(cpu, &rcu_delta_jiffies) ||
Signature · 1 line
1.8.3.1
PATCH 3/4 nohz_full: fix code style issue of tick_nohz_full_stop_tick
In reply to Frederic WeisbeckerFrom: Alex Shi <[email protected]>
Code usually starts with 'tab' instead of 7 'space' in kernel
--- kernel/time/tick-sched.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
kernel/time/tick-sched.c +8 -8
@@ -679,18 +679,18 @@ out:static void tick_nohz_full_stop_tick (struct tick_sched *ts) {#ifdef CONFIG_NO_HZ_FULL -int cpu =smp_processor_id (); +int cpu =smp_processor_id (); -if (!tick_nohz_full_cpu (cpu) ||is_idle_task (current)) -return ; +if (!tick_nohz_full_cpu (cpu) ||is_idle_task (current)) +return ; -if (!ts->tick_stopped && ts->nohz_mode ==NOHZ_MODE_INACTIVE ) -return ; +if (!ts->tick_stopped && ts->nohz_mode ==NOHZ_MODE_INACTIVE ) +return ; -if (!can_stop_full_tick ()) -return ; +if (!can_stop_full_tick ()) +return ; -tick_nohz_stop_sched_tick (ts,ktime_get (), cpu); +tick_nohz_stop_sched_tick (ts,ktime_get (), cpu);#endif }
Signature · 1 line
1.8.3.1
PATCH 4/4 sched/nohz: Fix overflow error in scheduler_tick_max_deferment()
In reply to Frederic WeisbeckerFrom: Kevin Hilman <[email protected]>
While calculating the scheduler tick max deferment, the delta is converted from microseconds to nanoseconds through a multiplication against NSEC_PER_USEC.
But this microseconds operand is an unsigned int, thus the result may likely overflow. The result is cast to u64 but only once the operation is completed, which is too late to avoid overflown result.
This is currently not a problem because the scheduler tick max deferment is 1 second. But this may become an issue as we plan to make this value tunable.
So lets fix this by casting the usecs value to u64 before multiplying by NSECS_PER_USEC.
Also to prevent from this kind of mistake to happen again, move this ad-hoc jiffies -> nsecs conversion to a new helper.
--- include/linux/jiffies.h | 6 ++++++ kernel/sched/core.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/jiffies.h +6 -0
@@ -294,6 +294,12 @@ extern unsigned long preset_lpj;*/ extern unsigned int jiffies_to_msecs (const unsigned long j);extern unsigned int jiffies_to_usecs (const unsigned long j); + +static inline u64 jiffies_to_nsecs (const unsigned long j) +{ +return (u64 )jiffies_to_usecs (j) *NSEC_PER_USEC ; +} +extern unsigned long msecs_to_jiffies (const unsigned int m);extern unsigned long usecs_to_jiffies (const unsigned int u);extern unsigned long timespec_to_jiffies (const struct timespec *value);
kernel/sched/core.c +1 -1
@@ -2325,7 +2325,7 @@ u64 scheduler_tick_max_deferment(void)if (time_before_eq (next, now))return 0 ; - return jiffies_to_usecs(next - now) * NSEC_PER_USEC; + return jiffies_to_nsecs(next - now); }#endif
Signature · 1 line
1.8.3.1
Quoted 31 lines · Frederic Weisbecker
Ingo,
Please pull the timers/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/coreHEAD:
8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1----
Nothing very exiting, just a bunch of non-critical cleanups for the next merge window:1) Make the IRQ tick APIs naming more symetric
2) Optimize a bit
jiffies_lockcode coverage3) Whitespace fixes from Alex Shi
4) Fix overflow in scheduler tick max deferment calculation. Given the current 1 second max limitation, this bug shouldn't happen in mainline. It's rather to prepare for making this value tunable. Or simply in case we change the current constant.
Thanks,
Frederic
---Frederic Weisbecker (2):
tick: Renametick_check_idle()totick_irq_enter()
nohz: Get timekeeping max deferment outsidejiffies_lock
Quoted 6 lines
Alex Shi (1):
nohz_full: fix code style issue oftick_nohz_full_stop_tickKevin Hilman (1):
sched/nohz: Fix overflow error inscheduler_tick_max_deferment()
Ping.
Quoted 7 lines
include/linux/jiffies.h | 6 ++++++ include/linux/tick.h | 6 +++--- kernel/sched/core.c | 2 +- kernel/softirq.c | 2 +- kernel/time/tick-sched.c | 27 ++++++++++++++------------- 5 files changed, 25 insertions(+), 18 deletions(-)
Ingo Molnar
maintainerQuoted 38 lines · Frederic Weisbecker
Ingo,
Please pull the timers/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/coreHEAD:
8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1----
Nothing very exiting, just a bunch of non-critical cleanups for the next merge window:1) Make the IRQ tick APIs naming more symetric
2) Optimize a bit
jiffies_lockcode coverage3) Whitespace fixes from Alex Shi
4) Fix overflow in scheduler tick max deferment calculation. Given the current 1 second max limitation, this bug shouldn't happen in mainline. It's rather to prepare for making this value tunable. Or simply in case we change the current constant.
Thanks,
Frederic
---Frederic Weisbecker (2):
tick: Renametick_check_idle()totick_irq_enter()
nohz: Get timekeeping max deferment outsidejiffies_lockAlex Shi (1):
nohz_full: fix code style issue oftick_nohz_full_stop_tickKevin Hilman (1):
sched/nohz: Fix overflow error inscheduler_tick_max_deferment()
Quoted 6 lines
include/linux/jiffies.h | 6 ++++++ include/linux/tick.h | 6 +++--- kernel/sched/core.c | 2 +- kernel/softirq.c | 2 +- kernel/time/tick-sched.c | 27 ++++++++++++++------------- 5 files changed, 25 insertions(+), 18 deletions(-)
Pulled, thanks Frederic!
Ingo