[2/2] rib6: mark error tests with unlikely

Message ID 20220413020935.90499-3-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series small RIB optimizations |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Stephen Hemminger April 13, 2022, 2:09 a.m. UTC
  Also mark some conditional functions as const.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/rib/rte_rib6.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
  

Comments

Vladimir Medvedkin April 26, 2022, 2:27 p.m. UTC | #1
On 13/04/2022 03:09, Stephen Hemminger wrote:
> Also mark some conditional functions as const.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>   lib/rib/rte_rib6.c | 25 ++++++++++++-------------
>   1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/lib/rib/rte_rib6.c b/lib/rib/rte_rib6.c
> index 042ac1f090bf..650bf1b8f681 100644
> --- a/lib/rib/rte_rib6.c
> +++ b/lib/rib/rte_rib6.c
> @@ -47,13 +47,13 @@ struct rte_rib6 {
>   };
>   
>   static inline bool
> -is_valid_node(struct rte_rib6_node *node)
> +is_valid_node(const struct rte_rib6_node *node)
>   {
>   	return (node->flag & RTE_RIB_VALID_NODE) == RTE_RIB_VALID_NODE;
>   }
>   
>   static inline bool
> -is_right_node(struct rte_rib6_node *node)
> +is_right_node(const struct rte_rib6_node *node)
>   {
>   	return node->parent->right == node;
>   }
> @@ -171,7 +171,7 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib,
>   	uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE];
>   	int i;
>   
> -	if ((rib == NULL) || (ip == NULL) || (depth > RIB6_MAXDEPTH)) {
> +	if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) {
>   		rte_errno = EINVAL;
>   		return NULL;
>   	}
> @@ -210,7 +210,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib,
>   	uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE];
>   	int i;
>   
> -	if ((rib == NULL) || (ip == NULL) || (depth > RIB6_MAXDEPTH)) {
> +	if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) {
>   		rte_errno = EINVAL;
>   		return NULL;
>   	}
> @@ -293,8 +293,7 @@ rte_rib6_insert(struct rte_rib6 *rib,
>   	int i, d;
>   	uint8_t common_depth, ip_xor;
>   
> -	if (unlikely((rib == NULL) || (ip == NULL) ||
> -			(depth > RIB6_MAXDEPTH))) {
> +	if (unlikely((rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH))) {
>   		rte_errno = EINVAL;
>   		return NULL;
>   	}
> @@ -413,7 +412,7 @@ int
>   rte_rib6_get_ip(const struct rte_rib6_node *node,
>   		uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
>   {
> -	if ((node == NULL) || (ip == NULL)) {
> +	if (unlikely(node == NULL || ip == NULL)) {
>   		rte_errno = EINVAL;
>   		return -1;
>   	}
> @@ -424,7 +423,7 @@ rte_rib6_get_ip(const struct rte_rib6_node *node,
>   int
>   rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth)
>   {
> -	if ((node == NULL) || (depth == NULL)) {
> +	if (unlikely(node == NULL || depth == NULL)) {
>   		rte_errno = EINVAL;
>   		return -1;
>   	}
> @@ -441,7 +440,7 @@ rte_rib6_get_ext(struct rte_rib6_node *node)
>   int
>   rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
>   {
> -	if ((node == NULL) || (nh == NULL)) {
> +	if (unlikely(node == NULL || nh == NULL)) {
>   		rte_errno = EINVAL;
>   		return -1;
>   	}
> @@ -452,7 +451,7 @@ rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
>   int
>   rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh)
>   {
> -	if (node == NULL) {
> +	if (unlikely(node == NULL)) {
>   		rte_errno = EINVAL;
>   		return -1;
>   	}
> @@ -471,7 +470,7 @@ rte_rib6_create(const char *name, int socket_id,
>   	struct rte_mempool *node_pool;
>   
>   	/* Check user arguments. */
> -	if (name == NULL || conf == NULL || conf->max_nodes <= 0) {
> +	if (unlikely(name == NULL || conf == NULL || conf->max_nodes <= 0)) {
>   		rte_errno = EINVAL;
>   		return NULL;
>   	}
> @@ -506,7 +505,7 @@ rte_rib6_create(const char *name, int socket_id,
>   
>   	/* allocate tailq entry */
>   	te = rte_zmalloc("RIB6_TAILQ_ENTRY", sizeof(*te), 0);
> -	if (te == NULL) {
> +	if (unlikely(te == NULL)) {
>   		RTE_LOG(ERR, LPM,
>   			"Can not allocate tailq entry for RIB6 %s\n", name);
>   		rte_errno = ENOMEM;
> @@ -516,7 +515,7 @@ rte_rib6_create(const char *name, int socket_id,
>   	/* Allocate memory to store the RIB6 data structures. */
>   	rib = rte_zmalloc_socket(mem_name,
>   		sizeof(struct rte_rib6), RTE_CACHE_LINE_SIZE, socket_id);
> -	if (rib == NULL) {
> +	if (unlikely(rib == NULL)) {
>   		RTE_LOG(ERR, LPM, "RIB6 %s memory allocation failed\n", name);
>   		rte_errno = ENOMEM;
>   		goto free_te;

Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
  

Patch

diff --git a/lib/rib/rte_rib6.c b/lib/rib/rte_rib6.c
index 042ac1f090bf..650bf1b8f681 100644
--- a/lib/rib/rte_rib6.c
+++ b/lib/rib/rte_rib6.c
@@ -47,13 +47,13 @@  struct rte_rib6 {
 };
 
 static inline bool
-is_valid_node(struct rte_rib6_node *node)
+is_valid_node(const struct rte_rib6_node *node)
 {
 	return (node->flag & RTE_RIB_VALID_NODE) == RTE_RIB_VALID_NODE;
 }
 
 static inline bool
-is_right_node(struct rte_rib6_node *node)
+is_right_node(const struct rte_rib6_node *node)
 {
 	return node->parent->right == node;
 }
@@ -171,7 +171,7 @@  rte_rib6_lookup_exact(struct rte_rib6 *rib,
 	uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE];
 	int i;
 
-	if ((rib == NULL) || (ip == NULL) || (depth > RIB6_MAXDEPTH)) {
+	if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
@@ -210,7 +210,7 @@  rte_rib6_get_nxt(struct rte_rib6 *rib,
 	uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE];
 	int i;
 
-	if ((rib == NULL) || (ip == NULL) || (depth > RIB6_MAXDEPTH)) {
+	if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
@@ -293,8 +293,7 @@  rte_rib6_insert(struct rte_rib6 *rib,
 	int i, d;
 	uint8_t common_depth, ip_xor;
 
-	if (unlikely((rib == NULL) || (ip == NULL) ||
-			(depth > RIB6_MAXDEPTH))) {
+	if (unlikely((rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH))) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
@@ -413,7 +412,7 @@  int
 rte_rib6_get_ip(const struct rte_rib6_node *node,
 		uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
 {
-	if ((node == NULL) || (ip == NULL)) {
+	if (unlikely(node == NULL || ip == NULL)) {
 		rte_errno = EINVAL;
 		return -1;
 	}
@@ -424,7 +423,7 @@  rte_rib6_get_ip(const struct rte_rib6_node *node,
 int
 rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth)
 {
-	if ((node == NULL) || (depth == NULL)) {
+	if (unlikely(node == NULL || depth == NULL)) {
 		rte_errno = EINVAL;
 		return -1;
 	}
@@ -441,7 +440,7 @@  rte_rib6_get_ext(struct rte_rib6_node *node)
 int
 rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
 {
-	if ((node == NULL) || (nh == NULL)) {
+	if (unlikely(node == NULL || nh == NULL)) {
 		rte_errno = EINVAL;
 		return -1;
 	}
@@ -452,7 +451,7 @@  rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
 int
 rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh)
 {
-	if (node == NULL) {
+	if (unlikely(node == NULL)) {
 		rte_errno = EINVAL;
 		return -1;
 	}
@@ -471,7 +470,7 @@  rte_rib6_create(const char *name, int socket_id,
 	struct rte_mempool *node_pool;
 
 	/* Check user arguments. */
-	if (name == NULL || conf == NULL || conf->max_nodes <= 0) {
+	if (unlikely(name == NULL || conf == NULL || conf->max_nodes <= 0)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
@@ -506,7 +505,7 @@  rte_rib6_create(const char *name, int socket_id,
 
 	/* allocate tailq entry */
 	te = rte_zmalloc("RIB6_TAILQ_ENTRY", sizeof(*te), 0);
-	if (te == NULL) {
+	if (unlikely(te == NULL)) {
 		RTE_LOG(ERR, LPM,
 			"Can not allocate tailq entry for RIB6 %s\n", name);
 		rte_errno = ENOMEM;
@@ -516,7 +515,7 @@  rte_rib6_create(const char *name, int socket_id,
 	/* Allocate memory to store the RIB6 data structures. */
 	rib = rte_zmalloc_socket(mem_name,
 		sizeof(struct rte_rib6), RTE_CACHE_LINE_SIZE, socket_id);
-	if (rib == NULL) {
+	if (unlikely(rib == NULL)) {
 		RTE_LOG(ERR, LPM, "RIB6 %s memory allocation failed\n", name);
 		rte_errno = ENOMEM;
 		goto free_te;