From patchwork Mon Oct 9 10:55:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianfeng Tan X-Patchwork-Id: 29933 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9E5B61B1F6; Mon, 9 Oct 2017 12:53:53 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 7186E1B1F1 for ; Mon, 9 Oct 2017 12:53:50 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Oct 2017 03:53:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,500,1500966000"; d="scan'208";a="321115994" Received: from dpdk06.sh.intel.com ([10.67.110.196]) by fmsmga004.fm.intel.com with ESMTP; 09 Oct 2017 03:53:48 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: jblunck@infradead.org, bruce.richardson@intel.com, konstantin.ananyev@intel.com, pablo.de.lara.guarch@intel.com, thomas@monjalon.net, yliu@fridaylinux.org, maxime.coquelin@redhat.com, mtetsuyah@gmail.com, ferruh.yigit@intel.com, Jianfeng Tan Date: Mon, 9 Oct 2017 10:55:05 +0000 Message-Id: <1507546506-25227-5-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507546506-25227-1-git-send-email-jianfeng.tan@intel.com> References: <1507519229-80692-1-git-send-email-jianfeng.tan@intel.com> <1507546506-25227-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v4 4/5] vhost: support to kick in secondary process 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" To support kick in secondary process, we propose callfd_pri and kickfd_pri to store the value in primary process; and by a new API, rte_vhost_set_vring_effective_fd(), we can set effective callfd and kickfd which can be used by secondary process. Note in this case, either primary process or the secondary process can kick the frontend; that is, they cannot kick a vring at the same time. Signed-off-by: Jianfeng Tan --- lib/librte_vhost/rte_vhost.h | 3 +++ lib/librte_vhost/rte_vhost_version.map | 7 +++++++ lib/librte_vhost/vhost.c | 37 ++++++++++++++++++++++++++++------ lib/librte_vhost/vhost.h | 3 +++ lib/librte_vhost/vhost_user.c | 17 ++++++++-------- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index 8c974eb..c82f249 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -432,6 +432,9 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem); int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, struct rte_vhost_vring *vring); +int rte_vhost_set_vring_effective_fd(int vid, uint16_t vring_idx, + int callfd, int kickfd); + /** * Get vhost RX queue avail count. * diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 1e70495..02142df 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -52,3 +52,10 @@ DPDK_17.08 { rte_vhost_rx_queue_count; } DPDK_17.05; + +DPDK_17.11 { + global: + + rte_vhost_set_vring_effective_fd; + +} DPDK_17.08; diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 2b687ea..11a3db1 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -98,10 +98,10 @@ get_device(int vid) static void cleanup_vq(struct vhost_virtqueue *vq, int destroy) { - if ((vq->callfd >= 0) && (destroy != 0)) - close(vq->callfd); - if (vq->kickfd >= 0) - close(vq->kickfd); + if ((vq->callfd_pri >= 0) && (destroy != 0)) + close(vq->callfd_pri); + if (vq->kickfd_pri >= 0) + close(vq->kickfd_pri); } /* @@ -146,6 +146,8 @@ init_vring_queue(struct vhost_virtqueue *vq) vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD; + vq->kickfd_pri = VIRTIO_UNINITIALIZED_EVENTFD; + vq->callfd_pri = VIRTIO_UNINITIALIZED_EVENTFD; /* Backends are set to -1 indicating an inactive device. */ vq->backend = -1; @@ -435,13 +437,36 @@ rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, vring->used = vq->used; vring->log_guest_addr = vq->log_guest_addr; - vring->callfd = vq->callfd; - vring->kickfd = vq->kickfd; + vring->callfd = vq->callfd_pri; + vring->kickfd = vq->kickfd_pri; vring->size = vq->size; return 0; } +int +rte_vhost_set_vring_effective_fd(int vid, uint16_t vring_idx, + int callfd, int kickfd) +{ + struct virtio_net *dev; + struct vhost_virtqueue *vq; + + dev = get_device(vid); + if (!dev) + return -1; + + if (vring_idx >= VHOST_MAX_VRING) + return -1; + + vq = dev->virtqueue[vring_idx]; + if (!vq) + return -1; + + vq->callfd = callfd; + vq->kickfd = kickfd; + + return 0; +} uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index bc1f31e..be57c52 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -98,9 +98,12 @@ struct vhost_virtqueue { /* Backend value to determine if device should started/stopped */ int backend; /* Used to notify the guest (trigger interrupt) */ + int callfd_pri; int callfd; /* Currently unused as polling mode is enabled */ + int kickfd_pri; int kickfd; + int enabled; /* Physical address of used ring, for logging */ diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index ad2e8d3..3d1eea4 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -661,10 +661,10 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) "vring call idx:%d file:%d\n", file.index, file.fd); vq = dev->virtqueue[file.index]; - if (vq->callfd >= 0) - close(vq->callfd); + if (vq->callfd_pri >= 0) + close(vq->callfd_pri); - vq->callfd = file.fd; + vq->callfd_pri = vq->callfd = file.fd; } static void @@ -682,9 +682,9 @@ vhost_user_set_vring_kick(struct virtio_net *dev, struct VhostUserMsg *pmsg) "vring kick idx:%d file:%d\n", file.index, file.fd); vq = dev->virtqueue[file.index]; - if (vq->kickfd >= 0) - close(vq->kickfd); - vq->kickfd = file.fd; + if (vq->kickfd_pri >= 0) + close(vq->kickfd_pri); + vq->kickfd_pri = vq->kickfd = file.fd; } static void @@ -731,10 +731,11 @@ vhost_user_get_vring_base(struct virtio_net *dev, * sent and only sent in vhost_vring_stop. * TODO: cleanup the vring, it isn't usable since here. */ - if (vq->kickfd >= 0) - close(vq->kickfd); + if (vq->kickfd_pri >= 0) + close(vq->kickfd_pri); vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; + vq->kickfd_pri = VIRTIO_UNINITIALIZED_EVENTFD; if (dev->dequeue_zero_copy) free_zmbufs(vq);