Skip to contentSkip to conversation

Remove sched_trace_*() helper functions

PATCH New Dietmar Eggemann 1 participant 4 messages Sep 7, 2020 Scheduler

lore
Share & tools
lore

Dietmar Eggemann

author reviewer
#0 lore raw

cover Remove sched_trace_*() helper functions

The patch ("sched/debug: Add new tracepoint to track cpu_capacity")
https://lkml.kernel.org/r/[email protected]
revealed the issue that with every tracepoint in the scheduler code there are sched_trace_*() helper functions in fair.c appearing which are exported via include/linux/sched.h.

Those tracepoints can be used to build tracepoint-to traceevent (tp-2-te) converters.

The sched_trace_*() helper functions provide access to data of internal scheduler structures, like struct rq. They support built-in or kernel module builds outside kernel/sched/. But they don't have to be maintained in the scheduler code.

kernel/sched/ is the natural place for a tp-2-te converter to get access to data of internal scheduler structures.

In case a tp-2-te converter has to be build outside the kernel code tree there is an easy way to make kernel/sched/sched.h visible. See header of "sched/fair: Remove sched_trace_*() helper functions" for details.

The first patch removes those sched_trace_*() helper functions from the scheduler.

The second patch removes cfs_rq_tg_path() from the scheduler since it can be coded inside a tp-2-te converter as well.

The third patch allows to use autogroup_path() from within a tp-2-te converter (i.e. from cfs_rq_tg_path()) in kernel modules builds.

The aim of tracepoints in the scheduler code is to keep the footprint of traceing code as small as possible and to not guarantee any stable ABI in relation to internal scheduler structures.

Dietmar Eggemann (3):
sched/fair: Remove sched_trace_*() helper functions sched/fair: Remove cfs_rq_tg_path()
sched/autogroup: Change autogroup_path() into a static inline function

 include/linux/sched.h    |  13 -----
 kernel/sched/autogroup.c |   8 ---
 kernel/sched/autogroup.h |   8 ++-
 kernel/sched/fair.c      | 105 ---------------------------------------
 kernel/sched/sched.h     |   3 --
 5 files changed, 7 insertions(+), 130 deletions(-)
Signature · 1 line
2.17.1
author reviewer
#1 lore raw

PATCH 1/3 sched/fair: Remove sched_trace_*() helper functions

The sched_trace_*() helper functions provide access to data of internal scheduler structures, like struct rq. They support built-in or kernel module builds outside kernel/sched/. But they don't have to be maintained in the scheduler code.

kernel/sched/ is the natural place for a tp-2-te converter to get access to data of internal scheduler structures.

In case a kernel module has to be build out-of tree there is an easy way to make kernel/sched/sched.h visible.

CFLAGS_foo.o := -I$KERNEL_SRC/kernel/sched

all:
make -C $KERNEL_SRC M=$(PWD) modules

The sched_trace_*() helper functions can be coded in a tp-2-te converter.

Remove them from kernel/sched/fair.c.

---
 include/linux/sched.h | 13 -------
 kernel/sched/fair.c   | 86 -------------------------------------------
 2 files changed, 99 deletions(-)
include/linux/sched.h +0 -13
index 2bf0af19a62a..23415088967d 100644
@@ -2035,17 +2035,4 @@ static inline void rseq_syscall(struct pt_regs *regs)
 
 #endif
 
-const struct sched_avg *sched_trace_cfs_rq_avg(struct cfs_rq *cfs_rq);
-char *sched_trace_cfs_rq_path(struct cfs_rq *cfs_rq, char *str, int len);
-int sched_trace_cfs_rq_cpu(struct cfs_rq *cfs_rq);
-
-const struct sched_avg *sched_trace_rq_avg_rt(struct rq *rq);
-const struct sched_avg *sched_trace_rq_avg_dl(struct rq *rq);
-const struct sched_avg *sched_trace_rq_avg_irq(struct rq *rq);
-
-int sched_trace_rq_cpu(struct rq *rq);
-int sched_trace_rq_nr_running(struct rq *rq);
-
-const struct cpumask *sched_trace_rd_span(struct root_domain *rd);
-
 #endif
kernel/sched/fair.c +0 -86

89 lines not on this page · raw message

Signature · 1 line
2.17.1
author reviewer
#2 lore raw

