NDN-DPDK
High-Speed Named Data Networking Forwarder
Loading...
Searching...
No Matches
mbuf.h
Go to the documentation of this file.
1#ifndef NDNDPDK_DPDK_MBUF_H
2#define NDNDPDK_DPDK_MBUF_H
3
5
6#include "tsc.h"
7#include <rte_mbuf.h>
8#include <rte_mbuf_dyn.h>
9#include <rte_ring.h>
10
11enum {
13 Mbuf_HasMark = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID,
14};
15
17
19bool
21
23__attribute__((nonnull)) static inline TscTime
24Mbuf_GetTimestamp(struct rte_mbuf* m) {
25 return *RTE_MBUF_DYNFIELD(m, Mbuf_Timestamp_DynFieldOffset_, TscTime*);
26}
27
29__attribute__((nonnull)) static inline void
30Mbuf_SetTimestamp(struct rte_mbuf* m, TscTime timestamp) {
31 *RTE_MBUF_DYNFIELD(m, Mbuf_Timestamp_DynFieldOffset_, TscTime*) = timestamp;
32}
33
35__attribute__((nonnull)) static inline uint32_t
36Mbuf_GetMark(const struct rte_mbuf* m) {
37 if ((m->ol_flags & Mbuf_HasMark) != Mbuf_HasMark) {
38 return 0;
39 }
40 return m->hash.fdir.hi;
41}
42
44__attribute__((nonnull)) static inline void
45Mbuf_SetMark(struct rte_mbuf* m, uint32_t value) {
46 m->ol_flags |= Mbuf_HasMark;
47 m->hash.fdir.hi = value;
48}
49
54__attribute__((nonnull)) static inline void
55Mbuf_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);
57 if (readTo != dst) {
58 rte_memcpy(dst, readTo, len);
59 }
60}
61
67__attribute__((nonnull)) int
68Mbuf_AsIovec(struct rte_mbuf* m, struct iovec* iov, uint32_t offset, uint32_t length);
69
85__attribute__((nonnull)) struct rte_mbuf*
86Mbuf_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);
88
95__attribute__((nonnull)) void
96Mbuf_RemainingIovec(struct spdk_iov_xfer ix, struct iovec* iov, int* iovcnt);
97
104__attribute__((nonnull, warn_unused_result)) static inline bool
105Mbuf_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));
109 return false;
110 }
111
112 lastSeg->next = tail;
113 head->nb_segs += tail->nb_segs;
114 head->pkt_len += tail->pkt_len;
115 return true;
116}
117
125__attribute__((nonnull, warn_unused_result)) static inline struct rte_mbuf*
126Mbuf_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)) {
132 continue;
133 }
134
135 if (head == NULL) {
136 head = m;
137 last = rte_pktmbuf_lastseg(m);
138 continue;
139 }
140
141 struct rte_mbuf* mLast = rte_pktmbuf_lastseg(m);
142 bool ok = Mbuf_Chain(head, last, m);
143 if (unlikely(!ok)) {
144 ++i;
145 rte_pktmbuf_free_bulk(&vec[i], count - i);
146 return NULL;
147 }
148 last = mLast;
149 }
150 return head;
151}
152
166__attribute__((nonnull(1, 3))) static inline uint16_t
167Mbuf_FreeSegs(struct rte_mbuf** begin, struct rte_mbuf* end, uint32_t* pktLen) {
168 uint16_t count = 0;
169 for (struct rte_mbuf* seg = *begin; seg != end;) {
170 struct rte_mbuf* next = seg->next;
171 ++count;
172 *pktLen -= seg->data_len;
173 rte_pktmbuf_free_seg(seg);
174 seg = next;
175 }
176 *begin = end;
177 return count;
178}
179
185__attribute__((nonnull)) static __rte_always_inline uint32_t
186Mbuf_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);
191 }
192 return nRej;
193}
194
195#endif // NDNDPDK_DPDK_MBUF_H
int Mbuf_Timestamp_DynFieldOffset_
Definition mbuf.c:5
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
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
@ 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