[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEUhbmXPAEjozYuoQpATzjS4E6Yo2eRpF6DJzxO8Cumdm57J3A@mail.gmail.com>
Date: Thu, 13 May 2021 16:13:53 +0800
From: Bin Meng <bmeng.cn@...il.com>
To: Gary Guo <gary@...yguo.net>
Cc: Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Nick Hu <nickhu@...estech.com>,
Nylon Chen <nylon7@...estech.com>,
linux-riscv <linux-riscv@...ts.infradead.org>,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] riscv: fix memmove and optimise memcpy when misalign
On Wed, Feb 17, 2021 at 7:00 AM Gary Guo <gary@...yguo.net> wrote:
>
> 04091d6 introduces an assembly version of memmove but
> it does take misalignment into account (it checks if
> length is a multiple of machine word size but pointers
> need also be aligned). As a result it will generate
> misaligned load/store for the majority of cases and causes
> significant performance regression on hardware that traps
> misaligned load/store and emulate them using firmware.
>
> The current behaviour of memcpy is that it checks if both
> src and dest pointers are co-aligned (aka congruent
> modular SZ_REG). If aligned, it will copy data word-by-word
> after first aligning pointers to word boundary. If src
> and dst are not co-aligned, however, byte-wise copy will
> be performed.
>
> This patch fixes the memmove and optimises memcpy for
> misaligned cases. It will first align destination pointer
> to word-boundary regardless whether src and dest are
> co-aligned or not. If they indeed are, then wordwise copy
> is performed. If they are not co-aligned, then it will
> load two adjacent words from src and use shifts to assemble
> a full machine word. Some additional assembly level
> micro-optimisation is also performed to ensure more
> instructions can be compressed (e.g. prefer a0 to t6).
>
> In my testing this speeds up memcpy 4~5x when src and dest
> are not co-aligned (which is quite common in networking),
> and speeds up memmove 1000+x by avoiding trapping to firmware.
>
> Signed-off-by: Gary Guo <gary@...yguo.net>
> ---
> arch/riscv/lib/memcpy.S | 223 ++++++++++++++++++++++++---------------
> arch/riscv/lib/memmove.S | 176 ++++++++++++++++++++----------
> 2 files changed, 257 insertions(+), 142 deletions(-)
>
Looks this patch remains unapplied.
This patch fixed an booting failure of U-Boot SPL on SiFive Unleashed
board, which was built from the latest U-Boot sources that has taken
the assembly version of mem* from the Linux kernel recently.
The exact load misalignment happens in the original memmove()
implementation that it does not handle the alignment correctly. With
this patch, the U-Boot SPL boots again.
Tested-by: Bin Meng <bmeng.cn@...il.com>
Regards,
Bin
Powered by blists - more mailing lists