mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
To: "Remy Bohmer" <linux@bohmer.net>
Cc: "Andrew Victor" <linux@maxim.org.za>,
	"ARM Linux Mailing List"
	<linux-arm-kernel@lists.arm.linux.org.uk>,
	"Russell King - ARM Linux" <linux@arm.linux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] atmel_serial: Split the interrupt handler
Date: Wed, 19 Dec 2007 13:34:11 +0100	[thread overview]
Message-ID: <20071219133411.24d146e7@dhcp-252-066.norway.atmel.com> (raw)
In-Reply-To: <3efb10970712180723x2cd22c5ei6b342f0ab7cc39c2@mail.gmail.com>

On Tue, 18 Dec 2007 16:23:11 +0100
"Remy Bohmer" <linux@bohmer.net> wrote:

> Preempt-RT now absolutely requires my (4th) IRQ_NODELAY patch, because
> the spinlock now is always inside the code, and not only in
> theexception path, and thus without my NO_DELAY patch we have a panic
> during boot.

Hmm...perhaps we can eliminate the locking in the status handler
too...? Does anyone see a problem with this patch?

diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index bce5d2a..fac37dc 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -152,6 +152,7 @@ struct atmel_uart_port {
 	struct tasklet_struct	tasklet;
 	unsigned int		irq_pending;
 	unsigned int		irq_status;
+	unsigned int		irq_status_prev;
 
 	struct circ_buf		rx_ring;
 };
@@ -585,12 +586,19 @@ atmel_handle_status(struct uart_port *port, unsigned int pending,
 {
 	struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
 
-	spin_lock(&port->lock);
-
-	atmel_port->irq_pending	|= pending;
+	/*
+	 * Try to avoid locking here since it may cause problems on
+	 * -rt. This may cause bits to re-appear in irq_pending due to
+	 * a race with atmel_tasklet_func(), but since the previous
+	 * status is tracked explicitly, this will only mean that the
+	 * tasklet will do a bit more work than strictly necessary.
+	 *
+	 * We must make sure that status is written before pending,
+	 * hence the barrier.
+	 */
 	atmel_port->irq_status	= status;
-
-	spin_unlock(&port->lock);
+	smp_mb();
+	atmel_port->irq_pending	|= pending;
 
 	tasklet_schedule(&atmel_port->tasklet);
 }
@@ -750,33 +758,32 @@ static void atmel_tasklet_func(unsigned long data)
 {
 	struct uart_port *port = (struct uart_port *)data;
 	struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
-	unsigned long flags;
 	unsigned int status;
+	unsigned int status_change;
 	unsigned int pending;
 
-	spin_lock_irqsave(&port->lock, flags);
+	pending = xchg(&atmel_port->irq_pending, 0);
 
-	if (atmel_port->irq_pending) {
-		pending = atmel_port->irq_pending;
+	if (pending) {
+		/* must read/update pending before reading status */
+		smp_mb();
 		status = atmel_port->irq_status;
-		atmel_port->irq_pending = 0;
-
-		spin_unlock_irqrestore(&port->lock, flags);
+		status_change = status ^ atmel_port->irq_status_prev;
 
 		/* TODO: All reads to CSR will clear these interrupts! */
-		if (pending & ATMEL_US_RIIC)
+		if (status_change & ATMEL_US_RI)
 			port->icount.rng++;
-		if (pending & ATMEL_US_DSRIC)
+		if (status_change & ATMEL_US_DSR)
 			port->icount.dsr++;
-		if (pending & ATMEL_US_DCDIC)
+		if (status_change & ATMEL_US_DCD)
 			uart_handle_dcd_change(port, !(status & ATMEL_US_DCD));
-		if (pending & ATMEL_US_CTSIC)
+		if (status_change & ATMEL_US_CTS)
 			uart_handle_cts_change(port, !(status & ATMEL_US_CTS));
-		if (pending & (ATMEL_US_RIIC | ATMEL_US_DSRIC
-					| ATMEL_US_DCDIC | ATMEL_US_CTSIC))
+		if (status_change & (ATMEL_US_RI | ATMEL_US_DSR
+					| ATMEL_US_DCD | ATMEL_US_CTS))
 			wake_up_interruptible(&port->info->delta_msr_wait);
-	} else {
-		spin_unlock_irqrestore(&port->lock, flags);
+
+		atmel_port->irq_status_prev = status;
 	}
 
 	if (atmel_use_dma_rx(port))

  parent reply	other threads:[~2007-12-19 12:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-18 14:14 Haavard Skinnemoen
2007-12-18 15:23 ` Remy Bohmer
2007-12-18 17:19   ` Haavard Skinnemoen
2007-12-18 19:18     ` Remy Bohmer
2007-12-19 12:34   ` Haavard Skinnemoen [this message]
2007-12-19 12:50     ` Remy Bohmer
2007-12-19 13:11       ` Haavard Skinnemoen
2007-12-19 13:18         ` Remy Bohmer
2007-12-19 13:24           ` Haavard Skinnemoen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071219133411.24d146e7@dhcp-252-066.norway.atmel.com \
    --to=hskinnemoen@atmel.com \
    --cc=linux-arm-kernel@lists.arm.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=linux@bohmer.net \
    --cc=linux@maxim.org.za \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®