Skip to content

Commit

Permalink
Print CPU cores used for plotting and replotting thread pools during …
Browse files Browse the repository at this point in the history
…start of the farmer
  • Loading branch information
nazar-pc committed Apr 3, 2024
1 parent 5b318e3 commit b99c961
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,12 @@ where
NonZeroUsize::new((cpu_cores.cpu_cores().len() / 2).max(1).min(8)).expect("Not zero; qed")
});

info!(
?plotting_thread_pool_core_indices,
?replotting_thread_pool_core_indices,
"Preparing plotting thread pools"
);

let plotting_thread_pool_manager = create_plotting_thread_pool_manager(
plotting_thread_pool_core_indices
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-farmer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(
array_chunks,
array_windows,
assert_matches,
const_option,
exact_size_is_empty,
Expand Down
49 changes: 46 additions & 3 deletions crates/subspace-farmer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::num::NonZeroUsize;
use std::ops::Deref;
use std::pin::{pin, Pin};
use std::task::{Context, Poll};
use std::{io, thread};
use std::{fmt, io, thread};
use thread_priority::{set_current_thread_priority, ThreadPriority};
use tokio::runtime::Handle;
use tokio::task;
Expand Down Expand Up @@ -143,14 +143,57 @@ where
}

/// Abstraction for CPU core set
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct CpuCoreSet {
/// CPU cores that belong to this set
cores: Vec<usize>,
#[cfg(feature = "numa")]
topology: Option<std::sync::Arc<hwlocality::Topology>>,
}

impl fmt::Debug for CpuCoreSet {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut s = f.debug_struct("CpuCoreSet");
#[cfg(not(feature = "numa"))]
if self.cores.array_windows::<2>().all(|&[a, b]| a + 1 == b) {
s.field(
"cores",
&format!(
"{}-{}",
self.cores.first().expect("List of cores is not empty; qed"),
self.cores.last().expect("List of cores is not empty; qed")
),
);
} else {
s.field(
"cores",
&self
.cores
.iter()
.map(usize::to_string)
.collect::<Vec<_>>()
.join(","),
);
}
#[cfg(feature = "numa")]
{
use hwlocality::cpu::cpuset::CpuSet;
use hwlocality::ffi::PositiveInt;

s.field(
"cores",
&CpuSet::from_iter(
self.cores.iter().map(|&core| {
PositiveInt::try_from(core).expect("Valid CPU core index; qed")
}),
),
);
}
s.finish_non_exhaustive()
}
}

impl CpuCoreSet {
/// Regroup CPU core sets to contain at most `target_sets` sets, useful when there are many L3
/// cache groups and not as many farms
Expand Down Expand Up @@ -197,7 +240,7 @@ impl CpuCoreSet {
let cpu_cores = CpuSet::from_iter(
self.cores
.iter()
.map(|&core| PositiveInt::try_from(core).expect("Valid CPU core")),
.map(|&core| PositiveInt::try_from(core).expect("Valid CPU core index; qed")),
);

if let Err(error) =
Expand Down

0 comments on commit b99c961

Please sign in to comment.