Here's a proposal for the new renamed cpuset API. Non trivial changes include: hwloc_cpuset_from_string -> hwloc_bitmap_sscanf hwloc_cpuset_cpu -> hwloc_bitmap_setonly hwloc_bitmap_all_but_cpu -> hwloc_bitmap_allbut
My plan would be to: * commit the attached file as hwloc/bitmap.h * drop everything from hwloc/cpuset.h, add a big deprecation warning in the header, make it include bitmap.h, and add typedef/#define for API backward compat * port all the internals to the new API * only #include bitmap.h internally * add ABI aliases at the end of src/cpuset.c (don't know if it's worth renaming this file) By the way, what's the proper way to do the latter? #pragma weak hwloc_cpuset_foo = hwloc_bitmap_foo ? use __hwloc_attribute_alias instead ? Brice
/* * Copyright © 2009 CNRS, INRIA, Université Bordeaux 1 * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. */ /** \file * \brief The bitmap API, for use in hwloc itself. */ #ifndef HWLOC_BITMAP_H #define HWLOC_BITMAP_H #include <hwloc/config.h> #ifdef __cplusplus extern "C" { #endif /** \defgroup hwlocality_bitmap The bitmap API * * For use in hwloc itself, a hwloc_bitmap_t usually represents a set of * objects, typically logical processors or memory nodes, indexed by OS * physical number. * * A bitmap may be infinite. * @{ */ /** \brief * Set of bits represented as an opaque pointer to an internal bitmap. */ typedef struct hwloc_bitmap_s * hwloc_bitmap_t; typedef const struct hwloc_bitmap_s * hwloc_const_bitmap_t; /* * Bitmap allocation, freeing and copying. */ /** \brief Allocate a new empty bitmap. * * \returns A valid bitmap or NULL. * * The bitmap should be freed by a corresponding call to * hwloc_bitmap_free(). */ HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc(void) __hwloc_attribute_malloc; /** \brief Free bitmap \p bitmap */ HWLOC_DECLSPEC void hwloc_bitmap_free(hwloc_bitmap_t bitmap); /** \brief Duplicate bitmap \p bitmap by allocating a new bitmap and copying \p bitmap contents */ HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap) __hwloc_attribute_malloc; /** \brief Copy the contents of bitmap \p src into the already allocated bitmap \p dst */ HWLOC_DECLSPEC void hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src); /* * Bitmap/String Conversion */ /** \brief Stringify a bitmap. * * Up to \p buflen characters may be written in buffer \p buf. * * \return the number of character that were actually written if not truncating, * or that would have been written (not including the ending \\0). */ HWLOC_DECLSPEC int hwloc_bitmap_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap); /** \brief Stringify a bitmap into a newly allocated string. * * \return the number of character that were actually written * (not including the ending \\0). */ HWLOC_DECLSPEC int hwloc_bitmap_asprintf(char ** strp, hwloc_const_bitmap_t bitmap); /** \brief Parse a bitmap string and stores it in bitmap \p bitmap. * * Must start and end with a digit. */ HWLOC_DECLSPEC int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string); /** \brief Stringify a bitmap in the taskset-specific format. * * The taskset command manipulates bitmap strings that contain a single * (possible very long) hexadecimal number starting with 0x. */ HWLOC_DECLSPEC int hwloc_bitmap_taskset_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap); /** \brief Stringify a bitmap into a newly allocated taskset-specific string. */ HWLOC_DECLSPEC int hwloc_bitmap_taskset_asprintf(char ** strp, hwloc_const_bitmap_t bitmap); /** \brief Parse a taskset-specific bitmap string and stores it in bitmap \p bitmap. */ HWLOC_DECLSPEC int hwloc_bitmap_taskset_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string); /* * Primitives & macros for building, modifying and consulting bitmaps. */ /** \brief Empty the bitmap \p bitmap */ HWLOC_DECLSPEC void hwloc_bitmap_zero(hwloc_bitmap_t bitmap); /** \brief Fill bitmap \p bitmap with all possible indexes (even if those objects don't exist or are otherwise unavailable) */ HWLOC_DECLSPEC void hwloc_bitmap_fill(hwloc_bitmap_t bitmap); /** \brief Setup bitmap \p bitmap from unsigned long \p mask */ HWLOC_DECLSPEC void hwloc_bitmap_from_ulong(hwloc_bitmap_t bitmap, unsigned long mask); /** \brief Setup bitmap \p bitmap from unsigned long \p mask used as \p i -th subset */ HWLOC_DECLSPEC void hwloc_bitmap_from_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask); /** \brief Convert the beginning part of bitmap \p bitmap into unsigned long \p mask */ HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ulong(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure; /** \brief Convert the \p i -th subset of bitmap \p bitmap into unsigned long mask */ HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ith_ulong(hwloc_const_bitmap_t bitmap, unsigned i) __hwloc_attribute_pure; /** \brief Empty the bitmap \p bitmap and add bit \p index */ HWLOC_DECLSPEC void hwloc_bitmap_setonly(hwloc_bitmap_t bitmap, unsigned index); /** \brief Fill the bitmap \p and clear the index \p index */ HWLOC_DECLSPEC void hwloc_bitmap_allbut(hwloc_bitmap_t bitmap, unsigned index); /** \brief Add index \p index in bitmap \p bitmap */ HWLOC_DECLSPEC void hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned index); /** \brief Add indexess from \p begin to \p end in bitmap \p bitmap */ HWLOC_DECLSPEC void hwloc_bitmap_set_range(hwloc_bitmap_t bitmap, unsigned begin, unsigned end); /** \brief Replace \p i -th subset of bitmap \p bitmap with unsigned long \p mask */ HWLOC_DECLSPEC void hwloc_bitmap_set_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask); /** \brief Remove index \p index from bitmap \p bitmap */ HWLOC_DECLSPEC void hwloc_bitmap_clr(hwloc_bitmap_t bitmap, unsigned index); /** \brief Remove index from \p begin to \p end in bitmap \p bitmap */ HWLOC_DECLSPEC void hwloc_bitmap_clr_range(hwloc_bitmap_t bitmap, unsigned begin, unsigned end); /** \brief Test whether index \p index is part of bitmap \p bitmap */ HWLOC_DECLSPEC int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned index) __hwloc_attribute_pure; /** \brief Test whether bitmap \p bitmap is empty */ HWLOC_DECLSPEC int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure; /** \brief Test whether bitmap \p bitmap is completely full */ HWLOC_DECLSPEC int hwloc_bitmap_isfull(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure; /** \brief Test whether bitmap \p bitmap1 is equal to bitmap \p bitmap2 */ HWLOC_DECLSPEC int hwloc_bitmap_isequal (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure; /** \brief Test whether bitmaps \p bitmap1 and \p bitmap2 intersects */ HWLOC_DECLSPEC int hwloc_bitmap_intersects (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure; /** \brief Test whether bitmap \p sub_bitmap is part of bitmap \p super_bitmap */ HWLOC_DECLSPEC int hwloc_bitmap_isincluded (hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap) __hwloc_attribute_pure; /** \brief Or bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res */ HWLOC_DECLSPEC void hwloc_bitmap_or (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2); /** \brief And bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res */ HWLOC_DECLSPEC void hwloc_bitmap_and (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2); /** \brief And bitmap \p bitmap1 and the negation of \p bitmap2 and store the result in bitmap \p res */ HWLOC_DECLSPEC void hwloc_bitmap_andnot (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2); /** \brief Xor bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res */ HWLOC_DECLSPEC void hwloc_bitmap_xor (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2); /** \brief Negate bitmap \p bitmap and store the result in bitmap \p res */ HWLOC_DECLSPEC void hwloc_bitmap_not (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap); /** \brief Compute the first index (least significant bit) in bitmap \p bitmap * * \return -1 if no index is set. */ HWLOC_DECLSPEC int hwloc_bitmap_first(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure; /** \brief Compute the last index (most significant bit) in bitmap \p bitmap * * \return -1 if no index is bitmap, or if the index bitmap is infinite. */ HWLOC_DECLSPEC int hwloc_bitmap_last(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure; /** \brief Compute the next index in bitmap \p bitmap which is after index \p prev * * \return -1 if no index with higher index is bitmap. */ HWLOC_DECLSPEC int hwloc_bitmap_next(hwloc_const_bitmap_t bitmap, unsigned prev) __hwloc_attribute_pure; /** \brief Keep a single index among those set in bitmap \p bitmap * * May be useful before binding so that the process does not * have a chance of migrating between multiple logical CPUs * in the original mask. */ HWLOC_DECLSPEC void hwloc_bitmap_singlify(hwloc_bitmap_t bitmap); /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 using their lowest index. * * Smaller least significant bit is smaller. * The empty bitmap is considered higher than anything. */ HWLOC_DECLSPEC int hwloc_bitmap_compare_first(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure; /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 using their highest index. * * Higher most significant bit is higher. * The empty bitmap is considered lower than anything. */ HWLOC_DECLSPEC int hwloc_bitmap_compare(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure; /** \brief Compute the "weight" of bitmap \p bitmap (i.e., number of * indexes that are in the bitmap). * * \return the number of indexes that are in the bitmap. */ HWLOC_DECLSPEC int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure; /** \brief Loop macro iterating on bitmap \p bitmap * \hideinitializer * * \p index is the loop variable; it should be an unsigned int. The * first iteration will set \p index to the lowest index in the bitmap. * Successive iterations will iterate through, in order, all remaining * indexes that in the bitmap. To be specific: each iteration will return a * value for \p index such that hwloc_bitmap_isset(bitmap, index) is true. * * The loop is infinite if the bitmap is infinite. */ #define hwloc_bitmap_foreach_begin(index, bitmap) \ do { \ for (index = hwloc_bitmap_first(bitmap); \ (unsigned) index != (unsigned) -1; \ index = hwloc_bitmap_next(bitmap, index)) { \ /** \brief End of loop. Needs a terminating ';'. * \hideinitializer * * \sa hwloc_bitmap_foreach_begin */ #define hwloc_bitmap_foreach_end() \ } \ } while (0) /** @} */ #ifdef __cplusplus } /* extern "C" */ #endif #endif /* HWLOC_BITMAP_H */