From 3ccb14d60d8768d8ba8dc029af2fe76e3801226f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 14 Jun 2022 11:18:40 +0200 Subject: [PATCH] MINOR: thread: get rid of MAX_THREADS_MASK This macro was used both for binding and for lookups. When binding tasks or FDs, using all_threads_mask instead is better as it will later be per group. For lookups, ~0UL always does the job. Thus in practice the macro was already almost not used anymore since the rest of the code could run fine with a constant of all ones there. --- doc/design-thoughts/thread-group.txt | 2 +- include/haproxy/applet.h | 2 +- include/haproxy/defaults.h | 2 -- include/haproxy/task.h | 2 +- src/check.c | 2 +- src/dns.c | 2 +- src/task.c | 8 ++++---- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/doc/design-thoughts/thread-group.txt b/doc/design-thoughts/thread-group.txt index a3b2b61f83..9d7d151aa6 100644 --- a/doc/design-thoughts/thread-group.txt +++ b/doc/design-thoughts/thread-group.txt @@ -536,7 +536,7 @@ broadcast it to any group. Right now in the code we have: - 18 calls of task_new(tid_bit) - - 18 calls of task_new(MAX_THREADS_MASK) + - 17 calls of task_new_anywhere() - 2 calls with a single bit Thus it looks like "task_new_anywhere()", "task_new_on()" and diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index eaea8d138e..84619de481 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -58,7 +58,7 @@ static inline struct appctx *appctx_new_here(struct applet *applet, struct sedes static inline struct appctx *appctx_new_anywhere(struct applet *applet, struct sedesc *sedesc) { - return appctx_new(applet, sedesc, MAX_THREADS_MASK); + return appctx_new(applet, sedesc, all_threads_mask); } /* Helper function to call .init applet callback function, if it exists. Returns 0 diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index 80b2e64313..21aae896dc 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -29,7 +29,6 @@ #ifndef USE_THREAD /* threads disabled, 1 thread max, 1 group max (note: group ids start at 1) */ #define MAX_THREADS 1 -#define MAX_THREADS_MASK 1 #define MAX_TGROUPS 1 #define MAX_THREADS_PER_GROUP 1 @@ -39,7 +38,6 @@ #ifndef MAX_THREADS #define MAX_THREADS LONGBITS #endif -#define MAX_THREADS_MASK (~0UL >> (LONGBITS - MAX_THREADS)) /* still limited to 1 group for now by default (note: group ids start at 1) */ #ifndef MAX_TGROUPS diff --git a/include/haproxy/task.h b/include/haproxy/task.h index 0ad4a1c85e..5d65013447 100644 --- a/include/haproxy/task.h +++ b/include/haproxy/task.h @@ -581,7 +581,7 @@ static inline struct task *task_new_here() */ static inline struct task *task_new_anywhere() { - return task_new(MAX_THREADS_MASK); + return task_new(all_threads_mask); } /* diff --git a/src/check.c b/src/check.c index f789959734..ada79ed557 100644 --- a/src/check.c +++ b/src/check.c @@ -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, MAX_THREADS_MASK); + task_set_affinity(t, all_threads_mask); 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); diff --git a/src/dns.c b/src/dns.c index 710cd5cb52..75949b59bf 100644 --- a/src/dns.c +++ b/src/dns.c @@ -74,7 +74,7 @@ static int dns_connect_nameserver(struct dns_nameserver *ns) /* Add the fd in the fd list and update its parameters */ dgram->t.sock.fd = fd; - fd_insert(fd, dgram, dgram_fd_handler, MAX_THREADS_MASK); + fd_insert(fd, dgram, dgram_fd_handler, all_threads_mask); fd_want_recv(fd); return 0; } diff --git a/src/task.c b/src/task.c index 09b8e72ff7..9512500614 100644 --- a/src/task.c +++ b/src/task.c @@ -902,10 +902,10 @@ void mworker_cleantasks() #ifdef USE_THREAD /* cleanup the global run queue */ - tmp_rq = eb32sc_first(&rqueue, MAX_THREADS_MASK); + tmp_rq = eb32sc_first(&rqueue, ~0UL); while (tmp_rq) { t = eb32sc_entry(tmp_rq, struct task, rq); - tmp_rq = eb32sc_next(tmp_rq, MAX_THREADS_MASK); + tmp_rq = eb32sc_next(tmp_rq, ~0UL); task_destroy(t); } /* cleanup the timers queue */ @@ -918,10 +918,10 @@ void mworker_cleantasks() #endif /* clean the per thread run queue */ for (i = 0; i < global.nbthread; i++) { - tmp_rq = eb32sc_first(&ha_thread_ctx[i].rqueue, MAX_THREADS_MASK); + tmp_rq = eb32sc_first(&ha_thread_ctx[i].rqueue, ~0UL); while (tmp_rq) { t = eb32sc_entry(tmp_rq, struct task, rq); - tmp_rq = eb32sc_next(tmp_rq, MAX_THREADS_MASK); + tmp_rq = eb32sc_next(tmp_rq, ~0UL); task_destroy(t); } /* cleanup the per thread timers queue */