Skip to content

Commit

Permalink
Add more debug information for ref_count inconsistencies
Browse files Browse the repository at this point in the history
Signed-off-by: Guvenc Gulce <[email protected]>
  • Loading branch information
guvenc committed Nov 5, 2024
1 parent d2f5b2c commit f14bc09
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions include/dp_refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,54 @@

#include <rte_atomic.h>
#include <rte_debug.h>
#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 {
Expand Down

0 comments on commit f14bc09

Please sign in to comment.