From: Tvrtko Ursulin <tursulin@ursulin.net>
To: Uros Bizjak <ubizjak@gmail.com>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Subject: Re: [PATCH] drm/i915/active: Use try_cmpxchg64() in __active_lookup()
Date: Thu, 14 Aug 2025 07:44:40 +0100 [thread overview]
Message-ID: <ceb80fde-dae5-478e-840c-9b949396d904@ursulin.net> (raw)
In-Reply-To: <20250725072727.68486-1-ubizjak@gmail.com>
Hi,
On 25/07/2025 08:26, Uros Bizjak wrote:
> 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 <ubizjak@gmail.com>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tursulin@ursulin.net>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Simona Vetter <simona@ffwll.ch>
> ---
> drivers/gpu/drm/i915/i915_active.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_active.c b/drivers/gpu/drm/i915/i915_active.c
> index 0dbc4e289300..6b0c1162505a 100644
> --- a/drivers/gpu/drm/i915/i915_active.c
> +++ b/drivers/gpu/drm/i915/i915_active.c
> @@ -257,10 +257,9 @@ static struct active_node *__active_lookup(struct i915_active *ref, u64 idx)
> * claimed the cache and we know that is does not match our
> * idx. If, and only if, the timeline is currently zero is it
> * worth competing to claim it atomically for ourselves (for
> - * only the winner of that race will cmpxchg return the old
> - * value of 0).
> + * only the winner of that race will cmpxchg succeed).
> */
> - if (!cached && !cmpxchg64(&it->timeline, 0, idx))
> + if (!cached && try_cmpxchg64(&it->timeline, &cached, idx))
> return it;
> }
>
Patch looks fine, thank you!
I've sent it for a CI pass (see
https://patchwork.freedesktop.org/series/152185/) before merging.
Regards,
Tvrtko
prev parent reply other threads:[~2025-08-14 6:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 7:26 Uros Bizjak
2025-08-14 6:44 ` Tvrtko Ursulin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ceb80fde-dae5-478e-840c-9b949396d904@ursulin.net \
--to=tursulin@ursulin.net \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=ubizjak@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®