[dpdk-dev,v4,01/10] devargs: introduce iterator

Message ID 4ae5a6e418b19a458aefee0621af9cc7baf76aab.1524522515.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Gaëtan Rivet April 23, 2018, 10:41 p.m. UTC
  In preparation to making devargs_list private.

Bus drivers generally need to access rte_devargs pertaining to their
operations. This match is a common operation for bus drivers.

Add a new accessor for the rte_devargs list.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 20 ++++++++++++++++++++
 lib/librte_eal/common/include/rte_devargs.h | 20 ++++++++++++++++++++
 lib/librte_eal/rte_eal_version.map          |  1 +
 3 files changed, 41 insertions(+)
  

Comments

Stephen Hemminger April 23, 2018, 11:54 p.m. UTC | #1
On Tue, 24 Apr 2018 00:41:01 +0200
Gaetan Rivet <gaetan.rivet@6wind.com> wrote:

> In preparation to making devargs_list private.
> 
> Bus drivers generally need to access rte_devargs pertaining to their
> operations. This match is a common operation for bus drivers.
> 
> Add a new accessor for the rte_devargs list.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/eal_common_devargs.c  | 20 ++++++++++++++++++++
>  lib/librte_eal/common/include/rte_devargs.h | 20 ++++++++++++++++++++
>  lib/librte_eal/rte_eal_version.map          |  1 +
>  3 files changed, 41 insertions(+)
> 
> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> index 810b3e18f..c6c5eabcf 100644
> --- a/lib/librte_eal/common/eal_common_devargs.c
> +++ b/lib/librte_eal/common/eal_common_devargs.c
> @@ -207,3 +207,23 @@ rte_eal_devargs_dump(FILE *f)
>  			devargs->name, devargs->args);
>  	}
>  }
> +
> +/* bus-aware rte_devargs iterator. */
> +__rte_experimental
> +struct rte_devargs *
> +rte_eal_devargs_next(const char *busname, const struct rte_devargs *start)
> +{
> +	struct rte_devargs *da;
> +
> +	if (start != NULL)
> +		da = TAILQ_NEXT(start, next);
> +	else
> +		da = TAILQ_FIRST(&devargs_list);
> +	while (da != NULL) {
> +		if (busname == NULL ||
> +		    (strcmp(busname, da->bus->name) == 0))
> +			return da;
> +		da = TAILQ_NEXT(da, next);
> +	}
> +	return NULL;
> +}

Can this be made to return a const pointer? It seems unsymmetrical to
get the next value as a non-const pointer when passed a const based on last value.
  
Gaëtan Rivet April 24, 2018, 10:22 a.m. UTC | #2
On Mon, Apr 23, 2018 at 04:54:17PM -0700, Stephen Hemminger wrote:
> On Tue, 24 Apr 2018 00:41:01 +0200
> Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> 
> > In preparation to making devargs_list private.
> > 
> > Bus drivers generally need to access rte_devargs pertaining to their
> > operations. This match is a common operation for bus drivers.
> > 
> > Add a new accessor for the rte_devargs list.
> > 
> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> >  lib/librte_eal/common/eal_common_devargs.c  | 20 ++++++++++++++++++++
> >  lib/librte_eal/common/include/rte_devargs.h | 20 ++++++++++++++++++++
> >  lib/librte_eal/rte_eal_version.map          |  1 +
> >  3 files changed, 41 insertions(+)
> > 
> > diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> > index 810b3e18f..c6c5eabcf 100644
> > --- a/lib/librte_eal/common/eal_common_devargs.c
> > +++ b/lib/librte_eal/common/eal_common_devargs.c
> > @@ -207,3 +207,23 @@ rte_eal_devargs_dump(FILE *f)
> >  			devargs->name, devargs->args);
> >  	}
> >  }
> > +
> > +/* bus-aware rte_devargs iterator. */
> > +__rte_experimental
> > +struct rte_devargs *
> > +rte_eal_devargs_next(const char *busname, const struct rte_devargs *start)
> > +{
> > +	struct rte_devargs *da;
> > +
> > +	if (start != NULL)
> > +		da = TAILQ_NEXT(start, next);
> > +	else
> > +		da = TAILQ_FIRST(&devargs_list);
> > +	while (da != NULL) {
> > +		if (busname == NULL ||
> > +		    (strcmp(busname, da->bus->name) == 0))
> > +			return da;
> > +		da = TAILQ_NEXT(da, next);
> > +	}
> > +	return NULL;
> > +}
> 
> Can this be made to return a const pointer? It seems unsymmetrical to
> get the next value as a non-const pointer when passed a const based on last value.
> 

I would like to, but this iterator is used in buses to match devargs and
assign it to an rte_devive. The devargs field there is not const.

We don't have a deprecation notice running on this. This might be worth
it, though, but I think this could come after integrating this series.
  

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 810b3e18f..c6c5eabcf 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -207,3 +207,23 @@  rte_eal_devargs_dump(FILE *f)
 			devargs->name, devargs->args);
 	}
 }
+
+/* bus-aware rte_devargs iterator. */
+__rte_experimental
+struct rte_devargs *
+rte_eal_devargs_next(const char *busname, const struct rte_devargs *start)
+{
+	struct rte_devargs *da;
+
+	if (start != NULL)
+		da = TAILQ_NEXT(start, next);
+	else
+		da = TAILQ_FIRST(&devargs_list);
+	while (da != NULL) {
+		if (busname == NULL ||
+		    (strcmp(busname, da->bus->name) == 0))
+			return da;
+		da = TAILQ_NEXT(da, next);
+	}
+	return NULL;
+}
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 84e5e23c4..969a10449 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -189,6 +189,26 @@  rte_eal_devargs_type_count(enum rte_devtype devtype);
  */
 void rte_eal_devargs_dump(FILE *f);
 
+/**
+ * Find next rte_devargs matching the provided bus name.
+ *
+ * @param busname
+ *   Limit the iteration to devargs related to buses
+ *   matching this name.
+ *   Will return any next rte_devargs if NULL.
+ *
+ * @param start
+ *   Starting iteration point. The iteration will start at
+ *   the first rte_devargs if NULL.
+ *
+ * @return
+ *   Next rte_devargs entry matching the requested bus,
+ *   NULL if there is none.
+ */
+__rte_experimental
+struct rte_devargs *
+rte_eal_devargs_next(const char *busname, const struct rte_devargs *start);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index d02d80b8a..74c779068 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -219,6 +219,7 @@  EXPERIMENTAL {
 	rte_dev_event_monitor_stop;
 	rte_eal_cleanup;
 	rte_eal_devargs_insert;
+	rte_eal_devargs_next;
 	rte_eal_devargs_parse;
 	rte_eal_devargs_remove;
 	rte_eal_hotplug_add;