Make clippy happier

This commit is contained in:
guillaume didier 2020-02-21 11:36:22 +01:00
parent f3f7aad23c
commit 44b0aaf372
6 changed files with 26 additions and 44 deletions

View File

@ -1,8 +1,8 @@
use crate::{flush, maccess, rdtsc_fence}; use crate::{flush, maccess, rdtsc_fence};
use polling_serial::serial_println; use polling_serial::serial_println;
use vga_buffer::println;
extern crate alloc; extern crate alloc;
use alloc::vec;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::cmp::min; use core::cmp::min;
@ -13,32 +13,28 @@ use core::cmp::min;
unsafe fn only_reload(p: *const u8) -> u64 { unsafe fn only_reload(p: *const u8) -> u64 {
let t = rdtsc_fence(); let t = rdtsc_fence();
maccess(p); maccess(p);
let d = rdtsc_fence() - t; rdtsc_fence() - t
d
} }
unsafe fn flush_and_reload(p: *const u8) -> u64 { unsafe fn flush_and_reload(p: *const u8) -> u64 {
flush(p); flush(p);
let t = rdtsc_fence(); let t = rdtsc_fence();
maccess(p); maccess(p);
let d = rdtsc_fence() - t; rdtsc_fence() - t
d
} }
unsafe fn load_and_flush(p: *const u8) -> u64 { unsafe fn load_and_flush(p: *const u8) -> u64 {
maccess(p); maccess(p);
let t = rdtsc_fence(); let t = rdtsc_fence();
flush(p); flush(p);
let d = rdtsc_fence() - t; rdtsc_fence() - t
d
} }
unsafe fn flush_and_flush(p: *const u8) -> u64 { unsafe fn flush_and_flush(p: *const u8) -> u64 {
flush(p); flush(p);
let t = rdtsc_fence(); let t = rdtsc_fence();
flush(p); flush(p);
let d = rdtsc_fence() - t; rdtsc_fence() - t
d
} }
const BUCKET_SIZE: usize = 5; const BUCKET_SIZE: usize = 5;
@ -57,19 +53,13 @@ pub fn calibrate_access() -> u64 {
// Histograms bucket of 5 and max at 400 cycles // Histograms bucket of 5 and max at 400 cycles
// Magic numbers to be justified // Magic numbers to be justified
// 80 is a size of screen // 80 is a size of screen
let mut hit_histogram = Vec::<u32>::with_capacity(BUCKET_NUMBER); let mut hit_histogram = vec![0; BUCKET_NUMBER]; //Vec::<u32>::with_capacity(BUCKET_NUMBER);
hit_histogram.resize(BUCKET_NUMBER, 0); //hit_histogram.resize(BUCKET_NUMBER, 0);
let mut miss_histogram = hit_histogram.clone(); let mut miss_histogram = hit_histogram.clone();
// the address in memory we are going to target // the address in memory we are going to target
let pointer = (&array[2048] as *const usize) as *const u8; let pointer = (&array[2048] as *const usize) as *const u8;
// sanity check
println!(
"&array[0]: {:p}, array[2048]{:p}",
(&array[0] as *const usize) as *const u8,
(&array[2048] as *const usize) as *const u8
);
// do a large sample of accesses to a cached line // do a large sample of accesses to a cached line
unsafe { maccess(pointer) }; unsafe { maccess(pointer) };
@ -136,19 +126,12 @@ pub fn calibrate_flush() -> u64 {
// Histograms bucket of 5 and max at 400 cycles // Histograms bucket of 5 and max at 400 cycles
// Magic numbers to be justified // Magic numbers to be justified
// 80 is a size of screen // 80 is a size of screen
let mut hit_histogram = Vec::<u32>::with_capacity(CFLUSH_BUCKET_NUMBER); let mut hit_histogram = vec![0; CFLUSH_BUCKET_NUMBER];
hit_histogram.resize(CFLUSH_BUCKET_NUMBER, 0);
let mut miss_histogram = hit_histogram.clone(); let mut miss_histogram = hit_histogram.clone();
// the address in memory we are going to target // the address in memory we are going to target
let pointer = (&array[2048] as *const usize) as *const u8; let pointer = (&array[2048] as *const usize) as *const u8;
// sanity check
println!(
"&array[0]: {:p}, array[2048]{:p}",
(&array[0] as *const usize) as *const u8,
(&array[2048] as *const usize) as *const u8
);
// do a large sample of accesses to a cached line // do a large sample of accesses to a cached line
for _ in 0..(4 << 20) { for _ in 0..(4 << 20) {

View File

@ -19,12 +19,12 @@ pub unsafe fn rdtsc_fence() -> u64 {
tsc tsc
} }
pub unsafe fn maccess<T>(p: *const T) -> () { pub unsafe fn maccess<T>(p: *const T) {
ptr::read_volatile(p); ptr::read_volatile(p);
} }
// flush (cflush) // flush (cflush)
pub unsafe fn flush(p: *const u8) -> () { pub unsafe fn flush(p: *const u8) {
arch_x86::_mm_clflush(p); arch_x86::_mm_clflush(p);
} }

View File

@ -46,7 +46,7 @@ const DISABLE_INTERRUPTS: u8 = 0x00; //
const DLAB: u8 = 0x80; const DLAB: u8 = 0x80;
const BASE_RATE: u32 = 115200; const BASE_RATE: u32 = 115_200;
const DIVISOR: u16 = 0x03; // The baud rate is 38400 const DIVISOR: u16 = 0x03; // The baud rate is 38400

View File

@ -6,7 +6,7 @@ use x86_64::{
}; };
pub const HEAP_START: usize = 0x4444_4444_0000; pub const HEAP_START: usize = 0x4444_4444_0000;
pub const HEAP_SIZE: usize = 0x1 << 20; // 1MB Heap pub const HEAP_SIZE: usize = 1 << 20; // 1MB Heap
pub fn init_heap( pub fn init_heap(
mapper: &mut impl Mapper<Size4KiB>, mapper: &mut impl Mapper<Size4KiB>,

View File

@ -9,13 +9,10 @@
extern crate alloc; extern crate alloc;
use bootloader::{entry_point, BootInfo}; use bootloader::{entry_point, BootInfo};
use cache_utils;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use dendrobates_tinctoreus_azureus::allocator; use dendrobates_tinctoreus_azureus::allocator;
use polling_serial::serial_println; use polling_serial::serial_println;
use vga_buffer; // required for custom panic handler use vga_buffer::println;
use vga_buffer::{print, println};
use x86_64;
use core::cmp::Ord; use core::cmp::Ord;
use core::ops::Sub; use core::ops::Sub;
@ -23,8 +20,17 @@ use core::ops::Sub;
#[cfg(not(test))] #[cfg(not(test))]
use dendrobates_tinctoreus_azureus::hlt_loop; use dendrobates_tinctoreus_azureus::hlt_loop;
use bootloader::bootinfo::MemoryRegionType::{InUse, Usable};
use bootloader::bootinfo::{FrameRange, MemoryMap, MemoryRegion};
use dendrobates_tinctoreus_azureus::memory;
#[cfg(not(test))] #[cfg(not(test))]
use vga_buffer::{set_colors, Color, ForegroundColor}; use vga_buffer::{set_colors, Color, ForegroundColor};
use x86_64::structures::paging::frame::PhysFrameRange;
use x86_64::structures::paging::{
Mapper, Page, PageSize, PageTableFlags, PhysFrame, Size4KiB, UnusedPhysFrame,
};
use x86_64::PhysAddr;
use x86_64::VirtAddr;
// Custom panic handler, required for freestanding program // Custom panic handler, required for freestanding program
#[cfg(not(test))] #[cfg(not(test))]
@ -104,12 +110,6 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
cache_utils::prefetcher::prefetcher_status() cache_utils::prefetcher::prefetcher_status()
); );
print!("Testing reverse range:");
for i in (0..2).rev() {
print!(" {}", i);
}
println!();
let threshold_access_p = cache_utils::calibration::calibrate_access(); let threshold_access_p = cache_utils::calibration::calibrate_access();
let threshold_flush_p = cache_utils::calibration::calibrate_flush(); let threshold_flush_p = cache_utils::calibration::calibrate_flush();
cache_utils::prefetcher::enable_prefetchers(false); cache_utils::prefetcher::enable_prefetchers(false);

View File

@ -55,7 +55,7 @@ pub fn create_example_mapping(
/// A FrameAllocator that returns usable frames from the bootloader's memory map. /// A FrameAllocator that returns usable frames from the bootloader's memory map.
pub struct BootInfoFrameAllocator { pub struct BootInfoFrameAllocator {
memory_map: &'static MemoryMap, memory_map: MemoryMap,
next: usize, next: usize,
} }
@ -65,14 +65,14 @@ impl BootInfoFrameAllocator {
/// This function is unsafe because the caller must guarantee that the passed /// This function is unsafe because the caller must guarantee that the passed
/// memory map is valid. The main requirement is that all frames that are marked /// memory map is valid. The main requirement is that all frames that are marked
/// as `USABLE` in it are really unused. /// as `USABLE` in it are really unused.
pub unsafe fn init(memory_map: &'static MemoryMap) -> Self { pub unsafe fn init(memory_map: MemoryMap) -> Self {
BootInfoFrameAllocator { BootInfoFrameAllocator {
memory_map, memory_map,
next: 0, next: 0,
} }
} }
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> { fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> + '_ {
// get usable regions from memory map // get usable regions from memory map
let regions = self.memory_map.iter(); let regions = self.memory_map.iter();
let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable); let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable);
@ -81,8 +81,7 @@ impl BootInfoFrameAllocator {
// transform to an iterator of frame start addresses // transform to an iterator of frame start addresses
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096)); // TODO Magic number, this is where 4k pages are enforced let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096)); // TODO Magic number, this is where 4k pages are enforced
// create `PhysFrame` types from the start addresses // create `PhysFrame` types from the start addresses
let frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))); frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)))
frames
} }
} }