diff mbox

[v3,2/3] api: pool: Move from buffer to packet pool parameters

Message ID 1423798368-16597-2-git-send-email-petri.savolainen@linaro.org
State Accepted
Commit dece68d4c710aa7fedc40e24fff6254a1502170b
Headers show

Commit Message

Petri Savolainen Feb. 13, 2015, 3:32 a.m. UTC
Change implementation, examples and test to use the new
packet pool parameters with ODP_POOL_PACKET type pools
(instead of using buffer pool parameters).

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
---
 example/generator/odp_generator.c                  |  9 +++---
 example/ipsec/odp_ipsec.c                          | 18 ++++++-----
 example/l2fwd/odp_l2fwd.c                          |  9 +++---
 example/packet/odp_pktio.c                         |  9 +++---
 platform/linux-generic/odp_buffer_pool.c           | 21 ++++++++-----
 test/validation/buffer/odp_buffer_pool_test.c      | 36 ++++++++++++++++------
 test/validation/buffer/odp_packet_test.c           |  8 ++---
 .../classification/odp_classification_tests.c      |  9 +++---
 test/validation/odp_crypto.c                       |  9 +++---
 test/validation/odp_pktio.c                        | 18 ++++++-----
 10 files changed, 88 insertions(+), 58 deletions(-)
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 38b6ca0..db9e0c2 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -607,10 +607,11 @@  int main(int argc, char *argv[])
 	printf("cpu mask:           %s\n", cpumaskstr);
 
 	/* Create packet pool */
-	params.buf.size  = SHM_PKT_POOL_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.num     = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
+	params.type        = ODP_POOL_PACKET;
 
 	pool = odp_pool_create("packet_pool", ODP_SHM_NULL, &params);
 
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 302097e..1aa68db 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -399,10 +399,11 @@  void ipsec_init_pre(void)
 	}
 
 	/* Create output buffer pool */
-	params.buf.size  = SHM_OUT_POOL_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = SHM_PKT_POOL_BUF_COUNT;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = SHM_OUT_POOL_BUF_SIZE;
+	params.pkt.len     = SHM_OUT_POOL_BUF_SIZE;
+	params.pkt.num     = SHM_PKT_POOL_BUF_COUNT;
+	params.type        = ODP_POOL_PACKET;
 
 	out_pool = odp_pool_create("out_pool", ODP_SHM_NULL, &params);
 
@@ -1256,10 +1257,11 @@  main(int argc, char *argv[])
 	odp_barrier_init(&sync_barrier, num_workers);
 
 	/* Create packet buffer pool */
-	params.buf.size  = SHM_PKT_POOL_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = SHM_PKT_POOL_BUF_COUNT;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.num     = SHM_PKT_POOL_BUF_COUNT;
+	params.type        = ODP_POOL_PACKET;
 
 	pkt_pool = odp_pool_create("packet_pool", ODP_SHM_NULL,
 					  &params);
diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c
index 183043f..0326a3c 100644
--- a/example/l2fwd/odp_l2fwd.c
+++ b/example/l2fwd/odp_l2fwd.c
@@ -357,10 +357,11 @@  int main(int argc, char *argv[])
 	}
 
 	/* Create packet pool */
-	params.buf.size  = SHM_PKT_POOL_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.num     = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
+	params.type        = ODP_POOL_PACKET;
 
 	pool = odp_pool_create("packet pool", ODP_SHM_NULL, &params);
 
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index 194173c..5eec796 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -337,10 +337,11 @@  int main(int argc, char *argv[])
 	printf("cpu mask:           %s\n", cpumaskstr);
 
 	/* Create packet pool */
