Skip to content

Commit

Permalink
ipc: move most functions to run from DRAM
Browse files Browse the repository at this point in the history
Mark most IPC functions as "cold" to run them directly in DRAM.
Explicitly avoid making exported functions "cold," also those that
are either known to or can potentially be called from hot code paths.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh committed Mar 4, 2025
1 parent c7f6a7a commit 1726dae
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 78 deletions.
2 changes: 0 additions & 2 deletions src/include/sof/ipc/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ typedef uint32_t ipc_comp;
struct ipc_comp_dev;
const struct comp_driver *ipc4_get_comp_drv(uint32_t module_id);
struct comp_dev *ipc4_get_comp_dev(uint32_t comp_id);
int ipc4_add_comp_dev(struct comp_dev *dev);
const struct comp_driver *ipc4_get_drv(const void *uuid);
int ipc4_chain_manager_create(struct ipc4_chain_dma *cdma);
int ipc4_chain_dma_state(struct comp_dev *dev, struct ipc4_chain_dma *cdma);
int ipc4_create_chain_dma(struct ipc *ipc, struct ipc4_chain_dma *cdma);
Expand Down
17 changes: 9 additions & 8 deletions src/ipc/ipc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <rtos/cache.h>
#include <sof/lib/cpu.h>
#include <sof/lib/mailbox.h>
#include <sof/lib/memory.h>
#include <sof/list.h>
#include <sof/platform.h>
#include <rtos/sof.h>
Expand Down Expand Up @@ -140,7 +141,7 @@ struct ipc_comp_dev *ipc_get_ppl_comp(struct ipc *ipc, uint32_t pipeline_id, int
return next_ppl_icd;
}

