amdgpu: Add amdgpu profiler IOCTL functions
Subsystems (2)
PATCH v2 1/1 amdgpu: Add amdgpu profiler IOCTL functions
to support PMC, PCSampling, SPM etc.
--- amdgpu/amdgpu.h | 8 +++++++ amdgpu/amdgpu_profiler.c | 46 ++++++++++++++++++++++++++++++++++++++++ amdgpu/meson.build | 2 +- include/drm/amdgpu_drm.h | 19 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 amdgpu/amdgpu_profiler.c
amdgpu/amdgpu.h +8 -0
@@ -2072,6 +2072,14 @@ int amdgpu_userq_signal(amdgpu_device_handle dev,int amdgpu_userq_wait (amdgpu_device_handle dev,struct drm_amdgpu_userq_wait *wait_data); +/** +* Acquire profiler version +* \param dev - \c [in] device handle +* +* \return 0 on success otherwise POSIX Error code +*/ +int amdgpu_profiler_version (amdgpu_device_handle dev); + #ifdef __cplusplus }#endif
amdgpu/amdgpu_profiler.c new file +46 -0
46 lines not on this page · raw message
amdgpu/meson.build +1 -1
@@ -27,7 +27,7 @@ libdrm_amdgpu = library( files( 'amdgpu_asic_id.c', 'amdgpu_bo.c', 'amdgpu_cs.c', 'amdgpu_device.c', 'amdgpu_gpu_info.c', 'amdgpu_vamgr.c', 'amdgpu_vm.c', 'handle_table.c', - 'amdgpu_userq.c', + 'amdgpu_userq.c', 'amdgpu_profiler.c', ), config_file, ],
include/drm/amdgpu_drm.h +19 -0
@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_PROFILER 0x20#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)
@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains
@@ -1616,6 +1618,23 @@ struct drm_amdgpu_info_gpuvm_fault {#define AMDGPU_FAMILY_GC_11_5_0 150/* GC 11.5.0 */ #define AMDGPU_FAMILY_GC_12_0_0 152/* GC 12.0.0 */ +/* +* Supported Profiler Operations +*/ +enum drm_amdgpu_profiler_ops { +AMDGPU_PROFILER_VERSION =0 , +}; + +struct drm_amdgpu_profiler_args { +__u32 op;/* amdgpu_profiler_op */ +union { +__u32 version;/* AMDGPU_PROFILER_VERSION_NUM +* lower 16 bit: minor +* higher 16 bit: major +*/ + }; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.34.1
Ping ...
Quoted 139 lines · James Zhu
to support PMC, PCSampling, SPM etc.
Signed-off-by James Zhu <[email protected]>--- amdgpu/amdgpu.h | 8 +++++++ amdgpu/amdgpu_profiler.c | 46 ++++++++++++++++++++++++++++++++++++++++ amdgpu/meson.build | 2 +- include/drm/amdgpu_drm.h | 19 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-)create mode 100644
amdgpu/amdgpu_profiler.camdgpu/amdgpu.h +8
-0@@ -2072,6 +2072,14 @@ int amdgpu_userq_signal(amdgpu_device_handle dev,int amdgpu_userq_wait (amdgpu_device_handle dev,struct drm_amdgpu_userq_wait *wait_data); +/** +* Acquire profiler version +* \param dev - \c [in] device handle +* +* \return 0 on success otherwise POSIX Error code +*/ +int amdgpu_profiler_version (amdgpu_device_handle dev); + #ifdef __cplusplus }#endif amdgpu/amdgpu_profiler.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 <string.h> +#include <errno.h> +#include "xf86drm.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +drm_public int +amdgpu_profiler_version (amdgpu_device_handle dev) +{ +int ret; +struct drm_amdgpu_profiler_args user_arg; + +if (!dev) +return -EINVAL ; + +memset (&user_arg,0 ,sizeof (user_arg)); + user_arg.op =AMDGPU_PROFILER_VERSION ; + + ret =drmCommandWriteRead (dev->fd,DRM_AMDGPU_PROFILER , + &user_arg,sizeof (user_arg)); + +return ret; +}amdgpu/meson.build +1
-1@@ -27,7 +27,7 @@ libdrm_amdgpu = library( files( 'amdgpu_asic_id.c', 'amdgpu_bo.c', 'amdgpu_cs.c', 'amdgpu_device.c', 'amdgpu_gpu_info.c', 'amdgpu_vamgr.c', 'amdgpu_vm.c', 'handle_table.c', - 'amdgpu_userq.c', + 'amdgpu_userq.c', 'amdgpu_profiler.c', ), config_file, ],include/drm/amdgpu_drm.h +19
-0@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_PROFILER 0x20#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)@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains @@ -1616,6 +1618,23 @@ struct drm_amdgpu_info_gpuvm_fault {#define AMDGPU_FAMILY_GC_11_5_0 150/* GC 11.5.0 */ #define AMDGPU_FAMILY_GC_12_0_0 152/* GC 12.0.0 */ +/* +* Supported Profiler Operations +*/ +enum drm_amdgpu_profiler_ops { +AMDGPU_PROFILER_VERSION =0 , +}; + +struct drm_amdgpu_profiler_args { +__u32 op;/* amdgpu_profiler_op */ +union { +__u32 version;/* AMDGPU_PROFILER_VERSION_NUM +* lower 16 bit: minor +* higher 16 bit: major +*/ + }; +}; +#if defined(__cplusplus) }#endif
Quoted 126 lines · James Zhu
to support PMC, PCSampling, SPM etc.
Signed-off-by James Zhu <[email protected]>--- amdgpu/amdgpu.h | 8 +++++++ amdgpu/amdgpu_profiler.c | 46 ++++++++++++++++++++++++++++++++++++++++ amdgpu/meson.build | 2 +- include/drm/amdgpu_drm.h | 19 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 amdgpu/amdgpu_profiler.camdgpu/amdgpu.h +8
-0@@ -2072,6 +2072,14 @@ int amdgpu_userq_signal(amdgpu_device_handle dev,int amdgpu_userq_wait (amdgpu_device_handle dev,struct drm_amdgpu_userq_wait *wait_data); +/** +* Acquire profiler version +* \param dev - \c [in] device handle +* +* \return 0 on success otherwise POSIX Error code +*/ +int amdgpu_profiler_version (amdgpu_device_handle dev); + #ifdef __cplusplus }#endif amdgpu/amdgpu_profiler.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 <string.h> +#include <errno.h> +#include "xf86drm.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +drm_public int +amdgpu_profiler_version (amdgpu_device_handle dev) +{ +int ret; +struct drm_amdgpu_profiler_args user_arg; + +if (!dev) +return -EINVAL ; + +memset (&user_arg,0 ,sizeof (user_arg)); + user_arg.op =AMDGPU_PROFILER_VERSION ; + + ret =drmCommandWriteRead (dev->fd,DRM_AMDGPU_PROFILER , + &user_arg,sizeof (user_arg)); + +return ret; +}amdgpu/meson.build +1
-1@@ -27,7 +27,7 @@ libdrm_amdgpu = library( files( 'amdgpu_asic_id.c', 'amdgpu_bo.c', 'amdgpu_cs.c', 'amdgpu_device.c', 'amdgpu_gpu_info.c', 'amdgpu_vamgr.c', 'amdgpu_vm.c', 'handle_table.c', - 'amdgpu_userq.c', + 'amdgpu_userq.c', 'amdgpu_profiler.c', ), config_file, ],include/drm/amdgpu_drm.h +8
-0@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_PROFILER 0x20#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)@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains @@ -1616,6 +1618,23 @@ struct drm_amdgpu_info_gpuvm_fault {#define AMDGPU_FAMILY_GC_11_5_0 150/* GC 11.5.0 */ #define AMDGPU_FAMILY_GC_12_0_0 152/* GC 12.0.0 */ +/* +* Supported Profiler Operations +*/ +enum drm_amdgpu_profiler_ops { +AMDGPU_PROFILER_VERSION =0 , +};
include/drm/amdgpu_drm.h struct drm_amdgpu_info_gpuvm_fault { · line 1636
Quoted 10 lines
include/drm/amdgpu_drm.h +10
-0+ +struct drm_amdgpu_profiler_args { +__u32 op;/* amdgpu_profiler_op */ +union { +__u32 version;/* AMDGPU_PROFILER_VERSION_NUM +* lower 16 bit: minor +* higher 16 bit: major +*/ + }; +};
I think this seems fine. I think we'd need to see what the other opcodes would look like. What is the version query used for? Can you provide an example of how the profiler would use this interface for actually profiling a job?
Alex
Quoted 7 lines
include/drm/amdgpu_drm.h +1
-1+#if defined(__cplusplus) }#endif --2.34.1
Hi Alex,
Thanks! Answer in line.
Best Regards!
James Zhu
Quoted 132 lines · Alex Deucher
Quoted 131 lines · James Zhu
to support PMC, PCSampling, SPM etc.
Signed-off-by James Zhu <[email protected]>--- amdgpu/amdgpu.h | 8 +++++++ amdgpu/amdgpu_profiler.c | 46 ++++++++++++++++++++++++++++++++++++++++ amdgpu/meson.build | 2 +- include/drm/amdgpu_drm.h | 19 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-)create mode 100644
amdgpu/amdgpu_profiler.camdgpu/amdgpu.h +8
-0@@ -2072,6 +2072,14 @@ int amdgpu_userq_signal(amdgpu_device_handle dev,int amdgpu_userq_wait (amdgpu_device_handle dev,struct drm_amdgpu_userq_wait *wait_data); +/** +* Acquire profiler version +* \param dev - \c [in] device handle +* +* \return 0 on success otherwise POSIX Error code +*/ +int amdgpu_profiler_version (amdgpu_device_handle dev); + #ifdef __cplusplus }#endif amdgpu/amdgpu_profiler.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 <string.h> +#include <errno.h> +#include "xf86drm.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +drm_public int +amdgpu_profiler_version (amdgpu_device_handle dev) +{ +int ret; +struct drm_amdgpu_profiler_args user_arg; + +if (!dev) +return -EINVAL ; + +memset (&user_arg,0 ,sizeof (user_arg)); + user_arg.op =AMDGPU_PROFILER_VERSION ; + + ret =drmCommandWriteRead (dev->fd,DRM_AMDGPU_PROFILER , + &user_arg,sizeof (user_arg)); + +return ret; +}amdgpu/meson.build +1
-1@@ -27,7 +27,7 @@ libdrm_amdgpu = library( files( 'amdgpu_asic_id.c', 'amdgpu_bo.c', 'amdgpu_cs.c', 'amdgpu_device.c', 'amdgpu_gpu_info.c', 'amdgpu_vamgr.c', 'amdgpu_vm.c', 'handle_table.c', - 'amdgpu_userq.c', + 'amdgpu_userq.c', 'amdgpu_profiler.c', ), config_file, ],include/drm/amdgpu_drm.h +14
-0@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_PROFILER 0x20#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)@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains @@ -1616,6 +1618,23 @@ struct drm_amdgpu_info_gpuvm_fault {#define AMDGPU_FAMILY_GC_11_5_0 150/* GC 11.5.0 */ #define AMDGPU_FAMILY_GC_12_0_0 152/* GC 12.0.0 */ +/* +* Supported Profiler Operations +*/ +enum drm_amdgpu_profiler_ops { +AMDGPU_PROFILER_VERSION =0 , +}; + +struct drm_amdgpu_profiler_args { +__u32 op;/* amdgpu_profiler_op */ +union { +__u32 version;/* AMDGPU_PROFILER_VERSION_NUM +* lower 16 bit: minor
Quoted 8 lines
include/drm/amdgpu_drm.h struct drm_amdgpu_info_gpuvm_fault { · line 1636
Quoted 4 lines
include/drm/amdgpu_drm.h +4
-0+* higher 16 bit: major +*/ + }; +};I think this seems fine. I think we'd need to see what the other opcodes would look like. What is the version query used for? Can you provide an example of how the profiler would use this interface for actually profiling a job?
[JZ] Profiler team requests this to track some profiler internal changes to
conduct profiler version control.
The op will include PMC, PC Sampling and SPM so far.
Quoted 10 lines
Alex
Quoted 7 lines
include/drm/amdgpu_drm.h +1
-1+#if defined(__cplusplus) }#endif --2.34.1
Quoted 151 lines · James Zhu
Hi Alex,
Thanks! Answer in line.
Best Regards!
James Zhu
Quoted 132 lines · Alex Deucher
Quoted 131 lines · James Zhu
to support PMC, PCSampling, SPM etc.
Signed-off-by James Zhu <[email protected]>--- amdgpu/amdgpu.h | 8 +++++++ amdgpu/amdgpu_profiler.c | 46 ++++++++++++++++++++++++++++++++++++++++ amdgpu/meson.build | 2 +- include/drm/amdgpu_drm.h | 19 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-)create mode 100644
amdgpu/amdgpu_profiler.camdgpu/amdgpu.h +8
-0@@ -2072,6 +2072,14 @@ int amdgpu_userq_signal(amdgpu_device_handle dev,int amdgpu_userq_wait (amdgpu_device_handle dev,struct drm_amdgpu_userq_wait *wait_data); +/** +* Acquire profiler version +* \param dev - \c [in] device handle +* +* \return 0 on success otherwise POSIX Error code +*/ +int amdgpu_profiler_version (amdgpu_device_handle dev); + #ifdef __cplusplus }#endif amdgpu/amdgpu_profiler.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 <string.h> +#include <errno.h> +#include "xf86drm.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +drm_public int +amdgpu_profiler_version (amdgpu_device_handle dev) +{ +int ret; +struct drm_amdgpu_profiler_args user_arg; + +if (!dev) +return -EINVAL ; + +memset (&user_arg,0 ,sizeof (user_arg)); + user_arg.op =AMDGPU_PROFILER_VERSION ; + + ret =drmCommandWriteRead (dev->fd,DRM_AMDGPU_PROFILER , + &user_arg,sizeof (user_arg)); + +return ret; +}amdgpu/meson.build +1
-1@@ -27,7 +27,7 @@ libdrm_amdgpu = library( files( 'amdgpu_asic_id.c', 'amdgpu_bo.c', 'amdgpu_cs.c', 'amdgpu_device.c', 'amdgpu_gpu_info.c', 'amdgpu_vamgr.c', 'amdgpu_vm.c', 'handle_table.c', - 'amdgpu_userq.c', + 'amdgpu_userq.c', 'amdgpu_profiler.c', ), config_file, ],include/drm/amdgpu_drm.h +14
-0@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_PROFILER 0x20#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)@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains @@ -1616,6 +1618,23 @@ struct drm_amdgpu_info_gpuvm_fault {#define AMDGPU_FAMILY_GC_11_5_0 150/* GC 11.5.0 */ #define AMDGPU_FAMILY_GC_12_0_0 152/* GC 12.0.0 */ +/* +* Supported Profiler Operations +*/ +enum drm_amdgpu_profiler_ops { +AMDGPU_PROFILER_VERSION =0 , +}; + +struct drm_amdgpu_profiler_args { +__u32 op;/* amdgpu_profiler_op */ +union { +__u32 version;/* AMDGPU_PROFILER_VERSION_NUM +* lower 16 bit: minor Quoted 8 lines
include/drm/amdgpu_drm.h struct drm_amdgpu_info_gpuvm_fault { · line 1636
Quoted 4 lines
include/drm/amdgpu_drm.h +4
-0+* higher 16 bit: major +*/ + }; +};I think this seems fine. I think we'd need to see what the other opcodes would look like. What is the version query used for? Can you provide an example of how the profiler would use this interface for actually profiling a job?
Quoted 5 lines
[JZ] Profiler team requests this to track some profiler internal changes to
conduct profiler version control.
The op will include PMC, PC Sampling and SPM so far.
That makes sense, but I don't think there is much to review here until we know what those interfaces will look like. Also note that even if the kernel driver supports a newer interface, it needs to continue to support older interface versions for backwards compatibility.
Alex
Quoted 11 lines
Quoted 11 lines
Alex
Quoted 7 lines
include/drm/amdgpu_drm.h +1
-1+#if defined(__cplusplus) }#endif --2.34.1
Quoted 152 lines · Alex Deucher
Quoted 151 lines · James Zhu
Hi Alex,
Thanks! Answer in line.
Best Regards!
James Zhu
Quoted 132 lines · Alex Deucher
Quoted 131 lines · James Zhu
to support PMC, PCSampling, SPM etc.
Signed-off-by James Zhu <[email protected]>--- amdgpu/amdgpu.h | 8 +++++++ amdgpu/amdgpu_profiler.c | 46 ++++++++++++++++++++++++++++++++++++++++ amdgpu/meson.build | 2 +- include/drm/amdgpu_drm.h | 19 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-)create mode 100644
amdgpu/amdgpu_profiler.camdgpu/amdgpu.h +8
-0@@ -2072,6 +2072,14 @@ int amdgpu_userq_signal(amdgpu_device_handle dev,int amdgpu_userq_wait (amdgpu_device_handle dev,struct drm_amdgpu_userq_wait *wait_data); +/** +* Acquire profiler version +* \param dev - \c [in] device handle +* +* \return 0 on success otherwise POSIX Error code +*/ +int amdgpu_profiler_version (amdgpu_device_handle dev); + #ifdef __cplusplus }#endif amdgpu/amdgpu_profiler.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 <string.h> +#include <errno.h> +#include "xf86drm.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +drm_public int +amdgpu_profiler_version (amdgpu_device_handle dev) +{ +int ret; +struct drm_amdgpu_profiler_args user_arg; + +if (!dev) +return -EINVAL ; + +memset (&user_arg,0 ,sizeof (user_arg)); + user_arg.op =AMDGPU_PROFILER_VERSION ; + + ret =drmCommandWriteRead (dev->fd,DRM_AMDGPU_PROFILER , + &user_arg,sizeof (user_arg)); + +return ret; +}amdgpu/meson.build +1
-1@@ -27,7 +27,7 @@ libdrm_amdgpu = library( files( 'amdgpu_asic_id.c', 'amdgpu_bo.c', 'amdgpu_cs.c', 'amdgpu_device.c', 'amdgpu_gpu_info.c', 'amdgpu_vamgr.c', 'amdgpu_vm.c', 'handle_table.c', - 'amdgpu_userq.c', + 'amdgpu_userq.c', 'amdgpu_profiler.c', ), config_file, ],include/drm/amdgpu_drm.h +14
-0@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_PROFILER 0x20#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)@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains @@ -1616,6 +1618,23 @@ struct drm_amdgpu_info_gpuvm_fault {#define AMDGPU_FAMILY_GC_11_5_0 150/* GC 11.5.0 */ #define AMDGPU_FAMILY_GC_12_0_0 152/* GC 12.0.0 */ +/* +* Supported Profiler Operations +*/ +enum drm_amdgpu_profiler_ops { +AMDGPU_PROFILER_VERSION =0 , +}; + +struct drm_amdgpu_profiler_args { +__u32 op;/* amdgpu_profiler_op */ +union { +__u32 version;/* AMDGPU_PROFILER_VERSION_NUM +* lower 16 bit: minor Quoted 8 lines
include/drm/amdgpu_drm.h struct drm_amdgpu_info_gpuvm_fault { · line 1636
Quoted 4 lines
include/drm/amdgpu_drm.h +4
-0+* higher 16 bit: major +*/ + }; +};I think this seems fine. I think we'd need to see what the other opcodes would look like. What is the version query used for? Can you provide an example of how the profiler would use this interface for actually profiling a job?
[JZ] Profiler team requests this to track some profiler internal changes to
Quoted 7 lines
Quoted 3 lines
conduct profiler version control.
The op will include PMC, PC Sampling and SPM so far.
That makes sense, but I don't think there is much to review here until we know what those interfaces will look like. Also note that even if the kernel driver supports a newer interface, it needs to continue to support older interface versions for backwards compatibility.
[JZ] Since ioctl interface is changed, user mode side needs update also.
If they open kfd interface, it will follow old version control. if they open
amdgpu interface, then it will update to new version control.
This is drm portion,and mostly relys on kernel portion. [PATCH v2] drm/amdgpu/uapi: add profiler interface needs more review on profiler interface implementation which
is based on device/XCP with out process embedded.
Thanks!
Quoted 12 lines
Alex
Quoted 9 lines
Quoted 9 lines
Alex
Quoted 7 lines
include/drm/amdgpu_drm.h +1
-1+#if defined(__cplusplus) }#endif --2.34.1