diff mbox

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

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

Commit Message

Bill Fischofer Feb. 11, 2015, 1:20 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 8 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
are not updated to reflect these changes. If this API is acceptable I'll
forward a complete patch conforming to it.

 include/odp/api/pool.h                   | 51 ++++++++++++++++++++++++++++----
 platform/linux-generic/odp_buffer_pool.c | 35 +++++++++++++++-------
 2 files changed, 71 insertions(+), 15 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/pool.h b/include/odp/api/pool.h
index b8c0f2e..c794c66 100644
--- a/include/odp/api/pool.h
+++ b/include/odp/api/pool.h
@@ -60,13 +60,54 @@  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 8
+					      bytes and will never be less
+					      than 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. */
+			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..17f5bf5 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,32 @@  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;
+		headroom = params->pkt.headroom;
+		tailroom = params->pkt.tailroom;
+		unsegmented = params->pkt.seg_size >= params->pkt.len;
 
-		if (unsegmented)
+		if (unsegmented) {
 			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf.size + tailroom,
+				headroom + params->pkt.len + tailroom,
 				buf_align);
-		else
-			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf.size + tailroom,
-				ODP_CONFIG_PACKET_BUF_LEN_MIN);
+		} else {
+			seg_size =
+				ODP_ALIGN_ROUNDUP(params->pkt.seg_size, 8);
+			if (seg_size == 0) {
+				blk_size = ODP_ALIGN_ROUNDUP(
+					headroom + params->pkt.len + tailroom,
+					ODP_CONFIG_PACKET_BUF_LEN_MIN);
+			} else {
+				if (seg_size < 256)
+					seg_size = 256;
+				else
+					seg_size =
+						ODP_ALIGN_ROUNDUP(seg_size, 8);
+				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 +294,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;