]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: set execution context on task/tasklet calls
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2026 08:33:28 +0000 (09:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 17:06:38 +0000 (18:06 +0100)
It now appears almost everywhere due to callbacks (e.g. ssl_sock_io_cb).
Muxes also become visible now on memory profiling. A small test on h1+ssl
yields 838 lines of statistics. The number of buckets should definitely
be increased, and more grouping criteria should be added.

A performance test was conducted to observe the possible effect of
setting the execution context on each task switch, and it didn't change
at all, remaining at about 1.01 billion ctxsw/s on a 128-thread EPYC.

include/haproxy/tinfo-t.h
src/task.c
src/tools.c

index 98b8762a8b31d4922002ab642a84a35c8eb4744f..bf9108cb855171349c6adbe135a8a8837e08a791 100644 (file)
@@ -87,6 +87,7 @@ enum thread_exec_ctx_type {
        TH_EX_CTX_ACTION,                   /* directly registered action function, using .action_kwl */
        TH_EX_CTX_FLT,                      /* filter whose config is in .flt_conf */
        TH_EX_CTX_MUX,                      /* mux whose mux_ops is in .mux_ops */
+       TH_EX_CTX_TASK,                     /* task or tasklet whose function is in .task */
 };
 
 struct thread_exec_ctx {
@@ -101,6 +102,7 @@ struct thread_exec_ctx {
                const struct action_kw_list *action_kwl;  /* used with TH_EX_CTX_ACTION */
                const struct flt_conf *flt_conf;  /* used with TH_EX_CTX_FLTCONF */
                const struct mux_ops *mux_ops;  /* used with TH_EX_CTX_MUX */
+               const struct task *(*task)(struct task *, void *, unsigned int); /* used with TH_EX_CTX_TASK */
        };
 };
 
index 3a3e3436fe9d2eab176c3f2a5b0765b5d6179e79..8f03b1ddadebe72ac98349e2295e0e4bfe91897a 100644 (file)
@@ -650,16 +650,19 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                if (state & TASK_F_TASKLET) {
                        /* this is a tasklet */
 
-                       t = process(t, ctx, state);
+                       t = EXEC_CTX_WITH_RET(EXEC_CTX_MAKE(TH_EX_CTX_TASK, process),
+                                             process(t, ctx, state));
                        if (t != NULL)
                                _HA_ATOMIC_AND(&t->state, ~TASK_RUNNING);
                } else {
                        /* This is a regular task */
 
                        if (process == process_stream)
-                               t = process_stream(t, ctx, state);
+                               t = EXEC_CTX_WITH_RET(EXEC_CTX_MAKE(TH_EX_CTX_TASK, process_stream),
+                                                     process_stream(t, ctx, state));
                        else
-                               t = process(t, ctx, state);
+                               t = EXEC_CTX_WITH_RET(EXEC_CTX_MAKE(TH_EX_CTX_TASK, process),
+                                                     process(t, ctx, state));
 
                        /* If there is a pending state, we have to wake up the task
                         * immediately, else we defer it into wait queue.
index 16796afcd700a6cd5e3d99dd4f8c4b1e870c35aa..e58f44c538622ccab3559854df0e04ba315fc934 100644 (file)
@@ -7548,6 +7548,10 @@ void chunk_append_thread_ctx(struct buffer *output, const struct thread_exec_ctx
        case TH_EX_CTX_MUX:
                chunk_appendf(output,"mux '%s'", ctx->mux_ops->name);
                break;
+       case TH_EX_CTX_TASK:
+               resolve_sym_name(output, "task '", ctx->task);
+               chunk_appendf(output,"'");
+               break;
        default:
                chunk_appendf(output,"other ctx %p", ctx->pointer);
                break;