From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-000f0801.pphosted.com (mx0b-000f0801.pphosted.com [67.231.152.113]) by dpdk.org (Postfix) with ESMTP id DB068201 for ; Thu, 29 Dec 2016 16:49:12 +0100 (CET) Received: from pps.filterd (m0000700.ppops.net [127.0.0.1]) by mx0b-000f0801.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uBTFdplC011308; Thu, 29 Dec 2016 07:49:12 -0800 Received: from brmwp-exmb11.corp.brocade.com ([208.47.132.227]) by mx0b-000f0801.pphosted.com with ESMTP id 27hqh5vfwr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 29 Dec 2016 07:49:12 -0800 Received: from [10.252.139.5] (10.252.139.5) by BRMWP-EXMB11.corp.brocade.com (172.16.59.77) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 29 Dec 2016 08:49:10 -0700 To: Yuanhan Liu References: <1482959452-18486-1-git-send-email-ciwillia@brocade.com> <20161229085132.GC21789@yliu-dev.sh.intel.com> CC: , , Wen Chiu From: "Charles (Chas) Williams" Message-ID: Date: Thu, 29 Dec 2016 10:49:08 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.5.1 MIME-Version: 1.0 In-Reply-To: <20161229085132.GC21789@yliu-dev.sh.intel.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: hq1wp-excas11.corp.brocade.com (10.70.36.102) To BRMWP-EXMB11.corp.brocade.com (172.16.59.77) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-29_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1612290232 Subject: Re: [dpdk-dev] [PATCH 1/2] vhost: reference count fix for nb_started_ports 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, 29 Dec 2016 15:49:13 -0000 On 12/29/2016 03:51 AM, Yuanhan Liu wrote: > On Wed, Dec 28, 2016 at 04:10:51PM -0500, Charles (Chas) Williams wrote: >> From: Wen Chiu >> >> Only increment and decrement nb_started_ports on the first and last >> device start and stop. Otherwise, nb_started_ports can become negative >> if a device is stopped multiple times. > > How could you be able to stop dev (precisely, invoke eth_dev_stop) > multiple times, judging that eth_dev_stop() will be invoked once > only? > > void > rte_eth_dev_stop(uint8_t port_id) > { > struct rte_eth_dev *dev; > > RTE_ETH_VALID_PORTID_OR_RET(port_id); > dev = &rte_eth_devices[port_id]; > > RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop); > > ==> if (dev->data->dev_started == 0) { > RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8 > " already stopped\n", > port_id); > return; > } > > ==> dev->data->dev_started = 0; > (*dev->dev_ops->dev_stop)(dev); > } > > Multiple threads? No, we aren't using multiple threads for control. But eth_dev_stop() is called in rte_pmd_vhost_remove(): static int rte_pmd_vhost_remove(const char *name) { ... pthread_mutex_lock(&internal_list_lock); TAILQ_REMOVE(&internal_list, list, next); pthread_mutex_unlock(&internal_list_lock); rte_free(list); eth_dev_stop(eth_dev); ... So, if we .dev_stop() and deatch the virtual device, eth_dev_stop() gets called twice. Calling .dev_stop() when you are about to detach the device seems completely reasonable. It also seems reasonable to call eth_dev_stop() inside rte_pmd_vhost_remove() in case the end user didn't do a .dev_stop().