examples/l3fwd: add option to set RX burst size
PATCH 1/1 examples/l3fwd: add option to set RX burst size
Now the Rx burst size is fixed to MAX_PKT_BURST (32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value is DEFAULT_PKT_BURST (32) and maximum value is MAX_PKT_BURST (512).
--- examples/l3fwd/l3fwd.h | 5 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 58 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 64 insertions(+), 7 deletions(-)
examples/l3fwd/l3fwd.h +4 -1
@@ -23,7 +23,8 @@#define RX_DESC_DEFAULT 1024#define TX_DESC_DEFAULT 1024 -#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ #define MEMPOOL_CACHE_SIZE 256
@@ -115,6 +116,8 @@ extern struct acl_algorithms acl_alg[];extern uint32_t max_pkt_len; +extern uint32_t nb_pkt_per_burst; +/* Send burst of packets on an output interface */ static inline int send_burst (struct lcore_conf *qconf,uint16_t n,uint16_t port)
examples/l3fwd/l3fwd_acl.c +1 -1
@@ -1119,7 +1119,7 @@ acl_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, - pkts_burst,MAX_PKT_BURST ); + pkts_burst, nb_pkt_per_burst);if (nb_rx >0 ) { acl_process_pkts(pkts_burst, hops, nb_rx,
examples/l3fwd/l3fwd_em.c +1 -1
@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_fib.c +1 -1
@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_lpm.c +1 -1
@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/main.c +56 -2
112 lines not on this page · raw message
Signature · 1 line
2.22.0
Quoted 7 lines · Jie Hai
Now the Rx burst size is fixed to
MAX_PKT_BURST(32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value isDEFAULT_PKT_BURST(32) and maximum value isMAX_PKT_BURST(512).Signed-off-by Jie Hai <[email protected]>
Quoted 8 lines
From: Jie Hai [mailto:[email protected]]
Sent: Saturday, 12 October 2024 10.41Now the Rx burst size is fixed to
MAX_PKT_BURST(32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value isDEFAULT_PKT_BURST(32) and maximum value isMAX_PKT_BURST(512).
Good idea.
examples/l3fwd/l3fwd.h line 30
Quoted 10 lines
Signed-off-by Jie Hai <[email protected]>---
examples/l3fwd/l3fwd.h +2
-1-#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ #define MEMPOOL_CACHE_SIZE 256
It seems strange to use a burst size larger than the mempool cache size.
You might want to make the cache size configurable too, or simply define MEMPOOL_CACHE_SIZE as RTE_MEMPOOL_CACHE_MAX_SIZE (currently 512) instead of 256.
And, as a safety measure, consider adding:
#include <assert.h> static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST);
v2 cover examples/l3fwd: add more options
In reply to Jie HaiAdd options to support configuring RX burst size and cache size of mbuf mempoool.
Jie Hai (2):
examples/l3fwd: add option to set RX burst size examples/l3fwd: add option to set mbuf cache size
examples/l3fwd/l3fwd.h | 8 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 89 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 96 insertions(+), 9 deletions(-)
Signature · 1 line
2.22.0
PATCH v2 1/2 examples/l3fwd: add option to set RX burst size
Now the Rx burst size is fixed to MAX_PKT_BURST (32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value is DEFAULT_PKT_BURST (32) and maximum value is MAX_PKT_BURST (512).
--- examples/l3fwd/l3fwd.h | 7 +++-- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 60 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 67 insertions(+), 8 deletions(-)
examples/l3fwd/l3fwd.h +5 -2
@@ -23,10 +23,11 @@#define RX_DESC_DEFAULT 1024#define TX_DESC_DEFAULT 1024 -#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ -#define MEMPOOL_CACHE_SIZE 256 +#define MEMPOOL_CACHE_SIZE RTE_MEMPOOL_CACHE_MAX_SIZE#define MAX_RX_QUEUE_PER_LCORE 16#define VECTOR_SIZE_DEFAULT MAX_PKT_BURST
@@ -115,6 +116,8 @@ extern struct acl_algorithms acl_alg[];extern uint32_t max_pkt_len; +extern uint32_t nb_pkt_per_burst; +/* Send burst of packets on an output interface */ static inline int send_burst (struct lcore_conf *qconf,uint16_t n,uint16_t port)
examples/l3fwd/l3fwd_acl.c +1 -1
@@ -1119,7 +1119,7 @@ acl_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, - pkts_burst,MAX_PKT_BURST ); + pkts_burst, nb_pkt_per_burst);if (nb_rx >0 ) { acl_process_pkts(pkts_burst, hops, nb_rx,
examples/l3fwd/l3fwd_em.c +1 -1
@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_fib.c +1 -1
@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_lpm.c +1 -1
@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/main.c +58 -2
122 lines not on this page · raw message
Signature · 1 line
2.22.0
Quoted 232 lines · Jie Hai
Now the Rx burst size is fixed to
MAX_PKT_BURST(32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value isDEFAULT_PKT_BURST(32) and maximum value isMAX_PKT_BURST(512).Signed-off-by Jie Hai <[email protected]>Acked-by Chengwen Feng <[email protected]>--- examples/l3fwd/l3fwd.h | 7 +++-- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 60 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 67 insertions(+), 8 deletions(-)examples/l3fwd/l3fwd.h +5
-2@@ -23,10 +23,11 @@#define RX_DESC_DEFAULT 1024#define TX_DESC_DEFAULT 1024 -#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ -#define MEMPOOL_CACHE_SIZE 256 +#define MEMPOOL_CACHE_SIZE RTE_MEMPOOL_CACHE_MAX_SIZE#define MAX_RX_QUEUE_PER_LCORE 16#define VECTOR_SIZE_DEFAULT MAX_PKT_BURST@@ -115,6 +116,8 @@ extern struct acl_algorithms acl_alg[];extern uint32_t max_pkt_len; +extern uint32_t nb_pkt_per_burst; +/* Send burst of packets on an output interface */ static inline int send_burst (struct lcore_conf *qconf,uint16_t n,uint16_t port)examples/l3fwd/l3fwd_acl.c +1
-1@@ -1119,7 +1119,7 @@ acl_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, - pkts_burst,MAX_PKT_BURST ); + pkts_burst, nb_pkt_per_burst);if (nb_rx >0 ) { acl_process_pkts(pkts_burst, hops, nb_rx,examples/l3fwd/l3fwd_em.c +1
-1@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;examples/l3fwd/l3fwd_fib.c +1
-1@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;examples/l3fwd/l3fwd_lpm.c +1
-1@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;examples/l3fwd/main.c +58
-2@@ -14,6 +14,7 @@#include <getopt.h> #include <signal.h> #include <stdbool.h> +#include <assert.h> #include <rte_common.h> #include <rte_vect.h> @@ -53,8 +54,10 @@#define MAX_LCORE_PARAMS 1024 +static_assert (MEMPOOL_CACHE_SIZE >=MAX_PKT_BURST );uint16_t nb_rxd =RX_DESC_DEFAULT ;uint16_t nb_txd =TX_DESC_DEFAULT ; +uint32_t nb_pkt_per_burst =DEFAULT_PKT_BURST ;/**< Ports set in promiscuous mode off by default. */ static int promiscuous_on;@@ -395,6 +398,7 @@ print_usage(const char *prgname)" --config (port,queue,lcore)[,(port,queue,lcore)]" " [--rx-queue-size NPKTS]" " [--tx-queue-size NPKTS]" +" [--burst NPKTS]" " [--eth-dest=X,MM:MM:MM:MM:MM:MM]" " [--max-pkt-len PKTLEN]" " [--no-numa]" @@ -420,6 +424,8 @@ print_usage(const char *prgname)" Default: %d\n" " --tx-queue-size NPKTS: Tx queue size in decimal\n" " Default: %d\n" +" --burst NPKTS: Burst 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" @@ -449,7 +455,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 , + prgname,RX_DESC_DEFAULT ,TX_DESC_DEFAULT ,DEFAULT_PKT_BURST , ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg); }@@ -667,6 +673,49 @@ parse_lookup(const char *optarg)return 0 ; } +static void +parse_pkt_burst (const char *optarg) +{ +struct rte_eth_dev_info dev_info; +unsigned long pkt_burst; +uint16_t burst_size; +char *end =NULL ; +int ret; + +/* parse decimal string */ + pkt_burst =strtoul (optarg, &end,10 ); +if ((optarg[0 ] =='\0' ) || (end ==NULL ) || (*end !='\0' )) +return ; + +if (pkt_burst >MAX_PKT_BURST ) { +RTE_LOG (INFO ,L3FWD ,"User provided burst must be <= %d. Using default value %d\n" , +MAX_PKT_BURST , nb_pkt_per_burst); +return ; + }else if (pkt_burst >0 ) { + nb_pkt_per_burst = (uint32_t )pkt_burst; +return ; + } + +/* If user gives a value of zero, query the PMD for its recommended Rx burst size. */ + ret =rte_eth_dev_info_get (0 , &dev_info); +if (ret !=0 ) +return ; + burst_size = dev_info.default_rxportconf.burst_size; +if (burst_size ==0 ) { +RTE_LOG (INFO ,L3FWD ,"PMD does not recommend a burst size. Using default value %d. " +"User provided value must be in [1, %d]\n" , + nb_pkt_per_burst,MAX_PKT_BURST ); +return ; + }else if (burst_size >MAX_PKT_BURST ) { +RTE_LOG (INFO ,L3FWD ,"PMD recommended burst size %d exceeds maximum value %d. " +"Using default value %d\n" , + burst_size,MAX_PKT_BURST , nb_pkt_per_burst); +return ; + } + nb_pkt_per_burst = burst_size; +RTE_LOG (INFO ,L3FWD ,"Using PMD-provided burst value %d\n" , burst_size); +} +#define MAX_JUMBO_PKT_LEN 9600 static const char short_options[] =@@ -698,6 +747,7 @@ static const char short_options[] =#define CMD_LINE_OPT_RULE_IPV4 "rule_ipv4"#define CMD_LINE_OPT_RULE_IPV6 "rule_ipv6"#define CMD_LINE_OPT_ALG "alg" +#define CMD_LINE_OPT_PKT_BURST "burst"enum {/* long options mapped to a short option */ @@ -726,7 +776,8 @@ enum {CMD_LINE_OPT_LOOKUP_NUM ,CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM , -CMD_LINE_OPT_VECTOR_TMO_NS_NUM +CMD_LINE_OPT_VECTOR_TMO_NS_NUM , +CMD_LINE_OPT_PKT_BURST_NUM }; static const struct option lgopts[] = {@@ -753,6 +804,7 @@ static const struct option lgopts[] = { {CMD_LINE_OPT_RULE_IPV4, 1, 0, CMD_LINE_OPT_RULE_IPV4_NUM}, {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}, {NULL, 0, 0, 0} };@@ -841,6 +893,10 @@ parse_args(int argc, char **argv)parse_queue_size (optarg, &nb_txd,0 );break ; +case CMD_LINE_OPT_PKT_BURST_NUM : +parse_pkt_burst (optarg); +break ; +case CMD_LINE_OPT_ETH_DEST_NUM :parse_eth_dest (optarg);break ;
PATCH v2 2/2 examples/l3fwd: add option to set mbuf cache size
In reply to Jie HaiThe 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 paramater to a maximum of RTE_MEMPOOL_CACHE_MAX_SIZE.
--- examples/l3fwd/l3fwd.h | 1 + examples/l3fwd/main.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)
examples/l3fwd/l3fwd.h +1 -0
@@ -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
examples/l3fwd/main.c +30 -3
@@ -58,6 +58,7 @@ static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST);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;
@@ -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]"
@@ -426,6 +428,8 @@ print_usage(const char *prgname)" Default: %d\n" " --burst NPKTS: Burst size in decimal\n" " Default: %d\n" +" --mbcache CACHESZ: 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"
@@ -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); }
@@ -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) {
@@ -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 */
@@ -777,7 +798,8 @@ enum {CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM ,CMD_LINE_OPT_VECTOR_TMO_NS_NUM , -CMD_LINE_OPT_PKT_BURST_NUM +CMD_LINE_OPT_PKT_BURST_NUM , +CMD_LINE_OPT_MB_CACHE_SIZE_NUM }; static const struct option lgopts[] = {
@@ -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} };
@@ -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 ;
@@ -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,
Signature · 1 line
2.22.0
Re: [PATCH v2 2/2] examples/l3fwd: add option to set mbuf cache size
lgtm, Acked-by: Huisong Li <[email protected]>
Quoted 130 lines · Jie Hai
The mempool cache size of mbuf is set to
RTE_MEMPOOL_CACHE_MAX_SIZEas default. This patch allows users to configure the cache size by "--mbcache", and limits the paramater to a maximum ofRTE_MEMPOOL_CACHE_MAX_SIZE.Signed-off-by Jie Hai <[email protected]>--- examples/l3fwd/l3fwd.h | 1 + examples/l3fwd/main.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)examples/l3fwd/l3fwd.h +1
-0@@ -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 intexamples/l3fwd/main.c +30
-3@@ -58,6 +58,7 @@ static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST);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;@@ -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]" @@ -426,6 +428,8 @@ print_usage(const char *prgname)" Default: %d\n" " --burst NPKTS: Burst size in decimal\n" " Default: %d\n" +" --mbcache CACHESZ: 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" @@ -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); }@@ -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) {@@ -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 */ @@ -777,7 +798,8 @@ enum {CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM ,CMD_LINE_OPT_VECTOR_TMO_NS_NUM , -CMD_LINE_OPT_PKT_BURST_NUM +CMD_LINE_OPT_PKT_BURST_NUM , +CMD_LINE_OPT_MB_CACHE_SIZE_NUM }; static const struct option lgopts[] = {@@ -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} };@@ -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 ;@@ -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,
RE: [PATCH v2 0/2] examples/l3fwd: add more options
In reply to Jie HaiFor the series,
v3 cover examples/l3fwd: add more options
In reply to Jie HaiAdd options to support configuring RX burst size and cache size of mbuf mempoool.
--
v3:
1. add Acked-bys.
2. fix compile error.
--
Jie Hai (2):
examples/l3fwd: add option to set RX burst size examples/l3fwd: add option to set mbuf cache size
examples/l3fwd/l3fwd.h | 8 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 89 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 96 insertions(+), 9 deletions(-)
Signature · 1 line
2.22.0
PATCH v3 1/2 examples/l3fwd: add option to set RX burst size
Now the Rx burst size is fixed to MAX_PKT_BURST (32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value is DEFAULT_PKT_BURST (32) and maximum value is MAX_PKT_BURST (512).
--- examples/l3fwd/l3fwd.h | 7 +++-- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 60 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 67 insertions(+), 8 deletions(-)
examples/l3fwd/l3fwd.h +5 -2
@@ -23,10 +23,11 @@#define RX_DESC_DEFAULT 1024#define TX_DESC_DEFAULT 1024 -#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ -#define MEMPOOL_CACHE_SIZE 256 +#define MEMPOOL_CACHE_SIZE RTE_MEMPOOL_CACHE_MAX_SIZE#define MAX_RX_QUEUE_PER_LCORE 16#define VECTOR_SIZE_DEFAULT MAX_PKT_BURST
@@ -115,6 +116,8 @@ extern struct acl_algorithms acl_alg[];extern uint32_t max_pkt_len; +extern uint32_t nb_pkt_per_burst; +/* Send burst of packets on an output interface */ static inline int send_burst (struct lcore_conf *qconf,uint16_t n,uint16_t port)
examples/l3fwd/l3fwd_acl.c +1 -1
@@ -1119,7 +1119,7 @@ acl_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, - pkts_burst,MAX_PKT_BURST ); + pkts_burst, nb_pkt_per_burst);if (nb_rx >0 ) { acl_process_pkts(pkts_burst, hops, nb_rx,
examples/l3fwd/l3fwd_em.c +1 -1
@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_fib.c +1 -1
@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_lpm.c +1 -1
@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/main.c +58 -2
122 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v3 2/2 examples/l3fwd: add option to set mbuf cache size
In reply to Jie HaiThe 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.
--- examples/l3fwd/l3fwd.h | 1 + examples/l3fwd/main.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)
examples/l3fwd/l3fwd.h +1 -0
@@ -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
examples/l3fwd/main.c +30 -3
@@ -58,6 +58,7 @@ static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST, "MAX_PKT_BURST should be at muint16_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;
@@ -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]"
@@ -426,6 +428,8 @@ print_usage(const char *prgname)" Default: %d\n" " --burst NPKTS: Burst size in decimal\n" " Default: %d\n" +" --mbcache CACHESZ: 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"
@@ -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); }
@@ -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) {
@@ -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 */
@@ -777,7 +798,8 @@ enum {CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM ,CMD_LINE_OPT_VECTOR_TMO_NS_NUM , -CMD_LINE_OPT_PKT_BURST_NUM +CMD_LINE_OPT_PKT_BURST_NUM , +CMD_LINE_OPT_MB_CACHE_SIZE_NUM }; static const struct option lgopts[] = {
@@ -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} };
@@ -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 ;
@@ -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,
Signature · 1 line
2.22.0
Re: [PATCH v3 2/2] examples/l3fwd: add option to set mbuf cache size
There's a little tip that can be modified, with that modified:
Quoted 46 lines · Jie Hai
The mempool cache size of mbuf is set to
RTE_MEMPOOL_CACHE_MAX_SIZEas default. This patch allows users to configure the cache size by "--mbcache", and limits the parameter to a maximum ofRTE_MEMPOOL_CACHE_MAX_SIZE.Signed-off-by Jie Hai <[email protected]>Acked-by Huisong Li <[email protected]>Acked-by Morten Brørup <[email protected]>--- examples/l3fwd/l3fwd.h | 1 + examples/l3fwd/main.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)examples/l3fwd/l3fwd.h +1
-0@@ -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 intexamples/l3fwd/main.c +2
-0@@ -58,6 +58,7 @@ static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST, "MAX_PKT_BURST should be at muint16_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;@@ -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]"
examples/l3fwd/main.c print_usage(const char *prgname) · line 431
Quoted 4 lines
examples/l3fwd/main.c +1
-0@@ -426,6 +428,8 @@ print_usage(const char *prgname)" Default: %d\n" " --burst NPKTS: Burst size in decimal\n" " Default: %d\n" +" --mbcache CACHESZ: Cache size in decimal\n"
Suggest " --mbcache CACHESZ: Mbuf cache size in decimal\n"
Quoted 82 lines
examples/l3fwd/main.c +27
-3+" 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" @@ -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); }@@ -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) {@@ -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 */ @@ -777,7 +798,8 @@ enum {CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM ,CMD_LINE_OPT_VECTOR_TMO_NS_NUM , -CMD_LINE_OPT_PKT_BURST_NUM +CMD_LINE_OPT_PKT_BURST_NUM , +CMD_LINE_OPT_MB_CACHE_SIZE_NUM }; static const struct option lgopts[] = {@@ -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} };@@ -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 ;@@ -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,
v4 cover examples/l3fwd: add more options
In reply to Jie HaiAdd options to support configuring RX burst size and cache size of mbuf mempoool.
--
v4:
1. fix help info.
v3:
1. add Acked-bys.
2. fix compile error.
--
Jie Hai (2):
examples/l3fwd: add option to set RX burst size examples/l3fwd: add option to set mbuf cache size
examples/l3fwd/l3fwd.h | 8 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 89 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 96 insertions(+), 9 deletions(-)
Signature · 1 line
2.22.0
PATCH v4 1/2 examples/l3fwd: add option to set RX burst size
Now the Rx burst size is fixed to MAX_PKT_BURST (32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value is DEFAULT_PKT_BURST (32) and maximum value is MAX_PKT_BURST (512).
--- examples/l3fwd/l3fwd.h | 7 +++-- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 60 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 67 insertions(+), 8 deletions(-)
examples/l3fwd/l3fwd.h +5 -2
@@ -23,10 +23,11 @@#define RX_DESC_DEFAULT 1024#define TX_DESC_DEFAULT 1024 -#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ -#define MEMPOOL_CACHE_SIZE 256 +#define MEMPOOL_CACHE_SIZE RTE_MEMPOOL_CACHE_MAX_SIZE#define MAX_RX_QUEUE_PER_LCORE 16#define VECTOR_SIZE_DEFAULT MAX_PKT_BURST
@@ -115,6 +116,8 @@ extern struct acl_algorithms acl_alg[];extern uint32_t max_pkt_len; +extern uint32_t nb_pkt_per_burst; +/* Send burst of packets on an output interface */ static inline int send_burst (struct lcore_conf *qconf,uint16_t n,uint16_t port)
examples/l3fwd/l3fwd_acl.c +1 -1
@@ -1119,7 +1119,7 @@ acl_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, - pkts_burst,MAX_PKT_BURST ); + pkts_burst, nb_pkt_per_burst);if (nb_rx >0 ) { acl_process_pkts(pkts_burst, hops, nb_rx,
examples/l3fwd/l3fwd_em.c +1 -1
@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_fib.c +1 -1
@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/l3fwd_lpm.c +1 -1
@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;
examples/l3fwd/main.c +58 -2
122 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v4 2/2 examples/l3fwd: add option to set mbuf cache size
In reply to Jie HaiThe 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.
--- examples/l3fwd/l3fwd.h | 1 + examples/l3fwd/main.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)
examples/l3fwd/l3fwd.h +1 -0
@@ -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
examples/l3fwd/main.c +30 -3
@@ -58,6 +58,7 @@ static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST, "MAX_PKT_BURST should be at muint16_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;
@@ -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]"
@@ -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"
@@ -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); }
@@ -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) {
@@ -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 */
@@ -777,7 +798,8 @@ enum {CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM ,CMD_LINE_OPT_VECTOR_TMO_NS_NUM , -CMD_LINE_OPT_PKT_BURST_NUM +CMD_LINE_OPT_PKT_BURST_NUM , +CMD_LINE_OPT_MB_CACHE_SIZE_NUM }; static const struct option lgopts[] = {
@@ -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} };
@@ -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 ;
@@ -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,
Signature · 1 line
2.22.0
Re: [PATCH v4 0/2] examples/l3fwd: add more options
In reply to Jie HaiHi, all maintainers,
Kindly ping for review.
Thanks,
Jie Hai
Quoted 24 lines · Jie Hai
Add options to support configuring RX burst size and cache size of mbuf mempoool.
--
v4:
1. fix help info.v3:
1. add Acked-bys.
2. fix compile error.
--Jie Hai (2):
examples/l3fwd: add option to set RX burst size examples/l3fwd: add option to set mbuf cache sizeexamples/l3fwd/l3fwd.h | 8 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 89 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 96 insertions(+), 9 deletions(-)
Re: [PATCH v4 0/2] examples/l3fwd: add more options
In reply to Jie HaiHi, Ferruh and Thomas,
Kindly ping for reviews.
Since this patchset has some Acked-bys and no comments, are there any comments or suggestions?
Best regards,
Jie Hai
Quoted 24 lines · Jie Hai
Add options to support configuring RX burst size and cache size of mbuf mempoool.
--
v4:
1. fix help info.v3:
1. add Acked-bys.
2. fix compile error.
--Jie Hai (2):
examples/l3fwd: add option to set RX burst size examples/l3fwd: add option to set mbuf cache sizeexamples/l3fwd/l3fwd.h | 8 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 89 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 96 insertions(+), 9 deletions(-)
Thomas Monjalon
AppliedRe: [PATCH v4 0/2] examples/l3fwd: add more options
In reply to Jie Hai18/10/2024 03:08, Jie Hai:
Quoted 2 lines
Add options to support configuring RX burst size and cache size of mbuf mempoool.
Applied, thanks.
Hi, all maintainers,
Kindly ping for review.
Thanks,
Jie Hai
Quoted 216 lines · Jie Hai
Now the Rx burst size is fixed to
MAX_PKT_BURST(32). This parameter needs to be modified in some performance optimization scenarios. So an option '--burst' is added to set the burst size explicitly. The default value isDEFAULT_PKT_BURST(32) and maximum value isMAX_PKT_BURST(512).Signed-off-by Jie Hai <[email protected]>--- examples/l3fwd/l3fwd.h | 5 +++- examples/l3fwd/l3fwd_acl.c | 2 +- examples/l3fwd/l3fwd_em.c | 2 +- examples/l3fwd/l3fwd_fib.c | 2 +- examples/l3fwd/l3fwd_lpm.c | 2 +- examples/l3fwd/main.c | 58 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 64 insertions(+), 7 deletions(-)examples/l3fwd/l3fwd.h +4
-1@@ -23,7 +23,8 @@#define RX_DESC_DEFAULT 1024#define TX_DESC_DEFAULT 1024 -#define MAX_PKT_BURST 32 +#define DEFAULT_PKT_BURST 32 +#define MAX_PKT_BURST 512#define BURST_TX_DRAIN_US 100/* TX drain every ~100us */ #define MEMPOOL_CACHE_SIZE 256@@ -115,6 +116,8 @@ extern struct acl_algorithms acl_alg[];extern uint32_t max_pkt_len; +extern uint32_t nb_pkt_per_burst; +/* Send burst of packets on an output interface */ static inline int send_burst (struct lcore_conf *qconf,uint16_t n,uint16_t port)examples/l3fwd/l3fwd_acl.c +1
-1@@ -1119,7 +1119,7 @@ acl_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, - pkts_burst,MAX_PKT_BURST ); + pkts_burst, nb_pkt_per_burst);if (nb_rx >0 ) { acl_process_pkts(pkts_burst, hops, nb_rx,examples/l3fwd/l3fwd_em.c +1
-1@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;examples/l3fwd/l3fwd_fib.c +1
-1@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;examples/l3fwd/l3fwd_lpm.c +1
-1@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy) portid = qconf->rx_queue_list[i].port_id; queueid = qconf->rx_queue_list[i].queue_id; nb_rx =rte_eth_rx_burst (portid, queueid, pkts_burst, -MAX_PKT_BURST ); + nb_pkt_per_burst);if (nb_rx ==0 )continue ;examples/l3fwd/main.c +56
-2@@ -55,6 +55,7 @@uint16_t nb_rxd =RX_DESC_DEFAULT ;uint16_t nb_txd =TX_DESC_DEFAULT ; +uint32_t nb_pkt_per_burst =DEFAULT_PKT_BURST ;/**< Ports set in promiscuous mode off by default. */ static int promiscuous_on;@@ -395,6 +396,7 @@ print_usage(const char *prgname)" --config (port,queue,lcore)[,(port,queue,lcore)]" " [--rx-queue-size NPKTS]" " [--tx-queue-size NPKTS]" +" [--burst NPKTS]" " [--eth-dest=X,MM:MM:MM:MM:MM:MM]" " [--max-pkt-len PKTLEN]" " [--no-numa]" @@ -420,6 +422,8 @@ print_usage(const char *prgname)" Default: %d\n" " --tx-queue-size NPKTS: Tx queue size in decimal\n" " Default: %d\n" +" --burst NPKTS: Burst 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" @@ -449,7 +453,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 , + prgname,RX_DESC_DEFAULT ,TX_DESC_DEFAULT ,DEFAULT_PKT_BURST , ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg); }@@ -667,6 +671,49 @@ parse_lookup(const char *optarg)return 0 ; } +static void +parse_pkt_burst (const char *optarg) +{ +struct rte_eth_dev_info dev_info; +uint16_t burst_size; +uint16_t pkt_burst; +char *end =NULL ; +int ret; + +/* parse decimal string */ + pkt_burst =strtoul (optarg, &end,10 ); +if ((optarg[0 ] =='\0' ) || (end ==NULL ) || (*end !='\0' )) +return ; + +if (pkt_burst >MAX_PKT_BURST ) { +RTE_LOG (INFO ,L3FWD ,"User provided burst must be <= %d. Using default value %d\n" , +MAX_PKT_BURST , nb_pkt_per_burst); +return ; + }else if (pkt_burst >0 ) { + nb_pkt_per_burst = pkt_burst; +return ; + } + +/* If user gives a value of zero, query the PMD for its recommended Rx burst size. */ + ret =rte_eth_dev_info_get (0 , &dev_info); +if (ret !=0 ) +return ; + burst_size = dev_info.default_rxportconf.burst_size; +if (burst_size ==0 ) { +RTE_LOG (INFO ,L3FWD ,"PMD does not recommend a burst size. Using default value %d. " +"User provided value must be in [1, %d]\n" , + nb_pkt_per_burst,MAX_PKT_BURST ); +return ; + }else if (burst_size >MAX_PKT_BURST ) { +RTE_LOG (INFO ,L3FWD ,"PMD recommended burst size %d exceeds maximum value %d. " +"Using default value %d\n" , + burst_size,MAX_PKT_BURST , nb_pkt_per_burst); +return ; + } + nb_pkt_per_burst = burst_size; +RTE_LOG (INFO ,L3FWD ,"Using PMD-provided burst value %d\n" , burst_size); +} +#define MAX_JUMBO_PKT_LEN 9600 static const char short_options[] =@@ -698,6 +745,7 @@ static const char short_options[] =#define CMD_LINE_OPT_RULE_IPV4 "rule_ipv4"#define CMD_LINE_OPT_RULE_IPV6 "rule_ipv6"#define CMD_LINE_OPT_ALG "alg" +#define CMD_LINE_OPT_PKT_BURST "burst"enum {/* long options mapped to a short option */ @@ -726,7 +774,8 @@ enum {CMD_LINE_OPT_LOOKUP_NUM ,CMD_LINE_OPT_ENABLE_VECTOR_NUM ,CMD_LINE_OPT_VECTOR_SIZE_NUM , -CMD_LINE_OPT_VECTOR_TMO_NS_NUM +CMD_LINE_OPT_VECTOR_TMO_NS_NUM , +CMD_LINE_OPTPKT_BURST_NUM }; static const struct option lgopts[] = {@@ -753,6 +802,7 @@ static const struct option lgopts[] = { {CMD_LINE_OPT_RULE_IPV4, 1, 0, CMD_LINE_OPT_RULE_IPV4_NUM}, {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_OPTPKT_BURST_NUM}, {NULL, 0, 0, 0} };@@ -841,6 +891,10 @@ parse_args(int argc, char **argv)parse_queue_size (optarg, &nb_txd,0 );break ; +case CMD_LINE_OPTPKT_BURST_NUM : +parse_pkt_burst (optarg); +break ; +case CMD_LINE_OPT_ETH_DEST_NUM :parse_eth_dest (optarg);break ;