fn calibration_for_core_pairs<'a>(
        t: &T,
        core_pairs: impl Iterator<Item = (usize, usize)> + Clone,
        pages: impl Iterator<Item = &'a [u8]>,
    ) -> Result<HashMap<AV, (ErrorPrediction, HashMap<SP, ThresholdError>)>, TopologyAwareError>
    {
        let core_per_socket = find_core_per_socket();

        let operations = [
            CalibrateOperation2T {
                prepare: maccess::<u8>,
                op: T::attack,
                name: "hit",
                display_name: "hit",
                t: &t,
            },
            CalibrateOperation2T {
                prepare: noop::<u8>,
                op: T::attack,
                name: "miss",
                display_name: "miss",
                t: &t,
            },
        ];
        const HIT_INDEX: usize = 0;
        const MISS_INDEX: usize = 1;

        let mut calibrate_results2t_vec = Vec::new();

        let slicing = match get_cache_slicing(core_per_socket) {
            Some(s) => s,
            None => {
                return Err(TopologyAwareError::NoSlicing);
            }
        };
        let h = |addr: usize| slicing.hash(addr).unwrap();

        for page in pages {
            // FIXME Cache line size is magic
            let mut r = unsafe {
                calibrate_fixed_freq_2_thread(
                    &page[0] as *const u8,
                    64,
                    page.len() as isize,
                    &mut core_pairs.clone(),
                    &operations,
                    CalibrationOptions {
                        hist_params: HistParams {
                            bucket_number: CFLUSH_BUCKET_NUMBER,
                            bucket_size: CFLUSH_BUCKET_SIZE,
                            iterations: CFLUSH_NUM_ITER,
                        },
                        verbosity: Verbosity::NoOutput,
                        optimised_addresses: true,
                    },
                    core_per_socket,
                )
            };
            calibrate_results2t_vec.append(&mut r);
        }
        let analysis: HashMap<ASVP, ThresholdError> = calibration_result_to_ASVP(
            calibrate_results2t_vec,
            |cal_1t_res| {
                let e = ErrorPredictions::predict_errors(HistogramCumSum::from_calibrate(
                    cal_1t_res, HIT_INDEX, MISS_INDEX,
                ));
                PotentialThresholds::minimizing_total_error(e)
                    .median()
                    .unwrap()
            },
            &h,
        )
        .map_err(|e| TopologyAwareError::Nix(e))?;

        let asvp_best_av_errors: HashMap<AV, (ErrorPrediction, HashMap<SP, ThresholdError>)> =
            accumulate(
                analysis,
                |asvp: ASVP| AV {
                    attacker: asvp.attacker,
                    victim: asvp.victim,
                },
                || (ErrorPrediction::default(), HashMap::new()),
                |acc: &mut (ErrorPrediction, HashMap<SP, ThresholdError>),
                 threshold_error,
                 asvp: ASVP,
                 av| {
                    assert_eq!(av.attacker, asvp.attacker);
                    assert_eq!(av.victim, asvp.victim);
                    let sp = SP {
                        slice: asvp.slice,
                        page: asvp.page,
                    };
                    acc.0 += threshold_error.error;
                    acc.1.insert(sp, threshold_error);
                },
            );
        Ok(asvp_best_av_errors)
    }
// Takes a buffer / list of addresses or pages
// Takes a list of core pairs
// Run optimized calibration and processes results
Takes a buffer / list of addresses or pages
Takes a list of core pairs
Run optimized calibration and processes results
Takes a buffer / list of addresses or pages Takes a list of core pairs Run optimized calibration and processes results
fn calibration_for_core_pairs<'a>(
        t: &T,
        core_pairs: impl Iterator<Item = (usize, usize)> + Clone,
        pages: impl Iterator<Item = &'a [u8]>,
    ) -> Result<HashMap<AV, (ErrorPrediction, HashMap<SP, ThresholdError>)>, TopologyAwareError>
    {
        let core_per_socket = find_core_per_socket();
        let operations = [
            CalibrateOperation2T {
                prepare: maccess::<u8>,
                op: T::attack,
                name: "hit",
                display_name: "hit",
                t: &t,
            },
            CalibrateOperation2T {
                prepare: noop::<u8>,
                op: T::attack,
                name: "miss",
                display_name: "miss",
                t: &t,
            },
        ];
        const HIT_INDEX: usize = 0;
        const MISS_INDEX: usize = 1;
        let mut calibrate_results2t_vec = Vec::new();
        let slicing = match get_cache_slicing(core_per_socket) {
            Some(s) => s,
            None => {
                return Err(TopologyAwareError::NoSlicing);
            }
        };
        let h = |addr: usize| slicing.hash(addr).unwrap();
        for page in pages {
            // FIXME Cache line size is magic
            let mut r = unsafe {
                calibrate_fixed_freq_2_thread(
                    &page[0] as *const u8,
                    64,
                    page.len() as isize,
                    &mut core_pairs.clone(),
                    &operations,
                    CalibrationOptions {
                        hist_params: HistParams {
                            bucket_number: CFLUSH_BUCKET_NUMBER,
                            bucket_size: CFLUSH_BUCKET_SIZE,
                            iterations: CFLUSH_NUM_ITER,
                        },
                        verbosity: Verbosity::NoOutput,
                        optimised_addresses: true,
                    },
                    core_per_socket,
                )
            };
            calibrate_results2t_vec.append(&mut r);
        }
        let analysis: HashMap<ASVP, ThresholdError> = calibration_result_to_ASVP(
            calibrate_results2t_vec,
            |cal_1t_res| {
                let e = ErrorPredictions::predict_errors(HistogramCumSum::from_calibrate(
                    cal_1t_res, HIT_INDEX, MISS_INDEX,
                ));
                PotentialThresholds::minimizing_total_error(e)
                    .median()
                    .unwrap()
            },
            &h,
        )
        .map_err(|e| TopologyAwareError::Nix(e))?;
        let asvp_best_av_errors: HashMap<AV, (ErrorPrediction, HashMap<SP, ThresholdError>)> =
            accumulate(
                analysis,
                |asvp: ASVP| AV {
                    attacker: asvp.attacker,
                    victim: asvp.victim,
                },
                || (ErrorPrediction::default(), HashMap::new()),
                |acc: &mut (ErrorPrediction, HashMap<SP, ThresholdError>),
                 threshold_error,
                 asvp: ASVP,
                 av| {
                    assert_eq!(av.attacker, asvp.attacker);
                    assert_eq!(av.victim, asvp.victim);
                    let sp = SP {
                        slice: asvp.slice,
                        page: asvp.page,
                    };
                    acc.0 += threshold_error.error;
                    acc.1.insert(sp, threshold_error);
                },
            );
        Ok(asvp_best_av_errors)
    }
