From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 201B71B1C5 for ; Thu, 28 Sep 2017 15:55:01 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Sep 2017 06:55:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,450,1500966000"; d="scan'208";a="157117756" Received: from dpdk06.sh.intel.com ([10.67.110.196]) by fmsmga006.fm.intel.com with ESMTP; 28 Sep 2017 06:54:59 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: 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: Thu, 28 Sep 2017 13:55:57 +0000 Message-Id: <1506606959-76230-11-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506606959-76230-1-git-send-email-jianfeng.tan@intel.com> References: <1503654052-84730-1-git-send-email-jianfeng.tan@intel.com> <1506606959-76230-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v2 10/12] 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: Thu, 28 Sep 2017 13:55:02 -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