Skip to content

Commit

Permalink
Ensure kfpu_begin()/end() are in same scope.
Browse files Browse the repository at this point in the history
For the variabe defined inside kfpu_begin().

Use kfpu_begin_ctx() for the split init/fini functions.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Mar 17, 2023
1 parent 27b335c commit 9465db8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
8 changes: 8 additions & 0 deletions include/os/windows/spl/sys/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ extern uint32_t kfpu_state;
if (NT_SUCCESS(saveStatus)) \
KeRestoreExtendedProcessorState(&SaveState);

#define kfpu_begin_ctx(O) \
(O)->saveStatus = \
KeSaveExtendedProcessorState(kfpu_state, &(O)->SaveState);

#define kfpu_end_ctx(O) \
if (NT_SUCCESS(((O)->saveStatus))) \
KeRestoreExtendedProcessorState(&(O)->SaveState);

/*
* CPUID feature tests for user-space. Linux kernel provides an interface for
* CPU feature testing.
Expand Down
4 changes: 4 additions & 0 deletions include/sys/zio_checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ typedef struct zio_abd_checksum_data {
fletcher_4_ctx_t *acd_ctx;
zio_cksum_t *acd_zcp;
void *acd_private;
#if defined(_WIN32) && defined(_KERNEL)
NTSTATUS saveStatus;
XSTATE_SAVE SaveState;
#endif
} zio_abd_checksum_data_t;

typedef void zio_abd_checksum_init_t(zio_abd_checksum_data_t *);
Expand Down
40 changes: 26 additions & 14 deletions module/zcommon/zfs_fletcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,14 @@ fletcher_4_native_impl(const void *buf, uint64_t size, zio_cksum_t *zcp)

if (ops->uses_fpu == B_TRUE) {
kfpu_begin();
}
ops->init_native(&ctx);
ops->compute_native(&ctx, buf, size);
ops->fini_native(&ctx, zcp);
if (ops->uses_fpu == B_TRUE) {
ops->init_native(&ctx);
ops->compute_native(&ctx, buf, size);
ops->fini_native(&ctx, zcp);
kfpu_end();
} else {
ops->init_native(&ctx);
ops->compute_native(&ctx, buf, size);
ops->fini_native(&ctx, zcp);
}
}

Expand Down Expand Up @@ -509,12 +511,14 @@ fletcher_4_byteswap_impl(const void *buf, uint64_t size, zio_cksum_t *zcp)

if (ops->uses_fpu == B_TRUE) {
kfpu_begin();
}
ops->init_byteswap(&ctx);
ops->compute_byteswap(&ctx, buf, size);
ops->fini_byteswap(&ctx, zcp);
if (ops->uses_fpu == B_TRUE) {
ops->init_byteswap(&ctx);
ops->compute_byteswap(&ctx, buf, size);
ops->fini_byteswap(&ctx, zcp);
kfpu_end();
} else {
ops->init_byteswap(&ctx);
ops->compute_byteswap(&ctx, buf, size);
ops->fini_byteswap(&ctx, zcp);
}
}

Expand Down Expand Up @@ -748,12 +752,12 @@ fletcher_4_benchmark_impl(boolean_t native, char *data, uint64_t data_size)
static void
fletcher_4_benchmark(void)
{
fletcher_4_ops_t *curr_impl;
const fletcher_4_ops_t *curr_impl;
int i, c;

/* Move supported implementations into fletcher_4_supp_impls */
for (i = 0, c = 0; i < ARRAY_SIZE(fletcher_4_impls); i++) {
curr_impl = (fletcher_4_ops_t *)fletcher_4_impls[i];
curr_impl = (const fletcher_4_ops_t *)fletcher_4_impls[i];

if (curr_impl->valid && curr_impl->valid())
fletcher_4_supp_impls[c++] = curr_impl;
Expand Down Expand Up @@ -831,7 +835,11 @@ abd_fletcher_4_init(zio_abd_checksum_data_t *cdp)
cdp->acd_private = (void *) ops;

if (ops->uses_fpu == B_TRUE) {
#if defined(_WIN32) && defined(_KERNEL)
kfpu_begin_ctx(cdp);
#else
kfpu_begin();
#endif
}
if (cdp->acd_byteorder == ZIO_CHECKSUM_NATIVE)
ops->init_native(cdp->acd_ctx);
Expand All @@ -843,7 +851,7 @@ abd_fletcher_4_init(zio_abd_checksum_data_t *cdp)
static void
abd_fletcher_4_fini(zio_abd_checksum_data_t *cdp)
{
fletcher_4_ops_t *ops = (fletcher_4_ops_t *)cdp->acd_private;
const fletcher_4_ops_t *ops = (fletcher_4_ops_t *)cdp->acd_private;

ASSERT(ops);

Expand All @@ -853,7 +861,11 @@ abd_fletcher_4_fini(zio_abd_checksum_data_t *cdp)
ops->fini_byteswap(cdp->acd_ctx, cdp->acd_zcp);

if (ops->uses_fpu == B_TRUE) {
#if defined(_WIN32) && defined(_KERNEL)
kfpu_end_ctx(cdp);
#else
kfpu_end();
#endif
}
}

Expand All @@ -880,7 +892,7 @@ abd_fletcher_4_iter(void *data, size_t size, void *private)
{
zio_abd_checksum_data_t *cdp = (zio_abd_checksum_data_t *)private;
fletcher_4_ctx_t *ctx = cdp->acd_ctx;
fletcher_4_ops_t *ops = (fletcher_4_ops_t *)cdp->acd_private;
const fletcher_4_ops_t *ops = (fletcher_4_ops_t *)cdp->acd_private;
boolean_t native = cdp->acd_byteorder == ZIO_CHECKSUM_NATIVE;
uint64_t asize = P2ALIGN(size, FLETCHER_MIN_SIMD_SIZE);

Expand Down

0 comments on commit 9465db8

Please sign in to comment.