delay-accounting.rst 4.6 KB

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