diff --git a/easy-fs-fuse/src/main.rs b/easy-fs-fuse/src/main.rs index d36d566d1cf5693927ebe7ad4fe423f38a8a014f..cf07b6186fa002c667bf09b02140aa2acb0da03f 100644 --- a/easy-fs-fuse/src/main.rs +++ b/easy-fs-fuse/src/main.rs @@ -56,13 +56,13 @@ fn easy_fs_pack() -> std::io::Result<()> { .write(true) .create(true) .open(format!("{}{}", target_path, "fs.img"))?; - f.set_len(128 * 2048 * 512).unwrap(); + f.set_len(16 * 2048 * 512).unwrap(); f }))); - // 128MiB, at most 4095 files + // 16MiB, at most 4095 files let efs = EasyFileSystem::create( block_file.clone(), - 128 * 2048, + 16 * 2048, 1, ); let root_inode = Arc::new(EasyFileSystem::root_inode(&efs)); diff --git a/os/Makefile b/os/Makefile index 07c10082183664d43368fd9bee06a1fbca0f7d12..864a4e438ccad8e40fd590afb9b6ce5951551d03 100644 --- a/os/Makefile +++ b/os/Makefile @@ -49,7 +49,7 @@ env: sdcard: fs-img @echo "Are you sure write to $(SDCARD) ? [y/N] " && read ans && [ $${ans:-N} = y ] - @sudo dd if=/dev/zero of=$(SDCARD) bs=1048576 count=256 + @sudo dd if=/dev/zero of=$(SDCARD) bs=1048576 count=32 @sudo dd if=$(FS_IMG) of=$(SDCARD) $(KERNEL_BIN): kernel @@ -57,7 +57,7 @@ $(KERNEL_BIN): kernel fs-img: $(APPS) @cd ../user && make build - @rm $(FS_IMG) + @rm $(FS_IMG) -f @cd ../easy-fs-fuse && cargo run --release -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/ $(APPS): diff --git a/os/src/timer.rs b/os/src/timer.rs index 92d50e3ade2b54f5b935d44f7948bb72c12b7ff8..ad226e64490b92c16dac3593ce40362586d0c78b 100644 --- a/os/src/timer.rs +++ b/os/src/timer.rs @@ -15,4 +15,4 @@ pub fn get_time_ms() -> usize { pub fn set_next_trigger() { set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC); -} \ No newline at end of file +} diff --git a/user/src/bin/race_adder.rs b/user/src/bin/race_adder.rs index 44d653fd5f2962e3e3e505236d0a745193916df9..dabead160e8bd1c1f03d69987ed9cd4615baa112 100644 --- a/user/src/bin/race_adder.rs +++ b/user/src/bin/race_adder.rs @@ -5,20 +5,21 @@ extern crate user_lib; extern crate alloc; -use user_lib::{exit, thread_create, waittid}; +use user_lib::{exit, thread_create, waittid, get_time}; use alloc::vec::Vec; static mut A: usize = 0; -const PER_THREAD: usize = 10000000; -const THREAD_COUNT: usize = 50; +const PER_THREAD: usize = 2000000; +const THREAD_COUNT: usize = 8; unsafe fn f() -> ! { + let start = get_time(); for _ in 0..PER_THREAD { let a = &mut A as *mut usize; let cur = a.read_volatile(); a.write_volatile(cur + 1); } - exit(0) + exit((get_time() - start) as i32) } #[no_mangle] @@ -27,10 +28,13 @@ pub fn main() -> i32 { for _ in 0..THREAD_COUNT { v.push(thread_create(f as usize) as usize); } + let mut time_cost = Vec::new(); for tid in v.iter() { - waittid(*tid); + time_cost.push(waittid(*tid)); + } + for (i, cost) in time_cost.iter().enumerate() { + println!("cost of thread#{} is {}ms", i, cost); } assert_eq!(unsafe { A }, PER_THREAD * THREAD_COUNT); - println!("total = {}", unsafe { A }); 0 } diff --git a/user/src/linker.ld b/user/src/linker.ld index 7273618c9f6b2cb497b34e1ffae692b79fcce40a..02f7b6bf583b6e26ab818f3f997edad2cbc0addb 100644 --- a/user/src/linker.ld +++ b/user/src/linker.ld @@ -2,7 +2,7 @@ OUTPUT_ARCH(riscv) ENTRY(_start) -BASE_ADDRESS = 0x0; +BASE_ADDRESS = 0x10000; SECTIONS { @@ -29,4 +29,4 @@ SECTIONS *(.eh_frame) *(.debug*) } -} \ No newline at end of file +}