From d08cdac785a52a2a279e4dbd149f4df9b03413c0 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Fri, 24 Sep 2010 22:44:30 +0000 Subject: [PATCH] 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 Acked-by: Kinsey Moore Acked-by: Russ Meyerriecks Acked-by: Tzafrir Cohen Review: https://reviewboard.asterisk.org/r/940/ git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9406 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/dahdi-base.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index 4fe9303..6e94782 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -7337,9 +7337,6 @@ static inline void __dahdi_ec_chunk(struct dahdi_chan *ss, unsigned char *rxchun { 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 @@ static inline void __dahdi_ec_chunk(struct dahdi_chan *ss, unsigned char *rxchun dahdi_kernel_fpu_end(); #endif } - spin_unlock_irqrestore(&ss->lock, flags); } /** @@ -7421,7 +7417,10 @@ static inline void __dahdi_ec_chunk(struct dahdi_chan *ss, unsigned char *rxchun */ 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_chunk(struct dahdi_chan *ss, unsigned char *rxchunk, const unsigne 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 dahdi_transmit(struct dahdi_span *span) int x,y,z; unsigned long flags; + local_irq_save(flags); + for (x=0;xchannels;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 @@ int dahdi_transmit(struct dahdi_span *span) } } - 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 @@ int dahdi_receive(struct dahdi_span *span) #ifdef CONFIG_DAHDI_WATCHDOG span->watchcounter--; #endif + local_irq_save(flags); + for (x=0;xchannels;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,10 +8784,12 @@ int dahdi_receive(struct dahdi_span *span) #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();