Skip to contentSkip to conversation

interconnect: qcom: bcm-voter: Clear the ALC vote left by the bootloader

PATCH In review Michael Auer 2 participants 4 messages Nov 20 – Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 interconnect: qcom: bcm-voter: Clear the ALC vote left by the bootloader

The bootloader can leave a vote on the ALC BCM. No icc node maps to ALC, so Linux never touches it and the vote stays. On SDM845 this keeps DDR out of its sleep state, and the SoC never reaches CX collapse or AOSS sleep in suspend.

Clear the vote when the voter probes: (12, 0) in the active-only set, as the downstream kernel does, and (0, 0) in the wake and sleep sets.

Tested on a OnePlus 6 (SDM845). Before, cxsd and aosd in qcom_stats stayed at 0. With this change, CX collapse was reached in 139 suspends over one night, for about 7.6 of 8.9 hours, and the average current over the night was about 27 mA. The active-only vote stays (12, 0) after suspend and resume, and the awake idle current with the display off did not change.

---
Changes in v2:
- Drop the dt-bindings change and the dummy ALC node. Clear the vote in bcm-voter at probe instead, with the code Konrad suggested.
- Link to v1: https://lore.kernel.org/r/[email protected]

This runs for every voter on every SoC that has an ALC entry in cmd-db. SDM845 only has the apps voter. Should it be limited to the apps voter?

Ard, the code is different from v1, so I did not keep your Tested-by. A retest on the C630 would be great.

 drivers/interconnect/qcom/bcm-voter.c | 42 +++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
drivers/interconnect/qcom/bcm-voter.c +42 -0
index 0880a287b0c0..f9d51f3d586d 100644
@@ -390,6 +390,46 @@ int qcom_icc_bcm_voter_commit(struct bcm_voter *voter)
 }
 EXPORT_SYMBOL_GPL(qcom_icc_bcm_voter_commit);
 
+/*
+ * ALC is not modeled by any icc node, but the bootloader may leave it voted,
+ * which prevents the SoC from reaching CX collapse and AOSS shutdown.
+ */
+static void bcm_voter_clear_alc(struct bcm_voter *voter)
+{
+	struct tcs_cmd cmd;
+	u32 addr;
+	int ret;
+
+	addr = cmd_db_read_addr("ALC");
+	if (!addr)
+		return;
+
+	tcs_cmd_gen(&cmd, 12, 0, addr, true,
+		    voter->tcs_wait & BIT(QCOM_ICC_BUCKET_AMC));
+
+	ret = rpmh_write(voter->dev, RPMH_ACTIVE_ONLY_STATE, &cmd, 1);
+	if (ret) {
+		dev_err(voter->dev, "Error sending ALC AMC RPMH request (%d)\n", ret);
+		return;
+	}
+
+	tcs_cmd_gen(&cmd, 0, 0, addr, true,
+		    voter->tcs_wait & BIT(QCOM_ICC_BUCKET_WAKE));
+
+	ret = rpmh_write(voter->dev, RPMH_WAKE_ONLY_STATE, &cmd, 1);
+	if (ret) {
+		dev_err(voter->dev, "Error sending ALC WAKE RPMH request (%d)\n", ret);
+		return;
+	}
+
+	tcs_cmd_gen(&cmd, 0, 0, addr, true,
+		    voter->tcs_wait & BIT(QCOM_ICC_BUCKET_SLEEP));
+
+	ret = rpmh_write(voter->dev, RPMH_SLEEP_STATE, &cmd, 1);
+	if (ret)
+		dev_err(voter->dev, "Error sending ALC SLEEP RPMH request (%d)\n", ret);
+}
+
 static int qcom_icc_bcm_voter_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -409,6 +449,8 @@ static int qcom_icc_bcm_voter_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&voter->commit_list);
 	INIT_LIST_HEAD(&voter->ws_list);
 
+	bcm_voter_clear_alc(voter);
+
 	mutex_lock(&bcm_voter_lock);
 	list_add_tail(&voter->voter_node, &bcm_voters);
 	mutex_unlock(&bcm_voter_lock);

base-commit: 3fd56a2833c22f62eb84297d0dbd47739632f1a0

Signature · 1 line
2.43.0
#1 lore raw

Hi,

A sashiko review of this patch found that the wake and sleep writes never reach the hardware. rpmh only caches them, the (0, 0) wake write replaces the (12, 0) wake value from the active-only write, and rpmh_flush() skips entries with equal sleep and wake values.

That matches the OnePlus 6: the rpmh cache has ALC at sleep 0 and wake 0, and the APPS DRV vote read back after a night with 139 suspends is still 0x20030000, so (12, 0). What I tested is the active-only (12, 0) vote alone, held through suspend, and with it the SoC reaches CX collapse.

Konrad, did you mean ALC to drop to (0, 0) in sleep? Then the wake write has to go, so that rpmh_flush() programs both sets. I can test that. If the active vote is enough, I would drop the wake and sleep writes in v3, so the code does what was tested.

The review also found that bcm_voter can be unbound while the voter stays on the bcm_voters list. That is older than this patch... I can send a separate patch that sets suppress_bind_attrs.

Best,
Michael

Quoted 96 lines · Michael Auer

The bootloader can leave a vote on the ALC BCM. No icc node maps to ALC, so Linux never touches it and the vote stays. On SDM845 this keeps DDR out of its sleep state, and the SoC never reaches CX collapse or AOSS sleep in suspend.

Clear the vote when the voter probes: (12, 0) in the active-only set, as the downstream kernel does, and (0, 0) in the wake and sleep sets.

Tested on a OnePlus 6 (SDM845). Before, cxsd and aosd in qcom_stats stayed at 0. With this change, CX collapse was reached in 139 suspends over one night, for about 7.6 of 8.9 hours, and the average current over the night was about 27 mA. The active-only vote stays (12, 0) after suspend and resume, and the awake idle current with the display off did not change.

---
Changes in v2:
- Drop the dt-bindings change and the dummy ALC node. Clear the vote in bcm-voter at probe instead, with the code Konrad suggested.
- Link to v1: https://lore.kernel.org/r/[email protected]

This runs for every voter on every SoC that has an ALC entry in cmd-db. SDM845 only has the apps voter. Should it be limited to the apps voter?

Ard, the code is different from v1, so I did not keep your Tested-by. A retest on the C630 would be great.

  drivers/interconnect/qcom/bcm-voter.c | 42 +++++++++++++++++++++++++++
  1 file changed, 42 insertions(+)
drivers/interconnect/qcom/bcm-voter.c +42 -0
index 0880a287b0c0..f9d51f3d586d 100644
@@ -390,6 +390,46 @@ int qcom_icc_bcm_voter_commit(struct bcm_voter *voter)
  }
  EXPORT_SYMBOL_GPL(qcom_icc_bcm_voter_commit);
 
