Skip to content

Commit 60b006b

Browse files
ubizjaktursulin
authored andcommitted
drm/i915/active: Use try_cmpxchg64() in __active_lookup()
Replace this pattern in __active_lookup(): cmpxchg64(*ptr, old, new) == old ... with the simpler and faster: try_cmpxchg64(*ptr, &old, new) The x86 CMPXCHG instruction returns success in the ZF flag, so this change saves a compare after the CMPXCHG. The patch also improves the explanation of what the code really does. cmpxchg64() will *succeed* for the winner of the race and try_cmpxchg64() nicely documents this fact. No functional change intended. Signed-off-by: Uros Bizjak <[email protected]> Cc: Jani Nikula <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: Rodrigo Vivi <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Cc: David Airlie <[email protected]> Cc: Simona Vetter <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Signed-off-by: Tvrtko Ursulin <[email protected]> Signed-off-by: Tvrtko Ursulin <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 317be9c commit 60b006b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/gpu/drm/i915/i915_active.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,9 @@ static struct active_node *__active_lookup(struct i915_active *ref, u64 idx)
257257
* claimed the cache and we know that is does not match our
258258
* idx. If, and only if, the timeline is currently zero is it
259259
* worth competing to claim it atomically for ourselves (for
260-
* only the winner of that race will cmpxchg return the old
261-
* value of 0).
260+
* only the winner of that race will cmpxchg succeed).
262261
*/
263-
if (!cached && !cmpxchg64(&it->timeline, 0, idx))
262+
if (!cached && try_cmpxchg64(&it->timeline, &cached, idx))
264263
return it;
265264
}
266265

0 commit comments

Comments
 (0)