Skip to contentSkip to conversation

spin lock usage optimization for RTC drivers

PATCH Applied Xiaofei Tan 2 participants 8 messages Feb 3, 2021 – Feb 6, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover spin lock usage optimization for RTC drivers

Replace spin_lock_irqsave with spin_lock in hard IRQ of RTC drivers. There is no function changes, but may speed up if interrupt happen too often.

Xiaofei Tan (6):
rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: pm8xxx: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: r7301: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: tegra: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: mxc: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: mxc_v2: Replace spin_lock_irqsave with spin_lock in hard IRQ

 drivers/rtc/rtc-cmos.c   | 5 ++---
 drivers/rtc/rtc-mxc.c    | 5 ++---
 drivers/rtc/rtc-mxc_v2.c | 7 +++----
 drivers/rtc/rtc-pm8xxx.c | 9 ++++-----
 drivers/rtc/rtc-r7301.c  | 5 ++---
 drivers/rtc/rtc-tegra.c  | 6 +++---
 6 files changed, 16 insertions(+), 21 deletions(-)
Signature · 1 line
2.8.1
#1 lore raw

PATCH 1/6 rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ

It is redundant to do irqsave and irqrestore in hardIRQ context, where it has been in a irq-disabled context.

---
 drivers/rtc/rtc-cmos.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/rtc/rtc-cmos.c +2 -3
index 68a9ac6..d46f59a 100644
@@ -649,11 +649,10 @@ static struct cmos_rtc	cmos_rtc;
 
 static irqreturn_t cmos_interrupt(int irq, void *p)
 {
-	unsigned long	flags;
 	u8		irqstat;
 	u8		rtc_control;
 
-	spin_lock_irqsave(&rtc_lock, flags);
+	spin_lock(&rtc_lock);
 
 	/* When the HPET interrupt handler calls us, the interrupt
 	 * status is passed as arg1 instead of the irq number.  But
@@ -687,7 +686,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
 			hpet_mask_rtc_irq_bit(RTC_AIE);
 		CMOS_READ(RTC_INTR_FLAGS);
 	}
-	spin_unlock_irqrestore(&rtc_lock, flags);
+	spin_unlock(&rtc_lock);
 
 	if (is_intr(irqstat)) {
 		rtc_update_irq(p, 1, irqstat);
Signature · 1 line
2.8.1
#2 lore raw

PATCH 2/6 rtc: pm8xxx: Replace spin_lock_irqsave with spin_lock in hard IRQ

In reply to Xiaofei Tan

It is redundant to do irqsave and irqrestore in hardIRQ context, where it has been in a irq-disabled context.

---
 drivers/rtc/rtc-pm8xxx.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/rtc/rtc-pm8xxx.c +4 -5
index 0d9dd6f..92642aa 100644
@@ -343,16 +343,15 @@ static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
 	const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
 	unsigned int ctrl_reg;
 	int rc;
-	unsigned long irq_flags;
 
 	rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF);
 
-	spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
+	spin_lock(&rtc_dd->ctrl_reg_lock);
 
 	/* Clear the alarm enable bit */
 	rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg);
 	if (rc) {
-		spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
+		spin_unlock(&rtc_dd->ctrl_reg_lock);
 		goto rtc_alarm_handled;
 	}
 
@@ -360,13 +359,13 @@ static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
 
 	rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg);
 	if (rc) {
-		spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
+		spin_unlock(&rtc_dd->ctrl_reg_lock);
 		dev_err(rtc_dd->rtc_dev,
 			"Write to alarm control register failed\n");
 		goto rtc_alarm_handled;
 	}
 
-	spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
+	spin_unlock(&rtc_dd->ctrl_reg_lock);
 
 	/* Clear RTC alarm register */
 	rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl2, &ctrl_reg);
Signature · 1 line
2.8.1
#3 lore raw

PATCH 3/6 rtc: r7301: Replace spin_lock_irqsave with spin_lock in hard IRQ

In reply to Xiaofei Tan

It is redundant to do irqsave and irqrestore in hardIRQ context, where it has been in a irq-disabled context.

---
 drivers/rtc/rtc-r7301.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/rtc/rtc-r7301.c +2 -3
index aaf1b95..5dbaeb7 100644
@@ -320,11 +320,10 @@ static irqreturn_t rtc7301_irq_handler(int irq, void *dev_id)
 {
 	struct rtc_device *rtc = dev_id;
 	struct rtc7301_priv *priv = dev_get_drvdata(rtc->dev.parent);
-	unsigned long flags;
 	irqreturn_t ret = IRQ_NONE;
 	u8 alrm_ctrl;
 
-	spin_lock_irqsave(&priv->lock, flags);
+	spin_lock(&priv->lock);
 
 	rtc7301_select_bank(priv, 1);
 
@@ -335,7 +334,7 @@ static irqreturn_t rtc7301_irq_handler(int irq, void *dev_id)
 		rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF);
 	}
 
-	spin_unlock_irqrestore(&priv->lock, flags);
+	spin_unlock(&priv->lock);
 
 	return ret;
 }
Signature · 1 line
2.8.1
#4 lore raw

PATCH 4/6 rtc: tegra: Replace spin_lock_irqsave with spin_lock in hard IRQ

In reply to Xiaofei Tan

It is redundant to do irqsave and irqrestore in hardIRQ context, where it has been in a irq-disabled context.

