Skip to content

Commit 68890e2

Browse files
diandersandersson
authored andcommitted
spi: spi-geni-qcom: Avoid clock setting if not needed
Every SPI transfer could have a different clock rate. The spi-geni-qcom controller code to deal with this was never very well optimized and has always had a lot of code plus some calls into the clk framework which, at the very least, would grab a mutex. However, until recently, the overhead wasn't _too_ much. That changed with commit 0e3b8a8 ("spi: spi-geni-qcom: Add interconnect support") we're now calling geni_icc_set_bw(), which leads to a bunch of math plus: geni_icc_set_bw() icc_set_bw() apply_constraints() qcom_icc_set() qcom_icc_bcm_voter_commit() rpmh_invalidate() rpmh_write_batch() ...and those rpmh commands can be a bit beefy if you call them too often. We already know what speed we were running at before, so if we see that nothing has changed let's avoid the whole pile of code. On my hardware, this made spi_geni_prepare_message() drop down from ~145 us down to ~14 us. NOTE: Potentially it might also make sense to add some code into the interconnect framework to avoid executing so much code when bandwidth isn't changing, but even if we did that we still want to short circuit here to save the extra math / clock calls. Acked-by: Mark Brown <[email protected]> Reviewed-by: Akash Asthana<[email protected]> Fixes: 0e3b8a8 ("spi: spi-geni-qcom: Add interconnect support") Signed-off-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/20200701174506.1.Icfdcee14649fc0a6c38e87477b28523d4e60bab3@changeid Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 8592eb9 commit 68890e2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/spi/spi-geni-qcom.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ static int geni_spi_set_clock_and_bw(struct spi_geni_master *mas,
201201
struct geni_se *se = &mas->se;
202202
int ret;
203203

204+
if (clk_hz == mas->cur_speed_hz)
205+
return 0;
206+
204207
ret = get_spi_clk_cfg(clk_hz, mas, &idx, &div);
205208
if (ret) {
206209
dev_err(mas->dev, "Err setting clk to %lu: %d\n", clk_hz, ret);
@@ -339,11 +342,9 @@ static void setup_fifo_xfer(struct spi_transfer *xfer,
339342
}
340343

341344
/* Speed and bits per word can be overridden per transfer */
342-
if (xfer->speed_hz != mas->cur_speed_hz) {
343-
ret = geni_spi_set_clock_and_bw(mas, xfer->speed_hz);
344-
if (ret)
345-
return;
346-
}
345+
ret = geni_spi_set_clock_and_bw(mas, xfer->speed_hz);
346+
if (ret)
347+
return;
347348

348349
mas->tx_rem_bytes = 0;
349350
mas->rx_rem_bytes = 0;

0 commit comments

Comments
 (0)