Skip to content

Commit bcc6ec3

Browse files
ubizjakIngo Molnar
authored and
Ingo Molnar
committed
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 <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1ce19bf commit bcc6ec3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

arch/x86/events/rapl.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,11 @@ static u64 rapl_event_update(struct perf_event *event)
179179
s64 delta, sdelta;
180180
int shift = RAPL_CNTR_WIDTH;
181181

182-
again:
183182
prev_raw_count = local64_read(&hwc->prev_count);
184-
rdmsrl(event->hw.event_base, new_raw_count);
185-
186-
if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
187-
new_raw_count) != prev_raw_count)
188-
goto again;
183+
do {
184+
rdmsrl(event->hw.event_base, new_raw_count);
185+
} while (!local64_try_cmpxchg(&hwc->prev_count,
186+
&prev_raw_count, new_raw_count));
189187

190188
/*
191189
* Now we have the new raw value and have updated the prev

0 commit comments

Comments
 (0)