Make clippy happier
This commit is contained in:
parent
f3f7aad23c
commit
44b0aaf372
@ -1,8 +1,8 @@
|
||||
use crate::{flush, maccess, rdtsc_fence};
|
||||
use polling_serial::serial_println;
|
||||
use vga_buffer::println;
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use core::cmp::min;
|
||||
|
||||
@ -13,32 +13,28 @@ use core::cmp::min;
|
||||
unsafe fn only_reload(p: *const u8) -> u64 {
|
||||
let t = rdtsc_fence();
|
||||
maccess(p);
|
||||
let d = rdtsc_fence() - t;
|
||||
d
|
||||
rdtsc_fence() - t
|
||||
}
|
||||
|
||||
unsafe fn flush_and_reload(p: *const u8) -> u64 {
|
||||
flush(p);
|
||||
let t = rdtsc_fence();
|
||||
maccess(p);
|
||||
let d = rdtsc_fence() - t;
|
||||
d
|
||||
rdtsc_fence() - t
|
||||
}
|
||||
|
||||
unsafe fn load_and_flush(p: *const u8) -> u64 {
|
||||
maccess(p);
|
||||
let t = rdtsc_fence();
|
||||
flush(p);
|
||||
let d = rdtsc_fence() - t;
|
||||
d
|
||||
rdtsc_fence() - t
|
||||
}
|
||||
|
||||
unsafe fn flush_and_flush(p: *const u8) -> u64 {
|
||||
flush(p);
|
||||
let t = rdtsc_fence();
|
||||
flush(p);
|
||||
let d = rdtsc_fence() - t;
|
||||
d
|
||||
rdtsc_fence() - t
|
||||
}
|
||||
|
||||
const BUCKET_SIZE: usize = 5;
|
||||
@ -57,19 +53,13 @@ pub fn calibrate_access() -> u64 {
|
||||
// Histograms bucket of 5 and max at 400 cycles
|
||||
// Magic numbers to be justified
|
||||
// 80 is a size of screen
|
||||
let mut hit_histogram = Vec::<u32>::with_capacity(BUCKET_NUMBER);
|
||||
hit_histogram.resize(BUCKET_NUMBER, 0);
|
||||
let mut hit_histogram = vec![0; BUCKET_NUMBER]; //Vec::<u32>::with_capacity(BUCKET_NUMBER);
|
||||
//hit_histogram.resize(BUCKET_NUMBER, 0);
|
||||
|
||||
let mut miss_histogram = hit_histogram.clone();
|
||||
|
||||
// the address in memory we are going to target
|
||||
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
|
||||
unsafe { maccess(pointer) };
|
||||
@ -136,19 +126,12 @@ pub fn calibrate_flush() -> u64 {
|
||||
// Histograms bucket of 5 and max at 400 cycles
|
||||
// Magic numbers to be justified
|
||||
// 80 is a size of screen
|
||||
let mut hit_histogram = Vec::<u32>::with_capacity(CFLUSH_BUCKET_NUMBER);
|
||||
hit_histogram.resize(CFLUSH_BUCKET_NUMBER, 0);
|
||||
let mut hit_histogram = vec![0; CFLUSH_BUCKET_NUMBER];
|
||||
|
||||
let mut miss_histogram = hit_histogram.clone();
|
||||
|
||||
// the address in memory we are going to target
|
||||
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
|
||||
for _ in 0..(4 << 20) {
|
||||
|
@ -19,12 +19,12 @@ pub unsafe fn rdtsc_fence() -> u64 {
|
||||
tsc
|
||||
}
|
||||
|
||||
pub unsafe fn maccess<T>(p: *const T) -> () {
|
||||
pub unsafe fn maccess<T>(p: *const T) {
|
||||
ptr::read_volatile(p);
|
||||
}
|
||||
|
||||
// flush (cflush)
|
||||
pub unsafe fn flush(p: *const u8) -> () {
|
||||
pub unsafe fn flush(p: *const u8) {
|
||||
arch_x86::_mm_clflush(p);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ const DISABLE_INTERRUPTS: u8 = 0x00; //
|
||||
|
||||
const DLAB: u8 = 0x80;
|
||||
|
||||
const BASE_RATE: u32 = 115200;
|
||||
const BASE_RATE: u32 = 115_200;
|
||||
|
||||
const DIVISOR: u16 = 0x03; // The baud rate is 38400
|
||||
|
||||
|
@ -6,7 +6,7 @@ use x86_64::{
|
||||
};
|
||||
|
||||
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(
|
||||
mapper: &mut impl Mapper<Size4KiB>,
|
||||
|
20
src/main.rs
20
src/main.rs
@ -9,13 +9,10 @@
|
||||
extern crate alloc;
|
||||
|
||||
use bootloader::{entry_point, BootInfo};
|
||||
use cache_utils;
|
||||
use core::panic::PanicInfo;
|
||||
use dendrobates_tinctoreus_azureus::allocator;
|
||||
use polling_serial::serial_println;
|
||||
use vga_buffer; // required for custom panic handler
|
||||
use vga_buffer::{print, println};
|
||||
use x86_64;
|
||||
use vga_buffer::println;
|
||||
|
||||
use core::cmp::Ord;
|
||||
use core::ops::Sub;
|
||||
@ -23,8 +20,17 @@ use core::ops::Sub;
|
||||
#[cfg(not(test))]
|
||||
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))]
|
||||
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
|
||||
#[cfg(not(test))]
|
||||
@ -104,12 +110,6 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
||||
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_flush_p = cache_utils::calibration::calibrate_flush();
|
||||
cache_utils::prefetcher::enable_prefetchers(false);
|
||||
|
@ -55,7 +55,7 @@ pub fn create_example_mapping(
|
||||
|
||||
/// A FrameAllocator that returns usable frames from the bootloader's memory map.
|
||||
pub struct BootInfoFrameAllocator {
|
||||
memory_map: &'static MemoryMap,
|
||||
memory_map: MemoryMap,
|
||||
next: usize,
|
||||
}
|
||||
|
||||
@ -65,14 +65,14 @@ impl BootInfoFrameAllocator {
|
||||
/// 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
|
||||
/// 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 {
|
||||
memory_map,
|
||||
next: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
|
||||
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> + '_ {
|
||||
// get usable regions from memory map
|
||||
let regions = self.memory_map.iter();
|
||||
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
|
||||
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
|
||||
let frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)));
|
||||
frames
|
||||
frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user