public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Eliot Courtney" <ecourtney@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	Björn Roy Baron <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>
Cc: "Zhi Wang" <zhiw@nvidia.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, <nouveau@lists.freedesktop.org>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
	<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v4 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue
Date: Mon, 02 Mar 2026 14:18:44 +0000	[thread overview]
Message-ID: <DGSD13LEUEZK.DXHNXLIRVY24@garyguo.net> (raw)
In-Reply-To: <20260302-cmdq-continuation-v4-2-c011f15aad58@nvidia.com>

On Mon Mar 2, 2026 at 11:42 AM GMT, Eliot Courtney wrote:
> Add a timeout to `allocate_command` which waits for space on the GSP
> command queue. It uses a similar timeout to nouveau.
>
> This lets `send_command` wait for space to free up in the command queue.
> This is required to support continuation records which can fill up the
> queue.

Any reason that this isn't implemented as a `poll_allocate_command` which just
returns a `EAGAIN`, and then a wrapper function that just waits for space to be
ready when it got one? This way the logic is cleaner.

(I write this with Rust async in mind)

>
> Tested-by: Zhi Wang <zhiw@nvidia.com>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
>  drivers/gpu/nova-core/gsp/cmdq.rs | 39 +++++++++++++++++++++++++++------------
>  1 file changed, 27 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
> index 87dbbd6d1be9..efbbc89f4d8a 100644
> --- a/drivers/gpu/nova-core/gsp/cmdq.rs
> +++ b/drivers/gpu/nova-core/gsp/cmdq.rs
> @@ -250,6 +250,19 @@ fn new(dev: &device::Device<device::Bound>) -> Result<Self> {
>          }
>      }
>  
> +    /// Returns the size of the region of the CPU message queue that the driver is currently allowed
> +    /// to write to, in bytes.
> +    fn driver_write_area_size(&self) -> usize {
> +        let tx = self.cpu_write_ptr();
> +        let rx = self.gsp_read_ptr();
> +
> +        // `rx` and `tx` are both in `0..MSGQ_NUM_PAGES` per the invariants of `gsp_read_ptr` and
> +        // `cpu_write_ptr`. The minimum value case is where `rx == 0` and `tx == MSGQ_NUM_PAGES -
> +        // 1`, which gives `0 + MSGQ_NUM_PAGES - (MSGQ_NUM_PAGES - 1) - 1 == 0`.
> +        let slots = (rx + MSGQ_NUM_PAGES - tx - 1) % MSGQ_NUM_PAGES;
> +        num::u32_as_usize(slots) * GSP_PAGE_SIZE
> +    }
> +
>      /// Returns the region of the GSP message queue that the driver is currently allowed to read
>      /// from.
>      ///
> @@ -281,15 +294,22 @@ fn new(dev: &device::Device<device::Bound>) -> Result<Self> {
>      }
>  
>      /// Allocates a region on the command queue that is large enough to send a command of `size`
> -    /// bytes.
> +    /// bytes, waiting for space to become available based on the provided timeout.
>      ///
>      /// This returns a [`GspCommand`] ready to be written to by the caller.
>      ///
>      /// # Errors
>      ///
> -    /// - `EAGAIN` if the driver area is too small to hold the requested command.
> +    /// - `ETIMEDOUT` if space does not become available within the timeout.
>      /// - `EIO` if the command header is not properly aligned.
> -    fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> {
> +    fn allocate_command(&mut self, size: usize, timeout: Delta) -> Result<GspCommand<'_>> {
> +        read_poll_timeout(
> +            || Ok(self.driver_write_area_size()),
> +            |available_bytes| *available_bytes >= size_of::<GspMsgElement>() + size,
> +            Delta::ZERO,
> +            timeout,
> +        )?;
> +
>          // Get the current writable area as an array of bytes.
>          let (slice_1, slice_2) = {
>              let (slice_1, slice_2) = self.driver_write_area();
> @@ -298,13 +318,6 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> {
>              (slice_1.as_flattened_mut(), slice_2.as_flattened_mut())
>          };
>  
> -        // If the GSP is still processing previous messages the shared region
> -        // may be full in which case we will have to retry once the GSP has
> -        // processed the existing commands.
> -        if size_of::<GspMsgElement>() + size > slice_1.len() + slice_2.len() {
> -            return Err(EAGAIN);
> -        }
> -
>          // Extract area for the `GspMsgElement`.
>          let (header, slice_1) = GspMsgElement::from_bytes_mut_prefix(slice_1).ok_or(EIO)?;
>  
> @@ -497,7 +510,7 @@ fn notify_gsp(bar: &Bar0) {
>      ///
>      /// # Errors
>      ///
> -    /// - `EAGAIN` if there was not enough space in the command queue to send the command.
> +    /// - `ETIMEDOUT` if space does not become available within the timeout.
>      /// - `EIO` if the variable payload requested by the command has not been entirely
>      ///   written to by its [`CommandToGsp::init_variable_payload`] method.
>      ///
> @@ -509,7 +522,9 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result
>          Error: From<M::InitError>,
>      {
>          let command_size = size_of::<M::Command>() + command.variable_payload_len();
> -        let dst = self.gsp_mem.allocate_command(command_size)?;
> +        let dst = self
> +            .gsp_mem
> +            .allocate_command(command_size, Delta::from_secs(1))?;

Let's make these consts, not magic numbers.

Best,
Gary

>  
>          // Extract area for the command itself.
>          let (cmd, payload_1) = M::Command::from_bytes_mut_prefix(dst.contents.0).ok_or(EIO)?;


  reply	other threads:[~2026-03-02 14:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 11:42 [PATCH v4 0/9] gpu: nova-core: gsp: add continuation record support Eliot Courtney
2026-03-02 11:42 ` [PATCH v4 1/9] gpu: nova-core: gsp: sort MsgFunction variants alphabetically Eliot Courtney
2026-03-02 13:47   ` Gary Guo
2026-03-02 14:49     ` Alexandre Courbot
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue Eliot Courtney
2026-03-02 14:18   ` Gary Guo [this message]
2026-03-03  3:07     ` Eliot Courtney
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 3/9] rust: add EMSGSIZE error code Eliot Courtney
2026-03-02 14:19   ` Gary Guo
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 4/9] gpu: nova-core: gsp: add checking oversized commands Eliot Courtney
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 5/9] gpu: nova-core: gsp: clarify invariant on command queue Eliot Courtney
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 6/9] gpu: nova-core: gsp: unconditionally call variable payload handling Eliot Courtney
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 7/9] gpu: nova-core: gsp: add command_size helper Eliot Courtney
2026-03-02 14:22   ` Gary Guo
2026-03-03  3:12     ` Eliot Courtney
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 8/9] gpu: nova-core: gsp: support large RPCs via continuation record Eliot Courtney
2026-03-02 13:06   ` Alexandre Courbot
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-02 11:42 ` [PATCH v4 9/9] gpu: nova-core: gsp: add tests for continuation records Eliot Courtney
2026-03-03  3:34   ` Claude review: " Claude Code Review Bot
2026-03-03  3:34 ` Claude review: gpu: nova-core: gsp: add continuation record support Claude Code Review Bot

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=DGSD13LEUEZK.DXHNXLIRVY24@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=zhiw@nvidia.com \
    /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