sched/idle: disable tick in idle=poll idle entry
Subsystems (2)
Quoted 9 lines · Marcelo Tosatti
Commit
a5183862e76fdc25f36b39c2489b816a5c66e2e5("tick/nohz: Conditionally restart tick on idle exit") allows anohz_fullCPU to enter idle and return from it with the scheduler tick disabled (since the tick might be undesired noise).The idle=poll case still unconditionally restarts the tick when entering idle.
Quoted 6 lines
To reduce the noise for that case as well, stop the tick when entering idle, for the idle=poll case.
Change
tick_nohz_full_kick_cputo setNEED_RESCHEDbit, to handle the case where a new timer is added from an interrupt. This breaks out ofcpu_idle_polland rearms the timer if necessary.
Frederic,
As a reminder, this is the original patch and discussion:
PATCH v2 1/1 sched/idle: disable tick in idle=poll idle entry
Commit a5183862e76fdc25f36b39c2489b816a5c66e2e5 ("tick/nohz: Conditionally restart tick on idle exit") allows a nohz_full CPU to enter idle and return from it with the scheduler tick disabled (since the tick might be undesired noise).
The idle=poll case still unconditionally restarts the tick when entering idle.
To reduce the noise for that case as well, stop the tick when entering idle, for the idle=poll case.
Change tick_nohz_full_kick_cpu to set NEED_RESCHED bit, to handle the case where a new timer is added from an interrupt. This breaks out of cpu_idle_poll and rearms the timer if necessary.
---
v2: Handle the case where a new timer is added from an interrupt (Frederic Weisbecker)
include/linux/sched.h | 2 ++ kernel/sched/core.c | 10 ++++++++++ kernel/sched/idle.c | 2 +- kernel/time/tick-sched.c | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)
include/linux/sched.h +2 -0
@@ -2428,4 +2428,6 @@ extern void migrate_enable(void); DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) +void set_tif_resched_if_polling (int cpu); +#endif
kernel/sched/core.c +10 -0
@@ -988,6 +988,11 @@ static bool set_nr_if_polling(struct task_struct *p)return true; } +void set_tif_resched_if_polling (int cpu) +{ +set_nr_if_polling (cpu_rq (cpu)->idle); +} +#else static inline bool set_nr_and_not_polling (struct thread_info *ti,int tif) {
@@ -999,6 +1004,11 @@ static inline bool set_nr_if_polling(struct task_struct *p) {return false; } + +void set_tif_resched_if_polling (int cpu) +{ +set_tsk_need_resched (cpu_rq (cpu)->idle); +}#endif static bool __wake_q_add (struct wake_q_head *head,struct task_struct *task)
kernel/sched/idle.c +1 -1
@@ -324,7 +324,7 @@ static void do_idle(void)* idle as we know that the IPI is going to arrive right away. */ if (cpu_idle_force_poll ||tick_check_broadcast_expired ()) { -tick_nohz_idle_restart_tick (); +tick_nohz_idle_stop_tick ();cpu_idle_poll (); }else {cpuidle_idle_call ();
kernel/time/tick-sched.c +1 -0
@@ -408,6 +408,7 @@ void tick_nohz_full_kick_cpu(int cpu)if (!tick_nohz_full_cpu (cpu))return ; +set_tif_resched_if_polling (cpu);irq_work_queue_on (&per_cpu (nohz_full_kick_work, cpu), cpu); }
Frederic Weisbecker
maintainer(Adding more people in Cc)
Quoted 70 lines · Marcelo Tosatti
Commit
a5183862e76fdc25f36b39c2489b816a5c66e2e5("tick/nohz: Conditionally restart tick on idle exit") allows anohz_fullCPU to enter idle and return from it with the scheduler tick disabled (since the tick might be undesired noise).The idle=poll case still unconditionally restarts the tick when entering idle.
To reduce the noise for that case as well, stop the tick when entering idle, for the idle=poll case.
Change
tick_nohz_full_kick_cputo setNEED_RESCHEDbit, to handle the case where a new timer is added from an interrupt. This breaks out ofcpu_idle_polland rearms the timer if necessary.---
v2: Handle the case where a new timer is added from an interrupt (Frederic Weisbecker)
include/linux/sched.h | 2 ++ kernel/sched/core.c | 10 ++++++++++ kernel/sched/idle.c | 2 +- kernel/time/tick-sched.c | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)include/linux/sched.h +2
-0@@ -2428,4 +2428,6 @@ extern void migrate_enable(void); DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) +void set_tif_resched_if_polling (int cpu); +#endif kernel/sched/core.c +10
-0@@ -988,6 +988,11 @@ static bool set_nr_if_polling(struct task_struct *p)return true; } +void set_tif_resched_if_polling (int cpu) +{ +set_nr_if_polling (cpu_rq (cpu)->idle); +} +#else static inline bool set_nr_and_not_polling (struct thread_info *ti,int tif) {@@ -999,6 +1004,11 @@ static inline bool set_nr_if_polling(struct task_struct *p) {return false; } + +void set_tif_resched_if_polling (int cpu) +{ +set_tsk_need_resched (cpu_rq (cpu)->idle); +}#endif static bool __wake_q_add (struct wake_q_head *head,struct task_struct *task)kernel/sched/idle.c +0
-0
kernel/sched/idle.c static void do_idle(void) · line 327
Quoted 5 lines
kernel/sched/idle.c +1
-1@@ -324,7 +324,7 @@ static void do_idle(void)* idle as we know that the IPI is going to arrive right away. */ if (cpu_idle_force_poll ||tick_check_broadcast_expired ()) { -tick_nohz_idle_restart_tick (); +tick_nohz_idle_stop_tick ();
Shouldn't we simply remove the tick_nohz_idle_restart_tick() line? The nohz_full CPU should have entered here with the tick disabled already.
Also non-nohz_full systems shouldn't care.
kernel/time/tick-sched.c void tick_nohz_full_kick_cpu(int cpu) · line 411
Quoted 12 lines
kernel/sched/idle.c +0
-0cpu_idle_poll (); }else {cpuidle_idle_call ();kernel/time/tick-sched.c +1
-0@@ -408,6 +408,7 @@ void tick_nohz_full_kick_cpu(int cpu)if (!tick_nohz_full_cpu (cpu))return ; +set_tif_resched_if_polling (cpu);
Perhaps stuff that within wake_up_full_nohz_cpu() and call set_nr_if_polling() directly. Also this needs a big comment.
Thanks.
Quoted 4 lines
kernel/time/tick-sched.c +0
-0irq_work_queue_on (&per_cpu (nohz_full_kick_work, cpu), cpu); }
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 8 lines · Marcelo Tosatti
Commit
a5183862e76fdc25f36b39c2489b816a5c66e2e5("tick/nohz: Conditionally restart tick on idle exit") allows anohz_fullCPU to enter idle and return from it with the scheduler tick disabled (since the tick might be undesired noise).The idle=poll case still unconditionally restarts the tick when entering idle.
Quoted 8 lines
To reduce the noise for that case as well, stop the tick when entering idle, for the idle=poll case.
Change
tick_nohz_full_kick_cputo setNEED_RESCHEDbit, to handle the case where a new timer is added from an interrupt. This breaks out ofcpu_idle_polland rearms the timer if necessary.---
ERROR: Missing Signed-off-by: line by nominal patch author 'Marcelo Tosatti <[email protected]>'
You've not started doing kernel development three days ago, right?
Quoted 82 lines · Frederic Weisbecker
(Adding more people in Cc)
Quoted 70 lines · Marcelo Tosatti
Commit
a5183862e76fdc25f36b39c2489b816a5c66e2e5("tick/nohz: Conditionally restart tick on idle exit") allows anohz_fullCPU to enter idle and return from it with the scheduler tick disabled (since the tick might be undesired noise).The idle=poll case still unconditionally restarts the tick when entering idle.
To reduce the noise for that case as well, stop the tick when entering idle, for the idle=poll case.
Change
tick_nohz_full_kick_cputo setNEED_RESCHEDbit, to handle the case where a new timer is added from an interrupt. This breaks out ofcpu_idle_polland rearms the timer if necessary.---
v2: Handle the case where a new timer is added from an interrupt (Frederic Weisbecker)
include/linux/sched.h | 2 ++ kernel/sched/core.c | 10 ++++++++++ kernel/sched/idle.c | 2 +- kernel/time/tick-sched.c | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)include/linux/sched.h +2
-0@@ -2428,4 +2428,6 @@ extern void migrate_enable(void); DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) +void set_tif_resched_if_polling (int cpu); +#endif kernel/sched/core.c +10
-0@@ -988,6 +988,11 @@ static bool set_nr_if_polling(struct task_struct *p)return true; } +void set_tif_resched_if_polling (int cpu) +{ +set_nr_if_polling (cpu_rq (cpu)->idle); +} +#else static inline bool set_nr_and_not_polling (struct thread_info *ti,int tif) {@@ -999,6 +1004,11 @@ static inline bool set_nr_if_polling(struct task_struct *p) {return false; } + +void set_tif_resched_if_polling (int cpu) +{ +set_tsk_need_resched (cpu_rq (cpu)->idle); +}#endif static bool __wake_q_add (struct wake_q_head *head,struct task_struct *task)kernel/sched/idle.c +0
-0kernel/sched/idle.c static void do_idle(void) · line 327
Quoted 5 lines
kernel/sched/idle.c +1
-1@@ -324,7 +324,7 @@ static void do_idle(void)* idle as we know that the IPI is going to arrive right away. */ if (cpu_idle_force_poll ||tick_check_broadcast_expired ()) { -tick_nohz_idle_restart_tick (); +tick_nohz_idle_stop_tick ();Shouldn't we simply remove the
tick_nohz_idle_restart_tick()line? Thenohz_fullCPU should have entered here with the tick disabled already.
Quoted 1 line
Also non-nohz_full systems shouldn't care.
With tick_nohz_idle_restart_tick removed:
<idle>-0 [001] d.h2. 51.356672: hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51360062500 softexpires=51360062500 mode=ABS <idle>-0 [001] d.h2. 51.357671: hrtimer_cancel: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h1. 51.357671: hrtimer_expire_entry: hrtimer=ffff927ae205c418 function=tick_nohz_handler now=51360063398 <idle>-0 [001] d.h1. 51.357671: hrtimer_expire_exit: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h2. 51.357671: hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51361062500 softexpires=51361062500 mode=ABS <idle>-0 [001] d.h2. 51.358671: hrtimer_cancel: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h1. 51.358671: hrtimer_expire_entry: hrtimer=ffff927ae205c418 function=tick_nohz_handler now=51361063420 <idle>-0 [001] d.h1. 51.358672: hrtimer_expire_exit: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h2. 51.358672: hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51362062500 softexpires=51362062500 mode=ABS <idle>-0 [001] d.h2. 51.359671: hrtimer_cancel: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h1. 51.359671: hrtimer_expire_entry: hrtimer=ffff927ae205c418 function=tick_nohz_handler now=51362063447 <idle>-0 [001] d.h1. 51.359672: hrtimer_expire_exit: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h2. 51.359672: hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51363062500 softexpires=51363062500 mode=ABS
CPU 1 is idle and isolated.
Quoted 11 lines
Quoted 11 lines
kernel/sched/idle.c +0
-0cpu_idle_poll (); }else {cpuidle_idle_call ();kernel/time/tick-sched.c +0
-0@@ -408,6 +408,7 @@ void tick_nohz_full_kick_cpu(int cpu)if (!tick_nohz_full_cpu (cpu))return ;
Quoted 4 lines
kernel/time/tick-sched.c void tick_nohz_full_kick_cpu(int cpu) · line 411
Quoted 1 line
kernel/time/tick-sched.c +1
-0+set_tif_resched_if_polling (cpu);Perhaps stuff that within
wake_up_full_nohz_cpu()and callset_nr_if_polling()directly.
Can't call set_nr_if_polling() directly since if TIF_POLLING_NRFLAG is undefined:
static inline bool set_nr_if_polling(struct task_struct *p)
{
return false;
}So the wakeup won't occur. Or am i missing something?
Quoted 1 line
Also this needs a big comment.
Sure!
Thanks.
Frederic Weisbecker
maintainerQuoted 101 lines · Marcelo Tosatti
Quoted 82 lines · Frederic Weisbecker
(Adding more people in Cc)
Quoted 70 lines · Marcelo Tosatti
Commit
a5183862e76fdc25f36b39c2489b816a5c66e2e5("tick/nohz: Conditionally restart tick on idle exit") allows anohz_fullCPU to enter idle and return from it with the scheduler tick disabled (since the tick might be undesired noise).The idle=poll case still unconditionally restarts the tick when entering idle.
To reduce the noise for that case as well, stop the tick when entering idle, for the idle=poll case.
Change
tick_nohz_full_kick_cputo setNEED_RESCHEDbit, to handle the case where a new timer is added from an interrupt. This breaks out ofcpu_idle_polland rearms the timer if necessary.---
v2: Handle the case where a new timer is added from an interrupt (Frederic Weisbecker)
include/linux/sched.h | 2 ++ kernel/sched/core.c | 10 ++++++++++ kernel/sched/idle.c | 2 +- kernel/time/tick-sched.c | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)include/linux/sched.h +2
-0@@ -2428,4 +2428,6 @@ extern void migrate_enable(void); DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) +void set_tif_resched_if_polling (int cpu); +#endif kernel/sched/core.c +10
-0@@ -988,6 +988,11 @@ static bool set_nr_if_polling(struct task_struct *p)return true; } +void set_tif_resched_if_polling (int cpu) +{ +set_nr_if_polling (cpu_rq (cpu)->idle); +} +#else static inline bool set_nr_and_not_polling (struct thread_info *ti,int tif) {@@ -999,6 +1004,11 @@ static inline bool set_nr_if_polling(struct task_struct *p) {return false; } + +void set_tif_resched_if_polling (int cpu) +{ +set_tsk_need_resched (cpu_rq (cpu)->idle); +}#endif static bool __wake_q_add (struct wake_q_head *head,struct task_struct *task)kernel/sched/idle.c +0
-0kernel/sched/idle.c static void do_idle(void) · line 327
Quoted 5 lines
kernel/sched/idle.c +1
-1@@ -324,7 +324,7 @@ static void do_idle(void)* idle as we know that the IPI is going to arrive right away. */ if (cpu_idle_force_poll ||tick_check_broadcast_expired ()) { -tick_nohz_idle_restart_tick (); +tick_nohz_idle_stop_tick ();Shouldn't we simply remove the
tick_nohz_idle_restart_tick()line? Thenohz_fullCPU should have entered here with the tick disabled already.Quoted 1 line
Also non-nohz_full systems shouldn't care.
With
tick_nohz_idle_restart_tickremoved:<idle>-0 [001] d.h2. 51.356672:
hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51360062500 softexpires=51360062500 mode=ABS <idle>-0 [001] d.h2. 51.357671:hrtimer_cancel: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h1. 51.357671:hrtimer_expire_entry: hrtimer=ffff927ae205c418 function=tick_nohz_handler now=51360063398 <idle>-0 [001] d.h1. 51.357671:hrtimer_expire_exit: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h2. 51.357671:hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51361062500 softexpires=51361062500 mode=ABS <idle>-0 [001] d.h2. 51.358671:hrtimer_cancel: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h1. 51.358671:hrtimer_expire_entry: hrtimer=ffff927ae205c418 function=tick_nohz_handler now=51361063420 <idle>-0 [001] d.h1. 51.358672:hrtimer_expire_exit: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h2. 51.358672:hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51362062500 softexpires=51362062500 mode=ABS <idle>-0 [001] d.h2. 51.359671:hrtimer_cancel: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h1. 51.359671:hrtimer_expire_entry: hrtimer=ffff927ae205c418 function=tick_nohz_handler now=51362063447 <idle>-0 [001] d.h1. 51.359672:hrtimer_expire_exit: hrtimer=ffff927ae205c418
<idle>-0 [001] d.h2. 51.359672:hrtimer_start: hrtimer=ffff927ae205c418 function=tick_nohz_handler expires=51363062500 softexpires=51363062500 mode=ABS
Quoted 1 line
CPU 1 is idle and isolated.
Suprising, somehow the CPU's tick never interrupted a non-idle section. I guess it's possible after boot. Or the CPU had tick dependencies before. I was about to propose stopping the tick right before exiting to userspace but since you're using idle=poll, I guess userspace must be reached as fast as possible and therefore you prefer to stop the tick before the next wake-up rather that after?
Also instead of polling in kernel, why not polling in userspace for events? This sounds like a saner isolation design. Entering/exiting the kernel is always a risk for something going wrong.
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
kernel/sched/idle.c +0
-0cpu_idle_poll (); }else {cpuidle_idle_call ();kernel/time/tick-sched.c +0
-0@@ -408,6 +408,7 @@ void tick_nohz_full_kick_cpu(int cpu)if (!tick_nohz_full_cpu (cpu))return ;Quoted 4 lines
kernel/time/tick-sched.c void tick_nohz_full_kick_cpu(int cpu) · line 411
Quoted 1 line
kernel/time/tick-sched.c +1
-0+set_tif_resched_if_polling (cpu);Perhaps stuff that within
wake_up_full_nohz_cpu()and callset_nr_if_polling()directly.Can't call
set_nr_if_polling()directly since ifTIF_POLLING_NRFLAGis undefined:
Quoted 6 lines
static inline bool
set_nr_if_polling(struct task_struct *p){ return false; }So the wakeup won't occur. Or am i missing something?
Ok but can you at least move that to wake_up_full_nohz_cpu()? tick_nohz_full_kick_cpu() is more general and doesn't only concern new timers.
Signature · 2 lines
Frederic Weisbecker SUSE Labs