Skip to content

Commit 13684e9

Browse files
geertuakpm00
authored andcommitted
lib: dhry: fix unstable smp_processor_id(_) usage
When running the in-kernel Dhrystone benchmark with CONFIG_DEBUG_PREEMPT=y: BUG: using smp_processor_id() in preemptible [00000000] code: bash/938 Fix this by not using smp_processor_id() directly, but instead wrapping the whole benchmark inside a get_cpu()/put_cpu() pair. This makes sure the whole benchmark is run on the same CPU core, and the reported values are consistent. Link: https://lkml.kernel.org/r/b0d29932bb24ad82cea7f821e295c898e9657be0.1678890070.git.geert+renesas@glider.be Fixes: d5528cc ("lib: add Dhrystone benchmark test") Signed-off-by: Geert Uytterhoeven <[email protected]> Reported-by: Tobias Klausmann <[email protected]> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217179 Signed-off-by: Andrew Morton <[email protected]>
1 parent d2e44a5 commit 13684e9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/dhry_run.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ MODULE_PARM_DESC(iterations,
3131

3232
static void dhry_benchmark(void)
3333
{
34+
unsigned int cpu = get_cpu();
3435
int i, n;
3536

3637
if (iterations > 0) {
@@ -45,9 +46,10 @@ static void dhry_benchmark(void)
4546
}
4647

4748
report:
49+
put_cpu();
4850
if (n >= 0)
49-
pr_info("CPU%u: Dhrystones per Second: %d (%d DMIPS)\n",
50-
smp_processor_id(), n, n / DHRY_VAX);
51+
pr_info("CPU%u: Dhrystones per Second: %d (%d DMIPS)\n", cpu,
52+
n, n / DHRY_VAX);
5153
else if (n == -EAGAIN)
5254
pr_err("Please increase the number of iterations\n");
5355
else

0 commit comments

Comments
 (0)