[PATCH DEBUG 2/2] sched: Add a stat for idle cpu selection race window.

From: Atish Patra
Date: Tue Oct 31 2017 - 01:29:57 EST


This is ** Debug ** only patch not intended for merging.

A new stat in schedstat is added that represents number of
times cpu was already claimed during wakeup while some other
cpu tries to schedule tasks on it again. It helps to verify
if the concerned issue is present in a specific becnhmark.

Tested-by: Joel Fernandes <joelaf@xxxxxxxxxx>
Signed-off-by: Atish Patra <atish.patra@xxxxxxxxxx>
---
kernel/sched/core.c | 4 +++-
kernel/sched/sched.h | 1 +
kernel/sched/stats.c | 5 +++--
3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d9d501c..d12b8c8 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3918,8 +3918,10 @@ int idle_cpu(int cpu)
return 0;
#endif

- if (per_cpu(claim_wakeup, cpu))
+ if (per_cpu(claim_wakeup, cpu)) {
+ schedstat_inc(rq->ttwu_claimed);
return 0;
+ }

return 1;
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 5f70b98..8f3047c 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -801,6 +801,7 @@ struct rq {
/* try_to_wake_up() stats */
unsigned int ttwu_count;
unsigned int ttwu_local;
+ unsigned int ttwu_claimed;
#endif

#ifdef CONFIG_SMP
diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c
index 87e2c9f..2290aa7 100644
--- a/kernel/sched/stats.c
+++ b/kernel/sched/stats.c
@@ -30,12 +30,13 @@ static int show_schedstat(struct seq_file *seq, void *v)

/* runqueue-specific stats */
seq_printf(seq,
- "cpu%d %u 0 %u %u %u %u %llu %llu %lu",
+ "cpu%d %u 0 %u %u %u %u %llu %llu %lu %u",
cpu, rq->yld_count,
rq->sched_count, rq->sched_goidle,
rq->ttwu_count, rq->ttwu_local,
rq->rq_cpu_time,
- rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount);
+ rq->rq_sched_info.run_delay,
+ rq->rq_sched_info.pcount, rq->ttwu_claimed);

seq_printf(seq, "\n");

--
2.7.4