From patchwork Tue Mar 31 07:38:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sivaprasad Tummala X-Patchwork-Id: 67455 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A1BEFA0562; Tue, 31 Mar 2020 09:37:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8DAB02C6D; Tue, 31 Mar 2020 09:37:40 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 25FC7FFA for ; Tue, 31 Mar 2020 09:37:38 +0200 (CEST) IronPort-SDR: LRQOEOHnRo2AS2X3yvSsSrBc3YksVb5ABQrTbj4ziPCclVhAI1drvKLffaLb0+OIRyIvij80Iv 2fkV8/jyuVKg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2020 00:37:37 -0700 IronPort-SDR: OKWaPlm55zxtRqqOVyQyk2e4A3LpdxBcQbOtlBIkLi4eFjwQfw8J2+rTnMMyAQecZE+ulssEV9 2M7vMZONywCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="252150284" Received: from unknown (HELO localhost.localdomain) ([10.190.212.182]) by orsmga006.jf.intel.com with ESMTP; 31 Mar 2020 00:37:35 -0700 From: Sivaprasad Tummala To: dev@dpdk.org Date: Tue, 31 Mar 2020 13:08:11 +0530 Message-Id: <20200331073811.54307-1-Sivaprasad.Tummala@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] examples/vhost: add vhostpmd support 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" Added vHostPMD based configuration of vHost devices. Currently vHost library calls are used for configuring the vhost device. vHostPMD is a pre-requisite for enabling future features supported such as FPGA and possibly CBDMA. With the vHostPMD integration, upstream features in PMD can be easily supported and additional features such as queue stats for vhost devices can be useful. With the patch, user has an option to select vHost PMD by passing "--use-vhost-pmd" option. Disabled by default. Note: vHost multi-queue is not enabled on this patch. Signed-off-by: Sivaprasad Tummala --- V2: - Reverted unregister_device to unregister_drivers - Ye Xiaolong - Updated port_init to log and return error to main - Ye Xiaolong - unregister_drivers for previous created vhost ports for failed vhost port configure - Ye Xialong --- examples/vhost/main.c | 153 ++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 66 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index b3e331045..0c3d93bbd 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -228,38 +228,44 @@ get_eth_conf(struct rte_eth_conf *eth_conf, uint32_t num_devices) * for the device to be re-used */ static void -unregister_device(int socket_num) +unregister_drivers(int socket_num) { - int ret; + int i, ret; - if (vhost_pmd) { - char drv_name[RTE_ETH_NAME_MAX_LEN]; - struct vhost_dev *vdev = NULL; - uint16_t port_id; - - snprintf(drv_name, RTE_ETH_NAME_MAX_LEN, - "net_vhost%d", socket_num); - ret = rte_eth_dev_get_port_by_name(drv_name, &port_id); - if (ret != 0) - rte_exit(EXIT_FAILURE, - "vhost device port id get failed.\n"); + for (i = 0; i < socket_num; i++) { + if (vhost_pmd) { + char drv_name[RTE_ETH_NAME_MAX_LEN]; + struct vhost_dev *vdev = NULL; + uint16_t port_id; - TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { - if (vdev->eth_dev_id == port_id) { - vdev->remove = 1; - break; + snprintf(drv_name, RTE_ETH_NAME_MAX_LEN, + "net_vhost%d", socket_num); + ret = rte_eth_dev_get_port_by_name(drv_name, &port_id); + if (ret != 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "Fail to get vhost port id for %s\n", + drv_name); + continue; } - } - /* Close the Ethernet device */ - rte_eth_dev_close(port_id); - } else { - ret = rte_vhost_driver_unregister(socket_files + - socket_num * PATH_MAX); - if (ret != 0) - RTE_LOG(ERR, VHOST_CONFIG, - "Fail to unregister vhost driver for %s.\n", - socket_files + socket_num * PATH_MAX); + TAILQ_FOREACH(vdev, &vhost_dev_list, + global_vdev_entry) { + if (vdev->eth_dev_id == port_id) { + vdev->remove = 1; + break; + } + } + + /* unregister the device */ + rte_eth_dev_close(port_id); + } else { + ret = rte_vhost_driver_unregister( + socket_files + i * PATH_MAX); + if (ret != 0) + RTE_LOG(ERR, VHOST_CONFIG, + "Fail to unregister vhost driver for %s.\n", + socket_files + i * PATH_MAX); + } } } @@ -268,7 +274,7 @@ unregister_device(int socket_num) * coming from the mbuf_pool passed as parameter */ static inline int -port_init_v2(uint16_t portid) +vhost_pmd_port_init(uint16_t portid) { struct rte_eth_rxconf rxq_conf; struct rte_eth_txconf txq_conf; @@ -289,10 +295,12 @@ port_init_v2(uint16_t portid) fflush(stdout); ret = rte_eth_dev_info_get(portid, &dev_info); - if (ret != 0) - rte_exit(EXIT_FAILURE, + if (ret != 0) { + RTE_LOG(ERR, VHOST_CONFIG, "Error during getting device (port %u) info: %s\n", portid, strerror(-ret)); + return ret; + } if (strncmp(dev_info.driver_name, "net_vhost", sizeof("net_vhost")) == 0) @@ -301,26 +309,33 @@ port_init_v2(uint16_t portid) vhost_device_event_callback, NULL); ret = rte_eth_dev_configure(portid, 1, 1, &port_conf); - if (ret < 0) - rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n", - ret, portid); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "Cannot configure device: err=%d, port=%u\n", + ret, portid); + return ret; + } nb_rxd = RTE_TEST_RX_DESC_DEFAULT; nb_txd = RTE_TEST_TX_DESC_DEFAULT; ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd); - if (ret < 0) - rte_exit(EXIT_FAILURE, - "Cannot adjust number of descriptors: err=%d, port=%u\n", - ret, portid); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "Cannot adjust number of descriptors: err=%d, port=%u\n", + ret, portid); + return ret; + } ret = rte_eth_macaddr_get(portid, &vmdq_ports_eth_addr[portid]); - if (ret < 0) - rte_exit(EXIT_FAILURE, - "Cannot get MAC address: err=%d, port=%u\n", - ret, portid); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "Cannot get MAC address: err=%d, port=%u\n", + ret, portid); + return ret; + } /* init RX queue */ fflush(stdout); @@ -330,9 +345,12 @@ port_init_v2(uint16_t portid) rte_eth_dev_socket_id(portid), &rxq_conf, mbuf_pool); - if (ret < 0) - rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n", - ret, portid); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "rte_eth_rx_queue_setup: err=%d, port=%u\n", + ret, portid); + return ret; + } /* init TX queue */ fflush(stdout); @@ -341,27 +359,29 @@ port_init_v2(uint16_t portid) ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, rte_eth_dev_socket_id(portid), &txq_conf); - if (ret < 0) - rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n", + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "rte_eth_rx_queue_setup: err=%d, port=%u\n", ret, portid); + return ret; + } /* Start device */ ret = rte_eth_dev_start(portid); - if (ret < 0) - rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n", - ret, portid); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "rte_eth_dev_start: err=%d, port=%u\n", + ret, portid); + return ret; + } if (promiscuous) { ret = rte_eth_promiscuous_enable(portid); if ((ret != 0) && (ret != -ENOTSUP)) { - uint8_t i; - - for (i = 0; i < nb_sockets; i++) - unregister_device(i); - - rte_exit(EXIT_FAILURE, - "rte_eth_promiscuous_enable:err=%s, port=%u\n", - rte_strerror(-ret), portid); + RTE_LOG(ERR, VHOST_CONFIG, + "rte_eth_promiscuous_enable: err=%d, port=%u\n", + ret, portid); + return ret; } } @@ -1207,6 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) return; if (vhost_pmd) { + uint32_t idx; + enqueue_count = rte_eth_tx_burst(vdev->eth_dev_id, 0, pkts, rx_count); if (unlikely(enqueue_count < rx_count)) { @@ -1222,7 +1244,6 @@ drain_eth_rx(struct vhost_dev *vdev) break; } /* Drop the remaining packets */ - uint32_t idx; for (idx = enqueue_count; idx < rx_count; idx++) rte_pktmbuf_free(pkts[idx]); } @@ -1620,10 +1641,7 @@ static void sigint_handler(__rte_unused int signum) { /* Unregister vhost driver. */ - uint8_t i; - - for (i = 0; i < nb_sockets; i++) - unregister_device(i); + unregister_drivers(nb_sockets); exit(0); } @@ -1806,25 +1824,26 @@ main(int argc, char *argv[]) ret = rte_dev_probe(dev_name); if (ret != 0) { + unregister_drivers(i); rte_exit(EXIT_FAILURE, "vhost user device probe failed\n"); } ret = rte_eth_dev_get_port_by_name(drv_name, &port); if (ret != 0) { - unregister_device(i); + unregister_drivers(i+1); rte_exit(EXIT_FAILURE, "vhost device port id get failed.\n"); } - ret = port_init_v2(port); + ret = vhost_pmd_port_init(port); if (ret != 0) { - unregister_device(i); + unregister_drivers(i+1); rte_exit(EXIT_FAILURE, "vhost device port initialization failed.\n"); } } else { ret = rte_vhost_driver_register(file, flags); if (ret != 0) { - unregister_device(i); + unregister_drivers(i); rte_exit(EXIT_FAILURE, "vhost driver register failure.\n"); } @@ -1862,11 +1881,13 @@ main(int argc, char *argv[]) ret = rte_vhost_driver_callback_register(file, &virtio_net_device_ops); if (ret != 0) { + unregister_drivers(i+1); rte_exit(EXIT_FAILURE, "failed to register vhost driver callbacks.\n"); } if (rte_vhost_driver_start(file) < 0) { + unregister_drivers(i+1); rte_exit(EXIT_FAILURE, "failed to start vhost driver.\n"); }