vppinfra: numa vector placement support
[vpp.git] / src / vlib / threads_cli.c
index ee63227..bcb85ec 100644 (file)
 #include <vlib/threads.h>
 #include <vlib/unix/unix.h>
 
-#if DPDK==1
-#include <rte_config.h>
-#include <rte_common.h>
-#include <rte_eal.h>
-#include <rte_launch.h>
-#include <rte_lcore.h>
-#endif
-
 static u8 *
 format_sched_policy_and_priority (u8 * s, va_list * args)
 {
@@ -71,74 +63,16 @@ show_threads_fn (vlib_main_t * vm,
 
       line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp);
 
-      int lcore = -1;
-      cpu_set_t cpuset;
-      CPU_ZERO (&cpuset);
-      int ret = -1;
-
-      ret =
-       pthread_getaffinity_np (w->thread_id, sizeof (cpu_set_t), &cpuset);
-      if (!ret)
-       {
-         int c;
-         for (c = 0; c < CPU_SETSIZE; c++)
-           if (CPU_ISSET (c, &cpuset))
-             {
-               if (lcore > -1)
-                 {
-                   lcore = -2;
-                   break;
-                 }
-               lcore = c;
-             }
-       }
-      else
-       {
-         lcore = w->lcore_id;
-       }
-
-      if (lcore > -1)
+      int cpu_id = w->cpu_id;
+      if (cpu_id > -1)
        {
-         const char *sys_cpu_path = "/sys/devices/system/cpu/cpu";
-         int socket_id = -1;
-         int core_id = -1;
-         u8 *p = 0;
-
-         p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, lcore, 0);
-         vlib_sysfs_read ((char *) p, "%d", &core_id);
-
-         vec_reset_length (p);
-         p =
-           format (p,
-                   "%s%u/topology/physical_package_id%c",
-                   sys_cpu_path, lcore, 0);
-         vlib_sysfs_read ((char *) p, "%d", &socket_id);
-         vec_free (p);
-
-         line = format (line, "%-7u%-7u%-7u%", lcore, core_id, socket_id);
-#if DPDK==1
-         ASSERT (lcore <= RTE_MAX_LCORE);
-         switch (lcore_config[lcore].state)
-           {
-           case WAIT:
-             line = format (line, "wait");
-             break;
-           case RUNNING:
-             line = format (line, "running");
-             break;
-           case FINISHED:
-             line = format (line, "finished");
-             break;
-           default:
-             line = format (line, "unknown");
-           }
-#endif
+         int core_id = w->core_id;
+         int numa_id = w->numa_id;
+         line = format (line, "%-7u%-7u%-7u%", cpu_id, core_id, numa_id);
        }
       else
        {
-         line =
-           format (line, "%-7s%-7s%-7s%", (lcore == -2) ? "M" : "n/a", "n/a",
-                   "n/a");
+         line = format (line, "%-7s%-7s%-7s%", "n/a", "n/a", "n/a");
        }
 
       vlib_cli_output (vm, "%v", line);
@@ -185,24 +119,34 @@ trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
        enable = 1;
       else if (unformat (line_input, "off"))
        enable = 0;
-      else if (unformat (line_input, "index %u"), &index)
+      else if (unformat (line_input, "index %u", &index))
        ;
       else
-       return clib_error_return (0, "parse error: '%U'",
-                                 format_unformat_error, line_input);
+       {
+         error = clib_error_return (0, "parse error: '%U'",
+                                    format_unformat_error, line_input);
+         goto done;
+       }
     }
 
-  unformat_free (line_input);
-
   if (enable > 1)
-    return clib_error_return (0, "expecting on or off");
+    {
+      error = clib_error_return (0, "expecting on or off");
+      goto done;
+    }
 
   if (vec_len (tm->frame_queue_mains) == 0)
-    return clib_error_return (0, "no worker handoffs exist");
+    {
+      error = clib_error_return (0, "no worker handoffs exist");
+      goto done;
+    }
 
   if (index > vec_len (tm->frame_queue_mains) - 1)
-    return clib_error_return (0,
-                             "expecting valid worker handoff queue index");
+    {
+      error = clib_error_return (0,
+                                "expecting valid worker handoff queue index");
+      goto done;
+    }
 
   fqm = vec_elt_at_index (tm->frame_queue_mains, index);
 
@@ -210,7 +154,7 @@ trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
   if (num_fq == 0)
     {
       vlib_cli_output (vm, "No frame queues exist\n");
-      return error;
+      goto done;
     }
 
   // Allocate storage for trace if necessary
@@ -224,11 +168,15 @@ trace_frame_queue (vlib_main_t * vm, unformat_input_t * input,
       fqt = &fqm->frame_queue_traces[fqix];
       fqh = &fqm->frame_queue_histogram[fqix];
 
-      memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors));
+      clib_memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors));
       fqt->written = 0;
-      memset (fqh, 0, sizeof (*fqh));
+      clib_memset (fqh, 0, sizeof (*fqh));
       fqm->vlib_frame_queues[fqix]->trace = enable;
     }
+
+done:
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -457,28 +405,33 @@ test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input,
       else if (unformat (line_input, "index %u", &index))
        ;
       else
-       return clib_error_return (0, "parse error: '%U'",
-                                 format_unformat_error, line_input);
+       {
+         error = clib_error_return (0, "parse error: '%U'",
+                                    format_unformat_error, line_input);
+         goto done;
+       }
     }
 
-  unformat_free (line_input);
-
   if (index > vec_len (tm->frame_queue_mains) - 1)
-    return clib_error_return (0,
-                             "expecting valid worker handoff queue index");
+    {
+      error = clib_error_return (0,
+                                "expecting valid worker handoff queue index");
+      goto done;
+    }
 
   fqm = vec_elt_at_index (tm->frame_queue_mains, index);
 
   if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32))
     {
-      return clib_error_return (0, "expecting 4,8,16,32");
+      error = clib_error_return (0, "expecting 4,8,16,32");
+      goto done;
     }
 
   num_fq = vec_len (fqm->vlib_frame_queues);
   if (num_fq == 0)
     {
       vlib_cli_output (vm, "No frame queues exist\n");
-      return error;
+      goto done;
     }
 
   for (fqix = 0; fqix < num_fq; fqix++)
@@ -486,6 +439,9 @@ test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input,
       fqm->vlib_frame_queues[fqix]->nelts = nelts;
     }
 
+done:
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -524,15 +480,19 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
       else if (unformat (line_input, "index %u", &index))
        ;
       else
-       return clib_error_return (0, "parse error: '%U'",
-                                 format_unformat_error, line_input);
+       {
+         error = clib_error_return (0, "parse error: '%U'",
+                                    format_unformat_error, line_input);
+         goto done;
+       }
     }
 
-  unformat_free (line_input);
-
   if (index > vec_len (tm->frame_queue_mains) - 1)
-    return clib_error_return (0,
-                             "expecting valid worker handoff queue index");
+    {
+      error = clib_error_return (0,
+                                "expecting valid worker handoff queue index");
+      goto done;
+    }
 
   fqm = vec_elt_at_index (tm->frame_queue_mains, index);
 
@@ -540,7 +500,7 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
   if (threshold == ~(u32) 0)
     {
       vlib_cli_output (vm, "expecting threshold value\n");
-      return error;
+      goto done;
     }
 
   if (threshold == 0)
@@ -550,7 +510,7 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
   if (num_fq == 0)
     {
       vlib_cli_output (vm, "No frame queues exist\n");
-      return error;
+      goto done;
     }
 
   for (fqix = 0; fqix < num_fq; fqix++)
@@ -558,6 +518,9 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input,
       fqm->vlib_frame_queues[fqix]->vector_threshold = threshold;
     }
 
+done:
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -569,7 +532,6 @@ VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = {
 };
 /* *INDENT-ON* */
 
-
 /*
  * fd.io coding-style-patch-verification: ON
  *