From 8ca5ee11584c995849b9baf70bb9e6686e3f66bb Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Wed, 26 Jun 2024 10:18:43 +0200 Subject: [PATCH] kcps: fix 0 module CPC case If a module contains 0 as its CPC value, the consumption calculation routine will assign a "safe" maximum value to keep the DSP running at the maximum clock rate. This works when constructing a pipeline, but when a pipeline is torn down, returning the maximum clock rate leads to the clock being reduced to a small value. Fix this by detecting such cases in pipeline termination code. Signed-off-by: Guennadi Liakhovetski --- src/audio/pipeline/pipeline-stream.c | 13 +++++++++++++ src/include/sof/audio/pipeline.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/audio/pipeline/pipeline-stream.c b/src/audio/pipeline/pipeline-stream.c index 7077f5e30251..2025f908fe47 100644 --- a/src/audio/pipeline/pipeline-stream.c +++ b/src/audio/pipeline/pipeline-stream.c @@ -344,11 +344,18 @@ static int pipeline_calc_cps_consumption(struct comp_dev *current, if (cd->cpc == 0) { /* Use maximum clock budget, assume 1ms chunk size */ + if (!ppl_data->kcps_acc[comp_core]) + ppl_data->kcps_acc[comp_core] = ppl_data->kcps[comp_core]; ppl_data->kcps[comp_core] = CLK_MAX_CPU_HZ / 1000; tr_warn(pipe, "0 CPS requested for module: %#x, core: %d using safe max KCPS: %u", current->ipc_config.id, comp_core, ppl_data->kcps[comp_core]); + /* + * This return code indicates to the caller, that the kcps calue + * shouldn't be used for slowing down the clock when terminating + * the pipeline + */ return PPL_STATUS_PATH_STOP; } else { kcps = cd->cpc * 1000 / current->period; @@ -430,6 +437,12 @@ int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd) ret = walk_ctx.comp_func(p->source_comp, NULL, &walk_ctx, PPL_DIR_DOWNSTREAM); for (int i = 0; i < arch_num_cpus(); i++) { + if (ret == PPL_STATUS_PATH_STOP) { + /* Restore the value before maximization */ + data.kcps[i] -= data.kcps_acc[i]; + data.kcps_acc[i] = 0; + } + if (data.kcps[i] > 0) { core_kcps_adjust(i, -data.kcps[i]); tr_info(pipe, "Sum of KCPS consumption: %d, core: %d", core_kcps_get(i), i); diff --git a/src/include/sof/audio/pipeline.h b/src/include/sof/audio/pipeline.h index 0edb3305680c..a3d9a91cd670 100644 --- a/src/include/sof/audio/pipeline.h +++ b/src/include/sof/audio/pipeline.h @@ -124,6 +124,7 @@ struct pipeline_data { uint32_t delay_ms; /* between PRE_{START,RELEASE} and {START,RELEASE} */ #if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL uint32_t kcps[CONFIG_CORE_COUNT]; /**< the max count of KCPS */ + uint32_t kcps_acc[CONFIG_CORE_COUNT]; /**< accumulated KCPS before maximization */ #endif };