Skip to contentSkip to conversation

rt-numa.h cleanups

PATCH In review Daniel Wagner 3 participants 22 messages Feb 10, 2021 – Feb 17, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

v4 cover rt-numa.h cleanups

This series cleans up the rt-numa.h header.

As we have a hard dependency on libnuma we can simplify the code in cyclictest. This allows remove all the small helpers in rt_numa.h. And with this we can remove the header and reduce the confusion with rt-numa.h

While at it, I simplified the --smp vs --affinity vs --threads logic. There is no need for additional variables to keep state. With this we also make --affinity to behave as with the rest of rt-tests. That is a plan -a will be the same as with -S. There is no need for -S anymore but I think we should leave it in place for backwards compatibility. I suspect, there must be a lot of muscle memory out there :)

Since signaltest has the same code as cyclictest, cleanup this tool as well.

With all those cleanups in cyclictest and signaltest, rt-numa.h contains only a three functions. The final part of the series is to remove unnecessary function arguments (max_cpus). This also fixes the theoretical problem that a sparse cpumask would not be handled correctly.

v4:
- build fix becaue of error.c -> rt-error.c

v3:
- added error handling for numa_on_node() return value
- added 'Rename error.h to rt-error.h' patch
- rebased, dropped applied patches
- fixed SoBs and stearing vs sterring spelling error

v2:
- added more cleanup patches

Daniel Wagner (16):
cyclictest: Use numa API directly
cyclictest: Mimic --smp behavior with --affinity
cyclictest: Simplify --smp vs --affinity vs --threads argument logic
signaltest: Use affinity_mask for steering thread placement
signaltest: Simplify --smp vs --affinity vs --threads argument logic
rt-numa: Remove unused definitions and numa_initialize()
rt-numa: Add generic cpu_for_thread() helper
rt-numa: Use mask size for iterator limit
rt-numa: Remove max_cpus argument from parse_cpusmask
signaltest: Remove unused max_cpus argument from process_options
cyclictest: Remove unused max_cpus argument from process_options
rt-numa: Use CPU_SETSIZE as upper loop limit
rt-numa: Remove used max_cpus argument from cpu_for_thread()
cyclictest: Remove max cpus used verbose information
cyclictest: Remove unecessary local variable
rt-tests: Rename error.h to rt-error.h

 Makefile                            |   2 +-
 src/cyclictest/cyclictest.c         | 111 ++++++++++------------------
 src/cyclictest/rt_numa.h            |  96 ------------------------
 src/include/pip_stress.h            |   5 +-
 src/include/{error.h => rt-error.h} |   0
 src/include/rt-numa.h               |  13 +---
 src/lib/{error.c => rt-error.c}     |   2 +-
 src/lib/rt-numa.c                   |  42 +++++------
 src/lib/rt-utils.c                  |   3 +-
 src/oslat/oslat.c                   |   5 +-
 src/pi_tests/pi_stress.c            |   3 +-
 src/pmqtest/pmqtest.c               |   6 +-
 src/ptsematest/ptsematest.c         |   6 +-
 src/sched_deadline/cyclicdeadline.c |   6 +-
 src/signaltest/signaltest.c         |  76 +++++--------------
 src/sigwaittest/sigwaittest.c       |   2 +-
 src/svsematest/svsematest.c         |   3 +-
 17 files changed, 99 insertions(+), 282 deletions(-)
 delete mode 100644 src/cyclictest/rt_numa.h
 rename src/include/{error.h => rt-error.h} (100%)
 rename src/lib/{error.c => rt-error.c} (98%)
Signature · 1 line
2.30.0
#1 lore raw

PATCH v4 1/16 cyclictest: Use numa API directly

There is no need for small libnuma wrappers functions as we always use libnuma. Remove them and get rid of rt_numa.h, so there is no confusion with rt-numa.h anymore.

---
 src/cyclictest/cyclictest.c | 43 +++++++++--------
 src/cyclictest/rt_numa.h    | 96 -------------------------------------
 2 files changed, 24 insertions(+), 115 deletions(-)
 delete mode 100644 src/cyclictest/rt_numa.h
src/cyclictest/cyclictest.c +24 -19
index 99846e78526f..6009ff2a83bc 100644
@@ -33,10 +33,10 @@
 #include <sys/utsname.h>
 #include <sys/mman.h>
 #include <sys/syscall.h>
-#include "rt_numa.h"
 
 #include "rt-utils.h"
 #include "rt-numa.h"
+#include "error.h"
 
 #include <bionic.h>
 
@@ -514,9 +514,9 @@ static void *timerthread(void *param)
 
 	memset(&stop, 0, sizeof(stop));
 
-	/* if we're running in numa mode, set our memory node */
-	if (par->node != -1)
-		rt_numa_set_numa_run_on_node(par->node, par->cpu);
+	if (numa_run_on_node(par->node))
+		warn("Could not set NUMA node %d for thread %d: %s\n",
+				par->node, par->cpu, strerror(errno));
 
 	if (par->cpu != -1) {
 		CPU_ZERO(&mask);
@@ -1251,7 +1251,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
 	}
 	if (error) {
 		if (affinity_mask)
-			rt_bitmask_free(affinity_mask);
+			numa_bitmask_free(affinity_mask);
 		display_help(1);
 	}
 }
@@ -1907,7 +1907,9 @@ int main(int argc, char **argv)
 			printf("Thread %d using cpu %d.\n", i, cpu);
 
 		/* find the memory node associated with the cpu i */
-		node = rt_numa_numa_node_of_cpu(cpu);
+		node = numa_node_of_cpu(cpu);
+		if (node == -1)
+			fatal("Invalid NUMA node selected via affinity mask\n");
 
 		/* get the stack size set for this thread */
 		if (pthread_attr_getstack(&attr, &currstk, &stksize))
@@ -1918,7 +1920,10 @@ int main(int argc, char **argv)
 			stksize = PTHREAD_STACK_MIN * 2;
 
 		/*  allocate memory for a stack on appropriate node */
-		stack = rt_numa_numa_alloc_onnode(stksize, node, cpu);
+		stack = numa_alloc_onnode(stksize, node);
+		if (!stack)
+			fatal("failed to allocate %d bytes on node %d for cpu %d\n",
+				stksize, node, cpu);
 
 		/* touch the stack pages to pre-fault them in */
 		memset(stack, 0, stksize);
@@ -1929,13 +1934,13 @@ int main(int argc, char **argv)
 				i, stack+stksize);
 
 		/* allocate the thread's parameter block  */
-		parameters[i] = par = threadalloc(sizeof(struct thread_param), node);
+		parameters[i] = par = numa_alloc_onnode(sizeof(struct thread_param), node);
 		if (par == NULL)
 			fatal("error allocating thread_param struct for thread %d\n", i);
 		memset(par, 0, sizeof(struct thread_param));
 
 		/* allocate the thread's statistics block */
-		statistics[i] = stat = threadalloc(sizeof(struct thread_stat), node);
+		statistics[i] = stat = numa_alloc_onnode(sizeof(struct thread_stat), node);
 		if (stat == NULL)
 			fatal("error allocating thread status struct for thread %d\n", i);
 		memset(stat, 0, sizeof(struct thread_stat));
