* [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
@ 2012-11-20 5:57 Mark Brown
[not found] ` <1353391041-28943-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2012-11-20 5:57 UTC (permalink / raw)
To: Wolfram Sang
Cc: Daniel Kurtz, Olof Johansson, Benson Leung, Doug Anderson,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown
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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
drivers/i2c/busses/i2c-s3c2410.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 31f802b..9050821 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -530,6 +530,7 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
unsigned long iicstat;
ktime_t start, now;
unsigned long delay;
+ int spins;
/* ensure the stop has been through the bus */
@@ -542,12 +543,22 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
* end of a transaction. However, really slow i2c devices can stretch
* the clock, delaying STOP generation.
*
- * As a compromise between idle detection latency for the normal, fast
- * case, and system load in the slow device case, use an exponential
- * back off in the polling loop, up to 1/10th of the total timeout,
- * then continue to poll at a constant rate up to the timeout.
+ * On slower SoCs this typically happens within a very small number of
+ * instructions so busy wait briefly to avoid scheduling overhead.
+ */
+ spins = 3;
+ do {
+ cpu_relax();
+ iicstat = readl(i2c->regs + S3C2410_IICSTAT);
+ } while ((iicstat & S3C2410_IICSTAT_START) && --spins);
+
+ /*
+ * If we do get an appreciable delay as a compromise between idle
+ * detection latency for the normal, fast case, and system load in the
+ * slow device case, use an exponential back off in the polling loop,
+ * up to 1/10th of the total timeout, then continue to poll at a
+ * constant rate up to the timeout.
*/
- iicstat = readl(i2c->regs + S3C2410_IICSTAT);
delay = 1;
while ((iicstat & S3C2410_IICSTAT_START) &&
ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
[not found] ` <1353391041-28943-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2012-11-20 9:45 ` Daniel Kurtz
[not found] ` <CAGS+omAkOwq7m_zGCYjwgrFY_jjNfWqvFqS29F5b6GBPr62UFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Kurtz @ 2012-11-20 9:45 UTC (permalink / raw)
To: Mark Brown
Cc: Wolfram Sang, Olof Johansson, Benson Leung, Doug Anderson,
Linux I2C
On Tue, Nov 20, 2012 at 1:57 PM, Mark Brown
<broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org> wrote:
> 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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
> ---
> drivers/i2c/busses/i2c-s3c2410.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
> index 31f802b..9050821 100644
> --- a/drivers/i2c/busses/i2c-s3c2410.c
> +++ b/drivers/i2c/busses/i2c-s3c2410.c
> @@ -530,6 +530,7 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
> unsigned long iicstat;
> ktime_t start, now;
> unsigned long delay;
> + int spins;
>
> /* ensure the stop has been through the bus */
>
> @@ -542,12 +543,22 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
> * end of a transaction. However, really slow i2c devices can stretch
> * the clock, delaying STOP generation.
> *
> - * As a compromise between idle detection latency for the normal, fast
> - * case, and system load in the slow device case, use an exponential
> - * back off in the polling loop, up to 1/10th of the total timeout,
> - * then continue to poll at a constant rate up to the timeout.
> + * On slower SoCs this typically happens within a very small number of
> + * instructions so busy wait briefly to avoid scheduling overhead.
> + */
> + spins = 3;
> + do {
> + cpu_relax();
> + iicstat = readl(i2c->regs + S3C2410_IICSTAT);
> + } while ((iicstat & S3C2410_IICSTAT_START) && --spins);
Can you avoid one cpu_relax() by reading IICSTAT first, and switch to
while { } instead of do { } while ()?
> +
> + /*
> + * If we do get an appreciable delay as a compromise between idle
> + * detection latency for the normal, fast case, and system load in the
> + * slow device case, use an exponential back off in the polling loop,
> + * up to 1/10th of the total timeout, then continue to poll at a
> + * constant rate up to the timeout.
> */
> - iicstat = readl(i2c->regs + S3C2410_IICSTAT);
> delay = 1;
> while ((iicstat & S3C2410_IICSTAT_START) &&
> ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) {
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
[not found] ` <CAGS+omAkOwq7m_zGCYjwgrFY_jjNfWqvFqS29F5b6GBPr62UFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2012-11-20 9:48 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2012-11-20 9:48 UTC (permalink / raw)
To: Daniel Kurtz
Cc: Wolfram Sang, Olof Johansson, Benson Leung, Doug Anderson,
Linux I2C
[-- Attachment #1: Type: text/plain, Size: 537 bytes --]
On Tue, Nov 20, 2012 at 05:45:55PM +0800, Daniel Kurtz wrote:
> On Tue, Nov 20, 2012 at 1:57 PM, Mark Brown
> > + spins = 3;
> > + do {
> > + cpu_relax();
> > + iicstat = readl(i2c->regs + S3C2410_IICSTAT);
> > + } while ((iicstat & S3C2410_IICSTAT_START) && --spins);
> Can you avoid one cpu_relax() by reading IICSTAT first, and switch to
> while { } instead of do { } while ()?
Of course. The CPUs that care about this are single core so the
cpu_relax() has no effect on them anyway.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
@ 2012-11-21 4:12 Mark Brown
[not found] ` <1353471131-23975-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2012-11-21 4:12 UTC (permalink / raw)
To: Wolfram Sang
Cc: Daniel Kurtz, Olof Johansson, Benson Leung, Doug Anderson,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown
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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
drivers/i2c/busses/i2c-s3c2410.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 31f802b..25dc3e2 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -530,6 +530,7 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
unsigned long iicstat;
ktime_t start, now;
unsigned long delay;
+ int spins;
/* ensure the stop has been through the bus */
@@ -542,12 +543,23 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
* end of a transaction. However, really slow i2c devices can stretch
* the clock, delaying STOP generation.
*
- * As a compromise between idle detection latency for the normal, fast
- * case, and system load in the slow device case, use an exponential
- * back off in the polling loop, up to 1/10th of the total timeout,
- * then continue to poll at a constant rate up to the timeout.
+ * On slower SoCs this typically happens within a very small number of
+ * instructions so busy wait briefly to avoid scheduling overhead.
*/
+ spins = 3;
iicstat = readl(i2c->regs + S3C2410_IICSTAT);
+ while ((iicstat & S3C2410_IICSTAT_START) && --spins) {
+ cpu_relax();
+ iicstat = readl(i2c->regs + S3C2410_IICSTAT);
+ }
+
+ /*
+ * If we do get an appreciable delay as a compromise between idle
+ * detection latency for the normal, fast case, and system load in the
+ * slow device case, use an exponential back off in the polling loop,
+ * up to 1/10th of the total timeout, then continue to poll at a
+ * constant rate up to the timeout.
+ */
delay = 1;
while ((iicstat & S3C2410_IICSTAT_START) &&
ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
[not found] ` <1353471131-23975-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2012-11-21 5:08 ` Olof Johansson
[not found] ` <CAOesGMhBZo6gKfzs1A954a_vaAMzy4px3TsgKE2rac_igH3sLw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-22 21:35 ` Wolfram Sang
1 sibling, 1 reply; 7+ messages in thread
From: Olof Johansson @ 2012-11-21 5:08 UTC (permalink / raw)
To: Mark Brown
Cc: Wolfram Sang, Daniel Kurtz, Olof Johansson, Benson Leung,
Doug Anderson, linux-i2c-u79uwXL29TY76Z2rM5mHXA
On Tue, Nov 20, 2012 at 8:12 PM, Mark Brown
<broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org> wrote:
> 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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
Acked-by: Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>
-Olof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
[not found] ` <CAOesGMhBZo6gKfzs1A954a_vaAMzy4px3TsgKE2rac_igH3sLw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2012-11-21 6:23 ` Daniel Kurtz
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Kurtz @ 2012-11-21 6:23 UTC (permalink / raw)
To: Olof Johansson
Cc: Mark Brown, Wolfram Sang, Olof Johansson, Benson Leung,
Doug Anderson, Linux I2C
On Wed, Nov 21, 2012 at 1:08 PM, Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org> wrote:
> On Tue, Nov 20, 2012 at 8:12 PM, Mark Brown
> <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org> wrote:
>> 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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
>
> Acked-by: Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>
Reviewed-by: Daniel Kurtz <djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>
> -Olof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads
[not found] ` <1353471131-23975-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-11-21 5:08 ` Olof Johansson
@ 2012-11-22 21:35 ` Wolfram Sang
1 sibling, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2012-11-22 21:35 UTC (permalink / raw)
To: Mark Brown
Cc: Daniel Kurtz, Olof Johansson, Benson Leung, Doug Anderson,
linux-i2c-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 1134 bytes --]
On Wed, Nov 21, 2012 at 01:12:11PM +0900, Mark Brown wrote:
> 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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
Applied to for-next, thanks everyone!
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-11-22 21:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-21 4:12 [PATCH] i2c: i2c-s3c2410: Remove recently introduced performance overheads Mark Brown
[not found] ` <1353471131-23975-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-11-21 5:08 ` Olof Johansson
[not found] ` <CAOesGMhBZo6gKfzs1A954a_vaAMzy4px3TsgKE2rac_igH3sLw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-21 6:23 ` Daniel Kurtz
2012-11-22 21:35 ` Wolfram Sang
-- strict thread matches above, loose matches on Subject: below --
2012-11-20 5:57 Mark Brown
[not found] ` <1353391041-28943-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-11-20 9:45 ` Daniel Kurtz
[not found] ` <CAGS+omAkOwq7m_zGCYjwgrFY_jjNfWqvFqS29F5b6GBPr62UFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-20 9:48 ` Mark Brown
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).