Skip to content

Commit 69e1e81

Browse files
Suresh SiddhaIngo Molnar
authored andcommitted
sched, nohz: Track nr_busy_cpus in the sched_group_power
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 idle, 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 state as the cpu enters and exits idle, the update of the stat during idle exit is delayed to the first timer tick that happens after the cpu becomes busy. This is done using NOHZ_IDLE flag in the struct rq's nohz_flags. Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20111202010832.555984323@sbsiddha-desk.sc.intel.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 1c792db commit 69e1e81

5 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,11 @@ extern int runqueue_is_locked(int cpu);
273273

274274
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
275275
extern void select_nohz_load_balancer(int stop_tick);
276+
extern void set_cpu_sd_state_idle(void);
276277
extern int get_nohz_timer_target(void);
277278
#else
278279
static inline void select_nohz_load_balancer(int stop_tick) { }
280+
static inline void set_cpu_sd_state_idle(void);
279281
#endif
280282

281283
/*
@@ -901,6 +903,10 @@ struct sched_group_power {
901903
* single CPU.
902904
*/
903905
unsigned int power, power_orig;
906+
/*
907+
* Number of busy cpus in this group.
908+
*/
909+
atomic_t nr_busy_cpus;
904910
};
905911

906912
struct sched_group {

‎kernel/sched/core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6024,6 +6024,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
60246024
return;
60256025

60266026
update_group_power(sd, cpu);
6027+
atomic_set(&sg->sgp->nr_busy_cpus, sg->group_weight);
60276028
}
60286029

60296030
int __weak arch_sd_sibling_asym_packing(void)

‎kernel/sched/fair.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,6 +4901,36 @@ static void nohz_balancer_kick(int cpu)
49014901
return;
49024902
}
49034903

4904+
static inline void set_cpu_sd_state_busy(void)
4905+
{
4906+
struct sched_domain *sd;
4907+
int cpu = smp_processor_id();
4908+
4909+
if (!test_bit(NOHZ_IDLE, nohz_flags(cpu)))
4910+
return;
4911+
clear_bit(NOHZ_IDLE, nohz_flags(cpu));
4912+
4913+
rcu_read_lock();
4914+
for_each_domain(cpu, sd)
4915+
atomic_inc(&sd->groups->sgp->nr_busy_cpus);
4916+
rcu_read_unlock();
4917+
}
4918+
4919+
void set_cpu_sd_state_idle(void)
4920+
{
4921+
struct sched_domain *sd;
4922+
int cpu = smp_processor_id();
4923+
4924+
if (test_bit(NOHZ_IDLE, nohz_flags(cpu)))
4925+
return;
4926+
set_bit(NOHZ_IDLE, nohz_flags(cpu));
4927+
4928+
rcu_read_lock();
4929+
for_each_domain(cpu, sd)
4930+
atomic_dec(&sd->groups->sgp->nr_busy_cpus);
4931+
rcu_read_unlock();
4932+
}
4933+
49044934
/*
49054935
* This routine will try to nominate the ilb (idle load balancing)
49064936
* owner among the cpus whose ticks are stopped. ilb owner will do the idle
@@ -5135,6 +5165,7 @@ static inline int nohz_kick_needed(struct rq *rq, int cpu)
51355165
* We may be recently in ticked or tickless idle mode. At the first
51365166
* busy tick after returning from idle, we will update the busy stats.
51375167
*/
5168+
set_cpu_sd_state_busy();
51385169
if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu))))
51395170
clear_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
51405171

‎kernel/sched/sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ extern void account_cfs_bandwidth_used(int enabled, int was_enabled);
10691069
enum rq_nohz_flag_bits {
10701070
NOHZ_TICK_STOPPED,
10711071
NOHZ_BALANCE_KICK,
1072+
NOHZ_IDLE,
10721073
};
10731074

10741075
#define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags)

‎kernel/time/tick-sched.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ void tick_nohz_stop_sched_tick(int inidle)
296296
cpu = smp_processor_id();
297297
ts = &per_cpu(tick_cpu_sched, cpu);
298298

299+
/*
300+
* Update the idle state in the scheduler domain hierarchy
301+
* when tick_nohz_stop_sched_tick() is called from the idle loop.
302+
* State will be updated to busy during the first busy tick after
303+
* exiting idle.
304+
*/
305+
if (inidle)
306+
set_cpu_sd_state_idle();
307+
299308
/*
300309
* Call to tick_nohz_start_idle stops the last_update_time from being
301310
* updated. Thus, it must not be called in the event we are called from

0 commit comments

Comments
 (0)