New version of the benchmark program

This commit is contained in:
Guillume DIDIER 2021-01-28 09:36:15 +01:00
parent 7a5cae722c
commit 68263dcd3a
5 changed files with 138 additions and 33 deletions

2
Cargo.lock generated
View File

@ -119,6 +119,8 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
name = "covert_channels_benchmark" name = "covert_channels_benchmark"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"basic_timing_cache_channel",
"cache_utils",
"covert_channels_evaluation", "covert_channels_evaluation",
"flush_flush", "flush_flush",
"flush_reload", "flush_reload",

View File

@ -9,7 +9,7 @@
// Should be used by F+F and non Naive F+R // Should be used by F+F and non Naive F+R
use crate::naive::NaiveTimingChannelHandle; //use crate::naive::NaiveTimingChannelHandle;
use cache_side_channel::SideChannelError::AddressNotReady; use cache_side_channel::SideChannelError::AddressNotReady;
use cache_side_channel::{ use cache_side_channel::{
CacheStatus, ChannelFatalError, ChannelHandle, CoreSpec, MultipleAddrCacheSideChannel, CacheStatus, ChannelFatalError, ChannelHandle, CoreSpec, MultipleAddrCacheSideChannel,

View File

@ -11,5 +11,7 @@ covert_channels_evaluation = { path = "../covert_channels_evaluation" }
flush_flush = { path = "../flush_flush" } flush_flush = { path = "../flush_flush" }
flush_reload = { path = "../flush_reload" } flush_reload = { path = "../flush_reload" }
nix = "0.18.0" nix = "0.18.0"
basic_timing_cache_channel = { path = "../basic_timing_cache_channel" }
cache_utils = { path = "../cache_utils" }

View File

@ -1,6 +1,6 @@
#![feature(unsafe_block_in_unsafe_fn)] #![feature(unsafe_block_in_unsafe_fn)]
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
/*
use std::io::{stdout, Write}; use std::io::{stdout, Write};
use covert_channels_evaluation::{benchmark_channel, CovertChannel, CovertChannelBenchmarkResult}; use covert_channels_evaluation::{benchmark_channel, CovertChannel, CovertChannelBenchmarkResult};
@ -113,8 +113,9 @@ fn run_benchmark<T: CovertChannel + 'static>(
var_T, var_T,
} }
} }
*/
fn main() { fn main() {
/*
let old = sched_getaffinity(Pid::from_raw(0)).unwrap(); let old = sched_getaffinity(Pid::from_raw(0)).unwrap();
println!( println!(
"Detailed:Benchmark,Pages,{},C,T", "Detailed:Benchmark,Pages,{},C,T",
@ -147,4 +148,6 @@ fn main() {
old, old,
); );
} }
*/
} }

View File

@ -3,12 +3,17 @@
use std::io::{stdout, Write}; use std::io::{stdout, Write};
//use basic_timing_cache_channel::{naive::NaiveTimingChannel, TopologyAwareTimingChannel};
use basic_timing_cache_channel::{TopologyAwareError, TopologyAwareTimingChannel};
use cache_utils::calibration::Threshold;
use covert_channels_evaluation::{benchmark_channel, CovertChannel, CovertChannelBenchmarkResult}; use covert_channels_evaluation::{benchmark_channel, CovertChannel, CovertChannelBenchmarkResult};
use flush_flush::naive::NaiveFlushAndFlush; use flush_flush::naive::NaiveFlushAndFlush;
use flush_flush::{FlushAndFlush, SingleFlushAndFlush}; use flush_flush::{FFPrimitives, FlushAndFlush, SingleFlushAndFlush};
use flush_reload::naive::NaiveFlushAndReload; use flush_reload::naive::{NaiveFRPrimitives, NaiveFlushAndReload};
use nix::sched::{sched_getaffinity, CpuSet};
use nix::unistd::Pid;
const NUM_BYTES: usize = 1 << 14; //20 const NUM_BYTES: usize = 1 << 12;
const NUM_PAGES: usize = 1; const NUM_PAGES: usize = 1;
@ -16,10 +21,10 @@ const NUM_PAGES_2: usize = 4;
const NUM_PAGE_MAX: usize = 32; const NUM_PAGE_MAX: usize = 32;
const NUM_ITER: usize = 32; const NUM_ITER: usize = 16;
struct BenchmarkStats { struct BenchmarkStats {
raw_res: Vec<CovertChannelBenchmarkResult>, raw_res: Vec<(CovertChannelBenchmarkResult, usize, usize)>,
average_p: f64, average_p: f64,
var_p: f64, var_p: f64,
average_C: f64, average_C: f64,
@ -30,34 +35,59 @@ struct BenchmarkStats {
fn run_benchmark<T: CovertChannel + 'static>( fn run_benchmark<T: CovertChannel + 'static>(
name: &str, name: &str,
constructor: impl Fn() -> T, constructor: impl Fn(usize, usize) -> (T, usize, usize),
num_iter: usize, num_iter: usize,
num_pages: usize, num_pages: usize,
old: CpuSet,
) -> BenchmarkStats { ) -> BenchmarkStats {
let mut results = Vec::new(); let mut results = Vec::new();
print!("Benchmarking {} with {} pages", name, num_pages); print!("Benchmarking {} with {} pages", name, num_pages);
for _ in 0..num_iter { let mut count = 0;
print!("."); for i in 0..CpuSet::count() {
stdout().flush().expect("Failed to flush"); for j in 0..CpuSet::count() {
let channel = constructor(); if old.is_set(i).unwrap() && old.is_set(j).unwrap() && i != j {
let r = benchmark_channel(channel, num_pages, NUM_BYTES); for _ in 0..num_iter {
results.push(r); 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));
}
}
}
} }
println!(); println!();
let mut average_p = 0.0; let mut average_p = 0.0;
let mut average_C = 0.0; let mut average_C = 0.0;
let mut average_T = 0.0; let mut average_T = 0.0;
for result in results.iter() { for result in results.iter() {
println!("{:?}", result); println!(
println!("C: {}, T: {}", result.capacity(), result.true_capacity()); "main: {} helper: {} result: {:?}",
println!("Detailed:\"{}\",{},{},{},{}", name, num_pages, result.csv(), result.capacity(), result.true_capacity()); result.1, result.2, result.0
average_p += result.error_rate; );
average_C += result.capacity(); println!(
average_T += result.true_capacity() "C: {}, T: {}",
result.0.capacity(),
result.0.true_capacity()
);
println!(
"Detailed:\"{}\",{},{},{},{},{},{}",
name,
num_pages,
result.1,
result.2,
result.0.csv(),
result.0.capacity(),
result.0.true_capacity()
);
average_p += result.0.error_rate;
average_C += result.0.capacity();
average_T += result.0.true_capacity()
} }
average_p /= num_iter as f64; average_p /= count as f64;
average_C /= num_iter as f64; average_C /= count as f64;
average_T /= num_iter as f64; average_T /= count as f64;
println!( println!(
"{} - {} Average p: {} C: {}, T: {}", "{} - {} Average p: {} C: {}, T: {}",
name, num_pages, average_p, average_C, average_T name, num_pages, average_p, average_C, average_T
@ -66,21 +96,25 @@ fn run_benchmark<T: CovertChannel + 'static>(
let mut var_C = 0.0; let mut var_C = 0.0;
let mut var_T = 0.0; let mut var_T = 0.0;
for result in results.iter() { for result in results.iter() {
let p = result.error_rate - average_p; let p = result.0.error_rate - average_p;
var_p += p * p; var_p += p * p;
let C = result.capacity() - average_C; let C = result.0.capacity() - average_C;
var_C += C * C; var_C += C * C;
let T = result.true_capacity() - average_T; let T = result.0.true_capacity() - average_T;
var_T += T * T; var_T += T * T;
} }
var_p /= num_iter as f64; var_p /= count as f64;
var_C /= num_iter as f64; var_C /= count as f64;
var_T /= num_iter as f64; var_T /= count as f64;
println!( println!(
"{} - {} Variance of p: {}, C: {}, T:{}", "{} - {} Variance of p: {}, C: {}, T:{}",
name, num_pages, var_p, var_C, var_T name, num_pages, var_p, var_C, var_T
); );
println!("CSV:\"{}\",{},{},{},{},{},{},{}",name,num_pages,average_p, average_C, average_T, var_p, var_C, var_T); println!(
"CSV:\"{}\",{},{},{},{},{},{},{}",
name, num_pages, average_p, average_C, average_T, var_p, var_C, var_T
);
BenchmarkStats { BenchmarkStats {
raw_res: results, raw_res: results,
average_p, average_p,
@ -93,9 +127,72 @@ fn run_benchmark<T: CovertChannel + 'static>(
} }
fn main() { fn main() {
println!("Detailed:Benchmark,Pages,{},C,T",CovertChannelBenchmarkResult::csv_header()); let old = sched_getaffinity(Pid::from_raw(0)).unwrap();
println!("CSV:Benchmark,Pages,p,C,T,var_p,var_C,var_T"); println!(
"Detailed:Benchmark,Pages,main_core,helper_core,{},C,T",
CovertChannelBenchmarkResult::csv_header()
);
println!("CSV:Benchmark,Pages,main_core,helper_core,p,C,T,var_p,var_C,var_T");
for num_pages in 1..=32 { for num_pages in 1..=32 {
let naive_ff = run_benchmark(
"Naive F+F",
|i, j| {
let mut r = NaiveFlushAndFlush::new(
Threshold {
bucket_index: 202,
miss_faster_than_hit: true,
},
FFPrimitives {},
);
r.set_cores(i, j);
(r, i, j)
},
NUM_ITER,
num_pages,
old,
);
let fr = run_benchmark(
"F+R",
|i, j| {
let mut r = NaiveFlushAndReload::new(
Threshold {
bucket_index: 250,
miss_faster_than_hit: false,
},
NaiveFRPrimitives {},
);
r.set_cores(i, j);
(r, i, j)
},
NUM_ITER,
num_pages,
old,
);
let ff = run_benchmark(
"Better F+F",
|i, j| {
let (mut r, i, j) = match FlushAndFlush::new_any_two_core(true, FFPrimitives {}) {
Ok((channel, _old, main_core, helper_core)) => {
(channel, main_core, helper_core)
}
Err(e) => {
panic!("{:?}", e);
}
};
(r, i, j)
},
1,
num_pages,
old,
);
}
}
/*
fn main() {
for num_pages in 1..=32 {
/*println!("Benchmarking F+F"); /*println!("Benchmarking F+F");
for _ in 0..16 { for _ in 0..16 {
// TODO Use the best possible ASV, not best possible AV // TODO Use the best possible ASV, not best possible AV
@ -142,3 +239,4 @@ fn main() {
); );
} }
} }
*/