From patchwork Sun Jan 1 18:53:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chas Williams X-Patchwork-Id: 18760 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 9CEC35592; Sun, 1 Jan 2017 19:55:29 +0100 (CET) Received: from mx0a-000f0801.pphosted.com (mx0a-000f0801.pphosted.com [67.231.144.122]) by dpdk.org (Postfix) with ESMTP id 2D5354CE6 for ; Sun, 1 Jan 2017 19:54:03 +0100 (CET) Received: from pps.filterd (m0048193.ppops.net [127.0.0.1]) by mx0a-000f0801.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id v01I5NWr032497; Sun, 1 Jan 2017 10:54:03 -0800 Received: from brmwp-exmb11.corp.brocade.com ([208.47.132.227]) by mx0a-000f0801.pphosted.com with ESMTP id 27pc9baq3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 01 Jan 2017 10:54:02 -0800 Received: from confsjhq2-2-001.brocade.com (10.252.139.5) by BRMWP-EXMB11.corp.brocade.com (172.16.59.77) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sun, 1 Jan 2017 11:54:00 -0700 From: "Charles (Chas) Williams" To: CC: , , "Charles (Chas) Williams" Date: Sun, 1 Jan 2017 13:53:48 -0500 Message-ID: <1483296828-18544-2-git-send-email-ciwillia@brocade.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1483296828-18544-1-git-send-email-ciwillia@brocade.com> References: <1483296828-18544-1-git-send-email-ciwillia@brocade.com> MIME-Version: 1.0 X-ClientProxiedBy: hq1wp-excas13.corp.brocade.com (10.70.36.103) To BRMWP-EXMB11.corp.brocade.com (172.16.59.77) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-01_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 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-1701010286 Subject: [dpdk-dev] [PATCH v2 2/2] net/vhost: emulate device start/stop behavior 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" .dev_start()/.dev_stop() roughly corresponds to the local device's port being up or down. This is different from the remote client being connected which is roughtly link up or down. Emulate the behavior by separately tracking the local start/stop state to determine if we should allow packets to be queued to the remote client. Signed-off-by: Chas Williams --- drivers/net/vhost/rte_eth_vhost.c | 65 ++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 6b11e40..c9e45eb 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -100,7 +100,8 @@ struct vhost_stats { struct vhost_queue { int vid; - rte_atomic32_t allow_queuing; + rte_atomic32_t connected; + rte_atomic32_t ready; rte_atomic32_t while_queuing; struct pmd_internal *internal; struct rte_mempool *mb_pool; @@ -383,18 +384,25 @@ vhost_update_packet_xstats(struct vhost_queue *vq, } } +static inline bool +queuing_stopped(struct vhost_queue *r) +{ + return unlikely(rte_atomic32_read(&r->connected) == 0 || + rte_atomic32_read(&r->ready) == 0); +} + static uint16_t eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { struct vhost_queue *r = q; uint16_t i, nb_rx = 0; - if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0)) + if (queuing_stopped(r)) return 0; rte_atomic32_set(&r->while_queuing, 1); - if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0)) + if (queuing_stopped(r)) goto out; /* Dequeue packets from guest TX queue */ @@ -422,12 +430,12 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) struct vhost_queue *r = q; uint16_t i, nb_tx = 0; - if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0)) + if (queuing_stopped(r)) return 0; rte_atomic32_set(&r->while_queuing, 1); - if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0)) + if (queuing_stopped(r)) goto out; /* Enqueue packets to guest RX queue */ @@ -546,13 +554,13 @@ new_device(int vid) vq = eth_dev->data->rx_queues[i]; if (vq == NULL) continue; - rte_atomic32_set(&vq->allow_queuing, 1); + rte_atomic32_set(&vq->connected, 1); } for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { vq = eth_dev->data->tx_queues[i]; if (vq == NULL) continue; - rte_atomic32_set(&vq->allow_queuing, 1); + rte_atomic32_set(&vq->connected, 1); } RTE_LOG(INFO, PMD, "New connection established\n"); @@ -585,7 +593,7 @@ destroy_device(int vid) vq = eth_dev->data->rx_queues[i]; if (vq == NULL) continue; - rte_atomic32_set(&vq->allow_queuing, 0); + rte_atomic32_set(&vq->connected, 0); while (rte_atomic32_read(&vq->while_queuing)) rte_pause(); } @@ -593,7 +601,7 @@ destroy_device(int vid) vq = eth_dev->data->tx_queues[i]; if (vq == NULL) continue; - rte_atomic32_set(&vq->allow_queuing, 0); + rte_atomic32_set(&vq->connected, 0); while (rte_atomic32_read(&vq->while_queuing)) rte_pause(); } @@ -770,14 +778,49 @@ vhost_driver_session_stop(void) } static int -eth_dev_start(struct rte_eth_dev *dev __rte_unused) +eth_dev_start(struct rte_eth_dev *dev) { + struct vhost_queue *vq; + unsigned i; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + vq = dev->data->rx_queues[i]; + if (vq == NULL) + continue; + rte_atomic32_set(&vq->ready, 1); + } + for (i = 0; i < dev->data->nb_tx_queues; i++) { + vq = dev->data->tx_queues[i]; + if (vq == NULL) + continue; + rte_atomic32_set(&vq->ready, 1); + } + return 0; } static void -eth_dev_stop(struct rte_eth_dev *dev __rte_unused) +eth_dev_stop(struct rte_eth_dev *dev) { + struct vhost_queue *vq; + unsigned i; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + vq = dev->data->rx_queues[i]; + if (vq == NULL) + continue; + rte_atomic32_set(&vq->ready, 0); + while (rte_atomic32_read(&vq->while_queuing)) + rte_pause(); + } + for (i = 0; i < dev->data->nb_tx_queues; i++) { + vq = dev->data->tx_queues[i]; + if (vq == NULL) + continue; + rte_atomic32_set(&vq->ready, 0); + while (rte_atomic32_read(&vq->while_queuing)) + rte_pause(); + } } static int