On Wed, Apr 23, 2014 at 5:11 PM, Sanjay Singh Rawat <sanjay.rawat@linaro.org> wrote:
Signed-off-by: Sanjay Singh Rawat <sanjay.rawat@linaro.org>
---
- This will help in catching issue like https://lkml.org/lkml/2014/3/25/122

- Tested on my x86 dev m/c
Output:
running hotplug stress on cpu : cpu1
pass: cpu hotplug count = 200 duration = 16.98 seconds
running hotplug stress on cpu : cpu2
pass: cpu hotplug count = 200 duration = 16.36 seconds
running hotplug stress on cpu : cpu3
pass: cpu hotplug count = 200 duration = 15.05 seconds

- Issue: For a hotplug count of 500 the system just hangs. Need to
  manually restart.
  Is it safe to simply plugout the cpu? What will happend to the tasks
  in the cpu runqueue.
---
 cpuhotplug/cpuhotplug_09.sh  |   70 ++++++++++++++++++++++++++++++++++++++++++
 cpuhotplug/cpuhotplug_09.txt |    1 +
 2 files changed, 71 insertions(+)
 create mode 100755 cpuhotplug/cpuhotplug_09.sh
 create mode 100644 cpuhotplug/cpuhotplug_09.txt

diff --git a/cpuhotplug/cpuhotplug_09.sh b/cpuhotplug/cpuhotplug_09.sh
new file mode 100755
index 0000000..be0c91c
--- /dev/null
+++ b/cpuhotplug/cpuhotplug_09.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+#
+# PM-QA validation test suite for the power management on Linux
+#
+# Copyright (C) 2014, Linaro Limited.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+# Contributors:
+#     Sanjay Singh Rawat <sanjay.rawat@linaro.org>
+#       - initial API and implementation
+#
+
+# URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_09
+
+source ../include/functions.sh
+STRESS_COUNT=200
+
+cpuhotplug_stress() {
+    local cpu=$1
+    local dirpath=$CPU_PATH/$1
+    local state=
+    local start=
+    local end=
+    shift 1
+
+    if [ "$cpu" == "cpu0" ]; then
+       # skipping main cpu
+       return 0
+    fi
+
+    echo "running hotplug stress on cpu :" $cpu
+    start=$(echo $(awk '{print $1}' /proc/uptime))
+
+    for i in $(seq 1 $STRESS_COUNT);
+    do
+        set_offline $cpu
+        state=$(get_online $cpu)
+        if [ $state -ne 0 ]; then
+            echo "fail: cpu offline failed at " $i
+           return 1
+        fi
+
+        set_online $cpu
+        state=$(get_online $cpu)
+        if [ $state -ne 1 ]; then
+            echo "fail: cpu online failed at " $i
+           return 1
+        fi
+    done
+
+    end=$(echo $(awk '{print $1}' /proc/uptime))
+    echo "pass: cpu hotplug in/out count =" $i "duration =" $(echo "$end-$start" | bc) "seconds"
+    return 0
+}
+
+for_each_cpu cpuhotplug_stress
+test_status_show
diff --git a/cpuhotplug/cpuhotplug_09.txt b/cpuhotplug/cpuhotplug_09.txt
new file mode 100644
index 0000000..5b0f8ac
--- /dev/null
+++ b/cpuhotplug/cpuhotplug_09.txt
@@ -0,0 +1 @@
+test to stress cpu hotplug feature
--
1.7.10.4


This is a good start, but too regular. I would like more randomness to the hotplug process in terms of order of cpus being hotplugged in and out. I tried to come up with something long ago[1] but didn't quite finish it.

The script should start with a list of cpus, then maintain a list of online and offline cpus (can be probed repeatedly at runtime too) and then at random select either the online or offline operation and then a random cpu from that list to online or offline.

Regards,
Amit