• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Test Case 3
4#
5
6export TCID="cpuhotplug03"
7export TST_TOTAL=1
8
9# Includes:
10. test.sh
11. cpuhotplug_testsuite.sh
12. cpuhotplug_hotplug.sh
13
14cat <<EOF
15Name:   $TCID
16Date:   `date`
17Desc:   Do tasks get scheduled to a newly on-lined CPU?
18
19EOF
20
21usage()
22{
23	cat << EOF
24	usage: $0 -c cpu -l loop
25
26	OPTIONS
27		-c  cpu which is specified for testing
28		-l  number of cycle test
29
30EOF
31	exit 1
32}
33
34# do_clean()
35#
36#  Callback to be executed when script exits from a user interrupt
37#  or regular program termination
38#
39do_clean()
40{
41	# Kill all the processes we started up and get rid of their pid files
42	if [ -e "/var/run/hotplug4_$$.pid" ]; then
43		for i in `cat /var/run/hotplug4_$$.pid`; do
44			kill_pid $i
45		done
46		rm /var/run/hotplug4_$$.pid
47	fi
48
49	# Restore CPU states
50	set_all_cpu_states "$cpu_states"
51}
52
53while getopts c:l: OPTION; do
54case $OPTION in
55	c)
56		CPU_TO_TEST=$OPTARG;;
57	l)
58		HOTPLUG03_LOOPS=$OPTARG;;
59	?)
60		usage;;
61	esac
62done
63
64LOOP_COUNT=1
65
66if tst_virt_hyperv; then
67	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
68fi
69
70cpus_num=$(get_present_cpus_num)
71if [ $cpus_num -lt 2 ]; then
72	tst_brkm TCONF "system doesn't have required CPU hotplug support"
73fi
74
75if [ -z $CPU_TO_TEST ]; then
76	tst_brkm TBROK "usage: ${0##*} <CPU to online>"
77fi
78
79# Validate the specified CPU is available
80if ! cpu_is_valid "${CPU_TO_TEST}" ; then
81	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
82fi
83
84TST_CLEANUP=do_clean
85
86cpu_states=$(get_all_cpu_states)
87
88until [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do
89
90	# Turns on all CPUs
91	for i in $( get_hotplug_cpus ); do
92            if ! cpu_is_online $i; then
93				if ! online_cpu $i; then
94                    tst_brkm TBROK "Could not online cpu $i"
95                fi
96            fi
97	done
98
99	if ! offline_cpu ${CPU_TO_TEST} ; then
100		tst_resm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
101	fi
102
103	# Start up a number of processes equal to twice the number of
104	# CPUs we have.  This is to help ensure we've got enough processes
105	# that at least one will migrate to the new CPU.  Store the PIDs
106	# so we can kill them later.
107	number_of_procs=$((cpus_num*2))
108	until [ $number_of_procs -eq 0 ]; do
109		cpuhotplug_do_spin_loop > /dev/null 2>&1 &
110		echo $! >> /var/run/hotplug4_$$.pid
111		number_of_procs=$((number_of_procs-1))
112	done
113
114	ps aux | head -n 1
115	ps aux | grep cpuhotplug_do_spin_loop
116
117	# Online the CPU
118	tst_resm TINFO "Onlining CPU ${CPU_TO_TEST}"
119	if ! online_cpu ${CPU_TO_TEST}; then
120		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
121	fi
122
123	sleep 1
124
125	# Verify at least one process has migrated to the new CPU
126	# Since procps v3.3.15, we need to accurately select command name
127	# by -C option, because procps cannot trucate normal command name
128	# to 15 characters by default).
129	ps -o psr -o command --no-headers -C cpuhotplug_do_s
130	if [ $? -ne 0 ]; then
131		tst_brkm TBROK "No cpuhotplug_do_spin_loop processes \
132			found on any processor"
133	fi
134	NUM=`ps -o psr -o command --no-headers -C cpuhotplug_do_s \
135		| sed -e "s/^ *//" | cut -d' ' -f 1 | grep "^${CPU_TO_TEST}$" \
136		| wc -l`
137	if [ $NUM -lt 1 ]; then
138		tst_resm TFAIL "No cpuhotplug_do_spin_loop processes found on \
139			CPU${CPU_TO_TEST}"
140		tst_exit
141	fi
142
143	do_clean
144
145	LOOP_COUNT=$((LOOP_COUNT+1))
146done
147
148tst_resm TPASS "$NUM cpuhotplug_do_spin_loop processes found on \
149	CPU${CPU_TO_TEST}"
150
151tst_exit
152