mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lyude Paul <lyude.paul@maintainer.cc>
To: Munique Feitoza <muniquefeitoz4@gmail.com>,
	Danilo Krummrich <dakr@kernel.org>
Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/nouveau/dispnv50: use exponential backoff when polling display notifiers
Date: Fri, 04 Dec 2026 16:41:42 -0500	[thread overview]
Message-ID: <e2b54c629b13d179d7ebd60a9ec5d324f052ebd7.camel@maintainer.cc> (raw)
In-Reply-To: <20261201194223.3802-1-muniquefeitoz4@gmail.com>

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@gmail.com>
> ---
>  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;
>  }
>  

      reply	other threads:[~2026-12-04 21:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:42 Munique Feitoza
2026-12-04 21:41 ` Lyude Paul [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2b54c629b13d179d7ebd60a9ec5d324f052ebd7.camel@maintainer.cc \
    --to=lyude.paul@maintainer.cc \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muniquefeitoz4@gmail.com \
    --cc=nouveau@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®