* [PATCH 0/7] Live migration acceleration with UADK
@ 2024-05-29 9:44 Shameer Kolothum via
2024-05-29 9:44 ` [PATCH 1/7] docs/migration: add uadk compression feature Shameer Kolothum via
` (7 more replies)
0 siblings, 8 replies; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Hi,
This series adds support for UADK library based hardware acceleration
for live migration. UADK[0] is a general-purpose user space accelerator
framework that uses shared virtual addressing (SVA) to provide a unified
programming interface for hardware acceleration of cryptographic and
compression algorithms.
UADK makes use of the UACCE(Unified/User-space-access-intended Accelerator
Framework) Linux kernel module which enables hardware accelerators from
different vendors that support SVA to adapt to UADK. Linux kernel from
v5.9 has support for UACCE and SVA on ARM64 platforms.
Currently, HiSilicon Kunpeng hardware accelerators have been registered with
UACCE and the Zip accelerator on these platforms can be used for compression
which can free up CPU computing power and improve computing performance.
This series is on top of Intel IAA accelerator live migration support
series[1] from Yuan Liu. Many thanks for doing this.
Initial tests were carried out on HiSilicon D06 platforms and the results
are as below:
Test setup: HiSilicon D06 boards connected over a 1Gbps n/w.
Host Kernel: Host Kernel: 6.7.0 Mainline Kernel.
Guest VM: 64 cpus, 16GB mem, hugepages, prealloc=on (80% Memory filled
with random data)
+--------+-------------+--------+--------+----------+------+
| | The number |total |downtime|pages per | CPU |
| None | of channels |time(ms)|(ms) |second | Util |
| Comp | | | | | |
| +-------------+-----------------+----------+------+
|Network | 2| 114536| 79| 32849 | 18%|
|BW: 1G +-------------+--------+--------+----------+------+
| | 4| 114327| 78| 34217 | 22%|
| +-------------+--------+--------+----------+------+
| | 8| 114231| 107| 211840 | 24%|
+--------+-------------+--------+--------+----------+------+
+--------+-------------+--------+--------+----------+------+
| | The number |total |downtime|pages per | CPU |
| UADK | of channels |time(ms)|(ms) |second | Util |
| Comp | | | | | |
| +-------------+-----------------+----------+------+
|Network | 2| 77192 | 75| 182679 | 24%|
|BW: 1G +-------------+--------+--------+----------+------+
| | 4| 77000 | 86| 185600 | 25%|
| +-------------+--------+--------+----------+------+
| | 8| 76835 | 97| 330966 | 27%|
+--------+-------------+--------+--------+----------+------+
+--------+-------------+--------+--------+----------+------+
| | The number |total |downtime|pages per | CPU |
| ZLIB | of channels |time(ms)|(ms) |second | Util |
| Comp | | | | | |
| +-------------+-----------------+----------+------+
|Network | 2| 134664| 73| 42666 | 200%|
|BW: 1G +-------------+--------+--------+----------+------+
| | 4| 71550 | 72| 181227 | 390%|
| +-------------+--------+--------+----------+------+
| | 8| 67781 | 108| 200960 | 460%|
+--------+-------------+--------+--------+----------+------+
+--------+-------------+--------+--------+----------+------+
| | The number |total |downtime|pages per | CPU |
| ZSTD | of channels |time(ms)|(ms) |second | Util |
| Comp | | | | | |
| +-------------+-----------------+----------+------+
|Network | 2| 67822 | 73| 202772 | 160%|
|BW: 1G +-------------+--------+--------+----------+------+
| | 4| 67460 | 107| 198400 | 180%|
| +-------------+--------+--------+----------+------+
| | 8| 67422 | 83 | 349808 | 215%|
+--------+-------------+--------+--------+----------+------+
From the above results, UADK has considerable CPU cycle savings
compared to both Zlib/Zstd. Also compared with Qemu
"multifd-compression none" mode UADK has an edge on migration
"total time".
Please take a look and let me know your feedback.
Thanks,
Shameer
[0] https://github.com/Linaro/uadk/tree/master/docs
[1] https://lore.kernel.org/qemu-devel/20240505165751.2392198-1-yuan1.liu@intel.com/
Shameer Kolothum (7):
docs/migration: add uadk compression feature
configure: Add uadk option
migration/multifd: add uadk compression framework
migration/multifd: Add UADK initialization
migration/multifd: Add UADK based compression and decompression
migration/multifd: Switch to no compression when no hardware support
tests/migration-test: add uadk compression test
docs/devel/migration/uadk-compression.rst | 144 +++++++++
hw/core/qdev-properties-system.c | 2 +-
meson.build | 14 +
meson_options.txt | 2 +
migration/meson.build | 1 +
migration/multifd-uadk.c | 368 ++++++++++++++++++++++
migration/multifd.h | 5 +-
qapi/migration.json | 5 +-
scripts/meson-buildoptions.sh | 3 +
tests/qtest/migration-test.c | 23 ++
10 files changed, 563 insertions(+), 4 deletions(-)
create mode 100644 docs/devel/migration/uadk-compression.rst
create mode 100644 migration/multifd-uadk.c
--
2.17.1
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 1/7] docs/migration: add uadk compression feature
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-05-30 13:25 ` Liu, Yuan1
2024-06-05 18:59 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 2/7] configure: Add uadk option Shameer Kolothum via
` (6 subsequent siblings)
7 siblings, 2 replies; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Document UADK(User Space Accelerator Development Kit) library details
and how to use that for migration.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
docs/devel/migration/uadk-compression.rst | 144 ++++++++++++++++++++++
1 file changed, 144 insertions(+)
create mode 100644 docs/devel/migration/uadk-compression.rst
diff --git a/docs/devel/migration/uadk-compression.rst b/docs/devel/migration/uadk-compression.rst
new file mode 100644
index 0000000000..988b92631e
--- /dev/null
+++ b/docs/devel/migration/uadk-compression.rst
@@ -0,0 +1,144 @@
+=========================================================
+User Space Accelerator Development Kit (UADK) Compression
+=========================================================
+UADK is a general-purpose user space accelerator framework that uses shared
+virtual addressing (SVA) to provide a unified programming interface for
+hardware acceleration of cryptographic and compression algorithms.
+
+UADK includes Unified/User-space-access-intended Accelerator Framework (UACCE),
+which enables hardware accelerators from different vendors that support SVA to
+adapt to UADK.
+
+Currently, HiSilicon Kunpeng hardware accelerators have been registered with
+UACCE. Through the UADK framework, users can run cryptographic and compression
+algorithms using hardware accelerators instead of CPUs, freeing up CPU
+computing power and improving computing performance.
+
+https://github.com/Linaro/uadk/tree/master/docs
+
+UADK Framework
+==============
+UADK consists of UACCE, vendors' drivers, and an algorithm layer. UADK requires
+the hardware accelerator to support SVA, and the operating system to support
+IOMMU and SVA. Hardware accelerators from different vendors are registered as
+different character devices with UACCE by using kernel-mode drivers of the
+vendors. A user can access the hardware accelerators by performing user-mode
+operations on the character devices.
+
+::
+
+ +----------------------------------+
+ | apps |
+ +----+------------------------+----+
+ | |
+ | |
+ +-------+--------+ +-------+-------+
+ | scheduler | | alg libraries |
+ +-------+--------+ +-------+-------+
+ | |
+ | |
+ | |
+ | +--------+------+
+ | | vendor drivers|
+ | +-+-------------+
+ | |
+ | |
+ +--+------------------+--+
+ | libwd |
+ User +----+-------------+-----+
+ --------------------------------------------------
+ Kernel +--+-----+ +------+
+ | uacce | | smmu |
+ +---+----+ +------+
+ |
+ +---+------------------+
+ | vendor kernel driver |
+ +----------------------+
+ --------------------------------------------------
+ +----------------------+
+ | HW Accelerators |
+ +----------------------+
+
+UADK Installation
+-----------------
+Build UADK
+^^^^^^^^^^
+
+.. code-block:: shell
+
+ git clone https://github.com/Linaro/uadk.git
+ cd uadk
+ mkdir build
+ ./autogen.sh
+ ./configure --prefix=$PWD/build
+ make
+ make install
+
+Without --prefix, UADK will be installed to /usr/local/lib by default.
+If get error:"cannot find -lnuma", please install the libnuma-dev
+
+Run pkg-config libwd to ensure env is setup correctly
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+* export PKG_CONFIG_PATH=$PWD/build/lib/pkgconfig
+* pkg-config libwd --cflags --libs
+ -I/usr/local/include -L/usr/local/lib -lwd
+
+* export PKG_CONFIG_PATH is required on demand.
+ Not required if UADK is installed to /usr/local/lib
+
+UADK Host Kernel Requirements
+-----------------------------
+User needs to make sure that ``UACCE`` is already supported in Linux kernel.
+The kernel version should be at least v5.9 with SVA (Shared Virtual
+Addressing) enabled.
+
+Kernel Configuration
+^^^^^^^^^^^^^^^^^^^^
+
+``UACCE`` could be built as module or built-in.
+
+Here's an example to enable UACCE with hardware accelerator in HiSilicon
+Kunpeng platform.
+
+* CONFIG_IOMMU_SVA_LIB=y
+* CONFIG_ARM_SMMU=y
+* CONFIG_ARM_SMMU_V3=y
+* CONFIG_ARM_SMMU_V3_SVA=y
+* CONFIG_PCI_PASID=y
+* CONFIG_UACCE=y
+* CONFIG_CRYPTO_DEV_HISI_QM=y
+* CONFIG_CRYPTO_DEV_HISI_ZIP=y
+
+Make sure all these above kernel configurations are selected.
+
+Accelerator dev node permissions
+--------------------------------
+Harware accelerators(eg: HiSilicon Kunpeng Zip accelerator) gets registered to
+UADK and char devices are created in dev directory. In order to access resources
+on hardware accelerator devices, write permission should be provided to user.
+
+.. code-block:: shell
+
+ $ sudo chmod 777 /dev/hisi_zip-*
+
+How To Use UADK Compression In Qemu Migration
+---------------------------------------------
+* Make sure UADK is installed as above
+* Build ``Qemu`` with ``--enable-uadk`` parameter
+
+ E.g. configure --target-list=aarch64-softmmu --enable-kvm ``--enable-uadk``
+
+* Enable ``UADK`` compression during migration
+
+ Set ``migrate_set_parameter multifd-compression uadk``
+
+Since UADK uses Shared Virtual Addressing(SVA) and device access virtual memory
+directly it is possible that SMMUv3 may enounter page faults while walking the
+IO page tables. This may impact the performance. In order to mitigate this,
+please make sure to specify ``-mem-prealloc`` parameter to the destination VM
+boot parameters.
+
+Though both UADK and ZLIB are based on the deflate compression algorithm, UADK
+is not fully compatible with ZLIB. Hence, please make sure to use ``uadk`` on
+both source and destination during migration.
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 2/7] configure: Add uadk option
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
2024-05-29 9:44 ` [PATCH 1/7] docs/migration: add uadk compression feature Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-06-04 21:25 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 3/7] migration/multifd: add uadk compression framework Shameer Kolothum via
` (5 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Add --enable-uadk and --disable-uadk options to enable and disable
UADK compression accelerator. This is for using UADK based hardware
accelerators for live migration.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
meson.build | 14 ++++++++++++++
meson_options.txt | 2 ++
scripts/meson-buildoptions.sh | 3 +++
3 files changed, 19 insertions(+)
diff --git a/meson.build b/meson.build
index 2a8d8385fe..f4ed29d876 100644
--- a/meson.build
+++ b/meson.build
@@ -1210,6 +1210,18 @@ if not get_option('qpl').auto() or have_system
required: get_option('qpl'),
method: 'pkg-config')
endif
+uadk = not_found
+if not get_option('uadk').auto() or have_system
+ libwd = dependency('libwd', version: '>=2.6',
+ required: get_option('uadk'),
+ method: 'pkg-config')
+ libwd_comp = dependency('libwd_comp', version: '>=2.6',
+ required: get_option('uadk'),
+ method: 'pkg-config')
+ if libwd.found() and libwd_comp.found()
+ uadk = declare_dependency(dependencies: [libwd, libwd_comp])
+ endif
+endif
virgl = not_found
have_vhost_user_gpu = have_tools and host_os == 'linux' and pixman.found()
@@ -2316,6 +2328,7 @@ config_host_data.set('CONFIG_STATX', has_statx)
config_host_data.set('CONFIG_STATX_MNT_ID', has_statx_mnt_id)
config_host_data.set('CONFIG_ZSTD', zstd.found())
config_host_data.set('CONFIG_QPL', qpl.found())
+config_host_data.set('CONFIG_UADK', uadk.found())
config_host_data.set('CONFIG_FUSE', fuse.found())
config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found())
config_host_data.set('CONFIG_SPICE_PROTOCOL', spice_protocol.found())
@@ -4444,6 +4457,7 @@ summary_info += {'bzip2 support': libbzip2}
summary_info += {'lzfse support': liblzfse}
summary_info += {'zstd support': zstd}
summary_info += {'Query Processing Library support': qpl}
+summary_info += {'UADK Library support': uadk}
summary_info += {'NUMA host support': numa}
summary_info += {'capstone': capstone}
summary_info += {'libpmem support': libpmem}
diff --git a/meson_options.txt b/meson_options.txt
index 562db29ab4..d327eba593 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -261,6 +261,8 @@ option('zstd', type : 'feature', value : 'auto',
description: 'zstd compression support')
option('qpl', type : 'feature', value : 'auto',
description: 'Query Processing Library support')
+option('uadk', type : 'feature', value : 'auto',
+ description: 'UADK Library support')
option('fuse', type: 'feature', value: 'auto',
description: 'FUSE block device export')
option('fuse_lseek', type : 'feature', value : 'auto',
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 26bf9e21fd..4aea75e9a5 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -223,6 +223,7 @@ meson_options_help() {
printf "%s\n" ' xkbcommon xkbcommon support'
printf "%s\n" ' zstd zstd compression support'
printf "%s\n" ' qpl Query Processing Library support'
+ printf "%s\n" ' uadk UADK Library support'
}
_meson_option_parse() {
case $1 in
@@ -565,6 +566,8 @@ _meson_option_parse() {
--disable-zstd) printf "%s" -Dzstd=disabled ;;
--enable-qpl) printf "%s" -Dqpl=enabled ;;
--disable-qpl) printf "%s" -Dqpl=disabled ;;
+ --enable-uadk) printf "%s" -Duadk=enabled ;;
+ --disable-uadk) printf "%s" -Duadk=disabled ;;
*) return 1 ;;
esac
}
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 3/7] migration/multifd: add uadk compression framework
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
2024-05-29 9:44 ` [PATCH 1/7] docs/migration: add uadk compression feature Shameer Kolothum via
2024-05-29 9:44 ` [PATCH 2/7] configure: Add uadk option Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-05-29 11:10 ` Markus Armbruster
2024-06-04 21:24 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 4/7] migration/multifd: Add UADK initialization Shameer Kolothum via
` (4 subsequent siblings)
7 siblings, 2 replies; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Adds the skeleton to support uadk compression method.
Complete functionality will be added in subsequent patches.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
hw/core/qdev-properties-system.c | 2 +-
migration/meson.build | 1 +
migration/multifd-uadk.c | 20 ++++++++++++++++++++
migration/multifd.h | 5 +++--
qapi/migration.json | 5 ++++-
5 files changed, 29 insertions(+), 4 deletions(-)
create mode 100644 migration/multifd-uadk.c
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 6ccd7224f6..f13350b4fb 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -659,7 +659,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {
const PropertyInfo qdev_prop_multifd_compression = {
.name = "MultiFDCompression",
.description = "multifd_compression values, "
- "none/zlib/zstd/qpl",
+ "none/zlib/zstd/qpl/uadk",
.enum_table = &MultiFDCompression_lookup,
.get = qdev_propinfo_get_enum,
.set = qdev_propinfo_set_enum,
diff --git a/migration/meson.build b/migration/meson.build
index 1d432d5328..ed687ae286 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -44,6 +44,7 @@ if get_option('live_block_migration').allowed()
endif
system_ss.add(when: zstd, if_true: files('multifd-zstd.c'))
system_ss.add(when: qpl, if_true: files('multifd-qpl.c'))
+system_ss.add(when: uadk, if_true: files('multifd-uadk.c'))
specific_ss.add(when: 'CONFIG_SYSTEM_ONLY',
if_true: files('ram.c',
diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
new file mode 100644
index 0000000000..c2bb07535b
--- /dev/null
+++ b/migration/multifd-uadk.c
@@ -0,0 +1,20 @@
+/*
+ * Multifd UADK compression accelerator implementation
+ *
+ * Copyright (c) 2024 Huawei Technologies R & D (UK) Ltd
+ *
+ * Authors:
+ * Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
+ *
+ * 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 "qemu/module.h"
+
+static void multifd_uadk_register(void)
+{
+ /* noop for now */
+}
+migration_init(multifd_uadk_register);
diff --git a/migration/multifd.h b/migration/multifd.h
index 5b7d9b15f8..0ecd6f47d7 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -34,13 +34,14 @@ MultiFDRecvData *multifd_get_recv_data(void);
/* Multifd Compression flags */
#define MULTIFD_FLAG_SYNC (1 << 0)
-/* We reserve 3 bits for compression methods */
-#define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
+/* We reserve 4 bits for compression methods */
+#define MULTIFD_FLAG_COMPRESSION_MASK (0xf << 1)
/* we need to be compatible. Before compression value was 0 */
#define MULTIFD_FLAG_NOCOMP (0 << 1)
#define MULTIFD_FLAG_ZLIB (1 << 1)
#define MULTIFD_FLAG_ZSTD (2 << 1)
#define MULTIFD_FLAG_QPL (4 << 1)
+#define MULTIFD_FLAG_UADK (8 << 1)
/* This value needs to be a multiple of qemu_target_page_size() */
#define MULTIFD_PACKET_SIZE (512 * 1024)
diff --git a/qapi/migration.json b/qapi/migration.json
index 854e8609bd..0eaea9b0c3 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -632,12 +632,15 @@
# the deflate compression algorithm and use the Intel In-Memory Analytics
# Accelerator(IAA) accelerated compression and decompression. (Since 9.1)
#
+# @uadk: use UADK library compression method. (Since 9.1)
+#
# Since: 5.0
##
{ 'enum': 'MultiFDCompression',
'data': [ 'none', 'zlib',
{ 'name': 'zstd', 'if': 'CONFIG_ZSTD' },
- { 'name': 'qpl', 'if': 'CONFIG_QPL' } ] }
+ { 'name': 'qpl', 'if': 'CONFIG_QPL' },
+ { 'name': 'uadk', 'if': 'CONFIG_UADK' } ] }
##
# @MigMode:
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 4/7] migration/multifd: Add UADK initialization
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
` (2 preceding siblings ...)
2024-05-29 9:44 ` [PATCH 3/7] migration/multifd: add uadk compression framework Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-06-05 14:58 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 5/7] migration/multifd: Add UADK based compression and decompression Shameer Kolothum via
` (3 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Initialize UADK session and allocate buffers required. The actual
compression/decompression will only be done in a subsequent patch.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
migration/multifd-uadk.c | 207 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 206 insertions(+), 1 deletion(-)
diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
index c2bb07535b..3172e4d5ca 100644
--- a/migration/multifd-uadk.c
+++ b/migration/multifd-uadk.c
@@ -12,9 +12,214 @@
#include "qemu/osdep.h"
#include "qemu/module.h"
+#include "qapi/error.h"
+#include "migration.h"
+#include "multifd.h"
+#include "options.h"
+#include "uadk/wd_comp.h"
+#include "uadk/wd_sched.h"
+
+struct wd_data {
+ handle_t handle;
+ uint8_t *buf;
+ uint32_t *buf_hdr;
+};
+
+static bool uadk_hw_initialised(void)
+{
+ char alg[] = "zlib";
+ int ret;
+
+ ret = wd_comp_init2(alg, SCHED_POLICY_RR, TASK_HW);
+ if (ret && ret != -WD_EEXIST) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+static struct wd_data *multifd_uadk_init_sess(uint32_t count,
+ uint32_t page_size,
+ bool compress, Error **errp)
+{
+ struct wd_comp_sess_setup ss = {0};
+ struct sched_params param = {0};
+ uint32_t size = count * page_size;
+ struct wd_data *wd;
+
+ if (!uadk_hw_initialised()) {
+ error_setg(errp, "multifd: UADK hardware not available");
+ return NULL;
+ }
+
+ wd = g_new0(struct wd_data, 1);
+ ss.alg_type = WD_ZLIB;
+ if (compress) {
+ ss.op_type = WD_DIR_COMPRESS;
+ /* Add an additional page for handling output > input */
+ size += page_size;
+ } else {
+ ss.op_type = WD_DIR_DECOMPRESS;
+ }
+ param.type = ss.op_type;
+ ss.sched_param = ¶m;
+
+ wd->handle = wd_comp_alloc_sess(&ss);
+ if (!wd->handle) {
+ error_setg(errp, "multifd: failed wd_comp_alloc_sess");
+ goto out;
+ }
+
+ wd->buf = g_try_malloc(size);
+ if (!wd->buf) {
+ error_setg(errp, "multifd: out of mem for uadk buf");
+ goto out_free_sess;
+ }
+ wd->buf_hdr = g_new0(uint32_t, count);
+ return wd;
+
+out_free_sess:
+ wd_comp_free_sess(wd->handle);
+out:
+ wd_comp_uninit2();
+ g_free(wd);
+ return NULL;
+}
+
+static void multifd_uadk_uninit_sess(struct wd_data *wd)
+{
+ wd_comp_free_sess(wd->handle);
+ wd_comp_uninit2();
+ g_free(wd->buf);
+ g_free(wd->buf_hdr);
+ g_free(wd);
+}
+
+/**
+ * multifd_uadk_send_setup: setup send side
+ *
+ * Returns 0 for success or -1 for error
+ *
+ * @p: Params for the channel that we are using
+ * @errp: pointer to an error
+ */
+static int multifd_uadk_send_setup(MultiFDSendParams *p, Error **errp)
+{
+ struct wd_data *wd;
+
+ wd = multifd_uadk_init_sess(p->page_count, p->page_size, true, errp);
+ if (!wd) {
+ return -1;
+ }
+
+ p->compress_data = wd;
+ assert(p->iov == NULL);
+ /*
+ * Each page will be compressed independently and sent using an IOV. The
+ * additional two IOVs are used to store packet header and compressed data
+ * length
+ */
+
+ p->iov = g_new0(struct iovec, p->page_count + 2);
+ return 0;
+}
+
+/**
+ * multifd_uadk_send_cleanup: cleanup send side
+ *
+ * Close the channel and return memory.
+ *
+ * @p: Params for the channel that we are using
+ * @errp: pointer to an error
+ */
+static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
+{
+ struct wd_data *wd = p->compress_data;
+
+ multifd_uadk_uninit_sess(wd);
+ p->compress_data = NULL;
+}
+
+/**
+ * multifd_uadk_send_prepare: prepare data to be able to send
+ *
+ * Create a compressed buffer with all the pages that we are going to
+ * send.
+ *
+ * Returns 0 for success or -1 for error
+ *
+ * @p: Params for the channel that we are using
+ * @errp: pointer to an error
+ */
+static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error **errp)
+{
+ return -1;
+}
+
+/**
+ * multifd_uadk_recv_setup: setup receive side
+ *
+ * Create the compressed channel and buffer.
+ *
+ * Returns 0 for success or -1 for error
+ *
+ * @p: Params for the channel that we are using
+ * @errp: pointer to an error
+ */
+static int multifd_uadk_recv_setup(MultiFDRecvParams *p, Error **errp)
+{
+ struct wd_data *wd;
+
+ wd = multifd_uadk_init_sess(p->page_count, p->page_size, false, errp);
+ if (!wd) {
+ return -1;
+ }
+ p->compress_data = wd;
+ return 0;
+}
+
+/**
+ * multifd_uadk_recv_cleanup: setup receive side
+ *
+ * For no compression this function does nothing.
+ *
+ * @p: Params for the channel that we are using
+ */
+static void multifd_uadk_recv_cleanup(MultiFDRecvParams *p)
+{
+ struct wd_data *wd = p->compress_data;
+
+ multifd_uadk_uninit_sess(wd);
+ p->compress_data = NULL;
+}
+
+/**
+ * multifd_uadk_recv: read the data from the channel into actual pages
+ *
+ * Read the compressed buffer, and uncompress it into the actual
+ * pages.
+ *
+ * Returns 0 for success or -1 for error
+ *
+ * @p: Params for the channel that we are using
+ * @errp: pointer to an error
+ */
+static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
+{
+ return -1;
+}
+
+static MultiFDMethods multifd_uadk_ops = {
+ .send_setup = multifd_uadk_send_setup,
+ .send_cleanup = multifd_uadk_send_cleanup,
+ .send_prepare = multifd_uadk_send_prepare,
+ .recv_setup = multifd_uadk_recv_setup,
+ .recv_cleanup = multifd_uadk_recv_cleanup,
+ .recv = multifd_uadk_recv,
+};
static void multifd_uadk_register(void)
{
- /* noop for now */
+ multifd_register_ops(MULTIFD_COMPRESSION_UADK, &multifd_uadk_ops);
}
migration_init(multifd_uadk_register);
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 5/7] migration/multifd: Add UADK based compression and decompression
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
` (3 preceding siblings ...)
2024-05-29 9:44 ` [PATCH 4/7] migration/multifd: Add UADK initialization Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-06-05 18:57 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 6/7] migration/multifd: Switch to no compression when no hardware support Shameer Kolothum via
` (2 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Uses UADK wd_do_comp_sync() API to (de)compress a normal page using
hardware accelerator.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
migration/multifd-uadk.c | 132 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 130 insertions(+), 2 deletions(-)
diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
index 3172e4d5ca..3329819bd4 100644
--- a/migration/multifd-uadk.c
+++ b/migration/multifd-uadk.c
@@ -13,6 +13,7 @@
#include "qemu/osdep.h"
#include "qemu/module.h"
#include "qapi/error.h"
+#include "exec/ramblock.h"
#include "migration.h"
#include "multifd.h"
#include "options.h"
@@ -140,6 +141,15 @@ static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
p->compress_data = NULL;
}
+static inline void prepare_next_iov(MultiFDSendParams *p, void *base,
+ uint32_t len)
+{
+ p->iov[p->iovs_num].iov_base = (uint8_t *)base;
+ p->iov[p->iovs_num].iov_len = len;
+ p->next_packet_size += len;
+ p->iovs_num++;
+}
+
/**
* multifd_uadk_send_prepare: prepare data to be able to send
*
@@ -153,7 +163,56 @@ static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
*/
static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error **errp)
{
- return -1;
+ struct wd_data *uadk_data = p->compress_data;
+ uint32_t hdr_size;
+ uint8_t *buf = uadk_data->buf;
+ int ret = 0;
+
+ if (!multifd_send_prepare_common(p)) {
+ goto out;
+ }
+
+ hdr_size = p->pages->normal_num * sizeof(uint32_t);
+ /* prepare the header that stores the lengths of all compressed data */
+ prepare_next_iov(p, uadk_data->buf_hdr, hdr_size);
+
+ for (int i = 0; i < p->pages->normal_num; i++) {
+ struct wd_comp_req creq = {
+ .op_type = WD_DIR_COMPRESS,
+ .src = p->pages->block->host + p->pages->offset[i],
+ .src_len = p->page_size,
+ .dst = buf,
+ /* Set dst_len to double the src to take care of -ve compression */
+ .dst_len = p->page_size * 2,
+ };
+
+ ret = wd_do_comp_sync(uadk_data->handle, &creq);
+ if (ret || creq.status) {
+ error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
+ p->id, ret, creq.status);
+ return -1;
+ }
+ if (creq.dst_len < p->page_size) {
+ uadk_data->buf_hdr[i] = cpu_to_be32(creq.dst_len);
+ prepare_next_iov(p, buf, creq.dst_len);
+ buf += creq.dst_len;
+ } else {
+ /*
+ * Send raw data if compressed out >= page_size. We might be better
+ * off sending raw data if output is slightly less than page_size
+ * as well because at the receive end we can skip the decompression.
+ * But it is tricky to find the right number here.
+ */
+ uadk_data->buf_hdr[i] = cpu_to_be32(p->page_size);
+ prepare_next_iov(p, p->pages->block->host + p->pages->offset[i],
+ p->page_size);
+ buf += p->page_size;
+ }
+ }
+out:
+ p->flags |= MULTIFD_FLAG_UADK;
+ multifd_send_fill_packet(p);
+ return 0;
}
/**
@@ -206,7 +265,76 @@ static void multifd_uadk_recv_cleanup(MultiFDRecvParams *p)
*/
static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
{
- return -1;
+ struct wd_data *uadk_data = p->compress_data;
+ uint32_t in_size = p->next_packet_size;
+ uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
+ uint32_t hdr_len = p->normal_num * sizeof(uint32_t);
+ uint32_t data_len = 0;
+ uint8_t *buf = uadk_data->buf;
+ int ret = 0;
+
+ if (flags != MULTIFD_FLAG_UADK) {
+ error_setg(errp, "multifd %u: flags received %x flags expected %x",
+ p->id, flags, MULTIFD_FLAG_ZLIB);
+ return -1;
+ }
+
+ multifd_recv_zero_page_process(p);
+ if (!p->normal_num) {
+ assert(in_size == 0);
+ return 0;
+ }
+
+ /* read compressed data lengths */
+ assert(hdr_len < in_size);
+ ret = qio_channel_read_all(p->c, (void *) uadk_data->buf_hdr,
+ hdr_len, errp);
+ if (ret != 0) {
+ return ret;
+ }
+
+ for (int i = 0; i < p->normal_num; i++) {
+ uadk_data->buf_hdr[i] = be32_to_cpu(uadk_data->buf_hdr[i]);
+ data_len += uadk_data->buf_hdr[i];
+ assert(uadk_data->buf_hdr[i] <= p->page_size);
+ }
+
+ /* read compressed data */
+ assert(in_size == hdr_len + data_len);
+ ret = qio_channel_read_all(p->c, (void *)buf, data_len, errp);
+ if (ret != 0) {
+ return ret;
+ }
+
+ for (int i = 0; i < p->normal_num; i++) {
+ struct wd_comp_req creq = {
+ .op_type = WD_DIR_DECOMPRESS,
+ .src = buf,
+ .src_len = uadk_data->buf_hdr[i],
+ .dst = p->host + p->normal[i],
+ .dst_len = p->page_size,
+ };
+
+ if (uadk_data->buf_hdr[i] == p->page_size) {
+ memcpy(p->host + p->normal[i], buf, p->page_size);
+ buf += p->page_size;
+ continue;
+ }
+
+ ret = wd_do_comp_sync(uadk_data->handle, &creq);
+ if (ret || creq.status) {
+ error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
+ p->id, ret, creq.status);
+ return -1;
+ }
+ if (creq.dst_len != p->page_size) {
+ error_setg(errp, "multifd %u: decompressed length error", p->id);
+ return -1;
+ }
+ buf += uadk_data->buf_hdr[i];
+ }
+
+ return 0;
}
static MultiFDMethods multifd_uadk_ops = {
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 6/7] migration/multifd: Switch to no compression when no hardware support
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
` (4 preceding siblings ...)
2024-05-29 9:44 ` [PATCH 5/7] migration/multifd: Add UADK based compression and decompression Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-06-05 19:08 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 7/7] tests/migration-test: add uadk compression test Shameer Kolothum via
2024-06-04 20:59 ` [PATCH 0/7] Live migration acceleration with UADK Peter Xu
7 siblings, 1 reply; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Send raw packets over if UADK hardware support is not available. This is to
satisfy Qemu qtest CI which may run on platforms that don't have UADK
hardware support. Subsequent patch will add support for uadk migration
qtest.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
migration/multifd-uadk.c | 89 +++++++++++++++++++++++-----------------
1 file changed, 52 insertions(+), 37 deletions(-)
diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
index 3329819bd4..9325c6a2b3 100644
--- a/migration/multifd-uadk.c
+++ b/migration/multifd-uadk.c
@@ -17,6 +17,7 @@
#include "migration.h"
#include "multifd.h"
#include "options.h"
+#include "qemu/error-report.h"
#include "uadk/wd_comp.h"
#include "uadk/wd_sched.h"
@@ -48,27 +49,28 @@ static struct wd_data *multifd_uadk_init_sess(uint32_t count,
uint32_t size = count * page_size;
struct wd_data *wd;
- if (!uadk_hw_initialised()) {
- error_setg(errp, "multifd: UADK hardware not available");
- return NULL;
- }
-
wd = g_new0(struct wd_data, 1);
- ss.alg_type = WD_ZLIB;
- if (compress) {
- ss.op_type = WD_DIR_COMPRESS;
- /* Add an additional page for handling output > input */
- size += page_size;
- } else {
- ss.op_type = WD_DIR_DECOMPRESS;
- }
- param.type = ss.op_type;
- ss.sched_param = ¶m;
- wd->handle = wd_comp_alloc_sess(&ss);
- if (!wd->handle) {
- error_setg(errp, "multifd: failed wd_comp_alloc_sess");
- goto out;
+ if (uadk_hw_initialised()) {
+ ss.alg_type = WD_ZLIB;
+ if (compress) {
+ ss.op_type = WD_DIR_COMPRESS;
+ /* Add an additional page for handling output > input */
+ size += page_size;
+ } else {
+ ss.op_type = WD_DIR_DECOMPRESS;
+ }
+ param.type = ss.op_type;
+ ss.sched_param = ¶m;
+
+ wd->handle = wd_comp_alloc_sess(&ss);
+ if (!wd->handle) {
+ error_setg(errp, "multifd: failed wd_comp_alloc_sess");
+ goto out;
+ }
+ } else {
+ /* For CI test use */
+ warn_report_once("UADK hardware not available. Switch to no compression mode");
}
wd->buf = g_try_malloc(size);
@@ -80,7 +82,9 @@ static struct wd_data *multifd_uadk_init_sess(uint32_t count,
return wd;
out_free_sess:
- wd_comp_free_sess(wd->handle);
+ if (wd->handle) {
+ wd_comp_free_sess(wd->handle);
+ }
out:
wd_comp_uninit2();
g_free(wd);
@@ -89,7 +93,9 @@ out:
static void multifd_uadk_uninit_sess(struct wd_data *wd)
{
- wd_comp_free_sess(wd->handle);
+ if (wd->handle) {
+ wd_comp_free_sess(wd->handle);
+ }
wd_comp_uninit2();
g_free(wd->buf);
g_free(wd->buf_hdr);
@@ -186,23 +192,26 @@ static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error **errp)
.dst_len = p->page_size * 2,
};
- ret = wd_do_comp_sync(uadk_data->handle, &creq);
- if (ret || creq.status) {
- error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
- p->id, ret, creq.status);
- return -1;
+ if (uadk_data->handle) {
+ ret = wd_do_comp_sync(uadk_data->handle, &creq);
+ if (ret || creq.status) {
+ error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
+ p->id, ret, creq.status);
+ return -1;
+ }
+ if (creq.dst_len < p->page_size) {
+ uadk_data->buf_hdr[i] = cpu_to_be32(creq.dst_len);
+ prepare_next_iov(p, buf, creq.dst_len);
+ buf += creq.dst_len;
+ }
}
- if (creq.dst_len < p->page_size) {
- uadk_data->buf_hdr[i] = cpu_to_be32(creq.dst_len);
- prepare_next_iov(p, buf, creq.dst_len);
- buf += creq.dst_len;
- } else {
- /*
- * Send raw data if compressed out >= page_size. We might be better
- * off sending raw data if output is slightly less than page_size
- * as well because at the receive end we can skip the decompression.
- * But it is tricky to find the right number here.
- */
+ /*
+ * Send raw data if no UADK hardware or if compressed out >= page_size.
+ * We might be better off sending raw data if output is slightly less
+ * than page_size as well because at the receive end we can skip the
+ * decompression. But it is tricky to find the right number here.
+ */
+ if (!uadk_data->handle || creq.dst_len >= p->page_size) {
uadk_data->buf_hdr[i] = cpu_to_be32(p->page_size);
prepare_next_iov(p, p->pages->block->host + p->pages->offset[i],
p->page_size);
@@ -321,6 +330,12 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
continue;
}
+ if (unlikely(!uadk_data->handle)) {
+ error_setg(errp, "multifd %u: UADK HW not available for decompression",
+ p->id);
+ return -1;
+ }
+
ret = wd_do_comp_sync(uadk_data->handle, &creq);
if (ret || creq.status) {
error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 7/7] tests/migration-test: add uadk compression test
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
` (5 preceding siblings ...)
2024-05-29 9:44 ` [PATCH 6/7] migration/multifd: Switch to no compression when no hardware support Shameer Kolothum via
@ 2024-05-29 9:44 ` Shameer Kolothum via
2024-06-05 19:18 ` Fabiano Rosas
2024-06-04 20:59 ` [PATCH 0/7] Live migration acceleration with UADK Peter Xu
7 siblings, 1 reply; 23+ messages in thread
From: Shameer Kolothum via @ 2024-05-29 9:44 UTC (permalink / raw)
To: peterx, farosas, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
tests/qtest/migration-test.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 0f75ed7c49..4104b41f66 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2785,6 +2785,14 @@ test_migrate_precopy_tcp_multifd_qpl_start(QTestState *from,
return test_migrate_precopy_tcp_multifd_start_common(from, to, "qpl");
}
#endif /* CONFIG_QPL */
+#ifdef CONFIG_UADK
+static void *
+test_migrate_precopy_tcp_multifd_uadk_start(QTestState *from,
+ QTestState *to)
+{
+ return test_migrate_precopy_tcp_multifd_start_common(from, to, "uadk");
+}
+#endif /* CONFIG_UADK */
static void test_multifd_tcp_uri_none(void)
{
@@ -2877,6 +2885,17 @@ static void test_multifd_tcp_qpl(void)
}
#endif
+#ifdef CONFIG_UADK
+static void test_multifd_tcp_uadk(void)
+{
+ MigrateCommon args = {
+ .listen_uri = "defer",
+ .start_hook = test_migrate_precopy_tcp_multifd_uadk_start,
+ };
+ test_precopy_common(&args);
+}
+#endif
+
#ifdef CONFIG_GNUTLS
static void *
test_migrate_multifd_tcp_tls_psk_start_match(QTestState *from,
@@ -3784,6 +3803,10 @@ int main(int argc, char **argv)
migration_test_add("/migration/multifd/tcp/plain/qpl",
test_multifd_tcp_qpl);
#endif
+#ifdef CONFIG_UADK
+ migration_test_add("/migration/multifd/tcp/plain/uadk",
+ test_multifd_tcp_uadk);
+#endif
#ifdef CONFIG_GNUTLS
migration_test_add("/migration/multifd/tcp/tls/psk/match",
test_multifd_tcp_tls_psk_match);
--
2.17.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [PATCH 3/7] migration/multifd: add uadk compression framework
2024-05-29 9:44 ` [PATCH 3/7] migration/multifd: add uadk compression framework Shameer Kolothum via
@ 2024-05-29 11:10 ` Markus Armbruster
2024-05-30 6:56 ` Shameerali Kolothum Thodi via
2024-06-04 21:24 ` Fabiano Rosas
1 sibling, 1 reply; 23+ messages in thread
From: Markus Armbruster @ 2024-05-29 11:10 UTC (permalink / raw)
To: Shameer Kolothum via
Cc: peterx, farosas, yuan1.liu, Shameer Kolothum, linuxarm,
linwenkai6, zhangfei.gao, huangchenghai2
Please cc: maintainers on patches. You can use
scripts/get_maintainer.pl to find them.
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Adds the skeleton to support uadk compression method.
> Complete functionality will be added in subsequent patches.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
[...]
> diff --git a/qapi/migration.json b/qapi/migration.json
> index 854e8609bd..0eaea9b0c3 100644
> --- a/qapi/migration.json
> +++ b/qapi/migration.json
> @@ -632,12 +632,15 @@
> # the deflate compression algorithm and use the Intel In-Memory Analytics
> # Accelerator(IAA) accelerated compression and decompression. (Since 9.1)
> #
> +# @uadk: use UADK library compression method. (Since 9.1)
Two spaces after '.' for consistency, please.
> +#
> # Since: 5.0
> ##
> { 'enum': 'MultiFDCompression',
> 'data': [ 'none', 'zlib',
> { 'name': 'zstd', 'if': 'CONFIG_ZSTD' },
> - { 'name': 'qpl', 'if': 'CONFIG_QPL' } ] }
> + { 'name': 'qpl', 'if': 'CONFIG_QPL' },
> + { 'name': 'uadk', 'if': 'CONFIG_UADK' } ] }
>
> ##
> # @MigMode:
QAPI schema
Acked-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: [PATCH 3/7] migration/multifd: add uadk compression framework
2024-05-29 11:10 ` Markus Armbruster
@ 2024-05-30 6:56 ` Shameerali Kolothum Thodi via
0 siblings, 0 replies; 23+ messages in thread
From: Shameerali Kolothum Thodi via @ 2024-05-30 6:56 UTC (permalink / raw)
To: Markus Armbruster, Shameer Kolothum via
Cc: peterx@redhat.com, farosas@suse.de, yuan1.liu@intel.com, Linuxarm,
linwenkai (C), zhangfei.gao@linaro.org, huangchenghai
> -----Original Message-----
> From: Markus Armbruster <armbru@redhat.com>
> Sent: Wednesday, May 29, 2024 12:11 PM
> To: Shameer Kolothum via <qemu-devel@nongnu.org>
> Cc: peterx@redhat.com; farosas@suse.de; yuan1.liu@intel.com; Shameerali
> Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>; Linuxarm
> <linuxarm@huawei.com>; linwenkai (C) <linwenkai6@hisilicon.com>;
> zhangfei.gao@linaro.org; huangchenghai <huangchenghai2@huawei.com>
> Subject: Re: [PATCH 3/7] migration/multifd: add uadk compression
> framework
>
> Please cc: maintainers on patches. You can use
> scripts/get_maintainer.pl to find them.
Sure. My bad.
>
> Shameer Kolothum via <qemu-devel@nongnu.org> writes:
>
> > Adds the skeleton to support uadk compression method.
> > Complete functionality will be added in subsequent patches.
> >
> > Signed-off-by: Shameer Kolothum
> <shameerali.kolothum.thodi@huawei.com>
>
> [...]
>
> > diff --git a/qapi/migration.json b/qapi/migration.json
> > index 854e8609bd..0eaea9b0c3 100644
> > --- a/qapi/migration.json
> > +++ b/qapi/migration.json
> > @@ -632,12 +632,15 @@
> > # the deflate compression algorithm and use the Intel In-Memory
> Analytics
> > # Accelerator(IAA) accelerated compression and decompression. (Since
> 9.1)
> > #
> > +# @uadk: use UADK library compression method. (Since 9.1)
>
> Two spaces after '.' for consistency, please.
Ok.
> > +#
> > # Since: 5.0
> > ##
> > { 'enum': 'MultiFDCompression',
> > 'data': [ 'none', 'zlib',
> > { 'name': 'zstd', 'if': 'CONFIG_ZSTD' },
> > - { 'name': 'qpl', 'if': 'CONFIG_QPL' } ] }
> > + { 'name': 'qpl', 'if': 'CONFIG_QPL' },
> > + { 'name': 'uadk', 'if': 'CONFIG_UADK' } ] }
> >
> > ##
> > # @MigMode:
>
> QAPI schema
> Acked-by: Markus Armbruster <armbru@redhat.com>
Thanks,
Shameer
^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: [PATCH 1/7] docs/migration: add uadk compression feature
2024-05-29 9:44 ` [PATCH 1/7] docs/migration: add uadk compression feature Shameer Kolothum via
@ 2024-05-30 13:25 ` Liu, Yuan1
2024-05-30 14:01 ` Shameerali Kolothum Thodi via
2024-06-05 18:59 ` Fabiano Rosas
1 sibling, 1 reply; 23+ messages in thread
From: Liu, Yuan1 @ 2024-05-30 13:25 UTC (permalink / raw)
To: Shameer Kolothum, peterx@redhat.com, farosas@suse.de
Cc: qemu-devel@nongnu.org, linuxarm@huawei.com,
linwenkai6@hisilicon.com, zhangfei.gao@linaro.org,
huangchenghai2@huawei.com
> -----Original Message-----
> From: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> Sent: Wednesday, May 29, 2024 5:44 PM
> To: peterx@redhat.com; farosas@suse.de; Liu, Yuan1 <yuan1.liu@intel.com>
> Cc: qemu-devel@nongnu.org; linuxarm@huawei.com; linwenkai6@hisilicon.com;
> zhangfei.gao@linaro.org; huangchenghai2@huawei.com
> Subject: [PATCH 1/7] docs/migration: add uadk compression feature
>
> Document UADK(User Space Accelerator Development Kit) library details
> and how to use that for migration.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
> docs/devel/migration/uadk-compression.rst | 144 ++++++++++++++++++++++
> 1 file changed, 144 insertions(+)
> create mode 100644 docs/devel/migration/uadk-compression.rst
>
> diff --git a/docs/devel/migration/uadk-compression.rst
> b/docs/devel/migration/uadk-compression.rst
> new file mode 100644
> index 0000000000..988b92631e
> --- /dev/null
> +++ b/docs/devel/migration/uadk-compression.rst
> @@ -0,0 +1,144 @@
> +=========================================================
> +User Space Accelerator Development Kit (UADK) Compression
> +=========================================================
> +UADK is a general-purpose user space accelerator framework that uses
> shared
> +virtual addressing (SVA) to provide a unified programming interface for
> +hardware acceleration of cryptographic and compression algorithms.
> +
> +UADK includes Unified/User-space-access-intended Accelerator Framework
> (UACCE),
> +which enables hardware accelerators from different vendors that support
> SVA to
> +adapt to UADK.
> +
> +Currently, HiSilicon Kunpeng hardware accelerators have been registered
> with
> +UACCE. Through the UADK framework, users can run cryptographic and
> compression
> +algorithms using hardware accelerators instead of CPUs, freeing up CPU
> +computing power and improving computing performance.
> +
> +https://github.com/Linaro/uadk/tree/master/docs
> +
> +UADK Framework
> +==============
> +UADK consists of UACCE, vendors' drivers, and an algorithm layer. UADK
> requires
> +the hardware accelerator to support SVA, and the operating system to
> support
> +IOMMU and SVA. Hardware accelerators from different vendors are
> registered as
> +different character devices with UACCE by using kernel-mode drivers of
> the
> +vendors. A user can access the hardware accelerators by performing user-
> mode
> +operations on the character devices.
> +
> +::
> +
> + +----------------------------------+
> + | apps |
> + +----+------------------------+----+
> + | |
> + | |
> + +-------+--------+ +-------+-------+
> + | scheduler | | alg libraries |
> + +-------+--------+ +-------+-------+
> + | |
> + | |
> + | |
> + | +--------+------+
> + | | vendor drivers|
> + | +-+-------------+
> + | |
> + | |
> + +--+------------------+--+
> + | libwd |
> + User +----+-------------+-----+
> + --------------------------------------------------
> + Kernel +--+-----+ +------+
> + | uacce | | smmu |
> + +---+----+ +------+
> + |
> + +---+------------------+
> + | vendor kernel driver |
> + +----------------------+
> + --------------------------------------------------
> + +----------------------+
> + | HW Accelerators |
> + +----------------------+
> +
> +UADK Installation
> +-----------------
> +Build UADK
> +^^^^^^^^^^
> +
> +.. code-block:: shell
> +
> + git clone https://github.com/Linaro/uadk.git
> + cd uadk
> + mkdir build
> + ./autogen.sh
> + ./configure --prefix=$PWD/build
> + make
> + make install
> +
> +Without --prefix, UADK will be installed to /usr/local/lib by default.
> +If get error:"cannot find -lnuma", please install the libnuma-dev
> +
> +Run pkg-config libwd to ensure env is setup correctly
> +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +* export PKG_CONFIG_PATH=$PWD/build/lib/pkgconfig
> +* pkg-config libwd --cflags --libs
> + -I/usr/local/include -L/usr/local/lib -lwd
> +
> +* export PKG_CONFIG_PATH is required on demand.
> + Not required if UADK is installed to /usr/local/lib
> +
> +UADK Host Kernel Requirements
> +-----------------------------
> +User needs to make sure that ``UACCE`` is already supported in Linux
> kernel.
> +The kernel version should be at least v5.9 with SVA (Shared Virtual
> +Addressing) enabled.
> +
> +Kernel Configuration
> +^^^^^^^^^^^^^^^^^^^^
> +
> +``UACCE`` could be built as module or built-in.
> +
> +Here's an example to enable UACCE with hardware accelerator in HiSilicon
> +Kunpeng platform.
> +
> +* CONFIG_IOMMU_SVA_LIB=y
> +* CONFIG_ARM_SMMU=y
> +* CONFIG_ARM_SMMU_V3=y
> +* CONFIG_ARM_SMMU_V3_SVA=y
> +* CONFIG_PCI_PASID=y
> +* CONFIG_UACCE=y
> +* CONFIG_CRYPTO_DEV_HISI_QM=y
> +* CONFIG_CRYPTO_DEV_HISI_ZIP=y
> +
> +Make sure all these above kernel configurations are selected.
> +
> +Accelerator dev node permissions
> +--------------------------------
> +Harware accelerators(eg: HiSilicon Kunpeng Zip accelerator) gets
> registered to
> +UADK and char devices are created in dev directory. In order to access
> resources
> +on hardware accelerator devices, write permission should be provided to
> user.
> +
> +.. code-block:: shell
> +
> + $ sudo chmod 777 /dev/hisi_zip-*
> +
> +How To Use UADK Compression In Qemu Migration
> +---------------------------------------------
> +* Make sure UADK is installed as above
> +* Build ``Qemu`` with ``--enable-uadk`` parameter
> +
> + E.g. configure --target-list=aarch64-softmmu --enable-kvm ``--enable-
> uadk``
> +
> +* Enable ``UADK`` compression during migration
> +
> + Set ``migrate_set_parameter multifd-compression uadk``
> +
> +Since UADK uses Shared Virtual Addressing(SVA) and device access virtual
> memory
> +directly it is possible that SMMUv3 may enounter page faults while
> walking the
> +IO page tables. This may impact the performance. In order to mitigate
> this,
> +please make sure to specify ``-mem-prealloc`` parameter to the
> destination VM
> +boot parameters.
Thank you so much for putting the IAA solution at the top and cc me.
I think migration performance will be better with '-mem-prealloc' option,
but I am considering whether '-mem-prealloc' is a mandatory option, from my
experience, SVA performance drops mainly caused by IOTLB flush and IO page fault,
I had some discussions with Peter Xu about the IOTLB flush issue, and it has
been improved.
https://patchew.org/QEMU/PH7PR11MB5941F04FBFB964CB2C968866A33E2@PH7PR11MB5941.namprd11.prod.outlook.com/
For IO page fault, the QPL(IAA userspace library) can process page fault
request instead of IOMMU, it means we can disable the I/O page fault feature
on the IAA device, and let the device still use SVA technology to avoid memory
copy.
I will provide the test results in my next version, do you have any ideas or
suggestions about this, thanks.
> +Though both UADK and ZLIB are based on the deflate compression algorithm,
> UADK
> +is not fully compatible with ZLIB. Hence, please make sure to use
> ``uadk`` on
> +both source and destination during migration.
> --
> 2.17.1
^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: [PATCH 1/7] docs/migration: add uadk compression feature
2024-05-30 13:25 ` Liu, Yuan1
@ 2024-05-30 14:01 ` Shameerali Kolothum Thodi via
2024-05-30 14:13 ` Liu, Yuan1
0 siblings, 1 reply; 23+ messages in thread
From: Shameerali Kolothum Thodi via @ 2024-05-30 14:01 UTC (permalink / raw)
To: Liu, Yuan1, peterx@redhat.com, farosas@suse.de
Cc: qemu-devel@nongnu.org, Linuxarm, linwenkai (C),
zhangfei.gao@linaro.org, huangchenghai
> -----Original Message-----
> From: Liu, Yuan1 <yuan1.liu@intel.com>
> Sent: Thursday, May 30, 2024 2:25 PM
> To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>;
> peterx@redhat.com; farosas@suse.de
> Cc: qemu-devel@nongnu.org; Linuxarm <linuxarm@huawei.com>; linwenkai (C)
> <linwenkai6@hisilicon.com>; zhangfei.gao@linaro.org; huangchenghai
> <huangchenghai2@huawei.com>
> Subject: RE: [PATCH 1/7] docs/migration: add uadk compression feature
>
> > -----Original Message-----
> > From: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> > Sent: Wednesday, May 29, 2024 5:44 PM
> > To: peterx@redhat.com; farosas@suse.de; Liu, Yuan1 <yuan1.liu@intel.com>
> > Cc: qemu-devel@nongnu.org; linuxarm@huawei.com;
> linwenkai6@hisilicon.com;
> > zhangfei.gao@linaro.org; huangchenghai2@huawei.com
> > Subject: [PATCH 1/7] docs/migration: add uadk compression feature
[...]
> > +Since UADK uses Shared Virtual Addressing(SVA) and device access virtual
> > memory
> > +directly it is possible that SMMUv3 may enounter page faults while
> > walking the
> > +IO page tables. This may impact the performance. In order to mitigate
> > this,
> > +please make sure to specify ``-mem-prealloc`` parameter to the
> > destination VM
> > +boot parameters.
>
> Thank you so much for putting the IAA solution at the top and cc me.
>
> I think migration performance will be better with '-mem-prealloc' option,
> but I am considering whether '-mem-prealloc' is a mandatory option, from my
> experience, SVA performance drops mainly caused by IOTLB flush and IO page
> fault,
> I had some discussions with Peter Xu about the IOTLB flush issue, and it has
> been improved.
> https://patchew.org/QEMU/PH7PR11MB5941F04FBFB964CB2C968866A33E2@
> PH7PR11MB5941.namprd11.prod.outlook.com/
Thanks for the link. Yes I have seen that discussion and this series is on top of that
patch for avoiding the zero page read fault.
>
> For IO page fault, the QPL(IAA userspace library) can process page fault
> request instead of IOMMU,
Sorry I didn't get this part completely. So if the page fault happens how the library
can handle it without IOMMU? Or you meant library will do memory perfecting before
to avoid the page fault?
it means we can disable the I/O page fault feature
> on the IAA device, and let the device still use SVA technology to avoid memory
> copy.
>
> I will provide the test results in my next version, do you have any ideas or
> suggestions about this, thanks.
I think our UADK test tool had an option to prefect the memory(write some random data
to memory) to avoid page fault penalty. I am not sure that is exposed through the API or not.
I will check with our UADK team.
Please do CC me when you post your next revision.
Thanks,
Shameer
^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: [PATCH 1/7] docs/migration: add uadk compression feature
2024-05-30 14:01 ` Shameerali Kolothum Thodi via
@ 2024-05-30 14:13 ` Liu, Yuan1
0 siblings, 0 replies; 23+ messages in thread
From: Liu, Yuan1 @ 2024-05-30 14:13 UTC (permalink / raw)
To: Shameerali Kolothum Thodi, peterx@redhat.com, farosas@suse.de
Cc: qemu-devel@nongnu.org, Linuxarm, linwenkai (C),
zhangfei.gao@linaro.org, huangchenghai
> -----Original Message-----
> From: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
> Sent: Thursday, May 30, 2024 10:01 PM
> To: Liu, Yuan1 <yuan1.liu@intel.com>; peterx@redhat.com; farosas@suse.de
> Cc: qemu-devel@nongnu.org; Linuxarm <linuxarm@huawei.com>; linwenkai (C)
> <linwenkai6@hisilicon.com>; zhangfei.gao@linaro.org; huangchenghai
> <huangchenghai2@huawei.com>
> Subject: RE: [PATCH 1/7] docs/migration: add uadk compression feature
>
>
>
> > -----Original Message-----
> > From: Liu, Yuan1 <yuan1.liu@intel.com>
> > Sent: Thursday, May 30, 2024 2:25 PM
> > To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>;
> > peterx@redhat.com; farosas@suse.de
> > Cc: qemu-devel@nongnu.org; Linuxarm <linuxarm@huawei.com>; linwenkai (C)
> > <linwenkai6@hisilicon.com>; zhangfei.gao@linaro.org; huangchenghai
> > <huangchenghai2@huawei.com>
> > Subject: RE: [PATCH 1/7] docs/migration: add uadk compression feature
> >
> > > -----Original Message-----
> > > From: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> > > Sent: Wednesday, May 29, 2024 5:44 PM
> > > To: peterx@redhat.com; farosas@suse.de; Liu, Yuan1
> <yuan1.liu@intel.com>
> > > Cc: qemu-devel@nongnu.org; linuxarm@huawei.com;
> > linwenkai6@hisilicon.com;
> > > zhangfei.gao@linaro.org; huangchenghai2@huawei.com
> > > Subject: [PATCH 1/7] docs/migration: add uadk compression feature
>
> [...]
>
> > > +Since UADK uses Shared Virtual Addressing(SVA) and device access
> virtual
> > > memory
> > > +directly it is possible that SMMUv3 may enounter page faults while
> > > walking the
> > > +IO page tables. This may impact the performance. In order to mitigate
> > > this,
> > > +please make sure to specify ``-mem-prealloc`` parameter to the
> > > destination VM
> > > +boot parameters.
> >
> > Thank you so much for putting the IAA solution at the top and cc me.
> >
> > I think migration performance will be better with '-mem-prealloc'
> option,
> > but I am considering whether '-mem-prealloc' is a mandatory option, from
> my
> > experience, SVA performance drops mainly caused by IOTLB flush and IO
> page
> > fault,
> > I had some discussions with Peter Xu about the IOTLB flush issue, and it
> has
> > been improved.
> > https://patchew.org/QEMU/PH7PR11MB5941F04FBFB964CB2C968866A33E2@
> > PH7PR11MB5941.namprd11.prod.outlook.com/
>
> Thanks for the link. Yes I have seen that discussion and this series is on
> top of that
> patch for avoiding the zero page read fault.
>
> >
> > For IO page fault, the QPL(IAA userspace library) can process page fault
> > request instead of IOMMU,
>
> Sorry I didn't get this part completely. So if the page fault happens how
> the library
> can handle it without IOMMU? Or you meant library will do memory
> perfecting before
> to avoid the page fault?
Yes, when the I/O page fault happens, the hardware will return the fault address
to the QPL, QPL will populate the memory as below, then resubmit the job to
hardware again.
if (AD_STATUS_READ_PAGE_FAULT == completion_record_ptr->status) {
volatile char* read_fault_address = (char *)fault_address;
*read_fault_address;
}
else { // AD_STATUS_WRITE_PAGE_FAULT
volatile char* write_fault_address = (char *)fault_address;
*write_fault_address = *write_fault_address;
}
> it means we can disable the I/O page fault feature
> > on the IAA device, and let the device still use SVA technology to avoid
> memory
> > copy.
> >
> > I will provide the test results in my next version, do you have any
> ideas or
> > suggestions about this, thanks.
>
> I think our UADK test tool had an option to prefect the memory(write some
> random data
> to memory) to avoid page fault penalty. I am not sure that is exposed
> through the API or not.
> I will check with our UADK team.
>
> Please do CC me when you post your next revision.
Sure
> Thanks,
> Shameer
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/7] Live migration acceleration with UADK
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
` (6 preceding siblings ...)
2024-05-29 9:44 ` [PATCH 7/7] tests/migration-test: add uadk compression test Shameer Kolothum via
@ 2024-06-04 20:59 ` Peter Xu
7 siblings, 0 replies; 23+ messages in thread
From: Peter Xu @ 2024-06-04 20:59 UTC (permalink / raw)
To: Shameer Kolothum
Cc: farosas, yuan1.liu, qemu-devel, linuxarm, linwenkai6,
zhangfei.gao, huangchenghai2
On Wed, May 29, 2024 at 10:44:20AM +0100, Shameer Kolothum via wrote:
> Hi,
>
> This series adds support for UADK library based hardware acceleration
> for live migration. UADK[0] is a general-purpose user space accelerator
> framework that uses shared virtual addressing (SVA) to provide a unified
> programming interface for hardware acceleration of cryptographic and
> compression algorithms.
>
> UADK makes use of the UACCE(Unified/User-space-access-intended Accelerator
> Framework) Linux kernel module which enables hardware accelerators from
> different vendors that support SVA to adapt to UADK. Linux kernel from
> v5.9 has support for UACCE and SVA on ARM64 platforms.
>
> Currently, HiSilicon Kunpeng hardware accelerators have been registered with
> UACCE and the Zip accelerator on these platforms can be used for compression
> which can free up CPU computing power and improve computing performance.
>
> This series is on top of Intel IAA accelerator live migration support
> series[1] from Yuan Liu. Many thanks for doing this.
Just looked at the IAA series too, I didn't read multifd-*.[ch] much on
both sides but both the series look pretty clean to me.
Thanks,
--
Peter Xu
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 3/7] migration/multifd: add uadk compression framework
2024-05-29 9:44 ` [PATCH 3/7] migration/multifd: add uadk compression framework Shameer Kolothum via
2024-05-29 11:10 ` Markus Armbruster
@ 2024-06-04 21:24 ` Fabiano Rosas
1 sibling, 0 replies; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-04 21:24 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Adds the skeleton to support uadk compression method.
> Complete functionality will be added in subsequent patches.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/7] configure: Add uadk option
2024-05-29 9:44 ` [PATCH 2/7] configure: Add uadk option Shameer Kolothum via
@ 2024-06-04 21:25 ` Fabiano Rosas
0 siblings, 0 replies; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-04 21:25 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Add --enable-uadk and --disable-uadk options to enable and disable
> UADK compression accelerator. This is for using UADK based hardware
> accelerators for live migration.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/7] migration/multifd: Add UADK initialization
2024-05-29 9:44 ` [PATCH 4/7] migration/multifd: Add UADK initialization Shameer Kolothum via
@ 2024-06-05 14:58 ` Fabiano Rosas
2024-06-05 15:17 ` Shameerali Kolothum Thodi via
0 siblings, 1 reply; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-05 14:58 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Initialize UADK session and allocate buffers required. The actual
> compression/decompression will only be done in a subsequent patch.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
> migration/multifd-uadk.c | 207 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 206 insertions(+), 1 deletion(-)
>
> diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
> index c2bb07535b..3172e4d5ca 100644
> --- a/migration/multifd-uadk.c
> +++ b/migration/multifd-uadk.c
> @@ -12,9 +12,214 @@
>
> #include "qemu/osdep.h"
> #include "qemu/module.h"
> +#include "qapi/error.h"
> +#include "migration.h"
> +#include "multifd.h"
> +#include "options.h"
> +#include "uadk/wd_comp.h"
> +#include "uadk/wd_sched.h"
> +
> +struct wd_data {
> + handle_t handle;
> + uint8_t *buf;
> + uint32_t *buf_hdr;
> +};
> +
> +static bool uadk_hw_initialised(void)
The first time this is called it will actually do the initialization,
no? If so, it should be uadk_hw_init().
> +{
> + char alg[] = "zlib";
> + int ret;
> +
> + ret = wd_comp_init2(alg, SCHED_POLICY_RR, TASK_HW);
> + if (ret && ret != -WD_EEXIST) {
> + return false;
> + } else {
> + return true;
> + }
> +}
> +
> +static struct wd_data *multifd_uadk_init_sess(uint32_t count,
> + uint32_t page_size,
> + bool compress, Error **errp)
> +{
> + struct wd_comp_sess_setup ss = {0};
> + struct sched_params param = {0};
> + uint32_t size = count * page_size;
> + struct wd_data *wd;
> +
> + if (!uadk_hw_initialised()) {
> + error_setg(errp, "multifd: UADK hardware not available");
Does the lib provide a software fallback path that we could use like QPL
does?
> + return NULL;
> + }
> +
> + wd = g_new0(struct wd_data, 1);
> + ss.alg_type = WD_ZLIB;
> + if (compress) {
> + ss.op_type = WD_DIR_COMPRESS;
> + /* Add an additional page for handling output > input */
> + size += page_size;
> + } else {
> + ss.op_type = WD_DIR_DECOMPRESS;
> + }
> + param.type = ss.op_type;
> + ss.sched_param = ¶m;
What about window size and compression level? Don't we need to set them
here? What do they default to?
> +
> + wd->handle = wd_comp_alloc_sess(&ss);
> + if (!wd->handle) {
> + error_setg(errp, "multifd: failed wd_comp_alloc_sess");
> + goto out;
> + }
> +
> + wd->buf = g_try_malloc(size);
> + if (!wd->buf) {
> + error_setg(errp, "multifd: out of mem for uadk buf");
> + goto out_free_sess;
> + }
> + wd->buf_hdr = g_new0(uint32_t, count);
> + return wd;
> +
> +out_free_sess:
> + wd_comp_free_sess(wd->handle);
> +out:
> + wd_comp_uninit2();
> + g_free(wd);
> + return NULL;
> +}
> +
> +static void multifd_uadk_uninit_sess(struct wd_data *wd)
> +{
> + wd_comp_free_sess(wd->handle);
> + wd_comp_uninit2();
> + g_free(wd->buf);
> + g_free(wd->buf_hdr);
> + g_free(wd);
> +}
> +
> +/**
> + * multifd_uadk_send_setup: setup send side
> + *
> + * Returns 0 for success or -1 for error
> + *
> + * @p: Params for the channel that we are using
> + * @errp: pointer to an error
> + */
> +static int multifd_uadk_send_setup(MultiFDSendParams *p, Error **errp)
> +{
> + struct wd_data *wd;
> +
> + wd = multifd_uadk_init_sess(p->page_count, p->page_size, true, errp);
> + if (!wd) {
> + return -1;
> + }
> +
> + p->compress_data = wd;
> + assert(p->iov == NULL);
> + /*
> + * Each page will be compressed independently and sent using an IOV. The
> + * additional two IOVs are used to store packet header and compressed data
> + * length
> + */
> +
> + p->iov = g_new0(struct iovec, p->page_count + 2);
> + return 0;
> +}
> +
> +/**
> + * multifd_uadk_send_cleanup: cleanup send side
> + *
> + * Close the channel and return memory.
> + *
> + * @p: Params for the channel that we are using
> + * @errp: pointer to an error
> + */
> +static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
> +{
> + struct wd_data *wd = p->compress_data;
> +
> + multifd_uadk_uninit_sess(wd);
> + p->compress_data = NULL;
> +}
> +
> +/**
> + * multifd_uadk_send_prepare: prepare data to be able to send
> + *
> + * Create a compressed buffer with all the pages that we are going to
> + * send.
> + *
> + * Returns 0 for success or -1 for error
> + *
> + * @p: Params for the channel that we are using
> + * @errp: pointer to an error
> + */
> +static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error **errp)
> +{
> + return -1;
> +}
> +
> +/**
> + * multifd_uadk_recv_setup: setup receive side
> + *
> + * Create the compressed channel and buffer.
> + *
> + * Returns 0 for success or -1 for error
> + *
> + * @p: Params for the channel that we are using
> + * @errp: pointer to an error
> + */
> +static int multifd_uadk_recv_setup(MultiFDRecvParams *p, Error **errp)
> +{
> + struct wd_data *wd;
> +
> + wd = multifd_uadk_init_sess(p->page_count, p->page_size, false, errp);
> + if (!wd) {
> + return -1;
> + }
> + p->compress_data = wd;
> + return 0;
> +}
> +
> +/**
> + * multifd_uadk_recv_cleanup: setup receive side
> + *
> + * For no compression this function does nothing.
This line makes no sense here.
> + *
> + * @p: Params for the channel that we are using
> + */
> +static void multifd_uadk_recv_cleanup(MultiFDRecvParams *p)
> +{
> + struct wd_data *wd = p->compress_data;
> +
> + multifd_uadk_uninit_sess(wd);
> + p->compress_data = NULL;
> +}
> +
> +/**
> + * multifd_uadk_recv: read the data from the channel into actual pages
> + *
> + * Read the compressed buffer, and uncompress it into the actual
> + * pages.
> + *
> + * Returns 0 for success or -1 for error
> + *
> + * @p: Params for the channel that we are using
> + * @errp: pointer to an error
> + */
> +static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
> +{
> + return -1;
> +}
> +
> +static MultiFDMethods multifd_uadk_ops = {
> + .send_setup = multifd_uadk_send_setup,
> + .send_cleanup = multifd_uadk_send_cleanup,
> + .send_prepare = multifd_uadk_send_prepare,
> + .recv_setup = multifd_uadk_recv_setup,
> + .recv_cleanup = multifd_uadk_recv_cleanup,
> + .recv = multifd_uadk_recv,
> +};
>
> static void multifd_uadk_register(void)
> {
> - /* noop for now */
> + multifd_register_ops(MULTIFD_COMPRESSION_UADK, &multifd_uadk_ops);
> }
> migration_init(multifd_uadk_register);
^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: [PATCH 4/7] migration/multifd: Add UADK initialization
2024-06-05 14:58 ` Fabiano Rosas
@ 2024-06-05 15:17 ` Shameerali Kolothum Thodi via
0 siblings, 0 replies; 23+ messages in thread
From: Shameerali Kolothum Thodi via @ 2024-06-05 15:17 UTC (permalink / raw)
To: Fabiano Rosas, peterx@redhat.com, yuan1.liu@intel.com
Cc: qemu-devel@nongnu.org, Linuxarm, linwenkai (C),
zhangfei.gao@linaro.org, huangchenghai
> -----Original Message-----
> From: Fabiano Rosas <farosas@suse.de>
> Sent: Wednesday, June 5, 2024 3:58 PM
> To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>;
> peterx@redhat.com; yuan1.liu@intel.com
> Cc: qemu-devel@nongnu.org; Linuxarm <linuxarm@huawei.com>; linwenkai
> (C) <linwenkai6@hisilicon.com>; zhangfei.gao@linaro.org; huangchenghai
> <huangchenghai2@huawei.com>
> Subject: Re: [PATCH 4/7] migration/multifd: Add UADK initialization
>
> Shameer Kolothum via <qemu-devel@nongnu.org> writes:
>
> > Initialize UADK session and allocate buffers required. The actual
> > compression/decompression will only be done in a subsequent patch.
> >
> > Signed-off-by: Shameer Kolothum
> <shameerali.kolothum.thodi@huawei.com>
> > ---
> > migration/multifd-uadk.c | 207
> ++++++++++++++++++++++++++++++++++++++-
> > 1 file changed, 206 insertions(+), 1 deletion(-)
> >
> > diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
> > index c2bb07535b..3172e4d5ca 100644
> > --- a/migration/multifd-uadk.c
> > +++ b/migration/multifd-uadk.c
> > @@ -12,9 +12,214 @@
> >
> > #include "qemu/osdep.h"
> > #include "qemu/module.h"
> > +#include "qapi/error.h"
> > +#include "migration.h"
> > +#include "multifd.h"
> > +#include "options.h"
> > +#include "uadk/wd_comp.h"
> > +#include "uadk/wd_sched.h"
> > +
> > +struct wd_data {
> > + handle_t handle;
> > + uint8_t *buf;
> > + uint32_t *buf_hdr;
> > +};
> > +
> > +static bool uadk_hw_initialised(void)
>
> The first time this is called it will actually do the initialization,
> no? If so, it should be uadk_hw_init().
Ok. Makes sense.
>
> > +{
> > + char alg[] = "zlib";
> > + int ret;
> > +
> > + ret = wd_comp_init2(alg, SCHED_POLICY_RR, TASK_HW);
> > + if (ret && ret != -WD_EEXIST) {
> > + return false;
> > + } else {
> > + return true;
> > + }
> > +}
> > +
> > +static struct wd_data *multifd_uadk_init_sess(uint32_t count,
> > + uint32_t page_size,
> > + bool compress, Error **errp)
> > +{
> > + struct wd_comp_sess_setup ss = {0};
> > + struct sched_params param = {0};
> > + uint32_t size = count * page_size;
> > + struct wd_data *wd;
> > +
> > + if (!uadk_hw_initialised()) {
> > + error_setg(errp, "multifd: UADK hardware not available");
>
> Does the lib provide a software fallback path that we could use like QPL
> does?
Unfortunately not. That is why I added patch #6 where we will just send
raw data to take care the CI test.
>
> > + return NULL;
> > + }
> > +
> > + wd = g_new0(struct wd_data, 1);
> > + ss.alg_type = WD_ZLIB;
> > + if (compress) {
> > + ss.op_type = WD_DIR_COMPRESS;
> > + /* Add an additional page for handling output > input */
> > + size += page_size;
> > + } else {
> > + ss.op_type = WD_DIR_DECOMPRESS;
> > + }
> > + param.type = ss.op_type;
> > + ss.sched_param = ¶m;
>
> What about window size and compression level? Don't we need to set them
> here? What do they default to?
Level 1 and 4K. I will add a comment here.
> > +
> > + wd->handle = wd_comp_alloc_sess(&ss);
> > + if (!wd->handle) {
> > + error_setg(errp, "multifd: failed wd_comp_alloc_sess");
> > + goto out;
> > + }
> > +
> > + wd->buf = g_try_malloc(size);
> > + if (!wd->buf) {
> > + error_setg(errp, "multifd: out of mem for uadk buf");
> > + goto out_free_sess;
> > + }
> > + wd->buf_hdr = g_new0(uint32_t, count);
> > + return wd;
> > +
> > +out_free_sess:
> > + wd_comp_free_sess(wd->handle);
> > +out:
> > + wd_comp_uninit2();
> > + g_free(wd);
> > + return NULL;
> > +}
> > +
> > +static void multifd_uadk_uninit_sess(struct wd_data *wd)
> > +{
> > + wd_comp_free_sess(wd->handle);
> > + wd_comp_uninit2();
> > + g_free(wd->buf);
> > + g_free(wd->buf_hdr);
> > + g_free(wd);
> > +}
> > +
> > +/**
> > + * multifd_uadk_send_setup: setup send side
> > + *
> > + * Returns 0 for success or -1 for error
> > + *
> > + * @p: Params for the channel that we are using
> > + * @errp: pointer to an error
> > + */
> > +static int multifd_uadk_send_setup(MultiFDSendParams *p, Error **errp)
> > +{
> > + struct wd_data *wd;
> > +
> > + wd = multifd_uadk_init_sess(p->page_count, p->page_size, true, errp);
> > + if (!wd) {
> > + return -1;
> > + }
> > +
> > + p->compress_data = wd;
> > + assert(p->iov == NULL);
> > + /*
> > + * Each page will be compressed independently and sent using an IOV.
> The
> > + * additional two IOVs are used to store packet header and compressed
> data
> > + * length
> > + */
> > +
> > + p->iov = g_new0(struct iovec, p->page_count + 2);
> > + return 0;
> > +}
> > +
> > +/**
> > + * multifd_uadk_send_cleanup: cleanup send side
> > + *
> > + * Close the channel and return memory.
> > + *
> > + * @p: Params for the channel that we are using
> > + * @errp: pointer to an error
> > + */
> > +static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error
> **errp)
> > +{
> > + struct wd_data *wd = p->compress_data;
> > +
> > + multifd_uadk_uninit_sess(wd);
> > + p->compress_data = NULL;
> > +}
> > +
> > +/**
> > + * multifd_uadk_send_prepare: prepare data to be able to send
> > + *
> > + * Create a compressed buffer with all the pages that we are going to
> > + * send.
> > + *
> > + * Returns 0 for success or -1 for error
> > + *
> > + * @p: Params for the channel that we are using
> > + * @errp: pointer to an error
> > + */
> > +static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error
> **errp)
> > +{
> > + return -1;
> > +}
> > +
> > +/**
> > + * multifd_uadk_recv_setup: setup receive side
> > + *
> > + * Create the compressed channel and buffer.
> > + *
> > + * Returns 0 for success or -1 for error
> > + *
> > + * @p: Params for the channel that we are using
> > + * @errp: pointer to an error
> > + */
> > +static int multifd_uadk_recv_setup(MultiFDRecvParams *p, Error **errp)
> > +{
> > + struct wd_data *wd;
> > +
> > + wd = multifd_uadk_init_sess(p->page_count, p->page_size, false, errp);
> > + if (!wd) {
> > + return -1;
> > + }
> > + p->compress_data = wd;
> > + return 0;
> > +}
> > +
> > +/**
> > + * multifd_uadk_recv_cleanup: setup receive side
> > + *
> > + * For no compression this function does nothing.
>
> This line makes no sense here.
Ok.
Thanks,
Shameer
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 5/7] migration/multifd: Add UADK based compression and decompression
2024-05-29 9:44 ` [PATCH 5/7] migration/multifd: Add UADK based compression and decompression Shameer Kolothum via
@ 2024-06-05 18:57 ` Fabiano Rosas
2024-06-06 7:11 ` Shameerali Kolothum Thodi via
0 siblings, 1 reply; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-05 18:57 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Uses UADK wd_do_comp_sync() API to (de)compress a normal page using
> hardware accelerator.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
A couple of comments below.
Reviewed-by: Fabiano Rosas <farosas@suse.de>
> ---
> migration/multifd-uadk.c | 132 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 130 insertions(+), 2 deletions(-)
>
> diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
> index 3172e4d5ca..3329819bd4 100644
> --- a/migration/multifd-uadk.c
> +++ b/migration/multifd-uadk.c
> @@ -13,6 +13,7 @@
> #include "qemu/osdep.h"
> #include "qemu/module.h"
> #include "qapi/error.h"
> +#include "exec/ramblock.h"
> #include "migration.h"
> #include "multifd.h"
> #include "options.h"
> @@ -140,6 +141,15 @@ static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
> p->compress_data = NULL;
> }
>
> +static inline void prepare_next_iov(MultiFDSendParams *p, void *base,
> + uint32_t len)
> +{
> + p->iov[p->iovs_num].iov_base = (uint8_t *)base;
> + p->iov[p->iovs_num].iov_len = len;
> + p->next_packet_size += len;
> + p->iovs_num++;
> +}
> +
> /**
> * multifd_uadk_send_prepare: prepare data to be able to send
> *
> @@ -153,7 +163,56 @@ static void multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
> */
> static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error **errp)
> {
> - return -1;
> + struct wd_data *uadk_data = p->compress_data;
> + uint32_t hdr_size;
> + uint8_t *buf = uadk_data->buf;
> + int ret = 0;
> +
> + if (!multifd_send_prepare_common(p)) {
> + goto out;
> + }
> +
> + hdr_size = p->pages->normal_num * sizeof(uint32_t);
> + /* prepare the header that stores the lengths of all compressed data */
> + prepare_next_iov(p, uadk_data->buf_hdr, hdr_size);
> +
> + for (int i = 0; i < p->pages->normal_num; i++) {
> + struct wd_comp_req creq = {
> + .op_type = WD_DIR_COMPRESS,
> + .src = p->pages->block->host + p->pages->offset[i],
> + .src_len = p->page_size,
> + .dst = buf,
> + /* Set dst_len to double the src to take care of -ve compression */
What's -ve compression?
> + .dst_len = p->page_size * 2,
> + };
> +
> + ret = wd_do_comp_sync(uadk_data->handle, &creq);
> + if (ret || creq.status) {
> + error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
> + p->id, ret, creq.status);
> + return -1;
> + }
> + if (creq.dst_len < p->page_size) {
> + uadk_data->buf_hdr[i] = cpu_to_be32(creq.dst_len);
> + prepare_next_iov(p, buf, creq.dst_len);
> + buf += creq.dst_len;
> + } else {
> + /*
> + * Send raw data if compressed out >= page_size. We might be better
> + * off sending raw data if output is slightly less than page_size
> + * as well because at the receive end we can skip the decompression.
> + * But it is tricky to find the right number here.
> + */
> + uadk_data->buf_hdr[i] = cpu_to_be32(p->page_size);
> + prepare_next_iov(p, p->pages->block->host + p->pages->offset[i],
> + p->page_size);
> + buf += p->page_size;
> + }
> + }
> +out:
> + p->flags |= MULTIFD_FLAG_UADK;
> + multifd_send_fill_packet(p);
> + return 0;
> }
>
> /**
> @@ -206,7 +265,76 @@ static void multifd_uadk_recv_cleanup(MultiFDRecvParams *p)
> */
> static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
> {
> - return -1;
> + struct wd_data *uadk_data = p->compress_data;
> + uint32_t in_size = p->next_packet_size;
> + uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> + uint32_t hdr_len = p->normal_num * sizeof(uint32_t);
> + uint32_t data_len = 0;
> + uint8_t *buf = uadk_data->buf;
> + int ret = 0;
> +
> + if (flags != MULTIFD_FLAG_UADK) {
> + error_setg(errp, "multifd %u: flags received %x flags expected %x",
> + p->id, flags, MULTIFD_FLAG_ZLIB);
> + return -1;
> + }
> +
> + multifd_recv_zero_page_process(p);
> + if (!p->normal_num) {
> + assert(in_size == 0);
> + return 0;
> + }
> +
> + /* read compressed data lengths */
> + assert(hdr_len < in_size);
> + ret = qio_channel_read_all(p->c, (void *) uadk_data->buf_hdr,
> + hdr_len, errp);
> + if (ret != 0) {
> + return ret;
> + }
> +
> + for (int i = 0; i < p->normal_num; i++) {
> + uadk_data->buf_hdr[i] = be32_to_cpu(uadk_data->buf_hdr[i]);
> + data_len += uadk_data->buf_hdr[i];
> + assert(uadk_data->buf_hdr[i] <= p->page_size);
> + }
> +
> + /* read compressed data */
> + assert(in_size == hdr_len + data_len);
> + ret = qio_channel_read_all(p->c, (void *)buf, data_len, errp);
> + if (ret != 0) {
> + return ret;
> + }
> +
> + for (int i = 0; i < p->normal_num; i++) {
> + struct wd_comp_req creq = {
> + .op_type = WD_DIR_DECOMPRESS,
> + .src = buf,
> + .src_len = uadk_data->buf_hdr[i],
> + .dst = p->host + p->normal[i],
> + .dst_len = p->page_size,
> + };
> +
> + if (uadk_data->buf_hdr[i] == p->page_size) {
> + memcpy(p->host + p->normal[i], buf, p->page_size);
> + buf += p->page_size;
> + continue;
> + }
> +
> + ret = wd_do_comp_sync(uadk_data->handle, &creq);
> + if (ret || creq.status) {
> + error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d status %d",
> + p->id, ret, creq.status);
It would be nice to be able to tell compression from decompression in
these error messages.
> + return -1;
> + }
> + if (creq.dst_len != p->page_size) {
> + error_setg(errp, "multifd %u: decompressed length error", p->id);
> + return -1;
> + }
> + buf += uadk_data->buf_hdr[i];
> + }
> +
> + return 0;
> }
>
> static MultiFDMethods multifd_uadk_ops = {
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 1/7] docs/migration: add uadk compression feature
2024-05-29 9:44 ` [PATCH 1/7] docs/migration: add uadk compression feature Shameer Kolothum via
2024-05-30 13:25 ` Liu, Yuan1
@ 2024-06-05 18:59 ` Fabiano Rosas
1 sibling, 0 replies; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-05 18:59 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Document UADK(User Space Accelerator Development Kit) library details
> and how to use that for migration.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
> docs/devel/migration/uadk-compression.rst | 144 ++++++++++++++++++++++
Missing an entry in the features.rst TOC.
> 1 file changed, 144 insertions(+)
> create mode 100644 docs/devel/migration/uadk-compression.rst
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/7] migration/multifd: Switch to no compression when no hardware support
2024-05-29 9:44 ` [PATCH 6/7] migration/multifd: Switch to no compression when no hardware support Shameer Kolothum via
@ 2024-06-05 19:08 ` Fabiano Rosas
0 siblings, 0 replies; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-05 19:08 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Send raw packets over if UADK hardware support is not available. This is to
> satisfy Qemu qtest CI which may run on platforms that don't have UADK
> hardware support. Subsequent patch will add support for uadk migration
> qtest.
>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 7/7] tests/migration-test: add uadk compression test
2024-05-29 9:44 ` [PATCH 7/7] tests/migration-test: add uadk compression test Shameer Kolothum via
@ 2024-06-05 19:18 ` Fabiano Rosas
0 siblings, 0 replies; 23+ messages in thread
From: Fabiano Rosas @ 2024-06-05 19:18 UTC (permalink / raw)
To: Shameer Kolothum, peterx, yuan1.liu
Cc: qemu-devel, linuxarm, linwenkai6, zhangfei.gao, huangchenghai2
Shameer Kolothum via <qemu-devel@nongnu.org> writes:
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: [PATCH 5/7] migration/multifd: Add UADK based compression and decompression
2024-06-05 18:57 ` Fabiano Rosas
@ 2024-06-06 7:11 ` Shameerali Kolothum Thodi via
0 siblings, 0 replies; 23+ messages in thread
From: Shameerali Kolothum Thodi via @ 2024-06-06 7:11 UTC (permalink / raw)
To: Fabiano Rosas, peterx@redhat.com, yuan1.liu@intel.com
Cc: qemu-devel@nongnu.org, Linuxarm, linwenkai (C),
zhangfei.gao@linaro.org, huangchenghai
> -----Original Message-----
> From: Fabiano Rosas <farosas@suse.de>
> Sent: Wednesday, June 5, 2024 7:57 PM
> To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>;
> peterx@redhat.com; yuan1.liu@intel.com
> Cc: qemu-devel@nongnu.org; Linuxarm <linuxarm@huawei.com>; linwenkai
> (C) <linwenkai6@hisilicon.com>; zhangfei.gao@linaro.org; huangchenghai
> <huangchenghai2@huawei.com>
> Subject: Re: [PATCH 5/7] migration/multifd: Add UADK based compression
> and decompression
>
> Shameer Kolothum via <qemu-devel@nongnu.org> writes:
>
> > Uses UADK wd_do_comp_sync() API to (de)compress a normal page using
> > hardware accelerator.
> >
> > Signed-off-by: Shameer Kolothum
> <shameerali.kolothum.thodi@huawei.com>
>
> A couple of comments below.
>
> Reviewed-by: Fabiano Rosas <farosas@suse.de>
> > ---
> > migration/multifd-uadk.c | 132
> ++++++++++++++++++++++++++++++++++++++-
> > 1 file changed, 130 insertions(+), 2 deletions(-)
> >
> > diff --git a/migration/multifd-uadk.c b/migration/multifd-uadk.c
> > index 3172e4d5ca..3329819bd4 100644
> > --- a/migration/multifd-uadk.c
> > +++ b/migration/multifd-uadk.c
> > @@ -13,6 +13,7 @@
> > #include "qemu/osdep.h"
> > #include "qemu/module.h"
> > #include "qapi/error.h"
> > +#include "exec/ramblock.h"
> > #include "migration.h"
> > #include "multifd.h"
> > #include "options.h"
> > @@ -140,6 +141,15 @@ static void
> multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
> > p->compress_data = NULL;
> > }
> >
> > +static inline void prepare_next_iov(MultiFDSendParams *p, void *base,
> > + uint32_t len)
> > +{
> > + p->iov[p->iovs_num].iov_base = (uint8_t *)base;
> > + p->iov[p->iovs_num].iov_len = len;
> > + p->next_packet_size += len;
> > + p->iovs_num++;
> > +}
> > +
> > /**
> > * multifd_uadk_send_prepare: prepare data to be able to send
> > *
> > @@ -153,7 +163,56 @@ static void
> multifd_uadk_send_cleanup(MultiFDSendParams *p, Error **errp)
> > */
> > static int multifd_uadk_send_prepare(MultiFDSendParams *p, Error
> **errp)
> > {
> > - return -1;
> > + struct wd_data *uadk_data = p->compress_data;
> > + uint32_t hdr_size;
> > + uint8_t *buf = uadk_data->buf;
> > + int ret = 0;
> > +
> > + if (!multifd_send_prepare_common(p)) {
> > + goto out;
> > + }
> > +
> > + hdr_size = p->pages->normal_num * sizeof(uint32_t);
> > + /* prepare the header that stores the lengths of all compressed data */
> > + prepare_next_iov(p, uadk_data->buf_hdr, hdr_size);
> > +
> > + for (int i = 0; i < p->pages->normal_num; i++) {
> > + struct wd_comp_req creq = {
> > + .op_type = WD_DIR_COMPRESS,
> > + .src = p->pages->block->host + p->pages->offset[i],
> > + .src_len = p->page_size,
> > + .dst = buf,
> > + /* Set dst_len to double the src to take care of -ve compression */
>
> What's -ve compression?
Just meant the case where output is > input. I can reword this.
>
> > + .dst_len = p->page_size * 2,
> > + };
> > +
> > + ret = wd_do_comp_sync(uadk_data->handle, &creq);
> > + if (ret || creq.status) {
> > + error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d
> status %d",
> > + p->id, ret, creq.status);
> > + return -1;
> > + }
> > + if (creq.dst_len < p->page_size) {
> > + uadk_data->buf_hdr[i] = cpu_to_be32(creq.dst_len);
> > + prepare_next_iov(p, buf, creq.dst_len);
> > + buf += creq.dst_len;
> > + } else {
> > + /*
> > + * Send raw data if compressed out >= page_size. We might be
> better
> > + * off sending raw data if output is slightly less than page_size
> > + * as well because at the receive end we can skip the
> decompression.
> > + * But it is tricky to find the right number here.
> > + */
> > + uadk_data->buf_hdr[i] = cpu_to_be32(p->page_size);
> > + prepare_next_iov(p, p->pages->block->host + p->pages->offset[i],
> > + p->page_size);
> > + buf += p->page_size;
> > + }
> > + }
> > +out:
> > + p->flags |= MULTIFD_FLAG_UADK;
> > + multifd_send_fill_packet(p);
> > + return 0;
> > }
> >
> > /**
> > @@ -206,7 +265,76 @@ static void
> multifd_uadk_recv_cleanup(MultiFDRecvParams *p)
> > */
> > static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)
> > {
> > - return -1;
> > + struct wd_data *uadk_data = p->compress_data;
> > + uint32_t in_size = p->next_packet_size;
> > + uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
> > + uint32_t hdr_len = p->normal_num * sizeof(uint32_t);
> > + uint32_t data_len = 0;
> > + uint8_t *buf = uadk_data->buf;
> > + int ret = 0;
> > +
> > + if (flags != MULTIFD_FLAG_UADK) {
> > + error_setg(errp, "multifd %u: flags received %x flags expected %x",
> > + p->id, flags, MULTIFD_FLAG_ZLIB);
> > + return -1;
> > + }
> > +
> > + multifd_recv_zero_page_process(p);
> > + if (!p->normal_num) {
> > + assert(in_size == 0);
> > + return 0;
> > + }
> > +
> > + /* read compressed data lengths */
> > + assert(hdr_len < in_size);
> > + ret = qio_channel_read_all(p->c, (void *) uadk_data->buf_hdr,
> > + hdr_len, errp);
> > + if (ret != 0) {
> > + return ret;
> > + }
> > +
> > + for (int i = 0; i < p->normal_num; i++) {
> > + uadk_data->buf_hdr[i] = be32_to_cpu(uadk_data->buf_hdr[i]);
> > + data_len += uadk_data->buf_hdr[i];
> > + assert(uadk_data->buf_hdr[i] <= p->page_size);
> > + }
> > +
> > + /* read compressed data */
> > + assert(in_size == hdr_len + data_len);
> > + ret = qio_channel_read_all(p->c, (void *)buf, data_len, errp);
> > + if (ret != 0) {
> > + return ret;
> > + }
> > +
> > + for (int i = 0; i < p->normal_num; i++) {
> > + struct wd_comp_req creq = {
> > + .op_type = WD_DIR_DECOMPRESS,
> > + .src = buf,
> > + .src_len = uadk_data->buf_hdr[i],
> > + .dst = p->host + p->normal[i],
> > + .dst_len = p->page_size,
> > + };
> > +
> > + if (uadk_data->buf_hdr[i] == p->page_size) {
> > + memcpy(p->host + p->normal[i], buf, p->page_size);
> > + buf += p->page_size;
> > + continue;
> > + }
> > +
> > + ret = wd_do_comp_sync(uadk_data->handle, &creq);
> > + if (ret || creq.status) {
> > + error_setg(errp, "multifd %u: failed wd_do_comp_sync, ret %d
> status %d",
> > + p->id, ret, creq.status);
>
> It would be nice to be able to tell compression from decompression in
> these error messages.
Ok. Will change.
Thanks,
Shameer
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2024-06-06 7:13 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-29 9:44 [PATCH 0/7] Live migration acceleration with UADK Shameer Kolothum via
2024-05-29 9:44 ` [PATCH 1/7] docs/migration: add uadk compression feature Shameer Kolothum via
2024-05-30 13:25 ` Liu, Yuan1
2024-05-30 14:01 ` Shameerali Kolothum Thodi via
2024-05-30 14:13 ` Liu, Yuan1
2024-06-05 18:59 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 2/7] configure: Add uadk option Shameer Kolothum via
2024-06-04 21:25 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 3/7] migration/multifd: add uadk compression framework Shameer Kolothum via
2024-05-29 11:10 ` Markus Armbruster
2024-05-30 6:56 ` Shameerali Kolothum Thodi via
2024-06-04 21:24 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 4/7] migration/multifd: Add UADK initialization Shameer Kolothum via
2024-06-05 14:58 ` Fabiano Rosas
2024-06-05 15:17 ` Shameerali Kolothum Thodi via
2024-05-29 9:44 ` [PATCH 5/7] migration/multifd: Add UADK based compression and decompression Shameer Kolothum via
2024-06-05 18:57 ` Fabiano Rosas
2024-06-06 7:11 ` Shameerali Kolothum Thodi via
2024-05-29 9:44 ` [PATCH 6/7] migration/multifd: Switch to no compression when no hardware support Shameer Kolothum via
2024-06-05 19:08 ` Fabiano Rosas
2024-05-29 9:44 ` [PATCH 7/7] tests/migration-test: add uadk compression test Shameer Kolothum via
2024-06-05 19:18 ` Fabiano Rosas
2024-06-04 20:59 ` [PATCH 0/7] Live migration acceleration with UADK Peter Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).