Skip to main content

Module vgabuf

Module vgabuf 

Source
Expand description

Lock-free circular buffer for VGA log lines.

The kernel’s log::info! / log::warn! / etc. macros write to this buffer instead of directly locking VGA_WRITER. A background display task (or the panic handler) calls vgabuf_flush_to_framebuffer() to render the buffered lines onto the actual framebuffer.

This decouples the hot logging path from the (comparatively) slow framebuffer drawing, preventing deadlocks and keeping log output fast.

StructsΒ§

VgaSlot πŸ”’
Raw storage: each slot is a fixed-size byte buffer. Wrapped in a newtype that is Sync because we only access slots via atomically-coordinated indices (single writer per slot).

ConstantsΒ§

FLUSH_BATCH πŸ”’
Maximum number of lines we render in one flush call (to keep frame time bounded).
VGABUF_CAPACITY
Maximum number of lines stored in the circular buffer. 512 gives ample headroom: at 100Hz flush Γ— 30 lines/batch, the writer would need to produce >512 log messages between two reader ticks to overwrite an unread slot.
VGABUF_LINE_LEN
Maximum byte length of a single log line (including trailing newline).

StaticsΒ§

DISPLAY_IDX πŸ”’
Slot that the display task has rendered up to (exclusive).
LENS πŸ”’
Length (in bytes) of each stored line. 0 means the slot is unused.
STORAGE πŸ”’
TOTAL_WRITTEN πŸ”’
Total lines written since boot (for ordering / watermark).
WRITE_IDX πŸ”’
Next slot to write into (monotonic, wraps via % CAPACITY).

FunctionsΒ§

vgabuf_drain_discard πŸ”’
Drain all pending lines without rendering (e.g. framebuffer not available).
vgabuf_flush_all
Flush all remaining lines (used by the panic handler before halting).
vgabuf_flush_all_direct πŸ”’
Fallback when VGA_WRITER is locked: use the direct panic drawer. Uses a fixed-size stack buffer to avoid heap allocation in panic context.
vgabuf_flush_to_framebuffer
Read buffered lines and render them onto the framebuffer via crate::arch::x86_64::vga::VGA_WRITER.
vgabuf_total_written
Return the total number of lines written since boot.
vgabuf_write
Write a line into the circular buffer.