diff options
author | Richard Braun <rbraun@sceen.net> | 2019-05-19 18:00:06 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2019-05-19 18:00:06 +0200 |
commit | c45d94a590d778c26dc78386c41231fed9df1b14 (patch) | |
tree | 5449081427d9f22aa45cde141a28a7b5f30f2cbd | |
parent | 294946552c4330ecb846d6b57cf81034844b8abf (diff) |
kern/{log,shell}: use a bulletin for initial log dump notification
-rw-r--r-- | kern/log.c | 42 | ||||
-rw-r--r-- | kern/log.h | 6 | ||||
-rw-r--r-- | kern/shell.c | 49 | ||||
-rw-r--r-- | kern/shell.h | 8 |
4 files changed, 49 insertions, 56 deletions
@@ -26,6 +26,7 @@ #include <string.h> #include <kern/arg.h> +#include <kern/bulletin.h> #include <kern/init.h> #include <kern/log.h> #include <kern/macros.h> @@ -54,9 +55,8 @@ static char log_buffer[LOG_BUFFER_SIZE]; static unsigned int log_nr_overruns; -#ifdef CONFIG_SHELL -static bool log_shell_started = false; -#endif +static bool log_bulletin_published; +static struct bulletin log_bulletin; /* * Global lock. @@ -141,25 +141,6 @@ log_print_record(const struct log_record *record, unsigned int level) } } -#ifdef CONFIG_SHELL - -static void -log_start_shell(unsigned long *flags) -{ - if (log_shell_started) { - return; - } - - log_shell_started = true; - spinlock_unlock_intr_restore(&log_lock, *flags); - shell_start(); - spinlock_lock_intr_save(&log_lock, flags); -} - -#else /* CONFIG_SHELL */ -#define log_start_shell(flags) -#endif /* CONFIG_SHELL */ - static void log_run(void *arg) { @@ -191,12 +172,10 @@ log_run(void *arg) break; } - /* - * Starting the shell when the log thread sleeps for the first - * time serializes log messages and shell prompt, resulting in - * a clean ordered output. - */ - log_start_shell(&flags); + if (!log_bulletin_published) { + bulletin_publish(&log_bulletin, 0); + log_bulletin_published = true; + } thread_sleep(&log_lock, &log_mbuf, "log_mbuf"); } @@ -297,6 +276,7 @@ log_setup(void) mbuf_init(&log_mbuf, log_buffer, sizeof(log_buffer), sizeof(struct log_record)); spinlock_init(&log_lock); + bulletin_init(&log_bulletin); boot_log_info(); arg_log_info(); @@ -539,3 +519,9 @@ log_vdebug(const char *format, va_list ap) { return log_vmsg(LOG_DEBUG, format, ap); } + +struct bulletin * +log_get_bulletin(void) +{ + return &log_bulletin; +} @@ -85,6 +85,12 @@ int log_vdebug(const char *format, va_list ap) __attribute__((format(printf, 1, 0))); /* + * The bulletin returned by this function is used to notify the initial log + * dump so that console output is well ordered. + */ +struct bulletin * log_get_bulletin(void); + +/* * This init operation provides : * - message logging * diff --git a/kern/shell.c b/kern/shell.c index 1fff5d26..65c995d6 100644 --- a/kern/shell.c +++ b/kern/shell.c @@ -26,6 +26,7 @@ #include <stdint.h> #include <string.h> +#include <kern/bulletin.h> #include <kern/hash.h> #include <kern/init.h> #include <kern/log.h> @@ -67,6 +68,8 @@ struct shell_esc_seq { #define SHELL_ERASE_BS '\b' #define SHELL_ERASE_DEL '\x7f' +static struct bulletin_sub shell_log_bulletin_sub; + static const char * shell_find_word(const char *str) { @@ -1114,7 +1117,7 @@ shell_process_ctrl_char(struct shell *shell, char c) return 0; } -void +static void shell_run(struct shell *shell) { int c, error, escape; @@ -1204,12 +1207,37 @@ shell_main_vfprintf(void *io_object, const char *format, va_list ap) vprintf(format, ap); } +static void +shell_main_run(void *arg) +{ + shell_run(arg); +} + +static void +shell_start(uintptr_t value, void *arg) +{ + struct thread_attr attr; + struct thread *thread; + int error; + + (void)value; + (void)arg; + + thread_attr_init(&attr, THREAD_KERNEL_PREFIX "shell"); + thread_attr_set_detached(&attr); + error = thread_create(&thread, &attr, shell_main_run, &shell_main); + error_check(error, "thread_create"); +} + static int __init shell_setup(void) { shell_cmd_set_init(&shell_main_cmd_set); shell_init(&shell_main, &shell_main_cmd_set, shell_main_getc, shell_main_vfprintf, NULL); + bulletin_subscribe(log_get_bulletin(), &shell_log_bulletin_sub, + shell_start, NULL); + return 0; } @@ -1223,22 +1251,3 @@ shell_get_main_cmd_set(void) { return &shell_main_cmd_set; } - -static void -shell_main_run(void *arg) -{ - shell_run(arg); -} - -void __init -shell_start(void) -{ - struct thread_attr attr; - struct thread *thread; - int error; - - thread_attr_init(&attr, THREAD_KERNEL_PREFIX "shell"); - thread_attr_set_detached(&attr); - error = thread_create(&thread, &attr, shell_main_run, &shell_main); - error_check(error, "thread_create"); -} diff --git a/kern/shell.h b/kern/shell.h index bde2a341..c01c719d 100644 --- a/kern/shell.h +++ b/kern/shell.h @@ -115,13 +115,6 @@ void shell_init(struct shell *shell, struct shell_cmd_set *cmd_set, void *io_object); /* - * Run the shell. - * - * This function doesn't return. - */ -void shell_run(struct shell *shell); - -/* * Obtain the command set associated with a shell. */ struct shell_cmd_set * shell_get_cmd_set(struct shell *shell); @@ -141,6 +134,5 @@ void shell_vprintf(struct shell *shell, const char *format, va_list ap) INIT_OP_DECLARE(shell_setup); struct shell_cmd_set * shell_get_main_cmd_set(void); -void shell_start(void); #endif /* KERN_SHELL_H */ |