[3/4] eal: add API to check if lcore id is valid

Message ID 20230309045738.1261000-4-honnappa.nagarahalli@arm.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series Small corrections in mempool |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Honnappa Nagarahalli March 9, 2023, 4:57 a.m. UTC
  Simple API to check if the lcore ID does not exceed the
maximum number of lcores configured.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
 lib/eal/include/rte_lcore.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Morten Brørup June 7, 2023, 10:19 a.m. UTC | #1
> From: Honnappa Nagarahalli [mailto:honnappa.nagarahalli@arm.com]
> Sent: Thursday, 9 March 2023 05.58
> 
> Simple API to check if the lcore ID does not exceed the
> maximum number of lcores configured.
> 
> Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> ---
>  lib/eal/include/rte_lcore.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
> index 6a355e9986..cf99919a02 100644
> --- a/lib/eal/include/rte_lcore.h
> +++ b/lib/eal/include/rte_lcore.h
> @@ -38,6 +38,20 @@ enum rte_lcore_role_t {
>  	ROLE_NON_EAL,
>  };
> 
> +/**
> + * Check if the lcore ID is valid
> + *
> + * @param lcore_id
> + *   The identifier of the lcore.
> + *
> + * @return
> + *   True if the given lcore ID is between 0 and RTE_MAX_LCORE-1.
> + */
> +static inline int rte_lcore_id_is_valid(unsigned int lcore_id)
> +{
> +	return (lcore_id < RTE_MAX_LCORE);
> +}
> +
>  /**
>   * Get a lcore's role.
>   *
> --
> 2.25.1
> 

Isn't LCORE_ID_ANY considered valid in some contexts?

I don't think this function adds any value; it only makes the lcore_id interpretation more opaque. Having this comparison, i.e. (lcore_id < RTE_MAX_LCORE), directly in the source code makes it more easily readable than a call to this function.

So, NAK from me.
  
Stephen Hemminger June 7, 2023, 3:05 p.m. UTC | #2
On Wed, 7 Jun 2023 12:19:00 +0200
Morten Brørup <mb@smartsharesystems.com> wrote:

> > From: Honnappa Nagarahalli [mailto:honnappa.nagarahalli@arm.com]
> > Sent: Thursday, 9 March 2023 05.58
> > 
> > Simple API to check if the lcore ID does not exceed the
> > maximum number of lcores configured.
> > 
> > Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>

What about cases where passed lcore set is sparse?
In that case, lcore would not be valid in API calls.
  

Patch

diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6a355e9986..cf99919a02 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -38,6 +38,20 @@  enum rte_lcore_role_t {
 	ROLE_NON_EAL,
 };
 
+/**
+ * Check if the lcore ID is valid
+ *
+ * @param lcore_id
+ *   The identifier of the lcore.
+ *
+ * @return
+ *   True if the given lcore ID is between 0 and RTE_MAX_LCORE-1.
+ */
+static inline int rte_lcore_id_is_valid(unsigned int lcore_id)
+{
+	return (lcore_id < RTE_MAX_LCORE);
+}
+
 /**
  * Get a lcore's role.
  *