lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1264001784-11965-3-git-send-email-jkacur@redhat.com>
Date:	Wed, 20 Jan 2010 16:36:24 +0100
From:	John Kacur <jkacur@...hat.com>
To:	Clark Williams <williams@...hat.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Carsten Emde <C.Emde@...dl.org>
Cc:	lkml <linux-kernel@...r.kernel.org>,
	rt-users <linux-rt-users@...r.kernel.org>,
	"Nikita V. Youshchenko" <yoush@...msu.su>,
	John Kacur <jkacur@...hat.com>
Subject: [PATCH 2/2] rt-tests: Make cyclic test compilable for non-numa systems.

Runtime tests are not sufficient, cyclic tests needs to be compilable
on non-numa systems.

This separates numa functionality into rt_numa.h

Signed-off-by: John Kacur <jkacur@...hat.com>
---
 src/cyclictest/cyclictest.c |   46 +++++++-------------------
 src/cyclictest/rt_numa.h    |   74 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 33 deletions(-)
 create mode 100644 src/cyclictest/rt_numa.h

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index c1b5c7f..cff414f 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -31,7 +31,7 @@
 #include <sys/time.h>
 #include <sys/utsname.h>
 #include <sys/mman.h>
-#include <numa.h>
+#include "rt_numa.h"
 
 #include "rt-utils.h"
 
@@ -542,11 +542,8 @@ void *timerthread(void *param)
 	cpu_set_t mask;
 
 	/* if we're running in numa mode, set our memory node */
-	if (par->node != -1) {
-		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->node != -1)
+		rt_numa_set_numa_run_on_node(par->node, par->cpu);
 
 	if (par->cpu != -1) {
 		CPU_ZERO(&mask);
@@ -804,7 +801,6 @@ static int interval = 1000;
 static int distance = 500;
 static int affinity = 0;
 static int smp = 0;
-static int numa = 0;
 
 enum {
 	AFFINITY_UNSPECIFIED,
@@ -987,10 +983,15 @@ static void process_options (int argc, char *argv[])
 		case 'U':  /* NUMA testing */
 			if (smp)
 				fatal("numa and smp options are mutually exclusive\n");
+#ifdef NUMA
 			numa = 1;
 			num_threads = max_cpus;
 			setaffinity = AFFINITY_USEALL;
 			use_nanosleep = MODE_CLOCK_NANOSLEEP;
+#else
+			warn("cyclicteset was not built with the numa option\n");
+			warn("ignoring --numa or -U\n");
+#endif
 			break;
 		case '?': display_help(0); break;
 		}
@@ -1178,24 +1179,6 @@ static void print_stat(struct thread_param *par, int index, int verbose)
 	}
 }
 
-void *
-threadalloc(size_t size, int node)
-{
-	if (node == -1)
-		return malloc(size);
-	return numa_alloc_onnode(size, node);
-}
-
-void
-threadfree(void *ptr, size_t size, int node)
-{
-	if (node == -1)
-		free(ptr);
-	else
-		numa_free(ptr, size);
-}			
-
-
 int main(int argc, char **argv)
 {
 	sigset_t sigset;
@@ -1212,8 +1195,8 @@ int main(int argc, char **argv)
 	if (check_privs())
 		exit(EXIT_FAILURE);
 
-	if (numa && numa_available() == -1)
-		fatal("--numa specified and numa functions not available\n");
+	/* Checks if numa is on, program exits if numa on but not available */
+	numa_on_and_available();
 
 	/* lock all memory (prevent paging) */
 	if (lockall)
@@ -1266,8 +1249,7 @@ int main(int argc, char **argv)
 			size_t stksize;
 
 			/* find the memory node associated with the cpu i */
-			if ((node = numa_node_of_cpu(i)) == -1)
-				fatal("invalid cpu passed to numa_node_of_cpu(%d)\n");
+			node = rt_numa_numa_node_of_cpu(i);
 
 			/* get the stack size set for for this thread */
 			if (pthread_attr_getstack(&attr, &currstk, &stksize))
@@ -1277,10 +1259,8 @@ int main(int argc, char **argv)
 			if (stksize == 0)
 				stksize = PTHREAD_STACK_MIN * 2;
 
-			/*  allocate memory for a stack on the appropriate node */
-			if ((stack = numa_alloc_onnode(stksize, node)) == NULL)
-				fatal("failed to allocate %d bytes on node %d for thread %d\n",
-				      stksize, node, i);
+			/*  allocate memory for a stack on appropriate node */
+			stack = rt_numa_numa_alloc_onnode(stksize, node, i);
 
 			/* set the thread's stack */
 			if (pthread_attr_setstack(&attr, stack, stksize))
diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h
new file mode 100644
index 0000000..1348163
--- /dev/null
+++ b/src/cyclictest/rt_numa.h
@@ -0,0 +1,74 @@
+#ifndef _RT_NUMA_H
+#define _RT_NUMA_H
+
+#include "rt-utils.h"
+
+static int numa = 0;
+
+#ifdef NUMA
+#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 numa_on_and_available()
+{
+	if (numa && numa_available() == -1)
+		fatal("--numa specified and numa functions not available.\n");
+}
+
+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 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;
+}
+
+#else
+
+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 void numa_on_and_available() { };
+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; }
+
+#endif	/* NUMA */
+
+#endif	/* _RT_NUMA_H */
-- 
1.6.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