+/*
+ * ALC is not modeled by any icc node, but the bootloader may leave it voted,
+ * which prevents the SoC from reaching CX collapse and AOSS shutdown.
+ */
+static void bcm_voter_clear_alc(struct bcm_voter *voter)
+{
+	struct tcs_cmd cmd;
+	u32 addr;
+	int ret;
+
+	addr = cmd_db_read_addr("ALC");
+	if (!addr)
+		return;
+
+	tcs_cmd_gen(&cmd, 12, 0, addr, true,
+		    voter->tcs_wait & BIT(QCOM_ICC_BUCKET_AMC));
+
+	ret = rpmh_write(voter->dev, RPMH_ACTIVE_ONLY_STATE, &cmd, 1);
+	if (ret) {
+		dev_err(voter->dev, "Error sending ALC AMC RPMH request (%d)\n", ret);
+		return;
+	}
+
+	tcs_cmd_gen(&cmd, 0, 0, addr, true,
+		    voter->tcs_wait & BIT(QCOM_ICC_BUCKET_WAKE));
+
+	ret = rpmh_write(voter->dev, RPMH_WAKE_ONLY_STATE, &cmd, 1);
+	if (ret) {
+		dev_err(voter->dev, "Error sending ALC WAKE RPMH request (%d)\n", ret);
+		return;
+	}
+
+	tcs_cmd_gen(&cmd, 0, 0, addr, true,
+		    voter->tcs_wait & BIT(QCOM_ICC_BUCKET_SLEEP));
+
+	ret = rpmh_write(voter->dev, RPMH_SLEEP_STATE, &cmd, 1);
+	if (ret)
+		dev_err(voter->dev, "Error sending ALC SLEEP RPMH request (%d)\n", ret);
+}
+
  static int qcom_icc_bcm_voter_probe(struct platform_device *pdev)
  {
  	struct device_node *np = pdev->dev.of_node;
@@ -409,6 +449,8 @@ static int qcom_icc_bcm_voter_probe(struct platform_device *pdev)
  	INIT_LIST_HEAD(&voter->commit_list);
  	INIT_LIST_HEAD(&voter->ws_list);
 
+	bcm_voter_clear_alc(voter);
+
  	mutex_lock(&bcm_voter_lock);
  	list_add_tail(&voter->voter_node, &bcm_voters);
  	mutex_unlock(&bcm_voter_lock);

base-commit: 3fd56a2833c22f62eb84297d0dbd47739632f1a0

#2 lore raw
Quoted 7 lines · Michael Auer

Hi,

A sashiko review of this patch found that the wake and sleep writes never reach the hardware. rpmh only caches them, the (0, 0) wake write replaces the (12, 0) wake value from the active-only write, and rpmh_flush() skips entries with equal sleep and wake values.

Quoted 5 lines

That matches the OnePlus 6: the rpmh cache has ALC at sleep 0 and wake 0, and the APPS DRV vote read back after a night with 139 suspends is still 0x20030000, so (12, 0). What I tested is the active-only (12, 0) vote alone, held through suspend, and with it the SoC reaches CX collapse.

I was hoping you would test my suggestion before sending it out..

Quoted 4 lines

Konrad, did you mean ALC to drop to (0, 0) in sleep? Then the wake write has to go, so that rpmh_flush() programs both sets. I can test that. If the active vote is enough, I would drop the wake and sleep writes in v3, so the code does what was tested.

My agent suggests that changing this to use rpmh_write_batch() as these aren't cached and should achieve the desired outcome, please explore that

Konrad

#3 lore raw

Hi Konrad,

Quoted 1 line

I was hoping you would test my suggestion before sending it out..

I did run it: the numbers in the commit message are from your code on the OnePlus 6. What I only saw after the review is that just the active-only write had an effect.

Quoted 3 lines

My agent suggests that changing this to use rpmh_write_batch() as these aren't cached and should achieve the desired outcome, please explore that

For sleep and wake, rpmh_write_batch() also only queues the request, on ctrlr->batch_cache, until rpmh_flush(). It skips the sleep == wake check, but qcom_icc_bcm_voter_commit() calls rpmh_invalidate() on every commit, and that frees the whole batch_cache.

I tried it on the OnePlus 6, with all three ALC votes sent through rpmh_write_batch() and a debug print in rpmh.c: both ALC batches were queued at probe and freed by rpmh_invalidate() 2 ms later, at the first icc commit. They never reached rpmh_flush(), and after suspend the vote was still the active-only (12, 0), as with v2. So ALC would have to be added to the wake and sleep batches of every commit.

Also, a (0, 0) wake vote that reaches the hardware would turn ALC off after the first resume.

rpmh_invalidate() does not touch the rpmh_write() cache, so I tested a smaller change: active-only (12, 0) and sleep (0, 0) with rpmh_write(), and no wake write. The active write also sets the cached wake value, so the sleep and wake values differ and rpmh_flush() programs both.

On the OnePlus 6 the rpmh cache now has ALC at sleep (0, 0) and wake (12, 0), and rpmh_flush() no longer skips it. The APPS DRV vote reads (12, 0) after boot and again after 16 suspends. In a 25 minute suspend test the SoC was in CX collapse for 86 % of the suspended time, the same as with v2.

If that is what you meant, I will send it as v3.

Thanks,
Michael