]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: don't set TASK_RUNNING on tasklets
authorWilly Tarreau <w@1wt.eu>
Fri, 31 Jan 2020 15:39:30 +0000 (16:39 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 31 Jan 2020 17:37:03 +0000 (18:37 +0100)
We can't clear flags on tasklets because we don't know if they're still
present upon return (they all return NULL, maybe that could change in
the future). As a side effect, once TASK_RUNNING is set, it's never
cleared anymore, which is misleading and resulted in some incorrect
flagging of bulk tasks in the recent scheduler changes. And the only
reason for setting TASK_RUNNING on tasklets was to detect self-wakers,
which is not done using a dedicated flag. So instead of setting this
flags for no opportunity to clear it, let's simply not set it.

src/task.c

index 5921c01fc922816cec7a1468c10a66bcb348a992..319ae93267bc1a34a89af7a696eb7e9eb85439a0 100644 (file)
@@ -329,10 +329,7 @@ static int run_tasks_from_list(struct list *list, int max)
 
        while (done < max && !LIST_ISEMPTY(list)) {
                t = (struct task *)LIST_ELEM(list->n, struct tasklet *, list);
-               state = (t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING)) | TASK_RUNNING;
-               state = _HA_ATOMIC_XCHG(&t->state, state);
-               __ha_barrier_atomic_store();
-               __tasklet_remove_from_tasklet_list((struct tasklet *)t);
+               state = (t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING));
 
                ti->flags &= ~TI_FL_STUCK; // this thread is still running
                activity[tid].ctxsw++;
@@ -342,6 +339,9 @@ static int run_tasks_from_list(struct list *list, int max)
                sched->current = t;
 
                if (TASK_IS_TASKLET(t)) {
+                       state = _HA_ATOMIC_XCHG(&t->state, state);
+                       __ha_barrier_atomic_store();
+                       __tasklet_remove_from_tasklet_list((struct tasklet *)t);
                        process(NULL, ctx, state);
                        done++;
                        sched->current = NULL;
@@ -349,6 +349,10 @@ static int run_tasks_from_list(struct list *list, int max)
                        continue;
                }
 
+               state = _HA_ATOMIC_XCHG(&t->state, state | TASK_RUNNING);
+               __ha_barrier_atomic_store();
+               __tasklet_remove_from_tasklet_list((struct tasklet *)t);
+
                /* OK then this is a regular task */
 
                task_per_thread[tid].task_list_size--;