Skip to content

Comments

ipc4: add counter to mtrace buffer status notification#10564

Open
ujfalusi wants to merge 1 commit intothesofproject:mainfrom
ujfalusi:peter/pr/mtrace-counter
Open

ipc4: add counter to mtrace buffer status notification#10564
ujfalusi wants to merge 1 commit intothesofproject:mainfrom
ujfalusi:peter/pr/mtrace-counter

Conversation

@ujfalusi
Copy link
Contributor

Increment a dedicated counter on each
SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS notification and place the current value in the IPC extension field, so the host side can distinguish consecutive mtrace notifications.

Increment a dedicated counter on each
SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS notification and place the
current value in the IPC extension field, so the host side
can distinguish consecutive mtrace notifications.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a counter mechanism to mtrace buffer status notifications to help the host distinguish between consecutive notifications. Each time a SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS notification is sent, a counter is incremented and its value is placed in the IPC extension field.

Changes:

  • Introduced an atomic counter for tracking mtrace notifications
  • Modified notification logic to increment and include counter value in extension field

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


#ifdef CONFIG_LOG_BACKEND_ADSP_MTRACE

static atomic_t mtrace_notify_counter;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The atomic counter should be initialized explicitly to ensure a known starting state. Consider using ATOMIC_INIT(0) or an initialization function to set the initial value to 0.

Suggested change
static atomic_t mtrace_notify_counter;
static atomic_t mtrace_notify_counter = ATOMIC_INIT(0);

Copilot uses AI. Check for mistakes.
Comment on lines +1668 to +1669
atomic_add(&mtrace_notify_counter, 1);
msg_notify.extension = atomic_read(&mtrace_notify_counter);
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

Using separate atomic_add() and atomic_read() operations creates a potential race condition. Between these two operations, another thread could modify the counter, causing the extension field to contain a different value than what was incremented. Use atomic_inc_return() or atomic_fetch_add() instead to atomically increment and read the value in a single operation.

Suggested change
atomic_add(&mtrace_notify_counter, 1);
msg_notify.extension = atomic_read(&mtrace_notify_counter);
msg_notify.extension = atomic_inc_return(&mtrace_notify_counter);

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

ack atomic_add() will return the current value which we should use in the extension.

Comment on lines +1668 to +1669
atomic_add(&mtrace_notify_counter, 1);
msg_notify.extension = atomic_read(&mtrace_notify_counter);
Copy link
Member

Choose a reason for hiding this comment

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

ack atomic_add() will return the current value which we should use in the extension.

Copy link
Contributor

@tmleman tmleman left a comment

Choose a reason for hiding this comment

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

Blocking until doubts are clarified.

Comment on lines 1667 to +1669
msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS);
msg_notify.extension = 0;
atomic_add(&mtrace_notify_counter, 1);
msg_notify.extension = atomic_read(&mtrace_notify_counter);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the host need this? Has there been a situation where it received the same notification more than once?
I checked the documentation and there is no such iterator in this message. I think in the case of all notifications the extension field remains empty.

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