1 #ifndef NDNDPDK_DPDK_MBUF_H
2 #define NDNDPDK_DPDK_MBUF_H
8 #include <rte_mbuf_dyn.h>
23 __attribute__((nonnull))
static inline TscTime
24 Mbuf_GetTimestamp(
struct rte_mbuf* m) {
29 __attribute__((nonnull))
static inline void
30 Mbuf_SetTimestamp(
struct rte_mbuf* m,
TscTime timestamp) {
35 __attribute__((nonnull))
static inline uint32_t
36 Mbuf_GetMark(
const struct rte_mbuf* m) {
40 return m->hash.fdir.hi;
44 __attribute__((nonnull))
static inline void
45 Mbuf_SetMark(
struct rte_mbuf* m, uint32_t value) {
47 m->hash.fdir.hi = value;
54 __attribute__((nonnull))
static inline void
55 Mbuf_ReadTo(
const struct rte_mbuf* m, uint32_t off, uint32_t len,
void* dst) {
56 const uint8_t* readTo = rte_pktmbuf_read(m, off, len, dst);
58 rte_memcpy(dst, readTo, len);
67 __attribute__((nonnull))
int
68 Mbuf_AsIovec(
struct rte_mbuf* m,
struct iovec* iov, uint32_t offset, uint32_t length);
85 __attribute__((nonnull))
struct rte_mbuf*
86 Mbuf_AllocRoom(
struct rte_mempool* mp,
struct iovec* iov,
int* iovcnt, uint16_t firstHeadroom,
87 uint16_t firstDataLen, uint16_t eachHeadroom, uint16_t eachDataLen, uint32_t pktLen);
95 __attribute__((nonnull))
void
104 __attribute__((nonnull, warn_unused_result))
static inline bool
105 Mbuf_Chain(
struct rte_mbuf* head,
struct rte_mbuf* lastSeg,
struct rte_mbuf* tail) {
106 if (unlikely(head->nb_segs + tail->nb_segs > RTE_MBUF_MAX_NB_SEGS)) {
107 struct rte_mbuf* mbufs[2] = {head, tail};
108 rte_pktmbuf_free_bulk(mbufs, RTE_DIM(mbufs));
112 lastSeg->next = tail;
113 head->nb_segs += tail->nb_segs;
114 head->pkt_len += tail->pkt_len;
125 __attribute__((nonnull, warn_unused_result))
static inline struct rte_mbuf*
126 Mbuf_ChainVector(
struct rte_mbuf* vec[], uint16_t count) {
127 struct rte_mbuf* head = NULL;
128 struct rte_mbuf* last = NULL;
129 for (uint16_t i = 0; i < count; ++i) {
130 struct rte_mbuf* m = vec[i];
131 if (unlikely(m == NULL)) {
137 last = rte_pktmbuf_lastseg(m);
141 struct rte_mbuf* mLast = rte_pktmbuf_lastseg(m);
142 bool ok = Mbuf_Chain(head, last, m);
145 rte_pktmbuf_free_bulk(&vec[i], count - i);
166 __attribute__((nonnull(1, 3))) static inline uint16_t
167 Mbuf_FreeSegs(struct rte_mbuf**
begin, struct rte_mbuf* end, uint32_t* pktLen) {
169 for (
struct rte_mbuf* seg = *
begin; seg != end;) {
170 struct rte_mbuf* next = seg->next;
172 *pktLen -= seg->data_len;
173 rte_pktmbuf_free_seg(seg);
185 __attribute__((nonnull))
static __rte_always_inline uint32_t
186 Mbuf_EnqueueVector(
struct rte_mbuf* vec[], uint32_t count,
struct rte_ring* ring,
bool autoFree) {
187 uint32_t nEnq = rte_ring_enqueue_burst(ring, (
void**)vec, count, NULL);
188 uint32_t nRej = count - nEnq;
189 if (autoFree && unlikely(nRej > 0)) {
190 rte_pktmbuf_free_bulk(&vec[nEnq], nRej);
struct rte_mbuf * Mbuf_AllocRoom(struct rte_mempool *mp, struct iovec *iov, int *iovcnt, uint16_t firstHeadroom, uint16_t firstDataLen, uint16_t eachHeadroom, uint16_t eachDataLen, uint32_t pktLen)
Allocate room within chained mbufs.
Definition: mbuf.c:33
bool Mbuf_RegisterDynFields()
Register mbuf dynfields.
Definition: mbuf.c:8
void Mbuf_RemainingIovec(struct spdk_iov_xfer ix, struct iovec *iov, int *iovcnt)
Recover remaining iovecs after spdk_iov_xfer_* operations.
Definition: mbuf.c:86
int Mbuf_Timestamp_DynFieldOffset_
Definition: mbuf.c:5
@ Mbuf_HasMark
mbuf.ol_flags bits to indicate MARK action was applied.
Definition: mbuf.h:13
int Mbuf_AsIovec(struct rte_mbuf *m, struct iovec *iov, uint32_t offset, uint32_t length)
Gather segments of m as iovec.
Definition: mbuf.c:14
void(* begin)(DiskStore *store, DiskStoreRequest *req, Packet *npkt, uint64_t slotID)
Definition: store.c:179
uint64_t TscTime
TSC clock time point.
Definition: tsc.h:9