Skip to content

Commit 1dcba1f

Browse files
committed
firmware: add NVIDIA persistence mode hook
Works for 'setup' and the recently added 'hotplug'. Takes care of loading the modules in the zone and enabling persistence mode so the GPU stays awake. Signed-off-by: Steven Noonan <steven@edera.dev>
1 parent ee69e5a commit 1dcba1f

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

hack/build/firmware.sh

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ if [ "${KERNEL_FLAVOR}" = "zone-nvidiagpu" ] && [ "${TARGET_ARCH_STANDARD}" = "x
9595
#
9696

9797
create_links() {
98+
local base_path="$1"
9899
# create soname links
99-
find "$WORKLOAD_OVERLAY_PATH" -type f -name '*.so*' ! -path '*xorg/*' -print0 | while read -d $'\0' _lib; do
100+
find "$base_path" -type f -name '*.so*' ! -path '*xorg/*' -print0 | while read -d $'\0' _lib; do
100101
_soname=$(dirname "${_lib}")/$(readelf -d "${_lib}" | grep -Po 'SONAME.*: \[\K[^]]*' || true)
101102
_base=$(echo ${_soname} | sed -r 's/(.*)\.so.*/\1.so/')
102103
[[ -e "${_soname}" ]] || ln -s $(basename "${_lib}") "${_soname}"
@@ -105,9 +106,10 @@ if [ "${KERNEL_FLAVOR}" = "zone-nvidiagpu" ] && [ "${TARGET_ARCH_STANDARD}" = "x
105106
}
106107

107108
multiarch_symlink_mirror() {
108-
local triplet="$1"
109-
local src="${WORKLOAD_OVERLAY_PATH}/usr/lib"
110-
local dst="${WORKLOAD_OVERLAY_PATH}/usr/lib/${triplet}"
109+
local base_path="$1"
110+
local triplet="$2"
111+
local src="${base_path}/usr/lib"
112+
local dst="${base_path}/usr/lib/${triplet}"
111113
pushd "$src" >/dev/null
112114

113115
# 1) Recreate directory structure (excluding the triplet subtree to avoid recursion)
@@ -223,10 +225,47 @@ if [ "${KERNEL_FLAVOR}" = "zone-nvidiagpu" ] && [ "${TARGET_ARCH_STANDARD}" = "x
223225
install -Dm644 "$NV_EXTRACT_PATH/out/"nvidia_layers.json "$WORKLOAD_OVERLAY_PATH/usr/share/vulkan/implicit_layer.d/nvidia_layers.json"
224226
install -Dm644 "$NV_EXTRACT_PATH/out/"nvidia_icd_vksc.json "$WORKLOAD_OVERLAY_PATH/usr/share/vulkansc/icd.d/nvidia_icd_vksc.json"
225227

226-
create_links
228+
create_links "$WORKLOAD_OVERLAY_PATH"
227229

228230
# For Debian-like distributions
229-
multiarch_symlink_mirror x86_64-linux-gnu
231+
multiarch_symlink_mirror "$WORKLOAD_OVERLAY_PATH" x86_64-linux-gnu
230232

231-
cd "${OLDDIR}"
233+
#
234+
# Create NVIDIA persistence mode hook, ensures the driver is loaded and
235+
# initialized, and always ready to run a workload
236+
#
237+
NVIDIA_BOOTSTRAP_OVERLAY_PATH="$ADDONS_OUTPUT_PATH/overlays/nvidia-bootstrap"
238+
239+
mkdir -p "$NVIDIA_BOOTSTRAP_OVERLAY_PATH"
240+
241+
for BINARY in "$NV_EXTRACT_PATH/out/"nvidia-smi; do
242+
BN="$(basename "$BINARY")"
243+
install -Dm755 "$BINARY" "$NVIDIA_BOOTSTRAP_OVERLAY_PATH/usr/bin/$BN"
244+
done
245+
246+
# HACK: Just using the builder's glibc binaries so we can run nvidia-smi
247+
# without a full workload image
248+
for LIBRARY in "$NV_EXTRACT_PATH/out/"libnvidia-ml.so* /lib64/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/lib{pthread,m,dl,c,rt}.so.*; do
249+
BN="$(basename "$LIBRARY")"
250+
install -Dm755 "$LIBRARY" "$NVIDIA_BOOTSTRAP_OVERLAY_PATH/usr/lib/$BN"
251+
done
252+
ln -s usr/lib "$NVIDIA_BOOTSTRAP_OVERLAY_PATH/lib64"
253+
254+
create_links "$NVIDIA_BOOTSTRAP_OVERLAY_PATH"
255+
multiarch_symlink_mirror "$NVIDIA_BOOTSTRAP_OVERLAY_PATH" x86_64-linux-gnu
256+
257+
mkdir -p "$ADDONS_OUTPUT_PATH/hooks"
258+
cat > "$ADDONS_OUTPUT_PATH/hooks/nvidia-persist.toml" <<-EOF
259+
[[hooks.setup]]
260+
modules = ["nvidia", "nvidia_drm"]
261+
execute = ["/usr/bin/nvidia-smi", "-pm", "1"]
262+
ignore-failure = true
263+
264+
[[hooks.hotplug]]
265+
modules = ["nvidia", "nvidia_drm"]
266+
execute = ["/usr/bin/nvidia-smi", "-pm", "1"]
267+
ignore-failure = true
268+
EOF
269+
270+
cd "$OLDDIR"
232271
fi

0 commit comments

Comments
 (0)