drm/amdgpu: use ring/hash for fault handling on GMC9 v2
Subsystems (3)
PATCH 1/2 drm/amdgpu: use ring/hash for fault handling on GMC9 v2
Further testing showed that the idea with the chash doesn't work as expected. Especially we can't predict when we can remove the entries from the hash again.
So replace the chash with a ring buffer/hash mix where entries in the container age automatically based on their timestamp.
v2: use ring buffer / hash mix
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 49 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 34 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 60 ++----------------------- 3 files changed, 86 insertions(+), 57 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +49 -0
@@ -240,3 +240,52 @@ void amdgpu_gmc_agp_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc)dev_info (adev->dev,"AGP: %lluM 0x%016llX - 0x%016llX\n" , mc->agp_size >>20 , mc->agp_start, mc->agp_end); } + +/** +* amdgpu_gmc_filter_faults - filter VM faults +* +* @adev: amdgpu device structure +* @addr: address of the VM fault +* @pasid: PASID of the process causing the fault +* @timestamp: timestamp of the fault +* +* Returns: +* True if the fault was filtered and should not be processed further. +* False if the fault is a new one and needs to be handled. +*/ +bool amdgpu_gmc_filter_faults (struct amdgpu_device *adev,uint64_t addr, +uint16_t pasid,uint64_t timestamp) +{ +struct amdgpu_gmc *gmc = &adev->gmc; + +uint64_t stamp, key = addr <<4 | pasid; +struct amdgpu_gmc_fault *fault; +uint32_t hash; + +/* If we don't have space left in the ring buffer return immediately */ + stamp =max (timestamp,AMDGPU_GMC_FAULT_TIMEOUT +1 ) - +AMDGPU_GMC_FAULT_TIMEOUT ; +if (gmc->fault_ring[gmc->last_fault].timestamp >= stamp) +return true; + +/* Try to find the fault in the hash */ + hash =hash_64 (key,AMDGPU_GMC_FAULT_HASH_ORDER ); + fault = &gmc->fault_ring[gmc->fault_hash[hash].idx]; +do { +if (fault->key == key) +return true; + + stamp = fault->timestamp; + fault = &gmc->fault_ring[fault->next]; + }while (fault->timestamp < stamp); + +/* Add the fault to the ring */ + fault = &gmc->fault_ring[gmc->last_fault]; + fault->key = key; + fault->timestamp = timestamp; + +/* And update the hash */ + fault->next = gmc->fault_hash[hash].idx; + gmc->fault_hash[hash].idx = gmc->last_fault++; +return false; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +34 -0
@@ -43,8 +43,34 @@*/ #define AMDGPU_GMC_HOLE_MASK 0x0000ffffffffffffULL +/* +* Ring size as power of two for the log of recent faults. +*/ +#define AMDGPU_GMC_FAULT_RING_ORDER 8 +#define AMDGPU_GMC_FAULT_RING_SIZE (1 << AMDGPU_GMC_FAULT_RING_ORDER) + +/* +* Hash size as power of two for the log of recent faults +*/ +#define AMDGPU_GMC_FAULT_HASH_ORDER 8 +#define AMDGPU_GMC_FAULT_HASH_SIZE (1 << AMDGPU_GMC_FAULT_HASH_ORDER) + +/* +* Number of IH timestamp ticks until a fault is considered handled +*/ +#define AMDGPU_GMC_FAULT_TIMEOUT 5000ULL +struct firmware ; +/* +* GMC page fault information +*/ +struct amdgpu_gmc_fault { +uint64_t timestamp; +uint64_t next:AMDGPU_GMC_FAULT_RING_ORDER ; +uint64_t key:52 ; +}; +/* * VMHUB structures, functions & helpers */
@@ -141,6 +167,12 @@ struct amdgpu_gmc {struct kfd_vm_fault_info *vm_fault_info;atomic_t vm_fault_info_updated; +struct amdgpu_gmc_fault fault_ring[AMDGPU_GMC_FAULT_RING_SIZE ]; +struct { +uint64_t idx:AMDGPU_GMC_FAULT_RING_ORDER ; + } fault_hash[AMDGPU_GMC_FAULT_HASH_SIZE ]; + uint64_t last_fault:AMDGPU_GMC_FAULT_RING_ORDER; +const struct amdgpu_gmc_funcs *gmc_funcs;struct amdgpu_xgmi xgmi;
@@ -195,5 +227,7 @@ void amdgpu_gmc_gart_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc);void amdgpu_gmc_agp_location (struct amdgpu_device *adev,struct amdgpu_gmc *mc); +bool amdgpu_gmc_filter_faults (struct amdgpu_device *adev,uint64_t addr, +uint16_t pasid,uint64_t timestamp);#endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +3 -57
74 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
A message that is not in the archive (sent off-list or not yet received): 20190307132846.1635-1-christian.koenig-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/amdgpu: remove chash
Remove the chash implementation for now since it isn't used any more.
--- drivers/gpu/drm/Kconfig | 2 - drivers/gpu/drm/Makefile | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 105 ---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 14 - drivers/gpu/drm/amd/include/linux/chash.h | 366 ------------- drivers/gpu/drm/amd/lib/Kconfig | 28 - drivers/gpu/drm/amd/lib/Makefile | 32 -- drivers/gpu/drm/amd/lib/chash.c | 638 ---------------------- 8 files changed, 1186 deletions(-) delete mode 100644 drivers/gpu/drm/amd/include/linux/chash.h delete mode 100644 drivers/gpu/drm/amd/lib/Kconfig delete mode 100644 drivers/gpu/drm/amd/lib/Makefile delete mode 100644 drivers/gpu/drm/amd/lib/chash.c
drivers/gpu/drm/Kconfig +0 -2
@@ -229,8 +229,6 @@ config DRM_AMDGPU source "drivers/gpu/drm/amd/amdgpu/Kconfig" -source "drivers/gpu/drm/amd/lib/Kconfig" - source "drivers/gpu/drm/nouveau/Kconfig" source "drivers/gpu/drm/i915/Kconfig"
drivers/gpu/drm/Makefile +0 -1
@@ -56,7 +56,6 @@ obj-$(CONFIG_DRM_TTM) += ttm/ obj-$(CONFIG_DRM_SCHED) += scheduler/ obj-$(CONFIG_DRM_TDFX) += tdfx/ obj-$(CONFIG_DRM_R128) += r128/ -obj-y += amd/lib/ obj-$(CONFIG_HSA_AMD) += amd/amdkfd/ obj-$(CONFIG_DRM_RADEON)+= radeon/ obj-$(CONFIG_DRM_AMDGPU)+= amd/amdgpu/
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -105
136 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -14
@@ -30,7 +30,6 @@#include <drm/gpu_scheduler.h> #include <drm/drm_file.h> #include <drm/ttm/ttm_bo_driver.h> -#include <linux/chash.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h"
@@ -178,13 +177,6 @@ struct amdgpu_task_info {pid_t tgid; }; -#define AMDGPU_PAGEFAULT_HASH_BITS 8 -struct amdgpu_retryfault_hashtable { - DECLARE_CHASH_TABLE(hash, AMDGPU_PAGEFAULT_HASH_BITS, 8, 0); -spinlock_t lock; -int count; -}; -struct amdgpu_vm {/* tree of virtual addresses mapped */ struct rb_root_cached va;
@@ -244,7 +236,6 @@ struct amdgpu_vm {struct ttm_lru_bulk_move lru_bulk_move;/* mark whether can do the bulk move */ bool bulk_moveable; -struct amdgpu_retryfault_hashtable *fault_hash; };struct amdgpu_vm_manager {
@@ -356,11 +347,6 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm);void amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm); - -int amdgpu_vm_add_fault (struct amdgpu_retryfault_hashtable *fault_hash,u64 key); - -void amdgpu_vm_clear_fault (struct amdgpu_retryfault_hashtable *fault_hash,u64 key); -void amdgpu_vm_del_from_lru_notify (struct ttm_buffer_object *bo);#endif
drivers/gpu/drm/amd/include/linux/chash.h deleted +0 -366
366 lines not on this page · raw message
drivers/gpu/drm/amd/lib/Kconfig deleted +0 -28
@@ -1,28 +0,0 @@ -menu "AMD Library routines" - -# -# Closed hash table -# -config CHASH - tristate - default DRM_AMDGPU - help - Statically sized closed hash table implementation with low - memory and CPU overhead. - -config CHASH_STATS - bool "Closed hash table performance statistics" - depends on CHASH - default n - help - Enable collection of performance statistics for closed hash tables. - -config CHASH_SELFTEST - bool "Closed hash table self test" - depends on CHASH - default n - help - Runs a selftest during module load. Several module parameters - are available to modify the behaviour of the test. - -endmenu
drivers/gpu/drm/amd/lib/Makefile deleted +0 -32
@@ -1,32 +0,0 @@ -# -# Copyright 2017 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. -# -# -# Makefile for AMD library routines, which are used by AMD driver -# components. -# -# This is for common library routines that can be shared between AMD -# driver components or later moved to kernel/lib for sharing with -# other drivers. - -ccflags-y := -I$(src)/../include - -obj-$(CONFIG_CHASH) += chash.o
drivers/gpu/drm/amd/lib/chash.c deleted +0 -638
638 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
Kuehling, Felix
Reviewed-by Felix KuehlingHmm, that's a clever (and elegant) little data structure. The series is
Regards,
Felix
Quoted 202 lines · Christian König
Further testing showed that the idea with the chash doesn't work as expected. Especially we can't predict when we can remove the entries from the hash again.
So replace the chash with a ring buffer/hash mix where entries in the container age automatically based on their timestamp.
v2: use ring buffer / hash mix
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 49 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 34 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 60 ++----------------------- 3 files changed, 86 insertions(+), 57 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +49
-0@@ -240,3 +240,52 @@ void amdgpu_gmc_agp_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc)dev_info (adev->dev,"AGP: %lluM 0x%016llX - 0x%016llX\n" , mc->agp_size >>20 , mc->agp_start, mc->agp_end); } + +/** +* amdgpu_gmc_filter_faults - filter VM faults +* +* @adev: amdgpu device structure +* @addr: address of the VM fault +* @pasid: PASID of the process causing the fault +* @timestamp: timestamp of the fault +* +* Returns: +* True if the fault was filtered and should not be processed further. +* False if the fault is a new one and needs to be handled. +*/ +bool amdgpu_gmc_filter_faults (struct amdgpu_device *adev,uint64_t addr, +uint16_t pasid,uint64_t timestamp) +{ +struct amdgpu_gmc *gmc = &adev->gmc; + +uint64_t stamp, key = addr <<4 | pasid; +struct amdgpu_gmc_fault *fault; +uint32_t hash; + +/* If we don't have space left in the ring buffer return immediately */ + stamp =max (timestamp,AMDGPU_GMC_FAULT_TIMEOUT +1 ) - +AMDGPU_GMC_FAULT_TIMEOUT ; +if (gmc->fault_ring[gmc->last_fault].timestamp >= stamp) +return true; + +/* Try to find the fault in the hash */ + hash =hash_64 (key,AMDGPU_GMC_FAULT_HASH_ORDER ); + fault = &gmc->fault_ring[gmc->fault_hash[hash].idx]; +do { +if (fault->key == key) +return true; + + stamp = fault->timestamp; + fault = &gmc->fault_ring[fault->next]; + }while (fault->timestamp < stamp); + +/* Add the fault to the ring */ + fault = &gmc->fault_ring[gmc->last_fault]; + fault->key = key; + fault->timestamp = timestamp; + +/* And update the hash */ + fault->next = gmc->fault_hash[hash].idx; + gmc->fault_hash[hash].idx = gmc->last_fault++; +return false; +}drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +34
-0@@ -43,8 +43,34 @@*/ #define AMDGPU_GMC_HOLE_MASK 0x0000ffffffffffffULL +/* +* Ring size as power of two for the log of recent faults. +*/ +#define AMDGPU_GMC_FAULT_RING_ORDER 8 +#define AMDGPU_GMC_FAULT_RING_SIZE (1 << AMDGPU_GMC_FAULT_RING_ORDER) + +/* +* Hash size as power of two for the log of recent faults +*/ +#define AMDGPU_GMC_FAULT_HASH_ORDER 8 +#define AMDGPU_GMC_FAULT_HASH_SIZE (1 << AMDGPU_GMC_FAULT_HASH_ORDER) + +/* +* Number of IH timestamp ticks until a fault is considered handled +*/ +#define AMDGPU_GMC_FAULT_TIMEOUT 5000ULL +struct firmware ; +/* +* GMC page fault information +*/ +struct amdgpu_gmc_fault { +uint64_t timestamp; +uint64_t next:AMDGPU_GMC_FAULT_RING_ORDER ; +uint64_t key:52 ; +}; +/* * VMHUB structures, functions & helpers */ @@ -141,6 +167,12 @@ struct amdgpu_gmc {struct kfd_vm_fault_info *vm_fault_info;atomic_t vm_fault_info_updated; +struct amdgpu_gmc_fault fault_ring[AMDGPU_GMC_FAULT_RING_SIZE ]; +struct { +uint64_t idx:AMDGPU_GMC_FAULT_RING_ORDER ; + } fault_hash[AMDGPU_GMC_FAULT_HASH_SIZE ]; + uint64_t last_fault:AMDGPU_GMC_FAULT_RING_ORDER; +const struct amdgpu_gmc_funcs *gmc_funcs;struct amdgpu_xgmi xgmi;@@ -195,5 +227,7 @@ void amdgpu_gmc_gart_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc);void amdgpu_gmc_agp_location (struct amdgpu_device *adev,struct amdgpu_gmc *mc); +bool amdgpu_gmc_filter_faults (struct amdgpu_device *adev,uint64_t addr, +uint16_t pasid,uint64_t timestamp);#endif drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-56@@ -416,62 +416,6 @@ static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,return 0 ; } -/** -* vega10_ih_prescreen_iv - prescreen an interrupt vector -* -* @adev: amdgpu_device pointer -* -* Returns true if the interrupt vector should be further processed. -*/ -static bool gmc_v9_0_prescreen_iv (struct amdgpu_device *adev, -struct amdgpu_iv_entry *entry, -uint64_t addr) -{ -struct amdgpu_vm *vm; -u64 key; -int r; - -/* No PASID, can't identify faulting process */ -if (!entry->pasid) -return true; - -/* Not a retry fault */ -if (!(entry->src_data[1 ] &0x80 )) -return true; - -/* Track retry faults in per-VM fault FIFO. */ -spin_lock (&adev->vm_manager.pasid_lock); - vm =idr_find (&adev->vm_manager.pasid_idr, entry->pasid); -if (!vm) { -/* VM not found, process it normally */ -spin_unlock (&adev->vm_manager.pasid_lock); -return true; - } - - key =AMDGPU_VM_FAULT (entry->pasid, addr); - r =amdgpu_vm_add_fault (vm->fault_hash, key); - -/* Hash table is full or the fault is already being processed, -* ignore further page faults -*/ -if (r !=0 ) { -spin_unlock (&adev->vm_manager.pasid_lock); -return false; - } -/* No locking required with single writer and single reader */ - r =kfifo_put (&vm->faults, key); -if (!r) { -/* FIFO is full. Ignore it until there is space */ -amdgpu_vm_clear_fault (vm->fault_hash, key); -spin_unlock (&adev->vm_manager.pasid_lock); -return false; - } - -spin_unlock (&adev->vm_manager.pasid_lock); -/* It's the first fault for this address, process it normally */ -return true; -} -static int gmc_v9_0_process_interrupt (struct amdgpu_device *adev,struct amdgpu_irq_src *source,struct amdgpu_iv_entry *entry)@@ -484,9 +428,11 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, addr = (u64 )entry->src_data[0 ] <<12 ; addr |= ((u64 )entry->src_data[1 ] &0xf ) <<44 ;
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, · line 438
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +3
-1-if (!gmc_v9_0_prescreen_iv (adev, entry, addr)) +if (retry_fault &&amdgpu_gmc_filter_faults (adev, addr, entry->pasid, + entry->timestamp))return 1 ;/* This also prevents sending it to KFD */ +/* If it's the first fault for this address, process it normally */ if (!amdgpu_sriov_vf (adev)) { status =RREG32 (hub->vm_l2_pro_fault_status);WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 );
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx