diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 02:26:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 02:27:51 -0300 |
| commit | 4fe27fa83d1454830dd4fd98c5a76747f30d2776 (patch) | |
| tree | 31f20f38fd57b83dac3d39dcb38af2bd2ccb704f | |
| parent | 54cd21e1bd487276142e3b1d62f1556f05b7f978 (diff) | |
| download | pardes-4fe27fa83d1454830dd4fd98c5a76747f30d2776.tar.gz pardes-4fe27fa83d1454830dd4fd98c5a76747f30d2776.zip | |
colors: the ring's resolve budget counted in instructions, not CPU time, so a loaded machine cannot fail it (the coordinator's item to the themes programme's colour agent: W3's gui unit-test failed "the whole ring resolves in 150 ms of CPU, no theme in over 0.5 ms" at a load of 8.7, and it would trip every agent's gates); THE CAUSE: the test held B9's budget (about 0.5 ms a theme, the ring in 150 ms, Debug, idle) to the thread's CPU time, the least of five a theme, which a busy machine stretches (a sibling hyperthread, a shared cache, a lower clock): L1 measured the slowest theme at 871 us under a load of 8.7 where it takes 291 to 307 us idle; THE FIX: the same budget in user-space instructions, which the load does not move: one Chrome.of a theme counted by the kernel's counter (perf_event_open, user space only, this thread), 3.5 M a theme and 1 050 M the ring, at the 7 a nanosecond this code retires idle (the ring's 304 M in 42 ms); where the kernel gives no counter (not Linux, perf_event_paranoid 3) the test is skipped; RUN (TEST FIRST): the old test with the count beside its CPU time, run three times in a row on a quiet machine (load 0.9 to 2.5): CPU time 49.0, 42.1 and 41.9 ms for the ring, the slowest theme 409, 304 and 298 us (a third apart between runs at load 2; W3's at 8.7 over the 500 us), the counts 304,213,813, 304,213,802 and 304,213,802 (the slowest by count ao's 2,881,625 or 2,881,626 each time); the new test twice: 304,213,792 and 304,213,795, ao's 2,881,625, within the budget by 3.5x (the ring) and 1.2x (a theme); gui unit-test -Dtest-filter="the whole ring resolves" 14/14 and the whole gui unit-test 1948/1952 (4 skipped; its one failure the known BaselineHarnessMismatch), 304,213,799 there; load 1.9 to 2.7
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
| -rw-r--r-- | core/colors.zig | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/core/colors.zig b/core/colors.zig index d280172e..315d1fc9 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -3,6 +3,7 @@ //! themes programme's), theme files, and switching themes at runtime. //! What a theme says is theme_schema.zig's. const pardes = @import("root.zig"); +const builtin = @import("builtin"); const schema = @import("theme_schema.zig"); pub const Theme = schema.Theme; pub const LegacyTheme = schema.LegacyTheme; @@ -2717,29 +2718,41 @@ test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), nati try std.testing.expectEqual(0, wrong); } -test "the whole ring resolves in 150 ms of CPU, no theme in over 0.5 ms (Debug)" { - const io = std.testing.io; - var total: i96 = 0; - var worst: i96 = 0; +/// B9's budget, about 0.5 ms a theme and the ring in 150 ms on an idle +/// machine (Debug), in user-space instructions, which a loaded machine does +/// not move: Chrome.of retires about 7 a nanosecond here (the ring's 304 M +/// in 42 ms of an idle CPU, 2026-11-26). +const theme_instructions: u64 = 3_500_000; +const ring_instructions: u64 = 1_050_000_000; + +test "the whole ring resolves within B9's budget, about 0.5 ms a theme and 150 ms in all on an idle machine, counted in instructions (Debug)" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + const linux = std.os.linux; + var attr: linux.perf_event_attr = .{ .type = .HARDWARE, .config = @intFromEnum(linux.PERF.COUNT.HW.INSTRUCTIONS), .flags = .{ .exclude_kernel = true, .exclude_hv = true } }; + const rc = linux.perf_event_open(&attr, 0, -1, -1, 0); + // No counter here (a container, perf_event_paranoid 3): nothing to count. + if (linux.errno(rc) != .SUCCESS) return error.SkipZigTest; + const fd: i32 = @intCast(rc); + defer _ = linux.close(fd); + var total: u64 = 0; + var worst: u64 = 0; var worst_at: usize = 0; for (&themes, 0..) |*th, i| { - // The least of five: a theme's own cost, not a page fault's. - var least: i96 = std.math.maxInt(i96); - for (0..5) |_| { - const start = std.Io.Clock.cpu_thread.now(io); - var c = Chrome.of(th); - std.mem.doNotOptimizeAway(&c); - least = @min(least, start.durationTo(std.Io.Clock.cpu_thread.now(io)).toNanoseconds()); - } - total += least; - if (least > worst) { - worst = least; + var before: u64 = 0; + var after: u64 = 0; + _ = linux.read(fd, std.mem.asBytes(&before), 8); + var c = Chrome.of(th); + std.mem.doNotOptimizeAway(&c); + _ = linux.read(fd, std.mem.asBytes(&after), 8); + total += after - before; + if (after - before > worst) { + worst = after - before; worst_at = i; } } - std.debug.print("ring resolved in {d} us, the slowest {s} in {d} us\n", .{ @divTrunc(total, 1000), themes[worst_at].name, @divTrunc(worst, 1000) }); - try std.testing.expect(total < 150 * std.time.ns_per_ms); - try std.testing.expect(worst <= std.time.ns_per_ms / 2); + std.debug.print("ring resolved in {d} instructions, the most {s}'s {d}\n", .{ total, themes[worst_at].name, worst }); + try std.testing.expect(total < ring_instructions); + try std.testing.expect(worst <= theme_instructions); } test "a theme file in the old names, a user's own or an older DumpThemes', and DumpThemes' now in the new names, load to the same Chrome" { |
