Skip to contentSkip to conversation

sched/debug: Add tracepoint for RT throttling

PATCH In review Benjamin Bouvier 3 participants 3 messages Dec 14, 2018 – Dec 15, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/debug: Add tracepoint for RT throttling

As there is currently no information on which RT task is throttled, add a new tracepoint for debug purpose. By the way improve printk debugging message by adding task name, pid and cpu for which the throttle has been executed.

---
 include/trace/events/sched.h | 27 +++++++++++++++++++++++++++
 kernel/sched/rt.c            |  6 +++++-
 2 files changed, 32 insertions(+), 1 deletion(-)
include/trace/events/sched.h +27 -0
index 9a4bdfadab07..09d3f7566f0a 100644
@@ -587,6 +587,33 @@ TRACE_EVENT(sched_wake_idle_without_ipi,
 
 	TP_printk("cpu=%d", __entry->cpu)
 );
+
+/*
+ * Tracepoint for RT throttling task.
+ */
+TRACE_EVENT(sched_rt_throttling,
+
+	TP_PROTO(struct task_struct *tsk, int cpu),
+
+	TP_ARGS(tsk, cpu),
+
+	TP_STRUCT__entry(
+		__array(char,	comm,	TASK_COMM_LEN)
+		__field(pid_t,	pid)
+		__field(int,	cpu)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+		__entry->pid	= tsk->pid;
+		__entry->cpu	= cpu;
+	),
+
+	TP_printk("comm=%s pid=%d cpu=%d",
+			__entry->comm, __entry->pid,
+			__entry->cpu)
+);
+
 #endif /* _TRACE_SCHED_H */
 
 /* This part must be outside protection */
kernel/sched/rt.c +5 -1
index a21ea6021929..1a0ee91c9e16 100644
@@ -6,6 +6,7 @@
 #include "sched.h"
 
 #include "pelt.h"
+#include <trace/events/sched.h>
 
 int sched_rr_timeslice = RR_TIMESLICE;
 int sysctl_sched_rr_timeslice = (MSEC_PER_SEC / HZ) * RR_TIMESLICE;
@@ -928,7 +929,10 @@ static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
 		 */
 		if (likely(rt_b->rt_runtime)) {
 			rt_rq->rt_throttled = 1;
-			printk_deferred_once("sched: RT throttling activated\n");
+			printk_deferred_once(
+				"sched: RT throttling activated for task pid %d (%s) on cpu:%d\n",
+				rt_rq->rq->curr->pid, rt_rq->rq->curr->comm, rt_rq->rq->cpu);
+			trace_sched_rt_throttling(rt_rq->rq->curr, rt_rq->rq->cpu);
 		} else {
 			/*
 			 * In case we did anyway, make it go away,
Signature · 1 line
2.10.2
#1 lore raw
Quoted 4 lines · Benjamin Bouvier

As there is currently no information on which RT task is throttled, add a new tracepoint for debug purpose. By the way improve printk debugging message by adding task name, pid and cpu for which the throttle has been executed.

Throttling is for _all_ RT class applications. The task you print might be innocent and getting the blame. The interesting part is to see all the RT tasks (not sure about DL) since the last time, the timer was started on the CPU.

Sebastian

#2 lore raw
In reply to Benjamin Bouvier
Thank you for the patch! Yet something to improve:

Hi Benjamin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.20-rc6 next-20181214]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Benjamin-Bouvier/sched-debug-Add-tracepoint-for-RT-throttling/20181216-050740
config: x86_64-randconfig-x001-201850 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

In file included from include/linux/kernel.h:14:0,

                    from arch/x86/include/asm/percpu.h:45,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/sched.h:12,
                    from kernel//sched/sched.h:5,
                    from kernel//sched/rt.c:6:
   kernel//sched/rt.c: In function 'sched_rt_runtime_exceeded':
>> kernel//sched/rt.c:934:59: error: 'struct rq' has no member named 'cpu'
        rt_rq->rq->curr->pid, rt_rq->rq->curr->comm, rt_rq->rq->cpu);
                                                              ^
   include/linux/printk.h:372:26: note: in definition of macro 'printk_deferred_once'
      printk_deferred(fmt, ##__VA_ARGS__);  \
                             ^~~~~~~~~~~
   kernel//sched/rt.c:935:56: error: 'struct rq' has no member named 'cpu'
       trace_sched_rt_throttling(rt_rq->rq->curr, rt_rq->rq->cpu);
                                                           ^~

vim +934 kernel//sched/rt.c

907
908 static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
909 {
910 u64 runtime = sched_rt_runtime(rt_rq);
911
912 if (rt_rq->rt_throttled)
913 return rt_rq_throttled(rt_rq);
914
915 if (runtime >= sched_rt_period(rt_rq))
916 return 0;
917
918 balance_runtime(rt_rq);
919 runtime = sched_rt_runtime(rt_rq);
920 if (runtime == RUNTIME_INF)
921 return 0;
922
923 if (rt_rq->rt_time > runtime) {
924 struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
925
926 /*
927 * Don't actually throttle groups that have no runtime assigned
928 * but accrue some time due to boosting.
929 */
930 if (likely(rt_b->rt_runtime)) {
931 rt_rq->rt_throttled = 1;
932 printk_deferred_once(
933 "sched: RT throttling activated for task pid %d (%s) on cpu:%d\n",

 > 934					rt_rq->rq->curr->pid, rt_rq->rq->curr->comm, rt_rq->rq->cpu);

935 trace_sched_rt_throttling(rt_rq->rq->curr, rt_rq->rq->cpu);
936 } else {
937 /*
938 * In case we did anyway, make it go away,
939 * replenishment is a joke, since it will replenish us
940 * with exactly 0 ns.
941 */
942 rt_rq->rt_time = 0;
943 }
944
945 if (rt_rq_throttled(rt_rq)) {
946 sched_rt_rq_dequeue(rt_rq);
947 return 1;
948 }
949 }
950
951 return 0;
952 }
953

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation