Skip to contentSkip to conversation

drm/amdgpu: optimize list operation in amdgpu_xgmi

PATCH In review Kevin Wang 2 participants 3 messages Feb 3, 2021

Subsystems (2)
lore
Share & tools
lore

Kevin Wang

author
#0 lore raw

PATCH 1/1 drm/amdgpu: optimize list operation in amdgpu_xgmi

simplify the list opertion.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +4 -6
index 541ef6be390f..659b385b27b5 100644
@@ -324,7 +324,7 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 {
-	struct amdgpu_hive_info *hive = NULL, *tmp = NULL;
+	struct amdgpu_hive_info *hive = NULL;
 	int ret;
 
 	if (!adev->gmc.xgmi.hive_id)
@@ -337,11 +337,9 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 
 	mutex_lock(&xgmi_mutex);
 
-	if (!list_empty(&xgmi_hive_list)) {
-		list_for_each_entry_safe(hive, tmp, &xgmi_hive_list, node)  {
-			if (hive->hive_id == adev->gmc.xgmi.hive_id)
-				goto pro_end;
-		}
+	list_for_each_entry(hive, &xgmi_hive_list, node)  {
+		if (hive->hive_id == adev->gmc.xgmi.hive_id)
+			goto pro_end;
 	}
 
 	hive = kzalloc(sizeof(*hive), GFP_KERNEL);
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw

Looks good to me. I see some more redundant code in that function, if you want to clean it up further:

Quoted 4 lines

        hive = kzalloc(sizeof(*hive), GFP_KERNEL);
        if (!hive) {
                dev_err(adev->dev, "XGMI: allocation failed\n"); hive = NULL;

No need to set hive to NULL. The condition above is only true if it's already NULL. Also you don't need to print error messages for out-of-memory errors, because kzalloc will be very noisy if it fails anyway.

Quoted 2 lines

                goto pro_end;
        }

Either way, this patch is:

Am 2021-02-03 um 4:42 a.m. schrieb Kevin Wang:

Quoted 25 lines

simplify the list opertion.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +1 -2
index 541ef6be390f..659b385b27b5 100644
@@ -324,7 +324,7 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 {
-	struct amdgpu_hive_info *hive = NULL, *tmp = NULL;
+	struct amdgpu_hive_info *hive = NULL;
 	int ret;
 
 	if (!adev->gmc.xgmi.hive_id)
@@ -337,11 +337,9 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 
 	mutex_lock(&xgmi_mutex);
 
-	if (!list_empty(&xgmi_hive_list)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) · line 345

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +3 -4
-		list_for_each_entry_safe(hive, tmp, &xgmi_hive_list, node)  {
-			if (hive->hive_id == adev->gmc.xgmi.hive_id)
-				goto pro_end;
-		}
+	list_for_each_entry(hive, &xgmi_hive_list, node)  {
+		if (hive->hive_id == adev->gmc.xgmi.hive_id)
+			goto pro_end;
 	}
 
 	hive = kzalloc(sizeof(*hive), GFP_KERNEL);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author Reviewed-by Felix Kuehling
#2 lore raw

[AMD Official Use Only - Internal Distribution Only]

thanks Felix,
I will continue to optimize related codes in the future.

Best Regards,
Kevin
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Wednesday, February 3, 2021 9:53 PM
To: Wang, Kevin(Yang) <[email protected]>; [email protected] <[email protected]>
Cc: Li, Dennis <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: optimize list operation in amdgpu_xgmi

Looks good to me. I see some more redundant code in that function, if you want to clean it up further:

Quoted 4 lines
        hive = kzalloc(sizeof(*hive), GFP_KERNEL);
        if (!hive) {
                dev_err(adev->dev, "XGMI: allocation failed\n");
                hive = NULL;

No need to set hive to NULL. The condition above is only true if it's already NULL. Also you don't need to print error messages for out-of-memory errors, because kzalloc will be very noisy if it fails anyway.

Quoted 2 lines
                goto pro_end;
        }

Either way, this patch is:

Am 2021-02-03 um 4:42 a.m. schrieb Kevin Wang:

Quoted 25 lines

simplify the list opertion.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +1 -2
index 541ef6be390f..659b385b27b5 100644
@@ -324,7 +324,7 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 {
-     struct amdgpu_hive_info *hive = NULL, *tmp = NULL;
+     struct amdgpu_hive_info *hive = NULL;
       int ret;
 
       if (!adev->gmc.xgmi.hive_id)
@@ -337,11 +337,9 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 
       mutex_lock(&xgmi_mutex);
 
-     if (!list_empty(&xgmi_hive_list)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) · line 345

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +3 -4
-             list_for_each_entry_safe(hive, tmp, &xgmi_hive_list, node)  {
-                     if (hive->hive_id == adev->gmc.xgmi.hive_id)
-                             goto pro_end;
-             }
+     list_for_each_entry(hive, &xgmi_hive_list, node)  {
+             if (hive->hive_id == adev->gmc.xgmi.hive_id)
+                     goto pro_end;
       }
 
       hive = kzalloc(sizeof(*hive), GFP_KERNEL);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx