• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Test Case 1
4#
5# Based on script by Ashok Raj <ashok.raj@intel.com>
6# Modified by Mark D and Bryce, Aug '05.
7
8export TCID="cpuhotplug01"
9export TST_TOTAL=1
10
11# Includes:
12. test.sh
13. cpuhotplug_testsuite.sh
14. cpuhotplug_hotplug.sh
15
16cat <<EOF
17Name:   $TCID
18Date:   `date`
19Desc:   What happens to disk controller interrupts when offlining CPUs?
20
21EOF
22
23usage()
24{
25	cat << EOF
26	usage: $0 -c cpu -l loop -n timeon -f timeoff -e timed
27
28	OPTIONS
29		-c  cpu which is specified for testing
30		-l  number of cycle test
31		-n	time delay after an online of cpu
32		-f	time delay after offline of cpu
33		-e	time delay before start of entire new cycle
34
35EOF
36	exit 1
37}
38
39# do_clean()
40#
41#  Callback to be executed when script exits from a user interrupt
42#  or regular program termination
43#
44do_clean()
45{
46	kill_pid ${WRL_ID}
47
48	# Restore CPU states
49	set_all_cpu_states "$cpu_states"
50}
51
52
53# do_offline(CPU)
54#
55#  Migrates some irq's onto the CPU, then offlines it
56#
57do_offline()
58{
59	CPU=${1#cpu}
60	# Migrate some irq's this way first.
61	IRQS=`get_all_irqs`
62	migrate_irq "${CPU}" "${IRQS}"
63	offline_cpu ${CPU}
64	if [ $? -ne 0 ]; then
65		if [ "$CPU" -ne 0 ]; then
66			CPU_COUNT=$((CPU_COUNT+1))
67			eval "OFFLINE_CPU_${CPU_COUNT}=$1"
68		fi
69		return 1
70	fi
71	return 0
72}
73
74
75# do_online(CPU)
76#
77#  Onlines the CPU and then sets the smp_affinity of all IRQs to
78#  this CPU.
79#
80do_online()
81{
82	CPU=${1#cpu}
83	online_cpu ${CPU}
84	if [ $? -ne 0 ]; then
85		return 1
86	fi
87	migrate_irq ${CPU}
88	if [ $? -ne 0 ]; then
89		return 1
90	fi
91}
92
93while getopts c:l:n:f:e: OPTION; do
94	case $OPTION in
95	c)
96		CPU_TO_TEST=$OPTARG;;
97	l)
98		HOTPLUG01_LOOPS=$OPTARG;;
99	n)
100		TM_ONLINE=$OPTARG;;
101	f)
102		TM_OFFLINE=$OPTARG;;
103	e)
104		TM_DLY=$OPTARG;;
105	?)
106		usage;;
107	esac
108done
109
110LOOP_COUNT=1
111
112tst_require_cmds perl
113
114if tst_virt_hyperv; then
115	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
116fi
117
118if [ $(get_present_cpus_num) -lt 2 ]; then
119	tst_brkm TCONF "system doesn't have required CPU hotplug support"
120fi
121
122if [ -z "${CPU_TO_TEST}" ]; then
123	tst_brkm TBROK "usage: ${0##*/} <CPU to online>"
124fi
125
126# Validate the specified CPU is available
127if ! cpu_is_valid "${CPU_TO_TEST}" ; then
128	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
129fi
130
131if ! cpu_is_online "${CPU_TO_TEST}" ; then
132	if ! online_cpu ${CPU_TO_TEST} ; then
133		tst_brkm TBROK "Could not online cpu $CPU_TO_TEST"
134	fi
135fi
136
137TST_CLEANUP=do_clean
138
139cpu_states=$(get_all_cpu_states)
140
141CPU_COUNT=0
142
143# Start up a process that writes to disk; keep track of its PID
144cpuhotplug_do_disk_write_loop > /dev/null 2>&1 &
145WRL_ID=$!
146
147until [ $LOOP_COUNT -gt $HOTPLUG01_LOOPS ]
148do
149
150	tst_resm TINFO "Starting loop"
151	IRQ_START=$(cat /proc/interrupts)
152
153	# Attempt to offline all CPUs
154	for cpu in $( get_hotplug_cpus ); do
155		if [ "$cpu" = "cpu0" ]; then
156			continue
157		fi
158		do_offline $cpu
159		err=$?
160		if [ $err -ne 0 ]; then
161			tst_brkm TBROK "offlining $cpu failed: $err"
162		else
163			tst_resm TINFO "offlining $cpu was ok"
164		fi
165		sleep $TM_OFFLINE
166	done
167
168	# Attempt to online all CPUs
169	for cpu in $( get_hotplug_cpus ); do
170		if [ "$cpu" = "cpu0" ]; then
171			continue
172		fi
173		do_online $cpu
174		err=$?
175		if [ $err -ne 0 ]; then
176			tst_brkm TBROK "onlining $cpu failed: $err"
177		else
178			tst_resm TINFO "onlining $cpu was ok"
179		fi
180		sleep $TM_ONLINE
181	done
182
183	IRQ_END=`cat /proc/interrupts`
184
185	# Print out a report showing the changes in IRQs
186	echo
187	echo
188	cpuhotplug_report_proc_interrupts "$IRQ_START" "$IRQ_END"
189	echo
190
191	sleep $TM_DLY
192	LOOP_COUNT=$((LOOP_COUNT+1))
193
194done
195
196tst_resm TPASS "online and offline cpu${CPU} when writing disk"
197
198tst_exit
199