Skip to contentSkip to conversation

genksyms: Support arm64 CRC32 hardware acceleration

PATCH In review Wentao Guan 3 participants 9 messages May 25 – May 28 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 genksyms: Support arm64 CRC32 hardware acceleration

Use hardware 'crc32b' to partial_crc32_one() when support, it shows 2x speed up than crctab32 way.

I think it will be scaled to more architecture.

---
changelog:
1. remove change in partial_crc32(),
for partial_crc32_one() already use crc32b.

---

---
 scripts/genksyms/genksyms.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
scripts/genksyms/genksyms.c +34 -0
index 83e48670c2fcf..80b7797c842aa 100644
@@ -116,8 +116,40 @@ static const uint32_t crctab32[] = {
 	0x2d02ef8dU
 };
 
+/*
+ * Architecture-specific CRC32 hardware acceleration.
+ */
+static int crc32_hw_available;
+
+#ifdef __aarch64__
+#include <sys/auxv.h>
+#include <asm/hwcap.h>
+
+static void crc32_check_hw(void)
+{
+	crc32_hw_available = (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
+}
+
+static inline uint32_t crc32_hw_byte(uint8_t c, uint32_t crc)
+{
+	asm volatile(".arch_extension crc\n\t"
+				"crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(c));
+	return crc;
+}
+
+#else
+static void crc32_check_hw(void)
+{
+	crc32_hw_available = 0;
+}
+#endif
+
 static uint32_t partial_crc32_one(uint8_t c, uint32_t crc)
 {
+#if defined(__aarch64__)
+	if (__builtin_expect(crc32_hw_available, 0))
+		return crc32_hw_byte(c, crc);
+#endif
 	return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
 }
 
@@ -740,6 +772,8 @@ int main(int argc, char **argv)
 	FILE *dumpfile = NULL, *ref_file = NULL;
 	int o;
 
+	crc32_check_hw();
+
 	struct option long_opts[] = {
 		{"debug", 0, 0, 'd'},
 		{"warnings", 0, 0, 'w'},
Signature · 1 line
2.30.2
#1 lore raw

+Cc: kbuild, modules

Quoted 4 lines · Wentao Guan

Use hardware 'crc32b' to partial_crc32_one() when support, it shows 2x speed up than crctab32 way.

I think it will be scaled to more architecture.

Could you please provide measurements showing how this improves the runtime of genksyms and affects the overall kernel build time? Are CRC calculations actually a hot path in genksyms? I don't think it is worth complicating the genksyms code with architecture-specific optimizations unless there is a clear benefit.

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

Signature · 2 lines
Thanks,
Petr
Quoted 66 lines

---
changelog:
1. remove change in partial_crc32(),
for partial_crc32_one() already use crc32b.

---

---
 scripts/genksyms/genksyms.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
scripts/genksyms/genksyms.c +34 -0
index 83e48670c2fcf..80b7797c842aa 100644
@@ -116,8 +116,40 @@ static const uint32_t crctab32[] = {
 	0x2d02ef8dU
 };
 
+/*
+ * Architecture-specific CRC32 hardware acceleration.
+ */
+static int crc32_hw_available;
+
+#ifdef __aarch64__
+#include <sys/auxv.h>
+#include <asm/hwcap.h>
+
+static void crc32_check_hw(void)
+{
+	crc32_hw_available = (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
+}
+
+static inline uint32_t crc32_hw_byte(uint8_t c, uint32_t crc)
+{
+	asm volatile(".arch_extension crc\n\t"
+				"crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(c));
+	return crc;
+}
+
+#else
+static void crc32_check_hw(void)
+{
+	crc32_hw_available = 0;
+}
+#endif
+
 static uint32_t partial_crc32_one(uint8_t c, uint32_t crc)
 {
+#if defined(__aarch64__)
+	if (__builtin_expect(crc32_hw_available, 0))
+		return crc32_hw_byte(c, crc);
+#endif
 	return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
 }
 
@@ -740,6 +772,8 @@ int main(int argc, char **argv)
 	FILE *dumpfile = NULL, *ref_file = NULL;
 	int o;
 
+	crc32_check_hw();
+
 	struct option long_opts[] = {
 		{"debug", 0, 0, 'd'},
 		{"warnings", 0, 0, 'w'},
#2 lore raw

Re: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~

Hello Petr,

Thanks for your reply,

Quoted 2 lines

Could you please provide measurements showing how this improves the runtime of genksyms and affects the overall kernel build time? Are

From my build kernel workload, genksyms perf report (record -g -F 99) show:
without patch:
- 7.83% 0.00% genksyms genksyms [.] _start
_start
- __libc_start_main
+ 3.19% yylex

     1.81% find_symbol
     0.92% is_reserved_word
     0.62% free_list

+ 0.56% export_symbol

with patch:(find_symbol() and export_symbol() benifit from this):
- 7.12% 0.00% genksyms genksyms [.] _start
_start
- __libc_start_main
- 3.01% yylex

       0.51% malloc
     1.65% find_symbol
     0.82% is_reserved_word
     0.50% free_list
Quoted 3 lines

CRC calculations actually a hot path in genksyms? I don't think it is worth complicating the genksyms code with architecture-specific optimizations unless there is a clear benefit.

Right.

Quoted 5 lines

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

I see gendwarfksyms use crc32 from <zlib.h>, which from zlib1g-dev and zlib1g.

BRs
Wentao Guan

#3 lore raw

Re: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~

Quoted 6 lines · Wentao Guan
Quoted 5 lines

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

I see gendwarfksyms use crc32 from <zlib.h>, which from zlib1g-dev and zlib1g.

Ah, I forgot about this, so gendwarfksyms should already be well optimized. I think that is the most important thing.

Signature · 2 lines
Thanks,
Petr
#4 lore raw

Re: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~

Quoted 10 lines · Wentao Guan
Quoted 6 lines
Quoted 5 lines

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

I see gendwarfksyms use crc32 from <zlib.h>, which from zlib1g-dev and zlib1g.

Ah, I forgot about this, so gendwarfksyms should already be well optimized. I think that is the most important thing.

Which way do you prefer? There are two ways now:
1. this work,
2. import zlib like gendwarfksyms and remove the huge crctab,
but need make sure any arch do not cause performance regression? (Assert the user libs precompile with +crc32 is right?)
I do some early tests show that:
1) zlib in x86 fast than genksym software
2) zlib in arm64 debian precompile slow than genksym software(crc32 not in armv8)
3) zlib in arm64 recompile with +crc32 same speed with genksyms hardware

BRs
Wentao Guan

#5 lore raw

Re: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~

Quoted 11 lines · Wentao Guan
Quoted 10 lines · Wentao Guan
Quoted 6 lines
Quoted 5 lines

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

I see gendwarfksyms use crc32 from <zlib.h>, which from zlib1g-dev and zlib1g.

Ah, I forgot about this, so gendwarfksyms should already be well optimized. I think that is the most important thing.

Quoted 9 lines

Which way do you prefer? There are two ways now:
1. this work,
2. import zlib like gendwarfksyms and remove the huge crctab,
but need make sure any arch do not cause performance regression? (Assert the user libs precompile with +crc32 is right?)
I do some early tests show that:
1) zlib in x86 fast than genksym software
2) zlib in arm64 debian precompile slow than genksym software(crc32 not in armv8)
3) zlib in arm64 recompile with +crc32 same speed with genksyms hardware

