diff mbox series

[2.0,v2,1/3] linux-gen: pktio: add IO interface operation data pool

Message ID 1510938009-12495-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [2.0,v2,1/3] linux-gen: pktio: add IO interface operation data pool | expand

Commit Message

Github ODP bot Nov. 17, 2017, 5 p.m. UTC
From: Bogdan Pricope <bogdan.pricope@linaro.org>


Pktio implementations will allocate pktio entries operations
data from this pool.

Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
/** Email created from pull request 297 (bogdanPricope:2_0_ops_alloc_pr)
 ** https://github.com/Linaro/odp/pull/297
 ** Patch: https://github.com/Linaro/odp/pull/297.patch
 ** Base sha: 6cd43041e55bd73a02ca202f835e590b3ad5c354
 ** Merge commit sha: c785d2a3749494734a049a6e261df1b741ea22e0
 **/
 include/odp/api/spec/packet_io.h                   |  5 ++
 platform/linux-dpdk/Makefile.am                    |  2 +
 platform/linux-generic/Makefile.am                 |  2 +
 .../linux-generic/include/odp_packet_io_pool.h     | 27 +++++++++++
 platform/linux-generic/odp_packet_io.c             |  9 ++++
 platform/linux-generic/odp_packet_io_pool.c        | 54 ++++++++++++++++++++++
 6 files changed, 99 insertions(+)
 create mode 100644 platform/linux-generic/include/odp_packet_io_pool.h
 create mode 100644 platform/linux-generic/odp_packet_io_pool.c
diff mbox series

Patch

diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h
index 52af646a6..70dacd3c9 100644
--- a/include/odp/api/spec/packet_io.h
+++ b/include/odp/api/spec/packet_io.h
@@ -1188,6 +1188,11 @@  uint64_t odp_pktin_ts_res(odp_pktio_t pktio);
  */
 odp_time_t odp_pktin_ts_from_ns(odp_pktio_t pktio, uint64_t ns);
 
+/**
+ * Packet IO operations data pool name
+ */
+#define ODP_PKTIO_OPS_DATA_POOL_NAME "ODP_PKTIO_OPS_DATA"
+
 /**
  * @}
  */
diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am
index f27d2b50c..9efd7fa5b 100644
--- a/platform/linux-dpdk/Makefile.am
+++ b/platform/linux-dpdk/Makefile.am
@@ -206,6 +206,7 @@  noinst_HEADERS = \
 		  ${top_srcdir}/platform/linux-generic/include/odp_packet_io_internal.h \
 		  ${srcdir}/include/odp_errno_define.h \
 		  ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ring_internal.h \
+		  ${top_srcdir}/platform/linux-generic/include/odp_packet_io_pool.h \
 		  ${top_srcdir}/platform/linux-generic/include/odp_pkt_queue_internal.h \
 		  ${srcdir}/include/odp_pool_internal.h \
 		  ${top_srcdir}/platform/linux-generic/include/odp_pool_subsystem.h \
@@ -260,6 +261,7 @@  __LIB__libodp_dpdk_la_SOURCES = \
 			   ../linux-generic/pktio/subsystem.c \
 			   odp_packet_flags.c \
 			   ../linux-generic/odp_packet_io.c \
+			   ../linux-generic/odp_packet_io_pool.c \
 			   ../linux-generic/pktio/loopback.c \
 			   ../linux-generic/odp_pkt_queue.c \
 			   pool/dpdk.c \
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 56ef03c6f..769edcf90 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -175,6 +175,7 @@  noinst_HEADERS = \
 		  include/odp_name_table_internal.h \
 		  include/odp_packet_internal.h \
 		  include/odp_packet_io_internal.h \
+		  include/odp_packet_io_pool.h \
 		  include/odp_packet_io_ring_internal.h \
 		  pktio/ethtool.h \
 		  pktio/common.h \
@@ -244,6 +245,7 @@  __LIB__libodp_linux_la_SOURCES = \
 			   odp_packet.c \
 			   odp_packet_flags.c \
 			   odp_packet_io.c \
