Skip to content

Commit 137034a

Browse files
committed
builders: deprecate linux common-build
1 parent afa8df3 commit 137034a

File tree

5 files changed

+108
-47
lines changed

5 files changed

+108
-47
lines changed

builders/default.nix

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ benchmark: lib.makeScope lib.callPackageWith (self: {
3434
overlays = self.initramfs_overlays;
3535
};
3636

37-
linux-common-build = callPackage ./imgBuilder/linux/common-build.nix {};
38-
linux = callPackage ./imgBuilder/linux {
39-
inherit (self) initramfs;
40-
common-build = self.linux-common-build;
41-
};
37+
linux = callPackage ./imgBuilder/linux { inherit (self) initramfs; };
4238

4339
dts = callPackage ./imgBuilder/opensbi/dts {};
4440
opensbi-common-build = callPackage ./imgBuilder/opensbi/common-build.nix {

builders/imgBuilder/linux/default.nix

+40-39
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
11
{ stdenv
2+
, runCommand
3+
, writeText
24
, bc
35
, flex
46
, 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
217

228
, riscv64-cc
239
, rmExt
2410
, initramfs
2511
, common-build
26-
}@args: let overlayfsDisabled = stdenv.mkDerivation {
12+
}@args: stdenv.mkDerivation (finalAttrs: {
2713
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+
};
2918
buildInputs = [
3019
bc
3120
flex
3221
bison
3322
riscv64-cc
3423
];
3524

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+
3655
buildPhase = ''
3756
export ARCH=riscv
3857
export CROSS_COMPILE=riscv64-unknown-linux-gnu-
3958
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-
4559
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
4762
make -j $NIX_BUILD_CORES
4863
'';
4964
installPhase = ''
50-
# runInLinuxVM will auto create dir $out
51-
rm -rf $out
5265
cp arch/riscv/boot/Image $out
5366
'';
5467
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+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{ stdenv
2+
, bc
3+
, flex
4+
, 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+
22+
, riscv64-cc
23+
, rmExt
24+
, initramfs
25+
, common-build
26+
}@args: let overlayfsDisabled = stdenv.mkDerivation {
27+
name = "${rmExt initramfs.name}.linux";
28+
src = common-build;
29+
buildInputs = [
30+
bc
31+
flex
32+
bison
33+
riscv64-cc
34+
];
35+
36+
buildPhase = ''
37+
export ARCH=riscv
38+
export CROSS_COMPILE=riscv64-unknown-linux-gnu-
39+
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+
export KBUILD_BUILD_TIMESTAMP=@0
46+
make xiangshan_benchmark_defconfig
47+
make -j $NIX_BUILD_CORES
48+
'';
49+
installPhase = ''
50+
# runInLinuxVM will auto create dir $out
51+
rm -rf $out
52+
cp arch/riscv/boot/Image $out
53+
'';
54+
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

docs/designs/4.builders/images/deps_dot.py

-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def __init__(self, **args):
2929
def __init__(self, **args):
3030
CCluster.__init__(self, "linux", **args)
3131
self.initramfs = add(self, self.InitRamFs())
32-
self.common_build = addNode(self, "common-build")
3332
def __init__(self, **args):
3433
CCluster.__init__(self, "opensbi", **args)
3534
self.dts = addNode(self, "dts")
@@ -100,7 +99,6 @@ def __init__(self, name, **args):
10099

101100
self._level2_ = add(self, CCluster("_level2_", label="", bgcolor="transparent", pencolor="transparent"))
102101
addEdge(self, self._level1_, self._level2_, color="transparent")
103-
self.linux_common_build = addNode(self._level2_, "linux-common-build"); set_colors.gcpt(self.linux_common_build)
104102
self.linux = addNode(self._level2_, "linux"); set_colors.gcpt(self.linux)
105103
self.dts = addNode(self._level2_, "dts"); set_colors.gcpt(self.dts)
106104
self.opensbi_common_build = addNode(self._level2_, "opensbi-common-build"); set_colors.gcpt(self.opensbi_common_build)
@@ -140,7 +138,6 @@ def addFlatEdge(g: Graph, n1: Node|CCluster, n2: Node|CCluster, **args):
140138
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux.initramfs.overlays.qemu_trap, output.qemu_trap)
141139
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux.initramfs.overlays, output.initramfs_overlays)
142140
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux.initramfs, output.initramfs)
143-
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux.common_build, output.linux_common_build)
144141
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux, output.linux)
145142
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.dts, output.dts)
146143
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.common_build, output.opensbi_common_build)

0 commit comments

Comments
 (0)