DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kamalakshitha Aligeri <kamalakshitha.aligeri@arm.com>
To: bruce.richardson@intel.com, mb@smartsharesystems.com,
	konstantin.ananyev@huawei.com, olivier.matz@6wind.com,
	andrew.rybchenko@oktetlabs.ru, Honnappa.Nagarahalli@arm.com
Cc: dev@dpdk.org, nd@arm.com,
	Kamalakshitha Aligeri <kamalakshitha.aligeri@arm.com>
Subject: [RFCv2 2/2] test/mempool: add zero-copy API's
Date: Tue, 24 Jan 2023 17:49:36 +0000	[thread overview]
Message-ID: <20230124174936.190800-2-kamalakshitha.aligeri@arm.com> (raw)
In-Reply-To: <20230124174936.190800-1-kamalakshitha.aligeri@arm.com>

Added mempool test cases with zero-copy get and put API's

Signed-off-by: Kamalakshitha Aligeri <kamalakshitha.aligeri@arm.com>
---
Link: https://patchwork.dpdk.org/project/dpdk/patch/20221227151700.80887-1-mb@smartsharesystems.com/
1. Added mempool test cases with zero-copy get and put API's

 app/test/test_mempool.c | 124 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 122 insertions(+), 2 deletions(-)

diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c
index 8e493eda47..a635a514a7 100644
--- a/app/test/test_mempool.c
+++ b/app/test/test_mempool.c
@@ -72,6 +72,122 @@ my_obj_init(struct rte_mempool *mp, __rte_unused void *arg,
 	*objnum = i;
 }
 
+/* basic tests with zero-copy API's (done on one core) */
+static int
+test_mempool_basic_zc_api(struct rte_mempool *mp, int use_external_cache)
+{
+	uint32_t *objnum;
+	void **objtable;
+	void *obj, *obj2;
+	char *obj_data;
+	int ret = 0;
+	unsigned int i, j;
+	int offset;
+	struct rte_mempool_cache *cache;
+	void **cache_objs;
+
+	if (use_external_cache) {
+		/* Create a user-owned mempool cache. */
+		cache = rte_mempool_cache_create(RTE_MEMPOOL_CACHE_MAX_SIZE,
+				SOCKET_ID_ANY);
+		if (cache == NULL)
+			RET_ERR();
+	} else {
+		/* May be NULL if cache is disabled. */
+		cache = rte_mempool_default_cache(mp, rte_lcore_id());
+	}
+
+	/* dump the mempool status */
+	rte_mempool_dump(stdout, mp);
+
+	printf("get an object\n");
+	cache_objs = rte_mempool_cache_zc_get_bulk(cache, mp, 1);
+	obj = *cache_objs;
+	rte_mempool_dump(stdout, mp);
+
+	/* tests that improve coverage */
+	printf("get object count\n");
+	/* We have to count the extra caches, one in this case. */
+	offset = use_external_cache ? 1 * cache->len : 0;
+	if (rte_mempool_avail_count(mp) + offset != MEMPOOL_SIZE - 1)
+		GOTO_ERR(ret, out);
+
+	printf("get private data\n");
+	if (rte_mempool_get_priv(mp) != (char *)mp +
+			RTE_MEMPOOL_HEADER_SIZE(mp, mp->cache_size))
+		GOTO_ERR(ret, out);
+
+#ifndef RTE_EXEC_ENV_FREEBSD /* rte_mem_virt2iova() not supported on bsd */
+	printf("get physical address of an object\n");
+	if (rte_mempool_virt2iova(obj) != rte_mem_virt2iova(obj))
+		GOTO_ERR(ret, out);
+#endif
+
+	printf("put the object back\n");
+	cache_objs = rte_mempool_cache_zc_put_bulk(cache, mp, 1);
+	rte_memcpy(cache_objs, &obj, sizeof(void *));
+	rte_mempool_dump(stdout, mp);
+
+	printf("get 2 objects\n");
+	cache_objs = rte_mempool_cache_zc_get_bulk(cache, mp, 1);
+	obj = *cache_objs;
+	cache_objs = rte_mempool_cache_zc_get_bulk(cache, mp, 1);
+	obj2 = *cache_objs;
+	rte_mempool_dump(stdout, mp);
+
+	printf("put the objects back\n");
+	cache_objs = rte_mempool_cache_zc_put_bulk(cache, mp, 1);
+	rte_memcpy(cache_objs, &obj, sizeof(void *));
+	cache_objs = rte_mempool_cache_zc_put_bulk(cache, mp, 1);
+	rte_memcpy(cache_objs, &obj2, sizeof(void *));
+	rte_mempool_dump(stdout, mp);
+
+	/*
+	 * get many objects: we cannot get them all because the cache
+	 * on other cores may not be empty.
+	 */
+	objtable = malloc(MEMPOOL_SIZE * sizeof(void *));
+	if (objtable == NULL)
+		GOTO_ERR(ret, out);
+
+	for (i = 0; i < MEMPOOL_SIZE; i++) {
+		cache_objs = rte_mempool_cache_zc_get_bulk(cache, mp, 1);
+		objtable[i] = *cache_objs;
+	}
+
+	/*
+	 * for each object, check that its content was not modified,
+	 * and put objects back in pool
+	 */
+	while (i--) {
+		obj = objtable[i];
+		obj_data = obj;
+		objnum = obj;
+		if (*objnum > MEMPOOL_SIZE) {
+			printf("bad object number(%d)\n", *objnum);
+			ret = -1;
+			break;
+		}
+		for (j = sizeof(*objnum); j < mp->elt_size; j++) {
+			if (obj_data[j] != 0)
+				ret = -1;
+		}
+		cache_objs = rte_mempool_cache_zc_put_bulk(cache, mp, 1);
+		rte_memcpy(cache_objs, &objtable[i], sizeof(void *));
+	}
+
+	free(objtable);
+	if (ret == -1)
+		printf("objects were modified!\n");
+
+out:
+	if (use_external_cache) {
+		rte_mempool_cache_flush(cache, mp);
+		rte_mempool_cache_free(cache);
+	}
+
+	return ret;
+}
 /* basic tests (done on one core) */
 static int
 test_mempool_basic(struct rte_mempool *mp, int use_external_cache)
@@ -982,8 +1098,12 @@ test_mempool(void)
 	if (test_mempool_basic(mp_nocache, 0) < 0)
 		GOTO_ERR(ret, err);
 
-	/* basic tests with cache */
-	if (test_mempool_basic(mp_cache, 0) < 0)
+	/* basic tests with zero-copy API's */
+	if (test_mempool_basic_zc_api(mp_cache, 0) < 0)
+		GOTO_ERR(ret, err);
+
+	/* basic tests with user-owned cache and zero-copy API's */
+	if (test_mempool_basic_zc_api(mp_nocache, 1) < 0)
 		GOTO_ERR(ret, err);
 
 	/* basic tests with user-owned cache */
-- 
2.25.1


      reply	other threads:[~2023-01-24 17:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 17:49 [RFCv2 1/2] net/i40e: replace get and put functions Kamalakshitha Aligeri
2023-01-24 17:49 ` Kamalakshitha Aligeri [this message]

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=20230124174936.190800-2-kamalakshitha.aligeri@arm.com \
    --to=kamalakshitha.aligeri@arm.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@huawei.com \
    --cc=mb@smartsharesystems.com \
    --cc=nd@arm.com \
    --cc=olivier.matz@6wind.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).