blob: cb61516483d30be2535600c6ac81765aa2bfcca2 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001Introduction:
2-------------
3
4The module hwlat_detector is a special purpose kernel module that is used to
5detect large system latencies induced by the behavior of certain underlying
6hardware or firmware, independent of Linux itself. The code was developed
7originally to detect SMIs (System Management Interrupts) on x86 systems,
8however there is nothing x86 specific about this patchset. It was
9originally written for use by the "RT" patch since the Real Time
10kernel is highly latency sensitive.
11
12SMIs are usually not serviced by the Linux kernel, which typically does not
13even know that they are occuring. SMIs are instead are set up by BIOS code
14and are serviced by BIOS code, usually for "critical" events such as
15management of thermal sensors and fans. Sometimes though, SMIs are used for
16other tasks and those tasks can spend an inordinate amount of time in the
17handler (sometimes measured in milliseconds). Obviously this is a problem if
18you are trying to keep event service latencies down in the microsecond range.
19
20The hardware latency detector works by hogging all of the cpus for configurable
21amounts of time (by calling stop_machine()), polling the CPU Time Stamp Counter
22for some period, then looking for gaps in the TSC data. Any gap indicates a
23time when the polling was interrupted and since the machine is stopped and
24interrupts turned off the only thing that could do that would be an SMI.
25
26Note that the SMI detector should *NEVER* be used in a production environment.
27It is intended to be run manually to determine if the hardware platform has a
28problem with long system firmware service routines.
29
30Usage:
31------
32
33Loading the module hwlat_detector passing the parameter "enabled=1" (or by
34setting the "enable" entry in "hwlat_detector" debugfs toggled on) is the only
35step required to start the hwlat_detector. It is possible to redefine the
36threshold in microseconds (us) above which latency spikes will be taken
37into account (parameter "threshold=").
38
39Example:
40
41 # modprobe hwlat_detector enabled=1 threshold=100
42
43After the module is loaded, it creates a directory named "hwlat_detector" under
44the debugfs mountpoint, "/debug/hwlat_detector" for this text. It is necessary
45to have debugfs mounted, which might be on /sys/debug on your system.
46
47The /debug/hwlat_detector interface contains the following files:
48
49count - number of latency spikes observed since last reset
50enable - a global enable/disable toggle (0/1), resets count
51max - maximum hardware latency actually observed (usecs)
52sample - a pipe from which to read current raw sample data
53 in the format <timestamp> <latency observed usecs>
54 (can be opened O_NONBLOCK for a single sample)
55threshold - minimum latency value to be considered (usecs)
56width - time period to sample with CPUs held (usecs)
57 must be less than the total window size (enforced)
58window - total period of sampling, width being inside (usecs)
59
60By default we will set width to 500,000 and window to 1,000,000, meaning that
61we will sample every 1,000,000 usecs (1s) for 500,000 usecs (0.5s). If we
62observe any latencies that exceed the threshold (initially 100 usecs),
63then we write to a global sample ring buffer of 8K samples, which is
64consumed by reading from the "sample" (pipe) debugfs file interface.