From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [RFC PATCH 2/5] mempool: driver for mempools of mbufs on shared memory
Date: Fri, 22 Sep 2023 09:19:09 +0100 [thread overview]
Message-ID: <20230922081912.7090-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20230922081912.7090-1-bruce.richardson@intel.com>
This mempool driver can be used with the shared_mem bus driver to create
a pool of shared mbufs on a shared memory segment.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/mempool/meson.build | 1 +
drivers/mempool/shared_mem/meson.build | 10 +++
drivers/mempool/shared_mem/shared_mem_mp.c | 94 ++++++++++++++++++++++
3 files changed, 105 insertions(+)
create mode 100644 drivers/mempool/shared_mem/meson.build
create mode 100644 drivers/mempool/shared_mem/shared_mem_mp.c
diff --git a/drivers/mempool/meson.build b/drivers/mempool/meson.build
index dc88812585..4326bd0ea3 100644
--- a/drivers/mempool/meson.build
+++ b/drivers/mempool/meson.build
@@ -8,6 +8,7 @@ drivers = [
'dpaa2',
'octeontx',
'ring',
+ 'shared_mem',
'stack',
]
diff --git a/drivers/mempool/shared_mem/meson.build b/drivers/mempool/shared_mem/meson.build
new file mode 100644
index 0000000000..ee740ccdc9
--- /dev/null
+++ b/drivers/mempool/shared_mem/meson.build
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2023 Intel Corporation
+
+if is_windows
+ build = false
+ reason = 'not supported on Windows'
+endif
+sources = files('shared_mem_mp.c')
+require_iova_in_mbuf = false
+deps += ['stack', 'bus_shared_mem']
diff --git a/drivers/mempool/shared_mem/shared_mem_mp.c b/drivers/mempool/shared_mem/shared_mem_mp.c
new file mode 100644
index 0000000000..7dae8aba92
--- /dev/null
+++ b/drivers/mempool/shared_mem/shared_mem_mp.c
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Intel Corporation
+ */
+#include <sys/types.h>
+#include <rte_mbuf.h>
+#include <rte_stack.h>
+#include <rte_mempool.h>
+#include <shared_mem_bus.h>
+
+RTE_LOG_REGISTER_DEFAULT(shared_mem_mp_log, DEBUG);
+#define MP_LOG(level, fmt, args...) rte_log(RTE_LOG_ ## level, \
+ shared_mem_mp_log, "## SHARED MP: %s(): " fmt "\n", __func__, ##args)
+#define MP_ERR(fmt, args...) MP_LOG(ERR, fmt, ## args)
+#define MP_INFO(fmt, args...) MP_LOG(INFO, fmt, ## args)
+#define MP_DEBUG(fmt, args...) MP_LOG(DEBUG, fmt, ## args)
+
+static int
+shm_mp_alloc(struct rte_mempool *mp)
+{
+ char name[RTE_STACK_NAMESIZE];
+ struct rte_stack *s;
+ int ret;
+
+ ret = snprintf(name, sizeof(name), RTE_MEMPOOL_MZ_FORMAT, mp->name);
+ if (ret < 0 || ret >= (int)sizeof(name)) {
+ rte_errno = ENAMETOOLONG;
+ return -rte_errno;
+ }
+
+ s = rte_stack_create(name, mp->size, mp->socket_id, 0);
+ if (s == NULL)
+ return -rte_errno;
+ MP_DEBUG("Stack created at address: %p", s);
+
+ mp->pool_data = s;
+
+ return 0;
+}
+
+static int
+shm_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
+ unsigned int n)
+{
+ struct rte_stack *s = mp->pool_data;
+
+ void *offset_table[n];
+ uintptr_t mempool_base = (uintptr_t)rte_shm_bus_get_mem_ptr(0); /* offset 0 == base addr */
+ for (uint i = 0; i < n; i++)
+ offset_table[i] = RTE_PTR_SUB(obj_table[i], mempool_base);
+
+ return rte_stack_push(s, offset_table, n) == 0 ? -ENOBUFS : 0;
+}
+
+static int
+shm_mp_dequeue(struct rte_mempool *mp, void **obj_table,
+ unsigned int n)
+{
+ struct rte_stack *s = mp->pool_data;
+ uintptr_t mempool_base = (uintptr_t)rte_shm_bus_get_mem_ptr(0); /* offset 0 == base addr */
+ uint16_t priv_size = rte_pktmbuf_priv_size(mp);
+
+ if (rte_stack_pop(s, obj_table, n) == 0)
+ return -ENOBUFS;
+ for (uint i = 0; i < n; i++) {
+ obj_table[i] = RTE_PTR_ADD(obj_table[i], mempool_base);
+ struct rte_mbuf *mb = obj_table[i];
+ mb->buf_addr = RTE_PTR_ADD(mb, sizeof(struct rte_mbuf) + priv_size);
+ mb->pool = mp;
+ }
+ return 0;
+}
+
+static unsigned
+shm_mp_get_count(const struct rte_mempool *mp)
+{
+ return rte_stack_count(mp->pool_data);
+}
+
+static void
+shm_mp_free(struct rte_mempool *mp)
+{
+ rte_stack_free(mp->pool_data);
+}
+
+static struct rte_mempool_ops ops_shared_mem_mp = {
+ .name = "shared_mem",
+ .alloc = shm_mp_alloc,
+ .free = shm_mp_free,
+ .enqueue = shm_mp_enqueue,
+ .dequeue = shm_mp_dequeue,
+ .get_count = shm_mp_get_count,
+};
+
+RTE_MEMPOOL_REGISTER_OPS(ops_shared_mem_mp);
--
2.39.2
next prev parent reply other threads:[~2023-09-22 8:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 8:19 [RFC PATCH 0/5] Using shared mempools for zero-copy IO proxying Bruce Richardson
2023-09-22 8:19 ` [RFC PATCH 1/5] bus: new driver to accept shared memory over unix socket Bruce Richardson
2023-11-23 14:50 ` Jerin Jacob
2023-09-22 8:19 ` Bruce Richardson [this message]
2023-09-22 8:19 ` [RFC PATCH 3/5] net: new ethdev driver to communicate using shared mem Bruce Richardson
2023-09-22 8:19 ` [RFC PATCH 4/5] app: add IO proxy app using shared memory interfaces Bruce Richardson
2023-09-22 8:19 ` [RFC PATCH 5/5] app/io-proxy: add startup commands Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230922081912.7090-3-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).