Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ signal-hook = "0.3.18"

monitor_rs = { path = "src/launch_manager_daemon/health_monitor_lib/rust_bindings" } # Temporary API
health_monitoring_lib = { path = "src/health_monitoring_lib" }
score_log = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.0.4" }
score_testing_macros = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.0.4" }
stdout_logger = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.0.4" }
containers = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.0.4" }
score_log = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }
score_testing_macros = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }
stdout_logger = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }
containers = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }
thread = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }

[workspace.lints.clippy]
std_instead_of_core = "warn"
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pip.parse(
)
use_repo(pip, "score_lifecycle_pip")

bazel_dep(name = "score_baselibs_rust", version = "0.1.0")
bazel_dep(name = "score_baselibs_rust", version = "0.1.1")
bazel_dep(name = "score_baselibs", version = "0.2.4")
bazel_dep(name = "score_logging", version = "0.1.0")

Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/health_monitoring_lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load("@score_baselibs//:bazel/unit_tests.bzl", "cc_gtest_unit_test")

COMMON_DEPS = [
"@score_baselibs_rust//src/containers:containers",
"@score_baselibs_rust//src/thread:thread",
"@score_baselibs_rust//src/log/score_log:score_log",
"//src/launch_manager_daemon/health_monitor_lib/rust_bindings:monitor_rs",
]
Expand All @@ -31,11 +32,13 @@ CC_SOURCES = [
"cpp/heartbeat_monitor.cpp",
"cpp/logic_monitor.cpp",
"cpp/health_monitor.cpp",
"cpp/thread.cpp",
]

