Re: [PATCH] drm/nouveau/dispnv50: use exponential backoff when polling display notifiers

From: Lyude Paul

Date: Fri Dec 04 2026 - 16:41:53 EST


JFYI - it's been delayed quite a bit because I've been busy working on
nova and rust KMS, but we actually do have a plan for fixing this issue
which involves actually adding proper support for awaken interrupts
which removes the need for busy-waiting entirely. I already have
patches written up for this, there's just a few kinks around GSP I need
to workout before getting it upstream.

So NAK on this for the time being.

On Tue, 2026-12-01 at 16:42 -0300, Munique Feitoza wrote:
> The dispnv50 notifier wait helpers (base507c_ntfy_wait_begun(),
> core507d_ntfy_wait_done(), corec37d_ntfy_wait_done(),
> ovly827e_ntfy_wait_begun(), and the core507d/core907d caps_init
> waits)
> poll in a nvif_msec(..., 2000ULL, ...) loop using a fixed
> usleep_range(1, 2).
>
> Because display flip/update notifiers can take milliseconds (up to a
> full
> vblank interval), waking every 1-2 us causes excessive hrtimer churn,
> context switches, and repeated nvif_device_time() ->
> nvkm_udevice_mthd()
> -> nv04_timer_read() PCIe MMIO reads on pre-Volta GPUs.
>
> Introduce nv50_disp_ntfy_wait() in disp.h using exponential backoff
> starting at 10 us and doubling up to 500 us. The fast path (notifier
> already signaled on the first check) remains unchanged with zero
> sleeps.
>
> Measured on an AMD Ryzen 5 5500 + NVIDIA GeForce GT 730 (GF108)
> running
> v7.4.0-rc1 with clocksource=tsc during 10s of 'vblank_mode=0 glmark2'
> (perf record -F 999 -a -g; perf stat -e cycles,context-
> switches,timer:hrtimer_start):
>
>   Metric                         Before          After
>   nv50_disp_atomic_commit_tail   35.02%          1.50%
>   base507c_ntfy_wait_begun       31.62%          0.66%
>   nvkm_udevice_mthd               2.46%          0.04%
>   Total CPU cycles (10s)         27,233,642,404  13,252,205,119 (-
> 51.3%)
>   context-switches (10s)         895,686         138,650        (-
> 84.5%)
>   timer:hrtimer_start (10s)      504,206         129,581        (-
> 74.3%)
>
> Signed-off-by: Munique Feitoza <muniquefeitoz4@xxxxxxxxx>
> ---
>  drivers/gpu/drm/nouveau/dispnv50/base507c.c |  7 ++-----
>  drivers/gpu/drm/nouveau/dispnv50/core507d.c | 16 +++++-----------
>  drivers/gpu/drm/nouveau/dispnv50/core907d.c |  9 +++------
>  drivers/gpu/drm/nouveau/dispnv50/corec37d.c |  7 ++-----
>  drivers/gpu/drm/nouveau/dispnv50/disp.h     | 19 +++++++++++++++++++
>  drivers/gpu/drm/nouveau/dispnv50/ovly827e.c |  7 ++-----
>  6 files changed, 33 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/base507c.c
> b/drivers/gpu/drm/nouveau/dispnv50/base507c.c
> index 41b648ab3c5e57..2f7ac655db898d 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/base507c.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/base507c.c
> @@ -147,11 +147,8 @@ int
>  base507c_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
>   struct nvif_device *device)
>  {
> - s64 time = nvif_msec(device, 2000ULL,
> - if (NVBO_TD32(bo, offset, NV_DISP_BASE_NOTIFIER_1,
> _0, STATUS, ==, BEGUN))
> - break;
> - usleep_range(1, 2);
> - );
> + s64 time = nv50_disp_ntfy_wait(device,
> + NVBO_TD32(bo, offset, NV_DISP_BASE_NOTIFIER_1, _0,
> STATUS, ==, BEGUN));
>   return time < 0 ? time : 0;
>  }
>  
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/core507d.c
> b/drivers/gpu/drm/nouveau/dispnv50/core507d.c
> index 46c94548052259..afd6fb87eeb5cb 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/core507d.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/core507d.c
> @@ -62,11 +62,8 @@ int
>  core507d_ntfy_wait_done(struct nouveau_bo *bo, u32 offset,
>   struct nvif_device *device)
>  {
> - s64 time = nvif_msec(device, 2000ULL,
> - if (NVBO_TD32(bo, offset, NV_DISP_CORE_NOTIFIER_1,
> COMPLETION_0, DONE, ==, TRUE))
> - break;
> - usleep_range(1, 2);
> - );
> + s64 time = nv50_disp_ntfy_wait(device,
> + NVBO_TD32(bo, offset, NV_DISP_CORE_NOTIFIER_1,
> COMPLETION_0, DONE, ==, TRUE));
>   return time < 0 ? time : 0;
>  }
>  
> @@ -115,12 +112,9 @@ core507d_caps_init(struct nouveau_drm *drm,
> struct nv50_disp *disp)
>   if (ret < 0)
>   return ret;
>  
> - time = nvif_msec(core->chan.base.device, 2000ULL,
> - if (NVBO_TD32(bo, NV50_DISP_CORE_NTFY,
> -        NV_DISP_CORE_NOTIFIER_1,
> CAPABILITIES_1, DONE, ==, TRUE))
> - break;
> - usleep_range(1, 2);
> - );
> + time = nv50_disp_ntfy_wait(core->chan.base.device,
> + NVBO_TD32(bo, NV50_DISP_CORE_NTFY,
> +   NV_DISP_CORE_NOTIFIER_1, CAPABILITIES_1,
> DONE, ==, TRUE));
>   if (time < 0)
>   NV_ERROR(drm, "core caps notifier timeout\n");
>  
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/core907d.c
> b/drivers/gpu/drm/nouveau/dispnv50/core907d.c
> index 8564d4dffaff0a..ca5f9692ef9df6 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/core907d.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/core907d.c
> @@ -44,12 +44,9 @@ core907d_caps_init(struct nouveau_drm *drm, struct
> nv50_disp *disp)
>   if (ret < 0)
>   return ret;
>  
> - time = nvif_msec(core->chan.base.device, 2000ULL,
> - if (NVBO_TD32(bo, NV50_DISP_CORE_NTFY,
> -        NV907D_CORE_NOTIFIER_3,
> CAPABILITIES_4, DONE, ==, TRUE))
> - break;
> - usleep_range(1, 2);
> - );
> + time = nv50_disp_ntfy_wait(core->chan.base.device,
> + NVBO_TD32(bo, NV50_DISP_CORE_NTFY,
> +   NV907D_CORE_NOTIFIER_3, CAPABILITIES_4,
> DONE, ==, TRUE));
>   if (time < 0)
>   NV_ERROR(drm, "core caps notifier timeout\n");
>  
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/corec37d.c
> b/drivers/gpu/drm/nouveau/dispnv50/corec37d.c
> index 83eec2f091f02e..ccf3e441ee8dca 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/corec37d.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/corec37d.c
> @@ -82,11 +82,8 @@ int
>  corec37d_ntfy_wait_done(struct nouveau_bo *bo, u32 offset,
>   struct nvif_device *device)
>  {
> - s64 time = nvif_msec(device, 2000ULL,
> - if (NVBO_TD32(bo, offset, NV_DISP_NOTIFIER, _0,
> STATUS, ==, FINISHED))
> - break;
> - usleep_range(1, 2);
> - );
> + s64 time = nv50_disp_ntfy_wait(device,
> + NVBO_TD32(bo, offset, NV_DISP_NOTIFIER, _0, STATUS,
> ==, FINISHED));
>   return time < 0 ? time : 0;
>  }
>  
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.h
> b/drivers/gpu/drm/nouveau/dispnv50/disp.h
> index 5d998f0319dcc2..b98e183d4e12a8 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/disp.h
> +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.h
> @@ -1,8 +1,11 @@
>  #ifndef __NV50_KMS_H__
>  #define __NV50_KMS_H__
> +#include <linux/delay.h>
> +#include <linux/minmax.h>
>  #include <linux/workqueue.h>
>  #include <nvif/mem.h>
>  #include <nvif/push.h>
> +#include <nvif/timer.h>
>  
>  #include "nouveau_display.h"
>  
> @@ -105,4 +108,20 @@ extern const u64 disp50xx_modifiers[];
>  extern const u64 disp90xx_modifiers[];
>  extern const u64 wndwc57e_modifiers[];
>  extern const u64 wndwca7e_modifiers[];
> +
> +/*
> + * Display notifiers (flip/update completion) can take up to a full
> frame
> + * (~16 ms) to signal. Back off the sleep interval exponentially
> instead of
> + * polling every 1-2 us, avoiding excessive hrtimer churn and PTIMER
> MMIO
> + * reads on pre-Volta GPUs.
> + */
> +#define nv50_disp_ntfy_wait(device, cond)
> ({ \
> + unsigned long _delay_us =
> 10; \
> + nvif_msec((device),
> 2000ULL, \
> + if
> (cond) \
> + break;
> \
> + usleep_range(_delay_us, _delay_us *
> 2); \
> + _delay_us = min(_delay_us * 2,
> 500UL); \
> + );
> \
> +})
>  #endif
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/ovly827e.c
> b/drivers/gpu/drm/nouveau/dispnv50/ovly827e.c
> index a5ae22ed663d7d..06d6a74b0e3cbb 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/ovly827e.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/ovly827e.c
> @@ -69,11 +69,8 @@ int
>  ovly827e_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
>   struct nvif_device *device)
>  {
> - s64 time = nvif_msec(device, 2000ULL,
> - if (NVBO_TD32(bo, offset, NV_DISP_NOTIFICATION_1,
> _3, STATUS, ==, BEGUN))
> - break;
> - usleep_range(1, 2);
> - );
> + s64 time = nv50_disp_ntfy_wait(device,
> + NVBO_TD32(bo, offset, NV_DISP_NOTIFICATION_1, _3,
> STATUS, ==, BEGUN));
>   return time < 0 ? time : 0;
>  }
>