On Wed, 2017-01-04 at 15:31 +0000, Ciara Loftus wrote:
> 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/attach and netdev-dpdk/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.

There are a couple of issues with the documentation part of this that
would be good to fix if/when you respin. I'll leave the rest of the
changes to someone better qualified to review them.

Stephen

> Signed-off-by: Mauricio Vasquez B
> <mauricio.vasquezber...@studenti.polito.it>
> Signed-off-by: Ciara Loftus <ciara.lof...@intel.com>
> Co-authored-by: Ciara Loftus <ciara.lof...@intel.com>
> ---
> Changelog:
> * Use xasprintf instead of snprintf when reporting attach/detach
> errors.
> * Updated format of link in docs to comply with new format.
> * Remove 'port-' from appctl netdev-dpdk/(port-)attach and detach
> commands
> * Free 'response' in attach and detach functions in netdev_dpdk
> * Add my Sign-off and Co-author tags
> * Fix docs - use port name for detach not PCI
> * Rewording of docs
> 
>  Documentation/howto/dpdk.rst | 27 +++++++++++++
>  NEWS                         |  1 +
>  lib/netdev-dpdk.c            | 95
> +++++++++++++++++++++++++++++++++++++++++---
>  3 files changed, 117 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/howto/dpdk.rst
> b/Documentation/howto/dpdk.rst
> index db92a8e..900f9b7 100644
> --- a/Documentation/howto/dpdk.rst
> +++ b/Documentation/howto/dpdk.rst
> @@ -298,6 +298,33 @@ physical ports which in turn effects the non-
> tunnel traffic performance.
>  So it is advised to turn off the Rx checksum offload for non-tunnel
> traffic use
>  cases to achieve the best performance.
>  
> +.. _port-hotplug:
> +
> +Port Hotplug
> +------------
> +
> +OvS supports port hotplugging, it allows to use ports that were not
> bound

femtonit: "OVS" or "Open vSwitch"

> +to DPDK when vswitchd was started.

How about:

  ...hotplugging, allowing the use of ports..

> +In order to attach a port, it has to be bound to DPDK using the
> +dpdk_nic_bind.py script:

Could you format the script name as code?

    ``dpdk_nic_bind.py``

> +
> +       $ $DPDK_DIR/tools/dpdk_nic_bind.py --bind=igb_uio
> 0000:01:00.0

You need to precede code with '::' or 'code-block' for this to format
properly. Also, you only need to indent the code blocks by four
characters. For example:

    .. code-block:: console

       $ cd $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/attach 0000:01:00.0

Likewise.

> +At this point, the user can create a ovs port using the add-port
> command.

Create a `dpdk` port? Or do you mean any type of port (in which case
maybe just say "...create a port")

Also, format add-port as ``code``

> +
> +It is also possible to detach a port from ovs, the user has to
> remove the
> +
> +
> +       $ ovs-appctl netdev-dpdk/detach dpdk0

See above.

> +This feature is not supported with VFIO and does not work with some
> NICs.
> +For more information please refer to the `DPDK Port Hotplug
> Framework
> +<http://dpdk.org/doc/guides/prog_guide/port_hotplug_framework.html#h
> otplug>`__.
> +
>  .. _dpdk-ovs-in-guest:
>  
>  OVS with DPDK Inside VMs
> diff --git a/NEWS b/NEWS
> index daa9ff5..8f8c2f7 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -47,6 +47,7 @@ Post-v2.6.0
>         which set the number of rx and tx descriptors to use for the
> given port.
>       * Support for DPDK v16.11.
>       * Support for rx checksum offload. Refer DPDK HOWTO for
> details.
> +     * Port Hotplug is now supported.
>     - Fedora packaging:
>       * A package upgrade does not automatically restart OVS service.
>     - ovs-vswitchd/ovs-vsctl:
> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
> index fc478c4..e231078 100644
> --- a/lib/netdev-dpdk.c
> +++ b/lib/netdev-dpdk.c
> @@ -2357,6 +2357,82 @@ netdev_dpdk_set_admin_state(struct
> unixctl_conn *conn, int argc,
>      unixctl_command_reply(conn, "OK");
>  }
>  
> +static void
> +netdev_dpdk_attach(struct unixctl_conn *conn, int argc OVS_UNUSED,
> +                   const char *argv[], void *aux OVS_UNUSED)
> +{
> +    int ret;
> +    char *response;
> +    uint8_t port_id;
> +
> +    ovs_mutex_lock(&dpdk_mutex);
> +
> +    ret = rte_eth_dev_attach(argv[1], &port_id);
> +    if (ret < 0) {
> +        response = xasprintf("Error attaching device '%s'",
> argv[1]);
> +        ovs_mutex_unlock(&dpdk_mutex);
> +        unixctl_command_reply_error(conn, response);
> +        free(response);
> +        return;
> +    }
> +
> +    response = xasprintf("Device '%s' has been attached as
> 'dpdk%d'",
> +                         argv[1], port_id);
> +
> +    ovs_mutex_unlock(&dpdk_mutex);
> +    unixctl_command_reply(conn, response);
> +    free(response);
> +}
> +
> +static void
> +netdev_dpdk_detach(struct unixctl_conn *conn, int argc OVS_UNUSED,
> +                   const char *argv[], void *aux OVS_UNUSED)
> +{
> +    int ret;
> +    char *response;
> +    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) {
> +        response = xasprintf("'%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);
> +        response = xasprintf("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) {
> +        response = xasprintf("Port '%s' can not be detached",
> argv[1]);
> +        goto error;
> +    }
> +
> +    response = xasprintf("Port '%s' has been detached", argv[1]);
> +
> +    ovs_mutex_unlock(&dpdk_mutex);
> +    unixctl_command_reply(conn, response);
> +    free(response);
> +    return;
> +
> +error:
> +    ovs_mutex_unlock(&dpdk_mutex);
> +    unixctl_command_reply_error(conn, response);
> +    free(response);
> +}
> +
>  /*
>   * Set virtqueue flags so that we do not receive interrupts.
>   */
> @@ -2632,6 +2708,12 @@ netdev_dpdk_class_init(void)
>          unixctl_command_register("netdev-dpdk/set-admin-state",
>                                   "[netdev] up|down", 1, 2,
>                                   netdev_dpdk_set_admin_state, NULL);
> +        unixctl_command_register("netdev-dpdk/attach",
> +                                 "pci address of device", 1, 1,
> +                                 netdev_dpdk_attach, NULL);
> +        unixctl_command_register("netdev-dpdk/detach",
> +                                 "port", 1, 1,
> +                                 netdev_dpdk_detach, NULL);
>  
>          ovsthread_once_done(&once);
>      }
> @@ -2668,7 +2750,7 @@ dpdk_ring_create(const char dev_name[],
> unsigned int port_no,
>  {
>      struct dpdk_ring *ivshmem;
>      char *ring_name;
> -    int err;
> +    int port_id;
>  
>      ivshmem = dpdk_rte_mzalloc(sizeof *ivshmem);
>      if (!ivshmem) {
> @@ -2698,19 +2780,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;
>  }
>  

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to