1#!/bin/sh
2#
3# Test Case 7
4#
5# Runs continuous offline/online of CPUs along with
6# a kernel compilation load.
7
8export TCID="cpuhotplug07"
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 when hotplugging during a heavy workload?
20Issue:  Hotplug bugs have been found during kernel compiles
21
22EOF
23
24usage()
25{
26	cat << EOF
27	usage: $0 -c cpu -l loop -d directory
28
29	OPTIONS
30		-c	cpu which is specified for testing
31		-l	number of cycle test
32		-d	kernel directory where run this test
33
34EOF
35	exit 1
36}
37
38do_clean()
39{
40	kill_pid ${KCOMPILE_LOOP_PID}
41}
42
43while getopts c:l:d: OPTION; do
44	case $OPTION in
45	c)
46		CPU_TO_TEST=$OPTARG;;
47	l)
48		HOTPLUG07_LOOPS=$OPTARG;;
49	d)
50		KERNEL_DIR=$OPTARG;;
51	?)
52		usage;;
53	esac
54done
55
56LOOP_COUNT=1
57
58if [ $(get_present_cpus_num) -lt 2 ]; then
59	tst_brkm TCONF "system doesn't have required CPU hotplug support"
60fi
61
62if [ ! -d "${KERNEL_DIR}" ]; then
63	tst_brkm TCONF "kernel directory - $KERNEL_DIR - does not exist"
64fi
65
66if [ -z "${CPU_TO_TEST}" ]; then
67	tst_brkm TBROK "usage: ${0##*/} <CPU to offline> <Kernel \
68		source code directory>"
69fi
70
71# Validate the specified CPU is available
72if ! cpu_is_valid "${CPU_TO_TEST}" ; then
73	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
74fi
75
76if ! cpu_is_online ${CPU_TO_TEST}; then
77	if ! online_cpu ${CPU_TO_TEST}; then
78		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
79	fi
80fi
81
82TST_CLEANUP=do_clean
83
84cpuhotplug_do_kcompile_loop $KERNEL_DIR > /dev/null 2>&1 &
85KCOMPILE_LOOP_PID=$!
86
87tst_resm TINFO "initial CPU affinity for kernel compile is: \
88	$(get_affinity_mask ${KCOMPILE_LOOP_PID})"
89
90sleep 2
91
92until [ $LOOP_COUNT -gt $HOTPLUG07_LOOPS ]; do
93
94	tst_resm TINFO "Starting loop"
95
96	# Move spin_loop.sh to the CPU to offline.
97	set_affinity ${KCOMPILE_LOOP_PID} ${CPU_TO_TEST}
98
99	offline_cpu ${CPU_TO_TEST}
100	RC=$?
101	echo "Offlining cpu${CPU_TO_TEST}: Return Code = ${RC}"
102
103	NEW_CPU=`ps --pid=${KCOMPILE_LOOP_PID} -o psr --no-headers`
104	if [ -z "${NEW_CPU}" ]; then
105		tst_brkm TBROK "PID ${KCOMPILE_LOOP_PID} no longer running"
106	fi
107	if [ "${CPU_TO_TEST}" = "${NEW_CPU}" ]; then
108		tst_resm TFAIL "process did not change from CPU ${NEW_CPU}"
109		tst_exit
110	fi
111
112	online_cpu ${CPU_TO_TEST}
113	RC=$?
114	echo "Onlining cpu${CPU_TO_TEST}: Return Code = ${RC}"
115
116	LOOP_COUNT=$((LOOP_COUNT+1))
117
118done
119
120tst_resm TPASS "turned off CPU ${CPU_TO_TEST}, process migrated to \
121	CPU ${NEW_CPU}"
122
123sleep 2
124
125tst_exit
126