150512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#!/bin/sh
250512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#
350512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak# Test Case 3
450512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#
550512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
6b1dc53985ea88d4b26f2f31958b39ba9c2dd2f18Jin Liexport TCID="cpuhotplug03"
7bfc77c7d01f9f109af343984329c6443a5564a51Xing Guexport TST_TOTAL=1
850512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
950512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak# Includes:
10bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu. test.sh
11bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu. cpuhotplug_testsuite.sh
12bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu. cpuhotplug_hotplug.sh
1350512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
147edded454a877368665cd1d450161a4442403340Garrett Coopercat <<EOF
157edded454a877368665cd1d450161a4442403340Garrett CooperName:   $TCID
167edded454a877368665cd1d450161a4442403340Garrett CooperDate:   `date`
177edded454a877368665cd1d450161a4442403340Garrett CooperDesc:   Do tasks get scheduled to a newly on-lined CPU?
187edded454a877368665cd1d450161a4442403340Garrett Cooper
197edded454a877368665cd1d450161a4442403340Garrett CooperEOF
2050512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
21bfc77c7d01f9f109af343984329c6443a5564a51Xing Guusage()
22bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu{
23bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	cat << EOF
24bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	usage: $0 -c cpu -l loop
25bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
26bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	OPTIONS
27bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		-c  cpu which is specified for testing
28bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		-l  number of cycle test
29bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
30bfc77c7d01f9f109af343984329c6443a5564a51Xing GuEOF
31bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	exit 1
32bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu}
3350512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
3450512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak# do_clean()
3550512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#
3650512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#  Callback to be executed when script exits from a user interrupt
3750512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#  or regular program termination
3850512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak#
3950512d9c147b0e8a05d4d814af3ba83852a79304subrata_modakdo_clean()
4050512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak{
417edded454a877368665cd1d450161a4442403340Garrett Cooper	# Kill all the processes we started up and get rid of their pid files
427edded454a877368665cd1d450161a4442403340Garrett Cooper	if [ -e "/var/run/hotplug4_$$.pid" ]; then
437edded454a877368665cd1d450161a4442403340Garrett Cooper		for i in `cat /var/run/hotplug4_$$.pid`; do
447edded454a877368665cd1d450161a4442403340Garrett Cooper			kill_pid $i
457edded454a877368665cd1d450161a4442403340Garrett Cooper		done
467edded454a877368665cd1d450161a4442403340Garrett Cooper		rm /var/run/hotplug4_$$.pid
477edded454a877368665cd1d450161a4442403340Garrett Cooper	fi
487edded454a877368665cd1d450161a4442403340Garrett Cooper
494cb969a72e34e61e2584c5282577aa5d95b112dfStanislav Kholmanskikh	# Restore CPU states
504cb969a72e34e61e2584c5282577aa5d95b112dfStanislav Kholmanskikh	set_all_cpu_states "$cpu_states"
5150512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak}
5250512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
53bfc77c7d01f9f109af343984329c6443a5564a51Xing Guwhile getopts c:l: OPTION; do
54bfc77c7d01f9f109af343984329c6443a5564a51Xing Gucase $OPTION in
55bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	c)
56bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		CPU_TO_TEST=$OPTARG;;
57bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	l)
58bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		HOTPLUG03_LOOPS=$OPTARG;;
59bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	?)
60bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		usage;;
61bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	esac
62bfc77c7d01f9f109af343984329c6443a5564a51Xing Gudone
63bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
64bfc77c7d01f9f109af343984329c6443a5564a51Xing GuLOOP_COUNT=1
65bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
6626777407207f2a43d88c13437737d2ca3737650cGuangwen Fengcpus_num=$(get_present_cpus_num)
6734dcc452a290282ffa09d13433664a1361ea06cdJan Stancekif [ $cpus_num -lt 2 ]; then
6822f3ba1ede4cacd5df765f3e4b86ca90dd7ff75cXing Gu	tst_brkm TCONF "system doesn't have required CPU hotplug support"
6922f3ba1ede4cacd5df765f3e4b86ca90dd7ff75cXing Gufi
7022f3ba1ede4cacd5df765f3e4b86ca90dd7ff75cXing Gu
71bfc77c7d01f9f109af343984329c6443a5564a51Xing Guif [ -z $CPU_TO_TEST ]; then
72bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	tst_brkm TBROK "usage: ${0##*} <CPU to online>"
73bfc77c7d01f9f109af343984329c6443a5564a51Xing Gufi
74bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
7522f3ba1ede4cacd5df765f3e4b86ca90dd7ff75cXing Gu# Validate the specified CPU is available
76bfc77c7d01f9f109af343984329c6443a5564a51Xing Guif ! cpu_is_valid "${CPU_TO_TEST}" ; then
7722f3ba1ede4cacd5df765f3e4b86ca90dd7ff75cXing Gu	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
78bfc77c7d01f9f109af343984329c6443a5564a51Xing Gufi
79bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
80bfc77c7d01f9f109af343984329c6443a5564a51Xing GuTST_CLEANUP=do_clean
81bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
824cb969a72e34e61e2584c5282577aa5d95b112dfStanislav Kholmanskikhcpu_states=$(get_all_cpu_states)
834cb969a72e34e61e2584c5282577aa5d95b112dfStanislav Kholmanskikh
84bfc77c7d01f9f109af343984329c6443a5564a51Xing Guuntil [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do
857edded454a877368665cd1d450161a4442403340Garrett Cooper
864cb969a72e34e61e2584c5282577aa5d95b112dfStanislav Kholmanskikh	# Turns on all CPUs
8734dcc452a290282ffa09d13433664a1361ea06cdJan Stancek	for i in $( get_hotplug_cpus ); do
88de2e6566934feea613b7cd9f959742071d4597f1Jin Li            if ! cpu_is_online $i; then
89bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu				if ! online_cpu $i; then
90bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu                    tst_brkm TBROK "Could not online cpu $i"
91de2e6566934feea613b7cd9f959742071d4597f1Jin Li                fi
92de2e6566934feea613b7cd9f959742071d4597f1Jin Li            fi
937edded454a877368665cd1d450161a4442403340Garrett Cooper	done
947edded454a877368665cd1d450161a4442403340Garrett Cooper
957edded454a877368665cd1d450161a4442403340Garrett Cooper	if ! offline_cpu ${CPU_TO_TEST} ; then
96bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		tst_resm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
977edded454a877368665cd1d450161a4442403340Garrett Cooper	fi
987edded454a877368665cd1d450161a4442403340Garrett Cooper
997edded454a877368665cd1d450161a4442403340Garrett Cooper	# Start up a number of processes equal to twice the number of
1007edded454a877368665cd1d450161a4442403340Garrett Cooper	# CPUs we have.  This is to help ensure we've got enough processes
10137550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman	# that at least one will migrate to the new CPU.  Store the PIDs
1027edded454a877368665cd1d450161a4442403340Garrett Cooper	# so we can kill them later.
10334dcc452a290282ffa09d13433664a1361ea06cdJan Stancek	number_of_procs=$((cpus_num*2))
10434dcc452a290282ffa09d13433664a1361ea06cdJan Stancek	until [ $number_of_procs -eq 0 ]; do
105bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		cpuhotplug_do_spin_loop > /dev/null 2>&1 &
1067edded454a877368665cd1d450161a4442403340Garrett Cooper		echo $! >> /var/run/hotplug4_$$.pid
10734dcc452a290282ffa09d13433664a1361ea06cdJan Stancek		number_of_procs=$((number_of_procs-1))
1087edded454a877368665cd1d450161a4442403340Garrett Cooper	done
1097edded454a877368665cd1d450161a4442403340Garrett Cooper
1107edded454a877368665cd1d450161a4442403340Garrett Cooper	ps aux | head -n 1
111e469ab15b2332629432b9347d6ad71dfef885e95Xing Gu	ps aux | grep cpuhotplug_do_spin_loop
1127edded454a877368665cd1d450161a4442403340Garrett Cooper
1137edded454a877368665cd1d450161a4442403340Garrett Cooper	# Online the CPU
1147edded454a877368665cd1d450161a4442403340Garrett Cooper	tst_resm TINFO "Onlining CPU ${CPU_TO_TEST}"
115bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	if ! online_cpu ${CPU_TO_TEST}; then
116bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
1177edded454a877368665cd1d450161a4442403340Garrett Cooper	fi
1187edded454a877368665cd1d450161a4442403340Garrett Cooper
1197edded454a877368665cd1d450161a4442403340Garrett Cooper	sleep 1
1207edded454a877368665cd1d450161a4442403340Garrett Cooper
1217edded454a877368665cd1d450161a4442403340Garrett Cooper	# Verify at least one process has migrated to the new CPU
122e469ab15b2332629432b9347d6ad71dfef885e95Xing Gu	ps -o psr -o command --no-headers -C cpuhotplug_do_spin_loop
123bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	if [ $? -ne 0 ]; then
124bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		tst_brkm TBROK "No cpuhotplug_do_spin_loop processes \
125bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu			found on any processor"
126bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	fi
127bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	NUM=`ps -o psr -o command --no-headers -C cpuhotplug_do_spin_loop \
128bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		| sed -e "s/^ *//" | cut -d' ' -f 1 | grep "^${CPU_TO_TEST}$" \
129bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		| wc -l`
130bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	if [ $NUM -lt 1 ]; then
131e469ab15b2332629432b9347d6ad71dfef885e95Xing Gu		tst_resm TFAIL "No cpuhotplug_do_spin_loop processes found on \
132e469ab15b2332629432b9347d6ad71dfef885e95Xing Gu			CPU${CPU_TO_TEST}"
133bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu		tst_exit
1347edded454a877368665cd1d450161a4442403340Garrett Cooper	fi
1357edded454a877368665cd1d450161a4442403340Garrett Cooper
1367edded454a877368665cd1d450161a4442403340Garrett Cooper	do_clean
1377edded454a877368665cd1d450161a4442403340Garrett Cooper
138bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	LOOP_COUNT=$((LOOP_COUNT+1))
13950512d9c147b0e8a05d4d814af3ba83852a79304subrata_modakdone
14050512d9c147b0e8a05d4d814af3ba83852a79304subrata_modak
141bfc77c7d01f9f109af343984329c6443a5564a51Xing Gutst_resm TPASS "$NUM cpuhotplug_do_spin_loop processes found on \
142bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu	CPU${CPU_TO_TEST}"
143bfc77c7d01f9f109af343984329c6443a5564a51Xing Gu
144bfc77c7d01f9f109af343984329c6443a5564a51Xing Gutst_exit
145