Skip to content

Commit 35a3919

Browse files
committed
test: 增加一个从中断发起到响应的延迟测试
Signed-off-by: YdrMaster <[email protected]>
1 parent e400481 commit 35a3919

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

legacy-console-bench/src/main.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,51 @@ extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
3434
static mut ebss: u64;
3535
}
3636
unsafe { r0::zero_bss(&mut sbss, &mut ebss) };
37+
// 初始化打印
3738
unsafe { UART = MaybeUninit::new(MmioSerialPort::new(0x1000_0000)) };
3839
rcore_console::init_console(&Console);
3940
rcore_console::set_log_level(option_env!("LOG"));
4041
rcore_console::test_log();
42+
// 打开软中断
43+
unsafe {
44+
sie::set_ssoft();
45+
sstatus::set_sie();
46+
};
47+
// 测试调用延迟
48+
let t0 = time::read();
4149

50+
for _ in 0..0xffff {
51+
let _ = sbi_rt::get_marchid();
52+
}
53+
54+
let t1 = time::read();
55+
log::info!("marchid duration = {}", t1 - t0);
56+
// 测试中断响应延迟
4257
let t0 = time::read();
4358

4459
for _ in 0..0xffff {
45-
let _ = sbi_rt::send_ipi(1 << hartid, 0);
60+
unsafe {
61+
core::arch::asm!(
62+
" la {0}, 1f
63+
csrw stvec, {0}
64+
ecall
65+
wfi
66+
.align 2
67+
1:
68+
",
69+
out(reg) _,
70+
in("a7") 0x735049,
71+
in("a6") 0,
72+
in("a0") 1 << hartid,
73+
in("a1") 0,
74+
options(nomem),
75+
);
76+
}
4677
}
4778

4879
let t1 = time::read();
80+
log::info!("ipi duration = {}", t1 - t0);
4981

50-
log::info!("{}", t1 - t0);
5182
system_reset(Shutdown, NoReason);
5283
unreachable!()
5384
}

0 commit comments

Comments
 (0)