Skip to content

Conversation

@marc-hb
Copy link
Collaborator

@marc-hb marc-hb commented Jul 1, 2021

See commit messages.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jul 1, 2021

The only checkpatch warning is WARNING: Consider removing the #if 1 and its #endif

Copy link
Member

Choose a reason for hiding this comment

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

We are probably missing other const usage wrt IPC too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably, this one just came up when looking at your valgrind fixes.

@lgirdwood
Copy link
Member

The only checkpatch warning is WARNING: Consider removing the #if 1 and its #endif

So CI is building and running successfully here with the new assert. I assume you have checked the binary size difference with XCC (assume GCC will be the same).

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.

So CI is building and running successfully here with the new assert.

No, it's commented out.

I assume you have checked the binary size difference with XCC (assume GCC will be the same).

I checked only with gcc10 and only with the default flags, that's why I left it commented out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably, this one just came up when looking at your valgrind fixes.

@lgirdwood
Copy link
Member

So CI is building and running successfully here with the new assert.

No, it's commented out.

I assume you have checked the binary size difference with XCC (assume GCC will be the same).

I checked only with gcc10 and only with the default flags, that's why I left it commented out.

ok, lets check with XCC before we merge this as we can remove the conditional or have an #if XCC instead.

@lgirdwood
Copy link
Member

So CI is building and running successfully here with the new assert.

No, it's commented out.

I assume you have checked the binary size difference with XCC (assume GCC will be the same).

I checked only with gcc10 and only with the default flags, that's why I left it commented out.

ok, lets check with XCC before we merge this as we can remove the conditional or have an #if XCC instead.

oh - CI probably has the info for XCC builds ?

marc-hb added 4 commits July 3, 2021 05:58
Does not silently succeeds when passed variables. Not enabled by default
in the unlikely case it wastes memory with some compiler and/or compiler
flags.

Issue found while testing tracing mismatch thesofproject#4388

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
'const' documents APIs and catches bugs.

This came while discussing thesofproject#4408

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
As requested in previous PR thesofproject#4428

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
Pure comments, no code change. Follow-up to commit 8633d5f ("cavs:
pm: improve PM_RUNTIME_HOST_DMA_L1 documentation")

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
@marc-hb marc-hb force-pushed the comments-ipc-const branch from 8ff495c to c48ddf6 Compare July 3, 2021 06:01
@marc-hb
Copy link
Collaborator Author

marc-hb commented Jul 3, 2021

I tested gcc and xcc with various -O levels. I found only one case where the array-based assert increases the .bss: gcc with -O0. All other cases keep the sizes the same. The xcc versions I looked at optimize the unused array away even at the -O0 level.

Comment updated accordingly.

#else
#define STATIC_ASSERT(COND, MESSAGE) \
__attribute__((unused)) \
static char META_CONCAT(arr_assertion_failed_, MESSAGE)[(COND) ? 1 : -1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it have to be static? And there's an additional space there

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does it have to be static?

Depends where you prefer to waste a few bytes per assertion at the -O0 level. I suspect the .bss is likely to have less performance impact.

And there's an additional space there

That was for aligning with the other one but not very useful, I can remove.

Copy link
Collaborator Author

@marc-hb marc-hb Jul 5, 2021

Choose a reason for hiding this comment

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

Depends where you prefer to waste a few bytes per assertion at the -O0 level. I suspect the .bss is likely to have less performance impact.

Actually: I didn't check whether gcc -O0 allocates unused local variables or not.

This is the reason this is disabled by default: it's very tedious and more importantly: unreliable to test every optimization level for every compiler.

@lgirdwood
Copy link
Member

I tested gcc and xcc with various -O levels. I found only one case where the array-based assert increases the .bss: gcc with -O0. All other cases keep the sizes the same. The xcc versions I looked at optimize the unused array away even at the -O0 level.

Comment updated accordingly.

Do we still need the #if 1 if not we can make this the default check or would you be happy to keep this around for more validation ?

@marc-hb
Copy link
Collaborator Author

marc-hb commented Jul 6, 2021

Do we still need the #if 1 if not we can make this the default check or would you be happy to keep this around for more validation ?

I don't like #if 1 either but this is really tricky situation.

On one hand I discovered that the typedef-based solution can silently succeed with variables, which is really bad for something called STATIC_ASSERT!

On the other hand the array based solution is 100% reliable BUT it can waste some memory with some compilers at the -O0 level. I can't test future compilers. So that's why I'm submitting it commented out: if anyone ever has some STATIC_ASSERT doubts like I had, they can quickly and locally use the array-based one and find their mistake.

@lgirdwood
Copy link
Member

CI showung a non booting DUT and a know alsabat issue on APL nocodec, both unrelated.

@lgirdwood lgirdwood merged commit 9d84c15 into thesofproject:main Jul 7, 2021
@marc-hb marc-hb deleted the comments-ipc-const branch September 2, 2021 23:47
@marc-hb marc-hb mentioned this pull request Sep 28, 2021
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