virtio: Use new buffer optimization

Change-Id: Ifc98373371b967c49a75989eac415ddda1dcf15f
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c
index 4f3066a..101576c 100644
--- a/src/vnet/devices/tap/tap.c
+++ b/src/vnet/devices/tap/tap.c
@@ -392,6 +392,7 @@
   vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, 0,
 				 VNET_HW_INTERFACE_RX_MODE_DEFAULT);
   vif->per_interface_next_index = ~0;
+  virtio_vring_set_numa_node (vm, vif, 0);
   vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
   vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
 			       VNET_HW_INTERFACE_FLAG_LINK_UP);
diff --git a/src/vnet/devices/virtio/node.c b/src/vnet/devices/virtio/node.c
index 6627456..78d071a 100644
--- a/src/vnet/devices/virtio/node.c
+++ b/src/vnet/devices/virtio/node.c
@@ -96,8 +96,10 @@
 
   next = vring->desc_next;
   avail = vring->avail->idx;
-  n_slots = vlib_buffer_alloc_to_ring (vm, vring->buffers, next, vring->size,
-				       n_slots);
+  n_slots =
+    vlib_buffer_alloc_to_ring_from_pool (vm, vring->buffers, next,
+					 vring->size, n_slots,
+					 vring->buffer_pool_index);
 
   if (n_slots == 0)
     return;
diff --git a/src/vnet/devices/virtio/pci.c b/src/vnet/devices/virtio/pci.c
index a90dca4..ffc18f4 100644
--- a/src/vnet/devices/virtio/pci.c
+++ b/src/vnet/devices/virtio/pci.c
@@ -873,6 +873,7 @@
   vnet_hw_interface_set_input_node (vnm, vif->hw_if_index,
 				    virtio_input_node.index);
   vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, 0, ~0);
+  virtio_vring_set_numa_node (vm, vif, 0);
 
   if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP)
     {
diff --git a/src/vnet/devices/virtio/virtio.c b/src/vnet/devices/virtio/virtio.c
index 94f140d..cfeb302 100644
--- a/src/vnet/devices/virtio/virtio.c
+++ b/src/vnet/devices/virtio/virtio.c
@@ -196,6 +196,21 @@
   return 0;
 }
 
+void
+virtio_vring_set_numa_node (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  u32 thread_index;
+  virtio_vring_t *vring = vec_elt_at_index (vif->vrings, idx);
+  thread_index =
+    vnet_get_device_input_thread_index (vnm, vif->hw_if_index,
+					vring->queue_id);
+  vring->buffer_pool_index =
+    vlib_buffer_pool_get_default_for_numa (vm,
+					   vlib_mains
+					   [thread_index]->numa_node);
+}
+
 inline void
 virtio_set_net_hdr_size (virtio_if_t * vif)
 {
diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h
index 73bb33f..b2e74be 100644
--- a/src/vnet/devices/virtio/virtio.h
+++ b/src/vnet/devices/virtio/virtio.h
@@ -103,6 +103,7 @@
   u16 desc_next;
   int kick_fd;
   int call_fd;
+  u8 buffer_pool_index;
   u16 size;
   u16 queue_id;
   u16 flags;
@@ -188,6 +189,8 @@
 				 u16 sz);
 clib_error_t *virtio_vring_free (vlib_main_t * vm, virtio_if_t * vif,
 				 u32 idx);
+void virtio_vring_set_numa_node (vlib_main_t * vm, virtio_if_t * vif,
+				 u32 idx);
 extern void virtio_free_used_desc (vlib_main_t * vm, virtio_vring_t * vring);
 extern void virtio_free_rx_buffers (vlib_main_t * vm, virtio_vring_t * vring);
 extern void virtio_set_net_hdr_size (virtio_if_t * vif);