Skip to content

nvidia: defer NVPCF notifications until runtime resume - #1299

Open
lars76 wants to merge 2 commits into
NVIDIA:mainfrom
lars76:fix-nvpcf-defer-v2
Open

lars76 wants to merge 2 commits into
NVIDIA:mainfrom
lars76:fix-nvpcf-defer-v2

Conversation

@lars76

@lars76 lars76 commented Aug 16, 2026 •

Copy link
Copy Markdown

TL;DR

On hybrid laptops, the NVIDIA GPU is powered down while idle. However, the firmware can still send NVPCF notifications:

  • once per 1% of battery discharge on the tested laptop;
  • after a platform-profile change, such as:
sudo sh -c 'echo balanced > /sys/firmware/acpi/platform_profile'
  1. The current driver wakes the NVIDIA GPU for approximately 20–22 seconds just to deliver each notification.
  2. This patch remembers that the power policy changed without waking the GPU. If more notifications arrive, one reminder is enough because the latest policy will be read later.
  3. When the GPU next wakes for actual use, the saved notification is delivered and nvidia-powerd reads the latest power limits.

Projected onto typical one-hour scenarios (derived from the measured per-wake cost, not from separate runtime A/B tests):

Scenario (1 h on battery) Stock driver With this patch
Light use, screen off 93% 94%
Browsing / light work 90% 92%
Video playback 78% 82%
Heavier work 70% 75%

Roughly 20% longer projected battery runtime during normal iGPU-only use.

Problem

On an ASUS GA403UI with an RTX 4070 Laptop GPU, the EC sends Notify(NPCF, 0xC0) for every 1% of battery discharge.

rm_acpi_nvpcf_notify() takes a dynamic-power reference for every notification, waking the GPU even when it is already runtime-suspended.

Each wake keeps the GPU in D0 for approximately 20–22 seconds while the deferred-idle checks complete.

Measured with driver 610.57.04 and Linux 7.1.6:

  • 12 notification-induced wakes during a 90-minute discharge;
  • 5.65% dGPU D0 duty while otherwise idle;
  • 110.4 ± 19.1 mWh consumed per wake;
  • approximately 1.1 W of average overhead in the measured discharge arm.

See also: #860 (same root cause), #905 (NVPCF subset), #1201 (same symptom on two other Zephyrus laptops).

Why the notification must not be dropped

The notification contains no policy data. It tells subscribers such as nvidia-powerd to retrieve the latest policy from the NVPCF _DSM.

With notifications discarded while the GPU was suspended, nvidia-powerd was not told to retrieve a changed profile. After the GPU resumed, it continued using the old 75/55 W limits instead of the new 90/65 W limits. The limits remained stale until another notification arrived.

This is an alternative to the NVPCF portion of #1181. Both approaches prevent the notification-induced wake, but this change preserves delivery of the notification after the GPU resumes.

Scope

This change handles NVPCF only.

A platform-profile change also updates the GPU's temperature target, and the firmware announces that with a second, independent notification on the GPU's ACPI device (ACPI_NOTIFY_GPS_STATUS_CHANGE, handled by RmHandleGPSStatusChange()).

Unlike NVPCF, that notification is consumed by the driver itself rather than by nvidia-powerd, and nothing re-reads the value later if it is missed.

This patch leaves it untouched, so on the tested laptop a profile change still wakes the GPU once. Since it only fires on user actions, the cost is negligible.

#1181 suppresses this notification as well.

How to test (Arch Linux)

git clone --depth 1 --branch fix-nvpcf-defer-v2 https://github.com/lars76/open-gpu-kernel-modules.git
cd open-gpu-kernel-modules
make modules -j$(nproc)
sudo install -Dm644 kernel-open/*.ko -t "/usr/lib/modules/$(uname -r)/updates/nvidia/"
sudo depmod
sudo mkinitcpio -P
reboot

After reboot, verify the patched modules are actually running:

modinfo -F filename nvidia            # expect .../updates/nvidia/nvidia.ko
cat /sys/module/nvidia/srcversion     # must match:
modinfo kernel-open/nvidia.ko | grep srcversion

Then test on battery: unplug at 98% or lower (at 99–100% the battery gauge stalls and the notification does not fire), wait a minute for the unplug wake to settle, and watch

cat /sys/bus/pci/drivers/nvidia/*/power/runtime_active_time

