diff --git a/os/src/drivers/block/virtio_blk.rs b/os/src/drivers/block/virtio_blk.rs index a30e3bf8..75e69c17 100644 --- a/os/src/drivers/block/virtio_blk.rs +++ b/os/src/drivers/block/virtio_blk.rs @@ -20,7 +20,8 @@ pub struct VirtIOBlock { } lazy_static! { - static ref QUEUE_FRAMES: UPIntrFreeCell> = unsafe { UPIntrFreeCell::new(Vec::new()) }; + static ref QUEUE_FRAMES: UPIntrFreeCell> = + unsafe { UPIntrFreeCell::new(Vec::new()) }; } impl BlockDevice for VirtIOBlock { diff --git a/os/src/drivers/chardev/ns16550a.rs b/os/src/drivers/chardev/ns16550a.rs index 81e3878b..da290633 100644 --- a/os/src/drivers/chardev/ns16550a.rs +++ b/os/src/drivers/chardev/ns16550a.rs @@ -1,7 +1,6 @@ ///! Ref: https://www.lammertbies.nl/comm/info/serial-uart ///! Ref: ns16550a datasheet: https://datasheetspdf.com/pdf-file/605590/NationalSemiconductor/NS16550A/1 ///! Ref: ns16450 datasheet: https://datasheetspdf.com/pdf-file/1311818/NationalSemiconductor/NS16450/1 - use super::CharDevice; use crate::sync::{Condvar, UPIntrFreeCell}; use crate::task::schedule; diff --git a/os/src/main.rs b/os/src/main.rs index a9323be1..3c23069b 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -46,7 +46,8 @@ use lazy_static::*; use sync::UPIntrFreeCell; lazy_static! { - pub static ref DEV_NON_BLOCKING_ACCESS: UPIntrFreeCell = unsafe { UPIntrFreeCell::new(false) }; + pub static ref DEV_NON_BLOCKING_ACCESS: UPIntrFreeCell = + unsafe { UPIntrFreeCell::new(false) }; } #[no_mangle] diff --git a/os/src/sync/condvar.rs b/os/src/sync/condvar.rs index c50a53e2..714782c2 100644 --- a/os/src/sync/condvar.rs +++ b/os/src/sync/condvar.rs @@ -1,5 +1,8 @@ use crate::sync::{Mutex, UPIntrFreeCell}; -use crate::task::{add_task, block_current_task, block_current_and_run_next, current_task, TaskControlBlock, TaskContext}; +use crate::task::{ + add_task, block_current_and_run_next, block_current_task, current_task, TaskContext, + TaskControlBlock, +}; use alloc::{collections::VecDeque, sync::Arc}; pub struct Condvar { diff --git a/os/src/sync/up.rs b/os/src/sync/up.rs index 3600271a..6c7a0f4a 100644 --- a/os/src/sync/up.rs +++ b/os/src/sync/up.rs @@ -1,7 +1,7 @@ use core::cell::{RefCell, RefMut, UnsafeCell}; use core::ops::{Deref, DerefMut}; -use riscv::register::sstatus; use lazy_static::*; +use riscv::register::sstatus; /* /// Wrap a static data structure inside it so that we are @@ -56,9 +56,8 @@ pub struct IntrMaskingInfo { } lazy_static! { - static ref INTR_MASKING_INFO: UPSafeCellRaw = unsafe { - UPSafeCellRaw::new(IntrMaskingInfo::new()) - }; + static ref INTR_MASKING_INFO: UPSafeCellRaw = + unsafe { UPSafeCellRaw::new(IntrMaskingInfo::new()) }; } impl IntrMaskingInfo { @@ -71,7 +70,9 @@ impl IntrMaskingInfo { pub fn enter(&mut self) { let sie = sstatus::read().sie(); - unsafe { sstatus::clear_sie(); } + unsafe { + sstatus::clear_sie(); + } if self.nested_level == 0 { self.sie_before_masking = sie; } @@ -81,7 +82,9 @@ impl IntrMaskingInfo { pub fn exit(&mut self) { self.nested_level -= 1; if self.nested_level == 0 && self.sie_before_masking { - unsafe { sstatus::set_sie(); } + unsafe { + sstatus::set_sie(); + } } } } @@ -101,14 +104,17 @@ impl UPIntrFreeCell { inner: RefCell::new(value), } } - + /// Panic if the data has been borrowed. pub fn exclusive_access(&self) -> UPIntrRefMut<'_, T> { INTR_MASKING_INFO.get_mut().enter(); UPIntrRefMut(Some(self.inner.borrow_mut())) } - pub fn exclusive_session(&self, f: F) -> V where F: FnOnce(&mut T) -> V { + pub fn exclusive_session(&self, f: F) -> V + where + F: FnOnce(&mut T) -> V, + { let mut inner = self.exclusive_access(); f(inner.deref_mut()) } @@ -132,4 +138,3 @@ impl<'a, T> DerefMut for UPIntrRefMut<'a, T> { self.0.as_mut().unwrap().deref_mut() } } - diff --git a/os/src/task/mod.rs b/os/src/task/mod.rs index 6b4082b4..9f8e3b10 100644 --- a/os/src/task/mod.rs +++ b/os/src/task/mod.rs @@ -26,7 +26,6 @@ pub use processor::{ pub use signal::SignalFlags; pub use task::{TaskControlBlock, TaskStatus}; - pub fn suspend_current_and_run_next() { // There must be an application running. let task = take_current_task().unwrap(); @@ -54,7 +53,7 @@ pub fn block_current_task() -> *mut TaskContext { } pub fn block_current_and_run_next() { - let task_cx_ptr = block_current_task(); + let task_cx_ptr = block_current_task(); schedule(task_cx_ptr); } diff --git a/os/src/task/processor.rs b/os/src/task/processor.rs index f196f681..dfa7d4c5 100644 --- a/os/src/task/processor.rs +++ b/os/src/task/processor.rs @@ -30,7 +30,8 @@ impl Processor { } lazy_static! { - pub static ref PROCESSOR: UPIntrFreeCell = unsafe { UPIntrFreeCell::new(Processor::new()) }; + pub static ref PROCESSOR: UPIntrFreeCell = + unsafe { UPIntrFreeCell::new(Processor::new()) }; } pub fn run_tasks() { @@ -94,9 +95,8 @@ pub fn current_kstack_top() -> usize { } pub fn schedule(switched_task_cx_ptr: *mut TaskContext) { - let idle_task_cx_ptr = PROCESSOR.exclusive_session(|processor| { - processor.get_idle_task_cx_ptr() - }); + let idle_task_cx_ptr = + PROCESSOR.exclusive_session(|processor| processor.get_idle_task_cx_ptr()); unsafe { __switch(switched_task_cx_ptr, idle_task_cx_ptr); } diff --git a/os/src/task/task.rs b/os/src/task/task.rs index 85d949f8..c620890e 100644 --- a/os/src/task/task.rs +++ b/os/src/task/task.rs @@ -1,7 +1,10 @@ use super::id::TaskUserRes; use super::{kstack_alloc, KernelStack, ProcessControlBlock, TaskContext}; use crate::trap::TrapContext; -use crate::{mm::PhysPageNum, sync::{UPIntrFreeCell, UPIntrRefMut}}; +use crate::{ + mm::PhysPageNum, + sync::{UPIntrFreeCell, UPIntrRefMut}, +}; use alloc::sync::{Arc, Weak}; pub struct TaskControlBlock { diff --git a/os/src/trap/mod.rs b/os/src/trap/mod.rs index 5eb417dc..ce2aae8e 100644 --- a/os/src/trap/mod.rs +++ b/os/src/trap/mod.rs @@ -11,7 +11,7 @@ use core::arch::{asm, global_asm}; use riscv::register::{ mtvec::TrapMode, scause::{self, Exception, Interrupt, Trap}, - sie, stval, stvec, sstatus, sscratch, + sie, sscratch, sstatus, stval, stvec, }; global_asm!(include_str!("trap.S")); @@ -23,7 +23,7 @@ pub fn init() { fn set_kernel_trap_entry() { extern "C" { fn __alltraps(); - fn __alltraps_k(); + fn __alltraps_k(); } let __alltraps_k_va = __alltraps_k as usize - __alltraps as usize + TRAMPOLINE; unsafe { @@ -52,7 +52,7 @@ fn enable_supervisor_interrupt() { fn disable_supervisor_interrupt() { unsafe { - sstatus::clear_sie(); + sstatus::clear_sie(); } } @@ -67,7 +67,7 @@ pub fn trap_handler() -> ! { // jump to next instruction anyway let mut cx = current_trap_cx(); cx.sepc += 4; - + enable_supervisor_interrupt(); // get system call return value @@ -150,19 +150,19 @@ pub fn trap_from_kernel(_trap_cx: &TrapContext) { match scause.cause() { Trap::Interrupt(Interrupt::SupervisorExternal) => { crate::board::irq_handler(); - }, + } Trap::Interrupt(Interrupt::SupervisorTimer) => { set_next_trigger(); check_timer(); // do not schedule now - }, + } _ => { panic!( "Unsupported trap from kernel: {:?}, stval = {:#x}!", scause.cause(), stval ); - }, + } } } diff --git a/user/src/bin/huge_write_mt.rs b/user/src/bin/huge_write_mt.rs index 63146a58..8ca75783 100644 --- a/user/src/bin/huge_write_mt.rs +++ b/user/src/bin/huge_write_mt.rs @@ -5,9 +5,9 @@ extern crate user_lib; extern crate alloc; -use alloc::{vec::Vec, string::String, fmt::format}; +use alloc::{fmt::format, string::String, vec::Vec}; +use user_lib::{close, get_time, gettid, open, write, OpenFlags}; use user_lib::{exit, thread_create, waittid}; -use user_lib::{close, get_time, open, write, OpenFlags, gettid}; fn worker(size_kib: usize) { let mut buffer = [0u8; 1024]; // 1KiB @@ -17,11 +17,11 @@ fn worker(size_kib: usize) { let filename = format(format_args!("testf{}\0", gettid())); let f = open(filename.as_str(), OpenFlags::CREATE | OpenFlags::WRONLY); if f < 0 { - panic!("Open test file failed!"); + panic!("Open test file failed!"); } let f = f as usize; for _ in 0..size_kib { - write(f, &buffer); + write(f, &buffer); } close(f); exit(0) @@ -34,18 +34,18 @@ pub fn main(argc: usize, argv: &[&str]) -> i32 { let size_kb = size_mb << 10; let workers = argv[1].parse::().expect("wrong argument"); assert!(workers >= 1 && size_kb % workers == 0, "wrong argument"); - + let start = get_time(); - + let mut v = Vec::new(); let size_mb = 1usize; for _ in 0..workers { - v.push(thread_create(worker as usize, size_kb / workers)); + v.push(thread_create(worker as usize, size_kb / workers)); } for tid in v.iter() { assert_eq!(0, waittid(*tid as usize)); } - + let time_ms = (get_time() - start) as usize; let speed_kbs = size_kb * 1000 / time_ms; println!( diff --git a/user/src/bin/usertests.rs b/user/src/bin/usertests.rs index 89f3ce51..32b28f6f 100644 --- a/user/src/bin/usertests.rs +++ b/user/src/bin/usertests.rs @@ -17,9 +17,7 @@ static SUCC_TESTS: &[&str] = &[ "yield\0", ]; -static FAIL_TESTS: &[&str] = &[ - "stack_overflow\0", -]; +static FAIL_TESTS: &[&str] = &["stack_overflow\0"]; use user_lib::{exec, fork, waitpid};