<div class="__aliyun_email_body_block"><div  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun"><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Hi Stephen,</span></div><div  style="clear: both;"><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Thank you for your valuable feedback. I fully understand your concern about pthread_cancel.<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">However, due to our chip design constraints, during the remove process, a few mailbox messages will still be sent after disabling mailbox interrupts.</span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Since mailbox interrupts are already closed at this point, we cannot rely on pipe reads to trigger mailbox ACK reception.<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Therefore, the acks of these mailbox messages have to be received using polling. This is why we need the NBL_CHAN_INTERRUPT_READY flag.</span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">I've implemented an alternative, adding a state flag NBL_CHAN_TEARDOWN to notify the polling task to exit.<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Here's the code modification.<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">I've tested this on our hardware and it works fine.<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Do you think this modification is okay?<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">diff --git a/drivers/net/nbl/nbl_hw/nbl_channel.c b/drivers/net/nbl/nbl_hw/nbl_channel.c<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">index a68060799c..c8572b3b4a 100644<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">--- a/drivers/net/nbl/nbl_hw/nbl_channel.c<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">+++ b/drivers/net/nbl/nbl_hw/nbl_channel.c<br ></span></div><div  style="clear: both;"><br ></div><div  style="clear: both;"><br ></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"> static uint32_t nbl_chan_thread_polling_task(void *param)<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"> {<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)param;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   union nbl_chan_info *chan_info = NBL_CHAN_MGT_TO_CHAN_INFO(chan_mgt);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   struct timespec time;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   char unused[16];<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   ssize_t nr = 0;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   time.tv_sec = 0;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   time.tv_nsec = 100000;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   while (true) {<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">     if (rte_bitmap_get(chan_info->mailbox.state_bmp, NBL_CHAN_INTERRUPT_READY)) {<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">       nr = read(chan_info->mailbox.fd[0], &unused, sizeof(unused));<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">       if (nr < 0)<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">         break;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">-     }<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun; color: rgb(0, 176, 80);">+     } else if (rte_bitmap_get(chan_info->mailbox.state_bmp, NBL_CHAN_TEARDOWN)) {<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun; color: rgb(0, 176, 80);">+       break;</span><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">+     }<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">     nbl_chan_clean_queue(chan_mgt);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">     nanosleep(&time, 0);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   }<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   return 0;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"> }<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"> static int nbl_chan_task_finish(void *priv)<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"> {<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)priv;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   union nbl_chan_info *chan_info = NBL_CHAN_MGT_TO_CHAN_INFO(chan_mgt);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="color: rgb(0, 176, 80); font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">-   pthread_cancel((pthread_t)chan_info->mailbox.tid.opaque_id);<br ></span></div><div  style="clear: both;"><span  style="color: rgb(0, 176, 80); font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">+   /* set teardown state to cause mailbox thread to exit */<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun; color: rgb(0, 176, 80);">+   nbl_chan_set_queue_state(priv, NBL_CHAN_TEARDOWN, true);</span><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   close(chan_info->mailbox.fd[0]);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   close(chan_info->mailbox.fd[1]);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   chan_info->mailbox.fd[0] = -1;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   chan_info->mailbox.fd[1] = -1;<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   rte_thread_join(chan_info->mailbox.tid, NULL);<br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">   return 0;<br ></span></div><div ><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"> }</span></div><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><blockquote  _quote="1" style="margin-right: 0px; margin-top: 0px; margin-bottom: 0px; font-family: Tahoma, Arial, STHeiti, SimSun; font-size: 14px; color: rgb(0, 0, 0);"><div  class="alimail-quote"><div  style="clear: both;">------------------------------------------------------------------</div><div  style="clear: both;">发件人:Stephen Hemminger <stephen@networkplumber.org></div><div  style="clear: both;">发送时间:2025年9月24日(周三) 02:25</div><div  style="clear: both;">收件人:Dimon<dimon.zhao@nebula-matrix.com></div><div  style="clear: both;">抄 送:dev<dev@dpdk.org>; Kyo Liu<kyo.liu@nebula-matrix.com>; Leon<leon.yu@nebula-matrix.com>; Sam<sam.chen@nebula-matrix.com></div><div  style="clear: both;">主 题:Re: [PATCH v10 04/17] net/nbl: add Channel layer definitions and implementation</div><div  style="clear: both;"><br ></div>On Mon, 22 Sep 2025 20:53:49 -0700<br >Dimon Zhao <dimon.zhao@nebula-matrix.com> wrote:<br ><br >> +<br >> +static int nbl_chan_task_finish(void *priv)<br >> +{<br >> + struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)priv;<br >> + union nbl_chan_info *chan_info = NBL_CHAN_MGT_TO_CHAN_INFO(chan_mgt);<br >> +<br >> + pthread_cancel((pthread_t)chan_info->mailbox.tid.opaque_id);<br >> + close(chan_info->mailbox.fd[0]);<br >> + close(chan_info->mailbox.fd[1]);<br >> + chan_info->mailbox.fd[0] = -1;<br >> + chan_info->mailbox.fd[1] = -1;<br >> + rte_thread_join(chan_info->mailbox.tid, NULL);<br >> + return 0;<br >> +}<br ><br >Using pthread_cancel has a couple of problems: pthread_cancel uses a signal and there is no safe equivalent on Windows<br ><br >A better alternative is to just close the pipe and then the read<br >will safely exit the read().  Something like this:<br ><br >diff --git a/drivers/net/nbl/nbl_hw/nbl_channel.c b/drivers/net/nbl/nbl_hw/nbl_channel.c<br >index a68060799c..c8572b3b4a 100644<br >--- a/drivers/net/nbl/nbl_hw/nbl_channel.c<br >+++ b/drivers/net/nbl/nbl_hw/nbl_channel.c<br >@@ -551,7 +551,7 @@ static int nbl_chan_task_finish(void *priv)<br >        struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)priv;<br >        union nbl_chan_info *chan_info = NBL_CHAN_MGT_TO_CHAN_INFO(chan_mgt);<br > <br >-       pthread_cancel((pthread_t)chan_info->mailbox.tid.opaque_id);<br >+       /* closing pipe will cause mailbox thread to exit */<br >        close(chan_info->mailbox.fd[0]);<br >        close(chan_info->mailbox.fd[1]);<br >        chan_info->mailbox.fd[0] = -1;<br ><br >Obviously, I don't have hardware so not tested.<br ><br >Yes, other drivers call pthread_cancel() and I am working on an RFC<br >patch series to eliminate all those places.</div></blockquote><div  style="line-height: 20px; clear: both;"><br ></div></div></div>
<div style="clear: both;"><span style="font-size: 10px; color: rgb(216, 216, 216);">本邮件所含信息及其任何附件为保密信息且可能属于专有信息。任何非指定接收人均无权访问本邮件。如果您不是该邮件的指定接收人,那么任何对本邮件内容进行披露,复制或使用的行为均是禁止的。如果您不是该邮件的指定接收人,请您立即通过邮件通知 compliance@nebula-matrix.com并立即删除您错误接受的邮件。</span></div><div style="clear: both;"><span style="font-size: 10px; color: rgb(216, 216, 216);">The information in this message and any attachments is confidential and may be privileged.  Access to this email by anyone other than the intended recipient is not authorized.  If you are not the intended recipient, disclosure, copying or use of the contents of this email is prohibited.  If you are not the intended recipient, please notify  compliance@nebula-matrix.com immediately by email, and please destroy the email you received in error.</span></div>