10 echo $msg must be run as root
>&2
16 SYSFS
=`mount -t sysfs | head -1 | awk '{ print $3 }'`
18 if [ ! -d "$SYSFS" ]; then
19 echo $msg sysfs is not mounted
>&2
23 if ! ls $SYSFS/devices
/system
/cpu
/cpu
* > /dev
/null
2>&1; then
24 echo $msg cpu hotplug is not supported
>&2
28 echo "CPU online/offline summary:"
29 online_cpus
=`cat $SYSFS/devices/system/cpu/online`
30 online_max
=${online_cpus##*-}
31 echo -e "\t Cpus in online state: $online_cpus"
33 offline_cpus
=`cat $SYSFS/devices/system/cpu/offline`
34 if [[ "a$offline_cpus" = "a" ]]; then
37 offline_max
=${offline_cpus##*-}
39 echo -e "\t Cpus in offline state: $offline_cpus"
43 # list all hot-pluggable CPUs
49 for cpu
in $SYSFS/devices
/system
/cpu
/cpu
*; do
50 if [ -f $cpu/online
] && grep -q $state $cpu/online
; then
56 hotplaggable_offline_cpus
()
61 hotpluggable_online_cpus
()
68 grep -q 1 $SYSFS/devices
/system
/cpu
/cpu
$1/online
73 grep -q 0 $SYSFS/devices
/system
/cpu
/cpu
$1/online
78 echo 1 > $SYSFS/devices
/system
/cpu
/cpu
$1/online
83 echo 0 > $SYSFS/devices
/system
/cpu
/cpu
$1/online
86 online_cpu_expect_success
()
90 if ! online_cpu
$cpu; then
91 echo $FUNCNAME $cpu: unexpected fail
>&2
92 elif ! cpu_is_online
$cpu; then
93 echo $FUNCNAME $cpu: unexpected offline
>&2
97 online_cpu_expect_fail
()
101 if online_cpu
$cpu 2> /dev
/null
; then
102 echo $FUNCNAME $cpu: unexpected success
>&2
103 elif ! cpu_is_offline
$cpu; then
104 echo $FUNCNAME $cpu: unexpected online
>&2
108 offline_cpu_expect_success
()
112 if ! offline_cpu
$cpu; then
113 echo $FUNCNAME $cpu: unexpected fail
>&2
114 elif ! cpu_is_offline
$cpu; then
115 echo $FUNCNAME $cpu: unexpected offline
>&2
119 offline_cpu_expect_fail
()
123 if offline_cpu
$cpu 2> /dev
/null
; then
124 echo $FUNCNAME $cpu: unexpected success
>&2
125 elif ! cpu_is_online
$cpu; then
126 echo $FUNCNAME $cpu: unexpected offline
>&2
138 while getopts e
:ahp
: opt
; do
147 echo "Usage $0 [ -a ] [ -e errno ] [ -p notifier-priority ]"
148 echo -e "\t default offline one cpu"
149 echo -e "\t run with -a option to offline all cpus"
158 if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then
159 echo "error code must be -4095 <= errno < 0" >&2
166 # Safe test (default) - offline and online one cpu
168 if [ $allcpus -eq 0 ]; then
169 echo "Limited scope test: one hotplug cpu"
170 echo -e "\t (leaves cpu in the original state):"
171 echo -e "\t online to offline to online: cpu $online_max"
172 offline_cpu_expect_success
$online_max
173 online_cpu_expect_success
$online_max
175 if [[ $offline_cpus -gt 0 ]]; then
176 echo -e "\t offline to online to offline: cpu $offline_max"
177 online_cpu_expect_success
$offline_max
178 offline_cpu_expect_success
$offline_max
182 echo "Full scope test: all hotplug cpus"
183 echo -e "\t online all offline cpus"
184 echo -e "\t offline all online cpus"
185 echo -e "\t online all offline cpus"
189 # Online all hot-pluggable CPUs
191 for cpu
in `hotplaggable_offline_cpus`; do
192 online_cpu_expect_success
$cpu
196 # Offline all hot-pluggable CPUs
198 for cpu
in `hotpluggable_online_cpus`; do
199 offline_cpu_expect_success
$cpu
203 # Online all hot-pluggable CPUs again
205 for cpu
in `hotplaggable_offline_cpus`; do
206 online_cpu_expect_success
$cpu
210 # Test with cpu notifier error injection
213 DEBUGFS
=`mount -t debugfs | head -1 | awk '{ print $3 }'`
214 NOTIFIER_ERR_INJECT_DIR
=$DEBUGFS/notifier-error-inject
/cpu
218 msg
="skip extra tests:"
220 /sbin
/modprobe
-q -r cpu-notifier-error-inject
221 /sbin
/modprobe
-q cpu-notifier-error-inject priority
=$priority
223 if [ ! -d "$DEBUGFS" ]; then
224 echo $msg debugfs is not mounted
>&2
228 if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
229 echo $msg cpu-notifier-error-inject module is not available
>&2
237 # Offline all hot-pluggable CPUs
239 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions
/CPU_DOWN_PREPARE
/error
240 for cpu
in `hotpluggable_online_cpus`; do
241 offline_cpu_expect_success
$cpu
245 # Test CPU hot-add error handling (offline => online)
247 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions
/CPU_UP_PREPARE
/error
248 for cpu
in `hotplaggable_offline_cpus`; do
249 online_cpu_expect_fail
$cpu
253 # Online all hot-pluggable CPUs
255 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions
/CPU_UP_PREPARE
/error
256 for cpu
in `hotplaggable_offline_cpus`; do
257 online_cpu_expect_success
$cpu
261 # Test CPU hot-remove error handling (online => offline)
263 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions
/CPU_DOWN_PREPARE
/error
264 for cpu
in `hotpluggable_online_cpus`; do
265 offline_cpu_expect_fail
$cpu
268 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions
/CPU_DOWN_PREPARE
/error
269 /sbin
/modprobe
-q -r cpu-notifier-error-inject