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 A8409CA600A for ; Thu, 8 Oct 2026 07:59:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 12F2610FC8F; Thu, 8 Oct 2026 07:59:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="YmCnqvkw"; dkim-atps=neutral Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010006.outbound.protection.outlook.com [52.101.193.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A02610FC8F for ; Thu, 8 Oct 2026 07:59:37 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=r+B/M+m4Idd/QIugb1paVQHNM5KFfuKZVg9Czju09BXINrJaRx6ss1dPZF0gtNBJ9T7eMaNA+nW4jW56k/XZbZzBmuvV2DnVA6Phr+EL/3zWQ4IsT6aOYBZd2l0Xw+O+HobFgEWSGrwTVPfY6BOFbARoVhSCbpxIpne/rG8GiHsSlJdSeK0B0FzPQAg5znc8eosLyDqkdV9p2IvlT8jfnxo7fjUJXsIfmPSOoVKlM4XmX7ibO7+MPJi2Cn2Hx94WFiq+5exK1QONh6iimfPQLcxHUDrIEbQt9EMFg/SIQpGrpP5aZoQ+OsbH1yU4lYEFBKdgxXMyiYtBn1S8KphJRw== 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=jPJUoRFjF1pqPX6cL6oqG+oQ+BgByzpp9gD9LM2boq4=; b=gydtzOi2VNwO0c6wQtN5wytHaxCld70szHKa0ubRy9U6dK0pRPXKqugWn6+20TwFUJSdLhbkM9XoQlVdV6zHxaL5u7KsO+c5JPfREVVzaYjFvX662GSnP7W756MhNX+CcEp8iPkeUfSwd7yTNhLr5sHx36PJdhxBTPmfhzoGslvpH4z646a4YjTNbiK83saJd3oBBDbHk8PfX3VJWqiTg4ObJ8ePnAxZPHRHvPL+HC8l2UTviWlzqMq40jqgSPHTvprkP4XFZ1p8YS6Z6c5Cqekt1b4zOjEpg91Wi3k9AhNb+tzXBtAFRUfj9EyrHryb5xRtjMXmKYRrRh2LiwTGkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=jPJUoRFjF1pqPX6cL6oqG+oQ+BgByzpp9gD9LM2boq4=; b=YmCnqvkwkKmcLSXJ7mk+tEVH9Tu2yg+uh/9z3tcTdkdz56Ru/I2ZKYalCb961ubRyfNNbZmbLrull+be7D32RhLvd6e/ZdpEfUWfVMkQ7DYAcLkS3MJOaOcNgUiyYE/6A4xctwRWDJpFCmhvZGQWMgG/ZTd2qsyhEEIsm3S5+MM= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB9457.namprd12.prod.outlook.com (2603:10b6:610:27c::7) by EAYPR12MB999157.namprd12.prod.outlook.com (2603:10b6:303:2bf::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.15; Thu, 8 Oct 2026 07:59:34 +0000 Received: from CH2PR12MB9457.namprd12.prod.outlook.com ([fe80::85a8:1df:840a:cd4c]) by CH2PR12MB9457.namprd12.prod.outlook.com ([fe80::85a8:1df:840a:cd4c%4]) with mapi id 15.21.0496.015; Thu, 8 Oct 2026 07:59:32 +0000 Content-Type: multipart/alternative; boundary="------------cdYvgbebxsFEQlu8s8roFe8N" Message-ID: <6befb9ce-4cac-4afc-91ad-ec7133ffb626@amd.com> Date: Thu, 8 Oct 2026 15:59:25 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 01/10] drm/amdgpu: implement PMC ioctl framework To: James Zhu , Alexander.Deucher@amd.com, felix.kuehling@amd.com, "Welton, Benjamin" Cc: Ray.Huang@amd.com, amd-gfx@lists.freedesktop.org References: <20260922093436.596947-1-lingshan.zhu@amd.com> <20260922093436.596947-2-lingshan.zhu@amd.com> Content-Language: en-US From: "Zhu, Lingshan" In-Reply-To: X-ClientProxiedBy: SI2PR04CA0011.apcprd04.prod.outlook.com (2603:1096:4:197::10) To CH2PR12MB9457.namprd12.prod.outlook.com (2603:10b6:610:27c::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR12MB9457:EE_|EAYPR12MB999157:EE_ X-MS-Office365-Filtering-Correlation-Id: 56153530-098d-459c-786d-08df25121621 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|23010399003|366016|6133799003|22082099003|18002099003|8096899003|3023799007|4143699003|10067099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: i2rCv4Qtxg+gCdcLm5rRowzhryVeYOSElS7E61GXdPUr59ICFUaFetCgEumXykBrP+hXnbOzDYwtlD5wljbsbaoclncH//khZ2KU9wR+3mR7vSuA78SD3ynRNRR16dkqN7EW6Iq5Q+T0Pw16RIEjPSOnCJFpU29YIkOT17zNGRumeFQz+LnlP6KXN77yoRU3204r7hmJ4U9RzMYRwWbAtNTfhQW66bwEK6yIf8ogAyPHNzTekp9AuviwsIIAx8/mebgNayRXf4Eywb1M1rq48AgFLXYhbCoEDu7DYi6O/D0RtRC+DhREeMY6/63H6n9haeI7QJDdSm0ufITo84of3wrpoB5SKQ9GT7s9AE3KSuJbw7lbiVU+4ok1indvnUjZRuw5zbklHkOuxhix7nTfwq/iRzXCQVjqvSmGpEGoJcs8Js4yrAM7CRTv++teDuG33++5kVXGXJYgIzisL5VT7eS03/umXAN1jzbg5EDgP+Y0hIyrDijBlbQ39xAwsczBWy9gxVusdpWwmNkHqQbZ356wPyQVpJ7Jl2/1mPamGd4oqlVGxhCIynboxCRt+CrSFbkIPsdhbwFrGMt+IPmpmTPLAfM+7Ny4eMrWxnc7XW+KdR2UUdh73xGgwLRu578+EW20+kv1sC77xF5/xUzKTJd+iLdQhzOJd026ygv/rmw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB9457.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(23010399003)(366016)(6133799003)(22082099003)(18002099003)(8096899003)(3023799007)(4143699003)(10067099003)(11063799006)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?T2lxNDVHQWhPbFNpckZRaDlLWUk4RTltNGNxL0FPd040eG9IaSswV1g1MzZ5?= =?utf-8?B?aGR4ajJXNGI2and2cUF4UEdrZTdsU2tkQk1lYlZHTlBFR3AxSkl0RFY3WTNn?= =?utf-8?B?TFkyREIzN0sxWUFCMFZqTkthR092aXZNZW9meSsxQllpS20rSGY2QWg1V1pv?= =?utf-8?B?VVZ3U0dJa1I0K0JBV2ROVXBQOHlkSVByeDM0NFc1NHhRY3ZYNkZjL21aOXBO?= =?utf-8?B?eFpXRXVaLzRmTX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UmRUV0ZI?= =?utf-8?B?cmZyUEhkRHhoUnQzYUZ3YndEVFNEWjhENStvWGdSZ25QVUZQWENCV1kxM1JV?= =?utf-8?B?MEtuVzdQREVwS0xvUk8zam5WNkJHVVR1d200UXNJUEdBNHBrbko3R2xRakpJ?= =?utf-8?B?MnhGRExMSFNmTG5lbFhOc2preXJSMzJ1dWhHRGpVMHhLM1ZxY3lnblRCay9I?= =?utf-8?B?N2RBRzhLRFpXRzI3bFAzY3NEUmZGRUxCMkRGNk1JbnlHMFlWODRHbXVnRTVJ?= =?utf-8?B?OTFMcDNZUVdBMFlseWlYdkFrN0d3ZWxLUURWMEgyMmNST1ZHVDhodz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56153530-098d-459c-786d-08df25121621 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB9457.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2026 07:59:32.4189 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sLSVPZ/bXcd7VeIraKfYujf0QBRdi3TyoTSFbGo9xXdzn/6LBoZHnvPsBLUYi5WfyiOQ39Uwsqdlj/FRE9RK5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: EAYPR12MB999157 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" --------------cdYvgbebxsFEQlu8s8roFe8N Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 9/24/2026 11:49 PM, James Zhu wrote: > > On 2026-09-23 23:38, Zhu, Lingshan wrote: >> On 9/23/2026 10:17 PM, James Zhu wrote: >>> >>> On 2026-09-22 05:34, Zhu Lingshan wrote: >>>> This commit implements basic ioctl framework for PMC, >>>> including basic operations. >>>> >>>> This commit also implements AMDGPU_PROFILER_OP_VERSION >>>> which report profiler version to the user space. >>>> >>>> Signed-off-by: Zhu Lingshan >>>> --- >>>>   drivers/gpu/drm/amd/amdgpu/Makefile          |  2 +- >>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c      |  2 + >>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 44 >>>> ++++++++++++++++++++ >>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 33 +++++++++++++++ >>>>   include/uapi/drm/amdgpu_drm.h                | 36 ++++++++++++++++ >>>>   5 files changed, 116 insertions(+), 1 deletion(-) >>>>   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c >>>>   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h >>>> >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile >>>> b/drivers/gpu/drm/amd/amdgpu/Makefile >>>> index 6fb0a913e33b..d7db69e9d6a0 100644 >>>> --- a/drivers/gpu/drm/amd/amdgpu/Makefile >>>> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile >>>> @@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.o >>>> amdgpu_doorbell_mgr.o amdgpu_kms >>>>       amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o >>>> amdgpu_lockdep.o \ >>>>       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o >>>> amdgpu_dev_coredump.o \ >>>>       amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o >>>> amdgpu_ip.o \ >>>> -    amdgpu_wb.o amdgpu_cwsr.o amdgpu_events.o >>>> +    amdgpu_wb.o amdgpu_cwsr.o amdgpu_events.o amdgpu_profiler.o >>>>     amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o >>>>   diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >>>> index 7c473f60bd28..a98c4a47e196 100644 >>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >>>> @@ -55,6 +55,7 @@ >>>>   #include "amdgpu_cwsr.h" >>>>   #include "amdgpu_userq_fence.h" >>>>   #include "../amdxcp/amdgpu_xcp_drv.h" >>>> +#include "amdgpu_profiler.h" >>>>     /* >>>>    * KMS wrapper. >>>> @@ -3096,6 +3097,7 @@ const struct drm_ioctl_desc >>>> amdgpu_ioctls_kms[] = { >>>>       DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, >>>> DRM_AUTH|DRM_RENDER_ALLOW), >>>>       DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, >>>> amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), >>>>       DRM_IOCTL_DEF_DRV(AMDGPU_PROC_OPTIONS, >>>> amdgpu_proc_options_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), >>>> +    DRM_IOCTL_DEF_DRV(AMDGPU_PROFILER, amdgpu_profiler_ioctl, >>>> DRM_AUTH|DRM_RENDER_ALLOW), >>>>   }; >>>>     static const struct drm_driver amdgpu_kms_driver = { >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c >>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c >>>> new file mode 100644 >>>> index 000000000000..04902696adab >>>> --- /dev/null >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c >>>> @@ -0,0 +1,44 @@ >>>> +// SPDX-License-Identifier: MIT >>>> +/* >>>> + * Copyright 2026 Advanced Micro Devices, Inc. >>>> + * >>>> + * Permission is hereby granted, free of charge, to any person >>>> obtaining a >>>> + * copy of this software and associated documentation files (the >>>> "Software"), >>>> + * to deal in the Software without restriction, including without >>>> limitation >>>> + * the rights to use, copy, modify, merge, publish, distribute, >>>> sublicense, >>>> + * and/or sell copies of the Software, and to permit persons to >>>> whom the >>>> + * Software is furnished to do so, subject to the following >>>> conditions: >>>> + * >>>> + * The above copyright notice and this permission notice shall be >>>> included in >>>> + * all copies or substantial portions of the Software. >>>> + * >>>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, >>>> EXPRESS OR >>>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF >>>> MERCHANTABILITY, >>>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO >>>> EVENT SHALL >>>> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, >>>> DAMAGES OR >>>> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR >>>> OTHERWISE, >>>> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE >>>> USE OR >>>> + * OTHER DEALINGS IN THE SOFTWARE. >>>> + * >>>> + */ >>>> + >>>> +#include >>>> +#include >>>> +#include "amdgpu_profiler.h" >>>> + >>>> +int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, >>>> struct drm_file *filp) >>>> +{ >>>> +    struct drm_amdgpu_profiler_args *args = data; >>>> + >>>> +    switch (args->op) { >>>> +    case AMDGPU_PROFILER_OP_VERSION: >>>> +        args->version = AMDGPU_PROFILER_VERSION_NUM; >>>> +        return 0; >>>> +    case AMDGPU_PROFILER_OP_RESERVE: >>>> +        return -EOPNOTSUPP; >>>> +    case AMDGPU_PROFILER_OP_PMC: >>>> +        return -EOPNOTSUPP; >>>> +    default: >>>> +        return -EINVAL; >>>> +    } >>>> +} >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h >>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h >>>> new file mode 100644 >>>> index 000000000000..c27b5f9b3ff0 >>>> --- /dev/null >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h >>>> @@ -0,0 +1,33 @@ >>>> +/* SPDX-License-Identifier: MIT */ >>>> +/* >>>> + * Copyright 2026 Advanced Micro Devices, Inc. >>>> + * >>>> + * Permission is hereby granted, free of charge, to any person >>>> obtaining a >>>> + * copy of this software and associated documentation files (the >>>> "Software"), >>>> + * to deal in the Software without restriction, including without >>>> limitation >>>> + * the rights to use, copy, modify, merge, publish, distribute, >>>> sublicense, >>>> + * and/or sell copies of the Software, and to permit persons to >>>> whom the >>>> + * Software is furnished to do so, subject to the following >>>> conditions: >>>> + * >>>> + * The above copyright notice and this permission notice shall be >>>> included in >>>> + * all copies or substantial portions of the Software. >>>> + * >>>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, >>>> EXPRESS OR >>>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF >>>> MERCHANTABILITY, >>>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO >>>> EVENT SHALL >>>> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, >>>> DAMAGES OR >>>> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR >>>> OTHERWISE, >>>> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE >>>> USE OR >>>> + * OTHER DEALINGS IN THE SOFTWARE. >>>> + * >>>> + */ >>>> + >>>> +#ifndef __AMDGPU_PROFILER_H__ >>>> +#define __AMDGPU_PROFILER_H__ >>>> + >>>> +#include >>>> +#include >>>> + >>>> +int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, >>>> struct drm_file *filp); >>>> + >>>> +#endif /* __AMDGPU_PROFILER_H__ */ >>>> diff --git a/include/uapi/drm/amdgpu_drm.h >>>> b/include/uapi/drm/amdgpu_drm.h >>>> index 9222be9a6d2a..acc63804ba8c 100644 >>>> --- a/include/uapi/drm/amdgpu_drm.h >>>> +++ b/include/uapi/drm/amdgpu_drm.h >>>> @@ -60,6 +60,7 @@ extern "C" { >>>>   #define DRM_AMDGPU_GEM_LIST_HANDLES    0x19 >>>>   #define DRM_AMDGPU_PROC_OPTIONS        0x1A >>>>   #define DRM_AMDGPU_CWSR            0x1B >>>> +#define DRM_AMDGPU_PROFILER        0x1C >>>>     #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + >>>> DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create) >>>>   #define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + >>>> DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap) >>>> @@ -83,6 +84,7 @@ extern "C" { >>>>   #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES >>>> DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct >>>> drm_amdgpu_gem_list_handles) >>>>   #define DRM_IOCTL_AMDGPU_PROC_OPTIONS DRM_IOWR(DRM_COMMAND_BASE + >>>> DRM_AMDGPU_PROC_OPTIONS, struct drm_amdgpu_proc_options) >>>>   #define DRM_IOCTL_AMDGPU_CWSR    DRM_IOWR(DRM_COMMAND_BASE + >>>> DRM_AMDGPU_CWSR, union drm_amdgpu_cwsr) >>>> +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + >>>> DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args) >>>>     /** >>>>    * DOC: memory domains >>>> @@ -1809,6 +1811,40 @@ struct drm_amdgpu_proc_options { >>>>       } kfd_sigbus_delay; >>>>   }; >>>>   +#define AMDGPU_PROFILER_VERSION_NUM    1 >>>> + >>>> +enum amdgpu_profiler_ops { >>>> +    AMDGPU_PROFILER_OP_VERSION = 1, >>>> +    AMDGPU_PROFILER_OP_RESERVE = 2, >>> [JZ] the implementation tells that it is >>> AMDGPU_PROFILER_OP_PMC_RESERVE, it is better to put it under new PMC >>> sub-ioctl op >> Do you mean implement it like {bool pmc_enable, bool reserve} in a >> struct? I am not sure it is a good idea >> and this reservation design is a improvement. Because it separates >> the reserve(lock) and unreserve(unlock), >> so we don't need to keep the reservation during the PMC operations in >> a complex way, and we won't meet >> the problems like how to handle the situation where the user tries to >> unlock but keeps enable = 1. > [JZ] profiler includes PMC, PC sampling, SPM etc. do the other feature > need reservation also? Hello James, I think we should implement reservations, but in different ways: 1) if it is a device scope profiler, then we should implement a reservation mechanism like this one. 2) if the profiler facility allows running multiple type of profiler concurrently(e.g, PMC and PC together), and some of the profiler may collect correlate data, then we need reservation because we don't want a profiler to sniff another. 3) if it is a dri node or any sub function profiler, then we should implement a proper reservation in that level. I believe we need a device level reservation for PMC. Thanks Lingshan >> >> Thanks >> Lingshan >>>> +    AMDGPU_PROFILER_OP_PMC = 3, >>>> +}; >>>> + >>>> +enum amdgpu_profiler_reserve_ops { >>>> +    /* release the device resertaion, only the reservation owner >>>> do this */ >>>> +    AMDGPU_PROFILER_RELEASE = 0, >>>> +    /* reserve the device profiler */ >>>> +    AMDGPU_PROFILER_RESERVE = 1, >>>> +    /* Clear the device profiler reservation, in case the reservation >>>> +     * owner can no longer release the reservation(e.g., it crashes), >>>> +     * This operation does not take the reseration nor touch >>>> profielr state >>>> +     */ >>>> +    AMDGPU_PROFILER_CLEAR_RESERVATION = 2, >>>> +}; >>>> + >>>> +struct drm_amdgpu_profiler_args { >>>> +    /* enum amdgpu_profiler_ops */ >>>> +    __u8 op; >>>> +    __u8 pad[3]; >>>> +    union { >>>> +        /* AMDGPU_PROFILER_OP_RESERVE: enum >>>> amdgpu_profiler_reserve_ops */ >>>> +        __u8 reserve; >>>> +        /* AMDGPU_PROFILER_OP_PMC: 1 enable PMC, 0 disable PMC */ >>>> +        __u8 perfcount_enable; >>>> +        /* AMDGPU_PROFILER_OP_VERSION: AMDGPU_PROFILER_VERSION_NUM */ >>>> +        __u32 version; >>>> +    }; >>>> +}; >>>> + >>>>   #if defined(__cplusplus) >>>>   } >>>>   #endif --------------cdYvgbebxsFEQlu8s8roFe8N Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 9/24/2026 11:49 PM, James Zhu wrote:

On 2026-09-23 23:38, Zhu, Lingshan wrote:
On 9/23/2026 10:17 PM, James Zhu wrote:

On 2026-09-22 05:34, Zhu Lingshan wrote:
This commit implements basic ioctl framework for PMC,
including basic operations.

This commit also implements AMDGPU_PROFILER_OP_VERSION
which report profiler version to the user space.

Signed-off-by: Zhu Lingshan<lingshan.zhu@amd.com>
---
  drivers/gpu/drm/amd/amdgpu/Makefile          |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c      |  2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 44 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 33 +++++++++++++++
  include/uapi/drm/amdgpu_drm.h                | 36 ++++++++++++++++
  5 files changed, 116 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
index 6fb0a913e33b..d7db69e9d6a0 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.o amdgpu_doorbell_mgr.o amdgpu_kms
      amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o amdgpu_lockdep.o \
      amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_dev_coredump.o \
      amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o amdgpu_ip.o \
-    amdgpu_wb.o amdgpu_cwsr.o amdgpu_events.o
+    amdgpu_wb.o amdgpu_cwsr.o amdgpu_events.o amdgpu_profiler.o
    amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
  diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 7c473f60bd28..a98c4a47e196 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -55,6 +55,7 @@
  #include "amdgpu_cwsr.h"
  #include "amdgpu_userq_fence.h"
  #include "../amdxcp/amdgpu_xcp_drv.h"
+#include "amdgpu_profiler.h"
    /*
   * KMS wrapper.
@@ -3096,6 +3097,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
      DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
      DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
      DRM_IOCTL_DEF_DRV(AMDGPU_PROC_OPTIONS, amdgpu_proc_options_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF_DRV(AMDGPU_PROFILER, amdgpu_profiler_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  };
    static const struct drm_driver amdgpu_kms_driver = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c
new file mode 100644
index 000000000000..04902696adab
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include <linux/errno.h>
+#include <drm/amdgpu_drm.h>
+#include "amdgpu_profiler.h"
+
+int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
+{
+    struct drm_amdgpu_profiler_args *args = data;
+
+    switch (args->op) {
+    case AMDGPU_PROFILER_OP_VERSION:
+        args->version = AMDGPU_PROFILER_VERSION_NUM;
+        return 0;
+    case AMDGPU_PROFILER_OP_RESERVE:
+        return -EOPNOTSUPP;
+    case AMDGPU_PROFILER_OP_PMC:
+        return -EOPNOTSUPP;
+    default:
+        return -EINVAL;
+    }
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
new file mode 100644
index 000000000000..c27b5f9b3ff0
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __AMDGPU_PROFILER_H__
+#define __AMDGPU_PROFILER_H__
+
+#include <drm/drm_device.h>
+#include <drm/drm_file.h>
+
+int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
+
+#endif /* __AMDGPU_PROFILER_H__ */
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 9222be9a6d2a..acc63804ba8c 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -60,6 +60,7 @@ extern "C" {
  #define DRM_AMDGPU_GEM_LIST_HANDLES    0x19
  #define DRM_AMDGPU_PROC_OPTIONS        0x1A
  #define DRM_AMDGPU_CWSR            0x1B
+#define DRM_AMDGPU_PROFILER        0x1C
    #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -83,6 +84,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
  #define DRM_IOCTL_AMDGPU_PROC_OPTIONS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROC_OPTIONS, struct drm_amdgpu_proc_options)
  #define DRM_IOCTL_AMDGPU_CWSR    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CWSR, union drm_amdgpu_cwsr)
+#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)
    /**
   * DOC: memory domains
@@ -1809,6 +1811,40 @@ struct drm_amdgpu_proc_options {
      } kfd_sigbus_delay;
  };
  +#define AMDGPU_PROFILER_VERSION_NUM    1
+
+enum amdgpu_profiler_ops {
+    AMDGPU_PROFILER_OP_VERSION = 1,
+    AMDGPU_PROFILER_OP_RESERVE = 2,
[JZ] the implementation tells that it is AMDGPU_PROFILER_OP_PMC_RESERVE, it is better to put it under new PMC sub-ioctl op
Do you mean implement it like {bool pmc_enable, bool reserve} in a struct? I am not sure it is a good idea
and this reservation design is a improvement. Because it separates the reserve(lock) and unreserve(unlock),
so we don't need to keep the reservation during the PMC operations in a complex way, and we won't meet
the problems like how to handle the situation where the user tries to unlock but keeps enable = 1.
[JZ] profiler includes PMC, PC sampling, SPM etc. do the other feature need reservation also?
Hello James,

I think we should implement reservations, but in different ways:
1) if it is a device scope profiler, then we should implement a reservation mechanism like this one.
2) if the profiler facility allows running multiple type of profiler concurrently(e.g, PMC and PC together),
and some of the profiler may collect correlate data, then we need reservation because we don't want a profiler to
sniff another.
3) if it is a dri node or any sub function profiler, then we should implement a proper reservation in that level.

I believe we need a device level reservation for PMC.

Thanks
Lingshan

Thanks
Lingshan
+    AMDGPU_PROFILER_OP_PMC = 3,
+};
+
+enum amdgpu_profiler_reserve_ops {
+    /* release the device resertaion, only the reservation owner do this */
+    AMDGPU_PROFILER_RELEASE = 0,
+    /* reserve the device profiler */
+    AMDGPU_PROFILER_RESERVE = 1,
+    /* Clear the device profiler reservation, in case the reservation
+     * owner can no longer release the reservation(e.g., it crashes),
+     * This operation does not take the reseration nor touch profielr state
+     */
+    AMDGPU_PROFILER_CLEAR_RESERVATION = 2,
+};
+
+struct drm_amdgpu_profiler_args {
+    /* enum amdgpu_profiler_ops */
+    __u8 op;
+    __u8 pad[3];
+    union {
+        /* AMDGPU_PROFILER_OP_RESERVE: enum amdgpu_profiler_reserve_ops */
+        __u8 reserve;
+        /* AMDGPU_PROFILER_OP_PMC: 1 enable PMC, 0 disable PMC */
+        __u8 perfcount_enable;
+        /* AMDGPU_PROFILER_OP_VERSION: AMDGPU_PROFILER_VERSION_NUM */
+        __u32 version;
+    };
+};
+
  #if defined(__cplusplus)
  }
  #endif
--------------cdYvgbebxsFEQlu8s8roFe8N--