[2/3] linux-gen: pool: use packet pool segment size selected at runtime

Message ID 1496216614-1147-2-git-send-email-matias.elo@nokia.com
State New
Headers show
Series
  • [1/3] linux-gen: pool: combine duplicate struct pool_t members
Related show

Commit Message

Elo, Matias (Nokia - FI/Espoo) May 31, 2017, 7:43 a.m.
Use stored packet pool segment length (pool_t.seg_len) instead of a define.
This enables creating packet pools with different segment sizes.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 platform/linux-generic/odp_packet.c   | 58 +++++++++++++++++------------------
 platform/linux-generic/pktio/netmap.c |  2 +-
 2 files changed, 30 insertions(+), 30 deletions(-)

-- 
2.7.4

Patch

diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index e715970..a8d61d2 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -21,9 +21,6 @@ 
 #include <stdio.h>
 #include <inttypes.h>
 
-/* Initial packet segment data length */
-#define BASE_LEN  CONFIG_PACKET_MAX_SEG_LEN
-
 #include <odp/visibility_begin.h>
 
 /* Fill in packet header field offsets for inline functions */
@@ -244,6 +241,7 @@  void packet_parse_reset(odp_packet_hdr_t *pkt_hdr)
 static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len,
 			       int parse)
 {
+	pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl);
 	uint32_t seg_len;
 	int num = pkt_hdr->buf_hdr.segcount;
 
@@ -251,7 +249,7 @@  static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len,
 		seg_len = len;
 		pkt_hdr->buf_hdr.seg[0].len = len;
 	} else {
-		seg_len = len - ((num - 1) * CONFIG_PACKET_MAX_SEG_LEN);
+		seg_len = len - ((num - 1) * pool->seg_len);
 
 		/* Last segment data length */
 		pkt_hdr->buf_hdr.seg[num - 1].len = seg_len;
@@ -277,8 +275,7 @@  static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len,
 	*/
 	pkt_hdr->frame_len = len;
 	pkt_hdr->headroom  = CONFIG_PACKET_HEADROOM;
-	pkt_hdr->tailroom  = CONFIG_PACKET_MAX_SEG_LEN - seg_len +
-			     CONFIG_PACKET_TAILROOM;
+	pkt_hdr->tailroom  = pool->seg_len - seg_len + CONFIG_PACKET_TAILROOM;
 
 	pkt_hdr->input = ODP_PKTIO_INVALID;
 }
@@ -286,13 +283,14 @@  static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len,
 static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num)
 {
 	odp_packet_hdr_t *hdr;
+	pool_t *pool = pool_entry_from_hdl(pkt_hdr[0]->buf_hdr.pool_hdl);
 	int i;
 
 	/* First segment is the packet descriptor */
 	hdr = pkt_hdr[0];
 
 	hdr->buf_hdr.seg[0].data = hdr->buf_hdr.base_data;
-	hdr->buf_hdr.seg[0].len  = BASE_LEN;
+	hdr->buf_hdr.seg[0].len  = pool->seg_len;
 
 	/* Link segments */
 	if (CONFIG_PACKET_MAX_SEGS != 1) {
@@ -305,28 +303,26 @@  static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num)
 				buf_hdr = &pkt_hdr[i]->buf_hdr;
 				hdr->buf_hdr.seg[i].hdr  = buf_hdr;
 				hdr->buf_hdr.seg[i].data = buf_hdr->base_data;
-				hdr->buf_hdr.seg[i].len  = BASE_LEN;
+				hdr->buf_hdr.seg[i].len  = pool->seg_len;
 			}
 		}
 	}
 }
 
 /* Calculate the number of segments */
