delay-accounting.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ================
  2. Delay accounting
  3. ================
  4. Tasks encounter delays in execution when they wait
  5. for some kernel resource to become available e.g. a
  6. runnable task may wait for a free CPU to run on.
  7. The per-task delay accounting functionality measures
  8. the delays experienced by a task while
  9. a) waiting for a CPU (while being runnable)
  10. b) completion of synchronous block I/O initiated by the task
  11. c) swapping in pages
  12. d) memory reclaim
  13. e) thrashing
  14. f) direct compact
  15. g) write-protect copy
  16. h) IRQ/SOFTIRQ
  17. and makes these statistics available to userspace through
  18. the taskstats interface.
  19. Such delays provide feedback for setting a task's cpu priority,
  20. io priority and rss limit values appropriately. Long delays for
  21. important tasks could be a trigger for raising its corresponding priority.
  22. The functionality, through its use of the taskstats interface, also provides
  23. delay statistics aggregated for all tasks (or threads) belonging to a
  24. thread group (corresponding to a traditional Unix process). This is a commonly
  25. needed aggregation that is more efficiently done by the kernel.
  26. Userspace utilities, particularly resource management applications, can also
  27. aggregate delay statistics into arbitrary groups. To enable this, delay
  28. statistics of a task are available both during its lifetime as well as on its
  29. exit, ensuring continuous and complete monitoring can be done.
  30. Interface
  31. ---------
  32. Delay accounting uses the taskstats interface which is described
  33. in detail in a separate document in this directory. Taskstats returns a
  34. generic data structure to userspace corresponding to per-pid and per-tgid
  35. statistics. The delay accounting functionality populates specific fields of
  36. this structure. See
  37. include/uapi/linux/taskstats.h
  38. for a description of the fields pertaining to delay accounting.
  39. It will generally be in the form of counters returning the cumulative
  40. delay seen for cpu, sync block I/O, swapin, memory reclaim, thrash page
  41. cache, direct compact, write-protect copy, IRQ/SOFTIRQ etc.
  42. Taking the difference of two successive readings of a given
  43. counter (say cpu_delay_total) for a task will give the delay
  44. experienced by the task waiting for the corresponding resource
  45. in that interval.
  46. When a task exits, records containing the per-task statistics
  47. are sent to userspace without requiring a command. If it is the last exiting
  48. task of a thread group, the per-tgid statistics are also sent. More details
  49. are given in the taskstats interface description.
  50. The getdelays.c userspace utility in tools/accounting directory allows simple
  51. commands to be run and the corresponding delay statistics to be displayed. It
  52. also serves as an example of using the taskstats interface.
  53. Usage
  54. -----
  55. Compile the kernel with::
  56. CONFIG_TASK_DELAY_ACCT=y
  57. CONFIG_TASKSTATS=y
  58. Delay accounting is disabled by default at boot up.
  59. To enable, add::
  60. delayacct
  61. to the kernel boot options. The rest of the instructions below assume this has
  62. been done. Alternatively, use sysctl kernel.task_delayacct to switch the state
  63. at runtime. Note however that only tasks started after enabling it will have
  64. delayacct information.
  65. After the system has booted up, use a utility
  66. similar to getdelays.c to access the delays
  67. seen by a given task or a task group (tgid).
  68. The utility also allows a given command to be
  69. executed and the corresponding delays to be
  70. seen.
  71. General format of the getdelays command::
  72. getdelays [-dilv] [-t tgid] [-p pid]
  73. Get delays, since system boot, for pid 10::
  74. # ./getdelays -d -p 10
  75. (output similar to next case)
  76. Get sum of delays, since system boot, for all pids with tgid 5::
  77. # ./getdelays -d -t 5
  78. print delayacct stats ON
  79. TGID 5
  80. CPU count real total virtual total delay total delay average
  81. 8 7000000 6872122 3382277 0.423ms
  82. IO count delay total delay average
  83. 0 0 0.000ms
  84. SWAP count delay total delay average
  85. 0 0 0.000ms
  86. RECLAIM count delay total delay average
  87. 0 0 0.000ms
  88. THRASHING count delay total delay average
  89. 0 0 0.000ms
  90. COMPACT count delay total delay average
  91. 0 0 0.000ms
  92. WPCOPY count delay total delay average
  93. 0 0 0.000ms
  94. IRQ count delay total delay average
  95. 0 0 0.000ms
  96. Get IO accounting for pid 1, it works only with -p::
  97. # ./getdelays -i -p 1
  98. printing IO accounting
  99. linuxrc: read=65536, write=0, cancelled_write=0
  100. The above command can be used with -v to get more debug information.