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

support "cold" data and code #9754

Merged
merged 5 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/zephyr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ jobs:
path: ./workspace/sof
filter: 'tree:0'

- name: free space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc

- name: west clones
run: pip3 install west && cd workspace/sof/ && west init -l &&
west update --narrow --fetch-opt=--filter=tree:0
Expand Down
8 changes: 8 additions & 0 deletions Kconfig.sof
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ config COMPILER_INLINE_FUNCTION_OPTION
help
When enabled, -fno-inline-function option is not passed to compiler

config COLD_STORE_EXECUTE_DRAM
Copy link
Member

Choose a reason for hiding this comment

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

I like this concept of the cold store. i.e. we keeps things in the cold store until we need to use them.

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 rather "unless," than "until." In most cases e.g. with "cold base firmware code" it's never copied to SRAM, it's marked as non-performance critical and is always executed in DRAM. Same with LLEXT module code. By default the same is done with data. But with data we plan an optimisation where one can explicitly request a copy of "cold" data in SRAM for a limited period of time.

bool "Execute and use cold data and code in DRAM"
help
Non-performance critical data and code can be kept in DRAM to be
accessed and executed there without copying to SRAM. Select this
option to enable this feature to save SRAM and to speed up SRAM
copying of performance-critical data and code.

rsource "src/Kconfig"

# See zephyr/modules/Kconfig
Expand Down
1 change: 1 addition & 0 deletions app/boards/intel_adsp_ace15_mtpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS=y
CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS=y
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: enabld

CONFIG_ZEPHYR_NATIVE_DRIVERS=y
CONFIG_ZEPHYR_DP_SCHEDULER=y
CONFIG_COLD_STORE_EXECUTE_DRAM=y

# SOF / loadable modules
CONFIG_INTEL_MODULES=y
Expand Down
8 changes: 8 additions & 0 deletions posix/include/sof/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@

#include <platform/lib/memory.h>

#ifndef __cold
#define __cold
#endif

#ifndef __cold_rodata
#define __cold_rodata
#endif

#endif /* __SOF_LIB_MEMORY_H__ */
8 changes: 4 additions & 4 deletions scripts/llext_link_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def main():
# run at arbitrary memory locations. One of the use-cases is running
# parts of the module directly in DRAM - sacrificing performance but
# saving scarce SRAM. We achieve this by placing non-performance
# critical functions in a .text.dram ELF section. When compiling and
# linking such functions, an additional .literal.dram section is
# automatically created. Note, that for some reason the compiler also
# marks that section as executable.
# critical functions in a .cold ELF section. When compiling and linking
# such functions, an additional .cold.literal section is automatically
# created. Note, that for some reason the compiler also marks that
# section as executable.
# This script links those sections at address 0. We could hard-code
# section names, but so far we choose to only link .text the "original"
# way and all other executable sections we link at 0.
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mfcc/mfcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SOF_DEFINE_REG_UUID(mfcc);

DECLARE_TR_CTX(mfcc_tr, SOF_UUID(mfcc_uuid), LOG_LEVEL_INFO);

