[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230123205515.001913664@infradead.org>
Date: Mon, 23 Jan 2023 21:50:11 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: mingo@...nel.org
Cc: will@...nel.org, peterz@...radead.org, boqun.feng@...il.com,
mark.rutland@....com, tglx@...utronix.de, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com,
seanjc@...gle.com, pbonzini@...hat.com, jgross@...e.com,
srivatsa@...il.mit.edu, amakhalov@...are.com,
pv-drivers@...are.com, rostedt@...dmis.org, mhiramat@...nel.org,
wanpengli@...cent.com, vkuznets@...hat.com,
boris.ostrovsky@...cle.com, rafael@...nel.org,
daniel.lezcano@...aro.org, juri.lelli@...hat.com,
vincent.guittot@...aro.org, dietmar.eggemann@....com,
bsegall@...gle.com, mgorman@...e.de, bristot@...hat.com,
vschneid@...hat.com, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, virtualization@...ts.linux-foundation.org,
linux-trace-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
Uros Bizjak <ubizjak@...il.com>
Subject: [PATCH 2/6] x86/pvclock: improve atomic update of last_value in pvclock_clocksource_read
From: Uros Bizjak <ubizjak@...il.com>
Improve atomic update of last_value in pvclock_clocksource_read:
- Atomic update can be skipped if the "last_value" is already
equal to "ret".
- The detection of atomic update failure is not correct. The value,
returned by atomic64_cmpxchg should be compared to the old value
from the location to be updated. If these two are the same, then
atomic update succeeded and "last_value" location is updated to
"ret" in an atomic way. Otherwise, the atomic update failed and
it should be retried with the value from "last_value" - exactly
what atomic64_try_cmpxchg does in a correct and more optimal way.
Signed-off-by: Uros Bizjak <ubizjak@...il.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Link: https://lkml.kernel.org/r/20230118202330.3740-1-ubizjak@gmail.com
---
arch/x86/kernel/pvclock.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index eda37df016f0..5a2a517dd61b 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -102,10 +102,9 @@ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
*/
last = atomic64_read(&last_value);
do {
- if (ret < last)
+ if (ret <= last)
return last;
- last = atomic64_cmpxchg(&last_value, last, ret);
- } while (unlikely(last != ret));
+ } while (!atomic64_try_cmpxchg(&last_value, &last, ret));
return ret;
}
--
2.39.0
Powered by blists - more mailing lists