delay-accounting.txt 3.7 KB

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