-
Notifications
You must be signed in to change notification settings - Fork 309
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
Fix i.MX93 compilation warnings related to mis-formatting / casting 64-bit types #8529
Fix i.MX93 compilation warnings related to mis-formatting / casting 64-bit types #8529
Conversation
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.
Don't think we can do this yet as we are more optimised for size vs portability.
@LaurentiuM1234 @dbaluta btw, can get this platform as a build check in CI ?
Understood. Frankly, I think forcing 64-bit types to 32-bit is not really the way to go so if anyone thinks this is a bad idea or opposes to this being merged then I'm all for dropping this and dealing with it when it becomes necessary. It would have been nice to get rid of all of those annoying warnings as it's become very hard to find new warnings in the sea of already existing warnings.
we already have a CI job building SOF for i.MX93. It's just that it's separate from the one building it for all other i.MX platforms. |
Marking this as a draft for now as I'm not sure about this solution |
Anything wrong with |
This probably requires skipping the As long as you don't plan to actually use |
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.
let's use %zu
please
5f01ab3
to
be2729a
Compare
sof-logger won't be used on i.MX93 but it's currently being used on the other i.MX boards. I've tested the logger on i.MX8QM and seems like it works although this is probably because my test scenario doesn't reach the modified print statements. @dbaluta @iuliana-prodan what's your take on this? Do we proceed with this and risk breaking sof-logger (assuming this would even break it)? Theoretically we should be ready to switch to serial debugging via Zephyr on all boards (except ULP)(also, this isn't the case for XTOS). I'm assuming this won't break the internal tests as afaik sof-logger isn't used there. I'm assuming Intel no longer uses sof-logger, right? EDIT: this may impact MTK and AMD though but I'm not 100% sure what their setup is so I can't really tell. |
You tested sof-logger, with these changes on 8QM and is ok, right? Therefore, I'm approving this! |
Yep, seems like it works fine, but please keep in mind that I've only tested a couple of aplays and nothing more so I can't guarantee that this won't break sof-logger
ACK. If everyone's OK with this then I'm going to remove from draft. As for the pointer downcast to 32-bit: we should be OK for now as there's no 64-bit platform using addresses encoded in 64 bits. |
Can you modify one statement that is actually in use (something outside error handling) and print some magic number with
Not in the main branch, no. Still in use in stable-v2.2. |
@@ -48,7 +48,7 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv, | |||
|
|||
if (!config) { | |||
comp_cl_err(drv, "module_adapter_new(), wrong input params! drv = %x config = %x", | |||
(uint32_t)drv, (uint32_t)config); | |||
(uint32_t)(uintptr_t)drv, (uint32_t)(uintptr_t)config); |
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.
Double casts are very rarely needed so they need at least a short comment/justification. I see you mentioned something in the commit message but that's too far away from the code.
Also: why not use %zu
/ (size_t)
here?
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.
one could use PRIxPTR
to print uintptr_t
directly
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.
Thanks for the suggestions! Decided to go with Marc's suggestion for now. Avoiding the PRI* macros for now because of some interesting points from zephyrproject-rtos/zephyr#46032.
comp_err(dev, "module_load_config(): wrong input params! dev %x, cfg %x size %d", | ||
(uint32_t)dev, (uint32_t)cfg, size); | ||
comp_err(dev, "module_load_config(): wrong input params! dev %x, cfg %x size %zu", | ||
(uint32_t)(uintptr_t)dev, (uint32_t)(uintptr_t)cfg, size); |
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.
See above
src/include/sof/drivers/mu.h
Outdated
} | ||
|
||
static inline void imx_mu_write(uint32_t val, uint32_t reg) | ||
{ | ||
*((volatile uint32_t*)(MU_BASE + reg)) = val; | ||
*((volatile uint32_t*)((uintptr_t)(MU_BASE + reg))) = val; |
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.
Again, MU_BASE is a literal so it is really not intuitive why this is needed. Please add a short explanation in the code (and this one does not seem explained by the commit message)
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.
Please do this instead (tested)
--- a/src/platform/imx93_a55/include/platform/lib/memory.h
+++ b/src/platform/imx93_a55/include/platform/lib/memory.h
@@ -49,7 +49,7 @@
#define HEAPMEM_SIZE 0x00010000
/* SOF uses A side of the WAKEUPMIX MU */
-#define MU_BASE 0x42430000
+#define MU_BASE ((uintptr_t)0x42430000)
/* SOF uses EDMA2 (a.k.a EDMA4 in the TRM) */
#define EDMA2_BASE 0x42010000
Or char *
if you prefer.
Fun fact: C++23 allows 0x42430000Z
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.
Fixed this by adding the ULL
suffix. This ought to make MU_BASE
64-bit.
@@ -184,7 +184,7 @@ int comp_data_blob_set(struct comp_data_blob_handler *blob_handler, | |||
} | |||
#endif | |||
|
|||
comp_dbg(blob_handler->dev, "comp_data_blob_set_cmd() pos = %d, fragment size = %d", | |||
comp_dbg(blob_handler->dev, "comp_data_blob_set_cmd() pos = %d, fragment size = %zu", |
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.
how about lld?
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.
zd is arch-dependent, lld is typically not.
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've tested the logger on i.MX8QM and seems like it works although this is probably because my test scenario doesn't reach the modified print statements
Can you modify one statement that is actually in use (something outside error handling) and print some magic number with
%zu
in that statement? If that one works and that number is logged properly then I think you can blindly change the other ones.
Please test %zu
with the sof-logger "for real" in at least one place before merging this great-looking but massive search/replace.
src/include/sof/drivers/mu.h
Outdated
} | ||
|
||
static inline void imx_mu_write(uint32_t val, uint32_t reg) | ||
{ | ||
*((volatile uint32_t*)(MU_BASE + reg)) = val; | ||
*((volatile uint32_t*)((uintptr_t)(MU_BASE + reg))) = val; |
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.
Please do this instead (tested)
--- a/src/platform/imx93_a55/include/platform/lib/memory.h
+++ b/src/platform/imx93_a55/include/platform/lib/memory.h
@@ -49,7 +49,7 @@
#define HEAPMEM_SIZE 0x00010000
/* SOF uses A side of the WAKEUPMIX MU */
-#define MU_BASE 0x42430000
+#define MU_BASE ((uintptr_t)0x42430000)
/* SOF uses EDMA2 (a.k.a EDMA4 in the TRM) */
#define EDMA2_BASE 0x42010000
Or char *
if you prefer.
Fun fact: C++23 allows 0x42430000Z
The only failure in https://sof-ci.01.org/sof-pr-viewer/#/build/PR8529/build13187149 (to which you don't have access, sorry about that) was a "west update" failure, so don't worry about it. |
@LaurentiuM1234 Let's also fix this:
|
With the following change:
I get the following messages in the logger (trace, -t):
which seems fine. Without trace (-t), the logger has the following output:
which doesn't seem to be related. |
be2729a
to
cc4eb17
Compare
should be fixed with cc4eb17. We could also squash this into the initial PR that causes this issue if you'd like. |
I'm fine that no need to squash it. |
Checkpatch is only checking... submitted patches one by one. So submitting a separate fixup commit will not turn things green in this PR and it will not help other, unrelated PRs either (cause they're not affected) A separate fixup commit will only help if/when someone changes the same line again. But then they're likely to break that line themselves anyway. |
Currently, building SOF on a 64-bit platform (i.e: i.MX93) leads to compilation warnings such as: "format '%d' expects argument of type 'int', but argument 5 has type 'long unsigned int'" This is because size_t is 64-bit on 64-bit platforms. As such, to get rid of these compilation warnings, use the %zu specifier when printing a size_t variable. Signed-off-by: Laurentiu Mihalcea <[email protected]>
Currently, the imx_mu_write() and imx_mu_read() functions cast MU_BASE's value to a pointer. On 64-bit platforms such as i.MX93 this leads to compilation warnings because the value of MU_BASE is 32-bit while the pointers are 64-bit. As such, to solve this, add the ULL suffix to the definition of MU_BASE to make it 64-bit. Signed-off-by: Laurentiu Mihalcea <[email protected]>
On 64-bit platforms such as i.MX93 the pointers are 64-bit. As such, casting them to uint32_t leads to compilation warnings such as: "cast to pointer from integer of different size" To fix this, cast to size_t which, on 32-bit platforms is 32-bit and 64-bit on 64-bit platforms. Printing will be done via "%zx". Signed-off-by: Laurentiu Mihalcea <[email protected]>
cc4eb17
to
826892e
Compare
squashed it after all. The issue was introduced by b1fabd4 anyways. |
SOFCI TEST |
Ready to go, waiting for CI to complete, but based on earlier runs (and PR content), this should pass. |
comp_err(dev, "module_load_config(): wrong input params! dev %x, cfg %x size %zu", | ||
(uint32_t)dev, (uint32_t)cfg, size); | ||
comp_err(dev, "module_load_config(): wrong input params! dev %zx, cfg %zx size %zu", | ||
(size_t)dev, (size_t)cfg, size); |
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 we actually not just printing these as pointers per %p
?
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 remember some confusion about whether sof-logger supports %p
(I think it does)
The actual build part of "sof-ci/jenkins/pr-build" seems have been successful, so I'll proceed to merge this. |
Awesome, now that we have a warnings-free build, let's keep it that way. Please review very small -Werror PR: |
Currently, building SOF on a 64-bit system (i.e: i.MX93) leads to compilation warnings such as:
"format '%d' expects argument of type 'int', but argument 5 has type 'long unsigned int'" or
"cast to pointer from integer of different size"
This is because pointers are 64-bit and size_t resolves to a 64-bit type. As such, casting a pointer to uint32_t when printing leads to int-to-pointer-cast warnings. Also, printing a size_t variable using the "%d" or "%u" formats leads to format warnings.
To fix this, cast all size_t variables to uint32_t when printing. Pointers shall also be casted to uintptr_t before casting to uint32_t. This is fine to do because i.MX93 uses 32-bit addresses anyways.
This in conjunction with #8528 fixes all compilation warnings for i.MX93.
This fix is not that great since it forces 64-bit types to 32-bit and counts on the fact that you won't have values that need 64-bit encoding, but it's a start I guess.