drm/amdkfd: Provide SMI events watch
Subsystems (3)
PATCH v3 1/1 drm/amdkfd: Provide SMI events watch
When the compute is malfunctioning or performance drops, the system admin will use SMI (System Management Interface) tool to monitor/diagnostic what went wrong. This patch provides an event watch interface for the user space to register events they are interested. After the event is registered, the user can use annoymous file descriptor's poll function with wait-time specified to wait for the event to happen. Once the event happens, the user can use read() to retrieve information related to the event.
VM fault event is done in this patch.
v2: - remove UNREGISTER and add event ENABLE/DISABLE
- correct kfifo usage
- move event message API to kfd_ioctl.h
v3: send the event msg in text than in binary
--- drivers/gpu/drm/amd/amdkfd/Makefile | 1 + drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c | 2 + drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 30 ++++ drivers/gpu/drm/amd/amdkfd/kfd_device.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 2 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 13 ++ drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 174 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h | 42 ++++++ include/uapi/linux/kfd_ioctl.h | 32 ++++- 9 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h
drivers/gpu/drm/amd/amdkfd/Makefile +1 -0
@@ -53,6 +53,7 @@ AMDKFD_FILES := $(AMDKFD_PATH)/kfd_module.o \ $(AMDKFD_PATH)/kfd_int_process_v9.o \ $(AMDKFD_PATH)/kfd_dbgdev.o \ $(AMDKFD_PATH)/kfd_dbgmgr.o \ + $(AMDKFD_PATH)/kfd_smi_events.o \ $(AMDKFD_PATH)/kfd_crat.o ifneq ($(CONFIG_AMD_IOMMU_V2),)
drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c +2 -0
@@ -24,6 +24,7 @@#include "kfd_events.h" #include "cik_int.h" #include "amdgpu_amdkfd.h" +#include "kfd_smi_events.h" static bool cik_event_interrupt_isr(struct kfd_dev *dev, const uint32_t *ih_ring_entry,
@@ -107,6 +108,7 @@ static void cik_event_interrupt_wq(struct kfd_dev *dev, ihre->source_id == CIK_INTSRC_GFX_MEM_PROT_FAULT) {struct kfd_vm_fault_info info; +kfd_smi_event_update_vmfault (dev, pasid);kfd_process_vm_fault (dev->dqm, pasid);memset (&info,0 ,sizeof (info));
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +30 -0
@@ -39,6 +39,7 @@#include "kfd_device_queue_manager.h" #include "kfd_dbgmgr.h" #include "amdgpu_amdkfd.h" +#include "kfd_smi_events.h" static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *);
@@ -1243,6 +1244,32 @@ static int kfd_ioctl_acquire_vm(struct file *filep, struct kfd_process *p,return ret; } +/* Handle requests for watching SMI events */ +static int kfd_ioctl_smi_events (struct file *filep, +struct kfd_process *p,void *data) +{ +struct kfd_ioctl_smi_events_args *args = data; +struct kfd_dev *dev; + + dev =kfd_device_by_id (args->gpu_id); +if (!dev) +return -EINVAL ; + +switch (args->op) { +case KFD_SMI_EVENTS_REGISTER : +/* register the device */ +return kfd_smi_event_register (dev, &args->data); +case KFD_SMI_EVENTS_ENABLE : +/* subscribe events to the device */ +return kfd_smi_event_enable (dev, args->events); +case KFD_SMI_EVENTS_DISABLE : +/* unsubscribe events */ +return kfd_smi_event_disable (dev, args->events); + } + +return -EINVAL ; +} +bool kfd_dev_is_large_bar (struct kfd_dev *dev) {struct kfd_local_mem_info mem_info;
@@ -1827,6 +1854,9 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {AMDKFD_IOCTL_DEF (AMDKFD_IOC_ALLOC_QUEUE_GWS , kfd_ioctl_alloc_queue_gws,0 ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_SMI_EVENTS , + kfd_ioctl_smi_events, 0), };#define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +1 -0
@@ -532,6 +532,7 @@ struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, kfd->device_info = device_info; kfd->pdev = pdev; kfd->init_complete = false; + kfd->smi_events.registered = false; kfd->kfd2kgd = f2g;atomic_set (&kfd->compute_profile,0 );
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
@@ -24,6 +24,7 @@#include "kfd_events.h" #include "soc15_int.h" #include "kfd_device_queue_manager.h" +#include "kfd_smi_events.h" static bool event_interrupt_isr_v9(struct kfd_dev *dev, const uint32_t *ih_ring_entry,
@@ -117,6 +118,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev, info.prot_read = ring_id &0x10 ; info.prot_write = ring_id &0x20 ; +kfd_smi_event_update_vmfault (dev, pasid);kfd_process_vm_fault (dev->dqm, pasid);kfd_signal_vm_fault_event (dev, pasid, &info); }
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +13 -0
@@ -223,6 +223,16 @@ struct kfd_vmid_info {uint32_t vmid_num_kfd; }; +struct kfd_smi_events { +struct mutex smi_mutex; +/* device is registered to watch events */ +bool registered; +/* events enabled */ +uint64_t events; +struct kfifo fifo; +wait_queue_head_t wait_queue; +}; +struct kfd_dev {struct kgd_dev *kgd;
@@ -309,6 +319,9 @@ struct kfd_dev {/* Global GWS resource shared b/t processes*/ void *gws; + +/* if this device is in SMI events watch */ +struct kfd_smi_events smi_events; };enum kfd_mempool {
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c new file +174 -0
174 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h new file +42 -0
42 lines not on this page · raw message
include/uapi/linux/kfd_ioctl.h +31 -1
@@ -442,6 +442,33 @@ struct kfd_ioctl_import_dmabuf_args {__u32 dmabuf_fd;/* to KFD */ }; +/* +* KFD SMI(System Management Interface) events +*/ +enum kfd_smi_events_op { +KFD_SMI_EVENTS_REGISTER =1 , +KFD_SMI_EVENTS_ENABLE , +KFD_SMI_EVENTS_DISABLE +}; + +/* Event type (defined by bitmask) */ +#define KFD_SMI_EVENT_VMFAULT 0x0000000000000001 + +struct kfd_ioctl_smi_events_args { +__u32 op;/* to KFD */ +__u64 events;/* to KFD */ +__u32 gpu_id;/* to KFD */ +__u32 data;/* from KFD */ +}; + +/* 1. All messages must start with (hex)uint64_event(16) + space(1) = 17 bytes +* 2. VmFault msg = (hex)uint32_pid(8) + space(1) + task name(16) = 25 +* When a new event msg uses more memory, change the calculation here. +* 3. End with \n(1) +* 17 + 25 + 1 = 43 +*/ +#define KFD_SMI_MAX_EVENT_MSG 43 +/* Register offset inside the remapped mmio page */ enum kfd_mmio_remap {
@@ -546,7 +573,10 @@ enum kfd_mmio_remap {#define AMDKFD_IOC_ALLOC_QUEUE_GWS \ AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args) +#define AMDKFD_IOC_SMI_EVENTS \ + AMDKFD_IOWR(0x1F, struct kfd_ioctl_smi_events_args) +#define AMDKFD_COMMAND_START 0x01 -#define AMDKFD_COMMAND_END 0x1F +#define AMDKFD_COMMAND_END 0x20#endif
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx