-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] sof: replace log calls with zephyr logging api #5411
Conversation
CI is not ready to use cavstool.py to read logs from shared memory, waiting the readiness of CI. Build failure on NXP SOCs, because log context not registered for NXP specific source files |
version 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume a subsequent PR will replace usage of tr_info() etc with LOG_INFO() ?
_TRACE_INV_ID, _TRACE_INV_ID, \ | ||
fmt, ##__VA_ARGS__) | ||
|
||
#ifdef __ZEPHYR__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, best to have a comment here say this is tmp until all users have been updated.
|
||
#define LOG_MODULE_REGISTER(ctx, level) | ||
#define LOG_MODULE_DECLARE(ctx, level) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to define LOG() here for xtos users, but I'm assuming this will be done in a subsequent PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I am not invent a new macro, and use it to wrap LOG_XXX(zephyr) and tr_xxx(XTOS). I just reuse those tr_xxx/comp_xxx/pipe_xxx macro, when sof build with zephyr, they are replaced with LOG_XXX, otherwise, they are replaced with xtos logging utilities.
Btw - I think this is ready for review, if its part 1 of the work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DECLARE_SOF_RT_UUID() macro should be empty when __ZEPHYR__
is defined. Then the compiler should automatically catch any usage of the older logger.
CI is not ready to use cavstool.py to read logs from shared memory, waiting the readiness of CI.
I believe cavstool.py is only compatible with (uncompressed) printk(), I think it's unrelated to Zephyr logging APIs. @andyross ?
Uncompressed logging is costly and won't fit in some products, to measure it try this one-line patch. It grows the sof-apl.ri Zephyr image size by about 30k (It also makes it crash after a short time but that's probably a different issue)
--- a/src/include/sof/trace/trace.h
+++ b/src/include/sof/trace/trace.h
@@ -216,7 +216,7 @@ void mtrace_event(const char *complete_packet, uint32_t length);
# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_DEBUG
# endif
#else /* copy only ERRORS */
-# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_WARNING
+# define MTRACE_DUPLICATION_LEVEL LOG_LEVEL_DEBUG
#endif /* CONFIG_TRACEM */
/* This function is _not_ passed the format string to save space */
Tested on TGL up extreme board with xcc.
Did you get any logs? Through which kernel driver and userspace?
I assume a subsequent PR will replace usage of tr_info() etc with LOG_INFO() ?
I don't think we should allow a concurrent and inconsistent mix of tr_...()
and LOG_...()
, trace.h
has way too many layers of indirections and #ifdef
conditionals already. Once we have the Zephyr side working then we can do a mass tr_
-> LOG_
search/replace to get rid of all the tr_...
calls and at the same time a LOG_...()
redirection to the internal and XTOS trace_with_whatever()
. So there will be a single logging API use at any given time.
src/ipc/ipc-helper.c
Outdated
/* create a new component in the pipeline */ | ||
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc) | ||
{ | ||
struct comp_buffer *buffer; | ||
|
||
tr_info(&buffer_tr, "buffer new size 0x%x id %d.%d flags 0x%x", | ||
tr_info(&ipc_tr, "buffer new size 0x%x id %d.%d flags 0x%x", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a bug fix or something... can you submit it separately?
src/schedule/zephyr_ll.c
Outdated
/* 1547fe68-de0c-11eb-8461-3158a1294853 */ | ||
DECLARE_SOF_UUID("zll-schedule", zll_sched_uuid, 0x1547fe68, 0xde0c, 0x11eb, | ||
DECLARE_SOF_UUID("ll-schedule", zll_sched_uuid, 0x1547fe68, 0xde0c, 0x11eb, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not a typo. There's some conflict with the ll-schedule
in XTOS when you do this, check the git and github history.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is by mistake, thank you for spotting this. I was intended to declare a logging context ll-schedule
both for src/schedule/zephyr_ll.c and src/schedule/ll_schedule.c. because ll_schedule.c is used with SOF+Zephyr on NXP SOCs.
It's OK to define a "zll-schedule" context and a "ll-schedule" context, but that is not consistent between and NXP.
#define tr_info(ctx, fmt, ...) \ | ||
trace_event_with_ids(_TRACE_INV_CLASS, ctx, \ | ||
_TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are all the non-atomic variants being removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are moved, not removed. check a little below, they are moved to the #else part.
Logging works, there is a log_backend_adsp module that forwards to the same intel_adsp_trace_out() utility used underneath printk(). (And of course LOG_PRINTK tends to be defined in such a circumstance, meaning that printk() itself gets expanded into a log call. Zephyr's log/trace/print subsystems all like to use each other as backends via a bunch of non-orthogonal tricks. It's sort of a mess, but in this case it does work.) |
I'd rather you wait for one or two days, I am working on the comp_xxx part, it is the last part, but somehow it depends on #5459. With this change, there will be build issue with SOF+Zephyr on NXP SOCs, I can help to fix it, but I am not able to test the fix, can you suggest something here? Or should we involve NXP friends here? |
Thanks @andyross for correcting me. Summarizing a further private chat: so SOF/Zephyr has already been using the Zephyr logging system for months through The part that I understood correctly: neither this backend nor the (literally) corresponding Another unknown is the performance impact of dropping DMA logging and switching to shared memory entirely. |
I think most of the work is in sof-test, CI shouldn't have to change much. We can "steal" the etrace slot - it's the same shared memory after all. The shared memory is already used by Zephyr and it can already be read by cavstool.py; I've been doing that for months. So the sof-test work can be started already, it's not blocked by this. |
@marc-hb Yes, namely, enable cavstool.py in sof-test. |
Version 3:
Our CI is not use the latest Zephyr, but a tested stable zephyr, so it fails the same way. the same error message I posted here: #5459 (comment), this zephyr PR maybe related: zephyrproject-rtos/zephyr#43174 Version 4:
|
@@ -152,6 +152,26 @@ enum { | |||
/** \brief Retrieves subid (comp id) from the component device */ | |||
#define trace_comp_get_subid(comp_p) ((comp_p)->ipc_config.id) | |||
|
|||
#ifdef __ZEPHYR__ | |||
/* class (driver) level (no device object) tracing */ | |||
#define comp_cl_err(drv_p, __e, ...) LOG_ERR(__e, ##__VA_ARGS__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for keeping these legacy macros in common code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to proceed in steps. This first, very big step is switching the "backend" to the Zephyr logging system. Once it's passing some tests we can start some massive search/replace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its already passing tests as we are using it in the Zephyr wrapper, this is just unnecessary churn. The aim of this PR should be to use the native Zephyr API and move the wrapper to xtos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a bit of Zephyr logging already but it's not tested at all, not collected and completely ignored.
I don't see any extra churn in this PR, most of it seems final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine, the Zephyr parts are tested by Zephyr CI. This gets everything ready for the DMA backend which will use the same kernel interface and flow control on current HW, albeit with a different trace tool from Zephyr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I wasn't very clear sorry: if we merge this now, we lose all firmware logs in all our Zephyr test results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in this case the xtos wrapper for LOG would be used until the Zephyr DMA backend is ready. The etrace parts should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For zephyr logging, context is define per module/file, when we use zephyr api, we don't need to pass a context pointer to it. but for XTOS logging calls, we need to pass a context to it. That's why I still use the tr_xxx here, for zephyr, it will be replaced with LOG_XXX, and the context pointer is ignored, for XTOS, everything keeps unchanged.
any reason for keeping these legacy macros in common code ?
Directly replace tr_xxx with zephyr LOG_XXX and provide wrapper for XTOS is not OK, because LOG_XXXs don't know how to handle the context pointer. Or I get it wrong here?
@@ -37,6 +37,18 @@ extern struct tr_ctx pipe_tr; | |||
tr_dbg(&pipe_tr, __e, ##__VA_ARGS__) | |||
|
|||
/* device tracing */ | |||
#ifdef __ZEPHYR__ | |||
|
|||
#define pipe_err(pipe_p, __e, ...) LOG_ERR(__e, ##__VA_ARGS__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, we should replace all the legacy macros with Zephyr versions.
BTW @aiChaoSONG how much does this PR make the image grow? |
@lgirdwood @marc-hb There are some issues, summarized below:
|
Ok, but then this PR is closed as its states the new Zephyr fixes the issue. I've no issue making these non inline, but please state the XCC build errors these fix in the PR/commit message.
Do you mean the logging is slow ?Can you provide more detail on "performance issue". |
With tr_xxx/pipe_xxx/dai_xx replaced with zephyr api, and set log level to LOG_LEVEL_DBG
logs from cavstool.py --log-only
With tr_xxx/pipe_xxx/dai_xx replaced with zephyr api, and set log level to LOG_LEVEL_INFOnly very slight log drop, and log print is realtime. demo video: https://www.youtube.com/watch?v=l8_kSImcC8s |
https://docs.zephyrproject.org/latest/reference/logging/index.html
|
@aiChaoSONG can you confirm the log timestamps are correct and not delayed ? DBG level is heavy (especially when using mailbox), but we can track this and retest when DMA backend is enabled. |
SOFCI TEST |
1 similar comment
SOFCI TEST |
looks like CI got stuck, unblocking. |
Multiple use of static inline functions across different C files will result in same symbol names defined in all of the corresponding object files, because XCC compiler emits the same symbol names based on the source file for those static variables inside functions. If Zephyr logging is used in SOF, we will have log context redefinition issue with XCC due to above reason. This patch workarounds the issue by removing the log calls in static inline functions that are used across multiple C files if Zephyr is used. BugLink: zephyrproject-rtos/zephyr#43786 Signed-off-by: Chao Song <[email protected]>
The log context in zephyr is per file or module. To use zephyr logging api, LOG_MODULE_REGISTER is used to register a log context, LOG_MODULE_DECLARE is used to refer to the registered context. For function in header file, LOG_MODULE_DECLARE should be used within that function to avoid context collapse, a condition one source file have multiple context registered or declared. Signed-off-by: Chao Song <[email protected]>
Can one of the admins verify this patch? |
@aiChaoSONG can you fix conflicts so we can rerun CI. Thanks |
The log context in zephyr is per file or module.
To use zephyr logging api, LOG_MODULE_REGISTER is used
to register a log context, LOG_MODULE_DECLARE is used
to refer to the registered context.
For function in header file, LOG_MODULE_DECLARE should
be used within that function to avoid context collapse,
a condition one source file have multiple context
registered or declared.
Signed-off-by: Chao Song [email protected]