DPDK  25.11.0
rte_mbuf_history.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2024 NVIDIA Corporation & Affiliates
3  */
4 
5 #ifndef _RTE_MBUF_HISTORY_H_
6 #define _RTE_MBUF_HISTORY_H_
7 
27 #include <rte_common.h>
28 #include <rte_debug.h>
29 
30 #include <rte_mbuf_dyn.h>
31 
32 /* Forward declaration to avoid circular dependency. */
33 struct rte_mbuf;
34 struct rte_mempool;
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 #define RTE_MBUF_HISTORY_BITS 4
44 
48 #define RTE_MBUF_HISTORY_MAX (sizeof(rte_mbuf_history_t) * 8 / RTE_MBUF_HISTORY_BITS)
49 
58  /* With ops below, mbuf is considered allocated. */
68  /* 13, reserved for future */
72 };
73 
78 
91 __rte_experimental
93 
105 static inline void rte_mbuf_history_mark(struct rte_mbuf *m, enum rte_mbuf_history_op op)
106 {
107 #ifndef RTE_MBUF_HISTORY_DEBUG
108  RTE_SET_USED(m);
109  RTE_SET_USED(op);
110 #else
111  RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
112  RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
113  if (unlikely(m == NULL))
114  return;
115 
116  rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
117  rte_mbuf_history_field_offset, rte_mbuf_history_t *);
118  uint64_t old_history = rte_atomic_load_explicit(history_field,
119  rte_memory_order_acquire);
120  uint64_t new_history;
121  do {
122  new_history = (old_history << RTE_MBUF_HISTORY_BITS) | op;
123  } while (unlikely(!rte_atomic_compare_exchange_weak_explicit(history_field,
124  &old_history, new_history,
125  rte_memory_order_release, rte_memory_order_acquire)));
126 #endif
127 }
128 
142 static inline void rte_mbuf_history_mark_bulk(struct rte_mbuf * const *mbufs,
143  unsigned int count, enum rte_mbuf_history_op op)
144 {
145 #ifndef RTE_MBUF_HISTORY_DEBUG
146  RTE_SET_USED(mbufs);
147  RTE_SET_USED(count);
148  RTE_SET_USED(op);
149 #else
150  RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
151  RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
152  if (unlikely(mbufs == NULL))
153  return;
154 
155  while (count--)
156  rte_mbuf_history_mark(*mbufs++, op);
157 #endif
158 }
159 
174 __rte_experimental
175 void rte_mbuf_history_dump(FILE *f, const struct rte_mbuf *m);
176 
188 __rte_experimental
189 void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool *mp);
190 
200 __rte_experimental
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif /* _RTE_MBUF_HISTORY_H_ */
#define unlikely(x)
#define RTE_SET_USED(x)
Definition: rte_common.h:264
#define RTE_MBUF_DYNFIELD(m, offset, type)
Definition: rte_mbuf_dyn.h:228
__rte_experimental void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool *mp)
__rte_experimental void rte_mbuf_history_dump_all(FILE *f)
__rte_experimental void rte_mbuf_history_init(void)
#define RTE_MBUF_HISTORY_BITS
rte_mbuf_history_op
@ RTE_MBUF_HISTORY_OP_TX_BUSY
@ RTE_MBUF_HISTORY_OP_NEVER
@ RTE_MBUF_HISTORY_OP_USR1
@ RTE_MBUF_HISTORY_OP_APP_ALLOC
@ RTE_MBUF_HISTORY_OP_MAX
@ RTE_MBUF_HISTORY_OP_DEQUEUE
@ RTE_MBUF_HISTORY_OP_ENQUEUE
@ RTE_MBUF_HISTORY_OP_APP_FREE
@ RTE_MBUF_HISTORY_OP_PMD_ALLOC
@ RTE_MBUF_HISTORY_OP_RX
@ RTE_MBUF_HISTORY_OP_LIB_FREE
@ RTE_MBUF_HISTORY_OP_TX
@ RTE_MBUF_HISTORY_OP_TX_PREP
@ RTE_MBUF_HISTORY_OP_PMD_FREE
@ RTE_MBUF_HISTORY_OP_USR2
@ RTE_MBUF_HISTORY_OP_LIB_ALLOC
int rte_mbuf_history_field_offset
__rte_experimental void rte_mbuf_history_dump(FILE *f, const struct rte_mbuf *m)
static void rte_mbuf_history_mark(struct rte_mbuf *m, enum rte_mbuf_history_op op)
static void rte_mbuf_history_mark_bulk(struct rte_mbuf *const *mbufs, unsigned int count, enum rte_mbuf_history_op op)