Skip to content

Commit 6edd5a4

Browse files
committed
fix: 所有 wfi 循环以对抗简单的硬件
Signed-off-by: YdrMaster <[email protected]>
1 parent 398419e commit 6edd5a4

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

bench-kernel/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
3939
rcore_console::init_console(&Console);
4040
rcore_console::set_log_level(option_env!("LOG"));
4141
rcore_console::test_log();
42-
// 打开软中断
43-
unsafe {
44-
sie::set_ssoft();
45-
sstatus::set_sie();
46-
};
42+
4743
// 测试调用延迟
4844
let t0 = time::read();
4945

@@ -53,18 +49,22 @@ extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
5349

5450
let t1 = time::read();
5551
log::info!("marchid duration = {}", t1 - t0);
52+
53+
// 打开软中断
54+
unsafe { sie::set_ssoft() };
5655
// 测试中断响应延迟
5756
let t0 = time::read();
58-
5957
for _ in 0..0x20000 {
6058
unsafe {
59+
sstatus::set_sie();
6160
core::arch::asm!(
6261
" la {0}, 1f
6362
csrw stvec, {0}
6463
mv a0, a2
6564
mv a1, zero
6665
ecall
67-
wfi
66+
0: wfi
67+
j 0b
6868
.align 2
6969
1: csrci sip, {ssip}
7070
",

rustsbi-qemu/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ unsafe extern "C" fn _start() -> ! {
6262

6363
#[naked]
6464
unsafe extern "C" fn _stop() -> ! {
65-
asm!("wfi", options(noreturn))
65+
asm!("0: wfi", "j 0b", options(noreturn))
6666
}
6767

6868
/// rust 入口。
@@ -400,8 +400,9 @@ impl rustsbi::Hsm for Hsm {
400400
csrrw {0}, mtvec, {0}
401401
csrr {1}, mepc
402402
csrrsi {2}, mstatus, {mie}
403-
wfi
404-
1: csrw mstatus, {2}
403+
0: wfi
404+
j 0b
405+
1: csrw mstatus, {2}
405406
csrw mepc, {1}
406407
csrw mtvec, {0}
407408
",

0 commit comments

Comments
 (0)