← Back to Pull requests

P1.5: local APIC timer at 1 kHz, PIT calibration, legacy PICs masked #77

Closed
unknown closed this pull request without merging on Sep 27, 2026 15:18 UTC
View on GitHub
unknown unknown commented on Sep 27, 2026 14:43 UTC
Author

Summary

Plan task P1.5: the local APIC is enabled and its timer ticks at 1 kHz; the legacy PICs are out of the way.

Design


  • PICs (arch::x86_64::pic): both 8259s are remapped to vectors 0xE0–0xEF and fully masked; those 16 vectors get no-op IDT handlers so a spurious IRQ7/IRQ15 is swallowed (a spurious IRQ must not be acknowledged) instead of hitting an empty gate or looking like a CPU exception.

  • PIT (arch::x86_64::pit): channel 2 in mode 0 as a one-shot stopwatch polled through port 0x61 (busy_wait_ms, chained in ≤50 ms chunks). It is the calibration reference until ACPI/HPET land in P1.6, and the timer test's independent clock.

  • APIC (arch::x86_64::apic): the register page from IA32_APIC_BASE (0xFEE00000) is device memory, which Limine's direct map does not cover (the first attempt page-faulted at hhdm + 0xFEE000F0). It is now mapped uncached/write-through at paging::KERNEL_MMIO_BASE (512 MiB into the dynamic region) through a new paging::map_mmio (unsafe: the caller vouches the frame is a device page, since the frame allocator never owns MMIO). SVR enables the APIC with spurious vector 0xFF; the timer counts down from u32::MAX for a PIT-timed 10 ms to measure ticks/ms (÷16 divider), then runs periodic on vector 32 at 1 kHz. The handler increments a counter and writes EOI; the spurious handler does nothing.

  • Boot: after all tables and the heap are up, kmain enables interrupts, counts ticks over a PIT-timed 100 ms, requires 90–110 (panics otherwise) and prints timer: LAPIC timer ticking at 1 kHz (N ticks in 100 ms); the uefi and bios smoke scenarios require that success line, so a dead timer cannot pass. Test builds keep interrupts off around the tests.
  • Tests (AC: timer ticks at 1 kHz; test counts ticks over a busy wait)


  • lapic_timer_ticks_at_one_khz: enables interrupts, PIT-waits 100 ms, requires 90–110 ticks, disables interrupts again.

  • Real boots (UEFI and BIOS): LAPIC timer ticking at 1 kHz (99 ticks in 100 ms) on both.
  • Verification


      apic: xAPIC id 0 at 0xfee00000 (mapped at 0xffff900020000000); timer 62646 ticks/ms (÷16), periodic at 1000 Hz on vector 32; PICs masked
    test summary:
      PASS  host unit tests: passed
      PASS  in-kernel tests (QEMU): chisel-test: 13 passed; 0 failed
      PASS  boot smoke (UEFI, BIOS, panic, double fault, page fault, stack overflow, OOM): 7 scenarios passed
    perf: all budgets met (kernel 69.5 KiB, ISO 3.89 MiB, boot 2238 ms, banner→halt 113 ms)
    

    fmt, clippy (host + kernel), docs-gate clean. PLAN §11 updated (P1.5 done, next P1.6).

    Closes #51
    task: P1.5

    🤖 Generated with Claude Code

    Diff: 333 lines (+249 / -84) across 4 files Reviewer: garrickdabbs Review duration: 34m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 333 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #77"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%