l4fwd: Add new cmd-line parameter --mbuf-num 70/25570/2
authorMariusz Drost <mariuszx.drost@intel.com>
Mon, 2 Mar 2020 13:30:25 +0000 (13:30 +0000)
committerMariusz Drost <mariuszx.drost@intel.com>
Tue, 3 Mar 2020 14:17:42 +0000 (14:17 +0000)
In some cases default value of MPOOL_NB_BUF is too large. Because of
that new cmd-line parameter is added (--mbuf-num/-M), so user can define
that value directly before running an application. Introduced parameter
is optional. Default value of MPOOL_NB_BUF (0x20000) is preserved.

Signed-off-by: Mariusz Drost <mariuszx.drost@intel.com>
Change-Id: I9517955f313b6e97da1bb20c50b25e761430e0a8

examples/l4fwd/README
examples/l4fwd/main.c
examples/l4fwd/netbe.h
examples/l4fwd/parse.c
examples/l4fwd/port.h

index dc3dc67..328f7ef 100644 (file)
       -K | --seckey <string> /* 16 character long secret key used by */ \
                              /* hash algorithms to generate the */ \
                              /* sequence number. */ \
+      -M | --mbuf-num <num> /* other than default number of mbufs per pool. */ \
       <port0_params> <port1_params> ... <portN_params>
 
    Note that: options -U and -T cannot be used together.
index 469776f..57e9cfd 100644 (file)
@@ -61,7 +61,7 @@ RTE_DEFINE_PER_LCORE(struct netfe_lcore *, _fe);
 
 static volatile int force_quit;
 
-static struct netbe_cfg becfg;
+static struct netbe_cfg becfg = {.mpool_buf_num=MPOOL_NB_BUF};
 static struct rte_mempool *mpool[RTE_MAX_NUMA_NODES + 1];
 static struct rte_mempool *frag_mpool[RTE_MAX_NUMA_NODES + 1];
 static char proto_name[3][10] = {"udp", "tcp", ""};
index 6d9aa35..661cdcb 100644 (file)
@@ -151,6 +151,7 @@ struct netbe_cfg {
        uint32_t arp;
        uint32_t prt_num;
        uint32_t cpu_num;
+       uint32_t mpool_buf_num;
        struct netbe_port *prt;
        struct netbe_lcore *cpu;
 };
index 40adee4..a1e7917 100644 (file)
@@ -45,6 +45,9 @@ static const struct {
 #define        OPT_SHORT_PROMISC       'P'
 #define        OPT_LONG_PROMISC        "promisc"
 
+#define        OPT_SHORT_MBUFNUM       'M'
+#define        OPT_LONG_MBUFNUM        "mbuf-num"
+
 #define        OPT_SHORT_RBUFS 'R'
 #define        OPT_LONG_RBUFS  "rbufs"
 
@@ -95,6 +98,7 @@ static const struct option long_opt[] = {
        {OPT_LONG_SBULK, 1, 0, OPT_SHORT_SBULK},
        {OPT_LONG_CTXFLAGS, 1, 0, OPT_SHORT_CTXFLAGS},
        {OPT_LONG_PROMISC, 0, 0, OPT_SHORT_PROMISC},
+       {OPT_LONG_MBUFNUM, 1, 0, OPT_SHORT_MBUFNUM},
        {OPT_LONG_RBUFS, 1, 0, OPT_SHORT_RBUFS},
        {OPT_LONG_SBUFS, 1, 0, OPT_SHORT_SBUFS},
        {OPT_LONG_BECFG, 1, 0, OPT_SHORT_BECFG},
@@ -816,7 +820,7 @@ parse_app_options(int argc, char **argv, struct netbe_cfg *cfg,
 
        optind = 0;
        optarg = NULL;
-       while ((opt = getopt_long(argc, argv, "aB:C:c:LPR:S:TUb:f:s:v:H:K:W:w:",
+       while ((opt = getopt_long(argc, argv, "aB:C:c:LPR:S:M:TUb:f:s:v:H:K:W:w:",
                        long_opt, &opt_idx)) != EOF) {
                if (opt == OPT_SHORT_ARP) {
                        cfg->arp = 1;
@@ -834,7 +838,13 @@ parse_app_options(int argc, char **argv, struct netbe_cfg *cfg,
                                        "for option: \'%c\'\n",
                                        __func__, optarg, opt);
                        ctx_prm->flags = v;
-               } else if (opt == OPT_SHORT_PROMISC) {
+               } else if (opt == OPT_SHORT_MBUFNUM) {
+                       rc = parse_uint_val(NULL, optarg, &v);
+                       if (rc < 0)
+                               rte_exit(EXIT_FAILURE, "%s: invalid value: %s "
+                                       "for option: \'%c\'\n",
+                                       __func__, optarg, opt);
+                       cfg->mpool_buf_num = v;
                } else if (opt == OPT_SHORT_PROMISC) {
                        cfg->promisc = 1;
                } else if (opt == OPT_SHORT_RBUFS) {
index a154844..8c1a899 100644 (file)
@@ -316,14 +316,14 @@ log_netbe_cfg(const struct netbe_cfg *ucfg)
 }
 
 static int
-pool_init(uint32_t sid)
+pool_init(uint32_t sid, uint32_t mpool_buf_num)
 {
        int32_t rc;
        struct rte_mempool *mp;
        char name[RTE_MEMPOOL_NAMESIZE];
 
        snprintf(name, sizeof(name), "MP%u", sid);
-       mp = rte_pktmbuf_pool_create(name, MPOOL_NB_BUF, MPOOL_CACHE_SIZE, 0,
+       mp = rte_pktmbuf_pool_create(name, mpool_buf_num, MPOOL_CACHE_SIZE, 0,
                RTE_MBUF_DEFAULT_BUF_SIZE, sid - 1);
        if (mp == NULL) {
                rc = -rte_errno;
@@ -337,14 +337,14 @@ pool_init(uint32_t sid)
 }
 
 static int
-frag_pool_init(uint32_t sid)
+frag_pool_init(uint32_t sid, uint32_t mpool_buf_num)
 {
        int32_t rc;
        struct rte_mempool *frag_mp;
        char frag_name[RTE_MEMPOOL_NAMESIZE];
 
        snprintf(frag_name, sizeof(frag_name), "frag_MP%u", sid);
-       frag_mp = rte_pktmbuf_pool_create(frag_name, MPOOL_NB_BUF,
+       frag_mp = rte_pktmbuf_pool_create(frag_name, mpool_buf_num,
                MPOOL_CACHE_SIZE, 0, FRAG_MBUF_BUF_SIZE, sid - 1);
        if (frag_mp == NULL) {
                rc = -rte_errno;
@@ -406,13 +406,13 @@ netbe_port_init(struct netbe_cfg *cfg)
                        assert(sid < RTE_DIM(mpool));
 
                        if (mpool[sid] == NULL) {
-                               rc = pool_init(sid);
+                               rc = pool_init(sid, cfg->mpool_buf_num);
                                if (rc != 0)
                                        return rc;
                        }
 
                        if (frag_mpool[sid] == NULL) {
-                               rc = frag_pool_init(sid);
+                               rc = frag_pool_init(sid, cfg->mpool_buf_num);
                                if (rc != 0)
                                        return rc;
                        }