Skip to content

Conversation

@lyakh
Copy link
Collaborator

@lyakh lyakh commented Dec 4, 2020

Alignment should always be done on powers of 2. Enforcing this rule also allows the use of binary AND for alignment instead of much slower division. Also add compile-time checks where possible.

@paulstelian97
Copy link
Collaborator

Are the failures related to the PR or is the CI crazy?

@lgirdwood
Copy link
Member

@paulstelian97 CI looks wrong - this could be due to maintenance so I will rerun.

@lgirdwood
Copy link
Member

SOFCI TEST

@lgirdwood
Copy link
Member

@lyakh I've merged some PRs so henec the conflicts - best to rebase and check on your return.

@lyakh lyakh force-pushed the align-check branch 4 times, most recently from 7ae9f3f to 8996147 Compare December 24, 2020 16:24
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

Can you put more context in the commit message telling us what this is fixing today. i.e. where are non powers of two being used today.

@lyakh
Copy link
Collaborator Author

lyakh commented Jan 4, 2021

Can you put more context in the commit message telling us what this is fixing today. i.e. where are non powers of two being used today.

@lgirdwood that's exactly the purpose of this PR - to identify any such occurrences. So far I'm not aware of any but since until now SOF alignment supported non power of 2 values, I propose to put compilation guards for any such calls. So far I'm not aware of any. I'll extend the commit message.

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

More comments on why GCC and XCC are different here.

Copy link
Member

Choose a reason for hiding this comment

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

why is this different for XCC, need to state this delta in the comments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lgirdwood comment added, conflict resolved. However I don't like all qemu targets failing (at least before). Let's wait for the new test to finish and if failures are still there, who can help get some debugging information from those failures?

@lyakh lyakh force-pushed the align-check branch 2 times, most recently from 74fa586 to 201c479 Compare January 7, 2021 12:50
Alignment should always be done on powers of 2. Enforcing this
rule also allows the use of binary AND for alignment instead of
much slower division. Also add compile-time checks where possible.
At the moment no non-power-of-2 alignment cases are known in SOF,
but a complete verification is difficult, therefore we add
compile- and runtime checks, enabled by default for now. After a
period of time (one or two releases) this verification option can
be converted to an off by default configuration parameter.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@lgirdwood
Copy link
Member

@lyakh all passing now.

@lgirdwood lgirdwood merged commit 39266ca into thesofproject:master Jan 8, 2021
@lyakh lyakh deleted the align-check branch January 8, 2021 10:12
@marc-hb
Copy link
Collaborator

marc-hb commented Jan 14, 2021

The use of GCC statement-expressions in ALIGN means these macros cannot be used to initialize statics anymore. This broke ./scripts/xtensa-build-all.sh sue (and ../scripts/xtensa-build-all.sh -a) While we may not care about Sue Creek (CI does not build it), maybe we care about a less usable ALIGN macro?

See quick and dirty compilation fix with more details in marc-hb@unalign-sue

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 14, 2021

Would C11 _Static_assert() make this simpler and as flexible as before?

Is C11 too high of a requirement?

@marc-hb marc-hb requested review from cujomalainey and removed request for jajanusz January 14, 2021 22:15
@marc-hb
Copy link
Collaborator

marc-hb commented Jan 14, 2021

Would C11 _Static_assert() make this simpler and as flexible as before?

Simpler yes, as flexible as before: no. _Static_assert() seems to be a statement syntactically or something close enough to it.

Naive question: why not just change the "ALIGN API" to have a 2-exponent argument instead? I mean like this:

-#define  ALIGN_UP_INTERNAL(val, align) (((val) + (     align) - 1) & ~((     align) - 1))
+#define ALIGN_UP2_INTERNAL(val, align) (((val) + (1 << align) - 1) & ~((1 << align) - 1))

Since you performed a rename and search/replace anyway. No need for any assert anymore, this is correct by construction.
EXT_MAN_ALIGN becomes EXT_MAN_EXPONENT_ALIGN or something. If there are some inputs that really cannot be converted to an exponent then leave the old macro only in those places and add an explicit assert "manually" next to them instead of sneaking one in a statement-expression.

Just for fun PS, in 2007: https://lkml.org/lkml/2007/1/10/165

I noticed that the ALIGN() macro in kernel.h didn't verify that the
alignment value was a power of 2, so i thought...

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 15, 2021

I found the ALIGN_UP_COMPILE macro without any non standard GCC statement-expression and meant for static initializers. However memory.h files are also included in assembly and in linker files, so it was not enough.

Tentative fix in common.h: restore basic ALIGN() macro compatible with assembly #3747

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.

4 participants