debug(timer): timer_handler 一次性 H + msleep 自旋 s,判定 ISR 是否被调用
apic.eoi 修复后仍挂在 sti done(无 msleep done)。加两处确定性诊断: - timer_handler 首次进入打印 'H':ISR 被调用则出现 - msleep 每 1M 次迭代打印 's':hlt 唤醒(中断触发)但 ticks 不推进则出现 判定: - 无 H → 定时中断未到达 timer_handler(IDT/PIC/APIC 路由) - 有 H → ISR 已调用,问题在 handler/ticks 推进 用后移除。
This commit is contained in:
1 parent
9082056fe0
commit
57c4092d19
1 file changed
+13
-1
@@ -2,6 +2,7 @@ import platform.pch.pic as pic
|
||||
import platform.pch.pit as pit
|
||||
import sched.sched as sched
|
||||
import drivers.core.cpu.apic as apic
|
||||
import drivers.serial.uart.serial as serial
|
||||
import asm
|
||||
import t, c
|
||||
|
||||
@@ -13,6 +14,7 @@ ticks: t.CStatic | t.CVolatile | t.CUInt64T = 0
|
||||
seconds: t.CStatic | t.CVolatile | t.CUInt32T = 0
|
||||
milliseconds: t.CStatic | t.CVolatile | t.CUInt32T = 0
|
||||
timer_running: t.CStatic | t.CVolatile | bool = False
|
||||
_dbg_once: t.CInt = 0
|
||||
|
||||
def timer_init():
|
||||
global ticks, seconds, milliseconds, timer_running
|
||||
@@ -25,7 +27,11 @@ def timer_init():
|
||||
pit.pit_init(TIMER_FREQUENCY)
|
||||
|
||||
def timer_handler():
|
||||
global ticks, seconds, milliseconds, timer_running
|
||||
global ticks, seconds, milliseconds, timer_running, _dbg_once
|
||||
# [DBG] 一次性打印:'H' 出现说明定时 ISR 被调用(用后移除)
|
||||
if _dbg_once == 0:
|
||||
_dbg_once = 1
|
||||
serial.puts("H")
|
||||
if not timer_running:
|
||||
pic.eoi(0)
|
||||
apic.eoi()
|
||||
@@ -95,7 +101,13 @@ def timer_get_time(out_seconds: t.CUInt32T | t.CPtr, out_milliseconds: t.CUInt32
|
||||
|
||||
def timer_msleep(ms: t.CUInt32T):
|
||||
target: t.CUInt64T = ticks + (ms + MILLISECONDS_PER_TICK - 1) / MILLISECONDS_PER_TICK
|
||||
_spin: t.CUInt64T = 0
|
||||
while ticks < target:
|
||||
# [DBG] 自旋计数:每 1M 次迭代打印 s——hlt 能唤醒说明中断触发
|
||||
# (用后移除)
|
||||
_spin += 1
|
||||
if (_spin & 0xFFFFF) == 0:
|
||||
serial.puts("s")
|
||||
asm.sti()
|
||||
asm.hlt()
|
||||
sched.Scheduler._yield()
|
||||
|
||||
Reference in new issue
Block a user