Skip to content

Commit

Permalink
Merge pull request #207 from bcressey/neuron-merge
Browse files Browse the repository at this point in the history
build neuron kmod in kernel packages
  • Loading branch information
bcressey authored Nov 5, 2024
2 parents 66eb03b + acc3b6a commit 614e8e0
Show file tree
Hide file tree
Showing 34 changed files with 333 additions and 142 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ members = [
"packages/kmod",
"packages/kmod-5.10-nvidia",
"packages/kmod-5.15-nvidia",
"packages/kmod-6.1-neuron",
"packages/kmod-6.1-nvidia",
"packages/kubernetes-1.24",
"packages/kubernetes-1.25",
Expand Down
1 change: 0 additions & 1 deletion kits/bottlerocket-core-kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ keyutils = { path = "../../packages/keyutils" }
kmod-5_10-nvidia = { path = "../../packages/kmod-5.10-nvidia" }
kmod-5_15-nvidia = { path = "../../packages/kmod-5.15-nvidia" }
kmod-6_1-nvidia = { path = "../../packages/kmod-6.1-nvidia" }
kmod-6_1-neuron = { path = "../../packages/kmod-6.1-neuron" }
kmod = { path = "../../packages/kmod" }
kubernetes-1_24 = { path = "../../packages/kubernetes-1.24" }
kubernetes-1_25 = { path = "../../packages/kubernetes-1.25" }
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion packages/kernel-5.10/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ package-name = "kernel-5.10"
path = "../packages.rs"

[[package.metadata.build-package.external-files]]
# Use latest-srpm-url.sh to get this.
# Use latest-kernel-srpm-url.sh to get this.
url = "https://cdn.amazonlinux.com/blobstore/a9b5c6b9ca0d2a84e4dc3b963a73017a055d602139d2293ff394d33b08111be7/kernel-5.10.227-219.884.amzn2.src.rpm"
sha512 = "6729b3ef34c451685d29b736a1a98a6487d158707f503ae35cb0427daf034a442d8768e3cc0db3781bb4b17f316fd53811a211892be52c7f8d2feadf7773611c"

[[package.metadata.build-package.external-files]]
# Use latest-neuron-srpm-url.sh to get this.
url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm"
sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579"

[build-dependencies]
microcode = { path = "../microcode" }
64 changes: 63 additions & 1 deletion packages/kernel-5.10/kernel-5.10.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ Release: 1%{?dist}
Summary: The Linux kernel
License: GPL-2.0 WITH Linux-syscall-note
URL: https://www.kernel.org/
# Use latest-srpm-url.sh to get this.
# Use latest-kernel-srpm-url.sh to get this.
Source0: https://cdn.amazonlinux.com/blobstore/a9b5c6b9ca0d2a84e4dc3b963a73017a055d602139d2293ff394d33b08111be7/kernel-5.10.227-219.884.amzn2.src.rpm
# Use latest-neuron-srpm-url.sh to get this.
Source1: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm
Source100: config-bottlerocket

# Neuron-related drop-ins.
Source220: neuron-sysinit.target.drop-in.conf
Source221: modprobe@neuron.service.drop-in.conf

# Help out-of-tree module builds run `make prepare` automatically.
Patch1001: 1001-Makefile-add-prepare-target-for-external-modules.patch
# Enable INITRAMFS_FORCE config option for our use case.
Expand Down Expand Up @@ -42,6 +48,11 @@ Requires: %{_cross_os}microcode-licenses
Requires: %{name}-modules = %{version}-%{release}
Requires: %{name}-devel = %{version}-%{release}

# Pull in platform-dependent modules.
%if "%{_cross_arch}" == "x86_64"
Requires: (%{name}-modules-neuron if (%{_cross_os}variant-platform(aws) without %{_cross_os}variant-flavor(nvidia)))
%endif

# The 5.10 kernel is not FIPS certified.
Conflicts: %{_cross_os}image-feature(fips)

Expand Down Expand Up @@ -72,6 +83,18 @@ Summary: Modules for the Linux kernel
%description modules
%{summary}.

%if "%{_cross_arch}" == "x86_64"
%package modules-neuron
Summary: Modules for the Linux kernel with Neuron hardware
Requires: %{name}
Requires: %{_cross_os}ghostdog
Requires: %{_cross_os}variant-platform(aws)
Conflicts: %{_cross_os}variant-flavor(nvidia)

%description modules-neuron
%{summary}.
%endif

%package headers
Summary: Header files for the Linux kernel for use by glibc

Expand Down Expand Up @@ -110,6 +133,13 @@ scripts/kconfig/merge_config.sh \

rm -f ../config-* ../*.patch

%if "%{_cross_arch}" == "x86_64"
cd %{_builddir}
rpm2cpio %{SOURCE1} | cpio -idmu './usr/src/aws-neuronx-*'
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \;
rm -r usr
%endif

%global kmake \
make -s\\\
ARCH="%{_cross_karch}"\\\
Expand All @@ -125,10 +155,22 @@ make -s\\\
%kmake %{?_smp_mflags} %{_cross_kimage}
%kmake %{?_smp_mflags} modules

%if "%{_cross_arch}" == "x86_64"
%kmake %{?_smp_mflags} M=%{_builddir}/neuron
%endif

%install
%kmake %{?_smp_mflags} headers_install
%kmake %{?_smp_mflags} modules_install

%if "%{_cross_arch}" == "x86_64"
%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install V=1
mv \
%{buildroot}%{kernel_libdir}/extra/%{_builddir}/neuron/neuron.ko* \
%{buildroot}%{kernel_libdir}/extra
rm -rf %{buildroot}%{kernel_libdir}/extra/%{_builddir}
%endif

install -d %{buildroot}/boot
install -T -m 0755 arch/%{_cross_karch}/boot/%{_cross_kimage} %{buildroot}/boot/vmlinuz
install -m 0644 .config %{buildroot}/boot/config
Expand Down Expand Up @@ -237,6 +279,18 @@ rm -f %{buildroot}%{kernel_libdir}/build %{buildroot}%{kernel_libdir}/source
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/build
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source

# Install a copy of System.map so that module dependencies can be regenerated.
install -p -m 0600 System.map %{buildroot}%{kernel_libdir}

%if "%{_cross_arch}" == "x86_64"
# Add Neuron-related drop-ins to load the module when the hardware is present.
mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d
install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf

mkdir -p %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d
install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf
%endif

%files
%license COPYING LICENSES/preferred/GPL-2.0 LICENSES/exceptions/Linux-syscall-note
%{_cross_attribution_file}
Expand All @@ -246,6 +300,14 @@ ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source
%files modules
%dir %{_cross_libdir}/modules
%{_cross_libdir}/modules/*
%exclude %{kernel_libdir}/extra/neuron.ko.gz

%if "%{_cross_arch}" == "x86_64"
%files modules-neuron
%{kernel_libdir}/extra/neuron.ko.gz
%{_cross_unitdir}/sysinit.target.d/neuron.conf
%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf
%endif

%files headers
%dir %{_cross_includedir}/asm
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/kernel-5.10/modprobe@neuron.service.drop-in.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
ConditionPathExists=!/etc/.neuron-modprobe-done

[Service]
ExecCondition=/usr/bin/touch /etc/.neuron-modprobe-done
ExecCondition=/usr/bin/ghostdog neuron-present
RemainAfterExit=true
2 changes: 2 additions & 0 deletions packages/kernel-5.10/neuron-sysinit.target.drop-in.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Unit]
Wants=modprobe@neuron.service
1 change: 1 addition & 0 deletions packages/kernel-5.15/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.rpm
7 changes: 6 additions & 1 deletion packages/kernel-5.15/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ package-name = "kernel-5.15"
path = "../packages.rs"

[[package.metadata.build-package.external-files]]
# Use latest-srpm-url.sh to get this.
# Use latest-kernel-srpm-url.sh to get this.
url = "https://cdn.amazonlinux.com/blobstore/9cea3dae03703f3c4c78fcb1302eeee5fe4c07ebf53d783cf3aaf7e4f30a6d39/kernel-5.15.168-114.166.amzn2.src.rpm"
sha512 = "5b0b0e2640bb04d4868b8820781029d8148c7939802c1b4edcf580533848afe70f7c6372e6e2306dfc017d2b32120a446ada15b105f7b2fe766b9382f83937d3"

[[package.metadata.build-package.external-files]]
# Use latest-neuron-srpm-url.sh to get this.
url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm"
sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579"

[build-dependencies]
microcode = { path = "../microcode" }
60 changes: 59 additions & 1 deletion packages/kernel-5.15/kernel-5.15.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ Release: 1%{?dist}
Summary: The Linux kernel
License: GPL-2.0 WITH Linux-syscall-note
URL: https://www.kernel.org/
# Use latest-srpm-url.sh to get this.
# Use latest-kernel-srpm-url.sh to get this.
Source0: https://cdn.amazonlinux.com/blobstore/9cea3dae03703f3c4c78fcb1302eeee5fe4c07ebf53d783cf3aaf7e4f30a6d39/kernel-5.15.168-114.166.amzn2.src.rpm
# Use latest-neuron-srpm-url.sh to get this.
Source1: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm
Source100: config-bottlerocket

# Neuron-related drop-ins.
Source220: neuron-sysinit.target.drop-in.conf
Source221: modprobe@neuron.service.drop-in.conf

# Help out-of-tree module builds run `make prepare` automatically.
Patch1001: 1001-Makefile-add-prepare-target-for-external-modules.patch
# Expose tools/* targets for out-of-tree module builds.
Expand Down Expand Up @@ -37,6 +43,11 @@ Requires: %{_cross_os}microcode-licenses
Requires: %{name}-modules = %{version}-%{release}
Requires: %{name}-devel = %{version}-%{release}

# Pull in platform-dependent modules.
%if "%{_cross_arch}" == "x86_64"
Requires: (%{name}-modules-neuron if (%{_cross_os}variant-platform(aws) without %{_cross_os}variant-flavor(nvidia)))
%endif

# The 5.15 kernel is not FIPS certified.
Conflicts: %{_cross_os}image-feature(fips)

Expand Down Expand Up @@ -67,6 +78,18 @@ Summary: Modules for the Linux kernel
%description modules
%{summary}.

%if "%{_cross_arch}" == "x86_64"
%package modules-neuron
Summary: Modules for the Linux kernel with Neuron hardware
Requires: %{name}
Requires: %{_cross_os}ghostdog
Requires: %{_cross_os}variant-platform(aws)
Conflicts: %{_cross_os}variant-flavor(nvidia)

%description modules-neuron
%{summary}.
%endif

%package headers
Summary: Header files for the Linux kernel for use by glibc

Expand Down Expand Up @@ -105,6 +128,13 @@ scripts/kconfig/merge_config.sh \

rm -f ../config-* ../*.patch

%if "%{_cross_arch}" == "x86_64"
cd %{_builddir}
rpm2cpio %{SOURCE1} | cpio -idmu './usr/src/aws-neuronx-*'
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \;
rm -r usr
%endif

%global kmake \
make -s\\\
ARCH="%{_cross_karch}"\\\
Expand All @@ -120,10 +150,18 @@ make -s\\\
%kmake %{?_smp_mflags} %{_cross_kimage}
%kmake %{?_smp_mflags} modules

%if "%{_cross_arch}" == "x86_64"
%kmake %{?_smp_mflags} M=%{_builddir}/neuron
%endif

%install
%kmake %{?_smp_mflags} headers_install
%kmake %{?_smp_mflags} modules_install

%if "%{_cross_arch}" == "x86_64"
%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install
%endif

install -d %{buildroot}/boot
install -T -m 0755 arch/%{_cross_karch}/boot/%{_cross_kimage} %{buildroot}/boot/vmlinuz
install -m 0644 .config %{buildroot}/boot/config
Expand Down Expand Up @@ -232,6 +270,18 @@ rm -f %{buildroot}%{kernel_libdir}/build %{buildroot}%{kernel_libdir}/source
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/build
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source

# Install a copy of System.map so that module dependencies can be regenerated.
install -p -m 0600 System.map %{buildroot}%{kernel_libdir}

%if "%{_cross_arch}" == "x86_64"
# Add Neuron-related drop-ins to load the module when the hardware is present.
mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d
install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf

mkdir -p %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d
install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf
%endif

%files
%license COPYING LICENSES/preferred/GPL-2.0 LICENSES/exceptions/Linux-syscall-note
%{_cross_attribution_file}
Expand All @@ -241,6 +291,14 @@ ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source
%files modules
%dir %{_cross_libdir}/modules
%{_cross_libdir}/modules/*
%exclude %{kernel_libdir}/extra/neuron.ko.gz

%if "%{_cross_arch}" == "x86_64"
%files modules-neuron
%{kernel_libdir}/extra/neuron.ko.gz
%{_cross_unitdir}/sysinit.target.d/neuron.conf
%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf
%endif

%files headers
%dir %{_cross_includedir}/asm
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/kernel-5.15/latest-neuron-srpm-url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
cmd="
dnf install -q -y --releasever=latest yum-utils &&
dnf download -q --repofrompath neuron,https://yum.repos.neuron.amazonaws.com --repo=neuron --urls aws-neuronx-dkms
"
docker run --rm amazonlinux:2023 bash -c "${cmd}" \
| grep '^http' \
| xargs --max-args=1 --no-run-if-empty realpath --canonicalize-missing --relative-to=. \
| sed 's_:/_://_'
7 changes: 7 additions & 0 deletions packages/kernel-5.15/modprobe@neuron.service.drop-in.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
ConditionPathExists=!/etc/.neuron-modprobe-done

[Service]
ExecCondition=/usr/bin/touch /etc/.neuron-modprobe-done
ExecCondition=/usr/bin/ghostdog neuron-present
RemainAfterExit=true
2 changes: 2 additions & 0 deletions packages/kernel-5.15/neuron-sysinit.target.drop-in.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Unit]
Wants=modprobe@neuron.service
1 change: 1 addition & 0 deletions packages/kernel-6.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.rpm
7 changes: 6 additions & 1 deletion packages/kernel-6.1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ package-name = "kernel-6.1"
path = "../packages.rs"

[[package.metadata.build-package.external-files]]
# Use latest-srpm-url.sh to get this.
# Use latest-kernel-srpm-url.sh to get this.
url = "https://cdn.amazonlinux.com/al2023/blobstore/3b0aa0d6cf05ca272d9802ccddfc28201675b2abac6abb307f5c4b8d3ca68d26/kernel-6.1.112-124.190.amzn2023.src.rpm"
sha512 = "f7c78716a78d453a0eaaae45f6aaf00a466d7b65e7def0c887f5ff267726b668f725b8a359770a93dbee477313cf297fa6b641580c073aa76dcefda39c19f5c2"

[[package.metadata.build-package.external-files]]
# Use latest-neuron-srpm-url.sh to get this.
url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm"
sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579"

[build-dependencies]
microcode = { path = "../microcode" }
Loading

0 comments on commit 614e8e0

Please sign in to comment.