kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu
Cc: christoffer.dall@linaro.org, pbonzini@redhat.com
Subject: [PATCH 3/3] arm/arm64: speed up spinlocks and atomic ops
Date: Thu, 25 Jun 2015 20:45:11 +0200	[thread overview]
Message-ID: <1435257911-9715-4-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1435257911-9715-1-git-send-email-drjones@redhat.com>

spinlock torture tests made it clear that checking mmu_enabled()
every time we call spin_lock is a bad idea. As most tests will
want the MMU enabled the entire time, then we can inline a light
weight "nobody disabled the mmu" check, and bail out early.

Adding a light weight inlined check vs. a compile-time flag
suggested by Paolo.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/mmu-api.h | 7 ++++++-
 lib/arm/mmu.c         | 9 +++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/arm/asm/mmu-api.h b/lib/arm/asm/mmu-api.h
index 12fdc57918c27..b2fc900a30add 100644
--- a/lib/arm/asm/mmu-api.h
+++ b/lib/arm/asm/mmu-api.h
@@ -1,7 +1,12 @@
 #ifndef __ASMARM_MMU_API_H_
 #define __ASMARM_MMU_API_H_
 extern pgd_t *mmu_idmap;
-extern bool mmu_enabled(void);
+extern unsigned int mmu_disabled_cpu_count;
+extern bool __mmu_enabled(void);
+static inline bool mmu_enabled(void)
+{
+	return mmu_disabled_cpu_count == 0 || __mmu_enabled();
+}
 extern void mmu_enable(pgd_t *pgtable);
 extern void mmu_disable(void);
 extern void mmu_enable_idmap(void);
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index ad558e177dd1c..e661d4f26e4b7 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -15,8 +15,9 @@ extern unsigned long etext;
 pgd_t *mmu_idmap;
 
 static cpumask_t mmu_disabled_cpumask;
+unsigned int mmu_disabled_cpu_count;
 
-bool mmu_enabled(void)
+bool __mmu_enabled(void)
 {
 	int cpu = current_thread_info()->cpu;
 
@@ -30,7 +31,9 @@ void mmu_enable(pgd_t *pgtable)
 
 	asm_mmu_enable(__pa(pgtable));
 	flush_tlb_all();
-	cpumask_clear_cpu(cpu, &mmu_disabled_cpumask);
+
+	if (cpumask_test_and_clear_cpu(cpu, &mmu_disabled_cpumask))
+		--mmu_disabled_cpu_count;
 }
 
 extern void asm_mmu_disable(void);
@@ -39,6 +42,8 @@ void mmu_disable(void)
 	int cpu = current_thread_info()->cpu;
 
 	cpumask_set_cpu(cpu, &mmu_disabled_cpumask);
+	++mmu_disabled_cpu_count;
+
 	asm_mmu_disable();
 }
 
-- 
2.4.3


  parent reply	other threads:[~2015-06-25 18:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 18:45 [PATCH 0/3] arm/arm64: rework mmu_enabled, for spinlock speedup Andrew Jones
2015-06-25 18:45 ` [PATCH 1/3] arm/arm64: Introduce mmu_disable Andrew Jones
2015-07-03 17:42   ` Paolo Bonzini
2015-06-25 18:45 ` [PATCH 2/3] arm/arm64: drop mmu_set_enabled Andrew Jones
2015-07-03 17:39   ` Paolo Bonzini
2015-07-06 12:41     ` Andrew Jones
2015-06-25 18:45 ` Andrew Jones [this message]
2015-07-03 17:43   ` [PATCH 3/3] arm/arm64: speed up spinlocks and atomic ops Paolo Bonzini

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=1435257911-9715-4-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=christoffer.dall@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=pbonzini@redhat.com \
    /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).