From: "Gaëtan Rivet" <gaetan.rivet@6wind.com>
To: Thomas Monjalon <thomas@monjalon.net>
Cc: dev@dpdk.org, ophirmu@mellanox.com, qi.z.zhang@intel.com,
ferruh.yigit@intel.com, ktraynor@redhat.com
Subject: Re: [dpdk-dev] [PATCH v5 5/5] eal: simplify parameters of hotplug functions
Date: Thu, 4 Oct 2018 11:44:37 +0200 [thread overview]
Message-ID: <20181004094437.yx4tfebyxbsfp6ry@bidouze.vm.6wind.com> (raw)
In-Reply-To: <20181003231046.26772-6-thomas@monjalon.net>
I much prefer this API,
I have one remark inline however.
On Thu, Oct 04, 2018 at 01:10:46AM +0200, Thomas Monjalon wrote:
> All information about a device to probe can be grouped
> in a common string, which is what we usually call devargs.
> An application should not have to parse this string before
> calling the EAL probe function.
> And the syntax could evolve to be more complex and support
> matching multiple devices in one string.
> That's why the bus name and device name should be removed from
> rte_eal_hotplug_add().
> Instead of changing this function, a simpler one is added
> and used in the old one, which may be deprecated later.
>
> When removing a device, we already know its rte_device handle
> which can be directly passed as parameter of rte_eal_hotplug_remove().
> If the rte_device is not known, it can be retrieved with the devargs,
> by iterating in the device list (future RTE_DEV_FOREACH()).
> Similarly to the probing case, a new function is added
> and used in the old one, which may be deprecated later.
> The new function is used in failsafe, because the replacement is easy.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Reviewed-by: Andrew Rybchenko <arybchenko@solarflare.com>
With the following remark being taken care of,
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
> drivers/net/failsafe/failsafe_eal.c | 3 +-
> drivers/net/failsafe/failsafe_ether.c | 3 +-
> lib/librte_eal/common/eal_common_dev.c | 80 ++++++++++++++++---------
> lib/librte_eal/common/include/rte_dev.h | 30 +++++++++-
> lib/librte_eal/rte_eal_version.map | 2 +
> 5 files changed, 83 insertions(+), 35 deletions(-)
>
<snip>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index ce6d145fb..5dcc1403f 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -129,46 +129,61 @@ int rte_eal_dev_detach(struct rte_device *dev)
>
> int
> rte_eal_hotplug_add(const char *busname, const char *devname,
> - const char *devargs)
> + const char *drvargs)
> {
> - struct rte_bus *bus;
> - struct rte_device *dev;
> - struct rte_devargs *da;
> int ret;
> + char *devargs = NULL;
> + int size, length = -1;
>
> - bus = rte_bus_find_by_name(busname);
> - if (bus == NULL) {
> - RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname);
> - return -ENOENT;
> - }
> + do { /* 2 iterations: first is to know string length */
> + size = length + 1;
> + length = snprintf(devargs, size, "%s:%s,%s", busname, devname, drvargs);
> + if (length >= size)
> + devargs = malloc(length + 1);
> + if (devargs == NULL)
> + return -ENOMEM;
> + } while (size == 0);
I don't see a good reason for writing it this way.
You use an additional state (size) and complicate something that is
pretty straightforward. To make sure no error was written here, I had to
do step-by-step careful reading, this should not be required by clean
code.
You should remove this loop, which then allow removing size, and forces using
simple code-flow.
>
> - if (bus->plug == NULL) {
> - RTE_LOG(ERR, EAL, "Function plug not supported by bus (%s)\n",
> - bus->name);
> - return -ENOTSUP;
> - }
> + ret = rte_dev_probe(devargs);
> +
> + free(devargs);
> + return ret;
> +}
> +
> +int __rte_experimental
> +rte_dev_probe(const char *devargs)
> +{
> + struct rte_device *dev;
> + struct rte_devargs *da;
> + int ret;
>
> da = calloc(1, sizeof(*da));
> if (da == NULL)
> return -ENOMEM;
>
> - ret = rte_devargs_parsef(da, "%s:%s,%s",
> - busname, devname, devargs);
> + ret = rte_devargs_parse(da, devargs);
> if (ret)
> goto err_devarg;
>
> + if (da->bus->plug == NULL) {
> + RTE_LOG(ERR, EAL, "Function plug not supported by bus (%s)\n",
> + da->bus->name);
> + ret = -ENOTSUP;
> + goto err_devarg;
> + }
> +
> ret = rte_devargs_insert(da);
> if (ret)
> goto err_devarg;
>
> - ret = bus->scan();
> + ret = da->bus->scan();
> if (ret)
> goto err_devarg;
>
> - dev = bus->find_device(NULL, cmp_dev_name, devname);
> + dev = da->bus->find_device(NULL, cmp_dev_name, da->name);
> if (dev == NULL) {
> RTE_LOG(ERR, EAL, "Cannot find device (%s)\n",
> - devname);
> + da->name);
> ret = -ENODEV;
> goto err_devarg;
> }
<snip>
--
Gaëtan Rivet
6WIND
next prev parent reply other threads:[~2018-10-04 9:44 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-07 22:27 [dpdk-dev] [RFC] " Thomas Monjalon
2018-09-26 21:47 ` [dpdk-dev] [PATCH v2 0/4] eal: simplify devargs and " Thomas Monjalon
2018-09-26 21:47 ` [dpdk-dev] [PATCH v2 1/4] devargs: remove deprecated functions Thomas Monjalon
2018-09-26 21:47 ` [dpdk-dev] [PATCH v2 2/4] devargs: simplify parameters of removal function Thomas Monjalon
2018-09-27 8:24 ` Ophir Munk
2018-09-27 21:31 ` Thomas Monjalon
2018-09-26 21:47 ` [dpdk-dev] [PATCH v2 3/4] eal: remove experimental flag of hotplug functions Thomas Monjalon
2018-09-26 21:47 ` [dpdk-dev] [PATCH v2 4/4] eal: simplify parameters " Thomas Monjalon
2018-09-28 16:21 ` [dpdk-dev] [PATCH v3 0/4] eal: simplify devargs and " Thomas Monjalon
2018-09-28 16:21 ` [dpdk-dev] [PATCH v3 1/4] devargs: remove deprecated functions Thomas Monjalon
2018-10-01 11:24 ` Andrew Rybchenko
2018-10-01 17:10 ` Thomas Monjalon
2018-09-28 16:21 ` [dpdk-dev] [PATCH v3 2/4] devargs: simplify parameters of removal function Thomas Monjalon
2018-10-01 11:25 ` Andrew Rybchenko
2018-10-01 19:47 ` Thomas Monjalon
2018-09-28 16:21 ` [dpdk-dev] [PATCH v3 3/4] eal: remove experimental flag of hotplug functions Thomas Monjalon
2018-10-01 11:26 ` Andrew Rybchenko
2018-10-01 19:54 ` Thomas Monjalon
2018-10-02 10:28 ` Ferruh Yigit
2018-10-03 8:42 ` Thomas Monjalon
2018-09-28 16:21 ` [dpdk-dev] [PATCH v3 4/4] eal: simplify parameters " Thomas Monjalon
2018-10-01 11:26 ` Andrew Rybchenko
2018-10-01 20:03 ` Thomas Monjalon
2018-10-01 20:52 ` [dpdk-dev] [PATCH v4 0/4] eal: simplify devargs and " Thomas Monjalon
2018-10-01 20:52 ` [dpdk-dev] [PATCH v4 1/4] devargs: remove deprecated functions Thomas Monjalon
2018-10-01 20:52 ` [dpdk-dev] [PATCH v4 2/4] devargs: simplify parameters of removal function Thomas Monjalon
2018-10-01 20:52 ` [dpdk-dev] [PATCH v4 3/4] eal: remove experimental flag of hotplug functions Thomas Monjalon
2018-10-01 20:52 ` [dpdk-dev] [PATCH v4 4/4] eal: simplify parameters " Thomas Monjalon
2018-10-03 23:10 ` [dpdk-dev] [PATCH v5 0/5] eal: simplify devargs and " Thomas Monjalon
2018-10-03 23:10 ` [dpdk-dev] [PATCH v5 1/5] devargs: remove deprecated functions Thomas Monjalon
2018-10-04 9:19 ` Gaëtan Rivet
2018-10-03 23:10 ` [dpdk-dev] [PATCH v5 2/5] devargs: simplify parameters of removal function Thomas Monjalon
2018-10-04 9:21 ` Gaëtan Rivet
2018-10-03 23:10 ` [dpdk-dev] [PATCH v5 3/5] eal: add bus pointer in device structure Thomas Monjalon
2018-10-04 9:31 ` Gaëtan Rivet
2018-10-04 9:48 ` Thomas Monjalon
2018-10-03 23:10 ` [dpdk-dev] [PATCH v5 4/5] eal: remove experimental flag of hotplug functions Thomas Monjalon
2018-10-04 9:33 ` Gaëtan Rivet
2018-10-03 23:10 ` [dpdk-dev] [PATCH v5 5/5] eal: simplify parameters " Thomas Monjalon
2018-10-04 9:44 ` Gaëtan Rivet [this message]
2018-10-04 11:46 ` Thomas Monjalon
2018-10-04 11:51 ` Gaëtan Rivet
2018-10-07 9:32 ` [dpdk-dev] [PATCH v6 0/5] eal: simplify devargs and " Thomas Monjalon
2018-10-07 9:32 ` [dpdk-dev] [PATCH v6 1/5] devargs: remove deprecated functions Thomas Monjalon
2018-10-07 9:32 ` [dpdk-dev] [PATCH v6 2/5] devargs: simplify parameters of removal function Thomas Monjalon
2018-10-07 9:32 ` [dpdk-dev] [PATCH v6 3/5] eal: add bus pointer in device structure Thomas Monjalon
2018-10-07 9:32 ` [dpdk-dev] [PATCH v6 4/5] eal: remove experimental flag of hotplug functions Thomas Monjalon
2018-10-07 9:32 ` [dpdk-dev] [PATCH v6 5/5] eal: simplify parameters " Thomas Monjalon
2018-10-08 21:45 ` [dpdk-dev] [PATCH v6 0/5] eal: simplify devargs and " Stephen Hemminger
2018-10-11 12:10 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181004094437.yx4tfebyxbsfp6ry@bidouze.vm.6wind.com \
--to=gaetan.rivet@6wind.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=ktraynor@redhat.com \
--cc=ophirmu@mellanox.com \
--cc=qi.z.zhang@intel.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).