Skip to content

Commit

Permalink
more macos fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpyattaev committed Jan 8, 2025
1 parent e00029a commit 185ad7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
10 changes: 6 additions & 4 deletions thread-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ impl ThreadManager {

#[cfg(test)]
mod tests {
use {crate::ThreadManagerConfig, std::io::Read};
#[cfg(target_os = "linux")]
use {
crate::{CoreAllocation, NativeConfig, RayonConfig, ThreadManager, ThreadManagerConfig},
std::{collections::HashMap, io::Read},
crate::{CoreAllocation, NativeConfig, RayonConfig, ThreadManager},
std::collections::HashMap,
};

#[test]
Expand Down Expand Up @@ -233,8 +235,6 @@ mod tests {
let affinity = affinity::get_thread_affinity().unwrap();
assert_eq!(affinity, expect_cores, "{}", error_msg);
}
#[cfg(not(target_os = "linux"))]
fn validate_affinity(_expect_cores: &[usize], _error_msg: &str) {}

/* #[test]
fn thread_priority() {
Expand Down Expand Up @@ -311,6 +311,7 @@ mod tests {
.unwrap();
}*/

#[cfg(target_os = "linux")]
#[test]
fn process_affinity() {
let conf = ThreadManagerConfig {
Expand Down Expand Up @@ -351,6 +352,7 @@ mod tests {
thread2.join().unwrap();
}

#[cfg(target_os = "linux")]
#[test]
fn rayon_affinity() {
let conf = ThreadManagerConfig {
Expand Down
29 changes: 18 additions & 11 deletions thread-manager/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {
};

#[cfg(not(target_os = "linux"))]
struct ThreadSchedulePolicy {}
#[derive(Clone, Copy)]
pub(crate) struct ThreadSchedulePolicy {}

static CORE_COUNT: OnceLock<usize> = OnceLock::new();

Expand Down Expand Up @@ -67,25 +68,31 @@ pub fn parse_policy(policy: &str) -> ThreadSchedulePolicy {
}

#[cfg(not(target_os = "linux"))]
pub fn parse_policy(policy: &str) -> ThreadSchedulePolicy {
ThreadSchedulePolicy
pub(crate) fn parse_policy(_policy: &str) -> ThreadSchedulePolicy {
ThreadSchedulePolicy {}
}

///Applies policy to the calling thread
pub fn apply_policy(
alloc: &CoreAllocation,
policy: ThreadSchedulePolicy,
priority: u8,
chosen_cores_mask: &std::sync::Mutex<Vec<usize>>,
) {
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "linux"))]
fn apply_thread_scheduler_policy(_policy: ThreadSchedulePolicy, _priority: u8) {}

#[cfg(target_os = "linux")]
fn apply_thread_scheduler_policy(policy: ThreadSchedulePolicy, priority: u8) {
if let Err(e) = std::thread::current().set_priority_and_policy(
policy,
thread_priority::ThreadPriority::Crossplatform((priority).try_into().unwrap()),
) {
panic!("Can not set thread priority, OS error {:?}", e);
}
}

///Applies policy to the calling thread
pub(crate) fn apply_policy(
alloc: &CoreAllocation,
policy: ThreadSchedulePolicy,
priority: u8,
chosen_cores_mask: &std::sync::Mutex<Vec<usize>>,
) {
apply_thread_scheduler_policy(policy, priority);
match alloc {
CoreAllocation::PinnedCores { min: _, max: _ } => {
let mut lg = chosen_cores_mask
Expand Down

0 comments on commit 185ad7f

Please sign in to comment.