Skip to content

Commit

Permalink
examples/l3fwd: add option to set mbuf cache size
Browse files Browse the repository at this point in the history
The mempool cache size of mbuf is set to
RTE_MEMPOOL_CACHE_MAX_SIZE as default. This patch allows
users to configure the cache size by "--mbcache", and limits
the parameter to a maximum of RTE_MEMPOOL_CACHE_MAX_SIZE.

Signed-off-by: Jie Hai <[email protected]>
Acked-by: Huisong Li <[email protected]>
Acked-by: Morten Brørup <[email protected]>
Acked-by: Chengwen Feng <[email protected]>
  • Loading branch information
Jie Hai authored and tmonjalo committed Nov 19, 2024
1 parent d5c4897 commit d9f26e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/l3fwd/l3fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ extern struct acl_algorithms acl_alg[];
extern uint32_t max_pkt_len;

extern uint32_t nb_pkt_per_burst;
extern uint32_t mb_mempool_cache_size;

/* Send burst of packets on an output interface */
static inline int
Expand Down
31 changes: 29 additions & 2 deletions examples/l3fwd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST, "MAX_PKT_BURST should be at m
uint16_t nb_rxd = RX_DESC_DEFAULT;
uint16_t nb_txd = TX_DESC_DEFAULT;
uint32_t nb_pkt_per_burst = DEFAULT_PKT_BURST;
uint32_t mb_mempool_cache_size = MEMPOOL_CACHE_SIZE;

/**< Ports set in promiscuous mode off by default. */
static int promiscuous_on;
Expand Down Expand Up @@ -399,6 +400,7 @@ print_usage(const char *prgname)
" [--rx-queue-size NPKTS]"
" [--tx-queue-size NPKTS]"
" [--burst NPKTS]"
" [--mbcache CACHESZ]"
" [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
" [--max-pkt-len PKTLEN]"
" [--no-numa]"
Expand Down Expand Up @@ -426,6 +428,8 @@ print_usage(const char *prgname)
" Default: %d\n"
" --burst NPKTS: Burst size in decimal\n"
" Default: %d\n"
" --mbcache CACHESZ: Mbuf cache size in decimal\n"
" Default: %d\n"
" --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
" --max-pkt-len PKTLEN: maximum packet length in decimal (64-9600)\n"
" --no-numa: Disable numa awareness\n"
Expand Down Expand Up @@ -455,7 +459,7 @@ print_usage(const char *prgname)
" another is route entry at while line leads with character '%c'.\n"
" --rule_ipv6=FILE: Specify the ipv6 rules entries file.\n"
" --alg: ACL classify method to use, one of: %s.\n\n",
prgname, RX_DESC_DEFAULT, TX_DESC_DEFAULT, DEFAULT_PKT_BURST,
prgname, RX_DESC_DEFAULT, TX_DESC_DEFAULT, DEFAULT_PKT_BURST, MEMPOOL_CACHE_SIZE,
ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg);
}

Expand Down Expand Up @@ -673,6 +677,22 @@ parse_lookup(const char *optarg)
return 0;
}

static void
parse_mbcache_size(const char *optarg)
{
unsigned long mb_cache_size;
char *end = NULL;

mb_cache_size = strtoul(optarg, &end, 10);
if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
return;
if (mb_cache_size <= RTE_MEMPOOL_CACHE_MAX_SIZE)
mb_mempool_cache_size = (uint32_t)mb_cache_size;
else
rte_exit(EXIT_FAILURE, "mbcache must be >= 0 and <= %d\n",
RTE_MEMPOOL_CACHE_MAX_SIZE);
}

static void
parse_pkt_burst(const char *optarg)
{
Expand Down Expand Up @@ -748,6 +768,7 @@ static const char short_options[] =
#define CMD_LINE_OPT_RULE_IPV6 "rule_ipv6"
#define CMD_LINE_OPT_ALG "alg"
#define CMD_LINE_OPT_PKT_BURST "burst"
#define CMD_LINE_OPT_MB_CACHE_SIZE "mbcache"

enum {
/* long options mapped to a short option */
Expand Down Expand Up @@ -778,6 +799,7 @@ enum {
CMD_LINE_OPT_VECTOR_SIZE_NUM,
CMD_LINE_OPT_VECTOR_TMO_NS_NUM,
CMD_LINE_OPT_PKT_BURST_NUM,
CMD_LINE_OPT_MB_CACHE_SIZE_NUM,
};

static const struct option lgopts[] = {
Expand Down Expand Up @@ -805,6 +827,7 @@ static const struct option lgopts[] = {
{CMD_LINE_OPT_RULE_IPV6, 1, 0, CMD_LINE_OPT_RULE_IPV6_NUM},
{CMD_LINE_OPT_ALG, 1, 0, CMD_LINE_OPT_ALG_NUM},
{CMD_LINE_OPT_PKT_BURST, 1, 0, CMD_LINE_OPT_PKT_BURST_NUM},
{CMD_LINE_OPT_MB_CACHE_SIZE, 1, 0, CMD_LINE_OPT_MB_CACHE_SIZE_NUM},
{NULL, 0, 0, 0}
};

Expand Down Expand Up @@ -897,6 +920,10 @@ parse_args(int argc, char **argv)
parse_pkt_burst(optarg);
break;

case CMD_LINE_OPT_MB_CACHE_SIZE_NUM:
parse_mbcache_size(optarg);
break;

case CMD_LINE_OPT_ETH_DEST_NUM:
parse_eth_dest(optarg);
break;
Expand Down Expand Up @@ -1089,7 +1116,7 @@ init_mem(uint16_t portid, unsigned int nb_mbuf)
portid, socketid);
pktmbuf_pool[portid][socketid] =
rte_pktmbuf_pool_create(s, nb_mbuf,
MEMPOOL_CACHE_SIZE, 0,
mb_mempool_cache_size, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
if (pktmbuf_pool[portid][socketid] == NULL)
rte_exit(EXIT_FAILURE,
Expand Down

0 comments on commit d9f26e5

Please sign in to comment.