Skip to content

Commit e9b0e3b

Browse files
committed
Tuning
1 parent 4441984 commit e9b0e3b

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

blog/2025-08-13-deadlines.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ In this case, the reaction in the `NetworkSender` will have the same level as th
173173
## Early Deadline Violation Detection
174174

175175
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.
177177
What if you need to react as soon as you know that the completion time will be late?
178178
Here we describe three complementary mechanisms that can react sooner.
179179

@@ -184,23 +184,15 @@ This mechanism works when the reaction is _started_ on time, but when we want it
184184
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).
185185
It computes as many prime numbers as it can before exceeding a time budget and then aborts.
186186

187-
### Watchdogs
187+
### Federates as Watchdog-Like Monitors
188188

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.
197191

198192
Consider the following example:
199193

200194
![FederatedWatchdog diagram](../static/img/blog/FederatedWatchdog.svg)
201195

202-
The code for this is:
203-
204196
```lf-c
205197
target C {
206198
coordination: decentralized
@@ -217,7 +209,7 @@ reactor Monitored(exec = 10 ms) {
217209
p.out -> complete
218210
}
219211
220-
reactor Watchdog(STA: time = 50 ms) {
212+
reactor Monitor(STA: time = 50 ms) {
221213
input inp:int
222214
timer t(0, 200 ms)
223215
@@ -238,22 +230,33 @@ federated reactor {
238230
@label("exec = 60 ms")
239231
m = new Monitored(exec = 60 ms)
240232
@label("STA = 50 ms")
241-
w = new Watchdog()
233+
w = new Monitor()
242234
m.complete -> w.inp
243235
}
244236
```
245237

246238
The `Monitored` reactor is simply a federate containing the sensor-processor-actuator chain.
247239
It is just like above except that it also copies the output of the processor to its own `complete` output.
248240

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.
253245
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.
255247
Otherwise, something has gone wrong that has led to a delay greater than 50 ms.
256248

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.
257260

258261
## Ongoing Research
259262

blog/src/FederatedWatchdog.lf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Use of the decentralized coordinator to implement a watchdog.
2+
* Use of the decentralized coordinator to implement a watchdog-like monitor.
33
*/
44
target C {
55
timeout: 1 s,
@@ -17,7 +17,7 @@ reactor Monitored(exec = 10 ms) {
1717
p.out -> complete
1818
}
1919

20-
reactor Watchdog(STA: time = 50 ms) {
20+
reactor Monitor(STA: time = 50 ms) {
2121
input inp:int
2222
timer t(0, 200 ms)
2323

@@ -38,6 +38,6 @@ federated reactor {
3838
@label("exec = 60 ms")
3939
m = new Monitored(exec = 60 ms)
4040
@label("STA = 50 ms")
41-
w = new Watchdog()
41+
w = new Monitor()
4242
m.complete -> w.inp
4343
}

0 commit comments

Comments
 (0)