| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>CPU & Scheduling | NebOS Architecture</title>
- <meta name="description" content="NebOS CPU architecture: GDT/TSS, PIC/PIT and LAPIC interrupts, IOAPIC masking, ACPI SMP bring-up, CFS-lite scheduling, wait queues, the big kernel lock, idle, power and AMD/Intel thermal management.">
- <link rel="icon" href="favicon.svg" type="image/svg+xml">
- <link rel="stylesheet" href="style.css">
- </head>
- <body>
- <a class="skip" href="#main">Skip to content</a>
- <header class="site-header">
- <a class="brand" href="index.html">
- <span class="brand-mark" aria-hidden="true"></span>
- <span>NebOS <span class="brand-sub">Architecture</span></span>
- </a>
- <nav class="site-nav" aria-label="Architecture sections">
- <a href="index.html">Overview</a>
- <a href="boot.html">Boot</a>
- <a href="memory.html">Memory</a>
- <a href="cpu.html" aria-current="page">CPU</a>
- <a href="drivers.html">Drivers</a>
- <a href="filesystems.html">Filesystems</a>
- <a href="graphics.html">Graphics</a>
- <a href="network.html">Network</a>
- <a href="userland.html">Userland</a>
- <a href="development.html">Development</a>
- </nav>
- </header>
- <main id="main" class="page">
- <div class="page-head">
- <p class="kicker">CPU & scheduling</p>
- <h1>Weighted fairness, one global run queue, one big lock.</h1>
- <p class="lede">
- NebOS runs a CFS-lite scheduler over a single global run queue and
- per-CPU <code>current</code> pointers. ACPI/MADT brings up the APs,
- each CPU has its own GDT, TSS and timer, and a sleeping recursive
- mutex — the big kernel lock — serializes kernel execution.
- </p>
- <div class="meta">
- <span class="pill">8 CPUs max</span>
- <span class="pill">64 process slots</span>
- <span class="pill">10 ms slice</span>
- <span class="pill">1 kHz busy / 100 Hz idle</span>
- </div>
- </div>
- <nav class="toc" aria-label="On this page">
- <h2>On this page</h2>
- <ul>
- <li><a href="#bringup">Boot CPU bring-up</a></li>
- <li><a href="#interrupts">Interrupts & timers</a></li>
- <li><a href="#smp">SMP bring-up</a></li>
- <li><a href="#process">Process model</a></li>
- <li><a href="#scheduler">CFS-lite scheduler</a></li>
- <li><a href="#bkl">Big kernel lock</a></li>
- <li><a href="#idle">Idle & power</a></li>
- <li><a href="#sources">Source map</a></li>
- </ul>
- </nav>
- <section id="bringup">
- <h2>Boot CPU bring-up</h2>
- <p>
- After <code>kernel_main</code> clears BSS and starts the boot console,
- the first structural step is <code>gdt_tss_init(0)</code>. The GDT/TSS
- and the per-CPU GS base must exist before any code that calls
- <code>current_proc()</code> or <code>this_cpu()</code>.
- </p>
- <ul>
- <li>Each CPU has a <code>struct cpu</code> holding <code>current</code>, <code>idle</code>, its TSS, LAPIC id, tick period and scheduling flags.</li>
- <li><code>%gs:0</code> points at the current CPU's <code>current</code> field; <span class="file">switch.S</span> reads it directly. A static assert locks the offsets.</li>
- <li>The TSS <code>esp0</code> is updated by <code>schedule()</code>, so ring-3 entry always lands on the process's kernel stack.</li>
- <li><code>process_init()</code> must run before <code>timer_init()</code>: once the PIT starts, the timer stub can switch context on every tick.</li>
- </ul>
- </section>
- <section id="interrupts">
- <h2>Interrupts & timers</h2>
- <p>
- The BSP keeps the legacy 8259 PIC and PIT; there is no IOAPIC
- driver. After ACPI init the kernel masks every normal IOAPIC
- redirection entry (leaving ExtINT entries alone, in case the 8259
- is routed through an IOAPIC pin), so firmware-left vectors cannot
- collide with the PIC vectors or the LAPIC timer. APs mask their
- LINT0/LINT1 inputs and use only their local APIC timer and IPIs.
- </p>
- <div class="table-wrap">
- <table>
- <thead>
- <tr><th>Source</th><th>Vector</th><th>Role</th></tr>
- </thead>
- <tbody>
- <tr><td>8259 PIC + PIT</td><td>IRQ0, etc.</td><td>BSP global clock and device interrupts; PIT tick advances the millisecond clock.</td></tr>
- <tr><td>LAPIC timer</td><td><code>0x30</code></td><td>Per-AP scheduling tick; 1 ms busy, 10 ms idle.</td></tr>
- <tr><td>LAPIC IPI</td><td><code>0x31</code></td><td>Reschedule request; must be EOIed on the target LAPIC.</td></tr>
- <tr><td><code>int 0x80</code></td><td>syscall gate</td><td>Ring-3 service entry.</td></tr>
- <tr><td><code>int 0x81</code></td><td>voluntary yield</td><td>Blocking helpers and <code>schedule()</code>.</td></tr>
- </tbody>
- </table>
- </div>
- <p>
- The timer period is not fixed. While a process runs, the BSP PIT ticks
- at 1 kHz and AP LAPIC timers tick every 1 ms. While a CPU is idle, the
- BSP drops to 100 Hz and APs to 10 ms so MWAIT/HLT can hold a deeper
- state. The global millisecond clock remains accurate because the PIT
- stub advances it by the current tick period.
- </p>
- <figure class="figure">
- <div class="bars" role="img" aria-label="Timer rates: 1000 Hz while busy, 100 Hz while idle. Bar widths are relative to 1000 Hz.">
- <div class="bar-row">
- <span class="bar-label">BSP busy</span>
- <div class="bar-track"><span class="bar-fill green" style="--w:100%"></span></div>
- <span class="bar-value">1000 Hz</span>
- </div>
- <div class="bar-row">
- <span class="bar-label">BSP idle</span>
- <div class="bar-track"><span class="bar-fill" style="--w:10%"></span></div>
- <span class="bar-value">100 Hz</span>
- </div>
- <div class="bar-row">
- <span class="bar-label">AP busy</span>
- <div class="bar-track"><span class="bar-fill green" style="--w:100%"></span></div>
- <span class="bar-value">1 ms</span>
- </div>
- <div class="bar-row">
- <span class="bar-label">AP idle</span>
- <div class="bar-track"><span class="bar-fill" style="--w:10%"></span></div>
- <span class="bar-value">10 ms</span>
- </div>
- </div>
- <figcaption>
- <strong>Race to idle, then stay there.</strong> When a wake-up
- arrives, <code>smp_resched_wake()</code> shortens the idle period so
- the woken process runs at the next millisecond instead of waiting
- out a 10 ms nap.
- </figcaption>
- </figure>
- </section>
- <section id="smp">
- <h2>SMP bring-up</h2>
- <p>
- SMP is ACPI-only: RSDP → RSDT/XSDT → MADT → CPU/LAPIC list. There is
- deliberately no Intel MP-table parser. A machine without ACPI, a
- usable MADT, the CPUID APIC bit or a LAPIC stays uniprocessor and
- follows exactly the old 8259/PIT path.
- </p>
- <p>
- The same table walk reads the FADT's <code>century</code> byte (offset
- 108) and exposes the CMOS register to <span class="file">rtc.c</span>,
- which writes it when setting the clock so the two-digit year stays in
- the intended century. Boards without ACPI get no century write and
- keep the 1970–2069 read window.
- </p>
- <p>
- It also caches the FADT power-management blocks and scans the DSDT
- (or an SSDT) for <code>\_S5</code>. The <code>poweroff</code> command
- read-modify-writes the sleep type into PM1a/PM1b, keeping the existing
- <code>SCI_EN</code> bit set — writing only the sleep bits clears it,
- and some real chipsets then ignore the request. It writes
- <code>SLP_TYP</code> first and <code>SLP_EN</code> in a second write.
- Intel-style southbridges clear <code>SMI_EN.SLP_SMI_EN</code> (bit 4
- at <code>PMBASE+0x30</code>): while that bit is set the chipset turns
- the <code>SLP_EN</code> write into an SMI instead of a power
- transition. NVIDIA nForce/MCP boards (the ION) run S5 through the
- firmware SMM instead: the kernel writes the sleep state into the
- BIOS NVS (<code>ASSB=5</code>, Linux <code>AOTB</code>/<code>OSTP</code>,
- <code>AAXB=0</code>) and arms <code>PS1S</code>/<code>PS1E</code> in
- the SMI block, matching the DSDT's <code>_PTS(5)</code>, before the
- <code>SLP_EN</code> write. If <code>SCI_EN</code> is clear it first
- enables ACPI mode through the FADT SMI command (or the conventional
- <code>0xB2</code>/<code>0xF1</code> pair). BIOS and UEFI boots share
- this path because both hand the kernel the same ACPI tables; only the
- RSDP discovery differs (EBDA scan versus the loader's boot info).
- Emulators whose tables do not decode <code>\_S5</code> fall back to
- the Bochs/QEMU shutdown ports. A failed poweroff returns to the
- desktop instead of halting, and the boot/poweroff log carries the
- PM1, <code>\_S5</code> and <code>SCI_EN</code> state. The same FADT
- walk caches the ACPI 2.0 <code>RESET_REG</code>/<code>RESET_VALUE</code>
- (when <code>RESET_REG_SUP</code> is set); <code>reboot</code> writes
- it first, then tries the Intel PCH <code>0xCF9</code>, the keyboard
- controller and a triple fault. That is what resets a UEFI machine
- with no working legacy keyboard controller.
- </p>
- <ol>
- <li>Copy the AP trampoline to <code>0x6000</code> (SIPI vector <code>0x06</code>).</li>
- <li>Allocate an AP idle PCB and kernel stack via <code>process_init_ap()</code>.</li>
- <li>Fill the startup block at <code>0x6F00</code> with CR3, stack top, C entry and CPU index.</li>
- <li>Send INIT, then SIPI-SIPI, with a second SIPI retry.</li>
- <li>The trampoline clears <code>CR0.CD</code>/<code>CR0.NW</code>: INIT leaves an AP with caching disabled (<code>CR0 = 0x60000010</code>), and before this every ring-3 process on an AP ran about 100× slower on real hardware (QEMU does not model caches). The wake-up value is written back to <code>0x6F10</code> and logged as <code>smp: AP n start cr0 …</code>.</li>
- <li>The AP enters <code>smp_ap_main</code>, initialises its LAPIC timer and idle loop, and waits.</li>
- <li>After device/FS setup, <code>smp_enable_sched()</code> lets APs take user work.</li>
- </ol>
- <p>
- Kernel threads stay pinned to the BSP; only ring-3 processes may run
- on an AP. Each AP runs <code>cpu_enable_sse()</code> because it starts
- with firmware <code>CR4</code>; without OSFXSR/OSXMMEXCPT the SSE2
- drawing fast paths would <code>#UD</code>. Every CPU also runs
- <code>cpu_init_fpu()</code> (<code>CR0.NE</code>/<code>MP</code>,
- <code>FNINIT</code>): an AP leaves INIT with <code>CR0.NE</code> clear
- and an x87 control word of <code>0x0040</code>, so every inexact
- floating-point result froze it until the next timer tick, and the
- browser's JavaScript ran hundreds of times slower on an AP. Each
- process owns its x87 state; <code>schedule()</code> saves it with
- <code>FNSAVE</code> and restores it with <code>FRSTOR</code> on every
- switch (108 bytes in <code>struct process</code>, no FXSR needed).
- </p>
- <div class="warn">
- <p><strong>No IOAPIC driver.</strong> Device IRQs never reach an AP,
- and <code>pit_irq_stub</code> is BSP-only. The kernel masks the
- IOAPIC's normal redirection entries after ACPI init
- (<span class="file">ioapic.c</span>) and keeps the 8259 path on
- LAPIC LINT0; ExtINT entries survive so firmware that routes the
- 8259 through an IOAPIC pin still works.</p>
- </div>
- </section>
- <section id="process">
- <h2>Process model</h2>
- <p>
- Every process is a stable heap-allocated PCB referenced from a sparse
- <code>procs[64]</code> table, so a process pointer never moves when
- another slot changes. The idle context is not a process slot: the
- <code>kernel_main</code> context becomes the BSP idle state, and APs
- have their own idle PCBs.
- </p>
- <ul>
- <li><strong>Kernel threads</strong> are created with <code>process_create</code> and take the BKL automatically.</li>
- <li><strong>Ring-3 processes</strong> are created from an ELF image with their own page directory, 32-page (128 KB) user stack and cwd.</li>
- <li><strong>The kworker</strong> is an ordinary kernel process that performs housekeeping and zombie reaping, so it cannot be starved by a busy system.</li>
- <li><strong>Stable naming:</strong> process names are 12 bytes; the PCB holds the TTY id, cwd, affinity mask, CPU accounting, the parent pid and the scheduling entity.</li>
- <li><strong>PID 1 is init.</strong> The kernel starts <code>/ramfs/bin/init</code> after the ramfs and <code>/share</code> mounts and before the WM. Init is a root process and the only creator of the WM and services; the kernel restarts it if it dies. <code>SYS_IS_INIT</code> lets the binary refuse a user-run start.</li>
- <li><strong>Parent death is the default.</strong> <code>process_exit()</code>, <code>process_kill()</code> and the reaper kill a process's whole descendant subtree. A child born while its parent is dying is aborted, and the process monitor's <em>End task</em> kills the subtree too.</li>
- <li><strong>Detached spawns.</strong> <code>SYS_SPAWN</code> takes a flags word. The default parents the child to the caller; <code>SYS_SPAWN_DETACH</code> skips the immediate parent and attaches the child to its parent (the terminal/WM session), or to 0 if that parent is gone. This keeps launched apps in the session tree: they outlive a file manager or chat window, but not the terminal/WM. Kernel commands (<code>SYS_SPAWN_KCMD</code>) stay parented. <code>SYS_PROCINFO</code> exposes <code>parent_pid</code>, and the graphical <code>process</code> monitor draws the table as an indented tree under each parent.</li>
- <li><strong>Fatal faults.</strong> A ring-3 fault kills that process (and its descendants) and keeps the kernel running; a ring-0 fault still shows the panic banner and halts.</li>
- </ul>
- <figure class="figure">
- <svg viewBox="0 0 920 260" role="img" aria-labelledby="states-title states-desc">
- <title id="states-title">Process state transitions</title>
- <desc id="states-desc">Processes move between ready, running, sleeping, blocked and dead states. Wake-ups return to ready, and exit or kill moves to dead.</desc>
- <rect class="svg-box green" x="48" y="96" width="150" height="58" rx="9"/>
- <text class="svg-text" x="123" y="120" text-anchor="middle">READY</text>
- <text class="svg-sub" x="123" y="140" text-anchor="middle">run queue</text>
- <rect class="svg-box accent" x="288" y="96" width="150" height="58" rx="9"/>
- <text class="svg-text" x="363" y="120" text-anchor="middle">RUNNING</text>
- <text class="svg-sub" x="363" y="140" text-anchor="middle">one per CPU</text>
- <rect class="svg-box blue" x="528" y="28" width="150" height="58" rx="9"/>
- <text class="svg-text" x="603" y="52" text-anchor="middle">SLEEPING</text>
- <text class="svg-sub" x="603" y="72" text-anchor="middle">deadline in sleep list</text>
- <rect class="svg-box blue" x="528" y="164" width="150" height="58" rx="9"/>
- <text class="svg-text" x="603" y="188" text-anchor="middle">BLOCKED</text>
- <text class="svg-sub" x="603" y="208" text-anchor="middle">wait queue</text>
- <rect class="svg-box amber" x="756" y="96" width="136" height="58" rx="9"/>
- <text class="svg-text" x="824" y="120" text-anchor="middle">DEAD</text>
- <text class="svg-sub" x="824" y="140" text-anchor="middle">zombie queue</text>
- <path class="svg-line green" d="M198 118h84"/>
- <path class="svg-line green" d="M276 112l7 6-7 6"/>
- <text class="svg-tiny" x="240" y="108" text-anchor="middle">pick</text>
- <path class="svg-line" d="M363 154v28H198v-24"/>
- <path class="svg-line" d="M192 162l6-7 6 7"/>
- <text class="svg-tiny" x="300" y="196" text-anchor="middle">slice / yield</text>
- <path class="svg-line blue" d="M438 112h84"/>
- <path class="svg-line blue" d="M516 106l7 6-7 6"/>
- <text class="svg-tiny" x="480" y="103" text-anchor="middle">sleep</text>
- <path class="svg-line blue" d="M438 138v46h84"/>
- <path class="svg-line blue" d="M516 178l7 6-7 6"/>
- <text class="svg-tiny" x="480" y="176" text-anchor="middle">wait</text>
- <path class="svg-line" d="M603 86V62h-240v34"/>
- <path class="svg-line" d="M357 90l6-7 6 7"/>
- <text class="svg-tiny" x="475" y="56" text-anchor="middle">wake</text>
- <path class="svg-line" d="M603 222v18H363v-18"/>
- <path class="svg-line" d="M357 228l6-7 6 7"/>
- <text class="svg-tiny" x="478" y="248" text-anchor="middle">wake</text>
- <path class="svg-line amber" d="M438 125h312"/>
- <path class="svg-line amber" d="M744 119l7 6-7 6"/>
- <text class="svg-tiny" x="594" y="119" text-anchor="middle">exit / kill</text>
- </svg>
- <figcaption>
- <strong>Five states, two queues.</strong> The run queue is global;
- the sleep list is sorted by deadline; wait queues are per-object.
- A woken process is clamped to the current minimum vruntime so an
- interactive wake-up is scheduled promptly without accumulating
- unbounded credit.
- </figcaption>
- </figure>
- </section>
- <section id="scheduler">
- <h2>CFS-lite scheduler</h2>
- <p>
- Weight is an integer from 1 to 16. Each ready process carries a
- 64-bit <code>vruntime</code> and a <code>stride = 2<sup>20</sup> / weight</code>.
- While a process runs, its vruntime advances by
- <code>elapsed_ms × stride</code>; the scheduler picks the runnable
- process with the smallest vruntime. The result is a long-term CPU
- share proportional to weight.
- </p>
- <ul>
- <li><strong>10 ms slice.</strong> A running process is preempted at the slice boundary unless it holds the BKL or has preemption disabled.</li>
- <li><strong>Global run queue.</strong> A single linked list protected by <code>sched_lock</code>; every CPU scans it for the minimum vruntime.</li>
- <li><strong>Wake-up clamp.</strong> A process waking from sleep or a wait queue is moved forward to the current minimum vruntime rather than receiving unlimited credit.</li>
- <li><strong>Affinity.</strong> A CPU bitmask restricts where a process may run; kernel threads are pinned to the BSP.</li>
- <li><strong><code>renice</code></strong> changes a live process's weight from the shell; the new stride takes effect immediately.</li>
- </ul>
- <figure class="figure">
- <div class="bars" role="img" aria-label="Scheduler weights: window manager 16, default processes and terminals 8, kworker 4, minimum 1. Bar widths are relative to 16.">
- <div class="bar-row">
- <span class="bar-label">WM / max</span>
- <div class="bar-track"><span class="bar-fill" style="--w:100%"></span></div>
- <span class="bar-value">16</span>
- </div>
- <div class="bar-row">
- <span class="bar-label">default / terminal</span>
- <div class="bar-track"><span class="bar-fill blue" style="--w:50%"></span></div>
- <span class="bar-value">8</span>
- </div>
- <div class="bar-row">
- <span class="bar-label">kworker</span>
- <div class="bar-track"><span class="bar-fill green" style="--w:25%"></span></div>
- <span class="bar-value">4</span>
- </div>
- <div class="bar-row">
- <span class="bar-label">minimum</span>
- <div class="bar-track"><span class="bar-fill" style="--w:6.25%"></span></div>
- <span class="bar-value">1</span>
- </div>
- </div>
- <figcaption>
- <strong>Weights seen in the tree.</strong> The ring-3 WM is raised
- to 16, the kworker is set to 4 and a new process starts at 8. Bar
- widths are relative to the maximum weight of 16.
- </figcaption>
- </figure>
- <p>
- The run queue is a flat list rather than a red-black tree; picking
- the minimum is a scan. With at most 64 processes this is simple and
- predictable, and the scheduler core stays small enough to audit.
- Sleeping processes sit in a sorted sleep list, so the tick handler
- wakes due sleepers without scanning every process.
- </p>
- </section>
- <section id="bkl">
- <h2>The big kernel lock</h2>
- <p>
- <code>bkl_*</code> is a sleeping recursive mutex, not a spinlock.
- Every ring-3 syscall and every kernel thread takes it; voluntary
- block and sleep points release it through <code>sched_yield</code>.
- Long serial and network waits use <code>bkl_pause()</code> /
- <code>bkl_resume()</code> so another CPU can make progress.
- </p>
- <ul>
- <li><strong>Not timer-preempted.</strong> A CPU running a BKL holder is skipped by the tick decision, so the owner can safely be in the middle of kernel data structures.</li>
- <li><strong>Recursive.</strong> The owner may re-enter; the depth is restored across a block in the PCB's <code>bkl_saved</code> field.</li>
- <li><strong>Sleep, not spin.</strong> A waiter blocks on the BKL wait queue and is woken when the owner releases.</li>
- <li><strong>Lock-free clock.</strong> <code>SYS_GET_TICKS_MS</code> is answered before the lock is taken (one aligned counter read). It is the hottest syscall: QuickJS's interrupt check called it every ~10000 operations and slept on a contended lock each time, and the browser's interrupt hook now reads the clock only every 16th check.</li>
- <li><strong>Contention statistics.</strong> <code>sched</code> prints how often a taker had to sleep, the total wait and the longest single hold with its holder, all since the previous <code>sched</code>.</li>
- <li><strong>Idle uses trylock.</strong> The idle fallback never blocks on the BKL; kworker and kernel commands take it normally.</li>
- </ul>
- <div class="note">
- <p><strong>Why one big lock?</strong> The kernel is small and not
- designed around fine-grained locking. The BKL keeps every kernel
- invariant simple, at the cost of serializing long kernel operations.
- Disk I/O still holds it, except a destructive format's raw-sector
- loop, which releases it so the WM and terminals keep running;
- network and serial waits drop it.</p>
- </div>
- </section>
- <section id="idle">
- <h2>Idle, power & thermals</h2>
- <p>
- <code>idle auto</code> is the default. It asks <span class="file">power.c</span>
- for the deepest usable hint: C6 (<code>0x20</code>) on
- Nehalem/Westmere, C6N (<code>0x58</code>) on Airmont/Braswell when
- CPUID advertises the C6 substates, and HLT on the older Atom boards
- where an old USB-legacy SMM hang made deep states risky.
- </p>
- <ul>
- <li><strong>Nehalem/Westmere P-states.</strong> <code>power_init</code> enables SpeedStep, raises the package C-state limit to C6 when unlocked, reads min/max ratios from <code>PLATFORM_INFO</code> and starts at the maximum non-turbo ratio. The target ratio goes in bits 15:8 of <code>IA32_PERF_CTL</code> with the low byte zero.</li>
- <li><strong>Airmont/Braswell P-states.</strong> Family 6 model <code>0x4C</code> reads the Atom ratio/VID MSRs (<code>0x66A..0x66D</code>), <code>MSR_FSB_FREQ</code> and the FSB table. The N3060 reports pstates 6..20, BCLK 80 MHz (1600 MHz nominal), turbo pstate 31 (2480 MHz) and VID 0x2D..0x3C. <code>power_init</code> enters at max non-turbo and the governor drops to pstate 6 (480 MHz); <code>IA32_PERF_CTL</code> carries the pstate in 15:8 and the Linux-interpolated VID in 7:0. Turbo is detected but not requested. The probe deliberately avoids package/power-SKU MSRs; an unsupported <code>rdmsr</code> before the IDT triple-faults.</li>
- <li><strong>Governor.</strong> A 100 ms window picks min/max/linear target pstates; short busy streaks jump to max immediately. Each CPU writes its own <code>IA32_PERF_CTL</code>; <code>cpufreq [auto|min|max|off|<pstate>]</code> overrides it, and <code>SYS_CPUFREQ</code> exposes the same auto/min/max/off mode to the Settings Power page.</li>
- <li><strong>Telemetry.</strong> <code>power</code> prints effective MHz from APERF/MPERF, the current/requested pstate and, on Airmont, the FSB, nominal MHz, turbo pstate/VID, VID range and live <code>PERF_CTL</code>; <code>sensors</code> prints the CPU temperature, board sensors and both EC types; <code>powerinfo</code> prints the AC adapter and battery state, and the WM top bar shows the temperature plus a far-right AC plug or level-filled battery icon on ThinkPads and Chromebooks.</li>
- <li><strong>Thermal.</strong> On Intel, each CPU samples its DTS once a second from its scheduler tick; the hottest core is exposed to ring 3. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere, the coretemp 90 °C table on Airmont, and the Bonnell table on older Atoms. On AMD family 15h models below <code>0x60</code> (Bulldozer/Piledriver/Steamroller), <span class="file">thermal.c</span> reads the package Tctl from <code>D18F3xA4</code> at PCI <code>0:18.3</code> (k10temp's <code>(raw × 125) m°C</code>, with the 49 °C range offset when bits 17:16 are both set) and publishes it to every CPU from the kworker under the BKL; PCI config space is deliberately not touched from the per-CPU timer interrupt.</li>
- <li><strong>Limits.</strong> Package C-states/S0ix remain firmware-managed; Airmont reports no C3/C6 residency and does not request the turbo pstate. The explicit <code>idle c6</code> override is the Nehalem <code>0x20</code> hint; use <code>idle auto</code> for the Airmont C6N (<code>0x58</code>) path.</li>
- </ul>
- </section>
- <section id="sources">
- <h2>Source map</h2>
- <ul class="filelist">
- <li><code>kernel/sched.c</code>, <code>kernel/sched.h</code> — scheduler core and BKL</li>
- <li><code>kernel/process.c</code>, <code>kernel/process.h</code> — PCBs, parent tracking, subtree kill and lifecycle</li>
- <li><code>kernel/init.c</code>, <code>kernel/init.h</code> — PID-1 init bootstrap, protection and restart</li>
- <li><code>kernel/switch.S</code> — context switch</li>
- <li><code>kernel/tss.c</code>, <code>kernel/tss.h</code> — per-CPU TSS</li>
- <li><code>kernel/acpi.c</code>, <code>kernel/ioapic.c</code>, <code>kernel/lapic.c</code>, <code>kernel/smp.c</code> — SMP, IOAPIC masking and the FADT S5 shutdown data</li>
- <li><code>kernel/poweroff.c</code> — ACPI S5 poweroff with the emulator port fallback</li>
- <li><code>kernel/reboot.c</code> — FADT ACPI reset with PCH/KBC/triple-fault fallbacks</li>
- <li><code>kernel/ap_tramp.S</code> — AP startup blob</li>
- <li><code>kernel/timer.S</code>, <code>kernel/idle.c</code>, <code>kernel/power.c</code></li>
- <li><code>kernel/thermal.c</code> — Intel DTS and AMD D18F3xA4 sampling</li>
- <li><code>kernel/spinlock.h</code> — IRQ-safe spinlocks</li>
- </ul>
- </section>
- </main>
- <footer class="site-footer">
- <div class="inner">
- <p><strong>NebOS 0.2.0</strong> · Architecture documentation · <a href="index.html">overview</a></p>
- <p>Maintain alongside <code>AGENTS.md</code> and the source files listed on each page.</p>
- </div>
- </footer>
- </body>
- </html>
|