Skip to content

Commit 3b2a793

Browse files
SSapkalPeter Zijlstra
authored andcommitted
sched: Report the different kinds of imbalances in /proc/schedstat
In /proc/schedstat, lb_imbalance reports the sum of imbalances discovered in sched domains with each call to sched_balance_rq(), which is not very useful because lb_imbalance does not mention whether the imbalance is due to load, utilization, nr_tasks or misfit_tasks. Remove this field from /proc/schedstat. Currently there is no field in /proc/schedstat to report different types of imbalances. Introduce new fields in /proc/schedstat to report the total imbalances in load, utilization, nr_tasks or misfit_tasks. Added fields to /proc/schedstat: - lb_imbalance_load: Total imbalance due to load. - lb_imbalance_util: Total imbalance due to utilization. - lb_imbalance_task: Total imbalance due to number of tasks. - lb_imbalance_misfit: Total imbalance due to misfit tasks. Signed-off-by: Swapnil Sapkal <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Shrikanth Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c3856c9 commit 3b2a793

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

include/linux/sched/topology.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ struct sched_domain {
114114
unsigned int lb_count[CPU_MAX_IDLE_TYPES];
115115
unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
116116
unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
117-
unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
117+
unsigned int lb_imbalance_load[CPU_MAX_IDLE_TYPES];
118+
unsigned int lb_imbalance_util[CPU_MAX_IDLE_TYPES];
119+
unsigned int lb_imbalance_task[CPU_MAX_IDLE_TYPES];
120+
unsigned int lb_imbalance_misfit[CPU_MAX_IDLE_TYPES];
118121
unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
119122
unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
120123
unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];

kernel/sched/fair.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11705,6 +11705,28 @@ static int should_we_balance(struct lb_env *env)
1170511705
return group_balance_cpu(sg) == env->dst_cpu;
1170611706
}
1170711707

11708+
static void update_lb_imbalance_stat(struct lb_env *env, struct sched_domain *sd,
11709+
enum cpu_idle_type idle)
11710+
{
11711+
if (!schedstat_enabled())
11712+
return;
11713+
11714+
switch (env->migration_type) {
11715+
case migrate_load:
11716+
__schedstat_add(sd->lb_imbalance_load[idle], env->imbalance);
11717+
break;
11718+
case migrate_util:
11719+
__schedstat_add(sd->lb_imbalance_util[idle], env->imbalance);
11720+
break;
11721+
case migrate_task:
11722+
__schedstat_add(sd->lb_imbalance_task[idle], env->imbalance);
11723+
break;
11724+
case migrate_misfit:
11725+
__schedstat_add(sd->lb_imbalance_misfit[idle], env->imbalance);
11726+
break;
11727+
}
11728+
}
11729+
1170811730
/*
1170911731
* Check this_cpu to ensure it is balanced within domain. Attempt to move
1171011732
* tasks if there is an imbalance.
@@ -11755,7 +11777,7 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
1175511777

1175611778
WARN_ON_ONCE(busiest == env.dst_rq);
1175711779

11758-
schedstat_add(sd->lb_imbalance[idle], env.imbalance);
11780+
update_lb_imbalance_stat(&env, sd, idle);
1175911781

1176011782
env.src_cpu = busiest->cpu;
1176111783
env.src_rq = busiest;

kernel/sched/stats.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ static int show_schedstat(struct seq_file *seq, void *v)
141141
seq_printf(seq, "domain%d %*pb", dcount++,
142142
cpumask_pr_args(sched_domain_span(sd)));
143143
for (itype = 0; itype < CPU_MAX_IDLE_TYPES; itype++) {
144-
seq_printf(seq, " %u %u %u %u %u %u %u %u",
144+
seq_printf(seq, " %u %u %u %u %u %u %u %u %u %u %u",
145145
sd->lb_count[itype],
146146
sd->lb_balanced[itype],
147147
sd->lb_failed[itype],
148-
sd->lb_imbalance[itype],
148+
sd->lb_imbalance_load[itype],
149+
sd->lb_imbalance_util[itype],
150+
sd->lb_imbalance_task[itype],
151+
sd->lb_imbalance_misfit[itype],
149152
sd->lb_gained[itype],
150153
sd->lb_hot_gained[itype],
151154
sd->lb_nobusyq[itype],

0 commit comments

Comments
 (0)