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@digium.com>
Acked-by: Kinsey Moore <kmoore@digium.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Review: https://reviewboard.asterisk.org/r/940/

git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9406 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
Shaun Ruffell 2010-09-24 22:44:30 +00:00
parent 6d807c7dfc
commit d08cdac785

View File

@ -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;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 @@ 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;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,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();