]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf/x86/amd: Use try_cmpxchg() in events/amd/{un,}core.c
authorUros Bizjak <ubizjak@gmail.com>
Thu, 25 Apr 2024 10:16:14 +0000 (12:16 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Aug 2024 13:34:00 +0000 (15:34 +0200)
[ Upstream commit cd84351c8c1baec86342d784feb884ace007d51c ]

Replace this pattern in events/amd/{un,}core.c:

    cmpxchg(*ptr, old, new) == old

... with the simpler and faster:

    try_cmpxchg(*ptr, &old, new)

The x86 CMPXCHG instruction returns success in the ZF flag, so this change
saves a compare after the CMPXCHG.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240425101708.5025-1-ubizjak@gmail.com
Stable-dep-of: f73cefa3b72e ("perf/x86: Fix smp_processor_id()-in-preemptible warnings")
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/events/amd/core.c
arch/x86/events/amd/uncore.c

index 1fc4ce44e743c037522e3712ba8386af35e0fe84..18bfe3451f3aa26b4dc614208f2dd73e1bd4014f 100644 (file)
@@ -433,7 +433,9 @@ static void __amd_put_nb_event_constraints(struct cpu_hw_events *cpuc,
         * when we come here
         */
        for (i = 0; i < x86_pmu.num_counters; i++) {
-               if (cmpxchg(nb->owners + i, event, NULL) == event)
+               struct perf_event *tmp = event;
+
+               if (try_cmpxchg(nb->owners + i, &tmp, NULL))
                        break;
        }
 }
index 5a4bfe9aea23784e49d214658bef3a9ec5fb4f12..0bfde2ea5cb8cec3701206b0570f7f6e869e7eb6 100644 (file)
@@ -162,7 +162,9 @@ static int amd_uncore_add(struct perf_event *event, int flags)
        /* if not, take the first available counter */
        hwc->idx = -1;
        for (i = 0; i < pmu->num_counters; i++) {
-               if (cmpxchg(&ctx->events[i], NULL, event) == NULL) {
+               struct perf_event *tmp = NULL;
+
+               if (try_cmpxchg(&ctx->events[i], &tmp, event)) {
                        hwc->idx = i;
                        break;
                }
@@ -196,7 +198,9 @@ static void amd_uncore_del(struct perf_event *event, int flags)
        event->pmu->stop(event, PERF_EF_UPDATE);
 
        for (i = 0; i < pmu->num_counters; i++) {
-               if (cmpxchg(&ctx->events[i], event, NULL) == event)
+               struct perf_event *tmp = event;
+
+               if (try_cmpxchg(&ctx->events[i], &tmp, NULL))
                        break;
        }