diff --git a/src/include/sof/trace/trace.h b/src/include/sof/trace/trace.h index 86e2c7d95983..13c9710939c3 100644 --- a/src/include/sof/trace/trace.h +++ b/src/include/sof/trace/trace.h @@ -150,8 +150,8 @@ void trace_on(void); void trace_off(void); void trace_init(struct sof *sof); void trace_log(bool send_atomic, const void *log_entry, - const struct tr_ctx *ctx, uint32_t id_1, uint32_t id_2, - int arg_count, ...); + const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, + uint32_t id_2, int arg_count, ...); #define _trace_event_with_ids(lvl, class, ctx, id_1, id_2, format, ...) \ _log_message(false, lvl, class, ctx, id_1, id_2, \ @@ -201,7 +201,7 @@ do { \ META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \ BASE_LOG_ASSERT_FAIL_MSG \ ); \ - trace_log(atomic, &log_entry, ctx, id_1, id_2, \ + trace_log(atomic, &log_entry, ctx, lvl, id_1, id_2, \ PP_NARG(__VA_ARGS__), ##__VA_ARGS__); \ } while (0) diff --git a/src/trace/trace.c b/src/trace/trace.c index a8b7193ff5cc..411d3a4235f4 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -96,9 +96,22 @@ static inline void mtrace_event(const char *data, uint32_t length) } #endif /* CONFIG_TRACEM */ +/** + * \brief Runtime trace filtering + * \param lvl log level (LOG_LEVEL_ ERROR, INFO, DEBUG ...) + * \param uuid uuid address + * \return false when trace is filtered out, otherwise true + */ +static inline bool trace_filter_pass(uint32_t lvl, + const struct tr_ctx *ctx) +{ + /* LOG_LEVEL_CRITICAL has low value, LOG_LEVEL_VERBOSE high */ + return lvl <= ctx->level; +} + void trace_log(bool send_atomic, const void *log_entry, - const struct tr_ctx *ctx, uint32_t id_1, uint32_t id_2, - int arg_count, ...) + const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, + uint32_t id_2, int arg_count, ...) { uint32_t data[MESSAGE_SIZE_DWORDS(_TRACE_EVENT_MAX_ARGUMENT_COUNT)]; const int message_size = MESSAGE_SIZE(arg_count); @@ -109,7 +122,7 @@ void trace_log(bool send_atomic, const void *log_entry, unsigned long flags; #endif /* CONFIG_TRACEM */ - if (!trace->enable) { + if (!trace->enable || !trace_filter_pass(lvl, ctx)) { platform_shared_commit(trace, sizeof(*trace)); return; } diff --git a/test/cmocka/src/common_mocks.c b/test/cmocka/src/common_mocks.c index 0ea7f6460b80..e53279e9636f 100644 --- a/test/cmocka/src/common_mocks.c +++ b/test/cmocka/src/common_mocks.c @@ -76,12 +76,13 @@ void WEAK __panic(uint32_t p, char *filename, uint32_t linenum) } void WEAK trace_log(bool send_atomic, const void *log_entry, - const struct tr_ctx *ctx, uint32_t id_1, uint32_t id_2, - int arg_count, ...) + const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, + uint32_t id_2, int arg_count, ...) { (void) send_atomic; (void) log_entry; (void) ctx; + (void) lvl; (void) id_1; (void) id_2; (void) arg_count;