sched: Show idlecore update stats

From: Srikar Dronamraju
Date: Thu May 06 2021 - 10:03:51 EST


Not for inclusion; Just for demonstration.

nr_idlecore_write: idlecore set unconditionally.
nr_idlecore_select; wakeup found an idle core when the current CPU was
busy.

nr_idlecore updates = nr_idlecore_write + nr_idlecore_select

Not-Signed-off-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
---
kernel/sched/debug.c | 2 ++
kernel/sched/fair.c | 12 +++++++++---
kernel/sched/sched.h | 2 ++
3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 486f403a778b..b50e0c5acf46 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -715,6 +715,8 @@ do { \
P(ttwu_count);
P(ttwu_local);
}
+ P(nr_idlecore_write);
+ P(nr_idlecore_select);
#undef P

spin_lock_irqsave(&sched_debug_lock, flags);
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 83104d3bd0f9..4ef0b7d959d5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5890,16 +5890,20 @@ static int wake_affine_idler_llc(struct task_struct *p, int pref_cpu, int try_cp

idle_core = READ_ONCE(pref_sds->idle_core);
if (idle_core > -1 && cpumask_test_cpu(idle_core, p->cpus_ptr) &&
- test_reset_idle_core(pref_sds, idle_core))
+ test_reset_idle_core(pref_sds, idle_core)) {
+ schedstat_inc(cpu_rq(idle_core)->nr_idlecore_select);
return idle_core;
+ }

if (available_idle_cpu(try_cpu) || sched_idle_cpu(try_cpu))
return try_cpu;

idle_core = READ_ONCE(try_sds->idle_core);
if (idle_core > -1 && cpumask_test_cpu(idle_core, p->cpus_ptr) &&
- test_reset_idle_core(try_sds, idle_core))
+ test_reset_idle_core(try_sds, idle_core)) {
+ schedstat_inc(cpu_rq(idle_core)->nr_idlecore_select);
return idle_core;
+ }

pnr_busy = atomic_read(&pref_sds->nr_busy_cpus);
tnr_busy = atomic_read(&try_sds->nr_busy_cpus);
@@ -6082,8 +6086,10 @@ static inline void set_idle_core(int cpu, int val)
struct sched_domain_shared *sds;

sds = rcu_dereference(per_cpu(sd_llc_shared, cpu));
- if (sds)
+ if (sds) {
WRITE_ONCE(sds->idle_core, val);
+ schedstat_inc(cpu_rq(cpu)->nr_idlecore_write);
+ }
}

static inline int get_idle_core(int cpu, int def)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index baf8d9a4cb26..06d81a9e0a48 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1060,6 +1060,8 @@ struct rq {
#ifdef CONFIG_SMP
unsigned int nr_pinned;
#endif
+ unsigned int nr_idlecore_write;
+ unsigned int nr_idlecore_select;
unsigned int push_busy;
struct cpu_stop_work push_work;
};
--
2.25.1