-	params.buf.size  = SHM_PKT_POOL_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.num     = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
+	params.type        = ODP_POOL_PACKET;
 
 	pool = odp_pool_create("packet_pool", ODP_SHM_NULL, &params);
 
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index 69acf1b..18ad358 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -126,7 +126,7 @@  odp_pool_t odp_pool_create(const char *name,
 		return ODP_POOL_INVALID;
 
 	/* Restriction for v1.0: All non-packet buffers are unsegmented */
-	int unsegmented = 1;
+	int unseg = 1;
 
 	/* Restriction for v1.0: No zeroization support */
 	const int zeroized = 0;
@@ -137,7 +137,12 @@  odp_pool_t odp_pool_create(const char *name,
 		0;
 
 	uint32_t blk_size, buf_stride;
-	uint32_t buf_align = params->buf.align;
+	uint32_t buf_align;
+
+	if (params->type == ODP_POOL_PACKET)
+		buf_align = 0;
+	else
+		buf_align = params->buf.align;
 
 	/* Validate requested buffer alignment */
 	if (buf_align > ODP_CONFIG_BUFFER_ALIGN_MAX ||
@@ -168,15 +173,15 @@  odp_pool_t odp_pool_create(const char *name,
 	case ODP_POOL_PACKET:
 		headroom = ODP_CONFIG_PACKET_HEADROOM;
 		tailroom = ODP_CONFIG_PACKET_TAILROOM;
-		unsegmented = params->buf.size > ODP_CONFIG_PACKET_BUF_LEN_MAX;
+		unseg = params->pkt.seg_len > ODP_CONFIG_PACKET_BUF_LEN_MAX;
 
-		if (unsegmented)
+		if (unseg)
 			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf.size + tailroom,
+				headroom + params->pkt.seg_len + tailroom,
 				buf_align);
 		else
 			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf.size + tailroom,
+				headroom + params->pkt.seg_len + tailroom,
 				ODP_CONFIG_PACKET_BUF_LEN_MIN);
 
 		buf_stride = params->type == ODP_POOL_PACKET ?
@@ -276,9 +281,9 @@  odp_pool_t odp_pool_create(const char *name,
 		/* Now safe to unlock since pool entry has been allocated */
 		POOL_UNLOCK(&pool->s.lock);
 
-		pool->s.flags.unsegmented = unsegmented;
+		pool->s.flags.unsegmented = unseg;
 		pool->s.flags.zeroized = zeroized;
-		pool->s.seg_size = unsegmented ?
+		pool->s.seg_size = unseg ?
 			blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
 
 
diff --git a/test/validation/buffer/odp_buffer_pool_test.c b/test/validation/buffer/odp_buffer_pool_test.c
index c018b59..ebeae75 100644
--- a/test/validation/buffer/odp_buffer_pool_test.c
+++ b/test/validation/buffer/odp_buffer_pool_test.c
@@ -10,23 +10,39 @@  static int pool_name_number = 1;
 static const int default_buffer_size = 1500;
 static const int default_buffer_num = 1000;
 
-odp_pool_t pool_create(int buf_num, int buf_size, int buf_type)
+odp_pool_t pool_create(int num, int size, int type)
 {
 	odp_pool_t pool;
 	char pool_name[ODP_POOL_NAME_LEN];
-	odp_pool_param_t params = {
-			.buf = {
-				.size  = buf_size,
-				.align = ODP_CACHE_LINE_SIZE,
-				.num   = buf_num,
-			},
-			.type = buf_type,
-	};
+	odp_pool_param_t param;
+
+	memset(&param, 0, sizeof(param));
+
+	switch (type) {
+	case ODP_POOL_BUFFER:
+		param.buf.size  = size;
+		param.buf.align = ODP_CACHE_LINE_SIZE;
+		param.buf.num   = num;
+		break;
+	case ODP_POOL_PACKET:
+		param.pkt.seg_len = size;
+		param.pkt.len     = size;
+		param.pkt.num     = num;
+		break;
+	case ODP_POOL_TIMEOUT:
+		param.tmo.num = num;
+		break;
+	default:
+		CU_FAIL("Bad pool type");
+		return ODP_POOL_INVALID;
+	}
+
+	param.type = type;
 
 	snprintf(pool_name, sizeof(pool_name),
 		 "test_buffer_pool-%d", pool_name_number++);
 
-	pool = odp_pool_create(pool_name, ODP_SHM_INVALID, &params);
+	pool = odp_pool_create(pool_name, ODP_SHM_INVALID, &param);
 	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
 
 	return pool;
diff --git a/test/validation/buffer/odp_packet_test.c b/test/validation/buffer/odp_packet_test.c
index b8995f7..f5830cc 100644
--- a/test/validation/buffer/odp_packet_test.c
+++ b/test/validation/buffer/odp_packet_test.c
@@ -22,10 +22,10 @@  odp_packet_t test_packet;
 int packet_testsuite_init(void)
 {
 	odp_pool_param_t params = {
-		.buf = {
-			.size  = PACKET_BUF_LEN,
-			.align = ODP_CACHE_LINE_SIZE,
-			.num  = 100,
+		.pkt = {
+			.seg_len = PACKET_BUF_LEN,
+			.len     = PACKET_BUF_LEN,
+			.num     = 100,
 		},
 		.type  = ODP_POOL_PACKET,
 	};
diff --git a/test/validation/classification/odp_classification_tests.c b/test/validation/classification/odp_classification_tests.c
index 45822d3..564455c 100644
--- a/test/validation/classification/odp_classification_tests.c
+++ b/test/validation/classification/odp_classification_tests.c
@@ -247,10 +247,11 @@  int classification_tests_init(void)
 	char queuename[ODP_QUEUE_NAME_LEN];
 	int i;
 
-	param.buf.size = SHM_PKT_BUF_SIZE;
-	param.buf.num = SHM_PKT_NUM_BUFS;
-	param.buf.align = 0;
-	param.type = ODP_POOL_PACKET;
+	memset(&param, 0, sizeof(param));
+	param.pkt.seg_len = SHM_PKT_BUF_SIZE;
+	param.pkt.len     = SHM_PKT_BUF_SIZE;
+	param.pkt.num     = SHM_PKT_NUM_BUFS;
+	param.type        = ODP_POOL_PACKET;
 
 	pool = odp_pool_create("classification_pool",
 				      ODP_SHM_NULL, &param);
diff --git a/test/validation/odp_crypto.c b/test/validation/odp_crypto.c
index d8db114..b109a75 100644
--- a/test/validation/odp_crypto.c
+++ b/test/validation/odp_crypto.c
@@ -29,10 +29,11 @@  int tests_global_init(void)
 	odp_pool_t pool;
 	odp_queue_t out_queue;
 
-	params.buf.size  = SHM_PKT_POOL_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
+	params.pkt.num     = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE;
+	params.type        = ODP_POOL_PACKET;
 
 	pool = odp_pool_create("packet_pool", ODP_SHM_NULL, &params);
 
diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c
index fef4eaa..3f9de3c 100644
--- a/test/validation/odp_pktio.c
+++ b/test/validation/odp_pktio.c
@@ -186,10 +186,11 @@  static int default_pool_create(void)
 	if (default_pkt_pool != ODP_POOL_INVALID)
 		return -1;
 
-	params.buf.size  = PKT_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = PKT_BUF_NUM;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = PKT_BUF_SIZE;
+	params.pkt.len     = PKT_BUF_SIZE;
+	params.pkt.num     = PKT_BUF_NUM;
+	params.type        = ODP_POOL_PACKET;
 
 	default_pkt_pool = odp_pool_create("pkt_pool_default",
 						  ODP_SHM_NULL, &params);
@@ -206,10 +207,11 @@  static odp_pktio_t create_pktio(const char *iface)
 	char pool_name[ODP_POOL_NAME_LEN];
 	odp_pool_param_t params;
 
-	params.buf.size  = PKT_BUF_SIZE;
-	params.buf.align = 0;
-	params.buf.num   = PKT_BUF_NUM;
-	params.type      = ODP_POOL_PACKET;
+	memset(&params, 0, sizeof(params));
+	params.pkt.seg_len = PKT_BUF_SIZE;
+	params.pkt.len     = PKT_BUF_SIZE;
+	params.pkt.num     = PKT_BUF_NUM;
+	params.type        = ODP_POOL_PACKET;
 
 	snprintf(pool_name, sizeof(pool_name), "pkt_pool_%s", iface);
 	pool = odp_pool_lookup(pool_name);