348 lines
13 KiB
Diff
348 lines
13 KiB
Diff
From 3313619bd53f1bafc5e48eb4642213fd5208c0e2 Mon Sep 17 00:00:00 2001
|
|
From: Lemmy Huang <hlm3280@163.com>
|
|
Date: Sun, 1 Sep 2024 11:33:12 +0800
|
|
Subject: [PATCH] cleancode: declare different cfg_params types
|
|
|
|
Signed-off-by: Lemmy Huang <hlm3280@163.com>
|
|
---
|
|
src/lstack/core/lstack_cfg.c | 10 +-
|
|
src/lstack/core/lstack_dpdk.c | 8 +-
|
|
src/lstack/core/lstack_protocol_stack.c | 2 +-
|
|
src/lstack/core/lstack_virtio.c | 4 +-
|
|
src/lstack/include/lstack_cfg.h | 161 +++++++++++----------
|
|
src/lstack/include/lstack_protocol_stack.h | 2 +-
|
|
src/lstack/netif/lstack_ethdev.c | 4 +-
|
|
src/lstack/netif/lstack_vdev.c | 2 +-
|
|
8 files changed, 104 insertions(+), 89 deletions(-)
|
|
|
|
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
|
|
index 882e60a..659a2a7 100644
|
|
--- a/src/lstack/core/lstack_cfg.c
|
|
+++ b/src/lstack/core/lstack_cfg.c
|
|
@@ -1300,9 +1300,9 @@ static int32_t parse_use_sockmap(void)
|
|
static int32_t parse_nic_rxqueue_size(void)
|
|
{
|
|
int32_t ret;
|
|
- PARSE_ARG(g_config_params.nic.rxqueue_size, "nic_rxqueue_size", 4096,
|
|
+ PARSE_ARG(g_config_params.rxqueue_size, "nic_rxqueue_size", 4096,
|
|
NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret);
|
|
- if (!rte_is_power_of_2(g_config_params.nic.rxqueue_size)) {
|
|
+ if (!rte_is_power_of_2(g_config_params.rxqueue_size)) {
|
|
LSTACK_LOG(ERR, LSTACK, "nic queue size only support power of two\n");
|
|
return -1;
|
|
}
|
|
@@ -1312,9 +1312,9 @@ static int32_t parse_nic_rxqueue_size(void)
|
|
static int32_t parse_nic_txqueue_size(void)
|
|
{
|
|
int32_t ret;
|
|
- PARSE_ARG(g_config_params.nic.txqueue_size, "nic_txqueue_size", 2048,
|
|
+ PARSE_ARG(g_config_params.txqueue_size, "nic_txqueue_size", 2048,
|
|
NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret);
|
|
- if (!rte_is_power_of_2(g_config_params.nic.txqueue_size)) {
|
|
+ if (!rte_is_power_of_2(g_config_params.txqueue_size)) {
|
|
LSTACK_LOG(ERR, LSTACK, "nic queue size only support power of two\n");
|
|
return -1;
|
|
}
|
|
@@ -1352,7 +1352,7 @@ static int32_t parse_stack_thread_mode(void)
|
|
static int32_t parse_nic_vlan_mode(void)
|
|
{
|
|
int32_t ret;
|
|
- PARSE_ARG(g_config_params.nic.vlan_mode, "nic_vlan_mode", -1, -1, 4094, ret);
|
|
+ PARSE_ARG(g_config_params.vlan_mode, "nic_vlan_mode", -1, -1, 4094, ret);
|
|
return ret;
|
|
}
|
|
|
|
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
|
|
index f87e362..1fe0f0a 100644
|
|
--- a/src/lstack/core/lstack_dpdk.c
|
|
+++ b/src/lstack/core/lstack_dpdk.c
|
|
@@ -432,8 +432,8 @@ static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint
|
|
|
|
eth_params->port_id = port_id;
|
|
eth_params->nb_queues = nb_queues;
|
|
- eth_params->nb_rx_desc = get_global_cfg_params()->nic.rxqueue_size;
|
|
- eth_params->nb_tx_desc = get_global_cfg_params()->nic.txqueue_size;
|
|
+ eth_params->nb_rx_desc = get_global_cfg_params()->rxqueue_size;
|
|
+ eth_params->nb_tx_desc = get_global_cfg_params()->txqueue_size;
|
|
eth_params->conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG;
|
|
eth_params->conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE;
|
|
eth_params->conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
|
|
@@ -571,7 +571,7 @@ int32_t dpdk_ethdev_init(int port_id)
|
|
}
|
|
|
|
/* after rte_eth_dev_configure */
|
|
- if ((get_global_cfg_params()->nic.vlan_mode != -1) &&
|
|
+ if ((get_global_cfg_params()->vlan_mode != -1) &&
|
|
((stack_group->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) == RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
|
|
/*
|
|
* vlan filter can be configured for switch,nic and software.
|
|
@@ -583,7 +583,7 @@ int32_t dpdk_ethdev_init(int port_id)
|
|
*/
|
|
if ((get_global_cfg_params()->bond_mode != BONDING_MODE_8023AD) &&
|
|
(get_global_cfg_params()->bond_mode != BONDING_MODE_ALB)) {
|
|
- ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1);
|
|
+ ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->vlan_mode, 1);
|
|
if (ret != 0) {
|
|
LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret);
|
|
return -1;
|
|
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
|
|
index f1eeba1..d03b744 100644
|
|
--- a/src/lstack/core/lstack_protocol_stack.c
|
|
+++ b/src/lstack/core/lstack_protocol_stack.c
|
|
@@ -571,7 +571,7 @@ static int stack_group_init_mempool(void)
|
|
struct cfg_params *cfg_params = get_global_cfg_params();
|
|
uint32_t total_mbufs = 0;
|
|
uint32_t total_conn_mbufs = cfg_params->mbuf_count_per_conn * cfg_params->tcp_conn_count;
|
|
- uint32_t total_nic_mbufs = cfg_params->nic.rxqueue_size + cfg_params->nic.txqueue_size;
|
|
+ uint32_t total_nic_mbufs = cfg_params->rxqueue_size + cfg_params->txqueue_size;
|
|
struct rte_mempool *rxtx_mbuf = NULL;
|
|
uint32_t cpu_id = 0;
|
|
unsigned numa_id = 0;
|
|
diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c
|
|
index 7a8d947..fefb06d 100644
|
|
--- a/src/lstack/core/lstack_virtio.c
|
|
+++ b/src/lstack/core/lstack_virtio.c
|
|
@@ -226,10 +226,10 @@ void virtio_tap_process_rx(uint16_t port, uint32_t queue_id)
|
|
* so no action will be taken.
|
|
* For TSO, tap devices do not support it, so no action will be taken.
|
|
*/
|
|
- if (get_global_cfg_params()->nic.vlan_mode != -1) {
|
|
+ if (get_global_cfg_params()->vlan_mode != -1) {
|
|
for (int i = 0; i< pkg_num; i++) {
|
|
pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_VLAN;
|
|
- pkts_burst[i]->vlan_tci = (u16_t)get_global_cfg_params()->nic.vlan_mode;
|
|
+ pkts_burst[i]->vlan_tci = (u16_t)get_global_cfg_params()->vlan_mode;
|
|
}
|
|
}
|
|
|
|
diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h
|
|
index 4fc99f3..5e2d6fc 100644
|
|
--- a/src/lstack/include/lstack_cfg.h
|
|
+++ b/src/lstack/include/lstack_cfg.h
|
|
@@ -50,93 +50,108 @@
|
|
#define LSTACK_LPM_PKTS_IN_DETECT 1000
|
|
#define LSTACK_LPM_RX_PKTS 20
|
|
|
|
-
|
|
#define LSTACK_LPM_PKTS_IN_DETECT_MIN 5
|
|
#define LSTACK_LPM_PKTS_IN_DETECT_MAX 65535
|
|
|
|
+struct dev_addr {
|
|
#define DEV_ADDR_TYPE_EMPTY 0
|
|
#define DEV_ADDR_TYPE_MAC 1
|
|
#define DEV_ADDR_TYPE_PCI 2
|
|
-
|
|
-struct dev_addr {
|
|
- uint8_t addr_type; // 0:empty, 1:mac, 2:pci
|
|
+ uint8_t addr_type;
|
|
union addr_union {
|
|
struct rte_ether_addr mac_addr;
|
|
struct rte_pci_addr pci_addr;
|
|
} addr;
|
|
};
|
|
|
|
-struct secondary_attach_arg {
|
|
- uint8_t socket_num;
|
|
- uint64_t socket_size;
|
|
- uint32_t socket_per_size[GAZELLE_MAX_NUMA_NODES];
|
|
- uintptr_t base_virtaddr;
|
|
- char file_prefix[PATH_MAX];
|
|
-};
|
|
-
|
|
-struct cfg_nic_params {
|
|
- uint32_t rxqueue_size;
|
|
- uint32_t txqueue_size;
|
|
- int32_t vlan_mode;
|
|
-};
|
|
-
|
|
struct cfg_params {
|
|
- ip4_addr_t host_addr;
|
|
- ip6_addr_t host_addr6;
|
|
- ip4_addr_t netmask;
|
|
- ip4_addr_t gateway_addr;
|
|
- uint8_t mac_addr[ETHER_ADDR_LEN];
|
|
- uint16_t num_cpu;
|
|
- uint32_t cpus[CFG_MAX_CPUS];
|
|
- uint32_t send_cpus[CFG_MAX_CPUS];
|
|
- uint32_t recv_cpus[CFG_MAX_CPUS];
|
|
- uint16_t app_exclude_num_cpu;
|
|
- uint32_t app_exclude_cpus[CFG_MAX_CPUS];
|
|
- uint8_t num_ports;
|
|
- uint16_t ports[CFG_MAX_PORTS];
|
|
char log_file[PATH_MAX];
|
|
- uint16_t low_power_mod;
|
|
- uint16_t lpm_rx_pkts;
|
|
- uint32_t lpm_detect_ms;
|
|
- uint32_t lpm_pkts_in_detect;
|
|
- uint32_t tcp_conn_count;
|
|
- uint32_t mbuf_count_per_conn;
|
|
- uint32_t read_connect_number;
|
|
- uint32_t rpc_number;
|
|
- uint32_t nic_read_number;
|
|
- uint8_t use_ltran; // false:lstack read from nic. true:lstack read form ltran process.
|
|
-
|
|
- uint16_t num_process;
|
|
- uint16_t num_listen_port;
|
|
- uint16_t is_primary;
|
|
- uint16_t num_queue;
|
|
- uint16_t tot_queue_num;
|
|
- uint8_t process_idx;
|
|
- uint32_t process_numa[PROTOCOL_STACK_MAX];
|
|
-
|
|
- bool kni_switch;
|
|
- bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread.
|
|
- bool app_bind_numa;
|
|
- bool main_thread_affinity;
|
|
- bool seperate_send_recv;
|
|
- int dpdk_argc;
|
|
- char **dpdk_argv;
|
|
- struct secondary_attach_arg sec_attach_arg;
|
|
- char unix_socket_filename[NAME_MAX];
|
|
- uint16_t send_ring_size;
|
|
- uint16_t recv_ring_size;
|
|
- bool tuple_filter;
|
|
- int8_t bond_mode;
|
|
- int32_t bond_miimon;
|
|
- struct dev_addr bond_slave_addr[GAZELLE_MAX_BOND_NUM];
|
|
- bool use_sockmap;
|
|
- bool udp_enable;
|
|
- struct cfg_nic_params nic;
|
|
- bool stack_mode_rtc;
|
|
- bool nonblock_mode;
|
|
- uint32_t rpc_msg_max;
|
|
- bool send_cache_mode;
|
|
- bool flow_bifurcation;
|
|
+
|
|
+ struct { // dpdk
|
|
+ char **dpdk_argv;
|
|
+ uint8_t dpdk_argc;
|
|
+ struct secondary_attach_arg {
|
|
+ uint8_t socket_num;
|
|
+ uint64_t socket_size;
|
|
+ uint32_t socket_per_size[GAZELLE_MAX_NUMA_NODES];
|
|
+ uintptr_t base_virtaddr;
|
|
+ char file_prefix[PATH_MAX];
|
|
+ } sec_attach_arg;
|
|
+ };
|
|
+
|
|
+ struct { // eth
|
|
+ ip4_addr_t host_addr;
|
|
+ ip6_addr_t host_addr6;
|
|
+ ip4_addr_t netmask;
|
|
+ ip4_addr_t gateway_addr;
|
|
+ uint8_t mac_addr[ETHER_ADDR_LEN];
|
|
+ int8_t bond_mode;
|
|
+ int32_t bond_miimon;
|
|
+ struct dev_addr bond_slave_addr[GAZELLE_MAX_BOND_NUM];
|
|
+ };
|
|
+
|
|
+ struct { // low_power
|
|
+ uint16_t low_power_mod;
|
|
+ uint16_t lpm_rx_pkts;
|
|
+ uint32_t lpm_detect_ms;
|
|
+ uint32_t lpm_pkts_in_detect;
|
|
+ };
|
|
+
|
|
+ struct { // eth_rxtx
|
|
+ uint32_t rxqueue_size;
|
|
+ uint32_t txqueue_size;
|
|
+ uint16_t num_queue;
|
|
+ uint16_t tot_queue_num;
|
|
+ bool send_cache_mode;
|
|
+ bool flow_bifurcation;
|
|
+ int32_t vlan_mode;
|
|
+ };
|
|
+
|
|
+ struct { // stack
|
|
+ uint16_t num_cpu;
|
|
+ uint32_t cpus[CFG_MAX_CPUS];
|
|
+
|
|
+ bool main_thread_affinity;
|
|
+ bool app_bind_numa;
|
|
+ uint16_t app_exclude_num_cpu;
|
|
+ uint32_t app_exclude_cpus[CFG_MAX_CPUS];
|
|
+
|
|
+ bool stack_mode_rtc;
|
|
+ bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread.
|
|
+
|
|
+ uint32_t read_connect_number;
|
|
+ uint32_t nic_read_number;
|
|
+ uint32_t rpc_number;
|
|
+ uint32_t rpc_msg_max;
|
|
+ };
|
|
+
|
|
+ struct { // socket
|
|
+ uint16_t send_ring_size;
|
|
+ uint16_t recv_ring_size;
|
|
+ uint32_t tcp_conn_count;
|
|
+ uint32_t mbuf_count_per_conn;
|
|
+ };
|
|
+
|
|
+ struct { // deprecated
|
|
+ char unix_socket_filename[NAME_MAX];
|
|
+ bool use_ltran; // false:lstack read from nic. true:lstack read form ltran process.
|
|
+ bool nonblock_mode;
|
|
+ bool udp_enable;
|
|
+ bool kni_switch;
|
|
+ };
|
|
+
|
|
+ struct { // experiment
|
|
+ uint16_t num_process;
|
|
+ uint16_t is_primary;
|
|
+ uint8_t process_idx;
|
|
+ uint32_t process_numa[PROTOCOL_STACK_MAX];
|
|
+ bool tuple_filter;
|
|
+ bool use_sockmap;
|
|
+
|
|
+ bool seperate_send_recv;
|
|
+ uint32_t send_cpus[CFG_MAX_CPUS];
|
|
+ uint32_t recv_cpus[CFG_MAX_CPUS];
|
|
+ };
|
|
};
|
|
|
|
struct cfg_params *get_global_cfg_params(void);
|
|
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
|
|
index 08a3901..8cb0020 100644
|
|
--- a/src/lstack/include/lstack_protocol_stack.h
|
|
+++ b/src/lstack/include/lstack_protocol_stack.h
|
|
@@ -34,7 +34,7 @@
|
|
#define SOCK_RECV_RING_SIZE_MAX (2048)
|
|
#define SOCK_SEND_RING_SIZE_MAX (2048)
|
|
|
|
-#define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->nic.rxqueue_size + 1024)
|
|
+#define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->rxqueue_size + 1024)
|
|
|
|
struct protocol_stack {
|
|
uint32_t tid;
|
|
diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c
|
|
index 4f3cbc1..1a721f6 100644
|
|
--- a/src/lstack/netif/lstack_ethdev.c
|
|
+++ b/src/lstack/netif/lstack_ethdev.c
|
|
@@ -418,8 +418,8 @@ int32_t ethdev_init(struct protocol_stack *stack)
|
|
}
|
|
|
|
/* 0-4094: The vlaue range for VLAN IDs is 0 to 4094. */
|
|
- if (get_global_cfg_params()->nic.vlan_mode >= 0 && get_global_cfg_params()->nic.vlan_mode <= 4094) {
|
|
- netif_set_vlan_tci(&stack->netif, (u16_t)get_global_cfg_params()->nic.vlan_mode);
|
|
+ if (get_global_cfg_params()->vlan_mode >= 0 && get_global_cfg_params()->vlan_mode <= 4094) {
|
|
+ netif_set_vlan_tci(&stack->netif, (u16_t)get_global_cfg_params()->vlan_mode);
|
|
}
|
|
|
|
netif_set_link_up(&stack->netif);
|
|
diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c
|
|
index 9ca77ba..e1a63a7 100644
|
|
--- a/src/lstack/netif/lstack_vdev.c
|
|
+++ b/src/lstack/netif/lstack_vdev.c
|
|
@@ -145,7 +145,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt
|
|
}
|
|
|
|
/* skip gro when tcp/ip cksum offloads disable */
|
|
- if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->nic.vlan_mode >= 0
|
|
+ if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->vlan_mode >= 0
|
|
&& !(get_protocol_stack_group()->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_STRIP))) {
|
|
return pkt_num;
|
|
}
|
|
--
|
|
2.33.0
|
|
|