!264 [sync] PR-263: move control_client_thread creation after control_in and dpdk_skip_nic_init & add ret check in pthread_create and fix example bug

From: @openeuler-sync-bot 
Reviewed-by: @kircher 
Signed-off-by: @kircher
This commit is contained in:
openeuler-ci-bot 2023-01-16 09:20:26 +00:00 committed by Gitee
commit c2bbf68966
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 105 additions and 1 deletions

View File

@ -0,0 +1,33 @@
From 400c9f494c2217cba4ca48af83c53f36663dc066 Mon Sep 17 00:00:00 2001
From: kircher <majun65@huawei.com>
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

View File

@ -0,0 +1,65 @@
From 627773adfafefdf295e680691c3d5b99c6b52c8c Mon Sep 17 00:00:00 2001
From: kircher <majun65@huawei.com>
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

View File

@ -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 <majun65@huawei.com> - 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 <majun65@huawei.com> - 1.0.1-44
- add the suggestion of using the -u parameter when the connection to unix socket fails