Skip to content

Commit

Permalink
Adapt jxiong:vectorized_fletcher (openzfs#4330) to
Browse files Browse the repository at this point in the history
  • Loading branch information
ironMann committed Mar 16, 2016
1 parent b378ac3 commit 904baa9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 64 deletions.
3 changes: 1 addition & 2 deletions include/sys/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ KERNEL_H = \
$(top_srcdir)/include/sys/zfs_ioctl.h \
$(top_srcdir)/include/sys/zfs_onexit.h \
${top_srcdir}/include/sys/zpl.h \
$(top_srcdir)/include/sys/zvol.h \
$(top_srcdir)/include/sys/platform_cpu_compat.h
$(top_srcdir)/include/sys/zvol.h

USER_H =

Expand Down
46 changes: 0 additions & 46 deletions include/sys/platform_cpu_compat.h

This file was deleted.

23 changes: 14 additions & 9 deletions module/zcommon/zfs_fletcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#include <sys/zio.h>
#include <sys/spa.h>
#include <zfs_fletcher.h>

void
Expand Down Expand Up @@ -256,10 +254,10 @@ fletcher_4_incremental_byteswap(const void *buf, uint64_t size,
fletcher_4_generic_byteswap(buf, size, zcp);
}


#if defined(_KERNEL) && defined(HAVE_SPL)
#include <sys/platform_cpu_compat.h>

#ifdef HAVE_KERNEL_CPU_AVX2
#if defined(HAVE_AVX) && defined(HAVE_AVX2)
#include "zfs_fletcher_intel.c"
#endif

Expand All @@ -270,15 +268,21 @@ static const struct fletcher_4_calls *fletcher_4_algos[] = {
#endif
};

#define BENCH_SIZE 4096
#define ZFS_ARRAY_SIZE(a) (sizeof (a) / sizeof (*a))
#define kernel_cpu_relax() do {} while (0)

/* cant use allocation methods from zfs module! */
static char databuf[BENCH_SIZE];

void
fletcher_4_init(void)
{
unsigned long bestperf = 0;
const void *databuf = current_text_addr();
const unsigned int bits = 4;
int i;

for (i = 0; i < ARRAY_SIZE(fletcher_4_algos); i++) {
for (i = 0; i < ZFS_ARRAY_SIZE(fletcher_4_algos); i++) {
const struct fletcher_4_calls *algo = fletcher_4_algos[i];
unsigned long perf = 0;
clock_t j0, j1;
Expand All @@ -288,12 +292,13 @@ fletcher_4_init(void)
continue;

kpreempt_disable();
j0 = lbolt;
while ((j1 = lbolt) == j0)
j0 = ddi_get_lbolt();
while ((j1 = ddi_get_lbolt()) == j0) {
kernel_cpu_relax();
}

algo->init(&zc);
while (ddi_time_before(lbolt, j1 + (1 << bits))) {
while (ddi_time_before(ddi_get_lbolt(), j1 + (1 << bits))) {
algo->compute(databuf, PAGE_SIZE, &zc);
perf++;
}
Expand Down
17 changes: 10 additions & 7 deletions module/zcommon/zfs_fletcher_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
* SOFTWARE.
*/

#if defined(HAVE_AVX) && defined(HAVE_AVX2)

#ifdef UNITTEST

#if defined(_KERNEL)
Expand All @@ -54,28 +56,27 @@
#include <stdbool.h>
#include <string.h>

#define kernel_fpu_save() do {} while (0)
#define kernel_fpu_restore() do {} while (0)
#define cpu_has_avx2 __builtin_cpu_supports("avx2")

typedef unsigned long long rlim64_t;

#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#include <sys/zio.h>
#include <sys/spa.h>

#include <zfs_fletcher.h>

#include "zfs_fletcher.c"
#endif /* #ifdef UNITTEST */

#include <linux/simd_x86.h>

static void
fletcher_4_avx2_init(zio_cksum_t *zcp)
{
ZIO_SET_CHECKSUM(zcp, 0, 0, 0, 0);

kernel_fpu_save();
kfpu_begin();

/* clear avx2 registers */
asm volatile("vpxor %ymm0, %ymm0, %ymm0");
Expand All @@ -98,7 +99,7 @@ fletcher_4_avx2_fini(zio_cksum_t *zcp)
asm volatile("vmovdqa %%ymm2, %0":"=m" (c));
asm volatile("vmovdqa %%ymm3, %0":"=m" (d));

kernel_fpu_restore();
kfpu_end();

A = a[0] + a[1] + a[2] + a[3];
B = 0 - a[1] - 2*a[2] - 3*a[3]
Expand Down Expand Up @@ -155,7 +156,7 @@ fletcher_4_avx2_byteswap(const void *buf, uint64_t size, zio_cksum_t *unused)

static boolean_t fletcher_4_avx2_valid(void)
{
return (cpu_has_avx2);
return (zfs_avx_available() && zfs_avx2_available());
}

static const struct fletcher_4_calls fletcher_4_avx2_calls = {
Expand Down Expand Up @@ -249,3 +250,5 @@ main(int argc, char **argv)
return (0);
}
#endif /* #ifdef UNITTEST */

#endif /* defined(HAVE_AVX) && defined(HAVE_AVX2) */

0 comments on commit 904baa9

Please sign in to comment.