From: Alexey Dobriyan <adobriyan@gmail.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] x86: branchless clear_page()
Date: Mon, 22 Aug 2016 23:52:29 +0300 [thread overview]
Message-ID: <20160822205229.GA2638@p183.telecom.by> (raw)
Apply alternatives at the call site instead of function body.
Save branch per clean page.
Bonus: tell gcc to not flush whole shebang of registers,
just RDI, RAX, RCX.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
arch/x86/include/asm/page_64.h | 16 +++++++++++++++-
arch/x86/lib/clear_page_64.S | 18 ++++++------------
2 files changed, 21 insertions(+), 13 deletions(-)
--- a/arch/x86/include/asm/page_64.h
+++ b/arch/x86/include/asm/page_64.h
@@ -4,6 +4,7 @@
#include <asm/page_64_types.h>
#ifndef __ASSEMBLY__
+#include <asm/alternative.h>
/* duplicated to the one in bootmem.h */
extern unsigned long max_pfn;
@@ -34,7 +35,20 @@ extern unsigned long __phys_addr_symbol(unsigned long);
#define pfn_valid(pfn) ((pfn) < max_pfn)
#endif
-void clear_page(void *page);
+void clear_page_mov(void *page);
+void clear_page_rep_stosq(void *page);
+void clear_page_rep_stosb(void *page);
+static __always_inline void clear_page(void *page)
+{
+ alternative_call_2(
+ clear_page_mov,
+ clear_page_rep_stosq, X86_FEATURE_REP_GOOD,
+ clear_page_rep_stosb, X86_FEATURE_ERMS,
+ "=D" (page),
+ "0" (page)
+ : "rax", "rcx", "memory"
+ );
+}
void copy_page(void *to, void *from);
#endif /* !__ASSEMBLY__ */
--- a/arch/x86/lib/clear_page_64.S
+++ b/arch/x86/lib/clear_page_64.S
@@ -1,6 +1,4 @@
#include <linux/linkage.h>
-#include <asm/cpufeatures.h>
-#include <asm/alternative-asm.h>
/*
* Most CPUs support enhanced REP MOVSB/STOSB instructions. It is
@@ -13,18 +11,14 @@
* Zero a page.
* %rdi - page
*/
-ENTRY(clear_page)
-
- ALTERNATIVE_2 "jmp clear_page_orig", "", X86_FEATURE_REP_GOOD, \
- "jmp clear_page_c_e", X86_FEATURE_ERMS
-
+ENTRY(clear_page_rep_stosq)
movl $4096/8,%ecx
xorl %eax,%eax
rep stosq
ret
-ENDPROC(clear_page)
+ENDPROC(clear_page_rep_stosq)
-ENTRY(clear_page_orig)
+ENTRY(clear_page_mov)
xorl %eax,%eax
movl $4096/64,%ecx
@@ -44,11 +38,11 @@ ENTRY(clear_page_orig)
jnz .Lloop
nop
ret
-ENDPROC(clear_page_orig)
+ENDPROC(clear_page_mov)
-ENTRY(clear_page_c_e)
+ENTRY(clear_page_rep_stosb)
movl $4096,%ecx
xorl %eax,%eax
rep stosb
ret
-ENDPROC(clear_page_c_e)
+ENDPROC(clear_page_rep_stosb)
next reply other threads:[~2016-08-22 20:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-22 20:52 Alexey Dobriyan [this message]
2016-08-22 20:54 ` [PATCH] x86: branchless clear_page() 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 ` [PATCH 3/3] x86: branchless copy_page() Alexey Dobriyan
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=20160822205229.GA2638@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).