diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2023-08-07 16:51:15 +0200 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2023-10-03 21:13:45 +0200 |
commit | bcc6ec3d954bbcc8bec34a21c05ea536a2e96d6f (patch) | |
tree | cf909666dfcc86ec6ec2c583c4db4cd5696264fe /arch/x86/events | |
parent | 1ce19bf90bd55bf54f9ed75d594029db63d395b0 (diff) |
perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update()
Use local64_try_cmpxchg() instead of local64_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. There is no need to re-read the value in the loop.
No functional change intended.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/r/20230807145134.3176-2-ubizjak@gmail.com
Diffstat (limited to 'arch/x86/events')
-rw-r--r-- | arch/x86/events/rapl.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index e8f53b2590a5..6d3e73848643 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -179,13 +179,11 @@ static u64 rapl_event_update(struct perf_event *event) s64 delta, sdelta; int shift = RAPL_CNTR_WIDTH; -again: prev_raw_count = local64_read(&hwc->prev_count); - rdmsrl(event->hw.event_base, new_raw_count); - - if (local64_cmpxchg(&hwc->prev_count, prev_raw_count, - new_raw_count) != prev_raw_count) - goto again; + do { + rdmsrl(event->hw.event_base, new_raw_count); + } while (!local64_try_cmpxchg(&hwc->prev_count, + &prev_raw_count, new_raw_count)); /* * Now we have the new raw value and have updated the prev |