+			   odp_packet_io_pool.c \
 			   pktio/ethtool.c \
 			   pktio/subsystem.c \
 			   pktio/ipc.c \
diff --git a/platform/linux-generic/include/odp_packet_io_pool.h b/platform/linux-generic/include/odp_packet_io_pool.h
new file mode 100644
index 000000000..59f6e41c1
--- /dev/null
+++ b/platform/linux-generic/include/odp_packet_io_pool.h
@@ -0,0 +1,27 @@ 
+/* Copyright (c) 2013, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP packet IO pool
+ */
+
+#ifndef ODP_PACKET_IO_POOL_H_
+#define ODP_PACKET_IO_POOL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int odp_packet_io_pool_create(void);
+int odp_packet_io_pool_destroy(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ODP_PACKET_IO_POOL_H_*/
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index a1c708616..432fcf7eb 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -10,6 +10,7 @@ 
 
 #include <odp/api/packet_io.h>
 #include <odp_packet_io_internal.h>
+#include <odp_packet_io_pool.h>
 #include <odp/api/packet.h>
 #include <odp_packet_internal.h>
 #include <odp_internal.h>
@@ -76,6 +77,10 @@  int odp_pktio_init_global(void)
 		pktio_entry_ptr[i] = pktio_entry;
 	}
 
+	if (odp_packet_io_pool_create()) {
+		odp_shm_free(shm);
+		return -1;
+	}
 	return odp_pktio_ops_init_global(true);
 }
 
@@ -1122,6 +1127,10 @@  int odp_pktio_term_global(void)
 
 	ret = odp_pktio_ops_term_global(false);
 
+	ret = odp_packet_io_pool_destroy();
+	if (ret)
+		ODP_ERR("unable to destroy pktio pool\n");
+
 	ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries"));
 	if (ret != 0)
 		ODP_ERR("shm free failed for odp_pktio_entries");
diff --git a/platform/linux-generic/odp_packet_io_pool.c b/platform/linux-generic/odp_packet_io_pool.c
new file mode 100644
index 000000000..edfa2ced9
--- /dev/null
+++ b/platform/linux-generic/odp_packet_io_pool.c
@@ -0,0 +1,54 @@ 
+/* Copyright (c) 2013, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include "config.h"
+
+#include <odp_posix_extensions.h>
+#include <odp/api/packet_io.h>
+#include <odp/api/std_clib.h>
+#include <odp/drv/shm.h>
+#include "odp_packet_io_pool.h"
+#include "odp_debug_internal.h"
+
+#define ODP_PKTIO_OPS_DATA_POOL_SIZE 160000
+
+int odp_packet_io_pool_create(void)
+{
+	odpdrv_shm_pool_t pktio_ops_pool;
+	odpdrv_shm_pool_param_t pktio_ops_param;
+
+	odp_memset(&pktio_ops_param, 0, sizeof(pktio_ops_param));
+	pktio_ops_param.pool_size = ODP_PKTIO_OPS_DATA_POOL_SIZE;
+	pktio_ops_param.min_alloc = 1;
+	pktio_ops_param.max_alloc = ODP_PKTIO_OPS_DATA_POOL_SIZE;
+
+	pktio_ops_pool = odpdrv_shm_pool_create(ODP_PKTIO_OPS_DATA_POOL_NAME,
+						&pktio_ops_param);
+	if (pktio_ops_pool == ODPDRV_SHM_POOL_INVALID) {
+		ODP_ERR("error to pool_create pktio_ops pool\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+int odp_packet_io_pool_destroy(void)
+{
+	odpdrv_shm_pool_t pktio_ops_pool;
+
+	pktio_ops_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME);
+	if (pktio_ops_pool == ODPDRV_SHM_POOL_INVALID) {
+		ODP_ERR("error pool_lookup pktio_ops pool\n");
+		return -1;
+	}
+
+	if (odpdrv_shm_pool_destroy(pktio_ops_pool)) {
+		ODP_ERR("error pool_destroy pktio_ops pool\n");
+		return -1;
+	}
+
+	return 0;
+}