Make the 2T calibration also handle the same core case (with no helper thread)

This commit is contained in:
GuillaumeDIDIER 2020-07-09 13:35:58 +02:00
parent daaca820fd
commit 2323c69ead

View File

@ -610,13 +610,18 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
} }
} }
helper_thread_params.stop.store(false, Ordering::Relaxed); let helper_thread = if helper_core != main_core {
// set up the helper thread helper_thread_params.stop.store(false, Ordering::Relaxed);
// set up the helper thread
let htp = helper_thread_params.clone();
let hc = helper_core;
let helper_thread = thread::spawn(move || calibrate_fixed_freq_2_thread_helper(htp, hc));
let htp = helper_thread_params.clone();
let hc = helper_core;
Some(thread::spawn(move || {
calibrate_fixed_freq_2_thread_helper(htp, hc)
}))
} else {
None
};
// do the calibration // do the calibration
let mut calibrate_result_vec = Vec::new(); let mut calibrate_result_vec = Vec::new();
@ -646,24 +651,40 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
}; };
calibrate_result.histogram.reserve(operations.len()); calibrate_result.histogram.reserve(operations.len());
for op in operations { if helper_core != main_core {
helper_thread_params.op.store(op.prepare, Ordering::Relaxed); for op in operations {
let mut hist = vec![0; hist_params.bucket_number]; helper_thread_params.op.store(op.prepare, Ordering::Relaxed);
for _ in 0..hist_params.iterations { let mut hist = vec![0; hist_params.bucket_number];
next(&helper_thread_params.turn); for _ in 0..hist_params.iterations {
wait(&helper_thread_params.turn, false); next(&helper_thread_params.turn);
let _time = unsafe { (op.op)(pointer) }; wait(&helper_thread_params.turn, false);
let _time = unsafe { (op.op)(pointer) };
}
for _ in 0..hist_params.iterations {
next(&helper_thread_params.turn);
wait(&helper_thread_params.turn, false);
let time = unsafe { (op.op)(pointer) };
let bucket = min(hist_params.bucket_number - 1, to_bucket(time));
hist[bucket] += 1;
}
calibrate_result.histogram.push(hist);
} }
for _ in 0..hist_params.iterations { } else {
next(&helper_thread_params.turn); for op in operations {
wait(&helper_thread_params.turn, false); let mut hist = vec![0; hist_params.bucket_number];
let time = unsafe { (op.op)(pointer) }; for _ in 0..hist_params.iterations {
let bucket = min(hist_params.bucket_number - 1, to_bucket(time)); unsafe { (op.prepare)(pointer) };
hist[bucket] += 1; let _time = unsafe { (op.op)(pointer) };
}
for _ in 0..hist_params.iterations {
unsafe { (op.prepare)(pointer) };
let time = unsafe { (op.op)(pointer) };
let bucket = min(hist_params.bucket_number - 1, to_bucket(time));
hist[bucket] += 1;
}
calibrate_result.histogram.push(hist);
} }
calibrate_result.histogram.push(hist);
} }
let mut sums = vec![0; operations.len()]; let mut sums = vec![0; operations.len()];
let median_thresholds: Vec<u32> = calibrate_result let median_thresholds: Vec<u32> = calibrate_result
@ -740,12 +761,15 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
helper_core, helper_core,
res: Ok(calibrate_result_vec), res: Ok(calibrate_result_vec),
}); });
// terminate the thread
helper_thread_params.stop.store(true, Ordering::Relaxed); if helper_core != main_core {
next(&helper_thread_params.turn); // terminate the thread
wait(&helper_thread_params.turn, false); helper_thread_params.stop.store(true, Ordering::Relaxed);
// join thread. next(&helper_thread_params.turn);
helper_thread.join(); wait(&helper_thread_params.turn, false);
// join thread.
helper_thread.unwrap().join();
}
} }
sched_setaffinity(Pid::from_raw(0), &old).unwrap(); sched_setaffinity(Pid::from_raw(0), &old).unwrap();