Skip to contentSkip to conversation

WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

PATCH Superseded Yichen Wang 5 participants 33 messages Jul 11, 2024 – Sep 16, 2024 Arm/Amlogic Meson SoC support

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#1 lore raw

PATCH v5 1/13 meson: Introduce new instruction set enqcmd to the build system.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

Enable instruction set enqcmd in build.

---
 meson.build                   | 14 ++++++++++++++
 meson_options.txt             |  2 ++
 scripts/meson-buildoptions.sh |  3 +++
 3 files changed, 19 insertions(+)
meson.build +14 -0
index 6a93da48e1..af650cfabf 100644
@@ -2893,6 +2893,20 @@ config_host_data.set('CONFIG_AVX512BW_OPT', get_option('avx512bw') \
     int main(int argc, char *argv[]) { return bar(argv[0]); }
   '''), error_message: 'AVX512BW not available').allowed())
 
+config_host_data.set('CONFIG_DSA_OPT', get_option('enqcmd') \
+  .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable ENQCMD') \
+  .require(cc.links('''
+    #include <stdint.h>
+    #include <cpuid.h>
+    #include <immintrin.h>
+    static int __attribute__((target("enqcmd"))) bar(void *a) {
+      uint64_t dst[8] = { 0 };
+      uint64_t src[8] = { 0 };
+      return _enqcmd(dst, src);
+    }
+    int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
+  '''), error_message: 'ENQCMD not available').allowed())
+
 # For both AArch64 and AArch32, detect if builtins are available.
 config_host_data.set('CONFIG_ARM_AES_BUILTIN', cc.compiles('''
     #include <arm_neon.h>
meson_options.txt +2 -0
index 0269fa0f16..4ed820bb8d 100644
@@ -121,6 +121,8 @@ option('avx2', type: 'feature', value: 'auto',
        description: 'AVX2 optimizations')
 option('avx512bw', type: 'feature', value: 'auto',
        description: 'AVX512BW optimizations')
+option('enqcmd', type: 'feature', value: 'disabled',
+       description: 'ENQCMD optimizations')
 option('keyring', type: 'feature', value: 'auto',
        description: 'Linux keyring support')
 option('libkeyutils', type: 'feature', value: 'auto',
scripts/meson-buildoptions.sh +3 -0
index cfadb5ea86..280e117687 100644
@@ -95,6 +95,7 @@ meson_options_help() {
   printf "%s\n" '  auth-pam        PAM access control'
   printf "%s\n" '  avx2            AVX2 optimizations'
   printf "%s\n" '  avx512bw        AVX512BW optimizations'
+  printf "%s\n" '  enqcmd          ENQCMD optimizations'
   printf "%s\n" '  blkio           libblkio block device driver'
   printf "%s\n" '  bochs           bochs image format support'
   printf "%s\n" '  bpf             eBPF support'
@@ -239,6 +240,8 @@ _meson_option_parse() {
     --disable-avx2) printf "%s" -Davx2=disabled ;;
     --enable-avx512bw) printf "%s" -Davx512bw=enabled ;;
     --disable-avx512bw) printf "%s" -Davx512bw=disabled ;;
+    --enable-enqcmd) printf "%s" -Denqcmd=enabled ;;
+    --disable-enqcmd) printf "%s" -Denqcmd=disabled ;;
     --enable-gcov) printf "%s" -Db_coverage=true ;;
     --disable-gcov) printf "%s" -Db_coverage=false ;;
     --enable-lto) printf "%s" -Db_lto=true ;;
Signature · 1 line
Yichen Wang
#5 lore raw

PATCH v5 3/13 util/dsa: Implement DSA device start and stop logic.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

* DSA device open and close.
* DSA group contains multiple DSA devices.
* DSA group configure/start/stop/clean.

---
 include/qemu/dsa.h |  86 +++++++++++++
 util/dsa.c         | 303 +++++++++++++++++++++++++++++++++++++++++++++
 util/meson.build   |   3 +
 3 files changed, 392 insertions(+)
 create mode 100644 include/qemu/dsa.h
 create mode 100644 util/dsa.c
include/qemu/dsa.h new file +86 -0
new file mode 100644
index 0000000000..29b60654e9
@@ -0,0 +1,86 @@
+/*
+ * Interface for using Intel Data Streaming Accelerator to offload certain
+ * background operations.
+ *
+ * Copyright (C) Bytedance Ltd.
+ *
+ * Authors:
+ *  Hao Xiang <[email protected]>
+ *  Yichen Wang <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_DSA_H
+#define QEMU_DSA_H
+
+#include "qemu/error-report.h"
+#include "qemu/thread.h"
+#include "qemu/queue.h"
+
+#ifdef CONFIG_DSA_OPT
+
+#pragma GCC push_options
+#pragma GCC target("enqcmd")
+
+#include <linux/idxd.h>
+#include "x86intrin.h"
+
+/**
+ * @brief Initializes DSA devices.
+ *
+ * @param dsa_parameter A list of DSA device path from migration parameter.
+ *
+ * @return int Zero if successful, otherwise non zero.
+ */
+int qemu_dsa_init(const char *dsa_parameter, Error **errp);
+
+/**
+ * @brief Start logic to enable using DSA.
+ */
+void qemu_dsa_start(void);
+
+/**
+ * @brief Stop the device group and the completion thread.
+ */
+void qemu_dsa_stop(void);
+
+/**
+ * @brief Clean up system resources created for DSA offloading.
+ */
+void qemu_dsa_cleanup(void);
+
+/**
+ * @brief Check if DSA is running.
+ *
+ * @return True if DSA is running, otherwise false.
+ */
+bool qemu_dsa_is_running(void);
+
+#else
+
+static inline bool qemu_dsa_is_running(void)
+{
+    return false;
+}
+
+static inline int qemu_dsa_init(const char *dsa_parameter, Error **errp)
+{
+    if (dsa_parameter != NULL && strlen(dsa_parameter) != 0) {
+        error_setg(errp, "DSA is not supported.");
+        return -1;
+    }
+
+    return 0;
+}
+
+static inline void qemu_dsa_start(void) {}
+
+static inline void qemu_dsa_stop(void) {}
+
+static inline void qemu_dsa_cleanup(void) {}
+
+#endif
+
+#endif
util/dsa.c new file +303 -0

303 lines not on this page · raw message

util/meson.build +3 -0
index 5d8bef9891..3360f62923 100644
@@ -88,6 +88,9 @@ if have_block or have_ga
 endif
 if have_block
   util_ss.add(files('aio-wait.c'))
+  if config_host_data.get('CONFIG_DSA_OPT')
+    util_ss.add(files('dsa.c'))
+  endif
   util_ss.add(files('buffer.c'))
   util_ss.add(files('bufferiszero.c'))
   util_ss.add(files('hbitmap.c'))
Signature · 1 line
Yichen Wang
#9 lore raw

PATCH v5 7/13 util/dsa: Implement DSA task asynchronous submission and wait for completion.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

* Add a DSA task completion callback.
* DSA completion thread will call the tasks's completion callback on every task/batch task completion.
* DSA submission path to wait for completion.
* Implement CPU fallback if DSA is not able to complete the task.

---
 include/qemu/dsa.h |  14 +++++
 util/dsa.c         | 125 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 135 insertions(+), 4 deletions(-)
include/qemu/dsa.h +14 -0
index 1b4baf1c80..20bb88d48c 100644
@@ -123,6 +123,20 @@ buffer_zero_batch_task_init(QemuDsaBatchTask *task,
  */
 void buffer_zero_batch_task_destroy(QemuDsaBatchTask *task);
 
+/**
+ * @brief Performs buffer zero comparison on a DSA batch task synchronously.
+ *
+ * @param batch_task A pointer to the batch task.
+ * @param buf An array of memory buffers.
+ * @param count The number of buffers in the array.
+ * @param len The buffer length.
+ *
+ * @return Zero if successful, otherwise non-zero.
+ */
+int
+buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,
+                              const void **buf, size_t count, size_t len);
+
 #else
 
 static inline bool qemu_dsa_is_running(void)
util/dsa.c +121 -4

164 lines not on this page · raw message

Signature · 1 line
Yichen Wang
#7 lore raw

PATCH v5 5/13 util/dsa: Implement DSA task asynchronous completion thread model.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

* Create a dedicated thread for DSA task completion.
* DSA completion thread runs a loop and poll for completed tasks.
* Start and stop DSA completion thread during DSA device start stop.

User space application can directly submit task to Intel DSA accelerator by writing to DSA's device memory (mapped in user space). Once a task is submitted, the device starts processing it and write the completion status back to the task. A user space application can poll the task's completion status to check for completion. This change uses a dedicated thread to perform DSA task completion checking.

---
 include/qemu/dsa.h |   1 +
 util/dsa.c         | 274 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 274 insertions(+), 1 deletion(-)
include/qemu/dsa.h +1 -0
index 9cc836b64c..d46a9f42a5 100644
@@ -69,6 +69,7 @@ typedef struct QemuDsaBatchTask {
     QemuDsaTaskType task_type;
     QemuDsaTaskStatus status;
     int batch_size;
+    bool *results;
     QSIMPLEQ_ENTRY(QemuDsaBatchTask) entry;
 } QemuDsaBatchTask;
 
util/dsa.c +273 -1

307 lines not on this page · raw message

Signature · 1 line
Yichen Wang
#4 lore raw

PATCH v5 2/13 util/dsa: Add idxd into linux header copy list.

In reply to Yichen Wang
---
 scripts/update-linux-headers.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/update-linux-headers.sh +1 -1
index c34ac6454e..5aba95d9cb 100755
@@ -193,7 +193,7 @@ rm -rf "$output/linux-headers/linux"
 mkdir -p "$output/linux-headers/linux"
 for header in const.h stddef.h kvm.h vfio.h vfio_ccw.h vfio_zdev.h vhost.h \
               psci.h psp-sev.h userfaultfd.h memfd.h mman.h nvme_ioctl.h \
-              vduse.h iommufd.h bits.h; do
+              vduse.h iommufd.h bits.h idxd.h; do
     cp "$hdrdir/include/linux/$header" "$output/linux-headers/linux"
 done
 
Signature · 1 line
Yichen Wang
#0 lore raw

v5 cover WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

v5
* Rebase on top of 39a032cea23e522268519d89bb738974bc43b6f6.
* Rename struct definitions with typedef and CamelCase names;
* Add build and runtime checks about DSA accelerator;
* Address all comments from v4 reviews about typos, licenses, comments, error reporting, etc.

v4
* Rebase on top of 85b597413d4370cb168f711192eaef2eb70535ac.
* A separate "multifd zero page checking" patchset was split from this patchset's v3 and got merged into master. v4 re-applied the rest of all commits on top of that patchset, re-factored and re-tested.
https://lore.kernel.org/all/[email protected]/
* There are some feedback from v3 I likely overlooked.

v3
* Rebase on top of 7425b6277f12e82952cede1f531bfc689bf77fb1.
* Fix error/warning from checkpatch.pl
* Fix use-after-free bug when multifd-dsa-accel option is not set.
* Handle error from dsa_init and correctly propogate the error.
* Remove unnecessary call to dsa_stop.
* Detect availability of DSA feature at compile time.
* Implement a generic batch_task structure and a DSA specific one dsa_batch_task.
* Remove all exit() calls and propagate errors correctly.
* Use bytes instead of page count to configure multifd-packet-size option.

v2
* Rebase on top of 3e01f1147a16ca566694b97eafc941d62fa1e8d8.
* Leave Juan's changes in their original form instead of squashing them.
* Add a new commit to refactor the multifd_send_thread function to prepare for introducing the DSA offload functionality.
* Use page count to configure multifd-packet-size option.
* Don't use the FLAKY flag in DSA tests.
* Test if DSA integration test is setup correctly and skip the test if
* not.
* Fixed broken link in the previous patch cover.

* Background:

I posted an RFC about DSA offloading in QEMU:
https://patchew.org/QEMU/[email protected]/

This patchset implements the DSA offloading on zero page checking in multifd live migration code path.

* Overview:

Intel Data Streaming Accelerator(DSA) is introduced in Intel's 4th generation Xeon server, aka Sapphire Rapids.
https://cdrdv2-public.intel.com/671116/341204-intel-data-streaming-accelerator-spec.pdf
https://www.intel.com/content/www/us/en/content-details/759709/intel-data-streaming-accelerator-user-guide.html
One of the things DSA can do is to offload memory comparison workload from CPU to DSA accelerator hardware. This patchset implements a solution to offload QEMU's zero page checking from CPU to DSA accelerator hardware. We gain two benefits from this change:
1. Reduces CPU usage in multifd live migration workflow across all use cases.
2. Reduces migration total time in some use cases.

* Design:

These are the logical steps to perform DSA offloading:
1. Configure DSA accelerators and create user space openable DSA work queues via the idxd driver.
2. Map DSA's work queue into a user space address space.
3. Fill an in-memory task descriptor to describe the memory operation.
4. Use dedicated CPU instruction _enqcmd to queue a task descriptor to the work queue.
5. Pull the task descriptor's completion status field until the task completes.
6. Check return status.

The memory operation is now totally done by the accelerator hardware but the new workflow introduces overheads. The overhead is the extra cost CPU prepares and submits the task descriptors and the extra cost CPU pulls for completion. The design is around minimizing these two overheads.

