lib/hash,lib/rcu: feature hidden key count in hash
PATCH 1/1 lib/hash,lib/rcu: feature hidden key count in hash
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using rte_hash_count with rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unless rte_rcu_qsbr_dq_reclaim is called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.
---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>
--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)
lib/hash/rte_cuckoo_hash.c +9 -0
@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL ) +return -EINVAL ; + +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {
lib/hash/rte_hash.h +13 -0
@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h); + +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. +*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h
lib/hash/version.map +1 -0
@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count; rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;
lib/rcu/rte_rcu_qsbr.c +8 -0
@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{ +return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)
lib/rcu/rte_rcu_qsbr.h +11 -0
@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available); +/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq); +/** * Delete a defer queue. *
lib/rcu/version.map +1 -0
@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;
Signature · 1 line
2.34.1
Any review please?
07/02/2024 16:33, Abdullah Ömer Yamaç:
Quoted 136 lines
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +9
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL ) +return -EINVAL ; + +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +13
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h); + +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. +*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count; rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +8
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{ +return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +11
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available); +/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq); +/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;
Hi Abdullah,
Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with RTE_HASH_QSBR_MODE_SYNC mode i.e. without defer queue.
Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )
input arguments must be checked since this is a public API, the same is true for rte_rcu_qsbr_dq_count()
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;
why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table.
did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0
lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;
new API must introduced as an experimental API. The same is true for rte_rcu_qsbr_dq_count()
Quoted 56 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +8
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{ +return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +11
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available); +/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq); +/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;
Signature · 2 lines
Regards, Vladimir
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by rte_hash_count - defer queue size.
I think if you need a non-blocking and multithreaded hash table, an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
Quoted 163 lines · Vladimir
Hi Abdullah,
Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr
is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq,
Quoted 8 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq,unsigned int n,
Quoted 19 lines
lib/rcu/rte_rcu_qsbr.c +8
-0return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{ +return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0lib/rcu/rte_rcu_qsbr.h int · line 795
Quoted 2 lines
lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int*available);
Quoted 20 lines
lib/rcu/rte_rcu_qsbr.h +11
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq); +/** * Delete a defer queue. * lib/rcu/version.map +0
-0lib/rcu/version.map DPDK_24 { · line 11
Quoted 7 lines
lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;--
Regards,
Vladimir
Quoted 9 lines · Abdullah Ömer Yamaç
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.
The entries in the defer queue are not reclaimed (there is a probability that all of them can be reclaimed) and hence they are not available for allocation. So, rte_hash_count - defer queue size might not give you the correct number you are expecting.
Currently, there is no API in hash library that forces a reclaim. Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to rte_hash_count should provide the exact count you are looking for.
Quoted 117 lines
I think if you need a non-blocking and multithreaded hash table, an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <[email protected]> wrote:
Hi Abdullah,Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 11 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; }
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +5
-0+/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{
Please validate dq here.
Quoted 14 lines
Quoted 14 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available);
Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);
Agree on the need for this API in RCU
Quoted 21 lines
Quoted 16 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;Signature · 2 lines
Regards, Vladimir
I appreciate that you gave me suggestions and comments. I will make changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 24 lines · Honnappa Nagarahalli
Quoted 3 lines
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 6 lines · wrote:
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say
the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size. The entries in the defer queue are not reclaimed (there is a probability that all of them can be reclaimed) and hence they are not available for allocation. So,rte_hash_count- defer queue size might not give you the correct number you are expecting.
Quoted 4 lines
Currently, there is no API in hash library that forces a reclaim. Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.
You are right; no API in the hash library forces a reclaim. In my application, I periodically call rte_count to retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?
Quoted 179 lines
Quoted 2 lines
I think if you need a non-blocking and multithreaded hash table, an
RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
Quoted 6 lines
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <
Quoted 5 lines · [email protected]> wrote:
Hi Abdullah,
Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr
is enabled
Quoted 93 lines
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq
Quoted 8 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq*dq, unsigned int n,
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +5
-0return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 5 lines
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int Quoted 8 lines
lib/rcu/rte_rcu_qsbr.h int · line 795
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +0
-0rte_rcu_qsbr_dq_delete(struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int*available);
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 9 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +0
-0lib/rcu/version.map DPDK_24 { · line 11
Quoted 7 lines
lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;--
Regards,
Vladimir
Quoted 13 lines · Abdullah Ömer Yamaç
I appreciate that you gave me suggestions and comments. I will make changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 4 lines · Honnappa Nagarahalli
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
Hello,
Quoted 7 lines
Quoted 3 lines
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.The entries in the defer queue are not reclaimed (there is a probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Currently, there is no API in hash library that forces a reclaim. Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.
You are right; no API in the hash library forces a reclaim. In my application, I periodically callrte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?
Retrieving the defer queue size will be cheaper. However, calling the reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
I am also wondering if a reclaim API in hash library is needed. Why not call rte_rcu_qsbr_dq_reclaim API from the application?
Quoted 172 lines
Quoted 117 lines
I think if you need a non-blocking and multithreaded hash table, an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <[email protected]> wrote:
Hi Abdullah,Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 11 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; }Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +5
-0+/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 14 lines
Quoted 14 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available);Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 16 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;Signature · 2 lines
Regards, Vladimir
Quoted 50 lines · Honnappa Nagarahalli
Quoted 3 lines
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 2 lines · wrote:
I appreciate that you gave me suggestions and comments. I will make
changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 2 lines
On Tue, Feb 20, 2024 at 2:35 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 6 lines · wrote:
Quoted 6 lines
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's
say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.Quoted 1 line
The entries in the defer queue are not reclaimed (there is a probability
that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Quoted 2 lines
Currently, there is no API in hash library that forces a reclaim. Does
it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.Quoted 1 line
You are right; no API in the hash library forces a reclaim. In my
application, I periodically call
rte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?
Retrieving the defer queue size will be cheaper. However, calling the reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
Quoted 3 lines
I am also wondering if a reclaim API in hash library is needed. Why not call
rte_rcu_qsbr_dq_reclaimAPI from the application?
The reason is simple. struct rte_hash *h is an internal structure and we cannot access the h->dq. So it is not possible to call reclaim.
Quoted 189 lines
Quoted 4 lines
Quoted 4 lines
I think if you need a non-blocking and multithreaded hash table, an
RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
Quoted 6 lines
Quoted 6 lines
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Hi Abdullah,
Could you please tell more about use cases where this API may be
useful?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
a new API to get the hidden key count in the hash table if the rcu
qsbr is enabled
Quoted 2 lines
Quoted 2 lines
Here in commit message and down below in doxygen comments, I think
this
Quoted 7 lines
Quoted 7 lines
statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 1 line · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the
hash
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not inthe
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
free queue. Unless
rte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. ThereforeI
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; }Quoted 5 lines
Quoted 5 lines
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c +4
-0+int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same
is
Quoted 18 lines
Quoted 18 lines
true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 15 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);Quoted 9 lines
Quoted 9 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h);
Quoted 9 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table.
Quoted 19 lines
Quoted 19 lines
did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 8 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq
Quoted 8 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq*dq, unsigned int n,
Quoted 10 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +5
-0return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int Quoted 8 lines
lib/rcu/rte_rcu_qsbr.h int · line 795
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +0
-0rte_rcu_qsbr_dq_delete(struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int*available);
Quoted 35 lines
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 9 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +0
-0lib/rcu/version.map DPDK_24 { · line 11
Quoted 7 lines
lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;--
Regards,
Vladimir
Quoted 23 lines · Abdullah Ömer Yamaç
Quoted 14 lines · Honnappa Nagarahalli
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
I appreciate that you gave me suggestions and comments. I will make changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 7 lines · Honnappa Nagarahalli
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.
Quoted 8 lines
Quoted 4 lines
The entries in the defer queue are not reclaimed (there is a probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Currently, there is no API in hash library that forces a reclaim. Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.
You are right; no API in the hash library forces a reclaim. In my application, I periodically callrte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?Retrieving the defer queue size will be cheaper. However, calling the reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
I am also wondering if a reclaim API in hash library is needed. Why not call
rte_rcu_qsbr_dq_reclaimAPI from the application? The reason is simple. structrte_hash*h is an internal structure and we cannot access theh->dq. So it is not possible to call reclaim.
Ack. This will be just a wrapper around the rte_rcu_qsbr_dq_reclaim.
Quoted 175 lines
Quoted 174 lines
Quoted 119 lines
I think if you need a non-blocking and multithreaded hash table, an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <[email protected]> wrote:
Hi Abdullah,Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 11 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; }Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +5
-0+/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 14 lines
Quoted 14 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available);Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 16 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;Signature · 2 lines
Regards, Vladimir
As a final decision, I will add a new hash API that forces the reclaim. Is it ok for everyone?
Quoted 259 lines · Honnappa Nagarahalli
Quoted 3 lines
On Feb 21, 2024, at 3:51 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 4 lines · wrote:
On Wed, Feb 21, 2024 at 6:24 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <
Quoted 2 lines · [email protected]> wrote:
Quoted 2 lines
I appreciate that you gave me suggestions and comments. I will make
changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 2 lines
Quoted 2 lines
On Tue, Feb 20, 2024 at 2:35 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <
Quoted 6 lines · [email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's
say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.Quoted 1 line
Quoted 1 line
The entries in the defer queue are not reclaimed (there is a
probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Quoted 2 lines
Quoted 2 lines
Currently, there is no API in hash library that forces a reclaim. Does
it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.Quoted 1 line
Quoted 1 line
You are right; no API in the hash library forces a reclaim. In my
application, I periodically call
rte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?Quoted 1 line
Retrieving the defer queue size will be cheaper. However, calling the
reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
Quoted 2 lines
I am also wondering if a reclaim API in hash library is needed. Why not
call
rte_rcu_qsbr_dq_reclaimAPI from the application?Quoted 1 line
The reason is simple. struct
rte_hash*h is an internal structure and wecannot access the
h->dq. So it is not possible to call reclaim. Ack. This will be just a wrapper around therte_rcu_qsbr_dq_reclaim.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
I think if you need a non-blocking and multithreaded hash table, an
RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Hi Abdullah,
Could you please tell more about use cases where this API may be
useful?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
a new API to get the hidden key count in the hash table if the rcu
qsbr is enabled
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Here in commit message and down below in doxygen comments, I think
this
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 1 line · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the
hash
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
table if the rcu qsbr is enabled. When using
rte_hash_countwithrcu
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
qsbr enabled, it will return the number of elements that are not
in the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
free queue. Unless
rte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed.Therefore I
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)Quoted 1 line
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/hash/rte_cuckoo_hash.cQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
index
70456754c4..3553f3efc7100644lib/hash/rte_cuckoo_hash.c +0
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; }Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c +4
-0+int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same
is
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 15 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 198
Quoted 3 lines
lib/hash/rte_hash.h +3
-0+ +/** +* Return the number of records in the defer queue of the hash table
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 6 lines
lib/hash/rte_hash.h +6
-0+* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct
Quoted 8 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct
rte_rcu_qsbr_dq*dq, unsigned int n,Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct · line 457
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +5
-0return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ Quoted 8 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.h int · line 794
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +0
-0int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned intn,
Quoted 1 line
Quoted 1 line
Quoted 1 line
lib/rcu/rte_rcu_qsbr.h int · line 795
Quoted 1 line
lib/rcu/rte_rcu_qsbr.h +0
-0unsigned int *freed, unsigned int *pending, unsigned int*available);
Quoted 36 lines
Quoted 35 lines
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h int · line 805
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 9 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +0
-0lib/rcu/version.map DPDK_24 { · line 11
Quoted 7 lines
lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;--
Regards,
Vladimir
Quoted 5 lines · Abdullah Ömer Yamaç
As a final decision, I will add a new hash API that forces the reclaim. Is it ok for everyone?
Ack from my side
Quoted 211 lines · Honnappa Nagarahalli
Quoted 23 lines · Abdullah Ömer Yamaç
Quoted 14 lines · Honnappa Nagarahalli
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
I appreciate that you gave me suggestions and comments. I will make changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 7 lines · Honnappa Nagarahalli
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.Quoted 8 lines
Quoted 4 lines
The entries in the defer queue are not reclaimed (there is a probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Currently, there is no API in hash library that forces a reclaim. Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.
You are right; no API in the hash library forces a reclaim. In my application, I periodically callrte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?Retrieving the defer queue size will be cheaper. However, calling the reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
I am also wondering if a reclaim API in hash library is needed. Why not call
rte_rcu_qsbr_dq_reclaimAPI from the application? The reason is simple. structrte_hash*h is an internal structure and we cannot access theh->dq. So it is not possible to call reclaim.Ack. This will be just a wrapper around the
rte_rcu_qsbr_dq_reclaim.Quoted 175 lines
Quoted 174 lines
Quoted 119 lines
I think if you need a non-blocking and multithreaded hash table, an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <[email protected]> wrote:
Hi Abdullah,Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 11 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; }Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +5
-0+/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 14 lines
Quoted 14 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available);Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 16 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;Signature · 2 lines
Regards, Vladimir
While I was implementing the new API, I realized one issue, and it would be good to discuss it here. First of all rte_rcu_qsbr_dq_reclaim function checks the state of the qsbr values. It means that all threads should report the quiescent states. It conflicts with my aim.
Let's think about below scenario:
Eight threads use a hash table and periodically report their quiescent states. One additional thread (main thread) periodically reports the hash size. I implemented the reclaim function in that thread. I mean, the main thread calls reclaim before the rte_hash_count.
Here is the exceptional case that I couldn't retrieve the correct hash size:
Assume that 6 of 8 threads reported quiescent states and 2 of them are still working on some process and haven't reported quiescent states yet. The main thread calls reclaim functions every time, but elements in dq will not be freed because 2 of the worker threads haven't reported their states (especially if they are waiting for some packets). So, my first proposed method is more suitable for this case. Any idea?
Quoted 278 lines · Honnappa Nagarahalli
Quoted 3 lines
On Feb 22, 2024, at 6:39 AM, Abdullah Ömer Yamaç <[email protected]>
Quoted 2 lines · wrote:
As a final decision, I will add a new hash API that forces the reclaim.
Is it ok for everyone?
Ack from my sideQuoted 2 lines
On Thu, Feb 22, 2024 at 5:37 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
On Feb 21, 2024, at 3:51 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
On Wed, Feb 21, 2024 at 6:24 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <
Quoted 2 lines · [email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
I appreciate that you gave me suggestions and comments. I will make
changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Tue, Feb 20, 2024 at 2:35 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <
Quoted 6 lines · [email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data
(let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.Quoted 1 line
Quoted 1 line
Quoted 1 line
The entries in the defer queue are not reclaimed (there is a
probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Currently, there is no API in hash library that forces a reclaim.
Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.Quoted 1 line
Quoted 1 line
Quoted 1 line
You are right; no API in the hash library forces a reclaim. In my
application, I periodically call
rte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?Quoted 1 line
Quoted 1 line
Retrieving the defer queue size will be cheaper. However, calling the
reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
Quoted 2 lines
Quoted 2 lines
I am also wondering if a reclaim API in hash library is needed. Why
not call
rte_rcu_qsbr_dq_reclaimAPI from the application?Quoted 1 line
Quoted 1 line
The reason is simple. struct
rte_hash*h is an internal structure andwe cannot access the
h->dq. So it is not possible to call reclaim.Quoted 6 lines
Ack. This will be just a wrapper around the
rte_rcu_qsbr_dq_reclaim.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
I think if you need a non-blocking and multithreaded hash table,
an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hi Abdullah,
Could you please tell more about use cases where this API may be
useful?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
a new API to get the hidden key count in the hash table if the
rcu qsbr is enabled
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Here in commit message and down below in doxygen comments, I think
this
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 1 line · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in
the hash
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
table if the rcu qsbr is enabled. When using
rte_hash_countwithrcu
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
qsbr enabled, it will return the number of elements that are not
in the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
free queue. Unless
rte_rcu_qsbr_dq_reclaimis called, the numberof
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
elements in the defer queue will not be counted and freed.
Therefore I
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
added a new API to get the number of hidden (defer queue)
elements
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
in the hash table. Then the user can calculate the total number
of
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
elements that are available in the hash table.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/hash/rte_cuckoo_hash.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash
Quoted 4 lines
index
70456754c4..3553f3efc7100644lib/hash/rte_cuckoo_hash.c +0
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash*h)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the
same is
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 15 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 198
Quoted 3 lines
lib/hash/rte_hash.h +3
-0+ +/** +* Return the number of records in the defer queue of the hash table
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 6 lines
lib/hash/rte_hash.h +6
-0+* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
did you mean how many records are kept in defer queue?
Quoted 9 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/hash/version.map DPDK_24 { · line 12
Quoted 7 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true
for
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
rte_rcu_qsbr_dq_count()lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct
Quoted 8 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct
rte_rcu_qsbr_dq*dq, unsigned int n,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct · line 457
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +5
-0return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.h int · line 794
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +0
-0int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsignedint n,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
lib/rcu/rte_rcu_qsbr.h int · line 795
Quoted 1 line
lib/rcu/rte_rcu_qsbr.h +0
-0unsigned int *freed, unsigned int *pending, unsigned int*available);
Quoted 37 lines
Quoted 36 lines
Quoted 35 lines
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h int · line 805
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 9 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +0
-0lib/rcu/version.map DPDK_24 { · line 11
Quoted 7 lines
lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;--
Regards,
Vladimir
Quoted 11 lines · Abdullah Ömer Yamaç
While I was implementing the new API, I realized one issue, and it would be good to discuss it here. First of all
rte_rcu_qsbr_dq_reclaimfunction checks the state of the qsbr values. It means that all threads should report the quiescent states. It conflicts with my aim.Let's think about below scenario:
Eight threads use a hash table and periodically report their quiescent states. One additional thread (main thread) periodically reports the hash size. I implemented the reclaim function in that thread. I mean, the main thread calls reclaim before therte_hash_count.Here is the exceptional case that I couldn't retrieve the correct hash size:
Assume that 6 of 8 threads reported quiescent states and 2 of them are still working on some process and haven't reported quiescent states yet. The main thread calls reclaim functions every time, but elements in dq will not be freed because 2 of the worker threads haven't reported their states (especially if they are waiting for some packets). So, my first proposed method is more suitable for this case. Any idea?
If 2 out of 8 threads have not reported their quiescent state then the elements that have not been acknowledged by those 2 threads cannot be reclaimed and cannot be allocated for further use. Using this you can calculate the most accurate number of entries in the hash table available for allocation.
Quoted 221 lines · Honnappa Nagarahalli
Quoted 5 lines · Abdullah Ömer Yamaç
As a final decision, I will add a new hash API that forces the reclaim. Is it ok for everyone?
Ack from my side
Quoted 211 lines · Honnappa Nagarahalli
Quoted 23 lines · Abdullah Ömer Yamaç
Quoted 14 lines · Honnappa Nagarahalli
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
I appreciate that you gave me suggestions and comments. I will make changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 7 lines · Honnappa Nagarahalli
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <[email protected]> wrote:
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data (let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.Quoted 8 lines
Quoted 4 lines
The entries in the defer queue are not reclaimed (there is a probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Currently, there is no API in hash library that forces a reclaim. Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.
You are right; no API in the hash library forces a reclaim. In my application, I periodically callrte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?Retrieving the defer queue size will be cheaper. However, calling the reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
I am also wondering if a reclaim API in hash library is needed. Why not call
rte_rcu_qsbr_dq_reclaimAPI from the application? The reason is simple. structrte_hash*h is an internal structure and we cannot access theh->dq. So it is not possible to call reclaim.Ack. This will be just a wrapper around the
rte_rcu_qsbr_dq_reclaim.Quoted 175 lines
Quoted 174 lines
Quoted 119 lines
I think if you need a non-blocking and multithreaded hash table, an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <[email protected]> wrote:
Hi Abdullah,Could you please tell more about use cases where this API may be useful?
Quoted 1 line
a new API to get the hidden key count in the hash table if the rcu qsbr is enabled
Here in commit message and down below in doxygen comments, I think this statement should be more specific because rcu can be created with
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 31 lines · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in the hash table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu qsbr enabled, it will return the number of elements that are not in the free queue. Unlessrte_rcu_qsbr_dq_reclaimis called, the number of elements in the defer queue will not be counted and freed. Therefore I added a new API to get the number of hidden (defer queue) elements in the hash table. Then the user can calculate the total number of elements that are available in the hash table.Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash *h)return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the same is true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash *h) · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 10 lines
lib/hash/rte_hash.h +9
-0+ +/** +* Return the number of records in the defer queue of the hash table +* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table. did you mean how many records are kept in defer queue?
Quoted 12 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0lib/hash/version.map DPDK_24 { · line 12
Quoted 4 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true for
rte_rcu_qsbr_dq_count()Quoted 11 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,return 0 ; }Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, · line 457
Quoted 5 lines
lib/rcu/rte_rcu_qsbr.c +5
-0+/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 14 lines
Quoted 14 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available);Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h int · line 806
Quoted 10 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 16 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;Signature · 2 lines
Regards, Vladimir
Sorry for the late reply. I understood what you mean. I will create only the reclaim API for the hash library. Thanks for the explanation.
Quoted 313 lines · Honnappa Nagarahalli
Quoted 3 lines
On Feb 28, 2024, at 5:44 AM, Abdullah Ömer Yamaç <[email protected]>
Quoted 2 lines · wrote:
While I was implementing the new API, I realized one issue, and it would
be good to discuss it here. First of all
rte_rcu_qsbr_dq_reclaimfunction checks the state of the qsbr values. It means that all threads should report the quiescent states. It conflicts with my aim.Quoted 3 lines
Let's think about below scenario:
Eight threads use a hash table and periodically report their quiescentstates. One additional thread (main thread) periodically reports the hash size. I implemented the reclaim function in that thread. I mean, the main thread calls reclaim before the
rte_hash_count.Quoted 2 lines
Here is the exceptional case that I couldn't retrieve the correct hash
size:
Quoted 1 line
Assume that 6 of 8 threads reported quiescent states and 2 of them are
still working on some process and haven't reported quiescent states yet. The main thread calls reclaim functions every time, but elements in dq will not be freed because 2 of the worker threads haven't reported their states (especially if they are waiting for some packets). So, my first proposed method is more suitable for this case. Any idea?
If 2 out of 8 threads have not reported their quiescent state then the elements that have not been acknowledged by those 2 threads cannot be reclaimed and cannot be allocated for further use. Using this you can calculate the most accurate number of entries in the hash table available for allocation.Quoted 2 lines
On Thu, Feb 22, 2024 at 7:44 PM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
On Feb 22, 2024, at 6:39 AM, Abdullah Ömer Yamaç <[email protected]>
Quoted 2 lines · wrote:
Quoted 2 lines
As a final decision, I will add a new hash API that forces the
reclaim. Is it ok for everyone?
Quoted 4 lines
Ack from my side
Quoted 2 lines
On Thu, Feb 22, 2024 at 5:37 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
On Feb 21, 2024, at 3:51 PM, Abdullah Ömer Yamaç <
Quoted 4 lines · [email protected]> wrote:
Quoted 4 lines
Quoted 4 lines
On Wed, Feb 21, 2024 at 6:24 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On Feb 20, 2024, at 12:58 PM, Abdullah Ömer Yamaç <
Quoted 2 lines · [email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I appreciate that you gave me suggestions and comments. I will
make changes according to all your recommendations, but before that, I want to make everyone's minds clear. Then, I will apply modifications.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Tue, Feb 20, 2024 at 2:35 AM Honnappa Nagarahalli <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On Feb 19, 2024, at 3:28 PM, Abdullah Ömer Yamaç <
Quoted 6 lines · [email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Hello,
Let me explain a use case;
I have a hash table whose key value is IP addresses, and data
(let's say the username of the IP) is related to the IP address. The key point is matching these data with flows. Flows are dynamic, and this hash table is dynamic, as well; both can change anytime. For example, when a flow starts, we look up the hash table with the corresponding IP and retrieve the username. We need to hold this username until the flow terminates, although we removed this IP key from the hash table (multithread). That's why we have RCU and defer queue is necessary for high performance. In my application, I need to know the number of IP-username entries. These numbers can be calculated by
rte_hash_count- defer queue size.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
The entries in the defer queue are not reclaimed (there is a
probability that all of them can be reclaimed) and hence they are not available for allocation. So,
rte_hash_count- defer queue size might not give you the correct number you are expecting.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Currently, there is no API in hash library that forces a reclaim.
Does it makes sense to have an API that just does the reclaim (and returns the number of entries pending in the defer queue)? A call to
rte_hash_countshould provide the exact count you are looking for.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
You are right; no API in the hash library forces a reclaim. In my
application, I periodically call
rte_countto retrieve hash size, and this data is shown in my GUI. So that means I need to call regularly reclaim. I am trying to figure out which is better, calling reclaim or retrieving the defer queue size. Any comment about this?Quoted 1 line
Quoted 1 line
Quoted 1 line
Retrieving the defer queue size will be cheaper. However, calling
the reclaim API will ensure the entries are freed hence providing an accurate number. Calling the reclaim API on an empty defer queue does not consume many cycles. If needed we could add a check for empty defer queue in the reclaim API and return early.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am also wondering if a reclaim API in hash library is needed. Why
not call
rte_rcu_qsbr_dq_reclaimAPI from the application?Quoted 1 line
Quoted 1 line
Quoted 1 line
The reason is simple. struct
rte_hash*h is an internal structureand we cannot access the
h->dq. So it is not possible to call reclaim.Quoted 6 lines
Quoted 6 lines
Ack. This will be just a wrapper around the
rte_rcu_qsbr_dq_reclaim.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
I think if you need a non-blocking and multithreaded hash table,
an RCU-enabled hash table is necessary. Also, this API is necessary if you need to get the actual matchable size.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
On Mon, Feb 19, 2024 at 8:36 PM Medvedkin, Vladimir <
Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hi Abdullah,
Could you please tell more about use cases where this API may be
useful?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
a new API to get the hidden key count in the hash table if the
rcu qsbr is enabled
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Here in commit message and down below in doxygen comments, I
think this
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
statement should be more specific because rcu can be created
with
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
RTE_HASH_QSBR_MODE_SYNCmode i.e. without defer queue.Also, new API must be reflected in release notes
Quoted 1 line · Abdullah Ömer Yamaç
This patch introduce a new API to get the hidden key count in
the hash
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
table if the rcu qsbr is enabled. When using
rte_hash_countwith rcu
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
qsbr enabled, it will return the number of elements that are
not in the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
free queue. Unless
rte_rcu_qsbr_dq_reclaimis called, thenumber of
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
elements in the defer queue will not be counted and freed.
Therefore I
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
added a new API to get the number of hidden (defer queue)
elements
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
in the hash table. Then the user can calculate the total
number of
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
elements that are available in the hash table.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Cc: Honnappa Nagarahalli <[email protected]>
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 9 +++++++++ lib/hash/rte_hash.h | 13 +++++++++++++ lib/hash/version.map | 1 + lib/rcu/rte_rcu_qsbr.c | 8 ++++++++ lib/rcu/rte_rcu_qsbr.h | 11 +++++++++++ lib/rcu/version.map | 1 + 6 files changed, 43 insertions(+)Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/hash/rte_cuckoo_hash.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash
Quoted 4 lines
index
70456754c4..3553f3efc7100644lib/hash/rte_cuckoo_hash.c +0
-0@@ -555,6 +555,15 @@ rte_hash_max_key_id(const struct rte_hash*h)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash · line 561
Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +4
-0return h->entries; } +int32_t +rte_hash_dq_count (const struct rte_hash *h) +{ +if (h->dq ==NULL )input arguments must be checked since this is a public API, the
same is
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
true for
rte_rcu_qsbr_dq_count()lib/hash/rte_cuckoo_hash.c rte_hash_max_key_id(const struct rte_hash · line 562
Quoted 1 line
lib/hash/rte_cuckoo_hash.c +1
-0+return -EINVAL ;why not just return 0?
Quoted 15 lines
lib/hash/rte_cuckoo_hash.c +4
-0+ +return rte_rcu_qsbr_dq_count (h->dq); +} +int32_t rte_hash_count (const struct rte_hash *h) {lib/hash/rte_hash.h +0
-0@@ -193,6 +193,19 @@ rte_hash_free(struct rte_hash *h);void rte_hash_reset (struct rte_hash *h);Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 198
Quoted 3 lines
lib/hash/rte_hash.h +3
-0+ +/** +* Return the number of records in the defer queue of the hash table
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/hash/rte_hash.h rte_hash_free(struct rte_hash *h); · line 204
Quoted 6 lines
lib/hash/rte_hash.h +6
-0+* if RCU is enabled. +* @param h +* Hash table to query from +* @return +* - -EINVAL if parameters are invalid +* - A value indicating how many records were inserted in the table.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
did you mean how many records are kept in defer queue?
Quoted 9 lines
lib/hash/rte_hash.h +4
-0+*/ +int32_t +rte_hash_dq_count (const struct rte_hash *h); +/** * Return the number of keys in the hash table * @param h lib/hash/version.map +0
-0Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/hash/version.map DPDK_24 { · line 12
Quoted 7 lines
lib/hash/version.map +1
-0@@ -9,6 +9,7 @@ DPDK_24 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_dq_count;new API must introduced as an experimental API. The same is true
for
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
rte_rcu_qsbr_dq_count()lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct
Quoted 8 lines
lib/hash/version.map +0
-0rte_hash_crc32_alg; rte_hash_crc_set_alg; rte_hash_create;lib/rcu/rte_rcu_qsbr.c +0
-0@@ -450,6 +450,14 @@ rte_rcu_qsbr_dq_reclaim(struct
rte_rcu_qsbr_dq*dq, unsigned int n,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c rte_rcu_qsbr_dq_reclaim(struct · line 457
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +5
-0return 0 ; } +/** +* Return the number of entries in a defer queue. +*/ +unsigned int rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq) +{Please validate dq here.
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/rcu/rte_rcu_qsbr.c +3
-0+return rte_ring_count (dq->r); +} +/* Delete a defer queue. */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.h int · line 794
Quoted 8 lines
lib/rcu/rte_rcu_qsbr.c +0
-0int rte_rcu_qsbr_dq_delete (struct rte_rcu_qsbr_dq *dq)lib/rcu/rte_rcu_qsbr.h +0
-0@@ -794,6 +794,17 @@ int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsignedint n,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
lib/rcu/rte_rcu_qsbr.h int · line 795
Quoted 1 line
lib/rcu/rte_rcu_qsbr.h +0
-0unsigned int *freed, unsigned int *pending, unsigned int*available);
Quoted 38 lines
Quoted 37 lines
Quoted 36 lines
Quoted 35 lines
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h int · line 805
Quoted 11 lines
lib/rcu/rte_rcu_qsbr.h +10
-0+/** +* Return the number of entries in a defer queue. +* +* @param dq +* Defer queue. +* @return +* The number of entries in the defer queue. +*/ +unsigned int +rte_rcu_qsbr_dq_count (struct rte_rcu_qsbr_dq *dq);Agree on the need for this API in RCU
Quoted 21 lines
Quoted 9 lines
lib/rcu/rte_rcu_qsbr.h +1
-0+/** * Delete a defer queue. * lib/rcu/version.map +0
-0lib/rcu/version.map DPDK_24 { · line 11
Quoted 7 lines
lib/rcu/version.map +1
-0@@ -5,6 +5,7 @@ DPDK_24 { rte_rcu_qsbr_dq_create; rte_rcu_qsbr_dq_delete; rte_rcu_qsbr_dq_enqueue; + rte_rcu_qsbr_dq_count; rte_rcu_qsbr_dq_reclaim; rte_rcu_qsbr_dump; rte_rcu_qsbr_get_memsize;--
Regards,
Vladimir
PATCH v2 1/1 lib/hash: feature reclaim defer queue
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 14 ++++++++++++++ lib/hash/version.map | 7 +++++++ 3 files changed, 44 insertions(+)
lib/hash/rte_cuckoo_hash.c +21 -0
@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL || h->dq ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size,NULL ,NULL ,NULL ); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +15 -0
@@ -674,6 +674,21 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* the hash object to reclaim resources +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer or invalid rcu mode +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h); + #ifdef __cplusplus }#endif
lib/hash/version.map +7 -0
@@ -48,3 +48,10 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + #added in 24.1 + rte_hash_rcu_qsbr_dq_reclaim; +}
Signature · 1 line
2.34.1
PATCH v2 1/1 lib/hash: feature reclaim defer queue
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 14 ++++++++++++++ lib/hash/version.map | 7 +++++++ 3 files changed, 44 insertions(+)
lib/hash/rte_cuckoo_hash.c +21 -0
@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL || h->dq ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size,NULL ,NULL ,NULL ); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +15 -0
@@ -674,6 +674,21 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* the hash object to reclaim resources +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer or invalid rcu mode +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h); + #ifdef __cplusplus }#endif
lib/hash/version.map +6 -0
@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +}
Signature · 1 line
2.34.1
Re: [PATCH v2] lib/hash: feature reclaim defer queue
Hello Abdullah,
Thank you for the patch, few comments inline.
The short commit log could be changed as follows:
"lib/hash: add defer queue reclaim API”
Quoted 9 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
Please add this only after you get an explicit Ack on the patch.
Quoted 11 lines
---
lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 14 ++++++++++++++ lib/hash/version.map | 7 +++++++ 3 files changed, 44 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1592
Quoted 5 lines
lib/hash/rte_cuckoo_hash.c +2
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h)
We need to add freed, pending and available parameters to this API. I think this information will be helpful for the users. For ex: in your use case, you could use the pending value to calculate the available hash entries.
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1596
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c +4
-0+{ +int ret; + +if (h->hash_rcu_cfg ==NULL || h->dq ==NULL ) {
We can skip NULL check for h->dq as the RCU reclaim API makes the same check.
Quoted 27 lines
lib/hash/rte_cuckoo_hash.c +15
-0+ rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size,NULL ,NULL ,NULL ); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void
remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned int i)lib/hash/rte_hash.h +1
-0@@ -674,6 +674,21 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/**
lib/hash/rte_hash.h rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32 · line 687
Quoted 10 lines
lib/hash/rte_hash.h +10
-0+* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* the hash object to reclaim resources +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer or invalid rcu mode
We can remove the ‘invalid rcd mode’.
Quoted 25 lines
lib/hash/rte_hash.h +4
-0+*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h); + #ifdef __cplusplus }#endif lib/hash/version.map +6
-0@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +}Signature · 1 line
2.34.1
Re: [PATCH v2] lib/hash: feature reclaim defer queue
Just one more question.
Quoted 34 lines · Honnappa Nagarahalli
Hello Abdullah,
Thank you for the patch, few comments inline.The short commit log could be changed as follows:
"lib/hash: add defer queue reclaim API”
Quoted 1 line
On Mar 2, 2024, at 3:27 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 8 lines · wrote:
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Please add this only after you get an explicit Ack on the patch.
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct
Quoted 11 lines
---
lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 14 ++++++++++++++ lib/hash/version.map | 7 +++++++ 3 files changed, 44 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct
rte_hash_rcu_config*cfg)Quoted 3 lines
lib/hash/rte_cuckoo_hash.c +0
-0return 0 ; }
Quoted 8 lines
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1592
Quoted 2 lines
lib/hash/rte_cuckoo_hash.c +2
-0+int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h)We need to add freed, pending and available parameters to this API. I think this information will be helpful for the users. For ex: in your use case, you could use the pending value to calculate the available hash entries.
The second parameter, "Maximum number of resources to free.", should be
available also? I set this value to " h->hash_rcu_cfg->max_reclaim_size", but it can be a parameter in addition to the above parameters
Quoted 77 lines
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1596
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c +4
-0+{ +int ret; + +if (h->hash_rcu_cfg ==NULL || h->dq ==NULL ) {We can skip NULL check for
h->dqas the RCU reclaim API makes the same check.lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)
Quoted 5 lines
lib/hash/rte_cuckoo_hash.c +5
-0+ rte_errno =EINVAL ; +return -1 ; + } + + ret = rte_rcu_qsbr_dq_reclaim(h->dq,
h->hash_rcu_cfg->max_reclaim_size, NULL, NULL, NULL);lib/hash/rte_hash.h rte_hash_iterate(const struct rte_hash *h, const
Quoted 18 lines
lib/hash/rte_cuckoo_hash.c +10
-0+if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void
remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned int i)lib/hash/rte_hash.h +0
-0@@ -674,6 +674,21 @@ rte_hash_iterate(const struct rte_hash *h, constvoid **key, void **data, uint32
Quoted 2 lines
lib/hash/rte_hash.h +0
-0*/ int rte_hash_rcu_qsbr_add(struct
rte_hash*h, structrte_hash_rcu_config*cfg);
Quoted 4 lines
+/**
+ * Reclaim resources from the defer queue.
+ * This API reclaim the resources from the defer queue if rcu isenabled.
Quoted 8 lines
+ *
+ * @param h
+ * the hash object to reclaim resources
+ * @return+ * On success - 0 + * On error - 1 with error code set in rte_errno. + * Possible rte_errno codes are: + * - EINVAL - invalid pointer or invalid rcu modeWe can remove the ‘invalid rcd mode’.
Quoted 25 lines
+ */
lib/hash/rte_hash.h +3
-0+__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h); +#ifdef
__cplusplus
}
#endiflib/hash/version.map +6
-1@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +} --2.34.1
Re: [PATCH v2] lib/hash: feature reclaim defer queue
Quoted 39 lines · Abdullah Ömer Yamaç
Just one more question.
On Sun, Mar 3, 2024 at 10:14 PM Honnappa Nagarahalli <[email protected]> wrote:
Hello Abdullah,
Thank you for the patch, few comments inline.The short commit log could be changed as follows:
"lib/hash: add defer queue reclaim API”
Quoted 9 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Please add this only after you get an explicit Ack on the patch.
Quoted 14 lines
---
lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 14 ++++++++++++++ lib/hash/version.map | 7 +++++++ 3 files changed, 44 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; }
Quoted 5 lines
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1592
Quoted 2 lines
lib/hash/rte_cuckoo_hash.c +2
-0+int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h)We need to add freed, pending and available parameters to this API. I think this information will be helpful for the users. For ex: in your use case, you could use the pending value to calculate the available hash entries.
The second parameter, "Maximum number of resources to free.", should be available also? I set this value to "
h->hash_rcu_cfg->max_reclaim_size", but it can be a parameter in addition to the above parameters
We don’t have to expose that in the API. The user has provided that already in max_reclaim_size. So, using "h->hash_rcu_cfg->max_reclaim_size” is enough.
Quoted 71 lines
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1596
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c +4
-0+{ +int ret; + +if (h->hash_rcu_cfg ==NULL || h->dq ==NULL ) {We can skip NULL check for
h->dqas the RCU reclaim API makes the same check.Quoted 27 lines
lib/hash/rte_cuckoo_hash.c +15
-0+ rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size,NULL ,NULL ,NULL ); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void
remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned int i)lib/hash/rte_hash.h +1
-0@@ -674,6 +674,21 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** lib/hash/rte_hash.h rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32 · line 687
Quoted 10 lines
lib/hash/rte_hash.h +10
-0+* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* the hash object to reclaim resources +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer or invalid rcu mode We can remove the ‘invalid rcd mode’.
Quoted 25 lines
lib/hash/rte_hash.h +4
-0+*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h); + #ifdef __cplusplus }#endif lib/hash/version.map +6
-0@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +}Signature · 1 line
2.34.1
PATCH v3 1/1 lib/hash: add defer queue reclaim API
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 28 +++++++++++++++++++++++++++- lib/hash/version.map | 6 ++++++ 3 files changed, 56 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +23 -0
@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +27 -1
@@ -631,7 +631,7 @@ rte_hash_lookup_with_hash_bulk_data(const struct rte_hash *h,*/ int rte_hash_lookup_bulk (const struct rte_hash *h,const void **keys, -uint32_t num_keys,int32_t *positions); +uint32_t num_keys,int32_t *positions);/** * Iterate through the hash table, returning key-value pairs.
@@ -674,6 +674,32 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param n +* Maximum number of resources to free. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +6 -0
@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
PATCH v3 1/1 lib/hash: add defer queue reclaim API
In reply to Honnappa NagarahalliThis patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 28 +++++++++++++++++++++++++++- lib/hash/version.map | 6 ++++++ 3 files changed, 56 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +23 -0
@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +26 -0
@@ -674,6 +674,32 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param n +* Maximum number of resources to free. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +6 -0
@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
PATCH v3 1/1 lib/hash: add defer queue reclaim API
In reply to Honnappa NagarahalliThis patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 24 ++++++++++++++++++++++++ lib/hash/version.map | 6 ++++++ 3 files changed, 53 insertions(+)
lib/hash/rte_cuckoo_hash.c +23 -0
@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +24 -0
@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +6 -0
@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
Re: [PATCH v3] lib/hash: add defer queue reclaim API
Hello,
Is there any other comment on this?
Quoted 108 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 24 ++++++++++++++++++++++++ lib/hash/version.map | 6 ++++++ 3 files changed, 53 insertions(+)lib/hash/rte_cuckoo_hash.c +16
-0@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { + HASH_LOG(ERR, + "%s: could not reclaim the defer queue in hashtable",
lib/hash/rte_cuckoo_hash.c +7
-0+ __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)lib/hash/rte_hash.h +11
-0@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, const void**key, void **data, uint32 */ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured.
+ * @param available
+ * Number of resources that can be added to the defer queue.
+ * This number might not be accurate if multi-thread safety is
configured.
+ * @return+ * On success - 0 + * On error - 1 with error code set in rte_errno. + * Possible rte_errno codes are: + * - EINVAL - invalid pointer+ */
lib/hash/rte_hash.h +4
-0+__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif lib/hash/version.map +6
-1@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +}; --2.34.1
Re: [PATCH v3] lib/hash: add defer queue reclaim API
Hello,
Could you check the last commit?
Thanks
Quoted 114 lines · Abdullah Ömer Yamaç
Hello,
Is there any other comment on this?Quoted 108 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 24 ++++++++++++++++++++++++ lib/hash/version.map | 6 ++++++ 3 files changed, 53 insertions(+)lib/hash/rte_cuckoo_hash.c +16
-0@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { + HASH_LOG(ERR, + "%s: could not reclaim the defer queue in hashtable",
lib/hash/rte_cuckoo_hash.c +7
-0+ __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)lib/hash/rte_hash.h +0
-0@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, constvoid **key, void **data, uint32
*/
int rte_hash_rcu_qsbr_add(structrte_hash*h, structrte_hash_rcu_config
*cfg);+/**
+ * Reclaim resources from the defer queue.
+ * This API reclaim the resources from the defer queue if rcu is enabled.
+ *
+ * @param h
+ * The hash object to reclaim resources.
+ * @param freed
+ * Number of resources that were freed.
+ * @param pending
+ * Number of resources pending on the defer queue.
+ * This number might not be accurate if multi-thread safety is
configured.
+ * @param available
+ * Number of resources that can be added to the defer queue.
+ * This number might not be accurate if multi-thread safety is
configured.
+ * @return+ * On success - 0 + * On error - 1 with error code set in rte_errno. + * Possible rte_errno codes are: + * - EINVAL - invalid pointer+ */
lib/hash/rte_hash.h +4
-0+__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif lib/hash/version.map +6
-1@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +}; --2.34.1
Re: [PATCH v3] lib/hash: add defer queue reclaim API
Apologies for the late reply. Looks good, few nits inline.
Can you please some simple unit tests?
Quoted 28 lines · Abdullah Ömer Yamaç
Hello,
Could you check the last commit?
ThanksOn Thu, Mar 14, 2024 at 10:04 AM Abdullah Ömer Yamaç <[email protected]> wrote:
Hello,
Is there any other comment on this?On Wed, Mar 6, 2024 at 1:13 PM Abdullah Ömer Yamaç <[email protected]> wrote:
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++ lib/hash/rte_hash.h | 24 ++++++++++++++++++++++++ lib/hash/version.map | 6 ++++++ 3 files changed, 53 insertions(+)lib/hash/rte_cuckoo_hash.c +0
-0
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1597
Quoted 10 lines
lib/hash/rte_cuckoo_hash.c +7
-0@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h->hash_rcu_cfg ==NULL ) {
Please check for ‘h’ being NULL.
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) · line 1599
Quoted 2 lines
lib/hash/rte_cuckoo_hash.c +2
-0+ rte_errno =EINVAL ; +return -1 ;
Return value should be positive 1 as per the API definition below
Quoted 70 lines
lib/hash/rte_cuckoo_hash.c +14
-0+ } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return -1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)lib/hash/rte_hash.h +24
-0@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif lib/hash/version.map +6
-0@@ -48,3 +48,9 @@ DPDK_24 { local: *; }; + +EXPERIMENTAL { + global: + + rte_hash_rcu_qsbr_dq_reclaim; +};Signature · 1 line
2.34.1
PATCH v4 1/1 lib/hash: add defer queue reclaim API
In reply to Abdullah Ömer YamaçThis patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- app/test/test_hash.c | 97 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 23 +++++++++ lib/hash/rte_hash.h | 24 ++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 151 insertions(+)
app/test/test_hash.c +97 -0
@@ -2183,6 +2183,100 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int +test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + +printf ("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n" ); + + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket (NULL , sz, +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL , +"RCU QSBR variable creation failed" ); + + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 , +"RCU QSBR variable initialization failed" ); + + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); +RETURN_IF_ERROR_RCU_QSBR (status !=0 , +"Attach RCU QSBR to hash table failed" ); + +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 , +"RCU QSBR thread registration failed" ); +rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Lookup inserted elements*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_lookup (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); +RETURN_IF_ERROR_RCU_QSBR (status <0 , +"failed to add key (pos[%u]=%d)" ,0 , + status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + +if (hash_size != (total_entries /2 +1 ) || freed != (total_entries /2 )) { +printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */
@@ -2261,6 +2355,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }
lib/hash/rte_cuckoo_hash.c +23 -0
@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return 1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +24 -0
@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +7 -0
@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
Re: [PATCH v4] lib/hash: add defer queue reclaim API
Hello, is there any other comment on this patch? Thanks
Quoted 234 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- app/test/test_hash.c | 97 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 23 +++++++++ lib/hash/rte_hash.h | 24 ++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 151 insertions(+)app/test/test_hash.c +41
-0@@ -2183,6 +2183,100 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int +test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + + printf("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n"); + + g_handle = rte_hash_create(&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket (NULL , sz, +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL , + "RCU QSBR variable creation failed"); + + status = rte_rcu_qsbr_init(g_qsv, RTE_MAX_LCORE); + RETURN_IF_ERROR_RCU_QSBR(status != 0, + "RCU QSBRvariable initialization failed");
app/test/test_hash.c +9
-0+ + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); + RETURN_IF_ERROR_RCU_QSBR(status != 0, + "Attach RCU QSBRto hash table failed");
app/test/test_hash.c +5
-0+ +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); + RETURN_IF_ERROR_RCU_QSBR(status != 0, + "RCU QSBR threadregistration failed");
app/test/test_hash.c +20
-0+rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Lookup inserted elements*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_lookup (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); + RETURN_IF_ERROR_RCU_QSBR(status < 0, + "failed to addkey (pos[%u]=%d)", 0,
app/test/test_hash.c +7
-0+ status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ + rte_hash_rcu_qsbr_dq_reclaim(g_handle, &freed, &pending,&available);
app/test/test_hash.c +5
-0+ +rte_hash_free (g_handle); +rte_free (g_qsv); + + if (hash_size != (total_entries / 2 + 1) || freed !=(
total_entries/ 2)) {app/test/test_hash.c +10
-0+printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */ @@ -2261,6 +2355,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }lib/hash/rte_cuckoo_hash.c +13
-0@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return 1 ; + } + + ret = rte_rcu_qsbr_dq_reclaim(h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed,pending, available);
lib/hash/rte_cuckoo_hash.c +3
-0+if (ret !=0 ) { + HASH_LOG(ERR, + "%s: could not reclaim the defer queue inhash table",
lib/hash/rte_cuckoo_hash.c +7
-0+ __func__); +return 1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)lib/hash/rte_hash.h +11
-0@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, const void**key, void **data, uint32 */ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured.
+ * @param available
+ * Number of resources that can be added to the defer queue.
+ * This number might not be accurate if multi-thread safety is
configured.
+ * @return+ * On success - 0 + * On error - 1 with error code set in rte_errno. + * Possible rte_errno codes are: + * - EINVAL - invalid pointer+ */
lib/hash/rte_hash.h +4
-0+__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif lib/hash/version.map +7
-1@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +}; --2.34.1
Re: [PATCH v4] lib/hash: add defer queue reclaim API
In reply to Abdullah Ömer YamaçReview
Quoted 2 lines · On Mon, 15 Apr 2024 11:26:02 +0000 Abdullah Ömer Yamaç <[email protected]>…
(quoted diff) +2
-0+ ret = rte_rcu_qsbr_dq_reclaim(h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available);
Indention here is odd. I would expect "freed," to line up right under h->dq. Since rte_rcu_qsbrs_dq_reclaim logs error on invalid parameters, this function should as well.
Total indent fixes:
lib/hash/rte_cuckoo_hash.c +4 -5
@@ -1590,21 +1590,20 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)int rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, -unsigned int *pending,unsigned int *available) +unsigned int *pending,unsigned int *available) {int ret;if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); rte_errno =EINVAL ;return 1 ; } ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, - freed, pending, available); + freed, pending, available);if (ret !=0 ) { -HASH_LOG (ERR , -"%s: could not reclaim the defer queue in hash table" , - __func__); +HASH_LOG (ERR ,"%s: could not reclaim the defer queue in hash table" , __func__);return 1 ; }
Re: [PATCH v4] lib/hash: add defer queue reclaim API
Thanks for the comments. This is due to the tab size, and I will fix them.
Quoted 53 lines · Stephen Hemminger
Quoted 1 line · On Mon, 15 Apr 2024 11:26:02 +0000 Abdullah Ömer Yamaç <[email protected]>…
+ ret = rte_rcu_qsbr_dq_reclaim(h->dq,
h->hash_rcu_cfg->max_reclaim_size,Quoted 1 line
+ freed,
pending, available);
Indention here is odd. I would expect "freed," to line up right under
h->dq.
Sincerte_rcu_qsbrs_dq_reclaimlogs error on invalid parameters, this function should as well.Total indent fixes:
lib/hash/rte_cuckoo_hash.c +3
-4@@ -1590,21 +1590,20 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, -unsigned int *pending,unsigned int *available) + unsigned int *pending, unsigned int *available) {int ret;if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); rte_errno =EINVAL ;return 1 ; } ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, - freed, pending, available); + freed, pending, available);if (ret !=0 ) { - HASH_LOG(ERR, - "%s: could not reclaim the defer queue inhash table",
lib/hash/rte_cuckoo_hash.c +1
-1- __func__); + HASH_LOG(ERR, "%s: could not reclaim the defer queue inhash table", __func__); return 1; }
PATCH v5 1/1 lib/hash: add defer queue reclaim API
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- app/test/test_hash.c | 90 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 21 +++++++++ lib/hash/rte_hash.h | 25 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 143 insertions(+)
app/test/test_hash.c +90 -0
@@ -2183,6 +2183,93 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + +printf ("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n" ); + + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket (NULL , sz,RTE_CACHE_LINE_SIZE , +SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL ,"RCU QSBR variable creation failed" ); + + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR variable initialization failed" ); + + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"Attach RCU QSBR to hash table failed" ); + +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR thread registration failed" ); +rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Lookup inserted elements*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_lookup (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); +RETURN_IF_ERROR_RCU_QSBR (status <0 ,"failed to add key (pos[%u]=%d)" ,0 , status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + +if (hash_size != (total_entries /2 +1 ) || freed != (total_entries /2 )) { +printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */
@@ -2261,6 +2348,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }
lib/hash/rte_cuckoo_hash.c +21 -0
@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed,unsigned int *pending, +unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, freed, pending, + available); +if (ret !=0 ) { +HASH_LOG (ERR ,"%s: could not reclaim the defer queue in hash table" , __func__); +return 1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +25 -0
@@ -674,6 +674,31 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending, +unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +7 -0
@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
Re: [PATCH v5] lib/hash: add defer queue reclaim API
Hello,
Any other comments?
Quoted 226 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- app/test/test_hash.c | 90 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 21 +++++++++ lib/hash/rte_hash.h | 25 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 143 insertions(+)app/test/test_hash.c +38
-0@@ -2183,6 +2183,93 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + + printf("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n"); + + g_handle = rte_hash_create(&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket (NULL , sz,RTE_CACHE_LINE_SIZE , +SOCKET_ID_ANY ); + RETURN_IF_ERROR_RCU_QSBR(g_qsv == NULL, "RCU QSBR variable creation failed"); + + status = rte_rcu_qsbr_init(g_qsv, RTE_MAX_LCORE); + RETURN_IF_ERROR_RCU_QSBR(status != 0, "RCU QSBR variableinitialization failed");
app/test/test_hash.c +8
-0+ + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); + RETURN_IF_ERROR_RCU_QSBR(status != 0, "Attach RCU QSBR to hashtable failed");
app/test/test_hash.c +4
-0+ +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); + RETURN_IF_ERROR_RCU_QSBR(status != 0, "RCU QSBR threadregistration failed");
app/test/test_hash.c +19
-0+rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Lookup inserted elements*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_lookup (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); + RETURN_IF_ERROR_RCU_QSBR(status < 0, "failed to add key(pos[%u]=%d)", 0, status);
app/test/test_hash.c +6
-0+ +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ + rte_hash_rcu_qsbr_dq_reclaim(g_handle, &freed, &pending,&available);
app/test/test_hash.c +5
-0+ +rte_hash_free (g_handle); +rte_free (g_qsv); + + if (hash_size != (total_entries / 2 + 1) || freed !=(
total_entries/ 2)) {app/test/test_hash.c +10
-0+printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */ @@ -2261,6 +2348,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }lib/hash/rte_cuckoo_hash.c +15
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed,unsigned int *pending, +unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, freed, pending, + available); +if (ret !=0 ) { + HASH_LOG(ERR, "%s: could not reclaim the defer queue inhash table",
__func__);lib/hash/rte_cuckoo_hash.c +6
-0+return 1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)lib/hash/rte_hash.h +11
-0@@ -674,6 +674,31 @@ rte_hash_iterate(const struct rte_hash *h, const void**key, void **data, uint32 */ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured.
+ * @param available
+ * Number of resources that can be added to the defer queue.
+ * This number might not be accurate if multi-thread safety is
configured.
+ * @return+ * On success - 0 + * On error - 1 with error code set in rte_errno. + * Possible rte_errno codes are: + * - EINVAL - invalid pointer+ */
lib/hash/rte_hash.h +4
-0+__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending, + unsigned int*available);
lib/hash/rte_hash.h +1
-0+ #ifdef __cplusplus }#endif lib/hash/version.map +7
-1@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +}; --2.34.1
Re: [PATCH v5] lib/hash: add defer queue reclaim API
In reply to Abdullah Ömer YamaçHi Abdullah,
This looks good, except for one comment inline.
Quoted 72 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
app/test/test_hash.c | 90 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 21 +++++++++ lib/hash/rte_hash.h | 25 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 143 insertions(+)app/test/test_hash.c +49
-0@@ -2183,6 +2183,93 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + +printf ("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n" ); + + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket (NULL , sz,RTE_CACHE_LINE_SIZE , +SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL ,"RCU QSBR variable creation failed" ); + + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR variable initialization failed" ); + + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"Attach RCU QSBR to hash table failed" ); + +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 );
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) · line 2244
Quoted 10 lines
app/test/test_hash.c +10
-0+RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR thread registration failed" ); +rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Lookup inserted elements*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_lookup (g_handle, &reclaim_keys[i]);
Why do we need to lookup the entries?
Quoted 125 lines
app/test/test_hash.c +31
-0+ +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); +RETURN_IF_ERROR_RCU_QSBR (status <0 ,"failed to add key (pos[%u]=%d)" ,0 , status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + +if (hash_size != (total_entries /2 +1 ) || freed != (total_entries /2 )) { +printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */ @@ -2261,6 +2348,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }lib/hash/rte_cuckoo_hash.c +21
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed,unsigned int *pending, +unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, freed, pending, + available); +if (ret !=0 ) { +HASH_LOG (ERR ,"%s: could not reclaim the defer queue in hash table" , __func__); +return 1 ; + } + +return 0 ; +} +static inline void
remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned int i)lib/hash/rte_hash.h +25
-0@@ -674,6 +674,31 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending, +unsigned int *available); + #ifdef __cplusplus }#endif lib/hash/version.map +7
-1@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +}; --
Quoted 2 lines
2.34.1
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Re: [PATCH v5] lib/hash: add defer queue reclaim API
Hello,
That's my mistake and I will discard the lookup part. While I was implementing these parts, I thought that readers should not be in a quiescent state, and I just wanted to make sure that these values were in use and the reader was in the critical section.
Thanks I will fix ASAP
Quoted 240 lines · Honnappa Nagarahalli
Hi Abdullah,
This looks good, except for one comment inline.Quoted 1 line
On Apr 27, 2024, at 2:54 PM, Abdullah Ömer Yamaç <[email protected]>
Quoted 38 lines · wrote:
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
app/test/test_hash.c | 90 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 21 +++++++++ lib/hash/rte_hash.h | 25 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 143 insertions(+)app/test/test_hash.c +16
-0@@ -2183,6 +2183,93 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL ,app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) · line 2211
Quoted 10 lines
app/test/test_hash.c +10
-0+ .hash_func_init_val = 0, + .socket_id = 0, + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + + printf("\n# Running RCU QSBR DQ mode, reclaim defer queue functionaltest\n");
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
Quoted 7 lines
app/test/test_hash.c +7
-0+ + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
RTE_CACHE_LINE_SIZE,app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) · line 2220
Quoted 2 lines
app/test/test_hash.c +2
-0+ SOCKET_ID_ANY); + RETURN_IF_ERROR_RCU_QSBR(g_qsv == NULL, "RCU QSBR variable creationfailed");
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
Quoted 3 lines
app/test/test_hash.c +3
-0+ + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); + RETURN_IF_ERROR_RCU_QSBR(status != 0, "RCU QSBR variableinitialization failed");
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
Quoted 8 lines
app/test/test_hash.c +8
-0+ + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); + RETURN_IF_ERROR_RCU_QSBR(status != 0, "Attach RCU QSBR to hash tablefailed");
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
Quoted 4 lines
app/test/test_hash.c +4
-0+ +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); + RETURN_IF_ERROR_RCU_QSBR(status != 0, "RCU QSBR thread registrationfailed");
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) · line 2244
Quoted 9 lines
app/test/test_hash.c +9
-0+rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Lookup inserted elements*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_lookup (g_handle, &reclaim_keys[i]);Why do we need to lookup the entries?
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
Quoted 10 lines
app/test/test_hash.c +10
-0+ +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); + RETURN_IF_ERROR_RCU_QSBR(status < 0, "failed to add key (pos[%u]=%d)",0, status);
app/test/test_hash.c test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
Quoted 11 lines
app/test/test_hash.c +11
-0+ +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + + if (hash_size != (total_entries / 2 + 1) || freed != (total_entries /2)) {
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct
Quoted 25 lines
app/test/test_hash.c +10
-0+printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */ @@ -2261,6 +2348,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }lib/hash/rte_cuckoo_hash.c +0
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct
rte_hash_rcu_config*cfg)lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct · line 1591
Quoted 4 lines
lib/hash/rte_cuckoo_hash.c +1
-0return 0 ; } +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int*freed, unsigned int *pending,
lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)
Quoted 11 lines
lib/hash/rte_cuckoo_hash.c +11
-0+ unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); + rte_errno =EINVAL ; +return 1 ; + } + + ret = rte_rcu_qsbr_dq_reclaim(h->dq,
h->hash_rcu_cfg->max_reclaim_size, freed, pending,lib/hash/rte_cuckoo_hash.c rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)
Quoted 3 lines
lib/hash/rte_cuckoo_hash.c +3
-0+ available); +if (ret !=0 ) { + HASH_LOG(ERR, "%s: could not reclaim the defer queue in hash table",
__func__);lib/hash/rte_hash.h rte_hash_iterate(const struct rte_hash *h, const
Quoted 14 lines
lib/hash/rte_cuckoo_hash.c +6
-0+return 1 ; + } + +return 0 ; +} +static inline void
remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned int i)lib/hash/rte_hash.h +0
-0@@ -674,6 +674,31 @@ rte_hash_iterate(const struct rte_hash *h, constvoid **key, void **data, uint32
Quoted 2 lines
lib/hash/rte_hash.h +0
-0*/ int rte_hash_rcu_qsbr_add(struct
rte_hash*h, structrte_hash_rcu_config*cfg);
Quoted 4 lines
+/**
+ * Reclaim resources from the defer queue.
+ * This API reclaim the resources from the defer queue if rcu isenabled.
Quoted 8 lines
+ *
+ * @param h
+ * The hash object to reclaim resources.
+ * @param freed
+ * Number of resources that were freed.
+ * @param pending
+ * Number of resources pending on the defer queue.
+ * This number might not be accurate if multi-thread safety isconfigured.
Quoted 3 lines
+ * @param available
+ * Number of resources that can be added to the defer queue.
+ * This number might not be accurate if multi-thread safety isconfigured.
lib/hash/rte_hash.h
Quoted 8 lines
+ * @return
+ * On success - 0 + * On error - 1 with error code set in rte_errno. + * Possible rte_errno codes are: + * - EINVAL - invalid pointer+ */
lib/hash/rte_hash.h +2
-0+__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int*freed,
Quoted 22 lines
lib/hash/rte_hash.h +3
-0+unsigned int *pending, + unsigned int *available); +#ifdef
__cplusplus
}
#endiflib/hash/version.map +7
-1@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +}; --Quoted 2 lines
2.34.1
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
PATCH v5 1/1 lib/hash: add defer queue reclaim API
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- app/test/test_hash.c | 88 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 23 ++++++++++ lib/hash/rte_hash.h | 24 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 142 insertions(+)
app/test/test_hash.c +88 -0
@@ -2183,6 +2183,91 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int +test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + +printf ("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n" ); + + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket ( +NULL , sz,RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL ,"RCU QSBR variable creation failed" ); + + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR variable initialization failed" ); + + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"Attach RCU QSBR to hash table failed" ); + +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR thread registration failed" ); +rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); +RETURN_IF_ERROR_RCU_QSBR (status <0 ,"failed to add key (pos[%u]=%d)" ,0 , status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + +if (hash_size != (total_entries /2 +1 ) || freed != (total_entries /2 )) { +printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} + +/* * Do all unit and performance tests. */
@@ -2261,6 +2346,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }
lib/hash/rte_cuckoo_hash.c +23 -0
@@ -1588,6 +1588,29 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int +rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed, +unsigned int *pending,unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, + freed, pending, available); +if (ret !=0 ) { +HASH_LOG (ERR , +"%s: could not reclaim the defer queue in hash table" , + __func__); +return 1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +24 -0
@@ -674,6 +674,30 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending,unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +7 -0
@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
PATCH v6 1/1 lib/hash: add defer queue reclaim API
In reply to Abdullah Ömer YamaçThis patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
--- app/test/test_hash.c | 87 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 21 +++++++++ lib/hash/rte_hash.h | 25 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 140 insertions(+)
app/test/test_hash.c +87 -0
@@ -2183,6 +2183,90 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int +test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + +printf ("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n" ); + + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket ( +NULL , sz,RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL ,"RCU QSBR variable creation failed" ); + + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR variable initialization failed" ); + + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"Attach RCU QSBR to hash table failed" ); + +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR thread registration failed" ); +rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); +RETURN_IF_ERROR_RCU_QSBR (status <0 ,"failed to add key (pos[%u]=%d)" ,0 , status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + +if (hash_size != (total_entries /2 +1 ) || freed != (total_entries /2 )) { +printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */
@@ -2261,6 +2345,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }
lib/hash/rte_cuckoo_hash.c +21 -0
@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed,unsigned int *pending, +unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, freed, pending, + available); +if (ret !=0 ) { +HASH_LOG (ERR ,"%s: could not reclaim the defer queue in hash table" , __func__); +return 1 ; + } + +return 0 ; +} +static inline void remove_entry (const struct rte_hash *h,struct rte_hash_bucket *bkt,unsigned int i)
lib/hash/rte_hash.h +25 -0
@@ -674,6 +674,31 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending, +unsigned int *available); + #ifdef __cplusplus }#endif
lib/hash/version.map +7 -0
@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +};
Signature · 1 line
2.34.1
Re: [PATCH v6] lib/hash: add defer queue reclaim API
Quoted 10 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
Quoted 198 lines
---
app/test/test_hash.c | 87 ++++++++++++++++++++++++++++++++++++++ lib/hash/rte_cuckoo_hash.c | 21 +++++++++ lib/hash/rte_hash.h | 25 +++++++++++ lib/hash/version.map | 7 +++ 4 files changed, 140 insertions(+)app/test/test_hash.c +87
-0@@ -2183,6 +2183,90 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) } +/* +* rte_hash_rcu_qsbr_dq_reclaim unit test. +*/ +static int +test_hash_rcu_qsbr_dq_reclaim (void ) +{ +size_t sz; +int32_t status; +unsigned int total_entries =8 ; +unsigned int freed, pending, available; +uint32_t reclaim_keys[8 ] = {10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 }; +struct rte_hash_rcu_config rcu_cfg = {0 }; +struct rte_hash_parameters hash_params = { + .name ="test_hash_rcu_qsbr_dq_reclaim" , + .entries = total_entries, + .key_len =sizeof (uint32_t ), + .hash_func =NULL , + .hash_func_init_val =0 , + .socket_id =0 , + }; + + hash_params.extra_flag =RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF ; + + g_qsv =NULL ; + g_handle =NULL ; + +printf ("\n# Running RCU QSBR DQ mode, reclaim defer queue functional test\n" ); + + g_handle =rte_hash_create (&hash_params); +RETURN_IF_ERROR_RCU_QSBR (g_handle ==NULL ,"Hash creation failed" ); + +/* Create RCU QSBR variable */ + sz =rte_rcu_qsbr_get_memsize (RTE_MAX_LCORE ); + g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket ( +NULL , sz,RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RETURN_IF_ERROR_RCU_QSBR (g_qsv ==NULL ,"RCU QSBR variable creation failed" ); + + status =rte_rcu_qsbr_init (g_qsv,RTE_MAX_LCORE ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR variable initialization failed" ); + + rcu_cfg.v = g_qsv; + rcu_cfg.dq_size = total_entries; + rcu_cfg.mode =RTE_HASH_QSBR_MODE_DQ ; + +/* Attach RCU QSBR to hash table */ + status =rte_hash_rcu_qsbr_add (g_handle, &rcu_cfg); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"Attach RCU QSBR to hash table failed" ); + +/* Register pseudo reader */ + status =rte_rcu_qsbr_thread_register (g_qsv,0 ); +RETURN_IF_ERROR_RCU_QSBR (status !=0 ,"RCU QSBR thread registration failed" ); +rte_rcu_qsbr_thread_online (g_qsv,0 ); + +/* Fill half of the hash table */ +for (size_t i =0 ; i < total_entries /2 ; i++) + status =rte_hash_add_key (g_handle, &reclaim_keys[i]); + +/* Try to put these elements into the defer queue*/ +for (size_t i =0 ; i < total_entries /2 ; i++) +rte_hash_del_key (g_handle, &reclaim_keys[i]); + +/* Reader quiescent */ +rte_rcu_qsbr_quiescent (g_qsv,0 ); + + status =rte_hash_add_key (g_handle, &reclaim_keys[0 ]); +RETURN_IF_ERROR_RCU_QSBR (status <0 ,"failed to add key (pos[%u]=%d)" ,0 , status); + +/* This should be (total_entries / 2) + 1 (last add) */ +unsigned int hash_size =rte_hash_count (g_handle); + +/* Freed size should be (total_entries / 2) */ +rte_hash_rcu_qsbr_dq_reclaim (g_handle, &freed, &pending, &available); + +rte_hash_free (g_handle); +rte_free (g_qsv); + +if (hash_size != (total_entries /2 +1 ) || freed != (total_entries /2 )) { +printf ("Failed to reclaim defer queue\n" ); +return -1 ; + } + +return 0 ; +} +/* * Do all unit and performance tests. */ @@ -2261,6 +2345,9 @@ test_hash(void)if (test_hash_rcu_qsbr_sync_mode (1 ) <0 )return -1 ; +if (test_hash_rcu_qsbr_dq_reclaim () <0 ) +return -1 ; +return 0 ; }lib/hash/rte_cuckoo_hash.c +21
-0@@ -1588,6 +1588,27 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg)return 0 ; } +int rte_hash_rcu_qsbr_dq_reclaim (struct rte_hash *h,unsigned int *freed,unsigned int *pending, +unsigned int *available) +{ +int ret; + +if (h ==NULL || h->hash_rcu_cfg ==NULL ) { +HASH_LOG (ERR ,"Invalid input parameter" ); + rte_errno =EINVAL ; +return 1 ; + } + + ret =rte_rcu_qsbr_dq_reclaim (h->dq, h->hash_rcu_cfg->max_reclaim_size, freed, pending, + available); +if (ret !=0 ) { +HASH_LOG (ERR ,"%s: could not reclaim the defer queue in hash table" , __func__); +return 1 ; + } + +return 0 ; +} +static inline void
remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned int i)lib/hash/rte_hash.h +25
-0@@ -674,6 +674,31 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32*/ int rte_hash_rcu_qsbr_add (struct rte_hash *h,struct rte_hash_rcu_config *cfg); +/** +* Reclaim resources from the defer queue. +* This API reclaim the resources from the defer queue if rcu is enabled. +* +* @param h +* The hash object to reclaim resources. +* @param freed +* Number of resources that were freed. +* @param pending +* Number of resources pending on the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @param available +* Number of resources that can be added to the defer queue. +* This number might not be accurate if multi-thread safety is configured. +* @return +* On success - 0 +* On error - 1 with error code set in rte_errno. +* Possible rte_errno codes are: +* - EINVAL - invalid pointer +*/ +__rte_experimental +int rte_hash_rcu_qsbr_dq_reclaim(struct rte_hash *h, unsigned int *freed, +unsigned int *pending, +unsigned int *available); + #ifdef __cplusplus }#endif lib/hash/version.map +7
-0@@ -53,3 +53,10 @@ INTERNAL { rte_thash_gfni_stub; rte_thash_gfni_bulk_stub; }; + +EXPERIMENTAL { + global: + + # added in 24.07 + rte_hash_rcu_qsbr_dq_reclaim; +};Signature · 1 line
2.34.1
David Marchand
AppliedRe: [PATCH v6] lib/hash: add defer queue reclaim API
Quoted 9 lines · Honnappa Nagarahalli
Quoted 8 lines · Abdullah Ömer Yamaç
This patch adds a new feature to the hash library to allow the user to reclaim the defer queue. This is useful when the user wants to force reclaim resources that are not being used. This API is only available if the RCU is enabled.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand