From 6cbe6424a71e232cbc893ff3bc915a5c6aa08d50 Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 11:26:06 +0200 Subject: [PATCH 1/7] cmake: host: enable traces Signed-off-by: Janusz Jankowski --- src/arch/host/CMakeLists.txt | 2 ++ src/arch/host/config.h.in | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/arch/host/CMakeLists.txt b/src/arch/host/CMakeLists.txt index 839f995917f4..2452486c4e21 100644 --- a/src/arch/host/CMakeLists.txt +++ b/src/arch/host/CMakeLists.txt @@ -19,6 +19,8 @@ set(CONFIG_COMP_MUX 1) set(CONFIG_COMP_SWITCH 1) set(CONFIG_COMP_DAI 1) set(CONFIG_COMP_SEL 1) +set(CONFIG_TRACE 1) +set(CONFIG_TRACEE 1) configure_file ( "${PROJECT_SOURCE_DIR}/src/arch/host/config.h.in" diff --git a/src/arch/host/config.h.in b/src/arch/host/config.h.in index f4dca43951ee..3bcd143a5e1e 100644 --- a/src/arch/host/config.h.in +++ b/src/arch/host/config.h.in @@ -9,3 +9,5 @@ #define CONFIG_COMP_MUX @CONFIG_COMP_MUX@ #define CONFIG_COMP_SWITCH @CONFIG_COMP_SWITCH@ #define CONFIG_COMP_DAI @CONFIG_COMP_DAI@ +#define CONFIG_TRACE @CONFIG_TRACE@ +#define CONFIG_TRACEE @CONFIG_TRACEE@ From 4ecc7923d222d97c63a4f96acf0092553f82e8cb Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 11:52:08 +0200 Subject: [PATCH 2/7] tools: scripts: update host installation path Signed-off-by: Janusz Jankowski --- tools/test/audio/src_run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/test/audio/src_run.sh b/tools/test/audio/src_run.sh index 9c88b17f1320..3c41a4f7a32e 100755 --- a/tools/test/audio/src_run.sh +++ b/tools/test/audio/src_run.sh @@ -10,7 +10,7 @@ FN_IN=$5 FN_OUT=$6 # The HOST_ROOT path need to be retrived from SOFT .configure command -HOST_ROOT=../../../../host-root +HOST_ROOT=../../../build_host/install/ HOST_EXE=$HOST_ROOT/bin/testbench HOST_LIB=$HOST_ROOT/lib @@ -18,7 +18,7 @@ HOST_LIB=$HOST_ROOT/lib INFMT=s${BITS_IN}le OUTFMT=s${BITS_IN}le MCLK=24576k -tplg1=../../test/topology/test-playback-ssp2-mclk-0-I2S- +tplg1=../../build_tools/test/topology/test-playback-ssp2-mclk-0-I2S- tplg2=${COMP}-${INFMT}-${OUTFMT}-48k-${MCLK}-nocodec.tplg TPLG=${tplg1}${tplg2} From 05f08cdbf6d69e5ce99d6209303dbccd20e2fb03 Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 17:27:23 +0200 Subject: [PATCH 3/7] component: add init as constructor for .so Component should register itself when built as shared lib. Signed-off-by: Janusz Jankowski --- src/include/sof/audio/component.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index 85a3f0a390ab..71fdb390ab6f 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -152,6 +152,10 @@ */ #ifdef UNIT_TEST #define DECLARE_COMPONENT(init) +#elif CONFIG_HOST +/* In case of shared libs components are initialised in dlopen */ +#define DECLARE_COMPONENT(init) __attribute__((constructor)) \ + static void _comp_init(void) { init(); } #else #define DECLARE_COMPONENT(init) __attribute__((__used__)) \ __attribute__((section(".comp_init"))) static void(*f)(void) = init From 91babfa1a9410508acc5d7f3409db426f40dedcf Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 17:31:10 +0200 Subject: [PATCH 4/7] testbench: remove dai and host All components should be added after sys_comp_init, to be able to register themselves. Dai and host are not used so it's better to just remove them. Signed-off-by: Janusz Jankowski --- src/audio/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index 9dca5e9bb6e4..f022d13cc614 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -74,8 +74,6 @@ add_library(sof_audio_core SHARED "") target_link_libraries(sof_audio_core PRIVATE sof_options) target_link_libraries(sof_audio_core PRIVATE -Wl,--export-dynamic) add_local_sources(sof_audio_core - dai.c - host.c pipeline.c component.c buffer.c From 44fd2bcbe472c75c52e4eb2bc13e6c3e103adf6e Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 17:38:18 +0200 Subject: [PATCH 5/7] host: schedule: check task_init op before calling Signed-off-by: Janusz Jankowski --- src/host/schedule.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/host/schedule.c b/src/host/schedule.c index 920938204290..b92a73e5f514 100644 --- a/src/host/schedule.c +++ b/src/host/schedule.c @@ -55,7 +55,10 @@ int schedule_task_init(struct task *task, uint16_t type, uint16_t priority, task->func = func; task->data = data; - return schedulers[task->type]->schedule_task_init(task, xflags); + if (schedulers[task->type]->schedule_task_init) + return schedulers[task->type]->schedule_task_init(task, xflags); + else + return -ENOENT; } void schedule_task(struct task *task, uint64_t start, uint64_t deadline, From 4a185008fc1cb9f590d4bf1eb17887b423582473 Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 17:41:55 +0200 Subject: [PATCH 6/7] testbench: open and register comp .so on first use Component is registered in function added to shared lib's constructors. We no longer call init found with dlsym, instead we delay delay dlopen until we want to register comp. Signed-off-by: Janusz Jankowski --- src/host/testbench.c | 50 ++++------------------------------ src/host/topology.c | 20 ++++++++++---- src/include/host/common_test.h | 1 - 3 files changed, 20 insertions(+), 51 deletions(-) diff --git a/src/host/testbench.c b/src/host/testbench.c index e212a0aa8b48..36283f0f8570 100644 --- a/src/host/testbench.c +++ b/src/host/testbench.c @@ -42,10 +42,9 @@ /* shared library look up table */ struct shared_lib_table lib_table[NUM_WIDGETS_SUPPORTED] = { -{"file", "", SND_SOC_TPLG_DAPM_AIF_IN, "", 0, NULL}, -{"vol", "libsof_volume.so", SND_SOC_TPLG_DAPM_PGA, "sys_comp_volume_init", 0, - NULL}, -{"src", "libsof_src.so", SND_SOC_TPLG_DAPM_SRC, "sys_comp_src_init", 0, NULL}, + {"file", "", SND_SOC_TPLG_DAPM_AIF_IN, 0, NULL}, + {"vol", "libsof_volume.so", SND_SOC_TPLG_DAPM_PGA, 0, NULL}, + {"src", "libsof_src.so", SND_SOC_TPLG_DAPM_SRC, 0, NULL}, }; /* main firmware context */ @@ -71,7 +70,6 @@ static void parse_libraries(char *libs) char *lib_token = NULL; char *comp_token = NULL; char *token = strtok_r(libs, ",", &lib_token); - char message[DEBUG_MSG_LEN]; int index; while (token) { @@ -92,19 +90,9 @@ static void parse_libraries(char *libs) if (!token1) break; - /* close default shared library object */ - if (lib_table[index].handle) - dlclose(lib_table[index].handle); - - /* open volume shared library object */ - lib_table[index].handle = dlopen(token1, RTLD_LAZY); - if (!lib_table[index].handle) { - fprintf(stderr, "error: %s\n", dlerror()); - exit(EXIT_FAILURE); - } - - sprintf(message, "opening shared lib %s\n", token1); - debug_print(message); + /* set to new name that may be used while loading */ + strncpy(lib_table[index].library_name, token1, + MAX_LIB_NAME_LEN - 1); /* next library */ token = strtok_r(NULL, ",", &lib_token); @@ -154,25 +142,6 @@ static void free_comps(void) } } -static int set_up_library_table(void) -{ - int i; - - /* set up default shared libraries */ - for (i = 1; i < NUM_WIDGETS_SUPPORTED; i++) { - - /* open default shared library */ - lib_table[i].handle = - dlopen(lib_table[i].library_name, RTLD_LAZY); - if (!lib_table[i].handle) { - fprintf(stderr, "error: %s\n", dlerror()); - return -EINVAL; - } - } - - return 0; -} - static void parse_input_args(int argc, char **argv, struct testbench_prm *tp) { int option = 0; @@ -246,13 +215,6 @@ int main(int argc, char **argv) tp.fs_in = 0; tp.fs_out = 0; - /* set up shared library look up table */ - ret = set_up_library_table(); - if (ret < 0) { - fprintf(stderr, "error: setting up shared libraried\n"); - exit(EXIT_FAILURE); - } - /* command line arguments*/ parse_input_args(argc, argv, &tp); diff --git a/src/host/topology.c b/src/host/topology.c index 08bc296fdfe4..b5974b8663b0 100644 --- a/src/host/topology.c +++ b/src/host/topology.c @@ -53,7 +53,7 @@ struct shared_lib_table *lib_table; static void register_comp(int comp_type) { int index; - char message[DEBUG_MSG_LEN]; + char message[DEBUG_MSG_LEN + MAX_LIB_NAME_LEN]; /* register file comp driver (no shared library needed) */ if (comp_type == SND_SOC_TPLG_DAPM_DAI_IN || @@ -77,11 +77,19 @@ static void register_comp(int comp_type) lib_table[index].comp_name); debug_print(message); - /* register comp driver */ - void (*comp_init)() = - (void (*)(void))dlsym(lib_table[index].handle, - lib_table[index].comp_init); - comp_init(); + /* open shared library object */ + sprintf(message, "opening shared lib %s\n", + lib_table[index].library_name); + debug_print(message); + + lib_table[index].handle = dlopen(lib_table[index].library_name, + RTLD_LAZY); + if (!lib_table[index].handle) { + fprintf(stderr, "error: %s\n", dlerror()); + exit(EXIT_FAILURE); + } + + /* comp init is executed on lib load */ lib_table[index].register_drv = 1; } diff --git a/src/include/host/common_test.h b/src/include/host/common_test.h index d8f9fe7697a2..e4b09f45cf0d 100644 --- a/src/include/host/common_test.h +++ b/src/include/host/common_test.h @@ -66,7 +66,6 @@ struct shared_lib_table { char *comp_name; char library_name[MAX_LIB_NAME_LEN]; uint32_t widget_type; - const char *comp_init; int register_drv; void *handle; }; From b09d6b2dedd3040f7d0754bac4b8333324e5a220 Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Thu, 4 Apr 2019 17:47:12 +0200 Subject: [PATCH 7/7] testbench: accumulate widgets while parsing Signed-off-by: Janusz Jankowski --- src/host/topology.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/host/topology.c b/src/host/topology.c index b5974b8663b0..10ee56744380 100644 --- a/src/host/topology.c +++ b/src/host/topology.c @@ -836,11 +836,13 @@ int parse_topology(struct sof *sof, struct shared_lib_table *library_table, sprintf(message, "number of DAPM widgets %d\n", hdr->count); debug_print(message); - size = sizeof(struct comp_info) * hdr->count; - temp_comp_list = (struct comp_info *)malloc(size); - num_comps = hdr->count; - for (i = 0; i < hdr->count; i++) + num_comps += hdr->count; + size = sizeof(struct comp_info) * num_comps; + temp_comp_list = (struct comp_info *) + realloc(temp_comp_list, size); + + for (i = (num_comps - hdr->count); i < num_comps; i++) load_widget(sof, fr_id, fw_id, sched_id, temp_comp_list, &pipeline, next_comp_id++,