1. In order to reduce the overhead on task preparation and submission, we use batch descriptors. A batch descriptor will contain N individual zero page checking tasks where the default N is 128 (default packet size / page size) and we can increase N by setting the packet size via a new migration option.
2. The multifd sender threads prepares and submits batch tasks to DSA hardware and it waits on a synchronization object for task completion. Whenever a DSA task is submitted, the task structure is added to a thread safe queue. It's safe to have multiple multifd sender threads to submit tasks concurrently.
3. Multiple DSA hardware devices can be used. During multifd initialization, every sender thread will be assigned a DSA device to work with. We use a round-robin scheme to evenly distribute the work across all used DSA devices.
4. Use a dedicated thread dsa_completion to perform busy pulling for all DSA task completions. The thread keeps dequeuing DSA tasks from the thread safe queue. The thread blocks when there is no outstanding DSA task. When pulling for completion of a DSA task, the thread uses CPU instruction _mm_pause between the iterations of a busy loop to save some CPU power as well as optimizing core resources for the other hypercore.
5. DSA accelerator can encounter errors. The most popular error is a page fault. We have tested using devices to handle page faults but performance is bad. Right now, if DSA hits a page fault, we fallback to use CPU to complete the rest of the work. The CPU fallback is done in the multifd sender thread.
6. Added a new migration option multifd-dsa-accel to set the DSA device path. If set, the multifd workflow will leverage the DSA devices for offloading.
7. Added a new migration option multifd-normal-page-ratio to make multifd live migration easier to test. Setting a normal page ratio will make live migration recognize a zero page as a normal page and send the entire payload over the network. If we want to send a large network payload and analyze throughput, this option is useful.
8. Added a new migration option multifd-packet-size. This can increase the number of pages being zero page checked and sent over the network. The extra synchronization between the sender threads and the dsa completion thread is an overhead. Using a large packet size can reduce that overhead.

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to control the total size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with the baseline.
6. Use "perf sched record" and "perf sched timehist" to analyze CPU usage.

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|---------------|
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|---------------|

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

	Latency
	|---------------|---------------|---------------|---------------|---------------|---------------|
	|		|total time	|down time	|throughput	|transferred-ram|total-ram	|
	|---------------|---------------|---------------|---------------|---------------|---------------|	
	|Baseline	|10343 ms	|161 ms		|41007.00 mbps	|51583797 kb	|102400520 kb	|
	|---------------|---------------|---------------|---------------|-------------------------------|
	|DSA offload	|9535 ms	|135 ms		|46554.40 mbps	|53947545 kb	|102400520 kb	|	
	|---------------|---------------|---------------|---------------|---------------|---------------|

Total time is 8% faster and down time is 16% faster.

B) Scenario 2: 100% (100GB) zero pages on an 100GB vm.

	CPU usage
	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|4860.718	|		|
	|	 	|multifdsend_0	|748.875	|		|
	|		|multifdsend_1	|898.498	|		|
	|		|multifdsend_2	|787.456	|		|
	|		|multifdsend_3	|764.537	|		|
	|		|multifdsend_4	|785.687	|		|
	|		|multifdsend_5	|756.941	|		|
	|		|multifdsend_6	|774.084	|		|
	|		|multifdsend_7	|782.900	|11154		|
	|---------------|---------------|-------------------------------|
	|DSA offloading	|live_migration	|3846.976	|		|
	|		|multifdsend_0	|191.880	|		|
	|		|multifdsend_1	|166.331	|		|
	|		|multifdsend_2	|168.528	|		|
	|		|multifdsend_3	|197.831	|		|
	|		|multifdsend_4	|169.580	|		|
	|		|multifdsend_5	|167.984	|		|
	|		|multifdsend_6	|198.042	|		|
	|		|multifdsend_7	|170.624	|		|
	|		|dsa_completion	|3428.669	|8700		|
	|---------------|---------------|---------------|---------------|

Baseline total runtime is 11154 msec and DSA offloading total runtime is 8700 msec. That is 22% CPU savings.

	Latency
	|--------------------------------------------------------------------------------------------|
	|		|total time	|down time	|throughput	|transferred-ram|total-ram   |
	|---------------|---------------|---------------|---------------|---------------|------------|	
	|Baseline	|4867 ms	|20 ms		|1.51 mbps	|565 kb		|102400520 kb|
	|---------------|---------------|---------------|---------------|----------------------------|
	|DSA offload	|3888 ms	|18 ms		|1.89 mbps	|565 kb		|102400520 kb|	
	|---------------|---------------|---------------|---------------|---------------|------------|

Total time 20% faster and down time 10% faster.

* Testing:

1. Added unit tests for cover the added code path in dsa.c
2. Added integration tests to cover multifd live migration using DSA offloading.

Hao Xiang (12):
meson: Introduce new instruction set enqcmd to the build system. util/dsa: Implement DSA device start and stop logic. util/dsa: Implement DSA task enqueue and dequeue. util/dsa: Implement DSA task asynchronous completion thread model. util/dsa: Implement zero page checking in DSA task. util/dsa: Implement DSA task asynchronous submission and wait for
completion.
migration/multifd: Add new migration option for multifd DSA
offloading.
migration/multifd: Prepare to introduce DSA acceleration on the
multifd path.
migration/multifd: Enable DSA offloading in multifd sender path. migration/multifd: Add migration option set packet size. util/dsa: Add unit test coverage for Intel DSA task submission and
completion.
migration/multifd: Add integration tests for multifd with Intel DSA
offloading.

Yichen Wang (1):
util/dsa: Add idxd into linux header copy list.

 include/qemu/dsa.h              |  176 +++++
 meson.build                     |   14 +
 meson_options.txt               |    2 +
 migration/migration-hmp-cmds.c  |   22 +-
 migration/migration.c           |    2 +-
 migration/multifd-zero-page.c   |  100 ++-
 migration/multifd-zlib.c        |    6 +-
 migration/multifd-zstd.c        |    6 +-
 migration/multifd.c             |   53 +-
 migration/multifd.h             |    8 +-
 migration/options.c             |   85 +++
 migration/options.h             |    2 +
 qapi/migration.json             |   49 +-
 scripts/meson-buildoptions.sh   |    3 +
 scripts/update-linux-headers.sh |    2 +-
 tests/qtest/migration-test.c    |   80 ++-
 tests/unit/meson.build          |    6 +
 tests/unit/test-dsa.c           |  503 ++++++++++++++
 util/dsa.c                      | 1082 +++++++++++++++++++++++++++++++
 util/meson.build                |    3 +
 20 files changed, 2177 insertions(+), 27 deletions(-)
 create mode 100644 include/qemu/dsa.h
 create mode 100644 tests/unit/test-dsa.c
 create mode 100644 util/dsa.c
Signature · 1 line
Yichen Wang
#18 lore raw

PATCH v5 9/13 migration/multifd: Prepare to introduce DSA acceleration on the multifd path.

From: Hao Xiang <[email protected]>

1. Refactor multifd_send_thread function.
2. Introduce the batch task structure in MultiFDSendParams.

---
 include/qemu/dsa.h  |  41 ++++---
 migration/multifd.c |   4 +
 migration/multifd.h |   3 +
 util/dsa.c          | 270 +++++++++++++++++++++++---------------------
 4 files changed, 172 insertions(+), 146 deletions(-)
include/qemu/dsa.h +26 -15
index 20bb88d48c..fd0305a7c7 100644
@@ -16,6 +16,7 @@
 #define QEMU_DSA_H
 
 #include "qemu/error-report.h"
+#include "exec/cpu-common.h"
 #include "qemu/thread.h"
 #include "qemu/queue.h"
 
@@ -70,10 +71,11 @@ typedef struct QemuDsaBatchTask {
     QemuDsaTaskStatus status;
     int batch_size;
     bool *results;
+    /* Address of each pages in pages */
+    ram_addr_t *addr;
     QSIMPLEQ_ENTRY(QemuDsaBatchTask) entry;
 } QemuDsaBatchTask;
 
-
 /**
  * @brief Initializes DSA devices.
  *
@@ -106,15 +108,13 @@ void qemu_dsa_cleanup(void);
 bool qemu_dsa_is_running(void);
 
 /**
- * @brief Initializes a buffer zero batch task.
+ * @brief Initializes a buffer zero DSA batch task.
  *
- * @param task A pointer to the batch task to initialize.
- * @param results A pointer to an array of zero page checking results.
- * @param batch_size The number of DSA tasks in the batch.
+ * @param batch_size The number of zero page checking tasks in the batch.
+ * @return A pointer to the zero page checking tasks initialized.
  */
-void
-buffer_zero_batch_task_init(QemuDsaBatchTask *task,
-                            bool *results, int batch_size);
+QemuDsaBatchTask *
+buffer_zero_batch_task_init(int batch_size);
 
 /**
  * @brief Performs the proper cleanup on a DSA batch task.
@@ -139,6 +139,8 @@ buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,
 
 #else
 
+typedef struct QemuDsaBatchTask {} QemuDsaBatchTask;
+
 static inline bool qemu_dsa_is_running(void)
 {
     return false;
@@ -146,19 +148,28 @@ static inline bool qemu_dsa_is_running(void)
 
 static inline int qemu_dsa_init(const char *dsa_parameter, Error **errp)
 {
-    if (dsa_parameter != NULL && strlen(dsa_parameter) != 0) {
-        error_setg(errp, "DSA is not supported.");
-        return -1;
-    }
-
-    return 0;
+    error_setg(errp, "DSA accelerator is not enabled.");
+    return -1;
 }
 
 static inline void qemu_dsa_start(void) {}
 
 static inline void qemu_dsa_stop(void) {}
 
-static inline void qemu_dsa_cleanup(void) {}
+static inline QemuDsaBatchTask *buffer_zero_batch_task_init(int batch_size)
+{
+    return NULL;
+}
+
+static inline void buffer_zero_batch_task_destroy(QemuDsaBatchTask *task) {}
+
+static inline int
+buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,
+                              const void **buf, size_t count, size_t len)
+{
+    error_setg(errp, "DSA accelerator is not enabled.");
+    return -1;
+}
 
 #endif
 
migration/multifd.c +4 -0
index 0b4cbaddfe..6f8edd4b6a 100644
@@ -13,6 +13,7 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/rcu.h"
+#include "qemu/dsa.h"
 #include "exec/target_page.h"
 #include "sysemu/sysemu.h"
 #include "exec/ramblock.h"
@@ -792,6 +793,8 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp)
     p->name = NULL;
     multifd_pages_clear(p->pages);
     p->pages = NULL;
+    buffer_zero_batch_task_destroy(p->dsa_batch_task);
+    p->dsa_batch_task = NULL;
     p->packet_len = 0;
     g_free(p->packet);
     p->packet = NULL;
@@ -1182,6 +1185,7 @@ bool multifd_send_setup(void)
         qemu_sem_init(&p->sem_sync, 0);
         p->id = i;
         p->pages = multifd_pages_init(page_count);
+        p->dsa_batch_task = buffer_zero_batch_task_init(page_count);
 
         if (use_packets) {
             p->packet_len = sizeof(MultiFDPacket_t)
migration/multifd.h +3 -0
index 0ecd6f47d7..027f57bf4e 100644
@@ -14,6 +14,7 @@
 #define QEMU_MIGRATION_MULTIFD_H
 
 #include "ram.h"
+#include "qemu/dsa.h"
 
 typedef struct MultiFDRecvData MultiFDRecvData;
 
@@ -137,6 +138,8 @@ typedef struct {
      * pending_job != 0 -> multifd_channel can use it.
      */
     MultiFDPages_t *pages;
+    /* Zero page checking batch task */
+    QemuDsaBatchTask *dsa_batch_task;
 
     /* thread local variables. No locking required */
 
util/dsa.c +139 -131

325 lines not on this page · raw message

Signature · 1 line
Yichen Wang
#10 lore raw

PATCH v5 8/13 migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

Intel DSA offloading is an optional feature that turns on if proper hardware and software stack is available. To turn on DSA offloading in multifd live migration:

dsa-accel-path="[dsa_dev_path1] [dsa_dev_path2] ... [dsa_dev_pathX]"

This feature is turned off by default.

---
 migration/migration-hmp-cmds.c | 15 ++++++++++-
 migration/options.c            | 47 ++++++++++++++++++++++++++++++++++
 migration/options.h            |  1 +
 qapi/migration.json            | 32 ++++++++++++++++++++---
 4 files changed, 90 insertions(+), 5 deletions(-)
migration/migration-hmp-cmds.c +14 -1
index 7d608d26e1..c422db4ecd 100644
@@ -312,7 +312,16 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
             params->tls_authz);
-
+        if (params->has_dsa_accel_path) {
+            strList *dsa_accel_path = params->dsa_accel_path;
+            monitor_printf(mon, "%s:",
+                MigrationParameter_str(MIGRATION_PARAMETER_DSA_ACCEL_PATH));
+            while (dsa_accel_path) {
+                monitor_printf(mon, " %s", dsa_accel_path->value);
+                dsa_accel_path = dsa_accel_path->next;
+            }
+            monitor_printf(mon, "\n");
+        }
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;
 
@@ -563,6 +572,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
         p->has_x_checkpoint_delay = true;
         visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
         break;
+    case MIGRATION_PARAMETER_DSA_ACCEL_PATH:
+        p->has_dsa_accel_path = true;
+        visit_type_strList(v, param, &p->dsa_accel_path, &err);
+        break;
     case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
         p->has_multifd_channels = true;
         visit_type_uint8(v, param, &p->multifd_channels, &err);
migration/options.c +47 -0

101 lines not on this page · raw message

migration/options.h +1 -0
index a2397026db..78b9e4080b 100644
@@ -85,6 +85,7 @@ const char *migrate_tls_creds(void);
 const char *migrate_tls_hostname(void);
 uint64_t migrate_xbzrle_cache_size(void);
 ZeroPageDetection migrate_zero_page_detection(void);
+const strList *migrate_dsa_accel_path(void);
 
 /* parameters helpers */
 
qapi/migration.json +28 -4
index 1234bef888..ff41780347 100644
@@ -619,10 +619,14 @@
 #     multifd migration is enabled, else in the main migration thread
 #     as for @legacy.
 #
+# @dsa-accel: Perform zero page checking with the DSA accelerator
+#     offloading in multifd sender thread if multifd migration is
+#     enabled, else in the main migration thread as for @legacy.
+#
 # Since: 9.0
 ##
 { 'enum': 'ZeroPageDetection',
-  'data': [ 'none', 'legacy', 'multifd' ] }
+  'data': [ 'none', 'legacy', 'multifd', 'dsa-accel' ] }
 
 ##
 # @BitmapMigrationBitmapAliasTransform:
@@ -825,6 +829,12 @@
 #     See description in @ZeroPageDetection.  Default is 'multifd'.
 #     (since 9.0)
 #
