2 # SPDX-License-Identifier: GPL-2.0
4 # Return true if perf_event_paranoid is > $1 and not running as root.
5 function ParanoidAndNotRoot
()
7 [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
10 # $1 name $2 extra_opt
13 echo -n "Checking $1 output: no args "
15 commachecker
--no-args
21 echo -n "Checking $1 output: system wide "
22 if ParanoidAndNotRoot
0
24 echo "[Skip] paranoid and not root"
28 commachecker
--system-wide
32 check_system_wide_no_aggr
()
34 echo -n "Checking $1 output: system wide no aggregation "
35 if ParanoidAndNotRoot
0
37 echo "[Skip] paranoid and not root"
40 perf stat
-A -a --no-merge $2 true
41 commachecker
--system-wide-no-aggr
47 echo -n "Checking $1 output: interval "
48 perf stat
-I 1000 $2 true
49 commachecker
--interval
55 echo -n "Checking $1 output: event "
56 perf stat
-e cpu-clock
$2 true
63 echo -n "Checking $1 output: per core "
64 if ParanoidAndNotRoot
0
66 echo "[Skip] paranoid and not root"
69 perf stat
--per-core -a $2 true
70 commachecker
--per-core
76 echo -n "Checking $1 output: per thread "
77 if ParanoidAndNotRoot
0
79 echo "[Skip] paranoid and not root"
82 perf stat
--per-thread -p $$
$2 true
83 commachecker
--per-thread
87 check_per_cache_instance
()
89 echo -n "Checking $1 output: per cache instance "
90 if ParanoidAndNotRoot
0
92 echo "[Skip] paranoid and not root"
95 perf stat
--per-cache -a $2 true
96 commachecker
--per-cache
102 echo -n "Checking $1 output: per cluster "
103 if ParanoidAndNotRoot
0
105 echo "[Skip] paranoid and not root"
108 perf stat
--per-cluster -a $2 true
114 echo -n "Checking $1 output: per die "
115 if ParanoidAndNotRoot
0
117 echo "[Skip] paranoid and not root"
120 perf stat
--per-die -a $2 true
121 commachecker
--per-die
127 echo -n "Checking $1 output: per node "
128 if ParanoidAndNotRoot
0
130 echo "[Skip] paranoid and not root"
133 perf stat
--per-node -a $2 true
134 commachecker
--per-node
140 echo -n "Checking $1 output: per socket "
141 if ParanoidAndNotRoot
0
143 echo "[Skip] paranoid and not root"
146 perf stat
--per-socket -a $2 true
147 commachecker
--per-socket
151 # The perf stat options for per-socket, per-core, per-die
152 # and -A ( no_aggr mode ) uses the info fetched from this
153 # directory: "/sys/devices/system/cpu/cpu*/topology". For
154 # example, socket value is fetched from "physical_package_id"
155 # file in topology directory.
156 # Reference: cpu__get_topology_int in util/cpumap.c
157 # If the platform doesn't expose topology information, values
158 # will be set to -1. For example, incase of pSeries platform
159 # of powerpc, value for "physical_package_id" is restricted
160 # and set to -1. Check here validates the socket-id read from
161 # topology file before proceeding further
163 FILE_LOC
="/sys/devices/system/cpu/cpu*/topology/"
164 FILE_NAME
="physical_package_id"
166 function check_for_topology
()
168 if ! ParanoidAndNotRoot
0
170 socket_file
=`ls $FILE_LOC/$FILE_NAME | head -n 1`
171 [ -z $socket_file ] && {
175 socket_id
=`cat $socket_file`
176 [ $socket_id == -1 ] && {