Skip to content

Commit

Permalink
Task scheduling: Don't immediately re-run a useless task.
Browse files Browse the repository at this point in the history
If a task's fire() method returns false, then delay re-running the task
until at least one other task runs.  This may require exiting the task loop
early.  Initial measurements show that this has a strangely good effect on
runtime, possibly due to cache layout or whatever; non-task-heap
performance on the NullTask test is 2.94s.  But the intention is to improve
performance of configurations with KernelTun-type elements that do
significant work in selected(); Roberto Riggio reported a problem.

Signed-off-by: Eddie Kohler <ekohler@gmail.com>
  • Loading branch information
kohler committed May 14, 2011
1 parent 5f8e246 commit 7fbfaba
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions lib/routerthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ RouterThread::run_tasks(int ntasks)
#if HAVE_MULTITHREAD
int runs;
#endif
bool work_done;

for (; ntasks >= 0; --ntasks) {
#if HAVE_TASK_HEAP
if (_task_heap.size() == 0)
Expand All @@ -380,7 +382,7 @@ RouterThread::run_tasks(int ntasks)
t->remove_from_scheduled_list();
if (t->_status.home_thread_id != thread_id())
t->move_thread_second_half();
goto post_fire;
continue;
}

#if HAVE_MULTITHREAD
Expand All @@ -390,7 +392,7 @@ RouterThread::run_tasks(int ntasks)
#endif

t->_status.is_scheduled = false;
t->fire();
work_done = t->fire();

#if HAVE_MULTITHREAD
if (runs > PROFILE_ELEMENT) {
Expand All @@ -405,6 +407,31 @@ RouterThread::run_tasks(int ntasks)
#if HAVE_STRIDE_SCHED
t->_pass += t->_stride;
#endif

// If the task didn't do any work, don't run it next. This might
// require delaying its pass, or exiting the scheduling loop
// entirely.
if (!work_done) {
#if HAVE_STRIDE_SCHED && HAVE_TASK_HEAP
if (_task_heap.size() < 2)
break;
#else
if (t->_next == this)
break;
#endif
#if HAVE_STRIDE_SCHED
# if HAVE_TASK_HEAP
unsigned p1 = _task_heap.at_u(1).pass;
if (_task_heap.size() > 2 && PASS_GT(p1, _task_heap.at_u(2).pass))
p1 = _task_heap.at_u(2).pass;
# else
unsigned p1 = t->_next->_pass;
# endif
if (PASS_GT(p1, t->_pass))
t->_pass = p1;
#endif
}

#if HAVE_STRIDE_SCHED && HAVE_TASK_HEAP
task_reheapify_from(0, t);
#else
Expand All @@ -426,9 +453,6 @@ RouterThread::run_tasks(int ntasks)
#endif
} else
t->remove_from_scheduled_list();

post_fire:
/* do nothing */;
}
}

Expand Down

0 comments on commit 7fbfaba

Please sign in to comment.