From Fedora Project Wiki
(Created page with "== Why 32-bit Linux? == The motivation for using a 32-bit Linux kernel is to reduce memory footprint and meet the small capacity of DDR & cache requirement .(e.g., 64/128MB SIP SoC). The size of ilp32's long & pointer is just half of lp64's (rv64 default abi - longs and pointers are all 64-bit). This significant difference in data type causes different memory & cache footprint costs. Here is the comparison measurement between s32ilp32, s64ilp32, and s64lp64 in the same...")
 
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Why 32-bit Linux? ==
{{lang|en|zh-cn|page=Architectures/RISC-V/64ILP32}}


The motivation for using a 32-bit Linux kernel is to reduce memory footprint and meet the small capacity of DDR & cache requirement .(e.g., 64/128MB SIP SoC).
== what is rv64ilp32? ==
The advancement of AIoT technology has driven the demand for higher computing power in Microcontrollers (MCU) and Application Processors (AP), highlighting the limitations of the 32-bit architecture. Memory access and atomic operation instructions are challenging to meet the requirements of modern systems, leading to a transition towards a 64-bit architecture. This transition faces challenges: running 32-bit software on 64-bit hardware affects performance due to the mismatch in pointer and register widths. To address this issue, the Xuantie team of DAMO Academy of Alibaba proposed the Relaxed-Addressing Mode and, in collaboration with the PLCT Lab of Institute of Software, Chinese Academy of Sciences , released the industry's first RISC-V new 32-bit product-grade open-source toolchain (rv64ilp32 toolchain), designed specifically for firmware, RTOS, and the Linux kernel, optimizing performance and cost. The new 32-bit Linux kernel significantly surpasses traditional solutions in performance, with a 300% improvement in ebpf performance and a 17% increase in iperf-tcp.


The size of ilp32's long & pointer is just half of lp64's (rv64 default abi - longs and pointers are all 64-bit). This significant difference in data type causes different memory & cache footprint costs. Here is the comparison measurement between s32ilp32, s64ilp32, and s64lp64 in the same 128MB qemu system environment:
The Fedora community has a rich software ecosystem for RISC-V, and compared to traditional 64-bit solutions, the new 32-bit builds can save 39% of memory. This advantage makes Fedora RISC-V more widely applicable in the embedded system. Seeing the potential of the new 32-bit, we initiated the new 32-bit Fedora Remix project, which can now run on the k230 development board:


=== Rootfs: ===
[[File:K230.jpg|thumb]]
* u32ilp32 - Using the same 32-bit userspace rootfs.ext2 (UXL=32) binary from buildroot 2023.02-rc3, qemu_riscv32_virt_defconfig
 
== Quick Start ==
CanMV-K230 Fedora Firmware download:
 
