* [PATCH 2/4] rt-tests: cyclictest: Remove support for compiling without NUMA
2020-03-04 21:55 [PATCH 1/4] rt-tests: cyclictest: Remove HAVE_PARSE_CPUSTRING_ALL John Kacur
@ 2020-03-04 21:55 ` John Kacur
2020-03-04 21:55 ` [PATCH 3/4] rt-tests: cyclictest: Make the affinity mask apply to the main thread too John Kacur
2020-03-04 21:55 ` [PATCH 4/4] rt-tests: cyclictest: Fix -t without a user specified [NUM] John Kacur
2 siblings, 0 replies; 4+ messages in thread
From: John Kacur @ 2020-03-04 21:55 UTC (permalink / raw)
To: rt-users; +Cc: Clark Williams, John Kacur
We announced way back in 2015 that compiling without the NUMA libs was
no-longer supported, but we left the bits in there for you to do it
anyway.
Since this is not supported, and is broken now anyway, let's remove the
cruft.
Of course running on non-NUMA machines should still work fine.
Signed-off-by: John Kacur <jkacur@redhat.com>
---
Makefile | 17 +++-------
src/cyclictest/rt_numa.h | 67 ----------------------------------------
2 files changed, 4 insertions(+), 80 deletions(-)
diff --git a/Makefile b/Makefile
index 186eccb1c882..1475007d7bb4 100644
--- a/Makefile
+++ b/Makefile
@@ -76,19 +76,10 @@ ostype := $(lastword $(subst -, ,$(dumpmachine)))
machinetype := $(shell echo $(dumpmachine)| \
sed -e 's/-.*//' -e 's/i.86/i386/' -e 's/mips.*/mips/' -e 's/ppc.*/powerpc/')
-# The default is to assume you have libnuma installed, which is fine to do
-# even on non-numa machines. If you don't want to install the numa libs, for
-# example, they might not be available in an embedded environment, then
-# compile with
-# make NUMA=0
-ifneq ($(filter x86_64 i386 ia64 mips powerpc,$(machinetype)),)
-NUMA := 1
-endif
-
-ifeq ($(NUMA),1)
- CFLAGS += -DNUMA
- NUMA_LIBS = -lnuma
-endif
+# You have to have libnuma installed, which is fine to do even if you are
+# running on non-numa machines
+CFLAGS += -DNUMA
+NUMA_LIBS = -lnuma
include src/arch/android/Makefile
diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h
index 466f0b68f801..46690941e0a6 100644
--- a/src/cyclictest/rt_numa.h
+++ b/src/cyclictest/rt_numa.h
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* A numa library for cyclictest.
- * The functions here are designed to work whether cyclictest has been
- * compiled with numa support or not.
*
* (C) 2010 John Kacur <jkacur@redhat.com>
* (C) 2010 Clark Williams <williams@redhat.com>
@@ -17,7 +15,6 @@
static int numa = 0;
-#ifdef NUMA
#include <numa.h>
static void *
@@ -86,70 +83,6 @@ static inline void rt_bitmask_free(struct bitmask *mask)
numa_bitmask_free(mask);
}
-
-#else /* ! NUMA */
-
-struct bitmask {
- unsigned long size; /* number of bits in the map */
- unsigned long *maskp;
-};
-#define BITS_PER_LONG (8*sizeof(long))
-
-static inline void *threadalloc(size_t size, int n) { return malloc(size); }
-static inline void threadfree(void *ptr, size_t s, int n) { free(ptr); }
-static inline void rt_numa_set_numa_run_on_node(int n, int c) { }
-static inline int rt_numa_numa_node_of_cpu(int cpu) { return -1; }
-static void *rt_numa_numa_alloc_onnode(size_t s, int n, int c) { return NULL; }
-
-/*
- * Map legacy CPU affinity behavior onto bit mask infrastructure
- */
-static inline unsigned int rt_numa_bitmask_isbitset( const struct bitmask *mask,
- unsigned long i)
-{
- long bit = mask->maskp[i/BITS_PER_LONG] & (1<<(i % BITS_PER_LONG));
- return (bit != 0);
-}
-
-static inline struct bitmask* rt_numa_parse_cpustring(const char* s,
- int max_cpus)
-{
- int cpu;
- struct bitmask *mask = NULL;
- cpu = atoi(s);
- if (0 <= cpu && cpu < max_cpus) {
- mask = malloc(sizeof(*mask));
- if (mask) {
- /* Round up to integral number of longs to contain
- * max_cpus bits */
- int nlongs = (max_cpus+BITS_PER_LONG-1)/BITS_PER_LONG;
-
- mask->maskp = calloc(nlongs, sizeof(unsigned long));
- if (mask->maskp) {
- mask->maskp[cpu/BITS_PER_LONG] |=
- (1UL << (cpu % BITS_PER_LONG));
- mask->size = max_cpus;
- } else {
- free(mask);
- mask = NULL;
- }
- }
- }
- return mask;
-}
-
-static inline void rt_bitmask_free(struct bitmask *mask)
-{
- free(mask->maskp);
- free(mask);
-}
-
-#endif /* NUMA */
-
-/*
- * Any behavioral differences above are transparent to these functions
- */
-
/** Returns number of bits set in mask. */
static inline unsigned int rt_numa_bitmask_count(const struct bitmask *mask)
{
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/4] rt-tests: cyclictest: Make the affinity mask apply to the main thread too
2020-03-04 21:55 [PATCH 1/4] rt-tests: cyclictest: Remove HAVE_PARSE_CPUSTRING_ALL John Kacur
2020-03-04 21:55 ` [PATCH 2/4] rt-tests: cyclictest: Remove support for compiling without NUMA John Kacur
@ 2020-03-04 21:55 ` John Kacur
2020-03-04 21:55 ` [PATCH 4/4] rt-tests: cyclictest: Fix -t without a user specified [NUM] John Kacur
2 siblings, 0 replies; 4+ messages in thread
From: John Kacur @ 2020-03-04 21:55 UTC (permalink / raw)
To: rt-users; +Cc: Clark Williams, John Kacur
There is no reason that the main thread should be treated differently,
so apply the affinity setting there too.
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/cyclictest/cyclictest.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 13d2b1722890..f8df4c6954ad 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1992,6 +1992,17 @@ int main(int argc, char **argv)
if (verbose)
printf("Max CPUs = %d\n", max_cpus);
+ /* Restrict the main pid to the affinity specified by the user */
+ if (affinity_mask != NULL) {
+ int res;
+
+ errno = 0;
+ res = numa_sched_setaffinity(getpid(), affinity_mask);
+ if (res != 0) {
+ warn("Couldn't setaffinity in main thread: %s\n", strerror(errno));
+ }
+ }
+
if (trigger) {
int retval;
retval = trigger_init();
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4/4] rt-tests: cyclictest: Fix -t without a user specified [NUM]
2020-03-04 21:55 [PATCH 1/4] rt-tests: cyclictest: Remove HAVE_PARSE_CPUSTRING_ALL John Kacur
2020-03-04 21:55 ` [PATCH 2/4] rt-tests: cyclictest: Remove support for compiling without NUMA John Kacur
2020-03-04 21:55 ` [PATCH 3/4] rt-tests: cyclictest: Make the affinity mask apply to the main thread too John Kacur
@ 2020-03-04 21:55 ` John Kacur
2 siblings, 0 replies; 4+ messages in thread
From: John Kacur @ 2020-03-04 21:55 UTC (permalink / raw)
To: rt-users; +Cc: Clark Williams, John Kacur
Fix -t without a specified [NUM] to run the same number of threads as
available processors.
Currently it runs the same number of threads as cpus on a system.
However, if cyclictest is contrained to run on a smaller set of cpus
either because of a container or a user specified affinity or a
combination of the two, then the actual number of available cpus is
smaller. -t should reflect that.
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/cyclictest/cyclictest.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index f8df4c6954ad..c5f1fd46567a 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1040,6 +1040,35 @@ static unsigned int is_cpumask_zero(const struct bitmask *mask)
return (rt_numa_bitmask_count(mask) == 0);
}
+/* Get available cpus according to getaffinity or according to the
+ * intersection of getaffinity and the user specified affinity
+ * in the case of AFFINITY_SPECIFIED, the function has to be called
+ * after the call to parse_cpumask made in process_options()
+ */
+static int get_available_cpus(void)
+{
+ int num_cpus = 0;
+ int res;
+ pthread_t thread;
+ cpu_set_t cpuset;
+
+
+ if (affinity_mask != NULL) {
+ num_cpus = rt_numa_bitmask_count(affinity_mask);
+ } else {
+ CPU_ZERO(&cpuset);
+ thread = pthread_self();
+ res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+ if (res != 0) {
+ fatal("pthread_getaffinity_np failed: %s\n", strerror(res));
+ }
+ num_cpus = CPU_COUNT(&cpuset);
+ }
+
+ return num_cpus;
+
+}
+
/* cpu_for_thread AFFINITY_SPECIFIED */
static int cpu_for_thread_sp(int thread_num, int max_cpus)
{
@@ -1358,7 +1387,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
if (numa)
fatal("numa and smp options are mutually exclusive\n");
smp = 1;
- num_threads = max_cpus;
+ num_threads = -1; /* update after parsing */
setaffinity = AFFINITY_USEALL;
break;
case 't':
@@ -1372,7 +1401,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
else if (optind<argc && atoi(argv[optind]))
num_threads = atoi(argv[optind]);
else
- num_threads = max_cpus;
+ num_threads = -1; /* update after parsing */
break;
case OPT_TRIGGER:
trigger = atoi(optarg);
@@ -1485,6 +1514,9 @@ static void process_options (int argc, char *argv[], int max_cpus)
if (priority < 0 || priority > 99)
error = 1;
+ if (num_threads == -1)
+ num_threads = get_available_cpus();
+
if (priospread && priority == 0) {
fprintf(stderr, "defaulting realtime priority to %d\n",
num_threads+1);
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread