提交 0ae2c49e authored 作者: Serhij S's avatar Serhij S

quietly apply params if thread is going to be parked

上级 1a67259d
...@@ -167,7 +167,7 @@ impl Builder { ...@@ -167,7 +167,7 @@ impl Builder {
thread_init_internal(tx, park_on_errors); thread_init_internal(tx, park_on_errors);
f() f()
})?; })?;
let tid = thread_init_external(rx, &rt_params)?; let tid = thread_init_external(rx, &rt_params, park_on_errors)?;
Ok(Task { Ok(Task {
name, name,
handle, handle,
...@@ -218,7 +218,7 @@ impl Builder { ...@@ -218,7 +218,7 @@ impl Builder {
thread_init_internal(tx, park_on_errors); thread_init_internal(tx, park_on_errors);
f() f()
})?; })?;
let tid = thread_init_external(rx, &rt_params)?; let tid = thread_init_external(rx, &rt_params, park_on_errors)?;
Ok(ScopedTask { Ok(ScopedTask {
name, name,
handle, handle,
...@@ -290,8 +290,8 @@ impl<T> Task<T> { ...@@ -290,8 +290,8 @@ impl<T> Task<T> {
} }
/// Applies new real-time params /// Applies new real-time params
pub fn apply_rt_params(&mut self, rt_params: RTParams) -> Result<()> { pub fn apply_rt_params(&mut self, rt_params: RTParams) -> Result<()> {
if let Err(e) = apply_thread_params(self.tid, &rt_params) { if let Err(e) = apply_thread_params(self.tid, &rt_params, false) {
let _ = apply_thread_params(self.tid, &self.rt_params); let _ = apply_thread_params(self.tid, &self.rt_params, false);
return Err(e); return Err(e);
} }
self.rt_params = rt_params; self.rt_params = rt_params;
...@@ -351,8 +351,8 @@ impl<'scope, T> ScopedTask<'scope, T> { ...@@ -351,8 +351,8 @@ impl<'scope, T> ScopedTask<'scope, T> {
} }
/// Applies new real-time params /// Applies new real-time params
pub fn apply_rt_params(&mut self, rt_params: RTParams) -> Result<()> { pub fn apply_rt_params(&mut self, rt_params: RTParams) -> Result<()> {
if let Err(e) = apply_thread_params(self.tid, &rt_params) { if let Err(e) = apply_thread_params(self.tid, &rt_params, false) {
let _ = apply_thread_params(self.tid, &self.rt_params); let _ = apply_thread_params(self.tid, &self.rt_params, false);
return Err(e); return Err(e);
} }
self.rt_params = rt_params; self.rt_params = rt_params;
...@@ -454,13 +454,14 @@ fn thread_init_internal( ...@@ -454,13 +454,14 @@ fn thread_init_internal(
fn thread_init_external( fn thread_init_external(
rx_tid: oneshot::Receiver<(libc::c_int, oneshot::Sender<bool>)>, rx_tid: oneshot::Receiver<(libc::c_int, oneshot::Sender<bool>)>,
params: &RTParams, params: &RTParams,
quiet: bool,
) -> Result<libc::c_int> { ) -> Result<libc::c_int> {
let (tid, tx_ok) = rx_tid.recv()?; let (tid, tx_ok) = rx_tid.recv()?;
if tid < 0 { if tid < 0 {
tx_ok.send(false).map_err(|e| Error::IO(e.to_string()))?; tx_ok.send(false).map_err(|e| Error::IO(e.to_string()))?;
return Err(Error::RTGetTId(tid)); return Err(Error::RTGetTId(tid));
} }
if let Err(e) = apply_thread_params(tid, params) { if let Err(e) = apply_thread_params(tid, params, quiet) {
tx_ok.send(false).map_err(|e| Error::IO(e.to_string()))?; tx_ok.send(false).map_err(|e| Error::IO(e.to_string()))?;
return Err(e); return Err(e);
} }
...@@ -468,7 +469,7 @@ fn thread_init_external( ...@@ -468,7 +469,7 @@ fn thread_init_external(
Ok(tid) Ok(tid)
} }
fn apply_thread_params(tid: libc::c_int, params: &RTParams) -> Result<()> { fn apply_thread_params(tid: libc::c_int, params: &RTParams, quiet: bool) -> Result<()> {
if !is_realtime() { if !is_realtime() {
return Ok(()); return Ok(());
} }
...@@ -480,10 +481,12 @@ fn apply_thread_params(tid: libc::c_int, params: &RTParams) -> Result<()> { ...@@ -480,10 +481,12 @@ fn apply_thread_params(tid: libc::c_int, params: &RTParams) -> Result<()> {
} }
let res = libc::sched_setaffinity(tid, std::mem::size_of::<libc::cpu_set_t>(), &cpuset); let res = libc::sched_setaffinity(tid, std::mem::size_of::<libc::cpu_set_t>(), &cpuset);
if res != 0 { if res != 0 {
if !quiet {
eprintln!( eprintln!(
"Error setting CPU affinity: {}", "Error setting CPU affinity: {}",
std::io::Error::last_os_error() std::io::Error::last_os_error()
); );
}
return Err(Error::RTSchedSetAffinity(res)); return Err(Error::RTSchedSetAffinity(res));
} }
} }
...@@ -499,10 +502,12 @@ fn apply_thread_params(tid: libc::c_int, params: &RTParams) -> Result<()> { ...@@ -499,10 +502,12 @@ fn apply_thread_params(tid: libc::c_int, params: &RTParams) -> Result<()> {
) )
}; };
if res != 0 { if res != 0 {
if !quiet {
eprintln!( eprintln!(
"Error setting scheduler: {}", "Error setting scheduler: {}",
std::io::Error::last_os_error() std::io::Error::last_os_error()
); );
}
return Err(Error::RTSchedSetSchduler(res)); return Err(Error::RTSchedSetSchduler(res));
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论