From: riel@redhat.com
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, williams@redhat.com, luto@kernel.org,
mingo@kernel.org, bonzini@redhat.com, fweisbec@redhat.com,
peterz@infradead.org, heiko.carstens@de.ibm.com,
tglx@linutronix.de, Rik van Riel <riel@redhat.com>,
Ingo Molnar <mingo@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 3/3] context_tracking,x86: remove extraneous irq disable & enable from context tracking on syscall entry
Date: Thu, 30 Apr 2015 17:23:55 -0400 [thread overview]
Message-ID: <1430429035-25563-4-git-send-email-riel@redhat.com> (raw)
In-Reply-To: <1430429035-25563-1-git-send-email-riel@redhat.com>
From: Rik van Riel <riel@redhat.com>
On syscall entry with nohz_full on, we enable interrupts, call user_exit,
disable interrupts, do something, re-enable interrupts, and go on our
merry way.
Profiling shows that a large amount of the nohz_full overhead comes
from the extraneous disabling and re-enabling of interrupts. Andy
suggested simply not enabling interrupts until after the context
tracking code has done its thing, which allows us to skip a whole
interrupt disable & re-enable cycle.
This patch builds on top of these patches by Paolo:
https://lkml.org/lkml/2015/4/28/188
https://lkml.org/lkml/2015/4/29/139
Together with this patch I posted earlier this week, the syscall path
on a nohz_full cpu seems to be about 10% faster.
https://lkml.org/lkml/2015/4/24/394
My test is a simple microbenchmark that calls getpriority() in a loop
10 million times:
run time system time
vanilla 5.49s 2.08s
__acct patch 5.21s 1.92s
both patches 4.88s 1.71s
Cc: Frederic Weisbecker <fweisbec@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Suggested-by: Andy Lutomirsky <amluto@amacapital.net>
Signed-off-by: Rik van Riel <riel@redhat.com>
---
arch/x86/kernel/entry_32.S | 4 ++--
arch/x86/kernel/entry_64.S | 4 ++--
arch/x86/kernel/ptrace.c | 6 +++++-
include/linux/context_tracking.h | 11 +++++++++++
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 1c309763e321..0bdf8c7057e4 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -406,7 +406,6 @@ ENTRY(ia32_sysenter_target)
pushl_cfi %eax
SAVE_ALL
- ENABLE_INTERRUPTS(CLBR_NONE)
/*
* Load the potential sixth argument from user stack.
@@ -424,6 +423,7 @@ ENTRY(ia32_sysenter_target)
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
jnz sysenter_audit
+ ENABLE_INTERRUPTS(CLBR_NONE)
sysenter_do_call:
cmpl $(NR_syscalls), %eax
jae sysenter_badsys
@@ -647,7 +647,7 @@ END(work_pending)
syscall_trace_entry:
movl $-ENOSYS,PT_EAX(%esp)
movl %esp, %eax
- call syscall_trace_enter
+ call syscall_trace_enter /* returns with irqs enabled */
/* What it returned is what we'll actually use. */
cmpl $(NR_syscalls), %eax
jnae syscall_call
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 02c2eff7478d..f7751da7b53e 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -228,7 +228,6 @@ GLOBAL(system_call_after_swapgs)
* task preemption. We must enable interrupts only after we're done
* with using rsp_scratch:
*/
- ENABLE_INTERRUPTS(CLBR_NONE)
pushq_cfi %r11 /* pt_regs->flags */
pushq_cfi $__USER_CS /* pt_regs->cs */
pushq_cfi %rcx /* pt_regs->ip */
@@ -248,6 +247,7 @@ GLOBAL(system_call_after_swapgs)
testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jnz tracesys
+ ENABLE_INTERRUPTS(CLBR_NONE)
system_call_fastpath:
#if __SYSCALL_MASK == ~0
cmpq $__NR_syscall_max,%rax
@@ -313,7 +313,7 @@ GLOBAL(system_call_after_swapgs)
tracesys:
movq %rsp, %rdi
movl $AUDIT_ARCH_X86_64, %esi
- call syscall_trace_enter_phase1
+ call syscall_trace_enter_phase1 /* returns with interrupts enabled */
test %rax, %rax
jnz tracesys_phase2 /* if needed, run the slow path */
RESTORE_C_REGS_EXCEPT_RAX /* else restore clobbered regs */
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index a7bc79480719..066c86d0b68c 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -1456,6 +1456,8 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
*
* NB: We don't have full pt_regs here, but regs->orig_ax and regs->ax
* are fully functional.
+ * Called with IRQs disabled, to be enabled after the context tracking
+ * code has run.
*
* For phase 2's benefit, our return value is:
* 0: resume the syscall
@@ -1477,10 +1479,12 @@ unsigned long syscall_trace_enter_phase1(struct pt_regs *regs, u32 arch)
* doing anything that could touch RCU.
*/
if (work & _TIF_NOHZ) {
- user_exit();
+ user_exit_irqsoff();
work &= ~_TIF_NOHZ;
}
+ local_irq_enable();
+
#ifdef CONFIG_SECCOMP
/*
* Do seccomp first -- it should minimize exposure of other
diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index 5d3719aed958..dc3b169b2b70 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -25,12 +25,23 @@ static inline void user_enter(void)
context_tracking_enter(CONTEXT_USER);
}
+
static inline void user_exit(void)
{
if (context_tracking_is_enabled())
context_tracking_exit(CONTEXT_USER);
}
+/* Called with IRQs already disabled. */
+static inline void user_exit_irqsoff(void)
+{
+ if (in_interrupt())
+ return;
+
+ if (context_tracking_is_enabled())
+ __context_tracking_exit(CONTEXT_USER);
+}
+
static inline enum ctx_state exception_enter(void)
{
enum ctx_state prev_ctx;
--
2.1.0
next prev parent reply other threads:[~2015-04-30 21:24 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 21:23 [PATCH 0/3] reduce nohz_full syscall overhead by 10% riel
2015-04-30 21:23 ` [PATCH 1/3] reduce indentation in __acct_update_integrals riel
2015-04-30 21:23 ` [PATCH 2/3] remove local_irq_save from __acct_update_integrals riel
2015-04-30 21:23 ` riel [this message]
2015-04-30 21:56 ` [PATCH 3/3] context_tracking,x86: remove extraneous irq disable & enable from context tracking on syscall entry Andy Lutomirski
2015-05-01 6:40 ` Ingo Molnar
2015-05-01 15:20 ` Rik van Riel
2015-05-01 15:59 ` Ingo Molnar
2015-05-01 16:03 ` Andy Lutomirski
2015-05-01 16:21 ` Ingo Molnar
2015-05-01 16:26 ` Rik van Riel
2015-05-01 16:34 ` Ingo Molnar
2015-05-01 18:05 ` Rik van Riel
2015-05-01 18:40 ` Ingo Molnar
2015-05-01 19:11 ` Rik van Riel
2015-05-01 19:37 ` Andy Lutomirski
2015-05-02 5:27 ` Ingo Molnar
2015-05-02 18:27 ` Rik van Riel
2015-05-03 18:41 ` Andy Lutomirski
2015-05-07 10:35 ` Ingo Molnar
2015-05-04 9:26 ` Paolo Bonzini
2015-05-04 13:30 ` Rik van Riel
2015-05-04 14:06 ` Rik van Riel
2015-05-04 14:19 ` Rik van Riel
2015-05-04 15:59 ` question about RCU dynticks_nesting Rik van Riel
2015-05-04 18:39 ` Paul E. McKenney
2015-05-04 19:39 ` Rik van Riel
2015-05-04 20:02 ` Paul E. McKenney
2015-05-04 20:13 ` Rik van Riel
2015-05-04 20:38 ` Paul E. McKenney
2015-05-04 20:53 ` Rik van Riel
2015-05-05 5:54 ` Paul E. McKenney
2015-05-06 1:49 ` Mike Galbraith
2015-05-06 3:44 ` Mike Galbraith
2015-05-06 6:06 ` Paul E. McKenney
2015-05-06 6:52 ` Mike Galbraith
2015-05-06 7:01 ` Mike Galbraith
2015-05-07 0:59 ` Frederic Weisbecker
2015-05-07 15:44 ` Rik van Riel
2015-05-04 19:00 ` Rik van Riel
2015-05-04 19:39 ` Paul E. McKenney
2015-05-04 19:59 ` Rik van Riel
2015-05-04 20:40 ` Paul E. McKenney
2015-05-05 10:53 ` Peter Zijlstra
2015-05-05 12:34 ` Paul E. McKenney
2015-05-05 13:00 ` Peter Zijlstra
2015-05-05 18:35 ` Paul E. McKenney
2015-05-05 21:09 ` Rik van Riel
2015-05-06 5:41 ` Paul E. McKenney
2015-05-05 10:48 ` Peter Zijlstra
2015-05-05 10:51 ` Peter Zijlstra
2015-05-05 12:30 ` Paul E. McKenney
2015-05-02 4:06 ` [PATCH 3/3] context_tracking,x86: remove extraneous irq disable & enable from context tracking on syscall entry Mike Galbraith
2015-05-01 16:37 ` Ingo Molnar
2015-05-01 16:40 ` Rik van Riel
2015-05-01 16:45 ` Ingo Molnar
2015-05-01 16:54 ` Rik van Riel
2015-05-01 17:12 ` Ingo Molnar
2015-05-01 17:22 ` Rik van Riel
2015-05-01 17:59 ` Ingo Molnar
2015-05-01 16:22 ` Rik van Riel
2015-05-01 16:27 ` Ingo Molnar
2015-05-03 13:23 ` Mike Galbraith
2015-05-03 17:30 ` Rik van Riel
2015-05-03 18:24 ` Andy Lutomirski
2015-05-03 18:52 ` Rik van Riel
2015-05-07 10:48 ` Ingo Molnar
2015-05-07 12:18 ` Frederic Weisbecker
2015-05-07 12:29 ` Ingo Molnar
2015-05-07 15:47 ` Rik van Riel
2015-05-08 7:58 ` Ingo Molnar
2015-05-07 12:22 ` Andy Lutomirski
2015-05-07 12:44 ` Ingo Molnar
2015-05-07 12:49 ` Ingo Molnar
2015-05-08 6:17 ` Paul E. McKenney
2015-05-07 12:52 ` Andy Lutomirski
2015-05-07 15:08 ` Ingo Molnar
2015-05-07 17:47 ` Andy Lutomirski
2015-05-08 6:37 ` Ingo Molnar
2015-05-08 10:59 ` Andy Lutomirski
2015-05-08 11:27 ` Ingo Molnar
2015-05-08 12:56 ` Andy Lutomirski
2015-05-08 13:27 ` Ingo Molnar
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=1430429035-25563-4-git-send-email-riel@redhat.com \
--to=riel@redhat.com \
--cc=bonzini@redhat.com \
--cc=fweisbec@redhat.com \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
--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
Powered by JetHome