All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpu: nova-core: gsp: cmdq: do not sleep in wait_for_msg
@ 2026-10-30  3:21 Alexandre Courbot
  2026-10-30  4:32 ` Eliot Courtney
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Courbot @ 2026-10-30  3:21 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, linux-kernel, rust-for-linux,
	Alexandre Courbot

If a message is not immediately available on the queue, `wait_for_msg`
sleeps for 1 millisecond before checking again. This is 3 orders of
magnitude more than Nouveau (which sleeps for 1 microsecond) or OpenRM
(which does not sleep at all and busy-polls) and is way too much, as GSP
commands are expected to be processed much faster than that.

Set the sleep time to `Delta::ZERO` to mirror OpenRM's behavior. This
makes the CPU busy-loop with a call to `cpu_relax` at each iteration,
keeping latency to a minimum.

Slightly higher values like 2us were also considered, but with such low
values `fsleep` also busy-waits, and would thus only add latency for no
benefit.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index e6d9a97130ea..d8c00df012bf 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -590,9 +590,8 @@ fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result {
     fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
         // Wait for a message to arrive from the GSP.
         let (slice_1, slice_2) = if timeout == Delta::ZERO {
-            // If `timeout == Delta::ZERO`, check the message queue once as `read_poll_timeout` can
-            // potentially sleep if the clock hasn't moved forward while the condition was being
-            // checked.
+            // If `timeout == Delta::ZERO`, check the message queue exactly once instead of calling
+            // `read_poll_timeout`, which would keep polling until the clock moves forward.
             let slices = self.gsp_mem.driver_read_area();
             if !slices.0.is_empty() {
                 Ok(slices)
@@ -603,7 +602,7 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
             read_poll_timeout(
                 || Ok(self.gsp_mem.driver_read_area()),
                 |driver_area| !driver_area.0.is_empty(),
-                Delta::from_millis(1),
+                Delta::ZERO,
                 timeout,
             )
         }

---
base-commit: 9b840ed71d34ff545e3ada8be2ad5daaae542b50
change-id: 20261030-cmdq_wait_msg_timeout-26df11234d10

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpu: nova-core: gsp: cmdq: do not sleep in wait_for_msg
  2026-10-30  3:21 [PATCH] gpu: nova-core: gsp: cmdq: do not sleep in wait_for_msg Alexandre Courbot
@ 2026-10-30  4:32 ` Eliot Courtney
  2026-10-30  5:21   ` Alexandre Courbot
  0 siblings, 1 reply; 3+ messages in thread
From: Eliot Courtney @ 2026-10-30  4:32 UTC (permalink / raw)
  To: Alexandre Courbot, Danilo Krummrich, Alice Ryhl, David Airlie,
	Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, linux-kernel, rust-for-linux

On Fri Oct 30, 2026 at 12:21 PM JST, Alexandre Courbot wrote:
> If a message is not immediately available on the queue, `wait_for_msg`
> sleeps for 1 millisecond before checking again. This is 3 orders of
> magnitude more than Nouveau (which sleeps for 1 microsecond) or OpenRM
> (which does not sleep at all and busy-polls) and is way too much, as GSP
> commands are expected to be processed much faster than that.
>
> Set the sleep time to `Delta::ZERO` to mirror OpenRM's behavior. This
> makes the CPU busy-loop with a call to `cpu_relax` at each iteration,
> keeping latency to a minimum.
>
> Slightly higher values like 2us were also considered, but with such low
> values `fsleep` also busy-waits, and would thus only add latency for no
> benefit.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/gpu/nova-core/gsp/cmdq.rs | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
> index e6d9a97130ea..d8c00df012bf 100644
> --- a/drivers/gpu/nova-core/gsp/cmdq.rs
> +++ b/drivers/gpu/nova-core/gsp/cmdq.rs
> @@ -590,9 +590,8 @@ fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result {
>      fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
>          // Wait for a message to arrive from the GSP.
>          let (slice_1, slice_2) = if timeout == Delta::ZERO {
> -            // If `timeout == Delta::ZERO`, check the message queue once as `read_poll_timeout` can
> -            // potentially sleep if the clock hasn't moved forward while the condition was being
> -            // checked.
> +            // If `timeout == Delta::ZERO`, check the message queue exactly once instead of calling
> +            // `read_poll_timeout`, which would keep polling until the clock moves forward.
>              let slices = self.gsp_mem.driver_read_area();
>              if !slices.0.is_empty() {
>                  Ok(slices)
> @@ -603,7 +602,7 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
>              read_poll_timeout(
>                  || Ok(self.gsp_mem.driver_read_area()),
>                  |driver_area| !driver_area.0.is_empty(),
> -                Delta::from_millis(1),
> +                Delta::ZERO,
>                  timeout,
>              )
>          }
>
> ---
> base-commit: 9b840ed71d34ff545e3ada8be2ad5daaae542b50
> change-id: 20261030-cmdq_wait_msg_timeout-26df11234d10
>
> Best regards,
> --  
> Alexandre Courbot <acourbot@nvidia.com>

Previously we had a discussion about Delta::ZERO waits [1] and Danilo
had some concerns about creating unnecessary contention by reading
coherent memory extremely often. Also, AFAICT `fsleep`'s busy wait is a
bit nicer than just spinning. WDYT? I think switching this to
Delta::from_micros(1) is probably better.

[1]: https://lore.kernel.org/all/DGTYVZMRVLLE.3HQVL7ZT6MU7H@kernel.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpu: nova-core: gsp: cmdq: do not sleep in wait_for_msg
  2026-10-30  4:32 ` Eliot Courtney
