Skip to content

Commit 0f9f917

Browse files
committed
test: 改为测 get_mxxx 的性能
Signed-off-by: YdrMaster <[email protected]>
1 parent 3c2da81 commit 0f9f917

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

legacy-console-bench/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
sbi-rt = { version = "0.0.2", features = ["legacy"] }
9+
sbi-rt = "0.0.2"
1010
riscv = "0.9.0"
1111
r0 = "1"
12+
uart_16550 = "0.2"
1213

1314
console = { git = "https://github.com/YdrMaster/rCore-Tutorial-in-single-workspace" }

legacy-console-bench/src/main.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#![feature(naked_functions, asm_const)]
44
#![deny(warnings)]
55

6-
#[macro_use]
7-
extern crate console;
6+
use core::mem::MaybeUninit;
87

98
use console::log;
109
use riscv::register::*;
1110
use sbi_rt::*;
11+
use uart_16550::MmioSerialPort;
1212

1313
#[naked]
1414
#[no_mangle]
@@ -35,17 +35,15 @@ extern "C" fn rust_main(_hartid: usize, _dtb_pa: usize) -> ! {
3535
static mut ebss: u64;
3636
}
3737
unsafe { r0::zero_bss(&mut sbss, &mut ebss) };
38+
unsafe { UART = MaybeUninit::new(MmioSerialPort::new(0x1000_0000)) };
3839
console::init_console(&Console);
3940
console::set_log_level(option_env!("LOG"));
4041
console::test_log();
4142

4243
let t0 = time::read();
4344

44-
for i in 0..0x2000 {
45-
print!("{i:#08x}");
46-
for _ in 0..8 {
47-
print!("{}", 8 as char);
48-
}
45+
for _ in 0..0xffff {
46+
let _ = sbi_rt::get_marchid();
4947
}
5048

5149
let t1 = time::read();
@@ -62,12 +60,12 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
6260
loop {}
6361
}
6462

65-
pub struct Console;
63+
struct Console;
64+
static mut UART: MaybeUninit<MmioSerialPort> = MaybeUninit::uninit();
6665

6766
impl console::Console for Console {
6867
#[inline]
6968
fn put_char(&self, c: u8) {
70-
#[allow(deprecated)]
71-
legacy::console_putchar(c as _);
69+
unsafe { UART.assume_init_mut().send(c) }
7270
}
7371
}

0 commit comments

Comments
 (0)