Skip to content

Commit

Permalink
Regroup and leverage all CPU cores instead of printing a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Jan 30, 2024
1 parent faff228 commit cc0aff4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
39 changes: 22 additions & 17 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use subspace_farmer::utils::ss58::parse_ss58_reward_address;
use subspace_farmer::utils::{
all_cpu_cores, create_plotting_thread_pool_manager, parse_cpu_cores_sets,
recommended_number_of_farming_threads, run_future_in_dedicated_thread,
thread_pool_core_indices, AsyncJoinOnDrop,
thread_pool_core_indices, AsyncJoinOnDrop, CpuCoreSet,
};
use subspace_farmer::{Identity, NodeClient, NodeRpcClient};
use subspace_farmer_components::plotting::PlottedSector;
Expand Down Expand Up @@ -461,8 +461,8 @@ where
None => farmer_app_info.protocol_info.max_pieces_in_sector,
};

let plotting_thread_pool_core_indices;
let replotting_thread_pool_core_indices;
let mut plotting_thread_pool_core_indices;
let mut replotting_thread_pool_core_indices;
if let Some(plotting_cpu_cores) = plotting_cpu_cores {
plotting_thread_pool_core_indices = parse_cpu_cores_sets(&plotting_cpu_cores)
.map_err(|error| anyhow::anyhow!("Failed to parse `--plotting-cpu-cores`: {error}"))?;
Expand Down Expand Up @@ -495,6 +495,25 @@ where
}
replotting_thread_pool_core_indices
};

if plotting_thread_pool_core_indices.len() > 1 {
info!(
l3_cache_groups = %plotting_thread_pool_core_indices.len(),
"Multiple L3 cache groups detected"
);

if plotting_thread_pool_core_indices.len() > disk_farms.len() {
plotting_thread_pool_core_indices =
CpuCoreSet::regroup(&plotting_thread_pool_core_indices, disk_farms.len());
replotting_thread_pool_core_indices =
CpuCoreSet::regroup(&replotting_thread_pool_core_indices, disk_farms.len());

info!(
farms_count = %disk_farms.len(),
"Regrouped CPU cores to match number of farms, more farms may leverage CPU more efficiently"
);
}
}
}

let downloading_semaphore = Arc::new(Semaphore::new(
Expand All @@ -512,20 +531,6 @@ where
.map(|farming_thread_pool_size| farming_thread_pool_size.get())
.unwrap_or_else(recommended_number_of_farming_threads);

let all_cpu_cores = all_cpu_cores();
if all_cpu_cores.len() > 1 {
info!(l3_cache_groups = %all_cpu_cores.len(), "Multiple L3 cache groups detected");

if all_cpu_cores.len() > disk_farms.len() {
warn!(
l3_cache_groups = %all_cpu_cores.len(),
farms_count = %disk_farms.len(),
"Too few disk farms, CPU will not be utilized fully during plotting, same number \
of farms as L3 cache groups or more is recommended"
);
}
}

let mut plotting_delay_senders = Vec::with_capacity(disk_farms.len());

for (disk_farm_index, disk_farm) in disk_farms.into_iter().enumerate() {
Expand Down
21 changes: 21 additions & 0 deletions crates/subspace-farmer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ pub struct CpuCoreSet {
}

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
pub fn regroup(cpu_core_sets: &[Self], target_sets: usize) -> Vec<Self> {
cpu_core_sets
// Chunk CPU core sets
.chunks(cpu_core_sets.len().div_ceil(target_sets))
.map(|sets| Self {
// Combine CPU cores
cores: sets
.iter()
.flat_map(|set| set.cores.iter())
.copied()
.collect(),
// Preserve topology object
#[cfg(feature = "numa")]
topology: sets[0].topology.clone(),
})
.collect()
}

/// Get cpu core numbers in this set
pub fn cpu_cores(&self) -> &[usize] {
&self.cores
}
Expand Down

0 comments on commit cc0aff4

Please sign in to comment.