+# @dsa-accel-path: If enabled, use DSA accelerator offloading for
+#     certain memory operations. Enable DSA accelerator for zero
+#     page detection offloading by setting the @zero-page-detection
+#     to dsa-accel. This parameter defines the dsa device path, and
+#     defaults to an empty list. (since 9.2)
+#
 # @direct-io: Open migration files with O_DIRECT when possible.  This
 #     only has effect if the @mapped-ram capability is enabled.
 #     (Since 9.1)
@@ -843,7 +853,7 @@
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'cpu-throttle-tailslow',
            'tls-creds', 'tls-hostname', 'tls-authz', 'max-bandwidth',
-           'avail-switchover-bandwidth', 'downtime-limit',
+           'avail-switchover-bandwidth', 'downtime-limit', 'dsa-accel-path',
            { 'name': 'x-checkpoint-delay', 'features': [ 'unstable' ] },
            'multifd-channels',
            'xbzrle-cache-size', 'max-postcopy-bandwidth',
@@ -1000,6 +1010,12 @@
 #     See description in @ZeroPageDetection.  Default is 'multifd'.
 #     (since 9.0)
 #
+# @dsa-accel-path: If enabled, use DSA accelerator offloading for
+#     certain memory operations. Enable DSA accelerator for zero
+#     page detection offloading by setting the @zero-page-detection
+#     to dsa-accel. This parameter defines the dsa device path, and
+#     defaults to an empty list. (since 9.2)
+#
 # @direct-io: Open migration files with O_DIRECT when possible.  This
 #     only has effect if the @mapped-ram capability is enabled.
 #     (Since 9.1)
@@ -1044,7 +1060,8 @@
             '*vcpu-dirty-limit': 'uint64',
             '*mode': 'MigMode',
             '*zero-page-detection': 'ZeroPageDetection',
-            '*direct-io': 'bool' } }
+            '*direct-io': 'bool',
+            '*dsa-accel-path': ['str'] } }
 
 ##
 # @migrate-set-parameters:
@@ -1204,6 +1221,12 @@
 #     See description in @ZeroPageDetection.  Default is 'multifd'.
 #     (since 9.0)
 #
+# @dsa-accel-path: If enabled, use DSA accelerator offloading for
+#     certain memory operations. Enable DSA accelerator for zero
+#     page detection offloading by setting the @zero-page-detection
+#     to dsa-accel. This parameter defines the dsa device path, and
+#     defaults to an empty list. (since 9.2)
+#
 # @direct-io: Open migration files with O_DIRECT when possible.  This
 #     only has effect if the @mapped-ram capability is enabled.
 #     (Since 9.1)
@@ -1245,7 +1268,8 @@
             '*vcpu-dirty-limit': 'uint64',
             '*mode': 'MigMode',
             '*zero-page-detection': 'ZeroPageDetection',
-            '*direct-io': 'bool' } }
+            '*direct-io': 'bool',
+            '*dsa-accel-path': ['str'] } }
 
 ##
 # @query-migrate-parameters:
Signature · 1 line
Yichen Wang
#6 lore raw

PATCH v5 4/13 util/dsa: Implement DSA task enqueue and dequeue.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

* Use a safe thread queue for DSA task enqueue/dequeue.
* Implement DSA task submission.
* Implement DSA batch task submission.

---
 include/qemu/dsa.h |  46 ++++++++++
 util/dsa.c         | 222 ++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 246 insertions(+), 22 deletions(-)
include/qemu/dsa.h +46 -0
index 29b60654e9..9cc836b64c 100644
@@ -27,6 +27,52 @@
 #include <linux/idxd.h>
 #include "x86intrin.h"
 
+typedef enum QemuDsaTaskType {
+    QEMU_DSA_TASK = 0,
+    QEMU_DSA_BATCH_TASK
+} QemuDsaTaskType;
+
+typedef enum QemuDsaTaskStatus {
+    QEMU_DSA_TASK_READY = 0,
+    QEMU_DSA_TASK_PROCESSING,
+    QEMU_DSA_TASK_COMPLETION
+} QemuDsaTaskStatus;
+
+typedef struct {
+    void *work_queue;
+} QemuDsaDevice;
+
+typedef QSIMPLEQ_HEAD(QemuDsaTaskQueue, QemuDsaBatchTask) QemuDsaTaskQueue;
+
+typedef struct {
+    QemuDsaDevice *dsa_devices;
+    int num_dsa_devices;
+    /* The index of the next DSA device to be used. */
+    uint32_t device_allocator_index;
+    bool running;
+    QemuMutex task_queue_lock;
+    QemuCond task_queue_cond;
+    QemuDsaTaskQueue task_queue;
+} QemuDsaDeviceGroup;
+
+typedef void (*qemu_dsa_completion_fn)(void *);
+
+typedef struct QemuDsaBatchTask {
+    struct dsa_hw_desc batch_descriptor;
+    struct dsa_hw_desc *descriptors;
+    struct dsa_completion_record batch_completion __attribute__((aligned(32)));
+    struct dsa_completion_record *completions;
+    QemuDsaDeviceGroup *group;
+    QemuDsaDevice *device;
+    qemu_dsa_completion_fn completion_callback;
+    QemuSemaphore sem_task_complete;
+    QemuDsaTaskType task_type;
+    QemuDsaTaskStatus status;
+    int batch_size;
+    QSIMPLEQ_ENTRY(QemuDsaBatchTask) entry;
+} QemuDsaBatchTask;
+
+
 /**
  * @brief Initializes DSA devices.
  *
util/dsa.c +200 -22

260 lines not on this page · raw message

Signature · 1 line
Yichen Wang
#8 lore raw

PATCH v5 6/13 util/dsa: Implement zero page checking in DSA task.

In reply to Yichen Wang

From: Hao Xiang <[email protected]>

Create DSA task with operation code DSA_OPCODE_COMPVAL. Here we create two types of DSA tasks, a single DSA task and a batch DSA task. Batch DSA task reduces task submission overhead and hence should be the default option. However, due to the way DSA hardware works, a DSA batch task must contain at least two individual tasks. There are times we need to submit a single task and hence a single DSA task submission is also required.

---
 include/qemu/dsa.h |  18 ++++
 util/dsa.c         | 247 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 244 insertions(+), 21 deletions(-)
include/qemu/dsa.h +18 -0
index d46a9f42a5..1b4baf1c80 100644
@@ -105,6 +105,24 @@ void qemu_dsa_cleanup(void);
  */
 bool qemu_dsa_is_running(void);
 
+/**
+ * @brief Initializes a buffer zero batch task.
+ *
+ * @param task A pointer to the batch task to initialize.
+ * @param results A pointer to an array of zero page checking results.
+ * @param batch_size The number of DSA tasks in the batch.
+ */
+void
+buffer_zero_batch_task_init(QemuDsaBatchTask *task,
+                            bool *results, int batch_size);
+
+/**
+ * @brief Performs the proper cleanup on a DSA batch task.
+ *
+ * @param task A pointer to the batch task to cleanup.
+ */
+void buffer_zero_batch_task_destroy(QemuDsaBatchTask *task);
+
 #else
 
 static inline bool qemu_dsa_is_running(void)
util/dsa.c +226 -21

295 lines not on this page · raw message

Signature · 1 line
Yichen Wang
#11 lore raw

Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Yichen Wang
Quoted 13 lines · Yichen Wang
migration/options.c +1 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000

migration/options.c Property migration_properties[] = { · line 172

Quoted 10 lines
migration/options.c +4 -0
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),

I changed the dsa-accel-path to be a ['str'], i.e. strList* in C. However, I am having a hard time about how to define the proper properties here. I don't know what MARCO to use and I can't find good examples... Need some guidance about how to proceed. Basically I will need this to pass something like '-global migration.dsa-accel-path="/dev/dsa/wq0.0"' in cmdline, or "migrate_set_parameter dsa-accel-path" in QEMU CLI. Don't know how to pass strList there.

Thanks very much!

#20 lore raw
In reply to Yichen Wang
Quoted 58 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to control the total size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with the baseline.
6. Use "perf sched record" and "perf sched timehist" to analyze CPU usage.

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|---------------|
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|---------------|
Quoted 5 lines

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

Signature · 1 line
MST
#31 lore raw
In reply to Yichen Wang
Quoted 36 lines · Yichen Wang

v5
* Rebase on top of 39a032cea23e522268519d89bb738974bc43b6f6.
* Rename struct definitions with typedef and CamelCase names;
* Add build and runtime checks about DSA accelerator;
* Address all comments from v4 reviews about typos, licenses, comments, error reporting, etc.

v4
* Rebase on top of 85b597413d4370cb168f711192eaef2eb70535ac.
* A separate "multifd zero page checking" patchset was split from this patchset's v3 and got merged into master. v4 re-applied the rest of all commits on top of that patchset, re-factored and re-tested.
https://lore.kernel.org/all/[email protected]/
* There are some feedback from v3 I likely overlooked.

v3
* Rebase on top of 7425b6277f12e82952cede1f531bfc689bf77fb1.
* Fix error/warning from checkpatch.pl
* Fix use-after-free bug when multifd-dsa-accel option is not set.
* Handle error from dsa_init and correctly propogate the error.
* Remove unnecessary call to dsa_stop.
* Detect availability of DSA feature at compile time.
* Implement a generic batch_task structure and a DSA specific one dsa_batch_task.
* Remove all exit() calls and propagate errors correctly.
* Use bytes instead of page count to configure multifd-packet-size option.

v2
* Rebase on top of 3e01f1147a16ca566694b97eafc941d62fa1e8d8.
* Leave Juan's changes in their original form instead of squashing them.
* Add a new commit to refactor the multifd_send_thread function to prepare for introducing the DSA offload functionality.
* Use page count to configure multifd-packet-size option.
* Don't use the FLAKY flag in DSA tests.
* Test if DSA integration test is setup correctly and skip the test if
* not.
* Fixed broken link in the previous patch cover.

Quoted 1 line

* Background:

The DSA interface here is extremely low level: it would mean we add a ton of complex fragile code for any new accelerator. Please add something high level and simple on top of this. Off the top of my head:

void start_memcmp(void *a, void *b, int cnt, void *opaque,

	void (*callback)(int result, void *a, void *b, int cnt, void *opaque)
	);

Do all the batching hacks internally.

Quoted 249 lines

I posted an RFC about DSA offloading in QEMU:
https://patchew.org/QEMU/[email protected]/

This patchset implements the DSA offloading on zero page checking in multifd live migration code path.

* Overview:

Intel Data Streaming Accelerator(DSA) is introduced in Intel's 4th generation Xeon server, aka Sapphire Rapids.
https://cdrdv2-public.intel.com/671116/341204-intel-data-streaming-accelerator-spec.pdf
https://www.intel.com/content/www/us/en/content-details/759709/intel-data-streaming-accelerator-user-guide.html
One of the things DSA can do is to offload memory comparison workload from CPU to DSA accelerator hardware. This patchset implements a solution to offload QEMU's zero page checking from CPU to DSA accelerator hardware. We gain two benefits from this change:
1. Reduces CPU usage in multifd live migration workflow across all use cases.
2. Reduces migration total time in some use cases.

* Design:

These are the logical steps to perform DSA offloading:
1. Configure DSA accelerators and create user space openable DSA work queues via the idxd driver.
2. Map DSA's work queue into a user space address space.
3. Fill an in-memory task descriptor to describe the memory operation.
4. Use dedicated CPU instruction _enqcmd to queue a task descriptor to the work queue.
5. Pull the task descriptor's completion status field until the task completes.
6. Check return status.

The memory operation is now totally done by the accelerator hardware but the new workflow introduces overheads. The overhead is the extra cost CPU prepares and submits the task descriptors and the extra cost CPU pulls for completion. The design is around minimizing these two overheads.

1. In order to reduce the overhead on task preparation and submission, we use batch descriptors. A batch descriptor will contain N individual zero page checking tasks where the default N is 128 (default packet size / page size) and we can increase N by setting the packet size via a new migration option.
2. The multifd sender threads prepares and submits batch tasks to DSA hardware and it waits on a synchronization object for task completion. Whenever a DSA task is submitted, the task structure is added to a thread safe queue. It's safe to have multiple multifd sender threads to submit tasks concurrently.
3. Multiple DSA hardware devices can be used. During multifd initialization, every sender thread will be assigned a DSA device to work with. We use a round-robin scheme to evenly distribute the work across all used DSA devices.
4. Use a dedicated thread dsa_completion to perform busy pulling for all DSA task completions. The thread keeps dequeuing DSA tasks from the thread safe queue. The thread blocks when there is no outstanding DSA task. When pulling for completion of a DSA task, the thread uses CPU instruction _mm_pause between the iterations of a busy loop to save some CPU power as well as optimizing core resources for the other hypercore.
5. DSA accelerator can encounter errors. The most popular error is a page fault. We have tested using devices to handle page faults but performance is bad. Right now, if DSA hits a page fault, we fallback to use CPU to complete the rest of the work. The CPU fallback is done in the multifd sender thread.
6. Added a new migration option multifd-dsa-accel to set the DSA device path. If set, the multifd workflow will leverage the DSA devices for offloading.
7. Added a new migration option multifd-normal-page-ratio to make multifd live migration easier to test. Setting a normal page ratio will make live migration recognize a zero page as a normal page and send the entire payload over the network. If we want to send a large network payload and analyze throughput, this option is useful.
8. Added a new migration option multifd-packet-size. This can increase the number of pages being zero page checked and sent over the network. The extra synchronization between the sender threads and the dsa completion thread is an overhead. Using a large packet size can reduce that overhead.

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to control the total size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with the baseline.
6. Use "perf sched record" and "perf sched timehist" to analyze CPU usage.

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|---------------|
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|---------------|

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

	Latency
	|---------------|---------------|---------------|---------------|---------------|---------------|
	|		|total time	|down time	|throughput	|transferred-ram|total-ram	|
	|---------------|---------------|---------------|---------------|---------------|---------------|	
	|Baseline	|10343 ms	|161 ms		|41007.00 mbps	|51583797 kb	|102400520 kb	|
	|---------------|---------------|---------------|---------------|-------------------------------|
	|DSA offload	|9535 ms	|135 ms		|46554.40 mbps	|53947545 kb	|102400520 kb	|	
	|---------------|---------------|---------------|---------------|---------------|---------------|

