Skip to contentSkip to conversation

mips: Bring over optimized memset() routine from Linux.

PATCH New Jason McMullan 4 participants 6 messages Jun 4, 2008 – Jul 7, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mips: Bring over optimized memset() routine from Linux.

This commit pulls over the memset() MIPS routine from Linux 2.6.26, which provides a 10x to 20x speedup over the generic byte-at-a-time routine. This is especially useful on platforms with manual ECC scrubbing, that require all of memory to be written at least once after a power cycle.

---
 include/asm-mips/string.h |    2 +-
 lib_mips/Makefile         |    2 +-
 lib_mips/memset.S         |  174 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+), 2 deletions(-)
 create mode 100644 lib_mips/memset.S
include/asm-mips/string.h +1 -1
index 579a591..0df1463 100644
@@ -27,7 +27,7 @@ extern int strcmp(__const__ char *__cs, __const__ char *__ct);
 #undef __HAVE_ARCH_STRNCMP
 extern int strncmp(__const__ char *__cs, __const__ char *__ct, __kernel_size_t __count);
 
-#undef __HAVE_ARCH_MEMSET
+#define __HAVE_ARCH_MEMSET
 extern void *memset(void *__s, int __c, __kernel_size_t __count);
 
 #undef __HAVE_ARCH_MEMCPY
lib_mips/Makefile +1 -1
index 8176437..9149039 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(ARCH).a
 
-SOBJS-y	+=
+SOBJS-y	+= memset.o
 
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
lib_mips/memset.S new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#1 lore raw

PATCH 1/1 mips: Bring over optimized memset() routine from Linux.

Hi Jason,

Quoted 11 lines · Jason McMullan

This commit pulls over the memset() MIPS routine from Linux 2.6.26, which provides a 10x to 20x speedup over the generic byte-at-a-time routine. This is especially useful on platforms with manual ECC scrubbing, that require all of memory to be written at least once after a power cycle.

---
 include/asm-mips/string.h |    2 +-
 lib_mips/Makefile         |    2 +-
 lib_mips/memset.S         |  174 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+), 2 deletions(-)
 create mode 100644 lib_mips/memset.S

IIRC, Linux's memset relies on AdEL/AdES exceptions. We have Status.EXL enabled, but don't have proper exception handlers, yet. So my question is does this code always works expectedly, or works with some alignment restriction?

And some nitpickings. See below.

Quoted 7 lines
lib_mips/memset.S new file +1 -0
new file mode 100644
index 0000000..f1c07d7
@@ -0,0 +1,174 @@
+/*

lib_mips/memset.S line 11

Quoted 10 lines
lib_mips/memset.S new file +10 -0
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1998, 1999, 2000 by Ralf Baechle
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ * Copyright (C) 2007  Maciej W. Rozycki
+ */
+#include <asm/asm.h>
+//#include <asm/asm-offsets.h>

Please remove unused #include. Even '#if 0'-ing is not allowed in U-Boot policy.

Quoted 39 lines
lib_mips/memset.S new file +39 -0
+#include <asm/regdef.h>
+
+#if LONGSIZE == 4
+#define LONG_S_L swl
+#define LONG_S_R swr
+#else
+#define LONG_S_L sdl
+#define LONG_S_R sdr
+#endif
+
+#define EX(insn,reg,addr,handler)			\
+9:	insn	reg, addr;				\
+	.section __ex_table,"a"; 			\
+	PTR	9b, handler; 				\
+	.previous
+
+	.macro	f_fill64 dst, offset, val, fixup
+	EX(LONG_S, \val, (\offset +  0 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  1 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  2 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  3 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  4 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  5 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  6 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  7 * LONGSIZE)(\dst), \fixup)
+#if LONGSIZE == 4
+	EX(LONG_S, \val, (\offset +  8 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset +  9 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset + 10 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset + 11 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset + 12 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset + 13 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset + 14 * LONGSIZE)(\dst), \fixup)
+	EX(LONG_S, \val, (\offset + 15 * LONGSIZE)(\dst), \fixup)
+#endif
+	.endm
+
+/*
+ * memset(void *s, int c, size_t n)

lib_mips/memset.S line 60

Quoted 10 lines
lib_mips/memset.S new file +10 -0
+ *
+ * a0: start of area to clear
+ * a1: char to fill with
+ * a2: size of area to clear
+ */
+	.set	noreorder
+	.align	5
+LEAF(memset)
+	beqz		a1, 1f
+	 move		v0, a0			/* result */
        ^
Quoted 5 lines
lib_mips/memset.S new file +5 -0
+	andi		a1, 0xff		/* spread fillword */
+	LONG_SLL		t1, a1, 8
+	or		a1, t1
+	LONG_SLL		t1, a1, 16
+#if LONGSIZE == 8

lib_mips/memset.S line 76

