nuttx
nuttx copied to clipboard
sched:rw_sem: replace mutex with spinlock
Summary
The overhead of spinlok is less than mutext (mutex need to call enter_critical section.)
After this patch, down_write_trylock
and down_read_trylock
can be use in interrupt context.
Impact
semaphore
Testing
CI
Hi @xiaoxiang781216,
Do you know why some platform not config spinlock? Even in 1cpu, in multi-threading environment spinlock is also needed.
How do you think this path? Is it reasonable?
Ping @xiaoxiang781216
Hi @xiaoxiang781216,
Do you know why some platform not config spinlock? Even in 1cpu, in multi-threading environment spinlock is also needed.
How do you think this path? Is it reasonable?
spinlock isn't required for single core.
Hi @xiaoxiang781216, Do you know why some platform not config spinlock? Even in 1cpu, in multi-threading environment spinlock is also needed. How do you think this path? Is it reasonable?
spinlock isn't required for single core.
Yes, your right. If we do not consider single core. Use spinlock is better than mutex right?
For single core, we also don't need spinlock. Is there any problem? Or I missed something?
In the single core, spinlock map to disable/enable irq
In the single core, spinlock map to disable/enable irq
Oh, I made a mistake.
If I want to replace mutex with spinlock, I should use spinlock_irqsave()
and spinlock_irqrestore()
.
In the mutex, it will call enter_critical_section
, this function will disable interrupt, right?
If only use spinlock, the interrupt is not disable.
But It will increase interrupt latency.
Hi @xiaoxiang781216, Do you know why some platform not config spinlock? Even in 1cpu, in multi-threading environment spinlock is also needed. How do you think this path? Is it reasonable?
spinlock isn't required for single core.
In my mind, single core may need spinlock too, because there are two hardware threading(register sets) in a core.
Hi @xiaoxiang781216, Do you know why some platform not config spinlock? Even in 1cpu, in multi-threading environment spinlock is also needed. How do you think this path? Is it reasonable?
spinlock isn't required for single core.
In my mind, single core may need spinlock too, because there are two hardware threading(register sets) in a core.
no, disable interrupt could forbid other thread switch in.
@TaiJuWu Which configuration does the CI use to check this PR?
@TaiJuWu Which configuration does the CI use to check this PR?
You can see the related log of CI. https://github.com/apache/nuttx/pull/11769#discussion_r1526280639
@TaiJuWu Which configuration does the CI use to check this PR?
You can see the related log of CI. #11769 (comment)
So, do you mean that this PR does not break the CI now? However, my understanding is that there is no test code that uses rw_sem so far.
@TaiJuWu Which configuration does the CI use to check this PR?
You can see the related log of CI. #11769 (comment)
So, do you mean that this PR does not break the CI now? However, my understanding is that there is no test code that uses rw_sem so far.
Both answers are yes. There is no testcase for rw_sem at run time.