12#ifndef __SOF_TRACE_TRACE_SOFLOGGER_H__
13#define __SOF_TRACE_TRACE_SOFLOGGER_H__
16#include <platform/trace/trace.h>
41#define _DECLARE_LOG_ENTRY(lvl, format, comp_class, n_params) \
42 __section(".static_log." #lvl) \
43 static const struct { \
45 uint32_t component_class; \
46 uint32_t params_num; \
48 uint32_t file_name_len; \
50 const char file_name[sizeof(RELATIVE_FILE)]; \
51 const char text[sizeof(format)]; \
57 sizeof(RELATIVE_FILE), \
63#define _TRACE_EVENT_MAX_ARGUMENT_COUNT 4
102#define trace_event_with_ids(class, ctx, id_1, id_2, format, ...) \
103 _trace_event_with_ids(LOG_LEVEL_INFO, class, ctx, id_1, id_2, \
104 format, ##__VA_ARGS__)
106#define trace_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
107 _trace_event_atomic_with_ids(LOG_LEVEL_INFO, class, ctx, id_1, id_2, \
108 format, ##__VA_ARGS__)
110#define trace_warn_with_ids(class, ctx, id_1, id_2, format, ...) \
111 _trace_event_with_ids(LOG_LEVEL_WARNING, class, ctx, id_1, id_2, \
112 format, ##__VA_ARGS__)
114#define trace_warn_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
115 _trace_event_atomic_with_ids(LOG_LEVEL_WARNING, class, \
117 format, ##__VA_ARGS__)
156typedef void (*
log_func_t)(
bool send_atomic,
const void *log_entry,
const struct tr_ctx *ctx,
157 uint32_t lvl, uint32_t id_1, uint32_t id_2,
int arg_count, va_list args);
172 uint32_t lvl, uint32_t id_1, uint32_t id_2,
int arg_count, va_list args);
187 uint32_t lvl, uint32_t id_1, uint32_t id_2,
int arg_count, va_list args);
209#define _trace_event_with_ids(lvl, class, ctx, id_1, id_2, format, ...) \
210 _log_message(trace_log_filtered, false, lvl, class, ctx, id_1, id_2, format, ##__VA_ARGS__)
212#define _trace_event_atomic_with_ids(lvl, class, ctx, id_1, id_2, format, ...) \
213 _log_message(trace_log_filtered, true, lvl, class, ctx, id_1, id_2, format, ##__VA_ARGS__)
237# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_INFO
239# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_DEBUG
242# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_ERROR
258 const struct tr_ctx *ctx,
const uint32_t lvl,
259 uint32_t id_1, uint32_t id_2,
int arg_count, ...);
268extern int host_trace_level;
270char *get_trace_class(uint32_t trace_class);
271#define _log_message(ignored_log_func, atomic, level, comp_class, ctx, id_1, id_2, format, ...) \
277 char slevel[5][4] = {"dis", "err", "wrn", "inf", "dbg"}; \
278 char *msg = "(%s:%d) " format; \
279 if (level <= host_trace_level) { \
280 gettimeofday(&tv, NULL); \
281 fprintf(stderr, "trace: [%ld.%6.6ld] <%s> ", tv.tv_sec, tv.tv_usec, \
283 fprintf(stderr, msg, strrchr(__FILE__, '/') + 1, \
284 __LINE__, ##__VA_ARGS__); \
285 fprintf(stderr, "\n"); \
289#define trace_point(x) do {} while (0)
293#define trace_point(x) platform_trace_point(x)
295#define BASE_LOG_ASSERT_FAIL_MSG \
296unsupported_amount_of_params_in_trace_event\
297_thrown_from_macro_BASE_LOG_in_trace_h
299#define CT_ASSERT(COND, MESSAGE) \
300 ((void)sizeof(char[1 - 2 * !(COND)]))
302#define trace_check_size_uint32(a) \
303 CT_ASSERT(sizeof(a) <= sizeof(uint32_t), "error: trace argument is bigger than a uint32_t");
305#define STATIC_ASSERT_ARG_SIZE(...) \
306 META_MAP(1, trace_check_size_uint32, __VA_ARGS__)
313#define _log_message(log_func, atomic, lvl, comp_class, ctx, id_1, id_2, format, ...) \
315 _DECLARE_LOG_ENTRY(lvl, format, comp_class, \
316 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \
317 STATIC_ASSERT_ARG_SIZE(__VA_ARGS__); \
318 STATIC_ASSERT(_TRACE_EVENT_MAX_ARGUMENT_COUNT >= \
319 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
320 BASE_LOG_ASSERT_FAIL_MSG \
322 _log_sofdict(log_func, atomic, &log_entry, ctx, lvl, id_1, id_2, \
323 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), ##__VA_ARGS__); \
324 _log_nodict(atomic, META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
325 lvl, format, ##__VA_ARGS__); \
332#define _log_nodict(atomic, arg_count, lvl, format, ...) \
334 if ((lvl) <= MTRACE_DUPLICATION_LEVEL) \
335 printk("%llu " format "\n", k_cycle_get_64(), \
339#define _log_nodict(atomic, n_args, lvl, format, ...)
346#define tracev_event_with_ids(class, ctx, id_1, id_2, format, ...) \
347 _trace_event_with_ids(LOG_LEVEL_VERBOSE, class, \
349 format, ##__VA_ARGS__)
351#define tracev_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
352 _trace_event_atomic_with_ids(LOG_LEVEL_VERBOSE, class, \
354 format, ##__VA_ARGS__)
357#define tracev_event_with_ids(class, ctx, id_1, id_2, format, ...) \
358 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
359#define tracev_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
360 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
367#define _trace_error_with_ids(class, ctx, id_1, id_2, format, ...) \
368 _log_message(trace_log_filtered, true, LOG_LEVEL_CRITICAL, class, ctx, id_1, \
369 id_2, format, ##__VA_ARGS__)
370#define trace_error_with_ids(class, ctx, id_1, id_2, format, ...) \
371 _trace_error_with_ids(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
372#define trace_error_atomic_with_ids(...) trace_error_with_ids(__VA_ARGS__)
376#define trace_error_with_ids(...) trace_event_with_ids(__VA_ARGS__)
377#define trace_error_atomic_with_ids(...) \
378 trace_event_atomic_with_ids(__VA_ARGS__)
393#define trace_dev_err(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
394 trace_error_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
395 get_id_m(dev), get_subid_m(dev), \
399#define trace_dev_warn(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
400 trace_warn_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
401 get_id_m(dev), get_subid_m(dev), \
405#define trace_dev_info(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
406 trace_event_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
407 get_id_m(dev), get_subid_m(dev), \
411#define trace_dev_dbg(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
412 tracev_event_with_ids(_TRACE_INV_CLASS, \
413 get_ctx_m(dev), get_id_m(dev), \
414 get_subid_m(dev), fmt, ##__VA_ARGS__)
418#define tr_err_atomic(ctx, fmt, ...) \
419 trace_error_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
420 _TRACE_INV_ID, _TRACE_INV_ID, \
423#define tr_warn_atomic(ctx, fmt, ...) \
424 trace_warn_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
425 _TRACE_INV_ID, _TRACE_INV_ID, \
428#define tr_info_atomic(ctx, fmt, ...) \
429 trace_event_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
430 _TRACE_INV_ID, _TRACE_INV_ID, \
433#define tr_dbg_atomic(ctx, fmt, ...) \
434 tracev_event_atomic_with_ids(_TRACE_INV_CLASS, ctx, \
435 _TRACE_INV_ID, _TRACE_INV_ID, \
438#define tr_err(ctx, fmt, ...) \
439 trace_error_with_ids(_TRACE_INV_CLASS, ctx, \
440 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
442#define tr_warn(ctx, fmt, ...) \
443 trace_warn_with_ids(_TRACE_INV_CLASS, ctx, \
444 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
446#define tr_info(ctx, fmt, ...) \
447 trace_event_with_ids(_TRACE_INV_CLASS, ctx, \
448 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
451#define tr_dbg(ctx, fmt, ...) \
452 tracev_event_with_ids(_TRACE_INV_CLASS, ctx, \
453 _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
464#define mtrace_printf(log_level, format_str, ...) \
466 STATIC_ASSERT(META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__) \
467 <= _TRACE_EVENT_MAX_ARGUMENT_COUNT, \
468 too_many_mtrace_printf_arguments); \
469 _DECLARE_LOG_ENTRY(log_level, format_str, _TRACE_INV_CLASS, \
470 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \
471 mtrace_dict_entry(true, (uint32_t)&log_entry, \
472 META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
void mtrace_event(const char *complete_packet, uint32_t length)
Posts a fully prepared log header and log entry packet to mtrace buffer.
void(* log_func_t)(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args)
Function pointer type for formatted trace logger backends.
Definition trace-soflogger.h:156
void trace_flush_dma_to_mbox(void)
Flush buffered trace data from DMA buffer to Mailbox Window.
void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args)
Emit an unfiltered dictionary trace message directly to buffers.
void mtrace_dict_entry(bool atomic_context, uint32_t log_entry_pointer, int n_args,...)
Appends one SOF dictionary entry and log statement to shared memory mtrace.
void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args)
Emit a filtered dictionary trace message.
void trace_init(struct sof *sof)
Initialize the trace subsystem and allocate global trace buffers.
void _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry, const struct tr_ctx *ctx, const uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count,...)
Internal dictionary logger formatting and dispatch helper.
struct sof_ipc_trace_filter_elem * trace_filter_fill(struct sof_ipc_trace_filter_elem *elem, struct sof_ipc_trace_filter_elem *end, struct trace_filter *filter)
Populate an IPC trace filter element array.
int trace_filter_update(const struct trace_filter *elem)
Update runtime trace filtering configuration from IPC payload.
void trace_off(void)
Globally pause trace event logging.
static struct trace * trace_get(void)
Retrieve global trace subsystem context from SOF runtime.
Definition trace-soflogger.h:70
void trace_on(void)
Globally resume trace event logging.
struct sof * sof_get(void)
Get the global Sound Open Firmware runtime instance pointer.
User-space ABI log levels and binary trace packet header definitions.
part of sof_ipc_trace_filter, ABI3.17
Definition trace.h:74
General firmware context.
Definition sof.h:50
struct trace * trace
Definition sof.h:67
Runtime trace filter criteria for components and pipelines.
Definition trace-soflogger.h:31
uint32_t uuid_id
Component UUID type identifier, or 0 for wildcard.
Definition trace-soflogger.h:32
int32_t log_level
Target log level threshold (LOG_LEVEL_*)
Definition trace-soflogger.h:35
int32_t pipe_id
Pipeline ID, or -1 for wildcard.
Definition trace-soflogger.h:34
int32_t comp_id
Component ID, or -1 for wildcard.
Definition trace-soflogger.h:33