]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: move profiling bit to per-thread
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Jun 2022 13:59:39 +0000 (15:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 14 Jun 2022 08:38:03 +0000 (10:38 +0200)
Instead of having a global mask of all the profiled threads, let's have
one flag per thread in each thread's flags. They are never accessed more
than one at a time an are better located inside the threads' contexts for
both performance and scalability.

doc/design-thoughts/thread-group.txt
include/haproxy/activity.h
include/haproxy/task.h
include/haproxy/tinfo-t.h
src/activity.c
src/debug.c
src/task.c

index 551a5518c0f61389521c771cd46fc7c851a4123c..a3b2b61f83d68073b24742b1879a1bfc23f6d857 100644 (file)
@@ -60,10 +60,11 @@ Task creation currently takes a thread mask of either tid_bit, a specific
 mask, or MAX_THREADS_MASK. How to create a task able to run anywhere
 (checks, Lua, ...) ?
 
-Profiling
+Profiling -> completed
 ---------
 There should be one task_profiling_mask per thread group. Enabling or
 disabling profiling should be made per group (possibly by iterating).
+-> not needed anymore, one flag per thread in each thread's context.
 
 Thread isolation
 ----------------
@@ -405,7 +406,7 @@ the FD, and all those with a bit in it ought to do it.
 
   - lock debugging must reproduce tgid
 
-  - task profiling must be made per-group (annoying), unless we want to add a
+  * task profiling must be made per-group (annoying), unless we want to add a
     per-thread TH_FL_* flag and have the rare places where the bit is changed
     iterate over all threads if needed. Sounds preferable overall.
 
index f0ca4eea15c42273396cfa4b1bfcd95c840f3ab5..0c5727ba9819ff479e28225d7f621d4c27f1c677 100644 (file)
@@ -26,7 +26,6 @@
 #include <haproxy/api.h>
 
 extern unsigned int profiling;
-extern unsigned long task_profiling_mask;
 extern struct activity activity[MAX_THREADS];
 extern struct sched_activity sched_activity[256];
 
index b3e054408e886d5846400fca82fe1d2828a805fe..0ad4a1c85e69b7e8c83f517e69a1559bae6e1865 100644 (file)
@@ -401,7 +401,7 @@ static inline void _tasklet_wakeup_on(struct tasklet *tl, int thr, const char *f
        tl->debug.caller_idx = !tl->debug.caller_idx;
        tl->debug.caller_file[tl->debug.caller_idx] = file;
        tl->debug.caller_line[tl->debug.caller_idx] = line;
-       if (task_profiling_mask & tid_bit)
+       if (th_ctx->flags & TH_FL_TASK_PROFILING)
                tl->call_date = now_mono_time();
 #endif
        __tasklet_wakeup_on(tl, thr);
@@ -452,7 +452,7 @@ static inline void _task_instant_wakeup(struct task *t, unsigned int f, const ch
        tl->debug.caller_idx = !tl->debug.caller_idx;
        tl->debug.caller_file[tl->debug.caller_idx] = file;
        tl->debug.caller_line[tl->debug.caller_idx] = line;
-       if (task_profiling_mask & tid_bit)
+       if (th_ctx->flags & TH_FL_TASK_PROFILING)
                tl->call_date = now_mono_time();
 #endif
        __tasklet_wakeup_on(tl, thr);
index 2c01480155afd140c9df339cb737b807a52a589c..4f3b9f629c358ca60825d6bf76012268058eab34 100644 (file)
@@ -37,6 +37,7 @@ enum {
 
 /* thread_ctx flags, for ha_thread_ctx[].flags */
 #define TH_FL_STUCK             0x00000001
+#define TH_FL_TASK_PROFILING    0x00000002
 
 /* Thread group information. This defines a base and a count of global thread
  * IDs which belong to it, and which can be looked up into thread_info/ctx. It
index 10ee65dc211b15e5218e3e2b75f155401ddb16a2..eb49169b581d1e4102ca879590f98fcd8b3eb9c4 100644 (file)
@@ -42,7 +42,6 @@ struct show_prof_ctx {
 
 /* bit field of profiling options. Beware, may be modified at runtime! */
 unsigned int profiling __read_mostly = HA_PROF_TASKS_AOFF;
-unsigned long task_profiling_mask __read_mostly = 0;
 
 /* One struct per thread containing all collected measurements */
 struct activity activity[MAX_THREADS] __attribute__((aligned(64))) = { };
@@ -384,16 +383,16 @@ void activity_count_runtime(uint32_t run_time)
         * profiling to "on" when automatic, and going back below the "down"
         * threshold switches to off. The forced modes don't check the load.
         */
-       if (!(task_profiling_mask & tid_bit)) {
+       if (!(th_ctx->flags & TH_FL_TASK_PROFILING)) {
                if (unlikely((profiling & HA_PROF_TASKS_MASK) == HA_PROF_TASKS_ON ||
                             ((profiling & HA_PROF_TASKS_MASK) == HA_PROF_TASKS_AON &&
                             swrate_avg(run_time, TIME_STATS_SAMPLES) >= up)))
-                       _HA_ATOMIC_OR(&task_profiling_mask, tid_bit);
+                       _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_TASK_PROFILING);
        } else {
                if (unlikely((profiling & HA_PROF_TASKS_MASK) == HA_PROF_TASKS_OFF ||
                             ((profiling & HA_PROF_TASKS_MASK) == HA_PROF_TASKS_AOFF &&
                             swrate_avg(run_time, TIME_STATS_SAMPLES) <= down)))
-                       _HA_ATOMIC_AND(&task_profiling_mask, ~tid_bit);
+                       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_TASK_PROFILING);
        }
 }
 
index 9a5c2946bc09f648543c8082804dbd9d3c994156..9c23d8a75c01e56f47b2daeb1e5b26a14dbe3433 100644 (file)
@@ -179,12 +179,12 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
                      ha_thread_ctx[thr].rq_total,
                      ha_thread_info[thr].tg->tgid, ha_thread_info[thr].ltid + 1,
                      stuck,
-                     !!(task_profiling_mask & thr_bit));
+                     !!(th_ctx->flags & TH_FL_TASK_PROFILING));
 
        chunk_appendf(buf,
                      " harmless=%d wantrdv=%d",
                      !!(threads_harmless_mask & thr_bit),
-                     !!(threads_want_rdv_mask & thr_bit));
+                     !!(th_ctx->flags & TH_FL_TASK_PROFILING));
 
        chunk_appendf(buf, "\n");
        chunk_appendf(buf, "             cpu_ns: poll=%llu now=%llu diff=%llu\n", p, n, n-p);
index 05a5e3cd2a0d11ce251b501ea0325631b496312f..09b8e72ff719b76318db9db36220d2142b85a646 100644 (file)
@@ -218,7 +218,7 @@ void __task_wakeup(struct task *t)
                t->rq.key += offset;
        }
 
-       if (task_profiling_mask & tid_bit)
+       if (th_ctx->flags & TH_FL_TASK_PROFILING)
                t->call_date = now_mono_time();
 
        eb32sc_insert(root, &t->rq, t->thread_mask);
@@ -562,7 +562,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                        LIST_DEL_INIT(&((struct tasklet *)t)->list);
                        __ha_barrier_store();
 
-                       if (unlikely(task_profiling_mask & tid_bit)) {
+                       if (unlikely(th_ctx->flags & TH_FL_TASK_PROFILING)) {
                                profile_entry = sched_activity_entry(sched_activity, t->process);
                                before = now_mono_time();
 #ifdef DEBUG_TASK
@@ -587,7 +587,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                                continue;
                        }
 
-                       if (unlikely(task_profiling_mask & tid_bit)) {
+                       if (unlikely(th_ctx->flags & TH_FL_TASK_PROFILING)) {
                                HA_ATOMIC_INC(&profile_entry->calls);
                                HA_ATOMIC_ADD(&profile_entry->cpu_time, now_mono_time() - before);
                        }