CC_HDRS = [
"cpp/include/score/hm/common.h",
"cpp/include/score/hm/tag.h",
"cpp/include/score/hm/thread.h",
"cpp/include/score/hm/deadline/deadline_monitor.h",
"cpp/include/score/hm/heartbeat/heartbeat_monitor.h",
"cpp/include/score/hm/logic/logic_monitor.h",
Expand Down Expand Up @@ -158,6 +161,7 @@ cc_gtest_unit_test(
name = "cpp_tests",
srcs = [
"cpp/tests/health_monitor_test.cpp",
"cpp/tests/integrated_test.cpp",
"cpp/tests/log_init.cpp",
],
linkopts = select({
Expand Down
1 change: 1 addition & 0 deletions src/health_monitoring_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "rust/lib.rs"
workspace = true

[dependencies]
thread.workspace = true
score_log.workspace = true
score_testing_macros.workspace = true
containers.workspace = true
Expand Down
17 changes: 17 additions & 0 deletions src/health_monitoring_lib/cpp/health_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ FFICode health_monitor_builder_destroy(FFIHandle health_monitor_builder_handle);
FFICode health_monitor_builder_build(FFIHandle health_monitor_builder_handle,
const uint64_t* supervisor_cycle_ms,
const uint64_t* internal_cycle_ms,
FFIHandle thread_parameters_handle,
FFIHandle* health_monitor_handle_out);
FFICode health_monitor_builder_add_deadline_monitor(FFIHandle health_monitor_builder_handle,
const MonitorTag* monitor_tag,
Expand Down Expand Up @@ -129,6 +130,12 @@ HealthMonitorBuilder HealthMonitorBuilder::with_supervisor_api_cycle(std::chrono
return std::move(*this);
}

HealthMonitorBuilder HealthMonitorBuilder::thread_parameters(score::hm::ThreadParameters&& thread_parameters) &&
{
thread_parameters_ = std::move(thread_parameters);
return std::move(*this);
}

score::cpp::expected<HealthMonitor, Error> HealthMonitorBuilder::build() &&
{
auto health_monitor_builder_handle = health_monitor_builder_handle_.drop_by_rust();
Expand All @@ -146,10 +153,20 @@ score::cpp::expected<HealthMonitor, Error> HealthMonitorBuilder::build() &&
internal_processing_cycle_ms = &internal_processing_cycle_ms_.value();
}

// Handle thread parameters.
FFIHandle thread_parameters_handle{nullptr};
if (thread_parameters_.has_value())
{
auto rust_handle{thread_parameters_.value().drop_by_rust()};
SCORE_LANGUAGE_FUTURECPP_ASSERT(rust_handle.has_value());
thread_parameters_handle = rust_handle.value();
}

FFIHandle health_monitor_handle{nullptr};
auto result{health_monitor_builder_build(health_monitor_builder_handle.value(),
supervisor_api_cycle_ms,
internal_processing_cycle_ms,
thread_parameters_handle,
&health_monitor_handle)};
if (result != kSuccess)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <score/hm/heartbeat/heartbeat_monitor.h>
#include <score/hm/logic/logic_monitor.h>
#include <score/hm/tag.h>
#include <score/hm/thread.h>

namespace score::hm
{
Expand Down Expand Up @@ -59,6 +60,9 @@ class HealthMonitorBuilder final
/// This duration determines how often the health monitor checks deadlines.
HealthMonitorBuilder with_internal_processing_cycle(std::chrono::milliseconds cycle_duration) &&;

/// Sets the monitoring thread parameters.
HealthMonitorBuilder thread_parameters(score::hm::ThreadParameters&& thread_parameters) &&;

/// Build a new `HealthMonitor` instance based on provided parameters.
score::cpp::expected<HealthMonitor, Error> build() &&;

Expand All @@ -67,6 +71,7 @@ class HealthMonitorBuilder final

std::optional<uint64_t> supervisor_api_cycle_ms_;
std::optional<uint64_t> internal_processing_cycle_ms_;
std::optional<ThreadParameters> thread_parameters_;
};

class HealthMonitor final
Expand Down
91 changes: 91 additions & 0 deletions src/health_monitoring_lib/cpp/include/score/hm/thread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/********************************************************************************
* 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
********************************************************************************/
#ifndef SCORE_HM_THREAD_H
#define SCORE_HM_THREAD_H

#include "common.h"
#include <cstdint>
#include <vector>

namespace score::hm
{

class HealthMonitorBuilder;

/// Scheduler policy.
enum class SchedulerPolicy : int32_t
{
Other,
Fifo,
RoundRobin,
};

/// Get min thread priority for given policy.
int32_t scheduler_policy_priority_min(SchedulerPolicy scheduler_policy);

/// Get max thread priority for given policy.
int32_t scheduler_policy_priority_max(SchedulerPolicy scheduler_policy);

class SchedulerParameters final
{
public:
/// Create a new `SchedulerParameters`.
/// Priority must be in allowed range for the scheduler policy.
SchedulerParameters(SchedulerPolicy policy, int32_t priority);

/// Scheduler policy.
SchedulerPolicy policy() const;

/// Thread priority.
int32_t priority() const;

private:
SchedulerPolicy policy_;
int32_t priority_;
};

/// Thread parameters.
class ThreadParameters final : public internal::RustDroppable<ThreadParameters>
{
public:
/// Create a new `ThreadParameters` containing default values.
ThreadParameters();

/// Scheduler parameters, including scheduler policy and thread priority.
ThreadParameters scheduler_parameters(SchedulerParameters scheduler_parameters) &&;

/// Set thread affinity - array of CPU core IDs that the thread can run on.
ThreadParameters affinity(const std::vector<size_t>& affinity) &&;

/// Set stack size.
ThreadParameters stack_size(size_t stack_size) &&;

protected:
std::optional<internal::FFIHandle> _drop_by_rust_impl()
{
return thread_parameters_handle_.drop_by_rust();
}

private:
internal::DroppableFFIHandle thread_parameters_handle_;

// Allow to hide `drop_by_rust` implementation.
friend class internal::RustDroppable<ThreadParameters>;

// Allow `HealthMonitorBuilder` to access `drop_by_rust` implementation.
friend class score::hm::HealthMonitorBuilder;
};

} // namespace score::hm

#endif // SCORE_HM_THREAD_H
Loading
Loading