-
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
Platform support for Embedded targets #106
Conversation
…mon.c but still has linking problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strategy you have followed here relies on the compiler to detect physical actions and set NUMBER_WORKERS, choosing the threaded runtime. This is why the functions in lf_os_single_threaded_support.c can be empty. However, this has a downside: It means the mutex mechanism of the unthreaded runtime is essentially untested. In fact, I have my doubts it is correct. The mutex is held only for very short times compared to the threaded runtime. Seems like there is real risk of lurking race conditions(?).
Only the Arduino is using this, and that doesn't look correct to me because _lf_timer_interrupted seems to never get reset. Do we have any way to test the Arduino implementation?
What I had in mind was to actually allow physical actions with the unthreaded runtime. This means the mutex acquisition and release should closely mimic (or exactly match) what reactor_threaded.c does. This also means we could have regression tests that have physical actions with the unthreaded runtime running on all the platforms.
…ake sure we advance to the correct tag
It's been a while since I looked at this code, but I think the new API for entering a critical section will take care of a big part of the problem, which is that tracing calls write to a common data structure. Alternatively, this could be refactored to have a separate data structure per worker. I think the reason for needing to create a thread is to write to a file when the data structure fills up. I guess this could be handled differently in the unthreaded runtime with conditional code. |
OK, so you are saying that if we are using the unthreaded runtime with tracing enabled, I don't see the place in |
@lhstrh. After a converation with @edwardalee about tracing today I have concluded that the current implementation is sufficient. The tracing only needs to synchronize access "internally". This is done with a mutex local to From all the source files including I will do a pass through the PR and address Edwards comments and fix what I see, then I guess we could do a final review and merge? |
Co-authored-by: Edward A. Lee <eal@eecs.berkeley.edu>
core/platform/lf_arduino_support.c
Outdated
|
||
/** | ||
* @brief Sleep until an absolute time. | ||
* FIXME: For improved power consumption this should be implemented with a HW timer and interrupts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sleep until is for internal use only and should only be called from a critical section, while advancing time. Maybe the API should be: _lf_sleep_until_locked
?
core/platform/lf_arduino_support.c
Outdated
return 0; | ||
} | ||
|
||
int lf_critical_section_enter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for suggestion will add this!
core/platform/lf_nrf52_support.c
Outdated
* set appropriately (see `man 2 clock_gettime`). | ||
*/ | ||
int lf_clock_gettime(instant_t* t) { | ||
if (t == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments...
core/trace.c
Outdated
@@ -29,14 +29,19 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* Include this file instead of trace.h to get tracing. | |||
* See trace.h file for instructions. | |||
*/ | |||
|
|||
// FIXME: Should be renamed if we use the hack below maybe: LF_INCLUDE_TRACE_FILES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this FIXME
should not be left unaddressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. My suggestion is to call it LF_TRACE
, and the macro below can be called _LF_TRACE
. The second macro should never be messed with by the user and is only for getting the threaded API from platform.h even if the unthreaded runtime is used
include/core/platform.h
Outdated
@@ -42,8 +42,20 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
#ifndef PLATFORM_H | |||
#define PLATFORM_H | |||
|
|||
#if defined(ARDUINO) | |||
// FIXME: We could also use a single flag since this is truly binary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the fixme. I think it is okay to have 2 flags (THREADED and UNTHREADED)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, that sounds confusing though. What if both are true?
Co-authored-by: Marten Lohstroh <marten@berkeley.edu>
What is the status of this lock-time PR? |
It's almost ready, but there are still a few small things that need @erlingrj's attention (comments ☝️). Once addressed, we can merge. |
include/core/platform.h
Outdated
@@ -42,8 +42,20 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
#ifndef PLATFORM_H | |||
#define PLATFORM_H | |||
|
|||
#if defined(ARDUINO) | |||
// FIXME: We could also use a single flag since this is truly binary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the fixme. I think it is okay to have 2 flags (THREADED and UNTHREADED)
#else | ||
#include "lf_C11_threads_support.h" | ||
#endif | ||
#include "lf_os_single_threaded_support.c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Windows implementation is moved to its header-file (like it is for macOS and Linux). This makes it possible to have both the threaded and the unthreaded API present in the same binary.
core/trace.c
Outdated
@@ -29,14 +29,19 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* Include this file instead of trace.h to get tracing. | |||
* See trace.h file for instructions. | |||
*/ | |||
|
|||
// FIXME: Should be renamed if we use the hack below maybe: LF_INCLUDE_TRACE_FILES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. My suggestion is to call it LF_TRACE
, and the macro below can be called _LF_TRACE
. The second macro should never be messed with by the user and is only for getting the threaded API from platform.h even if the unthreaded runtime is used
#endif | ||
|
||
int lf_critical_section_enter() { | ||
// FIXME: Is this what we want? Dont we want to grab a mutex here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the unthreaded runtime + Linux is intended to be a very special case where you should not use other threads to schedule physical actions. I think the macro above would catch such a scenario. I think we can close this for now. I will remove the fixme
Co-authored-by: Marten Lohstroh <marten@berkeley.edu>
This PR creates runtime support for (bare-iron) single-threaded targets with interrupts.
Polish existing NRF52 support
wait_until
tolf_sleep_until
lf_sleep_until
into smaller functionsSettle on API changes
LF_MIN_SLEEP_DURATION
to platform supportARDUINO
directive and addNO_TTY
or something along those linesMerge changes into
lock-time
Merge
main
intolock-time
General cleanup, comments, and removal of spurious
.c
-file includesFixes #109
Companion of lf-lang/lingua-franca#1348.