Skip to content

Commit 9e761bf

Browse files
ubizjakalexdeucher
authored andcommitted
drm/amdgpu: Use local64_try_cmpxchg in amdgpu_perf_read
Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old in amdgpu_perf_read. 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: Alex Deucher <[email protected]> Cc: "Christian König" <[email protected]> Cc: "Pan, Xinhui" <[email protected]> Cc: David Airlie <[email protected]> Cc: Daniel Vetter <[email protected]> Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 59070fd commit 9e761bf

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,8 @@ static void amdgpu_perf_read(struct perf_event *event)
276276
(!pe->adev->df.funcs->pmc_get_count))
277277
return;
278278

279+
prev = local64_read(&hwc->prev_count);
279280
do {
280-
prev = local64_read(&hwc->prev_count);
281-
282281
switch (hwc->config_base) {
283282
case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
284283
case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
@@ -289,7 +288,7 @@ static void amdgpu_perf_read(struct perf_event *event)
289288
count = 0;
290289
break;
291290
}
292-
} while (local64_cmpxchg(&hwc->prev_count, prev, count) != prev);
291+
} while (!local64_try_cmpxchg(&hwc->prev_count, &prev, count));
293292

294293
local64_add(count - prev, &event->count);
295294
}

0 commit comments

Comments
 (0)