From 57c4092d192ece9d4dfcf795acde32a3006c7698 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 26 Aug 2026 18:26:34 +0800 Subject: [PATCH] =?UTF-8?q?debug(timer):=20timer=5Fhandler=20=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=80=A7=20H=20+=20msleep=20=E8=87=AA=E6=97=8B=20s?= =?UTF-8?q?=EF=BC=8C=E5=88=A4=E5=AE=9A=20ISR=20=E6=98=AF=E5=90=A6=E8=A2=AB?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 推进 用后移除。 --- VKernel/Kernel/platform/pch/timer.vp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/VKernel/Kernel/platform/pch/timer.vp b/VKernel/Kernel/platform/pch/timer.vp index da8cd0e..96637ab 100644 --- a/VKernel/Kernel/platform/pch/timer.vp +++ b/VKernel/Kernel/platform/pch/timer.vp @@ -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()