Merge branch 'maint-0.3.2' into release-0.3.2

This commit is contained in:
Nick Mathewson 2018-02-01 16:58:03 -05:00
commit 90716e3f9c
4 changed files with 29 additions and 12 deletions

4
changes/bug24700 Normal file
View File

@ -0,0 +1,4 @@
o Minor bugfixes (scheduler, KIST):
- Avoid adding the same channel twice in the KIST scheduler pending list
wasting CPU cycles at handling the same channel twice. Fixes bug 24700;
bugfix on 0.3.2.1-alpha.

View File

@ -951,6 +951,9 @@ channel_init(channel_t *chan)
/* Scheduler state is idle */ /* Scheduler state is idle */
chan->scheduler_state = SCHED_CHAN_IDLE; chan->scheduler_state = SCHED_CHAN_IDLE;
/* Channel is not in the scheduler heap. */
chan->sched_heap_idx = -1;
} }
/** /**

View File

@ -537,10 +537,12 @@ scheduler_channel_has_waiting_cells,(channel_t *chan))
* channels_pending. * channels_pending.
*/ */
chan->scheduler_state = SCHED_CHAN_PENDING; chan->scheduler_state = SCHED_CHAN_PENDING;
smartlist_pqueue_add(channels_pending, if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
scheduler_compare_channels, smartlist_pqueue_add(channels_pending,
offsetof(channel_t, sched_heap_idx), scheduler_compare_channels,
chan); offsetof(channel_t, sched_heap_idx),
chan);
}
log_debug(LD_SCHED, log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p went from waiting_for_cells " "Channel " U64_FORMAT " at %p went from waiting_for_cells "
"to pending", "to pending",
@ -664,10 +666,12 @@ scheduler_channel_wants_writes(channel_t *chan)
*/ */
log_debug(LD_SCHED, "chan=%" PRIu64 " became pending", log_debug(LD_SCHED, "chan=%" PRIu64 " became pending",
chan->global_identifier); chan->global_identifier);
smartlist_pqueue_add(channels_pending, if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
scheduler_compare_channels, smartlist_pqueue_add(channels_pending,
offsetof(channel_t, sched_heap_idx), scheduler_compare_channels,
chan); offsetof(channel_t, sched_heap_idx),
chan);
}
chan->scheduler_state = SCHED_CHAN_PENDING; chan->scheduler_state = SCHED_CHAN_PENDING;
log_debug(LD_SCHED, log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p went from waiting_to_write " "Channel " U64_FORMAT " at %p went from waiting_to_write "

View File

@ -689,7 +689,6 @@ kist_scheduler_run(void)
* after the scheduling loop is over. They can hopefully be taken care of * after the scheduling loop is over. They can hopefully be taken care of
* in the next scheduling round. * in the next scheduling round.
*/ */
chan->scheduler_state = SCHED_CHAN_WAITING_TO_WRITE;
if (!to_readd) { if (!to_readd) {
to_readd = smartlist_new(); to_readd = smartlist_new();
} }
@ -701,8 +700,10 @@ kist_scheduler_run(void)
/* Case 4: cells to send, and still open for writes */ /* Case 4: cells to send, and still open for writes */
chan->scheduler_state = SCHED_CHAN_PENDING; chan->scheduler_state = SCHED_CHAN_PENDING;
smartlist_pqueue_add(cp, scheduler_compare_channels, if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
offsetof(channel_t, sched_heap_idx), chan); smartlist_pqueue_add(cp, scheduler_compare_channels,
offsetof(channel_t, sched_heap_idx), chan);
}
} }
} /* End of main scheduling loop */ } /* End of main scheduling loop */
@ -722,8 +723,13 @@ kist_scheduler_run(void)
SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) { SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) {
readd_chan->scheduler_state = SCHED_CHAN_PENDING; readd_chan->scheduler_state = SCHED_CHAN_PENDING;
if (!smartlist_contains(cp, readd_chan)) { if (!smartlist_contains(cp, readd_chan)) {
smartlist_pqueue_add(cp, scheduler_compare_channels, if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
/* XXXX Note that the check above is in theory redundant with
* the smartlist_contains check. But let's make sure we're
* not messing anything up, and leave them both for now. */
smartlist_pqueue_add(cp, scheduler_compare_channels,
offsetof(channel_t, sched_heap_idx), readd_chan); offsetof(channel_t, sched_heap_idx), readd_chan);
}
} }
} SMARTLIST_FOREACH_END(readd_chan); } SMARTLIST_FOREACH_END(readd_chan);
smartlist_free(to_readd); smartlist_free(to_readd);