riscv: Use CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS to set misaligned access speed
cover riscv: Use CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS to set misaligned access speed
If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is enabled, no time needs to be spent in the misaligned access speed probe. Disable the probe in this case and set respective uses to "fast" misaligned accesses. On riscv, this config is selected if RISCV_EFFICIENT_UNALIGNED_ACCESS is selected, which is dependent on NONPORTABLE.
---
Charlie Jenkins (2):
riscv: lib: Introduce has_fast_misaligned_access function
riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
arch/riscv/include/asm/cpufeature.h | 13 +++++++++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ arch/riscv/lib/csum.c | 5 +---- 5 files changed, 26 insertions(+), 4 deletions(-)
---
base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d
change-id: 20240131-disable_misaligned_probe_config-043aea375f93
Signature · 1 line
- Charlie
PATCH 1/2 riscv: lib: Introduce has_fast_misaligned_access function
Create has_fast_misaligned_access to avoid needing to explicitly check the fast_misaligned_access_speed_key static key.
--- arch/riscv/include/asm/cpufeature.h | 6 ++++++ arch/riscv/lib/csum.c | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-)
arch/riscv/include/asm/cpufeature.h +6 -0
@@ -28,7 +28,9 @@ struct riscv_isainfo { DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_PER_CPU (long, misaligned_access_speed); +#endif /* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS ];
@@ -137,4 +139,8 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsiDECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return static_branch_likely (&fast_misaligned_access_speed_key); +}#endif
arch/riscv/lib/csum.c +1 -4
@@ -318,10 +318,7 @@ unsigned int do_csum(const unsigned char *buff, int len)* branches. The largest chunk of overlap was delegated into the * do_csum_common function. */ -if (static_branch_likely (&fast_misaligned_access_speed_key)) -return do_csum_no_alignment (buff, len); - -if (((unsigned long )buff &OFFSET_MASK ) ==0 ) +if (has_fast_misaligned_accesses () || (((unsigned long )buff &OFFSET_MASK ) ==0b101 ))return do_csum_no_alignment (buff, len);return do_csum_with_alignment (buff, len);
Signature · 1 line
2.43.0
PATCH 2/2 riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
In reply to Charlie JenkinsWhen CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is selected, the cpus can be set to have fast misaligned access without needing to probe.
--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)
arch/riscv/include/asm/cpufeature.h +7 -0
@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif
arch/riscv/kernel/cpufeature.c +4 -0
@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word
@@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();
@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {
arch/riscv/kernel/sys_hwprobe.c +4 -0
@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;
@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,
arch/riscv/kernel/traps_misaligned.c +4 -0
@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr); +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif if (!unaligned_enabled)return -1 ;
@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);
@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif bool unaligned_ctl_available (void ) {
Signature · 1 line
2.43.0
Re: [PATCH 2/2] riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Quoted 59 lines · Charlie Jenkins
When
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis selected, the cpus can be set to have fast misaligned access without needing to probe.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)arch/riscv/include/asm/cpufeature.h +7
-0@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif arch/riscv/kernel/cpufeature.c +3
-0@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word @@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();
arch/riscv/kernel/cpufeature.c static int check_unaligned_access_all_cpus(void) · line 955
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {
Hi Charlie,
Generally, having so much ifdef in various pieces of code is probably not a good idea.
AFAICT, if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is enabled, the whole misaligned access speed checking could be opt-out. which means that probably everything related to misaligned accesses should be moved in it's own file build it only for CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=n only.
Quoted 26 lines
arch/riscv/kernel/sys_hwprobe.c +4
-0@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,
arch/riscv/kernel/traps_misaligned.c int handle_misaligned_load(struct pt_regs *regs) · line 418
Quoted 6 lines
arch/riscv/kernel/traps_misaligned.c +2
-0@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr); +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif
I think that rather using ifdefery inside this file (traps_misaligned.c)
it can be totally opt-out in case we haveCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS since it implies that misaligned accesses are not emulated (at least that is my understanding).
Thanks,
Clément
Quoted 20 lines
arch/riscv/kernel/traps_misaligned.c +2
-0if (!unaligned_enabled)return -1 ;@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif bool unaligned_ctl_available (void ) {
Re: [PATCH 2/2] riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Quoted 72 lines · Clément Léger
Quoted 59 lines · Charlie Jenkins
When
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis selected, the cpus can be set to have fast misaligned access without needing to probe.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)arch/riscv/include/asm/cpufeature.h +7
-0@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif arch/riscv/kernel/cpufeature.c +3
-0@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word @@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();arch/riscv/kernel/cpufeature.c static int check_unaligned_access_all_cpus(void) · line 955
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {Hi Charlie,
Quoted 8 lines
Generally, having so much ifdef in various pieces of code is probably not a good idea.
AFAICT, if
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis enabled, the whole misaligned access speed checking could be opt-out. which means that probably everything related to misaligned accesses should be moved in it's own file build it only forCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=nonly.
I will look into doing something more clever here! I agree it is not very nice to have so many ifdefs scattered.
Quoted 30 lines
Quoted 30 lines
arch/riscv/kernel/sys_hwprobe.c +4
-0@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,arch/riscv/kernel/traps_misaligned.c +0
-0@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr);
Quoted 9 lines
arch/riscv/kernel/traps_misaligned.c int handle_misaligned_load(struct pt_regs *regs) · line 418
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +2
-0+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif I think that rather using ifdefery inside this file (
traps_misaligned.c)
it can be totally opt-out in case we haveCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSsince it implies that misaligned accesses are not emulated (at least that is my understanding).
That's a great idea, I believe that is correct.
- Charlie
Quoted 28 lines
Thanks,
Clément
Quoted 20 lines
arch/riscv/kernel/traps_misaligned.c +2
-0if (!unaligned_enabled)return -1 ;@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif bool unaligned_ctl_available (void ) {
Re: [PATCH 2/2] riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
I am a little confused here - I was testing with 6.8-rc1 and it didn't seem to have the behavior of performing the probe (The probe kills boot performance in my application and I've had to patch out the probe in mid-6.x kernels).
Did something get reverted to bring back the probe even when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=Y between rc1 and trunk? Or am I misremembering/accidentally patched?
Quoted 163 lines · Charlie Jenkins
Quoted 72 lines · Clément Léger
Quoted 59 lines · Charlie Jenkins
When
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis selected, the cpus can be set to have fast misaligned access without needing to probe.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)arch/riscv/include/asm/cpufeature.h +7
-0@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif arch/riscv/kernel/cpufeature.c +3
-0@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word @@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();arch/riscv/kernel/cpufeature.c static int check_unaligned_access_all_cpus(void) · line 955
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {Hi Charlie,
Quoted 8 lines
Generally, having so much ifdef in various pieces of code is probably not a good idea.
AFAICT, if
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis enabled, the whole misaligned access speed checking could be opt-out. which means that probably everything related to misaligned accesses should be moved in it's own file build it only forCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=nonly.I will look into doing something more clever here! I agree it is not very nice to have so many ifdefs scattered.
Quoted 30 lines
Quoted 30 lines
arch/riscv/kernel/sys_hwprobe.c +4
-0@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,arch/riscv/kernel/traps_misaligned.c +0
-0@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr);Quoted 9 lines
arch/riscv/kernel/traps_misaligned.c int handle_misaligned_load(struct pt_regs *regs) · line 418
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +2
-0+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif I think that rather using ifdefery inside this file (
traps_misaligned.c)
it can be totally opt-out in case we haveCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSsince it implies that misaligned accesses are not emulated (at least that is my understanding).That's a great idea, I believe that is correct.
- Charlie
Quoted 22 lines
Thanks,
Clément
Quoted 17 lines
arch/riscv/kernel/traps_misaligned.c +2
-0if (!unaligned_enabled)return -1 ;@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif Quoted 6 lines
arch/riscv/kernel/traps_misaligned.c void unaligned_emulation_finish(void) · line 649
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +0
-0bool unaligned_ctl_available (void ) {_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH 2/2] riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Quoted 8 lines · Charles Lohr
I am a little confused here - I was testing with 6.8-rc1 and it didn't seem to have the behavior of performing the probe (The probe kills boot performance in my application and I've had to patch out the probe in mid-6.x kernels).
Did something get reverted to bring back the probe even when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=Ybetween rc1 and trunk? Or am I misremembering/accidentally patched?
After pulling a clean version of 6.8-rc1 and setting CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS I still see the probe happen. Before sending this I looked for a patch that disabled the probe but was unable to find one, if there exists a patch can you point me to it?
- Charlie
Quoted 165 lines · Charlie Jenkins
Quoted 163 lines · Clément Léger
Quoted 72 lines · Charlie Jenkins
Quoted 59 lines
When
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis selected, the cpus can be set to have fast misaligned access without needing to probe.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)arch/riscv/include/asm/cpufeature.h +7
-0@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif arch/riscv/kernel/cpufeature.c +3
-0@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word @@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();arch/riscv/kernel/cpufeature.c static int check_unaligned_access_all_cpus(void) · line 955
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {Hi Charlie,
Quoted 8 lines
Generally, having so much ifdef in various pieces of code is probably not a good idea.
AFAICT, if
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis enabled, the whole misaligned access speed checking could be opt-out. which means that probably everything related to misaligned accesses should be moved in it's own file build it only forCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=nonly.I will look into doing something more clever here! I agree it is not very nice to have so many ifdefs scattered.
Quoted 30 lines
Quoted 30 lines
arch/riscv/kernel/sys_hwprobe.c +4
-0@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,arch/riscv/kernel/traps_misaligned.c +0
-0@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr);Quoted 9 lines
arch/riscv/kernel/traps_misaligned.c int handle_misaligned_load(struct pt_regs *regs) · line 418
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +2
-0+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif I think that rather using ifdefery inside this file (
traps_misaligned.c)
it can be totally opt-out in case we haveCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSsince it implies that misaligned accesses are not emulated (at least that is my understanding).That's a great idea, I believe that is correct.
- Charlie
Quoted 22 lines
Thanks,
Clément
Quoted 17 lines
arch/riscv/kernel/traps_misaligned.c +2
-0if (!unaligned_enabled)return -1 ;@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif Quoted 6 lines
arch/riscv/kernel/traps_misaligned.c void unaligned_emulation_finish(void) · line 649
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +0
-0bool unaligned_ctl_available (void ) {_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH 2/2] riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
I am very sorry for wasting your time - I did have it patched out in the build system here. I can't wait for this feature to land, so I can enjoy faster boot times without a patch.
Charles
Quoted 183 lines · Charlie Jenkins
Quoted 8 lines · Charles Lohr
I am a little confused here - I was testing with 6.8-rc1 and it didn't seem to have the behavior of performing the probe (The probe kills boot performance in my application and I've had to patch out the probe in mid-6.x kernels).
Did something get reverted to bring back the probe even when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=Ybetween rc1 and trunk? Or am I misremembering/accidentally patched?After pulling a clean version of 6.8-rc1 and setting
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSI still see the probe happen. Before sending this I looked for a patch that disabled the probe but was unable to find one, if there exists a patch can you point me to it?- Charlie
Quoted 165 lines · Charlie Jenkins
Quoted 163 lines · Clément Léger
Quoted 72 lines · Charlie Jenkins
Quoted 59 lines
When
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis selected, the cpus can be set to have fast misaligned access without needing to probe.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)arch/riscv/include/asm/cpufeature.h +7
-0@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif arch/riscv/kernel/cpufeature.c +3
-0@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word @@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();arch/riscv/kernel/cpufeature.c static int check_unaligned_access_all_cpus(void) · line 955
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {Hi Charlie,
Quoted 8 lines
Generally, having so much ifdef in various pieces of code is probably not a good idea.
AFAICT, if
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis enabled, the whole misaligned access speed checking could be opt-out. which means that probably everything related to misaligned accesses should be moved in it's own file build it only forCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=nonly.I will look into doing something more clever here! I agree it is not very nice to have so many ifdefs scattered.
Quoted 30 lines
Quoted 30 lines
arch/riscv/kernel/sys_hwprobe.c +4
-0@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,arch/riscv/kernel/traps_misaligned.c +0
-0@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr);Quoted 9 lines
arch/riscv/kernel/traps_misaligned.c int handle_misaligned_load(struct pt_regs *regs) · line 418
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +2
-0+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif I think that rather using ifdefery inside this file (
traps_misaligned.c)
it can be totally opt-out in case we haveCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSsince it implies that misaligned accesses are not emulated (at least that is my understanding).That's a great idea, I believe that is correct.
- Charlie
Quoted 22 lines
Thanks,
Clément
Quoted 17 lines
arch/riscv/kernel/traps_misaligned.c +2
-0if (!unaligned_enabled)return -1 ;@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif Quoted 6 lines
arch/riscv/kernel/traps_misaligned.c void unaligned_emulation_finish(void) · line 649
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +0
-0bool unaligned_ctl_available (void ) {_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH 2/2] riscv: Disable misaligned access probe when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Quoted 5 lines · Charles Lohr
I am very sorry for wasting your time - I did have it patched out in the build system here. I can't wait for this feature to land, so I can enjoy faster boot times without a patch.
Charles
No worries!
- Charlie
Quoted 185 lines · Charlie Jenkins
Quoted 183 lines · Charles Lohr
Quoted 8 lines
I am a little confused here - I was testing with 6.8-rc1 and it didn't seem to have the behavior of performing the probe (The probe kills boot performance in my application and I've had to patch out the probe in mid-6.x kernels).
Did something get reverted to bring back the probe even when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=Ybetween rc1 and trunk? Or am I misremembering/accidentally patched?After pulling a clean version of 6.8-rc1 and setting
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSI still see the probe happen. Before sending this I looked for a patch that disabled the probe but was unable to find one, if there exists a patch can you point me to it?- Charlie
Quoted 165 lines · Charlie Jenkins
Quoted 163 lines · Clément Léger
Quoted 72 lines · Charlie Jenkins
Quoted 59 lines
When
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis selected, the cpus can be set to have fast misaligned access without needing to probe.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/cpufeature.h | 7 +++++++ arch/riscv/kernel/cpufeature.c | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 4 ++++ arch/riscv/kernel/traps_misaligned.c | 4 ++++ 4 files changed, 19 insertions(+)arch/riscv/include/asm/cpufeature.h +7
-0@@ -137,10 +137,17 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsireturn __riscv_isa_extension_available (hart_isa[cpu].isa, ext); } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); static __always_inline bool has_fast_misaligned_accesses(void) {return static_branch_likely (&fast_misaligned_access_speed_key); } +#else +static __always_inline bool has_fast_misaligned_accesses(void) +{ +return true; +} +#endif #endif arch/riscv/kernel/cpufeature.c +3
-0@@ -43,10 +43,12 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);static cpumask_t fast_misaligned_access; +#endif /** * riscv_isa_extension_base() - Get base extension word @@ -706,6 +708,7 @@ unsigned long riscv_get_elf_hwcap(void)return hwcap; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS static int check_unaligned_access (void *param) {int cpu =smp_processor_id ();arch/riscv/kernel/cpufeature.c static int check_unaligned_access_all_cpus(void) · line 955
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -946,6 +949,7 @@ static int check_unaligned_access_all_cpus(void) }arch_initcall (check_unaligned_access_all_cpus); +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ void riscv_user_isa_enable (void ) {Hi Charlie,
Quoted 8 lines
Generally, having so much ifdef in various pieces of code is probably not a good idea.
AFAICT, if
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSis enabled, the whole misaligned access speed checking could be opt-out. which means that probably everything related to misaligned accesses should be moved in it's own file build it only forCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=nonly.I will look into doing something more clever here! I agree it is not very nice to have so many ifdefs scattered.
Quoted 30 lines
Quoted 30 lines
arch/riscv/kernel/sys_hwprobe.c +4
-0@@ -149,6 +149,7 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext)static u64 hwprobe_misaligned (const struct cpumask *cpus) { +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS int cpu;u64 perf =-1ULL ;@@ -168,6 +169,9 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)return RISCV_HWPROBE_MISALIGNED_UNKNOWN ;return perf; +#else +return RISCV_HWPROBE_MISALIGNED_FAST ; +#endif } static void hwprobe_one_pair(struct riscv_hwprobe *pair,arch/riscv/kernel/traps_misaligned.c +0
-0@@ -413,7 +413,9 @@ int handle_misaligned_load(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_ALIGNMENT_FAULTS ,1 , regs, addr);Quoted 9 lines
arch/riscv/kernel/traps_misaligned.c int handle_misaligned_load(struct pt_regs *regs) · line 418
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +2
-0+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS *this_cpu_ptr (&misaligned_access_speed) =RISCV_HWPROBE_MISALIGNED_EMULATED ; +#endif I think that rather using ifdefery inside this file (
traps_misaligned.c)
it can be totally opt-out in case we haveCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSsince it implies that misaligned accesses are not emulated (at least that is my understanding).That's a great idea, I believe that is correct.
- Charlie
Quoted 22 lines
Thanks,
Clément
Quoted 17 lines
arch/riscv/kernel/traps_misaligned.c +2
-0if (!unaligned_enabled)return -1 ;@@ -596,6 +598,7 @@ int handle_misaligned_store(struct pt_regs *regs)return 0 ; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS bool check_unaligned_access_emulated (int cpu) {long *mas_ptr =per_cpu_ptr (&misaligned_access_speed, cpu);@@ -640,6 +643,7 @@ void unaligned_emulation_finish(void) } unaligned_ctl = true; } +#endif Quoted 6 lines
arch/riscv/kernel/traps_misaligned.c void unaligned_emulation_finish(void) · line 649
Quoted 3 lines
arch/riscv/kernel/traps_misaligned.c +0
-0bool unaligned_ctl_available (void ) {_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv