Skip to content

Commit 31f313d

Browse files
broonieWolfram Sang
authored andcommitted
i2c: s3c2410: Remove recently introduced performance overheads
The changes in "i2c-s3c2410: use exponential back off while polling for bus idle" remove the initial busy wait for I2C transfers to complete and replace it with usleep_range() calls which will schedule. Since for older SoCs I2C transfers would usually complete within an extremely small number of CPU cycles there is a win from not having to schedule. This happens because on the older SoCs the cores run at a smaller multiple of the speeds that the I2C bus is operating at; on more modern SoCs the busy wait is less likely to be effective. Fix the issue by restoring the busy wait, reducing the number of spins from 20 to 3 which covers the overwhelming majority of I2C transfers on the SoCs where the busy wait is effective. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Olof Johansson <olof@lixom.net> Reviewed-by: Daniel Kurtz <djkurtz@chromium.org> Reviewed-by: Doug Anderson <dianders@chromium.org> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
1 parent c5d5474 commit 31f313d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/i2c/busses/i2c-s3c2410.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
554554
unsigned long iicstat;
555555
ktime_t start, now;
556556
unsigned long delay;
557+
int spins;
557558

558559
/* ensure the stop has been through the bus */
559560

@@ -566,12 +567,23 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
566567
* end of a transaction. However, really slow i2c devices can stretch
567568
* the clock, delaying STOP generation.
568569
*
569-
* As a compromise between idle detection latency for the normal, fast
570-
* case, and system load in the slow device case, use an exponential
571-
* back off in the polling loop, up to 1/10th of the total timeout,
572-
* then continue to poll at a constant rate up to the timeout.
570+
* On slower SoCs this typically happens within a very small number of
571+
* instructions so busy wait briefly to avoid scheduling overhead.
573572
*/
573+
spins = 3;
574574
iicstat = readl(i2c->regs + S3C2410_IICSTAT);
575+
while ((iicstat & S3C2410_IICSTAT_START) && --spins) {
576+
cpu_relax();
577+
iicstat = readl(i2c->regs + S3C2410_IICSTAT);
578+
}
579+
580+
/*
581+
* If we do get an appreciable delay as a compromise between idle
582+
* detection latency for the normal, fast case, and system load in the
583+
* slow device case, use an exponential back off in the polling loop,
584+
* up to 1/10th of the total timeout, then continue to poll at a
585+
* constant rate up to the timeout.
586+
*/
575587
delay = 1;
576588
while ((iicstat & S3C2410_IICSTAT_START) &&
577589
ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) {

0 commit comments

Comments
 (0)