@@ -1944,8 +1949,8 @@ int main(int argc, char **argv)
 		if (histogram) {
 			int bufsize = histogram * sizeof(long);
 
-			stat->hist_array = threadalloc(bufsize, node);
-			stat->outliers = threadalloc(bufsize, node);
+			stat->hist_array = numa_alloc_onnode(bufsize, node);
+			stat->outliers = numa_alloc_onnode(bufsize, node);
 			if (stat->hist_array == NULL || stat->outliers == NULL)
 				fatal("failed to allocate histogram of size %d on node %d\n",
 				      histogram, i);
@@ -1955,14 +1960,14 @@ int main(int argc, char **argv)
 
 		if (verbose) {
 			int bufsize = VALBUF_SIZE * sizeof(long);
-			stat->values = threadalloc(bufsize, node);
+			stat->values = numa_alloc_onnode(bufsize, node);
 			if (!stat->values)
 				goto outall;
 			memset(stat->values, 0, bufsize);
 			par->bufmsk = VALBUF_SIZE - 1;
 			if (smi) {
 				int bufsize = VALBUF_SIZE * sizeof(long);
-				stat->smis = threadalloc(bufsize, node);
+				stat->smis = numa_alloc_onnode(bufsize, node);
 				if (!stat->smis)
 					goto outall;
 				memset(stat->smis, 0, bufsize);
@@ -2077,7 +2082,7 @@ int main(int argc, char **argv)
 				print_stat(stdout, parameters[i], i, 0, 0);
 		}
 		if (statistics[i]->values)
-			threadfree(statistics[i]->values, VALBUF_SIZE*sizeof(long), parameters[i]->node);
+			numa_free(statistics[i]->values, VALBUF_SIZE*sizeof(long));
 	}
 
 	if (trigger)
@@ -2086,8 +2091,8 @@ int main(int argc, char **argv)
 	if (histogram) {
 		print_hist(parameters, num_threads);
 		for (i = 0; i < num_threads; i++) {
-			threadfree(statistics[i]->hist_array, histogram*sizeof(long), parameters[i]->node);
-			threadfree(statistics[i]->outliers, histogram*sizeof(long), parameters[i]->node);
+			numa_free(statistics[i]->hist_array, histogram*sizeof(long));
+			numa_free(statistics[i]->outliers, histogram*sizeof(long));
 		}
 	}
 
@@ -2103,14 +2108,14 @@ int main(int argc, char **argv)
 	for (i=0; i < num_threads; i++) {
 		if (!statistics[i])
 			continue;
-		threadfree(statistics[i], sizeof(struct thread_stat), parameters[i]->node);
+		numa_free(statistics[i], sizeof(struct thread_stat));
 	}
 
  outpar:
 	for (i = 0; i < num_threads; i++) {
 		if (!parameters[i])
 			continue;
-		threadfree(parameters[i], sizeof(struct thread_param), parameters[i]->node);
+		numa_free(parameters[i], sizeof(struct thread_param));
 	}
  out:
 	/* close any tracer file descriptors */
@@ -2125,7 +2130,7 @@ int main(int argc, char **argv)
 		close(latency_target_fd);
 
 	if (affinity_mask)
-		rt_bitmask_free(affinity_mask);
+		numa_bitmask_free(affinity_mask);
 
 	/* Remove running status shared memory file if it exists */
 	if (rstat_fd >= 0)
src/cyclictest/rt_numa.h deleted +0 -96

96 lines not on this page · raw message

Signature · 1 line
2.30.0
#2 lore raw

Re: [PATCH rt-tests v4 01/16] cyclictest: Use numa API directly

Quoted 268 lines · Daniel Wagner

There is no need for small libnuma wrappers functions as we always use libnuma. Remove them and get rid of rt_numa.h, so there is no confusion with rt-numa.h anymore.

---
 src/cyclictest/cyclictest.c | 43 +++++++++--------
 src/cyclictest/rt_numa.h    | 96 -------------------------------------
 2 files changed, 24 insertions(+), 115 deletions(-)
 delete mode 100644 src/cyclictest/rt_numa.h
src/cyclictest/cyclictest.c +24 -19
index 99846e78526f..6009ff2a83bc 100644
@@ -33,10 +33,10 @@
 #include <sys/utsname.h>
 #include <sys/mman.h>
 #include <sys/syscall.h>
-#include "rt_numa.h"
 
 #include "rt-utils.h"
 #include "rt-numa.h"
+#include "error.h"
 
 #include <bionic.h>
 
@@ -514,9 +514,9 @@ static void *timerthread(void *param)
 
 	memset(&stop, 0, sizeof(stop));
 
-	/* if we're running in numa mode, set our memory node */
-	if (par->node != -1)
-		rt_numa_set_numa_run_on_node(par->node, par->cpu);
+	if (numa_run_on_node(par->node))
+		warn("Could not set NUMA node %d for thread %d: %s\n",
+				par->node, par->cpu, strerror(errno));
 
 	if (par->cpu != -1) {
 		CPU_ZERO(&mask);
@@ -1251,7 +1251,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
 	}
 	if (error) {
 		if (affinity_mask)
-			rt_bitmask_free(affinity_mask);
+			numa_bitmask_free(affinity_mask);
 		display_help(1);
 	}
 }
@@ -1907,7 +1907,9 @@ int main(int argc, char **argv)
 			printf("Thread %d using cpu %d.\n", i, cpu);
 
 		/* find the memory node associated with the cpu i */
-		node = rt_numa_numa_node_of_cpu(cpu);
+		node = numa_node_of_cpu(cpu);
+		if (node == -1)
+			fatal("Invalid NUMA node selected via affinity mask\n");
 
 		/* get the stack size set for this thread */
 		if (pthread_attr_getstack(&attr, &currstk, &stksize))
@@ -1918,7 +1920,10 @@ int main(int argc, char **argv)
 			stksize = PTHREAD_STACK_MIN * 2;
 
 		/*  allocate memory for a stack on appropriate node */
-		stack = rt_numa_numa_alloc_onnode(stksize, node, cpu);
+		stack = numa_alloc_onnode(stksize, node);
+		if (!stack)
+			fatal("failed to allocate %d bytes on node %d for cpu %d\n",
+				stksize, node, cpu);
 
 		/* touch the stack pages to pre-fault them in */
 		memset(stack, 0, stksize);
@@ -1929,13 +1934,13 @@ int main(int argc, char **argv)
 				i, stack+stksize);
 
 		/* allocate the thread's parameter block  */
-		parameters[i] = par = threadalloc(sizeof(struct thread_param), node);
+		parameters[i] = par = numa_alloc_onnode(sizeof(struct thread_param), node);
 		if (par == NULL)
 			fatal("error allocating thread_param struct for thread %d\n", i);
 		memset(par, 0, sizeof(struct thread_param));
 
 		/* allocate the thread's statistics block */
-		statistics[i] = stat = threadalloc(sizeof(struct thread_stat), node);
+		statistics[i] = stat = numa_alloc_onnode(sizeof(struct thread_stat), node);
 		if (stat == NULL)
 			fatal("error allocating thread status struct for thread %d\n", i);
 		memset(stat, 0, sizeof(struct thread_stat));
