xref: /OK3568_Linux_fs/kernel/Documentation/scheduler/sched-stats.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun====================
2*4882a593SmuzhiyunScheduler Statistics
3*4882a593Smuzhiyun====================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunVersion 15 of schedstats dropped counters for some sched_yield:
6*4882a593Smuzhiyunyld_exp_empty, yld_act_empty and yld_both_empty. Otherwise, it is
7*4882a593Smuzhiyunidentical to version 14.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunVersion 14 of schedstats includes support for sched_domains, which hit the
10*4882a593Smuzhiyunmainline kernel in 2.6.20 although it is identical to the stats from version
11*4882a593Smuzhiyun12 which was in the kernel from 2.6.13-2.6.19 (version 13 never saw a kernel
12*4882a593Smuzhiyunrelease).  Some counters make more sense to be per-runqueue; other to be
13*4882a593Smuzhiyunper-domain.  Note that domains (and their associated information) will only
14*4882a593Smuzhiyunbe pertinent and available on machines utilizing CONFIG_SMP.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunIn version 14 of schedstat, there is at least one level of domain
17*4882a593Smuzhiyunstatistics for each cpu listed, and there may well be more than one
18*4882a593Smuzhiyundomain.  Domains have no particular names in this implementation, but
19*4882a593Smuzhiyunthe highest numbered one typically arbitrates balancing across all the
20*4882a593Smuzhiyuncpus on the machine, while domain0 is the most tightly focused domain,
21*4882a593Smuzhiyunsometimes balancing only between pairs of cpus.  At this time, there
22*4882a593Smuzhiyunare no architectures which need more than three domain levels. The first
23*4882a593Smuzhiyunfield in the domain stats is a bit map indicating which cpus are affected
24*4882a593Smuzhiyunby that domain.
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunThese fields are counters, and only increment.  Programs which make use
27*4882a593Smuzhiyunof these will need to start with a baseline observation and then calculate
28*4882a593Smuzhiyunthe change in the counters at each subsequent observation.  A perl script
29*4882a593Smuzhiyunwhich does this for many of the fields is available at
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun    http://eaglet.pdxhosts.com/rick/linux/schedstat/
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunNote that any such script will necessarily be version-specific, as the main
34*4882a593Smuzhiyunreason to change versions is changes in the output format.  For those wishing
35*4882a593Smuzhiyunto write their own scripts, the fields are described here.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunCPU statistics
38*4882a593Smuzhiyun--------------
39*4882a593Smuzhiyuncpu<N> 1 2 3 4 5 6 7 8 9
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunFirst field is a sched_yield() statistic:
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun     1) # of times sched_yield() was called
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunNext three are schedule() statistics:
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun     2) This field is a legacy array expiration count field used in the O(1)
48*4882a593Smuzhiyun	scheduler. We kept it for ABI compatibility, but it is always set to zero.
49*4882a593Smuzhiyun     3) # of times schedule() was called
50*4882a593Smuzhiyun     4) # of times schedule() left the processor idle
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunNext two are try_to_wake_up() statistics:
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun     5) # of times try_to_wake_up() was called
55*4882a593Smuzhiyun     6) # of times try_to_wake_up() was called to wake up the local cpu
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunNext three are statistics describing scheduling latency:
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun     7) sum of all time spent running by tasks on this processor (in jiffies)
60*4882a593Smuzhiyun     8) sum of all time spent waiting to run by tasks on this processor (in
61*4882a593Smuzhiyun        jiffies)
62*4882a593Smuzhiyun     9) # of timeslices run on this cpu
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunDomain statistics
66*4882a593Smuzhiyun-----------------
67*4882a593SmuzhiyunOne of these is produced per domain for each cpu described. (Note that if
68*4882a593SmuzhiyunCONFIG_SMP is not defined, *no* domains are utilized and these lines
69*4882a593Smuzhiyunwill not appear in the output.)
70*4882a593Smuzhiyun
71*4882a593Smuzhiyundomain<N> <cpumask> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunThe first field is a bit mask indicating what cpus this domain operates over.
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunThe next 24 are a variety of load_balance() statistics in grouped into types
76*4882a593Smuzhiyunof idleness (idle, busy, and newly idle):
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun    1)  # of times in this domain load_balance() was called when the
79*4882a593Smuzhiyun        cpu was idle
80*4882a593Smuzhiyun    2)  # of times in this domain load_balance() checked but found
81*4882a593Smuzhiyun        the load did not require balancing when the cpu was idle
82*4882a593Smuzhiyun    3)  # of times in this domain load_balance() tried to move one or
83*4882a593Smuzhiyun        more tasks and failed, when the cpu was idle
84*4882a593Smuzhiyun    4)  sum of imbalances discovered (if any) with each call to
85*4882a593Smuzhiyun        load_balance() in this domain when the cpu was idle
86*4882a593Smuzhiyun    5)  # of times in this domain pull_task() was called when the cpu
87*4882a593Smuzhiyun        was idle
88*4882a593Smuzhiyun    6)  # of times in this domain pull_task() was called even though
89*4882a593Smuzhiyun        the target task was cache-hot when idle
90*4882a593Smuzhiyun    7)  # of times in this domain load_balance() was called but did
91*4882a593Smuzhiyun        not find a busier queue while the cpu was idle
92*4882a593Smuzhiyun    8)  # of times in this domain a busier queue was found while the
93*4882a593Smuzhiyun        cpu was idle but no busier group was found
94*4882a593Smuzhiyun    9)  # of times in this domain load_balance() was called when the
95*4882a593Smuzhiyun        cpu was busy
96*4882a593Smuzhiyun    10) # of times in this domain load_balance() checked but found the
97*4882a593Smuzhiyun        load did not require balancing when busy
98*4882a593Smuzhiyun    11) # of times in this domain load_balance() tried to move one or
99*4882a593Smuzhiyun        more tasks and failed, when the cpu was busy
100*4882a593Smuzhiyun    12) sum of imbalances discovered (if any) with each call to
101*4882a593Smuzhiyun        load_balance() in this domain when the cpu was busy
102*4882a593Smuzhiyun    13) # of times in this domain pull_task() was called when busy
103*4882a593Smuzhiyun    14) # of times in this domain pull_task() was called even though the
104*4882a593Smuzhiyun        target task was cache-hot when busy
105*4882a593Smuzhiyun    15) # of times in this domain load_balance() was called but did not
106*4882a593Smuzhiyun        find a busier queue while the cpu was busy
107*4882a593Smuzhiyun    16) # of times in this domain a busier queue was found while the cpu
108*4882a593Smuzhiyun        was busy but no busier group was found
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun    17) # of times in this domain load_balance() was called when the
111*4882a593Smuzhiyun        cpu was just becoming idle
112*4882a593Smuzhiyun    18) # of times in this domain load_balance() checked but found the
113*4882a593Smuzhiyun        load did not require balancing when the cpu was just becoming idle
114*4882a593Smuzhiyun    19) # of times in this domain load_balance() tried to move one or more
115*4882a593Smuzhiyun        tasks and failed, when the cpu was just becoming idle
116*4882a593Smuzhiyun    20) sum of imbalances discovered (if any) with each call to
117*4882a593Smuzhiyun        load_balance() in this domain when the cpu was just becoming idle
118*4882a593Smuzhiyun    21) # of times in this domain pull_task() was called when newly idle
119*4882a593Smuzhiyun    22) # of times in this domain pull_task() was called even though the
120*4882a593Smuzhiyun        target task was cache-hot when just becoming idle
121*4882a593Smuzhiyun    23) # of times in this domain load_balance() was called but did not
122*4882a593Smuzhiyun        find a busier queue while the cpu was just becoming idle
123*4882a593Smuzhiyun    24) # of times in this domain a busier queue was found while the cpu
124*4882a593Smuzhiyun        was just becoming idle but no busier group was found
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun   Next three are active_load_balance() statistics:
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun    25) # of times active_load_balance() was called
129*4882a593Smuzhiyun    26) # of times active_load_balance() tried to move a task and failed
130*4882a593Smuzhiyun    27) # of times active_load_balance() successfully moved a task
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun   Next three are sched_balance_exec() statistics:
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun    28) sbe_cnt is not used
135*4882a593Smuzhiyun    29) sbe_balanced is not used
136*4882a593Smuzhiyun    30) sbe_pushed is not used
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun   Next three are sched_balance_fork() statistics:
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun    31) sbf_cnt is not used
141*4882a593Smuzhiyun    32) sbf_balanced is not used
142*4882a593Smuzhiyun    33) sbf_pushed is not used
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun   Next three are try_to_wake_up() statistics:
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun    34) # of times in this domain try_to_wake_up() awoke a task that
147*4882a593Smuzhiyun        last ran on a different cpu in this domain
148*4882a593Smuzhiyun    35) # of times in this domain try_to_wake_up() moved a task to the
149*4882a593Smuzhiyun        waking cpu because it was cache-cold on its own cpu anyway
150*4882a593Smuzhiyun    36) # of times in this domain try_to_wake_up() started passive balancing
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun/proc/<pid>/schedstat
153*4882a593Smuzhiyun---------------------
154*4882a593Smuzhiyunschedstats also adds a new /proc/<pid>/schedstat file to include some of
155*4882a593Smuzhiyunthe same information on a per-process level.  There are three fields in
156*4882a593Smuzhiyunthis file correlating for that process to:
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun     1) time spent on the cpu
159*4882a593Smuzhiyun     2) time spent waiting on a runqueue
160*4882a593Smuzhiyun     3) # of timeslices run on this cpu
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunA program could be easily written to make use of these extra fields to
163*4882a593Smuzhiyunreport on how well a particular process or set of processes is faring
164*4882a593Smuzhiyununder the scheduler's policies.  A simple version of such a program is
165*4882a593Smuzhiyunavailable at
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun    http://eaglet.pdxhosts.com/rick/linux/schedstat/v12/latency.c
168