Skip to content
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

Rename IS_ALIGN() to SOF_IS_ALIGN() #8755

Closed
wants to merge 2 commits into from

Conversation

marc-hb
Copy link
Collaborator

@marc-hb marc-hb commented Jan 17, 2024

This is the simplest, cheapest and safest to avoid the collision with
the incoming Zephyr macro IS_ALIGN() submitted in
zephyrproject-rtos/zephyr#67243

As SOF depends on Zephyr, most SOF symbols should be prefixed SOF_ or
something specific.

This is compliant with:
https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#rule-a-3-macro-name-collisions

Signed-off-by: Marc Herbert [email protected]

This reverts commit 0a3b816.

Opportunistic, `#ifndef` definitions make macro troubleshooting even
more of a nightmare than it already is.

https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#rule-a-3-macro-name-collisions
forbids #ifndef in Zephyr.

Signed-off-by: Marc Herbert <[email protected]>
This is the simplest, cheapest and safest to avoid the collision with
the incoming Zephyr macro IS_ALIGN() submitted in
zephyrproject-rtos/zephyr#67243

As SOF depends on Zephyr, most SOF symbols should be prefixed SOF_ or
something specific.

This is compliant with:
https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#rule-a-3-macro-name-collisions

Signed-off-by: Marc Herbert <[email protected]>
@marc-hb
Copy link
Collaborator Author

marc-hb commented Jan 17, 2024

Failures to compile with the Zephyr main branch are known and unrelated:
https://github.com/thesofproject/sof/actions/runs/7562861040/job/20594168710?pr=8754

implicit declaration of function 'z_smp_thread_init';

They're caused by backwards-incompatible change:

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jan 18, 2024

Unrelated pause-resume failure in ACE https://sof-ci.01.org/sofpr/PR8755/build1982/devicetest/index.html . pause-resume is not reliable right now. Maybe #8651?

Unrelated FW reported error: 104 - Other failure of module instance initialization request in https://sof-ci.01.org/sofpr/PR8755/build1983/devicetest/index.html, thesofproject/linux#4832

checkpatch https://github.com/thesofproject/sof/actions/runs/7563103579/job/20594859309?pr=8755 complains about the URL being too long.

Everything else green.

Copy link
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to use native Zephyr APIs and this seems to be taking us away from it

#define IS_ALIGNED(size, alignment) ((size) % (alignment) == 0)
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if zephyrproject-rtos/zephyr#67243 happens to be merged before this (yes, I know that it's currently blocked) and we move to a Zephyr version after it, this would break compilation. Why not just merge these two commits?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should hold of until we can get the Zephyr interface merged in. We have the SMP interface in flight (plus the regression), so the air is getting too thick with incompatible combinations.

@@ -633,7 +633,7 @@ static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t
period_count);
buf_size = period_count * period_bytes;
do {
if (IS_ALIGNED(buf_size, max_block_count)) {
if (SOF_IS_ALIGNED(buf_size, max_block_count)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it the plan then after zephyrproject-rtos/zephyr#67243 is merged to move to the "proper" Zephyr-provided IS_ALIGNED() and to rename back?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an alternative would be to take the Zephyr change with IS_ALIGNED in, then add IS_ALIGNED definition only for xtos builds in SOF, and call it a day.

The current ifdef can carry us until then.

Or we merge this, but I agree this is going against our long term plans. We want to use native Zephyr interfaces in generic SOF code whenever possible (e.g. #5794).

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this we should consider also moving this to rtos abstraction and keep using native interfaces.

#define IS_ALIGNED(size, alignment) ((size) % (alignment) == 0)
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should hold of until we can get the Zephyr interface merged in. We have the SMP interface in flight (plus the regression), so the air is getting too thick with incompatible combinations.

@@ -633,7 +633,7 @@ static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t
period_count);
buf_size = period_count * period_bytes;
do {
if (IS_ALIGNED(buf_size, max_block_count)) {
if (SOF_IS_ALIGNED(buf_size, max_block_count)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an alternative would be to take the Zephyr change with IS_ALIGNED in, then add IS_ALIGNED definition only for xtos builds in SOF, and call it a day.

The current ifdef can carry us until then.

Or we merge this, but I agree this is going against our long term plans. We want to use native Zephyr interfaces in generic SOF code whenever possible (e.g. #5794).

Copy link
Collaborator Author

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to use native Zephyr APIs and this seems to be taking us away from it

In theory yes. In practice these are 4 lines in 2 files.

Every time we want to use a "Zephyr API", we have to implement some indirection logic for XTOS that we (Intel) can't test any more.

Calling this one-liner macro a "Zephyr API" is blowing it out of proportion.

I'm aware the "air is getting thick" and this is precisely why this PR is the simplest, cheapest and safest solution in the short term. I understand and agree in general but this particular example is just 4 lines; let's not over-engineer it.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jan 19, 2024

In theory yes. In practice these are 4 lines in 2 files.

4 lines including... 3 lines in unused and never compiled kpb.c. I had to change the defconfig to compile-test it.

I think we have much bigger problems to solve than making this one-liner macro used once "API policy compliant"

Copy link
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, no, I don't like this. I really don't think we should add a SOF_* version for every Zephyr macro. We want to use them directly and for non-Zephyr builds define them in compatibility headers.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jan 19, 2024

I really don't think we should add a SOF_* version for every Zephyr macro.

I forgot how many times I wrote "just this one, with have bigger problems"

We want to use them directly and for non-Zephyr builds define them in compatibility headers.

Agreed, please send a better (and tested) PR since you have the time.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jan 19, 2024

After a chat with @lyakh I realized I forgot to explicit the main concern behind this PR: if the SOF definition is guarded with the (evil) #ifndef and the Zephyr definition is not (cause it's evil), then compilation success depends on which order the .h files are included. Anything that depends on inclusion order is of course super evil too.

I admit I didn't check whether inclusion order this an actual problem right now, it was much faster (and safer) to submit this PR. Actually testing this inclusion order problem could require testing multiple defconfig variations again.

Even if not today, the inclusion order could very easily become a real problem in any future refactoring. Hence this dead simple PR to move on with our lives.

@lyakh
Copy link
Collaborator

lyakh commented Jan 19, 2024

After a chat with @lyakh I realized I forgot to explicit the main concern behind this PR: if the SOF definition is guarded with the (evil) #ifndef and the Zephyr definition is not (cause it's evil), then compilation success depends on which order the .h files are included. Anything that depends on inclusion order is of course super evil too.

I admit I didn't check whether inclusion order this an actual problem right now, it was much faster (and safer) to submit this PR. Actually testing this inclusion order problem could require testing multiple defconfig variations again.

Even if not today, the inclusion order could very easily become a real problem in any future refactoring. Hence this dead simple PR to move on with our lives.

@marc-hb no, there's no order problem there. The header is already included before the #ifndef:

#ifdef __ZEPHYR__
#include <zephyr/sys/util.h>
#endif
/* Align the number to the nearest alignment value */
#ifndef IS_ALIGNED
#define IS_ALIGNED(size, alignment) ((size) % (alignment) == 0)
#endif

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jan 19, 2024

OK, let's not worry then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants