drm/amdkfd: Track SDMA utilization per process
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: Track SDMA utilization per process
Track SDMA usage on a per process basis and report it through sysfs. The value in the sysfs file indicates the amount of time SDMA has been in-use by this process since the creation of the process. This value is in microsecond granularity.
v2:
- Remove unnecessary checks for pdd is kfd_procfs_show().
- Make counter part of the kfd_sdma_activity_handler_workarea structure.
Signed-off-by Mukul Joshi <[email protected]>
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 57 ++++++++ .../drm/amd/amdkfd/kfd_device_queue_manager.h | 2 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 16 ++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 130 ++++++++++++++++-- 4 files changed, 191 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +57 -0
@@ -153,6 +153,52 @@ void decrement_queue_count(struct device_queue_manager *dqm, dqm->active_cp_queue_count--; } +int read_sdma_queue_counter (struct queue *q,uint64_t *val) +{ +int ret; +uint64_t tmp =0 ; + +if (!q || !val) +return -EINVAL ; +/* +* SDMA activity counter is stored at queue's RPTR + 0x8 location. +*/ +if (!access_ok ((const void __user *)((uint64_t )q->properties.read_ptr + +sizeof (uint64_t )),sizeof (uint64_t ))) { +pr_err ("Can't access sdma queue activity counter\n" ); +return -EFAULT ; + } + + ret =get_user (tmp, (uint64_t *)((uint64_t )(q->properties.read_ptr) + +sizeof (uint64_t ))); +if (!ret) { + *val = tmp; + } + +return ret; +} + +static int update_sdma_queue_past_activity_stats (struct kfd_process_device *pdd, +struct queue *q) +{ +int ret; +uint64_t val =0 ; + +if (!pdd) +return -ENODEV ; + + ret =read_sdma_queue_counter (q, &val); +if (ret) { +pr_err ("Failed to read SDMA queue counter for queue: %d\n" , + q->properties.queue_id); +return ret; + } + +WRITE_ONCE (pdd->sdma_past_activity_counter, pdd->sdma_past_activity_counter + val); + +return ret; +} +static int allocate_doorbell (struct qcm_process_device *qpd,struct queue *q) {struct kfd_dev *dev = qpd->dqm->dev;
@@ -487,6 +533,12 @@ static int destroy_queue_nocpsch_locked(struct device_queue_manager *dqm,if (retval == -ETIME ) qpd->reset_wavefronts = true; +/* Get the SDMA queue stats */ +if ((q->properties.type ==KFD_QUEUE_TYPE_SDMA ) || + (q->properties.type ==KFD_QUEUE_TYPE_SDMA_XGMI )) { +update_sdma_queue_past_activity_stats (qpd_to_pdd (qpd), q); + } + mqd_mgr->free_mqd (mqd_mgr, q->mqd, q->mqd_mem_obj);list_del (&q->list);
@@ -1468,6 +1520,11 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm, } } +/* Get the SDMA queue stats */ +if ((q->properties.type ==KFD_QUEUE_TYPE_SDMA ) || + (q->properties.type ==KFD_QUEUE_TYPE_SDMA_XGMI )) { +update_sdma_queue_past_activity_stats (qpd_to_pdd (qpd), q); + }/* * Unconditionally decrement this counter, regardless of the queue's * type
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +2 -0
@@ -251,4 +251,6 @@ static inline void dqm_unlock(struct device_queue_manager *dqm) mutex_unlock(&dqm->lock_hidden); } +int read_sdma_queue_counter (struct queue *q,uint64_t *val); +#endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +14 -2
@@ -633,7 +633,14 @@ enum kfd_pdd_bound { PDD_BOUND_SUSPENDED, }; -#define MAX_VRAM_FILENAME_LEN 11 +#define MAX_SYSFS_FILENAME_LEN 11 + +/* +* SDMA counter runs at 100MHz frequency. +* We display SDMA activity in microsecond granularity in sysfs. +* As a result, the divisor is 100. +*/ +#define SDMA_ACTIVITY_DIVISOR 100/* Data that is per-process-per device. */ struct kfd_process_device {
@@ -681,7 +688,12 @@ struct kfd_process_device {/* VRAM usage */ uint64_t vram_usage;struct attribute attr_vram; -char vram_filename[MAX_VRAM_FILENAME_LEN ]; +char vram_filename[MAX_SYSFS_FILENAME_LEN ]; + +/* SDMA activity tracking */ +uint64_t sdma_past_activity_counter; +struct attribute attr_sdma; +char sdma_filename[MAX_SYSFS_FILENAME_LEN ]; };#define qpd_to_pdd (x) container_of(x, struct kfd_process_device, qpd)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +118 -12
185 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx