From df1f0f4a02aa41a0a77ef2d991a0c13bd0a58d81 Mon Sep 17 00:00:00 2001 From: kircher Date: Sat, 5 Nov 2022 18:39:23 +0800 Subject: [PATCH] sync add-kni-local-support-in-lstack (cherry picked from commit 2cdfeca9aaaac2a63357bc155f6260c421c952e7) --- 0119-add-kni-local-support-in-lstack.patch | 85 ++++++++++++++++++++++ gazelle.spec | 6 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 0119-add-kni-local-support-in-lstack.patch diff --git a/0119-add-kni-local-support-in-lstack.patch b/0119-add-kni-local-support-in-lstack.patch new file mode 100644 index 0000000..3fd4d3e --- /dev/null +++ b/0119-add-kni-local-support-in-lstack.patch @@ -0,0 +1,85 @@ +From d09e1b2a18c59ae9692d678004f9612f9e990e35 Mon Sep 17 00:00:00 2001 +From: kircher +Date: Sat, 5 Nov 2022 15:00:44 +0800 +Subject: [PATCH] add kni support in lstack + +--- + src/lstack/api/lstack_wrap.c | 6 +++++- + src/lstack/core/lstack_dpdk.c | 6 ++++++ + src/lstack/core/lstack_protocol_stack.c | 8 ++++++++ + 3 files changed, 19 insertions(+), 1 deletion(-) + +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index 1c7a722..1a654e9 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -36,6 +36,10 @@ + #include "gazelle_base_func.h" + #include "lstack_thread_rpc.h" + ++#ifndef SOCK_TYPE_MASK ++#define SOCK_TYPE_MASK 0xf ++#endif ++ + enum KERNEL_LWIP_PATH { + PATH_KERNEL = 0, + PATH_LWIP, +@@ -293,7 +297,7 @@ static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, c + static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) + { + if ((domain != AF_INET && domain != AF_UNSPEC) +- || posix_api->ues_posix) { ++ || posix_api->ues_posix || ((type & SOCK_TYPE_MASK) & ~SOCK_STREAM)) { + return posix_api->socket_fn(domain, type, protocol); + } + +diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c +index 39f8ecf..c63fbaa 100644 +--- a/src/lstack/core/lstack_dpdk.c ++++ b/src/lstack/core/lstack_dpdk.c +@@ -520,10 +520,16 @@ static void set_kni_ip_mac(uint16_t port_id) + if (strcpy_s(set_ifr.ifr_name, sizeof(set_ifr.ifr_name), GAZELLE_KNI_NAME) != 0) { + LSTACK_LOG(ERR, LSTACK, "strcpy_s fail \n"); + } ++ + if (posix_api->ioctl_fn(fd, SIOCSIFADDR, &set_ifr) < 0) { + LSTACK_LOG(ERR, LSTACK, "set kni ip=%u fail\n", cfg->host_addr.addr); + } + ++ sin->sin_addr.s_addr = cfg->netmask.addr; ++ if (posix_api->ioctl_fn(fd, SIOCSIFNETMASK, &set_ifr) < 0) { ++ LSTACK_LOG(ERR, LSTACK, "set kni netmask=%u fail\n", cfg->netmask.addr); ++ } ++ + posix_api->close_fn(fd); + } + +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 2759d7d..3daa09f 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -422,6 +422,7 @@ static void* gazelle_stack_thread(void *arg) + { + uint16_t queue_id = *(uint16_t *)arg; + bool use_ltran_flag = use_ltran(); ++ bool kni_switch = get_global_cfg_params()->kni_switch; + uint32_t wakeup_tick = 0; + + struct protocol_stack *stack = stack_thread_init(queue_id); +@@ -449,6 +450,13 @@ static void* gazelle_stack_thread(void *arg) + wakeup_kernel_event(stack); + wakeup_stack_epoll(stack); + } ++ ++ /* KNI requests are generally low-rate I/Os, ++ * so processing KNI requests only in the thread with queue_id No.0 is sufficient. */ ++ if (kni_switch && !queue_id && !(wakeup_tick & 0xfff)) { ++ rte_kni_handle_request(get_gazelle_kni()); ++ } ++ + wakeup_tick++; + + sys_timer_run(); +-- +2.33.0 + diff --git a/gazelle.spec b/gazelle.spec index 13cd8e0..06115fb 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.1 -Release: 17 +Release: 18 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -133,6 +133,7 @@ Patch9115: 0115-add-usleep-when-write_ring-is-busy.patch Patch9116: 0116-optimize-variable-access.patch Patch9117: 0117-add-gro.patch Patch9118: 0118-expand-nic-rx-desc-size.patch +Patch9119: 0119-add-kni-local-support-in-lstack.patch %description %{name} is a high performance user-mode stack. @@ -173,6 +174,9 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Sat Nov 05 2022 kircher - 1.0.1-18 +- Add kni local support in lstack + * Fri Nov 04 2022 wuchangsheng - 1.0.1-17 - Optimize ceph client performance