From: Yipeng Wang <yipeng1.wang@intel.com>
To: pablo.de.lara.guarch@intel.com
Cc: dev@dpdk.org, yipeng1.wang@intel.com, bruce.richardson@intel.com,
honnappa.nagarahalli@arm.com, vguvva@caviumnetworks.com,
brijesh.s.singh@gmail.com
Subject: [dpdk-dev] [PATCH v4 8/8] hash: add new API function to query the key count
Date: Mon, 9 Jul 2018 03:45:03 -0700 [thread overview]
Message-ID: <1531133103-437316-9-git-send-email-yipeng1.wang@intel.com> (raw)
In-Reply-To: <1531133103-437316-1-git-send-email-yipeng1.wang@intel.com>
Add a new function, rte_hash_count, to return the number of keys that
are currently stored in the hash table. Corresponding test functions are
added into hash_test and hash_multiwriter test.
Signed-off-by: Yipeng Wang <yipeng1.wang@intel.com>
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
lib/librte_hash/rte_cuckoo_hash.c | 24 ++++++++++++++++++++++++
lib/librte_hash/rte_hash.h | 11 +++++++++++
lib/librte_hash/rte_hash_version.map | 8 ++++++++
test/test/test_hash.c | 12 ++++++++++++
test/test/test_hash_multiwriter.c | 8 ++++++++
5 files changed, 63 insertions(+)
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 35631cc..bb67ade 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -370,6 +370,30 @@ rte_hash_secondary_hash(const hash_sig_t primary_hash)
return primary_hash ^ ((tag + 1) * alt_bits_xor);
}
+int32_t
+rte_hash_count(const struct rte_hash *h)
+{
+ uint32_t tot_ring_cnt, cached_cnt = 0;
+ uint32_t i, ret;
+
+ if (h == NULL)
+ return -EINVAL;
+
+ if (h->multi_writer_support) {
+ tot_ring_cnt = h->entries + (RTE_MAX_LCORE - 1) *
+ (LCORE_CACHE_SIZE - 1);
+ for (i = 0; i < RTE_MAX_LCORE; i++)
+ cached_cnt += h->local_free_slots[i].len;
+
+ ret = tot_ring_cnt - rte_ring_count(h->free_slots) -
+ cached_cnt;
+ } else {
+ tot_ring_cnt = h->entries;
+ ret = tot_ring_cnt - rte_ring_count(h->free_slots);
+ }
+ return ret;
+}
+
/* Read write locks implemented using rte_rwlock */
static inline void
__hash_rw_writer_lock(const struct rte_hash *h)
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index ecb49e4..1f1a276 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -127,6 +127,17 @@ void
rte_hash_reset(struct rte_hash *h);
/**
+ * Return the number of keys in the hash table
+ * @param h
+ * Hash table to query from
+ * @return
+ * - -EINVAL if parameters are invalid
+ * - A value indicating how many keys were inserted in the table.
+ */
+int32_t
+rte_hash_count(const struct rte_hash *h);
+
+/**
* Add a key-value pair to an existing hash table.
* This operation is not multi-thread safe
* and should only be called from one thread.
diff --git a/lib/librte_hash/rte_hash_version.map b/lib/librte_hash/rte_hash_version.map
index 52a2576..e216ac8 100644
--- a/lib/librte_hash/rte_hash_version.map
+++ b/lib/librte_hash/rte_hash_version.map
@@ -45,3 +45,11 @@ DPDK_16.07 {
rte_hash_get_key_with_position;
} DPDK_2.2;
+
+
+DPDK_18.08 {
+ global:
+
+ rte_hash_count;
+
+} DPDK_16.07;
diff --git a/test/test/test_hash.c b/test/test/test_hash.c
index edf41f5..b3db9fd 100644
--- a/test/test/test_hash.c
+++ b/test/test/test_hash.c
@@ -1103,6 +1103,7 @@ static int test_average_table_utilization(void)
unsigned i, j;
unsigned added_keys, average_keys_added = 0;
int ret;
+ unsigned int cnt;
printf("\n# Running test to determine average utilization"
"\n before adding elements begins to fail\n");
@@ -1121,13 +1122,24 @@ static int test_average_table_utilization(void)
for (i = 0; i < ut_params.key_len; i++)
simple_key[i] = rte_rand() % 255;
ret = rte_hash_add_key(handle, simple_key);
+ if (ret < 0)
+ break;
}
+
if (ret != -ENOSPC) {
printf("Unexpected error when adding keys\n");
rte_hash_free(handle);
return -1;
}
+ cnt = rte_hash_count(handle);
+ if (cnt != added_keys) {
+ printf("rte_hash_count returned wrong value %u, %u,"
+ "%u\n", j, added_keys, cnt);
+ rte_hash_free(handle);
+ return -1;
+ }
+
average_keys_added += added_keys;
/* Reset the table */
diff --git a/test/test/test_hash_multiwriter.c b/test/test/test_hash_multiwriter.c
index ef5fce3..f182f40 100644
--- a/test/test/test_hash_multiwriter.c
+++ b/test/test/test_hash_multiwriter.c
@@ -116,6 +116,7 @@ test_hash_multiwriter(void)
uint32_t duplicated_keys = 0;
uint32_t lost_keys = 0;
+ uint32_t count;
snprintf(name, 32, "test%u", calledCount++);
hash_params.name = name;
@@ -163,6 +164,13 @@ test_hash_multiwriter(void)
NULL, CALL_MASTER);
rte_eal_mp_wait_lcore();
+ count = rte_hash_count(handle);
+ if (count != rounded_nb_total_tsx_insertion) {
+ printf("rte_hash_count returned wrong value %u, %d\n",
+ rounded_nb_total_tsx_insertion, count);
+ goto err3;
+ }
+
while (rte_hash_iterate(handle, &next_key, &next_data, &iter) >= 0) {
/* Search for the key in the list of keys added .*/
i = *(const uint32_t *)next_key;
--
2.7.4
next prev parent reply other threads:[~2018-07-09 17:52 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-08 10:51 [dpdk-dev] [PATCH v1 0/3] Add read-write concurrency to rte_hash library Yipeng Wang
2018-06-08 10:51 ` [dpdk-dev] [PATCH v1 1/3] hash: add read and write concurrency support Yipeng Wang
2018-06-26 14:59 ` De Lara Guarch, Pablo
2018-06-08 10:51 ` [dpdk-dev] [PATCH v1 2/3] test: add test case for read write concurrency Yipeng Wang
2018-06-26 15:48 ` De Lara Guarch, Pablo
2018-06-08 10:51 ` [dpdk-dev] [PATCH v1 3/3] hash: add new API function to query the key count Yipeng Wang
2018-06-26 16:11 ` De Lara Guarch, Pablo
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 0/6] Add read-write concurrency to rte_hash library Yipeng Wang
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 1/6] hash: make duplicated code into functions Yipeng Wang
2018-07-06 10:04 ` De Lara Guarch, Pablo
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 2/6] hash: add read and write concurrency support Yipeng Wang
2018-07-06 17:11 ` De Lara Guarch, Pablo
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 3/6] test: add tests in hash table perf test Yipeng Wang
2018-07-06 17:17 ` De Lara Guarch, Pablo
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 4/6] test: add test case for read write concurrency Yipeng Wang
2018-07-06 17:31 ` De Lara Guarch, Pablo
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 5/6] hash: fix to have more accurate key slot size Yipeng Wang
2018-07-06 17:32 ` De Lara Guarch, Pablo
2018-06-29 12:24 ` [dpdk-dev] [PATCH v2 6/6] hash: add new API function to query the key count Yipeng Wang
2018-07-06 17:36 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 0/8] Add read-write concurrency to rte_hash library Yipeng Wang
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 1/8] hash: fix multiwriter lock memory allocation Yipeng Wang
2018-07-09 11:26 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 2/8] hash: fix a multi-writer bug Yipeng Wang
2018-07-09 14:16 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 3/8] hash: fix to have more accurate key slot size Yipeng Wang
2018-07-09 14:20 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 4/8] hash: make duplicated code into functions Yipeng Wang
2018-07-09 14:25 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 5/8] hash: add read and write concurrency support Yipeng Wang
2018-07-09 14:28 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 6/8] test: add tests in hash table perf test Yipeng Wang
2018-07-09 15:33 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 7/8] test: add test case for read write concurrency Yipeng Wang
2018-07-09 16:24 ` De Lara Guarch, Pablo
2018-07-06 19:46 ` [dpdk-dev] [PATCH v3 8/8] hash: add new API function to query the key count Yipeng Wang
2018-07-09 16:22 ` De Lara Guarch, Pablo
2018-07-09 10:44 ` [dpdk-dev] [PATCH v4 0/8] Add read-write concurrency to rte_hash library Yipeng Wang
2018-07-09 10:44 ` [dpdk-dev] [PATCH v4 1/8] hash: fix multiwriter lock memory allocation Yipeng Wang
2018-07-09 10:44 ` [dpdk-dev] [PATCH v4 2/8] hash: fix a multi-writer race condition Yipeng Wang
2018-07-09 10:44 ` [dpdk-dev] [PATCH v4 3/8] hash: fix key slot size accuracy Yipeng Wang
2018-07-09 10:44 ` [dpdk-dev] [PATCH v4 4/8] hash: make duplicated code into functions Yipeng Wang
2018-07-09 10:45 ` [dpdk-dev] [PATCH v4 5/8] hash: add read and write concurrency support Yipeng Wang
2018-07-09 10:45 ` [dpdk-dev] [PATCH v4 6/8] test: add tests in hash table perf test Yipeng Wang
2018-07-09 10:45 ` [dpdk-dev] [PATCH v4 7/8] test: add test case for read write concurrency Yipeng Wang
2018-07-09 10:45 ` Yipeng Wang [this message]
2018-07-10 18:00 ` [dpdk-dev] [PATCH v4 0/8] Add read-write concurrency to rte_hash library Honnappa Nagarahalli
2018-07-12 1:31 ` Wang, Yipeng1
2018-07-12 2:36 ` Honnappa Nagarahalli
2018-07-13 1:47 ` Wang, Yipeng1
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 " Yipeng Wang
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 1/8] hash: fix multiwriter lock memory allocation Yipeng Wang
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 2/8] hash: fix a multi-writer race condition Yipeng Wang
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 3/8] hash: fix key slot size accuracy Yipeng Wang
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 4/8] hash: make duplicated code into functions Yipeng Wang
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 5/8] hash: add read and write concurrency support Yipeng Wang
2018-07-11 20:49 ` Stephen Hemminger
2018-07-12 1:22 ` Wang, Yipeng1
2018-07-12 20:30 ` Thomas Monjalon
2018-07-13 1:55 ` Wang, Yipeng1
2018-08-17 12:51 ` ASM
2018-07-10 16:59 ` [dpdk-dev] [PATCH v5 6/8] test: add tests in hash table perf test Yipeng Wang
2018-07-10 17:00 ` [dpdk-dev] [PATCH v5 7/8] test: add test case for read write concurrency Yipeng Wang
2018-07-10 17:00 ` [dpdk-dev] [PATCH v5 8/8] hash: add new API function to query the key count Yipeng Wang
2018-07-12 21:03 ` [dpdk-dev] [PATCH v5 0/8] Add read-write concurrency to rte_hash library 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=1531133103-437316-9-git-send-email-yipeng1.wang@intel.com \
--to=yipeng1.wang@intel.com \
--cc=brijesh.s.singh@gmail.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=honnappa.nagarahalli@arm.com \
--cc=pablo.de.lara.guarch@intel.com \
--cc=vguvva@caviumnetworks.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).