drm/amdgpu: Don't enable sdma 4.4.5 CTXEMPTY interrupt
Subsystems (3)
PATCH 1/6 drm/amdgpu: Don't enable sdma 4.4.5 CTXEMPTY interrupt
The sdma context empty interrupt is dropped in amdgpu_irq_dispatch as unregistered interrupt src_id 243, this interrupt accounts to 1/3 of total interrupts and causes IH primary ring overflow when running stressful benchmark application. Disable this interrupt has no side effect found.
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +5 -3
@@ -973,10 +973,12 @@ static int sdma_v4_4_2_inst_start(struct amdgpu_device *adev,/* set utc l1 enable flag always to 1 */ temp =RREG32_SDMA (i, regSDMA_CNTL); temp =REG_SET_FIELD (temp,SDMA_CNTL ,UTC_L1_ENABLE ,1 ); -/* enable context empty interrupt during initialization */ - temp =REG_SET_FIELD (temp,SDMA_CNTL ,CTXEMPTY_INT_ENABLE ,1 ); -WREG32_SDMA (i, regSDMA_CNTL, temp); +if (amdgpu_ip_version (adev,SDMA0_HWIP ,0 ) <IP_VERSION (4 ,4 ,5 )) { +/* enable context empty interrupt during initialization */ + temp =REG_SET_FIELD (temp,SDMA_CNTL ,CTXEMPTY_INT_ENABLE ,1 ); +WREG32_SDMA (i, regSDMA_CNTL, temp); + }if (!amdgpu_sriov_vf (adev)) {if (adev->firmware.load_type !=AMDGPU_FW_LOAD_PSP ) {/* unhalt engine */
Signature · 1 line
2.47.1
PATCH 2/6 drm/amdkfd: KFD interrupt access ih_fifo data in-place
To handle 40000 to 80000 interrupts per second running CPX mode with 4 streams/queues per KFD node, KFD interrupt handler becomes the performance bottleneck.
Remove the kfifo_out memcpy overhead by accessing ih_fifo data in-place and updating rptr with kfifo_skip_count.
--- drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 35 +++++++++------------- 1 file changed, 14 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +14 -21
@@ -114,50 +114,43 @@ void kfd_interrupt_exit(struct kfd_node *node)*/ bool enqueue_ih_ring_entry (struct kfd_node *node,const void *ih_ring_entry) { -int count; - - count =kfifo_in (&node->ih_fifo, ih_ring_entry, - node->kfd->device_info.ih_ring_entry_size); -if (count != node->kfd->device_info.ih_ring_entry_size) { +if (kfifo_is_full (&node->ih_fifo)) {dev_dbg_ratelimited (node->adev->dev, -"Interrupt ring overflow, dropping interrupt %d\n" , - count); +"Interrupt ring overflow, dropping interrupt\n" );return false; } +kfifo_in (&node->ih_fifo, ih_ring_entry, node->kfd->device_info.ih_ring_entry_size);return true; }/* * Assumption: single reader/writer. This function is not re-entrant */ -static bool dequeue_ih_ring_entry (struct kfd_node *node,void *ih_ring_entry) +static bool dequeue_ih_ring_entry (struct kfd_node *node,u32 **ih_ring_entry) {int count; - count =kfifo_out (&node->ih_fifo, ih_ring_entry, - node->kfd->device_info.ih_ring_entry_size); - -WARN_ON (count && count != node->kfd->device_info.ih_ring_entry_size); +if (kfifo_is_empty (&node->ih_fifo)) +return false; + count =kfifo_out_linear_ptr (&node->ih_fifo, ih_ring_entry, + node->kfd->device_info.ih_ring_entry_size); +WARN_ON (count != node->kfd->device_info.ih_ring_entry_size);return count == node->kfd->device_info.ih_ring_entry_size; }static void interrupt_wq (struct work_struct *work) { - struct kfd_node *dev = container_of(work, struct kfd_node, - interrupt_work); -uint32_t ih_ring_entry[KFD_MAX_RING_ENTRY_SIZE ]; + struct kfd_node *dev = container_of(work, struct kfd_node, interrupt_work); +uint32_t *ih_ring_entry;unsigned long start_jiffies = jiffies; -if (dev->kfd->device_info.ih_ring_entry_size >sizeof (ih_ring_entry)) { -dev_err_once (dev->adev->dev,"Ring entry too small\n" ); -return ; - } - -while (dequeue_ih_ring_entry (dev, ih_ring_entry)) { +while (dequeue_ih_ring_entry (dev, &ih_ring_entry)) { dev->kfd->device_info.event_interrupt_class->interrupt_wq (dev, ih_ring_entry); +kfifo_skip_count (&dev->ih_fifo, dev->kfd->device_info.ih_ring_entry_size); +if (time_is_before_jiffies (start_jiffies +HZ )) {/* If we spent more than a second processing signals, * reschedule the worker to avoid soft-lockup warnings
Signature · 1 line
2.47.1
PATCH 3/6 drm/amdgpu: Optimize gfx v9 GPU page fault handling
In reply to Philip YangAfter GPU page fault, there are lots of page fault interrupts generated at short period even with CAM filter enabled because the fault address is different. Each page fault copy to KFD ih fifo to send event to user space by KFD interrupt worker, this could cause KFD ih fifo overflow while other processes generate events at same time.
KFD process is aborted after GPU page fault, we only need one GPU page fault interrupt sent to KFD ih fifo to send memory exception event to user space.
Incease KFD ih fifo size to 2 times of IH primary ring size, to handle the burst events case.
This patch handle the gfx v9 path, cover retry on/off and CAM filter on/off cases.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 10 ++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 4 ++ drivers/gpu/drm/amd/amdkfd/kfd_device.c | 67 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 + 5 files changed, 85 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +10 -0
@@ -433,6 +433,9 @@ void kgd2kfd_unlock_kfd(void);int kgd2kfd_start_sched (struct kfd_dev *kfd,uint32_t node_id);int kgd2kfd_stop_sched (struct kfd_dev *kfd,uint32_t node_id);bool kgd2kfd_compute_active (struct kfd_dev *kfd,uint32_t node_id); +bool kgd2kfd_vmfault_fast_path (struct amdgpu_device *adev,struct amdgpu_iv_entry *entry, +bool retry_fault); +#else static inline int kgd2kfd_init (void ) {
@@ -518,5 +521,12 @@ static inline bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id) {return false; } + +static bool kgd2kfd_vmfault_fast_path (struct amdgpu_device *adev,struct amdgpu_iv_entry *entry, +bool retry_fault) +{ +return false; +} +#endif #endif /* AMDGPU_AMDKFD_H_INCLUDED */
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
@@ -64,6 +64,7 @@#include "amdgpu_ras.h" #include "amdgpu_xgmi.h" +#include "kfd_priv.h" /* add these here since we already include dce12 headers and these are for DCN */ #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION 0x055d
@@ -623,6 +624,9 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, } } +if (kgd2kfd_vmfault_fast_path (adev, entry, retry_fault)) +return 1 ; +if (!printk_ratelimit ())return 0 ;
drivers/gpu/drm/amd/amdkfd/kfd_device.c +67 -0
73 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +1 -1
@@ -46,7 +46,7 @@#include <linux/kfifo.h> #include "kfd_priv.h" -#define KFD_IH_NUM_ENTRIES 8192 +#define KFD_IH_NUM_ENTRIES 16384static void interrupt_wq (struct work_struct *);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -0
@@ -1003,6 +1003,9 @@ struct kfd_process {struct semaphore runtime_enable_sema;bool is_runtime_retry;struct kfd_runtime_info runtime_info; + +/* if gpu page fault sent to KFD */ +bool gpu_page_fault; };#define KFD_PROCESS_TABLE_SIZE 5/* bits: 32 entries */
Signature · 1 line
2.47.1
PATCH 4/6 drm/amdkfd: Queue interrupt work to different CPU
In reply to Philip YangFor CPX mode, each KFD node has interrupt worker to process ih_fifo to send events to user space. Currently all interrupt workers of same adev queue to same CPU, all workers execution are actually serialized and this cause KFD ih_fifo overflow when CPU usage is high.
Use per-GPU unbounded highpri queue with number of workers equals to number of partitions, let queue_work select the next CPU round robin among the local CPUs of same NUMA.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 25 ++++++++-------------- drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 25 ++++++++-------------- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 ++- 3 files changed, 20 insertions(+), 33 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +9 -16
@@ -649,6 +649,14 @@ static void kfd_cleanup_nodes(struct kfd_dev *kfd, unsigned int num_nodes)struct kfd_node *knode;unsigned int i; +/* +* flush_work ensures that there are no outstanding +* work-queue items that will access interrupt_ring. New work items +* can't be created because we stopped interrupt handling above. +*/ +flush_workqueue (kfd->ih_wq); +destroy_workqueue (kfd->ih_wq); +for (i =0 ; i < num_nodes; i++) { knode = kfd->nodes[i];device_queue_manager_uninit (knode->dqm);
@@ -1066,21 +1074,6 @@ static int kfd_resume(struct kfd_node *node)return err; } -static inline void kfd_queue_work (struct workqueue_struct *wq, -struct work_struct *work) -{ -int cpu, new_cpu; - - cpu = new_cpu =smp_processor_id (); -do { - new_cpu =cpumask_next (new_cpu, cpu_online_mask) % nr_cpu_ids; -if (cpu_to_node (new_cpu) ==numa_node_id ()) -break ; - }while (cpu != new_cpu); - -queue_work_on (new_cpu, wq, work); -} -/* This is called directly from KGD at ISR. */ void kgd2kfd_interrupt (struct kfd_dev *kfd,const void *ih_ring_entry) {
@@ -1106,7 +1099,7 @@ void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry) patched_ihre, &is_patched) && enqueue_ih_ring_entry(node, is_patched ? patched_ihre : ih_ring_entry)) { -kfd_queue_work (node->ih_wq, &node->interrupt_work); +queue_work (node->kfd->ih_wq, &node->interrupt_work);spin_unlock_irqrestore (&node->interrupt_lock, flags);return ; }
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +9 -16
@@ -62,11 +62,14 @@ int kfd_interrupt_init(struct kfd_node *node)return r; } - node->ih_wq =alloc_workqueue ("KFD IH" ,WQ_HIGHPRI ,1 ); -if (unlikely (!node->ih_wq)) { -kfifo_free (&node->ih_fifo); -dev_err (node->adev->dev,"Failed to allocate KFD IH workqueue\n" ); -return -ENOMEM ; +if (!node->kfd->ih_wq) { + node->kfd->ih_wq =alloc_workqueue ("KFD IH" ,WQ_HIGHPRI |WQ_UNBOUND , + node->kfd->num_nodes); +if (unlikely (!node->kfd->ih_wq)) { +kfifo_free (&node->ih_fifo); +dev_err (node->adev->dev,"Failed to allocate KFD IH workqueue\n" ); +return -ENOMEM ; + } }spin_lock_init (&node->interrupt_lock);
@@ -96,16 +99,6 @@ void kfd_interrupt_exit(struct kfd_node *node)spin_lock_irqsave (&node->interrupt_lock, flags); node->interrupts_active = false;spin_unlock_irqrestore (&node->interrupt_lock, flags); - -/* -* flush_work ensures that there are no outstanding -* work-queue items that will access interrupt_ring. New work items -* can't be created because we stopped interrupt handling above. -*/ -flush_workqueue (node->ih_wq); - -destroy_workqueue (node->ih_wq); -kfifo_free (&node->ih_fifo); }
@@ -155,7 +148,7 @@ static void interrupt_wq(struct work_struct *work)/* If we spent more than a second processing signals, * reschedule the worker to avoid soft-lockup warnings */ -queue_work (dev->ih_wq, &dev->interrupt_work); +queue_work (dev->kfd->ih_wq, &dev->interrupt_work);break ; } }
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
@@ -274,7 +274,6 @@ struct kfd_node {/* Interrupts */ struct kfifo ih_fifo; -struct workqueue_struct *ih_wq;struct work_struct interrupt_work;spinlock_t interrupt_lock;
@@ -367,6 +366,8 @@ struct kfd_dev {struct kfd_node *nodes[MAX_KFD_NODES ];unsigned int num_nodes; +struct workqueue_struct *ih_wq; +/* Kernel doorbells for KFD device */ struct amdgpu_bo *doorbells;
Signature · 1 line
2.47.1
PATCH 5/6 drm/amdkfd: Improve signal event slow path
In reply to Philip YangIf event slot is not signaled, kfd_signal_event_interrupt goes to slow path to scan all event slots to find the signaled event, this is needed for old ASICs that don't have the event ID or the event IDs are incorrect in the IH payload.
There is case that GPU signal the same event twice, then driver process the first event interrupt, set_event and event slot is auto-reset, then for the second event interrupt, KFD goes to slow path as event is not signaled, just drop the second event interrupt because the application only need wakeup once.
--- drivers/gpu/drm/amd/amdkfd/kfd_events.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +11 -0
@@ -748,6 +748,16 @@ void kfd_signal_event_interrupt(u32 pasid, uint32_t partial_id,uint64_t *slots =page_slots (p->signal_page);uint32_t id; +/* +* If id is valid but slot is not signaled, GPU may signal the same event twice +* before driver have chance to process the first interrupt, then signal slot is +* auto-reset after set_event wakeup the user space, just drop the second event as +* the application only need wakeup once. +*/ +if ((valid_id_bits >31 || (1U << valid_id_bits) >=KFD_SIGNAL_EVENT_LIMIT ) && + partial_id <KFD_SIGNAL_EVENT_LIMIT && slots[partial_id] ==UNSIGNALED_EVENT_SLOT ) + goto out_unlock; +if (valid_id_bits)pr_debug_ratelimited ("Partial ID invalid: %u (%u valid bits)\n" , partial_id, valid_id_bits);
@@ -776,6 +786,7 @@ void kfd_signal_event_interrupt(u32 pasid, uint32_t partial_id, } } +out_unlock:rcu_read_unlock ();kfd_unref_process (p); }
Signature · 1 line
2.47.1
PATCH 6/6 drm/amdgpu: Show warning message if IH ring overflow
In reply to Philip YangIf IH primary ring and KFD ih fifo overflows, we may miss CP, SDMA interrupts and cause application soft hang. Show warning message with ring name if overflow happens.
Add function to get ih ring name to avoid duplicating it. To keep warning message consistent between GPU generations, change all *_ih.c except ASICs older than Vega which has only one ih ring.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 6 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 1 + drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/vega10_ih.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/vega20_ih.c | 5 ++--- drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +6 -0
@@ -298,3 +298,9 @@ uint64_t amdgpu_ih_decode_iv_ts_helper(struct amdgpu_ih_ring *ih, u32 rptr, dw2 =le32_to_cpu (ih->ring[ring_index +2 ]);return dw1 | ((u64)(dw2 &0xffff ) <<32 ); } + +const char *amdgpu_ih_ring_name (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih) +{ +return ih == &adev->irq.ih ?"ih" : ih == &adev->irq.ih_soft ?"sw ih" : + ih == &adev->irq.ih1 ?"ih1" : ih == &adev->irq.ih2 ?"ih2" :"unknown" ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1 -0
@@ -110,4 +110,5 @@ void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, struct amdgpu_iv_entry *entry);uint64_t amdgpu_ih_decode_iv_ts_helper (struct amdgpu_ih_ring *ih,u32 rptr,signed int offset); +const char *amdgpu_ih_ring_name (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);#endif
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +2 -3
@@ -434,9 +434,8 @@ static u32 navi10_ih_get_wptr(struct amdgpu_device *adev,* this should allow us to catch up. */ tmp = (wptr +32 ) & ih->ptr_mask; -dev_warn (adev->dev,"IH ring buffer overflow " -"(0x%08X, 0x%08X, 0x%08X)\n" , - wptr, ih->rptr, tmp); +dev_warn (adev->dev,"%s ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n" , +amdgpu_ih_ring_name (adev, ih), wptr, ih->rptr, tmp); ih->rptr = tmp; tmp =RREG32_NO_KIQ (ih_regs->ih_rb_cntl);
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +2 -3
@@ -364,9 +364,8 @@ static u32 vega10_ih_get_wptr(struct amdgpu_device *adev,* this should allow us to catchup. */ tmp = (wptr +32 ) & ih->ptr_mask; -dev_warn (adev->dev,"IH ring buffer overflow " -"(0x%08X, 0x%08X, 0x%08X)\n" , - wptr, ih->rptr, tmp); +dev_warn_ratelimited (adev->dev,"%s ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n" , +amdgpu_ih_ring_name (adev, ih), wptr, ih->rptr, tmp); ih->rptr = tmp; tmp =RREG32_NO_KIQ (ih_regs->ih_rb_cntl);
drivers/gpu/drm/amd/amdgpu/vega20_ih.c +2 -3
@@ -444,9 +444,8 @@ static u32 vega20_ih_get_wptr(struct amdgpu_device *adev,* this should allow us to catchup. */ tmp = (wptr +32 ) & ih->ptr_mask; -dev_warn (adev->dev,"IH ring buffer overflow " -"(0x%08X, 0x%08X, 0x%08X)\n" , - wptr, ih->rptr, tmp); +dev_warn_ratelimited (adev->dev,"%s ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n" , +amdgpu_ih_ring_name (adev, ih), wptr, ih->rptr, tmp); ih->rptr = tmp; tmp =RREG32_NO_KIQ (ih_regs->ih_rb_cntl);
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c +2 -2
@@ -108,8 +108,8 @@ void kfd_interrupt_exit(struct kfd_node *node)bool enqueue_ih_ring_entry (struct kfd_node *node,const void *ih_ring_entry) {if (kfifo_is_full (&node->ih_fifo)) { -dev_dbg_ratelimited (node->adev->dev, -"Interrupt ring overflow, dropping interrupt\n" ); +dev_warn_ratelimited (node->adev->dev,"KFD node %d ih_fifo overflow\n" , + node->node_id);return false; }
Signature · 1 line
2.47.1