@@ -1944,8 +1949,8 @@ int main(int argc, char **argv)
 		if (histogram) {
 			int bufsize = histogram * sizeof(long);
 
-			stat->hist_array = threadalloc(bufsize, node);
-			stat->outliers = threadalloc(bufsize, node);
+			stat->hist_array = numa_alloc_onnode(bufsize, node);
+			stat->outliers = numa_alloc_onnode(bufsize, node);
 			if (stat->hist_array == NULL || stat->outliers == NULL)
 				fatal("failed to allocate histogram of size %d on node %d\n",
 				      histogram, i);
@@ -1955,14 +1960,14 @@ int main(int argc, char **argv)
 
 		if (verbose) {
 			int bufsize = VALBUF_SIZE * sizeof(long);
-			stat->values = threadalloc(bufsize, node);
+			stat->values = numa_alloc_onnode(bufsize, node);
 			if (!stat->values)
 				goto outall;
 			memset(stat->values, 0, bufsize);
 			par->bufmsk = VALBUF_SIZE - 1;
 			if (smi) {
 				int bufsize = VALBUF_SIZE * sizeof(long);
-				stat->smis = threadalloc(bufsize, node);
+				stat->smis = numa_alloc_onnode(bufsize, node);
 				if (!stat->smis)
 					goto outall;
 				memset(stat->smis, 0, bufsize);
@@ -2077,7 +2082,7 @@ int main(int argc, char **argv)
 				print_stat(stdout, parameters[i], i, 0, 0);
 		}
 		if (statistics[i]->values)
-			threadfree(statistics[i]->values, VALBUF_SIZE*sizeof(long), parameters[i]->node);
+			numa_free(statistics[i]->values, VALBUF_SIZE*sizeof(long));
 	}
 
 	if (trigger)
@@ -2086,8 +2091,8 @@ int main(int argc, char **argv)
 	if (histogram) {
 		print_hist(parameters, num_threads);
 		for (i = 0; i < num_threads; i++) {
-			threadfree(statistics[i]->hist_array, histogram*sizeof(long), parameters[i]->node);
-			threadfree(statistics[i]->outliers, histogram*sizeof(long), parameters[i]->node);
+			numa_free(statistics[i]->hist_array, histogram*sizeof(long));
+			numa_free(statistics[i]->outliers, histogram*sizeof(long));
 		}
 	}
 
@@ -2103,14 +2108,14 @@ int main(int argc, char **argv)
 	for (i=0; i < num_threads; i++) {
 		if (!statistics[i])
 			continue;
-		threadfree(statistics[i], sizeof(struct thread_stat), parameters[i]->node);
+		numa_free(statistics[i], sizeof(struct thread_stat));
 	}
 
  outpar:
 	for (i = 0; i < num_threads; i++) {
 		if (!parameters[i])
 			continue;
-		threadfree(parameters[i], sizeof(struct thread_param), parameters[i]->node);
+		numa_free(parameters[i], sizeof(struct thread_param));
 	}
  out:
 	/* close any tracer file descriptors */
@@ -2125,7 +2130,7 @@ int main(int argc, char **argv)
 		close(latency_target_fd);
 
 	if (affinity_mask)
-		rt_bitmask_free(affinity_mask);
+		numa_bitmask_free(affinity_mask);
 
 	/* Remove running status shared memory file if it exists */
 	if (rstat_fd >= 0)
src/cyclictest/rt_numa.h deleted +0 -96
deleted file mode 100644
index 8d02f419ed6d..000000000000
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * A numa library for cyclictest.
- *
- * (C) 2010 John Kacur <[email protected]>
- * (C) 2010 Clark Williams <[email protected]>
- *
- */
-
-#ifndef _RT_NUMA_H
-#define _RT_NUMA_H
-
-#include "rt-utils.h"
-#include "error.h"
-
-#include <numa.h>
-
-static void *
-threadalloc(size_t size, int node)
-{
-	if (node == -1)
-		return malloc(size);
-	return numa_alloc_onnode(size, node);
-}
-
-static void
-threadfree(void *ptr, size_t size, int node)
-{
-	if (node == -1)
-		free(ptr);
-	else
-		numa_free(ptr, size);
-}
-
-static void rt_numa_set_numa_run_on_node(int node, int cpu)
-{
-	int res;
-	res = numa_run_on_node(node);
-	if (res)
-		warn("Could not set NUMA node %d for thread %d: %s\n",
-				node, cpu, strerror(errno));
-	return;
-}
-
-static void *rt_numa_numa_alloc_onnode(size_t size, int node, int cpu)
-{
-	void *stack;
-	stack = numa_alloc_onnode(size, node);
-	if (stack == NULL)
-		fatal("failed to allocate %d bytes on node %d for cpu %d\n",
-				size, node, cpu);
-	return stack;
-}
-
-/*
- * Use new bit mask CPU affinity behavior
- */
-static int rt_numa_numa_node_of_cpu(int cpu)
-{
-	int node;
-	node = numa_node_of_cpu(cpu);
-	if (node == -1)
-		fatal("invalid cpu passed to numa_node_of_cpu(%d)\n", cpu);
-	return node;
-}
-
-static inline unsigned int rt_numa_bitmask_isbitset( const struct bitmask *mask,
-	unsigned long i)
-{
-	return numa_bitmask_isbitset(mask,i);
-}
-
-static inline struct bitmask* rt_numa_parse_cpustring(const char* s,
-	int max_cpus)
-{
-	return numa_parse_cpustring_all(s);
-}
-
-static inline void rt_bitmask_free(struct bitmask *mask)
-{
-	numa_bitmask_free(mask);
-}
-
-/** Returns number of bits set in mask. */
-static inline unsigned int rt_numa_bitmask_count(const struct bitmask *mask)
-{
-	unsigned int num_bits = 0, i;
-	for (i = 0; i < mask->size; i++) {
-		if (rt_numa_bitmask_isbitset(mask, i))
-			num_bits++;
-	}
-	/* Could stash this instead of recomputing every time. */
-	return num_bits;
-}
-
-#endif	/* _RT_NUMA_H */
Signature · 1 line
2.30.0

I don't want to do this right now until we figure out the future of rt_numa.h

Using rt_numa.h is not harmful, and in fact using the numa api directly increases the code size in cyclictest.

We can revisit this later, but I don't want it to hold up the JSON stuff anymore.

Thanks

John

#3 lore raw

PATCH v4 2/16 cyclictest: Mimic --smp behavior with --affinity

In reply to Daniel Wagner

Let --affinity without an argument behave in the same way as --smp. Run a thread on each CPU. This makes cyclictest behave as the rest of the rt-tests when --affinity is used.

---
 src/cyclictest/cyclictest.c | 2 ++
 1 file changed, 2 insertions(+)
src/cyclictest/cyclictest.c +2 -0
index 6009ff2a83bc..4c02f067fbad 100644
@@ -1019,6 +1019,8 @@ static void process_options(int argc, char *argv[], int max_cpus)
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
 				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
+			} else {
+				num_threads = -1;
 			}
 			break;
 		case 'A':
Signature · 1 line
2.30.0
#4 lore raw

Re: [PATCH rt-tests v4 02/16] cyclictest: Mimic --smp behavior with --affinity

Quoted 26 lines · Daniel Wagner

Let --affinity without an argument behave in the same way as --smp. Run a thread on each CPU. This makes cyclictest behave as the rest of the rt-tests when --affinity is used.

---
 src/cyclictest/cyclictest.c | 2 ++
 1 file changed, 2 insertions(+)
src/cyclictest/cyclictest.c +2 -0
index 6009ff2a83bc..4c02f067fbad 100644
@@ -1019,6 +1019,8 @@ static void process_options(int argc, char *argv[], int max_cpus)
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
 				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
+			} else {
+				num_threads = -1;
 			}
 			break;
 		case 'A':
Signature · 1 line
2.30.0

This doesn't look right. num_threads = -1 will get the number of cpus after parsing, so that's okay, it should imply use all available cpus, and also the priorities of all threads are the same.

As I've explained though, I'm not ready to drop the possibility to compile without numa, and then we need to think what this implies to the smp option. I do like the way you are simplifying things here, we maybe able to drop smp altogether in the future, or have it just an option that keeps the priorities the same.

Need to look at it more, not applying right now. I want to get the JSON code applied, this stuff is holding it up.

#5 lore raw

PATCH v4 3/16 cyclictest: Simplify --smp vs --affinity vs --threads argument logic

In reply to Daniel Wagner

Allow each command line only to update one variable and do the final decission at the end of the parsing step. With this the order of the command line is not important.

---
 src/cyclictest/cyclictest.c | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)
src/cyclictest/cyclictest.c +8 -26
index 4c02f067fbad..b5cca3ae166b 100644
@@ -880,14 +880,13 @@ static int timermode = TIMER_ABSTIME;
 static int use_system;
 static int priority;
 static int policy = SCHED_OTHER;	/* default policy if not specified */
-static int num_threads = 1;
+static int num_threads = -1;
 static int max_cycles;
 static int clocksel = 0;
 static int quiet;
 static int interval = DEFAULT_INTERVAL;
 static int distance = -1;
 static struct bitmask *affinity_mask = NULL;
