buffers: support per-numa-domain buffer size

Currently, buffers-per-numa is used for all NUMA domains, and there's
no way to allocate different amounts for each domain.

Therefore, this adds a per-NUMA-domain buffer config section, which
currently has a single option to set the number of buffers.

If it's not specified or set to zero, the code falls back to
buffers-per-numa as before.

Type: improvement
Change-Id: If35d7a9eff6f8d1d78063ea7873dbf50780d0ec3
Signed-off-by: Lukas Stockner <lstockner@genesiscloud.com>
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index 674f15d..5ba4227 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -663,7 +663,7 @@
 				  u8 unpriv)
 {
   vlib_buffer_main_t *bm = vm->buffer_main;
-  u32 buffers_per_numa = bm->buffers_per_numa;
+  u32 buffers_per_numa = bm->buffers_per_numa[numa_node];
   clib_error_t *error;
   u32 buffer_size;
   uword n_pages, pagesize;
@@ -680,6 +680,9 @@
 			      "size (%llu)", buffer_size, pagesize);
 
   if (buffers_per_numa == 0)
+    buffers_per_numa = bm->default_buffers_per_numa;
+
+  if (buffers_per_numa == 0)
     buffers_per_numa = unpriv ? VLIB_BUFFER_DEFAULT_BUFFERS_PER_NUMA_UNPRIV :
       VLIB_BUFFER_DEFAULT_BUFFERS_PER_NUMA;
 
@@ -906,18 +909,48 @@
 }
 
 static clib_error_t *
+vlib_buffers_numa_configure (vlib_buffer_main_t *bm, u32 numa_node,
+			     unformat_input_t *input)
+{
+  u32 buffers = 0;
+
+  if (numa_node >= VLIB_BUFFER_MAX_NUMA_NODES)
+    return clib_error_return (0, "invalid numa node");
+
+  if (!input)
+    return 0;
+
+  unformat_skip_white_space (input);
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "buffers %u", &buffers))
+	;
+      else
+	return unformat_parse_error (input);
+    }
+
+  bm->buffers_per_numa[numa_node] = buffers;
+  return 0;
+}
+
+static clib_error_t *
 vlib_buffers_configure (vlib_main_t * vm, unformat_input_t * input)
 {
   vlib_buffer_main_t *bm;
+  u32 numa_node;
+  unformat_input_t sub_input;
+  clib_error_t *error = 0;
 
   vlib_buffer_main_alloc (vm);
 
   bm = vm->buffer_main;
   bm->log2_page_size = CLIB_MEM_PAGE_SZ_UNKNOWN;
+  memset (bm->buffers_per_numa, 0, sizeof (bm->buffers_per_numa));
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (input, "buffers-per-numa %u", &bm->buffers_per_numa))
+      if (unformat (input, "buffers-per-numa %u",
+		    &bm->default_buffers_per_numa))
 	;
       else if (unformat (input, "page-size %U", unformat_log2_page_size,
 			 &bm->log2_page_size))
@@ -925,6 +958,15 @@
       else if (unformat (input, "default data-size %u",
 			 &bm->default_data_size))
 	;
+      else if (unformat (input, "numa %u %U", &numa_node,
+			 unformat_vlib_cli_sub_input, &sub_input))
+	{
+	  error = vlib_buffers_numa_configure (bm, numa_node, &sub_input);
+	  unformat_free (&sub_input);
+
+	  if (error)
+	    return error;
+	}
       else
 	return unformat_parse_error (input);
     }