aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / ui / boot_show.c
| 1 | /* boot_show.c -- the boot sequence on any screen, and its frame receipt |
| 2 | * (boot_show.h). */ |
| 3 | #include "boot_show.h" |
| 4 | #include "allen_ui.h" |
| 5 | |
| 6 | static struct { |
| 7 | int on, over; |
| 8 | uint64_t hz, t0; |
| 9 | uint64_t (*clock)(void); |
| 10 | ck_boot_present_fn present; |
| 11 | void *ctx; |
| 12 | uint32_t frames, dropped, ms; |
| 13 | int32_t last_slot; /* the slot of the last frame shown; -1 before the first */ |
| 14 | uint64_t busy, slowest; |
| 15 | } bs; |
| 16 | |
| 17 | static uint32_t night_ms(uint64_t now) { return bs.on ? (uint32_t)((now - bs.t0) * 1000u / bs.hz) : 0; } |
| 18 | |
| 19 | int ck_boot_show_start(volatile uint32_t *fb, uint32_t w, uint32_t h, uint32_t pitch, uint32_t format, void *mem, |
| 20 | size_t mem_len, uint64_t hz, uint64_t now, uint64_t (*clock)(void), ck_boot_present_fn present, |
| 21 | void *ctx) |
| 22 | { |
| 23 | if (ck_allen_ui_start(fb, w, h, pitch, format, mem, mem_len, hz, now, clock)) |
| 24 | return -1; |
| 25 | bs.on = 1, bs.over = 0, bs.hz = hz, bs.t0 = now, bs.clock = clock, bs.present = present, bs.ctx = ctx; |
| 26 | bs.frames = bs.dropped = bs.ms = 0, bs.last_slot = -1, bs.busy = bs.slowest = 0; |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | uint32_t ck_boot_show_ms(uint64_t now) { return night_ms(now); } |
| 31 | |
| 32 | uint32_t ck_boot_show_audio_frame(uint64_t now) |
| 33 | { |
| 34 | return bs.on ? (uint32_t)((now - bs.t0) * CK_CHIRP_RATE / bs.hz) : 0; |
| 35 | } |
| 36 | |
| 37 | /* The slots from the last frame shown up to (not including) slot s showed |
| 38 | * nothing new. */ |
| 39 | static void count_gap(int32_t s) |
| 40 | { |
| 41 | if (s > bs.last_slot + 1) |
| 42 | bs.dropped += (uint32_t)(s - bs.last_slot - 1); |
| 43 | } |
| 44 | |
| 45 | int ck_boot_show_tick(uint64_t now) |
| 46 | { |
| 47 | if (!bs.on || bs.over) |
| 48 | return 0; |
| 49 | uint32_t t = night_ms(now); |
| 50 | if (t >= CK_BOOT_SHOW_MS) { |
| 51 | count_gap((int32_t)CK_BOOT_SHOW_SLOTS); |
| 52 | bs.over = 1, bs.ms = CK_BOOT_SHOW_MS; |
| 53 | return 0; |
| 54 | } |
| 55 | bs.ms = t; |
| 56 | uint64_t c0 = bs.clock ? bs.clock() : now; |
| 57 | if (!ck_allen_ui_tick(now)) |
| 58 | return 1; |
| 59 | if (bs.present) |
| 60 | bs.present(bs.ctx); |
| 61 | uint64_t c = (bs.clock ? bs.clock() : now) - c0; |
| 62 | bs.busy += c; |
| 63 | if (c > bs.slowest) |
| 64 | bs.slowest = c; |
| 65 | bs.frames++; |
| 66 | int32_t s = (int32_t)(t * CK_BOOT_SHOW_HZ / 1000u); |
| 67 | count_gap(s); |
| 68 | if (s > bs.last_slot) |
| 69 | bs.last_slot = s; |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | void ck_boot_show_stats(struct ck_boot_show_stats *s) |
| 74 | { |
| 75 | uint32_t slots = bs.over ? CK_BOOT_SHOW_SLOTS : bs.ms * CK_BOOT_SHOW_HZ / 1000u; |
| 76 | s->frames = bs.frames; |
| 77 | s->slots = slots; |
| 78 | s->dropped = bs.over ? bs.dropped : (slots > (uint32_t)(bs.last_slot + 1) ? bs.dropped + slots - (uint32_t)(bs.last_slot + 1) : bs.dropped); |
| 79 | s->average_us = bs.frames && bs.hz ? (uint32_t)(bs.busy * 1000000u / bs.hz / bs.frames) : 0; |
| 80 | s->slowest_us = bs.hz ? (uint32_t)(bs.slowest * 1000000u / bs.hz) : 0; |
| 81 | s->ms = bs.ms; |
| 82 | } |