All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v9 0/9] x86 tlb optimisation and clean up
@ 2012-06-25  6:08 Alex Shi
  2012-06-25  6:08 ` [PATCH v9 1/9] x86/tlb_info: get last level TLB entry number of CPU Alex Shi
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Alex Shi @ 2012-06-25  6:08 UTC (permalink / raw)
  To: tglx, mingo, hpa, arnd, rostedt, fweisbec
  Cc: jeremy, alex.shi, luto, yinghai, riel, avi, len.brown, tj, akpm,
	cl, borislav.petkov, ak, jbeulich, eric.dumazet, akinobu.mita,
	vapier, cpw, steiner, viro, kamezawa.hiroyu, rientjes, aarcange,
	linux-kernel, yongjie.ren

Update to V9 version. This version is mainly for commit change.

1, It split the 6th patch into 6th and 7th for one patch to one issue.

2, update commit log for the 7th patch to include Yongjie's testing
results, I don't know why lkml can not show the e-mail, maybe some
words make it looks as spam?, Anyway I believe guys in to/cc list
have the data. So, attached the e-mail contents into log.

3, change commit log for 8th, 9th to include most clear explaination
and detailed testing result.


This patch set has clear performance gain, and clean up IDT table.

It is also quite safe after many review comments from Peter Anvin,
PeterZ, Nick Piggin, Steven Rostedt, Andi Kleen and Borislav etc. 
And it runs well with my long time performance testing...

Anyone like to give the reason if it is not readly for upstream?

Best Regards!
Alex


[PATCH v9 1/9] x86/tlb_info: get last level TLB entry number of CPU
[PATCH v9 2/9] x86/flush_tlb: try flush_tlb_single one by one in
[PATCH v9 3/9] x86/tlb: fall back to flush all when meet a THP large
[PATCH v9 4/9] x86/tlb: add tlb_flushall_shift for specific CPU
[PATCH v9 5/9] x86/tlb: add tlb_flushall_shift knob into debugfs
[PATCH v9 6/9] mm/mmu_gather: enable tlb flush range in generic
[PATCH v9 7/9] x86/tlb: enable tlb flush range support for x86
[PATCH v9 8/9] x86/tlb: replace INVALIDATE_TLB_VECTOR by
[PATCH v9 9/9] x86/tlb: do flush_tlb_kernel_range by 'invlpg'

^ permalink raw reply	[flat|nested] 20+ messages in thread
* [PATCH v10 5/9] x86/tlb: add tlb_flushall_shift knob into debugfs
@ 2012-06-28  1:02 Alex Shi
  2012-06-28 15:41 ` [tip:x86/mm] " tip-bot for Alex Shi
  0 siblings, 1 reply; 20+ messages in thread
From: Alex Shi @ 2012-06-28  1:02 UTC (permalink / raw)
  To: tglx, mingo, hpa, arnd, rostedt, fweisbec
  Cc: jeremy, alex.shi, luto, yinghai, riel, avi, len.brown, tj, akpm,
	cl, borislav.petkov, ak, jbeulich, eric.dumazet, akinobu.mita,
	vapier, cpw, steiner, viro, kamezawa.hiroyu, rientjes, aarcange,
	linux-kernel

kernel will replace cr3 rewrite with invlpg when
  tlb_flush_entries <= active_tlb_entries / 2^tlb_flushall_factor
if tlb_flushall_factor is -1, kernel won't do this replacement.

User can modify its value according to specific CPU/applications.

Thanks for Borislav providing the help message of
CONFIG_DEBUG_TLBFLUSH.

Signed-off-by: Alex Shi <alex.shi@intel.com>
---
 arch/x86/Kconfig.debug |   19 +++++++++++++++++
 arch/x86/mm/tlb.c      |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index e46c214..b322f12 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -129,6 +129,25 @@ config DOUBLEFAULT
 	  option saves about 4k and might cause you much additional grey
 	  hair.
 
