Skip to content

Commit 1cff1e9

Browse files
authored
Merge pull request #2662 from subspace/print-cpu-cores-on-start
Print CPU cores used for plotting and replotting thread pools during start of the farmer
2 parents 6c357aa + b99c961 commit 1cff1e9

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs

+6
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ where
641641
NonZeroUsize::new((cpu_cores.cpu_cores().len() / 2).max(1).min(8)).expect("Not zero; qed")
642642
});
643643

644+
info!(
645+
?plotting_thread_pool_core_indices,
646+
?replotting_thread_pool_core_indices,
647+
"Preparing plotting thread pools"
648+
);
649+
644650
let plotting_thread_pool_manager = create_plotting_thread_pool_manager(
645651
plotting_thread_pool_core_indices
646652
.into_iter()

crates/subspace-farmer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(
22
array_chunks,
3+
array_windows,
34
assert_matches,
45
const_option,
56
exact_size_is_empty,

crates/subspace-farmer/src/utils.rs

+46-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::num::NonZeroUsize;
1515
use std::ops::Deref;
1616
use std::pin::{pin, Pin};
1717
use std::task::{Context, Poll};
18-
use std::{io, thread};
18+
use std::{fmt, io, thread};
1919
use thread_priority::{set_current_thread_priority, ThreadPriority};
2020
use tokio::runtime::Handle;
2121
use tokio::task;
@@ -143,14 +143,57 @@ where
143143
}
144144

145145
/// Abstraction for CPU core set
146-
#[derive(Debug, Clone)]
146+
#[derive(Clone)]
147147
pub struct CpuCoreSet {
148148
/// CPU cores that belong to this set
149149
cores: Vec<usize>,
150150
#[cfg(feature = "numa")]
151151
topology: Option<std::sync::Arc<hwlocality::Topology>>,
152152
}
153153

154+
impl fmt::Debug for CpuCoreSet {
155+
#[inline]
156+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
157+
let mut s = f.debug_struct("CpuCoreSet");
158+
#[cfg(not(feature = "numa"))]
159+
if self.cores.array_windows::<2>().all(|&[a, b]| a + 1 == b) {
160+
s.field(
161+
"cores",
162+
&format!(
163+
"{}-{}",
164+
self.cores.first().expect("List of cores is not empty; qed"),
165+
self.cores.last().expect("List of cores is not empty; qed")
166+
),
167+
);
168+
} else {
169+
s.field(
170+
"cores",
171+
&self
172+
.cores
173+
.iter()
174+
.map(usize::to_string)
175+
.collect::<Vec<_>>()
176+
.join(","),
177+
);
178+
}
179+
#[cfg(feature = "numa")]
180+
{
181+
use hwlocality::cpu::cpuset::CpuSet;
182+
use hwlocality::ffi::PositiveInt;
183+
184+
s.field(
185+
"cores",
186+
&CpuSet::from_iter(
187+
self.cores.iter().map(|&core| {
188+
PositiveInt::try_from(core).expect("Valid CPU core index; qed")
189+
}),
190+
),
191+
);
192+
}
193+
s.finish_non_exhaustive()
194+
}
195+
}
196+
154197
impl CpuCoreSet {
155198
/// Regroup CPU core sets to contain at most `target_sets` sets, useful when there are many L3
156199
/// cache groups and not as many farms
@@ -197,7 +240,7 @@ impl CpuCoreSet {
197240
let cpu_cores = CpuSet::from_iter(
198241
self.cores
199242
.iter()
200-
.map(|&core| PositiveInt::try_from(core).expect("Valid CPU core")),
243+
.map(|&core| PositiveInt::try_from(core).expect("Valid CPU core index; qed")),
201244
);
202245

203246
if let Err(error) =

0 commit comments

Comments
 (0)