]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: activity: make the profiling status per thread and not global
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Apr 2019 06:57:41 +0000 (08:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Apr 2019 15:26:19 +0000 (17:26 +0200)
In order to later support automatic profiling turn on/off, we need to
have it per-thread. We're keeping the global option to know whether to
turn it or on off, but the profiling status is now set per thread. We're
updating the status in activity_count_runtime() which is called before
entering poll(). The reason is that we'll extend this with run time
measurement when deciding to automatically turn it on or off.

include/proto/activity.h
src/activity.c
src/task.c

index 098206e182b149e2fdd195360890cda47f44e85f..922f493924b97eebebcd7ef9fa22c6cf71d00aa0 100644 (file)
@@ -32,6 +32,7 @@
 #define HA_PROF_TASKS       0x00000001     /* enable per-task CPU profiling */
 
 extern unsigned int profiling;
+extern unsigned long task_profiling_mask;
 extern struct activity activity[MAX_THREADS];
 
 
@@ -67,6 +68,14 @@ static inline void activity_count_runtime()
 
        run_time = (before_poll.tv_sec - after_poll.tv_sec) * 1000000U + (before_poll.tv_usec - after_poll.tv_usec);
        swrate_add(&activity[tid].avg_loop_us, TIME_STATS_SAMPLES, run_time);
+
+       if (!(task_profiling_mask & tid_bit)) {
+               if (unlikely(profiling & HA_PROF_TASKS))
+                       _HA_ATOMIC_OR(&task_profiling_mask, tid_bit);
+       } else {
+               if (unlikely(!(profiling & HA_PROF_TASKS)))
+                       _HA_ATOMIC_AND(&task_profiling_mask, ~tid_bit);
+       }
 }
 
 
index b48f4b43b20748b0c6ecc0312fd1ff5bbf5e3ee5..eac2c10c34295f6378f1dd3a9c8dc242a6b80609 100644 (file)
@@ -24,6 +24,7 @@
 
 /* bit field of profiling options. Beware, may be modified at runtime! */
 unsigned int profiling = 0;
+unsigned long task_profiling_mask = 0;
 
 /* One struct per thread containing all collected measurements */
 struct activity activity[MAX_THREADS] __attribute__((aligned(64))) = { };
index 04476fe5aa3cf006a27504ff92c38293baebf622..27757436d7d7f2e599a4813e0242df01e5dcf3f6 100644 (file)
@@ -93,7 +93,7 @@ void __task_wakeup(struct task *t, struct eb_root *root)
                t->rq.key += offset;
        }
 
-       if (profiling & HA_PROF_TASKS)
+       if (task_profiling_mask & tid_bit)
                t->call_date = now_mono_time();
 
        eb32sc_insert(root, &t->rq, t->thread_mask);