Watchdogs #1379
Replies: 2 comments
-
The implementation looks good to me. We will also require to acquire the mutex before invoking any other reaction in the same Reactor. For the single-threaded targets we would need to go to sleep on HW timer and have the watchdog body be invoked either in:
I think this means that we need a unique timer (or timer channel) for each watchdog. This is how I would do it:
I think there are many edge cases here and the design for single-threaded runtime must be thought through more thoroughly. But an important observation is that this is not feasible without using Timer peripherals external to the CPU which mean that we should probably re-evaluate the idea of build bare-metal support just on the CPU rather than on the SDK |
Beta Was this translation helpful? Give feedback.
-
StepsAdding new syntax
Reactor-c runtime
|
Beta Was this translation helpful? Give feedback.
-
Watchdogs
A watchdog is specified as follows:
The
min_timeout
parameter is optional and defaults to zero. In the target language, there are two API functions:Let
timeout
=additional_timeout
+min_timeout
. When you calllf_watchdog_start
, a physical timer gets set to expire at physical time equal to the current logical time t plus thetimeout
. Iflf_watchdog_stop
is called before the physical timer expires, then the timer is canceled. Iflf_watchdog_start
is called again before the physical timer expires, then it simply gets reset to expire at the newly specified time.If and when the physical timer expires, two things happen. First, if an optional code body is specified with the watchdog declaration, then that code body is executed. This code will be mutually exclusive with any reactions in the same reactor. It has access to the
self
struct, and can therefore read parameters and read and write state variables. It does not have access to ports, actions, or watchdogs.Second, any reactions that list
watchdog_name
among their triggers will be invoked at the current logical time plus one microstep. NOTE: An alternative would be schedule it like a physical action. Which is better?Usage patterns:
Lag monitor:
The goal is to ensure that logical time does not lag too much behind physical time.
The
panic()
function will be invoked if an only if the reaction to timert
does not get invoked by physical time n x 10 + 100 ms, where n is 0 for the first timer tick, 1 for the second, etc. Note that this is distinct from adeadline
, where the handler is invoked if the n-th reaction tot
is invoked after physical time n x 10 plus the deadline time.One-Time Lag Monitor:
The above example restarts the watchdog on every timer tick, but we may not want to restart the watchdog after it expires once. This is accomplished by:
Notice that there is a race condition between the two code bodies. If the watchdog timer expires right around the time that the timer reaction is being invoked, then the order in which the watchdog body and the reaction body are invoked is not defined. If the timer reaction is invoked first, then the invocation of the watchdog body will be canceled.
Mode Switch
FIXME: Mode switch example with a reaction triggered by the watchdog.
Implementation
The watchdog has a state variable
expiration
that is a time initialized to NEVER.Sketch:
The thread body looks like this:
Questions and Discussion
Note that the watchdog body has no access to actions and hence cannot call schedule. This is why the watchdog is also a trigger.
Note that the watchdog trigger will occur at the next available logical tag, as if a logical action had been asynchronously scheduled (something that is not allowed). The reason for this is that if we were instead to treat it as a physical action, it could end up on the event queue behind many other events that will have to be handled before you can react to the watchdog expirations.
Note that it might be tempting to use this mechanism to achieve anytime computation, where you set a physical time bound on the execution of a reaction and then interrupt it when that time expires. However, this will not work because the watchdog handler is mutually exclusive with the reactions in the same reactor. To achieve anytime computation, use FIXME (checking deadlines during runtime).
In case we want a mechanism that aborts a rogue long running reaction, a general method might be to have the runtime call
setjmp
prior to executing a reaction. Then exception handling code could calllongjmp
to abort the reaction. Problems:How to handle shutdown? Stop all watchdogs?
Beta Was this translation helpful? Give feedback.
All reactions