From: Waiman Long <longman@redhat.com>
To: Jeremy Fitzhardinge <jeremy@goop.org>,
Chris Wright <chrisw@sous-sol.org>,
Alok Kataria <akataria@vmware.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Cc: Waiman Long <longman@redhat.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: [PATCH] x86/paravirt: Avoid setting IF flag, if not necessary
Date: Mon, 6 Feb 2017 16:02:41 -0500 [thread overview]
Message-ID: <1486414961-1065-1-git-send-email-longman@redhat.com> (raw)
Setting the IF flag can cause an VM exit. So we should avoid touching
the IF flag until absolutely necessary. This patch change the way
the paravirt arch_local_irq_restore() works by checking the previous
flags value and call arch_local_irq_enable() only if the IF flag was
set previously.
On a 32 vCPUs KVM guest running the AIM7 five-sec workload,
the performance increased slightly from 302136.32 jobs/min to
306185.57 (about 1.3%) jobs/min and the %CPU time consumed by
_raw_spin_unlock_irqrestore decreased slightly from 1.68% to 1.53%
with this patch.
Signed-off-by: Waiman Long <longman@redhat.com>
---
arch/x86/include/asm/paravirt.h | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
index 1eea6ca..864f57b 100644
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -6,6 +6,7 @@
#ifdef CONFIG_PARAVIRT
#include <asm/pgtable_types.h>
#include <asm/asm.h>
+#include <asm/processor-flags.h>
#include <asm/paravirt_types.h>
@@ -762,11 +763,6 @@ static inline notrace unsigned long arch_local_save_flags(void)
return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
}
-static inline notrace void arch_local_irq_restore(unsigned long f)
-{
- PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
-}
-
static inline notrace void arch_local_irq_disable(void)
{
PVOP_VCALLEE0(pv_irq_ops.irq_disable);
@@ -786,6 +782,16 @@ static inline notrace unsigned long arch_local_irq_save(void)
return f;
}
+/*
+ * In a VM, setting the IF flag can cause an expensive VM exit. So if
+ * interrupt was disabled before arch_local_irq_save(), we don't need to
+ * do anything at all, thus saving an VM exit.
+ */
+static inline notrace void arch_local_irq_restore(unsigned long f)
+{
+ if (f & X86_EFLAGS_IF)
+ arch_local_irq_enable();
+}
/* Make sure as little as possible of this mess escapes. */
#undef PARAVIRT_CALL
--
1.8.3.1
next reply other threads:[~2017-02-06 21:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-06 21:02 Waiman Long [this message]
2017-02-09 2:13 ` [lkp-robot] [x86/paravirt] b1e955caea: WARNING:at_kernel/locking/lockdep.c:#trace_hardirqs_off_caller kernel test robot
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=1486414961-1065-1-git-send-email-longman@redhat.com \
--to=longman@redhat.com \
--cc=akataria@vmware.com \
--cc=chrisw@sous-sol.org \
--cc=hpa@zytor.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=tglx@linutronix.de \
--cc=virtualization@lists.linux-foundation.org \
--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;
as well as URLs for NNTP newsgroup(s).