-
Notifications
You must be signed in to change notification settings - Fork 11
Deadline monitor implementation #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pawelrutkaq
merged 5 commits into
eclipse-score:main
from
qorix-group:pawelrutkaq_deadline_monitor
Jan 22, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c421b3b
Initial version
pawelrutkaq 3ffe3d2
DeadlineMonitor: Introduce impl for DeadlineMonitoring
pawelrutkaq f1c0de9
Apply review comments
pawelrutkaq feded75
Fix PhmDaemon init list order issue
pawelrutkaq 27461da
Add DeadlineState UT
pawelrutkaq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/module/health_monitor/architecture/assets/hm_duration_range.puml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| @startuml | ||
|
|
||
| +struct DurationRange | ||
| +struct TimeRange | ||
| { | ||
| min: Duration | ||
| max: Duration | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // ******************************************************************************* | ||
| // Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| // | ||
| // See the NOTICE file(s) distributed with this work for additional | ||
| // information regarding copyright ownership. | ||
| // | ||
| // This program and the accompanying materials are made available under the | ||
| // terms of the Apache License Version 2.0 which is available at | ||
| // <https://www.apache.org/licenses/LICENSE-2.0> | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // ******************************************************************************* | ||
|
|
||
| use crate::log::*; | ||
| use core::time::Duration; | ||
|
|
||
| /// Unique identifier for deadlines. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, ScoreDebug)] | ||
| pub struct IdentTag(&'static str); // Internal representation as a leaked string slice for now. It can be also an str to u64 conversion. Since this is internal only, we can change it later if needed. | ||
|
|
||
| impl From<String> for IdentTag { | ||
| fn from(value: String) -> Self { | ||
| Self(value.leak()) | ||
| } | ||
| } | ||
|
|
||
| impl From<&str> for IdentTag { | ||
| fn from(value: &str) -> Self { | ||
| Self(value.to_string().leak()) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
| pub struct TimeRange { | ||
| pub min: Duration, | ||
| pub max: Duration, | ||
| } | ||
|
|
||
| impl TimeRange { | ||
| pub fn new(min: Duration, max: Duration) -> Self { | ||
| assert!(min <= max, "TimeRange min must be less than or equal to max"); | ||
| Self { min, max } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // ******************************************************************************* | ||
| // Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| // | ||
| // See the NOTICE file(s) distributed with this work for additional | ||
| // information regarding copyright ownership. | ||
| // | ||
| // This program and the accompanying materials are made available under the | ||
| // terms of the Apache License Version 2.0 which is available at | ||
| // <https://www.apache.org/licenses/LICENSE-2.0> | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // ******************************************************************************* | ||
| use core::{ | ||
| ops::Deref, | ||
| sync::atomic::{AtomicBool, Ordering}, | ||
| }; | ||
|
|
||
| use crate::TimeRange; | ||
|
|
||
| /// Index type for identifying states associated with deadlines. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
| pub(super) struct StateIndex(usize); | ||
pawelrutkaq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| impl StateIndex { | ||
| pub fn new(index: usize) -> Self { | ||
| Self(index) | ||
| } | ||
| } | ||
|
|
||
| impl Deref for StateIndex { | ||
| type Target = usize; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| /// Template for a deadline, managing its range and usage state. | ||
| pub(super) struct DeadlineTemplate { | ||
| range: TimeRange, | ||
| is_in_use: AtomicBool, | ||
| pub assigned_state_index: StateIndex, | ||
| } | ||
|
|
||
| impl DeadlineTemplate { | ||
| pub(super) fn new(range: TimeRange, state_index: StateIndex) -> Self { | ||
| Self { | ||
| range, | ||
| is_in_use: AtomicBool::new(false), | ||
| assigned_state_index: state_index, | ||
| } | ||
| } | ||
|
|
||
| /// Attempts to acquire the deadline for use. | ||
| /// Returns Some(TimeRange) if successful, None if already in use. | ||
| pub(super) fn acquire_deadline(&self) -> Option<TimeRange> { | ||
| if self | ||
| .is_in_use | ||
| .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) | ||
| .is_ok() | ||
| { | ||
| Some(self.range) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| /// Releases the deadline, marking it as not in use. | ||
| pub(super) fn release_deadline(&self) { | ||
| self.is_in_use.store(false, Ordering::Relaxed); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use std::sync::Arc; | ||
|
|
||
| use crate::TimeRange; | ||
| use core::time::Duration; | ||
|
|
||
| #[test] | ||
| fn new_and_fields() { | ||
| let range = TimeRange::new(Duration::from_secs(1), Duration::from_secs(2)); | ||
| let idx = StateIndex::new(7); | ||
| let tmpl = DeadlineTemplate::new(range, idx); | ||
| assert_eq!(tmpl.range.min, Duration::from_secs(1)); | ||
| assert_eq!(tmpl.range.max, Duration::from_secs(2)); | ||
| assert_eq!(*tmpl.assigned_state_index, 7); | ||
| assert!(!tmpl.is_in_use.load(Ordering::Relaxed)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn acquire_and_release_deadline() { | ||
| let range = TimeRange::new(Duration::from_secs(3), Duration::from_secs(4)); | ||
| let idx = StateIndex::new(0); | ||
| let tmpl = Arc::new(DeadlineTemplate::new(range, idx)); | ||
|
|
||
| // First acquire should succeed | ||
| assert_eq!(tmpl.acquire_deadline(), Some(range)); | ||
| // Second acquire should fail | ||
| assert_eq!(tmpl.acquire_deadline(), None); | ||
|
|
||
| // Release and acquire again | ||
| tmpl.release_deadline(); | ||
| assert_eq!(tmpl.acquire_deadline(), Some(range)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn concurrent_acquire() { | ||
| use std::thread; | ||
| let range = TimeRange::new(Duration::from_secs(5), Duration::from_secs(6)); | ||
| let idx = StateIndex::new(1); | ||
| let tmpl = Arc::new(DeadlineTemplate::new(range, idx)); | ||
|
|
||
| let tmpl1 = tmpl.clone(); | ||
| let tmpl2 = tmpl.clone(); | ||
| let h1 = thread::spawn(move || tmpl1.acquire_deadline()); | ||
| let h2 = thread::spawn(move || tmpl2.acquire_deadline()); | ||
| let r1 = h1.join().unwrap(); | ||
| let r2 = h2.join().unwrap(); | ||
| // Only one thread should succeed | ||
| assert!(matches!((r1, r2), (Some(_), None) | (None, Some(_)))); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.