Skip to content

Commit 0def905

Browse files
marc-hblgirdwood
authored andcommitted
trace: move CONFIG_TRACEM implementation up a couple levels
From deep down trace.c:va_tracelog() up to the _log_message() level. Also rename va_tracelog() to the more specific dma_tracelog() Preparation to support the DMA trace in Zephyr. The only functional change in this commit is that DMA messages copied to the shared memory are not de-duplicated any more (a.k.a "adaptive rate limiting" or CONFIG_TRACE_FILTERING_ADAPTIVE). These are generally supposed to be high level hence rare enough; otherwise there is probably a "bigger problem". Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent e1aa806 commit 0def905

File tree

3 files changed

+67
-43
lines changed

3 files changed

+67
-43
lines changed

src/include/sof/trace/trace.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ struct trace_filter {
9797

9898
#if CONFIG_TRACE
9999

100+
#include <stdarg.h>
101+
#include <user/trace.h> /* LOG_LEVEL_... */
102+
100103
/*
101104
* trace_event macro definition
102105
*
@@ -144,10 +147,13 @@ void trace_off(void);
144147
void trace_init(struct sof *sof);
145148

146149
/* All tracing macros in this file end up calling these functions in the end. */
150+
typedef void (*log_func_t)(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
151+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args);
152+
147153
void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
148-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...);
154+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args);
149155
void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
150-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...);
156+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args);
151157
struct sof_ipc_trace_filter_elem *trace_filter_fill(struct sof_ipc_trace_filter_elem *elem,
152158
struct sof_ipc_trace_filter_elem *end,
153159
struct trace_filter *filter);
@@ -198,6 +204,17 @@ void mtrace_event(const char *complete_packet, uint32_t length);
198204
format \
199205
}
200206

207+
#ifdef CONFIG_TRACEM /* Send everything to shared memory too */
208+
# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_DEBUG
209+
#else /* copy only ERRORS */
210+
# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_ERROR
211+
#endif /* CONFIG_TRACEM */
212+
213+
/* This function is _not_ passed the format string to save space */
214+
void _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry,
215+
const struct tr_ctx *ctx, const uint32_t lvl,
216+
uint32_t id_1, uint32_t id_2, int arg_count, ...);
217+
201218
/* _log_message() */
202219

203220
#ifdef CONFIG_LIBRARY
@@ -237,7 +254,8 @@ _thrown_from_macro_BASE_LOG_in_trace_h
237254

238255
/** _log_message is where the memory-saving dictionary magic described
239256
* above happens: the "format" string argument is moved to a special
240-
* linker section and replaced by a &log_entry pointer to it.
257+
* linker section and replaced by a &log_entry pointer to it. This must
258+
* be a macro for the source location to be meaningful.
241259
*/
242260
#define _log_message(log_func, atomic, lvl, comp_class, ctx, id_1, id_2, format, ...) \
243261
do { \
@@ -248,8 +266,8 @@ do { \
248266
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
249267
BASE_LOG_ASSERT_FAIL_MSG \
250268
); \
251-
log_func(atomic, &log_entry, ctx, lvl, id_1, id_2, \
252-
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), ##__VA_ARGS__); \
269+
_log_sofdict(log_func, atomic, &log_entry, ctx, lvl, id_1, id_2, \
270+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), ##__VA_ARGS__); \
253271
} while (0)
254272

255273
#endif /* CONFIG_LIBRARY */

src/trace/trace.c

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,15 @@ static bool trace_filter_flood(uint32_t log_level, uint32_t entry, uint64_t mess
222222

223223
/** Implementation shared and invoked by both adaptive filtering and
224224
* not. Serializes events into trace messages and passes them to
225-
* dtrace_event() or to mtrace_event() or to both depending on the log
226-
* lvl and the Kconfiguration.
225+
* dtrace_event()
227226
*/
228-
static void vatrace_log(bool send_atomic, uint32_t log_entry, const struct tr_ctx *ctx,
229-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list vargs)
227+
static void dma_trace_log(bool send_atomic, uint32_t log_entry, const struct tr_ctx *ctx,
228+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list vargs)
230229
{
231230
uint32_t data[MESSAGE_SIZE_DWORDS(_TRACE_EVENT_MAX_ARGUMENT_COUNT)];
232231
const int message_size = MESSAGE_SIZE(arg_count);
233232
int i;
234233

235-
#if CONFIG_TRACEM
236-
unsigned long flags;
237-
struct trace *trace = trace_get();
238-
#endif /* CONFIG TRACEM */
239-
240234
/* fill log content. arg_count is in the dictionary. */
241235
put_header(data, ctx->uuid_p, id_1, id_2, log_entry,
242236
platform_safe_get_time(timer_get()));
@@ -250,42 +244,25 @@ static void vatrace_log(bool send_atomic, uint32_t log_entry, const struct tr_ct
250244
else
251245
dtrace_event((const char *)data, message_size);
252246

253-
#if CONFIG_TRACEM
254-
/* send event by mail box too. */
255-
if (send_atomic) {
256-
mtrace_event((const char *)data, MESSAGE_SIZE(arg_count));
257-
} else {
258-
spin_lock_irq(&trace->lock, flags);
259-
mtrace_event((const char *)data, MESSAGE_SIZE(arg_count));
260-
spin_unlock_irq(&trace->lock, flags);
261-
}
262-
#else
263-
/* send event by mail box if level is LOG_LEVEL_CRITICAL. */
264-
if (lvl == LOG_LEVEL_CRITICAL)
265-
mtrace_event((const char *)data, MESSAGE_SIZE(arg_count));
266-
#endif /* CONFIG_TRACEM */
267247
}
268248

269249
void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
270-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...)
250+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list vl)
271251
{
272252
struct trace *trace = trace_get();
273-
va_list vl;
274253

275254
if (!trace->enable) {
276255
return;
277256
}
278257

279-
va_start(vl, arg_count);
280-
vatrace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);
281-
va_end(vl);
258+
dma_trace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);
282259
}
283260

