Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Uros Bizjak and committed by
Alex Deucher
9e761bff 59070fd9

+2 -3
+2 -3
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
··· 276 276 (!pe->adev->df.funcs->pmc_get_count)) 277 277 return; 278 278 279 + prev = local64_read(&hwc->prev_count); 279 280 do { 280 - prev = local64_read(&hwc->prev_count); 281 - 282 281 switch (hwc->config_base) { 283 282 case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF: 284 283 case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI: ··· 288 289 count = 0; 289 290 break; 290 291 } 291 - } while (local64_cmpxchg(&hwc->prev_count, prev, count) != prev); 292 + } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, count)); 292 293 293 294 local64_add(count - prev, &event->count); 294 295 }