Skip to contentSkip to conversation

Improve the CPU hot plug tests

PATCH Superseded Thomas Huth 4 participants 13 messages Oct 17, 2017 – Oct 18, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Improve the CPU hot plug tests

So far the CPU hot-plug qtest was only checking "cpu-add" on x86. With these patches, we now test "device_add" for hot-plugging CPUs on x86, and enable the test on ppc64 and s390x, too.

Thomas Huth (4):
tests: Rename pc-cpu-test.c to cpu-plug-test.c tests/cpu-plug-test: Check the CPU hot-plugging with device_add, too tests/cpu-plug-test: Check CPU hot-plugging on ppc64, too tests/cpu-plug-test: Test CPU hot-plugging on s390x

 tests/Makefile.include |   6 +-
 tests/cpu-plug-test.c  | 261 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/pc-cpu-test.c    | 135 -------------------------
 3 files changed, 265 insertions(+), 137 deletions(-)
 create mode 100644 tests/cpu-plug-test.c
 delete mode 100644 tests/pc-cpu-test.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/4 tests: Rename pc-cpu-test.c to cpu-plug-test.c

The test will be extended to work on other architectures, too, so let's use a more generic name for the file and the functions in here first.

---
 tests/Makefile.include                   |  4 ++--
 tests/{pc-cpu-test.c => cpu-plug-test.c} | 24 ++++++++++++------------
 2 files changed, 14 insertions(+), 14 deletions(-)
 rename tests/{pc-cpu-test.c => cpu-plug-test.c} (87%)
tests/Makefile.include +2 -2
index 4ca15e6..3d7e814 100644
@@ -276,7 +276,7 @@ gcov-files-i386-y += hw/usb/dev-hid.c
 gcov-files-i386-y += hw/usb/dev-storage.c
 check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-xhci.c
-check-qtest-i386-y += tests/pc-cpu-test$(EXESUF)
+check-qtest-i386-y += tests/cpu-plug-test$(EXESUF)
 check-qtest-i386-y += tests/q35-test$(EXESUF)
 check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
 gcov-files-i386-y += hw/pci-host/q35.c
@@ -780,7 +780,7 @@ tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
-tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
+tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o
 tests/postcopy-test$(EXESUF): tests/postcopy-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \
 	$(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) \
