From: Alexey Dobriyan <adobriyan@gmail.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] x86: branchless copy_page()
Date: Tue, 23 Aug 2016 19:28:21 +0300 [thread overview]
Message-ID: <20160823162821.GA2433@p183.telecom.by> (raw)
In-Reply-To: <20160823162533.GB2286@p183.telecom.by>
Apply alternatives at the call site instead of function body.
Save branch per copied page.
Rename individual function, show immediately in profiles
which method is being used.
RBX and R12 are saved and restored by unrolled-mov implementation,
don't clobber them explicitly.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
arch/x86/include/asm/page_64.h | 15 ++++++++++++++-
arch/x86/kernel/x8664_ksyms_64.c | 4 +++-
arch/x86/lib/copy_page_64.S | 14 ++++----------
3 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,21 @@ static __always_inline void clear_page(void *page)
: "rax", "rcx", "memory"
);
}
-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", "memory"
+ );
+}
#endif /* !__ASSEMBLY__ */
#ifdef CONFIG_X86_VSYSCALL_EMULATION
--- a/arch/x86/kernel/x8664_ksyms_64.c
+++ b/arch/x86/kernel/x8664_ksyms_64.c
@@ -40,7 +40,9 @@ EXPORT_SYMBOL(_copy_to_user);
EXPORT_SYMBOL_GPL(memcpy_mcsafe);
-EXPORT_SYMBOL(copy_page);
+EXPORT_SYMBOL(copy_page_mov);
+EXPORT_SYMBOL(copy_page_rep_movsq);
+EXPORT_SYMBOL(copy_page_rep_movsb);
EXPORT_SYMBOL(clear_page_mov);
EXPORT_SYMBOL(clear_page_rep_stosq);
EXPORT_SYMBOL(clear_page_rep_stosb);
--- 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>
/*
* Some CPUs run faster using the string copy instructions (sane microcode).
@@ -11,15 +9,11 @@
* 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)
+ENDPROC(copy_page_rep_movsq)
ENTRY(copy_page_rep_movsb)
mov $4096, %ecx
@@ -27,7 +21,7 @@ ENTRY(copy_page_rep_movsb)
ret
ENDPROC(copy_page_rep_movsb)
-ENTRY(copy_page_regs)
+ENTRY(copy_page_mov)
subq $2*8, %rsp
movq %rbx, (%rsp)
movq %r12, 1*8(%rsp)
@@ -92,4 +86,4 @@ ENTRY(copy_page_regs)
movq 1*8(%rsp), %r12
addq $2*8, %rsp
ret
-ENDPROC(copy_page_regs)
+ENDPROC(copy_page_mov)
prev parent reply other threads:[~2016-08-23 16:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-22 20:52 [PATCH] x86: branchless clear_page() Alexey Dobriyan
2016-08-22 20:54 ` Alexey Dobriyan
2016-08-22 21:06 ` Borislav Petkov
2016-08-23 10:46 ` Alexey Dobriyan
2016-08-23 13:43 ` Brian Gerst
2016-08-23 16:15 ` Alexey Dobriyan
2016-08-23 16:19 ` [PATCH 1/3] " Alexey Dobriyan
2016-08-23 16:25 ` [PATCH 2/3] x86: support REP MOVSB copy_page() Alexey Dobriyan
2016-08-23 16:28 ` Alexey Dobriyan [this message]
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=20160823162821.GA2433@p183.telecom.by \
--to=adobriyan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).