backport upstream patches from repository
(cherry picked from commit acaa789aa85d602fc946045431a51d0422696c4e)
This commit is contained in:
parent
9ed82c2b52
commit
af183e9773
351
0056-ltran-support-checksum.patch
Normal file
351
0056-ltran-support-checksum.patch
Normal file
@ -0,0 +1,351 @@
|
||||
From 5c44c739f651e295141c096bf676cc3bc7ce7460 Mon Sep 17 00:00:00 2001
|
||||
From: wu-changsheng <wuchangsheng2@huawei.com>
|
||||
Date: Thu, 7 Jul 2022 22:21:34 +0800
|
||||
Subject: [PATCH 01/19] ltran support checksum
|
||||
|
||||
---
|
||||
src/common/dpdk_common.c | 44 ++++++++++++++
|
||||
src/common/dpdk_common.h | 4 ++
|
||||
src/common/gazelle_reg_msg.h | 2 +
|
||||
src/lstack/core/lstack_control_plane.c | 4 ++
|
||||
src/lstack/core/lstack_dpdk.c | 67 +++-------------------
|
||||
src/lstack/include/lstack_protocol_stack.h | 2 +
|
||||
src/ltran/ltran_ethdev.c | 48 +++++++++++-----
|
||||
src/ltran/ltran_instance.c | 3 +
|
||||
src/ltran/ltran_param.h | 2 +
|
||||
9 files changed, 102 insertions(+), 74 deletions(-)
|
||||
|
||||
diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c
|
||||
index 63dcfc1..939d135 100644
|
||||
--- a/src/common/dpdk_common.c
|
||||
+++ b/src/common/dpdk_common.c
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <rte_ethdev.h>
|
||||
#include <rte_bus_pci.h>
|
||||
#include <rte_mbuf.h>
|
||||
+#include <rte_ethdev.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "dpdk_common.h"
|
||||
@@ -87,6 +88,49 @@ static int32_t kni_config_network_interface(uint16_t port_id, uint8_t if_up)
|
||||
return ret;
|
||||
}
|
||||
|
||||
+void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info)
|
||||
+{
|
||||
+ uint64_t rx_ol = 0;
|
||||
+ uint64_t tx_ol = 0;
|
||||
+ uint64_t rx_ol_capa = dev_info->rx_offload_capa;
|
||||
+ uint64_t tx_ol_capa = dev_info->tx_offload_capa;
|
||||
+
|
||||
+ // rx ip
|
||||
+ if (rx_ol_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
|
||||
+ rx_ol |= DEV_RX_OFFLOAD_IPV4_CKSUM;
|
||||
+ COMMON_INFO("DEV_RX_OFFLOAD_IPV4_CKSUM\n");
|
||||
+ }
|
||||
+
|
||||
+ if (rx_ol_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
|
||||
+ rx_ol |= DEV_RX_OFFLOAD_TCP_CKSUM;
|
||||
+ COMMON_INFO("DEV_RX_OFFLOAD_TCP_CKSUM\n");
|
||||
+ }
|
||||
+
|
||||
+ // tx ip
|
||||
+ if (tx_ol_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
|
||||
+ tx_ol |= DEV_TX_OFFLOAD_IPV4_CKSUM;
|
||||
+ COMMON_INFO("DEV_TX_OFFLOAD_IPV4_CKSUM\n");
|
||||
+ }
|
||||
+
|
||||
+ // tx tcp
|
||||
+ if (tx_ol_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
|
||||
+ tx_ol |= DEV_TX_OFFLOAD_TCP_CKSUM;
|
||||
+ COMMON_INFO("DEV_TX_OFFLOAD_TCP_CKSUM\n");
|
||||
+ }
|
||||
+
|
||||
+ if (!(rx_ol & DEV_RX_OFFLOAD_TCP_CKSUM) || !(rx_ol & DEV_RX_OFFLOAD_IPV4_CKSUM)) {
|
||||
+ rx_ol = 0;
|
||||
+ }
|
||||
+ if (!(tx_ol & DEV_TX_OFFLOAD_TCP_CKSUM) || !(tx_ol & DEV_TX_OFFLOAD_IPV4_CKSUM)) {
|
||||
+ tx_ol = 0;
|
||||
+ }
|
||||
+
|
||||
+ conf->rxmode.offloads = rx_ol;
|
||||
+ conf->txmode.offloads = tx_ol;
|
||||
+
|
||||
+ COMMON_INFO("set checksum offloads\n");
|
||||
+}
|
||||
+
|
||||
int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool)
|
||||
{
|
||||
int32_t ret;
|
||||
diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h
|
||||
index 4a7bd37..6a6a030 100644
|
||||
--- a/src/common/dpdk_common.h
|
||||
+++ b/src/common/dpdk_common.h
|
||||
@@ -67,6 +67,10 @@ int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool);
|
||||
int32_t kni_process_tx(struct rte_mbuf **pkts_burst, uint32_t count);
|
||||
void kni_process_rx(uint16_t port);
|
||||
|
||||
+struct rte_eth_conf;
|
||||
+struct rte_eth_dev_info;
|
||||
+void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info);
|
||||
+
|
||||
/*
|
||||
gazelle custom rte ring interface
|
||||
lightweight ring reduce atomic and smp_mb.
|
||||
diff --git a/src/common/gazelle_reg_msg.h b/src/common/gazelle_reg_msg.h
|
||||
index ff846fd..f5842e7 100644
|
||||
--- a/src/common/gazelle_reg_msg.h
|
||||
+++ b/src/common/gazelle_reg_msg.h
|
||||
@@ -94,6 +94,8 @@ struct reg_response_msg {
|
||||
struct {
|
||||
uintptr_t base_virtaddr;
|
||||
uint64_t socket_size;
|
||||
+ uint64_t rx_offload;
|
||||
+ uint64_t tx_offload;
|
||||
} msg;
|
||||
};
|
||||
|
||||
diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c
|
||||
index ef38fb5..c86dab1 100644
|
||||
--- a/src/lstack/core/lstack_control_plane.c
|
||||
+++ b/src/lstack/core/lstack_control_plane.c
|
||||
@@ -297,6 +297,10 @@ static int32_t client_reg_proc_memory(bool is_reconnect)
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ struct protocol_stack_group *stack_group = get_protocol_stack_group();
|
||||
+ stack_group->rx_offload = recv_msg.msg.rx_offload;
|
||||
+ stack_group->tx_offload = recv_msg.msg.tx_offload;
|
||||
+
|
||||
if (!is_reconnect) {
|
||||
ret = proc_memory_init(&recv_msg);
|
||||
if (ret != 0) {
|
||||
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
|
||||
index 6675d7b..13df6a3 100644
|
||||
--- a/src/lstack/core/lstack_dpdk.c
|
||||
+++ b/src/lstack/core/lstack_dpdk.c
|
||||
@@ -313,68 +313,12 @@ static struct eth_params *alloc_eth_params(uint16_t port_id, uint16_t nb_queues)
|
||||
|
||||
uint64_t get_eth_params_rx_ol(void)
|
||||
{
|
||||
- return use_ltran() ? 0 : get_protocol_stack_group()->eth_params->conf.rxmode.offloads;
|
||||
+ return get_protocol_stack_group()->rx_offload;
|
||||
}
|
||||
|
||||
uint64_t get_eth_params_tx_ol(void)
|
||||
{
|
||||
- return use_ltran() ? 0 : get_protocol_stack_group()->eth_params->conf.txmode.offloads;
|
||||
-}
|
||||
-
|
||||
-static int eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info)
|
||||
-{
|
||||
-#if CHECKSUM_OFFLOAD_ALL
|
||||
- uint64_t rx_ol = 0;
|
||||
- uint64_t tx_ol = 0;
|
||||
-
|
||||
- uint64_t rx_ol_capa = dev_info->rx_offload_capa;
|
||||
- uint64_t tx_ol_capa = dev_info->tx_offload_capa;
|
||||
-
|
||||
- // rx ip
|
||||
-#if CHECKSUM_CHECK_IP_HW
|
||||
- if (rx_ol_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
|
||||
- rx_ol |= DEV_RX_OFFLOAD_IPV4_CKSUM;
|
||||
- LSTACK_LOG(INFO, LSTACK, "DEV_RX_OFFLOAD_IPV4_CKSUM\n");
|
||||
- }
|
||||
-#endif
|
||||
-
|
||||
- // rx tcp
|
||||
-#if CHECKSUM_CHECK_TCP_HW
|
||||
- if (rx_ol_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
|
||||
- rx_ol |= DEV_RX_OFFLOAD_TCP_CKSUM;
|
||||
- LSTACK_LOG(INFO, LSTACK, "DEV_RX_OFFLOAD_TCP_CKSUM\n");
|
||||
- }
|
||||
-#endif
|
||||
-
|
||||
- // tx ip
|
||||
-#if CHECKSUM_GEN_IP_HW
|
||||
- if (tx_ol_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
|
||||
- tx_ol |= DEV_TX_OFFLOAD_IPV4_CKSUM;
|
||||
- LSTACK_LOG(INFO, LSTACK, "DEV_TX_OFFLOAD_IPV4_CKSUM\n");
|
||||
- }
|
||||
-#endif
|
||||
-
|
||||
- // tx tcp
|
||||
-#if CHECKSUM_GEN_TCP_HW
|
||||
- if (tx_ol_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
|
||||
- tx_ol |= DEV_TX_OFFLOAD_TCP_CKSUM;
|
||||
- LSTACK_LOG(INFO, LSTACK, "DEV_TX_OFFLOAD_TCP_CKSUM\n");
|
||||
- }
|
||||
-#endif
|
||||
- if (!(rx_ol & DEV_RX_OFFLOAD_TCP_CKSUM) || !(rx_ol & DEV_RX_OFFLOAD_IPV4_CKSUM)) {
|
||||
- rx_ol = 0;
|
||||
- }
|
||||
- if (!(tx_ol & DEV_TX_OFFLOAD_TCP_CKSUM) || !(tx_ol & DEV_TX_OFFLOAD_IPV4_CKSUM)) {
|
||||
- tx_ol = 0;
|
||||
- }
|
||||
-
|
||||
- conf->rxmode.offloads = rx_ol;
|
||||
- conf->txmode.offloads = tx_ol;
|
||||
-
|
||||
- LSTACK_LOG(INFO, LSTACK, "set checksum offloads\n");
|
||||
-#endif /* CHECKSUM_OFFLOAD_ALL */
|
||||
-
|
||||
- return 0;
|
||||
+ return get_protocol_stack_group()->tx_offload;
|
||||
}
|
||||
|
||||
static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info)
|
||||
@@ -471,8 +415,11 @@ int32_t dpdk_ethdev_init(void)
|
||||
}
|
||||
eth_params_checksum(ð_params->conf, &dev_info);
|
||||
int32_t rss_enable = eth_params_rss(ð_params->conf, &dev_info);
|
||||
- get_protocol_stack_group()->eth_params = eth_params;
|
||||
- get_protocol_stack_group()->port_id = eth_params->port_id;
|
||||
+ struct protocol_stack_group *stack_group = get_protocol_stack_group();
|
||||
+ stack_group->eth_params = eth_params;
|
||||
+ stack_group->port_id = eth_params->port_id;
|
||||
+ stack_group->rx_offload = eth_params->conf.rxmode.offloads;
|
||||
+ stack_group->tx_offload = eth_params->conf.txmode.offloads;
|
||||
|
||||
ret = rte_eth_dev_configure(port_id, nb_queues, nb_queues, ð_params->conf);
|
||||
if (ret < 0) {
|
||||
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
|
||||
index 8a6aa9d..e5eedd7 100644
|
||||
--- a/src/lstack/include/lstack_protocol_stack.h
|
||||
+++ b/src/lstack/include/lstack_protocol_stack.h
|
||||
@@ -70,6 +70,8 @@ struct protocol_stack_group {
|
||||
sem_t thread_phase1;
|
||||
sem_t ethdev_init;
|
||||
sem_t all_init;
|
||||
+ uint64_t rx_offload;
|
||||
+ uint64_t tx_offload;
|
||||
struct rte_mempool *kni_pktmbuf_pool;
|
||||
struct eth_params *eth_params;
|
||||
struct protocol_stack *stacks[PROTOCOL_STACK_MAX];
|
||||
diff --git a/src/ltran/ltran_ethdev.c b/src/ltran/ltran_ethdev.c
|
||||
index 7d42fcd..03c692d 100644
|
||||
--- a/src/ltran/ltran_ethdev.c
|
||||
+++ b/src/ltran/ltran_ethdev.c
|
||||
@@ -237,19 +237,31 @@ static int32_t ltran_single_slave_port_init(uint16_t port_num, struct rte_mempoo
|
||||
uint16_t rx_queue_num = (uint16_t)get_ltran_config()->bond.rx_queue_num;
|
||||
uint16_t tx_queue_num = (uint16_t)get_ltran_config()->bond.tx_queue_num;
|
||||
struct rte_eth_dev_info dev_info;
|
||||
- struct rte_eth_conf port_conf = {0};
|
||||
uint16_t queue_id;
|
||||
|
||||
+ rte_eth_dev_stop(port_num);
|
||||
+
|
||||
+ if (rte_eth_dev_info_get(port_num, &dev_info) != 0) {
|
||||
+ LTRAN_ERR("Fail rte_eth_dev_info_get\n");
|
||||
+ return GAZELLE_ERR;
|
||||
+ }
|
||||
+
|
||||
+ struct rte_eth_conf port_conf = {0};
|
||||
+ port_conf.txmode.mq_mode = ETH_MQ_TX_NONE;
|
||||
+ port_conf.link_speeds = ETH_LINK_SPEED_AUTONEG;
|
||||
+ eth_params_checksum(&port_conf, &dev_info);
|
||||
port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
|
||||
|
||||
- rte_eth_dev_stop(port_num);
|
||||
- int32_t ret = rte_eth_dev_configure(port_num, rx_queue_num, tx_queue_num, &port_conf);
|
||||
- if (ret != 0) {
|
||||
- LTRAN_ERR("rte_eth_dev_configure failed in slave port initialize. errno: %d, port: %d\n", ret, port_num);
|
||||
+ struct ltran_config *ltran_config = get_ltran_config();
|
||||
+ ltran_config->dpdk.rx_offload = port_conf.rxmode.offloads;
|
||||
+ ltran_config->dpdk.tx_offload = port_conf.txmode.offloads;
|
||||
+
|
||||
+ if (rte_eth_dev_configure(port_num, rx_queue_num, tx_queue_num, &port_conf)) {
|
||||
+ LTRAN_ERR("rte_eth_dev_configure failed in slave port initialize. errno: %d, port: %hu\n", errno, port_num);
|
||||
return GAZELLE_ERR;
|
||||
}
|
||||
|
||||
- ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_num, &rx_ring_size, &tx_ring_size);
|
||||
+ int32_t ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_num, &rx_ring_size, &tx_ring_size);
|
||||
if (ret != 0) {
|
||||
LTRAN_ERR("rte_eth_dev_adjust_nb_rx_tx_desc failed in slave port initialize. errno: %d, port: %d \n", ret,
|
||||
port_num);
|
||||
@@ -266,7 +278,6 @@ static int32_t ltran_single_slave_port_init(uint16_t port_num, struct rte_mempoo
|
||||
}
|
||||
}
|
||||
|
||||
- rte_eth_dev_info_get(port_num, &dev_info);
|
||||
for (queue_id = 0; queue_id < tx_queue_num; queue_id++) {
|
||||
ret = rte_eth_tx_queue_setup(port_num, queue_id, tx_ring_size, (uint32_t)rte_eth_dev_socket_id(port_num),
|
||||
&dev_info.default_txconf);
|
||||
@@ -345,10 +356,25 @@ static int32_t ltran_bond_port_attr_set(uint16_t port_num, uint16_t bond_port_id
|
||||
uint16_t rx_queue_num = (uint16_t)ltran_config->bond.rx_queue_num;
|
||||
uint16_t tx_queue_num = (uint16_t)ltran_config->bond.tx_queue_num;
|
||||
|
||||
+ int32_t ret = ltran_eth_bond_slave(port_info, port_num, bond_port_id);
|
||||
+ if (ret < 0) {
|
||||
+ LTRAN_ERR("rte_eth_bond_slave_add failed with bond port num: %d, errno: %d \n", port_num, ret);
|
||||
+ return GAZELLE_ERR;
|
||||
+ }
|
||||
+
|
||||
+ struct rte_eth_dev_info dev_info;
|
||||
+ if (rte_eth_dev_info_get(bond_port_id, &dev_info) != 0) {
|
||||
+ LTRAN_ERR("faile rte_eth_dev_info_get\n");
|
||||
+ return GAZELLE_ERR;
|
||||
+ }
|
||||
+
|
||||
struct rte_eth_conf port_conf = {0};
|
||||
port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
|
||||
+ port_conf.txmode.mq_mode = ETH_MQ_TX_NONE;
|
||||
+ port_conf.link_speeds = ETH_LINK_SPEED_AUTONEG;
|
||||
+ eth_params_checksum(&port_conf, &dev_info);
|
||||
|
||||
- int32_t ret = rte_eth_dev_configure(bond_port_id, rx_queue_num, tx_queue_num, &port_conf);
|
||||
+ ret = rte_eth_dev_configure(bond_port_id, rx_queue_num, tx_queue_num, &port_conf);
|
||||
if (ret != 0) {
|
||||
LTRAN_ERR("rte_eth_dev_configure failed with bond port num: %d, errno: %d \n", port_num, ret);
|
||||
return GAZELLE_ERR;
|
||||
@@ -362,12 +388,6 @@ static int32_t ltran_bond_port_attr_set(uint16_t port_num, uint16_t bond_port_id
|
||||
LTRAN_DEBUG("Bond port adujst rx_ring_size: %hu, tx_ring_size: %hu. bond port num: %hu \n",
|
||||
rx_ring_size, tx_ring_size, port_num);
|
||||
|
||||
- ret = ltran_eth_bond_slave(port_info, port_num, bond_port_id);
|
||||
- if (ret < 0) {
|
||||
- LTRAN_ERR("rte_eth_bond_slave_add failed with bond port num: %d, errno: %d \n", port_num, ret);
|
||||
- return GAZELLE_ERR;
|
||||
- }
|
||||
-
|
||||
ret = ltran_eth_rx_queue_setup(bond_port_id, pktmbuf_rxpool, rx_queue_num, rx_ring_size);
|
||||
if (ret < 0) {
|
||||
LTRAN_ERR("rte_eth_rx_queue_setup failed in bond port initialize. errno: %d, port: %d \n", ret, port_num);
|
||||
diff --git a/src/ltran/ltran_instance.c b/src/ltran/ltran_instance.c
|
||||
index f8bb43f..15f4bb4 100644
|
||||
--- a/src/ltran/ltran_instance.c
|
||||
+++ b/src/ltran/ltran_instance.c
|
||||
@@ -450,6 +450,7 @@ int32_t handle_reg_msg_proc_mem(int32_t fd, struct reg_request_msg *recv_msg)
|
||||
struct reg_response_msg send_msg;
|
||||
struct client_proc_conf *conf = &recv_msg->msg.proc;
|
||||
struct gazelle_instance *instance = NULL;
|
||||
+ struct ltran_config *ltran_config = get_ltran_config();
|
||||
|
||||
(void)memset_s(&send_msg, sizeof(send_msg), 0, sizeof(send_msg));
|
||||
|
||||
@@ -479,6 +480,8 @@ int32_t handle_reg_msg_proc_mem(int32_t fd, struct reg_request_msg *recv_msg)
|
||||
|
||||
send_msg.msg.socket_size = instance->socket_size;
|
||||
send_msg.msg.base_virtaddr = instance->base_virtaddr;
|
||||
+ send_msg.msg.rx_offload = ltran_config->dpdk.rx_offload;
|
||||
+ send_msg.msg.tx_offload = ltran_config->dpdk.tx_offload;
|
||||
send_msg.type = RSP_OK;
|
||||
ret = write_specied_len(fd, (char *)&send_msg, sizeof(send_msg));
|
||||
if (ret != 0) {
|
||||
diff --git a/src/ltran/ltran_param.h b/src/ltran/ltran_param.h
|
||||
index d3af24e..442694c 100644
|
||||
--- a/src/ltran/ltran_param.h
|
||||
+++ b/src/ltran/ltran_param.h
|
||||
@@ -25,6 +25,8 @@ struct ltran_config {
|
||||
char **dpdk_argv;
|
||||
int32_t dpdk_argc;
|
||||
int32_t kni_switch;
|
||||
+ uint64_t rx_offload;
|
||||
+ uint64_t tx_offload;
|
||||
} dpdk;
|
||||
|
||||
struct {
|
||||
--
|
||||
2.23.0
|
||||
|
||||
287
0057-add-examples-readme-compile-components-main-file-and.patch
Normal file
287
0057-add-examples-readme-compile-components-main-file-and.patch
Normal file
@ -0,0 +1,287 @@
|
||||
From f02d373216f17fa6c9ca500e49d7f05f876d22a2 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?=E6=9D=A8=E6=B4=8B?= <yyangoO@outlook.com>
|
||||
Date: Wed, 29 Jun 2022 14:33:23 +0800
|
||||
Subject: [PATCH 02/19] add examples readme, compile components, main file and
|
||||
utilities header
|
||||
|
||||
---
|
||||
examples/CMakeLists.txt | 34 ++++++++++++++++++++
|
||||
examples/README.md | 44 +++++++++++++++++++++++++
|
||||
examples/inc/parameter.h | 65 +++++++++++++++++++++++++++++++++++++
|
||||
examples/inc/utilities.h | 69 ++++++++++++++++++++++++++++++++++++++++
|
||||
examples/main.c | 23 ++++++++++++++
|
||||
5 files changed, 235 insertions(+)
|
||||
create mode 100644 examples/CMakeLists.txt
|
||||
create mode 100644 examples/README.md
|
||||
create mode 100644 examples/inc/parameter.h
|
||||
create mode 100644 examples/inc/utilities.h
|
||||
create mode 100644 examples/main.c
|
||||
|
||||
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 0000000..0fd09ab
|
||||
--- /dev/null
|
||||
+++ b/examples/CMakeLists.txt
|
||||
@@ -0,0 +1,34 @@
|
||||
+# Copyright (c) 2022-2023. yyangoO.
|
||||
+# gazelle is licensed under the Mulan PSL v2.
|
||||
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+# You may obtain a copy of Mulan PSL v2 at:
|
||||
+# http://license.coscl.org.cn/MulanPSL2
|
||||
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+# PURPOSE.
|
||||
+# See the Mulan PSL v2 for more details.
|
||||
+
|
||||
+
|
||||
+cmake_minimum_required(VERSION 3.12.1)
|
||||
+
|
||||
+set(PROJECT_NAME example)
|
||||
+
|
||||
+project(${PROJECT_NAME})
|
||||
+
|
||||
+message(STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR})
|
||||
+message(STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR})
|
||||
+
|
||||
+set(CMAKE_C_FLAGS "-O2 -g -fstack-protector-strong -Wall -Werror -pthread")
|
||||
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D EXAMPLE_COMPILE")
|
||||
+
|
||||
+include_directories(${PROJECT_SOURCE_DIR}/inc)
|
||||
+
|
||||
+set(HEADERS
|
||||
+ inc/utilities.h
|
||||
+ inc/parameter.h
|
||||
+)
|
||||
+set(SOURCES
|
||||
+ main.c
|
||||
+)
|
||||
+
|
||||
+add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
||||
diff --git a/examples/README.md b/examples/README.md
|
||||
new file mode 100644
|
||||
index 0000000..f5dc76f
|
||||
--- /dev/null
|
||||
+++ b/examples/README.md
|
||||
@@ -0,0 +1,44 @@
|
||||
+# gazzle 示例程序
|
||||
+
|
||||
+* 支持 TCP 、 unix 非阻塞通讯。
|
||||
+* 支持多线程网络 IO 复用模型,线程之间相互独立。TCP 的 `listen` 、`epoll` 、`read` 、`write` 、`connect` 等接口都在同一线程内。`connect` 连接数可配。
|
||||
+* 支持多线程网络非对称模型,一个 listen 线程,若干个读写线程。listen 线程和读写线程使用 `poll` / `epoll` 监听事件。
|
||||
+* 支持 `recvmsg` 、`sendmsg` 、`recv` 、`send` 、`getpeername` 、`getsockopt` 、`epoll_ctl` 等 posix 接口。
|
||||
+* 网络通讯报文采用问答方式,丢包或者内容错误则报错并停止通讯。报文内容有变化,长度可配。
|
||||
+
|
||||
+## 网络模型
|
||||
+
|
||||
+* **单线程非阻塞**:采用同步非阻塞 IO 模型,在单线程中采用非阻塞的方式监听并发起 IO 请求,当内核中数据到达后读取数据、执行业务逻辑并发送。
|
||||
+* **多线程非阻塞IO复用**:基于 `epoll` 实现多线程非阻塞 IO 模型。每个线程之间互不干涉。通过 `epoll` 监控多个当前线程负责的 fd ,当任何一个数据状态准备就绪时,返回并执行读写操作和对应的业务逻辑。
|
||||
+* **多线程非阻塞非对称**:采用基于 `epoll` 的单线程多路 IO 复用监听连接事件,并采用多线程的方式完成后续读写监听业务。 server 在启动监听之前,开辟一定数量的线程,用线程池管理。主线程创建监听 `fd` 之后,采用多路 IO 复用机制 (`epoll`) 进行 IO 状态监控。当监听到客户端的连接请求时,建立连接并将相关 `fd` 分发给线程池的某个线程进行监听。线程池中的每个线程都采用多路 IO 复用机制 (`epoll`) ,用来监听主线程中建立成功并分发下来的 `socket` 。
|
||||
+
|
||||
+## 程序接口
|
||||
+
|
||||
+* `--as [server | client]`:作为服务端还是客户端。
|
||||
+ * `server`:作为服务端。
|
||||
+ * `client`:作为客户端。
|
||||
+* `--ip [xxx.xxx.xxx.xxx]`:IP地址。
|
||||
+* `--port [xxxx]`:端口。
|
||||
+* `--model [-mum | -mud]` :采用的网络模型类型。
|
||||
+ * `-mum (multi thread, unblock, multiplexing IO)`:多线程非阻塞IO复用。
|
||||
+ * `-mud (multi thread, unblock, dissymmetric)`:多线程非阻塞非对称。
|
||||
+* `--threadnum`:线程数设置。
|
||||
+* `--connectnum`:连接数设置。
|
||||
+* `--api [unix | posix]`:内部实现的接口类型。
|
||||
+ * `unix` :基于 unix 接口实现。
|
||||
+ * `posix` :基于 posix 接口实现。
|
||||
+* `--pktlen [xxxx]`:报文长度配置。
|
||||
+* `--verify [on | off]`:是否校验报文。
|
||||
+* `--ringpmd [on | off]`:是否基于 dpkg ring PMD 收发环回。
|
||||
+* `--help [--xxx]`:获得帮助信息。
|
||||
+
|
||||
+## 使用
|
||||
+
|
||||
+```
|
||||
+cd build
|
||||
+mkdir examples
|
||||
+cd examples
|
||||
+cmake ../../examples
|
||||
+make
|
||||
+./examples --help
|
||||
+```
|
||||
diff --git a/examples/inc/parameter.h b/examples/inc/parameter.h
|
||||
new file mode 100644
|
||||
index 0000000..7912862
|
||||
--- /dev/null
|
||||
+++ b/examples/inc/parameter.h
|
||||
@@ -0,0 +1,65 @@
|
||||
+/*
|
||||
+* Copyright (c) 2022-2023. yyangoO.
|
||||
+* gazelle is licensed under the Mulan PSL v2.
|
||||
+* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+* You may obtain a copy of Mulan PSL v2 at:
|
||||
+* http://license.coscl.org.cn/MulanPSL2
|
||||
+* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+* PURPOSE.
|
||||
+* See the Mulan PSL v2 for more details.
|
||||
+*/
|
||||
+
|
||||
+
|
||||
+#ifndef __PARAMETER_H__
|
||||
+#define __PARAMETER_H__
|
||||
+
|
||||
+
|
||||
+#include "utilities.h"
|
||||
+
|
||||
+
|
||||
+/**
|
||||
+ * @brief porgram parameter
|
||||
+ * The porgram's parameters.
|
||||
+ */
|
||||
+struct ProgramParams
|
||||
+{
|
||||
+ char* as; ///< as server or client
|
||||
+ char* ip; ///< IP address
|
||||
+ uint32_t port; ///< port
|
||||
+ char* model; ///< model type
|
||||
+ uint32_t thread_num; ///< the number of threads
|
||||
+ uint32_t connect_num; ///< the connection number
|
||||
+ char* api; ///< the type of api
|
||||
+ uint32_t pktlen; ///< the packet length
|
||||
+ bool verify; ///< if we verify the message or not
|
||||
+ bool ringpmd; ///< if we use ring PMD or not
|
||||
+};
|
||||
+
|
||||
+
|
||||
+/**
|
||||
+ * @brief initialize the parameters
|
||||
+ * This function initializes the parameters of main function.
|
||||
+ * @param params the parameters pointer
|
||||
+ */
|
||||
+void program_params_init(struct ProgramParams *params);
|
||||
+
|
||||
+/**
|
||||
+ * @brief parse the parameters
|
||||
+ * This function parses the parameters of main function.
|
||||
+ * @param params the parameters pointer
|
||||
+ * @param argc the count of arguments
|
||||
+ * @param argv the value of arguments
|
||||
+ * @return the result flag
|
||||
+ */
|
||||
+int32_t program_params_parse(struct ProgramParams *params, int argc, char *argv[]);
|
||||
+
|
||||
+/**
|
||||
+ * @brief print the parameters
|
||||
+ * This function prints the parameters of main function.
|
||||
+ * @param params the parameters pointer
|
||||
+ */
|
||||
+void program_params_print(struct ProgramParams *params);
|
||||
+
|
||||
+
|
||||
+#endif // __PARAMETER_H__
|
||||
diff --git a/examples/inc/utilities.h b/examples/inc/utilities.h
|
||||
new file mode 100644
|
||||
index 0000000..d800531
|
||||
--- /dev/null
|
||||
+++ b/examples/inc/utilities.h
|
||||
@@ -0,0 +1,69 @@
|
||||
+/*
|
||||
+* Copyright (c) 2022-2023. yyangoO.
|
||||
+* gazelle is licensed under the Mulan PSL v2.
|
||||
+* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+* You may obtain a copy of Mulan PSL v2 at:
|
||||
+* http://license.coscl.org.cn/MulanPSL2
|
||||
+* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+* PURPOSE.
|
||||
+* See the Mulan PSL v2 for more details.
|
||||
+*/
|
||||
+
|
||||
+
|
||||
+#ifndef __UTILITIES_H__
|
||||
+#define __UTILITIES_H__
|
||||
+
|
||||
+
|
||||
+#include <string.h>
|
||||
+#include <stdio.h>
|
||||
+#include <stdbool.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <stddef.h>
|
||||
+#include <inttypes.h>
|
||||
+
|
||||
+#include <unistd.h>
|
||||
+#include <pthread.h>
|
||||
+
|
||||
+#include <sys/types.h>
|
||||
+
|
||||
+
|
||||
+#define PRINT_ERROR(str) do \
|
||||
+ { \
|
||||
+ printf("\n[error]: "); \
|
||||
+ printf(str); \
|
||||
+ printf("\n"); \
|
||||
+ } while(0)
|
||||
+#define PRINT_WARNNING(str) do \
|
||||
+ { \
|
||||
+ printf("\n[warnning]: "); \
|
||||
+ printf(str); \
|
||||
+ printf("\n"); \
|
||||
+ } while(0)
|
||||
+#define LIMIT_VAL_RANGE(val, min, max) ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val)))
|
||||
+#define CHECK_VAL_RANGE(val, min, max) ((val) < (min) ? (false) : ((val) > (max) ? (false) : (true)))
|
||||
+
|
||||
+#define PROGRAM_OK (0) ///< program ok flag
|
||||
+#define PROGRAM_FINISH (1) ///< program finish flag
|
||||
+#define PROGRAM_FAULT (-1) ///< program fault flag
|
||||
+
|
||||
+#define UNIX_TCP_PORT_MIN (1024) ///< TCP minimum port number in unix
|
||||
+#define UNIX_TCP_PORT_MAX (65535) ///< TCP minimum port number in unix
|
||||
+#define THREAD_NUM_MIN (1) ///< minimum number of thead
|
||||
+#define THREAD_NUM_MAX (1000) ///< maximum number of thead
|
||||
+#define MESSAGE_PKTLEN_MIN (1) ///< minimum length of message (1 byte)
|
||||
+#define MESSAGE_PKTLEN_MAX (10485760) ///< maximum length of message (10 Mb)
|
||||
+
|
||||
+#define DEFAULT_PARAM_AS ("server") ///< default type
|
||||
+#define DEFAULT_PARAM_IP ("127.0.0.1") ///< default IP
|
||||
+#define DEFAULT_PARAM_PORT (5050) ///< default port
|
||||
+#define DEFAULT_PARAM_MODEL ("mum") ///< default model type
|
||||
+#define DEFAULT_PARAM_CONNECT_NUM (10) ///< default connection number
|
||||
+#define DEFAULT_PARAM_THREAD_NUM (8) ///< default thread number
|
||||
+#define DEFAULT_PARAM_API ("posix") ///< default API type
|
||||
+#define DEFAULT_PARAM_PKTLEN (1024) ///< default packet length of message
|
||||
+#define DEFAULT_PARAM_VERIFY (true) ///< default flag of message verifying
|
||||
+#define DEFAULT_PARAM_RINGPMD (false) ///< default flag of ring PMD
|
||||
+
|
||||
+
|
||||
+#endif // __UTILITIES_H__
|
||||
diff --git a/examples/main.c b/examples/main.c
|
||||
new file mode 100644
|
||||
index 0000000..30d04e6
|
||||
--- /dev/null
|
||||
+++ b/examples/main.c
|
||||
@@ -0,0 +1,23 @@
|
||||
+/*
|
||||
+* Copyright (c) 2022-2023. yyangoO.
|
||||
+* gazelle is licensed under the Mulan PSL v2.
|
||||
+* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+* You may obtain a copy of Mulan PSL v2 at:
|
||||
+* http://license.coscl.org.cn/MulanPSL2
|
||||
+* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+* PURPOSE.
|
||||
+* See the Mulan PSL v2 for more details.
|
||||
+*/
|
||||
+
|
||||
+
|
||||
+#include "utilities.h"
|
||||
+#include "parameter.h"
|
||||
+
|
||||
+
|
||||
+int32_t main(int argc, char *argv[])
|
||||
+{
|
||||
+ int32_t ret = PROGRAM_OK;
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
--
|
||||
2.23.0
|
||||
|
||||
550
0058-add-examples-parameter-parsing.patch
Normal file
550
0058-add-examples-parameter-parsing.patch
Normal file
@ -0,0 +1,550 @@
|
||||
From 69be15c6a29d05c6b7f95e8fb778f79f51cf9240 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?=E6=9D=A8=E6=B4=8B?= <yyangoO@outlook.com>
|
||||
Date: Mon, 11 Jul 2022 20:10:25 +0800
|
||||
Subject: [PATCH 03/19] add examples parameter parsing
|
||||
|
||||
---
|
||||
examples/CMakeLists.txt | 1 +
|
||||
examples/README.md | 30 ++---
|
||||
examples/inc/parameter.h | 68 +++++++++-
|
||||
examples/inc/utilities.h | 34 ++---
|
||||
examples/main.c | 11 ++
|
||||
examples/src/parameter.c | 267 +++++++++++++++++++++++++++++++++++++++
|
||||
6 files changed, 372 insertions(+), 39 deletions(-)
|
||||
create mode 100644 examples/src/parameter.c
|
||||
|
||||
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
|
||||
index 0fd09ab..2e62bd3 100644
|
||||
--- a/examples/CMakeLists.txt
|
||||
+++ b/examples/CMakeLists.txt
|
||||
@@ -29,6 +29,7 @@ set(HEADERS
|
||||
)
|
||||
set(SOURCES
|
||||
main.c
|
||||
+ src/parameter.c
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
||||
diff --git a/examples/README.md b/examples/README.md
|
||||
index f5dc76f..6f82bb2 100644
|
||||
--- a/examples/README.md
|
||||
+++ b/examples/README.md
|
||||
@@ -14,23 +14,23 @@
|
||||
|
||||
## 程序接口
|
||||
|
||||
-* `--as [server | client]`:作为服务端还是客户端。
|
||||
+* `-a, --as [server | client]`:作为服务端还是客户端。
|
||||
* `server`:作为服务端。
|
||||
* `client`:作为客户端。
|
||||
-* `--ip [xxx.xxx.xxx.xxx]`:IP地址。
|
||||
-* `--port [xxxx]`:端口。
|
||||
-* `--model [-mum | -mud]` :采用的网络模型类型。
|
||||
- * `-mum (multi thread, unblock, multiplexing IO)`:多线程非阻塞IO复用。
|
||||
- * `-mud (multi thread, unblock, dissymmetric)`:多线程非阻塞非对称。
|
||||
-* `--threadnum`:线程数设置。
|
||||
-* `--connectnum`:连接数设置。
|
||||
-* `--api [unix | posix]`:内部实现的接口类型。
|
||||
- * `unix` :基于 unix 接口实现。
|
||||
- * `posix` :基于 posix 接口实现。
|
||||
-* `--pktlen [xxxx]`:报文长度配置。
|
||||
-* `--verify [on | off]`:是否校验报文。
|
||||
-* `--ringpmd [on | off]`:是否基于 dpkg ring PMD 收发环回。
|
||||
-* `--help [--xxx]`:获得帮助信息。
|
||||
+* `-i, --ip [xxx.xxx.xxx.xxx]`:IP地址。
|
||||
+* `-p, --port [xxxx]`:端口。
|
||||
+* `-m, --model [mum | mud]`:采用的网络模型类型。
|
||||
+ * `mum (multi thread, unblock, multiplexing IO)`:多线程非阻塞IO复用。
|
||||
+ * `mud (multi thread, unblock, dissymmetric)`:多线程非阻塞非对称。
|
||||
+* `-t, --threadnum`:线程数设置。
|
||||
+* `-c, --connectnum`:连接数设置。
|
||||
+* `-A, --api [unix | posix]`:内部实现的接口类型。
|
||||
+ * `unix`:基于 unix 接口实现。
|
||||
+ * `posix`:基于 posix 接口实现。
|
||||
+* `-P, --pktlen [xxxx]`:报文长度配置。
|
||||
+* `-v, --verify`:是否校验报文。
|
||||
+* `-r, --ringpmd`:是否基于dpdk ring PMD 收发环回。
|
||||
+* `-h, --help`:获得帮助信息。
|
||||
|
||||
## 使用
|
||||
|
||||
diff --git a/examples/inc/parameter.h b/examples/inc/parameter.h
|
||||
index 7912862..fe0dce0 100644
|
||||
--- a/examples/inc/parameter.h
|
||||
+++ b/examples/inc/parameter.h
|
||||
@@ -11,13 +11,67 @@
|
||||
*/
|
||||
|
||||
|
||||
-#ifndef __PARAMETER_H__
|
||||
-#define __PARAMETER_H__
|
||||
+#ifndef __EXAMPLES_PARAMETER_H__
|
||||
+#define __EXAMPLES_PARAMETER_H__
|
||||
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
|
||||
+#define PARAM_DEFAULT_AS ("server") ///< default type
|
||||
+#define PARAM_DEFAULT_IP ("127.0.0.1") ///< default IP
|
||||
+#define PARAM_DEFAULT_PORT (5050) ///< default port
|
||||
+#define PARAM_DEFAULT_MODEL ("mum") ///< default model type
|
||||
+#define PARAM_DEFAULT_CONNECT_NUM (10) ///< default connection number
|
||||
+#define PARAM_DEFAULT_THREAD_NUM (8) ///< default thread number
|
||||
+#define PARAM_DEFAULT_API ("posix") ///< default API type
|
||||
+#define PARAM_DEFAULT_PKTLEN (1024) ///< default packet length of message
|
||||
+#define PARAM_DEFAULT_VERIFY (false) ///< default flag of message verifying
|
||||
+#define PARAM_DEFAULT_RINGPMD (false) ///< default flag of ring PMD of dpdk
|
||||
+
|
||||
+enum
|
||||
+{
|
||||
+#define PARAM_NAME_AS ("as") ///< name of parameter type
|
||||
+ PARAM_NUM_AS = 'a',
|
||||
+#define PARAM_NAME_IP ("ip") ///< name of parameter IP
|
||||
+ PARAM_NUM_IP = 'i',
|
||||
+#define PARAM_NAME_PORT ("port") ///< name of parameter port
|
||||
+ PARAM_NUM_PORT = 'p',
|
||||
+#define PARAM_NAME_MODEL ("model") ///< name of parameter model type
|
||||
+ PARAM_NUM_MODEL = 'm',
|
||||
+#define PARAM_NAME_CONNECT_NUM ("connectnum") ///< name of parameter connection number
|
||||
+ PARAM_NUM_CONNECT_NUM = 'c',
|
||||
+#define PARAM_NAME_THREAD_NUM ("threadnum") ///< name of parameter thread number
|
||||
+ PARAM_NUM_THREAD_NUM = 't',
|
||||
+#define PARAM_NAME_API ("api") ///< name of parameter API type
|
||||
+ PARAM_NUM_API = 'A',
|
||||
+#define PARAM_NAME_PKTLEN ("pktlen") ///< name of parameter packet length of message
|
||||
+ PARAM_NUM_PKTLEN = 'P',
|
||||
+#define PARAM_NAME_VERIFY ("verify") ///< name of parameter flag of message verifying
|
||||
+ PARAM_NUM_VERIFY = 'v',
|
||||
+#define PARAM_NAME_RINGPMD ("ringpmd") ///< name of parameter flag of ring PMD of dpdk
|
||||
+ PARAM_NUM_RINGPMD = 'r',
|
||||
+#define PARAM_NAME_HELP ("help") ///< name of parameter help
|
||||
+ PARAM_NUM_HELP = 'h',
|
||||
+};
|
||||
+
|
||||
+#define NO_ARGUMENT 0 ///< options takes no arguments
|
||||
+#define REQUIRED_ARGUMETN 1 ///< options requires arguments
|
||||
+#define OPTIONAL_ARGUMETN 2 ///< options arguments are optional
|
||||
+
|
||||
+
|
||||
+/**
|
||||
+ * @brief program option description
|
||||
+ * The program option description.
|
||||
+ */
|
||||
+struct ProgramOption
|
||||
+{
|
||||
+ const char *name; ///< name of program option
|
||||
+ int32_t has_arg; ///< whether program option takes an argument, one of no, required, and optional
|
||||
+ int32_t *flag; ///< if not `NULL`, set `*flag` to `val` when option found
|
||||
+ int32_t val; ///< the number of this program option
|
||||
+};
|
||||
+
|
||||
/**
|
||||
* @brief porgram parameter
|
||||
* The porgram's parameters.
|
||||
@@ -44,6 +98,12 @@ struct ProgramParams
|
||||
*/
|
||||
void program_params_init(struct ProgramParams *params);
|
||||
|
||||
+/**
|
||||
+ * @brief print help information
|
||||
+ * This function prints help informations.
|
||||
+ */
|
||||
+void program_params_help(void);
|
||||
+
|
||||
/**
|
||||
* @brief parse the parameters
|
||||
* This function parses the parameters of main function.
|
||||
@@ -52,7 +112,7 @@ void program_params_init(struct ProgramParams *params);
|
||||
* @param argv the value of arguments
|
||||
* @return the result flag
|
||||
*/
|
||||
-int32_t program_params_parse(struct ProgramParams *params, int argc, char *argv[]);
|
||||
+int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char *argv[]);
|
||||
|
||||
/**
|
||||
* @brief print the parameters
|
||||
@@ -62,4 +122,4 @@ int32_t program_params_parse(struct ProgramParams *params, int argc, char *argv[
|
||||
void program_params_print(struct ProgramParams *params);
|
||||
|
||||
|
||||
-#endif // __PARAMETER_H__
|
||||
+#endif // __EXAMPLES_PARAMETER_H__
|
||||
diff --git a/examples/inc/utilities.h b/examples/inc/utilities.h
|
||||
index d800531..bccd523 100644
|
||||
--- a/examples/inc/utilities.h
|
||||
+++ b/examples/inc/utilities.h
|
||||
@@ -11,8 +11,8 @@
|
||||
*/
|
||||
|
||||
|
||||
-#ifndef __UTILITIES_H__
|
||||
-#define __UTILITIES_H__
|
||||
+#ifndef __EXAMPLES_UTILITIES_H__
|
||||
+#define __EXAMPLES_UTILITIES_H__
|
||||
|
||||
|
||||
#include <string.h>
|
||||
@@ -21,30 +21,35 @@
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
-
|
||||
#include <unistd.h>
|
||||
+#include <ctype.h>
|
||||
+
|
||||
#include <pthread.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
+#include <sys/socket.h>
|
||||
|
||||
+#include <netinet/in.h>
|
||||
+#include <arpa/inet.h>
|
||||
|
||||
-#define PRINT_ERROR(str) do \
|
||||
+
|
||||
+#define PRINT_ERROR(format, ...) do \
|
||||
{ \
|
||||
printf("\n[error]: "); \
|
||||
- printf(str); \
|
||||
+ printf(format, ##__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while(0)
|
||||
-#define PRINT_WARNNING(str) do \
|
||||
+#define PRINT_WARNNING(format, ...) do \
|
||||
{ \
|
||||
printf("\n[warnning]: "); \
|
||||
- printf(str); \
|
||||
+ printf(format, ##__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while(0)
|
||||
#define LIMIT_VAL_RANGE(val, min, max) ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val)))
|
||||
#define CHECK_VAL_RANGE(val, min, max) ((val) < (min) ? (false) : ((val) > (max) ? (false) : (true)))
|
||||
|
||||
#define PROGRAM_OK (0) ///< program ok flag
|
||||
-#define PROGRAM_FINISH (1) ///< program finish flag
|
||||
+#define PROGRAM_ABORT (1) ///< program abort flag
|
||||
#define PROGRAM_FAULT (-1) ///< program fault flag
|
||||
|
||||
#define UNIX_TCP_PORT_MIN (1024) ///< TCP minimum port number in unix
|
||||
@@ -54,16 +59,5 @@
|
||||
#define MESSAGE_PKTLEN_MIN (1) ///< minimum length of message (1 byte)
|
||||
#define MESSAGE_PKTLEN_MAX (10485760) ///< maximum length of message (10 Mb)
|
||||
|
||||
-#define DEFAULT_PARAM_AS ("server") ///< default type
|
||||
-#define DEFAULT_PARAM_IP ("127.0.0.1") ///< default IP
|
||||
-#define DEFAULT_PARAM_PORT (5050) ///< default port
|
||||
-#define DEFAULT_PARAM_MODEL ("mum") ///< default model type
|
||||
-#define DEFAULT_PARAM_CONNECT_NUM (10) ///< default connection number
|
||||
-#define DEFAULT_PARAM_THREAD_NUM (8) ///< default thread number
|
||||
-#define DEFAULT_PARAM_API ("posix") ///< default API type
|
||||
-#define DEFAULT_PARAM_PKTLEN (1024) ///< default packet length of message
|
||||
-#define DEFAULT_PARAM_VERIFY (true) ///< default flag of message verifying
|
||||
-#define DEFAULT_PARAM_RINGPMD (false) ///< default flag of ring PMD
|
||||
-
|
||||
|
||||
-#endif // __UTILITIES_H__
|
||||
+#endif // __EXAMPLES_UTILITIES_H__
|
||||
diff --git a/examples/main.c b/examples/main.c
|
||||
index 30d04e6..ed3abef 100644
|
||||
--- a/examples/main.c
|
||||
+++ b/examples/main.c
|
||||
@@ -13,11 +13,22 @@
|
||||
|
||||
#include "utilities.h"
|
||||
#include "parameter.h"
|
||||
+#include "server.h"
|
||||
+
|
||||
+
|
||||
+static struct ProgramParams prog_params;
|
||||
|
||||
|
||||
int32_t main(int argc, char *argv[])
|
||||
{
|
||||
int32_t ret = PROGRAM_OK;
|
||||
|
||||
+ program_params_init(&prog_params);
|
||||
+ ret = program_params_parse(&prog_params, argc, argv);
|
||||
+ if (PROGRAM_ABORT == ret) {
|
||||
+ return ret;
|
||||
+ }
|
||||
+ program_params_print(&prog_params);
|
||||
+
|
||||
return ret;
|
||||
}
|
||||
diff --git a/examples/src/parameter.c b/examples/src/parameter.c
|
||||
new file mode 100644
|
||||
index 0000000..8abcc68
|
||||
--- /dev/null
|
||||
+++ b/examples/src/parameter.c
|
||||
@@ -0,0 +1,267 @@
|
||||
+/*
|
||||
+* Copyright (c) 2022-2023. yyangoO.
|
||||
+* gazelle is licensed under the Mulan PSL v2.
|
||||
+* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+* You may obtain a copy of Mulan PSL v2 at:
|
||||
+* http://license.coscl.org.cn/MulanPSL2
|
||||
+* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+* PURPOSE.
|
||||
+* See the Mulan PSL v2 for more details.
|
||||
+*/
|
||||
+
|
||||
+
|
||||
+#include "parameter.h"
|
||||
+
|
||||
+
|
||||
+// program short options
|
||||
+const char prog_short_opts[] = \
|
||||
+ "a:" // as
|
||||
+ "i:" // ip
|
||||
+ "p:" // port
|
||||
+ "m:" // model
|
||||
+ "t:" // thread number
|
||||
+ "c:" // connect number
|
||||
+ "A:" // api
|
||||
+ "P:" // pktlen
|
||||
+ "v" // verify
|
||||
+ "r" // ringpmd
|
||||
+ "h" // help
|
||||
+ ;
|
||||
+
|
||||
+// program long options
|
||||
+const struct ProgramOption prog_long_opts[] = \
|
||||
+{
|
||||
+ {PARAM_NAME_AS, REQUIRED_ARGUMETN, NULL, PARAM_NUM_AS},
|
||||
+ {PARAM_NAME_IP, REQUIRED_ARGUMETN, NULL, PARAM_NUM_IP},
|
||||
+ {PARAM_NAME_PORT, REQUIRED_ARGUMETN, NULL, PARAM_NUM_PORT},
|
||||
+ {PARAM_NAME_MODEL, REQUIRED_ARGUMETN, NULL, PARAM_NUM_MODEL},
|
||||
+ {PARAM_NAME_THREAD_NUM, REQUIRED_ARGUMETN, NULL, PARAM_NUM_THREAD_NUM},
|
||||
+ {PARAM_NAME_CONNECT_NUM, REQUIRED_ARGUMETN, NULL, PARAM_NUM_CONNECT_NUM},
|
||||
+ {PARAM_NAME_API, REQUIRED_ARGUMETN, NULL, PARAM_NUM_API},
|
||||
+ {PARAM_NAME_PKTLEN, REQUIRED_ARGUMETN, NULL, PARAM_NUM_PKTLEN},
|
||||
+ {PARAM_NAME_VERIFY, NO_ARGUMENT, NULL, PARAM_NUM_VERIFY},
|
||||
+ {PARAM_NAME_RINGPMD, NO_ARGUMENT, NULL, PARAM_NUM_RINGPMD},
|
||||
+ {PARAM_NAME_HELP, NO_ARGUMENT, NULL, PARAM_NUM_HELP},
|
||||
+};
|
||||
+
|
||||
+
|
||||
+// get long options
|
||||
+int getopt_long(int argc, char * const argv[], const char *optstring, const struct ProgramOption *long_opts, int *long_idx);
|
||||
+
|
||||
+
|
||||
+// set `as` parameter
|
||||
+void program_param_prase_as(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ if (0 == strcmp(arg, "server") || 0 == strcmp(arg, "client")) {
|
||||
+ params->as = arg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `ip` parameter
|
||||
+void program_param_prase_ip(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ if (INADDR_NONE == inet_addr(arg)) {
|
||||
+ params->ip = arg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `port` parameter
|
||||
+void program_param_prase_port(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ int32_t port_arg = atoi(optarg);
|
||||
+ if (CHECK_VAL_RANGE(port_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX)) {
|
||||
+ params->port = (uint32_t)port_arg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `model` parameter
|
||||
+void program_param_prase_model(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ if (0 == strcmp(optarg, "mum") || 0 == strcmp(optarg, "mud")) {
|
||||
+ params->model = optarg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `connect_num` parameter
|
||||
+void program_param_prase_connectnum(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ int32_t connectnum_arg = atoi(optarg);
|
||||
+ if (0 < connectnum_arg) {
|
||||
+ params->connect_num = (uint32_t)connectnum_arg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `thread_num` parameter
|
||||
+void program_param_prase_threadnum(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ int32_t threadnum_arg = atoi(optarg);
|
||||
+ if (CHECK_VAL_RANGE(threadnum_arg, THREAD_NUM_MIN, THREAD_NUM_MAX)) {
|
||||
+ params->thread_num = (uint32_t)threadnum_arg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `api` parameter
|
||||
+void program_param_prase_api(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ if (0 == strcmp(optarg, "unix") || 0 == strcmp(optarg, "posix")) {
|
||||
+ params->api = optarg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// set `pktlen` parameter
|
||||
+void program_param_prase_pktlen(struct ProgramParams *params, char *arg, const char *name)
|
||||
+{
|
||||
+ int32_t pktlen_arg = atoi(optarg);
|
||||
+ if (CHECK_VAL_RANGE(pktlen_arg, MESSAGE_PKTLEN_MIN, MESSAGE_PKTLEN_MAX)) {
|
||||
+ params->pktlen = (uint32_t)pktlen_arg;
|
||||
+ }
|
||||
+ else {
|
||||
+ PRINT_ERROR("illigal argument -- %s \n", name);
|
||||
+ exit(PROGRAM_ABORT);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// initialize the parameters
|
||||
+void program_params_init(struct ProgramParams *params)
|
||||
+{
|
||||
+ params->as = PARAM_DEFAULT_AS;
|
||||
+ params->ip = PARAM_DEFAULT_IP;
|
||||
+ params->port = PARAM_DEFAULT_PORT;
|
||||
+ params->model = PARAM_DEFAULT_MODEL;
|
||||
+ params->thread_num = PARAM_DEFAULT_CONNECT_NUM;
|
||||
+ params->connect_num = PARAM_DEFAULT_THREAD_NUM;
|
||||
+ params->api = PARAM_DEFAULT_API;
|
||||
+ params->pktlen = PARAM_DEFAULT_PKTLEN;
|
||||
+ params->verify = PARAM_DEFAULT_VERIFY;
|
||||
+ params->ringpmd = PARAM_DEFAULT_RINGPMD;
|
||||
+}
|
||||
+
|
||||
+// print program helps
|
||||
+void program_params_help(void)
|
||||
+{
|
||||
+ printf("\n");
|
||||
+ printf("-a, --as [server | client]: set programas server or client. \n");
|
||||
+ printf(" server: as server. \n");
|
||||
+ printf(" client: as client. \n");
|
||||
+ printf("-i, --ip [xxx.xxx.xxx.xxx]: set ip address. \n");
|
||||
+ printf("-p, --port [xxxx]: set port number in range of %d - %d. \n", UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX);
|
||||
+ printf("-m, --model [mum | mud]: set the network model. \n");
|
||||
+ printf(" mum: multi thread, unblock, multiplexing IO network model. \n");
|
||||
+ printf(" mud: multi thread, unblock, dissymmetric network model. \n");
|
||||
+ printf("-t, --threadnum [xxxx]: set thread number in range of %d - %d. \n", THREAD_NUM_MIN, THREAD_NUM_MAX);
|
||||
+ printf("-c, --connectnum [xxxx]: set thread number of connection. \n");
|
||||
+ printf("-A, --api [unix | posix]: set api type is server or client. \n");
|
||||
+ printf(" unix: use unix's api. \n");
|
||||
+ printf(" posix: use posix api. \n");
|
||||
+ printf("-P, --pktlen [xxxx]: set packet length in range of %d - %d. \n", MESSAGE_PKTLEN_MIN, MESSAGE_PKTLEN_MAX);
|
||||
+ printf("-v, --verify: set to verifying the message packet. \n");
|
||||
+ printf("-r, --ringpmd: set use ringpmd. \n");
|
||||
+ printf("-h, --help: see helps. \n");
|
||||
+ printf("\n");
|
||||
+}
|
||||
+
|
||||
+// parse the parameters
|
||||
+int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char *argv[])
|
||||
+{
|
||||
+ int32_t c;
|
||||
+
|
||||
+ while (true) {
|
||||
+ int32_t opt_idx = 0;
|
||||
+
|
||||
+ c = getopt_long(argc, argv, prog_short_opts, prog_long_opts, &opt_idx);
|
||||
+
|
||||
+ if (-1 == c) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ switch (c) {
|
||||
+ case (PARAM_NUM_AS):
|
||||
+ program_param_prase_as(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_IP):
|
||||
+ program_param_prase_ip(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_PORT):
|
||||
+ program_param_prase_port(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_MODEL):
|
||||
+ program_param_prase_model(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_CONNECT_NUM):
|
||||
+ program_param_prase_connectnum(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_THREAD_NUM):
|
||||
+ program_param_prase_threadnum(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_API):
|
||||
+ program_param_prase_api(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_PKTLEN):
|
||||
+ program_param_prase_pktlen(params, optarg, prog_long_opts[opt_idx].name);
|
||||
+ break;
|
||||
+ case (PARAM_NUM_VERIFY):
|
||||
+ params->verify = true;
|
||||
+ break;
|
||||
+ case (PARAM_NUM_RINGPMD):
|
||||
+ params->ringpmd = true;
|
||||
+ break;
|
||||
+ case (PARAM_NUM_HELP):
|
||||
+ program_params_help();
|
||||
+ return PROGRAM_ABORT;
|
||||
+ case ('?'):
|
||||
+ return PROGRAM_ABORT;
|
||||
+ default:
|
||||
+ program_params_help();
|
||||
+ return PROGRAM_ABORT;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return PROGRAM_OK;
|
||||
+}
|
||||
+
|
||||
+// print the parameters
|
||||
+void program_params_print(struct ProgramParams *params)
|
||||
+{
|
||||
+ printf("\n");
|
||||
+ printf("[program parameters]: \n");
|
||||
+ printf("--> [as]: %s \n", params->as);
|
||||
+ printf("--> [ip]: %s \n", params->ip);
|
||||
+ printf("--> [port]: %u \n", params->port);
|
||||
+ printf("--> [model]: %s \n", params->model);
|
||||
+ printf("--> [thread number]: %u \n", params->thread_num);
|
||||
+ printf("--> [connection number]: %u \n", params->connect_num);
|
||||
+ printf("--> [api]: %s \n", params->api);
|
||||
+ printf("--> [packet length]: %u \n", params->pktlen);
|
||||
+ printf("--> [verify]: %s \n", (true == params->verify) ? "on" : "off");
|
||||
+ printf("--> [ringpmd]: %s \n", (true == params->ringpmd) ? "on" : "off");
|
||||
+ printf("\n");
|
||||
+}
|
||||
--
|
||||
2.23.0
|
||||
|
||||
58
0059-lstack-core-fix-reta_conf-array-size-calculation.patch
Normal file
58
0059-lstack-core-fix-reta_conf-array-size-calculation.patch
Normal file
@ -0,0 +1,58 @@
|
||||
From 11f46783f88912e3c204fc12d4f33034f371881b Mon Sep 17 00:00:00 2001
|
||||
From: Honggang LI <honggangli@163.com>
|
||||
Date: Thu, 23 Jun 2022 13:36:36 +0800
|
||||
Subject: [PATCH 19/40] lstack/core: fix reta_conf array size calculation
|
||||
|
||||
When dev_info.reta_size is smaller than RTE_RETA_GROUP_SIZE, the first
|
||||
parameter (nmemb) of calloc is zero.
|
||||
|
||||
If nmemb is 0, then calloc() returns either NULL, or a unique pointer
|
||||
value that can later be successfully passed to free(). When non-NULL
|
||||
unique pointer was returned, rss_setup() will failed because of garbage
|
||||
value in memory pointed by the unique pointer.
|
||||
|
||||
Signed-off-by: Honggang LI <honggangli@163.com>
|
||||
---
|
||||
src/lstack/core/lstack_dpdk.c | 12 ++++++++----
|
||||
1 file changed, 8 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
|
||||
index df0332b..3f0dbb4 100644
|
||||
--- a/src/lstack/core/lstack_dpdk.c
|
||||
+++ b/src/lstack/core/lstack_dpdk.c
|
||||
@@ -428,6 +428,7 @@ static int rss_setup(const int port_id, const uint16_t nb_queues)
|
||||
int ret;
|
||||
struct rte_eth_dev_info dev_info;
|
||||
struct rte_eth_rss_reta_entry64 *reta_conf = NULL;
|
||||
+ size_t reta_conf_size, n;
|
||||
|
||||
rte_eth_dev_info_get(port_id, &dev_info);
|
||||
|
||||
@@ -435,8 +436,11 @@ static int rss_setup(const int port_id, const uint16_t nb_queues)
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
- reta_conf = calloc(dev_info.reta_size / RTE_RETA_GROUP_SIZE,
|
||||
- sizeof(struct rte_eth_rss_reta_entry64));
|
||||
+ reta_conf_size = dev_info.reta_size / RTE_RETA_GROUP_SIZE;
|
||||
+ if (dev_info.reta_size % RTE_RETA_GROUP_SIZE)
|
||||
+ reta_conf_size += 1;
|
||||
+
|
||||
+ reta_conf = calloc(reta_conf_size, sizeof(struct rte_eth_rss_reta_entry64));
|
||||
if (!reta_conf) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
@@ -446,8 +450,8 @@ static int rss_setup(const int port_id, const uint16_t nb_queues)
|
||||
one_reta_conf->reta[i % RTE_RETA_GROUP_SIZE] = i % nb_queues;
|
||||
}
|
||||
|
||||
- for (i = 0; i < dev_info.reta_size / RTE_RETA_GROUP_SIZE; i++) {
|
||||
- struct rte_eth_rss_reta_entry64 *one_reta_conf = &reta_conf[i];
|
||||
+ for (n = 0; n < reta_conf_size; n++) {
|
||||
+ struct rte_eth_rss_reta_entry64 *one_reta_conf = &reta_conf[n];
|
||||
one_reta_conf->mask = 0xFFFFFFFFFFFFFFFFULL;
|
||||
}
|
||||
|
||||
--
|
||||
2.23.0
|
||||
|
||||
39
0060-Replace-gettid-with-rte_gettid.patch
Normal file
39
0060-Replace-gettid-with-rte_gettid.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From e1c6c79565a549866fbe7cb770a6f09183676c0b Mon Sep 17 00:00:00 2001
|
||||
From: Honggang LI <honggangli@163.com>
|
||||
Date: Wed, 13 Jul 2022 09:50:06 +0800
|
||||
Subject: [PATCH 07/19] Replace gettid() with rte_gettid()
|
||||
|
||||
Signed-off-by: Honggang LI <honggangli@163.com>
|
||||
---
|
||||
src/lstack/core/lstack_protocol_stack.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
|
||||
index a1f3790..2acf77a 100644
|
||||
--- a/src/lstack/core/lstack_protocol_stack.c
|
||||
+++ b/src/lstack/core/lstack_protocol_stack.c
|
||||
@@ -67,10 +67,10 @@ static inline void set_stack_idx(uint16_t idx)
|
||||
|
||||
long get_stack_tid(void)
|
||||
{
|
||||
- static PER_THREAD long g_stack_tid = 0;
|
||||
+ static PER_THREAD int32_t g_stack_tid = 0;
|
||||
|
||||
if (g_stack_tid == 0) {
|
||||
- g_stack_tid = syscall(__NR_gettid);
|
||||
+ g_stack_tid = rte_gettid();
|
||||
}
|
||||
|
||||
return g_stack_tid;
|
||||
@@ -245,7 +245,7 @@ static int32_t init_stack_value(struct protocol_stack *stack, uint16_t queue_id)
|
||||
memset_s(stack, sizeof(*stack), 0, sizeof(*stack));
|
||||
|
||||
set_stack_idx(queue_id);
|
||||
- stack->tid = gettid();
|
||||
+ stack->tid = rte_gettid();
|
||||
stack->queue_id = queue_id;
|
||||
stack->port_id = stack_group->port_id;
|
||||
stack->cpu_id = get_global_cfg_params()->cpus[queue_id];
|
||||
--
|
||||
2.23.0
|
||||
|
||||
190
0061-modify-the-code-for-canonical-and-update-the-cmake-b.patch
Normal file
190
0061-modify-the-code-for-canonical-and-update-the-cmake-b.patch
Normal file
@ -0,0 +1,190 @@
|
||||
From 3ddd9dadcdd3bf5b451f0170f88b9f4957eceb26 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?=E6=9D=A8=E6=B4=8B?= <yyangoO@outlook.com>
|
||||
Date: Tue, 12 Jul 2022 20:55:33 +0800
|
||||
Subject: [PATCH 08/19] modify the code for canonical and update the cmake
|
||||
build components
|
||||
|
||||
---
|
||||
examples/CMakeLists.txt | 13 +++----------
|
||||
examples/inc/utilities.h | 14 ++++++++++++++
|
||||
examples/main.c | 3 +--
|
||||
examples/src/parameter.c | 22 +++++++++++-----------
|
||||
4 files changed, 29 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
|
||||
index 2e62bd3..b1c2b07 100644
|
||||
--- a/examples/CMakeLists.txt
|
||||
+++ b/examples/CMakeLists.txt
|
||||
@@ -23,13 +23,6 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D EXAMPLE_COMPILE")
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/inc)
|
||||
|
||||
-set(HEADERS
|
||||
- inc/utilities.h
|
||||
- inc/parameter.h
|
||||
-)
|
||||
-set(SOURCES
|
||||
- main.c
|
||||
- src/parameter.c
|
||||
-)
|
||||
-
|
||||
-add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
||||
+aux_source_directory(${PROJECT_SOURCE_DIR}/src SOURCES)
|
||||
+
|
||||
+add_executable(${PROJECT_NAME} main.c ${SOURCES})
|
||||
diff --git a/examples/inc/utilities.h b/examples/inc/utilities.h
|
||||
index bccd523..b594469 100644
|
||||
--- a/examples/inc/utilities.h
|
||||
+++ b/examples/inc/utilities.h
|
||||
@@ -24,10 +24,12 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
+#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
+#include <sys/epoll.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
@@ -45,6 +47,18 @@
|
||||
printf(format, ##__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while(0)
|
||||
+#define PRINT_SERVER(format, ...) do \
|
||||
+ { \
|
||||
+ printf("<server>: "); \
|
||||
+ printf(format, ##__VA_ARGS__); \
|
||||
+ printf("\n"); \
|
||||
+ } while(0)
|
||||
+#define PRINT_CLIENT(format, ...) do \
|
||||
+ { \
|
||||
+ printf("<client>: "); \
|
||||
+ printf(format, ##__VA_ARGS__); \
|
||||
+ printf("\n"); \
|
||||
+ } while(0)
|
||||
#define LIMIT_VAL_RANGE(val, min, max) ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val)))
|
||||
#define CHECK_VAL_RANGE(val, min, max) ((val) < (min) ? (false) : ((val) > (max) ? (false) : (true)))
|
||||
|
||||
diff --git a/examples/main.c b/examples/main.c
|
||||
index ed3abef..a7daded 100644
|
||||
--- a/examples/main.c
|
||||
+++ b/examples/main.c
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include "utilities.h"
|
||||
#include "parameter.h"
|
||||
-#include "server.h"
|
||||
|
||||
|
||||
static struct ProgramParams prog_params;
|
||||
@@ -25,7 +24,7 @@ int32_t main(int argc, char *argv[])
|
||||
|
||||
program_params_init(&prog_params);
|
||||
ret = program_params_parse(&prog_params, argc, argv);
|
||||
- if (PROGRAM_ABORT == ret) {
|
||||
+ if (ret == PROGRAM_ABORT) {
|
||||
return ret;
|
||||
}
|
||||
program_params_print(&prog_params);
|
||||
diff --git a/examples/src/parameter.c b/examples/src/parameter.c
|
||||
index 8abcc68..ff3bcbc 100644
|
||||
--- a/examples/src/parameter.c
|
||||
+++ b/examples/src/parameter.c
|
||||
@@ -53,7 +53,7 @@ int getopt_long(int argc, char * const argv[], const char *optstring, const stru
|
||||
// set `as` parameter
|
||||
void program_param_prase_as(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
- if (0 == strcmp(arg, "server") || 0 == strcmp(arg, "client")) {
|
||||
+ if (strcmp(arg, "server") == 0 || strcmp(arg, "client") == 0) {
|
||||
params->as = arg;
|
||||
}
|
||||
else {
|
||||
@@ -65,7 +65,7 @@ void program_param_prase_as(struct ProgramParams *params, char *arg, const char
|
||||
// set `ip` parameter
|
||||
void program_param_prase_ip(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
- if (INADDR_NONE == inet_addr(arg)) {
|
||||
+ if (inet_addr(arg) != INADDR_NONE) {
|
||||
params->ip = arg;
|
||||
}
|
||||
else {
|
||||
@@ -78,7 +78,7 @@ void program_param_prase_ip(struct ProgramParams *params, char *arg, const char
|
||||
void program_param_prase_port(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
int32_t port_arg = atoi(optarg);
|
||||
- if (CHECK_VAL_RANGE(port_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX)) {
|
||||
+ if (CHECK_VAL_RANGE(port_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX) == true) {
|
||||
params->port = (uint32_t)port_arg;
|
||||
}
|
||||
else {
|
||||
@@ -90,7 +90,7 @@ void program_param_prase_port(struct ProgramParams *params, char *arg, const cha
|
||||
// set `model` parameter
|
||||
void program_param_prase_model(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
- if (0 == strcmp(optarg, "mum") || 0 == strcmp(optarg, "mud")) {
|
||||
+ if (strcmp(optarg, "mum") == 0 || strcmp(optarg, "mud") == 0) {
|
||||
params->model = optarg;
|
||||
}
|
||||
else {
|
||||
@@ -103,7 +103,7 @@ void program_param_prase_model(struct ProgramParams *params, char *arg, const ch
|
||||
void program_param_prase_connectnum(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
int32_t connectnum_arg = atoi(optarg);
|
||||
- if (0 < connectnum_arg) {
|
||||
+ if (connectnum_arg > 0) {
|
||||
params->connect_num = (uint32_t)connectnum_arg;
|
||||
}
|
||||
else {
|
||||
@@ -116,7 +116,7 @@ void program_param_prase_connectnum(struct ProgramParams *params, char *arg, con
|
||||
void program_param_prase_threadnum(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
int32_t threadnum_arg = atoi(optarg);
|
||||
- if (CHECK_VAL_RANGE(threadnum_arg, THREAD_NUM_MIN, THREAD_NUM_MAX)) {
|
||||
+ if (CHECK_VAL_RANGE(threadnum_arg, THREAD_NUM_MIN, THREAD_NUM_MAX) == true) {
|
||||
params->thread_num = (uint32_t)threadnum_arg;
|
||||
}
|
||||
else {
|
||||
@@ -128,7 +128,7 @@ void program_param_prase_threadnum(struct ProgramParams *params, char *arg, cons
|
||||
// set `api` parameter
|
||||
void program_param_prase_api(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
- if (0 == strcmp(optarg, "unix") || 0 == strcmp(optarg, "posix")) {
|
||||
+ if (strcmp(optarg, "unix") == 0 || strcmp(optarg, "posix") == 0) {
|
||||
params->api = optarg;
|
||||
}
|
||||
else {
|
||||
@@ -141,7 +141,7 @@ void program_param_prase_api(struct ProgramParams *params, char *arg, const char
|
||||
void program_param_prase_pktlen(struct ProgramParams *params, char *arg, const char *name)
|
||||
{
|
||||
int32_t pktlen_arg = atoi(optarg);
|
||||
- if (CHECK_VAL_RANGE(pktlen_arg, MESSAGE_PKTLEN_MIN, MESSAGE_PKTLEN_MAX)) {
|
||||
+ if (CHECK_VAL_RANGE(pktlen_arg, MESSAGE_PKTLEN_MIN, MESSAGE_PKTLEN_MAX) == true) {
|
||||
params->pktlen = (uint32_t)pktlen_arg;
|
||||
}
|
||||
else {
|
||||
@@ -157,8 +157,8 @@ void program_params_init(struct ProgramParams *params)
|
||||
params->ip = PARAM_DEFAULT_IP;
|
||||
params->port = PARAM_DEFAULT_PORT;
|
||||
params->model = PARAM_DEFAULT_MODEL;
|
||||
- params->thread_num = PARAM_DEFAULT_CONNECT_NUM;
|
||||
- params->connect_num = PARAM_DEFAULT_THREAD_NUM;
|
||||
+ params->thread_num = PARAM_DEFAULT_THREAD_NUM;
|
||||
+ params->connect_num = PARAM_DEFAULT_CONNECT_NUM;
|
||||
params->api = PARAM_DEFAULT_API;
|
||||
params->pktlen = PARAM_DEFAULT_PKTLEN;
|
||||
params->verify = PARAM_DEFAULT_VERIFY;
|
||||
@@ -199,7 +199,7 @@ int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char *
|
||||
|
||||
c = getopt_long(argc, argv, prog_short_opts, prog_long_opts, &opt_idx);
|
||||
|
||||
- if (-1 == c) {
|
||||
+ if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
--
|
||||
2.23.0
|
||||
|
||||
46
0062-enable-secure-compile-and-open-compile-log.patch
Normal file
46
0062-enable-secure-compile-and-open-compile-log.patch
Normal file
@ -0,0 +1,46 @@
|
||||
From 2e36e8a3885563d12eac0e5cbed56ddaf1d28e27 Mon Sep 17 00:00:00 2001
|
||||
From: jiangheng <jiangheng14@huawei.com>
|
||||
Date: Thu, 14 Jul 2022 22:05:57 +0800
|
||||
Subject: [PATCH 09/19] enable-secure-compile-and-open-compile-log
|
||||
|
||||
---
|
||||
src/lstack/Makefile | 2 +-
|
||||
src/ltran/CMakeLists.txt | 5 +++--
|
||||
2 files changed, 4 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/lstack/Makefile b/src/lstack/Makefile
|
||||
index 8fc2435..98289d8 100644
|
||||
--- a/src/lstack/Makefile
|
||||
+++ b/src/lstack/Makefile
|
||||
@@ -21,7 +21,7 @@ OPTIMIZATION = -O2 -g
|
||||
RM = rm -f
|
||||
LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck
|
||||
|
||||
-SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC
|
||||
+SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2
|
||||
|
||||
INC = -I$(LSTACK_DIR)/include \
|
||||
-I$(LSTACK_DIR)/../common \
|
||||
diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt
|
||||
index c21d88a..970bc1b 100644
|
||||
--- a/src/ltran/CMakeLists.txt
|
||||
+++ b/src/ltran/CMakeLists.txt
|
||||
@@ -13,7 +13,8 @@ project(ltran)
|
||||
|
||||
set(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common)
|
||||
|
||||
-set(CMAKE_C_FLAGS "-O2 -g -fstack-protector-strong -Wall -Werror -fPIE -pie -pthread")
|
||||
+set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
+set(CMAKE_C_FLAGS "-g -fstack-protector-strong -Wall -Werror -fPIE -pie -pthread -D_FORTIFY_SOURCE=2 -O2 -fPIC")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D LTRAN_COMPILE")
|
||||
|
||||
if($ENV{GAZELLE_COVERAGE_ENABLE})
|
||||
@@ -57,4 +58,4 @@ set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--w
|
||||
|
||||
add_executable(gazellectl ltran_dfx.c ${COMMON_DIR}/gazelle_dfx_msg.c)
|
||||
target_include_directories(gazellectl PRIVATE $ENV{DPDK_INCLUDE_FILE} ${COMMON_DIR})
|
||||
-target_link_libraries(gazellectl PRIVATE boundscheck)
|
||||
+target_link_libraries(gazellectl PRIVATE boundscheck -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack)
|
||||
--
|
||||
2.23.0
|
||||
|
||||
27
0063-support-epoll-et-trig-mode.patch
Normal file
27
0063-support-epoll-et-trig-mode.patch
Normal file
@ -0,0 +1,27 @@
|
||||
From 6114f85920ac4d24b73d892a1ebe1890efd48a3a Mon Sep 17 00:00:00 2001
|
||||
From: jiangheng <jiangheng14@huawei.com>
|
||||
Date: Thu, 14 Jul 2022 22:16:04 +0800
|
||||
Subject: [PATCH 10/19] support-epoll-et-trig-mode
|
||||
|
||||
---
|
||||
src/lstack/api/lstack_epoll.c | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
|
||||
index 4978f02..5d7a4b8 100644
|
||||
--- a/src/lstack/api/lstack_epoll.c
|
||||
+++ b/src/lstack/api/lstack_epoll.c
|
||||
@@ -288,6 +288,10 @@ static int32_t epoll_lwip_event(struct wakeup_poll *wakeup, struct epoll_event *
|
||||
accept_num++;
|
||||
}
|
||||
|
||||
+ if (sock->epoll_events & EPOLLET) {
|
||||
+ list_del_node_null(&sock->event_list);
|
||||
+ }
|
||||
+
|
||||
events[event_num].events = sock->events;
|
||||
events[event_num].data = sock->ep_data;
|
||||
event_num++;
|
||||
--
|
||||
2.23.0
|
||||
|
||||
169
0064-lstack-support-low-power.patch
Normal file
169
0064-lstack-support-low-power.patch
Normal file
@ -0,0 +1,169 @@
|
||||
From 314689e509a2ddc491eb1bf6ecd40f1a8e6be3db Mon Sep 17 00:00:00 2001
|
||||
From: jiangheng <jiangheng14@huawei.com>
|
||||
Date: Thu, 14 Jul 2022 22:19:54 +0800
|
||||
Subject: [PATCH 11/19] lstack support low power
|
||||
|
||||
---
|
||||
src/lstack/core/lstack_protocol_stack.c | 57 ++++++++++++++--------
|
||||
src/lstack/include/lstack_ethdev.h | 1 -
|
||||
src/lstack/include/lstack_protocol_stack.h | 1 +
|
||||
src/lstack/netif/lstack_ethdev.c | 10 ----
|
||||
4 files changed, 38 insertions(+), 31 deletions(-)
|
||||
|
||||
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
|
||||
index 2acf77a..595b97e 100644
|
||||
--- a/src/lstack/core/lstack_protocol_stack.c
|
||||
+++ b/src/lstack/core/lstack_protocol_stack.c
|
||||
@@ -132,9 +132,18 @@ struct protocol_stack *get_bind_protocol_stack(void)
|
||||
return stack_group->stacks[index];
|
||||
}
|
||||
|
||||
-void lstack_low_power_idling(void)
|
||||
+static uint32_t get_protocol_traffic(struct protocol_stack *stack)
|
||||
+{
|
||||
+ if (use_ltran()) {
|
||||
+ return rte_ring_count(stack->rx_ring) + rte_ring_count(stack->tx_ring);
|
||||
+ }
|
||||
+
|
||||
+ /* only lstack mode, have not appropriate method to get traffic */
|
||||
+ return LSTACK_LPM_RX_PKTS + 1;
|
||||
+}
|
||||
+
|
||||
+void low_power_idling(struct protocol_stack *stack)
|
||||
{
|
||||
- static PER_THREAD uint32_t wakeup_flag = 0;
|
||||
static PER_THREAD uint32_t last_cycle_ts = 0;
|
||||
static PER_THREAD uint64_t last_cycle_pkts = 0;
|
||||
struct timespec st = {
|
||||
@@ -147,14 +156,9 @@ void lstack_low_power_idling(void)
|
||||
set the CPU decentralization flag;
|
||||
2. If the number of received packets exceeds the threshold, the authorization mark will end;
|
||||
3. If the number of rx queue packets is less than the threshold, set the CPU delegation flag; */
|
||||
- if (get_global_cfg_params()->low_power_mod == 0) {
|
||||
- wakeup_flag = 0;
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- if (eth_get_flow_cnt() < LSTACK_LPM_RX_PKTS) {
|
||||
- wakeup_flag = 1;
|
||||
+ if (get_protocol_traffic(stack) < LSTACK_LPM_RX_PKTS) {
|
||||
nanosleep(&st, &st);
|
||||
+ stack->low_power = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,18 +169,18 @@ void lstack_low_power_idling(void)
|
||||
uint64_t now_pkts = get_protocol_stack()->stats.rx;
|
||||
uint32_t now_ts = sys_now();
|
||||
if (((now_ts - last_cycle_ts) > LSTACK_LPM_DETECT_MS) ||
|
||||
- (wakeup_flag && ((now_pkts - last_cycle_pkts) >= LSTACK_LPM_PKTS_IN_DETECT))) {
|
||||
- if (!wakeup_flag && ((now_pkts - last_cycle_pkts) < LSTACK_LPM_PKTS_IN_DETECT)) {
|
||||
- wakeup_flag = 1;
|
||||
- } else if (wakeup_flag && ((now_pkts - last_cycle_pkts) >= LSTACK_LPM_PKTS_IN_DETECT)) {
|
||||
- wakeup_flag = 0;
|
||||
+ ((now_pkts - last_cycle_pkts) >= LSTACK_LPM_PKTS_IN_DETECT)) {
|
||||
+ if ((now_pkts - last_cycle_pkts) < LSTACK_LPM_PKTS_IN_DETECT) {
|
||||
+ stack->low_power = true;
|
||||
+ } else {
|
||||
+ stack->low_power = false;
|
||||
}
|
||||
|
||||
last_cycle_ts = now_ts;
|
||||
last_cycle_pkts = now_pkts;
|
||||
}
|
||||
|
||||
- if (wakeup_flag) {
|
||||
+ if (stack->low_power) {
|
||||
nanosleep(&st, &st);
|
||||
}
|
||||
}
|
||||
@@ -221,16 +225,25 @@ static void* gazelle_wakeup_thread(void *arg)
|
||||
uint16_t queue_id = *(uint16_t *)arg;
|
||||
struct protocol_stack *stack = get_protocol_stack_group()->stacks[queue_id];
|
||||
|
||||
- int32_t lcore_id = get_global_cfg_params()->wakeup[stack->queue_id];
|
||||
+ struct cfg_params *cfg = get_global_cfg_params();
|
||||
+ int32_t lcore_id = cfg->wakeup[stack->queue_id];
|
||||
thread_affinity_init(lcore_id);
|
||||
|
||||
+ struct timespec st = {
|
||||
+ .tv_sec = 0,
|
||||
+ .tv_nsec = 1
|
||||
+ };
|
||||
+
|
||||
LSTACK_LOG(INFO, LSTACK, "weakup_%02d start\n", stack->queue_id);
|
||||
|
||||
- sem_t *event_sem[WAKEUP_MAX_NUM];
|
||||
- int num;
|
||||
for (;;) {
|
||||
- num = gazelle_light_ring_dequeue_burst(stack->wakeup_ring, (void **)event_sem, WAKEUP_MAX_NUM);
|
||||
- for (int i = 0; i < num; i++) {
|
||||
+ if (cfg->low_power_mod != 0 && stack->low_power) {
|
||||
+ nanosleep(&st, &st);
|
||||
+ }
|
||||
+
|
||||
+ sem_t *event_sem[WAKEUP_MAX_NUM];
|
||||
+ uint32_t num = gazelle_light_ring_dequeue_burst(stack->wakeup_ring, (void **)event_sem, WAKEUP_MAX_NUM);
|
||||
+ for (uint32_t i = 0; i < num; i++) {
|
||||
sem_post(event_sem[i]);
|
||||
}
|
||||
}
|
||||
@@ -423,6 +436,10 @@ static void* gazelle_stack_thread(void *arg)
|
||||
send_stack_list(stack, SEND_LIST_MAX);
|
||||
|
||||
sys_timer_run();
|
||||
+
|
||||
+ if (get_global_cfg_params()->low_power_mod != 0) {
|
||||
+ low_power_idling(stack);
|
||||
+ }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
diff --git a/src/lstack/include/lstack_ethdev.h b/src/lstack/include/lstack_ethdev.h
|
||||
index 573a413..0e8400f 100644
|
||||
--- a/src/lstack/include/lstack_ethdev.h
|
||||
+++ b/src/lstack/include/lstack_ethdev.h
|
||||
@@ -31,7 +31,6 @@ struct eth_dev_ops {
|
||||
|
||||
int32_t ethdev_init(struct protocol_stack *stack);
|
||||
int32_t eth_dev_poll(void);
|
||||
-uint32_t eth_get_flow_cnt(void);
|
||||
void eth_dev_recv(struct rte_mbuf *mbuf);
|
||||
|
||||
#endif /* __GAZELLE_ETHDEV_H__ */
|
||||
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
|
||||
index e5eedd7..0faeccf 100644
|
||||
--- a/src/lstack/include/lstack_protocol_stack.h
|
||||
+++ b/src/lstack/include/lstack_protocol_stack.h
|
||||
@@ -45,6 +45,7 @@ struct protocol_stack {
|
||||
struct rte_ring *wakeup_ring;
|
||||
struct reg_ring_msg *reg_buf;
|
||||
|
||||
+ volatile bool low_power;
|
||||
volatile uint16_t conn_num __rte_cache_aligned;
|
||||
lockless_queue rpc_queue __rte_cache_aligned;
|
||||
char pad __rte_cache_aligned;
|
||||
diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c
|
||||
index 7938520..0f30d76 100644
|
||||
--- a/src/lstack/netif/lstack_ethdev.c
|
||||
+++ b/src/lstack/netif/lstack_ethdev.c
|
||||
@@ -111,16 +111,6 @@ int32_t eth_dev_poll(void)
|
||||
return nr_pkts;
|
||||
}
|
||||
|
||||
-uint32_t eth_get_flow_cnt(void)
|
||||
-{
|
||||
- if (use_ltran()) {
|
||||
- return rte_ring_count(get_protocol_stack()->rx_ring) + rte_ring_count(get_protocol_stack()->tx_ring);
|
||||
- } else {
|
||||
- /* can't get flow cnt, lstack_low_power_idling don't use this params */
|
||||
- return LSTACK_LPM_RX_PKTS + 1;
|
||||
- }
|
||||
-}
|
||||
-
|
||||
static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf)
|
||||
{
|
||||
struct protocol_stack *stack = get_protocol_stack();
|
||||
--
|
||||
2.23.0
|
||||
|
||||
39
0065-add-port-mask-range-check.patch
Normal file
39
0065-add-port-mask-range-check.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From 324c47ae4bd64bed134f75dc2a9ec93f8161ea26 Mon Sep 17 00:00:00 2001
|
||||
From: jiangheng <jiangheng14@huawei.com>
|
||||
Date: Thu, 14 Jul 2022 22:23:51 +0800
|
||||
Subject: [PATCH 12/19] add-port-mask-range-check
|
||||
|
||||
---
|
||||
src/ltran/ltran_param.c | 11 ++++++++++-
|
||||
1 file changed, 10 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c
|
||||
index aafbeee..cd65531 100644
|
||||
--- a/src/ltran/ltran_param.c
|
||||
+++ b/src/ltran/ltran_param.c
|
||||
@@ -335,12 +335,21 @@ static int32_t parse_bond_ports(const config_t *config, const char *key, struct
|
||||
}
|
||||
|
||||
ltran_config->bond.port_num = separate_str_to_array(port_str, ltran_config->bond.portmask, GAZELLE_MAX_BOND_NUM);
|
||||
- if (ltran_config->bond.port_num >= GAZELLE_MAX_BOND_NUM) {
|
||||
+ if (ltran_config->bond.port_num > GAZELLE_MAX_BOND_NUM) {
|
||||
free(port_str);
|
||||
gazelle_set_errno(GAZELLE_ERANGE);
|
||||
return GAZELLE_ERR;
|
||||
}
|
||||
|
||||
+ for (uint32_t i = 0; i < ltran_config->bond.port_num; i++) {
|
||||
+ if (ltran_config->bond.portmask[i] < GAZELLE_BOND_PORT_MASK_MIN ||
|
||||
+ ltran_config->bond.portmask[i] > GAZELLE_BOND_PORT_MASK_MAX) {
|
||||
+ free(port_str);
|
||||
+ gazelle_set_errno(GAZELLE_ERANGE);
|
||||
+ return GAZELLE_ERR;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
free(port_str);
|
||||
return GAZELLE_OK;
|
||||
}
|
||||
--
|
||||
2.23.0
|
||||
|
||||
125
0066-release-kni-device.patch
Normal file
125
0066-release-kni-device.patch
Normal file
@ -0,0 +1,125 @@
|
||||
From 7fac90c4e7bb0faf7c5341452a7b2a02470748d3 Mon Sep 17 00:00:00 2001
|
||||
From: jiangheng <jiangheng14@huawei.com>
|
||||
Date: Thu, 14 Jul 2022 22:25:44 +0800
|
||||
Subject: [PATCH 13/19] release-kni-device
|
||||
|
||||
---
|
||||
src/common/dpdk_common.c | 11 ++++++++++-
|
||||
src/common/dpdk_common.h | 1 +
|
||||
src/lstack/api/lstack_signal.c | 7 ++++++-
|
||||
src/lstack/core/lstack_init.c | 2 ++
|
||||
src/ltran/main.c | 5 +++--
|
||||
5 files changed, 22 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c
|
||||
index 939d135..8d056f9 100644
|
||||
--- a/src/common/dpdk_common.c
|
||||
+++ b/src/common/dpdk_common.c
|
||||
@@ -184,6 +184,15 @@ int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+void dpdk_kni_release(void)
|
||||
+{
|
||||
+ if (g_pkni) {
|
||||
+ rte_kni_release(g_pkni);
|
||||
+ }
|
||||
+
|
||||
+ g_pkni = NULL;
|
||||
+}
|
||||
+
|
||||
int32_t kni_process_tx(struct rte_mbuf **pkts_burst, uint32_t count)
|
||||
{
|
||||
uint32_t i = rte_kni_tx_burst(g_pkni, pkts_burst, count);
|
||||
@@ -211,4 +220,4 @@ void kni_process_rx(uint16_t port)
|
||||
pkts_burst[i] = NULL;
|
||||
}
|
||||
}
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+}
|
||||
diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h
|
||||
index 6a6a030..2066159 100644
|
||||
--- a/src/common/dpdk_common.h
|
||||
+++ b/src/common/dpdk_common.h
|
||||
@@ -66,6 +66,7 @@ struct rte_kni* get_gazelle_kni(void);
|
||||
int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool);
|
||||
int32_t kni_process_tx(struct rte_mbuf **pkts_burst, uint32_t count);
|
||||
void kni_process_rx(uint16_t port);
|
||||
+void dpdk_kni_release(void);
|
||||
|
||||
struct rte_eth_conf;
|
||||
struct rte_eth_dev_info;
|
||||
diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c
|
||||
index 4dba472..e73bc61 100644
|
||||
--- a/src/lstack/api/lstack_signal.c
|
||||
+++ b/src/lstack/api/lstack_signal.c
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <lwip/lwipsock.h>
|
||||
#include <lwip/posix_api.h>
|
||||
|
||||
+#include "lstack_cfg.h"
|
||||
+#include "dpdk_common.h"
|
||||
#include "lstack_log.h"
|
||||
#include "lstack_control_plane.h"
|
||||
|
||||
@@ -55,9 +57,12 @@ static inline bool match_hijack_signal(int sig)
|
||||
static void lstack_sig_default_handler(int sig)
|
||||
{
|
||||
LSTACK_LOG(ERR, LSTACK, "lstack dumped,caught signal:%d\n", sig);
|
||||
- control_fd_close();
|
||||
dump_stack();
|
||||
lwip_exit();
|
||||
+ if (!use_ltran()) {
|
||||
+ dpdk_kni_release();
|
||||
+ }
|
||||
+ control_fd_close();
|
||||
(void)kill(getpid(), sig);
|
||||
}
|
||||
|
||||
diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c
|
||||
index 78040b0..a506b34 100644
|
||||
--- a/src/lstack/core/lstack_init.c
|
||||
+++ b/src/lstack/core/lstack_init.c
|
||||
@@ -152,6 +152,8 @@ __attribute__((destructor)) void gazelle_network_exit(void)
|
||||
if (ret < 0) {
|
||||
LSTACK_LOG(ERR, LSTACK, "rte_pdump_uninit failed\n");
|
||||
}
|
||||
+
|
||||
+ dpdk_kni_release();
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/ltran/main.c b/src/ltran/main.c
|
||||
index 701df3c..328ca89 100644
|
||||
--- a/src/ltran/main.c
|
||||
+++ b/src/ltran/main.c
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <rte_malloc.h>
|
||||
|
||||
+#include "dpdk_common.h"
|
||||
#include "ltran_config.h"
|
||||
#include "ltran_log.h"
|
||||
#include "ltran_stat.h"
|
||||
@@ -55,6 +56,7 @@ static void sig_default_handler(int32_t sig)
|
||||
{
|
||||
LTRAN_ERR("ltran dumped,caught signal:%d.\n", sig);
|
||||
print_stack();
|
||||
+ dpdk_kni_release();
|
||||
kill(getpid(), sig);
|
||||
}
|
||||
|
||||
@@ -125,8 +127,7 @@ static void ltran_core_destroy(void)
|
||||
gazelle_stack_htable_destroy();
|
||||
gazelle_tcp_conn_htable_destroy();
|
||||
gazelle_tcp_sock_htable_destroy();
|
||||
-
|
||||
- return;
|
||||
+ dpdk_kni_release();
|
||||
}
|
||||
|
||||
static void wait_thread_finish(pthread_t ctrl_thread, uint32_t next_core)
|
||||
--
|
||||
2.23.0
|
||||
|
||||
167
0067-optimize-check-ltran-exist.patch
Normal file
167
0067-optimize-check-ltran-exist.patch
Normal file
@ -0,0 +1,167 @@
|
||||
From 07bb11a2f0b7a1b5e7cf2c965f490d6d83a0b92b Mon Sep 17 00:00:00 2001
|
||||
From: jiangheng <jiangheng14@huawei.com>
|
||||
Date: Thu, 14 Jul 2022 22:28:06 +0800
|
||||
Subject: [PATCH 14/19] optimize check ltran exist
|
||||
|
||||
---
|
||||
src/ltran/ltran_dfx.c | 89 +++++++++++++++++++++++--------------------
|
||||
1 file changed, 47 insertions(+), 42 deletions(-)
|
||||
|
||||
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
|
||||
index 7db1adc..2b71021 100644
|
||||
--- a/src/ltran/ltran_dfx.c
|
||||
+++ b/src/ltran/ltran_dfx.c
|
||||
@@ -52,7 +52,7 @@ static int32_t g_ltran_rate_show_flag = GAZELLE_OFF; // not show when first g
|
||||
static struct gazelle_stat_ltran_total g_last_ltran_total;
|
||||
static struct gazelle_stat_lstack_total g_last_lstack_total[GAZELLE_MAX_STACK_ARRAY_SIZE];
|
||||
|
||||
-static bool g_use_ltran;
|
||||
+static bool g_use_ltran = false;
|
||||
|
||||
/* Use the largest data structure. */
|
||||
#define GAZELLE_CMD_RESP_BUFFER_SIZE (sizeof(struct gazelle_stack_dfx_data) / sizeof(char))
|
||||
@@ -104,23 +104,6 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = {
|
||||
|
||||
static int32_t g_wait_reply = 1;
|
||||
|
||||
-static pid_t ltran_process_exist(void)
|
||||
-{
|
||||
- #define LINE 1024
|
||||
- #define BASE_DEC_SCALE 10
|
||||
- char line[LINE];
|
||||
- FILE *cmd = popen("pidof ltran", "r");
|
||||
-
|
||||
- if (fgets(line, LINE, cmd) == NULL) {
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- pid_t pid = strtoul(line, NULL, BASE_DEC_SCALE);
|
||||
- (void)pclose(cmd);
|
||||
-
|
||||
- return pid;
|
||||
-}
|
||||
-
|
||||
static void gazelle_print_ltran_conn(void *buf, const struct gazelle_stat_msg_request *req_msg)
|
||||
{
|
||||
struct gazelle_stat_forward_table *table = (struct gazelle_stat_forward_table *)buf;
|
||||
@@ -160,7 +143,7 @@ static void gazelle_print_ltran_sock(void *buf, const struct gazelle_stat_msg_re
|
||||
printf("ltran sock table num: %u\n", table->conn_num);
|
||||
}
|
||||
|
||||
-static int32_t dfx_stat_conn_to_ltran(struct gazelle_stat_msg_request *req_msg)
|
||||
+static int32_t dfx_connect_ltran(bool use_ltran, bool probe)
|
||||
{
|
||||
int32_t ret, fd;
|
||||
struct sockaddr_un addr;
|
||||
@@ -177,7 +160,7 @@ static int32_t dfx_stat_conn_to_ltran(struct gazelle_stat_msg_request *req_msg)
|
||||
}
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
- if (g_use_ltran) {
|
||||
+ if (use_ltran) {
|
||||
ret = strncpy_s(addr.sun_path, sizeof(addr.sun_path), GAZELLE_DFX_SOCK_PATHNAME,
|
||||
strlen(GAZELLE_DFX_SOCK_PATHNAME) + 1);
|
||||
if (ret != EOK) {
|
||||
@@ -193,12 +176,24 @@ static int32_t dfx_stat_conn_to_ltran(struct gazelle_stat_msg_request *req_msg)
|
||||
|
||||
ret = connect(fd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un));
|
||||
if (ret == -1) {
|
||||
- printf("connect ltran failed. errno: %d ret=%d\n", errno, ret);
|
||||
+ if (!probe) {
|
||||
+ printf("connect ltran failed. errno: %d ret=%d\n", errno, ret);
|
||||
+ }
|
||||
close(fd);
|
||||
return GAZELLE_ERR;
|
||||
}
|
||||
|
||||
- ret = write_specied_len(fd, (char *)req_msg, sizeof(*req_msg));
|
||||
+ return fd;
|
||||
+}
|
||||
+
|
||||
+static int32_t dfx_stat_conn_to_ltran(struct gazelle_stat_msg_request *req_msg)
|
||||
+{
|
||||
+ int32_t fd = dfx_connect_ltran(g_use_ltran, false);
|
||||
+ if (fd < 0) {
|
||||
+ return fd;
|
||||
+ }
|
||||
+
|
||||
+ int32_t ret = write_specied_len(fd, (char *)req_msg, sizeof(*req_msg));
|
||||
if (ret == -1) {
|
||||
printf("write request msg failed ret=%d\n", ret);
|
||||
close(fd);
|
||||
@@ -899,8 +894,7 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
|
||||
}
|
||||
|
||||
if (i < conn->total_conn_num) {
|
||||
- printf("...\n");
|
||||
- printf("Total connections: %u, display connections: %u\n", conn->total_conn_num, i);
|
||||
+ printf("...\nTotal connections: %u, display connections: %u\n", conn->total_conn_num, i);
|
||||
}
|
||||
|
||||
if (stat->eof != 0) {
|
||||
@@ -1199,29 +1193,13 @@ static int32_t check_cmd_support(struct gazelle_stat_msg_request *req_msg, int32
|
||||
return -1;
|
||||
}
|
||||
|
||||
-int32_t main(int32_t argc, char *argv[])
|
||||
+int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num)
|
||||
{
|
||||
- struct gazelle_stat_msg_request req_msg[GAZELLE_CMD_MAX] = {0};
|
||||
- int32_t req_msg_num, ret;
|
||||
+ int32_t ret;
|
||||
int32_t msg_index = 0;
|
||||
struct gazelle_dfx_list *dfx = NULL;
|
||||
char recv_buf[GAZELLE_CMD_RESP_BUFFER_SIZE + 1] = {0};
|
||||
|
||||
- g_use_ltran = ltran_process_exist() ? true : false;
|
||||
- req_msg_num = parse_dfx_cmd_args(argc, argv, req_msg);
|
||||
- if (req_msg_num <= 0 || req_msg_num > GAZELLE_CMD_MAX) {
|
||||
- show_usage();
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- if (!g_use_ltran) {
|
||||
- g_gazelle_dfx_tbl[GAZELLE_STAT_LSTACK_SHOW].recv_size = sizeof(struct gazelle_stack_dfx_data);
|
||||
- ret = check_cmd_support(req_msg, req_msg_num);
|
||||
- if (ret < 0) {
|
||||
- return -1;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
for (;;) {
|
||||
dfx = find_dfx_node(req_msg[msg_index].stat_mode);
|
||||
if (dfx == NULL) {
|
||||
@@ -1260,3 +1238,30 @@ int32_t main(int32_t argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
+int32_t main(int32_t argc, char *argv[])
|
||||
+{
|
||||
+ struct gazelle_stat_msg_request req_msg[GAZELLE_CMD_MAX] = {0};
|
||||
+ int32_t req_msg_num, ret;
|
||||
+
|
||||
+ int32_t fd = dfx_connect_ltran(true, true);
|
||||
+ if (fd > 0) {
|
||||
+ g_use_ltran = true;
|
||||
+ close(fd);
|
||||
+ }
|
||||
+ req_msg_num = parse_dfx_cmd_args(argc, argv, req_msg);
|
||||
+ if (req_msg_num <= 0 || req_msg_num > GAZELLE_CMD_MAX) {
|
||||
+ show_usage();
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (!g_use_ltran) {
|
||||
+ g_gazelle_dfx_tbl[GAZELLE_STAT_LSTACK_SHOW].recv_size = sizeof(struct gazelle_stack_dfx_data);
|
||||
+ ret = check_cmd_support(req_msg, req_msg_num);
|
||||
+ if (ret < 0) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return dfx_loop(req_msg, req_msg_num);
|
||||
+}
|
||||
--
|
||||
2.23.0
|
||||
|
||||
4389
0068-clean-code.patch
Normal file
4389
0068-clean-code.patch
Normal file
File diff suppressed because it is too large
Load Diff
1163
0069-clean-code.patch
Normal file
1163
0069-clean-code.patch
Normal file
File diff suppressed because it is too large
Load Diff
155
0070-Support-build-gazelle-with-clang.patch
Normal file
155
0070-Support-build-gazelle-with-clang.patch
Normal file
@ -0,0 +1,155 @@
|
||||
From 6331e41c9b6abf156a8de3c87c09131c6d3d84ba Mon Sep 17 00:00:00 2001
|
||||
From: Honggang LI <honggangli@163.com>
|
||||
Date: Fri, 15 Jul 2022 12:18:43 +0800
|
||||
Subject: [PATCH 17/19] Support build gazelle with clang
|
||||
|
||||
Execute following bash command to build gazelle with clang:
|
||||
|
||||
$ VERBOSE=1 CC=clang sh build/build.sh
|
||||
|
||||
Signed-off-by: Honggang LI <honggangli@163.com>
|
||||
---
|
||||
src/common/dpdk_common.h | 2 +-
|
||||
src/common/gazelle_base_func.h | 3 +++
|
||||
src/lstack/Makefile | 8 ++++++--
|
||||
src/lstack/api/lstack_epoll.c | 2 +-
|
||||
src/lstack/core/lstack_lwip.c | 2 +-
|
||||
src/lstack/core/lstack_protocol_stack.c | 2 +-
|
||||
src/lstack/core/lstack_thread_rpc.c | 2 +-
|
||||
src/ltran/CMakeLists.txt | 6 +++++-
|
||||
src/ltran/ltran_stack.c | 2 +-
|
||||
9 files changed, 20 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h
|
||||
index 493b435..01c941d 100644
|
||||
--- a/src/common/dpdk_common.h
|
||||
+++ b/src/common/dpdk_common.h
|
||||
@@ -29,7 +29,7 @@
|
||||
struct pbuf;
|
||||
static inline struct rte_mbuf *pbuf_to_mbuf(struct pbuf *p)
|
||||
{
|
||||
- return ((struct rte_mbuf *)((uint8_t *)(p) - sizeof(struct rte_mbuf) - GAZELLE_MBUFF_PRIV_SIZE));
|
||||
+ return ((struct rte_mbuf *)(void *)((uint8_t *)(p) - sizeof(struct rte_mbuf) - GAZELLE_MBUFF_PRIV_SIZE));
|
||||
}
|
||||
static inline struct pbuf_custom *mbuf_to_pbuf(struct rte_mbuf *m)
|
||||
{
|
||||
diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h
|
||||
index 9d7381e..fe3411a 100644
|
||||
--- a/src/common/gazelle_base_func.h
|
||||
+++ b/src/common/gazelle_base_func.h
|
||||
@@ -32,4 +32,7 @@ int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size);
|
||||
|
||||
int32_t check_and_set_run_dir(void);
|
||||
|
||||
+#undef container_of
|
||||
+#define container_of(ptr, type, field) ((type *)(void*)(((char *)(ptr)) - offsetof(type, field)))
|
||||
+
|
||||
#endif /* ifndef __GAZELLE_BASE_FUNC_H__ */
|
||||
diff --git a/src/lstack/Makefile b/src/lstack/Makefile
|
||||
index 98289d8..0fb4405 100644
|
||||
--- a/src/lstack/Makefile
|
||||
+++ b/src/lstack/Makefile
|
||||
@@ -16,12 +16,16 @@ LIB_PATH ?= /usr/lib64
|
||||
|
||||
AR = ar
|
||||
ARFLAGS = crDP
|
||||
-CC = gcc
|
||||
+CC ?= gcc
|
||||
OPTIMIZATION = -O2 -g
|
||||
RM = rm -f
|
||||
LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck
|
||||
|
||||
-SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2
|
||||
+ifeq ($(CC),gcc)
|
||||
+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2
|
||||
+else ifeq($(CC),clang)
|
||||
+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -fPIC
|
||||
+endif
|
||||
|
||||
INC = -I$(LSTACK_DIR)/include \
|
||||
-I$(LSTACK_DIR)/../common \
|
||||
diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
|
||||
index 06a099d..310a0e7 100644
|
||||
--- a/src/lstack/api/lstack_epoll.c
|
||||
+++ b/src/lstack/api/lstack_epoll.c
|
||||
@@ -187,7 +187,7 @@ static uint16_t find_max_cnt_stack(int32_t *stack_count, uint16_t stack_num, str
|
||||
}
|
||||
|
||||
/* first bind and all stack same. choice tick as queue_id, avoid all bind to statck_0. */
|
||||
- static uint16_t tick = 0;
|
||||
+ static _Atomic uint16_t tick = 0;
|
||||
if (all_same_cnt && stack_num) {
|
||||
max_index = atomic_fetch_add(&tick, 1) % stack_num;
|
||||
}
|
||||
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
|
||||
index 9f51ebd..4c2f0ea 100644
|
||||
--- a/src/lstack/core/lstack_lwip.c
|
||||
+++ b/src/lstack/core/lstack_lwip.c
|
||||
@@ -104,7 +104,7 @@ static void replenish_send_idlembuf(struct rte_ring *ring)
|
||||
|
||||
void gazelle_init_sock(int32_t fd)
|
||||
{
|
||||
- static uint32_t name_tick = 0;
|
||||
+ static _Atomic uint32_t name_tick = 0;
|
||||
struct protocol_stack *stack = get_protocol_stack();
|
||||
struct lwip_sock *sock = get_socket(fd);
|
||||
if (sock == NULL) {
|
||||
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
|
||||
index 577711a..a2dd62c 100644
|
||||
--- a/src/lstack/core/lstack_protocol_stack.c
|
||||
+++ b/src/lstack/core/lstack_protocol_stack.c
|
||||
@@ -113,7 +113,7 @@ struct protocol_stack *get_bind_protocol_stack(void)
|
||||
|
||||
/* close listen shadow, per app communication thread select only one stack */
|
||||
if (get_global_cfg_params()->listen_shadow == false) {
|
||||
- static uint16_t stack_index = 0;
|
||||
+ static _Atomic uint16_t stack_index = 0;
|
||||
index = atomic_fetch_add(&stack_index, 1);
|
||||
if (index >= stack_group->stack_num) {
|
||||
LSTACK_LOG(ERR, LSTACK, "thread =%hu larger than stack num = %hu\n", index, stack_group->stack_num);
|
||||
diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c
|
||||
index 58c4b05..5a05c82 100644
|
||||
--- a/src/lstack/core/lstack_thread_rpc.c
|
||||
+++ b/src/lstack/core/lstack_thread_rpc.c
|
||||
@@ -82,7 +82,7 @@ static inline __attribute__((always_inline)) void rpc_msg_free(struct rpc_msg *m
|
||||
msg->self_release = 0;
|
||||
msg->func = NULL;
|
||||
|
||||
- atomic_fetch_add(&msg->pool->cons, 1);
|
||||
+ atomic_fetch_add((_Atomic uint32_t *)&msg->pool->cons, 1);
|
||||
}
|
||||
|
||||
static inline __attribute__((always_inline)) void rpc_call(lockless_queue *queue, struct rpc_msg *msg)
|
||||
diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt
|
||||
index 970bc1b..9c6751c 100644
|
||||
--- a/src/ltran/CMakeLists.txt
|
||||
+++ b/src/ltran/CMakeLists.txt
|
||||
@@ -14,7 +14,11 @@ project(ltran)
|
||||
set(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
-set(CMAKE_C_FLAGS "-g -fstack-protector-strong -Wall -Werror -fPIE -pie -pthread -D_FORTIFY_SOURCE=2 -O2 -fPIC")
|
||||
+if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
+ set(CMAKE_C_FLAGS "-g -fstack-protector-strong -Wall -Werror -fPIE -pie -pthread -D_FORTIFY_SOURCE=2 -O2 -fPIC")
|
||||
+elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
+ set(CMAKE_C_FLAGS "-O2 -g -fstack-protector-strong -Wall -Werror -fPIE -pthread")
|
||||
+endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D LTRAN_COMPILE")
|
||||
|
||||
if($ENV{GAZELLE_COVERAGE_ENABLE})
|
||||
diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c
|
||||
index 2049003..4be7c23 100644
|
||||
--- a/src/ltran/ltran_stack.c
|
||||
+++ b/src/ltran/ltran_stack.c
|
||||
@@ -88,7 +88,7 @@ const struct gazelle_stack *gazelle_stack_get_by_tid(const struct gazelle_stack_
|
||||
uint32_t index;
|
||||
const struct gazelle_stack *stack = NULL;
|
||||
const struct gazelle_stack_hbucket *stack_hbucket = NULL;
|
||||
- const struct hlist_node *node = NULL;
|
||||
+ struct hlist_node *node = NULL;
|
||||
const struct hlist_head *head = NULL;
|
||||
|
||||
index = tid_hash_fn(tid) % GAZELLE_MAX_STACK_HTABLE_SIZE;
|
||||
--
|
||||
2.23.0
|
||||
|
||||
76
0071-Allow-dynamic-load-PMDs.patch
Normal file
76
0071-Allow-dynamic-load-PMDs.patch
Normal file
@ -0,0 +1,76 @@
|
||||
From 15dbe826aef71330043818c9a6c187819823768a Mon Sep 17 00:00:00 2001
|
||||
From: Honggang LI <honggangli@163.com>
|
||||
Date: Mon, 18 Jul 2022 10:57:34 +0800
|
||||
Subject: [PATCH 18/19] Allow dynamic load PMDs
|
||||
|
||||
Signed-off-by: Honggang LI <honggangli@163.com>
|
||||
---
|
||||
src/lstack/Makefile | 52 +++++++++----------
|
||||
1 files changed, 26 insertions(+), 26 deletions(-)
|
||||
|
||||
diff --git a/src/lstack/Makefile b/src/lstack/Makefile
|
||||
index 0fb4405..7ce35d4 100644
|
||||
--- a/src/lstack/Makefile
|
||||
+++ b/src/lstack/Makefile
|
||||
@@ -57,32 +57,32 @@ include $(patsubst %, %/dir.mk, $(DIRS))
|
||||
OBJS = $(subst .c,.o,$(SRCS))
|
||||
|
||||
LWIP_LIB = $(LIB_PATH)/liblwip.a
|
||||
-LIBRTE_LIB = $(LIB_PATH)/librte_bus_pci.a \
|
||||
- $(LIB_PATH)/librte_pci.a \
|
||||
- $(LIB_PATH)/librte_cmdline.a \
|
||||
- $(LIB_PATH)/librte_hash.a \
|
||||
- $(LIB_PATH)/librte_mempool.a \
|
||||
- $(LIB_PATH)/librte_mempool_ring.a \
|
||||
- $(LIB_PATH)/librte_timer.a \
|
||||
- $(LIB_PATH)/librte_eal.a \
|
||||
- $(LIB_PATH)/librte_ring.a \
|
||||
- $(LIB_PATH)/librte_mbuf.a \
|
||||
- $(LIB_PATH)/librte_telemetry.a \
|
||||
- $(LIB_PATH)/librte_kni.a \
|
||||
- $(LIB_PATH)/librte_net_ixgbe.a \
|
||||
- $(LIB_PATH)/librte_kvargs.a \
|
||||
- $(LIB_PATH)/librte_net_hinic.a \
|
||||
- $(LIB_PATH)/librte_net_i40e.a \
|
||||
- $(LIB_PATH)/librte_net_virtio.a \
|
||||
- $(LIB_PATH)/librte_bus_vdev.a \
|
||||
- $(LIB_PATH)/librte_net.a \
|
||||
- $(LIB_PATH)/librte_rcu.a \
|
||||
- $(LIB_PATH)/librte_ethdev.a \
|
||||
- $(LIB_PATH)/librte_pdump.a \
|
||||
- $(LIB_PATH)/librte_bpf.a \
|
||||
- $(LIB_PATH)/librte_pcapng.a \
|
||||
- $(LIB_PATH)/librte_security.a \
|
||||
- $(LIB_PATH)/librte_cryptodev.a
|
||||
+LIBRTE_LIB = $(LIB_PATH)/librte_bus_pci.so \
|
||||
+ $(LIB_PATH)/librte_pci.so \
|
||||
+ $(LIB_PATH)/librte_cmdline.so \
|
||||
+ $(LIB_PATH)/librte_hash.so \
|
||||
+ $(LIB_PATH)/librte_mempool.so \
|
||||
+ $(LIB_PATH)/librte_mempool_ring.so \
|
||||
+ $(LIB_PATH)/librte_timer.so \
|
||||
+ $(LIB_PATH)/librte_eal.so \
|
||||
+ $(LIB_PATH)/librte_ring.so \
|
||||
+ $(LIB_PATH)/librte_mbuf.so \
|
||||
+ $(LIB_PATH)/librte_telemetry.so \
|
||||
+ $(LIB_PATH)/librte_kni.so \
|
||||
+ $(LIB_PATH)/librte_net_ixgbe.so \
|
||||
+ $(LIB_PATH)/librte_kvargs.so \
|
||||
+ $(LIB_PATH)/librte_net_hinic.so \
|
||||
+ $(LIB_PATH)/librte_net_i40e.so \
|
||||
+ $(LIB_PATH)/librte_net_virtio.so \
|
||||
+ $(LIB_PATH)/librte_bus_vdev.so \
|
||||
+ $(LIB_PATH)/librte_net.so \
|
||||
+ $(LIB_PATH)/librte_rcu.so \
|
||||
+ $(LIB_PATH)/librte_ethdev.so \
|
||||
+ $(LIB_PATH)/librte_pdump.so \
|
||||
+ $(LIB_PATH)/librte_bpf.so \
|
||||
+ $(LIB_PATH)/librte_pcapng.so \
|
||||
+ $(LIB_PATH)/librte_security.so \
|
||||
+ $(LIB_PATH)/librte_cryptodev.so
|
||||
|
||||
|
||||
DEP_LIBS = $(LWIP_LIB) $(LIBRTE_LIB)
|
||||
--
|
||||
2.23.0
|
||||
|
||||
21
gazelle.spec
21
gazelle.spec
@ -2,7 +2,7 @@
|
||||
|
||||
Name: gazelle
|
||||
Version: 1.0.1
|
||||
Release: 10
|
||||
Release: 11
|
||||
Summary: gazelle is a high performance user-mode stack
|
||||
License: Mulan PSL v2
|
||||
URL: https://gitee.com/openeuler/gazelle
|
||||
@ -70,6 +70,22 @@ Patch9052: 0052-bugfix-https-gitee.com-src-openeuler-gazelle-issues-.patch
|
||||
Patch9053: 0053-update-README.md.patch
|
||||
Patch9054: 0054-ltran-fix-use-after-free-issue.patch
|
||||
Patch9055: 0055-refactor-pkt-read-send-performance.patch
|
||||
Patch9056: 0056-ltran-support-checksum.patch
|
||||
Patch9057: 0057-add-examples-readme-compile-components-main-file-and.patch
|
||||
Patch9058: 0058-add-examples-parameter-parsing.patch
|
||||
Patch9059: 0059-lstack-core-fix-reta_conf-array-size-calculation.patch
|
||||
Patch9060: 0060-Replace-gettid-with-rte_gettid.patch
|
||||
Patch9061: 0061-modify-the-code-for-canonical-and-update-the-cmake-b.patch
|
||||
Patch9062: 0062-enable-secure-compile-and-open-compile-log.patch
|
||||
Patch9063: 0063-support-epoll-et-trig-mode.patch
|
||||
Patch9064: 0064-lstack-support-low-power.patch
|
||||
Patch9065: 0065-add-port-mask-range-check.patch
|
||||
Patch9066: 0066-release-kni-device.patch
|
||||
Patch9067: 0067-optimize-check-ltran-exist.patch
|
||||
Patch9068: 0068-clean-code.patch
|
||||
Patch9069: 0069-clean-code.patch
|
||||
Patch9070: 0070-Support-build-gazelle-with-clang.patch
|
||||
Patch9071: 0071-Allow-dynamic-load-PMDs.patch
|
||||
|
||||
%description
|
||||
%{name} is a high performance user-mode stack.
|
||||
@ -110,6 +126,9 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b
|
||||
%config(noreplace) %{conf_path}/ltran.conf
|
||||
|
||||
%changelog
|
||||
* Tue Jul 19 2022 xiusailong <xiusailong@huawei.com> - 1.0.1-11
|
||||
- reconstruct packet sending and receiving to improve performance
|
||||
|
||||
* Thu Jul 7 2022 jiangheng <jiangheng14@huawei.com> - 1.0.1-10
|
||||
- Type:bugfix
|
||||
- CVE:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user