I think it would be useful to first have more data showing that the CRC calculation in genksyms is a hot path and contributes significantly to the overall kernel build time.

Signature · 2 lines
Thanks,
Petr
#6 lore raw

Re: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~

Hello Petr,

Quoted 22 lines · Wentao Guan
Quoted 11 lines
Quoted 10 lines · Wentao Guan
Quoted 6 lines
Quoted 5 lines

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

I see gendwarfksyms use crc32 from <zlib.h>, which from zlib1g-dev and zlib1g.

Ah, I forgot about this, so gendwarfksyms should already be well optimized. I think that is the most important thing.

Quoted 9 lines

Which way do you prefer? There are two ways now:
1. this work,
2. import zlib like gendwarfksyms and remove the huge crctab,
but need make sure any arch do not cause performance regression? (Assert the user libs precompile with +crc32 is right?)
I do some early tests show that:
1) zlib in x86 fast than genksym software
2) zlib in arm64 debian precompile slow than genksym software(crc32 not in armv8)
3) zlib in arm64 recompile with +crc32 same speed with genksyms hardware

Quoted 3 lines

I think it would be useful to first have more data showing that the CRC calculation in genksyms is a hot path and contributes significantly to the overall kernel build time.

You are right.
1. genksyms contributes significantly to the overall kernel build time. Test with arm64 defconfig and enable/disable CONFIG_GENKSYMS (11m50s/9m48s)
2. crc32 shows ~10% affect in perf record w/o patch.
3. but this patch w/o doesn`t affect the overall kernel build time 11m50s(+-1s).
4. so try to use zlib and delete the hard code crctab32 table?

BRs
Wentao Guan

RFC PATCH:
From f8f1c2301ddb70fb42a56fd7228db3dbd248e2b4 Mon Sep 17 00:00:00 2001
From: Wentao Guan <[email protected]>
Date: Mon, 25 May 2026 20:02:03 +0800
Subject: [PATCH] genksyms: use crc32 from zlib

---
 scripts/genksyms/Makefile   |  1 +
 scripts/genksyms/genksyms.c | 70 +++++--------------------------------
 2 files changed, 9 insertions(+), 62 deletions(-)
scripts/genksyms/Makefile +1 -0
index 4350311fb7b39..068e79626ffe7 100644
@@ -7,6 +7,7 @@ genksyms-objs   := genksyms.o parse.tab.o lex.lex.o
 # -I needed for generated C source to include headers in source tree
 HOSTCFLAGS_parse.tab.o := -I $(src)
 HOSTCFLAGS_lex.lex.o := -I $(src)
+HOSTLDLIBS_genksyms :=  -lz
 
 # dependencies on generated files need to be listed explicitly
 $(obj)/lex.lex.o: $(obj)/parse.tab.h
scripts/genksyms/genksyms.c +8 -62

106 lines not on this page · raw message

Signature · 1 line
2.30.2
#7 lore raw

Re: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~

In reply to Petr Pavlu

Hello Petr,

Quoted 22 lines · Wentao Guan
Quoted 11 lines
Quoted 10 lines · Wentao Guan
Quoted 6 lines
Quoted 5 lines

Additionally, many distributions already switched to gendwarfksyms last year. Unless someone provides a good reason to keep genksyms around, I expect it will be deprecated soon and eventually removed. It would be more valuable to show whether the same optimization is worthwhile for gendwarfksyms.

I see gendwarfksyms use crc32 from <zlib.h>, which from zlib1g-dev and zlib1g.

Ah, I forgot about this, so gendwarfksyms should already be well optimized. I think that is the most important thing.

Quoted 9 lines

Which way do you prefer? There are two ways now:
1. this work,
2. import zlib like gendwarfksyms and remove the huge crctab,
but need make sure any arch do not cause performance regression? (Assert the user libs precompile with +crc32 is right?)
I do some early tests show that:
1) zlib in x86 fast than genksym software
2) zlib in arm64 debian precompile slow than genksym software(crc32 not in armv8)
3) zlib in arm64 recompile with +crc32 same speed with genksyms hardware

Quoted 3 lines

I think it would be useful to first have more data showing that the CRC calculation in genksyms is a hot path and contributes significantly to the overall kernel build time.

I found that 'nm' is slow and a really crazy but significantly improve my build speed, from 11m50s down to 11m18s:

scripts/Makefile.build +1 -1
index 0c838c467..d5b9db6d3 100644
@@ -231,7 +231,7 @@ ifdef CONFIG_MODVERSIONS
 #   be compiled and linked to the kernel and/or modules.
 
 gen_symversions =                                                              \
-       if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_'; then             \
+       if strings $@ 2>/dev/null | grep -q '__export_symbol_'; then            \
                $(cmd_gensymtypes_$1) >> $(dot-target).cmd;                     \
        fi
 

BRs
Wentao Guan

#8 lore raw
In reply to Wentao Guan
kernel test robot noticed the following build warnings:

Hi Wentao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v7.1-rc5 next-20260527]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wentao-Guan/genksyms-Support-arm64-CRC32-hardware-acceleration/20260525-151229
base:   linus/master
patch link:    https://lore.kernel.org/r/20260525070344.1564886-1-guanwentao%40uniontech.com
patch subject: [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration
config: um-randconfig-002 (https://download.01.org/0day-ci/archive/20260528/[email protected]/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 9409c07de6378507397ecdb6f05f628f58110112)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260528/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> scripts/genksyms/genksyms.c:122:12: warning: variable 'crc32_hw_available' set but not used [-Wunused-but-set-global]
     122 | static int crc32_hw_available;
         |            ^
   1 warning generated.
--
>> scripts/genksyms/genksyms.c:122:12: warning: variable 'crc32_hw_available' set but not used [-Wunused-but-set-global]
     122 | static int crc32_hw_available;
         |            ^

1 warning generated.

vim +/crc32_hw_available +122 scripts/genksyms/genksyms.c

118
119 /*
120 * Architecture-specific CRC32 hardware acceleration.
121 */

 > 122	static int crc32_hw_available;

123

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki