Skip to content

Commit 10dafae

Browse files
committed
sched: Report the different kinds of imbalances in /proc/schedstat
JIRA: https://issues.redhat.com/browse/RHEL-23495 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 20a9e21 commit 10dafae

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
@@ -11219,6 +11219,28 @@ static int should_we_balance(struct lb_env *env)
1121911219
return group_balance_cpu(sg) == env->dst_cpu;
1122011220
}
1122111221

11222+
static void update_lb_imbalance_stat(struct lb_env *env, struct sched_domain *sd,
11223+
enum cpu_idle_type idle)
11224+
{
11225+
if (!schedstat_enabled())
11226+
return;
11227+
11228+
switch (env->migration_type) {
11229+
case migrate_load:
11230+
__schedstat_add(sd->lb_imbalance_load[idle], env->imbalance);
11231+
break;
11232+
case migrate_util:
11233+
__schedstat_add(sd->lb_imbalance_util[idle], env->imbalance);
11234+
break;
11235+
case migrate_task:
11236+
__schedstat_add(sd->lb_imbalance_task[idle], env->imbalance);
11237+
break;
11238+
case migrate_misfit:
11239+
__schedstat_add(sd->lb_imbalance_misfit[idle], env->imbalance);
11240+
break;
11241+
}
11242+
}
11243+
1122211244
/*
1122311245
* Check this_cpu to ensure it is balanced within domain. Attempt to move
1122411246
* tasks if there is an imbalance.
@@ -11269,7 +11291,7 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
1126911291

1127011292
WARN_ON_ONCE(busiest == env.dst_rq);
1127111293

11272-
schedstat_add(sd->lb_imbalance[idle], env.imbalance);
11294+
update_lb_imbalance_stat(&env, sd, idle);
1127311295

1127411296
env.src_cpu = busiest->cpu;
1127511297
env.src_rq = busiest;

kernel/sched/stats.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ static int show_schedstat(struct seq_file *seq, void *v)
151151
seq_printf(seq, "domain%d %*pb", dcount++,
152152
cpumask_pr_args(sched_domain_span(sd)));
153153
for (itype = 0; itype < CPU_MAX_IDLE_TYPES; itype++) {
154-
seq_printf(seq, " %u %u %u %u %u %u %u %u",
154+
seq_printf(seq, " %u %u %u %u %u %u %u %u %u %u %u",
155155
sd->lb_count[itype],
156156
sd->lb_balanced[itype],
157157
sd->lb_failed[itype],
158-
sd->lb_imbalance[itype],
158+
sd->lb_imbalance_load[itype],
159+
sd->lb_imbalance_util[itype],
160+
sd->lb_imbalance_task[itype],
161+
sd->lb_imbalance_misfit[itype],
159162
sd->lb_gained[itype],
160163
sd->lb_hot_gained[itype],
161164
sd->lb_nobusyq[itype],

0 commit comments

Comments
 (0)