lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1632907214-29633-1-git-send-email-lirongqing@baidu.com>
Date:   Wed, 29 Sep 2021 17:20:14 +0800
From:   Li RongQing <lirongqing@...du.com>
To:     lirongqing@...du.com, linux-kernel@...r.kernel.org,
        tglx@...utronix.de
Subject: [PATCH] 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 <lirongqing@...du.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