+/* Reads the cpu mask configuration from 'cmask' and sets the
+ * 'available' of corresponding cores. For unspecified cores,
+ * sets 'available' to false. */
+void
+ovs_numa_set_cpu_mask(const char *cmask)
+{
+ int core_id = 0;
+ int i;
+
+ if (!found_numa_and_core) {
+ return;
+ }
+
+ /* If no mask specified, resets the 'available' to true for all cores. */
+ if (!cmask) {
+ struct cpu_core *core;
+
+ HMAP_FOR_EACH(core, hmap_node, &all_cpu_cores) {
+ core->available = true;
+ }
+
+ return;
+ }
+
+ for (i = strlen(cmask) - 1; i >= 0; i--) {
+ char hex = toupper(cmask[i]);
+ int bin, j;
+
+ if (hex >= '0' && hex <= '9') {
+ bin = hex - '0';
+ } else if (hex >= 'A' && hex <= 'F') {
+ bin = hex - 'A' + 10;
+ } else {
+ bin = 0;
+ VLOG_WARN("Invalid cpu mask: %c", cmask[i]);
+ }
+
+ for (j = 0; j < 4; j++) {
+ struct cpu_core *core;
+
+ core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
+ hash_int(core_id++, 0)),
+ struct cpu_core, hmap_node);
+ core->available = (bin >> j) & 0x1;
+
+ if (core_id >= hmap_count(&all_cpu_cores)) {
+ return;
+ }
+ }
+ }
+
+ /* For unspecified cores, sets 'available' to false. */
+ while (core_id < hmap_count(&all_cpu_cores)) {
+ struct cpu_core *core;
+
+ core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
+ hash_int(core_id++, 0)),
+ struct cpu_core, hmap_node);
+ core->available = false;
+ }
+}
+