Commit 57e8d5ec authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Alberto Escolar
Browse files

log: fix log_flush()

The logging thread is usually woken up by a timer, if the timer
period is longer than 10ms, log_flush() can iterate multiple times
needlessly, while waiting for the next timer. Instead wake up the
logging thread to let it flush the queue immediately. Besides a
hard-coded polling period of 10ms is too long for some applications,
make it a Kconfig parameter.

Signed-off-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
parent 4eb917f8
Loading
Loading
Loading
Loading
+12 −0
Changes for subsys/logging/Kconfig.mode: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -74,3 +74,15 @@ config LOG_DEFAULT_MINIMAL
config LOG_MULTIDOMAIN
	bool "Multi-domain logger"
	select LOG_TIMESTAMP_64BIT

if LOG_MODE_DEFERRED

config LOG_FLUSH_SLEEP_US
	int "Sleep time when flushing the log queue, microseconds"
	range 100 100000
	default 10000
	help
	  In deferred logging mode this is the time, used in
	  log_flush() on each sleep iteration in microseconds.

endif # LOG_MODE_DEFERRED
+2 −1
Changes for subsys/logging/log_core.c: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1003,7 +1003,8 @@ void log_flush(void)
{
	if (IS_ENABLED(CONFIG_LOG_PROCESS_THREAD)) {
		while (atomic_get(&buffered_cnt)) {
			k_sleep(K_MSEC(10));
			log_thread_trigger();
			k_sleep(K_USEC(CONFIG_LOG_FLUSH_SLEEP_US));
		}
	} else {
		while (LOG_PROCESS()) {