From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id E9C9D1E34 for ; Sun, 16 Jul 2017 15:26:14 +0200 (CEST) Received: from pure.maildistiller.com (unknown [10.110.50.29]) by dispatch1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTP id 76E8D6005C; Sun, 16 Jul 2017 13:26:14 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from mx1-us1.ppe-hosted.com (unknown [10.110.49.251]) by pure.maildistiller.com (Proofpoint Essentials ESMTP Server) with ESMTPS id DDE856004F; Sun, 16 Jul 2017 13:26:13 +0000 (UTC) Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id B01CE2006C; Sun, 16 Jul 2017 13:26:13 +0000 (UTC) Received: from [192.168.239.128] (85.187.13.33) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Sun, 16 Jul 2017 06:26:09 -0700 To: Stephen Hemminger , CC: Stephen Hemminger References: <20170714183027.16021-1-stephen@networkplumber.org> <20170714183027.16021-2-stephen@networkplumber.org> From: Andrew Rybchenko Message-ID: <0ce78069-6517-aaf1-cfe9-165192a4cc5f@solarflare.com> Date: Sun, 16 Jul 2017 16:26:06 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170714183027.16021-2-stephen@networkplumber.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [85.187.13.33] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ocex03.SolarFlarecom.com (10.20.40.36) X-MDID: 1500211574-nVmIgHQG1tV6 Subject: Re: [dpdk-dev] [RFC 01/14] ethdev: add link status read/write 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: Sun, 16 Jul 2017 13:26:15 -0000 On 07/14/2017 09:30 PM, Stephen Hemminger wrote: > Many drivers are all doing copy/paste of the same code to atomicly > update the link status. Reduce duplication, and allow for future > changes by having common function for this. > > Signed-off-by: Stephen Hemminger > --- > lib/librte_ether/rte_ethdev.c | 36 ++++++++++++++++++++++++++++++++++++ > lib/librte_ether/rte_ethdev.h | 28 ++++++++++++++++++++++++++++ > 2 files changed, 64 insertions(+) > > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c > index a1b744704f3a..7532fc6b65f0 100644 > --- a/lib/librte_ether/rte_ethdev.c > +++ b/lib/librte_ether/rte_ethdev.c > @@ -1332,6 +1332,42 @@ rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link) > } > > int > +_rte_eth_link_update(struct rte_eth_dev *dev, > + const struct rte_eth_link *link) > +{ > + volatile struct rte_eth_link *dev_link = &(dev->data->dev_link); > + struct rte_eth_link old; > + > + RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t)); > + > + old = *dev_link; > + > + /* Only reason we use cmpset rather than set is > + * that on some architecture may use sign bit as a flag value. May I ask to provide more details here. > + */ > + while (rte_atomic64_cmpset((volatile uint64_t *)dev_link, > + *(volatile uint64_t *)dev_link, > + *(const uint64_t *)link) == 0) Shouldn't it be: do { old = *dev_link; } while (rte_atomic64_cmpset((volatile uint64_t *)dev_link, *(uint64_t *)&old, *(const uint64_t *)link) == 0); At least it has some sense to guarantee transition from old to new talking below comparison into account. > + continue; > + > + return (old.link_status == link->link_status) ? -1 : 0; > +} > + > +void _rte_eth_link_read(struct rte_eth_dev *dev, > + struct rte_eth_link *link) > +{ > + const uint64_t *src = (const uint64_t *)&(dev->data->dev_link); > + volatile uint64_t *dst = (uint64_t *)link; > + > + RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t)); > + > + /* Note: this should never fail since both destination and expected > + * values are the same and are a pointer from caller. > + */ > + rte_atomic64_cmpset(dst, *dst, *src); > +} > + > +int > rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats) > { > struct rte_eth_dev *dev; > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h > index f6837278521c..974657933f23 100644 > --- a/lib/librte_ether/rte_ethdev.h > +++ b/lib/librte_ether/rte_ethdev.h > @@ -2219,6 +2219,34 @@ void rte_eth_link_get(uint8_t port_id, struct rte_eth_link *link); > */ > void rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *link); > > + > +/** > + * @internal > + * Atomically write the link status for the specific device. > + * It is for use by DPDK device driver use only. > + * User applications should not call it > + * > + * @param dev > + * Pointer to struct rte_eth_dev. > + * @param link > + * New link status value. > + * @return > + * -1 if link state has changed, 0 if the same. > + */ > +int _rte_eth_link_update(struct rte_eth_dev *dev, > + const struct rte_eth_link *link); > + > +/** > + * @internal > + * Atomically read the link speed and status. > + * @param dev > + * Pointer to struct rte_eth_dev. > + * @param link > + * link status value. > + */ > +void _rte_eth_link_read(struct rte_eth_dev *dev, > + struct rte_eth_link *link); > + > /** > * Retrieve the general I/O statistics of an Ethernet device. > *