Connect to the sched_update_prio tracepoint
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 13 May 2016 18:59:56 +0000 (14:59 -0400)
committerJulien Desfossez <jdesfossez@efficios.com>
Mon, 19 Sep 2016 16:54:44 +0000 (12:54 -0400)
This tracepoint allows to keep track of all explicit priority changes of a
task. It outputs the scheduling policy, the nice value, the rt_priority and the
deadline-related attributes (dl_runtime, dl_deadline and dl_period).

It is emitted in the code path of the sched_setscheduler, sched_setattr,
sched_setparam, and nice system calls.

This allows the analysis of real-time scheduling delays based on the configured
scheduling priorities and policies, which cannot be performed with the current
instrumentation in sched_switch. Also, instead of exposing the internal kernel
prio field, this tracepoint only outputs the user-visible priority attributes.

The effective priority of running threads can also be temporarily changed in
the PI code, but a dedicated tracepoint is already in place to cover this case.

Here are a few output examples:
After fork of a normal task:

renice -n 10 of a normal task:
sched_update_prio: { cpu_id = 4 }, { comm = "sleep", tid = 8149, prio = 30,
policy = ( "SCHED_NORMAL" : container = 0 ), nice = 10, rt_priority = 0,
dl_runtime = 0, dl_deadline = 0, dl_period = 0 }

SCHED_FIFO 60:
sched_update_prio: { cpu_id = 6 }, { comm = "chrt", tid = 7857, prio = -61,
policy = ( "SCHED_FIFO" : container = 1 ), nice = 0, rt_priority = 60,
dl_runtime = 0, dl_deadline = 0, dl_period = 0 }

SCHED_RR 60:
sched_update_prio: { cpu_id = 3 }, { comm = "chrt", tid = 8157, prio = -61,
policy = ( "SCHED_RR" : container = 2 ), nice = 0, rt_priority = 60, dl_runtime
= 0, dl_deadline = 0, dl_period = 0 }

SCHED_DEADLINE:
sched_update_prio: { cpu_id = 7 }, { comm = "b", tid = 8162, prio = -101,
policy = ( "SCHED_DEADLINE" : container = 6 ), nice = 0, rt_priority = 0,
dl_runtime = 10000000, dl_deadline = 30000000, dl_period = 30000000 }

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
instrumentation/events/lttng-module/sched.h
instrumentation/events/mainline/sched.h

index e5066afe3b55049a422afc7b944c601cdc61f9d6..9eb41183b6223b73e3bc528979a2f3c14a24693f 100644 (file)
@@ -113,6 +113,19 @@ static inline long __trace_sched_switch_state(struct task_struct *p)
 
 #endif /* _TRACE_SCHED_DEF_ */
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0))
+LTTNG_TRACEPOINT_ENUM(lttng_sched_policy,
+       TP_ENUM_VALUES(
+               ctf_enum_value("SCHED_NORMAL", SCHED_NORMAL)
+               ctf_enum_value("SCHED_FIFO", SCHED_FIFO)
+               ctf_enum_value("SCHED_RR", SCHED_RR)
+               ctf_enum_value("SCHED_BATCH", SCHED_BATCH)
+               ctf_enum_value("SCHED_IDLE", SCHED_IDLE)
+               ctf_enum_value("SCHED_DEADLINE", SCHED_DEADLINE)
+       )
+)
+#endif
+
 /*
  * Tracepoint for calling kthread_stop, performed to end a kthread:
  */
@@ -560,6 +573,30 @@ LTTNG_TRACEPOINT_EVENT(sched_pi_setprio,
 )
 #endif
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0))
+/*
+ * Tracepoint for priority changes of a task.
+ */
+LTTNG_TRACEPOINT_EVENT(sched_update_prio,
+
+       TP_PROTO(struct task_struct *tsk),
+
+       TP_ARGS(tsk),
+
+       TP_FIELDS(
+               ctf_array_text(char, comm, tsk->comm, TASK_COMM_LEN)
+               ctf_integer(pid_t, tid, tsk->pid)
+               ctf_integer(int, prio, tsk->prio - MAX_RT_PRIO)
+               ctf_enum(lttng_sched_policy, unsigned int, policy, tsk->policy)
+               ctf_integer(int, nice, task_nice(tsk))
+               ctf_integer(unsigned int, rt_priority, tsk->rt_priority)
+               ctf_integer(u64, dl_runtime, tsk->dl.dl_runtime)
+               ctf_integer(u64, dl_deadline, tsk->dl.dl_deadline)
+               ctf_integer(u64, dl_period, tsk->dl.dl_period)
+       )
+)
+#endif
+
 #endif /* LTTNG_TRACE_SCHED_H */
 
 /* This part must be outside protection */
index ea7a2035456d4f913e15b9997696ab5ca4934ad1..882d67bef41fc38dbb12263a3d5d9719e678336b 100644 (file)
@@ -426,6 +426,34 @@ TRACE_EVENT(sched_pi_setprio,
                        __entry->oldprio, __entry->newprio)
 );
 
+/*
+ * Tracepoint for priority changes of a task.
+ */
+TRACE_EVENT(sched_set_prio,
+
+       TP_PROTO(struct task_struct *tsk, int newprio),
+
+       TP_ARGS(tsk, newprio),
+
+       TP_STRUCT__entry(
+               __array( char,  comm,   TASK_COMM_LEN   )
+               __field( pid_t, pid                     )
+               __field( int,   oldprio                 )
+               __field( int,   newprio                 )
+       ),
+
+       TP_fast_assign(
+               memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+               __entry->pid            = tsk->pid;
+               __entry->oldprio        = tsk->prio;
+               __entry->newprio        = newprio;
+       ),
+
+       TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
+                       __entry->comm, __entry->pid,
+                       __entry->oldprio, __entry->newprio)
+);
+
 #endif /* _TRACE_SCHED_H */
 
 /* This part must be outside protection */
This page took 0.026644 seconds and 5 git commands to generate.