drm/amdkfd: Use dev_error intead of pr_error
Subsystems (3)
PATCH 1/2 drm/amdkfd: Use dev_error intead of pr_error
No functional change. This will help in moving gpu_id creation to next step while still being able to identify the correct GPU
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +8 -11
@@ -1773,7 +1773,7 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, structpr_debug ("Added [%d] GPU cache entries\n" , num_of_entries); } -static int kfd_topology_add_device_locked (struct kfd_node *gpu,uint32_t gpu_id, +static int kfd_topology_add_device_locked (struct kfd_node *gpu,struct kfd_topology_device **dev) {int proximity_domain = ++topology_crat_proximity_domain;
@@ -1786,8 +1786,7 @@ static int kfd_topology_add_device_locked(struct kfd_node *gpu, uint32_t gpu_id,COMPUTE_UNIT_GPU , gpu, proximity_domain);if (res) { -pr_err ("Error creating VCRAT for GPU (ID: 0x%x)\n" , - gpu_id); +dev_err (gpu->adev->dev,"Error creating VCRAT\n" ); topology_crat_proximity_domain--; goto err; }
@@ -1798,8 +1797,7 @@ static int kfd_topology_add_device_locked(struct kfd_node *gpu, uint32_t gpu_id, &temp_topology_device_list, proximity_domain);if (res) { -pr_err ("Error parsing VCRAT for GPU (ID: 0x%x)\n" , - gpu_id); +dev_err (gpu->adev->dev,"Error parsing VCRAT\n" ); topology_crat_proximity_domain--; goto err; }
@@ -1825,8 +1823,8 @@ static int kfd_topology_add_device_locked(struct kfd_node *gpu, uint32_t gpu_id,if (!res) sys_props.generation_count++;else -pr_err ("Failed to update GPU (ID: 0x%x) to sysfs topology. res=%d\n" , - gpu_id, res); +dev_err (gpu->adev->dev,"Failed to update GPU to sysfs topology. res=%d\n" , + res); err:kfd_destroy_crat_image (crat_image);
@@ -1951,11 +1949,10 @@ int kfd_topology_add_device(struct kfd_node *gpu) gpu_id =kfd_generate_gpu_id (gpu);if (gpu->xcp && !gpu->xcp->ddev) {dev_warn (gpu->adev->dev, -"Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned." , - gpu_id); +"Won't add GPU to topology since it has no drm node assigned." );return 0 ; }else { -pr_debug ("Adding new GPU (ID: 0x%x) to topology\n" , gpu_id); +dev_dbg (gpu->adev->dev,"Adding new GPU to topology\n" ); }/* Check to see if this gpu device exists in the topology_device_list.
@@ -1967,7 +1964,7 @@ int kfd_topology_add_device(struct kfd_node *gpu)down_write (&topology_lock); dev =kfd_assign_gpu (gpu);if (!dev) - res =kfd_topology_add_device_locked (gpu, gpu_id, &dev); + res =kfd_topology_add_device_locked (gpu, &dev);up_write (&topology_lock);if (res)return res;
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdkfd: Improve chances of unique gpu_id
gpu_id needs to be unique for user space to identify GPUs via KFD interface. Do a single pass search to detect collision. If detected, increment gpu_id by one.
Probability of collisons are very rare. Hence, no more complexity is added to ensure uniqueness.
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +10 -2
@@ -1095,6 +1095,8 @@ static uint32_t kfd_generate_gpu_id(struct kfd_node *gpu)uint32_t hashout;uint32_t buf[8 ];uint64_t local_mem_size; +struct kfd_topology_device *dev; +bool is_unique = true;int i;if (!gpu)
@@ -1115,7 +1117,13 @@ static uint32_t kfd_generate_gpu_id(struct kfd_node *gpu)for (i =0 , hashout =0 ; i <8 ; i++) hashout ^=hash_32 (buf[i],KFD_GPU_ID_HASH_WIDTH ); -return hashout; +down_read (&topology_lock); +list_for_each_entry (dev, &topology_device_list, list) { +if (dev->gpu && dev->gpu_id == hashout) + is_unique = false; + } +up_read (&topology_lock); +return is_unique ? hashout : ++hashout; }/* kfd_assign_gpu - Attach @gpu to the correct kfd topology device. If * the GPU device is not already present in the topology device
@@ -1946,7 +1954,6 @@ int kfd_topology_add_device(struct kfd_node *gpu)struct amdgpu_gfx_config *gfx_info = &gpu->adev->gfx.config;struct amdgpu_cu_info *cu_info = &gpu->adev->gfx.cu_info; - gpu_id =kfd_generate_gpu_id (gpu);if (gpu->xcp && !gpu->xcp->ddev) {dev_warn (gpu->adev->dev,"Won't add GPU to topology since it has no drm node assigned." );
@@ -1969,6 +1976,7 @@ int kfd_topology_add_device(struct kfd_node *gpu)if (res)return res; + gpu_id =kfd_generate_gpu_id (gpu); dev->gpu_id = gpu_id; gpu->id = gpu_id;
Signature · 1 line
2.34.1
Felix Kuehling
maintainerRe: [PATCH 2/2] drm/amdkfd: Improve chances of unique gpu_id
Quoted 25 lines · Harish Kasiviswanathan
gpu_idneeds to be unique for user space to identify GPUs via KFD interface. Do a single pass search to detect collision. If detected, incrementgpu_idby one.Probability of collisons are very rare. Hence, no more complexity is added to ensure uniqueness.>
Signed-off-by Harish Kasiviswanathan <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2
-0@@ -1095,6 +1095,8 @@ static uint32_t kfd_generate_gpu_id(struct kfd_node *gpu)uint32_t hashout;uint32_t buf[8 ];uint64_t local_mem_size; +struct kfd_topology_device *dev; +bool is_unique = true;int i;if (!gpu)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c static uint32_t kfd_generate_gpu_id(struct kfd_node *gpu) · line 1123
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4
-1@@ -1115,7 +1117,13 @@ static uint32_t kfd_generate_gpu_id(struct kfd_node *gpu)for (i =0 , hashout =0 ; i <8 ; i++) hashout ^=hash_32 (buf[i],KFD_GPU_ID_HASH_WIDTH ); -return hashout; +down_read (&topology_lock); +list_for_each_entry (dev, &topology_device_list, list) { +if (dev->gpu && dev->gpu_id == hashout) + is_unique = false;
You can break early here.
drivers/gpu/drm/amd/amdkfd/kfd_topology.c static uint32_t kfd_generate_gpu_id(struct kfd_node *gpu) · line 1126
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3
-0+ } +up_read (&topology_lock); +return is_unique ? hashout : ++hashout;
We should make sure that hashout stays within the KFD_GPU_ID_HASH_WIDTH. And if we're already adding a collision check, we may as well make it air-tight. It should be easy enough by wrapping it in a do-while loop. While we're at it, can we also check that the hash is not 0, because that value is used for non-GPU nodes? I think this would satisfy all my requests:
do {
if (!hashout)
hashout++;
is_unique = true;
list_for_each_entry(dev, &topology_device_list, list) {
if (dev->gpu && dev->gpu_id == hashout) {
is_unique = false;
hashout = (hashout + 1) &
((1U << KFD_GPU_ID_HASH_WIDTH) - 1);
break;
}
}
} while (!is_unique);Regards,
Felix
Quoted 19 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-1}/* kfd_assign_gpu - Attach @gpu to the correct kfd topology device. If * the GPU device is not already present in the topology device @@ -1946,7 +1954,6 @@ int kfd_topology_add_device(struct kfd_node *gpu)struct amdgpu_gfx_config *gfx_info = &gpu->adev->gfx.config;struct amdgpu_cu_info *cu_info = &gpu->adev->gfx.cu_info; - gpu_id =kfd_generate_gpu_id (gpu);if (gpu->xcp && !gpu->xcp->ddev) {dev_warn (gpu->adev->dev,"Won't add GPU to topology since it has no drm node assigned." );@@ -1969,6 +1976,7 @@ int kfd_topology_add_device(struct kfd_node *gpu)if (res)return res; + gpu_id =kfd_generate_gpu_id (gpu); dev->gpu_id = gpu_id; gpu->id = gpu_id;
Quoted 4 lines · Harish Kasiviswanathan
No functional change. This will help in moving
gpu_idcreation to next step while still being able to identify the correct GPUSigned-off-by Harish Kasiviswanathan <[email protected]>
Quoted 71 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_topology.c +8
-11@@ -1773,7 +1773,7 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, structpr_debug ("Added [%d] GPU cache entries\n" , num_of_entries); } -static int kfd_topology_add_device_locked (struct kfd_node *gpu,uint32_t gpu_id, +static int kfd_topology_add_device_locked (struct kfd_node *gpu,struct kfd_topology_device **dev) {int proximity_domain = ++topology_crat_proximity_domain;@@ -1786,8 +1786,7 @@ static int kfd_topology_add_device_locked(struct kfd_node *gpu, uint32_t gpu_id,COMPUTE_UNIT_GPU , gpu, proximity_domain);if (res) { -pr_err ("Error creating VCRAT for GPU (ID: 0x%x)\n" , - gpu_id); +dev_err (gpu->adev->dev,"Error creating VCRAT\n" ); topology_crat_proximity_domain--; goto err; }@@ -1798,8 +1797,7 @@ static int kfd_topology_add_device_locked(struct kfd_node *gpu, uint32_t gpu_id, &temp_topology_device_list, proximity_domain);if (res) { -pr_err ("Error parsing VCRAT for GPU (ID: 0x%x)\n" , - gpu_id); +dev_err (gpu->adev->dev,"Error parsing VCRAT\n" ); topology_crat_proximity_domain--; goto err; }@@ -1825,8 +1823,8 @@ static int kfd_topology_add_device_locked(struct kfd_node *gpu, uint32_t gpu_id,if (!res) sys_props.generation_count++;else -pr_err ("Failed to update GPU (ID: 0x%x) to sysfs topology. res=%d\n" , - gpu_id, res); +dev_err (gpu->adev->dev,"Failed to update GPU to sysfs topology. res=%d\n" , + res); err:kfd_destroy_crat_image (crat_image);@@ -1951,11 +1949,10 @@ int kfd_topology_add_device(struct kfd_node *gpu) gpu_id =kfd_generate_gpu_id (gpu);if (gpu->xcp && !gpu->xcp->ddev) {dev_warn (gpu->adev->dev, -"Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned." , - gpu_id); +"Won't add GPU to topology since it has no drm node assigned." );return 0 ; }else { -pr_debug ("Adding new GPU (ID: 0x%x) to topology\n" , gpu_id); +dev_dbg (gpu->adev->dev,"Adding new GPU to topology\n" ); }/* Check to see if this gpu device exists in the topology_device_list. @@ -1967,7 +1964,7 @@ int kfd_topology_add_device(struct kfd_node *gpu)down_write (&topology_lock); dev =kfd_assign_gpu (gpu);if (!dev) - res =kfd_topology_add_device_locked (gpu, gpu_id, &dev); + res =kfd_topology_add_device_locked (gpu, &dev);up_write (&topology_lock);if (res)return res;