across 2–3% of discharge. Patched: the value stays flat. Stock: it grows by roughly 20,000 ms per 1%. Do not run nvidia-smi or lspci during the window, as both wake the GPU themselves.

Uninstall:

sudo rm -r "/usr/lib/modules/$(uname -r)/updates/nvidia"
sudo depmod && sudo mkinitcpio -P

@gprieto

gprieto commented Aug 30, 2026 •

Copy link
Copy Markdown

Tried this on my GA403UV on 7.1.9-arch1-2, and there are no more power draw spikes every 4-5 minutes. But manually changing the platform-profile still triggers a power draw spike, even in Integrated mode.

@gprieto

gprieto commented Aug 30, 2026

Copy link
Copy Markdown

Sorry, I just read the

A platform-profile change also updates the GPU's temperature target, and the firmware announces that with a second, independent notification on the GPU's ACPI device (ACPI_NOTIFY_GPS_STATUS_CHANGE, handled by RmHandleGPSStatusChange()).

Unlike NVPCF, that notification is consumed by the driver itself rather than by nvidia-powerd, and nothing re-reads the value later if it is missed.

This patch leaves it untouched, so on the tested laptop a profile change still wakes the GPU once. Since it only fires on user actions, the cost is negligible.

It makes sense to me to also defer that notification, as it is not needed while the GPU is powered down.

@lcrdl

lcrdl commented Sep 24, 2026 •

Copy link
Copy Markdown

I tested around it on the same model family (GA403UV, RTX 4060 Laptop, driver 615.71.09, Linux 7.2.6) and found a similar issue that I don't think are covered by this PR nor #1181 covers. This time it happens on AC, and much more often than the battery-tick case.

Essentially, the dGPU moves from D3cold to D0 roughly every 30 s. It stays in D0 for ~25 s and only reaches D3cold for 1–6 s before being woken again.

From what I saw, the wake-up is due to Notify(PEGP, 0xD1/0xD2/0xD3) to the GPU's ACPI device: 43 notifies in 60 s in my case. All notifications have stopped once battery has reached its charge limit.

@sergihrs

Copy link
Copy Markdown

Tested c70c661 + 555c98d on an ASUS ROG Zephyrus G16 GU605CP (RTX 5070 Laptop GB206 10de:2d58, Core Ultra 9 285H), nvidia-open 610.57.04 patched via DKMS, kernel 7.2.5.
Stock: 22/22 battery-% drops woke the dGPU for ~24 s each (~90 mWh per wake, about 11 % of battery energy).
Patched: 4/4 drops with the dGPU staying in D3 (runtime_active_time +0 ms over 14 min on battery). nvidia-powerd still sets 110 W on AC; no NVRM errors.

@OmerFarukOruc

Copy link
Copy Markdown

Tested c70c661 + 555c98d on an ASUS ROG Zephyrus G16 GA605WI (Ryzen AI 9 HX 370 / Radeon 890M, RTX 4070 Laptop 10de:2860), BIOS GA605WI.316, nvidia-open 615.78.08 (both commits apply cleanly), kernel 7.2.8, NixOS, NVreg_DynamicPowerManagement=0x02. Same trigger as the ProArt report in #1300: EC query _QB6 calls STPL() and notifies NPCF on every 1 % battery drop.

Idle on battery, Plasma Wayland, polling power/runtime_status once a second without running nvidia-smi:

battery drops wakes on a drop
stock 615.78.08 4 (100 to 96 %) 4, each resumed within 1 s and active 20 to 22 s
with this PR 4 (100 to 96 %) 0

