Add scheduler stats to record number of times preemption delay was granted
or denied.
Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
---
include/linux/sched.h | 8 ++++++++
kernel/sched/core.c | 12 ++++++++++++
kernel/sched/debug.c | 4 ++++
mm/task_shared.c | 2 ++
4 files changed, 26 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index b53e7a878a01..e3f5760632f4 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -327,6 +327,10 @@ extern void io_schedule_finish(int token);
extern long io_schedule_timeout(long timeout);
extern void io_schedule(void);
extern void hrtick_local_start(u64 delay);
+#ifdef CONFIG_TASKSHARED
+extern void update_stat_preempt_delayed(struct task_struct *t);
+extern void update_stat_preempt_denied(struct task_struct *t);
+#endif
/**
* struct prev_cputime - snapshot of system and user cputime
@@ -532,6 +536,10 @@ struct sched_statistics {
u64 nr_wakeups_affine_attempts;
u64 nr_wakeups_passive;
u64 nr_wakeups_idle;
+#ifdef CONFIG_TASKSHARED
+ u64 nr_preempt_delay_granted;
+ u64 nr_preempt_delay_denied;
+#endif
#ifdef CONFIG_SCHED_CORE
u64 core_forceidle_sum;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 713c43491403..54fa4b68adaf 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -916,6 +916,18 @@ void hrtick_local_start(u64 delay)
rq_unlock(rq, &rf);
}
+#ifdef CONFIG_TASKSHARED
+void update_stat_preempt_delayed(struct task_struct *t)
+{
+ schedstat_inc(t->stats.nr_preempt_delay_granted);
+}
+
+void update_stat_preempt_denied(struct task_struct *t)
+{
+ schedstat_inc(t->stats.nr_preempt_delay_denied);
+}
+#endif
+
static void hrtick_rq_init(struct rq *rq)
{
#ifdef CONFIG_SMP
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 4a9fbbe843c0..ace7856f13c3 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -1215,6 +1215,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
P_SCHEDSTAT(nr_wakeups_affine_attempts);
P_SCHEDSTAT(nr_wakeups_passive);
P_SCHEDSTAT(nr_wakeups_idle);
+#ifdef CONFIG_TASKSHARED
+ P_SCHEDSTAT(nr_preempt_delay_granted);
+ P_SCHEDSTAT(nr_preempt_delay_denied);
+#endif
avg_atom = p->se.sum_exec_runtime;
if (nr_switches)
diff --git a/mm/task_shared.c b/mm/task_shared.c
index 5b8a068a6b44..35aecc718c8e 100644
--- a/mm/task_shared.c
+++ b/mm/task_shared.c
@@ -285,6 +285,7 @@ bool taskshrd_delay_resched(void)
/* not granted */
shrdp->kaddr->ts.sched_delay
= TASK_PREEMPT_DELAY_DENIED;
+ update_stat_preempt_denied(t);
}
return false;
}
@@ -295,6 +296,7 @@ bool taskshrd_delay_resched(void)
/* granted */
shrdp->kaddr->ts.sched_delay = TASK_PREEMPT_DELAY_GRANTED;
t->taskshrd_sched_delay = 1;
+ update_stat_preempt_delayed(t);
return true;
}
--
2.43.5