From 77551ee8a733e7ef2a12691ddcd263528c2ea1e0 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 26 Jul 2018 15:59:38 +0200 Subject: [PATCH] BUG/MEDIUM: tasks: make __task_unlink_rq responsible for the rqueue size. As __task_wakeup() is responsible for increasing rqueue_local[tid]/global_rqueue_size, make __task_unlink_rq responsible for decreasing it, as process_runnable_tasks() isn't the only one that removes tasks from runqueues. --- include/proto/task.h | 12 ++++++++++-- src/task.c | 6 ++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/proto/task.h b/include/proto/task.h index 3969dc3..fe4699a 100644 --- a/include/proto/task.h +++ b/include/proto/task.h @@ -95,8 +95,11 @@ extern THREAD_LOCAL struct task *curr_task; /* task currently running or NULL */ extern THREAD_LOCAL struct eb32sc_node *rq_next; /* Next task to be potentially run */ #ifdef USE_THREAD extern struct eb_root rqueue; /* tree constituting the run queue */ +extern int global_rqueue_size; /* Number of element sin the global runqueue */ #endif + extern struct eb_root rqueue_local[MAX_THREADS]; /* tree constituting the per-thread run queue */ +extern int rqueue_size[MAX_THREADS]; /* Number of elements in the per-thread run queue */ extern struct list task_list[MAX_THREADS]; /* List of tasks to be run, mixing tasks and tasklets */ extern int task_list_size[MAX_THREADS]; /* Number of task sin the task_list */ @@ -180,9 +183,14 @@ static inline struct task *task_unlink_wq(struct task *t) static inline struct task *__task_unlink_rq(struct task *t) { HA_ATOMIC_SUB(&tasks_run_queue, 1); - eb32sc_delete(&t->rq); - if (t->state & TASK_GLOBAL) +#ifdef USE_THREAD + if (t->state & TASK_GLOBAL) { HA_ATOMIC_AND(&t->state, ~TASK_GLOBAL); + global_rqueue_size--; + } else +#endif + rqueue_size[tid]--; + eb32sc_delete(&t->rq); if (likely(t->nice)) HA_ATOMIC_SUB(&niced_tasks, 1); return t; diff --git a/src/task.c b/src/task.c index 94482ec..11255c3 100644 --- a/src/task.c +++ b/src/task.c @@ -52,10 +52,10 @@ __decl_hathreads(HA_SPINLOCK_T __attribute__((aligned(64))) wq_lock); /* spin lo static struct eb_root timers; /* sorted timers tree */ #ifdef USE_THREAD struct eb_root rqueue; /* tree constituting the run queue */ -static int global_rqueue_size; /* Number of element sin the global runqueue */ +int global_rqueue_size; /* Number of element sin the global runqueue */ #endif struct eb_root rqueue_local[MAX_THREADS]; /* tree constituting the per-thread run queue */ -static int rqueue_size[MAX_THREADS]; /* Number of elements in the per-thread run queue */ +int rqueue_size[MAX_THREADS]; /* Number of elements in the per-thread run queue */ static unsigned int rqueue_ticks; /* insertion count */ /* Puts the task in run queue at a position depending on t->nice. is @@ -297,7 +297,6 @@ void process_runnable_tasks() t = eb32sc_entry(rq_next, struct task, rq); rq_next = eb32sc_next(rq_next, tid_bit); - global_rqueue_size--; /* detach the task from the queue */ __task_unlink_rq(t); @@ -342,7 +341,6 @@ void process_runnable_tasks() /* detach the task from the queue */ __task_unlink_rq(t); - rqueue_size[tid]--; /* And add it to the local task list */ task_insert_into_tasklet_list(t); } -- 1.7.10.4