Use Intel DSA accelerator to offload zero page checking in multifd live migration.
Subsystems (2)
v6 cover Use Intel DSA accelerator to offload zero page checking in multifd live migration.
v6
* Rebase on top of 838fc0a8769d7cc6edfe50451ba4e3368395f5c1;
* Refactor code to have clean history on all commits;
* Add comments on DSA specific defines about how the value is picked;
* Address all comments from v5 reviews about api defines, questions, etc.;
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 (11):
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: 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.
hmp-commands.hx | 2 +- include/qemu/dsa.h | 189 ++++++ meson.build | 14 + meson_options.txt | 2 + migration/migration-hmp-cmds.c | 26 +- migration/multifd-zero-page.c | 133 +++- migration/multifd-zlib.c | 6 +- migration/multifd-zstd.c | 6 +- migration/multifd.c | 19 +- migration/multifd.h | 5 + migration/options.c | 69 ++ 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 | 1114 +++++++++++++++++++++++++++++++ util/meson.build | 3 + 20 files changed, 2204 insertions(+), 29 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
PATCH v6 1/12 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 +14 -0
@@ -2954,6 +2954,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
@@ -123,6 +123,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
@@ -96,6 +96,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'
@@ -241,6 +242,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
PATCH v6 2/12 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
@@ -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
PATCH v6 3/12 util/dsa: Implement DSA device start and stop logic.
In reply to Yichen WangFrom: 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 | 103 +++++++++++++++++ util/dsa.c | 282 +++++++++++++++++++++++++++++++++++++++++++++ util/meson.build | 3 + 3 files changed, 388 insertions(+) create mode 100644 include/qemu/dsa.h create mode 100644 util/dsa.c
include/qemu/dsa.h new file +103 -0
@@ -0,0 +1,103 @@ +/* +* 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" + +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 ; + +/** +* @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 strList *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 strList *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 +282 -0
282 lines not on this page · raw message
util/meson.build +3 -0
@@ -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
Re: [PATCH v6 03/12] util/dsa: Implement DSA device start and stop logic.
util/meson.build if have_block or have_ga · line 93
Quoted 11 lines · Yichen Wang
util/meson.build +3
-0@@ -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
It's not clear to me why this needs to be under have_block.
Since we want to make sure this file is ignored on !x86, maybe it should be put under the "elif cpu in ['x86', 'x86_64']" section.
Quoted 6 lines
util/meson.build +0
-0util_ss.add(files('buffer.c')) util_ss.add(files('bufferiszero.c')) util_ss.add(files('hbitmap.c'))Signature · 1 line
Yichen Wang
Signature · 1 line
Peter Xu
Re: [PATCH v6 03/12] util/dsa: Implement DSA device start and stop logic.
In reply to Yichen WangQuoted 264 lines · Yichen Wang
From: Hao Xiang <[email protected]>
* DSA device open and close.
* DSA group contains multiple DSA devices.
* DSA group configure/start/stop/clean.Signed-off-by Hao Xiang <[email protected]>Signed-off-by Bryan Zhang <[email protected]>Signed-off-by Yichen Wang <[email protected]>--- include/qemu/dsa.h | 103 +++++++++++++++++ util/dsa.c | 282 +++++++++++++++++++++++++++++++++++++++++++++ util/meson.build | 3 + 3 files changed, 388 insertions(+) create mode 100644 include/qemu/dsa.h create mode 100644 util/dsa.cinclude/qemu/dsa.h new file +103
-0@@ -0,0 +1,103 @@ +/* +* 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" + +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 ; + +/** +* @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 strList *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 strList *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 +132
-0@@ -0,0 +1,282 @@ +/* +* Use Intel Data Streaming Accelerator to offload certain background +* operations. +* +* Copyright (C) Bytedance Ltd. +* +* Authors: +* Hao Xiang <[email protected]> +* Bryan Zhang <[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. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/queue.h" +#include "qemu/memalign.h" +#include "qemu/lockable.h" +#include "qemu/cutils.h" +#include "qemu/dsa.h" +#include "qemu/bswap.h" +#include "qemu/error-report.h" +#include "qemu/rcu.h" + +#pragma GCC push_options +#pragma GCC target("enqcmd") + +#include <linux/idxd.h> +#include "x86intrin.h" + +#define DSA_WQ_PORTAL_SIZE 4096 +#define MAX_DSA_DEVICES 16 + +uint32_t max_retry_count; +static QemuDsaDeviceGroup dsa_group; + + +/** +* @brief This function opens a DSA device's work queue and +* maps the DSA device memory into the current process. +* +* @param dsa_wq_path A pointer to the DSA device work queue's file path. +* @return A pointer to the mapped memory, or MAP_FAILED on failure. +*/ +static void * +map_dsa_device (const char *dsa_wq_path) +{ +void *dsa_device; +int fd; + + fd =open (dsa_wq_path,O_RDWR ); +if (fd <0 ) { +error_report ("Open %s failed with errno = %d." , + dsa_wq_path, errno); +return MAP_FAILED ; + } + dsa_device =mmap (NULL ,DSA_WQ_PORTAL_SIZE ,PROT_WRITE , +MAP_SHARED |MAP_POPULATE , fd,0 ); +close (fd); +if (dsa_device ==MAP_FAILED ) { +error_report ("mmap failed with errno = %d." , errno); +return MAP_FAILED ; + } +return dsa_device; +} + +/** +* @brief Initializes a DSA device structure. +* +* @param instance A pointer to the DSA device. +* @param work_queue A pointer to the DSA work queue. +*/ +static void +dsa_device_init (QemuDsaDevice *instance, +void *dsa_work_queue) +{ + instance->work_queue = dsa_work_queue; +} + +/** +* @brief Cleans up a DSA device structure. +* +* @param instance A pointer to the DSA device to cleanup. +*/ +static void +dsa_device_cleanup (QemuDsaDevice *instance) +{ +if (instance->work_queue !=MAP_FAILED ) { +munmap (instance->work_queue,DSA_WQ_PORTAL_SIZE ); + } +} + +/** +* @brief Initializes a DSA device group. +* +* @param group A pointer to the DSA device group. +* @param dsa_parameter A list of DSA device path from are separated by space +* character migration parameter. Multiple DSA device path. +* +* @return Zero if successful, non-zero otherwise. +*/ +static int +dsa_device_group_init (QemuDsaDeviceGroup *group, +const strList *dsa_parameter, +Error **errp) +{ +if (dsa_parameter ==NULL ) { +error_setg (errp,"dsa device path is not supplied." ); +return -1 ; + } + +int ret =0 ; +const char *dsa_path[MAX_DSA_DEVICES ]; +int num_dsa_devices =0 ; + +while (dsa_parameter) { + dsa_path[num_dsa_devices++] = dsa_parameter->value; +if (num_dsa_devices ==MAX_DSA_DEVICES ) { +break ; + } + dsa_parameter = dsa_parameter->next; + } + + group->dsa_devices = +g_new0 (QemuDsaDevice, num_dsa_devices); + group->num_dsa_devices = num_dsa_devices; + group->device_allocator_index =0 ; + + group->running = false; +qemu_mutex_init (&group->task_queue_lock);
util/dsa.c line 142
Quoted 10 lines
util/dsa.c new file +10
-0+qemu_cond_init (&group->task_queue_cond); +QSIMPLEQ_INIT (&group->task_queue); + +void *dsa_wq =MAP_FAILED ; +for (int i =0 ; i < num_dsa_devices; i++) { + dsa_wq =map_dsa_device (dsa_path[i]); +if (dsa_wq ==MAP_FAILED ) { +error_setg (errp,"map_dsa_device failed MAP_FAILED." ); + ret =-1 ; + goto exit;
This will leave subsequent dsa_devices uninitialized after map_dsa_device fails for the i-th device, but the loop at dsa_device_group_cleanup() still passes all of them into dsa_device_cleanup(), so the check != MAP_FAILED there will be true.
util/dsa.c line 144
Quoted 2 lines
util/dsa.c new file +2
-0+ } +dsa_device_init (&dsa_group.dsa_devices[i], dsa_wq);
I think you mean &group->dsa_devices[i] here.
Quoted 152 lines
util/dsa.c new file +138
-0+ } + +exit: +return ret; +} + +/** +* @brief Starts a DSA device group. +* +* @param group A pointer to the DSA device group. +*/ +static void +dsa_device_group_start (QemuDsaDeviceGroup *group) +{ + group->running = true; +} + +/** +* @brief Stops a DSA device group. +* +* @param group A pointer to the DSA device group. +*/ +__attribute__((unused)) +static void +dsa_device_group_stop (QemuDsaDeviceGroup *group) +{ + group->running = false; +} + +/** +* @brief Cleans up a DSA device group. +* +* @param group A pointer to the DSA device group. +*/ +static void +dsa_device_group_cleanup (QemuDsaDeviceGroup *group) +{ +if (!group->dsa_devices) { +return ; + } +for (int i =0 ; i < group->num_dsa_devices; i++) { +dsa_device_cleanup (&group->dsa_devices[i]); + } +g_free (group->dsa_devices); + group->dsa_devices =NULL ; + +qemu_mutex_destroy (&group->task_queue_lock); +qemu_cond_destroy (&group->task_queue_cond); +} + +/** +* @brief Returns the next available DSA device in the group. +* +* @param group A pointer to the DSA device group. +* +* @return struct QemuDsaDevice* A pointer to the next available DSA device +* in the group. +*/ +__attribute__((unused)) +static QemuDsaDevice * +dsa_device_group_get_next_device (QemuDsaDeviceGroup *group) +{ +if (group->num_dsa_devices ==0 ) { +return NULL ; + } +uint32_t current =qatomic_fetch_inc (&group->device_allocator_index); + current %= group->num_dsa_devices; +return &group->dsa_devices[current]; +} + +/** +* @brief Check if DSA is running. +* +* @return True if DSA is running, otherwise false. +*/ +bool qemu_dsa_is_running (void ) +{ +return false; +} + +static void +dsa_globals_init (void ) +{ + max_retry_count =UINT32_MAX ; +} + +/** +* @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 strList *dsa_parameter,Error **errp) +{ +dsa_globals_init (); + +return dsa_device_group_init (&dsa_group, dsa_parameter, errp); +} + +/** +* @brief Start logic to enable using DSA. +* +*/ +void qemu_dsa_start (void ) +{ +if (dsa_group.num_dsa_devices ==0 ) { +return ; + } +if (dsa_group.running) { +return ; + } +dsa_device_group_start (&dsa_group); +} + +/** +* @brief Stop the device group and the completion thread. +* +*/ +void qemu_dsa_stop (void ) +{ +QemuDsaDeviceGroup *group = &dsa_group; + +if (!group->running) { +return ; + } +} + +/** +* @brief Clean up system resources created for DSA offloading. +* +*/ +void qemu_dsa_cleanup (void ) +{ +qemu_dsa_stop (); +dsa_device_group_cleanup (&dsa_group); +} +util/meson.build +3
-0@@ -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'))
PATCH v6 4/12 util/dsa: Implement DSA task enqueue and dequeue.
In reply to Yichen WangFrom: 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 | 29 +++++++ util/dsa.c | 202 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 230 insertions(+), 1 deletion(-)
include/qemu/dsa.h +29 -0
@@ -27,6 +27,17 @@#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 ;
@@ -44,6 +55,24 @@ typedef struct {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 +201 -1
226 lines not on this page · raw message
Signature · 1 line
Yichen Wang
PATCH v6 5/12 util/dsa: Implement DSA task asynchronous completion thread model.
In reply to Yichen WangFrom: 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
@@ -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
PATCH v6 6/12 util/dsa: Implement zero page checking in DSA task.
In reply to Yichen WangFrom: 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 | 45 ++++++-- util/dsa.c | 254 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 270 insertions(+), 29 deletions(-)
include/qemu/dsa.h +37 -8
@@ -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. *
@@ -105,8 +107,26 @@ void qemu_dsa_cleanup(void);*/ bool qemu_dsa_is_running (void ); +/** +* @brief Initializes a buffer zero DSA batch task. +* +* @param batch_size The number of zero page checking tasks in the batch. +* @return A pointer to the zero page checking tasks initialized. +*/ +QemuDsaBatchTask * +buffer_zero_batch_task_init (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 +typedef struct QemuDsaBatchTask {}QemuDsaBatchTask ; +static inline bool qemu_dsa_is_running (void ) {return false;
@@ -114,19 +134,28 @@ static inline bool qemu_dsa_is_running(void)static inline int qemu_dsa_init (const strList *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
util/dsa.c +233 -21
299 lines not on this page · raw message
Signature · 1 line
Yichen Wang
PATCH v6 7/12 util/dsa: Implement DSA task asynchronous submission and wait for completion.
In reply to Yichen WangFrom: 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
@@ -123,6 +123,20 @@ buffer_zero_batch_task_init(int batch_size);*/ 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 typedef struct QemuDsaBatchTask {}QemuDsaBatchTask ;
util/dsa.c +121 -4
164 lines not on this page · raw message
Signature · 1 line
Yichen Wang
PATCH v6 8/12 migration/multifd: Add new migration option for multifd DSA offloading.
In reply to Yichen WangFrom: 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 by setting:
zero-page-detection=dsa-accel dsa-accel-path=[dsa_dev_path1] [dsa_dev_path2] ... [dsa_dev_pathX]
This feature is turned off by default.
--- hmp-commands.hx | 2 +- include/qemu/dsa.h | 13 +++++++++++++ migration/migration-hmp-cmds.c | 19 ++++++++++++++++++- migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 32 ++++++++++++++++++++++++++++---- util/dsa.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-)
hmp-commands.hx +1 -1
@@ -1009,7 +1009,7 @@ ERST { .name = "migrate_set_parameter", - .args_type = "parameter:s,value:s", + .args_type = "parameter:s,value:S", .params = "parameter value", .help = "Set the parameter for migration", .cmd = hmp_migrate_set_parameter,
include/qemu/dsa.h +13 -0
@@ -100,6 +100,13 @@ void qemu_dsa_stop(void);*/ void qemu_dsa_cleanup (void ); +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ); +/** * @brief Check if DSA is running. *
@@ -141,6 +148,12 @@ buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,typedef struct QemuDsaBatchTask {}QemuDsaBatchTask ; +static inline bool qemu_dsa_is_supported (void ) +{ +return false; +} + +static inline bool qemu_dsa_is_running (void ) {return false;
migration/migration-hmp-cmds.c +18 -1
@@ -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,14 @@ 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; + g_autofree char **strv = g_strsplit(valuestr ? : "", " ", -1); +strList **tail = &p->dsa_accel_path; +for (int i =0 ; strv[i]; i++) { +QAPI_LIST_APPEND (tail, strv[i]); + } +break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true;visit_type_uint8 (v, param, &p->multifd_channels, &err);
migration/options.c +30 -0
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/dsa.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h"
@@ -832,6 +833,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 ();
@@ -945,6 +953,8 @@ 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->has_dsa_accel_path = true; + params->dsa_accel_path =QAPI_CLONE (strList, s->parameters.dsa_accel_path);return params; }
@@ -953,6 +963,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;
@@ -1165,6 +1176,14 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_zero_page_detection && + params->zero_page_detection ==ZERO_PAGE_DETECTION_DSA_ACCEL ) { +if (!qemu_dsa_is_supported ()) { +error_setg (errp,"DSA acceleration is not supported." ); +return false; + } + } +return true; }
@@ -1278,6 +1297,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)
@@ -1410,6 +1434,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)
migration/options.h +1 -0
@@ -86,6 +86,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
@@ -626,10 +626,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:
@@ -837,6 +841,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)
@@ -855,7 +865,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',
@@ -1018,6 +1028,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)
@@ -1063,7 +1079,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @migrate-set-parameters:
@@ -1228,6 +1245,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)
@@ -1270,7 +1293,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @query-migrate-parameters:
util/dsa.c +31 -0
@@ -23,6 +23,7 @@#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include <cpuid.h> #pragma GCC push_options#pragma GCC target("enqcmd")
@@ -691,6 +692,36 @@ static void dsa_completion_thread_stop(void *opaque)qemu_sem_destroy (&thread_context->sem_init_done); } +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ) +{ +/* +* movdir64b is indicated by bit 28 of ecx in CPUID leaf 7, subleaf 0. +* enqcmd is indicated by bit 29 of ecx in CPUID leaf 7, subleaf 0. +* Doc: https://cdrdv2-public.intel.com/819680/architecture-instruction-\ +* set-extensions-programming-reference.pdf +*/ +uint32_t eax, ebx, ecx, edx; +bool movedirb_enabled; +bool enqcmd_enabled; + +__get_cpuid_count (7 ,0 , &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; +} +/** * @brief Check if DSA is running. *
Signature · 1 line
Yichen Wang
Re: [PATCH v6 08/12] migration/multifd: Add new migration option for multifd DSA offloading.
Quoted 1 line · * Yichen Wang ([email protected]) wrote:
From: Hao Xiang <[email protected]>
Please split the cpuid stuff out into a separate patch; it feels like it should be in some x86 specific place.
Quoted 6 lines
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 by setting:
zero-page-detection=dsa-accel dsa-accel-path=[dsa_dev_path1] [
dsa_dev_path2] ... [dsa_dev_pathX]
I'd like to suggest changing that to:
accel-path=dsa:dev_path1 dsa:dev_path2 somethingelse:dev_path2 etc
that means we don't need a new option when someone adds a different accelerator.
Dave
Quoted 19 lines
This feature is turned off by default.
Signed-off-by Hao Xiang <[email protected]>Signed-off-by Yichen Wang <[email protected]>--- hmp-commands.hx | 2 +- include/qemu/dsa.h | 13 +++++++++++++ migration/migration-hmp-cmds.c | 19 ++++++++++++++++++- migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 32 ++++++++++++++++++++++++++++---- util/dsa.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-)hmp-commands.hx +0
-0
hmp-commands.hx ERST · line 1012
Quoted 5 lines
hmp-commands.hx +1
-1@@ -1009,7 +1009,7 @@ ERST { .name = "migrate_set_parameter", - .args_type = "parameter:s,value:s", + .args_type = "parameter:s,value:S",
Can you show the case you need this for?
Dave
Quoted 306 lines
hmp-commands.hx +0
-0.params = "parameter value", .help = "Set the parameter for migration", .cmd = hmp_migrate_set_parameter,include/qemu/dsa.h +13
-0@@ -100,6 +100,13 @@ void qemu_dsa_stop(void);*/ void qemu_dsa_cleanup (void ); +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ); +/** * @brief Check if DSA is running. * @@ -141,6 +148,12 @@ buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,typedef struct QemuDsaBatchTask {}QemuDsaBatchTask ; +static inline bool qemu_dsa_is_supported (void ) +{ +return false; +} + +static inline bool qemu_dsa_is_running (void ) {return false;migration/migration-hmp-cmds.c +18
-1@@ -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,14 @@ 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; + g_autofree char **strv = g_strsplit(valuestr ? : "", " ", -1); +strList **tail = &p->dsa_accel_path; +for (int i =0 ; strv[i]; i++) { +QAPI_LIST_APPEND (tail, strv[i]); + } +break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true;visit_type_uint8 (v, param, &p->multifd_channels, &err);migration/options.c +30
-0@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/dsa.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -832,6 +833,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 ();@@ -945,6 +953,8 @@ 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->has_dsa_accel_path = true; + params->dsa_accel_path =QAPI_CLONE (strList, s->parameters.dsa_accel_path);return params; }@@ -953,6 +963,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;@@ -1165,6 +1176,14 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_zero_page_detection && + params->zero_page_detection ==ZERO_PAGE_DETECTION_DSA_ACCEL ) { +if (!qemu_dsa_is_supported ()) { +error_setg (errp,"DSA acceleration is not supported." ); +return false; + } + } +return true; }@@ -1278,6 +1297,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)@@ -1410,6 +1434,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)migration/options.h +1
-0@@ -86,6 +86,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@@ -626,10 +626,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:@@ -837,6 +841,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)@@ -855,7 +865,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',@@ -1018,6 +1028,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)@@ -1063,7 +1079,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @migrate-set-parameters:@@ -1228,6 +1245,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)@@ -1270,7 +1293,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @query-migrate-parameters:util/dsa.c +31
-0@@ -23,6 +23,7 @@#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include <cpuid.h> #pragma GCC push_options#pragma GCC target("enqcmd")@@ -691,6 +692,36 @@ static void dsa_completion_thread_stop(void *opaque)qemu_sem_destroy (&thread_context->sem_init_done); } +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ) +{ +/* +* movdir64b is indicated by bit 28 of ecx in CPUID leaf 7, subleaf 0. +* enqcmd is indicated by bit 29 of ecx in CPUID leaf 7, subleaf 0. +* Doc: https://cdrdv2-public.intel.com/819680/architecture-instruction-\ +* set-extensions-programming-reference.pdf +*/ +uint32_t eax, ebx, ecx, edx; +bool movedirb_enabled; +bool enqcmd_enabled; + +__get_cpuid_count (7 ,0 , &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; +} +/** * @brief Check if DSA is running. * Signature · 1 line
Yichen Wang
Signature · 4 lines
-----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
Re: [External] Re: [PATCH v6 08/12] migration/multifd: Add new migration option for multifd DSA offloading.
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 1 line · * Yichen Wang ([email protected]) wrote:
From: Hao Xiang <[email protected]>
Please split the cpuid stuff out into a separate patch; it feels like it should be in some x86 specific place.
DSA is an Intel feature/device, and it only makes sense on x86. I mean, dsa.c already implies that it is a x86 specific feature. So I guess keeping it in the dsa.c is a better option?
Quoted 8 lines
Quoted 7 lines
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 by setting:
zero-page-detection=dsa-accel dsa-accel-path=[dsa_dev_path1] [
dsa_dev_path2] ... [dsa_dev_pathX]
Quoted 6 lines
I'd like to suggest changing that to:
accel-path=dsa:dev_path1 dsa:dev_path2 somethingelse:dev_path2 etc
that means we don't need a new option when someone adds a different accelerator.
It all depends on the implementation of "other accelerators". I am OK with this change if you believe that is better.
Quoted 22 lines
Dave
Quoted 20 lines
This feature is turned off by default.
Signed-off-by Hao Xiang <[email protected]>Signed-off-by Yichen Wang <[email protected]>--- hmp-commands.hx | 2 +- include/qemu/dsa.h | 13 +++++++++++++ migration/migration-hmp-cmds.c | 19 ++++++++++++++++++- migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 32 ++++++++++++++++++++++++++++---- util/dsa.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-)hmp-commands.hx +0
-0@@ -1009,7 +1009,7 @@ ERST
Quoted 7 lines
hmp-commands.hx ERST · line 1012
Quoted 4 lines
hmp-commands.hx +1
-1{ .name = "migrate_set_parameter", - .args_type = "parameter:s,value:s", + .args_type = "parameter:s,value:S",Can you show the case you need this for?
That is used for pass a strList in the QEMU CLI. Without this change, I cannot do:migrate_set_parameter dsa-accel-path /dev/dsa/wq0.1 /dev/dsa/wq0.1 and it will complain.
Quoted 313 lines
Dave
Quoted 304 lines
hmp-commands.hx +0
-0.params = "parameter value", .help = "Set the parameter for migration", .cmd = hmp_migrate_set_parameter,include/qemu/dsa.h +13
-0@@ -100,6 +100,13 @@ void qemu_dsa_stop(void);*/ void qemu_dsa_cleanup (void ); +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ); +/** * @brief Check if DSA is running. * @@ -141,6 +148,12 @@ buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,typedef struct QemuDsaBatchTask {}QemuDsaBatchTask ; +static inline bool qemu_dsa_is_supported (void ) +{ +return false; +} + +static inline bool qemu_dsa_is_running (void ) {return false;migration/migration-hmp-cmds.c +18
-1@@ -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,14 @@ 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; + g_autofree char **strv = g_strsplit(valuestr ? : "", " ", -1); +strList **tail = &p->dsa_accel_path; +for (int i =0 ; strv[i]; i++) { +QAPI_LIST_APPEND (tail, strv[i]); + } +break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true;visit_type_uint8 (v, param, &p->multifd_channels, &err);migration/options.c +30
-0@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/dsa.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -832,6 +833,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 ();@@ -945,6 +953,8 @@ 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->has_dsa_accel_path = true; + params->dsa_accel_path =QAPI_CLONE (strList, s->parameters.dsa_accel_path);return params; }@@ -953,6 +963,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;@@ -1165,6 +1176,14 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_zero_page_detection && + params->zero_page_detection ==ZERO_PAGE_DETECTION_DSA_ACCEL ) { +if (!qemu_dsa_is_supported ()) { +error_setg (errp,"DSA acceleration is not supported." ); +return false; + } + } +return true; }@@ -1278,6 +1297,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)@@ -1410,6 +1434,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)migration/options.h +1
-0@@ -86,6 +86,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@@ -626,10 +626,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:@@ -837,6 +841,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)@@ -855,7 +865,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',@@ -1018,6 +1028,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)@@ -1063,7 +1079,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @migrate-set-parameters:@@ -1228,6 +1245,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)@@ -1270,7 +1293,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @query-migrate-parameters:util/dsa.c +31
-1@@ -23,6 +23,7 @@#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include <cpuid.h> #pragma GCC push_options#pragma GCC target("enqcmd")@@ -691,6 +692,36 @@ static void dsa_completion_thread_stop(void *opaque)qemu_sem_destroy (&thread_context->sem_init_done); } +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ) +{ +/* +* movdir64b is indicated by bit 28 of ecx in CPUID leaf 7, subleaf 0. +* enqcmd is indicated by bit 29 of ecx in CPUID leaf 7, subleaf 0. +* Doc: https://cdrdv2-public.intel.com/819680/architecture-instruction-\ +* set-extensions-programming-reference.pdf +*/ +uint32_t eax, ebx, ecx, edx; +bool movedirb_enabled; +bool enqcmd_enabled; + +__get_cpuid_count (7 ,0 , &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; +} +/** * @brief Check if DSA is running. * -- Quoted 2 lines
Yichen Wang
--
-----Open up your eyes, open up your mind, open up your code -------/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
Re: [External] Re: [PATCH v6 08/12] migration/multifd: Add new migration option for multifd DSA offloading.
Quoted 4 lines · * Yichen Wang ([email protected]) wrote:
Quoted 2 lines · Dr. David Alan Gilbert
* Yichen Wang ([email protected]) wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
From: Hao Xiang <[email protected]>
Please split the cpuid stuff out into a separate patch; it feels like it should be in some x86 specific place.
DSA is an Intel feature/device, and it only makes sense on x86. I mean,
dsa.calready implies that it is a x86 specific feature. So I guess keeping it in thedsa.cis a better option?
Yes, the dsa.c might be OK; we just shouldn't have very x86 specific code in the other places.
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
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 by setting:
zero-page-detection=dsa-accel dsa-accel-path=[dsa_dev_path1] [
dsa_dev_path2] ... [dsa_dev_pathX]I'd like to suggest changing that to:
Quoted 7 lines
Quoted 4 lines
accel-path=dsa:dev_path1 dsa:dev_path2 somethingelse:dev_path2 etc
that means we don't need a new option when someone adds a different accelerator.
It all depends on the implementation of "other accelerators". I am OK with this change if you believe that is better.
I think so; it makes no assumption about what any other accelerator might need, but means we don't need to add yet another command for them.
Quoted 30 lines
Quoted 22 lines
Dave
Quoted 20 lines
This feature is turned off by default.
Signed-off-by Hao Xiang <[email protected]>Signed-off-by Yichen Wang <[email protected]>--- hmp-commands.hx | 2 +- include/qemu/dsa.h | 13 +++++++++++++ migration/migration-hmp-cmds.c | 19 ++++++++++++++++++- migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 32 ++++++++++++++++++++++++++++---- util/dsa.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-)hmp-commands.hx +0
-0@@ -1009,7 +1009,7 @@ ERSTQuoted 7 lines
hmp-commands.hx ERST · line 1012
Quoted 4 lines
hmp-commands.hx +1
-1{ .name = "migrate_set_parameter", - .args_type = "parameter:s,value:s", + .args_type = "parameter:s,value:S",Can you show the case you need this for?
Quoted 4 lines
That is used for pass a strList in the QEMU CLI. Without this change, I cannot do:
migrate_set_parameterdsa-accel-path/dev/dsa/wq0.1/dev/dsa/wq0.1and it will complain.
OK, please make sure you get a sensible error if you try and pass a string list to one of the existing parameters.
Dave
Quoted 313 lines
Quoted 313 lines
Dave
Quoted 304 lines
hmp-commands.hx +0
-0.params = "parameter value", .help = "Set the parameter for migration", .cmd = hmp_migrate_set_parameter,include/qemu/dsa.h +13
-0@@ -100,6 +100,13 @@ void qemu_dsa_stop(void);*/ void qemu_dsa_cleanup (void ); +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ); +/** * @brief Check if DSA is running. * @@ -141,6 +148,12 @@ buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task,typedef struct QemuDsaBatchTask {}QemuDsaBatchTask ; +static inline bool qemu_dsa_is_supported (void ) +{ +return false; +} + +static inline bool qemu_dsa_is_running (void ) {return false;migration/migration-hmp-cmds.c +18
-1@@ -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,14 @@ 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; + g_autofree char **strv = g_strsplit(valuestr ? : "", " ", -1); +strList **tail = &p->dsa_accel_path; +for (int i =0 ; strv[i]; i++) { +QAPI_LIST_APPEND (tail, strv[i]); + } +break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true;visit_type_uint8 (v, param, &p->multifd_channels, &err);migration/options.c +30
-0@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/dsa.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -832,6 +833,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 ();@@ -945,6 +953,8 @@ 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->has_dsa_accel_path = true; + params->dsa_accel_path =QAPI_CLONE (strList, s->parameters.dsa_accel_path);return params; }@@ -953,6 +963,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;@@ -1165,6 +1176,14 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_zero_page_detection && + params->zero_page_detection ==ZERO_PAGE_DETECTION_DSA_ACCEL ) { +if (!qemu_dsa_is_supported ()) { +error_setg (errp,"DSA acceleration is not supported." ); +return false; + } + } +return true; }@@ -1278,6 +1297,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)@@ -1410,6 +1434,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)migration/options.h +1
-0@@ -86,6 +86,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@@ -626,10 +626,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:@@ -837,6 +841,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)@@ -855,7 +865,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',@@ -1018,6 +1028,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)@@ -1063,7 +1079,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @migrate-set-parameters:@@ -1228,6 +1245,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)@@ -1270,7 +1293,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*dsa-accel-path': [ 'str' ] } } ## # @query-migrate-parameters:util/dsa.c +31
-1@@ -23,6 +23,7 @@#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include <cpuid.h> #pragma GCC push_options#pragma GCC target("enqcmd")@@ -691,6 +692,36 @@ static void dsa_completion_thread_stop(void *opaque)qemu_sem_destroy (&thread_context->sem_init_done); } +/** +* @brief Check if DSA is supported. +* +* @return True if DSA is supported, otherwise false. +*/ +bool qemu_dsa_is_supported (void ) +{ +/* +* movdir64b is indicated by bit 28 of ecx in CPUID leaf 7, subleaf 0. +* enqcmd is indicated by bit 29 of ecx in CPUID leaf 7, subleaf 0. +* Doc: https://cdrdv2-public.intel.com/819680/architecture-instruction-\ +* set-extensions-programming-reference.pdf +*/ +uint32_t eax, ebx, ecx, edx; +bool movedirb_enabled; +bool enqcmd_enabled; + +__get_cpuid_count (7 ,0 , &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; +} +/** * @brief Check if DSA is running. * -- Quoted 2 lines
Yichen Wang
--
-----Open up your eyes, open up your mind, open up your code -------/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
Signature · 4 lines
-----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
PATCH v6 9/12 migration/multifd: Enable DSA offloading in multifd sender path.
In reply to Yichen WangFrom: Hao Xiang <[email protected]>
Multifd sender path gets an array of pages queued by the migration thread. It performs zero page checking on every page in the array. The pages are classfied as either a zero page or a normal page. This change uses Intel DSA to offload the zero page checking from CPU to the DSA accelerator. The sender thread submits a batch of pages to DSA hardware and waits for the DSA completion thread to signal for work completion.
--- migration/multifd-zero-page.c | 133 ++++++++++++++++++++++++++++++---- migration/multifd.c | 19 ++++- migration/multifd.h | 5 ++ 3 files changed, 141 insertions(+), 16 deletions(-)
migration/multifd-zero-page.c +119 -14
@@ -21,7 +21,9 @@static bool multifd_zero_page_enabled (void ) { -return migrate_zero_page_detection () ==ZERO_PAGE_DETECTION_MULTIFD ; +ZeroPageDetection curMethod =migrate_zero_page_detection (); +return (curMethod ==ZERO_PAGE_DETECTION_MULTIFD || + curMethod ==ZERO_PAGE_DETECTION_DSA_ACCEL ); }static void swap_page_offset (ram_addr_t *pages_offset,int a,int b)
@@ -37,26 +39,49 @@ static void swap_page_offset(ram_addr_t *pages_offset, int a, int b) pages_offset[b] = temp; } +#ifdef CONFIG_DSA_OPT + +static void swap_result (bool *results,int a,int b) +{ +bool temp; + +if (a == b) { +return ; + } + + temp = results[a]; + results[a] = results[b]; + results[b] = temp; +} +/** -* multifd_send_zero_page_detect: Perform zero page detection on all pages. +* zero_page_detect_dsa: Perform zero page detection using +* Intel Data Streaming Accelerator (DSA). * -* Sorts normal pages before zero pages in p->pages->offset and updates -* p->pages->normal_num. +* Sorts normal pages before zero pages in pages->offset and updates +* pages->normal_num. * * @param p A pointer to the send params. */ -void multifd_send_zero_page_detect (MultiFDSendParams *p) +static void zero_page_detect_dsa (MultiFDSendParams *p) {MultiFDPages_t *pages = &p->data->u.ram;RAMBlock *rb = pages->block; -int i =0 ; -int j = pages->num -1 ; +bool *results = p->dsa_batch_task->results; -if (!multifd_zero_page_enabled ()) { - pages->normal_num = pages->num; - goto out; +for (int i =0 ; i < pages->num; i++) { + p->dsa_batch_task->addr[i] = + (ram_addr_t)(rb->host + pages->offset[i]); } +buffer_is_zero_dsa_batch_sync (p->dsa_batch_task, + (const void **)p->dsa_batch_task->addr, + pages->num, +multifd_ram_page_size ()); + +int i =0 ; +int j = pages->num -1 ; +/* * Sort the page offset array by moving all normal pages to * the left and all zero pages to the right of the array.
@@ -64,23 +89,39 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p)while (i <= j) {uint64_t offset = pages->offset[i]; -if (!buffer_is_zero (rb->host + offset,multifd_ram_page_size ())) { +if (!results[i]) { i++;continue ; } +swap_result (results, i, j);swap_page_offset (pages->offset, i, j);ram_release_page (rb->idstr, offset); j--; } pages->normal_num = i; +} -out: -stat64_add (&mig_stats.normal_pages, pages->normal_num); -stat64_add (&mig_stats.zero_pages, pages->num - pages->normal_num); +void multifd_dsa_cleanup (void ) +{ +qemu_dsa_cleanup (); +} + +#else + +static void zero_page_detect_dsa (MultiFDSendParams *p) +{ +g_assert_not_reached (); +} + +void multifd_dsa_cleanup (void ) +{ +g_assert_not_reached (); } +#endif +void multifd_recv_zero_page_process (MultiFDRecvParams *p) {for (int i =0 ; i < p->zero_num; i++) {
@@ -92,3 +133,67 @@ void multifd_recv_zero_page_process(MultiFDRecvParams *p) } } } + +/** +* zero_page_detect_cpu: Perform zero page detection using CPU. +* +* Sorts normal pages before zero pages in p->pages->offset and updates +* p->pages->normal_num. +* +* @param p A pointer to the send params. +*/ +static void zero_page_detect_cpu (MultiFDSendParams *p) +{ +MultiFDPages_t *pages = &p->data->u.ram; +RAMBlock *rb = pages->block; +int i =0 ; +int j = pages->num -1 ; + +if (!multifd_zero_page_enabled ()) { + pages->normal_num = pages->num; +return ; + } + +/* +* Sort the page offset array by moving all normal pages to +* the left and all zero pages to the right of the array. +*/ +while (i <= j) { +uint64_t offset = pages->offset[i]; + +if (!buffer_is_zero (rb->host + offset,multifd_ram_page_size ())) { + i++; +continue ; + } + +swap_page_offset (pages->offset, i, j); +ram_release_page (rb->idstr, offset); + j--; + } + + pages->normal_num = i; +} + +/** +* multifd_send_zero_page_detect: Perform zero page detection on all pages. +* +* @param p A pointer to the send params. +*/ +void multifd_send_zero_page_detect (MultiFDSendParams *p) +{ +MultiFDPages_t *pages = &p->data->u.ram; + +if (!multifd_zero_page_enabled ()) { + pages->normal_num = pages->num; +return ; + } + +if (qemu_dsa_is_running ()) { +zero_page_detect_dsa (p); + }else { +zero_page_detect_cpu (p); + } + +stat64_add (&mig_stats.normal_pages, pages->normal_num); +stat64_add (&mig_stats.zero_pages, pages->num - pages->normal_num); +}
migration/multifd.c +17 -2
@@ -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"
@@ -462,6 +463,8 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp) p->name =NULL ;g_free (p->data); p->data =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 ;
@@ -493,6 +496,8 @@ void multifd_send_shutdown(void)multifd_send_terminate_threads (); +multifd_dsa_cleanup (); +for (i =0 ; i <migrate_multifd_channels (); i++) {MultiFDSendParams *p = &multifd_send_state->params[i];Error *local_err =NULL ;
@@ -814,11 +819,21 @@ bool multifd_send_setup(void)uint32_t page_count =multifd_ram_page_count ();bool use_packets =multifd_use_packets ();uint8_t i; +Error *local_err =NULL ;if (!migrate_multifd ()) {return true; } +if (s && + s->parameters.zero_page_detection ==ZERO_PAGE_DETECTION_DSA_ACCEL ) { +const strList *dsa_parameter =migrate_dsa_accel_path (); +if (qemu_dsa_init (dsa_parameter, &local_err)) { +return false; + } +qemu_dsa_start (); + } + thread_count =migrate_multifd_channels (); multifd_send_state =g_malloc0 (sizeof (*multifd_send_state)); multifd_send_state->params =g_new0 (MultiFDSendParams, thread_count);
@@ -829,12 +844,12 @@ bool multifd_send_setup(void)for (i =0 ; i < thread_count; i++) {MultiFDSendParams *p = &multifd_send_state->params[i]; -Error *local_err =NULL ;qemu_sem_init (&p->sem,0 );qemu_sem_init (&p->sem_sync,0 ); p->id = i; p->data =multifd_send_data_alloc (); + p->dsa_batch_task =buffer_zero_batch_task_init (page_count);if (use_packets) { p->packet_len =sizeof (MultiFDPacket_t)
@@ -865,7 +880,6 @@ bool multifd_send_setup(void)for (i =0 ; i < thread_count; i++) {MultiFDSendParams *p = &multifd_send_state->params[i]; -Error *local_err =NULL ; ret = multifd_send_state->ops->send_setup (p, &local_err);if (ret) {
@@ -1047,6 +1061,7 @@ void multifd_recv_cleanup(void)qemu_thread_join (&p->thread); } } +multifd_dsa_cleanup ();for (i =0 ; i <migrate_multifd_channels (); i++) {multifd_recv_cleanup_channel (&multifd_recv_state->params[i]); }
migration/multifd.h +5 -0
@@ -15,6 +15,7 @@#include "exec/target_page.h" #include "ram.h" +#include "qemu/dsa.h" typedef struct MultiFDRecvData MultiFDRecvData ;typedef struct MultiFDSendData MultiFDSendData ;
@@ -155,6 +156,9 @@ typedef struct {bool pending_sync;MultiFDSendData *data; +/* Zero page checking batch task */ +QemuDsaBatchTask *dsa_batch_task; +/* thread local variables. No locking required */ /* pointer to the packet */
@@ -313,6 +317,7 @@ void multifd_send_fill_packet(MultiFDSendParams *p);bool multifd_send_prepare_common (MultiFDSendParams *p);void multifd_send_zero_page_detect (MultiFDSendParams *p);void multifd_recv_zero_page_process (MultiFDRecvParams *p); +void multifd_dsa_cleanup (void );static inline void multifd_send_prepare_header (MultiFDSendParams *p) {
Signature · 1 line
Yichen Wang
Re: [PATCH v6 09/12] migration/multifd: Enable DSA offloading in multifd sender path.
Quoted 150 lines · Yichen Wang
From: Hao Xiang <[email protected]>
Multifd sender path gets an array of pages queued by the migration thread. It performs zero page checking on every page in the array. The pages are classfied as either a zero page or a normal page. This change uses Intel DSA to offload the zero page checking from CPU to the DSA accelerator. The sender thread submits a batch of pages to DSA hardware and waits for the DSA completion thread to signal for work completion.
Signed-off-by Hao Xiang <[email protected]>Signed-off-by Yichen Wang <[email protected]>--- migration/multifd-zero-page.c | 133 ++++++++++++++++++++++++++++++---- migration/multifd.c | 19 ++++- migration/multifd.h | 5 ++ 3 files changed, 141 insertions(+), 16 deletions(-)migration/multifd-zero-page.c +65
-14@@ -21,7 +21,9 @@static bool multifd_zero_page_enabled (void ) { -return migrate_zero_page_detection () ==ZERO_PAGE_DETECTION_MULTIFD ; +ZeroPageDetection curMethod =migrate_zero_page_detection (); +return (curMethod ==ZERO_PAGE_DETECTION_MULTIFD || + curMethod ==ZERO_PAGE_DETECTION_DSA_ACCEL ); }static void swap_page_offset (ram_addr_t *pages_offset,int a,int b)@@ -37,26 +39,49 @@ static void swap_page_offset(ram_addr_t *pages_offset, int a, int b) pages_offset[b] = temp; } +#ifdef CONFIG_DSA_OPT + +static void swap_result (bool *results,int a,int b) +{ +bool temp; + +if (a == b) { +return ; + } + + temp = results[a]; + results[a] = results[b]; + results[b] = temp; +} +/** -* multifd_send_zero_page_detect: Perform zero page detection on all pages. +* zero_page_detect_dsa: Perform zero page detection using +* Intel Data Streaming Accelerator (DSA). * -* Sorts normal pages before zero pages in p->pages->offset and updates -* p->pages->normal_num. +* Sorts normal pages before zero pages in pages->offset and updates +* pages->normal_num. * * @param p A pointer to the send params. */ -void multifd_send_zero_page_detect (MultiFDSendParams *p) +static void zero_page_detect_dsa (MultiFDSendParams *p) {MultiFDPages_t *pages = &p->data->u.ram;RAMBlock *rb = pages->block; -int i =0 ; -int j = pages->num -1 ; +bool *results = p->dsa_batch_task->results; -if (!multifd_zero_page_enabled ()) { - pages->normal_num = pages->num; - goto out; +for (int i =0 ; i < pages->num; i++) { + p->dsa_batch_task->addr[i] = + (ram_addr_t)(rb->host + pages->offset[i]); } +buffer_is_zero_dsa_batch_sync (p->dsa_batch_task, + (const void **)p->dsa_batch_task->addr, + pages->num, +multifd_ram_page_size ()); + +int i =0 ; +int j = pages->num -1 ; +/* * Sort the page offset array by moving all normal pages to * the left and all zero pages to the right of the array. @@ -64,23 +89,39 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p)while (i <= j) {uint64_t offset = pages->offset[i]; -if (!buffer_is_zero (rb->host + offset,multifd_ram_page_size ())) { +if (!results[i]) { i++;continue ; } +swap_result (results, i, j);swap_page_offset (pages->offset, i, j);ram_release_page (rb->idstr, offset); j--; } pages->normal_num = i; +} -out: -stat64_add (&mig_stats.normal_pages, pages->normal_num); -stat64_add (&mig_stats.zero_pages, pages->num - pages->normal_num); +void multifd_dsa_cleanup (void ) +{ +qemu_dsa_cleanup (); +} + +#else + +static void zero_page_detect_dsa (MultiFDSendParams *p) +{ +g_assert_not_reached (); +} + +void multifd_dsa_cleanup (void ) +{ +g_assert_not_reached (); } +#endif +void multifd_recv_zero_page_process (MultiFDRecvParams *p) {for (int i =0 ; i < p->zero_num; i++) {@@ -92,3 +133,67 @@ void multifd_recv_zero_page_process(MultiFDRecvParams *p) } } } + +/** +* zero_page_detect_cpu: Perform zero page detection using CPU. +* +* Sorts normal pages before zero pages in p->pages->offset and updates +* p->pages->normal_num. +* +* @param p A pointer to the send params. +*/ +static void zero_page_detect_cpu (MultiFDSendParams *p)
migration/multifd-zero-page.c void multifd_recv_zero_page_process(MultiFDRecvParams *p) · line 155
Quoted 10 lines
migration/multifd-zero-page.c +10
-0+{ +MultiFDPages_t *pages = &p->data->u.ram; +RAMBlock *rb = pages->block; +int i =0 ; +int j = pages->num -1 ; + +if (!multifd_zero_page_enabled ()) { + pages->normal_num = pages->num; +return ; + }
This is already done in the caller.
Quoted 23 lines
migration/multifd-zero-page.c +23
-0+ +/* +* Sort the page offset array by moving all normal pages to +* the left and all zero pages to the right of the array. +*/ +while (i <= j) { +uint64_t offset = pages->offset[i]; + +if (!buffer_is_zero (rb->host + offset,multifd_ram_page_size ())) { + i++; +continue ; + } + +swap_page_offset (pages->offset, i, j); +ram_release_page (rb->idstr, offset); + j--; + } + + pages->normal_num = i; +} + +/** +* multifd_send_zero_page_detect: Perform zero page detection on all pages.
migration/multifd-zero-page.c void multifd_recv_zero_page_process(MultiFDRecvParams *p) · line 188
Quoted 10 lines
migration/multifd-zero-page.c +10
-0+* +* @param p A pointer to the send params. +*/ +void multifd_send_zero_page_detect (MultiFDSendParams *p) +{ +MultiFDPages_t *pages = &p->data->u.ram; + +if (!multifd_zero_page_enabled ()) { + pages->normal_num = pages->num; +return ;
goto out;
migration/multifd-zero-page.c void multifd_recv_zero_page_process(MultiFDRecvParams *p) · line 196
Quoted 8 lines
migration/multifd-zero-page.c +8
-0+ } + +if (qemu_dsa_is_running ()) { +zero_page_detect_dsa (p); + }else { +zero_page_detect_cpu (p); + } +
out:
Quoted 115 lines
migration/multifd-zero-page.c +3
-0+stat64_add (&mig_stats.normal_pages, pages->normal_num); +stat64_add (&mig_stats.zero_pages, pages->num - pages->normal_num); +}migration/multifd.c +17
-2@@ -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" @@ -462,6 +463,8 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp) p->name =NULL ;g_free (p->data); p->data =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 ;@@ -493,6 +496,8 @@ void multifd_send_shutdown(void)multifd_send_terminate_threads (); +multifd_dsa_cleanup (); +for (i =0 ; i <migrate_multifd_channels (); i++) {MultiFDSendParams *p = &multifd_send_state->params[i];Error *local_err =NULL ;@@ -814,11 +819,21 @@ bool multifd_send_setup(void)uint32_t page_count =multifd_ram_page_count ();bool use_packets =multifd_use_packets ();uint8_t i; +Error *local_err =NULL ;if (!migrate_multifd ()) {return true; } +if (s && + s->parameters.zero_page_detection ==ZERO_PAGE_DETECTION_DSA_ACCEL ) { +const strList *dsa_parameter =migrate_dsa_accel_path (); +if (qemu_dsa_init (dsa_parameter, &local_err)) { +return false; + } +qemu_dsa_start (); + } + thread_count =migrate_multifd_channels (); multifd_send_state =g_malloc0 (sizeof (*multifd_send_state)); multifd_send_state->params =g_new0 (MultiFDSendParams, thread_count);@@ -829,12 +844,12 @@ bool multifd_send_setup(void)for (i =0 ; i < thread_count; i++) {MultiFDSendParams *p = &multifd_send_state->params[i]; -Error *local_err =NULL ;qemu_sem_init (&p->sem,0 );qemu_sem_init (&p->sem_sync,0 ); p->id = i; p->data =multifd_send_data_alloc (); + p->dsa_batch_task =buffer_zero_batch_task_init (page_count);if (use_packets) { p->packet_len =sizeof (MultiFDPacket_t)@@ -865,7 +880,6 @@ bool multifd_send_setup(void)for (i =0 ; i < thread_count; i++) {MultiFDSendParams *p = &multifd_send_state->params[i]; -Error *local_err =NULL ; ret = multifd_send_state->ops->send_setup (p, &local_err);if (ret) {@@ -1047,6 +1061,7 @@ void multifd_recv_cleanup(void)qemu_thread_join (&p->thread); } } +multifd_dsa_cleanup ();for (i =0 ; i <migrate_multifd_channels (); i++) {multifd_recv_cleanup_channel (&multifd_recv_state->params[i]); }migration/multifd.h +5
-0@@ -15,6 +15,7 @@#include "exec/target_page.h" #include "ram.h" +#include "qemu/dsa.h" typedef struct MultiFDRecvData MultiFDRecvData ;typedef struct MultiFDSendData MultiFDSendData ;@@ -155,6 +156,9 @@ typedef struct {bool pending_sync;MultiFDSendData *data; +/* Zero page checking batch task */ +QemuDsaBatchTask *dsa_batch_task; +/* thread local variables. No locking required */ /* pointer to the packet */ @@ -313,6 +317,7 @@ void multifd_send_fill_packet(MultiFDSendParams *p);bool multifd_send_prepare_common (MultiFDSendParams *p);void multifd_send_zero_page_detect (MultiFDSendParams *p);void multifd_recv_zero_page_process (MultiFDRecvParams *p); +void multifd_dsa_cleanup (void );static inline void multifd_send_prepare_header (MultiFDSendParams *p) {
PATCH v6 10/12 migration/multifd: Add migration option set packet size.
In reply to Yichen WangFrom: Hao Xiang <[email protected]>
During live migration, if the latency between sender and receiver is high and bandwidth is also high (a long and fat pipe), using a bigger packet size can help reduce migration total time. The current multifd packet size is 128 * 4kb. In addition, Intel DSA offloading performs better with a large batch task.
This change adds an option to set the packet size, which is also useful for performance tuning. Both sender and receiver needs to set the same packet size for things to work.
Set the option:migrate_set_parameter multifd-packet-size 4190208
--- migration/migration-hmp-cmds.c | 7 ++++++ migration/multifd-zlib.c | 6 ++++-- migration/multifd-zstd.c | 6 ++++-- migration/options.c | 39 ++++++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 21 +++++++++++++++--- 6 files changed, 73 insertions(+), 7 deletions(-)
migration/migration-hmp-cmds.c +7 -0
@@ -292,6 +292,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon,"%s: %u ms\n" ,MigrationParameter_str (MIGRATION_PARAMETER_X_CHECKPOINT_DELAY ), params->x_checkpoint_delay); +monitor_printf (mon,"%s: %" PRIu64"\n" , +MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_PACKET_SIZE ), + params->multifd_packet_size);monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_CHANNELS ), params->multifd_channels);
@@ -580,6 +583,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)QAPI_LIST_APPEND (tail, strv[i]); }break ; +case MIGRATION_PARAMETER_MULTIFD_PACKET_SIZE : + p->has_multifd_packet_size = true; +visit_type_size (v, param, &p->multifd_packet_size, &err); +break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true;visit_type_uint8 (v, param, &p->multifd_channels, &err);
migration/multifd-zlib.c +4 -2
@@ -39,6 +39,7 @@ static int multifd_zlib_send_setup(MultiFDSendParams *p, Error **errp) struct zlib_data *z = g_new0(struct zlib_data, 1);z_stream *zs = &z->zs;const char *err_msg; +uint64_t multifd_packet_size =migrate_multifd_packet_size (); zs->zalloc =Z_NULL ; zs->zfree =Z_NULL ;
@@ -48,7 +49,7 @@ static int multifd_zlib_send_setup(MultiFDSendParams *p, Error **errp) goto err_free_z; }/* This is the maximum size of the compressed buffer */ - z->zbuff_len =compressBound (MULTIFD_PACKET_SIZE ); + z->zbuff_len =compressBound (multifd_packet_size); z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) { err_msg ="out of memory for zbuff" ;
@@ -162,6 +163,7 @@ out:static int multifd_zlib_recv_setup (MultiFDRecvParams *p,Error **errp) { +uint64_t multifd_packet_size =migrate_multifd_packet_size (); struct zlib_data *z = g_new0(struct zlib_data, 1);z_stream *zs = &z->zs;
@@ -176,7 +178,7 @@ static int multifd_zlib_recv_setup(MultiFDRecvParams *p, Error **errp)return -1 ; }/* To be safe, we reserve twice the size of the packet */ - z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; + z->zbuff_len = multifd_packet_size *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {inflateEnd (zs);
migration/multifd-zstd.c +4 -2
@@ -39,6 +39,7 @@ struct zstd_data {static int multifd_zstd_send_setup (MultiFDSendParams *p,Error **errp) { +uint64_t multifd_packet_size =migrate_multifd_packet_size (); struct zstd_data *z = g_new0(struct zstd_data, 1);int res;
@@ -58,7 +59,7 @@ static int multifd_zstd_send_setup(MultiFDSendParams *p, Error **errp)return -1 ; }/* This is the maximum size of the compressed buffer */ - z->zbuff_len =ZSTD_compressBound (MULTIFD_PACKET_SIZE ); + z->zbuff_len =ZSTD_compressBound (multifd_packet_size); z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {ZSTD_freeCStream (z->zcs);
@@ -149,6 +150,7 @@ out:static int multifd_zstd_recv_setup (MultiFDRecvParams *p,Error **errp) { +uint64_t multifd_packet_size =migrate_multifd_packet_size (); struct zstd_data *z = g_new0(struct zstd_data, 1);int ret;
@@ -170,7 +172,7 @@ static int multifd_zstd_recv_setup(MultiFDRecvParams *p, Error **errp) }/* To be safe, we reserve twice the size of the packet */ - z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; + z->zbuff_len = multifd_packet_size *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {ZSTD_freeDStream (z->zds);
migration/options.c +39 -0
@@ -80,6 +80,13 @@#define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5#define DEFAULT_MIGRATE_ANNOUNCE_STEP 100 +/* +* Parameter for multifd packet size. +*/ +#define DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE (128 * 4 * 1024) +/* DSA device supports up to 1024 batches, i.e. 1024 * 4K pages */ +#define MAX_MIGRATE_MULTIFD_PACKET_SIZE (1024 * 4 * 1024) +#define DEFINE_PROP_MIG_CAP (name, x) \ DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false)
@@ -173,6 +180,9 @@ Property migration_properties[] = {DEFINE_PROP_ZERO_PAGE_DETECTION ("zero-page-detection" , MigrationState, parameters.zero_page_detection,ZERO_PAGE_DETECTION_MULTIFD ), +DEFINE_PROP_SIZE ("multifd-packet-size" , MigrationState, + parameters.multifd_packet_size, +DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE ),/* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
@@ -783,6 +793,13 @@ int migrate_multifd_channels(void)return s->parameters.multifd_channels; } +uint64_t migrate_multifd_packet_size (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->parameters.multifd_packet_size; +} +MultiFDCompression migrate_multifd_compression (void ) {MigrationState *s =migrate_get_current ();
@@ -911,6 +928,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->downtime_limit = s->parameters.downtime_limit; params->has_x_checkpoint_delay = true; params->x_checkpoint_delay = s->parameters.x_checkpoint_delay; + params->has_multifd_packet_size = true; + params->multifd_packet_size = s->parameters.multifd_packet_size; params->has_multifd_channels = true; params->multifd_channels = s->parameters.multifd_channels; params->has_multifd_compression = true;
@@ -973,6 +992,7 @@ void migrate_params_init(MigrationParameters *params) params->has_max_bandwidth = true; params->has_downtime_limit = true; params->has_x_checkpoint_delay = true; + params->has_multifd_packet_size = true; params->has_multifd_channels = true; params->has_multifd_compression = true; params->has_multifd_zlib_level = true;
@@ -1055,6 +1075,19 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)/* x_checkpoint_delay is now always positive */ + if (params->has_multifd_packet_size && + ((params->multifd_packet_size < DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE) || + (params->multifd_packet_size > MAX_MIGRATE_MULTIFD_PACKET_SIZE) || + (params->multifd_packet_size % qemu_target_page_size() != 0))) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "multifd_packet_size", + "an integer in the range of " + stringify(DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE) + " to "stringify(MAX_MIGRATE_MULTIFD_PACKET_SIZE)", " + "and must be a multiple of guest VM's page size."); + return false; + } + if (params->has_multifd_channels && (params->multifd_channels < 1)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_channels",
@@ -1236,6 +1269,9 @@ static void migrate_params_test_apply(MigrateSetParameters *params, dest->x_checkpoint_delay = params->x_checkpoint_delay; } +if (params->has_multifd_packet_size) { + dest->multifd_packet_size = params->multifd_packet_size; + }if (params->has_multifd_channels) { dest->multifd_channels = params->multifd_channels; }
@@ -1364,6 +1400,9 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)colo_checkpoint_delay_set (); } +if (params->has_multifd_packet_size) { + s->parameters.multifd_packet_size = params->multifd_packet_size; + }if (params->has_multifd_channels) { s->parameters.multifd_channels = params->multifd_channels; }
migration/options.h +1 -0
@@ -87,6 +87,7 @@ 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 ); +uint64_t migrate_multifd_packet_size (void );/* parameters helpers */
qapi/migration.json +18 -3
@@ -851,6 +851,10 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @multifd-packet-size: Packet size in bytes used to migrate data. +# The value needs to be a multiple of guest page size. +# The default value is 524288 and max value is 4190208. (Since 9.2) +# # Features: # # @unstable: Members @x-checkpoint-delay and
@@ -877,7 +881,8 @@ 'vcpu-dirty-limit', 'mode', 'zero-page-detection', - 'direct-io'] } + 'direct-io', + 'multifd-packet-size'] } ## # @MigrateSetParameters:
@@ -1038,6 +1043,10 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @multifd-packet-size: Packet size in bytes used to migrate data. +# The value needs to be a multiple of guest page size. +# The default value is 524288 and max value is 4190208. (Since 9.2) +# # Features: # # @unstable: Members @x-checkpoint-delay and
@@ -1080,7 +1089,8 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*dsa-accel-path': [ 'str' ] } } + '*dsa-accel-path': [ 'str' ], + '*multifd-packet-size' : 'uint64'} } ## # @migrate-set-parameters:
@@ -1255,6 +1265,10 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @multifd-packet-size: Packet size in bytes used to migrate data. +# The value needs to be a multiple of guest page size. +# The default value is 524288 and max value is 4190208. (Since 9.2) +# # Features: # # @unstable: Members @x-checkpoint-delay and
@@ -1294,7 +1308,8 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*dsa-accel-path': [ 'str' ] } } + '*dsa-accel-path': [ 'str' ], + '*multifd-packet-size': 'uint64' } } ## # @query-migrate-parameters:
Signature · 1 line
Yichen Wang
Re: [PATCH v6 10/12] migration/multifd: Add migration option set packet size.
Quoted 12 lines · Yichen Wang
From: Hao Xiang <[email protected]>
During live migration, if the latency between sender and receiver is high and bandwidth is also high (a long and fat pipe), using a bigger packet size can help reduce migration total time. The current multifd packet size is 128 * 4kb. In addition, Intel DSA offloading performs better with a large batch task.
This change adds an option to set the packet size, which is also useful for performance tuning. Both sender and receiver needs to set the same packet size for things to work.
Quoted 5 lines
Set the option:
migrate_set_parametermultifd-packet-size 4190208Signed-off-by Hao Xiang <[email protected]>Signed-off-by Yichen Wang <[email protected]>
Looks good to me. However, could you do a migration-test pass setting the maximum value for all the tests to see if anything breaks?
Quoted 268 lines
--- migration/migration-hmp-cmds.c | 7 ++++++ migration/multifd-zlib.c | 6 ++++-- migration/multifd-zstd.c | 6 ++++-- migration/options.c | 39 ++++++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 21 +++++++++++++++--- 6 files changed, 73 insertions(+), 7 deletions(-)migration/migration-hmp-cmds.c +7
-0@@ -292,6 +292,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon,"%s: %u ms\n" ,MigrationParameter_str (MIGRATION_PARAMETER_X_CHECKPOINT_DELAY ), params->x_checkpoint_delay); +monitor_printf (mon,"%s: %" PRIu64"\n" , +MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_PACKET_SIZE ), + params->multifd_packet_size);monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_CHANNELS ), params->multifd_channels);@@ -580,6 +583,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)QAPI_LIST_APPEND (tail, strv[i]); }break ; +case MIGRATION_PARAMETER_MULTIFD_PACKET_SIZE : + p->has_multifd_packet_size = true; +visit_type_size (v, param, &p->multifd_packet_size, &err); +break ;case MIGRATION_PARAMETER_MULTIFD_CHANNELS : p->has_multifd_channels = true;visit_type_uint8 (v, param, &p->multifd_channels, &err);migration/multifd-zlib.c +4
-2@@ -39,6 +39,7 @@ static int multifd_zlib_send_setup(MultiFDSendParams *p, Error **errp) struct zlib_data *z = g_new0(struct zlib_data, 1);z_stream *zs = &z->zs;const char *err_msg; +uint64_t multifd_packet_size =migrate_multifd_packet_size (); zs->zalloc =Z_NULL ; zs->zfree =Z_NULL ;@@ -48,7 +49,7 @@ static int multifd_zlib_send_setup(MultiFDSendParams *p, Error **errp) goto err_free_z; }/* This is the maximum size of the compressed buffer */ - z->zbuff_len =compressBound (MULTIFD_PACKET_SIZE ); + z->zbuff_len =compressBound (multifd_packet_size); z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) { err_msg ="out of memory for zbuff" ;@@ -162,6 +163,7 @@ out:static int multifd_zlib_recv_setup (MultiFDRecvParams *p,Error **errp) { +uint64_t multifd_packet_size =migrate_multifd_packet_size (); struct zlib_data *z = g_new0(struct zlib_data, 1);z_stream *zs = &z->zs;@@ -176,7 +178,7 @@ static int multifd_zlib_recv_setup(MultiFDRecvParams *p, Error **errp)return -1 ; }/* To be safe, we reserve twice the size of the packet */ - z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; + z->zbuff_len = multifd_packet_size *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {inflateEnd (zs);migration/multifd-zstd.c +4
-2@@ -39,6 +39,7 @@ struct zstd_data {static int multifd_zstd_send_setup (MultiFDSendParams *p,Error **errp) { +uint64_t multifd_packet_size =migrate_multifd_packet_size (); struct zstd_data *z = g_new0(struct zstd_data, 1);int res;@@ -58,7 +59,7 @@ static int multifd_zstd_send_setup(MultiFDSendParams *p, Error **errp)return -1 ; }/* This is the maximum size of the compressed buffer */ - z->zbuff_len =ZSTD_compressBound (MULTIFD_PACKET_SIZE ); + z->zbuff_len =ZSTD_compressBound (multifd_packet_size); z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {ZSTD_freeCStream (z->zcs);@@ -149,6 +150,7 @@ out:static int multifd_zstd_recv_setup (MultiFDRecvParams *p,Error **errp) { +uint64_t multifd_packet_size =migrate_multifd_packet_size (); struct zstd_data *z = g_new0(struct zstd_data, 1);int ret;@@ -170,7 +172,7 @@ static int multifd_zstd_recv_setup(MultiFDRecvParams *p, Error **errp) }/* To be safe, we reserve twice the size of the packet */ - z->zbuff_len =MULTIFD_PACKET_SIZE *2 ; + z->zbuff_len = multifd_packet_size *2 ; z->zbuff =g_try_malloc (z->zbuff_len);if (!z->zbuff) {ZSTD_freeDStream (z->zds);migration/options.c +39
-0@@ -80,6 +80,13 @@#define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5#define DEFAULT_MIGRATE_ANNOUNCE_STEP 100 +/* +* Parameter for multifd packet size. +*/ +#define DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE (128 * 4 * 1024) +/* DSA device supports up to 1024 batches, i.e. 1024 * 4K pages */ +#define MAX_MIGRATE_MULTIFD_PACKET_SIZE (1024 * 4 * 1024) +#define DEFINE_PROP_MIG_CAP (name, x) \ DEFINE_PROP_BOOL(name, MigrationState, capabilities[x], false)@@ -173,6 +180,9 @@ Property migration_properties[] = {DEFINE_PROP_ZERO_PAGE_DETECTION ("zero-page-detection" , MigrationState, parameters.zero_page_detection,ZERO_PAGE_DETECTION_MULTIFD ), +DEFINE_PROP_SIZE ("multifd-packet-size" , MigrationState, + parameters.multifd_packet_size, +DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE ),/* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),@@ -783,6 +793,13 @@ int migrate_multifd_channels(void)return s->parameters.multifd_channels; } +uint64_t migrate_multifd_packet_size (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->parameters.multifd_packet_size; +} +MultiFDCompression migrate_multifd_compression (void ) {MigrationState *s =migrate_get_current ();@@ -911,6 +928,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->downtime_limit = s->parameters.downtime_limit; params->has_x_checkpoint_delay = true; params->x_checkpoint_delay = s->parameters.x_checkpoint_delay; + params->has_multifd_packet_size = true; + params->multifd_packet_size = s->parameters.multifd_packet_size; params->has_multifd_channels = true; params->multifd_channels = s->parameters.multifd_channels; params->has_multifd_compression = true;@@ -973,6 +992,7 @@ void migrate_params_init(MigrationParameters *params) params->has_max_bandwidth = true; params->has_downtime_limit = true; params->has_x_checkpoint_delay = true; + params->has_multifd_packet_size = true; params->has_multifd_channels = true; params->has_multifd_compression = true; params->has_multifd_zlib_level = true;@@ -1055,6 +1075,19 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)/* x_checkpoint_delay is now always positive */ + if (params->has_multifd_packet_size && + ((params->multifd_packet_size < DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE) || + (params->multifd_packet_size > MAX_MIGRATE_MULTIFD_PACKET_SIZE) || + (params->multifd_packet_size % qemu_target_page_size() != 0))) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "multifd_packet_size", + "an integer in the range of " + stringify(DEFAULT_MIGRATE_MULTIFD_PACKET_SIZE) + " to "stringify(MAX_MIGRATE_MULTIFD_PACKET_SIZE)", " + "and must be a multiple of guest VM's page size."); + return false; + } + if (params->has_multifd_channels && (params->multifd_channels < 1)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_channels",@@ -1236,6 +1269,9 @@ static void migrate_params_test_apply(MigrateSetParameters *params, dest->x_checkpoint_delay = params->x_checkpoint_delay; } +if (params->has_multifd_packet_size) { + dest->multifd_packet_size = params->multifd_packet_size; + }if (params->has_multifd_channels) { dest->multifd_channels = params->multifd_channels; }@@ -1364,6 +1400,9 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)colo_checkpoint_delay_set (); } +if (params->has_multifd_packet_size) { + s->parameters.multifd_packet_size = params->multifd_packet_size; + }if (params->has_multifd_channels) { s->parameters.multifd_channels = params->multifd_channels; }migration/options.h +1
-0@@ -87,6 +87,7 @@ 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 ); +uint64_t migrate_multifd_packet_size (void );/* parameters helpers */ qapi/migration.json +12
-2@@ -851,6 +851,10 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @multifd-packet-size: Packet size in bytes used to migrate data. +# The value needs to be a multiple of guest page size. +# The default value is 524288 and max value is 4190208. (Since 9.2) +# # Features: # # @unstable: Members @x-checkpoint-delay and@@ -877,7 +881,8 @@ 'vcpu-dirty-limit', 'mode', 'zero-page-detection', - 'direct-io'] } + 'direct-io', + 'multifd-packet-size'] } ## # @MigrateSetParameters:@@ -1038,6 +1043,10 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @multifd-packet-size: Packet size in bytes used to migrate data. +# The value needs to be a multiple of guest page size. +# The default value is 524288 and max value is 4190208. (Since 9.2) +# # Features: # # @unstable: Members @x-checkpoint-delay and@@ -1080,7 +1089,8 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*dsa-accel-path': [ 'str' ] } } + '*dsa-accel-path': [ 'str' ], + '*multifd-packet-size' : 'uint64'} } ## # @migrate-set-parameters:
qapi/migration.json line 1270
Quoted 6 lines
qapi/migration.json +3
-0@@ -1255,6 +1265,10 @@ # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) # +# @multifd-packet-size: Packet size in bytes used to migrate data. +# The value needs to be a multiple of guest page size. +# The default value is 524288 and max value is 4190208. (Since 9.2)
These will rot, better leave them out.
Quoted 14 lines
qapi/migration.json +3
-1+# # Features: # # @unstable: Members @x-checkpoint-delay and@@ -1294,7 +1308,8 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*dsa-accel-path': [ 'str' ] } } + '*dsa-accel-path': [ 'str' ], + '*multifd-packet-size': 'uint64' } } ## # @query-migrate-parameters:
PATCH v6 11/12 util/dsa: Add unit test coverage for Intel DSA task submission and completion.
In reply to Yichen WangFrom: Hao Xiang <[email protected]>
* Test DSA start and stop path.
* Test DSA configure and cleanup path.
* Test DSA task submission and completion path.
--- tests/unit/meson.build | 6 + tests/unit/test-dsa.c | 503 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 509 insertions(+) create mode 100644 tests/unit/test-dsa.c
tests/unit/meson.build +6 -0
@@ -50,6 +50,12 @@ tests = { 'test-fifo': [], } +if config_host_data.get('CONFIG_DSA_OPT') + tests += { + 'test-dsa': [], + } +endif + if have_system or have_tools tests += { 'test-qmp-event': [testqapi],
tests/unit/test-dsa.c new file +503 -0
503 lines not on this page · raw message
Signature · 1 line
Yichen Wang
PATCH v6 12/12 migration/multifd: Add integration tests for multifd with Intel DSA offloading.
In reply to Yichen WangFrom: Hao Xiang <[email protected]>
* Add test case to start and complete multifd live migration with DSA offloading enabled.
* Add test case to start and cancel multifd live migration with DSA offloading enabled.
--- tests/qtest/migration-test.c | 80 +++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-)
tests/qtest/migration-test.c +79 -1
@@ -611,6 +611,13 @@ typedef struct {bool suspend_me; } MigrateStart; +/* +* It requires separate steps to configure and enable DSA device. +* This test assumes that the configuration is done already. +*/ +static const char *dsa_dev_path_p ="['/dev/dsa/wq4.0']" ; +static const char *dsa_dev_path ="/dev/dsa/wq4.0" ; +/* * A hook that runs after the src and dst QEMUs have been * created, but before the migration is started. This can
@@ -3230,7 +3237,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)* * And see that it works */ -static void test_multifd_tcp_cancel (void ) +static void test_multifd_tcp_cancel_common (bool use_dsa) {MigrateStart args = { .hide_stderr = true,
@@ -3250,6 +3257,11 @@ static void test_multifd_tcp_cancel(void)migrate_set_capability (from,"multifd" , true);migrate_set_capability (to,"multifd" , true); +if (use_dsa) { +migrate_set_parameter_str (from,"zero-page-detection" ,"dsa-accel" ); +migrate_set_parameter_str (from,"dsa-accel-path" , dsa_dev_path_p); + } +/* Start incoming migration from the 1st socket */ migrate_incoming_qmp (to,"tcp:127.0.0.1:0" ,"{}" );
@@ -3300,6 +3312,49 @@ static void test_multifd_tcp_cancel(void)test_migrate_end (from, to2, true); } +/* +* This test does: +* source target +* migrate_incoming +* migrate +* migrate_cancel +* launch another target +* migrate +* +* And see that it works +*/ +static void test_multifd_tcp_cancel (void ) +{ +test_multifd_tcp_cancel_common (false); +} + +#ifdef CONFIG_DSA_OPT + +static void *test_migrate_precopy_tcp_multifd_start_dsa (QTestState *from, +QTestState *to) +{ +migrate_set_parameter_str (from,"zero-page-detection" ,"dsa-accel" ); +migrate_set_parameter_str (from,"dsa-accel-path" , dsa_dev_path_p); +return test_migrate_precopy_tcp_multifd_start_common (from, to,"none" ); +} + +static void test_multifd_tcp_zero_page_dsa (void ) +{ +MigrateCommon args = { + .listen_uri ="defer" , + .start_hook = test_migrate_precopy_tcp_multifd_start_dsa, + }; + +test_precopy_common (&args); +} + +static void test_multifd_tcp_cancel_dsa (void ) +{ +test_multifd_tcp_cancel_common (true); +} + +#endif +static void calc_dirty_rate (QTestState *who,uint64_t calc_time) { qtest_qmp_assert_success(who,
@@ -3727,6 +3782,19 @@ static bool kvm_dirty_ring_supported(void)#endif } +#ifdef CONFIG_DSA_OPT +static int test_dsa_setup (void ) +{ +int fd; + fd =open (dsa_dev_path,O_RDWR ); +if (fd <0 ) { +return -1 ; + } +close (fd); +return 0 ; +} +#endif +int main (int argc,char **argv) {bool has_kvm, has_tcg;
@@ -3939,6 +4007,16 @@ int main(int argc, char **argv) test_multifd_tcp_zero_page_legacy);migration_test_add ("/migration/multifd/tcp/plain/zero-page/none" , test_multifd_tcp_no_zero_page); + +#ifdef CONFIG_DSA_OPT +if (g_str_equal (arch,"x86_64" ) &&test_dsa_setup () ==0 ) { +migration_test_add ("/migration/multifd/tcp/plain/zero-page/dsa" , + test_multifd_tcp_zero_page_dsa); +migration_test_add ("/migration/multifd/tcp/plain/cancel/dsa" , + test_multifd_tcp_cancel_dsa); + } +#endif +migration_test_add ("/migration/multifd/tcp/plain/cancel" , test_multifd_tcp_cancel); migration_test_add("/migration/multifd/tcp/plain/zlib",
Signature · 1 line
Yichen Wang
Quoted 140 lines · Yichen Wang
v6
* Rebase on top of838fc0a8769d7cc6edfe50451ba4e3368395f5c1;
* Refactor code to have clean history on all commits;
* Add comments on DSA specific defines about how the value is picked;
* Address all comments from v5 reviews about api defines, questions, etc.;v5
* Rebase on top of39a032cea23e522268519d89bb738974bc43b6f6.
* 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 of85b597413d4370cb168f711192eaef2eb70535ac.
* 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 of7425b6277f12e82952cede1f531bfc689bf77fb1.
* Fix error/warning from checkpatch.pl
* Fix use-after-free bug when multifd-dsa-accel option is not set.
* Handle error fromdsa_initand correctly propogate the error.
* Remove unnecessary call todsa_stop.
* Detect availability of DSA feature at compile time.
* Implement a genericbatch_taskstructure and a DSA specific onedsa_batch_task.
* Remove allexit()calls and propagate errors correctly.
* Use bytes instead of page count to configure multifd-packet-size option.v2
* Rebase on top of3e01f1147a16ca566694b97eafc941d62fa1e8d8.
* Leave Juan's changes in their original form instead of squashing them.
* Add a new commit to refactor themultifd_send_threadfunction 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_enqcmdto 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 threaddsa_completionto 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_pausebetween 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
Quoted 4 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 size of the payload sent over the network.
I didn't find this option. Is it removed?
Quoted 50 lines
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_Xandlive_migrationthreads runtime. DSA offloading total runtime is calculated by adding up allmultifdsend_X,live_migrationanddsa_completionthreads 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 | |---------------|---------------|---------------|---------------|---------------|---------------|
Quoted 1 line
Total time is 8% faster and down time is 16% faster.
Is this average test results out of many, or one test?
I wonder how the total time and downtime stablizes even across runs.
Quoted 86 lines
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 (11):
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: 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.hmp-commands.hx | 2 +- include/qemu/dsa.h | 189 ++++++ meson.build | 14 + meson_options.txt | 2 + migration/migration-hmp-cmds.c | 26 +- migration/multifd-zero-page.c | 133 +++- migration/multifd-zlib.c | 6 +- migration/multifd-zstd.c | 6 +- migration/multifd.c | 19 +- migration/multifd.h | 5 + migration/options.c | 69 ++ 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 ++-
Quoted 8 lines
tests/unit/meson.build | 6 + tests/unit/test-dsa.c | 503 ++++++++++++++ util/dsa.c | 1114 +++++++++++++++++++++++++++++++ util/meson.build | 3 + 20 files changed, 2204 insertions(+), 29 deletions(-) create mode 100644 include/qemu/dsa.h create mode 100644 tests/unit/test-dsa.c create mode 100644 util/dsa.c
The doc update is still missing under docs/, we may need that for a final merge.
Are you using this in production? How it performs in real life? What is the major issue to solve for you? Is it "zero detect eats cpu too much", or "migration too slow", or "we're doing experiment with the new hardwares, and see how it goes if we apply it on top of migrations"?
There're a lot of new code added for dsa just for this optimization on zero page detection. We'd better understand the major benefits, and also whether that's applicable to other part of qemu or migration-only. I actually wonder if we're going to support enqcmd whether migration is the best starting point (rather than other places where we emulate tons of devices, and maybe some backends can speedup IOs with enqcmd in some form?).. but it's more of a pure question.
Thanks,
Signature · 1 line
Peter Xu
Quoted 8 lines · * Peter Xu ([email protected]) wrote:
The doc update is still missing under docs/, we may need that for a final merge.
Are you using this in production? How it performs in real life? What is the major issue to solve for you? Is it "zero detect eats cpu too much", or "migration too slow", or "we're doing experiment with the new hardwares, and see how it goes if we apply it on top of migrations"?
Quoted 7 lines
There're a lot of new code added for dsa just for this optimization on zero page detection. We'd better understand the major benefits, and also whether that's applicable to other part of qemu or migration-only. I actually wonder if we're going to support enqcmd whether migration is the best starting point (rather than other places where we emulate tons of devices, and maybe some backends can speedup IOs with enqcmd in some form?).. but it's more of a pure question.
The other thing that worries me here is that there's not much abstraction, I'm sure there's a whole bunch of offload cards that could do tricks like this; how do we avoid having this much extra code for each one?
Dave
Quoted 6 lines
Thanks,
Signature · 1 line
Peter Xu
Signature · 4 lines
-----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
Quoted 6 lines · Peter Xu
On Wed, Oct 09, 2024 at 04:45:58PM -0700, Yichen Wang wrote:
The doc update is still missing under docs/, we may need that for a final merge.
I will work with Intel to prepare a doc in my next patch.
Quoted 5 lines
Are you using this in production? How it performs in real life? What is the major issue to solve for you? Is it "zero detect eats cpu too much", or "migration too slow", or "we're doing experiment with the new hardwares, and see how it goes if we apply it on top of migrations"?
Yes, we do use it in production. Our codebase is based on an old QEMU release (5.X), so we backported the series there. The major use case is just to accelerate the live migration, and it is currently under QA scale testing. The main motivation is, we reserve 4 cores for all control plane services including QEMU. While doing 2nd-scheduling (i.e. live migration to reduce the fragmentations, and very commonly seen on cloud providers), we realize QEMU will eat a lot of CPUs which causes jitter and slowness on the control planes. Even though this is not happening too frequently, we still want it to be stable. With the help of DSA, it saves CPU while accelerates the process, so we want to use it in production.
Quoted 8 lines
There're a lot of new code added for dsa just for this optimization on zero page detection. We'd better understand the major benefits, and also whether that's applicable to other part of qemu or migration-only. I actually wonder if we're going to support enqcmd whether migration is the best starting point (rather than other places where we emulate tons of devices, and maybe some backends can speedup IOs with enqcmd in some form?).. but it's more of a pure question.
I tried to put most of the code in dsa.c and do minimum changes on all other files. Even in dsa.c, it has the abstraction for "submit task", and the implementation of "submit a buffer_zero task". I think this is the best I can think of. I am open to suggestions of how we can help to move this forward. :)
Quoted 5 lines
Thanks,
--
Peter Xu
Quoted 16 lines · Yichen Wang
Quoted 6 lines · Peter Xu
On Wed, Oct 09, 2024 at 04:45:58PM -0700, Yichen Wang wrote:
The doc update is still missing under docs/, we may need that for a final merge.
I will work with Intel to prepare a doc in my next patch.
Quoted 5 lines
Are you using this in production? How it performs in real life? What is the major issue to solve for you? Is it "zero detect eats cpu too much", or "migration too slow", or "we're doing experiment with the new hardwares, and see how it goes if we apply it on top of migrations"?
Quoted 11 lines
Yes, we do use it in production. Our codebase is based on an old QEMU release (5.X), so we backported the series there. The major use case is just to accelerate the live migration, and it is currently under QA scale testing. The main motivation is, we reserve 4 cores for all control plane services including QEMU. While doing 2nd-scheduling (i.e. live migration to reduce the fragmentations, and very commonly seen on cloud providers), we realize QEMU will eat a lot of CPUs which causes jitter and slowness on the control planes. Even though this is not happening too frequently, we still want it to be stable. With the help of DSA, it saves CPU while accelerates the process, so we want to use it in production.
Thanks. Please consider adding something like this (issues, why DSA help and how, etc.) into the doc file.
Quoted 10 lines
Quoted 9 lines
There're a lot of new code added for dsa just for this optimization on zero page detection. We'd better understand the major benefits, and also whether that's applicable to other part of qemu or migration-only. I actually wonder if we're going to support enqcmd whether migration is the best starting point (rather than other places where we emulate tons of devices, and maybe some backends can speedup IOs with enqcmd in some form?).. but it's more of a pure question.
Quoted 5 lines
I tried to put most of the code in
dsa.cand do minimum changes on all other files. Even indsa.c, it has the abstraction for "submit task", and the implementation of "submit abuffer_zerotask". I think this is the best I can think of. I am open to suggestions of how we can help to move this forward. :)
That's ok.
Though I think you ignored some of my question in the email on some parameter I never found myself in this series but got mentioned. If you plan to repost soon, please help make sure the patchset is properly tested (including builds), and the results are reflecting what was posted.
Thanks,
Signature · 1 line
Peter Xu
Quoted 281 lines · Yichen Wang
v6
* Rebase on top of838fc0a8769d7cc6edfe50451ba4e3368395f5c1;
* Refactor code to have clean history on all commits;
* Add comments on DSA specific defines about how the value is picked;
* Address all comments from v5 reviews about api defines, questions, etc.;v5
* Rebase on top of39a032cea23e522268519d89bb738974bc43b6f6.
* 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 of85b597413d4370cb168f711192eaef2eb70535ac.
* 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 of7425b6277f12e82952cede1f531bfc689bf77fb1.
* Fix error/warning from checkpatch.pl
* Fix use-after-free bug when multifd-dsa-accel option is not set.
* Handle error fromdsa_initand correctly propogate the error.
* Remove unnecessary call todsa_stop.
* Detect availability of DSA feature at compile time.
* Implement a genericbatch_taskstructure and a DSA specific onedsa_batch_task.
* Remove allexit()calls and propagate errors correctly.
* Use bytes instead of page count to configure multifd-packet-size option.v2
* Rebase on top of3e01f1147a16ca566694b97eafc941d62fa1e8d8.
* Leave Juan's changes in their original form instead of squashing them.
* Add a new commit to refactor themultifd_send_threadfunction 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_enqcmdto 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 threaddsa_completionto 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_pausebetween 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.0000We 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_Xandlive_migrationthreads runtime. DSA offloading total runtime is calculated by adding up allmultifdsend_X,live_migrationanddsa_completionthreads 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 (11):
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: 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.hmp-commands.hx | 2 +- include/qemu/dsa.h | 189 ++++++ meson.build | 14 + meson_options.txt | 2 + migration/migration-hmp-cmds.c | 26 +- migration/multifd-zero-page.c | 133 +++- migration/multifd-zlib.c | 6 +- migration/multifd-zstd.c | 6 +- migration/multifd.c | 19 +- migration/multifd.h | 5 + migration/options.c | 69 ++ 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 ++-
Quoted 8 lines
tests/unit/meson.build | 6 + tests/unit/test-dsa.c | 503 ++++++++++++++ util/dsa.c | 1114 +++++++++++++++++++++++++++++++ util/meson.build | 3 + 20 files changed, 2204 insertions(+), 29 deletions(-) create mode 100644 include/qemu/dsa.h create mode 100644 tests/unit/test-dsa.c create mode 100644 util/dsa.c
Still doesn't build without DSA:
qemu/include/qemu/dsa.h: In function ‘buffer_is_zero_dsa_batch_sync’:/home/fabiano/kvm/qemu/include/qemu/dsa.h:183:16: error: ‘errp’ undeclared (first use in this function); did you mean ‘errno’?
error_setg(errp, "DSA accelerator is not enabled.");
^
qemu/include/qapi/error.h:318:26: note: in definition of macro ‘error_setg’
error_setg_internal((errp), __FILE__, __LINE__, __func__, \
^~~~
qemu/include/qemu/dsa.h:183:16: note: each undeclared identifier is reported only once for each function it appears in
error_setg(errp, "DSA accelerator is not enabled.");
^
qemu/include/qapi/error.h:318:26: note: in definition of macro ‘error_setg’
error_setg_internal((errp), __FILE__, __LINE__, __func__, \
^~~~Quoted 11 lines · Fabiano Rosas
Yichen Wang <[email protected]> writes:
Still doesn't build without DSA:
qemu/include/qemu/dsa.h: In function ‘buffer_is_zero_dsa_batch_sync’:/home/fabiano/kvm/qemu/include/qemu/dsa.h:183:16: error: ‘errp’ undeclared (first use in this function); did you mean ‘errno’?
Quoted 11 lines
error_setg(errp, "DSA accelerator is not enabled.");
^
qemu/include/qapi/error.h:318:26: note: in definition of macro ‘error_setg’
error_setg_internal((errp), __FILE__, __LINE__, __func__, \
^~~~
qemu/include/qemu/dsa.h:183:16: note: each undeclared identifier is reported only once for each function it appears in
error_setg(errp, "DSA accelerator is not enabled.");
^
qemu/include/qapi/error.h:318:26: note: in definition of macro ‘error_setg’
error_setg_internal((errp), __FILE__, __LINE__, __func__, \
^~~~Sorry for that, I will make sure I test both for my last version before git send-mail...