From bebbf379c10d05c16547bb04cec2e69e483d8c19 Mon Sep 17 00:00:00 2001 From: guillaume didier Date: Wed, 1 Apr 2020 16:31:06 +0200 Subject: [PATCH] Make clippy happier --- cache_utils/src/calibration.rs | 5 ++--- cache_utils/src/main.rs | 4 ++-- cache_utils/src/prefetcher.rs | 35 +++++++++++++++++++--------------- src/main.rs | 28 +++++++++++++++++---------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/cache_utils/src/calibration.rs b/cache_utils/src/calibration.rs index ee5eba5..bd19543 100644 --- a/cache_utils/src/calibration.rs +++ b/cache_utils/src/calibration.rs @@ -2,7 +2,7 @@ use crate::{flush, maccess, rdtsc_fence}; use core::arch::x86_64 as arch_x86; #[cfg(feature = "no_std")] -use polling_serial::serial_println as println; +use polling_serial::{serial_print as print, serial_println as println}; #[derive(Ord, PartialOrd, Eq, PartialEq)] pub enum Verbosity { @@ -13,7 +13,7 @@ pub enum Verbosity { } extern crate alloc; -use crate::calibration::Verbosity::{Debug, NoOutput, RawResult, Thresholds}; +use crate::calibration::Verbosity::*; use alloc::vec; use alloc::vec::Vec; use core::cmp::min; @@ -150,7 +150,6 @@ const CFLUSH_BUCKET_SIZE: usize = 1; const CFLUSH_BUCKET_NUMBER: usize = 500; const CFLUSH_NUM_ITER: u32 = 1 << 11; -const CFLUSH_SPURIOUS_THRESHOLD: usize = 1; /* TODO Code cleanup : - change type back to a slice OK diff --git a/cache_utils/src/main.rs b/cache_utils/src/main.rs index cca6e41..dfdf770 100644 --- a/cache_utils/src/main.rs +++ b/cache_utils/src/main.rs @@ -81,8 +81,8 @@ pub fn main() { println!("skipping"); continue; } - Err(_) => { - panic!("Unexpected error while setting affinity"); + Err(e) => { + panic!("Unexpected error while setting affinity: {}", e); } } } diff --git a/cache_utils/src/prefetcher.rs b/cache_utils/src/prefetcher.rs index d960505..83f8f58 100644 --- a/cache_utils/src/prefetcher.rs +++ b/cache_utils/src/prefetcher.rs @@ -1,8 +1,6 @@ use x86_64::registers::model_specific::Msr; use crate::calibration::only_flush; -use crate::flush; -use crate::maccess; extern crate alloc; use alloc::vec; @@ -28,26 +26,33 @@ pub fn enable_prefetchers(status: bool) { unsafe { msr.write(value) }; } -pub fn prefetcher_fun( +pub unsafe fn prefetcher_fun( victim_4k_addr: *mut u8, #[allow(non_snake_case)] _victim_2M_addr: *mut u8, threshold_ff: u64, ) -> Vec { - let mut results = vec![0; 4096 / 64]; + fn implementation( + victim_4k_addr: *mut u8, + #[allow(non_snake_case)] _victim_2M_addr: *mut u8, + threshold_ff: u64, + ) -> Vec { + let mut results = vec![0; 4096 / 64]; - if false { - for _ in 0..N { - //unsafe { maccess(victim4kaddr) }; - for j in (0..4096).step_by(64).rev() { - let t = unsafe { only_flush(victim_4k_addr.offset(j)) }; - if threshold_ff < t { - // hit - results[(j / 64) as usize] += 1; - } else if threshold_ff > t { - results[(j / 64) as usize] -= 1; + if false { + for _ in 0..N { + //unsafe { maccess(victim4kaddr) }; + for j in (0..4096).step_by(64).rev() { + let t = unsafe { only_flush(victim_4k_addr.offset(j)) }; + if threshold_ff < t { + // hit + results[(j / 64) as usize] += 1; + } else if threshold_ff > t { + results[(j / 64) as usize] -= 1; + } } } } + results } - results + implementation(victim_4k_addr, _victim_2M_addr, threshold_ff) } diff --git a/src/main.rs b/src/main.rs index 74aaf3c..6d9f89c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -269,18 +269,26 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { let threshold_flush = 0; // FIXME serial_println!("0"); - let r_no_prefetch = prefetcher_fun( - victim4k_start as *mut u8, - unsafe { (victim.range.start_addr() as *mut u8).offset(phys_mem_offset.as_u64() as isize) }, - threshold_flush, - ); + let r_no_prefetch = unsafe { + prefetcher_fun( + victim4k_start as *mut u8, + unsafe { + (victim.range.start_addr() as *mut u8).offset(phys_mem_offset.as_u64() as isize) + }, + threshold_flush, + ) + }; serial_println!("1"); enable_prefetchers(true); - let r_prefetch = prefetcher_fun( - victim4k_start as *mut u8, - unsafe { (victim.range.start_addr() as *mut u8).offset(phys_mem_offset.as_u64() as isize) }, - threshold_flush, - ); + let r_prefetch = unsafe { + prefetcher_fun( + victim4k_start as *mut u8, + unsafe { + (victim.range.start_addr() as *mut u8).offset(phys_mem_offset.as_u64() as isize) + }, + threshold_flush, + ) + }; for (i, (&npf, pf)) in r_no_prefetch.iter().zip(r_prefetch).enumerate() { serial_println!("{} {} {}", i, npf, pf);