Skip to contentSkip to conversation

Revert always use libnuma patches

PATCH In review John Kacur 3 participants 8 messages Feb 19, 2021 – Feb 22, 2021

lore
Share & tools
lore

John Kacur

author
#0 lore raw

cover Revert always use libnuma patches

libnuma is a build requirement but not a runtime requirement.

Test branch unstable/devel/no-numa-runtime

I would appreciate some testing before I push commits upstream

John

John Kacur (3):
Revert "cyclictest: Use affinity_mask for steering thread placement" Revert "cyclictest: Always use libnuma"
Revert "signaltest: Always use libnuma"

 src/cyclictest/cyclictest.c | 97 ++++++++++++++++++++++++-------------
 src/cyclictest/rt_numa.h    |  2 +
 src/signaltest/signaltest.c | 10 ++--
 3 files changed, 71 insertions(+), 38 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/3 Revert "cyclictest: Use affinity_mask for steering thread placement"

This reverts commit 8305e65092deeaf900366c6250d4b319f6c274b6.

Reverting to put back the code that allows us to run on machines without libnuma.

However, there were some ideas in this patch that were not directly related to that and could be revisited.

---
 src/cyclictest/cyclictest.c | 38 ++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)
src/cyclictest/cyclictest.c +31 -7
index c3d45f3ae31b..e2753db39c02 100644
@@ -892,6 +892,7 @@ static int interval = DEFAULT_INTERVAL;
 static int distance = -1;
 static struct bitmask *affinity_mask = NULL;
 static int smp = 0;
