aboutsummaryrefslogtreecommitdiff
path: root/migration
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2023-05-17 20:00:30 -0700
committerRichard Henderson <richard.henderson@linaro.org>2023-05-23 16:51:18 -0700
commit7ba7db9fa101f59cd42cc8ead8a83b121a852943 (patch)
tree6ca3b59ea82b7d2629346e1fb88823c38bbccb30 /migration
parent1b48d0abdf3b723f2d0f91172dcc9f89d50a92ce (diff)
migration/xbzrle: Use i386 host/cpuinfo.h
Perform the function selection once, and only if CONFIG_AVX512_OPT is enabled. Centralize the selection to xbzrle.c, instead of spreading the init across 3 files. Remove xbzrle-bench.c. The benefit of being able to benchmark the different implementations is less important than not peeking into the internals of the implementation. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'migration')
-rw-r--r--migration/ram.c34
-rw-r--r--migration/xbzrle.c26
-rw-r--r--migration/xbzrle.h5
3 files changed, 29 insertions, 36 deletions
diff --git a/migration/ram.c b/migration/ram.c
index 9fb076fa58..88a6c82e63 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -90,34 +90,6 @@
#define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x200
/* We can't use any flag that is bigger than 0x200 */
-int (*xbzrle_encode_buffer_func)(uint8_t *, uint8_t *, int,
- uint8_t *, int) = xbzrle_encode_buffer;
-#if defined(CONFIG_AVX512BW_OPT)
-#include "qemu/cpuid.h"
-static void __attribute__((constructor)) init_cpu_flag(void)
-{
- unsigned max = __get_cpuid_max(0, NULL);
- int a, b, c, d;
- if (max >= 1) {
- __cpuid(1, a, b, c, d);
- /* We must check that AVX is not just available, but usable. */
- if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >= 7) {
- int bv;
- __asm("xgetbv" : "=a"(bv), "=d"(d) : "c"(0));
- __cpuid_count(7, 0, a, b, c, d);
- /* 0xe6:
- * XCR0[7:5] = 111b (OPMASK state, upper 256-bit of ZMM0-ZMM15
- * and ZMM16-ZMM31 state are enabled by OS)
- * XCR0[2:1] = 11b (XMM state and YMM state are enabled by OS)
- */
- if ((bv & 0xe6) == 0xe6 && (b & bit_AVX512BW)) {
- xbzrle_encode_buffer_func = xbzrle_encode_buffer_avx512;
- }
- }
- }
-}
-#endif
-
XBZRLECacheStats xbzrle_counters;
/* used by the search for pages to send */
@@ -660,9 +632,9 @@ static int save_xbzrle_page(RAMState *rs, PageSearchStatus *pss,
memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE);
/* XBZRLE encoding (if there is no overflow) */
- encoded_len = xbzrle_encode_buffer_func(prev_cached_page, XBZRLE.current_buf,
- TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
- TARGET_PAGE_SIZE);
+ encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,
+ TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
+ TARGET_PAGE_SIZE);
/*
* Update the cache contents, so that it corresponds to the data
diff --git a/migration/xbzrle.c b/migration/xbzrle.c
index 751b5428f7..3eddcf249b 100644
--- a/migration/xbzrle.c
+++ b/migration/xbzrle.c
@@ -17,8 +17,9 @@
#if defined(CONFIG_AVX512BW_OPT)
#include <immintrin.h>
+#include "host/cpuinfo.h"
-int __attribute__((target("avx512bw")))
+static int __attribute__((target("avx512bw")))
xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
uint8_t *dst, int dlen)
{
@@ -135,6 +136,29 @@ xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
}
return d;
}
+
+static int xbzrle_encode_buffer_int(uint8_t *old_buf, uint8_t *new_buf,
+ int slen, uint8_t *dst, int dlen);
+
+static int (*accel_func)(uint8_t *, uint8_t *, int, uint8_t *, int);
+
+static void __attribute__((constructor)) init_accel(void)
+{
+ unsigned info = cpuinfo_init();
+ if (info & CPUINFO_AVX512BW) {
+ accel_func = xbzrle_encode_buffer_avx512;
+ } else {
+ accel_func = xbzrle_encode_buffer_int;
+ }
+}
+
+int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
+ uint8_t *dst, int dlen)
+{
+ return accel_func(old_buf, new_buf, slen, dst, dlen);
+}
+
+#define xbzrle_encode_buffer xbzrle_encode_buffer_int
#endif
/*
diff --git a/migration/xbzrle.h b/migration/xbzrle.h
index 6feb49160a..39e651b9ec 100644
--- a/migration/xbzrle.h
+++ b/migration/xbzrle.h
@@ -18,8 +18,5 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
uint8_t *dst, int dlen);
int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
-#if defined(CONFIG_AVX512BW_OPT)
-int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
- uint8_t *dst, int dlen);
-#endif
+
#endif