tests/cpu-plug-test.c renamed from tests/pc-cpu-test.c +12 -12
similarity index 87%
rename from tests/pc-cpu-test.c
rename to tests/cpu-plug-test.c
index 11d3e81..4579119 100644
@@ -1,5 +1,5 @@
 /*
- * QTest testcase for PC CPUs
+ * QTest testcase for CPU plugging
  *
  * Copyright (c) 2015 SUSE Linux GmbH
  *
@@ -13,7 +13,7 @@
 #include "libqtest.h"
 #include "qapi/qmp/types.h"
 
-struct PCTestData {
+struct PlugTestData {
     char *machine;
     const char *cpu_model;
     unsigned sockets;
@@ -21,11 +21,11 @@ struct PCTestData {
     unsigned threads;
     unsigned maxcpus;
 };
-typedef struct PCTestData PCTestData;
+typedef struct PlugTestData PlugTestData;
 
-static void test_pc_with_cpu_add(gconstpointer data)
+static void test_plug_with_cpu_add(gconstpointer data)
 {
-    const PCTestData *s = data;
+    const PlugTestData *s = data;
     char *args;
     QDict *response;
     unsigned int i;
@@ -48,9 +48,9 @@ static void test_pc_with_cpu_add(gconstpointer data)
     g_free(args);
 }
 
-static void test_pc_without_cpu_add(gconstpointer data)
+static void test_plug_without_cpu_add(gconstpointer data)
 {
-    const PCTestData *s = data;
+    const PlugTestData *s = data;
     char *args;
     QDict *response;
 
@@ -73,7 +73,7 @@ static void test_pc_without_cpu_add(gconstpointer data)
 
 static void test_data_free(gpointer data)
 {
-    PCTestData *pc = data;
+    PlugTestData *pc = data;
 
     g_free(pc->machine);
     g_free(pc);
@@ -82,12 +82,12 @@ static void test_data_free(gpointer data)
 static void add_pc_test_case(const char *mname)
 {
     char *path;
-    PCTestData *data;
+    PlugTestData *data;
 
     if (!g_str_has_prefix(mname, "pc-")) {
         return;
     }
-    data = g_new(PCTestData, 1);
+    data = g_new(PlugTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
     data->sockets = 1;
@@ -108,14 +108,14 @@ static void add_pc_test_case(const char *mname)
         path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
-        qtest_add_data_func_full(path, data, test_pc_without_cpu_add,
+        qtest_add_data_func_full(path, data, test_plug_without_cpu_add,
                                  test_data_free);
         g_free(path);
     } else {
         path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
-        qtest_add_data_func_full(path, data, test_pc_with_cpu_add,
+        qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
                                  test_data_free);
         g_free(path);
     }
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] tests: Rename pc-cpu-test.c to cpu-plug-test.c

Quoted 4 lines · Thomas Huth

The test will be extended to work on other architectures, too, so let's use a more generic name for the file and the functions in here first.

Quoted 120 lines
---
 tests/Makefile.include                   |  4 ++--
 tests/{pc-cpu-test.c => cpu-plug-test.c} | 24 ++++++++++++------------
 2 files changed, 14 insertions(+), 14 deletions(-)
 rename tests/{pc-cpu-test.c => cpu-plug-test.c} (87%)
tests/Makefile.include +2 -2
index 4ca15e6..3d7e814 100644
@@ -276,7 +276,7 @@ gcov-files-i386-y += hw/usb/dev-hid.c
 gcov-files-i386-y += hw/usb/dev-storage.c
 check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-xhci.c
-check-qtest-i386-y += tests/pc-cpu-test$(EXESUF)
+check-qtest-i386-y += tests/cpu-plug-test$(EXESUF)
 check-qtest-i386-y += tests/q35-test$(EXESUF)
 check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
 gcov-files-i386-y += hw/pci-host/q35.c
@@ -780,7 +780,7 @@ tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
-tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
+tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o
 tests/postcopy-test$(EXESUF): tests/postcopy-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \
 	$(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) \
tests/cpu-plug-test.c renamed from tests/pc-cpu-test.c +12 -12
similarity index 87%
rename from tests/pc-cpu-test.c
rename to tests/cpu-plug-test.c
index 11d3e81..4579119 100644
@@ -1,5 +1,5 @@
 /*
- * QTest testcase for PC CPUs
+ * QTest testcase for CPU plugging
  *
  * Copyright (c) 2015 SUSE Linux GmbH
  *
@@ -13,7 +13,7 @@
 #include "libqtest.h"
 #include "qapi/qmp/types.h"
 
-struct PCTestData {
+struct PlugTestData {
     char *machine;
     const char *cpu_model;
     unsigned sockets;
@@ -21,11 +21,11 @@ struct PCTestData {
     unsigned threads;
     unsigned maxcpus;
 };
-typedef struct PCTestData PCTestData;
+typedef struct PlugTestData PlugTestData;
 
-static void test_pc_with_cpu_add(gconstpointer data)
+static void test_plug_with_cpu_add(gconstpointer data)
 {
-    const PCTestData *s = data;
+    const PlugTestData *s = data;
     char *args;
     QDict *response;
     unsigned int i;
@@ -48,9 +48,9 @@ static void test_pc_with_cpu_add(gconstpointer data)
     g_free(args);
 }
 
-static void test_pc_without_cpu_add(gconstpointer data)
+static void test_plug_without_cpu_add(gconstpointer data)
 {
-    const PCTestData *s = data;
+    const PlugTestData *s = data;
     char *args;
     QDict *response;
 
@@ -73,7 +73,7 @@ static void test_pc_without_cpu_add(gconstpointer data)
 
 static void test_data_free(gpointer data)
 {
-    PCTestData *pc = data;
+    PlugTestData *pc = data;
 
     g_free(pc->machine);
     g_free(pc);
@@ -82,12 +82,12 @@ static void test_data_free(gpointer data)
 static void add_pc_test_case(const char *mname)
 {
     char *path;
-    PCTestData *data;
+    PlugTestData *data;
 
     if (!g_str_has_prefix(mname, "pc-")) {
         return;
     }
-    data = g_new(PCTestData, 1);
+    data = g_new(PlugTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
     data->sockets = 1;
@@ -108,14 +108,14 @@ static void add_pc_test_case(const char *mname)
         path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
-        qtest_add_data_func_full(path, data, test_pc_without_cpu_add,
+        qtest_add_data_func_full(path, data, test_plug_without_cpu_add,
                                  test_data_free);
         g_free(path);
     } else {
         path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
-        qtest_add_data_func_full(path, data, test_pc_with_cpu_add,
+        qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
                                  test_data_free);
         g_free(path);
     }
Reviewed-by on v1 1/4
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] tests: Rename pc-cpu-test.c to cpu-plug-test.c

In reply to Thomas Huth
Quoted 114 lines · Thomas Huth

The test will be extended to work on other architectures, too, so let's use a more generic name for the file and the functions in here first.

---
 tests/Makefile.include                   |  4 ++--
 tests/{pc-cpu-test.c => cpu-plug-test.c} | 24 ++++++++++++------------
 2 files changed, 14 insertions(+), 14 deletions(-)
 rename tests/{pc-cpu-test.c => cpu-plug-test.c} (87%)
tests/Makefile.include +2 -2
index 4ca15e6..3d7e814 100644
@@ -276,7 +276,7 @@ gcov-files-i386-y += hw/usb/dev-hid.c
 gcov-files-i386-y += hw/usb/dev-storage.c
 check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-xhci.c
-check-qtest-i386-y += tests/pc-cpu-test$(EXESUF)
+check-qtest-i386-y += tests/cpu-plug-test$(EXESUF)
 check-qtest-i386-y += tests/q35-test$(EXESUF)
 check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
 gcov-files-i386-y += hw/pci-host/q35.c
@@ -780,7 +780,7 @@ tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
-tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
+tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o
 tests/postcopy-test$(EXESUF): tests/postcopy-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \
 	$(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) \
tests/cpu-plug-test.c renamed from tests/pc-cpu-test.c +11 -11
similarity index 87%
rename from tests/pc-cpu-test.c
rename to tests/cpu-plug-test.c
index 11d3e81..4579119 100644
@@ -1,5 +1,5 @@
 /*
- * QTest testcase for PC CPUs
+ * QTest testcase for CPU plugging
  *
  * Copyright (c) 2015 SUSE Linux GmbH
  *
@@ -13,7 +13,7 @@
 #include "libqtest.h"
 #include "qapi/qmp/types.h"
 
-struct PCTestData {
+struct PlugTestData {
     char *machine;
     const char *cpu_model;
     unsigned sockets;
@@ -21,11 +21,11 @@ struct PCTestData {
     unsigned threads;
     unsigned maxcpus;
 };
-typedef struct PCTestData PCTestData;
+typedef struct PlugTestData PlugTestData;
 
-static void test_pc_with_cpu_add(gconstpointer data)
+static void test_plug_with_cpu_add(gconstpointer data)
 {
-    const PCTestData *s = data;
+    const PlugTestData *s = data;
     char *args;
     QDict *response;
     unsigned int i;
@@ -48,9 +48,9 @@ static void test_pc_with_cpu_add(gconstpointer data)
     g_free(args);
 }
 
-static void test_pc_without_cpu_add(gconstpointer data)
+static void test_plug_without_cpu_add(gconstpointer data)
 {
-    const PCTestData *s = data;
+    const PlugTestData *s = data;
     char *args;
     QDict *response;
 
@@ -73,7 +73,7 @@ static void test_pc_without_cpu_add(gconstpointer data)
 
 static void test_data_free(gpointer data)
 {
-    PCTestData *pc = data;
+    PlugTestData *pc = data;
 
     g_free(pc->machine);
     g_free(pc);
@@ -82,12 +82,12 @@ static void test_data_free(gpointer data)
 static void add_pc_test_case(const char *mname)
 {
     char *path;
-    PCTestData *data;
+    PlugTestData *data;
 
     if (!g_str_has_prefix(mname, "pc-")) {
         return;
     }
-    data = g_new(PCTestData, 1);
+    data = g_new(PlugTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
     data->sockets = 1;
@@ -108,14 +108,14 @@ static void add_pc_test_case(const char *mname)
         path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
-        qtest_add_data_func_full(path, data, test_pc_without_cpu_add,
+        qtest_add_data_func_full(path, data, test_plug_without_cpu_add,
                                  test_data_free);

tests/cpu-plug-test.c static void add_pc_test_case(const char *mname) · line 121

Quoted 10 lines
tests/cpu-plug-test.c renamed from tests/pc-cpu-test.c +1 -1
         g_free(path);
     } else {
         path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
-        qtest_add_data_func_full(path, data, test_pc_with_cpu_add,
+        qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
                                  test_data_free);
         g_free(path);
     }
Signature · 3 lines
Thanks,

David
#4 lore raw

PATCH 2/4 tests/cpu-plug-test: Check the CPU hot-plugging with device_add, too

In reply to Thomas Huth

Using 'device_add' instead of 'cpu-add' is the new way for hot-plugging CPUs, so we should test this regularly, too.

---
 tests/cpu-plug-test.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
tests/cpu-plug-test.c +40 -2
index 4579119..5fef297 100644
@@ -16,6 +16,7 @@
 struct PlugTestData {
     char *machine;
     const char *cpu_model;
+    const char *device_model;
     unsigned sockets;
     unsigned cores;
     unsigned threads;
@@ -71,6 +72,34 @@ static void test_plug_without_cpu_add(gconstpointer data)
     g_free(args);
 }
 
+static void test_plug_with_device_add_x86(gconstpointer data)
+{
+    const PlugTestData *td = data;
+    char *args;
+    unsigned int s, c, t;
+
+    args = g_strdup_printf("-machine %s -cpu %s "
+                           "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                           td->machine, td->cpu_model,
+                           td->sockets, td->cores, td->threads, td->maxcpus);
+    qtest_start(args);
+
+    for (s = td->sockets; s < td->maxcpus / td->cores / td->threads; s++) {
+        for (c = 0; c < td->cores; c++) {
+            for (t = 0; t < td->threads; t++) {
+                char *id = g_strdup_printf("id-%i-%i-%i", s, c, t);
+                qtest_qmp_device_add(td->device_model, id, "'socket-id':'%i', "
+                                     "'core-id':'%i', 'thread-id':'%i'",
+                                     s, c, t);
+                g_free(id);
+            }
+        }
+    }
+
+    qtest_end();
+    g_free(args);
+}
+
 static void test_data_free(gpointer data)
 {
     PlugTestData *pc = data;
@@ -90,6 +119,7 @@ static void add_pc_test_case(const char *mname)
     data = g_new(PlugTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
+    data->device_model = "Haswell-x86_64-cpu";
     data->sockets = 1;
     data->cores = 3;
     data->threads = 2;
@@ -105,19 +135,27 @@ static void add_pc_test_case(const char *mname)
         (strcmp(mname, "pc-0.12") == 0) ||
         (strcmp(mname, "pc-0.11") == 0) ||
         (strcmp(mname, "pc-0.10") == 0)) {
-        path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
+        path = g_strdup_printf("cpu-plug/%s/init/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
         qtest_add_data_func_full(path, data, test_plug_without_cpu_add,
                                  test_data_free);
         g_free(path);
     } else {
-        path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
+        PlugTestData *data2 = g_memdup(data, sizeof(PlugTestData));
+        data2->machine = g_strdup(mname);
+        path = g_strdup_printf("cpu-plug/%s/cpu-add/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
         qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
                                  test_data_free);
         g_free(path);
+        path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
+                               mname, data2->sockets, data2->cores,
+                               data2->threads, data2->maxcpus);
+        qtest_add_data_func_full(path, data2, test_plug_with_device_add_x86,
+                                 test_data_free);
+        g_free(path);
     }
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/4
#5 lore raw

Re: [Qemu-devel] [PATCH 2/4] tests/cpu-plug-test: Check the CPU hot-plugging with device_add, too

Quoted 26 lines · Thomas Huth

Using 'device_add' instead of 'cpu-add' is the new way for hot-plugging CPUs, so we should test this regularly, too.

---
 tests/cpu-plug-test.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
tests/cpu-plug-test.c +3 -0
index 4579119..5fef297 100644
@@ -16,6 +16,7 @@
 struct PlugTestData {
     char *machine;
     const char *cpu_model;
+    const char *device_model;
     unsigned sockets;
     unsigned cores;
     unsigned threads;
@@ -71,6 +72,34 @@ static void test_plug_without_cpu_add(gconstpointer data)
     g_free(args);
 }
 
+static void test_plug_with_device_add_x86(gconstpointer data)
+{

tests/cpu-plug-test.c static void test_plug_without_cpu_add(gconstpointer data) · line 86

Quoted 10 lines
tests/cpu-plug-test.c +10 -0
+    const PlugTestData *td = data;
+    char *args;
+    unsigned int s, c, t;
+
+    args = g_strdup_printf("-machine %s -cpu %s "
+                           "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                           td->machine, td->cpu_model,
+                           td->sockets, td->cores, td->threads, td->maxcpus);
+    qtest_start(args);
+

I wonder if we should also query the hotpluggable CPUs via query-hotpluggable-cpus and try to add all (maybe even in random order). Could also be a second test case.

Quoted 31 lines
tests/cpu-plug-test.c +17 -0
+    for (s = td->sockets; s < td->maxcpus / td->cores / td->threads; s++) {
+        for (c = 0; c < td->cores; c++) {
+            for (t = 0; t < td->threads; t++) {
+                char *id = g_strdup_printf("id-%i-%i-%i", s, c, t);
+                qtest_qmp_device_add(td->device_model, id, "'socket-id':'%i', "
+                                     "'core-id':'%i', 'thread-id':'%i'",
+                                     s, c, t);
+                g_free(id);
+            }
+        }
+    }
+
+    qtest_end();
+    g_free(args);
+}
+
 static void test_data_free(gpointer data)
 {
     PlugTestData *pc = data;
@@ -90,6 +119,7 @@ static void add_pc_test_case(const char *mname)
     data = g_new(PlugTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
+    data->device_model = "Haswell-x86_64-cpu";
     data->sockets = 1;
     data->cores = 3;
     data->threads = 2;
@@ -105,19 +135,27 @@ static void add_pc_test_case(const char *mname)
         (strcmp(mname, "pc-0.12") == 0) ||
         (strcmp(mname, "pc-0.11") == 0) ||
         (strcmp(mname, "pc-0.10") == 0)) {

tests/cpu-plug-test.c static void add_pc_test_case(const char *mname) · line 145

Quoted 10 lines
tests/cpu-plug-test.c +2 -2
-        path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
+        path = g_strdup_printf("cpu-plug/%s/init/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
         qtest_add_data_func_full(path, data, test_plug_without_cpu_add,
                                  test_data_free);
         g_free(path);
     } else {
-        path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
+        PlugTestData *data2 = g_memdup(data, sizeof(PlugTestData));

add an empty line?

Quoted 7 lines
tests/cpu-plug-test.c +2 -0
+        data2->machine = g_strdup(mname);
+        path = g_strdup_printf("cpu-plug/%s/cpu-add/%ux%ux%u&maxcpus=%u",
                                mname, data->sockets, data->cores,
                                data->threads, data->maxcpus);
         qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
                                  test_data_free);

tests/cpu-plug-test.c static void add_pc_test_case(const char *mname) · line 161

Quoted 10 lines
tests/cpu-plug-test.c +6 -0
         g_free(path);
+        path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
+                               mname, data2->sockets, data2->cores,
+                               data2->threads, data2->maxcpus);
+        qtest_add_data_func_full(path, data2, test_plug_with_device_add_x86,
+                                 test_data_free);
+        g_free(path);
     }
 }
 

device_model can usually be created from cpu_model (although not 100% clean, e.g. s390 vs. s390x). But the distinction here actually allows us to test that we can't plug mixed CPU models.

So we might add a test case later that tries to hotplug a different CPU.

Signature · 3 lines
Thanks,

David
#6 lore raw

PATCH 3/4 tests/cpu-plug-test: Check CPU hot-plugging on ppc64, too

In reply to Thomas Huth

Hot plugging on ppc64 is possible via "device_add", too. Unlike x86, we must not specify a 'socket-id' and 'thread-id' here, so this needs to be done with a separate function that just specifies the 'core-id' during the "device_add".

---
 tests/Makefile.include |  1 +
 tests/cpu-plug-test.c  | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
tests/Makefile.include +1 -0
index 3d7e814..cbec19f 100644
@@ -332,6 +332,7 @@ check-qtest-ppc64-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-ppc64-y += tests/display-vga-test$(EXESUF)
 check-qtest-ppc64-y += tests/numa-test$(EXESUF)
 check-qtest-ppc64-$(CONFIG_IVSHMEM) += tests/ivshmem-test$(EXESUF)
+check-qtest-ppc64-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-sh4-y = tests/endianness-test$(EXESUF)
 
tests/cpu-plug-test.c +50 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Reviewed-by Tested-by on v1 3/4
#7 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH 3/4] tests/cpu-plug-test: Check CPU hot-plugging on ppc64, too

Quoted 6 lines · Thomas Huth

Hot plugging on ppc64 is possible via "device_add", too. Unlike x86, we must not specify a 'socket-id' and 'thread-id' here, so this needs to be done with a separate function that just specifies the 'core-id' during the "device_add".

Quoted 92 lines
---
  tests/Makefile.include |  1 +
  tests/cpu-plug-test.c  | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 51 insertions(+)
tests/Makefile.include +1 -0
index 3d7e814..cbec19f 100644
@@ -332,6 +332,7 @@ check-qtest-ppc64-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
  check-qtest-ppc64-y += tests/display-vga-test$(EXESUF)
  check-qtest-ppc64-y += tests/numa-test$(EXESUF)
  check-qtest-ppc64-$(CONFIG_IVSHMEM) += tests/ivshmem-test$(EXESUF)
+check-qtest-ppc64-y += tests/cpu-plug-test$(EXESUF)
 
  check-qtest-sh4-y = tests/endianness-test$(EXESUF)
 
tests/cpu-plug-test.c +50 -0
index 5fef297..714a69c 100644
@@ -100,6 +100,28 @@ static void test_plug_with_device_add_x86(gconstpointer data)
      g_free(args);
  }
 
+static void test_plug_with_device_add_coreid(gconstpointer data)
+{
+    const PlugTestData *td = data;
+    char *args;
+    unsigned int c;
+
+    args = g_strdup_printf("-machine %s -cpu %s "
+                           "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                           td->machine, td->cpu_model,
+                           td->sockets, td->cores, td->threads, td->maxcpus);
+    qtest_start(args);
+
+    for (c = td->cores; c < td->maxcpus / td->sockets / td->threads; c++) {
+        char *id = g_strdup_printf("id-%i", c);
+        qtest_qmp_device_add(td->device_model, id, "'core-id':'%i'", c);
+        g_free(id);
+    }
+
+    qtest_end();
+    g_free(args);
+}
+
  static void test_data_free(gpointer data)
  {
      PlugTestData *pc = data;
@@ -159,6 +181,32 @@ static void add_pc_test_case(const char *mname)
      }
  }
 
+static void add_pseries_test_case(const char *mname)
+{
+    char *path;
+    PlugTestData *data;
+
+    if (!g_str_has_prefix(mname, "pseries-") ||
+        (g_str_has_prefix(mname, "pseries-2.") && atoi(&mname[10]) < 7)) {
+        return;
+    }
+    data = g_new(PlugTestData, 1);
+    data->machine = g_strdup(mname);
+    data->cpu_model = "POWER8_v2.0";
+    data->device_model = "power8_v2.0-spapr-cpu-core";
+    data->sockets = 2;
+    data->cores = 3;
+    data->threads = 1;
+    data->maxcpus = data->sockets * data->cores * data->threads * 2;
+
+    path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
+                           mname, data->sockets, data->cores,
+                           data->threads, data->maxcpus);
+    qtest_add_data_func_full(path, data, test_plug_with_device_add_coreid,
+                             test_data_free);
+    g_free(path);
+}
+
  int main(int argc, char **argv)
  {
      const char *arch = qtest_get_arch();
@@ -167,6 +215,8 @@ int main(int argc, char **argv)
 
      if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
          qtest_cb_for_every_machine(add_pc_test_case);
+    } else if (g_str_equal(arch, "ppc64")) {
+        qtest_cb_for_every_machine(add_pseries_test_case);
      }
 
      return g_test_run();
#8 lore raw

PATCH 4/4 tests/cpu-plug-test: Test CPU hot-plugging on s390x

In reply to Thomas Huth

CPU hot-plugging on s390x is possible with both, "cpu-add" and "device_add", so test both.

---
 tests/Makefile.include |  1 +
 tests/cpu-plug-test.c  | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
tests/Makefile.include +1 -0
index cbec19f..85cf9ea 100644
@@ -368,6 +368,7 @@ check-qtest-s390x-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
+check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/qom-test$(EXESUF)
 check-qtest-generic-y += tests/test-hmp$(EXESUF)
tests/cpu-plug-test.c +38 -0
index 714a69c..58edaf6 100644
@@ -207,6 +207,42 @@ static void add_pseries_test_case(const char *mname)
     g_free(path);
 }
 
+static void add_s390x_test_case(const char *mname)
+{
+    char *path;
+    PlugTestData *data, *data2;
+
+    if (!g_str_has_prefix(mname, "s390-ccw-virtio-")) {
+        return;
+    }
+
+    data = g_new(PlugTestData, 1);
+    data->machine = g_strdup(mname);
+    data->cpu_model = "qemu";
+    data->device_model = "qemu-s390-cpu";
+    data->sockets = 1;
+    data->cores = 3;
+    data->threads = 1;
+    data->maxcpus = data->sockets * data->cores * data->threads * 2;
+
+    data2 = g_memdup(data, sizeof(PlugTestData));
+    data2->machine = g_strdup(mname);
+
+    path = g_strdup_printf("cpu-plug/%s/cpu-add/%ux%ux%u&maxcpus=%u",
+                           mname, data->sockets, data->cores,
+                           data->threads, data->maxcpus);
+    qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
+                             test_data_free);
+    g_free(path);
+
+    path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
+                           mname, data2->sockets, data2->cores,
+                           data2->threads, data2->maxcpus);
+    qtest_add_data_func_full(path, data2, test_plug_with_device_add_coreid,
+                             test_data_free);
+    g_free(path);
+}
+
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();
@@ -217,6 +253,8 @@ int main(int argc, char **argv)
         qtest_cb_for_every_machine(add_pc_test_case);
     } else if (g_str_equal(arch, "ppc64")) {
         qtest_cb_for_every_machine(add_pseries_test_case);
+    } else if (g_str_equal(arch, "s390x")) {
+        qtest_cb_for_every_machine(add_s390x_test_case);
     }
 
     return g_test_run();
Signature · 1 line
1.8.3.1
Reviewed-by on v1 4/4
#9 lore raw

Re: [Qemu-devel] [PATCH 4/4] tests/cpu-plug-test: Test CPU hot-plugging on s390x

Quoted 70 lines · Thomas Huth

CPU hot-plugging on s390x is possible with both, "cpu-add" and "device_add", so test both.

---
 tests/Makefile.include |  1 +
 tests/cpu-plug-test.c  | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
tests/Makefile.include +1 -0
index cbec19f..85cf9ea 100644
@@ -368,6 +368,7 @@ check-qtest-s390x-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
+check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/qom-test$(EXESUF)
 check-qtest-generic-y += tests/test-hmp$(EXESUF)
tests/cpu-plug-test.c +36 -0
index 714a69c..58edaf6 100644
@@ -207,6 +207,42 @@ static void add_pseries_test_case(const char *mname)
     g_free(path);
 }
 
+static void add_s390x_test_case(const char *mname)
+{
+    char *path;
+    PlugTestData *data, *data2;
+
+    if (!g_str_has_prefix(mname, "s390-ccw-virtio-")) {
+        return;
+    }
+
+    data = g_new(PlugTestData, 1);
+    data->machine = g_strdup(mname);
+    data->cpu_model = "qemu";
+    data->device_model = "qemu-s390-cpu";
+    data->sockets = 1;
+    data->cores = 3;
+    data->threads = 1;
+    data->maxcpus = data->sockets * data->cores * data->threads * 2;
+
+    data2 = g_memdup(data, sizeof(PlugTestData));
+    data2->machine = g_strdup(mname);
+
+    path = g_strdup_printf("cpu-plug/%s/cpu-add/%ux%ux%u&maxcpus=%u",
+                           mname, data->sockets, data->cores,
+                           data->threads, data->maxcpus);
+    qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
+                             test_data_free);
+    g_free(path);
+
+    path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
+                           mname, data2->sockets, data2->cores,
+                           data2->threads, data2->maxcpus);
+    qtest_add_data_func_full(path, data2, test_plug_with_device_add_coreid,
+                             test_data_free);
+    g_free(path);
+}
+
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();

tests/cpu-plug-test.c int main(int argc, char **argv) · line 260

Quoted 8 lines
tests/cpu-plug-test.c +2 -0
@@ -217,6 +253,8 @@ int main(int argc, char **argv)
         qtest_cb_for_every_machine(add_pc_test_case);
     } else if (g_str_equal(arch, "ppc64")) {
         qtest_cb_for_every_machine(add_pseries_test_case);
+    } else if (g_str_equal(arch, "s390x")) {
+        qtest_cb_for_every_machine(add_s390x_test_case);
     }
 
     return g_test_run();

Looks sane to me, haven't tested it, though.

Signature · 3 lines
Thanks,

David
#10 lore raw
In reply to Thomas Huth
Quoted 3 lines · Thomas Huth

So far the CPU hot-plug qtest was only checking "cpu-add" on x86. With these patches, we now test "device_add" for hot-plugging CPUs on x86, and enable the test on ppc64 and s390x, too.

Question: is there a reason other than "no one bothered" to not have a CPU hot unplug test, something around the lines of the now cpu-plug-test.c? I might give it a shot if there is no known roadblocks against it.

Thanks,

Daniel

Quoted 14 lines

Thomas Huth (4):
tests: Rename pc-cpu-test.c to cpu-plug-test.c tests/cpu-plug-test: Check the CPU hot-plugging with device_add, too tests/cpu-plug-test: Check CPU hot-plugging on ppc64, too tests/cpu-plug-test: Test CPU hot-plugging on s390x

  tests/Makefile.include |   6 +-
  tests/cpu-plug-test.c  | 261 +++++++++++++++++++++++++++++++++++++++++++++++++
  tests/pc-cpu-test.c    | 135 -------------------------
  3 files changed, 265 insertions(+), 137 deletions(-)

create mode 100644 tests/cpu-plug-test.c
delete mode 100644 tests/pc-cpu-test.c

#11 lore raw
Quoted 11 lines · Daniel Henrique Barboza
Quoted 3 lines · Thomas Huth

So far the CPU hot-plug qtest was only checking "cpu-add" on x86. With these patches, we now test "device_add" for hot-plugging CPUs on x86, and enable the test on ppc64 and s390x, too.

Question: is there a reason other than "no one bothered" to not have a CPU hot
unplug test, something around the lines of the now cpu-plug-test.c? I might give it a shot if there is no known roadblocks against it.

AFAIK on x86, you need some ACPI magic on the guest side to do this (something similar to qpci_unplug_acpi_device_test() in tests/libqos/pci-pc.c I guess). And on s390x, CPU unplug is not supported at all. But it might work on ppc64 without guest intervention, not sure - maybe Bharata can comment on this...

Thomas

#12 lore raw
Quoted 10 lines · Thomas Huth
Quoted 9 lines · Daniel Henrique Barboza
Quoted 3 lines · Thomas Huth

So far the CPU hot-plug qtest was only checking "cpu-add" on x86. With these patches, we now test "device_add" for hot-plugging CPUs on x86, and enable the test on ppc64 and s390x, too.

Question: is there a reason other than "no one bothered" to not have a CPU hot
unplug test, something around the lines of the now cpu-plug-test.c? I might give it a shot if there is no known roadblocks against it.

Quoted 5 lines

AFAIK on x86, you need some ACPI magic on the guest side to do this (something similar to qpci_unplug_acpi_device_test() in tests/libqos/pci-pc.c I guess). And on s390x, CPU unplug is not supported at all. But it might work on ppc64 without guest intervention, not sure - maybe Bharata can comment on this...

Good point, it won't work in spapr machine without guest intervention too. Both CPU and LMB unplug relies on guest-side callbacks to complete the operation.

I'll see how this ACPI magic you mentioned is done and see how hard it is to do it for ppc64.

Daniel

Quoted 3 lines

Thomas