fn calibration_for_core_pairs < ' a > ( t : & T , core_pairs : impl Iterator < Item = ( usize , usize ) > + Clone , pages : impl Iterator < Item = & ' a [ u8 ] > , ) -> Result < HashMap < AV , ( ErrorPrediction , HashMap < SP , ThresholdError > ) > , TopologyAwareError > { let core_per_socket = find_core_per_socket ( ) ; let operations = [ CalibrateOperation2T { prepare : maccess :: < u8 > , op : T :: attack , name : " " , display_name : " " , t : & t , } , CalibrateOperation2T { prepare : noop :: < u8 > , op : T :: attack , name : " " , display_name : " " , t : & t , } , ] ; const HIT_INDEX : usize = 0 ; const MISS_INDEX : usize = 1 ; let mut calibrate_results2t_vec = Vec :: new ( ) ; let slicing = match get_cache_slicing ( core_per_socket ) { Some ( s ) => s , None => { return Err ( TopologyAwareError :: NoSlicing ) ; } } ; let h = | addr : usize | slicing . hash ( addr ) . unwrap ( ) ; for page in pages { // FIXME Cache line size is magic let mut r = unsafe { calibrate_fixed_freq_2_thread ( & page [ 0 ] as * const u8 , 64 , page . len ( ) as isize , & mut core_pairs . clone ( ) , & operations , CalibrationOptions { hist_params : HistParams { bucket_number : CFLUSH_BUCKET_NUMBER , bucket_size : CFLUSH_BUCKET_SIZE , iterations : CFLUSH_NUM_ITER , } , verbosity : Verbosity :: NoOutput , optimised_addresses : true , } , core_per_socket , ) } ; calibrate_results2t_vec . append ( & mut r ) ; } let analysis : HashMap < ASVP , ThresholdError > = calibration_result_to_ASVP ( calibrate_results2t_vec , | cal_1t_res | { let e = ErrorPredictions :: predict_errors ( HistogramCumSum :: from_calibrate ( cal_1t_res , HIT_INDEX , MISS_INDEX , ) ) ; PotentialThresholds :: minimizing_total_error ( e ) . median ( ) . unwrap ( ) } , & h , ) . map_err ( | e | TopologyAwareError :: Nix ( e ) ) ? ; let asvp_best_av_errors : HashMap < AV , ( ErrorPrediction , HashMap < SP , ThresholdError > ) > = accumulate ( analysis , | asvp : ASVP | AV { attacker : asvp . attacker , victim : asvp . victim , } , | | ( ErrorPrediction :: default ( ) , HashMap :: new ( ) ) , | acc : & mut ( ErrorPrediction , HashMap < SP , ThresholdError > ) , threshold_error , asvp : ASVP , av | { assert_eq ! ( av attacker asvp attacker ) ; assert_eq ! ( av victim asvp victim ) ; let sp = SP { slice : asvp . slice , page : asvp . page , } ; acc . 0 += threshold_error . error ; acc . 1 . insert ( sp , threshold_error ) ; } , ) ; Ok ( asvp_best_av_errors ) }
Takes a buffer / list of addresses or pages
Takes a list of core pairs
Run optimized calibration and processes results
Takes a buffer / list of addresses or pages Takes a list of core pairs Run optimized calibration and processes results
t
&T
core_pairs
impl Iterator<Item = (usize, usize)> + Clone
pages
impl Iterator<Item = &'a [u8]>