diff mbox

[RFC,PATCHv2] api: pool: proposed pool parameters for packets

Message ID 1423686902-10251-1-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Feb. 11, 2015, 8:35 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---

Based on the discussions we had this afternoon, here is a proposed patch
that I believe covers the concerns of all parties.  The application is
free to request minimum segment sizes or to leave that to the implementation
or to request that packets be unsegmented. The implementation, in turn,
controls the actual segment size used (if any) and will reject pool create
requests that it is unable to comply with. It is also part of the API
specification that any segment size used by an ODP implementation will be a
minimum of 256 bytes and always be a multiple of the requested
align bytes in size.

This also adds requested headroom and tailroom parameters to the pool create
parameter list for packets.  

Note that this is an RFC because it is not a complete patch: The examples and
tests are not updated to reflect these changes. If this API is acceptable I'll
forward a complete patch conforming to it.

v2 clarifies that seg_size is a multiple of align and how this is used to
control unsegmened pools.  If pkt.seg_size >= pkt.len the pool is unsegmented
and pkt.seg_len is the maximum length packet that the pool will support.

 include/odp/api/pool.h                   | 54 +++++++++++++++++++++++++++++---
 platform/linux-generic/odp_buffer_pool.c | 29 ++++++++++-------
 2 files changed, 66 insertions(+), 17 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/pool.h b/include/odp/api/pool.h
index b8c0f2e..3713674 100644
--- a/include/odp/api/pool.h
+++ b/include/odp/api/pool.h
@@ -60,13 +60,57 @@  typedef struct odp_pool_param_t {
 					     of 8. */
 			uint32_t num;   /**< Number of buffers in the pool */
 		} buf;
-/* Reserved for packet and timeout specific params
 		struct {
-			uint32_t seg_size;
-			uint32_t seg_align;
-			uint32_t num;
+			uint32_t len;      /**< Expected average packet length
+					      in bytes. This is used by the
+					      implementation to calculate
+					      the amount of storage needed for
+					      the pool. If this number is less
+					      than the actual average packet
+					      length then the effect will be
+					      that the number of packets that
+					      can be stored in the pool will be
+					      less than num. */
+			uint32_t align;    /**< Minimum pkt alignment in bytes.
+					      Valid values are powers of two.
+					      Use 0 for default alignment.
+					      Default will always be a multiple
+					      of 8. */
+			uint32_t num;      /**< Maximum number of packets
+					      that this pool may contain. */
+			uint32_t seg_size; /**< Requested minimum segment size
+					      to be used for this pool, The
+					      implementation is free to use
+					      a segment size larger than this
+					      value. Any segment size used
+					      will always be a multiple of
+					      align bytes and will never be
+					      < 256 bytes. If seg_size == 0,
+					      the application has no
+					      preference and the implementation
+					      is free to a segment size of
+					      its choosing, subject to the
+					      previously noted constraints.
+					      If seg_size >= len, the
+					      application is requesting that
+					      the pool be unsegmented and
+					      seg_size is the maximum sized
+					      packet that the pool will
+					      support. */
+			uint32_t headroom; /**< Requested headroom for packets
+					      allocated from this pool. This
+					      is the minimum headroom that
+					      will be used. The implementation
+					      may increase this value by any
+					      multiple of 8 for internal
+					      reasons. */
+			uint32_t tailroom; /**< Requested tailroom for packets
+					      allocated from this pool. This
+					      is the minimum tailroom that
+					      will be used. The implementation
+					      may increase this by any byte
+					      value for internal reasons. */
 		} pkt;
-*/
 		struct {
 			uint32_t __res1; /* Keep struct identical to buf, */
 			uint32_t __res2; /* until pool implementation is fixed*/
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index 69acf1b..ea764d9 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -138,6 +138,7 @@  odp_pool_t odp_pool_create(const char *name,
 
 	uint32_t blk_size, buf_stride;
 	uint32_t buf_align = params->buf.align;
+	uint32_t seg_size;
 
 	/* Validate requested buffer alignment */
 	if (buf_align > ODP_CONFIG_BUFFER_ALIGN_MAX ||
@@ -166,18 +167,22 @@  odp_pool_t odp_pool_create(const char *name,
 		break;
 
 	case ODP_POOL_PACKET:
-		headroom = ODP_CONFIG_PACKET_HEADROOM;
-		tailroom = ODP_CONFIG_PACKET_TAILROOM;
-		unsegmented = params->buf.size > ODP_CONFIG_PACKET_BUF_LEN_MAX;
-
-		if (unsegmented)
-			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf.size + tailroom,
-				buf_align);
+		headroom = params->pkt.headroom;
+		tailroom = params->pkt.tailroom;
+		unsegmented = params->pkt.seg_size >= params->pkt.len;
+
+		if (params->pkt.seg_size == 0)
+			seg_size = ODP_CONFIG_PACKET_BUF_LEN_MIN;
+		else if (params->pkt.seg_size < 256)
+			seg_size = 256;
 		else
-			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf.size + tailroom,
-				ODP_CONFIG_PACKET_BUF_LEN_MIN);
+			seg_size = params->pkt.seg_size;
+
+		seg_size = ODP_ALIGN_ROUNDUP(params->pkt.seg_size,
+					     buf_align);
+		blk_size = ODP_ALIGN_ROUNDUP(
+			headroom + params->pkt.len + tailroom,
+			seg_size);
 
 		buf_stride = params->type == ODP_POOL_PACKET ?
 			sizeof(odp_packet_hdr_stride) :
@@ -279,7 +284,7 @@  odp_pool_t odp_pool_create(const char *name,
 		pool->s.flags.unsegmented = unsegmented;
 		pool->s.flags.zeroized = zeroized;
 		pool->s.seg_size = unsegmented ?
-			blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
+			blk_size : seg_size;
 
 
 		uint8_t *block_base_addr = pool->s.pool_base_addr;