From patchwork Mon Jul 31 10:52:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 708874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC04CC001DE for ; Mon, 31 Jul 2023 10:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232252AbjGaKyR (ORCPT ); Mon, 31 Jul 2023 06:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231837AbjGaKxZ (ORCPT ); Mon, 31 Jul 2023 06:53:25 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 577B01BD6 for ; Mon, 31 Jul 2023 03:52:33 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4fb7dc16ff0so6995165e87.2 for ; Mon, 31 Jul 2023 03:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690800751; x=1691405551; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=xVvWZuZykGB5bMQAupOuWvDvdMeiJLjxPsV4TGGQesg=; b=eDvFqWCzdd6OlEph6PTSxP7744I61Ot/s84FP2ZORdSHbReEGTypSqX+LEX5+Lo/wH 2w385t/63vUv4SIIY+mmfSY6ZStvpnGiC7WAZ0hSv4C5CdcJHaVQPa704dehHQtqwVav rL5pgl+ZC3/yD5I1CWDW9BsYOk+g+otnOE6lvsgbuNRD+nTydjTQVOtg3aP5G2b6hKa4 VqXy78xyWoajws1v6jl8Xkdw+NDSbgVvIopD47OGdv0akiGZU5vCy85MXVzc64T47aYe mdGNkJBEbBvBr2da3BrFU/isnNjTDr9p4pJ1DxmYyK9/YERsldWCoT3Y9CdZWILtCIA1 S7zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690800751; x=1691405551; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xVvWZuZykGB5bMQAupOuWvDvdMeiJLjxPsV4TGGQesg=; b=ZQdeuzMWh/bZWp5fYQViax2bDHR0xky0IahYQ6g9DQDWJlbFpvXTMCm7jVVCsLeyl1 tZzNAqVL2BoAUojyMSa0kVqjd9icNnbIfniCi6QXtbbgyoYF+rR5kME5EvCvLwfZl2z2 jWhacQT3I1IsIsPajjNlageYF5DNzegNHM4CZ65uT5I35WjWoAQ9BbwLp+T5vIBcHtYa VOgiseD0VRbJ7lRpJARpheoLG9NdoZoiSNJDB/gr4cdPvduP2ijsSqU/zbACUYSJo4AD SG1O917V6ZpJoBJ8XNYvZBybYSl0PhOMZOzRVu2p/sazoKxcfSQWqS80qmvs2lIysBiv k6pA== X-Gm-Message-State: ABy/qLZtv1btaS3GKMfQS7PTzboQr+YVpxU3BrfNizisusY2+JU+Zwjz wxLSUDr7UFCVV18H0mOBNWVM8Q== X-Google-Smtp-Source: APBJJlFV7t4btE6CmOURCabRnHjP9HKiAcSfqFMdiFhrlKwJxpFX/ROUqVWivY2kbmwauP606A0EHg== X-Received: by 2002:a19:6917:0:b0:4f8:4216:e91f with SMTP id e23-20020a196917000000b004f84216e91fmr4229253lfc.63.1690800751450; Mon, 31 Jul 2023 03:52:31 -0700 (PDT) Received: from [192.168.1.101] (abyk53.neoplus.adsl.tpnet.pl. [83.9.30.53]) by smtp.gmail.com with ESMTPSA id p13-20020a05651238cd00b004fdc7ec5cbesm2016936lft.300.2023.07.31.03.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 03:52:31 -0700 (PDT) From: Konrad Dybcio Date: Mon, 31 Jul 2023 12:52:18 +0200 Subject: [PATCH v2 02/10] interconnect: qcom: icc-rpm: Separate out clock rate calulcations MIME-Version: 1.0 Message-Id: <20230726-topic-icc_coeff-v2-2-8c91c6c76076@linaro.org> References: <20230726-topic-icc_coeff-v2-0-8c91c6c76076@linaro.org> In-Reply-To: <20230726-topic-icc_coeff-v2-0-8c91c6c76076@linaro.org> To: Andy Gross , Bjorn Andersson , Georgi Djakov , Michael Turquette , Stephen Boyd Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1690800744; l=2807; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=l2ys7kUG65Xi3tEUxGk88Ev+nzyHo4Dj5sUaoIzZZZA=; b=VqPlFtmOHF3NLS2AmYOlrACcxBUYD72n5jfWXxo+SYpGi/YBmMubNIOA+JpVGSZtQvxS/Q7+S pWrJZbnz3vbAG2KkwA8NNsoFPd87W/fjKrbDx9lfaXyzYAYtFYzvwCL X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In preparation for also setting per-node clock rates, separate out the logic that computes it. Signed-off-by: Konrad Dybcio --- drivers/interconnect/qcom/icc-rpm.c | 46 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/interconnect/qcom/icc-rpm.c b/drivers/interconnect/qcom/icc-rpm.c index a837d20af79e..f1d8ed354718 100644 --- a/drivers/interconnect/qcom/icc-rpm.c +++ b/drivers/interconnect/qcom/icc-rpm.c @@ -291,6 +291,29 @@ static int qcom_icc_bw_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, return 0; } +static u64 qcom_icc_calc_rate(struct qcom_icc_provider *qp, struct qcom_icc_node *qn, int ctx) +{ + u64 agg_avg_rate, agg_peak_rate, agg_rate; + + if (qn->channels) + agg_avg_rate = div_u64(qn->sum_avg[ctx], qn->channels); + else + agg_avg_rate = qn->sum_avg[ctx]; + + /* Check if the node has a specific coefficient first*/ + if (qp->ab_coeff) + agg_avg_rate = mult_frac(qp->ab_coeff, agg_avg_rate, 100); + + if (qp->ib_coeff) + agg_peak_rate = mult_frac(100, qn->max_peak[ctx], qp->ib_coeff); + else + agg_peak_rate = qn->max_peak[ctx]; + + agg_rate = max_t(u64, agg_avg_rate, agg_peak_rate); + + return div_u64(agg_rate, qn->buswidth); +} + /** * qcom_icc_bus_aggregate - calculate bus clock rates by traversing all nodes * @provider: generic interconnect provider @@ -299,10 +322,9 @@ static int qcom_icc_bw_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, static void qcom_icc_bus_aggregate(struct icc_provider *provider, u64 *agg_clk_rate) { struct qcom_icc_provider *qp = to_qcom_provider(provider); - u64 agg_avg_rate, agg_peak_rate, agg_rate; struct qcom_icc_node *qn; struct icc_node *node; - int i; + int ctx; /* * Iterate nodes on the provider, aggregate bandwidth requests for @@ -310,23 +332,9 @@ static void qcom_icc_bus_aggregate(struct icc_provider *provider, u64 *agg_clk_r */ list_for_each_entry(node, &provider->nodes, node_list) { qn = node->data; - for (i = 0; i < QCOM_SMD_RPM_STATE_NUM; i++) { - if (qn->channels) - agg_avg_rate = div_u64(qn->sum_avg[i], qn->channels); - else - agg_avg_rate = qn->sum_avg[i]; - - if (qp->ab_coeff) - agg_avg_rate = mult_frac(qp->ab_coeff, agg_avg_rate, 100); - - if (qp->ib_coeff) - agg_peak_rate = mult_frac(100, qn->max_peak[i], qp->ib_coeff); - else - agg_peak_rate = qn->max_peak[i]; - - agg_rate = max_t(u64, agg_avg_rate, agg_peak_rate); - - agg_clk_rate[i] = max_t(u64, agg_clk_rate[i], agg_rate); + for (ctx = 0; ctx < QCOM_SMD_RPM_STATE_NUM; ctx++) { + agg_clk_rate[ctx] = max_t(u64, agg_clk_rate[ctx], + qcom_icc_calc_rate(qp, qn, ctx)); } } }