delay-accounting.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. and makes these statistics available to userspace through
  14. the taskstats interface.
  15. Such delays provide feedback for setting a task's cpu priority,
  16. io priority and rss limit values appropriately. Long delays for
  17. important tasks could be a trigger for raising its corresponding priority.
  18. The functionality, through its use of the taskstats interface, also provides
  19. delay statistics aggregated for all tasks (or threads) belonging to a
  20. thread group (corresponding to a traditional Unix process). This is a commonly
  21. needed aggregation that is more efficiently done by the kernel.
  22. Userspace utilities, particularly resource management applications, can also
  23. aggregate delay statistics into arbitrary groups. To enable this, delay
  24. statistics of a task are available both during its lifetime as well as on its
  25. exit, ensuring continuous and complete monitoring can be done.
  26. Interface
  27. ---------
  28. Delay accounting uses the taskstats interface which is described
  29. in detail in a separate document in this directory. Taskstats returns a
  30. generic data structure to userspace corresponding to per-pid and per-tgid
  31. statistics. The delay accounting functionality populates specific fields of
  32. this structure. See
  33. include/linux/taskstats.h
  34. for a description of the fields pertaining to delay accounting.
  35. It will generally be in the form of counters returning the cumulative
  36. delay seen for cpu, sync block I/O, swapin, memory reclaim etc.
  37. Taking the difference of two successive readings of a given
  38. counter (say cpu_delay_total) for a task will give the delay
  39. experienced by the task waiting for the corresponding resource
  40. in that interval.
  41. When a task exits, records containing the per-task statistics
  42. are sent to userspace without requiring a command. If it is the last exiting
  43. task of a thread group, the per-tgid statistics are also sent. More details
  44. are given in the taskstats interface description.
  45. The getdelays.c userspace utility in tools/accounting directory allows simple
  46. commands to be run and the corresponding delay statistics to be displayed. It
  47. also serves as an example of using the taskstats interface.
  48. Usage
  49. -----
  50. Compile the kernel with::
  51. CONFIG_TASK_DELAY_ACCT=y
  52. CONFIG_TASKSTATS=y
  53. Delay accounting is enabled by default at boot up.
  54. To disable, add::
  55. nodelayacct
  56. to the kernel boot options. The rest of the instructions
  57. below assume this has not been done.
  58. After the system has booted up, use a utility
  59. similar to getdelays.c to access the delays
  60. seen by a given task or a task group (tgid).
  61. The utility also allows a given command to be
  62. executed and the corresponding delays to be
  63. seen.
  64. General format of the getdelays command::
  65. getdelays [-t tgid] [-p pid] [-c cmd...]
  66. Get delays, since system boot, for pid 10::
  67. # ./getdelays -p 10
  68. (output similar to next case)
  69. Get sum of delays, since system boot, for all pids with tgid 5::
  70. # ./getdelays -t 5
  71. CPU count real total virtual total delay total
  72. 7876 92005750 100000000 24001500
  73. IO count delay total
  74. 0 0
  75. SWAP count delay total
  76. 0 0
  77. RECLAIM count delay total
  78. 0 0
  79. Get delays seen in executing a given simple command::
  80. # ./getdelays -c ls /
  81. bin data1 data3 data5 dev home media opt root srv sys usr
  82. boot data2 data4 data6 etc lib mnt proc sbin subdomain tmp var
  83. CPU count real total virtual total delay total
  84. 6 4000250 4000000 0
  85. IO count delay total
  86. 0 0
  87. SWAP count delay total
  88. 0 0
  89. RECLAIM count delay total
  90. 0 0