public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] cpuhotplug fixes
@ 2015-04-08 17:33 Stanislav Kholmanskikh
  2015-04-08 17:33 ` [LTP] [PATCH 1/3] cpuhotplug: use cpu states in cleanup Stanislav Kholmanskikh
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2015-04-08 17:33 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

Hi!

The current version of cpuhotplug04.sh fails with our sparc64 kernel:

Name:   cpuhotplug04
Date:   Mon Apr  6 14:30:45 EDT 2015
Desc:   Does it prevent us from offlining the last CPU?

cat: /sys/devices/system/cpu/cpu3/online: No such file or directory
/opt/ltp/testcases/bin/cpuhotplug_hotplug.sh: line 210: [: =: unary operator expected
cpuhotplug04 1 TBROK : cpu3 cannot be onlined

because the kernel doesn't support hotpluggable cpus.

This series is an attempt to fix cpuhotplug04 plus some other 'improvements'.

Tested in our sparc64 environment and in a x86_64 virtual box vm (both with and without
cpu0_hotplug kernel cmdline), but additional testing is welcome :)

Thanks.

PS: should not be a blocker for the upcoming LTP release


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 1/3] cpuhotplug: use cpu states in cleanup
  2015-04-08 17:33 [LTP] cpuhotplug fixes Stanislav Kholmanskikh
@ 2015-04-08 17:33 ` Stanislav Kholmanskikh
  2015-04-08 17:33 ` [LTP] [PATCH 2/3] cpu_hotplug: added get_hotplug_cpus, get_hotplug_cpus_num Stanislav Kholmanskikh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2015-04-08 17:33 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

There is a couple of good functions:
 * get_all_cpu_states
 * set_all_cpu_states
which can help to avoid unnecessary cleanup logic in test cases.

So let's use them.

Also modified offline_cpu and online_cpu, so now they do nothing if
the cpu is already in the desired state.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 .../hotplug/cpu_hotplug/functional/cpuhotplug01.sh |   11 ++++-------
 .../hotplug/cpu_hotplug/functional/cpuhotplug03.sh |   12 +++++-------
 .../hotplug/cpu_hotplug/functional/cpuhotplug04.sh |   18 +++++-------------
 .../cpu_hotplug/include/cpuhotplug_hotplug.sh      |   16 ++++++++++------
 4 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh
index f91cf88..52598a9 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh
@@ -45,13 +45,8 @@ do_clean()
 {
 	kill_pid ${WRL_ID}
 
-	# Turns off the cpus that were off before the test start
-	until [ $CPU_COUNT -eq 0 ]; do
-		offline_cpu=$(eval "echo \$OFFLINE_CPU_${CPU_COUNT}")
-		tst_resm TINFO "CPU = $CPU_COUNT @on = $offline_cpu"
-		offline_cpu $offline_cpu
-		CPU_COUNT=$((CPU_COUNT-1))
-	done
+	# Restore CPU states
+	set_all_cpu_states "$cpu_states"
 }
 
 
@@ -138,6 +133,8 @@ fi
 
 TST_CLEANUP=do_clean
 
+cpu_states=$(get_all_cpu_states)
+
 CPU_COUNT=0
 
 # Start up a process that writes to disk; keep track of its PID
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
index 8176fb3..817f066 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
@@ -46,11 +46,8 @@ do_clean()
 		rm /var/run/hotplug4_$$.pid
 	fi
 
-	# Turn off the CPUs that were off before the test start
-	until [ $cpu -eq 0 ];do
-		offline_cpu $(eval "echo \$on_${cpu}")
-		cpu=$((cpu-1))
-	done
+	# Restore CPU states
+	set_all_cpu_states "$cpu_states"
 }
 
 while getopts c:l: OPTION; do
@@ -82,11 +79,13 @@ fi
 
 TST_CLEANUP=do_clean
 
+cpu_states=$(get_all_cpu_states)
+
 until [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do
 	cpu=0
 	number_of_cpus=0
 
-	# Turns on all CPUs and saves their states
+	# Turns on all CPUs
 	for i in $( get_all_cpus ); do
             if [ "$i" = "cpu0" ]; then
                 continue
@@ -96,7 +95,6 @@ until [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do
                     tst_brkm TBROK "Could not online cpu $i"
                 fi
 				cpu=$((cpu+1))
-                eval "on_${cpu}=$i"
             fi
 		number_of_cpus=$((number_of_cpus+1))
 	done
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
index 72fbc6e..ea2723b 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
@@ -33,17 +33,8 @@ EOF
 do_clean()
 {
 	# Online the ones that were on initially
-	until [ $cpu -eq 0 ]; do
-		online_cpu $(eval "echo \$on_${cpu}")
-		cpu=$((cpu-1))
-	done
-
-	# Return CPU 0 to its initial state
-	if [ $cpustate = 1 ]; then
-		online_cpu 0
-	else
-		offline_cpu 0
-	fi
+	# Restore CPU states
+	set_all_cpu_states "$cpu_states"
 }
 
 while getopts l: OPTION; do
@@ -64,11 +55,13 @@ fi
 
 TST_CLEANUP=do_clean
 
+cpu_states=$(get_all_cpu_states)
+
 until [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do
 	cpu=0
 	cpustate=1
 
-	# Online all the CPUs' keep track of which were already on
+	# Online all the CPUs
 	for i in $(get_all_cpus); do
 		if [ "$i" != "cpu0" ]; then
 			if ! cpu_is_online $i; then
@@ -77,7 +70,6 @@ until [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do
 				fi
 			fi
 			cpu=$((cpu+1))
-			eval "on_${cpu}=$i"
 			echo $i
 		else
 			if online_cpu $i; then
diff --git a/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh b/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh
index dd8472f..f553d0c 100644
--- a/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh
@@ -73,6 +73,9 @@ online_cpu()
     if [ ! -w /sys/devices/system/cpu/cpu${CPU}/online ]; then
         return 1
     fi
+
+    cpu_is_online ${CPU} && return 0
+
     $TIME echo 1 > /sys/devices/system/cpu/cpu${CPU}/online
     RC=$?
     report_timing "Online cpu ${CPU}"
@@ -91,6 +94,9 @@ offline_cpu()
     if [ ! -w /sys/devices/system/cpu/cpu${CPU}/online ]; then
         return 1
     fi
+
+    ! cpu_is_online ${CPU} && return 0
+
     $TIME echo 0 > /sys/devices/system/cpu/cpu${CPU}/online
     RC=$?
     report_timing "Offline cpu ${CPU}"
@@ -141,20 +147,18 @@ get_all_cpu_states()
 
 # set_all_cpu_states(STATES)
 #
-#  Sets all of the CPU states according to $STATE, which must be
+#  Sets all of the CPU states according to STATES, which must be
 #  of the form "cpuX:Y", where X is the CPU number and Y its state.
 #  Each must be on a separate line.
 #
 set_all_cpu_states()
 {
-    for cpu_state in $STATE; do
-        cpu=`echo $c | cut -d: -f 1`
-        state=`echo $c | cut -d: -f 1`
+    for cpu_state in $1; do
+        cpu=`echo $cpu_state | cut -d: -f 1`
+        state=`echo $cpu_state | cut -d: -f 2`
         if [ $state = 1 ]; then
-            echo "# Re-onlining $cpu"
             online_cpu $cpu
         else
-            echo "# Re-offlining $cpu"
             offline_cpu $cpu
         fi
     done
-- 
1.7.1


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/3] cpu_hotplug: added get_hotplug_cpus, get_hotplug_cpus_num
  2015-04-08 17:33 [LTP] cpuhotplug fixes Stanislav Kholmanskikh
  2015-04-08 17:33 ` [LTP] [PATCH 1/3] cpuhotplug: use cpu states in cleanup Stanislav Kholmanskikh
