Certain platforms require that some buses (or individual nodes) make
some additional changes to the clock rate formula, throwing in some
magic, Qualcomm-defined coefficients, to account for "inefficiencies".
Add the framework for it and utilize it on a couple SoCs.
Signed-off-by: Konrad Dybcio <[email protected]>
---
Changes in v3:
- Allocate the node bus clock on the stack, as dynamically allocating
it actually wastes memory on systems with 64-bit pointers..
- Add the node bus clock struct member in the correct patch
- Simplify using coefficients by only checking the node-level ones, and
setting them equal to the bus-specific ones at probe if absent
- Fix building on arm32
- Mention some references to the related downstream code
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Use the (arguably less favourable but necessary for precission) 100/x
instead of x/100 for ib coefficient, update values in consequent
patches to reflect that
- Rename "_percent" to "_coeff" because of /\
- Add the necessary code to support per-node clocks
- Add the necessary code to support per-node coefficients
- Hook up the CPUSS<->GNoC clock on QCM2290
- Update EBI node on QCM2290
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Konrad Dybcio (10):
interconnect: qcom: icc-rpm: Add AB/IB calculations coefficients
interconnect: qcom: icc-rpm: Separate out clock rate calulcations
interconnect: qcom: icc-rpm: Let nodes drive their own bus clock
interconnect: qcom: icc-rpm: Check for node-specific rate coefficients
interconnect: qcom: qcm2290: Hook up MAS_APPS_PROC's bus clock
interconnect: qcom: qcm2290: Set AB coefficients
interconnect: qcom: qcm2290: Update EBI channel configuration
interconnect: qcom: sdm660: Set AB/IB coefficients
interconnect: qcom: msm8996: Set AB/IB coefficients
clk: qcom: smd-rpm: Move CPUSS_GNoC clock to interconnect
drivers/clk/qcom/clk-smd-rpm.c | 16 +++++--
drivers/interconnect/qcom/icc-rpm-clocks.c | 6 +++
drivers/interconnect/qcom/icc-rpm.c | 76 +++++++++++++++++++++++++-----
drivers/interconnect/qcom/icc-rpm.h | 15 ++++++
drivers/interconnect/qcom/msm8996.c | 8 +++-
drivers/interconnect/qcom/qcm2290.c | 9 +++-
drivers/interconnect/qcom/sdm660.c | 4 ++
7 files changed, 115 insertions(+), 19 deletions(-)
---
base-commit: 71cd4fc492ec41e4acd85e98bbf7a13753fc1e03
change-id: 20230726-topic-icc_coeff-b053d5409b9f
Best regards,
--
Konrad Dybcio <[email protected]>
This single node has its own clock which seems to be responsible for
transactions between CPUSS (CPU + some stuff) and the GNOC. See [1]
for reference.
Define it and hook it up.
[1] https://android.googlesource.com/kernel/msm-extra/devicetree/+/02f8c342b23c20a5cf967df649814be37a08227c%5E%21/#F0
Signed-off-by: Konrad Dybcio <[email protected]>
---
drivers/interconnect/qcom/icc-rpm-clocks.c | 6 ++++++
drivers/interconnect/qcom/icc-rpm.h | 1 +
drivers/interconnect/qcom/qcm2290.c | 3 +++
3 files changed, 10 insertions(+)
diff --git a/drivers/interconnect/qcom/icc-rpm-clocks.c b/drivers/interconnect/qcom/icc-rpm-clocks.c
index 63c82a91bbc7..ac1677de7dfd 100644
--- a/drivers/interconnect/qcom/icc-rpm-clocks.c
+++ b/drivers/interconnect/qcom/icc-rpm-clocks.c
@@ -25,6 +25,12 @@ const struct rpm_clk_resource bimc_clk = {
};
EXPORT_SYMBOL_GPL(bimc_clk);
+const struct rpm_clk_resource mem_1_clk = {
+ .resource_type = QCOM_SMD_RPM_MEM_CLK,
+ .clock_id = 1,
+};
+EXPORT_SYMBOL_GPL(mem_1_clk);
+
const struct rpm_clk_resource bus_0_clk = {
.resource_type = QCOM_SMD_RPM_BUS_CLK,
.clock_id = 0,
diff --git a/drivers/interconnect/qcom/icc-rpm.h b/drivers/interconnect/qcom/icc-rpm.h
index 4abf99ce2690..a13768cfd231 100644
--- a/drivers/interconnect/qcom/icc-rpm.h
+++ b/drivers/interconnect/qcom/icc-rpm.h
@@ -152,6 +152,7 @@ extern const struct rpm_clk_resource bimc_clk;
extern const struct rpm_clk_resource bus_0_clk;
extern const struct rpm_clk_resource bus_1_clk;
extern const struct rpm_clk_resource bus_2_clk;
+extern const struct rpm_clk_resource mem_1_clk;
extern const struct rpm_clk_resource mmaxi_0_clk;
extern const struct rpm_clk_resource mmaxi_1_clk;
extern const struct rpm_clk_resource qup_clk;
diff --git a/drivers/interconnect/qcom/qcm2290.c b/drivers/interconnect/qcom/qcm2290.c
index 3c3b24264a5b..52a6eb32e832 100644
--- a/drivers/interconnect/qcom/qcm2290.c
+++ b/drivers/interconnect/qcom/qcm2290.c
@@ -112,6 +112,9 @@ static struct qcom_icc_node mas_appss_proc = {
.qos.qos_mode = NOC_QOS_MODE_FIXED,
.qos.prio_level = 0,
.qos.areq_prio = 0,
+ .bus_clk_desc = &mem_1_clk,
+ .ab_coeff = 159,
+ .ib_coeff = 96,
.mas_rpm_id = 0,
.slv_rpm_id = -1,
.num_links = ARRAY_SIZE(mas_appss_proc_links),
--
2.41.0
Some nodes may have different coefficients than the general values for
bus they're attached to. Check for that and use them if present. See
[1], [2] for reference.
[1] https://github.com/sonyxperiadev/kernel/commit/7456d9779af9ad6bb9c7ee6f33d5c5a8d3648e24
[2] https://github.com/artem/android_kernel_sony_msm8996/commit/bf7a8985dcaf0eab5bc2562d2d6775e7e29c0f30
Signed-off-by: Konrad Dybcio <[email protected]>
---
drivers/interconnect/qcom/icc-rpm.c | 14 ++++++++++----
drivers/interconnect/qcom/icc-rpm.h | 5 +++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/interconnect/qcom/icc-rpm.c b/drivers/interconnect/qcom/icc-rpm.c
index 1d3af4e9ead8..9c40314e03b5 100644
--- a/drivers/interconnect/qcom/icc-rpm.c
+++ b/drivers/interconnect/qcom/icc-rpm.c
@@ -300,14 +300,14 @@ static u64 qcom_icc_calc_rate(struct qcom_icc_provider *qp, struct qcom_icc_node
else
agg_avg_rate = qn->sum_avg[ctx];
- if (qp->ab_coeff) {
- agg_avg_rate = agg_avg_rate * qp->ab_coeff;
+ if (qn->ab_coeff) {
+ agg_avg_rate = agg_avg_rate * qn->ab_coeff;
agg_avg_rate = div_u64(agg_avg_rate, 100);
}
- if (qp->ib_coeff) {
+ if (qn->ib_coeff) {
agg_peak_rate = qn->max_peak[ctx] * 100;
- agg_peak_rate = div_u64(qn->max_peak[ctx], qp->ib_coeff);
+ agg_peak_rate = div_u64(qn->max_peak[ctx], qn->ib_coeff);
} else {
agg_peak_rate = qn->max_peak[ctx];
}
@@ -563,6 +563,12 @@ int qnoc_probe(struct platform_device *pdev)
for (i = 0; i < num_nodes; i++) {
size_t j;
+ if (!qnodes[i]->ab_coeff)
+ qnodes[i]->ab_coeff = qp->ab_coeff;
+
+ if (!qnodes[i]->ib_coeff)
+ qnodes[i]->ib_coeff = qp->ib_coeff;
+
node = icc_node_create(qnodes[i]->id);
if (IS_ERR(node)) {
ret = PTR_ERR(node);
diff --git a/drivers/interconnect/qcom/icc-rpm.h b/drivers/interconnect/qcom/icc-rpm.h
index f9ef16f570be..4abf99ce2690 100644
--- a/drivers/interconnect/qcom/icc-rpm.h
+++ b/drivers/interconnect/qcom/icc-rpm.h
@@ -103,6 +103,9 @@ struct qcom_icc_qos {
* @mas_rpm_id: RPM id for devices that are bus masters
* @slv_rpm_id: RPM id for devices that are bus slaves
* @qos: NoC QoS setting parameters
+ * @ab_coeff: a percentage-based coefficient for compensating the AB calculations
+ * @ib_coeff: an inverse-percentage-based coefficient for compensating the IB calculations
+ * @bus_clk_rate: a pointer to an array containing bus clock rates in Hz
*/
struct qcom_icc_node {
unsigned char *name;
@@ -117,6 +120,8 @@ struct qcom_icc_node {
int mas_rpm_id;
int slv_rpm_id;
struct qcom_icc_qos qos;
+ u16 ab_coeff;
+ u16 ib_coeff;
u32 bus_clk_rate[QCOM_SMD_RPM_STATE_NUM];
};
--
2.41.0
Some buses need additional manual adjustments atop the usual
calculations. Fill in the missing coefficients.
Signed-off-by: Konrad Dybcio <[email protected]>
---
drivers/interconnect/qcom/qcm2290.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/interconnect/qcom/qcm2290.c b/drivers/interconnect/qcom/qcm2290.c
index 52a6eb32e832..42fa01c66e73 100644
--- a/drivers/interconnect/qcom/qcm2290.c
+++ b/drivers/interconnect/qcom/qcm2290.c
@@ -1201,6 +1201,7 @@ static const struct qcom_icc_desc qcm2290_bimc = {
.regmap_cfg = &qcm2290_bimc_regmap_config,
/* M_REG_BASE() in vendor msm_bus_bimc_adhoc driver */
.qos_offset = 0x8000,
+ .ab_coeff = 153,
};
static struct qcom_icc_node * const qcm2290_cnoc_nodes[] = {
@@ -1327,6 +1328,7 @@ static const struct qcom_icc_desc qcm2290_mmnrt_virt = {
.bus_clk_desc = &mmaxi_0_clk,
.regmap_cfg = &qcm2290_snoc_regmap_config,
.qos_offset = 0x15000,
+ .ab_coeff = 142,
};
static struct qcom_icc_node * const qcm2290_mmrt_virt_nodes[] = {
@@ -1342,6 +1344,7 @@ static const struct qcom_icc_desc qcm2290_mmrt_virt = {
.bus_clk_desc = &mmaxi_1_clk,
.regmap_cfg = &qcm2290_snoc_regmap_config,
.qos_offset = 0x15000,
+ .ab_coeff = 139,
};
static const struct of_device_id qcm2290_noc_of_match[] = {
--
2.41.0
On Tue, Aug 08, 2023 at 01:43:35PM +0200, Konrad Dybcio wrote:
> Some nodes may have different coefficients than the general values for
> bus they're attached to. Check for that and use them if present. See
> [1], [2] for reference.
>
> [1] https://github.com/sonyxperiadev/kernel/commit/7456d9779af9ad6bb9c7ee6f33d5c5a8d3648e24
> [2] https://github.com/artem/android_kernel_sony_msm8996/commit/bf7a8985dcaf0eab5bc2562d2d6775e7e29c0f30
> Signed-off-by: Konrad Dybcio <[email protected]>
> ---
> drivers/interconnect/qcom/icc-rpm.c | 14 ++++++++++----
> drivers/interconnect/qcom/icc-rpm.h | 5 +++++
> 2 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/interconnect/qcom/icc-rpm.c b/drivers/interconnect/qcom/icc-rpm.c
> index 1d3af4e9ead8..9c40314e03b5 100644
> --- a/drivers/interconnect/qcom/icc-rpm.c
> +++ b/drivers/interconnect/qcom/icc-rpm.c
> @@ -300,14 +300,14 @@ static u64 qcom_icc_calc_rate(struct qcom_icc_provider *qp, struct qcom_icc_node
> else
> agg_avg_rate = qn->sum_avg[ctx];
>
> - if (qp->ab_coeff) {
> - agg_avg_rate = agg_avg_rate * qp->ab_coeff;
> + if (qn->ab_coeff) {
> + agg_avg_rate = agg_avg_rate * qn->ab_coeff;
> agg_avg_rate = div_u64(agg_avg_rate, 100);
> }
>
> - if (qp->ib_coeff) {
> + if (qn->ib_coeff) {
> agg_peak_rate = qn->max_peak[ctx] * 100;
> - agg_peak_rate = div_u64(qn->max_peak[ctx], qp->ib_coeff);
> + agg_peak_rate = div_u64(qn->max_peak[ctx], qn->ib_coeff);
> } else {
> agg_peak_rate = qn->max_peak[ctx];
> }
> @@ -563,6 +563,12 @@ int qnoc_probe(struct platform_device *pdev)
> for (i = 0; i < num_nodes; i++) {
> size_t j;
>
> + if (!qnodes[i]->ab_coeff)
> + qnodes[i]->ab_coeff = qp->ab_coeff;
> +
> + if (!qnodes[i]->ib_coeff)
> + qnodes[i]->ib_coeff = qp->ib_coeff;
> +
> node = icc_node_create(qnodes[i]->id);
> if (IS_ERR(node)) {
> ret = PTR_ERR(node);
> diff --git a/drivers/interconnect/qcom/icc-rpm.h b/drivers/interconnect/qcom/icc-rpm.h
> index f9ef16f570be..4abf99ce2690 100644
> --- a/drivers/interconnect/qcom/icc-rpm.h
> +++ b/drivers/interconnect/qcom/icc-rpm.h
> @@ -103,6 +103,9 @@ struct qcom_icc_qos {
> * @mas_rpm_id: RPM id for devices that are bus masters
> * @slv_rpm_id: RPM id for devices that are bus slaves
> * @qos: NoC QoS setting parameters
> + * @ab_coeff: a percentage-based coefficient for compensating the AB calculations
> + * @ib_coeff: an inverse-percentage-based coefficient for compensating the IB calculations
> + * @bus_clk_rate: a pointer to an array containing bus clock rates in Hz
Nitpick: The doc comment needs to be moved to the earlier patch as well. :)
> */
> struct qcom_icc_node {
> unsigned char *name;
> @@ -117,6 +120,8 @@ struct qcom_icc_node {
> int mas_rpm_id;
> int slv_rpm_id;
> struct qcom_icc_qos qos;
> + u16 ab_coeff;
> + u16 ib_coeff;
> u32 bus_clk_rate[QCOM_SMD_RPM_STATE_NUM];
> };
>
>
> --
> 2.41.0
>
On 10.08.2023 09:26, Stephan Gerhold wrote:
> On Tue, Aug 08, 2023 at 01:43:35PM +0200, Konrad Dybcio wrote:
>> Some nodes may have different coefficients than the general values for
>> bus they're attached to. Check for that and use them if present. See
>> [1], [2] for reference.
>>
>> [1] https://github.com/sonyxperiadev/kernel/commit/7456d9779af9ad6bb9c7ee6f33d5c5a8d3648e24
>> [2] https://github.com/artem/android_kernel_sony_msm8996/commit/bf7a8985dcaf0eab5bc2562d2d6775e7e29c0f30
>> Signed-off-by: Konrad Dybcio <[email protected]>
>> ---
>> drivers/interconnect/qcom/icc-rpm.c | 14 ++++++++++----
>> drivers/interconnect/qcom/icc-rpm.h | 5 +++++
>> 2 files changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/interconnect/qcom/icc-rpm.c b/drivers/interconnect/qcom/icc-rpm.c
>> index 1d3af4e9ead8..9c40314e03b5 100644
>> --- a/drivers/interconnect/qcom/icc-rpm.c
>> +++ b/drivers/interconnect/qcom/icc-rpm.c
>> @@ -300,14 +300,14 @@ static u64 qcom_icc_calc_rate(struct qcom_icc_provider *qp, struct qcom_icc_node
>> else
>> agg_avg_rate = qn->sum_avg[ctx];
>>
>> - if (qp->ab_coeff) {
>> - agg_avg_rate = agg_avg_rate * qp->ab_coeff;
>> + if (qn->ab_coeff) {
>> + agg_avg_rate = agg_avg_rate * qn->ab_coeff;
>> agg_avg_rate = div_u64(agg_avg_rate, 100);
>> }
>>
>> - if (qp->ib_coeff) {
>> + if (qn->ib_coeff) {
>> agg_peak_rate = qn->max_peak[ctx] * 100;
>> - agg_peak_rate = div_u64(qn->max_peak[ctx], qp->ib_coeff);
>> + agg_peak_rate = div_u64(qn->max_peak[ctx], qn->ib_coeff);
>> } else {
>> agg_peak_rate = qn->max_peak[ctx];
>> }
>> @@ -563,6 +563,12 @@ int qnoc_probe(struct platform_device *pdev)
>> for (i = 0; i < num_nodes; i++) {
>> size_t j;
>>
>> + if (!qnodes[i]->ab_coeff)
>> + qnodes[i]->ab_coeff = qp->ab_coeff;
>> +
>> + if (!qnodes[i]->ib_coeff)
>> + qnodes[i]->ib_coeff = qp->ib_coeff;
>> +
>> node = icc_node_create(qnodes[i]->id);
>> if (IS_ERR(node)) {
>> ret = PTR_ERR(node);
>> diff --git a/drivers/interconnect/qcom/icc-rpm.h b/drivers/interconnect/qcom/icc-rpm.h
>> index f9ef16f570be..4abf99ce2690 100644
>> --- a/drivers/interconnect/qcom/icc-rpm.h
>> +++ b/drivers/interconnect/qcom/icc-rpm.h
>> @@ -103,6 +103,9 @@ struct qcom_icc_qos {
>> * @mas_rpm_id: RPM id for devices that are bus masters
>> * @slv_rpm_id: RPM id for devices that are bus slaves
>> * @qos: NoC QoS setting parameters
>> + * @ab_coeff: a percentage-based coefficient for compensating the AB calculations
>> + * @ib_coeff: an inverse-percentage-based coefficient for compensating the IB calculations
>> + * @bus_clk_rate: a pointer to an array containing bus clock rates in Hz
>
> Nitpick: The doc comment needs to be moved to the earlier patch as well. :)
Gah :P
Konrad