Total time is 8% faster and down time is 16% faster.

B) Scenario 2: 100% (100GB) zero pages on an 100GB vm.

	CPU usage
	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|4860.718	|		|
	|	 	|multifdsend_0	|748.875	|		|
	|		|multifdsend_1	|898.498	|		|
	|		|multifdsend_2	|787.456	|		|
	|		|multifdsend_3	|764.537	|		|
	|		|multifdsend_4	|785.687	|		|
	|		|multifdsend_5	|756.941	|		|
	|		|multifdsend_6	|774.084	|		|
	|		|multifdsend_7	|782.900	|11154		|
	|---------------|---------------|-------------------------------|
	|DSA offloading	|live_migration	|3846.976	|		|
	|		|multifdsend_0	|191.880	|		|
	|		|multifdsend_1	|166.331	|		|
	|		|multifdsend_2	|168.528	|		|
	|		|multifdsend_3	|197.831	|		|
	|		|multifdsend_4	|169.580	|		|
	|		|multifdsend_5	|167.984	|		|
	|		|multifdsend_6	|198.042	|		|
	|		|multifdsend_7	|170.624	|		|
	|		|dsa_completion	|3428.669	|8700		|
	|---------------|---------------|---------------|---------------|

Baseline total runtime is 11154 msec and DSA offloading total runtime is 8700 msec. That is 22% CPU savings.

	Latency
	|--------------------------------------------------------------------------------------------|
	|		|total time	|down time	|throughput	|transferred-ram|total-ram   |
	|---------------|---------------|---------------|---------------|---------------|------------|	
	|Baseline	|4867 ms	|20 ms		|1.51 mbps	|565 kb		|102400520 kb|
	|---------------|---------------|---------------|---------------|----------------------------|
	|DSA offload	|3888 ms	|18 ms		|1.89 mbps	|565 kb		|102400520 kb|	
	|---------------|---------------|---------------|---------------|---------------|------------|

Total time 20% faster and down time 10% faster.

* Testing:

1. Added unit tests for cover the added code path in dsa.c
2. Added integration tests to cover multifd live migration using DSA offloading.

Hao Xiang (12):
meson: Introduce new instruction set enqcmd to the build system. util/dsa: Implement DSA device start and stop logic. util/dsa: Implement DSA task enqueue and dequeue. util/dsa: Implement DSA task asynchronous completion thread model. util/dsa: Implement zero page checking in DSA task. util/dsa: Implement DSA task asynchronous submission and wait for
completion.
migration/multifd: Add new migration option for multifd DSA
offloading.
migration/multifd: Prepare to introduce DSA acceleration on the
multifd path.
migration/multifd: Enable DSA offloading in multifd sender path. migration/multifd: Add migration option set packet size. util/dsa: Add unit test coverage for Intel DSA task submission and
completion.
migration/multifd: Add integration tests for multifd with Intel DSA
offloading.

Yichen Wang (1):
util/dsa: Add idxd into linux header copy list.

 include/qemu/dsa.h              |  176 +++++
 meson.build                     |   14 +
 meson_options.txt               |    2 +
 migration/migration-hmp-cmds.c  |   22 +-
 migration/migration.c           |    2 +-
 migration/multifd-zero-page.c   |  100 ++-
 migration/multifd-zlib.c        |    6 +-
 migration/multifd-zstd.c        |    6 +-
 migration/multifd.c             |   53 +-
 migration/multifd.h             |    8 +-
 migration/options.c             |   85 +++
 migration/options.h             |    2 +
 qapi/migration.json             |   49 +-
 scripts/meson-buildoptions.sh   |    3 +
 scripts/update-linux-headers.sh |    2 +-
 tests/qtest/migration-test.c    |   80 ++-
 tests/unit/meson.build          |    6 +
 tests/unit/test-dsa.c           |  503 ++++++++++++++
 util/dsa.c                      | 1082 +++++++++++++++++++++++++++++++
 util/meson.build                |    3 +
 20 files changed, 2177 insertions(+), 27 deletions(-)
 create mode 100644 include/qemu/dsa.h
 create mode 100644 tests/unit/test-dsa.c
 create mode 100644 util/dsa.c
Signature · 1 line
Yichen Wang
#21 lore raw
In reply to Michael S. Tsirkin
Quoted 87 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 19 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
Quoted 3 lines

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to control

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with the

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to analyze CPU

usage.

Quoted 30 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|---------------|
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|---------------|
Quoted 5 lines

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Quoted 7 lines

Sounds good but a question: what if several qemu instances are migrated in parallel?

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances.
The DSA resource used by each process is called a work queue, each DSA device can support up to 8 work queues and work queues are classified into dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically, there is no limit on the number of processes in a shared queue, it is based on enqcmd + SVM technology.

https://www.kernel.org/doc/html/v5.17/x86/sva.html

Quoted 2 lines

--
MST

#22 lore raw
Quoted 100 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 87 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 19 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
Quoted 3 lines

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to control

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with the

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to analyze CPU

usage.

Quoted 30 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|---------------|
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|---------------|
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|---------------|
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|---------------|
Quoted 5 lines

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Quoted 7 lines

Sounds good but a question: what if several qemu instances are migrated in parallel?

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances.
The DSA resource used by each process is called a work queue, each DSA device can support up to 8 work queues and work queues are classified into dedicated queues and shared queues.

Quoted 4 lines

A dedicated queue can only serve one process. Theoretically, there is no limit on the number of processes in a shared queue, it is based on enqcmd + SVM technology.

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100 single cpu qemu instances with no issue. What happens if you do this with DSA?

Quoted 2 lines
Quoted 2 lines

--
MST

#23 lore raw
Quoted 128 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 8:24 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé

<[email protected]>;

Quoted 6 lines
Quoted 6 lines

Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>; Ho-

Ren

Quoted 2 lines
Quoted 2 lines

(Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 22 lines
Quoted 22 lines

zero page checking in multifd live migration.

Quoted 19 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to

control

Quoted 6 lines
Quoted 6 lines

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with

the

Quoted 9 lines
Quoted 9 lines

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to analyze CPU

usage.

Quoted 6 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|-------------

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|-------------

--|

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|-------------

--|

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|-------------

--|

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Quoted 8 lines
Quoted 4 lines

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances. The DSA resource used by each process is called a work queue, each DSA device can support up to 8 work queues and work queues are classified

into

Quoted 3 lines

dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically, there is no

Quoted 8 lines

limit

Quoted 1 line

on the number of processes in a shared queue, it is based on enqcmd +

SVM technology.

Quoted 2 lines

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100 single cpu qemu instances with no issue. What happens if you do this with DSA?

First, the DSA work queue needs to be configured in shared mode, and one queue is enough.

The maximum depth of the work queue of the DSA hardware is 128, which means that the number of zero-page detection tasks submitted cannot exceed 128, otherwise, enqcmd will return an error until the work queue is available again

100 Qemu instances need to be migrated concurrently, I don't have any data on this yet, I think the 100 zero-page detection tasks can be successfully submitted to the DSA hardware work queue, but the throughput of DSA's zero-page detection also needs to be considered. Once the DSA maximum throughput is reached, the work queue may be filled up quickly, this will cause some Qemu instances to be temporarily unable to submit new tasks to DSA. This is likely to happen in the first round of migration memory iteration.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--
MST

#24 lore raw
Quoted 144 lines · On Mon, Jul 15, 2024 at 01:09:59PM +0000, Liu, Yuan1 wrote:
Quoted 128 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 8:24 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé

<[email protected]>;

Quoted 6 lines
Quoted 6 lines

Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>; Ho-

Ren

Quoted 2 lines
Quoted 2 lines

(Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 22 lines
Quoted 22 lines

zero page checking in multifd live migration.

Quoted 19 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to

control

Quoted 6 lines
Quoted 6 lines

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare with

the

Quoted 9 lines
Quoted 9 lines

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to analyze CPU

usage.

Quoted 6 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|-------------

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|-------------

--|

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|-------------

--|

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|-------------

--|

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Baseline total runtime is calculated by adding up all multifdsend_X and live_migration threads runtime. DSA offloading total runtime is calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Quoted 8 lines
Quoted 4 lines

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances. The DSA resource used by each process is called a work queue, each DSA device can support up to 8 work queues and work queues are classified

into

Quoted 3 lines

dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically, there is no

Quoted 8 lines

limit

Quoted 1 line

on the number of processes in a shared queue, it is based on enqcmd +

SVM technology.

Quoted 2 lines

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100 single cpu qemu instances with no issue. What happens if you do this with DSA?

First, the DSA work queue needs to be configured in shared mode, and one queue is enough.

The maximum depth of the work queue of the DSA hardware is 128, which means that the number of zero-page detection tasks submitted cannot exceed 128, otherwise, enqcmd will return an error until the work queue is available again

Quoted 6 lines

100 Qemu instances need to be migrated concurrently, I don't have any data on this yet, I think the 100 zero-page detection tasks can be successfully submitted to the DSA hardware work queue, but the throughput of DSA's zero-page detection also needs to be considered. Once the DSA maximum throughput is reached, the work queue may be filled up quickly, this will cause some Qemu instances to be temporarily unable to submit new tasks to DSA.

The unfortunate reality here would be that there's likely no QoS, this is purely fifo, right?

Quoted 2 lines

This is likely to happen in the first round of migration memory iteration.

Try testing this and see then?

Signature · 1 line
MST
#2 lore raw

RE: [PATCH v5 01/13] meson: Introduce new instruction set enqcmd to the build system.

In reply to Yichen Wang
Quoted 42 lines

-----Original Message-----
From: Yichen Wang <[email protected]>
Sent: Friday, July 12, 2024 5:53 AM
To: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Michael S. Tsirkin <[email protected]>; Cornelia Huck <[email protected]>; [email protected]
Cc: Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>; Wang, Yichen <[email protected]>
Subject: [PATCH v5 01/13] meson: Introduce new instruction set enqcmd to the build system.

From: Hao Xiang <[email protected]>

Enable instruction set enqcmd in build.

---
 meson.build                   | 14 ++++++++++++++
 meson_options.txt             |  2 ++
 scripts/meson-buildoptions.sh |  3 +++
 3 files changed, 19 insertions(+)
meson.build +4 -0
index 6a93da48e1..af650cfabf 100644
@@ -2893,6 +2893,20 @@ config_host_data.set('CONFIG_AVX512BW_OPT',
 get_option('avx512bw') \
     int main(int argc, char *argv[]) { return bar(argv[0]); }
   '''), error_message: 'AVX512BW not available').allowed())
 
+config_host_data.set('CONFIG_DSA_OPT', get_option('enqcmd') \
+  .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot
 enable ENQCMD') \
+  .require(cc.links('''
+    #include <stdint.h>

meson.build config_host_data.set('CONFIG_AVX512BW_OPT', · line 2911

Quoted 10 lines
meson.build +10 -0
+    #include <cpuid.h>
+    #include <immintrin.h>
+    static int __attribute__((target("enqcmd"))) bar(void *a) {
+      uint64_t dst[8] = { 0 };
+      uint64_t src[8] = { 0 };
+      return _enqcmd(dst, src);
+    }
+    int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
+  '''), error_message: 'ENQCMD not available').allowed())
+

How about using cpuid instruction to dynamically detect enqcmd and movdir64b instructions?

My reasons are as follows
1. enqcmd/movdir64b and DSA devices are used together. DSA devices are dynamically detected, so enqcmd can also dynamically detect.

Simple code for dynamically detect movdir64b and enqcmd

   bool check_dsa_instructions(void) {
       uint32_t eax, ebx, ecx, edx;
       bool movedirb_enabled;
       bool enqcmd_enabled;

       cpuid(0x07, 0x0, &eax, &ebx, &ecx, &edx);
       movedirb_enabled = (ecx >> 28) & 0x1;
       if (!movedirb_enabled) {
           return false;
       }
       enqcmd_enabled = (ecx >> 29) & 0x1;
       if (!enqcmd_enabled) {
           return false;
       }
       return true;
    }
    https://cdrdv2-public.intel.com/819680/architecture-instruction-set-extensions-programming-reference.pdf

2. The enqcmd/movdir64b are new instructions, I checked they are integrated into GCC10 However, users do not need gcc10 or higher to use two instructions. Simple code to implement enqcmd
static inline int enqcmd(volatile void *reg, struct dsa_hw_desc *desc)

   {
       uint8_t retry;
       asm volatile (".byte 0xf2, 0x0f, 0x38, 0xf8, 0x02\t\n"
       "setz %0\t\n":"=r" (retry):"a"(reg), "d"(desc));
       return (int)retry;

} file:///C:/Users/yliu80/Downloads/353216-data-streaming-accelerator-user-guide-002.pdf

Quoted 39 lines
meson.build +0 -0
 # For both AArch64 and AArch32, detect if builtins are available.

config_host_data.set('CONFIG_ARM_AES_BUILTIN', cc.compiles('''

     #include <arm_neon.h>
meson_options.txt +2 -0
index 0269fa0f16..4ed820bb8d 100644
@@ -121,6 +121,8 @@ option('avx2', type: 'feature', value: 'auto',
        description: 'AVX2 optimizations')
 option('avx512bw', type: 'feature', value: 'auto',
        description: 'AVX512BW optimizations')
+option('enqcmd', type: 'feature', value: 'disabled',
+       description: 'ENQCMD optimizations')
 option('keyring', type: 'feature', value: 'auto',
        description: 'Linux keyring support')
 option('libkeyutils', type: 'feature', value: 'auto',
scripts/meson-buildoptions.sh +3 -1
index cfadb5ea86..280e117687 100644
@@ -95,6 +95,7 @@ meson_options_help() {
   printf "%s\n" '  auth-pam        PAM access control'
   printf "%s\n" '  avx2            AVX2 optimizations'
   printf "%s\n" '  avx512bw        AVX512BW optimizations'
+  printf "%s\n" '  enqcmd          ENQCMD optimizations'
   printf "%s\n" '  blkio           libblkio block device driver'
   printf "%s\n" '  bochs           bochs image format support'
   printf "%s\n" '  bpf             eBPF support'
@@ -239,6 +240,8 @@ _meson_option_parse() {
     --disable-avx2) printf "%s" -Davx2=disabled ;;
     --enable-avx512bw) printf "%s" -Davx512bw=enabled ;;
     --disable-avx512bw) printf "%s" -Davx512bw=disabled ;;
+    --enable-enqcmd) printf "%s" -Denqcmd=enabled ;;
+    --disable-enqcmd) printf "%s" -Denqcmd=disabled ;;
     --enable-gcov) printf "%s" -Db_coverage=true ;;
     --disable-gcov) printf "%s" -Db_coverage=false ;;
     --enable-lto) printf "%s" -Db_lto=true ;;
