From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Anatoly Burakov <anatoly.burakov@intel.com>,
Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [RFC 1/6] eal: avoid using pthread_cancel
Date: Wed, 24 Sep 2025 09:51:08 -0700 [thread overview]
Message-ID: <20250924165527.268645-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20250924165527.268645-1-stephen@networkplumber.org>
The multi-process handling thread can be managed more safely
by closing the underlying socket rather than pthread_cancel.
Closing the socket in the main thread will cause the read()
in the MP handler to unblock.
The use of atomic for updating the socket fd is not needed.
The fd for the socket is set before the thread is created
and not modified again until handler has exited.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/common/eal_common_proc.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c
index 0dea787e38..8e60e815ed 100644
--- a/lib/eal/common/eal_common_proc.c
+++ b/lib/eal/common/eal_common_proc.c
@@ -34,7 +34,7 @@
#include "eal_filesystem.h"
#include "eal_internal_cfg.h"
-static RTE_ATOMIC(int) mp_fd = -1;
+static int mp_fd = -1;
static rte_thread_t mp_handle_tid;
static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */
static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */
@@ -406,17 +406,9 @@ mp_handle(void *arg __rte_unused)
{
struct mp_msg_internal msg;
struct sockaddr_un sa;
- int fd;
-
- while ((fd = rte_atomic_load_explicit(&mp_fd, rte_memory_order_relaxed)) >= 0) {
- int ret;
-
- ret = read_msg(fd, &msg, &sa);
- if (ret <= 0)
- break;
+ while (read_msg(mp_fd, &msg, &sa) > 0)
process_msg(&msg, &sa);
- }
return 0;
}
@@ -656,7 +648,7 @@ rte_mp_channel_init(void)
EAL_LOG(ERR, "failed to create mp thread: %s",
strerror(errno));
close(dir_fd);
- close(rte_atomic_exchange_explicit(&mp_fd, -1, rte_memory_order_relaxed));
+ close(mp_fd);
return -1;
}
@@ -670,15 +662,11 @@ rte_mp_channel_init(void)
void
rte_mp_channel_cleanup(void)
{
- int fd;
-
- fd = rte_atomic_exchange_explicit(&mp_fd, -1, rte_memory_order_relaxed);
- if (fd < 0)
- return;
+ /* shutdown() will cause recvmsg to unblock */
+ shutdown(mp_fd, SHUT_RDWR);
- pthread_cancel((pthread_t)mp_handle_tid.opaque_id);
rte_thread_join(mp_handle_tid, NULL);
- close_socket_fd(fd);
+ close_socket_fd(mp_fd);
}
/**
--
2.47.3
next prev parent reply other threads:[~2025-09-24 16:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 16:51 [RFC 0/6] get rid of pthread_cancel Stephen Hemminger
2025-09-24 16:51 ` Stephen Hemminger [this message]
2025-09-24 16:51 ` [RFC 2/6] eventdev: avoid use " Stephen Hemminger
2025-09-24 16:51 ` [RFC 3/6] raw/ifpga: " Stephen Hemminger
2025-09-24 16:51 ` [RFC 4/6] dma/skeleton: " Stephen Hemminger
2025-09-25 1:20 ` fengchengwen
2025-09-24 16:51 ` [RFC 5/6] intel/ipn3ke: " Stephen Hemminger
2025-09-24 16:51 ` [RFC 6/6] intel/iavf: remove " Stephen Hemminger
2025-09-25 15:11 ` Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250924165527.268645-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=roretzla@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).