@ 2026-10-30  5:21   ` Alexandre Courbot
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Courbot @ 2026-10-30  5:21 UTC (permalink / raw)
  To: Eliot Courtney
  Cc: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
	John Hubbard, Alistair Popple, Timur Tabi, Zhi Wang, nova-gpu,
	linux-kernel, rust-for-linux

On Fri Oct 30, 2026 at 1:32 PM JST, Eliot Courtney wrote:
> On Fri Oct 30, 2026 at 12:21 PM JST, Alexandre Courbot wrote:
>> If a message is not immediately available on the queue, `wait_for_msg`
>> sleeps for 1 millisecond before checking again. This is 3 orders of
>> magnitude more than Nouveau (which sleeps for 1 microsecond) or OpenRM
>> (which does not sleep at all and busy-polls) and is way too much, as GSP
>> commands are expected to be processed much faster than that.
>>
>> Set the sleep time to `Delta::ZERO` to mirror OpenRM's behavior. This
>> makes the CPU busy-loop with a call to `cpu_relax` at each iteration,
>> keeping latency to a minimum.
>>
>> Slightly higher values like 2us were also considered, but with such low
>> values `fsleep` also busy-waits, and would thus only add latency for no
>> benefit.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> ---
>>  drivers/gpu/nova-core/gsp/cmdq.rs | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
>> index e6d9a97130ea..d8c00df012bf 100644
>> --- a/drivers/gpu/nova-core/gsp/cmdq.rs
>> +++ b/drivers/gpu/nova-core/gsp/cmdq.rs
>> @@ -590,9 +590,8 @@ fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result {
>>      fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
>>          // Wait for a message to arrive from the GSP.
>>          let (slice_1, slice_2) = if timeout == Delta::ZERO {
>> -            // If `timeout == Delta::ZERO`, check the message queue once as `read_poll_timeout` can
>> -            // potentially sleep if the clock hasn't moved forward while the condition was being
>> -            // checked.
>> +            // If `timeout == Delta::ZERO`, check the message queue exactly once instead of calling
>> +            // `read_poll_timeout`, which would keep polling until the clock moves forward.
>>              let slices = self.gsp_mem.driver_read_area();
>>              if !slices.0.is_empty() {
>>                  Ok(slices)
>> @@ -603,7 +602,7 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
>>              read_poll_timeout(
>>                  || Ok(self.gsp_mem.driver_read_area()),
>>                  |driver_area| !driver_area.0.is_empty(),
>> -                Delta::from_millis(1),
>> +                Delta::ZERO,
>>                  timeout,
>>              )
>>          }
>>
>> ---
>> base-commit: 9b840ed71d34ff545e3ada8be2ad5daaae542b50
>> change-id: 20261030-cmdq_wait_msg_timeout-26df11234d10
>>
>> Best regards,
>> --  
>> Alexandre Courbot <acourbot@nvidia.com>
>
> Previously we had a discussion about Delta::ZERO waits [1] and Danilo
> had some concerns about creating unnecessary contention by reading
> coherent memory extremely often. Also, AFAICT `fsleep`'s busy wait is a
> bit nicer than just spinning. WDYT? I think switching this to
> Delta::from_micros(1) is probably better.

Anything works for me as long as we reduce the spinning-induced latency
to something reasonable. I'll resping with `from_micros(1)`.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-30  5:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30  3:21 [PATCH] gpu: nova-core: gsp: cmdq: do not sleep in wait_for_msg Alexandre Courbot
2026-10-30  4:32 ` Eliot Courtney
2026-10-30  5:21   ` Alexandre Courbot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.