Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdkfd: Use VMID bitmap from KGD v2

The hard-coded values related to VMID were removed in KFD, as those
values can be calculated in the KFD initialization function.

v2: remove unnecessary local variable

Signed-off-by: Yong Zhao <yong.zhao@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>

authored by

Yong Zhao and committed by
Oded Gabbay
44008d7a b90e3fbe

+21 -19
+2 -7
drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c
··· 769 769 union GRBM_GFX_INDEX_BITS reg_gfx_index; 770 770 struct kfd_process_device *pdd; 771 771 struct dbg_wave_control_info wac_info; 772 - int temp; 773 - int first_vmid_to_scan = 8; 774 - int last_vmid_to_scan = 15; 775 - 776 - first_vmid_to_scan = ffs(dev->shared_resources.compute_vmid_bitmap) - 1; 777 - temp = dev->shared_resources.compute_vmid_bitmap >> first_vmid_to_scan; 778 - last_vmid_to_scan = first_vmid_to_scan + ffz(temp); 772 + int first_vmid_to_scan = dev->vm_info.first_vmid_kfd; 773 + int last_vmid_to_scan = dev->vm_info.last_vmid_kfd; 779 774 780 775 reg_sq_cmd.u32All = 0; 781 776 status = 0;
+5
drivers/gpu/drm/amd/amdkfd/kfd_device.c
··· 219 219 220 220 kfd->shared_resources = *gpu_resources; 221 221 222 + kfd->vm_info.first_vmid_kfd = ffs(gpu_resources->compute_vmid_bitmap)-1; 223 + kfd->vm_info.last_vmid_kfd = fls(gpu_resources->compute_vmid_bitmap)-1; 224 + kfd->vm_info.vmid_num_kfd = kfd->vm_info.last_vmid_kfd 225 + - kfd->vm_info.first_vmid_kfd + 1; 226 + 222 227 /* calculate max size of mqds needed for queues */ 223 228 size = max_num_of_queues_per_device * 224 229 kfd->device_info->mqd_size_aligned;
+6 -7
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
··· 113 113 if (dqm->vmid_bitmap == 0) 114 114 return -ENOMEM; 115 115 116 - bit = find_first_bit((unsigned long *)&dqm->vmid_bitmap, CIK_VMID_NUM); 116 + bit = find_first_bit((unsigned long *)&dqm->vmid_bitmap, 117 + dqm->dev->vm_info.vmid_num_kfd); 117 118 clear_bit(bit, (unsigned long *)&dqm->vmid_bitmap); 118 119 119 - /* Kaveri kfd vmid's starts from vmid 8 */ 120 - allocated_vmid = bit + KFD_VMID_START_OFFSET; 120 + allocated_vmid = bit + dqm->dev->vm_info.first_vmid_kfd; 121 121 pr_debug("vmid allocation %d\n", allocated_vmid); 122 122 qpd->vmid = allocated_vmid; 123 123 q->properties.vmid = allocated_vmid; ··· 132 132 struct qcm_process_device *qpd, 133 133 struct queue *q) 134 134 { 135 - int bit = qpd->vmid - KFD_VMID_START_OFFSET; 135 + int bit = qpd->vmid - dqm->dev->vm_info.first_vmid_kfd; 136 136 137 137 /* Release the vmid mapping */ 138 138 set_pasid_vmid_mapping(dqm, 0, qpd->vmid); ··· 507 507 dqm->allocated_queues[pipe] |= 1 << queue; 508 508 } 509 509 510 - dqm->vmid_bitmap = (1 << VMID_PER_DEVICE) - 1; 510 + dqm->vmid_bitmap = (1 << dqm->dev->vm_info.vmid_num_kfd) - 1; 511 511 dqm->sdma_bitmap = (1 << CIK_SDMA_QUEUES) - 1; 512 512 513 513 return 0; ··· 613 613 int i, mec; 614 614 struct scheduling_resources res; 615 615 616 - res.vmid_mask = (1 << VMID_PER_DEVICE) - 1; 617 - res.vmid_mask <<= KFD_VMID_START_OFFSET; 616 + res.vmid_mask = dqm->dev->shared_resources.compute_vmid_bitmap; 618 617 619 618 res.queue_mask = 0; 620 619 for (i = 0; i < KGD_MAX_QUEUES; ++i) {
-4
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
··· 32 32 #define KFD_UNMAP_LATENCY_MS (4000) 33 33 #define QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS (2 * KFD_UNMAP_LATENCY_MS + 1000) 34 34 35 - #define CIK_VMID_NUM (8) 36 - #define KFD_VMID_START_OFFSET (8) 37 - #define VMID_PER_DEVICE CIK_VMID_NUM 38 - #define KFD_DQM_FIRST_PIPE (0) 39 35 #define CIK_SDMA_QUEUES (4) 40 36 #define CIK_SDMA_QUEUES_PER_ENGINE (2) 41 37 #define CIK_SDMA_ENGINE_NUM (2)
+7
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
··· 141 141 uint32_t *cpu_ptr; 142 142 }; 143 143 144 + struct kfd_vmid_info { 145 + uint32_t first_vmid_kfd; 146 + uint32_t last_vmid_kfd; 147 + uint32_t vmid_num_kfd; 148 + }; 149 + 144 150 struct kfd_dev { 145 151 struct kgd_dev *kgd; 146 152 ··· 168 162 */ 169 163 170 164 struct kgd2kfd_shared_resources shared_resources; 165 + struct kfd_vmid_info vm_info; 171 166 172 167 const struct kfd2kgd_calls *kfd2kgd; 173 168 struct mutex doorbell_mutex;
+1 -1
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
··· 187 187 case KFD_QUEUE_TYPE_COMPUTE: 188 188 /* check if there is over subscription */ 189 189 if ((sched_policy == KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION) && 190 - ((dev->dqm->processes_count >= VMID_PER_DEVICE) || 190 + ((dev->dqm->processes_count >= dev->vm_info.vmid_num_kfd) || 191 191 (dev->dqm->queue_count >= get_queues_num(dev->dqm)))) { 192 192 pr_err("Over-subscription is not allowed in radeon_kfd.sched_policy == 1\n"); 193 193 retval = -EPERM;