From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 62DEB1B1EE for ; Mon, 9 Oct 2017 12:53:48 +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:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,500,1500966000"; d="scan'208";a="321115976" Received: from dpdk06.sh.intel.com ([10.67.110.196]) by fmsmga004.fm.intel.com with ESMTP; 09 Oct 2017 03:53:46 -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:04 +0000 Message-Id: <1507546506-25227-4-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 3/5] vhost: allocate virtio_net in memzone 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: Mon, 09 Oct 2017 10:53:49 -0000 Instead of allocate on the stack, change to allocate in memzone so that we can retrieve them in secondary processes. TODO: numa awareness. Signed-off-by: Jianfeng Tan --- lib/librte_vhost/socket.c | 2 ++ lib/librte_vhost/vhost.c | 34 ++++++++++++++++++++++++++++++++-- lib/librte_vhost/vhost.h | 4 +++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 41aa3f9..35b9751 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -606,6 +606,8 @@ rte_vhost_driver_register(const char *path, uint64_t flags) int ret = -1; struct vhost_user_socket *vsocket; + alloc_vhost_devices(); + if (!path) return -1; diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 0b6aa1c..2b687ea 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -47,15 +47,45 @@ #include #include #include +#include #include "vhost.h" -struct virtio_net *vhost_devices[MAX_VHOST_DEVICE]; +#define MZ_VHOST_DEVICES "mz_vhost_devices" +struct virtio_net **vhost_devices; + +void +alloc_vhost_devices(void) +{ + const struct rte_memzone *mz; + + if (vhost_devices != NULL) + return; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + mz = rte_memzone_reserve(MZ_VHOST_DEVICES, + MAX_VHOST_DEVICE * sizeof(*vhost_devices), + rte_socket_id(), 0); + } else + mz = rte_memzone_lookup(MZ_VHOST_DEVICES); + + if (mz == NULL) + rte_panic("Cannot allocate memzone for vhost_devices\n"); + + vhost_devices = mz->addr; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + memset(vhost_devices, 0, + MAX_VHOST_DEVICE * sizeof(*vhost_devices)); +} struct virtio_net * get_device(int vid) { - struct virtio_net *dev = vhost_devices[vid]; + struct virtio_net *dev; + + alloc_vhost_devices(); + + dev = vhost_devices[vid]; if (unlikely(!dev)) { RTE_LOG(ERR, VHOST_CONFIG, diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 6fe72ae..bc1f31e 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -278,7 +278,7 @@ vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq, extern uint64_t VHOST_FEATURES; #define MAX_VHOST_DEVICE 1024 -extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE]; +extern struct virtio_net **vhost_devices; /* Convert guest physical address to host physical address */ static __rte_always_inline phys_addr_t @@ -300,6 +300,8 @@ gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size) return 0; } + +void alloc_vhost_devices(void); struct virtio_net *get_device(int vid); int vhost_new_device(void); -- 2.7.4