Rm spin::Mutex except for easy-fs & add new test huge_write & flush cache to disk after a write transaction
This commit is contained in:
parent
569e2fe2fe
commit
b8a14182cd
36 changed files with 339 additions and 229 deletions
|
@ -13,7 +13,7 @@ use k210_soc::{
|
|||
sysctl,
|
||||
sleep::usleep,
|
||||
};
|
||||
use spin::Mutex;
|
||||
use crate::sync::UPSafeCell;
|
||||
use lazy_static::*;
|
||||
use super::BlockDevice;
|
||||
use core::convert::TryInto;
|
||||
|
@ -711,7 +711,9 @@ fn io_init() {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref PERIPHERALS: Mutex<Peripherals> = Mutex::new(Peripherals::take().unwrap());
|
||||
static ref PERIPHERALS: UPSafeCell<Peripherals> = unsafe {
|
||||
UPSafeCell::new(Peripherals::take().unwrap())
|
||||
};
|
||||
}
|
||||
|
||||
fn init_sdcard() -> SDCard<SPIImpl<SPI0>> {
|
||||
|
@ -735,19 +737,19 @@ fn init_sdcard() -> SDCard<SPIImpl<SPI0>> {
|
|||
sd
|
||||
}
|
||||
|
||||
pub struct SDCardWrapper(Mutex<SDCard<SPIImpl<SPI0>>>);
|
||||
pub struct SDCardWrapper(UPSafeCell<SDCard<SPIImpl<SPI0>>>);
|
||||
|
||||
impl SDCardWrapper {
|
||||
pub fn new() -> Self {
|
||||
Self(Mutex::new(init_sdcard()))
|
||||
unsafe { Self(UPSafeCell::new(init_sdcard())) }
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockDevice for SDCardWrapper {
|
||||
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
|
||||
self.0.lock().read_sector(buf,block_id as u32).unwrap();
|
||||
self.0.exclusive_access().read_sector(buf,block_id as u32).unwrap();
|
||||
}
|
||||
fn write_block(&self, block_id: usize, buf: &[u8]) {
|
||||
self.0.lock().write_sector(buf,block_id as u32).unwrap();
|
||||
self.0.exclusive_access().write_sector(buf,block_id as u32).unwrap();
|
||||
}
|
||||
}
|
|
@ -12,34 +12,42 @@ use crate::mm::{
|
|||
kernel_token,
|
||||
};
|
||||
use super::BlockDevice;
|
||||
use spin::Mutex;
|
||||
use crate::sync::UPSafeCell;
|
||||
use alloc::vec::Vec;
|
||||
use lazy_static::*;
|
||||
|
||||
#[allow(unused)]
|
||||
const VIRTIO0: usize = 0x10001000;
|
||||
|
||||
pub struct VirtIOBlock(Mutex<VirtIOBlk<'static>>);
|
||||
pub struct VirtIOBlock(UPSafeCell<VirtIOBlk<'static>>);
|
||||
|
||||
lazy_static! {
|
||||
static ref QUEUE_FRAMES: Mutex<Vec<FrameTracker>> = Mutex::new(Vec::new());
|
||||
static ref QUEUE_FRAMES: UPSafeCell<Vec<FrameTracker>> = unsafe {
|
||||
UPSafeCell::new(Vec::new())
|
||||
};
|
||||
}
|
||||
|
||||
impl BlockDevice for VirtIOBlock {
|
||||
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
|
||||
self.0.lock().read_block(block_id, buf).expect("Error when reading VirtIOBlk");
|
||||
self.0.exclusive_access()
|
||||
.read_block(block_id, buf)
|
||||
.expect("Error when reading VirtIOBlk");
|
||||
}
|
||||
fn write_block(&self, block_id: usize, buf: &[u8]) {
|
||||
self.0.lock().write_block(block_id, buf).expect("Error when writing VirtIOBlk");
|
||||
self.0.exclusive_access()
|
||||
.write_block(block_id, buf)
|
||||
.expect("Error when writing VirtIOBlk");
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtIOBlock {
|
||||
#[allow(unused)]
|
||||
pub fn new() -> Self {
|
||||
Self(Mutex::new(VirtIOBlk::new(
|
||||
unsafe { &mut *(VIRTIO0 as *mut VirtIOHeader) }
|
||||
).unwrap()))
|
||||
unsafe {
|
||||
Self(UPSafeCell::new(VirtIOBlk::new(
|
||||
&mut *(VIRTIO0 as *mut VirtIOHeader)
|
||||
).unwrap()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +58,7 @@ pub extern "C" fn virtio_dma_alloc(pages: usize) -> PhysAddr {
|
|||
let frame = frame_alloc().unwrap();
|
||||
if i == 0 { ppn_base = frame.ppn; }
|
||||
assert_eq!(frame.ppn.0, ppn_base.0 + i);
|
||||
QUEUE_FRAMES.lock().push(frame);
|
||||
QUEUE_FRAMES.exclusive_access().push(frame);
|
||||
}
|
||||
ppn_base.into()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue