test: select memcpy alignment unit at run-time

This patch modifies assignment of alignment unit from build-time
to run-time based on CPU flags that machine supports.

Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
This commit is contained in:
Xiaoyun Li 2017-10-13 17:01:48 +08:00 committed by Thomas Monjalon
parent 84cc318424
commit c7fbc80fe6

View File

@ -42,6 +42,7 @@
#include <rte_malloc.h> #include <rte_malloc.h>
#include <rte_memcpy.h> #include <rte_memcpy.h>
#include <rte_cpuflags.h>
#include "test.h" #include "test.h"
@ -79,13 +80,7 @@ static size_t buf_sizes[TEST_VALUE_RANGE];
#define TEST_BATCH_SIZE 100 #define TEST_BATCH_SIZE 100
/* Data is aligned on this many bytes (power of 2) */ /* Data is aligned on this many bytes (power of 2) */
#ifdef RTE_MACHINE_CPUFLAG_AVX512F static uint8_t alignment_unit = 16;
#define ALIGNMENT_UNIT 64
#elif defined RTE_MACHINE_CPUFLAG_AVX2
#define ALIGNMENT_UNIT 32
#else /* RTE_MACHINE_CPUFLAG */
#define ALIGNMENT_UNIT 16
#endif /* RTE_MACHINE_CPUFLAG */
/* /*
* Pointers used in performance tests. The two large buffers are for uncached * Pointers used in performance tests. The two large buffers are for uncached
@ -95,25 +90,54 @@ static size_t buf_sizes[TEST_VALUE_RANGE];
static uint8_t *large_buf_read, *large_buf_write; static uint8_t *large_buf_read, *large_buf_write;
static uint8_t *small_buf_read, *small_buf_write; static uint8_t *small_buf_read, *small_buf_write;
/* Initialise alignment_unit based on machine at run-time. */
static void
init_alignment_unit(void)
{
#ifdef CC_SUPPORT_AVX512
if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F)) {
alignment_unit = 64;
return;
}
#endif
#ifdef CC_SUPPORT_AVX2
if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2)) {
alignment_unit = 32;
return;
}
#endif
alignment_unit = 16;
}
/* Initialise data buffers. */ /* Initialise data buffers. */
static int static int
init_buffers(void) init_buffers(void)
{ {
unsigned i; unsigned i;
large_buf_read = rte_malloc("memcpy", LARGE_BUFFER_SIZE + ALIGNMENT_UNIT, ALIGNMENT_UNIT); init_alignment_unit();
large_buf_read = rte_malloc("memcpy",
LARGE_BUFFER_SIZE + alignment_unit,
alignment_unit);
if (large_buf_read == NULL) if (large_buf_read == NULL)
goto error_large_buf_read; goto error_large_buf_read;
large_buf_write = rte_malloc("memcpy", LARGE_BUFFER_SIZE + ALIGNMENT_UNIT, ALIGNMENT_UNIT); large_buf_write = rte_malloc("memcpy",
LARGE_BUFFER_SIZE + alignment_unit,
alignment_unit);
if (large_buf_write == NULL) if (large_buf_write == NULL)
goto error_large_buf_write; goto error_large_buf_write;
small_buf_read = rte_malloc("memcpy", SMALL_BUFFER_SIZE + ALIGNMENT_UNIT, ALIGNMENT_UNIT); small_buf_read = rte_malloc("memcpy",
SMALL_BUFFER_SIZE + alignment_unit,
alignment_unit);
if (small_buf_read == NULL) if (small_buf_read == NULL)
goto error_small_buf_read; goto error_small_buf_read;
small_buf_write = rte_malloc("memcpy", SMALL_BUFFER_SIZE + ALIGNMENT_UNIT, ALIGNMENT_UNIT); small_buf_write = rte_malloc("memcpy",
SMALL_BUFFER_SIZE + alignment_unit,
alignment_unit);
if (small_buf_write == NULL) if (small_buf_write == NULL)
goto error_small_buf_write; goto error_small_buf_write;
@ -153,7 +177,7 @@ static inline size_t
get_rand_offset(size_t uoffset) get_rand_offset(size_t uoffset)
{ {
return ((rte_rand() % (LARGE_BUFFER_SIZE - SMALL_BUFFER_SIZE)) & return ((rte_rand() % (LARGE_BUFFER_SIZE - SMALL_BUFFER_SIZE)) &
~(ALIGNMENT_UNIT - 1)) + uoffset; ~(alignment_unit - 1)) + uoffset;
} }
/* Fill in source and destination addresses. */ /* Fill in source and destination addresses. */
@ -321,7 +345,8 @@ perf_test(void)
"(bytes) (ticks) (ticks) (ticks) (ticks)\n" "(bytes) (ticks) (ticks) (ticks) (ticks)\n"
"------- -------------- -------------- -------------- --------------"); "------- -------------- -------------- -------------- --------------");
printf("\n========================== %2dB aligned ============================", ALIGNMENT_UNIT); printf("\n========================= %2dB aligned ============================",
alignment_unit);
/* Do aligned tests where size is a variable */ /* Do aligned tests where size is a variable */
perf_test_variable_aligned(); perf_test_variable_aligned();
printf("\n------- -------------- -------------- -------------- --------------"); printf("\n------- -------------- -------------- -------------- --------------");