--

Yichen Wang

#25 lore raw
In reply to Michael S. Tsirkin
Quoted 188 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 10:43 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 01:09:59PM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 8:24 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau

<[email protected]>;

Quoted 1 line
Quoted 1 line

Daniel P. Berrangé <[email protected]>; Thomas Huth

<[email protected]>;

Quoted 1 line
Quoted 1 line

Philippe Mathieu-Daudé <[email protected]>; Peter Xu

<[email protected]>;

Quoted 1 line
Quoted 1 line

Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>;

Markus

Quoted 1 line
Quoted 1 line

Armbruster <[email protected]>; Cornelia Huck <[email protected]>;

qemu-

Quoted 4 lines
Quoted 4 lines

[email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 9 lines
Quoted 9 lines

zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé

Quoted 4 lines
Quoted 4 lines

<[email protected]>;

Quoted 3 lines
Quoted 3 lines

Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus

Armbruster

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>;

Ho-

Quoted 29 lines
Quoted 29 lines

Ren

Quoted 2 lines
Quoted 2 lines

(Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 25 lines
Quoted 25 lines

zero page checking in multifd live migration.

Quoted 22 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to

Quoted 7 lines
Quoted 7 lines

control

Quoted 6 lines
Quoted 6 lines

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare

with

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to analyze

CPU

Quoted 33 lines
Quoted 33 lines
Quoted 7 lines
Quoted 7 lines

usage.

Quoted 6 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|-------------

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|-------------

--|

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|-------------

--|

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|-------------
Quoted 3 lines
Quoted 3 lines

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Baseline total runtime is calculated by adding up all

multifdsend_X

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and live_migration threads runtime. DSA offloading total runtime

is

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances. The DSA resource used by each process is called a work queue, each

DSA

Quoted 1 line
Quoted 1 line
Quoted 1 line

device can support up to 8 work queues and work queues are

classified

Quoted 4 lines
Quoted 4 lines

into

Quoted 3 lines

dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically, there

is no

Quoted 2 lines
Quoted 2 lines

limit

Quoted 1 line

on the number of processes in a shared queue, it is based on enqcmd

+

Quoted 6 lines
Quoted 6 lines

SVM technology.

Quoted 2 lines

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100 single cpu qemu instances with no issue. What happens if you do this with

DSA?

Quoted 5 lines

First, the DSA work queue needs to be configured in shared mode, and one queue is enough.

The maximum depth of the work queue of the DSA hardware is 128, which

means

Quoted 1 line

that the number of zero-page detection tasks submitted cannot exceed

128,

Quoted 1 line

otherwise, enqcmd will return an error until the work queue is available

again

Quoted 2 lines

100 Qemu instances need to be migrated concurrently, I don't have any

data on

Quoted 1 line

this yet, I think the 100 zero-page detection tasks can be successfully

submitted

Quoted 1 line

to the DSA hardware work queue, but the throughput of DSA's zero-page

detection also

Quoted 8 lines
Quoted 1 line

needs to be considered. Once the DSA maximum throughput is reached, the

work queue

Quoted 1 line

may be filled up quickly, this will cause some Qemu instances to be

temporarily unable

Quoted 1 line

to submit new tasks to DSA.

The unfortunate reality here would be that there's likely no QoS, this is purely fifo, right?

Yes, this scenario may be fifo, assuming that the number of pages each task is the same, because DSA hardware consists of multiple work engines, they can process tasks concurrently, usually in a round-robin way to get tasks from the work queue.

DSA supports priority and flow control based on work queue granularity.
https://github.com/intel/idxd-config/blob/stable/Documentation/accfg/accel-config-config-wq.txt

Quoted 4 lines
Quoted 2 lines

This is likely to happen in the first round of migration memory iteration.

Try testing this and see then?

Yes, I can test based on this patch set. Please review the test scenario My server has 192 CPUs, and 8 DSA devices, 100Gbps NIC.
All 8 DSA devices serve 100 Qemu instances for simultaneous live migration. Each VM has 1 vCPU, and 1G memory, with no workload in the VM.

You want to know if some Qemu instances are stalled because of DSA, right?

Quoted 2 lines

--
MST

#26 lore raw
Quoted 159 lines

-----Original Message-----
From: Liu, Yuan1
Sent: Monday, July 15, 2024 11:23 PM
To: Michael S. Tsirkin <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: RE: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 7 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 10:43 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth

<[email protected]>;

Quoted 1 line

Philippe Mathieu-Daudé <[email protected]>; Peter Xu

<[email protected]>;

Quoted 38 lines

Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 01:09:59PM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 8:24 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau

<[email protected]>;

Quoted 1 line
Quoted 1 line

Daniel P. Berrangé <[email protected]>; Thomas Huth

<[email protected]>;

Quoted 1 line
Quoted 1 line

Philippe Mathieu-Daudé <[email protected]>; Peter Xu

<[email protected]>;

Quoted 1 line
Quoted 1 line

Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>;

Markus

Quoted 1 line
Quoted 1 line

Armbruster <[email protected]>; Cornelia Huck <[email protected]>;

qemu-

Quoted 4 lines
Quoted 4 lines

[email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 9 lines
Quoted 9 lines

zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

<[email protected]>;

Quoted 3 lines
Quoted 3 lines

Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus

Armbruster

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam

<[email protected]>;

Quoted 30 lines

Ho-

Quoted 29 lines
Quoted 29 lines

Ren

Quoted 2 lines
Quoted 2 lines

(Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 25 lines
Quoted 25 lines

zero page checking in multifd live migration.

Quoted 22 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio

to

Quoted 11 lines
Quoted 7 lines
Quoted 7 lines

control

Quoted 6 lines
Quoted 6 lines

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare

with

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to

analyze

Quoted 8 lines

CPU

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

usage.

Quoted 6 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|-------

------

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--|

Quoted 1 line
Quoted 1 line
Quoted 1 line
	|		|comm		|runtime(msec)
	|totaltime(msec)|
> > > > > > 	|---------------|---------------|---------------|-------

------

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

--|

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922
	|
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
	|---------------|---------------|---------------|-------

------

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

--|

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568
	|
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
	|---------------|---------------|---------------|-------

------

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--|

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 21 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Baseline total runtime is calculated by adding up all

multifdsend_X

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and live_migration threads runtime. DSA offloading total

runtime

Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec

runtime

Quoted 13 lines

and

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 1 line

that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

If I understand correctly, you are concerned that in some scenarios the accelerator itself is the migration bottleneck, causing the migration performance to be degraded.

My understanding is to make full use of the accelerator bandwidth, and once the accelerator is the bottleneck, it will fall back to zero-page detection by the CPU.

For example, when the enqcmd command returns an error which means the work queue is full, then we can add some retry mechanisms or directly use CPU detection.

Quoted 79 lines
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

A DSA device can be assigned to multiple Qemu instances. The DSA resource used by each process is called a work queue, each

DSA

Quoted 1 line
Quoted 1 line
Quoted 1 line

device can support up to 8 work queues and work queues are

classified

Quoted 4 lines
Quoted 4 lines

into

Quoted 3 lines

dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically, there

is no

Quoted 2 lines
Quoted 2 lines

limit

Quoted 1 line

on the number of processes in a shared queue, it is based on

enqcmd

Quoted 6 lines

+

Quoted 5 lines
Quoted 5 lines

SVM technology.

Quoted 2 lines

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100

single

Quoted 4 lines
Quoted 1 line
Quoted 1 line

cpu qemu instances with no issue. What happens if you do this with

DSA?

Quoted 2 lines

First, the DSA work queue needs to be configured in shared mode, and

one

Quoted 7 lines
Quoted 3 lines

queue is enough.

The maximum depth of the work queue of the DSA hardware is 128, which

means

Quoted 1 line

that the number of zero-page detection tasks submitted cannot exceed

128,

Quoted 1 line

otherwise, enqcmd will return an error until the work queue is

available

Quoted 5 lines

again

Quoted 2 lines

100 Qemu instances need to be migrated concurrently, I don't have any

data on

Quoted 1 line

this yet, I think the 100 zero-page detection tasks can be

successfully

Quoted 4 lines

submitted

Quoted 1 line

to the DSA hardware work queue, but the throughput of DSA's zero-page

detection also

Quoted 1 line

needs to be considered. Once the DSA maximum throughput is reached,

the

Quoted 7 lines

work queue

Quoted 1 line

may be filled up quickly, this will cause some Qemu instances to be

temporarily unable

Quoted 1 line

to submit new tasks to DSA.

The unfortunate reality here would be that there's likely no QoS, this is purely fifo, right?

Yes, this scenario may be fifo, assuming that the number of pages each task
is the same, because DSA hardware consists of multiple work engines, they can
process tasks concurrently, usually in a round-robin way to get tasks from the
work queue.

DSA supports priority and flow control based on work queue granularity.
https://github.com/intel/idxd-
config/blob/stable/Documentation/accfg/accel-config-config-wq.txt

Quoted 4 lines
Quoted 2 lines

This is likely to happen in the first round of migration memory iteration.

Try testing this and see then?

Yes, I can test based on this patch set. Please review the test scenario My server has 192 CPUs, and 8 DSA devices, 100Gbps NIC.
All 8 DSA devices serve 100 Qemu instances for simultaneous live migration.
Each VM has 1 vCPU, and 1G memory, with no workload in the VM.

You want to know if some Qemu instances are stalled because of DSA, right?

Quoted 2 lines

--
MST

#29 lore raw
In reply to Liu, Yuan1
Quoted 197 lines · On Mon, Jul 15, 2024 at 03:23:13PM +0000, Liu, Yuan1 wrote:
Quoted 188 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 10:43 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 01:09:59PM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 8:24 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau

<[email protected]>;

Quoted 1 line
Quoted 1 line

Daniel P. Berrangé <[email protected]>; Thomas Huth

<[email protected]>;

Quoted 1 line
Quoted 1 line

Philippe Mathieu-Daudé <[email protected]>; Peter Xu

<[email protected]>;

Quoted 1 line
Quoted 1 line

Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>;

Markus

Quoted 1 line
Quoted 1 line

Armbruster <[email protected]>; Cornelia Huck <[email protected]>;

qemu-

Quoted 4 lines
Quoted 4 lines

[email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 9 lines
Quoted 9 lines

zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé

Quoted 4 lines
Quoted 4 lines

<[email protected]>;

Quoted 3 lines
Quoted 3 lines

Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus

Armbruster

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>;

Ho-

Quoted 29 lines
Quoted 29 lines

Ren

Quoted 2 lines
Quoted 2 lines

(Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 25 lines
Quoted 25 lines

zero page checking in multifd live migration.

Quoted 22 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-ratio to

Quoted 7 lines
Quoted 7 lines

control

Quoted 6 lines
Quoted 6 lines

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to compare

with

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to analyze

CPU

Quoted 33 lines
Quoted 33 lines
Quoted 7 lines
Quoted 7 lines

usage.

Quoted 6 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|-------------

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
	|		|comm		|runtime(msec)	|totaltime(msec)|
	|---------------|---------------|---------------|-------------

--|

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922		|
	|---------------|---------------|---------------|-------------

--|

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568		|
	|---------------|---------------|---------------|-------------
Quoted 3 lines
Quoted 3 lines

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Baseline total runtime is calculated by adding up all

multifdsend_X

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and live_migration threads runtime. DSA offloading total runtime

is

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

calculated by adding up all multifdsend_X, live_migration and dsa_completion threads runtime. 41922 msec VS 32568 msec runtime

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances. The DSA resource used by each process is called a work queue, each

DSA

Quoted 1 line
Quoted 1 line
Quoted 1 line

device can support up to 8 work queues and work queues are

classified

Quoted 4 lines
Quoted 4 lines

into

Quoted 3 lines

dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically, there

is no

Quoted 2 lines
Quoted 2 lines

limit

Quoted 1 line

on the number of processes in a shared queue, it is based on enqcmd

+

Quoted 6 lines
Quoted 6 lines

SVM technology.

Quoted 2 lines

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100 single cpu qemu instances with no issue. What happens if you do this with

DSA?

Quoted 5 lines

First, the DSA work queue needs to be configured in shared mode, and one queue is enough.

The maximum depth of the work queue of the DSA hardware is 128, which

means

Quoted 1 line

that the number of zero-page detection tasks submitted cannot exceed

128,

Quoted 1 line

otherwise, enqcmd will return an error until the work queue is available

again

Quoted 2 lines

100 Qemu instances need to be migrated concurrently, I don't have any

data on

Quoted 1 line

this yet, I think the 100 zero-page detection tasks can be successfully

submitted

Quoted 1 line

to the DSA hardware work queue, but the throughput of DSA's zero-page

detection also

Quoted 8 lines
Quoted 1 line

needs to be considered. Once the DSA maximum throughput is reached, the

work queue

Quoted 1 line

may be filled up quickly, this will cause some Qemu instances to be

temporarily unable

Quoted 1 line

to submit new tasks to DSA.

The unfortunate reality here would be that there's likely no QoS, this is purely fifo, right?

Quoted 7 lines

Yes, this scenario may be fifo, assuming that the number of pages each task is the same, because DSA hardware consists of multiple work engines, they can process tasks concurrently, usually in a round-robin way to get tasks from the work queue.

DSA supports priority and flow control based on work queue granularity.
https://github.com/intel/idxd-config/blob/stable/Documentation/accfg/accel-config-config-wq.txt

Right but it seems clear there aren't enough work queues for a typical setup.

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

This is likely to happen in the first round of migration memory iteration.

Try testing this and see then?

Yes, I can test based on this patch set. Please review the test scenario My server has 192 CPUs, and 8 DSA devices, 100Gbps NIC.
All 8 DSA devices serve 100 Qemu instances for simultaneous live migration. Each VM has 1 vCPU, and 1G memory, with no workload in the VM.

You want to know if some Qemu instances are stalled because of DSA, right?

And generally just run same benchmark you did compared to cpu:
worst case and average numbers would be interesting.

Quoted 2 lines
Quoted 2 lines

--
MST

#27 lore raw
In reply to Liu, Yuan1
Quoted 17 lines · On Mon, Jul 15, 2024 at 03:57:42PM +0000, Liu, Yuan1 wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Sounds good but a question: what if several qemu instances are migrated in parallel?

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

If I understand correctly, you are concerned that in some scenarios the accelerator itself is the migration bottleneck, causing the migration performance to be degraded.

Quoted 6 lines

My understanding is to make full use of the accelerator bandwidth, and once the accelerator is the bottleneck, it will fall back to zero-page detection by the CPU.

For example, when the enqcmd command returns an error which means the work queue is full, then we can add some retry mechanisms or directly use CPU detection.

How is it handled in your patch? If you just abort migration unless enqcmd succeeds then would that not be a bug, where loading the system leads to migraton failures?

Signature · 1 line
MST
#30 lore raw
In reply to Michael S. Tsirkin
Quoted 270 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, July 16, 2024 12:09 AM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 03:23:13PM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 10:43 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau

<[email protected]>;

Quoted 1 line
Quoted 1 line

Daniel P. Berrangé <[email protected]>; Thomas Huth

<[email protected]>;

Quoted 1 line
Quoted 1 line

Philippe Mathieu-Daudé <[email protected]>; Peter Xu

<[email protected]>;

Quoted 1 line
Quoted 1 line

Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>;

Markus

Quoted 1 line
Quoted 1 line

Armbruster <[email protected]>; Cornelia Huck <[email protected]>;

qemu-

Quoted 4 lines
Quoted 4 lines

[email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 32 lines
Quoted 32 lines

zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 01:09:59PM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, July 15, 2024 8:24 PM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau

<[email protected]>;

Quoted 1 line
Quoted 1 line

Daniel P. Berrangé <[email protected]>; Thomas Huth

<[email protected]>;

Quoted 1 line
Quoted 1 line

Philippe Mathieu-Daudé <[email protected]>; Peter Xu

<[email protected]>;

Quoted 1 line
Quoted 1 line

Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>;

Markus

Quoted 1 line
Quoted 1 line

Armbruster <[email protected]>; Cornelia Huck <[email protected]>;

qemu-

Quoted 4 lines
Quoted 4 lines

[email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to

offload

Quoted 9 lines
Quoted 9 lines

zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 08:29:03AM +0000, Liu, Yuan1 wrote:
Quoted 6 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Friday, July 12, 2024 6:49 AM
To: Wang, Yichen <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<[email protected]>;

Quoted 2 lines
Quoted 2 lines

Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano

Rosas

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]>; Eric Blake <[email protected]>; Markus

Armbruster

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam

<[email protected]>;

Quoted 4 lines
Quoted 4 lines

Ho-

Quoted 3 lines
Quoted 3 lines

Ren

Quoted 2 lines
Quoted 2 lines

(Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator

to

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

offload

Quoted 22 lines
Quoted 22 lines

zero page checking in multifd live migration.

Quoted 19 lines · Yichen Wang

* Performance:

We use two Intel 4th generation Xeon servers for testing.

Architecture:        x86_64
CPU(s):              192
Thread(s) per core:  2
Core(s) per socket:  48
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               143
Model name:          Intel(R) Xeon(R) Platinum 8457C
Stepping:            8
CPU MHz:             2538.624
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

We perform multifd live migration with below setup:
1. VM has 100GB memory.
2. Use the new migration option multifd-set-normal-page-

ratio to

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

control

Quoted 6 lines
Quoted 6 lines

the total

Quoted 5 lines

size of the payload sent over the network.
3. Use 8 multifd channels.
4. Use tcp for live migration.
4. Use CPU to perform zero page checking as the baseline.
5. Use one DSA device to offload zero page checking to

compare

Quoted 4 lines
Quoted 4 lines

with

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines

baseline.

Quoted 1 line

6. Use "perf sched record" and "perf sched timehist" to

analyze

Quoted 8 lines
Quoted 8 lines

CPU

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

usage.

Quoted 6 lines

A) Scenario 1: 50% (50GB) normal pages on an 100GB vm.

	CPU usage

	|---------------|---------------|---------------|-------

------

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--|

Quoted 1 line
Quoted 1 line
Quoted 1 line
	|		|comm		|runtime(msec)
	|totaltime(msec)|
> > > > > > > 	|---------------|---------------|---------------|-------

------

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

--|

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
	|Baseline	|live_migration	|5657.58	|		|
	|		|multifdsend_0	|3931.563	|		|
	|		|multifdsend_1	|4405.273	|		|
	|		|multifdsend_2	|3941.968	|		|
	|		|multifdsend_3	|5032.975	|		|
	|		|multifdsend_4	|4533.865	|		|
	|		|multifdsend_5	|4530.461	|		|
	|		|multifdsend_6	|5171.916	|		|
	|		|multifdsend_7	|4722.769	|41922
	|
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
	|---------------|---------------|---------------|-------

------

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

--|

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	|DSA		|live_migration	|6129.168	|		|
	|		|multifdsend_0	|2954.717	|		|
	|		|multifdsend_1	|2766.359	|		|
	|		|multifdsend_2	|2853.519	|		|
	|		|multifdsend_3	|2740.717	|		|
	|		|multifdsend_4	|2824.169	|		|
	|		|multifdsend_5	|2966.908	|		|
	|		|multifdsend_6	|2611.137	|		|
	|		|multifdsend_7	|3114.732	|		|
	|		|dsa_completion	|3612.564	|32568
	|
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
	|---------------|---------------|---------------|-------

------

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

--|

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Baseline total runtime is calculated by adding up all

multifdsend_X

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and live_migration threads runtime. DSA offloading total

runtime

Quoted 2 lines
Quoted 2 lines

is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

calculated by adding up all multifdsend_X, live_migration

and

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

dsa_completion threads runtime. 41922 msec VS 32568 msec

runtime

Quoted 9 lines
Quoted 9 lines

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances are migrated in parallel?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

A DSA device can be assigned to multiple Qemu instances. The DSA resource used by each process is called a work queue,

each

Quoted 7 lines
Quoted 7 lines

DSA

Quoted 1 line
Quoted 1 line
Quoted 1 line

device can support up to 8 work queues and work queues are

classified

Quoted 4 lines
Quoted 4 lines

into

Quoted 3 lines

dedicated queues and shared queues.

A dedicated queue can only serve one process. Theoretically,

there

Quoted 3 lines
Quoted 3 lines

is no

Quoted 2 lines
Quoted 2 lines

limit

Quoted 1 line

on the number of processes in a shared queue, it is based on

enqcmd

Quoted 6 lines
Quoted 6 lines

+

Quoted 5 lines
Quoted 5 lines

SVM technology.

Quoted 2 lines

https://www.kernel.org/doc/html/v5.17/x86/sva.html

This server has 200 CPUs which can thinkably migrate around 100

single

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

cpu qemu instances with no issue. What happens if you do this with

DSA?

Quoted 2 lines

First, the DSA work queue needs to be configured in shared mode, and

one

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

queue is enough.

The maximum depth of the work queue of the DSA hardware is 128,

which

Quoted 4 lines
Quoted 4 lines

means

Quoted 1 line

that the number of zero-page detection tasks submitted cannot exceed

128,

Quoted 1 line

otherwise, enqcmd will return an error until the work queue is

available

Quoted 3 lines
Quoted 3 lines

again

Quoted 2 lines

100 Qemu instances need to be migrated concurrently, I don't have

any

Quoted 2 lines
Quoted 2 lines

data on

Quoted 1 line

this yet, I think the 100 zero-page detection tasks can be

successfully

Quoted 2 lines
Quoted 2 lines

submitted

Quoted 1 line

to the DSA hardware work queue, but the throughput of DSA's zero-

page

Quoted 2 lines
Quoted 2 lines

detection also

Quoted 1 line

needs to be considered. Once the DSA maximum throughput is reached,

the

Quoted 9 lines
Quoted 7 lines

work queue

Quoted 1 line

may be filled up quickly, this will cause some Qemu instances to be

temporarily unable

Quoted 1 line

to submit new tasks to DSA.

The unfortunate reality here would be that there's likely no QoS, this is purely fifo, right?

Yes, this scenario may be fifo, assuming that the number of pages each

task

Quoted 1 line

is the same, because DSA hardware consists of multiple work engines,

they can

Quoted 1 line

process tasks concurrently, usually in a round-robin way to get tasks

from the

Quoted 4 lines

work queue.

DSA supports priority and flow control based on work queue granularity.
https://github.com/intel/idxd-

config/blob/stable/Documentation/accfg/accel-config-config-wq.txt

Right but it seems clear there aren't enough work queues for a typical setup.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This is likely to happen in the first round of migration memory iteration.

Try testing this and see then?

Yes, I can test based on this patch set. Please review the test scenario My server has 192 CPUs, and 8 DSA devices, 100Gbps NIC.
All 8 DSA devices serve 100 Qemu instances for simultaneous live

Quoted 8 lines

migration.

Quoted 3 lines

Each VM has 1 vCPU, and 1G memory, with no workload in the VM.

You want to know if some Qemu instances are stalled because of DSA,

right?

And generally just run same benchmark you did compared to cpu:
worst case and average numbers would be interesting.

Sure, I will have a test for this.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--
MST

#28 lore raw
In reply to Michael S. Tsirkin
Quoted 43 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, July 16, 2024 12:24 AM
To: Liu, Yuan1 <[email protected]>
Cc: Wang, Yichen <[email protected]>; Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Cornelia Huck <[email protected]>; qemu- [email protected]; Hao Xiang <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>
Subject: Re: [PATCH v5 00/13] WIP: Use Intel DSA accelerator to offload zero page checking in multifd live migration.

Quoted 6 lines · On Mon, Jul 15, 2024 at 03:57:42PM +0000, Liu, Yuan1 wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

that is 23% total CPU usage savings.

Here the DSA was mostly idle.

Sounds good but a question: what if several qemu instances

are

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

migrated in parallel?

Some accelerators tend to basically stall if several tasks are trying to use them at the same time.

Where is the boundary here?

If I understand correctly, you are concerned that in some scenarios the accelerator itself is the migration bottleneck, causing the migration

performance

Quoted 3 lines

to be degraded.

My understanding is to make full use of the accelerator bandwidth, and

once

Quoted 1 line

the accelerator is the bottleneck, it will fall back to zero-page

detection

Quoted 3 lines

by the CPU.

For example, when the enqcmd command returns an error which means the

Quoted 8 lines

work queue

Quoted 1 line

is full, then we can add some retry mechanisms or directly use CPU

detection.

How is it handled in your patch? If you just abort migration unless enqcmd succeeds then would that not be a bug, where loading the system leads to migraton failures?

Sorry for this, I have just started reviewing this patch. The content we discussed before is only related to the DSA device itself and may not be related to this patch's implementation. I will review the issue you mentioned carefully. Thank you for your reminder.

Quoted 2 lines

--
MST

#32 lore raw
In reply to Yichen Wang
Quoted 6 lines · Yichen Wang

v5
* Rebase on top of 39a032cea23e522268519d89bb738974bc43b6f6.
* Rename struct definitions with typedef and CamelCase names;
* Add build and runtime checks about DSA accelerator;
* Address all comments from v4 reviews about typos, licenses, comments, error reporting, etc.

Hi,

You forgot to make sure the patches compile without DSA support as well! =)

Also, please be more explicit on the state of the series, the WIP on the title is not enough. You can send the whole series as RFC (e.g. PATCH RFC v5) if it's not ready to merge, or put the RFC tag only on the patches you need help with. But make sure you have some words in the cover-letter stating what is going on.

Another point is, I see you have applied some suggestions from the previous version, but did those on top of the existing code in some cases. Try to avoid that and please fix it for the next version. That is, don't add code in one patch just to remove it on the next, try to apply the changes/suggestions on the patch that introduces the code, as much as possible.

#12 lore raw

Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Yichen Wang
Quoted 12 lines · Yichen Wang
Quoted 10 lines · Yichen Wang
migration/options.c +1 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
Quoted 8 lines

migration/options.c Property migration_properties[] = { · line 167

Quoted 8 lines
migration/options.c +2 -0
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */

This is mostly correct, I think, you just need to create a field in MigrationState to keep the length (instead of x). However, I found out just now that this only works with QMP. Let me ask for other's opinions...

Quoted 15 lines

migration/options.c Property migration_properties[] = { · line 172

Quoted 5 lines
migration/options.c +2 -0
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),

I changed the dsa-accel-path to be a ['str'], i.e. strList* in C. However, I am having a hard time about how to define the proper properties here. I don't know what MACRO to use and I can't find good examples... Need some guidance about how to proceed. Basically I will need this to pass something like '-global migration.dsa-accel-path="/dev/dsa/wq0.0"' in cmdline, or "migrate_set_parameter dsa-accel-path" in QEMU CLI. Don't know how to pass strList there.

Quoted 1 line

Thanks very much!

@Daniel, @Markus, any idea here?

If I'm reading this commit[1] right, it seems we decided to disallow passing of arrays without JSON, which affects -global on the command-line and HMP.

1- b06f8b500d (qdev: Rework array properties based on list visitor, 2023-11-09)

QMP shell:
(QEMU) migrate-set-parameters dsa-accel-path=['a','b'] {"return": {}}

HMP:
(qemu) migrate_set_parameter dsa-accel-path "['a','b']"
qemu-system-x86_64: ../qapi/string-input-visitor.c:343: parse_type_str:
Assertion `siv->lm == LM_NONE' failed.

Any recommendation? I believe all migration parameters so far can be set via those means, I don't think we can allow only this one to be QMP-only.

Or am I just missing something?

#17 lore raw

Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Yichen Wang
Quoted 109 lines · Yichen Wang

From: Hao Xiang <[email protected]>

Intel DSA offloading is an optional feature that turns on if proper hardware and software stack is available. To turn on DSA offloading in multifd live migration:

dsa-accel-path="[dsa_dev_path1] [dsa_dev_path2] ... [dsa_dev_pathX]"

This feature is turned off by default.

---
 migration/migration-hmp-cmds.c | 15 ++++++++++-
 migration/options.c            | 47 ++++++++++++++++++++++++++++++++++
 migration/options.h            |  1 +
 qapi/migration.json            | 32 ++++++++++++++++++++---
 4 files changed, 90 insertions(+), 5 deletions(-)
migration/migration-hmp-cmds.c +14 -1
index 7d608d26e1..c422db4ecd 100644
@@ -312,7 +312,16 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
             params->tls_authz);
-
+        if (params->has_dsa_accel_path) {
+            strList *dsa_accel_path = params->dsa_accel_path;
+            monitor_printf(mon, "%s:",
+                MigrationParameter_str(MIGRATION_PARAMETER_DSA_ACCEL_PATH));
+            while (dsa_accel_path) {
+                monitor_printf(mon, " %s", dsa_accel_path->value);
+                dsa_accel_path = dsa_accel_path->next;
+            }
+            monitor_printf(mon, "\n");
+        }
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;
 
@@ -563,6 +572,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
         p->has_x_checkpoint_delay = true;
         visit_type_uint32(v, param, &p->x_checkpoint_delay, &err);
         break;
+    case MIGRATION_PARAMETER_DSA_ACCEL_PATH:
+        p->has_dsa_accel_path = true;
+        visit_type_strList(v, param, &p->dsa_accel_path, &err);
+        break;
     case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
         p->has_multifd_channels = true;
         visit_type_uint8(v, param, &p->multifd_channels, &err);
migration/options.c +14 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
@@ -815,6 +820,13 @@ const char *migrate_tls_creds(void)
     return s->parameters.tls_creds;
 }
 
+const strList *migrate_dsa_accel_path(void)
+{
+    MigrationState *s = migrate_get_current();
+
+    return s->parameters.dsa_accel_path;
+}
+
 const char *migrate_tls_hostname(void)
 {
     MigrationState *s = migrate_get_current();
@@ -926,6 +938,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->zero_page_detection = s->parameters.zero_page_detection;
     params->has_direct_io = true;
     params->direct_io = s->parameters.direct_io;
+    params->dsa_accel_path = QAPI_CLONE(strList, s->parameters.dsa_accel_path);
 
     return params;
 }
@@ -934,6 +947,7 @@ void migrate_params_init(MigrationParameters *params)
 {
     params->tls_hostname = g_strdup("");
     params->tls_creds = g_strdup("");
+    params->dsa_accel_path = NULL;
 
     /* Set has_* up only for parameter checks */
     params->has_throttle_trigger_threshold = true;
@@ -1137,6 +1151,22 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
         return false;
     }
 

migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1163

Quoted 10 lines
migration/options.c +10 -0
+    if (params->has_zero_page_detection &&
+        params->zero_page_detection == ZERO_PAGE_DETECTION_DSA_ACCEL) {
+#ifdef CONFIG_DSA_OPT
+        unsigned int eax, ebx, ecx, edx;
+        /* ENQCMD is indicated by bit 29 of ecx in CPUID leaf 7, subleaf 0. */
+        if (!__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx) ||
+            !(ecx & (1 << 29))) {
+            error_setg(errp, "DSA acceleration is not supported by CPU");
+            return false;
+        }

This should be a function along with the others in dsa.h, then you wouldn't need the ifdef here.

Quoted 147 lines
migration/options.c +23 -0
+#else
+        error_setg(errp, "DSA acceleration is not enabled");
+        return false;
+#endif
+    }
+
     return true;
 }
 
@@ -1247,6 +1277,11 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     if (params->has_direct_io) {
         dest->direct_io = params->direct_io;
     }
+
+    if (params->has_dsa_accel_path) {
+        dest->has_dsa_accel_path = true;
+        dest->dsa_accel_path = params->dsa_accel_path;
+    }
 }
 
 static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
@@ -1376,6 +1411,12 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     if (params->has_direct_io) {
         s->parameters.direct_io = params->direct_io;
     }
+    if (params->has_dsa_accel_path) {
+        qapi_free_strList(s->parameters.dsa_accel_path);
+        s->parameters.has_dsa_accel_path = true;
+        s->parameters.dsa_accel_path =
+            QAPI_CLONE(strList, params->dsa_accel_path);
+    }
 }
 
 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
@@ -1401,6 +1442,12 @@ void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
         params->tls_authz->type = QTYPE_QSTRING;
         params->tls_authz->u.s = strdup("");
     }
+    /* if (params->dsa_accel_path */
+    /*     && params->dsa_accel_path->type == QTYPE_QNULL) { */
+    /*     qobject_unref(params->dsa_accel_path->u.n); */
+    /*     params->dsa_accel_path->type = QTYPE_QLIST; */
+    /*     params->dsa_accel_path->u.s = strdup(""); */
+    /* } */
 
     migrate_params_test_apply(params, &tmp);
 
migration/options.h +1 -0
index a2397026db..78b9e4080b 100644
@@ -85,6 +85,7 @@ const char *migrate_tls_creds(void);
 const char *migrate_tls_hostname(void);
 uint64_t migrate_xbzrle_cache_size(void);
 ZeroPageDetection migrate_zero_page_detection(void);
+const strList *migrate_dsa_accel_path(void);
 
 /* parameters helpers */
 
qapi/migration.json +28 -4
index 1234bef888..ff41780347 100644
@@ -619,10 +619,14 @@
 #     multifd migration is enabled, else in the main migration thread
 #     as for @legacy.
 #
+# @dsa-accel: Perform zero page checking with the DSA accelerator
+#     offloading in multifd sender thread if multifd migration is
+#     enabled, else in the main migration thread as for @legacy.
+#
 # Since: 9.0
 ##
 { 'enum': 'ZeroPageDetection',
-  'data': [ 'none', 'legacy', 'multifd' ] }
+  'data': [ 'none', 'legacy', 'multifd', 'dsa-accel' ] }
 
 ##
 # @BitmapMigrationBitmapAliasTransform:
@@ -825,6 +829,12 @@
 #     See description in @ZeroPageDetection.  Default is 'multifd'.
 #     (since 9.0)
 #
+# @dsa-accel-path: If enabled, use DSA accelerator offloading for
+#     certain memory operations. Enable DSA accelerator for zero
+#     page detection offloading by setting the @zero-page-detection
+#     to dsa-accel. This parameter defines the dsa device path, and
+#     defaults to an empty list. (since 9.2)
+#
 # @direct-io: Open migration files with O_DIRECT when possible.  This
 #     only has effect if the @mapped-ram capability is enabled.
 #     (Since 9.1)
@@ -843,7 +853,7 @@
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'cpu-throttle-tailslow',
            'tls-creds', 'tls-hostname', 'tls-authz', 'max-bandwidth',
-           'avail-switchover-bandwidth', 'downtime-limit',
+           'avail-switchover-bandwidth', 'downtime-limit', 'dsa-accel-path',
            { 'name': 'x-checkpoint-delay', 'features': [ 'unstable' ] },
            'multifd-channels',
            'xbzrle-cache-size', 'max-postcopy-bandwidth',
@@ -1000,6 +1010,12 @@
 #     See description in @ZeroPageDetection.  Default is 'multifd'.
 #     (since 9.0)
 #
+# @dsa-accel-path: If enabled, use DSA accelerator offloading for
+#     certain memory operations. Enable DSA accelerator for zero
+#     page detection offloading by setting the @zero-page-detection
+#     to dsa-accel. This parameter defines the dsa device path, and
+#     defaults to an empty list. (since 9.2)
+#
 # @direct-io: Open migration files with O_DIRECT when possible.  This
 #     only has effect if the @mapped-ram capability is enabled.
 #     (Since 9.1)
@@ -1044,7 +1060,8 @@
             '*vcpu-dirty-limit': 'uint64',
             '*mode': 'MigMode',
             '*zero-page-detection': 'ZeroPageDetection',
-            '*direct-io': 'bool' } }
+            '*direct-io': 'bool',
+            '*dsa-accel-path': ['str'] } }
 
 ##
 # @migrate-set-parameters:
@@ -1204,6 +1221,12 @@
 #     See description in @ZeroPageDetection.  Default is 'multifd'.
 #     (since 9.0)
 #
+# @dsa-accel-path: If enabled, use DSA accelerator offloading for
+#     certain memory operations. Enable DSA accelerator for zero
+#     page detection offloading by setting the @zero-page-detection
+#     to dsa-accel. This parameter defines the dsa device path, and
+#     defaults to an empty list. (since 9.2)
+#
 # @direct-io: Open migration files with O_DIRECT when possible.  This
 #     only has effect if the @mapped-ram capability is enabled.
 #     (Since 9.1)
@@ -1245,7 +1268,8 @@
             '*vcpu-dirty-limit': 'uint64',
             '*mode': 'MigMode',
             '*zero-page-detection': 'ZeroPageDetection',
-            '*direct-io': 'bool' } }
+            '*direct-io': 'bool',
+            '*dsa-accel-path': ['str'] } }
 
 ##
 # @query-migrate-parameters:
#19 lore raw

Re: [PATCH v5 09/13] migration/multifd: Prepare to introduce DSA acceleration on the multifd path.

In reply to Yichen Wang
Quoted 4 lines · Yichen Wang

From: Hao Xiang <[email protected]>

1. Refactor multifd_send_thread function.
2. Introduce the batch task structure in MultiFDSendParams.

This patch needs to be restructured, maybe even go away. Most of it has to be where these structures were introduced for the first time and any multifd parts have to go into another patch that touches only multifd code.

#13 lore raw

Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Fabiano Rosas
Quoted 63 lines · Fabiano Rosas
Quoted 12 lines · Yichen Wang
Quoted 10 lines · Yichen Wang
migration/options.c +1 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
Quoted 8 lines

migration/options.c Property migration_properties[] = { · line 167

Quoted 8 lines
migration/options.c +2 -0
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */

This is mostly correct, I think, you just need to create a field in MigrationState to keep the length (instead of x). However, I found out just now that this only works with QMP. Let me ask for other's opinions...

Quoted 15 lines

migration/options.c Property migration_properties[] = { · line 172

Quoted 5 lines
migration/options.c +2 -0
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),

I changed the dsa-accel-path to be a ['str'], i.e. strList* in C. However, I am having a hard time about how to define the proper properties here. I don't know what MACRO to use and I can't find good examples... Need some guidance about how to proceed. Basically I will need this to pass something like '-global migration.dsa-accel-path="/dev/dsa/wq0.0"' in cmdline, or "migrate_set_parameter dsa-accel-path" in QEMU CLI. Don't know how to pass strList there.

Quoted 1 line

Thanks very much!

@Daniel, @Markus, any idea here?

If I'm reading this commit[1] right, it seems we decided to disallow passing of arrays without JSON, which affects -global on the command-line and HMP.

1- b06f8b500d (qdev: Rework array properties based on list visitor, 2023-11-09)

QMP shell:
(QEMU) migrate-set-parameters dsa-accel-path=['a','b'] {"return": {}}

HMP:
(qemu) migrate_set_parameter dsa-accel-path "['a','b']"
qemu-system-x86_64: ../qapi/string-input-visitor.c:343: parse_type_str:
Assertion `siv->lm == LM_NONE' failed.

Quoted 5 lines

Any recommendation? I believe all migration parameters so far can be set via those means, I don't think we can allow only this one to be QMP-only.

Or am I just missing something?

I guess we could just skip adding property like Steve did here:

https://lore.kernel.org/r/[email protected]

#14 lore raw

Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Fabiano Rosas
Quoted 54 lines · Fabiano Rosas
Quoted 12 lines · Yichen Wang
Quoted 10 lines · Yichen Wang
migration/options.c +1 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
Quoted 8 lines

migration/options.c Property migration_properties[] = { · line 167

Quoted 8 lines
migration/options.c +2 -0
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */

This is mostly correct, I think, you just need to create a field in MigrationState to keep the length (instead of x). However, I found out just now that this only works with QMP. Let me ask for other's opinions...

Quoted 15 lines

migration/options.c Property migration_properties[] = { · line 172

Quoted 5 lines
migration/options.c +2 -0
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),

I changed the dsa-accel-path to be a ['str'], i.e. strList* in C. However, I am having a hard time about how to define the proper properties here. I don't know what MACRO to use and I can't find good examples... Need some guidance about how to proceed. Basically I will need this to pass something like '-global migration.dsa-accel-path="/dev/dsa/wq0.0"' in cmdline, or "migrate_set_parameter dsa-accel-path" in QEMU CLI. Don't know how to pass strList there.

Quoted 1 line

Thanks very much!

@Daniel, @Markus, any idea here?

If I'm reading this commit[1] right, it seems we decided to disallow passing of arrays without JSON, which affects -global on the command-line and HMP.

1- b06f8b500d (qdev: Rework array properties based on list visitor, 2023-11-09)

Quoted 8 lines

QMP shell:
(QEMU) migrate-set-parameters dsa-accel-path=['a','b'] {"return": {}}

HMP:
(qemu) migrate_set_parameter dsa-accel-path "['a','b']"
qemu-system-x86_64: ../qapi/string-input-visitor.c:343: parse_type_str:
Assertion `siv->lm == LM_NONE' failed.

HMP migrate_set_parameter doesn't support JSON. It uses the string input visitor to parse the value, which can only do lists of integers.

The string visitors have been thorns in my side since forever.

Quoted 5 lines

Any recommendation? I believe all migration parameters so far can be set via those means, I don't think we can allow only this one to be QMP-only.

Or am I just missing something?

I don't think the string input visitor can be compatibly extended to arbitrary lists.

We could replace HMP migrate_set_parameter by migrate_set_parameters. The new command parses its single argument into a struct MigrateSetParameters with keyval_parse(), qobject_input_visitor_new_keyval(), and visit_type_MigrateSetParameters().

#15 lore raw

Re: [External] Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

Quoted 77 lines · Markus Armbruster
Quoted 54 lines · Fabiano Rosas
Quoted 12 lines · Yichen Wang
Quoted 10 lines · Yichen Wang
migration/options.c +1 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
Quoted 8 lines

migration/options.c Property migration_properties[] = { · line 167

Quoted 8 lines
migration/options.c +2 -0
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */

This is mostly correct, I think, you just need to create a field in MigrationState to keep the length (instead of x). However, I found out just now that this only works with QMP. Let me ask for other's opinions...

Quoted 15 lines

migration/options.c Property migration_properties[] = { · line 172

Quoted 5 lines
migration/options.c +2 -0
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),

I changed the dsa-accel-path to be a ['str'], i.e. strList* in C. However, I am having a hard time about how to define the proper properties here. I don't know what MACRO to use and I can't find good examples... Need some guidance about how to proceed. Basically I will need this to pass something like '-global migration.dsa-accel-path="/dev/dsa/wq0.0"' in cmdline, or "migrate_set_parameter dsa-accel-path" in QEMU CLI. Don't know how to pass strList there.

Quoted 1 line

Thanks very much!

@Daniel, @Markus, any idea here?

If I'm reading this commit[1] right, it seems we decided to disallow passing of arrays without JSON, which affects -global on the command-line and HMP.

1- b06f8b500d (qdev: Rework array properties based on list visitor, 2023-11-09)

Quoted 8 lines

QMP shell:
(QEMU) migrate-set-parameters dsa-accel-path=['a','b'] {"return": {}}

HMP:
(qemu) migrate_set_parameter dsa-accel-path "['a','b']"
qemu-system-x86_64: ../qapi/string-input-visitor.c:343: parse_type_str:
Assertion `siv->lm == LM_NONE' failed.

HMP migrate_set_parameter doesn't support JSON. It uses the string input visitor to parse the value, which can only do lists of integers.

The string visitors have been thorns in my side since forever.

Quoted 5 lines

Any recommendation? I believe all migration parameters so far can be set via those means, I don't think we can allow only this one to be QMP-only.

Or am I just missing something?

Quoted 9 lines

I don't think the string input visitor can be compatibly extended to arbitrary lists.

We could replace HMP migrate_set_parameter by migrate_set_parameters. The new command parses its single argument into a struct MigrateSetParameters with keyval_parse(), qobject_input_visitor_new_keyval(), and visit_type_MigrateSetParameters().

I tried Fabiano's suggestion, and put a unit32_t in MigrateState data structure. I got exactly the same: "qemu-system-x86_64.dsa:
../../../qapi/string-input-visitor.c:343: parse_type_str: Assertion `siv->lm == LM_NONE' failed.". Steve's patch is more to be a read-only field from HMP, so probably I can't do that. Markus's suggestion seems to be too heavy for the patch and I took a quick glance and it doesn't seem to be easy to do.

So should we revert to the old "str" format instead of strList? Or how should I proceed here?

#3 lore raw

Re: [External] RE: [PATCH v5 01/13] meson: Introduce new instruction set enqcmd to the build system.

In reply to Liu, Yuan1
Quoted 84 lines · On Mon, Jul 15, 2024 at 8:02 AM Liu, Yuan1 <[email protected]> wrote:
Quoted 43 lines

-----Original Message-----
From: Yichen Wang <[email protected]>
Sent: Friday, July 12, 2024 5:53 AM
To: Paolo Bonzini <[email protected]>; Marc-André Lureau <[email protected]>; Daniel P. Berrangé <[email protected]>; Thomas Huth <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Michael S. Tsirkin <[email protected]>; Cornelia Huck <[email protected]>; [email protected]
Cc: Hao Xiang <[email protected]>; Liu, Yuan1 <[email protected]>; Kumar, Shivam <[email protected]>; Ho-Ren (Jack) Chuang <[email protected]>; Wang, Yichen <[email protected]>
Subject: [PATCH v5 01/13] meson: Introduce new instruction set enqcmd to the build system.

From: Hao Xiang <[email protected]>

Enable instruction set enqcmd in build.

---
 meson.build                   | 14 ++++++++++++++
 meson_options.txt             |  2 ++
 scripts/meson-buildoptions.sh |  3 +++
 3 files changed, 19 insertions(+)
meson.build +4 -0
index 6a93da48e1..af650cfabf 100644
@@ -2893,6 +2893,20 @@ config_host_data.set('CONFIG_AVX512BW_OPT',
 get_option('avx512bw') \
     int main(int argc, char *argv[]) { return bar(argv[0]); }
   '''), error_message: 'AVX512BW not available').allowed())
 
+config_host_data.set('CONFIG_DSA_OPT', get_option('enqcmd') \
+  .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot
 enable ENQCMD') \
+  .require(cc.links('''
+    #include <stdint.h>

meson.build config_host_data.set('CONFIG_AVX512BW_OPT', · line 2911

Quoted 10 lines
meson.build +10 -0
+    #include <cpuid.h>
+    #include <immintrin.h>
+    static int __attribute__((target("enqcmd"))) bar(void *a) {
+      uint64_t dst[8] = { 0 };
+      uint64_t src[8] = { 0 };
+      return _enqcmd(dst, src);
+    }
+    int main(int argc, char *argv[]) { return bar(argv[argc - 1]); }
+  '''), error_message: 'ENQCMD not available').allowed())
+

How about using cpuid instruction to dynamically detect enqcmd and movdir64b instructions?

My reasons are as follows
1. enqcmd/movdir64b and DSA devices are used together. DSA devices are dynamically detected, so enqcmd can also dynamically detect.

   Simple code for dynamically detect movdir64b and enqcmd
   bool check_dsa_instructions(void) {
       uint32_t eax, ebx, ecx, edx;
       bool movedirb_enabled;
       bool enqcmd_enabled;

       cpuid(0x07, 0x0, &eax, &ebx, &ecx, &edx);
       movedirb_enabled = (ecx >> 28) & 0x1;
       if (!movedirb_enabled) {
           return false;
       }
       enqcmd_enabled = (ecx >> 29) & 0x1;
       if (!enqcmd_enabled) {
           return false;
       }
       return true;
    }
    https://cdrdv2-public.intel.com/819680/architecture-instruction-set-extensions-programming-reference.pdf

2. The enqcmd/movdir64b are new instructions, I checked they are integrated into GCC10 However, users do not need gcc10 or higher to use two instructions. Simple code to implement enqcmd
static inline int enqcmd(volatile void *reg, struct dsa_hw_desc *desc)

Quoted 8 lines
   {
       uint8_t retry;
       asm volatile (".byte 0xf2, 0x0f, 0x38, 0xf8, 0x02\t\n"
       "setz %0\t\n":"=r" (retry):"a"(reg), "d"(desc));
       return (int)retry;

} file:///C:/Users/yliu80/Downloads/353216-data-streaming-accelerator-user-guide-002.pdf

This is for compile time detection. So if I am understanding correctly, we don't need this dynamic detection at meson build time, am I right? I actually already have similar code in dynamic detection at runtime, and I will refine that part with your suggestion above.

Quoted 40 lines
Quoted 39 lines
meson.build +0 -0
 # For both AArch64 and AArch32, detect if builtins are available.

config_host_data.set('CONFIG_ARM_AES_BUILTIN', cc.compiles('''

     #include <arm_neon.h>
meson_options.txt +2 -0
index 0269fa0f16..4ed820bb8d 100644
@@ -121,6 +121,8 @@ option('avx2', type: 'feature', value: 'auto',
        description: 'AVX2 optimizations')
 option('avx512bw', type: 'feature', value: 'auto',
        description: 'AVX512BW optimizations')
+option('enqcmd', type: 'feature', value: 'disabled',
+       description: 'ENQCMD optimizations')
 option('keyring', type: 'feature', value: 'auto',
        description: 'Linux keyring support')
 option('libkeyutils', type: 'feature', value: 'auto',
scripts/meson-buildoptions.sh +3 -1
index cfadb5ea86..280e117687 100644
@@ -95,6 +95,7 @@ meson_options_help() {
   printf "%s\n" '  auth-pam        PAM access control'
   printf "%s\n" '  avx2            AVX2 optimizations'
   printf "%s\n" '  avx512bw        AVX512BW optimizations'
+  printf "%s\n" '  enqcmd          ENQCMD optimizations'
   printf "%s\n" '  blkio           libblkio block device driver'
   printf "%s\n" '  bochs           bochs image format support'
   printf "%s\n" '  bpf             eBPF support'
@@ -239,6 +240,8 @@ _meson_option_parse() {
     --disable-avx2) printf "%s" -Davx2=disabled ;;
     --enable-avx512bw) printf "%s" -Davx512bw=enabled ;;
     --disable-avx512bw) printf "%s" -Davx512bw=disabled ;;
+    --enable-enqcmd) printf "%s" -Denqcmd=enabled ;;
+    --disable-enqcmd) printf "%s" -Denqcmd=disabled ;;
     --enable-gcov) printf "%s" -Db_coverage=true ;;
     --disable-gcov) printf "%s" -Db_coverage=false ;;
     --enable-lto) printf "%s" -Db_lto=true ;;
--

Yichen Wang

#16 lore raw

Re: [External] Re: [PATCH v5 08/13] migration/multifd: Add new migration option for multifd DSA offloading.

In reply to Yichen Wang
Quoted 88 lines · Yichen Wang
Quoted 77 lines · Markus Armbruster
Quoted 54 lines · Fabiano Rosas
Quoted 12 lines · Yichen Wang
Quoted 10 lines · Yichen Wang
migration/options.c +1 -0
index 645f55003d..f839493016 100644
@@ -29,6 +29,7 @@
 #include "ram.h"
 #include "options.h"
 #include "sysemu/kvm.h"
+#include <cpuid.h>
 
Quoted 8 lines

migration/options.c Property migration_properties[] = { · line 167

Quoted 8 lines
migration/options.c +2 -0
 /* Maximum migrate downtime set to 2000 seconds */
 #define MAX_MIGRATE_DOWNTIME_SECONDS 2000
@@ -162,6 +163,10 @@ Property migration_properties[] = {
     DEFINE_PROP_ZERO_PAGE_DETECTION("zero-page-detection", MigrationState,
                        parameters.zero_page_detection,
                        ZERO_PAGE_DETECTION_MULTIFD),
+    /* DEFINE_PROP_ARRAY("dsa-accel-path", MigrationState, x, */
+    /*                    parameters.dsa_accel_path, qdev_prop_string, char *), */

This is mostly correct, I think, you just need to create a field in MigrationState to keep the length (instead of x). However, I found out just now that this only works with QMP. Let me ask for other's opinions...

Quoted 15 lines

migration/options.c Property migration_properties[] = { · line 172

Quoted 5 lines
migration/options.c +2 -0
+    /* DEFINE_PROP_STRING("dsa-accel-path", MigrationState, */
+    /*                    parameters.dsa_accel_path), */
 
     /* Migration capabilities */
     DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),

I changed the dsa-accel-path to be a ['str'], i.e. strList* in C. However, I am having a hard time about how to define the proper properties here. I don't know what MACRO to use and I can't find good examples... Need some guidance about how to proceed. Basically I will need this to pass something like '-global migration.dsa-accel-path="/dev/dsa/wq0.0"' in cmdline, or "migrate_set_parameter dsa-accel-path" in QEMU CLI. Don't know how to pass strList there.

Quoted 1 line

Thanks very much!

@Daniel, @Markus, any idea here?

If I'm reading this commit[1] right, it seems we decided to disallow passing of arrays without JSON, which affects -global on the command-line and HMP.

1- b06f8b500d (qdev: Rework array properties based on list visitor, 2023-11-09)

Quoted 8 lines

QMP shell:
(QEMU) migrate-set-parameters dsa-accel-path=['a','b'] {"return": {}}

HMP:
(qemu) migrate_set_parameter dsa-accel-path "['a','b']"
qemu-system-x86_64: ../qapi/string-input-visitor.c:343: parse_type_str:
Assertion `siv->lm == LM_NONE' failed.

HMP migrate_set_parameter doesn't support JSON. It uses the string input visitor to parse the value, which can only do lists of integers.

The string visitors have been thorns in my side since forever.

Quoted 5 lines

Any recommendation? I believe all migration parameters so far can be set via those means, I don't think we can allow only this one to be QMP-only.

Or am I just missing something?

Quoted 9 lines

I don't think the string input visitor can be compatibly extended to arbitrary lists.

We could replace HMP migrate_set_parameter by migrate_set_parameters. The new command parses its single argument into a struct MigrateSetParameters with keyval_parse(), qobject_input_visitor_new_keyval(), and visit_type_MigrateSetParameters().

Quoted 5 lines

I tried Fabiano's suggestion, and put a unit32_t in MigrateState data structure. I got exactly the same: "qemu-system-x86_64.dsa:
../../../qapi/string-input-visitor.c:343: parse_type_str: Assertion `siv->lm == LM_NONE' failed.". Steve's patch is more to be a read-only field from HMP, so probably I can't do that.

What do you mean by read-only field? I thought his usage was the same as what we want for dsa-accel-path:

(qemu) migrate_set_parameter cpr-exec-command abc def (qemu) info migrate_parameters
...
cpr-exec-command: abc def

(gdb) p valuestr
$3 = 0x55555766a8d0 "abc def"
(gdb) p *p->cpr_exec_command
$6 = {next = 0x55555823d300, value = 0x55555765f690 "abc"} (gdb) p *p->cpr_exec_command.next
$7 = {next = 0x55555805be20, value = 0x555557fefc80 "def"}