Skip to content

Commit 9ac7d72

Browse files
tmlemankv2019i
authored andcommitted
ipc4: logging: Add dynamic log level control via logs_mask
Implement dynamic log level selection based on the logs_mask field from the IPC4_ENABLE_LOGS command, allowing the host to control firmware logging verbosity at runtime. Previously, logging was enabled with a fixed compile-time level (CONFIG_SOF_LOG_LEVEL), preventing dynamic control. This change parses the logs_mask[0] bits 0-4 to determine the requested log level and passes it to the backend. Mask bit mapping to Zephyr log levels: - bit 0 (critical/error) -> LOG_LEVEL_ERR (1) - bit 1 (high/warning) -> LOG_LEVEL_WRN (2) - bit 2 (medium) -> LOG_LEVEL_INF (3) - bit 3 (low/info) -> LOG_LEVEL_INF (3) - bit 4 (verbose/debug) -> LOG_LEVEL_DBG (4) The highest set bit determines the maximum log level. This allows the host to request ERROR-only logging for quiet operation, or DEBUG for verbose troubleshooting, without firmware recompilation. Additionally, log_backend_enable() is now always called (it is idempotent and safe for reconfiguration), removing the previous check that prevented level changes on already-active backends. A TODO comment documents that the mask handling should be improved with proper macros or structs in the future for better code maintainability, but the current implementation is sufficient. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
1 parent 49464c7 commit 9ac7d72

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/ipc/ipc4/logging.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,53 @@ int ipc4_logging_enable_logs(bool first_block,
140140
log_state = (const struct ipc4_log_state_info *)data;
141141

142142
if (log_state->enable) {
143+
uint32_t log_level = LOG_LEVEL_NONE; /* Default if no bits set */
144+
uint32_t mask = log_state->logs_mask[0];
145+
146+
/* TODO: Improve mask handling for better code maintainability
147+
* The logs_mask bits should be defined using proper macros or a struct
148+
* to improve readability and maintainability. Current hardcoded bit
149+
* positions are sufficient for now but should be refactored in the future.
150+
* Possible improvements:
151+
* - Define IPC4_LOG_MASK_* macros for each bit position
152+
* - Create a struct with bitfields for each priority level
153+
* - Add proper documentation in IPC4 specification headers
154+
*/
155+
156+
/* Determine log level from mask bits 0-4 (priority levels)
157+
* bit 0: critical & error -> LOG_LEVEL_ERR
158+
* bit 1: high & warning -> LOG_LEVEL_WRN
159+
* bit 2: medium -> LOG_LEVEL_INF
160+
* bit 3: low & info -> LOG_LEVEL_INF
161+
* bit 4: verbose & debug -> LOG_LEVEL_DBG
162+
* Check highest bit set to determine maximum log level
163+
*/
164+
if (mask & BIT(4))
165+
log_level = LOG_LEVEL_DBG;
166+
else if (mask & (BIT(3) | BIT(2)))
167+
log_level = LOG_LEVEL_INF;
168+
else if (mask & BIT(1))
169+
log_level = LOG_LEVEL_WRN;
170+
else if (mask & BIT(0))
171+
log_level = LOG_LEVEL_ERR;
172+
143173
adsp_mtrace_log_init(mtrace_log_hook);
144174
/* Initialize work queue if not already initialized */
145175
if (!log_work.work.handler)
146176
k_work_init_delayable(&log_work, log_work_handler);
147177

148-
/* Enable backend if not already active */
149-
if (!log_backend_is_active(log_backend))
150-
log_backend_enable(log_backend, mtrace_log_hook, CONFIG_SOF_LOG_LEVEL);
178+
/* Enable backend with determined log level
179+
*
180+
* Note: If CONFIG_LOG_RUNTIME_FILTERING is not enabled, the log_level
181+
* parameter has no effect - all logs are filtered at compile-time only.
182+
*
183+
* Note: Setting log_level to LOG_LEVEL_NONE will result in no logs being
184+
* output, as all runtime filters will be set to NONE. This behavior will
185+
* be useful in the future when per-source filtering can be specified via
186+
* IPC, allowing selective enabling of specific log sources while keeping
187+
* others disabled.
188+
*/
189+
log_backend_enable(log_backend, mtrace_log_hook, log_level);
151190

152191
mtrace_aging_timer = log_state->aging_timer_period;
153192
if (mtrace_aging_timer < IPC4_MTRACE_AGING_TIMER_MIN_MS) {

0 commit comments

Comments
 (0)