MINOR: tinfo: keep a copy of the pointer to the thread dump buffer
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Apr 2025 06:29:39 +0000 (08:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2025 15:04:35 +0000 (17:04 +0200)
Instead of using the thread dump buffer for post-mortem analysis, we'll
keep a copy of the assigned pointer whenever it's used, even for warnings
or "show threads". This will offer more opportunities to figure from a
core what happened, and will give us more freedom regarding the value of
the thread_dump_buffer itself. For example, even at the end of the dump
when the pointer is reset, the last used buffer is now preserved.

(cherry picked from commit 6d8a523d145a559d2ba4a14b46d27c73fe914c15)
[wt: dropped the doc which is not present in 3.1]
Signed-off-by: Willy Tarreau <w@1wt.eu>

include/haproxy/tinfo-t.h
src/debug.c

index 95604b0..229f0a4 100644 (file)
@@ -188,6 +188,7 @@ struct thread_ctx {
        unsigned long long out_bytes;           /* total #of bytes emitted */
        unsigned long long spliced_out_bytes;   /* total #of bytes emitted though a kernel pipe */
        struct buffer *thread_dump_buffer;      /* NULL out of dump, 0x02=to alloc, valid during a dump, |0x01 once done */
+       struct buffer *last_dump_buffer;        /* Copy of last buffer used for a dump; may be NULL or invalid; for post-mortem only */
        unsigned long long total_streams;       /* Total number of streams created on this thread */
        unsigned int stream_cnt;                /* Number of streams attached to this thread */
 
index bbefc09..8b94512 100644 (file)
@@ -317,6 +317,9 @@ void ha_thread_dump_one(int thr, int from_signal)
        unsigned long long n = now_cpu_time_thread(thr);
        int stuck = !!(ha_thread_ctx[thr].flags & TH_FL_STUCK);
 
+       /* keep a copy of the dump pointer for post-mortem analysis */
+       HA_ATOMIC_STORE(&ha_thread_ctx[thr].last_dump_buffer, buf);
+
        chunk_appendf(buf,
                      "%c%cThread %-2u: id=0x%llx act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n"
                      "     %2u/%-2u   stuck=%d prof=%d",