From: Li RongQing <lirongqing@baidu.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] KVM: Micro-optimize pvclock_clocksource_read
Date: Fri, 3 Sep 2021 20:45:08 +0800 [thread overview]
Message-ID: <1630673108-9121-1-git-send-email-lirongqing@baidu.com> (raw)
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
next reply other threads:[~2021-09-03 12:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-03 12:45 Li RongQing [this message]
2021-09-29 9:20 Li RongQing
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1630673108-9121-1-git-send-email-lirongqing@baidu.com \
--to=lirongqing@baidu.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®