void ipc_send_queued_msg(void)
__cold void ipc_send_queued_msg(void)
{
struct ipc *ipc = ipc_get();
struct ipc_msg *msg;
Expand Down Expand Up @@ -175,7 +176,7 @@ static struct k_work_q ipc_send_wq;
static K_THREAD_STACK_DEFINE(ipc_send_wq_stack, CONFIG_STACK_SIZE_IPC_TX);
#endif

static void schedule_ipc_worker(void)
__cold static void schedule_ipc_worker(void)
{
/*
* note: in XTOS builds, this is handled in
Expand All @@ -188,7 +189,7 @@ static void schedule_ipc_worker(void)
#endif
}

void ipc_msg_send_direct(struct ipc_msg *msg, void *data)
__cold void ipc_msg_send_direct(struct ipc_msg *msg, void *data)
{
struct ipc *ipc = ipc_get();
k_spinlock_key_t key;
Expand Down Expand Up @@ -255,7 +256,7 @@ void ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
EXPORT_SYMBOL(ipc_msg_send);

#ifdef __ZEPHYR__
static void ipc_work_handler(struct k_work *work)
__cold static void ipc_work_handler(struct k_work *work)
{
struct ipc *ipc = ipc_get();
k_spinlock_key_t key;
Expand All @@ -276,7 +277,7 @@ void ipc_schedule_process(struct ipc *ipc)
schedule_task(&ipc->ipc_task, 0, IPC_PERIOD_USEC);
}

int ipc_init(struct sof *sof)
__cold int ipc_init(struct sof *sof)
{
tr_dbg(&ipc_tr, "ipc_init()");

Expand Down Expand Up @@ -323,7 +324,7 @@ int ipc_init(struct sof *sof)
}

/* Locking: call with ipc->lock held and interrupts disabled */
void ipc_complete_cmd(struct ipc *ipc)
__cold void ipc_complete_cmd(struct ipc *ipc)
{
/*
* We have up to three contexts, attempting to complete IPC processing:
Expand All @@ -343,7 +344,7 @@ void ipc_complete_cmd(struct ipc *ipc)
ipc_platform_complete_cmd(ipc);
}

static void ipc_complete_task(void *data)
__cold static void ipc_complete_task(void *data)
{
struct ipc *ipc = data;
k_spinlock_key_t key;
Expand All @@ -354,7 +355,7 @@ static void ipc_complete_task(void *data)
k_spin_unlock(&ipc->lock, key);
}

static enum task_state ipc_do_cmd(void *data)
__cold static enum task_state ipc_do_cmd(void *data)
{
struct ipc *ipc = data;

Expand Down
25 changes: 13 additions & 12 deletions src/ipc/ipc-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <rtos/cache.h>
#include <sof/lib/cpu.h>
#include <sof/lib/mailbox.h>
#include <sof/lib/memory.h>
#include <sof/list.h>
#include <sof/platform.h>
#include <rtos/sof.h>
Expand All @@ -37,7 +38,7 @@

LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);

static bool valid_ipc_buffer_desc(const struct sof_ipc_buffer *desc)
__cold static bool valid_ipc_buffer_desc(const struct sof_ipc_buffer *desc)
{
if (desc->caps >= SOF_MEM_CAPS_LOWEST_INVALID)
return false;
Expand All @@ -47,7 +48,7 @@ static bool valid_ipc_buffer_desc(const struct sof_ipc_buffer *desc)
}

/* create a new component in the pipeline */
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared)
__cold struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared)
{
struct comp_buffer *buffer;

Expand Down Expand Up @@ -75,7 +76,7 @@ struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared
return buffer;
}

int32_t ipc_comp_pipe_id(const struct ipc_comp_dev *icd)
__cold int32_t ipc_comp_pipe_id(const struct ipc_comp_dev *icd)
{
switch (icd->type) {
case COMP_TYPE_COMPONENT:
Expand All @@ -95,9 +96,9 @@ int32_t ipc_comp_pipe_id(const struct ipc_comp_dev *icd)
/* Function overwrites PCM parameters (frame_fmt, buffer_fmt, channels, rate)
* with buffer parameters when specific flag is set.
*/
static void comp_update_params(uint32_t flag,
struct sof_ipc_stream_params *params,
struct comp_buffer *buffer)
__cold static void comp_update_params(uint32_t flag,
struct sof_ipc_stream_params *params,
struct comp_buffer *buffer)
{
if (flag & BUFF_PARAMS_FRAME_FMT)
params->frame_fmt = audio_stream_get_frm_fmt(&buffer->stream);
Expand All @@ -112,8 +113,8 @@ static void comp_update_params(uint32_t flag,
params->rate = audio_stream_get_rate(&buffer->stream);
}

int comp_verify_params(struct comp_dev *dev, uint32_t flag,
struct sof_ipc_stream_params *params)
__cold int comp_verify_params(struct comp_dev *dev, uint32_t flag,
struct sof_ipc_stream_params *params)
{
struct list_item *buffer_list;
struct list_item *source_list;
Expand Down Expand Up @@ -179,8 +180,8 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,
}
EXPORT_SYMBOL(comp_verify_params);

int comp_buffer_connect(struct comp_dev *comp, uint32_t comp_core,
struct comp_buffer *buffer, uint32_t dir)
__cold int comp_buffer_connect(struct comp_dev *comp, uint32_t comp_core,
struct comp_buffer *buffer, uint32_t dir)
{
/* check if it's a connection between cores */
if (buffer->core != comp_core) {
Expand All @@ -197,7 +198,7 @@ int comp_buffer_connect(struct comp_dev *comp, uint32_t comp_core,
return pipeline_connect(comp, buffer, dir);
}

int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id)
__cold int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id)
{
struct ipc_comp_dev *ipc_pipe;
struct ipc_comp_dev *icd;
Expand Down Expand Up @@ -260,7 +261,7 @@ int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id)
ipc_ppl_sink->cd);
}

int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
__cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
{
struct ipc_comp_dev *icd;
struct list_item *clist, *tmp;
Expand Down
Loading

0 comments on commit 1726dae

Please sign in to comment.