[PATCH v10 04/17] net/nbl: add Channel layer definitions and implementation

Stephen Hemminger stephen at networkplumber.org
Tue Sep 23 20:25:23 CEST 2025


On Mon, 22 Sep 2025 20:53:49 -0700
Dimon Zhao <dimon.zhao at nebula-matrix.com> wrote:

> +
> +static int nbl_chan_task_finish(void *priv)
> +{
> +	struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)priv;
> +	union nbl_chan_info *chan_info = NBL_CHAN_MGT_TO_CHAN_INFO(chan_mgt);
> +
> +	pthread_cancel((pthread_t)chan_info->mailbox.tid.opaque_id);
> +	close(chan_info->mailbox.fd[0]);
> +	close(chan_info->mailbox.fd[1]);
> +	chan_info->mailbox.fd[0] = -1;
> +	chan_info->mailbox.fd[1] = -1;
> +	rte_thread_join(chan_info->mailbox.tid, NULL);
> +	return 0;
> +}

Using pthread_cancel has a couple of problems: pthread_cancel uses a signal and there is no safe equivalent on Windows

A better alternative is to just close the pipe and then the read
will safely exit the read().  Something like this:

diff --git a/drivers/net/nbl/nbl_hw/nbl_channel.c b/drivers/net/nbl/nbl_hw/nbl_channel.c
index a68060799c..c8572b3b4a 100644
--- a/drivers/net/nbl/nbl_hw/nbl_channel.c
+++ b/drivers/net/nbl/nbl_hw/nbl_channel.c
@@ -551,7 +551,7 @@ static int nbl_chan_task_finish(void *priv)
        struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)priv;
        union nbl_chan_info *chan_info = NBL_CHAN_MGT_TO_CHAN_INFO(chan_mgt);
 
-       pthread_cancel((pthread_t)chan_info->mailbox.tid.opaque_id);
+       /* closing pipe will cause mailbox thread to exit */
        close(chan_info->mailbox.fd[0]);
        close(chan_info->mailbox.fd[1]);
        chan_info->mailbox.fd[0] = -1;

Obviously, I don't have hardware so not tested.

Yes, other drivers call pthread_cancel() and I am working on an RFC
patch series to eliminate all those places.



More information about the dev mailing list