[PATCH] trace/sched: add tgid for sched_wakeup_template

From: Tio Zhang
Date: Wed Mar 27 2024 - 04:55:26 EST


By doing this, we are able to filter tasks by tgid while we are
tracing wakeup events by ebpf or other methods.

For example, when we care about tracing a user space process (which has
uncertain number of LWPs, i.e, pids) to monitor its wakeup latency,
without tgid available in sched_wakeup tracepoints, we would struggle
finding out all pids to trace, or we could use kprobe to achieve tgid
tracing, which is less accurate and much less efficient than using
tracepoint.

Signed-off-by: Tio Zhang <tiozhang@xxxxxxxxxxxxxx>
Signed-off-by: Dylane Chen <dylanechen@xxxxxxxxxxxxxx>
---
include/trace/events/sched.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index dbb01b4b7451..ea7e525649e5 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -149,6 +149,7 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
__field( pid_t, pid )
__field( int, prio )
__field( int, target_cpu )
+ __field( pid_t, tgid )
),

TP_fast_assign(
@@ -156,11 +157,12 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
__entry->pid = p->pid;
__entry->prio = p->prio; /* XXX SCHED_DEADLINE */
__entry->target_cpu = task_cpu(p);
+ __entry->tgid = p->tgid;
),

- TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
+ TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d tgid=%d",
__entry->comm, __entry->pid, __entry->prio,
- __entry->target_cpu)
+ __entry->target_cpu, __entry->tgid)
);

/*
--
2.17.1