diff options
Diffstat (limited to 'core')
| -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" { |
