Browse Source

Merge branch 'bug24700_032_01' into bug24700_033_01

David Goulet 6 years ago
parent
commit
e1a40535ea
4 changed files with 29 additions and 12 deletions
  1. 4 0
      changes/bug24700
  2. 3 0
      src/or/channel.c
  3. 12 8
      src/or/scheduler.c
  4. 10 4
      src/or/scheduler_kist.c

+ 4 - 0
changes/bug24700

@@ -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.

+ 3 - 0
src/or/channel.c

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

+ 12 - 8
src/or/scheduler.c

@@ -560,10 +560,12 @@ scheduler_channel_has_waiting_cells,(channel_t *chan))
      * channels_pending.
      */
     scheduler_set_channel_state(chan, SCHED_CHAN_PENDING);
-    smartlist_pqueue_add(channels_pending,
-                         scheduler_compare_channels,
-                         offsetof(channel_t, sched_heap_idx),
-                         chan);
+    if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+      smartlist_pqueue_add(channels_pending,
+                           scheduler_compare_channels,
+                           offsetof(channel_t, sched_heap_idx),
+                           chan);
+    }
     /* If we made a channel pending, we potentially have scheduling work to
      * do. */
     the_scheduler->schedule();
@@ -678,11 +680,13 @@ scheduler_channel_wants_writes(channel_t *chan)
     /*
      * It can write now, so it goes to channels_pending.
      */
-    smartlist_pqueue_add(channels_pending,
-                         scheduler_compare_channels,
-                         offsetof(channel_t, sched_heap_idx),
-                         chan);
     scheduler_set_channel_state(chan, SCHED_CHAN_PENDING);
+    if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+      smartlist_pqueue_add(channels_pending,
+                           scheduler_compare_channels,
+                           offsetof(channel_t, sched_heap_idx),
+                           chan);
+    }
     /* We just made a channel pending, we have scheduling work to do. */
     the_scheduler->schedule();
   } else {

+ 10 - 4
src/or/scheduler_kist.c

@@ -685,7 +685,6 @@ kist_scheduler_run(void)
        * after the scheduling loop is over. They can hopefully be taken care of
        * in the next scheduling round.
        */
-      scheduler_set_channel_state(chan, SCHED_CHAN_WAITING_TO_WRITE);
       if (!to_readd) {
         to_readd = smartlist_new();
       }
@@ -695,8 +694,10 @@ kist_scheduler_run(void)
       /* Case 4: cells to send, and still open for writes */
 
       scheduler_set_channel_state(chan, SCHED_CHAN_PENDING);
-      smartlist_pqueue_add(cp, scheduler_compare_channels,
-                           offsetof(channel_t, sched_heap_idx), chan);
+      if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+        smartlist_pqueue_add(cp, scheduler_compare_channels,
+                             offsetof(channel_t, sched_heap_idx), chan);
+      }
     }
   } /* End of main scheduling loop */
 
@@ -716,8 +717,13 @@ kist_scheduler_run(void)
     SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) {
       scheduler_set_channel_state(readd_chan, SCHED_CHAN_PENDING);
       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);
+        }
       }
     } SMARTLIST_FOREACH_END(readd_chan);
     smartlist_free(to_readd);