Skip to content

Commit

Permalink
Add fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Oct 8, 2020
1 parent fb5172f commit 5589efe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
35 changes: 21 additions & 14 deletions storage-proofs/porep/src/stacked/vanilla/cores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,26 @@ pub fn checkout_core_group() -> Option<MutexGuard<'static, CoreGroup>> {
}
}

#[cfg(not(target_os = "windows"))]
pub type ThreadId = libc::pthread_t;

#[cfg(target_os = "windows")]
pub type ThreadId = winapi::winnt::HANDLE;

/// Helper method to get the thread id through libc, with current rust stable (1.5.0) its not
/// possible otherwise I think.
#[cfg(not(target_os = "windows"))]
fn get_thread_id() -> ThreadId {
unsafe { libc::pthread_self() }
}

#[cfg(target_os = "windows")]
fn get_thread_id() -> ThreadId {
unsafe { kernel32::GetCurrentThread() }
}

pub struct Cleanup {
tid: ThreadId,
prior_state: Option<hwloc::Bitmap>,
}

Expand All @@ -51,9 +70,8 @@ impl Drop for Cleanup {
match self.prior_state.take() {
Some(prior) => {
let child_topo = &TOPOLOGY;
let tid = get_thread_id();
let mut locked_topo = child_topo.lock().unwrap();
let _ = locked_topo.set_cpubind_for_thread(tid, prior, CPUBIND_THREAD);
let _ = locked_topo.set_cpubind_for_thread(self.tid, prior, CPUBIND_THREAD);
}
None => (),
}
Expand Down Expand Up @@ -91,6 +109,7 @@ pub fn bind_core(core_index: CoreIndex) -> Result<Cleanup> {
}

Ok(Cleanup {
tid,
prior_state: before,
})
}
Expand All @@ -109,18 +128,6 @@ fn get_core_by_index<'a>(topo: &'a Topology, index: CoreIndex) -> Result<&'a Top
}
}

/// Helper method to get the thread id through libc, with current rust stable (1.5.0) its not
/// possible otherwise I think.
#[cfg(not(target_os = "windows"))]
fn get_thread_id() -> libc::pthread_t {
unsafe { libc::pthread_self() }
}

#[cfg(target_os = "windows")]
fn get_thread_id() -> winapi::winnt::HANDLE {
unsafe { kernel32::GetCurrentThread() }
}

fn core_groups(cores_per_unit: usize) -> Option<Vec<Mutex<Vec<CoreIndex>>>> {
let topo = TOPOLOGY.lock().unwrap();

Expand Down
10 changes: 5 additions & 5 deletions storage-proofs/porep/src/stacked/vanilla/create_label/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,13 @@ pub fn create_labels_for_decoding<Tree: 'static + MerkleTreeTrait, T: AsRef<[u8]

let core_group = Arc::new(checkout_core_group());

if let Some(group) = &*core_group {
// When `_cleanup_handle` is dropped, the previous binding of thread will be restored.
let _cleanup_handle = (*core_group).as_ref().map(|group| {
// This could fail, but we will ignore the error if so.
// It will be logged as a warning by `bind_core`.
if let Some(&core_index) = group.get(0) {
let _ = bind_core(core_index);
}
};
debug!("binding core in main thread");
group.get(0).map(|core_index| bind_core(*core_index))
});

// NOTE: this means we currently keep 2x sector size around, to improve speed
let (parents_cache, mut layer_labels, mut exp_labels) = setup_create_label_memory(
Expand Down

0 comments on commit 5589efe

Please sign in to comment.