Skip to contentSkip to conversation

drm/vmwgfx: Don't memcmp equivalent pointers

PATCH Superseded Ian Forbes 2 participants 3 messages Mar 28, 2024 – Apr 5, 2024

Subsystems (4)
lore
Share & tools
lore

Ian Forbes

author
#0 lore raw

PATCH 1/1 drm/vmwgfx: Don't memcmp equivalent pointers

These pointers are frequently the same and memcmp does not compare the pointers before comparing their contents so this was wasting cycles comparing 16 KiB of memory which will always be equal.

Fixes bb6780aa5a1d9 ("drm/vmwgfx: Diff cursors when using cmds")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -1
index cd4925346ed4..fbcce84e2f4c 100644
@@ -216,7 +216,7 @@ static bool vmw_du_cursor_plane_has_changed(struct vmw_plane_state *old_vps,
 	new_image = vmw_du_cursor_plane_acquire_image(new_vps);
 
 	changed = false;
-	if (old_image && new_image)
+	if (old_image && new_image && (old_image != new_image))
 		changed = memcmp(old_image, new_image, size) != 0;
 
 	return changed;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 25 lines · Ian Forbes

These pointers are frequently the same and memcmp does not compare the pointers before comparing their contents so this was wasting cycles comparing 16 KiB of memory which will always be equal.

Fixes bb6780aa5a1d9 ("drm/vmwgfx: Diff cursors when using cmds")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -2
index cd4925346ed4..fbcce84e2f4c 100644
@@ -216,7 +216,7 @@ static bool vmw_du_cursor_plane_has_changed(struct vmw_plane_state *old_vps,
        new_image = vmw_du_cursor_plane_acquire_image(new_vps);
 
        changed = false;
-       if (old_image && new_image)
+       if (old_image && new_image && (old_image != new_image))
                changed = memcmp(old_image, new_image, size) != 0;
 
        return changed;
--
Quoted 2 lines

2.34.1

The patch looks good but please use "dim checkpatch" and fix the issues it found. For the "Fixes:" line you also want to use "dim fixes".

z

author
#2 lore raw

PATCH v2 1/1 drm/vmwgfx: Don't memcmp equivalent pointers

In reply to Ian Forbes

These pointers are frequently the same and memcmp does not compare the pointers before comparing their contents so this was wasting cycles comparing 16 KiB of memory which will always be equal.

Fixes bb6780aa5a1d ("drm/vmwgfx: Diff cursors when using cmds")
Cc <[email protected]> # v6.2+

---
v2: Fix code and commit message formatting.
--

 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -1
index cd4925346ed4..ef0af10c4968 100644
@@ -216,7 +216,7 @@ static bool vmw_du_cursor_plane_has_changed(struct vmw_plane_state *old_vps,
 	new_image = vmw_du_cursor_plane_acquire_image(new_vps);
 
 	changed = false;
-	if (old_image && new_image)
+	if (old_image && new_image && old_image != new_image)
 		changed = memcmp(old_image, new_image, size) != 0;
 
 	return changed;
Signature · 1 line
2.34.1