Skip to content

Commit c4744ab

Browse files
committed
trace: avoid passing va_list
Passing va_list seems to result in issues with stopping the DMA. Call log_func() and mtrace_dict_entry() in the _log_message() macro instead to prevent this. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 5371886 commit c4744ab

File tree

3 files changed

+37
-52
lines changed

3 files changed

+37
-52
lines changed

src/include/sof/trace/trace.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,10 @@ void trace_off(void);
147147
void trace_init(struct sof *sof);
148148

149149
/* 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-
153150
void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
154-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args);
151+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...);
155152
void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
156-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list args);
153+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...);
157154
struct sof_ipc_trace_filter_elem *trace_filter_fill(struct sof_ipc_trace_filter_elem *elem,
158155
struct sof_ipc_trace_filter_elem *end,
159156
struct trace_filter *filter);
@@ -217,11 +214,6 @@ void mtrace_event(const char *complete_packet, uint32_t length);
217214
# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_ERROR
218215
#endif /* CONFIG_TRACEM */
219216

220-
/* This function is _not_ passed the format string to save space */
221-
void _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry,
222-
const struct tr_ctx *ctx, const uint32_t lvl,
223-
uint32_t id_1, uint32_t id_2, int arg_count, ...);
224-
225217
/* _log_message() */
226218

