Path: blob/master/tools/perf/Documentation/cpu-and-latency-overheads.txt
26282 views
CPU and latency overheads1-------------------------2There are two notions of time: wall-clock time and CPU time.3For a single-threaded program, or a program running on a single-core machine,4these notions are the same. However, for a multi-threaded/multi-process program5running on a multi-core machine, these notions are significantly different.6Each second of wall-clock time we have number-of-cores seconds of CPU time.7Perf can measure overhead for both of these times (shown in 'overhead' and8'latency' columns for CPU and wall-clock time correspondingly).910Optimizing CPU overhead is useful to improve 'throughput', while optimizing11latency overhead is useful to improve 'latency'. It's important to understand12which one is useful in a concrete situation at hand. For example, the former13may be useful to improve max throughput of a CI build server that runs on 100%14CPU utilization, while the latter may be useful to improve user-perceived15latency of a single interactive program build.16These overheads may be significantly different in some cases. For example,17consider a program that executes function 'foo' for 9 seconds with 1 thread,18and then executes function 'bar' for 1 second with 128 threads (consumes19128 seconds of CPU time). The CPU overhead is: 'foo' - 6.6%, 'bar' - 93.4%.20While the latency overhead is: 'foo' - 90%, 'bar' - 10%. If we try to optimize21running time of the program looking at the (wrong in this case) CPU overhead,22we would concentrate on the function 'bar', but it can yield only 10% running23time improvement at best.2425By default, perf shows only CPU overhead. To show latency overhead, use26'perf record --latency' and 'perf report':2728-----------------------------------29Overhead Latency Command3093.88% 25.79% cc1311.90% 39.87% gzip320.99% 10.16% dpkg-deb330.57% 1.00% as340.40% 0.46% sh35-----------------------------------3637To sort by latency overhead, use 'perf report --latency':3839-----------------------------------40Latency Overhead Command4139.87% 1.90% gzip4225.79% 93.88% cc14310.16% 0.99% dpkg-deb444.17% 0.29% git452.81% 0.11% objtool46-----------------------------------4748To get insight into the difference between the overheads, you may check49parallelization histogram with '--sort=latency,parallelism,comm,symbol --hierarchy'50flags. It shows fraction of (wall-clock) time the workload utilizes different51numbers of cores ('Parallelism' column). For example, in the following case52the workload utilizes only 1 core most of the time, but also has some53highly-parallel phases, which explains significant difference between54CPU and wall-clock overheads:5556-----------------------------------57Latency Overhead Parallelism / Command / Symbol58+ 56.98% 2.29% 159+ 16.94% 1.36% 260+ 4.00% 20.13% 12561+ 3.66% 18.25% 12462+ 3.48% 17.66% 12663+ 3.26% 0.39% 364+ 2.61% 12.93% 12365-----------------------------------6667By expanding corresponding lines, you may see what commands/functions run68at the given parallelism level:6970-----------------------------------71Latency Overhead Parallelism / Command / Symbol72- 56.98% 2.29% 17332.80% 1.32% gzip744.46% 0.18% cc1752.81% 0.11% objtool762.43% 0.10% dpkg-source772.22% 0.09% ld782.10% 0.08% dpkg-genchanges79-----------------------------------8081To see the normal function-level profile for particular parallelism levels82(number of threads actively running on CPUs), you may use '--parallelism'83filter. For example, to see the profile only for low parallelism phases84of a workload use '--latency --parallelism=1-2' flags.858687