summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2022-07-12 17:05:47 +0200
committerJens Axboe <axboe@kernel.dk>2022-07-12 14:38:52 -0600
commitf4b1e27db49c8b985b116aa99481b4c6a4342ed4 (patch)
tree00b3861f47de1e179c300fc038c78fc1a3854a5f /block
parentf3ec5d11554778c24ac8915e847223ed71d104fc (diff)
block/rq_qos: Use atomic_try_cmpxchg in atomic_inc_below
Use atomic_try_cmpxchg instead of atomic_cmpxchg (*ptr, old, new) == old in atomic_inc_below. 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, atomic_try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails, enabling further code simplifications. No functional change intended. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Cc: Jens Axboe <axboe@kernel.dk> Link: https://lore.kernel.org/r/20220712150547.5786-1-ubizjak@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/blk-rq-qos.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index d3a75693adbf..88f0fe7dcf54 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -10,16 +10,10 @@ static bool atomic_inc_below(atomic_t *v, unsigned int below)
{
unsigned int cur = atomic_read(v);
- for (;;) {
- unsigned int old;
-
+ do {
if (cur >= below)
return false;
- old = atomic_cmpxchg(v, cur, cur + 1);
- if (old == cur)
- break;
- cur = old;
- }
+ } while (!atomic_try_cmpxchg(v, &cur, cur + 1));
return true;
}