This article was firstly published from http://oliveryang.net. The content reuse need include the original link.
SCHEDSTATS Perf Counters - Overview
1. What is the SCHEDSTATS?
SCHEDSTATS is a kernel debug feature which allows scheduler exports its pre-defined performance counters to user space. We can do following things by collecting and analyzing these perf counters,
- Debug or tune scheduler
- Debug or tune specific application or benchmark from scheduling perspective
2. How could we access SCHEDSTATS counters?
When SCHEDSTATS is enabled, scheduler statistics could be accessed by following ways,
Three proc files exported by SCHEDSTATS code
/proc/schedstat, /proc/[pid]/schedstat, /proc/[pid]/sched
Documentation/scheduler/sched-stats.txt file has the full description for file format. We can write user space tools to read and process the proc files.
pre-defined kernel trace points
Kernel trace points could be used by dynamic tracing tools, such as systemtap, perf. So far, in Linux 4.1, there are 4 sched_stat_* trace points defined by SCHEDSTATS code, there are 4 sched_stat_* trace points defined by SCHEDSTATS code.
# perf list | grep sched_stat_ sched:sched_stat_wait [Tracepoint event] sched:sched_stat_sleep [Tracepoint event] sched:sched_stat_iowait [Tracepoint event] sched:sched_stat_blocked [Tracepoint event] sched:sched_stat_runtime [Tracepoint event] >>>> Not a SCHEDSTAT trace point
Linux perf tool, record, report, script sub-commands could be used for getting system wide or per-task statistics.
sleep profiler when SCHEDSTATS is enabled
This needs readprofile command installed in user space. The usage of readprofile could be found from