mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-14 19:53:03 +00:00

Add x86_64 [V]PCLMULQDQ optimized implementations of crc64_be() and crc64_nvme() by wiring them up to crc-pclmul-template.S. crc64_be() is used by bcache and bcachefs, and crc64_nvme() is used by blk-integrity. Both features can CRC large amounts of data, and the developers of both features have expressed interest in having these CRCs be optimized. So this optimization should be worthwhile. (See https://lore.kernel.org/r/v36sousjd5ukqlkpdxslvpu7l37zbu7d7slgc2trjjqwty2bny@qgzew34feo2r and https://lore.kernel.org/r/20220222163144.1782447-11-kbusch@kernel.org) Benchmark results on AMD Ryzen 9 9950X (Zen 5) using crc_kunit: crc64_be: Length Before After ------ ------ ----- 1 633 MB/s 477 MB/s 16 717 MB/s 2517 MB/s 64 715 MB/s 7525 MB/s 127 714 MB/s 10002 MB/s 128 713 MB/s 13344 MB/s 200 715 MB/s 15752 MB/s 256 714 MB/s 22933 MB/s 511 715 MB/s 28025 MB/s 512 714 MB/s 49772 MB/s 1024 715 MB/s 65261 MB/s 3173 714 MB/s 78773 MB/s 4096 714 MB/s 83315 MB/s 16384 714 MB/s 89487 MB/s crc64_nvme: Length Before After ------ ------ ----- 1 716 MB/s 474 MB/s 16 717 MB/s 3303 MB/s 64 713 MB/s 7940 MB/s 127 715 MB/s 9867 MB/s 128 714 MB/s 13698 MB/s 200 715 MB/s 15995 MB/s 256 714 MB/s 23479 MB/s 511 714 MB/s 28013 MB/s 512 715 MB/s 51533 MB/s 1024 715 MB/s 66788 MB/s 3173 715 MB/s 79182 MB/s 4096 715 MB/s 83966 MB/s 16384 715 MB/s 89739 MB/s Acked-by: Keith Busch <kbusch@kernel.org> Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20250210174540.161705-7-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* CRC64 using [V]PCLMULQDQ instructions
|
|
*
|
|
* Copyright 2025 Google LLC
|
|
*/
|
|
|
|
#include <linux/crc64.h>
|
|
#include <linux/module.h>
|
|
#include "crc-pclmul-template.h"
|
|
|
|
static DEFINE_STATIC_KEY_FALSE(have_pclmulqdq);
|
|
|
|
DECLARE_CRC_PCLMUL_FUNCS(crc64_msb, u64);
|
|
DECLARE_CRC_PCLMUL_FUNCS(crc64_lsb, u64);
|
|
|
|
u64 crc64_be_arch(u64 crc, const u8 *p, size_t len)
|
|
{
|
|
CRC_PCLMUL(crc, p, len, crc64_msb, crc64_msb_0x42f0e1eba9ea3693_consts,
|
|
have_pclmulqdq);
|
|
return crc64_be_generic(crc, p, len);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crc64_be_arch);
|
|
|
|
u64 crc64_nvme_arch(u64 crc, const u8 *p, size_t len)
|
|
{
|
|
CRC_PCLMUL(crc, p, len, crc64_lsb, crc64_lsb_0x9a6c9329ac4bc9b5_consts,
|
|
have_pclmulqdq);
|
|
return crc64_nvme_generic(crc, p, len);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crc64_nvme_arch);
|
|
|
|
static int __init crc64_x86_init(void)
|
|
{
|
|
if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) {
|
|
static_branch_enable(&have_pclmulqdq);
|
|
INIT_CRC_PCLMUL(crc64_msb);
|
|
INIT_CRC_PCLMUL(crc64_lsb);
|
|
}
|
|
return 0;
|
|
}
|
|
arch_initcall(crc64_x86_init);
|
|
|
|
static void __exit crc64_x86_exit(void)
|
|
{
|
|
}
|
|
module_exit(crc64_x86_exit);
|
|
|
|
MODULE_DESCRIPTION("CRC64 using [V]PCLMULQDQ instructions");
|
|
MODULE_LICENSE("GPL");
|