npftest: add a choice of "rule" or "state" for -b option.

This commit is contained in:
rmind 2013-09-24 02:44:20 +00:00
parent a484105289
commit a99ac6280c
4 changed files with 44 additions and 31 deletions

View File

@ -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_TCP);
th = mbuf_return_hdrs(m, false, &ip);
m = mbuf_construct(IPPROTO_UDP);
uh = 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;
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);
printf("THREADS\tPKTS\n");
done = false;
run = false;
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);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: npf_test.h,v 1.9 2013/09/24 02:04:21 rmind Exp $ */
/* $NetBSD: npf_test.h,v 1.10 2013/09/24 02:44:20 rmind Exp $ */
/*
* Public Domain.
@ -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);

View File

@ -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();

View File

@ -1,4 +1,4 @@
/* $NetBSD: npftest.h,v 1.8 2013/09/24 02:04:21 rmind Exp $ */
/* $NetBSD: npftest.h,v 1.9 2013/09/24 02:44:20 rmind Exp $ */
/*
* Public Domain.
@ -17,7 +17,7 @@ unsigned rumpns_npf_test_getif(const char *);
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);