hwlat_detector.rst 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. =========================
  2. Hardware Latency Detector
  3. =========================
  4. Introduction
  5. -------------
  6. The tracer hwlat_detector is a special purpose tracer that is used to
  7. detect large system latencies induced by the behavior of certain underlying
  8. hardware or firmware, independent of Linux itself. The code was developed
  9. originally to detect SMIs (System Management Interrupts) on x86 systems,
  10. however there is nothing x86 specific about this patchset. It was
  11. originally written for use by the "RT" patch since the Real Time
  12. kernel is highly latency sensitive.
  13. SMIs are not serviced by the Linux kernel, which means that it does not
  14. even know that they are occuring. SMIs are instead set up by BIOS code
  15. and are serviced by BIOS code, usually for "critical" events such as
  16. management of thermal sensors and fans. Sometimes though, SMIs are used for
  17. other tasks and those tasks can spend an inordinate amount of time in the
  18. handler (sometimes measured in milliseconds). Obviously this is a problem if
  19. you are trying to keep event service latencies down in the microsecond range.
  20. The hardware latency detector works by hogging one of the cpus for configurable
  21. amounts of time (with interrupts disabled), polling the CPU Time Stamp Counter
  22. for some period, then looking for gaps in the TSC data. Any gap indicates a
  23. time when the polling was interrupted and since the interrupts are disabled,
  24. the only thing that could do that would be an SMI or other hardware hiccup
  25. (or an NMI, but those can be tracked).
  26. Note that the hwlat detector should *NEVER* be used in a production environment.
  27. It is intended to be run manually to determine if the hardware platform has a
  28. problem with long system firmware service routines.
  29. Usage
  30. ------
  31. Write the ASCII text "hwlat" into the current_tracer file of the tracing system
  32. (mounted at /sys/kernel/tracing or /sys/kernel/tracing). It is possible to
  33. redefine the threshold in microseconds (us) above which latency spikes will
  34. be taken into account.
  35. Example::
  36. # echo hwlat > /sys/kernel/tracing/current_tracer
  37. # echo 100 > /sys/kernel/tracing/tracing_thresh
  38. The /sys/kernel/tracing/hwlat_detector interface contains the following files:
  39. - width - time period to sample with CPUs held (usecs)
  40. must be less than the total window size (enforced)
  41. - window - total period of sampling, width being inside (usecs)
  42. By default the width is set to 500,000 and window to 1,000,000, meaning that
  43. for every 1,000,000 usecs (1s) the hwlat detector will spin for 500,000 usecs
  44. (0.5s). If tracing_thresh contains zero when hwlat tracer is enabled, it will
  45. change to a default of 10 usecs. If any latencies that exceed the threshold is
  46. observed then the data will be written to the tracing ring buffer.
  47. The minimum sleep time between periods is 1 millisecond. Even if width
  48. is less than 1 millisecond apart from window, to allow the system to not
  49. be totally starved.
  50. If tracing_thresh was zero when hwlat detector was started, it will be set
  51. back to zero if another tracer is loaded. Note, the last value in
  52. tracing_thresh that hwlat detector had will be saved and this value will
  53. be restored in tracing_thresh if it is still zero when hwlat detector is
  54. started again.
  55. The following tracing directory files are used by the hwlat_detector:
  56. in /sys/kernel/tracing:
  57. - tracing_threshold - minimum latency value to be considered (usecs)
  58. - tracing_max_latency - maximum hardware latency actually observed (usecs)
  59. - tracing_cpumask - the CPUs to move the hwlat thread across
  60. - hwlat_detector/width - specified amount of time to spin within window (usecs)
  61. - hwlat_detector/window - amount of time between (width) runs (usecs)
  62. The hwlat detector's kernel thread will migrate across each CPU specified in
  63. tracing_cpumask between each window. To limit the migration, either modify
  64. tracing_cpumask, or modify the hwlat kernel thread (named [hwlatd]) CPU
  65. affinity directly, and the migration will stop.