[PATCH v4 11/11] tools/perf: Allocate futex locks on the local CPU-node.

Sebastian Andrzej Siewior
2024-12-03T16:43:42Z

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
tools/perf/bench/futex-hash.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index 216b0d1301ffc..4c7c6677463f8 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -122,6 +122,8 @@ static void print_summary(void)
(int)bench__runtime.tv_sec);
}

+#include <numa.h>
+
#define PR_FUTEX_HASH 77
# define PR_FUTEX_HASH_SET_SLOTS 1
# define PR_FUTEX_HASH_GET_SLOTS 2
@@ -212,14 +214,19 @@ int bench_futex_hash(int argc, const char **argv)
size = CPU_ALLOC_SIZE(4096);

for (i = 0; i < params.nthreads; i++) {
+ unsigned int cpu_num;
worker[i].tid = i;
- worker[i].futex = calloc(params.nfutexes, sizeof(*worker[i].futex));
- if (!worker[i].futex)
- goto errmem;

CPU_ZERO_S(size, cpuset);
+ cpu_num = get_cpu_bit(&cpuset_, sizeof(cpuset_), i % nrcpus);
+ //worker[i].futex = calloc(params.nfutexes, sizeof(*worker[i].futex));

- CPU_SET_S(get_cpu_bit(&cpuset_, sizeof(cpuset_), i % nrcpus), size, cpuset);
+ worker[i].futex = numa_alloc_onnode(params.nfutexes * sizeof(*worker[i].futex),
+ numa_node_of_cpu(cpu_num));
+ if (worker[i].futex == MAP_FAILED || worker[i].futex == NULL)
+ goto errmem;
+
+ CPU_SET_S(cpu_num, size, cpuset);

ret = pthread_attr_setaffinity_np(&thread_attr, size, cpuset);
if (ret) {
@@ -271,7 +278,7 @@ int bench_futex_hash(int argc, const char **argv)
&worker[i].futex[params.nfutexes-1], t);
}

- zfree(&worker[i].futex);
+ numa_free(worker[i].futex, params.nfutexes * sizeof(*worker[i].futex));
}

print_summary();
--
2.45.2