Skip to content

Commit 9676d84

Browse files
ranj063kv2019i
authored andcommitted
ASoC: SOF: Convert the generic IPC flood test into SOF client
Move the IPC flood test code out from the debug file as separate SOF client driver. Based on the kernel configuration, the device registration for the new IPC flood test is going to happen in the core. With the separate client driver it is going to be possible to run multiple flood tests in parallel to increase the stress, the new Kconfig option can be used to select this (defaults to 1). In order to preserve backward compatibility with existing SW/scripts, the first IPC flood test's debugfs files have been linked to the old files. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Co-developed-by: Fred Oh <fred.oh@linux.intel.com> Signed-off-by: Fred Oh <fred.oh@linux.intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent de94efb commit 9676d84

7 files changed

Lines changed: 468 additions & 241 deletions

File tree

sound/soc/sof/Kconfig

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,23 @@ config SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE
194194
If unsure, select "N".
195195

196196
config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST
197-
bool "SOF enable IPC flood test"
197+
tristate "SOF enable IPC flood test"
198+
select SND_SOC_SOF_CLIENT
198199
help
199-
This option enables the IPC flood test which can be used to flood
200-
the DSP with test IPCs and gather stats about response times.
200+
This option enables a separate client device for IPC flood test
201+
which can be used to flood the DSP with test IPCs and gather stats
202+
about response times.
201203
Say Y if you want to enable IPC flood test.
202204
If unsure, select "N".
203205

206+
config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_NUM
207+
int "Number of IPC flood test clients"
208+
range 1 32
209+
default 2
210+
depends on SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST
211+
help
212+
Select the number of IPC flood test clients to be created.
213+
204214
config SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR
205215
bool "SOF enable IPC message injector"
206216
help

sound/soc/sof/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ snd-sof-pci-objs := sof-pci-dev.o
1111
snd-sof-acpi-objs := sof-acpi-dev.o
1212
snd-sof-of-objs := sof-of-dev.o
1313

14+
snd-sof-ipc-flood-test-objs := sof-client-ipc-flood-test.o
15+
1416
snd-sof-nocodec-objs := nocodec.o
1517

1618
snd-sof-utils-objs := sof-utils.o
@@ -24,6 +26,8 @@ obj-$(CONFIG_SND_SOC_SOF_ACPI_DEV) += snd-sof-acpi.o
2426
obj-$(CONFIG_SND_SOC_SOF_OF_DEV) += snd-sof-of.o
2527
obj-$(CONFIG_SND_SOC_SOF_PCI_DEV) += snd-sof-pci.o
2628

29+
obj-$(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST) += snd-sof-ipc-flood-test.o
30+
2731
obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
2832
obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
2933
obj-$(CONFIG_SND_SOC_SOF_AMD_TOPLEVEL) += amd/

sound/soc/sof/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,4 @@ MODULE_AUTHOR("Liam Girdwood");
484484
MODULE_DESCRIPTION("Sound Open Firmware (SOF) Core");
485485
MODULE_LICENSE("Dual BSD/GPL");
486486
MODULE_ALIAS("platform:sof-audio");
487+
MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);

sound/soc/sof/debug.c

Lines changed: 0 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -234,107 +234,6 @@ static int snd_sof_debugfs_probe_item(struct snd_sof_dev *sdev,
234234
}
235235
#endif
236236

237-
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)
238-
#define MAX_IPC_FLOOD_DURATION_MS 1000
239-
#define MAX_IPC_FLOOD_COUNT 10000
240-
#define IPC_FLOOD_TEST_RESULT_LEN 512
241-
242-
static int sof_debug_ipc_flood_test(struct snd_sof_dev *sdev,
243-
struct snd_sof_dfsentry *dfse,
244-
bool flood_duration_test,
245-
unsigned long ipc_duration_ms,
246-
unsigned long ipc_count)
247-
{
248-
struct sof_ipc_cmd_hdr hdr;
249-
struct sof_ipc_reply reply;
250-
u64 min_response_time = U64_MAX;
251-
ktime_t start, end, test_end;
252-
u64 avg_response_time = 0;
253-
u64 max_response_time = 0;
254-
u64 ipc_response_time;
255-
int i = 0;
256-
int ret;
257-
258-
/* configure test IPC */
259-
hdr.cmd = SOF_IPC_GLB_TEST_MSG | SOF_IPC_TEST_IPC_FLOOD;
260-
hdr.size = sizeof(hdr);
261-
262-
/* set test end time for duration flood test */
263-
if (flood_duration_test)
264-
test_end = ktime_get_ns() + ipc_duration_ms * NSEC_PER_MSEC;
265-
266-
/* send test IPC's */
267-
while (1) {
268-
start = ktime_get();
269-
ret = sof_ipc_tx_message(sdev->ipc, hdr.cmd, &hdr, hdr.size,
270-
&reply, sizeof(reply));
271-
end = ktime_get();
272-
273-
if (ret < 0)
274-
break;
275-
276-
/* compute min and max response times */
277-
ipc_response_time = ktime_to_ns(ktime_sub(end, start));
278-
min_response_time = min(min_response_time, ipc_response_time);
279-
max_response_time = max(max_response_time, ipc_response_time);
280-
281-
/* sum up response times */
282-
avg_response_time += ipc_response_time;
283-
i++;
284-
285-
/* test complete? */
286-
if (flood_duration_test) {
287-
if (ktime_to_ns(end) >= test_end)
288-
break;
289-
} else {
290-
if (i == ipc_count)
291-
break;
292-
}
293-
}
294-
295-
if (ret < 0)
296-
dev_err(sdev->dev,
297-
"error: ipc flood test failed at %d iterations\n", i);
298-
299-
/* return if the first IPC fails */
300-
if (!i)
301-
return ret;
302-
303-
/* compute average response time */
304-
do_div(avg_response_time, i);
305-
306-
/* clear previous test output */
307-
memset(dfse->cache_buf, 0, IPC_FLOOD_TEST_RESULT_LEN);
308-
309-
if (flood_duration_test) {
310-
dev_dbg(sdev->dev, "IPC Flood test duration: %lums\n",
311-
ipc_duration_ms);
312-
snprintf(dfse->cache_buf, IPC_FLOOD_TEST_RESULT_LEN,
313-
"IPC Flood test duration: %lums\n", ipc_duration_ms);
314-
}
315-
316-
dev_dbg(sdev->dev,
317-
"IPC Flood count: %d, Avg response time: %lluns\n",
318-
i, avg_response_time);
319-
dev_dbg(sdev->dev, "Max response time: %lluns\n",
320-
max_response_time);
321-
dev_dbg(sdev->dev, "Min response time: %lluns\n",
322-
min_response_time);
323-
324-
/* format output string */
325-
snprintf(dfse->cache_buf + strlen(dfse->cache_buf),
326-
IPC_FLOOD_TEST_RESULT_LEN - strlen(dfse->cache_buf),
327-
"IPC Flood count: %d\nAvg response time: %lluns\n",
328-
i, avg_response_time);
329-
330-
snprintf(dfse->cache_buf + strlen(dfse->cache_buf),
331-
IPC_FLOOD_TEST_RESULT_LEN - strlen(dfse->cache_buf),
332-
"Max response time: %lluns\nMin response time: %lluns\n",
333-
max_response_time, min_response_time);
334-
335-
return ret;
336-
}
337-
#endif
338237

339238
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR)
340239
static ssize_t msg_inject_read(struct file *file, char __user *buffer,
@@ -437,15 +336,6 @@ static int snd_sof_debugfs_msg_inject_item(struct snd_sof_dev *sdev,
437336
static ssize_t sof_dfsentry_write(struct file *file, const char __user *buffer,
438337
size_t count, loff_t *ppos)
439338
{
440-
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)
441-
struct snd_sof_dfsentry *dfse = file->private_data;
442-
struct snd_sof_dev *sdev = dfse->sdev;
443-
unsigned long ipc_duration_ms = 0;
444-
bool flood_duration_test = false;
445-
unsigned long ipc_count = 0;
446-
struct dentry *dentry;
447-
int err;
448-
#endif
449339
size_t size;
450340
char *string;
451341
int ret;
@@ -457,78 +347,6 @@ static ssize_t sof_dfsentry_write(struct file *file, const char __user *buffer,
457347
size = simple_write_to_buffer(string, count, ppos, buffer, count);
458348
ret = size;
459349

460-
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)
461-
/*
462-
* write op is only supported for ipc_flood_count or
463-
* ipc_flood_duration_ms debugfs entries atm.
464-
* ipc_flood_count floods the DSP with the number of IPC's specified.
465-
* ipc_duration_ms test floods the DSP for the time specified
466-
* in the debugfs entry.
467-
*/
468-
dentry = file->f_path.dentry;
469-
if (strcmp(dentry->d_name.name, "ipc_flood_count") &&
470-
strcmp(dentry->d_name.name, "ipc_flood_duration_ms")) {
471-
ret = -EINVAL;
472-
goto out;
473-
}
474-
475-
if (!strcmp(dentry->d_name.name, "ipc_flood_duration_ms"))
476-
flood_duration_test = true;
477-
478-
/* test completion criterion */
479-
if (flood_duration_test)
480-
ret = kstrtoul(string, 0, &ipc_duration_ms);
481-
else
482-
ret = kstrtoul(string, 0, &ipc_count);
483-
if (ret < 0)
484-
goto out;
485-
486-
/* limit max duration/ipc count for flood test */
487-
if (flood_duration_test) {
488-
if (!ipc_duration_ms) {
489-
ret = size;
490-
goto out;
491-
}
492-
493-
/* find the minimum. min() is not used to avoid warnings */
494-
if (ipc_duration_ms > MAX_IPC_FLOOD_DURATION_MS)
495-
ipc_duration_ms = MAX_IPC_FLOOD_DURATION_MS;
496-
} else {
497-
if (!ipc_count) {
498-
ret = size;
499-
goto out;
500-
}
501-
502-
/* find the minimum. min() is not used to avoid warnings */
503-
if (ipc_count > MAX_IPC_FLOOD_COUNT)
504-
ipc_count = MAX_IPC_FLOOD_COUNT;
505-
}
506-
507-
ret = pm_runtime_get_sync(sdev->dev);
508-
if (ret < 0 && ret != -EACCES) {
509-
dev_err_ratelimited(sdev->dev,
510-
"error: debugfs write failed to resume %d\n",
511-
ret);
512-
pm_runtime_put_noidle(sdev->dev);
513-
goto out;
514-
}
515-
516-
/* flood test */
517-
ret = sof_debug_ipc_flood_test(sdev, dfse, flood_duration_test,
518-
ipc_duration_ms, ipc_count);
519-
520-
pm_runtime_mark_last_busy(sdev->dev);
521-
err = pm_runtime_put_autosuspend(sdev->dev);
522-
if (err < 0)
523-
dev_err_ratelimited(sdev->dev,
524-
"error: debugfs write failed to idle %d\n",
525-
err);
526-
527-
/* return size if test is successful */
528-
if (ret >= 0)
529-
ret = size;
530-
out:
531-
#endif
532350
kfree(string);
533351
return ret;
534352
}
@@ -544,24 +362,6 @@ static ssize_t sof_dfsentry_read(struct file *file, char __user *buffer,
544362
int size;
545363
u8 *buf;
546364

547-
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)
548-
struct dentry *dentry;
549-
550-
dentry = file->f_path.dentry;
551-
if ((!strcmp(dentry->d_name.name, "ipc_flood_count") ||
552-
!strcmp(dentry->d_name.name, "ipc_flood_duration_ms"))) {
553-
if (*ppos)
554-
return 0;
555-
556-
count = strlen(dfse->cache_buf);
557-
size_ret = copy_to_user(buffer, dfse->cache_buf, count);
558-
if (size_ret)
559-
return -EFAULT;
560-
561-
*ppos += count;
562-
return count;
563-
}
564-
#endif
565365
size = dfse->size;
566366

567367
/* validate position & count */
@@ -719,19 +519,6 @@ int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
719519
dfse->size = size;
720520
dfse->sdev = sdev;
721521

722-
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)
723-
if (!strncmp(name, "ipc_flood", strlen("ipc_flood"))) {
724-
/*
725-
* cache_buf is unused for SOF_DFSENTRY_TYPE_BUF debugfs entries.
726-
* So, use it to save the results of the last IPC flood test.
727-
*/
728-
dfse->cache_buf = devm_kzalloc(sdev->dev, IPC_FLOOD_TEST_RESULT_LEN,
729-
GFP_KERNEL);
730-
if (!dfse->cache_buf)
731-
return -ENOMEM;
732-
}
733-
#endif
734-
735522
debugfs_create_file(name, mode, sdev->debugfs_root, dfse,
736523
&sof_dfs_fops);
737524
/* add to dfsentry list */
@@ -892,24 +679,6 @@ int snd_sof_dbg_init(struct snd_sof_dev *sdev)
892679
return err;
893680
#endif
894681

895-
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)
896-
/* create read-write ipc_flood_count debugfs entry */
897-
err = snd_sof_debugfs_buf_item(sdev, NULL, 0,
898-
"ipc_flood_count", 0666);
899-
900-
/* errors are only due to memory allocation, not debugfs */
901-
if (err < 0)
902-
return err;
903-
904-
/* create read-write ipc_flood_duration_ms debugfs entry */
905-
err = snd_sof_debugfs_buf_item(sdev, NULL, 0,
906-
"ipc_flood_duration_ms", 0666);
907-
908-
/* errors are only due to memory allocation, not debugfs */
909-
if (err < 0)
910-
return err;
911-
#endif
912-
913682
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR)
914683
err = snd_sof_debugfs_msg_inject_item(sdev, "ipc_msg_inject", 0644,
915684
&msg_inject_fops);

0 commit comments

Comments
 (0)