@ 2015-04-08 17:33 ` Stanislav Kholmanskikh
  2015-04-08 17:33 ` [LTP] [PATCH 3/3] cpuhotplug04.sh: operate only with hotpluggable CPUs Stanislav Kholmanskikh
  2015-04-28 17:05 ` [LTP] cpuhotplug fixes Cyril Hrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2015-04-08 17:33 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 .../cpu_hotplug/include/cpuhotplug_hotplug.sh      |   22 ++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh b/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh
index f553d0c..558ef12 100644
--- a/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh
@@ -131,6 +131,28 @@ get_all_cpus()
         sed "s/\/sys\/devices\/system\/cpu\///g" || return 2
 }
 
+# get_hotplug_cpus()
+#
+#  Prints a list of all hotpluggable CPUs
+#
+get_hotplug_cpus()
+{
+    ls /sys/devices/system/cpu/cpu[0-9]*/online 2> /dev/null | \
+        sed "s/\/sys\/devices\/system\/cpu\/\(cpu[0-9]*\)\/online/\1/g" || return 2
+}
+
+# get_hotplug_cpus_num()
+#
+#  Prints the number of hotpluggable CPUs
+#
+get_hotplug_cpus_num()
+{
+    hotplug_cpus=$(get_hotplug_cpus)
+    ret=$?
+    [ $ret -ne 0 ] && return 0
+
+    return $(echo "$hotplug_cpus" | grep -c 'cpu')
+}
 
 # get_all_cpu_states()
 #
-- 
1.7.1


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 3/3] cpuhotplug04.sh: operate only with hotpluggable CPUs
  2015-04-08 17:33 [LTP] cpuhotplug fixes Stanislav Kholmanskikh
  2015-04-08 17:33 ` [LTP] [PATCH 1/3] cpuhotplug: use cpu states in cleanup Stanislav Kholmanskikh
  2015-04-08 17:33 ` [LTP] [PATCH 2/3] cpu_hotplug: added get_hotplug_cpus, get_hotplug_cpus_num Stanislav Kholmanskikh
@ 2015-04-08 17:33 ` Stanislav Kholmanskikh
  2015-04-28 17:05 ` [LTP] cpuhotplug fixes Cyril Hrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2015-04-08 17:33 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

If cpu0 is hotpluggable, then the last CPU may not be cpu0, and
there is no reason to treat cpu0 as a special case.

To make the test be more generic I'm proposing these changes:
 * Operate (offline/online) only with hotpluggable CPUs, because
   how can we enable/disable a CPU if there is no 'online' file?

 * If all CPUs in the system are hotpluggable, then we expect that
   the kernel will only refuse to offline the last CPU. And this
   last CPU may not be cpu0.

 * If only a part of CPUs in the system is hotpluggable, then we
   should be able to offline all of them

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 .../hotplug/cpu_hotplug/functional/cpuhotplug04.sh |   56 +++++++++++--------
 1 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
index ea2723b..7dcb91b 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
@@ -49,41 +49,49 @@ done
 LOOP_COUNT=1
 
 get_cpus_num
-if [ $? -lt 2 ]; then
+cpus_num=$?
+if [ $cpus_num -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
 fi
 
+get_hotplug_cpus_num
+if [ $? -lt 1 ]; then
+	tst_brkm TCONF "system doesn't have at least one hotpluggable CPU"
+fi
+
 TST_CLEANUP=do_clean
 
 cpu_states=$(get_all_cpu_states)
 
 until [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do
-	cpu=0
-	cpustate=1
-
-	# Online all the CPUs
-	for i in $(get_all_cpus); do
-		if [ "$i" != "cpu0" ]; then
-			if ! cpu_is_online $i; then
-				if ! online_cpu $i; then
-					tst_brkm TBROK "$i cannot be onlined"
-				fi
-			fi
-			cpu=$((cpu+1))
-			echo $i
-		else
-			if online_cpu $i; then
-				cpustate=0
+
+	# Online all the hotpluggable CPUs
+	for i in $(get_hotplug_cpus); do
+		if ! cpu_is_online $i; then
+			if ! online_cpu $i; then
+				tst_brkm TBROK "$i can not be onlined"
 			fi
 		fi
 	done
 
-	# Now offline all the CPUs
-	for i in $(get_all_cpus); do
-		if ! offline_cpu $i; then
-			if [ "x$i" != "xcpu0" ]; then
-				tst_resm TFAIL "Did not offline first CPU (offlined $i instead)"
-				tst_exit
+	# Now offline them
+	cpu=0
+	for i in $(get_hotplug_cpus); do
+		cpu=$((cpu + 1))
+
+		# If all the CPUs are hotpluggable, we expect
+		# that the kernel will refuse to offline the last CPU.
+		# If only some of the CPUs are hotpluggable,
+		# they all can be offlined.
+		if [ $cpu -eq $cpus_num ]; then
+			if offline_cpu $i 2> /dev/null; then
+				tst_brkm TFAIL "Have we just offlined the last CPU?"
+			else
+				tst_resm TPASS "System prevented us from offlining the last CPU - $i"
+			fi
+		else
+			if ! offline_cpu $i; then
+				tst_brkm TFAIL "Could not offline $i"
 			fi
 		fi
 	done
@@ -92,6 +100,6 @@ until [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do
 
 done
 
-tst_resm TPASS "Successfully offlined first CPU, $i"
+tst_resm TPASS "Success"
 
 tst_exit
-- 
1.7.1


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] cpuhotplug fixes
  2015-04-08 17:33 [LTP] cpuhotplug fixes Stanislav Kholmanskikh
                   ` (2 preceding siblings ...)
  2015-04-08 17:33 ` [LTP] [PATCH 3/3] cpuhotplug04.sh: operate only with hotpluggable CPUs Stanislav Kholmanskikh
@ 2015-04-28 17:05 ` Cyril Hrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2015-04-28 17:05 UTC (permalink / raw)
  To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list

Hi!
Jan has send overlaping patchset just today, can you coordinate with him on
solution?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-04-28 17:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-08 17:33 [LTP] cpuhotplug fixes Stanislav Kholmanskikh
2015-04-08 17:33 ` [LTP] [PATCH 1/3] cpuhotplug: use cpu states in cleanup Stanislav Kholmanskikh
2015-04-08 17:33 ` [LTP] [PATCH 2/3] cpu_hotplug: added get_hotplug_cpus, get_hotplug_cpus_num Stanislav Kholmanskikh
2015-04-08 17:33 ` [LTP] [PATCH 3/3] cpuhotplug04.sh: operate only with hotpluggable CPUs Stanislav Kholmanskikh
2015-04-28 17:05 ` [LTP] cpuhotplug fixes Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox