From 4e419aa8624a6846ac9e126bb853e8b7471be2c9 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 16 Sep 2014 21:58:29 +0200 Subject: [PATCH] Extends tests to use AVX2 functions. --- cmdline/speed.c | 104 ++++++++++++++++++++++++-- raid/cpu.h | 2 +- raid/test.c | 12 ++- raid/test/fulltest.c | 2 + raid/test/speedtest.c | 167 +++++++++++++++++++++++++++++++++++++++++- raid/x86z.c | 2 +- 6 files changed, 278 insertions(+), 11 deletions(-) diff --git a/cmdline/speed.c b/cmdline/speed.c index 7b1b76c1..07f5e863 100644 --- a/cmdline/speed.c +++ b/cmdline/speed.c @@ -127,7 +127,7 @@ void speed(int period) raid_cpu_has_sse2() ? " sse2" : "", raid_cpu_has_ssse3() ? " ssse3" : "", raid_cpu_has_sse42() ? " sse42" : "", - raid_cpu_has_avx2() ? "avx2" : "", + raid_cpu_has_avx2() ? " avx2" : "", raid_cpu_has_slowmult() ? " slowmult" : "", raid_cpu_has_slowpshufb() ? " slowpshufb" : "", raid_cpu_has_slowextendedreg() ? " slowext" : "" @@ -156,7 +156,7 @@ void speed(int period) printf("Speed test using %u data buffers of %u bytes, for a total of %u KiB.\n", nd, size, nd * size / 1024); printf("Memory blocks have a displacement of %u bytes to improve cache performance.\n", RAID_MALLOC_DISPLACEMENT); - printf("The reported value is the aggregate bandwidth of all data blocks in MiB/s,\n"); + printf("The reported values are the aggregate bandwidth of all data blocks in MiB/s,\n"); printf("not counting parity blocks.\n"); printf("\n"); @@ -478,10 +478,6 @@ void speed(int period) } printf("%8s", ""); -#ifdef CONFIG_X86_64 - printf("%8s", ""); -#endif - printf("%8s", ""); #ifdef CONFIG_X86_64 if (raid_cpu_has_avx2()) { @@ -539,6 +535,19 @@ void speed(int period) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen4_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); @@ -585,6 +594,19 @@ void speed(int period) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen5_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); @@ -631,6 +653,19 @@ void speed(int period) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen6_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); printf("\n"); @@ -642,6 +677,7 @@ void speed(int period) printf("%8s", "int8"); #ifdef CONFIG_X86 printf("%8s", "ssse3"); + printf("%8s", "avx2"); #endif printf("\n"); @@ -668,6 +704,16 @@ void speed(int period) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + /* +1 to avoid GEN1 optimized case */ + raid_rec1_avx2(1, id, ip + 1, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -694,6 +740,16 @@ void speed(int period) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + /* +1 to avoid GEN1 optimized case */ + raid_rec2_avx2(2, id, ip + 1, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -718,6 +774,15 @@ void speed(int period) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(3, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -742,6 +807,15 @@ void speed(int period) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(4, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -766,6 +840,15 @@ void speed(int period) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(5, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -790,6 +873,15 @@ void speed(int period) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(6, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); printf("\n"); diff --git a/raid/cpu.h b/raid/cpu.h index 164321f2..c0c5793c 100644 --- a/raid/cpu.h +++ b/raid/cpu.h @@ -138,7 +138,7 @@ static inline int raid_cpu_has_avx2(void) if (!raid_cpu_has_xsavexrstor()) return 0; - /* check if the OS suports AVX2 registers */ + /* check if the OS supports AVX2 registers */ if (!raid_os_support_256bit_regs()) return 0; diff --git a/raid/test.c b/raid/test.c index 0fd8e981..7e3a7cef 100644 --- a/raid/test.c +++ b/raid/test.c @@ -185,18 +185,24 @@ int raid_test_rec(int mode, int nd, size_t size) #ifdef CONFIG_X86 if (raid_cpu_has_ssse3()) f[i][nf[i]++] = raid_rec1_ssse3; + if (raid_cpu_has_avx2()) + f[i][nf[i]++] = raid_rec1_avx2; #endif } else if (i == 1) { f[i][nf[i]++] = raid_rec2_int8; #ifdef CONFIG_X86 if (raid_cpu_has_ssse3()) f[i][nf[i]++] = raid_rec2_ssse3; + if (raid_cpu_has_avx2()) + f[i][nf[i]++] = raid_rec2_avx2; #endif } else { f[i][nf[i]++] = raid_recX_int8; #ifdef CONFIG_X86 if (raid_cpu_has_ssse3()) f[i][nf[i]++] = raid_recX_ssse3; + if (raid_cpu_has_avx2()) + f[i][nf[i]++] = raid_recX_avx2; #endif } } @@ -339,6 +345,9 @@ int raid_test_par(int mode, int nd, size_t size) #ifdef CONFIG_X86_64 if (raid_cpu_has_avx2()) { f[nf++] = raid_gen3_avx2ext; + f[nf++] = raid_gen4_avx2ext; + f[nf++] = raid_gen5_avx2ext; + f[nf++] = raid_gen6_avx2ext; } #endif #endif @@ -355,9 +364,8 @@ int raid_test_par(int mode, int nd, size_t size) } #ifdef CONFIG_X86_64 - if (raid_cpu_has_avx2()) { + if (raid_cpu_has_avx2()) f[nf++] = raid_genz_avx2ext; - } #endif #endif } diff --git a/raid/test/fulltest.c b/raid/test/fulltest.c index c4918bac..fd9d0278 100644 --- a/raid/test/fulltest.c +++ b/raid/test/fulltest.c @@ -46,6 +46,8 @@ int main(void) printf("Including x86 SSE2 functions\n"); if (raid_cpu_has_ssse3()) printf("Including x86 SSSE3 functions\n"); + if (raid_cpu_has_avx2()) + printf("Including x86 AVX2 functions\n"); #endif #ifdef CONFIG_X86_64 printf("Including x64 extended SSE register set\n"); diff --git a/raid/test/speedtest.c b/raid/test/speedtest.c index 6cdfb1c9..d605ccc5 100644 --- a/raid/test/speedtest.c +++ b/raid/test/speedtest.c @@ -112,7 +112,7 @@ void speed(void) printf("Speed test using %u data buffers of %u bytes, for a total of %u KiB.\n", nd, size, nd * size / 1024); printf("Memory blocks have a displacement of %u bytes to improve cache performance.\n", RAID_MALLOC_DISPLACEMENT); - printf("The reported value is the aggregate bandwidth of all data blocks in MiB/s,\n"); + printf("The reported values are the aggregate bandwidth of all data blocks in MiB/s,\n"); printf("not counting parity blocks.\n"); printf("\n"); @@ -144,6 +144,10 @@ void speed(void) printf("%8s", "ssse3"); #ifdef CONFIG_X86_64 printf("%8s", "ssse3e"); +#endif + printf("%8s", "avx2"); +#ifdef CONFIG_X86_64 + printf("%8s", "avx2e"); #endif #endif printf("\n"); @@ -175,6 +179,23 @@ void speed(void) raid_gen1_sse2(nd, size, v); } SPEED_STOP + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } + +#ifdef CONFIG_X86_64 + printf("%8s", ""); +#endif + printf("%8s", ""); +#ifdef CONFIG_X86_64 + printf("%8s", ""); +#endif + + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen1_avx2(nd, size, v); + } SPEED_STOP + printf("%8"PRIu64, ds / dt); fflush(stdout); } @@ -218,8 +239,24 @@ void speed(void) printf("%8"PRIu64, ds / dt); fflush(stdout); +#else + printf("%8s", ""); #endif } + + printf("%8s", ""); +#ifdef CONFIG_X86_64 + printf("%8s", ""); +#endif + + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen2_avx2(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } #endif printf("\n"); @@ -262,6 +299,23 @@ void speed(void) fflush(stdout); #endif } + + printf("%8s", ""); +#ifdef CONFIG_X86_64 + printf("%8s", ""); +#endif + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_genz_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); @@ -308,6 +362,19 @@ void speed(void) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen3_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); @@ -354,6 +421,19 @@ void speed(void) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen4_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); @@ -400,6 +480,19 @@ void speed(void) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen5_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); @@ -446,6 +539,19 @@ void speed(void) fflush(stdout); #endif } + + printf("%8s", ""); + +#ifdef CONFIG_X86_64 + if (raid_cpu_has_avx2()) { + SPEED_START { + raid_gen6_avx2ext(nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + fflush(stdout); + } +#endif #endif printf("\n"); printf("\n"); @@ -457,6 +563,7 @@ void speed(void) printf("%8s", "int8"); #ifdef CONFIG_X86 printf("%8s", "ssse3"); + printf("%8s", "avx2"); #endif printf("\n"); @@ -483,6 +590,16 @@ void speed(void) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + /* +1 to avoid GEN1 optimized case */ + raid_rec1_avx2(1, id, ip + 1, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -509,6 +626,16 @@ void speed(void) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + /* +1 to avoid GEN1 optimized case */ + raid_rec2_avx2(2, id, ip + 1, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -533,6 +660,15 @@ void speed(void) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(3, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -557,6 +693,15 @@ void speed(void) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(4, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -581,6 +726,15 @@ void speed(void) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(5, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); @@ -605,6 +759,15 @@ void speed(void) printf("%8"PRIu64, ds / dt); } + + if (raid_cpu_has_avx2()) { + SPEED_START { + for (j = 0; j < nd; ++j) + raid_recX_avx2(6, id, ip, nd, size, v); + } SPEED_STOP + + printf("%8"PRIu64, ds / dt); + } #endif printf("\n"); printf("\n"); @@ -624,6 +787,8 @@ int main(void) printf("Including x86 SSE2 functions\n"); if (raid_cpu_has_ssse3()) printf("Including x86 SSSE3 functions\n"); + if (raid_cpu_has_avx2()) + printf("Including x86 AVX2 functions\n"); #endif #ifdef CONFIG_X86_64 printf("Including x64 extended SSE register set\n"); diff --git a/raid/x86z.c b/raid/x86z.c index 45f168cc..7f7d2892 100644 --- a/raid/x86z.c +++ b/raid/x86z.c @@ -19,7 +19,7 @@ static const struct gfzconst16 { uint8_t poly[16]; uint8_t half[16]; uint8_t low7[16]; -} gfzconst16 __aligned(64) = { +} gfzconst16 __aligned(64) = { { 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d