From 85e1d687973907f9b033e9ad7d1c49f92334b88b Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Tue, 28 May 2024 17:56:33 +0300 Subject: [PATCH] zephyr: shell: add initial SOF custom commands One of the benefits and common ways to use the Zephyr shell subsystem is definition of application specific commands. This commit adds the initial SOF custom command, "sof test_inject_sched_gap". This new command allows to inject scheduling gaps into low-latency timer scheduler execution, using the domain_block() SOF interface. Optional argument can be used to specify duration of the block in micro seconds. The intent is to stress test a SOF configuration and test how the system behaves when audio pipeline is briefly starved. Example log of what is observed when test_inkect_sched_gap is run: [ 0.052431] ll_schedule: zephyr_domain_thread_fn: ll core 0 timer avg 3674, max 4326, overruns 0 [ 0.052831] ll_schedule: zephyr_domain_thread_fn: ll core 0 timer avg 3673, max 4318, overruns 0 ~$ ~$ sof test_inject_sched_gap 12000 [ 0.052968] ll_schedule: zephyr_domain_block: Blocking LL scheduler [ 0.052973] ll_schedule: zephyr_domain_unblock: Unblocking LL scheduler [ 0.052973] host_comp: host_get_copy_bytes_normal: comp:1 0x10004 no bytes to copy, available samples: 0, free_samples: 384 [ 0.053231] ll_schedule: zephyr_domain_thread_fn: ll core 0 timer avg 4074, max 437230, overruns 1 Signed-off-by: Kai Vehmanen --- zephyr/CMakeLists.txt | 4 ++++ zephyr/sof_shell.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 zephyr/sof_shell.c diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index e691dff9d880..7e6014c12841 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -905,6 +905,10 @@ zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST boot_test.c ) +zephyr_library_sources_ifdef(CONFIG_SHELL + sof_shell.c +) + zephyr_library_link_libraries(SOF) target_link_libraries(SOF INTERFACE zephyr_interface) diff --git a/zephyr/sof_shell.c b/zephyr/sof_shell.c new file mode 100644 index 000000000000..d36344b1b3fe --- /dev/null +++ b/zephyr/sof_shell.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright(c) 2024 Intel Corporation. + * + * Author: Kai Vehmanen + */ + +#include /* sof_get() */ +#include + +#include +#include +#include + +#define SOF_TEST_INJECT_SCHED_GAP_USEC 1500 + +static int cmd_sof_test_inject_sched_gap(const struct shell *sh, + size_t argc, char *argv[]) +{ + uint32_t block_time = SOF_TEST_INJECT_SCHED_GAP_USEC; + char *endptr = NULL; + +#ifndef CONFIG_CROSS_CORE_STREAM + shell_fprintf(sh, SHELL_NORMAL, "Domain blocking not supported, not reliable on SMP\n"); +#endif + + domain_block(sof_get()->platform_timer_domain); + + if (argc > 1) { + block_time = strtol(argv[1], &endptr, 0); + if (endptr == argv[1]) + return -EINVAL; + } + + k_busy_wait(block_time); + + domain_unblock(sof_get()->platform_timer_domain); + + return 0; +} + +SHELL_STATIC_SUBCMD_SET_CREATE(sof_commands, + SHELL_CMD(test_inject_sched_gap, NULL, + "Inject a gap to audio scheduling\n", + cmd_sof_test_inject_sched_gap), + + SHELL_SUBCMD_SET_END +); + +SHELL_CMD_REGISTER(sof, &sof_commands, + "SOF application commands", NULL);