From 4cf1fa220f9f790de5abe9ed81a507de3f751a2f Mon Sep 17 00:00:00 2001 From: Guillume DIDIER Date: Mon, 19 Jul 2021 09:36:25 +0200 Subject: [PATCH] Backport from 5c9ac31ab the logic avoid unnecessary iterations Improved version of the covert channels do not need to iterate over all core pairs (they pick their own core pair, and already iterate on all of them as part of calibration). This avoids an unnecessary n^4 complexity, and reduces it to n^2, where n is the number of cores. --- covert_channels_benchmark/src/main.rs | 41 +++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/covert_channels_benchmark/src/main.rs b/covert_channels_benchmark/src/main.rs index a570223..ed13b91 100644 --- a/covert_channels_benchmark/src/main.rs +++ b/covert_channels_benchmark/src/main.rs @@ -40,23 +40,35 @@ fn run_benchmark( num_iter: usize, num_pages: usize, old: CpuSet, + iterate_cores: bool, ) -> BenchmarkStats { let mut results = Vec::new(); print!("Benchmarking {} with {} pages", name, num_pages); let mut count = 0; - for i in 0..CpuSet::count() { - for j in 0..CpuSet::count() { - 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, main_core, helper_core) = constructor(i, j); - let r = benchmark_channel(channel, num_pages, NUM_BYTES); - results.push((r, main_core, helper_core)); + if iterate_cores { + for i in 0..CpuSet::count() { + for j in 0..CpuSet::count() { + 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, main_core, helper_core) = constructor(i, j); + let r = benchmark_channel(channel, num_pages, NUM_BYTES); + results.push((r, main_core, helper_core)); + } } } } + } else { + for _ in 0..num_iter { + count += 1; + print!("."); + stdout().flush().expect("Failed to flush"); + let (channel, main_core, helper_core) = constructor(0, 0); + let r = benchmark_channel(channel, num_pages, NUM_BYTES); + results.push((r, main_core, helper_core)); + } } println!(); let mut average_p = 0.0; @@ -149,6 +161,7 @@ fn main() { NUM_ITER, num_pages, old, + true, ); let naive_fr = run_benchmark( @@ -158,12 +171,14 @@ fn main() { bucket_index: 250, miss_faster_than_hit: false, }); + r.set_cores(i, j); (r, i, j) }, NUM_ITER, num_pages, old, + true, ); let ff = run_benchmark( @@ -179,9 +194,10 @@ fn main() { }; (r, i, j) }, - 1, + NUM_ITER, num_pages, old, + false, ); let fr = run_benchmark( @@ -197,9 +213,10 @@ fn main() { }; (r, i, j) }, - 1, + NUM_ITER, num_pages, old, + false, ); } }