nohz: Posix cpu timers handling on full dynticks
Ingo,
Please pull this second version of the dynticks handling of posix cpu timers from:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/nohz-posix-timers-v2
This fixes an issue with a race between run_posix_cpu_timers() and full dynticks CPUs that we found while discussing a patch with Olivier Langlois.
As a bonus, it also provides the other side of posix cpu timers handling in dynticks with the new helper to check before stopping the tick.
Thanks.
Frederic Weisbecker (3):
nohz: New APIs to re-evaluate the tick on full dynticks CPUs
posix_timers: Kick full dynticks CPUs when a posix cpu timer is armed
posix_timers: New API to prevent from stopping the tick when timers
are running
include/linux/posix-timers.h | 2 + include/linux/tick.h | 4 ++ kernel/posix-cpu-timers.c | 76 +++++++++++++++++++++++++++++++++--------- kernel/time/Kconfig | 1 + kernel/time/tick-sched.c | 51 ++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/3 nohz: New APIs to re-evaluate the tick on full dynticks CPUs
Provide two new helpers in order to notify the full dynticks CPUs about some internal system changes against which they may reconsider the state of their tick. Some practical examples include: posix cpu timers, perf tick and sched clock tick.
For now the notifying handler, implemented through IPIs, is a stub that will be implemented when we get the tick stop/restart infrastructure in.
--- include/linux/tick.h | 4 +++ kernel/time/Kconfig | 1 + kernel/time/tick-sched.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 0 deletions(-)
include/linux/tick.h +4 -0
@@ -159,8 +159,12 @@ static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }#ifdef CONFIG_NO_HZ_FULL extern int tick_nohz_full_cpu (int cpu); +extern void tick_nohz_full_kick (void ); +extern void tick_nohz_full_kick_all (void );#else static inline int tick_nohz_full_cpu (int cpu) {return 0 ; } +static inline void tick_nohz_full_kick (void ) { } +static inline void tick_nohz_full_kick_all (void ) { }#endif
kernel/time/Kconfig +1 -0
@@ -111,6 +111,7 @@ config NO_HZ_FULL select RCU_USER_QS select RCU_NOCB_CPU select CONTEXT_TRACKING_FORCE + select IRQ_WORK help Adaptively try to shutdown the tick whenever possible, even when the CPU is running tasks. Typically this requires running a single
kernel/time/tick-sched.c +51 -0
57 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 2/3 posix_timers: Kick full dynticks CPUs when a posix cpu timer is armed
In reply to Frederic WeisbeckerKick the full dynticks CPUs when a posix cpu timer is enqueued by way of a standard call to posix_cpu_timer_set() or set_process_cpu_timer(). This also include rescheduled firing timers.
This way they can re-evaluate the state of (and possibly restart) their tick against the new expiry modification.
--- kernel/posix-cpu-timers.c | 35 ++++++++++++++++++++++++++++++++++- 1 files changed, 34 insertions(+), 1 deletions(-)
kernel/posix-cpu-timers.c +34 -1
@@ -10,6 +10,8 @@#include <linux/kernel_stat.h> #include <trace/events/timer.h> #include <linux/random.h> +#include <linux/tick.h> +#include <linux/workqueue.h> /* * Called after updating RLIMIT_CPU to run cpu timer and update
@@ -636,6 +638,26 @@ static int cpu_timer_sample_group(const clockid_t which_clock,return 0 ; } +#ifdef CONFIG_NO_HZ_FULL +static void nohz_kick_work_fn (struct work_struct *work) +{ +tick_nohz_full_kick_all (); +} + +static DECLARE_WORK(nohz_kick_work, nohz_kick_work_fn); + +/* +* We need the IPIs to be sent from sane process context. +* The posix cpu timers are always set with irqs disabled. +*/ +static void posix_cpu_timer_kick_nohz (void ) +{ +schedule_work (&nohz_kick_work); +} +#else +static inline void posix_cpu_timer_kick_nohz (void ) { } +#endif +/* * Guts of sys_timer_settime for CPU timers. * This is called with the timer locked and interrupts disabled.
@@ -794,6 +816,8 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int flags,sample_to_timespec (timer->it_clock, old_incr, &old->it_interval); } +if (!ret) +posix_cpu_timer_kick_nohz ();return ret; }
@@ -1336,6 +1360,13 @@ void run_posix_cpu_timers(struct task_struct *tsk)cpu_timer_fire (timer);spin_unlock (&timer->it_lock); } + +/* +* In case some timers were rescheduled after the queue got emptied, +* wake up full dynticks CPUs. +*/ +if (tsk->signal->cputimer.running) +posix_cpu_timer_kick_nohz (); }/*
@@ -1366,7 +1397,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, }if (!*newval) -return ; + goto out; *newval += now.cpu; }
@@ -1384,6 +1415,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, tsk->signal->cputime_expires.virt_exp = *newval;break ; } +out: +posix_cpu_timer_kick_nohz (); } static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
Signature · 1 line
1.7.5.4
PATCH 3/3 posix_timers: New API to prevent from stopping the tick when timers are running
In reply to Frederic WeisbeckerBring a new helper that the full dynticks infrastructure can call in order to know if it can safely stop the tick from the posix cpu timers subsystem point of view.
--- include/linux/posix-timers.h | 2 ++ kernel/posix-cpu-timers.c | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-)
include/linux/posix-timers.h +2 -0
@@ -122,6 +122,8 @@ void run_posix_cpu_timers(struct task_struct *task);void posix_cpu_timers_exit (struct task_struct *task);void posix_cpu_timers_exit_group (struct task_struct *task); +bool posix_cpu_timers_can_stop_tick (struct task_struct *tsk); +void set_process_cpu_timer (struct task_struct *task,unsigned int clock_idx,cputime_t *newval,cputime_t *oldval);
kernel/posix-cpu-timers.c +26 -15
59 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Ingo Molnar
maintainerQuoted 22 lines · Frederic Weisbecker
Ingo,
Please pull this second version of the dynticks handling of posix cpu timers from:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/nohz-posix-timers-v2This fixes an issue with a race between
run_posix_cpu_timers()and full dynticks CPUs that we found while discussing a patch with Olivier Langlois.As a bonus, it also provides the other side of posix cpu timers handling in dynticks with the new helper to check before stopping the tick.
Thanks.
Frederic Weisbecker (3):
nohz: New APIs to re-evaluate the tick on full dynticks CPUs
posix_timers: Kick full dynticks CPUs when a posix cpu timer is armed
posix_timers: New API to prevent from stopping the tick when timers
are running
Quoted 6 lines
include/linux/posix-timers.h | 2 + include/linux/tick.h | 4 ++ kernel/posix-cpu-timers.c | 76 +++++++++++++++++++++++++++++++++--------- kernel/time/Kconfig | 1 + kernel/time/tick-sched.c | 51 ++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 16 deletions(-)
Pulled, thanks Frederic!
Ingo