[27.03 RFC PATCH v1 5/8] acl: use usage counters for ref counting

Anatoly Burakov anatoly.burakov at intel.com
Fri Oct 16 16:02:12 CEST 2026


Replace raw integer refcounts with EAL usage counters.

Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
 lib/acl/acl.h     | 4 +++-
 lib/acl/acl_bld.c | 9 ++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/acl/acl.h b/lib/acl/acl.h
index e1ecd1567b..8159915ea3 100644
--- a/lib/acl/acl.h
+++ b/lib/acl/acl.h
@@ -5,6 +5,8 @@
 #ifndef	_ACL_H_
 #define	_ACL_H_
 
+#include <rte_usage_count.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -104,7 +106,7 @@ struct rte_acl_match_results {
 struct rte_acl_node {
 	uint64_t node_index;  /* index for this node */
 	uint32_t level;       /* level 0-n in the trie */
-	uint32_t ref_count;   /* ref count for this node */
+	rte_usage_count_t ref_count; /* ref count for this node */
 	struct rte_acl_bitset  values;
 	/* set of all values that map to another node
 	 * (union of bits in each transition.
diff --git a/lib/acl/acl_bld.c b/lib/acl/acl_bld.c
index 99d1dbc467..60ca33a077 100644
--- a/lib/acl/acl_bld.c
+++ b/lib/acl/acl_bld.c
@@ -296,7 +296,7 @@ acl_add_ptr(struct acl_build_context *context,
 			acl_include(&node->ptrs[n].values, bits, 0);
 			acl_include(&node->values, bits, -1);
 			if (ptr != NULL)
-				ptr->ref_count++;
+				rte_usage_count_claim(&ptr->ref_count);
 			if (node->num_ptrs <= n)
 				node->num_ptrs = n + 1;
 			return 0;
@@ -411,7 +411,7 @@ acl_dup_node(struct acl_build_context *context, struct rte_acl_node *node)
 	for (n = 0; n < node->num_ptrs; n++) {
 		if (node->ptrs[n].ptr != NULL) {
 			next->ptrs[n].ptr = node->ptrs[n].ptr;
-			next->ptrs[n].ptr->ref_count++;
+			rte_usage_count_claim(&next->ptrs[n].ptr->ref_count);
 			acl_include(&next->ptrs[n].values,
 				&node->ptrs[n].values, -1);
 		}
@@ -449,8 +449,7 @@ acl_deref_ptr(struct acl_build_context *context,
 	/* De-reference the node at the specified pointer */
 	if (node != NULL && node->ptrs[index].ptr != NULL) {
 		ref_node = node->ptrs[index].ptr;
-		ref_node->ref_count--;
-		if (ref_node->ref_count == 0)
+		if (rte_usage_count_release(&ref_node->ref_count))
 			acl_free_node(context, ref_node);
 	}
 }
@@ -966,7 +965,7 @@ build_trie(struct acl_build_context *context, struct rte_acl_build_rule *head,
 
 		root = acl_alloc_node(context, 0);
 
-		root->ref_count = 1;
+		rte_usage_count_claim(&root->ref_count);
 		end = root;
 
 		for (n = 0; n < rule->config->num_fields; n++) {
-- 
2.52.0



More information about the dev mailing list