From 06c078f2608fbe9823f41bcb7645fe93d23a453b Mon Sep 17 00:00:00 2001 From: kircher Date: Mon, 16 Jan 2023 11:41:40 +0800 Subject: [PATCH] sync add ret check in pthread_create and fix example bug (cherry picked from commit f1a55c8332318e5f22d38ed2141642e7c701fbd9) --- ...ent_thread-creation-after-control_in.patch | 33 ++++++++++ ...n-pthread_create-and-fix-example-bug.patch | 65 +++++++++++++++++++ gazelle.spec | 8 ++- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 0181-move-control_client_thread-creation-after-control_in.patch create mode 100644 0182-add-ret-check-in-pthread_create-and-fix-example-bug.patch diff --git a/0181-move-control_client_thread-creation-after-control_in.patch b/0181-move-control_client_thread-creation-after-control_in.patch new file mode 100644 index 0000000..a22fe9c --- /dev/null +++ b/0181-move-control_client_thread-creation-after-control_in.patch @@ -0,0 +1,33 @@ +From 400c9f494c2217cba4ca48af83c53f36663dc066 Mon Sep 17 00:00:00 2001 +From: kircher +Date: Tue, 10 Jan 2023 20:11:05 +0800 +Subject: [PATCH] move control_client_thread creation after control_in and + dpdk_skip_nic_init + +--- + src/lstack/core/lstack_init.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c +index 6347ab1..477c5e2 100644 +--- a/src/lstack/core/lstack_init.c ++++ b/src/lstack/core/lstack_init.c +@@ -223,11 +223,14 @@ static void create_control_thread(void) + + pthread_t tid; + if (use_ltran()) { +- ret = pthread_create(&tid, NULL, (void *(*)(void *))control_client_thread, NULL); ++ /* ++ * The function call here should be in strict order. ++ */ + dpdk_skip_nic_init(); + if (control_init_client(false) != 0) { + LSTACK_EXIT(1, "control_init_client failed\n"); + } ++ ret = pthread_create(&tid, NULL, (void *(*)(void *))control_client_thread, NULL); + } else { + ret = pthread_create(&tid, NULL, (void *(*)(void *))control_server_thread, NULL); + ret = dpdk_eal_init(); +-- +2.33.0 + diff --git a/0182-add-ret-check-in-pthread_create-and-fix-example-bug.patch b/0182-add-ret-check-in-pthread_create-and-fix-example-bug.patch new file mode 100644 index 0000000..04f741e --- /dev/null +++ b/0182-add-ret-check-in-pthread_create-and-fix-example-bug.patch @@ -0,0 +1,65 @@ +From 627773adfafefdf295e680691c3d5b99c6b52c8c Mon Sep 17 00:00:00 2001 +From: kircher +Date: Tue, 10 Jan 2023 20:35:11 +0800 +Subject: [PATCH] add ret check in pthread_create and fix example bug + +--- + examples/src/utilities.c | 16 +++++++++++++++- + src/lstack/core/lstack_init.c | 10 ++++++---- + 2 files changed, 21 insertions(+), 5 deletions(-) + +diff --git a/examples/src/utilities.c b/examples/src/utilities.c +index b6ed269..38a0d3e 100644 +--- a/examples/src/utilities.c ++++ b/examples/src/utilities.c +@@ -124,5 +124,19 @@ int32_t create_socket_and_connect(int32_t *socket_fd, in_addr_t ip, uint16_t por + // set the socket to unblock + int32_t set_socket_unblock(int32_t socket_fd) + { +- return fcntl(socket_fd, F_SETFL, fcntl(socket_fd, F_GETFD, 0) | O_NONBLOCK); ++ int flags = -1; ++ ++ flags = fcntl(socket_fd, F_GETFL, 0); ++ if (flags == -1) { ++ printf("get socket flag error, fd:[%d], errno: %d\n", socket_fd, errno); ++ return -1; ++ } ++ ++ flags |= O_NONBLOCK; ++ if (fcntl(socket_fd, F_SETFL, flags) == -1) { ++ printf("set socket flag error, fd:[%d], errno: %d\n", socket_fd, errno); ++ return -1; ++ } ++ ++ return 0; + } +diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c +index 477c5e2..6309d1d 100644 +--- a/src/lstack/core/lstack_init.c ++++ b/src/lstack/core/lstack_init.c +@@ -231,16 +231,18 @@ static void create_control_thread(void) + LSTACK_EXIT(1, "control_init_client failed\n"); + } + ret = pthread_create(&tid, NULL, (void *(*)(void *))control_client_thread, NULL); ++ if (ret != 0) { ++ LSTACK_EXIT(1, "pthread_create failed ret=%d errno=%d\n", ret, errno); ++ } + } else { + ret = pthread_create(&tid, NULL, (void *(*)(void *))control_server_thread, NULL); ++ if (ret != 0) { ++ LSTACK_EXIT(1, "pthread_create failed ret=%d errno=%d\n", ret, errno); ++ } + ret = dpdk_eal_init(); + if (ret < 0) { + LSTACK_EXIT(1, "dpdk_eal_init failed ret=%d errno=%d\n", ret, errno); + } +- +- } +- if (ret != 0) { +- LSTACK_EXIT(1, "pthread_create failed ret=%d errno=%d\n", ret, errno); + } + + if (pthread_setname_np(tid, CONTROL_THREAD_NAME) != 0) { +-- +2.33.0 + diff --git a/gazelle.spec b/gazelle.spec index 79ac950..34e3eed 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.1 -Release: 44 +Release: 45 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -195,6 +195,8 @@ Patch9177: 0177-support-set-main-thread-affinity.patch Patch9178: 0178-reduce-epoll-wakeup.patch Patch9179: 0179-revert-expand-recv-data-buff.patch Patch9180: 0180-add-the-suggestion-of-using-the-u-parameter-when-the.patch +Patch9181: 0181-move-control_client_thread-creation-after-control_in.patch +Patch9182: 0182-add-ret-check-in-pthread_create-and-fix-example-bug.patch %description %{name} is a high performance user-mode stack. @@ -235,6 +237,10 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Mon Jan 16 2023 kircher - 1.0.1-45 +- add ret check in pthread_create and fix example bug +- move control_client_thread creation after control_in and dpdk_skip_nic_init + * Fri Jan 6 2023 kircher - 1.0.1-44 - add the suggestion of using the -u parameter when the connection to unix socket fails