From: "Fenghua Yu" <fenghua.yu@intel.com>
To: "Ingo Molnar" <mingo@elte.hu>,
"Thomas Gleixner" <tglx@linutronix.de>,
"H Peter Anvin" <hpa@zytor.com>,
"Asit K Mallick" <asit.k.mallick@intel.com>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Avi Kivity" <avi@redhat.com>,
"Arjan van de Ven" <arjan@infradead.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andi Kleen" <andi@firstfloor.org>
Cc: "linux-kernel" <linux-kernel@vger.kernel.org>,
"Fenghua Yu" <fenghua.yu@intel.com>
Subject: [PATCH 7/9] x86/lib/memcpy_64.S: Optimize memcpy by enhanced REP MOVSB/STOSB
Date: Tue, 17 May 2011 15:29:16 -0700 [thread overview]
Message-ID: <1305671358-14478-8-git-send-email-fenghua.yu@intel.com> (raw)
In-Reply-To: <1305671358-14478-1-git-send-email-fenghua.yu@intel.com>
From: Fenghua Yu <fenghua.yu@intel.com>
Support memcpy() with enhanced rep movsb. On processors supporting enhanced
rep movsb, the alternative memcpy() function using enhanced rep movsb overrides the original function and the fast string
function.
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
arch/x86/lib/memcpy_64.S | 45 ++++++++++++++++++++++++++++++++-------------
1 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
index 2a560bb..efbf2a0 100644
--- a/arch/x86/lib/memcpy_64.S
+++ b/arch/x86/lib/memcpy_64.S
@@ -4,6 +4,7 @@
#include <asm/cpufeature.h>
#include <asm/dwarf2.h>
+#include <asm/alternative-asm.h>
/*
* memcpy - Copy a memory block.
@@ -37,6 +38,23 @@
.Lmemcpy_e:
.previous
+/*
+ * memcpy_c_e() - enhanced fast string memcpy. This is faster and simpler than
+ * memcpy_c. Use memcpy_c_e when possible.
+ *
+ * This gets patched over the unrolled variant (below) via the
+ * alternative instructions framework:
+ */
+ .section .altinstr_replacement, "ax", @progbits
+.Lmemcpy_c_e:
+ movq %rdi, %rax
+
+ movl %edx, %ecx
+ rep movsb
+ ret
+.Lmemcpy_e_e:
+ .previous
+
ENTRY(__memcpy)
ENTRY(memcpy)
CFI_STARTPROC
@@ -171,21 +189,22 @@ ENDPROC(memcpy)
ENDPROC(__memcpy)
/*
- * Some CPUs run faster using the string copy instructions.
- * It is also a lot simpler. Use this when possible:
- */
-
- .section .altinstructions, "a"
- .align 8
- .quad memcpy
- .quad .Lmemcpy_c
- .word X86_FEATURE_REP_GOOD
-
- /*
+ * Some CPUs are adding enhanced REP MOVSB/STOSB feature
+ * If the feature is supported, memcpy_c_e() is the first choice.
+ * If enhanced rep movsb copy is not available, use fast string copy
+ * memcpy_c() when possible. This is faster and code is simpler than
+ * original memcpy().
+ * Otherwise, original memcpy() is used.
+ * In .altinstructions section, ERMS feature is placed after REG_GOOD
+ * feature to implement the right patch order.
+ *
* Replace only beginning, memcpy is used to apply alternatives,
* so it is silly to overwrite itself with nops - reboot is the
* only outcome...
*/
- .byte .Lmemcpy_e - .Lmemcpy_c
- .byte .Lmemcpy_e - .Lmemcpy_c
+ .section .altinstructions, "a"
+ altinstruction_entry memcpy,.Lmemcpy_c,X86_FEATURE_REP_GOOD,\
+ .Lmemcpy_e-.Lmemcpy_c,.Lmemcpy_e-.Lmemcpy_c
+ altinstruction_entry memcpy,.Lmemcpy_c_e,X86_FEATURE_ERMS, \
+ .Lmemcpy_e_e-.Lmemcpy_c_e,.Lmemcpy_e_e-.Lmemcpy_c_e
.previous
--
1.7.2
next prev parent reply other threads:[~2011-05-17 22:43 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-17 22:29 [PATCH 0/9] Optimize string operations by enhanced REP MOVSB/STOSB Fenghua Yu
2011-05-17 22:29 ` [PATCH 1/9] x86, cpu: Enable enhanced REP MOVSB/STOSB feature Fenghua Yu
2011-05-17 23:13 ` [tip:x86/cpufeature] x86, cpufeature: Add CPU feature bit for enhanced REP MOVSB/STOSB tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 2/9] x86/kernel/cpu/intel.c: Initialize Enhanced REP MOVSB/STOSBenhanced Fenghua Yu
2011-05-18 2:46 ` Andi Kleen
2011-05-18 3:47 ` H. Peter Anvin
2011-05-18 20:40 ` [tip:perf/core] x86, mem, intel: Initialize Enhanced REP MOVSB/STOSB tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 3/9] x86/kernel/alternative.c: Add comment for applying alternatives order Fenghua Yu
2011-05-18 20:40 ` [tip:perf/core] x86, alternative, doc: " tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 4/9] x86, alternative-asm.h: Add altinstruction_entry macro Fenghua Yu
2011-05-18 20:41 ` [tip:perf/core] x86, alternative: " tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 5/9] x86/lib/clear_page_64.S: Support clear_page() with enhanced REP MOVSB/STOSB Fenghua Yu
2011-05-18 20:41 ` [tip:perf/core] x86, mem: clear_page_64.S: " tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 6/9] x86/lib/copy_user_64.S: Support copy_to_user/copy_from_user by " Fenghua Yu
2011-05-18 20:42 ` [tip:perf/core] x86, mem: copy_user_64.S: Support copy_to/from_user " tip-bot for Fenghua Yu
2011-05-17 22:29 ` Fenghua Yu [this message]
2011-05-18 6:35 ` [PATCH 7/9] x86/lib/memcpy_64.S: Optimize memcpy " Ingo Molnar
2011-05-18 19:04 ` Yu, Fenghua
2011-05-18 20:42 ` [tip:perf/core] x86, mem: memcpy_64.S: " tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 8/9] x86/lib/memmove_64.S: Optimize memmove " Fenghua Yu
2011-05-18 20:43 ` [tip:perf/core] x86, mem: memmove_64.S: " tip-bot for Fenghua Yu
2011-05-17 22:29 ` [PATCH 9/9] x86/lib/memset_64.S: Optimize memset " Fenghua Yu
2011-05-18 2:57 ` Andi Kleen
2011-05-18 3:09 ` Yu, Fenghua
2011-05-18 4:05 ` Andi Kleen
2011-05-18 18:33 ` Yu, Fenghua
2011-05-18 18:39 ` Andi Kleen
2011-05-18 18:47 ` Ingo Molnar
2011-05-18 18:49 ` Yu, Fenghua
2011-05-18 20:43 ` [tip:perf/core] x86, mem: memset_64.S: " tip-bot for Fenghua Yu
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=1305671358-14478-8-git-send-email-fenghua.yu@intel.com \
--to=fenghua.yu@intel.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=arjan@infradead.org \
--cc=asit.k.mallick@intel.com \
--cc=avi@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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).