[dpdk-dev,04/15] examples/l2fwd: move globally accessed vars to common header
diff mbox series

Message ID 1528477766-15788-5-git-send-email-anoob.joseph@caviumnetworks.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • preparing l2fwd for eventmode additions
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Anoob Joseph June 8, 2018, 5:09 p.m. UTC
Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
 examples/l2fwd/l2fwd_common.h | 26 ++++++++++++++++++++++++++
 examples/l2fwd/main.c         | 41 +++++++++++++++++------------------------
 2 files changed, 43 insertions(+), 24 deletions(-)

Patch
diff mbox series

diff --git a/examples/l2fwd/l2fwd_common.h b/examples/l2fwd/l2fwd_common.h
index 40979fd..3e940e1 100644
--- a/examples/l2fwd/l2fwd_common.h
+++ b/examples/l2fwd/l2fwd_common.h
@@ -4,6 +4,10 @@ 
 #ifndef _L2FWD_COMMON_H_
 #define _L2FWD_COMMON_H_
 
+#include <stdbool.h>
+
+#include <rte_common.h>
+
 #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
 
 #define MAX_PKT_BURST 32
@@ -33,4 +37,26 @@  struct l2fwd_port_statistics {
 	uint64_t dropped;
 } __rte_cache_aligned;
 
+volatile bool force_quit;
+
+int mac_updating;
+
+/* ethernet addresses of ports */
+struct ether_addr l2fwd_ports_eth_addr[RTE_MAX_ETHPORTS];
+
+/* mask of enabled ports */
+uint32_t l2fwd_enabled_port_mask;
+
+/* list of enabled ports */
+uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS];
+
+struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
+
+struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
+
+struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS];
+
+/* A tsc-based timer responsible for triggering statistics printout */
+uint64_t timer_period;
+
 #endif /* _L2FWD_COMMON_H_ */
diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 11ca170..a6089a1 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -41,29 +41,11 @@ 
 
 #include "l2fwd_common.h"
 
-static volatile bool force_quit;
-
-/* MAC updating enabled by default */
-static int mac_updating = 1;
-
 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
 
-/* ethernet addresses of ports */
-static struct ether_addr l2fwd_ports_eth_addr[RTE_MAX_ETHPORTS];
-
-/* mask of enabled ports */
-static uint32_t l2fwd_enabled_port_mask = 0;
-
-/* list of enabled ports */
-static uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS];
-
 static unsigned int l2fwd_rx_queue_per_lcore = 1;
 
-struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
-
-static struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
-
 static struct rte_eth_conf port_conf = {
 	.rxmode = {
 		.split_hdr_size = 0,
@@ -77,11 +59,6 @@  static struct rte_eth_conf port_conf = {
 
 struct rte_mempool * l2fwd_pktmbuf_pool = NULL;
 
-struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS];
-
-/* A tsc-based timer responsible for triggering statistics printout */
-static uint64_t timer_period = 10; /* default period is 10 seconds */
-
 /* Print out statistics on packets dropped */
 static void
 print_stats(void)
@@ -489,6 +466,20 @@  signal_handler(int signum)
 	}
 }
 
+static void
+l2fwd_init_global_vars(void)
+{
+	force_quit = false;
+
+	/* MAC updating enabled by default */
+	mac_updating = 1;
+
+	/* Default period is 10 seconds */
+	timer_period = 10;
+
+	l2fwd_enabled_port_mask = 0;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -502,6 +493,9 @@  main(int argc, char **argv)
 	unsigned int nb_lcores = 0;
 	unsigned int nb_mbufs;
 
+	/* Set default values for global vars */
+	l2fwd_init_global_vars();
+
 	/* init EAL */
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
@@ -509,7 +503,6 @@  main(int argc, char **argv)
 	argc -= ret;
 	argv += ret;
 
-	force_quit = false;
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);