2020-11-23 13:03:48

by Yafang Shao

[permalink] [raw]
Subject: [RFC PATCH v2 0/5] sched: support schedstat for RT sched class

We want to measure the latency of RT tasks in our production
environment with schedstat facility, but currently schedstat is only
supported for fair sched class. This patchset enable it for RT sched class
as well.

The schedstat statistics are defined in struct sched_entity, which is a
member of struct task_struct, so we can resue it for RT sched class.

The schedstat usage in RT sched class is similar with fair sched class,
for example,
fair RT
enqueue update_stats_enqueue_fair update_stats_enqueue_rt
dequeue update_stats_dequeue_fair update_stats_dequeue_rt
put_prev_task update_stats_wait_start update_stats_wait_start
set_next_task update_stats_wait_end update_stats_wait_end
show /proc/[pid]/sched /proc/[pid]/sched

The sched:sched_stats_* tracepoints can be used to trace RT tasks as
well after that patchset.

PATCH #1 ~ #4 are the preparation of PATCH #5.

- v2:
keep the schedstats functions inline, per Mel.

Yafang Shao (5):
sched: don't include stats.h in sched.h
sched: define task_of() as a common helper
sched: make schedstats helper independent of cfs_rq
sched: define update_stats_curr_start() as a common helper
sched, rt: support schedstat for RT sched class

kernel/sched/core.c | 1 +
kernel/sched/deadline.c | 1 +
kernel/sched/debug.c | 1 +
kernel/sched/fair.c | 174 ++-------------------------------------
kernel/sched/idle.c | 1 +
kernel/sched/rt.c | 94 ++++++++++++++++++++-
kernel/sched/sched.h | 30 ++++++-
kernel/sched/stats.c | 1 +
kernel/sched/stats.h | 146 ++++++++++++++++++++++++++++++++
kernel/sched/stop_task.c | 1 +
10 files changed, 280 insertions(+), 170 deletions(-)

--
2.18.4


2020-11-23 13:03:49

by Yafang Shao

[permalink] [raw]
Subject: [RFC PATCH v2 2/5] sched: define task_of() as a common helper

task_of() is used to get task_struct from sched_entity. As sched_entity
in struct task_struct can be used by all sched class, we'd better move
this macro into sched.h, then it can be used by all sched class.

Signed-off-by: Yafang Shao <[email protected]>
---
kernel/sched/fair.c | 11 -----------
kernel/sched/sched.h | 8 ++++++++
2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8ff1daa3d9bb..59e454cae3be 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -259,12 +259,6 @@ const struct sched_class fair_sched_class;
*/

#ifdef CONFIG_FAIR_GROUP_SCHED
-static inline struct task_struct *task_of(struct sched_entity *se)
-{
- SCHED_WARN_ON(!entity_is_task(se));
- return container_of(se, struct task_struct, se);
-}
-
/* Walk up scheduling entities hierarchy */
#define for_each_sched_entity(se) \
for (; se; se = se->parent)
@@ -446,11 +440,6 @@ find_matching_se(struct sched_entity **se, struct sched_entity **pse)

#else /* !CONFIG_FAIR_GROUP_SCHED */

-static inline struct task_struct *task_of(struct sched_entity *se)
-{
- return container_of(se, struct task_struct, se);
-}
-
#define for_each_sched_entity(se) \
for (; se; se = NULL)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 871544bb9a38..9a4576ccf3d7 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2636,4 +2636,12 @@ static inline bool is_per_cpu_kthread(struct task_struct *p)
void swake_up_all_locked(struct swait_queue_head *q);
void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);

+static inline struct task_struct *task_of(struct sched_entity *se)
+{
+#ifdef CONFIG_FAIR_GROUP_SCHED
+ SCHED_WARN_ON(!entity_is_task(se));
+#endif
+ return container_of(se, struct task_struct, se);
+}
+
#endif /* _KERNEL_SCHED_SCHED_H */
--
2.18.4

2020-11-23 13:05:09

by Yafang Shao

[permalink] [raw]
Subject: [RFC PATCH v2 4/5] sched: define update_stats_curr_start() as a common helper

update_stats_curr_start() is used to update the exec_start when we are
starting a new run period, which is used by all sched class. So we'd
better define it as a common helper.

Signed-off-by: Yafang Shao <[email protected]>
---
kernel/sched/fair.c | 14 +-------------
kernel/sched/rt.c | 2 +-
kernel/sched/sched.h | 12 ++++++++++++
3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 946b60f586e4..13e803369ced 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -915,18 +915,6 @@ update_stats_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
}
}

-/*
- * We are picking a new current task - update its stats:
- */
-static inline void
-update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
-{
- /*
- * We are starting a new run period:
- */
- se->exec_start = rq_clock_task(rq_of(cfs_rq));
-}
-
/**************************************************
* Scheduling class queueing methods:
*/
@@ -4255,7 +4243,7 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
update_load_avg(cfs_rq, se, UPDATE_TG);
}

- update_stats_curr_start(cfs_rq, se);
+ update_stats_curr_start(rq_of(cfs_rq), se);
cfs_rq->curr = se;

/*
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index af772ac0f32d..3422dd85cfb4 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1574,7 +1574,7 @@ static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flag

static inline void set_next_task_rt(struct rq *rq, struct task_struct *p, bool first)
{
- p->se.exec_start = rq_clock_task(rq);
+ update_stats_curr_start(rq, &p->se);

/* The running task is never eligible for pushing */
dequeue_pushable_task(rq, p);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 9a4576ccf3d7..3948112dc31c 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2644,4 +2644,16 @@ static inline struct task_struct *task_of(struct sched_entity *se)
return container_of(se, struct task_struct, se);
}

+/*
+ * We are picking a new current task - update its stats:
+ */
+static inline void
+update_stats_curr_start(struct rq *rq, struct sched_entity *se)
+{
+ /*
+ * We are starting a new run period:
+ */
+ se->exec_start = rq_clock_task(rq);
+}
+
#endif /* _KERNEL_SCHED_SCHED_H */
--
2.18.4