Skip to content

Commit

Permalink
kcps: fix 0 module CPC case
Browse files Browse the repository at this point in the history
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 <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh committed Jul 16, 2024
1 parent 95517f8 commit a529d61
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/audio/pipeline/pipeline-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,15 @@ static int pipeline_calc_cps_consumption(struct comp_dev *current,

if (cd->cpc == 0) {
/* Use maximum clock budget, assume 1ms chunk size */
ppl_data->kcps[comp_core] = CLK_MAX_CPU_HZ / 1000;
uint32_t core_kcps = core_kcps_get(comp_core);

if (!current->kcps_inc[comp_core]) {
current->kcps_inc[comp_core] = core_kcps;
ppl_data->kcps[comp_core] = CLK_MAX_CPU_HZ / 1000 - core_kcps;
} else {
ppl_data->kcps[comp_core] = core_kcps - current->kcps_inc[comp_core];
current->kcps_inc[comp_core] = 0;
}
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]);
Expand All @@ -367,6 +375,9 @@ int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd)
{
int ret;
#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
/* FIXME: this must be a platform-specific parameter or a Kconfig option */
#define DSP_MIN_KCPS 50000

struct pipeline_data data = {
.start = p->source_comp,
.p = p,
Expand Down Expand Up @@ -431,8 +442,15 @@ int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd)

for (int i = 0; i < arch_num_cpus(); i++) {
if (data.kcps[i] > 0) {
uint32_t core_kcps = core_kcps_get(i);

/* Tests showed, that we cannot go below 40000kcps on MTL */
if (data.kcps[i] > core_kcps - DSP_MIN_KCPS)
data.kcps[i] = core_kcps - DSP_MIN_KCPS;

core_kcps_adjust(i, -data.kcps[i]);
tr_info(pipe, "Sum of KCPS consumption: %d, core: %d", core_kcps_get(i), i);
tr_info(pipe, "Sum of KCPS consumption: %d, core: %d",
core_kcps, i);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/include/sof/audio/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ struct comp_dev {
#if CONFIG_PERFORMANCE_COUNTERS
struct perf_cnt_data pcd;
#endif

#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
int32_t kcps_inc[CONFIG_CORE_COUNT];
#endif
};

/** @}*/
Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/audio/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct pipeline_data {
int cmd;
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 */
int32_t kcps[CONFIG_CORE_COUNT]; /**< the max count of KCPS */
#endif
};

Expand Down

0 comments on commit a529d61

Please sign in to comment.