From 5eae9509bb765b88f023090b4a5517053fb6af04 Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Fri, 20 May 2022 08:59:47 +0800 Subject: [PATCH] add cargo fmt in Makefile, and exec make fmt --- Makefile | 2 ++ os/src/board/qemu.rs | 19 +++++++++---------- os/src/console.rs | 2 +- os/src/drivers/block/mod.rs | 2 +- os/src/fs/easy_fs/efs.rs | 2 +- os/src/fs/inode.rs | 2 +- os/src/fs/mod.rs | 4 ++-- os/src/main.rs | 2 +- os/src/mm/frame_allocator.rs | 2 +- os/src/mm/memory_set.rs | 23 ++++++++++++++++++----- os/src/sync/up.rs | 2 +- os/src/syscall/fs.rs | 12 ++++++------ os/src/syscall/mod.rs | 16 ++++++++++------ os/src/syscall/process.rs | 8 ++++++-- os/src/task/id.rs | 8 ++++---- os/src/task/manager.rs | 4 ++-- os/src/task/mod.rs | 12 +++++++++--- os/src/task/process.rs | 12 +++++++++--- os/src/timer.rs | 2 +- user/src/bin/eisenberg.rs | 25 +++++++++++++++---------- user/src/bin/forktree.rs | 6 +++--- user/src/bin/peterson.rs | 8 ++++---- user/src/bin/usertests.rs | 8 ++++++-- user/src/lib.rs | 9 +++++---- 24 files changed, 118 insertions(+), 74 deletions(-) diff --git a/Makefile b/Makefile index 2e339762..a657cd92 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,5 @@ docker: build_docker: docker build -t ${DOCKER_NAME} . +fmt: + cd easy-fs; cargo fmt; cd ../easy-fs-fuse cargo fmt; cd ../os ; cargo fmt; cd ../user; cargo fmt; cd .. \ No newline at end of file diff --git a/os/src/board/qemu.rs b/os/src/board/qemu.rs index 441c7d57..db76333f 100644 --- a/os/src/board/qemu.rs +++ b/os/src/board/qemu.rs @@ -1,10 +1,10 @@ pub const CLOCK_FREQ: usize = 12500000; pub const MMIO: &[(usize, usize)] = &[ - (0x1000_0000, 0x1000), // VIRT_UART0 in virt machine - (0x1000_1000, 0x1000), // VIRT_VIRTIO in virt machine - (0x0C00_0000, 0x40_0000), // VIRT_PLIC in virt machine - (0x0010_0000, 0x00_2000), // VIRT_TEST/RTC in virt machine + (0x1000_0000, 0x1000), // VIRT_UART0 in virt machine + (0x1000_1000, 0x1000), // VIRT_VIRTIO in virt machine + (0x0C00_0000, 0x40_0000), // VIRT_PLIC in virt machine + (0x0010_0000, 0x00_2000), // VIRT_TEST/RTC in virt machine ]; pub type BlockDeviceImpl = crate::drivers::block::VirtIOBlock; @@ -19,7 +19,7 @@ use crate::drivers::plic::{IntrTargetPriority, PLIC}; pub fn device_init() { use riscv::register::sie; - + kprintln!("[KERN] board::qemu::device_init() begin"); let mut plic = unsafe { PLIC::new(VIRT_PLIC) }; let hart_id: usize = 0; @@ -54,8 +54,8 @@ use core::arch::asm; const EXIT_SUCCESS: u32 = 0x5555; // Equals `exit(0)`. qemu successful exit const EXIT_FAILURE_FLAG: u32 = 0x3333; -const EXIT_FAILURE: u32 = exit_code_encode(1); // Equals `exit(1)`. qemu failed exit -const EXIT_RESET: u32 = 0x7777; // qemu reset +const EXIT_FAILURE: u32 = exit_code_encode(1); // Equals `exit(1)`. qemu failed exit +const EXIT_RESET: u32 = 0x7777; // qemu reset pub trait QEMUExit { /// Exit with specified return code. @@ -72,7 +72,6 @@ pub trait QEMUExit { fn exit_failure(&self) -> !; } - /// RISCV64 configuration pub struct RISCV64 { /// Address of the sifive_test mapped device. @@ -125,6 +124,6 @@ impl QEMUExit for RISCV64 { } } -const VIRT_TEST: u64 =0x100000; +const VIRT_TEST: u64 = 0x100000; -pub const QEMU_EXIT_HANDLE: RISCV64 = RISCV64::new(VIRT_TEST); +pub const QEMU_EXIT_HANDLE: RISCV64 = RISCV64::new(VIRT_TEST); diff --git a/os/src/console.rs b/os/src/console.rs index 3ae0f908..acfdc90d 100644 --- a/os/src/console.rs +++ b/os/src/console.rs @@ -58,4 +58,4 @@ macro_rules! kprintln { ($fmt: literal $(, $($arg: tt)+)?) => { $crate::console::kprint(format_args!(concat!($fmt, "\n") $(, $($arg)+)?)); } -} \ No newline at end of file +} diff --git a/os/src/drivers/block/mod.rs b/os/src/drivers/block/mod.rs index fbd5de9d..1ac1c187 100644 --- a/os/src/drivers/block/mod.rs +++ b/os/src/drivers/block/mod.rs @@ -5,8 +5,8 @@ mod virtio_blk; pub use virtio_blk::VirtIOBlock; use crate::board::BlockDeviceImpl; -use alloc::sync::Arc; use crate::fs::easy_fs::BlockDevice; +use alloc::sync::Arc; use lazy_static::*; lazy_static! { diff --git a/os/src/fs/easy_fs/efs.rs b/os/src/fs/easy_fs/efs.rs index 586bba40..53446b81 100644 --- a/os/src/fs/easy_fs/efs.rs +++ b/os/src/fs/easy_fs/efs.rs @@ -1,8 +1,8 @@ +use super::BLOCK_SZ; use super::{ block_cache_sync_all, get_block_cache, Bitmap, BlockDevice, DiskInode, DiskInodeType, Inode, SuperBlock, }; -use super::BLOCK_SZ; use alloc::sync::Arc; use spin::Mutex; diff --git a/os/src/fs/inode.rs b/os/src/fs/inode.rs index a3601084..a642bd51 100644 --- a/os/src/fs/inode.rs +++ b/os/src/fs/inode.rs @@ -1,3 +1,4 @@ +use super::easy_fs::{EasyFileSystem, Inode}; use super::File; use crate::drivers::BLOCK_DEVICE; use crate::mm::UserBuffer; @@ -5,7 +6,6 @@ use crate::sync::UPIntrFreeCell; use alloc::sync::Arc; use alloc::vec::Vec; use bitflags::*; -use super::easy_fs::{EasyFileSystem, Inode}; use lazy_static::*; pub struct OSInode { diff --git a/os/src/fs/mod.rs b/os/src/fs/mod.rs index 5318b2b6..d71c5758 100644 --- a/os/src/fs/mod.rs +++ b/os/src/fs/mod.rs @@ -1,7 +1,7 @@ +pub mod easy_fs; mod inode; mod pipe; mod stdio; -pub mod easy_fs; use crate::mm::UserBuffer; pub trait File: Send + Sync { @@ -11,7 +11,7 @@ pub trait File: Send + Sync { fn write(&self, buf: UserBuffer) -> usize; } +pub use easy_fs::*; pub use inode::{list_apps, open_file, OSInode, OpenFlags}; pub use pipe::{make_pipe, Pipe}; pub use stdio::{Stdin, Stdout}; -pub use easy_fs::*; \ No newline at end of file diff --git a/os/src/main.rs b/os/src/main.rs index f86c74fd..eb7cd533 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -17,6 +17,7 @@ extern crate bitflags; #[macro_use] mod console; +mod board; mod config; mod drivers; mod fs; @@ -28,7 +29,6 @@ mod syscall; mod task; mod timer; mod trap; -mod board; // use board::*; core::arch::global_asm!(include_str!("entry.asm")); diff --git a/os/src/mm/frame_allocator.rs b/os/src/mm/frame_allocator.rs index a4602d2d..56d840c7 100644 --- a/os/src/mm/frame_allocator.rs +++ b/os/src/mm/frame_allocator.rs @@ -85,7 +85,7 @@ impl FrameAllocator for StackFrameAllocator { type FrameAllocatorImpl = StackFrameAllocator; lazy_static! { - pub static ref FRAME_ALLOCATOR: UPIntrFreeCell ={ + pub static ref FRAME_ALLOCATOR: UPIntrFreeCell = { kprintln!("[KERN] mm::frame_allocator::lazy_static!FRAME_ALLOCATOR begin"); unsafe { UPIntrFreeCell::new(FrameAllocatorImpl::new()) } }; diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index 11914c18..78353c5c 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -25,7 +25,7 @@ extern "C" { } lazy_static! { - pub static ref KERNEL_SPACE: Arc> ={ + pub static ref KERNEL_SPACE: Arc> = { kprintln!("[KERN] mm::memory_set::lazy_static!KERNEL_SPACE begin"); Arc::new(unsafe { UPIntrFreeCell::new(MemorySet::new_kernel()) }) }; @@ -95,9 +95,18 @@ impl MemorySet { // map trampoline memory_set.map_trampoline(); // map kernel sections - println!("[KERN] .text [{:#x}, {:#x})", stext as usize, etext as usize); - println!("[KERN] .rodata [{:#x}, {:#x})", srodata as usize, erodata as usize); - println!("[KERN] .data [{:#x}, {:#x})", sdata as usize, edata as usize); + println!( + "[KERN] .text [{:#x}, {:#x})", + stext as usize, etext as usize + ); + println!( + "[KERN] .rodata [{:#x}, {:#x})", + srodata as usize, erodata as usize + ); + println!( + "[KERN] .data [{:#x}, {:#x})", + sdata as usize, edata as usize + ); println!( "[KERN] .bss [{:#x}, {:#x})", sbss_with_stack as usize, ebss as usize @@ -271,7 +280,11 @@ impl MapArea { kprintln!("[KERN] mm::memory_set::MapArea::new() begin"); let start_vpn: VirtPageNum = start_va.floor(); let end_vpn: VirtPageNum = end_va.ceil(); - kprintln!("[KERN] mm::memory_set::MapArea::new(start_vpn: {:?}, end_vpn: {:?}) end", start_vpn, end_vpn); + kprintln!( + "[KERN] mm::memory_set::MapArea::new(start_vpn: {:?}, end_vpn: {:?}) end", + start_vpn, + end_vpn + ); Self { vpn_range: VPNRange::new(start_vpn, end_vpn), data_frames: BTreeMap::new(), diff --git a/os/src/sync/up.rs b/os/src/sync/up.rs index c444e7e2..001c0fcf 100644 --- a/os/src/sync/up.rs +++ b/os/src/sync/up.rs @@ -58,7 +58,7 @@ pub struct IntrMaskingInfo { lazy_static! { static ref INTR_MASKING_INFO: UPSafeCellRaw = unsafe { kprintln!("[KERN] sync::up::lazy_static!INTR_MASKING_INFO begin"); - UPSafeCellRaw::new(IntrMaskingInfo::new()) + UPSafeCellRaw::new(IntrMaskingInfo::new()) }; } diff --git a/os/src/syscall/fs.rs b/os/src/syscall/fs.rs index dd3d23d0..8576826a 100644 --- a/os/src/syscall/fs.rs +++ b/os/src/syscall/fs.rs @@ -4,9 +4,9 @@ use crate::task::{current_process, current_user_token}; use alloc::sync::Arc; pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize { - if fd!=1 && fd!=2 { + if fd != 1 && fd != 2 { kprintln!("[KERN] syscall::fs::sys_write(fd: {}) begin", fd); - } + } let token = current_user_token(); let process = current_process(); let inner = process.inner_exclusive_access(); @@ -27,8 +27,8 @@ pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize { } pub fn sys_read(fd: usize, buf: *const u8, len: usize) -> isize { - if fd!=0 { - kprintln!("[KERN] syscall::fs::sys_read(fd: {}) begin", fd); + if fd != 0 { + kprintln!("[KERN] syscall::fs::sys_read(fd: {}) begin", fd); } let token = current_user_token(); let process = current_process(); @@ -58,7 +58,7 @@ pub fn sys_open(path: *const u8, flags: u32) -> isize { let mut inner = process.inner_exclusive_access(); let fd = inner.alloc_fd(); inner.fd_table[fd] = Some(inode); - kprintln!("[KERN] syscall::fs::sys_open() return fd {}, end",fd); + kprintln!("[KERN] syscall::fs::sys_open() return fd {}, end", fd); fd as isize } else { -1 @@ -66,7 +66,7 @@ pub fn sys_open(path: *const u8, flags: u32) -> isize { } pub fn sys_close(fd: usize) -> isize { - kprintln!("[KERN] syscall::fs::sys_close(fd: {}) begin",fd); + kprintln!("[KERN] syscall::fs::sys_close(fd: {}) begin", fd); let process = current_process(); let mut inner = process.inner_exclusive_access(); if fd >= inner.fd_table.len() { diff --git a/os/src/syscall/mod.rs b/os/src/syscall/mod.rs index a4e12b20..fa604c61 100644 --- a/os/src/syscall/mod.rs +++ b/os/src/syscall/mod.rs @@ -37,11 +37,15 @@ use sync::*; use thread::*; pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize { - if syscall_id !=SYSCALL_YIELD && - syscall_id !=SYSCALL_WAITPID && - !(syscall_id ==SYSCALL_READ && args[0] == 0) && - !(syscall_id ==SYSCALL_WRITE && (args[0] == 1|| args[0] == 2)) { - kprintln!("[KERN] syscall::syscall(id: {}) begin", sys_id_str(syscall_id)); + if syscall_id != SYSCALL_YIELD + && syscall_id != SYSCALL_WAITPID + && !(syscall_id == SYSCALL_READ && args[0] == 0) + && !(syscall_id == SYSCALL_WRITE && (args[0] == 1 || args[0] == 2)) + { + kprintln!( + "[KERN] syscall::syscall(id: {}) begin", + sys_id_str(syscall_id) + ); } match syscall_id { SYSCALL_DUP => sys_dup(args[0]), @@ -106,4 +110,4 @@ pub fn sys_id_str(syscall_id: usize) -> &'static str { SYSCALL_CONDVAR_WAIT => "sys_condvar_wait", _ => "Unsupported syscall_id", } -} \ No newline at end of file +} diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index e54a9e8c..e762a3e7 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -96,13 +96,17 @@ pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize { // ++++ release child PCB }); if let Some((idx, _)) = pair { - kprintln!("[KERN] syscall::process::sys_waitpid(): remove child from PCB's children Vector"); + kprintln!( + "[KERN] syscall::process::sys_waitpid(): remove child from PCB's children Vector" + ); let child = inner.children.remove(idx); // confirm that child will be deallocated after being removed from children list assert_eq!(Arc::strong_count(&child), 1); let found_pid = child.getpid(); // ++++ temporarily access child PCB exclusively - kprintln!("[KERN] syscall::process::sys_waitpid(): get child's exit_code and return child pid"); + kprintln!( + "[KERN] syscall::process::sys_waitpid(): get child's exit_code and return child pid" + ); let exit_code = child.inner_exclusive_access().exit_code; // ++++ release child PCB *translated_refmut(inner.memory_set.token(), exit_code_ptr) = exit_code; diff --git a/os/src/task/id.rs b/os/src/task/id.rs index da9e5776..aca0ad52 100644 --- a/os/src/task/id.rs +++ b/os/src/task/id.rs @@ -47,7 +47,7 @@ lazy_static! { } lazy_static! { - static ref KSTACK_ALLOCATOR: UPIntrFreeCell ={ + static ref KSTACK_ALLOCATOR: UPIntrFreeCell = { kprintln!("[KERN] task::id::lazy_static!KSTACK_ALLOCATOR begin"); unsafe { UPIntrFreeCell::new(RecycleAllocator::new()) } }; @@ -101,7 +101,7 @@ impl Drop for KernelStack { KERNEL_SPACE .exclusive_access() .remove_area_with_start_vpn(kernel_stack_bottom_va.into()); - kprintln!("[KERN] task::id::Drop::drop end"); + kprintln!("[KERN] task::id::Drop::drop end"); } } @@ -201,8 +201,8 @@ impl TaskUserRes { process_inner .memory_set .remove_area_with_start_vpn(trap_cx_bottom_va.into()); - - kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res() end"); + + kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res() end"); } #[allow(unused)] diff --git a/os/src/task/manager.rs b/os/src/task/manager.rs index 354f1bc0..ce947ced 100644 --- a/os/src/task/manager.rs +++ b/os/src/task/manager.rs @@ -24,14 +24,14 @@ impl TaskManager { } lazy_static! { - pub static ref TASK_MANAGER: UPIntrFreeCell ={ + pub static ref TASK_MANAGER: UPIntrFreeCell = { kprintln!("[KERN] task::manager::lazy_static!TASK_MANAGER begin"); unsafe { UPIntrFreeCell::new(TaskManager::new()) } }; } lazy_static! { - pub static ref PID2PCB: UPIntrFreeCell>> ={ + pub static ref PID2PCB: UPIntrFreeCell>> = { kprintln!("[KERN] task::manager::lazy_static!PID2PCB begin"); unsafe { UPIntrFreeCell::new(BTreeMap::new()) } }; diff --git a/os/src/task/mod.rs b/os/src/task/mod.rs index b03a5039..c56ae6dc 100644 --- a/os/src/task/mod.rs +++ b/os/src/task/mod.rs @@ -101,7 +101,9 @@ pub fn exit_current_and_run_next(exit_code: i32) { remove_from_pid2process(pid); let mut process_inner = process.inner_exclusive_access(); // mark this process as a zombie process - kprintln!("[KERN] task::exit_current_and_run_next(): mark this process as a zombie process"); + kprintln!( + "[KERN] task::exit_current_and_run_next(): mark this process as a zombie process" + ); process_inner.is_zombie = true; // record exit code of main process kprintln!("[KERN] task::exit_current_and_run_next(): record exit code in process_inner"); @@ -109,7 +111,9 @@ pub fn exit_current_and_run_next(exit_code: i32) { { // move all child processes under init process - kprintln!("[KERN] task::exit_current_and_run_next(): move all child processes under INITPROC"); + kprintln!( + "[KERN] task::exit_current_and_run_next(): move all child processes under INITPROC" + ); let mut initproc_inner = INITPROC.inner_exclusive_access(); for child in process_inner.children.iter() { child.inner_exclusive_access().parent = Some(Arc::downgrade(&INITPROC)); @@ -130,7 +134,9 @@ pub fn exit_current_and_run_next(exit_code: i32) { } } - kprintln!("[KERN] task::exit_current_and_run_next(): clear children Vector in process_inner"); + kprintln!( + "[KERN] task::exit_current_and_run_next(): clear children Vector in process_inner" + ); // dealloc_tid and dealloc_user_res require access to PCB inner, so we // need to collect those user res first, then release process_inner // for now to avoid deadlock/double borrow problem. diff --git a/os/src/task/process.rs b/os/src/task/process.rs index a64c88bb..ee243043 100644 --- a/os/src/task/process.rs +++ b/os/src/task/process.rs @@ -164,7 +164,9 @@ impl ProcessControlBlock { kprintln!("[KERN] task::process::PCB::exec(): set trap_cx_ppn for this thread"); task_inner.trap_cx_ppn = task_inner.res.as_mut().unwrap().trap_cx_ppn(); // push arguments on user stack - kprintln!("[KERN] task::process::PCB::exec(): push arguments on user stack for this thread"); + kprintln!( + "[KERN] task::process::PCB::exec(): push arguments on user stack for this thread" + ); let mut user_sp = task_inner.res.as_mut().unwrap().ustack_top(); user_sp -= (args.len() + 1) * core::mem::size_of::(); let argv_base = user_sp; @@ -270,12 +272,16 @@ impl ProcessControlBlock { child_inner.tasks.push(Some(Arc::clone(&task))); drop(child_inner); // modify kstack_top in trap_cx of this thread - kprintln!("[KERN] task::process::PCB::fork(): modify child's kstack_top in trap_cx of child"); + kprintln!( + "[KERN] task::process::PCB::fork(): modify child's kstack_top in trap_cx of child" + ); let task_inner = task.inner_exclusive_access(); let trap_cx = task_inner.get_trap_cx(); trap_cx.kernel_sp = task.kstack.get_top(); drop(task_inner); - kprintln!("[KERN] task::process::PCB::fork(): insert in PID2PCB BTreeMap"); + kprintln!( + "[KERN] task::process::PCB::fork(): insert in PID2PCB BTreeMap" + ); insert_into_pid2process(child.getpid(), Arc::clone(&child)); // add this thread to scheduler kprintln!("[KERN] task::process::PCB::fork(): add_task(child task): add child thread to scheduler"); diff --git a/os/src/timer.rs b/os/src/timer.rs index 1702a2ff..402fefbe 100644 --- a/os/src/timer.rs +++ b/os/src/timer.rs @@ -52,7 +52,7 @@ impl Ord for TimerCondVar { } lazy_static! { - static ref TIMERS: UPIntrFreeCell> ={ + static ref TIMERS: UPIntrFreeCell> = { kprintln!("[KERN] timer::lazy_static!TIMERS begin"); unsafe { UPIntrFreeCell::new(BinaryHeap::::new()) } }; diff --git a/user/src/bin/eisenberg.rs b/user/src/bin/eisenberg.rs index f01ea1a2..5f5b3094 100644 --- a/user/src/bin/eisenberg.rs +++ b/user/src/bin/eisenberg.rs @@ -7,16 +7,18 @@ extern crate user_lib; extern crate alloc; extern crate core; -use user_lib::{thread_create, waittid, exit, sleep}; use alloc::vec::Vec; use core::sync::atomic::{AtomicUsize, Ordering}; +use user_lib::{exit, sleep, thread_create, waittid}; const N: usize = 2; const THREAD_NUM: usize = 10; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum FlagState { - Out, Want, In, + Out, + Want, + In, } static mut TURN: usize = 0; @@ -25,7 +27,7 @@ static mut FLAG: [FlagState; THREAD_NUM] = [FlagState::Out; THREAD_NUM]; static GUARD: AtomicUsize = AtomicUsize::new(0); fn critical_test_enter() { - assert_eq!(GUARD.fetch_add(1, Ordering::SeqCst), 0); + assert_eq!(GUARD.fetch_add(1, Ordering::SeqCst), 0); } fn critical_test_claim() { @@ -33,7 +35,7 @@ fn critical_test_claim() { } fn critical_test_exit() { - assert_eq!(GUARD.fetch_sub(1, Ordering::SeqCst), 1); + assert_eq!(GUARD.fetch_sub(1, Ordering::SeqCst), 1); } fn eisenberg_enter_critical(id: usize) { @@ -43,7 +45,7 @@ fn eisenberg_enter_critical(id: usize) { vstore!(&FLAG[id], FlagState::Want); loop { /* check if any with higher priority is `Want` or `In` */ - let mut prior_thread:Option = None; + let mut prior_thread: Option = None; let turn = vload!(&TURN); let ring_id = if id < turn { id + THREAD_NUM } else { id }; // FLAG.iter() may lead to some errors, use for-loop instead @@ -56,8 +58,11 @@ fn eisenberg_enter_critical(id: usize) { if prior_thread.is_none() { break; } - println!("Thread[{}]: prior thread {} exist, sleep and retry", - id, prior_thread.unwrap()); + println!( + "Thread[{}]: prior thread {} exist, sleep and retry", + id, + prior_thread.unwrap() + ); sleep(1); } /* now tentatively claim the resource */ @@ -86,7 +91,7 @@ fn eisenberg_exit_critical(id: usize) { /* find next one who wants to enter and give the turn to it*/ let mut next = id; let ring_id = id + THREAD_NUM; - for i in (id+1)..ring_id { + for i in (id + 1)..ring_id { let idx = i % THREAD_NUM; if vload!(&FLAG[idx]) == FlagState::Want { next = idx; @@ -119,7 +124,7 @@ pub fn main() -> i32 { let mut v = Vec::new(); // TODO: really shuffle assert_eq!(THREAD_NUM, 10); - let shuffle:[usize; 10] = [0, 7, 4, 6, 2, 9, 8, 1, 3, 5]; + let shuffle: [usize; 10] = [0, 7, 4, 6, 2, 9, 8, 1, 3, 5]; for i in 0..THREAD_NUM { v.push(thread_create(thread_fn as usize, shuffle[i])); } @@ -130,4 +135,4 @@ pub fn main() -> i32 { } println!("main thread exited."); 0 -} \ No newline at end of file +} diff --git a/user/src/bin/forktree.rs b/user/src/bin/forktree.rs index 4933f4ee..6b120ee2 100644 --- a/user/src/bin/forktree.rs +++ b/user/src/bin/forktree.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -use user_lib::{exit, fork, getpid, sleep, yield_, wait}; +use user_lib::{exit, fork, getpid, sleep, wait, yield_}; const DEPTH: usize = 4; @@ -28,7 +28,7 @@ fn fork_tree(cur: &str) { fork_child(cur, '0'); fork_child(cur, '1'); let mut exit_code: i32 = 0; - for _ in 0..2{ + for _ in 0..2 { wait(&mut exit_code); } } @@ -37,7 +37,7 @@ fn fork_tree(cur: &str) { pub fn main() -> i32 { fork_tree(""); let mut exit_code: i32 = 0; - for _ in 0..2{ + for _ in 0..2 { wait(&mut exit_code); } sleep(3000); diff --git a/user/src/bin/peterson.rs b/user/src/bin/peterson.rs index 21865e24..55519970 100644 --- a/user/src/bin/peterson.rs +++ b/user/src/bin/peterson.rs @@ -8,9 +8,9 @@ extern crate user_lib; extern crate alloc; extern crate core; -use user_lib::{thread_create, waittid, exit, sleep}; -use core::sync::atomic::{AtomicUsize, Ordering}; use alloc::vec::Vec; +use core::sync::atomic::{AtomicUsize, Ordering}; +use user_lib::{exit, sleep, thread_create, waittid}; const N: usize = 3; static mut TURN: usize = 0; @@ -26,7 +26,7 @@ fn critical_test_claim() { } fn critical_test_exit() { - assert_eq!(GUARD.fetch_sub(1, Ordering::SeqCst), 1); + assert_eq!(GUARD.fetch_sub(1, Ordering::SeqCst), 1); } fn peterson_enter_critical(id: usize, peer_id: usize) { @@ -75,4 +75,4 @@ pub fn main() -> i32 { } println!("main thread exited."); 0 -} \ No newline at end of file +} diff --git a/user/src/bin/usertests.rs b/user/src/bin/usertests.rs index 112f9969..eb706fd5 100644 --- a/user/src/bin/usertests.rs +++ b/user/src/bin/usertests.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -// not in SUCC_TESTS & FAIL_TESTS +// not in SUCC_TESTS & FAIL_TESTS // count_lines, infloop, user_shell, usertests // item of TESTS : app_name(argv_0), argv_1, argv_2, argv_3, exit_code @@ -115,7 +115,11 @@ pub fn main() -> i32 { let succ_num = run_tests(SUCC_TESTS); let err_num = run_tests(FAIL_TESTS); if succ_num == SUCC_TESTS.len() as i32 && err_num == FAIL_TESTS.len() as i32 { - println!("{} of sueecssed apps, {} of failed apps run correctly. \nUsertests passed!", SUCC_TESTS.len(), FAIL_TESTS.len() ); + println!( + "{} of sueecssed apps, {} of failed apps run correctly. \nUsertests passed!", + SUCC_TESTS.len(), + FAIL_TESTS.len() + ); return 0; } if succ_num != SUCC_TESTS.len() as i32 { diff --git a/user/src/lib.rs b/user/src/lib.rs index db743106..3d69007e 100644 --- a/user/src/lib.rs +++ b/user/src/lib.rs @@ -127,7 +127,8 @@ pub fn waitpid(pid: usize, exit_code: &mut i32) -> isize { // -1 or a real pid exit_pid => { println!("[USER] lib::waitpid() end: exit_pid {}", exit_pid); - return exit_pid; } + return exit_pid; + } } } } @@ -204,14 +205,14 @@ pub fn condvar_wait(condvar_id: usize, mutex_id: usize) { #[macro_export] macro_rules! vstore { - ($var_ref: expr, $value: expr) => { + ($var_ref: expr, $value: expr) => { unsafe { core::intrinsics::volatile_store($var_ref as *const _ as _, $value) } }; } #[macro_export] macro_rules! vload { - ($var_ref: expr) => { + ($var_ref: expr) => { unsafe { core::intrinsics::volatile_load($var_ref as *const _ as _) } }; } @@ -221,4 +222,4 @@ macro_rules! memory_fence { () => { core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst) }; -} \ No newline at end of file +}