KVM: Micro-optimize pvclock_clocksource_read
PATCH 1/1 KVM: Micro-optimize pvclock_clocksource_read
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 <[email protected]>
--- arch/x86/kernel/pvclock.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/pvclock.c +3 -2
@@ -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; }
Signature · 1 line
1.7.1