diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2024-03-06 19:45:18 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-03-08 08:02:01 +0100 |
commit | 2c04db06987189ec310f2f02a532604206b8cac5 (patch) | |
tree | bc96245e4acc0c3d3e17bb6b42f9c29bd747930f /common | |
parent | 7153d3cce08ada0101e87b08d4becbdc36348364 (diff) | |
download | barebox-2c04db06987189ec310f2f02a532604206b8cac5.tar.gz barebox-2c04db06987189ec310f2f02a532604206b8cac5.tar.xz |
console: scale number of log messages with available RAM
The default value of 1000 messages is too small with
CONFIG_COMPILE_LOGLEVEL=7, because the many driver debug messages
will evict any earlier error or warning messages that have been
in the log.
Assuming a log record size of 128 bytes, 1000 messages translates to
128kB, which has quite a bit of breathing room. Let's instead scale the
maximum with the available memory: one message per 32KiB of malloc area.
This gives us:
- 64M total memory -> ~32M malloc area -> 1K messages (128K bytes)
- 256M total memory -> ~128M malloc area -> 4K messages (512K bytes)
- 1G total memory -> ~512M malloc area -> 16K messages ( 2M bytes)
Users for which this is too excessive can still configure this via the
environment.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20240306184519.626594-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/console_common.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/common/console_common.c b/common/console_common.c index c785812992..d25fb0dc5d 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -14,12 +14,14 @@ #include <environment.h> #include <globalvar.h> #include <magicvar.h> +#include <memory.h> #include <of.h> #include <password.h> #include <clock.h> #include <malloc.h> #include <linux/pstore.h> #include <linux/math64.h> +#include <linux/sizes.h> #include <linux/overflow.h> #ifndef CONFIG_CONSOLE_NONE @@ -37,7 +39,7 @@ int barebox_loglevel = CONFIG_DEFAULT_LOGLEVEL; LIST_HEAD(barebox_logbuf); static int barebox_logbuf_num_messages; -static int barebox_log_max_messages = 1000; +static int barebox_log_max_messages; static void log_del(struct log_entry *log) { @@ -173,15 +175,18 @@ bool console_allow_color(void) static int console_common_init(void) { - if (IS_ENABLED(CONFIG_LOGBUF)) + if (IS_ENABLED(CONFIG_LOGBUF)) { + barebox_log_max_messages + = clamp(mem_malloc_size() / SZ_32K, 1000UL, 100000UL); globalvar_add_simple_int("log_max_messages", &barebox_log_max_messages, "%d"); + } globalvar_add_simple_bool("allow_color", &__console_allow_color); return globalvar_add_simple_int("loglevel", &barebox_loglevel, "%d"); } -device_initcall(console_common_init); +core_initcall(console_common_init); int log_writefile(const char *filepath) { |