public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] x86, tlb: switch cr3 in leave_mm() only when needed
@ 2012-03-22 23:33 Suresh Siddha
  2012-03-22 23:44 ` Linus Torvalds
  0 siblings, 1 reply; 10+ messages in thread
From: Suresh Siddha @ 2012-03-22 23:33 UTC (permalink / raw)
  To: Ingo Molnar, H. Peter Anvin, Linus Torvalds, Len Brown; +Cc: LKML

From: Suresh Siddha <suresh.b.siddha@intel.com>
Subject: x86, tlb: switch cr3 in leave_mm() only when needed

Currently leave_mm() unconditionally switches the cr3 to swapper_pg_dir.
But there is no need to change the cr3, if we already left that mm.

intel_idle() for example calls leave_mm() on every deep c-state entry where
the CPU flushes the TLB for us. Similarly flush_tlb_all() was also calling
leave_mm() whenever the TLB is in LAZY state. Both these paths will be
improved with this change.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---
 arch/x86/mm/tlb.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index d6c0418..ad695cc 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -61,11 +61,11 @@ static DEFINE_PER_CPU_READ_MOSTLY(int, tlb_vector_offset);
  */
 void leave_mm(int cpu)
 {
+	struct mm_struct *active_mm = percpu_read(cpu_tlbstate.active_mm);
 	if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
 		BUG();
-	cpumask_clear_cpu(cpu,
-			  mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
-	load_cr3(swapper_pg_dir);
+	if (cpumask_test_and_clear_cpu(cpu, mm_cpumask(active_mm)))
+		load_cr3(swapper_pg_dir);
 }
 EXPORT_SYMBOL_GPL(leave_mm);
 



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-03-26 22:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-22 23:33 [patch] x86, tlb: switch cr3 in leave_mm() only when needed Suresh Siddha
2012-03-22 23:44 ` Linus Torvalds
2012-03-23  0:01   ` Suresh Siddha
2012-03-23  0:20     ` H. Peter Anvin
2012-03-23  0:37       ` Linus Torvalds
2012-03-23  0:51         ` Suresh Siddha
2012-03-23  8:37           ` Ingo Molnar
2012-03-26 22:47             ` Suresh Siddha
2012-03-26 22:47               ` H. Peter Anvin
2012-03-23  0:31     ` [tip:x86/mm] x86, tlb: Switch " tip-bot for Suresh Siddha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox