Skip to content

Commit 4c09f20

Browse files
committed
ASoC: SOF: ipc4-mtrace: resync host_read_ptr on debugfs open and release
IPC4 mtrace debugfs read handler advances host_read_ptr in SRAM after consuming all available data. When file descriptor is closed, host_read_ptr is left equal to dsp_write_ptr in kernel core_data cache. So subsequent open() inherits this stale pointer. first read() call, sof_wait_mtrace_avail() find host_read_ptr == dsp_write_ptr and block waiting for NOTIFY_LOG_BUFFER_STATUS IPC from fw. Platforms with low post-boot DSP activity timer (256 ms) may not work good with reader timeout window, resulting in empty trace output. Fix this by re-reading dsp_write_ptr directly from SRAM in open() and aligning host_read_ptr to it, so new reader starts from current write position without waiting for IPC notification. Also reset host_read_ptr to dsp_write_ptr in release() to leave core_data to consistent state. Reset target is dsp_write_ptr (not 0) to avoid re-reading stale data that may remain before last wrap of circular buffer. Signed-off-by: Mateusz Junkier <mateusz.junkier@intel.com>
1 parent 667770d commit 4c09f20

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sound/soc/sof/ipc4-mtrace.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ static int sof_ipc4_mtrace_dfs_open(struct inode *inode, struct file *file)
109109
return -ENOMEM;
110110
}
111111

112+
/*
113+
* Re-sync dsp_write_ptr from SRAM and align host_read_ptr to it so
114+
* this reader starts from current write position and only sees
115+
* data written after this open(). Without this prior reader (e.g.
116+
* one-shot dd) may have advanced host_read_ptr to equal
117+
* dsp_write_ptr, causing next reader to block indefinitely on
118+
* platforms with low DSP activity.Resetting to current dsp_write_ptr
119+
* (not to 0) avoids re-reading stale data from wrapped circular buffer.
120+
*/
121+
if (core_data->slot_offset != SOF_IPC4_INVALID_SLOT_OFFSET) {
122+
struct snd_sof_dev *sdev = core_data->sdev;
123+
u32 write_ptr;
124+
125+
sof_mailbox_read(sdev, core_data->slot_offset + sizeof(u32),
126+
&write_ptr, sizeof(write_ptr));
127+
write_ptr -= write_ptr % 4;
128+
core_data->dsp_write_ptr = write_ptr;
129+
core_data->host_read_ptr = write_ptr;
130+
}
131+
112132
ret = simple_open(inode, file);
113133
if (ret) {
114134
kfree(core_data->log_buffer);
@@ -254,6 +274,14 @@ static int sof_ipc4_mtrace_dfs_release(struct inode *inode, struct file *file)
254274
scoped_guard(mutex, &core_data->buffer_lock) {
255275
kfree(core_data->log_buffer);
256276
core_data->log_buffer = NULL;
277+
/*
278+
* Align host_read_ptr to current dsp_write_ptr so that
279+
* subsequent open() starts from fresh data and isnt
280+
* blocked by stale pointer left by this reader. Using
281+
* dsp_write_ptr (not 0) avoids re-reading stale data from
282+
* wrapped circular buffer.
283+
*/
284+
core_data->host_read_ptr = core_data->dsp_write_ptr;
257285
}
258286

259287
return 0;

0 commit comments

Comments
 (0)