amdgpu: implement Performance Monitor Counter support
Subsystems (3)
cover amdgpu: implement Performance Monitor Counter support
This series implements PMC support for amdgpu. Including two parts:
1) PMC Enablement
2) Profiler Reservation
The user space should take the reservation, then set PMC.
This series depends on and used new helper introduced in another series:
https://lists.freedesktop.org/archives/amd-gfx/2026-August/151692.html
Please help Review
Thanks!
Zhu Lingshan (10):
drm/amdgpu: implement PMC ioctl framework drm/amdgpu: add device-wide PMC config drm/amdgpu: introduce PMC ioctl handler drm/amdgpu: implement reservation mechanism for PMC drm/amdgpu: set device-wide PMC enablement indicator drm/amdgpu: GFX11: set mqd->perfcount from mqd_prop drm/amdgpu: GFX12: set mqd->perfcount from mqd_prop drm/amdgpu: GFX12.1: set mqd->perfcount from mqd_prop drm/amdgpu: implement device PMC handler drm/amdgpu: set userq perf state before publish it
drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 + drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 166 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 38 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 95 ++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 11 ++ include/uapi/drm/amdgpu_drm.h | 36 ++++ 13 files changed, 390 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
Signature · 1 line
2.55.0
RFC 1/10 drm/amdgpu: implement PMC ioctl framework
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.
--- 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
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
@@ -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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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 = {
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +44 -0
44 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +33 -0
@@ -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__ */
include/uapi/drm/amdgpu_drm.h +36 -0
@@ -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 , +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
Signature · 1 line
2.55.0
Re: [RFC 01/10] drm/amdgpu: implement PMC ioctl framework
Quoted 160 lines · Zhu Lingshan
This commit implements basic ioctl framework for PMC, including basic operations.
This commit also implements
AMDGPU_PROFILER_OP_VERSIONwhich report profiler version to the user space.Signed-off-by Zhu Lingshan<[email protected]>--- 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.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.hdrivers/gpu/drm/amd/amdgpu/Makefile +1
-1@@ -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.odrivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-0@@ -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 = {drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +44
-0@@ -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 ; + } +}drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +33
-0@@ -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__ */ include/uapi/drm/amdgpu_drm.h +2
-0@@ -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
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_proc_options { · line 1818
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +5
-0@@ -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
Quoted 32 lines
include/uapi/drm/amdgpu_drm.h +29
-0+ 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
Re: [RFC 01/10] drm/amdgpu: implement PMC ioctl framework
Quoted 204 lines · James Zhu
Quoted 202 lines · Zhu Lingshan
This commit implements basic ioctl framework for PMC, including basic operations.
This commit also implements
AMDGPU_PROFILER_OP_VERSIONwhich report profiler version to the user space.Signed-off-by Zhu Lingshan<[email protected]>---
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.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.hdrivers/gpu/drm/amd/amdgpu/Makefile +0
-0@@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.oamdgpu_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 --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index7c473f60bd28..a98c4a47e196100644drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -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 structdrm_driveramdgpu_kms_driver= {drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +5
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +6
-0+ +#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)drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +15
-0+{ + 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; + } +}drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +5
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +8
-0+ +#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);drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +2
-0+ +#endif /* __AMDGPU_PROFILER_H__ */ include/uapi/drm/amdgpu_drm.h +2
-0@@ -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, uniondrm_amdgpu_gem_mmap)include/uapi/drm/amdgpu_drm.h +3
-0@@ -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, structdrm_amdgpu_profiler_args) /**
* DOC: memory domainsinclude/uapi/drm/amdgpu_drm.h +0
-0@@ -1809,6 +1811,40 @@ struct drm_amdgpu_proc_options { } kfd_sigbus_delay; };
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_proc_options { · line 1818
Quoted 5 lines
+#define AMDGPU_PROFILER_VERSION_NUM 1
include/uapi/drm/amdgpu_drm.h +4
-0+ +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.
Thanks
Lingshan
Quoted 35 lines
Quoted 35 lines
+
AMDGPU_PROFILER_OP_PMC= 3,include/uapi/drm/amdgpu_drm.h +4
-0+}; + +enum amdgpu_profiler_reserve_ops { + /* release the device resertaion, only the reservation owner dothis */
+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 thereservation(e.g., it crashes), + * This operation does not take the reseration nor touch profielr state
+ */
+AMDGPU_PROFILER_CLEAR_RESERVATION= 2,include/uapi/drm/amdgpu_drm.h +8
-0+}; + +struct drm_amdgpu_profiler_args { + /* enum amdgpu_profiler_ops */ + __u8 op; + __u8 pad[3]; + union { + /* AMDGPU_PROFILER_OP_RESERVE: enum
amdgpu_profiler_reserve_ops*/
+__u8reserve;
+ /*AMDGPU_PROFILER_OP_PMC: 1 enable PMC, 0 disable PMC */ +__u8perfcount_enable;
+ /*AMDGPU_PROFILER_OP_VERSION:AMDGPU_PROFILER_VERSION_NUM*/ +__u32version;
+ };include/uapi/drm/amdgpu_drm.h +2
-0+}; +#if
defined(__cplusplus)
}
#endif
Re: [RFC 01/10] drm/amdgpu: implement PMC ioctl framework
Quoted 198 lines · Lingshan
Quoted 189 lines · James Zhu
Quoted 187 lines · Zhu Lingshan
This commit implements basic ioctl framework for PMC, including basic operations.
This commit also implements
AMDGPU_PROFILER_OP_VERSIONwhich report profiler version to the user space.Signed-off-by Zhu Lingshan<[email protected]>---
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.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.hdrivers/gpu/drm/amd/amdgpu/Makefile +0
-0@@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.oamdgpu_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 --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.cindex7c473f60bd28..a98c4a47e196100644drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-0@@ -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_driveramdgpu_kms_driver= {drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +5
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +6
-0+ +#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)drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +15
-0+{ + 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; + } +}drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +5
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +8
-0+ +#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);drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +2
-0+ +#endif /* __AMDGPU_PROFILER_H__ */ include/uapi/drm/amdgpu_drm.h +2
-0@@ -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 {Quoted 8 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_proc_options { · line 1818
Quoted 7 lines
include/uapi/drm/amdgpu_drm.h +0
-0} kfd_sigbus_delay; };+#define AMDGPU_PROFILER_VERSION_NUM 1
include/uapi/drm/amdgpu_drm.h +4
-0+ +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
Quoted 4 lines
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?
Quoted 38 lines
Thanks
LingshanQuoted 35 lines
Quoted 35 lines
+
AMDGPU_PROFILER_OP_PMC= 3,include/uapi/drm/amdgpu_drm.h +4
-0+}; + +enum amdgpu_profiler_reserve_ops { + /* release the device resertaion, only the reservation owner dothis */
+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 thereservation(e.g., it crashes), + * This operation does not take the reseration nor touch profielr state
+ */
+AMDGPU_PROFILER_CLEAR_RESERVATION= 2,include/uapi/drm/amdgpu_drm.h +8
-0+}; + +struct drm_amdgpu_profiler_args { + /* enum amdgpu_profiler_ops */ + __u8 op; + __u8 pad[3]; + union { + /* AMDGPU_PROFILER_OP_RESERVE: enum
amdgpu_profiler_reserve_ops*/
+__u8reserve;
+ /*AMDGPU_PROFILER_OP_PMC: 1 enable PMC, 0 disable PMC */ +__u8perfcount_enable;
+ /*AMDGPU_PROFILER_OP_VERSION:AMDGPU_PROFILER_VERSION_NUM*/ +__u32version;
+ };include/uapi/drm/amdgpu_drm.h +2
-0+}; +#if
defined(__cplusplus)
}
#endif
Re: [RFC 01/10] drm/amdgpu: implement PMC ioctl framework
Quoted 227 lines · James Zhu
Quoted 217 lines · Lingshan
Quoted 208 lines · James Zhu
Quoted 206 lines · Zhu Lingshan
This commit implements basic ioctl framework for PMC, including basic operations.
This commit also implements
AMDGPU_PROFILER_OP_VERSIONwhich report profiler version to the user space.Signed-off-by Zhu Lingshan<[email protected]>---
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.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.hdrivers/gpu/drm/amd/amdgpu/Makefile +0
-0@@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.oamdgpu_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 --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index7c473f60bd28..a98c4a47e196100644drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -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 structdrm_driveramdgpu_kms_driver= {drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +5
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +6
-0+ +#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)drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c new file +15
-0+{ + 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; + } +}drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +5
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +8
-0+ +#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);drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h new file +2
-0+ +#endif /* __AMDGPU_PROFILER_H__ */ include/uapi/drm/amdgpu_drm.h +1
-0@@ -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, uniondrm_amdgpu_gem_mmap)include/uapi/drm/amdgpu_drm.h +0
-0@@ -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)
#defineDRM_IOCTL_AMDGPU_PROC_OPTIONSDRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROC_OPTIONS, struct drm_amdgpu_proc_options)#define DRM_IOCTL_AMDGPU_CWSRDRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CWSR, union drm_amdgpu_cwsr)
+#defineDRM_IOCTL_AMDGPU_PROFILERDRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/**
* DOC: memory domainsinclude/uapi/drm/amdgpu_drm.h +0
-0@@ -1809,6 +1811,40 @@ struct drm_amdgpu_proc_options { } kfd_sigbus_delay; };Quoted 8 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_proc_options { · line 1818
Quoted 5 lines
+#define AMDGPU_PROFILER_VERSION_NUM 1
include/uapi/drm/amdgpu_drm.h +4
-0+ +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 opQuoted 8 lines
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.
Quoted 2 lines
[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
Quoted 38 lines
Quoted 38 lines
Thanks
LingshanQuoted 35 lines
Quoted 35 lines
+
AMDGPU_PROFILER_OP_PMC= 3,include/uapi/drm/amdgpu_drm.h +4
-0+}; + +enum amdgpu_profiler_reserve_ops { + /* release the device resertaion, only the reservation ownerdo 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 thereservation(e.g., it crashes), + * This operation does not take the reseration nor touch profielr state
+ */
+AMDGPU_PROFILER_CLEAR_RESERVATION= 2,include/uapi/drm/amdgpu_drm.h +8
-0+}; + +struct drm_amdgpu_profiler_args { + /* enum amdgpu_profiler_ops */ + __u8 op; + __u8 pad[3]; + union { + /* AMDGPU_PROFILER_OP_RESERVE: enum
amdgpu_profiler_reserve_ops*/
+__u8reserve;
+ /*AMDGPU_PROFILER_OP_PMC: 1 enable PMC, 0 disable PMC */ +__u8perfcount_enable;
+ /*AMDGPU_PROFILER_OP_VERSION:AMDGPU_PROFILER_VERSION_NUM*/ +__u32version;
+ };include/uapi/drm/amdgpu_drm.h +2
-0+}; +#if
defined(__cplusplus)
}
#endif
RFC 2/10 drm/amdgpu: add device-wide PMC config
In reply to Zhu LingshanThis commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8 -0
@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { +struct mutex lock; +struct drm_file *owner; +bool enable; +}; +struct amdgpu_device {struct device *dev;struct pci_dev *pdev;
@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; +struct amdgpu_pmc_profiler pmc_profiler; +/* df */ struct amdgpu_df df;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); +mutex_init (&adev->pmc_profiler.lock);/* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class (adev);
@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)kfree (adev->pci_state);kfree (adev->pcie_reset_ctx.swds_pcistate);kfree (adev->pcie_reset_ctx.swus_pcistate); + +mutex_destroy (&adev->pmc_profiler.lock); }/**
Signature · 1 line
2.55.0
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.
[JZ] I think it should be render-node wide, not device-wide
Quoted 54 lines
Signed-off-by Zhu Lingshan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ 2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +8
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { +struct mutex lock; +struct drm_file *owner; +bool enable; +}; +struct amdgpu_device {struct device *dev;struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; +struct amdgpu_pmc_profiler pmc_profiler; +/* df */ struct amdgpu_df df;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); +mutex_init (&adev->pmc_profiler.lock);/* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class (adev);@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)kfree (adev->pci_state);kfree (adev->pcie_reset_ctx.swds_pcistate);kfree (adev->pcie_reset_ctx.swus_pcistate); + +mutex_destroy (&adev->pmc_profiler.lock); }/**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 6 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
It could be, but we don't have a requirement document defines the scope.
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager
Thanks
Lingshan
Quoted 53 lines
Quoted 53 lines
Signed-off-by Zhu Lingshan <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 3 +++2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { + struct mutex lock; + struct drm_file *owner; + bool enable; +}; + struct amdgpu_device { struct device *dev; struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; + /* df */ struct amdgpu_df df;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cindexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, mutex_init(&adev->pm.stable_pstate_ctx_lock); mutex_init(&adev->benchmark_mutex); mutex_init(&adev->gfx.reset_sem_mutex); + mutex_init(&adev->pmc_profiler.lock); /* Associate locks with lockdep classes for orderingvalidation */
amdgpu_lockdep_set_class(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->pci_state); kfree(adev->pcie_reset_ctx.swds_pcistate); kfree(adev->pcie_reset_ctx.swus_pcistate); + + mutex_destroy(&adev->pmc_profiler.lock); } /**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 6 lines · Lingshan
Quoted 5 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.
Quoted 7 lines
Quoted 1 line
[JZ] I think it should be render-node wide, not device-wide
Hi James,
It could be, but we don't have a requirement document defines the scope.
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager
[JZ] One device could be split into multiple nodes with different processes running.
I am wondering if this is really we want. Ben may comment on it.
Quoted 54 lines
Thanks
LingshanQuoted 51 lines
Quoted 51 lines
Signed-off-by Zhu Lingshan <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 3 +++2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { + struct mutex lock; + struct drm_file *owner; + bool enable; +}; + struct amdgpu_device { struct device *dev; struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; + /* df */ struct amdgpu_df df;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cindexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, mutex_init(&adev->pm.stable_pstate_ctx_lock); mutex_init(&adev->benchmark_mutex); mutex_init(&adev->gfx.reset_sem_mutex); + mutex_init(&adev->pmc_profiler.lock); /* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class(adev);@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->pci_state); kfree(adev->pcie_reset_ctx.swds_pcistate); kfree(adev->pcie_reset_ctx.swus_pcistate); + + mutex_destroy(&adev->pmc_profiler.lock); } /**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 13 lines · James Zhu
Quoted 11 lines · Lingshan
Quoted 6 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
It could be, but we don't have a requirement document defines the scope.
Quoted 7 lines
Quoted 2 lines
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager[JZ] One device could be split into multiple nodes with different processes running.
I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should be device scope.
Thanks
Lingshan
Quoted 58 lines
Quoted 58 lines
Thanks
LingshanQuoted 54 lines
Quoted 54 lines
Signed-off-by Zhu Lingshan <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 3 +++2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { + struct mutex lock; + struct drm_file *owner; + bool enable; +}; + struct amdgpu_device { struct device *dev; struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; + /* df */ struct amdgpu_df df;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cindexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, mutex_init(&adev->pm.stable_pstate_ctx_lock); mutex_init(&adev->benchmark_mutex); mutex_init(&adev->gfx.reset_sem_mutex); + mutex_init(&adev->pmc_profiler.lock); /* Associate locks with lockdep classes for orderingvalidation */
amdgpu_lockdep_set_class(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->pci_state); kfree(adev->pcie_reset_ctx.swds_pcistate); kfree(adev->pcie_reset_ctx.swus_pcistate); + + mutex_destroy(&adev->pmc_profiler.lock); } /**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
AMD General
Hi, Lingshan,
Sorry to reply later! Just be back from vacation.
Yes, there is only one set of PMC registers on the device.
But the minimum control scope is XCC. So, I think we should design PMC based on
Node instead of device. We need not enable the PMC on XCCs which have no PMC data collection request. Since the request is based on render node.
Thanks & Best Regards!
James Zhu
________________________________
From: Zhu, Lingshan <[email protected]>
Sent: Thursday, October 8, 2026 3:50 AM
To: Zhu, James <[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected] <[email protected]>
Subject: Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
On 9/24/2026 11:40 PM, James Zhu wrote:
On 2026-09-23 23:23, Zhu, Lingshan wrote:
On 9/23/2026 10:13 PM, James Zhu wrote:
On 2026-09-22 05:34, Zhu Lingshan wrote:
This commit implements a device-wide PMC config for amdgpu, which including the profiling owner, and the profiling enablement indicator.
[JZ] I think it should be render-node wide, not device-wide Hi James,
It could be, but we don't have a requirement document defines the scope.
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager
[JZ] One device could be split into multiple nodes with different processes running.
I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should be device scope.
Thanks
Lingshan
Thanks
Lingshan
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { +struct mutex lock; +struct drm_file *owner; +bool enable; +}; +struct amdgpu_device {struct device *dev;struct pci_dev *pdev;
@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; +/* df */ struct amdgpu_df df; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index c924a55fd16f..74ed42e53264 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); +mutex_init (&adev->pmc_profiler.lock);/* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class (adev);
@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)kfree (adev->pci_state);kfree (adev->pcie_reset_ctx.swds_pcistate);kfree (adev->pcie_reset_ctx.swus_pcistate); + +mutex_destroy (&adev->pmc_profiler.lock); }/**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 11 lines · James
AMD General
Hi, Lingshan,
Sorry to reply later! Just be back from vacation.
Yes, there is only one set of PMC registers on the device.
But the minimum control scope is XCC. So, I think we should design PMC based on Node instead of device. We need not enable the PMC on XCCs which have no PMC data collection request.
Since the request is based on render node.
They are per-device registers, so the scope should be the device, not XCC.
Another reason is, I assume we don't want one user to sniff another through PMC.
Thanks
Lingshan
Quoted 95 lines
Thanks & Best Regards!
James Zhu
--------------------------------------------------------------------------------
*From:* Zhu, Lingshan <[email protected]>
*Sent:* Thursday, October 8, 2026 3:50 AM
*To:* Zhu, James <[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>
*Cc:* Huang, Ray <[email protected]>; [email protected] <amd- [email protected]> *Subject:* Re: [RFC 02/10] drm/amdgpu: add device-wide PMC configQuoted 9 lines · James Zhu
Quoted 8 lines · Lingshan
Quoted 5 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
Quoted 8 lines
Quoted 4 lines
It could be, but we don't have a requirement document defines the scope.
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager[JZ] One device could be split into multiple nodes with different processes running.
I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should be device scope.
Thanks
LingshanQuoted 53 lines
Quoted 53 lines
Thanks
LingshanQuoted 51 lines
Quoted 51 lines
Signed-off-by Zhu Lingshan <[email protected]><mailto:[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ 2 files changed, 11 insertions(+)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
amdgpu/amdgpu.h
index8eff6b9ebe81..45897dca802f100644drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { +struct mutex lock; +struct drm_file *owner; +bool enable; +}; +struct amdgpu_device {struct device *dev;struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; +/* df */ struct amdgpu_df df; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/
drm/amd/amdgpu/amdgpu_device.c
indexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); +mutex_init (&adev->pmc_profiler.lock);/* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class (adev);@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)kfree (adev->pci_state);kfree (adev->pcie_reset_ctx.swds_pcistate);kfree (adev->pcie_reset_ctx.swus_pcistate); + +mutex_destroy (&adev->pmc_profiler.lock); }/**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 5 lines · Lingshan
Quoted 4 lines · James
AMD General
Hi, Lingshan,
Quoted 8 lines
Quoted 7 lines
Sorry to reply later! Just be back from vacation.
Yes, there is only one set of PMC registers on the device.
But the minimum control scope is XCC. So, I think we should design PMC based on Node instead of device. We need not enable the PMC on XCCs which have no PMC data collection request.
Since the request is based on render node.They are per-device registers, so the scope should be the device, not XCC.
[JZ] where did you get this information? From what I know, Compute / Shader PMCs / RLC & SPM Control / // / / / PC Sampling are all XCC based. a are all are
Quoted 2 lines
Another reason is, I assume we don't want one user to sniff another through PMC.
[JZ] if it is true, is it more easy to sniffer for per device design. the other nodes within the same device will enable PMC unexpectedly.
Quoted 96 lines
Thanks
LingshanQuoted 93 lines
Thanks & Best Regards!
James Zhu
--------------------------------------------------------------------------------
*From:* Zhu, Lingshan<[email protected]>
*Sent:* Thursday, October 8, 2026 3:50 AM
*To:* Zhu, James<[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix<[email protected]>
*Cc:* Huang, Ray<[email protected]>;[email protected] <amd- [email protected]> *Subject:* Re: [RFC 02/10] drm/amdgpu: add device-wide PMC configQuoted 9 lines · James Zhu
Quoted 8 lines · Lingshan
Quoted 5 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
Quoted 8 lines
Quoted 4 lines
It could be, but we don't have a requirement document defines the scope.
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager[JZ] One device could be split into multiple nodes with different processes running.
I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should be device scope.
Thanks
LingshanQuoted 52 lines
Quoted 52 lines
Thanks
LingshanQuoted 50 lines
Quoted 50 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ 2 files changed, 11 insertions(+)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
amdgpu/amdgpu.h
index8eff6b9ebe81..45897dca802f100644drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { +struct mutex lock; +struct drm_file *owner; +bool enable; +}; +struct amdgpu_device {struct device *dev;struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; +/* df */ struct amdgpu_df df; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/
drm/amd/amdgpu/amdgpu_device.c
indexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); +mutex_init (&adev->pmc_profiler.lock);/* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class (adev);@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)kfree (adev->pci_state);kfree (adev->pcie_reset_ctx.swds_pcistate);kfree (adev->pcie_reset_ctx.swus_pcistate); + +mutex_destroy (&adev->pmc_profiler.lock); }/**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 16 lines · James Zhu
Quoted 14 lines · Lingshan
Quoted 13 lines · James
AMD General
Hi, Lingshan,
Sorry to reply later! Just be back from vacation.
Yes, there is only one set of PMC registers on the device. But the minimum control scope is XCC. So, I think we should design PMC based on
Node instead of device. We need not enable the PMC on XCCs which have no PMC
data collection request.
Since the request is based on render node.
Quoted 5 lines
Quoted 2 lines
They are per-device registers, so the scope should be the device, not XCC.
[JZ] where did you get this information? From what I know, Compute / Shader PMCs / RLC & SPM Control / // / / / PC Sampling are all XCC based. a are all are
For GFX11/12, the instance number of XCC is 0, therefore their xcc_mask is 1, so the registers are per-device. You can read these information from sysfs and debugfs.
Please also take a look at KFD implementation at https://lists.freedesktop.org/archives/amd-gfx/2026-February/138408.html
It says: multiple PMC profilers on the same device can result in corrupted counter data
Quoted 5 lines
Quoted 3 lines
Another reason is, I assume we don't want one user to sniff another through PMC.
[JZ] if it is true, is it more easy to sniffer for per device design. the other nodes within the same device will enable PMC unexpectedly.
so we have implemented reservation/locking for PMC.
Thanks
Lingshan
Quoted 109 lines
Quoted 109 lines
Thanks
LingshanQuoted 106 lines
Thanks & Best Regards!
James Zhu
--------------------------------------------------------------------------------
*From:* Zhu, Lingshan<[email protected]>
*Sent:* Thursday, October 8, 2026 3:50 AM
*To:* Zhu, James<[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix<[email protected]> *Cc:* Huang, Ray<[email protected]>;[email protected] <amd- [email protected]>
*Subject:* Re: [RFC 02/10] drm/amdgpu: add device-wide PMC configQuoted 12 lines · James Zhu
Quoted 11 lines · Lingshan
Quoted 5 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
It could be, but we don't have a requirement document defines the scope.
Quoted 8 lines
Quoted 3 lines
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager[JZ] One device could be split into multiple nodes with different processes
running.I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should
be device scope.Thanks
LingshanQuoted 58 lines
Quoted 58 lines
Thanks
LingshanQuoted 56 lines
Quoted 56 lines
Signed-off-by Zhu Lingshan<[email protected]><mailto:[email protected]>
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 3 +++2 files changed, 11 insertions(+)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
amdgpu/amdgpu.h
index8eff6b9ebe81..45897dca802f100644drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { + struct mutex lock; + struct drm_file *owner; + bool enable; +}; + struct amdgpu_device { struct device *dev; struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; + /* df */ struct amdgpu_df df;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(structamdgpu_device *adev, mutex_init(&adev->pm.stable_pstate_ctx_lock); mutex_init(&adev->benchmark_mutex); mutex_init(&adev->gfx.reset_sem_mutex); + mutex_init(&adev->pmc_profiler.lock); /* Associate locks with lockdep classes for orderingvalidation */
amdgpu_lockdep_set_class(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->pci_state); kfree(adev->pcie_reset_ctx.swds_pcistate); kfree(adev->pcie_reset_ctx.swus_pcistate); + + mutex_destroy(&adev->pmc_profiler.lock); } /**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 15 lines · Lingshan
Quoted 14 lines · James Zhu
Quoted 12 lines · Lingshan
Quoted 11 lines · James
AMD General
Hi, Lingshan,
Sorry to reply later! Just be back from vacation.
Yes, there is only one set of PMC registers on the device.
But the minimum control scope is XCC. So, I think we should design PMC based on Node instead of device. We need not enable the PMC on XCCs which have no PMC data collection request.
Since the request is based on render node.
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
They are per-device registers, so the scope should be the device, not XCC.
[JZ] where did you get this information? From what I know, Compute / Shader PMCs / RLC & SPM Control / // / / / PC Sampling are all XCC based. a are all are
For GFX11/12, the instance number of XCC is 0, therefore their
xcc_maskis 1, so the registers are per-device. You can read these information from sysfs and debugfs.Please also take a look at KFD implementation athttps://lists.freedesktop.org/archives/amd-gfx/2026-February/138408.html
It says: multiple PMC profilers on the same device can result in corrupted counter data
[JZ] IIUC, the corruption data is with multiple processes enabled on same xcc. We still can have lock design to avoid multiple processes running on same node(same XCCs). we can run one PMC profiler on node1 only and leave other nodes on the same device have its own one only PMC profilers process running without affecting each other,.
Quoted 106 lines
Quoted 3 lines
Quoted 2 lines
Another reason is, I assume we don't want one user to sniff another through PMC.
[JZ] if it is true, is it more easy to sniffer for per device design. the other nodes within the same device will enable PMC unexpectedly.
so we have implemented reservation/locking for PMC.
Thanks
LingshanQuoted 99 lines
Quoted 99 lines
Thanks
LingshanQuoted 96 lines
Thanks & Best Regards!
James Zhu
--------------------------------------------------------------------------------
*From:* Zhu, Lingshan<[email protected]>
*Sent:* Thursday, October 8, 2026 3:50 AM
*To:* Zhu, James<[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix<[email protected]>
*Cc:* Huang, Ray<[email protected]>;[email protected] <amd- [email protected]> *Subject:* Re: [RFC 02/10] drm/amdgpu: add device-wide PMC configQuoted 9 lines · James Zhu
Quoted 8 lines · Lingshan
Quoted 5 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
Quoted 8 lines
Quoted 4 lines
It could be, but we don't have a requirement document defines the scope.
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager[JZ] One device could be split into multiple nodes with different processes running.
I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should be device scope.
Thanks
LingshanQuoted 54 lines
Quoted 54 lines
Thanks
LingshanQuoted 52 lines
Quoted 52 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 3 +++2 files changed, 11 insertions(+)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
amdgpu/amdgpu.h
index8eff6b9ebe81..45897dca802f100644drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { + struct mutex lock; + struct drm_file *owner; + bool enable; +}; + struct amdgpu_device { struct device *dev; struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; + /* df */ struct amdgpu_df df;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock); mutex_init(&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); + mutex_init(&adev->pmc_profiler.lock); /* Associate locks with lockdep classes for ordering validation */ amdgpu_lockdep_set_class(adev);@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->pci_state); kfree(adev->pcie_reset_ctx.swds_pcistate); kfree(adev->pcie_reset_ctx.swus_pcistate); + + mutex_destroy(&adev->pmc_profiler.lock); } /**
Re: [RFC 02/10] drm/amdgpu: add device-wide PMC config
Quoted 31 lines · James Zhu
Quoted 29 lines · Lingshan
Quoted 16 lines · James Zhu
Quoted 14 lines · Lingshan
Quoted 13 lines · James
AMD General
Hi, Lingshan,
Sorry to reply later! Just be back from vacation.
Yes, there is only one set of PMC registers on the device. But the minimum control scope is XCC. So, I think we should design PMC based on
Node instead of device. We need not enable the PMC on XCCs which have no PMC
data collection request.
Since the request is based on render node.Quoted 5 lines
Quoted 2 lines
They are per-device registers, so the scope should be the device, not XCC.
[JZ] where did you get this information? From what I know, Compute / Shader PMCs / RLC & SPM Control / // / / / PC Sampling are all XCC based. a are all are
For GFX11/12, the instance number of XCC is 0, therefore their
xcc_maskis 1, so the registers are per-device.
You can read these information from sysfs and debugfs.Please also take a look at KFD implementation athttps://lists.freedesktop.org/archives/amd-gfx/2026-February/138408.html
Quoted 8 lines
Quoted 2 lines
It says: multiple PMC profilers on the same device can result in corrupted counter data
[JZ] IIUC, the corruption data is with multiple processes enabled on same xcc. We still can have lock design to avoid multiple processes running on same node(same XCCs). we can run one PMC profiler on node1 only and leave other nodes on the same device have its own one only PMC profilers process running without affecting each other,.
This implementation only modifies perf_count_enable field in MQD, not touching per-XCC registers, and you have agreed that PMC registers are per-device before, so lets stick to the KFD design because it has been proven to work and this is a porting of KFD PMC.
Thanks
Lingshan
Quoted 120 lines
Quoted 120 lines
Quoted 7 lines
Quoted 4 lines
Another reason is, I assume we don't want one user to sniff another through PMC.
[JZ] if it is true, is it more easy to sniffer for per device design. the other nodes within the same device will enable PMC unexpectedly.
so we have implemented reservation/locking for PMC.
Thanks
LingshanQuoted 109 lines
Quoted 109 lines
Thanks
LingshanQuoted 106 lines
Thanks & Best Regards!
James Zhu
--------------------------------------------------------------------------------
*From:* Zhu, Lingshan<[email protected]>
*Sent:* Thursday, October 8, 2026 3:50 AM
*To:* Zhu, James<[email protected]>; Deucher, Alexander <[email protected]>; Kuehling, Felix<[email protected]> *Cc:* Huang, Ray<[email protected]>;[email protected] <amd- [email protected]>
*Subject:* Re: [RFC 02/10] drm/amdgpu: add device-wide PMC configQuoted 12 lines · James Zhu
Quoted 11 lines · Lingshan
Quoted 5 lines · James Zhu
Quoted 3 lines · Zhu Lingshan
This commit implements a device-wide PMC config
for amdgpu, which including the profiling owner,
and the profiling enablement indicator.[JZ] I think it should be render-node wide, not device-wide
Hi James,
It could be, but we don't have a requirement document defines the scope.
Quoted 8 lines
Quoted 3 lines
But normally a profiler is a device scope,
I see KFD profiler operates on all queues under the device queue manager[JZ] One device could be split into multiple nodes with different processes
running.I am wondering if this is really we want. Ben may comment on it.
Hello James,
Sorry for the late reply, it was mid-autumn festival and national holidays.
In my understanding, there is only one set of PMC registers on the device, so it should
be device scope.Thanks
LingshanQuoted 58 lines
Quoted 58 lines
Thanks
LingshanQuoted 56 lines
Quoted 56 lines
Signed-off-by Zhu Lingshan<[email protected]><mailto:[email protected]>
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 3 +++2 files changed, 11 insertions(+)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
amdgpu/amdgpu.h
index8eff6b9ebe81..45897dca802f100644drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0@@ -620,6 +620,12 @@ enum amdgpu_enforce_isolation_mode { AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, }; +struct amdgpu_pmc_profiler { + struct mutex lock; + struct drm_file *owner; + bool enable; +}; + struct amdgpu_device { struct device *dev; struct pci_dev *pdev;@@ -818,6 +824,8 @@ struct amdgpu_device {*/ struct xarray userq_doorbell_xa; + struct amdgpu_pmc_profiler pmc_profiler; + /* df */ struct amdgpu_df df;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexc924a55fd16f..74ed42e53264100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3673,6 +3673,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->pm.stable_pstate_ctx_lock); mutex_init(&adev->benchmark_mutex);mutex_init (&adev->gfx.reset_sem_mutex); + mutex_init(&adev->pmc_profiler.lock); /* Associate locks with lockdep classes for orderingvalidation */
amdgpu_lockdep_set_class(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -4244,6 +4245,8 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->pci_state); kfree(adev->pcie_reset_ctx.swds_pcistate); kfree(adev->pcie_reset_ctx.swus_pcistate); + + mutex_destroy(&adev->pmc_profiler.lock); } /**
RFC 3/10 drm/amdgpu: introduce PMC ioctl handler
In reply to Zhu LingshanThis commit introduces ioctl handler for PMC.
In this commit, the handler only performs
basic checkings, including permission and whether
user queues are enabled.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +27 -1
@@ -23,9 +23,35 @@*/ #include <linux/errno.h> +#include <linux/capability.h> #include <drm/amdgpu_drm.h> +#include "amdgpu.h" +#include "amdgpu_userq.h" #include "amdgpu_profiler.h" +static int amdgpu_profiler_check_access (struct drm_device *dev) +{ +if (!perfmon_capable ()) +return -EPERM ; + +if (!amdgpu_userq_enabled (dev)) +return -EOPNOTSUPP ; + +return 0 ; +} + +static int amdgpu_profiler_pmc (struct drm_device *dev,struct drm_file *filp, +bool enable) +{ +int ret; + + ret =amdgpu_profiler_check_access (dev); +if (ret) +return ret; + +return -EOPNOTSUPP ; +} +int amdgpu_profiler_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {struct drm_amdgpu_profiler_args *args = data;
@@ -37,7 +63,7 @@ int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *fcase AMDGPU_PROFILER_OP_RESERVE :return -EOPNOTSUPP ;case AMDGPU_PROFILER_OP_PMC : -return -EOPNOTSUPP ; +return amdgpu_profiler_pmc (dev, filp, args->perfcount_enable);default :return -EINVAL ; }
Signature · 1 line
2.55.0
RFC 4/10 drm/amdgpu: implement reservation mechanism for PMC
In reply to Zhu LingshanThis commit implements reserving (take the profiling ownership) and releasing (release the profiling ownership) of PMC.
A reservation can also be cleared by AMDGPU_PROFILER_CLEAR_RESERVATION in case the owner can no longer release it, e.g., it crashes.
Releasing is separated from reserving path by design, because the ownership needs to be kept during set_perfcount to avoid racings.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 73 +++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 3 + 3 files changed, 76 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2988,6 +2988,7 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp)amdgpu_evf_mgr_flush_suspend (&fpriv->evf_mgr);amdgpu_userq_mgr_fini (&fpriv->userq_mgr);amdgpu_evf_mgr_fini (&fpriv->evf_mgr); +amdgpu_profiler_release_device (drm_to_adev (dev), file_priv);drm_dev_exit (idx); }
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +72 -1
91 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h +3 -0
@@ -28,6 +28,9 @@#include <drm/drm_device.h> #include <drm/drm_file.h> +struct amdgpu_device ; + +int amdgpu_profiler_release_device (struct amdgpu_device *adev,struct drm_file *filp);int amdgpu_profiler_ioctl (struct drm_device *dev,void *data,struct drm_file *filp);#endif /* __AMDGPU_PROFILER_H__ */
Signature · 1 line
2.55.0
RFC 5/10 drm/amdgpu: set device-wide PMC enablement indicator
In reply to Zhu LingshanThis commit introduces a new function amdgpu_profiler_set_perfcount which sets the device-wide PMC enablement indicator.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 23 +++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2988,6 +2988,7 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp)amdgpu_evf_mgr_flush_suspend (&fpriv->evf_mgr);amdgpu_userq_mgr_fini (&fpriv->userq_mgr);amdgpu_evf_mgr_fini (&fpriv->evf_mgr); +amdgpu_profiler_set_perfcount (drm_to_adev (dev), file_priv, false);amdgpu_profiler_release_device (drm_to_adev (dev), file_priv);drm_dev_exit (idx); }
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +22 -1
@@ -77,6 +77,27 @@ static void amdgpu_profiler_clear_reservation(struct amdgpu_device *adev)mutex_unlock (&adev->pmc_profiler.lock); } +int amdgpu_profiler_set_perfcount (struct amdgpu_device *adev, +struct drm_file *filp,bool enable) +{ +int ret; + +mutex_lock (&adev->pmc_profiler.lock); + +if (adev->pmc_profiler.owner == filp) { +/* set device-wide PMC enablement bit, +* new created queues inherit it. +*/ + adev->pmc_profiler.enable = enable; + ret =0 ; + }else + ret = -EBUSY ; + +mutex_unlock (&adev->pmc_profiler.lock); + +return ret; +} +static int amdgpu_profiler_check_access (struct drm_device *dev) {if (!perfmon_capable ())
@@ -120,7 +141,7 @@ static int amdgpu_profiler_pmc(struct drm_device *dev, struct drm_file *filp,if (ret)return ret; -return -EOPNOTSUPP ; +return amdgpu_profiler_set_perfcount (drm_to_adev (dev), filp, enable); }int amdgpu_profiler_ioctl (struct drm_device *dev,void *data,struct drm_file *filp)
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h +2 -0
@@ -30,6 +30,8 @@struct amdgpu_device ; +int amdgpu_profiler_set_perfcount (struct amdgpu_device *adev,struct drm_file *filp, +bool enable);int amdgpu_profiler_release_device (struct amdgpu_device *adev,struct drm_file *filp);int amdgpu_profiler_ioctl (struct drm_device *dev,void *data,struct drm_file *filp);
Signature · 1 line
2.55.0
RFC 6/10 drm/amdgpu: GFX11: set mqd->perfcount from mqd_prop
In reply to Zhu LingshanThis commit implements a new callback set_mqd_perfcount
in struct amdgpu_mqd. This callback helps setting mqd->compute_perfcount_enable from amdgpu_mqd_prop->perfcount_enable.
This is a per-IP callback and it is NULL if an IP does not support PMC.
This commit also implements set_mqd_perfcount for GFX11.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 ++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 11 +++++++++++ 2 files changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +6 -0
@@ -479,12 +479,18 @@ struct amdgpu_mqd_prop {uint64_t ctx_save_area_addr;uint32_t ctx_save_area_size;uint32_t ctl_stack_size; +/* PMC compute_perfcount_enable that programmed into this queue's MQD */ +bool perfcount_enable; };struct amdgpu_mqd {unsigned mqd_size;int (*init_mqd)(struct amdgpu_device *adev,void *mqd,struct amdgpu_mqd_prop *p); +/* Per-IP callback to set compute_perfcount_enable, +* NULL when this IP's MQD has no perfcount_enable field. +*/ +void (*set_mqd_perfcount)(void *mqd,struct amdgpu_mqd_prop *p); };/*
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11 -0
@@ -4323,6 +4323,7 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m, mqd->header =0xC0310800 ; mqd->compute_pipelinestat_enable =0x00000001 ; + mqd->compute_perfcount_enable = prop->perfcount_enable; mqd->compute_static_thread_mgmt_se0 =0xffffffff ; mqd->compute_static_thread_mgmt_se1 =0xffffffff ; mqd->compute_static_thread_mgmt_se2 =0xffffffff ;
@@ -4459,6 +4460,14 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +static void gfx_v11_0_compute_mqd_set_perfcount (void *m, +struct amdgpu_mqd_prop *prop) +{ +struct v11_compute_mqd *mqd = m; + + mqd->compute_perfcount_enable = prop->perfcount_enable; +} +static int gfx_v11_0_kiq_init_register (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -7263,6 +7272,8 @@ static void gfx_v11_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v11_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v11_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].set_mqd_perfcount = + gfx_v11_0_compute_mqd_set_perfcount; } static void gfx_v11_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.55.0
RFC 7/10 drm/amdgpu: GFX12: set mqd->perfcount from mqd_prop
In reply to Zhu LingshanThis commit implements amdgpu_mqd->set_mqd_perfcount for GFX12, which helps setting mqd->compute_perfcount_enable from amdgpu_mqd_prop->perfcount_enable.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11 -0
@@ -3160,6 +3160,7 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m, mqd->header =0xC0310800 ; mqd->compute_pipelinestat_enable =0x00000001 ; + mqd->compute_perfcount_enable = prop->perfcount_enable; mqd->compute_static_thread_mgmt_se0 =0xffffffff ; mqd->compute_static_thread_mgmt_se1 =0xffffffff ; mqd->compute_static_thread_mgmt_se2 =0xffffffff ;
@@ -3313,6 +3314,14 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +static void gfx_v12_0_compute_mqd_set_perfcount (void *m, +struct amdgpu_mqd_prop *prop) +{ +struct v12_compute_mqd *mqd = m; + + mqd->compute_perfcount_enable = prop->perfcount_enable; +} +static int gfx_v12_0_kiq_init_register (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -5542,6 +5551,8 @@ static void gfx_v12_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v12_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v12_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].set_mqd_perfcount = + gfx_v12_0_compute_mqd_set_perfcount; } static void gfx_v12_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.55.0
RFC 8/10 drm/amdgpu: GFX12.1: set mqd->perfcount from mqd_prop
In reply to Zhu LingshanThis commit implements amdgpu_mqd->set_mqd_perfcount for GFX12.1, which helps setting mqd->compute_perfcount_enable from amdgpu_mqd_prop->perfcount_enable.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +11 -0
@@ -2170,6 +2170,7 @@ static int gfx_v12_1_compute_mqd_init(struct amdgpu_device *adev, void *m, mqd->header =0xC0310800 ; mqd->compute_pipelinestat_enable =0x00000001 ; + mqd->compute_perfcount_enable = prop->perfcount_enable; mqd->compute_static_thread_mgmt_se0 =0xffffffff ; mqd->compute_static_thread_mgmt_se1 =0xffffffff ; mqd->compute_static_thread_mgmt_se2 =0xffffffff ;
@@ -2298,6 +2299,14 @@ static int gfx_v12_1_compute_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +static void gfx_v12_1_compute_mqd_set_perfcount (void *m, +struct amdgpu_mqd_prop *prop) +{ +struct v12_1_compute_mqd *mqd = m; + + mqd->compute_perfcount_enable = prop->perfcount_enable; +} +static int gfx_v12_1_xcc_kiq_init_register (struct amdgpu_ring *ring,int xcc_id) {
@@ -4041,6 +4050,8 @@ static void gfx_v12_1_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v12_1_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v12_1_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].set_mqd_perfcount = + gfx_v12_1_compute_mqd_set_perfcount; } static void gfx_v12_1_set_user_cu_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.55.0
RFC 9/10 drm/amdgpu: implement device PMC handler
In reply to Zhu LingshanThis commit implements device PMC handler
--- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 68 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 + 3 files changed, 75 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +5 -1
@@ -95,7 +95,11 @@ int amdgpu_profiler_set_perfcount(struct amdgpu_device *adev,mutex_unlock (&adev->pmc_profiler.lock); -return ret; +if (ret) +return ret; + +/* no racings because the device was reserved by pmc_profiler.owner */ +return amdgpu_set_perfcount (adev, enable); }static int amdgpu_profiler_check_access (struct drm_device *dev)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +68 -0
74 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -0
@@ -189,6 +189,8 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev, u32 idx);int amdgpu_userq_start_sched_for_enforce_isolation (struct amdgpu_device *adev,u32 idx); + +int amdgpu_set_perfcount (struct amdgpu_device *adev,bool enable);void amdgpu_userq_reset_work (struct work_struct *work);void amdgpu_userq_pre_reset (struct amdgpu_device *adev);int amdgpu_userq_post_reset (struct amdgpu_device *adev,bool vram_lost);
Signature · 1 line
2.55.0
RFC 10/10 drm/amdgpu: set userq perf state before publish it
In reply to Zhu LingshanThis commit sets the perf state of a user queue
before publish it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +25 -2
@@ -731,6 +731,30 @@ static int amdgpu_userq_priority_permit(struct drm_file *filp,return -EACCES ; } +static int amdgpu_userq_attach (struct amdgpu_device *adev, +struct amdgpu_usermode_queue *queue, +u64 index) +{ +struct amdgpu_mqd *mqd_funcs = &adev->mqds[queue->queue_type]; +int r; + +mutex_lock (&adev->pmc_profiler.lock); + +/* set the queue PMC state based on the device PMC state */ +if (mqd_funcs->set_mqd_perfcount) { + queue->userq_prop->perfcount_enable = adev->pmc_profiler.enable; + mqd_funcs->set_mqd_perfcount (queue->mqd.cpu_ptr, + queue->userq_prop); + } + +/* attach the queue to the xarray */ + r =xa_insert_irq (&adev->userq_doorbell_xa, index, queue,GFP_KERNEL ); + +mutex_unlock (&adev->pmc_profiler.lock); + +return r; +} +static int amdgpu_userq_create (struct drm_file *filp,union drm_amdgpu_userq *args) {
@@ -831,8 +855,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)/* Update VM owner at userq submit-time for page-fault attribution. */ amdgpu_vm_set_task_info (&fpriv->vm); - r =xa_insert_irq (&adev->userq_doorbell_xa, index, queue, -GFP_KERNEL ); + r =amdgpu_userq_attach (adev, queue, index);if (r) goto clean_mqd;
Signature · 1 line
2.55.0
Hi Ben,
Please review these PMC patches for unified Kernel interface.
Thanks and Best Regards!
James Zhu
Quoted 43 lines · Zhu Lingshan
This series implements PMC support for amdgpu. Including two parts:
1) PMC Enablement
2) Profiler ReservationThe user space should take the reservation, then set PMC.
This series depends on and used new helper introduced in another series:
https://lists.freedesktop.org/archives/amd-gfx/2026-August/151692.htmlPlease help Review
Thanks!
Zhu Lingshan (10):
drm/amdgpu: implement PMC ioctl framework drm/amdgpu: add device-wide PMC config drm/amdgpu: introduce PMC ioctl handler drm/amdgpu: implement reservation mechanism for PMC drm/amdgpu: set device-wide PMC enablement indicator drm/amdgpu: GFX11: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12.1: setmqd->perfcountfrommqd_propdrm/amdgpu: implement device PMC handler drm/amdgpu: set userq perf state before publish itdrivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 + drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 166 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 38 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 95 ++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 11 ++ include/uapi/drm/amdgpu_drm.h | 36 ++++ 13 files changed, 390 insertions(+), 3 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
AMD General
For some background on my end, is this the porting over of the existing profiler work to KGD?
Ben
-----Original Message-----
From: Zhu, James <[email protected]>
Sent: Wednesday, September 23, 2026 7:02 AM
To: [email protected]; Welton, Benjamin <[email protected]>
Subject: Re: [RFC 00/10] amdgpu: implement Performance Monitor Counter support
Hi Ben,
Please review these PMC patches for unified Kernel interface.
Thanks and Best Regards!
James Zhu
Quoted 43 lines · Zhu Lingshan
This series implements PMC support for amdgpu. Including two parts:
1) PMC Enablement
2) Profiler ReservationThe user space should take the reservation, then set PMC.
This series depends on and used new helper introduced in another series:
https://lists.freedesktop.org/archives/amd-gfx/2026-August/151692.htmlPlease help Review
Thanks!
Zhu Lingshan (10):
drm/amdgpu: implement PMC ioctl framework drm/amdgpu: add device-wide PMC config drm/amdgpu: introduce PMC ioctl handler drm/amdgpu: implement reservation mechanism for PMC drm/amdgpu: set device-wide PMC enablement indicator drm/amdgpu: GFX11: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12.1: setmqd->perfcountfrommqd_propdrm/amdgpu: implement device PMC handler drm/amdgpu: set userq perf state before publish itdrivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 + drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 166 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 38 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 95 ++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 11 ++ include/uapi/drm/amdgpu_drm.h | 36 ++++ 13 files changed, 390 insertions(+), 3 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
Quoted 3 lines · Benjamin
AMD General
For some background on my end, is this the porting over of the existing profiler work to KGD?
[JZ] Yes, for profiler-PMC only. One of the main changes is from kfd device based PMC to render-node based PMC.
Quoted 61 lines
Ben
-----Original Message-----
From: Zhu, James <[email protected]>
Sent: Wednesday, September 23, 2026 7:02 AM
To: [email protected]; Welton, Benjamin <[email protected]>
Subject: Re: [RFC 00/10] amdgpu: implement Performance Monitor Counter supportHi Ben,
Please review these PMC patches for unified Kernel interface.
Thanks and Best Regards!
James Zhu
Quoted 43 lines · Zhu Lingshan
This series implements PMC support for amdgpu. Including two parts:
1) PMC Enablement
2) Profiler ReservationThe user space should take the reservation, then set PMC.
This series depends on and used new helper introduced in another series:
https://lists.freedesktop.org/archives/amd-gfx/2026-August/151692.htmlPlease help Review
Thanks!
Zhu Lingshan (10):
drm/amdgpu: implement PMC ioctl framework drm/amdgpu: add device-wide PMC config drm/amdgpu: introduce PMC ioctl handler drm/amdgpu: implement reservation mechanism for PMC drm/amdgpu: set device-wide PMC enablement indicator drm/amdgpu: GFX11: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12.1: setmqd->perfcountfrommqd_propdrm/amdgpu: implement device PMC handler drm/amdgpu: set userq perf state before publish itdrivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 + drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 166 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 38 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 95 ++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 11 ++ include/uapi/drm/amdgpu_drm.h | 36 ++++ 13 files changed, 390 insertions(+), 3 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
Quoted 5 lines · Benjamin
[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
AMD General
For some background on my end, is this the porting over of the existing profiler work to KGD?
Hello Ben,
Yes, it is a porting from KFD because I don't have any other documents.
However I still made some improvements like separate reservation from PMC enabling operation to avoid some corner cases.
Thanks
Lingshan
Quoted 61 lines
Ben
-----Original Message-----
From: Zhu, James <[email protected]>
Sent: Wednesday, September 23, 2026 7:02 AM
To: [email protected]; Welton, Benjamin <[email protected]>
Subject: Re: [RFC 00/10] amdgpu: implement Performance Monitor Counter supportHi Ben,
Please review these PMC patches for unified Kernel interface.
Thanks and Best Regards!
James Zhu
Quoted 43 lines · Zhu Lingshan
This series implements PMC support for amdgpu. Including two parts:
1) PMC Enablement
2) Profiler ReservationThe user space should take the reservation, then set PMC.
This series depends on and used new helper introduced in another series:
https://lists.freedesktop.org/archives/amd-gfx/2026-August/151692.htmlPlease help Review
Thanks!
Zhu Lingshan (10):
drm/amdgpu: implement PMC ioctl framework drm/amdgpu: add device-wide PMC config drm/amdgpu: introduce PMC ioctl handler drm/amdgpu: implement reservation mechanism for PMC drm/amdgpu: set device-wide PMC enablement indicator drm/amdgpu: GFX11: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12: setmqd->perfcountfrommqd_propdrm/amdgpu: GFX12.1: setmqd->perfcountfrommqd_propdrm/amdgpu: implement device PMC handler drm/amdgpu: set userq perf state before publish itdrivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 + drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 166 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 38 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 95 ++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 11 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 11 ++ include/uapi/drm/amdgpu_drm.h | 36 ++++ 13 files changed, 390 insertions(+), 3 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h