The patched run still had two wakes of about 21 s, one when unplugging the charger and one when the platform profile changed, both expected per the PR description. Between them the GPU stayed runtime-suspended; 1455 s suspended vs 44 s active over the 25-minute run. No driver errors in the kernel log after boot.

@rdoupe

rdoupe commented Oct 16, 2026

Copy link
Copy Markdown

Tested c70c661 + 555c98d on an ASUS ROG Zephyrus G16 GA605KM (Ryzen AI 7 350, RTX 5060 Laptop GPU 10de:2d59), BIOS GA605KM.307, nvidia-open 610.57.04 patched through DKMS (only this PR), kernel 7.2.5 (Arch-based), NVreg_DynamicPowerManagement left at its default. The patched module was the one loaded: /sys/module/nvidia/srcversion matched the DKMS build in updates/dkms/.

Same trigger as the GU605CP and GA605WI reports and #1300. On every 1 % battery drop the EC runs query 0x3F and then 0xB6. In this DSDT, _QB6 calls STPL(), which does Notify(NPCF, 0xC2) and Notify(NPCF, 0xC0).

Battery, idle desktop, no nvidia-smi/lspci while measuring:

battery drops dGPU woken by a drop
stock 610.57.04, EC dynamic debug on (ec.c) 13 13. Each Query(0xb6) started was followed 0.94-0.95 s later by nvidia 0000:64:00.0: Enabling HDA controller (runtime resume)
stock 610.57.04, power/runtime_status sampled every 5 s 2 2, each active for about 20-25 s. Battery-reported draw went from 9-10 W to 15-16.7 W during each wake
with this PR, power/runtime_status sampled every 5 s 3 (42 to 39 %, 15 min) 0. suspended in 179/179 samples, and no Enabling HDA controller in the kernel log during the run

No NVRM errors or assertions in the kernel log of the patched boot (about 16 h of uptime so far).

Not tested here: whether nvidia-powerd picks up the deferred notification after the next resume. On battery this firmware disables the DC Dynamic Boost controller anyway (Client (presumably SBIOS) has requested to disable Dynamic Boost DC controller). On AC the GPU is kept awake on this machine, so the deferral path is not used there. Also not tested: the platform-profile-change notification.

Logs were collected and summarised with help from an LLM assistant; every number comes from the kernel log and sysfs samples described above.

@ojura

ojura commented Nov 1, 2026

Copy link
Copy Markdown

This PR fixes the repeated GPU wakeups on my Legion 7 16IRX9 in Balanced mode on AC. The new RmDeferNvpcfNotifyIfIdle() helper can also crash if the driver fails to create the power-management mutex. A mode check before locking would fix that.

Test results

On this laptop, the firmware repeatedly reports the same power limits in the balanced platform profile on AC. The EC raises query 0x48 about every seven seconds, and _Q48 in SSDT4 calls Notify (\_SB.NPCF, 0xC0).

I tested PR commit 555c98d1 on an RTX 4070 Laptop GPU, BIOS NSCN41WW, Ubuntu 24.04, with NVreg_DynamicPowerManagement=0x02. For each patched run, I built the driver core from the matching NVIDIA tag for Ubuntu's nvidia-dkms-595-open 595.99.02 or nvidia-dkms-615-open 615.71.09.

The three 60-second runs recorded function-graph durations for nv_acpi_nvpcf_event, the EC's Query(0x48) debug messages and power/runtime_status:

  • Stock 595.91.07, kernel 7.0.0-34-generic: eight notifications. Two handler calls took 2.0 and 2.1 seconds. The GPU suspended twice, for about 0.8 seconds each time.
  • 595.99.02 with the PR alone, kernel 7.0.0-38-generic: nine notifications taking 10.6 to 41.4 µs. After entering suspend, the GPU stayed suspended through five further 0x48 queries.
  • 615.71.09 with the PR and the guard below, kernel 7.0.0-38-generic: nine notifications taking 10.4 to 29.2 µs. After entering suspend, the GPU stayed suspended through four further 0x48 queries.

