From 3bcd14f420508e5eea4cea1f333e37d0a6ac4ff9 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Fri, 24 Jun 2022 07:03:29 +0200 Subject: [PATCH] logging: Reduce code size for frontend only case Add early returns from functions which are not used when there is only one frontend in the system (no backends). This allows to significantly reduce logging code size in that configuration. Signed-off-by: Krzysztof Chruscinski --- subsys/logging/log_core.c | 19 +++++++++++++++---- tests/subsys/logging/log_api/src/main.c | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 2bbc3bf1067..14f647fbcac 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -197,6 +197,13 @@ void log_core_init(void) panic_mode = false; dropped_cnt = 0; + if (IS_ENABLED(CONFIG_LOG_FRONTEND)) { + log_frontend_init(); + if (IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY)) { + return; + } + } + /* Set default timestamp. */ if (sys_clock_hw_cycles_per_sec() > 1000000) { _timestamp_func = default_lf_get_timestamp; @@ -215,10 +222,6 @@ void log_core_init(void) if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) { z_log_runtime_filters_init(); } - - if (IS_ENABLED(CONFIG_LOG_FRONTEND)) { - log_frontend_init(); - } } static uint32_t activate_foreach_backend(uint32_t mask) @@ -245,6 +248,10 @@ static uint32_t z_log_init(bool blocking, bool can_sleep) { uint32_t mask = 0; + if (IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY)) { + return 0; + } + __ASSERT_NO_MSG(log_backend_count_get() < LOG_FILTERS_NUM_OF_SLOTS); int i; @@ -341,6 +348,9 @@ void z_impl_log_panic(void) if (IS_ENABLED(CONFIG_LOG_FRONTEND)) { log_frontend_panic(); + if (IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY)) { + goto out; + } } for (int i = 0; i < log_backend_count_get(); i++) { @@ -357,6 +367,7 @@ void z_impl_log_panic(void) } } +out: panic_mode = true; } diff --git a/tests/subsys/logging/log_api/src/main.c b/tests/subsys/logging/log_api/src/main.c index 87b2bc8a12f..96f716c9eb3 100644 --- a/tests/subsys/logging/log_api/src/main.c +++ b/tests/subsys/logging/log_api/src/main.c @@ -129,6 +129,10 @@ static void process_and_validate(bool backend2_enable, bool panic) return; } + if (IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY)) { + return; + } + mock_log_backend_validate(&backend1, panic); if (backend2_enable) {