use rmutex inside of all repeated implementation#6320
Conversation
ca0bc6f to
133f87a
Compare
e9db895 to
9aeddfe
Compare
aa0d037 to
3d021b1
Compare
pkarashchenko
left a comment
There was a problem hiding this comment.
In general looks good. Just few comments left
4614cf6 to
dfd8bae
Compare
|
Wow, that is something new. Need to check mainline builds |
0277763 to
d9d5704
Compare
|
@xiaoxiang781216 I see that we are attempting to solve the mutex issue with "small blood", but IMO we need to look deeper. We have priority inheritance in place that should be applied to mutex only, but is implemented at semaphore level (that I believe is totally wrong), so we have holder for mutex and holder for semaphore in case of priority inheritance that at the moment of time when mutex is held are the same process IDs. |
Yes, I agree that it isn't good to use semaphore both for the signal and lock. That's why we add nxmutex_t and nxrmutex_t:
With the above change, we can get the clean code base that:
The next steps are:
After this, all priority inheritance should get fixed. Of course, we can move the implementation of priority inheritance from sem_t to mutex_t, so people never get the unexpected behavior with semaphore. |
|
Sounds like a plan :) |
d17c862 to
3310dec
Compare
a21b691 to
6ac80a8
Compare
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
| static inline int syslog_dev_takesem(FAR struct syslog_dev_s *syslog_dev) | ||
| { | ||
| pid_t me = getpid(); | ||
| int ret; | ||
|
|
||
| /* Does this thread already hold the semaphore? That could happen if | ||
| * we were called recursively, i.e., if the logic kicked off by | ||
| * file_write() where to generate more debug output. Return an | ||
| * error in that case. | ||
| */ | ||
|
|
||
| if (syslog_dev->sl_holder == me) | ||
| { | ||
| /* Return an error (instead of deadlocking) */ | ||
|
|
||
| return -EWOULDBLOCK; | ||
| } | ||
|
|
||
| /* Either the semaphore is available or is currently held by another | ||
| * thread. Wait for it to become available. | ||
| */ | ||
|
|
||
| ret = nxsem_wait(&syslog_dev->sl_sem); | ||
| if (ret < 0) | ||
| { | ||
| return ret; | ||
| } | ||
|
|
||
| /* We hold the semaphore. We can safely mark ourself as the holder | ||
| * of the semaphore. | ||
| */ | ||
|
|
||
| syslog_dev->sl_holder = me; | ||
| return OK; | ||
| } |
There was a problem hiding this comment.
@xiaoxiang781216 I observe deadlock after I migrate my application to the latest NuttX master. I narrow down the issue and see that it happens when multiple tasks try to use syslog. I have a syslog configuration with 2 channels:
- Channel attached to console
- Channel attached to file on
/mnt/sdcard0/nuttx.log
When the issue happens I observe next picture:

I've noticed that before this change syslog_dev_takesem returned return -EWOULDBLOCK; with a comment /* Return an error (instead of deadlocking) */ and seems like this functionality has been broken now.
In general I think that we rush too much with replacing of semaphores with mutexes. For example the FLAT build functioning changed after this change since all nxsem_ API calls became replaced with sem_ API calls and introduced unnecessary cancellation points in kernel. I'm not sure about the side effect of this, but still investigating.
I think we need to revert part of the changes from this PR especially syslog part and part related to replacement in libc and get back nxmutex_ to use nxsem_ APIs only and use it in kernel part only for now. Then make a step-by-step change to user space.


Signed-off-by: anjiahao anjiahao@xiaomi.com
Impact
maybe Slightly reduced szie and increased speed
Testing
CI