This commit adds function in ovs-numa module which allows users to query the pinned cores on a numa node by providing the numa node id and a pre-allocated bitmap. The ovs-numa module will set the bit in bitmap for each pinned core.
Signed-off-by: Alex Wang <al...@nicira.com> --- lib/ovs-numa.c | 23 +++++++++++++++++++++++ lib/ovs-numa.h | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c index 26ab3cf..c62bfc4 100644 --- a/lib/ovs-numa.c +++ b/lib/ovs-numa.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <unistd.h> +#include "bitmap.h" #include "hash.h" #include "hmap.h" #include "list.h" @@ -47,6 +48,8 @@ VLOG_DEFINE_THIS_MODULE(ovs_numa); * user can assume core ids from 0 to N-1 are all valid and there is a * 'struct cpu_core' for each id. * + * NOTE, this module should only be used by the main thread. + * * NOTE, the assumption above will fail when cpu hotplug is used. In that * case ovs-numa will not function correctly. For now, add a TODO entry * for addressing it in the future. @@ -326,6 +329,26 @@ ovs_numa_unpin_core(int core_id) } } +/* Given the 'numa_id' and pre-allocated bitmap 'bm', returns the map + * of all pinned cores on the numa node. */ +void +ovs_numa_get_pinned_cores_on_numa(int numa_id, unsigned long *bm) +{ + if (bm && ovs_numa_numa_id_is_valid(numa_id)) { + struct numa_node *numa; + struct cpu_core *core; + + numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes, + hash_int(numa_id, 0)), + struct numa_node, hmap_node); + LIST_FOR_EACH(core, list_node, &numa->cores) { + if (core->pinned) { + bitmap_set1(bm, core->core_id); + } + } + } +} + /* Reads the cpu mask configuration from 'cmask' and sets the * 'available' of corresponding cores. For unspecified cores, * sets 'available' to false. */ diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h index fab2546..9a622bc 100644 --- a/lib/ovs-numa.h +++ b/lib/ovs-numa.h @@ -40,6 +40,7 @@ bool ovs_numa_try_pin_core_specific(int core_id); int ovs_numa_get_unpinned_core_any(void); int ovs_numa_get_unpinned_core_on_numa(int numa_id); void ovs_numa_unpin_core(int core_id); +void ovs_numa_get_pinned_cores_on_numa(int numa_id, unsigned long *map); #else @@ -121,5 +122,12 @@ ovs_numa_unpin_core(int core_id OVS_UNUSED) /* Nothing */ } +static inline void +ovs_numa_get_pinned_cores_on_numa(int numa_id OVS_UNUSED, + unsigned long *map OVS_UNUSED) +{ + /* Nothing */ +} + #endif /* __linux__ */ #endif /* ovs-thead.h */ -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev