rte_interrupts: add rte_eal_intr_exit to shut down IRQ thread
PATCH 1/3 rte_interrupts: add rte_eal_intr_exit to shut down IRQ thread
There is no good way to shut down this thread from an application signal handler. Here we add an rte_eal_intr_exit() function to allow this.
--- lib/librte_eal/common/include/rte_eal.h | 9 +++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++++++++ 2 files changed, 20 insertions(+)
lib/librte_eal/common/include/rte_eal.h +9 -0
@@ -165,6 +165,15 @@ int rte_eal_init(int argc, char **argv);typedef void (*rte_usage_hook_t )(const char * prgname);/** +* Shut down the EAL interrupt thread. +* +* This function can be called from a signal handler during application +* shutdown. +* +*/ +int rte_eal_intr_exit (void ); + +/** * Add application usage routine callout from the eal_usage() routine. * * This function allows the application to include its usage message
lib/librte_eal/linuxapp/eal/eal_interrupts.c +11 -0
@@ -892,6 +892,17 @@ rte_eal_intr_init(void)if (ret_1 !=0 )RTE_LOG (ERR ,EAL ,"Failed to set thread name for interrupt handling\n" ); + +int +rte_eal_intr_exit (void ) +{ +int ret =0 ; + + ret =pthread_cancel (intr_thread); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL , +"Failed to cancel thread for interrupt handling\n" ); +return -ret; }return -ret;
Signature · 1 line
2.5.0
PATCH 2/3 eal_interrupts: mark EAL interrupt thread as a daemon thread
This thread should not be stuck in an active state when the application is shutting down.
--- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 39 +++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-)
lib/librte_eal/linuxapp/eal/eal_interrupts.c +30 -9
@@ -867,6 +867,7 @@ rte_eal_intr_init(void) {int ret =0 , ret_1 =0 ;char thread_name[RTE_MAX_THREAD_NAME_LEN ]; +pthread_attr_t thread_attr;/* init the global interrupt source head */ TAILQ_INIT (&intr_sources);
@@ -878,20 +879,40 @@ rte_eal_intr_init(void)if (pipe (intr_pipe.pipefd) <0 )return -1 ; + ret =pthread_attr_init (&thread_attr); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL , +"Failed to init interrupt handling thread attributes\n" ); +return -ret; + } + + ret =pthread_attr_setdetachstate (&thread_attr,PTHREAD_CREATE_DETACHED ); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL , +"Failed to set interrupt handling thread attributes\n" ); +return -ret; + } +/* create the host thread to wait/handle the interrupt */ - ret =pthread_create (&intr_thread,NULL , + ret =pthread_create (&intr_thread, &thread_attr, eal_intr_thread_main,NULL );if (ret !=0 ) {RTE_LOG (ERR ,EAL ,"Failed to create thread for interrupt handling\n" ); - }else { -/* Set thread_name for aid in debugging. */ -snprintf (thread_name,RTE_MAX_THREAD_NAME_LEN , -"eal-intr-thread" ); - ret_1 =rte_thread_setname (intr_thread, thread_name); -if (ret_1 !=0 ) -RTE_LOG (ERR ,EAL , -"Failed to set thread name for interrupt handling\n" ); +return -ret; + } + +/* Set thread_name for aid in debugging. */ +snprintf (thread_name,RTE_MAX_THREAD_NAME_LEN , +"eal-intr-thread" ); + ret_1 =rte_thread_setname (intr_thread, thread_name); +if (ret_1 !=0 ) { +RTE_LOG (ERR ,EAL , +"Failed to set thread name for interrupt handling\n" ); + } + +return -ret; +}int rte_eal_intr_exit (void )
Signature · 1 line
2.5.0
PATCH 3/3 rte_epoll_wait: allow EINTR to be passed to caller
In reply to Matthew HallOtherwise the caller will not be able to handle a return from a signal handler.
--- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4 -2
@@ -1047,8 +1047,10 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events, rc =eal_epoll_process_event (evs, rc, events);break ; }else if (rc <0 ) { -if (errno ==EINTR ) -continue ; +if (errno ==EINTR ) { +/* timeout early (such as thread shutdown) */ +break ; + }/* epoll_wait fail */ RTE_LOG (ERR ,EAL ,"epoll_wait returns with fail %s\n" ,strerror (errno));
Signature · 1 line
2.5.0
2016-02-13 13:38, Matthew Hall:
Quoted 2 lines
There is no good way to shut down this thread from an application signal handler. Here we add an
rte_eal_intr_exit()function to allow this.
Please Cunming,
Would you have time to review this series about interrupt thread? Thank you
2016-02-28 22:17, Thomas Monjalon:
Quoted 7 lines
2016-02-13 13:38, Matthew Hall:
Quoted 2 lines
There is no good way to shut down this thread from an application signal handler. Here we add an
rte_eal_intr_exit()function to allow this.Please Cunming,
Would you have time to review this series about interrupt thread? Thank you
PING - reviewers wanted
Hi Mattew,
Quoted 22 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Matthew Hall
Sent: Sunday, February 14, 2016 5:39 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 1/3]rte_interrupts: addrte_eal_intr_exitto shut down IRQ threadThere is no good way to shut down this thread from an application signal handler. Here we add an
rte_eal_intr_exit()function to allow this.Signed-off-by Matthew Hall <[email protected]>--- lib/librte_eal/common/include/rte_eal.h | 9 +++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++++++++ 2 files changed, 20 insertions(+)lib/librte_eal/common/include/rte_eal.h +0
-0
lib/librte_eal/common/include/rte_eal.h int rte_eal_init(int argc, char **argv); · line 174
Quoted 10 lines
lib/librte_eal/common/include/rte_eal.h +7
-0@@ -165,6 +165,15 @@ int rte_eal_init(int argc, char **argv);typedef void (*rte_usage_hook_t )(const char * prgname);/** +* Shut down the EAL interrupt thread. +* +* This function can be called from a signal handler during application +* shutdown. +* +*/ +int rte_eal_intr_exit (void );
I'm trying to understand the motivation.
I don't think you're going to gracefully exit intr thread but leave all other eal threads live. We don't have API to new launch intr thread again. So I guess your app is using own pthread(none EAL thread), you're trying to safely shutdown the whole application by your signal handler. For this purpose, the device shall close safely(turn off intr) during the time, intr thread still wait but no event will be raised. In this view, it seems not necessary to have this new. Can you explain more detail for the purpose? Thanks.
Quoted 30 lines
lib/librte_eal/common/include/rte_eal.h +2
-0+ +/** * Add application usage routine callout from the eal_usage() routine. * * This function allows the application to include its usage message lib/librte_eal/linuxapp/eal/eal_interrupts.c +11
-1@@ -892,6 +892,17 @@ rte_eal_intr_init(void)if (ret_1 !=0 )RTE_LOG (ERR ,EAL ,"Failed to set thread name for interrupt handling\n" ); + +int +rte_eal_intr_exit (void ) +{ +int ret =0 ; + + ret =pthread_cancel (intr_thread); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL , +"Failed to cancel thread for interrupt handling\n" ); +return -ret; }return -ret; --2.5.0
PATCH 1/3 rte_interrupts: add rte_eal_intr_exit to shut down IRQ thread
In reply to Matthew HallQuoted 5 lines
From Cunming:
I'm trying to understand the motivation.I don't think you're going to gracefully exit intr thread but leave all other eal threads live. We don't have API to new launch intr thread again.
The doc comment added for rte_eal_intr_exit already explains this. According to the doc I wrote, use of the function is limited to shutting everything down.
Quoted 2 lines
So I guess your app is using own pthread(none EAL thread), you're trying to safely shutdown the whole application by your signal handler.
No, the app is using DPDK pthreads, and trying to shutdown everything safely and cleanly w/ its signal handler, across DPDK and many other services in the app.
Unfortunately, right now from my experience it is impossible to get everything to cleanly shutdown, one an interrupt thread is activated. Because interrupt threads violate violate POSIX semantics:
1) It ignores EINTR and immediately forcibly restarts a poll() syscall. If the signal is delivered to the interrupt thread of the process by the kernel, this makes the thread uninterruptible to process the signal. Stuck running forever.
2) It does not properly set PTHREAD_CREATE_DETACHED for a background thread. So it holds the process open for its infinite loop of poll(). Stuck running forever.
3) There is no way to access the thread_id from intr_thread. So then you can't call pthread_cancel on it to shut it down. Stuck running forever.
Quoted 2 lines
For this purpose, the device shall close safely(turn off intr) during the time, intr thread still wait but no event will be raised.
In theory yes. In practice no. Because the intr thread violated POSIX rules for background processing threads per above.
Quoted 2 lines
In this view, it seems not necessary to have this new. Can you explain more detail for the purpose?
Based on my testing, I disagree. I could not get reliable shutdowns without this, or I wouldn't have coded it. (:
Matthew.
Hi Matthew,
Quoted 9 lines · Matthew Hall
From Cunming:
Quoted 4 lines
I'm trying to understand the motivation.
I don't think you're going to gracefully exit intr thread but leave all other eal threads live. We don't have API to new launch intr thread again.
The doc comment added for
rte_eal_intr_exitalready explains this. According to the doc I wrote, use of the function is limited to shutting everything down.
Quoted 5 lines
Quoted 2 lines
So I guess your app is using own pthread(none EAL thread), you're trying to safely shutdown the whole application by your signal handler.
No, the app is using DPDK pthreads, and trying to shutdown everything safely and cleanly w/ its signal handler, across DPDK and many other services in the app.
Get you. You don't satisfy with the default termination signal handler(SIG_DEL). The purpose is to safely clean everything by self-defined signal handler. Can you share us more of your observation on why the default termination handler is not enough/safe? As some of the samples are using it to terminate app, your concern may be necessary to apply on them as well.
Quoted 7 lines
Unfortunately, right now from my experience it is impossible to get everything to cleanly shutdown, one an interrupt thread is activated. Because interrupt threads violate violate POSIX semantics:
1) It ignores EINTR and immediately forcibly restarts a
poll()syscall. If the signal is delivered to the interrupt thread of the process by the kernel, this makes the thread uninterruptible to process the signal. Stuck running forever.
If EINTR is caused by some non-term purpose signals, are you going to exit the interrupt thread any way?
Quoted 3 lines
2) It does not properly set
PTHREAD_CREATE_DETACHEDfor a background thread. So it holds the process open for its infinite loop ofpoll(). Stuck running forever.
Without setting 'PTHREAD_CREATE_DETACHED' won't cause the infinite loop. However by using pthread_cancel to terminate the thread, indeed it's necessary to set 'PTHREAD_CREATE_DETACHED'.
Quoted 2 lines
3) There is no way to access the
thread_idfromintr_thread. So then you can't callpthread_cancelon it to shut it down. Stuck running forever.
It looks like 'pthread_cancel' is the right way and I saw it continue keeps current EINTR handling in EAL interrupt thread.
Quoted 9 lines
Quoted 2 lines
For this purpose, the device shall close safely(turn off intr) during the time, intr thread still wait but no event will be raised.
In theory yes. In practice no. Because the intr thread violated POSIX rules for background processing threads per above.
Quoted 2 lines
In this view, it seems not necessary to have this new. Can you explain more detail for the purpose?
Based on my testing, I disagree. I could not get reliable shutdowns without this, or I wouldn't have coded it. (:
Now it's clear to me, overall it's fine. Three additional comments.
1. Can you explain and add patch comments why default signal handler is not good enough to terminate app.
2. I propose to add addition comments on rte_epoll_wait() API description. For any signal, it causes an error return, user needs to handle.
3. Will you do a favorite to add 'PTHREAD_CREATE_DETACHED' to all EAL pthread too.
Cunming
Quoted 3 lines
Matthew.
Quoted 1 line · Cunming
the default termination handler
I am not so experienced with this "default termination handler". Can someone clarify what it is so I could comment better about it?
Quoted 2 lines
If EINTR is caused by some non-term purpose signals, are you going to exit the interrupt thread any way?
We should discuss what makes sense here. I'm just trying to get some things working and finding EINTR was getting eaten and causing infinite looping.
Quoted 3 lines
Without setting '
PTHREAD_CREATE_DETACHED' won't cause the infinite loop. However by usingpthread_cancelto terminate the thread, indeed it's necessary to set 'PTHREAD_CREATE_DETACHED'.
My general understanding is that PTHREAD_CREATE_DETACHED should be used for any thread, which should not keep a process open by itself if it is executing, i.e. a "daemon thread". I believe the interrupt thread qualifies as such a thread if I have understood everything right (which is hard to promise when you only work in DPDK in spare time).
Quoted 2 lines
It looks like '
pthread_cancel' is the right way and I saw it continue keeps current EINTR handling in EAL interrupt thread.
It is one option. Depending what makes the most sense.
Quoted 2 lines
1. Can you explain and add patch comments why default signal handler is not good enough to terminate app.
Yes if someone call tell me more about what it is so I can check it.
Quoted 3 lines
2. I propose to add addition comments on
rte_epoll_wait()API description. For any signal, it causes an error return, user needs to handle.
Agreed.
Quoted 2 lines
3. Will you do a favorite to add '
PTHREAD_CREATE_DETACHED' to all EAL pthread too.
As a spare time developer I am a bit conservative about too large of a scope and messing with code for other threads or features I didn't personally use or test. This is because I don't have the same QA resources as Intel / 6WIND / etc.. Some help from a full time developer would be great here.
Quoted 1 line
Cunming
Matthew.
Hi Mattew,
Thank you for your time.
Quoted 4 lines · Matthew Hall
Quoted 1 line · Cunming
the default termination handler
I am not so experienced with this "default termination handler". Can someone clarify what it is so I could comment better about it?
For example, you're handling SIGINT. After finishing your necessary app cleanup, then 'signal(SIGINT, SIG_DFL); raise(SIGINT);'. The default signal handler can terminate the interrupt thread.
Quoted 5 lines
Quoted 3 lines
If EINTR is caused by some non-term purpose signals, are you going to exit the interrupt thread any way?
We should discuss what makes sense here. I'm just trying to get some things working and finding EINTR was getting eaten and causing infinite looping.
SIGINT/SIGTERM causes EINTR return, while SIGUSR1 also can cause the EINTR return. For the dedicated EAL interrupt thread, it won't be expected to exit for all kinds of the cause. On this view, I'm in favor of your patch which cancel the interrupt thread, but don't directly return by the EINTR.
Quoted 21 lines
Quoted 4 lines
Without setting '
PTHREAD_CREATE_DETACHED' won't cause the infinite loop. However by usingpthread_cancelto terminate the thread, indeed it's necessary to set 'PTHREAD_CREATE_DETACHED'.My general understanding is that
PTHREAD_CREATE_DETACHEDshould be used for any thread, which should not keep a process open by itself if it is executing, i.e. a "daemon thread". I believe the interrupt thread qualifies as such a thread if I have understood everything right (which is hard to promise when you only work in DPDK in spare time).Quoted 2 lines
It looks like '
pthread_cancel' is the right way and I saw it continue keeps current EINTR handling in EAL interrupt thread.It is one option. Depending what makes the most sense.
Quoted 2 lines
1. Can you explain and add patch comments why default signal handler is not good enough to terminate app.
Yes if someone call tell me more about what it is so I can check it.
Quoted 3 lines
2. I propose to add addition comments on
rte_epoll_wait()API description. For any signal, it causes an error return, user needs to handle.
Quoted 8 lines
Agreed.
Quoted 2 lines
3. Will you do a favorite to add '
PTHREAD_CREATE_DETACHED' to all EAL pthread too.As a spare time developer I am a bit conservative about too large of a scope and messing with code for other threads or features I didn't personally use or test. This is because I don't have the same QA resources as Intel / 6WIND / etc.. Some help from a full time developer would be great here.
All right, reasonable to me.
Quoted 3 lines
Quoted 2 lines
Cunming
Matthew.
Cunming, what is the status of this patchset, please?
2016-03-23 11:24, Liang, Cunming:
Quoted 59 lines
Hi Mattew,
Thank you for your time.
Quoted 4 lines · Matthew Hall
Quoted 1 line · Cunming
the default termination handler
I am not so experienced with this "default termination handler". Can someone clarify what it is so I could comment better about it?
For example, you're handling SIGINT. After finishing your necessary app cleanup, then '
signal(SIGINT, SIG_DFL); raise(SIGINT);'.
The default signal handler can terminate the interrupt thread.Quoted 5 lines
Quoted 3 lines
If EINTR is caused by some non-term purpose signals, are you going to exit the interrupt thread any way?
We should discuss what makes sense here. I'm just trying to get some things working and finding EINTR was getting eaten and causing infinite looping.
SIGINT/SIGTERM causes EINTR return, while SIGUSR1 also can cause the EINTR return. For the dedicated EAL interrupt thread, it won't be expected to exit for all kinds of the cause.
On this view, I'm in favor of your patch which cancel the interrupt thread, but don't directly return by the EINTR.Quoted 21 lines
Quoted 4 lines
Without setting '
PTHREAD_CREATE_DETACHED' won't cause the infinite loop. However by usingpthread_cancelto terminate the thread, indeed it's necessary to set 'PTHREAD_CREATE_DETACHED'.My general understanding is that
PTHREAD_CREATE_DETACHEDshould be used for any thread, which should not keep a process open by itself if it is executing, i.e. a "daemon thread". I believe the interrupt thread qualifies as such a thread if I have understood everything right (which is hard to promise when you only work in DPDK in spare time).Quoted 2 lines
It looks like '
pthread_cancel' is the right way and I saw it continue keeps current EINTR handling in EAL interrupt thread.It is one option. Depending what makes the most sense.
Quoted 2 lines
1. Can you explain and add patch comments why default signal handler is not good enough to terminate app.
Yes if someone call tell me more about what it is so I can check it.
Quoted 3 lines
2. I propose to add addition comments on
rte_epoll_wait()API description. For any signal, it causes an error return, user needs to handle.Quoted 8 lines
Agreed.
Quoted 2 lines
3. Will you do a favorite to add '
PTHREAD_CREATE_DETACHED' to all EAL pthread too.As a spare time developer I am a bit conservative about too large of a scope and messing with code for other threads or features I didn't personally use or test. This is because I don't have the same QA resources as Intel / 6WIND / etc.. Some help from a full time developer would be great here.
All right, reasonable to me.
Quoted 3 lines
Quoted 2 lines
Cunming
Matthew.
Hi Thomas,
Base on the previous conversation, at least it requires v2 to reword some comments.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
2. I propose to add addition comments on
rte_epoll_wait()API description. For any signal, it causes an error return, user needs to handle.Agreed.
In addition, one conversion is not close.
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
the default termination handler
I am not so experienced with this "default termination handler". Can
someone
Quoted 8 lines
Quoted 1 line
clarify what it is so I could comment better about it?
For example, you're handling SIGINT. After finishing your necessary app cleanup, then '
signal(SIGINT, SIG_DFL); raise(SIGINT);'.
The default signal handler can terminate the interrupt thread.Quoted 3 lines
Quoted 2 lines
1. Can you explain and add patch comments why default signal handler is not good enough to terminate app.
Yes if someone call tell me more about what it is so I can check it.
Thanks,
Cunming
Quoted 73 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Saturday, July 09, 2016 1:36 AM
To: Liang, Cunming <[email protected]>
Cc: Matthew Hall <[email protected]>; [email protected]
Subject: Re: [dpdk-dev,1/3]rte_interrupts: addrte_eal_intr_exitto shut down IRQ threadCunming, what is the status of this patchset, please?
2016-03-23 11:24, Liang, Cunming:
Quoted 8 lines
Hi Mattew,
Thank you for your time.
Quoted 3 lines · Matthew Hall
Quoted 1 line · Cunming
the default termination handler
I am not so experienced with this "default termination handler". Can
someone
Quoted 8 lines
Quoted 1 line
clarify what it is so I could comment better about it?
For example, you're handling SIGINT. After finishing your necessary app cleanup, then '
signal(SIGINT, SIG_DFL); raise(SIGINT);'.
The default signal handler can terminate the interrupt thread.Quoted 3 lines
Quoted 3 lines
If EINTR is caused by some non-term purpose signals, are you going to exit the interrupt thread any way?
Quoted 13 lines
Quoted 2 lines
We should discuss what makes sense here. I'm just trying to get some things working and finding EINTR was getting eaten and causing infinite looping.
SIGINT/SIGTERM causes EINTR return, while SIGUSR1 also can cause the EINTR return. For the dedicated EAL interrupt thread, it won't be expected to exit for all kinds of the cause.
On this view, I'm in favor of your patch which cancel the interrupt thread, but don't directly return by the EINTR.Quoted 5 lines
Quoted 4 lines
Without setting '
PTHREAD_CREATE_DETACHED' won't cause the infinite loop. However by usingpthread_cancelto terminate the thread, indeed it's necessary to set 'PTHREAD_CREATE_DETACHED'.My general understanding is that
PTHREAD_CREATE_DETACHEDshould beused for
Quoted 30 lines
Quoted 16 lines
any thread, which should not keep a process open by itself if it is executing, i.e. a "daemon thread". I believe the interrupt thread qualifies as such a thread if I have understood everything right (which is hard to promise when you only work in DPDK in spare time).
Quoted 2 lines
It looks like '
pthread_cancel' is the right way and I saw it continue keeps current EINTR handling in EAL interrupt thread.It is one option. Depending what makes the most sense.
Quoted 2 lines
1. Can you explain and add patch comments why default signal handler is not good enough to terminate app.
Yes if someone call tell me more about what it is so I can check it.
Quoted 3 lines
2. I propose to add addition comments on
rte_epoll_wait()API description. For any signal, it causes an error return, user needs to handle.Quoted 8 lines
Agreed.
Quoted 2 lines
3. Will you do a favorite to add '
PTHREAD_CREATE_DETACHED' to all EAL pthread too.As a spare time developer I am a bit conservative about too large of a scope and messing with code for other threads or features I didn't personally use or test. This is because I don't have the same QA resources as Intel / 6WIND / etc.. Some help from a full time developer would be great here.
All right, reasonable to me.
Quoted 3 lines
Quoted 2 lines
Cunming
Matthew.