Skip to contentSkip to conversation

SIGXCPU on pthread_mutex_unlock()

Xenomai Steve Hartmann 2 participants 5 messages Oct 7, 2014 – Oct 9, 2014

lore
Share & tools
lore
#0 lore raw

Hi folks,

I'm having an issue I hope someone here might be able to shed some light on.

I am running Xenomai 2.6.4 on linux 3.4.6. The application has a very large source base which was not originally designed for xenomai. I am using xenomai because of some new requirements and the addition of EtherLabs Ethercat master.
So in one of the original threads, which is running at PRI 0, I have two mutexes which when unlocked throw a SIGXCPU signal. These mutexes are only locked/unlocked in this same thread. I have seen this happen when a mutex which is not locked has an unlock attempt. This is not the case for this issue.

What could I be doing which would cause a pthread_mutex_unlock to throw the SIGXCPU signal? Any suggestions for troubleshooting techniques?

#1 lore raw
Quoted 8 lines · Steve Hartmann

Hi folks,

I'm having an issue I hope someone here might be able to shed some light on.

I am running Xenomai 2.6.4 on linux 3.4.6. The application has a very large source base which was not originally designed for xenomai. I am using xenomai because of some new requirements and the addition of EtherLabs Ethercat master.
So in one of the original threads, which is running at PRI 0, I have two mutexes which when unlocked throw a SIGXCPU signal. These mutexes are only locked/unlocked in this same thread. I have seen this happen when a mutex which is not locked has an unlock attempt. This is not the case for this issue.

What could I be doing which would cause a pthread_mutex_unlock to throw the SIGXCPU signal? Any suggestions for troubleshooting techniques?

When you receive the SIGXCPU signal, you should check the reason as demonstrated in the examples/native/sigdebug.c program.

Regards.

--
Gilles.

#2 lore raw
Quoted 5 lines · Gilles Chanteperdrix
Quoted 4 lines · Steve Hartmann

Hi folks,

I'm having an issue I hope someone here might be able to shed some light on.

Quoted 7 lines
Quoted 4 lines

I am running Xenomai 2.6.4 on linux 3.4.6. The application has a very large source base which was not originally designed for xenomai. I am using xenomai because of some new requirements and the addition of EtherLabs Ethercat master.
So in one of the original threads, which is running at PRI 0, I have two mutexes which when unlocked throw a SIGXCPU signal. These mutexes are only locked/unlocked in this same thread. I have seen this happen when a mutex which is not locked has an unlock attempt. This is not the case for this issue.

What could I be doing which would cause a pthread_mutex_unlock to throw the SIGXCPU signal? Any suggestions for troubleshooting techniques?

When you receive the SIGXCPU signal, you should check the reason as demonstrated in the examples/native/sigdebug.c program.

Or see:
http://xenomai.org/2014/06/finding-spurious-relaxes/

--
Gilles.

#3 lore raw
Quoted 21 lines · Gilles Chanteperdrix
Quoted 20 lines · Gilles Chanteperdrix
Quoted 3 lines · Steve Hartmann

Hi folks,

I'm having an issue I hope someone here might be able to shed some

light on.

Quoted 2 lines

I am running Xenomai 2.6.4 on linux 3.4.6. The application has a

very large source base which was not originally designed for xenomai. I am using xenomai because of some new requirements and the addition of EtherLabs Ethercat master.

Quoted 1 line

So in one of the original threads, which is running at PRI 0, I have

two mutexes which when unlocked throw a SIGXCPU signal. These mutexes are only locked/unlocked in this same thread. I have seen this happen when a mutex which is not locked has an unlock attempt. This is not the case for this issue.

Quoted 2 lines

What could I be doing which would cause a pthread_mutex_unlock to

throw the SIGXCPU signal? Any suggestions for troubleshooting techniques?

Quoted 8 lines
Quoted 2 lines

When you receive the SIGXCPU signal, you should check the reason as demonstrated in the examples/native/sigdebug.c program.

Or see:
http://xenomai.org/2014/06/finding-spurious-relaxes/

--
Gilles.

Thanks for the hints. I probably would have found it myself had I been searching for SIGDEBUG instead of SIGXCPU.

Anyway, the reason I am getting a SIGDEBUG_RESCNT_IMBALANCE. I did a search and saw there were some changes between 2.6.2.1 and 2.6.4 regarding the rescnt imbalance. I just so happen to have two machines running this same code - one on 2.6.2.1 and one on 2.6.4. Only the one on 2.6.4 machine is throwing this signal. Either the xenomai change introduced a new bug, or the change in xenomai has exposed a bug in our code. I have reviewed our code and it seems to be correct. I even threw in an extra pthread_mutex_trylock (for troubleshooting) just before the pthread_mutex_unlock and checked the return code just to make sure that it is locked. There are no instances where the extra trylock() actually succeeded, which made me more confident that our code is correct. The mutex is not recursive.

#4 lore raw
Quoted 36 lines · Steve Hartmann
Quoted 18 lines · Gilles Chanteperdrix
Quoted 17 lines · Gilles Chanteperdrix
Quoted 3 lines · Steve Hartmann

Hi folks,

I'm having an issue I hope someone here might be able to shed some

light on.

Quoted 2 lines

I am running Xenomai 2.6.4 on linux 3.4.6. The application has a

very large source base which was not originally designed for xenomai. I am using xenomai because of some new requirements and the addition of EtherLabs Ethercat master.

Quoted 1 line

So in one of the original threads, which is running at PRI 0, I have

two mutexes which when unlocked throw a SIGXCPU signal. These mutexes are only locked/unlocked in this same thread. I have seen this happen when a mutex which is not locked has an unlock attempt. This is not the case for this issue.

Quoted 2 lines

What could I be doing which would cause a pthread_mutex_unlock to

Quoted 9 lines
Quoted 5 lines

throw the SIGXCPU signal? Any suggestions for troubleshooting techniques?

When you receive the SIGXCPU signal, you should check the reason as demonstrated in the examples/native/sigdebug.c program.

Or see:
http://xenomai.org/2014/06/finding-spurious-relaxes/

Thanks for the hints. I probably would have found it myself had I been searching for SIGDEBUG instead of SIGXCPU.

Quoted 6 lines

Anyway, the reason I am getting a SIGDEBUG_RESCNT_IMBALANCE. I did a search and saw there were some changes between 2.6.2.1 and 2.6.4 regarding the rescnt imbalance. I just so happen to have two machines running this same code - one on 2.6.2.1 and one on 2.6.4. Only the one on 2.6.4 machine is throwing this signal. Either the xenomai change introduced a new bug, or the change in xenomai has exposed a bug in our code.

Indeed.

Quoted 6 lines

I have reviewed our code and it seems to be correct. I even
threw in an extra pthread_mutex_trylock (for troubleshooting) just before the pthread_mutex_unlock and checked the return code just to make sure that it is locked. There are no instances where the extra trylock() actually succeeded, which made me more confident that our code is correct. The mutex is not recursive.

The imbalance is not in the mutex lock count, it is an imbalance in a reference counter Xenomai maintains for tasks running with the SCHED_OTHER scheduling policy when then lock and unlock mutexes. Now, as you said, this imbalance means that either we have a bug in Xenomai, or the application does something which does not work with Xenomai, because this reference counter has some shortcomings. One of them being that it does not work correctly if you change scheduling policy (from SCHED_OTHER to SCHED_FIFO or SCHED_RR or the other way around) while holding a mutex.

A way to know for sure is to reduce your test case to a simple self-contained test case that we can run to reproduce the issue.

Regards.

--
Gilles.