Skip to content

Applies D-Notifier event that arrives on resume - #1493

Open
pacopedraza wants to merge 1 commit into
NVIDIA:mainfrom
pacopedraza:fpedraza/dnotifier-resume-fix
Open

pacopedraza wants to merge 1 commit into
NVIDIA:mainfrom
pacopedraza:fpedraza/dnotifier-resume-fix

Conversation

@pacopedraza

Copy link
Copy Markdown

On my Laptop the SBIOS sends the D-Notifier right when the system wakes up, before RM has resumed the GPU. RmHandleDNotifierEvent() gets NV_ERR_GPU_NOT_FULL_POWER back and the event is lost. The resume path calls RmRequestDNotifierState() to get it again, but this SBIOS doesn't implement GPS_FUNC_REQUESTDXSTATE (returns NV_ERR_NOT_SUPPORTED), so nothing ever re-applies it.

Save the event when it fails with NV_ERR_GPU_NOT_FULL_POWER and apply it in RmPowerManagement() after the GPU is back. If a newer event comes in first, it replaces the saved one. Also log the deferral at LEVEL_INFO, since it's not an error anymore.

Tested with 580.178.04 (same code as 615.78.08 here) on an Alienware m18 R1 with an RTX 4090 Laptop GPU, Fedora 43, kernel 7.2.11, s2idle. Did 4 suspend/resume cycles, on AC and on battery, sleeping between 2 and 13 minutes. Each time the saved event was applied fine about 0.7 s after resume, and the "Failed to handle ACPI D-Notifier event, status=0x11" error is gone. No Xids, and power limits/clocks after resume are the same as after a fresh boot. Also built it on 615.78.08 against kernels 7.1.9 and 7.2.11.

Link: #1372

On my Laptop the `SBIOS` sends the `D-Notifier` right when the system
wakes up, before RM has resumed the GPU. `RmHandleDNotifierEvent()`
gets `NV_ERR_GPU_NOT_FULL_POWER` back and the event is lost. The resume
path calls `RmRequestDNotifierState()` to get it again, but this
`SBIOS` doesn't implement `GPS_FUNC_REQUESTDXSTATE` (returns
`NV_ERR_NOT_SUPPORTED`), so nothing ever re-applies it.

Save the event when it fails with `NV_ERR_GPU_NOT_FULL_POWER` and apply
it in `RmPowerManagement()` after the GPU is back. If a newer event
comes in first, it replaces the saved one. Also log the deferral at
`LEVEL_INFO`, since it's not an error anymore.

Tested with `580.178.04` (same code as `615.78.08` here) on an Alienware
m18 R1 with an `RTX 4090` Laptop GPU, Fedora 43, kernel 7.2.11, s2idle.
Did 4 `suspend/resume` cycles, on AC and on battery, sleeping between
2 and 13 minutes. Each time the saved event was applied fine about
0.7 s after resume, and the "Failed to handle `ACPI` `D-Notifier` event,
status=0x11" error is gone. No Xids, and power limits/clocks after
resume are the same as after a fresh boot. Also built it on `615.78.08`
against kernels `7.1.9` and `7.2.11`.

Link: NVIDIA#1372

Signed-off-by: Francisco Pedraza <[email protected]>
@CLAassistant

CLAassistant commented Oct 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Helipil0t

Copy link
Copy Markdown

Positive test report for a locally adapted version of this PR on another Dell/Ada laptop:

  • Dell XPS 15 9530, Intel i7-13700H, RTX 4070 Laptop GPU
  • Debian, kernel 6.12.115+deb13.1-amd64
  • NVIDIA 620.70.06 open kernel modules
  • Dell WD22TB4 dock supplying power; same dock/display setup before and after

Before patching, suspend/resume could leave the GPU continuously hardware-power-braked, with GTA Enhanced dropping to roughly 12–21 FPS. The hardware power-brake counter advanced for essentially 100% of elapsed time, including under GPU load. Kernel logs showed:

RmHandleDNotifierEvent: Failed to handle ACPI D-Notifier event, status=0x11

Physically disconnecting and reconnecting the dock cleared the brake and restored performance. The firmware capability response did not advertise REQUESTDXSTATE support (function 0x12 / bit 18 clear). A separate current-BIOS-policy refresh/ACK request was accepted but did not clear the brake, either under load or at idle.

