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