drm/amdkfd: APU mode set max svm range pages

svm_migrate_init set the max svm range pages based on the KFD nodes
partition size. APU mode don't init pgmap because there is no migration.

kgd2kfd_device_init calls svm_migrate_init after KFD nodes allocation
and initialization.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Philip Yang 2023-03-23 08:45:56 -04:00 committed by Alex Deucher
parent 1c77527a69
commit 25f5070434
3 changed files with 17 additions and 10 deletions

View File

@ -724,9 +724,6 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
kfd_cwsr_init(kfd);
svm_migrate_init(kfd->adev);
dev_info(kfd_device, "Total number of KFD nodes to be created: %d\n",
kfd->num_nodes);
@ -794,6 +791,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
kfd->nodes[i] = node;
}
svm_migrate_init(kfd->adev);
if (kfd_resume_iommu(kfd))
goto kfd_resume_iommu_error;

View File

@ -1000,6 +1000,11 @@ int svm_migrate_init(struct amdgpu_device *adev)
if (!KFD_IS_SOC15(kfddev->dev))
return -EINVAL;
svm_range_set_max_pages(adev);
if (adev->gmc.is_app_apu)
return 0;
pgmap = &kfddev->pgmap;
memset(pgmap, 0, sizeof(*pgmap));
@ -1042,8 +1047,6 @@ int svm_migrate_init(struct amdgpu_device *adev)
amdgpu_amdkfd_reserve_system_mem(SVM_HMM_PAGE_STRUCT_SIZE(size));
svm_range_set_max_pages(adev);
pr_info("HMM registered %ldMB device memory\n", size >> 20);
return 0;

View File

@ -1938,14 +1938,19 @@ void svm_range_set_max_pages(struct amdgpu_device *adev)
{
uint64_t max_pages;
uint64_t pages, _pages;
uint64_t min_pages = 0;
int i;
for (i = 0; i < adev->kfd.dev->num_nodes; i++) {
pages = KFD_XCP_MEMORY_SIZE(adev, adev->kfd.dev->nodes[i]->xcp->id) >> 17;
pages = clamp(pages, 1ULL << 9, 1ULL << 18);
pages = rounddown_pow_of_two(pages);
min_pages = min_not_zero(min_pages, pages);
}
/* 1/32 VRAM size in pages */
pages = adev->gmc.real_vram_size >> 17;
pages = clamp(pages, 1ULL << 9, 1ULL << 18);
pages = rounddown_pow_of_two(pages);
do {
max_pages = READ_ONCE(max_svm_range_pages);
_pages = min_not_zero(max_pages, pages);
_pages = min_not_zero(max_pages, min_pages);
} while (cmpxchg(&max_svm_range_pages, max_pages, _pages) != max_pages);
}