[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAAfSe-uGLQ5fC31BggZ73P1vp5YckvntOy5CH_MGD3S+cp_TtQ@mail.gmail.com>
Date: Thu, 16 Oct 2025 17:12:20 +0800
From: Chunyan Zhang <zhang.lyra@...il.com>
To: linux-riscv@...ts.infradead.org,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Impact of RISC-V C Extension on Linux Kernel Size
Hi,
I was recently asked how much the RISC-V C extensions can shrink the
Linux kernel size. I looked it up online and could only roughly
predict a 25% reduction in theory. But I couldn't find more specific
data on the Linux kernel program. So I compiled a few kernel images
with or without RISC-V C extension and would like to share the data
and analysis. Maybe someone will also be interested.
The kernel version is v6.18-rc1, toolchain is
riscv64-glibc-ubuntu-22.04-gcc-nightly-2025.09.28-nightly.
Compile with C extension is the default, so to disable C extension on
riscv64, I hacked two Makefiles like below:
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index ecf2fcce2d92..e51810608695 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -61,7 +61,6 @@ endif
riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
-riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v
ifneq ($(CONFIG_RISCV_ISA_C),y)
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index f60fce69b725..0c93c397fed0 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -46,6 +46,7 @@ endif
always-$(KBUILD_BUILTIN) += vmlinux.lds
obj-y += head.o
+AFLAGS_head.o += -march=rv64gc
obj-y += soc.o
obj-$(CONFIG_RISCV_ALTERNATIVE) += alternative.o
obj-y += cpu.o
First with C extension (default):
$ make defconfig
$ time make vmlinux -j32
real 4m27.219s
user 57m28.761s
sys 5m19.494s
$ size vmlinux
text data bss dec hex filename
13294359 6288266 423589 20006214 1314546 vmlinux
Without C extension:
$ make clean
$ time make vmlinux -j32
real 4m34.450s
user 58m52.848s
sys 5m25.042s
$ size vmlinux
text data bss dec hex filename
17728589 6288586 423589 24440764 174efbc vmlinux
Build time for both is close, and we can get 25% and 18% for text
section and vmlinux size reduction respectively with C extension
support.
I also get performance test results with perf on Pioneer Board, which
is running kernel 6.6.111,
With C extension,
Performance counter stats for 'netperf' (3 runs):
9,966.81 msec task-clock # 0.995
CPUs utilized ( +- 0.04% )
780 context-switches # 78.260
/sec ( +- 1.74% )
35 cpu-migrations # 3.512
/sec ( +- 3.30% )
121 page-faults # 12.140
/sec ( +- 5.86% )
19,924,390,238 cycles # 1.999
GHz ( +- 0.04% )
7,681,821,013 instructions # 0.39
insn per cycle ( +- 0.88% )
0 branches # 0.000
/sec
0 branch-misses
10.01376 +- 0.00290 seconds time elapsed ( +- 0.03% )
Without C extension,
Performance counter stats for 'netperf' (3 runs):
9,967.98 msec task-clock # 0.995
CPUs utilized ( +- 0.02% )
772 context-switches # 77.448
/sec ( +- 1.78% )
33 cpu-migrations # 3.311
/sec ( +- 4.63% )
126 page-faults # 12.640
/sec ( +- 2.12% )
19,925,181,546 cycles # 1.999
GHz ( +- 0.02% )
6,639,648,698 instructions # 0.33
insn per cycle ( +- 0.96% )
0 branches # 0.000
/sec
0 branch-misses
10.01589 +- 0.00309 seconds time elapsed ( +- 0.03% )
IPC from 0.33 (without C) to 0.39 (with C), IPC is improved by 18%.
Thanks,
Chunyan
Powered by blists - more mailing lists