Re: [ovs-dev] [PATCH v3 13/18] ovs-numa: Add new dump types.

2017-01-13 Thread Ben Pfaff
On Sun, Jan 08, 2017 at 07:15:11PM -0800, Daniele Di Proietto wrote:
> They will be used by a future commit.
> 
> This patch introduces some code duplication which will be removed in a
> future commit.
> 
> Signed-off-by: Daniele Di Proietto 

The hexit_value() function might help, in
ovs_numa_dump_cores_with_cmask().


___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH v3 13/18] ovs-numa: Add new dump types.

2017-01-08 Thread Daniele Di Proietto
They will be used by a future commit.

This patch introduces some code duplication which will be removed in a
future commit.

Signed-off-by: Daniele Di Proietto 
---
 lib/ovs-numa.c | 78 ++
 lib/ovs-numa.h |  4 ++-
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c
index 85f392a91..61c31cf69 100644
--- a/lib/ovs-numa.c
+++ b/lib/ovs-numa.c
@@ -512,6 +512,84 @@ ovs_numa_dump_cores_on_numa(int numa_id)
 return dump;
 }
 
+struct ovs_numa_dump *
+ovs_numa_dump_cores_with_cmask(const char *cmask)
+{
+struct ovs_numa_dump *dump = xmalloc(sizeof *dump);
+int core_id = 0;
+int end_idx;
+
+hmap_init(>dump);
+
+/* Ignore leading 0x. */
+end_idx = 0;
+if (!strncmp(cmask, "0x", 2) || !strncmp(cmask, "0X", 2)) {
+end_idx = 2;
+}
+
+for (int i = strlen(cmask) - 1; i >= end_idx; i--) {
+char hex = toupper((unsigned char) cmask[i]);
+int bin, j;
+
+if (hex >= '0' && hex <= '9') {
+bin = hex - '0';
+} else if (hex >= 'A' && hex <= 'F') {
+bin = hex - 'A' + 10;
+} else {
+VLOG_WARN("Invalid cpu mask: %c", cmask[i]);
+bin = 0;
+}
+
+for (j = 0; j < 4; j++) {
+if ((bin >> j) & 0x1) {
+struct cpu_core *core = get_core_by_core_id(core_id);
+
+if (core) {
+struct ovs_numa_info *info = xmalloc(sizeof *info);
+
+info->numa_id = core->numa->numa_id;
+info->core_id = core->core_id;
+hmap_insert(>dump, >hmap_node,
+hash_2words(info->numa_id, info->core_id));
+}
+}
+
+core_id++;
+}
+}
+
+return dump;
+}
+
+struct ovs_numa_dump *
+ovs_numa_dump_n_cores_per_numa(int cores_per_numa)
+{
+struct ovs_numa_dump *dump = xmalloc(sizeof *dump);
+const struct numa_node *n;
+
+hmap_init(>dump);
+
+HMAP_FOR_EACH (n, hmap_node, _numa_nodes) {
+const struct cpu_core *core;
+int i = 0;
+
+LIST_FOR_EACH (core, list_node, >cores) {
+if (i++ >= cores_per_numa) {
+break;
+}
+
+struct ovs_numa_info *info = xmalloc(sizeof *info);
+
+info->numa_id = core->numa->numa_id;
+info->core_id = core->core_id;
+hmap_insert(>dump, >hmap_node,
+hash_2words(info->numa_id, info->core_id));
+}
+}
+
+return dump;
+}
+
 bool
 ovs_numa_dump_contains_core(const struct ovs_numa_dump *dump,
 int numa_id, unsigned core_id)
diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h
index c0eae07d8..62bdb225f 100644
--- a/lib/ovs-numa.h
+++ b/lib/ovs-numa.h
@@ -54,12 +54,14 @@ unsigned ovs_numa_get_unpinned_core_any(void);
 unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id);
 void ovs_numa_unpin_core(unsigned core_id);
 struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id);
+struct ovs_numa_dump *ovs_numa_dump_cores_with_cmask(const char *cmask);
+struct ovs_numa_dump *ovs_numa_dump_n_cores_per_numa(int n);
 bool ovs_numa_dump_contains_core(const struct ovs_numa_dump *,
  int numa_id, unsigned core_id);
 void ovs_numa_dump_destroy(struct ovs_numa_dump *);
 int ovs_numa_thread_setaffinity_core(unsigned core_id);
 
-#define FOR_EACH_CORE_ON_NUMA(ITER, DUMP)\
+#define FOR_EACH_CORE_ON_DUMP(ITER, DUMP)\
 HMAP_FOR_EACH((ITER), hmap_node, &(DUMP)->dump)
 
 #endif /* ovs-numa.h */
-- 
2.11.0

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev