linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead
@ 2020-07-07 20:16 Douglas Anderson
  2020-07-07 20:16 ` [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed Douglas Anderson
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Douglas Anderson @ 2020-07-07 20:16 UTC (permalink / raw)
  To: Mark Brown, Andy Gross, Bjorn Andersson
  Cc: mka, Akash Asthana, Rajendra Nayak, swboyd, linux-arm-msm,
	georgi.djakov, ctheegal, mkshah, Douglas Anderson, linux-kernel,
	linux-spi


Not to be confused with the similar series I posed for the _other_
Qualcomm SPI controller (spi-geni-qcom) [1], this one avoids the
overhead on the Quad SPI controller.

It's based atop the current Qualcomm tree including Rajendra's ("spi:
spi-qcom-qspi: Use OPP API to set clk/perf state").  As discussed in
individual patches, these could ideally land through the Qualcomm tree
with Mark's Ack.

Measuring:
* Before OPP / Interconnect patches reading all flash takes: ~3.4 seconds
* After OPP / Interconnect patches reading all flash takes: ~4.7 seconds
* After this patch reading all flash takes: ~3.3 seconds

[1] https://lore.kernel.org/r/20200702004509.2333554-1-dianders@chromium.org
[2] https://lore.kernel.org/r/1593769293-6354-2-git-send-email-rnayak@codeaurora.org


Douglas Anderson (2):
  spi: spi-qcom-qspi: Avoid clock setting if not needed
  spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms

 drivers/spi/spi-qcom-qspi.c | 45 ++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 10 deletions(-)

-- 
2.27.0.383.g050319c2ae-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed
  2020-07-07 20:16 [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Douglas Anderson
@ 2020-07-07 20:16 ` Douglas Anderson
  2020-07-08 17:04   ` Mark Brown
  2020-07-07 20:16 ` [PATCH 2/2] spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms Douglas Anderson
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Douglas Anderson @ 2020-07-07 20:16 UTC (permalink / raw)
  To: Mark Brown, Andy Gross, Bjorn Andersson
  Cc: mka, Akash Asthana, Rajendra Nayak, swboyd, linux-arm-msm,
	georgi.djakov, ctheegal, mkshah, Douglas Anderson, linux-kernel,
	linux-spi

As per recent changes to the spi-qcom-qspi, now when we set the clock
we'll call into the interconnect framework and also call the OPP API.
Those are expensive operations.  Let's avoid calling them if possible.
This has a big impact on getting transfer rates back up to where they
were (or maybe slightly better) before those patches landed.

Fixes: cff80645d6d3 ("spi: spi-qcom-qspi: Add interconnect support")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
This applies atop the Qualcomm tree after Rajendra's ("spi:
spi-qcom-qspi: Use OPP API to set clk/perf state") patch and I'd hope
it could land there with Mark's Ack just like the patch it Fixes did.

 drivers/spi/spi-qcom-qspi.c | 43 ++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi-qcom-qspi.c b/drivers/spi/spi-qcom-qspi.c
index 18a59aa23ef8..322b88c22a86 100644
--- a/drivers/spi/spi-qcom-qspi.c
+++ b/drivers/spi/spi-qcom-qspi.c
@@ -144,6 +144,7 @@ struct qcom_qspi {
 	struct icc_path *icc_path_cpu_to_qspi;
 	struct opp_table *opp_table;
 	bool has_opp_table;
+	unsigned long last_speed;
 	/* Lock to protect data accessed by IRQs */
 	spinlock_t lock;
 };
@@ -226,19 +227,13 @@ static void qcom_qspi_handle_err(struct spi_master *master,
 	spin_unlock_irqrestore(&ctrl->lock, flags);
 }
 
-static int qcom_qspi_transfer_one(struct spi_master *master,
-				  struct spi_device *slv,
-				  struct spi_transfer *xfer)
+static int qcom_qspi_set_speed(struct qcom_qspi *ctrl, unsigned long speed_hz)
 {
-	struct qcom_qspi *ctrl = spi_master_get_devdata(master);
 	int ret;
-	unsigned long speed_hz;
-	unsigned long flags;
 	unsigned int avg_bw_cpu;
 
-	speed_hz = slv->max_speed_hz;
-	if (xfer->speed_hz)
-		speed_hz = xfer->speed_hz;
+	if (speed_hz == ctrl->last_speed)
+		return 0;
 
 	/* In regular operation (SBL_EN=1) core must be 4x transfer clock */
 	ret = dev_pm_opp_set_rate(ctrl->dev, speed_hz * 4);
@@ -259,6 +254,28 @@ static int qcom_qspi_transfer_one(struct spi_master *master,
 		return ret;
 	}
 
+	ctrl->last_speed = speed_hz;
+
+	return 0;
+}
+
+static int qcom_qspi_transfer_one(struct spi_master *master,
+				  struct spi_device *slv,
+				  struct spi_transfer *xfer)
+{
+	struct qcom_qspi *ctrl = spi_master_get_devdata(master);
+	int ret;
+	unsigned long speed_hz;
+	unsigned long flags;
+
+	speed_hz = slv->max_speed_hz;
+	if (xfer->speed_hz)
+		speed_hz = xfer->speed_hz;
+
+	ret = qcom_qspi_set_speed(ctrl, speed_hz);
+	if (ret)
+		return ret;
+
 	spin_lock_irqsave(&ctrl->lock, flags);
 
 	/* We are half duplex, so either rx or tx will be set */
@@ -602,7 +619,13 @@ static int __maybe_unused qcom_qspi_runtime_resume(struct device *dev)
 		return ret;
 	}
 
