From 6095d57701cddd07e901bde214f066ff9c40bdda Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 16 May 2022 17:09:48 +0200 Subject: [PATCH] MINOR: applet: Add API to start applet on a thread subset In the same way than for the tasks, the applets api was changed to be able to start a new appctx on a thread subset. For now the feature is disabled. Only appctx_new_here() is working. But it will be possible to start an appctx on a specific thread or a subset via a mask. --- include/haproxy/applet.h | 17 ++++++++++++++++- src/applet.c | 7 +++++-- src/conn_stream.c | 2 +- src/dns.c | 2 +- src/flt_spoe.c | 2 +- src/hlua.c | 2 +- src/http_client.c | 2 +- src/peers.c | 2 +- src/sink.c | 2 +- 9 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index f8d180c7d6..0bba054df7 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -40,10 +40,25 @@ int appctx_buf_available(void *arg); void *applet_reserve_svcctx(struct appctx *appctx, size_t size); void appctx_shut(struct appctx *appctx); -struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp); +struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp, unsigned long thread_mask); int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buffer *input); void appctx_free_on_early_error(struct appctx *appctx); +static inline struct appctx *appctx_new_on(struct applet *applet, struct cs_endpoint *endp, uint thr) +{ + return appctx_new(applet, endp, 1UL << thr); +} + +static inline struct appctx *appctx_new_here(struct applet *applet, struct cs_endpoint *endp) +{ + return appctx_new(applet, endp, tid_bit); +} + +static inline struct appctx *appctx_new_anywhere(struct applet *applet, struct cs_endpoint *endp) +{ + return appctx_new(applet, endp, MAX_THREADS_MASK); +} + /* Helper function to call .init applet callback function, if it exists. Returns 0 * on success and -1 on error. */ diff --git a/src/applet.c b/src/applet.c index e8b56c144f..3c5ffb2569 100644 --- a/src/applet.c +++ b/src/applet.c @@ -31,10 +31,13 @@ DECLARE_POOL(pool_head_appctx, "appctx", sizeof(struct appctx)); * appctx_free(). is assigned as the applet, but it can be NULL. The * applet's task is always created on the current thread. */ -struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp) +struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp, unsigned long thread_mask) { struct appctx *appctx; + /* Disable the feature for now ! */ + BUG_ON(thread_mask != tid_bit); + appctx = pool_zalloc(pool_head_appctx); if (unlikely(!appctx)) goto fail_appctx; @@ -53,7 +56,7 @@ struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp) } appctx->endp = endp; - appctx->t = task_new_here(); + appctx->t = task_new(thread_mask); if (unlikely(!appctx->t)) goto fail_task; appctx->t->process = task_run_applet; diff --git a/src/conn_stream.c b/src/conn_stream.c index a37b4637ee..8bf9d52d86 100644 --- a/src/conn_stream.c +++ b/src/conn_stream.c @@ -476,7 +476,7 @@ struct appctx *cs_applet_create(struct conn_stream *cs, struct applet *app) DPRINTF(stderr, "registering handler %p for cs %p (was %p)\n", app, cs, cs_strm_task(cs)); - appctx = appctx_new(app, cs->endp); + appctx = appctx_new_here(app, cs->endp); if (!appctx) return NULL; cs_attach_applet(cs, appctx, appctx); diff --git a/src/dns.c b/src/dns.c index 839d613ee2..13bc1d7692 100644 --- a/src/dns.c +++ b/src/dns.c @@ -955,7 +955,7 @@ static struct appctx *dns_session_create(struct dns_session *ds) { struct appctx *appctx; - appctx = appctx_new(&dns_session_applet, NULL); + appctx = appctx_new_here(&dns_session_applet, NULL); if (!appctx) goto out_close; appctx->svcctx = (void *)ds; diff --git a/src/flt_spoe.c b/src/flt_spoe.c index 99ef7d6fd0..7d97fedd3a 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -2053,7 +2053,7 @@ spoe_create_appctx(struct spoe_config *conf) LIST_INIT(&spoe_appctx->waiting_queue); - if ((appctx = appctx_new(&spoe_applet, NULL)) == NULL) + if ((appctx = appctx_new_here(&spoe_applet, NULL)) == NULL) goto out_free_spoe_appctx; appctx->svcctx = spoe_appctx; diff --git a/src/hlua.c b/src/hlua.c index 4fb5a620a2..470a6754fd 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2999,7 +2999,7 @@ __LJMP static int hlua_socket_new(lua_State *L) lua_setmetatable(L, -2); /* Create the applet context */ - appctx = appctx_new(&update_applet, NULL); + appctx = appctx_new_here(&update_applet, NULL); if (!appctx) { hlua_pusherror(L, "socket: out of memory"); goto out_fail_conf; diff --git a/src/http_client.c b/src/http_client.c index ac134ad8f6..53086a3aa1 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -538,7 +538,7 @@ struct appctx *httpclient_start(struct httpclient *hc) /* The HTTP client will be created in the same thread as the caller, * avoiding threading issues */ - appctx = appctx_new(applet, NULL); + appctx = appctx_new_here(applet, NULL); if (!appctx) goto out; appctx->svcctx = hc; diff --git a/src/peers.c b/src/peers.c index eb69155fb4..0e48004770 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3199,7 +3199,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer peer->statuscode = PEER_SESS_SC_CONNECTCODE; peer->last_hdshk = now_ms; - appctx = appctx_new(&peer_applet, NULL); + appctx = appctx_new_here(&peer_applet, NULL); if (!appctx) goto out_close; appctx->svcctx = (void *)peer; diff --git a/src/sink.c b/src/sink.c index 21b590e5cb..a8635d1c52 100644 --- a/src/sink.c +++ b/src/sink.c @@ -673,7 +673,7 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink if (sft->srv->log_proto == SRV_LOG_PROTO_OCTET_COUNTING) applet = &sink_forward_oc_applet; - appctx = appctx_new(applet, NULL); + appctx = appctx_new_here(applet, NULL); if (!appctx) goto out_close; appctx->svcctx = (void *)sft; -- 2.39.5