interconnect: qcom: bcm-voter: Improve enable_mask handling
authorKonrad Dybcio <konrad.dybcio@linaro.org>
Fri, 11 Aug 2023 23:16:15 +0000 (01:16 +0200)
committerGeorgi Djakov <djakov@kernel.org>
Mon, 21 Aug 2023 22:39:24 +0000 (01:39 +0300)
We don't need all the complex arithmetic for BCMs utilizing enable_mask,
as all we need to do is to determine whether there's any user (or
keepalive) asking for it to be on.

Separate the logic for such BCMs for a small speed boost.

Suggested-by: Bjorn Andersson <quic_bjorande@quicinc.com>
Reviewed-by: Bjorn Andersson <quic_bjorande@quicinc.com>
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Link: https://lore.kernel.org/r/20230811-topic-icc_fix_1he-v2-1-0620af8ac133@linaro.org
Signed-off-by: Georgi Djakov <djakov@kernel.org>
drivers/interconnect/qcom/bcm-voter.c

index d5f2a6b..d857eb8 100644 (file)
@@ -58,6 +58,36 @@ static u64 bcm_div(u64 num, u32 base)
        return num;
 }
 
+/* BCMs with enable_mask use one-hot-encoding for on/off signaling */
+static void bcm_aggregate_mask(struct qcom_icc_bcm *bcm)
+{
+       struct qcom_icc_node *node;
+       int bucket, i;
+
+       for (bucket = 0; bucket < QCOM_ICC_NUM_BUCKETS; bucket++) {
+               bcm->vote_x[bucket] = 0;
+               bcm->vote_y[bucket] = 0;
+
+               for (i = 0; i < bcm->num_nodes; i++) {
+                       node = bcm->nodes[i];
+
+                       /* If any vote in this bucket exists, keep the BCM enabled */
+                       if (node->sum_avg[bucket] || node->max_peak[bucket]) {
+                               bcm->vote_x[bucket] = 0;
+                               bcm->vote_y[bucket] = bcm->enable_mask;
+                               break;
+                       }
+               }
+       }
+
+       if (bcm->keepalive) {
+               bcm->vote_x[QCOM_ICC_BUCKET_AMC] = 1;
+               bcm->vote_x[QCOM_ICC_BUCKET_WAKE] = 1;
+               bcm->vote_y[QCOM_ICC_BUCKET_AMC] = 1;
+               bcm->vote_y[QCOM_ICC_BUCKET_WAKE] = 1;
+       }
+}
+
 static void bcm_aggregate(struct qcom_icc_bcm *bcm)
 {
        struct qcom_icc_node *node;
@@ -83,11 +113,6 @@ static void bcm_aggregate(struct qcom_icc_bcm *bcm)
 
                temp = agg_peak[bucket] * bcm->vote_scale;
                bcm->vote_y[bucket] = bcm_div(temp, bcm->aux_data.unit);
-
-               if (bcm->enable_mask && (bcm->vote_x[bucket] || bcm->vote_y[bucket])) {
-                       bcm->vote_x[bucket] = 0;
-                       bcm->vote_y[bucket] = bcm->enable_mask;
-               }
        }
 
        if (bcm->keepalive && bcm->vote_x[QCOM_ICC_BUCKET_AMC] == 0 &&
@@ -260,8 +285,12 @@ int qcom_icc_bcm_voter_commit(struct bcm_voter *voter)
                return 0;
 
        mutex_lock(&voter->lock);
-       list_for_each_entry(bcm, &voter->commit_list, list)
-               bcm_aggregate(bcm);
+       list_for_each_entry(bcm, &voter->commit_list, list) {
+               if (bcm->enable_mask)
+                       bcm_aggregate_mask(bcm);
+               else
+                       bcm_aggregate(bcm);
+       }
 
        /*
         * Pre sort the BCMs based on VCD for ease of generating a command list