diff mbox series

[2.0,v3,1/2] linux-gen: pktio: add pktio operations data pool

Message ID 1511182808-32328-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [2.0,v3,1/2] linux-gen: pktio: add pktio operations data pool | expand

Commit Message

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


Pktio instances need a memory area where to store configuration or
state information. The size and structure of this area depends on
pktio type.
This pool is meant to be used for allocation of such memory areas.

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: 7b05757dc100acc261053cf8e9cb253091ceaf91
 **/
 platform/linux-dpdk/Makefile.am                    |  3 ++
 platform/linux-generic/Makefile.am                 |  3 ++
 .../linux-generic/include/odp_packet_io_pool.h     | 27 ++++++++++
 .../include/odp_packet_io_pool_access.h            | 58 ++++++++++++++++++++++
 platform/linux-generic/odp_packet_io.c             |  9 ++++
 platform/linux-generic/odp_packet_io_pool.c        | 55 ++++++++++++++++++++
 6 files changed, 155 insertions(+)
 create mode 100644 platform/linux-generic/include/odp_packet_io_pool.h
 create mode 100644 platform/linux-generic/include/odp_packet_io_pool_access.h
 create mode 100644 platform/linux-generic/odp_packet_io_pool.c
diff mbox series

Patch

diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am
index f27d2b50c..ee6c36e21 100644
--- a/platform/linux-dpdk/Makefile.am
+++ b/platform/linux-dpdk/Makefile.am
@@ -206,6 +206,8 @@  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_packet_io_pool_access.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 +262,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..a4aaa7693 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -175,6 +175,8 @@  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_pool_access.h \
 		  include/odp_packet_io_ring_internal.h \
 		  pktio/ethtool.h \
 		  pktio/common.h \
@@ -244,6 +246,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..59ad053b1
--- /dev/null
+++ b/platform/linux-generic/include/odp_packet_io_pool.h
@@ -0,0 +1,27 @@ 
+/* Copyright (c) 2017, 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/include/odp_packet_io_pool_access.h b/platform/linux-generic/include/odp_packet_io_pool_access.h
new file mode 100644
index 000000000..cdd7dd968
--- /dev/null
+++ b/platform/linux-generic/include/odp_packet_io_pool_access.h
@@ -0,0 +1,58 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP packet IO pool
+ */
+
+#ifndef ODP_PACKET_IO_POOL_ACCESS_H_
+#define ODP_PACKET_IO_POOL_ACCESS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp/api/align.h>
+#include <odp/drv/shm.h>
+
+/**
+ * Packet IO operations data pool name
+ */
+#define ODP_PKTIO_OPS_DATA_POOL_NAME "ODP_PKTIO_OPS_DATA"
+
+#define ODP_OPS_DATA_ALLOC(_size)					\
+({									\
+	odpdrv_shm_pool_t _pool;					\
+	void *_ops_data = NULL;						\
+									\
+	_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME);	\
+	if (_pool != ODPDRV_SHM_POOL_INVALID)				\
+		_ops_data = odpdrv_shm_pool_alloc(_pool,		\
+			ROUNDUP_CACHE_LINE(_size));			\
+									\
+	_ops_data;							\
+})
+
+#define ODP_OPS_DATA_FREE(_ops_data)					\
+({									\
+	odpdrv_shm_pool_t _pool;					\
+	int _result = -1;						\
+									\
+	_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME);	\
+	if (_pool != ODPDRV_SHM_POOL_INVALID) {				\
+		odpdrv_shm_pool_free(_pool, _ops_data);			\
+		_result = 0;						\
+	}								\
+	_result;							\
+})
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ODP_PACKET_IO_POOL_ACCESS_H_*/
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index a1c708616..efeac0269 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..3e1860475
--- /dev/null
+++ b/platform/linux-generic/odp_packet_io_pool.c
@@ -0,0 +1,55 @@ 
+/* Copyright (c) 2017, 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_packet_io_pool_access.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;
+}