Deadlock in CANCEL_RESTORE with CONFIG_XENO_ASYNC_CANCEL during thread suspension
Hi all,
using xenomai-forge with mercury, when CONFIG_XENO_ASYNC_CANCEL is defined, CANCEL_RESTORE will include a call to backtrace_check(), which in turn will call backtrace_dump, which will take the mutex "__printlock".
In case a thread gets suspended while holding that lock, the next call to CANCEL_RESTORE from whatever thread will cause a deadlock.
Is there any way of getting around that?
Regards,
Matthias
Quoted 11 lines · Matthias Schneider
Hi all,
using xenomai-forge with mercury, when
CONFIG_XENO_ASYNC_CANCELis defined,CANCEL_RESTOREwill include a call tobacktrace_check(), which in turn will callbacktrace_dump, which will take the mutex "__printlock".In case a thread gets suspended while holding that lock, the next call to
CANCEL_RESTOREfrom whatever thread will cause a deadlock.
That's the price for using thread suspend/resume unsafe constructs, we never know at which location we will be preempting threads.
Quoted 3 lines
Is there any way of getting around that?
We could block the notification signal when holding this internal lock. I'll have a look.
Signature · 1 line
Philippe.
----- Original Message -----
Quoted 24 lines
From: Philippe Gerum <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Monday, April 7, 2014 11:59 AM
Subject: Re: [Xenomai] Deadlock inCANCEL_RESTOREwithCONFIG_XENO_ASYNC_CANCELduring thread suspensionQuoted 11 lines · Matthias Schneider
Hi all,
using xenomai-forge with mercury, when
CONFIG_XENO_ASYNC_CANCELis defined,CANCEL_RESTOREwill include a call tobacktrace_check(), which in turn will callbacktrace_dump, which will take the mutex "__printlock".In case a thread gets suspended while holding that lock, the next call to
CANCEL_RESTOREfrom whatever thread will cause a deadlock.That's the price for using thread suspend/resume unsafe constructs, we never know at which location we will be preempting threads.
Quoted 1 line
Quoted 9 lines
Quoted 2 lines
Is there any way of getting around that?
We could block the notification signal when holding this internal lock. I'll have a look.
Signature · 1 line
Philippe.
Would the enclosed patch be an acceptable solution to the problem? It seems to work quite well in my case.
Regards,
Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace_dump_block_signals.patch
Type: text/x-patch
Size: 1109 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20140416/62286c16/attachment.bin>
Quoted 32 lines · Matthias Schneider
----- Original Message -----
Quoted 30 lines
From: Philippe Gerum <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Monday, April 7, 2014 11:59 AM
Subject: Re: [Xenomai] Deadlock inCANCEL_RESTOREwithCONFIG_XENO_ASYNC_CANCELduring thread suspensionQuoted 11 lines · Matthias Schneider
Hi all,
using xenomai-forge with mercury, when
CONFIG_XENO_ASYNC_CANCELis defined,CANCEL_RESTOREwill include a call tobacktrace_check(), which in turn will callbacktrace_dump, which will take the mutex "__printlock".In case a thread gets suspended while holding that lock, the next call to
CANCEL_RESTOREfrom whatever thread will cause a deadlock.That's the price for using thread suspend/resume unsafe constructs, we never know at which location we will be preempting threads.
Quoted 3 lines
Is there any way of getting around that?
We could block the notification signal when holding this internal lock. I'll have a look.
Quoted 7 lines
Quoted 3 lines
--
Philippe.Would the enclosed patch be an acceptable solution to the problem? It seems to work quite well in my case.
We need to block the notification signal each time the printout serialization lock is acquired, not only when dumping a backtrace.
It is also preferable not to assume any sigmask disposition when doing so, i.e. forcibly unblocking SIGNOTIFY may prove dangerous in the future, depending on the call site.
Also, the code should work for both the mercury and cobalt cores.
The commit below should address these issues:
http://git.xenomai.org/xenomai-forge.git/commit/?h=next&id=9ba637cc7902cea15944a894443e22caf0c19139
Signature · 1 line
Philippe.
----- Original Message -----
Quoted 58 lines
From: Philippe Gerum <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Monday, April 21, 2014 12:48 PM
Subject: Re: [Xenomai] Deadlock inCANCEL_RESTOREwithCONFIG_XENO_ASYNC_CANCELduring thread suspensionQuoted 4 lines · Matthias Schneider
----- Original Message -----
Quoted 2 lines
From: Philippe Gerum <[email protected]>
To: Matthias Schneider <[email protected]>;"[email protected]" <[email protected]>
Quoted 3 lines
Quoted 3 lines
Cc:
Sent: Monday, April 7, 2014 11:59 AM
Subject: Re: [Xenomai] Deadlock inCANCEL_RESTOREwith
CONFIG_XENO_ASYNC_CANCELduring thread suspensionQuoted 10 lines
Quoted 10 lines · Matthias Schneider
Quoted 8 lines
Hi all,
using xenomai-forge with mercury, when
CONFIG_XENO_ASYNC_CANCELis defined,CANCEL_RESTOREwill include a call tobacktrace_check(), which in turn will callbacktrace_dump, which will take the mutex "__printlock".Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
In case a thread gets suspended while holding that lock, the next call to
CANCEL_RESTOREfrom whatever thread will cause a deadlock.That's the price for using thread suspend/resume unsafe constructs,
we
Quoted 7 lines
Quoted 7 lines
never know at which location we will be preempting threads.
Quoted 3 lines
Is there any way of getting around that?
Quoted 8 lines
Quoted 6 lines
We could block the notification signal when holding this internal lock. I'll have a look.
--
Philippe.Would the enclosed patch be an acceptable solution to the problem? It seems
to
Quoted 2 lines
work quite well in my case.
We need to block the notification signal each time the printout serialization lock is acquired, not only when dumping a backtrace.
It is also preferable not to assume any sigmask disposition when doing so, i.e. forcibly unblocking SIGNOTIFY may prove dangerous in the future, depending on the call site.
Quoted 10 lines
Also, the code should work for both the mercury and cobalt cores.
The commit below should address these issues:
http://git.xenomai.org/xenomai-forge.git/commit/?h=next&id=9ba637cc7902cea15944a894443e22caf0c19139
Signature · 1 line
Philippe.
I can confirm that the fix is working - thanks for correcting my patch. In general, thread suspension on mercury seems to be working quite reliably now, I will let you know when/if I find another issue.
Matthias