perf: repaint the whole console only when something disturbed it

Console upkeep still runs every second, but a full repaint follows only when it
had to re-quiet the kernel, take the terminal back or noticed a new font, after
reconnecting, and every five seconds as a safety net.
This commit is contained in:
Willem Vanhulle committed 2026-10-21 13:24:35 +02:00
1 parent 552d1170ed
commit a071b2d065
5 files changed
+42 -29

No files matched your search

+18 -16
View File
@@ -58,14 +58,16 @@ impl Console {
self.foreground.is_some() self.foreground.is_some()
} }
pub fn keep_up(&mut self) { pub fn keep_up(&mut self) -> bool {
if let Some(quiet_kernel) = &mut self.quiet_kernel { let kernel_got_loud = self
quiet_kernel.keep_quiet(); .quiet_kernel
} .as_mut()
if let Some(foreground) = &self.foreground { .is_some_and(QuietKernelConsole::keep_quiet);
foreground.insist(); let terminal_was_taken = self.foreground.as_ref().is_some_and(ForegroundVt::insist);
} let glyphs = font_glyphs();
self.glyphs = font_glyphs(); let font_changed = glyphs != self.glyphs;
self.glyphs = glyphs;
kernel_got_loud || terminal_was_taken || font_changed
} }
} }
@@ -85,13 +87,15 @@ impl QuietKernelConsole {
Some(Self { previous_level }) Some(Self { previous_level })
} }
fn keep_quiet(&mut self) { fn keep_quiet(&mut self) -> bool {
let Some(level) = console_level() else { let Some(level) = console_level() else {
return; return false;
}; };
if level != ALERTS_ONLY && fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_ok() { if level == ALERTS_ONLY || fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_err() {
self.previous_level = level; return false;
} }
self.previous_level = level;
true
} }
} }
@@ -185,10 +189,8 @@ impl ForegroundVt {
Some(Self { own, previous }) Some(Self { own, previous })
} }
fn insist(&self) { fn insist(&self) -> bool {
if active_vt().is_some_and(|active| active != self.own) { active_vt().is_some_and(|active| active != self.own) && activate(self.own).is_ok()
let _ = activate(self.own);
}
} }
} }
+8 -3
View File
@@ -16,7 +16,8 @@ use crate::{
screen_settings::font_glyphs::Glyphs, screen_settings::font_glyphs::Glyphs,
}; };
const FULL_REPAINT_INTERVAL: Duration = Duration::from_secs(1); const CONSOLE_UPKEEP_INTERVAL: Duration = Duration::from_secs(1);
const FULL_REPAINT_INTERVAL: Duration = Duration::from_secs(5);
pub struct LiveDesk { pub struct LiveDesk {
console: Console, console: Console,
@@ -83,8 +84,8 @@ impl ConsoleDesk for LiveDesk {
self.follow_requests(true); self.follow_requests(true);
} }
fn keep_console_up(&mut self) { fn keep_console_up(&mut self) -> bool {
self.console.keep_up(); self.console.keep_up()
} }
fn take_clear_request(&mut self) -> bool { fn take_clear_request(&mut self) -> bool {
@@ -96,6 +97,10 @@ impl ConsoleDesk for LiveDesk {
} }
} }
pub fn console_upkeep_inputs() -> impl Stream<Item = ScreenInput> {
periodic_inputs(CONSOLE_UPKEEP_INTERVAL, || ScreenInput::ConsoleUpkeep)
}
pub fn full_repaint_inputs() -> impl Stream<Item = ScreenInput> { pub fn full_repaint_inputs() -> impl Stream<Item = ScreenInput> {
periodic_inputs(FULL_REPAINT_INTERVAL, || ScreenInput::FullRepaint) periodic_inputs(FULL_REPAINT_INTERVAL, || ScreenInput::FullRepaint)
} }
+7 -2
View File
@@ -8,7 +8,9 @@ use crate::{
console_session::{ console_session::{
ask_password::RequestWatch, ask_password::RequestWatch,
console_takeover::Console, console_takeover::Console,
live_desk::{LiveDesk, full_repaint_inputs, password_request_inputs}, live_desk::{
LiveDesk, console_upkeep_inputs, full_repaint_inputs, password_request_inputs,
},
stream_sources::{frame_inputs, key_inputs, termination_inputs}, stream_sources::{frame_inputs, key_inputs, termination_inputs},
watch_screen::{WatchEnding, WatchScreen, watch_until_ending}, watch_screen::{WatchEnding, WatchScreen, watch_until_ending},
}, },
@@ -88,7 +90,10 @@ async fn watch_live_boot(settings: &Settings, phase: Phase) -> Result<(), Error>
key_inputs()?, key_inputs()?,
), ),
stream::select( stream::select(
stream::select(frame_inputs(), full_repaint_inputs()), stream::select(
frame_inputs(),
stream::select(console_upkeep_inputs(), full_repaint_inputs()),
),
stream::select( stream::select(
termination_inputs()?, termination_inputs()?,
stream::iter(password_inputs).flatten(), stream::iter(password_inputs).flatten(),
+8 -7
View File
@@ -21,9 +21,9 @@ const PROJECTION_REFRESH: Duration = Duration::from_millis(100);
pub enum ScreenInput { pub enum ScreenInput {
Boot(Vec<BootChange>), Boot(Vec<BootChange>),
Reconnected,
Key(Event), Key(Event),
Frame, Frame,
ConsoleUpkeep,
FullRepaint, FullRepaint,
PasswordRequests, PasswordRequests,
Terminate, Terminate,
@@ -45,7 +45,9 @@ pub trait ConsoleDesk {
fn password_requests_changed(&mut self) {} fn password_requests_changed(&mut self) {}
fn keep_console_up(&mut self) {} fn keep_console_up(&mut self) -> bool {
false
}
fn take_clear_request(&mut self) -> bool { fn take_clear_request(&mut self) -> bool {
false false
@@ -102,14 +104,13 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
let now = self.now(); let now = self.now();
match input { match input {
ScreenInput::Boot(changes) => self.apply_boot_changes(changes), ScreenInput::Boot(changes) => self.apply_boot_changes(changes),
ScreenInput::Reconnected => {
self.full_repaint_due = true;
ControlFlow::Continue(())
}
ScreenInput::Key(event) => self.desk.press_key(&event, now), ScreenInput::Key(event) => self.desk.press_key(&event, now),
ScreenInput::Frame => self.desk.frame_passed(&mut self.state, now), ScreenInput::Frame => self.desk.frame_passed(&mut self.state, now),
ScreenInput::ConsoleUpkeep => {
self.full_repaint_due |= self.desk.keep_console_up();
ControlFlow::Continue(())
}
ScreenInput::FullRepaint => { ScreenInput::FullRepaint => {
self.desk.keep_console_up();
self.full_repaint_due = true; self.full_repaint_due = true;
ControlFlow::Continue(()) ControlFlow::Continue(())
} }
+1 -1
View File
@@ -133,7 +133,7 @@ impl BusFeed {
match self.open_watched().await { match self.open_watched().await {
Ok(watched) => { Ok(watched) => {
self.link = Link::Connected(watched.connection); self.link = Link::Connected(watched.connection);
vec![ScreenInput::Boot(watched.changes), ScreenInput::Reconnected] vec![ScreenInput::Boot(watched.changes), ScreenInput::FullRepaint]
} }
Err(_) if Instant::now() < deadline => { Err(_) if Instant::now() < deadline => {
sleep(FRAME_INTERVAL).await; sleep(FRAME_INTERVAL).await;