On Wed, Jul 30, 2025 at 06:18:45PM +0200, Gabriele Monaco wrote:
> Well, thinking about it again, these tracepoints might simplify things
> considerably when tasks change policy..
> 
> Syscalls may fail, for that you could register to sys_exit and check
> the return value, but at that point the policy changed already, so you
> cannot tell if it's a relevant event or not (e.g. same policy).
> Also sched_setscheduler_nocheck would be out of the picture here, not
> sure how recurrent that is though (and might not matter if you only
> focus on userspace tasks).
> 
> If you go down the route of adding tracepoints, why not have other
> classes benefit too? I believe calling them from the enqueue_task /
> dequeue_task in sched/core.c would allow you to easily filter out by
> policy anyway (haven't tested).

Something like the untested patch below?

Will you have a use case for it too? Then I will try to accommodate your
use case, otherwise I will do just enough for my case.

Nam

diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index c38f12f7f903..b50668052f99 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -906,6 +906,14 @@ DECLARE_TRACE(dequeue_task_rt,
        TP_PROTO(int cpu, struct task_struct *task),
        TP_ARGS(cpu, task));
 
+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..2af90532982a 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);
 
@@ -2103,6 +2105,8 @@ void enqueue_task(struct rq *rq, struct task_struct *p, 
int flags)
  */
 inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
 {
+       trace_dequeue_task_tp(rq->cpu, p);
+
        if (sched_core_enabled(rq))
                sched_core_dequeue(rq, p, flags);
 

Reply via email to