From 6d5aa2b00d41ecdb6eb1355309737647e177e5e6 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 10 Feb 2021 17:54:07 +0100 Subject: [PATCH 2/3] oslat: Use cpuset size as upper bound To assign the threads to the correct CPU we need to use the cpuset size as upper bound for the loop and not the number of threads. Fixes: 85b0763dacd9 ("oslat: Use parse_cpumask() from rt-numa.h") Reported-by: Peter Xu Signed-off-by: Daniel Wagner Signed-off-by: John Kacur --- src/oslat/oslat.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c index 7826c277f26d..2fe550b3ee12 100644 --- a/src/oslat/oslat.c +++ b/src/oslat/oslat.c @@ -747,9 +747,12 @@ int main(int argc, char *argv[]) n_cores = numa_bitmask_weight(cpu_set); TEST(threads = calloc(1, n_cores * sizeof(threads[0]))); - for (i = 0; i < n_cores; ++i) - if (numa_bitmask_isbitset(cpu_set, i) && move_to_core(i) == 0) + for (i = 0; n_cores && i < cpu_set->size; i++) { + if (numa_bitmask_isbitset(cpu_set, i) && move_to_core(i) == 0) { threads[g.n_threads_total++].core_i = i; + n_cores--; + } + } if (numa_bitmask_isbitset(cpu_set, 0) && g.rtprio) printf("WARNING: Running SCHED_FIFO workload on CPU 0 may hang the thread\n"); -- 2.26.2