diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-26 13:27:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-27 09:47:39 -0300 |
| commit | 11f380f6d7222f2cad93c2cdf13701ea1f903d47 (patch) | |
| tree | 803194ee5853a6b4cda93f90a95e28d1f02e69ae /src/allocators.zig | |
| parent | fbc194068687e49a8490c85c9f1257a2f2bb9079 (diff) | |
| download | pardes-11f380f6d7222f2cad93c2cdf13701ea1f903d47.tar.gz pardes-11f380f6d7222f2cad93c2cdf13701ea1f903d47.zip | |
One core behind N frontends, the board's own runner moved in, and every board cap on one screen
## The wire is the effect stream, not a new protocol
`pardes --detach` leaves a core running with no terminal; `pardes --attach` is a frontend that owns
a terminal and a socket and nothing else. N frontends on one core all look at the same screen —
`screen -x`, not N sessions.
The codec (`src/detached/wire.zig`) carries exactly one `Event` or one `Host.VTable` call per
message. That is not a coincidence and it is why there is no third vocabulary to keep in step: the
core's IO seam was already a struct of function pointers with plain-data arguments, so a socket is
a legal implementation of it. `nested.zig`'s socket could not be reused — it carries a builtin
command line, and a command line cannot carry a frame.
ARCHITECTURE-NEUTRAL on purpose, not as decoration. The frontend on the far end may be
riscv32-freestanding on the ESP32-P4 while the core is x86_64 Linux, so every field is an explicit
little-endian fixed width and no message is a blit of a native struct. A protocol that only works
between two builds of the same compiler would have thrown away the one frontend that motivated it.
## The board comes in; its toolchain stays out
`src/p4.zig` becomes `src/esp32p4.zig`, and the pardes half of `../05-zig-p4` — the vaxis-over-
serial runner, the UART editor terminal, the keystroke rescue ring, the on-die test suite — moves
into `src/esp32p4/`. `build.zig.zon` gains `.zig_p4 = .{ .path = "../05-zig-p4" }`, so
`zig build -Dplatform=esp32p4 -Desp32p4-firmware` builds, flashes, monitors and self-tests the
board from this repo's `build.zig`.
The DIVISION is the point. What moved is what only pardes wants: the runner that drives a pardes
core over a serial line. What stayed is everything a second project would also want — the HAL, the
register/radio/oracle layers, the linker script, `_start`. `zig_p4` declares no dependencies of its
own and its `build()` early-returns when it is not the root package, so this costs the package
graph exactly zero packages and the editor's own builds nothing at all.
## limits.zig: nine forgettable places become one budget
Nine `platform == .esp32p4` capacity tests lived in nine files. They were never nine decisions —
they are ONE decision, how much memory this build may spend, taken nine times where no reader could
see the total. `src/limits.zig` puts the whole budget on one screen with every cap named against
what it is measured against, derived from two booleans.
The payoff is testability on a machine that is not the board: the caps are ordinary comptime values,
so a host build can be compiled against the board's numbers and the parking, eviction and clamping
paths a 240 KiB core takes get exercised by the normal test suite instead of only over a UART.
## A bare `zig build`
`zig build` with no arguments now builds the tty and GUI binaries and installs them into
`~/.local/bin`, and says so once on stdout with the flag that overrides it. The old default built
one binary into `zig-out` — a path nothing on a `PATH` ever looks at, which made "build it" and
"use it" two different commands for no reason.
Diffstat (limited to 'src/allocators.zig')
| -rw-r--r-- | src/allocators.zig | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/src/allocators.zig b/src/allocators.zig index cf024a0b..61c55f39 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -1,43 +1,9 @@ const std = @import("std"); const builtin = @import("builtin"); -const config = @import("pardes_config"); +const limits = @import("limits.zig"); const Allocator = std.mem.Allocator; const debug_enabled = builtin.mode == .Debug; -/// Three tiers, because the address space differs by four orders of magnitude. -/// `reduced_target` is the browser: a wasm linear memory it grows on demand, so -/// the static reservations are megabytes rather than tens. -/// -/// `p4` is ESP32-P4 firmware, and its tier is deliberately ALL FALLBACK. Every -/// capacity here is a `StackFallbackAllocator`'s buffer, which is a static and -/// therefore lands in `.bss` — and on the P4 `.bss`, `.data` and the stack all -/// share ONE 240 KiB chunk of L2MEM at 0x4FF03000, while the heap the fallback -/// allocator hands out is the separate 384 KiB chunk at 0x4FF40000 - the 128 KiB -/// above that measured as L2 cache rather than memory. A -/// megabyte-shaped reservation here would not fit, and every byte that did fit -/// would be taken from the stack's neighbourhood to duplicate memory the heap -/// already has. So the buffers exist only because the type requires one: 4 KiB -/// absorbs the small churn, and everything else spills to the real heap on the -/// first allocation. -const p4 = config.platform == .p4; -const reduced_target = config.platform == .web or builtin.os.tag == .freestanding; -const KiB = 1024; -const MiB = 1024 * KiB; - -const capacities = struct { - const pardes = if (p4) 4 * KiB else if (reduced_target) 8 * MiB else 32 * MiB; - const frame = if (p4) 4 * KiB else if (reduced_target) 4 * MiB else 16 * MiB; - // Zero is legal and always spills, which is exactly what an arena for a - // compiled-out subsystem should do. `StackFallbackAllocator(0).buffer` is - // `[0]u8`; `get()` inits the FixedBufferAllocator over an empty slice, so - // `FixedBufferAllocator.alloc` fails every nonzero request and `alloc` - // falls through to `self.fallback_allocator.rawAlloc`, while `ownsPtr` over - // an empty range is false for every pointer so `resize`/`remap`/`free` - // route to the fallback too. See lib/std/heap.zig, StackFallbackAllocator. - const tree_sitter = if (p4) 0 else if (reduced_target) 4 * MiB else 16 * MiB; - const image = if (p4) 0 else if (reduced_target) 64 * KiB else 32 * MiB; - const pdf = if (p4) 0 else if (reduced_target or !config.mupdf) 64 * KiB else 64 * MiB; -}; pub const Allocators = struct { pardes: Allocator, @@ -48,11 +14,13 @@ pub const Allocators = struct { pdf: Allocator, }; -var pardes_fallback: std.heap.StackFallbackAllocator(capacities.pardes) = undefined; -var frame_fallback: std.heap.StackFallbackAllocator(capacities.frame) = undefined; -var tree_sitter_fallback: std.heap.StackFallbackAllocator(capacities.tree_sitter) = undefined; -var image_fallback: std.heap.StackFallbackAllocator(capacities.image) = undefined; -var pdf_fallback: std.heap.StackFallbackAllocator(capacities.pdf) = undefined; +/// The static reservations, one per profile tier. See `limits.arena` for why +/// each number is what it is, and why the board's are 4 KiB and zero. +var pardes_fallback: std.heap.StackFallbackAllocator(limits.arena.pardes) = undefined; +var frame_fallback: std.heap.StackFallbackAllocator(limits.arena.frame) = undefined; +var tree_sitter_fallback: std.heap.StackFallbackAllocator(limits.arena.tree_sitter) = undefined; +var image_fallback: std.heap.StackFallbackAllocator(limits.arena.image) = undefined; +var pdf_fallback: std.heap.StackFallbackAllocator(limits.arena.pdf) = undefined; const Debug = std.heap.DebugAllocator(.{}); var pardes_debug: Debug = .init; @@ -121,7 +89,7 @@ test "fixed allocators are separate, spill, and restart" { try std.testing.expect(frame_fallback.fixed_buffer_allocator.ownsPtr(frame.ptr)); try std.testing.expect(core.ptr != frame.ptr); - const spill = try allocs.pardes.alloc(u8, capacities.pardes + 1); + const spill = try allocs.pardes.alloc(u8, limits.arena.pardes + 1); try std.testing.expect(!pardes_fallback.fixed_buffer_allocator.ownsPtr(spill.ptr)); allocs.pardes.free(spill); allocs.frame.free(frame); |
