Improve cpu { coremask-% } configure option 96/13696/3
authorYi He <yi.he@arm.com>
Tue, 17 Jul 2018 06:18:41 +0000 (14:18 +0800)
committerDamjan Marion <dmarion@me.com>
Wed, 1 Aug 2018 20:41:04 +0000 (20:41 +0000)
Accept any sized hexadecimal bitmask specification to
support platforms with hundreds of cores.

Change-Id: Ib881db0cf60f78bdeffa13acfc2fc7fe7e128cc4
Signed-off-by: Yi He <yi.he@arm.com>
src/vlib/threads.c
src/vppinfra/bitmap.h

index 70f22b1..8e75592 100644 (file)
@@ -1267,7 +1267,6 @@ cpu_config (vlib_main_t * vm, unformat_input_t * input)
   uword *p;
   vlib_thread_main_t *tm = &vlib_thread_main;
   u8 *name;
-  u64 coremask;
   uword *bitmap;
   u32 count;
 
@@ -1296,25 +1295,10 @@ cpu_config (vlib_main_t * vm, unformat_input_t * input)
        ;
       else if (unformat (input, "skip-cores %u", &tm->skip_cores))
        ;
-      else if (unformat (input, "coremask-%s %llx", &name, &coremask))
-       {
-         p = hash_get_mem (tm->thread_registrations_by_name, name);
-         if (p == 0)
-           return clib_error_return (0, "no such thread type '%s'", name);
-
-         tr = (vlib_thread_registration_t *) p[0];
-
-         if (tr->use_pthreads)
-           return clib_error_return (0,
-                                     "coremask cannot be set for '%s' threads",
-                                     name);
-
-         tr->coremask = clib_bitmap_set_multiple
-           (tr->coremask, 0, coremask, BITS (coremask));
-         tr->count = clib_bitmap_count_set_bits (tr->coremask);
-       }
-      else if (unformat (input, "corelist-%s %U", &name, unformat_bitmap_list,
-                        &bitmap))
+      else if (unformat (input, "coremask-%s %U", &name,
+                        unformat_bitmap_mask, &bitmap) ||
+              unformat (input, "corelist-%s %U", &name,
+                        unformat_bitmap_list, &bitmap))
        {
          p = hash_get_mem (tm->thread_registrations_by_name, name);
          if (p == 0)
index 0e94d02..4f34007 100644 (file)
@@ -735,6 +735,42 @@ clib_bitmap_next_clear (uword * ai, uword i)
   return i;
 }
 
+/** unformat an any sized hexadecimal bitmask into a bitmap
+
+    uword * bitmap;
+    rv = unformat ("%U", unformat_bitmap_mask, &bitmap);
+
+    Standard unformat_function_t arguments
+
+    @param input - pointer an unformat_input_t
+    @param va - varargs list comprising a single uword **
+    @returns 1 on success, 0 on failure
+*/
+static inline uword
+unformat_bitmap_mask (unformat_input_t * input, va_list * va)
+{
+  u8 *v = 0;                   /* hexadecimal vector */
+  uword **bitmap_return = va_arg (*va, uword **);
+  uword *bitmap = 0;
+
+  if (unformat (input, "%U", unformat_hex_string, &v))
+    {
+      int i, s = vec_len (v) - 1;      /* 's' for significance or shift */
+
+      /* v[0] holds the most significant byte */
+      for (i = 0; s >= 0; i++, s--)
+       bitmap = clib_bitmap_set_multiple (bitmap,
+                                          s * BITS (v[i]), v[i],
+                                          BITS (v[i]));
+
+      vec_free (v);
+      *bitmap_return = bitmap;
+      return 1;
+    }
+
+  return 0;
+}
+
 /** unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
 
     uword * bitmap;