From patchwork Tue Sep 15 07:10:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanhan Liu X-Patchwork-Id: 517693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 62BFF1401AD for ; Tue, 15 Sep 2015 17:11:09 +1000 (AEST) Received: from localhost ([::1]:45519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbkOQ-000307-Gp for incoming@patchwork.ozlabs.org; Tue, 15 Sep 2015 03:11:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbkNZ-0001q0-Eb for qemu-devel@nongnu.org; Tue, 15 Sep 2015 03:10:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbkNX-0001PT-A8 for qemu-devel@nongnu.org; Tue, 15 Sep 2015 03:10:13 -0400 Received: from mga01.intel.com ([192.55.52.88]:55441) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbkNX-0001LT-4j for qemu-devel@nongnu.org; Tue, 15 Sep 2015 03:10:11 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 15 Sep 2015 00:09:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,533,1437462000"; d="scan'208";a="789617739" Received: from yliu-dev.sh.intel.com ([10.239.66.60]) by fmsmga001.fm.intel.com with ESMTP; 15 Sep 2015 00:09:51 -0700 From: Yuanhan Liu To: qemu-devel@nongnu.org Date: Tue, 15 Sep 2015 15:10:32 +0800 Message-Id: <1442301035-7550-6-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1442301035-7550-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1442301035-7550-1-git-send-email-yuanhan.liu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Cc: jasowang@redhat.com, changchun.ouyang@intel.com, Yuanhan Liu , mst@redhat.com Subject: [Qemu-devel] [PATCH 4/7] vhost-user: add VHOST_USER_GET_QUEUE_NUM message X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is for querying how many queues the backend supports if it has mq support(when VHOST_USER_PROTOCOL_F_MQ flag is set from the quried protocol features). vhost_net_get_max_queues() is the interface to export that value, and to tell if the backend supports # of queues user requested, which is done in the following patch. Signed-off-by: Yuanhan Liu --- docs/specs/vhost-user.txt | 11 +++++++++++ hw/net/vhost_net.c | 7 +++++++ hw/virtio/vhost-user.c | 15 ++++++++++++++- include/hw/virtio/vhost.h | 1 + include/net/vhost_net.h | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index ccbbcbb..43db9b4 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -301,3 +301,14 @@ Message types Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. + + * VHOST_USER_GET_QUEUE_NUM + + Id: 17 + Equivalent ioctl: N/A + Master payload: N/A + Slave payload: u64 + + Query how many queues the backend supports. This request should be + sent only when VHOST_USER_PROTOCOL_F_MQ is set in quried protocol + features by VHOST_USER_GET_PROTOCOL_FEATURES. diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 33b0e97..f9441e9 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -122,6 +122,11 @@ void vhost_net_ack_features(struct vhost_net *net, uint64_t features) vhost_ack_features(&net->dev, vhost_net_get_feature_bits(net), features); } +uint64_t vhost_net_get_max_queues(VHostNetState *net) +{ + return net->dev.max_queues; +} + static int vhost_net_get_fd(NetClientState *backend) { switch (backend->info->type) { @@ -144,6 +149,8 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) goto fail; } + net->dev.max_queues = 1; + if (backend_kernel) { r = vhost_net_get_fd(options->net_backend); if (r < 0) { diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 0ac8252..8b4b36b 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -25,7 +25,9 @@ #define VHOST_MEMORY_MAX_NREGIONS 8 #define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x0ULL +#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x1ULL + +#define VHOST_USER_PROTOCOL_F_MQ 0 typedef enum VhostUserRequest { VHOST_USER_NONE = 0, @@ -45,6 +47,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_VRING_ERR = 14, VHOST_USER_GET_PROTOCOL_FEATURES = 15, VHOST_USER_SET_PROTOCOL_FEATURES = 16, + VHOST_USER_GET_QUEUE_NUM = 17, VHOST_USER_MAX } VhostUserRequest; @@ -211,6 +214,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, switch (msg_request) { case VHOST_USER_GET_FEATURES: case VHOST_USER_GET_PROTOCOL_FEATURES: + case VHOST_USER_GET_QUEUE_NUM: need_reply = 1; break; @@ -315,6 +319,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, switch (msg_request) { case VHOST_USER_GET_FEATURES: case VHOST_USER_GET_PROTOCOL_FEATURES: + case VHOST_USER_GET_QUEUE_NUM: if (msg.size != sizeof(m.u64)) { error_report("Received bad msg size."); return -1; @@ -366,6 +371,14 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque) if (err < 0) { return err; } + + /* query the max queues we support if backend supports Multiple Queue */ + if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { + err = vhost_user_call(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); + if (err < 0) { + return err; + } + } } return 0; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 6467c73..c3758f3 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -48,6 +48,7 @@ struct vhost_dev { unsigned long long acked_features; unsigned long long backend_features; unsigned long long protocol_features; + unsigned long long max_queues; bool started; bool log_enabled; unsigned long long log_size; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 840d4b1..8db723e 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -13,6 +13,7 @@ typedef struct VhostNetOptions { void *opaque; } VhostNetOptions; +uint64_t vhost_net_get_max_queues(VHostNetState *net); struct vhost_net *vhost_net_init(VhostNetOptions *options); int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);