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

src: make coefficients constant #8829

Merged
merged 1 commit into from
Feb 7, 2024
Merged

src: make coefficients constant #8829

merged 1 commit into from
Feb 7, 2024

Conversation

lyakh
Copy link
Collaborator

@lyakh lyakh commented Feb 2, 2024

Make coefficients and their tables constant.

Make coefficients and their tables constant.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
Copy link
Collaborator

@singalsu singalsu left a comment

Choose a reason for hiding this comment

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

Reminder to myself, update the generator script to produce header files with this change.

@lgirdwood
Copy link
Member

@singalsu btw, all the SRC coefficients are loaded into uncache memory IIUC i.e. from binutils nm

400a9ca8 D src_in_fs
400a9cc4 D src_int16_0_0_0_0
400a9cec D src_int16_1_1_0_0
400a9f1c D src_int16_1_2_1814_5000
400a9ef4 D src_int16_1_3_1814_5000
400a9ecc D src_int16_1_6_1814_5000
400a9d8c D src_int16_20_21_1667_5000
400a9ea4 D src_int16_2_1_1814_5000
400a9d64 D src_int16_21_20_1667_5000
400a9e7c D src_int16_2_3_1814_5000
400a9d3c D src_int16_24_25_1814_5000
400a9d14 D src_int16_25_24_1814_5000
400a9e54 D src_int16_3_1_1814_5000
400a9e2c D src_int16_3_2_1814_5000
400a9e04 D src_int16_6_1_1814_5000
400a9ddc D src_int16_7_8_1814_5000
400a9db4 D src_int16_8_7_1814_5000
400aa098 D src_lite_tr
400a9c8c D src_out_fs
400a9bc8 D src_table1
400a9b04 D src_table2
400aa090 D src_tr

This means we need to ucache_to_cache then when we set up the pointers for coeffs.

@lyakh
Copy link
Collaborator Author

lyakh commented Feb 6, 2024

@singalsu btw, all the SRC coefficients are loaded into uncache memory IIUC i.e. from binutils nm

400a9ca8 D src_in_fs
400a9cc4 D src_int16_0_0_0_0
400a9cec D src_int16_1_1_0_0
400a9f1c D src_int16_1_2_1814_5000
400a9ef4 D src_int16_1_3_1814_5000
400a9ecc D src_int16_1_6_1814_5000
400a9d8c D src_int16_20_21_1667_5000
400a9ea4 D src_int16_2_1_1814_5000
400a9d64 D src_int16_21_20_1667_5000
400a9e7c D src_int16_2_3_1814_5000
400a9d3c D src_int16_24_25_1814_5000
400a9d14 D src_int16_25_24_1814_5000
400a9e54 D src_int16_3_1_1814_5000
400a9e2c D src_int16_3_2_1814_5000
400a9e04 D src_int16_6_1_1814_5000
400a9ddc D src_int16_7_8_1814_5000
400a9db4 D src_int16_8_7_1814_5000
400aa098 D src_lite_tr
400a9c8c D src_out_fs
400a9bc8 D src_table1
400a9b04 D src_table2
400aa090 D src_tr

This means we need to ucache_to_cache then when we set up the pointers for coeffs.

@lgirdwood this is before this commit, right? After it I see these in .rodata with cached aliases

@singalsu
Copy link
Collaborator

singalsu commented Feb 6, 2024

@lgirdwood @lyakh Wait, do you mean that const C arrays are potentially corrupt if accessed without those address conversions?

@singalsu
Copy link
Collaborator

singalsu commented Feb 6, 2024

Also, fast coefficients access is key for good performance. If memory where these are located is slow, the tables that the active x to y kHz rate conversion uses should be copied to a memory where the SIMD MAC instructions work efficiently. Because the tables are very large like 100 - 200 kB it would make sense to keep them in a large slow memory and copy to fastest RAM only the much smaller that time needed set.

@lyakh
Copy link
Collaborator Author

lyakh commented Feb 7, 2024

@lgirdwood @lyakh Wait, do you mean that const C arrays are potentially corrupt if accessed without those address conversions?

so weird, I thought I'd replied, sorry. No, it isn't about corruption. And I don't think any conversion is needed. After this commit I see all those arrays accessed via cached aliases, but maybe I'm missing some build configuration @lgirdwood ?

BTW, there's one more thing to check - explicit type conversions like

coefp = (ae_p16x2s *)cp;
- that's already a bug. That one explicitly removes the const qualifier from exactly those coefficients IIUC, so it can then in principle be used to corrupt them, yes. I assume we have a few of such conversions in the sources...

@lyakh
Copy link
Collaborator Author

lyakh commented Feb 7, 2024

Replying to myself: I found -Wcast-qual - @singalsu please try building the sources with it, and maybe @marc-hb we should add it to SOF in general

@lyakh
Copy link
Collaborator Author

lyakh commented Feb 7, 2024

CI: a known suspend-resume problem in https://sof-ci.01.org/sofpr/PR8829/build2554/devicetest/index.html and a supposedly unrelated fuzzer failure. "main" Zephyr build failures are known too

@lgirdwood
Copy link
Member

This means we need to ucache_to_cache then when we set up the pointers for coeffs.

@lgirdwood this is before this commit, right? After it I see these in .rodata with cached aliases

ok, great good to know RO is properly mapped here.

@lgirdwood lgirdwood merged commit 7f4e6ae into thesofproject:main Feb 7, 2024
39 of 44 checks passed
@lyakh lyakh deleted the src branch February 7, 2024 16:19
@singalsu
Copy link
Collaborator

singalsu commented Feb 8, 2024

Replying to myself: I found -Wcast-qual - @singalsu please try building the sources with it, and maybe @marc-hb we should add it to SOF in general

I tried but I have no idea how to fix container_of() macro.

@lyakh
Copy link
Collaborator Author

lyakh commented Feb 9, 2024

Replying to myself: I found -Wcast-qual - @singalsu please try building the sources with it, and maybe @marc-hb we should add it to SOF in general

I tried but I have no idea how to fix container_of() macro.

@singalsu we could add a

#define const_container_of(ptr, type, member) \
	({const typeof(((type *)0)->member)*__memberptr = (ptr); \
	(const type *)((const char *)__memberptr - offsetof(type, member)); })

and use it for const pointers instead of the usual container_of()

@singalsu
Copy link
Collaborator

Thanks @lyakh I'll try it if I can proceed with it!

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