227219
#ifdef CONFIG_LIBRARY
@@ -264,6 +256,26 @@ _thrown_from_macro_BASE_LOG_in_trace_h
264256
* linker section and replaced by a &log_entry pointer to it. This must
265257
* be a macro for the source location to be meaningful.
266258
*/
259+
#ifndef __ZEPHYR__
260+
#define _log_message(log_func, atomic, lvl, comp_class, ctx, id_1, id_2, format, ...) \
261+
do { \
262+
_DECLARE_LOG_ENTRY(lvl, format, comp_class, \
263+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \
264+
STATIC_ASSERT_ARG_SIZE(__VA_ARGS__); \
265+
STATIC_ASSERT(_TRACE_EVENT_MAX_ARGUMENT_COUNT >= \
266+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
267+
BASE_LOG_ASSERT_FAIL_MSG \
268+
); \
269+
(lvl <= MTRACE_DUPLICATION_LEVEL ? \
270+
mtrace_dict_entry(true, (uint32_t)&log_entry, \
271+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
272+
##__VA_ARGS__) : 0); \
273+
log_func(atomic, &log_entry, ctx, lvl, id_1, id_2, \
274+
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), ##__VA_ARGS__); \
275+
_log_nodict(atomic, META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
276+
lvl, format, ##__VA_ARGS__); \
277+
} while (0)
278+
#else
267279
#define _log_message(log_func, atomic, lvl, comp_class, ctx, id_1, id_2, format, ...) \
268280
do { \
269281
_DECLARE_LOG_ENTRY(lvl, format, comp_class, \
@@ -273,11 +285,12 @@ do { \
273285
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
274286
BASE_LOG_ASSERT_FAIL_MSG \
275287
); \
276-
_log_sofdict(log_func, atomic, &log_entry, ctx, lvl, id_1, id_2, \
288+
log_func(atomic, &log_entry, ctx, lvl, id_1, id_2, \
277289
META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), ##__VA_ARGS__); \
278290
_log_nodict(atomic, META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \
279291
lvl, format, ##__VA_ARGS__); \
280292
} while (0)
293+
#endif
281294

282295
#ifdef __ZEPHYR__
283296
/* Just like XTOS, only the most urgent messages go to limited

src/trace/trace.c

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,25 @@ static void dma_trace_log(bool send_atomic, uint32_t log_entry, const struct tr_
249249
}
250250

251251
void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
252-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list vl)
252+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...)
253253
{
254254
struct trace *trace = trace_get();
255+
va_list vl;
255256

256257
if (!trace->enable) {
257258
return;
258259
}
259260

261+
va_start(vl, arg_count);
260262
dma_trace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);
263+
va_end(vl);
261264
}
262265

263266
void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx,
264-
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, va_list vl)
267+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...)
265268
{
266269
struct trace *trace = trace_get();
270+
va_list vl;
267271

268272
#if CONFIG_TRACE_FILTERING_ADAPTIVE
269273
uint64_t current_ts;
@@ -289,7 +293,9 @@ void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr
289293
}
290294
#endif /* CONFIG_TRACE_FILTERING_ADAPTIVE */
291295

296+
va_start(vl, arg_count);
292297
dma_trace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);
298+
va_end(vl);
293299
}
294300

295301
struct sof_ipc_trace_filter_elem *trace_filter_fill(struct sof_ipc_trace_filter_elem *elem,
@@ -509,9 +515,9 @@ void trace_init(struct sof *sof)
509515
dma_trace_init_early(sof);
510516
}
511517

512-
static void mtrace_dict_entry_vl(bool atomic_context, uint32_t dict_entry_address,
513-
int n_args, va_list ap)
518+
void mtrace_dict_entry(bool atomic_context, uint32_t dict_entry_address, int n_args, ...)
514519
{
520+
va_list ap;
515521
int i;
516522
char packet[MESSAGE_SIZE(_TRACE_EVENT_MAX_ARGUMENT_COUNT)];
517523
uint32_t *args = (uint32_t *)&packet[MESSAGE_SIZE(0)];
@@ -520,8 +526,10 @@ static void mtrace_dict_entry_vl(bool atomic_context, uint32_t dict_entry_addres
520526
put_header(packet, dt_tr.uuid_p, _TRACE_INV_ID, _TRACE_INV_ID,
521527
dict_entry_address, tstamp);
522528

529+
va_start(ap, n_args);
523530
for (i = 0; i < MIN(n_args, _TRACE_EVENT_MAX_ARGUMENT_COUNT); i++)
524531
args[i] = va_arg(ap, uint32_t);
532+
va_end(ap);
525533

526534
if (atomic_context) {
527535
mtrace_event(packet, MESSAGE_SIZE(n_args));
@@ -534,31 +542,3 @@ static void mtrace_dict_entry_vl(bool atomic_context, uint32_t dict_entry_addres
534542
spin_unlock_irq(&trace->lock, saved_flags);
535543
}
536544
}
537-
538-
void mtrace_dict_entry(bool atomic_context, uint32_t dict_entry_address, int n_args, ...)
539-
{
540-
va_list ap;
541-
542-
va_start(ap, n_args);
543-
mtrace_dict_entry_vl(atomic_context, dict_entry_address, n_args, ap);
544-
va_end(ap);
545-
}
546-
547-
void _log_sofdict(log_func_t sofdict_logf, bool atomic, const void *log_entry,
548-
const struct tr_ctx *ctx, const uint32_t lvl,
549-
uint32_t id_1, uint32_t id_2, int arg_count, ...)
550-
{
551-
va_list ap;
552-
553-
#ifndef __ZEPHYR__ /* for Zephyr see _log_nodict() in trace.h */
554-
if (lvl <= MTRACE_DUPLICATION_LEVEL) {
555-
va_start(ap, arg_count);
556-
mtrace_dict_entry_vl(atomic, (uint32_t)log_entry, arg_count, ap);
557-
va_end(ap);
558-
}
559-
#endif
560-
561-
va_start(ap, arg_count);
562-
sofdict_logf(atomic, log_entry, ctx, lvl, id_1, id_2, arg_count, ap);
563-
va_end(ap);
564-
}

test/cmocka/src/common_mocks.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ 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,
106-
va_list args)
105+
uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...)
107106
{
108107
(void) send_atomic;
109108
(void) log_entry;
@@ -112,13 +111,6 @@ void WEAK trace_log_filtered(bool send_atomic, const void *log_entry, const stru
112111
(void) id_1;
113112
(void) id_2;
114113
(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-
{
122114
}
123115

124116
void WEAK trace_flush_dma_to_mbox(void)

0 commit comments

Comments
 (0)