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 18, 2023
1 parent 6b57fe1 commit fe8822b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 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
32 changes: 22 additions & 10 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 @@ -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 @@ -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 Down

0 comments on commit fe8822b

Please sign in to comment.