Skip to content

Commit db8fc10

Browse files
konradybcioGeorgi Djakov
authored andcommitted
interconnect: qcom: icc-rpm: Separate out clock rate calulcations
In preparation for also setting per-node clock rates, separate out the logic that computes it. Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org> Link: https://lore.kernel.org/r/20230726-topic-icc_coeff-v4-2-c04b60caa467@linaro.org Signed-off-by: Georgi Djakov <djakov@kernel.org>
1 parent dd01480 commit db8fc10

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

drivers/interconnect/qcom/icc-rpm.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,32 @@ static int qcom_icc_bw_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
291291
return 0;
292292
}
293293

294+
static u64 qcom_icc_calc_rate(struct qcom_icc_provider *qp, struct qcom_icc_node *qn, int ctx)
295+
{
296+
u64 agg_avg_rate, agg_peak_rate, agg_rate;
297+
298+
if (qn->channels)
299+
agg_avg_rate = div_u64(qn->sum_avg[ctx], qn->channels);
300+
else
301+
agg_avg_rate = qn->sum_avg[ctx];
302+
303+
if (qp->ab_coeff) {
304+
agg_avg_rate = agg_avg_rate * qp->ab_coeff;
305+
agg_avg_rate = div_u64(agg_avg_rate, 100);
306+
}
307+
308+
if (qp->ib_coeff) {
309+
agg_peak_rate = qn->max_peak[ctx] * 100;
310+
agg_peak_rate = div_u64(qn->max_peak[ctx], qp->ib_coeff);
311+
} else {
312+
agg_peak_rate = qn->max_peak[ctx];
313+
}
314+
315+
agg_rate = max_t(u64, agg_avg_rate, agg_peak_rate);
316+
317+
return div_u64(agg_rate, qn->buswidth);
318+
}
319+
294320
/**
295321
* qcom_icc_bus_aggregate - calculate bus clock rates by traversing all nodes
296322
* @provider: generic interconnect provider
@@ -299,38 +325,19 @@ static int qcom_icc_bw_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
299325
static void qcom_icc_bus_aggregate(struct icc_provider *provider, u64 *agg_clk_rate)
300326
{
301327
struct qcom_icc_provider *qp = to_qcom_provider(provider);
302-
u64 agg_avg_rate, agg_peak_rate, agg_rate;
303328
struct qcom_icc_node *qn;
304329
struct icc_node *node;
305-
int i;
330+
int ctx;
306331

307332
/*
308333
* Iterate nodes on the provider, aggregate bandwidth requests for
309334
* every bucket and convert them into bus clock rates.
310335
*/
311336
list_for_each_entry(node, &provider->nodes, node_list) {
312337
qn = node->data;
313-
for (i = 0; i < QCOM_SMD_RPM_STATE_NUM; i++) {
314-
if (qn->channels)
315-
agg_avg_rate = div_u64(qn->sum_avg[i], qn->channels);
316-
else
317-
agg_avg_rate = qn->sum_avg[i];
318-
319-
if (qp->ab_coeff) {
320-
agg_avg_rate = agg_avg_rate * qp->ab_coeff;
321-
agg_avg_rate = div_u64(agg_avg_rate, 100);
322-
}
323-
324-
if (qp->ib_coeff) {
325-
agg_peak_rate = qn->max_peak[i] * 100;
326-
agg_peak_rate = div_u64(qn->max_peak[i], qp->ib_coeff);
327-
} else {
328-
agg_peak_rate = qn->max_peak[i];
329-
}
330-
331-
agg_rate = max_t(u64, agg_avg_rate, agg_peak_rate);
332-
333-
agg_clk_rate[i] = max_t(u64, agg_clk_rate[i], agg_rate);
338+
for (ctx = 0; ctx < QCOM_SMD_RPM_STATE_NUM; ctx++) {
339+
agg_clk_rate[ctx] = max_t(u64, agg_clk_rate[ctx],
340+
qcom_icc_calc_rate(qp, qn, ctx));
334341
}
335342
}
336343
}

0 commit comments

Comments
 (0)