[PATCH 4/7] sched: Add sched_load_rq tracepoint
From: Qais Yousef
Date: Sun May 05 2019 - 07:59:21 EST
The new tracepoint allows tracking PELT signals at rq level for all
scheduling classes.
Signed-off-by: Qais Yousef <qais.yousef@xxxxxxx>
---
include/trace/events/sched.h | 9 ++++++++
kernel/sched/fair.c | 9 ++++++--
kernel/sched/pelt.c | 4 ++++
kernel/sched/sched_tracepoints.h | 39 ++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 2 deletions(-)
create mode 100644 kernel/sched/sched_tracepoints.h
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 9a4bdfadab07..2be4c471c6e9 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -587,6 +587,15 @@ TRACE_EVENT(sched_wake_idle_without_ipi,
TP_printk("cpu=%d", __entry->cpu)
);
+
+/*
+ * Following tracepoints are not exported in tracefs and provide hooking
+ * mechanisms only for testing and debugging purposes.
+ */
+DECLARE_TRACE(sched_load_rq,
+ TP_PROTO(int cpu, const char *path, struct sched_avg *avg),
+ TP_ARGS(cpu, path, avg));
+
#endif /* _TRACE_SCHED_H */
/* This part must be outside protection */
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 2b4963bbeab4..e1e0cc7db7f6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -21,8 +21,7 @@
* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
*/
#include "sched.h"
-
-#include <trace/events/sched.h>
+#include "sched_tracepoints.h"
/*
* Targeted preemption latency for CPU-bound tasks:
@@ -3139,6 +3138,8 @@ static inline int propagate_entity_load_avg(struct sched_entity *se)
update_tg_cfs_util(cfs_rq, se, gcfs_rq);
update_tg_cfs_runnable(cfs_rq, se, gcfs_rq);
+ sched_tp_load_cfs_rq(cfs_rq);
+
return 1;
}
@@ -3291,6 +3292,8 @@ static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
add_tg_cfs_propagate(cfs_rq, se->avg.load_sum);
cfs_rq_util_change(cfs_rq, flags);
+
+ sched_tp_load_cfs_rq(cfs_rq);
}
/**
@@ -3310,6 +3313,8 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
add_tg_cfs_propagate(cfs_rq, -se->avg.load_sum);
cfs_rq_util_change(cfs_rq, 0);
+
+ sched_tp_load_cfs_rq(cfs_rq);
}
/*
diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
index befce29bd882..302affb14302 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -26,6 +26,7 @@
#include <linux/sched.h>
#include "sched.h"
+#include "sched_tracepoints.h"
#include "pelt.h"
/*
@@ -292,6 +293,7 @@ int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq)
cfs_rq->curr != NULL)) {
___update_load_avg(&cfs_rq->avg, 1, 1);
+ sched_tp_load_cfs_rq(cfs_rq);
return 1;
}
@@ -317,6 +319,7 @@ int update_rt_rq_load_avg(u64 now, struct rq *rq, int running)
running)) {
___update_load_avg(&rq->avg_rt, 1, 1);
+ sched_tp_load_rt_rq(rq);
return 1;
}
@@ -340,6 +343,7 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq, int running)
running)) {
___update_load_avg(&rq->avg_dl, 1, 1);
+ sched_tp_load_dl_rq(rq);
return 1;
}
diff --git a/kernel/sched/sched_tracepoints.h b/kernel/sched/sched_tracepoints.h
new file mode 100644
index 000000000000..f4ded705118e
--- /dev/null
+++ b/kernel/sched/sched_tracepoints.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Scheduler tracepoints that are probe-able only and aren't exported ABI in
+ * tracefs.
+ */
+
+#include <trace/events/sched.h>
+
+#define SCHED_TP_PATH_LEN 64
+
+
+static __always_inline void sched_tp_load_cfs_rq(struct cfs_rq *cfs_rq)
+{
+ if (trace_sched_load_rq_enabled()) {
+ int cpu = cpu_of(rq_of(cfs_rq));
+ char path[SCHED_TP_PATH_LEN];
+
+ cfs_rq_tg_path(cfs_rq, path, SCHED_TP_PATH_LEN);
+ trace_sched_load_rq(cpu, path, &cfs_rq->avg);
+ }
+}
+
+static __always_inline void sched_tp_load_rt_rq(struct rq *rq)
+{
+ if (trace_sched_load_rq_enabled()) {
+ int cpu = cpu_of(rq);
+
+ trace_sched_load_rq(cpu, NULL, &rq->avg_rt);
+ }
+}
+
+static __always_inline void sched_tp_load_dl_rq(struct rq *rq)
+{
+ if (trace_sched_load_rq_enabled()) {
+ int cpu = cpu_of(rq);
+
+ trace_sched_load_rq(cpu, NULL, &rq->avg_dl);
+ }
+}
--
2.17.1