Skip to content

Commit 32d5f7a

Browse files
Merge patch series "RISC-V: hwprobe: Misaligned scalar perf fix and rename"
Evan Green <[email protected]> says: The CPUPERF0 hwprobe key was documented and identified in code as a bitmask value, but its contents were an enum. This produced incorrect behavior in conjunction with the WHICH_CPUS hwprobe flag. The first patch in this series fixes the bitmask/enum problem by creating a new hwprobe key that returns the same data, but is properly described as a value instead of a bitmask. The second patch renames the value definitions in preparation for adding vector misaligned access info. As of this version, the old defines are kept in place to maintain source compatibility with older userspace programs. * b4-shazam-merge: RISC-V: hwprobe: Add SCALAR to misaligned perf defines RISC-V: hwprobe: Add MISALIGNED_PERF key Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents e01d48c + 1f52888 commit 32d5f7a

File tree

6 files changed

+44
-29
lines changed

6 files changed

+44
-29
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,33 @@ The following keys are defined:
239239
ratified in commit 98918c844281 ("Merge pull request #1217 from
240240
riscv/zawrs") of riscv-isa-manual.
241241

242-
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance
243-
information about the selected set of processors.
242+
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
243+
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
244+
mistakenly classified as a bitmask rather than a value.
244245

245-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_UNKNOWN`: The performance of misaligned
246-
accesses is unknown.
246+
* :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`: An enum value describing
247+
the performance of misaligned scalar native word accesses on the selected set
248+
of processors.
247249

248-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_EMULATED`: Misaligned accesses are
249-
emulated via software, either in or below the kernel. These accesses are
250-
always extremely slow.
250+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN`: The performance of
251+
misaligned scalar accesses is unknown.
251252

252-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SLOW`: Misaligned accesses are slower
253-
than equivalent byte accesses. Misaligned accesses may be supported
254-
directly in hardware, or trapped and emulated by software.
253+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED`: Misaligned scalar
254+
accesses are emulated via software, either in or below the kernel. These
255+
accesses are always extremely slow.
255256

256-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_FAST`: Misaligned accesses are faster
257-
than equivalent byte accesses.
257+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW`: Misaligned scalar native
258+
word sized accesses are slower than the equivalent quantity of byte
259+
accesses. Misaligned accesses may be supported directly in hardware, or
260+
trapped and emulated by software.
258261

259-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_UNSUPPORTED`: Misaligned accesses are
260-
not supported at all and will generate a misaligned address fault.
262+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_FAST`: Misaligned scalar native
263+
word sized accesses are faster than the equivalent quantity of byte
264+
accesses.
265+
266+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED`: Misaligned scalar
267+
accesses are not supported at all and will generate a misaligned address
268+
fault.
261269

262270
* :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which
263271
represents the size of the Zicboz block in bytes.

arch/riscv/include/asm/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <uapi/asm/hwprobe.h>
1010

11-
#define RISCV_HWPROBE_MAX_KEY 8
11+
#define RISCV_HWPROBE_MAX_KEY 9
1212

1313
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1414
{

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ struct riscv_hwprobe {
8282
#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6
8383
#define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7
8484
#define RISCV_HWPROBE_KEY_TIME_CSR_FREQ 8
85+
#define RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF 9
86+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN 0
87+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED 1
88+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW 2
89+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_FAST 3
90+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED 4
8591
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
8692

8793
/* Flags */

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,26 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)
178178
perf = this_perf;
179179

180180
if (perf != this_perf) {
181-
perf = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
181+
perf = RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN;
182182
break;
183183
}
184184
}
185185

186186
if (perf == -1ULL)
187-
return RISCV_HWPROBE_MISALIGNED_UNKNOWN;
187+
return RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN;
188188

189189
return perf;
190190
}
191191
#else
192192
static u64 hwprobe_misaligned(const struct cpumask *cpus)
193193
{
194194
if (IS_ENABLED(CONFIG_RISCV_EFFICIENT_UNALIGNED_ACCESS))
195-
return RISCV_HWPROBE_MISALIGNED_FAST;
195+
return RISCV_HWPROBE_MISALIGNED_SCALAR_FAST;
196196

197197
if (IS_ENABLED(CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS) && unaligned_ctl_available())
198-
return RISCV_HWPROBE_MISALIGNED_EMULATED;
198+
return RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED;
199199

200-
return RISCV_HWPROBE_MISALIGNED_SLOW;
200+
return RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW;
201201
}
202202
#endif
203203

@@ -225,6 +225,7 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
225225
break;
226226

227227
case RISCV_HWPROBE_KEY_CPUPERF_0:
228+
case RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF:
228229
pair->value = hwprobe_misaligned(cpus);
229230
break;
230231

arch/riscv/kernel/traps_misaligned.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ int handle_misaligned_load(struct pt_regs *regs)
338338
perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, addr);
339339

340340
#ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS
341-
*this_cpu_ptr(&misaligned_access_speed) = RISCV_HWPROBE_MISALIGNED_EMULATED;
341+
*this_cpu_ptr(&misaligned_access_speed) = RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED;
342342
#endif
343343

344344
if (!unaligned_enabled)
@@ -532,13 +532,13 @@ static bool check_unaligned_access_emulated(int cpu)
532532
unsigned long tmp_var, tmp_val;
533533
bool misaligned_emu_detected;
534534

535-
*mas_ptr = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
535+
*mas_ptr = RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN;
536536

537537
__asm__ __volatile__ (
538538
" "REG_L" %[tmp], 1(%[ptr])\n"
539539
: [tmp] "=r" (tmp_val) : [ptr] "r" (&tmp_var) : "memory");
540540

541-
misaligned_emu_detected = (*mas_ptr == RISCV_HWPROBE_MISALIGNED_EMULATED);
541+
misaligned_emu_detected = (*mas_ptr == RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED);
542542
/*
543543
* If unaligned_ctl is already set, this means that we detected that all
544544
* CPUS uses emulated misaligned access at boot time. If that changed

arch/riscv/kernel/unaligned_access_speed.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static int check_unaligned_access(void *param)
3434
struct page *page = param;
3535
void *dst;
3636
void *src;
37-
long speed = RISCV_HWPROBE_MISALIGNED_SLOW;
37+
long speed = RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW;
3838

39-
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_UNKNOWN)
39+
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN)
4040
return 0;
4141

4242
/* Make an unaligned destination buffer. */
@@ -95,22 +95,22 @@ static int check_unaligned_access(void *param)
9595
}
9696

9797
if (word_cycles < byte_cycles)
98-
speed = RISCV_HWPROBE_MISALIGNED_FAST;
98+
speed = RISCV_HWPROBE_MISALIGNED_SCALAR_FAST;
9999

100100
ratio = div_u64((byte_cycles * 100), word_cycles);
101101
pr_info("cpu%d: Ratio of byte access time to unaligned word access is %d.%02d, unaligned accesses are %s\n",
102102
cpu,
103103
ratio / 100,
104104
ratio % 100,
105-
(speed == RISCV_HWPROBE_MISALIGNED_FAST) ? "fast" : "slow");
105+
(speed == RISCV_HWPROBE_MISALIGNED_SCALAR_FAST) ? "fast" : "slow");
106106

107107
per_cpu(misaligned_access_speed, cpu) = speed;
108108

109109
/*
110110
* Set the value of fast_misaligned_access of a CPU. These operations
111111
* are atomic to avoid race conditions.
112112
*/
113-
if (speed == RISCV_HWPROBE_MISALIGNED_FAST)
113+
if (speed == RISCV_HWPROBE_MISALIGNED_SCALAR_FAST)
114114
cpumask_set_cpu(cpu, &fast_misaligned_access);
115115
else
116116
cpumask_clear_cpu(cpu, &fast_misaligned_access);
@@ -188,7 +188,7 @@ static int riscv_online_cpu(unsigned int cpu)
188188
static struct page *buf;
189189

190190
/* We are already set since the last check */
191-
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_UNKNOWN)
191+
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN)
192192
goto exit;
193193

194194
buf = alloc_pages(GFP_KERNEL, MISALIGNED_BUFFER_ORDER);

0 commit comments

Comments
 (0)