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:
1 parent
552d1170ed
commit
a071b2d065
5 files changed
+42
-29
No files matched your search
@@ -58,14 +58,16 @@ impl Console {
|
||||
self.foreground.is_some()
|
||||
}
|
||||
|
||||
pub fn keep_up(&mut self) {
|
||||
if let Some(quiet_kernel) = &mut self.quiet_kernel {
|
||||
quiet_kernel.keep_quiet();
|
||||
}
|
||||
if let Some(foreground) = &self.foreground {
|
||||
foreground.insist();
|
||||
}
|
||||
self.glyphs = font_glyphs();
|
||||
pub fn keep_up(&mut self) -> bool {
|
||||
let kernel_got_loud = self
|
||||
.quiet_kernel
|
||||
.as_mut()
|
||||
.is_some_and(QuietKernelConsole::keep_quiet);
|
||||
let terminal_was_taken = self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
||||
let 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 })
|
||||
}
|
||||
|
||||
fn keep_quiet(&mut self) {
|
||||
fn keep_quiet(&mut self) -> bool {
|
||||
let Some(level) = console_level() else {
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
if level != ALERTS_ONLY && fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_ok() {
|
||||
self.previous_level = level;
|
||||
if level == ALERTS_ONLY || fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_err() {
|
||||
return false;
|
||||
}
|
||||
self.previous_level = level;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,10 +189,8 @@ impl ForegroundVt {
|
||||
Some(Self { own, previous })
|
||||
}
|
||||
|
||||
fn insist(&self) {
|
||||
if active_vt().is_some_and(|active| active != self.own) {
|
||||
let _ = activate(self.own);
|
||||
}
|
||||
fn insist(&self) -> bool {
|
||||
active_vt().is_some_and(|active| active != self.own) && activate(self.own).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ use crate::{
|
||||
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 {
|
||||
console: Console,
|
||||
@@ -83,8 +84,8 @@ impl ConsoleDesk for LiveDesk {
|
||||
self.follow_requests(true);
|
||||
}
|
||||
|
||||
fn keep_console_up(&mut self) {
|
||||
self.console.keep_up();
|
||||
fn keep_console_up(&mut self) -> bool {
|
||||
self.console.keep_up()
|
||||
}
|
||||
|
||||
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> {
|
||||
periodic_inputs(FULL_REPAINT_INTERVAL, || ScreenInput::FullRepaint)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ use crate::{
|
||||
console_session::{
|
||||
ask_password::RequestWatch,
|
||||
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},
|
||||
watch_screen::{WatchEnding, WatchScreen, watch_until_ending},
|
||||
},
|
||||
@@ -88,7 +90,10 @@ async fn watch_live_boot(settings: &Settings, phase: Phase) -> Result<(), Error>
|
||||
key_inputs()?,
|
||||
),
|
||||
stream::select(
|
||||
stream::select(frame_inputs(), full_repaint_inputs()),
|
||||
stream::select(
|
||||
frame_inputs(),
|
||||
stream::select(console_upkeep_inputs(), full_repaint_inputs()),
|
||||
),
|
||||
stream::select(
|
||||
termination_inputs()?,
|
||||
stream::iter(password_inputs).flatten(),
|
||||
|
||||
@@ -21,9 +21,9 @@ const PROJECTION_REFRESH: Duration = Duration::from_millis(100);
|
||||
|
||||
pub enum ScreenInput {
|
||||
Boot(Vec<BootChange>),
|
||||
Reconnected,
|
||||
Key(Event),
|
||||
Frame,
|
||||
ConsoleUpkeep,
|
||||
FullRepaint,
|
||||
PasswordRequests,
|
||||
Terminate,
|
||||
@@ -45,7 +45,9 @@ pub trait ConsoleDesk {
|
||||
|
||||
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 {
|
||||
false
|
||||
@@ -102,14 +104,13 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
||||
let now = self.now();
|
||||
match input {
|
||||
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::Frame => self.desk.frame_passed(&mut self.state, now),
|
||||
ScreenInput::ConsoleUpkeep => {
|
||||
self.full_repaint_due |= self.desk.keep_console_up();
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
ScreenInput::FullRepaint => {
|
||||
self.desk.keep_console_up();
|
||||
self.full_repaint_due = true;
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ impl BusFeed {
|
||||
match self.open_watched().await {
|
||||
Ok(watched) => {
|
||||
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 => {
|
||||
sleep(FRAME_INTERVAL).await;
|
||||
|
||||
Reference in new issue
Block a user