Module Name: src
Committed By: rmind
Date: Tue Sep 24 02:44:20 UTC 2013
Modified Files:
src/usr.sbin/npf/npftest: npftest.c npftest.h
src/usr.sbin/npf/npftest/libnpftest: npf_perf_test.c npf_test.h
Log Message:
npftest: add a choice of "rule" or "state" for -b option.
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/npf/npftest/npftest.c
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/npf/npftest/npftest.h
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/npf/npftest/libnpftest/npf_test.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/npf/npftest/npftest.c
diff -u src/usr.sbin/npf/npftest/npftest.c:1.11 src/usr.sbin/npf/npftest/npftest.c:1.12
--- src/usr.sbin/npf/npftest/npftest.c:1.11 Tue Sep 24 02:04:21 2013
+++ src/usr.sbin/npf/npftest/npftest.c Tue Sep 24 02:44:20 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: npftest.c,v 1.11 2013/09/24 02:04:21 rmind Exp $ */
+/* $NetBSD: npftest.c,v 1.12 2013/09/24 02:44:20 rmind Exp $ */
/*
* NPF testing framework.
@@ -137,12 +137,12 @@ arc4random(void)
int
main(int argc, char **argv)
{
- bool benchmark, test, ok, fail, tname_matched;
- char *config, *interface, *stream, *testname;
+ bool test, ok, fail, tname_matched;
+ char *benchmark, *config, *interface, *stream, *testname;
unsigned nthreads = 0;
int idx = -1, ch;
- benchmark = false;
+ benchmark = NULL;
test = false;
tname_matched = false;
@@ -154,10 +154,10 @@ main(int argc, char **argv)
verbose = false;
quiet = false;
- while ((ch = getopt(argc, argv, "bqvc:i:s:tT:Lp:")) != -1) {
+ while ((ch = getopt(argc, argv, "b:qvc:i:s:tT:Lp:")) != -1) {
switch (ch) {
case 'b':
- benchmark = true;
+ benchmark = optarg;
break;
case 'q':
quiet = true;
@@ -204,7 +204,7 @@ main(int argc, char **argv)
* interface should be specified. If benchmark, then the
* config should be loaded.
*/
- if (benchmark == test && (stream && !interface)) {
+ if ((benchmark != NULL) == test && (stream && !interface)) {
usage();
}
if (benchmark && (!config || !nthreads)) {
@@ -276,7 +276,12 @@ main(int argc, char **argv)
}
if (benchmark) {
- rumpns_npf_test_conc(nthreads);
+ if (strcmp("rule", benchmark) == 0) {
+ rumpns_npf_test_conc(false, nthreads);
+ }
+ if (strcmp("state", benchmark) == 0) {
+ rumpns_npf_test_conc(true, nthreads);
+ }
}
rump_unschedule();
Index: src/usr.sbin/npf/npftest/npftest.h
diff -u src/usr.sbin/npf/npftest/npftest.h:1.8 src/usr.sbin/npf/npftest/npftest.h:1.9
--- src/usr.sbin/npf/npftest/npftest.h:1.8 Tue Sep 24 02:04:21 2013
+++ src/usr.sbin/npf/npftest/npftest.h Tue Sep 24 02:44:20 2013
@@ -17,7 +17,7 @@ unsigned rumpns_npf_test_getif(const cha
int rumpns_npf_test_statetrack(const void *, size_t,
unsigned, bool, int64_t *);
-void rumpns_npf_test_conc(unsigned);
+void rumpns_npf_test_conc(bool, unsigned);
bool rumpns_npf_nbuf_test(bool);
bool rumpns_npf_bpf_test(bool);
Index: src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c
diff -u src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.1 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.2
--- src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.1 Tue Sep 24 02:04:21 2013
+++ src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Tue Sep 24 02:44:20 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_perf_test.c,v 1.1 2013/09/24 02:04:21 rmind Exp $ */
+/* $NetBSD: npf_perf_test.c,v 1.2 2013/09/24 02:44:20 rmind Exp $ */
/*
* NPF benchmarking.
@@ -16,24 +16,30 @@
#include "npf_impl.h"
#include "npf_test.h"
-#define NSECS 1 /* seconds */
+#define NSECS 10 /* seconds */
static volatile int run;
static volatile int done;
+static uint64_t * npackets;
+static bool stateful;
+
static struct mbuf *
-fill_packet(void)
+fill_packet(unsigned i)
{
struct mbuf *m;
struct ip *ip;
- struct tcphdr *th;
+ struct udphdr *uh;
+ char buf[32];
+
+ m = mbuf_construct(IPPROTO_UDP);
+ uh = mbuf_return_hdrs(m, false, &ip);
- m = mbuf_construct(IPPROTO_TCP);
- th = mbuf_return_hdrs(m, false, &ip);
+ snprintf(buf, sizeof(buf), "192.0.2.%u", i + i);
ip->ip_src.s_addr = inet_addr(PUB_IP1);
- ip->ip_dst.s_addr = inet_addr(LOCAL_IP3);
- th->th_sport = htons(80);
- th->th_dport = htons(15000);
+ ip->ip_dst.s_addr = inet_addr(stateful ? LOCAL_IP2 : LOCAL_IP3);
+ uh->uh_sport = htons(80);
+ uh->uh_dport = htons(15000 + i);
return m;
}
@@ -41,8 +47,9 @@ static void
worker(void *arg)
{
ifnet_t *ifp = ifunit(IFNAME_INT);
- uint64_t n = 0, *npackets = arg;
- struct mbuf *m = fill_packet();
+ unsigned int i = (uintptr_t)arg;
+ struct mbuf *m = fill_packet(i);
+ uint64_t n = 0;
while (!run)
/* spin-wait */;
@@ -53,28 +60,29 @@ worker(void *arg)
KASSERT(error == 0);
n++;
}
- *npackets = n;
+ npackets[i] = n;
kthread_exit(0);
}
void
-npf_test_conc(unsigned nthreads)
+npf_test_conc(bool st, unsigned nthreads)
{
- uint64_t total = 0, *npackets;
+ uint64_t total = 0;
int error;
lwp_t **l;
- npackets = kmem_zalloc(sizeof(uint64_t) * nthreads, KM_SLEEP);
- l = kmem_zalloc(sizeof(lwp_t *) * nthreads, KM_SLEEP);
-
printf("THREADS\tPKTS\n");
+ stateful = st;
done = false;
run = false;
+ npackets = kmem_zalloc(sizeof(uint64_t) * nthreads, KM_SLEEP);
+ l = kmem_zalloc(sizeof(lwp_t *) * nthreads, KM_SLEEP);
+
for (unsigned i = 0; i < nthreads; i++) {
const int flags = KTHREAD_MUSTJOIN | KTHREAD_MPSAFE;
error = kthread_create(PRI_NONE, flags, NULL,
- worker, &npackets[i], &l[i], "npfperf");
+ worker, (void *)(uintptr_t)i, &l[i], "npfperf");
KASSERT(error == 0);
}
Index: src/usr.sbin/npf/npftest/libnpftest/npf_test.h
diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.9 src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.10
--- src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.9 Tue Sep 24 02:04:21 2013
+++ src/usr.sbin/npf/npftest/libnpftest/npf_test.h Tue Sep 24 02:44:20 2013
@@ -45,7 +45,7 @@ unsigned npf_test_getif(const char *);
int npf_test_statetrack(const void *, size_t, unsigned,
bool, int64_t *);
-void npf_test_conc(unsigned);
+void npf_test_conc(bool, unsigned);
struct mbuf * mbuf_getwithdata(const void *, size_t);
struct mbuf * mbuf_construct_ether(int);