Skip to content

sched: support schedstats for RT sched class

Yafang Shao linux-rt-users lkml 5 versions – Applied

Status from this message: The following commit has been merged into the sched/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest8 patches 4 repliesApplied
  2. v3 posting 2/27 patches 12 repliesSuperseded
  3. v3 RFC posting 1/24 of 5 patches 1 replySuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v2 RFC5 patches2 repliesSuperseded
v1 RFC4 patches4 repliesSuperseded

Changes in v4 from the cover letter

Various code improvement per Peter,
- don't support schedstats for rt group
- introduce struct sched_entity_stats for fair group
- change the position of 'struct sched_statistics stats'
- fixes indent issue
- change the output format in /proc/[pid]/sched
- add the usecase of schedstats
- support schedstats for deadline task
- and other suggestions

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/8sched, fair: use __schedstat_set() in set_next_entity()kernel/sched/fair.c+1 -10 replies
2/8sched: make struct sched_statistics independent of fair sched classinclude/linux/sched.h kernel/sched/core.c kernel/sched/deadline.c +5 more+140 -1003 replies
3/8sched: make schedstats helpers independent of fair sched classkernel/sched/debug.c kernel/sched/fair.c kernel/sched/stats.c +1 more+159 -1180 replies
4/8sched: introduce task block time in schedstatsinclude/linux/sched.h kernel/sched/debug.c kernel/sched/stats.c+7 -20 replies
5/8sched, rt: support sched_stat_runtime tracepoint for RT sched classkernel/sched/rt.c+2 -00 replies
6/8sched, rt: support schedstats for RT sched classkernel/sched/rt.c+124 -00 replies
7/8sched, dl: support sched_stat_runtime tracepoint for deadline sched classkernel/sched/deadline.c+2 -00 replies
8/8sched, dl: support schedstats for deadline sched classkernel/sched/deadline.c+93 -00 replies

Reviews trailers per patch

3 of 8 patches have a Reviewed-by or Acked-by.

PatchMel Gorman
1/8A-b
2/8A-b
3/8A-b
4/8
5/8
6/8
7/8
8/8

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/8] sched: support schedstats for RT sched class

Why do we need schedstats ?
==========================

schedstats is a useful feature to do thread-level latency analysis. Our usecase as follows,

Userspace Code Scope Profiler

  {
      user_func_abc(); <----   uprobe_scope_begin() get start schedstats 
      ...
      user_func_xyz(); <----   uprobe_scope_end() get end schedstats
  }

Then with the result of (end - begin) we can get below latency details in a specific user scope,

scope_latency = Wait + Sleep + Blocked [1] + Run (stime + utime)

If there's no schedstats we have to trace the heavy sched::sched_switch and do a lot more stuff.

[1]. With patch #4 and don't include sum_block_runtime in sum_sleep_runtime

Support schedstats for RT sched class
=====================================

If we want to use the schedstats facility to trace other sched classes, we should make it independent of fair sched class. The struct sched_statistics is the schedular statistics of a task_struct or a task_group. So we can move it into struct task_struct and struct task_group to achieve the goal.

After the patch, schestats are orgnized as follows,

    struct task_struct {
       ...
       struct sched_entity se;
       struct sched_rt_entity rt;
       struct sched_dl_entity dl;
       ...
       struct sched_statistics stats;
       ...

};

Regarding the task group, schedstats is only supported for fair group sched, and a new struct sched_entity_stats is introduced, suggested by Peter -

    struct sched_entity_stats {
        struct sched_entity     se;
        struct sched_statistics stats;
    } __no_randomize_layout;

Then with the se in a task_group, we can easily get the stats.

The sched_statistics members may be frequently modified when schedstats is enabled, in order to avoid impacting on random data which may in the same cacheline with them, the struct sched_statistics is defined as cacheline aligned.

As this patch changes the core struct of scheduler, so I verified the performance it may impact on the scheduler with 'perf bench sched pipe', suggested by Mel. Below is the result, in which all the values are in usecs/op.

                                  Before               After
      kernel.sched_schedstats=0  5.2~5.4               5.2~5.4
      kernel.sched_schedstats=1  5.3~5.5               5.3~5.5

[These data is a little difference with the earlier version, that is
because my old test machine is destroyed so I have to use a new different test machine.]

Almost no impact on the sched performance.

The user can get the schedstats information in the same way in fair sched class. For example,
fair RT
/proc/[pid]/sched /proc/[pid]/sched

schedstats is not supported for RT group.

The sched:sched_stat_{wait, sleep, iowait, blocked} tracepoints can be used to trace RT tasks as well.

Support schedstats for any other sched classes
==============================================

After this patchset, it is very easy to extend the schedstats to any other sched classes. The deadline sched class is also supported in this patchset.

Changes Since v3:
Various code improvement per Peter,
- don't support schedstats for rt group
- introduce struct sched_entity_stats for fair group
- change the position of 'struct sched_statistics stats'
- fixes indent issue
- change the output format in /proc/[pid]/sched
- add the usecase of schedstats
- support schedstats for deadline task
- and other suggestions

Changes Since v2:
- Fixes the output format in /proc/[pid]/sched
- Rebase it on the latest code
- Redo the performance test

Changes since v1:
- Fix the build failure reported by kernel test robot.
- Add the performance data with 'perf bench sched pipe', suggested by Mel.
- Make the struct sched_statistics cacheline aligned.
- Introduce task block time in schedstats

Changes since RFC:
- improvement of schedstats helpers, per Mel.
- make struct schedstats independent of fair sched class

Yafang Shao (8):
sched, fair: use __schedstat_set() in set_next_entity()
sched: make struct sched_statistics independent of fair sched class
sched: make schedstats helpers independent of fair sched class
sched: introduce task block time in schedstats
sched, rt: support sched_stat_runtime tracepoint for RT sched class sched, rt: support schedstats for RT sched class
sched, dl: support sched_stat_runtime tracepoint for deadline sched
class
sched, dl: support schedstats for deadline sched class

 include/linux/sched.h    |   8 +-
 kernel/sched/core.c      |  25 +++---
 kernel/sched/deadline.c  |  99 +++++++++++++++++++++-
 kernel/sched/debug.c     |  97 +++++++++++----------
 kernel/sched/fair.c      | 177 +++++++++++----------------------------
 kernel/sched/rt.c        | 130 +++++++++++++++++++++++++++-
 kernel/sched/stats.c     | 104 +++++++++++++++++++++++
 kernel/sched/stats.h     |  49 +++++++++++
 kernel/sched/stop_task.c |   4 +-
 9 files changed, 500 insertions(+), 193 deletions(-)
Signature · 1 line
2.18.2