Skip to content

Commit ca1f4c9

Browse files
authored
Shutdown and termination sig handling (#15)
* Implement graceful shutdown and termination signalling * ctrlc is not built after rebasing * fixed ctrlc(score_crates) issue * use alloc and core libs instead of std whenever possible
1 parent a1f4373 commit ca1f4c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1175
-483
lines changed

Cargo.lock

Lines changed: 265 additions & 280 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ feo-log = { path = "feo-log" }
3232
feo-logger = { path = "feo-logger" }
3333
feo-time = { path = "feo-time" }
3434
feo-tracing = { path = "feo-tracing" }
35+
ctrlc = { version = "3.4.4", features = ["termination"] }
3536
futures = "0.3.31"
3637
human_bytes = "0.4.3"
3738
iceoryx2 = "0.5.0"
@@ -64,7 +65,6 @@ tracing = { version = "0.1.41", features = [
6465
"attributes",
6566
], default-features = false }
6667
tracing-subscriber = { version = "0.3.19", default-features = false }
67-
6868
[profile.profiling]
6969
inherits = "release"
7070
debug = true

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ git_override(
3333
bazel_dep(name = "score_crates", version = "1.0.0")
3434
git_override(
3535
module_name = "score_crates",
36-
commit = "2f0616c5af797f05788e4e5cad16f37699ea7a17",
36+
commit = "0748fc81379faf33dcb5616e7f0f4c17bce79372",
3737
remote = "https://github.com/eclipse-score/score-crates.git",
3838
)
3939

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Install *bytehound* with the following commands:
8989

9090
```sh
9191
wget https://github.com/koute/bytehound/releases/download/0.11.0/bytehound-x86_64-unknown-linux-gnu.tgz
92-
tar xzf bytehound-x86_64-unknown-linux-gnu.tgz bytehound libbytehound.so
92+
tar xzf bytehound-x86_64-unknown-linux-gnu.tgz bytehound libbytehound.so
9393
mv bytehound libbytehound.so $HOME/.cargo/bin
9494
```
9595

@@ -113,5 +113,3 @@ bytehound server memory-profiling_*.dat
113113

114114
Click on the [link](http://127.0.0.1:8080) in the output to open the browser and
115115
see the results. Setup ssh port forwarding if needed when working remote (`ssh -L 8080:localhost:8080 host`).
116-
117-

examples/rust/cycle-benchmark/src/bin/cycle_bench.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ mod direct_mpsc {
188188

189189
let agent_id = params.agent_id;
190190
PrimaryConfig {
191+
id: agent_id,
191192
cycle_time: params.feo_cycle_time,
192193
activity_dependencies: app_config.activity_dependencies(),
193194
// With only one agent, we cannot attach a recorder
@@ -237,13 +238,24 @@ mod direct_sockets {
237238
) -> PrimaryConfig {
238239
let agent_id = params.agent_id;
239240
PrimaryConfig {
241+
id: agent_id,
240242
cycle_time: params.feo_cycle_time,
241243
activity_dependencies: app_config.activity_dependencies(),
242244
recorder_ids: app_config.recorders(),
243245
worker_assignments: app_config.worker_assignments().remove(&agent_id).unwrap(),
244246
timeout: Duration::from_secs(10),
245247
connection_timeout: Duration::from_secs(10),
246248
endpoint: endpoint(&app_config, signalling),
249+
activity_agent_map: app_config
250+
.activity_worker_map()
251+
.iter()
252+
.map(|(act_id, w_id)| {
253+
(
254+
*act_id,
255+
app_config.worker_agent_map().get(w_id).copied().unwrap(),
256+
)
257+
})
258+
.collect(),
247259
}
248260
}
249261

examples/rust/mini-adas/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ rust_library(
5858
crate_features = [
5959
"com_linux_shm",
6060
"recording",
61-
"signalling_relayed_tcp",
61+
"signalling_direct_tcp",
6262
],
6363
crate_name = "mini_adas",
6464
proc_macro_deps = [
@@ -131,7 +131,7 @@ rust_binary(
131131
],
132132
crate_features = [
133133
"recording",
134-
"signalling_relayed_tcp",
134+
"signalling_direct_tcp",
135135
],
136136
visibility = ["//visibility:public"],
137137
deps = [

examples/rust/mini-adas/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,19 @@ cargo run --no-default-features --features signalling_direct_tcp --bin adas_seco
9393
cargo run --no-default-features --features signalling_direct_tcp --bin adas_secondary 2
9494
```
9595

96+
### Direct Mode with a Recorder
97+
98+
To run with a recorder in direct mode.
99+
100+
```sh
101+
# Use 400ms cycle time and wait for recorder 900
102+
cargo run --no-default-features --features "signalling_direct_tcp,com_iox2" --bin adas_primary -- 400 900
103+
```
104+
105+
```sh
106+
# Start recorder with ID 900 in direct mode
107+
cargo run --no-default-features --features "signalling_direct_tcp,recording,com_iox2" --bin adas_recorder -- 900
108+
```
109+
96110
Note that for mpsc-only signalling, there can be only a primary process without
97-
any secondaries or recorders, because mpsc does not support inter-process signalling.
111+
any secondaries or recorders, because mpsc does not support inter-process signalling.

examples/rust/mini-adas/src/activities/components.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ impl Activity for Camera {
9898
}
9999

100100
#[instrument(name = "Camera shutdown")]
101-
fn shutdown(&mut self) {}
101+
fn shutdown(&mut self) {
102+
debug!("Shutting down Camera activity {}", self.activity_id);
103+
}
102104
}
103105

104106
/// Radar activity
@@ -161,7 +163,9 @@ impl Activity for Radar {
161163
}
162164

163165
#[instrument(name = "Radar shutdown")]
164-
fn shutdown(&mut self) {}
166+
fn shutdown(&mut self) {
167+
debug!("Shutting down Radar activity {}", self.activity_id);
168+
}
165169
}
166170

167171
/// Neural network activity
@@ -251,7 +255,9 @@ impl Activity for NeuralNet {
251255
}
252256

253257
#[instrument(name = "NeuralNet shutdown")]
254-
fn shutdown(&mut self) {}
258+
fn shutdown(&mut self) {
259+
debug!("Shutting down NeuralNet activity {}", self.activity_id);
260+
}
255261
}
256262

257263
/// Emergency braking activity
@@ -328,7 +334,12 @@ impl Activity for EmergencyBraking {
328334
}
329335

330336
#[instrument(name = "EmergencyBraking shutdown")]
331-
fn shutdown(&mut self) {}
337+
fn shutdown(&mut self) {
338+
debug!(
339+
"Shutting down EmergencyBraking activity {}",
340+
self.activity_id
341+
);
342+
}
332343
}
333344

334345
/// Brake controller activity
@@ -378,7 +389,12 @@ impl Activity for BrakeController {
378389
}
379390

380391
#[instrument(name = "BrakeController shutdown")]
381-
fn shutdown(&mut self) {}
392+
fn shutdown(&mut self) {
393+
debug!(
394+
"Shutting down BrakeController activity {}",
395+
self.activity_id
396+
);
397+
}
382398
}
383399

384400
/// Environment renderer activity
@@ -422,7 +438,12 @@ impl Activity for EnvironmentRenderer {
422438
}
423439

424440
#[instrument(name = "EnvironmentRenderer shutdown")]
425-
fn shutdown(&mut self) {}
441+
fn shutdown(&mut self) {
442+
debug!(
443+
"Shutting down EnvironmentRenderer activity {}",
444+
self.activity_id
445+
);
446+
}
426447
}
427448

428449
/// Steering controller activity
@@ -470,7 +491,12 @@ impl Activity for SteeringController {
470491
}
471492

472493
#[instrument(name = "SteeringController shutdown")]
473-
fn shutdown(&mut self) {}
494+
fn shutdown(&mut self) {
495+
debug!(
496+
"Shutting down SteeringController activity {}",
497+
self.activity_id
498+
);
499+
}
474500
}
475501

476502
/// Create an activity input.

examples/rust/mini-adas/src/bin/adas_primary.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ mod cfg {
9999

100100
pub(super) fn make_config(params: Params) -> PrimaryConfig {
101101
PrimaryConfig {
102+
id: AGENT_ID,
102103
cycle_time: params.feo_cycle_time,
103104
activity_dependencies: activity_dependencies(),
104105
// With only one agent, we cannot attach a recorder
@@ -113,51 +114,91 @@ mod cfg {
113114
#[cfg(feature = "signalling_direct_tcp")]
114115
mod cfg {
115116
use super::{check_ids, Duration, Params, AGENT_ID};
116-
use feo::agent::NodeAddress;
117-
use feo::ids::AgentId;
118-
use mini_adas::config::{activity_dependencies, agent_assignments, BIND_ADDR};
119-
use std::collections::HashSet;
117+
use feo::{
118+
agent::NodeAddress,
119+
ids::{ActivityId, AgentId, WorkerId},
120+
};
121+
use mini_adas::config::{
122+
activity_dependencies, agent_assignments, worker_agent_map, BIND_ADDR,
123+
};
124+
use std::collections::{HashMap, HashSet};
120125

121126
pub(super) use feo::agent::direct::primary::{Primary, PrimaryConfig};
122127

123128
pub(super) fn make_config(params: Params) -> PrimaryConfig {
124129
let agent_ids: HashSet<AgentId> = agent_assignments().keys().copied().collect();
125130
check_ids(&params.recorder_ids, &agent_ids);
126131

132+
let activity_worker_map: HashMap<ActivityId, WorkerId> = agent_assignments()
133+
.values()
134+
.flat_map(|vec| {
135+
vec.iter()
136+
.flat_map(move |(wid, aid_b)| aid_b.iter().map(|v| (v.0, *wid)))
137+
})
138+
.collect();
139+
127140
PrimaryConfig {
141+
id: AGENT_ID,
128142
cycle_time: params.feo_cycle_time,
129143
activity_dependencies: activity_dependencies(),
130144
recorder_ids: params.recorder_ids,
131145
worker_assignments: agent_assignments().remove(&AGENT_ID).unwrap(),
132146
timeout: Duration::from_secs(10),
133147
connection_timeout: Duration::from_secs(10),
134148
endpoint: NodeAddress::Tcp(BIND_ADDR),
149+
activity_agent_map: activity_worker_map
150+
.iter()
151+
.map(|(activity_id, worker_id)| {
152+
let agent_id = worker_agent_map().get(worker_id).copied().unwrap();
153+
(*activity_id, agent_id)
154+
})
155+
.collect(),
135156
}
136157
}
137158
}
138159

139160
#[cfg(feature = "signalling_direct_unix")]
140161
mod cfg {
141162
use super::{check_ids, Duration, Params, AGENT_ID};
142-
use feo::agent::NodeAddress;
143-
use feo::ids::AgentId;
144-
use mini_adas::config::{activity_dependencies, agent_assignments, socket_paths};
145-
use std::collections::HashSet;
163+
use feo::{
164+
agent::NodeAddress,
165+
ids::{ActivityId, AgentId, WorkerId},
166+
};
167+
use mini_adas::config::{
168+
activity_dependencies, agent_assignments, socket_paths, worker_agent_map,
169+
};
170+
use std::collections::{HashMap, HashSet};
146171

147172
pub(super) use feo::agent::direct::primary::{Primary, PrimaryConfig};
148173

149174
pub(super) fn make_config(params: Params) -> PrimaryConfig {
150175
let agent_ids: HashSet<AgentId> = agent_assignments().keys().copied().collect();
151176
check_ids(&params.recorder_ids, &agent_ids);
152177

178+
let activity_worker_map: HashMap<ActivityId, WorkerId> = agent_assignments()
179+
.values()
180+
.flat_map(|vec| {
181+
vec.iter()
182+
.flat_map(move |(wid, aid_b)| aid_b.iter().map(|v| (v.0, *wid)))
183+
})
184+
.collect();
185+
153186
PrimaryConfig {
187+
id: AGENT_ID,
154188
cycle_time: params.feo_cycle_time,
155189
activity_dependencies: activity_dependencies(),
156190
recorder_ids: params.recorder_ids,
157191
worker_assignments: agent_assignments().remove(&AGENT_ID).unwrap(),
158192
timeout: Duration::from_secs(10),
159193
connection_timeout: Duration::from_secs(10),
160194
endpoint: NodeAddress::UnixSocket(socket_paths().0),
195+
activity_agent_map: activity_worker_map
196+
.iter()
197+
.map(|(activity_id, worker_id)| {
198+
let agent_id = worker_agent_map().get(worker_id).copied().unwrap();
199+
(*activity_id, agent_id)
200+
})
201+
.collect(),
161202
}
162203
}
163204
}

feo/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ rust_library(
7878
"//feo-log:libfeo_log_rust",
7979
"//feo-time:libfeo_time_rust",
8080
"//feo-tracing:libfeo_tracing_rust",
81+
"@score_crates//:ctrlc",
8182
"@score_crates//:libc",
8283
"@score_crates//:mio",
8384
],
@@ -149,6 +150,7 @@ rust_library(
149150
"//feo-log:libfeo_log_rust",
150151
"//feo-time:libfeo_time_rust",
151152
"//feo-tracing:libfeo_tracing_rust",
153+
"@score_crates//:ctrlc",
152154
"@score_crates//:libc",
153155
"@score_crates//:mio",
154156
"@score_crates//:postcard",

0 commit comments

Comments
 (0)