From 5e5f272b744d9da8511dba2bb4e05d2d6a0550aa Mon Sep 17 00:00:00 2001 From: Danny Auble <da@schedmd.com> Date: Tue, 1 May 2012 11:03:37 -0700 Subject: [PATCH] Simplify the way the hwloc_cpuset_t to hwloc_bitmap_t conversion is handled. --- src/plugins/task/cgroup/task_cgroup_cpuset.c | 58 +++++++++++++------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/plugins/task/cgroup/task_cgroup_cpuset.c b/src/plugins/task/cgroup/task_cgroup_cpuset.c index a6615e71898..a7667bede7e 100644 --- a/src/plugins/task/cgroup/task_cgroup_cpuset.c +++ b/src/plugins/task/cgroup/task_cgroup_cpuset.c @@ -59,6 +59,38 @@ #ifdef HAVE_HWLOC #include <hwloc.h> #include <hwloc/glibc-sched.h> + +# if HWLOC_API_VERSION <= 0x00010000 +/* after this version the cpuset structure and all it's functions + * changed to bitmaps. So to work with old hwloc's we just to the + * opposite to avoid having to put a bunch of ifdef's in the code we + * just do it here. + */ +typedef hwloc_cpuset_t hwloc_bitmap_t; + +static inline hwloc_bitmap_t hwloc_bitmap_alloc(void) +{ + return hwloc_cpuset_alloc(); +} + +static inline void hwloc_bitmap_free(hwloc_bitmap_t bitmap) +{ + hwloc_cpuset_free(bitmap); +} + +static inline void hwloc_bitmap_or( + hwloc_bitmap_t res, hwloc_bitmap_t bitmap1, hwloc_bitmap_t bitmap2) +{ + hwloc_cpuset_or(res, bitmap1, bitmap2); +} + +static inline int hwloc_bitmap_asprintf(char **str, hwloc_bitmap_t bitmap) +{ + return hwloc_cpuset_asprintf(str, bitmap); +} + +# endif + #endif #ifndef PATH_MAX @@ -704,11 +736,7 @@ extern int task_cgroup_cpuset_set_task_affinity(slurmd_job_t *job) int bind_verbose; hwloc_topology_t topology; -#if HWLOC_API_VERSION <= 0x00010000 - hwloc_cpuset_t cpuset; -#else hwloc_bitmap_t cpuset; -#endif hwloc_obj_type_t hwtype; hwloc_obj_type_t req_hwtype; @@ -722,11 +750,9 @@ extern int task_cgroup_cpuset_set_task_affinity(slurmd_job_t *job) /* Allocate and initialize hwloc objects */ hwloc_topology_init(&topology); -#if HWLOC_API_VERSION <= 0x00010000 - cpuset = hwloc_cpuset_alloc() ; -#else - cpuset = hwloc_bitmap_alloc() ; -#endif + + cpuset = hwloc_bitmap_alloc(); + hwloc_topology_load(topology); if ( hwloc_get_type_depth(topology, HWLOC_OBJ_NODE) > hwloc_get_type_depth(topology, HWLOC_OBJ_SOCKET) ) { @@ -842,6 +868,7 @@ extern int task_cgroup_cpuset_set_task_affinity(slurmd_job_t *job) "affinity",taskid,hwloc_obj_type_string(hwtype)); } else { + char *str; if (bind_verbose) { info("task/cgroup: task[%u] using %s granularity", @@ -860,12 +887,8 @@ extern int task_cgroup_cpuset_set_task_affinity(slurmd_job_t *job) req_hwtype, nobj, job, bind_verbose, cpuset); } - char *str; -#if HWLOC_API_VERSION <= 0x00010000 - hwloc_cpuset_asprintf(&str,cpuset); -#else - hwloc_bitmap_asprintf(&str,cpuset); -#endif + hwloc_bitmap_asprintf(&str, cpuset); + tssize = sizeof(cpu_set_t); if (hwloc_cpuset_to_glibc_sched_affinity(topology,cpuset, &ts,tssize) == 0) { @@ -887,11 +910,8 @@ extern int task_cgroup_cpuset_set_task_affinity(slurmd_job_t *job) } /* Destroy hwloc objects */ -#if HWLOC_API_VERSION <= 0x00010000 - hwloc_cpuset_free(cpuset); -#else hwloc_bitmap_free(cpuset); -#endif + hwloc_topology_destroy(topology); return fstatus; -- GitLab