delay-accounting.txt 3.7 KB

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