Stock 595.99.02 also reproduced the wakeups. I counted four 0x48 queries in a separate 30-second check. With LACT's GPU monitoring service (lactd) stopped, a 40-second poll of power/runtime_status recorded two suspensions, each followed by a resume.

Mutex check

If portSyncMutexCreate() fails, rm_init_dynamic_power_management() disables power management by setting the mode to NV_DYNAMIC_PM_NEVER and leaves dynamic_power.mutex NULL.

Both os_ref_dynamic_power() and os_unref_dynamic_power() return before locking in that mode. The new helper instead passes the NULL mutex to portSyncMutexAcquire().

Adding the same mode check avoids that call and keeps the existing notification path in coarse and disabled modes. This diff is against 595.99.02 with the PR applied; it also applies after the PR on 610.57.04, 615.71.09 and 615.78.08.

--- a/src/nvidia/arch/nvalloc/unix/src/dynamic-power.c
+++ b/src/nvidia/arch/nvalloc/unix/src/dynamic-power.c
@@ -1532,7 +1532,14 @@ NvBool RmDeferNvpcfNotifyIfIdle(
     nv_priv_t *nvp = NV_GET_NV_PRIV(nv);
     NvBool bDefer;
 
-    if (nvp == NULL)
+    /*
+     * Defer only when os_ref_dynamic_power(nv, NV_DYNAMIC_PM_FINE) would
+     * take the mutex and could resume the GPU. In coarse mode it does
+     * neither. In NV_DYNAMIC_PM_NEVER mode the mutex can be NULL, because
+     * rm_init_dynamic_power_management() selects that mode when it fails
+     * to create the mutex.
+     */
+    if ((nvp == NULL) || (NV_DYNAMIC_PM_FINE > nvp->dynamic_power.mode))
     {
         return NV_FALSE;
     }

@aritger

aritger commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the proposed fix. We have a solution incorporated in the driver and will be included in a future release. You can reference NVIDIA internal bug number 4084236.

@mhadidg

mhadidg commented Nov 15, 2026 •

Copy link
Copy Markdown

Same problem here on a Lenovo Legion Pro; only happens in the balanced profile.

System

  • Lenovo 83DE (Legion Pro), BIOS N2CN28WW,
  • Ubuntu, kernel 7.0.0-43-generic, driver 595.99.02 (open modules)

What I see

In balanced, the dGPU wakes from D3cold about every 2 min, stays on for ~20 s, then suspends again. Each wake comes ~1 s after EC query 0xA0:

01:25:51 ACPI: EC: Query(0xa0) started
01:25:52 dGPU resuming
01:27:50 ACPI: EC: Query(0xa0) started
01:27:51 dGPU resuming

bpftrace on __pm_runtime_resume shows the same path as in this PR:

kworker/16:1
  __pm_runtime_resume
  nv_indicate_not_idle
  os_ref_dynamic_power
  rm_acpi_nvpcf_notify
  nv_acpi_nvpcf_event
  acpi_ev_notify_dispatch
  acpi_os_execute_deferred

Profile test

After switching to performance, there were no more wakes. So the 0xA0 timer seems to run only in balanced.

@ffrangit

Copy link
Copy Markdown

Hi everyone,

I just wanted to add my voice in support of this PR. I'm running Arch Linux on an ASUS TUF Gaming A15 (FA506NCG) with an RTX 3050 Laptop GPU and a Radeon iGPU.

I was able to confirm this exact issue using bpftrace. The stack trace clearly shows the firmware sending NVPCF ACPI notifications and the driver waking up the dGPU (rm_acpi_nvpcf_notify -> os_ref_dynamic_power -> pci_device_shutdown) immediately after it tries to suspend, causing endless wake/sleep loops and battery drain when idle.

The detailed analysis and measurements in this PR are spot on. I would love to see this merged upstream so we don't have to rely on manual kernel module patching.

Thank you for the excellent work on this fix!

+1 for merging.

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.

10 participants