mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] console: scale number of log messages with available RAM
@ 2024-03-06 18:45 Ahmad Fatoum
  2024-03-06 18:45 ` [PATCH 2/2] commands: dmesg: support aborting dmesg output with ctrl-c Ahmad Fatoum
  2024-03-08  7:02 ` [PATCH 1/2] console: scale number of log messages with available RAM Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-03-06 18:45 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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>
---
 common/console_common.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/common/console_common.c b/common/console_common.c
index c78581299248..d25fb0dc5dde 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)
 {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] commands: dmesg: support aborting dmesg output with ctrl-c
  2024-03-06 18:45 [PATCH 1/2] console: scale number of log messages with available RAM Ahmad Fatoum
@ 2024-03-06 18:45 ` Ahmad Fatoum
  2024-03-08  7:02 ` [PATCH 1/2] console: scale number of log messages with available RAM Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-03-06 18:45 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

dmesg output can get very long, especially if debug messages are
compiled in and the maximum number of retained log messages is
increased.

Therefore, follow what we do for other potentially long-running
commands and allow the user to abort it with ctrl+c.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/dmesg.c        | 6 ++++--
 common/console_common.c | 6 +++++-
 include/linux/printk.h  | 2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/commands/dmesg.c b/commands/dmesg.c
index 83410234e1d6..8a60f075076e 100644
--- a/commands/dmesg.c
+++ b/commands/dmesg.c
@@ -76,7 +76,7 @@ static unsigned dmesg_get_levels(const char *__args)
 
 static int do_dmesg(int argc, char *argv[])
 {
-	int opt, i;
+	int opt, ret, i;
 	int delete_buf = 0, emit = 0;
 	unsigned flags = 0, levels = 0;
 	char *set = NULL;
@@ -148,7 +148,9 @@ static int do_dmesg(int argc, char *argv[])
 		return 0;
 	}
 
-	log_print(flags, levels);
+	ret = log_print(flags, levels);
+	if (ret)
+		return 1;
 
 	if (delete_buf)
 		log_clean(10);
diff --git a/common/console_common.c b/common/console_common.c
index d25fb0dc5dde..631756e4800c 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -208,7 +208,7 @@ int log_writefile(const char *filepath)
 	return ret < 0 ? ret : nbytes;
 }
 
-void log_print(unsigned flags, unsigned levels)
+int log_print(unsigned flags, unsigned levels)
 {
 	struct log_entry *log;
 	unsigned long last = 0;
@@ -219,6 +219,8 @@ void log_print(unsigned flags, unsigned levels)
 
 		if (levels && !(levels & (1 << log->level)))
 			continue;
+		if (ctrlc())
+			return -EINTR;
 
 		if (!(flags & (BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME
 			       | BAREBOX_LOG_DIFF_TIME)))
@@ -247,6 +249,8 @@ void log_print(unsigned flags, unsigned levels)
 
 		printf("%s", log->msg);
 	}
+
+	return 0;
 }
 
 int printf(const char *fmt, ...)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 0e9604bbe967..07403ea60cb7 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -189,7 +189,7 @@ extern void log_clean(unsigned int limit);
 #define BAREBOX_LOG_PRINT_TIME		BIT(0)
 
 int log_writefile(const char *filepath);
-void log_print(unsigned flags, unsigned levels);
+int log_print(unsigned flags, unsigned levels);
 
 struct va_format {
 	const char *fmt;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] console: scale number of log messages with available RAM
  2024-03-06 18:45 [PATCH 1/2] console: scale number of log messages with available RAM Ahmad Fatoum
  2024-03-06 18:45 ` [PATCH 2/2] commands: dmesg: support aborting dmesg output with ctrl-c Ahmad Fatoum
@ 2024-03-08  7:02 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-03-08  7:02 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Wed, 06 Mar 2024 19:45:18 +0100, Ahmad Fatoum wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/2] console: scale number of log messages with available RAM
      https://git.pengutronix.de/cgit/barebox/commit/?id=2c04db069871 (link may not be stable)
[2/2] commands: dmesg: support aborting dmesg output with ctrl-c
      https://git.pengutronix.de/cgit/barebox/commit/?id=9eb0055d0ae9 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-08  7:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-06 18:45 [PATCH 1/2] console: scale number of log messages with available RAM Ahmad Fatoum
2024-03-06 18:45 ` [PATCH 2/2] commands: dmesg: support aborting dmesg output with ctrl-c Ahmad Fatoum
2024-03-08  7:02 ` [PATCH 1/2] console: scale number of log messages with available RAM Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox