linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] RISC-V: Probe for misaligned access speed
@ 2023-08-18 19:41 Evan Green
  2023-08-18 19:41 ` [PATCH v4 1/2] RISC-V: Probe for unaligned " Evan Green
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Evan Green @ 2023-08-18 19:41 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Randy Dunlap, Heiko Stuebner, linux-doc, Björn Töpel,
	Conor Dooley, Guo Ren, Jisheng Zhang, linux-riscv, Samuel Holland,
	Sia Jee Heng, Marc Zyngier, Masahiro Yamada, Evan Green,
	Greentime Hu, Simon Hosie, Andrew Jones, Albert Ou,
	Alexandre Ghiti, Ley Foon Tan, Paul Walmsley, Anup Patel,
	Jonathan Corbet, linux-kernel, Xianting Tian, David Laight,
	Palmer Dabbelt, Andy Chiu


The current setting for the hwprobe bit indicating misaligned access
speed is controlled by a vendor-specific feature probe function. This is
essentially a per-SoC table we have to maintain on behalf of each vendor
going forward. Let's convert that instead to something we detect at
runtime.

We have two assembly routines at the heart of our probe: one that
does a bunch of word-sized accesses (without aligning its input buffer),
and the other that does byte accesses. If we can move a larger number of
bytes using misaligned word accesses than we can with the same amount of
time doing byte accesses, then we can declare misaligned accesses as
"fast".

The tradeoff of reducing this maintenance burden is boot time. We spend
4-6 jiffies per core doing this measurement (0-2 on jiffie edge
alignment, and 4 on measurement). The timing loop was based on
raid6_choose_gen(), which uses (16+1)*N jiffies (where N is the number
of algorithms). By taking only the fastest iteration out of all
attempts for use in the comparison, variance between runs is very low.
On my THead C906, it looks like this:

[    0.047563] cpu0: Ratio of byte access time to unaligned word access is 4.34, unaligned accesses are fast

Several others have chimed in with results on slow machines with the
older algorithm, which took all runs into account, including noise like
interrupts. Even with this variation, results indicate that in all cases
(fast, slow, and emulated) the measured numbers are nowhere near each
other (always multiple factors away).


Changes in v4:
 - Avoid the bare 64-bit divide which fails to link on 32-bit systems,
   use div_u64() (Palmer, buildrobot)

Changes in v3:
 - Fix documentation indentation (Conor)
 - Rename __copy_..._unaligned() to __riscv_copy_..._unaligned() (Conor)
 - Renamed c0,c1 to start_cycles, end_cycles (Conor)
 - Renamed j0,j1 to start_jiffies, now
 - Renamed check_unaligned_access0() to
   check_unaligned_access_boot_cpu() (Conor)

Changes in v2:
 - Explain more in the commit message (Conor)
 - Use a new algorithm that looks for the fastest run (David)
 - Clarify documentatin further (David and Conor)
 - Unify around a single word, "unaligned" (Conor)
 - Align asm operands, and other misc whitespace changes (Conor)

Evan Green (2):
  RISC-V: Probe for unaligned access speed
  RISC-V: alternative: Remove feature_probe_func

 Documentation/riscv/hwprobe.rst      |  11 ++-
 arch/riscv/errata/thead/errata.c     |   8 ---
 arch/riscv/include/asm/alternative.h |   5 --
 arch/riscv/include/asm/cpufeature.h  |   2 +
 arch/riscv/kernel/Makefile           |   1 +
 arch/riscv/kernel/alternative.c      |  19 -----
 arch/riscv/kernel/copy-unaligned.S   |  71 ++++++++++++++++++
 arch/riscv/kernel/copy-unaligned.h   |  13 ++++
 arch/riscv/kernel/cpufeature.c       | 104 +++++++++++++++++++++++++++
 arch/riscv/kernel/smpboot.c          |   3 +-
 10 files changed, 198 insertions(+), 39 deletions(-)
 create mode 100644 arch/riscv/kernel/copy-unaligned.S
 create mode 100644 arch/riscv/kernel/copy-unaligned.h

-- 
2.34.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-10-19  7:51 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18 19:41 [PATCH v4 0/2] RISC-V: Probe for misaligned access speed Evan Green
2023-08-18 19:41 ` [PATCH v4 1/2] RISC-V: Probe for unaligned " Evan Green
2023-09-13 12:36   ` Geert Uytterhoeven
2023-09-13 17:46     ` Evan Green
2023-09-14  7:32       ` Geert Uytterhoeven
2023-09-14  8:46         ` David Laight
2023-09-14 15:01           ` Evan Green
2023-09-14 15:55             ` David Laight
2023-09-14 16:36               ` Evan Green
2023-09-15  7:57                 ` David Laight
2023-09-15 16:47                   ` Evan Green
2023-10-19  6:37         ` Geert Uytterhoeven
2023-10-19  7:51           ` Lad, Prabhakar
2023-08-18 19:41 ` [PATCH v4 2/2] RISC-V: alternative: Remove feature_probe_func Evan Green
2023-08-30 20:30 ` [PATCH v4 0/2] RISC-V: Probe for misaligned access speed patchwork-bot+linux-riscv

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).