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.
This commit is contained in:
Olivier Houchard 2018-07-26 15:59:38 +02:00 committed by Willy Tarreau
parent 76e45181b2
commit 77551ee8a7
2 changed files with 12 additions and 6 deletions

View File

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

View File

@ -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 <t> in run queue at a position depending on t->nice. <t> 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);
}