From df0b47d80dfea568b40b206ea250662c6b510d7b Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 13 Aug 2024 17:15:53 +0200 Subject: [PATCH] llext: fix failures with short-lived pipelines When speaker-test stops, it once again creates and immediately destroys pipelines. This leads to failures with LLEXT. Add a minimum pipeline life time for such cases. Signed-off-by: Guennadi Liakhovetski --- app/boards/intel_adsp_ace15_mtpm.conf | 1 + src/audio/pipeline/pipeline-graph.c | 6 ++++++ src/include/sof/audio/pipeline.h | 1 + src/ipc/ipc4/helper.c | 12 ++++++++++++ src/library_manager/Kconfig | 11 +++++++++++ 5 files changed, 31 insertions(+) diff --git a/app/boards/intel_adsp_ace15_mtpm.conf b/app/boards/intel_adsp_ace15_mtpm.conf index e4e4b5c872f4..011fd69adf9f 100644 --- a/app/boards/intel_adsp_ace15_mtpm.conf +++ b/app/boards/intel_adsp_ace15_mtpm.conf @@ -41,6 +41,7 @@ CONFIG_DMA_DW_LLI_POOL_SIZE=50 CONFIG_INTEL_MODULES=y CONFIG_LIBRARY_MANAGER=y CONFIG_LIBRARY_AUTH_SUPPORT=y +CONFIG_LIBRARY_PIPELINE_FORCE_MIN_LIFETIME=100 CONFIG_INTEL_ADSP_TIMER=y CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y CONFIG_AMS=y diff --git a/src/audio/pipeline/pipeline-graph.c b/src/audio/pipeline/pipeline-graph.c index 42fbdc7bae8f..0f5874a09b7d 100644 --- a/src/audio/pipeline/pipeline-graph.c +++ b/src/audio/pipeline/pipeline-graph.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -260,6 +261,11 @@ static int pipeline_comp_complete(struct comp_dev *current, /* complete component init */ current->pipeline = ppl_data->p; + + if (comp_is_llext(current)) + /* pipelines are allocated using rzalloc(), so initially .init_time = 0 */ + current->pipeline->init_time = sof_cycle_get_64(); + /* LL module has its period always eq period of the pipeline * DP period is set to 0 as sink format may not yet been set * It will be calculated during module prepare operation diff --git a/src/include/sof/audio/pipeline.h b/src/include/sof/audio/pipeline.h index 2410f774f00d..4291e4d1d637 100644 --- a/src/include/sof/audio/pipeline.h +++ b/src/include/sof/audio/pipeline.h @@ -94,6 +94,7 @@ struct pipeline { bool aborted; /* STOP or PAUSE failed, stay active */ bool pending; /* trigger scheduled but not executed yet */ } trigger; + uint64_t init_time; }; struct pipeline_walk_context { diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index d427643ef3ea..5a2aefa1adcc 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -331,6 +331,7 @@ static int ipc_pipeline_module_free(uint32_t pipeline_id) int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id) { struct ipc_comp_dev *ipc_pipe; + uint64_t life_time; int ret; /* check whether pipeline exists */ @@ -342,6 +343,17 @@ int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id) if (!cpu_is_me(ipc_pipe->core)) return ipc4_process_on_core(ipc_pipe->core, false); + if (ipc_pipe->pipeline->init_time) { + /* + * This pipeline must not be destroyed before a minimum time + * since its creation has passed + */ + life_time = k_cyc_to_ms_near64(sof_cycle_get_64() - ipc_pipe->pipeline->init_time); + pipe_dbg(ipc_pipe->pipeline, "Extend pipeline life beyond %llu", life_time); + if (life_time < CONFIG_LIBRARY_PIPELINE_FORCE_MIN_LIFETIME) + k_msleep(CONFIG_LIBRARY_PIPELINE_FORCE_MIN_LIFETIME - life_time); + } + ret = ipc_pipeline_module_free(ipc_pipe->pipeline->pipeline_id); if (ret != IPC4_SUCCESS) { tr_err(&ipc_tr, "ipc_pipeline_free(): module free () failed"); diff --git a/src/library_manager/Kconfig b/src/library_manager/Kconfig index e167f956a37a..627553790beb 100644 --- a/src/library_manager/Kconfig +++ b/src/library_manager/Kconfig @@ -33,4 +33,15 @@ config LIBRARY_AUTH_SUPPORT could be used if enabled. If unsure say N. +config LIBRARY_PIPELINE_FORCE_MIN_LIFETIME + int "Minimum pipeline life-time in ms" + default 0 + range 0 500 + help + Typically pipelines are created for streaming, which lasts for + considerable time, at least seconds. But in some test-cases pipelines + are created and quickly destroyed again with no streaming at all. In + some configurations this leads to failures. This option allows setting + a minimum pipeline life-time, which fixes those scenarios. + endmenu