Skip to content

Commit e3ec7cf

Browse files
committed
ASoC: SOF: trace: move to opt-in with Kconfig and module parameter
In a number of debug cases, the DMA-based trace can add problems (e.g. with HDaudio channel allocation). It also generates additional traffic on the bus and if the DMA handling is unreliable will prevent audio use-cases from working normally. Using the trace also requires tools to be installed on the target. The trace can be instead handled as dynamic debug. We can use a Kconfig to force the trace to be enabled in all cases, or use a module parameter to enable it on a need-basis, e.g. by setting "options snd_sof sof_debug=0x1" in a /etc/modprobe.d file. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent 901cd2a commit e3ec7cf

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

sound/soc/sof/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ config SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE
128128
Say Y if you want to enable caching the memory windows.
129129
If unsure, select "N".
130130

131+
config SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE
132+
bool "SOF enable firmware trace"
133+
help
134+
The firmware trace can be enabled either at build-time with
135+
this option, or dynamically by setting flags in the SOF core
136+
module parameter (similar to dynamic debug)
137+
If unsure, select "N".
138+
131139
endif ## SND_SOC_SOF_DEBUG
132140

133141
endif ## SND_SOC_SOF_OPTIONS

sound/soc/sof/core.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#include "sof-priv.h"
1717
#include "ops.h"
1818

19+
static int sof_core_debug;
20+
module_param_named(sof_debug, sof_core_debug, int, 0444);
21+
MODULE_PARM_DESC(sof_debug, "SOF core debug options (0x0 all off)");
22+
23+
#define SOF_CORE_ENABLE_TRACE BIT(0)
24+
1925
/* SOF defaults if not provided by the platform in ms */
2026
#define TIMEOUT_DEFAULT_IPC_MS 5
2127
#define TIMEOUT_DEFAULT_BOOT_MS 100
@@ -350,12 +356,20 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
350356
goto fw_run_err;
351357
}
352358

353-
/* init DMA trace */
354-
ret = snd_sof_init_trace(sdev);
355-
if (ret < 0) {
356-
/* non fatal */
357-
dev_warn(sdev->dev,
358-
"warning: failed to initialize trace %d\n", ret);
359+
if (IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE) ||
360+
(sof_core_debug & SOF_CORE_ENABLE_TRACE)) {
361+
sdev->dtrace_is_supported = true;
362+
363+
/* init DMA trace */
364+
ret = snd_sof_init_trace(sdev);
365+
if (ret < 0) {
366+
/* non fatal */
367+
dev_warn(sdev->dev,
368+
"warning: failed to initialize trace %d\n",
369+
ret);
370+
}
371+
} else {
372+
dev_dbg(sdev->dev, "SOF firmware trace disabled\n");
359373
}
360374

361375
/* hereafter all FW boot flows are for PM reasons */

sound/soc/sof/sof-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ struct snd_sof_dev {
415415
int dma_trace_pages;
416416
wait_queue_head_t trace_sleep;
417417
u32 host_offset;
418+
u32 dtrace_is_supported; /* set with Kconfig or module parameter */
418419
u32 dtrace_is_enabled;
419420
u32 dtrace_error;
420421
u32 dtrace_draining;

sound/soc/sof/trace.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev)
167167
struct sof_ipc_reply ipc_reply;
168168
int ret;
169169

170+
if (!sdev->dtrace_is_supported)
171+
return 0;
172+
170173
if (sdev->dtrace_is_enabled || !sdev->dma_trace_pages)
171174
return -EINVAL;
172175

@@ -227,6 +230,9 @@ int snd_sof_init_trace(struct snd_sof_dev *sdev)
227230
{
228231
int ret;
229232

233+
if (!sdev->dtrace_is_supported)
234+
return 0;
235+
230236
/* set false before start initialization */
231237
sdev->dtrace_is_enabled = false;
232238

@@ -282,6 +288,9 @@ EXPORT_SYMBOL(snd_sof_init_trace);
282288
int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
283289
struct sof_ipc_dma_trace_posn *posn)
284290
{
291+
if (!sdev->dtrace_is_supported)
292+
return 0;
293+
285294
if (sdev->dtrace_is_enabled && sdev->host_offset != posn->host_offset) {
286295
sdev->host_offset = posn->host_offset;
287296
wake_up(&sdev->trace_sleep);
@@ -298,6 +307,9 @@ int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
298307
/* an error has occurred within the DSP that prevents further trace */
299308
void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev)
300309
{
310+
if (!sdev->dtrace_is_supported)
311+
return;
312+
301313
if (sdev->dtrace_is_enabled) {
302314
dev_err(sdev->dev, "error: waking up any trace sleepers\n");
303315
sdev->dtrace_error = true;
@@ -310,7 +322,7 @@ void snd_sof_release_trace(struct snd_sof_dev *sdev)
310322
{
311323
int ret;
312324

313-
if (!sdev->dtrace_is_enabled)
325+
if (!sdev->dtrace_is_supported || !sdev->dtrace_is_enabled)
314326
return;
315327

316328
ret = snd_sof_dma_trace_trigger(sdev, SNDRV_PCM_TRIGGER_STOP);
@@ -331,6 +343,9 @@ EXPORT_SYMBOL(snd_sof_release_trace);
331343

332344
void snd_sof_free_trace(struct snd_sof_dev *sdev)
333345
{
346+
if (!sdev->dtrace_is_supported)
347+
return;
348+
334349
snd_sof_release_trace(sdev);
335350

336351
snd_dma_free_pages(&sdev->dmatb);

0 commit comments

Comments
 (0)