+static int setaffinity = AFFINITY_UNSPECIFIED;
 
 static int clocksources[] = {
 	CLOCK_MONOTONIC,
@@ -1019,12 +1020,22 @@ static void process_options(int argc, char *argv[], int max_cpus)
 				break;
 			if (optarg) {
 				parse_cpumask(optarg, max_cpus, &affinity_mask);
+				setaffinity = AFFINITY_SPECIFIED;
 			} else if (optind < argc &&
 				   (atoi(argv[optind]) ||
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
 				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
+				setaffinity = AFFINITY_SPECIFIED;
+			} else {
+				setaffinity = AFFINITY_USEALL;
 			}
+
+			if (setaffinity == AFFINITY_SPECIFIED && !affinity_mask)
+				display_help(1);
+			if (verbose)
+				printf("Using %u cpus.\n",
+					numa_bitmask_weight(affinity_mask));
 			break;
 		case 'A':
 		case OPT_ALIGNED:
@@ -1117,6 +1128,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		case OPT_SMP: /* SMP testing */
 			smp = 1;
 			num_threads = -1; /* update after parsing */
+			setaffinity = AFFINITY_USEALL;
 			break;
 		case 't':
 		case OPT_THREADS:
@@ -1185,16 +1197,23 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		use_nanosleep = MODE_CLOCK_NANOSLEEP;
 	}
 
+	/* if smp wasn't requested, test for numa automatically */
+	if (!smp) {
+		if (setaffinity == AFFINITY_UNSPECIFIED)
+			setaffinity = AFFINITY_USEALL;
+	}
+
 	if (option_affinity && smp) {
 		warn("-a ignored due to smp mode\n");
 		if (affinity_mask) {
 			numa_bitmask_free(affinity_mask);
 			affinity_mask = NULL;
 		}
+		setaffinity = AFFINITY_USEALL;
 	}
 
 	if (smi) {
-		if (affinity_mask)
+		if (setaffinity == AFFINITY_UNSPECIFIED)
 			fatal("SMI counter relies on thread affinity\n");
 
 		if (!has_smi_counter())
@@ -1777,7 +1796,7 @@ int main(int argc, char **argv)
 	}
 
 	/* Restrict the main pid to the affinity specified by the user */
-	if (affinity_mask) {
+	if (affinity_mask != NULL) {
 		int res;
 
 		errno = 0;
@@ -1940,13 +1959,18 @@ int main(int argc, char **argv)
 		if (status != 0)
 			fatal("error from pthread_attr_init for thread %d: %s\n", i, strerror(status));
 
-		if (affinity_mask)
+		switch (setaffinity) {
+		case AFFINITY_UNSPECIFIED: cpu = -1; break;
+		case AFFINITY_SPECIFIED:
 			cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask);
-		else
+			if (verbose)
+				printf("Thread %d using cpu %d.\n", i, cpu);
+			break;
+		case AFFINITY_USEALL:
 			cpu = cpu_for_thread_ua(i, max_cpus);
-
-		if (verbose)
-			printf("Thread %d using cpu %d.\n", i, cpu);
+			break;
+		default: cpu = -1;
+		}
 
 		/* find the memory node associated with the cpu i */
 		node = rt_numa_numa_node_of_cpu(cpu);
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 2/3 Revert "cyclictest: Always use libnuma"

In reply to John Kacur

This reverts commit 512d2b74561d5bdab15cacb7b1931cd0aa01d6b5.

libnuma is a buildtime requirement but not a runtime environment

---
 src/cyclictest/cyclictest.c | 63 ++++++++++++++++++++-----------------
 src/cyclictest/rt_numa.h    |  2 ++
 2 files changed, 36 insertions(+), 29 deletions(-)
src/cyclictest/cyclictest.c +34 -29
index e2753db39c02..3e31937f7088 100644
@@ -1018,6 +1018,9 @@ static void process_options(int argc, char *argv[], int max_cpus)
 			/* smp sets AFFINITY_USEALL in OPT_SMP */
 			if (smp)
 				break;
+			if (numa_initialize())
+				fatal("Couldn't initialize libnuma");
+			numa = 1;
 			if (optarg) {
 				parse_cpumask(optarg, max_cpus, &affinity_mask);
 				setaffinity = AFFINITY_SPECIFIED;
@@ -1126,6 +1129,8 @@ static void process_options(int argc, char *argv[], int max_cpus)
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
 		case OPT_SMP: /* SMP testing */
+			if (numa)
+				fatal("numa and smp options are mutually exclusive\n");
 			smp = 1;
 			num_threads = -1; /* update after parsing */
 			setaffinity = AFFINITY_USEALL;
@@ -1199,17 +1204,16 @@ static void process_options(int argc, char *argv[], int max_cpus)
 
 	/* if smp wasn't requested, test for numa automatically */
 	if (!smp) {
+		if (numa_initialize())
+			fatal("Couldn't initialize libnuma");
+		numa = 1;
 		if (setaffinity == AFFINITY_UNSPECIFIED)
 			setaffinity = AFFINITY_USEALL;
 	}
 
-	if (option_affinity && smp) {
-		warn("-a ignored due to smp mode\n");
-		if (affinity_mask) {
-			numa_bitmask_free(affinity_mask);
-			affinity_mask = NULL;
-		}
-		setaffinity = AFFINITY_USEALL;
+	if (option_affinity) {
+		if (smp)
+			warn("-a ignored due to smp mode\n");
 	}
 
 	if (smi) {
@@ -1778,12 +1782,6 @@ int main(int argc, char **argv)
 	int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	int i, ret = -1;
 	int status;
-	void *stack;
-	void *currstk;
-	size_t stksize;
-
-	if (numa_initialize())
-		fatal("Couldn't initialize libnuma");
 
 	process_options(argc, argv, max_cpus);
 
@@ -1972,27 +1970,34 @@ int main(int argc, char **argv)
 		default: cpu = -1;
 		}
 
-		/* find the memory node associated with the cpu i */
-		node = rt_numa_numa_node_of_cpu(cpu);
+		node = -1;
+		if (numa) {
+			void *stack;
+			void *currstk;
+			size_t stksize;
 
-		/* get the stack size set for this thread */
-		if (pthread_attr_getstack(&attr, &currstk, &stksize))
-			fatal("failed to get stack size for thread %d\n", i);
+			/* find the memory node associated with the cpu i */
+			node = rt_numa_numa_node_of_cpu(cpu);
 
-		/* if the stack size is zero, set a default */
-		if (stksize == 0)
-			stksize = PTHREAD_STACK_MIN * 2;
+			/* get the stack size set for this thread */
+			if (pthread_attr_getstack(&attr, &currstk, &stksize))
+				fatal("failed to get stack size for thread %d\n", i);
 
-		/*  allocate memory for a stack on appropriate node */
-		stack = rt_numa_numa_alloc_onnode(stksize, node, cpu);
+			/* if the stack size is zero, set a default */
+			if (stksize == 0)
+				stksize = PTHREAD_STACK_MIN * 2;
 
-		/* touch the stack pages to pre-fault them in */
-		memset(stack, 0, stksize);
+			/*  allocate memory for a stack on appropriate node */
+			stack = rt_numa_numa_alloc_onnode(stksize, node, cpu);
 
-		/* set the thread's stack */
-		if (pthread_attr_setstack(&attr, stack, stksize))
-			fatal("failed to set stack addr for thread %d to 0x%x\n",
-				i, stack+stksize);
+			/* touch the stack pages to pre-fault them in */
+			memset(stack, 0, stksize);
+
+			/* set the thread's stack */
+			if (pthread_attr_setstack(&attr, stack, stksize))
+				fatal("failed to set stack addr for thread %d to 0x%x\n",
+				      i, stack+stksize);
+		}
 
 		/* allocate the thread's parameter block  */
 		parameters[i] = par = threadalloc(sizeof(struct thread_param), node);
src/cyclictest/rt_numa.h +2 -0
index 87f5d3b66458..4cbd979c21e8 100644
@@ -13,6 +13,8 @@
 #include "rt-utils.h"
 #include "rt-error.h"
 
+static int numa = 0;
+
 #include <numa.h>
 
 static void *
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH 3/3 Revert "signaltest: Always use libnuma"

In reply to John Kacur

This reverts commit 3079f1b10d086b878f52607035b328f450b8033e.

libnuma is a build-time requirement but not a runtime requirement

---
 src/signaltest/signaltest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/signaltest/signaltest.c +6 -4
index 1d1b070cf12b..4f8e7caea2c1 100644
@@ -207,6 +207,7 @@ static int quiet;
 static int lockall;
 static struct bitmask *affinity_mask = NULL;
 static int smp = 0;
+static int numa = 0;
 static int setaffinity = AFFINITY_UNSPECIFIED;
 static char outfile[MAX_PATH];
 
@@ -222,7 +223,6 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 {
 	int option_affinity = 0;
 	int error = 0;
-	int numa = 0;
 
 	for (;;) {
 		int option_index = 0;
@@ -253,6 +253,8 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 			/* smp sets AFFINITY_USEALL in OPT_SMP */
 			if (smp)
 				break;
+			if (numa_initialize())
+				fatal("Couldn't initialize libnuma");
 			numa = 1;
 			if (optarg) {
 				parse_cpumask(optarg, max_cpus, &affinity_mask);
@@ -337,6 +339,9 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 
 	/* if smp wasn't requested, test for numa automatically */
 	if (!smp) {
+		if (numa_initialize())
+			fatal("Couldn't initialize libnuma");
+		numa = 1;
 		if (setaffinity == AFFINITY_UNSPECIFIED)
 			setaffinity = AFFINITY_USEALL;
 	}
@@ -412,9 +417,6 @@ int main(int argc, char **argv)
 	int status, cpu;
 	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
-	if (numa_initialize())
-		fatal("Couldn't initialize libnuma");
-
 	process_options(argc, argv, max_cpus);
 
 	if (check_privs())
Signature · 1 line
2.26.2
#4 lore raw
In reply to John Kacur
Quoted 6 lines · John Kacur

libnuma is a build requirement but not a runtime requirement.

Test branch unstable/devel/no-numa-runtime

I would appreciate some testing before I push commits upstream

Now it is the same situation as in v1.10:
With the --smp option set, cyclictest runs on arm32. Otherwise I still get the "FATAL: Couldn't initialize libnuma" (newline missing!)

regards
Christian

author
#5 lore raw
Quoted 5 lines · Christian Eggers
Quoted 4 lines · John Kacur

libnuma is a build requirement but not a runtime requirement.

Test branch unstable/devel/no-numa-runtime

Quoted 11 lines
Quoted 2 lines

I would appreciate some testing before I push commits upstream

Now it is the same situation as in v1.10:
With the --smp option set, cyclictest runs on arm32. Otherwise I still get the "FATAL: Couldn't initialize libnuma" (newline missing!)

regards
Christian

I think I see the problem, the patch
rt-numa: Move thread placement code to rt-numa library

added the fatal if numa_failed.

Thanks for testing. I'll send a patch to put it back the old way.

John

#6 lore raw
Quoted 4 lines · John Kacur

I think I see the problem, the patch
rt-numa: Move thread placement code to rt-numa library

added the fatal if numa_failed.

Sorry about the mess, I thought we can relay on libnuma. The concept to depend on compile time on a library and not during runtime escaped my attention.

Quoted 1 line

Thanks for testing. I'll send a patch to put it back the old way.

Thanks John!

author
#7 lore raw
Quoted 9 lines · Daniel Wagner
Quoted 4 lines · John Kacur

I think I see the problem, the patch
rt-numa: Move thread placement code to rt-numa library

added the fatal if numa_failed.

Sorry about the mess, I thought we can relay on libnuma. The concept to depend on compile time on a library and not during runtime escaped my attention.

No problem, I should have caught this myself in code review.
I had honestly forgotten that when we made numa a compile time requirement that we made it so that it was not a runtime requirement, even though I wrote most of the code to achieve that.

Quoted 5 lines
Quoted 2 lines

Thanks for testing. I'll send a patch to put it back the old way.

Thanks John!