All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH] block: Use try_cmpxchg some more
Date: Mon, 11 Jul 2022 22:13:19 -0700	[thread overview]
Message-ID: <Ys0C72unFFlsWomq@infradead.org> (raw)
In-Reply-To: <20220711153301.2388-1-ubizjak@gmail.com>

On Mon, Jul 11, 2022 at 05:33:01PM +0200, Uros Bizjak wrote:
> Use try_cmpxchg family of functions instead of cmpxchg (*ptr, old, new) == old.
> x86 CMPXCHG instruction returns success in ZF flag, so this change saves a
> compare after cmpxchg (and related move instruction in front of cmpxchg).
> 
> Also, try_cmpxchg implicitly assigns old *ptr value to "old" when
> cmpxchg fails, enabling further code simplifications.
> 
> No functional change intended.

You might want to split this into a patch per caller as it might
attact different reviewers.

> +	do {
> +	} while (old && !atomic_try_cmpxchg(&blkg->use_delay, &old, old - 1));

It might just be me, but for loops with an empty body this do { } while
construct looks odd.  Why not:

	while (old && !atomic_try_cmpxchg(&blkg->use_delay, &old, old - 1))
		;

?

The the use of the atomic on ->use_delay looks really whacky to start
with.  To me it sounds like it really wants to use a proper lock
instead of all this magic.

>  	else
>  		return;
>  
> -	old = atomic_cmpxchg(&iolat->scale_cookie, our_cookie, cur_cookie);
> -
> -	/* Somebody beat us to the punch, just bail. */
> -	if (old != our_cookie)
> +	if (!atomic_try_cmpxchg(&iolat->scale_cookie, &our_cookie, cur_cookie)) {
> +		/* Somebody beat us to the punch, just bail. */
>  		return;
> +	}


	/* If somebody beat us to the punch, just bail. */
	if (!atomic_try_cmpxchg(&iolat->scale_cookie, &our_cookie, cur_cookie))
		return;


  reply	other threads:[~2022-07-12  5:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11 15:33 [PATCH] block: Use try_cmpxchg some more Uros Bizjak
2022-07-12  5:13 ` Christoph Hellwig [this message]
2022-07-12  7:04   ` Uros Bizjak
2022-07-12 12:48     ` Bart Van Assche

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=Ys0C72unFFlsWomq@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.