Idle balancer: cache align nohz structure to improve idle load balancing scalability
PATCH 1/1 Idle balancer: cache align nohz structure to improve idle load balancing scalability
Idle load balancing makes use of a global structure nohz to keep track of the cpu doing the idle load balancing, first and second busy cpu and the cpus that are idle. This leads to scalability issue.
For workload that has processes waking up and going to sleep often, the load_balancer, first_pick_cpu, second_cpu and idle_cpus_mask in the no_hz structure get updated very frequently. This causes lots of cache bouncing and slowing down the idle and wakeup path for large system with many cores/sockets. This is evident from up to 41% of cpu cycles spent in the function select_nohz_load_balancer from a test work load I ran. By putting these fields in their own cache line, the problem can be mitigated.
The test workload has multiple pairs of processes. Within a process pair, each process receive and then send message back and forth to the other process via a pipe connecting them. So at any one time, half the processes are active.
I found that for 32 pairs of processes, I got an increase of the rate of context switching between the processes by 37% and by 24% for 64 process pairs. The test was run on a 8 socket 64 cores NHM-EX system, where hyper-threading has been turned on.
Tim
Workload cpu cycle profile on vanilla kernel:
41.19% swapper [kernel.kallsyms] [k] select_nohz_load_balancer
- select_nohz_load_balancer
+ 54.91% tick_nohz_restart_sched_tick
+ 45.04% tick_nohz_stop_sched_tick
18.96% swapper [kernel.kallsyms] [k] mwait_idle_with_hints 3.50% swapper [kernel.kallsyms] [k] tick_nohz_restart_sched_tick 3.36% swapper [kernel.kallsyms] [k] tick_check_idle 2.96% swapper [kernel.kallsyms] [k] rcu_enter_nohz 2.40% swapper [kernel.kallsyms] [k] _raw_spin_lock 2.11% swapper [kernel.kallsyms] [k] tick_nohz_stop_sched_tick
kernel/sched_fair.c +4 -4
@@ -3639,10 +3639,10 @@ static inline void init_sched_softirq_csd(struct call_single_data *csd)* load balancing for all the idle CPUs. */ static struct { -atomic_t load_balancer; -atomic_t first_pick_cpu; -atomic_t second_pick_cpu; -cpumask_var_t idle_cpus_mask; +atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;cpumask_var_t grp_idle_mask;unsigned long next_balance;/* in jiffy units */ } nohz____cacheline_aligned ;
Quoted 49 lines · Tim Chen
Idle load balancing makes use of a global structure nohz to keep track of the cpu doing the idle load balancing, first and second busy cpu and the cpus that are idle. This leads to scalability issue.
For workload that has processes waking up and going to sleep often, the
load_balancer,first_pick_cpu,second_cpuandidle_cpus_maskin theno_hzstructure get updated very frequently. This causes lots of cache bouncing and slowing down the idle and wakeup path for large system with many cores/sockets. This is evident from up to 41% of cpu cycles spent in the functionselect_nohz_load_balancerfrom a test work load I ran. By putting these fields in their own cache line, the problem can be mitigated.The test workload has multiple pairs of processes. Within a process pair, each process receive and then send message back and forth to the other process via a pipe connecting them. So at any one time, half the processes are active.
I found that for 32 pairs of processes, I got an increase of the rate of context switching between the processes by 37% and by 24% for 64 process pairs. The test was run on a 8 socket 64 cores NHM-EX system, where hyper-threading has been turned on.
Tim
Workload cpu cycle profile on vanilla kernel:
41.19% swapper [kernel.kallsyms] [k]select_nohz_load_balancer
-select_nohz_load_balancer
+ 54.91%tick_nohz_restart_sched_tick
+ 45.04%tick_nohz_stop_sched_tick18.96% swapper [kernel.kallsyms] [k] mwait_idle_with_hints 3.50% swapper [kernel.kallsyms] [k] tick_nohz_restart_sched_tick 3.36% swapper [kernel.kallsyms] [k] tick_check_idle 2.96% swapper [kernel.kallsyms] [k] rcu_enter_nohz 2.40% swapper [kernel.kallsyms] [k] _raw_spin_lock 2.11% swapper [kernel.kallsyms] [k] tick_nohz_stop_sched_tickSigned-off-by Tim Chen <[email protected]>kernel/sched_fair.c +0
-1@@ -3639,10 +3639,10 @@ static inline void init_sched_softirq_csd(struct call_single_data *csd)* load balancing for all the idle CPUs. */ static struct { - atomic_t load_balancer;
kernel/sched_fair.c static inline void init_sched_softirq_csd(struct call_single_data *csd) · line 3648
Quoted 10 lines
kernel/sched_fair.c +4
-3-atomic_t first_pick_cpu; -atomic_t second_pick_cpu; -cpumask_var_t idle_cpus_mask; +atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;cpumask_var_t grp_idle_mask;unsigned long next_balance;/* in jiffy units */ } nohz____cacheline_aligned ;
Dont you increase cache footprint, say for an Uniprocessor machine ?
(CONFIG_SMP=n)
____cacheline_aligned_in_smp seems more suitable in this case.
Quoted 11 lines · Eric Dumazet
kernel/sched_fair.c static inline void init_sched_softirq_csd(struct call_single_data *csd) · line 3648
Quoted 8 lines
kernel/sched_fair.c +4
-0+atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;cpumask_var_t grp_idle_mask;unsigned long next_balance;/* in jiffy units */ } nohz____cacheline_aligned ;Dont you increase cache footprint, say for an Uniprocessor machine ?
Quoted 3 lines
(
CONFIG_SMP=n)
____cacheline_aligned_in_smpseems more suitable in this case.
I believe this code is already under ifdef CONFIG_SMP.
thanks,
suresh
Quoted 12 lines · Suresh Siddha
Quoted 11 lines · Eric Dumazet
kernel/sched_fair.c static inline void init_sched_softirq_csd(struct call_single_data *csd) · line 3648
Quoted 8 lines
kernel/sched_fair.c +4
-0+atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;cpumask_var_t grp_idle_mask;unsigned long next_balance;/* in jiffy units */ } nohz____cacheline_aligned ;Dont you increase cache footprint, say for an Uniprocessor machine ?
Quoted 5 lines
Quoted 3 lines
(
CONFIG_SMP=n)
____cacheline_aligned_in_smpseems more suitable in this case.I believe this code is already under ifdef
CONFIG_SMP.
Right now yes, but it might change in the future after some code cleanup / consolidation.
This kind of things are copy/pasted, and the right semantic here is ____cacheline_aligned_in_smp . It matches the changelog better.
Note: the ____cacheline_aligned on global "nohz" structure was quite different, and in contradiction of what this patch wants to do.
Previously, we wanted to group all fields on a single cache line. We now know it was not a scalable strategy, thanks to Tim.
Quoted 8 lines · Eric Dumazet
Dont you increase cache footprint, say for an Uniprocessor machine ?
(
CONFIG_SMP=n)
____cacheline_aligned_in_smpseems more suitable in this case.
Okay, using the smp version of the cache align in this updated patch.
Thanks.
------------
Idle load balancing makes use of a global structure nohz to keep track of the cpu doing the idle load balancing, first and second busy cpu and the cpus that are idle. This leads to scalability issue.
For workload that has processes waking up and going to sleep often, the load_balancer, first_pick_cpu, second_cpu and idle_cpus_mask in the no_hz structure get updated very frequently. This causes lots of cache bouncing and slowing down the idle and wakeup path for large system with many cores/sockets. This is evident from up to 41% of cpu cycles spent in the function select_nohz_load_balancer from a test work load I ran. By putting these fields in their own cache line, the problem can be mitigated.
The test workload has multiple pairs of processes. Within a process pair, each process receive and then send message back and forth to the other process via a pipe connecting them. So at any one time, half the processes are active.
I found that for 32 pairs of processes, I got an increase of the rate of context switching between the processes by 37% and by 24% for 64 process pairs. The test was run on a 8 socket 64 cores NHM-EX system, where hyper-threading has been turned on.
Tim
kernel/sched_fair.c +4 -4
@@ -3639,10 +3639,10 @@ static inline void init_sched_softirq_csd(struct call_single_data *csd)* load balancing for all the idle CPUs. */ static struct { -atomic_t load_balancer; -atomic_t first_pick_cpu; -atomic_t second_pick_cpu; -cpumask_var_t idle_cpus_mask; +atomic_t load_balancer____cacheline_aligned_in_smp ; +atomic_t first_pick_cpu____cacheline_aligned_in_smp ; +atomic_t second_pick_cpu____cacheline_aligned_in_smp ; +cpumask_var_t idle_cpus_mask____cacheline_aligned_in_smp ;cpumask_var_t grp_idle_mask;unsigned long next_balance;/* in jiffy units */ } nohz____cacheline_aligned ;
kernel/sched_fair.c static inline void init_sched_softirq_csd(struct call_single_data *csd) · line 3645
Quoted 10 lines · Tim Chen
*/
static struct {kernel/sched_fair.c +4
-4-atomic_t load_balancer; -atomic_t first_pick_cpu; -atomic_t second_pick_cpu; -cpumask_var_t idle_cpus_mask; +atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;
On large configs idle_cpu_masks may be allocated. May need more changes to tell the allocator to cache align/pad too?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only
Quoted 12 lines · Andi Kleen
Quoted 10 lines · Tim Chen
*/
static struct {
-atomic_tload_balancer;
-atomic_tfirst_pick_cpu;
-atomic_tsecond_pick_cpu;
-cpumask_var_tidle_cpus_mask;
+atomic_tload_balancer____cacheline_aligned;
+atomic_tfirst_pick_cpu____cacheline_aligned;
+atomic_tsecond_pick_cpu____cacheline_aligned;
+cpumask_var_tidle_cpus_mask____cacheline_aligned;
Quoted 3 lines
On large configs
idle_cpu_masksmay be allocated. May need more changes to tell the allocator to cache align/pad too?
An alternate approach is to split this struct per node/socket and do the nohz idle balancing logic at that level. That should be more scalable in terms of nohz balancing (ensure one CPU wont be doing nohz balancing for huge number of idle CPUs). I had looked at that approach couple of years earlier and couldn't measure that much of a gain. May be it is time to revisit that with increased core count.
Thanks,
Venki
Quoted 17 lines · Venki Pallipadi
Quoted 12 lines · Andi Kleen
kernel/sched_fair.c static inline void init_sched_softirq_csd(struct call_single_data *csd) · line 3645
Quoted 10 lines · Tim Chen
*/
static struct {kernel/sched_fair.c +4
-4-atomic_t load_balancer; -atomic_t first_pick_cpu; -atomic_t second_pick_cpu; -cpumask_var_t idle_cpus_mask; +atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;Quoted 3 lines
On large configs
idle_cpu_masksmay be allocated. May need more changes to tell the allocator to cache align/pad too?
Quoted 6 lines
An alternate approach is to split this struct per node/socket and do the nohz idle balancing logic at that level. That should be more scalable in terms of nohz balancing (ensure one CPU wont be doing nohz balancing for huge number of idle CPUs). I had looked at that approach couple of years earlier and couldn't measure that much of a gain. May be it is time to revisit that with increased core count.
I am actually looking at it. This is a quick fix for the meantime.
Even with this cacheline aligned, the first_pick_cpu and second_pick_cpu cacheline bouncing is still causing ~8% more performance impact on this synthetic lat_ctx heavy workload. For this experiment to measure the potential scope we have here, We left the cacheline bouncing associated with the nohz.idle_cpus_mask update in place.
thanks,
suresh
Peter Zijlstra
maintainerQuoted 17 lines · Venki Pallipadi
Quoted 12 lines · Andi Kleen
kernel/sched_fair.c static inline void init_sched_softirq_csd(struct call_single_data *csd) · line 3645
Quoted 10 lines · Tim Chen
*/
static struct {kernel/sched_fair.c +4
-4-atomic_t load_balancer; -atomic_t first_pick_cpu; -atomic_t second_pick_cpu; -cpumask_var_t idle_cpus_mask; +atomic_t load_balancer____cacheline_aligned ; +atomic_t first_pick_cpu____cacheline_aligned ; +atomic_t second_pick_cpu____cacheline_aligned ; +cpumask_var_t idle_cpus_mask____cacheline_aligned ;Quoted 3 lines
On large configs
idle_cpu_masksmay be allocated. May need more changes to tell the allocator to cache align/pad too?
Quoted 6 lines
An alternate approach is to split this struct per node/socket and do the nohz idle balancing logic at that level. That should be more scalable in terms of nohz balancing (ensure one CPU wont be doing nohz balancing for huge number of idle CPUs). I had looked at that approach couple of years earlier and couldn't measure that much of a gain. May be it is time to revisit that with increased core count.
Yeah, that would be best, although I remember there was a problem with your approach back then, a fully idle node would not balance at all or something like that.
A message that is not in the archive (sent off-list or not yet received): 4FF5AC937153B0459463C1A88EB478F20135D6ECB5@orsmsx505.amr.corp.intel.com
Quoted 7 lines · Suresh Siddha
Quoted 6 lines · Venki Pallipadi
An alternate approach is to split this struct per node/socket and do the nohz idle balancing logic at that level. That should be more scalable in terms of nohz balancing (ensure one CPU wont be doing nohz balancing for huge number of idle CPUs). I had looked at that approach couple of years earlier and couldn't measure that much of a gain. May be it is time to revisit that with increased core count.
Quoted 3 lines · Peter Zijlstra
Yeah, that would be best, although I remember there was a problem with your approach back then, a fully idle node would not balance at all or something like that.
That is correct. So to minimize the global updates I did two things.
1. Track nr of busy cpus in each scheduler group for each scheduler domain.
2. delay the update of nohz.idle_cpus_mask (And to the above mentioned new sched group specific busy stat) when coming out of idle to the first busy tick. And added idle_cpu() checks at couple of places in idle load balancing code to ensure that the cpu is really idle.
The kicked cpu will still do the idle load balancing on behalf of all the cpu's. We are kicking only when it is really needed.
If we add more smarts then we can split this also into multiple idle load balances in the future or kick the active load balance directly for the HT/MC cases where we want to spread busy cores/threads. This is open for future though.
Quoted 8 lines
I am actually looking at it. This is a quick fix for the meantime.
Even with this cacheline aligned, the
first_pick_cpuandsecond_pick_cpucacheline bouncing is still causing ~8% more performance impact on this syntheticlat_ctxheavy workload. For this experiment to measure the potential scope we have here, We left the cacheline bouncing associated with the nohz.idle_cpus_mask update in place.
Appended patch helped improve that workload by 100%. We haven't completed the testing of this patch but thought of getting quick feedback. Also I may have to split this into multiple patches (removing of nohz_stamp etc are not related). Thanks.
---
From: Suresh Siddha <[email protected]>
Subject: RFC: sched, nohz: sched group, domain aware nohz idle load balancing
Make nohz idle load balancing more scalabale by making it aware of sched group/ sched domains.
Introduce nr_busy_cpus in the struct sched_group_power [Not in sched_group because sched groups are duplicated for the SD_OVERLAP scheduler domain] and for each cpu that enters and exits tickless, this parameter will be updated in each scheduler group of the scheduler domain that this cpu belongs to.
To avoid the frequent update of this tickless state (global nohz data aswell as some what local nr_busy_cpus in the sched_group's) when the cpu enters and exits tickless idle often, the update of the exit state is delayed to the first timer tick that happens after the cpu becomes busy.
Idle load balance is kicked on one of the idle cpu's when there is atleast one idle cpu and
- a busy rq having more than one task or
- a busy scheduler group having multiple busy cpus that exceed the sched group power or
- for the SD_ASYM_PACKING domain, if the lower numbered cpu's in that domain are idle compared to the busy ones.
This will help in kicking the idle load balancing request only when there is a real imbalance. And once it is mostly balanced, these kicks will be minimized.
These changes helped improve the workload that is context switch intensive between number of task pairs by 2x on a 8 socket NHM-EX based system.
---
include/linux/sched.h | 4 + kernel/sched.c | 27 +++-- kernel/sched_fair.c | 264 ++++++++++++++++++------------------------------- 3 files changed, 116 insertions(+), 179 deletions(-)
include/linux/sched.h +4 -0
@@ -901,6 +901,10 @@ struct sched_group_power {* single CPU. */ unsigned int power, power_orig; +/* +* Number of busy cpus in this group. +*/ +atomic_t nr_busy_cpus; };struct sched_group {
kernel/sched.c +17 -10
@@ -600,8 +600,7 @@ struct rq {unsigned long cpu_load[CPU_LOAD_IDX_MAX ];unsigned long last_load_update_tick;#ifdef CONFIG_NO_HZ -u64 nohz_stamp; -unsigned char nohz_balance_kick; + unsigned int tick_stopped:1;#endif int skip_clock_update;
@@ -1337,6 +1336,20 @@ static void resched_cpu(int cpu) }#ifdef CONFIG_NO_HZ +#define NOHZ_BALANCE_KICK 0 +#define NOHZ_NEED_BALANCING 1 +/* +* idle load balancing details +* - When one of the busy CPUs notice that there may be an idle rebalancing +* needed, they will kick the idle load balancer, which then does idle +* load balancing for all the idle CPUs. +*/ +static struct { +cpumask_var_t idle_cpus_mask; +unsigned long next_balance;/* in jiffy units */ +unsigned long bits; +} nohz____cacheline_aligned ; +/* * In the semi idle case, use the nearest busy cpu for migrating timers * from an idle cpu. This is good for power-savings.
@@ -1406,7 +1419,8 @@ void wake_up_idle_cpu(int cpu)static inline bool got_nohz_idle_kick (void ) { -return idle_cpu (smp_processor_id ()) &&this_rq ()->nohz_balance_kick; +return idle_cpu (smp_processor_id ()) && +test_bit (NOHZ_BALANCE_KICK , &nohz.bits); }#else /* CONFIG_NO_HZ */
@@ -8297,9 +8311,6 @@ void __init sched_init(void) rq->idle_stamp =0 ; rq->avg_idle =2 *sysctl_sched_migration_cost;rq_attach_root (rq, &def_root_domain); -#ifdef CONFIG_NO_HZ - rq->nohz_balance_kick =0 ; -#endif #endif init_rq_hrtick (rq);atomic_set (&rq->nr_iowait,0 );
@@ -8344,10 +8355,6 @@ void __init sched_init(void)zalloc_cpumask_var (&sched_domains_tmpmask,GFP_NOWAIT );#ifdef CONFIG_NO_HZ zalloc_cpumask_var (&nohz.idle_cpus_mask,GFP_NOWAIT ); -alloc_cpumask_var (&nohz.grp_idle_mask,GFP_NOWAIT ); -atomic_set (&nohz.load_balancer, nr_cpu_ids); -atomic_set (&nohz.first_pick_cpu, nr_cpu_ids); -atomic_set (&nohz.second_pick_cpu, nr_cpu_ids);#endif /* May be allocated at isolcpus cmdline parse time */ if (cpu_isolated_map ==NULL )
kernel/sched_fair.c +95 -169
375 lines not on this page · raw message
Quoted 1 line · Suresh Siddha
That is correct. So to minimize the global updates I did two things.
Another issue I am trying to solve with nohz balancer is stale-ness of nohz.next_balance. As cpus enter/exit tickless state, nohz.next_balance is not updated to reflect that. I have found that its a predominant source of increased idle time with CFS bandwidth patches :
https://lkml.org/lkml/2011/9/26/162
While it may be costly to update nohz.next_balance during exit event, I think we should update it upon entry. I am working on a patch to make nohz.next_balance more precise. This requires tickless idle cpus to be tracked in a global rb-tree (each tickless idle cpu is inserted in this tree, indexed by its rq->next_balance). Having this rb-tree makes it easy to precisely determine min(rq->next_balance) when a kick is deserved, which I am hoping is good for both performance (on the dot wakeup) but also power (avoid unnecessary/early wakeup).
Draft patch is below. I was intending to post it soon along with some real-world benchmark numbers (based on matrix multiplication).
Any other suggestions to avoid this global rb-tree, but still keep nohz.next_balance as precise as possible, would be welcome!
--- Makefile | 2 kernel/sched.c | 9 ++ kernel/sched_fair.c | 185 +++++++++++++++++++++++++++++++++++++++++++----- kernel/sched_idletask.c | 2 4 files changed, 179 insertions(+), 19 deletions(-)
Makefile +1 -1
@@ -1,6 +1,6 @@ VERSION = 3 PATCHLEVEL = 1 -SUBLEVEL = 0 +SUBLEVEL = 0-myp EXTRAVERSION = NAME = "Divemaster Edition"
kernel/sched.c +9 -0
@@ -602,6 +602,7 @@ struct rq {#ifdef CONFIG_NO_HZ u64 nohz_stamp;unsigned char nohz_balance_kick; +struct rb_node nohz_node;#endif int skip_clock_update;
@@ -1409,6 +1410,8 @@ static inline bool got_nohz_idle_kick(vo return idle_cpu(smp_processor_id()) && this_rq()->nohz_balance_kick; } +static void reset_first_second_pick_cpu (int cpu); +#else /* CONFIG_NO_HZ */ static inline bool got_nohz_idle_kick (void )
@@ -1416,6 +1419,8 @@ static inline bool got_nohz_idle_kick(vo return false; } +static inline void reset_first_second_pick_cpu (int cpu) { } +#endif /* CONFIG_NO_HZ */ static u64 sched_avg_period (void )
@@ -8299,6 +8304,7 @@ void __init sched_init(void)rq_attach_root (rq, &def_root_domain);#ifdef CONFIG_NO_HZ rq->nohz_balance_kick =0 ; +rb_init_node (&rq->nohz_node);#endif #endif init_rq_hrtick (rq);
@@ -8344,10 +8350,13 @@ void __init sched_init(void)zalloc_cpumask_var (&sched_domains_tmpmask,GFP_NOWAIT );#ifdef CONFIG_NO_HZ zalloc_cpumask_var (&nohz.idle_cpus_mask,GFP_NOWAIT ); +zalloc_cpumask_var (&nohz.stale_idle_cpus_mask,GFP_NOWAIT );alloc_cpumask_var (&nohz.grp_idle_mask,GFP_NOWAIT );atomic_set (&nohz.load_balancer, nr_cpu_ids);atomic_set (&nohz.first_pick_cpu, nr_cpu_ids);atomic_set (&nohz.second_pick_cpu, nr_cpu_ids); + nohz.rq_next_balance =RB_ROOT ; +spin_lock_init (&nohz.next_balance_lock);#endif /* May be allocated at isolcpus cmdline parse time */ if (cpu_isolated_map ==NULL )
kernel/sched_fair.c +167 -18
253 lines not on this page · raw message
kernel/sched_idletask.c +2 -0
@@ -24,6 +24,8 @@ static struct task_struct *pick_next_tas {schedstat_inc (rq, sched_goidle);calc_load_account_idle (rq); +reset_first_second_pick_cpu (cpu_of (rq)); +return rq->idle; }
kernel/sched_fair.c static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) · line 4590
Quoted 10 lines · Suresh Siddha
kernel/sched_fair.c +10
-0+/* +* We were recently in tickless idle mode. We will do the delayed +* update of busy mode now (first busy tick after returning from idle). +*/ +if (unlikely (rq->tick_stopped)) { +cpumask_clear_cpu (cpu, nohz.idle_cpus_mask); + +if (cpumask_bits (nohz.idle_cpus_mask)[BIT_WORD (cpu)] ==0 && +cpumask_empty (nohz.idle_cpus_mask)) +clear_bit (NOHZ_NEED_BALANCING , &nohz.bits);
Can't this clear_bit race with set_bit() in select_nohz_load_balancer()?
CPU0 CPU1
cpumask_clear_cpu()
if ( ...)
cpumask_set_cpu(); set_bit(); clear_bit();
?
- vatsa
Quoted 17 lines · Srivatsa Vaddagiri
kernel/sched_fair.c static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) · line 4590
Quoted 10 lines · Suresh Siddha
kernel/sched_fair.c +10
-0+/* +* We were recently in tickless idle mode. We will do the delayed +* update of busy mode now (first busy tick after returning from idle). +*/ +if (unlikely (rq->tick_stopped)) { +cpumask_clear_cpu (cpu, nohz.idle_cpus_mask); + +if (cpumask_bits (nohz.idle_cpus_mask)[BIT_WORD (cpu)] ==0 && +cpumask_empty (nohz.idle_cpus_mask)) +clear_bit (NOHZ_NEED_BALANCING , &nohz.bits);Can't this
clear_bitrace withset_bit()inselect_nohz_load_balancer()?CPU0 CPU1
Quoted 8 lines
cpumask_clear_cpu()
if ( ...)cpumask_set_cpu(); set_bit(); clear_bit();?
Yes. All I want is a quick way of getting the cpumask_weight(nohz.idle_cpus_mask) so that the busy cpu need not spend much time to see if there is an idle cpu that needs idle load balancing. Let me see if there is any simple way or else we need nohz.nr_idle_cpus
thanks,
suresh
Peter Zijlstra
maintainerQuoted 9 lines · Suresh Siddha
kernel/sched_fair.c +1
-0@@ -3317,6 +3317,7 @@ static void update_cpu_power(struct sched_domain *sd, int cpu)cpu_rq (cpu)->cpu_power = power; sdg->sgp->power = power; +atomic_set (&sdg->sgp->nr_busy_cpus, sdg->group_weight); }static void update_group_power (struct sched_domain *sd,int cpu)
kernel/sched_fair.c static void update_group_power(struct sched_domain *sd, int cpu) · line 3344
Quoted 5 lines
kernel/sched_fair.c +1
-0@@ -3339,6 +3340,7 @@ static void update_group_power(struct sched_domain *sd, int cpu) }while (group != child->groups); sdg->sgp->power = power; +atomic_set (&sdg->sgp->nr_busy_cpus, sdg->group_weight); }
So we run this rather frequently, and it will trample all over:
kernel/sched_fair.c static void nohz_balancer_kick(int cpu) · line 4416
Quoted 3 lines
kernel/sched_fair.c +3
-0+*/ +for_each_domain (cpu, sd) +atomic_dec (&sd->groups->sgp->nr_busy_cpus);
because I cannot see any serialization between those sites.
Also, isn't it rather weird to just assume all cpus are busy in update_group_power()? If you would actually set the right value in update_cpu_power() you could use a straight sum in update_group_power() and get a more or less accurate number out.
Quoted 18 lines · Peter Zijlstra
Quoted 9 lines · Suresh Siddha
kernel/sched_fair.c +1
-0@@ -3317,6 +3317,7 @@ static void update_cpu_power(struct sched_domain *sd, int cpu)cpu_rq (cpu)->cpu_power = power; sdg->sgp->power = power; +atomic_set (&sdg->sgp->nr_busy_cpus, sdg->group_weight); }static void update_group_power (struct sched_domain *sd,int cpu)kernel/sched_fair.c static void update_group_power(struct sched_domain *sd, int cpu) · line 3344
Quoted 5 lines
kernel/sched_fair.c +1
-0@@ -3339,6 +3340,7 @@ static void update_group_power(struct sched_domain *sd, int cpu) }while (group != child->groups); sdg->sgp->power = power; +atomic_set (&sdg->sgp->nr_busy_cpus, sdg->group_weight); }So we run this rather frequently, and it will trample all over:
Quoted 5 lines
kernel/sched_fair.c static void nohz_balancer_kick(int cpu) · line 4416
Quoted 3 lines
kernel/sched_fair.c +3
-0+*/ +for_each_domain (cpu, sd) +atomic_dec (&sd->groups->sgp->nr_busy_cpus);because I cannot see any serialization between those sites.
That was an overlook from myside. I moved the initialization of this to init_sched_groups_power() now and there is no need to re-do this everytime we call the update_group_power().
Quoted 4 lines
Also, isn't it rather weird to just assume all cpus are busy in
update_group_power()? If you would actually set the right value inupdate_cpu_power()you could use a straight sum inupdate_group_power()and get a more or less accurate number out.
I will post an updated patch soon (once we complete the performance analysis of this patch with respect to other workloads) but the below hunk gives an idea of what I am planning to do now.
@@ -7369,6 +7384,7 @@ static void init_sched_groups_power(int cpu, struct sched_
return;
update_group_power(sd, cpu);+ atomic_set(&sg->sgp->nr_busy_cpus, sg->group_weight);
}
/*
thanks,
suresh