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
34 changes: 34 additions & 0 deletions src/ipc/ipc4/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,11 +1003,44 @@ void ipc_boot_complete_msg(struct ipc_cmd_hdr *header, uint32_t data)
}

#ifdef CONFIG_LOG_BACKEND_ADSP_MTRACE

static bool is_notification_queued(void)
{
struct ipc *ipc = ipc_get();
struct list_item *slist;
struct ipc_msg *msg;
k_spinlock_key_t key;
bool queued = false;

key = k_spin_lock(&ipc->lock);
if (list_is_empty(&ipc->msg_list))
goto out;

list_for_item(slist, &ipc->msg_list) {
msg = container_of(slist, struct ipc_msg, list);

if (msg == &msg_notify) {
Comment thread
lgirdwood marked this conversation as resolved.
Resolved
queued = true;
break;
}
}

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

return queued;
}

void ipc_send_buffer_status_notify(void)
{
/* a single msg_notify object is used */
if (is_notification_queued())
return;

msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS);
msg_notify.extension = 0;
msg_notify.tx_size = 0;
list_init(&msg_notify.list);

tr_dbg(&ipc_tr, "tx-notify\t: %#x|%#x", msg_notify.header, msg_notify.extension);

Expand Down Expand Up @@ -1040,6 +1073,7 @@ void ipc_cmd(struct ipc_cmd_hdr *_hdr)
msg_reply.tx_size = 0;
msg_reply.header = in->primary.dat;
msg_reply.extension = in->extension.dat;
list_init(&msg_reply.list);

target = in->primary.r.msg_tgt;

Expand Down
39 changes: 26 additions & 13 deletions src/ipc/ipc4/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ LOG_MODULE_REGISTER(mtrace, CONFIG_SOF_LOG_LEVEL);
*/
#define IPC4_MTRACE_AGING_TIMER_MIN_MS 100

/**
* Shortest time between IPC notifications sent to host. This
* is used as protection against a flood of log messages.
*/
#define IPC4_MTRACE_NOTIFY_MIN_DELTA_MS 10

/* bb2aa22e-1ab6-4650-8501-6e67fcc04f4e */
DECLARE_SOF_UUID("mtrace-task", mtrace_task_uuid, 0xbb2aa22e, 0x1ab6, 0x4650,
0x85, 0x01, 0x6e, 0x67, 0xfc, 0xc0, 0x4f, 0x4e);
Expand All @@ -59,27 +65,34 @@ struct task mtrace_task;

static void mtrace_log_hook(size_t written, size_t space_left)
{
if (arch_proc_id() == MTRACE_IPC_CORE &&
(space_left < NOTIFY_BUFFER_STATUS_THRESHOLD ||
k_uptime_delta(&mtrace_notify_last_sent) >= mtrace_aging_timer)) {
uint64_t delta;

mtrace_bytes_pending += written;

/* TODO: if hook is called on non-zero core, logs
* maybe lost with too slow aging timer. need to
* figure out a safe way to wake up the mtrace task
* from another core.
*/
if (arch_proc_id() != MTRACE_IPC_CORE)
return;

delta = k_uptime_get() - mtrace_notify_last_sent;

if (delta < IPC4_MTRACE_NOTIFY_MIN_DELTA_MS)
return;

if (space_left < NOTIFY_BUFFER_STATUS_THRESHOLD ||
delta >= mtrace_aging_timer) {
ipc_send_buffer_status_notify();
mtrace_notify_last_sent = k_uptime_get();
mtrace_bytes_pending = 0;

} else {
mtrace_bytes_pending += written;

/* TODO: if hook is called on non-zero core, logs
* maybe lost with too slow aging timer. need to
* figure out a safe way to wake up the mtrace task
* from another core.
*/
}
}

static enum task_state mtrace_task_run(void *data)
{
if (k_uptime_delta(&mtrace_notify_last_sent) >= mtrace_aging_timer &&
if (k_uptime_get() - mtrace_notify_last_sent >= mtrace_aging_timer &&
mtrace_bytes_pending)
mtrace_log_hook(0, 0);

Expand Down