From patchwork Mon Nov 6 14:20:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 834767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVvqt1rWSz9s7B for ; Tue, 7 Nov 2017 01:21:12 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 37097AD6; Mon, 6 Nov 2017 14:20:55 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9AAEAAD2 for ; Mon, 6 Nov 2017 14:20:53 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3469879 for ; Mon, 6 Nov 2017 14:20:53 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id 78so4122687qkz.0 for ; Mon, 06 Nov 2017 06:20:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Wy7soOzqm5ZM1Dy4o4rr19zQMGE1VfLok1SPJZmnnW4=; b=svOkjPmIQnEtMYevL5+Oc03is+Bf5fBuHIjdJQU0ZPwIujxoRoC5HtabhRr3CeVfTN HJ3DZxtLJ2fNglFG3aeoyyEeiKGWZkKPljRa0oJw3orNDh4zvr3hr4EpOPSVx6r41JLk Ld7LHF78cFbqq7xmTXUElQoNj9uSD7aFXWdN0esN4Xsecl5WSyNFVgkXd7zBma6ABZwZ DHyXUABSruJWRchKECFE6xhBNXlCxZvmQ/QXYFgMnJCu8+JGYpYu5HnmY9hI/mvbV7K6 +YauyYTfBVFUGKIdibrfmxgCvcksg68nLnA5EApRKnIVtVoGZWLflRgnUuDdv1PsQhwd 39lQ== X-Gm-Message-State: AJaThX4f3rjuuy/b1NCIcdLlTCPsoPtyVWhHLcUSFVDyJPjLAXyKrzWi ZU2OgjdNnIjX2mJBRDlOGUF8uBCUGhQ= X-Google-Smtp-Source: ABhQp+QwmBSCDWCQio9HRwkyfZPcdfVXNT/zjvCatySS/9f7WKd+lc2ZEKsXeYTdNjsvuIoedGBpSw== X-Received: by 10.55.21.197 with SMTP id 66mr8880779qkv.194.1509978052107; Mon, 06 Nov 2017 06:20:52 -0800 (PST) Received: from localhost ([189.114.243.96]) by smtp.gmail.com with ESMTPSA id b45sm8759020qta.89.2017.11.06.06.20.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2017 06:20:51 -0800 (PST) From: Flavio Leitner To: dev@openvswitch.org Date: Mon, 6 Nov 2017 12:20:41 -0200 Message-Id: <20171106142041.10350-1-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner Subject: [ovs-dev] [PATCH] netdev-dpdk: add a command to dump vhost-user info. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Add a command to dump vhost-user's information. Signed-off-by: Flavio Leitner --- lib/netdev-dpdk.c | 124 ++++++++++++++++++++++++++++++++++++++++++++- vswitchd/ovs-vswitchd.8.in | 4 ++ 2 files changed, 126 insertions(+), 2 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 1e9d78f58..b60a26d1f 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -974,20 +974,140 @@ dpdk_dev_parse_name(const char dev_name[], const char prefix[], } } +static void +netdev_dpdk_vhost_show__(struct ds *ds, struct netdev *netdev) +{ + struct netdev_dpdk *dpdk_dev = netdev_dpdk_cast(netdev); + bool client_mode = dpdk_dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT; + struct rte_vhost_vring vring; + char socket_name[PATH_MAX]; + uint64_t features; + uint16_t mtu; + int16_t vring_num; + int numa; + int vid; + int i; + + vid = netdev_dpdk_get_vid(dpdk_dev); + ds_put_format(ds, "vhost-user port: %s\n", netdev->name); + ds_put_format(ds, "\tMode: %s\n", client_mode ? "client" : "server"); + if (!rte_vhost_get_ifname(vid, socket_name, PATH_MAX)) { + ds_put_format(ds, "\tSocket: %s\n", socket_name); + } + + if (vid == -1) { + ds_put_cstr(ds, "\tStatus: Disconnected\n"); + return; + } else { + ds_put_cstr(ds, "\tStatus: Connected\n"); + } + + if (!rte_vhost_get_negotiated_features(vid, &features)) { + ds_put_format(ds, "\tNegotiated features: 0x%lx\n", features); + } + + if (!rte_vhost_get_mtu(vid, &mtu)) { + ds_put_format(ds, "\tMTU: %d\n", mtu); + } + + numa = rte_vhost_get_numa_node(vid); + if (numa != -1) { + ds_put_format(ds, "\tNUMA: %d\n", numa); + } + + vring_num = rte_vhost_get_vring_num(vid); + if (vring_num) { + ds_put_format(ds, "\tNumber of vrings: %d\n", vring_num); + } + + for (i = 0; i < vring_num; i++) { + rte_vhost_get_vhost_vring(vid, i, &vring); + ds_put_format(ds, "\tVring %d:\n", i); + ds_put_format(ds, "\t\tDescriptor length: %d\n", + vring.desc->len); + ds_put_format(ds, "\t\tRing size: %d\n", vring.size); + } +} + + +static void +netdev_dpdk_vhost_show(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + struct ds ds = DS_EMPTY_INITIALIZER; + struct netdev_dpdk *dpdk_dev; + + if (argc > 1) { + struct netdev *netdev = netdev_from_name(argv[1]); + if (!netdev) { + unixctl_command_reply_error(conn, "No such port"); + return; + } + + if (!is_dpdk_class(netdev->netdev_class)) { + netdev_close(netdev); + unixctl_command_reply_error(conn, "Not a vhost-user port"); + return; + } + + dpdk_dev = netdev_dpdk_cast(netdev); + ovs_mutex_lock(&dpdk_dev->mutex); + if (dpdk_dev->type != DPDK_DEV_VHOST) { + ovs_mutex_unlock(&dpdk_dev->mutex); + netdev_close(netdev); + unixctl_command_reply_error(conn, "Not a vhost-user port"); + return; + } + + netdev_dpdk_vhost_show__(&ds, netdev); + ovs_mutex_unlock(&dpdk_dev->mutex); + netdev_close(netdev); + } else { + ovs_mutex_lock(&dpdk_mutex); + LIST_FOR_EACH (dpdk_dev, list_node, &dpdk_list) { + ovs_mutex_lock(&dpdk_dev->mutex); + if (dpdk_dev->type != DPDK_DEV_VHOST) { + ovs_mutex_unlock(&dpdk_dev->mutex); + continue; + } + + netdev_dpdk_vhost_show__(&ds, dpdk_dev); + ovs_mutex_unlock(&dpdk_dev->mutex); + } + ovs_mutex_unlock(&dpdk_mutex); + } + + unixctl_command_reply(conn, ds_cstr(&ds)); + ds_destroy(&ds); +} + static int vhost_common_construct(struct netdev *netdev) OVS_REQUIRES(dpdk_mutex) { + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; int socket_id = rte_lcore_to_socket_id(rte_get_master_lcore()); struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); + int error; dev->tx_q = netdev_dpdk_alloc_txq(OVS_VHOST_MAX_QUEUE_NUM); if (!dev->tx_q) { return ENOMEM; } - return common_construct(netdev, DPDK_ETH_PORT_ID_INVALID, - DPDK_DEV_VHOST, socket_id); + error = common_construct(netdev, DPDK_ETH_PORT_ID_INVALID, + DPDK_DEV_VHOST, socket_id); + if (error) { + return error; + } + + if (ovsthread_once_start(&once)) { + unixctl_command_register("vhostuser/show", "[port]", 0, 1, + netdev_dpdk_vhost_show, NULL); + ovsthread_once_done(&once); + } + + return 0; } static int diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in index c18baf6db..607f6b046 100644 --- a/vswitchd/ovs-vswitchd.8.in +++ b/vswitchd/ovs-vswitchd.8.in @@ -156,6 +156,10 @@ event on all bridges. Displays detailed information about rapid spanning tree on the \fIbridge\fR. If \fIbridge\fR is not specified, then displays detailed information about all bridges with RSTP enabled. +.IP "\fBvhostuser/show\fR [\fIport\fR]" +Displays detailed internal information about a specific vhost-user \fIport\fR. +If \fIport\fR is not specified, then displays detailed information about all +vhost-user ports. .SS "BRIDGE COMMANDS" These commands manage bridges. .IP "\fBfdb/flush\fR [\fIbridge\fR]"