Permalink
Browse files

pktgen: Allow pktgenctl to specify # of packets to be queued onto TX …

…queue
  • Loading branch information...
1 parent dfd3b18 commit 793f802fe24d9d2c1de21e55cc3687f81bfce1e5 Sepherosa Ziehau committed Jan 6, 2013
@@ -95,6 +95,8 @@ struct pktgen {
int pktg_datalen;
struct ifnet *pktg_ifp;
+ int pktg_pktenq;
+
struct sockaddr_in pktg_src;
int pktg_ndst;
struct sockaddr_in *pktg_dst;
@@ -247,7 +249,7 @@ pktgen_config(struct pktgen *pktg, const struct pktgen_conf *conf)
const struct sockaddr *sa;
struct ifnet *ifp;
size_t dst_size;
- int i, error;
+ int i, error, pktenq;
if (pktg->pktg_flags & (PKTG_F_RUNNING | PKTG_F_CONFIG))
return EBUSY;
@@ -294,6 +296,14 @@ pktgen_config(struct pktgen *pktg, const struct pktgen_conf *conf)
goto failed;
}
+ pktenq = conf->pc_pktenq;
+ if (pktenq < 0 || pktenq > ifp->if_snd.ifq_maxlen) {
+ error = ENOBUFS;
+ goto failed;
+ } else if (pktenq == 0) {
+ pktenq = (ifp->if_snd.ifq_maxlen * 3) / 4;
+ }
+
sa = &conf->pc_dst_lladdr;
if (sa->sa_family != AF_LINK) {
error = EPROTONOSUPPORT;
@@ -316,6 +326,7 @@ pktgen_config(struct pktgen *pktg, const struct pktgen_conf *conf)
pktg->pktg_duration = conf->pc_duration;
pktg->pktg_datalen = conf->pc_datalen;
+ pktg->pktg_pktenq = pktenq;
pktg->pktg_ifp = ifp;
pktg->pktg_src = conf->pc_src;
pktg->pktg_ndst = conf->pc_ndst;
@@ -354,8 +365,8 @@ pktgen_start(struct pktgen *pktg)
if (cpuid != orig_cpuid)
lwkt_migratecpu(cpuid);
- alloc_cnt = ifp->if_snd.ifq_maxlen * 2;
- keep_cnt = (ifp->if_snd.ifq_maxlen * 3) / 4;
+ keep_cnt = pktg->pktg_pktenq;
+ alloc_cnt = keep_cnt * 2;
/*
* Prefault enough mbuf into mbuf objcache
@@ -46,6 +46,7 @@ struct pktgen_conf {
struct sockaddr_in pc_src;
int pc_ndst;
struct sockaddr_in *pc_dst;
+ int pc_pktenq;
};
#define PKTGENSTART _IO('G', 19)
@@ -60,8 +60,6 @@
#define INSRC_MASK 0x0002
#define EADDR_MASK 0x0004
#define IFACE_MASK 0x0008
-#define DATALEN_MASK 0x0010
-#define DURATION_MASK 0x0020
#define MASK_NEEDED (INDST_MASK | INSRC_MASK | EADDR_MASK | IFACE_MASK)
@@ -72,7 +70,7 @@ usage(void)
"-d dst_inaddr[:dst_port] [-d dst_inaddr[:dst_port] ...] "
"-s src_inaddr[:src_port] "
"-e (gw_eaddr|dst_eaddr) -i iface "
- "[-m data_len] [-l duration] [-D dev]\n");
+ "[-m data_len] [-l duration] [-D dev] [-q pktenq]\n");
exit(1);
}
@@ -123,7 +121,7 @@ main(int argc, char *argv[])
err(1, "calloc(%d dst)", ndst_alloc);
conf.pc_ndst = 0;
- while ((c = getopt(argc, argv, "d:s:e:i:m:l:D:")) != -1) {
+ while ((c = getopt(argc, argv, "d:s:e:i:m:l:D:q:")) != -1) {
switch (c) {
case 'd':
if (conf.pc_ndst >= ndst_alloc) {
@@ -182,18 +180,20 @@ main(int argc, char *argv[])
case 'm':
conf.pc_datalen = atoi(optarg);
- arg_mask |= DATALEN_MASK;
break;
case 'l':
conf.pc_duration = atoi(optarg);
- arg_mask |= DURATION_MASK;
break;
case 'D':
dev = optarg;
break;
+ case 'q':
+ conf.pc_pktenq = atoi(optarg);
+ break;
+
default:
usage();
}

0 comments on commit 793f802

Please sign in to comment.