[3/4] eal: add API to check if lcore id is valid
Checks
Commit Message
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
> 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.
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.
@@ -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.
*