WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Better locking strategy in serial rx interrupt handler a

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Better locking strategy in serial rx interrupt handler and getc. Release
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Mon, 30 May 2005 16:04:00 +0000
Delivery-date: Mon, 30 May 2005 17:02:16 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1595, 2005/05/30 17:04:00+01:00, kaf24@xxxxxxxxxxxxxxxxxxxx

        Better locking strategy in serial rx interrupt handler and getc. Release
        the spinlock after each loop iteration to prevent starvation of other
        cpus and of interrupt handling. Also neatly folds byte_matches() into
        serial_getc().
        Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>



 serial.c |   67 ++++++++++++++++++++++++++++-----------------------------------
 1 files changed, 30 insertions(+), 37 deletions(-)


diff -Nru a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c
--- a/xen/drivers/char/serial.c 2005-05-30 13:03:06 -04:00
+++ b/xen/drivers/char/serial.c 2005-05-30 13:03:06 -04:00
@@ -28,12 +28,14 @@
     BUG_ON(!port->driver);
     BUG_ON(!port->driver->getc);
 
-    spin_lock_irqsave(&port->lock, flags);
-
-    while ( port->driver->getc(port, &c) )
+    for ( ; ; )
     {
-        fn = NULL;
+        spin_lock_irqsave(&port->lock, flags);
+
+        if ( !port->driver->getc(port, &c) )
+            break;
 
+        fn = NULL;
         if ( port->rx != NULL )
             fn = port->rx;
         else if ( (c & 0x80) && (port->rx_hi != NULL) )
@@ -43,12 +45,12 @@
         else if ( (port->rxbufp - port->rxbufc) != RXBUFSZ )
             port->rxbuf[MASK_RXBUF_IDX(port->rxbufp++)] = c;            
 
+        spin_unlock_irqrestore(&port->lock, flags);
+
         if ( fn != NULL )
-        {
-            spin_unlock_irqrestore(&port->lock, flags);
             (*fn)(c & 0x7f, regs);
-            spin_lock_irqsave(&port->lock, flags);
-        }
+
+        cpu_relax();
     }
 
     spin_unlock_irqrestore(&port->lock, flags);
@@ -83,22 +85,6 @@
         serial_putc(handle, *s++);
 }
 
-/* Returns TRUE if given character (*pc) matches the serial handle. */
-static int byte_matches(int handle, unsigned char *pc)
-{
-    if ( !(handle & SERHND_HI) )
-    {
-        if ( !(handle & SERHND_LO) || !(*pc & 0x80) )
-            return 1;
-    }
-    else if ( *pc & 0x80 )
-    {
-        *pc &= 0x7f;
-        return 1;
-    }
-    return 0;
-}
-
 char serial_getc(int handle)
 {
     struct serial_port *port = &com[handle & SERHND_IDX];
@@ -108,21 +94,28 @@
     if ( (handle == -1) || !port->driver || !port->driver->getc )
         return '\0';
 
-    spin_lock_irqsave(&port->lock, flags);
+    do {        
+        for ( ; ; )
+        {
+            spin_lock_irqsave(&port->lock, flags);
+            
+            if ( port->rxbufp != port->rxbufc )
+            {
+                c = port->rxbuf[MASK_RXBUF_IDX(port->rxbufc++)];
+                break;
+            }
+            
+            if ( port->driver->getc(port, &c) )
+                break;
 
-    while ( port->rxbufp != port->rxbufc )
-    {
-        c = port->rxbuf[MASK_RXBUF_IDX(port->rxbufc++)];
-        if ( byte_matches(handle, &c) )
-            goto out;
-    }
-    
-    while ( !port->driver->getc(port, &c) && !byte_matches(handle, &c) )
-        continue;
+            spin_unlock_irqrestore(&port->lock, flags);
 
- out:
-    spin_unlock_irqrestore(&port->lock, flags);
-    return c;
+            cpu_relax();
+        }
+    } while ( ((handle & SERHND_LO) &&  (c & 0x80)) ||
+              ((handle & SERHND_HI) && !(c & 0x80)) );
+    
+    return c & 0x7f;
 }
 
 int serial_parse_handle(char *conf)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Better locking strategy in serial rx interrupt handler and getc. Release, BitKeeper Bot <=