Adaptations from this PR:

  1. Moved replay into the common successful rm_power_management() system-resume completion, before releasing the API/GPU locks, so the hook covers the legacy and S0ix/GC6 dispatch paths in 620.70.06.
  2. Retained the pending request if replay again returns NV_ERR_GPU_NOT_FULL_POWER; cleared it after success or a non-retryable error.
  3. Added diagnostic logging. The saved state remains the actual BIOS-requested auxiliary state; no power level or budget is forced.

Results: After a normal reboot, we verified the loaded custom module by its ELF build ID. Three suspend/resume checks passed with hardware power braking OFF. GTA ran at 60–70 FPS during testing; the second cycle followed quitting the game, and the third cycle suspended with GTA still running and again returned with the brake OFF. FPS after that third cycle was not separately recorded. nvidia-powerd was active and thermald stopped for these tests.

This supports the deferred-notifier approach for the reproduced resume failure. This was an adapted build, and we have not independently exercised every resume branch or the retained-retry condition. We have not yet collected post-patch kernel logs proving execution of the deferred replay itself.

The exact patch tested against 620.70.06 is included below for review and reproduction. Thank you for identifying this race.

Tested 620.70.06 adaptation
diff --git a/src/nvidia/arch/nvalloc/unix/include/nv-priv.h b/src/nvidia/arch/nvalloc/unix/include/nv-priv.h
--- a/src/nvidia/arch/nvalloc/unix/include/nv-priv.h
+++ b/src/nvidia/arch/nvalloc/unix/include/nv-priv.h
@@ -56,6 +56,8 @@
 {
     NvU32  IntrEn;
     NvBool InHibernate;
+    NvBool DNotifierPending;
+    NvU32  DNotifierAuxPowerState;
 } nv_pm_state_t;
 
 /*
diff --git a/src/nvidia/arch/nvalloc/unix/include/osapi.h b/src/nvidia/arch/nvalloc/unix/include/osapi.h
--- a/src/nvidia/arch/nvalloc/unix/include/osapi.h
+++ b/src/nvidia/arch/nvalloc/unix/include/osapi.h
@@ -129,6 +129,7 @@
 NV_STATUS  RmPowerSourceChangeEvent(nv_state_t *, NvU32);
 
 void       RmRequestDNotifierState(nv_state_t *);
+void       RmApplyPendingDNotifierState(nv_state_t *);
 
 const NvU8 *RmGetGpuUuidRaw(nv_state_t *);
 
diff --git a/src/nvidia/arch/nvalloc/unix/src/dynamic-power.c b/src/nvidia/arch/nvalloc/unix/src/dynamic-power.c
--- a/src/nvidia/arch/nvalloc/unix/src/dynamic-power.c
+++ b/src/nvidia/arch/nvalloc/unix/src/dynamic-power.c
@@ -2730,6 +2730,19 @@
                         }
                     }
 
+                    //
+                    // Replay only the actual SBIOS request saved when an ACPI
+                    // D-Notifier arrived before the GPU finished resuming.
+                    // This common system-resume completion covers the legacy
+                    // and S0ix/GC6 paths. Both API and GPU locks are held here;
+                    // runtime GCx transitions do not necessarily hold API lock.
+                    //
+                    if ((pmAction == NV_PM_ACTION_RESUME) &&
+                        (rmStatus == NV_OK) && IsMobile(pGpu))
+                    {
+                        RmApplyPendingDNotifierState(pNv);
+                    }
+
                     // UNLOCK: release GPUs lock
                     rmGpuLocksRelease(GPUS_LOCK_FLAGS_NONE, NULL);
                 }
diff --git a/src/nvidia/arch/nvalloc/unix/src/osapi.c b/src/nvidia/arch/nvalloc/unix/src/osapi.c
--- a/src/nvidia/arch/nvalloc/unix/src/osapi.c
+++ b/src/nvidia/arch/nvalloc/unix/src/osapi.c
@@ -1381,6 +1381,62 @@
 }
 
 /*!
+ * @brief Apply a D-Notifier event that was deferred because it arrived
+ * while the GPU was not at full power.
+ *
+ * The SBIOS may send D-Notifier events on system resume before RM has
+ * resumed the GPU. Those are rejected with NV_ERR_GPU_NOT_FULL_POWER and,
+ * if the SBIOS does not implement PFM_REQ_HNDLR_FUNC_REQUESTDXSTATE, never
+ * re-sent. The saved value comes from the original SBIOS event, not a chosen
+ * performance level. Caller must hold the API and GPU locks.
+ *
+ * @param[in]   pNv   nv_state_t pointer.
+ */
+void RmApplyPendingDNotifierState(
+    nv_state_t *pNv
+)
+{
+    nv_priv_t *nvp = NV_GET_NV_PRIV(pNv);
+    NV2080_CTRL_PERF_SET_AUX_POWER_STATE_PARAMS params = { 0 };
+    RM_API    *pRmApi = rmapiGetInterface(RMAPI_GPU_LOCK_INTERNAL);
+    NV_STATUS  status;
+
+    if (!nvp->pm_state.DNotifierPending)
+    {
+        return;
+    }
+
+    params.powerState = nvp->pm_state.DNotifierAuxPowerState;
+
+    status = pRmApi->Control(pRmApi, pNv->rmapi.hClient,
+                             pNv->rmapi.hSubDevice,
+                             NV2080_CTRL_CMD_PERF_SET_AUX_POWER_STATE,
+                             &params, sizeof(params));
+
+    // Keep a retryable request for a later successful system resume. Clear it
+    // only once accepted or after a non-retryable error. There is no retry loop.
+    nvp->pm_state.DNotifierPending = (status == NV_ERR_GPU_NOT_FULL_POWER);
+    if (status == NV_OK)
+    {
+        NV_PRINTF(LEVEL_INFO,
+                  "%s: Applied deferred SBIOS auxiliary power state %u\n",
+                  __FUNCTION__, params.powerState);
+    }
+    else if (status == NV_ERR_GPU_NOT_FULL_POWER)
+    {
+        NV_PRINTF(LEVEL_INFO,
+                  "%s: Deferred SBIOS auxiliary power state %u still pending\n",
+                  __FUNCTION__, params.powerState);
+    }
+    else
+    {
+        NV_PRINTF(LEVEL_ERROR,
+                  "%s: Failed to apply deferred D-Notifier event, status=0x%x\n",
+                  __FUNCTION__, status);
+    }
+}
+
+/*!
  * @brief Deal with D-notifier events to apply a performance
  * level based on the requested auxiliary power-state.
  * Read confluence page "D-Notifiers on Linux" for more details.
@@ -1394,6 +1450,7 @@
 )
 {
     NV2080_CTRL_PERF_SET_AUX_POWER_STATE_PARAMS params = { 0 };
+    nv_priv_t         *nvp = NV_GET_NV_PRIV(pNv);
     RM_API            *pRmApi;
     THREAD_STATE_NODE  threadState;
     NV_STATUS          rmStatus = NV_OK;
@@ -1430,9 +1487,23 @@
                                NV2080_CTRL_CMD_PERF_SET_AUX_POWER_STATE,
                                &params, sizeof(params));
 
+    //
+    // Remember a request the GPU could not take yet (e.g. sent by the SBIOS
+    // during system resume) so RmApplyPendingDNotifierState() can apply it.
+    // Any newer event replaces it.
+    //
+    nvp->pm_state.DNotifierPending = (rmStatus == NV_ERR_GPU_NOT_FULL_POWER);
+    nvp->pm_state.DNotifierAuxPowerState = params.powerState;
+
     RmUnixRmApiEpilogue(pNv, &threadState);
 
-    if (rmStatus != NV_OK)
+    if (rmStatus == NV_ERR_GPU_NOT_FULL_POWER)
+    {
+        NV_PRINTF(LEVEL_INFO,
+                  "%s: GPU not at full power, deferring ACPI D-Notifier event 0x%x (auxiliary state %u)\n",
+                  __FUNCTION__, event_type, params.powerState);
+    }
+    else if (rmStatus != NV_OK)
     {
         NV_PRINTF(LEVEL_ERROR,
                   "%s: Failed to handle ACPI D-Notifier event, status=0x%x\n",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants