Skip to content

Commit 3905cb6

Browse files
committed
sched: Report the different kinds of imbalances in /proc/schedstat
JIRA: https://issues.redhat.com/browse/RHEL-24185 commit 3b2a793 Author: Swapnil Sapkal <swapnil.sapkal@amd.com> Date: Fri Dec 20 06:32:21 2024 +0000 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 <swapnil.sapkal@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> Link: https://lore.kernel.org/r/20241220063224.17767-4-swapnil.sapkal@amd.com Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent e50f97d commit 3905cb6

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
@@ -11718,6 +11718,28 @@ static int should_we_balance(struct lb_env *env)
1171811718
return group_balance_cpu(sg) == env->dst_cpu;
1171911719
}
1172011720

11721+
static void update_lb_imbalance_stat(struct lb_env *env, struct sched_domain *sd,
11722+
enum cpu_idle_type idle)
11723+
{
11724+
if (!schedstat_enabled())
11725+
return;
11726+
11727+
switch (env->migration_type) {
11728+
case migrate_load:
11729+
__schedstat_add(sd->lb_imbalance_load[idle], env->imbalance);
11730+
break;
11731+
case migrate_util:
11732+
__schedstat_add(sd->lb_imbalance_util[idle], env->imbalance);
11733+
break;
11734+
case migrate_task:
11735+
__schedstat_add(sd->lb_imbalance_task[idle], env->imbalance);
11736+
break;
11737+
case migrate_misfit:
11738+
__schedstat_add(sd->lb_imbalance_misfit[idle], env->imbalance);
11739+
break;
11740+
}
11741+
}
11742+
1172111743
/*
1172211744
* Check this_cpu to ensure it is balanced within domain. Attempt to move
1172311745
* tasks if there is an imbalance.
@@ -11768,7 +11790,7 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
1176811790

1176911791
WARN_ON_ONCE(busiest == env.dst_rq);
1177011792

11771-
schedstat_add(sd->lb_imbalance[idle], env.imbalance);
11793+
update_lb_imbalance_stat(&env, sd, idle);
1177211794

1177311795
env.src_cpu = busiest->cpu;
1177411796
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)