linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: twl: optimize IRQ bit access
@ 2012-01-19 11:52 Venu Byravarasu
  2012-01-28  0:38 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Venu Byravarasu @ 2012-01-19 11:52 UTC (permalink / raw)
  To: a.zummo, rtc-linux, linux-kernel; +Cc: Venu Byravarasu

From: Venu Byravarasu <vbyravarasu@nvidia.com>

As TWL RTC driver is having a cached copy of enabled RTC interrupt bits
in variable rtc_irq_bits, that can be checked before really setting
or masking any of the interrupt bits.

Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com>
---
 drivers/rtc/rtc-twl.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index a0236a0..b1f6c8b 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -176,6 +176,10 @@ static int set_rtc_irq_bit(unsigned char bit)
 	unsigned char val;
 	int ret;
 
+	/* if the bit is set, return from here */
+	if (rtc_irq_bits & bit)
+		return 0;
+
 	val = rtc_irq_bits | bit;
 	val &= ~BIT_RTC_INTERRUPTS_REG_EVERY_M;
 	ret = twl_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
@@ -193,6 +197,10 @@ static int mask_rtc_irq_bit(unsigned char bit)
 	unsigned char val;
 	int ret;
 
+	/* if the bit is clear, return from here */
+	if (!(rtc_irq_bits & bit))
+		return 0;
+
 	val = rtc_irq_bits & ~bit;
 	ret = twl_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
 	if (ret == 0)
-- 
1.7.1.1


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

* Re: [PATCH] rtc: twl: optimize IRQ bit access
  2012-01-19 11:52 [PATCH] rtc: twl: optimize IRQ bit access Venu Byravarasu
@ 2012-01-28  0:38 ` Andrew Morton
  2012-01-30  3:17   ` Venu Byravarasu
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2012-01-28  0:38 UTC (permalink / raw)
  To: Venu Byravarasu; +Cc: a.zummo, rtc-linux, linux-kernel

On Thu, 19 Jan 2012 17:22:22 +0530
Venu Byravarasu <vbyravarasu@nvidia.com> wrote:

> From: Venu Byravarasu <vbyravarasu@nvidia.com>
> 
> As TWL RTC driver is having a cached copy of enabled RTC interrupt bits
> in variable rtc_irq_bits, that can be checked before really setting
> or masking any of the interrupt bits.
> 
> ...
>
> --- a/drivers/rtc/rtc-twl.c
> +++ b/drivers/rtc/rtc-twl.c
> @@ -176,6 +176,10 @@ static int set_rtc_irq_bit(unsigned char bit)
>  	unsigned char val;
>  	int ret;
>  
> +	/* if the bit is set, return from here */
> +	if (rtc_irq_bits & bit)
> +		return 0;
> +
>  	val = rtc_irq_bits | bit;
>  	val &= ~BIT_RTC_INTERRUPTS_REG_EVERY_M;
>  	ret = twl_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
> @@ -193,6 +197,10 @@ static int mask_rtc_irq_bit(unsigned char bit)
>  	unsigned char val;
>  	int ret;
>  
> +	/* if the bit is clear, return from here */
> +	if (!(rtc_irq_bits & bit))
> +		return 0;
> +
>  	val = rtc_irq_bits & ~bit;
>  	ret = twl_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
>  	if (ret == 0)

Are these functions called frequently enough to make this optimisation
significant?

I can see no locking protecting rtc_irq_bits from concurrent updaters. 
Is this code as racy as it appears?



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

* RE: [PATCH] rtc: twl: optimize IRQ bit access
  2012-01-28  0:38 ` Andrew Morton
@ 2012-01-30  3:17   ` Venu Byravarasu
  0 siblings, 0 replies; 3+ messages in thread
From: Venu Byravarasu @ 2012-01-30  3:17 UTC (permalink / raw)
  To: Andrew Morton; +Cc: a.zummo, rtc-linux, linux-kernel

> -----Original Message-----
> From: Andrew Morton [mailto:akpm@linux-foundation.org]
> Sent: Saturday, January 28, 2012 6:09 AM
> To: Venu Byravarasu
> Cc: a.zummo@towertech.it; rtc-linux@googlegroups.com; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH] rtc: twl: optimize IRQ bit access
> 
> Are these functions called frequently enough to make this optimisation
> significant?
I did not check how frequent these functions are called.
However, as the values are cached any way, thought of using them before doing hardware access.
> 
> I can see no locking protecting rtc_irq_bits from concurrent updaters.
> Is this code as racy as it appears?
Yes, looks like it is. Will push a separate patch to fix this issue.


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

end of thread, other threads:[~2012-01-30  3:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-19 11:52 [PATCH] rtc: twl: optimize IRQ bit access Venu Byravarasu
2012-01-28  0:38 ` Andrew Morton
2012-01-30  3:17   ` Venu Byravarasu

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).