From fbba0a3bf2dbfd86e48efe9745af9f94203d5f80 Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Awal Date: Thu, 11 May 2017 13:36:12 +0100 Subject: Added rte_ring wrapper functions to support dpdk-17.05 and older version Change-Id: I5cfcff8be275ab2a2fb4ad6a62777a8cb88f425b Signed-off-by: Mohammad Abdul Awal --- lib/Makefile | 1 + lib/libtle_l4p/Makefile | 1 + lib/libtle_l4p/misc.h | 4 +- lib/libtle_l4p/tcp_ctl.h | 6 +- lib/libtle_l4p/tcp_ofo.h | 2 +- lib/libtle_l4p/tcp_rxq.h | 2 +- lib/libtle_l4p/tcp_rxtx.c | 16 ++--- lib/libtle_l4p/tcp_stream.c | 7 +- lib/libtle_l4p/tcp_txq.h | 18 ++--- lib/libtle_l4p/udp_rxtx.c | 10 +-- lib/libtle_l4p/udp_stream.c | 6 +- lib/libtle_misc/Makefile | 35 +++++++++ lib/libtle_misc/tle_dpdk_wrapper.h | 141 +++++++++++++++++++++++++++++++++++++ 13 files changed, 214 insertions(+), 35 deletions(-) create mode 100644 lib/libtle_misc/Makefile create mode 100644 lib/libtle_misc/tle_dpdk_wrapper.h (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 201f078..6317af9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -21,6 +21,7 @@ endif include $(RTE_SDK)/mk/rte.vars.mk +DIRS-y += libtle_misc DIRS-y += libtle_dring DIRS-y += libtle_timer DIRS-y += libtle_l4p diff --git a/lib/libtle_l4p/Makefile b/lib/libtle_l4p/Makefile index c0d3e80..e1357d1 100644 --- a/lib/libtle_l4p/Makefile +++ b/lib/libtle_l4p/Makefile @@ -47,6 +47,7 @@ SYMLINK-y-include += tle_tcp.h SYMLINK-y-include += tle_udp.h # this lib dependencies +DEPDIRS-y += lib/libtle_misc DEPDIRS-y += lib/libtle_dring DEPDIRS-y += lib/libtle_timer diff --git a/lib/libtle_l4p/misc.h b/lib/libtle_l4p/misc.h index 55dca10..6450b67 100644 --- a/lib/libtle_l4p/misc.h +++ b/lib/libtle_l4p/misc.h @@ -16,6 +16,8 @@ #ifndef _MISC_H_ #define _MISC_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -402,7 +404,7 @@ empty_mbuf_ring(struct rte_ring *r) struct rte_mbuf *mb[MAX_PKT_BURST]; do { - n = rte_ring_dequeue_burst(r, (void **)mb, RTE_DIM(mb)); + n = _rte_ring_dequeue_burst(r, (void **)mb, RTE_DIM(mb)); for (i = 0; i != n; i++) rte_pktmbuf_free(mb[i]); } while (n != 0); diff --git a/lib/libtle_l4p/tcp_ctl.h b/lib/libtle_l4p/tcp_ctl.h index 8ffb924..f7e70e3 100644 --- a/lib/libtle_l4p/tcp_ctl.h +++ b/lib/libtle_l4p/tcp_ctl.h @@ -49,10 +49,10 @@ calc_rx_wnd(const struct tle_tcp_stream *s, uint32_t scale) /* peer doesn't support WSCALE option, wnd size is limited to 64K */ if (scale == TCP_WSCALE_NONE) { - wnd = s->rx.q->prod.mask << TCP_WSCALE_DEFAULT; + wnd = _rte_ring_get_mask(s->rx.q) << TCP_WSCALE_DEFAULT; return RTE_MIN(wnd, (uint32_t)UINT16_MAX); } else - return s->rx.q->prod.mask << scale; + return _rte_ring_get_mask(s->rx.q) << scale; } /* empty stream's receive queue */ @@ -74,7 +74,7 @@ empty_lq(struct tle_tcp_stream *s, struct stbl *st) struct stbl_entry *se[MAX_PKT_BURST]; do { - n = rte_ring_dequeue_burst(s->rx.q, (void **)se, RTE_DIM(se)); + n = _rte_ring_dequeue_burst(s->rx.q, (void **)se, RTE_DIM(se)); for (i = 0; i != n; i++) { mb = stbl_get_pkt(se[i]); get_pkt_info(mb, &pi, &si); diff --git a/lib/libtle_l4p/tcp_ofo.h b/lib/libtle_l4p/tcp_ofo.h index 4f3bdab..4580402 100644 --- a/lib/libtle_l4p/tcp_ofo.h +++ b/lib/libtle_l4p/tcp_ofo.h @@ -230,7 +230,7 @@ _ofodb_enqueue(struct rte_ring *r, const struct ofodb *db, union seqlen *sl) num = db->nb_elem; sl->raw = db->sl.raw; - n = rte_ring_enqueue_burst(r, (void * const *)db->obj, num); + n = _rte_ring_enqueue_burst(r, (void * const *)db->obj, num); sl->len -= tcp_mbuf_seq_free(db->obj + n, num - n); return num - n; diff --git a/lib/libtle_l4p/tcp_rxq.h b/lib/libtle_l4p/tcp_rxq.h index 90e657f..bddc28e 100644 --- a/lib/libtle_l4p/tcp_rxq.h +++ b/lib/libtle_l4p/tcp_rxq.h @@ -80,7 +80,7 @@ rx_ino_enqueue(struct tle_tcp_stream *s, union seqlen *sl, { uint32_t i, n; - n = rte_ring_enqueue_burst(s->rx.q, (void * const *)mb, num); + n = _rte_ring_enqueue_burst(s->rx.q, (void * const *)mb, num); /* error: can'queue some packets into receive buffer. */ for (i = n; i != num; i++) diff --git a/lib/libtle_l4p/tcp_rxtx.c b/lib/libtle_l4p/tcp_rxtx.c index ceaa2bc..ff39f32 100644 --- a/lib/libtle_l4p/tcp_rxtx.c +++ b/lib/libtle_l4p/tcp_rxtx.c @@ -154,14 +154,14 @@ static inline void stream_drb_free(struct tle_tcp_stream *s, struct tle_drb *drbs[], uint32_t nb_drb) { - rte_ring_enqueue_burst(s->tx.drb.r, (void **)drbs, nb_drb); + _rte_ring_enqueue_burst(s->tx.drb.r, (void **)drbs, nb_drb); } static inline uint32_t stream_drb_alloc(struct tle_tcp_stream *s, struct tle_drb *drbs[], uint32_t nb_drb) { - return rte_ring_dequeue_burst(s->tx.drb.r, (void **)drbs, nb_drb); + return _rte_ring_dequeue_burst(s->tx.drb.r, (void **)drbs, nb_drb); } static inline void @@ -939,7 +939,7 @@ rx_ack_listen(struct tle_tcp_stream *s, struct stbl *st, if (accept_prep_stream(s, st, cs, &so, tms, pi, si) == 0) { /* put new stream in the accept queue */ - if (rte_ring_enqueue_burst(s->rx.q, + if (_rte_ring_enqueue_burst(s->rx.q, (void * const *)&ts, 1) == 1) { *csp = cs; return 0; @@ -1927,7 +1927,7 @@ tle_tcp_stream_accept(struct tle_stream *ts, struct tle_stream *rs[], struct tle_tcp_stream *s; s = TCP_STREAM(ts); - n = rte_ring_mc_dequeue_burst(s->rx.q, (void **)rs, num); + n = _rte_ring_mc_dequeue_burst(s->rx.q, (void **)rs, num); if (n == 0) return 0; @@ -2138,7 +2138,7 @@ tle_tcp_stream_recv(struct tle_stream *ts, struct rte_mbuf *pkt[], uint16_t num) struct tle_tcp_stream *s; s = TCP_STREAM(ts); - n = rte_ring_mc_dequeue_burst(s->rx.q, (void **)pkt, num); + n = _rte_ring_mc_dequeue_burst(s->rx.q, (void **)pkt, num); if (n == 0) return 0; @@ -2174,7 +2174,7 @@ tx_segments(struct tle_tcp_stream *s, uint64_t ol_flags, if (i == num) { /* queue packets for further transmission. */ - rc = rte_ring_mp_enqueue_bulk(s->tx.q, (void **)segs, num); + rc = _rte_ring_mp_enqueue_bulk(s->tx.q, (void **)segs, num); if (rc != 0) free_segments(segs, num); } @@ -2228,8 +2228,8 @@ tle_tcp_stream_send(struct tle_stream *ts, struct rte_mbuf *pkt[], uint16_t num) if (i != k) { /* queue packets for further transmission. */ - n = rte_ring_mp_enqueue_burst(s->tx.q, (void **)pkt + k, - (i - k)); + n = _rte_ring_mp_enqueue_burst(s->tx.q, + (void **)pkt + k, (i - k)); k += n; /* diff --git a/lib/libtle_l4p/tcp_stream.c b/lib/libtle_l4p/tcp_stream.c index f06b2ed..af65967 100644 --- a/lib/libtle_l4p/tcp_stream.c +++ b/lib/libtle_l4p/tcp_stream.c @@ -28,7 +28,6 @@ #include "tcp_ofo.h" #include "tcp_txq.h" - static void unuse_stream(struct tle_tcp_stream *s) { @@ -81,7 +80,7 @@ alloc_ring(uint32_t n, uint32_t flags, int32_t socket) char name[RTE_RING_NAMESIZE]; n = rte_align32pow2(n); - sz = sizeof(*r) + n * sizeof(r->ring[0]); + sz = rte_ring_get_memsize(n); r = rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE, socket); if (r == NULL) { @@ -127,7 +126,7 @@ init_stream(struct tle_ctx *ctx, struct tle_tcp_stream *s) n = rte_align32pow2(k); /* size of the drbs ring */ - rsz = sizeof(*s->tx.drb.r) + n * sizeof(s->tx.drb.r->ring[0]); + rsz = rte_ring_get_memsize(n); rsz = RTE_ALIGN_CEIL(rsz, RTE_CACHE_LINE_SIZE); /* size of the drb. */ @@ -174,7 +173,7 @@ tcp_free_drbs(struct tle_stream *s, struct tle_drb *drb[], uint32_t nb_drb) struct tle_tcp_stream *us; us = (struct tle_tcp_stream *)s; - rte_ring_enqueue_burst(us->tx.drb.r, (void **)drb, nb_drb); + _rte_ring_enqueue_burst(us->tx.drb.r, (void **)drb, nb_drb); } static struct tle_timer_wheel * diff --git a/lib/libtle_l4p/tcp_txq.h b/lib/libtle_l4p/tcp_txq.h index 0b199ba..78f1d56 100644 --- a/lib/libtle_l4p/tcp_txq.h +++ b/lib/libtle_l4p/tcp_txq.h @@ -27,15 +27,15 @@ tcp_txq_get_nxt_objs(const struct tle_tcp_stream *s, uint32_t *num) struct rte_ring *r; r = s->tx.q; - sz = r->prod.size; - mask = r->prod.mask; + sz = _rte_ring_get_size(r); + mask = _rte_ring_get_mask(r); head = r->cons.head & mask; tail = r->prod.tail & mask; cnt = (tail >= head) ? tail - head : sz - head; *num = cnt; - return (struct rte_mbuf **)(r->ring + head); + return (struct rte_mbuf **)(_rte_ring_get_data(r) + head); } static inline struct rte_mbuf ** @@ -45,15 +45,15 @@ tcp_txq_get_una_objs(const struct tle_tcp_stream *s, uint32_t *num) struct rte_ring *r; r = s->tx.q; - sz = r->prod.size; - mask = r->prod.mask; + sz = _rte_ring_get_size(r); + mask = _rte_ring_get_mask(r); head = r->prod.tail & mask; tail = r->cons.tail & mask; cnt = (head >= tail) ? head - tail : sz - tail; *num = cnt; - return (struct rte_mbuf **)(r->ring + tail); + return (struct rte_mbuf **)(_rte_ring_get_data(r) + tail); } static inline void @@ -90,7 +90,7 @@ tcp_txq_nxt_cnt(struct tle_tcp_stream *s) struct rte_ring *r; r = s->tx.q; - return (r->prod.tail - r->cons.head) & r->prod.mask; + return (r->prod.tail - r->cons.head) & _rte_ring_get_mask(r); } static inline void @@ -101,7 +101,7 @@ txs_enqueue(struct tle_ctx *ctx, struct tle_tcp_stream *s) if (rte_atomic32_add_return(&s->tx.arm, 1) == 1) { r = CTX_TCP_TSQ(ctx); - n = rte_ring_enqueue_burst(r, (void * const *)&s, 1); + n = _rte_ring_enqueue_burst(r, (void * const *)&s, 1); RTE_VERIFY(n == 1); } } @@ -112,7 +112,7 @@ txs_dequeue_bulk(struct tle_ctx *ctx, struct tle_tcp_stream *s[], uint32_t num) struct rte_ring *r; r = CTX_TCP_TSQ(ctx); - return rte_ring_dequeue_burst(r, (void **)s, num); + return _rte_ring_dequeue_burst(r, (void **)s, num); } #ifdef __cplusplus diff --git a/lib/libtle_l4p/udp_rxtx.c b/lib/libtle_l4p/udp_rxtx.c index 01d3520..e6b8ded 100644 --- a/lib/libtle_l4p/udp_rxtx.c +++ b/lib/libtle_l4p/udp_rxtx.c @@ -97,7 +97,7 @@ rx_stream(struct tle_udp_stream *s, void *mb[], struct rte_mbuf *rp[], { uint32_t i, k, r; - r = rte_ring_enqueue_burst(s->rx.q, mb, num); + r = _rte_ring_enqueue_burst(s->rx.q, mb, num); /* if RX queue was empty invoke user RX notification callback. */ if (s->rx.cb.func != NULL && r != 0 && rte_ring_count(s->rx.q) == r) @@ -223,7 +223,7 @@ stream_drb_release(struct tle_udp_stream *s, struct tle_drb *drb[], uint32_t n; n = rte_ring_count(s->tx.drb.r); - rte_ring_enqueue_burst(s->tx.drb.r, (void **)drb, nb_drb); + _rte_ring_enqueue_burst(s->tx.drb.r, (void **)drb, nb_drb); /* If stream is still open, then mark it as avaialble for writing. */ if (rwl_try_acquire(&s->tx.use) > 0) { @@ -310,7 +310,7 @@ tle_udp_stream_recv(struct tle_stream *us, struct rte_mbuf *pkt[], uint16_t num) struct tle_udp_stream *s; s = UDP_STREAM(us); - n = rte_ring_mc_dequeue_burst(s->rx.q, (void **)pkt, num); + n = _rte_ring_mc_dequeue_burst(s->rx.q, (void **)pkt, num); if (n == 0) return 0; @@ -451,14 +451,14 @@ static inline void stream_drb_free(struct tle_udp_stream *s, struct tle_drb *drbs[], uint32_t nb_drb) { - rte_ring_enqueue_burst(s->tx.drb.r, (void **)drbs, nb_drb); + _rte_ring_enqueue_burst(s->tx.drb.r, (void **)drbs, nb_drb); } static inline uint32_t stream_drb_alloc(struct tle_udp_stream *s, struct tle_drb *drbs[], uint32_t nb_drb) { - return rte_ring_dequeue_burst(s->tx.drb.r, (void **)drbs, nb_drb); + return _rte_ring_dequeue_burst(s->tx.drb.r, (void **)drbs, nb_drb); } /* enqueue up to num packets to the destination device queue. */ diff --git a/lib/libtle_l4p/udp_stream.c b/lib/libtle_l4p/udp_stream.c index 9f379d9..29f5a40 100644 --- a/lib/libtle_l4p/udp_stream.c +++ b/lib/libtle_l4p/udp_stream.c @@ -69,7 +69,7 @@ init_stream(struct tle_ctx *ctx, struct tle_udp_stream *s) n = RTE_MAX(ctx->prm.max_stream_rbufs, 1U); n = rte_align32pow2(n); - sz = sizeof(*s->rx.q) + n * sizeof(s->rx.q->ring[0]); + sz = rte_ring_get_memsize(n); s->rx.q = rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE, ctx->prm.socket_id); @@ -90,7 +90,7 @@ init_stream(struct tle_ctx *ctx, struct tle_udp_stream *s) n = rte_align32pow2(k); /* size of the drbs ring */ - rsz = sizeof(*s->tx.drb.r) + n * sizeof(s->tx.drb.r->ring[0]); + rsz = rte_ring_get_memsize(n); rsz = RTE_ALIGN_CEIL(rsz, RTE_CACHE_LINE_SIZE); /* size of the drb. */ @@ -137,7 +137,7 @@ udp_free_drbs(struct tle_stream *s, struct tle_drb *drb[], uint32_t nb_drb) struct tle_udp_stream *us; us = (struct tle_udp_stream *)s; - rte_ring_enqueue_burst(us->tx.drb.r, (void **)drb, nb_drb); + _rte_ring_enqueue_burst(us->tx.drb.r, (void **)drb, nb_drb); } static int diff --git a/lib/libtle_misc/Makefile b/lib/libtle_misc/Makefile new file mode 100644 index 0000000..287d533 --- /dev/null +++ b/lib/libtle_misc/Makefile @@ -0,0 +1,35 @@ +# Copyright (c) 2017 Intel Corporation. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overwritten by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# library name +LIB = libtle_misc.a + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) + +EXPORT_MAP := tle_misc_version.map + +LIBABIVER := 1 + +SYMLINK-y-include += tle_dpdk_wrapper.h + +include $(TLDK_ROOT)/mk/tle.lib.mk diff --git a/lib/libtle_misc/tle_dpdk_wrapper.h b/lib/libtle_misc/tle_dpdk_wrapper.h new file mode 100644 index 0000000..6757663 --- /dev/null +++ b/lib/libtle_misc/tle_dpdk_wrapper.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017 Intel Corporation. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TLE_DPDK_WRAPPER_H_ +#define TLE_DPDK_WRAPPER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if RTE_VERSION >= RTE_VERSION_NUM(17, 5, 0, 0) + +static inline uint32_t +_rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, + uint32_t n) +{ + uint32_t rc; + + rc = rte_ring_mp_enqueue_bulk(r, (void * const *)obj_table, n, NULL); + if (rc == n) + return 0; + else + return -ENOSPC; +} + +static inline uint32_t +_rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table, + uint32_t n) +{ + return rte_ring_mp_enqueue_burst(r, (void * const *)obj_table, n, NULL); +} + +static inline uint32_t +_rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table, uint32_t n) +{ + return rte_ring_mc_dequeue_burst(r, (void **)obj_table, n, NULL); +} + +static inline uint32_t +_rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table, uint32_t n) +{ + return rte_ring_enqueue_burst(r, (void * const *)obj_table, n, NULL); +} + +static inline uint32_t +_rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table, uint32_t n) +{ + return rte_ring_dequeue_burst(r, (void **)obj_table, n, NULL); +} + +static inline uint32_t +_rte_ring_get_size(struct rte_ring *r) +{ + return r->size; +} + +static inline uint32_t +_rte_ring_get_mask(struct rte_ring *r) +{ + return r->mask; +} + +static inline void ** +_rte_ring_get_data(struct rte_ring *r) +{ + return (void **)(&r[1]); +} + +#else + +static inline uint32_t +_rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, + uint32_t n) +{ + return rte_ring_mp_enqueue_bulk(r, (void * const *)obj_table, n); +} + +static inline uint32_t +_rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table, + uint32_t n) +{ + return rte_ring_mp_enqueue_burst(r, (void * const *)obj_table, n); +} + +static inline uint32_t +_rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table, uint32_t n) +{ + return rte_ring_mc_dequeue_burst(r, (void **)obj_table, n); +} + +static inline uint32_t +_rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table, uint32_t n) +{ + return rte_ring_enqueue_burst(r, (void * const *)obj_table, n); +} + +static inline uint32_t +_rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table, uint32_t n) +{ + return rte_ring_dequeue_burst(r, (void **)obj_table, n); +} + +static inline uint32_t +_rte_ring_get_size(struct rte_ring *r) +{ + return r->prod.size; +} + +static inline uint32_t +_rte_ring_get_mask(struct rte_ring *r) +{ + return r->prod.mask; +} + +static inline void ** +_rte_ring_get_data(struct rte_ring *r) +{ + return (void **)r->ring; +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* TLE_DPDK_WRAPPER_H_ */ -- cgit 1.2.3-korg