mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Courbot <acourbot@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	 David Airlie <airlied@gmail.com>,
	Simona Vetter <simona@ffwll.ch>
Cc: John Hubbard <jhubbard@nvidia.com>,
	 Alistair Popple <apopple@nvidia.com>,
	Timur Tabi <ttabi@nvidia.com>,
	 Eliot Courtney <ecourtney@nvidia.com>,
	Zhi Wang <zhiw@nvidia.com>,
	 nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org,
	Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH 1/2] gpu: nova-core: gsp: cmdq: let GMC commands set their completion timeout
Date: Tue, 17 Nov 2026 00:06:45 +0900	[thread overview]
Message-ID: <20261117-cmdq-timeout-v1-1-4b50d0be335e@nvidia.com> (raw)
In-Reply-To: <20261117-cmdq-timeout-v1-0-4b50d0be335e@nvidia.com>

Every wait on the message queue uses `Cmdq::RECEIVE_TIMEOUT`, but some
GMC commands (notably r000's GSP_INIT, and a few vGPU commands) might
take longer to complete.

Make the timeout a parameter of `await_msg_with`, and take it from a new
`CommandToGsp::COMPLETION_TIMEOUT` associated constant when waiting for
the reply to a GMC command. The constant defaults to
`Cmdq::RECEIVE_TIMEOUT`, so existing commands are unaffected.

No functional change intended.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs     |  5 +++--
 drivers/gpu/nova-core/gsp/cmdq/gmc.rs | 14 +++++++++-----
 drivers/gpu/nova-core/gsp/cmdq/rpc.rs |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 8d34acaef9ea..ad37c979d8b7 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -686,7 +686,7 @@ fn consume_element<R>(
     /// Consumes messages from the queue until a message that satisfies `f` is encountered, and
     /// returns the result of `f`.
     ///
-    /// The message is waited for up to [`Cmdq::RECEIVE_TIMEOUT`] from the call.
+    /// The message is waited for up to `timeout` from the call.
     ///
     /// `f` is expected to return `Ok(Some(_))` with the result to return to the caller, and
     /// `Ok(None)` to signal that the received message was not the one expected (such messages are
@@ -700,9 +700,10 @@ fn consume_element<R>(
     /// - Any error returned by `f`.
     fn await_msg_with<R>(
         &mut self,
+        timeout: Delta,
         f: impl Fn(GspParsedMessage<'_>) -> Result<Option<R>>,
     ) -> Result<R> {
-        let deadline = Instant::<Monotonic>::now() + Cmdq::RECEIVE_TIMEOUT;
+        let deadline = Instant::<Monotonic>::now() + timeout;
         loop {
             let remaining = deadline - Instant::<Monotonic>::now();
             if remaining.is_negative() {
diff --git a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
index 04033c64ca72..512a327a1c89 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
@@ -6,6 +6,7 @@
 use kernel::{
     device,
     prelude::*,
+    time::Delta,
     transmute::{
         AsBytes,
         FromBytes, //
@@ -61,6 +62,9 @@ pub(crate) trait CommandToGsp {
     /// value).
     const MAX_REPLY_SIZE: u32;
 
+    /// Time given to the GSP to complete this command once it is sent.
+    const COMPLETION_TIMEOUT: Delta = Cmdq::RECEIVE_TIMEOUT;
+
     /// Error type returned by [`CommandToGsp::init`].
     type InitError;
 
@@ -283,8 +287,8 @@ impl Cmdq<'_> {
     ///
     /// - `EMSGSIZE` if the command does not fit in a single command queue element.
     /// - `ETIMEDOUT` if space does not become available to send the command, or if the reply does
-    ///   not arrive within [`Self::RECEIVE_TIMEOUT`] of the send, however many events arrive
-    ///   while waiting.
+    ///   not arrive within [`CommandToGsp::COMPLETION_TIMEOUT`] of the send, however many events
+    ///   arrive while waiting.
     /// - `EIO` if the variable payload requested by the command has not been entirely
     ///   written to by its [`CommandToGsp::init_variable_payload`] method, or if a message fails
     ///   framing or checksum validation.
@@ -350,7 +354,7 @@ fn send_gmc_command<C>(&mut self, command: C) -> Result<u32>
     }
 
     /// Receives the reply of type `C::Reply` to the command sent with sequence number `seq`,
-    /// waiting up to [`Cmdq::RECEIVE_TIMEOUT`] from the call.
+    /// waiting up to [`CommandToGsp::COMPLETION_TIMEOUT`] from the call.
     ///
     /// Any GMC event that arrives first is passed to `on_event`, and any RPC message is logged.
     /// Neither extends the deadline.
@@ -376,8 +380,7 @@ fn await_gmc_reply<C: CommandToGsp>(
     {
         let dev = self.dev;
 
-        // TODO: replace `u32` with `NvStatus` once it lands.
-        self.await_msg_with(|message| -> Result<Option<Result<C::Reply, u32>>> {
+        self.await_msg_with(C::COMPLETION_TIMEOUT, |message| {
             let gmc_message = match message {
                 GspParsedMessage::Gmc(gmc_message) => gmc_message,
                 _ => {
@@ -386,6 +389,7 @@ fn await_gmc_reply<C: CommandToGsp>(
                 }
             };
 
+            // TODO: use `NvStatus` instead of `u32` for status once it lands.
             let status = match gmc_message.reply_status(C::COMMAND, seq) {
                 Some(status) => status,
                 // Reply to another command, e.g. one that timed out earlier.
diff --git a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
index 10d3f68b2f61..012f3c82e7c5 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
@@ -401,6 +401,6 @@ fn await_rpc_msg<M: MessageFromGsp>(&mut self) -> Result<M>
             }
         };
 
-        self.await_msg_with(f)
+        self.await_msg_with(Cmdq::RECEIVE_TIMEOUT, f)
     }
 }

-- 
2.56.0


  reply	other threads:[~2026-11-16 15:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 15:06 [PATCH 0/2] gpu: nova-core: gsp: cmdq: preparatory patches for r000 and vGPU Alexandre Courbot
2026-11-16 15:06 ` Alexandre Courbot [this message]
2026-11-16 15:06 ` [PATCH 2/2] gpu: nova-core: gsp: cmdq: support GMC replies without payload Alexandre Courbot

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=20261117-cmdq-timeout-v1-1-4b50d0be335e@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=simona@ffwll.ch \
    --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

all inboxes | Powered by JetHome®