PATCH 2/3 sched/fair: Remove cfs_rq_tg_path()

In reply to Dietmar Eggemann

cfs_rq_tg_path() is used by a tracepoint-to traceevent (tp-2-te) converter to format the path of a taskgroup or autogroup respectively. It doesn't have any in-kernel users after the removal of the sched_trace_cfs_rq_path() helper function.

cfs_rq_tg_path() can be coded in a tp-2-te converter.

Remove it from kernel/sched/fair.c.

---
 kernel/sched/fair.c  | 19 -------------------
 kernel/sched/sched.h |  3 ---
 2 files changed, 22 deletions(-)
kernel/sched/fair.c +0 -19
index f7640af1dcaa..7b9b5ed3c506 100644
@@ -285,19 +285,6 @@ static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
 	return grp->my_q;
 }
 
-static inline void cfs_rq_tg_path(struct cfs_rq *cfs_rq, char *path, int len)
-{
-	if (!path)
-		return;
-
-	if (cfs_rq && task_group_is_autogroup(cfs_rq->tg))
-		autogroup_path(cfs_rq->tg, path, len);
-	else if (cfs_rq && cfs_rq->tg->css.cgroup)
-		cgroup_path(cfs_rq->tg->css.cgroup, path, len);
-	else
-		strlcpy(path, "(null)", len);
-}
-
 static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq)
 {
 	struct rq *rq = rq_of(cfs_rq);
@@ -472,12 +459,6 @@ static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
 	return NULL;
 }
 
-static inline void cfs_rq_tg_path(struct cfs_rq *cfs_rq, char *path, int len)
-{
-	if (path)
-		strlcpy(path, "(null)", len);
-}
-
 static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq)
 {
 	return true;
kernel/sched/sched.h +0 -3
index 28709f6b0975..5f2e9b396161 100644
@@ -730,7 +730,6 @@ static inline long se_runnable(struct sched_entity *se)
 	else
 		return se->runnable_weight;
 }
-
 #else
 #define entity_is_task(se)	1
 
@@ -1579,7 +1578,6 @@ static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
 	p->rt.parent = tg->rt_se[cpu];
 #endif
 }
-
 #else /* CONFIG_CGROUP_SCHED */
 
 static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
@@ -1587,7 +1585,6 @@ static inline struct task_group *task_group(struct task_struct *p)
 {
 	return NULL;
 }
-
 #endif /* CONFIG_CGROUP_SCHED */
 
 static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
Signature · 1 line
2.17.1
author reviewer
#3 lore raw

PATCH 3/3 sched/autogroup: Change autogroup_path() into a static inline function

In reply to Dietmar Eggemann

cfs_rq_tg_path() uses, besides cgroup_path(), autogroup_path() to format the path of a taskgroup or autogroup respectively.

Provide autogroup_path() as a static inline function like cgroup_path() so cfs_rq_tg_path() (from a tp-2-te converter) can use both in a kernel module build.

---
 kernel/sched/autogroup.c | 8 --------
 kernel/sched/autogroup.h | 8 +++++++-
 2 files changed, 7 insertions(+), 9 deletions(-)
kernel/sched/autogroup.c +0 -8
index 2067080bb235..3c6c78d909dd 100644
@@ -258,11 +258,3 @@ void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m)
 	autogroup_kref_put(ag);
 }
 #endif /* CONFIG_PROC_FS */
-
-int autogroup_path(struct task_group *tg, char *buf, int buflen)
-{
-	if (!task_group_is_autogroup(tg))
-		return 0;
-
-	return snprintf(buf, buflen, "%s-%ld", "/autogroup", tg->autogroup->id);
-}
kernel/sched/autogroup.h +7 -1
index b96419974a1f..001f4826d781 100644
@@ -35,7 +35,13 @@ autogroup_task_group(struct task_struct *p, struct task_group *tg)
 	return tg;
 }
 
-extern int autogroup_path(struct task_group *tg, char *buf, int buflen);
+static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
+{
+	if (!task_group_is_autogroup(tg))
+		return 0;
+
+	return snprintf(buf, buflen, "%s-%ld", "/autogroup", tg->autogroup->id);
+}
 
 #else /* !CONFIG_SCHED_AUTOGROUP */
 
Signature · 1 line
2.17.1