forked from andreas-abel/nanoBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel-nanoBench.sh
executable file
·164 lines (153 loc) · 6.61 KB
/
kernel-nanoBench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
source utils.sh
if [ "$EUID" -ne 0 ]; then
echo "Error: nanoBench requires root privileges" >&2
echo "Try \"sudo ./kernel-nanoBench.sh ...\"" >&2
exit 1
fi
if [ ! -e /sys/nb ]; then
echo "Error: nanoBench kernel module not loaded" >&2
echo "Load with \"sudo insmod kernel/nb.ko\"" >&2
exit 1
fi
if [ $(cat /sys/devices/system/cpu/smt/active) -ne 0 ]; then
echo "Note: Hyper-threading is enabled; it can be disabled with \"sudo ./disable-HT.sh\"" >&2
fi
cat /sys/nb/reset
taskset=""
filter_output="cat"
while [ "$1" ]; do
if [[ "$1" == -asm_i* ]]; then
assemble "$2" asm-init.bin
echo -n "asm-init.bin" > /sys/nb/init
rm -f asm-init.bin
shift 2
elif [[ "$1" == -asm_l* ]]; then
assemble "$2" asm-late-init.bin
echo -n "asm-late-init.bin" > /sys/nb/late_init
rm -f asm-late-init.bin
shift 2
elif [[ "$1" == -asm_o* ]]; then
assemble "$2" asm-one-time-init.bin
echo -n "asm-one-time-init.bin" > /sys/nb/one_time_init
rm -f asm-one-time-init.bin
shift 2
elif [[ "$1" == -as* ]]; then
assemble "$2" asm-code.bin
echo -n "asm-code.bin" > /sys/nb/code
rm -f asm-code.bin
shift 2
elif [[ "$1" == -code_i* ]]; then
echo -n "$2" > /sys/nb/init
shift 2
elif [[ "$1" == -code_l* ]]; then
echo -n "$2" > /sys/nb/late_init
shift 2
elif [[ "$1" == -code_o* ]]; then
echo -n "$2" > /sys/nb/one_time_init
shift 2
elif [[ "$1" == -cod* ]]; then
echo -n "$2" > /sys/nb/code
shift 2
elif [[ "$1" == -cpu ]]; then
taskset="taskset -c $2"
shift 2
elif [[ "$1" == -con* ]]; then
echo -n "$2" > /sys/nb/config
shift 2
elif [[ "$1" == -f* ]]; then
echo "1" > /sys/nb/fixed_counters
shift
elif [[ "$1" == -msr* ]]; then
echo -n "$2" > /sys/nb/msr_config
shift 2
elif [[ "$1" == -u* ]]; then
echo "$2" > /sys/nb/unroll_count
shift 2
elif [[ "$1" == -l* ]]; then
echo "$2" > /sys/nb/loop_count
shift 2
elif [[ "$1" == -no_m* ]]; then
echo "1" > /sys/nb/no_mem
shift
elif [[ "$1" == -no_n* ]]; then
echo "1" > /sys/nb/no_normalization
shift
elif [[ "$1" == -n* ]]; then
echo "$2" > /sys/nb/n_measurements
shift 2
elif [[ "$1" == -b* ]]; then
echo "1" > /sys/nb/basic_mode
shift
elif [[ "$1" == -v* ]]; then
echo "1" > /sys/nb/verbose
shift
elif [[ "$1" == -w* ]]; then
echo "$2" > /sys/nb/warm_up
shift 2
elif [[ "$1" == -initial* ]]; then
echo "$2" > /sys/nb/initial_warm_up
shift 2
elif [[ "$1" == -al* ]]; then
echo "$2" > /sys/nb/alignment_offset
shift 2
elif [[ "$1" == -df* ]]; then
echo "1" > /sys/nb/drain_frontend
shift
elif [[ "$1" == -min* ]]; then
echo "min" > /sys/nb/agg
shift
elif [[ "$1" == -max* ]]; then
echo "max" > /sys/nb/agg
shift
elif [[ "$1" == -med* ]]; then
echo "med" > /sys/nb/agg
shift
elif [[ "$1" == -avg* ]]; then
echo "avg" > /sys/nb/agg
shift
elif [[ "$1" == -r* ]]; then
filter_output="grep -v 0.00"
shift
elif [[ "$1" == -h* ]]; then
echo "kernel-nanoBench.sh usage:"
echo
echo " -asm <code>: Assembler code string (in Intel syntax) to be benchmarked."
echo " -asm_init <code>: Assembler code string (in Intel syntax) to be executed once in the beginning."
echo " -asm_late_init <code>: Assembler code string (in Intel syntax) to be executed once immediately before the code to be benchmarked."
echo " -asm_one_time_init <code>: Assembler code string (in Intel syntax) to be executed once before the first measurement."
echo " -code <filename>: Binary file containing the code to be benchmarked."
echo " -code_init <filename>: Binary file containing code to be executed once in the beginning."
echo " -code_late_init <filename>: Binary file containing code to be executed once immediately before the code to be benchmarked."
echo " -code_one_time_init <filename>: Binary file containing code to be executed once before the first measurement."
echo " -config <filename>: File with performance counter event specifications."
echo " -fixed_counters: Reads the fixed-function performance counters.\n"
echo " -n_measurements <n>: Number of times the measurements are repeated."
echo " -unroll_count <n>: Number of copies of the benchmark code inside the inner loop."
echo " -loop_count <n>: Number of iterations of the inner loop."
echo " -warm_up_count <n>: Number of runs before the first measurement gets recorded."
echo " -initial_warm_up_count <n>: Number of runs before any measurement is performed."
echo " -alignment_offset <n>: Alignment offset."
echo " -df: Drains front-end buffers between executing code_late_init and code."
echo " -avg: Selects the arithmetic mean as the aggregate function."
echo " -median: Selects the median as the aggregate function."
echo " -min: Selects the minimum as the aggregate function."
echo " -max: Selects the maximum as the aggregate function."
echo " -basic_mode: Enables basic mode."
echo " -no_mem: The code for reading the perf. ctrs. does not make memory accesses."
echo " -no_normalization: The measurement results are not divided by the number of repetitions."
echo " -remove_empty_events: Removes events from the output that did not occur."
echo " -cpu <n>: Pins the measurement thread to CPU n."
echo " -verbose: Outputs the results of all performance counter readings."
exit 0
else
echo "Invalid option: $1"
exit 1
fi
done
prev_nmi_watchdog=$(cat /proc/sys/kernel/nmi_watchdog)
[ $prev_nmi_watchdog != 0 ] && echo 0 > /proc/sys/kernel/nmi_watchdog
$taskset cat /proc/nanoBench | $filter_output
return_value=${PIPESTATUS[0]}
[ $prev_nmi_watchdog != 0 ] && echo $prev_nmi_watchdog > /proc/sys/kernel/nmi_watchdog
exit $return_value