diff mbox series

[rt-tests,v4,07/16] rt-numa: Add generic cpu_for_thread() helper

Message ID 20210210133450.6991-8-dwagner@suse.de
State New
Headers show
Series rt-numa.h cleanups | expand

Commit Message

Daniel Wagner Feb. 10, 2021, 1:34 p.m. UTC
Add an simpler wrapper which calls the right implementation depending
on if the cpumask is valid or not.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 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(-)
diff mbox series

Patch

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 3c6773c1dbb5..4e30abbe6035 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -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);
 
diff --git a/src/include/rt-numa.h b/src/include/rt-numa.h
index 54f5c3a240e9..189da3a804e1 100644
--- a/src/include/rt-numa.h
+++ b/src/include/rt-numa.h
@@ -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);
 
diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c
index fa83eae61084..7e99eab60681 100644
--- a/src/lib/rt-numa.c
+++ b/src/lib/rt-numa.c
@@ -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
diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c
index 41ebb2c87a2f..2ea5e6b58946 100644
--- a/src/signaltest/signaltest.c
+++ b/src/signaltest/signaltest.c
@@ -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);