* [PATCH] KVM: Micro-optimize pvclock_clocksource_read
@ 2021-09-29 9:20 Li RongQing
0 siblings, 0 replies; 2+ messages in thread
From: Li RongQing @ 2021-09-29 9:20 UTC (permalink / raw)
To: lirongqing, linux-kernel, tglx
Compare the return of atomic64_cmpxchg with previous save for last,
to reduce the number of while-loop iterations with atomic operations
from two to one in the most common situation
Original patch at:
https://kvm.vger.kernel.narkive.com/WraXedaQ/patch-kvm-pvclock-clocksource-read-while-loop-optimization
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
arch/x86/kernel/pvclock.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index eda37df..98d106f 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -67,8 +67,8 @@ u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
{
unsigned version;
+ u64 last, save;
u64 ret;
- u64 last;
u8 flags;
do {
@@ -104,8 +104,9 @@ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
do {
if (ret < last)
return last;
+ save = last;
last = atomic64_cmpxchg(&last_value, last, ret);
- } while (unlikely(last != ret));
+ } while (unlikely(last != save));
return ret;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] KVM: Micro-optimize pvclock_clocksource_read
@ 2021-09-03 12:45 Li RongQing
0 siblings, 0 replies; 2+ messages in thread
From: Li RongQing @ 2021-09-03 12:45 UTC (permalink / raw)
To: tglx, mingo, bp, x86, linux-kernel
Compare the return of atomic64_cmpxchg with previous save for last,
to reduce the number of while-loop iterations with atomic operations
from two to one in the most common situation
Original patch at:
https://kvm.vger.kernel.narkive.com/WraXedaQ/patch-kvm-pvclock-clocksource-read-while-loop-optimization
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
arch/x86/kernel/pvclock.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index eda37df..98d106f 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -67,8 +67,8 @@ u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
{
unsigned version;
+ u64 last, save;
u64 ret;
- u64 last;
u8 flags;
do {
@@ -104,8 +104,9 @@ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
do {
if (ret < last)
return last;
+ save = last;
last = atomic64_cmpxchg(&last_value, last, ret);
- } while (unlikely(last != ret));
+ } while (unlikely(last != save));
return ret;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-29 9:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 9:20 [PATCH] KVM: Micro-optimize pvclock_clocksource_read Li RongQing
-- strict thread matches above, loose matches on Subject: below --
2021-09-03 12:45 Li RongQing
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.