From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 6A9771B617 for ; Fri, 13 Oct 2017 04:02:56 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Oct 2017 19:02:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,369,1503385200"; d="scan'208";a="909478824" Received: from dpdk06.sh.intel.com ([10.67.110.196]) by FMSMGA003.fm.intel.com with ESMTP; 12 Oct 2017 19:02:53 -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: Fri, 13 Oct 2017 02:04:11 +0000 Message-Id: <1507860252-137510-4-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507860252-137510-1-git-send-email-jianfeng.tan@intel.com> References: <1507519229-80692-1-git-send-email-jianfeng.tan@intel.com> <1507860252-137510-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v7 3/4] 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: , X-List-Received-Date: Fri, 13 Oct 2017 02:02:57 -0000 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); -- 2.7.4