From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02EF7EA4E04 for ; Mon, 2 Mar 2026 14:18:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 525C510E105; Mon, 2 Mar 2026 14:18:51 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=garyguo.net header.i=@garyguo.net header.b="SojWXDMZ"; dkim-atps=neutral Received: from LO0P265CU003.outbound.protection.outlook.com (mail-uksouthazon11022131.outbound.protection.outlook.com [52.101.96.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 83A1910E521; Mon, 2 Mar 2026 14:18:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dyQ4V2MxLF3vcEup2k71LP3rTN7djM5N/YAyYbp8RvxgdkXE/5fRSYMiJhD2P7yp+u+ga1awUuifkH7DzHTadrrkwaAZIbO1EtCLECEgbHJlBrMVYIkiDKm4l8WSLY4JihK83yLs3mb1PEAMvCr8SBvvNgm822i7PvjEoJD+F7E9ywzj/SvSb6L0eLnh2B0fcmtBjHHNKN2yh0mx7zr4jrrv1qnOkDVn/7y5mq1OVa6vL1u7QpV70W7Ei7IzyqLtPR09xfdpXhVaK+WkKPUqroaIJRM64UDCQD2/gIv/D+dnMLWWwlAQ/WsMgQy591tMpsPpcmbu83Qwr/thsb2dLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=27hg2lWPJoZZ7dtgu7e0bWSqw3+DIEaMGm3+TVlFREM=; b=cKD6hxW23hl/r8Q8hDCFothk+mB6MXhDCRNe0KF05yNSClSfGwx2xYiNjPR9AcnOqD6Uf3aPfcDPdEjOFpMr/hpL1EiJyKdhKkEHICKajqT2QYPqWQqEv6Td8njWmEFtNSukg+5RXgKkUKcdJx3E915FnyA7FT201a9JeWdgAs+Hms+1UeT5++OxwR2un8/x6H738HWtI9zqKTAUCupBvJg+CCPwLP6v0+CcaufmPQp5FyoO/cjoh9NOFj3fCIhwrFNzi4r8NzO7uubHVVdeUC24a1T14sCgaUonqHf/a28oS3eOPuiIMdRLzed/r/MkEzApvEXbfcG99BJo4moL/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=27hg2lWPJoZZ7dtgu7e0bWSqw3+DIEaMGm3+TVlFREM=; b=SojWXDMZYyisTlg5PTRUeXCLD/AHiC1h4jk1AZlTP1ig8zlwlOwLJ6a6I67Zsmc3MClcroGeosEzP73GfFDBOKOgVztSRnnnS4Tq1yKnxhaMDooIOhMO0YEDhVS+Ew/jtq8D83EVnLJPgEmu3m3bWP5litLEgue15XyJIcwUMas= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by LOYP265MB1790.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:f2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16; Mon, 2 Mar 2026 14:18:45 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%5]) with mapi id 15.20.9654.020; Mon, 2 Mar 2026 14:18:45 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 02 Mar 2026 14:18:44 +0000 Message-Id: Cc: "Zhi Wang" , "John Hubbard" , "Alistair Popple" , "Joel Fernandes" , "Timur Tabi" , , , , Subject: Re: [PATCH v4 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue From: "Gary Guo" To: "Eliot Courtney" , "Danilo Krummrich" , "Alice Ryhl" , "Alexandre Courbot" , "David Airlie" , "Simona Vetter" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Trevor Gross" X-Mailer: aerc 0.21.0 References: <20260302-cmdq-continuation-v4-0-c011f15aad58@nvidia.com> <20260302-cmdq-continuation-v4-2-c011f15aad58@nvidia.com> In-Reply-To: <20260302-cmdq-continuation-v4-2-c011f15aad58@nvidia.com> X-ClientProxiedBy: LO4P265CA0143.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c4::19) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|LOYP265MB1790:EE_ X-MS-Office365-Filtering-Correlation-Id: 11787b35-8a4d-438b-d8a8-08de78669d04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|376014|1800799024|10070799003|366016|921020|7053199007; X-Microsoft-Antispam-Message-Info: tj9CTx9LMGM7ac5ysuDgedQkENssua55DeLqm11BhDe0HSFq6VeVbGV7iXD5cKpLZbCW35psFGu8+8VMdH1kZtnTUyrv+xl9//k57fDpoTg4TWcblEssK80zEbE+MUCl3XmDgPGXfCN2ADQU1Uz49k20FdlsHsscv+KOFqn+8pAAxkTxrNKvkzwBBKJDF85dYqbBeSbFoNEXyfLnbau6yqe68O48dUv4ql7ibuc/oLA7kH9f1ix34tn0Hhj9plg7PLQqcEjhRR8pXcocOmqt2/V++86NPCDhrvaeJySe3WBRDRiE+mzxndm/avg8n4q1fN/LCtLZEr++bm/HX75kdzEz0sSldHDIMnqiFAiL4UetrRIjb/oEwgHrxUP4g2ZjY1HNvgYoQBCHTu+gsEIOdbZFU9o+8WgADbFDO9Gk9cRF9VgkCMw/nenVJR8YqMXond+qjPupIe28OEuIhZZb+WOQt9PD8mpoJHdKu+TY+kO0sihVDU1NRhe9zcrPxH75iS9AFEkm9jyRaNFBRD4FKZO7oz+8nwTR3JwfNtOP+1C/NazsOsnX6dMHu8s0XOnNRXN7EcNEuMoHCUGu6V/w5LNk3ayx48l5peFqnv7E++S1gaOvhsPYuz8Du9XkdPEDn7lQMgkhDIbtWzLg/Ht4UWbc1JuFFJh/bDMGBmBi3zyKwuFvU1q1nNdp1NnYDpmoCAemE/s1Wf6J6jodhsfJsXyVGU3V7moXWGHqpN71Kc0ggQLym+tSGCb/uaCwTWuBVEsthfF5PS88f54tVFyq+A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230040)(7416014)(376014)(1800799024)(10070799003)(366016)(921020)(7053199007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UTY0YmtPUkJPZXgvMUNGdjkxdCtwODNrQjcyczVtSHlWTFh1Mnl2OHV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hbzdxaGlOdmVR?= =?utf-8?B?RUQ2Y3NZV0JvTkM2QTJ1LzJIQmM0SkxWT0czSU9DTzlZYTlnTHhmWE8zOEox?= =?utf-8?B?US90M3NwOG5GM2tVUXZCbGR3WS8yTTlXUnFLaHBpUTQ4dnBLNmVvQXhueVdI?= =?utf-8?B?dkNEUlFLQk9iNi9adWRDMm9DS0VKUUVnMXAvZWtIYTR3QTUxRmNwM0J3ZUFn?= =?utf-8?B?M0JFaWVPR2NaUkxoeEVOazAwTUlHbHYyR1ZhNDhya0FuTGRkR2IzWC9obXVL?= =?utf-8?B?blYzN0lpZkZyUCsrQ2dkazNuQktVQjRKVlRWT3ZEdHNKUk1LSFVkSGFUTTlo?= =?utf-8?B?ZVBtVXJ4czhxbmR1aUZNVVk1SW1zSmNsZHV4OVpDTzVxOG5EZG5mdTgza1U3?= =?utf-8?B?cUJEd2U2dzB5ZTcyMkNXbUtTUkNvWVMyRzhIR3ZMMVRjRXhNMEcrVUpyeTJU?= =?utf-8?B?dWg1RjBHWGdxTnd3OWdCSEhmWUhPYk55STlNUVNuM0JRZGRCNi9pdz09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 11787b35-8a4d-438b-d8a8-08de78669d04 X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 14:18:45.0333 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PtVVGU14QDMkxTKhcx/hT/peqd3Py3YSIlqr+XXLKLTB9K9OS8hCcN9kakDFoCvLcaPZYIykUXWyn6trhOFVMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LOYP265MB1790 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 j= ust returns a `EAGAIN`, and then a wrapper function that just waits for space t= o be ready when it got one? This way the logic is cleaner. (I write this with Rust async in mind) > > Tested-by: Zhi Wang > Signed-off-by: Eliot Courtney > --- > 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/gs= p/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) -> Resul= t { > } > } > =20 > + /// 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 =3D self.cpu_write_ptr(); > + let rx =3D self.gsp_read_ptr(); > + > + // `rx` and `tx` are both in `0..MSGQ_NUM_PAGES` per the invaria= nts of `gsp_read_ptr` and > + // `cpu_write_ptr`. The minimum value case is where `rx =3D=3D 0= ` and `tx =3D=3D MSGQ_NUM_PAGES - > + // 1`, which gives `0 + MSGQ_NUM_PAGES - (MSGQ_NUM_PAGES - 1) - = 1 =3D=3D 0`. > + let slots =3D (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 c= urrently allowed to read > /// from. > /// > @@ -281,15 +294,22 @@ fn new(dev: &device::Device) -> Resu= lt { > } > =20 > /// 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 provid= ed timeout. > /// > /// This returns a [`GspCommand`] ready to be written to by the call= er. > /// > /// # Errors > /// > - /// - `EAGAIN` if the driver area is too small to hold the requested= command. > + /// - `ETIMEDOUT` if space does not become available within the time= out. > /// - `EIO` if the command header is not properly aligned. > - fn allocate_command(&mut self, size: usize) -> Result= > { > + fn allocate_command(&mut self, size: usize, timeout: Delta) -> Resul= t> { > + read_poll_timeout( > + || Ok(self.driver_write_area_size()), > + |available_bytes| *available_bytes >=3D size_of::() + size, > + Delta::ZERO, > + timeout, > + )?; > + > // Get the current writable area as an array of bytes. > let (slice_1, slice_2) =3D { > let (slice_1, slice_2) =3D self.driver_write_area(); > @@ -298,13 +318,6 @@ fn allocate_command(&mut self, size: usize) -> Resul= t> { > (slice_1.as_flattened_mut(), slice_2.as_flattened_mut()) > }; > =20 > - // If the GSP is still processing previous messages the shared r= egion > - // may be full in which case we will have to retry once the GSP = has > - // processed the existing commands. > - if size_of::() + size > slice_1.len() + slice_2.l= en() { > - return Err(EAGAIN); > - } > - > // Extract area for the `GspMsgElement`. > let (header, slice_1) =3D GspMsgElement::from_bytes_mut_prefix(s= lice_1).ok_or(EIO)?; > =20 > @@ -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 time= out. > /// - `EIO` if the variable payload requested by the command has not= been entirely > /// written to by its [`CommandToGsp::init_variable_payload`] meth= od. > /// > @@ -509,7 +522,9 @@ pub(crate) fn send_command(&mut self, bar: &Bar0, = command: M) -> Result > Error: From, > { > let command_size =3D size_of::() + command.variable_= payload_len(); > - let dst =3D self.gsp_mem.allocate_command(command_size)?; > + let dst =3D self > + .gsp_mem > + .allocate_command(command_size, Delta::from_secs(1))?; Let's make these consts, not magic numbers. Best, Gary > =20 > // Extract area for the command itself. > let (cmd, payload_1) =3D M::Command::from_bytes_mut_prefix(dst.c= ontents.0).ok_or(EIO)?;