Skip to content

Commit cae701b

Browse files
ubizjakvinodkoul
authored andcommitted
dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update
Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old in perfmon_pmu_event_update. 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. Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Vinod Koul <vkoul@kernel.org> Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com> Link: https://lore.kernel.org/r/20230703145346.5206-1-ubizjak@gmail.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent f1de55f commit cae701b

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

drivers/dma/idxd/perfmon.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,11 @@ static void perfmon_pmu_event_update(struct perf_event *event)
245245
int shift = 64 - idxd->idxd_pmu->counter_width;
246246
struct hw_perf_event *hwc = &event->hw;
247247

248+
prev_raw_count = local64_read(&hwc->prev_count);
248249
do {
249-
prev_raw_count = local64_read(&hwc->prev_count);
250250
new_raw_count = perfmon_pmu_read_counter(event);
251-
} while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
252-
new_raw_count) != prev_raw_count);
253-
251+
} while (!local64_try_cmpxchg(&hwc->prev_count,
252+
&prev_raw_count, new_raw_count));
254253
n = (new_raw_count << shift);
255254
p = (prev_raw_count << shift);
256255

0 commit comments

Comments
 (0)