annotate docs/Benchmarking.rst @ 124:4fa72497ed5d

fix
author mir3636
date Thu, 30 Nov 2017 20:04:56 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 ==================================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 Benchmarking tips
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 ==================================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 Introduction
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 ============
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 For benchmarking a patch we want to reduce all possible sources of
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 noise as much as possible. How to do that is very OS dependent.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 Note that low noise is required, but not sufficient. It does not
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 exclude measurement bias. See
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 https://www.cis.upenn.edu/~cis501/papers/producing-wrong-data.pdf for
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 example.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 General
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 ================================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 * Use a high resolution timer, e.g. perf under linux.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 * Run the benchmark multiple times to be able to recognize noise.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 * Disable as many processes or services as possible on the target system.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 * Disable frequency scaling, turbo boost and address space
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 randomization (see OS specific section).
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 * Static link if the OS supports it. That avoids any variation that
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 might be introduced by loading dynamic libraries. This can be done
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 by passing ``-DLLVM_BUILD_STATIC=ON`` to cmake.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 * Try to avoid storage. On some systems you can use tmpfs. Putting the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 program, inputs and outputs on tmpfs avoids touching a real storage
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 system, which can have a pretty big variability.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 To mount it (on linux and freebsd at least)::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 mount -t tmpfs -o size=<XX>g none dir_to_mount
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 Linux
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 =====
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 * Disable address space randomization::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 echo 0 > /proc/sys/kernel/randomize_va_space
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 * Set scaling_governor to performance::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 do
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 echo performance > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 done
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 * Use https://github.com/lpechacek/cpuset to reserve cpus for just the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 program you are benchmarking. If using perf, leave at least 2 cores
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 so that perf runs in one and your program in another::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 cset shield -c N1,N2 -k on
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 This will move all threads out of N1 and N2. The ``-k on`` means
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 that even kernel threads are moved out.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 * Disable the SMT pair of the cpus you will use for the benchmark. The
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 pair of cpu N can be found in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 ``/sys/devices/system/cpu/cpuN/topology/thread_siblings_list`` and
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 disabled with::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 echo 0 > /sys/devices/system/cpu/cpuX/online
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 * Run the program with::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 cset shield --exec -- perf stat -r 10 <cmd>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 This will run the command after ``--`` in the isolated cpus. The
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 particular perf command runs the ``<cmd>`` 10 times and reports
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 statistics.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 With these in place you can expect perf variations of less than 0.1%.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 Linux Intel
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 -----------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 * Disable turbo mode::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo