Skip to content

Commit

Permalink
drm/amdgpu: Use local64_try_cmpxchg in amdgpu_perf_read
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ubizjak authored and alexdeucher committed Aug 9, 2023
1 parent 59070fd commit 9e761bf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ static void amdgpu_perf_read(struct perf_event *event)
(!pe->adev->df.funcs->pmc_get_count))
return;

prev = local64_read(&hwc->prev_count);
do {
prev = local64_read(&hwc->prev_count);

switch (hwc->config_base) {
case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
Expand All @@ -289,7 +288,7 @@ static void amdgpu_perf_read(struct perf_event *event)
count = 0;
break;
}
} while (local64_cmpxchg(&hwc->prev_count, prev, count) != prev);
} while (!local64_try_cmpxchg(&hwc->prev_count, &prev, count));

local64_add(count - prev, &event->count);
}
Expand Down

0 comments on commit 9e761bf

Please sign in to comment.