]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched: Report the different kinds of imbalances in /proc/schedstat
authorSwapnil Sapkal <swapnil.sapkal@amd.com>
Fri, 20 Dec 2024 06:32:21 +0000 (06:32 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 20 Dec 2024 14:31:17 +0000 (15:31 +0100)
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
include/linux/sched/topology.h
kernel/sched/fair.c
kernel/sched/stats.c

index 4237daa5ac7a259786a29a42fa60a3b6f7a8dba6..76a662e1ec243bbda00a6e3381cbb40d31bedfda 100644 (file)
@@ -114,7 +114,10 @@ struct sched_domain {
        unsigned int lb_count[CPU_MAX_IDLE_TYPES];
        unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
        unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
-       unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
+       unsigned int lb_imbalance_load[CPU_MAX_IDLE_TYPES];
+       unsigned int lb_imbalance_util[CPU_MAX_IDLE_TYPES];
+       unsigned int lb_imbalance_task[CPU_MAX_IDLE_TYPES];
+       unsigned int lb_imbalance_misfit[CPU_MAX_IDLE_TYPES];
        unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
        unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
        unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
index e5c0c61909b7fd9c0b73e27ebf5b7cd6d3b9dad5..b3418b5d484f8b8479b618bae1e7ba09c88cd57b 100644 (file)
@@ -11705,6 +11705,28 @@ static int should_we_balance(struct lb_env *env)
        return group_balance_cpu(sg) == env->dst_cpu;
 }
 
+static void update_lb_imbalance_stat(struct lb_env *env, struct sched_domain *sd,
+                                    enum cpu_idle_type idle)
+{
+       if (!schedstat_enabled())
+               return;
+
+       switch (env->migration_type) {
+       case migrate_load:
+               __schedstat_add(sd->lb_imbalance_load[idle], env->imbalance);
+               break;
+       case migrate_util:
+               __schedstat_add(sd->lb_imbalance_util[idle], env->imbalance);
+               break;
+       case migrate_task:
+               __schedstat_add(sd->lb_imbalance_task[idle], env->imbalance);
+               break;
+       case migrate_misfit:
+               __schedstat_add(sd->lb_imbalance_misfit[idle], env->imbalance);
+               break;
+       }
+}
+
 /*
  * Check this_cpu to ensure it is balanced within domain. Attempt to move
  * tasks if there is an imbalance.
@@ -11755,7 +11777,7 @@ redo:
 
        WARN_ON_ONCE(busiest == env.dst_rq);
 
-       schedstat_add(sd->lb_imbalance[idle], env.imbalance);
+       update_lb_imbalance_stat(&env, sd, idle);
 
        env.src_cpu = busiest->cpu;
        env.src_rq = busiest;
index eb0cdcd4d9212e3a5ce1696f4257f93c66dacfb2..802bd9398a2ef9acb7af29f52d2ceafe35061e95 100644 (file)
@@ -141,11 +141,14 @@ static int show_schedstat(struct seq_file *seq, void *v)
                        seq_printf(seq, "domain%d %*pb", dcount++,
                                   cpumask_pr_args(sched_domain_span(sd)));
                        for (itype = 0; itype < CPU_MAX_IDLE_TYPES; itype++) {
-                               seq_printf(seq, " %u %u %u %u %u %u %u %u",
+                               seq_printf(seq, " %u %u %u %u %u %u %u %u %u %u %u",
                                    sd->lb_count[itype],
                                    sd->lb_balanced[itype],
                                    sd->lb_failed[itype],
-                                   sd->lb_imbalance[itype],
+                                   sd->lb_imbalance_load[itype],
+                                   sd->lb_imbalance_util[itype],
+                                   sd->lb_imbalance_task[itype],
+                                   sd->lb_imbalance_misfit[itype],
                                    sd->lb_gained[itype],
                                    sd->lb_hot_gained[itype],
                                    sd->lb_nobusyq[itype],