summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2008-08-25 23:36:24 +0000
committerjkim <jkim@FreeBSD.org>2008-08-25 23:36:24 +0000
commita70ab99712ff5aceda3594e58eecfb8a48924908 (patch)
tree3e7ce578855d7433758a9148332eb83dc0186d43 /tools
parent7226acfb72220c90ec89893f90a3b1bbf1a2512f (diff)
downloadFreeBSD-src-a70ab99712ff5aceda3594e58eecfb8a48924908.zip
FreeBSD-src-a70ab99712ff5aceda3594e58eecfb8a48924908.tar.gz
Add a trivial bpf filter benchmark.
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/bpf/bpf_filter/Makefile10
-rw-r--r--tools/regression/bpf/bpf_filter/bpf_test.c17
2 files changed, 22 insertions, 5 deletions
diff --git a/tools/regression/bpf/bpf_filter/Makefile b/tools/regression/bpf/bpf_filter/Makefile
index f6e2330..5be486d 100644
--- a/tools/regression/bpf/bpf_filter/Makefile
+++ b/tools/regression/bpf/bpf_filter/Makefile
@@ -26,7 +26,9 @@ SRCS= ${.CURDIR}/bpf_test.c
CFLAGS+= -g -fno-builtin-abort -I${.CURDIR}/tests
-.if defined(LOG_LEVEL)
+.if defined(BPF_BENCHMARK)
+CFLAGS+= -DBPF_BENCHMARK -DLOG_LEVEL=0
+.elif defined(LOG_LEVEL)
CFLAGS+= -DLOG_LEVEL="${LOG_LEVEL}"
.endif
@@ -51,10 +53,14 @@ ${TEST}: ${.CURDIR}/tests/${TEST}.h ${SRCS}
all: ${TEST_CASES}
.for TEST in ${TEST_CASES}
-.if !defined(LOG_LEVEL) || (${LOG_LEVEL} > 0)
+.if defined(BPF_BENCHMARK) || !defined(LOG_LEVEL) || (${LOG_LEVEL} > 0)
@${ECHO} -n "${TEST}: "
.endif
+.if defined(BPF_BENCHMARK)
+ @-time ${.CURDIR}/${TEST}
+.else
@-${.CURDIR}/${TEST}
+.endif
@rm -f ${.CURDIR}/${TEST}
.endfor
diff --git a/tools/regression/bpf/bpf_filter/bpf_test.c b/tools/regression/bpf/bpf_filter/bpf_test.c
index f031d77..31a2043 100644
--- a/tools/regression/bpf/bpf_filter/bpf_test.c
+++ b/tools/regression/bpf/bpf_filter/bpf_test.c
@@ -44,6 +44,12 @@ __FBSDID("$FreeBSD$");
#define LOG_LEVEL 1
#endif
+#ifdef BPF_BENCHMARK
+#define BPF_NRUNS 10000000
+#else
+#define BPF_NRUNS 1
+#endif
+
static void sig_handler(int);
static int nins = sizeof(pc) / sizeof(pc[0]);
@@ -57,7 +63,7 @@ static u_int
bpf_compile_and_filter(void)
{
bpf_jit_filter *filter;
- u_int ret;
+ u_int i, ret;
/* Do not use BPF JIT compiler for an empty program */
if (nins == 0)
@@ -72,7 +78,8 @@ bpf_compile_and_filter(void)
exit(FATAL);
}
- ret = (*(filter->func))(pkt, wirelen, buflen);
+ for (i = 0; i < BPF_NRUNS; i++)
+ ret = (*(filter->func))(pkt, wirelen, buflen);
bpf_destroy_jit_filter(filter);
@@ -148,6 +155,9 @@ bpf_validate(const struct bpf_insn *f, int len)
int
main(void)
{
+#if !defined(BPF_JIT_COMPILER)
+ u_int i;
+#endif
u_int ret;
int sig;
#ifdef BPF_VALIDATE
@@ -178,7 +188,8 @@ main(void)
#ifdef BPF_JIT_COMPILER
ret = bpf_compile_and_filter();
#else
- ret = bpf_filter(pc, pkt, wirelen, buflen);
+ for (i = 0; i < BPF_NRUNS; i++)
+ ret = bpf_filter(pc, pkt, wirelen, buflen);
#endif
if (ret != expect) {
if (verbose > 1)
OpenPOWER on IntegriCloud