blob: 8a12f0730c94da018615aebc8e657daf65eadd80 [file] [log] [blame]
Shailabh Nagara3baf642006-07-14 00:24:42 -07001Delay accounting
2----------------
3
4Tasks encounter delays in execution when they wait
5for some kernel resource to become available e.g. a
6runnable task may wait for a free CPU to run on.
7
8The per-task delay accounting functionality measures
9the delays experienced by a task while
10
11a) waiting for a CPU (while being runnable)
12b) completion of synchronous block I/O initiated by the task
13c) swapping in pages
Keika Kobayashi9b0975a2008-07-25 01:48:54 -070014d) memory reclaim
Shailabh Nagara3baf642006-07-14 00:24:42 -070015
16and makes these statistics available to userspace through
17the taskstats interface.
18
19Such delays provide feedback for setting a task's cpu priority,
20io priority and rss limit values appropriately. Long delays for
21important tasks could be a trigger for raising its corresponding priority.
22
23The functionality, through its use of the taskstats interface, also provides
24delay statistics aggregated for all tasks (or threads) belonging to a
25thread group (corresponding to a traditional Unix process). This is a commonly
26needed aggregation that is more efficiently done by the kernel.
27
28Userspace utilities, particularly resource management applications, can also
29aggregate delay statistics into arbitrary groups. To enable this, delay
30statistics of a task are available both during its lifetime as well as on its
31exit, ensuring continuous and complete monitoring can be done.
32
33
34Interface
35---------
36
37Delay accounting uses the taskstats interface which is described
38in detail in a separate document in this directory. Taskstats returns a
39generic data structure to userspace corresponding to per-pid and per-tgid
40statistics. The delay accounting functionality populates specific fields of
41this structure. See
42 include/linux/taskstats.h
43for a description of the fields pertaining to delay accounting.
44It will generally be in the form of counters returning the cumulative
Keika Kobayashi9b0975a2008-07-25 01:48:54 -070045delay seen for cpu, sync block I/O, swapin, memory reclaim etc.
Shailabh Nagara3baf642006-07-14 00:24:42 -070046
47Taking the difference of two successive readings of a given
48counter (say cpu_delay_total) for a task will give the delay
49experienced by the task waiting for the corresponding resource
50in that interval.
51
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070052When a task exits, records containing the per-task statistics
53are sent to userspace without requiring a command. If it is the last exiting
54task of a thread group, the per-tgid statistics are also sent. More details
55are given in the taskstats interface description.
Shailabh Nagara3baf642006-07-14 00:24:42 -070056
57The getdelays.c userspace utility in this directory allows simple commands to
58be run and the corresponding delay statistics to be displayed. It also serves
59as an example of using the taskstats interface.
60
61Usage
62-----
63
64Compile the kernel with
65 CONFIG_TASK_DELAY_ACCT=y
66 CONFIG_TASKSTATS=y
67
Shailabh Nagar163ecdf2006-07-30 03:03:11 -070068Delay accounting is enabled by default at boot up.
69To disable, add
70 nodelayacct
71to the kernel boot options. The rest of the instructions
72below assume this has not been done.
Shailabh Nagara3baf642006-07-14 00:24:42 -070073
Shailabh Nagar163ecdf2006-07-30 03:03:11 -070074After the system has booted up, use a utility
Shailabh Nagara3baf642006-07-14 00:24:42 -070075similar to getdelays.c to access the delays
76seen by a given task or a task group (tgid).
77The utility also allows a given command to be
78executed and the corresponding delays to be
79seen.
80
81General format of the getdelays command
82
83getdelays [-t tgid] [-p pid] [-c cmd...]
84
85
86Get delays, since system boot, for pid 10
87# ./getdelays -p 10
88(output similar to next case)
89
90Get sum of delays, since system boot, for all pids with tgid 5
91# ./getdelays -t 5
92
93
94CPU count real total virtual total delay total
95 7876 92005750 100000000 24001500
96IO count delay total
97 0 0
Keika Kobayashi9b0975a2008-07-25 01:48:54 -070098SWAP count delay total
99 0 0
100RECLAIM count delay total
Shailabh Nagara3baf642006-07-14 00:24:42 -0700101 0 0
102
103Get delays seen in executing a given simple command
104# ./getdelays -c ls /
105
106bin data1 data3 data5 dev home media opt root srv sys usr
107boot data2 data4 data6 etc lib mnt proc sbin subdomain tmp var
108
109
110CPU count real total virtual total delay total
111 6 4000250 4000000 0
112IO count delay total
113 0 0
Keika Kobayashi9b0975a2008-07-25 01:48:54 -0700114SWAP count delay total
115 0 0
116RECLAIM count delay total
Shailabh Nagara3baf642006-07-14 00:24:42 -0700117 0 0