-static inline int num_segments(uint32_t len)
+static inline int num_segments(uint32_t len, uint32_t seg_len)
 {
-	uint32_t max_seg_len;
 	int num;
 
 	if (CONFIG_PACKET_MAX_SEGS == 1)
 		return 1;
 
 	num = 1;
-	max_seg_len = CONFIG_PACKET_MAX_SEG_LEN;
 
-	if (odp_unlikely(len > max_seg_len)) {
-		num = len / max_seg_len;
+	if (odp_unlikely(len > seg_len)) {
+		num = len / seg_len;
 
-		if (odp_likely((num * max_seg_len) != len))
+		if (odp_likely((num * seg_len) != len))
 			num += 1;
 	}
 
@@ -530,7 +526,7 @@  int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len,
 	pool_t *pool = pool_entry_from_hdl(pool_hdl);
 	int num, num_seg;
 
-	num_seg = num_segments(len);
+	num_seg = num_segments(len, pool->seg_len);
 	num     = packet_alloc(pool, len, max_num, num_seg, pkt, 1);
 
 	return num;
@@ -550,7 +546,7 @@  odp_packet_t odp_packet_alloc(odp_pool_t pool_hdl, uint32_t len)
 	if (odp_unlikely(len > pool->max_len))
 		return ODP_PACKET_INVALID;
 
-	num_seg = num_segments(len);
+	num_seg = num_segments(len, pool->seg_len);
 	num     = packet_alloc(pool, len, 1, num_seg, &pkt, 0);
 
 	if (odp_unlikely(num == 0))
@@ -573,7 +569,7 @@  int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len,
 	if (odp_unlikely(len > pool->max_len))
 		return -1;
 
-	num_seg = num_segments(len);
+	num_seg = num_segments(len, pool->seg_len);
 	num     = packet_alloc(pool, len, max_num, num_seg, pkt, 0);
 
 	return num;
@@ -721,10 +717,11 @@  static inline uint32_t pack_seg_head(odp_packet_hdr_t *pkt_hdr, int seg)
 
 static inline uint32_t pack_seg_tail(odp_packet_hdr_t *pkt_hdr, int seg)
 {
+	pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl);
 	odp_buffer_hdr_t *hdr = pkt_hdr->buf_hdr.seg[seg].hdr;
 	uint32_t len = pkt_hdr->buf_hdr.seg[seg].len;
 	uint8_t *src = pkt_hdr->buf_hdr.seg[seg].data;
-	uint8_t *dst = hdr->base_data + BASE_LEN - len;
+	uint8_t *dst = hdr->base_data + pool->seg_len - len;
 
 	if (dst != src) {
 		memmove(dst, src, len);
@@ -791,6 +788,7 @@  static inline uint32_t fill_seg_tail(odp_packet_hdr_t *pkt_hdr, int dst_seg,
 
 static inline int move_data_to_head(odp_packet_hdr_t *pkt_hdr, int segs)
 {
+	pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl);
 	int dst_seg, src_seg;
 	uint32_t len, free_len;
 	uint32_t moved = 0;
@@ -799,10 +797,10 @@  static inline int move_data_to_head(odp_packet_hdr_t *pkt_hdr, int segs)
 		len    = pack_seg_head(pkt_hdr, dst_seg);
 		moved += len;
 
-		if (len == BASE_LEN)
+		if (len == pool->seg_len)
 			continue;
 
-		free_len = BASE_LEN - len;
+		free_len = pool->seg_len - len;
 
 		for (src_seg = dst_seg + 1; CONFIG_PACKET_MAX_SEGS > 1 &&
 		     src_seg < segs; src_seg++) {
@@ -829,6 +827,7 @@  static inline int move_data_to_head(odp_packet_hdr_t *pkt_hdr, int segs)
 
 static inline int move_data_to_tail(odp_packet_hdr_t *pkt_hdr, int segs)
 {
+	pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl);
 	int dst_seg, src_seg;
 	uint32_t len, free_len;
 	uint32_t moved = 0;
@@ -837,10 +836,10 @@  static inline int move_data_to_tail(odp_packet_hdr_t *pkt_hdr, int segs)
 		len    = pack_seg_tail(pkt_hdr, dst_seg);
 		moved += len;
 
-		if (len == BASE_LEN)
+		if (len == pool->seg_len)
 			continue;
 
-		free_len = BASE_LEN - len;
+		free_len = pool->seg_len - len;
 
 		for (src_seg = dst_seg - 1; src_seg >= 0; src_seg--) {
 			len = fill_seg_tail(pkt_hdr, dst_seg, src_seg,
@@ -866,6 +865,7 @@  static inline int move_data_to_tail(odp_packet_hdr_t *pkt_hdr, int segs)
 
 static inline void reset_seg(odp_packet_hdr_t *pkt_hdr, int first, int num)
 {
+	pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl);
 	odp_buffer_hdr_t *hdr;
 	void *base;
 	int i;
@@ -873,7 +873,7 @@  static inline void reset_seg(odp_packet_hdr_t *pkt_hdr, int first, int num)
 	for (i = first; i < first + num; i++) {
 		hdr  = pkt_hdr->buf_hdr.seg[i].hdr;
 		base = hdr->base_data;
-		pkt_hdr->buf_hdr.seg[i].len  = BASE_LEN;
+		pkt_hdr->buf_hdr.seg[i].len  = pool->seg_len;
 		pkt_hdr->buf_hdr.seg[i].data = base;
 	}
 }
@@ -894,7 +894,7 @@  int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len,
 		if (odp_unlikely((frame_len + len) > pool->max_len))
 			return -1;
 
-		num  = num_segments(len - headroom);
+		num  = num_segments(len - headroom, pool->seg_len);
 		segs = pkt_hdr->buf_hdr.segcount;
 
 		if (odp_unlikely((segs + num) > CONFIG_PACKET_MAX_SEGS)) {
@@ -904,7 +904,7 @@  int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len,
 			int free_segs = 0;
 			uint32_t offset;
 
-			num = num_segments(frame_len + len);
+			num = num_segments(frame_len + len, pool->seg_len);
 
 			if (num > segs) {
 				/* Allocate additional segments */
@@ -942,7 +942,7 @@  int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len,
 			}
 
 			frame_len += len;
-			offset = (segs * BASE_LEN) - frame_len;
+			offset = (segs * pool->seg_len) - frame_len;
 
 			pkt_hdr->buf_hdr.seg[0].data += offset;
 			pkt_hdr->buf_hdr.seg[0].len  -= offset;
@@ -1060,7 +1060,7 @@  int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len,
 		if (odp_unlikely((frame_len + len) > pool->max_len))
 			return -1;
 
-		num  = num_segments(len - tailroom);
+		num  = num_segments(len - tailroom, pool->seg_len);
 		segs = pkt_hdr->buf_hdr.segcount;
 
 		if (odp_unlikely((segs + num) > CONFIG_PACKET_MAX_SEGS)) {
@@ -1070,7 +1070,7 @@  int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len,
 			int free_segs = 0;
 			uint32_t offset;
 
-			num = num_segments(frame_len + len);
+			num = num_segments(frame_len + len, pool->seg_len);
 
 			if (num > segs) {
 				/* Allocate additional segments */
@@ -1100,7 +1100,7 @@  int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len,
 			}
 
 			frame_len += len;
-			offset     = (segs * BASE_LEN) - frame_len;
+			offset     = (segs * pool->seg_len) - frame_len;
 
 			pkt_hdr->buf_hdr.seg[segs - 1].len -= offset;
 
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index ae3db34..1bffa6d 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -348,7 +348,7 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 	pkt_nm->pool = pool;
 
 	/* max frame len taking into account the l2-offset */
-	pkt_nm->max_frame_len = CONFIG_PACKET_MAX_SEG_LEN;
+	pkt_nm->max_frame_len = pool_entry_from_hdl(pool)->max_len;
 
 	/* allow interface to be opened with or without the 'netmap:' prefix */
 	prefix = "netmap:";