[v3] lib/hash: add defer queue reclaim API

Message ID 20240306101335.246097-1-aomeryamac@gmail.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series [v3] lib/hash: add defer queue reclaim API |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Abdullah Ömer Yamaç March 6, 2024, 10:13 a.m. UTC
  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ç <aomeryamac@gmail.com>
---
 lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++
 lib/hash/rte_hash.h        | 24 ++++++++++++++++++++++++
 lib/hash/version.map       |  6 ++++++
 3 files changed, 53 insertions(+)
  

Comments

Abdullah Ömer Yamaç March 14, 2024, 7:04 a.m. UTC | #1
Hello,
Is there any other comment on this?

On Wed, Mar 6, 2024 at 1:13 PM Abdullah Ömer Yamaç <aomeryamac@gmail.com>
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ç <aomeryamac@gmail.com>
> ---
>  lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++
>  lib/hash/rte_hash.h        | 24 ++++++++++++++++++++++++
>  lib/hash/version.map       |  6 ++++++
>  3 files changed, 53 insertions(+)
>
> diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
> index 9cf94645f6..1c360fa38b 100644
> --- a/lib/hash/rte_cuckoo_hash.c
> +++ b/lib/hash/rte_cuckoo_hash.c
> @@ -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)
> diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
> index 7ecc021111..edfa262aca 100644
> --- a/lib/hash/rte_hash.h
> +++ b/lib/hash/rte_hash.h
> @@ -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
> diff --git a/lib/hash/version.map b/lib/hash/version.map
> index 6b2afebf6b..fac7f81e6f 100644
> --- a/lib/hash/version.map
> +++ b/lib/hash/version.map
> @@ -48,3 +48,9 @@ DPDK_24 {
>
>         local: *;
>  };
> +
> +EXPERIMENTAL {
> +       global:
> +
> +       rte_hash_rcu_qsbr_dq_reclaim;
> +};
> \ No newline at end of file
> --
> 2.34.1
>
>
  
Abdullah Ömer Yamaç April 4, 2024, 10:11 a.m. UTC | #2
Hello,
Could you check the last commit?
Thanks

On Thu, Mar 14, 2024 at 10:04 AM Abdullah Ömer Yamaç <aomeryamac@gmail.com>
wrote:

> Hello,
> Is there any other comment on this?
>
> On Wed, Mar 6, 2024 at 1:13 PM Abdullah Ömer Yamaç <aomeryamac@gmail.com>
> 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ç <aomeryamac@gmail.com>
>> ---
>>  lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++
>>  lib/hash/rte_hash.h        | 24 ++++++++++++++++++++++++
>>  lib/hash/version.map       |  6 ++++++
>>  3 files changed, 53 insertions(+)
>>
>> diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
>> index 9cf94645f6..1c360fa38b 100644
>> --- a/lib/hash/rte_cuckoo_hash.c
>> +++ b/lib/hash/rte_cuckoo_hash.c
>> @@ -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)
>> diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
>> index 7ecc021111..edfa262aca 100644
>> --- a/lib/hash/rte_hash.h
>> +++ b/lib/hash/rte_hash.h
>> @@ -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
>> diff --git a/lib/hash/version.map b/lib/hash/version.map
>> index 6b2afebf6b..fac7f81e6f 100644
>> --- a/lib/hash/version.map
>> +++ b/lib/hash/version.map
>> @@ -48,3 +48,9 @@ DPDK_24 {
>>
>>         local: *;
>>  };
>> +
>> +EXPERIMENTAL {
>> +       global:
>> +
>> +       rte_hash_rcu_qsbr_dq_reclaim;
>> +};
>> \ No newline at end of file
>> --
>> 2.34.1
>>
>>
  
Honnappa Nagarahalli April 5, 2024, 2:11 a.m. UTC | #3
Apologies for the late reply. Looks good, few nits inline.

Can you please some simple unit tests?

> On Apr 4, 2024, at 5:11 AM, Abdullah Ömer Yamaç <aomeryamac@gmail.com> wrote:
> 
> Hello, 
> Could you check the last commit?
> Thanks
> 
> On Thu, Mar 14, 2024 at 10:04 AM Abdullah Ömer Yamaç <aomeryamac@gmail.com> wrote:
> Hello,
> Is there any other comment on this? 
> 
> On Wed, Mar 6, 2024 at 1:13 PM Abdullah Ömer Yamaç <aomeryamac@gmail.com> 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ç <aomeryamac@gmail.com>
> ---
>  lib/hash/rte_cuckoo_hash.c | 23 +++++++++++++++++++++++
>  lib/hash/rte_hash.h        | 24 ++++++++++++++++++++++++
>  lib/hash/version.map       |  6 ++++++
>  3 files changed, 53 insertions(+)
> 
> diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
> index 9cf94645f6..1c360fa38b 100644
> --- a/lib/hash/rte_cuckoo_hash.c
> +++ b/lib/hash/rte_cuckoo_hash.c
> @@ -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.

> +               rte_errno = EINVAL;
> +               return -1;
Return value should be positive 1 as per the API definition below

> +       }
> +
> +       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)
> diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
> index 7ecc021111..edfa262aca 100644
> --- a/lib/hash/rte_hash.h
> +++ b/lib/hash/rte_hash.h
> @@ -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
> diff --git a/lib/hash/version.map b/lib/hash/version.map
> index 6b2afebf6b..fac7f81e6f 100644
> --- a/lib/hash/version.map
> +++ b/lib/hash/version.map
> @@ -48,3 +48,9 @@ DPDK_24 {
> 
>         local: *;
>  };
> +
> +EXPERIMENTAL {
> +       global:
> +
> +       rte_hash_rcu_qsbr_dq_reclaim;
> +};
> \ No newline at end of file
> -- 
> 2.34.1
>
  

Patch

diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index 9cf94645f6..1c360fa38b 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -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)
diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
index 7ecc021111..edfa262aca 100644
--- a/lib/hash/rte_hash.h
+++ b/lib/hash/rte_hash.h
@@ -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
diff --git a/lib/hash/version.map b/lib/hash/version.map
index 6b2afebf6b..fac7f81e6f 100644
--- a/lib/hash/version.map
+++ b/lib/hash/version.map
@@ -48,3 +48,9 @@  DPDK_24 {
 
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	rte_hash_rcu_qsbr_dq_reclaim;
+};
\ No newline at end of file