[Babel-users] [PATCH 4/6] Tests: Add subdir and test for structure packing

Dave Taht dave.taht at gmail.com
Thu Mar 9 15:55:01 UTC 2017


From: Dave Taht <dave at taht.net>

An initial run of this test on x86_64 shows suboptimal packing for the
filter structure (can be 96), and kernel_route (can be 64).

Other things, such as kernel_rule, buffered_update and xroute could be
padded to more natural 8 byte boundaries for this arch. Other structure
optimizations are feasible. Having this tool readily available to
measure changes across different architectures is helpful.

./show_babel_packing

Compiled with gcc 5.4.0 for the x86_64 architecture in little endian mode
  24 = sizeof (filter_result)
 112 = sizeof (filter)
  44 = sizeof (buffered_update)
  56 = sizeof (interface_conf)
 272 = sizeof (interface)
  68 = sizeof (kernel_route)
  28 = sizeof (kernel_rule)
  64 = sizeof (kernel_filter)
  24 = sizeof (local_socket)
 120 = sizeof (neighbour)
  88 = sizeof (resend)
  88 = sizeof (babel_route)
  56 = sizeof (source)
  44 = sizeof (xroute)
---
 tests/.gitignore           | 11 ++++++++
 tests/Makefile             | 22 ++++++++++++++++
 tests/arch_detect.h        | 53 +++++++++++++++++++++++++++++++++++++
 tests/show_babel_packing.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 152 insertions(+)
 create mode 100644 tests/.gitignore
 create mode 100644 tests/Makefile
 create mode 100644 tests/arch_detect.h
 create mode 100644 tests/show_babel_packing.c

diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..dd71803
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,11 @@
+show_babel_packing
+*.o
+cscope.*
+gmon.out
+core
+TAGS
+tags
+*.rej
+*.orig
+*~
+\#*#
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..e6fe035
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,22 @@
+PREFIX = /usr/local
+MANDIR = $(PREFIX)/share/man
+
+PROGS = show_babel_packing
+
+CDEBUGFLAGS = -Os -g -Wall
+
+DEFINES = $(PLATFORM_DEFINES)
+
+CFLAGS = $(CDEBUGFLAGS) $(DEFINES) $(EXTRA_DEFINES)
+
+INCLUDES = babeld.h net.h kernel.c util.h interface.h source.h neighbour.h \
+       route.h xroute.h message.h resend.h configuration.h local.h \
+       disambiguation.h rule.h version.h
+
+INCLUDES1 := $(INCLUDES:%=../%)
+
+show_babel_packing: show_babel_packing.c $(INCLUDES1)
+	$(CC) $(CFLAGS) $(LDFLAGS) -I.. $@.c -o show_babel_packing $(OBJS) $(LDLIBS)
+
+clean:
+	-rm -f $(PROGS) show_babel_packing.o
diff --git a/tests/arch_detect.h b/tests/arch_detect.h
new file mode 100644
index 0000000..103c2ef
--- /dev/null
+++ b/tests/arch_detect.h
@@ -0,0 +1,53 @@
+/**
+ * arch_detect.h
+ *
+ * Toke Høiland-Jørgensen
+ * 2017-03-08
+ */
+
+#ifndef ARCH_DETECT_H
+#define ARCH_DETECT_H
+
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 10000 \
+                     + __GNUC_MINOR__ * 100 \
+                     + __GNUC_PATCHLEVEL__)
+#endif
+
+#define P(a)    typedef struct a a ##_t; \
+		printf("%4ld = sizeof (%s)\n", sizeof(a ## _t), #a)
+
+#if !(defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) \
+	|| defined(__i386__) || defined(__mips__))
+	const char arch[] = "unknown";
+#else
+#if defined(__arm__) || defined(__aarch64__)
+#if defined(__ARM_ARCH_ISA_A64__) || defined(__aarch64__)
+	const char arch[] = "aarch64";
+#else
+#ifdef __ARM_ARCH_7S__
+	const char arch[] = "armv7s";
+#else
+#ifdef __ARM_ARCH_7A__
+	const char arch[] = "armv7";
+#endif
+#endif
+#endif /* end of arm detection. Fixme - need to find neon regs */
+#else
+#if defined(__x86_64__)
+	const char arch[] = "x86_64";
+#endif
+
+#if defined(__i386__)
+const char arch[] = "x86";
+#endif
+
+#if defined(__mips__)
+const char arch[] = "MIPS";
+#endif
+
+#endif
+
+#endif
+
+#endif
diff --git a/tests/show_babel_packing.c b/tests/show_babel_packing.c
new file mode 100644
index 0000000..a670abd
--- /dev/null
+++ b/tests/show_babel_packing.c
@@ -0,0 +1,66 @@
+/**
+ * test_packing.c
+ */
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <time.h>
+#include <signal.h>
+#include <assert.h>
+#include <string.h>
+#include <getopt.h>
+
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <arpa/inet.h>
+
+#include "babeld.h"
+#include "util.h"
+#include "net.h"
+#include "kernel.h"
+#include "interface.h"
+#include "source.h"
+#include "neighbour.h"
+#include "route.h"
+#include "xroute.h"
+#include "message.h"
+#include "resend.h"
+#include "configuration.h"
+#include "local.h"
+#include "rule.h"
+#include "version.h"
+
+#include "arch_detect.h"
+
+int main()
+{
+#ifdef __GNUC__
+    printf("Compiled with gcc %d.%d.%d for the %s "
+        "architecture in %s mode\n",
+        __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__,
+        arch, __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ?
+        "little endian" : "big endian");
+#endif
+    P(filter_result);
+    P(filter);
+    P(buffered_update);
+    P(interface_conf);
+    P(interface);
+    P(kernel_route);
+    P(kernel_rule);
+    P(kernel_filter);
+    P(local_socket);
+    P(neighbour);
+    P(resend);
+    P(babel_route);
+    P(source);
+    P(xroute);
+    return 0;
+}
-- 
2.7.4




More information about the Babel-users mailing list