1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 # Return true if perf_event_paranoid is > $1 a 4 # Return true if perf_event_paranoid is > $1 and not running as root. 5 function ParanoidAndNotRoot() 5 function ParanoidAndNotRoot() 6 { 6 { 7 [ "$(id -u)" != 0 ] && [ "$(cat /proc 7 [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 8 } 8 } 9 9 10 # $1 name $2 extra_opt 10 # $1 name $2 extra_opt 11 check_no_args() 11 check_no_args() 12 { 12 { 13 echo -n "Checking $1 output: no args " 13 echo -n "Checking $1 output: no args " 14 perf stat $2 true 14 perf stat $2 true 15 commachecker --no-args 15 commachecker --no-args 16 echo "[Success]" 16 echo "[Success]" 17 } 17 } 18 18 19 check_system_wide() 19 check_system_wide() 20 { 20 { 21 echo -n "Checking $1 output: system wi 21 echo -n "Checking $1 output: system wide " 22 if ParanoidAndNotRoot 0 22 if ParanoidAndNotRoot 0 23 then 23 then 24 echo "[Skip] paranoid and not 24 echo "[Skip] paranoid and not root" 25 return 25 return 26 fi 26 fi 27 perf stat -a $2 true 27 perf stat -a $2 true 28 commachecker --system-wide 28 commachecker --system-wide 29 echo "[Success]" 29 echo "[Success]" 30 } 30 } 31 31 32 check_system_wide_no_aggr() 32 check_system_wide_no_aggr() 33 { 33 { 34 echo -n "Checking $1 output: system wi 34 echo -n "Checking $1 output: system wide no aggregation " 35 if ParanoidAndNotRoot 0 35 if ParanoidAndNotRoot 0 36 then 36 then 37 echo "[Skip] paranoid and not 37 echo "[Skip] paranoid and not root" 38 return 38 return 39 fi 39 fi 40 perf stat -A -a --no-merge $2 true 40 perf stat -A -a --no-merge $2 true 41 commachecker --system-wide-no-aggr 41 commachecker --system-wide-no-aggr 42 echo "[Success]" 42 echo "[Success]" 43 } 43 } 44 44 45 check_interval() 45 check_interval() 46 { 46 { 47 echo -n "Checking $1 output: interval 47 echo -n "Checking $1 output: interval " 48 perf stat -I 1000 $2 true 48 perf stat -I 1000 $2 true 49 commachecker --interval 49 commachecker --interval 50 echo "[Success]" 50 echo "[Success]" 51 } 51 } 52 52 53 check_event() 53 check_event() 54 { 54 { 55 echo -n "Checking $1 output: event " 55 echo -n "Checking $1 output: event " 56 perf stat -e cpu-clock $2 true 56 perf stat -e cpu-clock $2 true 57 commachecker --event 57 commachecker --event 58 echo "[Success]" 58 echo "[Success]" 59 } 59 } 60 60 61 check_per_core() 61 check_per_core() 62 { 62 { 63 echo -n "Checking $1 output: per core 63 echo -n "Checking $1 output: per core " 64 if ParanoidAndNotRoot 0 64 if ParanoidAndNotRoot 0 65 then 65 then 66 echo "[Skip] paranoid and not 66 echo "[Skip] paranoid and not root" 67 return 67 return 68 fi 68 fi 69 perf stat --per-core -a $2 true 69 perf stat --per-core -a $2 true 70 commachecker --per-core 70 commachecker --per-core 71 echo "[Success]" 71 echo "[Success]" 72 } 72 } 73 73 74 check_per_thread() 74 check_per_thread() 75 { 75 { 76 echo -n "Checking $1 output: per threa 76 echo -n "Checking $1 output: per thread " 77 if ParanoidAndNotRoot 0 77 if ParanoidAndNotRoot 0 78 then 78 then 79 echo "[Skip] paranoid and not 79 echo "[Skip] paranoid and not root" 80 return 80 return 81 fi 81 fi 82 perf stat --per-thread -p $$ $2 true 82 perf stat --per-thread -p $$ $2 true 83 commachecker --per-thread 83 commachecker --per-thread 84 echo "[Success]" 84 echo "[Success]" 85 } 85 } 86 86 87 check_per_cache_instance() 87 check_per_cache_instance() 88 { 88 { 89 echo -n "Checking $1 output: per cache 89 echo -n "Checking $1 output: per cache instance " 90 if ParanoidAndNotRoot 0 90 if ParanoidAndNotRoot 0 91 then 91 then 92 echo "[Skip] paranoid and not 92 echo "[Skip] paranoid and not root" 93 return 93 return 94 fi 94 fi 95 perf stat --per-cache -a $2 true 95 perf stat --per-cache -a $2 true 96 commachecker --per-cache 96 commachecker --per-cache 97 echo "[Success]" 97 echo "[Success]" 98 } 98 } 99 99 100 check_per_cluster() 100 check_per_cluster() 101 { 101 { 102 echo -n "Checking $1 output: per clust 102 echo -n "Checking $1 output: per cluster " 103 if ParanoidAndNotRoot 0 103 if ParanoidAndNotRoot 0 104 then 104 then 105 echo "[Skip] paranoid and not 105 echo "[Skip] paranoid and not root" 106 return 106 return 107 fi 107 fi 108 perf stat --per-cluster -a $2 true 108 perf stat --per-cluster -a $2 true 109 echo "[Success]" 109 echo "[Success]" 110 } 110 } 111 111 112 check_per_die() 112 check_per_die() 113 { 113 { 114 echo -n "Checking $1 output: per die " 114 echo -n "Checking $1 output: per die " 115 if ParanoidAndNotRoot 0 115 if ParanoidAndNotRoot 0 116 then 116 then 117 echo "[Skip] paranoid and not 117 echo "[Skip] paranoid and not root" 118 return 118 return 119 fi 119 fi 120 perf stat --per-die -a $2 true 120 perf stat --per-die -a $2 true 121 commachecker --per-die 121 commachecker --per-die 122 echo "[Success]" 122 echo "[Success]" 123 } 123 } 124 124 125 check_per_node() 125 check_per_node() 126 { 126 { 127 echo -n "Checking $1 output: per node 127 echo -n "Checking $1 output: per node " 128 if ParanoidAndNotRoot 0 128 if ParanoidAndNotRoot 0 129 then 129 then 130 echo "[Skip] paranoid and not 130 echo "[Skip] paranoid and not root" 131 return 131 return 132 fi 132 fi 133 perf stat --per-node -a $2 true 133 perf stat --per-node -a $2 true 134 commachecker --per-node 134 commachecker --per-node 135 echo "[Success]" 135 echo "[Success]" 136 } 136 } 137 137 138 check_per_socket() 138 check_per_socket() 139 { 139 { 140 echo -n "Checking $1 output: per socke 140 echo -n "Checking $1 output: per socket " 141 if ParanoidAndNotRoot 0 141 if ParanoidAndNotRoot 0 142 then 142 then 143 echo "[Skip] paranoid and not 143 echo "[Skip] paranoid and not root" 144 return 144 return 145 fi 145 fi 146 perf stat --per-socket -a $2 true 146 perf stat --per-socket -a $2 true 147 commachecker --per-socket 147 commachecker --per-socket 148 echo "[Success]" 148 echo "[Success]" 149 } 149 } 150 150 151 # The perf stat options for per-socket, per-co 151 # The perf stat options for per-socket, per-core, per-die 152 # and -A ( no_aggr mode ) uses the info fetche 152 # and -A ( no_aggr mode ) uses the info fetched from this 153 # directory: "/sys/devices/system/cpu/cpu*/top 153 # directory: "/sys/devices/system/cpu/cpu*/topology". For 154 # example, socket value is fetched from "physi 154 # example, socket value is fetched from "physical_package_id" 155 # file in topology directory. 155 # file in topology directory. 156 # Reference: cpu__get_topology_int in util/cpu 156 # Reference: cpu__get_topology_int in util/cpumap.c 157 # If the platform doesn't expose topology info 157 # If the platform doesn't expose topology information, values 158 # will be set to -1. For example, incase of pS 158 # will be set to -1. For example, incase of pSeries platform 159 # of powerpc, value for "physical_package_id" 159 # of powerpc, value for "physical_package_id" is restricted 160 # and set to -1. Check here validates the sock 160 # and set to -1. Check here validates the socket-id read from 161 # topology file before proceeding further 161 # topology file before proceeding further 162 162 163 FILE_LOC="/sys/devices/system/cpu/cpu*/topolog 163 FILE_LOC="/sys/devices/system/cpu/cpu*/topology/" 164 FILE_NAME="physical_package_id" 164 FILE_NAME="physical_package_id" 165 165 166 function check_for_topology() 166 function check_for_topology() 167 { 167 { 168 if ! ParanoidAndNotRoot 0 168 if ! ParanoidAndNotRoot 0 169 then 169 then 170 socket_file=`ls $FILE_LOC/$FIL 170 socket_file=`ls $FILE_LOC/$FILE_NAME | head -n 1` 171 [ -z $socket_file ] && { 171 [ -z $socket_file ] && { 172 echo 0 172 echo 0 173 return 173 return 174 } 174 } 175 socket_id=`cat $socket_file` 175 socket_id=`cat $socket_file` 176 [ $socket_id == -1 ] && { 176 [ $socket_id == -1 ] && { 177 echo 1 177 echo 1 178 return 178 return 179 } 179 } 180 fi 180 fi 181 echo 0 181 echo 0 182 } 182 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.