Trace - make clear that trace context is unused with Zephyr - #11102
Open
lyakh wants to merge 3 commits into
Open
Trace - make clear that trace context is unused with Zephyr#11102lyakh wants to merge 3 commits into
lyakh wants to merge 3 commits into
Conversation
Under Zephyr with CONFIG_ZEPHYR_LOG, tr_err()/tr_warn()/tr_info()/tr_dbg() expand directly to LOG_ERR()/LOG_WRN()/LOG_INF()/LOG_DBG() and completely ignore their first (tr_ctx) argument. A plain, otherwise-unreferenced DECLARE_TR_CTX() static is therefore dead and the linker discards it. However, a `struct comp_driver`/`struct dai_driver` instance whose `.tctx` field points at such a context keeps it alive, because the driver struct itself is always referenced (component/DAI driver registration). This adds a few bytes of otherwise-dead .data per affected driver and forces the firmware to retain values that can never be read on Zephyr. Guard the `.tctx = &foo_tr,` initializers (and the equivalent runtime `drv->tctx = &lib_manager_tr;` assignment) with #ifndef __ZEPHYR__ so the now fully-unreferenced trace contexts can be garbage-collected by the linker, same as any other unused DECLARE_TR_CTX(). Fix the shared DECLARE_MODULE_ADAPTER() macro once, which covers ~40 IPC4 module_adapter components: MODULE_ADAPTER_TCTX_INIT(tr) resolves to &(tr) normally and to NULL under Zephyr, so `.tctx = MODULE_ADAPTER_TCTX_INIT(tr),` still parses as a valid (harmless) initializer either way. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
pipeline_new() and buffer_new() unconditionally memcpy_s() the static pipe_tr/buffer_tr DECLARE_TR_CTX() objects into the new pipeline's/buffer's embedded tr_ctx field. On Zephyr this copy is pure overhead: comp_init() in component.h already skips the equivalent copy for comp_dev with #ifndef __ZEPHYR__, but these two sites were missed. buffer_new()'s copy was already conditional on \!CONFIG_SOF_USERSPACE_LL; simplify that to \!__ZEPHYR__ since CONFIG_SOF_USERSPACE_LL can only be defined in Zephyr builds. Also, since &pipe_tr/&buffer_tr were the only references to those objects, guarding the copy lets the linker garbage-collect them on Zephyr, same as ipc_tr and friends. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Under Zephyr with CONFIG_ZEPHYR_LOG, tr_err()/tr_warn()/tr_info()/tr_dbg() expand directly to LOG_ERR()/LOG_WRN()/LOG_INF()/LOG_DBG() and never look at their tr_ctx argument. None of these remaining DECLARE_TR_CTX() instances are referenced by anything other than tr_*() calls in the same file (verified: no .tctx/->tctx assignment picks up their address), so they are already dead code eliminated by the linker on Zephyr builds - this commit only documents that fact, it changes no generated code. (dai-legacy.c, host-legacy.c and the platform/library/schedule/*.c files are excluded: they are only ever built for non-Zephyr, non-hardware configurations - testbench/cmocka/legacy XTOS - so the comment would not apply to them.) Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
lyakh
requested review from
a team,
LaurentiuM1234,
abonislawski,
bardliao,
bhiregoudar,
dbaluta,
fkwasowi,
iganakov,
kuanhsuncheng,
kv2019i,
lbetlej,
lgirdwood,
marcinszkudlinski,
mmaka1,
pblaszko,
plbossart,
singalsu,
sunilkumardommati,
tlissows,
tmleman and
yaochunhung
as code owners
August 17, 2026 13:59
Copilot stopped reviewing on behalf of
lyakh due to an error
August 17, 2026 14:00
kv2019i
requested changes
Aug 17, 2026
kv2019i
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for tackling, but I think this needs iteration still...
| @@ -41,6 +41,7 @@ | |||
| LOG_MODULE_REGISTER(basefw, CONFIG_SOF_LOG_LEVEL); | |||
|
|
||
| static const struct comp_driver comp_basefw = { | ||
| .uid = SOF_RT_UUID(basefw_uuid), | ||
| #ifndef __ZEPHYR__ |
Collaborator
There was a problem hiding this comment.
Could this be reversed? I mean these are only needed in LIBRARY builds now (or are they even needed there)? Or maybe that's not accurate enough, but maybe "#ifdef CONFIG_TRACE" (i.e. a build really using sof-logger with dictionaries).
And for Zephyr, this doesn't cover the case where you build with Zephyr but disable CONFIG_ZEPHYR_LOG. I think these cases should be prevented somehow.
| @@ -35,6 +35,7 @@ LOG_MODULE_REGISTER(pipe, CONFIG_SOF_LOG_LEVEL); | |||
|
|
|||
| SOF_DEFINE_REG_UUID(pipe); | |||
Collaborator
There was a problem hiding this comment.
What's with the "!CONFIG_SOF_USERSPACE_LL" in the commit message?
|
|
||
| #else | ||
|
|
||
| /* unused with Zephyr, generates no output */ |
Collaborator
There was a problem hiding this comment.
unused if not CONFIG_TRACE, not really related to Zephyr...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have a lot of code that uses trace context like
tr_dbg()/tr_err()calls. Changing all those locations would be a very big change. This PR takes a middle ground: it adds comments to trace context declarations where they are harmless and makes harmless those, that end up generating needless code under Zephyr. Yes, made with AI.