#![deny(missing_docs)]
#![deny(unsafe_code)]
#![warn(clippy::all)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#[cfg(feature = "mimalloc")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
mod config;
mod daemon;
mod error;
mod pool;
pub mod coord;
pub mod lock;
pub mod resources;
pub mod shutdown;
pub mod signal;
pub mod subsystem;
pub use config::{Config, LogLevel};
pub use daemon::{Daemon, DaemonBuilder};
pub use error::{Error, Result};
pub use pool::*;
pub use shutdown::{ShutdownHandle, ShutdownReason};
pub use subsystem::{RestartPolicy, Subsystem, SubsystemId};
#[cfg(feature = "metrics")]
pub mod metrics;
#[cfg(feature = "profiling")]
pub mod profiling;
#[cfg(feature = "ipc")]
pub mod ipc;
#[cfg(feature = "high-res-timing")]
pub mod timing {
use quanta::Clock;
pub use quanta::Instant;
static CLOCK: std::sync::LazyLock<Clock> = std::sync::LazyLock::new(Clock::new);
#[inline]
pub fn now() -> Instant {
CLOCK.now()
}
}
#[cfg(feature = "scheduler-hints")]
pub mod scheduler {
use tracing::debug;
#[cfg(all(feature = "scheduler-hints-unix", unix))]
use tracing::info;
pub fn apply_process_hints(config: &crate::config::Config) {
let name = &config.name;
#[cfg(all(feature = "scheduler-hints-unix", unix))]
{
use std::process::Command;
let delta = "-5";
let pid = std::process::id().to_string();
let out = Command::new("renice")
.args(["-n", delta, "-p", pid.as_str()])
.output();
match out {
Ok(res) if res.status.success() => {
info!(%name, delta, "scheduler-hints: renice applied");
return;
}
Ok(res) => {
let code = res.status.code();
let stderr = String::from_utf8_lossy(&res.stderr);
debug!(%name, delta, code, stderr = %stderr, "scheduler-hints: renice failed (best-effort)");
}
Err(e) => {
debug!(%name, delta, error = %e, "scheduler-hints: renice invocation failed (best-effort)");
}
}
}
debug!(%name, "scheduler-hints: apply_process_hints (noop)");
}
pub fn apply_runtime_hints() {
#[cfg(all(feature = "scheduler-hints-unix", target_os = "linux"))]
{
use nix::sched::{sched_setaffinity, CpuSet};
use nix::unistd::Pid;
let mut set = CpuSet::new();
let cpus = num_cpus::get();
for cpu in 0..cpus {
let _ = set.set(cpu);
}
match sched_setaffinity(Pid::from_raw(0), &set) {
Ok(()) => debug!(
cpus,
"scheduler-hints: setaffinity applied to current process threads (best-effort)"
),
Err(e) => debug!(error = %e, "scheduler-hints: setaffinity failed (best-effort)"),
}
}
#[cfg(not(all(feature = "scheduler-hints-unix", target_os = "linux")))]
{
debug!("scheduler-hints: apply_runtime_hints (noop)");
}
}
}
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const DEFAULT_SHUTDOWN_TIMEOUT_MS: u64 = 5000;
pub const DEFAULT_CONFIG_FILE: &str = "daemon.toml";