From: David Hunt <david.hunt@intel.com>
To: dev@dpdk.org
Cc: olivier.matz@6wind.com, viktorin@rehivetech.com,
jerin.jacob@caviumnetworks.com, shreyansh.jain@nxp.com,
David Hunt <david.hunt@intel.com>
Subject: [dpdk-dev] [PATCH v4 2/2] test: migrate custom handler test to stack handler
Date: Thu, 30 Jun 2016 08:41:42 +0100 [thread overview]
Message-ID: <1467272502-56059-3-git-send-email-david.hunt@intel.com> (raw)
In-Reply-To: <1467272502-56059-1-git-send-email-david.hunt@intel.com>
After introducing the stack handler in the previous commit,
we now have very similar code to the custom handler in test_mempool.c,
which creates a custom mempool based on simple mallocs.
The stack handler is a cleaner example of adding a new mempool handler,
so this commit replaces the custom handler test with a stack
handler test, and removes the custom handler code.
Signed-off-by: David Hunt <david.hunt@intel.com>
---
app/test/test_mempool.c | 114 ++++++------------------------------------------
1 file changed, 13 insertions(+), 101 deletions(-)
diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c
index 31582d8..19b1eb9 100644
--- a/app/test/test_mempool.c
+++ b/app/test/test_mempool.c
@@ -83,99 +83,6 @@
static rte_atomic32_t synchro;
/*
- * Simple example of custom mempool structure. Holds pointers to all the
- * elements which are simply malloc'd in this example.
- */
-struct custom_mempool {
- rte_spinlock_t lock;
- unsigned count;
- unsigned size;
- void *elts[];
-};
-
-/*
- * Loop through all the element pointers and allocate a chunk of memory, then
- * insert that memory into the ring.
- */
-static int
-custom_mempool_alloc(struct rte_mempool *mp)
-{
- struct custom_mempool *cm;
-
- cm = rte_zmalloc("custom_mempool",
- sizeof(struct custom_mempool) + mp->size * sizeof(void *), 0);
- if (cm == NULL)
- return -ENOMEM;
-
- rte_spinlock_init(&cm->lock);
- cm->count = 0;
- cm->size = mp->size;
- mp->pool_data = cm;
- return 0;
-}
-
-static void
-custom_mempool_free(struct rte_mempool *mp)
-{
- rte_free((void *)(mp->pool_data));
-}
-
-static int
-custom_mempool_enqueue(struct rte_mempool *mp, void * const *obj_table,
- unsigned n)
-{
- struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data);
- int ret = 0;
-
- rte_spinlock_lock(&cm->lock);
- if (cm->count + n > cm->size) {
- ret = -ENOBUFS;
- } else {
- memcpy(&cm->elts[cm->count], obj_table, sizeof(void *) * n);
- cm->count += n;
- }
- rte_spinlock_unlock(&cm->lock);
- return ret;
-}
-
-
-static int
-custom_mempool_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
-{
- struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data);
- int ret = 0;
-
- rte_spinlock_lock(&cm->lock);
- if (n > cm->count) {
- ret = -ENOENT;
- } else {
- cm->count -= n;
- memcpy(obj_table, &cm->elts[cm->count], sizeof(void *) * n);
- }
- rte_spinlock_unlock(&cm->lock);
- return ret;
-}
-
-static unsigned
-custom_mempool_get_count(const struct rte_mempool *mp)
-{
- struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data);
-
- return cm->count;
-}
-
-static struct rte_mempool_ops mempool_ops_custom = {
- .name = "custom_handler",
- .alloc = custom_mempool_alloc,
- .free = custom_mempool_free,
- .enqueue = custom_mempool_enqueue,
- .dequeue = custom_mempool_dequeue,
- .get_count = custom_mempool_get_count,
-};
-
-MEMPOOL_REGISTER_OPS(mempool_ops_custom);
-
-/*
* save the object number in the first 4 bytes of object data. All
* other bytes are set to 0.
*/
@@ -573,6 +480,7 @@ test_mempool(void)
struct rte_mempool *mp_cache = NULL;
struct rte_mempool *mp_nocache = NULL;
struct rte_mempool *mp_ext = NULL;
+ struct rte_mempool *mp_stack = NULL;
rte_atomic32_init(&synchro);
@@ -602,25 +510,25 @@ test_mempool(void)
}
/* create a mempool with an external handler */
- mp_ext = rte_mempool_create_empty("test_ext",
+ mp_stack = rte_mempool_create_empty("test_stack",
MEMPOOL_SIZE,
MEMPOOL_ELT_SIZE,
RTE_MEMPOOL_CACHE_MAX_SIZE, 0,
SOCKET_ID_ANY, 0);
- if (mp_ext == NULL) {
- printf("cannot allocate mp_ext mempool\n");
+ if (mp_stack == NULL) {
+ printf("cannot allocate mp_stack mempool\n");
goto err;
}
- if (rte_mempool_set_ops_byname(mp_ext, "custom_handler", NULL) < 0) {
- printf("cannot set custom handler\n");
+ if (rte_mempool_set_ops_byname(mp_stack, "stack", NULL) < 0) {
+ printf("cannot set stack handler\n");
goto err;
}
- if (rte_mempool_populate_default(mp_ext) < 0) {
- printf("cannot populate mp_ext mempool\n");
+ if (rte_mempool_populate_default(mp_stack) < 0) {
+ printf("cannot populate mp_stack mempool\n");
goto err;
}
- rte_mempool_obj_iter(mp_ext, my_obj_init, NULL);
+ rte_mempool_obj_iter(mp_stack, my_obj_init, NULL);
/* retrieve the mempool from its name */
if (rte_mempool_lookup("test_nocache") != mp_nocache) {
@@ -655,6 +563,10 @@ test_mempool(void)
if (test_mempool_xmem_misc() < 0)
goto err;
+ /* test the stack handler */
+ if (test_mempool_basic(mp_stack) < 0)
+ goto err;
+
rte_mempool_list_dump(stdout);
return 0;
--
2.5.5
next prev parent reply other threads:[~2016-06-30 7:41 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-05 18:29 [dpdk-dev] [PATCH 0/2] mempool: add stack (fifo) mempool handler David Hunt
2016-05-05 18:29 ` [dpdk-dev] [PATCH 1/2] " David Hunt
2016-05-05 21:28 ` Stephen Hemminger
2016-05-19 15:21 ` Hunt, David
2016-05-05 18:29 ` [dpdk-dev] [PATCH 2/2] test: add autotest for external mempool stack handler David Hunt
2016-05-06 8:34 ` [dpdk-dev] [PATCH 0/2] mempool: add stack (fifo) mempool handler Tan, Jianfeng
2016-05-06 23:02 ` Hunt, David
2016-05-19 14:48 ` [dpdk-dev] v2 mempool: add stack (lifo) " David Hunt
2016-05-19 14:48 ` [dpdk-dev] [PATCH v2 1/3] " David Hunt
2016-05-23 12:55 ` Olivier Matz
2016-06-15 10:10 ` Hunt, David
2016-06-17 14:18 ` Hunt, David
2016-06-20 8:17 ` Olivier Matz
2016-06-20 12:59 ` Hunt, David
2016-06-29 14:31 ` Olivier MATZ
2016-05-19 14:48 ` [dpdk-dev] [PATCH v2 2/3] mempool: make declaration of handler structs const David Hunt
2016-05-23 12:55 ` Olivier Matz
2016-05-24 14:01 ` Hunt, David
2016-05-19 14:48 ` [dpdk-dev] [PATCH v2 3/3] test: add autotest for external mempool stack handler David Hunt
2016-05-19 15:16 ` [dpdk-dev] v2 mempool: add stack (lifo) mempool handler Hunt, David
2016-06-20 13:08 ` [dpdk-dev] mempool: add stack " David Hunt
2016-06-20 13:08 ` [dpdk-dev] [PATCH v3 1/2] mempool: add stack (lifo) " David Hunt
2016-06-20 13:25 ` Jerin Jacob
2016-06-20 13:54 ` Thomas Monjalon
2016-06-20 13:58 ` Ananyev, Konstantin
2016-06-20 14:22 ` Jerin Jacob
2016-06-20 17:56 ` Ananyev, Konstantin
2016-06-21 3:35 ` Jerin Jacob
2016-06-21 9:28 ` Ananyev, Konstantin
2016-06-21 9:44 ` Olivier Matz
2016-06-21 3:42 ` Jerin Jacob
2016-06-20 13:08 ` [dpdk-dev] [PATCH v3 2/2] test: add autotest for external mempool stack handler David Hunt
2016-06-30 7:41 ` [dpdk-dev] [PATCH v4 0/2] mempool: add stack mempool handler David Hunt
2016-06-30 7:41 ` [dpdk-dev] [PATCH v4 1/2] mempool: add stack (lifo) " David Hunt
2016-06-30 7:41 ` David Hunt [this message]
2016-06-30 9:45 ` [dpdk-dev] [PATCH v4 2/2] test: migrate custom handler test to stack handler Thomas Monjalon
2016-06-30 17:36 ` Hunt, David
2016-06-30 17:46 ` Thomas Monjalon
2016-06-30 17:49 ` Hunt, David
2016-06-30 18:05 ` [dpdk-dev] [PATCH v5 0/2] mempool: add stack mempool handler David Hunt
2016-06-30 18:05 ` [dpdk-dev] [PATCH v5 1/2] mempool: add stack (lifo) " David Hunt
2016-06-30 18:05 ` [dpdk-dev] [PATCH v5 2/2] test: migrate custom handler test to stack handler David Hunt
2016-07-01 7:32 ` Olivier MATZ
2016-07-01 7:46 ` [dpdk-dev] [PATCH v6 0/2] mempool: add stack mempool handler David Hunt
2016-07-01 7:46 ` [dpdk-dev] [PATCH v6 1/2] mempool: add stack (lifo) " David Hunt
2016-07-01 7:46 ` [dpdk-dev] [PATCH v6 2/2] test: migrate custom handler test to stack handler David Hunt
2016-07-01 8:18 ` [dpdk-dev] [PATCH v6 0/2] mempool: add stack mempool handler Olivier MATZ
2016-07-01 10:41 ` Thomas Monjalon
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=1467272502-56059-3-git-send-email-david.hunt@intel.com \
--to=david.hunt@intel.com \
--cc=dev@dpdk.org \
--cc=jerin.jacob@caviumnetworks.com \
--cc=olivier.matz@6wind.com \
--cc=shreyansh.jain@nxp.com \
--cc=viktorin@rehivetech.com \
/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).