85 lines
2.6 KiB
Diff
85 lines
2.6 KiB
Diff
From b07c57b33e4e24e873e680b8327f9be4f321caa9 Mon Sep 17 00:00:00 2001
|
|
From: Yunfeng Ye <yeyunfeng@huawei.com>
|
|
Date: Wed, 22 Apr 2020 10:19:52 +0800
|
|
Subject: [PATCH] cyclictest: Fix setaffinity error on large NUMA machines
|
|
|
|
An Error occurs when run: ./cyclictest -v -t 5 -p 80 -i 1000 -a 3
|
|
|
|
On large NUMA machines still getting the following error
|
|
WARN: Couldn't setaffinity in main thread: Invalid argument
|
|
|
|
Instead of calling numa_bitmask_alloc() with max_cpus, use
|
|
numa_allocate_cpumask() to fix this.
|
|
|
|
Also, make sure numa_available() is called before any other calls to the
|
|
numa library. Depending on how the options were invoked this could
|
|
happen in parse_cpumask for example. Note, this did not seem to cause
|
|
any problems in practice, but let's adhere to the library contract.
|
|
|
|
Signed-off-by: John Kacur <jkacur@redhat.com>
|
|
---
|
|
src/cyclictest/cyclictest.c | 26 +++++++++++++++++++-------
|
|
1 file changed, 19 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
|
|
index c5f1fd46567a..79bb1cb71c68 100644
|
|
--- a/src/cyclictest/cyclictest.c
|
|
+++ b/src/cyclictest/cyclictest.c
|
|
@@ -1135,7 +1135,7 @@ static void use_current_cpuset(const int max_cpus)
|
|
|
|
pid = getpid();
|
|
|
|
- curmask = numa_bitmask_alloc(sizeof(struct bitmask));
|
|
+ curmask = numa_allocate_cpumask();
|
|
numa_sched_getaffinity(pid, curmask);
|
|
|
|
/* Clear bits that are not set in both the cpuset from the environment,
|
|
@@ -1225,6 +1225,20 @@ enum option_values {
|
|
OPT_TRACEMARK, OPT_POSIX_TIMERS,
|
|
};
|
|
|
|
+/* numa_available() must be called before any other calls to the numa library */
|
|
+static void numa_initialize(void)
|
|
+{
|
|
+ static int is_initialized;
|
|
+
|
|
+ if (is_initialized == 1)
|
|
+ return;
|
|
+
|
|
+ if (numa_available() != -1)
|
|
+ numa = 1;
|
|
+
|
|
+ is_initialized = 1;
|
|
+}
|
|
+
|
|
/* Process commandline options */
|
|
static void process_options (int argc, char *argv[], int max_cpus)
|
|
{
|
|
@@ -1288,6 +1302,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
|
|
/* smp sets AFFINITY_USEALL in OPT_SMP */
|
|
if (smp)
|
|
break;
|
|
+ numa_initialize();
|
|
if (optarg != NULL) {
|
|
parse_cpumask(optarg, max_cpus);
|
|
setaffinity = AFFINITY_SPECIFIED;
|
|
@@ -1460,12 +1475,9 @@ static void process_options (int argc, char *argv[], int max_cpus)
|
|
/* if smp wasn't requested, test for numa automatically */
|
|
if (!smp) {
|
|
#ifdef NUMA
|
|
- if (numa_available() != -1) {
|
|
- numa = 1;
|
|
- if (setaffinity == AFFINITY_UNSPECIFIED) {
|
|
- setaffinity = AFFINITY_USEALL;
|
|
- }
|
|
- }
|
|
+ numa_initialize();
|
|
+ if (setaffinity == AFFINITY_UNSPECIFIED)
|
|
+ setaffinity = AFFINITY_USEALL;
|
|
#else
|
|
warn("cyclictest was not built with the numa option\n");
|
|
numa = 0;
|
|
--
|
|
2.21.3
|
|
|