drm/amdgpu: use ring/hash for fault handling on GMC9 v3
Subsystems (2)
PATCH 1/1 drm/amdgpu: use ring/hash for fault handling on GMC9 v3
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
v3: check the timeout to make sure all entries age
Signed-off-by Christian König <[email protected]>
Reviewed-by Felix Kuehling <[email protected]> (v2)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 55 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 34 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 60 ++----------------------- 3 files changed, 92 insertions(+), 57 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +55 -0
@@ -240,3 +240,58 @@ 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]; +while (fault->timestamp >= stamp) { +uint64_t tmp; + +if (fault->key == key) +return true; + + tmp = fault->timestamp; + fault = &gmc->fault_ring[fault->next]; + +/* Check if the entry was reused */ +if (fault->timestamp >= tmp) +break ; + } + +/* 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