MINOR: task: replace task_set_affinity() with task_set_thread()

The latter passes a thread ID instead of a mask, making the code simpler.
This commit is contained in:
Willy Tarreau 2022-06-15 17:20:16 +02:00
parent 159e3acf5d
commit eed3911a54
5 changed files with 19 additions and 17 deletions

View File

@ -91,10 +91,12 @@ void task_queue(t)
function for local tasks or for shared tasks who have the calling
thread in their thread mask.
void task_set_affinity(t, m)
Change task <t>'s thread_mask to new value <m>. This may only be
void task_set_thread(t, id)
Change task <t>'s thread ID to new value <id>. This may only be
performed by the task itself while running. This is only used to let a
task voluntarily migrate to another thread.
task voluntarily migrate to another thread. Thread id -1 is used to
indicate "any thread". It's ignored and replaced by zero when threads
are disabled.
void tasklet_wakeup(tl)
Make sure that tasklet <tl> will wake up, that is, will execute at

View File

@ -66,7 +66,7 @@ static inline int appctx_init(struct appctx *appctx)
* eventually be created. The affinity must be set now !
*/
BUG_ON(appctx->t->tid != tid);
task_set_affinity(appctx->t, tid_bit);
task_set_thread(appctx->t, tid);
if (appctx->applet->init)
return appctx->applet->init(appctx);

View File

@ -324,22 +324,22 @@ static inline void task_queue(struct task *task)
}
}
/* change the thread affinity of a task to <thread_mask>.
/* Change the thread affinity of a task to <thr>, which may either be a valid
* thread number from 0 to nbthread-1, or a negative value to allow the task
* to run on any thread.
*
* This may only be done from within the running task itself or during its
* initialization. It will unqueue and requeue the task from the wait queue
* if it was in it. This is safe against a concurrent task_queue() call because
* task_queue() itself will unlink again if needed after taking into account
* the new thread_mask.
*/
static inline void task_set_affinity(struct task *t, unsigned long thread_mask)
static inline void task_set_thread(struct task *t, int thr)
{
int thr;
if (atleast2(thread_mask))
thr = -1;
else
thr = my_ffsl(thread_mask) - 1;
#ifndef USE_THREAD
/* no shared queue without threads */
thr = 0;
#endif
if (unlikely(task_in_wq(t))) {
task_unlink_wq(t);
t->tid = thr;

View File

@ -1118,7 +1118,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
check->state |= CHK_ST_INPROGRESS;
TRACE_STATE("init new health-check", CHK_EV_TASK_WAKE|CHK_EV_HCHK_START, check);
task_set_affinity(t, tid_bit);
task_set_thread(t, tid);
check->current_step = NULL;
@ -1217,7 +1217,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
if (LIST_INLIST(&check->buf_wait.list))
LIST_DEL_INIT(&check->buf_wait.list);
task_set_affinity(t, all_threads_mask);
task_set_thread(t, -1);
check_release_buf(check, &check->bi);
check_release_buf(check, &check->bo);
check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC);

View File

@ -525,7 +525,7 @@ struct task *process_chk_proc(struct task *t, void *context, unsigned int state)
int t_con = tick_add(now_ms, s->proxy->timeout.connect);
t->expire = tick_first(t->expire, t_con);
}
task_set_affinity(t, tid_bit);
task_set_thread(t, tid);
goto reschedule;
}
@ -588,7 +588,7 @@ struct task *process_chk_proc(struct task *t, void *context, unsigned int state)
/* a success was detected */
check_notify_success(check);
}
task_set_affinity(t, 1);
task_set_thread(t, 0);
check->state &= ~CHK_ST_INPROGRESS;
pid_list_del(check->curpid);