-	return clk_bulk_prepare_enable(QSPI_NUM_CLKS, ctrl->clks);
+	ret = clk_bulk_prepare_enable(QSPI_NUM_CLKS, ctrl->clks);
+	if (ret)
+		return ret;
+
+	dev_pm_opp_set_rate(dev, ctrl->last_speed * 4);
+
+	return 0;
 }
 
 static int __maybe_unused qcom_qspi_suspend(struct device *dev)
-- 
2.27.0.383.g050319c2ae-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms
  2020-07-07 20:16 [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Douglas Anderson
  2020-07-07 20:16 ` [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed Douglas Anderson
@ 2020-07-07 20:16 ` Douglas Anderson
  2020-07-08 17:04   ` Mark Brown
  2020-07-08  8:39 ` [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Rajendra Nayak
  2020-07-09  6:50 ` Mukesh, Savaliya
  3 siblings, 1 reply; 7+ messages in thread
From: Douglas Anderson @ 2020-07-07 20:16 UTC (permalink / raw)
  To: Mark Brown, Andy Gross, Bjorn Andersson
  Cc: mka, Akash Asthana, Rajendra Nayak, swboyd, linux-arm-msm,
	georgi.djakov, ctheegal, mkshah, Douglas Anderson, linux-kernel,
	linux-spi

In commit cff80645d6d3 ("spi: spi-qcom-qspi: Add interconnect support")
the spi_geni_runtime_suspend() and spi_geni_runtime_resume()
became a bit slower.  Measuring on my hardware I see numbers in the
hundreds of microseconds now.

Let's use autosuspend to help avoid some of the overhead.  Now if
we're doing a bunch of transfers we won't need to be constantly
chruning.

The number 250 ms for the autosuspend delay was picked a bit
arbitrarily, so if someone has measurements showing a better value we
could easily change this.

Fixes: cff80645d6d3 ("spi: spi-qcom-qspi: Add interconnect support")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
This patch could go through the SPI tree or land in the Qualcomm tree.
The patch it Fixes is currently in the Qualcomm tree so if it lands in
the main SPI tree there'd be a bit of a perf regression in the
Qualcomm tree until things merge together in mainline.

 drivers/spi/spi-qcom-qspi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi-qcom-qspi.c b/drivers/spi/spi-qcom-qspi.c
index 322b88c22a86..6c39b23222b8 100644
--- a/drivers/spi/spi-qcom-qspi.c
+++ b/drivers/spi/spi-qcom-qspi.c
@@ -553,6 +553,8 @@ static int qcom_qspi_probe(struct platform_device *pdev)
 		goto exit_probe_master_put;
 	}
 
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_autosuspend_delay(dev, 250);
 	pm_runtime_enable(dev);
 
 	ret = spi_register_master(master);
-- 
2.27.0.383.g050319c2ae-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead
  2020-07-07 20:16 [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Douglas Anderson
  2020-07-07 20:16 ` [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed Douglas Anderson
  2020-07-07 20:16 ` [PATCH 2/2] spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms Douglas Anderson
@ 2020-07-08  8:39 ` Rajendra Nayak
  2020-07-09  6:50 ` Mukesh, Savaliya
  3 siblings, 0 replies; 7+ messages in thread
From: Rajendra Nayak @ 2020-07-08  8:39 UTC (permalink / raw)
  To: Douglas Anderson, Mark Brown, Andy Gross, Bjorn Andersson
  Cc: mka, Akash Asthana, swboyd, linux-arm-msm, georgi.djakov,
	ctheegal, mkshah, linux-kernel, linux-spi


On 7/8/2020 1:46 AM, Douglas Anderson wrote:
> 
> Not to be confused with the similar series I posed for the _other_
> Qualcomm SPI controller (spi-geni-qcom) [1], this one avoids the
> overhead on the Quad SPI controller.
> 
> It's based atop the current Qualcomm tree including Rajendra's ("spi:
> spi-qcom-qspi: Use OPP API to set clk/perf state").  As discussed in
> individual patches, these could ideally land through the Qualcomm tree
> with Mark's Ack.
> 
> Measuring:
> * Before OPP / Interconnect patches reading all flash takes: ~3.4 seconds
> * After OPP / Interconnect patches reading all flash takes: ~4.7 seconds
> * After this patch reading all flash takes: ~3.3 seconds

Thanks Doug, I saw similar benefit on my setup with these patches. They do help
reduce the (unnecessary) additional overhead so it makes sense to merge these
along with the OPP/Interconnect patches in-order to avoid the regression.

Reviewed-by: Rajendra Nayak <rnayak@codeaurora.org>
Tested-by: Rajendra Nayak <rnayak@codeaurora.org>

> 
> [1] https://lore.kernel.org/r/20200702004509.2333554-1-dianders@chromium.org
> [2] https://lore.kernel.org/r/1593769293-6354-2-git-send-email-rnayak@codeaurora.org
> 
> 
> Douglas Anderson (2):
>    spi: spi-qcom-qspi: Avoid clock setting if not needed
>    spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms
> 
>   drivers/spi/spi-qcom-qspi.c | 45 ++++++++++++++++++++++++++++---------
>   1 file changed, 35 insertions(+), 10 deletions(-)
> 

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed
  2020-07-07 20:16 ` [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed Douglas Anderson
@ 2020-07-08 17:04   ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2020-07-08 17:04 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: Andy Gross, Bjorn Andersson, mka, Akash Asthana, Rajendra Nayak,
	swboyd, linux-arm-msm, georgi.djakov, ctheegal, mkshah,
	linux-kernel, linux-spi

[-- Attachment #1: Type: text/plain, Size: 253 bytes --]

On Tue, Jul 07, 2020 at 01:16:40PM -0700, Douglas Anderson wrote:
> As per recent changes to the spi-qcom-qspi, now when we set the clock
> we'll call into the interconnect framework and also call the OPP API.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms
  2020-07-07 20:16 ` [PATCH 2/2] spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms Douglas Anderson
@ 2020-07-08 17:04   ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2020-07-08 17:04 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: Andy Gross, Bjorn Andersson, mka, Akash Asthana, Rajendra Nayak,
	swboyd, linux-arm-msm, georgi.djakov, ctheegal, mkshah,
	linux-kernel, linux-spi

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

On Tue, Jul 07, 2020 at 01:16:41PM -0700, Douglas Anderson wrote:
> In commit cff80645d6d3 ("spi: spi-qcom-qspi: Add interconnect support")
> the spi_geni_runtime_suspend() and spi_geni_runtime_resume()
> became a bit slower.  Measuring on my hardware I see numbers in the
> hundreds of microseconds now.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead
  2020-07-07 20:16 [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Douglas Anderson
                   ` (2 preceding siblings ...)
  2020-07-08  8:39 ` [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Rajendra Nayak
@ 2020-07-09  6:50 ` Mukesh, Savaliya
  3 siblings, 0 replies; 7+ messages in thread
From: Mukesh, Savaliya @ 2020-07-09  6:50 UTC (permalink / raw)
  To: Douglas Anderson, Mark Brown, Andy Gross, Bjorn Andersson
  Cc: mka, Akash Asthana, Rajendra Nayak, swboyd, linux-arm-msm,
	georgi.djakov, ctheegal, mkshah, linux-kernel, linux-spi


On 7/8/2020 1:46 AM, Douglas Anderson wrote:
> Not to be confused with the similar series I posed for the _other_
> Qualcomm SPI controller (spi-geni-qcom) [1], this one avoids the
> overhead on the Quad SPI controller.
>
> It's based atop the current Qualcomm tree including Rajendra's ("spi:
> spi-qcom-qspi: Use OPP API to set clk/perf state").  As discussed in
> individual patches, these could ideally land through the Qualcomm tree
> with Mark's Ack.
>
> Measuring:
> * Before OPP / Interconnect patches reading all flash takes: ~3.4 seconds
> * After OPP / Interconnect patches reading all flash takes: ~4.7 seconds
> * After this patch reading all flash takes: ~3.3 seconds
>
> [1] https://lore.kernel.org/r/20200702004509.2333554-1-dianders@chromium.org
> [2] https://lore.kernel.org/r/1593769293-6354-2-git-send-email-rnayak@codeaurora.org
>
>
> Douglas Anderson (2):
>    spi: spi-qcom-qspi: Avoid clock setting if not needed
>    spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms
>
>   drivers/spi/spi-qcom-qspi.c | 45 ++++++++++++++++++++++++++++---------
>   1 file changed, 35 insertions(+), 10 deletions(-)

Reviewed-by: Mukesh Kumar Savaliya <msavaliy@codeaurora.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-09  6:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 20:16 [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Douglas Anderson
2020-07-07 20:16 ` [PATCH 1/2] spi: spi-qcom-qspi: Avoid clock setting if not needed Douglas Anderson
2020-07-08 17:04   ` Mark Brown
2020-07-07 20:16 ` [PATCH 2/2] spi: spi-qcom-qspi: Set an autosuspend delay of 250 ms Douglas Anderson
2020-07-08 17:04   ` Mark Brown
2020-07-08  8:39 ` [PATCH 0/2] spi: spi-qcom-qspi: Avoid some per-transfer overhead Rajendra Nayak
2020-07-09  6:50 ` Mukesh, Savaliya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).