284261
void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
285-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...)
262+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list vl)
286263
{
287264
struct trace *trace = trace_get();
288-
va_list vl;
265+
289266
#if CONFIG_TRACE_FILTERING_ADAPTIVE
290267
uint64_t current_ts;
291268
#endif /* CONFIG_TRACE_FILTERING_ADAPTIVE */
@@ -310,9 +287,7 @@ void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr
310287
}
311288
#endif /* CONFIG_TRACE_FILTERING_ADAPTIVE */
312289

313-
va_start(vl, arg_count);
314-
vatrace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);
315-
va_end(vl);
290+
dma_trace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);
316291
}
317292

318293
struct sof_ipc_trace_filter_elem *trace_filter_fill(struct sof_ipc_trace_filter_elem *elem,
@@ -532,9 +507,9 @@ void trace_init(struct sof *sof)
532507
dma_trace_init_early(sof);
533508
}
534509

535-
void mtrace_dict_entry(bool atomic_context, uint32_t dict_entry_address, int n_args, ...)
510+
static void mtrace_dict_entry_vl(bool atomic_context, uint32_t dict_entry_address,
511+
int n_args, va_list ap)
536512
{
537-
va_list ap;
538513
int i;
539514
char packet[MESSAGE_SIZE(_TRACE_EVENT_MAX_ARGUMENT_COUNT)];
540515
uint32_t *args = (uint32_t *)&packet[MESSAGE_SIZE(0)];
@@ -543,10 +518,8 @@ void mtrace_dict_entry(bool atomic_context, uint32_t dict_entry_address, int n_a
543518
put_header(packet, dt_tr.uuid_p, _TRACE_INV_ID, _TRACE_INV_ID,
544519
dict_entry_address, tstamp);
545520

546-
va_start(ap, n_args);
547521
for (i = 0; i < MIN(n_args, _TRACE_EVENT_MAX_ARGUMENT_COUNT); i++)
548522
args[i] = va_arg(ap, uint32_t);
549-
va_end(ap);
550523

551524
if (atomic_context) {
552525
mtrace_event(packet, MESSAGE_SIZE(n_args));
@@ -559,3 +532,28 @@ void mtrace_dict_entry(bool atomic_context, uint32_t dict_entry_address, int n_a
559532
spin_unlock_irq(&trace->lock, saved_flags);
560533
}
561534
}
535+
536+
void mtrace_dict_entry(bool atomic_context, uint32_t dict_entry_address, int n_args, ...)
537+
{
538+
va_list ap;
539+
540+
va_start(ap, n_args);
541+
mtrace_dict_entry_vl(atomic_context, dict_entry_address, n_args, ap);
542+
va_end(ap);
543+
}
544+
545+
void _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry,
546+
const struct tr_ctx *ctx, const uint32_t lvl,
547+
uint32_t id_1, uint32_t id_2, int arg_count, ...)
548+
{
549+
va_list ap;
550+
551+
if (lvl <= MTRACE_DUPLICATION_LEVEL) {
552+
va_start(ap, arg_count);
553+
mtrace_dict_entry_vl(atomic, (uint32_t)log_entry, arg_count, ap);
554+
va_end(ap);
555+
}
556+
va_start(ap, arg_count);
557+
sofdict_logf(atomic, log_entry, ctx, lvl, id_1, id_2, arg_count, ap);
558+
va_end(ap);
559+
}

test/cmocka/src/common_mocks.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void WEAK __panic(uint32_t p, char *filename, uint32_t linenum)
102102

103103
#if CONFIG_TRACE
104104
void WEAK trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
105-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...)
105+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count,
106+
va_list args)
106107
{
107108
(void) send_atomic;
108109
(void) log_entry;
@@ -111,6 +112,13 @@ void WEAK trace_log_filtered(bool send_atomic, const void *log_entry, const stru
111112
(void) id_1;
112113
(void) id_2;
113114
(void) arg_count;
115+
(void) args;
116+
}
117+
118+
void WEAK _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry,
119+
const struct tr_ctx *ctx, const uint32_t lvl,
120+
uint32_t id_1, uint32_t id_2, int arg_count, ...)
121+
{
114122
}
115123

116124
void WEAK trace_flush_dma_to_mbox(void)

0 commit comments

Comments
 (0)