From 9082056fe0474b438b940f90ced81bb15a20e9d6 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 26 Aug 2026 18:23:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(timer):=20timer=5Fhandler=20=E8=A1=A5=20LAP?= =?UTF-8?q?IC=20EOI=EF=BC=8C=E4=BF=AE=E5=A4=8D=20APIC=20=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E5=90=8E=E5=AE=9A=E6=97=B6=E4=B8=AD=E6=96=AD=E8=A2=AB=E5=B1=8F?= =?UTF-8?q?=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit APIC 启用后(LINT0=EXTINT 送达),每次中断会置 LAPIC ISR,必须写 LAPIC_EOI(0x0B0) 清除。此前只发 PIC EOI(0x20/0xA0),LAPIC ISR 卡住 → 首个定时中断后后续中断全被屏蔽 → ticks 不推进 → timer_msleep 永久挂起 (清理诊断后稳定复现,serial.log 停在 "sti done" 无 "msleep done")。 两个分支(timer_running 早退 + 正常路径)都补 apic.eoi()。 --- VKernel/Kernel/platform/pch/timer.vp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/VKernel/Kernel/platform/pch/timer.vp b/VKernel/Kernel/platform/pch/timer.vp index 9b45895..da8cd0e 100644 --- a/VKernel/Kernel/platform/pch/timer.vp +++ b/VKernel/Kernel/platform/pch/timer.vp @@ -1,6 +1,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 asm import t, c @@ -27,6 +28,7 @@ def timer_handler(): global ticks, seconds, milliseconds, timer_running if not timer_running: pic.eoi(0) + apic.eoi() return c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) ticks = ticks + 1 @@ -37,6 +39,10 @@ def timer_handler(): c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) sched.Scheduler.sched_tick() pic.eoi(0) + # LAPIC EOI:APIC 启用后中断经 LINT0(EXTINT) 送达会置 LAPIC ISR, + # 只发 PIC EOI 不清 LAPIC ISR → 首个定时中断后后续中断被屏蔽 → + # ticks 不推进 → msleep 永久挂起(QEMU/OVMF 下 APIC 必启用)。 + apic.eoi() def timer_start(): global timer_running