Add trace points into enqueue_task() and dequeue_task(). They are useful to
implement RV monitor which validates RT scheduling.

Signed-off-by: Nam Cao <[email protected]>
---
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Vincent Guittot <[email protected]>
Cc: Dietmar Eggemann <[email protected]>
Cc: Ben Segall <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Valentin Schneider <[email protected]>
Cc: K Prateek Nayak <[email protected]>
---
v2: Move the tracepoints to cover all task enqueue/dequeue, not just RT
---
 include/trace/events/sched.h | 13 +++++++++++++
 kernel/sched/core.c          |  8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index c08893bde255..ec38928e61e7 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -898,6 +898,19 @@ DECLARE_TRACE(sched_set_need_resched,
        TP_PROTO(struct task_struct *tsk, int cpu, int tif),
        TP_ARGS(tsk, cpu, tif));
 
+/*
+ * The two trace points below may not work as expected for fair tasks due
+ * to delayed dequeue. See:
+ * https://lore.kernel.org/lkml/[email protected]/
+ */
+DECLARE_TRACE(enqueue_task,
+       TP_PROTO(int cpu, struct task_struct *task),
+       TP_ARGS(cpu, task));
+
+DECLARE_TRACE(dequeue_task,
+       TP_PROTO(int cpu, struct task_struct *task),
+       TP_ARGS(cpu, task));
+
 #endif /* _TRACE_SCHED_H */
 
 /* This part must be outside protection */
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b485e0639616..553c08a63395 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2077,6 +2077,8 @@ unsigned long get_wchan(struct task_struct *p)
 
 void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
 {
+       trace_enqueue_task_tp(rq->cpu, p);
+
        if (!(flags & ENQUEUE_NOCLOCK))
                update_rq_clock(rq);
 
@@ -2119,7 +2121,11 @@ inline bool dequeue_task(struct rq *rq, struct 
task_struct *p, int flags)
         * and mark the task ->sched_delayed.
         */
        uclamp_rq_dec(rq, p);
-       return p->sched_class->dequeue_task(rq, p, flags);
+       if (p->sched_class->dequeue_task(rq, p, flags)) {
+               trace_dequeue_task_tp(rq->cpu, p);
+               return true;
+       }
+       return false;
 }
 
 void activate_task(struct rq *rq, struct task_struct *p, int flags)
-- 
2.39.5


Reply via email to