-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interrupts may cause deadlocks with threaded runtime #393
Comments
This is a major issue for embedded platforms. Thanks for raising it. A couple of comments:
In summary, (2) looks like the best solution to me. |
I think we should use this opportunity to map this out entirely. As I see it there are actually two distinct synchronization needs:
How to do (1) and (2) depends on the following questions: We can make a matrix of this:
So basically, how to implement the synchronization will depend on the program and if it has physical actions, and if so, who can schedule event to those. For the threaded runtime, it makes sense that for all synchronization belonging to (1), it should use the platform API with I think this aligns with your suggestions, but without sacrificing performance (due to globally disabling interrupts) unless the program absolutely requires it. If we bring enclaves into the mix, then the implementation of the new level of indirection should be implemented differently for each enclave depending on whether it has physical actions on who is scheduling on it. |
#488 may be a fix; I started testing before I graduated but never finished it unfortunately |
Currently, the threaded runtime uses mutexes to maintain exclusive access to key data structures (namely, environments). On embedded systems, lingua franca also supports scheduling physical actions from interrupts, via
lf_schedule
. However, the following sequence of events may occur:LF_MUTEX_LOCK(&env->mutex)
)lf_schedule
, which also modifies the environment.In this case, the mutex was unhelpful, and the environment could be corrupted by the interrupt handler. The situation is even worse if the
lf_schedule
tries to acquire the mutex (is this the case? I could not find aLF_MUTEX_LOCK
line). Then, deadlock occurs inside the interrupt handler.There are a few potential solutions to this:
lf_mutex_init
andlf_mutex_init_with_interrupts
). The environments would be locked with "interrupt mutexes", and reactors locked with regular mutexes. On most platforms, the two APIs would just be equivalent. However, this would be a 3rd type of locking-related API (in addition to regular mutexes and critical sections), which may clutter the platform API.lf_schedule_external
, for scheduling from interrupts. Instead of modifying the environment, this function could have it's own queue for external events. Then whenever an event occurs, the scheduler would need to transfer external events from the external event queue onto the regular event queue. The advantage of this approach is that interrupts only need to be disabled when the external event queue is being modified. The main issue with this approach would be "waking up" the scheduler whenever the external event queue has something new; Currently, waking up is handled by_lf_cond_timedwait
, which assumes a mutex.The text was updated successfully, but these errors were encountered: