Skip to contentSkip to conversation

lib/string.c: add multibyte memset functions

PATCH New [email protected] 1 participant 1 message Sep 8, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 53/126 lib/string.c: add multibyte memset functions

From: Matthew Wilcox <[email protected]>
Subject: lib/string.c: add multibyte memset functions

Patch series "Multibyte memset variations", v4.

A relatively common idiom we're missing is a function to fill an area of memory with a pattern which is larger than a single byte. I first noticed this with a zram patch which wanted to fill a page with an 'unsigned long' value. There turn out to be quite a few places in the kernel which can benefit from using an optimised function rather than a loop; sometimes text size, sometimes speed, and sometimes both. The optimised PowerPC version (not included here) improves performance by about 30% on POWER8 on just the raw memset_l().

Most of the extra lines of code come from the three testcases I added.

This patch (of 8):

memset16(), memset32() and memset64() are like memset(), but allow the caller to fill the destination with a value larger than a single byte. memset_l() and memset_p() allow the caller to use unsigned long and pointer values respectively.

Cc "H. Peter Anvin" <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc David Miller <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Russell King <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Thomas Gleixner <[email protected]>

---

 include/linux/string.h |   30 +++++++++++++++++
 lib/string.c           |   66 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
include/linux/string.h renamed from include/linux/string.h~add-multibyte-memset-functions +30 -0
diff -puN include/linux/string.h~add-multibyte-memset-functions include/linux/string.h
@@ -99,6 +99,36 @@ extern __kernel_size_t strcspn(const cha
 #ifndef __HAVE_ARCH_MEMSET
 extern void * memset(void *,int,__kernel_size_t);
 #endif
+
+#ifndef __HAVE_ARCH_MEMSET16
+extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
+#endif
+
+#ifndef __HAVE_ARCH_MEMSET32
+extern void *memset32(uint32_t *, uint32_t, __kernel_size_t);
+#endif
+
+#ifndef __HAVE_ARCH_MEMSET64
+extern void *memset64(uint64_t *, uint64_t, __kernel_size_t);
+#endif
+
+static inline void *memset_l(unsigned long *p, unsigned long v,
+		__kernel_size_t n)
+{
+	if (BITS_PER_LONG == 32)
+		return memset32((uint32_t *)p, v, n);
+	else
+		return memset64((uint64_t *)p, v, n);
+}
+
+static inline void *memset_p(void **p, void *v, __kernel_size_t n)
+{
+	if (BITS_PER_LONG == 32)
+		return memset32((uint32_t *)p, (uintptr_t)v, n);
+	else
+		return memset64((uint64_t *)p, (uintptr_t)v, n);
+}
+
 #ifndef __HAVE_ARCH_MEMCPY
 extern void * memcpy(void *,const void *,__kernel_size_t);
 #endif
lib/string.c renamed from lib/string.c~add-multibyte-memset-functions +66 -0

72 lines not on this page · raw message

_