From: John Kacur <jkacur@redhat.com>
To: Clark Williams <williams@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
rt-users <linux-rt-users@vger.kernel.org>,
"Nikita V. Youshchenko" <yoush@cs.msu.su>,
John Kacur <jkacur@redhat.com>
Subject: [PATCH 2/2] rt-tests: Make cyclic test compilable for non-numa systems.
Date: Wed, 20 Jan 2010 16:36:24 +0100 [thread overview]
Message-ID: <1264001784-11965-3-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1264001784-11965-1-git-send-email-jkacur@redhat.com>
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@redhat.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
prev parent reply other threads:[~2010-01-20 15:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-20 15:36 [rt-tests] [PATCH 0/2] Make numa a compiletime option John Kacur
2010-01-20 15:36 ` [PATCH 1/2] rt-tests: Makefile: Add NUMA compile option John Kacur
2010-01-20 15:36 ` John Kacur [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264001784-11965-3-git-send-email-jkacur@redhat.com \
--to=jkacur@redhat.com \
--cc=C.Emde@osadl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
--cc=yoush@cs.msu.su \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).