]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: tasks: make __task_unlink_rq responsible for the rqueue size.
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 26 Jul 2018 13:59:38 +0000 (15:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Jul 2018 14:33:29 +0000 (16:33 +0200)
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
src/task.c

index 3969dc30ce3a6b4e7d036fefffaa59e3cd7ed1b8..fe4699ab2e1e53cfa48812cdf69ef399522b8020 100644 (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;
index 94482ecf157635e9c329590db44dbe0104a394be..11255c306a82454c8cfa4553a67f8fae8c3baac3 100644 (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);
        }