This set of patches are mostly clean-up to our new rt_numa.h file.
We need to add a copyright notice in every file for some distributions.
This also creates some changes to simplify and clean-up
the differences between the code for the older LIBNUMA_API_VERSION and the
newer ones. (or at least I hope you will think so).
Finally there is a change to automatically generate dependencies for the
Makefile.
John Kacur (5):
rt-tests: Add header including copyright notice to rt_numa.h
rt-tests: Separate the #ifdef LIBNUMA_API_VERSION functions.
rt-tests: Remove the ret variable, the end label and the goto.
rt-tests: Fix some style problems, such as spaces instead of tabs.
rt-tests: Automatically generate dependencies.
Makefile | 20 ++++++++++++---
src/cyclictest/rt_numa.h | 58 ++++++++++++++++++++++++++++-----------------
2 files changed, 52 insertions(+), 26 deletions(-)
From: John Kacur <[email protected]>
Fix some style problems, such as spaces instead of tabs, trailing spaces,
spaces required before }
Signed-off-by: John Kacur <[email protected]>
---
src/cyclictest/rt_numa.h | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h
index ac2aca2..73ef3d8 100644
--- a/src/cyclictest/rt_numa.h
+++ b/src/cyclictest/rt_numa.h
@@ -40,7 +40,7 @@ threadfree(void *ptr, size_t size, int node)
free(ptr);
else
numa_free(ptr, size);
-}
+}
static void rt_numa_set_numa_run_on_node(int node, int cpu)
{
@@ -73,29 +73,29 @@ static int rt_numa_numa_node_of_cpu(int cpu)
static int rt_numa_numa_node_of_cpu(int cpu)
{
unsigned char cpumask[16];
- int node, idx, bit;
+ int node, idx, bit;
int max_node, max_cpus;
max_node = numa_max_node();
max_cpus = sysconf(_SC_NPROCESSORS_CONF);
- if (cpu > max_cpus) {
- errno = EINVAL;
- return -1;
- }
+ if (cpu > max_cpus) {
+ errno = EINVAL;
+ return -1;
+ }
/* calculate bitmask index and relative bit position of cpu */
idx = cpu / 8;
bit = cpu % 8;
- for (node = 0; node <= max_node; node++) {
+ for (node = 0; node <= max_node; node++) {
if (numa_node_to_cpus(node, (void *) cpumask, sizeof(cpumask)))
return -1;
if (cpumask[idx] & (1<<bit))
return node;
- }
- errno = EINVAL;
+ }
+ errno = EINVAL;
return -1;
}
@@ -114,10 +114,10 @@ static void *rt_numa_numa_alloc_onnode(size_t size, int node, int cpu)
#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 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 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 */
--
1.6.6
Automatically generate dependencies. This will tell the make file that
cyclictest is dependent on rt_numa.h for example, and that if a change
is made there, then cyclictest needs to be remade.
Signed-off-by: John Kacur <[email protected]>
---
Makefile | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index 6156c03..4be0838 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,10 @@
VERSION_STRING = 0.63
-TARGETS = cyclictest signaltest pi_stress \
- rt-migrate-test ptsematest sigwaittest svsematest \
- sendme pip
+sources = cyclictest.c signaltest.c pi_stress.c rt-migrate-test.c \
+ ptsematest.c sigwaittest.c svsematest.c sendme.c pip.c
+
+TARGETS = $(sources:.c=)
+
LIBS = -lrt -lpthread
EXTRA_LIBS ?= -ldl # for get_cpu
DESTDIR ?=
@@ -39,9 +41,19 @@ VPATH += src/lib
%.o: %.c
$(CC) -D VERSION_STRING=$(VERSION_STRING) -c $< $(CFLAGS)
+# Pattern rule to generate dependency files from .c files
+%.d: %.c
+ @set -e; rm -f $@; \
+ $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
.PHONY: all
all: $(TARGETS) hwlatdetect
+# Include dependency files, automatically generate them if needed.
+-include $(sources:.c=.d)
+
cyclictest: cyclictest.o rt-utils.o
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(NUMA_LIBS)
@@ -73,7 +85,7 @@ sendme: sendme.o rt-utils.o rt-get_cpu.o
pip: pip.o error.o rt-utils.o
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-CLEANUP = $(TARGETS) *.o .depend *.*~ *.orig *.rej rt-tests.spec
+CLEANUP = $(TARGETS) *.o .depend *.*~ *.orig *.rej rt-tests.spec *.d
CLEANUP += $(if $(wildcard .git), ChangeLog)
.PHONY: clean
--
1.6.6
Remove the ret variable, the end lable and the goto. We already have
inconsistent exit points for the function, and the end lable wasn't strictly
for errors. Directly returning simplifies and shortens the code.
Signed-off-by: John Kacur <[email protected]>
---
src/cyclictest/rt_numa.h | 14 +++++---------
1 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h
index 8d44097..ac2aca2 100644
--- a/src/cyclictest/rt_numa.h
+++ b/src/cyclictest/rt_numa.h
@@ -73,7 +73,7 @@ static int rt_numa_numa_node_of_cpu(int cpu)
static int rt_numa_numa_node_of_cpu(int cpu)
{
unsigned char cpumask[16];
- int node, ret, idx, bit;
+ int node, idx, bit;
int max_node, max_cpus;
max_node = numa_max_node();
@@ -88,19 +88,15 @@ static int rt_numa_numa_node_of_cpu(int cpu)
idx = cpu / 8;
bit = cpu % 8;
- for (node = 0; node <= max_node; node++){
+ for (node = 0; node <= max_node; node++) {
if (numa_node_to_cpus(node, (void *) cpumask, sizeof(cpumask)))
return -1;
- if (cpumask[idx] & (1<<bit)) {
- ret = node;
- goto end;
- }
+ if (cpumask[idx] & (1<<bit))
+ return node;
}
- ret = -1;
errno = EINVAL;
-end:
- return ret;
+ return -1;
}
#endif /* LIBNUMA_API_VERSION */
--
1.6.6
Add a header which includes a copyright notice to rt_numa.h for cyclictest.
Signed-off-by: John Kacur <[email protected]>
---
src/cyclictest/rt_numa.h | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h
index a0ebe7f..14837ff 100644
--- a/src/cyclictest/rt_numa.h
+++ b/src/cyclictest/rt_numa.h
@@ -1,3 +1,16 @@
+/*
+ * A numa library for cyclictest.
+ * The functions here are designed to work whether cyclictest has been
+ * compiled with numa support or not, and whether the user uses the --numa
+ * option or not.
+ * They should also work correctly with older versions of the numactl lib
+ * such as the one found on RHEL5, or with the newer version 2 and above.
+ *
+ * (C) 2010 John Kacur <[email protected]>
+ * (C) 2010 Clark Williams <[email protected]>
+ *
+ */
+
#ifndef _RT_NUMA_H
#define _RT_NUMA_H
--
1.6.6
Separate the #ifdef LIBNUMA_API_VERSION of function rt_numa_numa_node_of_cpu,
it is slightly cleaner this way.
Signed-off-by: John Kacur <[email protected]>
---
src/cyclictest/rt_numa.h | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h
index 14837ff..8d44097 100644
--- a/src/cyclictest/rt_numa.h
+++ b/src/cyclictest/rt_numa.h
@@ -58,15 +58,20 @@ static void numa_on_and_available()
fatal("--numa specified and numa functions not available.\n");
}
+#if LIBNUMA_API_VERSION >= 2
static int rt_numa_numa_node_of_cpu(int cpu)
{
-#if LIBNUMA_API_VERSION >= 2
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;
-#else
+}
+
+#else /* LIBNUMA_API_VERSION == 1 */
+
+static int rt_numa_numa_node_of_cpu(int cpu)
+{
unsigned char cpumask[16];
int node, ret, idx, bit;
int max_node, max_cpus;
@@ -96,10 +101,10 @@ static int rt_numa_numa_node_of_cpu(int cpu)
errno = EINVAL;
end:
return ret;
-
-#endif
}
+#endif /* LIBNUMA_API_VERSION */
+
static void *rt_numa_numa_alloc_onnode(size_t size, int node, int cpu)
{
void *stack;
--
1.6.6