Skip to content

Commit 4ef0522

Browse files
author
neos-builder
committed
Consolidate scheduler config: single SchedulerConfig path
Remove duplicate builder methods (realtime(), with_blackbox(), with_safety_monitor(), enable_recording()) that duplicated what SchedulerConfig already provides. Add SchedulerConfig::deploy() preset. Restrict internal types to pub(crate). Update all tests and examples to use config-based API.
1 parent 7fbcae8 commit 4ef0522

14 files changed

Lines changed: 148 additions & 305 deletions

File tree

horus/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,21 @@ pub mod prelude {
8181
// ============================================
8282
pub use horus_core::scheduling::{
8383
// BlackBox flight recorder
84-
create_shared_blackbox,
8584
BlackBox,
8685
BlackBoxEvent,
8786
// Circuit breaker
8887
CircuitBreaker,
8988
CircuitState,
9089
// Safety monitoring
91-
SafetyMonitor,
9290
SafetyState,
9391
SafetyStats,
94-
SharedBlackBox,
95-
WCETEnforcer,
96-
Watchdog,
92+
WCETViolation,
9793
};
9894

9995
// ============================================
10096
// Telemetry
10197
// ============================================
102-
pub use horus_core::scheduling::{TelemetryEndpoint, TelemetryManager};
98+
pub use horus_core::scheduling::TelemetryEndpoint;
10399

104100
// ============================================
105101
// Node Tier
@@ -110,7 +106,7 @@ pub mod prelude {
110106
// Record/Replay
111107
// ============================================
112108
pub use horus_core::scheduling::{
113-
NodeRecorder, NodeRecording, NodeReplayer, NodeTickSnapshot, RecordingConfig,
109+
NodeRecorder, NodeRecording, NodeReplayer, NodeTickSnapshot,
114110
RecordingManager, SchedulerRecording,
115111
};
116112

@@ -148,7 +144,6 @@ pub mod prelude {
148144
RtPriority,
149145
RtScheduler,
150146
RtStats,
151-
WCETViolation,
152147
};
153148

154149
// ============================================
@@ -193,7 +188,7 @@ pub mod prelude {
193188
// ============================================
194189
// Error Types
195190
// ============================================
196-
pub use horus_core::error::{HorusError, HorusResult};
191+
pub use horus_core::error::{HorusError, HorusResult, Result};
197192

198193
// ============================================
199194
// Common Std Types

horus_core/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ let mut scheduler = Scheduler::safety_critical(); // Safety systems
5353
let mut scheduler = Scheduler::high_performance();// Parallel + 10kHz
5454
let mut scheduler = Scheduler::deterministic(); // Reproducible
5555

56-
// Builder for custom configuration
56+
// Custom configuration via SchedulerConfig
57+
let mut config = SchedulerConfig::standard();
58+
config.realtime.rt_scheduling_class = true;
59+
config.monitoring.black_box_enabled = true;
5760
let mut scheduler = Scheduler::new()
58-
.realtime()
61+
.with_config(config)
5962
.tick_hz(1000.0)
60-
.with_blackbox(16)
6163
.with_name("my_robot");
6264

6365
// Add nodes with execution order

horus_core/examples/scheduler_api_patterns.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///
33
/// The API uses progressive disclosure:
44
/// - `Scheduler::new()` — lightweight, no syscalls
5-
/// - Builder methods opt in to features: `.realtime()`, `.with_blackbox()`, `.tick_hz()`
5+
/// - `SchedulerConfig` fields opt in to features: RT, BlackBox, safety monitor
66
/// - Presets bundle common configurations: `deploy()`, `safety_critical()`, `deterministic()`
77
use horus_core::scheduling::{config::SchedulerConfig, Scheduler};
88

@@ -39,33 +39,38 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3939
println!();
4040

4141
// ========================================================================
42-
// Pattern 3: Builder — compose exactly what you need
42+
// Pattern 3: Config — compose exactly what you need
4343
// ========================================================================
44-
println!("Pattern 3: Builder Composition");
45-
println!("------------------------------");
44+
println!("Pattern 3: Config Composition");
45+
println!("-----------------------------");
4646

47+
let mut config = SchedulerConfig::standard();
48+
config.realtime.rt_scheduling_class = true;
49+
config.monitoring.black_box_enabled = true;
50+
config.monitoring.black_box_size_mb = 8;
4751
let _scheduler = Scheduler::new()
48-
.realtime() // RT priority + memory lock + CPU pin
49-
.with_blackbox(8) // 8MB flight recorder
52+
.with_config(config)
5053
.tick_hz(1000.0) // 1kHz control loop
5154
.with_name("CustomRobot");
5255

53-
println!("[OK] Custom builder composition");
56+
println!("[OK] Custom config composition");
5457
println!(" RT: enabled, BlackBox: 8MB, Rate: 1kHz\n");
5558

5659
// ========================================================================
57-
// Pattern 4: Config Preset (advanced)
60+
// Pattern 4: Config Preset + extras
5861
// ========================================================================
59-
println!("Pattern 4: Config Preset");
60-
println!("------------------------");
62+
println!("Pattern 4: Config Preset + Extras");
63+
println!("---------------------------------");
6164

65+
let mut config = SchedulerConfig::hard_realtime();
66+
config.realtime.safety_monitor = true;
67+
config.realtime.max_deadline_misses = 3;
6268
let _scheduler = Scheduler::new()
63-
.with_config(SchedulerConfig::hard_realtime())
69+
.with_config(config)
6470
.with_capacity(128)
65-
.with_safety_monitor(3)
6671
.with_name("HardRT");
6772

68-
println!("[OK] hard_realtime config preset");
73+
println!("[OK] hard_realtime config preset + safety monitor");
6974
println!(" WCET enforcement, 10ms watchdog, panic on deadline miss\n");
7075

7176
// ========================================================================
@@ -123,10 +128,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
123128
println!(" Scheduler::hard_realtime() Strict deadlines");
124129
println!(" Scheduler::deterministic() Reproducible execution");
125130
println!();
126-
println!(" .realtime() Opt-in RT priority + memory lock + CPU pin");
127-
println!(" .with_blackbox(N) Opt-in N MB flight recorder");
128-
println!(" .tick_hz(Hz) Set global tick rate");
129131
println!(" .with_config(C) Apply a SchedulerConfig preset");
132+
println!(" .tick_hz(Hz) Set global tick rate");
133+
println!(" .with_name(S) Name the scheduler instance");
134+
println!(" .with_capacity(N) Pre-allocate node slots");
130135

131136
Ok(())
132137
}

horus_core/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ macro_rules! horus_internal {
128128
/// Convenience type alias for Results using HorusError
129129
pub type HorusResult<T> = std::result::Result<T, HorusError>;
130130

131+
/// Short alias — `Result<T>` is equivalent to `HorusResult<T>`
132+
pub type Result<T> = HorusResult<T>;
133+
131134

132135
// ============================================
133136
// From implementations for common error types

horus_core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub use core::{
6969
RtConfigBuilder, RtCpuInfo, RtDegradation, RtKernelInfo, RtScheduler, TopicMetadata,
7070
DISCOVERY_TOPIC,
7171
};
72-
pub use error::{HorusError, HorusResult};
72+
pub use error::{HorusError, HorusResult, Result};
7373
pub use params::RuntimeParams;
7474
pub use scheduling::Scheduler;
7575

horus_core/src/scheduling/config.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,47 @@ impl SchedulerConfig {
271271
}
272272
}
273273

274+
/// Deploy configuration for production robots.
275+
///
276+
/// Standard rate (60 Hz) with RT features (best-effort) and a 16MB BlackBox flight recorder.
277+
pub fn deploy() -> Self {
278+
Self {
279+
execution: ExecutionMode::Sequential,
280+
timing: TimingConfig {
281+
global_rate_hz: 60.0,
282+
per_node_rates: true,
283+
},
284+
fault: FaultConfig {
285+
circuit_breaker_enabled: true,
286+
max_failures: 5,
287+
recovery_threshold: 3,
288+
circuit_timeout_ms: 5000,
289+
},
290+
realtime: RealTimeConfig {
291+
wcet_enforcement: false,
292+
deadline_monitoring: true,
293+
watchdog_enabled: true,
294+
watchdog_timeout_ms: 1000,
295+
safety_monitor: false,
296+
max_deadline_misses: 100,
297+
memory_locking: true,
298+
rt_scheduling_class: true,
299+
},
300+
resources: ResourceConfig {
301+
cpu_cores: None,
302+
numa_aware: false,
303+
},
304+
monitoring: MonitoringConfig {
305+
profiling_enabled: true,
306+
metrics_interval_ms: 1000,
307+
black_box_enabled: true,
308+
black_box_size_mb: 16,
309+
telemetry_endpoint: None,
310+
},
311+
recording: None,
312+
}
313+
}
314+
274315
/// Deterministic configuration for safety certification and replay
275316
pub fn deterministic() -> Self {
276317
Self {

horus_core/src/scheduling/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub use config::{
6262
ExecutionMode, FaultConfig, MonitoringConfig, RealTimeConfig, RecordingConfigYaml,
6363
ResourceConfig, SchedulerConfig, TimingConfig,
6464
};
65-
pub use safety_monitor::{SafetyMonitor, SafetyState, SafetyStats, WCETEnforcer, Watchdog};
65+
pub use safety_monitor::{SafetyState, SafetyStats, WCETViolation};
6666
pub use scheduler::{DegradationSeverity, RtDegradation, RtFeature, Scheduler};
6767
pub use types::SchedulerNodeMetrics;
6868

@@ -73,7 +73,7 @@ pub use rt::{
7373
};
7474

7575
// Re-export blackbox flight recorder
76-
pub use blackbox::{create_shared_blackbox, BlackBox, BlackBoxEvent, SharedBlackBox};
76+
pub use blackbox::{BlackBox, BlackBoxEvent};
7777

7878
// Re-export record/replay (public API)
7979
pub use record_replay::{
@@ -87,7 +87,6 @@ pub use record_replay::{
8787
NodeRecording,
8888
NodeReplayer,
8989
NodeTickSnapshot,
90-
RecordingConfig,
9190
RecordingDiff,
9291
RecordingManager,
9392
ReplayDebugger,
@@ -100,8 +99,8 @@ pub use record_replay::{
10099
// Re-export node tier from types
101100
pub use types::NodeTier;
102101

103-
// Re-export telemetry
104-
pub use telemetry::{TelemetryEndpoint, TelemetryManager};
102+
// Re-export telemetry (only user-facing endpoint type)
103+
pub use telemetry::TelemetryEndpoint;
105104

106105
// Re-export fault tolerance (public API)
107106
pub use fault_tolerance::{

horus_core/src/scheduling/record_replay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl RecordingConfig {
117117
/// Convert YAML-based recording config to runtime recording config.
118118
///
119119
/// This bridges the declarative `SchedulerConfig` preset system with the
120-
/// runtime `RecordingConfig` used by `NodeRecorder` and `Scheduler::enable_recording_with_config()`.
120+
/// runtime `RecordingConfig` used by `NodeRecorder` and `Scheduler::apply_config()`.
121121
impl From<super::config::RecordingConfigYaml> for RecordingConfig {
122122
fn from(yaml: super::config::RecordingConfigYaml) -> Self {
123123
let base_dir = yaml

0 commit comments

Comments
 (0)