| From: |
| Matteo Croce <mcroce-AT-linux.microsoft.com> |
| To: |
| linux-kernel-AT-vger.kernel.org, Nick Kossifidis <mick-AT-ics.forth.gr>, Guo Ren <guoren-AT-kernel.org>, Christoph Hellwig <hch-AT-infradead.org>, David Laight <David.Laight-AT-aculab.com>, Palmer Dabbelt <palmer-AT-dabbelt.com>, Emil Renner Berthing <kernel-AT-esmil.dk>, Drew Fustini <drew-AT-beagleboard.org> |
| Subject: |
| [PATCH v2 0/3] lib/string: optimized mem* functions |
| Date: |
| Fri, 02 Jul 2021 14:31:50 +0200 |
| Message-ID: |
| <20210702123153.14093-1-mcroce@linux.microsoft.com> |
| Cc: |
| linux-arch-AT-vger.kernel.org, Andrew Morton <akpm-AT-linux-foundation.org>, Nick Desaulniers <ndesaulniers-AT-google.com>, linux-riscv-AT-lists.infradead.org |
| Archive-link: |
| Article |
From: Matteo Croce <mcroce@microsoft.com>
Rewrite the generic mem{cpy,move,set} so that memory is accessed with
the widest size possible, but without doing unaligned accesses.
This was originally posted as C string functions for RISC-V[1], but as
there was no specific RISC-V code, it was proposed for the generic
lib/string.c implementation.
Tested on RISC-V and on x86_64 by undefining __HAVE_ARCH_MEM{CPY,SET,MOVE}
and HAVE_EFFICIENT_UNALIGNED_ACCESS.
These are the performances of memcpy() and memset() of a RISC-V machine
on a 32 mbyte buffer:
memcpy:
original aligned: 75 Mb/s
original unaligned: 75 Mb/s
new aligned: 114 Mb/s
new unaligned: 107 Mb/s
memset:
original aligned: 140 Mb/s
original unaligned: 140 Mb/s
new aligned: 241 Mb/s
new unaligned: 241 Mb/s
The size increase is negligible:
$ scripts/bloat-o-meter vmlinux.orig vmlinux
add/remove: 0/0 grow/shrink: 4/1 up/down: 427/-6 (421)
Function old new delta
memcpy 29 351 +322
memset 29 117 +88
strlcat 68 78 +10
strlcpy 50 57 +7
memmove 56 50 -6
Total: Before=8556964, After=8557385, chg +0.00%
These functions will be used for RISC-V initially.
[1] https://lore.kernel.org/linux-riscv/20210617152754.17960-...
Matteo Croce (3):
lib/string: optimized memcpy
lib/string: optimized memmove
lib/string: optimized memset
lib/string.c | 130 ++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 113 insertions(+), 17 deletions(-)
--
2.31.1