From f14bc09e05923d430eb365014494cb8db39c9961 Mon Sep 17 00:00:00 2001 From: Guvenc Gulce Date: Tue, 5 Nov 2024 14:41:23 +0100 Subject: [PATCH] Add more debug information for ref_count inconsistencies Signed-off-by: Guvenc Gulce --- include/dp_refcount.h | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/include/dp_refcount.h b/include/dp_refcount.h index d5f1b32b..d08b7a95 100644 --- a/include/dp_refcount.h +++ b/include/dp_refcount.h @@ -6,52 +6,54 @@ #include #include +#include "dp_log.h" #ifdef __cplusplus extern "C" { #endif + +#define DP_REF_VALIDATE(ref) \ + do { \ + if (!(ref)->valid) { \ + DPS_LOG_ERR("Invalid refcount object", _DP_LOG_INT("refcount", rte_atomic32_read(&ref->refcount))); \ + RTE_VERIFY(0); \ + } \ + } while (0) + struct dp_ref { rte_atomic32_t refcount; void (*release)(struct dp_ref *dpref); -#ifdef ENABLE_PYTEST bool valid; -#endif }; static inline void dp_ref_init(struct dp_ref *ref, void (*release)(struct dp_ref *dpref)) { rte_atomic32_set(&ref->refcount, 1); ref->release = release; -#ifdef ENABLE_PYTEST ref->valid = true; -#endif } static inline void dp_ref_inc(struct dp_ref *ref) { -#ifdef ENABLE_PYTEST - RTE_VERIFY(ref->valid); -#endif - RTE_VERIFY(rte_atomic32_read(&ref->refcount)); + DP_REF_VALIDATE(ref); rte_atomic32_add(&ref->refcount, 1); } static inline void dp_ref_dec(struct dp_ref *ref) { -#ifdef ENABLE_PYTEST - RTE_VERIFY(ref->valid); -#endif - if (rte_atomic32_dec_and_test(&ref->refcount)) + DP_REF_VALIDATE(ref); + if (rte_atomic32_dec_and_test(&ref->refcount)) { + ref->valid = false; ref->release(ref); + } } static inline bool dp_ref_dec_and_chk_freed(struct dp_ref *ref) { -#ifdef ENABLE_PYTEST - RTE_VERIFY(ref->valid); -#endif + DP_REF_VALIDATE(ref); if (rte_atomic32_dec_and_test(&ref->refcount)) { + ref->valid = false; ref->release(ref); return true; } else {