From: Ingo Molnar <mingo@elte.hu>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>,
tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org,
heukelum@fastmail.fm
Subject: Re: [PATCH 2/5] x86: ret_from_fork - get rid of jump back
Date: Thu, 27 Nov 2008 14:41:21 +0100 [thread overview]
Message-ID: <20081127134121.GA22736@elte.hu> (raw)
In-Reply-To: <20081126201054.GB2624@localhost>
* Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> [Andi Kleen - Wed, Nov 26, 2008 at 09:04:33PM +0100]
> | gorcunov@gmail.com writes:
> | > --- a/arch/x86/kernel/entry_64.S
> | > +++ b/arch/x86/kernel/entry_64.S
> | > @@ -379,7 +379,10 @@ ENTRY(ret_from_fork)
> | > GET_THREAD_INFO(%rcx)
> | > testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
> | > CFI_REMEMBER_STATE
> | > - jnz rff_trace
> | > + jz rff_action
> | > + movq %rsp,%rdi
> | > + call syscall_trace_leave
> | > + GET_THREAD_INFO(%rcx)
> |
> | The uncommon path is supposed to be out of line. I don't think
> | the CPU will like that.
> |
> | -Andi
> |
> | > rff_action:
> |
> | --
> | ak@linux.intel.com
> |
>
> Aha! Thanks Andi for review.
Unfortunately that review got you off the right track ...
The principle you applied was good: entry_64.S is murky, and we want
to simplify the current overcomplicated assembly code flow spaghetti
there.
Note that if you take a closer look at rff_trace/rff_action
ret_from_fork code here, you'll realize that it does all the wrong
things: for example it checks the TIF flag - while later on jumping
back to the ret-from-syscall path - duplicating the check needlessly.
But it gets worse than that: checking for _TIF_SYSCALL_TRACE is
completely unnecessary here because we clear that flag for every
freshly forked task. So the whole "tracing" code here, for which there
is this "out of line jump optimization" is in reality completely dead
code in the ptrace case...
Could you test something like the patch attached below, which cleans
up this code and applies the code reduction and speedup? Warning:
completely untested! Please check that things like strace -f and gdb
attaching to forked tasks still works fine. (it should by all means)
Thanks,
Ingo
---
arch/x86/kernel/entry_64.S | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
Index: linux/arch/x86/kernel/entry_64.S
===================================================================
--- linux.orig/arch/x86/kernel/entry_64.S
+++ linux/arch/x86/kernel/entry_64.S
@@ -366,34 +366,35 @@ ENTRY(save_paranoid)
END(save_paranoid)
/*
- * A newly forked process directly context switches into this.
+ * A newly forked process directly context switches into this address.
+ *
+ * rdi: prev task we switched from
*/
-/* rdi: prev */
ENTRY(ret_from_fork)
DEFAULT_FRAME
+
push kernel_eflags(%rip)
CFI_ADJUST_CFA_OFFSET 8
- popf # reset kernel eflags
+ popf # reset kernel eflags
CFI_ADJUST_CFA_OFFSET -8
- call schedule_tail
+
+ call schedule_tail # rdi: 'prev' task parameter
+
GET_THREAD_INFO(%rcx)
- testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
+
CFI_REMEMBER_STATE
- jnz rff_trace
-rff_action:
RESTORE_REST
- testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread?
+
+ testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
je int_ret_from_sys_call
- testl $_TIF_IA32,TI_flags(%rcx)
+
+ testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
jnz int_ret_from_sys_call
+
RESTORE_TOP_OF_STACK %rdi, -ARGOFFSET
- jmp ret_from_sys_call
+ jmp ret_from_sys_call # go to the SYSRET fastpath
+
CFI_RESTORE_STATE
-rff_trace:
- movq %rsp,%rdi
- call syscall_trace_leave
- GET_THREAD_INFO(%rcx)
- jmp rff_action
CFI_ENDPROC
END(ret_from_fork)
next prev parent reply other threads:[~2008-11-27 13:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-26 19:16 x86 -tip: entry_64.S cleanup series gorcunov
2008-11-26 19:17 ` [PATCH 1/5] x86: entry_64.S - use ENTRY to define child_rip gorcunov
2008-11-26 19:17 ` [PATCH 2/5] x86: ret_from_fork - get rid of jump back gorcunov
2008-11-26 19:33 ` Cyrill Gorcunov
2008-11-26 20:04 ` Andi Kleen
2008-11-26 20:10 ` Cyrill Gorcunov
2008-11-26 20:15 ` Cyrill Gorcunov
2008-11-27 13:41 ` Ingo Molnar [this message]
2008-11-27 14:16 ` Andi Kleen
2008-11-28 13:47 ` Ingo Molnar
2008-11-28 18:55 ` Andi Kleen
2008-11-27 16:20 ` Cyrill Gorcunov
2008-11-27 19:12 ` Cyrill Gorcunov
2008-11-26 19:17 ` [PATCH 3/5] x86: entry_64.S - use X86_EFLAGS_IF instead of hardcoded number gorcunov
2008-11-27 10:37 ` Alexander van Heukelum
2008-11-27 12:00 ` Ingo Molnar
2008-11-26 19:17 ` [PATCH 4/5] x86: ret_from_fork - add CFI proc annotation gorcunov
2008-11-27 10:15 ` Alexander van Heukelum
2008-11-27 11:27 ` Cyrill Gorcunov
2008-11-26 19:17 ` [PATCH 5/5] x86: entry_64.S - trivial: space, comments fixup gorcunov
2008-11-27 10:39 ` Alexander van Heukelum
2008-11-27 12:02 ` Ingo Molnar
2008-11-27 12:25 ` Cyrill Gorcunov
2008-11-27 18:10 ` Cyrill Gorcunov
2008-11-28 13:54 ` Ingo Molnar
2008-11-27 10:37 ` [PATCH 1/5] x86: entry_64.S - use ENTRY to define child_rip Alexander van Heukelum
2008-11-27 12:04 ` 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=20081127134121.GA22736@elte.hu \
--to=mingo@elte.hu \
--cc=andi@firstfloor.org \
--cc=gorcunov@gmail.com \
--cc=heukelum@fastmail.fm \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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