Skip to content

Commit 50eb5c9

Browse files
marc-hblgirdwood
authored andcommitted
trace.c: add mtrace_printf() low-level shortcut
Direct access to mbox shared memory logging when DMA tracing is either not initialized yet or disabled or found broken for any reason. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 532642b commit 50eb5c9

3 files changed

Lines changed: 58 additions & 4 deletions

File tree

src/include/sof/trace/trace.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,31 @@ struct tr_ctx {
413413
_TRACE_INV_ID, _TRACE_INV_ID, \
414414
fmt, ##__VA_ARGS__)
415415

416+
/** Direct, low-level access to mbox / shared memory logging when DMA
417+
* tracing is either not initialized yet or disabled or found broken for
418+
* any reason.
419+
* To keep it simpler than and with minimal dependencies on
420+
* the huge number of lines above, this does not check arguments at compile
421+
* time.
422+
* There is neither log level filtering, throttling or any other
423+
* advanced feature.
424+
*/
425+
#define mtrace_printf(log_level, format_str, ...) \
426+
do { \
427+
STATIC_ASSERT(META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__) \
428+
<= _TRACE_EVENT_MAX_ARGUMENT_COUNT, \
429+
too_many_mtrace_printf_arguments); \
430+
_DECLARE_LOG_ENTRY(log_level, format_str, _TRACE_INV_CLASS, \
431+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \
432+
mtrace_dict_entry((uint32_t)&log_entry, \
433+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
434+
##__VA_ARGS__); \
435+
} while (0)
436+
437+
/** Adds log_header prefix and appends arguments before sending */
438+
void mtrace_dict_entry(uint32_t log_entry_pointer, int n_args, ...);
439+
440+
/** Posts a fully prepared log header + log entry */
441+
void mtrace_event(const char *complete_packet, uint32_t length);
442+
416443
#endif /* __SOF_TRACE_TRACE_H__ */

src/trace/trace.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct trace {
7070

7171
#define TRACE_ID_MASK ((1 << TRACE_ID_LENGTH) - 1)
7272

73-
static void put_header(uint32_t *dst, const struct sof_uuid_entry *uid,
73+
static void put_header(void *dst, const struct sof_uuid_entry *uid,
7474
uint32_t id_1, uint32_t id_2,
7575
uint32_t entry, uint64_t timestamp)
7676
{
@@ -93,7 +93,7 @@ static void put_header(uint32_t *dst, const struct sof_uuid_entry *uid,
9393
}
9494

9595
/** Ring buffer for the mailbox trace */
96-
static inline void mtrace_event(const char *data, uint32_t length)
96+
void mtrace_event(const char *data, uint32_t length)
9797
{
9898
struct trace *trace = trace_get();
9999
char *t = (char *)MAILBOX_TRACE_BASE;
@@ -531,3 +531,22 @@ void trace_init(struct sof *sof)
531531

532532
dma_trace_init_early(sof);
533533
}
534+
535+
void mtrace_dict_entry(uint32_t dict_entry_address, int n_args, ...)
536+
{
537+
va_list ap;
538+
int i;
539+
char packet[MESSAGE_SIZE(_TRACE_EVENT_MAX_ARGUMENT_COUNT)];
540+
uint32_t *args = (uint32_t *)&packet[MESSAGE_SIZE(0)];
541+
const uint64_t tstamp = platform_safe_get_time(timer_get());
542+
543+
put_header(packet, dt_tr.uuid_p, _TRACE_INV_ID, _TRACE_INV_ID,
544+
dict_entry_address, tstamp);
545+
546+
va_start(ap, n_args);
547+
for (i = 0; i < n_args; i++)
548+
args[i] = va_arg(ap, uint32_t);
549+
va_end(ap);
550+
551+
mtrace_event(packet, MESSAGE_SIZE(n_args));
552+
}

zephyr/include/sof/trace/trace.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@ struct timer;
2525
uint64_t platform_timer_get(struct timer *timer);
2626

2727
/*
28-
* Use SOF macros, but let Zephyr take care of the physical log IO.
28+
* Override SOF dictionary macros for now and let Zephyr take care of
29+
* the physical log IO.
2930
*/
3031
#undef _log_message
32+
#undef mtrace_printf
3133

3234
#if USE_PRINTK
35+
#define mtrace_printf(level, format, ...) \
36+
do { \
37+
if ((level) <= SOF_ZEPHYR_TRACE_LEVEL) \
38+
printk("%llu: " format "\n", platform_timer_get(NULL), \
39+
##__VA_ARGS__); \
40+
} while (0)
3341
#define _log_message(log_func, atomic, level, comp_class, ctx, id1, id2, format, ...) \
3442
do { \
3543
if ((level) <= SOF_ZEPHYR_TRACE_LEVEL) \
3644
printk("%llu: " format "\n", platform_timer_get(NULL), \
3745
##__VA_ARGS__); \
3846
} while (0)
39-
#else
47+
#else /* not tested */
4048
#define _log_message(log_func, atomic, level, comp_class, ctx, id1, id2, format, ...) \
4149
do { \
4250
Z_LOG(level, "%u: " format, (uint32_t)platform_timer_get(NULL), \

0 commit comments

Comments
 (0)