+config DEBUG_TLBFLUSH
+	bool "Set upper limit of TLB entries to flush one-by-one"
+	depends on DEBUG_KERNEL && (X86_64 || X86_INVLPG)
+	---help---
+
+	X86-only for now.
+
+	This option allows the user to tune the amount of TLB entries the
+	kernel flushes one-by-one instead of doing a full TLB flush. In
+	certain situations, the former is cheaper. This is controlled by the
+	tlb_flushall_shift knob under /sys/kernel/debug/x86. If you set it
+	to -1, the code flushes the whole TLB unconditionally. Otherwise,
+	for positive values of it, the kernel will use single TLB entry
+	invalidating instructions according to the following formula:
+
+	flush_entries <= active_tlb_entries / 2^tlb_flushall_shift
+
+	If in doubt, say "N".
+
 config IOMMU_DEBUG
 	bool "Enable IOMMU debugging"
 	depends on GART_IOMMU && DEBUG_KERNEL
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 2939f2f..5911f61 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -12,6 +12,7 @@
 #include <asm/cache.h>
 #include <asm/apic.h>
 #include <asm/uv/uv.h>
+#include <linux/debugfs.h>
 
 DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate)
 			= { &init_mm, 0, };
@@ -430,3 +431,53 @@ void flush_tlb_all(void)
 {
 	on_each_cpu(do_flush_tlb_all, NULL, 1);
 }
+
+#ifdef CONFIG_DEBUG_TLBFLUSH
+static ssize_t tlbflush_read_file(struct file *file, char __user *user_buf,
+			     size_t count, loff_t *ppos)
+{
+	char buf[32];
+	unsigned int len;
+
+	len = sprintf(buf, "%hd\n", tlb_flushall_shift);
+	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t tlbflush_write_file(struct file *file,
+		 const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	char buf[32];
+	ssize_t len;
+	s8 shift;
+
+	len = min(count, sizeof(buf) - 1);
+	if (copy_from_user(buf, user_buf, len))
+		return -EFAULT;
+
+	buf[len] = '\0';
+	if (kstrtos8(buf, 0, &shift))
+		return -EINVAL;
+
+	if (shift > 64)
+		return -EINVAL;
+
+	tlb_flushall_shift = shift;
+	return count;
+}
+
+static const struct file_operations fops_tlbflush = {
+	.read = tlbflush_read_file,
+	.write = tlbflush_write_file,
+	.llseek = default_llseek,
+};
+
+static int __cpuinit create_tlb_flushall_shift(void)
+{
+	if (cpu_has_invlpg) {
+		debugfs_create_file("tlb_flushall_shift", S_IRUSR | S_IWUSR,
+			arch_debugfs_dir, NULL, &fops_tlbflush);
+	}
+	return 0;
+}
+late_initcall(create_tlb_flushall_shift);
+#endif
-- 
1.7.5.4


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

end of thread, other threads:[~2012-06-28 15:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-25  6:08 [PATCH v9 0/9] x86 tlb optimisation and clean up Alex Shi
2012-06-25  6:08 ` [PATCH v9 1/9] x86/tlb_info: get last level TLB entry number of CPU Alex Shi
2012-06-26 15:13   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 2/9] x86/flush_tlb: try flush_tlb_single one by one in flush_tlb_range Alex Shi
2012-06-26 15:13   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 3/9] x86/tlb: fall back to flush all when meet a THP large page Alex Shi
2012-06-26 15:14   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 4/9] x86/tlb: add tlb_flushall_shift for specific CPU Alex Shi
2012-06-26 15:15   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 5/9] x86/tlb: add tlb_flushall_shift knob into debugfs Alex Shi
2012-06-26 15:16   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 6/9] mm/mmu_gather: enable tlb flush range in generic mmu_gather Alex Shi
2012-06-26 15:17   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 7/9] x86/tlb: enable tlb flush range support for x86 Alex Shi
2012-06-26 15:18   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 8/9] x86/tlb: replace INVALIDATE_TLB_VECTOR by CALL_FUNCTION_VECTOR Alex Shi
2012-06-26 15:19   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-25  6:08 ` [PATCH v9 9/9] x86/tlb: do flush_tlb_kernel_range by 'invlpg' Alex Shi
2012-06-26 15:19   ` [tip:x86/mm] " tip-bot for Alex Shi
2012-06-28  1:02 [PATCH v10 5/9] x86/tlb: add tlb_flushall_shift knob into debugfs Alex Shi
2012-06-28 15:41 ` [tip:x86/mm] " tip-bot for Alex Shi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.