diff options
author | Tino Reichardt <milky-zfs@mcmilk.de> | 2022-09-28 08:53:18 +0000 |
---|---|---|
committer | Brian Behlendorf <behlendorf1@llnl.gov> | 2023-03-02 21:51:56 +0000 |
commit | 589143c225c7bca1ef99148c6eae1291174ca584 (patch) | |
tree | a73b304b4a667031b0398d24a8f8a2356044df61 /include/os/freebsd/spl | |
parent | 6723d1110f6daf93be93db74d5ea9f6b64c9bce5 (diff) | |
download | src-589143c225c7bca1ef99148c6eae1291174ca584.tar.gz src-589143c225c7bca1ef99148c6eae1291174ca584.zip |
Add SHA2 SIMD feature tests for FreeBSD
These are added:
- zfs_neon_available() for arm and aarch64
- zfs_sha256_available() for arm and aarch64
- zfs_sha512_available() for aarch64
- zfs_shani_available() for x86_64
Changes:
- simd_powerpc.h: change license from CDDL to BSD
Tested-by: Rich Ercolani <rincebrain@gmail.com>
Tested-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
Closes #13741
Diffstat (limited to 'include/os/freebsd/spl')
-rw-r--r-- | include/os/freebsd/spl/sys/mod_os.h | 6 | ||||
-rw-r--r-- | include/os/freebsd/spl/sys/simd.h | 6 | ||||
-rw-r--r-- | include/os/freebsd/spl/sys/simd_aarch64.h | 83 | ||||
-rw-r--r-- | include/os/freebsd/spl/sys/simd_arm.h | 73 | ||||
-rw-r--r-- | include/os/freebsd/spl/sys/simd_powerpc.h | 50 | ||||
-rw-r--r-- | include/os/freebsd/spl/sys/simd_x86.h | 13 |
6 files changed, 203 insertions, 28 deletions
diff --git a/include/os/freebsd/spl/sys/mod_os.h b/include/os/freebsd/spl/sys/mod_os.h index 48e8a2adb8d2..77ce75ca3f11 100644 --- a/include/os/freebsd/spl/sys/mod_os.h +++ b/include/os/freebsd/spl/sys/mod_os.h @@ -97,6 +97,12 @@ #define blake3_param_set_args(var) \ CTLTYPE_STRING, NULL, 0, blake3_param, "A" +#define sha256_param_set_args(var) \ + CTLTYPE_STRING, NULL, 0, sha256_param, "A" + +#define sha512_param_set_args(var) \ + CTLTYPE_STRING, NULL, 0, sha512_param, "A" + #include <sys/kernel.h> #define module_init(fn) \ static void \ diff --git a/include/os/freebsd/spl/sys/simd.h b/include/os/freebsd/spl/sys/simd.h index 3106e4853c70..4560bb05e978 100644 --- a/include/os/freebsd/spl/sys/simd.h +++ b/include/os/freebsd/spl/sys/simd.h @@ -32,6 +32,12 @@ #if defined(__amd64__) || defined(__i386__) #include <sys/simd_x86.h> +#elif defined(__arm__) +#include <sys/simd_arm.h> + +#elif defined(__aarch64__) +#include <sys/simd_aarch64.h> + #elif defined(__powerpc__) #include <sys/simd_powerpc.h> diff --git a/include/os/freebsd/spl/sys/simd_aarch64.h b/include/os/freebsd/spl/sys/simd_aarch64.h new file mode 100644 index 000000000000..847c2ed29189 --- /dev/null +++ b/include/os/freebsd/spl/sys/simd_aarch64.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * SIMD support: + * + * Following functions should be called to determine whether CPU feature + * is supported. All functions are usable in kernel and user space. + * If a SIMD algorithm is using more than one instruction set + * all relevant feature test functions should be called. + * + * Supported features: + * zfs_neon_available() + * zfs_sha256_available() + * zfs_sha512_available() + */ + +#ifndef _FREEBSD_SIMD_AARCH64_H +#define _FREEBSD_SIMD_AARCH64_H + +#include <sys/types.h> +#include <machine/elf.h> + +#define kfpu_allowed() 1 +#define kfpu_initialize(tsk) do {} while (0) +#define kfpu_begin() do {} while (0) +#define kfpu_end() do {} while (0) +#define kfpu_init() (0) +#define kfpu_fini() do {} while (0) + +/* + * Check if NEON is available + */ +static inline boolean_t +zfs_neon_available(void) +{ + return (elf_hwcap & HWCAP_FP); +} + +/* + * Check if SHA256 is available + */ +static inline boolean_t +zfs_sha256_available(void) +{ + return (elf_hwcap & HWCAP_SHA2); +} + +/* + * Check if SHA512 is available + */ +static inline boolean_t +zfs_sha512_available(void) +{ + return (elf_hwcap & HWCAP_SHA512); +} + +#endif /* _FREEBSD_SIMD_AARCH64_H */ diff --git a/include/os/freebsd/spl/sys/simd_arm.h b/include/os/freebsd/spl/sys/simd_arm.h new file mode 100644 index 000000000000..f6362cd6bb54 --- /dev/null +++ b/include/os/freebsd/spl/sys/simd_arm.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * SIMD support: + * + * Following functions should be called to determine whether CPU feature + * is supported. All functions are usable in kernel and user space. + * If a SIMD algorithm is using more than one instruction set + * all relevant feature test functions should be called. + * + * Supported features: + * zfs_neon_available() + * zfs_sha256_available() + */ + +#ifndef _FREEBSD_SIMD_ARM_H +#define _FREEBSD_SIMD_ARM_H + +#include <sys/types.h> +#include <machine/elf.h> + +#define kfpu_allowed() 1 +#define kfpu_initialize(tsk) do {} while (0) +#define kfpu_begin() do {} while (0) +#define kfpu_end() do {} while (0) +#define kfpu_init() (0) +#define kfpu_fini() do {} while (0) + +/* + * Check if NEON is available + */ +static inline boolean_t +zfs_neon_available(void) +{ + return (elf_hwcap & HWCAP_NEON); +} + +/* + * Check if SHA256 is available + */ +static inline boolean_t +zfs_sha256_available(void) +{ + return (elf_hwcap2 & HWCAP2_SHA2); +} + +#endif /* _FREEBSD_SIMD_ARM_H */ diff --git a/include/os/freebsd/spl/sys/simd_powerpc.h b/include/os/freebsd/spl/sys/simd_powerpc.h index 34d5e23e2fbb..edaab81d15fc 100644 --- a/include/os/freebsd/spl/sys/simd_powerpc.h +++ b/include/os/freebsd/spl/sys/simd_powerpc.h @@ -1,38 +1,32 @@ /* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. + * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de> + * All rights reserved. * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or https://opensource.org/licenses/CDDL-1.0. - * See the License for the specific language governing permissions - * and limitations under the License. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * - * CDDL HEADER END - */ - -/* - * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de> + * $FreeBSD$ */ /* - * USER API: - * - * Kernel fpu methods: - * kfpu_allowed() - * kfpu_begin() - * kfpu_end() - * kfpu_init() - * kfpu_fini() - * * SIMD support: * * Following functions should be called to determine whether CPU feature diff --git a/include/os/freebsd/spl/sys/simd_x86.h b/include/os/freebsd/spl/sys/simd_x86.h index 7a0ca243f768..6512d4fcba4f 100644 --- a/include/os/freebsd/spl/sys/simd_x86.h +++ b/include/os/freebsd/spl/sys/simd_x86.h @@ -174,6 +174,19 @@ zfs_avx2_available(void) } /* + * Check if SHA_NI instruction set is available + */ +static inline boolean_t +zfs_shani_available(void) +{ + boolean_t has_shani; + + has_shani = (cpu_stdext_feature & CPUID_STDEXT_SHA) != 0; + + return (has_shani && __ymm_enabled()); +} + +/* * AVX-512 family of instruction sets: * * AVX512F Foundation |