[Release 2024.03.03-128m · ruyisdk/mkimg-k230-rv64ilp32](https://github.com/ruyisdk/mkimg-k230-rv64ilp32/releases/tag/2024.03.03-128m)


=== Linux: ===
* s32ilp32 - Linux version 6.3.0-rc1 (124MB)
<pre>
<pre>
          rv32_defconfig: $(Q)$(MAKE) -f $(srctree)/Makefile
- rv64-canmv-rv64 (s64lp64+u64lp64)
          defconfig 32-bit.config
- rv32-canmv-rv64 (s64lp64+u32ilp32)
- rv32-canmv-rv64ilp32 (s64ilp64 + u32ilp32)
</pre>
</pre>


* s64lp64  - Linux version 6.3.0-rc1 (126MB)
Below is a comparison of memory overhead for different versions (compared to the traditional 64-bit k230, the new 32-bit Linux avoids 39% of memory overhead):
 
s64lp64 + u64lp64:
<pre>
<pre>
          defconfig: $(Q)$(MAKE) -f $(srctree)/Makefile defconfig
- free -h
-      total used free shared buff/cache available
- Mem: 107Mi 39Mi 15Mi 1.0Mi  52Mi      53Mi
</pre>
</pre>
s64lp64 + u32ilp32:
<pre>
free -h
    total used free shared buff/cache available
Mem: 107Mi 33Mi 31Mi 1.0Mi  41Mi      67Mi
</pre>
s64ilp32 + u32ilp32:
<pre>
free -h
    total used free shared buff/cache available
Mem: 108Mi 28Mi 41Mi 1.0Mi  38Mi      73Mi
</pre>
(used: 39MB -> 33MB -> 28MB, Prevent 39% memory waste in s64ilp32 + u32ilp32


* s64ilp32 - Linux version 6.3.0-rc1 (126MB)
== flash firmware ==
decompress zst file
<pre>
<pre>
          rv64ilp32_defconfig: $(Q)$(MAKE) -f $(srctree)/Makefile
zstd -d k230-sdcard-fedora_rv32-canmv-rv64ilp32.img.zst
  defconfig 64ilp32.config
</pre>
</pre>
=== Opensbi: ===


* m64lp64  - (2MB) OpenSBI v1.2-80-g4b28afc98bbe
Below is a comparison of memory overhead for different versions (compared to the traditional 64-bit k230, the new 32-bit Linux avoids 39% of memory overhead):
* m32ilp32 - (4MB) OpenSBI v1.2-80-g4b28afc98bbe


<pre>
wipefs -a /dev/sdb
dd if=k230-sdcard-fedora_rv32-canmv-rv64ilp32.img of=/dev/sdb bs=1M status=progress
sync
eject
</pre>


[[File:64ilp32.png|thumb]]
== Build Linux kernel ==
getting toolchain : https://github.com/ruyisdk/riscv-gnu-toolchain-rv64ilp32
 
geting Linux kernel:
<pre>
git clone https://github.com/ruyisdk/k230-rv64ilp32-linux-kernel.git -b k230-6.6-ilp32-128M --depth=1
cd k230-rv64ilp32-linux-kernel
</pre>
 
build the traditional s64lp64 Linux kernel:
<pre>
make ARCH=riscv CROSS_COMPILE=<YOUR PATH>/riscv/bin/riscv64-unknown-elf- k230_evb_linux_enable_vector_defconfig all
</pre>
To build a new 32-bit Linux, you only need to append a 64ilp32.config fragment.:
<pre>
make ARCH=riscv CROSS_COMPILE=<YOUR PATH>/riscv/bin/riscv64-unknown-elf- k230_evb_linux_enable_vector_defconfig 64ilp32.config all
</pre>

Latest revision as of 03:57, 6 March 2024

what is rv64ilp32?

The advancement of AIoT technology has driven the demand for higher computing power in Microcontrollers (MCU) and Application Processors (AP), highlighting the limitations of the 32-bit architecture. Memory access and atomic operation instructions are challenging to meet the requirements of modern systems, leading to a transition towards a 64-bit architecture. This transition faces challenges: running 32-bit software on 64-bit hardware affects performance due to the mismatch in pointer and register widths. To address this issue, the Xuantie team of DAMO Academy of Alibaba proposed the Relaxed-Addressing Mode and, in collaboration with the PLCT Lab of Institute of Software, Chinese Academy of Sciences , released the industry's first RISC-V new 32-bit product-grade open-source toolchain (rv64ilp32 toolchain), designed specifically for firmware, RTOS, and the Linux kernel, optimizing performance and cost. The new 32-bit Linux kernel significantly surpasses traditional solutions in performance, with a 300% improvement in ebpf performance and a 17% increase in iperf-tcp.

The Fedora community has a rich software ecosystem for RISC-V, and compared to traditional 64-bit solutions, the new 32-bit builds can save 39% of memory. This advantage makes Fedora RISC-V more widely applicable in the embedded system. Seeing the potential of the new 32-bit, we initiated the new 32-bit Fedora Remix project, which can now run on the k230 development board:

K230.jpg

Quick Start

CanMV-K230 Fedora Firmware download:

[Release 2024.03.03-128m · ruyisdk/mkimg-k230-rv64ilp32](https://github.com/ruyisdk/mkimg-k230-rv64ilp32/releases/tag/2024.03.03-128m)

- rv64-canmv-rv64 (s64lp64+u64lp64)
- rv32-canmv-rv64 (s64lp64+u32ilp32)
- rv32-canmv-rv64ilp32 (s64ilp64 + u32ilp32)

Below is a comparison of memory overhead for different versions (compared to the traditional 64-bit k230, the new 32-bit Linux avoids 39% of memory overhead):

s64lp64 + u64lp64:

- free -h
-      total used free shared buff/cache available
- Mem: 107Mi 39Mi 15Mi 1.0Mi  52Mi       53Mi

s64lp64 + u32ilp32:

free -h
     total used free shared buff/cache available
Mem: 107Mi 33Mi 31Mi 1.0Mi  41Mi       67Mi

s64ilp32 + u32ilp32:

free -h
     total used free shared buff/cache available
Mem: 108Mi 28Mi 41Mi 1.0Mi  38Mi       73Mi

(used: 39MB -> 33MB -> 28MB, Prevent 39% memory waste in s64ilp32 + u32ilp32

flash firmware

decompress zst file

zstd -d k230-sdcard-fedora_rv32-canmv-rv64ilp32.img.zst

Below is a comparison of memory overhead for different versions (compared to the traditional 64-bit k230, the new 32-bit Linux avoids 39% of memory overhead):

wipefs -a /dev/sdb
dd if=k230-sdcard-fedora_rv32-canmv-rv64ilp32.img of=/dev/sdb bs=1M status=progress
sync
eject

Build Linux kernel

getting toolchain : https://github.com/ruyisdk/riscv-gnu-toolchain-rv64ilp32

geting Linux kernel:

git clone https://github.com/ruyisdk/k230-rv64ilp32-linux-kernel.git -b k230-6.6-ilp32-128M --depth=1
cd k230-rv64ilp32-linux-kernel

build the traditional s64lp64 Linux kernel:

make ARCH=riscv CROSS_COMPILE=<YOUR PATH>/riscv/bin/riscv64-unknown-elf- k230_evb_linux_enable_vector_defconfig all

To build a new 32-bit Linux, you only need to append a 64ilp32.config fragment.:

make ARCH=riscv CROSS_COMPILE=<YOUR PATH>/riscv/bin/riscv64-unknown-elf- k230_evb_linux_enable_vector_defconfig 64ilp32.config all