* [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue @ 2015-05-28 2:04 Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie ` (3 more replies) 0 siblings, 4 replies; 18+ messages in thread From: Huawei Xie @ 2015-05-28 2:04 UTC (permalink / raw) To: dev The virtio_net device and vhost virt queue should be allocated on the same numa node as vring descriptors. When we firstly allocate the virtio_net device and vhost virt queue, we don't know the numa node of vring descriptors. When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptors, so we will try to reallocate virtio_net and vhost virt queue to the same numa node. Huawei Xie (2): use rte_malloc/free for virtio_net and virt_queue memory data allocation/free When we get the address of vring descriptor table, will try to reallocate virtio_net device and virtqueue to the same numa node. config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 112 ++++++++++++++++++++++++++++++++++++++---- mk/rte.app.mk | 3 ++ 4 files changed, 111 insertions(+), 9 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH RFC 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation 2015-05-28 2:04 [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Huawei Xie @ 2015-05-28 2:04 ` Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie ` (2 subsequent siblings) 3 siblings, 0 replies; 18+ messages in thread From: Huawei Xie @ 2015-05-28 2:04 UTC (permalink / raw) To: dev use rte_malloc/free for virtio_net and virt queue allocation/free Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- lib/librte_vhost/virtio-net.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 4672e67..19b74d6 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -45,6 +45,7 @@ #include <rte_log.h> #include <rte_string_fns.h> #include <rte_memory.h> +#include <rte_malloc.h> #include <rte_virtio_net.h> #include "vhost-net.h" @@ -202,9 +203,9 @@ static void free_device(struct virtio_net_config_ll *ll_dev) { /* Free any malloc'd memory */ - free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); - free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); - free(ll_dev); + rte_free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); + rte_free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); + rte_free(ll_dev); } /* @@ -278,7 +279,7 @@ new_device(struct vhost_device_ctx ctx) struct vhost_virtqueue *virtqueue_rx, *virtqueue_tx; /* Setup device and virtqueues. */ - new_ll_dev = malloc(sizeof(struct virtio_net_config_ll)); + new_ll_dev = rte_malloc(NULL, sizeof(struct virtio_net_config_ll), 0); if (new_ll_dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for dev.\n", @@ -286,19 +287,19 @@ new_device(struct vhost_device_ctx ctx) return -1; } - virtqueue_rx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_rx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_rx == NULL) { - free(new_ll_dev); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for rxq.\n", ctx.fh); return -1; } - virtqueue_tx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_tx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_tx == NULL) { - free(virtqueue_rx); - free(new_ll_dev); + rte_free(virtqueue_rx); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for txq.\n", ctx.fh); -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH RFC 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table 2015-05-28 2:04 [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie @ 2015-05-28 2:04 ` Huawei Xie 2015-06-03 23:38 ` [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Long, Thomas 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie 3 siblings, 0 replies; 18+ messages in thread From: Huawei Xie @ 2015-05-28 2:04 UTC (permalink / raw) To: dev When we get the address of vring descriptor table in VHOST_SET_VRING_ADDR message, will try to reallocate virtio_net device and virtqueue to the same numa node. Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++ mk/rte.app.mk | 3 ++ 4 files changed, 101 insertions(+) diff --git a/config/common_linuxapp b/config/common_linuxapp index 0078dc9..4ace24e 100644 --- a/config/common_linuxapp +++ b/config/common_linuxapp @@ -421,6 +421,7 @@ CONFIG_RTE_KNI_VHOST_DEBUG_TX=n # CONFIG_RTE_LIBRTE_VHOST=n CONFIG_RTE_LIBRTE_VHOST_USER=y +CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n # diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index a8645a6..6681f22 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -46,6 +46,10 @@ CFLAGS += -I vhost_cuse -lfuse LDFLAGS += -lfuse endif +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +LDFLAGS += -lnuma +endif + # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 19b74d6..8a80f5e 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -38,6 +38,9 @@ #include <stdlib.h> #include <sys/mman.h> #include <unistd.h> +#ifdef RTE_LIBRTE_VHOST_NUMA +#include <numaif.h> +#endif #include <sys/socket.h> @@ -481,6 +484,93 @@ set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state) } /* + * Reallocate virtio_det and vhost_virtqueue data structure to make them on the + * same numa node as the memory of vring descriptor. + */ +#ifdef RTE_LIBRTE_VHOST_NUMA +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index) +{ + int oldnode, newnode; + struct virtio_net_config_ll *old_ll_dev, *new_ll_dev; + struct vhost_virtqueue *old_vq, *new_vq; + int ret; + int realloc_dev = 0, realloc_vq = 0; + + old_ll_dev = (struct virtio_net_config_ll *)dev; + old_vq = dev->virtqueue[index]; + + ret = get_mempolicy(&newnode, NULL, 0, old_vq->desc, + MPOL_F_NODE | MPOL_F_ADDR); + ret = ret | get_mempolicy(&oldnode, NULL, 0, old_ll_dev, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vring desc or dev numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_dev = 1; + + ret = get_mempolicy(&oldnode, NULL, 0, old_vq, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vq numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_vq = 1; + + if (realloc_dev == 0 && realloc_vq == 0) + return dev; + + if (realloc_dev) + new_ll_dev = rte_malloc_socket(NULL, + sizeof(struct virtio_net_config_ll), 0, newnode); + if (realloc_vq) + new_vq = rte_malloc_socket(NULL, + sizeof(struct vhost_virtqueue), 0, newnode); + if (!new_ll_dev || !new_vq) { + if (new_ll_dev) + rte_free(new_ll_dev); + if (new_vq) + rte_free(new_vq); + return dev; + } + + if (realloc_vq) + memcpy(new_vq, old_vq, sizeof(*new_vq)); + if (realloc_dev) + memcpy(new_ll_dev, old_ll_dev, sizeof(*new_ll_dev)); + (new_ll_dev ? new_ll_dev : old_ll_dev)->dev.virtqueue[index] = + new_vq ? new_vq : old_vq; + if (realloc_vq) + rte_free(old_vq); + if (realloc_dev) { + if (ll_root == old_ll_dev) + ll_root = new_ll_dev; + else { + struct virtio_net_config_ll *prev = ll_root; + while (prev->next != old_ll_dev) + prev = prev->next; + prev->next = new_ll_dev; + new_ll_dev->next = old_ll_dev->next; + } + rte_free(old_ll_dev); + } + + return &new_ll_dev->dev; +} +#else +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index __rte_unused) +{ + return dev; +} +#endif + +/* * Called from CUSE IOCTL: VHOST_SET_VRING_ADDR * The virtio device sends us the desc, used and avail ring addresses. * This function then converts these to our address space. @@ -508,6 +598,9 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) return -1; } + dev = numa_realloc(dev, addr->index); + vq = dev->virtqueue[addr->index]; + vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev, addr->avail_user_addr); if (vq->avail == 0) { diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 1a2043a..5aba56a 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -92,6 +92,9 @@ endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lpcap +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma + ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n) _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse endif -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue 2015-05-28 2:04 [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie @ 2015-06-03 23:38 ` Long, Thomas 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie 3 siblings, 0 replies; 18+ messages in thread From: Long, Thomas @ 2015-06-03 23:38 UTC (permalink / raw) To: Xie, Huawei, dev Acked-by: Tommy Long <thomas.long@intel.com> -----Original Message----- From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Huawei Xie Sent: Thursday, May 28, 2015 3:04 AM To: dev@dpdk.org Subject: [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue The virtio_net device and vhost virt queue should be allocated on the same numa node as vring descriptors. When we firstly allocate the virtio_net device and vhost virt queue, we don't know the numa node of vring descriptors. When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptors, so we will try to reallocate virtio_net and vhost virt queue to the same numa node. Huawei Xie (2): use rte_malloc/free for virtio_net and virt_queue memory data allocation/free When we get the address of vring descriptor table, will try to reallocate virtio_net device and virtqueue to the same numa node. config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 112 ++++++++++++++++++++++++++++++++++++++---- mk/rte.app.mk | 3 ++ 4 files changed, 111 insertions(+), 9 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue 2015-05-28 2:04 [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Huawei Xie ` (2 preceding siblings ...) 2015-06-03 23:38 ` [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Long, Thomas @ 2015-06-05 3:13 ` Huawei Xie 2015-06-05 3:13 ` [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie ` (3 more replies) 3 siblings, 4 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-05 3:13 UTC (permalink / raw) To: dev The virtio_net device and vhost virt queue should be allocated on the same numa node as vring descriptors. When we firstly allocate the virtio_net device and vhost virt queue, we don't know the numa node of vring descriptors. When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptors, so we will try to reallocate virtio_net and vhost virt queue to the same numa node. Huawei Xie (2): use rte_malloc/free for virtio_net and virt_queue memory data allocation/free When we get the address of vring descriptor table, will try to reallocate virtio_net device and virtqueue to the same numa node. config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 112 ++++++++++++++++++++++++++++++++++++++---- mk/rte.app.mk | 3 ++ 4 files changed, 111 insertions(+), 9 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie @ 2015-06-05 3:13 ` Huawei Xie 2015-06-17 17:06 ` Thomas Monjalon 2015-06-05 3:13 ` [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie ` (2 subsequent siblings) 3 siblings, 1 reply; 18+ messages in thread From: Huawei Xie @ 2015-06-05 3:13 UTC (permalink / raw) To: dev use rte_malloc/free for virtio_net and virt queue allocation/free Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- lib/librte_vhost/virtio-net.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 4672e67..19b74d6 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -45,6 +45,7 @@ #include <rte_log.h> #include <rte_string_fns.h> #include <rte_memory.h> +#include <rte_malloc.h> #include <rte_virtio_net.h> #include "vhost-net.h" @@ -202,9 +203,9 @@ static void free_device(struct virtio_net_config_ll *ll_dev) { /* Free any malloc'd memory */ - free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); - free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); - free(ll_dev); + rte_free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); + rte_free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); + rte_free(ll_dev); } /* @@ -278,7 +279,7 @@ new_device(struct vhost_device_ctx ctx) struct vhost_virtqueue *virtqueue_rx, *virtqueue_tx; /* Setup device and virtqueues. */ - new_ll_dev = malloc(sizeof(struct virtio_net_config_ll)); + new_ll_dev = rte_malloc(NULL, sizeof(struct virtio_net_config_ll), 0); if (new_ll_dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for dev.\n", @@ -286,19 +287,19 @@ new_device(struct vhost_device_ctx ctx) return -1; } - virtqueue_rx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_rx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_rx == NULL) { - free(new_ll_dev); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for rxq.\n", ctx.fh); return -1; } - virtqueue_tx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_tx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_tx == NULL) { - free(virtqueue_rx); - free(new_ll_dev); + rte_free(virtqueue_rx); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for txq.\n", ctx.fh); -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation 2015-06-05 3:13 ` [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie @ 2015-06-17 17:06 ` Thomas Monjalon 0 siblings, 0 replies; 18+ messages in thread From: Thomas Monjalon @ 2015-06-17 17:06 UTC (permalink / raw) To: Huawei Xie; +Cc: dev 2015-06-05 11:13, Huawei Xie: > use rte_malloc/free for virtio_net and virt queue allocation/free > > Signed-off-by: Huawei Xie <huawei.xie@intel.com> I suggest this title: vhost: use rte_malloc to allocate device and queues ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie 2015-06-05 3:13 ` [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie @ 2015-06-05 3:13 ` Huawei Xie 2015-06-17 16:47 ` Thomas Monjalon 2015-06-09 4:05 ` [dpdk-dev] [PATCH 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Long, Thomas 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 3 siblings, 1 reply; 18+ messages in thread From: Huawei Xie @ 2015-06-05 3:13 UTC (permalink / raw) To: dev When we get the address of vring descriptor table in VHOST_SET_VRING_ADDR message, will try to reallocate virtio_net device and virtqueue to the same numa node. Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++ mk/rte.app.mk | 3 ++ 4 files changed, 101 insertions(+) diff --git a/config/common_linuxapp b/config/common_linuxapp index 0078dc9..4ace24e 100644 --- a/config/common_linuxapp +++ b/config/common_linuxapp @@ -421,6 +421,7 @@ CONFIG_RTE_KNI_VHOST_DEBUG_TX=n # CONFIG_RTE_LIBRTE_VHOST=n CONFIG_RTE_LIBRTE_VHOST_USER=y +CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n # diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index a8645a6..6681f22 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -46,6 +46,10 @@ CFLAGS += -I vhost_cuse -lfuse LDFLAGS += -lfuse endif +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +LDFLAGS += -lnuma +endif + # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 19b74d6..8a80f5e 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -38,6 +38,9 @@ #include <stdlib.h> #include <sys/mman.h> #include <unistd.h> +#ifdef RTE_LIBRTE_VHOST_NUMA +#include <numaif.h> +#endif #include <sys/socket.h> @@ -481,6 +484,93 @@ set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state) } /* + * Reallocate virtio_det and vhost_virtqueue data structure to make them on the + * same numa node as the memory of vring descriptor. + */ +#ifdef RTE_LIBRTE_VHOST_NUMA +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index) +{ + int oldnode, newnode; + struct virtio_net_config_ll *old_ll_dev, *new_ll_dev; + struct vhost_virtqueue *old_vq, *new_vq; + int ret; + int realloc_dev = 0, realloc_vq = 0; + + old_ll_dev = (struct virtio_net_config_ll *)dev; + old_vq = dev->virtqueue[index]; + + ret = get_mempolicy(&newnode, NULL, 0, old_vq->desc, + MPOL_F_NODE | MPOL_F_ADDR); + ret = ret | get_mempolicy(&oldnode, NULL, 0, old_ll_dev, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vring desc or dev numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_dev = 1; + + ret = get_mempolicy(&oldnode, NULL, 0, old_vq, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vq numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_vq = 1; + + if (realloc_dev == 0 && realloc_vq == 0) + return dev; + + if (realloc_dev) + new_ll_dev = rte_malloc_socket(NULL, + sizeof(struct virtio_net_config_ll), 0, newnode); + if (realloc_vq) + new_vq = rte_malloc_socket(NULL, + sizeof(struct vhost_virtqueue), 0, newnode); + if (!new_ll_dev || !new_vq) { + if (new_ll_dev) + rte_free(new_ll_dev); + if (new_vq) + rte_free(new_vq); + return dev; + } + + if (realloc_vq) + memcpy(new_vq, old_vq, sizeof(*new_vq)); + if (realloc_dev) + memcpy(new_ll_dev, old_ll_dev, sizeof(*new_ll_dev)); + (new_ll_dev ? new_ll_dev : old_ll_dev)->dev.virtqueue[index] = + new_vq ? new_vq : old_vq; + if (realloc_vq) + rte_free(old_vq); + if (realloc_dev) { + if (ll_root == old_ll_dev) + ll_root = new_ll_dev; + else { + struct virtio_net_config_ll *prev = ll_root; + while (prev->next != old_ll_dev) + prev = prev->next; + prev->next = new_ll_dev; + new_ll_dev->next = old_ll_dev->next; + } + rte_free(old_ll_dev); + } + + return &new_ll_dev->dev; +} +#else +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index __rte_unused) +{ + return dev; +} +#endif + +/* * Called from CUSE IOCTL: VHOST_SET_VRING_ADDR * The virtio device sends us the desc, used and avail ring addresses. * This function then converts these to our address space. @@ -508,6 +598,9 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) return -1; } + dev = numa_realloc(dev, addr->index); + vq = dev->virtqueue[addr->index]; + vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev, addr->avail_user_addr); if (vq->avail == 0) { diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 1a2043a..5aba56a 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -92,6 +92,9 @@ endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lpcap +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma + ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n) _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse endif -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table 2015-06-05 3:13 ` [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie @ 2015-06-17 16:47 ` Thomas Monjalon 2015-06-17 17:02 ` Thomas Monjalon 0 siblings, 1 reply; 18+ messages in thread From: Thomas Monjalon @ 2015-06-17 16:47 UTC (permalink / raw) To: Huawei Xie; +Cc: dev 2015-06-05 11:13, Huawei Xie: > --- a/mk/rte.app.mk > +++ b/mk/rte.app.mk > @@ -92,6 +92,9 @@ endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS > > _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lpcap > > +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) > +_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma > + > ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n) > _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse > endif An endif is missing. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table 2015-06-17 16:47 ` Thomas Monjalon @ 2015-06-17 17:02 ` Thomas Monjalon 0 siblings, 0 replies; 18+ messages in thread From: Thomas Monjalon @ 2015-06-17 17:02 UTC (permalink / raw) To: Huawei Xie, Tommy Long; +Cc: dev 2015-06-17 18:47, Thomas Monjalon: > 2015-06-05 11:13, Huawei Xie: > > --- a/mk/rte.app.mk > > +++ b/mk/rte.app.mk > > @@ -92,6 +92,9 @@ endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS > > > > _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lpcap > > > > +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) > > +_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma > > + > > ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n) > > _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse > > endif > > An endif is missing. After adding the endif and enabling the NUMA option, these errors appear: lib/librte_vhost/virtio-net.c:535:21: error: ‘new_vq’ may be used uninitialized in this function lib/librte_vhost/virtio-net.c:547:63: error: ‘new_ll_dev’ may be used uninitialized in this function Tommy, I won't review the code, but given it doesn't build, I can guess how it has been reviewed. Acked-by line is valuable only if the review is carefully done. This patch series go back to lowest merge priority. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [dpdk-dev] [PATCH 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie 2015-06-05 3:13 ` [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie 2015-06-05 3:13 ` [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie @ 2015-06-09 4:05 ` Long, Thomas 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 3 siblings, 0 replies; 18+ messages in thread From: Long, Thomas @ 2015-06-09 4:05 UTC (permalink / raw) To: Xie, Huawei, dev Acked-by: Tommy Long <thomas.long@intel.com> -----Original Message----- From: Xie, Huawei Sent: Friday, June 5, 2015 4:13 AM To: dev@dpdk.org Cc: Long, Thomas Subject: [PATCH 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue The virtio_net device and vhost virt queue should be allocated on the same numa node as vring descriptors. When we firstly allocate the virtio_net device and vhost virt queue, we don't know the numa node of vring descriptors. When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptors, so we will try to reallocate virtio_net and vhost virt queue to the same numa node. Huawei Xie (2): use rte_malloc/free for virtio_net and virt_queue memory data allocation/free When we get the address of vring descriptor table, will try to reallocate virtio_net device and virtqueue to the same numa node. config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 112 ++++++++++++++++++++++++++++++++++++++---- mk/rte.app.mk | 3 ++ 4 files changed, 111 insertions(+), 9 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie ` (2 preceding siblings ...) 2015-06-09 4:05 ` [dpdk-dev] [PATCH 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Long, Thomas @ 2015-06-18 16:59 ` Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 1/2] vhost: use rte_malloc to allocate " Huawei Xie ` (2 more replies) 3 siblings, 3 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-18 16:59 UTC (permalink / raw) To: dev The vhost device and queues should be allocated on the same numa node as vring descriptor table. When we firstly allocate the vhost device and queues, we don't know the numa node of vring descriptor table. When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptor table, we will try to reallocate vhost device and queues to the same numa node. Huawei Xie (2): use rte_malloc to allocate vhost device and queues reallocate vhost device and queues when we get the address of vring descriptor table config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 112 ++++++++++++++++++++++++++++++++++++++---- mk/rte.app.mk | 4 ++ 4 files changed, 112 insertions(+), 9 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH v2 1/2] vhost: use rte_malloc to allocate device and queues 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie @ 2015-06-18 16:59 ` Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2 siblings, 0 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-18 16:59 UTC (permalink / raw) To: dev use rte_malloc to allocate vhost device and queues Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- lib/librte_vhost/virtio-net.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 4672e67..19b74d6 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -45,6 +45,7 @@ #include <rte_log.h> #include <rte_string_fns.h> #include <rte_memory.h> +#include <rte_malloc.h> #include <rte_virtio_net.h> #include "vhost-net.h" @@ -202,9 +203,9 @@ static void free_device(struct virtio_net_config_ll *ll_dev) { /* Free any malloc'd memory */ - free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); - free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); - free(ll_dev); + rte_free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); + rte_free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); + rte_free(ll_dev); } /* @@ -278,7 +279,7 @@ new_device(struct vhost_device_ctx ctx) struct vhost_virtqueue *virtqueue_rx, *virtqueue_tx; /* Setup device and virtqueues. */ - new_ll_dev = malloc(sizeof(struct virtio_net_config_ll)); + new_ll_dev = rte_malloc(NULL, sizeof(struct virtio_net_config_ll), 0); if (new_ll_dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for dev.\n", @@ -286,19 +287,19 @@ new_device(struct vhost_device_ctx ctx) return -1; } - virtqueue_rx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_rx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_rx == NULL) { - free(new_ll_dev); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for rxq.\n", ctx.fh); return -1; } - virtqueue_tx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_tx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_tx == NULL) { - free(virtqueue_rx); - free(new_ll_dev); + rte_free(virtqueue_rx); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for txq.\n", ctx.fh); -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH v2 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 1/2] vhost: use rte_malloc to allocate " Huawei Xie @ 2015-06-18 16:59 ` Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2 siblings, 0 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-18 16:59 UTC (permalink / raw) To: dev When we get the address of vring descriptor table in VHOST_SET_VRING_ADDR message, will try to reallocate vhost device and queues to the same numa node. v2 changes: - fix uninitialised new_vq and new_ll_device - fix missed endif in rte.app.mk - fix new_ll_dev and new_vq allocation failure issue - return old virtio device if new_ll_dev isn't allocated Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++ mk/rte.app.mk | 4 ++ 4 files changed, 102 insertions(+) diff --git a/config/common_linuxapp b/config/common_linuxapp index 0078dc9..4ace24e 100644 --- a/config/common_linuxapp +++ b/config/common_linuxapp @@ -421,6 +421,7 @@ CONFIG_RTE_KNI_VHOST_DEBUG_TX=n # CONFIG_RTE_LIBRTE_VHOST=n CONFIG_RTE_LIBRTE_VHOST_USER=y +CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n # diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index a8645a6..6681f22 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -46,6 +46,10 @@ CFLAGS += -I vhost_cuse -lfuse LDFLAGS += -lfuse endif +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +LDFLAGS += -lnuma +endif + # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 19b74d6..0a065af 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -38,6 +38,9 @@ #include <stdlib.h> #include <sys/mman.h> #include <unistd.h> +#ifdef RTE_LIBRTE_VHOST_NUMA +#include <numaif.h> +#endif #include <sys/socket.h> @@ -481,6 +484,93 @@ set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state) } /* + * Reallocate virtio_det and vhost_virtqueue data structure to make them on the + * same numa node as the memory of vring descriptor. + */ +#ifdef RTE_LIBRTE_VHOST_NUMA +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index) +{ + int oldnode, newnode; + struct virtio_net_config_ll *old_ll_dev, *new_ll_dev = NULL; + struct vhost_virtqueue *old_vq, *new_vq = NULL; + int ret; + int realloc_dev = 0, realloc_vq = 0; + + old_ll_dev = (struct virtio_net_config_ll *)dev; + old_vq = dev->virtqueue[index]; + + ret = get_mempolicy(&newnode, NULL, 0, old_vq->desc, + MPOL_F_NODE | MPOL_F_ADDR); + ret = ret | get_mempolicy(&oldnode, NULL, 0, old_ll_dev, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vring desc or dev numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_dev = 1; + + ret = get_mempolicy(&oldnode, NULL, 0, old_vq, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vq numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_vq = 1; + + if (realloc_dev == 0 && realloc_vq == 0) + return dev; + + if (realloc_dev) + new_ll_dev = rte_malloc_socket(NULL, + sizeof(struct virtio_net_config_ll), 0, newnode); + if (realloc_vq) + new_vq = rte_malloc_socket(NULL, + sizeof(struct vhost_virtqueue), 0, newnode); + if (!new_ll_dev && !new_vq) { + if (new_ll_dev) + rte_free(new_ll_dev); + if (new_vq) + rte_free(new_vq); + return dev; + } + + if (realloc_vq) + memcpy(new_vq, old_vq, sizeof(*new_vq)); + if (realloc_dev) + memcpy(new_ll_dev, old_ll_dev, sizeof(*new_ll_dev)); + (new_ll_dev ? new_ll_dev : old_ll_dev)->dev.virtqueue[index] = + new_vq ? new_vq : old_vq; + if (realloc_vq) + rte_free(old_vq); + if (realloc_dev) { + if (ll_root == old_ll_dev) + ll_root = new_ll_dev; + else { + struct virtio_net_config_ll *prev = ll_root; + while (prev->next != old_ll_dev) + prev = prev->next; + prev->next = new_ll_dev; + new_ll_dev->next = old_ll_dev->next; + } + rte_free(old_ll_dev); + } + + return realloc_dev ? &new_ll_dev->dev : dev; +} +#else +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index __rte_unused) +{ + return dev; +} +#endif + +/* * Called from CUSE IOCTL: VHOST_SET_VRING_ADDR * The virtio device sends us the desc, used and avail ring addresses. * This function then converts these to our address space. @@ -508,6 +598,9 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) return -1; } + dev = numa_realloc(dev, addr->index); + vq = dev->virtqueue[addr->index]; + vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev, addr->avail_user_addr); if (vq->avail == 0) { diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 1a2043a..0d6c14a 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -92,6 +92,10 @@ endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lpcap +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma +endif + ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n) _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse endif -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 1/2] vhost: use rte_malloc to allocate " Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table Huawei Xie @ 2015-06-25 5:47 ` Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 1/2] vhost: use rte_malloc to allocate " Huawei Xie ` (2 more replies) 2 siblings, 3 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-25 5:47 UTC (permalink / raw) To: dev The vhost device and queues should be allocated on the same numa node as vring descriptor table. When we firstly allocate the vhost device and queues, we don't know the numa node of vring descriptor table. When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptor table, we will try to reallocate vhost device and queues to the same numa node. Huawei Xie (2): use rte_malloc to allocate vhost device and queues reallocate vhost device and queues when we get the address of vring descriptor table config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 107 ++++++++++++++++++++++++++++++++++++++---- mk/rte.app.mk | 4 ++ 4 files changed, 107 insertions(+), 9 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH v3 1/2] vhost: use rte_malloc to allocate device and queues 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie @ 2015-06-25 5:47 ` Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table Huawei Xie 2015-06-29 17:04 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Thomas Monjalon 2 siblings, 0 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-25 5:47 UTC (permalink / raw) To: dev use rte_malloc to allocate vhost device and queues Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- lib/librte_vhost/virtio-net.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 4672e67..19b74d6 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -45,6 +45,7 @@ #include <rte_log.h> #include <rte_string_fns.h> #include <rte_memory.h> +#include <rte_malloc.h> #include <rte_virtio_net.h> #include "vhost-net.h" @@ -202,9 +203,9 @@ static void free_device(struct virtio_net_config_ll *ll_dev) { /* Free any malloc'd memory */ - free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); - free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); - free(ll_dev); + rte_free(ll_dev->dev.virtqueue[VIRTIO_RXQ]); + rte_free(ll_dev->dev.virtqueue[VIRTIO_TXQ]); + rte_free(ll_dev); } /* @@ -278,7 +279,7 @@ new_device(struct vhost_device_ctx ctx) struct vhost_virtqueue *virtqueue_rx, *virtqueue_tx; /* Setup device and virtqueues. */ - new_ll_dev = malloc(sizeof(struct virtio_net_config_ll)); + new_ll_dev = rte_malloc(NULL, sizeof(struct virtio_net_config_ll), 0); if (new_ll_dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for dev.\n", @@ -286,19 +287,19 @@ new_device(struct vhost_device_ctx ctx) return -1; } - virtqueue_rx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_rx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_rx == NULL) { - free(new_ll_dev); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for rxq.\n", ctx.fh); return -1; } - virtqueue_tx = malloc(sizeof(struct vhost_virtqueue)); + virtqueue_tx = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0); if (virtqueue_tx == NULL) { - free(virtqueue_rx); - free(new_ll_dev); + rte_free(virtqueue_rx); + rte_free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for txq.\n", ctx.fh); -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [dpdk-dev] [PATCH v3 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 1/2] vhost: use rte_malloc to allocate " Huawei Xie @ 2015-06-25 5:47 ` Huawei Xie 2015-06-29 17:04 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Thomas Monjalon 2 siblings, 0 replies; 18+ messages in thread From: Huawei Xie @ 2015-06-25 5:47 UTC (permalink / raw) To: dev When we get the address of vring descriptor table in VHOST_SET_VRING_ADDR message, will try to reallocate vhost device and virt queue to the same numa node. v3 changes: - remove unnecessary rte_free of new_vq and new_ll_dev v2 changes: - fix uninitialised new_vq and new_ll_device - fix missed endif in rte.app.mk - fix new_ll_dev and new_vq allocation failure issue - return old virtio device if new_ll_dev isn't allocated Signed-off-by: Huawei Xie <huawei.xie@intel.com> --- config/common_linuxapp | 1 + lib/librte_vhost/Makefile | 4 ++ lib/librte_vhost/virtio-net.c | 88 +++++++++++++++++++++++++++++++++++++++++++ mk/rte.app.mk | 4 ++ 4 files changed, 97 insertions(+) diff --git a/config/common_linuxapp b/config/common_linuxapp index 0078dc9..4ace24e 100644 --- a/config/common_linuxapp +++ b/config/common_linuxapp @@ -421,6 +421,7 @@ CONFIG_RTE_KNI_VHOST_DEBUG_TX=n # CONFIG_RTE_LIBRTE_VHOST=n CONFIG_RTE_LIBRTE_VHOST_USER=y +CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n # diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index a8645a6..6681f22 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -46,6 +46,10 @@ CFLAGS += -I vhost_cuse -lfuse LDFLAGS += -lfuse endif +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +LDFLAGS += -lnuma +endif + # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 19b74d6..fcaefd6 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -38,6 +38,9 @@ #include <stdlib.h> #include <sys/mman.h> #include <unistd.h> +#ifdef RTE_LIBRTE_VHOST_NUMA +#include <numaif.h> +#endif #include <sys/socket.h> @@ -481,6 +484,88 @@ set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state) } /* + * Reallocate virtio_det and vhost_virtqueue data structure to make them on the + * same numa node as the memory of vring descriptor. + */ +#ifdef RTE_LIBRTE_VHOST_NUMA +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index) +{ + int oldnode, newnode; + struct virtio_net_config_ll *old_ll_dev, *new_ll_dev = NULL; + struct vhost_virtqueue *old_vq, *new_vq = NULL; + int ret; + int realloc_dev = 0, realloc_vq = 0; + + old_ll_dev = (struct virtio_net_config_ll *)dev; + old_vq = dev->virtqueue[index]; + + ret = get_mempolicy(&newnode, NULL, 0, old_vq->desc, + MPOL_F_NODE | MPOL_F_ADDR); + ret = ret | get_mempolicy(&oldnode, NULL, 0, old_ll_dev, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vring desc or dev numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_dev = 1; + + ret = get_mempolicy(&oldnode, NULL, 0, old_vq, + MPOL_F_NODE | MPOL_F_ADDR); + if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "Unable to get vq numa information.\n"); + return dev; + } + if (oldnode != newnode) + realloc_vq = 1; + + if (realloc_dev == 0 && realloc_vq == 0) + return dev; + + if (realloc_dev) + new_ll_dev = rte_malloc_socket(NULL, + sizeof(struct virtio_net_config_ll), 0, newnode); + if (realloc_vq) + new_vq = rte_malloc_socket(NULL, + sizeof(struct vhost_virtqueue), 0, newnode); + if (!new_ll_dev && !new_vq) + return dev; + + if (realloc_vq) + memcpy(new_vq, old_vq, sizeof(*new_vq)); + if (realloc_dev) + memcpy(new_ll_dev, old_ll_dev, sizeof(*new_ll_dev)); + (new_ll_dev ? new_ll_dev : old_ll_dev)->dev.virtqueue[index] = + new_vq ? new_vq : old_vq; + if (realloc_vq) + rte_free(old_vq); + if (realloc_dev) { + if (ll_root == old_ll_dev) + ll_root = new_ll_dev; + else { + struct virtio_net_config_ll *prev = ll_root; + while (prev->next != old_ll_dev) + prev = prev->next; + prev->next = new_ll_dev; + new_ll_dev->next = old_ll_dev->next; + } + rte_free(old_ll_dev); + } + + return realloc_dev ? &new_ll_dev->dev : dev; +} +#else +static struct virtio_net* +numa_realloc(struct virtio_net *dev, int index __rte_unused) +{ + return dev; +} +#endif + +/* * Called from CUSE IOCTL: VHOST_SET_VRING_ADDR * The virtio device sends us the desc, used and avail ring addresses. * This function then converts these to our address space. @@ -508,6 +593,9 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) return -1; } + dev = numa_realloc(dev, addr->index); + vq = dev->virtqueue[addr->index]; + vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev, addr->avail_user_addr); if (vq->avail == 0) { diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 1a2043a..0d6c14a 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -92,6 +92,10 @@ endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lpcap +ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) +_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma +endif + ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n) _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse endif -- 1.8.1.4 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 1/2] vhost: use rte_malloc to allocate " Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table Huawei Xie @ 2015-06-29 17:04 ` Thomas Monjalon 2 siblings, 0 replies; 18+ messages in thread From: Thomas Monjalon @ 2015-06-29 17:04 UTC (permalink / raw) To: Huawei Xie; +Cc: dev 2015-06-25 13:47, Huawei Xie: > The vhost device and queues should be allocated on the same numa node as vring descriptor table. > When we firstly allocate the vhost device and queues, we don't know the numa node of vring descriptor table. > When we receive the VHOST_SET_VRING_ADDR message, we get the numa node of vring descriptor table, we will try to reallocate vhost device and queues to the same numa node. Commit messages must be wrapped. > Huawei Xie (2): > use rte_malloc to allocate vhost device and queues > reallocate vhost device and queues when we get the address of vring descriptor table Applied, thanks ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2015-06-29 17:05 UTC | newest] Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-05-28 2:04 [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie 2015-05-28 2:04 ` [dpdk-dev] [PATCH RFC 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie 2015-06-03 23:38 ` [dpdk-dev] [PATCH RFC 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Long, Thomas 2015-06-05 3:13 ` [dpdk-dev] [PATCH " Huawei Xie 2015-06-05 3:13 ` [dpdk-dev] [PATCH 1/2] vhost: malloc -> rte_malloc for virtio_net and virt queue allocation Huawei Xie 2015-06-17 17:06 ` Thomas Monjalon 2015-06-05 3:13 ` [dpdk-dev] [PATCH 2/2] vhost: realloc virtio_net and virtqueue to the same node of vring desc table Huawei Xie 2015-06-17 16:47 ` Thomas Monjalon 2015-06-17 17:02 ` Thomas Monjalon 2015-06-09 4:05 ` [dpdk-dev] [PATCH 0/2] vhost: numa aware allocation of virtio_net device and vhost virt queue Long, Thomas 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 1/2] vhost: use rte_malloc to allocate " Huawei Xie 2015-06-18 16:59 ` [dpdk-dev] [PATCH v2 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 1/2] vhost: use rte_malloc to allocate " Huawei Xie 2015-06-25 5:47 ` [dpdk-dev] [PATCH v3 2/2] vhost: realloc vhost device and queues to the same numa node of vring desc table Huawei Xie 2015-06-29 17:04 ` [dpdk-dev] [PATCH v3 0/2] vhost: numa aware allocation of vhost device and queues Thomas Monjalon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).