[PATCH] schbench: fix per-cpu spin lock
From: Chen Yu
Date: Mon Aug 14 2023 - 08:00:06 EST
On a system with 1 socket offline, the CPU ids might not
be continuous. The per_cpu_locks is allocated based on the
number of online CPUs but not accessed continuously:
CPU(s): 224
On-line CPU(s) list: 0-55,112-167
Off-line CPU(s) list: 56-111,168-223
The per_cpu_locks is allocated for 112 elements, but be
accessed beyond an index of 112. This could bring unexpected
deadlock during the test.
Fix this by allocating the per_cpu_locks by the number of
possible CPUs, although there could be some waste of space.
Signed-off-by: Chen Yu <yu.c.chen@xxxxxxxxx>
---
schbench.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/schbench.c b/schbench.c
index 937f1f2..3eaf1a4 100644
--- a/schbench.c
+++ b/schbench.c
@@ -1359,7 +1359,7 @@ int main(int ac, char **av)
matrix_size = sqrt(cache_footprint_kb * 1024 / 3 / sizeof(unsigned long));
- num_cpu_locks = get_nprocs();
+ num_cpu_locks = get_nprocs_conf();
per_cpu_locks = calloc(num_cpu_locks, sizeof(struct per_cpu_lock));
if (!per_cpu_locks) {
perror("unable to allocate memory for per cpu locks\n");
--
2.25.1
> -chris
>