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

sof: coherent: Don't mark "struct coherent" as packed #8528

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

LaurentiuM1234
Copy link
Contributor

On 64-bit systems (i.e: i.MX93), marking "struct coherent" as packed leads to compilation warnings such as:

"warning: taking address of packed member of 'struct coherent' may result in an unaligned pointer value"

This is because the "list" attribute is found at offset 36, which is not 8B-aligned.

Since marking "struct coherent" as packed doesn't seem to be necessary, remove this to fix the compilation warnings.

A more detailed discussion regarding this issue can be found here: #8521.

@kv2019i
Copy link
Collaborator

kv2019i commented Nov 27, 2023

Adding @lyakh and @ranj063 to review. I can't recall why this was packed, but let's check with people working on the code. One part of coherent was that the "struct header" it adds to objects would need to be cache-line aligned. Not sure if packing is the right approach even then.

@lgirdwood
Copy link
Member

Packing was done to optimize on cache lines, but the atomic lock needs to be arch specific for size and alignment. i..e removing the pack should be fine on 32bit as types should naturally shrink.

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 27, 2023

You could/should say in the commit message that pahole shows that packed does not make any difference on 32 bits at the moment.

On 64-bit systems (i.e: i.MX93), marking "struct coherent"
as packed leads to compilation warnings such as:

"warning: taking address of packed member of 'struct coherent'
may result in an unaligned pointer value"

This is because the "list" attribute is found at offset 36,
which is not 8B-aligned. In contrast, 32-bit systems
don't have this problem as the "list" attribute is found at
offset 24 which is 4B-aligned.

Since marking "struct coherent" as packed doesn't seem to
be necessary, remove this to fix the compilation warnings.
On 32-bit systems, 'pahole' shows no difference between
the 'packed' and the non-'packed' cases as the fields are
already naturally aligned at the moment.

A more detailed discussion regarding this issue can be
found here: thesofproject#8521.

Signed-off-by: Laurentiu Mihalcea <[email protected]>
@LaurentiuM1234
Copy link
Contributor Author

You could/should say in the commit message that pahole shows that packed does not make any difference on 32 bits at the moment.

done!

@LaurentiuM1234
Copy link
Contributor Author

Packing was done to optimize on cache lines, but the atomic lock needs to be arch specific for size and alignment. i..e removing the pack should be fine on 32bit as types should naturally shrink.

By this you mean that packing struct coherent helps with fitting a structure/multiple structures using it in a single data cache line (since it should take less space)?

@lgirdwood
Copy link
Member

Packing was done to optimize on cache lines, but the atomic lock needs to be arch specific for size and alignment. i..e removing the pack should be fine on 32bit as types should naturally shrink.

By this you mean that packing struct coherent helps with fitting a structure/multiple structures using it in a single data cache line (since it should take less space)?

Yes, packing meant we helped optimise any struct fields to be on the same cache line. Never needed in practice though as the struct never grew much and was always smaller than cache line size.

marc-hb added a commit to marc-hb/sof that referenced this pull request Nov 27, 2023
Supersedes the "best effort" use of `packed`, being removed by thesofproject#8528

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

marc-hb commented Nov 27, 2023

Yes, packing meant we helped optimise any struct fields to be on the same cache line.

I submitted an compile-time assert in new #8539 which makes sure for real.

Never needed in practice though as the struct never grew much and was always smaller than cache line size.

At least AMD's Renoir has a DCACHE_LINE_SIZE of 8 bytes which is too small for struct coherent. There may be others, I didn't really check.

@LaurentiuM1234
Copy link
Contributor Author

At least AMD's Renoir has a DCACHE_LINE_SIZE of 8 bytes which is too small for struct coherent. There may be others, I didn't really check.

Hmm, I guess we could have went with the re-ordering of the struct coherent's attributes such that struct list_item is the first attribute and keeping struct coherent packed but in cases such as this one, keeping the packed attribute won't do much good either.

@kv2019i kv2019i merged commit d42911d into thesofproject:main Nov 28, 2023
41 of 43 checks passed
dbaluta pushed a commit that referenced this pull request Dec 5, 2023
Supersedes the "best effort" use of `packed`, being removed by #8528

Signed-off-by: Marc Herbert <[email protected]>
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.

6 participants