Skip to content

Conversation

@marc-hb
Copy link
Collaborator

@marc-hb marc-hb commented Nov 29, 2023

CMake decentralization per #8260

EDIT: There seems to be some confusion happening in the review comments right now.

Clarification: this CMake PR is BUG-FOR-BUG compatible.

There are Cmake and CONFIG bugs in zephyr/CMakeLists.txt right now that this #8260 effort is exposing. The purpose of this PR is to carefully NOT fix any of these bugs. The commits in this PR and all other 8260 commits in general are way too big to hide small functional changes inside. You really don't want your git bisect to land on a giant CONFIG_ commit like these. So this PR is strictly "bug-preserving". Garbage in, exact same garbage out.

If this PR made you discover some existing CMake or CONFIG bug, then please submit a smaller PR either before this PR is merged (and I will rebase and adjust), or after this PR. But please stop asking for bug fixes here.

marc-hb added a commit to marc-hb/sof that referenced this pull request Nov 29, 2023
In the review of commit 1bd9e0d ("cmake/zephyr: decentralize
src/ipc/"), Andy recommended "maybe work around this by adding yet
another layer of indirection". I rejected the idea at the time because
the level of duplication in the ipc/ directory was small. Then I looked
at the bigger math/ subdirectory and I realized in thesofproject#8548 that such an
indirection layer is actually required for bigger and/or more complex
cases. So I added that layer of indirection in commit
330d73e ("cmake: a few new add_local_sources[_ifdef]()
compatibility macros")

Now that we have it, we might as well use it and perform small
simplifications in ipc/cmake.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
@marc-hb marc-hb marked this pull request as ready for review November 30, 2023 00:15
@marc-hb marc-hb requested a review from singalsu as a code owner November 30, 2023 00:15
@keqiaozhang
Copy link
Collaborator

SOFCI TEST

@marc-hb
Copy link
Collaborator Author

marc-hb commented Nov 30, 2023

add_local_sources(sof numbers.c)

if(CONFIG_CORDIC_FIXED)
if(CONFIG_CORDIC_FIXED OR it_is_zephyr)
Copy link
Member

Choose a reason for hiding this comment

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

Btw, do we have a CONFIG_ZEPHYR we can use here instead of it_is_zephyr ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is_zephyr is only a check for CONFIG_ZEPHYR_SOF_MODULE. The indirection is for brevity, flexibility and "future-proofness".

Copy link
Member

Choose a reason for hiding this comment

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

why not just use CONFIG_ZEPHYR_SOF_MODULE if they are equivalent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are equivalent now but who knows in the future. I'm currently spreading this conditional across almost all sof/**/CMakeLists.txt files, so this very thin indirection protects us against any future change. If this CONFIG_ namve ever changes in Zephyr in the future we could even make the macro support both the old and new for a seamless transition.

Copy link
Member

Choose a reason for hiding this comment

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

If they are equivalent now then pls use, otherwise this is really just unneeded indirection today.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tend to agree that the existing kconfigs aren't super well named for this purpose. They're artifacts of the way the upstream Zephyr module system works: ZEPHYR_SOF_MODULE is automatically generated, and 'config SOF' is added in the Kconfig for the module. FWIW I NAK'd the latter because in this context it means the opposite of what it says ("CONFIG_SOF" might be expected to mean "xtos/traditional SOF and not Zephyr", when it means the opposite).

My personal vote would be a SOF-internal API that contains "zephyr" in the name like this one. Whether it's a kconfig or a cmake macro doesn't seem all that important I guess? Would be easy to fix in a different patch too.

Copy link
Collaborator Author

@marc-hb marc-hb Dec 5, 2023

Choose a reason for hiding this comment

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

CONFIG_CORDIC OR CONFIG_ZEPHYR_SOMETHING_MODULE_OPTION_OF_THE_DAY would also give the wrong impression that both are choices, see discussion below. The second one is obviously not a CONFIGuration choice.

Copy link
Member

Choose a reason for hiding this comment

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

We have a lot of naming inconsistent in SOF Kconfig space today, moving forward for v2.9 we can fix this with a CONFIG_SOF_ prefix i.e. its a SOF application Kconfig. For maths stuff we are going to be moving for v2.9 to
CONFIG_SOF_MATH_X
For Zephyr stuff, we need something CONFIG_SOF_ZEPHYR_X the precedence being this is a SOF Kconfig and NOT a Zephyr Kconfig.
@marc-hb can you incrementally change the is_zephyr to use the Kconfig, this way is easier for everyone to follow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For Zephyr stuff, we need something CONFIG_SOF_ZEPHYR_X the precedence being this is a SOF Kconfig and NOT a Zephyr Kconfig.
@marc-hb can you incrementally change the is_zephyr to use the Kconfig, this way is easier for everyone to follow.

You lost me sorry.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just found that some places started using CONFIG_ZEPHYR_NATIVE_DRIVERS...

Copy link
Contributor

@ShriramShastry ShriramShastry left a comment

Choose a reason for hiding this comment

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

I've added my review comments. I welcome you making changes.

add_local_sources(sof numbers.c)

if(CONFIG_CORDIC_FIXED)
if(CONFIG_CORDIC_FIXED OR it_is_zephyr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the same name for managing math functions under Zephyr is not a good idea.

Copy link
Collaborator Author

@marc-hb marc-hb Dec 5, 2023

Choose a reason for hiding this comment

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

I'm not sure I understand @ShriramShastry. The purpose of this PR is to be very careful and NOT make any config "management" change. That can come later after this clean up. Currently, maths function are NOT managed in Zephyr. Did you not notice?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, What I mean is that it_is_zephyr is used to enable and disable math functions. If the function is called in the code, you enable it_is_zephyr, otherwise you turn it off. What I'm not persuaded of is the use of the same flag (it_is_zephyr) across Zephyr code . If you have a solid justification (That's Zephyr) for using the same name, that's fine; otherwise, I advocate using a distinct naming policy for each math function.

Copy link
Collaborator Author

@marc-hb marc-hb Dec 5, 2023

Choose a reason for hiding this comment

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

that it_is_zephyr is used to enable and disable math functions

No, that's not what it is. No one is going to "turn Zephyr on/off" to enable/disable some math functions. No one can decide whether they use Zephyr or not, it's not a choice. There is no such choice.

Before this PR:

  • CORDIC is not optional in Zephyr. No such config "management" in Zephyr.

After this PR:

  • CORDIC is not optional in Zephyr. No such config "management" in Zephyr.

The purpose of this PR is to carefully NOT change that.

If you want make to make CORDIC or other math code CONFIGurable in Zephyr then please submit a separate PR. This PR is a pure clean-up, it does not make any CONFIG change.

add_local_sources_ifdef(CONFIG_MATH_EXP sof exp_fcn.c exp_fcn_hifi.c)

if(CONFIG_MATH_DECIBELS)
if(CONFIG_MATH_DECIBELS OR it_is_zephyr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the same name for managing math functions under Zephyr is not a good idea.

Copy link
Collaborator

Choose a reason for hiding this comment

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

my question of the day to these changes: I understand that it's just carried over from the present global sof/zephyr/CMakeLists.txt, but now that we move to these local files, shouldn't we rather just select MATH_DECIBELS somewhere with Zephyr?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I am thinking about it, and it makes more sense to me to have a select option with Zephyr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

shouldn't we rather just select MATH_DECIBELS somewhere with Zephyr?

Maybe yes but please, please do not distract this PR even further :-(

marc-hb added a commit to marc-hb/sof that referenced this pull request Dec 5, 2023
In the review of commit 1bd9e0d ("cmake/zephyr: decentralize
src/ipc/"), Andy recommended "maybe work around this by adding yet
another layer of indirection". I rejected the idea at the time because
the level of duplication in the ipc/ directory was small. Then I looked
at the bigger math/ subdirectory and I realized in thesofproject#8548 that such an
indirection layer is actually required for bigger and/or more complex
cases. So I added that layer of indirection in commit
330d73e ("cmake: a few new add_local_sources[_ifdef]()
compatibility macros")

Now that we have it, we might as well use it and perform small
simplifications in ipc/cmake.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
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.

There seems to be some confusion happening in the review comments right now.

Clarification: this CMake PR is BUG-FOR-BUG compatible.

There are Cmake and CONFIG bugs in zephyr/CMakeLists.txt right now that this #8260 effort is exposing. The purpose of this PR is to carefully NOT fix any of these bugs. The commits in this PR and all other 8260 commits in general are way too big to hide small functional changes inside. You really don't want your git bisect to land on a giant CONFIG_ commit like these. So this PR is strictly "bug-preserving". Garbage in, exact same garbage out.

If this PR made you discover some existing CMake or CONFIG bug, then please submit a smaller PR either before this PR is merged (and I will rebase and adjust), or after this PR. But please stop asking for bug fixes here.

I edited the description too.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Dec 6, 2023

Demoting to draft until @andrula-song 's bug fix is reviewed:

@marc-hb marc-hb marked this pull request as draft December 6, 2023 08:03
CMake decentralization per thesofproject#8260

The purpose of thesofproject#8260 is to divide and conquer the giant
zephyr/CMakeLists.txt file while staying _bug-for-bug compatible_.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
@marc-hb marc-hb marked this pull request as ready for review December 6, 2023 21:47
@marc-hb
Copy link
Collaborator Author

marc-hb commented Dec 6, 2023

Rebased on top of #8551. More comments added, thanks for the feedback!

lgirdwood pushed a commit that referenced this pull request Dec 7, 2023
In the review of commit 1bd9e0d ("cmake/zephyr: decentralize
src/ipc/"), Andy recommended "maybe work around this by adding yet
another layer of indirection". I rejected the idea at the time because
the level of duplication in the ipc/ directory was small. Then I looked
at the bigger math/ subdirectory and I realized in #8548 that such an
indirection layer is actually required for bigger and/or more complex
cases. So I added that layer of indirection in commit
330d73e ("cmake: a few new add_local_sources[_ifdef]()
compatibility macros")

Now that we have it, we might as well use it and perform small
simplifications in ipc/cmake.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
@marc-hb
Copy link
Collaborator Author

marc-hb commented Dec 12, 2023

I volunteered to do this on my "spare time" but this is proving too time consuming, it needs proper planning. Maybe another time?

@marc-hb marc-hb closed this Dec 12, 2023
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.

8 participants