|
1 | 1 | { stdenv
|
| 2 | +, runCommand |
| 3 | +, writeText |
2 | 4 | , bc
|
3 | 5 | , flex
|
4 | 6 | , bison
|
5 |
| -# * With OverlayFS disabled, the default `unpackPhase` will copy the entire `common-build`, |
6 |
| -# which involves approximately 1.7GB of disk writes. |
7 |
| -# When building N linux images simultaneously, the disk write throughput becomes N*1.7GB. |
8 |
| -# * With OverlayFS enabled, the build processes are overlaied onto 1.7GB `common-build`, |
9 |
| -# resulting in minimal disk writes. |
10 |
| -# However, because of the nix sandbox, overlayfs cannot be used directly in nix build processes, |
11 |
| -# we utilize `runInLinuxVM` to work around this limitation. |
12 |
| -# (For more details, see https://discourse.nixos.org/t/using-fuse-inside-nix-derivation/8534.) |
13 |
| -# * If your nixbld* users have access to /dev/kvm, |
14 |
| -# there will be no noticable performance degradation. |
15 |
| -# * If your nixbld* users lack access to /dev/kvm, |
16 |
| -# QEMU will fall back to translation mode (TCG), |
17 |
| -# which is approximately 100 times slower. |
18 |
| -, enableOverlayFS ? true |
19 |
| -, fuse-overlayfs |
20 |
| -, vmTools |
21 | 7 |
|
22 | 8 | , riscv64-cc
|
23 | 9 | , rmExt
|
24 | 10 | , initramfs
|
25 | 11 | , common-build
|
26 |
| -}@args: let overlayfsDisabled = stdenv.mkDerivation { |
| 12 | +}@args: stdenv.mkDerivation (finalAttrs: { |
27 | 13 | name = "${rmExt initramfs.name}.linux";
|
28 |
| - src = common-build; |
| 14 | + src = builtins.fetchurl { |
| 15 | + url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.10.7.tar.xz"; |
| 16 | + sha256 = "1adkbn6dqbpzlr3x87a18mhnygphmvx3ffscwa67090qy1zmc3ch"; |
| 17 | + }; |
29 | 18 | buildInputs = [
|
30 | 19 | bc
|
31 | 20 | flex
|
32 | 21 | bison
|
33 | 22 | riscv64-cc
|
34 | 23 | ];
|
35 | 24 |
|
| 25 | + patches = [ |
| 26 | + # Shutdown QEMU when the kernel raises a panic. |
| 27 | + # This feature prevents the kernel from entering an endless loop, |
| 28 | + # allowing for quicker identification of failed SPEC CPU testCases. |
| 29 | + ./panic_shutdown.patch |
| 30 | + ]; |
| 31 | + |
| 32 | + defconfig = runCommand "defconfig" {} '' |
| 33 | + path=$(tar tf ${finalAttrs.src} | grep arch/riscv/configs/defconfig) |
| 34 | + tar xf ${finalAttrs.src} $path -O > $out |
| 35 | + ''; |
| 36 | + baseconfig = runCommand "baseconfig" {} '' |
| 37 | + sed '/=m/d' ${finalAttrs.defconfig} | sed '/NFS/d' | sed '/CONFIG_FTRACE/d' > $out |
| 38 | + ''; |
| 39 | + # TODO: auto deduplicate and merge xiangshan_defconfig to baseconfig |
| 40 | + xiangshan_defconfig = writeText "xiangshan_defconfig" '' |
| 41 | + ${builtins.readFile finalAttrs.baseconfig} |
| 42 | + CONFIG_LOG_BUF_SHIFT=15 |
| 43 | + CONFIG_NONPORTABLE=y |
| 44 | + CONFIG_RISCV_SBI_V01=y |
| 45 | + CONFIG_SERIO_LIBPS2=y |
| 46 | + CONFIG_SERIAL_UARTLITE=y |
| 47 | + CONFIG_SERIAL_UARTLITE_CONSOLE=y |
| 48 | + CONFIG_HVC_RISCV_SBI=y |
| 49 | + CONFIG_STACKTRACE=y |
| 50 | + CONFIG_RCU_CPU_STALL_TIMEOUT=300 |
| 51 | + CONFIG_CMDLINE="norandmaps" |
| 52 | + CONFIG_INITRAMFS_SOURCE="${initramfs}" |
| 53 | + ''; |
| 54 | + |
36 | 55 | buildPhase = ''
|
37 | 56 | export ARCH=riscv
|
38 | 57 | export CROSS_COMPILE=riscv64-unknown-linux-gnu-
|
39 | 58 |
|
40 |
| - # Prepare benchmark config |
41 |
| - TESTCASE_DEFCONFIG=arch/riscv/configs/xiangshan_benchmark_defconfig |
42 |
| - cat arch/riscv/configs/xiangshan_defconfig > $TESTCASE_DEFCONFIG |
43 |
| - echo CONFIG_INITRAMFS_SOURCE=\"${initramfs}\" >> $TESTCASE_DEFCONFIG |
44 |
| -
|
45 | 59 | export KBUILD_BUILD_TIMESTAMP=@0
|
46 |
| - make xiangshan_benchmark_defconfig |
| 60 | + ln -s ${finalAttrs.xiangshan_defconfig} arch/riscv/configs/xiangshan_defconfig |
| 61 | + make xiangshan_defconfig |
47 | 62 | make -j $NIX_BUILD_CORES
|
48 | 63 | '';
|
49 | 64 | installPhase = ''
|
50 |
| - # runInLinuxVM will auto create dir $out |
51 |
| - rm -rf $out |
52 | 65 | cp arch/riscv/boot/Image $out
|
53 | 66 | '';
|
54 | 67 | passthru = args;
|
55 |
| -}; |
56 |
| -overlayfsEnabled = vmTools.runInLinuxVM (overlayfsDisabled.overrideAttrs (old: { |
57 |
| - unpackPhase = '' |
58 |
| - mkdir workdir |
59 |
| - mkdir upperdir |
60 |
| - mkdir overlaydir |
61 |
| - /run/modprobe fuse |
62 |
| - ${fuse-overlayfs}/bin/fuse-overlayfs -o lowerdir=${old.src},workdir=workdir,upperdir=upperdir overlaydir |
63 |
| - cd overlaydir |
64 |
| - ''; |
65 |
| - memSize = 2048; |
66 |
| -})); |
67 |
| -in if enableOverlayFS then overlayfsEnabled else overlayfsDisabled |
| 68 | +}) |
0 commit comments