Commit ec9025e5 authored by Kai Vehmanen's avatar Kai Vehmanen Committed by Mark Brown

ASoC: SOF: force end-of-file for debugfs trace at suspend

Current trace implementation gets out of sync when sof device
is put to suspend. The debugfs file handle is kept open, but
firmware will reset its state. After resume, debugfs client's
read offset will not be synchronized to firmware and this may
result in traces read in incorrect order and/or stale data being
read after resume.

Add logic to signal end-of-file to read() when firmware tracing
has ended, and all trace data has been read. This allows debugfs
client to capture all trace data, and reopen the trace file to
ensure proper synchronization with firmware after reopening
the node.
Signed-off-by: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent f627b052
...@@ -417,6 +417,8 @@ struct snd_sof_dev { ...@@ -417,6 +417,8 @@ struct snd_sof_dev {
u32 host_offset; u32 host_offset;
u32 dtrace_is_enabled; u32 dtrace_is_enabled;
u32 dtrace_error; u32 dtrace_error;
u32 dtrace_draining;
u32 msi_enabled; u32 msi_enabled;
void *private; /* core does not touch this */ void *private; /* core does not touch this */
......
...@@ -43,6 +43,15 @@ static size_t sof_wait_trace_avail(struct snd_sof_dev *sdev, ...@@ -43,6 +43,15 @@ static size_t sof_wait_trace_avail(struct snd_sof_dev *sdev,
if (ret) if (ret)
return ret; return ret;
if (!sdev->dtrace_is_enabled && sdev->dtrace_draining) {
/*
* tracing has ended and all traces have been
* read by client, return EOF
*/
sdev->dtrace_draining = false;
return 0;
}
/* wait for available trace data from FW */ /* wait for available trace data from FW */
init_waitqueue_entry(&wait, current); init_waitqueue_entry(&wait, current);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
...@@ -104,10 +113,23 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer, ...@@ -104,10 +113,23 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer,
return count; return count;
} }
static int sof_dfsentry_trace_release(struct inode *inode, struct file *file)
{
struct snd_sof_dfsentry *dfse = inode->i_private;
struct snd_sof_dev *sdev = dfse->sdev;
/* avoid duplicate traces at next open */
if (!sdev->dtrace_is_enabled)
sdev->host_offset = 0;
return 0;
}
static const struct file_operations sof_dfs_trace_fops = { static const struct file_operations sof_dfs_trace_fops = {
.open = simple_open, .open = simple_open,
.read = sof_dfsentry_trace_read, .read = sof_dfsentry_trace_read,
.llseek = default_llseek, .llseek = default_llseek,
.release = sof_dfsentry_trace_release,
}; };
static int trace_debugfs_create(struct snd_sof_dev *sdev) static int trace_debugfs_create(struct snd_sof_dev *sdev)
...@@ -155,6 +177,7 @@ int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev) ...@@ -155,6 +177,7 @@ int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev)
params.stream_tag = 0; params.stream_tag = 0;
sdev->host_offset = 0; sdev->host_offset = 0;
sdev->dtrace_draining = false;
ret = snd_sof_dma_trace_init(sdev, &params.stream_tag); ret = snd_sof_dma_trace_init(sdev, &params.stream_tag);
if (ret < 0) { if (ret < 0) {
...@@ -291,6 +314,8 @@ void snd_sof_release_trace(struct snd_sof_dev *sdev) ...@@ -291,6 +314,8 @@ void snd_sof_release_trace(struct snd_sof_dev *sdev)
"error: fail in snd_sof_dma_trace_release %d\n", ret); "error: fail in snd_sof_dma_trace_release %d\n", ret);
sdev->dtrace_is_enabled = false; sdev->dtrace_is_enabled = false;
sdev->dtrace_draining = true;
wake_up(&sdev->trace_sleep);
} }
EXPORT_SYMBOL(snd_sof_release_trace); EXPORT_SYMBOL(snd_sof_release_trace);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment