Skip to content

Commit

Permalink
sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote}
Browse files Browse the repository at this point in the history
Use try_cmpxchg64 instead of cmpxchg64 (*ptr, old, new) != old in
sched_clock_{local,remote}. x86 cmpxchg returns success in ZF flag,
so this change saves a compare after cmpxchg (and related move
instruction in front of cmpxchg).

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220518184953.3446778-1-ubizjak@gmail.com
  • Loading branch information
Uros Bizjak authored and Peter Zijlstra committed May 19, 2022
1 parent c2df0a6 commit 8491d1b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/sched/clock.c
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ notrace static u64 sched_clock_local(struct sched_clock_data *scd)
clock = wrap_max(clock, min_clock);
clock = wrap_min(clock, max_clock);

if (cmpxchg64(&scd->clock, old_clock, clock) != old_clock)
if (!try_cmpxchg64(&scd->clock, &old_clock, clock))
goto again;

return clock;
@@ -349,7 +349,7 @@ notrace static u64 sched_clock_remote(struct sched_clock_data *scd)
val = remote_clock;
}

if (cmpxchg64(ptr, old_val, val) != old_val)
if (!try_cmpxchg64(ptr, &old_val, val))
goto again;

return val;

0 comments on commit 8491d1b

Please sign in to comment.