Quoted 10 lines
lib_mips/memset.S new file +10 -0
+	or		a1, t1
+	LONG_SLL		t1, a1, 32
+#endif
+	or		a1, t1
+1:
+
+FEXPORT(__bzero)
+	sltiu		t0, a2, LONGSIZE	/* very small region? */
+	bnez		t0, .Lsmall_memset
+	 andi		t0, a0, LONGMASK	/* aligned? */
        ^

[further part snipped]

Please fix wrong indentations with proper tabs. I know this is exactly the same as Linux's memset, but we prefer to fix it correctly in U-Boot.

[ I used to do like you did, but changed my mind. Now I think this is
better practice. Incoherent indentations with Linux is not a big deal IMO. Just diff -w option blows them away. ]

Thanks in advance,

Signature · 2 lines
Shinya Kuribayashi
NEC Electronics
#2 lore raw

PATCH 1/1 mips: Bring over optimized memset() routine from Linux.

Quoted 18 lines · Shinya Kuribayashi
Quoted 5 lines
lib_mips/memset.S new file +5 -0
+	andi		a1, 0xff		/* spread fillword */
+	LONG_SLL		t1, a1, 8
+	or		a1, t1
+	LONG_SLL		t1, a1, 16
+#if LONGSIZE == 8

lib_mips/memset.S line 76

Quoted 10 lines
lib_mips/memset.S new file +10 -0
+	or		a1, t1
+	LONG_SLL		t1, a1, 32
+#endif
+	or		a1, t1
+1:
+
+FEXPORT(__bzero)
+	sltiu		t0, a2, LONGSIZE	/* very small region? */
+	bnez		t0, .Lsmall_memset
+	 andi		t0, a0, LONGMASK	/* aligned? */
        ^
Quoted 4 lines

[further part snipped]

Please fix wrong indentations with proper tabs. I know this is exactly the same as Linux's memset, but we prefer to fix it correctly in U-Boot.

I found that above is an intended space to indicate that the instruction is in the delay slot. I think it's probably a good old convention in MIPS assembly programming, and would like to leave it as it is, IMHO.

Anyway, sorry for my ignorance and please ignore my comments on this.

Signature · 2 lines
Shinya Kuribayashi
NEC Electronics
#3 lore raw

PATCH 1/1 mips: Bring over optimized memset() routine from Linux.

Quoted 4 lines · In message <[email protected]> you wrote:

I found that above is an intended space to indicate that the instruction is in the delay slot. I think it's probably a good old convention in MIPS assembly programming, and would like to leave it as it is, IMHO.

Indeed. If it has a deeper meaning, this should be left as is.

Quoted 1 line

Anyway, sorry for my ignorance and please ignore my comments on this.

Thanks for the explanation - I think most of us were not aware of any such conventions. Speaking for me - I definitely was not.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Time is fluid ... like a river with currents, eddies, backwash.
	-- Spock, "The City on the Edge of Forever", stardate 3134.0
#4 lore raw

PATCH 1/1 mips: Bring over optimized memset() routine from Linux.

In reply to Jason McMullan
Quoted 11 lines · In message <[email protected]> you wrote:

This commit pulls over the memset() MIPS routine from Linux 2.6.26, which provides a 10x to 20x speedup over the generic byte-at-a-time routine. This is especially useful on platforms with manual ECC scrubbing, that require all of memory to be written at least once after a power cycle.

---
 include/asm-mips/string.h |    2 +-
 lib_mips/Makefile         |    2 +-
 lib_mips/memset.S         |  174 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+), 2 deletions(-)
 create mode 100644 lib_mips/memset.S

Shinya Kuribayashi asked some questions about your patch, which you did not answer (as far as I can tell).

Do you intend to comment on the questions and/or submit a cleaned up version of the patch?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"You can have my Unix system when you  pry  it  from  my  cold,  dead
fingers."                                                - Cal Keegan
#5 lore raw

PATCH 1/1 mips: Bring over optimized memset()routine from Linux.

Quoted 8 lines · Wolfgang Denk
Quoted 5 lines · In message <[email protected]> you wrote:

This commit pulls over the memset() MIPS routine from Linux 2.6.26, which provides a 10x to 20x speedup over the generic byte-at-a-time routine. This is especially useful on platforms with manual ECC scrubbing, that require all of memory to be written at least once after a power cycle.

Do you intend to comment on the questions and/or submit a cleaned up version of the patch?

Unfortunately, no follow-up patch is forthcoming.

I was able to use a spare DMA engine on our SOC to perform the memory zeroing, which eliminated the need for the enhanced memcopy() routine.

Also, I am not familiar with the intricacies of MIPS exception handling for alignment issues, so I was not able to come up with a good solution for Shinya Kuribayashi's alignment trap issue questions.

Please retract the patch.

Jason McMullan
MTS SW
System Firmware

NetApp

724.741.5011    Fax
724.741.5166    Direct
412.656.3519    Mobile

jason.mcmullan at netapp.com
www.netapp.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.denx.de/pipermail/u-boot/attachments/20080707/0141f089/attachment.pgp