提交 b411d08f authored 作者: Serhij S's avatar Serhij S

certain pre-release fixes

上级 41da870a
...@@ -36,8 +36,8 @@ sysinfo = "0.29" ...@@ -36,8 +36,8 @@ sysinfo = "0.29"
thiserror = "1.0.57" thiserror = "1.0.57"
tracing = "0.1.40" tracing = "0.1.40"
signal-hook = "0.3.17" signal-hook = "0.3.17"
eva-common = { version = "0.3.85", features = ["events", "payload", "common-payloads", "acl"], optional = true } eva-common = { version = "^0.3.85", features = ["events", "payload", "common-payloads", "acl"], optional = true }
eva-sdk = { version = "0.3.61", features = ["controller"], optional = true } eva-sdk = { version = "^0.3.62", features = ["controller"], optional = true }
busrt = { version = "0.4.9", features = ["rpc", "ipc"], optional = true } busrt = { version = "0.4.9", features = ["rpc", "ipc"], optional = true }
tokio = { version = "1.36.0", optional = true } tokio = { version = "1.36.0", optional = true }
hostname = { version = "0.3.1", optional = true } hostname = { version = "0.3.1", optional = true }
...@@ -49,7 +49,7 @@ metrics = { version = "0.24", optional = true } ...@@ -49,7 +49,7 @@ metrics = { version = "0.24", optional = true }
snmp2 = { version = "0.3", optional = true } snmp2 = { version = "0.3", optional = true }
rtsc = "^0.3.12" rtsc = "^0.3.12"
rvideo = { version = "0.5", optional = true, default-features = false } rvideo = { version = "0.5", optional = true, default-features = false }
rflow = { version = "0.1", optional = true, default-features = false } rflow = { version = "^0.1.1", optional = true, default-features = false }
once_cell = { version = "1.19.0", optional = true } once_cell = { version = "1.19.0", optional = true }
parking_lot = { version = "0.12.3", optional = true } parking_lot = { version = "0.12.3", optional = true }
parking_lot_rt = { version = "0.12.1", optional = true } parking_lot_rt = { version = "0.12.1", optional = true }
......
...@@ -187,9 +187,8 @@ impl Communicator for Serial { ...@@ -187,9 +187,8 @@ impl Communicator for Serial {
.as_mut() .as_mut()
.unwrap() .unwrap()
.write_all(buf) .write_all(buf)
.map_err(|e| { .inspect_err(|_| {
self.reconnect(); self.reconnect();
e
}); });
if result.is_ok() { if result.is_ok() {
port.last_frame.replace(Instant::now()); port.last_frame.replace(Instant::now());
...@@ -204,9 +203,8 @@ impl Communicator for Serial { ...@@ -204,9 +203,8 @@ impl Communicator for Serial {
.as_mut() .as_mut()
.unwrap() .unwrap()
.read_exact(buf) .read_exact(buf)
.map_err(|e| { .inspect_err(|_| {
self.reconnect(); self.reconnect();
e
}) })
.map_err(Into::into) .map_err(Into::into)
} }
......
...@@ -376,6 +376,7 @@ mod test { ...@@ -376,6 +376,7 @@ mod test {
use super::Hub; use super::Hub;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[allow(dead_code)]
enum Message { enum Message {
Temperature(f64), Temperature(f64),
Humidity(f64), Humidity(f64),
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
use core::{fmt, num}; use core::{fmt, num};
use std::io::Write; use std::io::Write;
use std::panic::PanicInfo; use std::panic::PanicInfo;
use std::sync::atomic; use std::sync::atomic::{self, AtomicBool, Ordering};
use std::{env, sync::Arc, time::Duration}; use std::{env, sync::Arc, time::Duration};
use colored::Colorize as _; use colored::Colorize as _;
...@@ -104,9 +104,10 @@ pub mod hub_async; ...@@ -104,9 +104,10 @@ pub mod hub_async;
pub mod io; pub mod io;
/// Task supervisor to manage real-time threads /// Task supervisor to manage real-time threads
pub mod supervisor; pub mod supervisor;
/// Linux systme tools
pub mod system;
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone, Linux only /// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone, Linux only
pub mod thread_rt; pub mod thread_rt;
pub use rtsc::system;
/// State helper functions /// State helper functions
#[cfg(any(feature = "json", feature = "msgpack"))] #[cfg(any(feature = "json", feature = "msgpack"))]
...@@ -115,6 +116,18 @@ pub mod state; ...@@ -115,6 +116,18 @@ pub mod state;
/// The crate result type /// The crate result type
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
static REALTIME_MODE: AtomicBool = AtomicBool::new(true);
/// The function can be used in test environments to disable real-time functions but keep all
/// methods running with no errors
pub fn set_simulated() {
REALTIME_MODE.store(false, Ordering::Relaxed);
}
fn is_realtime() -> bool {
REALTIME_MODE.load(Ordering::Relaxed)
}
/// The crate error type /// The crate error type
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum Error { pub enum Error {
......
use crate::{is_realtime, Result};
use core::fmt;
/// Configure system parameters (global) while the process is running. Does nothing in simulated
/// mode. A wrapper around [`rtsc::system::linux::SystemConfig`] which respects simulated/real-time
/// mode.
///
/// Example:
///
/// ```rust,no_run
/// use roboplc::thread_rt::SystemConfig;
///
/// let _sys = SystemConfig::new().set("kernel/sched_rt_runtime_us", -1)
/// .apply()
/// .expect("Unable to set system config");
/// // some code
/// // system config is restored at the end of the scope
/// ```
#[allow(clippy::module_name_repetitions)]
#[derive(Default)]
pub struct SystemConfig(rtsc::system::linux::SystemConfig);
impl SystemConfig {
/// Creates a new system config object
#[must_use]
pub fn new() -> Self {
Self::default()
}
/// Set a parameter to configure
pub fn set<V: fmt::Display>(mut self, key: &'static str, value: V) -> Self {
if is_realtime() {
self.0 = self.0.set(key, value);
}
self
}
/// Apply values to /proc/sys keys
pub fn apply(self) -> Result<rtsc::system::linux::SystemConfigGuard> {
if is_realtime() {
return self.0.apply().map_err(Into::into);
}
Ok(rtsc::system::linux::SystemConfigGuard::default())
}
}
/// Configure CPU governors for the given CPUs. A wrapper around
/// [`rtsc::system::linux::CpuGovernor`] which respects simulated/real-time mode.
pub struct CpuGovernor(#[allow(dead_code)] rtsc::system::linux::CpuGovernor);
impl CpuGovernor {
/// Set performance governor for the given CPUs. This sets the maximum frequency for the CPUs,
/// increasing the power consumption but lowering their latency. It is enough to specify a
/// single logical core number per physical core. The governor is restored when the returned
/// guard object is dropped.
pub fn performance<I>(performance_cpus: I) -> Result<CpuGovernor>
where
I: IntoIterator<Item = usize>,
{
if is_realtime() {
let inner = rtsc::system::linux::CpuGovernor::performance(performance_cpus)?;
Ok(Self(inner))
} else {
Ok(Self(rtsc::system::linux::CpuGovernor::default()))
}
}
}
use crate::{time::Interval, Error, Result}; use crate::{is_realtime, time::Interval, Error, Result};
use bma_ts::{Monotonic, Timestamp}; use bma_ts::{Monotonic, Timestamp};
use colored::Colorize; use colored::Colorize;
use core::fmt; use core::fmt;
...@@ -7,7 +7,6 @@ use nix::{sys::signal, unistd}; ...@@ -7,7 +7,6 @@ use nix::{sys::signal, unistd};
use serde::{Deserialize, Serialize, Serializer}; use serde::{Deserialize, Serialize, Serializer};
use std::{ use std::{
collections::BTreeSet, collections::BTreeSet,
sync::atomic::{AtomicBool, Ordering},
thread::{self, JoinHandle, Scope, ScopedJoinHandle}, thread::{self, JoinHandle, Scope, ScopedJoinHandle},
time::Duration, time::Duration,
}; };
...@@ -15,18 +14,6 @@ use std::{ ...@@ -15,18 +14,6 @@ use std::{
use sysinfo::PidExt; use sysinfo::PidExt;
use sysinfo::{Pid, ProcessExt, System, SystemExt}; use sysinfo::{Pid, ProcessExt, System, SystemExt};
static REALTIME_MODE: AtomicBool = AtomicBool::new(true);
/// The function can be used in test environments to disable real-time functions but keep all
/// methods running with no errors
pub fn set_simulated() {
REALTIME_MODE.store(false, Ordering::Relaxed);
}
fn is_realtime() -> bool {
REALTIME_MODE.load(Ordering::Relaxed)
}
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
macro_rules! panic_os { macro_rules! panic_os {
() => { () => {
...@@ -99,34 +86,6 @@ impl From<Scheduling> for rtsc::thread_rt::Scheduling { ...@@ -99,34 +86,6 @@ impl From<Scheduling> for rtsc::thread_rt::Scheduling {
} }
} }
//#[cfg(target_os = "linux")]
//impl From<Scheduling> for libc::c_int {
//fn from(value: Scheduling) -> Self {
//match value {
//Scheduling::RoundRobin => libc::SCHED_RR,
//Scheduling::FIFO => libc::SCHED_FIFO,
//Scheduling::Idle => libc::SCHED_IDLE,
//Scheduling::Batch => libc::SCHED_BATCH,
//Scheduling::DeadLine => libc::SCHED_DEADLINE,
//Scheduling::Other => libc::SCHED_NORMAL,
//}
//}
//}
//#[cfg(target_os = "linux")]
//impl From<libc::c_int> for Scheduling {
//fn from(value: libc::c_int) -> Self {
//match value {
//libc::SCHED_RR => Scheduling::RoundRobin,
//libc::SCHED_FIFO => Scheduling::FIFO,
//libc::SCHED_IDLE => Scheduling::Idle,
//libc::SCHED_BATCH => Scheduling::Batch,
//libc::SCHED_DEADLINE => Scheduling::DeadLine,
//_ => Scheduling::Other,
//}
//}
//}
macro_rules! impl_builder_from { macro_rules! impl_builder_from {
($t: ty) => { ($t: ty) => {
impl From<$t> for Builder { impl From<$t> for Builder {
...@@ -650,65 +609,3 @@ fn get_child_pids_recursive(pid: Pid, sys: &System, to: &mut BTreeSet<Pid>) { ...@@ -650,65 +609,3 @@ fn get_child_pids_recursive(pid: Pid, sys: &System, to: &mut BTreeSet<Pid>) {
}; };
} }
} }
/// Configure system parameters (global) while the process is running. Does nothing in simulated
/// mode. A wrapper around [`rtsc::system::linux::SystemConfig`] which respects simulated/real-time
/// mode.
///
/// Example:
///
/// ```rust,no_run
/// use roboplc::thread_rt::SystemConfig;
///
/// let _sys = SystemConfig::new().set("kernel/sched_rt_runtime_us", -1)
/// .apply()
/// .expect("Unable to set system config");
/// // some code
/// // system config is restored at the end of the scope
/// ```
#[derive(Default)]
pub struct SystemConfig(rtsc::system::linux::SystemConfig);
impl SystemConfig {
/// Creates a new system config object
#[must_use]
pub fn new() -> Self {
Self::default()
}
/// Set a parameter to configure
pub fn set<V: fmt::Display>(mut self, key: &'static str, value: V) -> Self {
if is_realtime() {
self.0 = self.0.set(key, value);
}
self
}
/// Apply values to /proc/sys keys
pub fn apply(self) -> Result<rtsc::system::linux::SystemConfigGuard> {
if is_realtime() {
return self.0.apply().map_err(Into::into);
}
Ok(rtsc::system::linux::SystemConfigGuard::default())
}
}
/// Configure CPU governors for the given CPUs. A wrapper around
/// [`rtsc::system::linux::CpuGovernor`] which respects simulated/real-time mode.
pub struct CpuGovernor(#[allow(dead_code)] rtsc::system::linux::CpuGovernor);
impl CpuGovernor {
/// Set performance governor for the given CPUs. This sets the maximum frequency for the CPUs,
/// increasing the power consumption but lowering their latency. It is enough to specify a
/// single logical core number per physical core. The governor is restored when the returned
/// guard object is dropped.
pub fn performance<I>(performance_cpus: I) -> Result<CpuGovernor>
where
I: IntoIterator<Item = usize>,
{
if is_realtime() {
let inner = rtsc::system::linux::CpuGovernor::performance(performance_cpus)?;
Ok(Self(inner))
} else {
Ok(Self(rtsc::system::linux::CpuGovernor::default()))
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论