mutex:move mutex holder to struct mutex_s.#7426
Conversation
|
@xiaoxiang781216 @liguiding please review |
|
I am not sure whether we should print mutex holder in sched_dumpstack. |
In a real device and there is no JTAG (mainly for the device just sold out), this method will be helpful for debugging |
|
This change reminded me #6376 (comment) discussion. |
| * for debugging only. | ||
| */ | ||
|
|
||
| if (tid >= 0) |
There was a problem hiding this comment.
why not move to ps and crash dump?
There was a problem hiding this comment.
cmd_ps seems a good place to go.
What do you mean by crash dump? board_crashdump?
There was a problem hiding this comment.
e.g. arm_dumpstate
| if (tid >= 0) | ||
| { | ||
| tcb = nxsched_get_tcb(tid); | ||
| if (tcb != NULL && tcb->task_state == TSTATE_WAIT_SEM) |
There was a problem hiding this comment.
not all semaphore have holder field.
There was a problem hiding this comment.
As a matter of fact, I don't know how to tell the difference.
There is no way to differentiate waiting on a sem or on a mutex.
So I just print possible mutex holder anyway.
What's your suggestion?
There was a problem hiding this comment.
let's check the wait object. If semaphore has PRIOINHERIT_FLAGS_ENABLE flag then most probably it is a mutex and we can upcast it to mutex_t. That is one of the possible variants
There was a problem hiding this comment.
But it can't handle the project which doesn't enable priority inheritance.
There was a problem hiding this comment.
how about we design an internal function like:
int _nxsem_wait(FAR sem_t *sem, bool is_mutex)
Then we can differentiate mutex and sem.
After that, we can add a new TSTATE_WAIT_MUTEX, then we know if a task is waiting on mutex, and we can print the mutex holder in such case.
There was a problem hiding this comment.
An other approach could add a new flag in sem_t::flags to indicate whether is mutex or sem
779b17f to
572b8d0
Compare
572b8d0 to
8d93b6f
Compare
pkarashchenko
left a comment
There was a problem hiding this comment.
IMO we need to design and implement a separate kernel object and cleanup priority inheritance from semaphore
84f8778 to
12aad4e
Compare
|
@anjiahao1 please review this |
So that we can trace who holds the mutex when deadlock happens. Signed-off-by: 田昕 <tianxin7@xiaomi.com>
12aad4e to
c8f25fe
Compare
Signed-off-by: 田昕 tianxin7@xiaomi.com
Summary
We move the mutex holder to struct mutex_s so that we can trace who holds the mutex when deadlock happens.
We also print possible mutex holder in sched_dumpstack.
Impact
mutex_t and related code.
Testing
Tested on ESP32C3