---
 drivers/rtc/rtc-tegra.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/rtc-tegra.c +3 -3
index 8925015..85f7ad5 100644
@@ -232,7 +232,7 @@ static irqreturn_t tegra_rtc_irq_handler(int irq, void *data)
 {
 	struct device *dev = data;
 	struct tegra_rtc_info *info = dev_get_drvdata(dev);
-	unsigned long events = 0, flags;
+	unsigned long events = 0;
 	u32 status;
 
 	status = readl(info->base + TEGRA_RTC_REG_INTR_STATUS);
@@ -240,10 +240,10 @@ static irqreturn_t tegra_rtc_irq_handler(int irq, void *data)
 		/* clear the interrupt masks and status on any IRQ */
 		tegra_rtc_wait_while_busy(dev);
 
-		spin_lock_irqsave(&info->lock, flags);
+		spin_lock(&info->lock);
 		writel(0, info->base + TEGRA_RTC_REG_INTR_MASK);
 		writel(status, info->base + TEGRA_RTC_REG_INTR_STATUS);
-		spin_unlock_irqrestore(&info->lock, flags);
+		spin_unlock(&info->lock);
 	}
 
 	/* check if alarm */
Signature · 1 line
2.8.1
#5 lore raw

PATCH 5/6 rtc: mxc: Replace spin_lock_irqsave with spin_lock in hard IRQ

In reply to Xiaofei Tan

It is redundant to do irqsave and irqrestore in hardIRQ context, where it has been in a irq-disabled context.

---
 drivers/rtc/rtc-mxc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/rtc/rtc-mxc.c +2 -3
index 65b29b0..db57dda7 100644
@@ -189,11 +189,10 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
 	struct platform_device *pdev = dev_id;
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
-	unsigned long flags;
 	u32 status;
 	u32 events = 0;
 
-	spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
+	spin_lock(&pdata->rtc->irq_lock);
 	status = readw(ioaddr + RTC_RTCISR) & readw(ioaddr + RTC_RTCIENR);
 	/* clear interrupt sources */
 	writew(status, ioaddr + RTC_RTCISR);
@@ -209,7 +208,7 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
 		events |= (RTC_PF | RTC_IRQF);
 
 	rtc_update_irq(pdata->rtc, 1, events);
-	spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags);
+	spin_unlock(&pdata->rtc->irq_lock);
 
 	return IRQ_HANDLED;
 }
Signature · 1 line
2.8.1
#6 lore raw

PATCH 6/6 rtc: mxc_v2: Replace spin_lock_irqsave with spin_lock in hard IRQ

In reply to Xiaofei Tan

It is redundant to do irqsave and irqrestore in hardIRQ context, where it has been in a irq-disabled context.

---
 drivers/rtc/rtc-mxc_v2.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/rtc/rtc-mxc_v2.c +3 -4
index 0d73f6f..a577a74 100644
@@ -74,13 +74,12 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
 	struct device *dev = dev_id;
 	struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
 	void __iomem *ioaddr = pdata->ioaddr;
-	unsigned long flags;
 	u32 lp_status;
 	u32 lp_cr;
 
-	spin_lock_irqsave(&pdata->lock, flags);
+	spin_lock(&pdata->lock);
 	if (clk_enable(pdata->clk)) {
-		spin_unlock_irqrestore(&pdata->lock, flags);
+		spin_unlock(&pdata->lock);
 		return IRQ_NONE;
 	}
 
@@ -104,7 +103,7 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
 
 	mxc_rtc_sync_lp_locked(dev, ioaddr);
 	clk_disable(pdata->clk);
-	spin_unlock_irqrestore(&pdata->lock, flags);
+	spin_unlock(&pdata->lock);
 	return IRQ_HANDLED;
 }
 
Signature · 1 line
2.8.1
maintainer Applied
#7 lore raw
In reply to Xiaofei Tan
Quoted 12 lines · Xiaofei Tan

Replace spin_lock_irqsave with spin_lock in hard IRQ of RTC drivers. There is no function changes, but may speed up if interrupt happen too often.

Xiaofei Tan (6):
rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: pm8xxx: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: r7301: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: tegra: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: mxc: Replace spin_lock_irqsave with spin_lock in hard IRQ
rtc: mxc_v2: Replace spin_lock_irqsave with spin_lock in hard IRQ

Quoted 1 line

[...]

Applied, thanks!

[1/6] rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ

      commit: 6950d046eb6eabbc271fda416460c05f7a85698a
[2/6] rtc: pm8xxx: Replace spin_lock_irqsave with spin_lock in hard IRQ
      commit: 51317975565329ee50e52d0fffce50566b43cc2d
[3/6] rtc: r7301: Replace spin_lock_irqsave with spin_lock in hard IRQ
      commit: be3df3f85897e36163bfb764549acc69ec9b7afa
[4/6] rtc: tegra: Replace spin_lock_irqsave with spin_lock in hard IRQ
      commit: 669022c29af672205aaf53b76fd594dad2661ffe
[5/6] rtc: mxc: Replace spin_lock_irqsave with spin_lock in hard IRQ
      commit: 3f2d30184773e408c4e6f9e15c350828e482480c
[6/6] rtc: mxc_v2: Replace spin_lock_irqsave with spin_lock in hard IRQ
      commit: 0c1095d334dafda22463454b0519c926447b555e

Best regards,

Signature · 1 line
Alexandre Belloni <[email protected]>