-
Notifications
You must be signed in to change notification settings - Fork 5
nvidia: skip services when hardware is absent #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
meta-nvidia/recipes-graphics/nvidia/files/nvidia-fabricmanager-nvswitch-condition.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Skip the fabric manager cleanly on hosts without NVSwitch (i.e. any non | ||
| # HGX/DGX instance, including GPU instances that have no NVSwitch) instead of | ||
| # letting it fail. ExecCondition exit 1 -> systemd marks the unit as skipped, | ||
| # not failed. | ||
| [Service] | ||
| ExecCondition=/usr/bin/nvidia-gpu-detect nvswitch |
51 changes: 51 additions & 0 deletions
51
meta-nvidia/recipes-graphics/nvidia/files/nvidia-gpu-detect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/bin/sh | ||
| # nvidia-gpu-detect - report NVIDIA GPU / NVSwitch presence via sysfs PCI. | ||
| # | ||
| # Intended for use as a systemd ExecCondition= so that GPU-only services skip | ||
| # cleanly (instead of failing) on instances without a GPU / without NVSwitch. | ||
| # This lets the NVIDIA and plain images be merged into a single image. | ||
| # | ||
| # exit 0 -> hardware present (systemd runs the unit) | ||
| # exit 1 -> hardware absent (systemd skips the unit, no failure) | ||
| # | ||
| # Detection mirrors scripts/bin/enable_vfio_passthrough.sh, but reads PCI class | ||
| # codes from sysfs so it works before the nvidia driver is loaded and without | ||
| # relying on lspci / the pci.ids name database: | ||
| # | ||
| # GPU = NVIDIA (0x10de) VGA (0x0300xx) or 3D controller (0x0302xx) | ||
| # NVSwitch = NVIDIA (0x10de) bridge (0x06xxxx, any bridge subclass) | ||
| # | ||
| # NVSwitch matches any NVIDIA bridge-class device (mirrors the `grep 'Bridge'` | ||
| # heuristic in scripts/bin/enable_vfio_passthrough.sh) rather than only the | ||
| # "Other bridge" subclass 0x0680, so it stays correct if a future NVSwitch | ||
| # enumerates under a different bridge subclass. This is safe here because these | ||
| # images run as TDX guests whose only NVIDIA-vendor devices are passed-through | ||
| # GPUs (class 0x03xx) and NVSwitches (class 0x06xx). | ||
|
|
||
| NVIDIA_VENDOR="0x10de" | ||
|
|
||
|
kvinwang marked this conversation as resolved.
|
||
| # match_vendor_class <class-glob>: succeed if any PCI device has NVIDIA's | ||
| # vendor id and a class matching the given glob (e.g. "0x0302*"). | ||
| match_vendor_class() { | ||
| for dev in /sys/bus/pci/devices/*; do | ||
| [ -r "$dev/vendor" ] && [ -r "$dev/class" ] || continue | ||
| [ "$(cat "$dev/vendor")" = "$NVIDIA_VENDOR" ] || continue | ||
| case "$(cat "$dev/class")" in | ||
| $1) return 0 ;; | ||
| esac | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| case "${1:-gpu}" in | ||
| gpu) | ||
| match_vendor_class '0x0300*' || match_vendor_class '0x0302*' | ||
| ;; | ||
| nvswitch) | ||
| match_vendor_class '0x06*' | ||
| ;; | ||
| *) | ||
| echo "usage: ${0##*/} {gpu|nvswitch}" >&2 | ||
| exit 64 | ||
| ;; | ||
| esac | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
meta-nvidia/recipes-graphics/nvidia/nvidia-fabricmanager_%.bbappend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| FILESEXTRAPATHS:prepend := "${THISDIR}/files:" | ||
|
|
||
| # Only start the fabric manager when NVSwitch hardware is present, so the | ||
| # service is silently skipped (not failed) on non-NVSwitch instances. | ||
| SRC_URI += "file://nvidia-fabricmanager-nvswitch-condition.conf" | ||
|
|
||
| RDEPENDS:${PN} += "nvidia-gpu-detect" | ||
|
|
||
| do_install:append() { | ||
| install -d ${D}${systemd_system_unitdir}/nvidia-fabricmanager.service.d | ||
| install -m 0644 ${UNPACKDIR}/nvidia-fabricmanager-nvswitch-condition.conf \ | ||
| ${D}${systemd_system_unitdir}/nvidia-fabricmanager.service.d/10-nvswitch-condition.conf | ||
| } | ||
|
|
||
| FILES:${PN} += "${systemd_system_unitdir}/nvidia-fabricmanager.service.d/10-nvswitch-condition.conf" |
16 changes: 16 additions & 0 deletions
16
meta-nvidia/recipes-graphics/nvidia/nvidia-gpu-detect_1.0.bb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| SUMMARY = "Detect NVIDIA GPU / NVSwitch presence for conditional systemd services" | ||
| DESCRIPTION = "Small sysfs-based helper used as a systemd ExecCondition= so that \ | ||
| GPU-only services (nvidia-persistenced, nvidia-fabricmanager) skip cleanly on \ | ||
| instances without a GPU or without NVSwitch, allowing a single merged image." | ||
| LICENSE = "CLOSED" | ||
|
|
||
| SRC_URI = "file://nvidia-gpu-detect" | ||
|
|
||
| S = "${UNPACKDIR}" | ||
|
|
||
| do_install() { | ||
| install -d ${D}${bindir} | ||
| install -m 0755 ${UNPACKDIR}/nvidia-gpu-detect ${D}${bindir}/nvidia-gpu-detect | ||
| } | ||
|
|
||
| FILES:${PN} = "${bindir}/nvidia-gpu-detect" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.