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>
This commit is contained in:
parent
1b48d0abdf
commit
7ba7db9fa1
6 changed files with 39 additions and 550 deletions
|
|
@ -16,35 +16,6 @@
|
|||
|
||||
#define XBZRLE_PAGE_SIZE 4096
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void test_uleb(void)
|
||||
{
|
||||
uint32_t i, val;
|
||||
|
|
@ -83,8 +54,8 @@ static void test_encode_decode_zero(void)
|
|||
buffer[1000 + diff_len + 5] = 105;
|
||||
|
||||
/* encode zero page */
|
||||
dlen = xbzrle_encode_buffer_func(buffer, buffer, XBZRLE_PAGE_SIZE, compressed,
|
||||
XBZRLE_PAGE_SIZE);
|
||||
dlen = xbzrle_encode_buffer(buffer, buffer, XBZRLE_PAGE_SIZE,
|
||||
compressed, XBZRLE_PAGE_SIZE);
|
||||
g_assert(dlen == 0);
|
||||
|
||||
g_free(buffer);
|
||||
|
|
@ -107,8 +78,8 @@ static void test_encode_decode_unchanged(void)
|
|||
test[1000 + diff_len + 5] = 109;
|
||||
|
||||
/* test unchanged buffer */
|
||||
dlen = xbzrle_encode_buffer_func(test, test, XBZRLE_PAGE_SIZE, compressed,
|
||||
XBZRLE_PAGE_SIZE);
|
||||
dlen = xbzrle_encode_buffer(test, test, XBZRLE_PAGE_SIZE,
|
||||
compressed, XBZRLE_PAGE_SIZE);
|
||||
g_assert(dlen == 0);
|
||||
|
||||
g_free(test);
|
||||
|
|
@ -125,8 +96,8 @@ static void test_encode_decode_1_byte(void)
|
|||
|
||||
test[XBZRLE_PAGE_SIZE - 1] = 1;
|
||||
|
||||
dlen = xbzrle_encode_buffer_func(buffer, test, XBZRLE_PAGE_SIZE, compressed,
|
||||
XBZRLE_PAGE_SIZE);
|
||||
dlen = xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE,
|
||||
compressed, XBZRLE_PAGE_SIZE);
|
||||
g_assert(dlen == (uleb128_encode_small(&buf[0], 4095) + 2));
|
||||
|
||||
rc = xbzrle_decode_buffer(compressed, dlen, buffer, XBZRLE_PAGE_SIZE);
|
||||
|
|
@ -150,8 +121,8 @@ static void test_encode_decode_overflow(void)
|
|||
}
|
||||
|
||||
/* encode overflow */
|
||||
rc = xbzrle_encode_buffer_func(buffer, test, XBZRLE_PAGE_SIZE, compressed,
|
||||
XBZRLE_PAGE_SIZE);
|
||||
rc = xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE,
|
||||
compressed, XBZRLE_PAGE_SIZE);
|
||||
g_assert(rc == -1);
|
||||
|
||||
g_free(buffer);
|
||||
|
|
@ -181,8 +152,8 @@ static void encode_decode_range(void)
|
|||
test[1000 + diff_len + 5] = 109;
|
||||
|
||||
/* test encode/decode */
|
||||
dlen = xbzrle_encode_buffer_func(test, buffer, XBZRLE_PAGE_SIZE, compressed,
|
||||
XBZRLE_PAGE_SIZE);
|
||||
dlen = xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE,
|
||||
compressed, XBZRLE_PAGE_SIZE);
|
||||
|
||||
rc = xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE);
|
||||
g_assert(rc < XBZRLE_PAGE_SIZE);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue