From 4df8206832c365f7fcf4123b311414d664046e24 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 29 Aug 2008 15:26:14 +0200 Subject: [PATCH] [OPTIM] reduce the number of calls to task_wakeup() A test has shown that more than 16% of the calls to task_wakeup() could be avoided because the task is already woken up. So make it inline and move the test to the inline part. --- include/proto/task.h | 8 +++++++- src/task.c | 7 ++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/proto/task.h b/include/proto/task.h index 10f6b42f6a..fbb9ee891a 100644 --- a/include/proto/task.h +++ b/include/proto/task.h @@ -41,7 +41,13 @@ extern struct task *last_timer; /* optimization: last queued timer */ int init_task(); /* puts the task in run queue , and returns */ -struct task *task_wakeup(struct task *t); +struct task *__task_wakeup(struct task *t); +static inline struct task *task_wakeup(struct task *t) +{ + if (t->state == TASK_RUNNING) + return t; + return __task_wakeup(t); +} /* removes the task from the run queue if it was in it. * returns . diff --git a/src/task.c b/src/task.c index 15539c234b..5182b8170c 100644 --- a/src/task.c +++ b/src/task.c @@ -131,11 +131,8 @@ int init_task() * size. A nice value of -1024 sets the task to -run_queue*32, while a nice * value of 1024 sets the task to run_queue*32. */ -struct task *task_wakeup(struct task *t) +struct task *__task_wakeup(struct task *t) { - if (t->state == TASK_RUNNING) - return t; - task_dequeue(t); run_queue++; @@ -231,7 +228,7 @@ void wake_expired_tasks(int *next) /* detach the task from the queue and add the task to the run queue */ eb = eb32_next(eb); - task_wakeup(task); + __task_wakeup(task); } tree = (tree + 1) & TIMER_TREE_MASK; } while (((tree - now_tree) & TIMER_TREE_MASK) < TIMER_TREES/2);