-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge patch series "RISC-V: Probe for misaligned access speed"
Evan Green <evan@rivosinc.com> says: 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). * b4-shazam-merge: RISC-V: alternative: Remove feature_probe_func RISC-V: Probe for unaligned access speed Link: https://lore.kernel.org/r/20230818194136.4084400-1-evan@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
- Loading branch information
Showing
10 changed files
with
198 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* Copyright (C) 2023 Rivos Inc. */ | ||
|
||
#include <linux/linkage.h> | ||
#include <asm/asm.h> | ||
|
||
.text | ||
|
||
/* void __riscv_copy_words_unaligned(void *, const void *, size_t) */ | ||
/* Performs a memcpy without aligning buffers, using word loads and stores. */ | ||
/* Note: The size is truncated to a multiple of 8 * SZREG */ | ||
ENTRY(__riscv_copy_words_unaligned) | ||
andi a4, a2, ~((8*SZREG)-1) | ||
beqz a4, 2f | ||
add a3, a1, a4 | ||
1: | ||
REG_L a4, 0(a1) | ||
REG_L a5, SZREG(a1) | ||
REG_L a6, 2*SZREG(a1) | ||
REG_L a7, 3*SZREG(a1) | ||
REG_L t0, 4*SZREG(a1) | ||
REG_L t1, 5*SZREG(a1) | ||
REG_L t2, 6*SZREG(a1) | ||
REG_L t3, 7*SZREG(a1) | ||
REG_S a4, 0(a0) | ||
REG_S a5, SZREG(a0) | ||
REG_S a6, 2*SZREG(a0) | ||
REG_S a7, 3*SZREG(a0) | ||
REG_S t0, 4*SZREG(a0) | ||
REG_S t1, 5*SZREG(a0) | ||
REG_S t2, 6*SZREG(a0) | ||
REG_S t3, 7*SZREG(a0) | ||
addi a0, a0, 8*SZREG | ||
addi a1, a1, 8*SZREG | ||
bltu a1, a3, 1b | ||
|
||
2: | ||
ret | ||
END(__riscv_copy_words_unaligned) | ||
|
||
/* void __riscv_copy_bytes_unaligned(void *, const void *, size_t) */ | ||
/* Performs a memcpy without aligning buffers, using only byte accesses. */ | ||
/* Note: The size is truncated to a multiple of 8 */ | ||
ENTRY(__riscv_copy_bytes_unaligned) | ||
andi a4, a2, ~(8-1) | ||
beqz a4, 2f | ||
add a3, a1, a4 | ||
1: | ||
lb a4, 0(a1) | ||
lb a5, 1(a1) | ||
lb a6, 2(a1) | ||
lb a7, 3(a1) | ||
lb t0, 4(a1) | ||
lb t1, 5(a1) | ||
lb t2, 6(a1) | ||
lb t3, 7(a1) | ||
sb a4, 0(a0) | ||
sb a5, 1(a0) | ||
sb a6, 2(a0) | ||
sb a7, 3(a0) | ||
sb t0, 4(a0) | ||
sb t1, 5(a0) | ||
sb t2, 6(a0) | ||
sb t3, 7(a0) | ||
addi a0, a0, 8 | ||
addi a1, a1, 8 | ||
bltu a1, a3, 1b | ||
|
||
2: | ||
ret | ||
END(__riscv_copy_bytes_unaligned) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (C) 2023 Rivos, Inc. | ||
*/ | ||
#ifndef __RISCV_KERNEL_COPY_UNALIGNED_H | ||
#define __RISCV_KERNEL_COPY_UNALIGNED_H | ||
|
||
#include <linux/types.h> | ||
|
||
void __riscv_copy_words_unaligned(void *dst, const void *src, size_t size); | ||
void __riscv_copy_bytes_unaligned(void *dst, const void *src, size_t size); | ||
|
||
#endif /* __RISCV_KERNEL_COPY_UNALIGNED_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters