From 7b8dec570f818c8cfb5bab2438198c2fbdc44b49 Mon Sep 17 00:00:00 2001 From: Guillume DIDIER Date: Thu, 3 Dec 2020 10:02:01 +0100 Subject: [PATCH] Handle properly multi core --- .../src/bin/main-naive.rs | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/covert_channels_benchmark/src/bin/main-naive.rs b/covert_channels_benchmark/src/bin/main-naive.rs index ca58cbf..870c8ce 100644 --- a/covert_channels_benchmark/src/bin/main-naive.rs +++ b/covert_channels_benchmark/src/bin/main-naive.rs @@ -35,18 +35,22 @@ fn run_benchmark( constructor: impl Fn(usize, usize) -> T, num_iter: usize, num_pages: usize, + old: CpuSet, ) -> BenchmarkStats { let mut results = Vec::new(); print!("Benchmarking {} with {} pages", name, num_pages); - let old = sched_getaffinity(Pid::from_raw(0)).unwrap(); + let mut count = 0; for i in 0..CpuSet::count() { for j in 0..CpuSet::count() { - for _ in 0..num_iter { - print!("."); - stdout().flush().expect("Failed to flush"); - let channel = constructor(i, j); - let r = benchmark_channel(channel, num_pages, NUM_BYTES); - results.push(r); + if old.is_set(i).unwrap() && old.is_set(j).unwrap() && i != j { + for _ in 0..num_iter { + count += 1; + print!("."); + stdout().flush().expect("Failed to flush"); + let channel = constructor(i, j); + let r = benchmark_channel(channel, num_pages, NUM_BYTES); + results.push(r); + } } } } @@ -61,9 +65,9 @@ fn run_benchmark( average_C += result.capacity(); average_T += result.true_capacity() } - average_p /= num_iter as f64; - average_C /= num_iter as f64; - average_T /= num_iter as f64; + average_p /= count as f64; + average_C /= count as f64; + average_T /= count as f64; println!( "{} - {} Average p: {} C: {}, T: {}", name, num_pages, average_p, average_C, average_T @@ -79,9 +83,9 @@ fn run_benchmark( let T = result.true_capacity() - average_T; var_T += T * T; } - var_p /= num_iter as f64; - var_C /= num_iter as f64; - var_T /= num_iter as f64; + var_p /= count as f64; + var_C /= count as f64; + var_T /= count as f64; println!( "{} - {} Variance of p: {}, C: {}, T:{}", name, num_pages, var_p, var_C, var_T @@ -98,6 +102,8 @@ fn run_benchmark( } fn main() { + let old = sched_getaffinity(Pid::from_raw(0)).unwrap(); + for num_pages in 1..=32 { let naive_ff = run_benchmark( "Naive F+F", @@ -108,6 +114,7 @@ fn main() { }, NUM_ITER, num_pages, + old, ); let fr = run_benchmark( @@ -119,6 +126,7 @@ fn main() { }, NUM_ITER, num_pages, + old, ); } }