Upraven shell statusbar: odstraněn CPU usage a přidán periodický refresh vstupu
This commit is contained in:
+23
-1
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "drivers.h"
|
#include "drivers.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
#define KBD_HISTORY_MAX 32
|
#define KBD_HISTORY_MAX 32
|
||||||
#define KBD_HISTORY_LINE_MAX 128
|
#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_history_head = 0;
|
||||||
static int g_ctrl_down = 0;
|
static int g_ctrl_down = 0;
|
||||||
static int g_shift_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) {
|
static char apply_letter_case(char c) {
|
||||||
int upper = g_shift_down;
|
int upper = g_shift_down;
|
||||||
@@ -53,6 +56,11 @@ static const char keymap[128] = {
|
|||||||
void keyboard_init(void) {
|
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) {
|
int keyboard_try_read_key(void) {
|
||||||
unsigned char sc;
|
unsigned char sc;
|
||||||
int out = -1;
|
int out = -1;
|
||||||
@@ -225,13 +233,27 @@ static void history_push(const char *line) {
|
|||||||
int keyboard_readline(char *buffer, int max_len) {
|
int keyboard_readline(char *buffer, int max_len) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int history_nav = -1;
|
int history_nav = -1;
|
||||||
|
unsigned long last_refresh_tick = timer_ticks();
|
||||||
|
|
||||||
if (max_len <= 1) {
|
if (max_len <= 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
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) {
|
if (c == ASTER_KEY_F1 || c == ASTER_KEY_F2) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#define ASTER_KEY_RIGHT 0x106
|
#define ASTER_KEY_RIGHT 0x106
|
||||||
|
|
||||||
void keyboard_init(void);
|
void keyboard_init(void);
|
||||||
|
void keyboard_set_refresh_callback(void (*cb)(void), unsigned long interval_ticks);
|
||||||
int keyboard_read_key(void);
|
int keyboard_read_key(void);
|
||||||
int keyboard_try_read_key(void);
|
int keyboard_try_read_key(void);
|
||||||
int keyboard_readline(char *buffer, int max_len);
|
int keyboard_readline(char *buffer, int max_len);
|
||||||
|
|||||||
+5
-34
@@ -77,25 +77,6 @@ static unsigned int g_boot_splash_steps_done = 0;
|
|||||||
static char g_boot_splash_log[4][56];
|
static char g_boot_splash_log[4][56];
|
||||||
static unsigned int g_boot_splash_log_count = 0;
|
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) {
|
static usize append_text(char *dst, usize pos, usize max, const char *src) {
|
||||||
while (*src && pos + 1 < max) {
|
while (*src && pos + 1 < max) {
|
||||||
dst[pos++] = *src++;
|
dst[pos++] = *src++;
|
||||||
@@ -190,7 +171,6 @@ static void render_shell_statusbar(void) {
|
|||||||
usize total = memory_total_pages();
|
usize total = memory_total_pages();
|
||||||
usize freep = memory_free_pages();
|
usize freep = memory_free_pages();
|
||||||
usize used = total >= freep ? total - freep : 0;
|
usize used = total >= freep ? total - freep : 0;
|
||||||
unsigned int cpu = cpu_usage_percent();
|
|
||||||
char left[64];
|
char left[64];
|
||||||
char right[64];
|
char right[64];
|
||||||
char middle[64];
|
char middle[64];
|
||||||
@@ -227,21 +207,7 @@ static void render_shell_statusbar(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Right aligned label. */
|
|
||||||
right[0] = '\0';
|
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;
|
rlen = 0;
|
||||||
while (right[rlen]) ++rlen;
|
while (right[rlen]) ++rlen;
|
||||||
@@ -296,6 +262,10 @@ static void render_shell_statusbar(void) {
|
|||||||
display_set_cursor(save_row, save_col);
|
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) {
|
static inline void outb(u16 port, u8 value) {
|
||||||
__asm__ volatile ("outb %0, %1" : : "a"(value), "Nd"(port));
|
__asm__ volatile ("outb %0, %1" : : "a"(value), "Nd"(port));
|
||||||
}
|
}
|
||||||
@@ -2933,6 +2903,7 @@ void kmain(void) {
|
|||||||
|
|
||||||
boot_step_begin("Timer driver");
|
boot_step_begin("Timer driver");
|
||||||
timer_init((unsigned int)g_timer_hz);
|
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_ok("Timer driver");
|
||||||
|
|
||||||
boot_step_begin("Storage + AsterFS");
|
boot_step_begin("Storage + AsterFS");
|
||||||
|
|||||||
Reference in New Issue
Block a user