Skip to content

Commit 3fa76c7

Browse files
authored
Merge pull request #255 from ryanbreen/feat/network-fix-and-bcheck
feat: VirtIO PCI networking, NTP, BWM taskbar, keyboard fix
2 parents 8417efd + bac51b8 commit 3fa76c7

30 files changed

Lines changed: 1665 additions & 183 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ third-party/
8686
# EFI System Partition build artifact
8787
esp/
8888

89+
# Parallels EFI disk image (build artifact from build-efi.sh)
90+
scripts/parallels/breenix-efi.hds/
91+
8992
# Debug capture files
9093
serial-capture*.txt
9194
xhci_ftrace*.txt

docs/planning/compositor-cpu-attack-plan.md

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,30 @@
22

33
Baseline: BWM at 70% CPU, 155Hz loop, 6451us/iter, 13 syscalls/iter, 50% idle polling.
44

5-
## Priority 1: Event-Driven Compositor Wait [IN PROGRESS]
5+
## Priority 1: Event-Driven Compositor Wait [DONE]
66

7-
**Expected savings: 30-40% CPU**
8-
**Status: Implementing**
7+
**Actual savings: ~14% CPU (34% -> 20%)**
8+
**Status: Merged (PR #254)**
99

10-
New syscall op=22 `compositor_wait(timeout_ms)` that combines:
11-
- Dirty check for all windows (replaces 4x op=14 generation checks)
12-
- Keyboard/mouse input poll (replaces poll + mouse_state)
13-
- Window list change detection (replaces op=13 per-frame)
14-
- Blocks if nothing pending (replaces sleep_ms(2))
10+
New syscall op=23 `compositor_wait(timeout_ms, last_registry_gen)` that:
11+
- Blocks in kernel until woken by mark_window_dirty, mouse, or registry change
12+
- Returns bitmask: bit0=dirty, bit1=mouse, bit2=registry + packed registry_gen
13+
- USB HID mouse handler wakes compositor on movement
14+
- REGISTRY_GENERATION atomic bumped on window register
15+
- Removed duplicate blocking from op=16 composite_windows
1516

16-
Returns a bitmask of what's ready. Eliminates idle polling (500Hz -> 0Hz when idle).
17+
BWM main loop restructured: only blits when DIRTY flag set, only discovers
18+
windows when REGISTRY flag set, no idle polling.
1719

18-
Files:
19-
- kernel/src/syscall/graphics.rs: Add op=22 handler
20-
- libs/libbreenix/src/graphics.rs: Add compositor_wait() wrapper
21-
- userspace/programs/src/bwm.rs: Restructure main loop around compositor_wait
22-
23-
## Priority 2: MAP_SHARED Client Windows (Zero-Copy Blit)
24-
25-
**Expected savings: 15-25% CPU**
26-
**Status: Planned**
27-
28-
New syscall op=23 `map_window_buffer(buffer_id)` maps client window physical pages
29-
into BWM's address space (read-only). BWM blits directly from mapped pages to
30-
COMPOSITE_TEX. Eliminates:
31-
- 4x read_window_buffer syscalls per iteration
32-
- Kernel page-by-page copy under spinlock (up to 8.6MB for terminal)
33-
- pixel_cache intermediate copy
20+
## Priority 2: MAP_SHARED Client Windows + Occluded Blit [DONE]
3421

35-
Uses same infrastructure as map_compositor_texture (op=20).
22+
**Actual savings: ~36% CPU (70% -> 34%)**
23+
**Status: Merged (PR #253)**
3624

37-
Files:
38-
- kernel/src/syscall/graphics.rs: Add op=23 handler (model on op=20)
39-
- libs/libbreenix/src/graphics.rs: Add map_window_buffer() wrapper
40-
- userspace/programs/src/bwm.rs: Replace blit_client_pixels with direct mapped reads
25+
- op=21 `map_window_buffer`: maps client window physical pages into BWM read-only
26+
- op=22 `check_window_dirty`: lightweight generation check without pixel copy
27+
- Occluded blit: span-based row clipping skips pixels covered by higher-z windows
28+
- Eliminates: read_window_buffer syscalls, kernel page copies, pixel_cache, z-repair
4129

4230
## Priority 3: Strip Vestigial Composite Allocations
4331

@@ -53,40 +41,28 @@ Fix: Remove Vec construction, pass only bg_dirty + dirty_rect to GPU driver.
5341
Replace registered_windows() with direct-write to output buffer.
5442

5543
Files:
56-
- kernel/src/syscall/graphics.rs lines 1110-1147
44+
- kernel/src/syscall/graphics.rs (composite_windows handler)
5745
- kernel/src/drivers/virtio/gpu_pci.rs virgl_composite_windows signature
5846

59-
## Priority 4: Reduce clock_gettime Calls
47+
## Priority 4: Reduce clock_gettime Calls [DONE]
6048

61-
**Expected savings: 1-2% CPU**
62-
**Status: Planned**
49+
**Status: Done (part of PR #253)**
6350

64-
5x now_monotonic() per iteration is pure measurement overhead. Feature-gate behind
65-
a perf_instrumentation flag or reduce to 2 (start + end).
51+
Reduced from 5x now_monotonic() per iteration to 2 (start + end).
6652

67-
Files:
68-
- userspace/programs/src/bwm.rs: lines 539, 545, 558, 690, 738, 777
53+
## Priority 5: Batch Window Discovery [DONE]
6954

70-
## Priority 5: Batch Window Discovery
55+
**Status: Done (part of PR #254)**
7156

72-
**Expected savings: 1-2% CPU**
73-
**Status: Planned**
57+
REGISTRY_GENERATION atomic in kernel, compositor_wait returns generation.
58+
BWM only calls list_windows when registry changed.
7459

75-
list_windows (op=13) called every iteration but windows only change at startup.
76-
Add a registry generation counter in shared page. BWM checks counter, only calls
77-
list_windows when it changes.
60+
## Actual Results
7861

79-
Files:
80-
- kernel/src/syscall/graphics.rs: Add atomic generation to WindowRegistry
81-
- userspace/programs/src/bwm.rs line 548: Check generation before calling
82-
83-
## Projected Totals
84-
85-
| After Attack | CPU Estimate |
86-
|-------------|-------------|
87-
| Baseline | 70% |
88-
| +Priority 1 | 30-40% |
89-
| +Priority 2 | 15-20% |
90-
| +Priority 3 | 12-17% |
91-
| +Priority 4 | 11-16% |
92-
| +Priority 5 | 10-15% |
62+
| After Attack | CPU | FPS |
63+
|-------------|-----|-----|
64+
| Baseline | 70% | ~100 |
65+
| +Priority 2 (MAP_SHARED + occluded blit) | 34% | ~130 |
66+
| +Priority 1 (compositor_wait) | ~20% | ~186 |
67+
68+
Total reduction: 70% -> 20% (71% reduction), FPS: 100 -> 186 (86% increase).

kernel/src/arch_impl/aarch64/syscall_entry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ fn dispatch_syscall_enum(
469469
SyscallNumber::Yield => { crate::task::scheduler::yield_current(); 0 }
470470
SyscallNumber::GetTime => sys_get_time(),
471471
SyscallNumber::ClockGetTime => sys_clock_gettime(arg1 as u32, arg2 as *mut Timespec),
472+
SyscallNumber::ClockSetTime => result_to_u64(crate::syscall::time::sys_clock_settime(arg1 as u32, arg2 as *const crate::syscall::time::Timespec)),
472473
SyscallNumber::Nanosleep => result_to_u64(crate::syscall::time::sys_nanosleep(arg1, arg2)),
473474
SyscallNumber::Clone => result_to_u64(crate::syscall::clone::sys_clone(arg1, arg2, arg3, arg4, arg5)),
474475
SyscallNumber::Futex => result_to_u64(crate::syscall::futex::sys_futex(arg1, arg2 as u32, arg3 as u32, arg4, arg5, arg6 as u32)),

kernel/src/arch_impl/aarch64/timer_interrupt.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ pub extern "C" fn timer_interrupt_handler() {
275275
crate::drivers::usb::ehci::poll_keyboard();
276276
// Poll XHCI USB HID events (needed when PCI interrupt routing isn't available)
277277
crate::drivers::usb::xhci::poll_hid_events();
278+
// Poll VirtIO net PCI for incoming packets (PCI INTx routing not wired up)
279+
// Throttle to every 50th tick (~20Hz at 1000Hz timer) to avoid overhead
280+
if crate::drivers::virtio::net_pci::is_initialized() && _count % 50 == 0 {
281+
crate::task::softirqd::raise_softirq(crate::task::softirqd::SoftirqType::NetRx);
282+
}
278283
}
279284

280285
// CPU 0 only: soft lockup detector

kernel/src/drivers/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ pub fn init() -> usize {
126126
Err(e) => serial_println!("[drivers] VirtIO GPU (PCI) init failed: {}", e),
127127
}
128128

129+
// Initialize VirtIO network driver (PCI transport)
130+
match virtio::net_pci::init() {
131+
Ok(()) => serial_println!("[drivers] VirtIO network (PCI) initialized"),
132+
Err(e) => serial_println!("[drivers] VirtIO network (PCI) init failed: {}", e),
133+
}
134+
129135
// Initialize VMware SVGA3 GPU if present (VMware Fusion on ARM64)
130136
match vmware::svga3::init() {
131137
Ok(()) => {

kernel/src/drivers/virtio/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub mod input_mmio;
3838
#[cfg(target_arch = "aarch64")]
3939
pub mod sound_mmio;
4040
#[cfg(target_arch = "aarch64")]
41+
pub mod net_pci;
42+
#[cfg(target_arch = "aarch64")]
4143
pub mod gpu_pci;
4244
#[cfg(target_arch = "aarch64")]
4345
pub mod virgl;

0 commit comments

Comments
 (0)