From 87590d184aa9d2a668fb9d44043d3a6430a28031 Mon Sep 17 00:00:00 2001 From: Gege-Wang <2891067867@qq.com> Date: Fri, 29 Sep 2023 17:39:10 +0800 Subject: [PATCH 1/3] add unikernel bsp --- boards/riscv64/virt/README.md | 4 ++ src/feature/linux/unikernel/README.md | 71 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/feature/linux/unikernel/README.md diff --git a/boards/riscv64/virt/README.md b/boards/riscv64/virt/README.md index 79d858a..d79efe4 100644 --- a/boards/riscv64/virt/README.md +++ b/boards/riscv64/virt/README.md @@ -49,6 +49,10 @@ The default dtb is dumped out of QEMU: $ make boot DUMPDTB=1 +## unikernel + +Unikernel Linux is a small patch to Linux which allows to build many programs, unmodified, as unikernels. That means they are linked with the Linux kernel into a final vmlinuz and run in kernel space. Almost all features and drivers in Linux are available for use by the unikernel. + ## References * [Qemu RISCV Documentation](https://wiki.qemu.org/Documentation/Platforms/RISCV) diff --git a/src/feature/linux/unikernel/README.md b/src/feature/linux/unikernel/README.md new file mode 100644 index 0000000..ef8986b --- /dev/null +++ b/src/feature/linux/unikernel/README.md @@ -0,0 +1,71 @@ +# Unikernel Riscv Usage + +## Basic Usage + +Use the following command to compile Unikernel Riscv: + + $ make kernel + +Some work can be done automatically: + +1. Build the cross compiler +2. Switch to the selected kernel version +3. Patch the kernel with patches in bsp/patch/linux/ +4. Use config in bsp/configs/ as kernel config +5. Compile the kernel +6. Compile the dts + +## Burn + +The process of burning images onto the board can be referenced in bsp/burn_tools/README.md. + +## DTB + +Notice for burning: + +The compiled dtb shoule be renamed as light_lpi4a.dtb because U-Boot use this filename as the default dtb. + +Or you can modify the default config of /extlinux/extlinux.conf in boot.ext4. + +## BIOS + +Riscv64 requires a proxy kernel to do some prepare before running the real linux kernel. + +And the proxy kernel currently is replaced by the OpenSBI project. + +The OpenSBI used here is specially made for T-Head SoCs. + +More detailed instruction is in bsp/bios/opensbi/README.md. + +## U-Boot + +The U-Boot used here is specially made for T-Head SoCs. + +More detailed instruction is in bsp/uboot/README.md. + +## Latency testing + +After successfully booting the Linux on the board, real-time testing can be performed. + +Stress-ng can be used for generating system loads. + +I have tested real-time latency with the following stress-ng options: + +* stress-ng --cpu 4 +* stress-ng --vm 8 --vm-bytes 2G +* stress-ng --hdd 4 + +Cyclictest and Ftrace can be used for latency testing and tracing. + +Script for reference: + + $ mount -t tracefs none /sys/kernel/tracing + $ cd /sys/kernel/tracing + $ echo wakeup_rt > current_tracer + $ echo 1 > tracing_on + $ echo 0 > tracing_max_lat + $ stress-ng --cpu 4 & + $ cyclictest --mlockall --smp -- +## References + +* [Sipeed LicheePi 4A Documentation](https://wiki.sipeed.com/hardware/zh/lichee/th1520/lpi4a/1_intro.h) -- Gitee From 943e4420425bf85b807f56b6edd5397d4ac2f015 Mon Sep 17 00:00:00 2001 From: Gege-Wang <2891067867@qq.com> Date: Sat, 30 Sep 2023 11:11:47 +0800 Subject: [PATCH 2/3] add ukl Makefile --- boards/riscv64/virt/Makefile | 62 +++----------------- boards/riscv64/virt/Makefile_old | 98 ++++++++++++++++++++++++++++++++ boards/riscv64/virt/README.md | 67 ++++------------------ boards/riscv64/virt/bsp | 2 +- 4 files changed, 119 insertions(+), 110 deletions(-) create mode 100644 boards/riscv64/virt/Makefile_old diff --git a/boards/riscv64/virt/Makefile b/boards/riscv64/virt/Makefile index 745339a..2e4dc22 100644 --- a/boards/riscv64/virt/Makefile +++ b/boards/riscv64/virt/Makefile @@ -1,60 +1,28 @@ -# Copyright (C) 2016-2021 Wu Zhangjin +# Copyright (C) 2020 Wu Zhangjin +# _BASE: 1, virt; 2, real; 3: virt+real _BASE := 1 ARCH := riscv XARCH := riscv64 -# Use the default setting +# Use default setting CPU ?= SMP ?= 4 -MEM ?= 256M -QEMU ?= v6.0.0 +MEM ?= 8G +QEMU ?= v4.1.1 # Enable QEMU_US=1 for qemu-user-static QEMU_US ?= 0 -LINUX ?= v6.2 - -# git repos for the other kernel forks -KERNEL_GIT[KERNEL_FORK_openeuler] := https://gitee.com/openeuler/kernel.git -LINUX[KERNEL_FORK_openeuler] ?= 5.10.0-132.0.0 +LINUX ?= v6.5.2 BUILDROOT?= 2019.05 NETDEV_LIST := virtio NETDEV ?= virtio SERIAL ?= ttyS0 -# use bochs as VGA graphic device -FBDEV ?= stdvga -# use virtio as keyboard device -KBDEV ?= virtio - -UBOOT ?= v2022.04 - -KRN_ADDR?= 0x84000000 -RDK_ADDR?= 0x87500000 - -# QEMU load env.img to ram and then U-boot import it from ram -ENV_DEV_LIST := ram -ENV_DEV ?= ram -ENV_OFFSET ?= 0 -ENV_ADDR ?= 0x87300000 - -UCONFIG ?= qemu-riscv.h -BOOTDEV_LIST := tftp ram -BOOTDEV ?= ram - -# ref: https://wiki.qemu.org/Documentation/9psetup -# 9pnet based network filesystem sharing, aarch64/virt board support both virtio-9p-pci/-virtfs and virtio-9p-device -# But virtio-9p-device requires less kernel options (no need the PCI related parts in features/linux/9pnet/) -# To eanble this function, please make sure the 9pnet feature is enabled: make feature f=9pnet && make kernel-olddefconfig -# -# TODO: add board specific 9pnet options. -# - -NET9PDEV ?= virtio-9p-device - # virtio vda: https://wiki.debian.org/Arm64Qemu ROOTDEV_LIST := /dev/vda /dev/ram0 /dev/nfs ROOTDEV ?= /dev/vda -FSTYPE ?= ext2 +FSTYPE ?= ext4 +ROOTFS ?=$(BSP_ROOT)/$(BUILDROOT)/rootfs.img # fw_jump.elf and fw_dynamic.elf are built from https://gitlab.com/qemu-project/opensbi BIOS ?= $(or $(wildcard $(BSP_BIOS)/opensbi/generic/fw_dynamic.elf),$(BSP_BIOS)/opensbi/generic/fw_jump.elf) @@ -73,26 +41,12 @@ BIMAGE ?= $(BSP_UBOOT)/$(UBOOT)/u-boot UKIMAGE ?= $(KIMAGE) #DTB ?= $(BSP_KERNEL)/$(LINUX)/qemu-$(XARCH)-$(MACH).dtb -ifneq ($(wildcard $(DTB)),) - DTB_ADDR := 0x87000000 -else - DTB_ADDR := $$fdtcontroladdr -endif - ifeq ($(NOMMU),1) override SMP := 1 override BIOS := none override U := 0 endif -ROOTFS ?= $(BSP_ROOT)/$(BUILDROOT)/rootfs.cpio.gz -HROOTFS ?= $(BSP_ROOT)/$(BUILDROOT)/rootfs.$(FSTYPE) - #XKCLI ?= earlycon=sbi QTOOL[OS_trusty] ?= $(BSP_QEMU)/$(QEMU)/bin/qemu-system-$(XARCH) QTOOL[OS_focal] ?= $(BSP_QEMU)/$(QEMU)/bin/qemu-system-$(XARCH) - -# external toolchain, please download it while: make toolchain -# Available CCORI: bootlin, gnu-mcu-eclipse -CCORI[OS_trusty] ?= gnu-mcu-eclipse -CCORI[OS_focal] ?= internal diff --git a/boards/riscv64/virt/Makefile_old b/boards/riscv64/virt/Makefile_old new file mode 100644 index 0000000..745339a --- /dev/null +++ b/boards/riscv64/virt/Makefile_old @@ -0,0 +1,98 @@ +# Copyright (C) 2016-2021 Wu Zhangjin +_BASE := 1 +ARCH := riscv +XARCH := riscv64 +# Use the default setting +CPU ?= +SMP ?= 4 +MEM ?= 256M +QEMU ?= v6.0.0 +# Enable QEMU_US=1 for qemu-user-static +QEMU_US ?= 0 +LINUX ?= v6.2 + +# git repos for the other kernel forks +KERNEL_GIT[KERNEL_FORK_openeuler] := https://gitee.com/openeuler/kernel.git +LINUX[KERNEL_FORK_openeuler] ?= 5.10.0-132.0.0 + +BUILDROOT?= 2019.05 +NETDEV_LIST := virtio +NETDEV ?= virtio +SERIAL ?= ttyS0 + +# use bochs as VGA graphic device +FBDEV ?= stdvga +# use virtio as keyboard device +KBDEV ?= virtio + +UBOOT ?= v2022.04 + +KRN_ADDR?= 0x84000000 +RDK_ADDR?= 0x87500000 + +# QEMU load env.img to ram and then U-boot import it from ram +ENV_DEV_LIST := ram +ENV_DEV ?= ram +ENV_OFFSET ?= 0 +ENV_ADDR ?= 0x87300000 + +UCONFIG ?= qemu-riscv.h +BOOTDEV_LIST := tftp ram +BOOTDEV ?= ram + +# ref: https://wiki.qemu.org/Documentation/9psetup +# 9pnet based network filesystem sharing, aarch64/virt board support both virtio-9p-pci/-virtfs and virtio-9p-device +# But virtio-9p-device requires less kernel options (no need the PCI related parts in features/linux/9pnet/) +# To eanble this function, please make sure the 9pnet feature is enabled: make feature f=9pnet && make kernel-olddefconfig +# +# TODO: add board specific 9pnet options. +# + +NET9PDEV ?= virtio-9p-device + +# virtio vda: https://wiki.debian.org/Arm64Qemu +ROOTDEV_LIST := /dev/vda /dev/ram0 /dev/nfs +ROOTDEV ?= /dev/vda + +FSTYPE ?= ext2 + +# fw_jump.elf and fw_dynamic.elf are built from https://gitlab.com/qemu-project/opensbi +BIOS ?= $(or $(wildcard $(BSP_BIOS)/opensbi/generic/fw_dynamic.elf),$(BSP_BIOS)/opensbi/generic/fw_jump.elf) + +ifeq ($(vmlinuz),1) +ORIIMG ?= arch/$(ARCH)/boot/compressed/vmlinuz +KIMAGE ?= $(BSP_KERNEL)/$(LINUX)/vmlinuz +else +ORIIMG ?= arch/$(ARCH)/boot/Image +KIMAGE ?= $(BSP_KERNEL)/$(LINUX)/Image +endif + +#DTS ?= $(BSP_KERNEL)/$(LINUX)/qemu-$(XARCH)-$(MACH).dts +UORIIMG ?= $(ORIIMG) +BIMAGE ?= $(BSP_UBOOT)/$(UBOOT)/u-boot +UKIMAGE ?= $(KIMAGE) +#DTB ?= $(BSP_KERNEL)/$(LINUX)/qemu-$(XARCH)-$(MACH).dtb + +ifneq ($(wildcard $(DTB)),) + DTB_ADDR := 0x87000000 +else + DTB_ADDR := $$fdtcontroladdr +endif + +ifeq ($(NOMMU),1) + override SMP := 1 + override BIOS := none + override U := 0 +endif + +ROOTFS ?= $(BSP_ROOT)/$(BUILDROOT)/rootfs.cpio.gz +HROOTFS ?= $(BSP_ROOT)/$(BUILDROOT)/rootfs.$(FSTYPE) + +#XKCLI ?= earlycon=sbi +QTOOL[OS_trusty] ?= $(BSP_QEMU)/$(QEMU)/bin/qemu-system-$(XARCH) +QTOOL[OS_focal] ?= $(BSP_QEMU)/$(QEMU)/bin/qemu-system-$(XARCH) + +# external toolchain, please download it while: make toolchain +# Available CCORI: bootlin, gnu-mcu-eclipse +CCORI[OS_trusty] ?= gnu-mcu-eclipse +CCORI[OS_focal] ?= internal diff --git a/boards/riscv64/virt/README.md b/boards/riscv64/virt/README.md index d79efe4..c4c2642 100644 --- a/boards/riscv64/virt/README.md +++ b/boards/riscv64/virt/README.md @@ -1,68 +1,25 @@ - -# Risc64 Virt Usage +# Unikernel Riscv Usage ## Basic Usage -Works perfectly: - - $ make boot V=1 +Use the following command to compile kernel and dts: - $ make boot SHARE=1 + $ make kernel - $ make boot ROOTDEV=/dev/nfs +Some work can be done automatically: -Buildroot provides rootfs config and toolchain, mainline linux provides the -official kernel config, everything goes well. Qemu v4.0.0 has the riscv64 board -support. +1. Build the cross compiler +2. Switch to the selected kernel version +3. Patch the kernel with patches in bsp/patch/linux/ +4. Use config in bsp/configs/ as kernel config +5. Compile the kernel ## BIOS -The only difference is riscv64 requires a proxy kernel to do some prepare -before running the real linux kernel. and the proxy kernel currently is -replaced by the opensbi project. - -Newer qemu and kernel support works with the standard -bios option with opensbi. - -We can build one in Linux Lab with these commands: - - $ cd src/examples/ - $ git clone https://github.com/riscv/opensbi - $ cd opensbi - // for riscv32 - $ make all PLATFORM=generic LLVM=1 PLATFORM_RISCV_XLEN=32 - // for riscv64 - $ make all PLATFORM=generic LLVM=1 PLATFORM_RISCV_XLEN=64 - $ ls build/platform/generic/firmware/fw_jump.elf - -## DTS - -The cpu, memory and external devices configuration in dts must match the -setting from the QEMU options, otherwise, it may not boot. - -If want to change the QEMU options, please make sure update the dts -configurations too, or, simply reset `DTB` variable like this to use the -default dtb transferred by QEMU: - - $ make boot DTB= - -The default dtb is dumped out of QEMU: - - $ make boot DUMPDTB=1 - -## unikernel +Riscv64 requires a proxy kernel to do some prepare before running the real linux kernel. -Unikernel Linux is a small patch to Linux which allows to build many programs, unmodified, as unikernels. That means they are linked with the Linux kernel into a final vmlinuz and run in kernel space. Almost all features and drivers in Linux are available for use by the unikernel. +And the proxy kernel currently is replaced by the OpenSBI project. ## References -* [Qemu RISCV Documentation](https://wiki.qemu.org/Documentation/Platforms/RISCV) -* [RISCV Software Status](https://riscv.org/software-status) -* [RV8: RISC-V simulator for x86-64 (Another simulator)](https://github.com/rv8-io/rv8) -* [RISC-V Debian](https://wiki.debian.org/RISC-V) -* [Running 64- and 32-bit RISC-V Linux on QEMU](https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html) -* [RISC-V GNU Compiler Toolchain](https://github.com/riscv/riscv-gnu-toolchain) -* [Prebuilt GNU Toolchain](https://www.sifive.com/boards) -* [RISC-V Proxy Kernel and Boot Loader](https://github.com/riscv/riscv-pk) -* [RISC-V Open Source Supervisor Binary Interface](https://github.com/riscv/opensbi) -* buildroot/configs/qemu_riscv64_virt_defconfig -* buildroot/board/qemu/riscv64-virt/ +* [Sipeed LicheePi 4A Documentation](https://wiki.sipeed.com/hardware/zh/lichee/th1520/lpi4a/1_intro.html) diff --git a/boards/riscv64/virt/bsp b/boards/riscv64/virt/bsp index e2963d2..e517236 160000 --- a/boards/riscv64/virt/bsp +++ b/boards/riscv64/virt/bsp @@ -1 +1 @@ -Subproject commit e2963d29ec417e7df835c709d00bc3d511b2bc14 +Subproject commit e5172360a4c473b2358b1df0e6340a6d573a8a00 -- Gitee From 953a0d9b3a1d3f9e9d8af4860c7331325ec3a300 Mon Sep 17 00:00:00 2001 From: Gege-Wang <2891067867@qq.com> Date: Sat, 30 Sep 2023 12:10:23 +0800 Subject: [PATCH 3/3] test --- .gitmodules | 2 +- boards/riscv64/virt/README.md | 10 +++--- src/feature/linux/unikernel/README.md | 50 +++------------------------ 3 files changed, 11 insertions(+), 51 deletions(-) diff --git a/.gitmodules b/.gitmodules index 419e437..bb950b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -49,7 +49,7 @@ [submodule "boards/riscv64/virt/bsp"] ignore = all path = boards/riscv64/virt/bsp - url = https://gitee.com/tinylab/qemu-riscv64-virt.git + url = https://gitee.com/gegewang/unikernel-bsp.git [submodule "boards/x86_64/pc/bsp"] ignore = all path = boards/x86_64/pc/bsp diff --git a/boards/riscv64/virt/README.md b/boards/riscv64/virt/README.md index c4c2642..c4524c7 100644 --- a/boards/riscv64/virt/README.md +++ b/boards/riscv64/virt/README.md @@ -2,7 +2,7 @@ ## Basic Usage -Use the following command to compile kernel and dts: +Use the following command to compile Unikernel Riscv: $ make kernel @@ -13,13 +13,15 @@ Some work can be done automatically: 3. Patch the kernel with patches in bsp/patch/linux/ 4. Use config in bsp/configs/ as kernel config 5. Compile the kernel +6. Compile the dts ## BIOS -Riscv64 requires a proxy kernel to do some prepare before running the real linux kernel. +Riscv64 requires a proxy kernel to do some prepare before running the real linux kernel. And the proxy kernel currently is replaced by the OpenSBI project. -## References +# References -* [Sipeed LicheePi 4A Documentation](https://wiki.sipeed.com/hardware/zh/lichee/th1520/lpi4a/1_intro.html) +* [A unikernel based on Linux](https://next.redhat.com/2018/11/14/ukl-a-unikernel-based-on-linux/) +* [unikernelLinux](https://github.com/unikernelLinux/ukl) diff --git a/src/feature/linux/unikernel/README.md b/src/feature/linux/unikernel/README.md index ef8986b..f80c1e2 100644 --- a/src/feature/linux/unikernel/README.md +++ b/src/feature/linux/unikernel/README.md @@ -15,57 +15,15 @@ Some work can be done automatically: 5. Compile the kernel 6. Compile the dts -## Burn - -The process of burning images onto the board can be referenced in bsp/burn_tools/README.md. - -## DTB - -Notice for burning: - -The compiled dtb shoule be renamed as light_lpi4a.dtb because U-Boot use this filename as the default dtb. - -Or you can modify the default config of /extlinux/extlinux.conf in boot.ext4. - ## BIOS Riscv64 requires a proxy kernel to do some prepare before running the real linux kernel. And the proxy kernel currently is replaced by the OpenSBI project. -The OpenSBI used here is specially made for T-Head SoCs. - More detailed instruction is in bsp/bios/opensbi/README.md. + +# References -## U-Boot - -The U-Boot used here is specially made for T-Head SoCs. - -More detailed instruction is in bsp/uboot/README.md. - -## Latency testing - -After successfully booting the Linux on the board, real-time testing can be performed. - -Stress-ng can be used for generating system loads. - -I have tested real-time latency with the following stress-ng options: - -* stress-ng --cpu 4 -* stress-ng --vm 8 --vm-bytes 2G -* stress-ng --hdd 4 - -Cyclictest and Ftrace can be used for latency testing and tracing. - -Script for reference: - - $ mount -t tracefs none /sys/kernel/tracing - $ cd /sys/kernel/tracing - $ echo wakeup_rt > current_tracer - $ echo 1 > tracing_on - $ echo 0 > tracing_max_lat - $ stress-ng --cpu 4 & - $ cyclictest --mlockall --smp -- -## References - -* [Sipeed LicheePi 4A Documentation](https://wiki.sipeed.com/hardware/zh/lichee/th1520/lpi4a/1_intro.h) +* [A unikernel based on Linux](https://next.redhat.com/2018/11/14/ukl-a-unikernel-based-on-linux/) +* [unikernelLinux](https://github.com/unikernelLinux/ukl) -- Gitee