From: Willy Tarreau Date: Mon, 28 Apr 2025 07:05:02 +0000 (+0200) Subject: MINOR: threads: turn the full lock debugging to DEBUG_THREAD=2 X-Git-Tag: v3.2-dev13~67 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23371b3e7cd2a4fceb828ae50e43681cc44add66;p=thirdparty%2Fhaproxy.git MINOR: threads: turn the full lock debugging to DEBUG_THREAD=2 At level 1 it now does nothing. This is reserved for some subsequent patches which will implement lighter debugging. --- diff --git a/include/haproxy/thread-t.h b/include/haproxy/thread-t.h index 4539742b4..8eba633d0 100644 --- a/include/haproxy/thread-t.h +++ b/include/haproxy/thread-t.h @@ -98,7 +98,7 @@ /* When thread debugging is enabled, we remap HA_SPINLOCK_T and HA_RWLOCK_T to * complex structures which embed debugging info. */ -#if (DEBUG_THREAD < 1) && !defined(DEBUG_FULL) +#if (DEBUG_THREAD < 2) && !defined(DEBUG_FULL) #define HA_SPINLOCK_T __HA_SPINLOCK_T #define HA_RWLOCK_T __HA_RWLOCK_T diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index af449a6f7..f723583ab 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -305,7 +305,7 @@ static inline unsigned long thread_isolated() return _HA_ATOMIC_LOAD(&isolated_thread) == tid; } -#if (DEBUG_THREAD < 1) && !defined(DEBUG_FULL) +#if (DEBUG_THREAD < 2) && !defined(DEBUG_FULL) /* Thread debugging is DISABLED, these are the regular locking functions */ @@ -335,7 +335,7 @@ static inline unsigned long thread_isolated() #define HA_RWLOCK_TRYRDTOSK(lbl,l) (!pl_try_rtos(l)) /* R -?> S */ #define HA_RWLOCK_TRYRDTOWR(lbl, l) (!pl_try_rtow(l)) /* R -?> W */ -#else /* (DEBUG_THREAD < 1) && !defined(DEBUG_FULL) */ +#else /* (DEBUG_THREAD < 2) && !defined(DEBUG_FULL) */ /* Thread debugging is ENABLED, these are the instrumented functions */ diff --git a/src/thread.c b/src/thread.c index caaf7c25c..0bdb0f94d 100644 --- a/src/thread.c +++ b/src/thread.c @@ -260,7 +260,7 @@ void wait_for_threads_completion() for (i = 1; i < global.nbthread; i++) pthread_join(ha_pthread[i], NULL); -#if (DEBUG_THREAD > 0) || defined(DEBUG_FULL) +#if (DEBUG_THREAD > 1) || defined(DEBUG_FULL) show_lock_stats(); #endif } @@ -394,12 +394,7 @@ static int thread_cpus_enabled() #if (DEBUG_THREAD > 0) || defined(DEBUG_FULL) -struct lock_stat lock_stats_rd[LOCK_LABELS] = { }; -struct lock_stat lock_stats_sk[LOCK_LABELS] = { }; -struct lock_stat lock_stats_wr[LOCK_LABELS] = { }; - -/* this is only used below */ -static const char *lock_label(enum lock_label label) +const char *lock_label(enum lock_label label) { switch (label) { case TASK_RQ_LOCK: return "TASK_RQ"; @@ -454,6 +449,13 @@ static const char *lock_label(enum lock_label label) /* only way to come here is consecutive to an internal bug */ abort(); } +#endif + +#if (DEBUG_THREAD > 1) || defined(DEBUG_FULL) + +struct lock_stat lock_stats_rd[LOCK_LABELS] = { }; +struct lock_stat lock_stats_sk[LOCK_LABELS] = { }; +struct lock_stat lock_stats_wr[LOCK_LABELS] = { }; /* returns the num read/seek/write for a given label by summing buckets */ static uint64_t get_lock_stat_num_read(int lbl) @@ -1140,7 +1142,7 @@ void __spin_unlock(enum lock_label lbl, struct ha_spinlock *l, HA_ATOMIC_INC(&lock_stats_sk[lbl].num_unlocked); } -#endif // (DEBUG_THREAD > 0) || defined(DEBUG_FULL) +#endif // (DEBUG_THREAD > 1) || defined(DEBUG_FULL) #if defined(USE_PTHREAD_EMULATION)