const struct mfcc_func_map mfcc_fm[] = {
__cold_rodata const struct mfcc_func_map mfcc_fm[] = {
#if CONFIG_FORMAT_S16LE
{SOF_IPC_FRAME_S16_LE, mfcc_s16_default},
#endif /* CONFIG_FORMAT_S16LE */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mixin_mixout/mixin_mixout_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static void mix_s32_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t
}
#endif /* CONFIG_FORMAT_S32LE */

const struct mix_func_map mix_func_map[] = {
__cold_rodata const struct mix_func_map mix_func_map[] = {
#if CONFIG_FORMAT_S16LE
{ SOF_IPC_FRAME_S16_LE, mix_s16, mix_s16_gain },
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mixin_mixout/mixin_mixout_hifi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ static void mix_s32_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t

#endif /* CONFIG_FORMAT_S32LE */

const struct mix_func_map mix_func_map[] = {
__cold_rodata const struct mix_func_map mix_func_map[] = {
#if CONFIG_FORMAT_S16LE
{ SOF_IPC_FRAME_S16_LE, mix_s16, mix_s16_gain },
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mixin_mixout/mixin_mixout_hifi5.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static void mix_s32(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe
#endif /* CONFIG_FORMAT_S32LE */

/* TODO: implement mixing functions with gain support!*/
const struct mix_func_map mix_func_map[] = {
__cold_rodata const struct mix_func_map mix_func_map[] = {
#if CONFIG_FORMAT_S16LE
{ SOF_IPC_FRAME_S16_LE, mix_s16, mix_s16 },
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/audio/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ static uint32_t vol_zc_get_s32(const struct audio_stream *source,

#endif /* CONFIG_FORMAT_S32LE */

/** \brief Map of formats with dedicated zc functions. */
static const struct comp_zc_func_map zc_func_map[] = {
/**
* \brief Map of formats with dedicated zc functions.
*
* This is only used during @c .prepare() so it isn't performance-critical.
*/
__cold_rodata static const struct comp_zc_func_map zc_func_map[] = {
#if CONFIG_FORMAT_S16LE
{ SOF_IPC_FRAME_S16_LE, vol_zc_get_s16 },
#endif /* CONFIG_FORMAT_S16LE */
Expand Down
6 changes: 0 additions & 6 deletions src/include/module/module/llext.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ static const struct sof_module_api_build_info buildinfo __section(".mod_buildinf
.api_version_number.full = SOF_MODULE_API_CURRENT_VERSION, \
}

#if CONFIG_LLEXT_TYPE_ELF_RELOCATABLE && defined(LL_EXTENSION_BUILD)
#define __cold __section(".text.dram")
#else
#define __cold
#endif

#endif
2 changes: 1 addition & 1 deletion src/ipc/ipc4/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4)
* delete module <-------> free component
*/

static int ipc4_init_module_instance(struct ipc4_message_request *ipc4)
__cold static int ipc4_init_module_instance(struct ipc4_message_request *ipc4)
{
struct ipc4_module_init_instance module_init;
struct comp_dev *dev;
Expand Down
6 changes: 3 additions & 3 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static inline char *ipc4_get_comp_new_data(void)
}
#endif

struct comp_dev *comp_new_ipc4(struct ipc4_module_init_instance *module_init)
__cold struct comp_dev *comp_new_ipc4(struct ipc4_module_init_instance *module_init)
{
struct comp_ipc_config ipc_config;
const struct comp_driver *drv;
Expand Down Expand Up @@ -966,9 +966,9 @@ const struct comp_driver *ipc4_get_comp_drv(uint32_t module_id)
uint32_t lib_idx = LIB_MANAGER_GET_LIB_ID(module_id);

if (lib_idx == 0) {
/* module_id 0 is used for base fw which is in entry 1 */
/* module_id 0 is used for base fw which is in entry 1 or 2 */
if (!module_id)
entry_index = 1;
entry_index = 1 + IS_ENABLED(CONFIG_COLD_STORE_EXECUTE_DRAM);
else
entry_index = module_id;

Expand Down
6 changes: 6 additions & 0 deletions src/platform/ace30/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
*/
#define HEAPMEM_SIZE 0xD0000

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
#define __cold __section(".cold")
#define __cold_rodata __section(".coldrodata")
#endif

#endif /* __PLATFORM_LIB_MEMORY_H__ */

#else
Expand Down
6 changes: 6 additions & 0 deletions src/platform/lunarlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
*/
#define HEAPMEM_SIZE 0xF0000

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
#define __cold __section(".cold")
#define __cold_rodata __section(".coldrodata")
#endif

#endif /* __PLATFORM_LIB_MEMORY_H__ */

#else
Expand Down
6 changes: 6 additions & 0 deletions src/platform/meteorlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
*/
#define HEAPMEM_SIZE 0xF0000

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
#define __cold __section(".cold")
#define __cold_rodata __section(".coldrodata")
#endif

#endif /* __PLATFORM_LIB_MEMORY_H__ */

#else
Expand Down
14 changes: 14 additions & 0 deletions tools/rimage/config/lnl.toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

index = __COUNTER__

#if CONFIG_COLD_STORE_EXECUTE_DRAM
[[module.entry]]
name = "COLD"
uuid = "D406D134-C3C1-402C-8AEC-6821C0C2B0E6"
affinity_mask = "3"
instance_count = "1"
domain_types = "0"
load_type = "0"
module_type = "0"
auto_start = "0"

index = __COUNTER__
#endif

[[module.entry]]
name = "BASEFW"
uuid = "0E398C32-5ADE-BA4B-93B1-C50432280EE4"
Expand Down
14 changes: 14 additions & 0 deletions tools/rimage/config/mtl.toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

index = __COUNTER__

#if CONFIG_COLD_STORE_EXECUTE_DRAM
[[module.entry]]
name = "COLD"
uuid = "D406D134-C3C1-402C-8AEC-6821C0C2B0E6"
affinity_mask = "3"
instance_count = "1"
domain_types = "0"
load_type = "0"
module_type = "0"
auto_start = "0"

index = __COUNTER__
#endif

[[module.entry]]
name = "BASEFW"
uuid = "0E398C32-5ADE-BA4B-93B1-C50432280EE4"
Expand Down
14 changes: 14 additions & 0 deletions tools/rimage/config/ptl.toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ auto_start = "0"

index = __COUNTER__

#if CONFIG_COLD_STORE_EXECUTE_DRAM
[[module.entry]]
name = "COLD"
uuid = "D406D134-C3C1-402C-8AEC-6821C0C2B0E6"
affinity_mask = "3"
instance_count = "1"
domain_types = "0"
load_type = "0"
module_type = "0"
auto_start = "0"

index = __COUNTER__
#endif

[[module.entry]]
name = "BASEFW"
uuid = "0E398C32-5ADE-BA4B-93B1-C50432280EE4"
Expand Down
8 changes: 8 additions & 0 deletions xtos/include/sof/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@

#include <platform/lib/memory.h>

#ifndef __cold
#define __cold
#endif

#ifndef __cold_rodata
#define __cold_rodata
#endif

#endif /* __SOF_LIB_MEMORY_H__ */
8 changes: 8 additions & 0 deletions zephyr/include/sof/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@

#include <platform/lib/memory.h>

#ifndef __cold
#define __cold
#endif

#ifndef __cold_rodata
#define __cold_rodata
#endif

#endif /* __SOF_LIB_MEMORY_H__ */
Loading