Commit 1ac354be authored by Daniel Phillips's avatar Daniel Phillips Committed by Alex Deucher

drm/amdgpu: Pessimistic availability based on rounded up allocations

Separately accumulate a statistic of rounded up allocations to use
to report availability, with a view to increasing the likelihood a
buffer object can be successfully allocated at exactly the size
reported by the availability API.
Signed-off-by: default avatarDaniel Phillips <daniel.phillips@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent aec208ee
...@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence { ...@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence {
struct amdgpu_kfd_dev { struct amdgpu_kfd_dev {
struct kfd_dev *dev; struct kfd_dev *dev;
uint64_t vram_used; uint64_t vram_used;
uint64_t vram_used_aligned;
bool init_complete; bool init_complete;
struct work_struct reset_work; struct work_struct reset_work;
}; };
......
...@@ -182,8 +182,10 @@ int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev, ...@@ -182,8 +182,10 @@ int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,
*/ */
WARN_ONCE(vram_needed && !adev, WARN_ONCE(vram_needed && !adev,
"adev reference can't be null when vram is used"); "adev reference can't be null when vram is used");
if (adev) if (adev) {
adev->kfd.vram_used += vram_needed; adev->kfd.vram_used += vram_needed;
adev->kfd.vram_used_aligned += ALIGN(vram_needed, VRAM_AVAILABLITY_ALIGN);
}
kfd_mem_limit.system_mem_used += system_mem_needed; kfd_mem_limit.system_mem_used += system_mem_needed;
kfd_mem_limit.ttm_mem_used += ttm_mem_needed; kfd_mem_limit.ttm_mem_used += ttm_mem_needed;
...@@ -203,8 +205,10 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev, ...@@ -203,8 +205,10 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev,
} else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) { } else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
WARN_ONCE(!adev, WARN_ONCE(!adev,
"adev reference can't be null when alloc mem flags vram is set"); "adev reference can't be null when alloc mem flags vram is set");
if (adev) if (adev) {
adev->kfd.vram_used -= size; adev->kfd.vram_used -= size;
adev->kfd.vram_used_aligned -= ALIGN(size, VRAM_AVAILABLITY_ALIGN);
}
} else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) { } else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {
kfd_mem_limit.system_mem_used -= size; kfd_mem_limit.system_mem_used -= size;
} else if (!(alloc_flag & } else if (!(alloc_flag &
...@@ -1610,7 +1614,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev) ...@@ -1610,7 +1614,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)
size_t available; size_t available;
spin_lock(&kfd_mem_limit.mem_limit_lock); spin_lock(&kfd_mem_limit.mem_limit_lock);
available = adev->gmc.real_vram_size available = adev->gmc.real_vram_size
- adev->kfd.vram_used - adev->kfd.vram_used_aligned
- atomic64_read(&adev->vram_pin_size) - atomic64_read(&adev->vram_pin_size)
- reserved_for_pt; - reserved_for_pt;
spin_unlock(&kfd_mem_limit.mem_limit_lock); spin_unlock(&kfd_mem_limit.mem_limit_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment