Skip to content

Commit db0b125

Browse files
committed
CI: stop display container before switching driver modes
Closes #3183 Stop NVDisplay.ContainerLocalSystem before invoking nvidia-smi -fdm and wait for every NVDisplay.Container process to exit. After a driver install, the display container can crash-loop while the GPU is cycled. If its teardown overlaps PnP removal, nvlddmkm can remain loaded and nvidia-smi may never recover. Bound the process drain at 60 seconds and report remaining PIDs on failure. Preserve the existing mode-specific logging and device-cycle stabilization behavior.
1 parent dfad7e3 commit db0b125

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

‎ci/tools/configure_driver_mode.ps1‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,50 @@
1111
# Inputs (env):
1212
# DRIVER_MODE One of WDDM, TCC, MCDM.
1313

14+
function Stop-DisplayContainer {
15+
16+
# A crash-looping display-container process can race the subsequent device
17+
# cycle and prevent the NVIDIA kernel driver from unloading.
18+
Write-Output "Stopping NVDisplay.ContainerLocalSystem..."
19+
Stop-Service -Name "NVDisplay.ContainerLocalSystem" -Force -ErrorAction Stop
20+
21+
Write-Output "Waiting for NVDisplay.Container processes to exit..."
22+
$deadline = (Get-Date).AddSeconds(60)
23+
$container_processes = @(Get-Process -Name "NVDisplay.Container" -ErrorAction SilentlyContinue)
24+
while ($container_processes.Count -gt 0 -and (Get-Date) -lt $deadline) {
25+
Start-Sleep -Milliseconds 500
26+
$container_processes = @(Get-Process -Name "NVDisplay.Container" -ErrorAction SilentlyContinue)
27+
}
28+
if ($container_processes.Count -gt 0) {
29+
$process_ids = $container_processes.Id -join ", "
30+
Write-Error "NVDisplay.Container processes ($process_ids) did not exit within 60s of stopping NVDisplay.ContainerLocalSystem"
31+
exit 1
32+
}
33+
}
34+
1435
function Set-DriverMode {
1536

1637
# Map matrix DRIVER_MODE to nvidia-smi -fdm code.
1738
# This assumes we have the prior knowledge on which GPU can use which mode.
1839
$driver_mode = $env:DRIVER_MODE
1940
if ($driver_mode -eq "WDDM") {
2041
Write-Output "Setting driver mode to WDDM..."
21-
nvidia-smi -fdm 0
42+
$driver_mode_code = 0
2243
} elseif ($driver_mode -eq "TCC") {
2344
Write-Output "Setting driver mode to TCC..."
24-
nvidia-smi -fdm 1
45+
$driver_mode_code = 1
2546
} elseif ($driver_mode -eq "MCDM") {
2647
Write-Output "Setting driver mode to MCDM..."
27-
nvidia-smi -fdm 2
48+
$driver_mode_code = 2
2849
} else {
2950
Write-Output "Unknown driver mode: $driver_mode"
3051
exit 1
3152
}
3253

54+
Stop-DisplayContainer
55+
56+
nvidia-smi -fdm $driver_mode_code
57+
3358
# Only restart NVIDIA display adapters, not other display devices (e.g. QEMU VGA).
3459
$nvidia_devices = @(Get-PnpDevice -Class Display -FriendlyName "NVIDIA*")
3560
$gpu_count = $nvidia_devices.Count

0 commit comments

Comments
 (0)