You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/2025-08-13-deadlines.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,7 @@ In this case, the reaction in the `NetworkSender` will have the same level as th
173
173
## Early Deadline Violation Detection
174
174
175
175
A deadline violation handler is invoked when a reaction is to be _started_ late.
176
-
Above, we explained how to react to a late _completion time_ of a reaction, but that reaction is not invoked until the reaction actually completes.
176
+
Above, we explained how to react to a late _completion time_ of a reaction, but the handler is not invoked until the reaction actually completes.
177
177
What if you need to react as soon as you know that the completion time will be late?
178
178
Here we describe three complementary mechanisms that can react sooner.
179
179
@@ -184,23 +184,15 @@ This mechanism works when the reaction is _started_ on time, but when we want it
184
184
A nice example of this is given in the [AnytimePrime.lf](https://github.com/lf-lang/playground-lingua-franca/blob/main/examples/C/src/deadlines/AnytimePrime.lf) example in the [deadline collection](https://github.com/lf-lang/playground-lingua-franca/blob/main/examples/C/src/deadlines/README.md) of the [LF playground repo](https://github.com/lf-lang/playground-lingua-franca/tree/main).
185
185
It computes as many prime numbers as it can before exceeding a time budget and then aborts.
186
186
187
-
### Watchdogs
187
+
### Federates as Watchdog-Like Monitors
188
188
189
-
An experimental `watchdog` mechanism is available in LF and is described by
190
-
[Asch, et al., Software-Defined Watchdog Timers for Cyber-Physical Systems](https://ieeexplore.ieee.org/document/10693560).
191
-
A `watchdog` specifies a handler that is invoked if, after the watchdog is started using the [`lf_watchdog_start`](https://www.lf-lang.org/reactor-c/group__API.html#ga82bf2c7bd91fdf03b357914cf875dbb9) function in the [reactor API](https://www.lf-lang.org/reactor-c/group__API.html), the watchdog is not stopped or restarted within the specified amount of physical time.
192
-
193
-
### Federates as Watchdogs
194
-
195
-
The [decentralized coordinator](https://www.lf-lang.org/docs/next/writing-reactors/distributed-execution#decentralized-coordination) for federated execution gives a convenient mechanism for creating a form of watchdog that runs in a separate process or even on a separate machine.
196
-
This can give a more robust detection of a failure because the watchdog monitor can be put on a separate machine from the process being monitored.
189
+
The [decentralized coordinator](https://www.lf-lang.org/docs/next/writing-reactors/distributed-execution#decentralized-coordination) for federated execution gives a convenient mechanism for creating a form of watchdog-like monitor that runs in a separate process or even on a separate machine.
190
+
This can give a robust detection of a failure because the monitor can be put on a separate machine from the process being monitored.
The `Monitored` reactor is simply a federate containing the sensor-processor-actuator chain.
247
239
It is just like above except that it also copies the output of the processor to its own `complete` output.
248
240
249
-
The `Watchdog` federate has a timer that exactly the `Sensor` timer in offset and period.
250
-
It expects an input from the`Monitored` at each tick of this timer.
251
-
The [`STA` parameter](https://www.lf-lang.org/docs/next/writing-reactors/distributed-execution#safe-to-advance-sta) (**safe to advance**) specifies that it is safe to advance the federate's logical time to the logical time of the timer tick when physical time exceeds that logical time plus the `STA`.
252
-
The `STA` is set to 50 ms, so, at physical times 50 ms, 250 ms, 450 ms, etc. after the start time, if an input has not arrived, then the input will be assumed to be absent and the `Watchdog`'s reaction will be invoked.
241
+
The `Monitor` federate has a timer that exactly matches the `Sensor` timer in offset and period.
242
+
The `Monitor`expects an input from `Monitored` at each tick of this timer.
243
+
The [`STA` parameter](https://www.lf-lang.org/docs/next/writing-reactors/distributed-execution#safe-to-advance-sta) (**safe to advance**) specifies that it is safe to advance the federate's logical time to the logical time of the timer tick when physical time exceeds that logical time plus the `STA` even if input status is unknown.
244
+
The `STA` is set to 50 ms, so, at physical times 50 ms, 250 ms, 450 ms, etc. after the start time, if an input has not arrived, then the input will be assumed to be absent and the `Monitor`'s reaction will be invoked.
253
245
The reaction, therefore, just has to check whether the input is present.
254
-
If it is, then the `Monitored` federate is alive and well and its processor output was received by the `Watchdog` within 50 ms.
246
+
If it is, then the `Monitored` federate is alive and well and its processor output was received by the `Monitor` within 50 ms.
255
247
Otherwise, something has gone wrong that has led to a delay greater than 50 ms.
256
248
249
+
### Watchdogs
250
+
251
+
An experimental `watchdog` mechanism is available in LF and is described by
252
+
[Asch, et al., Software-Defined Watchdog Timers for Cyber-Physical Systems](https://ieeexplore.ieee.org/document/10693560).
253
+
A `watchdog` specifies a handler that is invoked if, after the watchdog is started using the [`lf_watchdog_start`](https://www.lf-lang.org/reactor-c/group__API.html#ga82bf2c7bd91fdf03b357914cf875dbb9) function in the [reactor API](https://www.lf-lang.org/reactor-c/group__API.html), the watchdog is not stopped or restarted within the specified amount of physical time.
254
+
255
+
A typical usage is to start a watchdog before a potentially problematic reaction is invoked and then stop the watchdog upon completion of the reaction.
256
+
As soon as the reaction takes too long to complete, the watchdog handler will be invoked.
257
+
258
+
Using watchdogs is tricky because the watchdog handler requires a mutual exclusion lock in order to safely access state variables (see [Asch, et al.](https://ieeexplore.ieee.org/document/10693560).
259
+
For this reason, federates (or, in the future, enclaves) are preferred.
0 commit comments