From patchwork Fri Jul 15 14:15:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Mauricio_V=C3=A1squez?= X-Patchwork-Id: 648834 X-Patchwork-Delegate: diproiettod@vmware.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rrZNn1bByz9s8d for ; Sat, 16 Jul 2016 00:15:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=studenti.polito.it header.i=@studenti.polito.it header.b=jegRx678; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 27A1710D75; Fri, 15 Jul 2016 07:15:51 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id E097610D5B for ; Fri, 15 Jul 2016 07:15:49 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 0ECFE1631B9 for ; Fri, 15 Jul 2016 08:15:49 -0600 (MDT) X-ASG-Debug-ID: 1468592145-0b32373da308ca0001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar6.cudamail.com with ESMTP id 1q6MpekajBh7wc9M (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 15 Jul 2016 08:15:45 -0600 (MDT) X-Barracuda-Envelope-From: mauricio.vasquezbernal@studenti.polito.it X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO compass.polito.it) (130.192.55.110) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 15 Jul 2016 14:15:44 -0000 Received-SPF: pass (mx3-pf2.cudamail.com: SPF record at studenti.polito.it designates 130.192.55.110 as permitted sender) X-Barracuda-Apparent-Source-IP: 130.192.55.110 X-Barracuda-RBL-IP: 130.192.55.110 Received: from localhost (localhost [127.0.0.1]) by compass.polito.it (Postfix) with ESMTP id 4EA89100205; Fri, 15 Jul 2016 16:15:41 +0200 (CEST) Authentication-Results: compass.polito.it (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=studenti.polito.it DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= studenti.polito.it; h=x-mailer:message-id:date:date:subject :subject:cc:to:from:from:received:received; s=y2k10; t= 1468592138; bh=EACXWyngF4tWK6vKFidkpgIPH4s5zevqMopuz7H/Gls=; b=j egRx678N3OrVQ8pghwp/FwdgAN8rG5tLQ3GyDZDd675MhiYMDnyMOBYTfbSVpVrV nQcMuE8h7tix8K9CZiNDznh/vBU0Ukq3kM5Y+Pl9kJMKXApDdpRVgXyTZ6OEgcOt p9dULztQ/BpPmAdudNrHDcIMaH0Qc+SB8St7uRJRI0= X-Virus-Scanned: amavisd-new at studenti.polito.it X-Spam-Flag: NO X-Spam-Score: -5.755 X-Spam-Level: X-Spam-Status: No, score=-5.755 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-5, AWL=0.745, BAYES_00=-1.5] autolearn=ham Received: from compass.polito.it ([127.0.0.1]) by localhost (compass.polito.it [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id C0G0jYgAqjJr; Fri, 15 Jul 2016 16:15:38 +0200 (CEST) Received: from mvb-X455LJ.ipv6.polito.it (unknown [130.192.225.241]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: s203403@studenti.polito.it) by compass.polito.it (Postfix) with ESMTPSA id 7ADD010021C; Fri, 15 Jul 2016 16:15:37 +0200 (CEST) X-CudaMail-Envelope-Sender: mauricio.vasquezbernal@studenti.polito.it From: Mauricio Vasquez B To: dev@openvswitch.org X-CudaMail-MID: CM-V2-714014187 X-CudaMail-DTE: 071516 X-CudaMail-Originating-IP: 130.192.55.110 Date: Fri, 15 Jul 2016 16:15:31 +0200 X-ASG-Orig-Subj: [##CM-V2-714014187##][PATCH v7] netdev-dpdk: add hotplug support Message-Id: <1468592131-8790-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> X-Mailer: git-send-email 1.9.1 X-GBUdb-Analysis: 0, 130.192.55.110, Ugly c=0 p=0 Source New X-MessageSniffer-Rules: 0-0-0-14557-c X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1468592145 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 1.85 X-Barracuda-Spam-Status: No, SCORE=1.85 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_RULE_7580B, BSF_RULE_7582B, BSF_SC5_MJ1963, DKIM_SIGNED, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.31283 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.50 BSF_RULE_7582B Custom Rule 7582B 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.75 BSF_RULE_7580B Custom Rule 7580B 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: fbl@sysclose.org, kevin.traynor@intel.com Subject: [ovs-dev] [PATCH v7] netdev-dpdk: add hotplug support X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" In order to use dpdk ports in ovs they have to be bound to a DPDK compatible driver before ovs is started. This patch adds the possibility to hotplug (or hot-unplug) a device after ovs has been started. The implementation adds two appctl commands: netdev-dpdk/port-attach and netdev-dpdk/port-detach After the user attaches a new device, it has to be added to a bridge using the add-port command, similarly, before detaching a device, it has to be removed using the del-port command. Signed-off-by: Mauricio Vasquez B --- v7: - rebase to master v6: - add explicit comment about supporting VFIO - rebase to master v5: - use two appctl commands instead of a single one - rebase to master v4: - fix typo in commit message - remove unnecessary whitespace change in INSTALL.DPDK.md v3: - create dpdk_port_attach and dpdk_port_detach functions - modify mutex locking order v2: - use rte_eth_dev_is_valid_port() to check if a port is valid INSTALL.DPDK-ADVANCED.md | 25 ++++++++++++ NEWS | 1 + lib/netdev-dpdk.c | 101 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 120 insertions(+), 7 deletions(-) diff --git a/INSTALL.DPDK-ADVANCED.md b/INSTALL.DPDK-ADVANCED.md index 9ae536d..61b4e82 100644 --- a/INSTALL.DPDK-ADVANCED.md +++ b/INSTALL.DPDK-ADVANCED.md @@ -12,6 +12,7 @@ OVS DPDK ADVANCED INSTALL GUIDE 7. [QOS](#qos) 8. [Rate Limiting](#rl) 9. [Vsperf](#vsperf) +10. [Port Hotplug](#hotplug) ## 1. Overview @@ -835,6 +836,29 @@ environment. More information can be found in below link. https://wiki.opnfv.org/display/vsperf/VSperf+Home +## 10. Port Hotplug + +OvS supports port hotplugging, it allows to use ports that were not bound +to DPDK when vswitchd was started. +In order to attach a port, it has to be bound to DPDK using the +dpdk_nic_bind.py script: + +`$DPDK_DIR/tools/dpdk_nic_bind.py --bind=igb_uio 0000:01:00.0` + +Then it can be attached to OVS: + +`ovs-appctl netdev-dpdk/port-attach 0000:01:00.0` + +At this point, the user can create a ovs port using the add-port command. + +It is also possible to detach a port from ovs, the user has to remove the +port using the del-port command, then it can be detached using: + +`ovs-appctl netdev-dpdk/port-detach dpdk0` + +This feature is not supported with VFIO and could not work with some NICs, +please refer to the [DPDK Port Hotplug Framework] in order to get more +information. Bug Reporting: -------------- @@ -850,3 +874,4 @@ Please report problems to bugs@openvswitch.org. [Guest VM using libvirt]: INSTALL.DPDK.md#ovstc [INSTALL DPDK]: INSTALL.DPDK.md#build [INSTALL OVS]: INSTALL.DPDK.md#build +[DPDK Port Hotplug Framework]: http://dpdk.org/doc/guides/prog_guide/port_hotplug_framework.html diff --git a/NEWS b/NEWS index 6496dc1..9064225 100644 --- a/NEWS +++ b/NEWS @@ -58,6 +58,7 @@ Post-v2.5.0 * PMD threads servicing vHost User ports can now come from the NUMA node that device memory is located on if CONFIG_RTE_LIBRTE_VHOST_NUMA is enabled in DPDK. + * Port Hotplug is now supported. - Increase number of registers to 16. - ovs-benchmark: This utility has been removed due to lack of use and bitrot. diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 85b18fd..3fab52c 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -644,7 +644,7 @@ dpdk_eth_dev_init(struct netdev_dpdk *dev) OVS_REQUIRES(dpdk_mutex) int diag; int n_rxq, n_txq; - if (dev->port_id < 0 || dev->port_id >= rte_eth_dev_count()) { + if (!rte_eth_dev_is_valid_port(dev->port_id)) { return ENODEV; } @@ -2172,6 +2172,83 @@ netdev_dpdk_set_admin_state(struct unixctl_conn *conn, int argc, unixctl_command_reply(conn, "OK"); } +static void +netdev_dpdk_port_attach(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + int ret; + char response[128]; + uint8_t port_id; + + ovs_mutex_lock(&dpdk_mutex); + + ret = rte_eth_dev_attach(argv[1], &port_id); + if (ret < 0) { + snprintf(response, sizeof(response), + "Error attaching device '%s'", argv[1]); + ovs_mutex_unlock(&dpdk_mutex); + unixctl_command_reply_error(conn, response); + return; + } + + snprintf(response, sizeof(response), + "Device '%s' has been attached as 'dpdk%d'", argv[1], port_id); + + ovs_mutex_unlock(&dpdk_mutex); + unixctl_command_reply(conn, response); +} + +static void +netdev_dpdk_port_detach(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + int ret; + char response[128]; + unsigned int parsed_port; + uint8_t port_id; + char devname[RTE_ETH_NAME_MAX_LEN]; + + ovs_mutex_lock(&dpdk_mutex); + + ret = dpdk_dev_parse_name(argv[1], "dpdk", &parsed_port); + if (ret) { + snprintf(response, sizeof(response), + "'%s' is not a valid port", argv[1]); + goto error; + } + + port_id = parsed_port; + + struct netdev *netdev = netdev_from_name(argv[1]); + if (netdev) { + netdev_close(netdev); + snprintf(response, sizeof(response), + "Port '%s' is being used. Remove it before detaching", + argv[1]); + goto error; + } + + rte_eth_dev_close(port_id); + + ret = rte_eth_dev_detach(port_id, devname); + if (ret < 0) { + snprintf(response, sizeof(response), + "Port '%s' can not be detached", argv[1]); + goto error; + } + + snprintf(response, sizeof(response), + "Port '%s' has been detached", argv[1]); + + ovs_mutex_unlock(&dpdk_mutex); + unixctl_command_reply(conn, response); + return; + +error: + ovs_mutex_unlock(&dpdk_mutex); + unixctl_command_reply_error(conn, response); +} + /* * Set virtqueue flags so that we do not receive interrupts. */ @@ -2457,6 +2534,15 @@ dpdk_common_init(void) "[netdev] up|down", 1, 2, netdev_dpdk_set_admin_state, NULL); + unixctl_command_register("netdev-dpdk/port-attach", + "pci address of device", 1, 1, + netdev_dpdk_port_attach, NULL); + + unixctl_command_register("netdev-dpdk/port-detach", + "port", 1, 1, + netdev_dpdk_port_detach, NULL); + + ovs_thread_create("dpdk_watchdog", dpdk_watchdog, NULL); } /* Client Rings */ @@ -2467,7 +2553,7 @@ dpdk_ring_create(const char dev_name[], unsigned int port_no, { struct dpdk_ring *ivshmem; char ring_name[RTE_RING_NAMESIZE]; - int err; + int err, port_id; ivshmem = dpdk_rte_mzalloc(sizeof *ivshmem); if (ivshmem == NULL) { @@ -2501,19 +2587,20 @@ dpdk_ring_create(const char dev_name[], unsigned int port_no, return ENOMEM; } - err = rte_eth_from_rings(dev_name, &ivshmem->cring_rx, 1, - &ivshmem->cring_tx, 1, SOCKET0); + port_id = rte_eth_from_rings(dev_name, &ivshmem->cring_rx, 1, + &ivshmem->cring_tx, 1, SOCKET0); - if (err < 0) { + if (port_id < 0) { rte_free(ivshmem); return ENODEV; } ivshmem->user_port_id = port_no; - ivshmem->eth_port_id = rte_eth_dev_count() - 1; + ivshmem->eth_port_id = port_id; + *eth_port_id = port_id; + ovs_list_push_back(&dpdk_ring_list, &ivshmem->list_node); - *eth_port_id = ivshmem->eth_port_id; return 0; }