]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Add API to start applet on a thread subset
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 16 May 2022 15:09:48 +0000 (17:09 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 May 2022 14:13:22 +0000 (16:13 +0200)
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
src/applet.c
src/conn_stream.c
src/dns.c
src/flt_spoe.c
src/hlua.c
src/http_client.c
src/peers.c
src/sink.c

index f8d180c7d6e8de28992ef3e5a5aff75cbe59604f..0bba054df737659b1f4dca7ea9d30efd06c6612e 100644 (file)
@@ -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.
  */
index e8b56c144f9c8353c8d721b1c8a1276b18596e15..3c5ffb256943d8863c34b951eb2b54a4d3b0654e 100644 (file)
@@ -31,10 +31,13 @@ DECLARE_POOL(pool_head_appctx,  "appctx",  sizeof(struct appctx));
  * appctx_free(). <applet> 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;
index a37b4637ee10bd8f2c1adb872fa62e81186bf08d..8bf9d52d86b1764329a813475da76a297f1e1659 100644 (file)
@@ -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);
index 839d613ee269f86ada8c86ef6378e32d7612e181..13bc1d76923eac2c71f3a602dd5360284d53e40f 100644 (file)
--- 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;
index 99ef7d6fd03fd3222a84f6459bc6e05c02ff1243..7d97fedd3a24e182ebdef38d124023cc1166f410 100644 (file)
@@ -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;
index 4fb5a620a27ed8309082d6443682270f0a68a071..470a6754fdbb007989364b737a8b24259cd8dfc6 100644 (file)
@@ -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;
index ac134ad8f625bbce4bafeb8ceac6b6d8a8b4cd32..53086a3aa1b037ce26772f66cc66eb651b369c87 100644 (file)
@@ -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;
index eb69155fb4de9e0529fae423b950db2d1f29ebf0..0e48004770038de5b78e55c7e543f964a9e06710 100644 (file)
@@ -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;
index 21b590e5cb06236ffcce5071e9cfd3d585c8c2f7..a8635d1c52608add201544bc6136284e7df00278 100644 (file)
@@ -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;