From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id B45241B138 for ; Thu, 4 Oct 2018 11:44:56 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id y16so9168862wrw.3 for ; Thu, 04 Oct 2018 02:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=xCaycom+NB8nGVrqtePHdsszNd0GZkDW0HKaG5bKBy4=; b=RsEmprj//N4pxcDtEILdO18RA3ikLewY9V/Tq0ssCgSdd5XLJL/c+6EbbaCpgXlfEW EVkIKtcAvdgmL9rszjaEIOXXt1dXPKkRQtrt661XdcXrP598i9rjOIgMAh4eH0jwSLp3 sTf0DIRE2zjxpevOU4Q3issz0bH8EggVkItsUS71gjkP5YO4Dl0JCnjaa+GE5jwsfSzN l8MprIPzmjTaHtIN5VeTO1YQ0qNTRPDUUhQo2v7BVendUlf2AwVhRVjL2CzW8DRl2TJi HTorsDX55BL5+hUT+du6pUmvndEcxj+/JeUfTQDgEemIovgqe9/EzFYcV6njdR+6zIYD wQZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=xCaycom+NB8nGVrqtePHdsszNd0GZkDW0HKaG5bKBy4=; b=JvJ7YkZA8Fo+3nEzjptQJjmQ6N+Rl4o0x+4sI4hx/OI+egxQkiqLVwcJ590+KTYnF3 8qglxjZnAJ3SHB3/EA8w63LqEJv/83bgaIxRU9AqvMYvTNsN26CmpSsXHoMa/bGYFC9Q MMkZcJkZBMHx7Y/pMFi4EDWaKpxKdUbHc7xOo7OK/rLeZNuTk4CZ2Sk7JFKOgaOFEheC dgaPoMd1iXnqAg9sj5BFJJk1AM4cVR8zYbBmSp5gKi169/i3qx9qf43F3RUwPHzUUTqX OXJGP3KolueAO5EwsuG44gNdMzbHMLHF8ptq0TndhcPoAYMA2MEnHgMFVtNsHHrm/QPV umJw== X-Gm-Message-State: ABuFfoiCv6NzAfLKJgSoH/96/yliP9eYkzD7+JjSPJ3Bxdd0qCh8nsB6 zf7CFdT9v8jDRQtbpzT3EGLNvDtZojs= X-Google-Smtp-Source: ACcGV612FAo63ZojSHjBFW+IbY5vkaSWI3PdUkhLLe5x/wH0WJNwlAVXdZCY4FKf4cVhlTkOYcO2Yw== X-Received: by 2002:adf:9e09:: with SMTP id u9-v6mr4068010wre.51.1538646296213; Thu, 04 Oct 2018 02:44:56 -0700 (PDT) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id g76-v6sm5882305wmd.25.2018.10.04.02.44.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Oct 2018 02:44:55 -0700 (PDT) Date: Thu, 4 Oct 2018 11:44:37 +0200 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: Thomas Monjalon Cc: dev@dpdk.org, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com, ktraynor@redhat.com Message-ID: <20181004094437.yx4tfebyxbsfp6ry@bidouze.vm.6wind.com> References: <20180907222727.20521-1-thomas@monjalon.net> <20181003231046.26772-1-thomas@monjalon.net> <20181003231046.26772-6-thomas@monjalon.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181003231046.26772-6-thomas@monjalon.net> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] [PATCH v5 5/5] eal: simplify parameters of hotplug functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Oct 2018 09:44:56 -0000 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 > Reviewed-by: Andrew Rybchenko With the following remark being taken care of, Acked-by: Gaetan Rivet > --- > 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(-) > > 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; > } -- Gaëtan Rivet 6WIND