Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E6FF606A31A for ; Tue, 1 Dec 2026 05:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=4e9+/JgF Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FDA810E253; Tue, 1 Dec 2026 05:32:27 +0000 (UTC) Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012029.outbound.protection.outlook.com [40.107.200.29]) by gabe.freedesktop.org (Postfix) with ESMTPS id 579C310E0A5 for ; Tue, 1 Dec 2026 05:32:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i5IvCnzTVUAT/vb2Q2QWRsQ4RQLzMkUg5A6xNjzcE8vtgZ/3ueSWbrK+17cfFpCdw8FeCBcSEkR8OLnCu866Ga0a/yo6wI3awcS+C5NP7w0feLVD7dY4TRhEQTEMhHyiXtYKt4RjVYPStGZva8Yu5A7nf5u68IpQ77JvwSkJ/pMp2V+yFIgRpq67sbBtWSVUUMVQBZfPb0XXCRhs+wA1i396Jgkyawpv1UJV1hjosLJtNX3RIrjN0xbElIfnuWdcdr5T70/OtDJN3eC16cK9DmbinJR/ALYAoFjKo/NZuKrD+MolttqvvMyhO6aCkhYIswuhir4rRGOWmrxXm9JgxA== 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=ZpHnfp2a6aNegHnBZlIDHAoC0/yIafBLsgR/nzCT1Zo=; b=HbEc5Iz/JRM57afimlGQsvY0OLvF0x5dQb90XH16wcv7Xf0WN/pk0WtOSV1KE8SQwVRz8NDmTm1b7rbFWoJELS5d9QoEF2QWiObjOvCL439nmYGANv9XLHC9ID5PWLa57DniJUGU/sy7ZWP5eZz012cpjgwTZ79k+ma7Pc8mM3YtkXx+Fi3M/BwlcoWgIK2R529b4Gt0i7zIjN70zlhRpQZQF/DRk9LNAe/UXn8h92Y4qpvUtwR/scR9jPq2WMI8bRB3fs16LO4xcknxLLZ5kCF7VT528XtMsFP9eIoxJthQnZbsJgckbhaIMox9cGN1LewTd/J1vwAJDQ5qdOonhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZpHnfp2a6aNegHnBZlIDHAoC0/yIafBLsgR/nzCT1Zo=; b=4e9+/JgFSvUpdfbcdKqOeGLZeeiS2khbJpVDfs8BSIzDNHi3Q1DpUqI5EfBPTEEzav84Sh1JpZ8g4LZPWocLl9qj3rxZixnJpUUnN8JoeM7I8sCy2aBiJvIzig8SJI6ut4WIw3ETqJCKcV+Wul5QuTDm5i6HPRADYIUy6OHcp3M= Received: from SJ2PR07CA0007.namprd07.prod.outlook.com (2603:10b6:a03:505::12) by CH2PR12MB9517.namprd12.prod.outlook.com (2603:10b6:610:27f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Tue, 1 Dec 2026 05:32:09 +0000 Received: from SJ5PEPF000001E9.namprd05.prod.outlook.com (2603:10b6:a03:505:cafe::ab) by SJ2PR07CA0007.outlook.office365.com (2603:10b6:a03:505::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 05:32:09 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SJ5PEPF000001E9.mail.protection.outlook.com (10.167.242.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 05:32:08 +0000 Received: from Satlexmb09.amd.com (10.181.42.218) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 23:32:08 -0600 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb09.amd.com (10.181.42.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 23:32:07 -0600 Received: from JesseDEV.amd.com (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Mon, 30 Nov 2026 23:32:01 -0600 From: Jesse Zhang To: CC: , Christian Koenig , Srinivasan Shanmugam , Alex Deucher Subject: [PATCH v2 01/11] drm/amdgpu: Document render-node EVENTFD subscriptions Date: Tue, 1 Dec 2026 13:30:44 +0800 Message-ID: <20261201053159.2550315-2-Jesse.Zhang@amd.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261201053159.2550315-1-Jesse.Zhang@amd.com> References: <20261201053159.2550315-1-Jesse.Zhang@amd.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001E9:EE_|CH2PR12MB9517:EE_ X-MS-Office365-Filtering-Correlation-Id: d9267d9e-2707-4adc-de8b-08df4f6c7189 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|1800799024|23010399003|82310400026|376014|56012099006|261028144727099003|261022105027099003|10067099003|261026140227099003|261026121527099003|261102123227099003|261021123027099003|261022075727099003|261021121427099003|261009223027099003|22082099003|18002099003|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: t568OB4mZ4WmLI/IWwkgBrPdvnfEMX0RsKrpfWR0CRBtMy9v6ijOI3mRNOTPmGFbOt2gMq6/opMKgcx0UYQlw5cOV+WpGPfXJGHcIK/qkB0LZUA3fJ10EZ1ZJmXfM4WrikhHAlKwAbPpM390DuaL/5zAEBdvMv9h1QNPcycbYYyMmf5Q/qmzsr8i5GjFExAx9nFbyNtYDH5nisMS5J2jLEqxFtnOGCBUHtdmPe3OP2RtwinmWJaxxkvk7S0a3cfRwjD+VwRzwJgyxbk71tyWAHhBAu7wypJUBjtVE/QHSrAfm/fDJAddKZdwi3rmBGS3UpNhpTsdajZq5GVxNx+8ZwdhOuTIu/FM2C7YDPKaTbPIi3SeZHBaHooW792agaRr8g9wA6gtAHm+/i1dxgPf3VvvAkeIcN+3m58b7DDcsiWetSvWgadmvs8U2ORvg3ynz2RDHXYQfjhmxxWiGjyNKp6Z4ZQsBhz9owUeiCekGls3lWar2VAdWxuz7N07eWSlHOlkm6nPc1ngFQBDilYK/9UZp8TUgwyIsiS6G4by5O7PBnYLWeIVfl4NYY25gHShH89NLKZvP4Lhvhvu5Gg1qaeILDtFgyobcG686GhZpuh2p2ZOAqYxQY5sYbn5edr9cavrzijGfEcE2UMisX7VeNxnNnmm2G1p134q9rzRE7nr5Bn/Utg6cYvrg/ckabaanNwnCq71Pz4nj7Tv4MagVA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700016)(1800799024)(23010399003)(82310400026)(376014)(56012099006)(261028144727099003)(261022105027099003)(10067099003)(261026140227099003)(261026121527099003)(261102123227099003)(261021123027099003)(261022075727099003)(261021121427099003)(261009223027099003)(22082099003)(18002099003)(11063799006)(6133799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZNMfknqBLqDtofcz2sh5/mrdu4DG+9/HcwQ45IXeeGF41C0zGZv/hc+wjDCTBMZECnDoKT85sVMZ1/yPBAk6KcC0ltlOtNoSI7L75lC9b20NgrzCPqLrtdK319MOSm9B50zcPkF4ewtFHTqKrC47nqQZWzSlKzfIuoI+0DWL6gxeIoatVADBKx7anfPyvq1fjcpiJ2pPuQDlMmyX3RNL5RP8fVzVPebpn2D6jjbMCuEUw65mt/Nh7lSw+Dl1VhJRsfEhqtApcpX5vLCHLjnHL/ZhCaLjvm0jCSTpFiXWDhsk3DLzElnBITK/grWET5kTxgYY4aSsAfoa2hQOTUC/jSnAAoqvVa+n8bCWA/xkleIaoJTzXtQTIF2+fxzAmiagSTBuvmOJNGiWuSvzYjeQbogWrB1lpLtLEVe1S4YGJVbr868lsBteDkftnABl/O+Z X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 05:32:08.8530 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9267d9e-2707-4adc-de8b-08df4f6c7189 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001E9.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB9517 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Srinivasan Shanmugam Add documentation describing the render-node EVENTFD interface. Document the supported event types, subscription model, queue-scoped versus device-scoped events, subscription lifetime and cleanup, and example userspace usage. Also add the document to the AMDGPU documentation index. The documentation matches the current EVENTFD UAPI and is intended to serve as a reference for userspace applications using the interface. Suggested-by: Alex Deucher Signed-off-by: Srinivasan Shanmugam --- Documentation/gpu/amdgpu/eventfd.rst | 134 +++++++++++++++++++++++++++ Documentation/gpu/amdgpu/index.rst | 1 + include/uapi/drm/amdgpu_drm.h | 24 ++--- 3 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 Documentation/gpu/amdgpu/eventfd.rst diff --git a/Documentation/gpu/amdgpu/eventfd.rst b/Documentation/gpu/amdgpu/eventfd.rst new file mode 100644 index 000000000000..1ad34abf1322 --- /dev/null +++ b/Documentation/gpu/amdgpu/eventfd.rst @@ -0,0 +1,134 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================== +AMDGPU render-node EVENTFD API +============================== + +Overview +======== + +The AMDGPU EVENTFD ioctl lets a render-node client subscribe an eventfd to +driver-defined GPU events. + +EVENTFD is a notification interface. It wakes userspace when a matching event +occurs, but it does not carry event metadata. Event-specific metadata, when +available through a separate interface, is not returned through the eventfd +counter. + +The ioctl is available on an AMDGPU render-node file descriptor and uses +``struct drm_amdgpu_eventfd``. + +Creating a subscription +======================= + +Userspace first creates an eventfd with ``eventfd(2)``. It then fills +``struct drm_amdgpu_eventfd`` as follows: + +``op`` + Set to ``DRM_AMDGPU_EVENTFD_OP_BIND``. + +``event_type`` + Set to one of the values in ``enum drm_amdgpu_event_type``. + +``eventfd`` + Set to the file descriptor returned by ``eventfd(2)``. File descriptor zero + is valid. + +``queue_id`` + For queue-scoped events, set this to the user queue handle returned by the + AMDGPU USERQ create ioctl. For device-scoped events, set this to zero. + +``flags`` + Must be zero. + +Userspace then calls ``DRM_IOCTL_AMDGPU_EVENTFD`` on the AMDGPU render-node +file descriptor. + +The driver resolves ``queue_id`` to the corresponding queue object during the +ioctl. + +Repeating the same bind for the same event type, queue, and eventfd is +idempotent. + +Queue-scoped events +=================== + +Queue-scoped events are associated with a user queue and require a non-zero +``queue_id`` belonging to the same render-node file. + +Examples of queue-scoped events include +``DRM_AMDGPU_EVENT_TYPE_USERQ_EOP`` and +``DRM_AMDGPU_EVENT_TYPE_QUEUE_RESET``. + +The event-type definitions indicate which events are queue-scoped. + +Device-scoped events +==================== + +Device-scoped events are not associated with a user queue and require +``queue_id`` to be zero. + +Examples of device-scoped events include +``DRM_AMDGPU_EVENT_TYPE_MEMORY_EXCEPTION`` and +``DRM_AMDGPU_EVENT_TYPE_GPU_RESET``. + +The event-type definitions indicate which events are device-scoped. Event +producers may be added independently of the subscription infrastructure, so +the presence of an event type in the UAPI does not by itself guarantee that +every GPU generation produces that event. + +Receiving a notification +======================== + +When a matching event occurs, the driver signals the subscribed eventfd. + +Userspace reads or polls the eventfd using the normal eventfd API. + +The value read from the eventfd is the eventfd counter. It does not identify +the event type or contain an AMDGPU-specific payload. Applications should +maintain their own mapping between eventfd descriptors and subscriptions. + +Removing a subscription +======================= + +To remove a subscription, userspace submits the same event type, queue ID, and +eventfd with ``op`` set to ``DRM_AMDGPU_EVENTFD_OP_UNBIND``. + +The unbind operation removes only the matching association. + +Lifetime and cleanup +==================== + +A queue-scoped subscription retains a reference to its queue. The driver +removes all subscriptions associated with a queue when that queue is removed +from the USERQ manager. + +The driver also removes all remaining subscriptions when the render-node file +is closed. + +Usage example +============= + +The following example omits error handling for clarity:: + + int efd; + struct drm_amdgpu_eventfd args = { + .op = DRM_AMDGPU_EVENTFD_OP_BIND, + .event_type = DRM_AMDGPU_EVENT_TYPE_USERQ_EOP, + .queue_id = queue_id, + .flags = 0, + }; + + efd = eventfd(0, EFD_CLOEXEC); + args.eventfd = efd; + + ioctl(render_fd, DRM_IOCTL_AMDGPU_EVENTFD, &args); + + /* + * poll() or read() efd. The returned value is the eventfd counter, + * not an AMDGPU event record. + */ + + args.op = DRM_AMDGPU_EVENTFD_OP_UNBIND; + ioctl(render_fd, DRM_IOCTL_AMDGPU_EVENTFD, &args); + close(efd); diff --git a/Documentation/gpu/amdgpu/index.rst b/Documentation/gpu/amdgpu/index.rst index ba2ee7327867..41ab045dfa5f 100644 --- a/Documentation/gpu/amdgpu/index.rst +++ b/Documentation/gpu/amdgpu/index.rst @@ -25,3 +25,4 @@ Next (GCN), Radeon DNA (RDNA), and Compute DNA (CDNA) architectures. amdgpu-glossary ualink ptl + eventfd diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 8a546e0ae0a1..543f698b83cf 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -223,6 +223,13 @@ union drm_amdgpu_gem_create { struct drm_amdgpu_gem_create_out out; }; +/** + * enum drm_amdgpu_event_type - AMDGPU render-node event types + * @DRM_AMDGPU_EVENT_TYPE_USERQ_EOP: user queue reached an end-of-pipe event + * @DRM_AMDGPU_EVENT_TYPE_QUEUE_RESET: user queue was reset + * @DRM_AMDGPU_EVENT_TYPE_MEMORY_EXCEPTION: GPU memory exception + * @DRM_AMDGPU_EVENT_TYPE_GPU_RESET: device-wide GPU reset + */ enum drm_amdgpu_event_type { DRM_AMDGPU_EVENT_TYPE_USERQ_EOP = 1, DRM_AMDGPU_EVENT_TYPE_QUEUE_RESET = 2, @@ -230,6 +237,11 @@ enum drm_amdgpu_event_type { DRM_AMDGPU_EVENT_TYPE_GPU_RESET = 4, }; +/** + * enum drm_amdgpu_eventfd_op - EVENTFD subscription operations + * @DRM_AMDGPU_EVENTFD_OP_BIND: create an EVENTFD subscription + * @DRM_AMDGPU_EVENTFD_OP_UNBIND: remove an EVENTFD subscription + */ enum drm_amdgpu_eventfd_op { DRM_AMDGPU_EVENTFD_OP_BIND = 0, DRM_AMDGPU_EVENTFD_OP_UNBIND = 1, @@ -241,18 +253,8 @@ enum drm_amdgpu_eventfd_op { * @event_type: kernel-defined AMDGPU event type * @eventfd: eventfd file descriptor * @queue_id: queue identifier for queue-scoped subscriptions, or 0 for - * device/GPU-scoped subscriptions + * device-scoped subscriptions * @flags: must be 0 - * - * This ioctl lets userspace register or unregister eventfd notifications - * for a render-node event. - * - * Eventfd signaling is notification-only. - * - * USERQ_EOP and QUEUE_RESET are queue-scoped events. - * Userspace specifies @queue_id when registering these subscriptions. - * - * MEMORY_EXCEPTION is currently GPU-scoped and requires @queue_id = 0. */ struct drm_amdgpu_eventfd { __u32 op; -- 2.50.1