[svn-commits] sruffell: linux/trunk r9406 - /linux/trunk/drivers/dahdi/dahdi-base.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Sep 24 17:44:36 CDT 2010


Author: sruffell
Date: Fri Sep 24 17:44:30 2010
New Revision: 9406

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9406
Log:
dahdi: Only disable/enable interrupts once when iterating through channels.

dahdi_receive, dahdi_transmit, and dahdi_ec_span are mostly called from
interrupt context anyway, so we can save a few cycles by not saving and
restoring the interrupt flags for every channel.

On one 2.40GHz Xeon test machine, for a span with 24 channels w/o echocan
enabled with ~10000 samples:

Function        Avg Before   Avg After
======================================
dahdi_receive   2.109 us     1.547 us
dahdi_transmit  3.203 us     2.766 us
dahdi_ec_span   0.416 us     0.454 us

NOTE: The time went up slightly on dahdi_ec_span since I did not have
software echocan enabled and this change calls local_irq_save regardless
in dahdi_ec_span.  The slight increase in processing time in this case
is overshadowed by the savings in dahdi_receive and dahdi_transmit. If
echocan was enabled on all the channels there would be a time savings
in that dahdi_ec_span too.

When dahdi_receive/dahdi_transmit are called every millisecond (when
DAHDI_CHUNKSIZE == 8) this saves ~0.1% CPU time for each span.

Signed-off-by: Shaun Ruffell <sruffell at digium.com>
Acked-by: Kinsey Moore <kmoore at digium.com>
Acked-by: Russ Meyerriecks <rmeyerriecks at digium.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Review: https://reviewboard.asterisk.org/r/940/

Modified:
    linux/trunk/drivers/dahdi/dahdi-base.c

Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=9406&r1=9405&r2=9406
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Fri Sep 24 17:44:30 2010
@@ -7337,9 +7337,6 @@
 {
 	short rxlin, txlin;
 	int x;
-	unsigned long flags;
-
-	spin_lock_irqsave(&ss->lock, flags);
 
 	if (ss->readchunkpreec) {
 		/* Save a copy of the audio before the echo can has its way with it */
@@ -7405,7 +7402,6 @@
 		dahdi_kernel_fpu_end();
 #endif
 	}
-	spin_unlock_irqrestore(&ss->lock, flags);
 }
 
 /**
@@ -7421,7 +7417,10 @@
  */
 void dahdi_ec_chunk(struct dahdi_chan *ss, unsigned char *rxchunk, const unsigned char *txchunk)
 {
+	unsigned long flags;
+	spin_lock_irqsave(&ss->lock, flags);
 	__dahdi_ec_chunk(ss, rxchunk, txchunk);
+	spin_unlock_irqrestore(&ss->lock, flags);
 }
 
 /**
@@ -7435,10 +7434,16 @@
 void dahdi_ec_span(struct dahdi_span *span)
 {
 	int x;
+	unsigned long flags;
+	local_irq_save(flags);
 	for (x = 0; x < span->channels; x++) {
-		if (span->chans[x]->ec_current)
+		if (span->chans[x]->ec_current) {
+			spin_lock(&span->chans[x]->lock);
 			__dahdi_ec_chunk(span->chans[x], span->chans[x]->readchunk, span->chans[x]->writechunk);
-	}
+			spin_unlock(&span->chans[x]->lock);
+		}
+	}
+	local_irq_restore(flags);
 }
 
 /* return 0 if nothing detected, 1 if lack of tone, 2 if presence of tone */
@@ -8406,11 +8411,13 @@
 	int x,y,z;
 	unsigned long flags;
 
+	local_irq_save(flags);
+
 	for (x=0;x<span->channels;x++) {
 		struct dahdi_chan *const chan = span->chans[x];
-		spin_lock_irqsave(&chan->lock, flags);
+		spin_lock(&chan->lock);
 		if (chan->flags & DAHDI_FLAG_NOSTDTXRX) {
-			spin_unlock_irqrestore(&chan->lock, flags);
+			spin_unlock(&chan->lock);
 			continue;
 		}
 		if (chan == chan->master) {
@@ -8455,8 +8462,11 @@
 			}
 
 		}
-		spin_unlock_irqrestore(&chan->lock, flags);
-	}
+		spin_unlock(&chan->lock);
+	}
+
+	local_irq_restore(flags);
+
 	if (span->mainttimer) {
 		span->mainttimer -= DAHDI_CHUNKSIZE;
 		if (span->mainttimer <= 0) {
@@ -8700,10 +8710,12 @@
 #ifdef CONFIG_DAHDI_WATCHDOG
 	span->watchcounter--;
 #endif
+	local_irq_save(flags);
+
 	for (x=0;x<span->channels;x++) {
 		struct dahdi_chan *const chan = span->chans[x];
 		if (chan->master == chan) {
-			spin_lock_irqsave(&chan->lock, flags);
+			spin_lock(&chan->lock);
 			if (chan->nextslave) {
 				/* Must process each slave at the same time */
 				u_char data[DAHDI_CHUNKSIZE];
@@ -8772,9 +8784,11 @@
 #ifdef BUFFER_DEBUG
 			chan->statcount -= DAHDI_CHUNKSIZE;
 #endif
-			spin_unlock_irqrestore(&chan->lock, flags);
-		}
-	}
+			spin_unlock(&chan->lock);
+		}
+	}
+
+	local_irq_restore(flags);
 
 	if (span == master)
 		process_masterspan();




More information about the svn-commits mailing list