From 92e070c50f51491f1336b94215b5bb85332615cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Kala=C5=A1=20=28Floxen=29?= Date: Sun, 12 Jul 2026 12:34:30 +0200 Subject: [PATCH] =?UTF-8?q?Upraven=20shell=20statusbar:=20odstran=C4=9Bn?= =?UTF-8?q?=20CPU=20usage=20a=20p=C5=99id=C3=A1n=20periodick=C3=BD=20refre?= =?UTF-8?q?sh=20vstupu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/keyboard.c | 24 +++++++++++++++++++++++- include/drivers.h | 1 + kernel/main.c | 39 +++++---------------------------------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/drivers/keyboard.c b/drivers/keyboard.c index 07320d5..cb41613 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -13,6 +13,7 @@ #include "display.h" #include "drivers.h" +#include "timer.h" #define KBD_HISTORY_MAX 32 #define KBD_HISTORY_LINE_MAX 128 @@ -22,6 +23,8 @@ static int g_history_count = 0; static int g_history_head = 0; static int g_ctrl_down = 0; static int g_shift_down = 0; +static void (*g_refresh_cb)(void) = 0; +static unsigned long g_refresh_interval_ticks = 0; static char apply_letter_case(char c) { int upper = g_shift_down; @@ -53,6 +56,11 @@ static const char keymap[128] = { void keyboard_init(void) { } +void keyboard_set_refresh_callback(void (*cb)(void), unsigned long interval_ticks) { + g_refresh_cb = cb; + g_refresh_interval_ticks = interval_ticks; +} + int keyboard_try_read_key(void) { unsigned char sc; int out = -1; @@ -225,13 +233,27 @@ static void history_push(const char *line) { int keyboard_readline(char *buffer, int max_len) { int i = 0; int history_nav = -1; + unsigned long last_refresh_tick = timer_ticks(); if (max_len <= 1) { return 0; } for (;;) { - int c = keyboard_read_key(); + int c = keyboard_try_read_key(); + + if (c == -1) { + if (g_refresh_cb && g_refresh_interval_ticks > 0) { + unsigned long now = timer_ticks(); + if ((now - last_refresh_tick) >= g_refresh_interval_ticks) { + g_refresh_cb(); + last_refresh_tick = now; + } + } + + __asm__ volatile ("pause"); + continue; + } if (c == ASTER_KEY_F1 || c == ASTER_KEY_F2) { continue; diff --git a/include/drivers.h b/include/drivers.h index 59a5f6b..7d38da5 100644 --- a/include/drivers.h +++ b/include/drivers.h @@ -24,6 +24,7 @@ #define ASTER_KEY_RIGHT 0x106 void keyboard_init(void); +void keyboard_set_refresh_callback(void (*cb)(void), unsigned long interval_ticks); int keyboard_read_key(void); int keyboard_try_read_key(void); int keyboard_readline(char *buffer, int max_len); diff --git a/kernel/main.c b/kernel/main.c index 256e49c..0163730 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -77,25 +77,6 @@ static unsigned int g_boot_splash_steps_done = 0; static char g_boot_splash_log[4][56]; static unsigned int g_boot_splash_log_count = 0; -static unsigned int cpu_usage_percent(void) { - process_t *table = process_table(); - usize count = process_count(); - usize active = 0; - usize i; - - if (count == 0) { - return 0; - } - - for (i = 0; i < count; ++i) { - if (table[i].state == PROCESS_READY || table[i].state == PROCESS_RUNNING) { - ++active; - } - } - - return (unsigned int)((active * 100U) / count); -} - static usize append_text(char *dst, usize pos, usize max, const char *src) { while (*src && pos + 1 < max) { dst[pos++] = *src++; @@ -190,7 +171,6 @@ static void render_shell_statusbar(void) { usize total = memory_total_pages(); usize freep = memory_free_pages(); usize used = total >= freep ? total - freep : 0; - unsigned int cpu = cpu_usage_percent(); char left[64]; char right[64]; char middle[64]; @@ -227,21 +207,7 @@ static void render_shell_statusbar(void) { } } - /* Right aligned label. */ right[0] = '\0'; - if (!g_status_marquee_only) { - const char *prefix = "cpu usage: "; - usize p = 0; - while (prefix[p] && p < sizeof(right) - 1) { - right[p] = prefix[p]; - ++p; - } - p = append_uint(right, p, sizeof(right), cpu); - if (p + 1 < sizeof(right)) { - right[p++] = '%'; - } - right[p] = '\0'; - } rlen = 0; while (right[rlen]) ++rlen; @@ -296,6 +262,10 @@ static void render_shell_statusbar(void) { display_set_cursor(save_row, save_col); } +static void shell_status_refresh_callback(void) { + render_shell_statusbar(); +} + static inline void outb(u16 port, u8 value) { __asm__ volatile ("outb %0, %1" : : "a"(value), "Nd"(port)); } @@ -2933,6 +2903,7 @@ void kmain(void) { boot_step_begin("Timer driver"); timer_init((unsigned int)g_timer_hz); + keyboard_set_refresh_callback(shell_status_refresh_callback, g_timer_hz ? g_timer_hz : 100UL); boot_step_ok("Timer driver"); boot_step_begin("Storage + AsterFS");