Skip to content

ASoC: SOF: trace: sdev->host_offset management changes - #3516

Merged
plbossart merged 2 commits into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/dtrace_print_offsets_01
May 20, 2022
Merged

ASoC: SOF: trace: sdev->host_offset management changes#3516
plbossart merged 2 commits into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/dtrace_print_offsets_01

Conversation

@ujfalusi

Copy link
Copy Markdown
Collaborator

Hi,

The READ_ONCE(sdev->host_offset) alone does nothing to prevent any race regarding to host_offset change race prevention.
Introduce a new helper to do this in a correct way and while at it, print out the new offset for us to see where we are.

Additional debug prints can be added to track what is copied to user space with a simple change:

diff--gita/sound/soc/sof/trace.cb/sound/soc/sof/trace.cindex76c763da5804..32c3c0d8a75e100644---a/sound/soc/sof/trace.c+++b/sound/soc/sof/trace.c
@@ -334,8+334,10 @@ staticssize_tsof_dfsentry_trace_read(structfile*file, char__user*buffer,
}
/* no new trace data */-if (!avail)
+if (!avail) {
+dev_dbg(sdev->dev, "trace: nothing to copy\n");
return0;
+	}
/* make sure count is <= avail */if (count>avail)
@@ -349,6+351,8 @@ staticssize_tsof_dfsentry_trace_read(structfile*file, char__user*buffer,
*/
snd_dma_buffer_sync(&sdev->dmatb, SNDRV_DMA_SYNC_CPU);
/* copy available trace data to debugfs */+dev_dbg(sdev->dev, "trace: copy to user from offset : %#llx, count: %#zx\n",
+lpos, count);
rem=copy_to_user(buffer, ((u8*)(dfse->buf) +lpos), count);
if (rem)
return-EFAULT;

Comment threadsound/soc/sof/trace.c Outdated

if (ret == host_offset)
if (ret == host_offset) {
dev_dbg(sdev->dev, "trace: new host_offset: %#x\n", new_offset);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isn't this super-verbose? I wonder if this is going to fill the console with too many logs.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

If the debug is enabled we are printing the IPC messages (two per message). With this change it will look like this:

ipc rx: 0x90020000: GLB_TRACE_MSG: DMA_POSITION
trace: new host_offset: 0x7920
ipc rx done: 0x90020000: GLB_TRACE_MSG: DMA_POSITION

Instead of an empty indication that the position is updated we will know the value as well.
Then we have another print when the host_offset is reset to 0 (either because of closing the trace file or restart), but it is still one additional message.

It is not going to fill the console, but I always wondered what is the content behind the dtrace position update.

I can drop this print if you think we should not have it.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I will create a draft PR on top of this to print the trace file reads as well in hope that we can catch the empty trace with that and have some clue on what is going on.

@ujfalusi
ujfalusiforce-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 07ccf0d to 6651821CompareApril 5, 2022 08:02
@ujfalusi
ujfalusiforce-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 6651821 to 508e431CompareApril 5, 2022 08:55
@ujfalusi

Copy link
Copy Markdown
CollaboratorAuthor

Changes since v1:

  • Rebased on sof-dev (ipc3-dtrace introduction)

bardliao
bardliao previously approved these changes Apr 6, 2022
@ujfalusi
ujfalusiforce-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 508e431 to 75096dbCompareMay 4, 2022 07:01
@ujfalusi

Copy link
Copy Markdown
CollaboratorAuthor

Changes since v2:

  • rebased on topic/sof-dev

}

acpi_handle_info(handle, "Found %d idle states\n", last_index);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we remove this? I don't know what problem this tries to fix.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

certainly, this is needed for one of my DUTs, otherwise the dmesg is flooded with this message for some reason and I keep forgetting to drop this when I'm done testing before sending the PR.

I should have a hook to blow up when I try to push this patch to other branch than my wip...

Comment threadsound/soc/sof/ipc3-dtrace.c Outdated

static bool sof_dtrace_set_host_offset(struct snd_sof_dev *sdev, u32 new_offset)
{
u32 host_offset = READ_ONCE(sdev->host_offset);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so this is going to conflict with your very own PR #3662 changes, specifically 024c2eb

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yes, I'm aware of that, they are of different topic and I don't want to mix them. I'm fine with fixing up either when the time comes.

@plbossart

Copy link
Copy Markdown
Member

@ujfalusi rebase needed.

@ujfalusi
ujfalusiforce-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 75096db to debd209CompareMay 10, 2022 11:51
@ujfalusi

Copy link
Copy Markdown
CollaboratorAuthor

Changes since v3:

plbossart
plbossart previously approved these changes May 10, 2022
@plbossart

Copy link
Copy Markdown
Member

Any other review? @dbaluta@bardliao@ranj063@marc-hb

bardliao
bardliao previously approved these changes May 19, 2022
@plbossart

Copy link
Copy Markdown
Member

@ujfalusi conflict?

@ujfalusi

Copy link
Copy Markdown
CollaboratorAuthor

@ujfalusi conflict?

Yes, I know, I'll update it tomorrow.

…offset
We are using the READ_ONCE() on the debugfs read path for accessing
sdev->host_offset, but the set is not atomic or protected in any way.
Add a small helper to do the host_offset update and be really paranoid
about the a possible race in update
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…ta available
If no new trace data is available then return immediately, there is no
need to continue with the execution of the trace_read() function.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi
ujfalusi dismissed stale reviews from bardliao and plbossart via 9c037afMay 19, 2022 18:57
@ujfalusi
ujfalusiforce-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from debd209 to 9c037afCompareMay 19, 2022 18:57
@ujfalusi

Copy link
Copy Markdown
CollaboratorAuthor

Changes since v4:

  • rebased on sof-dev to resolve conflict.

@plbossart
plbossart merged commit 8a9e909 into thesofproject:topic/sof-devMay 20, 2022
@ujfalusi
ujfalusi deleted the peter/sof/pr/dtrace_print_offsets_01 branch November 18, 2022 07:36
Sign up for freeto 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

@ujfalusi@plbossart@bardliao