tools/perf: Fix perf bench futex to enable the run when some CPU's are offline
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 7 Jun 2024 04:43:52 +0000 (10:13 +0530)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 14 Jun 2024 04:26:58 +0000 (21:26 -0700)
Perf bench futex fails as below when attempted to run on
on a powerpc system:

 ./perf bench futex all
 Running futex/hash benchmark...
Run summary [PID 626307]: 80 threads, each operating on 1024 [private] futexes for 10 secs.

perf: pthread_create: No such file or directory

In the setup where this perf bench was ran, difference was that
partition had 640 CPU's, but not all CPUs were online. 80 CPUs
were online. While blocking the threads with futex_wait, code
sets the affinity using cpumask. The cpumask size used is 80
which is picked from "nrcpus = perf_cpu_map__nr(cpu)". Here the
benchmark reports fail while setting affinity for cpu number which
is greater than 80 or higher, because it attempts to set a bit
position which is not allocated on the cpumask. Fix this by changing
the size of cpumask to number of possible cpus and not the number
of online cpus.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Disha Goel <disgoel@linux.ibm.com>
Cc: akanksha@linux.ibm.com
Cc: kjain@linux.ibm.com
Cc: maddy@linux.ibm.com
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240607044354.82225-1-atrajeev@linux.vnet.ibm.com
tools/perf/bench/futex-hash.c
tools/perf/bench/futex-lock-pi.c
tools/perf/bench/futex-requeue.c
tools/perf/bench/futex-wake-parallel.c
tools/perf/bench/futex-wake.c

index 0c69d20efa329427c71141c09e6f1c1a9031738c..b472eded521b1c714c1bad921394bc1b28311efc 100644 (file)
@@ -174,7 +174,7 @@ int bench_futex_hash(int argc, const char **argv)
        pthread_attr_init(&thread_attr);
        gettimeofday(&bench__start, NULL);
 
-       nrcpus = perf_cpu_map__nr(cpu);
+       nrcpus = cpu__max_cpu().cpu;
        cpuset = CPU_ALLOC(nrcpus);
        BUG_ON(!cpuset);
        size = CPU_ALLOC_SIZE(nrcpus);
index 7a4973346180fc91009573c503a021c9b217ee29..0416120c091b2490a5062755d1b5ce7cce8d1de5 100644 (file)
@@ -122,7 +122,7 @@ static void create_threads(struct worker *w, struct perf_cpu_map *cpu)
 {
        cpu_set_t *cpuset;
        unsigned int i;
-       int nrcpus =  perf_cpu_map__nr(cpu);
+       int nrcpus =  cpu__max_cpu().cpu;
        size_t size;
 
        threads_starting = params.nthreads;
index d9ad736c1a3e0d13317aaf28a777a6327c17e5d3..aad5bfc4fe188d48690b3e88edc4f47c76354586 100644 (file)
@@ -125,7 +125,7 @@ static void block_threads(pthread_t *w, struct perf_cpu_map *cpu)
 {
        cpu_set_t *cpuset;
        unsigned int i;
-       int nrcpus = perf_cpu_map__nr(cpu);
+       int nrcpus = cpu__max_cpu().cpu;
        size_t size;
 
        threads_starting = params.nthreads;
index b66df553e5614cb393066f2ec8b66ee75ba15ed8..90a5b91bf1396ea64b6bbfe577faf86ab58da945 100644 (file)
@@ -149,7 +149,7 @@ static void block_threads(pthread_t *w, struct perf_cpu_map *cpu)
 {
        cpu_set_t *cpuset;
        unsigned int i;
-       int nrcpus = perf_cpu_map__nr(cpu);
+       int nrcpus = cpu__max_cpu().cpu;
        size_t size;
 
        threads_starting = params.nthreads;
index 690fd6d3da130161ac6473df2ba5dabecbc8324a..49b3c89b0b35d6b23183d78358a0d3ef88ff6853 100644 (file)
@@ -100,7 +100,7 @@ static void block_threads(pthread_t *w, struct perf_cpu_map *cpu)
        cpu_set_t *cpuset;
        unsigned int i;
        size_t size;
-       int nrcpus = perf_cpu_map__nr(cpu);
+       int nrcpus = cpu__max_cpu().cpu;
        threads_starting = params.nthreads;
 
        cpuset = CPU_ALLOC(nrcpus);