Message ID | 1528734090-220990-8-git-send-email-tiago.lam@intel.com |
---|---|
State | Superseded |
Headers | show |
Series | Support multi-segment mbufs | expand |
Please dismiss this one as it was sent by mistake. The other 07/13 patch ("dp-packet: Handle multi-seg mbufs in put_uninit().") is the correct one for the series. On 11/06/2018 17:21, Tiago Lam wrote: > The dp_packet_put*() function - dp_packet_put_uninit(), dp_packet_put() > and dp_packet_put_zeros() - are, in their current implementation, > operating on the data buffer of a dp_packet as if it were contiguous, > which in the case of multi-segment mbufs means they operate on the first > mbuf in the chain. However, in the case of dp_packet_put_uninit(), for > example, it is the data length of the last mbuf in the mbuf chain that > should be adjusted. These functions have thus been modified to support > multi-segment mbufs. > > Additionally, most of the core logic in dp_pcket_put_uninit() was moved > to a new helper function, dp_packet_put_uninit()_, to abstract the > implementation details from the API, since in the case of multi-seg > mbufs a new struct is returned that holds the mbuf and offset that > constitute the tail. For the single mbuf case a pointer to the byte that > constitute the tail still returned. > > Co-authored-by: Mark Kavanagh <mark.b.kavanagh@intel.com> > > Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com> > Signed-off-by: Tiago Lam <tiago.lam@intel.com> > --- > lib/dp-packet.c | 34 ++++++++++++++++++++++++---------- > lib/dp-packet.h | 5 +++++ > 2 files changed, 29 insertions(+), 10 deletions(-) > > diff --git a/lib/dp-packet.c b/lib/dp-packet.c > index 2aaeaae..9b97dd4 100644 > --- a/lib/dp-packet.c > +++ b/lib/dp-packet.c > @@ -321,29 +321,43 @@ dp_packet_put_uninit(struct dp_packet *b, size_t size) > void *p; > dp_packet_prealloc_tailroom(b, size); > p = dp_packet_tail(b); > +#ifdef DPDK_NETDEV > + struct rte_mbuf *mbuf; > + > + if (b->source == DPBUF_DPDK) { > + mbuf = rte_pktmbuf_lastseg(&b->mbuf); > + } else { > + mbuf = CONST_CAST(struct rte_mbuf *, &b->mbuf); > + } > + > + mbuf->data_len += size; > +#endif > dp_packet_set_size(b, dp_packet_size(b) + size); > + > return p; > } > > -/* Appends 'size' zeroed bytes to the tail end of 'b'. Data in 'b' is > - * reallocated and copied if necessary. Returns a pointer to the first byte of > - * the data's location in the dp_packet. */ > +/* Appends the 'size' bytes of data in 'p' to the tail end of 'b'. Data in 'b' > + * is reallocated and copied if necessary. Returns a pointer to the first > + * byte of the data's location in the dp_packet. */ > void * > -dp_packet_put_zeros(struct dp_packet *b, size_t size) > +dp_packet_put(struct dp_packet *b, const void *p, size_t size) > { > void *dst = dp_packet_put_uninit(b, size); > - memset(dst, 0, size); > + memcpy(dst, p, size); > + > return dst; > } > > -/* Appends the 'size' bytes of data in 'p' to the tail end of 'b'. Data in 'b' > - * is reallocated and copied if necessary. Returns a pointer to the first > - * byte of the data's location in the dp_packet. */ > +/* Appends 'size' zeroed bytes to the tail end of 'b'. Data in 'b' is > + * reallocated and copied if necessary. Returns a pointer to the first byte of > + * the data's location in the dp_packet. */ > void * > -dp_packet_put(struct dp_packet *b, const void *p, size_t size) > +dp_packet_put_zeros(struct dp_packet *b, size_t size) > { > void *dst = dp_packet_put_uninit(b, size); > - memcpy(dst, p, size); > + memset(dst, 0, size); > + > return dst; > } > > diff --git a/lib/dp-packet.h b/lib/dp-packet.h > index 21fa05e..8c0e23c 100644 > --- a/lib/dp-packet.h > +++ b/lib/dp-packet.h > @@ -83,6 +83,11 @@ struct dp_packet { > #ifdef DPDK_NETDEV > #define MBUF_BUF_END(BUF_ADDR, BUF_LEN) \ > (char *) (((char *) BUF_ADDR) + BUF_LEN) > + > +struct mbuf_tail { > + struct rte_mbuf *mbuf; > + uint16_t ofs; > +}; > #endif > > static inline void *dp_packet_data(const struct dp_packet *); >
diff --git a/lib/dp-packet.c b/lib/dp-packet.c index 2aaeaae..9b97dd4 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -321,29 +321,43 @@ dp_packet_put_uninit(struct dp_packet *b, size_t size) void *p; dp_packet_prealloc_tailroom(b, size); p = dp_packet_tail(b); +#ifdef DPDK_NETDEV + struct rte_mbuf *mbuf; + + if (b->source == DPBUF_DPDK) { + mbuf = rte_pktmbuf_lastseg(&b->mbuf); + } else { + mbuf = CONST_CAST(struct rte_mbuf *, &b->mbuf); + } + + mbuf->data_len += size; +#endif dp_packet_set_size(b, dp_packet_size(b) + size); + return p; } -/* Appends 'size' zeroed bytes to the tail end of 'b'. Data in 'b' is - * reallocated and copied if necessary. Returns a pointer to the first byte of - * the data's location in the dp_packet. */ +/* Appends the 'size' bytes of data in 'p' to the tail end of 'b'. Data in 'b' + * is reallocated and copied if necessary. Returns a pointer to the first + * byte of the data's location in the dp_packet. */ void * -dp_packet_put_zeros(struct dp_packet *b, size_t size) +dp_packet_put(struct dp_packet *b, const void *p, size_t size) { void *dst = dp_packet_put_uninit(b, size); - memset(dst, 0, size); + memcpy(dst, p, size); + return dst; } -/* Appends the 'size' bytes of data in 'p' to the tail end of 'b'. Data in 'b' - * is reallocated and copied if necessary. Returns a pointer to the first - * byte of the data's location in the dp_packet. */ +/* Appends 'size' zeroed bytes to the tail end of 'b'. Data in 'b' is + * reallocated and copied if necessary. Returns a pointer to the first byte of + * the data's location in the dp_packet. */ void * -dp_packet_put(struct dp_packet *b, const void *p, size_t size) +dp_packet_put_zeros(struct dp_packet *b, size_t size) { void *dst = dp_packet_put_uninit(b, size); - memcpy(dst, p, size); + memset(dst, 0, size); + return dst; } diff --git a/lib/dp-packet.h b/lib/dp-packet.h index 21fa05e..8c0e23c 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -83,6 +83,11 @@ struct dp_packet { #ifdef DPDK_NETDEV #define MBUF_BUF_END(BUF_ADDR, BUF_LEN) \ (char *) (((char *) BUF_ADDR) + BUF_LEN) + +struct mbuf_tail { + struct rte_mbuf *mbuf; + uint16_t ofs; +}; #endif static inline void *dp_packet_data(const struct dp_packet *);