-static int smp = 0;
 
 static int clocksources[] = {
 	CLOCK_MONOTONIC,
@@ -953,7 +952,7 @@ enum option_values {
 static void process_options(int argc, char *argv[], int max_cpus)
 {
 	int error = 0;
-	int option_affinity = 0;
+	int smp = 0;
 
 	for (;;) {
 		int option_index = 0;
@@ -1008,10 +1007,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		switch (c) {
 		case 'a':
 		case OPT_AFFINITY:
-			option_affinity = 1;
-			/* smp sets AFFINITY_USEALL in OPT_SMP */
-			if (smp)
-				break;
 			if (optarg) {
 				parse_cpumask(optarg, max_cpus, &affinity_mask);
 			} else if (optind < argc &&
@@ -1019,8 +1014,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
 				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
-			} else {
-				num_threads = -1;
 			}
 			break;
 		case 'A':
@@ -1108,22 +1101,14 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		case OPT_SYSTEM:
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
-		case OPT_SMP: /* SMP testing */
-			smp = 1;
-			num_threads = -1; /* update after parsing */
-			break;
+		case OPT_SMP:
+			smp = 1; break;
 		case 't':
 		case OPT_THREADS:
-			if (smp) {
-				warn("-t ignored due to smp mode\n");
-				break;
-			}
 			if (optarg != NULL)
 				num_threads = atoi(optarg);
 			else if (optind < argc && atoi(argv[optind]))
 				num_threads = atoi(argv[optind]);
-			else
-				num_threads = -1; /* update after parsing */
 			break;
 		case OPT_TRIGGER:
 			trigger = atoi(optarg);
@@ -1179,13 +1164,10 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		use_nanosleep = MODE_CLOCK_NANOSLEEP;
 	}
 
-	if (option_affinity && smp) {
-		warn("-a ignored due to smp mode\n");
-		if (affinity_mask) {
-			numa_bitmask_free(affinity_mask);
-			affinity_mask = NULL;
-		}
-	}
+	if (smp && num_threads != -1)
+		warn("--threads overwrites smp mode\n");
+	if (smp && affinity_mask)
+		warn("--affinity overwrites smp mode\n");
 
 	if (smi) {
 		if (affinity_mask)
Signature · 1 line
2.30.0
#6 lore raw

Re: [PATCH rt-tests v4 03/16] cyclictest: Simplify --smp vs --affinity vs --threads argument logic

Hi Daniel,

Spotted one typo below while browsing through the patches.

Quoted 2 lines · Daniel Wagner

Allow each command line only to update one variable and do the final decission at the end of the parsing step. With this the order

^
decision

Regards,
Punit

Quoted 99 lines

of the command line is not important.

---
 src/cyclictest/cyclictest.c | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)
src/cyclictest/cyclictest.c +8 -26
index 4c02f067fbad..b5cca3ae166b 100644
@@ -880,14 +880,13 @@ static int timermode = TIMER_ABSTIME;
 static int use_system;
 static int priority;
 static int policy = SCHED_OTHER;	/* default policy if not specified */
-static int num_threads = 1;
+static int num_threads = -1;
 static int max_cycles;
 static int clocksel = 0;
 static int quiet;
 static int interval = DEFAULT_INTERVAL;
 static int distance = -1;
 static struct bitmask *affinity_mask = NULL;
-static int smp = 0;
 
 static int clocksources[] = {
 	CLOCK_MONOTONIC,
@@ -953,7 +952,7 @@ enum option_values {
 static void process_options(int argc, char *argv[], int max_cpus)
 {
 	int error = 0;
-	int option_affinity = 0;
+	int smp = 0;
 
 	for (;;) {
 		int option_index = 0;
@@ -1008,10 +1007,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		switch (c) {
 		case 'a':
 		case OPT_AFFINITY:
-			option_affinity = 1;
-			/* smp sets AFFINITY_USEALL in OPT_SMP */
-			if (smp)
-				break;
 			if (optarg) {
 				parse_cpumask(optarg, max_cpus, &affinity_mask);
 			} else if (optind < argc &&
@@ -1019,8 +1014,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
 				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
-			} else {
-				num_threads = -1;
 			}
 			break;
 		case 'A':
@@ -1108,22 +1101,14 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		case OPT_SYSTEM:
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
-		case OPT_SMP: /* SMP testing */
-			smp = 1;
-			num_threads = -1; /* update after parsing */
-			break;
+		case OPT_SMP:
+			smp = 1; break;
 		case 't':
 		case OPT_THREADS:
-			if (smp) {
-				warn("-t ignored due to smp mode\n");
-				break;
-			}
 			if (optarg != NULL)
 				num_threads = atoi(optarg);
 			else if (optind < argc && atoi(argv[optind]))
 				num_threads = atoi(argv[optind]);
-			else
-				num_threads = -1; /* update after parsing */
 			break;
 		case OPT_TRIGGER:
 			trigger = atoi(optarg);
@@ -1179,13 +1164,10 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		use_nanosleep = MODE_CLOCK_NANOSLEEP;
 	}
 
-	if (option_affinity && smp) {
-		warn("-a ignored due to smp mode\n");
-		if (affinity_mask) {
-			numa_bitmask_free(affinity_mask);
-			affinity_mask = NULL;
-		}
-	}
+	if (smp && num_threads != -1)
+		warn("--threads overwrites smp mode\n");
+	if (smp && affinity_mask)
+		warn("--affinity overwrites smp mode\n");
 
 	if (smi) {
 		if (affinity_mask)
#7 lore raw

Re: [PATCH rt-tests v4 03/16] cyclictest: Simplify --smp vs --affinity vs --threads argument logic

Hi Punit,

Quoted 1 line · Punit Agrawal

Spotted one typo below while browsing through the patches.

Thanks, fixed the two commit message up.
Daniel

#8 lore raw

PATCH v4 4/16 signaltest: Use affinity_mask for steering thread placement

In reply to Daniel Wagner

We don't need an extra variable to track the state if a bitmask is available or not. Check directly if the mask is usable.

---
 src/signaltest/signaltest.c | 44 ++++++++-----------------------------
 1 file changed, 9 insertions(+), 35 deletions(-)
src/signaltest/signaltest.c +9 -35
index b3a82f8c4f65..e19fc9a740a9 100644
@@ -205,15 +205,13 @@ static int verbose;
 static int quiet;
 static int lockall;
 static struct bitmask *affinity_mask = NULL;
-static int smp = 0;
-static int setaffinity = AFFINITY_UNSPECIFIED;
 
 /* Process commandline options */
 static void process_options(int argc, char *argv[], unsigned int max_cpus)
 {
-	int option_affinity = 0;
 	int error = 0;
 	int numa = 0;
+	int smp = 0;
 
 	for (;;) {
 		int option_index = 0;
@@ -238,26 +236,19 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 			break;
 		switch (c) {
 		case 'a':
-			option_affinity = 1;
 			/* smp sets AFFINITY_USEALL in OPT_SMP */
 			if (smp)
 				break;
 			numa = 1;
 			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));
@@ -275,7 +266,6 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 				fatal("numa and smp options are mutually exclusive\n");
 			smp = 1;
 			num_threads = -1; /* update after parsing */
-			setaffinity = AFFINITY_USEALL;
 			break;
 		case 't': num_threads = atoi(optarg); break;
 		case 'v': verbose = 1; break;
@@ -294,16 +284,8 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 	if (num_threads < 2)
 		error = 1;
 
-	/* if smp wasn't requested, test for numa automatically */
-	if (!smp) {
-		if (setaffinity == AFFINITY_UNSPECIFIED)
-			setaffinity = AFFINITY_USEALL;
-	}
-
-	if (option_affinity) {
-		if (smp)
-			warn("-a ignored due to smp mode\n");
-	}
+	if (smp && affinity_mask)
+		warn("-a ignored due to smp mode\n");
 
 	if (error) {
 		if (affinity_mask)
@@ -365,7 +347,7 @@ int main(int argc, char **argv)
 		}
 
 	/* Restrict the main pid to the affinity specified by the user */
-	if (affinity_mask != NULL) {
+	if (affinity_mask) {
 		int res;
 
 		errno = 0;
@@ -400,21 +382,13 @@ int main(int argc, char **argv)
 			par[i].bufmsk = VALBUF_SIZE - 1;
 		}
 
-		switch (setaffinity) {
-		case AFFINITY_UNSPECIFIED:
-			cpu = -1;
-			break;
-		case AFFINITY_SPECIFIED:
+		if (affinity_mask)
 			cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask);
-			if (verbose)
-				printf("Thread %d using cpu %d.\n", i, cpu);
-			break;
-		case AFFINITY_USEALL:
+		else
 			cpu = cpu_for_thread_ua(i, max_cpus);
-			break;
-		default:
-			cpu = -1;
-		}
+
+		if (verbose)
+			printf("Thread %d using cpu %d.\n", i, cpu);
 
 		par[i].id = i;
 		par[i].prio = priority;
Signature · 1 line
2.30.0
#9 lore raw

PATCH v4 5/16 signaltest: Simplify --smp vs --affinity vs --threads argument logic

In reply to Daniel Wagner

Allow each command line only to update one variable and do the final decission at the end of the parsing step. With this the order of the command line is not important.

---
 src/signaltest/signaltest.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)
src/signaltest/signaltest.c +7 -16
index e19fc9a740a9..61420fa13347 100644
@@ -210,7 +210,6 @@ static struct bitmask *affinity_mask = NULL;
 static void process_options(int argc, char *argv[], unsigned int max_cpus)
 {
 	int error = 0;
-	int numa = 0;
 	int smp = 0;
 
 	for (;;) {
@@ -236,10 +235,6 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 			break;
 		switch (c) {
 		case 'a':
-			/* smp sets AFFINITY_USEALL in OPT_SMP */
-			if (smp)
-				break;
-			numa = 1;
 			if (optarg) {
 				parse_cpumask(optarg, max_cpus, &affinity_mask);
 			} else if (optind < argc &&
@@ -261,12 +256,7 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 		case 'm': lockall = 1; break;
 		case 'p': priority = atoi(optarg); break;
 		case 'q': quiet = 1; break;
-		case 'S':
-			if (numa)
-				fatal("numa and smp options are mutually exclusive\n");
-			smp = 1;
-			num_threads = -1; /* update after parsing */
-			break;
+		case 'S': smp = 1; break;
 		case 't': num_threads = atoi(optarg); break;
 		case 'v': verbose = 1; break;
 		}
@@ -278,15 +268,16 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 	if (priority < 0 || priority > 99)
 		error = 1;
 
-	if (num_threads == -1)
-		num_threads = get_available_cpus(affinity_mask);
+	if (smp) {
+		if (affinity_mask)
+			warn("--affinity overwrites smp mode\n");
+		else
+			num_threads = get_available_cpus(affinity_mask);
+	}
 
 	if (num_threads < 2)
 		error = 1;
 
-	if (smp && affinity_mask)
-		warn("-a ignored due to smp mode\n");
-
 	if (error) {
 		if (affinity_mask)
 			numa_bitmask_free(affinity_mask);
Signature · 1 line
2.30.0
#10 lore raw

PATCH v4 6/16 rt-numa: Remove unused definitions and numa_initialize()

In reply to Daniel Wagner

There is no user left of the AFFINITY_* enum. Remove them.

Also there is no need for numa_initialize() to prodect from being called several times. We can safely initialize libnuma at the begin of each program.

---
 src/cyclictest/cyclictest.c |  2 +-
 src/include/rt-numa.h       |  8 --------
 src/lib/rt-numa.c           | 15 ---------------
 src/signaltest/signaltest.c |  2 +-
 4 files changed, 2 insertions(+), 25 deletions(-)
src/cyclictest/cyclictest.c +1 -1
index b5cca3ae166b..3c6773c1dbb5 100644
@@ -1705,7 +1705,7 @@ int main(int argc, char **argv)
 	void *currstk;
 	size_t stksize;
 
-	if (numa_initialize())
+	if (numa_available() == -1)
 		fatal("Couldn't initialize libnuma");
 
 	process_options(argc, argv, max_cpus);
src/include/rt-numa.h +0 -8
index ca86a45dab3a..54f5c3a240e9 100644
@@ -4,14 +4,6 @@
 
 #include <numa.h>
 
-enum {
-	AFFINITY_UNSPECIFIED,
-	AFFINITY_SPECIFIED,
-	AFFINITY_USEALL
-};
-
-int numa_initialize(void);
-
 int get_available_cpus(struct bitmask *cpumask);
 int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask);
 int cpu_for_thread_ua(int thread_num, int max_cpus);
src/lib/rt-numa.c +0 -15
index 33fddba4358e..fa83eae61084 100644
@@ -13,21 +13,6 @@
 #include "error.h"
 #include "rt-numa.h"
 
-/* numa_available() must be called before any other calls to the numa library */
-int numa_initialize(void)
-{
-	static int is_initialized;
-
-	if (is_initialized == 1)
-		return 0;
-
-	if (numa_available() == -1)
-		return -1;
-
-	is_initialized = 1;
-	return 0;
-}
-
 int get_available_cpus(struct bitmask *cpumask)
 {
 	if (cpumask)
src/signaltest/signaltest.c +1 -1
index 61420fa13347..41ebb2c87a2f 100644
@@ -322,7 +322,7 @@ int main(int argc, char **argv)
 	int status, cpu;
 	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
-	if (numa_initialize())
+	if (numa_available() == -1)
 		fatal("Couldn't initialize libnuma");
 
 	process_options(argc, argv, max_cpus);
Signature · 1 line
2.30.0
#11 lore raw

PATCH v4 7/16 rt-numa: Add generic cpu_for_thread() helper

In reply to Daniel Wagner

Add an simpler wrapper which calls the right implementation depending on if the cpumask is valid or not.

---
 src/cyclictest/cyclictest.c |  6 +-----
 src/include/rt-numa.h       |  3 +--
 src/lib/rt-numa.c           | 13 ++++++++++---
 src/signaltest/signaltest.c |  6 +-----
 4 files changed, 13 insertions(+), 15 deletions(-)
src/cyclictest/cyclictest.c +1 -5
index 3c6773c1dbb5..4e30abbe6035 100644
@@ -1882,11 +1882,7 @@ 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)
-			cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask);
-		else
-			cpu = cpu_for_thread_ua(i, max_cpus);
-
+		cpu = cpu_for_thread(i, max_cpus, affinity_mask);
 		if (verbose)
 			printf("Thread %d using cpu %d.\n", i, cpu);
 
src/include/rt-numa.h +1 -2
index 54f5c3a240e9..189da3a804e1 100644
@@ -5,8 +5,7 @@
 #include <numa.h>
 
 int get_available_cpus(struct bitmask *cpumask);
-int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask);
-int cpu_for_thread_ua(int thread_num, int max_cpus);
+int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask);
 
 int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask);
 
src/lib/rt-numa.c +10 -3
index fa83eae61084..7e99eab60681 100644
@@ -21,7 +21,7 @@ int get_available_cpus(struct bitmask *cpumask)
 	return numa_num_task_cpus();
 }
 
-int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
+static int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
 {
 	unsigned int m, cpu, i, num_cpus;
 
@@ -44,8 +44,7 @@ int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
 	return 0;
 }
 
-/* cpu_for_thread AFFINITY_USEALL */
-int cpu_for_thread_ua(int thread_num, int max_cpus)
+static int cpu_for_thread_ua(int thread_num, int max_cpus)
 {
 	int res, num_cpus, i, m, cpu;
 	pthread_t thread;
@@ -73,6 +72,14 @@ int cpu_for_thread_ua(int thread_num, int max_cpus)
 	return 0;
 }
 
+int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask)
+{
+	if (cpumask)
+		return cpu_for_thread_sp(thread_num, max_cpus, cpumask);
+	else
+		return cpu_for_thread_ua(thread_num, max_cpus);
+}
+
 /*
  * After this function is called, affinity_mask is the intersection of
  * the user supplied affinity mask and the affinity mask from the run
src/signaltest/signaltest.c +1 -5
index 41ebb2c87a2f..2ea5e6b58946 100644
@@ -373,11 +373,7 @@ int main(int argc, char **argv)
 			par[i].bufmsk = VALBUF_SIZE - 1;
 		}
 
-		if (affinity_mask)
-			cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask);
-		else
-			cpu = cpu_for_thread_ua(i, max_cpus);
-
+		cpu = cpu_for_thread(i, max_cpus, affinity_mask);
 		if (verbose)
 			printf("Thread %d using cpu %d.\n", i, cpu);
 
Signature · 1 line
2.30.0
#12 lore raw

PATCH v4 8/16 rt-numa: Use mask size for iterator limit

In reply to Daniel Wagner

The bitmask structure knows its size use, thus use it as upper limit in the loop.

---
 src/lib/rt-numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/lib/rt-numa.c +2 -2
index 7e99eab60681..b1bbb8c8052c 100644
@@ -33,7 +33,7 @@ static int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpuma
 	m = thread_num % num_cpus;
 
 	/* there are num_cpus bits set, we want position of m'th one */
-	for (i = 0, cpu = 0; i < max_cpus; i++) {
+	for (i = 0, cpu = 0; i < cpumask->size; i++) {
 		if (numa_bitmask_isbitset(cpumask, i)) {
 			if (cpu == m)
 				return i;
@@ -97,7 +97,7 @@ static void use_current_cpuset(int max_cpus, struct bitmask *cpumask)
 	 * Clear bits that are not set in both the cpuset from the
 	 * environment, and in the user specified affinity.
 	 */
-	for (i = 0; i < max_cpus; i++) {
+	for (i = 0; i < cpumask->size; i++) {
 		if ((!numa_bitmask_isbitset(cpumask, i)) ||
 		    (!numa_bitmask_isbitset(curmask, i)))
 			numa_bitmask_clearbit(cpumask, i);
Signature · 1 line
2.30.0
#13 lore raw

PATCH v4 9/16 rt-numa: Remove max_cpus argument from parse_cpusmask

In reply to Daniel Wagner

Remove usused max_cpus argument from parse_cpumask().

---
 src/cyclictest/cyclictest.c | 4 ++--
 src/include/rt-numa.h       | 2 +-
 src/lib/rt-numa.c           | 6 +++---
 src/oslat/oslat.c           | 3 +--
 src/signaltest/signaltest.c | 4 ++--
 5 files changed, 9 insertions(+), 10 deletions(-)
src/cyclictest/cyclictest.c +2 -2
index 4e30abbe6035..acd456bd4c4d 100644
@@ -1008,12 +1008,12 @@ static void process_options(int argc, char *argv[], int max_cpus)
 		case 'a':
 		case OPT_AFFINITY:
 			if (optarg) {
-				parse_cpumask(optarg, max_cpus, &affinity_mask);
+				parse_cpumask(optarg, &affinity_mask);
 			} else if (optind < argc &&
 				   (atoi(argv[optind]) ||
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
-				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
+				parse_cpumask(argv[optind], &affinity_mask);
 			}
 			break;
 		case 'A':
src/include/rt-numa.h +1 -1
index 189da3a804e1..446ce54a6ba2 100644
@@ -7,6 +7,6 @@
 int get_available_cpus(struct bitmask *cpumask);
 int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask);
 
-int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask);
+int parse_cpumask(char *str, struct bitmask **cpumask);
 
 #endif
src/lib/rt-numa.c +3 -3
index b1bbb8c8052c..3a8441d5151c 100644
@@ -85,7 +85,7 @@ int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask)
  * the user supplied affinity mask and the affinity mask from the run
  * time environment
  */
-static void use_current_cpuset(int max_cpus, struct bitmask *cpumask)
+static void use_current_cpuset(struct bitmask *cpumask)
 {
 	struct bitmask *curmask;
 	int i;
@@ -106,7 +106,7 @@ static void use_current_cpuset(int max_cpus, struct bitmask *cpumask)
 	numa_bitmask_free(curmask);
 }
 
-int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask)
+int parse_cpumask(char *str, struct bitmask **cpumask)
 {
 	struct bitmask *mask;
 
@@ -120,7 +120,7 @@ int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask)
 		return 0;
 	}
 
-	use_current_cpuset(max_cpus, mask);
+	use_current_cpuset(mask);
 	*cpumask = mask;
 
 	return 0;
src/oslat/oslat.c +1 -2
index 5b7e0d5b5d5c..0811079d9f04 100644
@@ -716,7 +716,6 @@ int main(int argc, char *argv[])
 	struct thread *threads;
 	int i, n_cores;
 	struct bitmask *cpu_set = NULL;
-	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
 #ifdef FRC_MISSING
 	printf("This architecture is not yet supported. "
@@ -743,7 +742,7 @@ int main(int argc, char *argv[])
 
 	if (!g.cpu_list)
 		g.cpu_list = strdup("all");
-	if (parse_cpumask(g.cpu_list, max_cpus, &cpu_set))
+	if (parse_cpumask(g.cpu_list, &cpu_set))
 		exit(1);
 	n_cores = numa_bitmask_weight(cpu_set);
 
src/signaltest/signaltest.c +2 -2
index 2ea5e6b58946..0d189483753d 100644
@@ -236,12 +236,12 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 		switch (c) {
 		case 'a':
 			if (optarg) {
-				parse_cpumask(optarg, max_cpus, &affinity_mask);
+				parse_cpumask(optarg, &affinity_mask);
 			} else if (optind < argc &&
 				   (atoi(argv[optind]) ||
 				    argv[optind][0] == '0' ||
 				    argv[optind][0] == '!')) {
-				parse_cpumask(argv[optind], max_cpus, &affinity_mask);
+				parse_cpumask(argv[optind], &affinity_mask);
 			}
 
 			if (verbose)
Signature · 1 line
2.30.0
#14 lore raw

PATCH v4 10/16 signaltest: Remove unused max_cpus argument from process_options

In reply to Daniel Wagner

There is no use of this argument. Remove it.

---
 src/signaltest/signaltest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/signaltest/signaltest.c +2 -2
index 0d189483753d..3ca26fb373bb 100644
@@ -207,7 +207,7 @@ static int lockall;
 static struct bitmask *affinity_mask = NULL;
 
 /* Process commandline options */
-static void process_options(int argc, char *argv[], unsigned int max_cpus)
+static void process_options(int argc, char *argv[])
 {
 	int error = 0;
 	int smp = 0;
@@ -325,7 +325,7 @@ int main(int argc, char **argv)
 	if (numa_available() == -1)
 		fatal("Couldn't initialize libnuma");
 
-	process_options(argc, argv, max_cpus);
+	process_options(argc, argv);
 
 	if (check_privs())
 		exit(1);
Signature · 1 line
2.30.0
#15 lore raw

PATCH v4 11/16 cyclictest: Remove unused max_cpus argument from process_options

In reply to Daniel Wagner

There is no use of this argument. Remove it.

---
 src/cyclictest/cyclictest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +2 -2
index acd456bd4c4d..366b2aaaa9f8 100644
@@ -949,7 +949,7 @@ enum option_values {
 };
 
 /* Process commandline options */
-static void process_options(int argc, char *argv[], int max_cpus)
+static void process_options(int argc, char *argv[])
 {
 	int error = 0;
 	int smp = 0;
@@ -1708,7 +1708,7 @@ int main(int argc, char **argv)
 	if (numa_available() == -1)
 		fatal("Couldn't initialize libnuma");
 
-	process_options(argc, argv, max_cpus);
+	process_options(argc, argv);
 
 	if (check_privs())
 		exit(EXIT_FAILURE);
Signature · 1 line
2.30.0
#16 lore raw

PATCH v4 12/16 rt-numa: Use CPU_SETSIZE as upper loop limit

In reply to Daniel Wagner

The cpeset might not be dense, so user the CPU_SETSIZE as upper limit.

---
 src/lib/rt-numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/lib/rt-numa.c +1 -1
index 3a8441d5151c..45d4f1193d5f 100644
@@ -60,7 +60,7 @@ static int cpu_for_thread_ua(int thread_num, int max_cpus)
 	num_cpus = CPU_COUNT(&cpuset);
 	m = thread_num % num_cpus;
 
-	for (i = 0, cpu = 0; i < max_cpus; i++) {
+	for (i = 0, cpu = 0; i < CPU_SETSIZE; i++) {
 		if (CPU_ISSET(i, &cpuset)) {
 			if (cpu == m)
 				return i;
Signature · 1 line
2.30.0
#17 lore raw

PATCH v4 13/16 rt-numa: Remove used max_cpus argument from cpu_for_thread()

In reply to Daniel Wagner

There is no need to pass in the max_cpus anymore. Thus remove the argument.

---
 src/cyclictest/cyclictest.c |  2 +-
 src/include/rt-numa.h       |  2 +-
 src/lib/rt-numa.c           | 10 +++++-----
 src/signaltest/signaltest.c |  3 +--
 4 files changed, 8 insertions(+), 9 deletions(-)
src/cyclictest/cyclictest.c +1 -1
index 366b2aaaa9f8..7a0501031857 100644
@@ -1882,7 +1882,7 @@ int main(int argc, char **argv)
 		if (status != 0)
 			fatal("error from pthread_attr_init for thread %d: %s\n", i, strerror(status));
 
-		cpu = cpu_for_thread(i, max_cpus, affinity_mask);
+		cpu = cpu_for_thread(i, affinity_mask);
 		if (verbose)
 			printf("Thread %d using cpu %d.\n", i, cpu);
 
src/include/rt-numa.h +1 -1
index 446ce54a6ba2..405e57869735 100644
@@ -5,7 +5,7 @@
 #include <numa.h>
 
 int get_available_cpus(struct bitmask *cpumask);
-int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask);
+int cpu_for_thread(int thread_num, struct bitmask *cpumask);
 
 int parse_cpumask(char *str, struct bitmask **cpumask);
 
src/lib/rt-numa.c +5 -5
index 45d4f1193d5f..04f2e9adb4b1 100644
@@ -21,7 +21,7 @@ int get_available_cpus(struct bitmask *cpumask)
 	return numa_num_task_cpus();
 }
 
-static int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
+static int cpu_for_thread_sp(int thread_num, struct bitmask *cpumask)
 {
 	unsigned int m, cpu, i, num_cpus;
 
@@ -44,7 +44,7 @@ static int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpuma
 	return 0;
 }
 
-static int cpu_for_thread_ua(int thread_num, int max_cpus)
+static int cpu_for_thread_ua(int thread_num)
 {
 	int res, num_cpus, i, m, cpu;
 	pthread_t thread;
@@ -72,12 +72,12 @@ static int cpu_for_thread_ua(int thread_num, int max_cpus)
 	return 0;
 }
 
-int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask)
+int cpu_for_thread(int thread_num, struct bitmask *cpumask)
 {
 	if (cpumask)
-		return cpu_for_thread_sp(thread_num, max_cpus, cpumask);
+		return cpu_for_thread_sp(thread_num, cpumask);
 	else
-		return cpu_for_thread_ua(thread_num, max_cpus);
+		return cpu_for_thread_ua(thread_num);
 }
 
 /*
src/signaltest/signaltest.c +1 -2
index 3ca26fb373bb..5427db7f8d85 100644
@@ -320,7 +320,6 @@ int main(int argc, char **argv)
 	struct thread_stat *stat;
 	int i, ret = -1;
 	int status, cpu;
-	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
 	if (numa_available() == -1)
 		fatal("Couldn't initialize libnuma");
@@ -373,7 +372,7 @@ int main(int argc, char **argv)
 			par[i].bufmsk = VALBUF_SIZE - 1;
 		}
 
-		cpu = cpu_for_thread(i, max_cpus, affinity_mask);
+		cpu = cpu_for_thread(i, affinity_mask);
 		if (verbose)
 			printf("Thread %d using cpu %d.\n", i, cpu);
 
Signature · 1 line
2.30.0
#18 lore raw

PATCH v4 14/16 cyclictest: Remove max cpus used verbose information

In reply to Daniel Wagner

Since we always print the thread placement in verbose mode now, there is no need to print the max_cpus anymore. With the last of max_cpus gone, we can also remove the sysconf() call.

---
 src/cyclictest/cyclictest.c | 11 -----------
 1 file changed, 11 deletions(-)
src/cyclictest/cyclictest.c +0 -11
index 7a0501031857..8356786a80bb 100644
@@ -1697,8 +1697,6 @@ int main(int argc, char **argv)
 	int signum = SIGALRM;
 	int mode;
 	int cpu;
-	int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
-	int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	int i, ret = -1;
 	int status;
 	void *stack;
@@ -1713,11 +1711,6 @@ int main(int argc, char **argv)
 	if (check_privs())
 		exit(EXIT_FAILURE);
 
-	if (verbose) {
-		printf("Max CPUs = %d\n", max_cpus);
-		printf("Online CPUs = %d\n", online_cpus);
-	}
-
 	/* Restrict the main pid to the affinity specified by the user */
 	if (affinity_mask) {
 		int res;
@@ -1726,10 +1719,6 @@ int main(int argc, char **argv)
 		res = numa_sched_setaffinity(getpid(), affinity_mask);
 		if (res != 0)
 			warn("Couldn't setaffinity in main thread: %s\n", strerror(errno));
-
-		if (verbose)
-			printf("Using %u cpus.\n",
-				numa_bitmask_weight(affinity_mask));
 	}
 
 	if (trigger) {
Signature · 1 line
2.30.0
#19 lore raw

PATCH v4 15/16 cyclictest: Remove unecessary local variable

In reply to Daniel Wagner

The return value is not used, thus we can avoid the unussed local variable.

---
 src/cyclictest/cyclictest.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
src/cyclictest/cyclictest.c +2 -7
index 8356786a80bb..f912bcf82def 100644
@@ -1713,18 +1713,13 @@ int main(int argc, char **argv)
 
 	/* Restrict the main pid to the affinity specified by the user */
 	if (affinity_mask) {
-		int res;
-
 		errno = 0;
-		res = numa_sched_setaffinity(getpid(), affinity_mask);
-		if (res != 0)
+		if (numa_sched_setaffinity(getpid(), affinity_mask) != 0)
 			warn("Couldn't setaffinity in main thread: %s\n", strerror(errno));
 	}
 
 	if (trigger) {
-		int retval;
-		retval = trigger_init();
-		if (retval != 0) {
+		if (trigger_init() != 0) {
 			fprintf(stderr, "trigger_init() failed\n");
 			exit(EXIT_FAILURE);
 		}
Signature · 1 line
2.30.0
#20 lore raw

PATCH v4 16/16 rt-tests: Rename error.h to rt-error.h

In reply to Daniel Wagner

Avoid confusion with the system header called error.h.

---
 Makefile                            | 2 +-
 src/cyclictest/cyclictest.c         | 2 +-
 src/include/pip_stress.h            | 5 +++--
 src/include/{error.h => rt-error.h} | 0
 src/lib/{error.c => rt-error.c}     | 2 +-
 src/lib/rt-numa.c                   | 2 +-
 src/lib/rt-utils.c                  | 3 ++-
 src/oslat/oslat.c                   | 2 +-
 src/pi_tests/pi_stress.c            | 3 +--
 src/pmqtest/pmqtest.c               | 6 +++---
 src/ptsematest/ptsematest.c         | 6 +++---
 src/sched_deadline/cyclicdeadline.c | 6 +++---
 src/signaltest/signaltest.c         | 2 +-
 src/sigwaittest/sigwaittest.c       | 2 +-
 src/svsematest/svsematest.c         | 3 ++-
 15 files changed, 24 insertions(+), 22 deletions(-)
 rename src/include/{error.h => rt-error.h} (100%)
 rename src/lib/{error.c => rt-error.c} (98%)
Makefile +1 -1
index 636f1914a777..b17ac0957adc 100644
@@ -177,7 +177,7 @@ oslat: $(OBJDIR)/oslat.o $(OBJDIR)/librttest.a $(OBJDIR)/librttestnuma.a
 %.8.bz2: %.8
 	bzip2 -c $< > $@
 
-LIBOBJS =$(addprefix $(OBJDIR)/,error.o rt-get_cpu.o rt-sched.o rt-utils.o)
+LIBOBJS =$(addprefix $(OBJDIR)/,rt-error.o rt-get_cpu.o rt-sched.o rt-utils.o)
 $(OBJDIR)/librttest.a: $(LIBOBJS)
 	$(AR) rcs $@ $^
 
src/cyclictest/cyclictest.c +1 -1
index f912bcf82def..c4b2369bee6b 100644
@@ -36,7 +36,7 @@
 
 #include "rt-utils.h"
 #include "rt-numa.h"
-#include "error.h"
+#include "rt-error.h"
 
 #include <bionic.h>
 
src/include/pip_stress.h +3 -2
index ee8b545ab117..f03aaf397897 100644
@@ -14,8 +14,9 @@
 #include <sys/wait.h>
 #include <signal.h>
 #include <sched.h>
-#include <rt-utils.h>
-#include "error.h"
+
+#include "rt-utils.h"
+#include "rt-error.h"
 
 void low(pid_t pid);	/* low priority process */
 void medium(void);	/* medium priority process */
src/include/rt-error.h renamed from src/include/error.h +0 -0
similarity index 100%
rename from src/include/error.h
rename to src/include/rt-error.h
src/lib/rt-error.c renamed from src/lib/error.c +1 -1
similarity index 98%
rename from src/lib/error.c
rename to src/lib/rt-error.c
index 4434a842da17..616f70b044e0 100644
@@ -5,7 +5,7 @@
  * error routines, similar to those found in
  * Advanced Programming in the UNIX Environment 2nd ed.
  */
-#include "error.h"
+#include "rt-error.h"
 
 /* Print an error message, plus a message for err and exit with error err */
 void err_exit(int err, char *fmt, ...)
src/lib/rt-numa.c +1 -1
index 04f2e9adb4b1..4a0865715141 100644
@@ -10,7 +10,7 @@
 #include <sched.h>
 #include <pthread.h>
 
-#include "error.h"
+#include "rt-error.h"
 #include "rt-numa.h"
 
 int get_available_cpus(struct bitmask *cpumask)
src/lib/rt-utils.c +2 -1
index 2d68d62cd875..321a11b1172d 100644
@@ -20,9 +20,10 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/syscall.h> /* For SYS_gettid definitions */
+
 #include "rt-utils.h"
 #include "rt-sched.h"
-#include "error.h"
+#include "rt-error.h"
 
 #define  TRACEBUFSIZ  1024
 
src/oslat/oslat.c +1 -1
index 0811079d9f04..9e6f70600830 100644
@@ -43,7 +43,7 @@
 
 #include "rt-utils.h"
 #include "rt-numa.h"
-#include "error.h"
+#include "rt-error.h"
 
 #ifdef __GNUC__
 # define atomic_inc(ptr)   __sync_add_and_fetch((ptr), 1)
src/pi_tests/pi_stress.c +1 -2
index 538d12c975aa..49f89b7b0136 100644
@@ -47,8 +47,7 @@
 
 #include "rt-sched.h"
 #include "rt-utils.h"
-
-#include "error.h"
+#include "rt-error.h"
 
 /* test timeout */
 #define TIMEOUT 2
src/pmqtest/pmqtest.c +3 -3
index 5f7a24d55db6..349b47741003 100644
@@ -21,11 +21,11 @@
 #include <linux/unistd.h>
 #include <utmpx.h>
 #include <mqueue.h>
+#include <pthread.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
-
-#include <pthread.h>
+#include "rt-error.h"
 
 #define SYNCMQ_NAME "/syncmsg%d"
 #define TESTMQ_NAME "/testmsg%d"
src/ptsematest/ptsematest.c +3 -3
index f8f075591f4b..7d4ca97773d6 100644
@@ -19,11 +19,11 @@
 #include <sys/mman.h>
 #include <linux/unistd.h>
 #include <utmpx.h>
+#include <pthread.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
-
-#include <pthread.h>
+#include "rt-error.h"
 
 enum {
 	AFFINITY_UNSPECIFIED,
src/sched_deadline/cyclicdeadline.c +3 -3
index 6dcfd6074085..71cde5781499 100644
@@ -30,9 +30,9 @@
 #include <linux/unistd.h>
 #include <linux/magic.h>
 
-#include <rt-utils.h>
-#include <rt-sched.h>
-#include <error.h>
+#include "rt-utils.h"
+#include "rt-sched.h"
+#include "rt-error.h"
 
 #define _STR(x) #x
 #define STR(x) _STR(x)
src/signaltest/signaltest.c +1 -1
index 5427db7f8d85..c34bc994d886 100644
@@ -31,7 +31,7 @@
 #include <sys/time.h>
 #include <sys/mman.h>
 
-#include "error.h"
+#include "rt-error.h"
 #include "rt-utils.h"
 #include "rt-numa.h"
 
src/sigwaittest/sigwaittest.c +1 -1
index 7e287bd2424f..f10c24914d4a 100644
@@ -42,7 +42,7 @@
 
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
+#include "rt-error.h"
 
 enum {
 	AFFINITY_UNSPECIFIED,
src/svsematest/svsematest.c +2 -1
index 7388efb3f488..7a298e0dea8c 100644
@@ -28,9 +28,10 @@
 #include <sys/sem.h>
 #include <sys/time.h>
 #include <sys/mman.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
+#include "rt-error.h"
 
 #define SEM_WAIT_FOR_RECEIVER 0
 #define SEM_WAIT_FOR_SENDER 1
Signature · 1 line
2.30.0
#21 lore raw

Re: [PATCH rt-tests v4 16/16] rt-tests: Rename error.h to rt-error.h

Quoted 242 lines · Daniel Wagner

Avoid confusion with the system header called error.h.

---
 Makefile                            | 2 +-
 src/cyclictest/cyclictest.c         | 2 +-
 src/include/pip_stress.h            | 5 +++--
 src/include/{error.h => rt-error.h} | 0
 src/lib/{error.c => rt-error.c}     | 2 +-
 src/lib/rt-numa.c                   | 2 +-
 src/lib/rt-utils.c                  | 3 ++-
 src/oslat/oslat.c                   | 2 +-
 src/pi_tests/pi_stress.c            | 3 +--
 src/pmqtest/pmqtest.c               | 6 +++---
 src/ptsematest/ptsematest.c         | 6 +++---
 src/sched_deadline/cyclicdeadline.c | 6 +++---
 src/signaltest/signaltest.c         | 2 +-
 src/sigwaittest/sigwaittest.c       | 2 +-
 src/svsematest/svsematest.c         | 3 ++-
 15 files changed, 24 insertions(+), 22 deletions(-)
 rename src/include/{error.h => rt-error.h} (100%)
 rename src/lib/{error.c => rt-error.c} (98%)
Makefile +1 -1
index 636f1914a777..b17ac0957adc 100644
@@ -177,7 +177,7 @@ oslat: $(OBJDIR)/oslat.o $(OBJDIR)/librttest.a $(OBJDIR)/librttestnuma.a
 %.8.bz2: %.8
 	bzip2 -c $< > $@
 
-LIBOBJS =$(addprefix $(OBJDIR)/,error.o rt-get_cpu.o rt-sched.o rt-utils.o)
+LIBOBJS =$(addprefix $(OBJDIR)/,rt-error.o rt-get_cpu.o rt-sched.o rt-utils.o)
 $(OBJDIR)/librttest.a: $(LIBOBJS)
 	$(AR) rcs $@ $^
 
src/cyclictest/cyclictest.c +1 -1
index f912bcf82def..c4b2369bee6b 100644
@@ -36,7 +36,7 @@
 
 #include "rt-utils.h"
 #include "rt-numa.h"
-#include "error.h"
+#include "rt-error.h"
 
 #include <bionic.h>
 
src/include/pip_stress.h +3 -2
index ee8b545ab117..f03aaf397897 100644
@@ -14,8 +14,9 @@
 #include <sys/wait.h>
 #include <signal.h>
 #include <sched.h>
-#include <rt-utils.h>
-#include "error.h"
+
+#include "rt-utils.h"
+#include "rt-error.h"
 
 void low(pid_t pid);	/* low priority process */
 void medium(void);	/* medium priority process */
src/include/rt-error.h renamed from src/include/error.h +0 -0
similarity index 100%
rename from src/include/error.h
rename to src/include/rt-error.h
src/lib/rt-error.c renamed from src/lib/error.c +1 -1
similarity index 98%
rename from src/lib/error.c
rename to src/lib/rt-error.c
index 4434a842da17..616f70b044e0 100644
@@ -5,7 +5,7 @@
  * error routines, similar to those found in
  * Advanced Programming in the UNIX Environment 2nd ed.
  */
-#include "error.h"
+#include "rt-error.h"
 
 /* Print an error message, plus a message for err and exit with error err */
 void err_exit(int err, char *fmt, ...)
src/lib/rt-numa.c +1 -1
index 04f2e9adb4b1..4a0865715141 100644
@@ -10,7 +10,7 @@
 #include <sched.h>
 #include <pthread.h>
 
-#include "error.h"
+#include "rt-error.h"
 #include "rt-numa.h"
 
 int get_available_cpus(struct bitmask *cpumask)
src/lib/rt-utils.c +2 -1
index 2d68d62cd875..321a11b1172d 100644
@@ -20,9 +20,10 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/syscall.h> /* For SYS_gettid definitions */
+
 #include "rt-utils.h"
 #include "rt-sched.h"
-#include "error.h"
+#include "rt-error.h"
 
 #define  TRACEBUFSIZ  1024
 
src/oslat/oslat.c +1 -1
index 0811079d9f04..9e6f70600830 100644
@@ -43,7 +43,7 @@
 
 #include "rt-utils.h"
 #include "rt-numa.h"
-#include "error.h"
+#include "rt-error.h"
 
 #ifdef __GNUC__
 # define atomic_inc(ptr)   __sync_add_and_fetch((ptr), 1)
src/pi_tests/pi_stress.c +1 -2
index 538d12c975aa..49f89b7b0136 100644
@@ -47,8 +47,7 @@
 
 #include "rt-sched.h"
 #include "rt-utils.h"
-
-#include "error.h"
+#include "rt-error.h"
 
 /* test timeout */
 #define TIMEOUT 2
src/pmqtest/pmqtest.c +3 -3
index 5f7a24d55db6..349b47741003 100644
@@ -21,11 +21,11 @@
 #include <linux/unistd.h>
 #include <utmpx.h>
 #include <mqueue.h>
+#include <pthread.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
-
-#include <pthread.h>
+#include "rt-error.h"
 
 #define SYNCMQ_NAME "/syncmsg%d"
 #define TESTMQ_NAME "/testmsg%d"
src/ptsematest/ptsematest.c +3 -3
index f8f075591f4b..7d4ca97773d6 100644
@@ -19,11 +19,11 @@
 #include <sys/mman.h>
 #include <linux/unistd.h>
 #include <utmpx.h>
+#include <pthread.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
-
-#include <pthread.h>
+#include "rt-error.h"
 
 enum {
 	AFFINITY_UNSPECIFIED,
src/sched_deadline/cyclicdeadline.c +3 -3
index 6dcfd6074085..71cde5781499 100644
@@ -30,9 +30,9 @@
 #include <linux/unistd.h>
 #include <linux/magic.h>
 
-#include <rt-utils.h>
-#include <rt-sched.h>
-#include <error.h>
+#include "rt-utils.h"
+#include "rt-sched.h"
+#include "rt-error.h"
 
 #define _STR(x) #x
 #define STR(x) _STR(x)
src/signaltest/signaltest.c +1 -1
index 5427db7f8d85..c34bc994d886 100644
@@ -31,7 +31,7 @@
 #include <sys/time.h>
 #include <sys/mman.h>
 
-#include "error.h"
+#include "rt-error.h"
 #include "rt-utils.h"
 #include "rt-numa.h"
 
src/sigwaittest/sigwaittest.c +1 -1
index 7e287bd2424f..f10c24914d4a 100644
@@ -42,7 +42,7 @@
 
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
+#include "rt-error.h"
 
 enum {
 	AFFINITY_UNSPECIFIED,
src/svsematest/svsematest.c +2 -1
index 7388efb3f488..7a298e0dea8c 100644
@@ -28,9 +28,10 @@
 #include <sys/sem.h>
 #include <sys/time.h>
 #include <sys/mman.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-#include "error.h"
+#include "rt-error.h"
 
 #define SEM_WAIT_FOR_RECEIVER 0
 #define SEM_WAIT_FOR_SENDER 1
Signature · 1 line
2.30.0

- Fixed a conflict in cyclictest.c
- Fixed up rt_numa.h