From 915dc2392dbe46fa28532fb2b5a011e2aa466c7e Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 21 Oct 2024 14:47:17 +0300 Subject: [PATCH 1/5] xtos: compiler_attributes: add definition for __maybe_unused Add __maybe_unused attribute for XTOS, so this attribute can be used in common SOF code (it's already supported in Zephyr toolchains). Signed-off-by: Kai Vehmanen --- xtos/include/sof/compiler_attributes.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xtos/include/sof/compiler_attributes.h b/xtos/include/sof/compiler_attributes.h index 1b28e5ebad50..d961fa990613 100644 --- a/xtos/include/sof/compiler_attributes.h +++ b/xtos/include/sof/compiler_attributes.h @@ -19,6 +19,10 @@ #define __unused __attribute__((unused)) #endif +#ifndef __maybe_unused +#define __maybe_unused __attribute__((unused)) +#endif + #ifndef __aligned #define __aligned(x) __attribute__((__aligned__(x))) #endif From 5bbaa1e5605b640730bff0db672d21634feaa6e3 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 21 Oct 2024 19:40:01 +0300 Subject: [PATCH 2/5] posix: compiler_attributes: add definition for __maybe_unused Add __maybe_unused attribute for posix RTOS layer, so this attribute can be used in common SOF code (it's already supported in Zephyr+XTOS). Signed-off-by: Kai Vehmanen --- posix/include/sof/compiler_attributes.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/posix/include/sof/compiler_attributes.h b/posix/include/sof/compiler_attributes.h index bf88bfac4369..a223012d44ab 100644 --- a/posix/include/sof/compiler_attributes.h +++ b/posix/include/sof/compiler_attributes.h @@ -23,6 +23,10 @@ #define __unused __attribute__((unused)) #endif +#ifndef __maybe_unused +#define __maybe_unused __attribute__((unused)) +#endif + #endif #ifndef __aligned From 6ec9590631fd04e0ef153468d1e2740ce1682620 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 21 Oct 2024 14:26:10 +0300 Subject: [PATCH 3/5] trace: mark unused variables with __maybe_unused Mark local variables that are only used in logging macros with "__maybe_unused" attribute. The compiler errors are currently avoided with preprocessor logic done in preproc.h for SOF_TRACE_UNUSED, but this brings in quite a bit of definitions not really needed in Zephyr logs. Signed-off-by: Kai Vehmanen --- src/audio/module_adapter/module_adapter_ipc3.c | 2 +- src/audio/pipeline/pipeline-graph.c | 4 ++-- src/ipc/ipc3/dai.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/audio/module_adapter/module_adapter_ipc3.c b/src/audio/module_adapter/module_adapter_ipc3.c index 765c3e2b82fe..5adc3079708c 100644 --- a/src/audio/module_adapter/module_adapter_ipc3.c +++ b/src/audio/module_adapter/module_adapter_ipc3.c @@ -239,7 +239,7 @@ static int module_adapter_ctrl_get_set_data(struct comp_dev *dev, struct sof_ipc bool set) { int ret; - struct processing_module *mod = comp_mod(dev); + struct processing_module __maybe_unused *mod = comp_mod(dev); comp_dbg(dev, "module_adapter_ctrl_set_data() start, state %d, cmd %d", mod->priv.state, cdata->cmd); diff --git a/src/audio/pipeline/pipeline-graph.c b/src/audio/pipeline/pipeline-graph.c index 8b21774c6d19..8923caed32b3 100644 --- a/src/audio/pipeline/pipeline-graph.c +++ b/src/audio/pipeline/pipeline-graph.c @@ -283,9 +283,9 @@ int pipeline_complete(struct pipeline *p, struct comp_dev *source, }; #if !UNIT_TEST && !CONFIG_LIBRARY - int freq = clock_get_freq(cpu_get_id()); + int __maybe_unused freq = clock_get_freq(cpu_get_id()); #else - int freq = 0; + int __maybe_unused freq = 0; #endif int ret; diff --git a/src/ipc/ipc3/dai.c b/src/ipc/ipc3/dai.c index 8586dc779cff..508c07cbb065 100644 --- a/src/ipc/ipc3/dai.c +++ b/src/ipc/ipc3/dai.c @@ -203,7 +203,7 @@ int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev) int ipc_comp_dai_config(struct ipc *ipc, struct ipc_config_dai *common_config, void *spec_config) { - struct sof_ipc_dai_config *config = spec_config; + struct sof_ipc_dai_config __maybe_unused *config = spec_config; bool comp_on_core[CONFIG_CORE_COUNT] = { false }; struct sof_ipc_reply reply; struct ipc_comp_dev *icd; From 40f0911b1e50d1bcd8b1c4a85b924239448bf52f Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Wed, 9 Oct 2024 17:37:37 +0300 Subject: [PATCH 4/5] zephyr: add sof/trace/preproc.h Add Zephyr version of sof/trace/preproc.h interface. The full preproc.h interface needed for CONFIG_TRACE is not duplicated here, so this commit effectively prevents using CONFIG_TRACE in Zephyr. Link: https://github.com/thesofproject/sof/issues/9015 Signed-off-by: Kai Vehmanen --- zephyr/include/sof/trace/preproc.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 zephyr/include/sof/trace/preproc.h diff --git a/zephyr/include/sof/trace/preproc.h b/zephyr/include/sof/trace/preproc.h new file mode 100644 index 000000000000..83776e6fea4e --- /dev/null +++ b/zephyr/include/sof/trace/preproc.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2024 Intel Corporation. + */ + +#ifndef __SOF_TRACE_PREPROC_H__ +#define __SOF_TRACE_PREPROC_H__ + +#ifdef CONFIG_TRACE +#error "SOF dma-trace (CONFIG_TRACE) not supported in Zephyr builds. \ + Please use CONFIG_ZEPHYR_LOG instead." +#endif + +#ifndef CONFIG_ZEPHYR_LOG + +/* + * Unlike the XTOS version of this macro, this does not silence all + * compiler warnings about unused variables. + */ +#define SOF_TRACE_UNUSED(arg1, ...) ((void)arg1) + +#endif /* CONFIG_ZEPHYR_LOG */ + +#endif /* __SOF_TRACE_PREPROC_H__ */ From 6e167caae5c024a33a5186cafe016b36c95fe76a Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 18 Oct 2024 12:54:10 +0300 Subject: [PATCH 5/5] trace: make CONFIG_TRACE=n the default for Zephyr builds Make CONFIG_TRACE=n the default for Zephyr builds and update document to explain the trade-offs when using CONFIG_TRACE on Zephyr. Signed-off-by: Kai Vehmanen --- src/trace/Kconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/trace/Kconfig b/src/trace/Kconfig index e691bc9e3cd3..5ff6b2001130 100644 --- a/src/trace/Kconfig +++ b/src/trace/Kconfig @@ -6,9 +6,12 @@ menu "Trace" config TRACE bool "Trace" + default n if ZEPHYR_SOF_MODULE default y help - Enabling traces. All traces (normal and error) are sent by dma. + Enable SOF DMA based traces compatible with the sof-logger tool. + With Zephyr, RTOS side events are not seen in the SOF trace, so native + Zephyr logging (CONFIG_ZEPHYR_LOG) is recommended instead. config TRACEV bool "Trace verbose"