hwlat_detector.txt 3.8 KB

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