Skip to content
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 app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ CONFIG_SCHED_DEADLINE=y
CONFIG_SCHED_CPU_MASK=y
CONFIG_SMP_BOOT_DELAY=y

# SOF code assumes system work queue and other system
# wide threads are pinned to a single core.
# CPU_MASK_PIN_ONLY must be set for all SOF builds.
CONFIG_SCHED_CPU_MASK_PIN_ONLY=y

# Fix the sys ticks value until following bugs are solved:
# - https://github.com/zephyrproject-rtos/zephyr/issues/46378
CONFIG_SYS_CLOCK_TICKS_PER_SEC=15000
Expand Down
4 changes: 4 additions & 0 deletions src/include/sof/ipc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ struct ipc {
/* processing task */
struct task ipc_task;

#ifdef __ZEPHYR__
struct k_work_delayable z_delayed_work;
#endif

void *private;
};

Expand Down
39 changes: 39 additions & 0 deletions src/ipc/ipc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ void ipc_send_queued_msg(void)

key = k_spin_lock(&ipc->lock);

if (ipc_get()->pm_prepare_D3)
goto out;

/* any messages to send ? */
if (list_is_empty(&ipc->msg_list))
goto out;
Expand All @@ -182,6 +185,19 @@ void ipc_send_queued_msg(void)
k_spin_unlock(&ipc->lock, key);
}

static void schedule_ipc_worker(void)
{
/*
* note: in XTOS builds, this is handled in
* task_main_primary_core()
*/
#ifdef __ZEPHYR__
struct ipc *ipc = ipc_get();

k_work_schedule(&ipc->z_delayed_work, K_USEC(IPC_PERIOD_USEC));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so you'd retry every 100us?.. I think previously IPC_PERIOD_USEC was actually unused - it was "used" as a task period for the IPC task, but the IPC task was an EDF task, and the EDF scheduler ignores period...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@lyakh yes. this is fairly reasonable as we are mostly waiting for the kernel side to ACK the previous message and this should be very fast. OTOH, we could also trigger resend from the IPC driver and use a much slower timer to handle any lingering cases (maybe just to log an error). I can see from history that there was something like this in the old times, but Keyon removed it. Downside is that this needs to be added to all IPC drivers, while this logic is common for all.

#endif
}

void ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
{
struct ipc *ipc = ipc_get();
Expand Down Expand Up @@ -212,10 +228,29 @@ void ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
list_item_append(&msg->list, &ipc->msg_list);
}

schedule_ipc_worker();

out:
k_spin_unlock(&ipc->lock, key);
}

#ifdef __ZEPHYR__
static void ipc_work_handler(struct k_work *work)
{
struct ipc *ipc = ipc_get();
k_spinlock_key_t key;

ipc_send_queued_msg();

key = k_spin_lock(&ipc->lock);

if (!list_is_empty(&ipc->msg_list) && !ipc->pm_prepare_D3)
schedule_ipc_worker();

k_spin_unlock(&ipc->lock, key);
}
#endif

void ipc_schedule_process(struct ipc *ipc)
{
schedule_task(&ipc->ipc_task, 0, IPC_PERIOD_USEC);
Expand All @@ -234,6 +269,10 @@ int ipc_init(struct sof *sof)
list_init(&sof->ipc->msg_list);
list_init(&sof->ipc->comp_list);

#ifdef __ZEPHYR__
k_work_init_delayable(&sof->ipc->z_delayed_work, ipc_work_handler);
#endif

return platform_ipc_init(sof->ipc);
}

Expand Down
14 changes: 0 additions & 14 deletions zephyr/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,6 @@ unsigned int _xtos_ints_off(unsigned int mask)
return 0;
}

void ipc_send_queued_msg(void);

static void ipc_send_queued_callback(void *private_data, enum notify_id event_type,
void *caller_data)
{
if (!ipc_get()->pm_prepare_D3)
ipc_send_queued_msg();
}

/*
* Audio components.
*
Expand Down Expand Up @@ -651,11 +642,6 @@ int task_main_start(struct sof *sof)
__ASSERT_NO_MSG(cpu_get_id() == PLATFORM_PRIMARY_CORE_ID);
w_core_enable_mask |= BIT(PLATFORM_PRIMARY_CORE_ID);

/* Temporary fix for issue #4356 */
(void)notifier_register(NULL, scheduler_get_data(SOF_IPC_QUEUED_DOMAIN),
NOTIFIER_ID_LL_POST_RUN,
ipc_send_queued_callback, 0);

/* let host know DSP boot is complete */
ret = platform_boot_complete(0);

Expand Down