Path: blob/master/Documentation/accounting/delay-accounting.txt
10821 views
Delay accounting1----------------23Tasks encounter delays in execution when they wait4for some kernel resource to become available e.g. a5runnable task may wait for a free CPU to run on.67The per-task delay accounting functionality measures8the delays experienced by a task while910a) waiting for a CPU (while being runnable)11b) completion of synchronous block I/O initiated by the task12c) swapping in pages13d) memory reclaim1415and makes these statistics available to userspace through16the taskstats interface.1718Such delays provide feedback for setting a task's cpu priority,19io priority and rss limit values appropriately. Long delays for20important tasks could be a trigger for raising its corresponding priority.2122The functionality, through its use of the taskstats interface, also provides23delay statistics aggregated for all tasks (or threads) belonging to a24thread group (corresponding to a traditional Unix process). This is a commonly25needed aggregation that is more efficiently done by the kernel.2627Userspace utilities, particularly resource management applications, can also28aggregate delay statistics into arbitrary groups. To enable this, delay29statistics of a task are available both during its lifetime as well as on its30exit, ensuring continuous and complete monitoring can be done.313233Interface34---------3536Delay accounting uses the taskstats interface which is described37in detail in a separate document in this directory. Taskstats returns a38generic data structure to userspace corresponding to per-pid and per-tgid39statistics. The delay accounting functionality populates specific fields of40this structure. See41include/linux/taskstats.h42for a description of the fields pertaining to delay accounting.43It will generally be in the form of counters returning the cumulative44delay seen for cpu, sync block I/O, swapin, memory reclaim etc.4546Taking the difference of two successive readings of a given47counter (say cpu_delay_total) for a task will give the delay48experienced by the task waiting for the corresponding resource49in that interval.5051When a task exits, records containing the per-task statistics52are sent to userspace without requiring a command. If it is the last exiting53task of a thread group, the per-tgid statistics are also sent. More details54are given in the taskstats interface description.5556The getdelays.c userspace utility in this directory allows simple commands to57be run and the corresponding delay statistics to be displayed. It also serves58as an example of using the taskstats interface.5960Usage61-----6263Compile the kernel with64CONFIG_TASK_DELAY_ACCT=y65CONFIG_TASKSTATS=y6667Delay accounting is enabled by default at boot up.68To disable, add69nodelayacct70to the kernel boot options. The rest of the instructions71below assume this has not been done.7273After the system has booted up, use a utility74similar to getdelays.c to access the delays75seen by a given task or a task group (tgid).76The utility also allows a given command to be77executed and the corresponding delays to be78seen.7980General format of the getdelays command8182getdelays [-t tgid] [-p pid] [-c cmd...]838485Get delays, since system boot, for pid 1086# ./getdelays -p 1087(output similar to next case)8889Get sum of delays, since system boot, for all pids with tgid 590# ./getdelays -t 5919293CPU count real total virtual total delay total947876 92005750 100000000 2400150095IO count delay total960 097SWAP count delay total980 099RECLAIM count delay total1000 0101102Get delays seen in executing a given simple command103# ./getdelays -c ls /104105bin data1 data3 data5 dev home media opt root srv sys usr106boot data2 data4 data6 etc lib mnt proc sbin subdomain tmp var107108109CPU count real total virtual total delay total1106 4000250 4000000 0111IO count delay total1120 0113SWAP count delay total1140 0115RECLAIM count delay total1160 0117118119