* [PATCH] x86/pvclock: improve atomic update of last_value in pvclock_clocksource_read
@ 2023-01-18 20:23 Uros Bizjak
2023-01-31 14:22 ` [tip: sched/core] x86/pvclock: Improve atomic update of last_value in pvclock_clocksource_read() tip-bot2 for Uros Bizjak
0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2023-01-18 20:23 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
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@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip: sched/core] x86/pvclock: Improve atomic update of last_value in pvclock_clocksource_read()
2023-01-18 20:23 [PATCH] x86/pvclock: improve atomic update of last_value in pvclock_clocksource_read Uros Bizjak
@ 2023-01-31 14:22 ` tip-bot2 for Uros Bizjak
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-01-31 14:22 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Peter Zijlstra (Intel), Ingo Molnar, x86,
linux-kernel
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 5c9da9fe826d4a0d84bb322cca27cc8ad8d23b24
Gitweb: https://git.kernel.org/tip/5c9da9fe826d4a0d84bb322cca27cc8ad8d23b24
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Thu, 26 Jan 2023 16:08:35 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 31 Jan 2023 15:01:46 +01:00
x86/pvclock: Improve atomic update of last_value in pvclock_clocksource_read()
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@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/20230118202330.3740-1-ubizjak@gmail.com
Link: https://lore.kernel.org/r/20230126151323.643408110@infradead.org
---
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 eda37df..5a2a517 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;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-31 14:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-18 20:23 [PATCH] x86/pvclock: improve atomic update of last_value in pvclock_clocksource_read Uros Bizjak
2023-01-31 14:22 ` [tip: sched/core] x86/pvclock: Improve atomic update of last_value in pvclock_clocksource_read() tip-bot2 for Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox