]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
perf: VGA shadow buffer + batched TTY output — eliminates MMIO bottleneck
authorTulio A M Mendes <[email protected]>
Sat, 14 Feb 2026 05:56:56 +0000 (02:56 -0300)
committerTulio A M Mendes <[email protected]>
Sat, 14 Feb 2026 05:56:56 +0000 (02:56 -0300)
commit619cf907568dc2f996cf3364687c55e0f488cd19
treee02c03dd44b19ed0d1e2f44bc60f98eb9cee1311
parent4862eea9361f1c5755e93bcbe5b3dc5baa132b0e
perf: VGA shadow buffer + batched TTY output — eliminates MMIO bottleneck

VGA console was extremely slow in QEMU because every character caused:
- 4 outb I/O port writes for cursor update
- Direct writes to VGA MMIO (0xB8000) which QEMU traps per-access
- Full-screen memmove on MMIO for each scroll

Three-layer optimization:

1. Shadow buffer: all VGA writes target a RAM shadow[] array. Only
   dirty cells are flushed to VGA MMIO. Scrolling uses RAM-speed
   memmove instead of MMIO memmove.

2. Batched TTY output: tty_write_kbuf/tty_write now OPOST-expand
   into a local buffer and call console_write_buf() once per chunk
   instead of console_put_char() per character. VGA cursor is
   updated once per batch, not per character.

3. Deferred flush: vga_write_buf() (bulk TTY path) does NOT flush
   to VGA MMIO at all. Screen is refreshed at 50Hz via vga_flush()
   called from the timer tick. Single-char paths (echo, kprintf)
   still flush immediately for responsiveness.

Result: 20/20 smoke tests in 8s WITHOUT console=serial (was timing
out at 90s before). The console=serial workaround is no longer
needed.

Files changed:
- src/drivers/vga_console.c: shadow buffer, dirty tracking, flush
- src/drivers/timer.c: periodic vga_flush() on tick
- src/kernel/tty.c: tty_opost_expand + console_write_buf batching
- src/kernel/console.c: new console_write_buf()
- include/vga_console.h: vga_write_buf, vga_flush declarations
- include/console.h: console_write_buf declaration
- iso/boot/grub/grub.cfg: removed console=serial workaround
include/console.h
include/vga_console.h
iso/boot/grub/grub.cfg
src/drivers/timer.c
src/drivers/vga_console.c
src/kernel/console.c
src/kernel/tty.c