From: Willy Tarreau Date: Fri, 31 Jan 2020 15:39:30 +0000 (+0100) Subject: MINOR: task: don't set TASK_RUNNING on tasklets X-Git-Tag: v2.2-dev2~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=952c2640b009537bc7cae71f47cb869cb4b132df;p=thirdparty%2Fhaproxy.git MINOR: task: don't set TASK_RUNNING on tasklets 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. --- diff --git a/src/task.c b/src/task.c index 5921c01fc9..319ae93267 100644 --- a/src/task.c +++ b/src/task.c @@ -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--;