Commit 29ad06b4 authored by Victor Lopez's avatar Victor Lopez

Implement hwloc methods to obtain cpusets of cores

parent 75fccc05
......@@ -21,6 +21,7 @@
#include "debug.hpp"
#ifdef HWLOC
#include <hwloc/glibc-sched.h>
#ifdef GPU_DEV
#include <hwloc/cudart.h>
#endif
......@@ -176,4 +177,42 @@ bool Hwloc::isCpuAvailable( unsigned int cpu ) const
return hwloc_get_pu_obj_by_os_index( _hwlocTopology, cpu ) != NULL;
#endif
}
CpuSet Hwloc::getCoreCpusetOf( unsigned int cpu )
{
CpuSet core_cpuset;
#ifdef HWLOC
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index( _hwlocTopology, cpu );
hwloc_obj_t core = hwloc_get_ancestor_obj_by_type( _hwlocTopology, HWLOC_OBJ_CORE, pu );
hwloc_cpuset_to_glibc_sched_affinity( _hwlocTopology, core->cpuset,
core_cpuset.get_cpu_set_pointer(), sizeof(cpu_set_t));
#endif
return core_cpuset;
}
std::list<CpuSet> Hwloc::getCoreCpusetsOf( const CpuSet& parent )
{
std::list<CpuSet> core_cpusets;
#ifdef HWLOC
// Covert parent cpuset to hwlocset
hwloc_cpuset_t hwlocset = hwloc_bitmap_alloc();
hwloc_cpuset_from_glibc_sched_affinity( _hwlocTopology, hwlocset,
parent.get_cpu_set_pointer(), sizeof(cpu_set_t));
// Iterate cores inside parent cpuset
hwloc_obj_t core = NULL;
while ( (core = hwloc_get_next_obj_inside_cpuset_by_type(
_hwlocTopology, hwlocset, HWLOC_OBJ_CORE, core)) != NULL ) {
CpuSet core_cpuset;
hwloc_cpuset_to_glibc_sched_affinity( _hwlocTopology, core->cpuset,
core_cpuset.get_cpu_set_pointer(), sizeof(cpu_set_t));
// Append core cpuset to list
core_cpusets.push_back( core_cpuset );
}
hwloc_bitmap_free(hwlocset);
#endif
return core_cpusets;
}
}
......@@ -23,6 +23,7 @@
#include <config.hpp>
#include <string>
#include "cpuset.hpp"
#ifdef HWLOC
#include <hwloc.h>
......@@ -63,6 +64,8 @@ class Hwloc {
*/
bool isCpuAvailable( unsigned int cpu ) const;
CpuSet getCoreCpusetOf( unsigned int cpu );
std::list<CpuSet> getCoreCpusetsOf( const CpuSet& parent );
};
} // namespace nanos
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment