Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1631648
| From | Alexey Dobriyan <adobriyan@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/5] x86_64: inline copy_page() at call site |
| Date | 2017-04-26 20:30 +0200 |
| Message-ID | <tAzRo-5Yn-23@gated-at.bofh.it> (permalink) |
| References | <tAzRo-5Yn-17@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Avoid unconditional branch at every copy_page() call by using
alternatives and calling optimal variant directly.
Rename individual versions to immediately show which one is used in
profiles, etc.
RBX and R12 aren't clobbered because generic version restores them
and both REP versions don't touch them.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
arch/x86/include/asm/page_64.h | 16 ++++++++++++++--
arch/x86/lib/copy_page_64.S | 17 +++++++----------
2 files changed, 21 insertions(+), 12 deletions(-)
--- a/arch/x86/include/asm/page_64.h
+++ b/arch/x86/include/asm/page_64.h
@@ -49,8 +49,20 @@ static inline void clear_page(void *page)
: "memory", "rax", "rcx");
}
-void copy_page(void *to, void *from);
-
+void copy_page_mov(void *to, void *from);
+void copy_page_rep_movsq(void *to, void *from);
+void copy_page_rep_movsb(void *to, void *from);
+static __always_inline void copy_page(void *to, void *from)
+{
+ alternative_call_2(
+ copy_page_mov,
+ copy_page_rep_movsq, X86_FEATURE_REP_GOOD,
+ copy_page_rep_movsb, X86_FEATURE_ERMS,
+ ASM_OUTPUT2("=D" (to), "=S" (from)),
+ "0" (to), "1" (from)
+ : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "cc", "memory"
+ );
+}
#endif /* !__ASSEMBLY__ */
#ifdef CONFIG_X86_VSYSCALL_EMULATION
--- a/arch/x86/lib/copy_page_64.S
+++ b/arch/x86/lib/copy_page_64.S
@@ -1,8 +1,6 @@
/* Written 2003 by Andi Kleen, based on a kernel by Evandro Menezes */
#include <linux/linkage.h>
-#include <asm/cpufeatures.h>
-#include <asm/alternative-asm.h>
#include <asm/export.h>
/*
@@ -12,23 +10,21 @@
* prefetch distance based on SMP/UP.
*/
ALIGN
-ENTRY(copy_page)
- ALTERNATIVE_2 "jmp copy_page_regs", \
- "", X86_FEATURE_REP_GOOD, \
- "jmp copy_page_rep_movsb", X86_FEATURE_ERMS
+ENTRY(copy_page_rep_movsq)
movl $4096/8, %ecx
rep movsq
ret
-ENDPROC(copy_page)
-EXPORT_SYMBOL(copy_page)
+ENDPROC(copy_page_rep_movsq)
+EXPORT_SYMBOL(copy_page_rep_movsq)
ENTRY(copy_page_rep_movsb)
mov $4096, %ecx
rep movsb
ret
ENDPROC(copy_page_rep_movsb)
+EXPORT_SYMBOL(copy_page_rep_movsb)
-ENTRY(copy_page_regs)
+ENTRY(copy_page_mov)
subq $2*8, %rsp
movq %rbx, (%rsp)
movq %r12, 1*8(%rsp)
@@ -93,4 +89,5 @@ ENTRY(copy_page_regs)
movq 1*8(%rsp), %r12
addq $2*8, %rsp
ret
-ENDPROC(copy_page_regs)
+ENDPROC(copy_page_mov)
+EXPORT_SYMBOL(copy_page_mov)
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/5] x86_64: use REP MOVSB in copy_page() Alexey Dobriyan <adobriyan@gmail.com> - 2017-04-26 20:30 +0200
[PATCH 2/5] x86_64: inline copy_page() at call site Alexey Dobriyan <adobriyan@gmail.com> - 2017-04-26 20:30 +0200
[PATCH 3/5] x86_64: rename clear_page() and copy_user() variants Alexey Dobriyan <adobriyan@gmail.com> - 2017-04-26 20:40 +0200
[PATCH 5/5] x86_64: garbage collect headers in clear_page.S Alexey Dobriyan <adobriyan@gmail.com> - 2017-04-26 20:40 +0200
[PATCH 4/5] x86_64: clobber "cc" in inlined clear_page() Alexey Dobriyan <adobriyan@gmail.com> - 2017-04-26 20:40 +0200
Re: [PATCH 3/5] x86_64: rename clear_page() and copy_user() variants Borislav Petkov <bp@alien8.de> - 2017-05-05 19:00 +0200
Re: [PATCH 2/5] x86_64: inline copy_page() at call site Borislav Petkov <bp@alien8.de> - 2017-04-28 23:10 +0200
Re: [PATCH 2/5] x86_64: inline copy_page() at call site Alexey Dobriyan <adobriyan@gmail.com> - 2017-05-02 13:50 +0200
Re: [PATCH 2/5] x86_64: inline copy_page() at call site Borislav Petkov <bp@alien8.de> - 2017-05-02 14:10 +0200
csiph-web