Support Host Trap Sampling for gfx941/gfx942
Subsystems (3)
v3 cover Support Host Trap Sampling for gfx941/gfx942
PC sampling is a form of software profiling, where the threads of an application are periodically interrupted and the program counter that the threads are currently attempting to execute is saved out for profiling.
David Yat Sin (5):
drm/amdkfd/kfd_ioctl: add pc sampling support drm/amdkfd: add pc sampling support
drm/amdkfd: enable pc sampling query drm/amdkfd: enable pc sampling create drm/amdkfd: set debug trap bit when enabling PC Sampling
James Zhu (19):
drm/amdkfd: add pc sampling mutex
drm/amdkfd: add trace_id return
drm/amdkfd: check pcs_entry valid
drm/amdkfd: enable pc sampling destroy
drm/amdkfd: add interface to trigger pc sampling trap drm/amdkfd: trigger pc sampling trap for gfx v9 drm/amdkfd/gfx9: enable host trap
drm/amdgpu: use trapID 4 for host trap
drm/amdgpu: add sq host trap status check
drm/amdkfd: trigger pc sampling trap for arcturus drm/amdkfd: trigger pc sampling trap for aldebaran drm/amdkfd: use bit operation set debug trap
drm/amdkfd: add setting trap pc sampling flag
drm/amdkfd: enable pc sampling stop
drm/amdkfd: add queue remapping
drm/amdkfd: enable pc sampling start
drm/amdkfd: add pc sampling thread to trigger trap drm/amdkfd: add pc sampling release when process release drm/amdkfd: bump kfd ioctl minor version for pc sampling availability
.../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 11 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 14 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 73 + .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 7 + drivers/gpu/drm/amd/amdkfd/Makefile | 3 +- .../gpu/drm/amd/amdkfd/cwsr_trap_handler.h | 2106 +++++++++-------- .../drm/amd/amdkfd/cwsr_trap_handler_gfx9.asm | 29 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 73 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 22 + drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 + drivers/gpu/drm/amd/amdkfd/kfd_device.c | 14 + .../drm/amd/amdkfd/kfd_device_queue_manager.c | 11 + .../drm/amd/amdkfd/kfd_device_queue_manager.h | 5 + drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 405 ++++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h | 37 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 43 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 32 +- .../amd/include/asic_reg/gc/gc_9_0_offset.h | 2 + .../amd/include/asic_reg/gc/gc_9_0_sh_mask.h | 5 + .../gpu/drm/amd/include/kgd_kfd_interface.h | 6 + include/uapi/linux/kfd_ioctl.h | 60 +- 21 files changed, 1881 insertions(+), 1080 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h
Signature · 1 line
2.25.1
PATCH v3 1/24 drm/amdkfd/kfd_ioctl: add pc sampling support
From: David Yat Sin <[email protected]>
Add pc sampling support in kfd_ioctl.
The user mode code which uses this new kfd_ioctl is linked to
https://github.com/RadeonOpenCompute/ROCT-Thunk-Interface
with master branch.
--- include/uapi/linux/kfd_ioctl.h | 57 +++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)
include/uapi/linux/kfd_ioctl.h +56 -1
@@ -1446,6 +1446,58 @@ struct kfd_ioctl_dbg_trap_args { }; }; +/** +* kfd_ioctl_pc_sample_op - PC Sampling ioctl operations +* +* @KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES: Query device PC Sampling capabilities +* @KFD_IOCTL_PCS_OP_CREATE: Register this process with a per-device PC sampler instance +* @KFD_IOCTL_PCS_OP_DESTROY: Unregister from a previously registered PC sampler instance +* @KFD_IOCTL_PCS_OP_START: Process begins taking samples from a previously registered PC sampler instance +* @KFD_IOCTL_PCS_OP_STOP: Process stops taking samples from a previously registered PC sampler instance +*/ +enum kfd_ioctl_pc_sample_op { +KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES , +KFD_IOCTL_PCS_OP_CREATE , +KFD_IOCTL_PCS_OP_DESTROY , +KFD_IOCTL_PCS_OP_START , +KFD_IOCTL_PCS_OP_STOP , +}; + +/* Values have to be a power of 2*/ +#define KFD_IOCTL_PCS_FLAG_POWER_OF_2 0x00000001 + +enum kfd_ioctl_pc_sample_method { +KFD_IOCTL_PCS_METHOD_HOSTTRAP =1 , +KFD_IOCTL_PCS_METHOD_STOCHASTIC , +}; + +enum kfd_ioctl_pc_sample_type { +KFD_IOCTL_PCS_TYPE_TIME_US , +KFD_IOCTL_PCS_TYPE_CLOCK_CYCLES , +KFD_IOCTL_PCS_TYPE_INSTRUCTIONS +}; + +struct kfd_pc_sample_info { +__u64 interval;/* [IN] if PCS_TYPE_INTERVAL_US: sample interval in us +* if PCS_TYPE_CLOCK_CYCLES: sample interval in graphics core clk cycles +* if PCS_TYPE_INSTRUCTIONS: sample interval in instructions issued by +* graphics compute units +*/ +__u64 interval_min;/* [OUT] */ +__u64 interval_max;/* [OUT] */ +__u64 flags;/* [OUT] indicate potential restrictions e.g FLAG_POWER_OF_2 */ +__u32 method;/* [IN/OUT] kfd_ioctl_pc_sample_method */ +__u32 type;/* [IN/OUT] kfd_ioctl_pc_sample_type */ +}; + +struct kfd_ioctl_pc_sample_args { +__u64 sample_info_ptr;/* array of kfd_pc_sample_info */ +__u32 num_sample_info; +__u32 op;/* kfd_ioctl_pc_sample_op */ +__u32 gpu_id; +__u32 trace_id; +}; +#define AMDKFD_IOCTL_BASE 'K'#define AMDKFD_IO (nr) _IO(AMDKFD_IOCTL_BASE, nr)#define AMDKFD_IOR (nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)
@@ -1566,7 +1618,10 @@ struct kfd_ioctl_dbg_trap_args {#define AMDKFD_IOC_DBG_TRAP \ AMDKFD_IOWR(0x26, struct kfd_ioctl_dbg_trap_args) +#define AMDKFD_IOC_PC_SAMPLE \ + AMDKFD_IOWR(0x27, struct kfd_ioctl_pc_sample_args) +#define AMDKFD_COMMAND_START 0x01 -#define AMDKFD_COMMAND_END 0x27 +#define AMDKFD_COMMAND_END 0x28#endif
Signature · 1 line
2.25.1
PATCH v3 2/24 drm/amdkfd: add pc sampling support
In reply to James ZhuFrom: David Yat Sin <[email protected]>
Add pc sampling functions in amdkfd.
--- drivers/gpu/drm/amd/amdkfd/Makefile | 3 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 44 +++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 78 ++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h | 34 +++++++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 13 ++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h
drivers/gpu/drm/amd/amdkfd/Makefile +2 -1
@@ -57,7 +57,8 @@ AMDKFD_FILES := $(AMDKFD_PATH)/kfd_module.o \ $(AMDKFD_PATH)/kfd_int_process_v11.o \ $(AMDKFD_PATH)/kfd_smi_events.o \ $(AMDKFD_PATH)/kfd_crat.o \ - $(AMDKFD_PATH)/kfd_debug.o + $(AMDKFD_PATH)/kfd_debug.o \ + $(AMDKFD_PATH)/kfd_pc_sampling.o ifneq ($(CONFIG_DEBUG_FS),) AMDKFD_FILES += $(AMDKFD_PATH)/kfd_debugfs.o
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +44 -0
68 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c new file +78 -0
78 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* +* Copyright 2023 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 KFD_PC_SAMPLING_H_ +#define KFD_PC_SAMPLING_H_ + +#include "amdgpu.h" +#include "kfd_priv.h" + +int kfd_pc_sample (struct kfd_process_device *pdd, +struct kfd_ioctl_pc_sample_args __user *args); + +#endif /* KFD_PC_SAMPLING_H_ */
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +13 -0
@@ -144,6 +144,19 @@ enum kfd_ioctl_flags {* we also allow ioctls with SYS_ADMIN capability. */ KFD_IOC_FLAG_CHECKPOINT_RESTORE =BIT (0 ), + +/* +* @KFD_IOC_FLAG_PERFMON: +* Performance monitoring feature, GPU performance monitoring can allow users +* to gather some information about other processes. PC sampling can allow +* users to infer information about wavefronts from other processes that are +* running on the same CUs, such as which execution units they are using. As +* such, this type of performance monitoring should be protected and only +* available to users with sufficient capabilities: either CAP_PERFMON, or, +* for backwards compatibility, CAP_SYS_ADMIN. +*/ + + KFD_IOC_FLAG_PERFMON = BIT(1), };/* * Kernel module parameter to specify maximum number of supported queues per
Signature · 1 line
2.25.1
PATCH v3 3/24 drm/amdkfd: enable pc sampling query
In reply to James ZhuFrom: David Yat Sin <[email protected]>
Enable pc sampling to query system capability.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 54 +++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +53 -1
@@ -25,10 +25,62 @@#include "amdgpu_amdkfd.h" #include "kfd_pc_sampling.h" +struct supported_pc_sample_info { +uint32_t ip_version; +const struct kfd_pc_sample_info *sample_info; +}; + +const struct kfd_pc_sample_info sample_info_hosttrap_9_0_0 = { +0 ,1 , ~0ULL ,0 ,KFD_IOCTL_PCS_METHOD_HOSTTRAP ,KFD_IOCTL_PCS_TYPE_TIME_US }; + +struct supported_pc_sample_info supported_formats[] = { + {IP_VERSION (9 ,4 ,1 ), &sample_info_hosttrap_9_0_0 }, + {IP_VERSION (9 ,4 ,2 ), &sample_info_hosttrap_9_0_0 }, +}; +static int kfd_pc_sample_query_cap (struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *user_args) { -return -EINVAL ; +uint64_t sample_offset; +int num_method =0 ; +int i; + +for (i =0 ; i <ARRAY_SIZE (supported_formats); i++) +if (KFD_GC_VERSION (pdd->dev) == supported_formats[i].ip_version) + num_method++; + +if (!num_method) { +pr_debug ("PC Sampling not supported on GC_HWIP:0x%x." , + pdd->dev->adev->ip_versions[GC_HWIP ][0 ]); +return -EOPNOTSUPP ; + } + +if (!user_args->sample_info_ptr || !user_args->num_sample_info) { + user_args->num_sample_info = num_method; +return 0 ; + } + +if (user_args->num_sample_info < num_method) { + user_args->num_sample_info = num_method; +pr_debug ("Sample info buffer is not large enough, " +"ASIC requires space for %d kfd_pc_sample_info entries." , num_method); +return -ENOSPC ; + } + + sample_offset = user_args->sample_info_ptr; +for (i =0 ; i <ARRAY_SIZE (supported_formats); i++) { +if (KFD_GC_VERSION (pdd->dev) == supported_formats[i].ip_version) { +int ret =copy_to_user ((void __user *) sample_offset, + supported_formats[i].sample_info,sizeof (struct kfd_pc_sample_info )); +if (ret) { +pr_debug ("Failed to copy PC sampling info to user." ); +return -EFAULT ; + } + sample_offset +=sizeof (struct kfd_pc_sample_info ); + } + } + +return 0 ; }static int kfd_pc_sample_start (struct kfd_process_device *pdd)
Signature · 1 line
2.25.1
PATCH v3 4/24 drm/amdkfd: add pc sampling mutex
In reply to James ZhuAdd pc sampling mutex per node, and do init/destroy in node init.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 12 ++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 7 +++++++ 2 files changed, 19 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +12 -0
@@ -533,6 +533,16 @@ static void kfd_smi_init(struct kfd_node *dev)spin_lock_init (&dev->smi_lock); } +static void kfd_pc_sampling_init (struct kfd_node *dev) +{ +mutex_init (&dev->pcs_data.mutex); +} + +static void kfd_pc_sampling_exit (struct kfd_node *dev) +{ +mutex_destroy (&dev->pcs_data.mutex); +} +static int kfd_init_node (struct kfd_node *node) {int err =-1 ;
@@ -563,6 +573,7 @@ static int kfd_init_node(struct kfd_node *node) }kfd_smi_init (node); +kfd_pc_sampling_init (node);return 0 ;
@@ -593,6 +604,7 @@ static void kfd_cleanup_nodes(struct kfd_dev *kfd, unsigned int num_nodes)kfd_topology_remove_device (knode);if (knode->gws)amdgpu_amdkfd_free_gws (knode->adev, knode->gws); +kfd_pc_sampling_exit (knode);kfree (knode); kfd->nodes[i] =NULL ; }
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +7 -0
@@ -269,6 +269,11 @@ struct kfd_vmid_info {struct kfd_dev ; +/* Per device PC Sampling data */ +struct kfd_dev_pc_sampling { +struct mutex mutex; +}; +struct kfd_node {unsigned int node_id;struct amdgpu_device *adev;/* Duplicated here along with keeping
@@ -322,6 +327,8 @@ struct kfd_node {struct kfd_local_mem_info local_mem_info;struct kfd_dev *kfd; + +struct kfd_dev_pc_sampling pcs_data; };struct kfd_dev {
Signature · 1 line
2.25.1
PATCH v3 5/24 drm/amdkfd: enable pc sampling create
In reply to James ZhuFrom: David Yat Sin <[email protected]>
Enable pc sampling create.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 53 +++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 10 ++++ 2 files changed, 62 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +52 -1
@@ -97,7 +97,58 @@ static int kfd_pc_sample_stop(struct kfd_process_device *pdd)static int kfd_pc_sample_create (struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *user_args) { -return -EINVAL ; +struct kfd_pc_sample_info *supported_format =NULL ; +struct kfd_pc_sample_info user_info; +int ret; +int i; + +if (user_args->num_sample_info !=1 ) +return -EINVAL ; + + ret =copy_from_user (&user_info, (void __user *) user_args->sample_info_ptr, +sizeof (struct kfd_pc_sample_info )); +if (ret) { +pr_debug ("Failed to copy PC sampling info from user\n" ); +return -EFAULT ; + } + +for (i =0 ; i <ARRAY_SIZE (supported_formats); i++) { +if (KFD_GC_VERSION (pdd->dev) == supported_formats[i].ip_version + && user_info.method == supported_formats[i].sample_info->method + && user_info.type == supported_formats[i].sample_info->type + && user_info.interval <= supported_formats[i].sample_info->interval_max + && user_info.interval >= supported_formats[i].sample_info->interval_min) { + supported_format = + (struct kfd_pc_sample_info *)supported_formats[i].sample_info; +break ; + } + } + +if (!supported_format) { +pr_debug ("Sampling format is not supported!" ); +return -EOPNOTSUPP ; + } + +mutex_lock (&pdd->dev->pcs_data.mutex); +if (pdd->dev->pcs_data.hosttrap_entry.base.use_count && +memcmp (&pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info, + &user_info,sizeof (user_info))) { + ret =copy_to_user ((void __user *) user_args->sample_info_ptr, + &pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info, +sizeof (struct kfd_pc_sample_info )); +mutex_unlock (&pdd->dev->pcs_data.mutex); +return ret ? -EFAULT : -EEXIST ; + } + +/* TODO: add trace_id return */ + +if (!pdd->dev->pcs_data.hosttrap_entry.base.use_count) + pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info = user_info; + + pdd->dev->pcs_data.hosttrap_entry.base.use_count++; +mutex_unlock (&pdd->dev->pcs_data.mutex); + +return 0 ; }static int kfd_pc_sample_destroy (struct kfd_process_device *pdd,uint32_t trace_id)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +10 -0
@@ -269,9 +269,19 @@ struct kfd_vmid_info {struct kfd_dev ; +struct kfd_dev_pc_sampling_data { +uint32_t use_count;/* Num of PC sampling sessions */ +struct kfd_pc_sample_info pc_sample_info; +}; + +struct kfd_dev_pcs_hosttrap { +struct kfd_dev_pc_sampling_data base; +}; +/* Per device PC Sampling data */ struct kfd_dev_pc_sampling {struct mutex mutex; +struct kfd_dev_pcs_hosttrap hosttrap_entry; };struct kfd_node {
Signature · 1 line
2.25.1
PATCH v3 6/24 drm/amdkfd: add trace_id return
In reply to James ZhuAdd trace_id return for new pc sampling creation per device, Use IDR to quickly locate pc_sampling_entry for reference.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 20 +++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +2 -0
@@ -536,10 +536,12 @@ static void kfd_smi_init(struct kfd_node *dev)static void kfd_pc_sampling_init (struct kfd_node *dev) {mutex_init (&dev->pcs_data.mutex); +idr_init_base (&dev->pcs_data.hosttrap_entry.base.pc_sampling_idr,1 ); }static void kfd_pc_sampling_exit (struct kfd_node *dev) { +idr_destroy (&dev->pcs_data.hosttrap_entry.base.pc_sampling_idr);mutex_destroy (&dev->pcs_data.mutex); }
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +19 -1
@@ -99,6 +99,7 @@ static int kfd_pc_sample_create(struct kfd_process_device *pdd, {struct kfd_pc_sample_info *supported_format =NULL ;struct kfd_pc_sample_info user_info; +struct pc_sampling_entry *pcs_entry;int ret;int i;
@@ -140,7 +141,19 @@ static int kfd_pc_sample_create(struct kfd_process_device *pdd,return ret ? -EFAULT : -EEXIST ; } -/* TODO: add trace_id return */ + pcs_entry =kzalloc (sizeof (*pcs_entry),GFP_KERNEL ); +if (!pcs_entry) { +mutex_unlock (&pdd->dev->pcs_data.mutex); +return -ENOMEM ; + } + + i =idr_alloc_cyclic (&pdd->dev->pcs_data.hosttrap_entry.base.pc_sampling_idr, + pcs_entry,1 ,0 ,GFP_KERNEL ); +if (i <0 ) { +mutex_unlock (&pdd->dev->pcs_data.mutex); +kfree (pcs_entry); +return i; + }if (!pdd->dev->pcs_data.hosttrap_entry.base.use_count) pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info = user_info;
@@ -148,6 +161,11 @@ static int kfd_pc_sample_create(struct kfd_process_device *pdd, pdd->dev->pcs_data.hosttrap_entry.base.use_count++;mutex_unlock (&pdd->dev->pcs_data.mutex); + pcs_entry->pdd = pdd; + user_args->trace_id = (uint32_t )i; + +pr_debug ("alloc pcs_entry = %p, trace_id = 0x%x on gpu 0x%x" , pcs_entry, i, pdd->dev->id); +return 0 ; }
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
@@ -271,6 +271,7 @@ struct kfd_dev;struct kfd_dev_pc_sampling_data {uint32_t use_count;/* Num of PC sampling sessions */ +struct idr pc_sampling_idr;struct kfd_pc_sample_info pc_sample_info; };
@@ -756,6 +757,11 @@ enum kfd_pdd_bound {*/ #define SDMA_ACTIVITY_DIVISOR 100 +struct pc_sampling_entry { +bool enabled; +struct kfd_process_device *pdd; +}; +/* Data that is per-process-per device. */ struct kfd_process_device {/* The device that owns this data. */
Signature · 1 line
2.25.1
PATCH v3 7/24 drm/amdkfd: check pcs_entry valid
In reply to James ZhuCheck pcs_entry valid for pc sampling ioctl.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 33 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +30 -3
@@ -178,6 +178,24 @@ static int kfd_pc_sample_destroy(struct kfd_process_device *pdd, uint32_t trace_int kfd_pc_sample (struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *args) { +struct pc_sampling_entry *pcs_entry; + +if (args->op !=KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES && + args->op !=KFD_IOCTL_PCS_OP_CREATE ) { + +mutex_lock (&pdd->dev->pcs_data.mutex); + pcs_entry =idr_find (&pdd->dev->pcs_data.hosttrap_entry.base.pc_sampling_idr, + args->trace_id); +mutex_unlock (&pdd->dev->pcs_data.mutex); + +/* pcs_entry is only for this pc sampling process, +* which has kfd_process->mutex protected here. +*/ +if (!pcs_entry || + pcs_entry->pdd != pdd) +return -EINVAL ; + } +switch (args->op) {case KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES :return kfd_pc_sample_query_cap (pdd, args);
@@ -186,13 +204,22 @@ int kfd_pc_sample(struct kfd_process_device *pdd,return kfd_pc_sample_create (pdd, args);case KFD_IOCTL_PCS_OP_DESTROY : -return kfd_pc_sample_destroy (pdd, args->trace_id); +if (pcs_entry->enabled) +return -EBUSY ; +else +return kfd_pc_sample_destroy (pdd, args->trace_id);case KFD_IOCTL_PCS_OP_START : -return kfd_pc_sample_start (pdd); +if (pcs_entry->enabled) +return -EALREADY ; +else +return kfd_pc_sample_start (pdd);case KFD_IOCTL_PCS_OP_STOP : -return kfd_pc_sample_stop (pdd); +if (!pcs_entry->enabled) +return -EALREADY ; +else +return kfd_pc_sample_stop (pdd); }return -EINVAL ;
Signature · 1 line
2.25.1
PATCH v3 8/24 drm/amdkfd: enable pc sampling destroy
In reply to James ZhuEnable pc sampling destroy.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +17 -3
@@ -169,10 +169,24 @@ static int kfd_pc_sample_create(struct kfd_process_device *pdd,return 0 ; } -static int kfd_pc_sample_destroy (struct kfd_process_device *pdd,uint32_t trace_id) +static int kfd_pc_sample_destroy (struct kfd_process_device *pdd,uint32_t trace_id, +struct pc_sampling_entry *pcs_entry) { -return -EINVAL ; +pr_debug ("free pcs_entry = %p, trace_id = 0x%x on gpu 0x%x" , + pcs_entry, trace_id, pdd->dev->id); + +mutex_lock (&pdd->dev->pcs_data.mutex); + pdd->dev->pcs_data.hosttrap_entry.base.use_count--; +idr_remove (&pdd->dev->pcs_data.hosttrap_entry.base.pc_sampling_idr, trace_id); +if (!pdd->dev->pcs_data.hosttrap_entry.base.use_count) +memset (&pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info,0x0 , +sizeof (struct kfd_pc_sample_info )); +mutex_unlock (&pdd->dev->pcs_data.mutex); + +kvfree (pcs_entry); + +return 0 ; } int kfd_pc_sample(struct kfd_process_device *pdd,
@@ -207,7 +221,7 @@ int kfd_pc_sample(struct kfd_process_device *pdd,if (pcs_entry->enabled)return -EBUSY ;else -return kfd_pc_sample_destroy (pdd, args->trace_id); +return kfd_pc_sample_destroy (pdd, args->trace_id, pcs_entry);case KFD_IOCTL_PCS_OP_START :if (pcs_entry->enabled)
Signature · 1 line
2.25.1
PATCH v3 9/24 drm/amdkfd: add interface to trigger pc sampling trap
In reply to James ZhuAdd interface to trigger pc sampling trap.
--- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +6 -0
@@ -33,6 +33,7 @@#include <linux/dma-fence.h> #include "amdgpu_irq.h" #include "amdgpu_gfx.h" +#include <uapi/linux/kfd_ioctl.h> struct pci_dev ;struct amdgpu_device ;
@@ -318,6 +319,11 @@ struct kfd2kgd_calls {void (*program_trap_handler_settings)(struct amdgpu_device *adev,uint32_t vmid,uint64_t tba_addr,uint64_t tma_addr,uint32_t inst); +uint32_t (*trigger_pc_sample_trap)(struct amdgpu_device *adev, +uint32_t vmid, +uint32_t *target_simd, +uint32_t *target_wave_slot, + enum kfd_ioctl_pc_sample_method method); };#endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Signature · 1 line
2.25.1
PATCH v3 10/24 drm/amdkfd: trigger pc sampling trap for gfx v9
In reply to James ZhuImplement trigger pc sampling trap for gfx v9.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 36 +++++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 7 ++++ 2 files changed, 43 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +36 -0
@@ -1144,6 +1144,42 @@ void kgd_gfx_v9_program_trap_handler_settings(struct amdgpu_device *adev,kgd_gfx_v9_unlock_srbm (adev, inst); } +uint32_t kgd_gfx_v9_trigger_pc_sample_trap (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t max_wave_slot, +uint32_t max_simd, +uint32_t *target_simd, +uint32_t *target_wave_slot, +enum kfd_ioctl_pc_sample_method method) +{ +if (method ==KFD_IOCTL_PCS_METHOD_HOSTTRAP ) { +uint32_t value =0 ; + + value =REG_SET_FIELD (value,SQ_CMD ,CMD ,SQ_IND_CMD_CMD_TRAP ); + value =REG_SET_FIELD (value,SQ_CMD ,MODE ,SQ_IND_CMD_MODE_SINGLE ); + +/* select *target_simd */ + value =REG_SET_FIELD (value,SQ_CMD ,SIMD_ID , *target_simd); +/* select *target_wave_slot */ + value =REG_SET_FIELD (value,SQ_CMD ,WAVE_ID , (*target_wave_slot)++); + +mutex_lock (&adev->grbm_idx_mutex); +amdgpu_gfx_select_se_sh (adev,0xFFFFFFFF ,0xFFFFFFFF ,0xFFFFFFFF ,0 ); +WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); +mutex_unlock (&adev->grbm_idx_mutex); + + *target_wave_slot %= max_wave_slot; +if (!(*target_wave_slot)) { + (*target_simd)++; + *target_simd %= max_simd; + } + }else { +pr_debug ("PC Sampling method %d not supported." , method); +return -EOPNOTSUPP ; + } +return 0 ; +} +const struct kfd2kgd_calls gfx_v9_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings, .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h +7 -0
@@ -101,3 +101,10 @@ void kgd_gfx_v9_build_grace_period_packet_info(struct amdgpu_device *adev,uint32_t grace_period, uint32_t *reg_offset, uint32_t *reg_data); +uint32_t kgd_gfx_v9_trigger_pc_sample_trap (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t max_wave_slot, +uint32_t max_simd, +uint32_t *target_simd, +uint32_t *target_wave_slot, +enum kfd_ioctl_pc_sample_method method);
Signature · 1 line
2.25.1
PATCH v3 11/24 drm/amdkfd/gfx9: enable host trap
In reply to James ZhuEnable host trap.
--- .../gpu/drm/amd/amdkfd/cwsr_trap_handler.h | 63 +++++++++++-------- .../drm/amd/amdkfd/cwsr_trap_handler_gfx9.asm | 24 ++++--- 2 files changed, 52 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler.h +36 -27
@@ -274,14 +274,14 @@ static const uint32_t cwsr_trap_gfx8_hex[] = {static const uint32_t cwsr_trap_gfx9_hex[] = { -0xbf820001 ,0xbf820258 , +0xbf820001 ,0xbf82025e ,0xb8f8f802 ,0x8978ff78 ,0x00020006 ,0xb8fbf803 ,0x866eff78 ,0x00002000 ,0xbf840009 ,0x866eff6d ,0x00ff0000 ,0xbf85001e ,0x866eff7b ,0x00000400 , -0xbf850055 ,0xbf8e0010 , +0xbf85005b ,0xbf8e0010 ,0xb8fbf803 ,0xbf82fffa ,0x866eff7b ,0x03c00900 ,0xbf850015 ,0x866eff7b ,
@@ -294,7 +294,7 @@ static const uint32_t cwsr_trap_gfx9_hex[] = {0xbf850007 ,0xb8eef801 ,0x866eff6e ,0x00000800 ,0xbf850003 ,0x866eff7b , -0x00000400 ,0xbf85003a , +0x00000400 ,0xbf850040 ,0xb8faf807 ,0x867aff7a ,0x001f8000 ,0x8e7a8b7a , 0x8977ff77, 0xfc000000,
@@ -303,13 +303,16 @@ static const uint32_t cwsr_trap_gfx9_hex[] = {0xb8fbf813 ,0x8efa887a ,0xbf0d8f7b ,0xbf840002 ,0x877bff7b ,0xffff0000 , -0xc0031bbd ,0x00000010 , -0xbf8cc07f ,0x8e6e976e , -0x8977ff77 ,0x00800000 , -0x87776e77 ,0xc0071bbd , -0x00000000 ,0xbf8cc07f , +0xc0031c3d ,0x00000010 , +0xc0071bbd ,0x00000000 ,0xc0071ebd ,0x00000008 , -0xbf8cc07f ,0x86ee6e6e , +0xbf8cc07f ,0x8671ff6d , +0x01000000 ,0xbf840004 , +0x92f1ff70 ,0x00010001 , +0xbf840016 ,0xbf820005 , +0x86708170 ,0x8e709770 , +0x8977ff77 ,0x00800000 , +0x87777077 ,0x86ee6e6e ,0xbf840001 ,0xbe801d6e ,0x866eff6d ,0x01ff0000 , 0xbf850005, 0x8778ff78,
@@ -1098,14 +1101,14 @@ static const uint32_t cwsr_trap_nv1x_hex[] = { };static const uint32_t cwsr_trap_arcturus_hex[] = { -0xbf820001 ,0xbf8202d4 , +0xbf820001 ,0xbf8202da ,0xb8f8f802 ,0x8978ff78 ,0x00020006 ,0xb8fbf803 ,0x866eff78 ,0x00002000 ,0xbf840009 ,0x866eff6d ,0x00ff0000 ,0xbf85001e ,0x866eff7b ,0x00000400 , -0xbf850055 ,0xbf8e0010 , +0xbf85005b ,0xbf8e0010 ,0xb8fbf803 ,0xbf82fffa ,0x866eff7b ,0x03c00900 ,0xbf850015 ,0x866eff7b ,
@@ -1118,7 +1121,7 @@ static const uint32_t cwsr_trap_arcturus_hex[] = {0xbf850007 ,0xb8eef801 ,0x866eff6e ,0x00000800 ,0xbf850003 ,0x866eff7b , -0x00000400 ,0xbf85003a , +0x00000400 ,0xbf850040 ,0xb8faf807 ,0x867aff7a ,0x001f8000 ,0x8e7a8b7a , 0x8977ff77, 0xfc000000,
@@ -1127,13 +1130,16 @@ static const uint32_t cwsr_trap_arcturus_hex[] = {0xb8fbf813 ,0x8efa887a ,0xbf0d8f7b ,0xbf840002 ,0x877bff7b ,0xffff0000 , -0xc0031bbd ,0x00000010 , -0xbf8cc07f ,0x8e6e976e , -0x8977ff77 ,0x00800000 , -0x87776e77 ,0xc0071bbd , -0x00000000 ,0xbf8cc07f , +0xc0031c3d ,0x00000010 , +0xc0071bbd ,0x00000000 ,0xc0071ebd ,0x00000008 , -0xbf8cc07f ,0x86ee6e6e , +0xbf8cc07f ,0x8671ff6d , +0x01000000 ,0xbf840004 , +0x92f1ff70 ,0x00010001 , +0xbf840016 ,0xbf820005 , +0x86708170 ,0x8e709770 , +0x8977ff77 ,0x00800000 , +0x87777077 ,0x86ee6e6e ,0xbf840001 ,0xbe801d6e ,0x866eff6d ,0x01ff0000 , 0xbf850005, 0x8778ff78,
@@ -1578,14 +1584,14 @@ static const uint32_t cwsr_trap_arcturus_hex[] = { };static const uint32_t cwsr_trap_aldebaran_hex[] = { -0xbf820001 ,0xbf8202df , +0xbf820001 ,0xbf8202e5 ,0xb8f8f802 ,0x8978ff78 ,0x00020006 ,0xb8fbf803 ,0x866eff78 ,0x00002000 ,0xbf840009 ,0x866eff6d ,0x00ff0000 ,0xbf85001e ,0x866eff7b ,0x00000400 , -0xbf850055 ,0xbf8e0010 , +0xbf85005b ,0xbf8e0010 ,0xb8fbf803 ,0xbf82fffa ,0x866eff7b ,0x03c00900 ,0xbf850015 ,0x866eff7b ,
@@ -1598,7 +1604,7 @@ static const uint32_t cwsr_trap_aldebaran_hex[] = {0xbf850007 ,0xb8eef801 ,0x866eff6e ,0x00000800 ,0xbf850003 ,0x866eff7b , -0x00000400 ,0xbf85003a , +0x00000400 ,0xbf850040 ,0xb8faf807 ,0x867aff7a ,0x001f8000 ,0x8e7a8b7a , 0x8977ff77, 0xfc000000,
@@ -1607,13 +1613,16 @@ static const uint32_t cwsr_trap_aldebaran_hex[] = {0xb8fbf813 ,0x8efa887a ,0xbf0d8f7b ,0xbf840002 ,0x877bff7b ,0xffff0000 , -0xc0031bbd ,0x00000010 , -0xbf8cc07f ,0x8e6e976e , -0x8977ff77 ,0x00800000 , -0x87776e77 ,0xc0071bbd , -0x00000000 ,0xbf8cc07f , +0xc0031c3d ,0x00000010 , +0xc0071bbd ,0x00000000 ,0xc0071ebd ,0x00000008 , -0xbf8cc07f ,0x86ee6e6e , +0xbf8cc07f ,0x8671ff6d , +0x01000000 ,0xbf840004 , +0x92f1ff70 ,0x00010001 , +0xbf840016 ,0xbf820005 , +0x86708170 ,0x8e709770 , +0x8977ff77 ,0x00800000 , +0x87777077 ,0x86ee6e6e ,0xbf840001 ,0xbe801d6e ,0x866eff6d ,0x01ff0000 , 0xbf850005, 0x8778ff78,
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler_gfx9.asm +16 -8
@@ -104,6 +104,10 @@ var SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK = 0x1F8000 var SQ_WAVE_MODE_DEBUG_EN_MASK = 0x800 +var TMA_HOST_TRAP_EN_SHIFT = 1 +var TMA_HOST_TRAP_EN_SIZE = 1 +var TMA_HOST_TRAP_EN_BFE = (TMA_HOST_TRAP_EN_SHIFT | (TMA_HOST_TRAP_EN_SIZE << 16)) + var TTMP_SAVE_RCNT_FIRST_REPLAY_SHIFT = 26 // bits [31:26] unused by SPI debug data var TTMP_SAVE_RCNT_FIRST_REPLAY_MASK = 0xFC000000 var TTMP_DEBUG_TRAP_ENABLED_SHIFT = 23
@@ -288,17 +292,21 @@ L_FETCH_2ND_TRAP: s_or_b32 ttmp15, ttmp15, 0xFFFF0000 L_NO_SIGN_EXTEND_TMA: - s_load_dword ttmp2, [ttmp14, ttmp15], 0x10 glc:1 // debug trap enabled flag - s_waitcnt lgkmcnt(0) - s_lshl_b32 ttmp2, ttmp2, TTMP_DEBUG_TRAP_ENABLED_SHIFT - s_andn2_b32 s_save_ib_sts, s_save_ib_sts, TTMP_DEBUG_TRAP_ENABLED_MASK - s_or_b32 s_save_ib_sts, s_save_ib_sts, ttmp2 - + s_load_dword ttmp4, [ttmp14, ttmp15], 0x10 glc:1 // enable flags from 1st level TMA s_load_dwordx2 [ttmp2, ttmp3], [ttmp14, ttmp15], 0x0 glc:1 // second-level TBA - s_waitcnt lgkmcnt(0) s_load_dwordx2 [ttmp14, ttmp15], [ttmp14, ttmp15], 0x8 glc:1 // second-level TMA s_waitcnt lgkmcnt(0) - + s_and_b32 ttmp5, s_save_pc_hi, S_SAVE_PC_HI_HT_MASK // host trap request + s_cbranch_scc0 L_NOT_HT + s_bfe_u32 ttmp5, ttmp4, TMA_HOST_TRAP_EN_BFE // extract host_trap_en to ttmp5[0] + s_cbranch_scc0 L_EXIT_TRAP // HT requested, but host traps not enabled + s_branch L_GOTO_2ND_TRAP +L_NOT_HT: + s_and_b32 ttmp4, ttmp4, 0x1 // debug_enable bit left over + s_lshl_b32 ttmp4, ttmp4, TTMP_DEBUG_TRAP_ENABLED_SHIFT + s_andn2_b32 s_save_ib_sts, s_save_ib_sts, TTMP_DEBUG_TRAP_ENABLED_MASK + s_or_b32 s_save_ib_sts, s_save_ib_sts, ttmp4 +L_GOTO_2ND_TRAP: s_and_b64 [ttmp2, ttmp3], [ttmp2, ttmp3], [ttmp2, ttmp3] s_cbranch_scc0 L_NO_NEXT_TRAP // second-level trap handler not been set s_setpc_b64 [ttmp2, ttmp3] // jump to second-level trap handler
Signature · 1 line
2.25.1
PATCH v3 12/24 drm/amdgpu: use trapID 4 for host trap
In reply to James ZhuSince TRAPSTS.HOST_TRAP won't work pre-gfx943, so use TTMP1 (bit 24: HT) and (bit 16-23: trapID) to identify the host trap.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 2 + .../gpu/drm/amd/amdkfd/cwsr_trap_handler.h | 2117 +++++++++-------- .../drm/amd/amdkfd/cwsr_trap_handler_gfx9.asm | 5 + 3 files changed, 1070 insertions(+), 1054 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +2 -0
@@ -1162,6 +1162,8 @@ uint32_t kgd_gfx_v9_trigger_pc_sample_trap(struct amdgpu_device *adev, value =REG_SET_FIELD (value,SQ_CMD ,SIMD_ID , *target_simd);/* select *target_wave_slot */ value =REG_SET_FIELD (value,SQ_CMD ,WAVE_ID , (*target_wave_slot)++); +/* set TrapID 4 for HOSTTRAP */ + value =REG_SET_FIELD (value,SQ_CMD ,DATA ,0x4 );mutex_lock (&adev->grbm_idx_mutex);amdgpu_gfx_select_se_sh (adev,0xFFFFFFFF ,0xFFFFFFFF ,0xFFFFFFFF ,0 );
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler.h +1063 -1054
2,343 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler_gfx9.asm +5 -0
@@ -244,6 +244,11 @@ L_NOT_HALTED: SQ_WAVE_TRAPSTS_TRAP_AFTER_INST_MASK s_cbranch_scc1 L_FETCH_2ND_TRAP + // Check TTMP1 bits 24 (HT) and 23:16(trapID): HT == 1 & trapID == 4 + s_and_b32 ttmp2, s_save_pc_hi, (S_SAVE_PC_HI_TRAP_ID_MASK|S_SAVE_PC_HI_HT_MASK) + s_cmp_eq_u32 ttmp2, 0x1040000 + s_cbranch_scc1 L_FETCH_2ND_TRAP + // Check for maskable exceptions in trapsts.excp and trapsts.excp_hi. // Maskable exceptions only cause the wave to enter the trap handler if // their respective bit in mode.excp_en is set.
Signature · 1 line
2.25.1
PATCH v3 13/24 drm/amdgpu: add sq host trap status check
In reply to James ZhuBefore fire a new host trap, check the host trap status.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 35 +++++++++++++++++++ .../amd/include/asic_reg/gc/gc_9_0_offset.h | 2 ++ .../amd/include/asic_reg/gc/gc_9_0_sh_mask.h | 5 +++ 3 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +35 -0
@@ -1144,6 +1144,35 @@ void kgd_gfx_v9_program_trap_handler_settings(struct amdgpu_device *adev,kgd_gfx_v9_unlock_srbm (adev, inst); } +static uint32_t kgd_aldebaran_get_hosttrap_status (struct amdgpu_device *adev) +{ +uint32_t sq_hosttrap_status =0x0 ; +int i, j; + +mutex_lock (&adev->grbm_idx_mutex); +for (i =0 ; i < adev->gfx.config.max_shader_engines; i++) { +for (j =0 ; j < adev->gfx.config.max_sh_per_se; j++) { +amdgpu_gfx_select_se_sh (adev, i, j,0xffffffff ,0 ); + sq_hosttrap_status =RREG32_SOC15 (GC ,0 , mmSQ_HOSTTRAP_STATUS); + +if (sq_hosttrap_status &SQ_HOSTTRAP_STATUS__HTPENDING_OVERRIDE_MASK ) { +WREG32_SOC15 (GC ,0 , mmSQ_HOSTTRAP_STATUS, +SQ_HOSTTRAP_STATUS__HTPENDING_OVERRIDE_MASK ); + sq_hosttrap_status =0x0 ; +continue ; + } +if (sq_hosttrap_status) + goto out; + } + } + +out: +amdgpu_gfx_select_se_sh (adev,0xFFFFFFFF ,0xFFFFFFFF ,0xFFFFFFFF ,0 ); +mutex_unlock (&adev->grbm_idx_mutex); + +return sq_hosttrap_status; +} + uint32_t kgd_gfx_v9_trigger_pc_sample_trap(struct amdgpu_device *adev, uint32_t vmid, uint32_t max_wave_slot,
@@ -1154,6 +1183,12 @@ uint32_t kgd_gfx_v9_trigger_pc_sample_trap(struct amdgpu_device *adev, {if (method ==KFD_IOCTL_PCS_METHOD_HOSTTRAP ) {uint32_t value =0 ; +uint32_t sq_hosttrap_status =0x0 ; + + sq_hosttrap_status =kgd_aldebaran_get_hosttrap_status (adev); +/* skip when last host trap request is still pending to complete */ +if (sq_hosttrap_status) +return 0 ; value =REG_SET_FIELD (value,SQ_CMD ,CMD ,SQ_IND_CMD_CMD_TRAP ); value =REG_SET_FIELD (value,SQ_CMD ,MODE ,SQ_IND_CMD_MODE_SINGLE );
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_0_offset.h +2 -0
@@ -462,6 +462,8 @@#define mmSQ_IND_DATA_BASE_IDX 0#define mmSQ_CMD 0x037b#define mmSQ_CMD_BASE_IDX 0 +#define mmSQ_HOSTTRAP_STATUS 0x0376 +#define mmSQ_HOSTTRAP_STATUS_BASE_IDX 0#define mmSQ_TIME_HI 0x037c#define mmSQ_TIME_HI_BASE_IDX 0#define mmSQ_TIME_LO 0x037d
drivers/gpu/drm/amd/include/asic_reg/gc/gc_9_0_sh_mask.h +5 -0
@@ -2616,6 +2616,11 @@//SQ_CMD_TIMESTAMP #define SQ_CMD_TIMESTAMP__TIMESTAMP__SHIFT 0x0#define SQ_CMD_TIMESTAMP__TIMESTAMP_MASK 0x000000FFL +//SQ_HOSTTRAP_STATUS +#define SQ_HOSTTRAP_STATUS__HTPENDINGCOUNT__SHIFT 0x0 +#define SQ_HOSTTRAP_STATUS__HTPENDING_OVERRIDE__SHIFT 0x8 +#define SQ_HOSTTRAP_STATUS__HTPENDINGCOUNT_MASK 0x000000FFL +#define SQ_HOSTTRAP_STATUS__HTPENDING_OVERRIDE_MASK 0x00000100L//SQ_IND_INDEX #define SQ_IND_INDEX__WAVE_ID__SHIFT 0x0#define SQ_IND_INDEX__SIMD_ID__SHIFT 0x4
Signature · 1 line
2.25.1
PATCH v3 14/24 drm/amdkfd: trigger pc sampling trap for arcturus
In reply to James ZhuImplement trigger pc sampling trap for arcturus.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +13 -1
@@ -390,6 +390,17 @@ static uint32_t kgd_arcturus_disable_debug_trap(struct amdgpu_device *adev,return 0 ; } + +static uint32_t kgd_arcturus_trigger_pc_sample_trap (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t *target_simd, +uint32_t *target_wave_slot, +enum kfd_ioctl_pc_sample_method method) +{ +return kgd_gfx_v9_trigger_pc_sample_trap (adev, vmid,10 ,4 , + target_simd, target_wave_slot, method); +} +const struct kfd2kgd_calls arcturus_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings, .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
@@ -418,5 +429,6 @@ const struct kfd2kgd_calls arcturus_kfd2kgd = { .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy, - .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings + .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings, + .trigger_pc_sample_trap = kgd_arcturus_trigger_pc_sample_trap };
Signature · 1 line
2.25.1
PATCH v3 15/24 drm/amdkfd: trigger pc sampling trap for aldebaran
In reply to James ZhuImplement trigger pc sampling trap for aldebaran.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +11 -0
@@ -163,6 +163,16 @@ static uint32_t kgd_gfx_aldebaran_set_address_watch(return watch_address_cntl; } +static uint32_t kgd_aldebaran_trigger_pc_sample_trap (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t *target_simd, +uint32_t *target_wave_slot, +enum kfd_ioctl_pc_sample_method method) +{ +return kgd_gfx_v9_trigger_pc_sample_trap (adev, vmid,8 ,4 , + target_simd, target_wave_slot, method); +} +const struct kfd2kgd_calls aldebaran_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings, .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
@@ -191,4 +201,5 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = { .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings, + .trigger_pc_sample_trap = kgd_aldebaran_trigger_pc_sample_trap, };
Signature · 1 line
2.25.1
PATCH v3 16/24 drm/amdkfd: use bit operation set debug trap
In reply to James Zhu1st level TMA's 2nd byte which used for trap type setting, to use bit operation to change selected bit only.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +13 -3
@@ -1440,13 +1440,23 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)return true; } +/* bit offset in 1st-level TMA's 2nd byte which used for KFD_TRAP_TYPE_BIT */ +enum KFD_TRAP_TYPE_BIT { +KFD_TRAP_TYPE_DEBUG =0 ,/* bit 0 for debug trap */ +KFD_TRAP_TYPE_HOST , +KFD_TRAP_TYPE_STOCHASTIC , +}; +void kfd_process_set_trap_debug_flag (struct qcm_process_device *qpd,bool enabled) {if (qpd->cwsr_kaddr) { -uint64_t *tma = - (uint64_t *)(qpd->cwsr_kaddr +KFD_CWSR_TMA_OFFSET ); - tma[2 ] = enabled; +volatile unsigned long *tma = + (volatile unsigned long *)(qpd->cwsr_kaddr +KFD_CWSR_TMA_OFFSET ); +if (enabled) +set_bit (KFD_TRAP_TYPE_DEBUG , &tma[2 ]); +else +clear_bit (KFD_TRAP_TYPE_DEBUG , &tma[2 ]); } }
Signature · 1 line
2.25.1
PATCH v3 17/24 drm/amdkfd: add setting trap pc sampling flag
In reply to James ZhuAdd setting trap pc sampling flag.
--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 13 +++++++++++++ 2 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
@@ -1198,6 +1198,8 @@ void kfd_process_set_trap_handler(struct qcm_process_device *qpd, uint64_t tma_addr);void kfd_process_set_trap_debug_flag (struct qcm_process_device *qpd,bool enabled); +void kfd_process_set_trap_pc_sampling_flag (struct qcm_process_device *qpd, +enum kfd_ioctl_pc_sample_method method,bool enabled);/* CWSR initialization */ int kfd_process_init_cwsr_apu (struct kfd_process *process,struct file *filep);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +13 -0
@@ -1460,6 +1460,19 @@ void kfd_process_set_trap_debug_flag(struct qcm_process_device *qpd, } } +void kfd_process_set_trap_pc_sampling_flag (struct qcm_process_device *qpd, +enum kfd_ioctl_pc_sample_method method,bool enabled) +{ +if (qpd->cwsr_kaddr) { +volatile unsigned long *tma = + (volatile unsigned long *)(qpd->cwsr_kaddr +KFD_CWSR_TMA_OFFSET ); +if (enabled) +set_bit (method, &tma[2 ]); +else +clear_bit (method, &tma[2 ]); + } +} +/* * On return the kfd_process is fully operational and will be freed when the * mm is released
Signature · 1 line
2.25.1
PATCH v3 18/24 drm/amdkfd: enable pc sampling stop
In reply to James ZhuEnable pc sampling stop.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 28 +++++++++++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 4 +++ 2 files changed, 29 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +25 -3
@@ -88,10 +88,32 @@ static int kfd_pc_sample_start(struct kfd_process_device *pdd)return -EINVAL ; } -static int kfd_pc_sample_stop (struct kfd_process_device *pdd) +static int kfd_pc_sample_stop (struct kfd_process_device *pdd, +struct pc_sampling_entry *pcs_entry) { -return -EINVAL ; +bool pc_sampling_stop = false; + + pcs_entry->enabled = false; +mutex_lock (&pdd->dev->pcs_data.mutex); + pdd->dev->pcs_data.hosttrap_entry.base.active_count--; +if (!pdd->dev->pcs_data.hosttrap_entry.base.active_count) { +WRITE_ONCE (pdd->dev->pcs_data.hosttrap_entry.base.stop_enable, true); + pc_sampling_stop = true; + } +mutex_unlock (&pdd->dev->pcs_data.mutex); +if (pc_sampling_stop) { +kfd_process_set_trap_pc_sampling_flag (&pdd->qpd, + pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method, false); + +mutex_lock (&pdd->dev->pcs_data.mutex); + pdd->dev->pcs_data.hosttrap_entry.base.target_simd =0 ; + pdd->dev->pcs_data.hosttrap_entry.base.target_wave_slot =0 ; +WRITE_ONCE (pdd->dev->pcs_data.hosttrap_entry.base.stop_enable, false); +mutex_unlock (&pdd->dev->pcs_data.mutex); + } + +return 0 ; } static int kfd_pc_sample_create(struct kfd_process_device *pdd,
@@ -233,7 +255,7 @@ int kfd_pc_sample(struct kfd_process_device *pdd,if (!pcs_entry->enabled)return -EALREADY ;else -return kfd_pc_sample_stop (pdd); +return kfd_pc_sample_stop (pdd, pcs_entry); }return -EINVAL ;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +4 -0
@@ -271,6 +271,10 @@ struct kfd_dev;struct kfd_dev_pc_sampling_data {uint32_t use_count;/* Num of PC sampling sessions */ +uint32_t active_count;/* Num of active sessions */ +uint32_t target_simd;/* target simd for trap */ +uint32_t target_wave_slot;/* target wave slot for trap */ +bool stop_enable;/* pc sampling stop in process */ struct idr pc_sampling_idr;struct kfd_pc_sample_info pc_sample_info; };
Signature · 1 line
2.25.1
PATCH v3 19/24 drm/amdkfd: add queue remapping
In reply to James ZhuAdd queue remapping to ensure that any waves executing the PC sampling part of the trap handler are done before kfd_pc_sample_stop returns, and that no new waves enter that part of the trap handler afterwards. This avoids race conditions that could lead to use-after-free. Unmapping and remapping the queues either waits for the waves to drain, or preempts them with CWSR, which itself executes a trap and waits for previous traps to finish.
--- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 +++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h | 5 +++++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 3 +++ 3 files changed, 19 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +11 -0
@@ -3155,6 +3155,17 @@ int debug_refresh_runlist(struct device_queue_manager *dqm)return debug_map_and_unlock (dqm); } +void remap_queue (struct device_queue_manager *dqm, +enum kfd_unmap_queues_filter filter, +uint32_t filter_param, +uint32_t grace_period) +{ +dqm_lock (dqm); +if (!dqm->dev->kfd->shared_resources.enable_mes) +execute_queues_cpsch (dqm, filter, filter_param, grace_period); +dqm_unlock (dqm); +} +#if defined(CONFIG_DEBUG_FS ) static void seq_reg_dump(struct seq_file *m,
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +5 -0
@@ -303,6 +303,11 @@ int debug_lock_and_unmap(struct device_queue_manager *dqm);int debug_map_and_unlock (struct device_queue_manager *dqm);int debug_refresh_runlist (struct device_queue_manager *dqm); +void remap_queue (struct device_queue_manager *dqm, +enum kfd_unmap_queues_filter filter, +uint32_t filter_param, +uint32_t grace_period); +static inline unsigned int get_sh_mem_bases_32 (struct kfd_process_device *pdd) {return (pdd->lds_base >>16 ) &0xFF ;
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +3 -0
@@ -24,6 +24,7 @@#include "kfd_priv.h" #include "amdgpu_amdkfd.h" #include "kfd_pc_sampling.h" +#include "kfd_device_queue_manager.h" struct supported_pc_sample_info {uint32_t ip_version;
@@ -105,6 +106,8 @@ static int kfd_pc_sample_stop(struct kfd_process_device *pdd,if (pc_sampling_stop) {kfd_process_set_trap_pc_sampling_flag (&pdd->qpd, pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method, false); +remap_queue (pdd->dev->dqm, +KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES ,0 ,USE_DEFAULT_GRACE_PERIOD );mutex_lock (&pdd->dev->pcs_data.mutex); pdd->dev->pcs_data.hosttrap_entry.base.target_simd =0 ;
Signature · 1 line
2.25.1
PATCH v3 20/24 drm/amdkfd: enable pc sampling start
In reply to James ZhuEnable pc sampling start.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 26 +++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +23 -3
@@ -84,9 +84,29 @@ static int kfd_pc_sample_query_cap(struct kfd_process_device *pdd,return 0 ; } -static int kfd_pc_sample_start (struct kfd_process_device *pdd) +static int kfd_pc_sample_start (struct kfd_process_device *pdd, +struct pc_sampling_entry *pcs_entry) { -return -EINVAL ; +bool pc_sampling_start = false; + + pcs_entry->enabled = true; +mutex_lock (&pdd->dev->pcs_data.mutex); +if (!pdd->dev->pcs_data.hosttrap_entry.base.active_count) + pc_sampling_start = true; + pdd->dev->pcs_data.hosttrap_entry.base.active_count++; +mutex_unlock (&pdd->dev->pcs_data.mutex); + +while (pc_sampling_start) { +if (READ_ONCE (pdd->dev->pcs_data.hosttrap_entry.base.stop_enable)) { +usleep_range (1000 ,2000 ); + }else { +kfd_process_set_trap_pc_sampling_flag (&pdd->qpd, + pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method, true); +break ; + } + } + +return 0 ; } static int kfd_pc_sample_stop(struct kfd_process_device *pdd,
@@ -252,7 +272,7 @@ int kfd_pc_sample(struct kfd_process_device *pdd,if (pcs_entry->enabled)return -EALREADY ;else -return kfd_pc_sample_start (pdd); +return kfd_pc_sample_start (pdd, pcs_entry);case KFD_IOCTL_PCS_OP_STOP :if (!pcs_entry->enabled)
Signature · 1 line
2.25.1
PATCH v3 21/24 drm/amdkfd: add pc sampling thread to trigger trap
In reply to James ZhuAdd a kthread to trigger pc sampling trap.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 68 +++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + 2 files changed, 68 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +67 -1
@@ -39,6 +39,66 @@ struct supported_pc_sample_info supported_formats[] = { { IP_VERSION(9, 4, 2), &sample_info_hosttrap_9_0_0 }, }; +static int kfd_pc_sample_thread (void *param) +{ +struct amdgpu_device *adev; +struct kfd_node *node = param; +uint32_t timeout =0 ; + +mutex_lock (&node->pcs_data.mutex); +if (node->pcs_data.hosttrap_entry.base.active_count && + node->pcs_data.hosttrap_entry.base.pc_sample_info.interval && + node->kfd2kgd->trigger_pc_sample_trap) { +switch (node->pcs_data.hosttrap_entry.base.pc_sample_info.type) { +case KFD_IOCTL_PCS_TYPE_TIME_US : + timeout = (uint32_t )node->pcs_data.hosttrap_entry.base.pc_sample_info.interval; +break ; +default : +pr_debug ("PC Sampling type %d not supported." , + node->pcs_data.hosttrap_entry.base.pc_sample_info.type); + } + } +mutex_unlock (&node->pcs_data.mutex); +if (!timeout) +return -EINVAL ; + + adev = node->adev; + +allow_signal (SIGKILL ); +while (!kthread_should_stop () || + !READ_ONCE (node->pcs_data.hosttrap_entry.base.stop_enable)) { + node->kfd2kgd->trigger_pc_sample_trap (adev, node->vm_info.last_vmid_kfd, + &node->pcs_data.hosttrap_entry.base.target_simd, + &node->pcs_data.hosttrap_entry.base.target_wave_slot, + node->pcs_data.hosttrap_entry.base.pc_sample_info.method); +pr_debug_ratelimited ("triggered a host trap." ); + +if (signal_pending (node->pcs_data.hosttrap_entry.base.pc_sample_thread)) +break ; +usleep_range (timeout, timeout +10 ); + } + node->pcs_data.hosttrap_entry.base.pc_sample_thread =NULL ; + +return 0 ; +} + +static int kfd_pc_sample_thread_start (struct kfd_node *node) +{ +char thread_name[16 ]; +int ret =0 ; + +snprintf (thread_name,16 ,"pcs_%08x" , node->adev->ddev.render->index); + node->pcs_data.hosttrap_entry.base.pc_sample_thread = +kthread_run (kfd_pc_sample_thread, node, thread_name); +if (IS_ERR (node->pcs_data.hosttrap_entry.base.pc_sample_thread)) { + ret =PTR_ERR (node->pcs_data.hosttrap_entry.base.pc_sample_thread); + node->pcs_data.hosttrap_entry.base.pc_sample_thread =NULL ; +pr_debug ("Failed to create pc sample thread for %s.\n" , thread_name); + } + +return ret; +} +static int kfd_pc_sample_query_cap (struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *user_args) {
@@ -88,6 +148,7 @@ static int kfd_pc_sample_start(struct kfd_process_device *pdd, struct pc_sampling_entry *pcs_entry) {bool pc_sampling_start = false; +int ret =0 ; pcs_entry->enabled = true;mutex_lock (&pdd->dev->pcs_data.mutex);
@@ -102,11 +163,13 @@ static int kfd_pc_sample_start(struct kfd_process_device *pdd, }else {kfd_process_set_trap_pc_sampling_flag (&pdd->qpd, pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method, true); +if (!pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_thread) + ret =kfd_pc_sample_thread_start (pdd->dev);break ; } } -return 0 ; +return ret; } static int kfd_pc_sample_stop(struct kfd_process_device *pdd,
@@ -124,6 +187,9 @@ static int kfd_pc_sample_stop(struct kfd_process_device *pdd,mutex_unlock (&pdd->dev->pcs_data.mutex);if (pc_sampling_stop) { +kthread_stop (pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_thread); +while (pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_thread) +usleep_range (1000 ,2000 );kfd_process_set_trap_pc_sampling_flag (&pdd->qpd, pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method, false); remap_queue(pdd->dev->dqm,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -276,6 +276,7 @@ struct kfd_dev_pc_sampling_data {uint32_t target_wave_slot;/* target wave slot for trap */ bool stop_enable;/* pc sampling stop in process */ struct idr pc_sampling_idr; +struct task_struct *pc_sample_thread;struct kfd_pc_sample_info pc_sample_info; };
Signature · 1 line
2.25.1
PATCH v3 22/24 drm/amdkfd: add pc sampling release when process release
In reply to James ZhuAdd pc sampling release when process release, it will force to stop all activate sessions with this process.
--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 21 ++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h | 1 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 3 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +21 -0
@@ -300,6 +300,27 @@ static int kfd_pc_sample_destroy(struct kfd_process_device *pdd, uint32_t trace_return 0 ; } +void kfd_pc_sample_release (struct kfd_process_device *pdd) +{ +struct pc_sampling_entry *pcs_entry; +struct idr *idp; +uint32_t id; + +/* force to release all PC sampling task for this process */ + idp = &pdd->dev->pcs_data.hosttrap_entry.base.pc_sampling_idr; +mutex_lock (&pdd->dev->pcs_data.mutex); +idr_for_each_entry (idp, pcs_entry, id) { +if (pcs_entry->pdd != pdd) +continue ; +mutex_unlock (&pdd->dev->pcs_data.mutex); +if (pcs_entry->enabled) +kfd_pc_sample_stop (pdd, pcs_entry); +kfd_pc_sample_destroy (pdd, id, pcs_entry); +mutex_lock (&pdd->dev->pcs_data.mutex); + } +mutex_unlock (&pdd->dev->pcs_data.mutex); +} +int kfd_pc_sample (struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *args) {
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h +1 -0
@@ -30,5 +30,6 @@int kfd_pc_sample (struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *args); +void kfd_pc_sample_release (struct kfd_process_device *pdd);#endif /* KFD_PC_SAMPLING_H_ */
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3 -0
@@ -43,6 +43,7 @@ struct mm_struct;#include "kfd_svm.h" #include "kfd_smi_events.h" #include "kfd_debug.h" +#include "kfd_pc_sampling.h" /* * List of struct kfd_process (field kfd_process).
@@ -1021,6 +1022,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)pr_debug ("Releasing pdd (topology id %d) for process (pasid 0x%x)\n" , pdd->dev->id, p->pasid); +kfd_pc_sample_release (pdd); +kfd_process_device_destroy_cwsr_dgpu (pdd);kfd_process_device_destroy_ib_mem (pdd);
Signature · 1 line
2.25.1
PATCH v3 23/24 drm/amdkfd: set debug trap bit when enabling PC Sampling
In reply to James ZhuFrom: David Yat Sin <[email protected]>
We need the SPI_GDBG_PER_VMID_CNTL.TRAP_EN bit to be set during PC Sampling so that the TTMP registers are valid inside the sampling data. runtime_info.ttmp_setup will be cleared when the user application does the AMDKFD_IOC_RUNTIME_ENABLE ioctl without KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK flag on exit.
It is also not valid to have the debugger attached to a process while PC sampling is enabled so adding some checks to prevent this.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 31 ++++---------- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 22 ++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 ++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 43 +++++++++++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h | 4 +- 5 files changed, 75 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +9 -22
@@ -1775,7 +1775,7 @@ static int kfd_ioctl_pc_sample(struct file *filep,pr_debug ("failed to bind process %p with gpu id 0x%x" , p, args->gpu_id); ret = -ESRCH ; }else { - ret =kfd_pc_sample (pdd, args); + ret =kfd_pc_sample (p, pdd, args); } }mutex_unlock (&p->mutex);
@@ -2808,26 +2808,9 @@ static int runtime_enable(struct kfd_process *p, uint64_t r_debug, p->runtime_info.runtime_state =DEBUG_RUNTIME_STATE_ENABLED ; p->runtime_info.r_debug = r_debug; - p->runtime_info.ttmp_setup = enable_ttmp_setup; -if (p->runtime_info.ttmp_setup) { -for (i =0 ; i < p->n_pdds; i++) { -struct kfd_process_device *pdd = p->pdds[i]; - -if (!kfd_dbg_is_rlc_restore_supported (pdd->dev)) { -amdgpu_gfx_off_ctrl (pdd->dev->adev, false); - pdd->dev->kfd2kgd->enable_debug_trap ( - pdd->dev->adev, - true, - pdd->dev->vm_info.last_vmid_kfd); - }else if (kfd_dbg_is_per_vmid_supported (pdd->dev)) { - pdd->spi_dbg_override = pdd->dev->kfd2kgd->enable_debug_trap ( - pdd->dev->adev, - false, -0 ); - } - } - } +if (enable_ttmp_setup) +kfd_dbg_enable_ttmp_setup (p); retry:if (p->debug_trap_enabled) {
@@ -2976,9 +2959,13 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v goto out; } -/* Check if target is still PTRACED. */ rcu_read_lock (); -if (target != p && args->op !=KFD_IOC_DBG_TRAP_DISABLE + +if (kfd_pc_sampling_enabled (target)) { +pr_debug ("Cannot enable debug trap on PID:%d because PC Sampling active\n" , args->pid); + r = -EBUSY ; +/* Check if target is still PTRACED. */ + }else if (target != p && args->op !=KFD_IOC_DBG_TRAP_DISABLE &&ptrace_parent (target->lead_thread) != current) {pr_err ("PID %i is not PTRACED and cannot be debugged\n" , args->pid); r = -EPERM ;
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +22 -0
@@ -1118,3 +1118,25 @@ void kfd_dbg_set_enabled_debug_exception_mask(struct kfd_process *target,mutex_unlock (&target->event_mutex); } + +void kfd_dbg_enable_ttmp_setup (struct kfd_process *p) +{ +int i; + p->runtime_info.ttmp_setup = true; +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (!kfd_dbg_is_rlc_restore_supported (pdd->dev)) { +amdgpu_gfx_off_ctrl (pdd->dev->adev, false); + pdd->dev->kfd2kgd->enable_debug_trap ( + pdd->dev->adev, + true, + pdd->dev->vm_info.last_vmid_kfd); + }else if (kfd_dbg_is_per_vmid_supported (pdd->dev)) { + pdd->spi_dbg_override = pdd->dev->kfd2kgd->enable_debug_trap ( + pdd->dev->adev, + false, +0 ); + } + } +}
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +3 -0
@@ -90,6 +90,9 @@ int kfd_dbg_trap_device_snapshot(struct kfd_process *target,void kfd_dbg_set_enabled_debug_exception_mask (struct kfd_process *target,uint64_t exception_set_mask); + +void kfd_dbg_enable_ttmp_setup (struct kfd_process *p); +/* * If GFX off is enabled, chips that do not support RLC restore for the debug * registers will disable GFX off temporarily for the entire debug session.
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +38 -5
99 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h +3 -1
@@ -28,8 +28,10 @@#include "amdgpu.h" #include "kfd_priv.h" -int kfd_pc_sample (struct kfd_process_device *pdd, +int kfd_pc_sample (struct kfd_process *p,struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *args);void kfd_pc_sample_release (struct kfd_process_device *pdd); +bool kfd_pc_sampling_enabled (struct kfd_process *p); +#endif /* KFD_PC_SAMPLING_H_ */
Signature · 1 line
2.25.1
Re: [PATCH v3 23/24] drm/amdkfd: set debug trap bit when enabling PC Sampling
Quoted 136 lines · James Zhu
From: David Yat Sin<[email protected]>
We need the SPI_GDBG_PER_VMID_CNTL.TRAP_EN bit to be set during PC Sampling so that the TTMP registers are valid inside the sampling data. runtime_info.ttmp_setup will be cleared when the user application does the
AMDKFD_IOC_RUNTIME_ENABLEioctl withoutKFD_RUNTIME_ENABLE_MODE_ENABLE_MASKflag on exit.It is also not valid to have the debugger attached to a process while PC sampling is enabled so adding some checks to prevent this.
Signed-off-by David Yat Sin<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 31 ++++---------- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 22 ++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 ++ drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 43 +++++++++++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h | 4 +- 5 files changed, 75 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +9
-22@@ -1775,7 +1775,7 @@ static int kfd_ioctl_pc_sample(struct file *filep,pr_debug ("failed to bind process %p with gpu id 0x%x" , p, args->gpu_id); ret = -ESRCH ; }else { - ret =kfd_pc_sample (pdd, args); + ret =kfd_pc_sample (p, pdd, args); } }mutex_unlock (&p->mutex);@@ -2808,26 +2808,9 @@ static int runtime_enable(struct kfd_process *p, uint64_t r_debug, p->runtime_info.runtime_state =DEBUG_RUNTIME_STATE_ENABLED ; p->runtime_info.r_debug = r_debug; - p->runtime_info.ttmp_setup = enable_ttmp_setup; -if (p->runtime_info.ttmp_setup) { -for (i =0 ; i < p->n_pdds; i++) { -struct kfd_process_device *pdd = p->pdds[i]; - -if (!kfd_dbg_is_rlc_restore_supported (pdd->dev)) { -amdgpu_gfx_off_ctrl (pdd->dev->adev, false); - pdd->dev->kfd2kgd->enable_debug_trap ( - pdd->dev->adev, - true, - pdd->dev->vm_info.last_vmid_kfd); - }else if (kfd_dbg_is_per_vmid_supported (pdd->dev)) { - pdd->spi_dbg_override = pdd->dev->kfd2kgd->enable_debug_trap ( - pdd->dev->adev, - false, -0 ); - } - } - } +if (enable_ttmp_setup) +kfd_dbg_enable_ttmp_setup (p); retry:if (p->debug_trap_enabled) {@@ -2976,9 +2959,13 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v goto out; } -/* Check if target is still PTRACED. */ rcu_read_lock (); -if (target != p && args->op !=KFD_IOC_DBG_TRAP_DISABLE + +if (kfd_pc_sampling_enabled (target)) { +pr_debug ("Cannot enable debug trap on PID:%d because PC Sampling active\n" , args->pid); + r = -EBUSY ; +/* Check if target is still PTRACED. */ + }else if (target != p && args->op !=KFD_IOC_DBG_TRAP_DISABLE &&ptrace_parent (target->lead_thread) != current) {pr_err ("PID %i is not PTRACED and cannot be debugged\n" , args->pid); r = -EPERM ;drivers/gpu/drm/amd/amdkfd/kfd_debug.c +22
-0@@ -1118,3 +1118,25 @@ void kfd_dbg_set_enabled_debug_exception_mask(struct kfd_process *target,mutex_unlock (&target->event_mutex); } + +void kfd_dbg_enable_ttmp_setup (struct kfd_process *p) +{ +int i; + p->runtime_info.ttmp_setup = true; +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (!kfd_dbg_is_rlc_restore_supported (pdd->dev)) { +amdgpu_gfx_off_ctrl (pdd->dev->adev, false); + pdd->dev->kfd2kgd->enable_debug_trap ( + pdd->dev->adev, + true, + pdd->dev->vm_info.last_vmid_kfd); + }else if (kfd_dbg_is_per_vmid_supported (pdd->dev)) { + pdd->spi_dbg_override = pdd->dev->kfd2kgd->enable_debug_trap ( + pdd->dev->adev, + false, +0 ); + } + } +}drivers/gpu/drm/amd/amdkfd/kfd_debug.h +3
-0@@ -90,6 +90,9 @@ int kfd_dbg_trap_device_snapshot(struct kfd_process *target,void kfd_dbg_set_enabled_debug_exception_mask (struct kfd_process *target,uint64_t exception_set_mask); + +void kfd_dbg_enable_ttmp_setup (struct kfd_process *p); +/* * If GFX off is enabled, chips that do not support RLC restore for the debug * registers will disable GFX off temporarily for the entire debug session. drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +1
-0@@ -24,6 +24,7 @@#include "kfd_priv.h" #include "amdgpu_amdkfd.h" #include "kfd_pc_sampling.h" +#include "kfd_debug.h" #include "kfd_device_queue_manager.h" struct supported_pc_sample_info {
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c struct supported_pc_sample_info supported_formats[] = { · line 44
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +2
-0@@ -39,6 +40,19 @@ struct supported_pc_sample_info supported_formats[] = { { IP_VERSION(9, 4, 2), &sample_info_hosttrap_9_0_0 }, }; +/* Checks whether PC Sampling is enabled on any devices in use by this process */ +bool kfd_pc_sampling_enabled (struct kfd_process *p) {
[JZ] why not add flag p->enabled_trap_type eg0x1. for debug, 0x2 for host trap 0x4 for stochastic. ...
.... update p->enabled_trap_type after pcs creation successfully, clear when at the end of pcs destroy, then we needn't this function.
Quoted 17 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +11
-0+int i; + +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method) +return true; + } +return false; +} +static int kfd_pc_sample_thread (void *param) {struct amdgpu_device *adev;@@ -99,13 +113,19 @@ static int kfd_pc_sample_thread_start(struct kfd_node *node)return ret; }
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c static int kfd_pc_sample_thread_start(struct kfd_node *node) · line 123
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +2
-1-static int kfd_pc_sample_query_cap (struct kfd_process_device *pdd, +static int kfd_pc_sample_query_cap (struct kfd_process *p,struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *user_args) {uint64_t sample_offset;int num_method =0 ;int i; +if (p->debug_trap_enabled) {
[JZ] Move to kfd_pc_sample(...)
Quoted 18 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +6
-1+pr_debug ("Cannot have PC Sampling and debug trap simultaneously" ); + user_args->num_sample_info =0 ; +return 0 ; + } +for (i =0 ; i <ARRAY_SIZE (supported_formats); i++)if (KFD_GC_VERSION (pdd->dev) == supported_formats[i].ip_version) num_method++;@@ -205,7 +225,7 @@ static int kfd_pc_sample_stop(struct kfd_process_device *pdd,return 0 ; } -static int kfd_pc_sample_create (struct kfd_process_device *pdd, +static int kfd_pc_sample_create (struct kfd_process *p,struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *user_args) {struct kfd_pc_sample_info *supported_format =NULL ;
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c static int kfd_pc_sample_create(struct kfd_process_device *pdd, · line 240
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +1
-0@@ -217,6 +237,11 @@ static int kfd_pc_sample_create(struct kfd_process_device *pdd,if (user_args->num_sample_info !=1 )return -EINVAL ; +if (p->debug_trap_enabled) {
[JZ] Move to kfd_pc_sample(...)
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +4
-0+pr_debug ("Cannot have PC Sampling and debug trap simultaneously" ); +return -EBUSY ; + } + ret =copy_from_user (&user_info, (void __user *) user_args->sample_info_ptr,sizeof (struct kfd_pc_sample_info ));if (ret) {
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c static int kfd_pc_sample_create(struct kfd_process_device *pdd, · line 305
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +3
-0@@ -275,6 +300,14 @@ static int kfd_pc_sample_create(struct kfd_process_device *pdd, pcs_entry->pdd = pdd; user_args->trace_id = (uint32_t )i; +/* +* Set SPI_GDBG_PER_VMID_CNTL.TRAP_EN so that TTMP registers are valid in the sampling data +* p->runtime_info.ttmp_setup will be cleared when user application calls runtime_disable
[JZ] why don't put enable into runtime_enable with the same code level.
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c static int kfd_pc_sample_create(struct kfd_process_device *pdd, · line 308
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +3
-0+* on exit. +*/ +if (!p->runtime_info.ttmp_setup)
[JZ] this check can be put into kfd_dbg_enable_ttmp_setup
Quoted 42 lines
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c +4
-3+kfd_dbg_enable_ttmp_setup (p);pr_debug ("alloc pcs_entry = %p, trace_id = 0x%x on gpu 0x%x" , pcs_entry, i, pdd->dev->id);return 0 ;@@ -321,7 +354,7 @@ void kfd_pc_sample_release(struct kfd_process_device *pdd)mutex_unlock (&pdd->dev->pcs_data.mutex); } -int kfd_pc_sample (struct kfd_process_device *pdd, +int kfd_pc_sample (struct kfd_process *p,struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *args) {struct pc_sampling_entry *pcs_entry;@@ -344,10 +377,10 @@ int kfd_pc_sample(struct kfd_process_device *pdd,switch (args->op) {case KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES : -return kfd_pc_sample_query_cap (pdd, args); +return kfd_pc_sample_query_cap (p, pdd, args);case KFD_IOCTL_PCS_OP_CREATE : -return kfd_pc_sample_create (pdd, args); +return kfd_pc_sample_create (p, pdd, args);case KFD_IOCTL_PCS_OP_DESTROY :if (pcs_entry->enabled)drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.h +3
-1@@ -28,8 +28,10 @@#include "amdgpu.h" #include "kfd_priv.h" -int kfd_pc_sample (struct kfd_process_device *pdd, +int kfd_pc_sample (struct kfd_process *p,struct kfd_process_device *pdd,struct kfd_ioctl_pc_sample_args __user *args);void kfd_pc_sample_release (struct kfd_process_device *pdd); +bool kfd_pc_sampling_enabled (struct kfd_process *p); +#endif /* KFD_PC_SAMPLING_H_ */
PATCH v3 24/24 drm/amdkfd: bump kfd ioctl minor version for pc sampling availability
In reply to James ZhuBump the minor version to declare pc sampling feature is now available.
--- include/uapi/linux/kfd_ioctl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/kfd_ioctl.h +2 -1
@@ -40,9 +40,10 @@* - 1.12 - Add DMA buf export ioctl * - 1.13 - Add debugger API * - 1.14 - Update kfd_event_data +* - 1.15 - Add PC Sampling ioctl */ #define KFD_IOCTL_MAJOR_VERSION 1 -#define KFD_IOCTL_MINOR_VERSION 14 +#define KFD_IOCTL_MINOR_VERSION 15struct kfd_ioctl_get_version_args {__u32 major_version;/* from KFD */
Signature · 1 line
2.25.1