]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: prepare feed_post_mortem_late
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 15 Jul 2024 12:56:24 +0000 (14:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Jul 2024 12:04:41 +0000 (14:04 +0200)
Process runtime information could be very useful in post_mortem, but we have to
collect it just before calling run_poll_loop(). Like this we are sure, that
we've successfully applied all configuration parameters and what we've
collected are the latest runtime settings.

The most appropraite place to collect such information is
feed_post_mortem_late(). It's called in each thread, but puts thread info in
the post_mortem only when it's in the last thread context. As it's called
under mutex lock, other threads at this moment have to wait until
feed_post_mortem_late() and another initialization functions from
per_thread_init_list will finish. The number of threads could be large. So, to
avoid spending a lot of time under the lock, let's exit immediately from
feed_post_mortem_late(), if it wasn't called in the last thread.

src/debug.c

index 679a4e12746982dcbd0b1be41a19a9fac8e7b641..e57367c1e6dd960e64995444928821e312edc5b3 100644 (file)
@@ -2414,14 +2414,23 @@ void post_mortem_add_component(const char *name, const char *version,
 static int feed_post_mortem_late()
 {
        static int per_thread_info_collected;
+       int i;
 
-       if (HA_ATOMIC_ADD_FETCH(&per_thread_info_collected, 1) == global.nbthread) {
-               int i;
-               for (i = 0; i < global.nbthread; i++) {
-                       post_mortem.process.thread_info[i].pth_id = ha_thread_info[i].pth_id;
-                       post_mortem.process.thread_info[i].stack_top = ha_thread_info[i].stack_top;
-               }
+       if (HA_ATOMIC_ADD_FETCH(&per_thread_info_collected, 1) != global.nbthread)
+               return 1;
+
+       /* Collect thread info, only when we are in the last thread context.
+        * feed_post_mortem_late() is registered in per_thread_init_list. Each
+        * thread takes a mutex before looping over this list, so
+        * feed_post_mortem_late() will be called by each thread in exclusive
+        * manner, one by one in synchronious order. Thread unlocks mutex only
+        * after executing all init functions from this list.
+       */
+       for (i = 0; i < global.nbthread; i++) {
+               post_mortem.process.thread_info[i].pth_id = ha_thread_info[i].pth_id;
+               post_mortem.process.thread_info[i].stack_top = ha_thread_info[i].stack_top;
        }
+
        return 1;
 }