-
Notifications
You must be signed in to change notification settings - Fork 349
Rename MIN and MAX to Z_MIN and Z_MAX for Zephyr compatibility #4002
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
Conversation
|
The 3 checkpatch warnings long predate this PR. |
src/audio/asrc/asrc.c
Outdated
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.
What does it mean 'Zephyr compatibility' ? Is Zephyr using Z_MAX naming instead of MAX?
Zephyr has both The longer story is in SOF issue zephyrproject-rtos/zephyr#33567 fixed by this. |
|
https://sof-ci.01.org/sof-pr-viewer/#/build/PR4002/build6260929 built and ran unit tests fine but did not run any "real" tests without any error message available anywhere. I don't think this is caused by this PR because the exact same happened an hour later for totally unrelated PR @zrombel any idea? PS: I filed internal issue PTS-31638 |
I'm downgrading this to a draft until we have at least one positive Quickbuild run considering the number of files changed by this PR and how insanely complicated C pre-processing can sometimes get (e.g. #3804). While Quickbuild has been mostly dysfunctional recently, when we're lucky the tests it runs can find bugs nothing else does. For instance there seems to be no default configuration using |
src/include/sof/math/numbers.h
Outdated
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.
Can we have a sof-rtos.h that defines Z_MIN, Z_MAX etc and also does a
#ifdef ZEPHYR
#error This file should not be in Zephyr build
#endif This way there is no confusion over which macro we are using.
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.
Yes but later please, immediately after merging this. I want to keep this gigantic commit free of functional changes. At this moment the binary output is exactly the same before/after this commit which makes super quick and convenient to validate; no need to run any test (except for making sure nothing is missing from it, hence the wait for QB).
It also enough to fix zephyrproject-rtos/zephyr#33567 which has been blocked on it for some time (sorry), don't want to delay that more with more complex projects.
This will also avoid drowning the future sof-rtos.h in this one. Continuous Integration.
Finally, everything except Quickbuild has been passing, even https://sof-ci.01.org/sofpr/PR4002/build8591/devicetest has. Don't want to risk losing such an exceptional planet alignment.
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.
Now is the best time to make functional changes - as we have just tagged v1.7. We have far bigger problems if we get confused between sof RTS and Zephyr about which macros and APIs we are using.
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 rest of the PR is good except for this part.
Today we wrap Zephyr RTOS.
- Call most SOF RTOS APIs natively.
- Have a zephyr/wrapper.c that wraps the zephyr calls to look like SOF calls.
The target is to wrap SOF/xtos RTOS
- Call all RTOS APIs as native zephyr APIs.
- Have a file and header that wraps the SOF RTOS calls/macros so they look like Zephyr.
This PR needs to create a sof/xtos wrapper.c and header.
|
There was a hardware issue, Quickbuild is running again and it's green: https://sof-ci.01.org/sof-pr-viewer/#/build/PR4002/build6263141 |
lyakh
left a comment
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'm not sure this is the best solution. First of all the "z_" namespace is used by Zephyr, so, claiming it now for us doesn't seem logical to me. Secondly, I thought our goal was to use Zephyr APIs natively, and Zephyr does already define MIN() and MAX(), right? So, for Zephyr builds we should just remove our own definitions of those and automatically begin using those from Zephyr. Whereas only for native non-Zephyr builds we should use our own MIN(), MAX(), etc. Isn't this what we wanted to do?
As I already wrote above, Zephyr APIs use both Before this PR, SOF uses This PR is a (literally) big step towards the goal of using Zephyr APIs by merely switching to the name |
Fixes zephyrproject-rtos/zephyr#33567 No functional change, compiler output is identical. Note a number of some source files modified are not compiled in the default configurations and were not even compile-tested locally: src/ipc/handler.c src/schedule/timer_domain.c zephyr/wrapper.c src/audio/codec_adapter/codec_adapter.c src/audio/drc/drc.c src/audio/drc/drc_generic.c src/audio/crossover/crossover.c src/audio/smart_amp/smart_amp.c src/audio/smart_amp/smart_amp_maxim_dsm.c Signed-off-by: Marc Herbert <marc.herbert@intel.com>
|
Pure rebase to fix small conflict with 2888212, here's the manual 1: 7a5db242d47e ! 10: b47edcd8b041 Rename MIN and MAX to Z_MIN and Z_MAX for Zephyr compatibility
## src/audio/codec_adapter/codec_adapter.c ##
/* Allocate local buffer */
-- buff_size = MAX(cd->period_bytes, codec->cpd.in_buff_size) * buff_periods;
-+ buff_size = Z_MAX(cd->period_bytes, codec->cpd.in_buff_size) * buff_periods;
+- buff_size = MAX(cd->period_bytes, codec->cpd.out_buff_size) * buff_periods;
++ buff_size = Z_MAX(cd->period_bytes, codec->cpd.out_buff_size) * buff_periods;
if (cd->local_buff) {
ret = buffer_set_size(cd->local_buff, buff_size);
if (ret < 0) { |
|
a note that Z_/z_ zephyr APIs are internal to zephyr and shall not be used outside of Zephyr. |
|
Thanks @nashif, can you confirm the boundary of what "internal" means? More specifically, can you confirm |
|
@nashif I'm assuming we just use Zephyr |
|
As stated earlier, the most urgent problem is to resolve the clash between Zephyr's compile-time Assuming SOF should never use
I'm all for code re-use and I hate duplication but for such simple and short macros I don't think it matters. In this case I think it's better to keep it simple and have the same macros use the same definition always. We've seen the massive confusion that can happen when the pre-processor gets abused (#3804, admittedly an extreme example). The focus should IMHO be to get these different configurations to just compile with limited complexity which as we're seeing is already a challenge because outdated C doesn't support namespaces and its pre-processor even less; hence these PS: yet another git conflict, this time with |
Speaking of holding back Zephyr, there will be an extra step after this: cherry-picking it to |
|
This seems to be getting bikesheddy. Really the stuff in Zephyr util.h is something of a special case. We provide a bunch of unprefixed macros there that more or less conform to broad industry[1] convention, like IS_ENABLED, ARRAY_SIZE, CONTAINER_OF, etc... MIN and MAX are two of those, though they have an extra wart where we split the API into single- and multiple- evaluating versions (I genuinely did not notice this had happened). No one really seems to think Zephyr shouldn't be able to define MIN and MAX. No one really seems to think SOF shouldn't be able to use the same macros. The fact that Z_MAX has a Z on the front obscures the argument, I think. It's really not an "internal" API in any meaningful sense and Zephyr has no particular interests in preventing its use outside the tree. Some options:
[1] Properly pronounced "linux" in this context. |
|
Thanks @andyross for the additional details and suggestions, much appreciated.
I don't think anyone has the time to actually review every single use of theses macros in SOF and whether it's safe to "downgrade" them to multiple evaluation versions in every single place. Moreover there's a high risk of long time SOF contributors wrongly assuming these macros are safe wrt. multiple evaluations because it's actually the case with plain SOF and the tests are actually passing. Really not a fan of using the same name for different, incompatible implementations depending on the context.
I ran some quick and dirty
That search and replace was some amount of work but it's already been done in this PR and it passed all the tests. Changing the name again is a small effort now.
SOF could keep its own SOF_MIN definitions even when ZEPHYR, no need for any smart pre-processor logic here, it would not add any value in this particular case. The fewer the layers of pre-processing indirections and logic always the better. |
|
All, direction of travel is SOF becomes a Zephyr module and hence we wrap then deprecate the xtos/HAL/SOF RTOS macros and APIs. |
|
Decision is not to use the Z_MIN/Z_MAX macros because no one should (in fact very few do)
I took the time, submitted at #4119 that supersedes this. Closing. |
Fixes zephyrproject-rtos/zephyr#33567
No functional change, compiler output is identical.
Note a number of some source files modified are not compiled in the
default configurations and were not even compile-tested locally:
Signed-off-by: Marc Herbert marc.herbert@intel.com