Open pabigot opened 4 years ago
While we're thinking about this topic, it looks the the PREEMPT_RT patch to Linux goes even further and replaces some usages of spinlocks with RT-mutexes. There are caveats and I'm not sure how applicable this is to Zephyr, but interesting nonetheless https://lwn.net/Articles/146861/
API meeting
CONFIG_MULTITHREADING
is n
- Synchronization shall be disabled when
CONFIG_MULTITHREADING
isn
I am against forcing it for all drivers APIs.
When we need exclusive access to resources shared with interrupt context we need to lock interrupts to the level of the ISR(s) accessing it (or we need to disable the ISRs that access it - causing priority inversion). This cannot be done by a k_mutex
, so we will need at least two mechanisms. Which one depends on whether the project configures the interrupt service routine to run in interrupt context or meta-irq context.
Also, don't forget about access in an SMP environment and any issues with access originating from User threads.
There are three types of synchronization necessary for devices, several of which are considered in #22941 and its draft PRs particularly #24511:
The topic of this issue is access control, which historically has been implemented using
k_sem
. As originally raised in this comment I'd like to propose that was usek_mutex
instead, as this offers:The first question is whether this the right move. A follow-up question is whether the generic device API should provide support for any or all of the above synchronizations.
If we use
k_mutex
for access control we would need #25678 to be worked so its operations can be initiated from interrupt context, as is already allowed fork_sem
.