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.
Zhu Lingshan (12):
drm/amdgpu: introduce amdgpu_lookup_queue_by_doorbell drm/amdgpu: introduce new helper amdgpu_userq_xa_find 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 | 173 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 4 + 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 | 37 +++- 13 files changed, 470 insertions(+), 4 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.53.0
PATCH 1/12 drm/amdgpu: introduce amdgpu_lookup_queue_by_doorbell
This commit introduces a new helperamdgpu_lookup_queue_by_doorbell which helps
look up a user queue with the given doorbell id
in a xarray.
This function takes a kref of the user space queue.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 30 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 ++ 2 files changed, 32 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +30 -0
@@ -617,6 +617,36 @@ struct amdgpu_usermode_queue *amdgpu_userq_get(struct amdgpu_userq_mgr *uq_mgr,return queue; } +/** +* amdgpu_lookup_queue_by_doorbell - look up a user queue by doorbell +* @xa: user queue XArray indexed by doorbell +* @doorbell: doorbell index +* +* Return: A queue with the doorbell indexed, or NULL if no such a queue found. +* +* This function increases kref of the queue, the caller +* must release the reference with amdgpu_userq_put(). +*/ +struct amdgpu_usermode_queue * +amdgpu_lookup_queue_by_doorbell (struct xarray *xa,u32 doorbell) +{ +struct amdgpu_usermode_queue *queue; +unsigned long flags; + +xa_lock_irqsave (xa, flags); + queue =xa_load (xa, doorbell); +if (!queue) + goto out_unlock; + +if (!kref_get_unless_zero (&queue->refcount)) + queue =NULL ; + +out_unlock: +xa_unlock_irqrestore (xa, flags); + +return queue; +} +void amdgpu_userq_put (struct amdgpu_usermode_queue *queue) {if (queue)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -0
@@ -152,6 +152,8 @@ struct amdgpu_db_info { };struct amdgpu_usermode_queue *amdgpu_userq_get (struct amdgpu_userq_mgr *uq_mgr,u32 qid); +struct amdgpu_usermode_queue * +amdgpu_lookup_queue_by_doorbell (struct xarray *xa,u32 doorbell);void amdgpu_userq_put (struct amdgpu_usermode_queue *queue);int amdgpu_userq_ioctl (struct drm_device *dev,void *data,struct drm_file *filp);
Signature · 1 line
2.53.0
PATCH 2/12 drm/amdgpu: introduce new helper amdgpu_userq_xa_find
In reply to Zhu LingshanThis commit introduces a new helper amdgpu_userq_xa_find. This helper finds a queue from a XArray which has the lowest index that is at least the given index, and hold its kref.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +48 -0
@@ -653,6 +653,54 @@ void amdgpu_userq_put(struct amdgpu_usermode_queue *queue)kref_put (&queue->refcount, amdgpu_userq_kref_destroy); } +/** +* amdgpu_userq_xa_find - search the XArray for a queue +* @xa: user queue XArray +* @index: first index to search, updated by every iteration of the search +* +* Return: a queue which has the lowest index that is at least @index, +* or NULL when no queue was found. +* +* The caller must release the kref of a queue with amdgpu_userq_put() after use. +*/ +static struct amdgpu_usermode_queue * +amdgpu_userq_xa_find (struct xarray *xa,unsigned long *index) +{ +struct amdgpu_usermode_queue *queue; +unsigned long flags; + +xa_lock_irqsave (xa, flags); + queue =xa_find (xa, index,ULONG_MAX ,XA_PRESENT ); +while (queue) { +/* +* If found a queue but failed to get a kref, +* it means the queue is in destruction process, +* so skip it by continuing the loop. +* +* If get a kref of the queue, break the loop and return it. +*/ +if (kref_get_unless_zero (&queue->refcount)) +break ; + +/* +* If the index is ULONG_MAX, we have reached the end of the XArray. +* Break the loop and return NULL because ULONG_MAX + 1 = 0, +* which is the start of the XArray. +*/ +if (*index ==ULONG_MAX ) { + queue =NULL ; +break ; + } + + (*index)++; + queue =xa_find (xa, index,ULONG_MAX ,XA_PRESENT ); + } + +xa_unlock_irqrestore (xa, flags); + +return queue; +} +static int amdgpu_userq_priority_permit (struct drm_file *filp,int priority) {
Signature · 1 line
2.53.0
PATCH 3/12 drm/amdgpu: implement PMC ioctl framework
In reply to Zhu LingshanThis 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 | 37 +++++++++++++++- 5 files changed, 116 insertions(+), 2 deletions(-) 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_trap.o amdgpu_events.o + amdgpu_wb.o amdgpu_trap.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_trap.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 -1
@@ -60,7 +60,7 @@ extern "C" {#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19#define DRM_AMDGPU_PROC_OPTIONS 0x1A#define DRM_AMDGPU_TRAP 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)#define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
@@ -83,6 +83,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_TRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_TRAP, union drm_amdgpu_trap) +#define DRM_IOCTL_AMDGPU_PROFILER DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROFILER, struct drm_amdgpu_profiler_args)/** * DOC: memory domains
@@ -1821,6 +1822,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.53.0
PATCH 4/12 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.53.0
PATCH 5/12 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.53.0
PATCH 6/12 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.53.0
PATCH 7/12 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.53.0
PATCH 8/12 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
@@ -480,12 +480,18 @@ struct amdgpu_mqd_prop {uint32_t ctx_save_area_size;uint32_t ctl_stack_size;bool modify; +/* 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
@@ -4326,6 +4326,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 ;
@@ -4466,6 +4467,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;
@@ -7270,6 +7279,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.53.0
Re: [PATCH 08/12] drm/amdgpu: GFX11: set mqd->perfcount from mqd_prop
Quoted 27 lines · Zhu Lingshan
This commit implements a new callback
set_mqd_perfcount
in structamdgpu_mqd. This callback helps settingmqd->compute_perfcount_enablefromamdgpu_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_perfcountfor GFX11.Signed-off-by Zhu Lingshan <[email protected]>Reviewed-by Benjamin Welton <[email protected]>--- 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 +2
-0@@ -480,12 +480,18 @@ struct amdgpu_mqd_prop {uint32_t ctx_save_area_size;uint32_t ctl_stack_size;bool modify; +/* PMC compute_perfcount_enable that programmed into this queue's MQD */ +bool perfcount_enable;
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h struct amdgpu_mqd_prop { · line 494
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +4
-0};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);
Rather than adding a new callback, just route the update via init_mqd similar to what Jesse did for the modify queue interface.
Alex
Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +0
-0};/* drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-1@@ -4326,6 +4326,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 ;@@ -4466,6 +4467,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;@@ -7270,6 +7279,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, --2.53.0
Re: [PATCH 08/12] drm/amdgpu: GFX11: set mqd->perfcount from mqd_prop
Quoted 29 lines · Alex Deucher
Quoted 28 lines · Zhu Lingshan
This commit implements a new callback
set_mqd_perfcount
in structamdgpu_mqd. This callback helps settingmqd->compute_perfcount_enablefromamdgpu_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_perfcountfor GFX11.Signed-off-by Zhu Lingshan <[email protected]>Reviewed-by Benjamin Welton <[email protected]>--- 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 +2
-0@@ -480,12 +480,18 @@ struct amdgpu_mqd_prop {uint32_t ctx_save_area_size;uint32_t ctl_stack_size;bool modify; +/* PMC compute_perfcount_enable that programmed into this queue's MQD */ +bool perfcount_enable; };
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h struct amdgpu_mqd_prop { · line 494
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +4
-0struct 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);Rather than adding a new callback, just route the update via
init_mqdsimilar to what Jesse did for the modify queue interface.
Thanks Alex, I will work on this.
Thanks
Lingshan
Quoted 45 lines
Alex
Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +0
-0};/* drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-1@@ -4326,6 +4326,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 ;@@ -4466,6 +4467,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;@@ -7270,6 +7279,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, --2.53.0
PATCH 9/12 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
@@ -3163,6 +3163,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 ;
@@ -3318,6 +3319,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;
@@ -5547,6 +5556,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.53.0
PATCH 10/12 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.53.0
PATCH 11/12 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
@@ -180,6 +180,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.53.0
PATCH 12/12 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
@@ -716,6 +716,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) {
@@ -815,8 +839,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.53.0