mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 09:26:26 +04:00
Use latest virtio-drivers && add huge_write_mt but it cannot work now
This commit is contained in:
parent
6ef566faac
commit
d3bd19867c
@ -12,8 +12,7 @@ lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
|
||||
buddy_system_allocator = "0.6"
|
||||
bitflags = "1.2.1"
|
||||
xmas-elf = "0.7.0"
|
||||
#virtio-drivers = { git = "https://github.com/wyfcyx/virtio-drivers" }
|
||||
virtio-drivers = { path = "../../virtio-drivers" }
|
||||
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers" }
|
||||
k210-pac = { git = "https://github.com/wyfcyx/k210-pac" }
|
||||
k210-hal = { git = "https://github.com/wyfcyx/k210-hal" }
|
||||
k210-soc = { git = "https://github.com/wyfcyx/k210-soc" }
|
||||
|
@ -5,7 +5,7 @@ use crate::mm::{
|
||||
};
|
||||
use crate::sync::{UPSafeCell, Condvar};
|
||||
use lazy_static::*;
|
||||
use virtio_drivers::{VirtIOBlk, VirtIOHeader};
|
||||
use virtio_drivers::{VirtIOBlk, VirtIOHeader, BlkResp, RespStatus};
|
||||
use crate::DEV_NON_BLOCKING_ACCESS;
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::vec::Vec;
|
||||
@ -27,11 +27,13 @@ impl BlockDevice for VirtIOBlock {
|
||||
let nb = *DEV_NON_BLOCKING_ACCESS.exclusive_access();
|
||||
if nb {
|
||||
let mut blk = self.virtio_blk.exclusive_access();
|
||||
let mut resp = 0xffu8;
|
||||
let token = blk.read_block_nb(block_id, buf, &mut resp).unwrap();
|
||||
let mut resp = BlkResp::default();
|
||||
let token = unsafe {
|
||||
blk.read_block_nb(block_id, buf, &mut resp).unwrap()
|
||||
};
|
||||
drop(blk);
|
||||
self.condvars.get(&token).unwrap().wait();
|
||||
assert_eq!(resp, 0x0, "Error when reading VirtIOBlk");
|
||||
assert_eq!(resp.status(), RespStatus::Ok, "Error when reading VirtIOBlk");
|
||||
} else {
|
||||
self.virtio_blk
|
||||
.exclusive_access()
|
||||
@ -43,11 +45,13 @@ impl BlockDevice for VirtIOBlock {
|
||||
let nb = *DEV_NON_BLOCKING_ACCESS.exclusive_access();
|
||||
if nb {
|
||||
let mut blk = self.virtio_blk.exclusive_access();
|
||||
let mut resp = 0xffu8;
|
||||
let token = blk.write_block_nb(block_id, buf, &mut resp).unwrap();
|
||||
let mut resp = BlkResp::default();
|
||||
let token = unsafe {
|
||||
blk.write_block_nb(block_id, buf, &mut resp).unwrap()
|
||||
};
|
||||
drop(blk);
|
||||
self.condvars.get(&token).unwrap().wait();
|
||||
assert_eq!(resp, 0x0, "Error when reading VirtIOBlk");
|
||||
assert_eq!(resp.status(), RespStatus::Ok, "Error when writing VirtIOBlk");
|
||||
} else {
|
||||
self.virtio_blk
|
||||
.exclusive_access()
|
||||
|
@ -24,7 +24,7 @@ pub fn main() -> i32 {
|
||||
}
|
||||
close(f);
|
||||
let time_ms = (get_time() - start) as usize;
|
||||
let speed_kbs = size_mb * 1000000 / time_ms;
|
||||
let speed_kbs = (size_mb << 20) / time_ms;
|
||||
println!(
|
||||
"{}MiB written, time cost = {}ms, write speed = {}KiB/s",
|
||||
size_mb, time_ms, speed_kbs
|
||||
|
54
user/src/bin/huge_write_mt.rs
Normal file
54
user/src/bin/huge_write_mt.rs
Normal file
@ -0,0 +1,54 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, thread_create, waittid};
|
||||
use user_lib::{close, get_time, open, write, OpenFlags};
|
||||
|
||||
fn worker(size_kib: usize) {
|
||||
let mut buffer = [0u8; 1024]; // 1KiB
|
||||
for (i, ch) in buffer.iter_mut().enumerate() {
|
||||
*ch = i as u8;
|
||||
}
|
||||
for _ in 0..size_kib {
|
||||
write(3, &buffer);
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||
let f = open("testf\0", OpenFlags::CREATE | OpenFlags::WRONLY);
|
||||
if f < 0 {
|
||||
panic!("Open test file failed!");
|
||||
}
|
||||
let f = f as usize;
|
||||
assert_eq!(f, 3);
|
||||
assert_eq!(argc, 2, "wrong argument");
|
||||
let workers = argv[1].parse::<usize>().expect("wrong argument");
|
||||
assert!(workers >= 1 && 1024 % workers == 0, "wrong argument");
|
||||
|
||||
let start = get_time();
|
||||
|
||||
let mut v = Vec::new();
|
||||
let size_mb = 1usize;
|
||||
for i in 0..workers {
|
||||
v.push(thread_create(worker as usize, size_mb * 1024 / workers));
|
||||
}
|
||||
for tid in v.iter() {
|
||||
assert_eq!(0, waittid(*tid as usize));
|
||||
}
|
||||
|
||||
close(f);
|
||||
let time_ms = (get_time() - start) as usize;
|
||||
let speed_kbs = (size_mb << 20) / time_ms;
|
||||
println!(
|
||||
"{}MiB written, time cost = {}ms, write speed = {}KiB/s",
|
||||
size_mb, time_ms, speed_kbs
|
||||
);
|
||||
0
|
||||
}
|
Loading…
Reference in New Issue
Block a user