diff --git a/opal/class/opal_bitmap.c b/opal/class/opal_bitmap.c index d4e1e9f6b50..d113ed53537 100644 --- a/opal/class/opal_bitmap.c +++ b/opal/class/opal_bitmap.c @@ -23,35 +23,30 @@ #include "opal_config.h" -#include #include +#include -#include "opal/constants.h" #include "opal/class/opal_bitmap.h" +#include "opal/constants.h" /* The number of bits in the underlying type of the bitmap field * in the opal_bitmap_t struct */ -#define SIZE_OF_BASE_TYPE 64 +#define SIZE_OF_BASE_TYPE 64 static void opal_bitmap_construct(opal_bitmap_t *bm); static void opal_bitmap_destruct(opal_bitmap_t *bm); -OBJ_CLASS_INSTANCE(opal_bitmap_t, opal_object_t, - opal_bitmap_construct, opal_bitmap_destruct); - +OBJ_CLASS_INSTANCE(opal_bitmap_t, opal_object_t, opal_bitmap_construct, opal_bitmap_destruct); -static void -opal_bitmap_construct(opal_bitmap_t *bm) +static void opal_bitmap_construct(opal_bitmap_t *bm) { bm->bitmap = NULL; bm->array_size = 0; bm->max_size = INT_MAX; } - -static void -opal_bitmap_destruct(opal_bitmap_t *bm) +static void opal_bitmap_destruct(opal_bitmap_t *bm) { if (NULL != bm->bitmap) { free(bm->bitmap); @@ -59,8 +54,7 @@ opal_bitmap_destruct(opal_bitmap_t *bm) } } - -int opal_bitmap_set_max_size (opal_bitmap_t *bm, int max_size) +int opal_bitmap_set_max_size(opal_bitmap_t *bm, int max_size) { if (NULL == bm) { return OPAL_ERR_BAD_PARAM; @@ -71,14 +65,12 @@ int opal_bitmap_set_max_size (opal_bitmap_t *bm, int max_size) * we set it (in numbers of bits!), otherwise it is * set to INT_MAX in the constructor. */ - bm->max_size = (int)(((size_t)max_size + SIZE_OF_BASE_TYPE - 1) / SIZE_OF_BASE_TYPE); + bm->max_size = (int) (((size_t) max_size + SIZE_OF_BASE_TYPE - 1) / SIZE_OF_BASE_TYPE); return OPAL_SUCCESS; } - -int -opal_bitmap_init(opal_bitmap_t *bm, int size) +int opal_bitmap_init(opal_bitmap_t *bm, int size) { /* * Only if the caller set the maximum size before initializing, @@ -89,13 +81,14 @@ opal_bitmap_init(opal_bitmap_t *bm, int size) return OPAL_ERR_BAD_PARAM; } - bm->array_size = (int)(((size_t)size + SIZE_OF_BASE_TYPE - 1) / SIZE_OF_BASE_TYPE); - if( NULL != bm->bitmap ) { + bm->array_size = (int) (((size_t) size + SIZE_OF_BASE_TYPE - 1) / SIZE_OF_BASE_TYPE); + if (NULL != bm->bitmap) { free(bm->bitmap); - if(bm->max_size < bm->array_size) + if (bm->max_size < bm->array_size) { bm->max_size = bm->array_size; + } } - bm->bitmap = (uint64_t*) malloc(bm->array_size * sizeof(uint64_t)); + bm->bitmap = (uint64_t *) malloc(bm->array_size * sizeof(uint64_t)); if (NULL == bm->bitmap) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -104,9 +97,7 @@ opal_bitmap_init(opal_bitmap_t *bm, int size) return OPAL_SUCCESS; } - -int -opal_bitmap_set_bit(opal_bitmap_t *bm, int bit) +int opal_bitmap_set_bit(opal_bitmap_t *bm, int bit) { int index, offset, new_size; @@ -124,12 +115,13 @@ opal_bitmap_set_bit(opal_bitmap_t *bm, int bit) valid and we simply expand the bitmap */ new_size = index + 1; - if( new_size > bm->max_size ) + if (new_size > bm->max_size) { new_size = bm->max_size; + } /* New size is just a multiple of the original size to fit in the index. */ - bm->bitmap = (uint64_t*)realloc(bm->bitmap, new_size*sizeof(uint64_t)); + bm->bitmap = (uint64_t *) realloc(bm->bitmap, new_size * sizeof(uint64_t)); if (NULL == bm->bitmap) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -147,9 +139,7 @@ opal_bitmap_set_bit(opal_bitmap_t *bm, int bit) return OPAL_SUCCESS; } - -int -opal_bitmap_clear_bit(opal_bitmap_t *bm, int bit) +int opal_bitmap_clear_bit(opal_bitmap_t *bm, int bit) { int index, offset; @@ -164,9 +154,7 @@ opal_bitmap_clear_bit(opal_bitmap_t *bm, int bit) return OPAL_SUCCESS; } - -bool -opal_bitmap_is_set_bit(opal_bitmap_t *bm, int bit) +bool opal_bitmap_is_set_bit(opal_bitmap_t *bm, int bit) { int index, offset; @@ -184,9 +172,7 @@ opal_bitmap_is_set_bit(opal_bitmap_t *bm, int bit) return false; } - -int -opal_bitmap_clear_all_bits(opal_bitmap_t *bm) +int opal_bitmap_clear_all_bits(opal_bitmap_t *bm) { if (NULL == bm) { return OPAL_ERR_BAD_PARAM; @@ -196,9 +182,7 @@ opal_bitmap_clear_all_bits(opal_bitmap_t *bm) return OPAL_SUCCESS; } - -int -opal_bitmap_set_all_bits(opal_bitmap_t *bm) +int opal_bitmap_set_all_bits(opal_bitmap_t *bm) { if (NULL == bm) { return OPAL_ERR_BAD_PARAM; @@ -209,9 +193,7 @@ opal_bitmap_set_all_bits(opal_bitmap_t *bm) return OPAL_SUCCESS; } - -int -opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, int *position) +int opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, int *position) { int i = 0; uint64_t temp, all_ones = 0xffffffffffffffffUL; @@ -222,7 +204,7 @@ opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, int *position) /* Neglect all which don't have an unset bit */ *position = 0; - while((i < bm->array_size) && (bm->bitmap[i] == all_ones)) { + while ((i < bm->array_size) && (bm->bitmap[i] == all_ones)) { ++i; } @@ -236,8 +218,8 @@ opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, int *position) temp = bm->bitmap[i]; bm->bitmap[i] |= (bm->bitmap[i] + 1); /* Set the first zero bit */ - temp ^= bm->bitmap[i]; /* Compute the change: the first unset bit in the original number */ - while( !(temp & 0x1) ) { + temp ^= bm->bitmap[i]; /* Compute the change: the first unset bit in the original number */ + while (!(temp & 0x1)) { ++(*position); temp >>= 1; } @@ -253,17 +235,17 @@ int opal_bitmap_bitwise_and_inplace(opal_bitmap_t *dest, opal_bitmap_t *right) /* * Sanity check */ - if( NULL == dest || NULL == right ) { + if (NULL == dest || NULL == right) { return OPAL_ERR_BAD_PARAM; } - if( dest->array_size != right->array_size ) { + if (dest->array_size != right->array_size) { return OPAL_ERR_BAD_PARAM; } /* * Bitwise AND */ - for(i = 0; i < dest->array_size; ++i) { + for (i = 0; i < dest->array_size; ++i) { dest->bitmap[i] &= right->bitmap[i]; } @@ -277,17 +259,17 @@ int opal_bitmap_bitwise_or_inplace(opal_bitmap_t *dest, opal_bitmap_t *right) /* * Sanity check */ - if( NULL == dest || NULL == right ) { + if (NULL == dest || NULL == right) { return OPAL_ERR_BAD_PARAM; } - if( dest->array_size != right->array_size ) { + if (dest->array_size != right->array_size) { return OPAL_ERR_BAD_PARAM; } /* * Bitwise OR */ - for(i = 0; i < dest->array_size; ++i) { + for (i = 0; i < dest->array_size; ++i) { dest->bitmap[i] |= right->bitmap[i]; } @@ -301,17 +283,17 @@ int opal_bitmap_bitwise_xor_inplace(opal_bitmap_t *dest, opal_bitmap_t *right) /* * Sanity check */ - if( NULL == dest || NULL == right ) { + if (NULL == dest || NULL == right) { return OPAL_ERR_BAD_PARAM; } - if( dest->array_size != right->array_size ) { + if (dest->array_size != right->array_size) { return OPAL_ERR_BAD_PARAM; } /* * Bitwise XOR */ - for(i = 0; i < dest->array_size; ++i) { + for (i = 0; i < dest->array_size; ++i) { dest->bitmap[i] ^= right->bitmap[i]; } @@ -325,19 +307,19 @@ bool opal_bitmap_are_different(opal_bitmap_t *left, opal_bitmap_t *right) /* * Sanity check */ - if( NULL == left || NULL == right ) { + if (NULL == left || NULL == right) { return OPAL_ERR_BAD_PARAM; } - if( opal_bitmap_size(left) != opal_bitmap_size(right) ) { + if (opal_bitmap_size(left) != opal_bitmap_size(right)) { return true; } /* * Direct comparison */ - for(i = 0; i < left->array_size; ++i) { - if( left->bitmap[i] != right->bitmap[i] ) { + for (i = 0; i < left->array_size; ++i) { + if (left->bitmap[i] != right->bitmap[i]) { return true; } } @@ -345,12 +327,12 @@ bool opal_bitmap_are_different(opal_bitmap_t *left, opal_bitmap_t *right) return false; } -char * opal_bitmap_get_string(opal_bitmap_t *bitmap) +char *opal_bitmap_get_string(opal_bitmap_t *bitmap) { int i; char *bitmap_str = NULL; - if( NULL == bitmap) { + if (NULL == bitmap) { return NULL; } @@ -360,8 +342,8 @@ char * opal_bitmap_get_string(opal_bitmap_t *bitmap) } bitmap_str[bitmap->array_size * SIZE_OF_BASE_TYPE] = '\0'; - for( i = 0; i < (bitmap->array_size * SIZE_OF_BASE_TYPE); ++i) { - if( opal_bitmap_is_set_bit(bitmap, i) ) { + for (i = 0; i < (bitmap->array_size * SIZE_OF_BASE_TYPE); ++i) { + if (opal_bitmap_is_set_bit(bitmap, i)) { bitmap_str[i] = 'X'; } else { bitmap_str[i] = '_'; @@ -387,12 +369,14 @@ int opal_bitmap_num_set_bits(opal_bitmap_t *bm, int len) } #endif - for(i = 0; i < len; ++i) { - if( 0 == (val = bm->bitmap[i]) ) continue; + for (i = 0; i < len; ++i) { + if (0 == (val = bm->bitmap[i])) { + continue; + } /* Peter Wegner in CACM 3 (1960), 322. This method goes through as many * iterations as there are set bits. */ - for( ; val; cnt++ ) { - val &= val - 1; /* clear the least significant bit set */ + for (; val; cnt++) { + val &= val - 1; /* clear the least significant bit set */ } } diff --git a/opal/class/opal_bitmap.h b/opal/class/opal_bitmap.h index cda93888451..90c1a28b5c0 100644 --- a/opal/class/opal_bitmap.h +++ b/opal/class/opal_bitmap.h @@ -49,10 +49,10 @@ BEGIN_C_DECLS struct opal_bitmap_t { - opal_object_t super; /**< Subclass of opal_object_t */ - uint64_t *bitmap; /**< The actual bitmap array of characters */ - int array_size; /**< The actual array size that maintains the bitmap */ - int max_size; /**< The maximum size that this bitmap may grow (optional) */ + opal_object_t super; /**< Subclass of opal_object_t */ + uint64_t *bitmap; /**< The actual bitmap array of characters */ + int array_size; /**< The actual array size that maintains the bitmap */ + int max_size; /**< The maximum size that this bitmap may grow (optional) */ }; typedef struct opal_bitmap_t opal_bitmap_t; @@ -68,8 +68,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_bitmap_t); * @return OPAL error code or success * */ -OPAL_DECLSPEC int opal_bitmap_set_max_size (opal_bitmap_t *bm, int max_size); - +OPAL_DECLSPEC int opal_bitmap_set_max_size(opal_bitmap_t *bm, int max_size); /** * Initializes the bitmap and sets its size. This must be called @@ -80,8 +79,7 @@ OPAL_DECLSPEC int opal_bitmap_set_max_size (opal_bitmap_t *bm, int max_size); * @return OPAL error code or success * */ -OPAL_DECLSPEC int opal_bitmap_init (opal_bitmap_t *bm, int size); - +OPAL_DECLSPEC int opal_bitmap_init(opal_bitmap_t *bm, int size); /** * Set a bit of the bitmap. If the bit asked for is beyond the current @@ -95,7 +93,6 @@ OPAL_DECLSPEC int opal_bitmap_init (opal_bitmap_t *bm, int size); */ OPAL_DECLSPEC int opal_bitmap_set_bit(opal_bitmap_t *bm, int bit); - /** * Clear/unset a bit of the bitmap. If the bit is beyond the current * size of the bitmap, an error is returned @@ -107,21 +104,19 @@ OPAL_DECLSPEC int opal_bitmap_set_bit(opal_bitmap_t *bm, int bit); */ OPAL_DECLSPEC int opal_bitmap_clear_bit(opal_bitmap_t *bm, int bit); - /** - * Find out if a bit is set in the bitmap - * - * @param bitmap The input bitmap (IN) - * @param bit The bit which is to be checked (IN) - * @return true if the bit is set - * false if the bit is not set OR the index - * is outside the bounds of the provided - * bitmap - * - */ + * Find out if a bit is set in the bitmap + * + * @param bitmap The input bitmap (IN) + * @param bit The bit which is to be checked (IN) + * @return true if the bit is set + * false if the bit is not set OR the index + * is outside the bounds of the provided + * bitmap + * + */ OPAL_DECLSPEC bool opal_bitmap_is_set_bit(opal_bitmap_t *bm, int bit); - /** * Find the first clear bit in the bitmap and set it * @@ -130,9 +125,7 @@ OPAL_DECLSPEC bool opal_bitmap_is_set_bit(opal_bitmap_t *bm, int bit); * @return err OPAL_SUCCESS on success */ -OPAL_DECLSPEC int opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, - int *position); - +OPAL_DECLSPEC int opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, int *position); /** * Clear all bits in the bitmap @@ -143,7 +136,6 @@ OPAL_DECLSPEC int opal_bitmap_find_and_set_first_unset_bit(opal_bitmap_t *bm, */ OPAL_DECLSPEC int opal_bitmap_clear_all_bits(opal_bitmap_t *bm); - /** * Set all bits in the bitmap * @param bitmap The input bitmap (IN) @@ -152,7 +144,6 @@ OPAL_DECLSPEC int opal_bitmap_clear_all_bits(opal_bitmap_t *bm); */ OPAL_DECLSPEC int opal_bitmap_set_all_bits(opal_bitmap_t *bm); - /** * Gives the current size (number of bits) in the bitmap. This is the * legal (accessible) number of bits @@ -166,7 +157,6 @@ static inline int opal_bitmap_size(opal_bitmap_t *bm) return (NULL == bm) ? 0 : (bm->array_size * ((int) (sizeof(*bm->bitmap) * 8))); } - /** * Copy a bitmap * @@ -176,10 +166,11 @@ static inline int opal_bitmap_size(opal_bitmap_t *bm) */ static inline void opal_bitmap_copy(opal_bitmap_t *dest, opal_bitmap_t *src) { - if( dest->array_size < src->array_size ) { - if( NULL != dest->bitmap) free(dest->bitmap); + if (dest->array_size < src->array_size) { + if (NULL != dest->bitmap) + free(dest->bitmap); dest->max_size = src->max_size; - dest->bitmap = (uint64_t*)malloc(src->array_size*sizeof(uint64_t)); + dest->bitmap = (uint64_t *) malloc(src->array_size * sizeof(uint64_t)); } memcpy(dest->bitmap, src->bitmap, src->array_size * sizeof(uint64_t)); dest->array_size = src->array_size; @@ -228,7 +219,7 @@ OPAL_DECLSPEC bool opal_bitmap_are_different(opal_bitmap_t *left, opal_bitmap_t * @param bitmap Point to the bitmap to represent * @return Pointer to the string (caller must free if not NULL) */ -OPAL_DECLSPEC char * opal_bitmap_get_string(opal_bitmap_t *bitmap); +OPAL_DECLSPEC char *opal_bitmap_get_string(opal_bitmap_t *bitmap); /** * Return the number of 'unset' bits, upto the specified length diff --git a/opal/class/opal_cstring.c b/opal/class/opal_cstring.c index e203e83d0ca..c5d230d19b1 100644 --- a/opal/class/opal_cstring.c +++ b/opal/class/opal_cstring.c @@ -13,20 +13,15 @@ #include "opal_cstring.h" -#include -#include -#include #include "opal/constants.h" #include "opal/util/string_copy.h" +#include +#include +#include static void opal_cstring_ctor(opal_cstring_t *obj); -OBJ_CLASS_INSTANCE( - opal_cstring_t, - opal_object_t, - &opal_cstring_ctor, - NULL -); +OBJ_CLASS_INSTANCE(opal_cstring_t, opal_object_t, &opal_cstring_ctor, NULL); /* make sure we have sufficient padding to always null-terminate the string */ #if (__STDC_VERSION__ >= 201112L) @@ -36,9 +31,9 @@ _Static_assert(sizeof(opal_cstring_t) > offsetof(opal_cstring_t, string), static void opal_cstring_ctor(opal_cstring_t *obj) { - *(size_t*)&(obj->length) = 0; + *(size_t *) &(obj->length) = 0; /* make sure the string is null-terminated */ - ((char*)obj->string)[0] = '\n'; + ((char *) obj->string)[0] = '\n'; } static inline size_t opal_cstring_alloc_size(size_t len) @@ -51,27 +46,27 @@ static inline size_t opal_cstring_alloc_size(size_t len) return (res > sizeof(opal_cstring_t)) ? res : sizeof(opal_cstring_t); } -opal_cstring_t* opal_cstring_create_l(const char *string, size_t len) +opal_cstring_t *opal_cstring_create_l(const char *string, size_t len) { if (NULL == string || 0 == len) { return OBJ_NEW(opal_cstring_t); } /* Allocate space for the object, the characters in \c string and the terminating null */ - opal_cstring_t* res = (opal_cstring_t*)malloc(opal_cstring_alloc_size(len)); + opal_cstring_t *res = (opal_cstring_t *) malloc(opal_cstring_alloc_size(len)); if (NULL == res) { return NULL; } OBJ_CONSTRUCT(res, opal_cstring_t); /* cast away const for setting the member values */ - *(size_t*)&(res->length) = len; - opal_string_copy((char*)res->string, string, len+1); + *(size_t *) &(res->length) = len; + opal_string_copy((char *) res->string, string, len + 1); return res; } -opal_cstring_t* opal_cstring_create(const char *string) +opal_cstring_t *opal_cstring_create(const char *string) { if (NULL == string) { return OBJ_NEW(opal_cstring_t); @@ -80,7 +75,6 @@ opal_cstring_t* opal_cstring_create(const char *string) return opal_cstring_create_l(string, len); } - int opal_cstring_to_int(opal_cstring_t *string, int *interp) { long tmp; @@ -93,18 +87,20 @@ int opal_cstring_to_int(opal_cstring_t *string, int *interp) errno = 0; tmp = strtol(string->string, &endp, 10); /* we found something not a number */ - if (*endp != '\0') return OPAL_ERR_BAD_PARAM; + if (*endp != '\0') { + return OPAL_ERR_BAD_PARAM; + } /* underflow */ - if (tmp == 0 && errno == EINVAL) return OPAL_ERR_BAD_PARAM; + if (tmp == 0 && errno == EINVAL) { + return OPAL_ERR_BAD_PARAM; + } *interp = (int) tmp; return OPAL_SUCCESS; } - -static int -opal_str_to_bool_impl(const char *string, bool *interp) +static int opal_str_to_bool_impl(const char *string, bool *interp) { const char *ptr = string; @@ -116,11 +112,9 @@ opal_str_to_bool_impl(const char *string, bool *interp) if ('\0' != *ptr) { if (isdigit(*ptr)) { *interp = (bool) atoi(ptr); - } else if (0 == strncasecmp(ptr, "yes", 3) || - 0 == strncasecmp(ptr, "true", 4)) { + } else if (0 == strncasecmp(ptr, "yes", 3) || 0 == strncasecmp(ptr, "true", 4)) { *interp = true; - } else if (0 == strncasecmp(ptr, "no", 2) && - 0 == strncasecmp(ptr, "false", 5)) { + } else if (0 == strncasecmp(ptr, "no", 2) && 0 == strncasecmp(ptr, "false", 5)) { *interp = false; } else { *interp = false; @@ -130,8 +124,7 @@ opal_str_to_bool_impl(const char *string, bool *interp) return OPAL_SUCCESS; } -int -opal_cstring_to_bool(opal_cstring_t *string, bool *interp) +int opal_cstring_to_bool(opal_cstring_t *string, bool *interp) { return opal_str_to_bool_impl(string->string, interp); } diff --git a/opal/class/opal_cstring.h b/opal/class/opal_cstring.h index 7c0676c443e..a5def2e075f 100644 --- a/opal/class/opal_cstring.h +++ b/opal/class/opal_cstring.h @@ -68,13 +68,12 @@ struct opal_cstring_t { opal_object_t super; const size_t length; //< the number of characters not including the null-terminator - char _ignored; //< single char forcing additional padding to always ensure null-termination + char _ignored; //< single char forcing additional padding to always ensure null-termination const char string[]; //< FMA containing the string, making use of padding bytes }; typedef struct opal_cstring_t opal_cstring_t; - BEGIN_C_DECLS /** @@ -95,7 +94,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_cstring_t); * */ OPAL_DECLSPEC -opal_cstring_t* opal_cstring_create(const char *string) __opal_attribute_malloc__; +opal_cstring_t *opal_cstring_create(const char *string) __opal_attribute_malloc__; /** * Create a new instance of a reference-counted immutable string object @@ -108,7 +107,7 @@ opal_cstring_t* opal_cstring_create(const char *string) __opal_attribute_malloc_ * If \c string is \c NULL or \c length is zero the resulting string will be empty. */ OPAL_DECLSPEC -opal_cstring_t* opal_cstring_create_l(const char *string, size_t length) __opal_attribute_malloc__; +opal_cstring_t *opal_cstring_create_l(const char *string, size_t length) __opal_attribute_malloc__; /** * Convert string to integer @@ -127,7 +126,6 @@ opal_cstring_t* opal_cstring_create_l(const char *string, size_t length) __opal_ OPAL_DECLSPEC int opal_cstring_to_int(opal_cstring_t *string, int *interp); - /** * Convert string to boolean * @@ -155,7 +153,6 @@ int opal_cstring_to_int(opal_cstring_t *string, int *interp); OPAL_DECLSPEC int opal_cstring_to_bool(opal_cstring_t *string, bool *interp); - OPAL_DECLSPEC bool opal_str_to_bool(const char *string); diff --git a/opal/class/opal_fifo.c b/opal/class/opal_fifo.c index 238801d4922..c3cd93d1c31 100644 --- a/opal/class/opal_fifo.c +++ b/opal/class/opal_fifo.c @@ -22,7 +22,7 @@ #include "opal_config.h" #include "opal/class/opal_fifo.h" -static void opal_fifo_construct (opal_fifo_t *fifo) +static void opal_fifo_construct(opal_fifo_t *fifo) { OBJ_CONSTRUCT(&fifo->opal_fifo_ghost, opal_list_item_t); diff --git a/opal/class/opal_fifo.h b/opal/class/opal_fifo.h index 3cc88393cd1..4e76f2d6d51 100644 --- a/opal/class/opal_fifo.h +++ b/opal/class/opal_fifo.h @@ -29,8 +29,8 @@ #include "opal_config.h" #include "opal/class/opal_lifo.h" -#include "opal/sys/atomic.h" #include "opal/mca/threads/mutex.h" +#include "opal/sys/atomic.h" BEGIN_C_DECLS @@ -59,12 +59,12 @@ typedef struct opal_fifo_t opal_fifo_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_fifo_t); -static inline opal_list_item_t *opal_fifo_head (opal_fifo_t* fifo) +static inline opal_list_item_t *opal_fifo_head(opal_fifo_t *fifo) { return (opal_list_item_t *) fifo->opal_fifo_head.data.item; } -static inline opal_list_item_t *opal_fifo_tail (opal_fifo_t* fifo) +static inline opal_list_item_t *opal_fifo_tail(opal_fifo_t *fifo) { return (opal_list_item_t *) fifo->opal_fifo_tail.data.item; } @@ -73,9 +73,9 @@ static inline opal_list_item_t *opal_fifo_tail (opal_fifo_t* fifo) * compare-and-swap. On most architectures the reading of a pointer is an * atomic operation so we don't have to protect it. */ -static inline bool opal_fifo_is_empty( opal_fifo_t* fifo ) +static inline bool opal_fifo_is_empty(opal_fifo_t *fifo) { - return opal_fifo_head (fifo) == &fifo->opal_fifo_ghost; + return opal_fifo_head(fifo) == &fifo->opal_fifo_ghost; } #if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 && !OPAL_HAVE_ATOMIC_LLSC_PTR @@ -84,28 +84,27 @@ static inline bool opal_fifo_is_empty( opal_fifo_t* fifo ) * to allow the upper level to detect if this element is the first one in the * list (if the list was empty before this operation). */ -static inline opal_list_item_t *opal_fifo_push_atomic (opal_fifo_t *fifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_fifo_push_atomic(opal_fifo_t *fifo, opal_list_item_t *item) { opal_counted_pointer_t tail = {.value = fifo->opal_fifo_tail.value}; - const opal_list_item_t * const ghost = &fifo->opal_fifo_ghost; + const opal_list_item_t *const ghost = &fifo->opal_fifo_ghost; item->opal_list_next = (opal_list_item_t *) ghost; - opal_atomic_wmb (); + opal_atomic_wmb(); do { - if (opal_update_counted_pointer (&fifo->opal_fifo_tail, &tail, item)) { + if (opal_update_counted_pointer(&fifo->opal_fifo_tail, &tail, item)) { break; } } while (1); - opal_atomic_wmb (); + opal_atomic_wmb(); - if ((intptr_t) ghost == tail.data.item) { + if ((intptr_t) ghost == tail.data.item) { /* update the head */ opal_counted_pointer_t head = {.value = fifo->opal_fifo_head.value}; - opal_update_counted_pointer (&fifo->opal_fifo_head, &head, item); + opal_update_counted_pointer(&fifo->opal_fifo_head, &head, item); } else { /* update previous item */ ((opal_list_item_t *) tail.data.item)->opal_list_next = item; @@ -117,16 +116,16 @@ static inline opal_list_item_t *opal_fifo_push_atomic (opal_fifo_t *fifo, /* Retrieve one element from the FIFO. If we reach the ghost element then the FIFO * is empty so we return NULL. */ -static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) +static inline opal_list_item_t *opal_fifo_pop_atomic(opal_fifo_t *fifo) { opal_list_item_t *item, *next, *ghost = &fifo->opal_fifo_ghost; opal_counted_pointer_t head, tail; - opal_read_counted_pointer (&fifo->opal_fifo_head, &head); + opal_read_counted_pointer(&fifo->opal_fifo_head, &head); do { tail.value = fifo->opal_fifo_tail.value; - opal_atomic_rmb (); + opal_atomic_rmb(); item = (opal_list_item_t *) head.data.item; next = (opal_list_item_t *) item->opal_list_next; @@ -136,29 +135,30 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) } /* the head or next pointer are in an inconsistent state. keep looping. */ - if (tail.data.item != (intptr_t) item && (intptr_t) ghost != tail.data.item && ghost == next) { - opal_read_counted_pointer (&fifo->opal_fifo_head, &head); + if (tail.data.item != (intptr_t) item && (intptr_t) ghost != tail.data.item + && ghost == next) { + opal_read_counted_pointer(&fifo->opal_fifo_head, &head); continue; } /* try popping the head */ - if (opal_update_counted_pointer (&fifo->opal_fifo_head, &head, next)) { + if (opal_update_counted_pointer(&fifo->opal_fifo_head, &head, next)) { break; } } while (1); - opal_atomic_wmb (); + opal_atomic_wmb(); /* check for tail and head consistency */ if (ghost == next) { /* the head was just set to &fifo->opal_fifo_ghost. try to update the tail as well */ - if (!opal_update_counted_pointer (&fifo->opal_fifo_tail, &tail, ghost)) { + if (!opal_update_counted_pointer(&fifo->opal_fifo_tail, &tail, ghost)) { /* tail was changed by a push operation. wait for the item's next pointer to be se then * update the head */ /* wait for next pointer to be updated by push */ do { - opal_atomic_rmb (); + opal_atomic_rmb(); } while (ghost == item->opal_list_next); /* update the head with the real next value. note that no other thread @@ -166,7 +166,7 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) * with the next pointer. push will not see an empty list and other pop * operations will loop until the head is consistent. */ fifo->opal_fifo_head.data.item = (intptr_t) item->opal_list_next; - opal_atomic_wmb (); + opal_atomic_wmb(); } } @@ -180,20 +180,20 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) /* When compare-and-set 128 is not available we avoid the ABA problem by * using a spin-lock on the head (using the head counter). Otherwise * the algorithm is identical to the compare-and-set 128 version. */ -static inline opal_list_item_t *opal_fifo_push_atomic (opal_fifo_t *fifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_fifo_push_atomic(opal_fifo_t *fifo, opal_list_item_t *item) { - const opal_list_item_t * const ghost = &fifo->opal_fifo_ghost; + const opal_list_item_t *const ghost = &fifo->opal_fifo_ghost; opal_list_item_t *tail_item; item->opal_list_next = (opal_list_item_t *) ghost; - opal_atomic_wmb (); + opal_atomic_wmb(); /* try to get the tail */ - tail_item = (opal_list_item_t *) opal_atomic_swap_ptr (&fifo->opal_fifo_tail.data.item, (intptr_t) item); + tail_item = (opal_list_item_t *) opal_atomic_swap_ptr(&fifo->opal_fifo_tail.data.item, + (intptr_t) item); - opal_atomic_wmb (); + opal_atomic_wmb(); if (ghost == tail_item) { /* update the head */ @@ -203,7 +203,7 @@ static inline opal_list_item_t *opal_fifo_push_atomic (opal_fifo_t *fifo, tail_item->opal_list_next = item; } - opal_atomic_wmb (); + opal_atomic_wmb(); return (opal_list_item_t *) tail_item; } @@ -211,11 +211,11 @@ static inline opal_list_item_t *opal_fifo_push_atomic (opal_fifo_t *fifo, /* Retrieve one element from the FIFO. If we reach the ghost element then the FIFO * is empty so we return NULL. */ -static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) +static inline opal_list_item_t *opal_fifo_pop_atomic(opal_fifo_t *fifo) { - const opal_list_item_t * const ghost = &fifo->opal_fifo_ghost; + const opal_list_item_t *const ghost = &fifo->opal_fifo_ghost; -#if OPAL_HAVE_ATOMIC_LLSC_PTR +# if OPAL_HAVE_ATOMIC_LLSC_PTR register opal_list_item_t *item, *next; int attempt = 0, ret = 0; @@ -224,7 +224,7 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) if (++attempt == 5) { /* deliberatly suspend this thread to allow other threads to run. this should * only occur during periods of contention on the lifo. */ - _opal_lifo_release_cpu (); + _opal_lifo_release_cpu(); attempt = 0; } @@ -243,21 +243,21 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) opal_atomic_sc_ptr(&fifo->opal_fifo_head.data.item, next, ret); } while (!ret); -#else +# else opal_list_item_t *item, *next; /* protect against ABA issues by "locking" the head */ do { - if (!opal_atomic_swap_32 ((opal_atomic_int32_t *) &fifo->opal_fifo_head.data.counter, 1)) { + if (!opal_atomic_swap_32((opal_atomic_int32_t *) &fifo->opal_fifo_head.data.counter, 1)) { break; } - opal_atomic_wmb (); + opal_atomic_wmb(); } while (1); opal_atomic_wmb(); - item = opal_fifo_head (fifo); + item = opal_fifo_head(fifo); if (ghost == item) { fifo->opal_fifo_head.data.counter = 0; return NULL; @@ -265,21 +265,22 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) next = (opal_list_item_t *) item->opal_list_next; fifo->opal_fifo_head.data.item = (uintptr_t) next; -#endif +# endif if (ghost == next) { void *tmp = item; - if (!opal_atomic_compare_exchange_strong_ptr (&fifo->opal_fifo_tail.data.item, (intptr_t *) &tmp, (intptr_t) ghost)) { + if (!opal_atomic_compare_exchange_strong_ptr(&fifo->opal_fifo_tail.data.item, + (intptr_t *) &tmp, (intptr_t) ghost)) { do { - opal_atomic_rmb (); + opal_atomic_rmb(); } while (ghost == item->opal_list_next); fifo->opal_fifo_head.data.item = (intptr_t) item->opal_list_next; } } - opal_atomic_wmb (); + opal_atomic_wmb(); /* unlock the head */ fifo->opal_fifo_head.data.counter = 0; @@ -292,15 +293,14 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo) #endif /* single threaded versions of push/pop */ -static inline opal_list_item_t *opal_fifo_push_st (opal_fifo_t *fifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_fifo_push_st(opal_fifo_t *fifo, opal_list_item_t *item) { - opal_list_item_t *prev = opal_fifo_tail (fifo); + opal_list_item_t *prev = opal_fifo_tail(fifo); item->opal_list_next = &fifo->opal_fifo_ghost; fifo->opal_fifo_tail.data.item = (intptr_t) item; - if (&fifo->opal_fifo_ghost == opal_fifo_head (fifo)) { + if (&fifo->opal_fifo_ghost == opal_fifo_head(fifo)) { fifo->opal_fifo_head.data.item = (intptr_t) item; } else { prev->opal_list_next = item; @@ -309,16 +309,16 @@ static inline opal_list_item_t *opal_fifo_push_st (opal_fifo_t *fifo, return (opal_list_item_t *) item->opal_list_next; } -static inline opal_list_item_t *opal_fifo_pop_st (opal_fifo_t *fifo) +static inline opal_list_item_t *opal_fifo_pop_st(opal_fifo_t *fifo) { - opal_list_item_t *item = opal_fifo_head (fifo); + opal_list_item_t *item = opal_fifo_head(fifo); if (item == &fifo->opal_fifo_ghost) { return NULL; } fifo->opal_fifo_head.data.item = (intptr_t) item->opal_list_next; - if (&fifo->opal_fifo_ghost == opal_fifo_head (fifo)) { + if (&fifo->opal_fifo_ghost == opal_fifo_head(fifo)) { fifo->opal_fifo_tail.data.item = (intptr_t) &fifo->opal_fifo_ghost; } @@ -327,25 +327,24 @@ static inline opal_list_item_t *opal_fifo_pop_st (opal_fifo_t *fifo) } /* push/pop versions conditioned off opal_using_threads() */ -static inline opal_list_item_t *opal_fifo_push (opal_fifo_t *fifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_fifo_push(opal_fifo_t *fifo, opal_list_item_t *item) { - if (opal_using_threads ()) { - return opal_fifo_push_atomic (fifo, item); + if (opal_using_threads()) { + return opal_fifo_push_atomic(fifo, item); } - return opal_fifo_push_st (fifo, item); + return opal_fifo_push_st(fifo, item); } -static inline opal_list_item_t *opal_fifo_pop (opal_fifo_t *fifo) +static inline opal_list_item_t *opal_fifo_pop(opal_fifo_t *fifo) { - if (opal_using_threads ()) { - return opal_fifo_pop_atomic (fifo); + if (opal_using_threads()) { + return opal_fifo_pop_atomic(fifo); } - return opal_fifo_pop_st (fifo); + return opal_fifo_pop_st(fifo); } END_C_DECLS -#endif /* OPAL_FIFO_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_FIFO_H_HAS_BEEN_INCLUDED */ diff --git a/opal/class/opal_free_list.c b/opal/class/opal_free_list.c index 7fb010effc0..a5eb9f75295 100644 --- a/opal/class/opal_free_list.c +++ b/opal/class/opal_free_list.c @@ -24,21 +24,19 @@ #include "opal_config.h" -#include "opal/class/opal_free_list.h" #include "opal/align.h" -#include "opal/util/output.h" -#include "opal/mca/mpool/mpool.h" +#include "opal/class/opal_free_list.h" #include "opal/mca/mpool/base/base.h" +#include "opal/mca/mpool/mpool.h" #include "opal/mca/rcache/rcache.h" +#include "opal/util/output.h" #include "opal/util/sys_limits.h" typedef struct opal_free_list_item_t opal_free_list_memory_t; -OBJ_CLASS_INSTANCE(opal_free_list_item_t, - opal_list_item_t, - NULL, NULL); +OBJ_CLASS_INSTANCE(opal_free_list_item_t, opal_list_item_t, NULL, NULL); -static void opal_free_list_construct(opal_free_list_t* fl) +static void opal_free_list_construct(opal_free_list_t *fl) { OBJ_CONSTRUCT(&fl->fl_lock, opal_mutex_t); OBJ_CONSTRUCT(&fl->fl_condition, opal_condition_t); @@ -54,22 +52,21 @@ static void opal_free_list_construct(opal_free_list_t* fl) fl->fl_mpool = NULL; fl->fl_rcache = NULL; /* default flags */ - fl->fl_rcache_reg_flags = MCA_RCACHE_FLAGS_CACHE_BYPASS | - MCA_RCACHE_FLAGS_CUDA_REGISTER_MEM; + fl->fl_rcache_reg_flags = MCA_RCACHE_FLAGS_CACHE_BYPASS | MCA_RCACHE_FLAGS_CUDA_REGISTER_MEM; fl->ctx = NULL; OBJ_CONSTRUCT(&(fl->fl_allocations), opal_list_t); } -static void opal_free_list_allocation_release (opal_free_list_t *fl, opal_free_list_memory_t *fl_mem) +static void opal_free_list_allocation_release(opal_free_list_t *fl, opal_free_list_memory_t *fl_mem) { if (NULL != fl->fl_rcache) { - fl->fl_rcache->rcache_deregister (fl->fl_rcache, fl_mem->registration); + fl->fl_rcache->rcache_deregister(fl->fl_rcache, fl_mem->registration); } if (NULL != fl->fl_mpool) { - fl->fl_mpool->mpool_free (fl->fl_mpool, fl_mem->ptr); + fl->fl_mpool->mpool_free(fl->fl_mpool, fl_mem->ptr); } else if (fl_mem->ptr) { - free (fl_mem->ptr); + free(fl_mem->ptr); } /* destruct the item (we constructed it), then free the memory chunk */ @@ -90,8 +87,8 @@ static void opal_free_list_destruct(opal_free_list_t *fl) } #endif - while(NULL != (item = opal_lifo_pop(&(fl->super)))) { - fl_item = (opal_free_list_item_t*)item; + while (NULL != (item = opal_lifo_pop(&(fl->super)))) { + fl_item = (opal_free_list_item_t *) item; /* destruct the item (we constructed it), the underlying memory will be * reclaimed when we free the slab (opal_free_list_memory_t ptr) @@ -99,8 +96,8 @@ static void opal_free_list_destruct(opal_free_list_t *fl) OBJ_DESTRUCT(fl_item); } - while(NULL != (item = opal_list_remove_first(&fl->fl_allocations))) { - opal_free_list_allocation_release (fl, (opal_free_list_memory_t *) item); + while (NULL != (item = opal_list_remove_first(&fl->fl_allocations))) { + opal_free_list_allocation_release(fl, (opal_free_list_memory_t *) item); } OBJ_DESTRUCT(&fl->fl_allocations); @@ -111,14 +108,13 @@ static void opal_free_list_destruct(opal_free_list_t *fl) OBJ_CLASS_INSTANCE(opal_free_list_t, opal_lifo_t, opal_free_list_construct, opal_free_list_destruct); - -int opal_free_list_init (opal_free_list_t *flist, size_t frag_size, size_t frag_alignment, - opal_class_t *frag_class, size_t payload_buffer_size, - size_t payload_buffer_alignment, int num_elements_to_alloc, - int max_elements_to_alloc, int num_elements_per_alloc, - mca_mpool_base_module_t *mpool, int rcache_reg_flags, - mca_rcache_base_module_t *rcache, opal_free_list_item_init_fn_t item_init, - void *ctx) +int opal_free_list_init(opal_free_list_t *flist, size_t frag_size, size_t frag_alignment, + opal_class_t *frag_class, size_t payload_buffer_size, + size_t payload_buffer_alignment, int num_elements_to_alloc, + int max_elements_to_alloc, int num_elements_per_alloc, + mca_mpool_base_module_t *mpool, int rcache_reg_flags, + mca_rcache_base_module_t *rcache, opal_free_list_item_init_fn_t item_init, + void *ctx) { /* alignment must be more than zero and power of two */ if (frag_alignment <= 1 || (frag_alignment & (frag_alignment - 1))) { @@ -126,8 +122,10 @@ int opal_free_list_init (opal_free_list_t *flist, size_t frag_size, size_t frag_ } if (0 < payload_buffer_size) { - if (payload_buffer_alignment <= 1 || (payload_buffer_alignment & (payload_buffer_alignment - 1))) + if (payload_buffer_alignment <= 1 + || (payload_buffer_alignment & (payload_buffer_alignment - 1))) { return OPAL_ERROR; + } } if (frag_class && frag_size < frag_class->cls_sizeof) { @@ -155,13 +153,14 @@ int opal_free_list_init (opal_free_list_t *flist, size_t frag_size, size_t frag_ flist->ctx = ctx; if (num_elements_to_alloc) { - return opal_free_list_grow_st (flist, num_elements_to_alloc, NULL); + return opal_free_list_grow_st(flist, num_elements_to_alloc, NULL); } return OPAL_SUCCESS; } -int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_free_list_item_t **item_out) +int opal_free_list_grow_st(opal_free_list_t *flist, size_t num_elements, + opal_free_list_item_t **item_out) { unsigned char *ptr, *payload_ptr = NULL; opal_free_list_memory_t *alloc_ptr; @@ -169,8 +168,8 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f mca_rcache_base_registration_t *reg = NULL; int rc = OPAL_SUCCESS; - if (flist->fl_max_to_alloc && (flist->fl_num_allocated + num_elements) > - flist->fl_max_to_alloc) { + if (flist->fl_max_to_alloc + && (flist->fl_num_allocated + num_elements) > flist->fl_max_to_alloc) { num_elements = flist->fl_max_to_alloc - flist->fl_num_allocated; } @@ -182,17 +181,17 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f /* NTH: calculate allocation alignment first as it might change the number of elements */ if (0 != flist->fl_payload_buffer_size) { - elem_size = OPAL_ALIGN(flist->fl_payload_buffer_size, - flist->fl_payload_buffer_alignment, size_t); + elem_size = OPAL_ALIGN(flist->fl_payload_buffer_size, flist->fl_payload_buffer_alignment, + size_t); /* elem_size should not be 0 here */ - assert (elem_size > 0); + assert(elem_size > 0); buffer_size = num_elements * elem_size; align = flist->fl_payload_buffer_alignment; if (MCA_RCACHE_FLAGS_CUDA_REGISTER_MEM & flist->fl_rcache_reg_flags) { - size_t pagesize = opal_getpagesize (); + size_t pagesize = opal_getpagesize(); /* CUDA cannot handle registering overlapping regions, so make * sure each region is page sized and page aligned. */ align = OPAL_ALIGN(align, pagesize, size_t); @@ -204,8 +203,8 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f } /* calculate head allocation size */ - alloc_size = num_elements * head_size + sizeof(opal_free_list_memory_t) + - flist->fl_frag_alignment; + alloc_size = num_elements * head_size + sizeof(opal_free_list_memory_t) + + flist->fl_frag_alignment; alloc_ptr = (opal_free_list_memory_t *) malloc(alloc_size); if (OPAL_UNLIKELY(NULL == alloc_ptr)) { @@ -214,18 +213,21 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f if (0 != flist->fl_payload_buffer_size) { /* allocate the rest from the mpool (or use memalign/malloc) */ - payload_ptr = (unsigned char *) flist->fl_mpool->mpool_alloc(flist->fl_mpool, buffer_size, align, 0); + payload_ptr = (unsigned char *) flist->fl_mpool->mpool_alloc(flist->fl_mpool, buffer_size, + align, 0); if (NULL == payload_ptr) { free(alloc_ptr); return OPAL_ERR_TEMP_OUT_OF_RESOURCE; } if (flist->fl_rcache) { - rc = flist->fl_rcache->rcache_register (flist->fl_rcache, payload_ptr, num_elements * elem_size, - flist->fl_rcache_reg_flags, MCA_RCACHE_ACCESS_ANY, ®); + rc = flist->fl_rcache->rcache_register(flist->fl_rcache, payload_ptr, + num_elements * elem_size, + flist->fl_rcache_reg_flags, + MCA_RCACHE_ACCESS_ANY, ®); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - free (alloc_ptr); - flist->fl_mpool->mpool_free (flist->fl_mpool, payload_ptr); + free(alloc_ptr); + flist->fl_mpool->mpool_free(flist->fl_mpool, payload_ptr); return rc; } @@ -235,16 +237,16 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f /* make the alloc_ptr a list item, save the chunk in the allocations list, * and have ptr point to memory right after the list item structure */ OBJ_CONSTRUCT(alloc_ptr, opal_free_list_item_t); - opal_list_append(&(flist->fl_allocations), (opal_list_item_t*)alloc_ptr); + opal_list_append(&(flist->fl_allocations), (opal_list_item_t *) alloc_ptr); alloc_ptr->registration = reg; alloc_ptr->ptr = payload_ptr; - ptr = (unsigned char*)alloc_ptr + sizeof(opal_free_list_memory_t); - ptr = OPAL_ALIGN_PTR(ptr, flist->fl_frag_alignment, unsigned char*); + ptr = (unsigned char *) alloc_ptr + sizeof(opal_free_list_memory_t); + ptr = OPAL_ALIGN_PTR(ptr, flist->fl_frag_alignment, unsigned char *); - for(size_t i = 0; i < num_elements ; ++i) { - opal_free_list_item_t* item = (opal_free_list_item_t*)ptr; + for (size_t i = 0; i < num_elements; ++i) { + opal_free_list_item_t *item = (opal_free_list_item_t *) ptr; item->registration = reg; item->ptr = payload_ptr; @@ -255,7 +257,7 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f if (flist->item_init) { if (OPAL_SUCCESS != (rc = flist->item_init(item, flist->ctx))) { num_elements = i; - OBJ_DESTRUCT (item); + OBJ_DESTRUCT(item); break; } } @@ -268,7 +270,7 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f * if one is available */ *item_out = item; } else { - opal_lifo_push_atomic (&flist->super, &item->super); + opal_lifo_push_atomic(&flist->super, &item->super); } ptr += head_size; @@ -279,8 +281,8 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements, opal_f if (OPAL_SUCCESS != rc && 0 == num_elements) { /* couldn't initialize any items */ - opal_list_remove_item (&flist->fl_allocations, (opal_list_item_t *) alloc_ptr); - opal_free_list_allocation_release (flist, alloc_ptr); + opal_list_remove_item(&flist->fl_allocations, (opal_list_item_t *) alloc_ptr); + opal_free_list_allocation_release(flist, alloc_ptr); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -304,16 +306,16 @@ int opal_free_list_resize_mt(opal_free_list_t *flist, size_t size) return OPAL_SUCCESS; } - opal_mutex_lock (&flist->fl_lock); + opal_mutex_lock(&flist->fl_lock); do { - ret = opal_free_list_grow_st (flist, flist->fl_num_per_alloc, NULL); + ret = opal_free_list_grow_st(flist, flist->fl_num_per_alloc, NULL); if (OPAL_SUCCESS != ret) { break; } - inc_num = (ssize_t)size - (ssize_t)flist->fl_num_allocated; + inc_num = (ssize_t) size - (ssize_t) flist->fl_num_allocated; } while (inc_num > 0); - opal_mutex_unlock (&flist->fl_lock); + opal_mutex_unlock(&flist->fl_lock); return ret; } diff --git a/opal/class/opal_free_list.h b/opal/class/opal_free_list.h index ddc383fb912..f48ebc18258 100644 --- a/opal/class/opal_free_list.h +++ b/opal/class/opal_free_list.h @@ -26,9 +26,9 @@ #include "opal_config.h" #include "opal/class/opal_lifo.h" -#include "opal/prefetch.h" -#include "opal/mca/threads/condition.h" #include "opal/constants.h" +#include "opal/mca/threads/condition.h" +#include "opal/prefetch.h" #include "opal/runtime/opal.h" BEGIN_C_DECLS @@ -50,8 +50,7 @@ struct opal_free_list_item_t; * function should return OPAL_SUCCESS. On any error * opal_free_list_grow will stop initializing new items. */ -typedef int (*opal_free_list_item_init_fn_t) ( - struct opal_free_list_item_t *item, void *ctx); +typedef int (*opal_free_list_item_init_fn_t)(struct opal_free_list_item_t *item, void *ctx); struct opal_free_list_t { /** Items in a free list are stored last-in first-out */ @@ -97,8 +96,7 @@ typedef struct opal_free_list_t opal_free_list_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_free_list_t); struct mca_mpool_base_registration_t; -struct opal_free_list_item_t -{ +struct opal_free_list_item_t { opal_list_item_t super; struct mca_rcache_base_registration_t *registration; void *ptr; @@ -106,14 +104,14 @@ struct opal_free_list_item_t typedef struct opal_free_list_item_t opal_free_list_item_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_free_list_item_t); - /** * Initialize a free list. * * @param free_list (IN) Free list. * @param frag_size (IN) Size of each element - allocated by malloc. * @param frag_alignment (IN) Fragment alignment. - * @param frag_class (IN) opal_class_t of element - used to initialize allocated elements. + * @param frag_class (IN) opal_class_t of element - used to initialize allocated + * elements. * @param payload_buffer_size (IN) Size of payload buffer - allocated from mpool. * @param payload_buffer_alignment (IN) Payload buffer alignment. * @param num_elements_to_alloc (IN) Initial number of elements to allocate. @@ -126,20 +124,14 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_free_list_item_t); * @param ctx (IN) Initialization function context. */ -OPAL_DECLSPEC int opal_free_list_init (opal_free_list_t *free_list, - size_t frag_size, - size_t frag_alignment, - opal_class_t* frag_class, - size_t payload_buffer_size, - size_t payload_buffer_alignment, - int num_elements_to_alloc, - int max_elements_to_alloc, - int num_elements_per_alloc, - struct mca_mpool_base_module_t *mpool, - int rcache_reg_flags, - struct mca_rcache_base_module_t *rcache, - opal_free_list_item_init_fn_t item_init, - void *ctx); +OPAL_DECLSPEC int opal_free_list_init(opal_free_list_t *free_list, size_t frag_size, + size_t frag_alignment, opal_class_t *frag_class, + size_t payload_buffer_size, size_t payload_buffer_alignment, + int num_elements_to_alloc, int max_elements_to_alloc, + int num_elements_per_alloc, + struct mca_mpool_base_module_t *mpool, int rcache_reg_flags, + struct mca_rcache_base_module_t *rcache, + opal_free_list_item_init_fn_t item_init, void *ctx); /** * Grow the free list by at most num_elements elements. @@ -163,7 +155,8 @@ OPAL_DECLSPEC int opal_free_list_init (opal_free_list_t *free_list, * and assumes NULL is an out of memory condition (which it wasn't necessarily * before this parameter was added). */ -OPAL_DECLSPEC int opal_free_list_grow_st (opal_free_list_t *flist, size_t num_elements, opal_free_list_item_t **item_out); +OPAL_DECLSPEC int opal_free_list_grow_st(opal_free_list_t *flist, size_t num_elements, + opal_free_list_item_t **item_out); /** * Grow the free list to be at least size elements. @@ -179,8 +172,7 @@ OPAL_DECLSPEC int opal_free_list_grow_st (opal_free_list_t *flist, size_t num_el * chunks). This function is thread-safe and will obtain the free list lock before * growing the free list. */ -OPAL_DECLSPEC int opal_free_list_resize_mt (opal_free_list_t *flist, size_t size); - +OPAL_DECLSPEC int opal_free_list_resize_mt(opal_free_list_t *flist, size_t size); /** * Attemp to obtain an item from a free list. @@ -195,44 +187,41 @@ OPAL_DECLSPEC int opal_free_list_resize_mt (opal_free_list_t *flist, size_t size * (opal_free_list_get_mt), single threaded (opal_free_list_get_st), * and opal_using_threads conditioned (opal_free_list_get). */ -static inline opal_free_list_item_t *opal_free_list_get_mt (opal_free_list_t *flist) +static inline opal_free_list_item_t *opal_free_list_get_mt(opal_free_list_t *flist) { - opal_free_list_item_t *item = - (opal_free_list_item_t*) opal_lifo_pop_atomic (&flist->super); + opal_free_list_item_t *item = (opal_free_list_item_t *) opal_lifo_pop_atomic(&flist->super); if (OPAL_UNLIKELY(NULL == item)) { - opal_mutex_lock (&flist->fl_lock); - opal_free_list_grow_st (flist, flist->fl_num_per_alloc, &item); - opal_mutex_unlock (&flist->fl_lock); + opal_mutex_lock(&flist->fl_lock); + opal_free_list_grow_st(flist, flist->fl_num_per_alloc, &item); + opal_mutex_unlock(&flist->fl_lock); } return item; } -static inline opal_free_list_item_t *opal_free_list_get_st (opal_free_list_t *flist) +static inline opal_free_list_item_t *opal_free_list_get_st(opal_free_list_t *flist) { - opal_free_list_item_t *item = - (opal_free_list_item_t*) opal_lifo_pop_st (&flist->super); + opal_free_list_item_t *item = (opal_free_list_item_t *) opal_lifo_pop_st(&flist->super); if (OPAL_UNLIKELY(NULL == item)) { - opal_free_list_grow_st (flist, flist->fl_num_per_alloc, &item); + opal_free_list_grow_st(flist, flist->fl_num_per_alloc, &item); } return item; } -static inline opal_free_list_item_t *opal_free_list_get (opal_free_list_t *flist) +static inline opal_free_list_item_t *opal_free_list_get(opal_free_list_t *flist) { - if (opal_using_threads ()) { - return opal_free_list_get_mt (flist); + if (opal_using_threads()) { + return opal_free_list_get_mt(flist); } - return opal_free_list_get_st (flist); + return opal_free_list_get_st(flist); } /** compatibility macro */ -#define OPAL_FREE_LIST_GET(fl, item) \ - (item) = opal_free_list_get (fl) +#define OPAL_FREE_LIST_GET(fl, item) (item) = opal_free_list_get(fl) /** * Blocking call to obtain an item from a free list. @@ -247,27 +236,25 @@ static inline opal_free_list_item_t *opal_free_list_get (opal_free_list_t *flist */ /** compatibility macro */ -#define OPAL_FREE_LIST_WAIT(fl, item) \ - (item) = opal_free_list_wait (fl) +#define OPAL_FREE_LIST_WAIT(fl, item) (item) = opal_free_list_wait(fl) -static inline opal_free_list_item_t *opal_free_list_wait_mt (opal_free_list_t *fl) +static inline opal_free_list_item_t *opal_free_list_wait_mt(opal_free_list_t *fl) { - opal_free_list_item_t *item = - (opal_free_list_item_t *) opal_lifo_pop_atomic (&fl->super); + opal_free_list_item_t *item = (opal_free_list_item_t *) opal_lifo_pop_atomic(&fl->super); while (NULL == item) { - if (!opal_mutex_trylock (&fl->fl_lock)) { - if (fl->fl_max_to_alloc <= fl->fl_num_allocated || - OPAL_SUCCESS != opal_free_list_grow_st (fl, fl->fl_num_per_alloc, &item)) { + if (!opal_mutex_trylock(&fl->fl_lock)) { + if (fl->fl_max_to_alloc <= fl->fl_num_allocated + || OPAL_SUCCESS != opal_free_list_grow_st(fl, fl->fl_num_per_alloc, &item)) { fl->fl_num_waiting++; - opal_condition_wait (&fl->fl_condition, &fl->fl_lock); + opal_condition_wait(&fl->fl_condition, &fl->fl_lock); fl->fl_num_waiting--; } else { if (0 < fl->fl_num_waiting) { if (1 == fl->fl_num_waiting) { - opal_condition_signal (&fl->fl_condition); + opal_condition_signal(&fl->fl_condition); } else { - opal_condition_broadcast (&fl->fl_condition); + opal_condition_broadcast(&fl->fl_condition); } } } @@ -276,42 +263,41 @@ static inline opal_free_list_item_t *opal_free_list_wait_mt (opal_free_list_t *f * the one holding the lock in the begining already grow the list. I will * release the lock and try to get a new element until I succeed. */ - opal_mutex_lock (&fl->fl_lock); + opal_mutex_lock(&fl->fl_lock); } - opal_mutex_unlock (&fl->fl_lock); + opal_mutex_unlock(&fl->fl_lock); if (NULL == item) { - item = (opal_free_list_item_t *) opal_lifo_pop_atomic (&fl->super); + item = (opal_free_list_item_t *) opal_lifo_pop_atomic(&fl->super); } } return item; } -static inline opal_free_list_item_t *opal_free_list_wait_st (opal_free_list_t *fl) +static inline opal_free_list_item_t *opal_free_list_wait_st(opal_free_list_t *fl) { - opal_free_list_item_t *item = - (opal_free_list_item_t *) opal_lifo_pop (&fl->super); + opal_free_list_item_t *item = (opal_free_list_item_t *) opal_lifo_pop(&fl->super); while (NULL == item) { - if (fl->fl_max_to_alloc <= fl->fl_num_allocated || - OPAL_SUCCESS != opal_free_list_grow_st (fl, fl->fl_num_per_alloc, &item)) { + if (fl->fl_max_to_alloc <= fl->fl_num_allocated + || OPAL_SUCCESS != opal_free_list_grow_st(fl, fl->fl_num_per_alloc, &item)) { /* try to make progress */ - opal_progress (); + opal_progress(); } if (NULL == item) { - item = (opal_free_list_item_t *) opal_lifo_pop (&fl->super); + item = (opal_free_list_item_t *) opal_lifo_pop(&fl->super); } } return item; } -static inline opal_free_list_item_t *opal_free_list_wait (opal_free_list_t *fl) +static inline opal_free_list_item_t *opal_free_list_wait(opal_free_list_t *fl) { - if (opal_using_threads ()) { - return opal_free_list_wait_mt (fl); + if (opal_using_threads()) { + return opal_free_list_wait_mt(fl); } else { - return opal_free_list_wait_st (fl); + return opal_free_list_wait_st(fl); } } @@ -322,54 +308,49 @@ static inline opal_free_list_item_t *opal_free_list_wait (opal_free_list_t *fl) * @param item (OUT) Allocated item. * */ -static inline void opal_free_list_return_mt (opal_free_list_t *flist, - opal_free_list_item_t *item) +static inline void opal_free_list_return_mt(opal_free_list_t *flist, opal_free_list_item_t *item) { - opal_list_item_t* original; + opal_list_item_t *original; - original = opal_lifo_push_atomic (&flist->super, &item->super); + original = opal_lifo_push_atomic(&flist->super, &item->super); if (&flist->super.opal_lifo_ghost == original) { if (flist->fl_num_waiting > 0) { /* one one item is being returned so it doesn't make sense to wake * more than a single waiting thread. additionally, posix thread * semantics do not require that the lock be held to signal the * condition variable. */ - opal_condition_signal (&flist->fl_condition); + opal_condition_signal(&flist->fl_condition); } } } -static inline void opal_free_list_return_st (opal_free_list_t *flist, - opal_free_list_item_t *item) +static inline void opal_free_list_return_st(opal_free_list_t *flist, opal_free_list_item_t *item) { - opal_list_item_t* original; + opal_list_item_t *original; - original = opal_lifo_push_st (&flist->super, &item->super); + original = opal_lifo_push_st(&flist->super, &item->super); if (&flist->super.opal_lifo_ghost == original) { if (flist->fl_num_waiting > 0) { /* one one item is being returned so it doesn't make sense to wake * more than a single waiting thread. additionally, posix thread * semantics do not require that the lock be held to signal the * condition variable. */ - opal_condition_signal (&flist->fl_condition); + opal_condition_signal(&flist->fl_condition); } } } -static inline void opal_free_list_return (opal_free_list_t *flist, - opal_free_list_item_t *item) +static inline void opal_free_list_return(opal_free_list_t *flist, opal_free_list_item_t *item) { - if (opal_using_threads ()) { - opal_free_list_return_mt (flist, item); + if (opal_using_threads()) { + opal_free_list_return_mt(flist, item); } else { - opal_free_list_return_st (flist, item); + opal_free_list_return_st(flist, item); } } /** compatibility macro */ -#define OPAL_FREE_LIST_RETURN(fl, item) \ - opal_free_list_return (fl, item) +#define OPAL_FREE_LIST_RETURN(fl, item) opal_free_list_return(fl, item) END_C_DECLS #endif - diff --git a/opal/class/opal_graph.c b/opal/class/opal_graph.c index 8ee0e88702f..a6804d32e57 100644 --- a/opal/class/opal_graph.c +++ b/opal/class/opal_graph.c @@ -23,9 +23,9 @@ #include "opal_config.h" +#include "opal/class/opal_graph.h" #include "opal/class/opal_list.h" #include "opal/constants.h" -#include "opal/class/opal_graph.h" #include "opal/util/output.h" static int compare_vertex_distance(const void *item1, const void *item2); @@ -34,49 +34,28 @@ static int compare_vertex_distance(const void *item1, const void *item2); * Graph classes */ - static void opal_graph_vertex_construct(opal_graph_vertex_t *vertex); static void opal_graph_vertex_destruct(opal_graph_vertex_t *vertex); -OBJ_CLASS_INSTANCE( - opal_graph_vertex_t, - opal_list_item_t, - opal_graph_vertex_construct, - opal_graph_vertex_destruct -); - +OBJ_CLASS_INSTANCE(opal_graph_vertex_t, opal_list_item_t, opal_graph_vertex_construct, + opal_graph_vertex_destruct); static void opal_graph_edge_construct(opal_graph_edge_t *edge); static void opal_graph_edge_destruct(opal_graph_edge_t *edge); -OBJ_CLASS_INSTANCE( - opal_graph_edge_t, - opal_list_item_t, - opal_graph_edge_construct, - opal_graph_edge_destruct -); +OBJ_CLASS_INSTANCE(opal_graph_edge_t, opal_list_item_t, opal_graph_edge_construct, + opal_graph_edge_destruct); static void opal_graph_construct(opal_graph_t *graph); static void opal_graph_destruct(opal_graph_t *graph); -OBJ_CLASS_INSTANCE( - opal_graph_t, - opal_object_t, - opal_graph_construct, - opal_graph_destruct -); +OBJ_CLASS_INSTANCE(opal_graph_t, opal_object_t, opal_graph_construct, opal_graph_destruct); static void opal_adjacency_list_construct(opal_adjacency_list_t *aj_list); static void opal_adjacency_list_destruct(opal_adjacency_list_t *aj_list); -OBJ_CLASS_INSTANCE( - opal_adjacency_list_t, - opal_list_item_t, - opal_adjacency_list_construct, - opal_adjacency_list_destruct -); - - +OBJ_CLASS_INSTANCE(opal_adjacency_list_t, opal_list_item_t, opal_adjacency_list_construct, + opal_adjacency_list_destruct); /* * @@ -112,7 +91,6 @@ static void opal_graph_vertex_destruct(opal_graph_vertex_t *vertex) vertex->print_vertex = NULL; } - /* * * opal_graph_edge_t interface @@ -127,7 +105,6 @@ static void opal_graph_edge_construct(opal_graph_edge_t *edge) edge->in_adj_list = NULL; } - static void opal_graph_edge_destruct(opal_graph_edge_t *edge) { edge->end = NULL; @@ -136,14 +113,12 @@ static void opal_graph_edge_destruct(opal_graph_edge_t *edge) edge->in_adj_list = NULL; } - /* * * opal_graph_t interface * */ - static void opal_graph_construct(opal_graph_t *graph) { graph->adjacency_list = OBJ_NEW(opal_list_t); @@ -172,8 +147,8 @@ static void opal_adjacency_list_construct(opal_adjacency_list_t *aj_list) static void opal_adjacency_list_destruct(opal_adjacency_list_t *aj_list) { - aj_list->vertex = NULL; - OPAL_LIST_RELEASE(aj_list->edges); + aj_list->vertex = NULL; + OPAL_LIST_RELEASE(aj_list->edges); } /** @@ -191,17 +166,17 @@ static void delete_all_edges_conceded_to_vertex(opal_graph_t *graph, opal_graph_ /** * for all the adjacency list in the graph */ - OPAL_LIST_FOREACH(aj_list, graph->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, graph->adjacency_list, opal_adjacency_list_t) { /** * for all the edges in the adjacency list */ - OPAL_LIST_FOREACH_SAFE(edge, next, aj_list->edges, opal_graph_edge_t) { + OPAL_LIST_FOREACH_SAFE (edge, next, aj_list->edges, opal_graph_edge_t) { /** * if the edge is ended in the vertex */ if (edge->end == vertex) { /* Delete this edge */ - opal_list_remove_item(edge->in_adj_list->edges, (opal_list_item_t*)edge); + opal_list_remove_item(edge->in_adj_list->edges, (opal_list_item_t *) edge); /* distract this edge */ OBJ_RELEASE(edge); } @@ -218,30 +193,29 @@ static void delete_all_edges_conceded_to_vertex(opal_graph_t *graph, opal_graph_ */ void opal_graph_add_vertex(opal_graph_t *graph, opal_graph_vertex_t *vertex) { - opal_adjacency_list_t *aj_list; - - /** - * Find if this vertex already exists in the graph. - */ - OPAL_LIST_FOREACH(aj_list, graph->adjacency_list, opal_adjacency_list_t) { - if (aj_list->vertex == vertex) { - /* If this vertex exists, dont do anything. */ - return; - } - } - /* Construct a new adjacency list */ - aj_list = OBJ_NEW(opal_adjacency_list_t); - aj_list->vertex = vertex; - /* point the vertex to the adjacency list of the vertex (for easy searching) */ - vertex->in_adj_list = aj_list; - /* Append the new creates adjacency list to the graph */ - opal_list_append(graph->adjacency_list, (opal_list_item_t*)aj_list); - /* point the vertex to the graph it belongs to (mostly for debug uses)*/ - vertex->in_graph = graph; - /* increase the number of vertices in the graph */ - graph->number_of_vertices++; -} + opal_adjacency_list_t *aj_list; + /** + * Find if this vertex already exists in the graph. + */ + OPAL_LIST_FOREACH (aj_list, graph->adjacency_list, opal_adjacency_list_t) { + if (aj_list->vertex == vertex) { + /* If this vertex exists, dont do anything. */ + return; + } + } + /* Construct a new adjacency list */ + aj_list = OBJ_NEW(opal_adjacency_list_t); + aj_list->vertex = vertex; + /* point the vertex to the adjacency list of the vertex (for easy searching) */ + vertex->in_adj_list = aj_list; + /* Append the new creates adjacency list to the graph */ + opal_list_append(graph->adjacency_list, (opal_list_item_t *) aj_list); + /* point the vertex to the graph it belongs to (mostly for debug uses)*/ + vertex->in_graph = graph; + /* increase the number of vertices in the graph */ + graph->number_of_vertices++; +} /** * This graph API adds an edge (connection between two @@ -256,14 +230,13 @@ void opal_graph_add_vertex(opal_graph_t *graph, opal_graph_vertex_t *vertex) */ int opal_graph_add_edge(opal_graph_t *graph, opal_graph_edge_t *edge) { - opal_adjacency_list_t *aj_list, *start_aj_list= NULL; + opal_adjacency_list_t *aj_list, *start_aj_list = NULL; bool end_found = false; - /** * find the vertices that this edge should connect. */ - OPAL_LIST_FOREACH(aj_list, graph->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, graph->adjacency_list, opal_adjacency_list_t) { if (aj_list->vertex == edge->start) { start_aj_list = aj_list; } @@ -279,15 +252,14 @@ int opal_graph_add_edge(opal_graph_t *graph, opal_graph_edge_t *edge) return OPAL_ERROR; } /* point the edge to the adjacency list of the start vertex (for easy search) */ - edge->in_adj_list=start_aj_list; + edge->in_adj_list = start_aj_list; /* append the edge to the adjacency list of the start vertex */ - opal_list_append(start_aj_list->edges, (opal_list_item_t*)edge); + opal_list_append(start_aj_list->edges, (opal_list_item_t *) edge); /* increase the graph size */ graph->number_of_edges++; return OPAL_SUCCESS; } - /** * This graph API removes an edge (a connection between two * vertices) from the graph. The most common use of this API is @@ -299,10 +271,10 @@ int opal_graph_add_edge(opal_graph_t *graph, opal_graph_edge_t *edge) * @param graph The graph that this edge will be remove from. * @param edge the edge that we want to remove. */ -void opal_graph_remove_edge (opal_graph_t *graph, opal_graph_edge_t *edge) +void opal_graph_remove_edge(opal_graph_t *graph, opal_graph_edge_t *edge) { /* remove the edge from the list it belongs to */ - opal_list_remove_item(edge->in_adj_list->edges, (opal_list_item_t*)edge); + opal_list_remove_item(edge->in_adj_list->edges, (opal_list_item_t *) edge); /* decrees the number of edges in the graph */ graph->number_of_edges--; /* Note that the edge is not destructed - the caller should destruct this edge. */ @@ -328,7 +300,7 @@ void opal_graph_remove_vertex(opal_graph_t *graph, opal_graph_vertex_t *vertex) * remove the adjscency list of this vertex from the graph and * destruct it. */ - opal_list_remove_item(graph->adjacency_list, (opal_list_item_t*)adj_list); + opal_list_remove_item(graph->adjacency_list, (opal_list_item_t *) adj_list); OBJ_RELEASE(adj_list); /** * delete all the edges that connected *to* the vertex. @@ -351,7 +323,8 @@ void opal_graph_remove_vertex(opal_graph_t *graph, opal_graph_vertex_t *vertex) * vertices or infinity if the vertices are not * connected. */ -uint32_t opal_graph_adjacent(opal_graph_t *graph, opal_graph_vertex_t *vertex1, opal_graph_vertex_t *vertex2) +uint32_t opal_graph_adjacent(opal_graph_t *graph, opal_graph_vertex_t *vertex1, + opal_graph_vertex_t *vertex2) { opal_adjacency_list_t *adj_list; opal_graph_edge_t *edge; @@ -360,14 +333,16 @@ uint32_t opal_graph_adjacent(opal_graph_t *graph, opal_graph_vertex_t *vertex1, * Verify that the first vertex belongs to the graph. */ if (graph != vertex1->in_graph) { - OPAL_OUTPUT((0,"opal_graph_adjacent 1 Vertex1 %p not in the graph %p\n",(void *)vertex1,(void *)graph)); + OPAL_OUTPUT((0, "opal_graph_adjacent 1 Vertex1 %p not in the graph %p\n", (void *) vertex1, + (void *) graph)); return DISTANCE_INFINITY; } /** * Verify that the second vertex belongs to the graph. */ if (graph != vertex2->in_graph) { - OPAL_OUTPUT((0,"opal_graph_adjacent 2 Vertex2 %p not in the graph %p\n",(void *)vertex2,(void *)graph)); + OPAL_OUTPUT((0, "opal_graph_adjacent 2 Vertex2 %p not in the graph %p\n", (void *) vertex2, + (void *) graph)); return DISTANCE_INFINITY; } /** @@ -382,9 +357,10 @@ uint32_t opal_graph_adjacent(opal_graph_t *graph, opal_graph_vertex_t *vertex1, * vertex. */ adj_list = (opal_adjacency_list_t *) vertex1->in_adj_list; - OPAL_LIST_FOREACH(edge, adj_list->edges, opal_graph_edge_t) { + OPAL_LIST_FOREACH (edge, adj_list->edges, opal_graph_edge_t) { if (edge->end == vertex2) { - /* if the second vertex was found in the adjacency list of the first one, return the weight */ + /* if the second vertex was found in the adjacency list of the first one, return the + * weight */ return edge->weight; } } @@ -434,7 +410,7 @@ opal_graph_vertex_t *opal_graph_find_vertex(opal_graph_t *graph, void *vertex_da /** * Run on all the vertices of the graph */ - OPAL_LIST_FOREACH(aj_list, graph->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, graph->adjacency_list, opal_adjacency_list_t) { if (NULL != aj_list->vertex->compare_vertex) { /* if the vertex data of a vertex is equal to the vertex data */ if (0 == aj_list->vertex->compare_vertex(aj_list->vertex->vertex_data, vertex_data)) { @@ -447,7 +423,6 @@ opal_graph_vertex_t *opal_graph_find_vertex(opal_graph_t *graph, void *vertex_da return NULL; } - /** * This graph API returns an array of pointers of all the * vertices in the graph. @@ -471,9 +446,9 @@ int opal_graph_get_graph_vertices(opal_graph_t *graph, opal_pointer_array_t *ver return 0; } /* Run on all the vertices of the graph */ - OPAL_LIST_FOREACH(aj_list, graph->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, graph->adjacency_list, opal_adjacency_list_t) { /* Add the vertex to the vertices array */ - opal_pointer_array_add(vertices_list,(void *)aj_list->vertex); + opal_pointer_array_add(vertices_list, (void *) aj_list->vertex); } /* return the vertices list */ return graph->number_of_vertices; @@ -492,7 +467,8 @@ int opal_graph_get_graph_vertices(opal_graph_t *graph, opal_pointer_array_t *ver * * @return int the number of adjacents in the list. */ -int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *vertex, opal_value_array_t *adjacents) +int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *vertex, + opal_value_array_t *adjacents) { opal_adjacency_list_t *adj_list; opal_graph_edge_t *edge; @@ -503,7 +479,7 @@ int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *v * Verify that the vertex belongs to the graph. */ if (graph != vertex->in_graph) { - OPAL_OUTPUT((0,"Vertex %p not in the graph %p\n", (void *)vertex, (void *)graph)); + OPAL_OUTPUT((0, "Vertex %p not in the graph %p\n", (void *) vertex, (void *) graph)); return 0; } /** @@ -513,7 +489,7 @@ int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *v /* find the number of adjcents of this vertex */ adjacents_number = opal_list_get_size(adj_list->edges); /* Run on all the edges from this vertex */ - OPAL_LIST_FOREACH(edge, adj_list->edges, opal_graph_edge_t) { + OPAL_LIST_FOREACH (edge, adj_list->edges, opal_graph_edge_t) { /* assign vertices and their weight in the adjcents list */ distance_from.vertex = edge->end; distance_from.weight = edge->weight; @@ -533,7 +509,8 @@ int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *v * @return uint32_t the distance between the two vertices. */ -uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t *vertex1, opal_graph_vertex_t *vertex2) +uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t *vertex1, + opal_graph_vertex_t *vertex2) { opal_value_array_t *distance_array; uint32_t items_in_distance_array, spf = DISTANCE_INFINITY; @@ -544,14 +521,16 @@ uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t *vertex1, opal_ * Verify that the first vertex belongs to the graph. */ if (graph != vertex1->in_graph) { - OPAL_OUTPUT((0,"opal_graph_spf 1 Vertex1 %p not in the graph %p\n",(void *)vertex1,(void *)graph)); + OPAL_OUTPUT((0, "opal_graph_spf 1 Vertex1 %p not in the graph %p\n", (void *) vertex1, + (void *) graph)); return DISTANCE_INFINITY; } /** * Verify that the second vertex belongs to the graph. */ if (graph != vertex2->in_graph) { - OPAL_OUTPUT((0,"opal_graph_spf 2 Vertex2 %p not in the graph %p\n",(void *)vertex2,(void *)graph)); + OPAL_OUTPUT((0, "opal_graph_spf 2 Vertex2 %p not in the graph %p\n", (void *) vertex2, + (void *) graph)); return DISTANCE_INFINITY; } /** @@ -559,7 +538,7 @@ uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t *vertex1, opal_ */ distance_array = OBJ_NEW(opal_value_array_t); opal_value_array_init(distance_array, sizeof(vertex_distance_from_t)); - opal_value_array_reserve(distance_array,50); + opal_value_array_reserve(distance_array, 50); items_in_distance_array = opal_graph_dijkstra(graph, vertex1, distance_array); /** * find the end vertex in the distance array that Dijkstra @@ -595,8 +574,8 @@ static int compare_vertex_distance(const void *item1, const void *item2) vertex_distance_from_t *vertex_dist1, *vertex_dist2; /* convert the void pointers to vertex distance pointers. */ - vertex_dist1 = (vertex_distance_from_t *)item1; - vertex_dist2 = (vertex_distance_from_t *)item2; + vertex_dist1 = (vertex_distance_from_t *) item1; + vertex_dist2 = (vertex_distance_from_t *) item2; /* If the first item weight is higher then the second item weight return 1*/ if (vertex_dist1->weight > vertex_dist2->weight) { @@ -610,7 +589,6 @@ static int compare_vertex_distance(const void *item1, const void *item2) return -1; } - /** * This graph API returns the distance (weight) from a reference * vertex to all other vertices in the graph using the Dijkstra @@ -623,7 +601,8 @@ static int compare_vertex_distance(const void *item1, const void *item2) * * @return uint32_t the size of the distance array */ -uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, opal_value_array_t *distance_array) +uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, + opal_value_array_t *distance_array) { int graph_order; vertex_distance_from_t *Q, *q_start, *current_vertex; @@ -632,22 +611,22 @@ uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, o int i; uint32_t weight; - /** * Verify that the reference vertex belongs to the graph. */ if (graph != vertex->in_graph) { - OPAL_OUTPUT((0,"opal:graph:dijkstra: vertex %p not in the graph %p\n",(void *)vertex,(void *)graph)); + OPAL_OUTPUT((0, "opal:graph:dijkstra: vertex %p not in the graph %p\n", (void *) vertex, + (void *) graph)); return 0; } /* get the order of the graph and allocate a working queue accordingly */ graph_order = opal_graph_get_order(graph); - Q = (vertex_distance_from_t *)malloc(graph_order * sizeof(vertex_distance_from_t)); + Q = (vertex_distance_from_t *) malloc(graph_order * sizeof(vertex_distance_from_t)); /* assign a pointer to the start of the queue */ q_start = Q; /* run on all the vertices of the graph */ i = 0; - OPAL_LIST_FOREACH(adj_list, graph->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (adj_list, graph->adjacency_list, opal_adjacency_list_t) { /* insert the vertices pointes to the working queue */ Q[i].vertex = adj_list->vertex; /** @@ -667,7 +646,8 @@ uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, o q_start++; /* decrees the number of vertices in the queue */ number_of_items_in_q--; - /* find the distance of all other vertices in the queue from the first vertex in the queue */ + /* find the distance of all other vertices in the queue from the first vertex in the queue + */ for (i = 0; i < number_of_items_in_q; i++) { weight = opal_graph_adjacent(graph, current_vertex->vertex, q_start[i].vertex); /** @@ -682,11 +662,12 @@ uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, o } } /* sort again the working queue */ - qsort(q_start, number_of_items_in_q, sizeof(vertex_distance_from_t), compare_vertex_distance); + qsort(q_start, number_of_items_in_q, sizeof(vertex_distance_from_t), + compare_vertex_distance); } /* copy the working queue the the returned distance array */ - for (i = 0; i < graph_order-1; i++) { - opal_value_array_append_item(distance_array, (void *)&(Q[i+1])); + for (i = 0; i < graph_order - 1; i++) { + opal_value_array_append_item(distance_array, (void *) &(Q[i + 1])); } /* free the working queue */ free(Q); @@ -694,7 +675,6 @@ uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, o return graph_order - 1; } - /** * This graph API duplicates a graph. Note that this API does * not copy the graph but builds a new graph while coping just @@ -712,7 +692,7 @@ void opal_graph_duplicate(opal_graph_t **dest, opal_graph_t *src) /* construct a new graph */ *dest = OBJ_NEW(opal_graph_t); /* Run on all the vertices of the src graph */ - OPAL_LIST_FOREACH(aj_list, src->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, src->adjacency_list, opal_adjacency_list_t) { /* for each vertex in the src graph, construct a new vertex */ vertex = OBJ_NEW(opal_graph_vertex_t); /* associate the new vertex to a vertex from the original graph */ @@ -741,14 +721,15 @@ void opal_graph_duplicate(opal_graph_t **dest, opal_graph_t *src) * Now, copy all the edges from the source graph */ /* Run on all the adjscency lists in the graph */ - OPAL_LIST_FOREACH(aj_list, src->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, src->adjacency_list, opal_adjacency_list_t) { /* for all the edges in the adjscency list */ - OPAL_LIST_FOREACH(edge, aj_list->edges, opal_graph_edge_t) { + OPAL_LIST_FOREACH (edge, aj_list->edges, opal_graph_edge_t) { /* construct new edge for the new graph */ new_edge = OBJ_NEW(opal_graph_edge_t); /* copy the edge weight from the original edge */ new_edge->weight = edge->weight; - /* connect the new edge according to start and end associations to the vertices of the src graph */ + /* connect the new edge according to start and end associations to the vertices of the + * src graph */ new_edge->start = edge->start->sibling; new_edge->end = edge->end->sibling; /* add the new edge to the new graph */ @@ -772,31 +753,29 @@ void opal_graph_print(opal_graph_t *graph) opal_output(0, " Graph "); opal_output(0, "===================="); /* run on all the vertices of the graph */ - OPAL_LIST_FOREACH(aj_list, graph->adjacency_list, opal_adjacency_list_t) { + OPAL_LIST_FOREACH (aj_list, graph->adjacency_list, opal_adjacency_list_t) { /* print vertex data to temporary string*/ if (NULL != aj_list->vertex->print_vertex) { need_free1 = true; tmp_str1 = aj_list->vertex->print_vertex(aj_list->vertex->vertex_data); - } - else { + } else { need_free1 = false; tmp_str1 = ""; } /* print vertex */ - opal_output(0, "V(%s) Connections:",tmp_str1); + opal_output(0, "V(%s) Connections:", tmp_str1); /* run on all the edges of the vertex */ - OPAL_LIST_FOREACH(edge, aj_list->edges, opal_graph_edge_t) { + OPAL_LIST_FOREACH (edge, aj_list->edges, opal_graph_edge_t) { /* print the vertex data of the vertex in the end of the edge to a temporary string */ if (NULL != edge->end->print_vertex) { need_free2 = true; tmp_str2 = edge->end->print_vertex(edge->end->vertex_data); - } - else { + } else { need_free2 = false; tmp_str2 = ""; } /* print the edge */ - opal_output(0, " E(%s -> %d -> %s)",tmp_str1, edge->weight, tmp_str2); + opal_output(0, " E(%s -> %d -> %s)", tmp_str1, edge->weight, tmp_str2); if (need_free2) { free(tmp_str2); } @@ -806,4 +785,3 @@ void opal_graph_print(opal_graph_t *graph) } } } - diff --git a/opal/class/opal_graph.h b/opal/class/opal_graph.h index 47b5f54bdb9..13548edf2c4 100644 --- a/opal/class/opal_graph.h +++ b/opal/class/opal_graph.h @@ -28,39 +28,39 @@ #define OPAL_GRAPH_H #include "opal_config.h" -#include -#include -#include "opal/class/opal_object.h" #include "opal/class/opal_list.h" +#include "opal/class/opal_object.h" #include "opal/class/opal_pointer_array.h" #include "opal/class/opal_value_array.h" +#include +#include BEGIN_C_DECLS - /* When two vertices are not connected, the distance between them is infinite. */ +/* When two vertices are not connected, the distance between them is infinite. */ #define DISTANCE_INFINITY 0x7fffffff - /* A class for vertex */ +/* A class for vertex */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_graph_vertex_t); - /* A class for an edge (a connection between two verices) */ +/* A class for an edge (a connection between two verices) */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_graph_edge_t); - /* A class for an adjacency list */ +/* A class for an adjacency list */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_adjacency_list_t); - /* A class for graph */ +/* A class for graph */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_graph_t); - /** - * Function pointer for coping a vertex data from one vertex to - * another - * - * @param dst The destination pointer of vertex_data - * @param src The source pointer of the vertex_data - * - * - */ +/** + * Function pointer for coping a vertex data from one vertex to + * another + * + * @param dst The destination pointer of vertex_data + * @param src The source pointer of the vertex_data + * + * + */ typedef void (*opal_graph_copy_vertex_data)(void **dst, void *src); /** @@ -88,7 +88,7 @@ typedef void *(*opal_graph_alloc_vertex_data)(void); * vertex_data2 and -1- vertex_data1 is smaller the * vertex_data2. */ -typedef int (*opal_graph_compare_vertex_data)(void *vertex_data1, void *vertex_data2); +typedef int (*opal_graph_compare_vertex_data)(void *vertex_data1, void *vertex_data2); /** * print a vertex data. @@ -97,24 +97,24 @@ typedef int (*opal_graph_compare_vertex_data)(void *vertex_data1, void *vertex_ */ typedef char *(*opal_graph_print_vertex)(void *vertex_data); - /** * A vertex class. */ struct opal_graph_vertex_t { - opal_list_item_t super; /* A pointer to a vertex parent */ - void *in_graph; /* A pointer to the graph that this vertex belongs to */ - void *in_adj_list; /* A pointer to the adjacency that this vertex belongs to */ - void *vertex_data;/* A pointer to some data. this pointer can point to the struct the this*/ - /* vertex belongs to*/ - struct opal_graph_vertex_t *sibling;/* A pointer to a sibling vertex. */ - /* if this vertex was copied this pointer will point to the source vertex */ - /* This pointer is for internal uses. */ - opal_graph_copy_vertex_data copy_vertex_data; /* A function to copy vertex data */ - opal_graph_free_vertex_data free_vertex_data; /* A function to print vertex data */ - opal_graph_alloc_vertex_data alloc_vertex_data;/* A function to allocate vertex data */ - opal_graph_compare_vertex_data compare_vertex; /* A function to compare between two vertices data */ - opal_graph_print_vertex print_vertex; /* A function to print vertex data */ + opal_list_item_t super; /* A pointer to a vertex parent */ + void *in_graph; /* A pointer to the graph that this vertex belongs to */ + void *in_adj_list; /* A pointer to the adjacency that this vertex belongs to */ + void *vertex_data; /* A pointer to some data. this pointer can point to the struct the this*/ + /* vertex belongs to*/ + struct opal_graph_vertex_t *sibling; /* A pointer to a sibling vertex. */ + /* if this vertex was copied this pointer will point to the source vertex */ + /* This pointer is for internal uses. */ + opal_graph_copy_vertex_data copy_vertex_data; /* A function to copy vertex data */ + opal_graph_free_vertex_data free_vertex_data; /* A function to print vertex data */ + opal_graph_alloc_vertex_data alloc_vertex_data; /* A function to allocate vertex data */ + opal_graph_compare_vertex_data + compare_vertex; /* A function to compare between two vertices data */ + opal_graph_print_vertex print_vertex; /* A function to print vertex data */ }; /** @@ -126,9 +126,9 @@ typedef struct opal_graph_vertex_t opal_graph_vertex_t; * An opal_adjacency_list_t class */ struct opal_adjacency_list_t { - opal_list_item_t super; /* A pointer to vertex parent */ - opal_graph_vertex_t *vertex; /* The adjacency_list is for adjacent of this vertex */ - opal_list_t *edges; /* An edge list for all the adjacent and their weights */ + opal_list_item_t super; /* A pointer to vertex parent */ + opal_graph_vertex_t *vertex; /* The adjacency_list is for adjacent of this vertex */ + opal_list_t *edges; /* An edge list for all the adjacent and their weights */ }; /** @@ -144,13 +144,13 @@ typedef struct opal_adjacency_list_t opal_adjacency_list_t; * contains a weight field. */ struct opal_graph_edge_t { - opal_list_item_t super; /* A pointer to the edge parent */ - opal_graph_vertex_t *start; /* The start vertex. */ - opal_graph_vertex_t *end; /* The end vertex */ - uint32_t weight; /* The weight of this edge */ - opal_adjacency_list_t *in_adj_list; /* The adjacency list in witch this edge in.*/ - /* This adjacency list contains the start vertex of this edge*/ - /* and its for internal uses */ + opal_list_item_t super; /* A pointer to the edge parent */ + opal_graph_vertex_t *start; /* The start vertex. */ + opal_graph_vertex_t *end; /* The end vertex */ + uint32_t weight; /* The weight of this edge */ + opal_adjacency_list_t *in_adj_list; /* The adjacency list in witch this edge in.*/ + /* This adjacency list contains the start vertex of this edge*/ + /* and its for internal uses */ }; /** @@ -158,15 +158,14 @@ struct opal_graph_edge_t { */ typedef struct opal_graph_edge_t opal_graph_edge_t; - /** * A graph class. */ struct opal_graph_t { - opal_object_t super; - opal_list_t *adjacency_list; - int number_of_edges; - int number_of_vertices; + opal_object_t super; + opal_list_t *adjacency_list; + int number_of_edges; + int number_of_vertices; }; /** @@ -180,7 +179,7 @@ typedef struct opal_graph_t opal_graph_t; */ struct vertex_distance_from_t { opal_graph_vertex_t *vertex; - uint32_t weight; + uint32_t weight; }; /** @@ -231,7 +230,7 @@ OPAL_DECLSPEC int opal_graph_add_edge(opal_graph_t *graph, opal_graph_edge_t *ed * @param graph The graph that this edge will be remove from. * @param edge the edge that we want to remove. */ -OPAL_DECLSPEC void opal_graph_remove_edge (opal_graph_t *graph, opal_graph_edge_t *edge); +OPAL_DECLSPEC void opal_graph_remove_edge(opal_graph_t *graph, opal_graph_edge_t *edge); /** * This graph API tell us if two vertices are adjacent @@ -244,7 +243,8 @@ OPAL_DECLSPEC void opal_graph_remove_edge (opal_graph_t *graph, opal_graph_edge_ * vertices or infinity if the vertices are not * connected. */ -OPAL_DECLSPEC uint32_t opal_graph_adjacent(opal_graph_t *graph, opal_graph_vertex_t *vertex1, opal_graph_vertex_t *vertex2); +OPAL_DECLSPEC uint32_t opal_graph_adjacent(opal_graph_t *graph, opal_graph_vertex_t *vertex1, + opal_graph_vertex_t *vertex2); /** * This Graph API returns the order of the graph (number of @@ -277,7 +277,6 @@ OPAL_DECLSPEC int opal_graph_get_size(opal_graph_t *graph); */ OPAL_DECLSPEC opal_graph_vertex_t *opal_graph_find_vertex(opal_graph_t *graph, void *vertex_data); - /** * This graph API returns an array of pointers of all the * vertices in the graph. @@ -290,7 +289,8 @@ OPAL_DECLSPEC opal_graph_vertex_t *opal_graph_find_vertex(opal_graph_t *graph, v * @return int returning the graph order (the * number of vertices in the returned array) */ -OPAL_DECLSPEC int opal_graph_get_graph_vertices(opal_graph_t *graph, opal_pointer_array_t *vertices_list); +OPAL_DECLSPEC int opal_graph_get_graph_vertices(opal_graph_t *graph, + opal_pointer_array_t *vertices_list); /** * This graph API returns all the adjacent of a vertex and the @@ -305,7 +305,8 @@ OPAL_DECLSPEC int opal_graph_get_graph_vertices(opal_graph_t *graph, opal_pointe * * @return int the number of adjacent in the list. */ -OPAL_DECLSPEC int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *vertex, opal_value_array_t *adjacent); +OPAL_DECLSPEC int opal_graph_get_adjacent_vertices(opal_graph_t *graph, opal_graph_vertex_t *vertex, + opal_value_array_t *adjacent); /** * This graph API duplicates a graph. Note that this API does @@ -326,7 +327,8 @@ OPAL_DECLSPEC void opal_graph_duplicate(opal_graph_t **dest, opal_graph_t *src); * * @return uint32_t the distance between the two vertices. */ -OPAL_DECLSPEC uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t *vertex1, opal_graph_vertex_t *vertex2); +OPAL_DECLSPEC uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t *vertex1, + opal_graph_vertex_t *vertex2); /** * This graph API returns the distance (weight) from a reference @@ -340,7 +342,8 @@ OPAL_DECLSPEC uint32_t opal_graph_spf(opal_graph_t *graph, opal_graph_vertex_t * * * @return uint32_t the size of the distance array */ -OPAL_DECLSPEC uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, opal_value_array_t *distance_array); +OPAL_DECLSPEC uint32_t opal_graph_dijkstra(opal_graph_t *graph, opal_graph_vertex_t *vertex, + opal_value_array_t *distance_array); /** * This graph API prints a graph - mostly for debug uses. @@ -350,6 +353,4 @@ OPAL_DECLSPEC void opal_graph_print(opal_graph_t *graph); END_C_DECLS - #endif /* OPAL_GRAPH_H */ - diff --git a/opal/class/opal_hash_table.c b/opal/class/opal_hash_table.c index 628440dc1fa..9912332b361 100644 --- a/opal/class/opal_hash_table.c +++ b/opal/class/opal_hash_table.c @@ -24,12 +24,12 @@ #include "opal_config.h" -#include #include +#include -#include "opal/util/output.h" #include "opal/class/opal_hash_table.h" #include "opal/constants.h" +#include "opal/util/output.h" /* * opal_hash_table_t @@ -92,16 +92,16 @@ */ struct opal_hash_element_t { - int valid; /* whether this element is valid */ - union { /* the key, in its various forms */ - uint32_t u32; - uint64_t u64; + int valid; /* whether this element is valid */ + union { /* the key, in its various forms */ + uint32_t u32; + uint64_t u64; struct { - const void * key; - size_t key_size; - } ptr; - } key; - void * value; /* the value */ + const void *key; + size_t key_size; + } ptr; + } key; + void *value; /* the value */ }; typedef struct opal_hash_element_t opal_hash_element_t; @@ -110,35 +110,29 @@ struct opal_hash_type_methods_t { * The value is not owned by the hash table * The key,key_size of pointer keys is */ - void (*elt_destructor)(opal_hash_element_t * elt); + void (*elt_destructor)(opal_hash_element_t *elt); /* Hash the key of the element -- for growing and adjusting-after-removal */ - uint64_t (*hash_elt)(opal_hash_element_t * elt); + uint64_t (*hash_elt)(opal_hash_element_t *elt); }; /* interact with the class-like mechanism */ -static void opal_hash_table_construct(opal_hash_table_t* ht); -static void opal_hash_table_destruct(opal_hash_table_t* ht); +static void opal_hash_table_construct(opal_hash_table_t *ht); +static void opal_hash_table_destruct(opal_hash_table_t *ht); -OBJ_CLASS_INSTANCE( - opal_hash_table_t, - opal_object_t, - opal_hash_table_construct, - opal_hash_table_destruct -); +OBJ_CLASS_INSTANCE(opal_hash_table_t, opal_object_t, opal_hash_table_construct, + opal_hash_table_destruct); -static void -opal_hash_table_construct(opal_hash_table_t* ht) +static void opal_hash_table_construct(opal_hash_table_t *ht) { - ht->ht_table = NULL; - ht->ht_capacity = ht->ht_size = ht->ht_growth_trigger = 0; - ht->ht_density_numer = ht->ht_density_denom = 0; - ht->ht_growth_numer = ht->ht_growth_denom = 0; - ht->ht_type_methods = NULL; + ht->ht_table = NULL; + ht->ht_capacity = ht->ht_size = ht->ht_growth_trigger = 0; + ht->ht_density_numer = ht->ht_density_denom = 0; + ht->ht_growth_numer = ht->ht_growth_denom = 0; + ht->ht_type_methods = NULL; } -static void -opal_hash_table_destruct(opal_hash_table_t* ht) +static void opal_hash_table_destruct(opal_hash_table_t *ht) { opal_hash_table_remove_all(ht); free(ht->ht_table); @@ -148,49 +142,47 @@ opal_hash_table_destruct(opal_hash_table_t* ht) * Init, etc */ -static size_t -opal_hash_round_capacity_up(size_t capacity) +static size_t opal_hash_round_capacity_up(size_t capacity) { /* round up to (1 mod 30) */ - return ((capacity+29)/30*30 + 1); + return ((capacity + 29) / 30 * 30 + 1); } /* this could be the new init if people wanted a more general API */ /* (that's why it isn't static) */ -int /* OPAL_ return code */ -opal_hash_table_init2(opal_hash_table_t* ht, size_t estimated_max_size, - int density_numer, int density_denom, - int growth_numer, int growth_denom) +int /* OPAL_ return code */ +opal_hash_table_init2(opal_hash_table_t *ht, size_t estimated_max_size, int density_numer, + int density_denom, int growth_numer, int growth_denom) { size_t est_capacity = estimated_max_size * density_denom / density_numer; size_t capacity = opal_hash_round_capacity_up(est_capacity); - ht->ht_table = (opal_hash_element_t*) calloc(capacity, sizeof(opal_hash_element_t)); + ht->ht_table = (opal_hash_element_t *) calloc(capacity, sizeof(opal_hash_element_t)); if (NULL == ht->ht_table) { return OPAL_ERR_OUT_OF_RESOURCE; } - ht->ht_capacity = capacity; - ht->ht_density_numer = density_numer; - ht->ht_density_denom = density_denom; - ht->ht_growth_numer = growth_numer; - ht->ht_growth_denom = growth_denom; + ht->ht_capacity = capacity; + ht->ht_density_numer = density_numer; + ht->ht_density_denom = density_denom; + ht->ht_growth_numer = growth_numer; + ht->ht_growth_denom = growth_denom; ht->ht_growth_trigger = capacity * density_numer / density_denom; - ht->ht_type_methods = NULL; + ht->ht_type_methods = NULL; return OPAL_SUCCESS; } -int /* OPAL_ return code */ -opal_hash_table_init(opal_hash_table_t* ht, size_t table_size) +int /* OPAL_ return code */ +opal_hash_table_init(opal_hash_table_t *ht, size_t table_size) { /* default to density of 1/2 and growth of 2/1 */ return opal_hash_table_init2(ht, table_size, 1, 2, 2, 1); } -int /* OPAL_ return code */ -opal_hash_table_remove_all(opal_hash_table_t* ht) +int /* OPAL_ return code */ +opal_hash_table_remove_all(opal_hash_table_t *ht) { size_t ii; for (ii = 0; ii < ht->ht_capacity; ii += 1) { - opal_hash_element_t * elt = &ht->ht_table[ii]; + opal_hash_element_t *elt = &ht->ht_table[ii]; if (elt->valid && ht->ht_type_methods && ht->ht_type_methods->elt_destructor) { ht->ht_type_methods->elt_destructor(elt); } @@ -204,22 +196,22 @@ opal_hash_table_remove_all(opal_hash_table_t* ht) return OPAL_SUCCESS; } -static int /* OPAL_ return code */ -opal_hash_grow(opal_hash_table_t * ht) +static int /* OPAL_ return code */ +opal_hash_grow(opal_hash_table_t *ht) { size_t jj, ii; - opal_hash_element_t* old_table; - opal_hash_element_t* new_table; + opal_hash_element_t *old_table; + opal_hash_element_t *new_table; size_t old_capacity; size_t new_capacity; - old_table = ht->ht_table; + old_table = ht->ht_table; old_capacity = ht->ht_capacity; new_capacity = old_capacity * ht->ht_growth_numer / ht->ht_growth_denom; new_capacity = opal_hash_round_capacity_up(new_capacity); - new_table = (opal_hash_element_t*) calloc(new_capacity, sizeof(new_table[0])); + new_table = (opal_hash_element_t *) calloc(new_capacity, sizeof(new_table[0])); if (NULL == new_table) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -233,14 +225,16 @@ opal_hash_grow(opal_hash_table_t * ht) deleted, so we still own the ptr key storage, just in the new table now */ for (jj = 0; jj < old_capacity; jj += 1) { - opal_hash_element_t * old_elt; - opal_hash_element_t * new_elt; - old_elt = &old_table[jj]; + opal_hash_element_t *old_elt; + opal_hash_element_t *new_elt; + old_elt = &old_table[jj]; if (old_elt->valid) { - for (ii = (ht->ht_type_methods->hash_elt(old_elt)%new_capacity); ; ii += 1) { - if (ii == new_capacity) { ii = 0; } + for (ii = (ht->ht_type_methods->hash_elt(old_elt) % new_capacity);; ii += 1) { + if (ii == new_capacity) { + ii = 0; + } new_elt = &new_table[ii]; - if (! new_elt->valid) { + if (!new_elt->valid) { *new_elt = *old_elt; break; } @@ -259,16 +253,16 @@ opal_hash_grow(opal_hash_table_t * ht) removed. With the help of the type methods this can be generic. The important thing is to rehash any valid elements immediately following the element-being-removed */ -static int /* OPAL_ return code */ -opal_hash_table_remove_elt_at(opal_hash_table_t * ht, size_t ii) +static int /* OPAL_ return code */ +opal_hash_table_remove_elt_at(opal_hash_table_t *ht, size_t ii) { size_t jj, capacity = ht->ht_capacity; - opal_hash_element_t* elts = ht->ht_table; - opal_hash_element_t * elt; + opal_hash_element_t *elts = ht->ht_table; + opal_hash_element_t *elt; elt = &elts[ii]; - if (! elt->valid) { + if (!elt->valid) { /* huh? removing a not-valid element? */ return OPAL_ERROR; } @@ -288,19 +282,23 @@ opal_hash_table_remove_elt_at(opal_hash_table_t * ht, size_t ii) * then z moves down a little: XYyabCz.. * then . means we're done */ - for (ii = ii+1; ; ii += 1) { /* scan immediately following elements */ - if (ii == capacity) { ii = 0; } + for (ii = ii + 1;; ii += 1) { /* scan immediately following elements */ + if (ii == capacity) { + ii = 0; + } elt = &elts[ii]; - if (! elt->valid) { - break; /* done */ + if (!elt->valid) { + break; /* done */ } /* rehash it and move it if necessary */ - for (jj = ht->ht_type_methods->hash_elt(elt)%capacity; ; jj += 1) { - if (jj == capacity) { jj = 0; } + for (jj = ht->ht_type_methods->hash_elt(elt) % capacity;; jj += 1) { + if (jj == capacity) { + jj = 0; + } if (jj == ii) { /* already in place, either ideal or best-for-now */ break; - } else if (! elts[jj].valid) { + } else if (!elts[jj].valid) { /* move it down, and invaildate where it came from */ elts[jj] = elts[ii]; elts[ii].valid = 0; @@ -314,46 +312,42 @@ opal_hash_table_remove_elt_at(opal_hash_table_t * ht, size_t ii) return OPAL_SUCCESS; } - /***************************************************************************/ -static uint64_t -opal_hash_hash_elt_uint32(opal_hash_element_t * elt) +static uint64_t opal_hash_hash_elt_uint32(opal_hash_element_t *elt) { - return elt->key.u32; + return elt->key.u32; } -static const struct opal_hash_type_methods_t -opal_hash_type_methods_uint32 = { - NULL, - opal_hash_hash_elt_uint32 -}; +static const struct opal_hash_type_methods_t opal_hash_type_methods_uint32 + = {NULL, opal_hash_hash_elt_uint32}; -int /* OPAL_ return code */ -opal_hash_table_get_value_uint32(opal_hash_table_t* ht, uint32_t key, void * *value) +int /* OPAL_ return code */ +opal_hash_table_get_value_uint32(opal_hash_table_t *ht, uint32_t key, void **value) { size_t ii, capacity = ht->ht_capacity; - opal_hash_element_t * elt; + opal_hash_element_t *elt; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_get_value_uint32:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERROR; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_uint32 != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_uint32 != ht->ht_type_methods) { opal_output(0, "opal_hash_table_get_value_uint32:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_uint32; - for (ii = key%capacity; ; ii += 1) { - if (ii == capacity) { ii = 0; } + for (ii = key % capacity;; ii += 1) { + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { return OPAL_ERR_NOT_FOUND; } else if (elt->key.u32 == key) { *value = elt->value; @@ -362,35 +356,35 @@ opal_hash_table_get_value_uint32(opal_hash_table_t* ht, uint32_t key, void * *va /* keey looking */ } } - } -int /* OPAL_ return code */ -opal_hash_table_set_value_uint32(opal_hash_table_t * ht, uint32_t key, void * value) +int /* OPAL_ return code */ +opal_hash_table_set_value_uint32(opal_hash_table_t *ht, uint32_t key, void *value) { int rc; size_t ii, capacity = ht->ht_capacity; - opal_hash_element_t * elt; + opal_hash_element_t *elt; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_set_value_uint32:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERR_BAD_PARAM; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_uint32 != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_uint32 != ht->ht_type_methods) { opal_output(0, "opal_hash_table_set_value_uint32:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_uint32; - for (ii = key%capacity; ; ii += 1) { - if (ii == capacity) { ii = 0; } + for (ii = key % capacity;; ii += 1) { + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { /* new entry */ elt->key.u32 = key; elt->value = value; @@ -412,31 +406,31 @@ opal_hash_table_set_value_uint32(opal_hash_table_t * ht, uint32_t key, void * va } } -int -opal_hash_table_remove_value_uint32(opal_hash_table_t * ht, uint32_t key) +int opal_hash_table_remove_value_uint32(opal_hash_table_t *ht, uint32_t key) { size_t ii, capacity = ht->ht_capacity; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_get_value_uint32:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERROR; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_uint32 != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_uint32 != ht->ht_type_methods) { opal_output(0, "opal_hash_table_remove_value_uint32:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_uint32; - for (ii = key%capacity; ; ii += 1) { - opal_hash_element_t * elt; - if (ii == capacity) ii = 0; + for (ii = key % capacity;; ii += 1) { + opal_hash_element_t *elt; + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { return OPAL_ERR_NOT_FOUND; } else if (elt->key.u32 == key) { return opal_hash_table_remove_elt_at(ht, ii); @@ -446,48 +440,43 @@ opal_hash_table_remove_value_uint32(opal_hash_table_t * ht, uint32_t key) } } - /***************************************************************************/ - -static uint64_t -opal_hash_hash_elt_uint64(opal_hash_element_t * elt) +static uint64_t opal_hash_hash_elt_uint64(opal_hash_element_t *elt) { - return elt->key.u64; + return elt->key.u64; } -static const struct opal_hash_type_methods_t -opal_hash_type_methods_uint64 = { - NULL, - opal_hash_hash_elt_uint64 -}; +static const struct opal_hash_type_methods_t opal_hash_type_methods_uint64 + = {NULL, opal_hash_hash_elt_uint64}; -int /* OPAL_ return code */ -opal_hash_table_get_value_uint64(opal_hash_table_t * ht, uint64_t key, void * *value) +int /* OPAL_ return code */ +opal_hash_table_get_value_uint64(opal_hash_table_t *ht, uint64_t key, void **value) { size_t ii; size_t capacity = ht->ht_capacity; - opal_hash_element_t * elt; + opal_hash_element_t *elt; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_get_value_uint64:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERROR; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_uint64 != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_uint64 != ht->ht_type_methods) { opal_output(0, "opal_hash_table_get_value_uint64:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_uint64; - for (ii = key%capacity; ; ii += 1) { - if (ii == capacity) { ii = 0; } + for (ii = key % capacity;; ii += 1) { + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { return OPAL_ERR_NOT_FOUND; } else if (elt->key.u64 == key) { *value = elt->value; @@ -496,35 +485,35 @@ opal_hash_table_get_value_uint64(opal_hash_table_t * ht, uint64_t key, void * *v /* keep looking */ } } - } -int /* OPAL_ return code */ -opal_hash_table_set_value_uint64(opal_hash_table_t * ht, uint64_t key, void * value) +int /* OPAL_ return code */ +opal_hash_table_set_value_uint64(opal_hash_table_t *ht, uint64_t key, void *value) { int rc; size_t ii, capacity = ht->ht_capacity; - opal_hash_element_t * elt; + opal_hash_element_t *elt; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_set_value_uint64:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERR_BAD_PARAM; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_uint64 != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_uint64 != ht->ht_type_methods) { opal_output(0, "opal_hash_table_set_value_uint64:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_uint64; - for (ii = key%capacity; ; ii += 1) { - if (ii == capacity) { ii = 0; } + for (ii = key % capacity;; ii += 1) { + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { /* new entry */ elt->key.u64 = key; elt->value = value; @@ -545,32 +534,32 @@ opal_hash_table_set_value_uint64(opal_hash_table_t * ht, uint64_t key, void * va } } - -int /* OPAL_ return code */ -opal_hash_table_remove_value_uint64(opal_hash_table_t * ht, uint64_t key) +int /* OPAL_ return code */ +opal_hash_table_remove_value_uint64(opal_hash_table_t *ht, uint64_t key) { size_t ii, capacity = ht->ht_capacity; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_get_value_uint64:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERROR; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_uint64 != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_uint64 != ht->ht_type_methods) { opal_output(0, "opal_hash_table_remove_value_uint64:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_uint64; - for (ii = key%capacity; ; ii += 1) { - opal_hash_element_t * elt; - if (ii == capacity) { ii = 0; } + for (ii = key % capacity;; ii += 1) { + opal_hash_element_t *elt; + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { return OPAL_ERR_NOT_FOUND; } else if (elt->key.u64 == key) { return opal_hash_table_remove_elt_at(ht, ii); @@ -580,80 +569,72 @@ opal_hash_table_remove_value_uint64(opal_hash_table_t * ht, uint64_t key) } } - /***************************************************************************/ /* helper function used in several places */ -static uint64_t -opal_hash_hash_key_ptr(const void * key, size_t key_size) +static uint64_t opal_hash_hash_key_ptr(const void *key, size_t key_size) { uint64_t hash; const unsigned char *scanner; size_t ii; hash = 0; - scanner = (const unsigned char *)key; + scanner = (const unsigned char *) key; for (ii = 0; ii < key_size; ii += 1) { - hash = HASH_MULTIPLIER*hash + *scanner++; + hash = HASH_MULTIPLIER * hash + *scanner++; } return hash; } /* ptr methods */ -static void -opal_hash_destruct_elt_ptr(opal_hash_element_t * elt) +static void opal_hash_destruct_elt_ptr(opal_hash_element_t *elt) { elt->key.ptr.key_size = 0; - void * key = (void *) elt->key.ptr.key; /* cast away const so we can free it */ + void *key = (void *) elt->key.ptr.key; /* cast away const so we can free it */ if (NULL != key) { elt->key.ptr.key = NULL; free(key); } } -static uint64_t -opal_hash_hash_elt_ptr(opal_hash_element_t * elt) +static uint64_t opal_hash_hash_elt_ptr(opal_hash_element_t *elt) { return opal_hash_hash_key_ptr(elt->key.ptr.key, elt->key.ptr.key_size); } -static const struct opal_hash_type_methods_t -opal_hash_type_methods_ptr = { - opal_hash_destruct_elt_ptr, - opal_hash_hash_elt_ptr -}; +static const struct opal_hash_type_methods_t opal_hash_type_methods_ptr + = {opal_hash_destruct_elt_ptr, opal_hash_hash_elt_ptr}; -int /* OPAL_ return code */ -opal_hash_table_get_value_ptr(opal_hash_table_t * ht, - const void * key, size_t key_size, - void * *value) +int /* OPAL_ return code */ +opal_hash_table_get_value_ptr(opal_hash_table_t *ht, const void *key, size_t key_size, void **value) { size_t ii, capacity = ht->ht_capacity; - opal_hash_element_t * elt; + opal_hash_element_t *elt; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_get_value_ptr:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERROR; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_ptr != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_ptr != ht->ht_type_methods) { opal_output(0, "opal_hash_table_get_value_ptr:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_ptr; - for (ii = opal_hash_hash_key_ptr(key, key_size)%capacity; ; ii += 1) { - if (ii == capacity) { ii = 0; } + for (ii = opal_hash_hash_key_ptr(key, key_size) % capacity;; ii += 1) { + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { return OPAL_ERR_NOT_FOUND; - } else if (elt->key.ptr.key_size == key_size && - 0 == memcmp(elt->key.ptr.key, key, key_size)) { + } else if (elt->key.ptr.key_size == key_size + && 0 == memcmp(elt->key.ptr.key, key, key_size)) { *value = elt->value; return OPAL_SUCCESS; } else { @@ -662,38 +643,37 @@ opal_hash_table_get_value_ptr(opal_hash_table_t * ht, } } -int /* OPAL_ return code */ -opal_hash_table_set_value_ptr(opal_hash_table_t * ht, - const void * key, size_t key_size, - void * value) +int /* OPAL_ return code */ +opal_hash_table_set_value_ptr(opal_hash_table_t *ht, const void *key, size_t key_size, void *value) { int rc; size_t ii, capacity = ht->ht_capacity; - opal_hash_element_t * elt; + opal_hash_element_t *elt; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_set_value_ptr:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERR_BAD_PARAM; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_ptr != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_ptr != ht->ht_type_methods) { opal_output(0, "opal_hash_table_set_value_ptr:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_ptr; - for (ii = opal_hash_hash_key_ptr(key, key_size)%capacity; ; ii += 1) { - if (ii == capacity) { ii = 0; } + for (ii = opal_hash_hash_key_ptr(key, key_size) % capacity;; ii += 1) { + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { /* new entry */ - void * key_local = malloc(key_size); + void *key_local = malloc(key_size); memcpy(key_local, key, key_size); - elt->key.ptr.key = key_local; + elt->key.ptr.key = key_local; elt->key.ptr.key_size = key_size; elt->value = value; elt->valid = 1; @@ -704,8 +684,8 @@ opal_hash_table_set_value_ptr(opal_hash_table_t * ht, } } return OPAL_SUCCESS; - } else if (elt->key.ptr.key_size == key_size && - 0 == memcmp(elt->key.ptr.key, key, key_size)) { + } else if (elt->key.ptr.key_size == key_size + && 0 == memcmp(elt->key.ptr.key, key, key_size)) { /* replace existing value */ elt->value = value; return OPAL_SUCCESS; @@ -715,35 +695,35 @@ opal_hash_table_set_value_ptr(opal_hash_table_t * ht, } } -int /* OPAL_ return code */ -opal_hash_table_remove_value_ptr(opal_hash_table_t * ht, - const void * key, size_t key_size) +int /* OPAL_ return code */ +opal_hash_table_remove_value_ptr(opal_hash_table_t *ht, const void *key, size_t key_size) { size_t ii, capacity = ht->ht_capacity; #if OPAL_ENABLE_DEBUG - if(capacity == 0) { + if (capacity == 0) { opal_output(0, "opal_hash_table_get_value_ptr:" - "opal_hash_table_init() has not been called"); + "opal_hash_table_init() has not been called"); return OPAL_ERROR; } - if (NULL != ht->ht_type_methods && - &opal_hash_type_methods_ptr != ht->ht_type_methods) { + if (NULL != ht->ht_type_methods && &opal_hash_type_methods_ptr != ht->ht_type_methods) { opal_output(0, "opal_hash_table_remove_value_ptr:" - "hash table is for a different key type"); - return OPAL_ERROR; + "hash table is for a different key type"); + return OPAL_ERROR; } #endif ht->ht_type_methods = &opal_hash_type_methods_ptr; - for (ii = opal_hash_hash_key_ptr(key, key_size)%capacity; ; ii += 1) { - opal_hash_element_t * elt; - if (ii == capacity) { ii = 0; } + for (ii = opal_hash_hash_key_ptr(key, key_size) % capacity;; ii += 1) { + opal_hash_element_t *elt; + if (ii == capacity) { + ii = 0; + } elt = &ht->ht_table[ii]; - if (! elt->valid) { + if (!elt->valid) { return OPAL_ERR_NOT_FOUND; - } else if (elt->key.ptr.key_size == key_size && - 0 == memcmp(elt->key.ptr.key, key, key_size)) { + } else if (elt->key.ptr.key_size == key_size + && 0 == memcmp(elt->key.ptr.key, key, key_size)) { return opal_hash_table_remove_elt_at(ht, ii); } else { /* keep looking */ @@ -754,115 +734,103 @@ opal_hash_table_remove_value_ptr(opal_hash_table_t * ht, /***************************************************************************/ /* Traversals */ -static int /* OPAL_ return code */ +static int /* OPAL_ return code */ opal_hash_table_get_next_elt(opal_hash_table_t *ht, - opal_hash_element_t * prev_elt, /* NULL means find first */ - opal_hash_element_t * *next_elt) + opal_hash_element_t *prev_elt, /* NULL means find first */ + opal_hash_element_t **next_elt) { - opal_hash_element_t* elts = ht->ht_table; - size_t ii, capacity = ht->ht_capacity; + opal_hash_element_t *elts = ht->ht_table; + size_t ii, capacity = ht->ht_capacity; - for (ii = (NULL == prev_elt ? 0 : (prev_elt-elts)+1); ii < capacity; ii += 1) { - opal_hash_element_t * elt = &elts[ii]; - if (elt->valid) { - *next_elt = elt; - return OPAL_SUCCESS; + for (ii = (NULL == prev_elt ? 0 : (prev_elt - elts) + 1); ii < capacity; ii += 1) { + opal_hash_element_t *elt = &elts[ii]; + if (elt->valid) { + *next_elt = elt; + return OPAL_SUCCESS; + } } - } - return OPAL_ERROR; + return OPAL_ERROR; } -int /* OPAL_ return code */ -opal_hash_table_get_first_key_uint32(opal_hash_table_t * ht, - uint32_t *key, void * *value, - void * *node) +int /* OPAL_ return code */ +opal_hash_table_get_first_key_uint32(opal_hash_table_t *ht, uint32_t *key, void **value, + void **node) { - return opal_hash_table_get_next_key_uint32(ht, key, value, NULL, node); + return opal_hash_table_get_next_key_uint32(ht, key, value, NULL, node); } -int /* OPAL_ return code */ -opal_hash_table_get_next_key_uint32(opal_hash_table_t * ht, - uint32_t *key, void * *value, - void * in_node, void * *out_node) +int /* OPAL_ return code */ +opal_hash_table_get_next_key_uint32(opal_hash_table_t *ht, uint32_t *key, void **value, + void *in_node, void **out_node) { - opal_hash_element_t * elt; - if (OPAL_SUCCESS == opal_hash_table_get_next_elt(ht, (opal_hash_element_t *) in_node, &elt)) { - *key = elt->key.u32; - *value = elt->value; - *out_node = elt; - return OPAL_SUCCESS; - } - return OPAL_ERROR; + opal_hash_element_t *elt; + if (OPAL_SUCCESS == opal_hash_table_get_next_elt(ht, (opal_hash_element_t *) in_node, &elt)) { + *key = elt->key.u32; + *value = elt->value; + *out_node = elt; + return OPAL_SUCCESS; + } + return OPAL_ERROR; } -int /* OPAL_ return code */ -opal_hash_table_get_first_key_ptr(opal_hash_table_t * ht, - void * *key, size_t *key_size, void * *value, - void * *node) +int /* OPAL_ return code */ +opal_hash_table_get_first_key_ptr(opal_hash_table_t *ht, void **key, size_t *key_size, void **value, + void **node) { - return opal_hash_table_get_next_key_ptr(ht, key, key_size, value, NULL, node); + return opal_hash_table_get_next_key_ptr(ht, key, key_size, value, NULL, node); } -int /* OPAL_ return code */ -opal_hash_table_get_next_key_ptr(opal_hash_table_t * ht, - void * *key, size_t *key_size, void * *value, - void * in_node, void * *out_node) +int /* OPAL_ return code */ +opal_hash_table_get_next_key_ptr(opal_hash_table_t *ht, void **key, size_t *key_size, void **value, + void *in_node, void **out_node) { - opal_hash_element_t * elt; - if (OPAL_SUCCESS == opal_hash_table_get_next_elt(ht, (opal_hash_element_t *) in_node, &elt)) { - *key = (void *)elt->key.ptr.key; - *key_size = elt->key.ptr.key_size; - *value = elt->value; - *out_node = elt; - return OPAL_SUCCESS; - } - return OPAL_ERROR; + opal_hash_element_t *elt; + if (OPAL_SUCCESS == opal_hash_table_get_next_elt(ht, (opal_hash_element_t *) in_node, &elt)) { + *key = (void *) elt->key.ptr.key; + *key_size = elt->key.ptr.key_size; + *value = elt->value; + *out_node = elt; + return OPAL_SUCCESS; + } + return OPAL_ERROR; } -int /* OPAL_ return code */ -opal_hash_table_get_first_key_uint64(opal_hash_table_t * ht, - uint64_t *key, void * *value, - void * *node) +int /* OPAL_ return code */ +opal_hash_table_get_first_key_uint64(opal_hash_table_t *ht, uint64_t *key, void **value, + void **node) { - return opal_hash_table_get_next_key_uint64(ht, key, value, NULL, node); + return opal_hash_table_get_next_key_uint64(ht, key, value, NULL, node); } -int /* OPAL_ return code */ -opal_hash_table_get_next_key_uint64(opal_hash_table_t * ht, - uint64_t *key, void * *value, - void * in_node, void * *out_node) +int /* OPAL_ return code */ +opal_hash_table_get_next_key_uint64(opal_hash_table_t *ht, uint64_t *key, void **value, + void *in_node, void **out_node) { - opal_hash_element_t * elt; - if (OPAL_SUCCESS == opal_hash_table_get_next_elt(ht, (opal_hash_element_t *) in_node, &elt)) { - *key = elt->key.u64; - *value = elt->value; - *out_node = elt; - return OPAL_SUCCESS; - } - return OPAL_ERROR; + opal_hash_element_t *elt; + if (OPAL_SUCCESS == opal_hash_table_get_next_elt(ht, (opal_hash_element_t *) in_node, &elt)) { + *key = elt->key.u64; + *value = elt->value; + *out_node = elt; + return OPAL_SUCCESS; + } + return OPAL_ERROR; } /* there was/is no traversal for the ptr case; it would go here */ /* interact with the class-like mechanism */ -static void opal_proc_table_construct(opal_proc_table_t* pt); -static void opal_proc_table_destruct(opal_proc_table_t* pt); +static void opal_proc_table_construct(opal_proc_table_t *pt); +static void opal_proc_table_destruct(opal_proc_table_t *pt); -OBJ_CLASS_INSTANCE( - opal_proc_table_t, - opal_hash_table_t, - opal_proc_table_construct, - opal_proc_table_destruct -); +OBJ_CLASS_INSTANCE(opal_proc_table_t, opal_hash_table_t, opal_proc_table_construct, + opal_proc_table_destruct); -static void -opal_proc_table_construct(opal_proc_table_t* pt) +static void opal_proc_table_construct(opal_proc_table_t *pt) { - pt->pt_size = 0; + pt->pt_size = 0; } -static void -opal_proc_table_destruct(opal_proc_table_t* pt) +static void opal_proc_table_destruct(opal_proc_table_t *pt) { } @@ -870,22 +838,24 @@ opal_proc_table_destruct(opal_proc_table_t* pt) * Init, etc */ -int opal_proc_table_init(opal_proc_table_t* pt, size_t jobids, size_t vpids) { +int opal_proc_table_init(opal_proc_table_t *pt, size_t jobids, size_t vpids) +{ int rc; - if (OPAL_SUCCESS != (rc=opal_hash_table_init(&pt->super, jobids))) { + if (OPAL_SUCCESS != (rc = opal_hash_table_init(&pt->super, jobids))) { return rc; } pt->vpids_size = vpids; return OPAL_SUCCESS; } -int opal_proc_table_remove_all(opal_proc_table_t *pt) { +int opal_proc_table_remove_all(opal_proc_table_t *pt) +{ int rc; - opal_hash_table_t * vpids; + opal_hash_table_t *vpids; uint32_t jobid; - void * node; + void *node; - rc = opal_hash_table_get_first_key_uint32(&pt->super, &jobid, (void **)&vpids, &node); + rc = opal_hash_table_get_first_key_uint32(&pt->super, &jobid, (void **) &vpids, &node); if (OPAL_SUCCESS == rc) { do { @@ -893,19 +863,19 @@ int opal_proc_table_remove_all(opal_proc_table_t *pt) { opal_hash_table_remove_all(vpids); OBJ_RELEASE(vpids); } - rc = opal_hash_table_get_next_key_uint32 (&pt->super, &jobid, - (void **) &vpids, node, &node); + rc = opal_hash_table_get_next_key_uint32(&pt->super, &jobid, (void **) &vpids, node, + &node); } while (OPAL_SUCCESS == rc); } return rc; } -int opal_proc_table_get_value(opal_proc_table_t* pt, opal_process_name_t key, - void** ptr) { +int opal_proc_table_get_value(opal_proc_table_t *pt, opal_process_name_t key, void **ptr) +{ int rc; - opal_hash_table_t * vpids; - rc = opal_hash_table_get_value_uint32(&pt->super, key.jobid, (void **)&vpids); + opal_hash_table_t *vpids; + rc = opal_hash_table_get_value_uint32(&pt->super, key.jobid, (void **) &vpids); if (rc != OPAL_SUCCESS) { return rc; } @@ -913,20 +883,21 @@ int opal_proc_table_get_value(opal_proc_table_t* pt, opal_process_name_t key, return rc; } -int opal_proc_table_set_value(opal_proc_table_t* pt, opal_process_name_t key, void* value) { +int opal_proc_table_set_value(opal_proc_table_t *pt, opal_process_name_t key, void *value) +{ int rc; - opal_hash_table_t * vpids; - rc = opal_hash_table_get_value_uint32(&pt->super, key.jobid, (void **)&vpids); + opal_hash_table_t *vpids; + rc = opal_hash_table_get_value_uint32(&pt->super, key.jobid, (void **) &vpids); if (rc != OPAL_SUCCESS) { vpids = OBJ_NEW(opal_hash_table_t); if (NULL == vpids) { return OPAL_ERR_OUT_OF_RESOURCE; } - if (OPAL_SUCCESS != (rc=opal_hash_table_init(vpids, pt->vpids_size))) { + if (OPAL_SUCCESS != (rc = opal_hash_table_init(vpids, pt->vpids_size))) { OBJ_RELEASE(vpids); return rc; } - if (OPAL_SUCCESS != (rc=opal_hash_table_set_value_uint32(&pt->super, key.jobid, vpids))) { + if (OPAL_SUCCESS != (rc = opal_hash_table_set_value_uint32(&pt->super, key.jobid, vpids))) { OBJ_RELEASE(vpids); return rc; } @@ -935,13 +906,15 @@ int opal_proc_table_set_value(opal_proc_table_t* pt, opal_process_name_t key, vo return rc; } -int opal_proc_table_remove_value(opal_proc_table_t* pt, opal_process_name_t key) { +int opal_proc_table_remove_value(opal_proc_table_t *pt, opal_process_name_t key) +{ int rc; - opal_hash_table_t * vpids; - if (OPAL_SUCCESS != (rc=opal_hash_table_get_value_uint32(&pt->super, key.jobid, (void **)&vpids))) { + opal_hash_table_t *vpids; + if (OPAL_SUCCESS + != (rc = opal_hash_table_get_value_uint32(&pt->super, key.jobid, (void **) &vpids))) { return rc; } - if (OPAL_SUCCESS == (rc=opal_hash_table_remove_value_uint32(vpids, key.vpid))) { + if (OPAL_SUCCESS == (rc = opal_hash_table_remove_value_uint32(vpids, key.vpid))) { if (0 == vpids->ht_size) { opal_hash_table_remove_value_uint32(&pt->super, key.jobid); OBJ_RELEASE(vpids); @@ -950,12 +923,15 @@ int opal_proc_table_remove_value(opal_proc_table_t* pt, opal_process_name_t key) return rc; } -int opal_proc_table_get_first_key(opal_proc_table_t *pt, opal_process_name_t *key, - void **value, void **node1, void **node2) { +int opal_proc_table_get_first_key(opal_proc_table_t *pt, opal_process_name_t *key, void **value, + void **node1, void **node2) +{ int rc; uint32_t jobid, vpid; - opal_hash_table_t * vpids; - if (OPAL_SUCCESS != (rc=opal_hash_table_get_first_key_uint32(&pt->super, &jobid, (void **)&vpids, node1))) { + opal_hash_table_t *vpids; + if (OPAL_SUCCESS + != (rc = opal_hash_table_get_first_key_uint32(&pt->super, &jobid, (void **) &vpids, + node1))) { return rc; } rc = opal_hash_table_get_first_key_uint32(vpids, &vpid, value, node2); @@ -966,13 +942,13 @@ int opal_proc_table_get_first_key(opal_proc_table_t *pt, opal_process_name_t *ke return rc; } -int opal_proc_table_get_next_key(opal_proc_table_t *pt, opal_process_name_t *key, - void **value, void *in_node1, void **out_node1, - void *in_node2, void **out_node2) { +int opal_proc_table_get_next_key(opal_proc_table_t *pt, opal_process_name_t *key, void **value, + void *in_node1, void **out_node1, void *in_node2, void **out_node2) +{ int rc; - uint32_t jobid = ((opal_hash_element_t *)in_node1)->key.u32; + uint32_t jobid = ((opal_hash_element_t *) in_node1)->key.u32; uint32_t vpid; - opal_hash_table_t * vpids = ((opal_hash_element_t *)in_node1)->value; + opal_hash_table_t *vpids = ((opal_hash_element_t *) in_node1)->value; rc = opal_hash_table_get_next_key_uint32(vpids, &vpid, value, in_node2, out_node2); if (OPAL_SUCCESS == rc) { @@ -981,7 +957,9 @@ int opal_proc_table_get_next_key(opal_proc_table_t *pt, opal_process_name_t *key *out_node1 = in_node1; return rc; } - if (OPAL_SUCCESS != (rc=opal_hash_table_get_next_key_uint32(&pt->super, &jobid, (void **)&vpids, in_node1, out_node1))) { + if (OPAL_SUCCESS + != (rc = opal_hash_table_get_next_key_uint32(&pt->super, &jobid, (void **) &vpids, in_node1, + out_node1))) { return rc; } rc = opal_hash_table_get_first_key_uint32(vpids, &vpid, value, out_node2); diff --git a/opal/class/opal_hash_table.h b/opal/class/opal_hash_table.h index 4622ed4a81f..37ef25ad3b0 100644 --- a/opal/class/opal_hash_table.h +++ b/opal/class/opal_hash_table.h @@ -37,29 +37,26 @@ #include "opal_config.h" -#include #include "opal/class/opal_list.h" #include "opal/util/proc.h" +#include BEGIN_C_DECLS OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_hash_table_t); -struct opal_hash_table_t -{ - opal_object_t super; /**< subclass of opal_object_t */ - struct opal_hash_element_t * ht_table; /**< table of elements (opaque to users) */ - size_t ht_capacity; /**< allocated size (capacity) of table */ - size_t ht_size; /**< number of extant entries */ - size_t ht_growth_trigger; /**< size hits this and table is grown */ - int ht_density_numer, ht_density_denom; /**< max allowed density of table */ - int ht_growth_numer, ht_growth_denom; /**< growth factor when grown */ - const struct opal_hash_type_methods_t * ht_type_methods; +struct opal_hash_table_t { + opal_object_t super; /**< subclass of opal_object_t */ + struct opal_hash_element_t *ht_table; /**< table of elements (opaque to users) */ + size_t ht_capacity; /**< allocated size (capacity) of table */ + size_t ht_size; /**< number of extant entries */ + size_t ht_growth_trigger; /**< size hits this and table is grown */ + int ht_density_numer, ht_density_denom; /**< max allowed density of table */ + int ht_growth_numer, ht_growth_denom; /**< growth factor when grown */ + const struct opal_hash_type_methods_t *ht_type_methods; }; typedef struct opal_hash_table_t opal_hash_table_t; - - /** * Initializes the table size, must be called before using * the table. @@ -71,12 +68,12 @@ typedef struct opal_hash_table_t opal_hash_table_t; * */ -OPAL_DECLSPEC int opal_hash_table_init(opal_hash_table_t* ht, size_t table_size); +OPAL_DECLSPEC int opal_hash_table_init(opal_hash_table_t *ht, size_t table_size); /* this could be the new init if people wanted a more general API */ -OPAL_DECLSPEC int opal_hash_table_init2(opal_hash_table_t* ht, size_t estimated_max_size, - int density_numer, int density_denom, - int growth_numer, int growth_denom); +OPAL_DECLSPEC int opal_hash_table_init2(opal_hash_table_t *ht, size_t estimated_max_size, + int density_numer, int density_denom, int growth_numer, + int growth_denom); /** * Returns the number of elements currently stored in the table. @@ -114,8 +111,8 @@ OPAL_DECLSPEC int opal_hash_table_remove_all(opal_hash_table_t *ht); * */ -OPAL_DECLSPEC int opal_hash_table_get_value_uint32(opal_hash_table_t* table, uint32_t key, - void** ptr); +OPAL_DECLSPEC int opal_hash_table_get_value_uint32(opal_hash_table_t *table, uint32_t key, + void **ptr); /** * Set value based on uint32_t key. @@ -127,7 +124,8 @@ OPAL_DECLSPEC int opal_hash_table_get_value_uint32(opal_hash_table_t* table, uin * */ -OPAL_DECLSPEC int opal_hash_table_set_value_uint32(opal_hash_table_t* table, uint32_t key, void* value); +OPAL_DECLSPEC int opal_hash_table_set_value_uint32(opal_hash_table_t *table, uint32_t key, + void *value); /** * Remove value based on uint32_t key. @@ -138,7 +136,7 @@ OPAL_DECLSPEC int opal_hash_table_set_value_uint32(opal_hash_table_t* table, uin * */ -OPAL_DECLSPEC int opal_hash_table_remove_value_uint32(opal_hash_table_t* table, uint32_t key); +OPAL_DECLSPEC int opal_hash_table_remove_value_uint32(opal_hash_table_t *table, uint32_t key); /** * Retrieve value via uint64_t key. @@ -166,7 +164,8 @@ OPAL_DECLSPEC int opal_hash_table_get_value_uint64(opal_hash_table_t *table, uin * */ -OPAL_DECLSPEC int opal_hash_table_set_value_uint64(opal_hash_table_t *table, uint64_t key, void* value); +OPAL_DECLSPEC int opal_hash_table_set_value_uint64(opal_hash_table_t *table, uint64_t key, + void *value); /** * Remove value based on uint64_t key. @@ -192,7 +191,7 @@ OPAL_DECLSPEC int opal_hash_table_remove_value_uint64(opal_hash_table_t *table, * */ -OPAL_DECLSPEC int opal_hash_table_get_value_ptr(opal_hash_table_t *table, const void* key, +OPAL_DECLSPEC int opal_hash_table_get_value_ptr(opal_hash_table_t *table, const void *key, size_t keylen, void **ptr); /** @@ -205,7 +204,8 @@ OPAL_DECLSPEC int opal_hash_table_get_value_ptr(opal_hash_table_t *table, const * */ -OPAL_DECLSPEC int opal_hash_table_set_value_ptr(opal_hash_table_t *table, const void* key, size_t keylen, void* value); +OPAL_DECLSPEC int opal_hash_table_set_value_ptr(opal_hash_table_t *table, const void *key, + size_t keylen, void *value); /** * Remove value based on arbitrary length binary key. @@ -216,8 +216,8 @@ OPAL_DECLSPEC int opal_hash_table_set_value_ptr(opal_hash_table_t *table, const * */ -OPAL_DECLSPEC int opal_hash_table_remove_value_ptr(opal_hash_table_t *table, const void* key, size_t keylen); - +OPAL_DECLSPEC int opal_hash_table_remove_value_ptr(opal_hash_table_t *table, const void *key, + size_t keylen); /** The following functions are only for allowing iterating through the hash table. The calls return along with a key, a pointer to @@ -242,8 +242,7 @@ OPAL_DECLSPEC int opal_hash_table_remove_value_ptr(opal_hash_table_t *table, con */ OPAL_DECLSPEC int opal_hash_table_get_first_key_uint32(opal_hash_table_t *table, uint32_t *key, - void **value, void **node); - + void **value, void **node); /** * Get the next 32 bit key from the hash table, knowing the current key @@ -260,9 +259,7 @@ OPAL_DECLSPEC int opal_hash_table_get_first_key_uint32(opal_hash_table_t *table, */ OPAL_DECLSPEC int opal_hash_table_get_next_key_uint32(opal_hash_table_t *table, uint32_t *key, - void **value, void *in_node, - void **out_node); - + void **value, void *in_node, void **out_node); /** * Get the first 64 key from the hash table, which can be used later to @@ -278,8 +275,7 @@ OPAL_DECLSPEC int opal_hash_table_get_next_key_uint32(opal_hash_table_t *table, */ OPAL_DECLSPEC int opal_hash_table_get_first_key_uint64(opal_hash_table_t *table, uint64_t *key, - void **value, void **node); - + void **value, void **node); /** * Get the next 64 bit key from the hash table, knowing the current key @@ -296,9 +292,7 @@ OPAL_DECLSPEC int opal_hash_table_get_first_key_uint64(opal_hash_table_t *table, */ OPAL_DECLSPEC int opal_hash_table_get_next_key_uint64(opal_hash_table_t *table, uint64_t *key, - void **value, void *in_node, - void **out_node); - + void **value, void *in_node, void **out_node); /** * Get the first ptr bit key from the hash table, which can be used later to @@ -314,9 +308,8 @@ OPAL_DECLSPEC int opal_hash_table_get_next_key_uint64(opal_hash_table_t *table, * */ -OPAL_DECLSPEC int opal_hash_table_get_first_key_ptr(opal_hash_table_t *table, void* *key, - size_t *key_size, void **value, void **node); - +OPAL_DECLSPEC int opal_hash_table_get_first_key_ptr(opal_hash_table_t *table, void **key, + size_t *key_size, void **value, void **node); /** * Get the next ptr bit key from the hash table, knowing the current key @@ -333,28 +326,23 @@ OPAL_DECLSPEC int opal_hash_table_get_first_key_ptr(opal_hash_table_t *table, vo * */ -OPAL_DECLSPEC int opal_hash_table_get_next_key_ptr(opal_hash_table_t *table, void* *key, - size_t *key_size, void **value, - void *in_node, void **out_node); - - +OPAL_DECLSPEC int opal_hash_table_get_next_key_ptr(opal_hash_table_t *table, void **key, + size_t *key_size, void **value, void *in_node, + void **out_node); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_proc_table_t); -struct opal_proc_table_t -{ - opal_hash_table_t super; /**< subclass of opal_object_t */ - size_t pt_size; /**< number of extant entries */ - size_t vpids_size; +struct opal_proc_table_t { + opal_hash_table_t super; /**< subclass of opal_object_t */ + size_t pt_size; /**< number of extant entries */ + size_t vpids_size; // FIXME // Begin KLUDGE!! So ompi/debuggers/ompi_common_dll.c doesn't complain - size_t pt_table_size; /**< size of table */ + size_t pt_table_size; /**< size of table */ // End KLUDGE }; typedef struct opal_proc_table_t opal_proc_table_t; - - /** * Initializes the table size, must be called before using * the table. @@ -368,7 +356,7 @@ typedef struct opal_proc_table_t opal_proc_table_t; * */ -OPAL_DECLSPEC int opal_proc_table_init(opal_proc_table_t* pt, size_t jobids, size_t vpids); +OPAL_DECLSPEC int opal_proc_table_init(opal_proc_table_t *pt, size_t jobids, size_t vpids); /** * Remove all elements from the table. @@ -393,8 +381,8 @@ OPAL_DECLSPEC int opal_proc_table_remove_all(opal_proc_table_t *pt); * */ -OPAL_DECLSPEC int opal_proc_table_get_value(opal_proc_table_t* pt, opal_process_name_t key, - void** ptr); +OPAL_DECLSPEC int opal_proc_table_get_value(opal_proc_table_t *pt, opal_process_name_t key, + void **ptr); /** * Set value based on opal_process_name_t key. @@ -406,7 +394,8 @@ OPAL_DECLSPEC int opal_proc_table_get_value(opal_proc_table_t* pt, opal_process_ * */ -OPAL_DECLSPEC int opal_proc_table_set_value(opal_proc_table_t* pt, opal_process_name_t key, void* value); +OPAL_DECLSPEC int opal_proc_table_set_value(opal_proc_table_t *pt, opal_process_name_t key, + void *value); /** * Remove value based on opal_process_name_t key. @@ -417,8 +406,7 @@ OPAL_DECLSPEC int opal_proc_table_set_value(opal_proc_table_t* pt, opal_process_ * */ -OPAL_DECLSPEC int opal_proc_table_remove_value(opal_proc_table_t* pt, opal_process_name_t key); - +OPAL_DECLSPEC int opal_proc_table_remove_value(opal_proc_table_t *pt, opal_process_name_t key); /** * Get the first opal_process_name_t key from the hash table, which can be used later to @@ -439,7 +427,6 @@ OPAL_DECLSPEC int opal_proc_table_remove_value(opal_proc_table_t* pt, opal_proce OPAL_DECLSPEC int opal_proc_table_get_first_key(opal_proc_table_t *pt, opal_process_name_t *key, void **value, void **node1, void **node2); - /** * Get the next opal_process_name_t key from the hash table, knowing the current key * @param pt The hash table pointer (IN) @@ -483,16 +470,19 @@ OPAL_DECLSPEC int opal_proc_table_get_next_key(opal_proc_table_t *pt, opal_proce * } */ #define OPAL_HASH_TABLE_FOREACH(key, type, value, ht) \ - for (void *_nptr=NULL; \ - OPAL_SUCCESS == opal_hash_table_get_next_key_##type(ht, &key, (void **)&value, _nptr, &_nptr);) - -#define OPAL_HASH_TABLE_FOREACH_PTR(key, value, ht, body) \ - { \ - size_t key_size_; \ - for (void *_nptr=NULL; \ - OPAL_SUCCESS == opal_hash_table_get_next_key_ptr (ht, &key, &key_size_, (void **)&value, _nptr, &_nptr);) \ - body \ - } + for (void *_nptr = NULL; \ + OPAL_SUCCESS \ + == opal_hash_table_get_next_key_##type(ht, &key, (void **) &value, _nptr, &_nptr);) + +#define OPAL_HASH_TABLE_FOREACH_PTR(key, value, ht, body) \ + { \ + size_t key_size_; \ + for (void *_nptr = NULL; \ + OPAL_SUCCESS \ + == opal_hash_table_get_next_key_ptr(ht, &key, &key_size_, (void **) &value, _nptr, \ + &_nptr);) \ + body \ + } END_C_DECLS -#endif /* OPAL_HASH_TABLE_H */ +#endif /* OPAL_HASH_TABLE_H */ diff --git a/opal/class/opal_hotel.c b/opal/class/opal_hotel.c index 50b46e10a58..4777a54aba9 100644 --- a/opal/class/opal_hotel.c +++ b/opal/class/opal_hotel.c @@ -13,17 +13,16 @@ #include "opal_config.h" -#include #include +#include -#include "opal/util/event.h" #include "opal/class/opal_hotel.h" - +#include "opal/util/event.h" static void local_eviction_callback(int fd, short flags, void *arg) { - opal_hotel_room_eviction_callback_arg_t *eargs = - (opal_hotel_room_eviction_callback_arg_t*) arg; + opal_hotel_room_eviction_callback_arg_t *eargs = (opal_hotel_room_eviction_callback_arg_t *) + arg; void *occupant = eargs->hotel->rooms[eargs->room_num].occupant; /* Remove the occurpant from the room. @@ -39,23 +38,17 @@ static void local_eviction_callback(int fd, short flags, void *arg) hotel->unoccupied_rooms[hotel->last_unoccupied_room] = eargs->room_num; /* Invoke the user callback to tell them that they were evicted */ - hotel->evict_callback_fn(hotel, - eargs->room_num, - occupant); + hotel->evict_callback_fn(hotel, eargs->room_num, occupant); } - -int opal_hotel_init(opal_hotel_t *h, int num_rooms, - opal_event_base_t *evbase, - uint32_t eviction_timeout, - int eviction_event_priority, +int opal_hotel_init(opal_hotel_t *h, int num_rooms, opal_event_base_t *evbase, + uint32_t eviction_timeout, int eviction_event_priority, opal_hotel_eviction_callback_fn_t evict_callback_fn) { int i; /* Bozo check */ - if (num_rooms <= 0 || - NULL == evict_callback_fn) { + if (num_rooms <= 0 || NULL == evict_callback_fn) { return OPAL_ERR_BAD_PARAM; } @@ -64,12 +57,12 @@ int opal_hotel_init(opal_hotel_t *h, int num_rooms, h->eviction_timeout.tv_usec = eviction_timeout % 1000000; h->eviction_timeout.tv_sec = eviction_timeout / 1000000; h->evict_callback_fn = evict_callback_fn; - h->rooms = (opal_hotel_room_t*)malloc(num_rooms * sizeof(opal_hotel_room_t)); + h->rooms = (opal_hotel_room_t *) malloc(num_rooms * sizeof(opal_hotel_room_t)); if (NULL != evict_callback_fn) { - h->eviction_args = - (opal_hotel_room_eviction_callback_arg_t*)malloc(num_rooms * sizeof(opal_hotel_room_eviction_callback_arg_t)); + h->eviction_args = (opal_hotel_room_eviction_callback_arg_t *) malloc( + num_rooms * sizeof(opal_hotel_room_eviction_callback_arg_t)); } - h->unoccupied_rooms = (int*) malloc(num_rooms * sizeof(int)); + h->unoccupied_rooms = (int *) malloc(num_rooms * sizeof(int)); h->last_unoccupied_room = num_rooms - 1; for (i = 0; i < num_rooms; ++i) { @@ -85,14 +78,11 @@ int opal_hotel_init(opal_hotel_t *h, int num_rooms, /* Create this room's event (but don't add it) */ if (NULL != h->evbase) { - opal_event_set(h->evbase, - &(h->rooms[i].eviction_timer_event), - -1, 0, local_eviction_callback, - &(h->eviction_args[i])); + opal_event_set(h->evbase, &(h->rooms[i].eviction_timer_event), -1, 0, + local_eviction_callback, &(h->eviction_args[i])); /* Set the priority so it gets serviced properly */ - opal_event_set_priority(&(h->rooms[i].eviction_timer_event), - eviction_event_priority); + opal_event_set_priority(&(h->rooms[i].eviction_timer_event), eviction_event_priority); } } @@ -136,7 +126,4 @@ static void destructor(opal_hotel_t *h) } } -OBJ_CLASS_INSTANCE(opal_hotel_t, - opal_object_t, - constructor, - destructor); +OBJ_CLASS_INSTANCE(opal_hotel_t, opal_object_t, constructor, destructor); diff --git a/opal/class/opal_hotel.h b/opal/class/opal_hotel.h index 52cf5a4b1b4..3e12e460f65 100644 --- a/opal/class/opal_hotel.h +++ b/opal/class/opal_hotel.h @@ -55,19 +55,18 @@ #include "opal_config.h" +#include "opal/class/opal_object.h" #include "opal/constants.h" -#include "opal/util/output.h" #include "opal/prefetch.h" -#include "opal/class/opal_object.h" #include "opal/util/event.h" +#include "opal/util/output.h" BEGIN_C_DECLS struct opal_hotel_t; /* User-supplied function to be invoked when an occupant is evicted. */ -typedef void (*opal_hotel_eviction_callback_fn_t)(struct opal_hotel_t *hotel, - int room_num, +typedef void (*opal_hotel_eviction_callback_fn_t)(struct opal_hotel_t *hotel, int room_num, void *occupant); /* Note that this is an internal data structure; it is not part of the @@ -158,10 +157,8 @@ OBJ_CLASS_DECLARATION(opal_hotel_t); * @return OPAL_SUCCESS if all initializations were succesful. Otherwise, * the error indicate what went wrong in the function. */ -OPAL_DECLSPEC int opal_hotel_init(opal_hotel_t *hotel, int num_rooms, - opal_event_base_t *evbase, - uint32_t eviction_timeout, - int eviction_event_priority, +OPAL_DECLSPEC int opal_hotel_init(opal_hotel_t *hotel, int num_rooms, opal_event_base_t *evbase, + uint32_t eviction_timeout, int eviction_event_priority, opal_hotel_eviction_callback_fn_t evict_callback_fn); /** @@ -184,9 +181,7 @@ OPAL_DECLSPEC int opal_hotel_init(opal_hotel_t *hotel, int num_rooms, * @return OPAL_ERR_TEMP_OUT_OF_RESOURCE is the hotel is full. Try * again later. */ -static inline int opal_hotel_checkin(opal_hotel_t *hotel, - void *occupant, - int *room_num) +static inline int opal_hotel_checkin(opal_hotel_t *hotel, void *occupant, int *room_num) { opal_hotel_room_t *room; @@ -202,8 +197,7 @@ static inline int opal_hotel_checkin(opal_hotel_t *hotel, /* Assign the event and make it pending */ if (NULL != hotel->evbase) { - opal_event_add(&(room->eviction_timer_event), - &(hotel->eviction_timeout)); + opal_event_add(&(room->eviction_timer_event), &(hotel->eviction_timeout)); } return OPAL_SUCCESS; @@ -213,9 +207,7 @@ static inline int opal_hotel_checkin(opal_hotel_t *hotel, * Same as opal_hotel_checkin(), but slightly optimized for when the * caller *knows* that there is a room available. */ -static inline void opal_hotel_checkin_with_res(opal_hotel_t *hotel, - void *occupant, - int *room_num) +static inline void opal_hotel_checkin_with_res(opal_hotel_t *hotel, void *occupant, int *room_num) { opal_hotel_room_t *room; @@ -227,8 +219,7 @@ static inline void opal_hotel_checkin_with_res(opal_hotel_t *hotel, /* Assign the event and make it pending */ if (NULL != hotel->evbase) { - opal_event_add(&(room->eviction_timer_event), - &(hotel->eviction_timeout)); + opal_event_add(&(room->eviction_timer_event), &(hotel->eviction_timeout)); } } @@ -281,7 +272,8 @@ static inline void opal_hotel_checkout(opal_hotel_t *hotel, int room_num) * * Use this checkout and when caller needs the occupant */ -static inline void opal_hotel_checkout_and_return_occupant(opal_hotel_t *hotel, int room_num, void **occupant) +static inline void opal_hotel_checkout_and_return_occupant(opal_hotel_t *hotel, int room_num, + void **occupant) { opal_hotel_room_t *room; @@ -291,7 +283,7 @@ static inline void opal_hotel_checkout_and_return_occupant(opal_hotel_t *hotel, /* If there's an occupant in the room, check them out */ room = &(hotel->rooms[room_num]); if (OPAL_LIKELY(NULL != room->occupant)) { - opal_output (10, "checking out occupant %p from room num %d", room->occupant, room_num); + opal_output(10, "checking out occupant %p from room num %d", room->occupant, room_num); /* Do not change this logic without also changing the same logic in opal_hotel_checkout() and opal_hotel.c:local_eviction_callback(). */ @@ -303,8 +295,7 @@ static inline void opal_hotel_checkout_and_return_occupant(opal_hotel_t *hotel, hotel->last_unoccupied_room++; assert(hotel->last_unoccupied_room < hotel->num_rooms); hotel->unoccupied_rooms[hotel->last_unoccupied_room] = room_num; - } - else { + } else { *occupant = NULL; } } @@ -315,7 +306,7 @@ static inline void opal_hotel_checkout_and_return_occupant(opal_hotel_t *hotel, * @return bool true if empty false if there is a occupant(s) * */ -static inline bool opal_hotel_is_empty (opal_hotel_t *hotel) +static inline bool opal_hotel_is_empty(opal_hotel_t *hotel) { if (hotel->last_unoccupied_room == hotel->num_rooms - 1) return true; @@ -345,7 +336,7 @@ static inline void opal_hotel_knock(opal_hotel_t *hotel, int room_num, void **oc /* If there's an occupant in the room, have them come to the door */ room = &(hotel->rooms[room_num]); if (OPAL_LIKELY(NULL != room->occupant)) { - opal_output (10, "occupant %p in room num %d responded to knock", room->occupant, room_num); + opal_output(10, "occupant %p in room num %d responded to knock", room->occupant, room_num); *occupant = room->occupant; } } diff --git a/opal/class/opal_interval_tree.c b/opal/class/opal_interval_tree.c index 8b6fb2dd61f..98a5f7034c1 100644 --- a/opal/class/opal_interval_tree.c +++ b/opal/class/opal_interval_tree.c @@ -29,25 +29,29 @@ #include /* Private functions */ -static void opal_interval_tree_insert_node (opal_interval_tree_t *tree, opal_interval_tree_node_t *node); +static void opal_interval_tree_insert_node(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node); /* tree rebalancing functions */ -static void opal_interval_tree_delete_fixup (opal_interval_tree_t *tree, opal_interval_tree_node_t *node, - opal_interval_tree_node_t *parent); -static void opal_interval_tree_insert_fixup (opal_interval_tree_t *tree, opal_interval_tree_node_t *x); +static void opal_interval_tree_delete_fixup(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node, + opal_interval_tree_node_t *parent); +static void opal_interval_tree_insert_fixup(opal_interval_tree_t *tree, + opal_interval_tree_node_t *x); -static opal_interval_tree_node_t *opal_interval_tree_next (opal_interval_tree_t *tree, - opal_interval_tree_node_t *node); -static opal_interval_tree_node_t * opal_interval_tree_find_node(opal_interval_tree_t *tree, - uint64_t low, uint64_t high, - void *data); +static opal_interval_tree_node_t *opal_interval_tree_next(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node); +static opal_interval_tree_node_t * +opal_interval_tree_find_node(opal_interval_tree_t *tree, uint64_t low, uint64_t high, void *data); -static opal_interval_tree_node_t *left_rotate (opal_interval_tree_t *tree, opal_interval_tree_node_t *x); -static opal_interval_tree_node_t *right_rotate (opal_interval_tree_t *tree, opal_interval_tree_node_t *x); +static opal_interval_tree_node_t *left_rotate(opal_interval_tree_t *tree, + opal_interval_tree_node_t *x); +static opal_interval_tree_node_t *right_rotate(opal_interval_tree_t *tree, + opal_interval_tree_node_t *x); -static void inorder_destroy(opal_interval_tree_t *tree, opal_interval_tree_node_t * node); +static void inorder_destroy(opal_interval_tree_t *tree, opal_interval_tree_node_t *node); -#define max(x,y) (((x) > (y)) ? (x) : (y)) +#define max(x, y) (((x) > (y)) ? (x) : (y)) /** * the constructor function. creates the free list to get the nodes from @@ -56,7 +60,7 @@ static void inorder_destroy(opal_interval_tree_t *tree, opal_interval_tree_node_ * * @retval NONE */ -static void opal_interval_tree_construct (opal_interval_tree_t *tree) +static void opal_interval_tree_construct(opal_interval_tree_t *tree) { OBJ_CONSTRUCT(&tree->root, opal_interval_tree_node_t); OBJ_CONSTRUCT(&tree->nill, opal_interval_tree_node_t); @@ -85,7 +89,7 @@ static void opal_interval_tree_construct (opal_interval_tree_t *tree) /* set all reader epochs to UINT_MAX. this value is used to simplfy * checks against the current epoch. */ - for (int i = 0 ; i < OPAL_INTERVAL_TREE_MAX_READERS ; ++i) { + for (int i = 0; i < OPAL_INTERVAL_TREE_MAX_READERS; ++i) { tree->reader_epochs[i] = UINT_MAX; } } @@ -95,9 +99,9 @@ static void opal_interval_tree_construct (opal_interval_tree_t *tree) * * @param object the tree object */ -static void opal_interval_tree_destruct (opal_interval_tree_t *tree) +static void opal_interval_tree_destruct(opal_interval_tree_t *tree) { - opal_interval_tree_destroy (tree); + opal_interval_tree_destroy(tree); OBJ_DESTRUCT(&tree->free_list); OBJ_DESTRUCT(&tree->root); @@ -114,7 +118,7 @@ typedef int32_t opal_interval_tree_token_t; /** * @brief pick and return a reader slot */ -static opal_interval_tree_token_t opal_interval_tree_reader_get_token (opal_interval_tree_t *tree) +static opal_interval_tree_token_t opal_interval_tree_reader_get_token(opal_interval_tree_t *tree) { opal_interval_tree_token_t token = -1; @@ -125,49 +129,56 @@ static opal_interval_tree_token_t opal_interval_tree_reader_get_token (opal_inte * using atomics. */ token = tree->reader_id++ % OPAL_INTERVAL_TREE_MAX_READERS; while (OPAL_UNLIKELY(reader_count <= token)) { - if (opal_atomic_compare_exchange_strong_32 (&tree->reader_count, &reader_count, token + 1)) { + if (opal_atomic_compare_exchange_strong_32(&tree->reader_count, &reader_count, + token + 1)) { break; } } } - while (!OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32((opal_atomic_int32_t *) &tree->reader_epochs[token], - &(int32_t) {UINT_MAX}, tree->epoch)); + while ( + !OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32((opal_atomic_int32_t *) &tree->reader_epochs[token], + &(int32_t){UINT_MAX}, tree->epoch)) { + } return token; } -static void opal_interval_tree_reader_return_token (opal_interval_tree_t *tree, opal_interval_tree_token_t token) +static void opal_interval_tree_reader_return_token(opal_interval_tree_t *tree, + opal_interval_tree_token_t token) { tree->reader_epochs[token] = UINT_MAX; } /* Create the tree */ -int opal_interval_tree_init (opal_interval_tree_t *tree) +int opal_interval_tree_init(opal_interval_tree_t *tree) { - return opal_free_list_init (&tree->free_list, sizeof(opal_interval_tree_node_t), - opal_cache_line_size, OBJ_CLASS(opal_interval_tree_node_t), - 0, opal_cache_line_size, 0, -1 , 128, NULL, 0, NULL, NULL, NULL); + return opal_free_list_init(&tree->free_list, sizeof(opal_interval_tree_node_t), + opal_cache_line_size, OBJ_CLASS(opal_interval_tree_node_t), 0, + opal_cache_line_size, 0, -1, 128, NULL, 0, NULL, NULL, NULL); } -static bool opal_interval_tree_write_trylock (opal_interval_tree_t *tree) +static bool opal_interval_tree_write_trylock(opal_interval_tree_t *tree) { - opal_atomic_rmb (); - return !(tree->lock || opal_atomic_swap_32 (&tree->lock, 1)); + opal_atomic_rmb(); + return !(tree->lock || opal_atomic_swap_32(&tree->lock, 1)); } -static void opal_interval_tree_write_lock (opal_interval_tree_t *tree) +static void opal_interval_tree_write_lock(opal_interval_tree_t *tree) { - while (!opal_interval_tree_write_trylock (tree)); + while (!opal_interval_tree_write_trylock(tree)) { + } } -static void opal_interval_tree_write_unlock (opal_interval_tree_t *tree) +static void opal_interval_tree_write_unlock(opal_interval_tree_t *tree) { - opal_atomic_wmb (); + opal_atomic_wmb(); tree->lock = 0; } -static void opal_interval_tree_insert_fixup_helper (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) { +static void opal_interval_tree_insert_fixup_helper(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) +{ opal_interval_tree_node_t *y, *parent = node->parent; bool rotate_right = false; @@ -186,13 +197,13 @@ static void opal_interval_tree_insert_fixup_helper (opal_interval_tree_t *tree, parent->color = OPAL_INTERVAL_TREE_COLOR_BLACK; y->color = OPAL_INTERVAL_TREE_COLOR_BLACK; parent->parent->color = OPAL_INTERVAL_TREE_COLOR_RED; - opal_interval_tree_insert_fixup_helper (tree, parent->parent); + opal_interval_tree_insert_fixup_helper(tree, parent->parent); return; } if (rotate_right) { if (node == parent->right) { - node = left_rotate (tree, parent); + node = left_rotate(tree, parent); parent = node->parent; } @@ -209,14 +220,16 @@ static void opal_interval_tree_insert_fixup_helper (opal_interval_tree_t *tree, (void) left_rotate(tree, parent->parent); } - opal_interval_tree_insert_fixup_helper (tree, node); + opal_interval_tree_insert_fixup_helper(tree, node); } -static void opal_interval_tree_insert_fixup (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) { +static void opal_interval_tree_insert_fixup(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) +{ /* do the rotations */ /* usually one would have to check for NULL, but because of the sentinal, * we don't have to */ - opal_interval_tree_insert_fixup_helper (tree, node); + opal_interval_tree_insert_fixup_helper(tree, node); /* after the rotations the root is black */ tree->root.left->color = OPAL_INTERVAL_TREE_COLOR_BLACK; @@ -232,8 +245,8 @@ static void opal_interval_tree_insert_fixup (opal_interval_tree_t *tree, opal_in * @returns the next node to fixup or root if done */ static inline opal_interval_tree_node_t * -opal_interval_tree_delete_fixup_helper (opal_interval_tree_t *tree, opal_interval_tree_node_t *node, - opal_interval_tree_node_t *parent, const bool left) +opal_interval_tree_delete_fixup_helper(opal_interval_tree_t *tree, opal_interval_tree_node_t *node, + opal_interval_tree_node_t *parent, const bool left) { opal_interval_tree_node_t *w; @@ -251,7 +264,8 @@ opal_interval_tree_delete_fixup_helper (opal_interval_tree_t *tree, opal_interva } } - if ((w->left->color == OPAL_INTERVAL_TREE_COLOR_BLACK) && (w->right->color == OPAL_INTERVAL_TREE_COLOR_BLACK)) { + if ((w->left->color == OPAL_INTERVAL_TREE_COLOR_BLACK) + && (w->right->color == OPAL_INTERVAL_TREE_COLOR_BLACK)) { w->color = OPAL_INTERVAL_TREE_COLOR_RED; return parent; } @@ -282,14 +296,15 @@ opal_interval_tree_delete_fixup_helper (opal_interval_tree_t *tree, opal_interva /* return the root */ return tree->root.left; - } +} /* Fixup the balance of the btree after deletion */ -static void opal_interval_tree_delete_fixup (opal_interval_tree_t *tree, opal_interval_tree_node_t *node, - opal_interval_tree_node_t *parent) +static void opal_interval_tree_delete_fixup(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node, + opal_interval_tree_node_t *parent) { while ((node != tree->root.left) && (node->color == OPAL_INTERVAL_TREE_COLOR_BLACK)) { - node = opal_interval_tree_delete_fixup_helper (tree, node, parent, node == parent->left); + node = opal_interval_tree_delete_fixup_helper(tree, node, parent, node == parent->left); parent = node->parent; } @@ -299,44 +314,45 @@ static void opal_interval_tree_delete_fixup (opal_interval_tree_t *tree, opal_in /* traverse the garbage-collection list and return any nodes that can not have any * references. this function MUST be called with the writer lock held. */ -static void opal_interval_tree_gc_clean (opal_interval_tree_t *tree) +static void opal_interval_tree_gc_clean(opal_interval_tree_t *tree) { opal_interval_tree_node_t *node, *next; uint32_t oldest_epoch = UINT_MAX; - if (0 == opal_list_get_size (&tree->gc_list)) { + if (0 == opal_list_get_size(&tree->gc_list)) { return; } - for (int i = 0 ; i < tree->reader_count ; ++i) { - oldest_epoch = (oldest_epoch < tree->reader_epochs[i]) ? oldest_epoch : tree->reader_epochs[i]; + for (int i = 0; i < tree->reader_count; ++i) { + oldest_epoch = (oldest_epoch < tree->reader_epochs[i]) ? oldest_epoch + : tree->reader_epochs[i]; } - OPAL_LIST_FOREACH_SAFE(node, next, &tree->gc_list, opal_interval_tree_node_t) { + OPAL_LIST_FOREACH_SAFE (node, next, &tree->gc_list, opal_interval_tree_node_t) { if (node->epoch < oldest_epoch) { - opal_list_remove_item (&tree->gc_list, &node->super.super); - opal_free_list_return_st (&tree->free_list, &node->super); + opal_list_remove_item(&tree->gc_list, &node->super.super); + opal_free_list_return_st(&tree->free_list, &node->super); } } } /* This inserts a node into the tree based on the passed values. */ -int opal_interval_tree_insert (opal_interval_tree_t *tree, void *value, uint64_t low, uint64_t high) +int opal_interval_tree_insert(opal_interval_tree_t *tree, void *value, uint64_t low, uint64_t high) { - opal_interval_tree_node_t * node; + opal_interval_tree_node_t *node; if (low > high) { return OPAL_ERR_BAD_PARAM; } - opal_interval_tree_write_lock (tree); + opal_interval_tree_write_lock(tree); - opal_interval_tree_gc_clean (tree); + opal_interval_tree_gc_clean(tree); /* get the memory for a node */ - node = (opal_interval_tree_node_t *) opal_free_list_get (&tree->free_list); + node = (opal_interval_tree_node_t *) opal_free_list_get(&tree->free_list); if (OPAL_UNLIKELY(NULL == node)) { - opal_interval_tree_write_unlock (tree); + opal_interval_tree_write_unlock(tree); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -348,17 +364,19 @@ int opal_interval_tree_insert (opal_interval_tree_t *tree, void *value, uint64_t node->epoch = tree->epoch; /* insert the node into the tree */ - opal_interval_tree_insert_node (tree, node); + opal_interval_tree_insert_node(tree, node); - opal_interval_tree_insert_fixup (tree, node); - opal_interval_tree_write_unlock (tree); + opal_interval_tree_insert_fixup(tree, node); + opal_interval_tree_write_unlock(tree); return OPAL_SUCCESS; } -static int opal_interval_tree_compare_node(opal_interval_tree_node_t *node, uint64_t low, uint64_t high, void *data) { - if ((data && node->low == low && node->high == high && node->data == data) || - (!data && node->low <= low && node->high >= high)) { +static int opal_interval_tree_compare_node(opal_interval_tree_node_t *node, uint64_t low, + uint64_t high, void *data) +{ + if ((data && node->low == low && node->high == high && node->data == data) + || (!data && node->low <= low && node->high >= high)) { return 0; } if (node->low > low) { @@ -379,8 +397,10 @@ static int opal_interval_tree_compare_node(opal_interval_tree_node_t *node, uint return 1; } -static opal_interval_tree_node_t *opal_interval_tree_find_interval(opal_interval_tree_t *tree, opal_interval_tree_node_t *node, uint64_t low, - uint64_t high, void *data) +static opal_interval_tree_node_t *opal_interval_tree_find_interval(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node, + uint64_t low, uint64_t high, + void *data) { if (node == &tree->nill) { return NULL; @@ -392,136 +412,144 @@ static opal_interval_tree_node_t *opal_interval_tree_find_interval(opal_interval } if (-1 == check) { - return opal_interval_tree_find_interval (tree, node->left, low, high, data); + return opal_interval_tree_find_interval(tree, node->left, low, high, data); } - return opal_interval_tree_find_interval (tree, node->right, low, high, data); + return opal_interval_tree_find_interval(tree, node->right, low, high, data); } /* Finds the node in the tree based on the key and returns a pointer * to the node. This is a bit a code duplication, but this has to be fast * so we go ahead with the duplication */ -static opal_interval_tree_node_t *opal_interval_tree_find_node(opal_interval_tree_t *tree, uint64_t low, uint64_t high, void *data) +static opal_interval_tree_node_t * +opal_interval_tree_find_node(opal_interval_tree_t *tree, uint64_t low, uint64_t high, void *data) { - return opal_interval_tree_find_interval (tree, tree->root.left, low, high, data); + return opal_interval_tree_find_interval(tree, tree->root.left, low, high, data); } -void *opal_interval_tree_find_overlapping (opal_interval_tree_t *tree, uint64_t low, uint64_t high) +void *opal_interval_tree_find_overlapping(opal_interval_tree_t *tree, uint64_t low, uint64_t high) { opal_interval_tree_token_t token; opal_interval_tree_node_t *node; - token = opal_interval_tree_reader_get_token (tree); - node = opal_interval_tree_find_node (tree, low, high, NULL); - opal_interval_tree_reader_return_token (tree, token); + token = opal_interval_tree_reader_get_token(tree); + node = opal_interval_tree_find_node(tree, low, high, NULL); + opal_interval_tree_reader_return_token(tree, token); return node ? node->data : NULL; } -static size_t opal_interval_tree_depth_node (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static size_t opal_interval_tree_depth_node(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) { if (&tree->nill == node) { return 0; } - return 1 + max (opal_interval_tree_depth_node (tree, node->right), opal_interval_tree_depth_node (tree, node->left)); + return 1 + + max(opal_interval_tree_depth_node(tree, node->right), + opal_interval_tree_depth_node(tree, node->left)); } -size_t opal_interval_tree_depth (opal_interval_tree_t *tree) +size_t opal_interval_tree_depth(opal_interval_tree_t *tree) { opal_interval_tree_token_t token; size_t depth; - token = opal_interval_tree_reader_get_token (tree); - depth = opal_interval_tree_depth_node (tree, &tree->root); - opal_interval_tree_reader_return_token (tree, token); + token = opal_interval_tree_reader_get_token(tree); + depth = opal_interval_tree_depth_node(tree, &tree->root); + opal_interval_tree_reader_return_token(tree, token); return depth; } /* update the value of a tree pointer */ -static inline void rp_publish (opal_interval_tree_node_t **ptr, opal_interval_tree_node_t *node) +static inline void rp_publish(opal_interval_tree_node_t **ptr, opal_interval_tree_node_t *node) { /* ensure all writes complete before continuing */ - opal_atomic_wmb (); + opal_atomic_wmb(); /* just set the value */ *ptr = node; } - -static inline void rp_wait_for_readers (opal_interval_tree_t *tree) +static inline void rp_wait_for_readers(opal_interval_tree_t *tree) { uint32_t epoch_id = ++tree->epoch; /* wait for all readers to see the new tree version */ - for (int i = 0 ; i < tree->reader_count ; ++i) { - while (tree->reader_epochs[i] < epoch_id); + for (int i = 0; i < tree->reader_count; ++i) { + while (tree->reader_epochs[i] < epoch_id) { + } } } /* waits for all writers to finish with the node then releases the last reference */ -static inline void rp_free_wait (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static inline void rp_free_wait(opal_interval_tree_t *tree, opal_interval_tree_node_t *node) { - rp_wait_for_readers (tree); + rp_wait_for_readers(tree); /* no other threads are working on this node so go ahead and return it */ - opal_free_list_return_st (&tree->free_list, &node->super); + opal_free_list_return_st(&tree->free_list, &node->super); } /* schedules the node for releasing */ -static inline void rp_free (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static inline void rp_free(opal_interval_tree_t *tree, opal_interval_tree_node_t *node) { - opal_list_append (&tree->gc_list, &node->super.super); + opal_list_append(&tree->gc_list, &node->super.super); } -static opal_interval_tree_node_t *opal_interval_tree_node_copy (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static opal_interval_tree_node_t *opal_interval_tree_node_copy(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) { - opal_interval_tree_node_t *copy = (opal_interval_tree_node_t *) opal_free_list_wait_st (&tree->free_list); + opal_interval_tree_node_t *copy = (opal_interval_tree_node_t *) opal_free_list_wait_st( + &tree->free_list); size_t color_offset = offsetof(opal_interval_tree_node_t, color); - assert (NULL != copy); - memcpy ((unsigned char *) copy + color_offset, (unsigned char *) node + color_offset, - sizeof (*node) - color_offset); + assert(NULL != copy); + memcpy((unsigned char *) copy + color_offset, (unsigned char *) node + color_offset, + sizeof(*node) - color_offset); return copy; } /* this function deletes a node that is either a left or right leaf (or both) */ -static void opal_interval_tree_delete_leaf (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static void opal_interval_tree_delete_leaf(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) { const opal_interval_tree_node_t *nill = &tree->nill; opal_interval_tree_node_t **parent_ptr, *next, *parent = node->parent; opal_interval_tree_nodecolor_t color = node->color; - assert (node->left == nill || node->right == nill); + assert(node->left == nill || node->right == nill); parent_ptr = (parent->right == node) ? &parent->right : &parent->left; next = (node->right == nill) ? node->left : node->right; next->parent = node->parent; - rp_publish (parent_ptr, next); + rp_publish(parent_ptr, next); - rp_free (tree, node); + rp_free(tree, node); if (OPAL_INTERVAL_TREE_COLOR_BLACK == color) { if (OPAL_INTERVAL_TREE_COLOR_RED == next->color) { next->color = OPAL_INTERVAL_TREE_COLOR_BLACK; } else { - opal_interval_tree_delete_fixup (tree, next, parent); + opal_interval_tree_delete_fixup(tree, next, parent); } } } -static void opal_interval_tree_delete_interior (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static void opal_interval_tree_delete_interior(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) { opal_interval_tree_node_t **parent_ptr, *next, *next_copy, *parent = node->parent; opal_interval_tree_nodecolor_t color = node->color, next_color; parent_ptr = (parent->right == node) ? &parent->right : &parent->left; - next = opal_interval_tree_next (tree, node); + next = opal_interval_tree_next(tree, node); next_color = next->color; if (next != node->right) { /* case 3 */ - next_copy = opal_interval_tree_node_copy (tree, next); + next_copy = opal_interval_tree_node_copy(tree, next); next_copy->color = node->color; next_copy->left = node->left; next_copy->left->parent = next_copy; @@ -529,40 +557,40 @@ static void opal_interval_tree_delete_interior (opal_interval_tree_t *tree, opal next_copy->right->parent = next_copy; next_copy->parent = node->parent; - rp_publish (parent_ptr, next_copy); - rp_free_wait (tree, node); + rp_publish(parent_ptr, next_copy); + rp_free_wait(tree, node); - opal_interval_tree_delete_leaf (tree, next); + opal_interval_tree_delete_leaf(tree, next); } else { /* case 2. no copies are needed */ next->color = color; next->left = node->left; next->left->parent = next; next->parent = node->parent; - rp_publish (parent_ptr, next); - rp_free (tree, node); + rp_publish(parent_ptr, next); + rp_free(tree, node); - /* since we are actually "deleting" the next node the fixup needs to happen on the - * right child of next (by definition next was a left child) */ + /* since we are actually "deleting" the next node the fixup needs to happen on the + * right child of next (by definition next was a left child) */ if (OPAL_INTERVAL_TREE_COLOR_BLACK == next_color) { - if (OPAL_INTERVAL_TREE_COLOR_RED == next->right->color) { - next->right->color = OPAL_INTERVAL_TREE_COLOR_BLACK; + if (OPAL_INTERVAL_TREE_COLOR_RED == next->right->color) { + next->right->color = OPAL_INTERVAL_TREE_COLOR_BLACK; } else { - opal_interval_tree_delete_fixup (tree, next->right, next); - } - } + opal_interval_tree_delete_fixup(tree, next->right, next); + } + } } } /* Delete a node from the tree based on the key */ -int opal_interval_tree_delete (opal_interval_tree_t *tree, uint64_t low, uint64_t high, void *data) +int opal_interval_tree_delete(opal_interval_tree_t *tree, uint64_t low, uint64_t high, void *data) { opal_interval_tree_node_t *node; - opal_interval_tree_write_lock (tree); - node = opal_interval_tree_find_node (tree, low, high, data); + opal_interval_tree_write_lock(tree); + node = opal_interval_tree_find_node(tree, low, high, data); if (NULL == node) { - opal_interval_tree_write_unlock (tree); + opal_interval_tree_write_unlock(tree); return OPAL_ERR_NOT_FOUND; } @@ -575,23 +603,23 @@ int opal_interval_tree_delete (opal_interval_tree_t *tree, uint64_t low, uint64_ * 3) p is a interior node * we replace node with next(node) */ - + if ((node->left == &tree->nill) || (node->right == &tree->nill)) { /* handle case 1 */ - opal_interval_tree_delete_leaf (tree, node); + opal_interval_tree_delete_leaf(tree, node); } else { /* handle case 2 and 3 */ - opal_interval_tree_delete_interior (tree, node); + opal_interval_tree_delete_interior(tree, node); } --tree->tree_size; - opal_interval_tree_write_unlock (tree); + opal_interval_tree_write_unlock(tree); return OPAL_SUCCESS; } -int opal_interval_tree_destroy (opal_interval_tree_t *tree) +int opal_interval_tree_destroy(opal_interval_tree_t *tree) { /* Recursive inorder traversal for delete */ inorder_destroy(tree, &tree->root); @@ -599,9 +627,9 @@ int opal_interval_tree_destroy (opal_interval_tree_t *tree) return OPAL_SUCCESS; } - /* Find the next inorder successor of a node */ -static opal_interval_tree_node_t *opal_interval_tree_next (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static opal_interval_tree_node_t *opal_interval_tree_next(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) { opal_interval_tree_node_t *p = node->right; @@ -629,7 +657,8 @@ static opal_interval_tree_node_t *opal_interval_tree_next (opal_interval_tree_t /* Insert an element in the normal binary search tree fashion */ /* this function goes through the tree and finds the leaf where * the node will be inserted */ -static void opal_interval_tree_insert_node (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static void opal_interval_tree_insert_node(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node) { opal_interval_tree_node_t *parent = &tree->root; opal_interval_tree_node_t *n = parent->left; /* the real root of the tree */ @@ -646,7 +675,7 @@ static void opal_interval_tree_insert_node (opal_interval_tree_t *tree, opal_int while (n != nill) { check = opal_interval_tree_compare_node(n, node->low, node->high, node->data); /* node already exists */ - assert (0 != check); + assert(0 != check); if (n->max < node->high) { n->max = node->high; @@ -654,7 +683,7 @@ static void opal_interval_tree_insert_node (opal_interval_tree_t *tree, opal_int parent = n; n = (-1 == check) ? n->left : n->right; - assert (nill == n || n->parent == parent); + assert(nill == n || n->parent == parent); } /* place it on either the left or the right */ @@ -670,9 +699,9 @@ static void opal_interval_tree_insert_node (opal_interval_tree_t *tree, opal_int ++tree->tree_size; } -static int inorder_traversal (opal_interval_tree_t *tree, uint64_t low, uint64_t high, - bool partial_ok, opal_interval_tree_action_fn_t action, - opal_interval_tree_node_t * node, void *ctx) +static int inorder_traversal(opal_interval_tree_t *tree, uint64_t low, uint64_t high, + bool partial_ok, opal_interval_tree_action_fn_t action, + opal_interval_tree_node_t *node, void *ctx) { int rc; @@ -685,12 +714,12 @@ static int inorder_traversal (opal_interval_tree_t *tree, uint64_t low, uint64_t return rc; } - if ((!partial_ok && (node->low <= low && node->high >= high)) || - (partial_ok && ((low >= node->low && low <= node->high) || - (high >= node->low && high <= node->high) || - (node->low >= low && node->low <= high) || - (node->high >= high && node->high <= high)))) { - rc = action (node->low, node->high, node->data, ctx); + if ((!partial_ok && (node->low <= low && node->high >= high)) + || (partial_ok + && ((low >= node->low && low <= node->high) || (high >= node->low && high <= node->high) + || (node->low >= low && node->low <= high) + || (node->high >= high && node->high <= high)))) { + rc = action(node->low, node->high, node->data, ctx); if (OPAL_SUCCESS != rc) { return rc; } @@ -701,7 +730,7 @@ static int inorder_traversal (opal_interval_tree_t *tree, uint64_t low, uint64_t /* Free the nodes in inorder fashion */ -static void inorder_destroy (opal_interval_tree_t *tree, opal_interval_tree_node_t *node) +static void inorder_destroy(opal_interval_tree_t *tree, opal_interval_tree_node_t *node) { if (node == &tree->nill) { return; @@ -711,18 +740,18 @@ static void inorder_destroy (opal_interval_tree_t *tree, opal_interval_tree_node inorder_destroy(tree, node->right); if (node->left != &tree->nill) { - opal_free_list_return_st (&tree->free_list, &node->left->super); + opal_free_list_return_st(&tree->free_list, &node->left->super); } if (node->right != &tree->nill) { - opal_free_list_return_st (&tree->free_list, &node->right->super); + opal_free_list_return_st(&tree->free_list, &node->right->super); } } /* Try to access all the elements of the hashmap conditionally */ -int opal_interval_tree_traverse (opal_interval_tree_t *tree, uint64_t low, uint64_t high, - bool partial_ok, opal_interval_tree_action_fn_t action, void *ctx) +int opal_interval_tree_traverse(opal_interval_tree_t *tree, uint64_t low, uint64_t high, + bool partial_ok, opal_interval_tree_action_fn_t action, void *ctx) { opal_interval_tree_token_t token; int rc; @@ -731,16 +760,17 @@ int opal_interval_tree_traverse (opal_interval_tree_t *tree, uint64_t low, uint6 return OPAL_ERR_BAD_PARAM; } - token = opal_interval_tree_reader_get_token (tree); - rc = inorder_traversal (tree, low, high, partial_ok, action, tree->root.left, ctx); - opal_interval_tree_reader_return_token (tree, token); + token = opal_interval_tree_reader_get_token(tree); + rc = inorder_traversal(tree, low, high, partial_ok, action, tree->root.left, ctx); + opal_interval_tree_reader_return_token(tree, token); return rc; } /* Left rotate the tree */ /* basically what we want to do is to make x be the left child * of its right child */ -static opal_interval_tree_node_t *left_rotate (opal_interval_tree_t *tree, opal_interval_tree_node_t *x) +static opal_interval_tree_node_t *left_rotate(opal_interval_tree_t *tree, + opal_interval_tree_node_t *x) { opal_interval_tree_node_t *x_copy = x; opal_interval_tree_node_t *y = x->right; @@ -754,16 +784,16 @@ static opal_interval_tree_node_t *left_rotate (opal_interval_tree_t *tree, opal_ /* x's parent is now y */ x_copy->parent = y; x_copy->right = y->left; - x_copy->max = max (x_copy->high, max (x_copy->left->max, x_copy->left->max)); + x_copy->max = max(x_copy->high, max(x_copy->left->max, x_copy->left->max)); - rp_publish (&y->left, x_copy); + rp_publish(&y->left, x_copy); /* normlly we would have to check to see if we are at the root. * however, the root sentinal takes care of it for us */ if (x == parent->left) { - rp_publish (&parent->left, y); + rp_publish(&parent->left, y); } else { - rp_publish (&parent->right, y); + rp_publish(&parent->right, y); } /* the old parent of x is now y's parent */ @@ -772,11 +802,11 @@ static opal_interval_tree_node_t *left_rotate (opal_interval_tree_t *tree, opal_ return x_copy; } - /* Right rotate the tree */ /* basically what we want to do is to make x be the right child * of its left child */ -static opal_interval_tree_node_t *right_rotate (opal_interval_tree_t *tree, opal_interval_tree_node_t *x) +static opal_interval_tree_node_t *right_rotate(opal_interval_tree_t *tree, + opal_interval_tree_node_t *x) { opal_interval_tree_node_t *x_copy = x; opal_interval_tree_node_t *y = x->left; @@ -790,7 +820,7 @@ static opal_interval_tree_node_t *right_rotate (opal_interval_tree_t *tree, opal x_copy->left = y->right; x_copy->parent = y; - rp_publish (&y->right, x_copy); + rp_publish(&y->right, x_copy); /* the maximum value in the subtree rooted at y is now the value it * was at x */ @@ -798,9 +828,9 @@ static opal_interval_tree_node_t *right_rotate (opal_interval_tree_t *tree, opal y->parent = parent; if (parent->left == x) { - rp_publish (&parent->left, y); + rp_publish(&parent->left, y); } else { - rp_publish (&parent->right, y); + rp_publish(&parent->right, y); } return x_copy; @@ -812,17 +842,18 @@ size_t opal_interval_tree_size(opal_interval_tree_t *tree) return tree->tree_size; } -static bool opal_interval_tree_verify_node (opal_interval_tree_t *tree, opal_interval_tree_node_t *node, int black_depth, - int current_black_depth) +static bool opal_interval_tree_verify_node(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node, int black_depth, + int current_black_depth) { if (node == &tree->nill) { return true; } - if (OPAL_INTERVAL_TREE_COLOR_RED == node->color && - (OPAL_INTERVAL_TREE_COLOR_BLACK != node->left->color || - OPAL_INTERVAL_TREE_COLOR_BLACK != node->right->color)) { - fprintf (stderr, "Red node has a red child!\n"); + if (OPAL_INTERVAL_TREE_COLOR_RED == node->color + && (OPAL_INTERVAL_TREE_COLOR_BLACK != node->left->color + || OPAL_INTERVAL_TREE_COLOR_BLACK != node->right->color)) { + fprintf(stderr, "Red node has a red child!\n"); return false; } @@ -832,18 +863,20 @@ static bool opal_interval_tree_verify_node (opal_interval_tree_t *tree, opal_int if (node->left == &tree->nill && node->right == &tree->nill) { if (black_depth != current_black_depth) { - fprintf (stderr, "Found leaf with unexpected black depth: %d, expected: %d\n", current_black_depth, black_depth); + fprintf(stderr, "Found leaf with unexpected black depth: %d, expected: %d\n", + current_black_depth, black_depth); return false; } return true; } - return opal_interval_tree_verify_node (tree, node->left, black_depth, current_black_depth) || - opal_interval_tree_verify_node (tree, node->right, black_depth, current_black_depth); + return opal_interval_tree_verify_node(tree, node->left, black_depth, current_black_depth) + || opal_interval_tree_verify_node(tree, node->right, black_depth, current_black_depth); } -static int opal_interval_tree_black_depth (opal_interval_tree_t *tree, opal_interval_tree_node_t *node, int depth) +static int opal_interval_tree_black_depth(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node, int depth) { if (node == &tree->nill) { return depth; @@ -854,36 +887,37 @@ static int opal_interval_tree_black_depth (opal_interval_tree_t *tree, opal_inte depth++; } - return opal_interval_tree_black_depth (tree, node->left, depth); + return opal_interval_tree_black_depth(tree, node->left, depth); } -bool opal_interval_tree_verify (opal_interval_tree_t *tree) +bool opal_interval_tree_verify(opal_interval_tree_t *tree) { int black_depth; if (OPAL_INTERVAL_TREE_COLOR_BLACK != tree->root.left->color) { - fprintf (stderr, "Root node of tree is NOT black!\n"); + fprintf(stderr, "Root node of tree is NOT black!\n"); return false; } if (OPAL_INTERVAL_TREE_COLOR_BLACK != tree->nill.color) { - fprintf (stderr, "Leaf node color is NOT black!\n"); + fprintf(stderr, "Leaf node color is NOT black!\n"); return false; } - black_depth = opal_interval_tree_black_depth (tree, tree->root.left, 0); + black_depth = opal_interval_tree_black_depth(tree, tree->root.left, 0); - return opal_interval_tree_verify_node (tree, tree->root.left, black_depth, 0); + return opal_interval_tree_verify_node(tree, tree->root.left, black_depth, 0); } -static void opal_interval_tree_dump_node (opal_interval_tree_t *tree, opal_interval_tree_node_t *node, int black_rank, FILE *fh) +static void opal_interval_tree_dump_node(opal_interval_tree_t *tree, + opal_interval_tree_node_t *node, int black_rank, FILE *fh) { const char *color = (node->color == OPAL_INTERVAL_TREE_COLOR_BLACK) ? "black" : "red"; uintptr_t left = (uintptr_t) node->left, right = (uintptr_t) node->right; opal_interval_tree_node_t *nill = &tree->nill; if (node->color == OPAL_INTERVAL_TREE_COLOR_BLACK) { - ++black_rank; + ++black_rank; } if (nill == node) { @@ -893,46 +927,48 @@ static void opal_interval_tree_dump_node (opal_interval_tree_t *tree, opal_inter /* print out nill nodes if any */ if ((uintptr_t) nill == left) { left = (uintptr_t) node | 0x1; - fprintf (fh, " Node%lx [color=black,label=nill];\n\n", left); + fprintf(fh, " Node%lx [color=black,label=nill];\n\n", left); } else { left = (uintptr_t) node->left; } if ((uintptr_t) nill == right) { right = (uintptr_t) node | 0x2; - fprintf (fh, " Node%lx [color=black,label=nill];\n\n", right); + fprintf(fh, " Node%lx [color=black,label=nill];\n\n", right); } else { right = (uintptr_t) node->right; } /* print out this node and its edges */ - fprintf (fh, " Node%lx [color=%s,shape=box,label=\"[0x%" PRIx64 ",0x%" PRIx64 "]\\nmax=0x%" PRIx64 - "\\ndata=0x%lx\\nblack rank=%d\"];\n", (uintptr_t) node, color, node->low, node->high, node->max, - (uintptr_t) node->data, black_rank); - fprintf (fh, " Node%lx -> Node%lx;\n", (uintptr_t) node, left); - fprintf (fh, " Node%lx -> Node%lx;\n\n", (uintptr_t) node, right); + fprintf(fh, + " Node%lx [color=%s,shape=box,label=\"[0x%" PRIx64 ",0x%" PRIx64 "]\\nmax=0x%" PRIx64 + "\\ndata=0x%lx\\nblack rank=%d\"];\n", + (uintptr_t) node, color, node->low, node->high, node->max, (uintptr_t) node->data, + black_rank); + fprintf(fh, " Node%lx -> Node%lx;\n", (uintptr_t) node, left); + fprintf(fh, " Node%lx -> Node%lx;\n\n", (uintptr_t) node, right); if (node != tree->root.left) { - fprintf (fh, " Node%lx -> Node%lx;\n\n", (uintptr_t) node, (uintptr_t) node->parent); + fprintf(fh, " Node%lx -> Node%lx;\n\n", (uintptr_t) node, (uintptr_t) node->parent); } - opal_interval_tree_dump_node (tree, node->left, black_rank, fh); - opal_interval_tree_dump_node (tree, node->right, black_rank, fh); + opal_interval_tree_dump_node(tree, node->left, black_rank, fh); + opal_interval_tree_dump_node(tree, node->right, black_rank, fh); } -int opal_interval_tree_dump (opal_interval_tree_t *tree, const char *path) +int opal_interval_tree_dump(opal_interval_tree_t *tree, const char *path) { FILE *fh; - fh = fopen (path, "w"); + fh = fopen(path, "w"); if (NULL == fh) { return OPAL_ERR_BAD_PARAM; } - fprintf (fh, "digraph {\n"); - fprintf (fh, " graph [ordering=\"out\"];"); - opal_interval_tree_dump_node (tree, tree->root.left, 0, fh); - fprintf (fh, "}\n"); + fprintf(fh, "digraph {\n"); + fprintf(fh, " graph [ordering=\"out\"];"); + opal_interval_tree_dump_node(tree, tree->root.left, 0, fh); + fprintf(fh, "}\n"); - fclose (fh); + fclose(fh); return OPAL_SUCCESS; } diff --git a/opal/class/opal_interval_tree.h b/opal/class/opal_interval_tree.h index 68f6fe4cef5..ff324c05c8f 100644 --- a/opal/class/opal_interval_tree.h +++ b/opal/class/opal_interval_tree.h @@ -29,10 +29,10 @@ #define OPAL_INTERVAL_TREE_H #include "opal_config.h" -#include -#include "opal/constants.h" -#include "opal/class/opal_object.h" #include "opal/class/opal_free_list.h" +#include "opal/class/opal_object.h" +#include "opal/constants.h" +#include BEGIN_C_DECLS /* @@ -40,20 +40,22 @@ BEGIN_C_DECLS */ /** - * red and black enum - */ -typedef enum {OPAL_INTERVAL_TREE_COLOR_RED, OPAL_INTERVAL_TREE_COLOR_BLACK} opal_interval_tree_nodecolor_t; + * red and black enum + */ +typedef enum { + OPAL_INTERVAL_TREE_COLOR_RED, + OPAL_INTERVAL_TREE_COLOR_BLACK +} opal_interval_tree_nodecolor_t; /** - * node data structure - */ -struct opal_interval_tree_node_t -{ - opal_free_list_item_t super; /**< the parent class */ + * node data structure + */ +struct opal_interval_tree_node_t { + opal_free_list_item_t super; /**< the parent class */ opal_interval_tree_nodecolor_t color; /**< the node color */ - struct opal_interval_tree_node_t *parent;/**< the parent node, can be NULL */ - struct opal_interval_tree_node_t *left; /**< the left child - can be nill */ - struct opal_interval_tree_node_t *right; /**< the right child - can be nill */ + struct opal_interval_tree_node_t *parent; /**< the parent node, can be NULL */ + struct opal_interval_tree_node_t *left; /**< the left child - can be nill */ + struct opal_interval_tree_node_t *right; /**< the right child - can be nill */ /** edit epoch associated with this node */ uint32_t epoch; /** data for this interval */ @@ -71,22 +73,22 @@ typedef struct opal_interval_tree_node_t opal_interval_tree_node_t; #define OPAL_INTERVAL_TREE_MAX_READERS 128 /** - * the data structure that holds all the needed information about the tree. - */ + * the data structure that holds all the needed information about the tree. + */ struct opal_interval_tree_t { - opal_object_t super; /**< the parent class */ + opal_object_t super; /**< the parent class */ /* this root pointer doesn't actually point to the root of the tree. * rather, it points to a sentinal node who's left branch is the real * root of the tree. This is done to eliminate special cases */ - opal_interval_tree_node_t root; /**< a pointer to the root of the tree */ - opal_interval_tree_node_t nill; /**< the nill sentinal node */ - opal_free_list_t free_list; /**< the free list to get the memory from */ - opal_list_t gc_list; /**< list of nodes that need to be released */ - uint32_t epoch; /**< current update epoch */ - opal_atomic_size_t tree_size; /**< the current size of the tree */ - opal_atomic_int32_t lock; /**< update lock */ - opal_atomic_int32_t reader_count; /**< current highest reader slot to check */ - volatile uint32_t reader_id; /**< next reader slot to check */ + opal_interval_tree_node_t root; /**< a pointer to the root of the tree */ + opal_interval_tree_node_t nill; /**< the nill sentinal node */ + opal_free_list_t free_list; /**< the free list to get the memory from */ + opal_list_t gc_list; /**< list of nodes that need to be released */ + uint32_t epoch; /**< current update epoch */ + opal_atomic_size_t tree_size; /**< the current size of the tree */ + opal_atomic_int32_t lock; /**< update lock */ + opal_atomic_int32_t reader_count; /**< current highest reader slot to check */ + volatile uint32_t reader_id; /**< next reader slot to check */ opal_atomic_uint32_t reader_epochs[OPAL_INTERVAL_TREE_MAX_READERS]; }; typedef struct opal_interval_tree_t opal_interval_tree_t; @@ -98,10 +100,10 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_interval_tree_t); /* Function pointers for map traversal function */ /** - * this function is used for the opal_interval_tree_traverse function. - * it is passed a pointer to the value for each node and, if it returns - * a one, the action function is called on that node. Otherwise, the node is ignored. - */ + * this function is used for the opal_interval_tree_traverse function. + * it is passed a pointer to the value for each node and, if it returns + * a one, the action function is called on that node. Otherwise, the node is ignored. + */ typedef int (*opal_interval_tree_condition_fn_t)(void *); /** * this function is used for the user to perform any action on the passed @@ -116,93 +118,96 @@ typedef int (*opal_interval_tree_action_fn_t)(uint64_t low, uint64_t high, void */ /** - * the function creates a new tree - * - * @param tree a pointer to an allocated area of memory for the main - * tree data structure. - * @param comp a pointer to the function to use for comaparing 2 nodes - * - * @retval OPAL_SUCCESS if it is successful - * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful - */ -OPAL_DECLSPEC int opal_interval_tree_init(opal_interval_tree_t * tree); - + * the function creates a new tree + * + * @param tree a pointer to an allocated area of memory for the main + * tree data structure. + * @param comp a pointer to the function to use for comaparing 2 nodes + * + * @retval OPAL_SUCCESS if it is successful + * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful + */ +OPAL_DECLSPEC int opal_interval_tree_init(opal_interval_tree_t *tree); /** - * inserts a node into the tree - * - * @param tree a pointer to the tree data structure - * @param key the key for the node - * @param value the value for the node - * - * @retval OPAL_SUCCESS - * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful - */ -OPAL_DECLSPEC int opal_interval_tree_insert(opal_interval_tree_t *tree, void *value, uint64_t low, uint64_t high); + * inserts a node into the tree + * + * @param tree a pointer to the tree data structure + * @param key the key for the node + * @param value the value for the node + * + * @retval OPAL_SUCCESS + * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful + */ +OPAL_DECLSPEC int opal_interval_tree_insert(opal_interval_tree_t *tree, void *value, uint64_t low, + uint64_t high); /** - * finds a value in the tree based on the passed key using passed - * compare function - * - * @param tree a pointer to the tree data structure - * @param key a pointer to the key - * @param compare function - * - * @retval pointer to the value if found - * @retval NULL if not found - */ -OPAL_DECLSPEC void *opal_interval_tree_find_overlapping (opal_interval_tree_t *tree, uint64_t low, uint64_t high); + * finds a value in the tree based on the passed key using passed + * compare function + * + * @param tree a pointer to the tree data structure + * @param key a pointer to the key + * @param compare function + * + * @retval pointer to the value if found + * @retval NULL if not found + */ +OPAL_DECLSPEC void *opal_interval_tree_find_overlapping(opal_interval_tree_t *tree, uint64_t low, + uint64_t high); /** - * deletes a node based on its interval - * - * @param tree a pointer to the tree data structure - * @param low low value of interval - * @param high high value of interval - * @param data data to match (NULL for any) - * - * @retval OPAL_SUCCESS if the node is found and deleted - * @retval OPAL_ERR_NOT_FOUND if the node is not found - * - * This function finds and deletes an interval from the tree that exactly matches - * the given range. - */ -OPAL_DECLSPEC int opal_interval_tree_delete(opal_interval_tree_t *tree, uint64_t low, uint64_t high, void *data); + * deletes a node based on its interval + * + * @param tree a pointer to the tree data structure + * @param low low value of interval + * @param high high value of interval + * @param data data to match (NULL for any) + * + * @retval OPAL_SUCCESS if the node is found and deleted + * @retval OPAL_ERR_NOT_FOUND if the node is not found + * + * This function finds and deletes an interval from the tree that exactly matches + * the given range. + */ +OPAL_DECLSPEC int opal_interval_tree_delete(opal_interval_tree_t *tree, uint64_t low, uint64_t high, + void *data); /** - * frees all the nodes on the tree - * - * @param tree a pointer to the tree data structure - * - * @retval OPAL_SUCCESS - */ + * frees all the nodes on the tree + * + * @param tree a pointer to the tree data structure + * + * @retval OPAL_SUCCESS + */ OPAL_DECLSPEC int opal_interval_tree_destroy(opal_interval_tree_t *tree); /** - * traverses the entire tree, performing the cond function on each of the - * values and if it returns one it performs the action function on the values - * - * @param tree a pointer to the tree - * @param low low value of interval - * @param high high value of interval - * @param partial_ok traverse nodes that parially overlap the given range - * @param action a pointer to the action function - * @param ctx context to pass to action function - * - * @retval OPAL_SUCCESS - * @retval OPAL_ERROR if there is an error - */ -OPAL_DECLSPEC int opal_interval_tree_traverse (opal_interval_tree_t *tree, uint64_t low, uint64_t high, - bool complete, opal_interval_tree_action_fn_t action, void *ctx); + * traverses the entire tree, performing the cond function on each of the + * values and if it returns one it performs the action function on the values + * + * @param tree a pointer to the tree + * @param low low value of interval + * @param high high value of interval + * @param partial_ok traverse nodes that parially overlap the given range + * @param action a pointer to the action function + * @param ctx context to pass to action function + * + * @retval OPAL_SUCCESS + * @retval OPAL_ERROR if there is an error + */ +OPAL_DECLSPEC int opal_interval_tree_traverse(opal_interval_tree_t *tree, uint64_t low, + uint64_t high, bool complete, + opal_interval_tree_action_fn_t action, void *ctx); /** - * returns the size of the tree - * - * @param tree a pointer to the tree data structure - * - * @retval int the nuber of items on the tree - */ -OPAL_DECLSPEC size_t opal_interval_tree_size (opal_interval_tree_t *tree); + * returns the size of the tree + * + * @param tree a pointer to the tree data structure + * + * @retval int the nuber of items on the tree + */ +OPAL_DECLSPEC size_t opal_interval_tree_size(opal_interval_tree_t *tree); /** * Diagnostic function to get the max depth of an interval tree. @@ -213,7 +218,7 @@ OPAL_DECLSPEC size_t opal_interval_tree_size (opal_interval_tree_t *tree); * maximum depth. For a valid interval tree this depth will always be * O(log(n)) where n is the number of intervals in the tree. */ -OPAL_DECLSPEC size_t opal_interval_tree_depth (opal_interval_tree_t *tree); +OPAL_DECLSPEC size_t opal_interval_tree_depth(opal_interval_tree_t *tree); /** * Diagnostic function that can be used to verify that an interval tree @@ -224,7 +229,7 @@ OPAL_DECLSPEC size_t opal_interval_tree_depth (opal_interval_tree_t *tree); * @returns true if the tree is a valid interval tree * @returns false otherwise */ -OPAL_DECLSPEC bool opal_interval_tree_verify (opal_interval_tree_t *tree); +OPAL_DECLSPEC bool opal_interval_tree_verify(opal_interval_tree_t *tree); /** * Dump a DOT representation of the interval tree @@ -235,7 +240,7 @@ OPAL_DECLSPEC bool opal_interval_tree_verify (opal_interval_tree_t *tree); * This function dumps the tree and includes: color, data value, interval, and sub-tree * min and max. */ -OPAL_DECLSPEC int opal_interval_tree_dump (opal_interval_tree_t *tree, const char *path); +OPAL_DECLSPEC int opal_interval_tree_dump(opal_interval_tree_t *tree, const char *path); END_C_DECLS #endif /* OPAL_INTERVAL_TREE_H */ diff --git a/opal/class/opal_lifo.c b/opal/class/opal_lifo.c index c2fc30c51c6..e4bcce794d8 100644 --- a/opal/class/opal_lifo.c +++ b/opal/class/opal_lifo.c @@ -22,7 +22,7 @@ #include "opal_config.h" #include "opal/class/opal_lifo.h" -static void opal_lifo_construct (opal_lifo_t *lifo) +static void opal_lifo_construct(opal_lifo_t *lifo) { OBJ_CONSTRUCT(&lifo->opal_lifo_ghost, opal_list_item_t); lifo->opal_lifo_ghost.opal_list_next = &lifo->opal_lifo_ghost; diff --git a/opal/class/opal_lifo.h b/opal/class/opal_lifo.h index 4c34fbe5f5c..ba973417dff 100644 --- a/opal/class/opal_lifo.h +++ b/opal/class/opal_lifo.h @@ -29,17 +29,17 @@ #define OPAL_LIFO_H_HAS_BEEN_INCLUDED #include "opal_config.h" -#include #include "opal/class/opal_list.h" +#include -#include "opal/sys/atomic.h" #include "opal/mca/threads/mutex.h" +#include "opal/sys/atomic.h" BEGIN_C_DECLS /* NTH: temporarily suppress warnings about this not being defined */ #if !defined(OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128) -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 0 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 0 #endif /** @@ -61,28 +61,29 @@ union opal_counted_pointer_t { }; typedef union opal_counted_pointer_t opal_counted_pointer_t; - #if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 && !OPAL_HAVE_ATOMIC_LLSC_PTR /* Add one element to the FIFO. We will return the last head of the list * to allow the upper level to detect if this element is the first one in the * list (if the list was empty before this operation). */ -static inline bool opal_update_counted_pointer (volatile opal_counted_pointer_t * volatile addr, opal_counted_pointer_t *old, - opal_list_item_t *item) +static inline bool opal_update_counted_pointer(volatile opal_counted_pointer_t *volatile addr, + opal_counted_pointer_t *old, opal_list_item_t *item) { opal_counted_pointer_t new_p; new_p.data.item = (intptr_t) item; new_p.data.counter = old->data.counter + 1; - return opal_atomic_compare_exchange_strong_128 (&addr->atomic_value, &old->value, new_p.value); + return opal_atomic_compare_exchange_strong_128(&addr->atomic_value, &old->value, new_p.value); } -__opal_attribute_always_inline__ -static inline void opal_read_counted_pointer (volatile opal_counted_pointer_t * volatile addr, opal_counted_pointer_t *value) +__opal_attribute_always_inline__ static inline void +opal_read_counted_pointer(volatile opal_counted_pointer_t *volatile addr, + opal_counted_pointer_t *value) { - /* most platforms do not read the value atomically so make sure we read the counted pointer in a specific order */ + /* most platforms do not read the value atomically so make sure we read the counted pointer in a + * specific order */ value->data.counter = addr->data.counter; - opal_atomic_rmb (); + opal_atomic_rmb(); value->data.item = addr->data.item; } @@ -91,7 +92,7 @@ static inline void opal_read_counted_pointer (volatile opal_counted_pointer_t * /** * @brief Helper function for lifo/fifo to sleep this thread if excessive contention is detected */ -static inline void _opal_lifo_release_cpu (void) +static inline void _opal_lifo_release_cpu(void) { /* NTH: there are many ways to cause the current thread to be suspended. This one * should work well in most cases. Another approach would be to use poll (NULL, 0, ) but @@ -99,11 +100,10 @@ static inline void _opal_lifo_release_cpu (void) * is a performance improvement for the lifo test when this call is made on detection * of contention but it may not translate into actually MPI or application performance * improvements. */ - static struct timespec interval = { .tv_sec = 0, .tv_nsec = 100 }; - nanosleep (&interval, NULL); + static struct timespec interval = {.tv_sec = 0, .tv_nsec = 100}; + nanosleep(&interval, NULL); } - /* Atomic Last In First Out lists. If we are in a multi-threaded environment then the * atomicity is insured via the compare-and-swap operation, if not we simply do a read * and/or a write. @@ -127,34 +127,32 @@ typedef struct opal_lifo_t opal_lifo_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_lifo_t); - /* The ghost pointer will never change. The head will change via an atomic * compare-and-swap. On most architectures the reading of a pointer is an * atomic operation so we don't have to protect it. */ -static inline bool opal_lifo_is_empty( opal_lifo_t* lifo ) +static inline bool opal_lifo_is_empty(opal_lifo_t *lifo) { return (opal_list_item_t *) lifo->opal_lifo_head.data.item == &lifo->opal_lifo_ghost; } - #if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 && !OPAL_HAVE_ATOMIC_LLSC_PTR /* Add one element to the LIFO. We will return the last head of the list * to allow the upper level to detect if this element is the first one in the * list (if the list was empty before this operation). */ -static inline opal_list_item_t *opal_lifo_push_atomic (opal_lifo_t *lifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_lifo_push_atomic(opal_lifo_t *lifo, opal_list_item_t *item) { opal_list_item_t *next = (opal_list_item_t *) lifo->opal_lifo_head.data.item; do { item->opal_list_next = next; - opal_atomic_wmb (); + opal_atomic_wmb(); /* to protect against ABA issues it is sufficient to only update the counter in pop */ - if (opal_atomic_compare_exchange_strong_ptr (&lifo->opal_lifo_head.data.item, (intptr_t *) &next, (intptr_t) item)) { + if (opal_atomic_compare_exchange_strong_ptr(&lifo->opal_lifo_head.data.item, + (intptr_t *) &next, (intptr_t) item)) { return next; } /* DO some kind of pause to release the bus */ @@ -164,12 +162,12 @@ static inline opal_list_item_t *opal_lifo_push_atomic (opal_lifo_t *lifo, /* Retrieve one element from the LIFO. If we reach the ghost element then the LIFO * is empty so we return NULL. */ -static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) +static inline opal_list_item_t *opal_lifo_pop_atomic(opal_lifo_t *lifo) { opal_counted_pointer_t old_head; opal_list_item_t *item; - opal_read_counted_pointer (&lifo->opal_lifo_head, &old_head); + opal_read_counted_pointer(&lifo->opal_lifo_head, &old_head); do { item = (opal_list_item_t *) old_head.data.item; @@ -177,9 +175,9 @@ static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) return NULL; } - if (opal_update_counted_pointer (&lifo->opal_lifo_head, &old_head, - (opal_list_item_t *) item->opal_list_next)) { - opal_atomic_wmb (); + if (opal_update_counted_pointer(&lifo->opal_lifo_head, &old_head, + (opal_list_item_t *) item->opal_list_next)) { + opal_atomic_wmb(); item->opal_list_next = NULL; return item; } @@ -192,8 +190,7 @@ static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) * to allow the upper level to detect if this element is the first one in the * list (if the list was empty before this operation). */ -static inline opal_list_item_t *opal_lifo_push_atomic (opal_lifo_t *lifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_lifo_push_atomic(opal_lifo_t *lifo, opal_list_item_t *item) { opal_list_item_t *next = (opal_list_item_t *) lifo->opal_lifo_head.data.item; @@ -203,8 +200,9 @@ static inline opal_list_item_t *opal_lifo_push_atomic (opal_lifo_t *lifo, do { item->opal_list_next = next; opal_atomic_wmb(); - if (opal_atomic_compare_exchange_strong_ptr (&lifo->opal_lifo_head.data.item, (intptr_t *) &next, (intptr_t) item)) { - opal_atomic_wmb (); + if (opal_atomic_compare_exchange_strong_ptr(&lifo->opal_lifo_head.data.item, + (intptr_t *) &next, (intptr_t) item)) { + opal_atomic_wmb(); /* now safe to pop this item */ item->item_free = 0; return next; @@ -213,12 +211,12 @@ static inline opal_list_item_t *opal_lifo_push_atomic (opal_lifo_t *lifo, } while (1); } -#if OPAL_HAVE_ATOMIC_LLSC_PTR +# if OPAL_HAVE_ATOMIC_LLSC_PTR /* Retrieve one element from the LIFO. If we reach the ghost element then the LIFO * is empty so we return NULL. */ -static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) +static inline opal_list_item_t *opal_lifo_pop_atomic(opal_lifo_t *lifo) { register opal_list_item_t *item, *next; int attempt = 0, ret; @@ -227,7 +225,7 @@ static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) if (++attempt == 5) { /* deliberatly suspend this thread to allow other threads to run. this should * only occur during periods of contention on the lifo. */ - _opal_lifo_release_cpu (); + _opal_lifo_release_cpu(); attempt = 0; } @@ -240,33 +238,34 @@ static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) opal_atomic_sc_ptr(&lifo->opal_lifo_head.data.item, next, ret); } while (!ret); - opal_atomic_wmb (); + opal_atomic_wmb(); item->opal_list_next = NULL; return item; } -#else +# else /* Retrieve one element from the LIFO. If we reach the ghost element then the LIFO * is empty so we return NULL. */ -static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) +static inline opal_list_item_t *opal_lifo_pop_atomic(opal_lifo_t *lifo) { opal_list_item_t *item, *head, *ghost = &lifo->opal_lifo_ghost; - while ((item=(opal_list_item_t *)lifo->opal_lifo_head.data.item) != ghost) { + while ((item = (opal_list_item_t *) lifo->opal_lifo_head.data.item) != ghost) { /* ensure it is safe to pop the head */ if (opal_atomic_swap_32((opal_atomic_int32_t *) &item->item_free, 1)) { continue; } - opal_atomic_wmb (); + opal_atomic_wmb(); head = item; /* try to swap out the head pointer */ - if (opal_atomic_compare_exchange_strong_ptr (&lifo->opal_lifo_head.data.item, (intptr_t *) &head, - (intptr_t) item->opal_list_next)) { + if (opal_atomic_compare_exchange_strong_ptr(&lifo->opal_lifo_head.data.item, + (intptr_t *) &head, + (intptr_t) item->opal_list_next)) { break; } @@ -281,19 +280,18 @@ static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) return NULL; } - opal_atomic_wmb (); + opal_atomic_wmb(); item->opal_list_next = NULL; return item; } -#endif /* OPAL_HAVE_ATOMIC_LLSC_PTR */ +# endif /* OPAL_HAVE_ATOMIC_LLSC_PTR */ #endif /* single-threaded versions of the lifo functions */ -static inline opal_list_item_t *opal_lifo_push_st (opal_lifo_t *lifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_lifo_push_st(opal_lifo_t *lifo, opal_list_item_t *item) { item->opal_list_next = (opal_list_item_t *) lifo->opal_lifo_head.data.item; item->item_free = 0; @@ -301,7 +299,7 @@ static inline opal_list_item_t *opal_lifo_push_st (opal_lifo_t *lifo, return (opal_list_item_t *) item->opal_list_next; } -static inline opal_list_item_t *opal_lifo_pop_st (opal_lifo_t *lifo) +static inline opal_list_item_t *opal_lifo_pop_st(opal_lifo_t *lifo) { opal_list_item_t *item; item = (opal_list_item_t *) lifo->opal_lifo_head.data.item; @@ -316,25 +314,24 @@ static inline opal_list_item_t *opal_lifo_pop_st (opal_lifo_t *lifo) } /* conditional versions of lifo functions. use atomics if opal_using_threads is set */ -static inline opal_list_item_t *opal_lifo_push (opal_lifo_t *lifo, - opal_list_item_t *item) +static inline opal_list_item_t *opal_lifo_push(opal_lifo_t *lifo, opal_list_item_t *item) { - if (opal_using_threads ()) { - return opal_lifo_push_atomic (lifo, item); + if (opal_using_threads()) { + return opal_lifo_push_atomic(lifo, item); } - return opal_lifo_push_st (lifo, item); + return opal_lifo_push_st(lifo, item); } -static inline opal_list_item_t *opal_lifo_pop (opal_lifo_t *lifo) +static inline opal_list_item_t *opal_lifo_pop(opal_lifo_t *lifo) { - if (opal_using_threads ()) { - return opal_lifo_pop_atomic (lifo); + if (opal_using_threads()) { + return opal_lifo_pop_atomic(lifo); } - return opal_lifo_pop_st (lifo); + return opal_lifo_pop_st(lifo); } END_C_DECLS -#endif /* OPAL_LIFO_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_LIFO_H_HAS_BEEN_INCLUDED */ diff --git a/opal/class/opal_list.c b/opal/class/opal_list.c index f61580eeabd..47ffb033004 100644 --- a/opal/class/opal_list.c +++ b/opal/class/opal_list.c @@ -26,26 +26,16 @@ * List classes */ -static void opal_list_item_construct(opal_list_item_t*); -static void opal_list_item_destruct(opal_list_item_t*); +static void opal_list_item_construct(opal_list_item_t *); +static void opal_list_item_destruct(opal_list_item_t *); -OBJ_CLASS_INSTANCE( - opal_list_item_t, - opal_object_t, - opal_list_item_construct, - opal_list_item_destruct -); +OBJ_CLASS_INSTANCE(opal_list_item_t, opal_object_t, opal_list_item_construct, + opal_list_item_destruct); -static void opal_list_construct(opal_list_t*); -static void opal_list_destruct(opal_list_t*); - -OBJ_CLASS_INSTANCE( - opal_list_t, - opal_object_t, - opal_list_construct, - opal_list_destruct -); +static void opal_list_construct(opal_list_t *); +static void opal_list_destruct(opal_list_t *); +OBJ_CLASS_INSTANCE(opal_list_t, opal_object_t, opal_list_construct, opal_list_destruct); /* * @@ -66,12 +56,11 @@ static void opal_list_item_construct(opal_list_item_t *item) static void opal_list_item_destruct(opal_list_item_t *item) { #if OPAL_ENABLE_DEBUG - assert( 0 == item->opal_list_item_refcount ); - assert( NULL == item->opal_list_item_belong_to ); -#endif /* OPAL_ENABLE_DEBUG */ + assert(0 == item->opal_list_item_refcount); + assert(NULL == item->opal_list_item_belong_to); +#endif /* OPAL_ENABLE_DEBUG */ } - /* * * opal_list_list_t interface @@ -85,8 +74,8 @@ static void opal_list_construct(opal_list_t *list) should never be removed from this list, added to another list, etc. So set them to sentinel values. */ - OBJ_CONSTRUCT( &(list->opal_list_sentinel), opal_list_item_t ); - list->opal_list_sentinel.opal_list_item_refcount = 1; + OBJ_CONSTRUCT(&(list->opal_list_sentinel), opal_list_item_t); + list->opal_list_sentinel.opal_list_item_refcount = 1; list->opal_list_sentinel.opal_list_item_belong_to = list; #endif @@ -95,7 +84,6 @@ static void opal_list_construct(opal_list_t *list) list->opal_list_length = 0; } - /* * Reset all the pointers to be NULL -- do not actually destroy * anything. @@ -105,22 +93,20 @@ static void opal_list_destruct(opal_list_t *list) opal_list_construct(list); } - /* * Insert an item at a specific place in a list */ bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx) { /* Adds item to list at index and retains item. */ - int i; + int i; volatile opal_list_item_t *ptr, *next; - if ( idx >= (long long)list->opal_list_length ) { + if (idx >= (long long) list->opal_list_length) { return false; } - if ( 0 == idx ) - { + if (0 == idx) { opal_list_prepend(list, item); } else { #if OPAL_ENABLE_DEBUG @@ -131,8 +117,9 @@ bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx) #endif /* pointer to element 0 */ ptr = list->opal_list_sentinel.opal_list_next; - for ( i = 0; i < idx-1; i++ ) + for (i = 0; i < idx - 1; i++) { ptr = ptr->opal_list_next; + } next = ptr->opal_list_next; item->opal_list_next = next; @@ -144,7 +131,7 @@ bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx) /* Spot check: ensure this item is only on the list that we just inserted it into */ - opal_atomic_add ( &(item->opal_list_item_refcount), 1 ); + opal_atomic_add(&(item->opal_list_item_refcount), 1); assert(1 == item->opal_list_item_refcount); item->opal_list_item_belong_to = list; #endif @@ -154,11 +141,8 @@ bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx) return true; } - -static -void -opal_list_transfer(opal_list_item_t *pos, opal_list_item_t *begin, - opal_list_item_t *end) +static void opal_list_transfer(opal_list_item_t *pos, opal_list_item_t *begin, + opal_list_item_t *end) { volatile opal_list_item_t *tmp; @@ -175,25 +159,21 @@ opal_list_transfer(opal_list_item_t *pos, opal_list_item_t *begin, begin->opal_list_prev = tmp; #if OPAL_ENABLE_DEBUG { - volatile opal_list_item_t* item = begin; - while( pos != item ) { + volatile opal_list_item_t *item = begin; + while (pos != item) { item->opal_list_item_belong_to = pos->opal_list_item_belong_to; item = item->opal_list_next; assert(NULL != item); } } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ } } - -void -opal_list_join(opal_list_t *thislist, opal_list_item_t *pos, - opal_list_t *xlist) +void opal_list_join(opal_list_t *thislist, opal_list_item_t *pos, opal_list_t *xlist) { if (0 != opal_list_get_size(xlist)) { - opal_list_transfer(pos, opal_list_get_first(xlist), - opal_list_get_end(xlist)); + opal_list_transfer(pos, opal_list_get_first(xlist), opal_list_get_end(xlist)); /* fix the sizes */ thislist->opal_list_length += xlist->opal_list_length; @@ -201,11 +181,8 @@ opal_list_join(opal_list_t *thislist, opal_list_item_t *pos, } } - -void -opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos, - opal_list_t *xlist, opal_list_item_t *first, - opal_list_item_t *last) +void opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos, opal_list_t *xlist, + opal_list_item_t *first, opal_list_item_t *last) { size_t change = 0; opal_list_item_t *tmp; @@ -215,7 +192,7 @@ opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos, * first, since last might be end and then we wouldn't be able * to run the loop) */ - for (tmp = first ; tmp != last ; tmp = opal_list_get_next(tmp)) { + for (tmp = first; tmp != last; tmp = opal_list_get_next(tmp)) { change++; } @@ -227,31 +204,28 @@ opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos, } } - -int opal_list_sort(opal_list_t* list, opal_list_item_compare_fn_t compare) +int opal_list_sort(opal_list_t *list, opal_list_item_compare_fn_t compare) { - opal_list_item_t* item; - opal_list_item_t** items; - size_t i, index=0; + opal_list_item_t *item; + opal_list_item_t **items; + size_t i, index = 0; if (0 == list->opal_list_length) { return OPAL_SUCCESS; } - items = (opal_list_item_t**)malloc(sizeof(opal_list_item_t*) * - list->opal_list_length); + items = (opal_list_item_t **) malloc(sizeof(opal_list_item_t *) * list->opal_list_length); if (NULL == items) { return OPAL_ERR_OUT_OF_RESOURCE; } - while(NULL != (item = opal_list_remove_first(list))) { + while (NULL != (item = opal_list_remove_first(list))) { items[index++] = item; } - qsort(items, index, sizeof(opal_list_item_t*), - (int(*)(const void*,const void*))compare); - for (i=0; i #include -#include "opal/class/opal_object.h" #if OPAL_ENABLE_DEBUG /* Need atomics for debugging (reference counting) */ -#include "opal/sys/atomic.h" -#include "opal/mca/threads/mutex.h" +# include "opal/mca/threads/mutex.h" +# include "opal/sys/atomic.h" #endif BEGIN_C_DECLS @@ -93,19 +93,17 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_list_t); */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_list_item_t); - /** * \internal * * Struct of an opal_list_item_t */ -struct opal_list_item_t -{ +struct opal_list_item_t { opal_object_t super; /**< Generic parent class for all Open MPI objects */ - volatile struct opal_list_item_t * volatile opal_list_next; + volatile struct opal_list_item_t *volatile opal_list_next; /**< Pointer to next list item */ - volatile struct opal_list_item_t * volatile opal_list_prev; + volatile struct opal_list_item_t *volatile opal_list_prev; /**< Pointer to previous list item */ int32_t item_free; @@ -113,7 +111,7 @@ struct opal_list_item_t /** Atomic reference count for debugging */ opal_atomic_int32_t opal_list_item_refcount; /** The list this item belong to */ - volatile struct opal_list_t* opal_list_item_belong_to; + volatile struct opal_list_t *opal_list_item_belong_to; #endif }; /** @@ -121,7 +119,6 @@ struct opal_list_item_t */ typedef struct opal_list_item_t opal_list_item_t; - /** * Get the next item in a list. * @@ -130,7 +127,7 @@ typedef struct opal_list_item_t opal_list_item_t; * @returns The next item in the list */ #define opal_list_get_next(item) \ - ((item) ? ((opal_list_item_t*) ((opal_list_item_t*)(item))->opal_list_next) : NULL) + ((item) ? ((opal_list_item_t *) ((opal_list_item_t *) (item))->opal_list_next) : NULL) /** * Get the next item in a list. @@ -140,21 +137,19 @@ typedef struct opal_list_item_t opal_list_item_t; * @returns The next item in the list */ #define opal_list_get_prev(item) \ - ((item) ? ((opal_list_item_t*) ((opal_list_item_t*)(item))->opal_list_prev) : NULL) - + ((item) ? ((opal_list_item_t *) ((opal_list_item_t *) (item))->opal_list_prev) : NULL) /** * \internal * * Struct of an opal_list_t */ -struct opal_list_t -{ - opal_object_t super; +struct opal_list_t { + opal_object_t super; /**< Generic parent class for all Open MPI objects */ - opal_list_item_t opal_list_sentinel; + opal_list_item_t opal_list_sentinel; /**< Head and tail item of the list */ - volatile size_t opal_list_length; + volatile size_t opal_list_length; /**< Quick reference to the number of items in the list */ }; /** @@ -170,28 +165,27 @@ typedef struct opal_list_t opal_list_t; * * @param[in] list List to destruct or release */ -#define OPAL_LIST_DESTRUCT(list) \ - do { \ - opal_list_item_t *it; \ - if (1 == ((opal_object_t*)(list))->obj_reference_count) { \ - while (NULL != (it = opal_list_remove_first(list))) { \ - OBJ_RELEASE(it); \ - } \ - } \ - OBJ_DESTRUCT(list); \ - } while(0); - -#define OPAL_LIST_RELEASE(list) \ - do { \ - opal_list_item_t *it; \ - if (1 == ((opal_object_t*)(list))->obj_reference_count) { \ - while (NULL != (it = opal_list_remove_first(list))) { \ - OBJ_RELEASE(it); \ - } \ - } \ - OBJ_RELEASE(list); \ - } while(0); - +#define OPAL_LIST_DESTRUCT(list) \ + do { \ + opal_list_item_t *it; \ + if (1 == ((opal_object_t *) (list))->obj_reference_count) { \ + while (NULL != (it = opal_list_remove_first(list))) { \ + OBJ_RELEASE(it); \ + } \ + } \ + OBJ_DESTRUCT(list); \ + } while (0); + +#define OPAL_LIST_RELEASE(list) \ + do { \ + opal_list_item_t *it; \ + if (1 == ((opal_object_t *) (list))->obj_reference_count) { \ + while (NULL != (it = opal_list_remove_first(list))) { \ + OBJ_RELEASE(it); \ + } \ + } \ + OBJ_RELEASE(list); \ + } while (0); /** * Loop over a list. @@ -210,15 +204,15 @@ typedef struct opal_list_t opal_list_t; * do something(foo); * } */ -#define OPAL_LIST_FOREACH(item, list, type) \ - for (item = (type *) (list)->opal_list_sentinel.opal_list_next ; \ - item != (type *) &(list)->opal_list_sentinel ; \ - item = (type *) ((opal_list_item_t *) (item))->opal_list_next) +#define OPAL_LIST_FOREACH(item, list, type) \ + for (item = (type *) (list)->opal_list_sentinel.opal_list_next; \ + item != (type *) &(list)->opal_list_sentinel; \ + item = (type *) ((opal_list_item_t *) (item))->opal_list_next) -#define OPAL_LIST_FOREACH_DECL(item, list, type) \ - for (type *item = (type *) (list)->opal_list_sentinel.opal_list_next ; \ - item != (type *) &(list)->opal_list_sentinel ; \ - item = (type *) ((opal_list_item_t *) (item))->opal_list_next) +#define OPAL_LIST_FOREACH_DECL(item, list, type) \ + for (type *item = (type *) (list)->opal_list_sentinel.opal_list_next; \ + item != (type *) &(list)->opal_list_sentinel; \ + item = (type *) ((opal_list_item_t *) (item))->opal_list_next) /** * Loop over a list in reverse. @@ -237,10 +231,10 @@ typedef struct opal_list_t opal_list_t; * do something; * } */ -#define OPAL_LIST_FOREACH_REV(item, list, type) \ - for (item = (type *) (list)->opal_list_sentinel.opal_list_prev ; \ - item != (type *) &(list)->opal_list_sentinel ; \ - item = (type *) ((opal_list_item_t *) (item))->opal_list_prev) +#define OPAL_LIST_FOREACH_REV(item, list, type) \ + for (item = (type *) (list)->opal_list_sentinel.opal_list_prev; \ + item != (type *) &(list)->opal_list_sentinel; \ + item = (type *) ((opal_list_item_t *) (item))->opal_list_prev) /** * Loop over a list in a *safe* way @@ -261,11 +255,11 @@ typedef struct opal_list_t opal_list_t; * opal_list_remove_item (list, (opal_list_item_t *) foo); * } */ -#define OPAL_LIST_FOREACH_SAFE(item, next, list, type) \ - for (item = (type *) (list)->opal_list_sentinel.opal_list_next, \ - next = (type *) ((opal_list_item_t *) (item))->opal_list_next ;\ - item != (type *) &(list)->opal_list_sentinel ; \ - item = next, next = (type *) ((opal_list_item_t *) (item))->opal_list_next) +#define OPAL_LIST_FOREACH_SAFE(item, next, list, type) \ + for (item = (type *) (list)->opal_list_sentinel.opal_list_next, \ + next = (type *) ((opal_list_item_t *) (item))->opal_list_next; \ + item != (type *) &(list)->opal_list_sentinel; \ + item = next, next = (type *) ((opal_list_item_t *) (item))->opal_list_next) /** * Loop over a list in a *safe* way @@ -286,12 +280,11 @@ typedef struct opal_list_t opal_list_t; * opal_list_remove_item (list, (opal_list_item_t *) foo); * } */ -#define OPAL_LIST_FOREACH_SAFE_REV(item, prev, list, type) \ - for (item = (type *) (list)->opal_list_sentinel.opal_list_prev, \ - prev = (type *) ((opal_list_item_t *) (item))->opal_list_prev ;\ - item != (type *) &(list)->opal_list_sentinel ; \ - item = prev, prev = (type *) ((opal_list_item_t *) (item))->opal_list_prev) - +#define OPAL_LIST_FOREACH_SAFE_REV(item, prev, list, type) \ + for (item = (type *) (list)->opal_list_sentinel.opal_list_prev, \ + prev = (type *) ((opal_list_item_t *) (item))->opal_list_prev; \ + item != (type *) &(list)->opal_list_sentinel; \ + item = prev, prev = (type *) ((opal_list_item_t *) (item))->opal_list_prev) /** * Check for empty list @@ -305,13 +298,11 @@ typedef struct opal_list_t opal_list_t; * This is an inlined function in compilers that support inlining, * so it's usually a cheap operation. */ -static inline bool opal_list_is_empty(opal_list_t* list) +static inline bool opal_list_is_empty(opal_list_t *list) { - return (list->opal_list_sentinel.opal_list_next == - &(list->opal_list_sentinel) ? true : false); + return (list->opal_list_sentinel.opal_list_next == &(list->opal_list_sentinel) ? true : false); } - /** * Return the first item on the list (does not remove it). * @@ -326,14 +317,14 @@ static inline bool opal_list_is_empty(opal_list_t* list) * This is an inlined function in compilers that support inlining, so * it's usually a cheap operation. */ -static inline opal_list_item_t* opal_list_get_first(opal_list_t* list) +static inline opal_list_item_t *opal_list_get_first(opal_list_t *list) { - opal_list_item_t* item = (opal_list_item_t*)list->opal_list_sentinel.opal_list_next; + opal_list_item_t *item = (opal_list_item_t *) list->opal_list_sentinel.opal_list_next; #if OPAL_ENABLE_DEBUG /* Spot check: ensure that the first item is only on one list */ assert(1 == item->opal_list_item_refcount); - assert( list == item->opal_list_item_belong_to ); + assert(list == item->opal_list_item_belong_to); #endif return item; @@ -353,14 +344,14 @@ static inline opal_list_item_t* opal_list_get_first(opal_list_t* list) * This is an inlined function in compilers that support inlining, so * it's usually a cheap operation. */ -static inline opal_list_item_t* opal_list_get_last(opal_list_t* list) +static inline opal_list_item_t *opal_list_get_last(opal_list_t *list) { - opal_list_item_t* item = (opal_list_item_t *)list->opal_list_sentinel.opal_list_prev; + opal_list_item_t *item = (opal_list_item_t *) list->opal_list_sentinel.opal_list_prev; #if OPAL_ENABLE_DEBUG /* Spot check: ensure that the last item is only on one list */ - assert( 1 == item->opal_list_item_refcount ); - assert( list == item->opal_list_item_belong_to ); + assert(1 == item->opal_list_item_refcount); + assert(list == item->opal_list_item_belong_to); #endif return item; @@ -383,7 +374,7 @@ static inline opal_list_item_t* opal_list_get_last(opal_list_t* list) * This is an inlined function in compilers that support inlining, so * it's usually a cheap operation. */ -static inline opal_list_item_t* opal_list_get_begin(opal_list_t* list) +static inline opal_list_item_t *opal_list_get_begin(opal_list_t *list) { return &(list->opal_list_sentinel); } @@ -405,12 +396,11 @@ static inline opal_list_item_t* opal_list_get_begin(opal_list_t* list) * This is an inlined function in compilers that support inlining, so * it's usually a cheap operation. */ -static inline opal_list_item_t* opal_list_get_end(opal_list_t* list) +static inline opal_list_item_t *opal_list_get_end(opal_list_t *list) { return &(list->opal_list_sentinel); } - /** * Return the number of items in a list * @@ -430,7 +420,7 @@ static inline opal_list_item_t* opal_list_get_end(opal_list_t* list) * never called on the specified list, this function will always be * O(1). */ -static inline size_t opal_list_get_size(opal_list_t* list) +static inline size_t opal_list_get_size(opal_list_t *list) { #if OPAL_ENABLE_DEBUG && 0 /* not sure if we really want this running in devel, as it does @@ -440,14 +430,15 @@ static inline size_t opal_list_get_size(opal_list_t* list) size_t check_len = 0; opal_list_item_t *item; - for (item = opal_list_get_first(list) ; - item != opal_list_get_end(list) ; + for (item = opal_list_get_first(list); item != opal_list_get_end(list); item = opal_list_get_next(item)) { check_len++; } if (check_len != list->opal_list_length) { - fprintf(stderr," Error :: opal_list_get_size - opal_list_length does not match actual list length\n"); + fprintf( + stderr, + " Error :: opal_list_get_size - opal_list_length does not match actual list length\n"); fflush(stderr); abort(); } @@ -456,7 +447,6 @@ static inline size_t opal_list_get_size(opal_list_t* list) return list->opal_list_length; } - /** * Remove an item from a list. * @@ -478,51 +468,49 @@ static inline size_t opal_list_get_size(opal_list_t* list) * This is an inlined function in compilers that support inlining, so * it's usually a cheap operation. */ -static inline opal_list_item_t *opal_list_remove_item - (opal_list_t *list, opal_list_item_t *item) +static inline opal_list_item_t *opal_list_remove_item(opal_list_t *list, opal_list_item_t *item) { #if OPAL_ENABLE_DEBUG opal_list_item_t *item_ptr; bool found = false; /* check to see that the item is in the list */ - for (item_ptr = opal_list_get_first(list); - item_ptr != opal_list_get_end(list); - item_ptr = (opal_list_item_t *)(item_ptr->opal_list_next)) { + for (item_ptr = opal_list_get_first(list); item_ptr != opal_list_get_end(list); + item_ptr = (opal_list_item_t *) (item_ptr->opal_list_next)) { if (item_ptr == (opal_list_item_t *) item) { found = true; break; } } if (!found) { - fprintf(stderr," Warning :: opal_list_remove_item - the item %p is not on the list %p \n",(void*) item, (void*) list); + fprintf(stderr, " Warning :: opal_list_remove_item - the item %p is not on the list %p \n", + (void *) item, (void *) list); fflush(stderr); - return (opal_list_item_t *)NULL; + return (opal_list_item_t *) NULL; } - assert( list == item->opal_list_item_belong_to ); + assert(list == item->opal_list_item_belong_to); #endif /* reset next pointer of previous element */ - item->opal_list_prev->opal_list_next=item->opal_list_next; + item->opal_list_prev->opal_list_next = item->opal_list_next; /* reset previous pointer of next element */ - item->opal_list_next->opal_list_prev=item->opal_list_prev; + item->opal_list_next->opal_list_prev = item->opal_list_prev; list->opal_list_length--; #if OPAL_ENABLE_DEBUG /* Spot check: ensure that this item is still only on one list */ - OPAL_THREAD_ADD_FETCH32( &(item->opal_list_item_refcount), -1 ); + OPAL_THREAD_ADD_FETCH32(&(item->opal_list_item_refcount), -1); assert(0 == item->opal_list_item_refcount); item->opal_list_item_belong_to = NULL; #endif - return (opal_list_item_t *)item->opal_list_prev; + return (opal_list_item_t *) item->opal_list_prev; } - /** * Append an item to the end of the list. * @@ -538,55 +526,53 @@ static inline opal_list_item_t *opal_list_remove_item */ #if OPAL_ENABLE_DEBUG -#define opal_list_append(l,i) \ -_opal_list_append(l,i,__FILE__,__LINE__) +# define opal_list_append(l, i) _opal_list_append(l, i, __FILE__, __LINE__) #else -#define opal_list_append(l,i) \ -_opal_list_append(l,i) -#endif /* OPAL_ENABLE_DEBUG */ +# define opal_list_append(l, i) _opal_list_append(l, i) +#endif /* OPAL_ENABLE_DEBUG */ static inline void _opal_list_append(opal_list_t *list, opal_list_item_t *item #if OPAL_ENABLE_DEBUG - , const char* FILE_NAME, int LINENO -#endif /* OPAL_ENABLE_DEBUG */ - ) + , + const char *FILE_NAME, int LINENO +#endif /* OPAL_ENABLE_DEBUG */ +) { - opal_list_item_t* sentinel = &(list->opal_list_sentinel); + opal_list_item_t *sentinel = &(list->opal_list_sentinel); #if OPAL_ENABLE_DEBUG - /* Spot check: ensure that this item is previously on no lists */ + /* Spot check: ensure that this item is previously on no lists */ - assert(0 == item->opal_list_item_refcount); - assert( NULL == item->opal_list_item_belong_to ); - item->super.cls_init_file_name = FILE_NAME; - item->super.cls_init_lineno = LINENO; + assert(0 == item->opal_list_item_refcount); + assert(NULL == item->opal_list_item_belong_to); + item->super.cls_init_file_name = FILE_NAME; + item->super.cls_init_lineno = LINENO; #endif - /* set new element's previous pointer */ - item->opal_list_prev = sentinel->opal_list_prev; + /* set new element's previous pointer */ + item->opal_list_prev = sentinel->opal_list_prev; - /* reset previous pointer on current last element */ - sentinel->opal_list_prev->opal_list_next = item; + /* reset previous pointer on current last element */ + sentinel->opal_list_prev->opal_list_next = item; - /* reset new element's next pointer */ - item->opal_list_next = sentinel; + /* reset new element's next pointer */ + item->opal_list_next = sentinel; - /* reset the list's tail element previous pointer */ - sentinel->opal_list_prev = item; + /* reset the list's tail element previous pointer */ + sentinel->opal_list_prev = item; - /* increment list element counter */ - list->opal_list_length++; + /* increment list element counter */ + list->opal_list_length++; #if OPAL_ENABLE_DEBUG - /* Spot check: ensure this item is only on the list that we just - appended it to */ + /* Spot check: ensure this item is only on the list that we just + appended it to */ - OPAL_THREAD_ADD_FETCH32( &(item->opal_list_item_refcount), 1 ); - assert(1 == item->opal_list_item_refcount); - item->opal_list_item_belong_to = list; + OPAL_THREAD_ADD_FETCH32(&(item->opal_list_item_refcount), 1); + assert(1 == item->opal_list_item_refcount); + item->opal_list_item_belong_to = list; #endif } - /** * Prepend an item to the beginning of the list. * @@ -600,43 +586,41 @@ static inline void _opal_list_append(opal_list_t *list, opal_list_item_t *item * This is an inlined function in compilers that support inlining, so * it's usually a cheap operation. */ -static inline void opal_list_prepend(opal_list_t *list, - opal_list_item_t *item) +static inline void opal_list_prepend(opal_list_t *list, opal_list_item_t *item) { - opal_list_item_t* sentinel = &(list->opal_list_sentinel); + opal_list_item_t *sentinel = &(list->opal_list_sentinel); #if OPAL_ENABLE_DEBUG - /* Spot check: ensure that this item is previously on no lists */ + /* Spot check: ensure that this item is previously on no lists */ - assert(0 == item->opal_list_item_refcount); - assert( NULL == item->opal_list_item_belong_to ); + assert(0 == item->opal_list_item_refcount); + assert(NULL == item->opal_list_item_belong_to); #endif - /* reset item's next pointer */ - item->opal_list_next = sentinel->opal_list_next; + /* reset item's next pointer */ + item->opal_list_next = sentinel->opal_list_next; - /* reset item's previous pointer */ - item->opal_list_prev = sentinel; + /* reset item's previous pointer */ + item->opal_list_prev = sentinel; - /* reset previous first element's previous poiner */ - sentinel->opal_list_next->opal_list_prev = item; + /* reset previous first element's previous poiner */ + sentinel->opal_list_next->opal_list_prev = item; - /* reset head's next pointer */ - sentinel->opal_list_next = item; + /* reset head's next pointer */ + sentinel->opal_list_next = item; - /* increment list element counter */ - list->opal_list_length++; + /* increment list element counter */ + list->opal_list_length++; #if OPAL_ENABLE_DEBUG - /* Spot check: ensure this item is only on the list that we just - prepended it to */ + /* Spot check: ensure this item is only on the list that we just + prepended it to */ - OPAL_THREAD_ADD_FETCH32( &(item->opal_list_item_refcount), 1 ); - assert(1 == item->opal_list_item_refcount); - item->opal_list_item_belong_to = list; + OPAL_THREAD_ADD_FETCH32(&(item->opal_list_item_refcount), 1); + assert(1 == item->opal_list_item_refcount); + item->opal_list_item_belong_to = list; #endif } - /** * Remove the first item from the list and return it. * @@ -655,50 +639,49 @@ static inline void opal_list_prepend(opal_list_t *list, */ static inline opal_list_item_t *opal_list_remove_first(opal_list_t *list) { - /* Removes and returns first item on list. - Caller now owns the item and should release the item - when caller is done with it. - */ - opal_list_item_t *item; - if ( 0 == list->opal_list_length ) { - return (opal_list_item_t *)NULL; - } + /* Removes and returns first item on list. + Caller now owns the item and should release the item + when caller is done with it. + */ + opal_list_item_t *item; + if (0 == list->opal_list_length) { + return (opal_list_item_t *) NULL; + } #if OPAL_ENABLE_DEBUG - /* Spot check: ensure that the first item is only on this list */ + /* Spot check: ensure that the first item is only on this list */ - assert(1 == list->opal_list_sentinel.opal_list_next->opal_list_item_refcount); + assert(1 == list->opal_list_sentinel.opal_list_next->opal_list_item_refcount); #endif - /* reset list length counter */ - list->opal_list_length--; + /* reset list length counter */ + list->opal_list_length--; - /* get pointer to first element on the list */ - item = (opal_list_item_t *) list->opal_list_sentinel.opal_list_next; + /* get pointer to first element on the list */ + item = (opal_list_item_t *) list->opal_list_sentinel.opal_list_next; - /* reset previous pointer of next item on the list */ - item->opal_list_next->opal_list_prev = item->opal_list_prev; + /* reset previous pointer of next item on the list */ + item->opal_list_next->opal_list_prev = item->opal_list_prev; - /* reset the head next pointer */ - list->opal_list_sentinel.opal_list_next = item->opal_list_next; + /* reset the head next pointer */ + list->opal_list_sentinel.opal_list_next = item->opal_list_next; #if OPAL_ENABLE_DEBUG - assert( list == item->opal_list_item_belong_to ); - item->opal_list_item_belong_to = NULL; - item->opal_list_prev=(opal_list_item_t *)NULL; - item->opal_list_next=(opal_list_item_t *)NULL; + assert(list == item->opal_list_item_belong_to); + item->opal_list_item_belong_to = NULL; + item->opal_list_prev = (opal_list_item_t *) NULL; + item->opal_list_next = (opal_list_item_t *) NULL; - /* Spot check: ensure that the item we're returning is now on no - lists */ + /* Spot check: ensure that the item we're returning is now on no + lists */ - OPAL_THREAD_ADD_FETCH32( &item->opal_list_item_refcount, -1 ); - assert(0 == item->opal_list_item_refcount); + OPAL_THREAD_ADD_FETCH32(&item->opal_list_item_refcount, -1); + assert(0 == item->opal_list_item_refcount); #endif - return item; + return item; } - /** * Remove the last item from the list and return it. * @@ -717,57 +700,57 @@ static inline opal_list_item_t *opal_list_remove_first(opal_list_t *list) */ static inline opal_list_item_t *opal_list_remove_last(opal_list_t *list) { - /* Removes, releases and returns last item on list. - Caller now owns the item and should release the item - when caller is done with it. - */ - opal_list_item_t *item; - if ( 0 == list->opal_list_length ) { - return (opal_list_item_t *)NULL; - } + /* Removes, releases and returns last item on list. + Caller now owns the item and should release the item + when caller is done with it. + */ + opal_list_item_t *item; + if (0 == list->opal_list_length) { + return (opal_list_item_t *) NULL; + } #if OPAL_ENABLE_DEBUG - /* Spot check: ensure that the first item is only on this list */ + /* Spot check: ensure that the first item is only on this list */ - assert(1 == list->opal_list_sentinel.opal_list_prev->opal_list_item_refcount); + assert(1 == list->opal_list_sentinel.opal_list_prev->opal_list_item_refcount); #endif - /* reset list length counter */ - list->opal_list_length--; + /* reset list length counter */ + list->opal_list_length--; - /* get item */ - item = (opal_list_item_t *) list->opal_list_sentinel.opal_list_prev; + /* get item */ + item = (opal_list_item_t *) list->opal_list_sentinel.opal_list_prev; - /* reset previous pointer on next to last pointer */ - item->opal_list_prev->opal_list_next = item->opal_list_next; + /* reset previous pointer on next to last pointer */ + item->opal_list_prev->opal_list_next = item->opal_list_next; - /* reset tail's previous pointer */ - list->opal_list_sentinel.opal_list_prev = item->opal_list_prev; + /* reset tail's previous pointer */ + list->opal_list_sentinel.opal_list_prev = item->opal_list_prev; #if OPAL_ENABLE_DEBUG - assert( list == item->opal_list_item_belong_to ); - item->opal_list_next = item->opal_list_prev = (opal_list_item_t *)NULL; + assert(list == item->opal_list_item_belong_to); + item->opal_list_next = item->opal_list_prev = (opal_list_item_t *) NULL; - /* Spot check: ensure that the item we're returning is now on no - lists */ + /* Spot check: ensure that the item we're returning is now on no + lists */ - OPAL_THREAD_ADD_FETCH32(&item->opal_list_item_refcount, -1 ); - assert(0 == item->opal_list_item_refcount); - item->opal_list_item_belong_to = NULL; + OPAL_THREAD_ADD_FETCH32(&item->opal_list_item_refcount, -1); + assert(0 == item->opal_list_item_refcount); + item->opal_list_item_belong_to = NULL; #endif - return item; + return item; } - /** - * Add an item to the list before a given element - * - * @param list The list container - * @param pos List element to insert \c item before - * @param item The item to insert - * - * Inserts \c item before \c pos. This is an O(1) operation. - */ +/** + * Add an item to the list before a given element + * + * @param list The list container + * @param pos List element to insert \c item before + * @param item The item to insert + * + * Inserts \c item before \c pos. This is an O(1) operation. + */ static inline void opal_list_insert_pos(opal_list_t *list, opal_list_item_t *pos, opal_list_item_t *item) { @@ -776,7 +759,7 @@ static inline void opal_list_insert_pos(opal_list_t *list, opal_list_item_t *pos not on any list */ assert(0 == item->opal_list_item_refcount); - assert( NULL == item->opal_list_item_belong_to ); + assert(NULL == item->opal_list_item_belong_to); #endif /* point item at the existing elements */ @@ -794,126 +777,121 @@ static inline void opal_list_insert_pos(opal_list_t *list, opal_list_item_t *pos /* Spot check: double check that this item is only on the list that we just added it to */ - OPAL_THREAD_ADD_FETCH32( &(item->opal_list_item_refcount), 1 ); + OPAL_THREAD_ADD_FETCH32(&(item->opal_list_item_refcount), 1); assert(1 == item->opal_list_item_refcount); item->opal_list_item_belong_to = list; #endif } - /** - * Add an item to the list at a specific index location in the list. - * - * @param list The list container - * @param item The item to insert - * @param index Location to add the item - * - * @returns true if insertion succeeded; otherwise false - * - * This is potentially an O(N) operation to traverse down to the - * correct location in the list and add an item. - * - * Example: if idx = 2 and list = item1->item2->item3->item4, then - * after insert, list = item1->item2->item->item3->item4. - * - * If index is greater than the length of the list, no action is - * performed and false is returned. - */ - OPAL_DECLSPEC bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, - long long idx); - - - /** - * Join a list into another list - * - * @param thislist List container for list being operated on - * @param pos List item in \c thislist marking the position before - * which items are inserted - * @param xlist List container for list being spliced from - * - * Join a list into another list. All of the elements of \c xlist - * are inserted before \c pos and removed from \c xlist. - * - * This operation is an O(1) operation. Both \c thislist and \c - * xlist must be valid list containsers. \c xlist will be empty - * but valid after the call. All pointers to \c opal_list_item_t - * containers remain valid, including those that point to elements - * in \c xlist. - */ - OPAL_DECLSPEC void opal_list_join(opal_list_t *thislist, opal_list_item_t *pos, - opal_list_t *xlist); - - - /** - * Splice a list into another list - * - * @param thislist List container for list being operated on - * @param pos List item in \c thislist marking the position before - * which items are inserted - * @param xlist List container for list being spliced from - * @param first List item in \c xlist marking the start of elements - * to be copied into \c thislist - * @param last List item in \c xlist marking the end of elements - * to be copied into \c thislist - * - * Splice a subset of a list into another list. The \c [first, - * last) elements of \c xlist are moved into \c thislist, - * inserting them before \c pos. \c pos must be a valid iterator - * in \c thislist and \c [first, last) must be a valid range in \c - * xlist. \c postition must not be in the range \c [first, last). - * It is, however, valid for \c xlist and \c thislist to be the - * same list. - * - * This is an O(N) operation because the length of both lists must - * be recomputed. - */ - OPAL_DECLSPEC void opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos, - opal_list_t *xlist, opal_list_item_t *first, - opal_list_item_t *last); - - /** - * Comparison function for opal_list_sort(), below. - * - * @param a Pointer to a pointer to an opal_list_item_t. - * Explanation below. - * @param b Pointer to a pointer to an opal_list_item_t. - * Explanation below. - * @retval 1 if \em a is greater than \em b - * @retval 0 if \em a is equal to \em b - * @retval -1 if \em a is less than \em b - * - * This function is invoked by qsort(3) from within - * opal_list_sort(). It is important to understand what - * opal_list_sort() does before invoking qsort, so go read that - * documentation first. - * - * The important thing to realize here is that a and b will be \em - * double pointers to the items that you need to compare. Here's - * a sample compare function to illustrate this point: - */ - typedef int (*opal_list_item_compare_fn_t)(opal_list_item_t **a, - opal_list_item_t **b); - - /** - * Sort a list with a provided compare function. - * - * @param list The list to sort - * @param compare Compare function - * - * Put crassly, this function's complexity is O(N) + O(log(N)). - * Its algorithm is: - * - * - remove every item from the list and put the corresponding - * (opal_list_item_t*)'s in an array - * - call qsort(3) with that array and your compare function - * - re-add every element of the now-sorted array to the list - * - * The resulting list is now ordered. Note, however, that since - * an array of pointers is sorted, the comparison function must do - * a double de-reference to get to the actual opal_list_item_t (or - * whatever the underlying type is). See the documentation of - * opal_list_item_compare_fn_t for an example). - */ - OPAL_DECLSPEC int opal_list_sort(opal_list_t* list, opal_list_item_compare_fn_t compare); +/** + * Add an item to the list at a specific index location in the list. + * + * @param list The list container + * @param item The item to insert + * @param index Location to add the item + * + * @returns true if insertion succeeded; otherwise false + * + * This is potentially an O(N) operation to traverse down to the + * correct location in the list and add an item. + * + * Example: if idx = 2 and list = item1->item2->item3->item4, then + * after insert, list = item1->item2->item->item3->item4. + * + * If index is greater than the length of the list, no action is + * performed and false is returned. + */ +OPAL_DECLSPEC bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx); + +/** + * Join a list into another list + * + * @param thislist List container for list being operated on + * @param pos List item in \c thislist marking the position before + * which items are inserted + * @param xlist List container for list being spliced from + * + * Join a list into another list. All of the elements of \c xlist + * are inserted before \c pos and removed from \c xlist. + * + * This operation is an O(1) operation. Both \c thislist and \c + * xlist must be valid list containsers. \c xlist will be empty + * but valid after the call. All pointers to \c opal_list_item_t + * containers remain valid, including those that point to elements + * in \c xlist. + */ +OPAL_DECLSPEC void opal_list_join(opal_list_t *thislist, opal_list_item_t *pos, opal_list_t *xlist); + +/** + * Splice a list into another list + * + * @param thislist List container for list being operated on + * @param pos List item in \c thislist marking the position before + * which items are inserted + * @param xlist List container for list being spliced from + * @param first List item in \c xlist marking the start of elements + * to be copied into \c thislist + * @param last List item in \c xlist marking the end of elements + * to be copied into \c thislist + * + * Splice a subset of a list into another list. The \c [first, + * last) elements of \c xlist are moved into \c thislist, + * inserting them before \c pos. \c pos must be a valid iterator + * in \c thislist and \c [first, last) must be a valid range in \c + * xlist. \c postition must not be in the range \c [first, last). + * It is, however, valid for \c xlist and \c thislist to be the + * same list. + * + * This is an O(N) operation because the length of both lists must + * be recomputed. + */ +OPAL_DECLSPEC void opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos, + opal_list_t *xlist, opal_list_item_t *first, + opal_list_item_t *last); + +/** + * Comparison function for opal_list_sort(), below. + * + * @param a Pointer to a pointer to an opal_list_item_t. + * Explanation below. + * @param b Pointer to a pointer to an opal_list_item_t. + * Explanation below. + * @retval 1 if \em a is greater than \em b + * @retval 0 if \em a is equal to \em b + * @retval -1 if \em a is less than \em b + * + * This function is invoked by qsort(3) from within + * opal_list_sort(). It is important to understand what + * opal_list_sort() does before invoking qsort, so go read that + * documentation first. + * + * The important thing to realize here is that a and b will be \em + * double pointers to the items that you need to compare. Here's + * a sample compare function to illustrate this point: + */ +typedef int (*opal_list_item_compare_fn_t)(opal_list_item_t **a, opal_list_item_t **b); + +/** + * Sort a list with a provided compare function. + * + * @param list The list to sort + * @param compare Compare function + * + * Put crassly, this function's complexity is O(N) + O(log(N)). + * Its algorithm is: + * + * - remove every item from the list and put the corresponding + * (opal_list_item_t*)'s in an array + * - call qsort(3) with that array and your compare function + * - re-add every element of the now-sorted array to the list + * + * The resulting list is now ordered. Note, however, that since + * an array of pointers is sorted, the comparison function must do + * a double de-reference to get to the actual opal_list_item_t (or + * whatever the underlying type is). See the documentation of + * opal_list_item_compare_fn_t for an example). + */ +OPAL_DECLSPEC int opal_list_sort(opal_list_t *list, opal_list_item_compare_fn_t compare); END_C_DECLS diff --git a/opal/class/opal_object.c b/opal/class/opal_object.c index 64fef5712fc..c7127d1f587 100644 --- a/opal/class/opal_object.c +++ b/opal/class/opal_object.c @@ -29,9 +29,9 @@ #include -#include "opal/sys/atomic.h" #include "opal/class/opal_object.h" #include "opal/constants.h" +#include "opal/sys/atomic.h" /* * Instantiation of class descriptor for the base class. This is @@ -56,27 +56,25 @@ int opal_class_init_epoch = 1; * Local variables */ static opal_atomic_lock_t class_lock = OPAL_ATOMIC_LOCK_INIT; -static void** classes = NULL; +static void **classes = NULL; static int num_classes = 0; static int max_classes = 0; static const int increment = 10; - /* * Local functions */ static void save_class(opal_class_t *cls); static void expand_array(void); - /* * Lazy initialization of class descriptor. */ void opal_class_initialize(opal_class_t *cls) { opal_class_t *c; - opal_construct_t* cls_construct_array; - opal_destruct_t* cls_destruct_array; + opal_construct_t *cls_construct_array; + opal_destruct_t *cls_destruct_array; int cls_construct_array_count; int cls_destruct_array_count; int i; @@ -107,12 +105,12 @@ void opal_class_initialize(opal_class_t *cls) cls->cls_depth = 0; cls_construct_array_count = 0; - cls_destruct_array_count = 0; + cls_destruct_array_count = 0; for (c = cls; c; c = c->cls_parent) { - if( NULL != c->cls_construct ) { + if (NULL != c->cls_construct) { cls_construct_array_count++; } - if( NULL != c->cls_destruct ) { + if (NULL != c->cls_destruct) { cls_destruct_array_count++; } cls->cls_depth++; @@ -123,38 +121,35 @@ void opal_class_initialize(opal_class_t *cls) * plus for each a NULL-sentinel */ - cls->cls_construct_array = - (void (**)(opal_object_t*))malloc((cls_construct_array_count + - cls_destruct_array_count + 2) * - sizeof(opal_construct_t) ); + cls->cls_construct_array = (void (**)(opal_object_t *)) malloc( + (cls_construct_array_count + cls_destruct_array_count + 2) * sizeof(opal_construct_t)); if (NULL == cls->cls_construct_array) { perror("Out of memory"); exit(-1); } - cls->cls_destruct_array = - cls->cls_construct_array + cls_construct_array_count + 1; + cls->cls_destruct_array = cls->cls_construct_array + cls_construct_array_count + 1; /* * The constructor array is reversed, so start at the end */ cls_construct_array = cls->cls_construct_array + cls_construct_array_count; - cls_destruct_array = cls->cls_destruct_array; + cls_destruct_array = cls->cls_destruct_array; c = cls; - *cls_construct_array = NULL; /* end marker for the constructors */ + *cls_construct_array = NULL; /* end marker for the constructors */ for (i = 0; i < cls->cls_depth; i++) { - if( NULL != c->cls_construct ) { + if (NULL != c->cls_construct) { --cls_construct_array; *cls_construct_array = c->cls_construct; } - if( NULL != c->cls_destruct ) { + if (NULL != c->cls_destruct) { *cls_destruct_array = c->cls_destruct; cls_destruct_array++; } c = c->cls_parent; } - *cls_destruct_array = NULL; /* end marker for the destructors */ + *cls_destruct_array = NULL; /* end marker for the destructors */ cls->cls_initialized = opal_class_init_epoch; save_class(cls); @@ -164,7 +159,6 @@ void opal_class_initialize(opal_class_t *cls) opal_atomic_unlock(&class_lock); } - /* * Note that this is finalize for *all* classes. */ @@ -193,7 +187,6 @@ int opal_class_finalize(void) return OPAL_SUCCESS; } - static void save_class(opal_class_t *cls) { if (num_classes >= max_classes) { @@ -204,13 +197,12 @@ static void save_class(opal_class_t *cls) ++num_classes; } - static void expand_array(void) { int i; max_classes += increment; - classes = (void**)realloc(classes, sizeof(opal_class_t*) * max_classes); + classes = (void **) realloc(classes, sizeof(opal_class_t *) * max_classes); if (NULL == classes) { perror("class malloc failed"); exit(-1); @@ -219,4 +211,3 @@ static void expand_array(void) classes[i] = NULL; } } - diff --git a/opal/class/opal_object.h b/opal/class/opal_object.h index 2a2f1edbbe3..6b60726f1c3 100644 --- a/opal/class/opal_object.h +++ b/opal/class/opal_object.h @@ -129,16 +129,15 @@ BEGIN_C_DECLS #if OPAL_ENABLE_DEBUG /* Any kind of unique ID should do the job */ -#define OPAL_OBJ_MAGIC_ID ((0xdeafbeedULL << 32) + 0xdeafbeedULL) +# define OPAL_OBJ_MAGIC_ID ((0xdeafbeedULL << 32) + 0xdeafbeedULL) #endif /* typedefs ***********************************************************/ typedef struct opal_object_t opal_object_t; typedef struct opal_class_t opal_class_t; -typedef void (*opal_construct_t) (opal_object_t *); -typedef void (*opal_destruct_t) (opal_object_t *); - +typedef void (*opal_construct_t)(opal_object_t *); +typedef void (*opal_destruct_t)(opal_object_t *); /* types **************************************************************/ @@ -156,10 +155,10 @@ struct opal_class_t { int cls_initialized; /**< is class initialized */ int cls_depth; /**< depth of class hierarchy tree */ opal_construct_t *cls_construct_array; - /**< array of parent class constructors */ + /**< array of parent class constructors */ opal_destruct_t *cls_destruct_array; - /**< array of parent class destructors */ - size_t cls_sizeof; /**< size of an object instance */ + /**< array of parent class destructors */ + size_t cls_sizeof; /**< size of an object instance */ }; extern int opal_class_init_epoch; @@ -170,20 +169,16 @@ extern int opal_class_init_epoch; * @param NAME Name of the class to initialize */ #if OPAL_ENABLE_DEBUG -#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) \ - { \ - .obj_magic_id = OPAL_OBJ_MAGIC_ID, \ - .obj_class = OBJ_CLASS(BASE_CLASS), \ - .obj_reference_count = 1, \ - .cls_init_file_name = __FILE__, \ - .cls_init_lineno = __LINE__, \ - } +# define OPAL_OBJ_STATIC_INIT(BASE_CLASS) \ + { \ + .obj_magic_id = OPAL_OBJ_MAGIC_ID, .obj_class = OBJ_CLASS(BASE_CLASS), \ + .obj_reference_count = 1, .cls_init_file_name = __FILE__, .cls_init_lineno = __LINE__, \ + } #else -#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) \ - { \ - .obj_class = OBJ_CLASS(BASE_CLASS), \ - .obj_reference_count = 1, \ - } +# define OPAL_OBJ_STATIC_INIT(BASE_CLASS) \ + { \ + .obj_class = OBJ_CLASS(BASE_CLASS), .obj_reference_count = 1, \ + } #endif /** @@ -197,12 +192,13 @@ struct opal_object_t { struct's memory */ uint64_t obj_magic_id; #endif - opal_class_t *obj_class; /**< class descriptor */ - opal_atomic_int32_t obj_reference_count; /**< reference count */ + opal_class_t *obj_class; /**< class descriptor */ + opal_atomic_int32_t obj_reference_count; /**< reference count */ #if OPAL_ENABLE_DEBUG - const char* cls_init_file_name; /**< In debug mode store the file where the object get contructed */ - int cls_init_lineno; /**< In debug mode store the line number where the object get contructed */ -#endif /* OPAL_ENABLE_DEBUG */ + const char + *cls_init_file_name; /**< In debug mode store the file where the object get contructed */ + int cls_init_lineno; /**< In debug mode store the line number where the object get contructed */ +#endif /* OPAL_ENABLE_DEBUG */ }; /* macros ************************************************************/ @@ -214,8 +210,7 @@ struct opal_object_t { * @param NAME Name of class * @return Pointer to class descriptor */ -#define OBJ_CLASS(NAME) (&(NAME ## _class)) - +#define OBJ_CLASS(NAME) (&(NAME##_class)) /** * Static initializer for a class descriptor @@ -227,16 +222,16 @@ struct opal_object_t { * * Put this in NAME.c */ -#define OBJ_CLASS_INSTANCE(NAME, PARENT, CONSTRUCTOR, DESTRUCTOR) \ - opal_class_t NAME ## _class = { \ - # NAME, \ - OBJ_CLASS(PARENT), \ - (opal_construct_t) CONSTRUCTOR, \ - (opal_destruct_t) DESTRUCTOR, \ - 0, 0, NULL, NULL, \ - sizeof(NAME) \ - } - +#define OBJ_CLASS_INSTANCE(NAME, PARENT, CONSTRUCTOR, DESTRUCTOR) \ + opal_class_t NAME##_class = {#NAME, \ + OBJ_CLASS(PARENT), \ + (opal_construct_t) CONSTRUCTOR, \ + (opal_destruct_t) DESTRUCTOR, \ + 0, \ + 0, \ + NULL, \ + NULL, \ + sizeof(NAME)} /** * Declaration for class descriptor @@ -245,9 +240,7 @@ struct opal_object_t { * * Put this in NAME.h */ -#define OBJ_CLASS_DECLARATION(NAME) \ - extern opal_class_t NAME ## _class - +#define OBJ_CLASS_DECLARATION(NAME) extern opal_class_t NAME##_class /** * Create an object: dynamically allocate storage and run the class @@ -256,22 +249,20 @@ struct opal_object_t { * @param type Type (class) of the object * @return Pointer to the object */ -static inline opal_object_t *opal_obj_new(opal_class_t * cls); +static inline opal_object_t *opal_obj_new(opal_class_t *cls); #if OPAL_ENABLE_DEBUG -static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* file, int line) +static inline opal_object_t *opal_obj_new_debug(opal_class_t *type, const char *file, int line) { - opal_object_t* object = opal_obj_new(type); + opal_object_t *object = opal_obj_new(type); object->obj_magic_id = OPAL_OBJ_MAGIC_ID; object->cls_init_file_name = file; object->cls_init_lineno = line; return object; } -#define OBJ_NEW(type) \ - ((type *)opal_obj_new_debug(OBJ_CLASS(type), __FILE__, __LINE__)) +# define OBJ_NEW(type) ((type *) opal_obj_new_debug(OBJ_CLASS(type), __FILE__, __LINE__)) #else -#define OBJ_NEW(type) \ - ((type *) opal_obj_new(OBJ_CLASS(type))) -#endif /* OPAL_ENABLE_DEBUG */ +# define OBJ_NEW(type) ((type *) opal_obj_new(OBJ_CLASS(type))) +#endif /* OPAL_ENABLE_DEBUG */ /** * Retain an object (by incrementing its reference count) @@ -279,15 +270,15 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* * @param object Pointer to the object */ #if OPAL_ENABLE_DEBUG -#define OBJ_RETAIN(object) \ - do { \ - assert(NULL != ((opal_object_t *) (object))->obj_class); \ - assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ - opal_obj_update((opal_object_t *) (object), 1); \ - assert(((opal_object_t *) (object))->obj_reference_count >= 0); \ - } while (0) +# define OBJ_RETAIN(object) \ + do { \ + assert(NULL != ((opal_object_t *) (object))->obj_class); \ + assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ + opal_obj_update((opal_object_t *) (object), 1); \ + assert(((opal_object_t *) (object))->obj_reference_count >= 0); \ + } while (0) #else -#define OBJ_RETAIN(object) opal_obj_update((opal_object_t *) (object), 1); +# define OBJ_RETAIN(object) opal_obj_update((opal_object_t *) (object), 1); #endif /** @@ -295,19 +286,19 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* * an object change. */ #if OPAL_ENABLE_DEBUG -#define OBJ_REMEMBER_FILE_AND_LINENO( OBJECT, FILE, LINENO ) \ - do { \ - ((opal_object_t*)(OBJECT))->cls_init_file_name = FILE; \ - ((opal_object_t*)(OBJECT))->cls_init_lineno = LINENO; \ - } while(0) -#define OBJ_SET_MAGIC_ID( OBJECT, VALUE ) \ - do { \ - ((opal_object_t*)(OBJECT))->obj_magic_id = (VALUE); \ - } while(0) +# define OBJ_REMEMBER_FILE_AND_LINENO(OBJECT, FILE, LINENO) \ + do { \ + ((opal_object_t *) (OBJECT))->cls_init_file_name = FILE; \ + ((opal_object_t *) (OBJECT))->cls_init_lineno = LINENO; \ + } while (0) +# define OBJ_SET_MAGIC_ID(OBJECT, VALUE) \ + do { \ + ((opal_object_t *) (OBJECT))->obj_magic_id = (VALUE); \ + } while (0) #else -#define OBJ_REMEMBER_FILE_AND_LINENO( OBJECT, FILE, LINENO ) -#define OBJ_SET_MAGIC_ID( OBJECT, VALUE ) -#endif /* OPAL_ENABLE_DEBUG */ +# define OBJ_REMEMBER_FILE_AND_LINENO(OBJECT, FILE, LINENO) +# define OBJ_SET_MAGIC_ID(OBJECT, VALUE) +#endif /* OPAL_ENABLE_DEBUG */ /** * Release an object (by decrementing its reference count). If the @@ -322,49 +313,49 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* * */ #if OPAL_ENABLE_DEBUG -#define OBJ_RELEASE(object) \ - do { \ - assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ - assert(NULL != ((opal_object_t *) (object))->obj_class); \ - if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ - OBJ_SET_MAGIC_ID((object), 0); \ - opal_obj_run_destructors((opal_object_t *) (object)); \ - OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ - free((void *) object); \ - object = NULL; \ - } \ - } while (0) +# define OBJ_RELEASE(object) \ + do { \ + assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ + assert(NULL != ((opal_object_t *) (object))->obj_class); \ + if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ + OBJ_SET_MAGIC_ID((object), 0); \ + opal_obj_run_destructors((opal_object_t *) (object)); \ + OBJ_REMEMBER_FILE_AND_LINENO(object, __FILE__, __LINE__); \ + free((void *) object); \ + object = NULL; \ + } \ + } while (0) #else -#define OBJ_RELEASE(object) \ - do { \ - if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ - opal_obj_run_destructors((opal_object_t *) (object)); \ - free((void *) object); \ - object = NULL; \ - } \ - } while (0) +# define OBJ_RELEASE(object) \ + do { \ + if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ + opal_obj_run_destructors((opal_object_t *) (object)); \ + free((void *) object); \ + object = NULL; \ + } \ + } while (0) #endif #if OPAL_ENABLE_DEBUG -#define OBJ_RELEASE_NO_NULLIFY(object) \ - do { \ - assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ - assert(NULL != ((opal_object_t *) (object))->obj_class); \ - if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ - OBJ_SET_MAGIC_ID((object), 0); \ - opal_obj_run_destructors((opal_object_t *) (object)); \ - OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ - free((void *) object); \ - } \ - } while (0) +# define OBJ_RELEASE_NO_NULLIFY(object) \ + do { \ + assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ + assert(NULL != ((opal_object_t *) (object))->obj_class); \ + if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ + OBJ_SET_MAGIC_ID((object), 0); \ + opal_obj_run_destructors((opal_object_t *) (object)); \ + OBJ_REMEMBER_FILE_AND_LINENO(object, __FILE__, __LINE__); \ + free((void *) object); \ + } \ + } while (0) #else -#define OBJ_RELEASE_NO_NULLIFY(object) \ - do { \ - if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ - opal_obj_run_destructors((opal_object_t *) (object)); \ - free((void *) object); \ - } \ - } while (0) +# define OBJ_RELEASE_NO_NULLIFY(object) \ + do { \ + if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ + opal_obj_run_destructors((opal_object_t *) (object)); \ + free((void *) object); \ + } \ + } while (0) #endif /** @@ -374,23 +365,22 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* * @param type The object type */ -#define OBJ_CONSTRUCT(object, type) \ -do { \ - OBJ_CONSTRUCT_INTERNAL((object), OBJ_CLASS(type)); \ -} while (0) - -#define OBJ_CONSTRUCT_INTERNAL(object, type) \ -do { \ - OBJ_SET_MAGIC_ID((object), OPAL_OBJ_MAGIC_ID); \ - if (opal_class_init_epoch != (type)->cls_initialized) { \ - opal_class_initialize((type)); \ - } \ - ((opal_object_t *) (object))->obj_class = (type); \ - ((opal_object_t *) (object))->obj_reference_count = 1; \ - opal_obj_run_constructors((opal_object_t *) (object)); \ - OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ -} while (0) +#define OBJ_CONSTRUCT(object, type) \ + do { \ + OBJ_CONSTRUCT_INTERNAL((object), OBJ_CLASS(type)); \ + } while (0) +#define OBJ_CONSTRUCT_INTERNAL(object, type) \ + do { \ + OBJ_SET_MAGIC_ID((object), OPAL_OBJ_MAGIC_ID); \ + if (opal_class_init_epoch != (type)->cls_initialized) { \ + opal_class_initialize((type)); \ + } \ + ((opal_object_t *) (object))->obj_class = (type); \ + ((opal_object_t *) (object))->obj_reference_count = 1; \ + opal_obj_run_constructors((opal_object_t *) (object)); \ + OBJ_REMEMBER_FILE_AND_LINENO(object, __FILE__, __LINE__); \ + } while (0) /** * Destruct (finalize) an object that is not dynamically allocated. @@ -398,19 +388,19 @@ do { \ * @param object Pointer to the object */ #if OPAL_ENABLE_DEBUG -#define OBJ_DESTRUCT(object) \ -do { \ - assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ - OBJ_SET_MAGIC_ID((object), 0); \ - opal_obj_run_destructors((opal_object_t *) (object)); \ - OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ -} while (0) +# define OBJ_DESTRUCT(object) \ + do { \ + assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \ + OBJ_SET_MAGIC_ID((object), 0); \ + opal_obj_run_destructors((opal_object_t *) (object)); \ + OBJ_REMEMBER_FILE_AND_LINENO(object, __FILE__, __LINE__); \ + } while (0) #else -#define OBJ_DESTRUCT(object) \ -do { \ - opal_obj_run_destructors((opal_object_t *) (object)); \ - OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ -} while (0) +# define OBJ_DESTRUCT(object) \ + do { \ + opal_obj_run_destructors((opal_object_t *) (object)); \ + OBJ_REMEMBER_FILE_AND_LINENO(object, __FILE__, __LINE__); \ + } while (0) #endif OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_object_t); @@ -450,20 +440,19 @@ OPAL_DECLSPEC int opal_class_finalize(void); * Hardwired for fairly shallow inheritance trees * @param size Pointer to the object. */ -static inline void opal_obj_run_constructors(opal_object_t * object) +static inline void opal_obj_run_constructors(opal_object_t *object) { - opal_construct_t* cls_construct; + opal_construct_t *cls_construct; assert(NULL != object->obj_class); cls_construct = object->obj_class->cls_construct_array; - while( NULL != *cls_construct ) { + while (NULL != *cls_construct) { (*cls_construct)(object); cls_construct++; } } - /** * Run the hierarchy of class destructors for this object, in a * parent-last order. @@ -472,20 +461,19 @@ static inline void opal_obj_run_constructors(opal_object_t * object) * * @param size Pointer to the object. */ -static inline void opal_obj_run_destructors(opal_object_t * object) +static inline void opal_obj_run_destructors(opal_object_t *object) { - opal_destruct_t* cls_destruct; + opal_destruct_t *cls_destruct; assert(NULL != object->obj_class); cls_destruct = object->obj_class->cls_destruct_array; - while( NULL != *cls_destruct ) { + while (NULL != *cls_destruct) { (*cls_destruct)(object); cls_destruct++; } } - /** * Create new object: dynamically allocate storage and run the class * constructor. @@ -496,7 +484,7 @@ static inline void opal_obj_run_destructors(opal_object_t * object) * @param cls Pointer to the class descriptor of this object * @return Pointer to the object */ -static inline opal_object_t *opal_obj_new(opal_class_t * cls) +static inline opal_object_t *opal_obj_new(opal_class_t *cls) { opal_object_t *object; assert(cls->cls_sizeof >= sizeof(opal_object_t)); @@ -517,7 +505,6 @@ static inline opal_object_t *opal_obj_new(opal_class_t * cls) return object; } - /** * Atomically update the object's reference count by some increment. * diff --git a/opal/class/opal_pointer_array.c b/opal/class/opal_pointer_array.c index b28337a616c..f00d5fa8bb0 100644 --- a/opal/class/opal_pointer_array.c +++ b/opal/class/opal_pointer_array.c @@ -19,20 +19,19 @@ #include "opal_config.h" -#include -#include #include +#include +#include -#include "opal/constants.h" #include "opal/class/opal_pointer_array.h" +#include "opal/constants.h" #include "opal/util/output.h" static void opal_pointer_array_construct(opal_pointer_array_t *); static void opal_pointer_array_destruct(opal_pointer_array_t *); static bool grow_table(opal_pointer_array_t *table, int at_least); -OBJ_CLASS_INSTANCE(opal_pointer_array_t, opal_object_t, - opal_pointer_array_construct, +OBJ_CLASS_INSTANCE(opal_pointer_array_t, opal_object_t, opal_pointer_array_construct, opal_pointer_array_destruct); /* @@ -56,11 +55,11 @@ static void opal_pointer_array_construct(opal_pointer_array_t *array) static void opal_pointer_array_destruct(opal_pointer_array_t *array) { /* free table */ - if( NULL != array->free_bits) { + if (NULL != array->free_bits) { free(array->free_bits); array->free_bits = NULL; } - if( NULL != array->addr ) { + if (NULL != array->addr) { free(array->addr); array->addr = NULL; } @@ -76,12 +75,12 @@ static void opal_pointer_array_destruct(opal_pointer_array_t *array) * Translate an index position into the free bits array into 2 values, the * index of the element and the index of the bit position. */ -#define GET_BIT_POS(IDX, BIDX, PIDX) \ - do { \ - uint32_t __idx = (uint32_t)(IDX); \ - (BIDX) = (__idx / (8 * sizeof(uint64_t))); \ - (PIDX) = (__idx % (8 * sizeof(uint64_t))); \ - } while(0) +#define GET_BIT_POS(IDX, BIDX, PIDX) \ + do { \ + uint32_t __idx = (uint32_t)(IDX); \ + (BIDX) = (__idx / (8 * sizeof(uint64_t))); \ + (PIDX) = (__idx % (8 * sizeof(uint64_t))); \ + } while (0) /** * A classical find first zero bit (ffs) on a large array. It checks starting @@ -92,61 +91,67 @@ static void opal_pointer_array_destruct(opal_pointer_array_t *array) * indicator to constants (the type is inferred by the compiler according to * the number of bits necessary to represent it). */ -#define FIND_FIRST_ZERO(START_IDX, STORE) \ - do { \ - uint32_t __b_idx, __b_pos; \ - if( 0 == table->number_free ) { \ - (STORE) = table->size; \ - break; \ - } \ - GET_BIT_POS((START_IDX), __b_idx, __b_pos); \ - for (; table->free_bits[__b_idx] == 0xFFFFFFFFFFFFFFFFu; __b_idx++); \ - assert(__b_idx < (uint32_t)table->size); \ - uint64_t __check_value = table->free_bits[__b_idx]; \ - __b_pos = 0; \ - \ - if( 0x00000000FFFFFFFFu == (__check_value & 0x00000000FFFFFFFFu) ) { \ - __check_value >>= 32; __b_pos += 32; \ - } \ - if( 0x000000000000FFFFu == (__check_value & 0x000000000000FFFFu) ) { \ - __check_value >>= 16; __b_pos += 16; \ - } \ - if( 0x00000000000000FFu == (__check_value & 0x00000000000000FFu) ) { \ - __check_value >>= 8; __b_pos += 8; \ - } \ - if( 0x000000000000000Fu == (__check_value & 0x000000000000000Fu) ) { \ - __check_value >>= 4; __b_pos += 4; \ - } \ - if( 0x0000000000000003u == (__check_value & 0x0000000000000003u) ) { \ - __check_value >>= 2; __b_pos += 2; \ - } \ - if( 0x0000000000000001u == (__check_value & 0x0000000000000001u) ) { \ - __b_pos += 1; \ - } \ - (STORE) = (__b_idx * 8 * sizeof(uint64_t)) + __b_pos; \ - } while(0) +#define FIND_FIRST_ZERO(START_IDX, STORE) \ + do { \ + uint32_t __b_idx, __b_pos; \ + if (0 == table->number_free) { \ + (STORE) = table->size; \ + break; \ + } \ + GET_BIT_POS((START_IDX), __b_idx, __b_pos); \ + for (; table->free_bits[__b_idx] == 0xFFFFFFFFFFFFFFFFu; __b_idx++) \ + ; \ + assert(__b_idx < (uint32_t) table->size); \ + uint64_t __check_value = table->free_bits[__b_idx]; \ + __b_pos = 0; \ + \ + if (0x00000000FFFFFFFFu == (__check_value & 0x00000000FFFFFFFFu)) { \ + __check_value >>= 32; \ + __b_pos += 32; \ + } \ + if (0x000000000000FFFFu == (__check_value & 0x000000000000FFFFu)) { \ + __check_value >>= 16; \ + __b_pos += 16; \ + } \ + if (0x00000000000000FFu == (__check_value & 0x00000000000000FFu)) { \ + __check_value >>= 8; \ + __b_pos += 8; \ + } \ + if (0x000000000000000Fu == (__check_value & 0x000000000000000Fu)) { \ + __check_value >>= 4; \ + __b_pos += 4; \ + } \ + if (0x0000000000000003u == (__check_value & 0x0000000000000003u)) { \ + __check_value >>= 2; \ + __b_pos += 2; \ + } \ + if (0x0000000000000001u == (__check_value & 0x0000000000000001u)) { \ + __b_pos += 1; \ + } \ + (STORE) = (__b_idx * 8 * sizeof(uint64_t)) + __b_pos; \ + } while (0) /** * Set the IDX bit in the free_bits array. The bit should be previously unset. */ -#define SET_BIT(IDX) \ - do { \ - uint32_t __b_idx, __b_pos; \ - GET_BIT_POS((IDX), __b_idx, __b_pos); \ - assert( 0 == (table->free_bits[__b_idx] & (((uint64_t)1) << __b_pos))); \ - table->free_bits[__b_idx] |= (((uint64_t)1) << __b_pos); \ - } while(0) +#define SET_BIT(IDX) \ + do { \ + uint32_t __b_idx, __b_pos; \ + GET_BIT_POS((IDX), __b_idx, __b_pos); \ + assert(0 == (table->free_bits[__b_idx] & (((uint64_t) 1) << __b_pos))); \ + table->free_bits[__b_idx] |= (((uint64_t) 1) << __b_pos); \ + } while (0) /** * Unset the IDX bit in the free_bits array. The bit should be previously set. */ -#define UNSET_BIT(IDX) \ - do { \ - uint32_t __b_idx, __b_pos; \ - GET_BIT_POS((IDX), __b_idx, __b_pos); \ - assert( (table->free_bits[__b_idx] & (((uint64_t)1) << __b_pos))); \ - table->free_bits[__b_idx] ^= (((uint64_t)1) << __b_pos); \ - } while(0) +#define UNSET_BIT(IDX) \ + do { \ + uint32_t __b_idx, __b_pos; \ + GET_BIT_POS((IDX), __b_idx, __b_pos); \ + assert((table->free_bits[__b_idx] & (((uint64_t) 1) << __b_pos))); \ + table->free_bits[__b_idx] ^= (((uint64_t) 1) << __b_pos); \ + } while (0) #if 0 /** @@ -175,9 +180,8 @@ static void opal_pointer_array_validate(opal_pointer_array_t *array) /** * initialize an array object */ -int opal_pointer_array_init(opal_pointer_array_t* array, - int initial_allocation, - int max_size, int block_size) +int opal_pointer_array_init(opal_pointer_array_t *array, int initial_allocation, int max_size, + int block_size) { size_t num_bytes; @@ -193,12 +197,12 @@ int opal_pointer_array_init(opal_pointer_array_t* array, num_bytes = (0 < initial_allocation ? initial_allocation : block_size); /* Allocate and set the array to NULL */ - array->addr = (void **)calloc(num_bytes, sizeof(void*)); + array->addr = (void **) calloc(num_bytes, sizeof(void *)); if (NULL == array->addr) { /* out of memory */ return OPAL_ERR_OUT_OF_RESOURCE; } - array->free_bits = (uint64_t*)calloc(TYPE_ELEM_COUNT(uint64_t, num_bytes), sizeof(uint64_t)); - if (NULL == array->free_bits) { /* out of memory */ + array->free_bits = (uint64_t *) calloc(TYPE_ELEM_COUNT(uint64_t, num_bytes), sizeof(uint64_t)); + if (NULL == array->free_bits) { /* out of memory */ free(array->addr); array->addr = NULL; return OPAL_ERR_OUT_OF_RESOURCE; @@ -225,15 +229,15 @@ int opal_pointer_array_add(opal_pointer_array_t *table, void *ptr) if (table->number_free == 0) { /* need to grow table */ - if (!grow_table(table, index) ) { + if (!grow_table(table, index)) { OPAL_THREAD_UNLOCK(&(table->lock)); return OPAL_ERR_OUT_OF_RESOURCE; } } - assert( (table->addr != NULL) && (table->size > 0) ); - assert( (table->lowest_free >= 0) && (table->lowest_free < table->size) ); - assert( (table->number_free > 0) && (table->number_free <= table->size) ); + assert((table->addr != NULL) && (table->size > 0)); + assert((table->lowest_free >= 0) && (table->lowest_free < table->size)); + assert((table->number_free > 0) && (table->number_free <= table->size)); /* * add pointer to table, and return the index @@ -268,8 +272,7 @@ int opal_pointer_array_add(opal_pointer_array_t *table, void *ptr) * * Assumption: NULL element is free element. */ -int opal_pointer_array_set_item(opal_pointer_array_t *table, int index, - void * value) +int opal_pointer_array_set_item(opal_pointer_array_t *table, int index, void *value) { assert(table != NULL); @@ -288,8 +291,8 @@ int opal_pointer_array_set_item(opal_pointer_array_t *table, int index, } assert(table->size > index); /* mark element as free, if NULL element */ - if( NULL == value ) { - if( NULL != table->addr[index] ) { + if (NULL == value) { + if (NULL != table->addr[index]) { if (index < table->lowest_free) { table->lowest_free = index; } @@ -301,11 +304,11 @@ int opal_pointer_array_set_item(opal_pointer_array_t *table, int index, table->number_free--; SET_BIT(index); /* Reset lowest_free if required */ - if ( index == table->lowest_free ) { + if (index == table->lowest_free) { FIND_FIRST_ZERO(index, table->lowest_free); } } else { - assert( index != table->lowest_free ); + assert(index != table->lowest_free); } } table->addr[index] = value; @@ -337,8 +340,7 @@ int opal_pointer_array_set_item(opal_pointer_array_t *table, int index, * In contrary to array_set, this function does not allow to overwrite * a value, unless the previous value is NULL ( equiv. to free ). */ -bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *table, - int index, void *value) +bool opal_pointer_array_test_and_set_item(opal_pointer_array_t *table, int index, void *value) { assert(table != NULL); assert(index >= 0); @@ -353,7 +355,7 @@ bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *table, /* expand table if required to set a specific index */ OPAL_THREAD_LOCK(&(table->lock)); - if ( index < table->size && table->addr[index] != NULL ) { + if (index < table->size && table->addr[index] != NULL) { /* This element is already in use */ OPAL_THREAD_UNLOCK(&(table->lock)); return false; @@ -376,8 +378,8 @@ bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *table, table->number_free--; SET_BIT(index); /* Reset lowest_free if required */ - if( table->number_free > 0 ) { - if ( index == table->lowest_free ) { + if (table->number_free > 0) { + if (index == table->lowest_free) { FIND_FIRST_ZERO(index, table->lowest_free); } } else { @@ -400,7 +402,7 @@ bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *table, int opal_pointer_array_set_size(opal_pointer_array_t *array, int new_size) { OPAL_THREAD_LOCK(&(array->lock)); - if(new_size > array->size) { + if (new_size > array->size) { if (!grow_table(array, new_size)) { OPAL_THREAD_UNLOCK(&(array->lock)); return OPAL_ERROR; @@ -416,9 +418,9 @@ static bool grow_table(opal_pointer_array_t *table, int at_least) void *p; new_size = table->block_size * ((at_least + 1 + table->block_size - 1) / table->block_size); - if( new_size >= table->max_size ) { + if (new_size >= table->max_size) { new_size = table->max_size; - if( at_least >= table->max_size ) { + if (at_least >= table->max_size) { return false; } } @@ -429,19 +431,18 @@ static bool grow_table(opal_pointer_array_t *table, int at_least) } table->number_free += (new_size - table->size); - table->addr = (void**)p; + table->addr = (void **) p; for (i = table->size; i < new_size; ++i) { table->addr[i] = NULL; } new_size_int = TYPE_ELEM_COUNT(uint64_t, new_size); - if( (int)(TYPE_ELEM_COUNT(uint64_t, table->size)) != new_size_int ) { - p = (uint64_t*)realloc(table->free_bits, new_size_int * sizeof(uint64_t)); + if ((int) (TYPE_ELEM_COUNT(uint64_t, table->size)) != new_size_int) { + p = (uint64_t *) realloc(table->free_bits, new_size_int * sizeof(uint64_t)); if (NULL == p) { return false; } - table->free_bits = (uint64_t*)p; - for (i = TYPE_ELEM_COUNT(uint64_t, table->size); - i < new_size_int; i++ ) { + table->free_bits = (uint64_t *) p; + for (i = TYPE_ELEM_COUNT(uint64_t, table->size); i < new_size_int; i++) { table->free_bits[i] = 0; } } diff --git a/opal/class/opal_pointer_array.h b/opal/class/opal_pointer_array.h index ec6a883f5e4..dac859b3d14 100644 --- a/opal/class/opal_pointer_array.h +++ b/opal/class/opal_pointer_array.h @@ -31,8 +31,8 @@ #include "opal_config.h" -#include "opal/mca/threads/mutex.h" #include "opal/class/opal_object.h" +#include "opal/mca/threads/mutex.h" #include "opal/prefetch.h" BEGIN_C_DECLS @@ -59,7 +59,7 @@ struct opal_pointer_array_t { /** block size for each allocation */ int block_size; /** pointer to an array of bits to speed up the research for an empty position. */ - uint64_t* free_bits; + uint64_t *free_bits; /** pointer to array of pointers */ void **addr; }; @@ -86,9 +86,8 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_pointer_array_t); * @return OPAL_SUCCESS if all initializations were succesfull. Otherwise, * the error indicate what went wrong in the function. */ -OPAL_DECLSPEC int opal_pointer_array_init( opal_pointer_array_t* array, - int initial_allocation, - int max_size, int block_size ); +OPAL_DECLSPEC int opal_pointer_array_init(opal_pointer_array_t *array, int initial_allocation, + int max_size, int block_size); /** * Add a pointer to the array (Grow the array, if need be) @@ -110,8 +109,7 @@ OPAL_DECLSPEC int opal_pointer_array_add(opal_pointer_array_t *array, void *ptr) * * @return Error code. (-1) indicates an error. */ -OPAL_DECLSPEC int opal_pointer_array_set_item(opal_pointer_array_t *array, - int index, void *value); +OPAL_DECLSPEC int opal_pointer_array_set_item(opal_pointer_array_t *array, int index, void *value); /** * Get the value of an element in array @@ -122,12 +120,11 @@ OPAL_DECLSPEC int opal_pointer_array_set_item(opal_pointer_array_t *array, * @return Error code. NULL indicates an error. */ -static inline void *opal_pointer_array_get_item(opal_pointer_array_t *table, - int element_index) +static inline void *opal_pointer_array_get_item(opal_pointer_array_t *table, int element_index) { void *p; - if( OPAL_UNLIKELY(0 > element_index || table->size <= element_index) ) { + if (OPAL_UNLIKELY(0 > element_index || table->size <= element_index)) { return NULL; } OPAL_THREAD_LOCK(&(table->lock)); @@ -136,7 +133,6 @@ static inline void *opal_pointer_array_get_item(opal_pointer_array_t *table, return p; } - /** * Get the size of the pointer array * @@ -149,7 +145,7 @@ static inline void *opal_pointer_array_get_item(opal_pointer_array_t *table, */ static inline int opal_pointer_array_get_size(opal_pointer_array_t *array) { - return array->size; + return array->size; } /** @@ -178,9 +174,8 @@ OPAL_DECLSPEC int opal_pointer_array_set_size(opal_pointer_array_t *array, int s * In contrary to array_set, this function does not allow to overwrite * a value, unless the previous value is NULL ( equiv. to free ). */ -OPAL_DECLSPEC bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *table, - int index, - void *value); +OPAL_DECLSPEC bool opal_pointer_array_test_and_set_item(opal_pointer_array_t *table, int index, + void *value); /** * Empty the array. @@ -191,16 +186,17 @@ OPAL_DECLSPEC bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *t static inline void opal_pointer_array_remove_all(opal_pointer_array_t *array) { int i; - if( array->number_free == array->size ) - return; /* nothing to do here this time (the array is already empty) */ + if (array->number_free == array->size) + return; /* nothing to do here this time (the array is already empty) */ OPAL_THREAD_LOCK(&array->lock); array->lowest_free = 0; array->number_free = array->size; - for(i = 0; i < array->size; i++) { + for (i = 0; i < array->size; i++) { array->addr[i] = NULL; } - for(i = 0; i < (int)((array->size + 8*sizeof(uint64_t) - 1) / (8*sizeof(uint64_t))); i++) { + for (i = 0; i < (int) ((array->size + 8 * sizeof(uint64_t) - 1) / (8 * sizeof(uint64_t))); + i++) { array->free_bits[i] = 0; } OPAL_THREAD_UNLOCK(&array->lock); diff --git a/opal/class/opal_rb_tree.c b/opal/class/opal_rb_tree.c index cdbaa187642..96400edeed7 100644 --- a/opal/class/opal_rb_tree.c +++ b/opal/class/opal_rb_tree.c @@ -27,19 +27,15 @@ #include "opal/class/opal_rb_tree.h" /* Private functions */ -static void btree_insert(opal_rb_tree_t *tree, opal_rb_tree_node_t * node); -static void btree_delete_fixup(opal_rb_tree_t *tree, opal_rb_tree_node_t * x); -static opal_rb_tree_node_t * btree_successor(opal_rb_tree_t * tree, - opal_rb_tree_node_t * node); -static opal_rb_tree_node_t * opal_rb_tree_find_node(opal_rb_tree_t *tree, void *key); -static void left_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t * x); -static void right_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t * x); -static void inorder_destroy(opal_rb_tree_t *tree, opal_rb_tree_node_t * node); -static void inorder_traversal(opal_rb_tree_t *tree, - opal_rb_tree_condition_fn_t cond, - opal_rb_tree_action_fn_t action, - opal_rb_tree_node_t * node); - +static void btree_insert(opal_rb_tree_t *tree, opal_rb_tree_node_t *node); +static void btree_delete_fixup(opal_rb_tree_t *tree, opal_rb_tree_node_t *x); +static opal_rb_tree_node_t *btree_successor(opal_rb_tree_t *tree, opal_rb_tree_node_t *node); +static opal_rb_tree_node_t *opal_rb_tree_find_node(opal_rb_tree_t *tree, void *key); +static void left_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t *x); +static void right_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t *x); +static void inorder_destroy(opal_rb_tree_t *tree, opal_rb_tree_node_t *node); +static void inorder_traversal(opal_rb_tree_t *tree, opal_rb_tree_condition_fn_t cond, + opal_rb_tree_action_fn_t action, opal_rb_tree_node_t *node); /** * the constructor function. creates the free list to get the nodes from @@ -48,14 +44,14 @@ static void inorder_traversal(opal_rb_tree_t *tree, * * @retval NONE */ -static void opal_rb_tree_construct(opal_object_t * object) +static void opal_rb_tree_construct(opal_object_t *object) { - opal_rb_tree_t * tree = (opal_rb_tree_t *) object; + opal_rb_tree_t *tree = (opal_rb_tree_t *) object; tree->root_ptr = NULL; OBJ_CONSTRUCT(&(tree->free_list), opal_free_list_t); - opal_free_list_init (&(tree->free_list), sizeof(opal_rb_tree_node_t), - opal_cache_line_size, OBJ_CLASS(opal_rb_tree_node_t), - 0,opal_cache_line_size, 0, -1 , 128, NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&(tree->free_list), sizeof(opal_rb_tree_node_t), opal_cache_line_size, + OBJ_CLASS(opal_rb_tree_node_t), 0, opal_cache_line_size, 0, -1, 128, NULL, + 0, NULL, NULL, NULL); } /** @@ -63,35 +59,33 @@ static void opal_rb_tree_construct(opal_object_t * object) * * @param object the tree object */ -static void opal_rb_tree_destruct(opal_object_t * object) +static void opal_rb_tree_destruct(opal_object_t *object) { - if(NULL != ((opal_rb_tree_t *)object)->root_ptr) { + if (NULL != ((opal_rb_tree_t *) object)->root_ptr) { opal_rb_tree_destroy((opal_rb_tree_t *) object); } - OBJ_DESTRUCT(&(((opal_rb_tree_t *)object)->free_list)); + OBJ_DESTRUCT(&(((opal_rb_tree_t *) object)->free_list)); return; } /* declare the instance of the classes */ OBJ_CLASS_INSTANCE(opal_rb_tree_node_t, opal_free_list_item_t, NULL, NULL); -OBJ_CLASS_INSTANCE(opal_rb_tree_t, opal_object_t, opal_rb_tree_construct, - opal_rb_tree_destruct); +OBJ_CLASS_INSTANCE(opal_rb_tree_t, opal_object_t, opal_rb_tree_construct, opal_rb_tree_destruct); /* Create the tree */ -int opal_rb_tree_init(opal_rb_tree_t * tree, - opal_rb_tree_comp_fn_t comp) +int opal_rb_tree_init(opal_rb_tree_t *tree, opal_rb_tree_comp_fn_t comp) { - opal_free_list_item_t * node; + opal_free_list_item_t *node; /* we need to get memory for the root pointer from the free list */ - node = opal_free_list_get (&(tree->free_list)); + node = opal_free_list_get(&(tree->free_list)); tree->root_ptr = (opal_rb_tree_node_t *) node; if (NULL == node) { return OPAL_ERR_OUT_OF_RESOURCE; } - node = opal_free_list_get (&(tree->free_list)); + node = opal_free_list_get(&(tree->free_list)); if (NULL == node) { - opal_free_list_return (&tree->free_list, (opal_free_list_item_t*)tree->root_ptr); + opal_free_list_return(&tree->free_list, (opal_free_list_item_t *) tree->root_ptr); return OPAL_ERR_OUT_OF_RESOURCE; } tree->nill = (opal_rb_tree_node_t *) node; @@ -115,16 +109,15 @@ int opal_rb_tree_init(opal_rb_tree_t * tree, return OPAL_SUCCESS; } - /* This inserts a node into the tree based on the passed values. */ -int opal_rb_tree_insert(opal_rb_tree_t *tree, void * key, void * value) +int opal_rb_tree_insert(opal_rb_tree_t *tree, void *key, void *value) { - opal_rb_tree_node_t * y; - opal_rb_tree_node_t * node; - opal_free_list_item_t * item; + opal_rb_tree_node_t *y; + opal_rb_tree_node_t *node; + opal_free_list_item_t *item; /* get the memory for a node */ - item = opal_free_list_get (&tree->free_list); + item = opal_free_list_get(&tree->free_list); if (NULL == item) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -180,10 +173,9 @@ int opal_rb_tree_insert(opal_rb_tree_t *tree, void * key, void * value) } /* Finds the node in the tree based on the key */ -void * opal_rb_tree_find_with(opal_rb_tree_t *tree, void *key, - opal_rb_tree_comp_fn_t compfn) +void *opal_rb_tree_find_with(opal_rb_tree_t *tree, void *key, opal_rb_tree_comp_fn_t compfn) { - opal_rb_tree_node_t * node; + opal_rb_tree_node_t *node; int compvalue; node = tree->root_ptr->left; @@ -203,9 +195,9 @@ void * opal_rb_tree_find_with(opal_rb_tree_t *tree, void *key, /* Finds the node in the tree based on the key and returns a pointer * to the node. This is a bit a code duplication, but this has to be fast * so we go ahead with the duplication */ -static opal_rb_tree_node_t * opal_rb_tree_find_node(opal_rb_tree_t *tree, void *key) +static opal_rb_tree_node_t *opal_rb_tree_find_node(opal_rb_tree_t *tree, void *key) { - opal_rb_tree_node_t * node; + opal_rb_tree_node_t *node; int compvalue; node = tree->root_ptr->left; @@ -225,10 +217,10 @@ static opal_rb_tree_node_t * opal_rb_tree_find_node(opal_rb_tree_t *tree, void * /* Delete a node from the tree based on the key */ int opal_rb_tree_delete(opal_rb_tree_t *tree, void *key) { - opal_rb_tree_node_t * p; - opal_rb_tree_node_t * todelete; - opal_rb_tree_node_t * y; - opal_free_list_item_t * item; + opal_rb_tree_node_t *p; + opal_rb_tree_node_t *todelete; + opal_rb_tree_node_t *y; + opal_free_list_item_t *item; p = opal_rb_tree_find_node(tree, key); if (NULL == p) { @@ -252,7 +244,7 @@ int opal_rb_tree_delete(opal_rb_tree_t *tree, void *key) tree->root_ptr->left = y; } else { if (todelete == todelete->parent->left) { - todelete->parent->left = y; + todelete->parent->left = y; } else { todelete->parent->right = y; } @@ -267,16 +259,15 @@ int opal_rb_tree_delete(opal_rb_tree_t *tree, void *key) btree_delete_fixup(tree, y); } item = (opal_free_list_item_t *) todelete; - opal_free_list_return (&(tree->free_list), item); + opal_free_list_return(&(tree->free_list), item); --tree->tree_size; return OPAL_SUCCESS; } - /* Destroy the hashmap */ int opal_rb_tree_destroy(opal_rb_tree_t *tree) { - opal_free_list_item_t * item; + opal_free_list_item_t *item; /* Recursive inorder traversal for delete */ inorder_destroy(tree, tree->root_ptr); @@ -287,16 +278,15 @@ int opal_rb_tree_destroy(opal_rb_tree_t *tree) /* free the tree->nill node */ item = (opal_free_list_item_t *) tree->nill; - opal_free_list_return (&(tree->free_list), item); + opal_free_list_return(&(tree->free_list), item); return OPAL_SUCCESS; } - /* Find the next inorder successor of a node */ -static opal_rb_tree_node_t * btree_successor(opal_rb_tree_t * tree, opal_rb_tree_node_t * node) +static opal_rb_tree_node_t *btree_successor(opal_rb_tree_t *tree, opal_rb_tree_node_t *node) { - opal_rb_tree_node_t * p; + opal_rb_tree_node_t *p; if (node->right == tree->nill) { p = node->parent; @@ -304,27 +294,26 @@ static opal_rb_tree_node_t * btree_successor(opal_rb_tree_t * tree, opal_rb_tree node = p; p = p->parent; } - if(p == tree->root_ptr) { + if (p == tree->root_ptr) { return tree->nill; } return p; } p = node->right; - while(p->left != tree->nill) { + while (p->left != tree->nill) { p = p->left; } return p; } - /* Insert an element in the normal binary search tree fashion */ /* this function goes through the tree and finds the leaf where * the node will be inserted */ -static void btree_insert(opal_rb_tree_t *tree, opal_rb_tree_node_t * node) +static void btree_insert(opal_rb_tree_t *tree, opal_rb_tree_node_t *node) { - opal_rb_tree_node_t * parent = tree->root_ptr; - opal_rb_tree_node_t * n = parent->left; /* the real root of the tree */ + opal_rb_tree_node_t *parent = tree->root_ptr; + opal_rb_tree_node_t *n = parent->left; /* the real root of the tree */ /* set up initial values for the node */ node->color = RED; @@ -339,7 +328,7 @@ static void btree_insert(opal_rb_tree_t *tree, opal_rb_tree_node_t * node) } /* place it on either the left or the right */ - if((parent == tree->root_ptr) || (tree->comp(node->key, parent->key) <= 0)) { + if ((parent == tree->root_ptr) || (tree->comp(node->key, parent->key) <= 0)) { parent->left = node; } else { parent->right = node; @@ -354,10 +343,10 @@ static void btree_insert(opal_rb_tree_t *tree, opal_rb_tree_node_t * node) } /* Fixup the balance of the btree after deletion */ -static void btree_delete_fixup(opal_rb_tree_t *tree, opal_rb_tree_node_t * x) +static void btree_delete_fixup(opal_rb_tree_t *tree, opal_rb_tree_node_t *x) { - opal_rb_tree_node_t * w; - opal_rb_tree_node_t * root = tree->root_ptr->left; + opal_rb_tree_node_t *w; + opal_rb_tree_node_t *root = tree->root_ptr->left; while ((x != root) && (x->color == BLACK)) { if (x == x->parent->left) { w = x->parent->right; @@ -415,13 +404,11 @@ static void btree_delete_fixup(opal_rb_tree_t *tree, opal_rb_tree_node_t * x) return; } - /* Free the nodes in inorder fashion */ -static void -inorder_destroy(opal_rb_tree_t *tree, opal_rb_tree_node_t * node) +static void inorder_destroy(opal_rb_tree_t *tree, opal_rb_tree_node_t *node) { - opal_free_list_item_t * item; + opal_free_list_item_t *item; if (node == tree->nill) { return; @@ -432,21 +419,20 @@ inorder_destroy(opal_rb_tree_t *tree, opal_rb_tree_node_t * node) if (node->left != tree->nill) { item = (opal_free_list_item_t *) node->left; --tree->tree_size; - opal_free_list_return (&tree->free_list, item); + opal_free_list_return(&tree->free_list, item); } inorder_destroy(tree, node->right); if (node->right != tree->nill) { item = (opal_free_list_item_t *) node->right; --tree->tree_size; - opal_free_list_return (&tree->free_list, item); + opal_free_list_return(&tree->free_list, item); } } /* Try to access all the elements of the hashmap conditionally */ -int opal_rb_tree_traverse(opal_rb_tree_t *tree, - opal_rb_tree_condition_fn_t cond, +int opal_rb_tree_traverse(opal_rb_tree_t *tree, opal_rb_tree_condition_fn_t cond, opal_rb_tree_action_fn_t action) { if ((cond == NULL) || (action == NULL)) { @@ -458,11 +444,8 @@ int opal_rb_tree_traverse(opal_rb_tree_t *tree, return OPAL_SUCCESS; } - -static void inorder_traversal(opal_rb_tree_t *tree, - opal_rb_tree_condition_fn_t cond, - opal_rb_tree_action_fn_t action, - opal_rb_tree_node_t * node) +static void inorder_traversal(opal_rb_tree_t *tree, opal_rb_tree_condition_fn_t cond, + opal_rb_tree_action_fn_t action, opal_rb_tree_node_t *node) { if (node == tree->nill) { return; @@ -480,14 +463,14 @@ static void inorder_traversal(opal_rb_tree_t *tree, /* Left rotate the tree */ /* basically what we want to do is to make x be the left child * of its right child */ -static void left_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t * x) +static void left_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t *x) { - opal_rb_tree_node_t * y; + opal_rb_tree_node_t *y; y = x->right; /* make the left child of y's parent be x if it is not the sentinal node*/ if (y->left != tree->nill) { - y->left->parent=x; + y->left->parent = x; } /* normlly we would have to check to see if we are at the root. @@ -507,17 +490,16 @@ static void left_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t * x) return; } - /* Right rotate the tree */ /* basically what we want to do is to make x be the right child * of its left child */ -static void right_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t * x) +static void right_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t *x) { - opal_rb_tree_node_t * y; + opal_rb_tree_node_t *y; y = x->left; - if(y->right != tree->nill) { + if (y->right != tree->nill) { y->right->parent = x; } @@ -535,16 +517,15 @@ static void right_rotate(opal_rb_tree_t *tree, opal_rb_tree_node_t * x) return; } - /* returns the size of the tree */ int opal_rb_tree_size(opal_rb_tree_t *tree) { - return tree->tree_size; + return tree->tree_size; } /* below are a couple of debugging functions */ #if 0 -#include +# include static void inorder(opal_rb_tree_t * tree, opal_rb_tree_node_t * node); static void print_inorder(opal_rb_tree_t * tree); diff --git a/opal/class/opal_rb_tree.h b/opal/class/opal_rb_tree.h index c405904b699..67d595e8c23 100644 --- a/opal/class/opal_rb_tree.h +++ b/opal/class/opal_rb_tree.h @@ -29,10 +29,10 @@ #define OPAL_RB_TREE_H #include "opal_config.h" -#include -#include "opal/constants.h" -#include "opal/class/opal_object.h" #include "opal/class/opal_free_list.h" +#include "opal/class/opal_object.h" +#include "opal/constants.h" +#include BEGIN_C_DECLS /* @@ -40,43 +40,42 @@ BEGIN_C_DECLS */ /** - * red and black enum - */ -typedef enum {RED, BLACK} opal_rb_tree_nodecolor_t; + * red and black enum + */ +typedef enum { RED, BLACK } opal_rb_tree_nodecolor_t; /** - * node data structure - */ -struct opal_rb_tree_node_t -{ + * node data structure + */ +struct opal_rb_tree_node_t { opal_free_list_item_t super; /**< the parent class */ opal_rb_tree_nodecolor_t color; /**< the node color */ - struct opal_rb_tree_node_t * parent;/**< the parent node, can be NULL */ - struct opal_rb_tree_node_t * left; /**< the left child - can be nill */ - struct opal_rb_tree_node_t * right; /**< the right child - can be nill */ + struct opal_rb_tree_node_t *parent; /**< the parent node, can be NULL */ + struct opal_rb_tree_node_t *left; /**< the left child - can be nill */ + struct opal_rb_tree_node_t *right; /**< the right child - can be nill */ void *key; /**< a pointer to the key */ void *value; /**< a pointer to the value */ }; typedef struct opal_rb_tree_node_t opal_rb_tree_node_t; /** - * the compare function typedef. This function is used to compare 2 nodes. - */ + * the compare function typedef. This function is used to compare 2 nodes. + */ typedef int (*opal_rb_tree_comp_fn_t)(void *key1, void *key2); /** - * the data structure that holds all the needed information about the tree. - */ + * the data structure that holds all the needed information about the tree. + */ struct opal_rb_tree_t { - opal_object_t parent; /**< the parent class */ + opal_object_t parent; /**< the parent class */ /* this root pointer doesn't actually point to the root of the tree. * rather, it points to a sentinal node who's left branch is the real * root of the tree. This is done to eliminate special cases */ - opal_rb_tree_node_t * root_ptr; /**< a pointer to the root of the tree */ - opal_rb_tree_node_t * nill; /**< the nill sentinal node */ - opal_rb_tree_comp_fn_t comp; /**< the compare function */ - opal_free_list_t free_list; /**< the free list to get the memory from */ - size_t tree_size; /**< the size of the tree */ + opal_rb_tree_node_t *root_ptr; /**< a pointer to the root of the tree */ + opal_rb_tree_node_t *nill; /**< the nill sentinal node */ + opal_rb_tree_comp_fn_t comp; /**< the compare function */ + opal_free_list_t free_list; /**< the free list to get the memory from */ + size_t tree_size; /**< the size of the tree */ }; typedef struct opal_rb_tree_t opal_rb_tree_t; @@ -87,10 +86,10 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_rb_tree_t); /* Function pointers for map traversal function */ /** - * this function is used for the opal_rb_tree_traverse function. - * it is passed a pointer to the value for each node and, if it returns - * a one, the action function is called on that node. Otherwise, the node is ignored. - */ + * this function is used for the opal_rb_tree_traverse function. + * it is passed a pointer to the value for each node and, if it returns + * a one, the action function is called on that node. Otherwise, the node is ignored. + */ typedef int (*opal_rb_tree_condition_fn_t)(void *); /** * this function is used for the user to perform any action on the passed @@ -105,101 +104,99 @@ typedef void (*opal_rb_tree_action_fn_t)(void *, void *); */ /** - * the function creates a new tree - * - * @param tree a pointer to an allocated area of memory for the main - * tree data structure. - * @param comp a pointer to the function to use for comaparing 2 nodes - * - * @retval OPAL_SUCCESS if it is successful - * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful - */ -OPAL_DECLSPEC int opal_rb_tree_init(opal_rb_tree_t * tree, opal_rb_tree_comp_fn_t comp); - + * the function creates a new tree + * + * @param tree a pointer to an allocated area of memory for the main + * tree data structure. + * @param comp a pointer to the function to use for comaparing 2 nodes + * + * @retval OPAL_SUCCESS if it is successful + * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful + */ +OPAL_DECLSPEC int opal_rb_tree_init(opal_rb_tree_t *tree, opal_rb_tree_comp_fn_t comp); /** - * inserts a node into the tree - * - * @param tree a pointer to the tree data structure - * @param key the key for the node - * @param value the value for the node - * - * @retval OPAL_SUCCESS - * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful - */ -OPAL_DECLSPEC int opal_rb_tree_insert(opal_rb_tree_t *tree, void * key, void * value); + * inserts a node into the tree + * + * @param tree a pointer to the tree data structure + * @param key the key for the node + * @param value the value for the node + * + * @retval OPAL_SUCCESS + * @retval OPAL_ERR_TEMP_OUT_OF_RESOURCE if unsuccessful + */ +OPAL_DECLSPEC int opal_rb_tree_insert(opal_rb_tree_t *tree, void *key, void *value); /** - * finds a value in the tree based on the passed key using passed - * compare function - * - * @param tree a pointer to the tree data structure - * @param key a pointer to the key - * @param compare function - * - * @retval pointer to the value if found - * @retval NULL if not found - */ -OPAL_DECLSPEC void * opal_rb_tree_find_with(opal_rb_tree_t *tree, void *key, opal_rb_tree_comp_fn_t compfn); + * finds a value in the tree based on the passed key using passed + * compare function + * + * @param tree a pointer to the tree data structure + * @param key a pointer to the key + * @param compare function + * + * @retval pointer to the value if found + * @retval NULL if not found + */ +OPAL_DECLSPEC void *opal_rb_tree_find_with(opal_rb_tree_t *tree, void *key, + opal_rb_tree_comp_fn_t compfn); /** - * finds a value in the tree based on the passed key - * - * @param tree a pointer to the tree data structure - * @param key a pointer to the key - * - * @retval pointer to the value if found - * @retval NULL if not found - */ -static inline void * opal_rb_tree_find(opal_rb_tree_t *tree, void *key) + * finds a value in the tree based on the passed key + * + * @param tree a pointer to the tree data structure + * @param key a pointer to the key + * + * @retval pointer to the value if found + * @retval NULL if not found + */ +static inline void *opal_rb_tree_find(opal_rb_tree_t *tree, void *key) { return opal_rb_tree_find_with(tree, key, tree->comp); } /** - * deletes a node based on its key - * - * @param tree a pointer to the tree data structure - * @param key a pointer to the key - * - * @retval OPAL_SUCCESS if the node is found and deleted - * @retval OPAL_ERR_NOT_FOUND if the node is not found - */ + * deletes a node based on its key + * + * @param tree a pointer to the tree data structure + * @param key a pointer to the key + * + * @retval OPAL_SUCCESS if the node is found and deleted + * @retval OPAL_ERR_NOT_FOUND if the node is not found + */ OPAL_DECLSPEC int opal_rb_tree_delete(opal_rb_tree_t *tree, void *key); /** - * frees all the nodes on the tree - * - * @param tree a pointer to the tree data structure - * - * @retval OPAL_SUCCESS - */ + * frees all the nodes on the tree + * + * @param tree a pointer to the tree data structure + * + * @retval OPAL_SUCCESS + */ OPAL_DECLSPEC int opal_rb_tree_destroy(opal_rb_tree_t *tree); /** - * traverses the entire tree, performing the cond function on each of the - * values and if it returns one it performs the action function on the values - * - * @param tree a pointer to the tree - * @param cond a pointer to the condition function - * @param action a pointer to the action function - * - * @retval OPAL_SUCCESS - * @retval OPAL_ERROR if there is an error - */ -OPAL_DECLSPEC int opal_rb_tree_traverse(opal_rb_tree_t *tree, - opal_rb_tree_condition_fn_t cond, - opal_rb_tree_action_fn_t action); + * traverses the entire tree, performing the cond function on each of the + * values and if it returns one it performs the action function on the values + * + * @param tree a pointer to the tree + * @param cond a pointer to the condition function + * @param action a pointer to the action function + * + * @retval OPAL_SUCCESS + * @retval OPAL_ERROR if there is an error + */ +OPAL_DECLSPEC int opal_rb_tree_traverse(opal_rb_tree_t *tree, opal_rb_tree_condition_fn_t cond, + opal_rb_tree_action_fn_t action); /** - * returns the size of the tree - * - * @param tree a pointer to the tree data structure - * - * @retval int the nuber of items on the tree - */ + * returns the size of the tree + * + * @param tree a pointer to the tree data structure + * + * @retval int the nuber of items on the tree + */ OPAL_DECLSPEC int opal_rb_tree_size(opal_rb_tree_t *tree); END_C_DECLS #endif /* OPAL_RB_TREE_H */ - diff --git a/opal/class/opal_ring_buffer.c b/opal/class/opal_ring_buffer.c index e06b00eb889..60eed931562 100644 --- a/opal/class/opal_ring_buffer.c +++ b/opal/class/opal_ring_buffer.c @@ -20,19 +20,18 @@ #include "opal_config.h" -#include -#include #include +#include +#include -#include "opal/constants.h" #include "opal/class/opal_ring_buffer.h" +#include "opal/constants.h" #include "opal/util/output.h" static void opal_ring_buffer_construct(opal_ring_buffer_t *); static void opal_ring_buffer_destruct(opal_ring_buffer_t *); -OBJ_CLASS_INSTANCE(opal_ring_buffer_t, opal_object_t, - opal_ring_buffer_construct, +OBJ_CLASS_INSTANCE(opal_ring_buffer_t, opal_object_t, opal_ring_buffer_construct, opal_ring_buffer_destruct); /* @@ -54,7 +53,7 @@ static void opal_ring_buffer_construct(opal_ring_buffer_t *ring) */ static void opal_ring_buffer_destruct(opal_ring_buffer_t *ring) { - if( NULL != ring->addr) { + if (NULL != ring->addr) { free(ring->addr); ring->addr = NULL; } @@ -68,7 +67,7 @@ static void opal_ring_buffer_destruct(opal_ring_buffer_t *ring) /** * initialize a ring object */ -int opal_ring_buffer_init(opal_ring_buffer_t* ring, int size) +int opal_ring_buffer_init(opal_ring_buffer_t *ring, int size) { /* check for errors */ if (NULL == ring) { @@ -76,7 +75,7 @@ int opal_ring_buffer_init(opal_ring_buffer_t* ring, int size) } /* Allocate and set the ring to NULL */ - ring->addr = (char **)calloc(size * sizeof(char*), 1); + ring->addr = (char **) calloc(size * sizeof(char *), 1); if (NULL == ring->addr) { /* out of memory */ return OPAL_ERR_OUT_OF_RESOURCE; } @@ -85,20 +84,20 @@ int opal_ring_buffer_init(opal_ring_buffer_t* ring, int size) return OPAL_SUCCESS; } -void* opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr) +void *opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr) { - char *p=NULL; + char *p = NULL; OPAL_ACQUIRE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); if (NULL != ring->addr[ring->head]) { - p = (char*)ring->addr[ring->head]; + p = (char *) ring->addr[ring->head]; if (ring->tail == ring->size - 1) { ring->tail = 0; } else { ring->tail = ring->head + 1; } } - ring->addr[ring->head] = (char*)ptr; + ring->addr[ring->head] = (char *) ptr; if (ring->tail < 0) { ring->tail = ring->head; } @@ -108,21 +107,21 @@ void* opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr) ring->head++; } OPAL_RELEASE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); - return (void*)p; + return (void *) p; } -void* opal_ring_buffer_pop(opal_ring_buffer_t *ring) +void *opal_ring_buffer_pop(opal_ring_buffer_t *ring) { - char *p=NULL; + char *p = NULL; OPAL_ACQUIRE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); if (-1 == ring->tail) { /* nothing has been put on the ring yet */ p = NULL; } else { - p = (char*)ring->addr[ring->tail]; + p = (char *) ring->addr[ring->tail]; ring->addr[ring->tail] = NULL; - if (ring->tail == ring->size-1) { + if (ring->tail == ring->size - 1) { ring->tail = 0; } else { ring->tail++; @@ -133,12 +132,12 @@ void* opal_ring_buffer_pop(opal_ring_buffer_t *ring) } } OPAL_RELEASE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); - return (void*)p; + return (void *) p; } - void* opal_ring_buffer_poke(opal_ring_buffer_t *ring, int i) - { - char *p=NULL; +void *opal_ring_buffer_poke(opal_ring_buffer_t *ring, int i) +{ + char *p = NULL; int offset; OPAL_ACQUIRE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); @@ -161,5 +160,5 @@ void* opal_ring_buffer_pop(opal_ring_buffer_t *ring) p = ring->addr[offset]; } OPAL_RELEASE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); - return (void*)p; + return (void *) p; } diff --git a/opal/class/opal_ring_buffer.h b/opal/class/opal_ring_buffer.h index ed607709dfd..b36374a82c7 100644 --- a/opal/class/opal_ring_buffer.h +++ b/opal/class/opal_ring_buffer.h @@ -26,8 +26,8 @@ #include "opal_config.h" -#include "opal/mca/threads/threads.h" #include "opal/class/opal_object.h" +#include "opal/mca/threads/threads.h" #include "opal/util/output.h" BEGIN_C_DECLS @@ -68,7 +68,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_ring_buffer_t); * @return OPAL_SUCCESS if all initializations were succesful. Otherwise, * the error indicate what went wrong in the function. */ -OPAL_DECLSPEC int opal_ring_buffer_init(opal_ring_buffer_t* ring, int size); +OPAL_DECLSPEC int opal_ring_buffer_init(opal_ring_buffer_t *ring, int size); /** * Push an item onto the ring buffer @@ -79,8 +79,7 @@ OPAL_DECLSPEC int opal_ring_buffer_init(opal_ring_buffer_t* ring, int size); * @return OPAL_SUCCESS. Returns error if ring cannot take * another entry */ -OPAL_DECLSPEC void* opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr); - +OPAL_DECLSPEC void *opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr); /** * Pop an item off of the ring. The oldest entry on the ring will be @@ -91,14 +90,14 @@ OPAL_DECLSPEC void* opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr); * @return Error code. NULL indicates an error. */ -OPAL_DECLSPEC void* opal_ring_buffer_pop(opal_ring_buffer_t *ring); +OPAL_DECLSPEC void *opal_ring_buffer_pop(opal_ring_buffer_t *ring); /* * Access an element of the ring, without removing it, indexed * starting at the tail - a value of -1 will return the element * at the head of the ring */ -OPAL_DECLSPEC void* opal_ring_buffer_poke(opal_ring_buffer_t *ring, int i); +OPAL_DECLSPEC void *opal_ring_buffer_poke(opal_ring_buffer_t *ring, int i); END_C_DECLS diff --git a/opal/class/opal_value_array.c b/opal/class/opal_value_array.c index a9615dc1cba..18936b1fdf7 100644 --- a/opal/class/opal_value_array.c +++ b/opal/class/opal_value_array.c @@ -20,8 +20,7 @@ #include "opal/class/opal_value_array.h" - -static void opal_value_array_construct(opal_value_array_t* array) +static void opal_value_array_construct(opal_value_array_t *array) { array->array_items = NULL; array->array_size = 0; @@ -29,38 +28,36 @@ static void opal_value_array_construct(opal_value_array_t* array) array->array_alloc_size = 0; } -static void opal_value_array_destruct(opal_value_array_t* array) +static void opal_value_array_destruct(opal_value_array_t *array) { - if (NULL != array->array_items) + if (NULL != array->array_items) { free(array->array_items); + } } -OBJ_CLASS_INSTANCE( - opal_value_array_t, - opal_object_t, - opal_value_array_construct, - opal_value_array_destruct -); +OBJ_CLASS_INSTANCE(opal_value_array_t, opal_object_t, opal_value_array_construct, + opal_value_array_destruct); - -int opal_value_array_set_size(opal_value_array_t* array, size_t size) +int opal_value_array_set_size(opal_value_array_t *array, size_t size) { #if OPAL_ENABLE_DEBUG - if(array->array_item_sizeof == 0) { + if (array->array_item_sizeof == 0) { opal_output(0, "opal_value_array_set_size: item size must be initialized"); return OPAL_ERR_BAD_PARAM; } #endif - if(size > array->array_alloc_size) { - while(array->array_alloc_size < size) + if (size > array->array_alloc_size) { + while (array->array_alloc_size < size) { array->array_alloc_size <<= 1; - array->array_items = (unsigned char *)realloc(array->array_items, - array->array_alloc_size * array->array_item_sizeof); - if (NULL == array->array_items) + } + array->array_items = (unsigned char *) realloc(array->array_items, + array->array_alloc_size + * array->array_item_sizeof); + if (NULL == array->array_items) { return OPAL_ERR_OUT_OF_RESOURCE; + } } array->array_size = size; return OPAL_SUCCESS; } - diff --git a/opal/class/opal_value_array.h b/opal/class/opal_value_array.h index de59eb358af..01472bc427d 100644 --- a/opal/class/opal_value_array.h +++ b/opal/class/opal_value_array.h @@ -23,12 +23,12 @@ #include #ifdef HAVE_STRINGS_H -#include +# include #endif /* HAVE_STRINGS_H */ #include "opal/class/opal_object.h" #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" #endif #include "opal/constants.h" @@ -38,13 +38,12 @@ BEGIN_C_DECLS * @file Array of elements maintained by value. */ -struct opal_value_array_t -{ - opal_object_t super; - unsigned char* array_items; - size_t array_item_sizeof; - size_t array_size; - size_t array_alloc_size; +struct opal_value_array_t { + opal_object_t super; + unsigned char *array_items; + size_t array_item_sizeof; + size_t array_size; + size_t array_alloc_size; }; typedef struct opal_value_array_t opal_value_array_t; @@ -68,11 +67,11 @@ static inline int opal_value_array_init(opal_value_array_t *array, size_t item_s array->array_item_sizeof = item_sizeof; array->array_alloc_size = 1; array->array_size = 0; - array->array_items = (unsigned char*)realloc(array->array_items, item_sizeof * array->array_alloc_size); + array->array_items = (unsigned char *) realloc(array->array_items, + item_sizeof * array->array_alloc_size); return (NULL != array->array_items) ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE; } - /** * Reserve space in the array for new elements, but do not change the size. * @@ -81,22 +80,21 @@ static inline int opal_value_array_init(opal_value_array_t *array, size_t item_s * @return OPAL error code. */ -static inline int opal_value_array_reserve(opal_value_array_t* array, size_t size) +static inline int opal_value_array_reserve(opal_value_array_t *array, size_t size) { - if(size > array->array_alloc_size) { - array->array_items = (unsigned char*)realloc(array->array_items, array->array_item_sizeof * size); - if(NULL == array->array_items) { - array->array_size = 0; - array->array_alloc_size = 0; - return OPAL_ERR_OUT_OF_RESOURCE; - } - array->array_alloc_size = size; - } - return OPAL_SUCCESS; + if (size > array->array_alloc_size) { + array->array_items = (unsigned char *) realloc(array->array_items, + array->array_item_sizeof * size); + if (NULL == array->array_items) { + array->array_size = 0; + array->array_alloc_size = 0; + return OPAL_ERR_OUT_OF_RESOURCE; + } + array->array_alloc_size = size; + } + return OPAL_SUCCESS; } - - /** * Retreives the number of elements in the array. * @@ -104,12 +102,11 @@ static inline int opal_value_array_reserve(opal_value_array_t* array, size_t siz * @return The number of elements currently in use. */ -static inline size_t opal_value_array_get_size(opal_value_array_t* array) +static inline size_t opal_value_array_get_size(opal_value_array_t *array) { return array->array_size; } - /** * Set the number of elements in the array. * @@ -125,8 +122,7 @@ static inline size_t opal_value_array_get_size(opal_value_array_t* array) * return the new size. */ -OPAL_DECLSPEC int opal_value_array_set_size(opal_value_array_t* array, size_t size); - +OPAL_DECLSPEC int opal_value_array_set_size(opal_value_array_t *array, size_t size); /** * Macro to retrieve an item from the array by value. @@ -143,7 +139,7 @@ OPAL_DECLSPEC int opal_value_array_set_size(opal_value_array_t* array, size_t si */ #define OPAL_VALUE_ARRAY_GET_ITEM(array, item_type, item_index) \ - ((item_type*)((array)->array_items))[item_index] + ((item_type *) ((array)->array_items))[item_index] /** * Retrieve an item from the array by reference. @@ -157,9 +153,10 @@ OPAL_DECLSPEC int opal_value_array_set_size(opal_value_array_t* array, size_t si * array size, the array is grown to satisfy the request. */ -static inline void* opal_value_array_get_item(opal_value_array_t *array, size_t item_index) +static inline void *opal_value_array_get_item(opal_value_array_t *array, size_t item_index) { - if(item_index >= array->array_size && opal_value_array_set_size(array, item_index+1) != OPAL_SUCCESS) + if (item_index >= array->array_size + && opal_value_array_set_size(array, item_index + 1) != OPAL_SUCCESS) return NULL; return array->array_items + (item_index * array->array_item_sizeof); } @@ -181,7 +178,7 @@ static inline void* opal_value_array_get_item(opal_value_array_t *array, size_t */ #define OPAL_VALUE_ARRAY_SET_ITEM(array, item_type, item_index, item_value) \ - (((item_type*)((array)->array_items))[item_index] = item_value) + (((item_type *) ((array)->array_items))[item_index] = item_value) /** * Set an array element by value. @@ -197,17 +194,18 @@ static inline void* opal_value_array_get_item(opal_value_array_t *array, size_t * copied into the array by value. */ -static inline int opal_value_array_set_item(opal_value_array_t *array, size_t item_index, const void* item) +static inline int opal_value_array_set_item(opal_value_array_t *array, size_t item_index, + const void *item) { int rc; - if(item_index >= array->array_size && - (rc = opal_value_array_set_size(array, item_index+1)) != OPAL_SUCCESS) + if (item_index >= array->array_size + && (rc = opal_value_array_set_size(array, item_index + 1)) != OPAL_SUCCESS) return rc; - memcpy(array->array_items + (item_index * array->array_item_sizeof), item, array->array_item_sizeof); + memcpy(array->array_items + (item_index * array->array_item_sizeof), item, + array->array_item_sizeof); return OPAL_SUCCESS; } - /** * Appends an item to the end of the array. * @@ -227,7 +225,6 @@ static inline int opal_value_array_append_item(opal_value_array_t *array, const return opal_value_array_set_item(array, array->array_size, item); } - /** * Remove a specific item from the array. * @@ -244,12 +241,13 @@ static inline int opal_value_array_remove_item(opal_value_array_t *array, size_t { #if OPAL_ENABLE_DEBUG if (item_index >= array->array_size) { - opal_output(0, "opal_value_array_remove_item: invalid index %lu\n", (unsigned long)item_index); + opal_output(0, "opal_value_array_remove_item: invalid index %lu\n", + (unsigned long) item_index); return OPAL_ERR_BAD_PARAM; } #endif - memmove(array->array_items+(array->array_item_sizeof * item_index), - array->array_items+(array->array_item_sizeof * (item_index+1)), + memmove(array->array_items + (array->array_item_sizeof * item_index), + array->array_items + (array->array_item_sizeof * (item_index + 1)), array->array_item_sizeof * (array->array_size - item_index - 1)); array->array_size--; return OPAL_SUCCESS; @@ -271,10 +269,8 @@ static inline int opal_value_array_remove_item(opal_value_array_t *array, size_t * number of pointer dereferences. */ -#define OPAL_VALUE_ARRAY_GET_BASE(array, item_type) \ - ((item_type*) ((array)->array_items)) +#define OPAL_VALUE_ARRAY_GET_BASE(array, item_type) ((item_type *) ((array)->array_items)) END_C_DECLS #endif - diff --git a/opal/datatype/opal_convertor.c b/opal/datatype/opal_convertor.c index 36736a3007f..34efaaa8f16 100644 --- a/opal/datatype/opal_convertor.c +++ b/opal/datatype/opal_convertor.c @@ -25,63 +25,64 @@ #include "opal_config.h" #include -#include #include +#include #include "opal/prefetch.h" #include "opal/util/arch.h" #include "opal/util/output.h" -#include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" +#include "opal/datatype/opal_convertor_internal.h" +#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_checksum.h" +#include "opal/datatype/opal_datatype_internal.h" #include "opal/datatype/opal_datatype_prototypes.h" -#include "opal/datatype/opal_convertor_internal.h" #if OPAL_CUDA_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" -#define MEMCPY_CUDA( DST, SRC, BLENGTH, CONVERTOR ) \ - CONVERTOR->cbmemcpy( (DST), (SRC), (BLENGTH), (CONVERTOR) ) +# include "opal/mca/common/cuda/common_cuda.h" +# define MEMCPY_CUDA(DST, SRC, BLENGTH, CONVERTOR) \ + CONVERTOR->cbmemcpy((DST), (SRC), (BLENGTH), (CONVERTOR)) #endif -static void opal_convertor_construct( opal_convertor_t* convertor ) +static void opal_convertor_construct(opal_convertor_t *convertor) { - convertor->pStack = convertor->static_stack; - convertor->stack_size = DT_STATIC_STACK_SIZE; + convertor->pStack = convertor->static_stack; + convertor->stack_size = DT_STATIC_STACK_SIZE; convertor->partial_length = 0; - convertor->remoteArch = opal_local_arch; - convertor->flags = OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED; + convertor->remoteArch = opal_local_arch; + convertor->flags = OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED; #if OPAL_CUDA_SUPPORT - convertor->cbmemcpy = &opal_cuda_memcpy; + convertor->cbmemcpy = &opal_cuda_memcpy; #endif } - -static void opal_convertor_destruct( opal_convertor_t* convertor ) +static void opal_convertor_destruct(opal_convertor_t *convertor) { - opal_convertor_cleanup( convertor ); + opal_convertor_cleanup(convertor); } -OBJ_CLASS_INSTANCE(opal_convertor_t, opal_object_t, opal_convertor_construct, opal_convertor_destruct ); +OBJ_CLASS_INSTANCE(opal_convertor_t, opal_object_t, opal_convertor_construct, + opal_convertor_destruct); -static opal_convertor_master_t* opal_convertor_master_list = NULL; +static opal_convertor_master_t *opal_convertor_master_list = NULL; extern conversion_fct_t opal_datatype_heterogeneous_copy_functions[OPAL_DATATYPE_MAX_PREDEFINED]; extern conversion_fct_t opal_datatype_copy_functions[OPAL_DATATYPE_MAX_PREDEFINED]; -void opal_convertor_destroy_masters( void ) +void opal_convertor_destroy_masters(void) { - opal_convertor_master_t* master = opal_convertor_master_list; + opal_convertor_master_t *master = opal_convertor_master_list; - while( NULL != master ) { + while (NULL != master) { opal_convertor_master_list = master->next; master->next = NULL; /* Cleanup the conversion function if not one of the defaults */ - if( (master->pFunctions != opal_datatype_heterogeneous_copy_functions) && - (master->pFunctions != opal_datatype_copy_functions) ) - free( master->pFunctions ); + if ((master->pFunctions != opal_datatype_heterogeneous_copy_functions) + && (master->pFunctions != opal_datatype_copy_functions)) { + free(master->pFunctions); + } - free( master ); + free(master); master = opal_convertor_master_list; } } @@ -91,54 +92,55 @@ void opal_convertor_destroy_masters( void ) * is already a master convertor for this architecture then return it. * Otherwise, create and initialize a full featured master convertor. */ -opal_convertor_master_t* opal_convertor_find_or_create_master( uint32_t remote_arch ) +opal_convertor_master_t *opal_convertor_find_or_create_master(uint32_t remote_arch) { - opal_convertor_master_t* master = opal_convertor_master_list; + opal_convertor_master_t *master = opal_convertor_master_list; int i; - size_t* remote_sizes; + size_t *remote_sizes; - while( NULL != master ) { - if( master->remote_arch == remote_arch ) + while (NULL != master) { + if (master->remote_arch == remote_arch) { return master; + } master = master->next; } /** * Create a new convertor matching the specified architecture and add it to the * master convertor list. */ - master = (opal_convertor_master_t*)malloc( sizeof(opal_convertor_master_t) ); + master = (opal_convertor_master_t *) malloc(sizeof(opal_convertor_master_t)); master->next = opal_convertor_master_list; opal_convertor_master_list = master; master->remote_arch = remote_arch; - master->flags = 0; + master->flags = 0; master->hetero_mask = 0; /** * Most of the sizes will be identical, so for now just make a copy of * the local ones. As master->remote_sizes is defined as being an array of * consts we have to manually cast it before using it for writing purposes. */ - remote_sizes = (size_t*)master->remote_sizes; + remote_sizes = (size_t *) master->remote_sizes; memcpy(remote_sizes, opal_datatype_local_sizes, sizeof(size_t) * OPAL_DATATYPE_MAX_PREDEFINED); /** * If the local and remote architecture are the same there is no need * to check for the remote data sizes. They will always be the same as * the local ones. */ - if( master->remote_arch == opal_local_arch ) { + if (master->remote_arch == opal_local_arch) { master->pFunctions = opal_datatype_copy_functions; master->flags |= CONVERTOR_HOMOGENEOUS; return master; } /* Find out the remote bool size */ - if( opal_arch_checkmask( &master->remote_arch, OPAL_ARCH_BOOLIS8 ) ) { + if (opal_arch_checkmask(&master->remote_arch, OPAL_ARCH_BOOLIS8)) { remote_sizes[OPAL_DATATYPE_BOOL] = 1; - } else if( opal_arch_checkmask( &master->remote_arch, OPAL_ARCH_BOOLIS16 ) ) { + } else if (opal_arch_checkmask(&master->remote_arch, OPAL_ARCH_BOOLIS16)) { remote_sizes[OPAL_DATATYPE_BOOL] = 2; - } else if( opal_arch_checkmask( &master->remote_arch, OPAL_ARCH_BOOLIS32 ) ) { + } else if (opal_arch_checkmask(&master->remote_arch, OPAL_ARCH_BOOLIS32)) { remote_sizes[OPAL_DATATYPE_BOOL] = 4; } else { - opal_output( 0, "Unknown sizeof(bool) for the remote architecture\n" ); + opal_output(0, "Unknown sizeof(bool) for the remote architecture\n"); } /** @@ -147,67 +149,70 @@ opal_convertor_master_t* opal_convertor_find_or_create_master( uint32_t remote_a * 2 architectures don't have the same endianess all data with a length * over 2 bytes (with the exception of logicals) have to be byte-swapped. */ - for( i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) { - if( remote_sizes[i] != opal_datatype_local_sizes[i] ) - master->hetero_mask |= (((uint32_t)1) << i); + for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) { + if (remote_sizes[i] != opal_datatype_local_sizes[i]) { + master->hetero_mask |= (((uint32_t) 1) << i); + } } - if( opal_arch_checkmask( &master->remote_arch, OPAL_ARCH_ISBIGENDIAN ) != - opal_arch_checkmask( &opal_local_arch, OPAL_ARCH_ISBIGENDIAN ) ) { + if (opal_arch_checkmask(&master->remote_arch, OPAL_ARCH_ISBIGENDIAN) + != opal_arch_checkmask(&opal_local_arch, OPAL_ARCH_ISBIGENDIAN)) { uint32_t hetero_mask = 0; - for( i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) { - if( remote_sizes[i] > 1 ) - hetero_mask |= (((uint32_t)1) << i); + for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) { + if (remote_sizes[i] > 1) { + hetero_mask |= (((uint32_t) 1) << i); + } } - hetero_mask &= ~(((uint32_t)1) << OPAL_DATATYPE_BOOL); + hetero_mask &= ~(((uint32_t) 1) << OPAL_DATATYPE_BOOL); master->hetero_mask |= hetero_mask; } - master->pFunctions = (conversion_fct_t*)malloc( sizeof(opal_datatype_heterogeneous_copy_functions) ); + master->pFunctions = (conversion_fct_t *) malloc( + sizeof(opal_datatype_heterogeneous_copy_functions)); /** * Usually the heterogeneous functions are slower than the copy ones. Let's * try to minimize the usage of the heterogeneous versions. */ - for( i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) { - if( master->hetero_mask & (((uint32_t)1) << i) ) + for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) { + if (master->hetero_mask & (((uint32_t) 1) << i)) { master->pFunctions[i] = opal_datatype_heterogeneous_copy_functions[i]; - else + } else { master->pFunctions[i] = opal_datatype_copy_functions[i]; + } } /* We're done so far, return the mater convertor */ return master; } - -opal_convertor_t* opal_convertor_create( int32_t remote_arch, int32_t mode ) +opal_convertor_t *opal_convertor_create(int32_t remote_arch, int32_t mode) { - opal_convertor_t* convertor = OBJ_NEW(opal_convertor_t); - opal_convertor_master_t* master; + opal_convertor_t *convertor = OBJ_NEW(opal_convertor_t); + opal_convertor_master_t *master; - master = opal_convertor_find_or_create_master( remote_arch ); + master = opal_convertor_find_or_create_master(remote_arch); convertor->remoteArch = remote_arch; - convertor->stack_pos = 0; - convertor->flags = master->flags; - convertor->master = master; + convertor->stack_pos = 0; + convertor->flags = master->flags; + convertor->master = master; return convertor; } -#define OPAL_CONVERTOR_SET_STATUS_BEFORE_PACK_UNPACK( CONVERTOR, IOV, OUT, MAX_DATA ) \ - do { \ - /* protect against over packing data */ \ - if( OPAL_UNLIKELY((CONVERTOR)->flags & CONVERTOR_COMPLETED) ) { \ - (IOV)[0].iov_len = 0; \ - *(OUT) = 0; \ - *(MAX_DATA) = 0; \ - return 1; /* nothing to do */ \ - } \ - (CONVERTOR)->checksum = OPAL_CSUM_ZERO; \ - (CONVERTOR)->csum_ui1 = 0; \ - (CONVERTOR)->csum_ui2 = 0; \ - assert( (CONVERTOR)->bConverted < (CONVERTOR)->local_size ); \ - } while(0) +#define OPAL_CONVERTOR_SET_STATUS_BEFORE_PACK_UNPACK(CONVERTOR, IOV, OUT, MAX_DATA) \ + do { \ + /* protect against over packing data */ \ + if (OPAL_UNLIKELY((CONVERTOR)->flags & CONVERTOR_COMPLETED)) { \ + (IOV)[0].iov_len = 0; \ + *(OUT) = 0; \ + *(MAX_DATA) = 0; \ + return 1; /* nothing to do */ \ + } \ + (CONVERTOR)->checksum = OPAL_CSUM_ZERO; \ + (CONVERTOR)->csum_ui1 = 0; \ + (CONVERTOR)->csum_ui2 = 0; \ + assert((CONVERTOR)->bConverted < (CONVERTOR)->local_size); \ + } while (0) /** * Return 0 if everything went OK and if there is still room before the complete @@ -215,37 +220,37 @@ opal_convertor_t* opal_convertor_create( int32_t remote_arch, int32_t mode ) * 1 if everything went fine and the data was completly converted * -1 something wrong occurs. */ -int32_t opal_convertor_pack( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ) +int32_t opal_convertor_pack(opal_convertor_t *pConv, struct iovec *iov, uint32_t *out_size, + size_t *max_data) { - OPAL_CONVERTOR_SET_STATUS_BEFORE_PACK_UNPACK( pConv, iov, out_size, max_data ); + OPAL_CONVERTOR_SET_STATUS_BEFORE_PACK_UNPACK(pConv, iov, out_size, max_data); - if( OPAL_LIKELY(pConv->flags & CONVERTOR_NO_OP) ) { + if (OPAL_LIKELY(pConv->flags & CONVERTOR_NO_OP)) { /** * We are doing conversion on a contiguous datatype on a homogeneous * environment. The convertor contain minimal information, we only * use the bConverted to manage the conversion. */ uint32_t i; - unsigned char* base_pointer; + unsigned char *base_pointer; size_t pending_length = pConv->local_size - pConv->bConverted; *max_data = pending_length; - opal_convertor_get_current_pointer( pConv, (void**)&base_pointer ); + opal_convertor_get_current_pointer(pConv, (void **) &base_pointer); - for( i = 0; i < *out_size; i++ ) { - if( iov[i].iov_len >= pending_length ) { + for (i = 0; i < *out_size; i++) { + if (iov[i].iov_len >= pending_length) { goto complete_contiguous_data_pack; } - if( OPAL_LIKELY(NULL == iov[i].iov_base) ) + if (OPAL_LIKELY(NULL == iov[i].iov_base)) { iov[i].iov_base = (IOVBASE_TYPE *) base_pointer; - else + } else { #if OPAL_CUDA_SUPPORT - MEMCPY_CUDA( iov[i].iov_base, base_pointer, iov[i].iov_len, pConv ); + MEMCPY_CUDA(iov[i].iov_base, base_pointer, iov[i].iov_len, pConv); #else - MEMCPY( iov[i].iov_base, base_pointer, iov[i].iov_len ); + MEMCPY(iov[i].iov_base, base_pointer, iov[i].iov_len); #endif + } pending_length -= iov[i].iov_len; base_pointer += iov[i].iov_len; } @@ -253,53 +258,52 @@ int32_t opal_convertor_pack( opal_convertor_t* pConv, pConv->bConverted += (*max_data); return 0; -complete_contiguous_data_pack: + complete_contiguous_data_pack: iov[i].iov_len = pending_length; - if( OPAL_LIKELY(NULL == iov[i].iov_base) ) + if (OPAL_LIKELY(NULL == iov[i].iov_base)) { iov[i].iov_base = (IOVBASE_TYPE *) base_pointer; - else + } else { #if OPAL_CUDA_SUPPORT - MEMCPY_CUDA( iov[i].iov_base, base_pointer, iov[i].iov_len, pConv ); + MEMCPY_CUDA(iov[i].iov_base, base_pointer, iov[i].iov_len, pConv); #else - MEMCPY( iov[i].iov_base, base_pointer, iov[i].iov_len ); + MEMCPY(iov[i].iov_base, base_pointer, iov[i].iov_len); #endif + } pConv->bConverted = pConv->local_size; *out_size = i + 1; pConv->flags |= CONVERTOR_COMPLETED; return 1; } - return pConv->fAdvance( pConv, iov, out_size, max_data ); + return pConv->fAdvance(pConv, iov, out_size, max_data); } - -int32_t opal_convertor_unpack( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ) +int32_t opal_convertor_unpack(opal_convertor_t *pConv, struct iovec *iov, uint32_t *out_size, + size_t *max_data) { - OPAL_CONVERTOR_SET_STATUS_BEFORE_PACK_UNPACK( pConv, iov, out_size, max_data ); + OPAL_CONVERTOR_SET_STATUS_BEFORE_PACK_UNPACK(pConv, iov, out_size, max_data); - if( OPAL_LIKELY(pConv->flags & CONVERTOR_NO_OP) ) { + if (OPAL_LIKELY(pConv->flags & CONVERTOR_NO_OP)) { /** * We are doing conversion on a contiguous datatype on a homogeneous * environment. The convertor contain minimal informations, we only * use the bConverted to manage the conversion. */ uint32_t i; - unsigned char* base_pointer; + unsigned char *base_pointer; size_t pending_length = pConv->local_size - pConv->bConverted; *max_data = pending_length; - opal_convertor_get_current_pointer( pConv, (void**)&base_pointer ); + opal_convertor_get_current_pointer(pConv, (void **) &base_pointer); - for( i = 0; i < *out_size; i++ ) { - if( iov[i].iov_len >= pending_length ) { + for (i = 0; i < *out_size; i++) { + if (iov[i].iov_len >= pending_length) { goto complete_contiguous_data_unpack; } #if OPAL_CUDA_SUPPORT - MEMCPY_CUDA( base_pointer, iov[i].iov_base, iov[i].iov_len, pConv ); + MEMCPY_CUDA(base_pointer, iov[i].iov_base, iov[i].iov_len, pConv); #else - MEMCPY( base_pointer, iov[i].iov_base, iov[i].iov_len ); + MEMCPY(base_pointer, iov[i].iov_base, iov[i].iov_len); #endif pending_length -= iov[i].iov_len; base_pointer += iov[i].iov_len; @@ -308,12 +312,12 @@ int32_t opal_convertor_unpack( opal_convertor_t* pConv, pConv->bConverted += (*max_data); return 0; -complete_contiguous_data_unpack: + complete_contiguous_data_unpack: iov[i].iov_len = pending_length; #if OPAL_CUDA_SUPPORT - MEMCPY_CUDA( base_pointer, iov[i].iov_base, iov[i].iov_len, pConv ); + MEMCPY_CUDA(base_pointer, iov[i].iov_base, iov[i].iov_len, pConv); #else - MEMCPY( base_pointer, iov[i].iov_base, iov[i].iov_len ); + MEMCPY(base_pointer, iov[i].iov_base, iov[i].iov_len); #endif pConv->bConverted = pConv->local_size; *out_size = i + 1; @@ -321,16 +325,16 @@ int32_t opal_convertor_unpack( opal_convertor_t* pConv, return 1; } - return pConv->fAdvance( pConv, iov, out_size, max_data ); + return pConv->fAdvance(pConv, iov, out_size, max_data); } -static inline int -opal_convertor_create_stack_with_pos_contig( opal_convertor_t* pConvertor, - size_t starting_point, const size_t* sizes ) +static inline int opal_convertor_create_stack_with_pos_contig(opal_convertor_t *pConvertor, + size_t starting_point, + const size_t *sizes) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - const opal_datatype_t* pData = pConvertor->pDesc; - dt_elem_desc_t* pElems; + dt_stack_t *pStack; /* pointer to the position on the stack */ + const opal_datatype_t *pData = pConvertor->pDesc; + dt_elem_desc_t *pElems; size_t count; ptrdiff_t extent; @@ -344,10 +348,10 @@ opal_convertor_create_stack_with_pos_contig( opal_convertor_t* pConvertor, count = starting_point / pData->size; extent = pData->ub - pData->lb; - pStack[0].type = OPAL_DATATYPE_LOOP; /* the first one is always the loop */ - pStack[0].count = pConvertor->count - count; - pStack[0].index = -1; - pStack[0].disp = count * extent; + pStack[0].type = OPAL_DATATYPE_LOOP; /* the first one is always the loop */ + pStack[0].count = pConvertor->count - count; + pStack[0].index = -1; + pStack[0].disp = count * extent; /* now compute the number of pending bytes */ count = starting_point % pData->size; @@ -355,28 +359,27 @@ opal_convertor_create_stack_with_pos_contig( opal_convertor_t* pConvertor, * We save the current displacement starting from the begining * of this data. */ - if( OPAL_LIKELY(0 == count) ) { - pStack[1].type = pElems->elem.common.type; - pStack[1].count = pElems->elem.blocklen; + if (OPAL_LIKELY(0 == count)) { + pStack[1].type = pElems->elem.common.type; + pStack[1].count = pElems->elem.blocklen; } else { - pStack[1].type = OPAL_DATATYPE_UINT1; + pStack[1].type = OPAL_DATATYPE_UINT1; pStack[1].count = pData->size - count; } - pStack[1].disp = count; - pStack[1].index = 0; /* useless */ + pStack[1].disp = count; + pStack[1].index = 0; /* useless */ pConvertor->bConverted = starting_point; pConvertor->stack_pos = 1; - assert( 0 == pConvertor->partial_length ); + assert(0 == pConvertor->partial_length); return OPAL_SUCCESS; } -static inline int -opal_convertor_create_stack_at_begining( opal_convertor_t* convertor, - const size_t* sizes ) +static inline int opal_convertor_create_stack_at_begining(opal_convertor_t *convertor, + const size_t *sizes) { - dt_stack_t* pStack = convertor->pStack; - dt_elem_desc_t* pElems; + dt_stack_t *pStack = convertor->pStack; + dt_elem_desc_t *pElems; /** * The prepare function already make the selection on which data representation @@ -384,9 +387,9 @@ opal_convertor_create_stack_at_begining( opal_convertor_t* convertor, */ pElems = convertor->use_desc->desc; - convertor->stack_pos = 1; + convertor->stack_pos = 1; convertor->partial_length = 0; - convertor->bConverted = 0; + convertor->bConverted = 0; /** * Fill the first position on the stack. This one correspond to the * last fake OPAL_DATATYPE_END_LOOP that we add to the data representation and @@ -394,24 +397,22 @@ opal_convertor_create_stack_at_begining( opal_convertor_t* convertor, */ pStack[0].index = -1; pStack[0].count = convertor->count; - pStack[0].disp = 0; - pStack[0].type = OPAL_DATATYPE_LOOP; + pStack[0].disp = 0; + pStack[0].type = OPAL_DATATYPE_LOOP; pStack[1].index = 0; pStack[1].disp = 0; - if( pElems[0].elem.common.type == OPAL_DATATYPE_LOOP ) { + if (pElems[0].elem.common.type == OPAL_DATATYPE_LOOP) { pStack[1].count = pElems[0].loop.loops; - pStack[1].type = OPAL_DATATYPE_LOOP; + pStack[1].type = OPAL_DATATYPE_LOOP; } else { - pStack[1].count = (size_t)pElems[0].elem.count * pElems[0].elem.blocklen; - pStack[1].type = pElems[0].elem.common.type; + pStack[1].count = (size_t) pElems[0].elem.count * pElems[0].elem.blocklen; + pStack[1].type = pElems[0].elem.common.type; } return OPAL_SUCCESS; } - -int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor, - size_t* position ) +int32_t opal_convertor_set_position_nocheck(opal_convertor_t *convertor, size_t *position) { int32_t rc; @@ -421,15 +422,17 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor, * if we plan to rollback the convertor then first we have to reset it at * the beginning. */ - if( OPAL_LIKELY(convertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) { - rc = opal_convertor_create_stack_with_pos_contig( convertor, (*position), - opal_datatype_local_sizes ); + if (OPAL_LIKELY(convertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) { + rc = opal_convertor_create_stack_with_pos_contig(convertor, (*position), + opal_datatype_local_sizes); } else { - if( (0 == (*position)) || ((*position) < convertor->bConverted) ) { - rc = opal_convertor_create_stack_at_begining( convertor, opal_datatype_local_sizes ); - if( 0 == (*position) ) return rc; + if ((0 == (*position)) || ((*position) < convertor->bConverted)) { + rc = opal_convertor_create_stack_at_begining(convertor, opal_datatype_local_sizes); + if (0 == (*position)) { + return rc; + } } - rc = opal_convertor_generic_simple_position( convertor, position ); + rc = opal_convertor_generic_simple_position(convertor, position); /** * If we have a non-contigous send convertor don't allow it move in the middle * of a predefined datatype, it won't be able to copy out the left-overs @@ -437,7 +440,7 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor, * boundaries. As we allow partial predefined datatypes on the contiguous * case, we should be accepted by any receiver convertor. */ - if( CONVERTOR_SEND & convertor->flags ) { + if (CONVERTOR_SEND & convertor->flags) { convertor->bConverted -= convertor->partial_length; convertor->partial_length = 0; } @@ -446,9 +449,7 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor, return rc; } -static size_t -opal_datatype_compute_remote_size( const opal_datatype_t* pData, - const size_t* sizes ) +static size_t opal_datatype_compute_remote_size(const opal_datatype_t *pData, const size_t *sizes) { uint32_t typeMask = pData->bdt_used; size_t length = 0; @@ -457,15 +458,15 @@ opal_datatype_compute_remote_size( const opal_datatype_t* pData, return sizes[pData->desc.desc->elem.common.type]; } - if( OPAL_UNLIKELY(NULL == pData->ptypes) ) { + if (OPAL_UNLIKELY(NULL == pData->ptypes)) { /* Allocate and fill the array of types used in the datatype description */ - opal_datatype_compute_ptypes( (opal_datatype_t*)pData ); + opal_datatype_compute_ptypes((opal_datatype_t *) pData); } - for( int i = OPAL_DATATYPE_FIRST_TYPE; typeMask && (i < OPAL_DATATYPE_MAX_PREDEFINED); i++ ) { - if( typeMask & ((uint32_t)1 << i) ) { + for (int i = OPAL_DATATYPE_FIRST_TYPE; typeMask && (i < OPAL_DATATYPE_MAX_PREDEFINED); i++) { + if (typeMask & ((uint32_t) 1 << i)) { length += (pData->ptypes[i] * sizes[i]); - typeMask ^= ((uint32_t)1 << i); + typeMask ^= ((uint32_t) 1 << i); } } return length; @@ -476,20 +477,22 @@ opal_datatype_compute_remote_size( const opal_datatype_t* pData, * and redirect the convertor description toward the non-optimized * datatype representation. */ -size_t opal_convertor_compute_remote_size( opal_convertor_t* pConvertor ) +size_t opal_convertor_compute_remote_size(opal_convertor_t *pConvertor) { - opal_datatype_t* datatype = (opal_datatype_t*)pConvertor->pDesc; - + opal_datatype_t *datatype = (opal_datatype_t *) pConvertor->pDesc; + pConvertor->remote_size = pConvertor->local_size; - if( OPAL_UNLIKELY(datatype->bdt_used & pConvertor->master->hetero_mask) ) { + if (OPAL_UNLIKELY(datatype->bdt_used & pConvertor->master->hetero_mask)) { pConvertor->flags &= (~CONVERTOR_HOMOGENEOUS); - if (!(pConvertor->flags & CONVERTOR_SEND && pConvertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) { + if (!(pConvertor->flags & CONVERTOR_SEND + && pConvertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) { pConvertor->use_desc = &(datatype->desc); } - if( 0 == (pConvertor->flags & CONVERTOR_HAS_REMOTE_SIZE) ) { + if (0 == (pConvertor->flags & CONVERTOR_HAS_REMOTE_SIZE)) { /* This is for a single datatype, we must update it with the count */ pConvertor->remote_size = opal_datatype_compute_remote_size(datatype, - pConvertor->master->remote_sizes); + pConvertor->master + ->remote_sizes); pConvertor->remote_size *= pConvertor->count; } } @@ -504,151 +507,158 @@ size_t opal_convertor_compute_remote_size( opal_convertor_t* pConvertor ) * here that the convertor is clean, either never initialized or already * cleaned. */ -#define OPAL_CONVERTOR_PREPARE( convertor, datatype, count, pUserBuf ) \ - { \ - convertor->local_size = count * datatype->size; \ - convertor->pBaseBuf = (unsigned char*)pUserBuf; \ - convertor->count = count; \ - convertor->pDesc = (opal_datatype_t*)datatype; \ - convertor->bConverted = 0; \ - convertor->use_desc = &(datatype->opt_desc); \ - /* If the data is empty we just mark the convertor as \ - * completed. With this flag set the pack and unpack functions \ - * will not do anything. \ - */ \ - if( OPAL_UNLIKELY((0 == count) || (0 == datatype->size)) ) { \ - convertor->flags |= (OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED | CONVERTOR_HAS_REMOTE_SIZE); \ - convertor->local_size = convertor->remote_size = 0; \ - return OPAL_SUCCESS; \ - } \ - \ - /* Grab the datatype part of the flags */ \ - convertor->flags &= CONVERTOR_TYPE_MASK; \ - convertor->flags |= (CONVERTOR_DATATYPE_MASK & datatype->flags); \ - convertor->flags |= (CONVERTOR_NO_OP | CONVERTOR_HOMOGENEOUS); \ - \ - convertor->remote_size = convertor->local_size; \ - if( OPAL_LIKELY(convertor->remoteArch == opal_local_arch) ) { \ - if( !(convertor->flags & CONVERTOR_WITH_CHECKSUM) && \ - ((convertor->flags & OPAL_DATATYPE_FLAG_NO_GAPS) || \ - ((convertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) && (1 == count))) ) { \ - return OPAL_SUCCESS; \ - } \ - } \ - \ - assert( (convertor)->pDesc == (datatype) ); \ - opal_convertor_compute_remote_size( convertor ); \ - assert( NULL != convertor->use_desc->desc ); \ - /* For predefined datatypes (contiguous) do nothing more */ \ - /* if checksum is enabled then always continue */ \ - if( ((convertor->flags & (CONVERTOR_WITH_CHECKSUM | OPAL_DATATYPE_FLAG_NO_GAPS)) \ - == OPAL_DATATYPE_FLAG_NO_GAPS) && \ - ((convertor->flags & (CONVERTOR_SEND | CONVERTOR_HOMOGENEOUS)) == \ - (CONVERTOR_SEND | CONVERTOR_HOMOGENEOUS)) ) { \ - return OPAL_SUCCESS; \ - } \ - convertor->flags &= ~CONVERTOR_NO_OP; \ - { \ - uint32_t required_stack_length = datatype->loops + 1; \ - \ - if( required_stack_length > convertor->stack_size ) { \ - assert(convertor->pStack == convertor->static_stack); \ - convertor->stack_size = required_stack_length; \ - convertor->pStack = (dt_stack_t*)malloc(sizeof(dt_stack_t) * \ - convertor->stack_size ); \ - } \ - } \ - opal_convertor_create_stack_at_begining( convertor, opal_datatype_local_sizes ); \ - } - - -int32_t opal_convertor_prepare_for_recv( opal_convertor_t* convertor, - const struct opal_datatype_t* datatype, - size_t count, - const void* pUserBuf ) +#define OPAL_CONVERTOR_PREPARE(convertor, datatype, count, pUserBuf) \ + { \ + convertor->local_size = count * datatype->size; \ + convertor->pBaseBuf = (unsigned char *) pUserBuf; \ + convertor->count = count; \ + convertor->pDesc = (opal_datatype_t *) datatype; \ + convertor->bConverted = 0; \ + convertor->use_desc = &(datatype->opt_desc); \ + /* If the data is empty we just mark the convertor as \ + * completed. With this flag set the pack and unpack functions \ + * will not do anything. \ + */ \ + if (OPAL_UNLIKELY((0 == count) || (0 == datatype->size))) { \ + convertor->flags |= (OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED \ + | CONVERTOR_HAS_REMOTE_SIZE); \ + convertor->local_size = convertor->remote_size = 0; \ + return OPAL_SUCCESS; \ + } \ + \ + /* Grab the datatype part of the flags */ \ + convertor->flags &= CONVERTOR_TYPE_MASK; \ + convertor->flags |= (CONVERTOR_DATATYPE_MASK & datatype->flags); \ + convertor->flags |= (CONVERTOR_NO_OP | CONVERTOR_HOMOGENEOUS); \ + \ + convertor->remote_size = convertor->local_size; \ + if (OPAL_LIKELY(convertor->remoteArch == opal_local_arch)) { \ + if (!(convertor->flags & CONVERTOR_WITH_CHECKSUM) \ + && ((convertor->flags & OPAL_DATATYPE_FLAG_NO_GAPS) \ + || ((convertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) && (1 == count)))) { \ + return OPAL_SUCCESS; \ + } \ + } \ + \ + assert((convertor)->pDesc == (datatype)); \ + opal_convertor_compute_remote_size(convertor); \ + assert(NULL != convertor->use_desc->desc); \ + /* For predefined datatypes (contiguous) do nothing more */ \ + /* if checksum is enabled then always continue */ \ + if (((convertor->flags & (CONVERTOR_WITH_CHECKSUM | OPAL_DATATYPE_FLAG_NO_GAPS)) \ + == OPAL_DATATYPE_FLAG_NO_GAPS) \ + && ((convertor->flags & (CONVERTOR_SEND | CONVERTOR_HOMOGENEOUS)) \ + == (CONVERTOR_SEND | CONVERTOR_HOMOGENEOUS))) { \ + return OPAL_SUCCESS; \ + } \ + convertor->flags &= ~CONVERTOR_NO_OP; \ + { \ + uint32_t required_stack_length = datatype->loops + 1; \ + \ + if (required_stack_length > convertor->stack_size) { \ + assert(convertor->pStack == convertor->static_stack); \ + convertor->stack_size = required_stack_length; \ + convertor->pStack = (dt_stack_t *) malloc(sizeof(dt_stack_t) \ + * convertor->stack_size); \ + } \ + } \ + opal_convertor_create_stack_at_begining(convertor, opal_datatype_local_sizes); \ + } + +int32_t opal_convertor_prepare_for_recv(opal_convertor_t *convertor, + const struct opal_datatype_t *datatype, size_t count, + const void *pUserBuf) { /* Here I should check that the data is not overlapping */ convertor->flags |= CONVERTOR_RECV; #if OPAL_CUDA_SUPPORT - if (!( convertor->flags & CONVERTOR_SKIP_CUDA_INIT )) { + if (!(convertor->flags & CONVERTOR_SKIP_CUDA_INIT)) { mca_cuda_convertor_init(convertor, pUserBuf); } #endif - assert(! (convertor->flags & CONVERTOR_SEND)); - OPAL_CONVERTOR_PREPARE( convertor, datatype, count, pUserBuf ); + assert(!(convertor->flags & CONVERTOR_SEND)); + OPAL_CONVERTOR_PREPARE(convertor, datatype, count, pUserBuf); #if defined(CHECKSUM) - if( OPAL_UNLIKELY(convertor->flags & CONVERTOR_WITH_CHECKSUM) ) { - if( OPAL_UNLIKELY(!(convertor->flags & CONVERTOR_HOMOGENEOUS)) ) { + if (OPAL_UNLIKELY(convertor->flags & CONVERTOR_WITH_CHECKSUM)) { + if (OPAL_UNLIKELY(!(convertor->flags & CONVERTOR_HOMOGENEOUS))) { convertor->fAdvance = opal_unpack_general_checksum; } else { - if( convertor->pDesc->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { + if (convertor->pDesc->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { convertor->fAdvance = opal_unpack_homogeneous_contig_checksum; } else { convertor->fAdvance = opal_generic_simple_unpack_checksum; } } - } else -#endif /* defined(CHECKSUM) */ - if( OPAL_UNLIKELY(!(convertor->flags & CONVERTOR_HOMOGENEOUS)) ) { + } else { +#endif /* defined(CHECKSUM) */ + if (OPAL_UNLIKELY(!(convertor->flags & CONVERTOR_HOMOGENEOUS))) { convertor->fAdvance = opal_unpack_general; } else { - if( convertor->pDesc->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { + if (convertor->pDesc->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { convertor->fAdvance = opal_unpack_homogeneous_contig; } else { convertor->fAdvance = opal_generic_simple_unpack; } } +#if defined(CHECKSUM) + } +#endif return OPAL_SUCCESS; } - -int32_t opal_convertor_prepare_for_send( opal_convertor_t* convertor, - const struct opal_datatype_t* datatype, - size_t count, - const void* pUserBuf ) +int32_t opal_convertor_prepare_for_send(opal_convertor_t *convertor, + const struct opal_datatype_t *datatype, size_t count, + const void *pUserBuf) { convertor->flags |= CONVERTOR_SEND; #if OPAL_CUDA_SUPPORT - if (!( convertor->flags & CONVERTOR_SKIP_CUDA_INIT )) { + if (!(convertor->flags & CONVERTOR_SKIP_CUDA_INIT)) { mca_cuda_convertor_init(convertor, pUserBuf); } #endif - OPAL_CONVERTOR_PREPARE( convertor, datatype, count, pUserBuf ); + OPAL_CONVERTOR_PREPARE(convertor, datatype, count, pUserBuf); #if defined(CHECKSUM) - if( convertor->flags & CONVERTOR_WITH_CHECKSUM ) { - if( CONVERTOR_SEND_CONVERSION == (convertor->flags & (CONVERTOR_SEND_CONVERSION|CONVERTOR_HOMOGENEOUS)) ) { + if (convertor->flags & CONVERTOR_WITH_CHECKSUM) { + if (CONVERTOR_SEND_CONVERSION + == (convertor->flags & (CONVERTOR_SEND_CONVERSION | CONVERTOR_HOMOGENEOUS))) { convertor->fAdvance = opal_pack_general_checksum; } else { - if( datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { - if( ((datatype->ub - datatype->lb) == (ptrdiff_t)datatype->size) - || (1 >= convertor->count) ) + if (datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + if (((datatype->ub - datatype->lb) == (ptrdiff_t) datatype->size) + || (1 >= convertor->count)) { convertor->fAdvance = opal_pack_homogeneous_contig_checksum; - else + } else { convertor->fAdvance = opal_pack_homogeneous_contig_with_gaps_checksum; + } } else { convertor->fAdvance = opal_generic_simple_pack_checksum; } } - } else -#endif /* defined(CHECKSUM) */ - if( CONVERTOR_SEND_CONVERSION == (convertor->flags & (CONVERTOR_SEND_CONVERSION|CONVERTOR_HOMOGENEOUS)) ) { + } else { +#endif /* defined(CHECKSUM) */ + if (CONVERTOR_SEND_CONVERSION + == (convertor->flags & (CONVERTOR_SEND_CONVERSION | CONVERTOR_HOMOGENEOUS))) { convertor->fAdvance = opal_pack_general; } else { - if( datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { - if( ((datatype->ub - datatype->lb) == (ptrdiff_t)datatype->size) - || (1 >= convertor->count) ) + if (datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + if (((datatype->ub - datatype->lb) == (ptrdiff_t) datatype->size) + || (1 >= convertor->count)) { convertor->fAdvance = opal_pack_homogeneous_contig; - else + } else { convertor->fAdvance = opal_pack_homogeneous_contig_with_gaps; + } } else { convertor->fAdvance = opal_generic_simple_pack; } } +#if defined(CHECKSUM) + } +#endif return OPAL_SUCCESS; } @@ -662,90 +672,109 @@ int32_t opal_convertor_prepare_for_send( opal_convertor_t* convertor, * ready to use starting from the old position. If copy_stack is false then the convertor * is created with a empty stack (you have to use opal_convertor_set_position before using it). */ -int opal_convertor_clone( const opal_convertor_t* source, - opal_convertor_t* destination, - int32_t copy_stack ) +int opal_convertor_clone(const opal_convertor_t *source, opal_convertor_t *destination, + int32_t copy_stack) { - destination->remoteArch = source->remoteArch; - destination->flags = source->flags; - destination->pDesc = source->pDesc; - destination->use_desc = source->use_desc; - destination->count = source->count; - destination->pBaseBuf = source->pBaseBuf; - destination->fAdvance = source->fAdvance; - destination->master = source->master; - destination->local_size = source->local_size; - destination->remote_size = source->remote_size; + destination->remoteArch = source->remoteArch; + destination->flags = source->flags; + destination->pDesc = source->pDesc; + destination->use_desc = source->use_desc; + destination->count = source->count; + destination->pBaseBuf = source->pBaseBuf; + destination->fAdvance = source->fAdvance; + destination->master = source->master; + destination->local_size = source->local_size; + destination->remote_size = source->remote_size; /* create the stack */ - if( OPAL_UNLIKELY(source->stack_size > DT_STATIC_STACK_SIZE) ) { - destination->pStack = (dt_stack_t*)malloc(sizeof(dt_stack_t) * source->stack_size ); + if (OPAL_UNLIKELY(source->stack_size > DT_STATIC_STACK_SIZE)) { + destination->pStack = (dt_stack_t *) malloc(sizeof(dt_stack_t) * source->stack_size); } else { destination->pStack = destination->static_stack; } destination->stack_size = source->stack_size; /* initialize the stack */ - if( OPAL_LIKELY(0 == copy_stack) ) { + if (OPAL_LIKELY(0 == copy_stack)) { destination->bConverted = -1; - destination->stack_pos = -1; + destination->stack_pos = -1; } else { - memcpy( destination->pStack, source->pStack, sizeof(dt_stack_t) * (source->stack_pos+1) ); + memcpy(destination->pStack, source->pStack, sizeof(dt_stack_t) * (source->stack_pos + 1)); destination->bConverted = source->bConverted; - destination->stack_pos = source->stack_pos; + destination->stack_pos = source->stack_pos; } #if OPAL_CUDA_SUPPORT - destination->cbmemcpy = source->cbmemcpy; + destination->cbmemcpy = source->cbmemcpy; #endif return OPAL_SUCCESS; } - -void opal_convertor_dump( opal_convertor_t* convertor ) +void opal_convertor_dump(opal_convertor_t *convertor) { - opal_output( 0, "Convertor %p count %" PRIsize_t " stack position %u bConverted %" PRIsize_t "\n" - "\tlocal_size %" PRIsize_t " remote_size %" PRIsize_t " flags %X stack_size %u pending_length %" PRIsize_t "\n" - "\tremote_arch %u local_arch %u\n", - (void*)convertor, - convertor->count, convertor->stack_pos, convertor->bConverted, - convertor->local_size, convertor->remote_size, - convertor->flags, convertor->stack_size, convertor->partial_length, - convertor->remoteArch, opal_local_arch ); - if( convertor->flags & CONVERTOR_RECV ) opal_output( 0, "unpack "); - if( convertor->flags & CONVERTOR_SEND ) opal_output( 0, "pack "); - if( convertor->flags & CONVERTOR_SEND_CONVERSION ) opal_output( 0, "conversion "); - if( convertor->flags & CONVERTOR_HOMOGENEOUS ) opal_output( 0, "homogeneous " ); - else opal_output( 0, "heterogeneous "); - if( convertor->flags & CONVERTOR_NO_OP ) opal_output( 0, "no_op "); - if( convertor->flags & CONVERTOR_WITH_CHECKSUM ) opal_output( 0, "checksum "); - if( convertor->flags & CONVERTOR_CUDA ) opal_output( 0, "CUDA "); - if( convertor->flags & CONVERTOR_CUDA_ASYNC ) opal_output( 0, "CUDA Async "); - if( convertor->flags & CONVERTOR_COMPLETED ) opal_output( 0, "COMPLETED "); - - opal_datatype_dump( convertor->pDesc ); - if( !((0 == convertor->stack_pos) && - ((size_t)convertor->pStack[convertor->stack_pos].index > convertor->pDesc->desc.length)) ) { + opal_output(0, + "Convertor %p count %" PRIsize_t " stack position %u bConverted %" PRIsize_t "\n" + "\tlocal_size %" PRIsize_t " remote_size %" PRIsize_t + " flags %X stack_size %u pending_length %" PRIsize_t "\n" + "\tremote_arch %u local_arch %u\n", + (void *) convertor, convertor->count, convertor->stack_pos, convertor->bConverted, + convertor->local_size, convertor->remote_size, convertor->flags, + convertor->stack_size, convertor->partial_length, convertor->remoteArch, + opal_local_arch); + if (convertor->flags & CONVERTOR_RECV) { + opal_output(0, "unpack "); + } + if (convertor->flags & CONVERTOR_SEND) { + opal_output(0, "pack "); + } + if (convertor->flags & CONVERTOR_SEND_CONVERSION) { + opal_output(0, "conversion "); + } + if (convertor->flags & CONVERTOR_HOMOGENEOUS) { + opal_output(0, "homogeneous "); + } else { + opal_output(0, "heterogeneous "); + } + if (convertor->flags & CONVERTOR_NO_OP) { + opal_output(0, "no_op "); + } + if (convertor->flags & CONVERTOR_WITH_CHECKSUM) { + opal_output(0, "checksum "); + } + if (convertor->flags & CONVERTOR_CUDA) { + opal_output(0, "CUDA "); + } + if (convertor->flags & CONVERTOR_CUDA_ASYNC) { + opal_output(0, "CUDA Async "); + } + if (convertor->flags & CONVERTOR_COMPLETED) { + opal_output(0, "COMPLETED "); + } + + opal_datatype_dump(convertor->pDesc); + if (!((0 == convertor->stack_pos) + && ((size_t) convertor->pStack[convertor->stack_pos].index + > convertor->pDesc->desc.length))) { /* only if the convertor is completely initialized */ - opal_output( 0, "Actual stack representation\n" ); - opal_datatype_dump_stack( convertor->pStack, convertor->stack_pos, - convertor->pDesc->desc.desc, convertor->pDesc->name ); + opal_output(0, "Actual stack representation\n"); + opal_datatype_dump_stack(convertor->pStack, convertor->stack_pos, + convertor->pDesc->desc.desc, convertor->pDesc->name); } } - -void opal_datatype_dump_stack( const dt_stack_t* pStack, int stack_pos, - const union dt_elem_desc* pDesc, const char* name ) +void opal_datatype_dump_stack(const dt_stack_t *pStack, int stack_pos, + const union dt_elem_desc *pDesc, const char *name) { - opal_output( 0, "\nStack %p stack_pos %d name %s\n", (void*)pStack, stack_pos, name ); - for( ; stack_pos >= 0; stack_pos-- ) { - opal_output( 0, "%d: pos %d count %" PRIsize_t " disp %ld ", stack_pos, pStack[stack_pos].index, - pStack[stack_pos].count, pStack[stack_pos].disp ); - if( pStack->index != -1 ) - opal_output( 0, "\t[desc count %lu disp %ld extent %ld]\n", - (unsigned long)pDesc[pStack[stack_pos].index].elem.count, - (long)pDesc[pStack[stack_pos].index].elem.disp, - (long)pDesc[pStack[stack_pos].index].elem.extent ); - else - opal_output( 0, "\n" ); - } - opal_output( 0, "\n" ); + opal_output(0, "\nStack %p stack_pos %d name %s\n", (void *) pStack, stack_pos, name); + for (; stack_pos >= 0; stack_pos--) { + opal_output(0, "%d: pos %d count %" PRIsize_t " disp %ld ", stack_pos, + pStack[stack_pos].index, pStack[stack_pos].count, pStack[stack_pos].disp); + if (pStack->index != -1) { + opal_output(0, "\t[desc count %lu disp %ld extent %ld]\n", + (unsigned long) pDesc[pStack[stack_pos].index].elem.count, + (long) pDesc[pStack[stack_pos].index].elem.disp, + (long) pDesc[pStack[stack_pos].index].elem.extent); + } else { + opal_output(0, "\n"); + } + } + opal_output(0, "\n"); } diff --git a/opal/datatype/opal_convertor.h b/opal/datatype/opal_convertor.h index b24d94c37b0..05cc2b2ec67 100644 --- a/opal/datatype/opal_convertor.h +++ b/opal/datatype/opal_convertor.h @@ -28,7 +28,7 @@ #include "opal_config.h" #ifdef HAVE_SYS_UIO_H -#include +# include #endif #include "opal/constants.h" @@ -40,117 +40,112 @@ BEGIN_C_DECLS * CONVERTOR SECTION */ /* keep the last 16 bits free for data flags */ -#define CONVERTOR_DATATYPE_MASK 0x0000FFFF -#define CONVERTOR_SEND_CONVERSION 0x00010000 -#define CONVERTOR_RECV 0x00020000 -#define CONVERTOR_SEND 0x00040000 -#define CONVERTOR_HOMOGENEOUS 0x00080000 -#define CONVERTOR_NO_OP 0x00100000 -#define CONVERTOR_WITH_CHECKSUM 0x00200000 -#define CONVERTOR_CUDA 0x00400000 -#define CONVERTOR_CUDA_ASYNC 0x00800000 -#define CONVERTOR_TYPE_MASK 0x10FF0000 -#define CONVERTOR_STATE_START 0x01000000 -#define CONVERTOR_STATE_COMPLETE 0x02000000 -#define CONVERTOR_STATE_ALLOC 0x04000000 -#define CONVERTOR_COMPLETED 0x08000000 -#define CONVERTOR_CUDA_UNIFIED 0x10000000 -#define CONVERTOR_HAS_REMOTE_SIZE 0x20000000 -#define CONVERTOR_SKIP_CUDA_INIT 0x40000000 +#define CONVERTOR_DATATYPE_MASK 0x0000FFFF +#define CONVERTOR_SEND_CONVERSION 0x00010000 +#define CONVERTOR_RECV 0x00020000 +#define CONVERTOR_SEND 0x00040000 +#define CONVERTOR_HOMOGENEOUS 0x00080000 +#define CONVERTOR_NO_OP 0x00100000 +#define CONVERTOR_WITH_CHECKSUM 0x00200000 +#define CONVERTOR_CUDA 0x00400000 +#define CONVERTOR_CUDA_ASYNC 0x00800000 +#define CONVERTOR_TYPE_MASK 0x10FF0000 +#define CONVERTOR_STATE_START 0x01000000 +#define CONVERTOR_STATE_COMPLETE 0x02000000 +#define CONVERTOR_STATE_ALLOC 0x04000000 +#define CONVERTOR_COMPLETED 0x08000000 +#define CONVERTOR_CUDA_UNIFIED 0x10000000 +#define CONVERTOR_HAS_REMOTE_SIZE 0x20000000 +#define CONVERTOR_SKIP_CUDA_INIT 0x40000000 union dt_elem_desc; typedef struct opal_convertor_t opal_convertor_t; -typedef int32_t (*convertor_advance_fct_t)( opal_convertor_t* pConvertor, - struct iovec* iov, - uint32_t* out_size, - size_t* max_data ); -typedef void*(*memalloc_fct_t)( size_t* pLength, void* userdata ); -typedef void*(*memcpy_fct_t)( void* dest, const void* src, size_t n, opal_convertor_t* pConvertor ); +typedef int32_t (*convertor_advance_fct_t)(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +typedef void *(*memalloc_fct_t)(size_t *pLength, void *userdata); +typedef void *(*memcpy_fct_t)(void *dest, const void *src, size_t n, opal_convertor_t *pConvertor); /* The master convertor struct (defined in convertor_internal.h) */ struct opal_convertor_master_t; struct dt_stack_t { - int32_t index; /**< index in the element description */ - int16_t type; /**< the type used for the last pack/unpack (original or OPAL_DATATYPE_UINT1) */ - int16_t padding; - size_t count; /**< number of times we still have to do it */ - ptrdiff_t disp; /**< actual displacement depending on the count field */ + int32_t index; /**< index in the element description */ + int16_t type; /**< the type used for the last pack/unpack (original or OPAL_DATATYPE_UINT1) */ + int16_t padding; + size_t count; /**< number of times we still have to do it */ + ptrdiff_t disp; /**< actual displacement depending on the count field */ }; typedef struct dt_stack_t dt_stack_t; /** * */ -#define DT_STATIC_STACK_SIZE 5 /**< This should be sufficient for most applications */ +#define DT_STATIC_STACK_SIZE 5 /**< This should be sufficient for most applications */ struct opal_convertor_t { - opal_object_t super; /**< basic superclass */ - uint32_t remoteArch; /**< the remote architecture */ - uint32_t flags; /**< the properties of this convertor */ - size_t local_size; /**< overall length data on local machine, compared to bConverted */ - size_t remote_size; /**< overall length data on remote machine, compared to bConverted */ - const opal_datatype_t* pDesc; /**< the datatype description associated with the convertor */ - const dt_type_desc_t* use_desc; /**< the version used by the convertor (normal or optimized) */ - opal_datatype_count_t count; /**< the total number of full datatype elements */ + opal_object_t super; /**< basic superclass */ + uint32_t remoteArch; /**< the remote architecture */ + uint32_t flags; /**< the properties of this convertor */ + size_t local_size; /**< overall length data on local machine, compared to bConverted */ + size_t remote_size; /**< overall length data on remote machine, compared to bConverted */ + const opal_datatype_t *pDesc; /**< the datatype description associated with the convertor */ + const dt_type_desc_t *use_desc; /**< the version used by the convertor (normal or optimized) */ + opal_datatype_count_t count; /**< the total number of full datatype elements */ /* --- cacheline boundary (64 bytes - if 64bits arch and !OPAL_ENABLE_DEBUG) --- */ - uint32_t stack_size; /**< size of the allocated stack */ - unsigned char* pBaseBuf; /**< initial buffer as supplied by the user */ - dt_stack_t* pStack; /**< the local stack for the actual conversion */ - convertor_advance_fct_t fAdvance; /**< pointer to the pack/unpack functions */ + uint32_t stack_size; /**< size of the allocated stack */ + unsigned char *pBaseBuf; /**< initial buffer as supplied by the user */ + dt_stack_t *pStack; /**< the local stack for the actual conversion */ + convertor_advance_fct_t fAdvance; /**< pointer to the pack/unpack functions */ /* --- cacheline boundary (96 bytes - if 64bits arch and !OPAL_ENABLE_DEBUG) --- */ - struct opal_convertor_master_t* master; /**< the master convertor */ + struct opal_convertor_master_t *master; /**< the master convertor */ /* All others fields get modified for every call to pack/unpack functions */ - uint32_t stack_pos; /**< the actual position on the stack */ - size_t partial_length; /**< amount of data left over from the last unpack */ - size_t bConverted; /**< # of bytes already converted */ + uint32_t stack_pos; /**< the actual position on the stack */ + size_t partial_length; /**< amount of data left over from the last unpack */ + size_t bConverted; /**< # of bytes already converted */ /* --- cacheline boundary (128 bytes - if 64bits arch and !OPAL_ENABLE_DEBUG) --- */ - uint32_t checksum; /**< checksum computed by pack/unpack operation */ - uint32_t csum_ui1; /**< partial checksum computed by pack/unpack operation */ - size_t csum_ui2; /**< partial checksum computed by pack/unpack operation */ + uint32_t checksum; /**< checksum computed by pack/unpack operation */ + uint32_t csum_ui1; /**< partial checksum computed by pack/unpack operation */ + size_t csum_ui2; /**< partial checksum computed by pack/unpack operation */ /* --- fields are no more aligned on cacheline --- */ - dt_stack_t static_stack[DT_STATIC_STACK_SIZE]; /**< local stack for small datatypes */ + dt_stack_t static_stack[DT_STATIC_STACK_SIZE]; /**< local stack for small datatypes */ #if OPAL_CUDA_SUPPORT - memcpy_fct_t cbmemcpy; /**< memcpy or cuMemcpy */ - void * stream; /**< CUstream for async copy */ + memcpy_fct_t cbmemcpy; /**< memcpy or cuMemcpy */ + void *stream; /**< CUstream for async copy */ #endif }; -OPAL_DECLSPEC OBJ_CLASS_DECLARATION( opal_convertor_t ); - +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_convertor_t); /* * */ -static inline uint32_t opal_convertor_get_checksum( opal_convertor_t* convertor ) +static inline uint32_t opal_convertor_get_checksum(opal_convertor_t *convertor) { return convertor->checksum; } - /* * */ -OPAL_DECLSPEC int32_t opal_convertor_pack( opal_convertor_t* pConv, struct iovec* iov, - uint32_t* out_size, size_t* max_data ); +OPAL_DECLSPEC int32_t opal_convertor_pack(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); /* * */ -OPAL_DECLSPEC int32_t opal_convertor_unpack( opal_convertor_t* pConv, struct iovec* iov, - uint32_t* out_size, size_t* max_data ); +OPAL_DECLSPEC int32_t opal_convertor_unpack(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); /* * */ -OPAL_DECLSPEC opal_convertor_t* opal_convertor_create( int32_t remote_arch, int32_t mode ); - +OPAL_DECLSPEC opal_convertor_t *opal_convertor_create(int32_t remote_arch, int32_t mode); /** * The cleanup function will put the convertor in exactly the same state as after a call @@ -159,21 +154,20 @@ OPAL_DECLSPEC opal_convertor_t* opal_convertor_create( int32_t remote_arch, int3 * cache. The OBJ_CONSTRUCT on the convertor should be called only on the first creation * of a request (not when extracted from the cache). */ -static inline int opal_convertor_cleanup( opal_convertor_t* convertor ) +static inline int opal_convertor_cleanup(opal_convertor_t *convertor) { - if( OPAL_UNLIKELY(convertor->stack_size > DT_STATIC_STACK_SIZE) ) { - free( convertor->pStack ); - convertor->pStack = convertor->static_stack; + if (OPAL_UNLIKELY(convertor->stack_size > DT_STATIC_STACK_SIZE)) { + free(convertor->pStack); + convertor->pStack = convertor->static_stack; convertor->stack_size = DT_STATIC_STACK_SIZE; } - convertor->pDesc = NULL; + convertor->pDesc = NULL; convertor->stack_pos = 0; - convertor->flags = OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED; + convertor->flags = OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED; return OPAL_SUCCESS; } - /** * Return: 0 if no packing is required for sending (the upper layer * can use directly the pointer to the contiguous user @@ -182,14 +176,18 @@ static inline int opal_convertor_cleanup( opal_convertor_t* convertor ) * (source arch != dest arch) or non contiguous memory * layout. */ -static inline int32_t opal_convertor_need_buffers( const opal_convertor_t* pConvertor ) +static inline int32_t opal_convertor_need_buffers(const opal_convertor_t *pConvertor) { - if (OPAL_UNLIKELY(0 == (pConvertor->flags & CONVERTOR_HOMOGENEOUS))) return 1; + if (OPAL_UNLIKELY(0 == (pConvertor->flags & CONVERTOR_HOMOGENEOUS))) + return 1; #if OPAL_CUDA_SUPPORT - if( pConvertor->flags & (CONVERTOR_CUDA | CONVERTOR_CUDA_UNIFIED)) return 1; + if (pConvertor->flags & (CONVERTOR_CUDA | CONVERTOR_CUDA_UNIFIED)) + return 1; #endif - if( pConvertor->flags & OPAL_DATATYPE_FLAG_NO_GAPS ) return 0; - if( (pConvertor->count == 1) && (pConvertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) return 0; + if (pConvertor->flags & OPAL_DATATYPE_FLAG_NO_GAPS) + return 0; + if ((pConvertor->count == 1) && (pConvertor->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) + return 0; return 1; } @@ -198,34 +196,30 @@ static inline int32_t opal_convertor_need_buffers( const opal_convertor_t* pConv * depend on the configuration of the master convertor. In homogeneous * environments, the local and remote sizes are identical. */ -size_t -opal_convertor_compute_remote_size( opal_convertor_t* pConv ); +size_t opal_convertor_compute_remote_size(opal_convertor_t *pConv); /** * Return the local size of the convertor (count times the size of the datatype). */ -static inline void opal_convertor_get_packed_size( const opal_convertor_t* pConv, - size_t* pSize ) +static inline void opal_convertor_get_packed_size(const opal_convertor_t *pConv, size_t *pSize) { *pSize = pConv->local_size; } - /** * Return the remote size of the convertor (count times the remote size of the * datatype). On homogeneous environments the local and remote sizes are * identical. */ -static inline void opal_convertor_get_unpacked_size( const opal_convertor_t* pConv, - size_t* pSize ) +static inline void opal_convertor_get_unpacked_size(const opal_convertor_t *pConv, size_t *pSize) { - if( pConv->flags & CONVERTOR_HOMOGENEOUS ) { + if (pConv->flags & CONVERTOR_HOMOGENEOUS) { *pSize = pConv->local_size; return; } - if( 0 == (CONVERTOR_HAS_REMOTE_SIZE & pConv->flags) ) { - assert(! (pConv->flags & CONVERTOR_SEND)); - opal_convertor_compute_remote_size( (opal_convertor_t*)pConv); + if (0 == (CONVERTOR_HAS_REMOTE_SIZE & pConv->flags)) { + assert(!(pConv->flags & CONVERTOR_SEND)); + opal_convertor_compute_remote_size((opal_convertor_t *) pConv); } *pSize = pConv->remote_size; } @@ -235,89 +229,75 @@ static inline void opal_convertor_get_unpacked_size( const opal_convertor_t* pCo * mostly useful for contiguous datatypes, when we need to get the pointer to the * contiguous piece of memory. */ -static inline void opal_convertor_get_current_pointer( const opal_convertor_t* pConv, - void** position ) +static inline void opal_convertor_get_current_pointer(const opal_convertor_t *pConv, + void **position) { - unsigned char* base = pConv->pBaseBuf + pConv->bConverted + pConv->pDesc->true_lb; - *position = (void*)base; + unsigned char *base = pConv->pBaseBuf + pConv->bConverted + pConv->pDesc->true_lb; + *position = (void *) base; } -static inline void opal_convertor_get_offset_pointer( const opal_convertor_t* pConv, - size_t offset, void** position ) +static inline void opal_convertor_get_offset_pointer(const opal_convertor_t *pConv, size_t offset, + void **position) { - unsigned char* base = pConv->pBaseBuf + offset + pConv->pDesc->true_lb; - *position = (void*)base; + unsigned char *base = pConv->pBaseBuf + offset + pConv->pDesc->true_lb; + *position = (void *) base; } - /* * */ -OPAL_DECLSPEC int32_t opal_convertor_prepare_for_send( opal_convertor_t* convertor, - const struct opal_datatype_t* datatype, - size_t count, - const void* pUserBuf); - -static inline int32_t opal_convertor_copy_and_prepare_for_send( const opal_convertor_t* pSrcConv, - const struct opal_datatype_t* datatype, - size_t count, - const void* pUserBuf, - int32_t flags, - opal_convertor_t* convertor ) +OPAL_DECLSPEC int32_t opal_convertor_prepare_for_send(opal_convertor_t *convertor, + const struct opal_datatype_t *datatype, + size_t count, const void *pUserBuf); + +static inline int32_t opal_convertor_copy_and_prepare_for_send( + const opal_convertor_t *pSrcConv, const struct opal_datatype_t *datatype, size_t count, + const void *pUserBuf, int32_t flags, opal_convertor_t *convertor) { convertor->remoteArch = pSrcConv->remoteArch; - convertor->flags = pSrcConv->flags | flags; - convertor->master = pSrcConv->master; + convertor->flags = pSrcConv->flags | flags; + convertor->master = pSrcConv->master; - return opal_convertor_prepare_for_send( convertor, datatype, count, pUserBuf ); + return opal_convertor_prepare_for_send(convertor, datatype, count, pUserBuf); } /* * */ -OPAL_DECLSPEC int32_t opal_convertor_prepare_for_recv( opal_convertor_t* convertor, - const struct opal_datatype_t* datatype, - size_t count, - const void* pUserBuf ); -static inline int32_t opal_convertor_copy_and_prepare_for_recv( const opal_convertor_t* pSrcConv, - const struct opal_datatype_t* datatype, - size_t count, - const void* pUserBuf, - int32_t flags, - opal_convertor_t* convertor ) +OPAL_DECLSPEC int32_t opal_convertor_prepare_for_recv(opal_convertor_t *convertor, + const struct opal_datatype_t *datatype, + size_t count, const void *pUserBuf); +static inline int32_t opal_convertor_copy_and_prepare_for_recv( + const opal_convertor_t *pSrcConv, const struct opal_datatype_t *datatype, size_t count, + const void *pUserBuf, int32_t flags, opal_convertor_t *convertor) { convertor->remoteArch = pSrcConv->remoteArch; - convertor->flags = (pSrcConv->flags | flags); - convertor->master = pSrcConv->master; + convertor->flags = (pSrcConv->flags | flags); + convertor->master = pSrcConv->master; - return opal_convertor_prepare_for_recv( convertor, datatype, count, pUserBuf ); + return opal_convertor_prepare_for_recv(convertor, datatype, count, pUserBuf); } /* * Give access to the raw memory layout based on the datatype. */ -OPAL_DECLSPEC int32_t -opal_convertor_raw( opal_convertor_t* convertor, /* [IN/OUT] */ - struct iovec* iov, /* [IN/OUT] */ - uint32_t* iov_count, /* [IN/OUT] */ - size_t* length ); /* [OUT] */ - +OPAL_DECLSPEC int32_t opal_convertor_raw(opal_convertor_t *convertor, /* [IN/OUT] */ + struct iovec *iov, /* [IN/OUT] */ + uint32_t *iov_count, /* [IN/OUT] */ + size_t *length); /* [OUT] */ /* * Upper level does not need to call the _nocheck function directly. */ -OPAL_DECLSPEC int32_t -opal_convertor_set_position_nocheck( opal_convertor_t* convertor, - size_t* position ); -static inline int32_t -opal_convertor_set_position( opal_convertor_t* convertor, - size_t* position ) +OPAL_DECLSPEC int32_t opal_convertor_set_position_nocheck(opal_convertor_t *convertor, + size_t *position); +static inline int32_t opal_convertor_set_position(opal_convertor_t *convertor, size_t *position) { /* * Do not allow the convertor to go outside the data boundaries. This test include * the check for datatype with size zero as well as for convertors with a count of zero. */ - if( OPAL_UNLIKELY(convertor->local_size <= *position) ) { + if (OPAL_UNLIKELY(convertor->local_size <= *position)) { convertor->flags |= CONVERTOR_COMPLETED; convertor->bConverted = convertor->local_size; *position = convertor->bConverted; @@ -327,76 +307,66 @@ opal_convertor_set_position( opal_convertor_t* convertor, /* * If the convertor is already at the correct position we are happy. */ - if( OPAL_LIKELY((*position) == convertor->bConverted) ) return OPAL_SUCCESS; + if (OPAL_LIKELY((*position) == convertor->bConverted)) + return OPAL_SUCCESS; /* Remove the completed flag if it's already set */ convertor->flags &= ~CONVERTOR_COMPLETED; - if( (convertor->flags & OPAL_DATATYPE_FLAG_NO_GAPS) && + if ((convertor->flags & OPAL_DATATYPE_FLAG_NO_GAPS) && #if defined(CHECKSUM) !(convertor->flags & CONVERTOR_WITH_CHECKSUM) && -#endif /* defined(CHECKSUM) */ - (convertor->flags & (CONVERTOR_SEND | CONVERTOR_HOMOGENEOUS)) ) { +#endif /* defined(CHECKSUM) */ + (convertor->flags & (CONVERTOR_SEND | CONVERTOR_HOMOGENEOUS))) { /* Contiguous and no checkpoint and no homogeneous unpack */ convertor->bConverted = *position; return OPAL_SUCCESS; } - return opal_convertor_set_position_nocheck( convertor, position ); + return opal_convertor_set_position_nocheck(convertor, position); } /* * */ -static inline int32_t -opal_convertor_personalize( opal_convertor_t* convertor, - uint32_t flags, - size_t* position ) +static inline int32_t opal_convertor_personalize(opal_convertor_t *convertor, uint32_t flags, + size_t *position) { convertor->flags |= flags; - if( OPAL_UNLIKELY(NULL == position) ) + if (OPAL_UNLIKELY(NULL == position)) return OPAL_SUCCESS; - return opal_convertor_set_position( convertor, position ); + return opal_convertor_set_position(convertor, position); } /* * */ -OPAL_DECLSPEC int -opal_convertor_clone( const opal_convertor_t* source, - opal_convertor_t* destination, - int32_t copy_stack ); - -static inline int -opal_convertor_clone_with_position( const opal_convertor_t* source, - opal_convertor_t* destination, - int32_t copy_stack, - size_t* position ) +OPAL_DECLSPEC int opal_convertor_clone(const opal_convertor_t *source, + opal_convertor_t *destination, int32_t copy_stack); + +static inline int opal_convertor_clone_with_position(const opal_convertor_t *source, + opal_convertor_t *destination, + int32_t copy_stack, size_t *position) { - (void)opal_convertor_clone( source, destination, copy_stack ); - return opal_convertor_set_position( destination, position ); + (void) opal_convertor_clone(source, destination, copy_stack); + return opal_convertor_set_position(destination, position); } /* * */ -OPAL_DECLSPEC void -opal_convertor_dump( opal_convertor_t* convertor ); +OPAL_DECLSPEC void opal_convertor_dump(opal_convertor_t *convertor); -OPAL_DECLSPEC void -opal_datatype_dump_stack( const dt_stack_t* pStack, - int stack_pos, - const union dt_elem_desc* pDesc, - const char* name ); +OPAL_DECLSPEC void opal_datatype_dump_stack(const dt_stack_t *pStack, int stack_pos, + const union dt_elem_desc *pDesc, const char *name); /* * */ -OPAL_DECLSPEC int -opal_convertor_generic_simple_position( opal_convertor_t* pConvertor, - size_t* position ); +OPAL_DECLSPEC int opal_convertor_generic_simple_position(opal_convertor_t *pConvertor, + size_t *position); END_C_DECLS -#endif /* OPAL_CONVERTOR_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_CONVERTOR_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_convertor_internal.h b/opal/datatype/opal_convertor_internal.h index 39690f5bd19..167530b669d 100644 --- a/opal/datatype/opal_convertor_internal.h +++ b/opal/datatype/opal_convertor_internal.h @@ -22,18 +22,17 @@ BEGIN_C_DECLS -typedef int32_t (*conversion_fct_t)( opal_convertor_t* pConvertor, uint32_t count, - const void* from, size_t from_len, ptrdiff_t from_extent, - void* to, size_t to_length, ptrdiff_t to_extent, - ptrdiff_t *advance ); +typedef int32_t (*conversion_fct_t)(opal_convertor_t *pConvertor, uint32_t count, const void *from, + size_t from_len, ptrdiff_t from_extent, void *to, + size_t to_length, ptrdiff_t to_extent, ptrdiff_t *advance); typedef struct opal_convertor_master_t { - struct opal_convertor_master_t* next; - uint32_t remote_arch; - uint32_t flags; - uint32_t hetero_mask; - const size_t remote_sizes[OPAL_DATATYPE_MAX_PREDEFINED]; - conversion_fct_t* pFunctions; /**< the convertor functions pointer */ + struct opal_convertor_master_t *next; + uint32_t remote_arch; + uint32_t flags; + uint32_t hetero_mask; + const size_t remote_sizes[OPAL_DATATYPE_MAX_PREDEFINED]; + conversion_fct_t *pFunctions; /**< the convertor functions pointer */ } opal_convertor_master_t; /* @@ -41,15 +40,14 @@ typedef struct opal_convertor_master_t { * convertor hold all informations related to a defined architecture, such as the sizes * of the predefined data-types, the conversion functions, ... */ -opal_convertor_master_t* opal_convertor_find_or_create_master( uint32_t remote_arch ); +opal_convertor_master_t *opal_convertor_find_or_create_master(uint32_t remote_arch); /* * Destroy all pending master convertors. This function is usually called when we * shutdown the data-type engine, once all convertors have been destroyed. */ -void opal_convertor_destroy_masters( void ); - +void opal_convertor_destroy_masters(void); END_C_DECLS -#endif /* OPAL_CONVERTOR_INTERNAL_HAS_BEEN_INCLUDED */ +#endif /* OPAL_CONVERTOR_INTERNAL_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_convertor_raw.c b/opal/datatype/opal_convertor_raw.c index 7e938a53c7c..f8241f93b13 100644 --- a/opal/datatype/opal_convertor_raw.c +++ b/opal/datatype/opal_convertor_raw.c @@ -23,11 +23,14 @@ #include "opal_stdint.h" #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" -#define DO_DEBUG(INST) if( opal_ddt_raw_debug ) { INST } +# define DO_DEBUG(INST) \ + if (opal_ddt_raw_debug) { \ + INST \ + } #else -#define DO_DEBUG(INST) +# define DO_DEBUG(INST) #endif /* OPAL_ENABLE_DEBUG */ /* Take a new iovec (base + len) and try to merge it with what we already @@ -35,18 +38,18 @@ * iovec location. If we need to advance position and we reach the end * of the iovec array, return 1 to signal we did not saved the last iovec. */ -static inline int -opal_convertor_merge_iov( struct iovec* iov, uint32_t* iov_count, - IOVBASE_TYPE* base, size_t len, - uint32_t* idx ) +static inline int opal_convertor_merge_iov(struct iovec *iov, uint32_t *iov_count, + IOVBASE_TYPE *base, size_t len, uint32_t *idx) { - if( 0 != iov[*idx].iov_len ) { - if( base == ((char*)iov[*idx].iov_base + iov[*idx].iov_len) ) { - iov[*idx].iov_len += len; /* merge with previous iovec */ + if (0 != iov[*idx].iov_len) { + if (base == ((char *) iov[*idx].iov_base + iov[*idx].iov_len)) { + iov[*idx].iov_len += len; /* merge with previous iovec */ return 0; - } /* cannot merge, move to the next position */ + } /* cannot merge, move to the next position */ *idx = *idx + 1; - if( *idx == *iov_count ) return 1; /* do not overwrite outside the iovec array boundaries */ + if (*idx == *iov_count) { + return 1; /* do not overwrite outside the iovec array boundaries */ + } } iov[*idx].iov_base = base; iov[*idx].iov_len = len; @@ -58,45 +61,43 @@ opal_convertor_merge_iov( struct iovec* iov, uint32_t* iov_count, * conversion (i.e. no heterogeneity) is taken into account, and that all * length we're working on are local. */ -int32_t -opal_convertor_raw( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* iov_count, - size_t* length ) +int32_t opal_convertor_raw(opal_convertor_t *pConvertor, struct iovec *iov, uint32_t *iov_count, + size_t *length) { const opal_datatype_t *pData = pConvertor->pDesc; - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - size_t count_desc; /* the number of items already done in the actual pos_desc */ + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + size_t count_desc; /* the number of items already done in the actual pos_desc */ size_t do_now, blength; - dt_elem_desc_t* description, *pElem; - unsigned char *source_base; /* origin of the data */ - size_t sum_iov_len = 0; /* sum of raw data lengths in the iov_len fields */ - uint32_t index = 0; /* the iov index and a simple counter */ + dt_elem_desc_t *description, *pElem; + unsigned char *source_base; /* origin of the data */ + size_t sum_iov_len = 0; /* sum of raw data lengths in the iov_len fields */ + uint32_t index = 0; /* the iov index and a simple counter */ - assert( (*iov_count) > 0 ); - if( OPAL_LIKELY(pConvertor->flags & CONVERTOR_COMPLETED) ) { + assert((*iov_count) > 0); + if (OPAL_LIKELY(pConvertor->flags & CONVERTOR_COMPLETED)) { iov[0].iov_base = NULL; - iov[0].iov_len = 0; - *iov_count = 0; - *length = iov[0].iov_len; - return 1; /* We're still done */ + iov[0].iov_len = 0; + *iov_count = 0; + *length = iov[0].iov_len; + return 1; /* We're still done */ } - if( OPAL_LIKELY(pConvertor->flags & CONVERTOR_NO_OP) ) { + if (OPAL_LIKELY(pConvertor->flags & CONVERTOR_NO_OP)) { /* The convertor contain minimal informations, we only use the bConverted * to manage the conversion. This function work even after the convertor * was moved to a specific position. */ - opal_convertor_get_current_pointer( pConvertor, (void**)&iov[0].iov_base ); + opal_convertor_get_current_pointer(pConvertor, (void **) &iov[0].iov_base); iov[0].iov_len = pConvertor->local_size - pConvertor->bConverted; *length = iov[0].iov_len; pConvertor->bConverted = pConvertor->local_size; pConvertor->flags |= CONVERTOR_COMPLETED; *iov_count = 1; - return 1; /* we're done */ + return 1; /* we're done */ } - DO_DEBUG( opal_output( 0, "opal_convertor_raw( %p, {%p, %" PRIu32 "}, %"PRIsize_t " )\n", (void*)pConvertor, - (void*)iov, *iov_count, *length ); ); + DO_DEBUG(opal_output(0, "opal_convertor_raw( %p, {%p, %" PRIu32 "}, %" PRIsize_t " )\n", + (void *) pConvertor, (void *) iov, *iov_count, *length);); description = pConvertor->use_desc->desc; @@ -105,91 +106,99 @@ opal_convertor_raw( opal_convertor_t* pConvertor, * due to the fact that the convertor can stop in the middle of a data with a count */ pStack = pConvertor->pStack + pConvertor->stack_pos; - pos_desc = pStack->index; - source_base = pConvertor->pBaseBuf + pStack->disp; - count_desc = pStack->count; + pos_desc = pStack->index; + source_base = pConvertor->pBaseBuf + pStack->disp; + count_desc = pStack->count; pStack--; pConvertor->stack_pos--; pElem = &(description[pos_desc]); - DO_DEBUG( opal_output( 0, "raw start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" - "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pos_desc, count_desc, (long)(source_base - pConvertor->pBaseBuf), - pConvertor->stack_pos, pStack->index, pStack->count, (long)pStack->disp ); ); + DO_DEBUG(opal_output(0, + "raw start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" + "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", + pos_desc, count_desc, (long) (source_base - pConvertor->pBaseBuf), + pConvertor->stack_pos, pStack->index, pStack->count, + (long) pStack->disp);); iov[index].iov_len = 0; /* Special case if we start from a position that is in the middle of a data element blocklen. * We can treat this outside the loop as it is an exception that can only happen once, * and will simplify the loop handling. */ - if( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { - const ddt_elem_desc_t* current = &(pElem->elem); + if (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { + const ddt_elem_desc_t *current = &(pElem->elem); - if( count_desc != ((size_t)current->count * current->blocklen) ) { /* Not the full element description */ - if( (do_now = count_desc % current->blocklen) ) { - do_now = current->blocklen - do_now; /* how much left in the block */ + if (count_desc + != ((size_t) current->count + * current->blocklen)) { /* Not the full element description */ + if ((do_now = count_desc % current->blocklen)) { + do_now = current->blocklen - do_now; /* how much left in the block */ source_base += current->disp; blength = do_now * opal_datatype_basicDatatypes[current->common.type]->size; - OPAL_DATATYPE_SAFEGUARD_POINTER( source_base, blength, pConvertor->pBaseBuf, - pConvertor->pDesc, pConvertor->count ); - DO_DEBUG( opal_output( 0, "raw 1. iov[%d] = {base %p, length %" PRIsize_t "}\n", - index, (void*)source_base, blength ); ); - opal_convertor_merge_iov( iov, iov_count, - (IOVBASE_TYPE *) source_base, blength, &index ); + OPAL_DATATYPE_SAFEGUARD_POINTER(source_base, blength, pConvertor->pBaseBuf, + pConvertor->pDesc, pConvertor->count); + DO_DEBUG(opal_output(0, "raw 1. iov[%d] = {base %p, length %" PRIsize_t "}\n", + index, (void *) source_base, blength);); + opal_convertor_merge_iov(iov, iov_count, (IOVBASE_TYPE *) source_base, blength, + &index); /* ignore the return value, we know there was at least one element in the iovec */ sum_iov_len += blength; count_desc -= do_now; - source_base += (blength - current->blocklen * opal_datatype_basicDatatypes[current->common.type]->size + - current->extent - current->disp); + source_base += (blength + - current->blocklen + * opal_datatype_basicDatatypes[current->common.type]->size + + current->extent - current->disp); } } } - while( 1 ) { - while( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { - const ddt_elem_desc_t* current = &(pElem->elem); + while (1) { + while (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { + const ddt_elem_desc_t *current = &(pElem->elem); source_base += current->disp; do_now = current->count; - if( count_desc != ((size_t)current->count * current->blocklen) ) { + if (count_desc != ((size_t) current->count * current->blocklen)) { do_now = count_desc / current->blocklen; - assert( 0 == (count_desc % current->blocklen) ); + assert(0 == (count_desc % current->blocklen)); } blength = current->blocklen * opal_datatype_basicDatatypes[current->common.type]->size; - for(size_t _i = 0; _i < do_now; _i++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( source_base, blength, pConvertor->pBaseBuf, - pConvertor->pDesc, pConvertor->count ); - DO_DEBUG( opal_output( 0, "raw 2. iov[%d] = {base %p, length %" PRIsize_t "}\n", - index, (void*)source_base, blength ); ); - if( opal_convertor_merge_iov( iov, iov_count, - (IOVBASE_TYPE *) source_base, blength, &index ) ) - break; /* no more iovec available, bail out */ + for (size_t _i = 0; _i < do_now; _i++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(source_base, blength, pConvertor->pBaseBuf, + pConvertor->pDesc, pConvertor->count); + DO_DEBUG(opal_output(0, "raw 2. iov[%d] = {base %p, length %" PRIsize_t "}\n", + index, (void *) source_base, blength);); + if (opal_convertor_merge_iov(iov, iov_count, (IOVBASE_TYPE *) source_base, blength, + &index)) { + break; /* no more iovec available, bail out */ + } source_base += current->extent; sum_iov_len += blength; count_desc -= current->blocklen; } - if( 0 == count_desc ) { /* completed */ + if (0 == count_desc) { /* completed */ source_base = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); continue; } source_base -= current->disp; goto complete_loop; } - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */ - DO_DEBUG( opal_output( 0, "raw end_loop count %" PRIsize_t " stack_pos %d" - " pos_desc %d disp %ld space %" PRIsize_t "\n", - pStack->count, pConvertor->stack_pos, - pos_desc, (long)pStack->disp, sum_iov_len ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( 0 == pConvertor->stack_pos ) { + if (OPAL_DATATYPE_END_LOOP == pElem->elem.common.type) { /* end of the current loop */ + DO_DEBUG(opal_output(0, + "raw end_loop count %" PRIsize_t " stack_pos %d" + " pos_desc %d disp %ld space %" PRIsize_t "\n", + pStack->count, pConvertor->stack_pos, pos_desc, + (long) pStack->disp, sum_iov_len);); + if (--(pStack->count) == 0) { /* end of loop */ + if (0 == pConvertor->stack_pos) { /* we're done. Force the exit of the main for loop (around iovec) */ - index++; /* account for the currently updating iovec */ + index++; /* account for the currently updating iovec */ goto complete_loop; } pConvertor->stack_pos--; @@ -197,32 +206,35 @@ opal_convertor_raw( opal_convertor_t* pConvertor, pos_desc++; } else { pos_desc = pStack->index + 1; - if( pStack->index == -1 ) { + if (pStack->index == -1) { pStack->disp += (pData->ub - pData->lb); } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); - pStack->disp += description[pStack->index].loop.extent; /* jump by the loop extent */ + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); + pStack->disp += description[pStack->index] + .loop.extent; /* jump by the loop extent */ } } source_base = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "raw new_loop count %" PRIsize_t " stack_pos %d " - "pos_desc %d disp %ld space %" PRIsize_t "\n", - pStack->count, pConvertor->stack_pos, - pos_desc, (long)pStack->disp, sum_iov_len ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "raw new_loop count %" PRIsize_t " stack_pos %d " + "pos_desc %d disp %ld space %" PRIsize_t "\n", + pStack->count, pConvertor->stack_pos, pos_desc, + (long) pStack->disp, sum_iov_len);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - ptrdiff_t local_disp = (ptrdiff_t)source_base; - ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)(pElem + pElem->loop.items); + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + ptrdiff_t local_disp = (ptrdiff_t) source_base; + ddt_endloop_desc_t *end_loop = (ddt_endloop_desc_t *) (pElem + pElem->loop.items); - if( pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { + if (pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { ptrdiff_t offset = end_loop->first_elem_disp; source_base += offset; - for(; count_desc > 0; ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( source_base, end_loop->size, pConvertor->pBaseBuf, - pConvertor->pDesc, pConvertor->count ); - if( opal_convertor_merge_iov( iov, iov_count, - (IOVBASE_TYPE *) source_base, end_loop->size, &index ) ) { + for (; count_desc > 0;) { + OPAL_DATATYPE_SAFEGUARD_POINTER(source_base, end_loop->size, + pConvertor->pBaseBuf, pConvertor->pDesc, + pConvertor->count); + if (opal_convertor_merge_iov(iov, iov_count, (IOVBASE_TYPE *) source_base, + end_loop->size, &index)) { source_base -= offset; goto complete_loop; } @@ -230,36 +242,41 @@ opal_convertor_raw( opal_convertor_t* pConvertor, source_base += pElem->loop.extent; sum_iov_len += end_loop->size; count_desc--; - DO_DEBUG( opal_output( 0, "raw contig loop generate iov[%d] = {base %p, length %" PRIsize_t "}" - "space %" PRIsize_t " [pos_desc %d]\n", - index, iov[index].iov_base, iov[index].iov_len, - sum_iov_len, pos_desc ); ); + DO_DEBUG(opal_output( + 0, + "raw contig loop generate iov[%d] = {base %p, length %" PRIsize_t + "}" + "space %" PRIsize_t " [pos_desc %d]\n", + index, iov[index].iov_base, iov[index].iov_len, sum_iov_len, + pos_desc);); } source_base -= offset; pos_desc += pElem->loop.items + 1; } else { - local_disp = (ptrdiff_t)source_base - local_disp; - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp + local_disp); + local_disp = (ptrdiff_t) source_base - local_disp; + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp + local_disp); pos_desc++; } source_base = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop"); } } - complete_loop: - pConvertor->bConverted += sum_iov_len; /* update the already converted bytes */ +complete_loop: + pConvertor->bConverted += sum_iov_len; /* update the already converted bytes */ *length = sum_iov_len; *iov_count = index; - if( pConvertor->bConverted == pConvertor->local_size ) { + if (pConvertor->bConverted == pConvertor->local_size) { pConvertor->flags |= CONVERTOR_COMPLETED; return 1; } /* I complete an element, next step I should go to the next one */ - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_UINT1, count_desc, - source_base - pConvertor->pBaseBuf ); - DO_DEBUG( opal_output( 0, "raw save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pConvertor->stack_pos, pStack->index, pStack->count, (long)pStack->disp ); ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_UINT1, count_desc, + source_base - pConvertor->pBaseBuf); + DO_DEBUG( + opal_output(0, + "raw save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", + pConvertor->stack_pos, pStack->index, pStack->count, (long) pStack->disp);); return 0; } diff --git a/opal/datatype/opal_copy_functions.c b/opal/datatype/opal_copy_functions.c index ad315f787e4..0cb8b50c274 100644 --- a/opal/datatype/opal_copy_functions.c +++ b/opal/datatype/opal_copy_functions.c @@ -19,11 +19,11 @@ #include -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" -#include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_datatype_checksum.h" #include "opal/datatype/opal_convertor_internal.h" +#include "opal/datatype/opal_datatype.h" +#include "opal/datatype/opal_datatype_checksum.h" +#include "opal/datatype/opal_datatype_internal.h" /* * This function is used to copy data from one buffer to another. The assumption @@ -39,43 +39,42 @@ * * Return value: Number of elements of type TYPE copied */ -#define COPY_TYPE( TYPENAME, TYPE, COUNT ) \ -static int copy_##TYPENAME( opal_convertor_t *pConvertor, size_t count, \ - char* from, size_t from_len, ptrdiff_t from_extent, \ - char* to, size_t to_len, ptrdiff_t to_extent, \ - ptrdiff_t *advance) \ -{ \ - size_t remote_TYPE_size = sizeof(TYPE) * (COUNT); /* TODO */ \ - size_t local_TYPE_size = (COUNT) * sizeof(TYPE); \ - \ - /* make sure the remote buffer is large enough to hold the data */ \ - if( (remote_TYPE_size * count) > from_len ) { \ - count = from_len / remote_TYPE_size; \ - if( (count * remote_TYPE_size) != from_len ) { \ - DUMP( "oops should I keep this data somewhere (excedent %d bytes)?\n", \ - from_len - (count * remote_TYPE_size) ); \ - } \ - DUMP( "correct: copy %s count %d from buffer %p with length %d to %p space %d\n", \ - #TYPE, count, from, from_len, to, to_len ); \ - } else \ - DUMP( " copy %s count %d from buffer %p with length %d to %p space %d\n", \ - #TYPE, count, from, from_len, to, to_len ); \ - \ - if( (from_extent == (ptrdiff_t)local_TYPE_size) && \ - (to_extent == (ptrdiff_t)remote_TYPE_size) ) { \ - /* copy of contigous data at both source and destination */ \ - MEMCPY( to, from, count * local_TYPE_size ); \ - } else { \ - /* source or destination are non-contigous */ \ - for(size_t i = 0; i < count; i++ ) { \ - MEMCPY( to, from, local_TYPE_size ); \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - *advance = count * from_extent; \ - return count; \ -} +#define COPY_TYPE(TYPENAME, TYPE, COUNT) \ + static int copy_##TYPENAME(opal_convertor_t *pConvertor, size_t count, char *from, \ + size_t from_len, ptrdiff_t from_extent, char *to, size_t to_len, \ + ptrdiff_t to_extent, ptrdiff_t *advance) \ + { \ + size_t remote_TYPE_size = sizeof(TYPE) * (COUNT); /* TODO */ \ + size_t local_TYPE_size = (COUNT) * sizeof(TYPE); \ + \ + /* make sure the remote buffer is large enough to hold the data */ \ + if ((remote_TYPE_size * count) > from_len) { \ + count = from_len / remote_TYPE_size; \ + if ((count * remote_TYPE_size) != from_len) { \ + DUMP("oops should I keep this data somewhere (excedent %d bytes)?\n", \ + from_len - (count * remote_TYPE_size)); \ + } \ + DUMP("correct: copy %s count %d from buffer %p with length %d to %p space %d\n", \ + #TYPE, count, from, from_len, to, to_len); \ + } else \ + DUMP(" copy %s count %d from buffer %p with length %d to %p space %d\n", \ + #TYPE, count, from, from_len, to, to_len); \ + \ + if ((from_extent == (ptrdiff_t) local_TYPE_size) \ + && (to_extent == (ptrdiff_t) remote_TYPE_size)) { \ + /* copy of contigous data at both source and destination */ \ + MEMCPY(to, from, count *local_TYPE_size); \ + } else { \ + /* source or destination are non-contigous */ \ + for (size_t i = 0; i < count; i++) { \ + MEMCPY(to, from, local_TYPE_size); \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + *advance = count * from_extent; \ + return count; \ + } /* * This function is used to copy data from one buffer to another. The assumption @@ -91,195 +90,194 @@ static int copy_##TYPENAME( opal_convertor_t *pConvertor, size_t count, * * Return value: Number of elements of type TYPE copied */ -#define COPY_CONTIGUOUS_BYTES( TYPENAME, COUNT ) \ -static size_t copy_##TYPENAME##_##COUNT( opal_convertor_t *pConvertor, size_t count, \ - char* from, size_t from_len, ptrdiff_t from_extent, \ - char* to, size_t to_len, ptrdiff_t to_extent, \ - ptrdiff_t *advance ) \ -{ \ - size_t remote_TYPE_size = (size_t)(COUNT); /* TODO */ \ - size_t local_TYPE_size = (size_t)(COUNT); \ - \ - if( (remote_TYPE_size * count) > from_len ) { \ - count = from_len / remote_TYPE_size; \ - if( (count * remote_TYPE_size) != from_len ) { \ - DUMP( "oops should I keep this data somewhere (excedent %d bytes)?\n", \ - from_len - (count * remote_TYPE_size) ); \ - } \ - DUMP( "correct: copy %s count %d from buffer %p with length %d to %p space %d\n", \ - #TYPENAME, count, from, from_len, to, to_len ); \ - } else \ - DUMP( " copy %s count %d from buffer %p with length %d to %p space %d\n", \ - #TYPENAME, count, from, from_len, to, to_len ); \ - \ - if( (from_extent == (ptrdiff_t)local_TYPE_size) && \ - (to_extent == (ptrdiff_t)remote_TYPE_size) ) { \ - MEMCPY( to, from, count * local_TYPE_size ); \ - } else { \ - for(size_t i = 0; i < count; i++ ) { \ - MEMCPY( to, from, local_TYPE_size ); \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - *advance = count * from_extent; \ - return count; \ -} +#define COPY_CONTIGUOUS_BYTES(TYPENAME, COUNT) \ + static size_t copy_##TYPENAME##_##COUNT(opal_convertor_t *pConvertor, size_t count, \ + char *from, size_t from_len, ptrdiff_t from_extent, \ + char *to, size_t to_len, ptrdiff_t to_extent, \ + ptrdiff_t *advance) \ + { \ + size_t remote_TYPE_size = (size_t)(COUNT); /* TODO */ \ + size_t local_TYPE_size = (size_t)(COUNT); \ + \ + if ((remote_TYPE_size * count) > from_len) { \ + count = from_len / remote_TYPE_size; \ + if ((count * remote_TYPE_size) != from_len) { \ + DUMP("oops should I keep this data somewhere (excedent %d bytes)?\n", \ + from_len - (count * remote_TYPE_size)); \ + } \ + DUMP("correct: copy %s count %d from buffer %p with length %d to %p space %d\n", \ + #TYPENAME, count, from, from_len, to, to_len); \ + } else \ + DUMP(" copy %s count %d from buffer %p with length %d to %p space %d\n", \ + #TYPENAME, count, from, from_len, to, to_len); \ + \ + if ((from_extent == (ptrdiff_t) local_TYPE_size) \ + && (to_extent == (ptrdiff_t) remote_TYPE_size)) { \ + MEMCPY(to, from, count *local_TYPE_size); \ + } else { \ + for (size_t i = 0; i < count; i++) { \ + MEMCPY(to, from, local_TYPE_size); \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + *advance = count * from_extent; \ + return count; \ + } /* set up copy functions for the basic C MPI data types */ /* per default, select all of them */ -#define REQUIRE_COPY_BYTES_1 1 -#define REQUIRE_COPY_BYTES_2 1 -#define REQUIRE_COPY_BYTES_4 1 -#define REQUIRE_COPY_BYTES_8 1 +#define REQUIRE_COPY_BYTES_1 1 +#define REQUIRE_COPY_BYTES_2 1 +#define REQUIRE_COPY_BYTES_4 1 +#define REQUIRE_COPY_BYTES_8 1 #define REQUIRE_COPY_BYTES_16 1 #if REQUIRE_COPY_BYTES_1 -COPY_CONTIGUOUS_BYTES( bytes, 1 ) +COPY_CONTIGUOUS_BYTES(bytes, 1) #endif #if REQUIRE_COPY_BYTES_2 -COPY_CONTIGUOUS_BYTES( bytes, 2 ) +COPY_CONTIGUOUS_BYTES(bytes, 2) #endif #if REQUIRE_COPY_BYTES_4 -COPY_CONTIGUOUS_BYTES( bytes, 4 ) +COPY_CONTIGUOUS_BYTES(bytes, 4) #endif #if REQUIRE_COPY_BYTES_8 -COPY_CONTIGUOUS_BYTES( bytes, 8 ) +COPY_CONTIGUOUS_BYTES(bytes, 8) #endif #if REQUIRE_COPY_BYTES_16 -COPY_CONTIGUOUS_BYTES( bytes, 16 ) +COPY_CONTIGUOUS_BYTES(bytes, 16) #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 2 -COPY_TYPE( float_2, short float, 1 ) +COPY_TYPE(float_2, short float, 1) #elif SIZEOF_FLOAT == 2 -COPY_TYPE( float_2, float, 1 ) +COPY_TYPE(float_2, float, 1) #elif SIZEOF_DOUBLE == 2 -COPY_TYPE( float_2, double, 1 ) +COPY_TYPE(float_2, double, 1) #elif SIZEOF_LONG_DOUBLE == 2 -COPY_TYPE( float_2, long double, 1 ) +COPY_TYPE(float_2, long double, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 2 -COPY_TYPE( float_2, opal_short_float_t, 1 ) +COPY_TYPE(float_2, opal_short_float_t, 1) #else /* #error No basic type for copy function for opal_datatype_float2 found */ -#define copy_float_2 NULL +# define copy_float_2 NULL #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 4 -COPY_TYPE( float_4, short float, 1 ) +COPY_TYPE(float_4, short float, 1) #elif SIZEOF_FLOAT == 4 -COPY_TYPE( float_4, float, 1 ) +COPY_TYPE(float_4, float, 1) #elif SIZEOF_DOUBLE == 4 -COPY_TYPE( float_4, double, 1 ) +COPY_TYPE(float_4, double, 1) #elif SIZEOF_LONG_DOUBLE == 4 -COPY_TYPE( float_4, long double, 1 ) +COPY_TYPE(float_4, long double, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 4 -COPY_TYPE( float_4, opal_short_float_t, 1 ) +COPY_TYPE(float_4, opal_short_float_t, 1) #else -#error No basic type for copy function for opal_datatype_float4 found +# error No basic type for copy function for opal_datatype_float4 found #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 8 -COPY_TYPE( float_8, short float, 1 ) +COPY_TYPE(float_8, short float, 1) #elif SIZEOF_FLOAT == 8 -COPY_TYPE( float_8, float, 1 ) +COPY_TYPE(float_8, float, 1) #elif SIZEOF_DOUBLE == 8 -COPY_TYPE( float_8, double, 1 ) +COPY_TYPE(float_8, double, 1) #elif SIZEOF_LONG_DOUBLE == 8 -COPY_TYPE( float_8, long double, 1 ) +COPY_TYPE(float_8, long double, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 8 -COPY_TYPE( float_8, opal_short_float_t, 1 ) +COPY_TYPE(float_8, opal_short_float_t, 1) #else -#error No basic type for copy function for opal_datatype_float8 found +# error No basic type for copy function for opal_datatype_float8 found #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 12 -COPY_TYPE( float_12, short float, 1 ) +COPY_TYPE(float_12, short float, 1) #elif SIZEOF_FLOAT == 12 -COPY_TYPE( float_12, float, 1 ) +COPY_TYPE(float_12, float, 1) #elif SIZEOF_DOUBLE == 12 -COPY_TYPE( float_12, double, 1 ) +COPY_TYPE(float_12, double, 1) #elif SIZEOF_LONG_DOUBLE == 12 -COPY_TYPE( float_12, long double, 1 ) +COPY_TYPE(float_12, long double, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 12 -COPY_TYPE( float_12, opal_short_float_t, 1 ) +COPY_TYPE(float_12, opal_short_float_t, 1) #else /* #error No basic type for copy function for opal_datatype_float12 found */ -#define copy_float_12 NULL +# define copy_float_12 NULL #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 16 -COPY_TYPE( float_16, short float, 1 ) +COPY_TYPE(float_16, short float, 1) #elif SIZEOF_FLOAT == 16 -COPY_TYPE( float_16, float, 1 ) +COPY_TYPE(float_16, float, 1) #elif SIZEOF_DOUBLE == 16 -COPY_TYPE( float_16, double, 1 ) +COPY_TYPE(float_16, double, 1) #elif SIZEOF_LONG_DOUBLE == 16 -COPY_TYPE( float_16, long double, 1 ) +COPY_TYPE(float_16, long double, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 16 -COPY_TYPE( float_16, opal_short_float_t, 1 ) +COPY_TYPE(float_16, opal_short_float_t, 1) #else /* #error No basic type for copy function for opal_datatype_float16 found */ -#define copy_float_16 NULL +# define copy_float_16 NULL #endif #if defined(HAVE_SHORT_FLOAT__COMPLEX) -COPY_TYPE ( short_float_complex, short float _Complex, 1) +COPY_TYPE(short_float_complex, short float _Complex, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_COMPLEX_T) -COPY_TYPE ( short_float_complex, opal_short_float_complex_t, 1) +COPY_TYPE(short_float_complex, opal_short_float_complex_t, 1) #else /* #error No basic type for copy function for opal_datatype_short_float_complex found */ -#define copy_short_float_complex NULL +# define copy_short_float_complex NULL #endif -COPY_TYPE ( float_complex, float _Complex, 1) +COPY_TYPE(float_complex, float _Complex, 1) -COPY_TYPE ( double_complex, double _Complex, 1) +COPY_TYPE(double_complex, double _Complex, 1) -COPY_TYPE ( long_double_complex, long double _Complex, 1) +COPY_TYPE(long_double_complex, long double _Complex, 1) #if SIZEOF__BOOL == SIZEOF_CHAR -COPY_TYPE (bool, char, 1) +COPY_TYPE(bool, char, 1) #elif SIZEOF__BOOL == SIZEOF_SHORT -COPY_TYPE (bool, short, 1) +COPY_TYPE(bool, short, 1) #elif SIZEOF__BOOL == SIZEOF_INT -COPY_TYPE (bool, int, 1) +COPY_TYPE(bool, int, 1) #elif SIZEOF__BOOL == SIZEOF_LONG -COPY_TYPE (bool, long, 1) +COPY_TYPE(bool, long, 1) #else -#error No basic type for copy function for opal_datatype_bool found +# error No basic type for copy function for opal_datatype_bool found #endif -COPY_TYPE (wchar, wchar_t, 1) - +COPY_TYPE(wchar, wchar_t, 1) /* Table of predefined copy functions - one for each OPAL type */ /* NOTE: The order of this array *MUST* match the order in opal_datatype_basicDatatypes */ conversion_fct_t opal_datatype_copy_functions[OPAL_DATATYPE_MAX_PREDEFINED] = { - (conversion_fct_t)NULL, /* OPAL_DATATYPE_LOOP */ - (conversion_fct_t)NULL, /* OPAL_DATATYPE_END_LOOP */ - (conversion_fct_t)NULL, /* OPAL_DATATYPE_LB */ - (conversion_fct_t)NULL, /* OPAL_DATATYPE_UB */ - (conversion_fct_t)copy_bytes_1, /* OPAL_DATATYPE_INT1 */ - (conversion_fct_t)copy_bytes_2, /* OPAL_DATATYPE_INT2 */ - (conversion_fct_t)copy_bytes_4, /* OPAL_DATATYPE_INT4 */ - (conversion_fct_t)copy_bytes_8, /* OPAL_DATATYPE_INT8 */ - (conversion_fct_t)copy_bytes_16, /* OPAL_DATATYPE_INT16 */ - (conversion_fct_t)copy_bytes_1, /* OPAL_DATATYPE_UINT1 */ - (conversion_fct_t)copy_bytes_2, /* OPAL_DATATYPE_UINT2 */ - (conversion_fct_t)copy_bytes_4, /* OPAL_DATATYPE_UINT4 */ - (conversion_fct_t)copy_bytes_8, /* OPAL_DATATYPE_UINT8 */ - (conversion_fct_t)copy_bytes_16, /* OPAL_DATATYPE_UINT16 */ - (conversion_fct_t)copy_float_2, /* OPAL_DATATYPE_FLOAT2 */ - (conversion_fct_t)copy_float_4, /* OPAL_DATATYPE_FLOAT4 */ - (conversion_fct_t)copy_float_8, /* OPAL_DATATYPE_FLOAT8 */ - (conversion_fct_t)copy_float_12, /* OPAL_DATATYPE_FLOAT12 */ - (conversion_fct_t)copy_float_16, /* OPAL_DATATYPE_FLOAT16 */ - (conversion_fct_t)copy_short_float_complex, /* OPAL_DATATYPE_SHORT_FLOAT_COMPLEX */ - (conversion_fct_t)copy_float_complex, /* OPAL_DATATYPE_FLOAT_COMPLEX */ - (conversion_fct_t)copy_double_complex, /* OPAL_DATATYPE_DOUBLE_COMPLEX */ - (conversion_fct_t)copy_long_double_complex, /* OPAL_DATATYPE_LONG_DOUBLE_COMPLEX */ - (conversion_fct_t)copy_bool, /* OPAL_DATATYPE_BOOL */ - (conversion_fct_t)copy_wchar, /* OPAL_DATATYPE_WCHAR */ - (conversion_fct_t)NULL /* OPAL_DATATYPE_UNAVAILABLE */ + (conversion_fct_t) NULL, /* OPAL_DATATYPE_LOOP */ + (conversion_fct_t) NULL, /* OPAL_DATATYPE_END_LOOP */ + (conversion_fct_t) NULL, /* OPAL_DATATYPE_LB */ + (conversion_fct_t) NULL, /* OPAL_DATATYPE_UB */ + (conversion_fct_t) copy_bytes_1, /* OPAL_DATATYPE_INT1 */ + (conversion_fct_t) copy_bytes_2, /* OPAL_DATATYPE_INT2 */ + (conversion_fct_t) copy_bytes_4, /* OPAL_DATATYPE_INT4 */ + (conversion_fct_t) copy_bytes_8, /* OPAL_DATATYPE_INT8 */ + (conversion_fct_t) copy_bytes_16, /* OPAL_DATATYPE_INT16 */ + (conversion_fct_t) copy_bytes_1, /* OPAL_DATATYPE_UINT1 */ + (conversion_fct_t) copy_bytes_2, /* OPAL_DATATYPE_UINT2 */ + (conversion_fct_t) copy_bytes_4, /* OPAL_DATATYPE_UINT4 */ + (conversion_fct_t) copy_bytes_8, /* OPAL_DATATYPE_UINT8 */ + (conversion_fct_t) copy_bytes_16, /* OPAL_DATATYPE_UINT16 */ + (conversion_fct_t) copy_float_2, /* OPAL_DATATYPE_FLOAT2 */ + (conversion_fct_t) copy_float_4, /* OPAL_DATATYPE_FLOAT4 */ + (conversion_fct_t) copy_float_8, /* OPAL_DATATYPE_FLOAT8 */ + (conversion_fct_t) copy_float_12, /* OPAL_DATATYPE_FLOAT12 */ + (conversion_fct_t) copy_float_16, /* OPAL_DATATYPE_FLOAT16 */ + (conversion_fct_t) copy_short_float_complex, /* OPAL_DATATYPE_SHORT_FLOAT_COMPLEX */ + (conversion_fct_t) copy_float_complex, /* OPAL_DATATYPE_FLOAT_COMPLEX */ + (conversion_fct_t) copy_double_complex, /* OPAL_DATATYPE_DOUBLE_COMPLEX */ + (conversion_fct_t) copy_long_double_complex, /* OPAL_DATATYPE_LONG_DOUBLE_COMPLEX */ + (conversion_fct_t) copy_bool, /* OPAL_DATATYPE_BOOL */ + (conversion_fct_t) copy_wchar, /* OPAL_DATATYPE_WCHAR */ + (conversion_fct_t) NULL /* OPAL_DATATYPE_UNAVAILABLE */ }; diff --git a/opal/datatype/opal_copy_functions_heterogeneous.c b/opal/datatype/opal_copy_functions_heterogeneous.c index 7a3e7d57f92..be2adf33bce 100644 --- a/opal/datatype/opal_copy_functions_heterogeneous.c +++ b/opal/datatype/opal_copy_functions_heterogeneous.c @@ -17,7 +17,7 @@ #include "opal_config.h" #ifdef HAVE_IEEE754_H -#include +# include #endif #include @@ -25,13 +25,12 @@ #include "opal/util/arch.h" -#include "opal/types.h" -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" -#include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_datatype_checksum.h" #include "opal/datatype/opal_convertor_internal.h" - +#include "opal/datatype/opal_datatype.h" +#include "opal/datatype/opal_datatype_checksum.h" +#include "opal/datatype/opal_datatype_internal.h" +#include "opal/types.h" /* * Long-Term TODO: @@ -44,24 +43,24 @@ * A better way would be to have a conversion registration functionality. */ -static inline void -opal_dt_swap_bytes(void *to_p, const void *from_p, const size_t size, size_t count) +static inline void opal_dt_swap_bytes(void *to_p, const void *from_p, const size_t size, + size_t count) { size_t i; size_t back_i = size - 1; - uint8_t *to = (uint8_t*) to_p; - uint8_t *from = (uint8_t*) from_p; + uint8_t *to = (uint8_t *) to_p; + uint8_t *from = (uint8_t *) from_p; /* Do the first element */ - for (i = 0 ; i < size ; i++, back_i--) { + for (i = 0; i < size; i++, back_i--) { to[back_i] = from[i]; } /* Do all the others if any */ - while(count > 1) { + while (count > 1) { to += size; from += size; count--; - for (i = 0, back_i = size - 1 ; i < size ; i++, back_i--) { + for (i = 0, back_i = size - 1; i < size; i++, back_i--) { to[back_i] = from[i]; } } @@ -69,67 +68,69 @@ opal_dt_swap_bytes(void *to_p, const void *from_p, const size_t size, size_t cou #ifdef HAVE_IEEE754_H struct bit128 { - unsigned int mantissa3:32; - unsigned int mantissa2:32; - unsigned int mantissa1:32; - unsigned int mantissa0:16; - unsigned int exponent:15; - unsigned int negative:1; + unsigned int mantissa3 : 32; + unsigned int mantissa2 : 32; + unsigned int mantissa1 : 32; + unsigned int mantissa0 : 16; + unsigned int exponent : 15; + unsigned int negative : 1; }; struct bit80 { - unsigned int pad:32; - unsigned int empty:16; - unsigned int negative:1; - unsigned int exponent:15; - unsigned int mantissa0:32; - unsigned int mantissa1:32; + unsigned int pad : 32; + unsigned int empty : 16; + unsigned int negative : 1; + unsigned int exponent : 15; + unsigned int mantissa0 : 32; + unsigned int mantissa1 : 32; }; -static inline void -opal_dt_swap_long_double(void *to_p, const void *from_p, const size_t size, size_t count, uint32_t remoteArch) +static inline void opal_dt_swap_long_double(void *to_p, const void *from_p, const size_t size, + size_t count, uint32_t remoteArch) { -#ifdef HAVE_IEEE754_H +# ifdef HAVE_IEEE754_H - if ((opal_local_arch&OPAL_ARCH_LDISINTEL) && !(remoteArch&OPAL_ARCH_LDISINTEL)) { -#ifdef __x86_64 - long double*to = (long double *) to_p; + if ((opal_local_arch & OPAL_ARCH_LDISINTEL) && !(remoteArch & OPAL_ARCH_LDISINTEL)) { +# ifdef __x86_64 + long double *to = (long double *) to_p; - for (size_t i=0; imantissa0 << 15) & 0x7FFF8000) | ((b->mantissa1 >> 17) & 0x00007FFF); - ld.ieee.mantissa1 = ((b->mantissa1 << 15) & 0xFFFF8000) | ((b->mantissa2 << 17) & 0x000007FFF); + ld.ieee.mantissa0 = 0x80000000 | (((unsigned int) b->mantissa0 << 15) & 0x7FFF8000) + | ((b->mantissa1 >> 17) & 0x00007FFF); + ld.ieee.mantissa1 = ((b->mantissa1 << 15) & 0xFFFF8000) + | ((b->mantissa2 << 17) & 0x000007FFF); ld.ieee.exponent = b->exponent; ld.ieee.negative = b->negative; - MEMCPY( to, &ld, sizeof(long double)); + MEMCPY(to, &ld, sizeof(long double)); } -#endif - } else if (!(opal_local_arch&OPAL_ARCH_LDISINTEL) && (remoteArch&OPAL_ARCH_LDISINTEL)) { -#ifdef __sparcv9 - long double*to = (long double *) to_p; +# endif + } else if (!(opal_local_arch & OPAL_ARCH_LDISINTEL) && (remoteArch & OPAL_ARCH_LDISINTEL)) { +# ifdef __sparcv9 + long double *to = (long double *) to_p; - for (size_t i=0; imantissa0 << 1) | (b->mantissa1 & 0x80000000); ld.ieee.mantissa1 = (b->mantissa1 << 1) & 0xFFFFFFFE; ld.ieee.exponent = b->exponent; ld.ieee.negative = b->negative; - MEMCPY( to, &ld, sizeof(long double)); + MEMCPY(to, &ld, sizeof(long double)); } -#endif +# endif } -#else +# else assert(0); -#endif +# endif } #else -#define opal_dt_swap_long_double(to_p, from_p, size, count, remoteArch) +# define opal_dt_swap_long_double(to_p, from_p, size, count, remoteArch) #endif /** @@ -138,182 +139,179 @@ opal_dt_swap_long_double(void *to_p, const void *from_p, const size_t size, size * wrong endianess translation will be done. Instead, use the * COPY_2SAMETYPE_HETEROGENEOUS. */ -#define COPY_TYPE_HETEROGENEOUS( TYPENAME, TYPE ) \ - COPY_TYPE_HETEROGENEOUS_INTERNAL( TYPENAME, TYPE, 0 ) - -#define COPY_TYPE_HETEROGENEOUS_INTERNAL( TYPENAME, TYPE, LONG_DOUBLE ) \ -static int32_t \ -copy_##TYPENAME##_heterogeneous(opal_convertor_t *pConvertor, size_t count, \ - const char* from, size_t from_len, ptrdiff_t from_extent, \ - char* to, size_t to_length, ptrdiff_t to_extent, \ - ptrdiff_t *advance) \ -{ \ - size_t i; \ - \ - datatype_check( #TYPE, sizeof(TYPE), sizeof(TYPE), &count, \ - from, from_len, from_extent, \ - to, to_length, to_extent); \ - \ - if ((pConvertor->remoteArch & OPAL_ARCH_ISBIGENDIAN) != \ - (opal_local_arch & OPAL_ARCH_ISBIGENDIAN)) { \ - if( (to_extent == from_extent) && (to_extent == sizeof(TYPE)) ) { \ - opal_dt_swap_bytes(to, from, sizeof(TYPE), count); \ - if (LONG_DOUBLE) { \ - opal_dt_swap_long_double(to, from, sizeof(TYPE), count, pConvertor->remoteArch);\ - } \ - } else { \ - for( i = 0; i < count; i++ ) { \ - opal_dt_swap_bytes(to, from, sizeof(TYPE), 1); \ - if (LONG_DOUBLE) { \ - opal_dt_swap_long_double(to, from, sizeof(TYPE), 1, pConvertor->remoteArch);\ - } \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - } else if ((ptrdiff_t)sizeof(TYPE) == to_extent && \ - (ptrdiff_t)sizeof(TYPE) == from_extent) { \ - MEMCPY( to, from, count * sizeof(TYPE) ); \ - } else { \ - /* source or destination are non-contigous */ \ - for( i = 0; i < count; i++ ) { \ - MEMCPY( to, from, sizeof(TYPE) ); \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - *advance = count * from_extent; \ - return count; \ -} - -#define COPY_2SAMETYPE_HETEROGENEOUS( TYPENAME, TYPE ) \ - COPY_2SAMETYPE_HETEROGENEOUS_INTERNAL( TYPENAME, TYPE, 0) - -#define COPY_2SAMETYPE_HETEROGENEOUS_INTERNAL( TYPENAME, TYPE, LONG_DOUBLE) \ -static int32_t \ -copy_##TYPENAME##_heterogeneous(opal_convertor_t *pConvertor, size_t count, \ - const char* from, size_t from_len, ptrdiff_t from_extent, \ - char* to, size_t to_length, ptrdiff_t to_extent, \ - ptrdiff_t *advance) \ -{ \ - size_t i; \ - \ - datatype_check( #TYPE, sizeof(TYPE), sizeof(TYPE), &count, \ - from, from_len, from_extent, \ - to, to_length, to_extent); \ - \ - if ((pConvertor->remoteArch & OPAL_ARCH_ISBIGENDIAN) != \ - (opal_local_arch & OPAL_ARCH_ISBIGENDIAN)) { \ - if( (to_extent == from_extent) && (to_extent == (2 * sizeof(TYPE))) ) { \ - opal_dt_swap_bytes(to, from, sizeof(TYPE), 2 * count); \ - if (LONG_DOUBLE) { \ - opal_dt_swap_long_double(to, from, sizeof(TYPE), 2*count, pConvertor->remoteArch);\ - } \ - } else { \ - for( i = 0; i < count; i++ ) { \ - opal_dt_swap_bytes(to, from, sizeof(TYPE), 2); \ - if (LONG_DOUBLE) { \ - opal_dt_swap_long_double(to, from, sizeof(TYPE), 2, pConvertor->remoteArch);\ - } \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - } else if ((ptrdiff_t)sizeof(TYPE) == to_extent && \ - (ptrdiff_t)sizeof(TYPE) == from_extent) { \ - MEMCPY( to, from, count * sizeof(TYPE) ); \ - } else { \ - /* source or destination are non-contigous */ \ - for( i = 0; i < count; i++ ) { \ - MEMCPY( to, from, sizeof(TYPE) ); \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - *advance = count * from_extent; \ - return count; \ -} +#define COPY_TYPE_HETEROGENEOUS(TYPENAME, TYPE) COPY_TYPE_HETEROGENEOUS_INTERNAL(TYPENAME, TYPE, 0) + +#define COPY_TYPE_HETEROGENEOUS_INTERNAL(TYPENAME, TYPE, LONG_DOUBLE) \ + static int32_t copy_##TYPENAME##_heterogeneous(opal_convertor_t *pConvertor, size_t count, \ + const char *from, size_t from_len, \ + ptrdiff_t from_extent, char *to, \ + size_t to_length, ptrdiff_t to_extent, \ + ptrdiff_t *advance) \ + { \ + size_t i; \ + \ + datatype_check(#TYPE, sizeof(TYPE), sizeof(TYPE), &count, from, from_len, from_extent, to, \ + to_length, to_extent); \ + \ + if ((pConvertor->remoteArch & OPAL_ARCH_ISBIGENDIAN) \ + != (opal_local_arch & OPAL_ARCH_ISBIGENDIAN)) { \ + if ((to_extent == from_extent) && (to_extent == sizeof(TYPE))) { \ + opal_dt_swap_bytes(to, from, sizeof(TYPE), count); \ + if (LONG_DOUBLE) { \ + opal_dt_swap_long_double(to, from, sizeof(TYPE), count, \ + pConvertor->remoteArch); \ + } \ + } else { \ + for (i = 0; i < count; i++) { \ + opal_dt_swap_bytes(to, from, sizeof(TYPE), 1); \ + if (LONG_DOUBLE) { \ + opal_dt_swap_long_double(to, from, sizeof(TYPE), 1, \ + pConvertor->remoteArch); \ + } \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + } else if ((ptrdiff_t) sizeof(TYPE) == to_extent \ + && (ptrdiff_t) sizeof(TYPE) == from_extent) { \ + MEMCPY(to, from, count * sizeof(TYPE)); \ + } else { \ + /* source or destination are non-contigous */ \ + for (i = 0; i < count; i++) { \ + MEMCPY(to, from, sizeof(TYPE)); \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + *advance = count * from_extent; \ + return count; \ + } -#define COPY_2TYPE_HETEROGENEOUS( TYPENAME, TYPE1, TYPE2 ) \ -static int32_t \ -copy_##TYPENAME##_heterogeneous(opal_convertor_t *pConvertor, size_t count, \ - const char* from, size_t from_len, ptrdiff_t from_extent, \ - char* to, size_t to_length, ptrdiff_t to_extent, \ - ptrdiff_t *advance) \ -{ \ - size_t i; \ - \ - datatype_check( #TYPENAME, sizeof(TYPE1) + sizeof(TYPE2), \ - sizeof(TYPE1) + sizeof(TYPE2), &count, \ - from, from_len, from_extent, \ - to, to_length, to_extent); \ - \ - if ((pConvertor->remoteArch & OPAL_ARCH_ISBIGENDIAN) != \ - (opal_local_arch & OPAL_ARCH_ISBIGENDIAN)) { \ - /* source and destination are different endianness */ \ - for( i = 0; i < count; i++ ) { \ - TYPE1* to_1, *from_1; \ - TYPE2* to_2, *from_2; \ - to_1 = (TYPE1*) to; from_1 = (TYPE1*) from; \ - opal_dt_swap_bytes(to_1, from_1, sizeof(TYPE1), 1); \ - to_2 = (TYPE2*) (to_1 + 1); from_2 = (TYPE2*) (from_1 + 1); \ - opal_dt_swap_bytes(to_2, from_2, sizeof(TYPE2), 1); \ - to += to_extent; \ - from += from_extent; \ - } \ - } else if ((ptrdiff_t)(sizeof(TYPE1) + sizeof(TYPE2)) == to_extent && \ - (ptrdiff_t)(sizeof(TYPE1) + sizeof(TYPE2)) == from_extent) { \ - /* source and destination are contigous */ \ - MEMCPY( to, from, count * (sizeof(TYPE1) + sizeof(TYPE2)) ); \ - } else { \ - /* source or destination are non-contigous */ \ - for( i = 0; i < count; i++ ) { \ - MEMCPY( to, from, sizeof(TYPE1) + sizeof(TYPE2) ); \ - to += to_extent; \ - from += from_extent; \ - } \ - } \ - *advance = count * from_extent; \ - return count; \ -} +#define COPY_2SAMETYPE_HETEROGENEOUS(TYPENAME, TYPE) \ + COPY_2SAMETYPE_HETEROGENEOUS_INTERNAL(TYPENAME, TYPE, 0) + +#define COPY_2SAMETYPE_HETEROGENEOUS_INTERNAL(TYPENAME, TYPE, LONG_DOUBLE) \ + static int32_t copy_##TYPENAME##_heterogeneous(opal_convertor_t *pConvertor, size_t count, \ + const char *from, size_t from_len, \ + ptrdiff_t from_extent, char *to, \ + size_t to_length, ptrdiff_t to_extent, \ + ptrdiff_t *advance) \ + { \ + size_t i; \ + \ + datatype_check(#TYPE, sizeof(TYPE), sizeof(TYPE), &count, from, from_len, from_extent, to, \ + to_length, to_extent); \ + \ + if ((pConvertor->remoteArch & OPAL_ARCH_ISBIGENDIAN) \ + != (opal_local_arch & OPAL_ARCH_ISBIGENDIAN)) { \ + if ((to_extent == from_extent) && (to_extent == (2 * sizeof(TYPE)))) { \ + opal_dt_swap_bytes(to, from, sizeof(TYPE), 2 * count); \ + if (LONG_DOUBLE) { \ + opal_dt_swap_long_double(to, from, sizeof(TYPE), 2 * count, \ + pConvertor->remoteArch); \ + } \ + } else { \ + for (i = 0; i < count; i++) { \ + opal_dt_swap_bytes(to, from, sizeof(TYPE), 2); \ + if (LONG_DOUBLE) { \ + opal_dt_swap_long_double(to, from, sizeof(TYPE), 2, \ + pConvertor->remoteArch); \ + } \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + } else if ((ptrdiff_t) sizeof(TYPE) == to_extent \ + && (ptrdiff_t) sizeof(TYPE) == from_extent) { \ + MEMCPY(to, from, count * sizeof(TYPE)); \ + } else { \ + /* source or destination are non-contigous */ \ + for (i = 0; i < count; i++) { \ + MEMCPY(to, from, sizeof(TYPE)); \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + *advance = count * from_extent; \ + return count; \ + } +#define COPY_2TYPE_HETEROGENEOUS(TYPENAME, TYPE1, TYPE2) \ + static int32_t copy_##TYPENAME##_heterogeneous(opal_convertor_t *pConvertor, size_t count, \ + const char *from, size_t from_len, \ + ptrdiff_t from_extent, char *to, \ + size_t to_length, ptrdiff_t to_extent, \ + ptrdiff_t *advance) \ + { \ + size_t i; \ + \ + datatype_check(#TYPENAME, sizeof(TYPE1) + sizeof(TYPE2), sizeof(TYPE1) + sizeof(TYPE2), \ + &count, from, from_len, from_extent, to, to_length, to_extent); \ + \ + if ((pConvertor->remoteArch & OPAL_ARCH_ISBIGENDIAN) \ + != (opal_local_arch & OPAL_ARCH_ISBIGENDIAN)) { \ + /* source and destination are different endianness */ \ + for (i = 0; i < count; i++) { \ + TYPE1 *to_1, *from_1; \ + TYPE2 *to_2, *from_2; \ + to_1 = (TYPE1 *) to; \ + from_1 = (TYPE1 *) from; \ + opal_dt_swap_bytes(to_1, from_1, sizeof(TYPE1), 1); \ + to_2 = (TYPE2 *) (to_1 + 1); \ + from_2 = (TYPE2 *) (from_1 + 1); \ + opal_dt_swap_bytes(to_2, from_2, sizeof(TYPE2), 1); \ + to += to_extent; \ + from += from_extent; \ + } \ + } else if ((ptrdiff_t)(sizeof(TYPE1) + sizeof(TYPE2)) == to_extent \ + && (ptrdiff_t)(sizeof(TYPE1) + sizeof(TYPE2)) == from_extent) { \ + /* source and destination are contigous */ \ + MEMCPY(to, from, count *(sizeof(TYPE1) + sizeof(TYPE2))); \ + } else { \ + /* source or destination are non-contigous */ \ + for (i = 0; i < count; i++) { \ + MEMCPY(to, from, sizeof(TYPE1) + sizeof(TYPE2)); \ + to += to_extent; \ + from += from_extent; \ + } \ + } \ + *advance = count * from_extent; \ + return count; \ + } -static inline void -datatype_check(char *type, size_t local_size, size_t remote_size, size_t *count, - const char* from, size_t from_len, ptrdiff_t from_extent, - char* to, size_t to_len, ptrdiff_t to_extent) +static inline void datatype_check(char *type, size_t local_size, size_t remote_size, size_t *count, + const char *from, size_t from_len, ptrdiff_t from_extent, + char *to, size_t to_len, ptrdiff_t to_extent) { /* make sure the remote buffer is large enough to hold the data */ - if( (remote_size * *count) > from_len ) { + if ((remote_size * *count) > from_len) { *count = from_len / remote_size; - if( (*count * remote_size) != from_len ) { - DUMP( "oops should I keep this data somewhere (excedent %d bytes)?\n", - from_len - (*count * remote_size) ); + if ((*count * remote_size) != from_len) { + DUMP("oops should I keep this data somewhere (excedent %d bytes)?\n", + from_len - (*count * remote_size)); } - DUMP( "correct: copy %s count %d from buffer %p with length %d to %p space %d\n", - "char", *count, from, from_len, to, to_len ); + DUMP("correct: copy %s count %d from buffer %p with length %d to %p space %d\n", "char", + *count, from, from_len, to, to_len); } else { - DUMP( " copy %s count %d from buffer %p with length %d to %p space %d\n", - "char", *count, from, from_len, to, to_len ); + DUMP(" copy %s count %d from buffer %p with length %d to %p space %d\n", "char", + *count, from, from_len, to, to_len); } } -#define CXX_BOOL_COPY_LOOP(TYPE) \ - for(size_t i = 0; i < count; i++ ) { \ - bool *to_real = (bool*) to; \ - *to_real = *((TYPE*) from) == 0 ? false : true; \ - to += to_extent; \ - from += from_extent; \ +#define CXX_BOOL_COPY_LOOP(TYPE) \ + for (size_t i = 0; i < count; i++) { \ + bool *to_real = (bool *) to; \ + *to_real = *((TYPE *) from) == 0 ? false : true; \ + to += to_extent; \ + from += from_extent; \ } -static int32_t -copy_cxx_bool_heterogeneous(opal_convertor_t *pConvertor, size_t count, - const char* from, size_t from_len, ptrdiff_t from_extent, - char* to, size_t to_length, ptrdiff_t to_extent, - ptrdiff_t *advance) +static int32_t copy_cxx_bool_heterogeneous(opal_convertor_t *pConvertor, size_t count, + const char *from, size_t from_len, ptrdiff_t from_extent, + char *to, size_t to_length, ptrdiff_t to_extent, + ptrdiff_t *advance) { /* fix up the from extent */ - if ((pConvertor->remoteArch & OPAL_ARCH_BOOLISxx) != - (opal_local_arch & OPAL_ARCH_BOOLISxx)) { + if ((pConvertor->remoteArch & OPAL_ARCH_BOOLISxx) != (opal_local_arch & OPAL_ARCH_BOOLISxx)) { switch (pConvertor->remoteArch & OPAL_ARCH_BOOLISxx) { case OPAL_ARCH_BOOLIS8: from_extent = 1; @@ -327,13 +325,12 @@ copy_cxx_bool_heterogeneous(opal_convertor_t *pConvertor, size_t count, } } - datatype_check( "bool", sizeof(bool), sizeof(bool), &count, - from, from_len, from_extent, - to, to_length, to_extent); + datatype_check("bool", sizeof(bool), sizeof(bool), &count, from, from_len, from_extent, to, + to_length, to_extent); - if ((to_extent != sizeof(bool) || from_extent != sizeof(bool)) || - ((pConvertor->remoteArch & OPAL_ARCH_BOOLISxx) != - (opal_local_arch & OPAL_ARCH_BOOLISxx))) { + if ((to_extent != sizeof(bool) || from_extent != sizeof(bool)) + || ((pConvertor->remoteArch & OPAL_ARCH_BOOLISxx) + != (opal_local_arch & OPAL_ARCH_BOOLISxx))) { switch (pConvertor->remoteArch & OPAL_ARCH_BOOLISxx) { case OPAL_ARCH_BOOLIS8: CXX_BOOL_COPY_LOOP(int8_t); @@ -346,148 +343,146 @@ copy_cxx_bool_heterogeneous(opal_convertor_t *pConvertor, size_t count, break; } } else { - MEMCPY( to, from, count * sizeof(bool) ); + MEMCPY(to, from, count * sizeof(bool)); } *advance = count * from_extent; return count; } - COPY_TYPE_HETEROGENEOUS(int1, int8_t) COPY_TYPE_HETEROGENEOUS(int2, int16_t) COPY_TYPE_HETEROGENEOUS(int4, int32_t) #ifdef HAVE_INT64_T COPY_TYPE_HETEROGENEOUS(int8, int64_t) #else -#define copy_int8_heterogeneous NULL +# define copy_int8_heterogeneous NULL #endif #ifdef HAVE_INT128_T COPY_TYPE_HETEROGENEOUS(int16, int128_t) #else -#define copy_int16_heterogeneous NULL +# define copy_int16_heterogeneous NULL #endif - #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 2 -COPY_TYPE_HETEROGENEOUS( float2, short float ) +COPY_TYPE_HETEROGENEOUS(float2, short float) #elif SIZEOF_FLOAT == 2 -COPY_TYPE_HETEROGENEOUS( float2, float ) +COPY_TYPE_HETEROGENEOUS(float2, float) #elif SIZEOF_DOUBLE == 2 -COPY_TYPE_HETEROGENEOUS( float2, double ) +COPY_TYPE_HETEROGENEOUS(float2, double) #elif SIZEOF_LONG_DOUBLE == 2 -COPY_TYPE_HETEROGENEOUS( float2, long double ) +COPY_TYPE_HETEROGENEOUS(float2, long double) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 2 -COPY_TYPE_HETEROGENEOUS( float2, opal_short_float_t ) +COPY_TYPE_HETEROGENEOUS(float2, opal_short_float_t) #else /* #error No basic type for copy function for opal_datatype_float2 found */ -#define copy_float2_heterogeneous NULL +# define copy_float2_heterogeneous NULL #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 4 -COPY_TYPE_HETEROGENEOUS( float4, short float ) +COPY_TYPE_HETEROGENEOUS(float4, short float) #elif SIZEOF_FLOAT == 4 -COPY_TYPE_HETEROGENEOUS( float4, float ) +COPY_TYPE_HETEROGENEOUS(float4, float) #elif SIZEOF_DOUBLE == 4 -COPY_TYPE_HETEROGENEOUS( float4, double ) +COPY_TYPE_HETEROGENEOUS(float4, double) #elif SIZEOF_LONG_DOUBLE == 4 -COPY_TYPE_HETEROGENEOUS( float4, long double ) +COPY_TYPE_HETEROGENEOUS(float4, long double) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 4 -COPY_TYPE_HETEROGENEOUS( float4, opal_short_float_t ) +COPY_TYPE_HETEROGENEOUS(float4, opal_short_float_t) #else /* #error No basic type for copy function for opal_datatype_float4 found */ -#define copy_float4_heterogeneous NULL +# define copy_float4_heterogeneous NULL #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 8 -COPY_TYPE_HETEROGENEOUS( float8, short float ) +COPY_TYPE_HETEROGENEOUS(float8, short float) #elif SIZEOF_FLOAT == 8 -COPY_TYPE_HETEROGENEOUS( float8, float ) +COPY_TYPE_HETEROGENEOUS(float8, float) #elif SIZEOF_DOUBLE == 8 -COPY_TYPE_HETEROGENEOUS( float8, double ) +COPY_TYPE_HETEROGENEOUS(float8, double) #elif SIZEOF_LONG_DOUBLE == 8 -COPY_TYPE_HETEROGENEOUS( float8, long double ) +COPY_TYPE_HETEROGENEOUS(float8, long double) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 8 -COPY_TYPE_HETEROGENEOUS( float8, opal_short_float_t ) +COPY_TYPE_HETEROGENEOUS(float8, opal_short_float_t) #else /* #error No basic type for copy function for opal_datatype_float8 found */ -#define copy_float8_heterogeneous NULL +# define copy_float8_heterogeneous NULL #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 12 -COPY_TYPE_HETEROGENEOUS( float12, short float ) +COPY_TYPE_HETEROGENEOUS(float12, short float) #elif SIZEOF_FLOAT == 12 -COPY_TYPE_HETEROGENEOUS( float12, float ) +COPY_TYPE_HETEROGENEOUS(float12, float) #elif SIZEOF_DOUBLE == 12 -COPY_TYPE_HETEROGENEOUS( float12, double ) +COPY_TYPE_HETEROGENEOUS(float12, double) #elif SIZEOF_LONG_DOUBLE == 12 -COPY_TYPE_HETEROGENEOUS( float12, long double ) +COPY_TYPE_HETEROGENEOUS(float12, long double) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 12 -COPY_TYPE_HETEROGENEOUS( float12, opal_short_float_t ) +COPY_TYPE_HETEROGENEOUS(float12, opal_short_float_t) #else /* #error No basic type for copy function for opal_datatype_float12 found */ -#define copy_float12_heterogeneous NULL +# define copy_float12_heterogeneous NULL #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 16 -COPY_TYPE_HETEROGENEOUS( float16, short float ) +COPY_TYPE_HETEROGENEOUS(float16, short float) #elif SIZEOF_FLOAT == 16 -COPY_TYPE_HETEROGENEOUS( float16, float ) +COPY_TYPE_HETEROGENEOUS(float16, float) #elif SIZEOF_DOUBLE == 16 -COPY_TYPE_HETEROGENEOUS( float16, double ) +COPY_TYPE_HETEROGENEOUS(float16, double) #elif SIZEOF_LONG_DOUBLE == 16 -COPY_TYPE_HETEROGENEOUS_INTERNAL( float16, long double, 1) +COPY_TYPE_HETEROGENEOUS_INTERNAL(float16, long double, 1) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 16 -COPY_TYPE_HETEROGENEOUS( float16, opal_short_float_t ) +COPY_TYPE_HETEROGENEOUS(float16, opal_short_float_t) #else /* #error No basic type for copy function for opal_datatype_float16 found */ -#define copy_float16_heterogeneous NULL +# define copy_float16_heterogeneous NULL #endif #if defined(HAVE_SHORT_FLOAT__COMPLEX) -COPY_2SAMETYPE_HETEROGENEOUS( short_float_complex, short float _Complex ) +COPY_2SAMETYPE_HETEROGENEOUS(short_float_complex, short float _Complex) #elif defined(HAVE_OPAL_SHORT_FLOAT_COMPLEX_T) -COPY_2SAMETYPE_HETEROGENEOUS( short_float_complex, opal_short_float_complex_t ) +COPY_2SAMETYPE_HETEROGENEOUS(short_float_complex, opal_short_float_complex_t) #else /* #error No basic type for copy function for opal_datatype_short_float_complex found */ -#define copy_short_float_complex_heterogeneous NULL +# define copy_short_float_complex_heterogeneous NULL #endif -COPY_2SAMETYPE_HETEROGENEOUS( float_complex, float ) +COPY_2SAMETYPE_HETEROGENEOUS(float_complex, float) -COPY_2SAMETYPE_HETEROGENEOUS( double_complex, double ) +COPY_2SAMETYPE_HETEROGENEOUS(double_complex, double) -COPY_2SAMETYPE_HETEROGENEOUS_INTERNAL( long_double_complex, long double, 1) +COPY_2SAMETYPE_HETEROGENEOUS_INTERNAL(long_double_complex, long double, 1) -COPY_TYPE_HETEROGENEOUS (wchar, wchar_t) +COPY_TYPE_HETEROGENEOUS(wchar, wchar_t) /* table of predefined copy functions - one for each MPI type */ conversion_fct_t opal_datatype_heterogeneous_copy_functions[OPAL_DATATYPE_MAX_PREDEFINED] = { - [OPAL_DATATYPE_LOOP] = NULL, - [OPAL_DATATYPE_END_LOOP] = NULL, - [OPAL_DATATYPE_LB] = NULL, - [OPAL_DATATYPE_UB] = NULL, - [OPAL_DATATYPE_INT1] = (conversion_fct_t) copy_int1_heterogeneous, - [OPAL_DATATYPE_INT2] = (conversion_fct_t) copy_int2_heterogeneous, - [OPAL_DATATYPE_INT4] = (conversion_fct_t) copy_int4_heterogeneous, - [OPAL_DATATYPE_INT8] = (conversion_fct_t) copy_int8_heterogeneous, - [OPAL_DATATYPE_INT16] = (conversion_fct_t) copy_int16_heterogeneous, - [OPAL_DATATYPE_UINT1] = (conversion_fct_t) copy_int1_heterogeneous, - [OPAL_DATATYPE_UINT2] = (conversion_fct_t) copy_int2_heterogeneous, - [OPAL_DATATYPE_UINT4] = (conversion_fct_t) copy_int4_heterogeneous, - [OPAL_DATATYPE_UINT8] = (conversion_fct_t) copy_int8_heterogeneous, - [OPAL_DATATYPE_UINT16] = (conversion_fct_t) copy_int16_heterogeneous, - [OPAL_DATATYPE_FLOAT2] = (conversion_fct_t) copy_float2_heterogeneous, - [OPAL_DATATYPE_FLOAT4] = (conversion_fct_t) copy_float4_heterogeneous, - [OPAL_DATATYPE_FLOAT8] = (conversion_fct_t) copy_float8_heterogeneous, - [OPAL_DATATYPE_FLOAT12] = (conversion_fct_t) copy_float12_heterogeneous, - [OPAL_DATATYPE_FLOAT16] = (conversion_fct_t) copy_float16_heterogeneous, - [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = (conversion_fct_t) copy_short_float_complex_heterogeneous, - [OPAL_DATATYPE_FLOAT_COMPLEX] = (conversion_fct_t) copy_float_complex_heterogeneous, - [OPAL_DATATYPE_DOUBLE_COMPLEX] = (conversion_fct_t) copy_double_complex_heterogeneous, - [OPAL_DATATYPE_LONG_DOUBLE_COMPLEX] = (conversion_fct_t) copy_long_double_complex_heterogeneous, - [OPAL_DATATYPE_BOOL] = (conversion_fct_t) copy_cxx_bool_heterogeneous, - [OPAL_DATATYPE_WCHAR] = (conversion_fct_t) copy_wchar_heterogeneous, - [OPAL_DATATYPE_UNAVAILABLE] = NULL, + [OPAL_DATATYPE_LOOP] = NULL, + [OPAL_DATATYPE_END_LOOP] = NULL, + [OPAL_DATATYPE_LB] = NULL, + [OPAL_DATATYPE_UB] = NULL, + [OPAL_DATATYPE_INT1] = (conversion_fct_t) copy_int1_heterogeneous, + [OPAL_DATATYPE_INT2] = (conversion_fct_t) copy_int2_heterogeneous, + [OPAL_DATATYPE_INT4] = (conversion_fct_t) copy_int4_heterogeneous, + [OPAL_DATATYPE_INT8] = (conversion_fct_t) copy_int8_heterogeneous, + [OPAL_DATATYPE_INT16] = (conversion_fct_t) copy_int16_heterogeneous, + [OPAL_DATATYPE_UINT1] = (conversion_fct_t) copy_int1_heterogeneous, + [OPAL_DATATYPE_UINT2] = (conversion_fct_t) copy_int2_heterogeneous, + [OPAL_DATATYPE_UINT4] = (conversion_fct_t) copy_int4_heterogeneous, + [OPAL_DATATYPE_UINT8] = (conversion_fct_t) copy_int8_heterogeneous, + [OPAL_DATATYPE_UINT16] = (conversion_fct_t) copy_int16_heterogeneous, + [OPAL_DATATYPE_FLOAT2] = (conversion_fct_t) copy_float2_heterogeneous, + [OPAL_DATATYPE_FLOAT4] = (conversion_fct_t) copy_float4_heterogeneous, + [OPAL_DATATYPE_FLOAT8] = (conversion_fct_t) copy_float8_heterogeneous, + [OPAL_DATATYPE_FLOAT12] = (conversion_fct_t) copy_float12_heterogeneous, + [OPAL_DATATYPE_FLOAT16] = (conversion_fct_t) copy_float16_heterogeneous, + [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = (conversion_fct_t) copy_short_float_complex_heterogeneous, + [OPAL_DATATYPE_FLOAT_COMPLEX] = (conversion_fct_t) copy_float_complex_heterogeneous, + [OPAL_DATATYPE_DOUBLE_COMPLEX] = (conversion_fct_t) copy_double_complex_heterogeneous, + [OPAL_DATATYPE_LONG_DOUBLE_COMPLEX] = (conversion_fct_t) copy_long_double_complex_heterogeneous, + [OPAL_DATATYPE_BOOL] = (conversion_fct_t) copy_cxx_bool_heterogeneous, + [OPAL_DATATYPE_WCHAR] = (conversion_fct_t) copy_wchar_heterogeneous, + [OPAL_DATATYPE_UNAVAILABLE] = NULL, }; diff --git a/opal/datatype/opal_datatype.h b/opal/datatype/opal_datatype.h index 8f054f7c7b0..41da0f40d35 100644 --- a/opal/datatype/opal_datatype.h +++ b/opal/datatype/opal_datatype.h @@ -52,7 +52,7 @@ BEGIN_C_DECLS * This must match the same definition as in opal_datatype_internal.h */ #if !defined(OPAL_DATATYPE_MAX_PREDEFINED) -#define OPAL_DATATYPE_MAX_PREDEFINED 26 +# define OPAL_DATATYPE_MAX_PREDEFINED 26 #endif /* * No more than this number of _Basic_ datatypes in C/CPP or Fortran @@ -61,28 +61,29 @@ BEGIN_C_DECLS * * BEWARE: This constant should reflect whatever the OMPI-layer needs. */ -#define OPAL_DATATYPE_MAX_SUPPORTED 50 - +#define OPAL_DATATYPE_MAX_SUPPORTED 50 /* flags for the datatypes. */ -#define OPAL_DATATYPE_FLAG_UNAVAILABLE 0x0001 /**< datatypes unavailable on the build (OS or compiler dependant) */ -#define OPAL_DATATYPE_FLAG_PREDEFINED 0x0002 /**< cannot be removed: initial and predefined datatypes */ -#define OPAL_DATATYPE_FLAG_COMMITTED 0x0004 /**< ready to be used for a send/recv operation */ -#define OPAL_DATATYPE_FLAG_OVERLAP 0x0008 /**< datatype is unpropper for a recv operation */ -#define OPAL_DATATYPE_FLAG_CONTIGUOUS 0x0010 /**< contiguous datatype */ -#define OPAL_DATATYPE_FLAG_NO_GAPS 0x0020 /**< no gaps around the datatype, aka OPAL_DATATYPE_FLAG_CONTIGUOUS and extent == size */ -#define OPAL_DATATYPE_FLAG_USER_LB 0x0040 /**< has a user defined LB */ -#define OPAL_DATATYPE_FLAG_USER_UB 0x0080 /**< has a user defined UB */ -#define OPAL_DATATYPE_FLAG_DATA 0x0100 /**< data or control structure */ +#define OPAL_DATATYPE_FLAG_UNAVAILABLE \ + 0x0001 /**< datatypes unavailable on the build (OS or compiler dependant) */ +#define OPAL_DATATYPE_FLAG_PREDEFINED \ + 0x0002 /**< cannot be removed: initial and predefined datatypes */ +#define OPAL_DATATYPE_FLAG_COMMITTED 0x0004 /**< ready to be used for a send/recv operation */ +#define OPAL_DATATYPE_FLAG_OVERLAP 0x0008 /**< datatype is unpropper for a recv operation */ +#define OPAL_DATATYPE_FLAG_CONTIGUOUS 0x0010 /**< contiguous datatype */ +#define OPAL_DATATYPE_FLAG_NO_GAPS \ + 0x0020 /**< no gaps around the datatype, aka OPAL_DATATYPE_FLAG_CONTIGUOUS and extent == size \ + */ +#define OPAL_DATATYPE_FLAG_USER_LB 0x0040 /**< has a user defined LB */ +#define OPAL_DATATYPE_FLAG_USER_UB 0x0080 /**< has a user defined UB */ +#define OPAL_DATATYPE_FLAG_DATA 0x0100 /**< data or control structure */ /* * We should make the difference here between the predefined contiguous and non contiguous * datatypes. The OPAL_DATATYPE_FLAG_BASIC is held by all predefined contiguous datatypes. */ -#define OPAL_DATATYPE_FLAG_BASIC (OPAL_DATATYPE_FLAG_PREDEFINED | \ - OPAL_DATATYPE_FLAG_CONTIGUOUS | \ - OPAL_DATATYPE_FLAG_NO_GAPS | \ - OPAL_DATATYPE_FLAG_DATA | \ - OPAL_DATATYPE_FLAG_COMMITTED) +#define OPAL_DATATYPE_FLAG_BASIC \ + (OPAL_DATATYPE_FLAG_PREDEFINED | OPAL_DATATYPE_FLAG_CONTIGUOUS | OPAL_DATATYPE_FLAG_NO_GAPS \ + | OPAL_DATATYPE_FLAG_DATA | OPAL_DATATYPE_FLAG_COMMITTED) /** * The number of supported entries in the data-type definition and the @@ -94,44 +95,43 @@ typedef size_t opal_datatype_count_t; typedef union dt_elem_desc dt_elem_desc_t; struct dt_type_desc_t { - opal_datatype_count_t length; /**< the maximum number of elements in the description array */ - opal_datatype_count_t used; /**< the number of used elements in the description array */ - dt_elem_desc_t* desc; + opal_datatype_count_t length; /**< the maximum number of elements in the description array */ + opal_datatype_count_t used; /**< the number of used elements in the description array */ + dt_elem_desc_t *desc; }; typedef struct dt_type_desc_t dt_type_desc_t; - /* * The datatype description. */ struct opal_datatype_t { - opal_object_t super; /**< basic superclass */ - uint16_t flags; /**< the flags */ - uint16_t id; /**< data id, normally the index in the data array. */ - uint32_t bdt_used; /**< bitset of which basic datatypes are used in the data description */ - size_t size; /**< total size in bytes of the memory used by the data if - the data is put on a contiguous buffer */ - ptrdiff_t true_lb; /**< the true lb of the data without user defined lb and ub */ - ptrdiff_t true_ub; /**< the true ub of the data without user defined lb and ub */ - ptrdiff_t lb; /**< lower bound in memory */ - ptrdiff_t ub; /**< upper bound in memory */ + opal_object_t super; /**< basic superclass */ + uint16_t flags; /**< the flags */ + uint16_t id; /**< data id, normally the index in the data array. */ + uint32_t bdt_used; /**< bitset of which basic datatypes are used in the data description */ + size_t size; /**< total size in bytes of the memory used by the data if + the data is put on a contiguous buffer */ + ptrdiff_t true_lb; /**< the true lb of the data without user defined lb and ub */ + ptrdiff_t true_ub; /**< the true ub of the data without user defined lb and ub */ + ptrdiff_t lb; /**< lower bound in memory */ + ptrdiff_t ub; /**< upper bound in memory */ /* --- cacheline 1 boundary (64 bytes) --- */ - size_t nbElems; /**< total number of elements inside the datatype */ - uint32_t align; /**< data should be aligned to */ - uint32_t loops; /**< number of loops on the iternal type stack */ + size_t nbElems; /**< total number of elements inside the datatype */ + uint32_t align; /**< data should be aligned to */ + uint32_t loops; /**< number of loops on the iternal type stack */ /* Attribute fields */ - char name[OPAL_MAX_OBJECT_NAME]; /**< name of the datatype */ - dt_type_desc_t desc; /**< the data description */ - dt_type_desc_t opt_desc; /**< short description of the data used when conversion is useless - or in the send case (without conversion) */ - - size_t *ptypes; /**< array of basic predefined types that facilitate the computing - of the remote size in heterogeneous environments. The length of the - array is dependent on the maximum number of predefined datatypes of - all language interfaces (because Fortran is not known at the OPAL - layer). This field should never be initialized in homogeneous - environments */ + char name[OPAL_MAX_OBJECT_NAME]; /**< name of the datatype */ + dt_type_desc_t desc; /**< the data description */ + dt_type_desc_t opt_desc; /**< short description of the data used when conversion is useless + or in the send case (without conversion) */ + + size_t *ptypes; /**< array of basic predefined types that facilitate the computing + of the remote size in heterogeneous environments. The length of the + array is dependent on the maximum number of predefined datatypes of + all language interfaces (because Fortran is not known at the OPAL + layer). This field should never be initialized in homogeneous + environments */ /* --- cacheline 5 boundary (320 bytes) was 32-36 bytes ago --- */ /* size: 352, cachelines: 6, members: 15 */ @@ -140,9 +140,10 @@ struct opal_datatype_t { typedef struct opal_datatype_t opal_datatype_t; -OPAL_DECLSPEC OBJ_CLASS_DECLARATION( opal_datatype_t ); +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_datatype_t); -OPAL_DECLSPEC extern const opal_datatype_t* opal_datatype_basicDatatypes[OPAL_DATATYPE_MAX_PREDEFINED]; +OPAL_DECLSPEC extern const opal_datatype_t + *opal_datatype_basicDatatypes[OPAL_DATATYPE_MAX_PREDEFINED]; OPAL_DECLSPEC extern const size_t opal_datatype_local_sizes[OPAL_DATATYPE_MAX_PREDEFINED]; /* Local Architecture as provided by opal_arch_compute_local_id() */ @@ -156,21 +157,21 @@ OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_loop; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_end_loop; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_lb; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_ub; -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int1; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int2; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int4; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int8; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int16; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint1; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint2; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint4; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint8; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint16; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float2; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float4; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float8; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float12; /* in bytes */ -OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float16; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int1; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int2; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int4; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int8; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_int16; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint1; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint2; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint4; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint8; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_uint16; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float2; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float4; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float8; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float12; /* in bytes */ +OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float16; /* in bytes */ OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_short_float_complex; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_float_complex; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_double_complex; @@ -178,38 +179,33 @@ OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_long_double_complex; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_bool; OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_wchar; - /* * Functions exported externally */ int opal_datatype_register_params(void); -OPAL_DECLSPEC int32_t opal_datatype_init( void ); -OPAL_DECLSPEC opal_datatype_t* opal_datatype_create( int32_t expectedSize ); -OPAL_DECLSPEC int32_t opal_datatype_create_desc( opal_datatype_t * datatype, int32_t expectedSize ); -OPAL_DECLSPEC int32_t opal_datatype_commit( opal_datatype_t * pData ); -OPAL_DECLSPEC int32_t opal_datatype_destroy( opal_datatype_t** ); -OPAL_DECLSPEC int32_t opal_datatype_is_monotonic( opal_datatype_t* type); - -static inline int32_t -opal_datatype_is_committed( const opal_datatype_t* type ) +OPAL_DECLSPEC int32_t opal_datatype_init(void); +OPAL_DECLSPEC opal_datatype_t *opal_datatype_create(int32_t expectedSize); +OPAL_DECLSPEC int32_t opal_datatype_create_desc(opal_datatype_t *datatype, int32_t expectedSize); +OPAL_DECLSPEC int32_t opal_datatype_commit(opal_datatype_t *pData); +OPAL_DECLSPEC int32_t opal_datatype_destroy(opal_datatype_t **); +OPAL_DECLSPEC int32_t opal_datatype_is_monotonic(opal_datatype_t *type); + +static inline int32_t opal_datatype_is_committed(const opal_datatype_t *type) { return ((type->flags & OPAL_DATATYPE_FLAG_COMMITTED) == OPAL_DATATYPE_FLAG_COMMITTED); } -static inline int32_t -opal_datatype_is_overlapped( const opal_datatype_t* type ) +static inline int32_t opal_datatype_is_overlapped(const opal_datatype_t *type) { return ((type->flags & OPAL_DATATYPE_FLAG_OVERLAP) == OPAL_DATATYPE_FLAG_OVERLAP); } -static inline int32_t -opal_datatype_is_valid( const opal_datatype_t* type ) +static inline int32_t opal_datatype_is_valid(const opal_datatype_t *type) { return !((type->flags & OPAL_DATATYPE_FLAG_UNAVAILABLE) == OPAL_DATATYPE_FLAG_UNAVAILABLE); } -static inline int32_t -opal_datatype_is_predefined( const opal_datatype_t* type ) +static inline int32_t opal_datatype_is_predefined(const opal_datatype_t *type) { return (type->flags & OPAL_DATATYPE_FLAG_PREDEFINED); } @@ -218,103 +214,92 @@ opal_datatype_is_predefined( const opal_datatype_t* type ) * This function return true (1) if the datatype representation depending on the count * is contiguous in the memory. And false (0) otherwise. */ -static inline int32_t -opal_datatype_is_contiguous_memory_layout( const opal_datatype_t* datatype, int32_t count ) +static inline int32_t opal_datatype_is_contiguous_memory_layout(const opal_datatype_t *datatype, + int32_t count) { - if( !(datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) return 0; - if( (count == 1) || (datatype->flags & OPAL_DATATYPE_FLAG_NO_GAPS) ) return 1; + if (!(datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) + return 0; + if ((count == 1) || (datatype->flags & OPAL_DATATYPE_FLAG_NO_GAPS)) + return 1; return 0; } - -OPAL_DECLSPEC void -opal_datatype_dump( const opal_datatype_t* pData ); +OPAL_DECLSPEC void opal_datatype_dump(const opal_datatype_t *pData); /* data creation functions */ /** * Create a duplicate of the source datatype. */ -OPAL_DECLSPEC int32_t -opal_datatype_clone( const opal_datatype_t* src_type, - opal_datatype_t* dest_type ); +OPAL_DECLSPEC int32_t opal_datatype_clone(const opal_datatype_t *src_type, + opal_datatype_t *dest_type); /** * A contiguous array of identical datatypes. */ -OPAL_DECLSPEC int32_t -opal_datatype_create_contiguous( int count, const opal_datatype_t* oldType, - opal_datatype_t** newType ); +OPAL_DECLSPEC int32_t opal_datatype_create_contiguous(int count, const opal_datatype_t *oldType, + opal_datatype_t **newType); /** * Add a new datatype to the base type description. The count is the number * repetitions of the same element to be added, and the extent is the extent * of each element. The displacement is the initial displacement of the * first element. */ -OPAL_DECLSPEC int32_t -opal_datatype_add( opal_datatype_t* pdtBase, - const opal_datatype_t* pdtAdd, size_t count, - ptrdiff_t disp, ptrdiff_t extent ); +OPAL_DECLSPEC int32_t opal_datatype_add(opal_datatype_t *pdtBase, const opal_datatype_t *pdtAdd, + size_t count, ptrdiff_t disp, ptrdiff_t extent); /** * Alter the lb and extent of an existing datatype in place. */ -OPAL_DECLSPEC int32_t -opal_datatype_resize( opal_datatype_t* type, - ptrdiff_t lb, - ptrdiff_t extent ); +OPAL_DECLSPEC int32_t opal_datatype_resize(opal_datatype_t *type, ptrdiff_t lb, ptrdiff_t extent); -static inline int32_t -opal_datatype_type_lb( const opal_datatype_t* pData, ptrdiff_t* disp ) +static inline int32_t opal_datatype_type_lb(const opal_datatype_t *pData, ptrdiff_t *disp) { *disp = pData->lb; return 0; } -static inline int32_t -opal_datatype_type_ub( const opal_datatype_t* pData, ptrdiff_t* disp ) +static inline int32_t opal_datatype_type_ub(const opal_datatype_t *pData, ptrdiff_t *disp) { *disp = pData->ub; return 0; } -static inline int32_t -opal_datatype_type_size( const opal_datatype_t* pData, size_t *size ) +static inline int32_t opal_datatype_type_size(const opal_datatype_t *pData, size_t *size) { *size = pData->size; return 0; } -static inline int32_t -opal_datatype_type_extent( const opal_datatype_t* pData, ptrdiff_t* extent ) +static inline int32_t opal_datatype_type_extent(const opal_datatype_t *pData, ptrdiff_t *extent) { *extent = pData->ub - pData->lb; return 0; } -static inline int32_t -opal_datatype_get_extent( const opal_datatype_t* pData, ptrdiff_t* lb, ptrdiff_t* extent) +static inline int32_t opal_datatype_get_extent(const opal_datatype_t *pData, ptrdiff_t *lb, + ptrdiff_t *extent) { - *lb = pData->lb; *extent = pData->ub - pData->lb; + *lb = pData->lb; + *extent = pData->ub - pData->lb; return 0; } -static inline int32_t -opal_datatype_get_true_extent( const opal_datatype_t* pData, ptrdiff_t* true_lb, ptrdiff_t* true_extent) +static inline int32_t opal_datatype_get_true_extent(const opal_datatype_t *pData, + ptrdiff_t *true_lb, ptrdiff_t *true_extent) { *true_lb = pData->true_lb; *true_extent = (pData->true_ub - pData->true_lb); return 0; } -OPAL_DECLSPEC ssize_t -opal_datatype_get_element_count( const opal_datatype_t* pData, size_t iSize ); -OPAL_DECLSPEC int32_t -opal_datatype_set_element_count( const opal_datatype_t* pData, size_t count, size_t* length ); -OPAL_DECLSPEC int32_t -opal_datatype_copy_content_same_ddt( const opal_datatype_t* pData, int32_t count, - char* pDestBuf, char* pSrcBuf ); +OPAL_DECLSPEC ssize_t opal_datatype_get_element_count(const opal_datatype_t *pData, size_t iSize); +OPAL_DECLSPEC int32_t opal_datatype_set_element_count(const opal_datatype_t *pData, size_t count, + size_t *length); +OPAL_DECLSPEC int32_t opal_datatype_copy_content_same_ddt(const opal_datatype_t *pData, + int32_t count, char *pDestBuf, + char *pSrcBuf); -OPAL_DECLSPEC int opal_datatype_compute_ptypes( opal_datatype_t* datatype ); +OPAL_DECLSPEC int opal_datatype_compute_ptypes(opal_datatype_t *datatype); /* Compute the span in memory of count datatypes. This function help with temporary * memory allocations for receiving already typed data (such as those used for reduce @@ -325,9 +310,8 @@ OPAL_DECLSPEC int opal_datatype_compute_ptypes( opal_datatype_t* datatype ); * Returns: the memory span of count repetition of the datatype, and in the gap * argument, the number of bytes of the gap at the beginning. */ -static inline ptrdiff_t -opal_datatype_span( const opal_datatype_t* pData, size_t count, - ptrdiff_t* gap) +static inline ptrdiff_t opal_datatype_span(const opal_datatype_t *pData, size_t count, + ptrdiff_t *gap) { if (OPAL_UNLIKELY(0 == pData->size) || (0 == count)) { *gap = 0; @@ -344,12 +328,12 @@ opal_datatype_span( const opal_datatype_t* pData, size_t count, * Set a breakpoint to this function in your favorite debugger * to make it stop on all pack and unpack errors. */ -OPAL_DECLSPEC int -opal_datatype_safeguard_pointer_debug_breakpoint( const void* actual_ptr, int length, - const void* initial_ptr, - const opal_datatype_t* pData, - int count ); -#endif /* OPAL_ENABLE_DEBUG */ +OPAL_DECLSPEC int opal_datatype_safeguard_pointer_debug_breakpoint(const void *actual_ptr, + int length, + const void *initial_ptr, + const opal_datatype_t *pData, + int count); +#endif /* OPAL_ENABLE_DEBUG */ END_C_DECLS -#endif /* OPAL_DATATYPE_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_DATATYPE_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_datatype_add.c b/opal/datatype/opal_datatype_add.c index 7038d37a4c4..705956c19b5 100644 --- a/opal/datatype/opal_datatype_add.c +++ b/opal/datatype/opal_datatype_add.c @@ -26,66 +26,88 @@ #include #include "opal/constants.h" -#include "opal/util/output.h" #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" +#include "opal/util/output.h" /* macros to play with the flags */ -#define SET_CONTIGUOUS_FLAG( INT_VALUE ) (INT_VALUE) = (INT_VALUE) | (OPAL_DATATYPE_FLAG_CONTIGUOUS) -#define SET_NO_GAP_FLAG( INT_VALUE ) (INT_VALUE) = (INT_VALUE) | (OPAL_DATATYPE_FLAG_NO_GAPS) -#define UNSET_CONTIGUOUS_FLAG( INT_VALUE ) (INT_VALUE) = (INT_VALUE) & (~(OPAL_DATATYPE_FLAG_CONTIGUOUS | OPAL_DATATYPE_FLAG_NO_GAPS)) +#define SET_CONTIGUOUS_FLAG(INT_VALUE) (INT_VALUE) = (INT_VALUE) | (OPAL_DATATYPE_FLAG_CONTIGUOUS) +#define SET_NO_GAP_FLAG(INT_VALUE) (INT_VALUE) = (INT_VALUE) | (OPAL_DATATYPE_FLAG_NO_GAPS) +#define UNSET_CONTIGUOUS_FLAG(INT_VALUE) \ + (INT_VALUE) = (INT_VALUE) & (~(OPAL_DATATYPE_FLAG_CONTIGUOUS | OPAL_DATATYPE_FLAG_NO_GAPS)) #if defined(__GNUC__) && !defined(__STDC__) -#define LMAX(A,B) ({ ptrdiff_t _a = (A), _b = (B); (_a < _b ? _b : _a) }) -#define LMIN(A,B) ({ ptrdiff_t _a = (A), _b = (B); (_a < _b ? _a : _b); }) -#define IMAX(A,B) ({ int _a = (A), _b = (B); (_a < _b ? _b : _a); }) +# define LMAX(A, B) \ + ({ \ + ptrdiff_t _a = (A), _b = (B); \ + (_a < _b ? _b : _a) \ + }) +# define LMIN(A, B) \ + ({ \ + ptrdiff_t _a = (A), _b = (B); \ + (_a < _b ? _a : _b); \ + }) +# define IMAX(A, B) \ + ({ \ + int _a = (A), _b = (B); \ + (_a < _b ? _b : _a); \ + }) #else -static inline ptrdiff_t LMAX( ptrdiff_t a, ptrdiff_t b ) { return ( a < b ? b : a ); } -static inline ptrdiff_t LMIN( ptrdiff_t a, ptrdiff_t b ) { return ( a < b ? a : b ); } -static inline int IMAX( int a, int b ) { return ( a < b ? b : a ); } -#endif /* __GNU__ */ - -#define OPAL_DATATYPE_COMPUTE_REQUIRED_ENTRIES( _pdtAdd, _count, _extent, _place_needed) \ -{ \ - if( (_pdtAdd)->flags & OPAL_DATATYPE_FLAG_PREDEFINED ) { /* add a basic datatype */ \ - (_place_needed) = ((_extent) == (ptrdiff_t)(_pdtAdd)->size ? 1 : 3); \ - } else { \ - (_place_needed) = (_pdtAdd)->desc.used; \ - if( (_count) != 1 ) { \ - if( (_place_needed) < (MAX_DT_COMPONENT_COUNT - 2) ) { \ - (_place_needed) += 2; /* for the loop markers */ \ - } else { \ - /* The data-type contain too many elements. We will be unable \ - * to handle it, so let's just complain by now. \ - */ \ - opal_output( 0, "Too many elements in the datatype. The limit is %ud\n", \ - MAX_DT_COMPONENT_COUNT ); \ - return OPAL_ERROR; \ - } \ - } \ - } \ +static inline ptrdiff_t LMAX(ptrdiff_t a, ptrdiff_t b) +{ + return (a < b ? b : a); } - -#define OPAL_DATATYPE_LB_UB_CONT( _count, _disp, _old_lb, _old_ub, _old_extent, _new_lb, _new_ub ) \ -{ \ - if( 0 == _count ) { \ - _new_lb = (_old_lb) + (_disp); \ - _new_ub = (_old_ub) + (_disp); \ - } else { \ - ptrdiff_t lower, upper; \ - upper = (_disp) + (_old_extent) * ((_count) - 1); \ - lower = (_disp); \ - if( lower < upper ) { \ - _new_lb = lower; \ - _new_ub = upper; \ - } else { \ - _new_lb = upper; \ - _new_ub = lower; \ - } \ - _new_lb += (_old_lb); \ - _new_ub += (_old_ub); \ - }\ +static inline ptrdiff_t LMIN(ptrdiff_t a, ptrdiff_t b) +{ + return (a < b ? a : b); } +static inline int IMAX(int a, int b) +{ + return (a < b ? b : a); +} +#endif /* __GNU__ */ + +#define OPAL_DATATYPE_COMPUTE_REQUIRED_ENTRIES(_pdtAdd, _count, _extent, _place_needed) \ + { \ + if ((_pdtAdd)->flags & OPAL_DATATYPE_FLAG_PREDEFINED) { /* add a basic datatype */ \ + (_place_needed) = ((_extent) == (ptrdiff_t)(_pdtAdd)->size ? 1 : 3); \ + } else { \ + (_place_needed) = (_pdtAdd)->desc.used; \ + if ((_count) != 1) { \ + if ((_place_needed) < (MAX_DT_COMPONENT_COUNT - 2)) { \ + (_place_needed) += 2; /* for the loop markers */ \ + } else { \ + /* The data-type contain too many elements. We will be unable \ + * to handle it, so let's just complain by now. \ + */ \ + opal_output(0, "Too many elements in the datatype. The limit is %ud\n", \ + MAX_DT_COMPONENT_COUNT); \ + return OPAL_ERROR; \ + } \ + } \ + } \ + } + +#define OPAL_DATATYPE_LB_UB_CONT(_count, _disp, _old_lb, _old_ub, _old_extent, _new_lb, _new_ub) \ + { \ + if (0 == _count) { \ + _new_lb = (_old_lb) + (_disp); \ + _new_ub = (_old_ub) + (_disp); \ + } else { \ + ptrdiff_t lower, upper; \ + upper = (_disp) + (_old_extent) * ((_count) -1); \ + lower = (_disp); \ + if (lower < upper) { \ + _new_lb = lower; \ + _new_ub = upper; \ + } else { \ + _new_lb = upper; \ + _new_ub = lower; \ + } \ + _new_lb += (_old_lb); \ + _new_ub += (_old_ub); \ + } \ + } /* When we add a datatype we should update it's definition depending on the * initial displacement for the whole data, so the displacement of all elements @@ -102,11 +124,11 @@ static inline int IMAX( int a, int b ) { return ( a < b ? b : a ); } * be sure that the pdtBase datatype is correctly initialized with all fields * set to ZERO if it's a empty datatype. */ -int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtAdd, - size_t count, ptrdiff_t disp, ptrdiff_t extent ) +int32_t opal_datatype_add(opal_datatype_t *pdtBase, const opal_datatype_t *pdtAdd, size_t count, + ptrdiff_t disp, ptrdiff_t extent) { uint32_t newLength, place_needed = 0, i; - short localFlags = 0; /* no specific options yet */ + short localFlags = 0; /* no specific options yet */ dt_elem_desc_t *pLast, *pLoop = NULL; ptrdiff_t lb, ub, true_lb, true_ub, epsilon, old_true_ub; @@ -116,42 +138,46 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * non-negative integers. If the value is zero, no elements are generated in * the type map and there is no effect on datatype bounds or extent. */ - if( 0 == count ) return OPAL_SUCCESS; + if (0 == count) { + return OPAL_SUCCESS; + } /* the extent should always be positive. So a negative value here have a * special meaning ie. default extent as computed by ub - lb */ - if( extent == -1 ) extent = (pdtAdd->ub - pdtAdd->lb); + if (extent == -1) { + extent = (pdtAdd->ub - pdtAdd->lb); + } /* Deal with the special markers (OPAL_DATATYPE_LB and OPAL_DATATYPE_UB) */ - if( OPAL_DATATYPE_LB == pdtAdd->id ) { - pdtBase->bdt_used |= (((uint32_t)1) << OPAL_DATATYPE_LB); - if( pdtBase->flags & OPAL_DATATYPE_FLAG_USER_LB ) { - pdtBase->lb = LMIN( pdtBase->lb, disp ); + if (OPAL_DATATYPE_LB == pdtAdd->id) { + pdtBase->bdt_used |= (((uint32_t) 1) << OPAL_DATATYPE_LB); + if (pdtBase->flags & OPAL_DATATYPE_FLAG_USER_LB) { + pdtBase->lb = LMIN(pdtBase->lb, disp); } else { pdtBase->lb = disp; pdtBase->flags |= OPAL_DATATYPE_FLAG_USER_LB; } - if( (pdtBase->ub - pdtBase->lb) != (ptrdiff_t)pdtBase->size ) { + if ((pdtBase->ub - pdtBase->lb) != (ptrdiff_t) pdtBase->size) { pdtBase->flags &= ~OPAL_DATATYPE_FLAG_NO_GAPS; } return OPAL_SUCCESS; /* Just ignore the OPAL_DATATYPE_LOOP and OPAL_DATATYPE_END_LOOP */ - } else if( OPAL_DATATYPE_UB == pdtAdd->id ) { - pdtBase->bdt_used |= (((uint32_t)1) << OPAL_DATATYPE_UB); - if( pdtBase->flags & OPAL_DATATYPE_FLAG_USER_UB ) { - pdtBase->ub = LMAX( pdtBase->ub, disp ); + } else if (OPAL_DATATYPE_UB == pdtAdd->id) { + pdtBase->bdt_used |= (((uint32_t) 1) << OPAL_DATATYPE_UB); + if (pdtBase->flags & OPAL_DATATYPE_FLAG_USER_UB) { + pdtBase->ub = LMAX(pdtBase->ub, disp); } else { pdtBase->ub = disp; pdtBase->flags |= OPAL_DATATYPE_FLAG_USER_UB; } - if( (pdtBase->ub - pdtBase->lb) != (ptrdiff_t)pdtBase->size ) { + if ((pdtBase->ub - pdtBase->lb) != (ptrdiff_t) pdtBase->size) { pdtBase->flags &= ~OPAL_DATATYPE_FLAG_NO_GAPS; } return OPAL_SUCCESS; /* Just ignore the OPAL_DATATYPE_LOOP and OPAL_DATATYPE_END_LOOP */ } /* Compute the number of entries we need in the datatype description */ - OPAL_DATATYPE_COMPUTE_REQUIRED_ENTRIES( pdtAdd, count, extent, place_needed ); + OPAL_DATATYPE_COMPUTE_REQUIRED_ENTRIES(pdtAdd, count, extent, place_needed); /* * Compute the lower and upper bound of the datatype. We do it in 2 steps. @@ -159,7 +185,7 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * count. Then update the lb value depending on the user markers and * update the global lb and ub. */ - OPAL_DATATYPE_LB_UB_CONT( count, disp, pdtAdd->lb, pdtAdd->ub, extent, lb, ub ); + OPAL_DATATYPE_LB_UB_CONT(count, disp, pdtAdd->lb, pdtAdd->ub, extent, lb, ub); /* Compute the true_lb and true_ub for the datatype to be added, taking * in account the number of repetions. These values do not include the @@ -167,7 +193,7 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA */ true_lb = lb - (pdtAdd->lb - pdtAdd->true_lb); true_ub = ub - (pdtAdd->ub - pdtAdd->true_ub); - if( true_lb > true_ub ) { + if (true_lb > true_ub) { old_true_ub = true_lb; true_lb = true_ub; true_ub = old_true_ub; @@ -188,29 +214,29 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * if the USER has explicitly set it. The result lb is the MIN between * the all lb + disp if and only if all or nobody flags's contain the LB. */ - if( (pdtAdd->flags ^ pdtBase->flags) & OPAL_DATATYPE_FLAG_USER_LB ) { - if( pdtBase->flags & OPAL_DATATYPE_FLAG_USER_LB ) { - lb = pdtBase->lb; /* base type has a user provided lb */ + if ((pdtAdd->flags ^ pdtBase->flags) & OPAL_DATATYPE_FLAG_USER_LB) { + if (pdtBase->flags & OPAL_DATATYPE_FLAG_USER_LB) { + lb = pdtBase->lb; /* base type has a user provided lb */ } pdtBase->flags |= OPAL_DATATYPE_FLAG_USER_LB; } else { /* both of them have the LB flag or both of them dont have it */ - lb = LMIN( pdtBase->lb, lb ); + lb = LMIN(pdtBase->lb, lb); } /* the same apply for the upper bound except for the case where * either of them has the flag UB, in which case we should * compute the UB including the natural alignement of the data. */ - if( (pdtBase->flags ^ pdtAdd->flags) & OPAL_DATATYPE_FLAG_USER_UB ) { - if( pdtBase->flags & OPAL_DATATYPE_FLAG_USER_UB ) { + if ((pdtBase->flags ^ pdtAdd->flags) & OPAL_DATATYPE_FLAG_USER_UB) { + if (pdtBase->flags & OPAL_DATATYPE_FLAG_USER_UB) { ub = pdtBase->ub; } pdtBase->flags |= OPAL_DATATYPE_FLAG_USER_UB; } else { /* both of them have the UB flag or both of them dont have it */ /* we should compute the extent depending on the alignement */ - ub = LMAX( pdtBase->ub, ub ); + ub = LMAX(pdtBase->ub, ub); } /* While the true_lb and true_ub have to be ordered to have the true_lb lower * than the true_ub, the ub and lb do not have to be ordered. They should be @@ -220,7 +246,7 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA pdtBase->ub = ub; /* compute the new memory alignement */ - pdtBase->align = IMAX( pdtBase->align, pdtAdd->align ); + pdtBase->align = IMAX(pdtBase->align, pdtAdd->align); /* Now that we have the new ub and the alignment we should update the ub to match * the new alignement. We have to add an epsilon that is the least nonnegative @@ -228,9 +254,9 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * This rule apply only if there is user specified upper bound as stated in the * MPI standard MPI 1.2 page 71. */ - if( !(pdtBase->flags & OPAL_DATATYPE_FLAG_USER_UB) ) { + if (!(pdtBase->flags & OPAL_DATATYPE_FLAG_USER_UB)) { epsilon = (pdtBase->ub - pdtBase->lb) % pdtBase->align; - if( 0 != epsilon ) { + if (0 != epsilon) { pdtBase->ub += (pdtBase->align - epsilon); } } @@ -247,7 +273,7 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * extension, the count set to zero can be used to reset the alignment of * the data, but not for changing the true_lb and true_ub. */ - if( (0 == count) || (0 == pdtAdd->size) ) { + if ((0 == count) || (0 == pdtAdd->size)) { return OPAL_SUCCESS; } @@ -255,11 +281,14 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * the data-type we can update the size, true_lb and true_ub. */ pdtBase->size += count * pdtAdd->size; - if( 0 == pdtBase->nbElems ) old_true_ub = disp; - else old_true_ub = pdtBase->true_ub; - if( 0 != pdtBase->size ) { - pdtBase->true_lb = LMIN( true_lb, pdtBase->true_lb ); - pdtBase->true_ub = LMAX( true_ub, pdtBase->true_ub ); + if (0 == pdtBase->nbElems) { + old_true_ub = disp; + } else { + old_true_ub = pdtBase->true_ub; + } + if (0 != pdtBase->size) { + pdtBase->true_lb = LMIN(true_lb, pdtBase->true_lb); + pdtBase->true_ub = LMAX(true_ub, pdtBase->true_ub); } else { pdtBase->true_lb = true_lb; pdtBase->true_ub = true_ub; @@ -267,10 +296,10 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA pdtBase->bdt_used |= pdtAdd->bdt_used; newLength = pdtBase->desc.used + place_needed; - if( newLength > pdtBase->desc.length ) { - newLength = ((newLength / DT_INCREASE_STACK) + 1 ) * DT_INCREASE_STACK; - pdtBase->desc.desc = (dt_elem_desc_t*)realloc( pdtBase->desc.desc, - sizeof(dt_elem_desc_t) * newLength ); + if (newLength > pdtBase->desc.length) { + newLength = ((newLength / DT_INCREASE_STACK) + 1) * DT_INCREASE_STACK; + pdtBase->desc.desc = (dt_elem_desc_t *) realloc(pdtBase->desc.desc, + sizeof(dt_elem_desc_t) * newLength); pdtBase->desc.length = newLength; } pLast = &(pdtBase->desc.desc[pdtBase->desc.used]); @@ -278,23 +307,26 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA * of an predefined contiguous datatype. This part is unable to handle any * predefined non contiguous datatypes (like MPI_SHORT_INT). */ - if( (pdtAdd->flags & (OPAL_DATATYPE_FLAG_PREDEFINED | OPAL_DATATYPE_FLAG_DATA)) == (OPAL_DATATYPE_FLAG_PREDEFINED | OPAL_DATATYPE_FLAG_DATA) ) { - if( NULL != pdtBase->ptypes ) + if ((pdtAdd->flags & (OPAL_DATATYPE_FLAG_PREDEFINED | OPAL_DATATYPE_FLAG_DATA)) + == (OPAL_DATATYPE_FLAG_PREDEFINED | OPAL_DATATYPE_FLAG_DATA)) { + if (NULL != pdtBase->ptypes) { pdtBase->ptypes[pdtAdd->id] += count; + } - pLast->elem.common.flags = pdtAdd->flags & ~(OPAL_DATATYPE_FLAG_COMMITTED); - pLast->elem.common.type = pdtAdd->id; - pLast->elem.disp = disp; - pLast->elem.extent = (ptrdiff_t)count * extent; + pLast->elem.common.flags = pdtAdd->flags & ~(OPAL_DATATYPE_FLAG_COMMITTED); + pLast->elem.common.type = pdtAdd->id; + pLast->elem.disp = disp; + pLast->elem.extent = (ptrdiff_t) count * extent; /* assume predefined datatypes without extent, aka. contiguous */ - pLast->elem.count = 1; - pLast->elem.blocklen = count; - if( extent != (ptrdiff_t)pdtAdd->size ) { /* not contiguous: let's fix */ - pLast->elem.count = count; - pLast->elem.blocklen = 1; - pLast->elem.extent = extent; - if( count > 1 ) { /* gaps around the predefined datatype */ - pLast->elem.common.flags &= ~(OPAL_DATATYPE_FLAG_CONTIGUOUS | OPAL_DATATYPE_FLAG_NO_GAPS); + pLast->elem.count = 1; + pLast->elem.blocklen = count; + if (extent != (ptrdiff_t) pdtAdd->size) { /* not contiguous: let's fix */ + pLast->elem.count = count; + pLast->elem.blocklen = 1; + pLast->elem.extent = extent; + if (count > 1) { /* gaps around the predefined datatype */ + pLast->elem.common.flags &= ~(OPAL_DATATYPE_FLAG_CONTIGUOUS + | OPAL_DATATYPE_FLAG_NO_GAPS); } } pdtBase->desc.used++; @@ -303,43 +335,46 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA pdtBase->loops += pdtAdd->loops; pdtBase->flags |= (pdtAdd->flags & OPAL_DATATYPE_FLAG_USER_LB); pdtBase->flags |= (pdtAdd->flags & OPAL_DATATYPE_FLAG_USER_UB); - if( (NULL != pdtBase->ptypes) && (NULL != pdtAdd->ptypes) ) { - for( i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) - if( pdtAdd->ptypes[i] != 0 ) pdtBase->ptypes[i] += (count * pdtAdd->ptypes[i]); + if ((NULL != pdtBase->ptypes) && (NULL != pdtAdd->ptypes)) { + for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) { + if (pdtAdd->ptypes[i] != 0) { + pdtBase->ptypes[i] += (count * pdtAdd->ptypes[i]); + } + } } - if( 1 == pdtAdd->desc.used ) { - pLast->elem = pdtAdd->desc.desc[0].elem; - pLast->elem.disp += disp; - if( 1 == count ) { + if (1 == pdtAdd->desc.used) { + pLast->elem = pdtAdd->desc.desc[0].elem; + pLast->elem.disp += disp; + if (1 == count) { /* Extent only has a meaning when there are multiple elements. Bail out */ - } else if( 1 == pLast->elem.count ) { - /* The size and true_extent of the added datatype are identical, signaling a datatype - * that is mostly contiguous with the exception of the initial and final gaps. These - * gaps do not matter here as they will amended (the initial gaps being shifted by the - * new displacement and the final gap being replaced with the new gap + } else if (1 == pLast->elem.count) { + /* The size and true_extent of the added datatype are identical, signaling a + * datatype that is mostly contiguous with the exception of the initial and final + * gaps. These gaps do not matter here as they will amended (the initial gaps being + * shifted by the new displacement and the final gap being replaced with the new gap */ - if( pdtAdd->desc.desc[0].elem.extent == extent ) { + if (pdtAdd->desc.desc[0].elem.extent == extent) { /* pure bliss everything is fully contiguous and we can collapse * everything by updating the blocklen and extent */ pLast->elem.blocklen *= count; - pLast->elem.extent *= count; + pLast->elem.extent *= count; } else { pLast->elem.count = count; pLast->elem.extent = extent; } - } else if( extent == ((ptrdiff_t)pLast->elem.count * pLast->elem.extent) ) { + } else if (extent == ((ptrdiff_t) pLast->elem.count * pLast->elem.extent)) { /* It's just a repetition of the same element, increase the count */ /* We need to protect against the case where the multiplication below results in a - * number larger than the max uint32_t. In the unlikely situation where that's the case - * we should not try to optimize the item further but instead fall back and build a loop - * around it. + * number larger than the max uint32_t. In the unlikely situation where that's the + * case we should not try to optimize the item further but instead fall back and + * build a loop around it. */ uint32_t cnt = pLast->elem.count * count; - if( cnt < pLast->elem.count ) { + if (cnt < pLast->elem.count) { goto build_loop; } - pLast->elem.count = cnt; /* we're good, merge the elements */ + pLast->elem.count = cnt; /* we're good, merge the elements */ } else { /* No luck here, no optimization can be applied. Fall back to the * normal case where we add a loop around the datatype. @@ -349,34 +384,34 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA pdtBase->desc.used++; } else { -build_loop: + build_loop: /* if the extent of the datatype is the same as the extent of the loop * description of the datatype then we simply have to update the main loop. */ - if( count != 1 ) { + if (count != 1) { pLoop = pLast; - CREATE_LOOP_START( pLast, count, pdtAdd->desc.used + 1, extent, - (pdtAdd->flags & ~(OPAL_DATATYPE_FLAG_COMMITTED)) ); - pdtBase->loops += 2; + CREATE_LOOP_START(pLast, count, pdtAdd->desc.used + 1, extent, + (pdtAdd->flags & ~(OPAL_DATATYPE_FLAG_COMMITTED))); + pdtBase->loops += 2; pdtBase->desc.used += 2; pLast++; } - for( i = 0; i < pdtAdd->desc.used; i++ ) { - pLast->elem = pdtAdd->desc.desc[i].elem; - if( OPAL_DATATYPE_FLAG_DATA & pLast->elem.common.flags ) + for (i = 0; i < pdtAdd->desc.used; i++) { + pLast->elem = pdtAdd->desc.desc[i].elem; + if (OPAL_DATATYPE_FLAG_DATA & pLast->elem.common.flags) { pLast->elem.disp += disp; - else if( OPAL_DATATYPE_END_LOOP == pLast->elem.common.type ) { + } else if (OPAL_DATATYPE_END_LOOP == pLast->elem.common.type) { pLast->end_loop.first_elem_disp += disp; } pLast++; } pdtBase->desc.used += pdtAdd->desc.used; - if( pLoop != NULL ) { - int index = GET_FIRST_NON_LOOP( pLoop ); - assert( pLoop[index].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ); - CREATE_LOOP_END( pLast, pdtAdd->desc.used + 1, pLoop[index].elem.disp, - pdtAdd->size, pLoop->loop.common.flags ); + if (pLoop != NULL) { + int index = GET_FIRST_NON_LOOP(pLoop); + assert(pLoop[index].elem.common.flags & OPAL_DATATYPE_FLAG_DATA); + CREATE_LOOP_END(pLast, pdtAdd->desc.used + 1, pLoop[index].elem.disp, pdtAdd->size, + pLoop->loop.common.flags); } } /* should I add some space until the extent of this datatype ? */ @@ -389,19 +424,20 @@ int32_t opal_datatype_add( opal_datatype_t* pdtBase, const opal_datatype_t* pdtA */ localFlags = pdtBase->flags & pdtAdd->flags; UNSET_CONTIGUOUS_FLAG(pdtBase->flags); - if( (localFlags & OPAL_DATATYPE_FLAG_CONTIGUOUS) /* both type were contiguous */ - && ((disp + pdtAdd->true_lb) == old_true_ub) /* and there is no gap between them */ - && ( ((ptrdiff_t)pdtAdd->size == extent) /* the size and the extent of the - * added type have to match */ - || (count < 2)) ) { /* if the count is bigger than 2 */ - SET_CONTIGUOUS_FLAG(pdtBase->flags); - if( (ptrdiff_t)pdtBase->size == (pdtBase->ub - pdtBase->lb) ) - SET_NO_GAP_FLAG(pdtBase->flags); + if ((localFlags & OPAL_DATATYPE_FLAG_CONTIGUOUS) /* both type were contiguous */ + && ((disp + pdtAdd->true_lb) == old_true_ub) /* and there is no gap between them */ + && (((ptrdiff_t) pdtAdd->size == extent) /* the size and the extent of the + * added type have to match */ + || (count < 2))) { /* if the count is bigger than 2 */ + SET_CONTIGUOUS_FLAG(pdtBase->flags); + if ((ptrdiff_t) pdtBase->size == (pdtBase->ub - pdtBase->lb)) { + SET_NO_GAP_FLAG(pdtBase->flags); + } } /* If the NO_GAP flag is set the contiguous have to be set too */ - if( pdtBase->flags & OPAL_DATATYPE_FLAG_NO_GAPS ) { - assert( pdtBase->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ); + if (pdtBase->flags & OPAL_DATATYPE_FLAG_NO_GAPS) { + assert(pdtBase->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS); } pdtBase->nbElems += (count * pdtAdd->nbElems); diff --git a/opal/datatype/opal_datatype_checksum.h b/opal/datatype/opal_datatype_checksum.h index 64fecd179b9..7b59e4f7930 100644 --- a/opal/datatype/opal_datatype_checksum.h +++ b/opal/datatype/opal_datatype_checksum.h @@ -19,37 +19,42 @@ #ifndef DATATYPE_CHECKSUM_H_HAS_BEEN_INCLUDED #define DATATYPE_CHECKSUM_H_HAS_BEEN_INCLUDED - #include "opal/datatype/opal_datatype_memcpy.h" #include "opal/util/crc.h" #if defined(CHECKSUM) -#if defined (OPAL_CSUM_DST) -#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \ -do { \ - (CONVERTOR)->checksum += OPAL_CSUM_BCOPY_PARTIAL( (SRC), (DST), (BLENGTH), (BLENGTH), &(CONVERTOR)->csum_ui1, &(CONVERTOR)->csum_ui2 ); \ -} while (0) +# if defined(OPAL_CSUM_DST) +# define MEMCPY_CSUM(DST, SRC, BLENGTH, CONVERTOR) \ + do { \ + (CONVERTOR)->checksum += OPAL_CSUM_BCOPY_PARTIAL((SRC), (DST), (BLENGTH), \ + (BLENGTH), \ + &(CONVERTOR)->csum_ui1, \ + &(CONVERTOR)->csum_ui2); \ + } while (0) -#else /* if OPAL_CSUM_DST */ +# else /* if OPAL_CSUM_DST */ -#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \ -do { \ - (CONVERTOR)->checksum += OPAL_CSUM_BCOPY_PARTIAL( (SRC), (DST), (BLENGTH), (BLENGTH), &(CONVERTOR)->csum_ui1, &(CONVERTOR)->csum_ui2 ); \ -} while (0) -#endif /* if OPAL_CSUM_DST */ +# define MEMCPY_CSUM(DST, SRC, BLENGTH, CONVERTOR) \ + do { \ + (CONVERTOR)->checksum += OPAL_CSUM_BCOPY_PARTIAL((SRC), (DST), (BLENGTH), \ + (BLENGTH), \ + &(CONVERTOR)->csum_ui1, \ + &(CONVERTOR)->csum_ui2); \ + } while (0) +# endif /* if OPAL_CSUM_DST */ -#define COMPUTE_CSUM( SRC, BLENGTH, CONVERTOR ) \ -do { \ - (CONVERTOR)->checksum += OPAL_CSUM_PARTIAL( (SRC), (BLENGTH), &(CONVERTOR)->csum_ui1, &(CONVERTOR)->csum_ui2 ); \ -} while (0) +# define COMPUTE_CSUM(SRC, BLENGTH, CONVERTOR) \ + do { \ + (CONVERTOR)->checksum += OPAL_CSUM_PARTIAL((SRC), (BLENGTH), &(CONVERTOR)->csum_ui1, \ + &(CONVERTOR)->csum_ui2); \ + } while (0) -#else /* if CHECKSUM */ +#else /* if CHECKSUM */ -#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \ - MEMCPY( (DST), (SRC), (BLENGTH) ) +# define MEMCPY_CSUM(DST, SRC, BLENGTH, CONVERTOR) MEMCPY((DST), (SRC), (BLENGTH)) -#define COMPUTE_CSUM( SRC, BLENGTH, CONVERTOR ) +# define COMPUTE_CSUM(SRC, BLENGTH, CONVERTOR) -#endif /* if CHECKSUM */ -#endif /* DATATYPE_CHECKSUM_H_HAS_BEEN_INCLUDED */ +#endif /* if CHECKSUM */ +#endif /* DATATYPE_CHECKSUM_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_datatype_clone.c b/opal/datatype/opal_datatype_clone.c index 59e82bb40cf..2ef94d7c036 100644 --- a/opal/datatype/opal_datatype_clone.c +++ b/opal/datatype/opal_datatype_clone.c @@ -32,15 +32,15 @@ * * Clone all the values from oldType into newType without allocating a new datatype. */ -int32_t opal_datatype_clone( const opal_datatype_t * src_type, opal_datatype_t * dest_type ) +int32_t opal_datatype_clone(const opal_datatype_t *src_type, opal_datatype_t *dest_type) { - int32_t desc_length = src_type->desc.used + 1; /* +1 because of the fake OPAL_DATATYPE_END_LOOP entry */ - dt_elem_desc_t* temp = dest_type->desc.desc; /* temporary copy of the desc pointer */ + int32_t desc_length = src_type->desc.used + + 1; /* +1 because of the fake OPAL_DATATYPE_END_LOOP entry */ + dt_elem_desc_t *temp = dest_type->desc.desc; /* temporary copy of the desc pointer */ /* copy _excluding_ the super object, we want to keep the cls_destruct_array */ - memcpy( (char*)dest_type + sizeof(opal_object_t), - (char*)src_type + sizeof(opal_object_t), - sizeof(opal_datatype_t)-sizeof(opal_object_t) ); + memcpy((char *) dest_type + sizeof(opal_object_t), (char *) src_type + sizeof(opal_object_t), + sizeof(opal_datatype_t) - sizeof(opal_object_t)); dest_type->flags &= (~OPAL_DATATYPE_FLAG_PREDEFINED); dest_type->ptypes = NULL; @@ -49,27 +49,29 @@ int32_t opal_datatype_clone( const opal_datatype_t * src_type, opal_datatype_t * /** * Allow duplication of MPI_UB and MPI_LB. */ - if( 0 != src_type->desc.used ) { - memcpy( dest_type->desc.desc, src_type->desc.desc, sizeof(dt_elem_desc_t) * desc_length ); - if( 0 != src_type->opt_desc.used ) { - if( src_type->opt_desc.desc == src_type->desc.desc) { + if (0 != src_type->desc.used) { + memcpy(dest_type->desc.desc, src_type->desc.desc, sizeof(dt_elem_desc_t) * desc_length); + if (0 != src_type->opt_desc.used) { + if (src_type->opt_desc.desc == src_type->desc.desc) { dest_type->opt_desc = dest_type->desc; } else { desc_length = dest_type->opt_desc.used + 1; - dest_type->opt_desc.desc = (dt_elem_desc_t*)malloc( desc_length * sizeof(dt_elem_desc_t) ); + dest_type->opt_desc.desc = (dt_elem_desc_t *) malloc(desc_length + * sizeof(dt_elem_desc_t)); /* * Yes, the dest_type->opt_desc.length is just the opt_desc.used of the old Type. */ dest_type->opt_desc.length = src_type->opt_desc.used; dest_type->opt_desc.used = src_type->opt_desc.used; - memcpy( dest_type->opt_desc.desc, src_type->opt_desc.desc, desc_length * sizeof(dt_elem_desc_t) ); + memcpy(dest_type->opt_desc.desc, src_type->opt_desc.desc, + desc_length * sizeof(dt_elem_desc_t)); } } else { - assert( NULL == dest_type->opt_desc.desc ); - assert( 0 == dest_type->opt_desc.length ); + assert(NULL == dest_type->opt_desc.desc); + assert(0 == dest_type->opt_desc.length); } } - dest_type->id = src_type->id; /* preserve the default id. This allow us to - * copy predefined types. */ + dest_type->id = src_type->id; /* preserve the default id. This allow us to + * copy predefined types. */ return OPAL_SUCCESS; } diff --git a/opal/datatype/opal_datatype_copy.c b/opal/datatype/opal_datatype_copy.c index e13d17fa59c..465f479e46c 100644 --- a/opal/datatype/opal_datatype_copy.c +++ b/opal/datatype/opal_datatype_copy.c @@ -27,19 +27,21 @@ #include #include -#include "opal/prefetch.h" -#include "opal/util/output.h" -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" -#include "opal/datatype/opal_datatype_internal.h" +#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_checksum.h" - +#include "opal/datatype/opal_datatype_internal.h" +#include "opal/prefetch.h" +#include "opal/util/output.h" #if OPAL_ENABLE_DEBUG -#define DO_DEBUG(INST) if( opal_ddt_copy_debug ) { INST } +# define DO_DEBUG(INST) \ + if (opal_ddt_copy_debug) { \ + INST \ + } #else -#define DO_DEBUG(INST) -#endif /* OPAL_ENABLE_DEBUG */ +# define DO_DEBUG(INST) +#endif /* OPAL_ENABLE_DEBUG */ static size_t opal_datatype_memop_block_size = 128 * 1024; @@ -47,72 +49,74 @@ static size_t opal_datatype_memop_block_size = 128 * 1024; * Non overlapping memory regions */ #undef MEM_OP_NAME -#define MEM_OP_NAME non_overlap +#define MEM_OP_NAME non_overlap #undef MEM_OP -#define MEM_OP MEMCPY +#define MEM_OP MEMCPY #include "opal_datatype_copy.h" -#define MEMMOVE(d, s, l) \ - do { \ - if( (((d) < (s)) && (((d) + (l)) > (s))) || \ - (((s) < (d)) && (((s) + (l)) > (d))) ) { \ - memmove( (d), (s), (l) ); \ - } else { \ - MEMCPY( (d), (s), (l) ); \ - } \ +#define MEMMOVE(d, s, l) \ + do { \ + if ((((d) < (s)) && (((d) + (l)) > (s))) || (((s) < (d)) && (((s) + (l)) > (d)))) { \ + memmove((d), (s), (l)); \ + } else { \ + MEMCPY((d), (s), (l)); \ + } \ } while (0) /** * Overlapping memory regions */ #undef MEM_OP_NAME -#define MEM_OP_NAME overlap +#define MEM_OP_NAME overlap #undef MEM_OP -#define MEM_OP MEMMOVE +#define MEM_OP MEMMOVE #include "opal_datatype_copy.h" #if OPAL_CUDA_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" - -#undef MEM_OP_NAME -#define MEM_OP_NAME non_overlap_cuda -#undef MEM_OP -#define MEM_OP opal_cuda_memcpy_sync -#include "opal_datatype_copy.h" - -#undef MEM_OP_NAME -#define MEM_OP_NAME overlap_cuda -#undef MEM_OP -#define MEM_OP opal_cuda_memmove -#include "opal_datatype_copy.h" - -#define SET_CUDA_COPY_FCT(cuda_device_bufs, fct, copy_function) \ - do { \ - if (true == cuda_device_bufs) { \ - fct = copy_function; \ - } \ - } while(0) +# include "opal/mca/common/cuda/common_cuda.h" + +# undef MEM_OP_NAME +# define MEM_OP_NAME non_overlap_cuda +# undef MEM_OP +# define MEM_OP opal_cuda_memcpy_sync +# include "opal_datatype_copy.h" + +# undef MEM_OP_NAME +# define MEM_OP_NAME overlap_cuda +# undef MEM_OP +# define MEM_OP opal_cuda_memmove +# include "opal_datatype_copy.h" + +# define SET_CUDA_COPY_FCT(cuda_device_bufs, fct, copy_function) \ + do { \ + if (true == cuda_device_bufs) { \ + fct = copy_function; \ + } \ + } while (0) #else -#define SET_CUDA_COPY_FCT(cuda_device_bufs, fct, copy_function) +# define SET_CUDA_COPY_FCT(cuda_device_bufs, fct, copy_function) #endif -int32_t opal_datatype_copy_content_same_ddt( const opal_datatype_t* datatype, int32_t count, - char* destination_base, char* source_base ) +int32_t opal_datatype_copy_content_same_ddt(const opal_datatype_t *datatype, int32_t count, + char *destination_base, char *source_base) { ptrdiff_t extent; - int32_t (*fct)( const opal_datatype_t*, int32_t, char*, char*); + int32_t (*fct)(const opal_datatype_t *, int32_t, char *, char *); #if OPAL_CUDA_SUPPORT bool cuda_device_bufs = opal_cuda_check_bufs(destination_base, source_base); #endif - DO_DEBUG( opal_output( 0, "opal_datatype_copy_content_same_ddt( %p, %d, dst %p, src %p )\n", - (void*)datatype, count, (void*)destination_base, (void*)source_base ); ); + DO_DEBUG(opal_output(0, "opal_datatype_copy_content_same_ddt( %p, %d, dst %p, src %p )\n", + (void *) datatype, count, (void *) destination_base, + (void *) source_base);); /* empty data ? then do nothing. This should normally be trapped * at a higher level. */ - if( 0 == count ) return 1; + if (0 == count) { + return 1; + } /** * see discussion in coll_basic_reduce.c for the computation of extent when @@ -123,19 +127,18 @@ int32_t opal_datatype_copy_content_same_ddt( const opal_datatype_t* datatype, in fct = non_overlap_copy_content_same_ddt; SET_CUDA_COPY_FCT(cuda_device_bufs, fct, non_overlap_cuda_copy_content_same_ddt); - if( destination_base < source_base ) { - if( (destination_base + extent) > source_base ) { + if (destination_base < source_base) { + if ((destination_base + extent) > source_base) { /* memmove */ fct = overlap_copy_content_same_ddt; SET_CUDA_COPY_FCT(cuda_device_bufs, fct, overlap_cuda_copy_content_same_ddt); } } else { - if( (source_base + extent) > destination_base ) { + if ((source_base + extent) > destination_base) { /* memmove */ fct = overlap_copy_content_same_ddt; SET_CUDA_COPY_FCT(cuda_device_bufs, fct, overlap_cuda_copy_content_same_ddt); } } - return fct( datatype, count, destination_base, source_base ); + return fct(datatype, count, destination_base, source_base); } - diff --git a/opal/datatype/opal_datatype_copy.h b/opal/datatype/opal_datatype_copy.h index 1a5c021e760..20fea3a9046 100644 --- a/opal/datatype/opal_datatype_copy.h +++ b/opal/datatype/opal_datatype_copy.h @@ -14,46 +14,41 @@ */ #ifdef HAVE_ALLOCA_H -#include +# include #endif #if !defined(MEM_OP_NAME) -#error -#endif /* !defined((MEM_OP_NAME) */ +# error +#endif /* !defined((MEM_OP_NAME) */ #if !defined(MEM_OP) -#error -#endif /* !defined(MEM_OP) */ +# error +#endif /* !defined(MEM_OP) */ #ifndef STRINGIFY -# define STRINGIFY_(arg) #arg -# define STRINGIFY(arg) STRINGIFY_(arg) +# define STRINGIFY_(arg) # arg +# define STRINGIFY(arg) STRINGIFY_(arg) #endif #ifndef DT_CONCAT -# define DT__CONCAT(a, b) a##b -# define DT_CONCAT(a, b) DT__CONCAT(a, b) +# define DT__CONCAT(a, b) a##b +# define DT_CONCAT(a, b) DT__CONCAT(a, b) #endif +#define _predefined_data DT_CONCAT(MEM_OP_NAME, _predefined_data) +#define _contiguous_loop DT_CONCAT(MEM_OP_NAME, _contiguous_loop) +#define _copy_content_same_ddt DT_CONCAT(MEM_OP_NAME, _copy_content_same_ddt) -#define _predefined_data DT_CONCAT(MEM_OP_NAME,_predefined_data) -#define _contiguous_loop DT_CONCAT(MEM_OP_NAME,_contiguous_loop) -#define _copy_content_same_ddt DT_CONCAT(MEM_OP_NAME,_copy_content_same_ddt) - -static inline void _predefined_data( const dt_elem_desc_t* ELEM, - const opal_datatype_t* DATATYPE, - unsigned char* SOURCE_BASE, - size_t TOTAL_COUNT, - size_t COUNT, - unsigned char* SOURCE, - unsigned char* DESTINATION, - size_t* SPACE ) +static inline void _predefined_data(const dt_elem_desc_t *ELEM, const opal_datatype_t *DATATYPE, + unsigned char *SOURCE_BASE, size_t TOTAL_COUNT, size_t COUNT, + unsigned char *SOURCE, unsigned char *DESTINATION, + size_t *SPACE) { - const ddt_elem_desc_t* _elem = &((ELEM)->elem); - unsigned char* _source = (SOURCE) + _elem->disp; - unsigned char* _destination = (DESTINATION) + _elem->disp; + const ddt_elem_desc_t *_elem = &((ELEM)->elem); + unsigned char *_source = (SOURCE) + _elem->disp; + unsigned char *_destination = (DESTINATION) + _elem->disp; size_t do_now = _elem->count, do_now_bytes; - assert( (COUNT) == (do_now * _elem->blocklen)); + assert((COUNT) == (do_now * _elem->blocklen)); /* We don't a prologue and epilogue here as we are __always__ working * with full copies of the data description. @@ -63,179 +58,187 @@ static inline void _predefined_data( const dt_elem_desc_t* ELEM, * Compute how many full blocklen we need to do and do them. */ do_now_bytes = _elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size; - assert( (do_now * do_now_bytes) <= (*SPACE) ); - - for(size_t _i = 0; _i < do_now; _i++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( _source, do_now_bytes, (SOURCE_BASE), - (DATATYPE), (TOTAL_COUNT) ); - DO_DEBUG( opal_output( 0, "copy %s( %p, %p, %" PRIsize_t " ) => space %" PRIsize_t "\n", - STRINGIFY(MEM_OP_NAME), (void*)_destination, (void*)_source, do_now_bytes, *(SPACE) - _i * do_now_bytes ); ); - MEM_OP( _destination, _source, do_now_bytes ); + assert((do_now * do_now_bytes) <= (*SPACE)); + + for (size_t _i = 0; _i < do_now; _i++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(_source, do_now_bytes, (SOURCE_BASE), (DATATYPE), + (TOTAL_COUNT)); + DO_DEBUG(opal_output(0, "copy %s( %p, %p, %" PRIsize_t " ) => space %" PRIsize_t "\n", + STRINGIFY(MEM_OP_NAME), (void *) _destination, (void *) _source, + do_now_bytes, *(SPACE) -_i * do_now_bytes);); + MEM_OP(_destination, _source, do_now_bytes); _destination += _elem->extent; - _source += _elem->extent; + _source += _elem->extent; } *(SPACE) -= (do_now_bytes * do_now); } -static inline void _contiguous_loop( const dt_elem_desc_t* ELEM, - const opal_datatype_t* DATATYPE, - unsigned char* SOURCE_BASE, - size_t TOTAL_COUNT, - size_t COUNT, - unsigned char* SOURCE, - unsigned char* DESTINATION, - size_t* SPACE ) +static inline void _contiguous_loop(const dt_elem_desc_t *ELEM, const opal_datatype_t *DATATYPE, + unsigned char *SOURCE_BASE, size_t TOTAL_COUNT, size_t COUNT, + unsigned char *SOURCE, unsigned char *DESTINATION, + size_t *SPACE) { - ddt_loop_desc_t *_loop = (ddt_loop_desc_t*)(ELEM); - ddt_endloop_desc_t* _end_loop = (ddt_endloop_desc_t*)((ELEM) + _loop->items); - unsigned char* _source = (SOURCE) + _end_loop->first_elem_disp; - unsigned char* _destination = (DESTINATION) + _end_loop->first_elem_disp; + ddt_loop_desc_t *_loop = (ddt_loop_desc_t *) (ELEM); + ddt_endloop_desc_t *_end_loop = (ddt_endloop_desc_t *) ((ELEM) + _loop->items); + unsigned char *_source = (SOURCE) + _end_loop->first_elem_disp; + unsigned char *_destination = (DESTINATION) + _end_loop->first_elem_disp; size_t _copy_loops = (COUNT); - if( _loop->extent == (ptrdiff_t)_end_loop->size ) { /* the loop is contiguous */ + if (_loop->extent == (ptrdiff_t) _end_loop->size) { /* the loop is contiguous */ _copy_loops *= _end_loop->size; - OPAL_DATATYPE_SAFEGUARD_POINTER( _source, _copy_loops, (SOURCE_BASE), - (DATATYPE), (TOTAL_COUNT) ); - MEM_OP( _destination, _source, _copy_loops ); + OPAL_DATATYPE_SAFEGUARD_POINTER(_source, _copy_loops, (SOURCE_BASE), (DATATYPE), + (TOTAL_COUNT)); + MEM_OP(_destination, _source, _copy_loops); } else { - for(size_t _i = 0; _i < _copy_loops; _i++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( _source, _end_loop->size, (SOURCE_BASE), - (DATATYPE), (TOTAL_COUNT) ); - DO_DEBUG( opal_output( 0, "copy 3. %s( %p, %p, %" PRIsize_t " ) => space %" PRIsize_t "\n", - STRINGIFY(MEM_OP_NAME), (void*)_destination, (void*)_source, _end_loop->size, *(SPACE) - _i * _end_loop->size ); ); - MEM_OP( _destination, _source, _end_loop->size ); - _source += _loop->extent; + for (size_t _i = 0; _i < _copy_loops; _i++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(_source, _end_loop->size, (SOURCE_BASE), (DATATYPE), + (TOTAL_COUNT)); + DO_DEBUG(opal_output(0, + "copy 3. %s( %p, %p, %" PRIsize_t " ) => space %" PRIsize_t "\n", + STRINGIFY(MEM_OP_NAME), (void *) _destination, (void *) _source, + _end_loop->size, *(SPACE) -_i * _end_loop->size);); + MEM_OP(_destination, _source, _end_loop->size); + _source += _loop->extent; _destination += _loop->extent; } _copy_loops *= _end_loop->size; } - *(SPACE) -= _copy_loops; + *(SPACE) -= _copy_loops; } -static inline int32_t _copy_content_same_ddt( const opal_datatype_t* datatype, int32_t count, - char* destination_base, char* source_base ) +static inline int32_t _copy_content_same_ddt(const opal_datatype_t *datatype, int32_t count, + char *destination_base, char *source_base) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - int32_t stack_pos; /* index of the stack level */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - uint32_t count_desc; /* the number of items already done in the actual pos_desc */ - dt_elem_desc_t* description; - dt_elem_desc_t* pElem; + dt_stack_t *pStack; /* pointer to the position on the stack */ + int32_t stack_pos; /* index of the stack level */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + uint32_t count_desc; /* the number of items already done in the actual pos_desc */ + dt_elem_desc_t *description; + dt_elem_desc_t *pElem; size_t iov_len_local; - unsigned char *source = (unsigned char*)source_base, - *destination = (unsigned char*)destination_base; + unsigned char *source = (unsigned char *) source_base, + *destination = (unsigned char *) destination_base; - DO_DEBUG( opal_output( 0, "_copy_content_same_ddt( %p, %d, dst %p, src %p )\n", - (void*)datatype, count, (void*)destination_base, (void*)source_base ); ); + DO_DEBUG(opal_output(0, "_copy_content_same_ddt( %p, %d, dst %p, src %p )\n", (void *) datatype, + count, (void *) destination_base, (void *) source_base);); - iov_len_local = (size_t)count * datatype->size; + iov_len_local = (size_t) count * datatype->size; /* If we have to copy a contiguous datatype then simply * do a MEM_OP. */ - if( datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { + if (datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { ptrdiff_t extent = (datatype->ub - datatype->lb); /* Now that we know the datatype is contiguous, we should move the 2 pointers * source and destination to the correct displacement. */ destination += datatype->true_lb; - source += datatype->true_lb; - if( (ptrdiff_t)datatype->size == extent ) { /* all contiguous == no gaps around */ + source += datatype->true_lb; + if ((ptrdiff_t) datatype->size == extent) { /* all contiguous == no gaps around */ size_t total_length = iov_len_local; size_t memop_chunk = opal_datatype_memop_block_size; - OPAL_DATATYPE_SAFEGUARD_POINTER( source, iov_len_local, - (unsigned char*)source_base, datatype, count ); - while( total_length > 0 ) { - if( memop_chunk > total_length ) memop_chunk = total_length; - DO_DEBUG( opal_output( 0, "copy c1. %s( %p, %p, %lu ) => space %lu\n", - STRINGIFY(MEM_OP_NAME), (void*)destination, (void*)source, (unsigned long)memop_chunk, (unsigned long)total_length ); ); - MEM_OP( destination, source, memop_chunk ); - destination += memop_chunk; - source += memop_chunk; - total_length -= memop_chunk; + OPAL_DATATYPE_SAFEGUARD_POINTER(source, iov_len_local, (unsigned char *) source_base, + datatype, count); + while (total_length > 0) { + if (memop_chunk > total_length) + memop_chunk = total_length; + DO_DEBUG(opal_output(0, "copy c1. %s( %p, %p, %lu ) => space %lu\n", + STRINGIFY(MEM_OP_NAME), (void *) destination, (void *) source, + (unsigned long) memop_chunk, (unsigned long) total_length);); + MEM_OP(destination, source, memop_chunk); + destination += memop_chunk; + source += memop_chunk; + total_length -= memop_chunk; } - return 0; /* completed */ + return 0; /* completed */ } - for( pos_desc = 0; (int32_t)pos_desc < count; pos_desc++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( destination, datatype->size, - (unsigned char*)destination_base, datatype, count ); - OPAL_DATATYPE_SAFEGUARD_POINTER( source, datatype->size, - (unsigned char*)source_base, datatype, count ); - DO_DEBUG( opal_output( 0, "copy c2. %s( %p, %p, %lu ) => space %lu\n", - STRINGIFY(MEM_OP_NAME), (void*)destination, (void*)source, (unsigned long)datatype->size, - (unsigned long)(iov_len_local - (pos_desc * datatype->size)) ); ); - MEM_OP( destination, source, datatype->size ); + for (pos_desc = 0; (int32_t) pos_desc < count; pos_desc++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(destination, datatype->size, + (unsigned char *) destination_base, datatype, count); + OPAL_DATATYPE_SAFEGUARD_POINTER(source, datatype->size, (unsigned char *) source_base, + datatype, count); + DO_DEBUG(opal_output(0, "copy c2. %s( %p, %p, %lu ) => space %lu\n", + STRINGIFY(MEM_OP_NAME), (void *) destination, (void *) source, + (unsigned long) datatype->size, + (unsigned long) (iov_len_local - (pos_desc * datatype->size)));); + MEM_OP(destination, source, datatype->size); destination += extent; source += extent; } - return 0; /* completed */ + return 0; /* completed */ } - pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (datatype->loops + 1) ); + pStack = (dt_stack_t *) alloca(sizeof(dt_stack_t) * (datatype->loops + 1)); pStack->count = count; - pStack->index = -1; - pStack->disp = 0; + pStack->index = -1; + pStack->disp = 0; pos_desc = 0; stack_pos = 0; description = datatype->opt_desc.desc; - if( NULL == description ) { + if (NULL == description) { description = datatype->desc.desc; } - UPDATE_INTERNAL_COUNTERS( description, 0, pElem, count_desc ); + UPDATE_INTERNAL_COUNTERS(description, 0, pElem, count_desc); - while( 1 ) { - while( OPAL_LIKELY(pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) ) { + while (1) { + while (OPAL_LIKELY(pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA)) { /* now here we have a basic datatype */ - _predefined_data( pElem, datatype, (unsigned char*)source_base, count, count_desc, - source, destination, &iov_len_local ); - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + _predefined_data(pElem, datatype, (unsigned char *) source_base, count, count_desc, + source, destination, &iov_len_local); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); } - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */ - DO_DEBUG( opal_output( 0, "copy end_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %ld space %lu\n", - pStack->count, stack_pos, pos_desc, pStack->disp, (unsigned long)iov_len_local ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( stack_pos == 0 ) { - assert( iov_len_local == 0 ); - return 0; /* completed */ + if (OPAL_DATATYPE_END_LOOP == pElem->elem.common.type) { /* end of the current loop */ + DO_DEBUG(opal_output(0, + "copy end_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %ld space %lu\n", + pStack->count, stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); + if (--(pStack->count) == 0) { /* end of loop */ + if (stack_pos == 0) { + assert(iov_len_local == 0); + return 0; /* completed */ } stack_pos--; pStack--; pos_desc++; } else { pos_desc = pStack->index + 1; - if( pStack->index == -1 ) { + if (pStack->index == -1) { pStack->disp += (datatype->ub - datatype->lb); } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); pStack->disp += description[pStack->index].loop.extent; } } - source = (unsigned char*)source_base + pStack->disp; - destination = (unsigned char*)destination_base + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "copy new_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %ld space %lu\n", - pStack->count, stack_pos, pos_desc, pStack->disp, (unsigned long)iov_len_local ); ); + source = (unsigned char *) source_base + pStack->disp; + destination = (unsigned char *) destination_base + pStack->disp; + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "copy new_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %ld space %lu\n", + pStack->count, stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - ptrdiff_t local_disp = (ptrdiff_t)source; - if( pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { - _contiguous_loop( pElem, datatype, (unsigned char*)source_base, count, count_desc, - source, destination, &iov_len_local ); + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + ptrdiff_t local_disp = (ptrdiff_t) source; + if (pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + _contiguous_loop(pElem, datatype, (unsigned char *) source_base, count, count_desc, + source, destination, &iov_len_local); pos_desc += pElem->loop.items + 1; goto update_loop_description; } - local_disp = (ptrdiff_t)source - local_disp; - PUSH_STACK( pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp + local_disp); + local_disp = (ptrdiff_t) source - local_disp; + PUSH_STACK(pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp + local_disp); pos_desc++; - update_loop_description: /* update the current state */ - source = (unsigned char*)source_base + pStack->disp; - destination = (unsigned char*)destination_base + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pStack, stack_pos, pElem, "advance loop" ); + update_loop_description: /* update the current state */ + source = (unsigned char *) source_base + pStack->disp; + destination = (unsigned char *) destination_base + pStack->disp; + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pStack, stack_pos, pElem, "advance loop"); continue; } } diff --git a/opal/datatype/opal_datatype_create.c b/opal/datatype/opal_datatype_create.c index 122521989b8..536bdb6bd87 100644 --- a/opal/datatype/opal_datatype_create.c +++ b/opal/datatype/opal_datatype_create.c @@ -24,62 +24,63 @@ #include +#include "limits.h" #include "opal/constants.h" #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -#include "limits.h" #include "opal/prefetch.h" -static void opal_datatype_construct( opal_datatype_t* pData ) +static void opal_datatype_construct(opal_datatype_t *pData) { - pData->size = 0; - pData->flags = OPAL_DATATYPE_FLAG_CONTIGUOUS; - pData->id = 0; - pData->bdt_used = 0; - pData->size = 0; - pData->true_lb = LONG_MAX; - pData->true_ub = LONG_MIN; - pData->lb = LONG_MAX; - pData->ub = LONG_MIN; - pData->align = 1; - pData->nbElems = 0; + pData->size = 0; + pData->flags = OPAL_DATATYPE_FLAG_CONTIGUOUS; + pData->id = 0; + pData->bdt_used = 0; + pData->size = 0; + pData->true_lb = LONG_MAX; + pData->true_ub = LONG_MIN; + pData->lb = LONG_MAX; + pData->ub = LONG_MIN; + pData->align = 1; + pData->nbElems = 0; memset(pData->name, 0, OPAL_MAX_OBJECT_NAME); - pData->desc.desc = NULL; - pData->desc.length = 0; - pData->desc.used = 0; + pData->desc.desc = NULL; + pData->desc.length = 0; + pData->desc.used = 0; - pData->opt_desc.desc = NULL; - pData->opt_desc.length = 0; - pData->opt_desc.used = 0; + pData->opt_desc.desc = NULL; + pData->opt_desc.length = 0; + pData->opt_desc.used = 0; - pData->ptypes = NULL; - pData->loops = 0; + pData->ptypes = NULL; + pData->loops = 0; } -static void opal_datatype_destruct( opal_datatype_t* datatype ) +static void opal_datatype_destruct(opal_datatype_t *datatype) { /** * As the default description and the optimized description might point to the * same data description we should start by cleaning the optimized description. */ - if( NULL != datatype->opt_desc.desc ) { - if( datatype->opt_desc.desc != datatype->desc.desc ) - free( datatype->opt_desc.desc ); + if (NULL != datatype->opt_desc.desc) { + if (datatype->opt_desc.desc != datatype->desc.desc) { + free(datatype->opt_desc.desc); + } datatype->opt_desc.length = 0; - datatype->opt_desc.used = 0; - datatype->opt_desc.desc = NULL; + datatype->opt_desc.used = 0; + datatype->opt_desc.desc = NULL; } if (!opal_datatype_is_predefined(datatype)) { - if( NULL != datatype->desc.desc ) { - free( datatype->desc.desc ); + if (NULL != datatype->desc.desc) { + free(datatype->desc.desc); datatype->desc.length = 0; - datatype->desc.used = 0; - datatype->desc.desc = NULL; + datatype->desc.used = 0; + datatype->desc.desc = NULL; } } /* dont free the ptypes of predefined types (it was not dynamically allocated) */ - if( (NULL != datatype->ptypes) && (!opal_datatype_is_predefined(datatype)) ) { + if ((NULL != datatype->ptypes) && (!opal_datatype_is_predefined(datatype))) { free(datatype->ptypes); datatype->ptypes = NULL; } @@ -90,27 +91,32 @@ static void opal_datatype_destruct( opal_datatype_t* datatype ) OBJ_CLASS_INSTANCE(opal_datatype_t, opal_object_t, opal_datatype_construct, opal_datatype_destruct); -opal_datatype_t* opal_datatype_create( int32_t expectedSize ) +opal_datatype_t *opal_datatype_create(int32_t expectedSize) { - opal_datatype_t* datatype = (opal_datatype_t*)OBJ_NEW(opal_datatype_t); + opal_datatype_t *datatype = (opal_datatype_t *) OBJ_NEW(opal_datatype_t); - if( expectedSize == -1 ) expectedSize = DT_INCREASE_STACK; - datatype->desc.length = expectedSize + 1; /* one for the fake elem at the end */ - datatype->desc.used = 0; - datatype->desc.desc = (dt_elem_desc_t*)calloc(datatype->desc.length, sizeof(dt_elem_desc_t)); - /* BEWARE: an upper-layer configured with OPAL_MAX_OBJECT_NAME different than the OPAL-layer will not work! */ - memset( datatype->name, 0, OPAL_MAX_OBJECT_NAME ); + if (expectedSize == -1) { + expectedSize = DT_INCREASE_STACK; + } + datatype->desc.length = expectedSize + 1; /* one for the fake elem at the end */ + datatype->desc.used = 0; + datatype->desc.desc = (dt_elem_desc_t *) calloc(datatype->desc.length, sizeof(dt_elem_desc_t)); + /* BEWARE: an upper-layer configured with OPAL_MAX_OBJECT_NAME different than the OPAL-layer + * will not work! */ + memset(datatype->name, 0, OPAL_MAX_OBJECT_NAME); return datatype; } -int32_t opal_datatype_create_desc( opal_datatype_t * datatype, int32_t expectedSize ) +int32_t opal_datatype_create_desc(opal_datatype_t *datatype, int32_t expectedSize) { - if( expectedSize == -1 ) + if (expectedSize == -1) { expectedSize = DT_INCREASE_STACK; - datatype->desc.length = expectedSize + 1; /* one for the fake elem at the end */ - datatype->desc.used = 0; - datatype->desc.desc = (dt_elem_desc_t*)calloc(datatype->desc.length, sizeof(dt_elem_desc_t)); - if (NULL == datatype->desc.desc) + } + datatype->desc.length = expectedSize + 1; /* one for the fake elem at the end */ + datatype->desc.used = 0; + datatype->desc.desc = (dt_elem_desc_t *) calloc(datatype->desc.length, sizeof(dt_elem_desc_t)); + if (NULL == datatype->desc.desc) { return OPAL_ERR_OUT_OF_RESOURCE; + } return OPAL_SUCCESS; } diff --git a/opal/datatype/opal_datatype_create_contiguous.c b/opal/datatype/opal_datatype_create_contiguous.c index 3db53000d16..28664d64c8c 100644 --- a/opal/datatype/opal_datatype_create_contiguous.c +++ b/opal/datatype/opal_datatype_create_contiguous.c @@ -24,17 +24,17 @@ #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -int32_t opal_datatype_create_contiguous( int count, const opal_datatype_t* oldType, - opal_datatype_t** newType ) +int32_t opal_datatype_create_contiguous(int count, const opal_datatype_t *oldType, + opal_datatype_t **newType) { - opal_datatype_t* pdt; + opal_datatype_t *pdt; - if( 0 == count ) { - pdt = opal_datatype_create( 0 ); - opal_datatype_add( pdt, &opal_datatype_empty, 0, 0, 0 ); + if (0 == count) { + pdt = opal_datatype_create(0); + opal_datatype_add(pdt, &opal_datatype_empty, 0, 0, 0); } else { - pdt = opal_datatype_create( oldType->desc.used + 2 ); - opal_datatype_add( pdt, oldType, count, 0, (oldType->ub - oldType->lb) ); + pdt = opal_datatype_create(oldType->desc.used + 2); + opal_datatype_add(pdt, oldType, count, 0, (oldType->ub - oldType->lb)); } *newType = pdt; return OPAL_SUCCESS; diff --git a/opal/datatype/opal_datatype_destroy.c b/opal/datatype/opal_datatype_destroy.c index d468cd07e8c..3381df622bf 100644 --- a/opal/datatype/opal_datatype_destroy.c +++ b/opal/datatype/opal_datatype_destroy.c @@ -23,15 +23,15 @@ #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -int32_t opal_datatype_destroy( opal_datatype_t** dt ) +int32_t opal_datatype_destroy(opal_datatype_t **dt) { - opal_datatype_t* pData = *dt; + opal_datatype_t *pData = *dt; - if( (pData->flags & OPAL_DATATYPE_FLAG_PREDEFINED) && - (pData->super.obj_reference_count <= 1) ) + if ((pData->flags & OPAL_DATATYPE_FLAG_PREDEFINED) && (pData->super.obj_reference_count <= 1)) { return OPAL_ERROR; + } - OBJ_RELEASE( pData ); + OBJ_RELEASE(pData); *dt = NULL; return OPAL_SUCCESS; } diff --git a/opal/datatype/opal_datatype_dump.c b/opal/datatype/opal_datatype_dump.c index 27903db657e..ca06a79307a 100644 --- a/opal/datatype/opal_datatype_dump.c +++ b/opal/datatype/opal_datatype_dump.c @@ -24,134 +24,181 @@ #include "opal_config.h" -#include #include +#include #include "opal/constants.h" -#include "opal/util/output.h" #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" +#include "opal/util/output.h" /******************************************************** * Data dumping functions ********************************************************/ -int opal_datatype_contain_basic_datatypes( const opal_datatype_t* pData, char* ptr, size_t length ) +int opal_datatype_contain_basic_datatypes(const opal_datatype_t *pData, char *ptr, size_t length) { int i; int32_t index = 0; uint64_t mask = 1; - if( pData->flags & OPAL_DATATYPE_FLAG_USER_LB ) index += snprintf( ptr, length - index, "lb " ); - if( pData->flags & OPAL_DATATYPE_FLAG_USER_UB ) index += snprintf( ptr + index, length - index, "ub " ); - for( i = 0; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) { - if( pData->bdt_used & mask ) { - if( NULL == pData->ptypes ) { - index += snprintf( ptr + index, length - index, "%s:* ", opal_datatype_basicDatatypes[i]->name ); + if (pData->flags & OPAL_DATATYPE_FLAG_USER_LB) { + index += snprintf(ptr, length - index, "lb "); + } + if (pData->flags & OPAL_DATATYPE_FLAG_USER_UB) { + index += snprintf(ptr + index, length - index, "ub "); + } + for (i = 0; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) { + if (pData->bdt_used & mask) { + if (NULL == pData->ptypes) { + index += snprintf(ptr + index, length - index, "%s:* ", + opal_datatype_basicDatatypes[i]->name); } else { - index += snprintf( ptr + index, length - index, "%s:%" PRIsize_t " ", opal_datatype_basicDatatypes[i]->name, - pData->ptypes[i]); + index += snprintf(ptr + index, length - index, "%s:%" PRIsize_t " ", + opal_datatype_basicDatatypes[i]->name, pData->ptypes[i]); } } mask <<= 1; - if( length <= (size_t)index ) break; + if (length <= (size_t) index) { + break; + } } return index; } -int opal_datatype_dump_data_flags( unsigned short usflags, char* ptr, size_t length ) +int opal_datatype_dump_data_flags(unsigned short usflags, char *ptr, size_t length) { int index = 0; - if( length < 22 ) return 0; - index = snprintf( ptr, 22, "-----------[---][---]" ); /* set everything to - */ - if( usflags & OPAL_DATATYPE_FLAG_COMMITTED ) ptr[1] = 'c'; - if( usflags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) ptr[2] = 'C'; - if( usflags & OPAL_DATATYPE_FLAG_OVERLAP ) ptr[3] = 'o'; - if( usflags & OPAL_DATATYPE_FLAG_USER_LB ) ptr[4] = 'l'; - if( usflags & OPAL_DATATYPE_FLAG_USER_UB ) ptr[5] = 'u'; - if( usflags & OPAL_DATATYPE_FLAG_PREDEFINED ) ptr[6] = 'P'; - if( !(usflags & OPAL_DATATYPE_FLAG_NO_GAPS) ) ptr[7] = 'G'; - if( usflags & OPAL_DATATYPE_FLAG_DATA ) ptr[8] = 'D'; - if( (usflags & OPAL_DATATYPE_FLAG_BASIC) == OPAL_DATATYPE_FLAG_BASIC ) ptr[9] = 'B'; + if (length < 22) { + return 0; + } + index = snprintf(ptr, 22, "-----------[---][---]"); /* set everything to - */ + if (usflags & OPAL_DATATYPE_FLAG_COMMITTED) { + ptr[1] = 'c'; + } + if (usflags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + ptr[2] = 'C'; + } + if (usflags & OPAL_DATATYPE_FLAG_OVERLAP) { + ptr[3] = 'o'; + } + if (usflags & OPAL_DATATYPE_FLAG_USER_LB) { + ptr[4] = 'l'; + } + if (usflags & OPAL_DATATYPE_FLAG_USER_UB) { + ptr[5] = 'u'; + } + if (usflags & OPAL_DATATYPE_FLAG_PREDEFINED) { + ptr[6] = 'P'; + } + if (!(usflags & OPAL_DATATYPE_FLAG_NO_GAPS)) { + ptr[7] = 'G'; + } + if (usflags & OPAL_DATATYPE_FLAG_DATA) { + ptr[8] = 'D'; + } + if ((usflags & OPAL_DATATYPE_FLAG_BASIC) == OPAL_DATATYPE_FLAG_BASIC) { + ptr[9] = 'B'; + } /* We know nothing about the upper level language or flags! */ /* ... */ return index; } - -int opal_datatype_dump_data_desc( dt_elem_desc_t* pDesc, int nbElems, char* ptr, size_t length ) +int opal_datatype_dump_data_desc(dt_elem_desc_t *pDesc, int nbElems, char *ptr, size_t length) { int i; int32_t index = 0; - for( i = 0; i < nbElems; i++ ) { - index += opal_datatype_dump_data_flags( pDesc->elem.common.flags, ptr + index, length ); - if( length <= (size_t)index ) break; - index += snprintf( ptr + index, length - index, "%15s ", opal_datatype_basicDatatypes[pDesc->elem.common.type]->name ); - if( length <= (size_t)index ) break; - if( OPAL_DATATYPE_LOOP == pDesc->elem.common.type ) - index += snprintf( ptr + index, length - index, "%u times the next %u elements extent %td\n", - pDesc->loop.loops, pDesc->loop.items, - pDesc->loop.extent ); - else if( OPAL_DATATYPE_END_LOOP == pDesc->elem.common.type ) - index += snprintf( ptr + index, length - index, "prev %u elements first elem displacement %td size of data %" PRIsize_t "\n", - pDesc->end_loop.items, pDesc->end_loop.first_elem_disp, - pDesc->end_loop.size ); - else - index += snprintf( ptr + index, length - index, "count %u disp 0x%tx (%td) blen %" PRIsize_t " extent %td (size %zd)\n", - pDesc->elem.count, pDesc->elem.disp, pDesc->elem.disp, pDesc->elem.blocklen, - pDesc->elem.extent, (pDesc->elem.count * pDesc->elem.blocklen * opal_datatype_basicDatatypes[pDesc->elem.common.type]->size) ); + for (i = 0; i < nbElems; i++) { + index += opal_datatype_dump_data_flags(pDesc->elem.common.flags, ptr + index, length); + if (length <= (size_t) index) { + break; + } + index += snprintf(ptr + index, length - index, "%15s ", + opal_datatype_basicDatatypes[pDesc->elem.common.type]->name); + if (length <= (size_t) index) { + break; + } + if (OPAL_DATATYPE_LOOP == pDesc->elem.common.type) { + index += snprintf(ptr + index, length - index, + "%u times the next %u elements extent %td\n", pDesc->loop.loops, + pDesc->loop.items, pDesc->loop.extent); + } else if (OPAL_DATATYPE_END_LOOP == pDesc->elem.common.type) { + index += snprintf( + ptr + index, length - index, + "prev %u elements first elem displacement %td size of data %" PRIsize_t "\n", + pDesc->end_loop.items, pDesc->end_loop.first_elem_disp, pDesc->end_loop.size); + } else { + index += snprintf(ptr + index, length - index, + "count %u disp 0x%tx (%td) blen %" PRIsize_t + " extent %td (size %zd)\n", + pDesc->elem.count, pDesc->elem.disp, pDesc->elem.disp, + pDesc->elem.blocklen, pDesc->elem.extent, + (pDesc->elem.count * pDesc->elem.blocklen + * opal_datatype_basicDatatypes[pDesc->elem.common.type]->size)); + } pDesc++; - if( length <= (size_t)index ) break; + if (length <= (size_t) index) { + break; + } } return index; } - -void opal_datatype_dump( const opal_datatype_t* pData ) +void opal_datatype_dump(const opal_datatype_t *pData) { size_t length; int index = 0; - char* buffer; + char *buffer; length = pData->opt_desc.used + pData->desc.used; length = length * 100 + 500; - buffer = (char*)malloc( length ); - index += snprintf( buffer, length - index, "Datatype %p[%s] size %" PRIsize_t " align %u id %u length %" PRIsize_t " used %" PRIsize_t "\n" - "true_lb %td true_ub %td (true_extent %td) lb %td ub %td (extent %td)\n" - "nbElems %" PRIsize_t " loops %u flags %X (", - (void*)pData, pData->name, pData->size, pData->align, (uint32_t)pData->id, pData->desc.length, pData->desc.used, - pData->true_lb, pData->true_ub, pData->true_ub - pData->true_lb, - pData->lb, pData->ub, pData->ub - pData->lb, - pData->nbElems, pData->loops, (int)pData->flags ); + buffer = (char *) malloc(length); + index += snprintf(buffer, length - index, + "Datatype %p[%s] size %" PRIsize_t " align %u id %u length %" PRIsize_t + " used %" PRIsize_t "\n" + "true_lb %td true_ub %td (true_extent %td) lb %td ub %td (extent %td)\n" + "nbElems %" PRIsize_t " loops %u flags %X (", + (void *) pData, pData->name, pData->size, pData->align, (uint32_t) pData->id, + pData->desc.length, pData->desc.used, pData->true_lb, pData->true_ub, + pData->true_ub - pData->true_lb, pData->lb, pData->ub, pData->ub - pData->lb, + pData->nbElems, pData->loops, (int) pData->flags); /* dump the flags */ - if( pData->flags == OPAL_DATATYPE_FLAG_PREDEFINED ) - index += snprintf( buffer + index, length - index, "predefined " ); - else { - if( pData->flags & OPAL_DATATYPE_FLAG_COMMITTED ) index += snprintf( buffer + index, length - index, "committed " ); - if( pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) index += snprintf( buffer + index, length - index, "contiguous " ); - } - index += snprintf( buffer + index, length - index, ")" ); - index += opal_datatype_dump_data_flags( pData->flags, buffer + index, length - index ); + if (pData->flags == OPAL_DATATYPE_FLAG_PREDEFINED) { + index += snprintf(buffer + index, length - index, "predefined "); + } else { + if (pData->flags & OPAL_DATATYPE_FLAG_COMMITTED) { + index += snprintf(buffer + index, length - index, "committed "); + } + if (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + index += snprintf(buffer + index, length - index, "contiguous "); + } + } + index += snprintf(buffer + index, length - index, ")"); + index += opal_datatype_dump_data_flags(pData->flags, buffer + index, length - index); { - index += snprintf( buffer + index, length - index, "\n contain " ); - index += opal_datatype_contain_basic_datatypes( pData, buffer + index, length - index ); - index += snprintf( buffer + index, length - index, "\n" ); + index += snprintf(buffer + index, length - index, "\n contain "); + index += opal_datatype_contain_basic_datatypes(pData, buffer + index, length - index); + index += snprintf(buffer + index, length - index, "\n"); } - if( (pData->opt_desc.desc != pData->desc.desc) && (NULL != pData->opt_desc.desc) ) { + if ((pData->opt_desc.desc != pData->desc.desc) && (NULL != pData->opt_desc.desc)) { /* If the data is already committed print everything including the last * fake OPAL_DATATYPE_END_LOOP entry. */ - index += opal_datatype_dump_data_desc( pData->desc.desc, pData->desc.used + 1, buffer + index, length - index ); - index += snprintf( buffer + index, length - index, "Optimized description \n" ); - index += opal_datatype_dump_data_desc( pData->opt_desc.desc, pData->opt_desc.used + 1, buffer + index, length - index ); + index += opal_datatype_dump_data_desc(pData->desc.desc, pData->desc.used + 1, + buffer + index, length - index); + index += snprintf(buffer + index, length - index, "Optimized description \n"); + index += opal_datatype_dump_data_desc(pData->opt_desc.desc, pData->opt_desc.used + 1, + buffer + index, length - index); } else { - index += opal_datatype_dump_data_desc( pData->desc.desc, pData->desc.used, buffer + index, length - index ); - index += snprintf( buffer + index, length - index, "No optimized description\n" ); + index += opal_datatype_dump_data_desc(pData->desc.desc, pData->desc.used, buffer + index, + length - index); + index += snprintf(buffer + index, length - index, "No optimized description\n"); } - buffer[index] = '\0'; /* make sure we end the string with 0 */ - opal_output( 0, "%s\n", buffer ); + buffer[index] = '\0'; /* make sure we end the string with 0 */ + opal_output(0, "%s\n", buffer); free(buffer); } diff --git a/opal/datatype/opal_datatype_fake_stack.c b/opal/datatype/opal_datatype_fake_stack.c index aee2ccf9058..dffd20be8a8 100644 --- a/opal/datatype/opal_datatype_fake_stack.c +++ b/opal/datatype/opal_datatype_fake_stack.c @@ -26,32 +26,31 @@ #include #ifdef HAVE_ALLOCA_H -#include +# include #endif -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" +#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" +extern int opal_convertor_create_stack_with_pos_general(opal_convertor_t *convertor, + size_t starting_point, const size_t *sizes); -extern int opal_convertor_create_stack_with_pos_general( opal_convertor_t* convertor, - size_t starting_point, const size_t* sizes ); - -int opal_convertor_create_stack_with_pos_general( opal_convertor_t* pConvertor, - size_t starting_point, const size_t* sizes ) +int opal_convertor_create_stack_with_pos_general(opal_convertor_t *pConvertor, + size_t starting_point, const size_t *sizes) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - int pos_desc; /* actual position in the description of the derived datatype */ + dt_stack_t *pStack; /* pointer to the position on the stack */ + int pos_desc; /* actual position in the description of the derived datatype */ size_t lastLength = 0; - const opal_datatype_t* pData = pConvertor->pDesc; + const opal_datatype_t *pData = pConvertor->pDesc; size_t loop_length, *remoteLength, remote_size; size_t resting_place = starting_point; - dt_elem_desc_t* pElems; + dt_elem_desc_t *pElems; size_t count; - assert( 0 != starting_point ); - assert( pConvertor->bConverted != starting_point ); - assert( starting_point <=(pConvertor->count * pData->size) ); + assert(0 != starting_point); + assert(pConvertor->bConverted != starting_point); + assert(starting_point <= (pConvertor->count * pData->size)); /*opal_output( 0, "Data extent %d size %d count %d total_size %d starting_point %d\n", pData->ub - pData->lb, pData->size, pConvertor->count, @@ -64,24 +63,25 @@ int opal_convertor_create_stack_with_pos_general( opal_convertor_t* pConvertor, */ pElems = pConvertor->use_desc->desc; - if( (pConvertor->flags & CONVERTOR_HOMOGENEOUS) && (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) { + if ((pConvertor->flags & CONVERTOR_HOMOGENEOUS) + && (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) { /* Special case for contiguous datatypes */ int32_t cnt = (int32_t)(starting_point / pData->size); ptrdiff_t extent = pData->ub - pData->lb; - loop_length = GET_FIRST_NON_LOOP( pElems ); - pStack[0].disp = pElems[loop_length].elem.disp; - pStack[0].type = OPAL_DATATYPE_LOOP; + loop_length = GET_FIRST_NON_LOOP(pElems); + pStack[0].disp = pElems[loop_length].elem.disp; + pStack[0].type = OPAL_DATATYPE_LOOP; pStack[0].count = pConvertor->count - cnt; - cnt = (int32_t)(starting_point - cnt * pData->size); /* number of bytes after the loop */ - pStack[1].index = 0; - pStack[1].type = OPAL_DATATYPE_UINT1; - pStack[1].disp = pStack[0].disp; - pStack[1].count = pData->size - cnt; + cnt = (int32_t)(starting_point - cnt * pData->size); /* number of bytes after the loop */ + pStack[1].index = 0; + pStack[1].type = OPAL_DATATYPE_UINT1; + pStack[1].disp = pStack[0].disp; + pStack[1].count = pData->size - cnt; - if( (ptrdiff_t)pData->size == extent ) { /* all elements are contiguous */ + if ((ptrdiff_t) pData->size == extent) { /* all elements are contiguous */ pStack[1].disp += starting_point; - } else { /* each is contiguous but there are gaps inbetween */ + } else { /* each is contiguous but there are gaps inbetween */ pStack[1].disp += (pConvertor->count - pStack[0].count) * extent + cnt; } @@ -91,47 +91,47 @@ int opal_convertor_create_stack_with_pos_general( opal_convertor_t* pConvertor, } /* remove from the main loop all the complete datatypes */ - assert (! (pConvertor->flags & CONVERTOR_SEND)); - remote_size = opal_convertor_compute_remote_size( pConvertor ); - count = starting_point / remote_size; + assert(!(pConvertor->flags & CONVERTOR_SEND)); + remote_size = opal_convertor_compute_remote_size(pConvertor); + count = starting_point / remote_size; resting_place -= (remote_size * count); - pStack->count = pConvertor->count - count; - pStack->index = -1; + pStack->count = pConvertor->count - count; + pStack->index = -1; - loop_length = GET_FIRST_NON_LOOP( pElems ); + loop_length = GET_FIRST_NON_LOOP(pElems); pStack->disp = count * (pData->ub - pData->lb) + pElems[loop_length].elem.disp; - pos_desc = 0; - remoteLength = (size_t*)alloca( sizeof(size_t) * (pConvertor->pDesc->loops + 1)); - remoteLength[0] = 0; /* initial value set to ZERO */ + pos_desc = 0; + remoteLength = (size_t *) alloca(sizeof(size_t) * (pConvertor->pDesc->loops + 1)); + remoteLength[0] = 0; /* initial value set to ZERO */ loop_length = 0; /* The only way to get out of this loop is when we reach the desired position or * when we finish the whole datatype. */ - while( pos_desc < (int32_t)pConvertor->use_desc->used ) { - if( OPAL_DATATYPE_END_LOOP == pElems->elem.common.type ) { /* end of the current loop */ - ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)pElems; + while (pos_desc < (int32_t) pConvertor->use_desc->used) { + if (OPAL_DATATYPE_END_LOOP == pElems->elem.common.type) { /* end of the current loop */ + ddt_endloop_desc_t *end_loop = (ddt_endloop_desc_t *) pElems; ptrdiff_t extent; - if( (loop_length * pStack->count) > resting_place ) { + if ((loop_length * pStack->count) > resting_place) { /* We will stop somewhere on this loop. To avoid moving inside the loop * multiple times, we can compute the index of the loop where we will * stop. Once this index is computed we can then reparse the loop once * until we find the correct position. */ int32_t cnt = (int32_t)(resting_place / loop_length); - if( pStack->index == -1 ) { + if (pStack->index == -1) { extent = pData->ub - pData->lb; } else { - assert( OPAL_DATATYPE_LOOP == (pElems - end_loop->items)->loop.common.type ); - extent = ((ddt_loop_desc_t*)(pElems - end_loop->items))->extent; + assert(OPAL_DATATYPE_LOOP == (pElems - end_loop->items)->loop.common.type); + extent = ((ddt_loop_desc_t *) (pElems - end_loop->items))->extent; } pStack->count -= (cnt + 1); resting_place -= cnt * loop_length; pStack->disp += (cnt + 1) * extent; /* reset the remoteLength as we act as restarting the last loop */ - pos_desc -= (end_loop->items - 1); /* go back to the first element in the loop */ + pos_desc -= (end_loop->items - 1); /* go back to the first element in the loop */ pElems -= (end_loop->items - 1); remoteLength[pConvertor->stack_pos] = 0; loop_length = 0; @@ -140,7 +140,7 @@ int opal_convertor_create_stack_with_pos_general( opal_convertor_t* pConvertor, /* Not in this loop. Cleanup the stack and advance to the * next data description. */ - resting_place -= (loop_length * (pStack->count - 1)); /* update the resting place */ + resting_place -= (loop_length * (pStack->count - 1)); /* update the resting place */ pStack--; pConvertor->stack_pos--; pos_desc++; @@ -149,34 +149,33 @@ int opal_convertor_create_stack_with_pos_general( opal_convertor_t* pConvertor, loop_length = remoteLength[pConvertor->stack_pos]; continue; } - if( OPAL_DATATYPE_LOOP == pElems->elem.common.type ) { + if (OPAL_DATATYPE_LOOP == pElems->elem.common.type) { remoteLength[pConvertor->stack_pos] += loop_length; - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, - pElems->loop.loops, pStack->disp ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, + pElems->loop.loops, pStack->disp); pos_desc++; pElems++; remoteLength[pConvertor->stack_pos] = 0; - loop_length = 0; /* starting a new loop */ + loop_length = 0; /* starting a new loop */ } - while( pElems->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (pElems->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ - const opal_datatype_t* basic_type = BASIC_DDT_FROM_ELEM( (*pElems) ); - lastLength = (size_t)pElems->elem.count * basic_type->size; - if( resting_place < lastLength ) { + const opal_datatype_t *basic_type = BASIC_DDT_FROM_ELEM((*pElems)); + lastLength = (size_t) pElems->elem.count * basic_type->size; + if (resting_place < lastLength) { int32_t cnt = (int32_t)(resting_place / basic_type->size); loop_length += (cnt * basic_type->size); resting_place -= (cnt * basic_type->size); - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElems->elem.common.type, - pElems->elem.count - cnt, - pElems->elem.disp + cnt * pElems->elem.extent ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, pElems->elem.common.type, + pElems->elem.count - cnt, pElems->elem.disp + cnt * pElems->elem.extent); pConvertor->bConverted = starting_point - resting_place; - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, - pConvertor->pDesc->desc.desc, pConvertor->pDesc->name ); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, + pConvertor->pDesc->desc.desc, pConvertor->pDesc->name); return OPAL_SUCCESS; } loop_length += lastLength; resting_place -= lastLength; - pos_desc++; /* advance to the next data */ + pos_desc++; /* advance to the next data */ pElems++; } } diff --git a/opal/datatype/opal_datatype_get_count.c b/opal/datatype/opal_datatype_get_count.c index 12dba4d0d48..202601d97a2 100644 --- a/opal/datatype/opal_datatype_get_count.c +++ b/opal/datatype/opal_datatype_get_count.c @@ -12,12 +12,12 @@ */ #include "opal_config.h" -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" +#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" #ifdef HAVE_ALLOCA_H -#include +# include #endif /* Get the number of elements from the data-type that can be @@ -28,68 +28,76 @@ * positive = number of basic elements inside * negative = some error occurs */ -ssize_t opal_datatype_get_element_count( const opal_datatype_t* datatype, size_t iSize ) +ssize_t opal_datatype_get_element_count(const opal_datatype_t *datatype, size_t iSize) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ ssize_t nbElems = 0, stack_pos = 0; size_t local_size; - dt_elem_desc_t* pElems; + dt_elem_desc_t *pElems; /* Normally the size should be less or equal to the size of the datatype. * This function does not support a iSize bigger than the size of the datatype. */ - assert( iSize <= datatype->size ); - DUMP( "dt_count_elements( %p, %ul )\n", (void*)datatype, (unsigned long)iSize ); - pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (datatype->loops + 2) ); - pStack->count = 1; - pStack->index = -1; - pStack->disp = 0; - pElems = datatype->desc.desc; - pos_desc = 0; + assert(iSize <= datatype->size); + DUMP("dt_count_elements( %p, %ul )\n", (void *) datatype, (unsigned long) iSize); + pStack = (dt_stack_t *) alloca(sizeof(dt_stack_t) * (datatype->loops + 2)); + pStack->count = 1; + pStack->index = -1; + pStack->disp = 0; + pElems = datatype->desc.desc; + pos_desc = 0; - while( 1 ) { /* loop forever the exit condition is on the last OPAL_DATATYPE_END_LOOP */ - if( OPAL_DATATYPE_END_LOOP == pElems[pos_desc].elem.common.type ) { /* end of the current loop */ - if( --(pStack->count) == 0 ) { /* end of loop */ - stack_pos--; pStack--; - if( stack_pos == -1 ) return nbElems; /* completed */ - pos_desc++; /* advance to the next element after the end loop */ + while (1) { /* loop forever the exit condition is on the last OPAL_DATATYPE_END_LOOP */ + if (OPAL_DATATYPE_END_LOOP + == pElems[pos_desc].elem.common.type) { /* end of the current loop */ + if (--(pStack->count) == 0) { /* end of loop */ + stack_pos--; + pStack--; + if (stack_pos == -1) { + return nbElems; /* completed */ + } + pos_desc++; /* advance to the next element after the end loop */ } else { - pos_desc = pStack->index + 1; /* go back to the begining of the loop */ + pos_desc = pStack->index + 1; /* go back to the begining of the loop */ } continue; } - if( OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type ) { + if (OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type) { do { - PUSH_STACK( pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, pElems[pos_desc].loop.loops, 0 ); + PUSH_STACK(pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, + pElems[pos_desc].loop.loops, 0); pos_desc++; - } while( OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type ); /* let's start another loop */ - DDT_DUMP_STACK( pStack, stack_pos, pElems, "advance loops" ); + } while (OPAL_DATATYPE_LOOP + == pElems[pos_desc].elem.common.type); /* let's start another loop */ + DDT_DUMP_STACK(pStack, stack_pos, pElems, "advance loops"); } - while( pElems[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (pElems[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ - const opal_datatype_t* basic_type = BASIC_DDT_FROM_ELEM(pElems[pos_desc]); - local_size = ((size_t)pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen) * basic_type->size; - if( local_size >= iSize ) { + const opal_datatype_t *basic_type = BASIC_DDT_FROM_ELEM(pElems[pos_desc]); + local_size = ((size_t) pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen) + * basic_type->size; + if (local_size >= iSize) { local_size = iSize / basic_type->size; - nbElems += (int32_t)local_size; + nbElems += (int32_t) local_size; iSize -= local_size * basic_type->size; return (iSize == 0 ? nbElems : -1); } - nbElems += ((size_t)pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen); + nbElems += ((size_t) pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen); iSize -= local_size; - pos_desc++; /* advance to the next data */ + pos_desc++; /* advance to the next data */ } } } -int32_t opal_datatype_set_element_count( const opal_datatype_t* datatype, size_t count, size_t* length ) +int32_t opal_datatype_set_element_count(const opal_datatype_t *datatype, size_t count, + size_t *length) { - dt_stack_t* pStack; /* pointer to the position on the stack */ + dt_stack_t *pStack; /* pointer to the position on the stack */ size_t pos_desc; /* actual position in the description of the derived datatype */ int32_t stack_pos = 0; size_t local_length = 0; - dt_elem_desc_t* pElems; + dt_elem_desc_t *pElems; /** * Handle all complete multiple of the datatype. @@ -98,47 +106,53 @@ int32_t opal_datatype_set_element_count( const opal_datatype_t* datatype, size_t pos_desc = count / local_length; count = count % local_length; *length = datatype->size * pos_desc; - if( 0 == count ) { + if (0 == count) { return 0; } - DUMP( "dt_set_element_count( %p, %d )\n", (void*)datatype, count ); - pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (datatype->loops + 2) ); - pStack->count = 1; - pStack->index = -1; - pStack->disp = 0; - pElems = datatype->desc.desc; - pos_desc = 0; + DUMP("dt_set_element_count( %p, %d )\n", (void *) datatype, count); + pStack = (dt_stack_t *) alloca(sizeof(dt_stack_t) * (datatype->loops + 2)); + pStack->count = 1; + pStack->index = -1; + pStack->disp = 0; + pElems = datatype->desc.desc; + pos_desc = 0; - while( 1 ) { /* loop forever the exit condition is on the last OPAL_DATATYPE_END_LOOP */ - if( OPAL_DATATYPE_END_LOOP == pElems[pos_desc].elem.common.type ) { /* end of the current loop */ - if( --(pStack->count) == 0 ) { /* end of loop */ - stack_pos--; pStack--; - if( stack_pos == -1 ) return 0; - pos_desc++; /* advance to the next element after the end loop */ + while (1) { /* loop forever the exit condition is on the last OPAL_DATATYPE_END_LOOP */ + if (OPAL_DATATYPE_END_LOOP + == pElems[pos_desc].elem.common.type) { /* end of the current loop */ + if (--(pStack->count) == 0) { /* end of loop */ + stack_pos--; + pStack--; + if (stack_pos == -1) { + return 0; + } + pos_desc++; /* advance to the next element after the end loop */ } else { - pos_desc = pStack->index + 1; /* go back to the begining of the loop */ + pos_desc = pStack->index + 1; /* go back to the begining of the loop */ } continue; } - if( OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type ) { + if (OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type) { do { - PUSH_STACK( pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, pElems[pos_desc].loop.loops, 0 ); + PUSH_STACK(pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, + pElems[pos_desc].loop.loops, 0); pos_desc++; - } while( OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type ); /* let's start another loop */ - DDT_DUMP_STACK( pStack, stack_pos, pElems, "advance loops" ); + } while (OPAL_DATATYPE_LOOP + == pElems[pos_desc].elem.common.type); /* let's start another loop */ + DDT_DUMP_STACK(pStack, stack_pos, pElems, "advance loops"); } - while( pElems[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (pElems[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ - const opal_datatype_t* basic_type = BASIC_DDT_FROM_ELEM(pElems[pos_desc]); - local_length = ((size_t)pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen); - if( local_length >= count ) { + const opal_datatype_t *basic_type = BASIC_DDT_FROM_ELEM(pElems[pos_desc]); + local_length = ((size_t) pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen); + if (local_length >= count) { *length += count * basic_type->size; return 0; } *length += local_length * basic_type->size; count -= local_length; - pos_desc++; /* advance to the next data */ + pos_desc++; /* advance to the next data */ } } } @@ -150,51 +164,62 @@ int32_t opal_datatype_set_element_count( const opal_datatype_t* datatype, size_t * when we use get_element_count). Thus, we will pay the cost once per * datatype, but we will only update this array if/when needed. */ -int opal_datatype_compute_ptypes( opal_datatype_t* datatype ) +int opal_datatype_compute_ptypes(opal_datatype_t *datatype) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ ssize_t nbElems = 0, stack_pos = 0; - dt_elem_desc_t* pElems; + dt_elem_desc_t *pElems; - if( NULL != datatype->ptypes ) return 0; - datatype->ptypes = (size_t*)calloc(OPAL_DATATYPE_MAX_SUPPORTED, sizeof(size_t)); + if (NULL != datatype->ptypes) { + return 0; + } + datatype->ptypes = (size_t *) calloc(OPAL_DATATYPE_MAX_SUPPORTED, sizeof(size_t)); - DUMP( "opal_datatype_compute_ptypes( %p )\n", (void*)datatype ); - pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (datatype->loops + 2) ); - pStack->count = 1; - pStack->index = -1; - pStack->disp = 0; - pElems = datatype->desc.desc; - pos_desc = 0; + DUMP("opal_datatype_compute_ptypes( %p )\n", (void *) datatype); + pStack = (dt_stack_t *) alloca(sizeof(dt_stack_t) * (datatype->loops + 2)); + pStack->count = 1; + pStack->index = -1; + pStack->disp = 0; + pElems = datatype->desc.desc; + pos_desc = 0; - while( 1 ) { /* loop forever the exit condition is on the last OPAL_DATATYPE_END_LOOP */ - if( OPAL_DATATYPE_END_LOOP == pElems[pos_desc].elem.common.type ) { /* end of the current loop */ - if( --(pStack->count) == 0 ) { /* end of loop */ - stack_pos--; pStack--; - if( stack_pos == -1 ) return 0; /* completed */ - pos_desc++; /* advance to the next element after the end loop */ + while (1) { /* loop forever the exit condition is on the last OPAL_DATATYPE_END_LOOP */ + if (OPAL_DATATYPE_END_LOOP + == pElems[pos_desc].elem.common.type) { /* end of the current loop */ + if (--(pStack->count) == 0) { /* end of loop */ + stack_pos--; + pStack--; + if (stack_pos == -1) { + return 0; /* completed */ + } + pos_desc++; /* advance to the next element after the end loop */ } else { - pos_desc = pStack->index + 1; /* go back to the begining of the loop */ + pos_desc = pStack->index + 1; /* go back to the begining of the loop */ } continue; } - if( OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type ) { + if (OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type) { do { - PUSH_STACK( pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, pElems[pos_desc].loop.loops, 0 ); + PUSH_STACK(pStack, stack_pos, pos_desc, OPAL_DATATYPE_LOOP, + pElems[pos_desc].loop.loops, 0); pos_desc++; - } while( OPAL_DATATYPE_LOOP == pElems[pos_desc].elem.common.type ); /* let's start another loop */ - DDT_DUMP_STACK( pStack, stack_pos, pElems, "advance loops" ); + } while (OPAL_DATATYPE_LOOP + == pElems[pos_desc].elem.common.type); /* let's start another loop */ + DDT_DUMP_STACK(pStack, stack_pos, pElems, "advance loops"); } - while( pElems[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (pElems[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ - datatype->ptypes[pElems[pos_desc].elem.common.type] += (size_t)pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen; - nbElems += (size_t)pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen; + datatype->ptypes[pElems[pos_desc].elem.common.type] += (size_t) pElems[pos_desc] + .elem.count + * pElems[pos_desc].elem.blocklen; + nbElems += (size_t) pElems[pos_desc].elem.count * pElems[pos_desc].elem.blocklen; - DUMP( " compute_ptypes-add: type %d count %"PRIsize_t" (total type %u total %lld)\n", - pElems[pos_desc].elem.common.type, datatype->ptypes[pElems[pos_desc].elem.common.type], - pElems[pos_desc].elem.count, nbElems ); - pos_desc++; /* advance to the next data */ + DUMP(" compute_ptypes-add: type %d count %" PRIsize_t " (total type %u total %lld)\n", + pElems[pos_desc].elem.common.type, + datatype->ptypes[pElems[pos_desc].elem.common.type], pElems[pos_desc].elem.count, + nbElems); + pos_desc++; /* advance to the next data */ } } } diff --git a/opal/datatype/opal_datatype_internal.h b/opal/datatype/opal_datatype_internal.h index b14acdf6168..10134549e5b 100644 --- a/opal/datatype/opal_datatype_internal.h +++ b/opal/datatype/opal_datatype_internal.h @@ -34,57 +34,21 @@ #include #if defined(VERBOSE) -#include "opal/util/output.h" +# include "opal/util/output.h" extern int opal_datatype_dfd; -# define DDT_DUMP_STACK( PSTACK, STACK_POS, PDESC, NAME ) \ - opal_datatype_dump_stack( (PSTACK), (STACK_POS), (PDESC), (NAME) ) -# if defined(ACCEPT_C99) -# define DUMP( ARGS... ) opal_output(opal_datatype_dfd, __VA_ARGS__) -# else -# if defined(__GNUC__) && !defined(__STDC__) -# define DUMP(ARGS...) opal_output( opal_datatype_dfd, ARGS) -# else -static inline void DUMP( char* fmt, ... ) -{ - va_list list; +# define DDT_DUMP_STACK(PSTACK, STACK_POS, PDESC, NAME) \ + opal_datatype_dump_stack((PSTACK), (STACK_POS), (PDESC), (NAME)) + +# define DUMP(ARGS...) opal_output(opal_datatype_dfd, ARGS) - va_start( list, fmt ); - opal_output_vverbose( 0, opal_datatype_dfd, fmt, list ); - va_end( list ); -} -# endif /* __GNUC__ && !__STDC__ */ -# endif /* ACCEPT_C99 */ #else -# define DDT_DUMP_STACK( PSTACK, STACK_POS, PDESC, NAME ) -# if defined(ACCEPT_C99) + +# define DDT_DUMP_STACK(PSTACK, STACK_POS, PDESC, NAME) # define DUMP(ARGS...) -# else -# if defined(__GNUC__) && !defined(__STDC__) -# define DUMP(ARGS...) -# else - /* If we do not compile with PGI, mark the parameter as unused */ -# if !defined(__PGI) -# define __opal_attribute_unused_tmp__ __opal_attribute_unused__ -# else -# define __opal_attribute_unused_tmp__ -# endif -static inline void DUMP( char* fmt __opal_attribute_unused_tmp__, ... ) -{ -#if defined(__PGI) - /* Some compilers complain if we have "..." arguments and no - corresponding va_start() */ - va_list arglist; - va_start(arglist, fmt); - va_end(arglist); -#endif -} -# undef __opal_attribute_unused_tmp__ -# endif /* __GNUC__ && !__STDC__ */ -# endif /* ACCEPT_C99 */ -#endif /* VERBOSE */ +#endif /* VERBOSE */ /* * There 3 types of predefined data types. @@ -102,51 +66,51 @@ static inline void DUMP( char* fmt __opal_attribute_unused_tmp__, ... ) * NOTE: This predefined datatype order should be matched by any upper-level * users of the OPAL datatype. */ -#define OPAL_DATATYPE_LOOP 0 -#define OPAL_DATATYPE_END_LOOP 1 -#define OPAL_DATATYPE_LB 2 -#define OPAL_DATATYPE_UB 3 -#define OPAL_DATATYPE_FIRST_TYPE 4 /* Number of first real type */ -#define OPAL_DATATYPE_INT1 4 -#define OPAL_DATATYPE_INT2 5 -#define OPAL_DATATYPE_INT4 6 -#define OPAL_DATATYPE_INT8 7 -#define OPAL_DATATYPE_INT16 8 -#define OPAL_DATATYPE_UINT1 9 -#define OPAL_DATATYPE_UINT2 10 -#define OPAL_DATATYPE_UINT4 11 -#define OPAL_DATATYPE_UINT8 12 -#define OPAL_DATATYPE_UINT16 13 -#define OPAL_DATATYPE_FLOAT2 14 -#define OPAL_DATATYPE_FLOAT4 15 -#define OPAL_DATATYPE_FLOAT8 16 -#define OPAL_DATATYPE_FLOAT12 17 -#define OPAL_DATATYPE_FLOAT16 18 +#define OPAL_DATATYPE_LOOP 0 +#define OPAL_DATATYPE_END_LOOP 1 +#define OPAL_DATATYPE_LB 2 +#define OPAL_DATATYPE_UB 3 +#define OPAL_DATATYPE_FIRST_TYPE 4 /* Number of first real type */ +#define OPAL_DATATYPE_INT1 4 +#define OPAL_DATATYPE_INT2 5 +#define OPAL_DATATYPE_INT4 6 +#define OPAL_DATATYPE_INT8 7 +#define OPAL_DATATYPE_INT16 8 +#define OPAL_DATATYPE_UINT1 9 +#define OPAL_DATATYPE_UINT2 10 +#define OPAL_DATATYPE_UINT4 11 +#define OPAL_DATATYPE_UINT8 12 +#define OPAL_DATATYPE_UINT16 13 +#define OPAL_DATATYPE_FLOAT2 14 +#define OPAL_DATATYPE_FLOAT4 15 +#define OPAL_DATATYPE_FLOAT8 16 +#define OPAL_DATATYPE_FLOAT12 17 +#define OPAL_DATATYPE_FLOAT16 18 #define OPAL_DATATYPE_SHORT_FLOAT_COMPLEX 19 -#define OPAL_DATATYPE_FLOAT_COMPLEX 20 -#define OPAL_DATATYPE_DOUBLE_COMPLEX 21 +#define OPAL_DATATYPE_FLOAT_COMPLEX 20 +#define OPAL_DATATYPE_DOUBLE_COMPLEX 21 #define OPAL_DATATYPE_LONG_DOUBLE_COMPLEX 22 -#define OPAL_DATATYPE_BOOL 23 -#define OPAL_DATATYPE_WCHAR 24 -#define OPAL_DATATYPE_UNAVAILABLE 25 +#define OPAL_DATATYPE_BOOL 23 +#define OPAL_DATATYPE_WCHAR 24 +#define OPAL_DATATYPE_UNAVAILABLE 25 #ifndef OPAL_DATATYPE_MAX_PREDEFINED -#define OPAL_DATATYPE_MAX_PREDEFINED (OPAL_DATATYPE_UNAVAILABLE+1) +# define OPAL_DATATYPE_MAX_PREDEFINED (OPAL_DATATYPE_UNAVAILABLE + 1) #elif OPAL_DATATYPE_MAX_PREDEFINED <= OPAL_DATATYPE_UNAVAILABLE /* * If the number of basic datatype should change update * OPAL_DATATYPE_MAX_PREDEFINED in opal_datatype.h */ -#error OPAL_DATATYPE_MAX_PREDEFINED should be updated to the next value after the OPAL_DATATYPE_UNAVAILABLE define +# error OPAL_DATATYPE_MAX_PREDEFINED should be updated to the next value after the OPAL_DATATYPE_UNAVAILABLE define #endif -#define DT_INCREASE_STACK 8 +#define DT_INCREASE_STACK 8 BEGIN_C_DECLS struct ddt_elem_id_description { - uint16_t flags; /**< flags for the record */ - uint16_t type; /**< the basic data type id */ + uint16_t flags; /**< flags for the record */ + uint16_t type; /**< the basic data type id */ }; typedef struct ddt_elem_id_description ddt_elem_id_description; @@ -156,11 +120,11 @@ typedef struct ddt_elem_id_description ddt_elem_id_description; * and then an extent for all the extra count. */ struct ddt_elem_desc { - ddt_elem_id_description common; /**< basic data description and flags */ - uint32_t count; /**< number of blocks */ - size_t blocklen; /**< number of elements on each block */ - ptrdiff_t extent; /**< extent of each block (in bytes) */ - ptrdiff_t disp; /**< displacement of the first block */ + ddt_elem_id_description common; /**< basic data description and flags */ + uint32_t count; /**< number of blocks */ + size_t blocklen; /**< number of elements on each block */ + ptrdiff_t extent; /**< extent of each block (in bytes) */ + ptrdiff_t disp; /**< displacement of the first block */ }; typedef struct ddt_elem_desc ddt_elem_desc_t; @@ -173,73 +137,73 @@ typedef struct ddt_elem_desc ddt_elem_desc_t; * the first element. */ struct ddt_loop_desc { - ddt_elem_id_description common; /**< basic data description and flags */ - uint32_t items; /**< number of items in the loop */ - uint32_t loops; /**< number of elements */ - size_t unused; /**< not used right now */ - ptrdiff_t extent; /**< extent of the whole loop */ + ddt_elem_id_description common; /**< basic data description and flags */ + uint32_t items; /**< number of items in the loop */ + uint32_t loops; /**< number of elements */ + size_t unused; /**< not used right now */ + ptrdiff_t extent; /**< extent of the whole loop */ }; typedef struct ddt_loop_desc ddt_loop_desc_t; struct ddt_endloop_desc { - ddt_elem_id_description common; /**< basic data description and flags */ - uint32_t items; /**< number of elements */ - uint32_t unused; /**< not used right now */ - size_t size; /**< real size of the data in the loop */ - ptrdiff_t first_elem_disp; /**< the displacement of the first block in the loop */ + ddt_elem_id_description common; /**< basic data description and flags */ + uint32_t items; /**< number of elements */ + uint32_t unused; /**< not used right now */ + size_t size; /**< real size of the data in the loop */ + ptrdiff_t first_elem_disp; /**< the displacement of the first block in the loop */ }; typedef struct ddt_endloop_desc ddt_endloop_desc_t; union dt_elem_desc { - ddt_elem_desc_t elem; - ddt_loop_desc_t loop; + ddt_elem_desc_t elem; + ddt_loop_desc_t loop; ddt_endloop_desc_t end_loop; }; -#define CREATE_LOOP_START( _place, _count, _items, _extent, _flags ) \ - do { \ - (_place)->loop.common.type = OPAL_DATATYPE_LOOP; \ - (_place)->loop.common.flags = (_flags) & ~OPAL_DATATYPE_FLAG_DATA; \ - (_place)->loop.loops = (_count); \ - (_place)->loop.items = (_items); \ - (_place)->loop.extent = (_extent); \ - (_place)->loop.unused = -1; \ - } while(0) - -#define CREATE_LOOP_END( _place, _items, _first_item_disp, _size, _flags ) \ +#define CREATE_LOOP_START(_place, _count, _items, _extent, _flags) \ + do { \ + (_place)->loop.common.type = OPAL_DATATYPE_LOOP; \ + (_place)->loop.common.flags = (_flags) & ~OPAL_DATATYPE_FLAG_DATA; \ + (_place)->loop.loops = (_count); \ + (_place)->loop.items = (_items); \ + (_place)->loop.extent = (_extent); \ + (_place)->loop.unused = -1; \ + } while (0) + +#define CREATE_LOOP_END(_place, _items, _first_item_disp, _size, _flags) \ do { \ (_place)->end_loop.common.type = OPAL_DATATYPE_END_LOOP; \ (_place)->end_loop.common.flags = (_flags) & ~OPAL_DATATYPE_FLAG_DATA; \ (_place)->end_loop.items = (_items); \ (_place)->end_loop.first_elem_disp = (_first_item_disp); \ - (_place)->end_loop.size = (_size); /* the size inside the loop */ \ + (_place)->end_loop.size = (_size); /* the size inside the loop */ \ (_place)->end_loop.unused = -1; \ - } while(0) - + } while (0) /** * Create an element entry in the description. If the element is contiguous * collapse everything into the blocklen. */ -#define CREATE_ELEM(_place, _type, _flags, _blocklen, _count, _disp, _extent) \ - do { \ - (_place)->elem.common.flags = (_flags) | OPAL_DATATYPE_FLAG_DATA; \ - (_place)->elem.common.type = (_type); \ - (_place)->elem.blocklen = (_blocklen); \ - (_place)->elem.count = (_count); \ - (_place)->elem.extent = (_extent); \ - (_place)->elem.disp = (_disp); \ - if( _extent == (ptrdiff_t)(_blocklen * opal_datatype_basicDatatypes[_type]->size) ) { \ - /* collapse it into a single large blocklen */ \ - (_place)->elem.blocklen *= _count; \ - (_place)->elem.extent *= _count; \ - (_place)->elem.count = 1; \ - } \ - } while(0) +#define CREATE_ELEM(_place, _type, _flags, _blocklen, _count, _disp, _extent) \ + do { \ + (_place)->elem.common.flags = (_flags) | OPAL_DATATYPE_FLAG_DATA; \ + (_place)->elem.common.type = (_type); \ + (_place)->elem.blocklen = (_blocklen); \ + (_place)->elem.count = (_count); \ + (_place)->elem.extent = (_extent); \ + (_place)->elem.disp = (_disp); \ + if (_extent == (ptrdiff_t) (_blocklen * opal_datatype_basicDatatypes[_type]->size)) { \ + /* collapse it into a single large blocklen */ \ + (_place)->elem.blocklen *= _count; \ + (_place)->elem.extent *= _count; \ + (_place)->elem.count = 1; \ + } \ + } while (0) /* * This array holds the descriptions desc.desc[2] of the predefined basic datatypes. */ -OPAL_DECLSPEC extern union dt_elem_desc opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_MAX_PREDEFINED]; +OPAL_DECLSPEC extern union dt_elem_desc + opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_MAX_PREDEFINED]; struct opal_datatype_t; /* Other fields starting after bdt_used (index of OPAL_DATATYPE_LOOP should be ONE) */ @@ -252,7 +216,11 @@ struct opal_datatype_t; */ #define OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE NULL -#define OPAL_DATATYPE_INIT_PTYPES_ARRAY(NAME) (size_t[OPAL_DATATYPE_MAX_PREDEFINED]){ [OPAL_DATATYPE_ ## NAME] = 1, [OPAL_DATATYPE_MAX_PREDEFINED-1] = 0 } +#define OPAL_DATATYPE_INIT_PTYPES_ARRAY(NAME) \ + (size_t[OPAL_DATATYPE_MAX_PREDEFINED]) \ + { \ + [OPAL_DATATYPE_##NAME] = 1, [OPAL_DATATYPE_MAX_PREDEFINED - 1] = 0 \ + } #define OPAL_DATATYPE_INIT_NAME(NAME) "OPAL_" #NAME @@ -261,345 +229,354 @@ struct opal_datatype_t; * into the array opal_datatype_predefined_type_desc, which is initialized at * runtime in opal_datatype_init(). Each basic type has two desc-elements.... */ -#define OPAL_DATATYPE_INIT_DESC_PREDEFINED(NAME) \ - { \ - .length = 1, .used = 1, \ - .desc = &(opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_ ## NAME]) \ +#define OPAL_DATATYPE_INIT_DESC_PREDEFINED(NAME) \ + { \ + .length = 1, .used = 1, \ + .desc = &(opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_##NAME]) \ } -#define OPAL_DATATYPE_INIT_DESC_NULL {.length = 0, .used = 0, .desc = NULL} - -#define OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED( NAME, FLAGS ) \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ - .flags = OPAL_DATATYPE_FLAG_UNAVAILABLE | OPAL_DATATYPE_FLAG_PREDEFINED | (FLAGS), \ - .id = OPAL_DATATYPE_ ## NAME, \ - .bdt_used = 0, \ - .size = 0, \ - .true_lb = 0, .true_ub = 0, .lb = 0, .ub = 0, \ - .align = 0, \ - .nbElems = 1, \ - .name = OPAL_DATATYPE_INIT_NAME(NAME), \ - .desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(UNAVAILABLE), \ - .opt_desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(UNAVAILABLE), \ - .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ +#define OPAL_DATATYPE_INIT_DESC_NULL \ + { \ + .length = 0, .used = 0, .desc = NULL \ } -#define OPAL_DATATYPE_INITIALIZER_UNAVAILABLE( FLAGS ) \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED( UNAVAILABLE, (FLAGS) ) - -#define OPAL_DATATYPE_INITIALIZER_EMPTY( FLAGS ) \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ - .flags = OPAL_DATATYPE_FLAG_PREDEFINED | (FLAGS), \ - .id = 0, \ - .bdt_used = 0, \ - .size = 0, \ - .true_lb = 0, .true_ub = 0, .lb = 0, .ub = 0, \ - .align = 0, \ - .nbElems = 1, \ - .name = OPAL_DATATYPE_INIT_NAME(EMPTY), \ - .desc = OPAL_DATATYPE_INIT_DESC_NULL, \ - .opt_desc = OPAL_DATATYPE_INIT_DESC_NULL, \ - .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ +#define OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED(NAME, FLAGS) \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ + .flags = OPAL_DATATYPE_FLAG_UNAVAILABLE | OPAL_DATATYPE_FLAG_PREDEFINED | (FLAGS), \ + .id = OPAL_DATATYPE_##NAME, .bdt_used = 0, .size = 0, .true_lb = 0, .true_ub = 0, .lb = 0, \ + .ub = 0, .align = 0, .nbElems = 1, .name = OPAL_DATATYPE_INIT_NAME(NAME), \ + .desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(UNAVAILABLE), \ + .opt_desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(UNAVAILABLE), \ + .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ } -#define OPAL_DATATYPE_INIT_BASIC_TYPE( TYPE, NAME, FLAGS ) \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ - .flags = OPAL_DATATYPE_FLAG_PREDEFINED | (FLAGS), \ - .id = TYPE, \ - .bdt_used = (((uint32_t)1)<<(TYPE)), \ - .size = 0, \ - .true_lb = 0, .true_ub = 0, .lb = 0, .ub = 0, \ - .align = 0, \ - .nbElems = 1, \ - .name = OPAL_DATATYPE_INIT_NAME(NAME), \ - .desc = OPAL_DATATYPE_INIT_DESC_NULL, \ - .opt_desc = OPAL_DATATYPE_INIT_DESC_NULL, \ - .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ +#define OPAL_DATATYPE_INITIALIZER_UNAVAILABLE(FLAGS) \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED(UNAVAILABLE, (FLAGS)) + +#define OPAL_DATATYPE_INITIALIZER_EMPTY(FLAGS) \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ + .flags = OPAL_DATATYPE_FLAG_PREDEFINED | (FLAGS), .id = 0, .bdt_used = 0, .size = 0, \ + .true_lb = 0, .true_ub = 0, .lb = 0, .ub = 0, .align = 0, .nbElems = 1, \ + .name = OPAL_DATATYPE_INIT_NAME(EMPTY), .desc = OPAL_DATATYPE_INIT_DESC_NULL, \ + .opt_desc = OPAL_DATATYPE_INIT_DESC_NULL, \ + .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ } -#define OPAL_DATATYPE_INIT_BASIC_DATATYPE( TYPE, ALIGN, NAME, FLAGS ) \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ - .flags = OPAL_DATATYPE_FLAG_BASIC | (FLAGS), \ - .id = OPAL_DATATYPE_ ## NAME, \ - .bdt_used = (((uint32_t)1)<<(OPAL_DATATYPE_ ## NAME)), \ - .size = sizeof(TYPE), \ - .true_lb = 0, .true_ub = sizeof(TYPE), .lb = 0, .ub = sizeof(TYPE), \ - .align = (ALIGN), \ - .nbElems = 1, \ - .name = OPAL_DATATYPE_INIT_NAME(NAME), \ - .desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(NAME), \ - .opt_desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(NAME), \ - .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ +#define OPAL_DATATYPE_INIT_BASIC_TYPE(TYPE, NAME, FLAGS) \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ + .flags = OPAL_DATATYPE_FLAG_PREDEFINED | (FLAGS), .id = TYPE, \ + .bdt_used = (((uint32_t) 1) << (TYPE)), .size = 0, .true_lb = 0, .true_ub = 0, .lb = 0, \ + .ub = 0, .align = 0, .nbElems = 1, .name = OPAL_DATATYPE_INIT_NAME(NAME), \ + .desc = OPAL_DATATYPE_INIT_DESC_NULL, .opt_desc = OPAL_DATATYPE_INIT_DESC_NULL, \ + .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ } -#define OPAL_DATATYPE_INITIALIZER_INT1(FLAGS) \ - OPAL_DATATYPE_HANDLE_INT1( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_INT2(FLAGS) \ - OPAL_DATATYPE_HANDLE_INT2( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_INT4(FLAGS) \ - OPAL_DATATYPE_HANDLE_INT4( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_INT8(FLAGS) \ - OPAL_DATATYPE_HANDLE_INT8( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_INT16(FLAGS) \ - OPAL_DATATYPE_HANDLE_INT16( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_UINT1(FLAGS) \ - OPAL_DATATYPE_HANDLE_UINT1( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_UINT2(FLAGS) \ - OPAL_DATATYPE_HANDLE_UINT2( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_UINT4(FLAGS) \ - OPAL_DATATYPE_HANDLE_UINT4( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_UINT8(FLAGS) \ - OPAL_DATATYPE_HANDLE_UINT8( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_UINT16(FLAGS) \ - OPAL_DATATYPE_HANDLE_UINT16( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_FLOAT2(FLAGS) \ - OPAL_DATATYPE_HANDLE_FLOAT2( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_FLOAT4(FLAGS) \ - OPAL_DATATYPE_HANDLE_FLOAT4( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_FLOAT8(FLAGS) \ - OPAL_DATATYPE_HANDLE_FLOAT8( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_FLOAT12(FLAGS) \ - OPAL_DATATYPE_HANDLE_FLOAT12( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_FLOAT16(FLAGS) \ - OPAL_DATATYPE_HANDLE_FLOAT16( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_SHORT_FLOAT_COMPLEX(FLAGS) \ - OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_FLOAT_COMPLEX(FLAGS) \ - OPAL_DATATYPE_HANDLE_FLOAT_COMPLEX( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_DOUBLE_COMPLEX(FLAGS) \ - OPAL_DATATYPE_HANDLE_DOUBLE_COMPLEX( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_LONG_DOUBLE_COMPLEX(FLAGS) \ - OPAL_DATATYPE_HANDLE_LONG_DOUBLE_COMPLEX( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_BOOL(FLAGS) \ - OPAL_DATATYPE_HANDLE_BOOL( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_WCHAR(FLAGS) \ - OPAL_DATATYPE_HANDLE_WCHAR( \ - OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ - OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) -#define OPAL_DATATYPE_INITIALIZER_LOOP(FLAGS) OPAL_DATATYPE_INIT_BASIC_TYPE( OPAL_DATATYPE_LOOP, LOOP_S, FLAGS ) -#define OPAL_DATATYPE_INITIALIZER_END_LOOP(FLAGS) OPAL_DATATYPE_INIT_BASIC_TYPE( OPAL_DATATYPE_END_LOOP, LOOP_E, FLAGS ) -#define OPAL_DATATYPE_INITIALIZER_LB(FLAGS) OPAL_DATATYPE_INIT_BASIC_TYPE( OPAL_DATATYPE_LB, LB, FLAGS ) -#define OPAL_DATATYPE_INITIALIZER_UB(FLAGS) OPAL_DATATYPE_INIT_BASIC_TYPE( OPAL_DATATYPE_UB, UB, FLAGS ) - - -#define OPAL_DATATYPE_HANDLE_INT1(AV, NOTAV, FLAGS) AV( int8_t, OPAL_ALIGNMENT_INT8, INT1, FLAGS ) -#define OPAL_DATATYPE_HANDLE_INT2(AV, NOTAV, FLAGS) AV( int16_t, OPAL_ALIGNMENT_INT16, INT2, FLAGS ) -#define OPAL_DATATYPE_HANDLE_INT4(AV, NOTAV, FLAGS) AV( int32_t, OPAL_ALIGNMENT_INT32, INT4, FLAGS ) -#define OPAL_DATATYPE_HANDLE_INT8(AV, NOTAV, FLAGS) AV( int64_t, OPAL_ALIGNMENT_INT64, INT8, FLAGS ) +#define OPAL_DATATYPE_INIT_BASIC_DATATYPE(TYPE, ALIGN, NAME, FLAGS) \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ + .flags = OPAL_DATATYPE_FLAG_BASIC | (FLAGS), .id = OPAL_DATATYPE_##NAME, \ + .bdt_used = (((uint32_t) 1) << (OPAL_DATATYPE_##NAME)), .size = sizeof(TYPE), \ + .true_lb = 0, .true_ub = sizeof(TYPE), .lb = 0, .ub = sizeof(TYPE), .align = (ALIGN), \ + .nbElems = 1, .name = OPAL_DATATYPE_INIT_NAME(NAME), \ + .desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(NAME), \ + .opt_desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(NAME), \ + .ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY_UNAVAILABLE \ + } + +#define OPAL_DATATYPE_INITIALIZER_INT1(FLAGS) \ + OPAL_DATATYPE_HANDLE_INT1(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_INT2(FLAGS) \ + OPAL_DATATYPE_HANDLE_INT2(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_INT4(FLAGS) \ + OPAL_DATATYPE_HANDLE_INT4(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_INT8(FLAGS) \ + OPAL_DATATYPE_HANDLE_INT8(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_INT16(FLAGS) \ + OPAL_DATATYPE_HANDLE_INT16(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_UINT1(FLAGS) \ + OPAL_DATATYPE_HANDLE_UINT1(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_UINT2(FLAGS) \ + OPAL_DATATYPE_HANDLE_UINT2(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_UINT4(FLAGS) \ + OPAL_DATATYPE_HANDLE_UINT4(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_UINT8(FLAGS) \ + OPAL_DATATYPE_HANDLE_UINT8(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_UINT16(FLAGS) \ + OPAL_DATATYPE_HANDLE_UINT16(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_FLOAT2(FLAGS) \ + OPAL_DATATYPE_HANDLE_FLOAT2(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_FLOAT4(FLAGS) \ + OPAL_DATATYPE_HANDLE_FLOAT4(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_FLOAT8(FLAGS) \ + OPAL_DATATYPE_HANDLE_FLOAT8(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_FLOAT12(FLAGS) \ + OPAL_DATATYPE_HANDLE_FLOAT12(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_FLOAT16(FLAGS) \ + OPAL_DATATYPE_HANDLE_FLOAT16(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_SHORT_FLOAT_COMPLEX(FLAGS) \ + OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_FLOAT_COMPLEX(FLAGS) \ + OPAL_DATATYPE_HANDLE_FLOAT_COMPLEX(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_DOUBLE_COMPLEX(FLAGS) \ + OPAL_DATATYPE_HANDLE_DOUBLE_COMPLEX(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_LONG_DOUBLE_COMPLEX(FLAGS) \ + OPAL_DATATYPE_HANDLE_LONG_DOUBLE_COMPLEX(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_BOOL(FLAGS) \ + OPAL_DATATYPE_HANDLE_BOOL(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_WCHAR(FLAGS) \ + OPAL_DATATYPE_HANDLE_WCHAR(OPAL_DATATYPE_INIT_BASIC_DATATYPE, \ + OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_LOOP(FLAGS) \ + OPAL_DATATYPE_INIT_BASIC_TYPE(OPAL_DATATYPE_LOOP, LOOP_S, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_END_LOOP(FLAGS) \ + OPAL_DATATYPE_INIT_BASIC_TYPE(OPAL_DATATYPE_END_LOOP, LOOP_E, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_LB(FLAGS) \ + OPAL_DATATYPE_INIT_BASIC_TYPE(OPAL_DATATYPE_LB, LB, FLAGS) +#define OPAL_DATATYPE_INITIALIZER_UB(FLAGS) \ + OPAL_DATATYPE_INIT_BASIC_TYPE(OPAL_DATATYPE_UB, UB, FLAGS) + +#define OPAL_DATATYPE_HANDLE_INT1(AV, NOTAV, FLAGS) AV(int8_t, OPAL_ALIGNMENT_INT8, INT1, FLAGS) +#define OPAL_DATATYPE_HANDLE_INT2(AV, NOTAV, FLAGS) AV(int16_t, OPAL_ALIGNMENT_INT16, INT2, FLAGS) +#define OPAL_DATATYPE_HANDLE_INT4(AV, NOTAV, FLAGS) AV(int32_t, OPAL_ALIGNMENT_INT32, INT4, FLAGS) +#define OPAL_DATATYPE_HANDLE_INT8(AV, NOTAV, FLAGS) AV(int64_t, OPAL_ALIGNMENT_INT64, INT8, FLAGS) #ifdef HAVE_INT128_T -#define OPAL_DATATYPE_HANDLE_INT16(AV, NOTAV, FLAGS) AV( int128_t, OPAL_ALIGNMENT_INT128, INT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_INT16(AV, NOTAV, FLAGS) \ + AV(int128_t, OPAL_ALIGNMENT_INT128, INT16, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_INT16(AV, NOTAV, FLAGS) NOTAV( INT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_INT16(AV, NOTAV, FLAGS) NOTAV(INT16, FLAGS) #endif -#define OPAL_DATATYPE_HANDLE_UINT1(AV, NOTAV, FLAGS) AV( uint8_t, OPAL_ALIGNMENT_INT8, UINT1, FLAGS ) -#define OPAL_DATATYPE_HANDLE_UINT2(AV, NOTAV, FLAGS) AV( uint16_t, OPAL_ALIGNMENT_INT16, UINT2, FLAGS ) -#define OPAL_DATATYPE_HANDLE_UINT4(AV, NOTAV, FLAGS) AV( uint32_t, OPAL_ALIGNMENT_INT32, UINT4, FLAGS ) -#define OPAL_DATATYPE_HANDLE_UINT8(AV, NOTAV, FLAGS) AV( uint64_t, OPAL_ALIGNMENT_INT64, UINT8, FLAGS ) +#define OPAL_DATATYPE_HANDLE_UINT1(AV, NOTAV, FLAGS) AV(uint8_t, OPAL_ALIGNMENT_INT8, UINT1, FLAGS) +#define OPAL_DATATYPE_HANDLE_UINT2(AV, NOTAV, FLAGS) \ + AV(uint16_t, OPAL_ALIGNMENT_INT16, UINT2, FLAGS) +#define OPAL_DATATYPE_HANDLE_UINT4(AV, NOTAV, FLAGS) \ + AV(uint32_t, OPAL_ALIGNMENT_INT32, UINT4, FLAGS) +#define OPAL_DATATYPE_HANDLE_UINT8(AV, NOTAV, FLAGS) \ + AV(uint64_t, OPAL_ALIGNMENT_INT64, UINT8, FLAGS) #ifdef HAVE_UINT128_T -#define OPAL_DATATYPE_HANDLE_UINT16(AV, NOTAV, FLAGS) AV( uint128_t, OPAL_ALIGNMENT_INT128, UINT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_UINT16(AV, NOTAV, FLAGS) \ + AV(uint128_t, OPAL_ALIGNMENT_INT128, UINT16, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_UINT16(AV, NOTAV, FLAGS) NOTAV( INT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_UINT16(AV, NOTAV, FLAGS) NOTAV(INT16, FLAGS) #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 2 -#define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) AV( short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT2, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) \ + AV(short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT2, FLAGS) #elif SIZEOF_FLOAT == 2 -#define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) AV( float, OPAL_ALIGNMENT_FLOAT, FLOAT2, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) \ + AV(float, OPAL_ALIGNMENT_FLOAT, FLOAT2, FLAGS) #elif SIZEOF_DOUBLE == 2 -#define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) AV( double, OPAL_ALIGNMENT_DOUBLE, FLOAT2, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) \ + AV(double, OPAL_ALIGNMENT_DOUBLE, FLOAT2, FLAGS) #elif SIZEOF_LONG_DOUBLE == 2 -#define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) AV( long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT2, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) \ + AV(long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT2, FLAGS) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 2 -#define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) AV( opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT2, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) \ + AV(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT2, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) NOTAV( FLOAT2, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT2(AV, NOTAV, FLAGS) NOTAV(FLOAT2, FLAGS) #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 4 -#define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) AV( short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT4, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) \ + AV(short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT4, FLAGS) #elif SIZEOF_FLOAT == 4 -#define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) AV( float, OPAL_ALIGNMENT_FLOAT, FLOAT4, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) \ + AV(float, OPAL_ALIGNMENT_FLOAT, FLOAT4, FLAGS) #elif SIZEOF_DOUBLE == 4 -#define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) AV( double, OPAL_ALIGNMENT_DOUBLE, FLOAT4, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) \ + AV(double, OPAL_ALIGNMENT_DOUBLE, FLOAT4, FLAGS) #elif SIZEOF_LONG_DOUBLE == 4 -#define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) AV( long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT4, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) \ + AV(long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT4, FLAGS) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 4 -#define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) AV( opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT4, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) \ + AV(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT4, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) NOTAV( FLOAT4, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT4(AV, NOTAV, FLAGS) NOTAV(FLOAT4, FLAGS) #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 8 -#define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) AV( short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT8, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) \ + AV(short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT8, FLAGS) #elif SIZEOF_FLOAT == 8 -#define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) AV( float, OPAL_ALIGNMENT_FLOAT, FLOAT8, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) \ + AV(float, OPAL_ALIGNMENT_FLOAT, FLOAT8, FLAGS) #elif SIZEOF_DOUBLE == 8 -#define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) AV( double, OPAL_ALIGNMENT_DOUBLE, FLOAT8, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) \ + AV(double, OPAL_ALIGNMENT_DOUBLE, FLOAT8, FLAGS) #elif SIZEOF_LONG_DOUBLE == 8 -#define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) AV( long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT8, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) \ + AV(long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT8, FLAGS) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 8 -#define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) AV( opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT8, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) \ + AV(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT8, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) NOTAV( FLOAT8, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT8(AV, NOTAV, FLAGS) NOTAV(FLOAT8, FLAGS) #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 12 -#define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) AV( short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT12, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) \ + AV(short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT12, FLAGS) #elif SIZEOF_FLOAT == 12 -#define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) AV( float, OPAL_ALIGNMENT_FLOAT, FLOAT12, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) \ + AV(float, OPAL_ALIGNMENT_FLOAT, FLOAT12, FLAGS) #elif SIZEOF_DOUBLE == 12 -#define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) AV( double, OPAL_ALIGNMENT_DOUBLE, FLOAT12, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) \ + AV(double, OPAL_ALIGNMENT_DOUBLE, FLOAT12, FLAGS) #elif SIZEOF_LONG_DOUBLE == 12 -#define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) AV( long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT12, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) \ + AV(long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT12, FLAGS) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 12 -#define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) AV( opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT12, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) \ + AV(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT12, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) NOTAV( FLOAT12, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT12(AV, NOTAV, FLAGS) NOTAV(FLOAT12, FLAGS) #endif #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 16 -#define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) AV( short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) \ + AV(short float, OPAL_ALIGNMENT_SHORT_FLOAT, FLOAT16, FLAGS) #elif SIZEOF_FLOAT == 16 -#define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) AV( float, OPAL_ALIGNMENT_FLOAT, FLOAT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) \ + AV(float, OPAL_ALIGNMENT_FLOAT, FLOAT16, FLAGS) #elif SIZEOF_DOUBLE == 16 -#define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) AV( double, OPAL_ALIGNMENT_DOUBLE, FLOAT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) \ + AV(double, OPAL_ALIGNMENT_DOUBLE, FLOAT16, FLAGS) #elif SIZEOF_LONG_DOUBLE == 16 -#define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) AV( long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) \ + AV(long double, OPAL_ALIGNMENT_LONG_DOUBLE, FLOAT16, FLAGS) #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 16 -#define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) AV( opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) \ + AV(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, FLOAT16, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) NOTAV( FLOAT16, FLAGS ) +# define OPAL_DATATYPE_HANDLE_FLOAT16(AV, NOTAV, FLAGS) NOTAV(FLOAT16, FLAGS) #endif #if defined(HAVE_SHORT_FLOAT__COMPLEX) -#define OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(AV, NOTAV, FLAGS) AV( short float _Complex, OPAL_ALIGNMENT_SHORT_FLOAT_COMPLEX, SHORT_FLOAT_COMPLEX, FLAGS ) +# define OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(AV, NOTAV, FLAGS) \ + AV(short float _Complex, OPAL_ALIGNMENT_SHORT_FLOAT_COMPLEX, SHORT_FLOAT_COMPLEX, FLAGS) #elif defined(HAVE_OPAL_SHORT_FLOAT_COMPLEX_T) -#define OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(AV, NOTAV, FLAGS) AV( opal_short_float_complex_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, SHORT_FLOAT_COMPLEX, FLAGS ) +# define OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(AV, NOTAV, FLAGS) \ + AV(opal_short_float_complex_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T, SHORT_FLOAT_COMPLEX, \ + FLAGS) #else -#define OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(AV, NOTAV, FLAGS) NOTAV( SHORT_FLOAT_COMPLEX, FLAGS) +# define OPAL_DATATYPE_HANDLE_SHORT_FLOAT_COMPLEX(AV, NOTAV, FLAGS) \ + NOTAV(SHORT_FLOAT_COMPLEX, FLAGS) #endif -#define OPAL_DATATYPE_HANDLE_FLOAT_COMPLEX(AV, NOTAV, FLAGS) AV( float _Complex, OPAL_ALIGNMENT_FLOAT_COMPLEX, FLOAT_COMPLEX, FLAGS ) +#define OPAL_DATATYPE_HANDLE_FLOAT_COMPLEX(AV, NOTAV, FLAGS) \ + AV(float _Complex, OPAL_ALIGNMENT_FLOAT_COMPLEX, FLOAT_COMPLEX, FLAGS) -#define OPAL_DATATYPE_HANDLE_DOUBLE_COMPLEX(AV, NOTAV, FLAGS) AV( double _Complex, OPAL_ALIGNMENT_DOUBLE_COMPLEX, DOUBLE_COMPLEX, FLAGS ) +#define OPAL_DATATYPE_HANDLE_DOUBLE_COMPLEX(AV, NOTAV, FLAGS) \ + AV(double _Complex, OPAL_ALIGNMENT_DOUBLE_COMPLEX, DOUBLE_COMPLEX, FLAGS) -#define OPAL_DATATYPE_HANDLE_LONG_DOUBLE_COMPLEX(AV, NOTAV, FLAGS) AV( long double _Complex, OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX, LONG_DOUBLE_COMPLEX, FLAGS ) +#define OPAL_DATATYPE_HANDLE_LONG_DOUBLE_COMPLEX(AV, NOTAV, FLAGS) \ + AV(long double _Complex, OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX, LONG_DOUBLE_COMPLEX, FLAGS) -#define OPAL_DATATYPE_HANDLE_BOOL(AV, NOTAV, FLAGS) AV( _Bool, OPAL_ALIGNMENT_BOOL, BOOL, FLAGS ) +#define OPAL_DATATYPE_HANDLE_BOOL(AV, NOTAV, FLAGS) AV(_Bool, OPAL_ALIGNMENT_BOOL, BOOL, FLAGS) #if OPAL_ALIGNMENT_WCHAR != 0 -#define OPAL_DATATYPE_HANDLE_WCHAR(AV, NOTAV, FLAGS) AV( wchar_t, OPAL_ALIGNMENT_WCHAR, WCHAR, FLAGS ) +# define OPAL_DATATYPE_HANDLE_WCHAR(AV, NOTAV, FLAGS) \ + AV(wchar_t, OPAL_ALIGNMENT_WCHAR, WCHAR, FLAGS) #else -#define OPAL_DATATYPE_HANDLE_WCHAR(AV, NOTAV, FLAGS) NOTAV( WCHAR, FLAGS ) +# define OPAL_DATATYPE_HANDLE_WCHAR(AV, NOTAV, FLAGS) NOTAV(WCHAR, FLAGS) #endif -#define BASIC_DDT_FROM_ELEM( ELEM ) (opal_datatype_basicDatatypes[(ELEM).elem.common.type]) +#define BASIC_DDT_FROM_ELEM(ELEM) (opal_datatype_basicDatatypes[(ELEM).elem.common.type]) -#define SAVE_STACK( PSTACK, INDEX, TYPE, COUNT, DISP) \ -do { \ - (PSTACK)->index = (INDEX); \ - (PSTACK)->type = (TYPE); \ - (PSTACK)->count = (COUNT); \ - (PSTACK)->disp = (DISP); \ -} while(0) +#define SAVE_STACK(PSTACK, INDEX, TYPE, COUNT, DISP) \ + do { \ + (PSTACK)->index = (INDEX); \ + (PSTACK)->type = (TYPE); \ + (PSTACK)->count = (COUNT); \ + (PSTACK)->disp = (DISP); \ + } while (0) -#define PUSH_STACK( PSTACK, STACK_POS, INDEX, TYPE, COUNT, DISP) \ -do { \ - dt_stack_t* pTempStack = (PSTACK) + 1; \ - SAVE_STACK( pTempStack, (INDEX), (TYPE), (COUNT), (DISP) ); \ - (STACK_POS)++; \ - (PSTACK) = pTempStack; \ -} while(0) +#define PUSH_STACK(PSTACK, STACK_POS, INDEX, TYPE, COUNT, DISP) \ + do { \ + dt_stack_t *pTempStack = (PSTACK) + 1; \ + SAVE_STACK(pTempStack, (INDEX), (TYPE), (COUNT), (DISP)); \ + (STACK_POS)++; \ + (PSTACK) = pTempStack; \ + } while (0) #if OPAL_ENABLE_DEBUG -#define OPAL_DATATYPE_SAFEGUARD_POINTER( ACTPTR, LENGTH, INITPTR, PDATA, COUNT ) \ - { \ - unsigned char *__lower_bound = (INITPTR), *__upper_bound; \ - assert( ((LENGTH) != 0) && ((COUNT) != 0) ); \ - __lower_bound += (PDATA)->true_lb; \ - __upper_bound = (INITPTR) + (PDATA)->true_ub + \ - ((PDATA)->ub - (PDATA)->lb) * ((COUNT) - 1); \ - if( ((ACTPTR) < __lower_bound) || ((ACTPTR) >= __upper_bound) ) { \ - opal_datatype_safeguard_pointer_debug_breakpoint( (ACTPTR), (LENGTH), (INITPTR), (PDATA), (COUNT) ); \ - opal_output( 0, "%s:%d\n\tPointer %p size %lu is outside [%p,%p] for\n\tbase ptr %p count %lu and data \n", \ - __FILE__, __LINE__, (void*)(ACTPTR), (unsigned long)(LENGTH), (void*)__lower_bound, (void*)__upper_bound, \ - (void*)(INITPTR), (unsigned long)(COUNT) ); \ - opal_datatype_dump( (PDATA) ); \ - } \ - } +# define OPAL_DATATYPE_SAFEGUARD_POINTER(ACTPTR, LENGTH, INITPTR, PDATA, COUNT) \ + { \ + unsigned char *__lower_bound = (INITPTR), *__upper_bound; \ + assert(((LENGTH) != 0) && ((COUNT) != 0)); \ + __lower_bound += (PDATA)->true_lb; \ + __upper_bound = (INITPTR) + (PDATA)->true_ub + \ + ((PDATA)->ub - (PDATA)->lb) * ((COUNT) -1); \ + if (((ACTPTR) < __lower_bound) || ((ACTPTR) >= __upper_bound)) { \ + opal_datatype_safeguard_pointer_debug_breakpoint((ACTPTR), (LENGTH), (INITPTR), \ + (PDATA), (COUNT)); \ + opal_output(0, \ + "%s:%d\n\tPointer %p size %lu is outside [%p,%p] for\n\tbase ptr %p " \ + "count %lu and data \n", \ + __FILE__, __LINE__, (void *) (ACTPTR), (unsigned long) (LENGTH), \ + (void *) __lower_bound, (void *) __upper_bound, (void *) (INITPTR), \ + (unsigned long) (COUNT)); \ + opal_datatype_dump((PDATA)); \ + } \ + } #else -#define OPAL_DATATYPE_SAFEGUARD_POINTER( ACTPTR, LENGTH, INITPTR, PDATA, COUNT ) -#endif /* OPAL_ENABLE_DEBUG */ +# define OPAL_DATATYPE_SAFEGUARD_POINTER(ACTPTR, LENGTH, INITPTR, PDATA, COUNT) +#endif /* OPAL_ENABLE_DEBUG */ -static inline int GET_FIRST_NON_LOOP( const union dt_elem_desc* _pElem ) +static inline int GET_FIRST_NON_LOOP(const union dt_elem_desc *_pElem) { int element_index = 0; /* We dont have to check for the end as we always put an END_LOOP * at the end of all datatype descriptions. */ - while( _pElem->elem.common.type == OPAL_DATATYPE_LOOP ) { - ++_pElem; element_index++; + while (_pElem->elem.common.type == OPAL_DATATYPE_LOOP) { + ++_pElem; + element_index++; } return element_index; } -#define UPDATE_INTERNAL_COUNTERS( DESCRIPTION, POSITION, ELEMENT, COUNTER ) \ - do { \ - (ELEMENT) = &((DESCRIPTION)[(POSITION)]); \ - if( OPAL_DATATYPE_LOOP == (ELEMENT)->elem.common.type ) \ - (COUNTER) = (ELEMENT)->loop.loops; \ - else \ - (COUNTER) = (ELEMENT)->elem.count * (ELEMENT)->elem.blocklen; \ +#define UPDATE_INTERNAL_COUNTERS(DESCRIPTION, POSITION, ELEMENT, COUNTER) \ + do { \ + (ELEMENT) = &((DESCRIPTION)[(POSITION)]); \ + if (OPAL_DATATYPE_LOOP == (ELEMENT)->elem.common.type) \ + (COUNTER) = (ELEMENT)->loop.loops; \ + else \ + (COUNTER) = (ELEMENT)->elem.count * (ELEMENT)->elem.blocklen; \ } while (0) -OPAL_DECLSPEC int opal_datatype_contain_basic_datatypes( const struct opal_datatype_t* pData, char* ptr, size_t length ); -OPAL_DECLSPEC int opal_datatype_dump_data_flags( unsigned short usflags, char* ptr, size_t length ); -OPAL_DECLSPEC int opal_datatype_dump_data_desc( union dt_elem_desc* pDesc, int nbElems, char* ptr, size_t length ); +OPAL_DECLSPEC int opal_datatype_contain_basic_datatypes(const struct opal_datatype_t *pData, + char *ptr, size_t length); +OPAL_DECLSPEC int opal_datatype_dump_data_flags(unsigned short usflags, char *ptr, size_t length); +OPAL_DECLSPEC int opal_datatype_dump_data_desc(union dt_elem_desc *pDesc, int nbElems, char *ptr, + size_t length); extern bool opal_ddt_position_debug; extern bool opal_ddt_copy_debug; @@ -608,4 +585,4 @@ extern bool opal_ddt_pack_debug; extern bool opal_ddt_raw_debug; END_C_DECLS -#endif /* OPAL_DATATYPE_INTERNAL_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_DATATYPE_INTERNAL_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_datatype_memcpy.h b/opal/datatype/opal_datatype_memcpy.h index 972009ac96a..daa6b474bba 100644 --- a/opal/datatype/opal_datatype_memcpy.h +++ b/opal/datatype/opal_datatype_memcpy.h @@ -14,7 +14,6 @@ #ifndef OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED #define OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED -#define MEMCPY( DST, SRC, BLENGTH ) \ - memcpy( (DST), (SRC), (BLENGTH) ) +#define MEMCPY(DST, SRC, BLENGTH) memcpy((DST), (SRC), (BLENGTH)) -#endif /* OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_datatype_module.c b/opal/datatype/opal_datatype_module.c index 1ce57e67b50..d8bc8f9d47c 100644 --- a/opal/datatype/opal_datatype_module.c +++ b/opal/datatype/opal_datatype_module.c @@ -31,13 +31,13 @@ #include +#include "opal/datatype/opal_convertor_internal.h" +#include "opal/datatype/opal_datatype.h" +#include "opal/datatype/opal_datatype_internal.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/runtime/opal.h" #include "opal/util/arch.h" #include "opal/util/output.h" -#include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_datatype.h" -#include "opal/datatype/opal_convertor_internal.h" -#include "opal/mca/base/mca_base_var.h" /* by default the debuging is turned off */ int opal_datatype_dfd = -1; @@ -46,7 +46,7 @@ bool opal_ddt_pack_debug = false; bool opal_ddt_position_debug = false; bool opal_ddt_copy_debug = false; bool opal_ddt_raw_debug = false; -int opal_ddt_verbose = -1; /* Has the datatype verbose it's own output stream */ +int opal_ddt_verbose = -1; /* Has the datatype verbose it's own output stream */ extern int opal_cuda_verbose; @@ -56,58 +56,64 @@ extern int opal_cuda_verbose; * into an array, which is initialized at runtime. * Everything is constant. */ -OPAL_DECLSPEC const opal_datatype_t opal_datatype_empty = OPAL_DATATYPE_INITIALIZER_EMPTY(OPAL_DATATYPE_FLAG_CONTIGUOUS); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_empty = OPAL_DATATYPE_INITIALIZER_EMPTY( + OPAL_DATATYPE_FLAG_CONTIGUOUS); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_loop = OPAL_DATATYPE_INITIALIZER_LOOP(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_end_loop = OPAL_DATATYPE_INITIALIZER_END_LOOP(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_lb = OPAL_DATATYPE_INITIALIZER_LB(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_ub = OPAL_DATATYPE_INITIALIZER_UB(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_int1 = OPAL_DATATYPE_INITIALIZER_INT1(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_int2 = OPAL_DATATYPE_INITIALIZER_INT2(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_int4 = OPAL_DATATYPE_INITIALIZER_INT4(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_int8 = OPAL_DATATYPE_INITIALIZER_INT8(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_int16 = OPAL_DATATYPE_INITIALIZER_INT16(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint1 = OPAL_DATATYPE_INITIALIZER_UINT1(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint2 = OPAL_DATATYPE_INITIALIZER_UINT2(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint4 = OPAL_DATATYPE_INITIALIZER_UINT4(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint8 = OPAL_DATATYPE_INITIALIZER_UINT8(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint16 = OPAL_DATATYPE_INITIALIZER_UINT16(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_float2 = OPAL_DATATYPE_INITIALIZER_FLOAT2(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_float4 = OPAL_DATATYPE_INITIALIZER_FLOAT4(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_float8 = OPAL_DATATYPE_INITIALIZER_FLOAT8(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_float12 = OPAL_DATATYPE_INITIALIZER_FLOAT12(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_float16 = OPAL_DATATYPE_INITIALIZER_FLOAT16(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_short_float_complex = OPAL_DATATYPE_INITIALIZER_SHORT_FLOAT_COMPLEX(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_float_complex = OPAL_DATATYPE_INITIALIZER_FLOAT_COMPLEX(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_double_complex = OPAL_DATATYPE_INITIALIZER_DOUBLE_COMPLEX(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_long_double_complex = OPAL_DATATYPE_INITIALIZER_LONG_DOUBLE_COMPLEX(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_bool = OPAL_DATATYPE_INITIALIZER_BOOL(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_wchar = OPAL_DATATYPE_INITIALIZER_WCHAR(0); -OPAL_DECLSPEC const opal_datatype_t opal_datatype_unavailable = OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED(UNAVAILABLE, 0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_loop = OPAL_DATATYPE_INITIALIZER_LOOP(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_end_loop = OPAL_DATATYPE_INITIALIZER_END_LOOP(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_lb = OPAL_DATATYPE_INITIALIZER_LB(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_ub = OPAL_DATATYPE_INITIALIZER_UB(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_int1 = OPAL_DATATYPE_INITIALIZER_INT1(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_int2 = OPAL_DATATYPE_INITIALIZER_INT2(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_int4 = OPAL_DATATYPE_INITIALIZER_INT4(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_int8 = OPAL_DATATYPE_INITIALIZER_INT8(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_int16 = OPAL_DATATYPE_INITIALIZER_INT16(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint1 = OPAL_DATATYPE_INITIALIZER_UINT1(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint2 = OPAL_DATATYPE_INITIALIZER_UINT2(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint4 = OPAL_DATATYPE_INITIALIZER_UINT4(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint8 = OPAL_DATATYPE_INITIALIZER_UINT8(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint16 = OPAL_DATATYPE_INITIALIZER_UINT16(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_float2 = OPAL_DATATYPE_INITIALIZER_FLOAT2(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_float4 = OPAL_DATATYPE_INITIALIZER_FLOAT4(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_float8 = OPAL_DATATYPE_INITIALIZER_FLOAT8(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_float12 = OPAL_DATATYPE_INITIALIZER_FLOAT12(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_float16 = OPAL_DATATYPE_INITIALIZER_FLOAT16(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_short_float_complex + = OPAL_DATATYPE_INITIALIZER_SHORT_FLOAT_COMPLEX(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_float_complex + = OPAL_DATATYPE_INITIALIZER_FLOAT_COMPLEX(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_double_complex + = OPAL_DATATYPE_INITIALIZER_DOUBLE_COMPLEX(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_long_double_complex + = OPAL_DATATYPE_INITIALIZER_LONG_DOUBLE_COMPLEX(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_bool = OPAL_DATATYPE_INITIALIZER_BOOL(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_wchar = OPAL_DATATYPE_INITIALIZER_WCHAR(0); +OPAL_DECLSPEC const opal_datatype_t opal_datatype_unavailable + = OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED(UNAVAILABLE, 0); -OPAL_DECLSPEC dt_elem_desc_t opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_MAX_PREDEFINED] = {{{{0}}}}; +OPAL_DECLSPEC dt_elem_desc_t opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_MAX_PREDEFINED] + = {{{{0}}}}; /* * NOTE: The order of this array *MUST* match the order in opal_datatype_basicDatatypes * (use of designated initializers should relax this restrictions some) */ -OPAL_DECLSPEC const size_t opal_datatype_local_sizes[OPAL_DATATYPE_MAX_PREDEFINED] = -{ +OPAL_DECLSPEC const size_t opal_datatype_local_sizes[OPAL_DATATYPE_MAX_PREDEFINED] = { [OPAL_DATATYPE_INT1] = sizeof(int8_t), [OPAL_DATATYPE_INT2] = sizeof(int16_t), [OPAL_DATATYPE_INT4] = sizeof(int32_t), [OPAL_DATATYPE_INT8] = sizeof(int64_t), - [OPAL_DATATYPE_INT16] = 16, /* sizeof (int128_t) */ + [OPAL_DATATYPE_INT16] = 16, /* sizeof (int128_t) */ [OPAL_DATATYPE_UINT1] = sizeof(uint8_t), [OPAL_DATATYPE_UINT2] = sizeof(uint16_t), [OPAL_DATATYPE_UINT4] = sizeof(uint32_t), [OPAL_DATATYPE_UINT8] = sizeof(uint64_t), - [OPAL_DATATYPE_UINT16] = 16, /* sizeof (uint128_t) */ - [OPAL_DATATYPE_FLOAT2] = 2, /* sizeof (float2) */ - [OPAL_DATATYPE_FLOAT4] = 4, /* sizeof (float4) */ - [OPAL_DATATYPE_FLOAT8] = 8, /* sizeof (float8) */ - [OPAL_DATATYPE_FLOAT12] = 12, /* sizeof (float12) */ - [OPAL_DATATYPE_FLOAT16] = 16, /* sizeof (float16) */ + [OPAL_DATATYPE_UINT16] = 16, /* sizeof (uint128_t) */ + [OPAL_DATATYPE_FLOAT2] = 2, /* sizeof (float2) */ + [OPAL_DATATYPE_FLOAT4] = 4, /* sizeof (float4) */ + [OPAL_DATATYPE_FLOAT8] = 8, /* sizeof (float8) */ + [OPAL_DATATYPE_FLOAT12] = 12, /* sizeof (float12) */ + [OPAL_DATATYPE_FLOAT16] = 16, /* sizeof (float16) */ #if defined(HAVE_SHORT_FLOAT__COMPLEX) [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = sizeof(short float _Complex), #elif defined(HAVE_OPAL_SHORT_FLOAT_COMPLEX_T) @@ -118,15 +124,15 @@ OPAL_DECLSPEC const size_t opal_datatype_local_sizes[OPAL_DATATYPE_MAX_PREDEFINE [OPAL_DATATYPE_FLOAT_COMPLEX] = sizeof(float _Complex), [OPAL_DATATYPE_DOUBLE_COMPLEX] = sizeof(double _Complex), [OPAL_DATATYPE_LONG_DOUBLE_COMPLEX] = sizeof(long double _Complex), - [OPAL_DATATYPE_BOOL] = sizeof (_Bool), - [OPAL_DATATYPE_WCHAR] = sizeof (wchar_t), + [OPAL_DATATYPE_BOOL] = sizeof(_Bool), + [OPAL_DATATYPE_WCHAR] = sizeof(wchar_t), }; /* * NOTE: The order of this array *MUST* match what is listed in datatype.h * (use of designated initializers should relax this restrictions some) */ -OPAL_DECLSPEC const opal_datatype_t* opal_datatype_basicDatatypes[OPAL_DATATYPE_MAX_PREDEFINED] = { +OPAL_DECLSPEC const opal_datatype_t *opal_datatype_basicDatatypes[OPAL_DATATYPE_MAX_PREDEFINED] = { [OPAL_DATATYPE_LOOP] = &opal_datatype_loop, [OPAL_DATATYPE_END_LOOP] = &opal_datatype_end_loop, [OPAL_DATATYPE_LB] = &opal_datatype_lb, @@ -135,12 +141,14 @@ OPAL_DECLSPEC const opal_datatype_t* opal_datatype_basicDatatypes[OPAL_DATATYPE_ [OPAL_DATATYPE_INT2] = &opal_datatype_int2, [OPAL_DATATYPE_INT4] = &opal_datatype_int4, [OPAL_DATATYPE_INT8] = &opal_datatype_int8, - [OPAL_DATATYPE_INT16] = &opal_datatype_int16, /* Yes, double-machine word integers are available */ + [OPAL_DATATYPE_INT16] = &opal_datatype_int16, /* Yes, double-machine word integers are available + */ [OPAL_DATATYPE_UINT1] = &opal_datatype_uint1, [OPAL_DATATYPE_UINT2] = &opal_datatype_uint2, [OPAL_DATATYPE_UINT4] = &opal_datatype_uint4, [OPAL_DATATYPE_UINT8] = &opal_datatype_uint8, - [OPAL_DATATYPE_UINT16] = &opal_datatype_uint16, /* Yes, double-machine word integers are available */ + [OPAL_DATATYPE_UINT16] = &opal_datatype_uint16, /* Yes, double-machine word integers are + available */ [OPAL_DATATYPE_FLOAT2] = &opal_datatype_float2, [OPAL_DATATYPE_FLOAT4] = &opal_datatype_float4, [OPAL_DATATYPE_FLOAT8] = &opal_datatype_float8, @@ -155,78 +163,80 @@ OPAL_DECLSPEC const opal_datatype_t* opal_datatype_basicDatatypes[OPAL_DATATYPE_ [OPAL_DATATYPE_UNAVAILABLE] = &opal_datatype_unavailable, }; - int opal_datatype_register_params(void) { #if OPAL_ENABLE_DEBUG int ret; - ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_unpack_debug", - "Whether to output debugging information in the ddt unpack functions (nonzero = enabled)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_unpack_debug); + ret = mca_base_var_register( + "opal", "mpi", NULL, "ddt_unpack_debug", + "Whether to output debugging information in the ddt unpack functions (nonzero = enabled)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_unpack_debug); if (0 > ret) { return ret; } - ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_pack_debug", - "Whether to output debugging information in the ddt pack functions (nonzero = enabled)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_pack_debug); + ret = mca_base_var_register( + "opal", "mpi", NULL, "ddt_pack_debug", + "Whether to output debugging information in the ddt pack functions (nonzero = enabled)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_pack_debug); if (0 > ret) { return ret; } - ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_raw_debug", - "Whether to output debugging information in the ddt raw functions (nonzero = enabled)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_raw_debug); + ret = mca_base_var_register( + "opal", "mpi", NULL, "ddt_raw_debug", + "Whether to output debugging information in the ddt raw functions (nonzero = enabled)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_raw_debug); if (0 > ret) { return ret; } - ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_position_debug", - "Non zero lead to output generated by the datatype position functions", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_position_debug); + ret = mca_base_var_register( + "opal", "mpi", NULL, "ddt_position_debug", + "Non zero lead to output generated by the datatype position functions", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_position_debug); if (0 > ret) { return ret; } - ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_copy_debug", - "Whether to output debugging information in the ddt copy functions (nonzero = enabled)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_copy_debug); + ret = mca_base_var_register( + "opal", "mpi", NULL, "ddt_copy_debug", + "Whether to output debugging information in the ddt copy functions (nonzero = enabled)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_copy_debug); if (0 > ret) { return ret; } - ret = mca_base_var_register ("opal", "opal", NULL, "ddt_verbose", - "Set level of opal datatype verbosity", - MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_ddt_verbose); + ret = mca_base_var_register("opal", "opal", NULL, "ddt_verbose", + "Set level of opal datatype verbosity", MCA_BASE_VAR_TYPE_INT, NULL, + 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_8, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_ddt_verbose); if (0 > ret) { return ret; } -#if OPAL_CUDA_SUPPORT +# if OPAL_CUDA_SUPPORT /* Set different levels of verbosity in the cuda related code. */ - ret = mca_base_var_register ("opal", "opal", NULL, "cuda_verbose", - "Set level of opal cuda verbosity", - MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_cuda_verbose); + ret = mca_base_var_register("opal", "opal", NULL, "cuda_verbose", + "Set level of opal cuda verbosity", MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_8, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_cuda_verbose); if (0 > ret) { return ret; } -#endif +# endif #endif /* OPAL_ENABLE_DEBUG */ return OPAL_SUCCESS; } -static void opal_datatype_finalize (void) +static void opal_datatype_finalize(void) { /* As the synonyms are just copies of the internal data we should not free them. * Anyway they are over the limit of OPAL_DATATYPE_MAX_PREDEFINED so they will never get freed. @@ -238,13 +248,13 @@ static void opal_datatype_finalize (void) /* clear all master convertors */ opal_convertor_destroy_masters(); - opal_output_close (opal_datatype_dfd); + opal_output_close(opal_datatype_dfd); opal_datatype_dfd = -1; } -int32_t opal_datatype_init( void ) +int32_t opal_datatype_init(void) { - const opal_datatype_t* datatype; + const opal_datatype_t *datatype; int32_t i; /** @@ -252,34 +262,34 @@ int32_t opal_datatype_init( void ) * call OBJ_DESTRUCT without going too deep in the initialization process. */ opal_class_initialize(OBJ_CLASS(opal_datatype_t)); - for( i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) { + for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) { datatype = opal_datatype_basicDatatypes[i]; /* All of the predefined OPAL types don't have any GAPS! */ - datatype->desc.desc[0].elem.common.flags = OPAL_DATATYPE_FLAG_PREDEFINED | - OPAL_DATATYPE_FLAG_DATA | - OPAL_DATATYPE_FLAG_CONTIGUOUS | - OPAL_DATATYPE_FLAG_NO_GAPS; - datatype->desc.desc[0].elem.common.type = i; - datatype->desc.desc[0].elem.count = 1; - datatype->desc.desc[0].elem.blocklen = 1; - datatype->desc.desc[0].elem.disp = 0; - datatype->desc.desc[0].elem.extent = datatype->size; + datatype->desc.desc[0].elem.common.flags = OPAL_DATATYPE_FLAG_PREDEFINED + | OPAL_DATATYPE_FLAG_DATA + | OPAL_DATATYPE_FLAG_CONTIGUOUS + | OPAL_DATATYPE_FLAG_NO_GAPS; + datatype->desc.desc[0].elem.common.type = i; + datatype->desc.desc[0].elem.count = 1; + datatype->desc.desc[0].elem.blocklen = 1; + datatype->desc.desc[0].elem.disp = 0; + datatype->desc.desc[0].elem.extent = datatype->size; - datatype->desc.desc[1].end_loop.common.flags = 0; - datatype->desc.desc[1].end_loop.common.type = OPAL_DATATYPE_END_LOOP; - datatype->desc.desc[1].end_loop.items = 1; + datatype->desc.desc[1].end_loop.common.flags = 0; + datatype->desc.desc[1].end_loop.common.type = OPAL_DATATYPE_END_LOOP; + datatype->desc.desc[1].end_loop.items = 1; datatype->desc.desc[1].end_loop.first_elem_disp = datatype->desc.desc[0].elem.disp; - datatype->desc.desc[1].end_loop.size = datatype->size; + datatype->desc.desc[1].end_loop.size = datatype->size; } /* Enable a private output stream for datatype */ - if( opal_ddt_verbose > 0 ) { + if (opal_ddt_verbose > 0) { opal_datatype_dfd = opal_output_open(NULL); opal_output_set_verbosity(opal_datatype_dfd, opal_ddt_verbose); } - opal_finalize_register_cleanup (opal_datatype_finalize); + opal_finalize_register_cleanup(opal_datatype_finalize); return OPAL_SUCCESS; } @@ -289,11 +299,10 @@ int32_t opal_datatype_init( void ) * Set a breakpoint to this function in your favorite debugger * to make it stop on all pack and unpack errors. */ -int opal_datatype_safeguard_pointer_debug_breakpoint( const void* actual_ptr, int length, - const void* initial_ptr, - const opal_datatype_t* pData, - int count ) +int opal_datatype_safeguard_pointer_debug_breakpoint(const void *actual_ptr, int length, + const void *initial_ptr, + const opal_datatype_t *pData, int count) { return 0; } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ diff --git a/opal/datatype/opal_datatype_monotonic.c b/opal/datatype/opal_datatype_monotonic.c index 247fd66142d..67498332ca2 100644 --- a/opal/datatype/opal_datatype_monotonic.c +++ b/opal/datatype/opal_datatype_monotonic.c @@ -17,9 +17,9 @@ #include #include "opal/constants.h" +#include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_convertor.h" #define OPAL_DATATYPE_MAX_MONOTONIC_IOVEC 32 @@ -28,41 +28,42 @@ * the contiguous pieces are always advancing in the same direction, i.e. * there is no potential for overlap. */ -int32_t opal_datatype_is_monotonic(opal_datatype_t* type ) +int32_t opal_datatype_is_monotonic(opal_datatype_t *type) { struct iovec iov[OPAL_DATATYPE_MAX_MONOTONIC_IOVEC]; - ptrdiff_t upper_limit = (ptrdiff_t)type->true_lb; /* as conversion base will be NULL the first address is true_lb */ + ptrdiff_t upper_limit = (ptrdiff_t) type->true_lb; /* as conversion base will be NULL the first + address is true_lb */ size_t max_data = 0x7FFFFFFF; opal_convertor_t *pConv; bool monotonic = true; uint32_t iov_count; int rc; - pConv = opal_convertor_create( opal_local_arch, 0 ); + pConv = opal_convertor_create(opal_local_arch, 0); if (OPAL_UNLIKELY(NULL == pConv)) { return -1; } - rc = opal_convertor_prepare_for_send( pConv, type, 1, NULL ); - if( OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { + rc = opal_convertor_prepare_for_send(pConv, type, 1, NULL); + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { OBJ_RELEASE(pConv); return -1; } do { iov_count = OPAL_DATATYPE_MAX_MONOTONIC_IOVEC; - rc = opal_convertor_raw( pConv, iov, &iov_count, &max_data); + rc = opal_convertor_raw(pConv, iov, &iov_count, &max_data); for (uint32_t i = 0; i < iov_count; i++) { - if ((ptrdiff_t)iov[i].iov_base < upper_limit) { + if ((ptrdiff_t) iov[i].iov_base < upper_limit) { monotonic = false; goto cleanup; } /* The new upper bound is at the end of the iovec */ - upper_limit = (ptrdiff_t)iov[i].iov_base + iov[i].iov_len; + upper_limit = (ptrdiff_t) iov[i].iov_base + iov[i].iov_len; } } while (rc != 1); - cleanup: - OBJ_RELEASE( pConv ); +cleanup: + OBJ_RELEASE(pConv); return monotonic; } diff --git a/opal/datatype/opal_datatype_optimize.c b/opal/datatype/opal_datatype_optimize.c index 2e661b95daa..de6c3eb6560 100644 --- a/opal/datatype/opal_datatype_optimize.c +++ b/opal/datatype/opal_datatype_optimize.c @@ -26,70 +26,74 @@ #include #include -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" +#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -static int32_t -opal_datatype_optimize_short( opal_datatype_t* pData, - size_t count, - dt_type_desc_t* pTypeDesc ) +static int32_t opal_datatype_optimize_short(opal_datatype_t *pData, size_t count, + dt_type_desc_t *pTypeDesc) { - dt_elem_desc_t* pElemDesc; + dt_elem_desc_t *pElemDesc; dt_stack_t *pOrigStack, *pStack; /* pointer to the position on the stack */ - int32_t pos_desc = 0; /* actual position in the description of the derived datatype */ + int32_t pos_desc = 0; /* actual position in the description of the derived datatype */ int32_t stack_pos = 0; int32_t nbElems = 0; ptrdiff_t total_disp = 0; ddt_elem_desc_t last = {.common.flags = 0xFFFF /* all on */, .count = 0, .disp = 0}, compress; - ddt_elem_desc_t* current; + ddt_elem_desc_t *current; - pOrigStack = pStack = (dt_stack_t*)malloc( sizeof(dt_stack_t) * (pData->loops+2) ); - SAVE_STACK( pStack, -1, 0, count, 0 ); + pOrigStack = pStack = (dt_stack_t *) malloc(sizeof(dt_stack_t) * (pData->loops + 2)); + SAVE_STACK(pStack, -1, 0, count, 0); - pTypeDesc->length = 2 * pData->desc.used + 1 /* for the fake OPAL_DATATYPE_END_LOOP at the end */; - pTypeDesc->desc = pElemDesc = (dt_elem_desc_t*)malloc( sizeof(dt_elem_desc_t) * pTypeDesc->length ); + pTypeDesc->length = 2 * pData->desc.used + + 1 /* for the fake OPAL_DATATYPE_END_LOOP at the end */; + pTypeDesc->desc = pElemDesc = (dt_elem_desc_t *) malloc(sizeof(dt_elem_desc_t) + * pTypeDesc->length); pTypeDesc->used = 0; - assert( OPAL_DATATYPE_END_LOOP == pData->desc.desc[pData->desc.used].elem.common.type ); + assert(OPAL_DATATYPE_END_LOOP == pData->desc.desc[pData->desc.used].elem.common.type); - while( stack_pos >= 0 ) { - if( OPAL_DATATYPE_END_LOOP == pData->desc.desc[pos_desc].elem.common.type ) { /* end of the current loop */ - ddt_endloop_desc_t* end_loop = &(pData->desc.desc[pos_desc].end_loop); - if( 0 != last.count ) { - CREATE_ELEM( pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, - last.blocklen, last.count, last.disp, last.extent ); - pElemDesc++; nbElems++; - last.count= 0; + while (stack_pos >= 0) { + if (OPAL_DATATYPE_END_LOOP + == pData->desc.desc[pos_desc].elem.common.type) { /* end of the current loop */ + ddt_endloop_desc_t *end_loop = &(pData->desc.desc[pos_desc].end_loop); + if (0 != last.count) { + CREATE_ELEM(pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, last.blocklen, + last.count, last.disp, last.extent); + pElemDesc++; + nbElems++; + last.count = 0; } - CREATE_LOOP_END( pElemDesc, nbElems - pStack->index + 1, /* # of elems in this loop */ - end_loop->first_elem_disp, end_loop->size, end_loop->common.flags ); - if( --stack_pos >= 0 ) { /* still something to do ? */ - ddt_loop_desc_t* pStartLoop = &(pTypeDesc->desc[pStack->index - 1].loop); + CREATE_LOOP_END(pElemDesc, nbElems - pStack->index + 1, /* # of elems in this loop */ + end_loop->first_elem_disp, end_loop->size, end_loop->common.flags); + if (--stack_pos >= 0) { /* still something to do ? */ + ddt_loop_desc_t *pStartLoop = &(pTypeDesc->desc[pStack->index - 1].loop); pStartLoop->items = pElemDesc->end_loop.items; - total_disp = pStack->disp; /* update the displacement position */ + total_disp = pStack->disp; /* update the displacement position */ } - pElemDesc++; nbElems++; - pStack--; /* go down one position on the stack */ + pElemDesc++; + nbElems++; + pStack--; /* go down one position on the stack */ pos_desc++; continue; } - if( OPAL_DATATYPE_LOOP == pData->desc.desc[pos_desc].elem.common.type ) { - ddt_loop_desc_t* loop = (ddt_loop_desc_t*)&(pData->desc.desc[pos_desc]); - int index = GET_FIRST_NON_LOOP( &(pData->desc.desc[pos_desc]) ); + if (OPAL_DATATYPE_LOOP == pData->desc.desc[pos_desc].elem.common.type) { + ddt_loop_desc_t *loop = (ddt_loop_desc_t *) &(pData->desc.desc[pos_desc]); + int index = GET_FIRST_NON_LOOP(&(pData->desc.desc[pos_desc])); - if( loop->common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { - ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)&(pData->desc.desc[pos_desc + loop->items]); + if (loop->common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + ddt_endloop_desc_t *end_loop = (ddt_endloop_desc_t *) &( + pData->desc.desc[pos_desc + loop->items]); assert(pData->desc.desc[pos_desc + index].elem.disp == end_loop->first_elem_disp); compress.common.flags = loop->common.flags; - compress.common.type = pData->desc.desc[pos_desc + index].elem.common.type; + compress.common.type = pData->desc.desc[pos_desc + index].elem.common.type; compress.blocklen = pData->desc.desc[pos_desc + index].elem.blocklen; - for( uint32_t i = index+1; i < loop->items; i++ ) { + for (uint32_t i = index + 1; i < loop->items; i++) { current = &pData->desc.desc[pos_desc + i].elem; - assert(1 == current->count); - if( (current->common.type == OPAL_DATATYPE_LOOP) || - compress.common.type != current->common.type ) { + assert(1 == current->count); + if ((current->common.type == OPAL_DATATYPE_LOOP) + || compress.common.type != current->common.type) { compress.common.type = OPAL_DATATYPE_UINT1; compress.blocklen = end_loop->size; break; @@ -99,11 +103,14 @@ opal_datatype_optimize_short( opal_datatype_t* pData, compress.count = loop->loops; compress.extent = loop->extent; compress.disp = end_loop->first_elem_disp; - if( compress.extent == (ptrdiff_t)(compress.blocklen * opal_datatype_basicDatatypes[compress.common.type]->size) ) { - /* The compressed element is contiguous: collapse it into a single large blocklen */ + if (compress.extent + == (ptrdiff_t)(compress.blocklen + * opal_datatype_basicDatatypes[compress.common.type]->size)) { + /* The compressed element is contiguous: collapse it into a single large + * blocklen */ compress.blocklen *= compress.count; - compress.extent *= compress.count; - compress.count = 1; + compress.extent *= compress.count; + compress.count = 1; } /** * The current loop has been compressed and can now be treated as if it @@ -121,23 +128,26 @@ opal_datatype_optimize_short( opal_datatype_t* pData, * in reducing the number of memcpy during pack/unpack. */ - if( 0 != last.count ) { /* Generate the pending element */ - CREATE_ELEM( pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, - last.blocklen, last.count, last.disp, last.extent ); - pElemDesc++; nbElems++; - last.count = 0; + if (0 != last.count) { /* Generate the pending element */ + CREATE_ELEM(pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, last.blocklen, + last.count, last.disp, last.extent); + pElemDesc++; + nbElems++; + last.count = 0; last.common.type = OPAL_DATATYPE_LOOP; } /* Can we unroll the loop? */ - if( (loop->items <= 3) && (loop->loops <= 2) ) { + if ((loop->items <= 3) && (loop->loops <= 2)) { ptrdiff_t elem_displ = 0; - for( uint32_t i = 0; i < loop->loops; i++ ) { - for( uint32_t j = 0; j < (loop->items - 1); j++ ) { + for (uint32_t i = 0; i < loop->loops; i++) { + for (uint32_t j = 0; j < (loop->items - 1); j++) { current = &pData->desc.desc[pos_desc + index + j].elem; - CREATE_ELEM( pElemDesc, current->common.type, current->common.flags, - current->blocklen, current->count, current->disp + elem_displ, current->extent ); - pElemDesc++; nbElems++; + CREATE_ELEM(pElemDesc, current->common.type, current->common.flags, + current->blocklen, current->count, current->disp + elem_displ, + current->extent); + pElemDesc++; + nbElems++; } elem_displ += loop->extent; } @@ -145,26 +155,31 @@ opal_datatype_optimize_short( opal_datatype_t* pData, goto complete_loop; } - CREATE_LOOP_START( pElemDesc, loop->loops, loop->items, loop->extent, loop->common.flags ); - pElemDesc++; nbElems++; - PUSH_STACK( pStack, stack_pos, nbElems, OPAL_DATATYPE_LOOP, loop->loops, total_disp ); + CREATE_LOOP_START(pElemDesc, loop->loops, loop->items, loop->extent, + loop->common.flags); + pElemDesc++; + nbElems++; + PUSH_STACK(pStack, stack_pos, nbElems, OPAL_DATATYPE_LOOP, loop->loops, total_disp); pos_desc++; - DDT_DUMP_STACK( pStack, stack_pos, pData->desc.desc, "advance loops" ); + DDT_DUMP_STACK(pStack, stack_pos, pData->desc.desc, "advance loops"); complete_loop: - total_disp = pStack->disp; /* update the displacement */ + total_disp = pStack->disp; /* update the displacement */ continue; } - while( pData->desc.desc[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { /* go over all basic datatype elements */ + while (pData->desc.desc[pos_desc].elem.common.flags + & OPAL_DATATYPE_FLAG_DATA) { /* go over all basic datatype elements */ current = &pData->desc.desc[pos_desc].elem; - pos_desc++; /* point to the next element as current points to the current one */ + pos_desc++; /* point to the next element as current points to the current one */ - fuse_loops: - if( 0 == last.count ) { /* first data of the datatype */ + fuse_loops: + if (0 == last.count) { /* first data of the datatype */ last = *current; - continue; /* next data */ - } else { /* can we merge it in order to decrease count */ - if( (ptrdiff_t)last.blocklen * (ptrdiff_t)opal_datatype_basicDatatypes[last.common.type]->size == last.extent ) { + continue; /* next data */ + } else { /* can we merge it in order to decrease count */ + if ((ptrdiff_t) last.blocklen + * (ptrdiff_t) opal_datatype_basicDatatypes[last.common.type]->size + == last.extent) { last.extent *= last.count; last.blocklen *= last.count; last.count = 1; @@ -174,33 +189,34 @@ opal_datatype_optimize_short( opal_datatype_t* pData, /* are the two elements compatible: aka they have very similar values and they * can be merged together by increasing the count, and/or changing the extent. */ - if( (last.blocklen * opal_datatype_basicDatatypes[last.common.type]->size) == - (current->blocklen * opal_datatype_basicDatatypes[current->common.type]->size) ) { - ddt_elem_desc_t save = last; /* safekeep the type and blocklen */ - if( last.common.type != current->common.type ) { - last.blocklen *= opal_datatype_basicDatatypes[last.common.type]->size; - last.common.type = OPAL_DATATYPE_UINT1; + if ((last.blocklen * opal_datatype_basicDatatypes[last.common.type]->size) + == (current->blocklen * opal_datatype_basicDatatypes[current->common.type]->size)) { + ddt_elem_desc_t save = last; /* safekeep the type and blocklen */ + if (last.common.type != current->common.type) { + last.blocklen *= opal_datatype_basicDatatypes[last.common.type]->size; + last.common.type = OPAL_DATATYPE_UINT1; } - if( (last.extent * (ptrdiff_t)last.count + last.disp) == current->disp ) { - if( 1 == current->count ) { + if ((last.extent * (ptrdiff_t) last.count + last.disp) == current->disp) { + if (1 == current->count) { last.count++; continue; } - if( last.extent == current->extent ) { + if (last.extent == current->extent) { last.count += current->count; continue; } } - if( 1 == last.count ) { - /* we can ignore the extent of the element with count == 1 and merge them together if their displacements match */ - if( 1 == current->count ) { + if (1 == last.count) { + /* we can ignore the extent of the element with count == 1 and merge them + * together if their displacements match */ + if (1 == current->count) { last.extent = current->disp - last.disp; last.count++; continue; } /* can we compute a matching displacement ? */ - if( (last.disp + current->extent) == current->disp ) { + if ((last.disp + current->extent) == current->disp) { last.extent = current->extent; last.count = current->count + last.count; continue; @@ -210,105 +226,115 @@ opal_datatype_optimize_short( opal_datatype_t* pData, last.common.type = save.common.type; /* try other optimizations */ } - /* are the elements fusionable such that we can fusion the last blocklen of one with the first - * blocklen of the other. + /* are the elements fusionable such that we can fusion the last blocklen of one with the + * first blocklen of the other. */ - if( (ptrdiff_t)(last.disp + (last.count - 1) * last.extent + last.blocklen * opal_datatype_basicDatatypes[last.common.type]->size) == - current->disp ) { - if( last.count != 1 ) { - CREATE_ELEM( pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, - last.blocklen, last.count - 1, last.disp, last.extent ); - pElemDesc++; nbElems++; + if ((ptrdiff_t)(last.disp + (last.count - 1) * last.extent + + last.blocklen * opal_datatype_basicDatatypes[last.common.type]->size) + == current->disp) { + if (last.count != 1) { + CREATE_ELEM(pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, + last.blocklen, last.count - 1, last.disp, last.extent); + pElemDesc++; + nbElems++; last.disp += (last.count - 1) * last.extent; last.count = 1; } - if( last.common.type == current->common.type ) { + if (last.common.type == current->common.type) { last.blocklen += current->blocklen; } else { - last.blocklen = ((last.blocklen * opal_datatype_basicDatatypes[last.common.type]->size) + - (current->blocklen * opal_datatype_basicDatatypes[current->common.type]->size)); + last.blocklen = ((last.blocklen + * opal_datatype_basicDatatypes[last.common.type]->size) + + (current->blocklen + * opal_datatype_basicDatatypes[current->common.type] + ->size)); last.common.type = OPAL_DATATYPE_UINT1; } last.extent += current->extent; - if( current->count != 1 ) { - CREATE_ELEM( pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, - last.blocklen, last.count, last.disp, last.extent ); - pElemDesc++; nbElems++; + if (current->count != 1) { + CREATE_ELEM(pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, + last.blocklen, last.count, last.disp, last.extent); + pElemDesc++; + nbElems++; last = *current; last.count -= 1; last.disp += last.extent; } continue; } - CREATE_ELEM( pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, - last.blocklen, last.count, last.disp, last.extent ); - pElemDesc++; nbElems++; + CREATE_ELEM(pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, last.blocklen, + last.count, last.disp, last.extent); + pElemDesc++; + nbElems++; last = *current; } } - if( 0 != last.count ) { - CREATE_ELEM( pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, - last.blocklen, last.count, last.disp, last.extent ); - pElemDesc++; nbElems++; + if (0 != last.count) { + CREATE_ELEM(pElemDesc, last.common.type, OPAL_DATATYPE_FLAG_BASIC, last.blocklen, + last.count, last.disp, last.extent); + pElemDesc++; + nbElems++; } /* cleanup the stack */ - pTypeDesc->used = nbElems - 1; /* except the last fake END_LOOP */ + pTypeDesc->used = nbElems - 1; /* except the last fake END_LOOP */ free(pOrigStack); return OPAL_SUCCESS; } -int32_t opal_datatype_commit( opal_datatype_t * pData ) +int32_t opal_datatype_commit(opal_datatype_t *pData) { - ddt_endloop_desc_t* pLast = &(pData->desc.desc[pData->desc.used].end_loop); + ddt_endloop_desc_t *pLast = &(pData->desc.desc[pData->desc.used].end_loop); ptrdiff_t first_elem_disp = 0; - if( pData->flags & OPAL_DATATYPE_FLAG_COMMITTED ) return OPAL_SUCCESS; + if (pData->flags & OPAL_DATATYPE_FLAG_COMMITTED) { + return OPAL_SUCCESS; + } pData->flags |= OPAL_DATATYPE_FLAG_COMMITTED; /* We have to compute the displacement of the first non loop item in the * description. */ - if( 0 != pData->size ) { + if (0 != pData->size) { int index; - dt_elem_desc_t* pElem = pData->desc.desc; + dt_elem_desc_t *pElem = pData->desc.desc; - index = GET_FIRST_NON_LOOP( pElem ); - assert( pElem[index].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ); + index = GET_FIRST_NON_LOOP(pElem); + assert(pElem[index].elem.common.flags & OPAL_DATATYPE_FLAG_DATA); first_elem_disp = pElem[index].elem.disp; } /* let's add a fake element at the end just to avoid useless comparaisons * in pack/unpack functions. */ - pLast->common.type = OPAL_DATATYPE_END_LOOP; - pLast->common.flags = 0; - pLast->items = pData->desc.used; + pLast->common.type = OPAL_DATATYPE_END_LOOP; + pLast->common.flags = 0; + pLast->items = pData->desc.used; pLast->first_elem_disp = first_elem_disp; - pLast->size = pData->size; + pLast->size = pData->size; /* If there is no datatype description how can we have an optimized description ? */ - if( 0 == pData->desc.used ) { + if (0 == pData->desc.used) { pData->opt_desc.length = 0; - pData->opt_desc.desc = NULL; - pData->opt_desc.used = 0; + pData->opt_desc.desc = NULL; + pData->opt_desc.used = 0; return OPAL_SUCCESS; } /* If the data is contiguous is useless to generate an optimized version. */ /*if( pData->size == (pData->true_ub - pData->true_lb) ) return OPAL_SUCCESS; */ - (void)opal_datatype_optimize_short( pData, 1, &(pData->opt_desc) ); - if( 0 != pData->opt_desc.used ) { + (void) opal_datatype_optimize_short(pData, 1, &(pData->opt_desc)); + if (0 != pData->opt_desc.used) { /* let's add a fake element at the end just to avoid useless comparaisons * in pack/unpack functions. */ pLast = &(pData->opt_desc.desc[pData->opt_desc.used].end_loop); - pLast->common.type = OPAL_DATATYPE_END_LOOP; - pLast->common.flags = 0; - pLast->items = pData->opt_desc.used; + pLast->common.type = OPAL_DATATYPE_END_LOOP; + pLast->common.flags = 0; + pLast->items = pData->opt_desc.used; pLast->first_elem_disp = first_elem_disp; - pLast->size = pData->size; + pLast->size = pData->size; } return OPAL_SUCCESS; } diff --git a/opal/datatype/opal_datatype_pack.c b/opal/datatype/opal_datatype_pack.c index b5225017a59..51bf0fecec4 100644 --- a/opal/datatype/opal_datatype_pack.c +++ b/opal/datatype/opal_datatype_pack.c @@ -29,40 +29,40 @@ #include "opal/datatype/opal_datatype_internal.h" #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" -#define DO_DEBUG(INST) if( opal_ddt_pack_debug ) { INST } +# define DO_DEBUG(INST) \ + if (opal_ddt_pack_debug) { \ + INST \ + } #else -#define DO_DEBUG(INST) -#endif /* OPAL_ENABLE_DEBUG */ +# define DO_DEBUG(INST) +#endif /* OPAL_ENABLE_DEBUG */ #include "opal/datatype/opal_datatype_checksum.h" #include "opal/datatype/opal_datatype_pack.h" #include "opal/datatype/opal_datatype_prototypes.h" #if defined(CHECKSUM) -#define opal_pack_homogeneous_contig_function opal_pack_homogeneous_contig_checksum -#define opal_pack_homogeneous_contig_with_gaps_function opal_pack_homogeneous_contig_with_gaps_checksum -#define opal_generic_simple_pack_function opal_generic_simple_pack_checksum -#define opal_pack_general_function opal_pack_general_checksum +# define opal_pack_homogeneous_contig_function opal_pack_homogeneous_contig_checksum +# define opal_pack_homogeneous_contig_with_gaps_function \ + opal_pack_homogeneous_contig_with_gaps_checksum +# define opal_generic_simple_pack_function opal_generic_simple_pack_checksum +# define opal_pack_general_function opal_pack_general_checksum #else -#define opal_pack_homogeneous_contig_function opal_pack_homogeneous_contig -#define opal_pack_homogeneous_contig_with_gaps_function opal_pack_homogeneous_contig_with_gaps -#define opal_generic_simple_pack_function opal_generic_simple_pack -#define opal_pack_general_function opal_pack_general -#endif /* defined(CHECKSUM) */ - +# define opal_pack_homogeneous_contig_function opal_pack_homogeneous_contig +# define opal_pack_homogeneous_contig_with_gaps_function opal_pack_homogeneous_contig_with_gaps +# define opal_generic_simple_pack_function opal_generic_simple_pack +# define opal_pack_general_function opal_pack_general +#endif /* defined(CHECKSUM) */ /* the contig versions does not use the stack. They can easily retrieve * the status with just the informations from pConvertor->bConverted. */ -int32_t -opal_pack_homogeneous_contig_function( opal_convertor_t* pConv, - struct iovec* iov, - uint32_t* out_size, - size_t* max_data ) +int32_t opal_pack_homogeneous_contig_function(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { - dt_stack_t* pStack = pConv->pStack; + dt_stack_t *pStack = pConv->pStack; unsigned char *source_base = NULL; uint32_t iov_count; size_t length = pConv->local_size - pConv->bConverted, initial_amount = pConv->bConverted; @@ -72,18 +72,21 @@ opal_pack_homogeneous_contig_function( opal_convertor_t* pConv, /* There are some optimizations that can be done if the upper level * does not provide a buffer. */ - for( iov_count = 0; iov_count < (*out_size); iov_count++ ) { - if( 0 == length ) break; - if( (size_t)iov[iov_count].iov_len > length ) + for (iov_count = 0; iov_count < (*out_size); iov_count++) { + if (0 == length) { + break; + } + if ((size_t) iov[iov_count].iov_len > length) { iov[iov_count].iov_len = length; - if( iov[iov_count].iov_base == NULL ) { + } + if (iov[iov_count].iov_base == NULL) { iov[iov_count].iov_base = (IOVBASE_TYPE *) source_base; - COMPUTE_CSUM( iov[iov_count].iov_base, iov[iov_count].iov_len, pConv ); + COMPUTE_CSUM(iov[iov_count].iov_base, iov[iov_count].iov_len, pConv); } else { /* contiguous data just memcpy the smallest data in the user buffer */ - OPAL_DATATYPE_SAFEGUARD_POINTER( source_base, iov[iov_count].iov_len, - pConv->pBaseBuf, pConv->pDesc, pConv->count ); - MEMCPY_CSUM( iov[iov_count].iov_base, source_base, iov[iov_count].iov_len, pConv ); + OPAL_DATATYPE_SAFEGUARD_POINTER(source_base, iov[iov_count].iov_len, pConv->pBaseBuf, + pConv->pDesc, pConv->count); + MEMCPY_CSUM(iov[iov_count].iov_base, source_base, iov[iov_count].iov_len, pConv); } length -= iov[iov_count].iov_len; pConv->bConverted += iov[iov_count].iov_len; @@ -94,131 +97,140 @@ opal_pack_homogeneous_contig_function( opal_convertor_t* pConv, /* update the return value */ *max_data = pConv->bConverted - initial_amount; *out_size = iov_count; - if( pConv->bConverted == pConv->local_size ) { + if (pConv->bConverted == pConv->local_size) { pConv->flags |= CONVERTOR_COMPLETED; return 1; } return 0; } - -int32_t -opal_pack_homogeneous_contig_with_gaps_function( opal_convertor_t* pConv, - struct iovec* iov, - uint32_t* out_size, - size_t* max_data ) +int32_t opal_pack_homogeneous_contig_with_gaps_function(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { size_t remaining, length, initial_bytes_converted = pConv->bConverted; - const opal_datatype_t* pData = pConv->pDesc; - dt_stack_t* stack = pConv->pStack; + const opal_datatype_t *pData = pConv->pDesc; + dt_stack_t *stack = pConv->pStack; ptrdiff_t extent = pData->ub - pData->lb; unsigned char *user_memory, *packed_buffer; uint32_t idx; size_t i; - /* The memory layout is contiguous with gaps in the begining and at the end. The datatype true_lb - * is the initial displacement, the size the length of the contiguous area and the extent represent - * how much we should jump between elements. + /* The memory layout is contiguous with gaps in the begining and at the end. The datatype + * true_lb is the initial displacement, the size the length of the contiguous area and the + * extent represent how much we should jump between elements. */ - assert( (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) && ((ptrdiff_t)pData->size != extent) ); - assert( pData->opt_desc.used <= 1 ); - DO_DEBUG( opal_output( 0, "pack_homogeneous_contig( pBaseBuf %p, iov_count %d )\n", - (void*)pConv->pBaseBuf, *out_size ); ); - if( stack[1].type != opal_datatype_uint1.id ) { + assert((pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) && ((ptrdiff_t) pData->size != extent)); + assert(pData->opt_desc.used <= 1); + DO_DEBUG(opal_output(0, "pack_homogeneous_contig( pBaseBuf %p, iov_count %d )\n", + (void *) pConv->pBaseBuf, *out_size);); + if (stack[1].type != opal_datatype_uint1.id) { stack[1].count *= opal_datatype_basicDatatypes[stack[1].type]->size; - stack[1].type = opal_datatype_uint1.id; + stack[1].type = opal_datatype_uint1.id; } /* We can provide directly the pointers in the user buffers (like the convertor_raw) */ - if( NULL == iov[0].iov_base ) { + if (NULL == iov[0].iov_base) { user_memory = pConv->pBaseBuf + pData->true_lb; - for( idx = 0; (idx < (*out_size)) && stack[0].count; idx++ ) { + for (idx = 0; (idx < (*out_size)) && stack[0].count; idx++) { iov[idx].iov_base = user_memory + stack[0].disp + stack[1].disp; - iov[idx].iov_len = stack[1].count; - COMPUTE_CSUM( iov[idx].iov_base, iov[idx].iov_len, pConv ); + iov[idx].iov_len = stack[1].count; + COMPUTE_CSUM(iov[idx].iov_base, iov[idx].iov_len, pConv); pConv->bConverted += stack[1].count; stack[0].disp += extent; stack[0].count--; - stack[1].disp = 0; - stack[1].count = pData->size; /* we might need this to update the partial - * length for the first iteration */ + stack[1].disp = 0; + stack[1].count = pData->size; /* we might need this to update the partial + * length for the first iteration */ } goto update_status_and_return; } - for( idx = 0; idx < (*out_size); idx++ ) { + for (idx = 0; idx < (*out_size); idx++) { /* Limit the amount of packed data to the data left over on this convertor */ remaining = pConv->local_size - pConv->bConverted; - if( 0 == remaining ) break; /* we're done this time */ - if( remaining > iov[idx].iov_len ) + if (0 == remaining) { + break; /* we're done this time */ + } + if (remaining > iov[idx].iov_len) { remaining = iov[idx].iov_len; - packed_buffer = (unsigned char *)iov[idx].iov_base; + } + packed_buffer = (unsigned char *) iov[idx].iov_base; pConv->bConverted += remaining; user_memory = pConv->pBaseBuf + pData->true_lb + stack[0].disp + stack[1].disp; - DO_DEBUG( opal_output( 0, "pack_homogeneous_contig( user_memory %p, packed_buffer %p length %" PRIsize_t "\n", - (void*)user_memory, (void*)packed_buffer, remaining ); ); + DO_DEBUG(opal_output( + 0, + "pack_homogeneous_contig( user_memory %p, packed_buffer %p length %" PRIsize_t + "\n", + (void *) user_memory, (void *) packed_buffer, remaining);); - length = (0 == pConv->stack_pos ? 0 : stack[1].count); /* left over from the last pack */ + length = (0 == pConv->stack_pos ? 0 : stack[1].count); /* left over from the last pack */ /* data left from last round and enough space in the buffer */ - if( (pData->size != length) && (length <= remaining)) { + if ((pData->size != length) && (length <= remaining)) { /* copy the partial left-over from the previous round */ - OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, length, pConv->pBaseBuf, - pData, pConv->count ); - DO_DEBUG( opal_output( 0, "pack dest %p src %p length %" PRIsize_t " [prologue]\n", - (void*)user_memory, (void*)packed_buffer, length ); ); - MEMCPY_CSUM( packed_buffer, user_memory, length, pConv ); - packed_buffer += length; - remaining -= length; + OPAL_DATATYPE_SAFEGUARD_POINTER(user_memory, length, pConv->pBaseBuf, pData, + pConv->count); + DO_DEBUG(opal_output(0, "pack dest %p src %p length %" PRIsize_t " [prologue]\n", + (void *) user_memory, (void *) packed_buffer, length);); + MEMCPY_CSUM(packed_buffer, user_memory, length, pConv); + packed_buffer += length; + remaining -= length; stack[1].count -= length; - stack[1].disp += length; /* just in case, we overwrite this below */ - if( 0 == stack[1].count) { /* one completed element */ + stack[1].disp += length; /* just in case, we overwrite this below */ + if (0 == stack[1].count) { /* one completed element */ stack[0].count--; stack[0].disp += extent; - if( 0 == stack[0].count ) /* not yet done */ + if (0 == stack[0].count) { /* not yet done */ break; + } stack[1].count = pData->size; stack[1].disp = 0; } user_memory = pConv->pBaseBuf + pData->true_lb + stack[0].disp + stack[1].disp; } - for( i = 0; pData->size <= remaining; i++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, pData->size, pConv->pBaseBuf, - pData, pConv->count ); - DO_DEBUG( opal_output( 0, "pack dest %p src %p length %" PRIsize_t " [%" PRIsize_t "/%" PRIsize_t "\n", - (void*)user_memory, (void*)packed_buffer, pData->size, remaining, iov[idx].iov_len ); ); - MEMCPY_CSUM( packed_buffer, user_memory, pData->size, pConv ); + for (i = 0; pData->size <= remaining; i++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(user_memory, pData->size, pConv->pBaseBuf, pData, + pConv->count); + DO_DEBUG(opal_output(0, + "pack dest %p src %p length %" PRIsize_t " [%" PRIsize_t + "/%" PRIsize_t "\n", + (void *) user_memory, (void *) packed_buffer, pData->size, + remaining, iov[idx].iov_len);); + MEMCPY_CSUM(packed_buffer, user_memory, pData->size, pConv); packed_buffer += pData->size; - user_memory += extent; - remaining -= pData->size; + user_memory += extent; + remaining -= pData->size; } - stack[0].count -= i; /* the entire datatype copied above */ - stack[0].disp += (i * extent); + stack[0].count -= i; /* the entire datatype copied above */ + stack[0].disp += (i * extent); /* Copy the last bits */ - if( 0 != remaining ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, remaining, pConv->pBaseBuf, - pData, pConv->count ); - DO_DEBUG( opal_output( 0, "4. pack dest %p src %p length %" PRIsize_t "\n", - (void*)user_memory, (void*)packed_buffer, remaining ); ); - MEMCPY_CSUM( packed_buffer, user_memory, remaining, pConv ); + if (0 != remaining) { + OPAL_DATATYPE_SAFEGUARD_POINTER(user_memory, remaining, pConv->pBaseBuf, pData, + pConv->count); + DO_DEBUG(opal_output(0, "4. pack dest %p src %p length %" PRIsize_t "\n", + (void *) user_memory, (void *) packed_buffer, remaining);); + MEMCPY_CSUM(packed_buffer, user_memory, remaining, pConv); stack[1].count -= remaining; - stack[1].disp += remaining; /* keep the += in case we are copying less that the datatype size */ - if( 0 == stack[1].count ) { /* prepare for the next element */ + stack[1].disp += remaining; /* keep the += in case we are copying less that the datatype + size */ + if (0 == stack[1].count) { /* prepare for the next element */ stack[1].count = pData->size; - stack[1].disp = 0; + stack[1].disp = 0; } } } - update_status_and_return: +update_status_and_return: *out_size = idx; *max_data = pConv->bConverted - initial_bytes_converted; - if( pConv->bConverted == pConv->local_size ) pConv->flags |= CONVERTOR_COMPLETED; - return !!(pConv->flags & CONVERTOR_COMPLETED); /* done or not */ + if (pConv->bConverted == pConv->local_size) { + pConv->flags |= CONVERTOR_COMPLETED; + } + return !!(pConv->flags & CONVERTOR_COMPLETED); /* done or not */ } /* The pack/unpack functions need a cleanup. I have to create a proper interface to access @@ -227,29 +239,27 @@ opal_pack_homogeneous_contig_with_gaps_function( opal_convertor_t* pConv, * But first let's make some global assumptions: * - a datatype (with the flag DT_DATA set) will have the contiguous flags set if and only if * the data is really contiguous (extent equal with size) - * - for the OPAL_DATATYPE_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop is - * contiguous but with a gap in the begining or at the end. + * - for the OPAL_DATATYPE_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop + * is contiguous but with a gap in the begining or at the end. * - the DT_CONTIGUOUS flag for the type OPAL_DATATYPE_END_LOOP is meaningless. */ -int32_t -opal_generic_simple_pack_function( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ) +int32_t opal_generic_simple_pack_function(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - size_t count_desc; /* the number of items already done in the actual pos_desc */ - size_t total_packed = 0; /* total amount packed this time */ - dt_elem_desc_t* description; - dt_elem_desc_t* pElem; + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + size_t count_desc; /* the number of items already done in the actual pos_desc */ + size_t total_packed = 0; /* total amount packed this time */ + dt_elem_desc_t *description; + dt_elem_desc_t *pElem; const opal_datatype_t *pData = pConvertor->pDesc; unsigned char *conv_ptr, *iov_ptr; size_t iov_len_local; uint32_t iov_count; - DO_DEBUG( opal_output( 0, "opal_convertor_generic_simple_pack( %p:%p, {%p, %lu}, %d )\n", - (void*)pConvertor, (void*)pConvertor->pBaseBuf, - (void*)iov[0].iov_base, (unsigned long)iov[0].iov_len, *out_size ); ); + DO_DEBUG(opal_output(0, "opal_convertor_generic_simple_pack( %p:%p, {%p, %lu}, %d )\n", + (void *) pConvertor, (void *) pConvertor->pBaseBuf, + (void *) iov[0].iov_base, (unsigned long) iov[0].iov_len, *out_size);); description = pConvertor->use_desc->desc; @@ -258,114 +268,124 @@ opal_generic_simple_pack_function( opal_convertor_t* pConvertor, * due to the fact that the convertor can stop in the middle of a data with a count */ pStack = pConvertor->pStack + pConvertor->stack_pos; - pos_desc = pStack->index; - conv_ptr = pConvertor->pBaseBuf + pStack->disp; + pos_desc = pStack->index; + conv_ptr = pConvertor->pBaseBuf + pStack->disp; count_desc = pStack->count; pStack--; pConvertor->stack_pos--; pElem = &(description[pos_desc]); - DO_DEBUG( opal_output( 0, "pack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" - "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pos_desc, count_desc, (long)(conv_ptr - pConvertor->pBaseBuf), - pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp ); ); + DO_DEBUG(opal_output(0, + "pack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" + "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", + pos_desc, count_desc, (long) (conv_ptr - pConvertor->pBaseBuf), + pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp);); - for( iov_count = 0; iov_count < (*out_size); iov_count++ ) { + for (iov_count = 0; iov_count < (*out_size); iov_count++) { iov_ptr = (unsigned char *) iov[iov_count].iov_base; iov_len_local = iov[iov_count].iov_len; - if( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { - if( ((size_t)pElem->elem.count * pElem->elem.blocklen) != count_desc ) { + if (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { + if (((size_t) pElem->elem.count * pElem->elem.blocklen) != count_desc) { /* we have a partial (less than blocklen) basic datatype */ - int rc = PACK_PARTIAL_BLOCKLEN( pConvertor, pElem, count_desc, - conv_ptr, iov_ptr, iov_len_local ); - if( 0 == rc ) /* not done */ + int rc = PACK_PARTIAL_BLOCKLEN(pConvertor, pElem, count_desc, conv_ptr, iov_ptr, + iov_len_local); + if (0 == rc) { /* not done */ goto complete_loop; - if( 0 == count_desc ) { + } + if (0 == count_desc) { conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); } } } - while( 1 ) { - while( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (1) { + while (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* we have a basic datatype (working on full blocks) */ - PACK_PREDEFINED_DATATYPE( pConvertor, pElem, count_desc, - conv_ptr, iov_ptr, iov_len_local ); - if( 0 != count_desc ) /* completed? */ + PACK_PREDEFINED_DATATYPE(pConvertor, pElem, count_desc, conv_ptr, iov_ptr, + iov_len_local); + if (0 != count_desc) { /* completed? */ goto complete_loop; + } conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); } - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */ - DO_DEBUG( opal_output( 0, "pack end_loop count %" PRIsize_t " stack_pos %d" - " pos_desc %d disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, - pos_desc, pStack->disp, (unsigned long)iov_len_local ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( 0 == pConvertor->stack_pos ) { + if (OPAL_DATATYPE_END_LOOP == pElem->elem.common.type) { /* end of the current loop */ + DO_DEBUG(opal_output(0, + "pack end_loop count %" PRIsize_t " stack_pos %d" + " pos_desc %d disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); + if (--(pStack->count) == 0) { /* end of loop */ + if (0 == pConvertor->stack_pos) { /* we're done. Force the exit of the main for loop (around iovec) */ *out_size = iov_count; goto complete_loop; } - pConvertor->stack_pos--; /* go one position up on the stack */ + pConvertor->stack_pos--; /* go one position up on the stack */ pStack--; - pos_desc++; /* and move to the next element */ + pos_desc++; /* and move to the next element */ } else { - pos_desc = pStack->index + 1; /* jump back to the begining of the loop */ - if( pStack->index == -1 ) { /* If it's the datatype count loop */ - pStack->disp += (pData->ub - pData->lb); /* jump by the datatype extent */ + pos_desc = pStack->index + 1; /* jump back to the begining of the loop */ + if (pStack->index == -1) { /* If it's the datatype count loop */ + pStack->disp += (pData->ub - pData->lb); /* jump by the datatype extent */ } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); - pStack->disp += description[pStack->index].loop.extent; /* jump by the loop extent */ + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); + pStack->disp += description[pStack->index] + .loop.extent; /* jump by the loop extent */ } } conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "pack new_loop count %" PRIsize_t " stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - count_desc, pStack->disp, (unsigned long)iov_len_local ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "pack new_loop count %" PRIsize_t + " stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, count_desc, + pStack->disp, (unsigned long) iov_len_local);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - ptrdiff_t local_disp = (ptrdiff_t)conv_ptr; - if( pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { - PACK_CONTIGUOUS_LOOP( pConvertor, pElem, count_desc, - conv_ptr, iov_ptr, iov_len_local ); - if( 0 == count_desc ) { /* completed */ + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + ptrdiff_t local_disp = (ptrdiff_t) conv_ptr; + if (pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + PACK_CONTIGUOUS_LOOP(pConvertor, pElem, count_desc, conv_ptr, iov_ptr, + iov_len_local); + if (0 == count_desc) { /* completed */ pos_desc += pElem->loop.items + 1; goto update_loop_description; } /* Save the stack with the correct last_count value. */ } - local_disp = (ptrdiff_t)conv_ptr - local_disp; - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp + local_disp); + local_disp = (ptrdiff_t) conv_ptr - local_disp; + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp + local_disp); pos_desc++; - update_loop_description: /* update the current state */ + update_loop_description: /* update the current state */ conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop"); } } complete_loop: - iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ + iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ total_packed += iov[iov_count].iov_len; } *max_data = total_packed; - pConvertor->bConverted += total_packed; /* update the already converted bytes */ + pConvertor->bConverted += total_packed; /* update the already converted bytes */ *out_size = iov_count; - if( pConvertor->bConverted == pConvertor->local_size ) { + if (pConvertor->bConverted == pConvertor->local_size) { pConvertor->flags |= CONVERTOR_COMPLETED; return 1; } /* Save the global position for the next round */ - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, - conv_ptr - pConvertor->pBaseBuf ); - DO_DEBUG( opal_output( 0, "pack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp ); ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, + conv_ptr - pConvertor->pBaseBuf); + DO_DEBUG(opal_output(0, + "pack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %ld\n", + pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp);); return 0; } @@ -382,64 +402,62 @@ opal_generic_simple_pack_function( opal_convertor_t* pConvertor, * -1 something wrong occurs. */ -static inline void -pack_predefined_heterogeneous( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** SOURCE, - unsigned char** DESTINATION, - size_t* SPACE ) +static inline void pack_predefined_heterogeneous(opal_convertor_t *CONVERTOR, + const dt_elem_desc_t *ELEM, size_t *COUNT, + unsigned char **SOURCE, + unsigned char **DESTINATION, size_t *SPACE) { - const opal_convertor_master_t* master = (CONVERTOR)->master; - const ddt_elem_desc_t* _elem = &((ELEM)->elem); - unsigned char* _source = (*SOURCE) + _elem->disp; + const opal_convertor_master_t *master = (CONVERTOR)->master; + const ddt_elem_desc_t *_elem = &((ELEM)->elem); + unsigned char *_source = (*SOURCE) + _elem->disp; ptrdiff_t advance; size_t _count = *(COUNT); size_t _r_blength; _r_blength = master->remote_sizes[_elem->common.type]; - if( (_count * _r_blength) > *(SPACE) ) { + if ((_count * _r_blength) > *(SPACE)) { _count = (*(SPACE) / _r_blength); - if( 0 == _count ) return; /* nothing to do */ + if (0 == _count) { + return; /* nothing to do */ + } } - OPAL_DATATYPE_SAFEGUARD_POINTER( _source, (_count * _elem->extent), (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "pack [l %s r %s] memcpy( %p, %p, %lu ) => space %lu\n", - ((ptrdiff_t)(opal_datatype_basicDatatypes[_elem->common.type]->size) == _elem->extent) ? "cont" : "----", - ((ptrdiff_t)_r_blength == _elem->extent) ? "cont" : "----", - (void*)*(DESTINATION), (void*)_source, (unsigned long)_r_blength, - (unsigned long)(*(SPACE)) ); ); - master->pFunctions[_elem->common.type]( CONVERTOR, _count, - _source, *SPACE, _elem->extent, - *DESTINATION, *SPACE, _r_blength, - &advance ); - _r_blength *= _count; /* update the remote length to encompass all the elements */ - *(SOURCE) += _count * _elem->extent; + OPAL_DATATYPE_SAFEGUARD_POINTER(_source, (_count * _elem->extent), (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "pack [l %s r %s] memcpy( %p, %p, %lu ) => space %lu\n", + ((ptrdiff_t)(opal_datatype_basicDatatypes[_elem->common.type]->size) + == _elem->extent) + ? "cont" + : "----", + ((ptrdiff_t) _r_blength == _elem->extent) ? "cont" : "----", + (void *) *(DESTINATION), (void *) _source, (unsigned long) _r_blength, + (unsigned long) (*(SPACE)));); + master->pFunctions[_elem->common.type](CONVERTOR, _count, _source, *SPACE, _elem->extent, + *DESTINATION, *SPACE, _r_blength, &advance); + _r_blength *= _count; /* update the remote length to encompass all the elements */ + *(SOURCE) += _count * _elem->extent; *(DESTINATION) += _r_blength; - *(SPACE) -= _r_blength; - *(COUNT) -= _count; + *(SPACE) -= _r_blength; + *(COUNT) -= _count; } -int32_t -opal_pack_general_function( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ) +int32_t opal_pack_general_function(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - size_t count_desc; /* the number of items already done in the actual pos_desc */ - size_t total_packed = 0; /* total amount packed this time */ - dt_elem_desc_t* description; - dt_elem_desc_t* pElem; + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + size_t count_desc; /* the number of items already done in the actual pos_desc */ + size_t total_packed = 0; /* total amount packed this time */ + dt_elem_desc_t *description; + dt_elem_desc_t *pElem; const opal_datatype_t *pData = pConvertor->pDesc; unsigned char *conv_ptr, *iov_ptr; size_t iov_len_local; uint32_t iov_count; - DO_DEBUG( opal_output( 0, "opal_convertor_general_pack( %p:%p, {%p, %lu}, %d )\n", - (void*)pConvertor, (void*)pConvertor->pBaseBuf, - (void*)iov[0].iov_base, (unsigned long)iov[0].iov_len, *out_size ); ); + DO_DEBUG(opal_output(0, "opal_convertor_general_pack( %p:%p, {%p, %lu}, %d )\n", + (void *) pConvertor, (void *) pConvertor->pBaseBuf, + (void *) iov[0].iov_base, (unsigned long) iov[0].iov_len, *out_size);); description = pConvertor->use_desc->desc; @@ -448,77 +466,83 @@ opal_pack_general_function( opal_convertor_t* pConvertor, * due to the fact that the convertor can stop in the middle of a data with a count */ pStack = pConvertor->pStack + pConvertor->stack_pos; - pos_desc = pStack->index; - conv_ptr = pConvertor->pBaseBuf + pStack->disp; + pos_desc = pStack->index; + conv_ptr = pConvertor->pBaseBuf + pStack->disp; count_desc = pStack->count; pStack--; pConvertor->stack_pos--; pElem = &(description[pos_desc]); - DO_DEBUG( opal_output( 0, "pack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" - "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pos_desc, count_desc, (long)(conv_ptr - pConvertor->pBaseBuf), - pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp ); ); + DO_DEBUG(opal_output(0, + "pack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" + "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", + pos_desc, count_desc, (long) (conv_ptr - pConvertor->pBaseBuf), + pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp);); - for( iov_count = 0; iov_count < (*out_size); iov_count++ ) { + for (iov_count = 0; iov_count < (*out_size); iov_count++) { iov_ptr = (unsigned char *) iov[iov_count].iov_base; iov_len_local = iov[iov_count].iov_len; - while( 1 ) { - while( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (1) { + while (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ - DO_DEBUG( opal_output( 0, "pack (%p:%ld, %" PRIsize_t ", %ld) -> (%p, %ld) type %s\n", - (void*)pConvertor->pBaseBuf, conv_ptr + pElem->elem.disp - pConvertor->pBaseBuf, - count_desc, description[pos_desc].elem.extent, - (void*)iov_ptr, iov_len_local, - opal_datatype_basicDatatypes[pElem->elem.common.type]->name ); ); - - pack_predefined_heterogeneous( pConvertor, pElem, &count_desc, - &conv_ptr, &iov_ptr, &iov_len_local); + DO_DEBUG(opal_output(0, "pack (%p:%ld, %" PRIsize_t ", %ld) -> (%p, %ld) type %s\n", + (void *) pConvertor->pBaseBuf, + conv_ptr + pElem->elem.disp - pConvertor->pBaseBuf, count_desc, + description[pos_desc].elem.extent, (void *) iov_ptr, + iov_len_local, + opal_datatype_basicDatatypes[pElem->elem.common.type]->name);); + + pack_predefined_heterogeneous(pConvertor, pElem, &count_desc, &conv_ptr, &iov_ptr, + &iov_len_local); #if 0 PACK_PREDEFINED_DATATYPE( pConvertor, pElem, count_desc, conv_ptr, iov_ptr, iov_len_local ); #endif - if( 0 == count_desc ) { /* completed */ + if (0 == count_desc) { /* completed */ conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); continue; } goto complete_loop; } - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */ - DO_DEBUG( opal_output( 0, "pack end_loop count %" PRIsize_t " stack_pos %d" - " pos_desc %d disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, - pos_desc, pStack->disp, (unsigned long)iov_len_local ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( 0 == pConvertor->stack_pos ) { + if (OPAL_DATATYPE_END_LOOP == pElem->elem.common.type) { /* end of the current loop */ + DO_DEBUG(opal_output(0, + "pack end_loop count %" PRIsize_t " stack_pos %d" + " pos_desc %d disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); + if (--(pStack->count) == 0) { /* end of loop */ + if (0 == pConvertor->stack_pos) { /* we lie about the size of the next element in order to * make sure we exit the main loop. */ *out_size = iov_count; - goto complete_loop; /* completed */ + goto complete_loop; /* completed */ } pConvertor->stack_pos--; pStack--; pos_desc++; } else { pos_desc = pStack->index + 1; - if( pStack->index == -1 ) { + if (pStack->index == -1) { pStack->disp += (pData->ub - pData->lb); } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); pStack->disp += description[pStack->index].loop.extent; } } conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "pack new_loop count %" PRIsize_t " stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - count_desc, pStack->disp, (unsigned long)iov_len_local ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "pack new_loop count %" PRIsize_t + " stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, count_desc, + pStack->disp, (unsigned long) iov_len_local);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - ptrdiff_t local_disp = (ptrdiff_t)conv_ptr; + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + ptrdiff_t local_disp = (ptrdiff_t) conv_ptr; #if 0 if( pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { PACK_CONTIGUOUS_LOOP( pConvertor, pElem, count_desc, @@ -529,35 +553,37 @@ opal_pack_general_function( opal_convertor_t* pConvertor, } /* Save the stack with the correct last_count value. */ } -#endif /* in a heterogeneous environment we can't handle the contiguous loops */ - local_disp = (ptrdiff_t)conv_ptr - local_disp; - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp + local_disp); +#endif /* in a heterogeneous environment we can't handle the contiguous loops */ + local_disp = (ptrdiff_t) conv_ptr - local_disp; + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp + local_disp); pos_desc++; #if 0 update_loop_description: /* update the current state */ -#endif /* in a heterogeneous environment we can't handle the contiguous loops */ +#endif /* in a heterogeneous environment we can't handle the contiguous loops */ conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop"); continue; } } complete_loop: - iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ + iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ total_packed += iov[iov_count].iov_len; } *max_data = total_packed; - pConvertor->bConverted += total_packed; /* update the already converted bytes */ + pConvertor->bConverted += total_packed; /* update the already converted bytes */ *out_size = iov_count; - if( pConvertor->bConverted == pConvertor->local_size ) { + if (pConvertor->bConverted == pConvertor->local_size) { pConvertor->flags |= CONVERTOR_COMPLETED; return 1; } /* Save the global position for the next round */ - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, - conv_ptr - pConvertor->pBaseBuf ); - DO_DEBUG( opal_output( 0, "pack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t" disp %ld\n", - pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp ); ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, + conv_ptr - pConvertor->pBaseBuf); + DO_DEBUG(opal_output(0, + "pack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %ld\n", + pConvertor->stack_pos, pStack->index, pStack->count, pStack->disp);); return 0; } diff --git a/opal/datatype/opal_datatype_pack.h b/opal/datatype/opal_datatype_pack.h index 75ef69a4c4d..63fe7f41d48 100644 --- a/opal/datatype/opal_datatype_pack.h +++ b/opal/datatype/opal_datatype_pack.h @@ -24,33 +24,29 @@ #if !defined(CHECKSUM) && OPAL_CUDA_SUPPORT /* Make use of existing macro to do CUDA style memcpy */ -#undef MEMCPY_CSUM -#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \ - CONVERTOR->cbmemcpy( (DST), (SRC), (BLENGTH), (CONVERTOR) ) +# undef MEMCPY_CSUM +# define MEMCPY_CSUM(DST, SRC, BLENGTH, CONVERTOR) \ + CONVERTOR->cbmemcpy((DST), (SRC), (BLENGTH), (CONVERTOR)) #endif /** - * This function deals only with partial elements. The COUNT points however to the whole leftover count, - * but this function is only expected to operate on an amount less than blength, that would allow the rest - * of the pack process to handle only entire blength blocks (plus the left over). + * This function deals only with partial elements. The COUNT points however to the whole leftover + * count, but this function is only expected to operate on an amount less than blength, that would + * allow the rest of the pack process to handle only entire blength blocks (plus the left over). * * Return 1 if we are now aligned on a block, 0 otherwise. */ -static inline int -pack_partial_blocklen( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** memory, - unsigned char** packed, - size_t* SPACE ) +static inline int pack_partial_blocklen(opal_convertor_t *CONVERTOR, const dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **memory, + unsigned char **packed, size_t *SPACE) { - const ddt_elem_desc_t* _elem = &((ELEM)->elem); + const ddt_elem_desc_t *_elem = &((ELEM)->elem); size_t do_now_bytes = opal_datatype_basicDatatypes[_elem->common.type]->size; size_t do_now = *(COUNT); - unsigned char* _memory = (*memory) + _elem->disp; - unsigned char* _packed = *packed; + unsigned char *_memory = (*memory) + _elem->disp; + unsigned char *_packed = *packed; - assert( *(COUNT) <= ((size_t)_elem->count * _elem->blocklen) ); + assert(*(COUNT) <= ((size_t) _elem->count * _elem->blocklen)); /** * First check if we already did something on this element ? The COUNT is the number @@ -58,89 +54,92 @@ pack_partial_blocklen( opal_convertor_t* CONVERTOR, * should be manipulated in the current call (this number is instead reflected on the * SPACE). */ - if( 0 == (do_now = (*COUNT) % _elem->blocklen) ) + if (0 == (do_now = (*COUNT) % _elem->blocklen)) return 1; - size_t left_in_block = do_now; /* left in the current blocklen */ + size_t left_in_block = do_now; /* left in the current blocklen */ - if( (do_now_bytes * do_now) > *(SPACE) ) + if ((do_now_bytes * do_now) > *(SPACE)) do_now = (*SPACE) / do_now_bytes; do_now_bytes *= do_now; - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "pack memcpy( %p, %p, %lu ) => space %lu [partial]\n", - (void*) _packed, (void*)_memory, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE)) ); ); - MEMCPY_CSUM( _packed, _memory, do_now_bytes, (CONVERTOR) ); - *(memory) += (ptrdiff_t)do_now_bytes; - if( do_now == left_in_block ) /* compensate if completed a blocklen */ - *(memory) += _elem->extent - (_elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size); - - *(COUNT) -= do_now; - *(SPACE) -= do_now_bytes; + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, do_now_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "pack memcpy( %p, %p, %lu ) => space %lu [partial]\n", (void *) _packed, + (void *) _memory, (unsigned long) do_now_bytes, + (unsigned long) (*(SPACE)));); + MEMCPY_CSUM(_packed, _memory, do_now_bytes, (CONVERTOR)); + *(memory) += (ptrdiff_t) do_now_bytes; + if (do_now == left_in_block) /* compensate if completed a blocklen */ + *(memory) += _elem->extent + - (_elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size); + + *(COUNT) -= do_now; + *(SPACE) -= do_now_bytes; *(packed) += do_now_bytes; return (do_now == left_in_block); } /** - * Pack entire blocks, plus a possible remainder if SPACE is constrained to less than COUNT elements. + * Pack entire blocks, plus a possible remainder if SPACE is constrained to less than COUNT + * elements. */ -static inline void -pack_predefined_data( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** memory, - unsigned char** packed, - size_t* SPACE ) +static inline void pack_predefined_data(opal_convertor_t *CONVERTOR, const dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **memory, + unsigned char **packed, size_t *SPACE) { - const ddt_elem_desc_t* _elem = &((ELEM)->elem); + const ddt_elem_desc_t *_elem = &((ELEM)->elem); size_t blocklen_bytes = opal_datatype_basicDatatypes[_elem->common.type]->size; size_t cando_count = *(COUNT), do_now_bytes; - unsigned char* _memory = (*memory) + _elem->disp; - unsigned char* _packed = *packed; + unsigned char *_memory = (*memory) + _elem->disp; + unsigned char *_packed = *packed; - assert( 0 == (cando_count % _elem->blocklen) ); /* no partials here */ - assert( *(COUNT) <= ((size_t)_elem->count * _elem->blocklen) ); + assert(0 == (cando_count % _elem->blocklen)); /* no partials here */ + assert(*(COUNT) <= ((size_t) _elem->count * _elem->blocklen)); - if( (blocklen_bytes * cando_count) > *(SPACE) ) + if ((blocklen_bytes * cando_count) > *(SPACE)) cando_count = (*SPACE) / blocklen_bytes; /* premptively update the number of COUNT we will return. */ *(COUNT) -= cando_count; - if(_elem->blocklen < 9) { - if((!(CONVERTOR->flags & CONVERTOR_CUDA)) && OPAL_LIKELY(OPAL_SUCCESS == - opal_datatype_pack_predefined_element(&_memory, &_packed, cando_count, _elem))) { + if (_elem->blocklen < 9) { + if ((!(CONVERTOR->flags & CONVERTOR_CUDA)) + && OPAL_LIKELY( + OPAL_SUCCESS + == opal_datatype_pack_predefined_element(&_memory, &_packed, cando_count, _elem))) { goto update_and_return; } /* else unrecognized _elem->common.type, use the memcpy path */ } - if(_elem->blocklen == 1) { - for(; cando_count > 0; cando_count--) { - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "pack memcpy( %p, %p, %lu ) => space %lu [blen = 1]\n", - (void*)_packed, (void*)_memory, (unsigned long)blocklen_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); ); - MEMCPY_CSUM( _packed, _memory, blocklen_bytes, (CONVERTOR) ); - _packed += blocklen_bytes; - _memory += _elem->extent; + if (_elem->blocklen == 1) { + for (; cando_count > 0; cando_count--) { + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "pack memcpy( %p, %p, %lu ) => space %lu [blen = 1]\n", + (void *) _packed, (void *) _memory, (unsigned long) blocklen_bytes, + (unsigned long) (*(SPACE) - (_packed - *(packed))));); + MEMCPY_CSUM(_packed, _memory, blocklen_bytes, (CONVERTOR)); + _packed += blocklen_bytes; + _memory += _elem->extent; } goto update_and_return; } - if( (1 < _elem->count) && (_elem->blocklen <= cando_count) ) { + if ((1 < _elem->count) && (_elem->blocklen <= cando_count)) { blocklen_bytes *= _elem->blocklen; do { /* Do as many full blocklen as possible */ - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "pack 2. memcpy( %p, %p, %lu ) => space %lu\n", - (void*)_packed, (void*)_memory, (unsigned long)blocklen_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); ); - MEMCPY_CSUM( _packed, _memory, blocklen_bytes, (CONVERTOR) ); - _packed += blocklen_bytes; - _memory += _elem->extent; + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "pack 2. memcpy( %p, %p, %lu ) => space %lu\n", + (void *) _packed, (void *) _memory, (unsigned long) blocklen_bytes, + (unsigned long) (*(SPACE) - (_packed - *(packed))));); + MEMCPY_CSUM(_packed, _memory, blocklen_bytes, (CONVERTOR)); + _packed += blocklen_bytes; + _memory += _elem->extent; cando_count -= _elem->blocklen; } while (_elem->blocklen <= cando_count); } @@ -148,70 +147,69 @@ pack_predefined_data( opal_convertor_t* CONVERTOR, /** * As an epilog do anything left from the last blocklen. */ - if( 0 != cando_count ) { - assert( (cando_count < _elem->blocklen) || - ((1 == _elem->count) && (cando_count <= _elem->blocklen)) ); + if (0 != cando_count) { + assert((cando_count < _elem->blocklen) + || ((1 == _elem->count) && (cando_count <= _elem->blocklen))); do_now_bytes = cando_count * opal_datatype_basicDatatypes[_elem->common.type]->size; - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "pack 3. memcpy( %p, %p, %lu ) => space %lu [epilog]\n", - (void*)_packed, (void*)_memory, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); ); - MEMCPY_CSUM( _packed, _memory, do_now_bytes, (CONVERTOR) ); - _memory += do_now_bytes; - _packed += do_now_bytes; + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, do_now_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "pack 3. memcpy( %p, %p, %lu ) => space %lu [epilog]\n", + (void *) _packed, (void *) _memory, (unsigned long) do_now_bytes, + (unsigned long) (*(SPACE) - (_packed - *(packed))));); + MEMCPY_CSUM(_packed, _memory, do_now_bytes, (CONVERTOR)); + _memory += do_now_bytes; + _packed += do_now_bytes; } - update_and_return: - *(memory) = _memory - _elem->disp; - *(SPACE) -= (_packed - *packed); - *(packed) = _packed; +update_and_return: + *(memory) = _memory - _elem->disp; + *(SPACE) -= (_packed - *packed); + *(packed) = _packed; } -static inline void pack_contiguous_loop( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** memory, - unsigned char** packed, - size_t* SPACE ) +static inline void pack_contiguous_loop(opal_convertor_t *CONVERTOR, const dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **memory, + unsigned char **packed, size_t *SPACE) { - const ddt_loop_desc_t *_loop = (ddt_loop_desc_t*)(ELEM); - const ddt_endloop_desc_t* _end_loop = (ddt_endloop_desc_t*)((ELEM) + _loop->items); - unsigned char* _memory = (*memory) + _end_loop->first_elem_disp; + const ddt_loop_desc_t *_loop = (ddt_loop_desc_t *) (ELEM); + const ddt_endloop_desc_t *_end_loop = (ddt_endloop_desc_t *) ((ELEM) + _loop->items); + unsigned char *_memory = (*memory) + _end_loop->first_elem_disp; size_t _copy_loops = *(COUNT); - if( (_copy_loops * _end_loop->size) > *(SPACE) ) + if ((_copy_loops * _end_loop->size) > *(SPACE)) _copy_loops = (*(SPACE) / _end_loop->size); - for(size_t _i = 0; _i < _copy_loops; _i++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, _end_loop->size, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "pack 3. memcpy( %p, %p, %lu ) => space %lu\n", - (void*)*(packed), (void*)_memory, (unsigned long)_end_loop->size, (unsigned long)(*(SPACE) - _i * _end_loop->size) ); ); - MEMCPY_CSUM( *(packed), _memory, _end_loop->size, (CONVERTOR) ); + for (size_t _i = 0; _i < _copy_loops; _i++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, _end_loop->size, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "pack 3. memcpy( %p, %p, %lu ) => space %lu\n", (void *) *(packed), + (void *) _memory, (unsigned long) _end_loop->size, + (unsigned long) (*(SPACE) -_i * _end_loop->size));); + MEMCPY_CSUM(*(packed), _memory, _end_loop->size, (CONVERTOR)); *(packed) += _end_loop->size; - _memory += _loop->extent; + _memory += _loop->extent; } *(memory) = _memory - _end_loop->first_elem_disp; *(SPACE) -= _copy_loops * _end_loop->size; *(COUNT) -= _copy_loops; } -#define PACK_PARTIAL_BLOCKLEN( CONVERTOR, /* the convertor */ \ - ELEM, /* the basic element to be packed */ \ - COUNT, /* the number of elements */ \ - MEMORY, /* the source pointer (char*) */ \ - PACKED, /* the destination pointer (char*) */ \ - SPACE ) /* the space in the destination buffer */ \ -pack_partial_blocklen( (CONVERTOR), (ELEM), &(COUNT), &(MEMORY), &(PACKED), &(SPACE) ) - -#define PACK_PREDEFINED_DATATYPE( CONVERTOR, /* the convertor */ \ - ELEM, /* the basic element to be packed */ \ - COUNT, /* the number of elements */ \ - MEMORY, /* the source pointer (char*) */ \ - PACKED, /* the destination pointer (char*) */ \ - SPACE ) /* the space in the destination buffer */ \ -pack_predefined_data( (CONVERTOR), (ELEM), &(COUNT), &(MEMORY), &(PACKED), &(SPACE) ) - -#define PACK_CONTIGUOUS_LOOP( CONVERTOR, ELEM, COUNT, MEMORY, PACKED, SPACE ) \ - pack_contiguous_loop( (CONVERTOR), (ELEM), &(COUNT), &(MEMORY), &(PACKED), &(SPACE) ) - -#endif /* OPAL_DATATYPE_PACK_H_HAS_BEEN_INCLUDED */ +#define PACK_PARTIAL_BLOCKLEN(CONVERTOR, /* the convertor */ \ + ELEM, /* the basic element to be packed */ \ + COUNT, /* the number of elements */ \ + MEMORY, /* the source pointer (char*) */ \ + PACKED, /* the destination pointer (char*) */ \ + SPACE) /* the space in the destination buffer */ \ + pack_partial_blocklen((CONVERTOR), (ELEM), &(COUNT), &(MEMORY), &(PACKED), &(SPACE)) + +#define PACK_PREDEFINED_DATATYPE(CONVERTOR, /* the convertor */ \ + ELEM, /* the basic element to be packed */ \ + COUNT, /* the number of elements */ \ + MEMORY, /* the source pointer (char*) */ \ + PACKED, /* the destination pointer (char*) */ \ + SPACE) /* the space in the destination buffer */ \ + pack_predefined_data((CONVERTOR), (ELEM), &(COUNT), &(MEMORY), &(PACKED), &(SPACE)) + +#define PACK_CONTIGUOUS_LOOP(CONVERTOR, ELEM, COUNT, MEMORY, PACKED, SPACE) \ + pack_contiguous_loop((CONVERTOR), (ELEM), &(COUNT), &(MEMORY), &(PACKED), &(SPACE)) + +#endif /* OPAL_DATATYPE_PACK_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_datatype_pack_unpack_predefined.h b/opal/datatype/opal_datatype_pack_unpack_predefined.h index 94e50b3ea22..261f2d48adf 100644 --- a/opal/datatype/opal_datatype_pack_unpack_predefined.h +++ b/opal/datatype/opal_datatype_pack_unpack_predefined.h @@ -68,180 +68,177 @@ * do a manual copy for larger blocklengths, but more data will have * to be gathered to see if an implementation would be * better over the current implementation. -*/ - -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_ONE(stride, blocklen) { \ - for (; i; i--) { \ - *_dest = *_src; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} + */ -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_TWO(stride, blocklen) { \ - for (; i > 1; i -= 2) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_ONE(stride, blocklen) \ + { \ + for (; i; i--) { \ + *_dest = *_src; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_THREE(stride, blocklen) { \ - for (; i > 2; i -= 3) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _dest[2] = _src[2]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_TWO(stride, blocklen) \ + { \ + for (; i > 1; i -= 2) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FOUR(stride, blocklen) { \ - for (; i > 3; i -= 4) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _dest[2] = _src[2]; \ - _dest[3] = _src[3]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_THREE(stride, blocklen) \ + { \ + for (; i > 2; i -= 3) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _dest[2] = _src[2]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FIVE(stride, blocklen) { \ - for (; i > 4; i -= 5) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _dest[2] = _src[2]; \ - _dest[3] = _src[3]; \ - _dest[4] = _src[4]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FOUR(stride, blocklen) \ + { \ + for (; i > 3; i -= 4) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _dest[2] = _src[2]; \ + _dest[3] = _src[3]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SIX(stride, blocklen) { \ - for (; i > 5; i -= 6) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _dest[2] = _src[2]; \ - _dest[3] = _src[3]; \ - _dest[4] = _src[4]; \ - _dest[5] = _src[5]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FIVE(stride, blocklen) \ + { \ + for (; i > 4; i -= 5) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _dest[2] = _src[2]; \ + _dest[3] = _src[3]; \ + _dest[4] = _src[4]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SEVEN(stride, blocklen) { \ - for (; i > 6; i -= 7) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _dest[2] = _src[2]; \ - _dest[3] = _src[3]; \ - _dest[4] = _src[4]; \ - _dest[5] = _src[5]; \ - _dest[6] = _src[6]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SIX(stride, blocklen) \ + { \ + for (; i > 5; i -= 6) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _dest[2] = _src[2]; \ + _dest[3] = _src[3]; \ + _dest[4] = _src[4]; \ + _dest[5] = _src[5]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_EIGHT(stride, blocklen) { \ - for (; i > 7; i -= 8) { \ - _dest[0] = _src[0]; \ - _dest[1] = _src[1]; \ - _dest[2] = _src[2]; \ - _dest[3] = _src[3]; \ - _dest[4] = _src[4]; \ - _dest[5] = _src[5]; \ - _dest[6] = _src[6]; \ - _dest[7] = _src[7]; \ - _src += stride; \ - _dest += blocklen; \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SEVEN(stride, blocklen) \ + { \ + for (; i > 6; i -= 7) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _dest[2] = _src[2]; \ + _dest[3] = _src[3]; \ + _dest[4] = _src[4]; \ + _dest[5] = _src[5]; \ + _dest[6] = _src[6]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_RESIDUAL_DATA() { \ - if(i != 0) { \ - for (; i > 0; i--) { \ - *_dest++ = *_src++; \ - } \ - } \ -} +#define OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_EIGHT(stride, blocklen) \ + { \ + for (; i > 7; i -= 8) { \ + _dest[0] = _src[0]; \ + _dest[1] = _src[1]; \ + _dest[2] = _src[2]; \ + _dest[3] = _src[3]; \ + _dest[4] = _src[4]; \ + _dest[5] = _src[5]; \ + _dest[6] = _src[6]; \ + _dest[7] = _src[7]; \ + _src += stride; \ + _dest += blocklen; \ + } \ + } + +#define OPAL_DATATYPE_PACK_PREDEFINED_RESIDUAL_DATA() \ + { \ + if (i != 0) { \ + for (; i > 0; i--) { \ + *_dest++ = *_src++; \ + } \ + } \ + } + +#define OPAL_DATATYPE_PACK_PREDEFINED_ELEMENT(src_base, dest_base, count, stride, blocklen, type) \ + { \ + type *_src = (type *) src_base; \ + type *_dest = (type *) dest_base; \ + register unsigned long i = count; \ + if (blocklen == 1) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_ONE(stride, blocklen); \ + } else if (blocklen == 2) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_TWO(stride, blocklen); \ + } else if (blocklen == 3) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_THREE(stride, blocklen); \ + } else if (blocklen == 4) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FOUR(stride, blocklen); \ + } else if (blocklen == 5) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FIVE(stride, blocklen); \ + } else if (blocklen == 6) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SIX(stride, blocklen); \ + } else if (blocklen == 7) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SEVEN(stride, blocklen); \ + } else if (blocklen == 8) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_EIGHT(stride, blocklen); \ + } \ + OPAL_DATATYPE_PACK_PREDEFINED_RESIDUAL_DATA() \ + src_base = (unsigned char *) _src; \ + dest_base = (unsigned char *) _dest; \ + } + +#define OPAL_DATATYPE_UNPACK_PREDEFINED_ELEMENT(src_base, dest_base, count, stride, blocklen, \ + type) \ + { \ + type *_src = (type *) src_base; \ + type *_dest = (type *) dest_base; \ + register unsigned long i = count; \ + /* (reversing the meanings of blocklen and stride and using the "PACK" macro) */ \ + if (blocklen == 1) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_ONE(blocklen, stride); \ + } else if (blocklen == 2) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_TWO(blocklen, stride); \ + } else if (blocklen == 3) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_THREE(blocklen, stride); \ + } else if (blocklen == 4) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FOUR(blocklen, stride); \ + } else if (blocklen == 5) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FIVE(blocklen, stride); \ + } else if (blocklen == 6) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SIX(blocklen, stride); \ + } else if (blocklen == 7) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SEVEN(blocklen, stride); \ + } else if (blocklen == 8) { \ + OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_EIGHT(blocklen, stride); \ + } \ + OPAL_DATATYPE_PACK_PREDEFINED_RESIDUAL_DATA() \ + src_base = (unsigned char *) _src; \ + dest_base = (unsigned char *) _dest; \ + } -#define OPAL_DATATYPE_PACK_PREDEFINED_ELEMENT(src_base, dest_base, count, stride, blocklen, type) { \ - type* _src = (type *) src_base; \ - type* _dest = (type *) dest_base; \ - register unsigned long i = count; \ - if(blocklen == 1) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_ONE(stride, blocklen); \ - } \ - else if (blocklen == 2) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_TWO(stride, blocklen); \ - } \ - else if (blocklen == 3) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_THREE(stride, blocklen); \ - } \ - else if (blocklen == 4) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FOUR(stride, blocklen); \ - } \ - else if (blocklen == 5) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FIVE(stride, blocklen); \ - } \ - else if (blocklen == 6) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SIX(stride, blocklen); \ - } \ - else if (blocklen == 7) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SEVEN(stride, blocklen); \ - } \ - else if (blocklen == 8) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_EIGHT(stride, blocklen); \ - } \ - OPAL_DATATYPE_PACK_PREDEFINED_RESIDUAL_DATA() \ - src_base = (unsigned char *) _src; \ - dest_base = (unsigned char *) _dest; \ -} \ - -#define OPAL_DATATYPE_UNPACK_PREDEFINED_ELEMENT(src_base, dest_base, count, stride, blocklen, type) { \ - type* _src = (type *) src_base; \ - type* _dest = (type *) dest_base; \ - register unsigned long i = count; \ - /* (reversing the meanings of blocklen and stride and using the "PACK" macro) */ \ - if(blocklen == 1) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_ONE(blocklen, stride); \ - } \ - else if (blocklen == 2) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_TWO(blocklen, stride); \ - } \ - else if (blocklen == 3) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_THREE(blocklen, stride); \ - } \ - else if (blocklen == 4) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FOUR(blocklen, stride); \ - } \ - else if (blocklen == 5) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_FIVE(blocklen, stride); \ - } \ - else if (blocklen == 6) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SIX(blocklen, stride); \ - } \ - else if (blocklen == 7) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_SEVEN(blocklen, stride); \ - } \ - else if (blocklen == 8) { \ - OPAL_DATATYPE_PACK_PREDEFINED_BLOCKLEN_EIGHT(blocklen, stride); \ - } \ - OPAL_DATATYPE_PACK_PREDEFINED_RESIDUAL_DATA() \ - src_base = (unsigned char *) _src; \ - dest_base = (unsigned char *) _dest; \ -} \ - -static inline int -opal_datatype_unpack_predefined_element( unsigned char** rtn_src, - unsigned char** rtn_dest, - size_t cando_count, - const ddt_elem_desc_t* elem) +static inline int opal_datatype_unpack_predefined_element(unsigned char **rtn_src, + unsigned char **rtn_dest, + size_t cando_count, + const ddt_elem_desc_t *elem) { size_t stride; // elem's extent but in terms of count rather than bytes size_t blocklen; @@ -256,12 +253,10 @@ opal_datatype_unpack_predefined_element( unsigned char** rtn_src, unsigned char *src = *rtn_src; unsigned char *dest = *rtn_dest; - if ((uintptr_t)src % align || - (uintptr_t)dest % align || - (elem->extent % align && cando_count > blocklen)) - { - return OPAL_ERROR; - } + if ((uintptr_t) src % align || (uintptr_t) dest % align + || (elem->extent % align && cando_count > blocklen)) { + return OPAL_ERROR; + } /* * Here as an example of how we want to call our macro, if the incoming id @@ -278,109 +273,107 @@ opal_datatype_unpack_predefined_element( unsigned char** rtn_src, * Otherwise we'd have to copy and maintain essentially the same blob of * macros that already exist in opal_datatype_internal.h. */ -#define OPAL_DATATYPE_MYUNPACK(NAME) \ - do { \ - OPAL_DATATYPE_HANDLE_ ## NAME( \ - OPAL_DATATYPE_MYUNPACK_AVAILABLE, \ - OPAL_DATATYPE_MYUNPACK_NOTAVAIL, 0); \ +#define OPAL_DATATYPE_MYUNPACK(NAME) \ + do { \ + OPAL_DATATYPE_HANDLE_##NAME(OPAL_DATATYPE_MYUNPACK_AVAILABLE, \ + OPAL_DATATYPE_MYUNPACK_NOTAVAIL, 0); \ } while (0) -#define OPAL_DATATYPE_MYUNPACK_AVAILABLE(TYPE, unused_ALIGN, NAME, unused) \ - do { \ +#define OPAL_DATATYPE_MYUNPACK_AVAILABLE(TYPE, unused_ALIGN, NAME, unused) \ + do { \ OPAL_DATATYPE_UNPACK_PREDEFINED_ELEMENT(src, dest, cando_count, stride, blocklen, TYPE); \ - success = true; \ + success = true; \ } while (0) #define OPAL_DATATYPE_MYUNPACK_NOTAVAIL(NAME, unused) \ - do { \ - success = false; \ + do { \ + success = false; \ } while (0) bool success = false; - switch(id) { - case OPAL_DATATYPE_INT1: - // The below macro should expand to - // OPAL_DATATYPE_UNPACK_PREDEFINED_ELEMENT(src, dest, cando_count, stride, blocklen, int8_t); - // by using OPAL_DATATYPE_HANDLE_* where it finds that INT1 means int8_t etc - OPAL_DATATYPE_MYUNPACK(INT1); - break; - case OPAL_DATATYPE_INT2: - OPAL_DATATYPE_MYUNPACK(INT2); - break; - case OPAL_DATATYPE_INT4: - OPAL_DATATYPE_MYUNPACK(INT4); - break; - case OPAL_DATATYPE_INT8: - OPAL_DATATYPE_MYUNPACK(INT8); - break; - case OPAL_DATATYPE_INT16: - OPAL_DATATYPE_MYUNPACK(INT16); - break; - case OPAL_DATATYPE_UINT1: - OPAL_DATATYPE_MYUNPACK(UINT1); - break; - case OPAL_DATATYPE_UINT2: - OPAL_DATATYPE_MYUNPACK(UINT2); - break; - case OPAL_DATATYPE_UINT4: - OPAL_DATATYPE_MYUNPACK(UINT4); - break; - case OPAL_DATATYPE_UINT8: - OPAL_DATATYPE_MYUNPACK(UINT8); - break; - case OPAL_DATATYPE_UINT16: - OPAL_DATATYPE_MYUNPACK(UINT16); - break; - case OPAL_DATATYPE_FLOAT2: - OPAL_DATATYPE_MYUNPACK(FLOAT2); - break; - case OPAL_DATATYPE_FLOAT4: - OPAL_DATATYPE_MYUNPACK(FLOAT4); - break; - case OPAL_DATATYPE_FLOAT8: - OPAL_DATATYPE_MYUNPACK(FLOAT8); - break; - case OPAL_DATATYPE_FLOAT12: - OPAL_DATATYPE_MYUNPACK(FLOAT12); - break; - case OPAL_DATATYPE_FLOAT16: - OPAL_DATATYPE_MYUNPACK(FLOAT16); - break; - case OPAL_DATATYPE_SHORT_FLOAT_COMPLEX: - OPAL_DATATYPE_MYUNPACK(SHORT_FLOAT_COMPLEX); - break; - case OPAL_DATATYPE_FLOAT_COMPLEX: - OPAL_DATATYPE_MYUNPACK(FLOAT_COMPLEX); - break; - case OPAL_DATATYPE_DOUBLE_COMPLEX: - OPAL_DATATYPE_MYUNPACK(DOUBLE_COMPLEX); - break; - case OPAL_DATATYPE_LONG_DOUBLE_COMPLEX: - OPAL_DATATYPE_MYUNPACK(LONG_DOUBLE_COMPLEX); - break; - case OPAL_DATATYPE_BOOL: - OPAL_DATATYPE_MYUNPACK(BOOL); - break; - case OPAL_DATATYPE_WCHAR: - OPAL_DATATYPE_MYUNPACK(WCHAR); - break; - default: - return OPAL_ERROR; + switch (id) { + case OPAL_DATATYPE_INT1: + // The below macro should expand to + // OPAL_DATATYPE_UNPACK_PREDEFINED_ELEMENT(src, dest, cando_count, stride, blocklen, + // int8_t); by using OPAL_DATATYPE_HANDLE_* where it finds that INT1 means int8_t etc + OPAL_DATATYPE_MYUNPACK(INT1); + break; + case OPAL_DATATYPE_INT2: + OPAL_DATATYPE_MYUNPACK(INT2); + break; + case OPAL_DATATYPE_INT4: + OPAL_DATATYPE_MYUNPACK(INT4); + break; + case OPAL_DATATYPE_INT8: + OPAL_DATATYPE_MYUNPACK(INT8); + break; + case OPAL_DATATYPE_INT16: + OPAL_DATATYPE_MYUNPACK(INT16); + break; + case OPAL_DATATYPE_UINT1: + OPAL_DATATYPE_MYUNPACK(UINT1); + break; + case OPAL_DATATYPE_UINT2: + OPAL_DATATYPE_MYUNPACK(UINT2); + break; + case OPAL_DATATYPE_UINT4: + OPAL_DATATYPE_MYUNPACK(UINT4); + break; + case OPAL_DATATYPE_UINT8: + OPAL_DATATYPE_MYUNPACK(UINT8); + break; + case OPAL_DATATYPE_UINT16: + OPAL_DATATYPE_MYUNPACK(UINT16); + break; + case OPAL_DATATYPE_FLOAT2: + OPAL_DATATYPE_MYUNPACK(FLOAT2); + break; + case OPAL_DATATYPE_FLOAT4: + OPAL_DATATYPE_MYUNPACK(FLOAT4); + break; + case OPAL_DATATYPE_FLOAT8: + OPAL_DATATYPE_MYUNPACK(FLOAT8); + break; + case OPAL_DATATYPE_FLOAT12: + OPAL_DATATYPE_MYUNPACK(FLOAT12); + break; + case OPAL_DATATYPE_FLOAT16: + OPAL_DATATYPE_MYUNPACK(FLOAT16); + break; + case OPAL_DATATYPE_SHORT_FLOAT_COMPLEX: + OPAL_DATATYPE_MYUNPACK(SHORT_FLOAT_COMPLEX); + break; + case OPAL_DATATYPE_FLOAT_COMPLEX: + OPAL_DATATYPE_MYUNPACK(FLOAT_COMPLEX); + break; + case OPAL_DATATYPE_DOUBLE_COMPLEX: + OPAL_DATATYPE_MYUNPACK(DOUBLE_COMPLEX); + break; + case OPAL_DATATYPE_LONG_DOUBLE_COMPLEX: + OPAL_DATATYPE_MYUNPACK(LONG_DOUBLE_COMPLEX); + break; + case OPAL_DATATYPE_BOOL: + OPAL_DATATYPE_MYUNPACK(BOOL); + break; + case OPAL_DATATYPE_WCHAR: + OPAL_DATATYPE_MYUNPACK(WCHAR); + break; + default: + return OPAL_ERROR; } if (!success) { return OPAL_ERROR; } - *rtn_src = src; + *rtn_src = src; *rtn_dest = dest; return OPAL_SUCCESS; } -static inline int -opal_datatype_pack_predefined_element( unsigned char** rtn_src, - unsigned char** rtn_dest, - size_t cando_count, - const ddt_elem_desc_t* elem) +static inline int opal_datatype_pack_predefined_element(unsigned char **rtn_src, + unsigned char **rtn_dest, + size_t cando_count, + const ddt_elem_desc_t *elem) { size_t stride; // elem's extent but in terms of count rather than bytes size_t blocklen; @@ -395,107 +388,104 @@ opal_datatype_pack_predefined_element( unsigned char** rtn_src, unsigned char *src = *rtn_src; unsigned char *dest = *rtn_dest; - if ((uintptr_t)src % align || - (uintptr_t)dest % align || - (elem->extent % align && cando_count > blocklen)) - { - return OPAL_ERROR; - } - -#define OPAL_DATATYPE_MYPACK(NAME) \ - do { \ - OPAL_DATATYPE_HANDLE_ ## NAME( \ - OPAL_DATATYPE_MYPACK_AVAILABLE, \ - OPAL_DATATYPE_MYPACK_NOTAVAIL, 0); \ + if ((uintptr_t) src % align || (uintptr_t) dest % align + || (elem->extent % align && cando_count > blocklen)) { + return OPAL_ERROR; + } + +#define OPAL_DATATYPE_MYPACK(NAME) \ + do { \ + OPAL_DATATYPE_HANDLE_##NAME(OPAL_DATATYPE_MYPACK_AVAILABLE, OPAL_DATATYPE_MYPACK_NOTAVAIL, \ + 0); \ } while (0) -#define OPAL_DATATYPE_MYPACK_AVAILABLE(TYPE, unused_ALIGN, NAME, unused) \ - do { \ +#define OPAL_DATATYPE_MYPACK_AVAILABLE(TYPE, unused_ALIGN, NAME, unused) \ + do { \ OPAL_DATATYPE_PACK_PREDEFINED_ELEMENT(src, dest, cando_count, stride, blocklen, TYPE); \ - success = true; \ + success = true; \ } while (0) #define OPAL_DATATYPE_MYPACK_NOTAVAIL(NAME, unused) \ - do { \ - success = false; \ + do { \ + success = false; \ } while (0) bool success = false; - switch(id) { - case OPAL_DATATYPE_INT1: - // The below macro should expand to - // OPAL_DATATYPE_PACK_PREDEFINED_ELEMENT(src, dest, cando_count, stride, blocklen, int8_t); - // by using OPAL_DATATYPE_HANDLE_* where it finds that INT1 means int8_t etc - OPAL_DATATYPE_MYPACK(INT1); - break; - case OPAL_DATATYPE_INT2: - OPAL_DATATYPE_MYPACK(INT2); - break; - case OPAL_DATATYPE_INT4: - OPAL_DATATYPE_MYPACK(INT4); - break; - case OPAL_DATATYPE_INT8: - OPAL_DATATYPE_MYPACK(INT8); - break; - case OPAL_DATATYPE_INT16: - OPAL_DATATYPE_MYPACK(INT16); - break; - case OPAL_DATATYPE_UINT1: - OPAL_DATATYPE_MYPACK(UINT1); - break; - case OPAL_DATATYPE_UINT2: - OPAL_DATATYPE_MYPACK(UINT2); - break; - case OPAL_DATATYPE_UINT4: - OPAL_DATATYPE_MYPACK(UINT4); - break; - case OPAL_DATATYPE_UINT8: - OPAL_DATATYPE_MYPACK(UINT8); - break; - case OPAL_DATATYPE_UINT16: - OPAL_DATATYPE_MYPACK(UINT16); - break; - case OPAL_DATATYPE_FLOAT2: - OPAL_DATATYPE_MYPACK(FLOAT2); - break; - case OPAL_DATATYPE_FLOAT4: - OPAL_DATATYPE_MYPACK(FLOAT4); - break; - case OPAL_DATATYPE_FLOAT8: - OPAL_DATATYPE_MYPACK(FLOAT8); - break; - case OPAL_DATATYPE_FLOAT12: - OPAL_DATATYPE_MYPACK(FLOAT12); - break; - case OPAL_DATATYPE_FLOAT16: - OPAL_DATATYPE_MYPACK(FLOAT16); - break; - case OPAL_DATATYPE_SHORT_FLOAT_COMPLEX: - OPAL_DATATYPE_MYPACK(SHORT_FLOAT_COMPLEX); - break; - case OPAL_DATATYPE_FLOAT_COMPLEX: - OPAL_DATATYPE_MYPACK(FLOAT_COMPLEX); - break; - case OPAL_DATATYPE_DOUBLE_COMPLEX: - OPAL_DATATYPE_MYPACK(DOUBLE_COMPLEX); - break; - case OPAL_DATATYPE_LONG_DOUBLE_COMPLEX: - OPAL_DATATYPE_MYPACK(LONG_DOUBLE_COMPLEX); - break; - case OPAL_DATATYPE_BOOL: - OPAL_DATATYPE_MYPACK(BOOL); - break; - case OPAL_DATATYPE_WCHAR: - OPAL_DATATYPE_MYPACK(WCHAR); - break; - default: - return OPAL_ERROR; + switch (id) { + case OPAL_DATATYPE_INT1: + // The below macro should expand to + // OPAL_DATATYPE_PACK_PREDEFINED_ELEMENT(src, dest, cando_count, stride, blocklen, int8_t); + // by using OPAL_DATATYPE_HANDLE_* where it finds that INT1 means int8_t etc + OPAL_DATATYPE_MYPACK(INT1); + break; + case OPAL_DATATYPE_INT2: + OPAL_DATATYPE_MYPACK(INT2); + break; + case OPAL_DATATYPE_INT4: + OPAL_DATATYPE_MYPACK(INT4); + break; + case OPAL_DATATYPE_INT8: + OPAL_DATATYPE_MYPACK(INT8); + break; + case OPAL_DATATYPE_INT16: + OPAL_DATATYPE_MYPACK(INT16); + break; + case OPAL_DATATYPE_UINT1: + OPAL_DATATYPE_MYPACK(UINT1); + break; + case OPAL_DATATYPE_UINT2: + OPAL_DATATYPE_MYPACK(UINT2); + break; + case OPAL_DATATYPE_UINT4: + OPAL_DATATYPE_MYPACK(UINT4); + break; + case OPAL_DATATYPE_UINT8: + OPAL_DATATYPE_MYPACK(UINT8); + break; + case OPAL_DATATYPE_UINT16: + OPAL_DATATYPE_MYPACK(UINT16); + break; + case OPAL_DATATYPE_FLOAT2: + OPAL_DATATYPE_MYPACK(FLOAT2); + break; + case OPAL_DATATYPE_FLOAT4: + OPAL_DATATYPE_MYPACK(FLOAT4); + break; + case OPAL_DATATYPE_FLOAT8: + OPAL_DATATYPE_MYPACK(FLOAT8); + break; + case OPAL_DATATYPE_FLOAT12: + OPAL_DATATYPE_MYPACK(FLOAT12); + break; + case OPAL_DATATYPE_FLOAT16: + OPAL_DATATYPE_MYPACK(FLOAT16); + break; + case OPAL_DATATYPE_SHORT_FLOAT_COMPLEX: + OPAL_DATATYPE_MYPACK(SHORT_FLOAT_COMPLEX); + break; + case OPAL_DATATYPE_FLOAT_COMPLEX: + OPAL_DATATYPE_MYPACK(FLOAT_COMPLEX); + break; + case OPAL_DATATYPE_DOUBLE_COMPLEX: + OPAL_DATATYPE_MYPACK(DOUBLE_COMPLEX); + break; + case OPAL_DATATYPE_LONG_DOUBLE_COMPLEX: + OPAL_DATATYPE_MYPACK(LONG_DOUBLE_COMPLEX); + break; + case OPAL_DATATYPE_BOOL: + OPAL_DATATYPE_MYPACK(BOOL); + break; + case OPAL_DATATYPE_WCHAR: + OPAL_DATATYPE_MYPACK(WCHAR); + break; + default: + return OPAL_ERROR; } if (!success) { return OPAL_ERROR; } - *rtn_src = src; + *rtn_src = src; *rtn_dest = dest; return OPAL_SUCCESS; } diff --git a/opal/datatype/opal_datatype_position.c b/opal/datatype/opal_datatype_position.c index 6dc38e4ff4a..0c965b89040 100644 --- a/opal/datatype/opal_datatype_position.c +++ b/opal/datatype/opal_datatype_position.c @@ -26,17 +26,20 @@ #include #include -#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_convertor.h" +#include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" -#define DO_DEBUG(INST) if( opal_ddt_position_debug ) { INST } +# define DO_DEBUG(INST) \ + if (opal_ddt_position_debug) { \ + INST \ + } #else -#define DO_DEBUG(INST) -#endif /* OPAL_ENABLE_DEBUG */ +# define DO_DEBUG(INST) +#endif /* OPAL_ENABLE_DEBUG */ /* The pack/unpack functions need a cleanup. I have to create a proper interface to access * all basic functionalities, hence using them as basic blocks for all conversion functions. @@ -44,75 +47,76 @@ * But first let's make some global assumptions: * - a datatype (with the flag DT_DATA set) will have the contiguous flags set if and only if * the data is really contiguous (extent equal with size) - * - for the OPAL_DATATYPE_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop is - * contiguous but with a gap in the begining or at the end. + * - for the OPAL_DATATYPE_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop + * is contiguous but with a gap in the begining or at the end. * - the DT_CONTIGUOUS flag for the type OPAL_DATATYPE_END_LOOP is meaningless. */ -static inline void -position_single_block(opal_convertor_t* CONVERTOR, - unsigned char** mem, ptrdiff_t mem_update, - size_t* space, size_t space_update, - size_t* cnt, size_t cnt_update) +static inline void position_single_block(opal_convertor_t *CONVERTOR, unsigned char **mem, + ptrdiff_t mem_update, size_t *space, size_t space_update, + size_t *cnt, size_t cnt_update) { - OPAL_DATATYPE_SAFEGUARD_POINTER( *mem, mem_update, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "position( %p, %lu ) => space %lu [prolog]\n", - (void*)*mem, (unsigned long)space_update, (unsigned long)(*space) ); ); - *mem += mem_update; + OPAL_DATATYPE_SAFEGUARD_POINTER(*mem, mem_update, (CONVERTOR)->pBaseBuf, (CONVERTOR)->pDesc, + (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "position( %p, %lu ) => space %lu [prolog]\n", (void *) *mem, + (unsigned long) space_update, (unsigned long) (*space));); + *mem += mem_update; *space -= space_update; - *cnt -= cnt_update; + *cnt -= cnt_update; } /** * Advance the convertors' position according. Update the pointer and the remaining space * accordingly. */ -static inline void -position_predefined_data( opal_convertor_t* CONVERTOR, - dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** POINTER, - size_t* SPACE ) +static inline void position_predefined_data(opal_convertor_t *CONVERTOR, dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **POINTER, size_t *SPACE) { - const ddt_elem_desc_t* _elem = &((ELEM)->elem); - size_t total_count = (size_t)_elem->count * _elem->blocklen; + const ddt_elem_desc_t *_elem = &((ELEM)->elem); + size_t total_count = (size_t) _elem->count * _elem->blocklen; size_t cando_count = (*SPACE) / opal_datatype_basicDatatypes[_elem->common.type]->size; size_t do_now, do_now_bytes = opal_datatype_basicDatatypes[_elem->common.type]->size; - unsigned char* _memory = (*POINTER) + _elem->disp; + unsigned char *_memory = (*POINTER) + _elem->disp; - assert( *(COUNT) <= ((size_t)_elem->count * _elem->blocklen) ); + assert(*(COUNT) <= ((size_t) _elem->count * _elem->blocklen)); - if( cando_count > *(COUNT) ) + if (cando_count > *(COUNT)) { cando_count = *(COUNT); + } - if( 1 == _elem->blocklen ) { - DO_DEBUG( opal_output( 0, "position( %p, %" PRIsize_t " ) x (count %" PRIsize_t ", extent %ld) => space %lu [prolog]\n", - (void*)_memory, (unsigned long)do_now_bytes, cando_count, _elem->extent, (unsigned long)(*SPACE) ); ); - _memory += cando_count * _elem->extent; - *SPACE -= cando_count * do_now_bytes; - *COUNT -= cando_count; + if (1 == _elem->blocklen) { + DO_DEBUG(opal_output(0, + "position( %p, %" PRIsize_t " ) x (count %" PRIsize_t + ", extent %ld) => space %lu [prolog]\n", + (void *) _memory, (unsigned long) do_now_bytes, cando_count, + _elem->extent, (unsigned long) (*SPACE));); + _memory += cando_count * _elem->extent; + *SPACE -= cando_count * do_now_bytes; + *COUNT -= cando_count; goto update_and_return; } /** * First check if we already did something on this element ? */ - do_now = (total_count - *(COUNT)); /* done elements */ - if( 0 != do_now ) { - do_now = do_now % _elem->blocklen; /* partial blocklen? */ + do_now = (total_count - *(COUNT)); /* done elements */ + if (0 != do_now) { + do_now = do_now % _elem->blocklen; /* partial blocklen? */ - if( 0 != do_now ) { - size_t left_in_block = _elem->blocklen - do_now; /* left in the current blocklen */ - do_now = (left_in_block > cando_count ) ? cando_count : left_in_block; + if (0 != do_now) { + size_t left_in_block = _elem->blocklen - do_now; /* left in the current blocklen */ + do_now = (left_in_block > cando_count) ? cando_count : left_in_block; do_now_bytes = do_now * opal_datatype_basicDatatypes[_elem->common.type]->size; - position_single_block( CONVERTOR, &_memory, do_now_bytes, - SPACE, do_now_bytes, COUNT, do_now ); + position_single_block(CONVERTOR, &_memory, do_now_bytes, SPACE, do_now_bytes, COUNT, + do_now); /* compensate if we just completed a blocklen */ - if( do_now == left_in_block ) - _memory += _elem->extent - (_elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size); + if (do_now == left_in_block) { + _memory += _elem->extent + - (_elem->blocklen + * opal_datatype_basicDatatypes[_elem->common.type]->size); + } cando_count -= do_now; } } @@ -121,49 +125,49 @@ position_predefined_data( opal_convertor_t* CONVERTOR, * Compute how many full blocklen we need to do and do them. */ do_now = cando_count / _elem->blocklen; - if( 0 != do_now ) { + if (0 != do_now) { do_now_bytes = _elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size; #if OPAL_ENABLE_DEBUG - for(size_t _i = 0; _i < do_now; _i++ ) { - position_single_block( CONVERTOR, &_memory, _elem->extent, - SPACE, do_now_bytes, COUNT, _elem->blocklen ); + for (size_t _i = 0; _i < do_now; _i++) { + position_single_block(CONVERTOR, &_memory, _elem->extent, SPACE, do_now_bytes, COUNT, + _elem->blocklen); cando_count -= _elem->blocklen; } #else - _memory += do_now * _elem->extent; - *SPACE -= do_now * do_now_bytes; - *COUNT -= do_now * _elem->blocklen; + _memory += do_now * _elem->extent; + *SPACE -= do_now * do_now_bytes; + *COUNT -= do_now * _elem->blocklen; cando_count -= do_now * _elem->blocklen; -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ } /** * As an epilog do anything left from the last blocklen. */ do_now = cando_count; - if( 0 != do_now ) { + if (0 != do_now) { do_now_bytes = do_now * opal_datatype_basicDatatypes[_elem->common.type]->size; - position_single_block( CONVERTOR, &_memory, do_now_bytes, - SPACE, do_now_bytes, COUNT, do_now ); + position_single_block(CONVERTOR, &_memory, do_now_bytes, SPACE, do_now_bytes, COUNT, + do_now); } - update_and_return: - *(POINTER) = _memory - _elem->disp; +update_and_return: + *(POINTER) = _memory - _elem->disp; } -int opal_convertor_generic_simple_position( opal_convertor_t* pConvertor, - size_t* position ) +int opal_convertor_generic_simple_position(opal_convertor_t *pConvertor, size_t *position) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - size_t count_desc; /* the number of items already done in the actual pos_desc */ + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + size_t count_desc; /* the number of items already done in the actual pos_desc */ size_t iov_len_local; - dt_elem_desc_t* description = pConvertor->use_desc->desc; - dt_elem_desc_t* pElem; /* current position */ + dt_elem_desc_t *description = pConvertor->use_desc->desc; + dt_elem_desc_t *pElem; /* current position */ unsigned char *base_pointer = pConvertor->pBaseBuf; ptrdiff_t extent = pConvertor->pDesc->ub - pConvertor->pDesc->lb; - DUMP( "opal_convertor_generic_simple_position( %p, &%ld )\n", (void*)pConvertor, (long)*position ); + DUMP("opal_convertor_generic_simple_position( %p, &%ld )\n", (void *) pConvertor, + (long) *position); assert(*position > pConvertor->bConverted); /* We dont want to have to parse the datatype multiple times. What we are interested in @@ -172,42 +176,50 @@ int opal_convertor_generic_simple_position( opal_convertor_t* pConvertor, * The only problem is that we have to modify all the elements on the stack. */ iov_len_local = *position - pConvertor->bConverted; - if( iov_len_local > pConvertor->pDesc->size ) { - pStack = pConvertor->pStack; /* we're working with the full stack */ + if (iov_len_local > pConvertor->pDesc->size) { + pStack = pConvertor->pStack; /* we're working with the full stack */ count_desc = iov_len_local / pConvertor->pDesc->size; - DO_DEBUG( opal_output( 0, "position before %lu asked %lu data size %lu" - " iov_len_local %lu count_desc %" PRIsize_t "\n", - (unsigned long)pConvertor->bConverted, (unsigned long)*position, (unsigned long)pConvertor->pDesc->size, - (unsigned long)iov_len_local, count_desc ); ); + DO_DEBUG(opal_output(0, + "position before %lu asked %lu data size %lu" + " iov_len_local %lu count_desc %" PRIsize_t "\n", + (unsigned long) pConvertor->bConverted, (unsigned long) *position, + (unsigned long) pConvertor->pDesc->size, (unsigned long) iov_len_local, + count_desc);); /* Update all the stack including the last one */ - for( pos_desc = 0; pos_desc <= pConvertor->stack_pos; pos_desc++ ) + for (pos_desc = 0; pos_desc <= pConvertor->stack_pos; pos_desc++) { pStack[pos_desc].disp += count_desc * extent; + } pConvertor->bConverted += count_desc * pConvertor->pDesc->size; iov_len_local = *position - pConvertor->bConverted; pStack[0].count -= count_desc; - DO_DEBUG( opal_output( 0, "after bConverted %lu remaining count %lu iov_len_local %lu\n", - (unsigned long)pConvertor->bConverted, (unsigned long)pStack[0].count, (unsigned long)iov_len_local ); ); + DO_DEBUG(opal_output(0, "after bConverted %lu remaining count %lu iov_len_local %lu\n", + (unsigned long) pConvertor->bConverted, + (unsigned long) pStack[0].count, (unsigned long) iov_len_local);); } pStack = pConvertor->pStack + pConvertor->stack_pos; - pos_desc = pStack->index; + pos_desc = pStack->index; base_pointer += pStack->disp; - count_desc = pStack->count; + count_desc = pStack->count; pStack--; pConvertor->stack_pos--; pElem = &(description[pos_desc]); - DO_DEBUG( opal_output( 0, "position start pos_desc %d count_desc %" PRIsize_t " disp %llx\n" - "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %llx\n", - pos_desc, count_desc, (unsigned long long)(base_pointer - pConvertor->pBaseBuf), - pConvertor->stack_pos, pStack->index, pStack->count, (unsigned long long)pStack->disp ); ); + DO_DEBUG(opal_output(0, + "position start pos_desc %d count_desc %" PRIsize_t " disp %llx\n" + "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %llx\n", + pos_desc, count_desc, + (unsigned long long) (base_pointer - pConvertor->pBaseBuf), + pConvertor->stack_pos, pStack->index, pStack->count, + (unsigned long long) pStack->disp);); /* Last data has been only partially converted. Compute the relative position */ - if( 0 != pConvertor->partial_length ) { + if (0 != pConvertor->partial_length) { size_t element_length = opal_datatype_basicDatatypes[pElem->elem.common.type]->size; size_t missing_length = element_length - pConvertor->partial_length; - if( missing_length >= iov_len_local ) { - pConvertor->partial_length = (pConvertor->partial_length + iov_len_local) % element_length; - pConvertor->bConverted += iov_len_local; + if (missing_length >= iov_len_local) { + pConvertor->partial_length = (pConvertor->partial_length + iov_len_local) + % element_length; + pConvertor->bConverted += iov_len_local; assert(pConvertor->partial_length < element_length); return 0; } @@ -216,89 +228,101 @@ int opal_convertor_generic_simple_position( opal_convertor_t* pConvertor, iov_len_local -= missing_length; count_desc--; } - while( 1 ) { - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the the entire datatype */ - DO_DEBUG( opal_output( 0, "position end_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %lx space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( pConvertor->stack_pos == 0 ) { + while (1) { + if (OPAL_DATATYPE_END_LOOP + == pElem->elem.common.type) { /* end of the the entire datatype */ + DO_DEBUG(opal_output(0, + "position end_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %lx space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); + if (--(pStack->count) == 0) { /* end of loop */ + if (pConvertor->stack_pos == 0) { pConvertor->flags |= CONVERTOR_COMPLETED; - goto complete_loop; /* completed */ + goto complete_loop; /* completed */ } pConvertor->stack_pos--; pStack--; pos_desc++; } else { - if( pStack->index == -1 ) { + if (pStack->index == -1) { pStack->disp += extent; - pos_desc = 0; /* back to the first element */ + pos_desc = 0; /* back to the first element */ } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); pStack->disp += description[pStack->index].loop.extent; - pos_desc = pStack->index; /* go back to the loop start itself to give a chance - * to move forward by entire loops */ + pos_desc = pStack->index; /* go back to the loop start itself to give a chance + * to move forward by entire loops */ } } base_pointer = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "position new_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %lx space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "position new_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %lx space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - ptrdiff_t local_disp = (ptrdiff_t)base_pointer; - ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)(pElem + pElem->loop.items); + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + ptrdiff_t local_disp = (ptrdiff_t) base_pointer; + ddt_endloop_desc_t *end_loop = (ddt_endloop_desc_t *) (pElem + pElem->loop.items); size_t full_loops = iov_len_local / end_loop->size; full_loops = count_desc <= full_loops ? count_desc : full_loops; - if( full_loops ) { - base_pointer += full_loops * pElem->loop.extent; + if (full_loops) { + base_pointer += full_loops * pElem->loop.extent; iov_len_local -= full_loops * end_loop->size; - count_desc -= full_loops; + count_desc -= full_loops; - if( 0 == count_desc ) { /* completed */ + if (0 == count_desc) { /* completed */ pos_desc += pElem->loop.items + 1; goto update_loop_description; } /* Save the stack with the correct last_count value. */ } - local_disp = (ptrdiff_t)base_pointer - local_disp; - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp + local_disp ); + local_disp = (ptrdiff_t) base_pointer - local_disp; + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp + local_disp); pos_desc++; - update_loop_description: /* update the current state */ + update_loop_description: /* update the current state */ base_pointer = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" ); - DO_DEBUG( opal_output( 0, "position set loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %lx space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop"); + DO_DEBUG(opal_output(0, + "position set loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %lx space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); continue; } - while( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ - position_predefined_data( pConvertor, pElem, &count_desc, &base_pointer, &iov_len_local ); - if( 0 != count_desc ) { /* completed */ + position_predefined_data(pConvertor, pElem, &count_desc, &base_pointer, &iov_len_local); + if (0 != count_desc) { /* completed */ pConvertor->partial_length = iov_len_local; goto complete_loop; } base_pointer = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "position set loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %lx space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "position set loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %lx space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); } } - complete_loop: - pConvertor->bConverted = *position; /* update the already converted bytes */ +complete_loop: + pConvertor->bConverted = *position; /* update the already converted bytes */ - if( !(pConvertor->flags & CONVERTOR_COMPLETED) ) { + if (!(pConvertor->flags & CONVERTOR_COMPLETED)) { /* I complete an element, next step I should go to the next one */ - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, - base_pointer - pConvertor->pBaseBuf ); - DO_DEBUG( opal_output( 0, "position save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %llx\n", - pConvertor->stack_pos, pStack->index, pStack->count, (unsigned long long)pStack->disp ); ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, + base_pointer - pConvertor->pBaseBuf); + DO_DEBUG(opal_output(0, + "position save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %llx\n", + pConvertor->stack_pos, pStack->index, pStack->count, + (unsigned long long) pStack->disp);); return 0; } return 1; diff --git a/opal/datatype/opal_datatype_prototypes.h b/opal/datatype/opal_datatype_prototypes.h index 668397112b8..4a0e1188bd2 100644 --- a/opal/datatype/opal_datatype_prototypes.h +++ b/opal/datatype/opal_datatype_prototypes.h @@ -16,74 +16,45 @@ #include "opal_config.h" - BEGIN_C_DECLS /* * First the public ones */ -OPAL_DECLSPEC int32_t -opal_pack_general( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -OPAL_DECLSPEC int32_t -opal_pack_general_checksum( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -OPAL_DECLSPEC int32_t -opal_unpack_general( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -OPAL_DECLSPEC int32_t -opal_unpack_general_checksum( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); +OPAL_DECLSPEC int32_t opal_pack_general(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +OPAL_DECLSPEC int32_t opal_pack_general_checksum(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +OPAL_DECLSPEC int32_t opal_unpack_general(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +OPAL_DECLSPEC int32_t opal_unpack_general_checksum(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); /* * Now the internal functions */ -int32_t -opal_pack_homogeneous_contig( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_pack_homogeneous_contig_checksum( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_pack_homogeneous_contig_with_gaps( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_pack_homogeneous_contig_with_gaps_checksum( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_generic_simple_pack( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_generic_simple_pack_checksum( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_unpack_homogeneous_contig( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_unpack_homogeneous_contig_checksum( opal_convertor_t* pConv, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_generic_simple_unpack( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); -int32_t -opal_generic_simple_unpack_checksum( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ); +int32_t opal_pack_homogeneous_contig(opal_convertor_t *pConv, struct iovec *iov, uint32_t *out_size, + size_t *max_data); +int32_t opal_pack_homogeneous_contig_checksum(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_pack_homogeneous_contig_with_gaps(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_pack_homogeneous_contig_with_gaps_checksum(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_generic_simple_pack(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_generic_simple_pack_checksum(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_unpack_homogeneous_contig(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_unpack_homogeneous_contig_checksum(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_generic_simple_unpack(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); +int32_t opal_generic_simple_unpack_checksum(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data); END_C_DECLS -#endif /* OPAL_DATATYPE_PROTOTYPES_H_HAS_BEEN_INCLUDED */ +#endif /* OPAL_DATATYPE_PROTOTYPES_H_HAS_BEEN_INCLUDED */ diff --git a/opal/datatype/opal_datatype_resize.c b/opal/datatype/opal_datatype_resize.c index 81b3c414243..fa9a2d794bc 100644 --- a/opal/datatype/opal_datatype_resize.c +++ b/opal/datatype/opal_datatype_resize.c @@ -19,7 +19,7 @@ #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -int32_t opal_datatype_resize( opal_datatype_t* type, ptrdiff_t lb, ptrdiff_t extent ) +int32_t opal_datatype_resize(opal_datatype_t *type, ptrdiff_t lb, ptrdiff_t extent) { type->lb = lb; type->ub = lb + extent; @@ -27,8 +27,7 @@ int32_t opal_datatype_resize( opal_datatype_t* type, ptrdiff_t lb, ptrdiff_t ext type->flags &= ~OPAL_DATATYPE_FLAG_NO_GAPS; type->flags |= OPAL_DATATYPE_FLAG_USER_LB; type->flags |= OPAL_DATATYPE_FLAG_USER_UB; - if( (extent == (ptrdiff_t)type->size) && - (type->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) { + if ((extent == (ptrdiff_t) type->size) && (type->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS)) { type->flags |= OPAL_DATATYPE_FLAG_NO_GAPS; } return OPAL_SUCCESS; diff --git a/opal/datatype/opal_datatype_unpack.c b/opal/datatype/opal_datatype_unpack.c index 6f9fdce2774..7ac93582d9d 100644 --- a/opal/datatype/opal_datatype_unpack.c +++ b/opal/datatype/opal_datatype_unpack.c @@ -31,27 +31,29 @@ #include "opal/datatype/opal_datatype_internal.h" #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" -#define DO_DEBUG(INST) if( opal_ddt_unpack_debug ) { INST } +# define DO_DEBUG(INST) \ + if (opal_ddt_unpack_debug) { \ + INST \ + } #else -#define DO_DEBUG(INST) -#endif /* OPAL_ENABLE_DEBUG */ +# define DO_DEBUG(INST) +#endif /* OPAL_ENABLE_DEBUG */ #include "opal/datatype/opal_datatype_checksum.h" -#include "opal/datatype/opal_datatype_unpack.h" #include "opal/datatype/opal_datatype_prototypes.h" +#include "opal/datatype/opal_datatype_unpack.h" #if defined(CHECKSUM) -#define opal_unpack_general_function opal_unpack_general_checksum -#define opal_unpack_homogeneous_contig_function opal_unpack_homogeneous_contig_checksum -#define opal_generic_simple_unpack_function opal_generic_simple_unpack_checksum +# define opal_unpack_general_function opal_unpack_general_checksum +# define opal_unpack_homogeneous_contig_function opal_unpack_homogeneous_contig_checksum +# define opal_generic_simple_unpack_function opal_generic_simple_unpack_checksum #else -#define opal_unpack_general_function opal_unpack_general -#define opal_unpack_homogeneous_contig_function opal_unpack_homogeneous_contig -#define opal_generic_simple_unpack_function opal_generic_simple_unpack -#endif /* defined(CHECKSUM) */ - +# define opal_unpack_general_function opal_unpack_general +# define opal_unpack_homogeneous_contig_function opal_unpack_homogeneous_contig +# define opal_generic_simple_unpack_function opal_generic_simple_unpack +#endif /* defined(CHECKSUM) */ /** * This function will be used to unpack all datatypes that have the contiguous flag set. @@ -62,90 +64,101 @@ * taken in account directly in the opal_convertor_unpack function (in convertor.c) for * the homogeneous case. */ -int32_t -opal_unpack_homogeneous_contig_function( opal_convertor_t* pConv, - struct iovec* iov, - uint32_t* out_size, - size_t* max_data ) +int32_t opal_unpack_homogeneous_contig_function(opal_convertor_t *pConv, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { const opal_datatype_t *pData = pConv->pDesc; unsigned char *user_memory, *packed_buffer; uint32_t iov_idx, i; size_t remaining, initial_bytes_converted = pConv->bConverted; - dt_stack_t* stack = pConv->pStack; + dt_stack_t *stack = pConv->pStack; ptrdiff_t extent = pData->ub - pData->lb; - DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( pBaseBuf %p, iov count %d )\n", - (void*)pConv->pBaseBuf, *out_size ); ); - if( stack[1].type != opal_datatype_uint1.id ) { + DO_DEBUG(opal_output(0, "unpack_homogeneous_contig( pBaseBuf %p, iov count %d )\n", + (void *) pConv->pBaseBuf, *out_size);); + if (stack[1].type != opal_datatype_uint1.id) { stack[1].count *= opal_datatype_basicDatatypes[stack[1].type]->size; stack[1].type = opal_datatype_uint1.id; } - if( (ptrdiff_t)pData->size == extent ) { - for( iov_idx = 0; iov_idx < (*out_size); iov_idx++ ) { + if ((ptrdiff_t) pData->size == extent) { + for (iov_idx = 0; iov_idx < (*out_size); iov_idx++) { remaining = pConv->local_size - pConv->bConverted; - if( 0 == remaining ) break; /* we're done this time */ - if( remaining > iov[iov_idx].iov_len ) + if (0 == remaining) { + break; /* we're done this time */ + } + if (remaining > iov[iov_idx].iov_len) { remaining = iov[iov_idx].iov_len; + } - packed_buffer = (unsigned char*)iov[iov_idx].iov_base; + packed_buffer = (unsigned char *) iov[iov_idx].iov_base; user_memory = pConv->pBaseBuf + pData->true_lb + pConv->bConverted; /* contiguous data or basic datatype with count */ - OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, remaining, - pConv->pBaseBuf, pData, pConv->count ); - DO_DEBUG( opal_output( 0, "unpack contig [%d] dest %p src %p length %" PRIsize_t "\n", - iov_idx, (void*)user_memory, (void*)packed_buffer, remaining ); ); - MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv ); + OPAL_DATATYPE_SAFEGUARD_POINTER(user_memory, remaining, pConv->pBaseBuf, pData, + pConv->count); + DO_DEBUG(opal_output(0, "unpack contig [%d] dest %p src %p length %" PRIsize_t "\n", + iov_idx, (void *) user_memory, (void *) packed_buffer, + remaining);); + MEMCPY_CSUM(user_memory, packed_buffer, remaining, pConv); pConv->bConverted += remaining; /* how much will get unpacked this time */ } } else { - for( iov_idx = 0; iov_idx < (*out_size); iov_idx++ ) { + for (iov_idx = 0; iov_idx < (*out_size); iov_idx++) { remaining = pConv->local_size - pConv->bConverted; - if( 0 == remaining ) break; /* we're done this time */ - if( remaining > iov[iov_idx].iov_len ) + if (0 == remaining) { + break; /* we're done this time */ + } + if (remaining > iov[iov_idx].iov_len) { remaining = iov[iov_idx].iov_len; + } - packed_buffer = (unsigned char*)iov[iov_idx].iov_base; + packed_buffer = (unsigned char *) iov[iov_idx].iov_base; user_memory = pConv->pBaseBuf + pData->true_lb + stack[0].disp + stack[1].disp; pConv->bConverted += remaining; /* how much will get unpacked this time */ - for( i = 0; stack[1].count <= remaining; i++ ) { /* partial or full data */ - OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, stack[1].count, pConv->pBaseBuf, - pData, pConv->count ); - DO_DEBUG( opal_output( 0, "unpack gaps [%d] dest %p src %p length %" PRIsize_t " [%d]\n", - iov_idx, (void*)user_memory, (void*)packed_buffer, stack[1].count, i ); ); - MEMCPY_CSUM( user_memory, packed_buffer, stack[1].count, pConv ); + for (i = 0; stack[1].count <= remaining; i++) { /* partial or full data */ + OPAL_DATATYPE_SAFEGUARD_POINTER(user_memory, stack[1].count, pConv->pBaseBuf, pData, + pConv->count); + DO_DEBUG(opal_output(0, + "unpack gaps [%d] dest %p src %p length %" PRIsize_t " [%d]\n", + iov_idx, (void *) user_memory, (void *) packed_buffer, + stack[1].count, i);); + MEMCPY_CSUM(user_memory, packed_buffer, stack[1].count, pConv); packed_buffer += stack[1].count; - remaining -= stack[1].count; + remaining -= stack[1].count; stack[0].count--; stack[0].disp += extent; stack[1].count = pData->size; - stack[1].disp = 0; + stack[1].disp = 0; user_memory = pConv->pBaseBuf + pData->true_lb + stack[0].disp; } /* Copy the last bits */ - if( 0 != remaining ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, remaining, pConv->pBaseBuf, - pData, pConv->count ); - DO_DEBUG( opal_output( 0, "unpack gaps [%d] dest %p src %p length %" PRIsize_t " [epilog]\n", - iov_idx, (void*)user_memory, (void*)packed_buffer, remaining ); ); - MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv ); + if (0 != remaining) { + OPAL_DATATYPE_SAFEGUARD_POINTER(user_memory, remaining, pConv->pBaseBuf, pData, + pConv->count); + DO_DEBUG( + opal_output(0, + "unpack gaps [%d] dest %p src %p length %" PRIsize_t " [epilog]\n", + iov_idx, (void *) user_memory, (void *) packed_buffer, remaining);); + MEMCPY_CSUM(user_memory, packed_buffer, remaining, pConv); stack[1].count -= remaining; - stack[1].disp += remaining; /* keep the += in case we are copying less that the datatype size */ - assert( stack[1].count ); + stack[1].disp += remaining; /* keep the += in case we are copying less that the + datatype size */ + assert(stack[1].count); } } } *out_size = iov_idx; /* we only reach this line after the for loop succesfully complete */ *max_data = pConv->bConverted - initial_bytes_converted; - if( pConv->bConverted == pConv->local_size ) pConv->flags |= CONVERTOR_COMPLETED; - return !!(pConv->flags & CONVERTOR_COMPLETED); /* done or not */ + if (pConv->bConverted == pConv->local_size) { + pConv->flags |= CONVERTOR_COMPLETED; + } + return !!(pConv->flags & CONVERTOR_COMPLETED); /* done or not */ } /** @@ -160,49 +173,51 @@ opal_unpack_homogeneous_contig_function( opal_convertor_t* pConv, * change the content of the data (as in all conversions that require changing the size * of the exponent or mantissa). */ -static inline void -opal_unpack_partial_datatype( opal_convertor_t* pConvertor, dt_elem_desc_t* pElem, - unsigned char* partial_data, - ptrdiff_t start_position, size_t length, - unsigned char** user_buffer ) +static inline void opal_unpack_partial_datatype(opal_convertor_t *pConvertor, dt_elem_desc_t *pElem, + unsigned char *partial_data, + ptrdiff_t start_position, size_t length, + unsigned char **user_buffer) { char unused_byte = 0x7F, saved_data[16]; unsigned char temporary[16], *temporary_buffer = temporary; - unsigned char* user_data = *user_buffer + pElem->elem.disp; + unsigned char *user_data = *user_buffer + pElem->elem.disp; size_t count_desc = 1; size_t data_length = opal_datatype_basicDatatypes[pElem->elem.common.type]->size; - DO_DEBUG( opal_output( 0, "unpack partial data start %lu end %lu data_length %lu user %p\n" - "\tbConverted %lu total_length %lu count %ld\n", - (unsigned long)start_position, (unsigned long)start_position + length, (unsigned long)data_length, (void*)*user_buffer, - (unsigned long)pConvertor->bConverted, (unsigned long)pConvertor->local_size, pConvertor->count ); ); + DO_DEBUG(opal_output(0, + "unpack partial data start %lu end %lu data_length %lu user %p\n" + "\tbConverted %lu total_length %lu count %ld\n", + (unsigned long) start_position, (unsigned long) start_position + length, + (unsigned long) data_length, (void *) *user_buffer, + (unsigned long) pConvertor->bConverted, + (unsigned long) pConvertor->local_size, pConvertor->count);); /* Find a byte that is not used in the partial buffer */ - find_unused_byte: - for(size_t i = 0; i < length; i++ ) { - if( unused_byte == partial_data[i] ) { +find_unused_byte: + for (size_t i = 0; i < length; i++) { + if (unused_byte == partial_data[i]) { unused_byte--; goto find_unused_byte; } } /* Copy and fill the rest of the buffer with the unused byte */ - memset( temporary, unused_byte, data_length ); - MEMCPY( temporary + start_position, partial_data, length ); + memset(temporary, unused_byte, data_length); + MEMCPY(temporary + start_position, partial_data, length); #if OPAL_CUDA_SUPPORT /* In the case where the data is being unpacked from device memory, need to * use the special host to device memory copy. Note this code path was only * seen on large receives of noncontiguous data via buffered sends. */ - pConvertor->cbmemcpy(saved_data, user_data, data_length, pConvertor ); + pConvertor->cbmemcpy(saved_data, user_data, data_length, pConvertor); #else /* Save the content of the user memory */ - MEMCPY( saved_data, user_data, data_length ); + MEMCPY(saved_data, user_data, data_length); #endif /* Then unpack the data into the user memory */ - UNPACK_PREDEFINED_DATATYPE( pConvertor, pElem, count_desc, - temporary_buffer, *user_buffer, data_length ); + UNPACK_PREDEFINED_DATATYPE(pConvertor, pElem, count_desc, temporary_buffer, *user_buffer, + data_length); /* reload the length as it is reset by the macro */ data_length = opal_datatype_basicDatatypes[pElem->elem.common.type]->size; @@ -217,16 +232,17 @@ opal_unpack_partial_datatype( opal_convertor_t* pConvertor, dt_elem_desc_t* pEle * data via buffered sends. */ { char resaved_data[16]; - pConvertor->cbmemcpy(resaved_data, user_data, data_length, pConvertor ); - for(size_t i = 0; i < data_length; i++ ) { - if( unused_byte == resaved_data[i] ) + pConvertor->cbmemcpy(resaved_data, user_data, data_length, pConvertor); + for (size_t i = 0; i < data_length; i++) { + if (unused_byte == resaved_data[i]) pConvertor->cbmemcpy(&user_data[i], &saved_data[i], 1, pConvertor); } } #else - for(size_t i = 0; i < data_length; i++ ) { - if( unused_byte == user_data[i] ) + for (size_t i = 0; i < data_length; i++) { + if (unused_byte == user_data[i]) { user_data[i] = saved_data[i]; + } } #endif } @@ -237,28 +253,27 @@ opal_unpack_partial_datatype( opal_convertor_t* pConvertor, dt_elem_desc_t* pEle * But first let's make some global assumptions: * - a datatype (with the flag DT_DATA set) will have the contiguous flags set if and only if * the data is really contiguous (extent equal with size) - * - for the OPAL_DATATYPE_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop is - * contiguous but with a gap in the begining or at the end. + * - for the OPAL_DATATYPE_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop + * is contiguous but with a gap in the begining or at the end. * - the DT_CONTIGUOUS flag for the type OPAL_DATATYPE_END_LOOP is meaningless. */ -int32_t -opal_generic_simple_unpack_function( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ) +int32_t opal_generic_simple_unpack_function(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - size_t count_desc; /* the number of items already done in the actual pos_desc */ - size_t total_unpacked = 0; /* total size unpacked this time */ - dt_elem_desc_t* description; - dt_elem_desc_t* pElem; + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + size_t count_desc; /* the number of items already done in the actual pos_desc */ + size_t total_unpacked = 0; /* total size unpacked this time */ + dt_elem_desc_t *description; + dt_elem_desc_t *pElem; const opal_datatype_t *pData = pConvertor->pDesc; unsigned char *conv_ptr, *iov_ptr; size_t iov_len_local; uint32_t iov_count; - DO_DEBUG( opal_output( 0, "opal_convertor_generic_simple_unpack( %p, {%p, %lu}, %u )\n", - (void*)pConvertor, (void*)iov[0].iov_base, (unsigned long)iov[0].iov_len, *out_size ); ); + DO_DEBUG(opal_output(0, "opal_convertor_generic_simple_unpack( %p, {%p, %lu}, %u )\n", + (void *) pConvertor, (void *) iov[0].iov_base, + (unsigned long) iov[0].iov_len, *out_size);); description = pConvertor->use_desc->desc; @@ -266,75 +281,80 @@ opal_generic_simple_unpack_function( opal_convertor_t* pConvertor, * main while loop we will set back the source_base to the correct value. This is * due to the fact that the convertor can stop in the middle of a data with a count */ - pStack = pConvertor->pStack + pConvertor->stack_pos; - pos_desc = pStack->index; - conv_ptr = pConvertor->pBaseBuf + pStack->disp; + pStack = pConvertor->pStack + pConvertor->stack_pos; + pos_desc = pStack->index; + conv_ptr = pConvertor->pBaseBuf + pStack->disp; count_desc = pStack->count; pStack--; pConvertor->stack_pos--; pElem = &(description[pos_desc]); - DO_DEBUG( opal_output( 0, "unpack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" - "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pos_desc, count_desc, (long)(conv_ptr - pConvertor->pBaseBuf), - pConvertor->stack_pos, pStack->index, pStack->count, (long)(pStack->disp) ); ); + DO_DEBUG(opal_output(0, + "unpack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" + "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", + pos_desc, count_desc, (long) (conv_ptr - pConvertor->pBaseBuf), + pConvertor->stack_pos, pStack->index, pStack->count, + (long) (pStack->disp));); - for( iov_count = 0; iov_count < (*out_size); iov_count++ ) { + for (iov_count = 0; iov_count < (*out_size); iov_count++) { iov_ptr = (unsigned char *) iov[iov_count].iov_base; iov_len_local = iov[iov_count].iov_len; - if( 0 != pConvertor->partial_length ) { + if (0 != pConvertor->partial_length) { size_t element_length = opal_datatype_basicDatatypes[pElem->elem.common.type]->size; size_t missing_length = element_length - pConvertor->partial_length; - assert( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ); - COMPUTE_CSUM( iov_ptr, missing_length, pConvertor ); - opal_unpack_partial_datatype( pConvertor, pElem, - iov_ptr, - pConvertor->partial_length, (size_t)(element_length - pConvertor->partial_length), - &conv_ptr ); + assert(pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA); + COMPUTE_CSUM(iov_ptr, missing_length, pConvertor); + opal_unpack_partial_datatype(pConvertor, pElem, iov_ptr, pConvertor->partial_length, + (size_t)(element_length - pConvertor->partial_length), + &conv_ptr); --count_desc; - if( 0 == count_desc ) { + if (0 == count_desc) { conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); } - iov_ptr += missing_length; + iov_ptr += missing_length; iov_len_local -= missing_length; - pConvertor->partial_length = 0; /* nothing more inside */ + pConvertor->partial_length = 0; /* nothing more inside */ } - if( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { - if( ((size_t)pElem->elem.count * pElem->elem.blocklen) != count_desc ) { + if (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { + if (((size_t) pElem->elem.count * pElem->elem.blocklen) != count_desc) { /* we have a partial (less than blocklen) basic datatype */ - int rc = UNPACK_PARTIAL_BLOCKLEN( pConvertor, pElem, count_desc, - iov_ptr, conv_ptr, iov_len_local ); - if( 0 == rc ) /* not done */ + int rc = UNPACK_PARTIAL_BLOCKLEN(pConvertor, pElem, count_desc, iov_ptr, conv_ptr, + iov_len_local); + if (0 == rc) { /* not done */ goto complete_loop; - if( 0 == count_desc ) { + } + if (0 == count_desc) { conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); } } } - while( 1 ) { - while( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + while (1) { + while (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* we have a basic datatype (working on full blocks) */ - UNPACK_PREDEFINED_DATATYPE( pConvertor, pElem, count_desc, - iov_ptr, conv_ptr, iov_len_local ); - if( 0 != count_desc ) /* completed? */ + UNPACK_PREDEFINED_DATATYPE(pConvertor, pElem, count_desc, iov_ptr, conv_ptr, + iov_len_local); + if (0 != count_desc) { /* completed? */ goto complete_loop; + } conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); } - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */ - DO_DEBUG( opal_output( 0, "unpack end_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( 0 == pConvertor->stack_pos ) { + if (OPAL_DATATYPE_END_LOOP == pElem->elem.common.type) { /* end of the current loop */ + DO_DEBUG(opal_output(0, + "unpack end_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); + if (--(pStack->count) == 0) { /* end of loop */ + if (0 == pConvertor->stack_pos) { /* we're done. Force the exit of the main for loop (around iovec) */ *out_size = iov_count; goto complete_loop; @@ -344,73 +364,76 @@ opal_generic_simple_unpack_function( opal_convertor_t* pConvertor, pos_desc++; } else { pos_desc = pStack->index + 1; - if( pStack->index == -1 ) { + if (pStack->index == -1) { pStack->disp += (pData->ub - pData->lb); } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); pStack->disp += description[pStack->index].loop.extent; } } conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "unpack new_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "unpack new_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - ptrdiff_t local_disp = (ptrdiff_t)conv_ptr; - if( pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) { - UNPACK_CONTIGUOUS_LOOP( pConvertor, pElem, count_desc, - iov_ptr, conv_ptr, iov_len_local ); - if( 0 == count_desc ) { /* completed */ + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + ptrdiff_t local_disp = (ptrdiff_t) conv_ptr; + if (pElem->loop.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) { + UNPACK_CONTIGUOUS_LOOP(pConvertor, pElem, count_desc, iov_ptr, conv_ptr, + iov_len_local); + if (0 == count_desc) { /* completed */ pos_desc += pElem->loop.items + 1; goto update_loop_description; } /* Save the stack with the correct last_count value. */ } - local_disp = (ptrdiff_t)conv_ptr - local_disp; - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp + local_disp); + local_disp = (ptrdiff_t) conv_ptr - local_disp; + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp + local_disp); pos_desc++; - update_loop_description: /* update the current state */ + update_loop_description: /* update the current state */ conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop"); } } complete_loop: - assert( pElem->elem.common.type < OPAL_DATATYPE_MAX_PREDEFINED ); - if( (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) && (0 != iov_len_local) ) { - unsigned char* temp = conv_ptr; + assert(pElem->elem.common.type < OPAL_DATATYPE_MAX_PREDEFINED); + if ((pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) && (0 != iov_len_local)) { + unsigned char *temp = conv_ptr; /* We have some partial data here. Let's copy it into the convertor * and keep it hot until the next round. */ - assert( iov_len_local < opal_datatype_basicDatatypes[pElem->elem.common.type]->size ); - COMPUTE_CSUM( iov_ptr, iov_len_local, pConvertor ); + assert(iov_len_local < opal_datatype_basicDatatypes[pElem->elem.common.type]->size); + COMPUTE_CSUM(iov_ptr, iov_len_local, pConvertor); - opal_unpack_partial_datatype( pConvertor, pElem, - iov_ptr, 0, iov_len_local, - &temp ); + opal_unpack_partial_datatype(pConvertor, pElem, iov_ptr, 0, iov_len_local, &temp); pConvertor->partial_length = iov_len_local; iov_len_local = 0; } - iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ + iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ total_unpacked += iov[iov_count].iov_len; } *max_data = total_unpacked; - pConvertor->bConverted += total_unpacked; /* update the already converted bytes */ + pConvertor->bConverted += total_unpacked; /* update the already converted bytes */ *out_size = iov_count; - if( pConvertor->bConverted == pConvertor->remote_size ) { + if (pConvertor->bConverted == pConvertor->remote_size) { pConvertor->flags |= CONVERTOR_COMPLETED; return 1; } /* Save the global position for the next round */ - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, - conv_ptr - pConvertor->pBaseBuf ); - DO_DEBUG( opal_output( 0, "unpack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pConvertor->stack_pos, pStack->index, pStack->count, (long)pStack->disp ); ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, + conv_ptr - pConvertor->pBaseBuf); + DO_DEBUG(opal_output(0, + "unpack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %ld\n", + pConvertor->stack_pos, pStack->index, pStack->count, + (long) pStack->disp);); return 0; } @@ -426,29 +449,28 @@ opal_generic_simple_unpack_function( opal_convertor_t* pConvertor, * 1 if everything went fine and the data was completly converted * -1 something wrong occurs. */ -int32_t -opal_unpack_general_function( opal_convertor_t* pConvertor, - struct iovec* iov, uint32_t* out_size, - size_t* max_data ) +int32_t opal_unpack_general_function(opal_convertor_t *pConvertor, struct iovec *iov, + uint32_t *out_size, size_t *max_data) { - dt_stack_t* pStack; /* pointer to the position on the stack */ - uint32_t pos_desc; /* actual position in the description of the derived datatype */ - size_t count_desc; /* the number of items already done in the actual pos_desc */ + dt_stack_t *pStack; /* pointer to the position on the stack */ + uint32_t pos_desc; /* actual position in the description of the derived datatype */ + size_t count_desc; /* the number of items already done in the actual pos_desc */ uint16_t type = OPAL_DATATYPE_MAX_PREDEFINED; /* type at current position */ - size_t total_unpacked = 0; /* total size unpacked this time */ - dt_elem_desc_t* description; - dt_elem_desc_t* pElem; + size_t total_unpacked = 0; /* total size unpacked this time */ + dt_elem_desc_t *description; + dt_elem_desc_t *pElem; const opal_datatype_t *pData = pConvertor->pDesc; unsigned char *conv_ptr, *iov_ptr; uint32_t iov_count; size_t iov_len_local; - const opal_convertor_master_t* master = pConvertor->master; - ptrdiff_t advance; /* number of bytes that we should advance the buffer */ + const opal_convertor_master_t *master = pConvertor->master; + ptrdiff_t advance; /* number of bytes that we should advance the buffer */ size_t rc; - DO_DEBUG( opal_output( 0, "opal_convertor_general_unpack( %p, {%p, %lu}, %d )\n", - (void*)pConvertor, (void*)iov[0].iov_base, (unsigned long)iov[0].iov_len, *out_size ); ); + DO_DEBUG(opal_output(0, "opal_convertor_general_unpack( %p, {%p, %lu}, %d )\n", + (void *) pConvertor, (void *) iov[0].iov_base, + (unsigned long) iov[0].iov_len, *out_size);); description = pConvertor->use_desc->desc; @@ -456,75 +478,83 @@ opal_unpack_general_function( opal_convertor_t* pConvertor, * main while loop we will set back the source_base to the correct value. This is * due to the fact that the convertor can stop in the middle of a data with a count */ - pStack = pConvertor->pStack + pConvertor->stack_pos; - pos_desc = pStack->index; - conv_ptr = pConvertor->pBaseBuf + pStack->disp; + pStack = pConvertor->pStack + pConvertor->stack_pos; + pos_desc = pStack->index; + conv_ptr = pConvertor->pBaseBuf + pStack->disp; count_desc = pStack->count; pStack--; pConvertor->stack_pos--; pElem = &(description[pos_desc]); - DO_DEBUG( opal_output( 0, "unpack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" - "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", - pos_desc, count_desc, (long)(conv_ptr - pConvertor->pBaseBuf), - pConvertor->stack_pos, pStack->index, pStack->count, (long)(pStack->disp) ); ); + DO_DEBUG(opal_output(0, + "unpack start pos_desc %d count_desc %" PRIsize_t " disp %ld\n" + "stack_pos %d pos_desc %d count_desc %" PRIsize_t " disp %ld\n", + pos_desc, count_desc, (long) (conv_ptr - pConvertor->pBaseBuf), + pConvertor->stack_pos, pStack->index, pStack->count, + (long) (pStack->disp));); - for( iov_count = 0; iov_count < (*out_size); iov_count++ ) { + for (iov_count = 0; iov_count < (*out_size); iov_count++) { iov_ptr = (unsigned char *) iov[iov_count].iov_base; iov_len_local = iov[iov_count].iov_len; - assert( 0 == pConvertor->partial_length ); - while( 1 ) { - while( pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) { + assert(0 == pConvertor->partial_length); + while (1) { + while (pElem->elem.common.flags & OPAL_DATATYPE_FLAG_DATA) { /* now here we have a basic datatype */ type = description[pos_desc].elem.common.type; - OPAL_DATATYPE_SAFEGUARD_POINTER( conv_ptr + pElem->elem.disp, pData->size, pConvertor->pBaseBuf, - pData, pConvertor->count ); - DO_DEBUG( opal_output( 0, "unpack (%p, %ld) -> (%p:%ld, %" PRIsize_t ", %ld) type %s\n", - (void*)iov_ptr, iov_len_local, - (void*)pConvertor->pBaseBuf, conv_ptr + pElem->elem.disp - pConvertor->pBaseBuf, - count_desc, description[pos_desc].elem.extent, - opal_datatype_basicDatatypes[type]->name ); ); - rc = master->pFunctions[type]( pConvertor, count_desc, - iov_ptr, iov_len_local, opal_datatype_basicDatatypes[type]->size, - conv_ptr + pElem->elem.disp, - (pConvertor->pDesc->ub - pConvertor->pDesc->lb) * pConvertor->count, - description[pos_desc].elem.extent, &advance ); - iov_len_local -= advance; /* decrease the available space in the buffer */ - iov_ptr += advance; /* increase the pointer to the buffer */ - count_desc -= rc; /* compute leftovers */ - if( 0 == count_desc ) { /* completed */ + OPAL_DATATYPE_SAFEGUARD_POINTER(conv_ptr + pElem->elem.disp, pData->size, + pConvertor->pBaseBuf, pData, pConvertor->count); + DO_DEBUG(opal_output(0, + "unpack (%p, %ld) -> (%p:%ld, %" PRIsize_t ", %ld) type %s\n", + (void *) iov_ptr, iov_len_local, (void *) pConvertor->pBaseBuf, + conv_ptr + pElem->elem.disp - pConvertor->pBaseBuf, count_desc, + description[pos_desc].elem.extent, + opal_datatype_basicDatatypes[type]->name);); + rc = master->pFunctions[type](pConvertor, count_desc, iov_ptr, iov_len_local, + opal_datatype_basicDatatypes[type]->size, + conv_ptr + pElem->elem.disp, + (pConvertor->pDesc->ub - pConvertor->pDesc->lb) + * pConvertor->count, + description[pos_desc].elem.extent, &advance); + iov_len_local -= advance; /* decrease the available space in the buffer */ + iov_ptr += advance; /* increase the pointer to the buffer */ + count_desc -= rc; /* compute leftovers */ + if (0 == count_desc) { /* completed */ conv_ptr = pConvertor->pBaseBuf + pStack->disp; - pos_desc++; /* advance to the next data */ - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - if( 0 == iov_len_local ) goto complete_loop; /* escape if we're done */ + pos_desc++; /* advance to the next data */ + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + if (0 == iov_len_local) { + goto complete_loop; /* escape if we're done */ + } continue; } conv_ptr += rc * description[pos_desc].elem.extent; - assert( pElem->elem.common.type < OPAL_DATATYPE_MAX_PREDEFINED ); - assert( 0 == iov_len_local ); - if( 0 != iov_len_local ) { - unsigned char* temp = conv_ptr; + assert(pElem->elem.common.type < OPAL_DATATYPE_MAX_PREDEFINED); + assert(0 == iov_len_local); + if (0 != iov_len_local) { + unsigned char *temp = conv_ptr; /* We have some partial data here. Let's copy it into the convertor * and keep it hot until the next round. */ - assert( iov_len_local < opal_datatype_basicDatatypes[pElem->elem.common.type]->size ); - COMPUTE_CSUM( iov_ptr, iov_len_local, pConvertor ); + assert(iov_len_local + < opal_datatype_basicDatatypes[pElem->elem.common.type]->size); + COMPUTE_CSUM(iov_ptr, iov_len_local, pConvertor); - opal_unpack_partial_datatype( pConvertor, pElem, - iov_ptr, 0, iov_len_local, - &temp ); + opal_unpack_partial_datatype(pConvertor, pElem, iov_ptr, 0, iov_len_local, + &temp); pConvertor->partial_length = iov_len_local; iov_len_local = 0; } goto complete_loop; } - if( OPAL_DATATYPE_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */ - DO_DEBUG( opal_output( 0, "unpack end_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); - if( --(pStack->count) == 0 ) { /* end of loop */ - if( 0 == pConvertor->stack_pos ) { + if (OPAL_DATATYPE_END_LOOP == pElem->elem.common.type) { /* end of the current loop */ + DO_DEBUG(opal_output(0, + "unpack end_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); + if (--(pStack->count) == 0) { /* end of loop */ + if (0 == pConvertor->stack_pos) { /* we're done. Force the exit of the main for loop (around iovec) */ *out_size = iov_count; goto complete_loop; @@ -534,44 +564,49 @@ opal_unpack_general_function( opal_convertor_t* pConvertor, pos_desc++; } else { pos_desc = pStack->index + 1; - if( pStack->index == -1 ) { + if (pStack->index == -1) { pStack->disp += (pData->ub - pData->lb); } else { - assert( OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type ); + assert(OPAL_DATATYPE_LOOP == description[pStack->index].loop.common.type); pStack->disp += description[pStack->index].loop.extent; } } conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DO_DEBUG( opal_output( 0, "unpack new_loop count %" PRIsize_t " stack_pos %d pos_desc %d disp %ld space %lu\n", - pStack->count, pConvertor->stack_pos, pos_desc, - pStack->disp, (unsigned long)iov_len_local ); ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DO_DEBUG(opal_output(0, + "unpack new_loop count %" PRIsize_t + " stack_pos %d pos_desc %d disp %ld space %lu\n", + pStack->count, pConvertor->stack_pos, pos_desc, pStack->disp, + (unsigned long) iov_len_local);); } - if( OPAL_DATATYPE_LOOP == pElem->elem.common.type ) { - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, - pStack->disp ); + if (OPAL_DATATYPE_LOOP == pElem->elem.common.type) { + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP, count_desc, + pStack->disp); pos_desc++; conv_ptr = pConvertor->pBaseBuf + pStack->disp; - UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc ); - DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" ); + UPDATE_INTERNAL_COUNTERS(description, pos_desc, pElem, count_desc); + DDT_DUMP_STACK(pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop"); continue; } } complete_loop: - iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ + iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */ total_unpacked += iov[iov_count].iov_len; } *max_data = total_unpacked; - pConvertor->bConverted += total_unpacked; /* update the already converted bytes */ + pConvertor->bConverted += total_unpacked; /* update the already converted bytes */ *out_size = iov_count; - if( pConvertor->bConverted == pConvertor->remote_size ) { + if (pConvertor->bConverted == pConvertor->remote_size) { pConvertor->flags |= CONVERTOR_COMPLETED; return 1; } /* Save the global position for the next round */ - PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, - conv_ptr - pConvertor->pBaseBuf ); - DO_DEBUG( opal_output( 0, "unpack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t" disp %ld\n", - pConvertor->stack_pos, pStack->index, pStack->count, (long)pStack->disp ); ); + PUSH_STACK(pStack, pConvertor->stack_pos, pos_desc, pElem->elem.common.type, count_desc, + conv_ptr - pConvertor->pBaseBuf); + DO_DEBUG(opal_output(0, + "unpack save stack stack_pos %d pos_desc %d count_desc %" PRIsize_t + " disp %ld\n", + pConvertor->stack_pos, pStack->index, pStack->count, + (long) pStack->disp);); return 0; } diff --git a/opal/datatype/opal_datatype_unpack.h b/opal/datatype/opal_datatype_unpack.h index 926cd25b0ca..9ec013d54a9 100644 --- a/opal/datatype/opal_datatype_unpack.h +++ b/opal/datatype/opal_datatype_unpack.h @@ -23,33 +23,29 @@ #if !defined(CHECKSUM) && OPAL_CUDA_SUPPORT /* Make use of existing macro to do CUDA style memcpy */ -#undef MEMCPY_CSUM -#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \ - CONVERTOR->cbmemcpy( (DST), (SRC), (BLENGTH), (CONVERTOR) ) +# undef MEMCPY_CSUM +# define MEMCPY_CSUM(DST, SRC, BLENGTH, CONVERTOR) \ + CONVERTOR->cbmemcpy((DST), (SRC), (BLENGTH), (CONVERTOR)) #endif /** - * This function deals only with partial elements. The COUNT points however to the whole leftover count, - * but this function is only expected to operate on an amount less than blength, that would allow the rest - * of the pack process to handle only entire blength blocks (plus the left over). + * This function deals only with partial elements. The COUNT points however to the whole leftover + * count, but this function is only expected to operate on an amount less than blength, that would + * allow the rest of the pack process to handle only entire blength blocks (plus the left over). * * Return 1 if we are now aligned on a block, 0 otherwise. */ -static inline int -unpack_partial_blocklen( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** packed, - unsigned char** memory, - size_t* SPACE ) +static inline int unpack_partial_blocklen(opal_convertor_t *CONVERTOR, const dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **packed, + unsigned char **memory, size_t *SPACE) { - const ddt_elem_desc_t* _elem = &((ELEM)->elem); + const ddt_elem_desc_t *_elem = &((ELEM)->elem); size_t do_now_bytes = opal_datatype_basicDatatypes[_elem->common.type]->size; size_t do_now = (*COUNT); - unsigned char* _memory = (*memory) + _elem->disp; - unsigned char* _packed = *packed; + unsigned char *_memory = (*memory) + _elem->disp; + unsigned char *_packed = *packed; - assert( *(COUNT) <= ((size_t)(_elem->count * _elem->blocklen)) ); + assert(*(COUNT) <= ((size_t)(_elem->count * _elem->blocklen))); /** * First check if we already did something on this element ? The COUNT is the number @@ -57,86 +53,88 @@ unpack_partial_blocklen( opal_convertor_t* CONVERTOR, * should be manipulated in the current call (this number is instead reflected on the * SPACE). */ - if( 0 == (do_now = (*COUNT) % _elem->blocklen) ) + if (0 == (do_now = (*COUNT) % _elem->blocklen)) return 1; - size_t left_in_block = do_now; /* left in the current blocklen */ + size_t left_in_block = do_now; /* left in the current blocklen */ - if( (do_now_bytes * do_now) > *(SPACE) ) + if ((do_now_bytes * do_now) > *(SPACE)) do_now = (*SPACE) / do_now_bytes; do_now_bytes *= do_now; - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "unpack memcpy( %p, %p, %lu ) => space %lu [prolog]\n", - (void*)_memory, (void*)_packed, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE)) ); ); - MEMCPY_CSUM( _memory, _packed, do_now_bytes, (CONVERTOR) ); - *(memory) += (ptrdiff_t)do_now_bytes; - if( do_now == left_in_block ) /* compensate if completed a blocklen */ - *(memory) += _elem->extent - (_elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size); - - *(COUNT) -= do_now; - *(SPACE) -= do_now_bytes; + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, do_now_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "unpack memcpy( %p, %p, %lu ) => space %lu [prolog]\n", + (void *) _memory, (void *) _packed, (unsigned long) do_now_bytes, + (unsigned long) (*(SPACE)));); + MEMCPY_CSUM(_memory, _packed, do_now_bytes, (CONVERTOR)); + *(memory) += (ptrdiff_t) do_now_bytes; + if (do_now == left_in_block) /* compensate if completed a blocklen */ + *(memory) += _elem->extent + - (_elem->blocklen * opal_datatype_basicDatatypes[_elem->common.type]->size); + + *(COUNT) -= do_now; + *(SPACE) -= do_now_bytes; *(packed) += do_now_bytes; return (do_now == left_in_block); } -static inline void -unpack_predefined_data( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** packed, - unsigned char** memory, - size_t* SPACE ) +static inline void unpack_predefined_data(opal_convertor_t *CONVERTOR, const dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **packed, + unsigned char **memory, size_t *SPACE) { - const ddt_elem_desc_t* _elem = &((ELEM)->elem); + const ddt_elem_desc_t *_elem = &((ELEM)->elem); size_t blocklen_bytes = opal_datatype_basicDatatypes[_elem->common.type]->size; size_t cando_count = (*COUNT), do_now_bytes; - unsigned char* _memory = (*memory) + _elem->disp; - unsigned char* _packed = *packed; + unsigned char *_memory = (*memory) + _elem->disp; + unsigned char *_packed = *packed; - assert( 0 == (cando_count % _elem->blocklen) ); /* no partials here */ - assert( *(COUNT) <= ((size_t)_elem->count * _elem->blocklen) ); + assert(0 == (cando_count % _elem->blocklen)); /* no partials here */ + assert(*(COUNT) <= ((size_t) _elem->count * _elem->blocklen)); - if( (blocklen_bytes * cando_count) > *(SPACE) ) + if ((blocklen_bytes * cando_count) > *(SPACE)) cando_count = (*SPACE) / blocklen_bytes; /* premptively update the number of COUNT we will return. */ *(COUNT) -= cando_count; - if( _elem->blocklen < 9 ) { - if((!(CONVERTOR->flags & CONVERTOR_CUDA)) && OPAL_LIKELY(OPAL_SUCCESS == - opal_datatype_unpack_predefined_element(&_packed, &_memory, cando_count, _elem))) { + if (_elem->blocklen < 9) { + if ((!(CONVERTOR->flags & CONVERTOR_CUDA)) + && OPAL_LIKELY(OPAL_SUCCESS + == opal_datatype_unpack_predefined_element(&_packed, &_memory, + cando_count, _elem))) { goto update_and_return; } /* else unrecognized _elem->common.type, use the memcpy path */ } - if( 1 == _elem->blocklen ) { /* Do as many full blocklen as possible */ - for(; cando_count > 0; cando_count--) { - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "unpack memcpy( %p, %p, %lu ) => space %lu [blen = 1]\n", - (void*)_memory, (void*)_packed, (unsigned long)blocklen_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); ); - MEMCPY_CSUM( _memory, _packed, blocklen_bytes, (CONVERTOR) ); - _packed += blocklen_bytes; - _memory += _elem->extent; + if (1 == _elem->blocklen) { /* Do as many full blocklen as possible */ + for (; cando_count > 0; cando_count--) { + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "unpack memcpy( %p, %p, %lu ) => space %lu [blen = 1]\n", + (void *) _memory, (void *) _packed, (unsigned long) blocklen_bytes, + (unsigned long) (*(SPACE) - (_packed - *(packed))));); + MEMCPY_CSUM(_memory, _packed, blocklen_bytes, (CONVERTOR)); + _packed += blocklen_bytes; + _memory += _elem->extent; } goto update_and_return; } - if( (1 < _elem->count) && (_elem->blocklen <= cando_count) ) { + if ((1 < _elem->count) && (_elem->blocklen <= cando_count)) { blocklen_bytes *= _elem->blocklen; do { /* Do as many full blocklen as possible */ - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "unpack 2. memcpy( %p, %p, %lu ) => space %lu\n", - (void*)_memory, (void*)_packed, (unsigned long)blocklen_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); ); - MEMCPY_CSUM( _memory, _packed, blocklen_bytes, (CONVERTOR) ); - _packed += blocklen_bytes; - _memory += _elem->extent; + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, blocklen_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "unpack 2. memcpy( %p, %p, %lu ) => space %lu\n", + (void *) _memory, (void *) _packed, (unsigned long) blocklen_bytes, + (unsigned long) (*(SPACE) - (_packed - *(packed))));); + MEMCPY_CSUM(_memory, _packed, blocklen_bytes, (CONVERTOR)); + _packed += blocklen_bytes; + _memory += _elem->extent; cando_count -= _elem->blocklen; } while (_elem->blocklen <= cando_count); } @@ -144,70 +142,69 @@ unpack_predefined_data( opal_convertor_t* CONVERTOR, /** * As an epilog do anything left from the last blocklen. */ - if( 0 != cando_count ) { - assert( (cando_count < _elem->blocklen) || - ((1 == _elem->count) && (cando_count <= _elem->blocklen)) ); + if (0 != cando_count) { + assert((cando_count < _elem->blocklen) + || ((1 == _elem->count) && (cando_count <= _elem->blocklen))); do_now_bytes = cando_count * opal_datatype_basicDatatypes[_elem->common.type]->size; - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "unpack 3. memcpy( %p, %p, %lu ) => space %lu [epilog]\n", - (void*)_memory, (void*)_packed, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); ); - MEMCPY_CSUM( _memory, _packed, do_now_bytes, (CONVERTOR) ); - _memory += do_now_bytes; - _packed += do_now_bytes; + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, do_now_bytes, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "unpack 3. memcpy( %p, %p, %lu ) => space %lu [epilog]\n", + (void *) _memory, (void *) _packed, (unsigned long) do_now_bytes, + (unsigned long) (*(SPACE) - (_packed - *(packed))));); + MEMCPY_CSUM(_memory, _packed, do_now_bytes, (CONVERTOR)); + _memory += do_now_bytes; + _packed += do_now_bytes; } - update_and_return: - *(memory) = _memory - _elem->disp; - *(SPACE) -= (_packed - *packed); - *(packed) = _packed; +update_and_return: + *(memory) = _memory - _elem->disp; + *(SPACE) -= (_packed - *packed); + *(packed) = _packed; } -static inline void unpack_contiguous_loop( opal_convertor_t* CONVERTOR, - const dt_elem_desc_t* ELEM, - size_t* COUNT, - unsigned char** packed, - unsigned char** memory, - size_t* SPACE ) +static inline void unpack_contiguous_loop(opal_convertor_t *CONVERTOR, const dt_elem_desc_t *ELEM, + size_t *COUNT, unsigned char **packed, + unsigned char **memory, size_t *SPACE) { - const ddt_loop_desc_t *_loop = (ddt_loop_desc_t*)(ELEM); - const ddt_endloop_desc_t* _end_loop = (ddt_endloop_desc_t*)((ELEM) + _loop->items); - unsigned char* _memory = (*memory) + _end_loop->first_elem_disp; + const ddt_loop_desc_t *_loop = (ddt_loop_desc_t *) (ELEM); + const ddt_endloop_desc_t *_end_loop = (ddt_endloop_desc_t *) ((ELEM) + _loop->items); + unsigned char *_memory = (*memory) + _end_loop->first_elem_disp; size_t _copy_loops = *(COUNT); - if( (_copy_loops * _end_loop->size) > *(SPACE) ) + if ((_copy_loops * _end_loop->size) > *(SPACE)) _copy_loops = (*(SPACE) / _end_loop->size); - for(size_t _i = 0; _i < _copy_loops; _i++ ) { - OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, _end_loop->size, (CONVERTOR)->pBaseBuf, - (CONVERTOR)->pDesc, (CONVERTOR)->count ); - DO_DEBUG( opal_output( 0, "unpack 3. memcpy( %p, %p, %lu ) => space %lu\n", - (void*)_memory, (void*)*(packed), (unsigned long)_end_loop->size, (unsigned long)(*(SPACE) - _i * _end_loop->size) ); ); - MEMCPY_CSUM( _memory, *(packed), _end_loop->size, (CONVERTOR) ); + for (size_t _i = 0; _i < _copy_loops; _i++) { + OPAL_DATATYPE_SAFEGUARD_POINTER(_memory, _end_loop->size, (CONVERTOR)->pBaseBuf, + (CONVERTOR)->pDesc, (CONVERTOR)->count); + DO_DEBUG(opal_output(0, "unpack 3. memcpy( %p, %p, %lu ) => space %lu\n", (void *) _memory, + (void *) *(packed), (unsigned long) _end_loop->size, + (unsigned long) (*(SPACE) -_i * _end_loop->size));); + MEMCPY_CSUM(_memory, *(packed), _end_loop->size, (CONVERTOR)); *(packed) += _end_loop->size; - _memory += _loop->extent; + _memory += _loop->extent; } - *(memory) = _memory - _end_loop->first_elem_disp; - *(SPACE) -= _copy_loops * _end_loop->size; - *(COUNT) -= _copy_loops; + *(memory) = _memory - _end_loop->first_elem_disp; + *(SPACE) -= _copy_loops * _end_loop->size; + *(COUNT) -= _copy_loops; } -#define UNPACK_PARTIAL_BLOCKLEN( CONVERTOR, /* the convertor */ \ - ELEM, /* the basic element to be packed */ \ - COUNT, /* the number of elements */ \ - PACKED, /* the destination pointer (char*) */ \ - MEMORY, /* the source pointer (char*) */ \ - SPACE ) /* the space in the destination buffer */ \ -unpack_partial_blocklen( (CONVERTOR), (ELEM), &(COUNT), &(PACKED), &(MEMORY), &(SPACE) ) - -#define UNPACK_PREDEFINED_DATATYPE( CONVERTOR, /* the convertor */ \ - ELEM, /* the basic element to be packed */ \ - COUNT, /* the number of elements */ \ - PACKED, /* the destination pointer (char*) */ \ - MEMORY, /* the source pointer (char*) */ \ - SPACE ) /* the space in the destination buffer */ \ -unpack_predefined_data( (CONVERTOR), (ELEM), &(COUNT), &(PACKED), &(MEMORY), &(SPACE) ) - -#define UNPACK_CONTIGUOUS_LOOP( CONVERTOR, ELEM, COUNT, PACKED, MEMORY, SPACE ) \ - unpack_contiguous_loop( (CONVERTOR), (ELEM), &(COUNT), &(PACKED), &(MEMORY), &(SPACE) ) - -#endif /* OPAL_DATATYPE_UNPACK_H_HAS_BEEN_INCLUDED */ +#define UNPACK_PARTIAL_BLOCKLEN(CONVERTOR, /* the convertor */ \ + ELEM, /* the basic element to be packed */ \ + COUNT, /* the number of elements */ \ + PACKED, /* the destination pointer (char*) */ \ + MEMORY, /* the source pointer (char*) */ \ + SPACE) /* the space in the destination buffer */ \ + unpack_partial_blocklen((CONVERTOR), (ELEM), &(COUNT), &(PACKED), &(MEMORY), &(SPACE)) + +#define UNPACK_PREDEFINED_DATATYPE(CONVERTOR, /* the convertor */ \ + ELEM, /* the basic element to be packed */ \ + COUNT, /* the number of elements */ \ + PACKED, /* the destination pointer (char*) */ \ + MEMORY, /* the source pointer (char*) */ \ + SPACE) /* the space in the destination buffer */ \ + unpack_predefined_data((CONVERTOR), (ELEM), &(COUNT), &(PACKED), &(MEMORY), &(SPACE)) + +#define UNPACK_CONTIGUOUS_LOOP(CONVERTOR, ELEM, COUNT, PACKED, MEMORY, SPACE) \ + unpack_contiguous_loop((CONVERTOR), (ELEM), &(COUNT), &(PACKED), &(MEMORY), &(SPACE)) + +#endif /* OPAL_DATATYPE_UNPACK_H_HAS_BEEN_INCLUDED */ diff --git a/opal/include/opal/align.h b/opal/include/opal/align.h index ba87490f8b2..8351668bbee 100644 --- a/opal/include/opal/align.h +++ b/opal/include/opal/align.h @@ -22,25 +22,25 @@ #ifndef OPAL_ALIGN_H #define OPAL_ALIGN_H -#define OPAL_DOWN_ALIGN(x,a,t) ((x) & ~(((t)(a)-1))) -#define OPAL_DOWN_ALIGN_PTR(x,a,t) ((t)OPAL_DOWN_ALIGN((uintptr_t)x, a, uintptr_t)) -#define OPAL_ALIGN(x,a,t) (((x)+((t)(a)-1)) & ~(((t)(a)-1))) -#define OPAL_ALIGN_PTR(x,a,t) ((t)OPAL_ALIGN((uintptr_t)x, a, uintptr_t)) -#define OPAL_ALIGN_PAD_AMOUNT(x,s) ((~((uintptr_t)(x))+1) & ((uintptr_t)(s)-1)) +#define OPAL_DOWN_ALIGN(x, a, t) ((x) & ~(((t)(a) -1))) +#define OPAL_DOWN_ALIGN_PTR(x, a, t) ((t) OPAL_DOWN_ALIGN((uintptr_t) x, a, uintptr_t)) +#define OPAL_ALIGN(x, a, t) (((x) + ((t)(a) -1)) & ~(((t)(a) -1))) +#define OPAL_ALIGN_PTR(x, a, t) ((t) OPAL_ALIGN((uintptr_t) x, a, uintptr_t)) +#define OPAL_ALIGN_PAD_AMOUNT(x, s) ((~((uintptr_t)(x)) + 1) & ((uintptr_t)(s) -1)) #if __STDC_VERSION__ >= 201101L -#include -#define OPAL_ALIGN_MIN (_Alignof(max_align_t)) +# include +# define OPAL_ALIGN_MIN (_Alignof(max_align_t)) #else -#if defined(OPAL_ALIGNMENT___FLOAT128) -#define OPAL_ALIGN_MIN (OPAL_ALIGNMENT___FLOAT128) -#elif defined(OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX) -#define OPAL_ALIGN_MIN (OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX) -#elif defined (OPAL_ALIGNMENT_LONG_DOUBLE) -#define OPAL_ALIGN_MIN (OPAL_ALIGNMENT_LONG_DOUBLE) -#else -#define OPAL_ALIGN_MIN (OPAL_ALIGNMENT_DOUBLE) -#endif +# if defined(OPAL_ALIGNMENT___FLOAT128) +# define OPAL_ALIGN_MIN (OPAL_ALIGNMENT___FLOAT128) +# elif defined(OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX) +# define OPAL_ALIGN_MIN (OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX) +# elif defined(OPAL_ALIGNMENT_LONG_DOUBLE) +# define OPAL_ALIGN_MIN (OPAL_ALIGNMENT_LONG_DOUBLE) +# else +# define OPAL_ALIGN_MIN (OPAL_ALIGNMENT_DOUBLE) +# endif #endif /* __STDC_VERSION__ >= 201101L */ #endif /* OPAL_ALIGN_H */ diff --git a/opal/include/opal/constants.h b/opal/include/opal/constants.h index 9ea9d0362da..72dc75d5934 100644 --- a/opal/include/opal/constants.h +++ b/opal/include/opal/constants.h @@ -23,85 +23,85 @@ /* error codes - don't forget to update opal/rutime/opal_init.c when adding to this list */ -#define OPAL_ERR_BASE 0 /* internal use only */ +#define OPAL_ERR_BASE 0 /* internal use only */ enum { - OPAL_SUCCESS = (OPAL_ERR_BASE), + OPAL_SUCCESS = (OPAL_ERR_BASE), - OPAL_ERROR = (OPAL_ERR_BASE - 1), - OPAL_ERR_OUT_OF_RESOURCE = (OPAL_ERR_BASE - 2), /* fatal error */ - OPAL_ERR_TEMP_OUT_OF_RESOURCE = (OPAL_ERR_BASE - 3), /* try again later */ - OPAL_ERR_RESOURCE_BUSY = (OPAL_ERR_BASE - 4), - OPAL_ERR_BAD_PARAM = (OPAL_ERR_BASE - 5), /* equivalent to MPI_ERR_ARG error code */ - OPAL_ERR_FATAL = (OPAL_ERR_BASE - 6), - OPAL_ERR_NOT_IMPLEMENTED = (OPAL_ERR_BASE - 7), - OPAL_ERR_NOT_SUPPORTED = (OPAL_ERR_BASE - 8), - OPAL_ERR_INTERRUPTED = (OPAL_ERR_BASE - 9), - OPAL_ERR_WOULD_BLOCK = (OPAL_ERR_BASE - 10), - OPAL_ERR_IN_ERRNO = (OPAL_ERR_BASE - 11), - OPAL_ERR_UNREACH = (OPAL_ERR_BASE - 12), - OPAL_ERR_NOT_FOUND = (OPAL_ERR_BASE - 13), - OPAL_EXISTS = (OPAL_ERR_BASE - 14), /* indicates that the specified object already exists */ - OPAL_ERR_TIMEOUT = (OPAL_ERR_BASE - 15), - OPAL_ERR_NOT_AVAILABLE = (OPAL_ERR_BASE - 16), - OPAL_ERR_PERM = (OPAL_ERR_BASE - 17), /* no permission */ - OPAL_ERR_VALUE_OUT_OF_BOUNDS = (OPAL_ERR_BASE - 18), - OPAL_ERR_FILE_READ_FAILURE = (OPAL_ERR_BASE - 19), - OPAL_ERR_FILE_WRITE_FAILURE = (OPAL_ERR_BASE - 20), - OPAL_ERR_FILE_OPEN_FAILURE = (OPAL_ERR_BASE - 21), - OPAL_ERR_PACK_MISMATCH = (OPAL_ERR_BASE - 22), - OPAL_ERR_PACK_FAILURE = (OPAL_ERR_BASE - 23), - OPAL_ERR_UNPACK_FAILURE = (OPAL_ERR_BASE - 24), - OPAL_ERR_UNPACK_INADEQUATE_SPACE = (OPAL_ERR_BASE - 25), + OPAL_ERROR = (OPAL_ERR_BASE - 1), + OPAL_ERR_OUT_OF_RESOURCE = (OPAL_ERR_BASE - 2), /* fatal error */ + OPAL_ERR_TEMP_OUT_OF_RESOURCE = (OPAL_ERR_BASE - 3), /* try again later */ + OPAL_ERR_RESOURCE_BUSY = (OPAL_ERR_BASE - 4), + OPAL_ERR_BAD_PARAM = (OPAL_ERR_BASE - 5), /* equivalent to MPI_ERR_ARG error code */ + OPAL_ERR_FATAL = (OPAL_ERR_BASE - 6), + OPAL_ERR_NOT_IMPLEMENTED = (OPAL_ERR_BASE - 7), + OPAL_ERR_NOT_SUPPORTED = (OPAL_ERR_BASE - 8), + OPAL_ERR_INTERRUPTED = (OPAL_ERR_BASE - 9), + OPAL_ERR_WOULD_BLOCK = (OPAL_ERR_BASE - 10), + OPAL_ERR_IN_ERRNO = (OPAL_ERR_BASE - 11), + OPAL_ERR_UNREACH = (OPAL_ERR_BASE - 12), + OPAL_ERR_NOT_FOUND = (OPAL_ERR_BASE - 13), + OPAL_EXISTS = (OPAL_ERR_BASE - 14), /* indicates that the specified object already exists */ + OPAL_ERR_TIMEOUT = (OPAL_ERR_BASE - 15), + OPAL_ERR_NOT_AVAILABLE = (OPAL_ERR_BASE - 16), + OPAL_ERR_PERM = (OPAL_ERR_BASE - 17), /* no permission */ + OPAL_ERR_VALUE_OUT_OF_BOUNDS = (OPAL_ERR_BASE - 18), + OPAL_ERR_FILE_READ_FAILURE = (OPAL_ERR_BASE - 19), + OPAL_ERR_FILE_WRITE_FAILURE = (OPAL_ERR_BASE - 20), + OPAL_ERR_FILE_OPEN_FAILURE = (OPAL_ERR_BASE - 21), + OPAL_ERR_PACK_MISMATCH = (OPAL_ERR_BASE - 22), + OPAL_ERR_PACK_FAILURE = (OPAL_ERR_BASE - 23), + OPAL_ERR_UNPACK_FAILURE = (OPAL_ERR_BASE - 24), + OPAL_ERR_UNPACK_INADEQUATE_SPACE = (OPAL_ERR_BASE - 25), OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER = (OPAL_ERR_BASE - 26), - OPAL_ERR_TYPE_MISMATCH = (OPAL_ERR_BASE - 27), - OPAL_ERR_OPERATION_UNSUPPORTED = (OPAL_ERR_BASE - 28), - OPAL_ERR_UNKNOWN_DATA_TYPE = (OPAL_ERR_BASE - 29), - OPAL_ERR_BUFFER = (OPAL_ERR_BASE - 30), - OPAL_ERR_DATA_TYPE_REDEF = (OPAL_ERR_BASE - 31), - OPAL_ERR_DATA_OVERWRITE_ATTEMPT = (OPAL_ERR_BASE - 32), - OPAL_ERR_MODULE_NOT_FOUND = (OPAL_ERR_BASE - 33), - OPAL_ERR_TOPO_SLOT_LIST_NOT_SUPPORTED = (OPAL_ERR_BASE - 34), - OPAL_ERR_TOPO_SOCKET_NOT_SUPPORTED = (OPAL_ERR_BASE - 35), - OPAL_ERR_TOPO_CORE_NOT_SUPPORTED = (OPAL_ERR_BASE - 36), - OPAL_ERR_NOT_ENOUGH_SOCKETS = (OPAL_ERR_BASE - 37), - OPAL_ERR_NOT_ENOUGH_CORES = (OPAL_ERR_BASE - 38), - OPAL_ERR_INVALID_PHYS_CPU = (OPAL_ERR_BASE - 39), - OPAL_ERR_MULTIPLE_AFFINITIES = (OPAL_ERR_BASE - 40), - OPAL_ERR_SLOT_LIST_RANGE = (OPAL_ERR_BASE - 41), - OPAL_ERR_NETWORK_NOT_PARSEABLE = (OPAL_ERR_BASE - 42), - OPAL_ERR_SILENT = (OPAL_ERR_BASE - 43), - OPAL_ERR_NOT_INITIALIZED = (OPAL_ERR_BASE - 44), - OPAL_ERR_NOT_BOUND = (OPAL_ERR_BASE - 45), - OPAL_ERR_TAKE_NEXT_OPTION = (OPAL_ERR_BASE - 46), - OPAL_ERR_PROC_ENTRY_NOT_FOUND = (OPAL_ERR_BASE - 47), - OPAL_ERR_DATA_VALUE_NOT_FOUND = (OPAL_ERR_BASE - 48), - OPAL_ERR_CONNECTION_FAILED = (OPAL_ERR_BASE - 49), - OPAL_ERR_AUTHENTICATION_FAILED = (OPAL_ERR_BASE - 50), - OPAL_ERR_COMM_FAILURE = (OPAL_ERR_BASE - 51), - OPAL_ERR_SERVER_NOT_AVAIL = (OPAL_ERR_BASE - 52), - OPAL_ERR_IN_PROCESS = (OPAL_ERR_BASE - 53), + OPAL_ERR_TYPE_MISMATCH = (OPAL_ERR_BASE - 27), + OPAL_ERR_OPERATION_UNSUPPORTED = (OPAL_ERR_BASE - 28), + OPAL_ERR_UNKNOWN_DATA_TYPE = (OPAL_ERR_BASE - 29), + OPAL_ERR_BUFFER = (OPAL_ERR_BASE - 30), + OPAL_ERR_DATA_TYPE_REDEF = (OPAL_ERR_BASE - 31), + OPAL_ERR_DATA_OVERWRITE_ATTEMPT = (OPAL_ERR_BASE - 32), + OPAL_ERR_MODULE_NOT_FOUND = (OPAL_ERR_BASE - 33), + OPAL_ERR_TOPO_SLOT_LIST_NOT_SUPPORTED = (OPAL_ERR_BASE - 34), + OPAL_ERR_TOPO_SOCKET_NOT_SUPPORTED = (OPAL_ERR_BASE - 35), + OPAL_ERR_TOPO_CORE_NOT_SUPPORTED = (OPAL_ERR_BASE - 36), + OPAL_ERR_NOT_ENOUGH_SOCKETS = (OPAL_ERR_BASE - 37), + OPAL_ERR_NOT_ENOUGH_CORES = (OPAL_ERR_BASE - 38), + OPAL_ERR_INVALID_PHYS_CPU = (OPAL_ERR_BASE - 39), + OPAL_ERR_MULTIPLE_AFFINITIES = (OPAL_ERR_BASE - 40), + OPAL_ERR_SLOT_LIST_RANGE = (OPAL_ERR_BASE - 41), + OPAL_ERR_NETWORK_NOT_PARSEABLE = (OPAL_ERR_BASE - 42), + OPAL_ERR_SILENT = (OPAL_ERR_BASE - 43), + OPAL_ERR_NOT_INITIALIZED = (OPAL_ERR_BASE - 44), + OPAL_ERR_NOT_BOUND = (OPAL_ERR_BASE - 45), + OPAL_ERR_TAKE_NEXT_OPTION = (OPAL_ERR_BASE - 46), + OPAL_ERR_PROC_ENTRY_NOT_FOUND = (OPAL_ERR_BASE - 47), + OPAL_ERR_DATA_VALUE_NOT_FOUND = (OPAL_ERR_BASE - 48), + OPAL_ERR_CONNECTION_FAILED = (OPAL_ERR_BASE - 49), + OPAL_ERR_AUTHENTICATION_FAILED = (OPAL_ERR_BASE - 50), + OPAL_ERR_COMM_FAILURE = (OPAL_ERR_BASE - 51), + OPAL_ERR_SERVER_NOT_AVAIL = (OPAL_ERR_BASE - 52), + OPAL_ERR_IN_PROCESS = (OPAL_ERR_BASE - 53), /* PMIx equivalents for notification support */ - OPAL_ERR_DEBUGGER_RELEASE = (OPAL_ERR_BASE - 54), - OPAL_ERR_HANDLERS_COMPLETE = (OPAL_ERR_BASE - 55), - OPAL_ERR_PARTIAL_SUCCESS = (OPAL_ERR_BASE - 56), - OPAL_ERR_PROC_ABORTED = (OPAL_ERR_BASE - 57), - OPAL_ERR_PROC_REQUESTED_ABORT = (OPAL_ERR_BASE - 58), - OPAL_ERR_PROC_ABORTING = (OPAL_ERR_BASE - 59), - OPAL_ERR_NODE_DOWN = (OPAL_ERR_BASE - 60), - OPAL_ERR_NODE_OFFLINE = (OPAL_ERR_BASE - 61), - OPAL_ERR_JOB_TERMINATED = (OPAL_ERR_BASE - 62), - OPAL_ERR_PROC_RESTART = (OPAL_ERR_BASE - 63), - OPAL_ERR_PROC_CHECKPOINT = (OPAL_ERR_BASE - 64), - OPAL_ERR_PROC_MIGRATE = (OPAL_ERR_BASE - 65), - OPAL_ERR_EVENT_REGISTRATION = (OPAL_ERR_BASE - 66), - OPAL_ERR_HEARTBEAT_ALERT = (OPAL_ERR_BASE - 67), - OPAL_ERR_FILE_ALERT = (OPAL_ERR_BASE - 68), - OPAL_ERR_MODEL_DECLARED = (OPAL_ERR_BASE - 69), - OPAL_PMIX_LAUNCH_DIRECTIVE = (OPAL_ERR_BASE - 70), - OPAL_OPERATION_SUCCEEDED = (OPAL_ERR_BASE - 71) + OPAL_ERR_DEBUGGER_RELEASE = (OPAL_ERR_BASE - 54), + OPAL_ERR_HANDLERS_COMPLETE = (OPAL_ERR_BASE - 55), + OPAL_ERR_PARTIAL_SUCCESS = (OPAL_ERR_BASE - 56), + OPAL_ERR_PROC_ABORTED = (OPAL_ERR_BASE - 57), + OPAL_ERR_PROC_REQUESTED_ABORT = (OPAL_ERR_BASE - 58), + OPAL_ERR_PROC_ABORTING = (OPAL_ERR_BASE - 59), + OPAL_ERR_NODE_DOWN = (OPAL_ERR_BASE - 60), + OPAL_ERR_NODE_OFFLINE = (OPAL_ERR_BASE - 61), + OPAL_ERR_JOB_TERMINATED = (OPAL_ERR_BASE - 62), + OPAL_ERR_PROC_RESTART = (OPAL_ERR_BASE - 63), + OPAL_ERR_PROC_CHECKPOINT = (OPAL_ERR_BASE - 64), + OPAL_ERR_PROC_MIGRATE = (OPAL_ERR_BASE - 65), + OPAL_ERR_EVENT_REGISTRATION = (OPAL_ERR_BASE - 66), + OPAL_ERR_HEARTBEAT_ALERT = (OPAL_ERR_BASE - 67), + OPAL_ERR_FILE_ALERT = (OPAL_ERR_BASE - 68), + OPAL_ERR_MODEL_DECLARED = (OPAL_ERR_BASE - 69), + OPAL_PMIX_LAUNCH_DIRECTIVE = (OPAL_ERR_BASE - 70), + OPAL_OPERATION_SUCCEEDED = (OPAL_ERR_BASE - 71) }; -#define OPAL_ERR_MAX (OPAL_ERR_BASE - 100) +#define OPAL_ERR_MAX (OPAL_ERR_BASE - 100) #endif /* OPAL_CONSTANTS_H */ diff --git a/opal/include/opal/hash_string.h b/opal/include/opal/hash_string.h index c4af2153806..58b71a3d02e 100644 --- a/opal/include/opal/hash_string.h +++ b/opal/include/opal/hash_string.h @@ -25,24 +25,24 @@ * @param hash (OUT) Where the hash value will be stored (uint32_t) * @param length (OUT) The computed length of the string (uint32_t) */ -#define OPAL_HASH_STRLEN( str, hash, length ) \ - do { \ - register const char *_str = (str); \ - register uint32_t _hash = 0; \ - register uint32_t _len = 0; \ - \ - while( *_str ) { \ - _len++; \ - _hash += *_str++; \ - _hash += (_hash << 10); \ - _hash ^= (_hash >> 6); \ - } \ - \ - _hash += (_hash << 3); \ - _hash ^= (_hash >> 11); \ - (hash) = (_hash + (_hash << 15)); \ - (length) = _len; \ - } while(0) +#define OPAL_HASH_STRLEN(str, hash, length) \ + do { \ + register const char *_str = (str); \ + register uint32_t _hash = 0; \ + register uint32_t _len = 0; \ + \ + while (*_str) { \ + _len++; \ + _hash += *_str++; \ + _hash += (_hash << 10); \ + _hash ^= (_hash >> 6); \ + } \ + \ + _hash += (_hash << 3); \ + _hash ^= (_hash >> 11); \ + (hash) = (_hash + (_hash << 15)); \ + (length) = _len; \ + } while (0) /** * Compute the hash value @@ -50,20 +50,20 @@ * @param str (IN) The string which will be parsed (char*) * @param hash (OUT) Where the hash value will be stored (uint32_t) */ -#define OPAL_HASH_STR( str, hash ) \ - do { \ - register const char *_str = (str); \ - register uint32_t _hash = 0; \ - \ - while( *_str ) { \ - _hash += *_str++; \ - _hash += (_hash << 10); \ - _hash ^= (_hash >> 6); \ - } \ - \ - _hash += (_hash << 3); \ - _hash ^= (_hash >> 11); \ - (hash) = (_hash + (_hash << 15)); \ - } while(0) +#define OPAL_HASH_STR(str, hash) \ + do { \ + register const char *_str = (str); \ + register uint32_t _hash = 0; \ + \ + while (*_str) { \ + _hash += *_str++; \ + _hash += (_hash << 10); \ + _hash ^= (_hash >> 6); \ + } \ + \ + _hash += (_hash << 3); \ + _hash ^= (_hash >> 11); \ + (hash) = (_hash + (_hash << 15)); \ + } while (0) -#endif /* OPAL_HASH_STRING_H */ +#endif /* OPAL_HASH_STRING_H */ diff --git a/opal/include/opal/opal_portable_platform.h b/opal/include/opal/opal_portable_platform.h index 5eaa28998b3..2cbc012697d 100644 --- a/opal/include/opal/opal_portable_platform.h +++ b/opal/include/opal/opal_portable_platform.h @@ -72,126 +72,129 @@ * */ #ifndef _STRINGIFY -#define _STRINGIFY_HELPER(x) #x -#define _STRINGIFY(x) _STRINGIFY_HELPER(x) +# define _STRINGIFY_HELPER(x) # x +# define _STRINGIFY(x) _STRINGIFY_HELPER(x) #endif #if defined(__INTEL_COMPILER) # define PLATFORM_COMPILER_FAMILYNAME INTEL -# define PLATFORM_COMPILER_FAMILYID 2 +# define PLATFORM_COMPILER_FAMILYID 2 # ifdef __cplusplus -# define PLATFORM_COMPILER_INTEL_CXX 1 +# define PLATFORM_COMPILER_INTEL_CXX 1 # else -# define PLATFORM_COMPILER_INTEL_C 1 +# define PLATFORM_COMPILER_INTEL_C 1 # endif -# define _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE 19700000 /* year 1970: predates most intel products :) */ +# define _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE \ + 19700000 /* year 1970: predates most intel products :) */ # ifdef __INTEL_COMPILER_BUILD_DATE # define _PLATFORM_INTEL_COMPILER_BUILD_DATE __INTEL_COMPILER_BUILD_DATE # else # define _PLATFORM_INTEL_COMPILER_BUILD_DATE _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE # endif - /* patch number is a decimal build date: YYYYMMDD */ -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - (((((maj) * 10) | (min)) << 20) | \ - ((pat) < _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE ? \ - _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE : ((pat)-_PLATFORM_COMPILER_INTEL_MIN_BUILDDATE))) -# define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(__INTEL_COMPILER/10, __INTEL_COMPILER/100, _PLATFORM_INTEL_COMPILER_BUILD_DATE) +/* patch number is a decimal build date: YYYYMMDD */ +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) \ + (((((maj) *10) | (min)) << 20) \ + | ((pat) < _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE \ + ? _PLATFORM_COMPILER_INTEL_MIN_BUILDDATE \ + : ((pat) -_PLATFORM_COMPILER_INTEL_MIN_BUILDDATE))) +# define PLATFORM_COMPILER_VERSION \ + PLATFORM_COMPILER_VERSION_INT(__INTEL_COMPILER / 10, __INTEL_COMPILER / 100, \ + _PLATFORM_INTEL_COMPILER_BUILD_DATE) # define PLATFORM_COMPILER_VERSION_STR \ - _STRINGIFY(__INTEL_COMPILER) "." _STRINGIFY(_PLATFORM_INTEL_COMPILER_BUILD_DATE) + _STRINGIFY(__INTEL_COMPILER) "." _STRINGIFY(_PLATFORM_INTEL_COMPILER_BUILD_DATE) #elif defined(__PATHSCALE__) # define PLATFORM_COMPILER_PATHSCALE 1 # define PLATFORM_COMPILER_FAMILYNAME PATHSCALE -# define PLATFORM_COMPILER_FAMILYID 3 +# define PLATFORM_COMPILER_FAMILYID 3 # ifdef __cplusplus -# define PLATFORM_COMPILER_PATHSCALE_CXX 1 +# define PLATFORM_COMPILER_PATHSCALE_CXX 1 # else -# define PLATFORM_COMPILER_PATHSCALE_C 1 +# define PLATFORM_COMPILER_PATHSCALE_C 1 # endif # define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(__PATHCC__,__PATHCC_MINOR__,__PATHCC_PATCHLEVEL__) + PLATFORM_COMPILER_VERSION_INT(__PATHCC__, __PATHCC_MINOR__, __PATHCC_PATCHLEVEL__) # define PLATFORM_COMPILER_VERSION_STR __PATHSCALE__ #elif defined(__PGI) -# define PLATFORM_COMPILER_PGI 1 +# define PLATFORM_COMPILER_PGI 1 # define PLATFORM_COMPILER_FAMILYNAME PGI -# define PLATFORM_COMPILER_FAMILYID 4 +# define PLATFORM_COMPILER_FAMILYID 4 # ifdef __cplusplus -# define PLATFORM_COMPILER_PGI_CXX 1 +# define PLATFORM_COMPILER_PGI_CXX 1 # else -# define PLATFORM_COMPILER_PGI_C 1 +# define PLATFORM_COMPILER_PGI_C 1 # endif # if __PGIC__ == 99 - /* bug 2230: PGI versioning was broken for some platforms in 7.0 - no way to know exact version, but provide something slightly more accurate */ -# define PLATFORM_COMPILER_VERSION 0x070000 -# define PLATFORM_COMPILER_VERSION_STR "7.?-?" +/* bug 2230: PGI versioning was broken for some platforms in 7.0 + no way to know exact version, but provide something slightly more accurate */ +# define PLATFORM_COMPILER_VERSION 0x070000 +# define PLATFORM_COMPILER_VERSION_STR "7.?-?" # elif defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) -# define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(__PGIC__,__PGIC_MINOR__,__PGIC_PATCHLEVEL__) -# define PLATFORM_COMPILER_VERSION_STR \ +# define PLATFORM_COMPILER_VERSION \ + PLATFORM_COMPILER_VERSION_INT(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) +# define PLATFORM_COMPILER_VERSION_STR \ _STRINGIFY(__PGIC__) "." _STRINGIFY(__PGIC_MINOR__) "-" _STRINGIFY(__PGIC_PATCHLEVEL__) # else - /* PGI before 6.1-4 lacks any version ID preprocessor macros - so use this filthy hack */ - /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - * We cannot do these within mpi.h.in, as we should not include ompi.h - * Hopefully, compilers with integrated preprocessors will not analyse code within the #if 0-block - * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - */ -#if 0 -# ifdef PLATFORM_PGI_IS_ANCIENT +/* PGI before 6.1-4 lacks any version ID preprocessor macros - so use this filthy hack */ +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + * We cannot do these within mpi.h.in, as we should not include ompi.h + * Hopefully, compilers with integrated preprocessors will not analyse code within the #if 0-block + * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + */ +# if 0 +# ifdef PLATFORM_PGI_IS_ANCIENT /* Include below might fail for ancient versions lacking this header, but testing shows it works back to at least 5.1-3 (Nov 2003), and based on docs probably back to 3.2 (Sep 2000) */ -# define PLATFORM_COMPILER_VERSION 0 -# elif defined(__x86_64__) /* bug 1753 - 64-bit omp.h upgrade happenned in <6.0-8,6.1-1) */ -# include "omp.h" -# if defined(_PGOMP_H) +# define PLATFORM_COMPILER_VERSION 0 +# elif defined( \ + __x86_64__) /* bug 1753 - 64-bit omp.h upgrade happenned in <6.0-8,6.1-1) */ +# include "omp.h" +# if defined(_PGOMP_H) /* 6.1.1 or newer */ -# define PLATFORM_COMPILER_VERSION 0x060101 -# define PLATFORM_COMPILER_VERSION_STR ">=6.1-1" -# else +# define PLATFORM_COMPILER_VERSION 0x060101 +# define PLATFORM_COMPILER_VERSION_STR ">=6.1-1" +# else /* 6.0.8 or older */ -# define PLATFORM_COMPILER_VERSION 0 -# define PLATFORM_COMPILER_VERSION_STR "<=6.0-8" -# endif -# else /* 32-bit omp.h upgrade happenned in <5.2-4,6.0-8 */ -# include "omp.h" -# if defined(_PGOMP_H) +# define PLATFORM_COMPILER_VERSION 0 +# define PLATFORM_COMPILER_VERSION_STR "<=6.0-8" +# endif +# else /* 32-bit omp.h upgrade happenned in <5.2-4,6.0-8 */ +# include "omp.h" +# if defined(_PGOMP_H) /* 6.0-8 or newer */ -# define PLATFORM_COMPILER_VERSION 0x060008 -# define PLATFORM_COMPILER_VERSION_STR ">=6.0-8" -# else +# define PLATFORM_COMPILER_VERSION 0x060008 +# define PLATFORM_COMPILER_VERSION_STR ">=6.0-8" +# else /* 5.2-4 or older */ -# define PLATFORM_COMPILER_VERSION 0 -# define PLATFORM_COMPILER_VERSION_STR "<=5.2-4" +# define PLATFORM_COMPILER_VERSION 0 +# define PLATFORM_COMPILER_VERSION_STR "<=5.2-4" +# endif # endif -# endif -#endif /* 0 */ - /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ +# endif /* 0 */ +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ # endif #elif defined(__xlC__) || defined(__ibmxl__) || defined(__IBMC__) || defined(__IBMCPP__) -# define PLATFORM_COMPILER_XLC 1 +# define PLATFORM_COMPILER_XLC 1 # define PLATFORM_COMPILER_FAMILYNAME XLC -# define PLATFORM_COMPILER_FAMILYID 5 +# define PLATFORM_COMPILER_FAMILYID 5 # ifdef __cplusplus -# define PLATFORM_COMPILER_XLC_CXX 1 +# define PLATFORM_COMPILER_XLC_CXX 1 # else -# define PLATFORM_COMPILER_XLC_C 1 +# define PLATFORM_COMPILER_XLC_C 1 # endif -# define PLATFORM_COMPILER_VERSION __xlC__ -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - ( ((maj) << 8) | ((min) << 4) | (pat) ) +# define PLATFORM_COMPILER_VERSION __xlC__ +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) (((maj) << 8) | ((min) << 4) | (pat)) #elif defined(__DECC) || defined(__DECCXX) -# define PLATFORM_COMPILER_COMPAQ 1 +# define PLATFORM_COMPILER_COMPAQ 1 # define PLATFORM_COMPILER_FAMILYNAME COMPAQ -# define PLATFORM_COMPILER_FAMILYID 6 +# define PLATFORM_COMPILER_FAMILYID 6 # ifdef __cplusplus -# define PLATFORM_COMPILER_COMPAQ_CXX 1 +# define PLATFORM_COMPILER_COMPAQ_CXX 1 # else -# define PLATFORM_COMPILER_COMPAQ_C 1 +# define PLATFORM_COMPILER_COMPAQ_C 1 # endif # if defined(__DECC_VER) # define PLATFORM_COMPILER_VERSION __DECC_VER @@ -199,145 +202,141 @@ # define PLATFORM_COMPILER_VERSION __DECCXX_VER # endif -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - ( ((maj) * 10000000) + ((min) * 100000) + (90000) + (pat) ) - /* 90000 = official ver, 80000 = customer special ver, 60000 = field test ver */ +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) \ + (((maj) *10000000) + ((min) *100000) + (90000) + (pat)) +/* 90000 = official ver, 80000 = customer special ver, 60000 = field test ver */ #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) -# define PLATFORM_COMPILER_SUN 1 +# define PLATFORM_COMPILER_SUN 1 # define PLATFORM_COMPILER_FAMILYNAME SUN -# define PLATFORM_COMPILER_FAMILYID 7 +# define PLATFORM_COMPILER_FAMILYID 7 # ifdef __cplusplus -# define PLATFORM_COMPILER_SUN_CXX 1 +# define PLATFORM_COMPILER_SUN_CXX 1 # else -# define PLATFORM_COMPILER_SUN_C 1 +# define PLATFORM_COMPILER_SUN_C 1 # endif # if defined(__SUNPRO_C) && __SUNPRO_C > 0 # define PLATFORM_COMPILER_VERSION __SUNPRO_C # elif defined(__SUNPRO_CC) && __SUNPRO_CC > 0 # define PLATFORM_COMPILER_VERSION __SUNPRO_CC # endif -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - ( ((maj) << 8) | ((min) << 4) | (pat) ) +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) (((maj) << 8) | ((min) << 4) | (pat)) #elif defined(__HP_cc) || defined(__HP_aCC) -# define PLATFORM_COMPILER_HP 1 +# define PLATFORM_COMPILER_HP 1 # define PLATFORM_COMPILER_FAMILYNAME HP -# define PLATFORM_COMPILER_FAMILYID 8 +# define PLATFORM_COMPILER_FAMILYID 8 # ifdef __cplusplus -# define PLATFORM_COMPILER_HP_CXX 1 +# define PLATFORM_COMPILER_HP_CXX 1 # else -# define PLATFORM_COMPILER_HP_C 1 +# define PLATFORM_COMPILER_HP_C 1 # endif # if defined(__HP_cc) && __HP_cc > 0 # define PLATFORM_COMPILER_VERSION __HP_cc # elif defined(__HP_aCC) && __HP_aCC > 0 # define PLATFORM_COMPILER_VERSION __HP_aCC # endif -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - ( ((maj) << 16) | ((min) << 8) | (pat) ) +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) (((maj) << 16) | ((min) << 8) | (pat)) -#elif defined(_SGI_COMPILER_VERSION) || \ - (defined(_COMPILER_VERSION) && defined(__sgi) && !defined(__GNUC__)) /* 7.3.0 and earlier lack _SGI_COMPILER_VERSION */ -# define PLATFORM_COMPILER_SGI 1 +#elif defined(_SGI_COMPILER_VERSION) \ + || (defined(_COMPILER_VERSION) && defined(__sgi) \ + && !defined(__GNUC__)) /* 7.3.0 and earlier lack _SGI_COMPILER_VERSION */ +# define PLATFORM_COMPILER_SGI 1 # define PLATFORM_COMPILER_FAMILYNAME SGI -# define PLATFORM_COMPILER_FAMILYID 9 +# define PLATFORM_COMPILER_FAMILYID 9 # ifdef __cplusplus -# define PLATFORM_COMPILER_SGI_CXX 1 +# define PLATFORM_COMPILER_SGI_CXX 1 # else -# define PLATFORM_COMPILER_SGI_C 1 +# define PLATFORM_COMPILER_SGI_C 1 # endif # if defined(_SGI_COMPILER_VERSION) && _SGI_COMPILER_VERSION > 0 # define PLATFORM_COMPILER_VERSION _SGI_COMPILER_VERSION # elif defined(_COMPILER_VERSION) && _COMPILER_VERSION > 0 # define PLATFORM_COMPILER_VERSION _COMPILER_VERSION # endif -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - ( ((maj) << 8) | ((min) << 4) | (pat) ) +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) (((maj) << 8) | ((min) << 4) | (pat)) #elif defined(_CRAYC) -# define PLATFORM_COMPILER_CRAY 1 +# define PLATFORM_COMPILER_CRAY 1 # define PLATFORM_COMPILER_FAMILYNAME CRAY -# define PLATFORM_COMPILER_FAMILYID 10 +# define PLATFORM_COMPILER_FAMILYID 10 # ifdef __cplusplus -# define PLATFORM_COMPILER_CRAY_CXX 1 +# define PLATFORM_COMPILER_CRAY_CXX 1 # else -# define PLATFORM_COMPILER_CRAY_C 1 +# define PLATFORM_COMPILER_CRAY_C 1 # endif # if defined(_RELEASE) && defined(_RELEASE_MINOR) /* X1 and XT */ -# define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(_RELEASE,_RELEASE_MINOR,0) -# elif defined(_RELEASE) /* T3E */ -# define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(_RELEASE,0,0) -# endif -# ifdef _RELEASE_STRING /* X1 and XT */ +# define PLATFORM_COMPILER_VERSION PLATFORM_COMPILER_VERSION_INT(_RELEASE, _RELEASE_MINOR, 0) +# elif defined(_RELEASE) /* T3E */ +# define PLATFORM_COMPILER_VERSION PLATFORM_COMPILER_VERSION_INT(_RELEASE, 0, 0) +# endif +# ifdef _RELEASE_STRING /* X1 and XT */ # define PLATFORM_COMPILER_VERSION_STR _RELEASE_STRING -# endif +# endif #elif defined(__KCC) -# define PLATFORM_COMPILER_KAI 1 +# define PLATFORM_COMPILER_KAI 1 # define PLATFORM_COMPILER_FAMILYNAME KAI -# define PLATFORM_COMPILER_FAMILYID 11 +# define PLATFORM_COMPILER_FAMILYID 11 # ifdef __cplusplus -# define PLATFORM_COMPILER_KAI_CXX 1 +# define PLATFORM_COMPILER_KAI_CXX 1 # else -# define PLATFORM_COMPILER_KAI_C 1 +# define PLATFORM_COMPILER_KAI_C 1 # endif #elif defined(__MTA__) -# define PLATFORM_COMPILER_MTA 1 +# define PLATFORM_COMPILER_MTA 1 # define PLATFORM_COMPILER_FAMILYNAME MTA -# define PLATFORM_COMPILER_FAMILYID 12 +# define PLATFORM_COMPILER_FAMILYID 12 # ifdef __cplusplus -# define PLATFORM_COMPILER_MTA_CXX 1 +# define PLATFORM_COMPILER_MTA_CXX 1 # else -# define PLATFORM_COMPILER_MTA_C 1 +# define PLATFORM_COMPILER_MTA_C 1 # endif #elif defined(_SX) -# define PLATFORM_COMPILER_NECSX 1 +# define PLATFORM_COMPILER_NECSX 1 # define PLATFORM_COMPILER_FAMILYNAME NECSX -# define PLATFORM_COMPILER_FAMILYID 13 +# define PLATFORM_COMPILER_FAMILYID 13 # ifdef __cplusplus -# define PLATFORM_COMPILER_NECSX_CXX 1 +# define PLATFORM_COMPILER_NECSX_CXX 1 # else -# define PLATFORM_COMPILER_NECSX_C 1 +# define PLATFORM_COMPILER_NECSX_C 1 # endif #elif defined(_MSC_VER) # define PLATFORM_COMPILER_MICROSOFT 1 # define PLATFORM_COMPILER_FAMILYNAME MICROSOFT -# define PLATFORM_COMPILER_FAMILYID 14 +# define PLATFORM_COMPILER_FAMILYID 14 # ifdef __cplusplus -# define PLATFORM_COMPILER_MICROSOFT_CXX 1 +# define PLATFORM_COMPILER_MICROSOFT_CXX 1 # else -# define PLATFORM_COMPILER_MICROSOFT_C 1 +# define PLATFORM_COMPILER_MICROSOFT_C 1 # endif # define PLATFORM_COMPILER_VERSION _MSC_VER #elif defined(__TINYC__) -# define PLATFORM_COMPILER_TINY 1 +# define PLATFORM_COMPILER_TINY 1 # define PLATFORM_COMPILER_FAMILYNAME TINY -# define PLATFORM_COMPILER_FAMILYID 15 +# define PLATFORM_COMPILER_FAMILYID 15 # ifdef __cplusplus -# define PLATFORM_COMPILER_TINY_CXX 1 +# define PLATFORM_COMPILER_TINY_CXX 1 # else -# define PLATFORM_COMPILER_TINY_C 1 +# define PLATFORM_COMPILER_TINY_C 1 # endif #elif defined(__LCC__) -# define PLATFORM_COMPILER_LCC 1 +# define PLATFORM_COMPILER_LCC 1 # define PLATFORM_COMPILER_FAMILYNAME LCC -# define PLATFORM_COMPILER_FAMILYID 16 +# define PLATFORM_COMPILER_FAMILYID 16 # ifdef __cplusplus -# define PLATFORM_COMPILER_LCC_CXX 1 +# define PLATFORM_COMPILER_LCC_CXX 1 # else -# define PLATFORM_COMPILER_LCC_C 1 +# define PLATFORM_COMPILER_LCC_C 1 # endif #else /* unknown compiler */ -# define PLATFORM_COMPILER_UNKNOWN 1 +# define PLATFORM_COMPILER_UNKNOWN 1 #endif /* this stanza comes last, because many vendor compilers lie and claim @@ -345,42 +344,40 @@ #if defined(__GNUC__) # undef PLATFORM_COMPILER_UNKNOWN # ifndef PLATFORM_COMPILER_FAMILYID -# define PLATFORM_COMPILER_GNU 1 +# define PLATFORM_COMPILER_GNU 1 # define PLATFORM_COMPILER_FAMILYNAME GNU -# define PLATFORM_COMPILER_FAMILYID 1 +# define PLATFORM_COMPILER_FAMILYID 1 # ifdef __cplusplus -# define PLATFORM_COMPILER_GNU_CXX 1 +# define PLATFORM_COMPILER_GNU_CXX 1 # else -# define PLATFORM_COMPILER_GNU_C 1 +# define PLATFORM_COMPILER_GNU_C 1 # endif # if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) # define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) + PLATFORM_COMPILER_VERSION_INT(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) # elif defined(__GNUC_MINOR__) /* older versions of egcs lack __GNUC_PATCHLEVEL__ */ # define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(__GNUC__,__GNUC_MINOR__,0) + PLATFORM_COMPILER_VERSION_INT(__GNUC__, __GNUC_MINOR__, 0) # else -# define PLATFORM_COMPILER_VERSION \ - PLATFORM_COMPILER_VERSION_INT(__GNUC__,0,0) +# define PLATFORM_COMPILER_VERSION PLATFORM_COMPILER_VERSION_INT(__GNUC__, 0, 0) # endif # define PLATFORM_COMPILER_VERSION_STR __PLATFORM_COMPILER_GNU_VERSION_STR # else # define _PLATFORM_COMPILER_GNU_VERSION_STR __PLATFORM_COMPILER_GNU_VERSION_STR # endif - /* gather any advertised GNU version number info, even for non-gcc compilers */ +/* gather any advertised GNU version number info, even for non-gcc compilers */ # if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) # define __PLATFORM_COMPILER_GNU_VERSION_STR \ - _STRINGIFY(__GNUC__) "." _STRINGIFY(__GNUC_MINOR__) "." _STRINGIFY(__GNUC_PATCHLEVEL__) + _STRINGIFY(__GNUC__) "." _STRINGIFY(__GNUC_MINOR__) "." _STRINGIFY(__GNUC_PATCHLEVEL__) # elif defined(__GNUC_MINOR__) # define __PLATFORM_COMPILER_GNU_VERSION_STR \ - _STRINGIFY(__GNUC__) "." _STRINGIFY(__GNUC_MINOR__) ".?" + _STRINGIFY(__GNUC__) "." _STRINGIFY(__GNUC_MINOR__) ".?" # else -# define __PLATFORM_COMPILER_GNU_VERSION_STR \ - _STRINGIFY(__GNUC__) ".?.?" +# define __PLATFORM_COMPILER_GNU_VERSION_STR _STRINGIFY(__GNUC__) ".?.?" # endif #elif defined(PLATFORM_COMPILER_UNKNOWN) /* unknown compiler */ # define PLATFORM_COMPILER_FAMILYNAME UNKNOWN -# define PLATFORM_COMPILER_FAMILYID 0 +# define PLATFORM_COMPILER_FAMILYID 0 #endif /* Default Values */ @@ -393,9 +390,7 @@ #endif #ifndef PLATFORM_COMPILER_VERSION_INT -# define PLATFORM_COMPILER_VERSION_INT(maj,min,pat) \ - (((maj) << 16) | ((min) << 8) | (pat)) +# define PLATFORM_COMPILER_VERSION_INT(maj, min, pat) (((maj) << 16) | ((min) << 8) | (pat)) #endif - #endif /* OPAL_PORTABLE_PLATFORM_H */ diff --git a/opal/include/opal/opal_socket_errno.h b/opal/include/opal/opal_socket_errno.h index 1e3f346a0cb..385bf8767a4 100644 --- a/opal/include/opal/opal_socket_errno.h +++ b/opal/include/opal/opal_socket_errno.h @@ -18,8 +18,8 @@ #ifndef OPAL_GET_SOCKET_ERROR_H #define OPAL_GET_SOCKET_ERROR_H -#include #include "opal/constants.h" +#include #define opal_socket_errno errno diff --git a/opal/include/opal/prefetch.h b/opal/include/opal/prefetch.h index 059b3a023f4..a94a26ca2f7 100644 --- a/opal/include/opal/prefetch.h +++ b/opal/include/opal/prefetch.h @@ -22,36 +22,36 @@ #if defined(c_plusplus) || defined(__cplusplus) /* C++ code */ -#if OMPI_CXX_HAVE_BUILTIN_EXPECT -#define OPAL_LIKELY(expression) __builtin_expect(!!(expression), 1) -#define OPAL_UNLIKELY(expression) __builtin_expect(!!(expression), 0) -#else -#define OPAL_LIKELY(expression) (expression) -#define OPAL_UNLIKELY(expression) (expression) -#endif - -#if OMPI_CXX_HAVE_BUILTIN_PREFETCH -#define OPAL_PREFETCH(address,rw,locality) __builtin_prefetch(address,rw,locality) -#else -#define OPAL_PREFETCH(address,rw,locality) -#endif +# if OMPI_CXX_HAVE_BUILTIN_EXPECT +# define OPAL_LIKELY(expression) __builtin_expect(!!(expression), 1) +# define OPAL_UNLIKELY(expression) __builtin_expect(!!(expression), 0) +# else +# define OPAL_LIKELY(expression) (expression) +# define OPAL_UNLIKELY(expression) (expression) +# endif + +# if OMPI_CXX_HAVE_BUILTIN_PREFETCH +# define OPAL_PREFETCH(address, rw, locality) __builtin_prefetch(address, rw, locality) +# else +# define OPAL_PREFETCH(address, rw, locality) +# endif #else /* C code */ -#if OPAL_C_HAVE_BUILTIN_EXPECT -#define OPAL_LIKELY(expression) __builtin_expect(!!(expression), 1) -#define OPAL_UNLIKELY(expression) __builtin_expect(!!(expression), 0) -#else -#define OPAL_LIKELY(expression) (expression) -#define OPAL_UNLIKELY(expression) (expression) -#endif - -#if OPAL_C_HAVE_BUILTIN_PREFETCH -#define OPAL_PREFETCH(address,rw,locality) __builtin_prefetch(address,rw,locality) -#else -#define OPAL_PREFETCH(address,rw,locality) -#endif +# if OPAL_C_HAVE_BUILTIN_EXPECT +# define OPAL_LIKELY(expression) __builtin_expect(!!(expression), 1) +# define OPAL_UNLIKELY(expression) __builtin_expect(!!(expression), 0) +# else +# define OPAL_LIKELY(expression) (expression) +# define OPAL_UNLIKELY(expression) (expression) +# endif + +# if OPAL_C_HAVE_BUILTIN_PREFETCH +# define OPAL_PREFETCH(address, rw, locality) __builtin_prefetch(address, rw, locality) +# else +# define OPAL_PREFETCH(address, rw, locality) +# endif #endif diff --git a/opal/include/opal/sys/architecture.h b/opal/include/opal/sys/architecture.h index 38338f1ecb2..35e7cad7886 100644 --- a/opal/include/opal/sys/architecture.h +++ b/opal/include/opal/sys/architecture.h @@ -31,18 +31,18 @@ #define OPAL_SYS_ARCHITECTURE_H /* Architectures */ -#define OPAL_UNSUPPORTED 0000 -#define OPAL_IA32 0010 -#define OPAL_X86_64 0030 -#define OPAL_POWERPC32 0050 -#define OPAL_POWERPC64 0051 -#define OPAL_ARM 0100 -#define OPAL_ARM64 0101 -#define OPAL_BUILTIN_GCC 0202 -#define OPAL_BUILTIN_NO 0203 -#define OPAL_BUILTIN_C11 0204 +#define OPAL_UNSUPPORTED 0000 +#define OPAL_IA32 0010 +#define OPAL_X86_64 0030 +#define OPAL_POWERPC32 0050 +#define OPAL_POWERPC64 0051 +#define OPAL_ARM 0100 +#define OPAL_ARM64 0101 +#define OPAL_BUILTIN_GCC 0202 +#define OPAL_BUILTIN_NO 0203 +#define OPAL_BUILTIN_C11 0204 /* Formats */ -#define OPAL_DEFAULT 1000 /* standard for given architecture */ +#define OPAL_DEFAULT 1000 /* standard for given architecture */ #endif /* #ifndef OPAL_SYS_ARCHITECTURE_H */ diff --git a/opal/include/opal/sys/arm/atomic.h b/opal/include/opal/sys/arm/atomic.h index ff2c5bab351..f6707e2c2e4 100644 --- a/opal/include/opal/sys/arm/atomic.h +++ b/opal/include/opal/sys/arm/atomic.h @@ -36,30 +36,30 @@ #if (OPAL_ASM_ARM_VERSION >= 7) -#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 +# define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 /* use the DMB instruction if available... */ -#define MB() __asm__ __volatile__ ("dmb" : : : "memory") -#define RMB() __asm__ __volatile__ ("dmb" : : : "memory") -#define WMB() __asm__ __volatile__ ("dmb" : : : "memory") +# define MB() __asm__ __volatile__("dmb" : : : "memory") +# define RMB() __asm__ __volatile__("dmb" : : : "memory") +# define WMB() __asm__ __volatile__("dmb" : : : "memory") #elif (OPAL_ASM_ARM_VERSION == 6) -#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 +# define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 /* ...or the v6-specific equivalent... */ -#define MB() __asm__ __volatile__ ("mcr p15, 0, r0, c7, c10, 5" : : : "memory") -#define RMB() MB() -#define WMB() MB() +# define MB() __asm__ __volatile__("mcr p15, 0, r0, c7, c10, 5" : : : "memory") +# define RMB() MB() +# define WMB() MB() #else -#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 +# define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 /* ...otherwise use the Linux kernel-provided barrier */ -#define MB() (*((void (*)(void))(0xffff0fa0)))() -#define RMB() MB() -#define WMB() MB() +# define MB() (*((void (*)(void))(0xffff0fa0)))() +# define RMB() MB() +# define WMB() MB() #endif @@ -71,34 +71,27 @@ #if (OPAL_HAVE_ATOMIC_MEM_BARRIER == 1) -static inline -void opal_atomic_mb(void) +static inline void opal_atomic_mb(void) { MB(); } - -static inline -void opal_atomic_rmb(void) +static inline void opal_atomic_rmb(void) { RMB(); } - -static inline -void opal_atomic_wmb(void) +static inline void opal_atomic_wmb(void) { WMB(); } -static inline -void opal_atomic_isync(void) +static inline void opal_atomic_isync(void) { } #endif - /********************************************************************** * * Atomic math operations @@ -107,15 +100,15 @@ void opal_atomic_isync(void) #if (OPAL_GCC_INLINE_ASSEMBLY && (OPAL_ASM_ARM_VERSION >= 6)) -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 -#define OPAL_HAVE_ATOMIC_MATH_32 1 -static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 +# define OPAL_HAVE_ATOMIC_MATH_32 1 +static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { - int32_t prev, tmp; - bool ret; + int32_t prev, tmp; + bool ret; - __asm__ __volatile__ ( - "1: ldrex %0, [%2] \n" + __asm__ __volatile__("1: ldrex %0, [%2] \n" " cmp %0, %3 \n" " bne 2f \n" " strex %1, %4, [%2] \n" @@ -123,13 +116,13 @@ static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t * " bne 1b \n" "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) : "cc", "memory"); - ret = (prev == *oldval); - *oldval = prev; - return ret; + ret = (prev == *oldval); + *oldval = prev; + return ret; } /* these two functions aren't inlined in the non-gcc case because then @@ -137,46 +130,47 @@ static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t * atomic_?mb can be inlined). Instead, we "inline" them by hand in the assembly, meaning there is one function call overhead instead of two */ -static inline bool opal_atomic_compare_exchange_strong_acq_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { bool rc; - rc = opal_atomic_compare_exchange_strong_32 (addr, oldval, newval); + rc = opal_atomic_compare_exchange_strong_32(addr, oldval, newval); opal_atomic_rmb(); return rc; } - -static inline bool opal_atomic_compare_exchange_strong_rel_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { opal_atomic_wmb(); - return opal_atomic_compare_exchange_strong_32 (addr, oldval, newval); + return opal_atomic_compare_exchange_strong_32(addr, oldval, newval); } -#if (OPAL_ASM_SUPPORT_64BIT == 1) +# if (OPAL_ASM_SUPPORT_64BIT == 1) -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 -static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 +static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { int64_t prev; int tmp; bool ret; - __asm__ __volatile__ ( - "1: ldrexd %0, %H0, [%2] \n" - " cmp %0, %3 \n" - " it eq \n" - " cmpeq %H0, %H3 \n" - " bne 2f \n" - " strexd %1, %4, %H4, [%2] \n" - " cmp %1, #0 \n" - " bne 1b \n" - "2: \n" - - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldrexd %0, %H0, [%2] \n" + " cmp %0, %3 \n" + " it eq \n" + " cmpeq %H0, %H3 \n" + " bne 2f \n" + " strexd %1, %4, %H4, [%2] \n" + " cmp %1, #0 \n" + " bne 1b \n" + "2: \n" + + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; @@ -188,62 +182,59 @@ static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t * atomic_?mb can be inlined). Instead, we "inline" them by hand in the assembly, meaning there is one function call overhead instead of two */ -static inline bool opal_atomic_compare_exchange_strong_acq_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { bool rc; - rc = opal_atomic_compare_exchange_strong_64 (addr, oldval, newval); + rc = opal_atomic_compare_exchange_strong_64(addr, oldval, newval); opal_atomic_rmb(); return rc; } - -static inline bool opal_atomic_compare_exchange_strong_rel_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { opal_atomic_wmb(); - return opal_atomic_compare_exchange_strong_64 (addr, oldval, newval); + return opal_atomic_compare_exchange_strong_64(addr, oldval, newval); } -#endif - +# endif -#define OPAL_HAVE_ATOMIC_ADD_32 1 -static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t* v, int inc) +# define OPAL_HAVE_ATOMIC_ADD_32 1 +static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t *v, int inc) { int32_t t, old; int tmp; - __asm__ __volatile__( - "1: ldrex %1, [%3] \n" + __asm__ __volatile__("1: ldrex %1, [%3] \n" " add %0, %1, %4 \n" " strex %2, %0, [%3] \n" " cmp %2, #0 \n" " bne 1b \n" - : "=&r" (t), "=&r" (old), "=&r" (tmp) - : "r" (v), "r" (inc) + : "=&r"(t), "=&r"(old), "=&r"(tmp) + : "r"(v), "r"(inc) : "cc", "memory"); - return old; } -#define OPAL_HAVE_ATOMIC_SUB_32 1 -static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t* v, int dec) +# define OPAL_HAVE_ATOMIC_SUB_32 1 +static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t *v, int dec) { int32_t t, old; int tmp; - __asm__ __volatile__( - "1: ldrex %1, [%3] \n" + __asm__ __volatile__("1: ldrex %1, [%3] \n" " sub %0, %1, %4 \n" " strex %2, %0, [%3] \n" " cmp %2, #0 \n" " bne 1b \n" - : "=&r" (t), "=&r" (old), "=&r" (tmp) - : "r" (v), "r" (dec) + : "=&r"(t), "=&r"(old), "=&r"(tmp) + : "r"(v), "r"(dec) : "cc", "memory"); return t; diff --git a/opal/include/opal/sys/arm/timer.h b/opal/include/opal/sys/arm/timer.h index b93689c908d..5c7e15641fc 100644 --- a/opal/include/opal/sys/arm/timer.h +++ b/opal/include/opal/sys/arm/timer.h @@ -16,8 +16,7 @@ typedef uint64_t opal_timer_t; -static inline opal_timer_t -opal_sys_timer_get_cycles(void) +static inline opal_timer_t opal_sys_timer_get_cycles(void) { opal_timer_t ret; struct tms accurate_clock; diff --git a/opal/include/opal/sys/arm64/atomic.h b/opal/include/opal/sys/arm64/atomic.h index 8495901ace1..a0fb441c7c4 100644 --- a/opal/include/opal/sys/arm64/atomic.h +++ b/opal/include/opal/sys/arm64/atomic.h @@ -27,30 +27,30 @@ #if !defined(OPAL_SYS_ARCH_ATOMIC_H) -#define OPAL_SYS_ARCH_ATOMIC_H 1 - -#if OPAL_GCC_INLINE_ASSEMBLY - -#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 -#define OPAL_HAVE_ATOMIC_SWAP_32 1 -#define OPAL_HAVE_ATOMIC_MATH_32 1 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 -#define OPAL_HAVE_ATOMIC_SWAP_64 1 -#define OPAL_HAVE_ATOMIC_ADD_32 1 -#define OPAL_HAVE_ATOMIC_AND_32 1 -#define OPAL_HAVE_ATOMIC_OR_32 1 -#define OPAL_HAVE_ATOMIC_XOR_32 1 -#define OPAL_HAVE_ATOMIC_SUB_32 1 -#define OPAL_HAVE_ATOMIC_ADD_64 1 -#define OPAL_HAVE_ATOMIC_AND_64 1 -#define OPAL_HAVE_ATOMIC_OR_64 1 -#define OPAL_HAVE_ATOMIC_XOR_64 1 -#define OPAL_HAVE_ATOMIC_SUB_64 1 - -#define MB() __asm__ __volatile__ ("dmb sy" : : : "memory") -#define RMB() __asm__ __volatile__ ("dmb ld" : : : "memory") -#define WMB() __asm__ __volatile__ ("dmb st" : : : "memory") +# define OPAL_SYS_ARCH_ATOMIC_H 1 + +# if OPAL_GCC_INLINE_ASSEMBLY + +# define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 +# define OPAL_HAVE_ATOMIC_SWAP_32 1 +# define OPAL_HAVE_ATOMIC_MATH_32 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 +# define OPAL_HAVE_ATOMIC_SWAP_64 1 +# define OPAL_HAVE_ATOMIC_ADD_32 1 +# define OPAL_HAVE_ATOMIC_AND_32 1 +# define OPAL_HAVE_ATOMIC_OR_32 1 +# define OPAL_HAVE_ATOMIC_XOR_32 1 +# define OPAL_HAVE_ATOMIC_SUB_32 1 +# define OPAL_HAVE_ATOMIC_ADD_64 1 +# define OPAL_HAVE_ATOMIC_AND_64 1 +# define OPAL_HAVE_ATOMIC_OR_64 1 +# define OPAL_HAVE_ATOMIC_XOR_64 1 +# define OPAL_HAVE_ATOMIC_SUB_64 1 + +# define MB() __asm__ __volatile__("dmb sy" : : : "memory") +# define RMB() __asm__ __volatile__("dmb ld" : : : "memory") +# define WMB() __asm__ __volatile__("dmb st" : : : "memory") /********************************************************************** * @@ -58,24 +58,24 @@ * *********************************************************************/ -static inline void opal_atomic_mb (void) +static inline void opal_atomic_mb(void) { MB(); } -static inline void opal_atomic_rmb (void) +static inline void opal_atomic_rmb(void) { RMB(); } -static inline void opal_atomic_wmb (void) +static inline void opal_atomic_wmb(void) { WMB(); } -static inline void opal_atomic_isync (void) +static inline void opal_atomic_isync(void) { - __asm__ __volatile__ ("isb"); + __asm__ __volatile__("isb"); } /********************************************************************** @@ -84,20 +84,21 @@ static inline void opal_atomic_isync (void) * *********************************************************************/ -static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { int32_t prev, tmp; bool ret; - __asm__ __volatile__ ("1: ldaxr %w0, [%2] \n" - " cmp %w0, %w3 \n" - " bne 2f \n" - " stxr %w1, %w4, [%2] \n" - " cbnz %w1, 1b \n" - "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldaxr %w0, [%2] \n" + " cmp %w0, %w3 \n" + " bne 2f \n" + " stxr %w1, %w4, [%2] \n" + " cbnz %w1, 1b \n" + "2: \n" + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; @@ -108,12 +109,12 @@ static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t new { int32_t ret, tmp; - __asm__ __volatile__ ("1: ldaxr %w0, [%2] \n" - " stlxr %w1, %w3, [%2] \n" - " cbnz %w1, 1b \n" - : "=&r" (ret), "=&r" (tmp) - : "r" (addr), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldaxr %w0, [%2] \n" + " stlxr %w1, %w3, [%2] \n" + " cbnz %w1, 1b \n" + : "=&r"(ret), "=&r"(tmp) + : "r"(addr), "r"(newval) + : "cc", "memory"); return ret; } @@ -123,79 +124,81 @@ static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t new atomic_?mb can be inlined). Instead, we "inline" them by hand in the assembly, meaning there is one function call overhead instead of two */ -static inline bool opal_atomic_compare_exchange_strong_acq_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { int32_t prev, tmp; bool ret; - __asm__ __volatile__ ("1: ldaxr %w0, [%2] \n" - " cmp %w0, %w3 \n" - " bne 2f \n" - " stxr %w1, %w4, [%2] \n" - " cbnz %w1, 1b \n" - "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldaxr %w0, [%2] \n" + " cmp %w0, %w3 \n" + " bne 2f \n" + " stxr %w1, %w4, [%2] \n" + " cbnz %w1, 1b \n" + "2: \n" + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; return ret; } - -static inline bool opal_atomic_compare_exchange_strong_rel_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { int32_t prev, tmp; bool ret; - __asm__ __volatile__ ("1: ldxr %w0, [%2] \n" - " cmp %w0, %w3 \n" - " bne 2f \n" - " stlxr %w1, %w4, [%2] \n" - " cbnz %w1, 1b \n" - "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldxr %w0, [%2] \n" + " cmp %w0, %w3 \n" + " bne 2f \n" + " stlxr %w1, %w4, [%2] \n" + " cbnz %w1, 1b \n" + "2: \n" + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; return ret; } -static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { int64_t prev; int tmp; bool ret; - __asm__ __volatile__ ("1: ldaxr %0, [%2] \n" - " cmp %0, %3 \n" - " bne 2f \n" - " stxr %w1, %4, [%2] \n" - " cbnz %w1, 1b \n" - "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldaxr %0, [%2] \n" + " cmp %0, %3 \n" + " bne 2f \n" + " stxr %w1, %4, [%2] \n" + " cbnz %w1, 1b \n" + "2: \n" + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; return ret; } -static inline int64_t opal_atomic_swap_64 (opal_atomic_int64_t *addr, int64_t newval) +static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval) { int64_t ret; int tmp; - __asm__ __volatile__ ("1: ldaxr %0, [%2] \n" - " stlxr %w1, %3, [%2] \n" - " cbnz %w1, 1b \n" - : "=&r" (ret), "=&r" (tmp) - : "r" (addr), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldaxr %0, [%2] \n" + " stlxr %w1, %3, [%2] \n" + " cbnz %w1, 1b \n" + : "=&r"(ret), "=&r"(tmp) + : "r"(addr), "r"(newval) + : "cc", "memory"); return ret; } @@ -205,65 +208,67 @@ static inline int64_t opal_atomic_swap_64 (opal_atomic_int64_t *addr, int64_t ne atomic_?mb can be inlined). Instead, we "inline" them by hand in the assembly, meaning there is one function call overhead instead of two */ -static inline bool opal_atomic_compare_exchange_strong_acq_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { int64_t prev; int tmp; bool ret; - __asm__ __volatile__ ("1: ldaxr %0, [%2] \n" - " cmp %0, %3 \n" - " bne 2f \n" - " stxr %w1, %4, [%2] \n" - " cbnz %w1, 1b \n" - "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldaxr %0, [%2] \n" + " cmp %0, %3 \n" + " bne 2f \n" + " stxr %w1, %4, [%2] \n" + " cbnz %w1, 1b \n" + "2: \n" + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; return ret; } - -static inline bool opal_atomic_compare_exchange_strong_rel_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { int64_t prev; int tmp; bool ret; - __asm__ __volatile__ ("1: ldxr %0, [%2] \n" - " cmp %0, %3 \n" - " bne 2f \n" - " stlxr %w1, %4, [%2] \n" - " cbnz %w1, 1b \n" - "2: \n" - : "=&r" (prev), "=&r" (tmp) - : "r" (addr), "r" (*oldval), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: ldxr %0, [%2] \n" + " cmp %0, %3 \n" + " bne 2f \n" + " stlxr %w1, %4, [%2] \n" + " cbnz %w1, 1b \n" + "2: \n" + : "=&r"(prev), "=&r"(tmp) + : "r"(addr), "r"(*oldval), "r"(newval) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; return ret; } -#define OPAL_ASM_MAKE_ATOMIC(type, bits, name, inst, reg) \ - static inline type opal_atomic_fetch_ ## name ## _ ## bits (opal_atomic_ ## type *addr, type value) \ - { \ - type newval, old; \ - int32_t tmp; \ - \ - __asm__ __volatile__("1: ldxr %" reg "1, [%3] \n" \ - " " inst " %" reg "0, %" reg "1, %" reg "4 \n" \ - " stxr %w2, %" reg "0, [%3] \n" \ - " cbnz %w2, 1b \n" \ - : "=&r" (newval), "=&r" (old), "=&r" (tmp) \ - : "r" (addr), "r" (value) \ - : "cc", "memory"); \ - \ - return old; \ - } +# define OPAL_ASM_MAKE_ATOMIC(type, bits, name, inst, reg) \ + static inline type opal_atomic_fetch_##name##_##bits(opal_atomic_##type *addr, \ + type value) \ + { \ + type newval, old; \ + int32_t tmp; \ + \ + __asm__ __volatile__("1: ldxr %" reg "1, [%3] \n" \ + " " inst " %" reg "0, %" reg "1, %" reg "4 \n" \ + " stxr %w2, %" reg "0, [%3] \n" \ + " cbnz %w2, 1b \n" \ + : "=&r"(newval), "=&r"(old), "=&r"(tmp) \ + : "r"(addr), "r"(value) \ + : "cc", "memory"); \ + \ + return old; \ + } OPAL_ASM_MAKE_ATOMIC(int32_t, 32, add, "add", "w") OPAL_ASM_MAKE_ATOMIC(int32_t, 32, and, "and", "w") @@ -276,6 +281,6 @@ OPAL_ASM_MAKE_ATOMIC(int64_t, 64, or, "orr", "") OPAL_ASM_MAKE_ATOMIC(int64_t, 64, xor, "eor", "") OPAL_ASM_MAKE_ATOMIC(int64_t, 64, sub, "sub", "") -#endif /* OPAL_GCC_INLINE_ASSEMBLY */ +# endif /* OPAL_GCC_INLINE_ASSEMBLY */ #endif /* ! OPAL_SYS_ARCH_ATOMIC_H */ diff --git a/opal/include/opal/sys/arm64/atomic_llsc.h b/opal/include/opal/sys/arm64/atomic_llsc.h index 56dff4934c3..807ff526a2c 100644 --- a/opal/include/opal/sys/arm64/atomic_llsc.h +++ b/opal/include/opal/sys/arm64/atomic_llsc.h @@ -25,68 +25,64 @@ #if !defined(OPAL_SYS_ARCH_ATOMIC_LLSC_H) -#define OPAL_SYS_ARCH_ATOMIC_LLSC_H +# define OPAL_SYS_ARCH_ATOMIC_LLSC_H -#if OPAL_C_GCC_INLINE_ASSEMBLY +# if OPAL_C_GCC_INLINE_ASSEMBLY -#undef OPAL_HAVE_ATOMIC_LLSC_32 -#undef OPAL_HAVE_ATOMIC_LLSC_64 +# undef OPAL_HAVE_ATOMIC_LLSC_32 +# undef OPAL_HAVE_ATOMIC_LLSC_64 -#define OPAL_HAVE_ATOMIC_LLSC_32 1 -#define OPAL_HAVE_ATOMIC_LLSC_64 1 +# define OPAL_HAVE_ATOMIC_LLSC_32 1 +# define OPAL_HAVE_ATOMIC_LLSC_64 1 -#define opal_atomic_ll_32(addr, ret) \ - do { \ - opal_atomic_int32_t *_addr = (addr); \ - int32_t _ret; \ - \ - __asm__ __volatile__ ("ldaxr %w0, [%1] \n" \ - : "=&r" (_ret) \ - : "r" (_addr)); \ - \ - ret = (typeof(ret)) _ret; \ - } while (0) +# define opal_atomic_ll_32(addr, ret) \ + do { \ + opal_atomic_int32_t *_addr = (addr); \ + int32_t _ret; \ + \ + __asm__ __volatile__("ldaxr %w0, [%1] \n" : "=&r"(_ret) : "r"(_addr)); \ + \ + ret = (typeof(ret)) _ret; \ + } while (0) -#define opal_atomic_sc_32(addr, newval, ret) \ - do { \ - opal_atomic_int32_t *_addr = (addr); \ - int32_t _newval = (int32_t) newval; \ - int _ret; \ - \ - __asm__ __volatile__ ("stlxr %w0, %w2, [%1] \n" \ - : "=&r" (_ret) \ - : "r" (_addr), "r" (_newval) \ - : "cc", "memory"); \ - \ - ret = (_ret == 0); \ - } while (0) +# define opal_atomic_sc_32(addr, newval, ret) \ + do { \ + opal_atomic_int32_t *_addr = (addr); \ + int32_t _newval = (int32_t) newval; \ + int _ret; \ + \ + __asm__ __volatile__("stlxr %w0, %w2, [%1] \n" \ + : "=&r"(_ret) \ + : "r"(_addr), "r"(_newval) \ + : "cc", "memory"); \ + \ + ret = (_ret == 0); \ + } while (0) -#define opal_atomic_ll_64(addr, ret) \ - do { \ - opal_atomic_int64_t *_addr = (addr); \ - int64_t _ret; \ - \ - __asm__ __volatile__ ("ldaxr %0, [%1] \n" \ - : "=&r" (_ret) \ - : "r" (_addr)); \ - \ - ret = (typeof(ret)) _ret; \ - } while (0) +# define opal_atomic_ll_64(addr, ret) \ + do { \ + opal_atomic_int64_t *_addr = (addr); \ + int64_t _ret; \ + \ + __asm__ __volatile__("ldaxr %0, [%1] \n" : "=&r"(_ret) : "r"(_addr)); \ + \ + ret = (typeof(ret)) _ret; \ + } while (0) -#define opal_atomic_sc_64(addr, newval, ret) \ - do { \ - opal_atomic_int64_t *_addr = (addr); \ - int64_t _newval = (int64_t) newval; \ - int _ret; \ - \ - __asm__ __volatile__ ("stlxr %w0, %2, [%1] \n" \ - : "=&r" (_ret) \ - : "r" (_addr), "r" (_newval) \ - : "cc", "memory"); \ - \ - ret = (_ret == 0); \ - } while (0) +# define opal_atomic_sc_64(addr, newval, ret) \ + do { \ + opal_atomic_int64_t *_addr = (addr); \ + int64_t _newval = (int64_t) newval; \ + int _ret; \ + \ + __asm__ __volatile__("stlxr %w0, %2, [%1] \n" \ + : "=&r"(_ret) \ + : "r"(_addr), "r"(_newval) \ + : "cc", "memory"); \ + \ + ret = (_ret == 0); \ + } while (0) -#endif /* OPAL_GCC_INLINE_ASSEMBLY */ +# endif /* OPAL_GCC_INLINE_ASSEMBLY */ #endif /* ! OPAL_SYS_ARCH_ATOMIC_LLSC_H */ diff --git a/opal/include/opal/sys/arm64/timer.h b/opal/include/opal/sys/arm64/timer.h index adf2dc57b99..fab38901a01 100644 --- a/opal/include/opal/sys/arm64/timer.h +++ b/opal/include/opal/sys/arm64/timer.h @@ -18,27 +18,24 @@ typedef uint64_t opal_timer_t; -static inline opal_timer_t -opal_sys_timer_get_cycles(void) +static inline opal_timer_t opal_sys_timer_get_cycles(void) { opal_timer_t ret; - __asm__ __volatile__ ("isb" ::: "memory"); - __asm__ __volatile__ ("mrs %0, CNTVCT_EL0" : "=r" (ret)); + __asm__ __volatile__("isb" ::: "memory"); + __asm__ __volatile__("mrs %0, CNTVCT_EL0" : "=r"(ret)); return ret; } - -static inline opal_timer_t -opal_sys_timer_get_freq(void) +static inline opal_timer_t opal_sys_timer_get_freq(void) { opal_timer_t freq; - __asm__ __volatile__ ("mrs %0, CNTFRQ_EL0" : "=r" (freq)); + __asm__ __volatile__("mrs %0, CNTFRQ_EL0" : "=r"(freq)); return (opal_timer_t)(freq); } #define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 -#define OPAL_HAVE_SYS_TIMER_GET_FREQ 1 +#define OPAL_HAVE_SYS_TIMER_GET_FREQ 1 #endif /* ! OPAL_SYS_ARCH_TIMER_H */ diff --git a/opal/include/opal/sys/atomic.h b/opal/include/opal/sys/atomic.h index e17212e9fee..fcb533e3d36 100644 --- a/opal/include/opal/sys/atomic.h +++ b/opal/include/opal/sys/atomic.h @@ -62,26 +62,25 @@ /* do some quick #define cleanup in cases where we are doing testing... */ #ifdef OPAL_DISABLE_INLINE_ASM -#undef OPAL_C_GCC_INLINE_ASSEMBLY -#define OPAL_C_GCC_INLINE_ASSEMBLY 0 +# undef OPAL_C_GCC_INLINE_ASSEMBLY +# define OPAL_C_GCC_INLINE_ASSEMBLY 0 #endif #if OPAL_ASSEMBLY_BUILTIN == OPAL_BUILTIN_C11 && !defined(__INTEL_COMPILER) -#include "atomic_stdc.h" +# include "atomic_stdc.h" #else /* !OPAL_C_HAVE__ATOMIC */ /* define OPAL_{GCC,DEC,XLC}_INLINE_ASSEMBLY based on the OPAL_C_{GCC,DEC,XLC}_INLINE_ASSEMBLY defines and whether we are in C or C++ */ -#if defined(c_plusplus) || defined(__cplusplus) +# if defined(c_plusplus) || defined(__cplusplus) /* We no longer support inline assembly for C++ as OPAL is a C-only interface */ -#define OPAL_GCC_INLINE_ASSEMBLY 0 -#else -#define OPAL_GCC_INLINE_ASSEMBLY OPAL_C_GCC_INLINE_ASSEMBLY -#endif - +# define OPAL_GCC_INLINE_ASSEMBLY 0 +# else +# define OPAL_GCC_INLINE_ASSEMBLY OPAL_C_GCC_INLINE_ASSEMBLY +# endif BEGIN_C_DECLS /********************************************************************** @@ -99,9 +98,9 @@ BEGIN_C_DECLS */ struct opal_atomic_lock_t { union { - opal_atomic_int32_t lock; /**< The lock address (an integer) */ + opal_atomic_int32_t lock; /**< The lock address (an integer) */ volatile unsigned char sparc_lock; /**< The lock address on sparc */ - char padding[sizeof(int)]; /**< Array for optional padding */ + char padding[sizeof(int)]; /**< Array for optional padding */ } u; }; typedef struct opal_atomic_lock_t opal_atomic_lock_t; @@ -112,49 +111,49 @@ typedef struct opal_atomic_lock_t opal_atomic_lock_t; * files if we need to specify them as inline or non-inline * *********************************************************************/ -#if !OPAL_GCC_INLINE_ASSEMBLY -#define OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER 0 -#define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 0 -#define OPAL_HAVE_INLINE_ATOMIC_ADD_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_AND_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_OR_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_XOR_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_SUB_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_ADD_64 0 -#define OPAL_HAVE_INLINE_ATOMIC_AND_64 0 -#define OPAL_HAVE_INLINE_ATOMIC_OR_64 0 -#define OPAL_HAVE_INLINE_ATOMIC_XOR_64 0 -#define OPAL_HAVE_INLINE_ATOMIC_SUB_64 0 -#define OPAL_HAVE_INLINE_ATOMIC_SWAP_32 0 -#define OPAL_HAVE_INLINE_ATOMIC_SWAP_64 0 -#else -#define OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER 1 -#define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 1 -#define OPAL_HAVE_INLINE_ATOMIC_ADD_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_AND_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_OR_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_XOR_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_SUB_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_ADD_64 1 -#define OPAL_HAVE_INLINE_ATOMIC_AND_64 1 -#define OPAL_HAVE_INLINE_ATOMIC_OR_64 1 -#define OPAL_HAVE_INLINE_ATOMIC_XOR_64 1 -#define OPAL_HAVE_INLINE_ATOMIC_SUB_64 1 -#define OPAL_HAVE_INLINE_ATOMIC_SWAP_32 1 -#define OPAL_HAVE_INLINE_ATOMIC_SWAP_64 1 -#endif +# if !OPAL_GCC_INLINE_ASSEMBLY +# define OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER 0 +# define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 0 +# define OPAL_HAVE_INLINE_ATOMIC_ADD_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_AND_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_OR_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_XOR_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_SUB_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_ADD_64 0 +# define OPAL_HAVE_INLINE_ATOMIC_AND_64 0 +# define OPAL_HAVE_INLINE_ATOMIC_OR_64 0 +# define OPAL_HAVE_INLINE_ATOMIC_XOR_64 0 +# define OPAL_HAVE_INLINE_ATOMIC_SUB_64 0 +# define OPAL_HAVE_INLINE_ATOMIC_SWAP_32 0 +# define OPAL_HAVE_INLINE_ATOMIC_SWAP_64 0 +# else +# define OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER 1 +# define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 1 +# define OPAL_HAVE_INLINE_ATOMIC_ADD_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_AND_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_OR_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_XOR_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_SUB_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_ADD_64 1 +# define OPAL_HAVE_INLINE_ATOMIC_AND_64 1 +# define OPAL_HAVE_INLINE_ATOMIC_OR_64 1 +# define OPAL_HAVE_INLINE_ATOMIC_XOR_64 1 +# define OPAL_HAVE_INLINE_ATOMIC_SUB_64 1 +# define OPAL_HAVE_INLINE_ATOMIC_SWAP_32 1 +# define OPAL_HAVE_INLINE_ATOMIC_SWAP_64 1 +# endif /** * Enumeration of lock states */ -enum { - OPAL_ATOMIC_LOCK_UNLOCKED = 0, - OPAL_ATOMIC_LOCK_LOCKED = 1 -}; +enum { OPAL_ATOMIC_LOCK_UNLOCKED = 0, OPAL_ATOMIC_LOCK_LOCKED = 1 }; -#define OPAL_ATOMIC_LOCK_INIT {.u = {.lock = OPAL_ATOMIC_LOCK_UNLOCKED}} +# define OPAL_ATOMIC_LOCK_INIT \ + { \ + .u = {.lock = OPAL_ATOMIC_LOCK_UNLOCKED } \ + } /********************************************************************** * @@ -162,44 +161,44 @@ enum { * default values for our support * *********************************************************************/ -#if defined(DOXYGEN) +# if defined(DOXYGEN) /* don't include system-level gorp when generating doxygen files */ -#elif OPAL_ASSEMBLY_BUILTIN == OPAL_BUILTIN_GCC -#include "opal/sys/gcc_builtin/atomic.h" -#elif OPAL_ASSEMBLY_ARCH == OPAL_X86_64 -#include "opal/sys/x86_64/atomic.h" -#elif OPAL_ASSEMBLY_ARCH == OPAL_ARM -#include "opal/sys/arm/atomic.h" -#elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 -#include "opal/sys/arm64/atomic.h" -#elif OPAL_ASSEMBLY_ARCH == OPAL_IA32 -#include "opal/sys/ia32/atomic.h" -#elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32 -#include "opal/sys/powerpc/atomic.h" -#elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64 -#include "opal/sys/powerpc/atomic.h" -#endif - -#ifndef DOXYGEN +# elif OPAL_ASSEMBLY_BUILTIN == OPAL_BUILTIN_GCC +# include "opal/sys/gcc_builtin/atomic.h" +# elif OPAL_ASSEMBLY_ARCH == OPAL_X86_64 +# include "opal/sys/x86_64/atomic.h" +# elif OPAL_ASSEMBLY_ARCH == OPAL_ARM +# include "opal/sys/arm/atomic.h" +# elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 +# include "opal/sys/arm64/atomic.h" +# elif OPAL_ASSEMBLY_ARCH == OPAL_IA32 +# include "opal/sys/ia32/atomic.h" +# elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32 +# include "opal/sys/powerpc/atomic.h" +# elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64 +# include "opal/sys/powerpc/atomic.h" +# endif + +# ifndef DOXYGEN /* compare and set operations can't really be emulated from software, so if these defines aren't already set, they should be set to 0 now */ -#ifndef OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 0 -#endif -#ifndef OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 0 -#endif -#ifndef OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 0 -#endif -#ifndef OPAL_HAVE_ATOMIC_LLSC_32 -#define OPAL_HAVE_ATOMIC_LLSC_32 0 -#endif -#ifndef OPAL_HAVE_ATOMIC_LLSC_64 -#define OPAL_HAVE_ATOMIC_LLSC_64 0 -#endif -#endif /* DOXYGEN */ +# ifndef OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 0 +# endif +# ifndef OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 0 +# endif +# ifndef OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 0 +# endif +# ifndef OPAL_HAVE_ATOMIC_LLSC_32 +# define OPAL_HAVE_ATOMIC_LLSC_32 0 +# endif +# ifndef OPAL_HAVE_ATOMIC_LLSC_64 +# define OPAL_HAVE_ATOMIC_LLSC_64 0 +# endif +# endif /* DOXYGEN */ /********************************************************************** * @@ -207,12 +206,12 @@ enum { * but can't inline * *********************************************************************/ -#if !defined(OPAL_HAVE_ATOMIC_MEM_BARRIER) && !defined(DOXYGEN) +# if !defined(OPAL_HAVE_ATOMIC_MEM_BARRIER) && !defined(DOXYGEN) /* no way to emulate in C code */ -#define OPAL_HAVE_ATOMIC_MEM_BARRIER 0 -#endif +# define OPAL_HAVE_ATOMIC_MEM_BARRIER 0 +# endif -#if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MEM_BARRIER +# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MEM_BARRIER /** * Memory barrier * @@ -227,10 +226,11 @@ enum { * if you need *both* read and write barriers. */ -#if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER +# if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER static inline -#endif -void opal_atomic_mb(void); +# endif + void + opal_atomic_mb(void); /** * Read memory barrier @@ -242,10 +242,11 @@ void opal_atomic_mb(void); * \c opal_atomic_rmb(). */ -#if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER +# if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER static inline -#endif -void opal_atomic_rmb(void); +# endif + void + opal_atomic_rmb(void); /** * Write memory barrier. @@ -257,13 +258,13 @@ void opal_atomic_rmb(void); * \c opal_atomic_wmb(). */ -#if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER +# if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER static inline -#endif -void opal_atomic_wmb(void); - -#endif /* defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MEM_BARRIER */ +# endif + void + opal_atomic_wmb(void); +# endif /* defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MEM_BARRIER */ /********************************************************************** * @@ -271,13 +272,14 @@ void opal_atomic_wmb(void); * *********************************************************************/ -#if !defined(OPAL_HAVE_ATOMIC_SPINLOCKS) && !defined(DOXYGEN) +# if !defined(OPAL_HAVE_ATOMIC_SPINLOCKS) && !defined(DOXYGEN) /* 0 is more like "pending" - we'll fix up at the end after all the static inline functions are declared */ -#define OPAL_HAVE_ATOMIC_SPINLOCKS 0 -#endif +# define OPAL_HAVE_ATOMIC_SPINLOCKS 0 +# endif -#if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_SPINLOCKS || (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) +# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_SPINLOCKS \ + || (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) /** * Initialize a lock to value @@ -285,11 +287,11 @@ void opal_atomic_wmb(void); * @param lock Address of the lock * @param value Initial value to set lock to */ -#if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 +# if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 static inline -#endif -void opal_atomic_lock_init(opal_atomic_lock_t* lock, int32_t value); - +# endif + void + opal_atomic_lock_init(opal_atomic_lock_t *lock, int32_t value); /** * Try to acquire a lock. @@ -297,104 +299,109 @@ void opal_atomic_lock_init(opal_atomic_lock_t* lock, int32_t value); * @param lock Address of the lock. * @return 0 if the lock was acquired, 1 otherwise. */ -#if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 +# if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 static inline -#endif -int opal_atomic_trylock(opal_atomic_lock_t *lock); - +# endif + int + opal_atomic_trylock(opal_atomic_lock_t *lock); /** * Acquire a lock by spinning. * * @param lock Address of the lock. */ -#if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 +# if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 static inline -#endif -void opal_atomic_lock(opal_atomic_lock_t *lock); - +# endif + void + opal_atomic_lock(opal_atomic_lock_t *lock); /** * Release a lock. * * @param lock Address of the lock. */ -#if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 +# if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 static inline -#endif -void opal_atomic_unlock(opal_atomic_lock_t *lock); - - -#if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 -#undef OPAL_HAVE_ATOMIC_SPINLOCKS -#define OPAL_HAVE_ATOMIC_SPINLOCKS (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) -#define OPAL_NEED_INLINE_ATOMIC_SPINLOCKS 1 -#endif +# endif + void + opal_atomic_unlock(opal_atomic_lock_t *lock); -#endif /* OPAL_HAVE_ATOMIC_SPINLOCKS */ +# if OPAL_HAVE_ATOMIC_SPINLOCKS == 0 +# undef OPAL_HAVE_ATOMIC_SPINLOCKS +# define OPAL_HAVE_ATOMIC_SPINLOCKS \ + (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) +# define OPAL_NEED_INLINE_ATOMIC_SPINLOCKS 1 +# endif +# endif /* OPAL_HAVE_ATOMIC_SPINLOCKS */ /********************************************************************** * * Atomic math operations * *********************************************************************/ -#if !defined(OPAL_HAVE_ATOMIC_CMPSET_32) && !defined(DOXYGEN) -#define OPAL_HAVE_ATOMIC_CMPSET_32 0 -#endif -#if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_CMPSET_32 +# if !defined(OPAL_HAVE_ATOMIC_CMPSET_32) && !defined(DOXYGEN) +# define OPAL_HAVE_ATOMIC_CMPSET_32 0 +# endif +# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_CMPSET_32 -#if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 +# if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 static inline -#endif -bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, - int32_t newval); +# endif + bool + opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, int32_t *oldval, + int32_t newval); -#if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 +# if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 static inline -#endif -bool opal_atomic_compare_exchange_strong_acq_32 (opal_atomic_int32_t *addr, int32_t *oldval, - int32_t newval); +# endif + bool + opal_atomic_compare_exchange_strong_acq_32(opal_atomic_int32_t *addr, int32_t *oldval, + int32_t newval); -#if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 +# if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 static inline -#endif -bool opal_atomic_compare_exchange_strong_rel_32 (opal_atomic_int32_t *addr, int32_t *oldval, - int32_t newval); -#endif - - -#if !defined(OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) && !defined(DOXYGEN) -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 0 -#endif -#if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 - -#if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 +# endif + bool + opal_atomic_compare_exchange_strong_rel_32(opal_atomic_int32_t *addr, int32_t *oldval, + int32_t newval); +# endif + +# if !defined(OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) && !defined(DOXYGEN) +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 0 +# endif +# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 + +# if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 static inline -#endif -bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, - int64_t newval); +# endif + bool + opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, int64_t *oldval, + int64_t newval); -#if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 +# if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 static inline -#endif -bool opal_atomic_compare_exchange_strong_acq_64 (opal_atomic_int64_t *addr, int64_t *oldval, - int64_t newval); +# endif + bool + opal_atomic_compare_exchange_strong_acq_64(opal_atomic_int64_t *addr, int64_t *oldval, + int64_t newval); -#if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 +# if OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 static inline -#endif -bool opal_atomic_compare_exchange_strong_rel_64 (opal_atomic_int64_t *addr, int64_t *oldval, - int64_t newval); +# endif + bool + opal_atomic_compare_exchange_strong_rel_64(opal_atomic_int64_t *addr, int64_t *oldval, + int64_t newval); -#endif +# endif -#if !defined(OPAL_HAVE_ATOMIC_MATH_32) && !defined(DOXYGEN) - /* define to 0 for these tests. WIll fix up later. */ - #define OPAL_HAVE_ATOMIC_MATH_32 0 -#endif +# if !defined(OPAL_HAVE_ATOMIC_MATH_32) && !defined(DOXYGEN) +/* define to 0 for these tests. WIll fix up later. */ +# define OPAL_HAVE_ATOMIC_MATH_32 0 +# endif -#if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 +# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 static inline int32_t opal_atomic_add_fetch_32(opal_atomic_int32_t *addr, int delta); static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t *addr, int delta); @@ -406,25 +413,25 @@ static inline int32_t opal_atomic_xor_fetch_32(opal_atomic_int32_t *addr, int32_ static inline int32_t opal_atomic_fetch_xor_32(opal_atomic_int32_t *addr, int32_t value); static inline int32_t opal_atomic_sub_fetch_32(opal_atomic_int32_t *addr, int delta); static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t *addr, int delta); -static inline int32_t opal_atomic_min_fetch_32 (opal_atomic_int32_t *addr, int32_t value); -static inline int32_t opal_atomic_fetch_min_32 (opal_atomic_int32_t *addr, int32_t value); -static inline int32_t opal_atomic_max_fetch_32 (opal_atomic_int32_t *addr, int32_t value); -static inline int32_t opal_atomic_fetch_max_32 (opal_atomic_int32_t *addr, int32_t value); +static inline int32_t opal_atomic_min_fetch_32(opal_atomic_int32_t *addr, int32_t value); +static inline int32_t opal_atomic_fetch_min_32(opal_atomic_int32_t *addr, int32_t value); +static inline int32_t opal_atomic_max_fetch_32(opal_atomic_int32_t *addr, int32_t value); +static inline int32_t opal_atomic_fetch_max_32(opal_atomic_int32_t *addr, int32_t value); -#endif /* OPAL_HAVE_ATOMIC_MATH_32 */ +# endif /* OPAL_HAVE_ATOMIC_MATH_32 */ -#if ! OPAL_HAVE_ATOMIC_MATH_32 +# if !OPAL_HAVE_ATOMIC_MATH_32 /* fix up the value of opal_have_atomic_math_32 to allow for C versions */ -#undef OPAL_HAVE_ATOMIC_MATH_32 -#define OPAL_HAVE_ATOMIC_MATH_32 OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 -#endif +# undef OPAL_HAVE_ATOMIC_MATH_32 +# define OPAL_HAVE_ATOMIC_MATH_32 OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 +# endif -#ifndef OPAL_HAVE_ATOMIC_MATH_64 +# ifndef OPAL_HAVE_ATOMIC_MATH_64 /* define to 0 for these tests. WIll fix up later. */ -#define OPAL_HAVE_ATOMIC_MATH_64 0 -#endif +# define OPAL_HAVE_ATOMIC_MATH_64 0 +# endif -#if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MATH_64 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 +# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MATH_64 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 static inline int64_t opal_atomic_add_fetch_64(opal_atomic_int64_t *addr, int64_t delta); static inline int64_t opal_atomic_fetch_add_64(opal_atomic_int64_t *addr, int64_t delta); @@ -435,107 +442,114 @@ static inline int64_t opal_atomic_fetch_or_64(opal_atomic_int64_t *addr, int64_t static inline int64_t opal_atomic_fetch_xor_64(opal_atomic_int64_t *addr, int64_t value); static inline int64_t opal_atomic_sub_fetch_64(opal_atomic_int64_t *addr, int64_t delta); static inline int64_t opal_atomic_fetch_sub_64(opal_atomic_int64_t *addr, int64_t delta); -static inline int64_t opal_atomic_min_fetch_64 (opal_atomic_int64_t *addr, int64_t value); -static inline int64_t opal_atomic_fetch_min_64 (opal_atomic_int64_t *addr, int64_t value); -static inline int64_t opal_atomic_max_fetch_64 (opal_atomic_int64_t *addr, int64_t value); -static inline int64_t opal_atomic_fetch_max_64 (opal_atomic_int64_t *addr, int64_t value); +static inline int64_t opal_atomic_min_fetch_64(opal_atomic_int64_t *addr, int64_t value); +static inline int64_t opal_atomic_fetch_min_64(opal_atomic_int64_t *addr, int64_t value); +static inline int64_t opal_atomic_max_fetch_64(opal_atomic_int64_t *addr, int64_t value); +static inline int64_t opal_atomic_fetch_max_64(opal_atomic_int64_t *addr, int64_t value); -#endif /* OPAL_HAVE_ATOMIC_MATH_64 */ +# endif /* OPAL_HAVE_ATOMIC_MATH_64 */ -#if ! OPAL_HAVE_ATOMIC_MATH_64 +# if !OPAL_HAVE_ATOMIC_MATH_64 /* fix up the value of opal_have_atomic_math_64 to allow for C versions */ -#undef OPAL_HAVE_ATOMIC_MATH_64 -#define OPAL_HAVE_ATOMIC_MATH_64 OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 -#endif +# undef OPAL_HAVE_ATOMIC_MATH_64 +# define OPAL_HAVE_ATOMIC_MATH_64 OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 +# endif /* provide a size_t add/subtract. When in debug mode, make it an * inline function so that we don't have any casts in the * interface and can catch type errors. When not in debug mode, * just make it a macro, so that there's no performance penalty */ -#if defined(DOXYGEN) || OPAL_ENABLE_DEBUG -static inline size_t -opal_atomic_add_fetch_size_t(opal_atomic_size_t *addr, size_t delta) +# if defined(DOXYGEN) || OPAL_ENABLE_DEBUG +static inline size_t opal_atomic_add_fetch_size_t(opal_atomic_size_t *addr, size_t delta) { -#if SIZEOF_SIZE_T == 4 - return (size_t) opal_atomic_add_fetch_32((int32_t*) addr, delta); -#elif SIZEOF_SIZE_T == 8 - return (size_t) opal_atomic_add_fetch_64((int64_t*) addr, delta); -#else -#error "Unknown size_t size" -#endif +# if SIZEOF_SIZE_T == 4 + return (size_t) opal_atomic_add_fetch_32((int32_t *) addr, delta); +# elif SIZEOF_SIZE_T == 8 + return (size_t) opal_atomic_add_fetch_64((int64_t *) addr, delta); +# else +# error "Unknown size_t size" +# endif } -static inline size_t -opal_atomic_fetch_add_size_t(opal_atomic_size_t *addr, size_t delta) +static inline size_t opal_atomic_fetch_add_size_t(opal_atomic_size_t *addr, size_t delta) { -#if SIZEOF_SIZE_T == 4 - return (size_t) opal_atomic_fetch_add_32((int32_t*) addr, delta); -#elif SIZEOF_SIZE_T == 8 - return (size_t) opal_atomic_fetch_add_64((int64_t*) addr, delta); -#else -#error "Unknown size_t size" -#endif +# if SIZEOF_SIZE_T == 4 + return (size_t) opal_atomic_fetch_add_32((int32_t *) addr, delta); +# elif SIZEOF_SIZE_T == 8 + return (size_t) opal_atomic_fetch_add_64((int64_t *) addr, delta); +# else +# error "Unknown size_t size" +# endif } -static inline size_t -opal_atomic_sub_fetch_size_t(opal_atomic_size_t *addr, size_t delta) +static inline size_t opal_atomic_sub_fetch_size_t(opal_atomic_size_t *addr, size_t delta) { -#if SIZEOF_SIZE_T == 4 - return (size_t) opal_atomic_sub_fetch_32((int32_t*) addr, delta); -#elif SIZEOF_SIZE_T == 8 - return (size_t) opal_atomic_sub_fetch_64((int64_t*) addr, delta); -#else -#error "Unknown size_t size" -#endif +# if SIZEOF_SIZE_T == 4 + return (size_t) opal_atomic_sub_fetch_32((int32_t *) addr, delta); +# elif SIZEOF_SIZE_T == 8 + return (size_t) opal_atomic_sub_fetch_64((int64_t *) addr, delta); +# else +# error "Unknown size_t size" +# endif } -static inline size_t -opal_atomic_fetch_sub_size_t(opal_atomic_size_t *addr, size_t delta) +static inline size_t opal_atomic_fetch_sub_size_t(opal_atomic_size_t *addr, size_t delta) { -#if SIZEOF_SIZE_T == 4 - return (size_t) opal_atomic_fetch_sub_32((int32_t*) addr, delta); -#elif SIZEOF_SIZE_T == 8 - return (size_t) opal_atomic_fetch_sub_64((int64_t*) addr, delta); -#else -#error "Unknown size_t size" -#endif +# if SIZEOF_SIZE_T == 4 + return (size_t) opal_atomic_fetch_sub_32((int32_t *) addr, delta); +# elif SIZEOF_SIZE_T == 8 + return (size_t) opal_atomic_fetch_sub_64((int64_t *) addr, delta); +# else +# error "Unknown size_t size" +# endif } -#else -#if SIZEOF_SIZE_T == 4 -#define opal_atomic_add_fetch_size_t(addr, delta) ((size_t) opal_atomic_add_fetch_32((opal_atomic_int32_t *) addr, delta)) -#define opal_atomic_fetch_add_size_t(addr, delta) ((size_t) opal_atomic_fetch_add_32((opal_atomic_int32_t *) addr, delta)) -#define opal_atomic_sub_fetch_size_t(addr, delta) ((size_t) opal_atomic_sub_fetch_32((opal_atomic_int32_t *) addr, delta)) -#define opal_atomic_fetch_sub_size_t(addr, delta) ((size_t) opal_atomic_fetch_sub_32((opal_atomic_int32_t *) addr, delta)) -#elif SIZEOF_SIZE_T == 8 -#define opal_atomic_add_fetch_size_t(addr, delta) ((size_t) opal_atomic_add_fetch_64((opal_atomic_int64_t *) addr, delta)) -#define opal_atomic_fetch_add_size_t(addr, delta) ((size_t) opal_atomic_fetch_add_64((opal_atomic_int64_t *) addr, delta)) -#define opal_atomic_sub_fetch_size_t(addr, delta) ((size_t) opal_atomic_sub_fetch_64((opal_atomic_int64_t *) addr, delta)) -#define opal_atomic_fetch_sub_size_t(addr, delta) ((size_t) opal_atomic_fetch_sub_64((opal_atomic_int64_t *) addr, delta)) -#else -#error "Unknown size_t size" -#endif -#endif - -#if defined(DOXYGEN) || (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) +# else +# if SIZEOF_SIZE_T == 4 +# define opal_atomic_add_fetch_size_t(addr, delta) \ + ((size_t) opal_atomic_add_fetch_32((opal_atomic_int32_t *) addr, delta)) +# define opal_atomic_fetch_add_size_t(addr, delta) \ + ((size_t) opal_atomic_fetch_add_32((opal_atomic_int32_t *) addr, delta)) +# define opal_atomic_sub_fetch_size_t(addr, delta) \ + ((size_t) opal_atomic_sub_fetch_32((opal_atomic_int32_t *) addr, delta)) +# define opal_atomic_fetch_sub_size_t(addr, delta) \ + ((size_t) opal_atomic_fetch_sub_32((opal_atomic_int32_t *) addr, delta)) +# elif SIZEOF_SIZE_T == 8 +# define opal_atomic_add_fetch_size_t(addr, delta) \ + ((size_t) opal_atomic_add_fetch_64((opal_atomic_int64_t *) addr, delta)) +# define opal_atomic_fetch_add_size_t(addr, delta) \ + ((size_t) opal_atomic_fetch_add_64((opal_atomic_int64_t *) addr, delta)) +# define opal_atomic_sub_fetch_size_t(addr, delta) \ + ((size_t) opal_atomic_sub_fetch_64((opal_atomic_int64_t *) addr, delta)) +# define opal_atomic_fetch_sub_size_t(addr, delta) \ + ((size_t) opal_atomic_fetch_sub_64((opal_atomic_int64_t *) addr, delta)) +# else +# error "Unknown size_t size" +# endif +# endif + +# if defined(DOXYGEN) \ + || (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) /* these are always done with inline functions, so always mark as static inline */ -static inline bool opal_atomic_compare_exchange_strong_xx (opal_atomic_intptr_t *addr, intptr_t *oldval, - int64_t newval, size_t length); -static inline bool opal_atomic_compare_exchange_strong_acq_xx (opal_atomic_intptr_t *addr, intptr_t *oldval, - int64_t newval, size_t length); -static inline bool opal_atomic_compare_exchange_strong_rel_xx (opal_atomic_intptr_t *addr, intptr_t *oldval, - int64_t newval, size_t length); - - -static inline bool opal_atomic_compare_exchange_strong_ptr (opal_atomic_intptr_t* addr, intptr_t *oldval, - intptr_t newval); -static inline bool opal_atomic_compare_exchange_strong_acq_ptr (opal_atomic_intptr_t* addr, intptr_t *oldval, - intptr_t newval); -static inline bool opal_atomic_compare_exchange_strong_rel_ptr (opal_atomic_intptr_t* addr, intptr_t *oldval, - intptr_t newval); +static inline bool opal_atomic_compare_exchange_strong_xx(opal_atomic_intptr_t *addr, + intptr_t *oldval, int64_t newval, + size_t length); +static inline bool opal_atomic_compare_exchange_strong_acq_xx(opal_atomic_intptr_t *addr, + intptr_t *oldval, int64_t newval, + size_t length); +static inline bool opal_atomic_compare_exchange_strong_rel_xx(opal_atomic_intptr_t *addr, + intptr_t *oldval, int64_t newval, + size_t length); + +static inline bool opal_atomic_compare_exchange_strong_ptr(opal_atomic_intptr_t *addr, + intptr_t *oldval, intptr_t newval); +static inline bool opal_atomic_compare_exchange_strong_acq_ptr(opal_atomic_intptr_t *addr, + intptr_t *oldval, intptr_t newval); +static inline bool opal_atomic_compare_exchange_strong_rel_ptr(opal_atomic_intptr_t *addr, + intptr_t *oldval, intptr_t newval); /** * Atomic compare and set of generic type with relaxed semantics. This @@ -550,9 +564,10 @@ static inline bool opal_atomic_compare_exchange_strong_rel_ptr (opal_atomic_intp * * See opal_atomic_compare_exchange_* for pseudo-code. */ -#define opal_atomic_compare_exchange_strong( ADDR, OLDVAL, NEWVAL ) \ - opal_atomic_compare_exchange_strong_xx( (opal_atomic_intptr_t*)(ADDR), (intptr_t *)(OLDVAL), \ - (intptr_t)(NEWVAL), sizeof(*(ADDR)) ) +# define opal_atomic_compare_exchange_strong(ADDR, OLDVAL, NEWVAL) \ + opal_atomic_compare_exchange_strong_xx((opal_atomic_intptr_t *) (ADDR), \ + (intptr_t *) (OLDVAL), (intptr_t)(NEWVAL), \ + sizeof(*(ADDR))) /** * Atomic compare and set of generic type with acquire semantics. This @@ -567,9 +582,10 @@ static inline bool opal_atomic_compare_exchange_strong_rel_ptr (opal_atomic_intp * * See opal_atomic_compare_exchange_acq_* for pseudo-code. */ -#define opal_atomic_compare_exchange_strong_acq( ADDR, OLDVAL, NEWVAL ) \ - opal_atomic_compare_exchange_strong_acq_xx( (opal_atomic_intptr_t*)(ADDR), (intptr_t *)(OLDVAL), \ - (intptr_t)(NEWVAL), sizeof(*(ADDR)) ) +# define opal_atomic_compare_exchange_strong_acq(ADDR, OLDVAL, NEWVAL) \ + opal_atomic_compare_exchange_strong_acq_xx((opal_atomic_intptr_t *) (ADDR), \ + (intptr_t *) (OLDVAL), (intptr_t)(NEWVAL), \ + sizeof(*(ADDR))) /** * Atomic compare and set of generic type with release semantics. This @@ -584,24 +600,22 @@ static inline bool opal_atomic_compare_exchange_strong_rel_ptr (opal_atomic_intp * * See opal_atomic_compare_exchange_rel_* for pseudo-code. */ -#define opal_atomic_compare_exchange_strong_rel( ADDR, OLDVAL, NEWVAL ) \ - opal_atomic_compare_exchange_strong_rel_xx( (opal_atomic_intptr_t*)(ADDR), (intptr_t *)(OLDVAL), \ - (intptr_t)(NEWVAL), sizeof(*(ADDR)) ) - +# define opal_atomic_compare_exchange_strong_rel(ADDR, OLDVAL, NEWVAL) \ + opal_atomic_compare_exchange_strong_rel_xx((opal_atomic_intptr_t *) (ADDR), \ + (intptr_t *) (OLDVAL), (intptr_t)(NEWVAL), \ + sizeof(*(ADDR))) -#endif /* (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) */ +# endif /* (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) */ -#if defined(DOXYGEN) || (OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_MATH_64) +# if defined(DOXYGEN) || (OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_MATH_64) -static inline void opal_atomic_add_xx(opal_atomic_intptr_t* addr, - int32_t value, size_t length); -static inline void opal_atomic_sub_xx(opal_atomic_intptr_t* addr, - int32_t value, size_t length); +static inline void opal_atomic_add_xx(opal_atomic_intptr_t *addr, int32_t value, size_t length); +static inline void opal_atomic_sub_xx(opal_atomic_intptr_t *addr, int32_t value, size_t length); -static inline intptr_t opal_atomic_add_fetch_ptr( opal_atomic_intptr_t* addr, void* delta ); -static inline intptr_t opal_atomic_fetch_add_ptr( opal_atomic_intptr_t* addr, void* delta ); -static inline intptr_t opal_atomic_sub_fetch_ptr( opal_atomic_intptr_t* addr, void* delta ); -static inline intptr_t opal_atomic_fetch_sub_ptr( opal_atomic_intptr_t* addr, void* delta ); +static inline intptr_t opal_atomic_add_fetch_ptr(opal_atomic_intptr_t *addr, void *delta); +static inline intptr_t opal_atomic_fetch_add_ptr(opal_atomic_intptr_t *addr, void *delta); +static inline intptr_t opal_atomic_sub_fetch_ptr(opal_atomic_intptr_t *addr, void *delta); +static inline intptr_t opal_atomic_fetch_sub_ptr(opal_atomic_intptr_t *addr, void *delta); /** * Atomically increment the content depending on the type. This @@ -613,9 +627,8 @@ static inline intptr_t opal_atomic_fetch_sub_ptr( opal_atomic_intptr_t* addr, vo * @param addr Address of * @param delta Value to add (converted to ). */ -#define opal_atomic_add( ADDR, VALUE ) \ - opal_atomic_add_xx( (opal_atomic_intptr_t*)(ADDR), (int32_t)(VALUE), \ - sizeof(*(ADDR)) ) +# define opal_atomic_add(ADDR, VALUE) \ + opal_atomic_add_xx((opal_atomic_intptr_t *) (ADDR), (int32_t)(VALUE), sizeof(*(ADDR))) /** * Atomically decrement the content depending on the type. This @@ -627,18 +640,16 @@ static inline intptr_t opal_atomic_fetch_sub_ptr( opal_atomic_intptr_t* addr, vo * @param addr Address of * @param delta Value to substract (converted to ). */ -#define opal_atomic_sub( ADDR, VALUE ) \ - opal_atomic_sub_xx( (opal_atomic_intptr_t*)(ADDR), (int32_t)(VALUE), \ - sizeof(*(ADDR)) ) - -#endif /* OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_MATH_64 */ +# define opal_atomic_sub(ADDR, VALUE) \ + opal_atomic_sub_xx((opal_atomic_intptr_t *) (ADDR), (int32_t)(VALUE), sizeof(*(ADDR))) +# endif /* OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_MATH_64 */ /* * Include inline implementations of everything not defined directly * in assembly */ -#include "opal/sys/atomic_impl.h" +# include "opal/sys/atomic_impl.h" #endif /* !OPAL_C_HAVE__ATOMIC */ @@ -649,38 +660,40 @@ static inline intptr_t opal_atomic_fetch_sub_ptr( opal_atomic_intptr_t* addr, vo * efficient version of the lock-free lifo and fifo. On Apple Silicon the * LL/SC fifo and lifo are ~ 2-20x faster than the CAS128 implementation. */ #if OPAL_ASSEMBLY_ARCH == OPAL_ARM64 -#include "opal/sys/arm64/atomic_llsc.h" +# include "opal/sys/arm64/atomic_llsc.h" #endif #if !defined(OPAL_HAVE_ATOMIC_LLSC_32) -#define OPAL_HAVE_ATOMIC_LLSC_32 0 +# define OPAL_HAVE_ATOMIC_LLSC_32 0 #endif #if !defined(OPAL_HAVE_ATOMIC_LLSC_64) -#define OPAL_HAVE_ATOMIC_LLSC_64 0 +# define OPAL_HAVE_ATOMIC_LLSC_64 0 #endif #if (OPAL_HAVE_ATOMIC_LLSC_32 || OPAL_HAVE_ATOMIC_LLSC_64) -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_LLSC_32 +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_LLSC_32 -#define opal_atomic_ll_ptr(addr, ret) opal_atomic_ll_32((opal_atomic_int32_t *) (addr), ret) -#define opal_atomic_sc_ptr(addr, value, ret) opal_atomic_sc_32((opal_atomic_int32_t *) (addr), (intptr_t) (value), ret) +# define opal_atomic_ll_ptr(addr, ret) opal_atomic_ll_32((opal_atomic_int32_t *) (addr), ret) +# define opal_atomic_sc_ptr(addr, value, ret) \ + opal_atomic_sc_32((opal_atomic_int32_t *) (addr), (intptr_t)(value), ret) -#define OPAL_HAVE_ATOMIC_LLSC_PTR 1 +# define OPAL_HAVE_ATOMIC_LLSC_PTR 1 -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_LLSC_64 +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_LLSC_64 -#define opal_atomic_ll_ptr(addr, ret) opal_atomic_ll_64((opal_atomic_int64_t *) (addr), ret) -#define opal_atomic_sc_ptr(addr, value, ret) opal_atomic_sc_64((opal_atomic_int64_t *) (addr), (intptr_t) (value), ret) +# define opal_atomic_ll_ptr(addr, ret) opal_atomic_ll_64((opal_atomic_int64_t *) (addr), ret) +# define opal_atomic_sc_ptr(addr, value, ret) \ + opal_atomic_sc_64((opal_atomic_int64_t *) (addr), (intptr_t)(value), ret) -#define OPAL_HAVE_ATOMIC_LLSC_PTR 1 +# define OPAL_HAVE_ATOMIC_LLSC_PTR 1 -#endif +# endif #else -#define OPAL_HAVE_ATOMIC_LLSC_PTR 0 +# define OPAL_HAVE_ATOMIC_LLSC_PTR 0 #endif /* (OPAL_HAVE_ATOMIC_LLSC_32 || OPAL_HAVE_ATOMIC_LLSC_64)*/ diff --git a/opal/include/opal/sys/atomic_impl.h b/opal/include/opal/sys/atomic_impl.h index 9df747eede7..d37b456a9f6 100644 --- a/opal/include/opal/sys/atomic_impl.h +++ b/opal/include/opal/sys/atomic_impl.h @@ -39,253 +39,259 @@ *********************************************************************/ #if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 -#if !defined(OPAL_HAVE_ATOMIC_MIN_32) -static inline int32_t opal_atomic_fetch_min_32 (opal_atomic_int32_t *addr, int32_t value) +# if !defined(OPAL_HAVE_ATOMIC_MIN_32) +static inline int32_t opal_atomic_fetch_min_32(opal_atomic_int32_t *addr, int32_t value) { int32_t old = *addr; do { if (old <= value) { break; } - } while (!opal_atomic_compare_exchange_strong_32 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_32(addr, &old, value)); return old; } -#define OPAL_HAVE_ATOMIC_MIN_32 1 +# define OPAL_HAVE_ATOMIC_MIN_32 1 -#endif /* OPAL_HAVE_ATOMIC_MIN_32 */ +# endif /* OPAL_HAVE_ATOMIC_MIN_32 */ -#if !defined(OPAL_HAVE_ATOMIC_MAX_32) -static inline int32_t opal_atomic_fetch_max_32 (opal_atomic_int32_t *addr, int32_t value) +# if !defined(OPAL_HAVE_ATOMIC_MAX_32) +static inline int32_t opal_atomic_fetch_max_32(opal_atomic_int32_t *addr, int32_t value) { int32_t old = *addr; do { if (old >= value) { break; } - } while (!opal_atomic_compare_exchange_strong_32 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_32(addr, &old, value)); return old; } -#define OPAL_HAVE_ATOMIC_MAX_32 1 -#endif /* OPAL_HAVE_ATOMIC_MAX_32 */ - -#define OPAL_ATOMIC_DEFINE_CMPXCG_OP(type, bits, operation, name) \ - static inline type opal_atomic_fetch_ ## name ## _ ## bits (opal_atomic_ ## type *addr, type value) \ - { \ - type oldval; \ - do { \ - oldval = *addr; \ - } while (!opal_atomic_compare_exchange_strong_ ## bits (addr, &oldval, oldval operation value)); \ - \ - return oldval; \ - } +# define OPAL_HAVE_ATOMIC_MAX_32 1 +# endif /* OPAL_HAVE_ATOMIC_MAX_32 */ + +# define OPAL_ATOMIC_DEFINE_CMPXCG_OP(type, bits, operation, name) \ + static inline type opal_atomic_fetch_##name##_##bits(opal_atomic_##type *addr, type value) \ + { \ + type oldval; \ + do { \ + oldval = *addr; \ + } while (!opal_atomic_compare_exchange_strong_##bits(addr, &oldval, \ + oldval operation value)); \ + \ + return oldval; \ + } -#if !defined(OPAL_HAVE_ATOMIC_SWAP_32) -#define OPAL_HAVE_ATOMIC_SWAP_32 1 -static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, - int32_t newval) +# if !defined(OPAL_HAVE_ATOMIC_SWAP_32) +# define OPAL_HAVE_ATOMIC_SWAP_32 1 +static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval) { int32_t old = *addr; do { - } while (!opal_atomic_compare_exchange_strong_32 (addr, &old, newval)); + } while (!opal_atomic_compare_exchange_strong_32(addr, &old, newval)); return old; } -#endif /* OPAL_HAVE_ATOMIC_SWAP_32 */ +# endif /* OPAL_HAVE_ATOMIC_SWAP_32 */ -#if !defined(OPAL_HAVE_ATOMIC_ADD_32) -#define OPAL_HAVE_ATOMIC_ADD_32 1 +# if !defined(OPAL_HAVE_ATOMIC_ADD_32) +# define OPAL_HAVE_ATOMIC_ADD_32 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int32_t, 32, +, add) -#endif /* OPAL_HAVE_ATOMIC_ADD_32 */ +# endif /* OPAL_HAVE_ATOMIC_ADD_32 */ -#if !defined(OPAL_HAVE_ATOMIC_AND_32) -#define OPAL_HAVE_ATOMIC_AND_32 1 +# if !defined(OPAL_HAVE_ATOMIC_AND_32) +# define OPAL_HAVE_ATOMIC_AND_32 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int32_t, 32, &, and) -#endif /* OPAL_HAVE_ATOMIC_AND_32 */ +# endif /* OPAL_HAVE_ATOMIC_AND_32 */ -#if !defined(OPAL_HAVE_ATOMIC_OR_32) -#define OPAL_HAVE_ATOMIC_OR_32 1 +# if !defined(OPAL_HAVE_ATOMIC_OR_32) +# define OPAL_HAVE_ATOMIC_OR_32 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int32_t, 32, |, or) -#endif /* OPAL_HAVE_ATOMIC_OR_32 */ +# endif /* OPAL_HAVE_ATOMIC_OR_32 */ -#if !defined(OPAL_HAVE_ATOMIC_XOR_32) -#define OPAL_HAVE_ATOMIC_XOR_32 1 +# if !defined(OPAL_HAVE_ATOMIC_XOR_32) +# define OPAL_HAVE_ATOMIC_XOR_32 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int32_t, 32, ^, xor) -#endif /* OPAL_HAVE_ATOMIC_XOR_32 */ +# endif /* OPAL_HAVE_ATOMIC_XOR_32 */ - -#if !defined(OPAL_HAVE_ATOMIC_SUB_32) -#define OPAL_HAVE_ATOMIC_SUB_32 1 +# if !defined(OPAL_HAVE_ATOMIC_SUB_32) +# define OPAL_HAVE_ATOMIC_SUB_32 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int32_t, 32, -, sub) -#endif /* OPAL_HAVE_ATOMIC_SUB_32 */ +# endif /* OPAL_HAVE_ATOMIC_SUB_32 */ #endif /* OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 */ - #if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 -#if !defined(OPAL_HAVE_ATOMIC_MIN_64) -static inline int64_t opal_atomic_fetch_min_64 (opal_atomic_int64_t *addr, int64_t value) +# if !defined(OPAL_HAVE_ATOMIC_MIN_64) +static inline int64_t opal_atomic_fetch_min_64(opal_atomic_int64_t *addr, int64_t value) { int64_t old = *addr; do { if (old <= value) { break; } - } while (!opal_atomic_compare_exchange_strong_64 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_64(addr, &old, value)); return old; } -#define OPAL_HAVE_ATOMIC_MIN_64 1 +# define OPAL_HAVE_ATOMIC_MIN_64 1 -#endif /* OPAL_HAVE_ATOMIC_MIN_64 */ +# endif /* OPAL_HAVE_ATOMIC_MIN_64 */ -#if !defined(OPAL_HAVE_ATOMIC_MAX_64) -static inline int64_t opal_atomic_fetch_max_64 (opal_atomic_int64_t *addr, int64_t value) +# if !defined(OPAL_HAVE_ATOMIC_MAX_64) +static inline int64_t opal_atomic_fetch_max_64(opal_atomic_int64_t *addr, int64_t value) { int64_t old = *addr; do { if (old >= value) { break; } - } while (!opal_atomic_compare_exchange_strong_64 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_64(addr, &old, value)); return old; } -#define OPAL_HAVE_ATOMIC_MAX_64 1 -#endif /* OPAL_HAVE_ATOMIC_MAX_64 */ +# define OPAL_HAVE_ATOMIC_MAX_64 1 +# endif /* OPAL_HAVE_ATOMIC_MAX_64 */ -#if !defined(OPAL_HAVE_ATOMIC_SWAP_64) -#define OPAL_HAVE_ATOMIC_SWAP_64 1 -static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, - int64_t newval) +# if !defined(OPAL_HAVE_ATOMIC_SWAP_64) +# define OPAL_HAVE_ATOMIC_SWAP_64 1 +static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval) { int64_t old = *addr; do { - } while (!opal_atomic_compare_exchange_strong_64 (addr, &old, newval)); + } while (!opal_atomic_compare_exchange_strong_64(addr, &old, newval)); return old; } -#endif /* OPAL_HAVE_ATOMIC_SWAP_64 */ +# endif /* OPAL_HAVE_ATOMIC_SWAP_64 */ -#if !defined(OPAL_HAVE_ATOMIC_ADD_64) -#define OPAL_HAVE_ATOMIC_ADD_64 1 +# if !defined(OPAL_HAVE_ATOMIC_ADD_64) +# define OPAL_HAVE_ATOMIC_ADD_64 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int64_t, 64, +, add) -#endif /* OPAL_HAVE_ATOMIC_ADD_64 */ +# endif /* OPAL_HAVE_ATOMIC_ADD_64 */ -#if !defined(OPAL_HAVE_ATOMIC_AND_64) -#define OPAL_HAVE_ATOMIC_AND_64 1 +# if !defined(OPAL_HAVE_ATOMIC_AND_64) +# define OPAL_HAVE_ATOMIC_AND_64 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int64_t, 64, &, and) -#endif /* OPAL_HAVE_ATOMIC_AND_64 */ +# endif /* OPAL_HAVE_ATOMIC_AND_64 */ -#if !defined(OPAL_HAVE_ATOMIC_OR_64) -#define OPAL_HAVE_ATOMIC_OR_64 1 +# if !defined(OPAL_HAVE_ATOMIC_OR_64) +# define OPAL_HAVE_ATOMIC_OR_64 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int64_t, 64, |, or) -#endif /* OPAL_HAVE_ATOMIC_OR_64 */ +# endif /* OPAL_HAVE_ATOMIC_OR_64 */ -#if !defined(OPAL_HAVE_ATOMIC_XOR_64) -#define OPAL_HAVE_ATOMIC_XOR_64 1 +# if !defined(OPAL_HAVE_ATOMIC_XOR_64) +# define OPAL_HAVE_ATOMIC_XOR_64 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int64_t, 64, ^, xor) -#endif /* OPAL_HAVE_ATOMIC_XOR_64 */ +# endif /* OPAL_HAVE_ATOMIC_XOR_64 */ -#if !defined(OPAL_HAVE_ATOMIC_SUB_64) -#define OPAL_HAVE_ATOMIC_SUB_64 1 +# if !defined(OPAL_HAVE_ATOMIC_SUB_64) +# define OPAL_HAVE_ATOMIC_SUB_64 1 OPAL_ATOMIC_DEFINE_CMPXCG_OP(int64_t, 64, -, sub) -#endif /* OPAL_HAVE_ATOMIC_SUB_64 */ +# endif /* OPAL_HAVE_ATOMIC_SUB_64 */ #else -#if !defined(OPAL_HAVE_ATOMIC_ADD_64) -#define OPAL_HAVE_ATOMIC_ADD_64 0 -#endif +# if !defined(OPAL_HAVE_ATOMIC_ADD_64) +# define OPAL_HAVE_ATOMIC_ADD_64 0 +# endif -#if !defined(OPAL_HAVE_ATOMIC_SUB_64) -#define OPAL_HAVE_ATOMIC_SUB_64 0 -#endif +# if !defined(OPAL_HAVE_ATOMIC_SUB_64) +# define OPAL_HAVE_ATOMIC_SUB_64 0 +# endif -#endif /* OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 */ +#endif /* OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 */ #if (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) -#if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 && OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 -#define OPAL_ATOMIC_DEFINE_CMPXCG_XX(semantics) \ - static inline bool \ - opal_atomic_compare_exchange_strong ## semantics ## xx (opal_atomic_intptr_t* addr, intptr_t *oldval, \ - int64_t newval, const size_t length) \ - { \ - switch (length) { \ - case 4: \ - return opal_atomic_compare_exchange_strong_32 ((opal_atomic_int32_t *) addr, \ - (int32_t *) oldval, (int32_t) newval); \ - case 8: \ - return opal_atomic_compare_exchange_strong_64 ((opal_atomic_int64_t *) addr, \ - (int64_t *) oldval, (int64_t) newval); \ - } \ - abort(); \ - } -#elif OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 -#define OPAL_ATOMIC_DEFINE_CMPXCG_XX(semantics) \ - static inline bool \ - opal_atomic_compare_exchange_strong ## semantics ## xx (opal_atomic_intptr_t* addr, intptr_t *oldval, \ - int64_t newval, const size_t length) \ - { \ - switch (length) { \ - case 4: \ - return opal_atomic_compare_exchange_strong_32 ((opal_atomic_int32_t *) addr, \ - (int32_t *) oldval, (int32_t) newval); \ - } \ - abort(); \ - } -#else -#error "Platform does not have required atomic compare-and-swap functionality" -#endif +# if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 && OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 +# define OPAL_ATOMIC_DEFINE_CMPXCG_XX(semantics) \ + static inline bool opal_atomic_compare_exchange_strong##semantics##xx( \ + opal_atomic_intptr_t *addr, intptr_t *oldval, int64_t newval, const size_t length) \ + { \ + switch (length) { \ + case 4: \ + return opal_atomic_compare_exchange_strong_32((opal_atomic_int32_t *) addr, \ + (int32_t *) oldval, \ + (int32_t) newval); \ + case 8: \ + return opal_atomic_compare_exchange_strong_64((opal_atomic_int64_t *) addr, \ + (int64_t *) oldval, \ + (int64_t) newval); \ + } \ + abort(); \ + } +# elif OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 +# define OPAL_ATOMIC_DEFINE_CMPXCG_XX(semantics) \ + static inline bool opal_atomic_compare_exchange_strong##semantics##xx( \ + opal_atomic_intptr_t *addr, intptr_t *oldval, int64_t newval, const size_t length) \ + { \ + switch (length) { \ + case 4: \ + return opal_atomic_compare_exchange_strong_32((opal_atomic_int32_t *) addr, \ + (int32_t *) oldval, \ + (int32_t) newval); \ + } \ + abort(); \ + } +# else +# error "Platform does not have required atomic compare-and-swap functionality" +# endif OPAL_ATOMIC_DEFINE_CMPXCG_XX(_) OPAL_ATOMIC_DEFINE_CMPXCG_XX(_acq_) OPAL_ATOMIC_DEFINE_CMPXCG_XX(_rel_) -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 -#define OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(semantics) \ - static inline bool \ - opal_atomic_compare_exchange_strong ## semantics ## ptr (opal_atomic_intptr_t* addr, intptr_t *oldval, intptr_t newval) \ - { \ - return opal_atomic_compare_exchange_strong_32 ((opal_atomic_int32_t *) addr, (int32_t *) oldval, (int32_t) newval); \ - } -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 -#define OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(semantics) \ - static inline bool \ - opal_atomic_compare_exchange_strong ## semantics ## ptr (opal_atomic_intptr_t* addr, intptr_t *oldval, intptr_t newval) \ - { \ - return opal_atomic_compare_exchange_strong_64 ((opal_atomic_int64_t *) addr, (int64_t *) oldval, (int64_t) newval); \ - } -#else -#error "Can not define opal_atomic_compare_exchange_strong_ptr with existing atomics" -#endif +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 +# define OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(semantics) \ + static inline bool \ + opal_atomic_compare_exchange_strong##semantics##ptr(opal_atomic_intptr_t *addr, \ + intptr_t *oldval, \ + intptr_t newval) \ + { \ + return opal_atomic_compare_exchange_strong_32((opal_atomic_int32_t *) addr, \ + (int32_t *) oldval, \ + (int32_t) newval); \ + } +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 +# define OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(semantics) \ + static inline bool \ + opal_atomic_compare_exchange_strong##semantics##ptr(opal_atomic_intptr_t *addr, \ + intptr_t *oldval, \ + intptr_t newval) \ + { \ + return opal_atomic_compare_exchange_strong_64((opal_atomic_int64_t *) addr, \ + (int64_t *) oldval, \ + (int64_t) newval); \ + } +# else +# error "Can not define opal_atomic_compare_exchange_strong_ptr with existing atomics" +# endif OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(_) OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(_acq_) @@ -293,69 +299,68 @@ OPAL_ATOMIC_DEFINE_CMPXCG_PTR_XX(_rel_) #endif /* (OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 || OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64) */ - #if (OPAL_HAVE_ATOMIC_SWAP_32 || OPAL_HAVE_ATOMIC_SWAP_64) -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_SWAP_32 -#define opal_atomic_swap_ptr(addr, value) (intptr_t) opal_atomic_swap_32((opal_atomic_int32_t *) addr, (int32_t) value) -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_SWAP_64 -#define opal_atomic_swap_ptr(addr, value) (intptr_t) opal_atomic_swap_64((opal_atomic_int64_t *) addr, (int64_t) value) -#endif +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_SWAP_32 +# define opal_atomic_swap_ptr(addr, value) \ + (intptr_t) opal_atomic_swap_32((opal_atomic_int32_t *) addr, (int32_t) value) +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_SWAP_64 +# define opal_atomic_swap_ptr(addr, value) \ + (intptr_t) opal_atomic_swap_64((opal_atomic_int64_t *) addr, (int64_t) value) +# endif #endif /* (OPAL_HAVE_ATOMIC_SWAP_32 || OPAL_HAVE_ATOMIC_SWAP_64) */ #if OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_MATH_64 -static inline void - opal_atomic_add_xx(opal_atomic_intptr_t* addr, int32_t value, size_t length) +static inline void opal_atomic_add_xx(opal_atomic_intptr_t *addr, int32_t value, size_t length) { - switch( length ) { -#if OPAL_HAVE_ATOMIC_ADD_32 - case 4: - (void) opal_atomic_fetch_add_32( (opal_atomic_int32_t*)addr, (int32_t)value ); - break; -#endif /* OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 */ - -#if OPAL_HAVE_ATOMIC_ADD_64 - case 8: - (void) opal_atomic_fetch_add_64( (opal_atomic_int64_t*)addr, (int64_t)value ); - break; -#endif /* OPAL_HAVE_ATOMIC_ADD_64 */ - default: - /* This should never happen, so deliberately abort (hopefully - leaving a corefile for analysis) */ - abort(); - } + switch (length) { +# if OPAL_HAVE_ATOMIC_ADD_32 + case 4: + (void) opal_atomic_fetch_add_32((opal_atomic_int32_t *) addr, (int32_t) value); + break; +# endif /* OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 */ + +# if OPAL_HAVE_ATOMIC_ADD_64 + case 8: + (void) opal_atomic_fetch_add_64((opal_atomic_int64_t *) addr, (int64_t) value); + break; +# endif /* OPAL_HAVE_ATOMIC_ADD_64 */ + default: + /* This should never happen, so deliberately abort (hopefully + leaving a corefile for analysis) */ + abort(); + } } - -static inline void -opal_atomic_sub_xx(opal_atomic_intptr_t* addr, int32_t value, size_t length) +static inline void opal_atomic_sub_xx(opal_atomic_intptr_t *addr, int32_t value, size_t length) { - switch( length ) { -#if OPAL_HAVE_ATOMIC_SUB_32 - case 4: - (void) opal_atomic_fetch_sub_32( (opal_atomic_int32_t*)addr, (int32_t)value ); - break; -#endif /* OPAL_HAVE_ATOMIC_SUB_32 */ - -#if OPAL_HAVE_ATOMIC_SUB_64 - case 8: - (void) opal_atomic_fetch_sub_64( (opal_atomic_int64_t*)addr, (int64_t)value ); - break; -#endif /* OPAL_HAVE_ATOMIC_SUB_64 */ - default: - /* This should never happen, so deliberately abort (hopefully - leaving a corefile for analysis) */ - abort(); - } + switch (length) { +# if OPAL_HAVE_ATOMIC_SUB_32 + case 4: + (void) opal_atomic_fetch_sub_32((opal_atomic_int32_t *) addr, (int32_t) value); + break; +# endif /* OPAL_HAVE_ATOMIC_SUB_32 */ + +# if OPAL_HAVE_ATOMIC_SUB_64 + case 8: + (void) opal_atomic_fetch_sub_64((opal_atomic_int64_t *) addr, (int64_t) value); + break; +# endif /* OPAL_HAVE_ATOMIC_SUB_64 */ + default: + /* This should never happen, so deliberately abort (hopefully + leaving a corefile for analysis) */ + abort(); + } } -#define OPAL_ATOMIC_DEFINE_OP_FETCH(op, operation, type, ptr_type, suffix) \ - static inline type opal_atomic_ ## op ## _fetch_ ## suffix (opal_atomic_ ## ptr_type *addr, type value) \ - { \ - return opal_atomic_fetch_ ## op ## _ ## suffix (addr, value) operation value; \ - } +# define OPAL_ATOMIC_DEFINE_OP_FETCH(op, operation, type, ptr_type, suffix) \ + static inline type opal_atomic_##op##_fetch_##suffix(opal_atomic_##ptr_type *addr, \ + type value) \ + { \ + return opal_atomic_fetch_##op##_##suffix(addr, value) operation value; \ + } OPAL_ATOMIC_DEFINE_OP_FETCH(add, +, int32_t, int32_t, 32) OPAL_ATOMIC_DEFINE_OP_FETCH(and, &, int32_t, int32_t, 32) @@ -363,89 +368,85 @@ OPAL_ATOMIC_DEFINE_OP_FETCH(or, |, int32_t, int32_t, 32) OPAL_ATOMIC_DEFINE_OP_FETCH(xor, ^, int32_t, int32_t, 32) OPAL_ATOMIC_DEFINE_OP_FETCH(sub, -, int32_t, int32_t, 32) -static inline int32_t opal_atomic_min_fetch_32 (opal_atomic_int32_t *addr, int32_t value) +static inline int32_t opal_atomic_min_fetch_32(opal_atomic_int32_t *addr, int32_t value) { - int32_t old = opal_atomic_fetch_min_32 (addr, value); + int32_t old = opal_atomic_fetch_min_32(addr, value); return old <= value ? old : value; } -static inline int32_t opal_atomic_max_fetch_32 (opal_atomic_int32_t *addr, int32_t value) +static inline int32_t opal_atomic_max_fetch_32(opal_atomic_int32_t *addr, int32_t value) { - int32_t old = opal_atomic_fetch_max_32 (addr, value); + int32_t old = opal_atomic_fetch_max_32(addr, value); return old >= value ? old : value; } -#if OPAL_HAVE_ATOMIC_MATH_64 +# if OPAL_HAVE_ATOMIC_MATH_64 OPAL_ATOMIC_DEFINE_OP_FETCH(add, +, int64_t, int64_t, 64) OPAL_ATOMIC_DEFINE_OP_FETCH(and, &, int64_t, int64_t, 64) OPAL_ATOMIC_DEFINE_OP_FETCH(or, |, int64_t, int64_t, 64) OPAL_ATOMIC_DEFINE_OP_FETCH(xor, ^, int64_t, int64_t, 64) OPAL_ATOMIC_DEFINE_OP_FETCH(sub, -, int64_t, int64_t, 64) -static inline int64_t opal_atomic_min_fetch_64 (opal_atomic_int64_t *addr, int64_t value) +static inline int64_t opal_atomic_min_fetch_64(opal_atomic_int64_t *addr, int64_t value) { - int64_t old = opal_atomic_fetch_min_64 (addr, value); + int64_t old = opal_atomic_fetch_min_64(addr, value); return old <= value ? old : value; } -static inline int64_t opal_atomic_max_fetch_64 (opal_atomic_int64_t *addr, int64_t value) +static inline int64_t opal_atomic_max_fetch_64(opal_atomic_int64_t *addr, int64_t value) { - int64_t old = opal_atomic_fetch_max_64 (addr, value); + int64_t old = opal_atomic_fetch_max_64(addr, value); return old >= value ? old : value; } -#endif +# endif -static inline intptr_t opal_atomic_fetch_add_ptr( opal_atomic_intptr_t* addr, - void* delta ) +static inline intptr_t opal_atomic_fetch_add_ptr(opal_atomic_intptr_t *addr, void *delta) { -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_ADD_32 - return opal_atomic_fetch_add_32((opal_atomic_int32_t*) addr, (unsigned long) delta); -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_ADD_64 - return opal_atomic_fetch_add_64((opal_atomic_int64_t*) addr, (unsigned long) delta); -#else - abort (); +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_ADD_32 + return opal_atomic_fetch_add_32((opal_atomic_int32_t *) addr, (unsigned long) delta); +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_ADD_64 + return opal_atomic_fetch_add_64((opal_atomic_int64_t *) addr, (unsigned long) delta); +# else + abort(); return 0; -#endif +# endif } -static inline intptr_t opal_atomic_add_fetch_ptr( opal_atomic_intptr_t* addr, - void* delta ) +static inline intptr_t opal_atomic_add_fetch_ptr(opal_atomic_intptr_t *addr, void *delta) { -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_ADD_32 - return opal_atomic_add_fetch_32((opal_atomic_int32_t*) addr, (unsigned long) delta); -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_ADD_64 - return opal_atomic_add_fetch_64((opal_atomic_int64_t*) addr, (unsigned long) delta); -#else - abort (); +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_ADD_32 + return opal_atomic_add_fetch_32((opal_atomic_int32_t *) addr, (unsigned long) delta); +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_ADD_64 + return opal_atomic_add_fetch_64((opal_atomic_int64_t *) addr, (unsigned long) delta); +# else + abort(); return 0; -#endif +# endif } -static inline intptr_t opal_atomic_fetch_sub_ptr( opal_atomic_intptr_t* addr, - void* delta ) +static inline intptr_t opal_atomic_fetch_sub_ptr(opal_atomic_intptr_t *addr, void *delta) { -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_SUB_32 - return opal_atomic_fetch_sub_32((opal_atomic_int32_t*) addr, (unsigned long) delta); -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_SUB_32 - return opal_atomic_fetch_sub_64((opal_atomic_int64_t*) addr, (unsigned long) delta); -#else +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_SUB_32 + return opal_atomic_fetch_sub_32((opal_atomic_int32_t *) addr, (unsigned long) delta); +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_SUB_32 + return opal_atomic_fetch_sub_64((opal_atomic_int64_t *) addr, (unsigned long) delta); +# else abort(); return 0; -#endif +# endif } -static inline intptr_t opal_atomic_sub_fetch_ptr( opal_atomic_intptr_t* addr, - void* delta ) +static inline intptr_t opal_atomic_sub_fetch_ptr(opal_atomic_intptr_t *addr, void *delta) { -#if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_SUB_32 - return opal_atomic_sub_fetch_32((opal_atomic_int32_t*) addr, (unsigned long) delta); -#elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_SUB_32 - return opal_atomic_sub_fetch_64((opal_atomic_int64_t*) addr, (unsigned long) delta); -#else +# if SIZEOF_VOID_P == 4 && OPAL_HAVE_ATOMIC_SUB_32 + return opal_atomic_sub_fetch_32((opal_atomic_int32_t *) addr, (unsigned long) delta); +# elif SIZEOF_VOID_P == 8 && OPAL_HAVE_ATOMIC_SUB_32 + return opal_atomic_sub_fetch_64((opal_atomic_int64_t *) addr, (unsigned long) delta); +# else abort(); return 0; -#endif +# endif } #endif /* OPAL_HAVE_ATOMIC_MATH_32 || OPAL_HAVE_ATOMIC_MATH_64 */ @@ -460,38 +461,32 @@ static inline intptr_t opal_atomic_sub_fetch_ptr( opal_atomic_intptr_t* addr, /* * Lock initialization function. It set the lock to UNLOCKED. */ -static inline void -opal_atomic_lock_init( opal_atomic_lock_t* lock, int32_t value ) +static inline void opal_atomic_lock_init(opal_atomic_lock_t *lock, int32_t value) { - lock->u.lock = value; + lock->u.lock = value; } - -static inline int -opal_atomic_trylock(opal_atomic_lock_t *lock) +static inline int opal_atomic_trylock(opal_atomic_lock_t *lock) { int32_t unlocked = OPAL_ATOMIC_LOCK_UNLOCKED; - bool ret = opal_atomic_compare_exchange_strong_acq_32 (&lock->u.lock, &unlocked, OPAL_ATOMIC_LOCK_LOCKED); + bool ret = opal_atomic_compare_exchange_strong_acq_32(&lock->u.lock, &unlocked, + OPAL_ATOMIC_LOCK_LOCKED); return (ret == false) ? 1 : 0; } - -static inline void -opal_atomic_lock(opal_atomic_lock_t *lock) +static inline void opal_atomic_lock(opal_atomic_lock_t *lock) { - while (opal_atomic_trylock (lock)) { + while (opal_atomic_trylock(lock)) { while (lock->u.lock == OPAL_ATOMIC_LOCK_LOCKED) { - /* spin */ ; + /* spin */; } } } - -static inline void -opal_atomic_unlock(opal_atomic_lock_t *lock) +static inline void opal_atomic_unlock(opal_atomic_lock_t *lock) { - opal_atomic_wmb(); - lock->u.lock=OPAL_ATOMIC_LOCK_UNLOCKED; + opal_atomic_wmb(); + lock->u.lock = OPAL_ATOMIC_LOCK_UNLOCKED; } #endif /* OPAL_HAVE_ATOMIC_SPINLOCKS */ diff --git a/opal/include/opal/sys/atomic_stdc.h b/opal/include/opal/sys/atomic_stdc.h index 1c31df8b7b2..2cb92f2b9f4 100644 --- a/opal/include/opal/sys/atomic_stdc.h +++ b/opal/include/opal/sys/atomic_stdc.h @@ -24,93 +24,120 @@ * definitions to be worthwhile. */ #if !defined(OPAL_ATOMIC_STDC_H) -#define OPAL_ATOMIC_STDC_H +# define OPAL_ATOMIC_STDC_H -#include -#include -#include "opal_stdint.h" +# include "opal_stdint.h" +# include +# include -#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 +# define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 -#define OPAL_HAVE_ATOMIC_SWAP_32 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 +# define OPAL_HAVE_ATOMIC_SWAP_32 1 -#define OPAL_HAVE_ATOMIC_MATH_32 1 -#define OPAL_HAVE_ATOMIC_ADD_32 1 -#define OPAL_HAVE_ATOMIC_AND_32 1 -#define OPAL_HAVE_ATOMIC_OR_32 1 -#define OPAL_HAVE_ATOMIC_XOR_32 1 -#define OPAL_HAVE_ATOMIC_SUB_32 1 +# define OPAL_HAVE_ATOMIC_MATH_32 1 +# define OPAL_HAVE_ATOMIC_ADD_32 1 +# define OPAL_HAVE_ATOMIC_AND_32 1 +# define OPAL_HAVE_ATOMIC_OR_32 1 +# define OPAL_HAVE_ATOMIC_XOR_32 1 +# define OPAL_HAVE_ATOMIC_SUB_32 1 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 -#define OPAL_HAVE_ATOMIC_SWAP_64 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 +# define OPAL_HAVE_ATOMIC_SWAP_64 1 -#define OPAL_HAVE_ATOMIC_MATH_64 1 -#define OPAL_HAVE_ATOMIC_ADD_64 1 -#define OPAL_HAVE_ATOMIC_AND_64 1 -#define OPAL_HAVE_ATOMIC_OR_64 1 -#define OPAL_HAVE_ATOMIC_XOR_64 1 -#define OPAL_HAVE_ATOMIC_SUB_64 1 +# define OPAL_HAVE_ATOMIC_MATH_64 1 +# define OPAL_HAVE_ATOMIC_ADD_64 1 +# define OPAL_HAVE_ATOMIC_AND_64 1 +# define OPAL_HAVE_ATOMIC_OR_64 1 +# define OPAL_HAVE_ATOMIC_XOR_64 1 +# define OPAL_HAVE_ATOMIC_SUB_64 1 -#define OPAL_HAVE_ATOMIC_MIN_32 1 -#define OPAL_HAVE_ATOMIC_MAX_32 1 +# define OPAL_HAVE_ATOMIC_MIN_32 1 +# define OPAL_HAVE_ATOMIC_MAX_32 1 -#define OPAL_HAVE_ATOMIC_MIN_64 1 -#define OPAL_HAVE_ATOMIC_MAX_64 1 +# define OPAL_HAVE_ATOMIC_MIN_64 1 +# define OPAL_HAVE_ATOMIC_MAX_64 1 -#define OPAL_HAVE_ATOMIC_SPINLOCKS 1 +# define OPAL_HAVE_ATOMIC_SPINLOCKS 1 -static inline void opal_atomic_mb (void) +static inline void opal_atomic_mb(void) { - atomic_thread_fence (memory_order_seq_cst); + atomic_thread_fence(memory_order_seq_cst); } -static inline void opal_atomic_wmb (void) +static inline void opal_atomic_wmb(void) { - atomic_thread_fence (memory_order_release); + atomic_thread_fence(memory_order_release); } -static inline void opal_atomic_rmb (void) +static inline void opal_atomic_rmb(void) { -#if OPAL_ASSEMBLY_ARCH == OPAL_X86_64 +# if OPAL_ASSEMBLY_ARCH == OPAL_X86_64 /* work around a bug in older gcc versions (observed in gcc 6.x) * where acquire seems to get treated as a no-op instead of being * equivalent to __asm__ __volatile__("": : :"memory") on x86_64 */ - opal_atomic_mb (); -#else - atomic_thread_fence (memory_order_acquire); -#endif + opal_atomic_mb(); +# else + atomic_thread_fence(memory_order_acquire); +# endif } -#define opal_atomic_compare_exchange_strong_32(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_relaxed, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_64(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_relaxed, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_ptr(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_relaxed, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_acq_32(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_acquire, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_acq_64(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_acquire, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_acq_ptr(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_acquire, memory_order_relaxed) - -#define opal_atomic_compare_exchange_strong_rel_32(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_release, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_rel_64(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_release, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_rel_ptr(addr, compare, value) atomic_compare_exchange_strong_explicit (addr, compare, value, memory_order_release, memory_order_relaxed) - -#define opal_atomic_compare_exchange_strong(addr, oldval, newval) atomic_compare_exchange_strong_explicit (addr, oldval, newval, memory_order_relaxed, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_acq(addr, oldval, newval) atomic_compare_exchange_strong_explicit (addr, oldval, newval, memory_order_acquire, memory_order_relaxed) -#define opal_atomic_compare_exchange_strong_rel(addr, oldval, newval) atomic_compare_exchange_strong_explicit (addr, oldval, newval, memory_order_release, memory_order_relaxed) - -#define opal_atomic_swap_32(addr, value) atomic_exchange_explicit ((_Atomic unsigned int *)addr, value, memory_order_relaxed) -#define opal_atomic_swap_64(addr, value) atomic_exchange_explicit ((_Atomic unsigned long *)addr, value, memory_order_relaxed) -#define opal_atomic_swap_ptr(addr, value) atomic_exchange_explicit ((_Atomic unsigned long *)addr, value, memory_order_relaxed) - -#define OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(op, bits, type, operator) \ - static inline type opal_atomic_fetch_ ## op ##_## bits (opal_atomic_ ## type *addr, type value) \ - { \ - return atomic_fetch_ ## op ## _explicit (addr, value, memory_order_relaxed); \ - } \ - \ - static inline type opal_atomic_## op ## _fetch_ ## bits (opal_atomic_ ## type *addr, type value) \ - { \ - return atomic_fetch_ ## op ## _explicit (addr, value, memory_order_relaxed) operator value; \ - } +# define opal_atomic_compare_exchange_strong_32(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_relaxed, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_64(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_relaxed, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_ptr(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_relaxed, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_acq_32(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_acquire, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_acq_64(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_acquire, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_acq_ptr(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_acquire, \ + memory_order_relaxed) + +# define opal_atomic_compare_exchange_strong_rel_32(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_release, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_rel_64(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_release, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_rel_ptr(addr, compare, value) \ + atomic_compare_exchange_strong_explicit(addr, compare, value, memory_order_release, \ + memory_order_relaxed) + +# define opal_atomic_compare_exchange_strong(addr, oldval, newval) \ + atomic_compare_exchange_strong_explicit(addr, oldval, newval, memory_order_relaxed, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_acq(addr, oldval, newval) \ + atomic_compare_exchange_strong_explicit(addr, oldval, newval, memory_order_acquire, \ + memory_order_relaxed) +# define opal_atomic_compare_exchange_strong_rel(addr, oldval, newval) \ + atomic_compare_exchange_strong_explicit(addr, oldval, newval, memory_order_release, \ + memory_order_relaxed) + +# define opal_atomic_swap_32(addr, value) \ + atomic_exchange_explicit((_Atomic unsigned int *) addr, value, memory_order_relaxed) +# define opal_atomic_swap_64(addr, value) \ + atomic_exchange_explicit((_Atomic unsigned long *) addr, value, memory_order_relaxed) +# define opal_atomic_swap_ptr(addr, value) \ + atomic_exchange_explicit((_Atomic unsigned long *) addr, value, memory_order_relaxed) + +# define OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(op, bits, type, operator) \ + static inline type opal_atomic_fetch_##op##_##bits(opal_atomic_##type *addr, type value) \ + { \ + return atomic_fetch_##op##_explicit(addr, value, memory_order_relaxed); \ + } \ + \ + static inline type opal_atomic_##op##_fetch_##bits(opal_atomic_##type *addr, type value) \ + { \ + return atomic_fetch_##op##_explicit(addr, value, memory_order_relaxed) operator value; \ + } OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(add, 32, int32_t, +) OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(add, 64, int64_t, +) @@ -129,141 +156,139 @@ OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(xor, 64, int64_t, ^) OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(and, 32, int32_t, &) OPAL_ATOMIC_STDC_DEFINE_FETCH_OP(and, 64, int64_t, &) -#define opal_atomic_add(addr, value) (void) atomic_fetch_add_explicit (addr, value, memory_order_relaxed) +# define opal_atomic_add(addr, value) \ + (void) atomic_fetch_add_explicit(addr, value, memory_order_relaxed) -static inline int32_t opal_atomic_fetch_min_32 (opal_atomic_int32_t *addr, int32_t value) +static inline int32_t opal_atomic_fetch_min_32(opal_atomic_int32_t *addr, int32_t value) { int32_t old = *addr; do { if (old <= value) { break; } - } while (!opal_atomic_compare_exchange_strong_32 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_32(addr, &old, value)); return old; } -static inline int32_t opal_atomic_fetch_max_32 (opal_atomic_int32_t *addr, int32_t value) +static inline int32_t opal_atomic_fetch_max_32(opal_atomic_int32_t *addr, int32_t value) { int32_t old = *addr; do { if (old >= value) { break; } - } while (!opal_atomic_compare_exchange_strong_32 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_32(addr, &old, value)); return old; } -static inline int64_t opal_atomic_fetch_min_64 (opal_atomic_int64_t *addr, int64_t value) +static inline int64_t opal_atomic_fetch_min_64(opal_atomic_int64_t *addr, int64_t value) { int64_t old = *addr; do { if (old <= value) { break; } - } while (!opal_atomic_compare_exchange_strong_64 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_64(addr, &old, value)); return old; } -static inline int64_t opal_atomic_fetch_max_64 (opal_atomic_int64_t *addr, int64_t value) +static inline int64_t opal_atomic_fetch_max_64(opal_atomic_int64_t *addr, int64_t value) { int64_t old = *addr; do { if (old >= value) { break; } - } while (!opal_atomic_compare_exchange_strong_64 (addr, &old, value)); + } while (!opal_atomic_compare_exchange_strong_64(addr, &old, value)); return old; } -static inline int32_t opal_atomic_min_fetch_32 (opal_atomic_int32_t *addr, int32_t value) +static inline int32_t opal_atomic_min_fetch_32(opal_atomic_int32_t *addr, int32_t value) { - int32_t old = opal_atomic_fetch_min_32 (addr, value); + int32_t old = opal_atomic_fetch_min_32(addr, value); return old <= value ? old : value; } -static inline int32_t opal_atomic_max_fetch_32 (opal_atomic_int32_t *addr, int32_t value) +static inline int32_t opal_atomic_max_fetch_32(opal_atomic_int32_t *addr, int32_t value) { - int32_t old = opal_atomic_fetch_max_32 (addr, value); + int32_t old = opal_atomic_fetch_max_32(addr, value); return old >= value ? old : value; } -static inline int64_t opal_atomic_min_fetch_64 (opal_atomic_int64_t *addr, int64_t value) +static inline int64_t opal_atomic_min_fetch_64(opal_atomic_int64_t *addr, int64_t value) { - int64_t old = opal_atomic_fetch_min_64 (addr, value); + int64_t old = opal_atomic_fetch_min_64(addr, value); return old <= value ? old : value; } -static inline int64_t opal_atomic_max_fetch_64 (opal_atomic_int64_t *addr, int64_t value) +static inline int64_t opal_atomic_max_fetch_64(opal_atomic_int64_t *addr, int64_t value) { - int64_t old = opal_atomic_fetch_max_64 (addr, value); + int64_t old = opal_atomic_fetch_max_64(addr, value); return old >= value ? old : value; } -#define OPAL_ATOMIC_LOCK_UNLOCKED false -#define OPAL_ATOMIC_LOCK_LOCKED true +# define OPAL_ATOMIC_LOCK_UNLOCKED false +# define OPAL_ATOMIC_LOCK_LOCKED true -#define OPAL_ATOMIC_LOCK_INIT ATOMIC_FLAG_INIT +# define OPAL_ATOMIC_LOCK_INIT ATOMIC_FLAG_INIT typedef atomic_flag opal_atomic_lock_t; /* * Lock initialization function. It set the lock to UNLOCKED. */ -static inline void opal_atomic_lock_init (opal_atomic_lock_t *lock, bool value) +static inline void opal_atomic_lock_init(opal_atomic_lock_t *lock, bool value) { - atomic_flag_clear (lock); + atomic_flag_clear(lock); } - -static inline int opal_atomic_trylock (opal_atomic_lock_t *lock) +static inline int opal_atomic_trylock(opal_atomic_lock_t *lock) { - return (int) atomic_flag_test_and_set (lock); + return (int) atomic_flag_test_and_set(lock); } - static inline void opal_atomic_lock(opal_atomic_lock_t *lock) { - while (opal_atomic_trylock (lock)) { + while (opal_atomic_trylock(lock)) { } } - -static inline void opal_atomic_unlock (opal_atomic_lock_t *lock) +static inline void opal_atomic_unlock(opal_atomic_lock_t *lock) { - atomic_flag_clear (lock); + atomic_flag_clear(lock); } - -#if OPAL_HAVE_C11_CSWAP_INT128 +# if OPAL_HAVE_C11_CSWAP_INT128 /* the C11 atomic compare-exchange is lock free so use it */ -#define opal_atomic_compare_exchange_strong_128 atomic_compare_exchange_strong +# define opal_atomic_compare_exchange_strong_128 atomic_compare_exchange_strong -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 -#elif OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128 +# elif OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128 -/* fall back on the __sync builtin if available since it will emit the expected instruction on x86_64 (cmpxchng16b) */ -__opal_attribute_always_inline__ -static inline bool opal_atomic_compare_exchange_strong_128 (opal_atomic_int128_t *addr, - opal_int128_t *oldval, opal_int128_t newval) +/* fall back on the __sync builtin if available since it will emit the expected instruction on + * x86_64 (cmpxchng16b) */ +__opal_attribute_always_inline__ static inline bool +opal_atomic_compare_exchange_strong_128(opal_atomic_int128_t *addr, opal_int128_t *oldval, + opal_int128_t newval) { - opal_int128_t prev = __sync_val_compare_and_swap (addr, *oldval, newval); + opal_int128_t prev = __sync_val_compare_and_swap(addr, *oldval, newval); bool ret = prev == *oldval; *oldval = prev; return ret; } -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 -#else +# else -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 0 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 0 -#endif +# endif #endif /* !defined(OPAL_ATOMIC_STDC_H) */ diff --git a/opal/include/opal/sys/cma.h b/opal/include/opal/sys/cma.h index 273b482e4c3..e5b4961613e 100644 --- a/opal/include/opal/sys/cma.h +++ b/opal/include/opal/sys/cma.h @@ -21,72 +21,63 @@ #if !defined(OPAL_ASSEMBLY_ARCH) /* need opal_config.h for the assembly architecture */ -#include "opal_config.h" +# include "opal_config.h" #endif #include "opal/sys/architecture.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef __linux__ /* Cross Memory Attach is so far only supported under linux */ -#if OPAL_ASSEMBLY_ARCH == OPAL_X86_64 -#define __NR_process_vm_readv 310 -#define __NR_process_vm_writev 311 -#elif OPAL_ASSEMBLY_ARCH == OPAL_IA32 -#define __NR_process_vm_readv 347 -#define __NR_process_vm_writev 348 -#elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32 -#define __NR_process_vm_readv 351 -#define __NR_process_vm_writev 352 -#elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64 -#define __NR_process_vm_readv 351 -#define __NR_process_vm_writev 352 -#elif OPAL_ASSEMBLY_ARCH == OPAL_ARM - -#define __NR_process_vm_readv 376 -#define __NR_process_vm_writev 377 - -#elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 +# if OPAL_ASSEMBLY_ARCH == OPAL_X86_64 +# define __NR_process_vm_readv 310 +# define __NR_process_vm_writev 311 +# elif OPAL_ASSEMBLY_ARCH == OPAL_IA32 +# define __NR_process_vm_readv 347 +# define __NR_process_vm_writev 348 +# elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32 +# define __NR_process_vm_readv 351 +# define __NR_process_vm_writev 352 +# elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64 +# define __NR_process_vm_readv 351 +# define __NR_process_vm_writev 352 +# elif OPAL_ASSEMBLY_ARCH == OPAL_ARM + +# define __NR_process_vm_readv 376 +# define __NR_process_vm_writev 377 + +# elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 /* ARM64 uses the asm-generic syscall numbers */ -#define __NR_process_vm_readv 270 -#define __NR_process_vm_writev 271 - -#else -#error "Unsupported architecture for process_vm_readv and process_vm_writev syscalls" -#endif +# define __NR_process_vm_readv 270 +# define __NR_process_vm_writev 271 +# else +# error "Unsupported architecture for process_vm_readv and process_vm_writev syscalls" +# endif -static inline ssize_t -process_vm_readv(pid_t pid, - const struct iovec *lvec, - unsigned long liovcnt, - const struct iovec *rvec, - unsigned long riovcnt, - unsigned long flags) +static inline ssize_t process_vm_readv(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, + const struct iovec *rvec, unsigned long riovcnt, + unsigned long flags) { - return syscall(__NR_process_vm_readv, pid, lvec, liovcnt, rvec, riovcnt, flags); + return syscall(__NR_process_vm_readv, pid, lvec, liovcnt, rvec, riovcnt, flags); } -static inline ssize_t -process_vm_writev(pid_t pid, - const struct iovec *lvec, - unsigned long liovcnt, - const struct iovec *rvec, - unsigned long riovcnt, - unsigned long flags) +static inline ssize_t process_vm_writev(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, + const struct iovec *rvec, unsigned long riovcnt, + unsigned long flags) { - return syscall(__NR_process_vm_writev, pid, lvec, liovcnt, rvec, riovcnt, flags); + return syscall(__NR_process_vm_writev, pid, lvec, liovcnt, rvec, riovcnt, flags); } #endif /* __linux__ */ diff --git a/opal/include/opal/sys/gcc_builtin/atomic.h b/opal/include/opal/sys/gcc_builtin/atomic.h index 7ff295bdc80..1b26a38dcd3 100644 --- a/opal/include/opal/sys/gcc_builtin/atomic.h +++ b/opal/include/opal/sys/gcc_builtin/atomic.h @@ -34,27 +34,26 @@ *********************************************************************/ #define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 -#define OPAL_HAVE_ATOMIC_MATH_32 1 +#define OPAL_HAVE_ATOMIC_MATH_32 1 #define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 -#define OPAL_HAVE_ATOMIC_ADD_32 1 -#define OPAL_HAVE_ATOMIC_AND_32 1 -#define OPAL_HAVE_ATOMIC_OR_32 1 -#define OPAL_HAVE_ATOMIC_XOR_32 1 -#define OPAL_HAVE_ATOMIC_SUB_32 1 -#define OPAL_HAVE_ATOMIC_SWAP_32 1 -#define OPAL_HAVE_ATOMIC_MATH_64 1 +#define OPAL_HAVE_ATOMIC_ADD_32 1 +#define OPAL_HAVE_ATOMIC_AND_32 1 +#define OPAL_HAVE_ATOMIC_OR_32 1 +#define OPAL_HAVE_ATOMIC_XOR_32 1 +#define OPAL_HAVE_ATOMIC_SUB_32 1 +#define OPAL_HAVE_ATOMIC_SWAP_32 1 +#define OPAL_HAVE_ATOMIC_MATH_64 1 #define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 -#define OPAL_HAVE_ATOMIC_ADD_64 1 -#define OPAL_HAVE_ATOMIC_AND_64 1 -#define OPAL_HAVE_ATOMIC_OR_64 1 -#define OPAL_HAVE_ATOMIC_XOR_64 1 -#define OPAL_HAVE_ATOMIC_SUB_64 1 -#define OPAL_HAVE_ATOMIC_SWAP_64 1 - +#define OPAL_HAVE_ATOMIC_ADD_64 1 +#define OPAL_HAVE_ATOMIC_AND_64 1 +#define OPAL_HAVE_ATOMIC_OR_64 1 +#define OPAL_HAVE_ATOMIC_XOR_64 1 +#define OPAL_HAVE_ATOMIC_SUB_64 1 +#define OPAL_HAVE_ATOMIC_SWAP_64 1 static inline void opal_atomic_mb(void) { - __atomic_thread_fence (__ATOMIC_SEQ_CST); + __atomic_thread_fence(__ATOMIC_SEQ_CST); } static inline void opal_atomic_rmb(void) @@ -62,15 +61,15 @@ static inline void opal_atomic_rmb(void) #if OPAL_ASSEMBLY_ARCH == OPAL_X86_64 /* work around a bug in older gcc versions where ACQUIRE seems to get * treated as a no-op instead */ - __asm__ __volatile__("": : :"memory"); + __asm__ __volatile__("" : : : "memory"); #else - __atomic_thread_fence (__ATOMIC_ACQUIRE); + __atomic_thread_fence(__ATOMIC_ACQUIRE); #endif } static inline void opal_atomic_wmb(void) { - __atomic_thread_fence (__ATOMIC_RELEASE); + __atomic_thread_fence(__ATOMIC_RELEASE); } #define MB() opal_atomic_mb() @@ -84,128 +83,140 @@ static inline void opal_atomic_wmb(void) /* * Suppress numerous (spurious ?) warnings from Oracle Studio compilers * see https://community.oracle.com/thread/3968347 - */ + */ #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) -#pragma error_messages(off, E_ARG_INCOMPATIBLE_WITH_ARG_L) +# pragma error_messages(off, E_ARG_INCOMPATIBLE_WITH_ARG_L) #endif -static inline bool opal_atomic_compare_exchange_strong_acq_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } - -static inline bool opal_atomic_compare_exchange_strong_rel_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_RELEASE, + __ATOMIC_RELAXED); } -static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } -static inline int32_t opal_atomic_swap_32 (opal_atomic_int32_t *addr, int32_t newval) +static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval) { int32_t oldval; - __atomic_exchange (addr, &newval, &oldval, __ATOMIC_RELAXED); + __atomic_exchange(addr, &newval, &oldval, __ATOMIC_RELAXED); return oldval; } static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t *addr, int32_t delta) { - return __atomic_fetch_add (addr, delta, __ATOMIC_RELAXED); + return __atomic_fetch_add(addr, delta, __ATOMIC_RELAXED); } static inline int32_t opal_atomic_fetch_and_32(opal_atomic_int32_t *addr, int32_t value) { - return __atomic_fetch_and (addr, value, __ATOMIC_RELAXED); + return __atomic_fetch_and(addr, value, __ATOMIC_RELAXED); } static inline int32_t opal_atomic_fetch_or_32(opal_atomic_int32_t *addr, int32_t value) { - return __atomic_fetch_or (addr, value, __ATOMIC_RELAXED); + return __atomic_fetch_or(addr, value, __ATOMIC_RELAXED); } static inline int32_t opal_atomic_fetch_xor_32(opal_atomic_int32_t *addr, int32_t value) { - return __atomic_fetch_xor (addr, value, __ATOMIC_RELAXED); + return __atomic_fetch_xor(addr, value, __ATOMIC_RELAXED); } static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t *addr, int32_t delta) { - return __atomic_fetch_sub (addr, delta, __ATOMIC_RELAXED); + return __atomic_fetch_sub(addr, delta, __ATOMIC_RELAXED); } -static inline bool opal_atomic_compare_exchange_strong_acq_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } -static inline bool opal_atomic_compare_exchange_strong_rel_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_RELEASE, + __ATOMIC_RELAXED); } - -static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } -static inline int64_t opal_atomic_swap_64 (opal_atomic_int64_t *addr, int64_t newval) +static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval) { int64_t oldval; - __atomic_exchange (addr, &newval, &oldval, __ATOMIC_RELAXED); + __atomic_exchange(addr, &newval, &oldval, __ATOMIC_RELAXED); return oldval; } static inline int64_t opal_atomic_fetch_add_64(opal_atomic_int64_t *addr, int64_t delta) { - return __atomic_fetch_add (addr, delta, __ATOMIC_RELAXED); + return __atomic_fetch_add(addr, delta, __ATOMIC_RELAXED); } static inline int64_t opal_atomic_fetch_and_64(opal_atomic_int64_t *addr, int64_t value) { - return __atomic_fetch_and (addr, value, __ATOMIC_RELAXED); + return __atomic_fetch_and(addr, value, __ATOMIC_RELAXED); } static inline int64_t opal_atomic_fetch_or_64(opal_atomic_int64_t *addr, int64_t value) { - return __atomic_fetch_or (addr, value, __ATOMIC_RELAXED); + return __atomic_fetch_or(addr, value, __ATOMIC_RELAXED); } static inline int64_t opal_atomic_fetch_xor_64(opal_atomic_int64_t *addr, int64_t value) { - return __atomic_fetch_xor (addr, value, __ATOMIC_RELAXED); + return __atomic_fetch_xor(addr, value, __ATOMIC_RELAXED); } static inline int64_t opal_atomic_fetch_sub_64(opal_atomic_int64_t *addr, int64_t delta) { - return __atomic_fetch_sub (addr, delta, __ATOMIC_RELAXED); + return __atomic_fetch_sub(addr, delta, __ATOMIC_RELAXED); } #if OPAL_HAVE_GCC_BUILTIN_CSWAP_INT128 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 -static inline bool opal_atomic_compare_exchange_strong_128 (opal_atomic_int128_t *addr, - opal_int128_t *oldval, opal_int128_t newval) +static inline bool opal_atomic_compare_exchange_strong_128(opal_atomic_int128_t *addr, + opal_int128_t *oldval, + opal_int128_t newval) { - return __atomic_compare_exchange_n (addr, oldval, newval, false, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + return __atomic_compare_exchange_n(addr, oldval, newval, false, __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } #elif defined(OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128) && OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128 -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 /* __atomic version is not lock-free so use legacy __sync version */ -static inline bool opal_atomic_compare_exchange_strong_128 (opal_atomic_opal_int128_t *addr, - opal_int128_t *oldval, opal_int128_t newval) +static inline bool opal_atomic_compare_exchange_strong_128(opal_atomic_opal_int128_t *addr, + opal_int128_t *oldval, + opal_int128_t newval) { - opal_int128_t prev = __sync_val_compare_and_swap (addr, *oldval, newval); + opal_int128_t prev = __sync_val_compare_and_swap(addr, *oldval, newval); bool ret = prev == *oldval; *oldval = prev; return ret; @@ -215,47 +226,48 @@ static inline bool opal_atomic_compare_exchange_strong_128 (opal_atomic_opal_int #if defined(__HLE__) -#include +# include -#define OPAL_HAVE_ATOMIC_SPINLOCKS 1 +# define OPAL_HAVE_ATOMIC_SPINLOCKS 1 -static inline void opal_atomic_lock_init (opal_atomic_lock_t* lock, int32_t value) +static inline void opal_atomic_lock_init(opal_atomic_lock_t *lock, int32_t value) { - lock->u.lock = value; + lock->u.lock = value; } static inline int opal_atomic_trylock(opal_atomic_lock_t *lock) { - int ret = __atomic_exchange_n (&lock->u.lock, OPAL_ATOMIC_LOCK_LOCKED, - __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); + int ret = __atomic_exchange_n(&lock->u.lock, OPAL_ATOMIC_LOCK_LOCKED, + __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); if (OPAL_ATOMIC_LOCK_LOCKED == ret) { /* abort the transaction */ - _mm_pause (); + _mm_pause(); return 1; } return 0; } -static inline void opal_atomic_lock (opal_atomic_lock_t *lock) +static inline void opal_atomic_lock(opal_atomic_lock_t *lock) { - while (OPAL_ATOMIC_LOCK_LOCKED == __atomic_exchange_n (&lock->u.lock, OPAL_ATOMIC_LOCK_LOCKED, - __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE)) { + while (OPAL_ATOMIC_LOCK_LOCKED + == __atomic_exchange_n(&lock->u.lock, OPAL_ATOMIC_LOCK_LOCKED, + __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE)) { /* abort the transaction */ - _mm_pause (); + _mm_pause(); } } -static inline void opal_atomic_unlock (opal_atomic_lock_t *lock) +static inline void opal_atomic_unlock(opal_atomic_lock_t *lock) { - __atomic_store_n (&lock->u.lock, OPAL_ATOMIC_LOCK_UNLOCKED, - __ATOMIC_RELEASE | __ATOMIC_HLE_RELEASE); + __atomic_store_n(&lock->u.lock, OPAL_ATOMIC_LOCK_UNLOCKED, + __ATOMIC_RELEASE | __ATOMIC_HLE_RELEASE); } #endif #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) -#pragma error_messages(default, E_ARG_INCOMPATIBLE_WITH_ARG_L) +# pragma error_messages(default, E_ARG_INCOMPATIBLE_WITH_ARG_L) #endif #endif /* ! OPAL_SYS_ARCH_ATOMIC_H */ diff --git a/opal/include/opal/sys/ia32/atomic.h b/opal/include/opal/sys/ia32/atomic.h index eac18b4b007..f44e1453b37 100644 --- a/opal/include/opal/sys/ia32/atomic.h +++ b/opal/include/opal/sys/ia32/atomic.h @@ -30,8 +30,7 @@ */ #define SMPLOCK "lock; " -#define MB() __asm__ __volatile__("": : :"memory") - +#define MB() __asm__ __volatile__("" : : : "memory") /********************************************************************** * @@ -43,8 +42,8 @@ #define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 #define OPAL_HAVE_ATOMIC_MATH_32 1 -#define OPAL_HAVE_ATOMIC_ADD_32 1 -#define OPAL_HAVE_ATOMIC_SUB_32 1 +#define OPAL_HAVE_ATOMIC_ADD_32 1 +#define OPAL_HAVE_ATOMIC_SUB_32 1 /********************************************************************** * @@ -58,13 +57,11 @@ static inline void opal_atomic_mb(void) MB(); } - static inline void opal_atomic_rmb(void) { MB(); } - static inline void opal_atomic_wmb(void) { MB(); @@ -76,7 +73,6 @@ static inline void opal_atomic_isync(void) #endif /* OPAL_GCC_INLINE_ASSEMBLY */ - /********************************************************************** * * Atomic math operations @@ -84,17 +80,17 @@ static inline void opal_atomic_isync(void) *********************************************************************/ #if OPAL_GCC_INLINE_ASSEMBLY -static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { - unsigned char ret; - __asm__ __volatile__ ( - SMPLOCK "cmpxchgl %3,%2 \n\t" - "sete %0 \n\t" - : "=qm" (ret), "+a" (*oldval), "+m" (*addr) - : "q"(newval) - : "memory", "cc"); - - return (bool) ret; + unsigned char ret; + __asm__ __volatile__(SMPLOCK "cmpxchgl %3,%2 \n\t" + "sete %0 \n\t" + : "=qm"(ret), "+a"(*oldval), "+m"(*addr) + : "q"(newval) + : "memory", "cc"); + + return (bool) ret; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ @@ -104,23 +100,21 @@ static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t * #if OPAL_GCC_INLINE_ASSEMBLY -#define OPAL_HAVE_ATOMIC_SWAP_32 1 +# define OPAL_HAVE_ATOMIC_SWAP_32 1 -static inline int32_t opal_atomic_swap_32( opal_atomic_int32_t *addr, - int32_t newval) +static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval) { int32_t oldval; - __asm__ __volatile__("xchg %1, %0" : - "=r" (oldval), "=m" (*addr) : - "0" (newval), "m" (*addr) : - "memory"); + __asm__ __volatile__("xchg %1, %0" + : "=r"(oldval), "=m"(*addr) + : "0"(newval), "m"(*addr) + : "memory"); return oldval; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ - #if OPAL_GCC_INLINE_ASSEMBLY /** @@ -130,19 +124,13 @@ static inline int32_t opal_atomic_swap_32( opal_atomic_int32_t *addr, * * Atomically adds @i to @v. */ -static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t* v, int i) +static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t *v, int i) { int ret = i; - __asm__ __volatile__( - SMPLOCK "xaddl %1,%0" - :"+m" (*v), "+r" (ret) - : - :"memory", "cc" - ); - return ret; + __asm__ __volatile__(SMPLOCK "xaddl %1,%0" : "+m"(*v), "+r"(ret) : : "memory", "cc"); + return ret; } - /** * atomic_sub - subtract the atomic variable * @i: integer value to subtract @@ -150,16 +138,11 @@ static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t* v, int i) * * Atomically subtracts @i from @v. */ -static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t* v, int i) +static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t *v, int i) { int ret = -i; - __asm__ __volatile__( - SMPLOCK "xaddl %1,%0" - :"+m" (*v), "+r" (ret) - : - :"memory", "cc" - ); - return ret; + __asm__ __volatile__(SMPLOCK "xaddl %1,%0" : "+m"(*v), "+r"(ret) : : "memory", "cc"); + return ret; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ diff --git a/opal/include/opal/sys/ia32/timer.h b/opal/include/opal/sys/ia32/timer.h index 2fb2beef639..9dcf8199444 100644 --- a/opal/include/opal/sys/ia32/timer.h +++ b/opal/include/opal/sys/ia32/timer.h @@ -19,7 +19,6 @@ #ifndef OPAL_SYS_ARCH_TIMER_H #define OPAL_SYS_ARCH_TIMER_H 1 - typedef uint64_t opal_timer_t; /* Using RDTSC(P) results in non-monotonic timers across cores */ @@ -28,28 +27,25 @@ typedef uint64_t opal_timer_t; #if OPAL_GCC_INLINE_ASSEMBLY -static inline opal_timer_t -opal_sys_timer_get_cycles(void) +static inline opal_timer_t opal_sys_timer_get_cycles(void) { opal_timer_t ret; int tmp; - __asm__ __volatile__( - "xchgl %%ebx, %1\n" + __asm__ __volatile__("xchgl %%ebx, %1\n" "cpuid\n" "xchgl %%ebx, %1\n" "rdtsc\n" - : "=A"(ret), "=r"(tmp) - :: "ecx"); + : "=A"(ret), "=r"(tmp)::"ecx"); return ret; } -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 #else -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 #endif /* OPAL_GCC_INLINE_ASSEMBLY */ diff --git a/opal/include/opal/sys/powerpc/atomic.h b/opal/include/opal/sys/powerpc/atomic.h index 393b92acba5..092968ef8cc 100644 --- a/opal/include/opal/sys/powerpc/atomic.h +++ b/opal/include/opal/sys/powerpc/atomic.h @@ -27,11 +27,10 @@ * On powerpc ... */ -#define MB() __asm__ __volatile__ ("sync" : : : "memory") -#define RMB() __asm__ __volatile__ ("lwsync" : : : "memory") -#define WMB() __asm__ __volatile__ ("lwsync" : : : "memory") -#define ISYNC() __asm__ __volatile__ ("isync" : : : "memory") - +#define MB() __asm__ __volatile__("sync" : : : "memory") +#define RMB() __asm__ __volatile__("lwsync" : : : "memory") +#define WMB() __asm__ __volatile__("lwsync" : : : "memory") +#define ISYNC() __asm__ __volatile__("isync" : : : "memory") /********************************************************************** * @@ -41,30 +40,28 @@ #define OPAL_HAVE_ATOMIC_MEM_BARRIER 1 #define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1 -#define OPAL_HAVE_ATOMIC_SWAP_32 1 -#define OPAL_HAVE_ATOMIC_LLSC_32 1 +#define OPAL_HAVE_ATOMIC_SWAP_32 1 +#define OPAL_HAVE_ATOMIC_LLSC_32 1 #define OPAL_HAVE_ATOMIC_MATH_32 1 -#define OPAL_HAVE_ATOMIC_ADD_32 1 -#define OPAL_HAVE_ATOMIC_AND_32 1 -#define OPAL_HAVE_ATOMIC_OR_32 1 -#define OPAL_HAVE_ATOMIC_XOR_32 1 -#define OPAL_HAVE_ATOMIC_SUB_32 1 - +#define OPAL_HAVE_ATOMIC_ADD_32 1 +#define OPAL_HAVE_ATOMIC_AND_32 1 +#define OPAL_HAVE_ATOMIC_OR_32 1 +#define OPAL_HAVE_ATOMIC_XOR_32 1 +#define OPAL_HAVE_ATOMIC_SUB_32 1 #if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) || OPAL_ASM_SUPPORT_64BIT -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 -#define OPAL_HAVE_ATOMIC_SWAP_64 1 -#define OPAL_HAVE_ATOMIC_LLSC_64 1 -#define OPAL_HAVE_ATOMIC_MATH_64 1 -#define OPAL_HAVE_ATOMIC_ADD_64 1 -#define OPAL_HAVE_ATOMIC_AND_64 1 -#define OPAL_HAVE_ATOMIC_OR_64 1 -#define OPAL_HAVE_ATOMIC_XOR_64 1 -#define OPAL_HAVE_ATOMIC_SUB_64 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1 +# define OPAL_HAVE_ATOMIC_SWAP_64 1 +# define OPAL_HAVE_ATOMIC_LLSC_64 1 +# define OPAL_HAVE_ATOMIC_MATH_64 1 +# define OPAL_HAVE_ATOMIC_ADD_64 1 +# define OPAL_HAVE_ATOMIC_AND_64 1 +# define OPAL_HAVE_ATOMIC_OR_64 1 +# define OPAL_HAVE_ATOMIC_XOR_64 1 +# define OPAL_HAVE_ATOMIC_SUB_64 1 #endif - /********************************************************************** * * Memory Barriers @@ -72,28 +69,22 @@ *********************************************************************/ #if OPAL_GCC_INLINE_ASSEMBLY -static inline -void opal_atomic_mb(void) +static inline void opal_atomic_mb(void) { MB(); } - -static inline -void opal_atomic_rmb(void) +static inline void opal_atomic_rmb(void) { RMB(); } - -static inline -void opal_atomic_wmb(void) +static inline void opal_atomic_wmb(void) { WMB(); } -static inline -void opal_atomic_isync(void) +static inline void opal_atomic_isync(void) { ISYNC(); } @@ -107,38 +98,38 @@ void opal_atomic_isync(void) *********************************************************************/ #if OPAL_GCC_INLINE_ASSEMBLY -#if defined(__xlC__) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__ibmxl__) +# if defined(__xlC__) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__ibmxl__) /* work-around bizzare xlc bug in which it sign-extends a pointer to a 32-bit signed integer */ -#define OPAL_ASM_ADDR(a) ((uintptr_t)a) -#else -#define OPAL_ASM_ADDR(a) (a) -#endif +# define OPAL_ASM_ADDR(a) ((uintptr_t) a) +# else +# define OPAL_ASM_ADDR(a) (a) +# endif -#if defined(__PGI) +# if defined(__PGI) /* work-around for bug in PGI 16.5-16.7 where the compiler fails to * correctly emit load instructions for 64-bit operands. without this * it will emit lwz instead of ld to load the 64-bit operand. */ -#define OPAL_ASM_VALUE64(x) (void *)(intptr_t) (x) -#else -#define OPAL_ASM_VALUE64(x) x -#endif +# define OPAL_ASM_VALUE64(x) (void *) (intptr_t)(x) +# else +# define OPAL_ASM_VALUE64(x) x +# endif -static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { int32_t prev; bool ret; - __asm__ __volatile__ ( - "1: lwarx %0, 0, %2 \n\t" - " cmpw 0, %0, %3 \n\t" - " bne- 2f \n\t" - " stwcx. %4, 0, %2 \n\t" - " bne- 1b \n\t" - "2:" - : "=&r" (prev), "=m" (*addr) - : "r" OPAL_ASM_ADDR(addr), "r" (*oldval), "r" (newval), "m" (*addr) - : "cc", "memory"); + __asm__ __volatile__("1: lwarx %0, 0, %2 \n\t" + " cmpw 0, %0, %3 \n\t" + " bne- 2f \n\t" + " stwcx. %4, 0, %2 \n\t" + " bne- 1b \n\t" + "2:" + : "=&r"(prev), "=m"(*addr) + : "r" OPAL_ASM_ADDR(addr), "r"(*oldval), "r"(newval), "m"(*addr) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; @@ -146,94 +137,92 @@ static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t * } /* NTH: the LL/SC support is done through macros due to issues with non-optimized builds. The reason - * is that even with an always_inline attribute the compiler may still emit instructions to store then - * load the arguments to/from the stack. This sequence may cause the ll reservation to be cancelled. */ -#define opal_atomic_ll_32(addr, ret) \ - do { \ - opal_atomic_int32_t *_addr = (addr); \ - int32_t _ret; \ - __asm__ __volatile__ ("lwarx %0, 0, %1 \n\t" \ - : "=&r" (_ret) \ - : "r" (_addr) \ - ); \ - ret = (typeof(ret)) _ret; \ - } while (0) - -#define opal_atomic_sc_32(addr, value, ret) \ - do { \ - opal_atomic_int32_t *_addr = (addr); \ - int32_t _ret, _foo, _newval = (int32_t) value; \ + * is that even with an always_inline attribute the compiler may still emit instructions to store + * then load the arguments to/from the stack. This sequence may cause the ll reservation to be + * cancelled. */ +# define opal_atomic_ll_32(addr, ret) \ + do { \ + opal_atomic_int32_t *_addr = (addr); \ + int32_t _ret; \ + __asm__ __volatile__("lwarx %0, 0, %1 \n\t" : "=&r"(_ret) : "r"(_addr)); \ + ret = (typeof(ret)) _ret; \ + } while (0) + +# define opal_atomic_sc_32(addr, value, ret) \ + do { \ + opal_atomic_int32_t *_addr = (addr); \ + int32_t _ret, _foo, _newval = (int32_t) value; \ \ - __asm__ __volatile__ (" stwcx. %4, 0, %3 \n\t" \ - " li %0,0 \n\t" \ - " bne- 1f \n\t" \ - " ori %0,%0,1 \n\t" \ - "1:" \ - : "=r" (_ret), "=m" (*_addr), "=r" (_foo) \ - : "r" (_addr), "r" (_newval) \ - : "cc", "memory"); \ - ret = _ret; \ - } while (0) + __asm__ __volatile__(" stwcx. %4, 0, %3 \n\t" \ + " li %0,0 \n\t" \ + " bne- 1f \n\t" \ + " ori %0,%0,1 \n\t" \ + "1:" \ + : "=r"(_ret), "=m"(*_addr), "=r"(_foo) \ + : "r"(_addr), "r"(_newval) \ + : "cc", "memory"); \ + ret = _ret; \ + } while (0) /* these two functions aren't inlined in the non-gcc case because then there would be two function calls (since neither cmpset_32 nor atomic_?mb can be inlined). Instead, we "inline" them by hand in the assembly, meaning there is one function call overhead instead of two */ -static inline bool opal_atomic_compare_exchange_strong_acq_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { bool rc; - rc = opal_atomic_compare_exchange_strong_32 (addr, oldval, newval); + rc = opal_atomic_compare_exchange_strong_32(addr, oldval, newval); opal_atomic_rmb(); return rc; } - -static inline bool opal_atomic_compare_exchange_strong_rel_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { opal_atomic_wmb(); - return opal_atomic_compare_exchange_strong_32 (addr, oldval, newval); + return opal_atomic_compare_exchange_strong_32(addr, oldval, newval); } static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval) { int32_t ret; - __asm__ __volatile__ ("1: lwarx %0, 0, %2 \n\t" - " stwcx. %3, 0, %2 \n\t" - " bne- 1b \n\t" - : "=&r" (ret), "=m" (*addr) - : "r" (addr), "r" (newval) - : "cc", "memory"); + __asm__ __volatile__("1: lwarx %0, 0, %2 \n\t" + " stwcx. %3, 0, %2 \n\t" + " bne- 1b \n\t" + : "=&r"(ret), "=m"(*addr) + : "r"(addr), "r"(newval) + : "cc", "memory"); - return ret; + return ret; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ - #if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) -#if OPAL_GCC_INLINE_ASSEMBLY - -#define OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(type, instr) \ -static inline int64_t opal_atomic_fetch_ ## type ## _64(opal_atomic_int64_t* v, int64_t val) \ -{ \ - int64_t t, old; \ - \ - __asm__ __volatile__( \ - "1: ldarx %1, 0, %4 \n\t" \ - " " #instr " %0, %3, %1 \n\t" \ - " stdcx. %0, 0, %4 \n\t" \ - " bne- 1b \n\t" \ - : "=&r" (t), "=&r" (old), "=m" (*v) \ - : "r" (OPAL_ASM_VALUE64(val)), "r" OPAL_ASM_ADDR(v), "m" (*v) \ - : "cc"); \ - \ - return old; \ -} +# if OPAL_GCC_INLINE_ASSEMBLY + +# define OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(type, instr) \ + static inline int64_t opal_atomic_fetch_##type##_64(opal_atomic_int64_t *v, \ + int64_t val) \ + { \ + int64_t t, old; \ + \ + __asm__ __volatile__("1: ldarx %1, 0, %4 \n\t" \ + " " #instr " %0, %3, %1 \n\t" \ + " stdcx. %0, 0, %4 \n\t" \ + " bne- 1b \n\t" \ + : "=&r"(t), "=&r"(old), "=m"(*v) \ + : "r"(OPAL_ASM_VALUE64(val)), "r" OPAL_ASM_ADDR(v), "m"(*v) \ + : "cc"); \ + \ + return old; \ + } OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(add, add) OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(and, and) @@ -241,81 +230,80 @@ OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(or, or) OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(xor, xor) OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_64(sub, subf) -static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { int64_t prev; bool ret; - __asm__ __volatile__ ( - "1: ldarx %0, 0, %2 \n\t" - " cmpd 0, %0, %3 \n\t" - " bne- 2f \n\t" - " stdcx. %4, 0, %2 \n\t" - " bne- 1b \n\t" - "2:" - : "=&r" (prev), "=m" (*addr) - : "r" (addr), "r" (OPAL_ASM_VALUE64(*oldval)), "r" (OPAL_ASM_VALUE64(newval)), "m" (*addr) - : "cc", "memory"); + __asm__ __volatile__("1: ldarx %0, 0, %2 \n\t" + " cmpd 0, %0, %3 \n\t" + " bne- 2f \n\t" + " stdcx. %4, 0, %2 \n\t" + " bne- 1b \n\t" + "2:" + : "=&r"(prev), "=m"(*addr) + : "r"(addr), "r"(OPAL_ASM_VALUE64(*oldval)), "r"(OPAL_ASM_VALUE64(newval)), + "m"(*addr) + : "cc", "memory"); ret = (prev == *oldval); *oldval = prev; return ret; } -#define opal_atomic_ll_64(addr, ret) \ - do { \ - opal_atomic_int64_t *_addr = (addr); \ - int64_t _ret; \ - __asm__ __volatile__ ("ldarx %0, 0, %1 \n\t" \ - : "=&r" (_ret) \ - : "r" (_addr) \ - ); \ - ret = (typeof(ret)) _ret; \ - } while (0) - -#define opal_atomic_sc_64(addr, value, ret) \ - do { \ - opal_atomic_int64_t *_addr = (addr); \ - int64_t _newval = (int64_t) value; \ - int32_t _ret; \ - \ - __asm__ __volatile__ (" stdcx. %2, 0, %1 \n\t" \ - " li %0,0 \n\t" \ - " bne- 1f \n\t" \ - " ori %0,%0,1 \n\t" \ - "1:" \ - : "=r" (_ret) \ - : "r" (_addr), "r" (OPAL_ASM_VALUE64(_newval)) \ - : "cc", "memory"); \ - ret = _ret; \ - } while (0) +# define opal_atomic_ll_64(addr, ret) \ + do { \ + opal_atomic_int64_t *_addr = (addr); \ + int64_t _ret; \ + __asm__ __volatile__("ldarx %0, 0, %1 \n\t" : "=&r"(_ret) : "r"(_addr)); \ + ret = (typeof(ret)) _ret; \ + } while (0) + +# define opal_atomic_sc_64(addr, value, ret) \ + do { \ + opal_atomic_int64_t *_addr = (addr); \ + int64_t _newval = (int64_t) value; \ + int32_t _ret; \ + \ + __asm__ __volatile__(" stdcx. %2, 0, %1 \n\t" \ + " li %0,0 \n\t" \ + " bne- 1f \n\t" \ + " ori %0,%0,1 \n\t" \ + "1:" \ + : "=r"(_ret) \ + : "r"(_addr), "r"(OPAL_ASM_VALUE64(_newval)) \ + : "cc", "memory"); \ + ret = _ret; \ + } while (0) static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval) { - int64_t ret; + int64_t ret; - __asm__ __volatile__ ("1: ldarx %0, 0, %2 \n\t" + __asm__ __volatile__("1: ldarx %0, 0, %2 \n\t" " stdcx. %3, 0, %2 \n\t" " bne- 1b \n\t" - : "=&r" (ret), "=m" (*addr) - : "r" (addr), "r" (OPAL_ASM_VALUE64(newval)) + : "=&r"(ret), "=m"(*addr) + : "r"(addr), "r"(OPAL_ASM_VALUE64(newval)) : "cc", "memory"); - return ret; + return ret; } -#endif /* OPAL_GCC_INLINE_ASSEMBLY */ +# endif /* OPAL_GCC_INLINE_ASSEMBLY */ #elif (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32) && OPAL_ASM_SUPPORT_64BIT -#ifndef ll_low /* GLIBC provides these somewhere, so protect */ -#define ll_low(x) *(((unsigned int*)&(x))+0) -#define ll_high(x) *(((unsigned int*)&(x))+1) -#endif +# ifndef ll_low /* GLIBC provides these somewhere, so protect */ +# define ll_low(x) *(((unsigned int *) &(x)) + 0) +# define ll_high(x) *(((unsigned int *) &(x)) + 1) +# endif -#if OPAL_GCC_INLINE_ASSEMBLY +# if OPAL_GCC_INLINE_ASSEMBLY -static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { int64_t prev; int ret; @@ -331,8 +319,7 @@ static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t * * into registers. We use r4,r5 so that the main block of code * is very similar to the pure 64 bit version. */ - __asm__ __volatile__ ( - "ld r4,%3 \n\t" + __asm__ __volatile__("ld r4,%3 \n\t" "ld r5,%4 \n\t" "1: ldarx %1, 0, %2 \n\t" " cmpd 0, %1, r4 \n\t" @@ -343,15 +330,14 @@ static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t * "xor r5,r4,%1 \n\t" "subfic r9,r5,0 \n\t" "adde %0,r9,r5 \n\t" - : "=&r" (ret), "+r" (prev) - : "r"OPAL_ASM_ADDR(addr), - "m"(*oldval), "m"(newval) + : "=&r"(ret), "+r"(prev) + : "r" OPAL_ASM_ADDR(addr), "m"(*oldval), "m"(newval) : "r4", "r5", "r9", "cc", "memory"); - *oldval = prev; - return (bool) ret; + *oldval = prev; + return (bool) ret; } -#endif /* OPAL_GCC_INLINE_ASSEMBLY */ +# endif /* OPAL_GCC_INLINE_ASSEMBLY */ #endif /* OPAL_ASM_SUPPORT_64BIT */ @@ -362,40 +348,39 @@ static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t * atomic_?mb can be inlined). Instead, we "inline" them by hand in the assembly, meaning there is one function call overhead instead of two */ -static inline bool opal_atomic_compare_exchange_strong_acq_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_acq_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { bool rc; - rc = opal_atomic_compare_exchange_strong_64 (addr, oldval, newval); + rc = opal_atomic_compare_exchange_strong_64(addr, oldval, newval); opal_atomic_rmb(); return rc; } - -static inline bool opal_atomic_compare_exchange_strong_rel_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_rel_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { opal_atomic_wmb(); - return opal_atomic_compare_exchange_strong_64 (addr, oldval, newval); + return opal_atomic_compare_exchange_strong_64(addr, oldval, newval); } - -#define OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_32(type, instr) \ -static inline int32_t opal_atomic_fetch_ ## type ## _32(opal_atomic_int32_t* v, int val) \ -{ \ - int32_t t, old; \ - \ - __asm__ __volatile__( \ - "1: lwarx %1, 0, %4 \n\t" \ - " " #instr " %0, %3, %1 \n\t" \ - " stwcx. %0, 0, %4 \n\t" \ - " bne- 1b \n\t" \ - : "=&r" (t), "=&r" (old), "=m" (*v) \ - : "r" (val), "r" OPAL_ASM_ADDR(v), "m" (*v) \ - : "cc"); \ - \ - return old; \ -} +# define OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_32(type, instr) \ + static inline int32_t opal_atomic_fetch_##type##_32(opal_atomic_int32_t *v, int val) \ + { \ + int32_t t, old; \ + \ + __asm__ __volatile__("1: lwarx %1, 0, %4 \n\t" \ + " " #instr " %0, %3, %1 \n\t" \ + " stwcx. %0, 0, %4 \n\t" \ + " bne- 1b \n\t" \ + : "=&r"(t), "=&r"(old), "=m"(*v) \ + : "r"(val), "r" OPAL_ASM_ADDR(v), "m"(*v) \ + : "cc"); \ + \ + return old; \ + } OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_32(add, add) OPAL_ATOMIC_POWERPC_DEFINE_ATOMIC_32(and, and) diff --git a/opal/include/opal/sys/powerpc/timer.h b/opal/include/opal/sys/powerpc/timer.h index 09d9f2cf89a..3dc165ce05d 100644 --- a/opal/include/opal/sys/powerpc/timer.h +++ b/opal/include/opal/sys/powerpc/timer.h @@ -19,31 +19,28 @@ #ifndef OPAL_SYS_ARCH_TIMER_H #define OPAL_SYS_ARCH_TIMER_H 1 - typedef uint64_t opal_timer_t; - #if OPAL_GCC_INLINE_ASSEMBLY -static inline opal_timer_t -opal_sys_timer_get_cycles(void) +static inline opal_timer_t opal_sys_timer_get_cycles(void) { unsigned int tbl, tbu0, tbu1; do { - __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0)); - __asm__ __volatile__ ("mftb %0" : "=r"(tbl)); - __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1)); + __asm__ __volatile__("mftbu %0" : "=r"(tbu0)); + __asm__ __volatile__("mftb %0" : "=r"(tbl)); + __asm__ __volatile__("mftbu %0" : "=r"(tbu1)); } while (tbu0 != tbu1); - return (((unsigned long long)tbu0) << 32) | tbl; + return (((unsigned long long) tbu0) << 32) | tbl; } -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 #else -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 #endif /* OPAL_GCC_INLINE_ASSEMBLY */ diff --git a/opal/include/opal/sys/timer.h b/opal/include/opal/sys/timer.h index 9cf844192e0..8bcd88a83f6 100644 --- a/opal/include/opal/sys/timer.h +++ b/opal/include/opal/sys/timer.h @@ -36,23 +36,23 @@ #include "opal/sys/architecture.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif /* do some quick #define cleanup in cases where we are doing testing... */ #ifdef OPAL_DISABLE_INLINE_ASM -#undef OPAL_C_GCC_INLINE_ASSEMBLY -#define OPAL_C_GCC_INLINE_ASSEMBLY 0 +# undef OPAL_C_GCC_INLINE_ASSEMBLY +# define OPAL_C_GCC_INLINE_ASSEMBLY 0 #endif /* define OPAL_{GCC,DEC,XLC}_INLINE_ASSEMBLY based on the OPAL_{C,CXX}_{GCC,DEC,XLC}_INLINE_ASSEMBLY defines and whether we are in C or C++ */ #if defined(c_plusplus) || defined(__cplusplus) -#define OPAL_GCC_INLINE_ASSEMBLY OPAL_CXX_GCC_INLINE_ASSEMBLY +# define OPAL_GCC_INLINE_ASSEMBLY OPAL_CXX_GCC_INLINE_ASSEMBLY #else -#define OPAL_GCC_INLINE_ASSEMBLY OPAL_C_GCC_INLINE_ASSEMBLY +# define OPAL_GCC_INLINE_ASSEMBLY OPAL_C_GCC_INLINE_ASSEMBLY #endif /********************************************************************** @@ -73,36 +73,36 @@ BEGIN_C_DECLS #if defined(DOXYGEN) /* don't include system-level gorp when generating doxygen files */ #elif OPAL_ASSEMBLY_ARCH == OPAL_X86_64 -#include "opal/sys/x86_64/timer.h" +# include "opal/sys/x86_64/timer.h" #elif OPAL_ASSEMBLY_ARCH == OPAL_ARM -#include "opal/sys/arm/timer.h" +# include "opal/sys/arm/timer.h" #elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 -#include "opal/sys/arm64/timer.h" +# include "opal/sys/arm64/timer.h" #elif OPAL_ASSEMBLY_ARCH == OPAL_IA32 -#include "opal/sys/ia32/timer.h" +# include "opal/sys/ia32/timer.h" #elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32 -#include "opal/sys/powerpc/timer.h" +# include "opal/sys/powerpc/timer.h" #elif OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64 -#include "opal/sys/powerpc/timer.h" +# include "opal/sys/powerpc/timer.h" #endif #ifndef DOXYGEN -#ifndef OPAL_HAVE_SYS_TIMER_GET_CYCLES -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 +# ifndef OPAL_HAVE_SYS_TIMER_GET_CYCLES +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 typedef long opal_timer_t; -#endif +# endif -#ifndef OPAL_HAVE_SYS_TIMER_GET_FREQ -#define OPAL_HAVE_SYS_TIMER_GET_FREQ 0 -#endif +# ifndef OPAL_HAVE_SYS_TIMER_GET_FREQ +# define OPAL_HAVE_SYS_TIMER_GET_FREQ 0 +# endif #endif #ifndef OPAL_HAVE_SYS_TIMER_IS_MONOTONIC -#define OPAL_HAVE_SYS_TIMER_IS_MONOTONIC 1 +# define OPAL_HAVE_SYS_TIMER_IS_MONOTONIC 1 -static inline bool opal_sys_timer_is_monotonic (void) +static inline bool opal_sys_timer_is_monotonic(void) { return OPAL_TIMER_MONOTONIC; } diff --git a/opal/include/opal/sys/x86_64/atomic.h b/opal/include/opal/sys/x86_64/atomic.h index 8853eb5c2b9..ba11b4bfd64 100644 --- a/opal/include/opal/sys/x86_64/atomic.h +++ b/opal/include/opal/sys/x86_64/atomic.h @@ -28,10 +28,8 @@ * On x86_64, we use cmpxchg. */ - #define SMPLOCK "lock; " -#define MB() __asm__ __volatile__("": : :"memory") - +#define MB() __asm__ __volatile__("" : : : "memory") /********************************************************************** * @@ -56,13 +54,11 @@ static inline void opal_atomic_mb(void) MB(); } - static inline void opal_atomic_rmb(void) { MB(); } - static inline void opal_atomic_wmb(void) { MB(); @@ -74,7 +70,6 @@ static inline void opal_atomic_isync(void) #endif /* OPAL_GCC_INLINE_ASSEMBLY */ - /********************************************************************** * * Atomic math operations @@ -82,17 +77,17 @@ static inline void opal_atomic_isync(void) *********************************************************************/ #if OPAL_GCC_INLINE_ASSEMBLY -static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval) +static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *addr, + int32_t *oldval, int32_t newval) { - unsigned char ret; - __asm__ __volatile__ ( - SMPLOCK "cmpxchgl %3,%2 \n\t" - "sete %0 \n\t" - : "=qm" (ret), "+a" (*oldval), "+m" (*addr) - : "q"(newval) - : "memory", "cc"); - - return (bool) ret; + unsigned char ret; + __asm__ __volatile__(SMPLOCK "cmpxchgl %3,%2 \n\t" + "sete %0 \n\t" + : "=qm"(ret), "+a"(*oldval), "+m"(*addr) + : "q"(newval) + : "memory", "cc"); + + return (bool) ret; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ @@ -102,18 +97,17 @@ static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t * #if OPAL_GCC_INLINE_ASSEMBLY -static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval) +static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *addr, + int64_t *oldval, int64_t newval) { - unsigned char ret; - __asm__ __volatile__ ( - SMPLOCK "cmpxchgq %3,%2 \n\t" - "sete %0 \n\t" - : "=qm" (ret), "+a" (*oldval), "+m" (*((opal_atomic_long_t *)addr)) - : "q"(newval) - : "memory", "cc" - ); - - return (bool) ret; + unsigned char ret; + __asm__ __volatile__(SMPLOCK "cmpxchgq %3,%2 \n\t" + "sete %0 \n\t" + : "=qm"(ret), "+a"(*oldval), "+m"(*((opal_atomic_long_t *) addr)) + : "q"(newval) + : "memory", "cc"); + + return (bool) ret; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ @@ -123,42 +117,39 @@ static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t * #if OPAL_GCC_INLINE_ASSEMBLY && OPAL_HAVE_CMPXCHG16B && HAVE_OPAL_INT128_T -static inline bool opal_atomic_compare_exchange_strong_128 (opal_atomic_int128_t *addr, opal_int128_t *oldval, opal_int128_t newval) +static inline bool opal_atomic_compare_exchange_strong_128(opal_atomic_int128_t *addr, + opal_int128_t *oldval, + opal_int128_t newval) { unsigned char ret; /* cmpxchg16b compares the value at the address with eax:edx (low:high). if the values are * the same the contents of ebx:ecx are stores at the address. in all cases the value stored * at the address is returned in eax:edx. */ - __asm__ __volatile__ (SMPLOCK "cmpxchg16b (%%rsi) \n\t" - "sete %0 \n\t" - : "=qm" (ret), "+a" (((int64_t *)oldval)[0]), "+d" (((int64_t *)oldval)[1]) - : "S" (addr), "b" (((int64_t *)&newval)[0]), "c" (((int64_t *)&newval)[1]) - : "memory", "cc"); + __asm__ __volatile__(SMPLOCK "cmpxchg16b (%%rsi) \n\t" + "sete %0 \n\t" + : "=qm"(ret), "+a"(((int64_t *) oldval)[0]), "+d"(((int64_t *) oldval)[1]) + : "S"(addr), "b"(((int64_t *) &newval)[0]), "c"(((int64_t *) &newval)[1]) + : "memory", "cc"); return (bool) ret; } -#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 +# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1 #endif /* OPAL_GCC_INLINE_ASSEMBLY */ - #if OPAL_GCC_INLINE_ASSEMBLY -#define OPAL_HAVE_ATOMIC_SWAP_32 1 +# define OPAL_HAVE_ATOMIC_SWAP_32 1 -#define OPAL_HAVE_ATOMIC_SWAP_64 1 +# define OPAL_HAVE_ATOMIC_SWAP_64 1 -static inline int32_t opal_atomic_swap_32( opal_atomic_int32_t *addr, - int32_t newval) +static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval) { int32_t oldval; - __asm__ __volatile__("xchg %1, %0" : - "=r" (oldval), "+m" (*addr) : - "0" (newval) : - "memory"); + __asm__ __volatile__("xchg %1, %0" : "=r"(oldval), "+m"(*addr) : "0"(newval) : "memory"); return oldval; } @@ -166,28 +157,22 @@ static inline int32_t opal_atomic_swap_32( opal_atomic_int32_t *addr, #if OPAL_GCC_INLINE_ASSEMBLY -static inline int64_t opal_atomic_swap_64( opal_atomic_int64_t *addr, - int64_t newval) +static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval) { int64_t oldval; - __asm__ __volatile__("xchgq %1, %0" : - "=r" (oldval), "+m" (*addr) : - "0" (newval) : - "memory"); + __asm__ __volatile__("xchgq %1, %0" : "=r"(oldval), "+m"(*addr) : "0"(newval) : "memory"); return oldval; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ - - #if OPAL_GCC_INLINE_ASSEMBLY -#define OPAL_HAVE_ATOMIC_MATH_32 1 -#define OPAL_HAVE_ATOMIC_MATH_64 1 +# define OPAL_HAVE_ATOMIC_MATH_32 1 +# define OPAL_HAVE_ATOMIC_MATH_64 1 -#define OPAL_HAVE_ATOMIC_ADD_32 1 +# define OPAL_HAVE_ATOMIC_ADD_32 1 /** * atomic_add - add integer to atomic variable @@ -196,19 +181,14 @@ static inline int64_t opal_atomic_swap_64( opal_atomic_int64_t *addr, * * Atomically adds @i to @v. */ -static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t* v, int i) +static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t *v, int i) { int ret = i; - __asm__ __volatile__( - SMPLOCK "xaddl %1,%0" - :"+m" (*v), "+r" (ret) - : - :"memory", "cc" - ); - return ret; + __asm__ __volatile__(SMPLOCK "xaddl %1,%0" : "+m"(*v), "+r"(ret) : : "memory", "cc"); + return ret; } -#define OPAL_HAVE_ATOMIC_ADD_64 1 +# define OPAL_HAVE_ATOMIC_ADD_64 1 /** * atomic_add - add integer to atomic variable @@ -217,19 +197,14 @@ static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t* v, int i) * * Atomically adds @i to @v. */ -static inline int64_t opal_atomic_fetch_add_64(opal_atomic_int64_t* v, int64_t i) +static inline int64_t opal_atomic_fetch_add_64(opal_atomic_int64_t *v, int64_t i) { int64_t ret = i; - __asm__ __volatile__( - SMPLOCK "xaddq %1,%0" - :"+m" (*v), "+r" (ret) - : - :"memory", "cc" - ); - return ret; + __asm__ __volatile__(SMPLOCK "xaddq %1,%0" : "+m"(*v), "+r"(ret) : : "memory", "cc"); + return ret; } -#define OPAL_HAVE_ATOMIC_SUB_32 1 +# define OPAL_HAVE_ATOMIC_SUB_32 1 /** * atomic_sub - subtract the atomic variable @@ -238,19 +213,14 @@ static inline int64_t opal_atomic_fetch_add_64(opal_atomic_int64_t* v, int64_t i * * Atomically subtracts @i from @v. */ -static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t* v, int i) +static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t *v, int i) { int ret = -i; - __asm__ __volatile__( - SMPLOCK "xaddl %1,%0" - :"+m" (*v), "+r" (ret) - : - :"memory", "cc" - ); - return ret; + __asm__ __volatile__(SMPLOCK "xaddl %1,%0" : "+m"(*v), "+r"(ret) : : "memory", "cc"); + return ret; } -#define OPAL_HAVE_ATOMIC_SUB_64 1 +# define OPAL_HAVE_ATOMIC_SUB_64 1 /** * atomic_sub - subtract the atomic variable @@ -259,16 +229,11 @@ static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t* v, int i) * * Atomically subtracts @i from @v. */ -static inline int64_t opal_atomic_fetch_sub_64(opal_atomic_int64_t* v, int64_t i) +static inline int64_t opal_atomic_fetch_sub_64(opal_atomic_int64_t *v, int64_t i) { int64_t ret = -i; - __asm__ __volatile__( - SMPLOCK "xaddq %1,%0" - :"+m" (*v), "+r" (ret) - : - :"memory", "cc" - ); - return ret; + __asm__ __volatile__(SMPLOCK "xaddq %1,%0" : "+m"(*v), "+r"(ret) : : "memory", "cc"); + return ret; } #endif /* OPAL_GCC_INLINE_ASSEMBLY */ diff --git a/opal/include/opal/sys/x86_64/timer.h b/opal/include/opal/sys/x86_64/timer.h index 9eb7e084208..743299e5e58 100644 --- a/opal/include/opal/sys/x86_64/timer.h +++ b/opal/include/opal/sys/x86_64/timer.h @@ -22,7 +22,6 @@ #ifndef OPAL_SYS_ARCH_TIMER_H #define OPAL_SYS_ARCH_TIMER_H 1 - typedef uint64_t opal_timer_t; /* Using RDTSC(P) results in non-monotonic timers across cores */ @@ -32,17 +31,16 @@ typedef uint64_t opal_timer_t; #if OPAL_GCC_INLINE_ASSEMBLY /* TODO: add AMD mfence version and dispatch at init */ -static inline opal_timer_t -opal_sys_timer_get_cycles(void) +static inline opal_timer_t opal_sys_timer_get_cycles(void) { - uint32_t l, h; - __asm__ __volatile__ ("lfence\n\t" - "rdtsc\n\t" - : "=a" (l), "=d" (h)); - return ((opal_timer_t)l) | (((opal_timer_t)h) << 32); + uint32_t l, h; + __asm__ __volatile__("lfence\n\t" + "rdtsc\n\t" + : "=a"(l), "=d"(h)); + return ((opal_timer_t) l) | (((opal_timer_t) h) << 32); } -static inline bool opal_sys_timer_is_monotonic (void) +static inline bool opal_sys_timer_is_monotonic(void) { int64_t tmp; int32_t cpuid1, cpuid2; @@ -50,22 +48,22 @@ static inline bool opal_sys_timer_is_monotonic (void) /* cpuid clobbers ebx but it must be restored for -fPIC so save * then restore ebx */ - __asm__ volatile ("xchg %%rbx, %2\n" - "cpuid\n" - "xchg %%rbx, %2\n": - "=a" (cpuid1), "=d" (cpuid2), "=r" (tmp) : - "a" (level) : - "ecx", "ebx"); + __asm__ volatile("xchg %%rbx, %2\n" + "cpuid\n" + "xchg %%rbx, %2\n" + : "=a"(cpuid1), "=d"(cpuid2), "=r"(tmp) + : "a"(level) + : "ecx", "ebx"); /* bit 8 of edx contains the invariant tsc flag */ return !!(cpuid2 & (1 << 8)); } -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 -#define OPAL_HAVE_SYS_TIMER_IS_MONOTONIC 1 +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1 +# define OPAL_HAVE_SYS_TIMER_IS_MONOTONIC 1 #else -#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 +# define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0 #endif /* OPAL_GCC_INLINE_ASSEMBLY */ diff --git a/opal/include/opal/types.h b/opal/include/opal/types.h index 2089057365a..bca24de238f 100644 --- a/opal/include/opal/types.h +++ b/opal/include/opal/types.h @@ -24,23 +24,23 @@ #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_SELECT_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" #endif /* @@ -48,13 +48,13 @@ */ typedef union { - uint64_t lval; - uint32_t ival; - void* pval; - struct { - uint32_t uval; - uint32_t lval; - } sval; + uint64_t lval; + uint32_t ival; + void *pval; + struct { + uint32_t uval; + uint32_t lval; + } sval; } opal_ptr_t; /* @@ -62,11 +62,11 @@ typedef union { */ #if defined(__APPLE__) || defined(__WINDOWS__) -typedef char* opal_iov_base_ptr_t; -#define OPAL_IOVBASE char +typedef char *opal_iov_base_ptr_t; +# define OPAL_IOVBASE char #else -#define OPAL_IOVBASE void -typedef void* opal_iov_base_ptr_t; +# define OPAL_IOVBASE void +typedef void *opal_iov_base_ptr_t; #endif /* @@ -79,7 +79,6 @@ typedef socklen_t opal_socklen_t; typedef int opal_socklen_t; #endif - /* * Convert a 64 bit value to network byte order. */ @@ -87,12 +86,13 @@ static inline uint64_t hton64(uint64_t val) __opal_attribute_const__; static inline uint64_t hton64(uint64_t val) { #ifdef HAVE_UNIX_BYTESWAP - union { uint64_t ll; - uint32_t l[2]; + union { + uint64_t ll; + uint32_t l[2]; } w, r; /* platform already in network byte order? */ - if(htonl(1) == 1L) + if (htonl(1) == 1L) return val; w.ll = val; r.l[0] = htonl(w.l[1]); @@ -111,12 +111,13 @@ static inline uint64_t ntoh64(uint64_t val) __opal_attribute_const__; static inline uint64_t ntoh64(uint64_t val) { #ifdef HAVE_UNIX_BYTESWAP - union { uint64_t ll; - uint32_t l[2]; + union { + uint64_t ll; + uint32_t l[2]; } w, r; /* platform already in network byte order? */ - if(htonl(1) == 1L) + if (htonl(1) == 1L) return val; w.ll = val; r.l[0] = ntohl(w.l[1]); @@ -127,33 +128,33 @@ static inline uint64_t ntoh64(uint64_t val) #endif } - /** * Convert between a local representation of pointer and a 64 bits value. */ -static inline uint64_t opal_ptr_ptol( void* ptr ) __opal_attribute_const__; -static inline uint64_t opal_ptr_ptol( void* ptr ) +static inline uint64_t opal_ptr_ptol(void *ptr) __opal_attribute_const__; +static inline uint64_t opal_ptr_ptol(void *ptr) { return (uint64_t)(uintptr_t) ptr; } -static inline void* opal_ptr_ltop( uint64_t value ) __opal_attribute_const__; -static inline void* opal_ptr_ltop( uint64_t value ) +static inline void *opal_ptr_ltop(uint64_t value) __opal_attribute_const__; +static inline void *opal_ptr_ltop(uint64_t value) { #if SIZEOF_VOID_P == 4 && OPAL_ENABLE_DEBUG if (value > ((1ULL << 32) - 1ULL)) { opal_output(0, "Warning: truncating value in opal_ptr_ltop"); } #endif - return (void*)(uintptr_t) value; + return (void *) (uintptr_t) value; } #if defined(WORDS_BIGENDIAN) || !defined(HAVE_UNIX_BYTESWAP) static inline uint16_t opal_swap_bytes2(uint16_t val) __opal_attribute_const__; static inline uint16_t opal_swap_bytes2(uint16_t val) { - union { uint16_t bigval; - uint8_t arrayval[2]; + union { + uint16_t bigval; + uint8_t arrayval[2]; } w, r; w.bigval = val; @@ -166,8 +167,9 @@ static inline uint16_t opal_swap_bytes2(uint16_t val) static inline uint32_t opal_swap_bytes4(uint32_t val) __opal_attribute_const__; static inline uint32_t opal_swap_bytes4(uint32_t val) { - union { uint32_t bigval; - uint8_t arrayval[4]; + union { + uint32_t bigval; + uint8_t arrayval[4]; } w, r; w.bigval = val; @@ -182,8 +184,9 @@ static inline uint32_t opal_swap_bytes4(uint32_t val) static inline uint64_t opal_swap_bytes8(uint64_t val) __opal_attribute_const__; static inline uint64_t opal_swap_bytes8(uint64_t val) { - union { uint64_t bigval; - uint8_t arrayval[8]; + union { + uint64_t bigval; + uint8_t arrayval[8]; } w, r; w.bigval = val; @@ -200,9 +203,9 @@ static inline uint64_t opal_swap_bytes8(uint64_t val) } #else -#define opal_swap_bytes2 htons -#define opal_swap_bytes4 htonl -#define opal_swap_bytes8 hton64 +# define opal_swap_bytes2 htons +# define opal_swap_bytes4 htonl +# define opal_swap_bytes8 hton64 #endif /* WORDS_BIGENDIAN || !HAVE_UNIX_BYTESWAP */ #endif /* OPAL_TYPES_H */ diff --git a/opal/include/opal_config_bottom.h b/opal/include/opal_config_bottom.h index d6f47f102f3..d2dd91c9a67 100644 --- a/opal/include/opal_config_bottom.h +++ b/opal/include/opal_config_bottom.h @@ -32,7 +32,7 @@ */ #ifndef OPAL_CONFIG_H -#error "opal_config_bottom.h should only be included from opal_config.h" +# error "opal_config_bottom.h should only be included from opal_config.h" #endif /* @@ -51,7 +51,7 @@ * default to 0. */ #ifndef OMPI_BUILDING -#define OMPI_BUILDING 1 +# define OMPI_BUILDING 1 #endif /* @@ -61,7 +61,7 @@ * know this file is not available, we can prevent flex from including it. */ #ifndef HAVE_UNISTD_H -#define YY_NO_UNISTD_H +# define YY_NO_UNISTD_H #endif /*********************************************************************** @@ -79,11 +79,11 @@ #undef BEGIN_C_DECLS #undef END_C_DECLS #if defined(c_plusplus) || defined(__cplusplus) -# define BEGIN_C_DECLS extern "C" { -# define END_C_DECLS } +# define BEGIN_C_DECLS extern "C" { +# define END_C_DECLS } #else -#define BEGIN_C_DECLS /* empty */ -#define END_C_DECLS /* empty */ +# define BEGIN_C_DECLS /* empty */ +# define END_C_DECLS /* empty */ #endif /** @@ -91,8 +91,8 @@ * usage. */ #if OPAL_HAVE_ATTRIBUTE_ALIGNED -# define __opal_attribute_aligned__(a) __attribute__((__aligned__(a))) -# define __opal_attribute_aligned_max__ __attribute__((__aligned__)) +# define __opal_attribute_aligned__(a) __attribute__((__aligned__(a))) +# define __opal_attribute_aligned_max__ __attribute__((__aligned__)) #else # define __opal_attribute_aligned__(a) # define __opal_attribute_aligned_max__ @@ -105,107 +105,107 @@ #endif #if OPAL_HAVE_ATTRIBUTE_COLD -# define __opal_attribute_cold__ __attribute__((__cold__)) +# define __opal_attribute_cold__ __attribute__((__cold__)) #else # define __opal_attribute_cold__ #endif #if OPAL_HAVE_ATTRIBUTE_CONST -# define __opal_attribute_const__ __attribute__((__const__)) +# define __opal_attribute_const__ __attribute__((__const__)) #else # define __opal_attribute_const__ #endif #if OPAL_HAVE_ATTRIBUTE_DEPRECATED -# define __opal_attribute_deprecated__ __attribute__((__deprecated__)) +# define __opal_attribute_deprecated__ __attribute__((__deprecated__)) #else # define __opal_attribute_deprecated__ #endif #if OPAL_HAVE_ATTRIBUTE_FORMAT -# define __opal_attribute_format__(a,b,c) __attribute__((__format__(a, b, c))) +# define __opal_attribute_format__(a, b, c) __attribute__((__format__(a, b, c))) #else -# define __opal_attribute_format__(a,b,c) +# define __opal_attribute_format__(a, b, c) #endif /* Use this __atribute__ on function-ptr declarations, only */ #if OPAL_HAVE_ATTRIBUTE_FORMAT_FUNCPTR -# define __opal_attribute_format_funcptr__(a,b,c) __attribute__((__format__(a, b, c))) +# define __opal_attribute_format_funcptr__(a, b, c) __attribute__((__format__(a, b, c))) #else -# define __opal_attribute_format_funcptr__(a,b,c) +# define __opal_attribute_format_funcptr__(a, b, c) #endif #if OPAL_HAVE_ATTRIBUTE_HOT -# define __opal_attribute_hot__ __attribute__((__hot__)) +# define __opal_attribute_hot__ __attribute__((__hot__)) #else # define __opal_attribute_hot__ #endif #if OPAL_HAVE_ATTRIBUTE_MALLOC -# define __opal_attribute_malloc__ __attribute__((__malloc__)) +# define __opal_attribute_malloc__ __attribute__((__malloc__)) #else # define __opal_attribute_malloc__ #endif #if OPAL_HAVE_ATTRIBUTE_MAY_ALIAS -# define __opal_attribute_may_alias__ __attribute__((__may_alias__)) +# define __opal_attribute_may_alias__ __attribute__((__may_alias__)) #else # define __opal_attribute_may_alias__ #endif #if OPAL_HAVE_ATTRIBUTE_NO_INSTRUMENT_FUNCTION -# define __opal_attribute_no_instrument_function__ __attribute__((__no_instrument_function__)) +# define __opal_attribute_no_instrument_function__ __attribute__((__no_instrument_function__)) #else # define __opal_attribute_no_instrument_function__ #endif #if OPAL_HAVE_ATTRIBUTE_NOINLINE -# define __opal_attribute_noinline__ __attribute__((__noinline__)) +# define __opal_attribute_noinline__ __attribute__((__noinline__)) #else # define __opal_attribute_noinline__ #endif #if OPAL_HAVE_ATTRIBUTE_NONNULL -# define __opal_attribute_nonnull__(a) __attribute__((__nonnull__(a))) -# define __opal_attribute_nonnull_all__ __attribute__((__nonnull__)) +# define __opal_attribute_nonnull__(a) __attribute__((__nonnull__(a))) +# define __opal_attribute_nonnull_all__ __attribute__((__nonnull__)) #else # define __opal_attribute_nonnull__(a) # define __opal_attribute_nonnull_all__ #endif #if OPAL_HAVE_ATTRIBUTE_NORETURN -# define __opal_attribute_noreturn__ __attribute__((__noreturn__)) +# define __opal_attribute_noreturn__ __attribute__((__noreturn__)) #else # define __opal_attribute_noreturn__ #endif /* Use this __atribute__ on function-ptr declarations, only */ #if OPAL_HAVE_ATTRIBUTE_NORETURN_FUNCPTR -# define __opal_attribute_noreturn_funcptr__ __attribute__((__noreturn__)) +# define __opal_attribute_noreturn_funcptr__ __attribute__((__noreturn__)) #else # define __opal_attribute_noreturn_funcptr__ #endif #if OPAL_HAVE_ATTRIBUTE_PACKED -# define __opal_attribute_packed__ __attribute__((__packed__)) +# define __opal_attribute_packed__ __attribute__((__packed__)) #else # define __opal_attribute_packed__ #endif #if OPAL_HAVE_ATTRIBUTE_PURE -# define __opal_attribute_pure__ __attribute__((__pure__)) +# define __opal_attribute_pure__ __attribute__((__pure__)) #else # define __opal_attribute_pure__ #endif #if OPAL_HAVE_ATTRIBUTE_SENTINEL -# define __opal_attribute_sentinel__ __attribute__((__sentinel__)) +# define __opal_attribute_sentinel__ __attribute__((__sentinel__)) #else # define __opal_attribute_sentinel__ #endif #if OPAL_HAVE_ATTRIBUTE_UNUSED -# define __opal_attribute_unused__ __attribute__((__unused__)) +# define __opal_attribute_unused__ __attribute__((__unused__)) #else # define __opal_attribute_unused__ #endif @@ -229,36 +229,36 @@ #endif #if OPAL_HAVE_ATTRIBUTE_DESTRUCTOR -# define __opal_attribute_destructor__ __attribute__((__destructor__)) +# define __opal_attribute_destructor__ __attribute__((__destructor__)) #else # define __opal_attribute_destructor__ #endif #if OPAL_HAVE_ATTRIBUTE_OPTNONE -# define __opal_attribute_optnone__ __attribute__((__optnone__)) +# define __opal_attribute_optnone__ __attribute__((__optnone__)) #else # define __opal_attribute_optnone__ #endif #if OPAL_HAVE_ATTRIBUTE_EXTENSION -# define __opal_attribute_extension__ __extension__ +# define __opal_attribute_extension__ __extension__ #else # define __opal_attribute_extension__ #endif -# if OPAL_C_HAVE_VISIBILITY -# define OPAL_DECLSPEC __opal_attribute_visibility__("default") -# define OPAL_MODULE_DECLSPEC __opal_attribute_visibility__("default") -# else +#if OPAL_C_HAVE_VISIBILITY +# define OPAL_DECLSPEC __opal_attribute_visibility__("default") +# define OPAL_MODULE_DECLSPEC __opal_attribute_visibility__("default") +#else # define OPAL_DECLSPEC # define OPAL_MODULE_DECLSPEC -# endif +#endif -#if !defined(__STDC_LIMIT_MACROS) && (defined(c_plusplus) || defined (__cplusplus)) +#if !defined(__STDC_LIMIT_MACROS) && (defined(c_plusplus) || defined(__cplusplus)) /* When using a C++ compiler, the max / min value #defines for std types are only included if __STDC_LIMIT_MACROS is set before including stdint.h */ -#define __STDC_LIMIT_MACROS +# define __STDC_LIMIT_MACROS #endif #include "opal_stdint.h" @@ -274,38 +274,38 @@ /* * Maximum size of a filename path. */ -#include -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#if defined(PATH_MAX) -#define OPAL_PATH_MAX (PATH_MAX + 1) -#elif defined(_POSIX_PATH_MAX) -#define OPAL_PATH_MAX (_POSIX_PATH_MAX + 1) -#else -#define OPAL_PATH_MAX 256 -#endif +# include +# ifdef HAVE_SYS_PARAM_H +# include +# endif +# if defined(PATH_MAX) +# define OPAL_PATH_MAX (PATH_MAX + 1) +# elif defined(_POSIX_PATH_MAX) +# define OPAL_PATH_MAX (_POSIX_PATH_MAX + 1) +# else +# define OPAL_PATH_MAX 256 +# endif /* * Set the compile-time path-separator on this system and variable separator */ -#define OPAL_PATH_SEP "/" -#define OPAL_ENV_SEP ':' - -#if defined(MAXHOSTNAMELEN) -#define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1) -#elif defined(HOST_NAME_MAX) -#define OPAL_MAXHOSTNAMELEN (HOST_NAME_MAX + 1) -#else +# define OPAL_PATH_SEP "/" +# define OPAL_ENV_SEP ':' + +# if defined(MAXHOSTNAMELEN) +# define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1) +# elif defined(HOST_NAME_MAX) +# define OPAL_MAXHOSTNAMELEN (HOST_NAME_MAX + 1) +# else /* SUSv2 guarantees that "Host names are limited to 255 bytes". */ -#define OPAL_MAXHOSTNAMELEN (255 + 1) -#endif +# define OPAL_MAXHOSTNAMELEN (255 + 1) +# endif -#define OPAL_LOCAL_MAXHOSTNAMELEN 4096 +# define OPAL_LOCAL_MAXHOSTNAMELEN 4096 -#if (OPAL_MAXHOSTNAMELEN > OPAL_LOCAL_MAXHOSTNAMELEN) -#define OPAL_LOCAL_MAXHOSTNAMELEN OPAL_MAXHOSTNAMELEN -#endif +# if (OPAL_MAXHOSTNAMELEN > OPAL_LOCAL_MAXHOSTNAMELEN) +# define OPAL_LOCAL_MAXHOSTNAMELEN OPAL_MAXHOSTNAMELEN +# endif /* * Do we want memory debugging? @@ -326,80 +326,81 @@ * this stuff enabled (like the memory manager code) a way to turn us * off */ -#if OPAL_ENABLE_MEM_DEBUG && !defined(OPAL_DISABLE_ENABLE_MEM_DEBUG) +# if OPAL_ENABLE_MEM_DEBUG && !defined(OPAL_DISABLE_ENABLE_MEM_DEBUG) /* It is safe to include opal/util/malloc.h here because a) it will only happen when we are building OMPI and therefore have a full OMPI source tree [including headers] available, and b) we guaranteed to *not* to include anything else via opal/util/malloc.h, so we won't have Cascading Includes Of Death. */ -# include "opal/util/malloc.h" -# if defined(malloc) -# undef malloc -# endif -# define malloc(size) opal_malloc((size), __FILE__, __LINE__) -# if defined(calloc) -# undef calloc -# endif -# define calloc(nmembers, size) opal_calloc((nmembers), (size), __FILE__, __LINE__) -# if defined(realloc) -# undef realloc -# endif -# define realloc(ptr, size) opal_realloc((ptr), (size), __FILE__, __LINE__) -# if defined(free) -# undef free -# endif -# define free(ptr) opal_free((ptr), __FILE__, __LINE__) +# include "opal/util/malloc.h" +# if defined(malloc) +# undef malloc +# endif +# define malloc(size) opal_malloc((size), __FILE__, __LINE__) +# if defined(calloc) +# undef calloc +# endif +# define calloc(nmembers, size) opal_calloc((nmembers), (size), __FILE__, __LINE__) +# if defined(realloc) +# undef realloc +# endif +# define realloc(ptr, size) opal_realloc((ptr), (size), __FILE__, __LINE__) +# if defined(free) +# undef free +# endif +# define free(ptr) opal_free((ptr), __FILE__, __LINE__) /* * If we're mem debugging, make the OPAL_DEBUG_ZERO resolve to memset */ -# include -# define OPAL_DEBUG_ZERO(obj) memset(&(obj), 0, sizeof(obj)) -#else -# define OPAL_DEBUG_ZERO(obj) -#endif +# include +# define OPAL_DEBUG_ZERO(obj) memset(&(obj), 0, sizeof(obj)) +# else +# define OPAL_DEBUG_ZERO(obj) +# endif /* * printf functions for portability (only when building Open MPI) */ -#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) -#include -#include -#endif +# if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) +# include +# include +# endif -#if !defined(HAVE_ASPRINTF) || !defined(HAVE_SNPRINTF) || !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) -#include "opal/util/printf.h" -#endif +# if !defined(HAVE_ASPRINTF) || !defined(HAVE_SNPRINTF) || !defined(HAVE_VASPRINTF) \ + || !defined(HAVE_VSNPRINTF) +# include "opal/util/printf.h" +# endif -#ifndef HAVE_ASPRINTF -# define asprintf opal_asprintf -#endif +# ifndef HAVE_ASPRINTF +# define asprintf opal_asprintf +# endif -#ifndef HAVE_SNPRINTF -# define snprintf opal_snprintf -#endif +# ifndef HAVE_SNPRINTF +# define snprintf opal_snprintf +# endif -#ifndef HAVE_VASPRINTF -# define vasprintf opal_vasprintf -#endif +# ifndef HAVE_VASPRINTF +# define vasprintf opal_vasprintf +# endif -#ifndef HAVE_VSNPRINTF -# define vsnprintf opal_vsnprintf -#endif +# ifndef HAVE_VSNPRINTF +# define vsnprintf opal_vsnprintf +# endif /* * Some platforms (Solaris) have a broken qsort implementation. Work * around by using our own. */ -#if OPAL_HAVE_BROKEN_QSORT -#ifdef qsort -#undef qsort -#endif +# if OPAL_HAVE_BROKEN_QSORT +# ifdef qsort +# undef qsort +# endif -#include "opal/util/qsort.h" -#define qsort opal_qsort -#endif +# include "opal/util/qsort.h" +# define qsort opal_qsort +# endif /* * On some homogenous big-iron machines (Sandia's Red Storm), there @@ -408,12 +409,24 @@ * and would want to talk to the outside world... On other platforms * we fail to detect them correctly. */ -#if !defined(HAVE_UNIX_BYTESWAP) -static inline uint32_t htonl(uint32_t hostvar) { return hostvar; } -static inline uint32_t ntohl(uint32_t netvar) { return netvar; } -static inline uint16_t htons(uint16_t hostvar) { return hostvar; } -static inline uint16_t ntohs(uint16_t netvar) { return netvar; } -#endif +# if !defined(HAVE_UNIX_BYTESWAP) +static inline uint32_t htonl(uint32_t hostvar) +{ + return hostvar; +} +static inline uint32_t ntohl(uint32_t netvar) +{ + return netvar; +} +static inline uint16_t htons(uint16_t hostvar) +{ + return hostvar; +} +static inline uint16_t ntohs(uint16_t netvar) +{ + return netvar; +} +# endif /* * Define __func__-preprocessor directive if the compiler does not @@ -422,61 +435,61 @@ static inline uint16_t ntohs(uint16_t netvar) { return netvar; } * coming from (assuming that __func__ is typically used for * printf-style debugging). */ -#if defined(HAVE_DECL___FUNC__) && !HAVE_DECL___FUNC__ -#define __func__ __FILE__ -#endif +# if defined(HAVE_DECL___FUNC__) && !HAVE_DECL___FUNC__ +# define __func__ __FILE__ +# endif -#define IOVBASE_TYPE void +# define IOVBASE_TYPE void /* ensure the bool type is defined as it is used everywhere */ -#include +# include /** * If we generate our own bool type, we need a special way to cast the result * in such a way to keep the compilers silent. */ -# define OPAL_INT_TO_BOOL(VALUE) (bool)(VALUE) +# define OPAL_INT_TO_BOOL(VALUE) (bool) (VALUE) /** * Top level define to check 2 things: a) if we want ipv6 support, and * b) the underlying system supports ipv6. Having one #define for * this makes it simpler to check throughout the code base. */ -#if OPAL_ENABLE_IPV6 && defined(HAVE_STRUCT_SOCKADDR_IN6) -#define OPAL_ENABLE_IPV6 1 -#else -#define OPAL_ENABLE_IPV6 0 -#endif +# if OPAL_ENABLE_IPV6 && defined(HAVE_STRUCT_SOCKADDR_IN6) +# define OPAL_ENABLE_IPV6 1 +# else +# define OPAL_ENABLE_IPV6 0 +# endif -#if !defined(HAVE_STRUCT_SOCKADDR_STORAGE) && defined(HAVE_STRUCT_SOCKADDR_IN) -#define sockaddr_storage sockaddr -#define ss_family sa_family -#endif +# if !defined(HAVE_STRUCT_SOCKADDR_STORAGE) && defined(HAVE_STRUCT_SOCKADDR_IN) +# define sockaddr_storage sockaddr +# define ss_family sa_family +# endif /* Compatibility structure so that we don't have to have as many #if checks in the code base */ -#if !defined(HAVE_STRUCT_SOCKADDR_IN6) && defined(HAVE_STRUCT_SOCKADDR_IN) -#define sockaddr_in6 sockaddr_in -#define sin6_len sin_len -#define sin6_family sin_family -#define sin6_port sin_port -#define sin6_addr sin_addr -#endif +# if !defined(HAVE_STRUCT_SOCKADDR_IN6) && defined(HAVE_STRUCT_SOCKADDR_IN) +# define sockaddr_in6 sockaddr_in +# define sin6_len sin_len +# define sin6_family sin_family +# define sin6_port sin_port +# define sin6_addr sin_addr +# endif -#if !HAVE_DECL_AF_UNSPEC -#define AF_UNSPEC 0 -#endif -#if !HAVE_DECL_PF_UNSPEC -#define PF_UNSPEC 0 -#endif -#if !HAVE_DECL_AF_INET6 -#define AF_INET6 AF_UNSPEC -#endif -#if !HAVE_DECL_PF_INET6 -#define PF_INET6 PF_UNSPEC -#endif +# if !HAVE_DECL_AF_UNSPEC +# define AF_UNSPEC 0 +# endif +# if !HAVE_DECL_PF_UNSPEC +# define PF_UNSPEC 0 +# endif +# if !HAVE_DECL_AF_INET6 +# define AF_INET6 AF_UNSPEC +# endif +# if !HAVE_DECL_PF_INET6 +# define PF_INET6 PF_UNSPEC +# endif -#if defined(__APPLE__) && defined(HAVE_INTTYPES_H) +# if defined(__APPLE__) && defined(HAVE_INTTYPES_H) /* Prior to Mac OS X 10.3, the length modifier "ll" wasn't supported, but "q" was for long long. This isn't ANSI C and causes a warning when using PRI?64 macros. We @@ -484,51 +497,51 @@ static inline uint16_t ntohs(uint16_t netvar) { return netvar; } need such backward compatibility. Instead, redefine the macros to be "ll", which is ANSI C and doesn't cause a compiler warning. */ -#include -#if defined(__PRI_64_LENGTH_MODIFIER__) -#undef __PRI_64_LENGTH_MODIFIER__ -#define __PRI_64_LENGTH_MODIFIER__ "ll" -#endif -#if defined(__SCN_64_LENGTH_MODIFIER__) -#undef __SCN_64_LENGTH_MODIFIER__ -#define __SCN_64_LENGTH_MODIFIER__ "ll" -#endif -#endif +# include +# if defined(__PRI_64_LENGTH_MODIFIER__) +# undef __PRI_64_LENGTH_MODIFIER__ +# define __PRI_64_LENGTH_MODIFIER__ "ll" +# endif +# if defined(__SCN_64_LENGTH_MODIFIER__) +# undef __SCN_64_LENGTH_MODIFIER__ +# define __SCN_64_LENGTH_MODIFIER__ "ll" +# endif +# endif -#ifdef MCS_VXWORKS +# ifdef MCS_VXWORKS /* VXWorks puts some common functions in oddly named headers. Rather than update all the places the functions are used, which would be a maintenance disatster, just update here... */ -#ifdef HAVE_IOLIB_H +# ifdef HAVE_IOLIB_H /* pipe(), ioctl() */ -#include -#endif -#ifdef HAVE_SOCKLIB_H +# include +# endif +# ifdef HAVE_SOCKLIB_H /* socket() */ -#include -#endif -#ifdef HAVE_HOSTLIB_H +# include +# endif +# ifdef HAVE_HOSTLIB_H /* gethostname() */ -#include -#endif -#endif +# include +# endif +# endif /* If we're in C++, then just undefine restrict and then define it to nothing. "restrict" is not part of the C++ language, and we don't have a corresponding AC_CXX_RESTRICT to figure out what the C++ compiler supports. */ -#if defined(c_plusplus) || defined(__cplusplus) -#undef restrict -#define restrict -#endif +# if defined(c_plusplus) || defined(__cplusplus) +# undef restrict +# define restrict +# endif -#ifdef HAVE_OPAL_SHORT_FLOAT_COMPLEX_T -#undef opal_short_float_complex_t +# ifdef HAVE_OPAL_SHORT_FLOAT_COMPLEX_T +# undef opal_short_float_complex_t typedef struct { opal_short_float_t real; opal_short_float_t imag; } opal_short_float_complex_t; -#endif +# endif #else @@ -541,12 +554,12 @@ typedef struct { So put them here in case any only else includes OMPI/ORTE/OPAL's config.h files. */ -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#undef PACKAGE_URL -#undef HAVE_CONFIG_H +# undef PACKAGE_BUGREPORT +# undef PACKAGE_NAME +# undef PACKAGE_STRING +# undef PACKAGE_TARNAME +# undef PACKAGE_VERSION +# undef PACKAGE_URL +# undef HAVE_CONFIG_H #endif /* OMPI_BUILDING */ diff --git a/opal/include/opal_config_top.h b/opal/include/opal_config_top.h index 1ce5267c389..a8b4e687846 100644 --- a/opal/include/opal_config_top.h +++ b/opal/include/opal_config_top.h @@ -16,7 +16,7 @@ */ #ifndef OPAL_CONFIG_H -#error "opal_config_top.h should only be included from opal_config.h" +# error "opal_config_top.h should only be included from opal_config.h" #endif /* The only purpose of this file is to undef the PACKAGE_ macros diff --git a/opal/include/opal_stdatomic.h b/opal/include/opal_stdatomic.h index 4c76f59c26a..4af17bc2b42 100644 --- a/opal/include/opal_stdatomic.h +++ b/opal/include/opal_stdatomic.h @@ -10,11 +10,11 @@ */ #if !defined(OPAL_STDATOMIC_H) -#define OPAL_STDATOMIC_H +# define OPAL_STDATOMIC_H -#include "opal_stdint.h" +# include "opal_stdint.h" -#if (OPAL_ASSEMBLY_BUILTIN != OPAL_BUILTIN_C11) || defined(__INTEL_COMPILER) +# if (OPAL_ASSEMBLY_BUILTIN != OPAL_BUILTIN_C11) || defined(__INTEL_COMPILER) typedef volatile int opal_atomic_int_t; typedef volatile long opal_atomic_long_t; @@ -29,15 +29,15 @@ typedef volatile ssize_t opal_atomic_ssize_t; typedef volatile intptr_t opal_atomic_intptr_t; typedef volatile uintptr_t opal_atomic_uintptr_t; -#else /* OPAL_HAVE_C__ATOMIC */ +# else /* OPAL_HAVE_C__ATOMIC */ -#include +# include -#ifdef __INTEL_COMPILER -#if __INTEL_COMPILER_BUILD_DATE <= 20200310 +# ifdef __INTEL_COMPILER +# if __INTEL_COMPILER_BUILD_DATE <= 20200310 #warning C11 _Atomic type not fully supported. The C11 atomic support should have been disabled. -#endif -#endif +# endif +# endif typedef atomic_int opal_atomic_int_t; typedef atomic_long opal_atomic_long_t; @@ -52,21 +52,21 @@ typedef _Atomic ssize_t opal_atomic_ssize_t; typedef _Atomic intptr_t opal_atomic_intptr_t; typedef _Atomic uintptr_t opal_atomic_uintptr_t; -#endif /* OPAL_HAVE_C__ATOMIC */ +# endif /* OPAL_HAVE_C__ATOMIC */ -#if HAVE_OPAL_INT128_T +# if HAVE_OPAL_INT128_T /* do not use C11 atomics for __int128 if they are not lock free */ -#if OPAL_HAVE_C11_CSWAP_INT128 && ! defined(__INTEL_COMPILER) +# if OPAL_HAVE_C11_CSWAP_INT128 && !defined(__INTEL_COMPILER) typedef _Atomic opal_int128_t opal_atomic_int128_t; -#else +# else typedef volatile opal_int128_t opal_atomic_int128_t; -#endif +# endif -#endif +# endif #endif /* !defined(OPAL_STDATOMIC_H) */ diff --git a/opal/include/opal_stdint.h b/opal/include/opal_stdint.h index e514b3854db..c5601f421cb 100644 --- a/opal/include/opal_stdint.h +++ b/opal/include/opal_stdint.h @@ -37,7 +37,7 @@ #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif /* 128-bit */ @@ -47,29 +47,29 @@ typedef int128_t opal_int128_t; typedef uint128_t opal_uint128_t; -#define HAVE_OPAL_INT128_T 1 +# define HAVE_OPAL_INT128_T 1 #elif defined(HAVE___INT128) /* suppress warning about __int128 type */ -#pragma GCC diagnostic push +# pragma GCC diagnostic push /* Clang won't quietly accept "-pedantic", but GCC versions older than ~4.8 * won't quietly accept "-Wpedanic". The whole "#pragma GCC diagnostic ..." * facility only was added to GCC as of version 4.6. */ -#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 6) -#pragma GCC diagnostic ignored "-Wpedantic" -#else -#pragma GCC diagnostic ignored "-pedantic" -#endif +# if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 6) +# pragma GCC diagnostic ignored "-Wpedantic" +# else +# pragma GCC diagnostic ignored "-pedantic" +# endif typedef __int128 opal_int128_t; typedef unsigned __int128 opal_uint128_t; -#pragma GCC diagnostic pop +# pragma GCC diagnostic pop -#define HAVE_OPAL_INT128_T 1 +# define HAVE_OPAL_INT128_T 1 #else -#define HAVE_OPAL_INT128_T 0 +# define HAVE_OPAL_INT128_T 0 #endif @@ -77,53 +77,52 @@ typedef unsigned __int128 opal_uint128_t; #if SIZEOF_VOID_P == SIZEOF_INT -#ifndef HAVE_INTPTR_T +# ifndef HAVE_INTPTR_T typedef signed int intptr_t; -#endif +# endif -#ifndef HAVE_UINTPTR_T +# ifndef HAVE_UINTPTR_T typedef unsigned int uintptr_t; -#endif +# endif #elif SIZEOF_VOID_P == SIZEOF_LONG -#ifndef HAVE_INTPTR_T +# ifndef HAVE_INTPTR_T typedef signed long intptr_t; -#endif +# endif -#ifndef HAVE_UINTPTR_T +# ifndef HAVE_UINTPTR_T typedef unsigned long uintptr_t; -#endif +# endif #elif SIZEOF_VOID_P == SIZEOF_LONG_LONG -#ifndef HAVE_INTPTR_T +# ifndef HAVE_INTPTR_T typedef signed long long intptr_t; -#endif -#ifndef HAVE_UINTPTR_T +# endif +# ifndef HAVE_UINTPTR_T typedef unsigned long long uintptr_t; -#endif +# endif #else -#error Failed to define pointer-sized integer types +# error Failed to define pointer-sized integer types #endif /* inttypes.h printf specifiers */ -# include +#include #ifndef PRIsize_t -# if defined(ACCEPT_C99) -# define PRIsize_t "zu" -# elif SIZEOF_SIZE_T == SIZEOF_LONG -# define PRIsize_t "lu" -# elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG -# define PRIsize_t "llu" -# else -# define PRIsize_t "u" -# endif +# if defined(ACCEPT_C99) +# define PRIsize_t "zu" +# elif SIZEOF_SIZE_T == SIZEOF_LONG +# define PRIsize_t "lu" +# elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG +# define PRIsize_t "llu" +# else +# define PRIsize_t "u" +# endif #endif #endif /* OPAL_STDINT_H */ - diff --git a/opal/mca/allocator/allocator.h b/opal/mca/allocator/allocator.h index 77180462c3d..28b87ddad36 100644 --- a/opal/mca/allocator/allocator.h +++ b/opal/mca/allocator/allocator.h @@ -19,9 +19,9 @@ * $HEADER$ */ /** - * @file - * The public definition of the MCA Allocator framework. - */ + * @file + * The public definition of the MCA Allocator framework. + */ #ifndef MCA_ALLOCATOR_H #define MCA_ALLOCATOR_H @@ -34,43 +34,35 @@ BEGIN_C_DECLS struct mca_allocator_base_module_t; /** - * The allocate function typedef for the function to be provided by the component. - */ -typedef void* (*mca_allocator_base_module_alloc_fn_t)( - struct mca_allocator_base_module_t*, - size_t size, - size_t align); + * The allocate function typedef for the function to be provided by the component. + */ +typedef void *(*mca_allocator_base_module_alloc_fn_t)(struct mca_allocator_base_module_t *, + size_t size, size_t align); /** - * The realloc function typedef - */ -typedef void* (*mca_allocator_base_module_realloc_fn_t)( - struct mca_allocator_base_module_t*, - void*, size_t); + * The realloc function typedef + */ +typedef void *(*mca_allocator_base_module_realloc_fn_t)(struct mca_allocator_base_module_t *, + void *, size_t); /** - * Free function typedef - */ -typedef void(*mca_allocator_base_module_free_fn_t)( - struct mca_allocator_base_module_t*, void *); - + * Free function typedef + */ +typedef void (*mca_allocator_base_module_free_fn_t)(struct mca_allocator_base_module_t *, void *); /** * compact/return memory to higher level allocator */ typedef int (*mca_allocator_base_module_compact_fn_t)( - struct mca_allocator_base_module_t* allocator -); - + struct mca_allocator_base_module_t *allocator); /** * cleanup (free) any resources held by allocator */ typedef int (*mca_allocator_base_module_finalize_fn_t)( - struct mca_allocator_base_module_t* allocator -); + struct mca_allocator_base_module_t *allocator); /** * The data structure for each component. @@ -94,34 +86,26 @@ struct mca_allocator_base_module_t { */ typedef struct mca_allocator_base_module_t mca_allocator_base_module_t; - /** - * A function to get more memory from the system. This function is to be - * provided by the module to the allocator framework. - */ + * A function to get more memory from the system. This function is to be + * provided by the module to the allocator framework. + */ -typedef void* (*mca_allocator_base_component_segment_alloc_fn_t)(void *ctx, - size_t *size); +typedef void *(*mca_allocator_base_component_segment_alloc_fn_t)(void *ctx, size_t *size); /** - * A function to free memory from the control of the allocator framework - * back to the system. This function is to be provided by the module to the - * allocator framework. - */ -typedef void (*mca_allocator_base_component_segment_free_fn_t)(void *ctx, - void *segment); - + * A function to free memory from the control of the allocator framework + * back to the system. This function is to be provided by the module to the + * allocator framework. + */ +typedef void (*mca_allocator_base_component_segment_free_fn_t)(void *ctx, void *segment); /** - * The function used to initialize the component. - */ -typedef struct mca_allocator_base_module_t* - (*mca_allocator_base_component_init_fn_t)( - bool enable_mpi_threads, - mca_allocator_base_component_segment_alloc_fn_t segment_alloc, - mca_allocator_base_component_segment_free_fn_t segment_free, - void *context -); + * The function used to initialize the component. + */ +typedef struct mca_allocator_base_module_t *(*mca_allocator_base_component_init_fn_t)( + bool enable_mpi_threads, mca_allocator_base_component_segment_alloc_fn_t segment_alloc, + mca_allocator_base_component_segment_free_fn_t segment_free, void *context); /** * The data structure provided by each component to the framework which @@ -144,10 +128,8 @@ typedef struct mca_allocator_base_component_2_0_0_t mca_allocator_base_component /** * Macro for use in components that are of type allocator */ -#define MCA_ALLOCATOR_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("allocator", 2, 0, 0) +#define MCA_ALLOCATOR_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("allocator", 2, 0, 0) END_C_DECLS #endif /* MCA_ALLOCATOR_H */ - diff --git a/opal/mca/allocator/base/allocator_base_frame.c b/opal/mca/allocator/base/allocator_base_frame.c index cf8559af2af..890d315a826 100644 --- a/opal/mca/allocator/base/allocator_base_frame.c +++ b/opal/mca/allocator/base/allocator_base_frame.c @@ -16,15 +16,14 @@ * $HEADER$ */ - #include "opal_config.h" #include #include -#include "opal/mca/mca.h" -#include "opal/mca/base/base.h" #include "opal/mca/allocator/allocator.h" #include "opal/mca/allocator/base/base.h" +#include "opal/mca/base/base.h" +#include "opal/mca/mca.h" /* * The following file was created by configure. It contains extern @@ -49,18 +48,17 @@ MCA_BASE_FRAMEWORK_DECLARE(opal, allocator, NULL, NULL, NULL, NULL, * @retval mca_allocator_base_component_t* pointer to the requested component * @retval NULL if the requested component is not found */ -mca_allocator_base_component_t* mca_allocator_component_lookup(const char* name) +mca_allocator_base_component_t *mca_allocator_component_lookup(const char *name) { /* Traverse the list of available components; call their init functions. */ mca_base_component_list_item_t *cli; - OPAL_LIST_FOREACH(cli, &opal_allocator_base_framework.framework_components, mca_base_component_list_item_t) { - mca_allocator_base_component_t* component = (mca_allocator_base_component_t *) cli->cli_component; - if(strcmp(component->allocator_version.mca_component_name, - name) == 0) { - return component; - } + OPAL_LIST_FOREACH (cli, &opal_allocator_base_framework.framework_components, + mca_base_component_list_item_t) { + mca_allocator_base_component_t *component = (mca_allocator_base_component_t *) + cli->cli_component; + if (strcmp(component->allocator_version.mca_component_name, name) == 0) { + return component; + } } return NULL; } - - diff --git a/opal/mca/allocator/base/base.h b/opal/mca/allocator/base/base.h index 4a75ffd824f..f77f14ae15a 100644 --- a/opal/mca/allocator/base/base.h +++ b/opal/mca/allocator/base/base.h @@ -26,20 +26,20 @@ #include "opal/mca/base/mca_base_framework.h" #include "opal/class/opal_list.h" -#include "opal/mca/mca.h" #include "opal/mca/allocator/allocator.h" +#include "opal/mca/mca.h" BEGIN_C_DECLS /** * Structure which describes a selected module. */ struct mca_allocator_base_selected_module_t { - opal_list_item_t super; - /**< Makes this an object of type opal_list_item */ - mca_allocator_base_component_t *allocator_component; - /**< Info about the module */ - mca_allocator_base_module_t *allocator_module; - /**< The function pointers for all the module's functions. */ + opal_list_item_t super; + /**< Makes this an object of type opal_list_item */ + mca_allocator_base_component_t *allocator_component; + /**< Info about the module */ + mca_allocator_base_module_t *allocator_module; + /**< The function pointers for all the module's functions. */ }; /** * Convenience typedef. @@ -51,9 +51,7 @@ typedef struct mca_allocator_base_selected_module_t mca_allocator_base_selected_ */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_allocator_base_selected_module_t); - -OPAL_DECLSPEC mca_allocator_base_component_t* mca_allocator_component_lookup(const char* name); - +OPAL_DECLSPEC mca_allocator_base_component_t *mca_allocator_component_lookup(const char *name); /* * Globals diff --git a/opal/mca/allocator/basic/allocator_basic.c b/opal/mca/allocator/basic/allocator_basic.c index 53c40ad85f1..ddb4d8193d7 100644 --- a/opal/mca/allocator/basic/allocator_basic.c +++ b/opal/mca/allocator/basic/allocator_basic.c @@ -26,62 +26,45 @@ #include "allocator_basic.h" #include "opal/constants.h" - - mca_allocator_base_component_t mca_allocator_basic_component = { - /* First, the mca_base_module_t struct containing meta information - about the module itself */ - - { - MCA_ALLOCATOR_BASE_VERSION_2_0_0, + /* First, the mca_base_module_t struct containing meta information + about the module itself */ - "basic", /* MCA module name */ - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - mca_allocator_basic_component_open, /* module open */ - mca_allocator_basic_component_close /* module close */ - }, - { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - mca_allocator_basic_component_init -}; + { + MCA_ALLOCATOR_BASE_VERSION_2_0_0, + "basic", /* MCA module name */ + OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + mca_allocator_basic_component_open, /* module open */ + mca_allocator_basic_component_close /* module close */ + }, + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + mca_allocator_basic_component_init}; -OBJ_CLASS_INSTANCE( - mca_allocator_basic_segment_t, - opal_free_list_item_t, - NULL, - NULL); - +OBJ_CLASS_INSTANCE(mca_allocator_basic_segment_t, opal_free_list_item_t, NULL, NULL); int mca_allocator_basic_component_open(void) { return OPAL_SUCCESS; } - int mca_allocator_basic_component_close(void) { return OPAL_SUCCESS; } - /** - * - */ - -mca_allocator_base_module_t* mca_allocator_basic_component_init( - bool enable_mpi_threads, - mca_allocator_base_component_segment_alloc_fn_t segment_alloc, - mca_allocator_base_component_segment_free_fn_t segment_free, - void *context) + * + */ + +mca_allocator_base_module_t *mca_allocator_basic_component_init( + bool enable_mpi_threads, mca_allocator_base_component_segment_alloc_fn_t segment_alloc, + mca_allocator_base_component_segment_free_fn_t segment_free, void *context) { - mca_allocator_basic_module_t *module = (mca_allocator_basic_module_t *) - malloc(sizeof(mca_allocator_basic_module_t)); + mca_allocator_basic_module_t *module = (mca_allocator_basic_module_t *) malloc( + sizeof(mca_allocator_basic_module_t)); if (NULL == module) { return NULL; } @@ -98,76 +81,68 @@ mca_allocator_base_module_t* mca_allocator_basic_component_init( OBJ_CONSTRUCT(&module->seg_lock, opal_mutex_t); OBJ_CONSTRUCT(&module->seg_descriptors, opal_free_list_t); - opal_free_list_init (&module->seg_descriptors, - sizeof(mca_allocator_basic_segment_t), - opal_cache_line_size, - OBJ_CLASS(mca_allocator_basic_segment_t), - 0,opal_cache_line_size, - 0, /* initial size */ - -1, /* maximum size */ - 16, /* increment to grow by */ - NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&module->seg_descriptors, sizeof(mca_allocator_basic_segment_t), + opal_cache_line_size, OBJ_CLASS(mca_allocator_basic_segment_t), 0, + opal_cache_line_size, 0, /* initial size */ + -1, /* maximum size */ + 16, /* increment to grow by */ + NULL, 0, NULL, NULL, NULL); return &module->super; } /** - * Combine adjacent segments together. + * Combine adjacent segments together. */ -static void mca_allocator_basic_combine_prev( - mca_allocator_basic_module_t* module, - mca_allocator_basic_segment_t* seg) +static void mca_allocator_basic_combine_prev(mca_allocator_basic_module_t *module, + mca_allocator_basic_segment_t *seg) { - opal_list_item_t* item = opal_list_get_prev(seg); - if(item != opal_list_get_begin(&module->seg_list)) { - mca_allocator_basic_segment_t *prev = (mca_allocator_basic_segment_t*)item; - if(prev->seg_addr + prev->seg_size == seg->seg_addr) { + opal_list_item_t *item = opal_list_get_prev(seg); + if (item != opal_list_get_begin(&module->seg_list)) { + mca_allocator_basic_segment_t *prev = (mca_allocator_basic_segment_t *) item; + if (prev->seg_addr + prev->seg_size == seg->seg_addr) { prev->seg_size += seg->seg_size; opal_list_remove_item(&module->seg_list, &seg->seg_item.super); - opal_free_list_return (&module->seg_descriptors, &seg->seg_item); + opal_free_list_return(&module->seg_descriptors, &seg->seg_item); return; } } } -static void mca_allocator_basic_combine_next( - mca_allocator_basic_module_t* module, - mca_allocator_basic_segment_t* seg) +static void mca_allocator_basic_combine_next(mca_allocator_basic_module_t *module, + mca_allocator_basic_segment_t *seg) { opal_list_item_t *item = opal_list_get_next(seg); - if(item != opal_list_get_end(&module->seg_list)) { - mca_allocator_basic_segment_t *next = (mca_allocator_basic_segment_t*)item; - if(seg->seg_addr + seg->seg_size == next->seg_addr) { + if (item != opal_list_get_end(&module->seg_list)) { + mca_allocator_basic_segment_t *next = (mca_allocator_basic_segment_t *) item; + if (seg->seg_addr + seg->seg_size == next->seg_addr) { next->seg_addr = seg->seg_addr; next->seg_size += seg->seg_size; opal_list_remove_item(&module->seg_list, &seg->seg_item.super); - opal_free_list_return (&module->seg_descriptors, &seg->seg_item); + opal_free_list_return(&module->seg_descriptors, &seg->seg_item); return; } } } /** - * Accepts a request for memory in a specific region defined by the - * mca_allocator_basic_options_t struct and returns a pointer to memory in that - * region or NULL if there was an error - * - * @param mem A pointer to the appropriate struct for the area of memory. - * @param size The size of the requested area of memory - * - * @retval Pointer to the area of memory if the allocation was successful - * @retval NULL if the allocation was unsuccessful - */ - -void *mca_allocator_basic_alloc( - mca_allocator_base_module_t * base, - size_t size, - size_t align) + * Accepts a request for memory in a specific region defined by the + * mca_allocator_basic_options_t struct and returns a pointer to memory in that + * region or NULL if there was an error + * + * @param mem A pointer to the appropriate struct for the area of memory. + * @param size The size of the requested area of memory + * + * @retval Pointer to the area of memory if the allocation was successful + * @retval NULL if the allocation was unsuccessful + */ + +void *mca_allocator_basic_alloc(mca_allocator_base_module_t *base, size_t size, size_t align) { - mca_allocator_basic_module_t* module = (mca_allocator_basic_module_t*)base; - mca_allocator_basic_segment_t* seg; - unsigned char* addr; + mca_allocator_basic_module_t *module = (mca_allocator_basic_module_t *) base; + mca_allocator_basic_segment_t *seg; + unsigned char *addr; size_t allocated_size; OPAL_THREAD_LOCK(&module->seg_lock); @@ -176,109 +151,106 @@ void *mca_allocator_basic_alloc( /* normalize size so we don't end up with seg_addr on an odd boundary */ size += sizeof(size_t) - (size & (sizeof(size_t) - 1)); /* search the list for a segment of the required size */ - OPAL_LIST_FOREACH(seg, &module->seg_list, mca_allocator_basic_segment_t) { + OPAL_LIST_FOREACH (seg, &module->seg_list, mca_allocator_basic_segment_t) { /* split the segment */ - if(seg->seg_size > size) { + if (seg->seg_size > size) { addr = seg->seg_addr; seg->seg_addr += size; seg->seg_size -= size; OPAL_THREAD_UNLOCK(&module->seg_lock); - *(size_t*)addr = size; - return addr+sizeof(size_t); + *(size_t *) addr = size; + return addr + sizeof(size_t); } else if (seg->seg_size == size) { addr = seg->seg_addr; opal_list_remove_item(&module->seg_list, (opal_list_item_t *) seg); - opal_free_list_return (&module->seg_descriptors, (opal_free_list_item_t *) seg); + opal_free_list_return(&module->seg_descriptors, (opal_free_list_item_t *) seg); OPAL_THREAD_UNLOCK(&module->seg_lock); - *(size_t*)addr = size; - return addr+sizeof(size_t); + *(size_t *) addr = size; + return addr + sizeof(size_t); } } /* request additional block */ allocated_size = size; - if(NULL == (addr = (unsigned char *)module->seg_alloc(module->super.alc_context, &allocated_size))) { + if (NULL + == (addr = (unsigned char *) module->seg_alloc(module->super.alc_context, + &allocated_size))) { OPAL_THREAD_UNLOCK(&module->seg_lock); return NULL; } /* create a segment for any extra allocation */ - if(allocated_size > size) { - seg = (mca_allocator_basic_segment_t *) opal_free_list_get (&module->seg_descriptors); + if (allocated_size > size) { + seg = (mca_allocator_basic_segment_t *) opal_free_list_get(&module->seg_descriptors); if (NULL == seg) { OPAL_THREAD_UNLOCK(&module->seg_lock); return NULL; } seg->seg_addr = addr + size; seg->seg_size = allocated_size - size; - opal_list_append (&module->seg_list, (opal_list_item_t *) seg); + opal_list_append(&module->seg_list, (opal_list_item_t *) seg); } - *(size_t*)addr = size; + *(size_t *) addr = size; OPAL_THREAD_UNLOCK(&module->seg_lock); - return addr+sizeof(size_t); + return addr + sizeof(size_t); } - /** - * Attempts to resize the passed region of memory into a larger or a smaller - * region. If it is unsuccessful, it will return NULL and the passed area of - * memory will be untouched. - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param size The size of the requested area of memory - * @param ptr A pointer to the region of memory to be resized - * - * @retval Pointer to the area of memory if the reallocation was successful - * @retval NULL if the allocation was unsuccessful - * - */ - -void * mca_allocator_basic_realloc( - mca_allocator_base_module_t * base, - void * ptr, - size_t size) + * Attempts to resize the passed region of memory into a larger or a smaller + * region. If it is unsuccessful, it will return NULL and the passed area of + * memory will be untouched. + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param size The size of the requested area of memory + * @param ptr A pointer to the region of memory to be resized + * + * @retval Pointer to the area of memory if the reallocation was successful + * @retval NULL if the allocation was unsuccessful + * + */ + +void *mca_allocator_basic_realloc(mca_allocator_base_module_t *base, void *ptr, size_t size) { - unsigned char* addr = ((unsigned char*)ptr) - sizeof(size_t); - size_t alloc_size = *(size_t*)addr; - if(size <= alloc_size) + unsigned char *addr = ((unsigned char *) ptr) - sizeof(size_t); + size_t alloc_size = *(size_t *) addr; + if (size <= alloc_size) { return ptr; - addr = (unsigned char *)mca_allocator_basic_alloc(base, size, 0); - if(addr == NULL) + } + addr = (unsigned char *) mca_allocator_basic_alloc(base, size, 0); + if (addr == NULL) { return addr; - memcpy(addr,ptr,alloc_size); - mca_allocator_basic_free(base,ptr); + } + memcpy(addr, ptr, alloc_size); + mca_allocator_basic_free(base, ptr); return addr; } - /** - * Frees the passed region of memory - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param ptr A pointer to the region of memory to be freed - * - * @retval None - * - */ -void mca_allocator_basic_free( - mca_allocator_base_module_t * base, - void * ptr) + * Frees the passed region of memory + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param ptr A pointer to the region of memory to be freed + * + * @retval None + * + */ +void mca_allocator_basic_free(mca_allocator_base_module_t *base, void *ptr) { - mca_allocator_basic_module_t* module = (mca_allocator_basic_module_t*)base; - mca_allocator_basic_segment_t* seg; - unsigned char* addr = (unsigned char*)ptr - sizeof(size_t); - size_t size = *(size_t*)addr; + mca_allocator_basic_module_t *module = (mca_allocator_basic_module_t *) base; + mca_allocator_basic_segment_t *seg; + unsigned char *addr = (unsigned char *) ptr - sizeof(size_t); + size_t size = *(size_t *) addr; OPAL_THREAD_LOCK(&module->seg_lock); /* maintain the free list in sorted order by address */ - OPAL_LIST_FOREACH(seg, &module->seg_list, mca_allocator_basic_segment_t) { + OPAL_LIST_FOREACH (seg, &module->seg_list, mca_allocator_basic_segment_t) { if (seg->seg_addr < addr) { /* can we grow the current entry */ - if(seg->seg_addr + seg->seg_size == addr) { + if (seg->seg_addr + seg->seg_size == addr) { seg->seg_size += size; mca_allocator_basic_combine_next(module, seg); OPAL_THREAD_UNLOCK(&module->seg_lock); @@ -286,28 +258,29 @@ void mca_allocator_basic_free( } /* otherwise continue to check next larger entry */ - } else { + } else { /* can this be combined with current entry */ - if(addr + size == seg->seg_addr) { + if (addr + size == seg->seg_addr) { seg->seg_addr = addr; seg->seg_size += size; mca_allocator_basic_combine_prev(module, seg); OPAL_THREAD_UNLOCK(&module->seg_lock); return; - /* insert before larger entry */ + /* insert before larger entry */ } else { - mca_allocator_basic_segment_t* new_seg; - new_seg = (mca_allocator_basic_segment_t *) - opal_free_list_get (&module->seg_descriptors); - if(NULL == new_seg) { + mca_allocator_basic_segment_t *new_seg; + new_seg = (mca_allocator_basic_segment_t *) opal_free_list_get( + &module->seg_descriptors); + if (NULL == new_seg) { OPAL_THREAD_UNLOCK(&module->seg_lock); return; } new_seg->seg_addr = addr; new_seg->seg_size = size; - opal_list_insert_pos(&module->seg_list, &seg->seg_item.super, (opal_list_item_t *) new_seg); + opal_list_insert_pos(&module->seg_list, &seg->seg_item.super, + (opal_list_item_t *) new_seg); OPAL_THREAD_UNLOCK(&module->seg_lock); return; } @@ -315,8 +288,8 @@ void mca_allocator_basic_free( } /* append to the end of the list */ - seg = (mca_allocator_basic_segment_t *) opal_free_list_get (&module->seg_descriptors); - if(NULL == seg) { + seg = (mca_allocator_basic_segment_t *) opal_free_list_get(&module->seg_descriptors); + if (NULL == seg) { OPAL_THREAD_UNLOCK(&module->seg_lock); return; } @@ -326,40 +299,39 @@ void mca_allocator_basic_free( OPAL_THREAD_UNLOCK(&module->seg_lock); } - /** - * Frees all the memory from all the basics back to the system. Note that - * this function only frees memory that was previously freed with - * mca_allocator_basic_free(). - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * - * @retval None - * - */ - -int mca_allocator_basic_compact(mca_allocator_base_module_t * mem) + * Frees all the memory from all the basics back to the system. Note that + * this function only frees memory that was previously freed with + * mca_allocator_basic_free(). + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * + * @retval None + * + */ + +int mca_allocator_basic_compact(mca_allocator_base_module_t *mem) { return OPAL_SUCCESS; } /** - * Cleanup all resources held by this allocator. - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * - * @retval None - * - */ - -int mca_allocator_basic_finalize(mca_allocator_base_module_t * base) + * Cleanup all resources held by this allocator. + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * + * @retval None + * + */ + +int mca_allocator_basic_finalize(mca_allocator_base_module_t *base) { - mca_allocator_basic_module_t* module = (mca_allocator_basic_module_t*)base; + mca_allocator_basic_module_t *module = (mca_allocator_basic_module_t *) base; // clear the list as we don't own these bits while (NULL != opal_list_remove_first(&module->seg_list)) { - continue; + continue; } OBJ_DESTRUCT(&module->seg_list); OBJ_DESTRUCT(&module->seg_lock); @@ -367,5 +339,3 @@ int mca_allocator_basic_finalize(mca_allocator_base_module_t * base) free(module); return OPAL_SUCCESS; } - - diff --git a/opal/mca/allocator/basic/allocator_basic.h b/opal/mca/allocator/basic/allocator_basic.h index 4766a994c8d..feb041b0803 100644 --- a/opal/mca/allocator/basic/allocator_basic.h +++ b/opal/mca/allocator/basic/allocator_basic.h @@ -27,12 +27,11 @@ #define ALLOCATOR_BASIC_H #include "opal_config.h" -#include -#include -#include "opal/mca/threads/mutex.h" #include "opal/class/opal_free_list.h" #include "opal/mca/allocator/allocator.h" - +#include "opal/mca/threads/mutex.h" +#include +#include /* * Free list of allocated segments @@ -40,12 +39,11 @@ struct mca_allocator_basic_segment_t { opal_free_list_item_t seg_item; - unsigned char* seg_addr; + unsigned char *seg_addr; size_t seg_size; }; typedef struct mca_allocator_basic_segment_t mca_allocator_basic_segment_t; - /* * Basic allocator module */ @@ -60,7 +58,6 @@ struct mca_allocator_basic_module_t { }; typedef struct mca_allocator_basic_module_t mca_allocator_basic_module_t; - BEGIN_C_DECLS /* @@ -71,99 +68,79 @@ int mca_allocator_basic_component_open(void); int mca_allocator_basic_component_close(void); /** - * The function used to initialize the component. - */ -mca_allocator_base_module_t* mca_allocator_basic_component_init( - bool enable_mpi_threads, - mca_allocator_base_component_segment_alloc_fn_t segment_alloc, - mca_allocator_base_component_segment_free_fn_t segment_free, - void *ctx -); + * The function used to initialize the component. + */ +mca_allocator_base_module_t *mca_allocator_basic_component_init( + bool enable_mpi_threads, mca_allocator_base_component_segment_alloc_fn_t segment_alloc, + mca_allocator_base_component_segment_free_fn_t segment_free, void *ctx); /** - * Accepts a request for memory in a specific region defined by the - * mca_allocator_basic_options_t struct and returns a pointer to memory in that - * region or NULL if there was an error - * - * @param mem A pointer to the appropriate struct for the area of memory. - * @param size The size of the requested area of memory - * - * @retval Pointer to the area of memory if the allocation was successful - * @retval NULL if the allocation was unsuccessful - */ - void * mca_allocator_basic_alloc( - mca_allocator_base_module_t * mem, - size_t size, - size_t align); + * Accepts a request for memory in a specific region defined by the + * mca_allocator_basic_options_t struct and returns a pointer to memory in that + * region or NULL if there was an error + * + * @param mem A pointer to the appropriate struct for the area of memory. + * @param size The size of the requested area of memory + * + * @retval Pointer to the area of memory if the allocation was successful + * @retval NULL if the allocation was unsuccessful + */ +void *mca_allocator_basic_alloc(mca_allocator_base_module_t *mem, size_t size, size_t align); /** - * Attempts to resize the passed region of memory into a larger or a smaller - * region. If it is unsuccessful, it will return NULL and the passed area of - * memory will be untouched. - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param size The size of the requested area of memory - * @param ptr A pointer to the region of memory to be resized - * - * @retval Pointer to the area of memory if the reallocation was successful - * @retval NULL if the allocation was unsuccessful - * - */ - void * mca_allocator_basic_realloc( - mca_allocator_base_module_t * mem, - void * ptr, - size_t size); + * Attempts to resize the passed region of memory into a larger or a smaller + * region. If it is unsuccessful, it will return NULL and the passed area of + * memory will be untouched. + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param size The size of the requested area of memory + * @param ptr A pointer to the region of memory to be resized + * + * @retval Pointer to the area of memory if the reallocation was successful + * @retval NULL if the allocation was unsuccessful + * + */ +void *mca_allocator_basic_realloc(mca_allocator_base_module_t *mem, void *ptr, size_t size); /** - * Frees the passed region of memory - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param ptr A pointer to the region of memory to be freed - * - * @retval None - * - */ - void mca_allocator_basic_free( - mca_allocator_base_module_t * mem, - void * ptr); + * Frees the passed region of memory + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param ptr A pointer to the region of memory to be freed + * + * @retval None + * + */ +void mca_allocator_basic_free(mca_allocator_base_module_t *mem, void *ptr); /** - * Frees all the memory from all the basics back to the system. Note that - * this function only frees memory that was previously freed with - * mca_allocator_basic_free(). - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * - * @retval None - * - */ - int mca_allocator_basic_compact( - mca_allocator_base_module_t * mem); + * Frees all the memory from all the basics back to the system. Note that + * this function only frees memory that was previously freed with + * mca_allocator_basic_free(). + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * + * @retval None + * + */ +int mca_allocator_basic_compact(mca_allocator_base_module_t *mem); /** - * Cleanup all resources held by this allocator. - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * - * @retval None - * - */ - int mca_allocator_basic_finalize( - mca_allocator_base_module_t * mem); + * Cleanup all resources held by this allocator. + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * + * @retval None + * + */ +int mca_allocator_basic_finalize(mca_allocator_base_module_t *mem); OPAL_DECLSPEC extern mca_allocator_base_component_t mca_allocator_basic_component; END_C_DECLS #endif /* ALLOCATOR_BUCKET_ALLOC_H */ - - - - - - - diff --git a/opal/mca/allocator/bucket/allocator_bucket.c b/opal/mca/allocator/bucket/allocator_bucket.c index e57b1648cb7..2a9119bc0c5 100644 --- a/opal/mca/allocator/bucket/allocator_bucket.c +++ b/opal/mca/allocator/bucket/allocator_bucket.c @@ -21,75 +21,67 @@ */ #include "opal_config.h" -#include "opal/mca/allocator/allocator.h" #include "opal/constants.h" +#include "opal/mca/allocator/allocator.h" #include "opal/mca/allocator/bucket/allocator_bucket_alloc.h" #include "opal/mca/base/mca_base_var.h" -struct mca_allocator_base_module_t* mca_allocator_bucket_module_init( - bool enable_mpi_threads, - mca_allocator_base_component_segment_alloc_fn_t segment_alloc, - mca_allocator_base_component_segment_free_fn_t segment_free, - void *context); +struct mca_allocator_base_module_t *mca_allocator_bucket_module_init( + bool enable_mpi_threads, mca_allocator_base_component_segment_alloc_fn_t segment_alloc, + mca_allocator_base_component_segment_free_fn_t segment_free, void *context); int mca_allocator_bucket_module_open(void); int mca_allocator_bucket_module_close(void); -void * mca_allocator_bucket_alloc_wrapper( - struct mca_allocator_base_module_t* allocator, - size_t size, size_t align); +void *mca_allocator_bucket_alloc_wrapper(struct mca_allocator_base_module_t *allocator, size_t size, + size_t align); static int mca_allocator_num_buckets; - - -int mca_allocator_bucket_finalize(struct mca_allocator_base_module_t* allocator) +int mca_allocator_bucket_finalize(struct mca_allocator_base_module_t *allocator) { mca_allocator_bucket_t *bucket = (mca_allocator_bucket_t *) allocator; mca_allocator_bucket_cleanup(allocator); - for (int i = 0 ; i < bucket->num_buckets ; ++i) { + for (int i = 0; i < bucket->num_buckets; ++i) { OBJ_DESTRUCT(&bucket->buckets[i].lock); } - free (bucket->buckets); + free(bucket->buckets); free(allocator); - return(OPAL_SUCCESS); + return (OPAL_SUCCESS); } -struct mca_allocator_base_module_t* mca_allocator_bucket_module_init( - bool enable_mpi_threads, - mca_allocator_base_component_segment_alloc_fn_t segment_alloc, - mca_allocator_base_component_segment_free_fn_t segment_free, - void *context) +struct mca_allocator_base_module_t *mca_allocator_bucket_module_init( + bool enable_mpi_threads, mca_allocator_base_component_segment_alloc_fn_t segment_alloc, + mca_allocator_base_component_segment_free_fn_t segment_free, void *context) { size_t alloc_size = sizeof(mca_allocator_bucket_t); - mca_allocator_bucket_t * retval; - mca_allocator_bucket_t * allocator = (mca_allocator_bucket_t *) malloc(alloc_size); - if(NULL == allocator) { + mca_allocator_bucket_t *retval; + mca_allocator_bucket_t *allocator = (mca_allocator_bucket_t *) malloc(alloc_size); + if (NULL == allocator) { return NULL; } retval = mca_allocator_bucket_init((mca_allocator_base_module_t *) allocator, - mca_allocator_num_buckets, - segment_alloc, - segment_free); - if(NULL == retval) { + mca_allocator_num_buckets, segment_alloc, segment_free); + if (NULL == retval) { free(allocator); return NULL; } - allocator->super.alc_alloc = mca_allocator_bucket_alloc_wrapper; + allocator->super.alc_alloc = mca_allocator_bucket_alloc_wrapper; allocator->super.alc_realloc = mca_allocator_bucket_realloc; - allocator->super.alc_free = mca_allocator_bucket_free; + allocator->super.alc_free = mca_allocator_bucket_free; allocator->super.alc_compact = mca_allocator_bucket_cleanup; allocator->super.alc_finalize = mca_allocator_bucket_finalize; allocator->super.alc_context = context; return (mca_allocator_base_module_t *) allocator; } -static int mca_allocator_bucket_module_register(void) { +static int mca_allocator_bucket_module_register(void) +{ mca_allocator_num_buckets = 30; (void) mca_base_component_var_register(&mca_allocator_bucket_component.allocator_version, "num_buckets", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, @@ -98,47 +90,37 @@ static int mca_allocator_bucket_module_register(void) { return OPAL_SUCCESS; } -int mca_allocator_bucket_module_open(void) { +int mca_allocator_bucket_module_open(void) +{ return OPAL_SUCCESS; } -int mca_allocator_bucket_module_close(void) { +int mca_allocator_bucket_module_close(void) +{ return OPAL_SUCCESS; } -void * mca_allocator_bucket_alloc_wrapper( - struct mca_allocator_base_module_t* allocator, - size_t size, - size_t align) +void *mca_allocator_bucket_alloc_wrapper(struct mca_allocator_base_module_t *allocator, size_t size, + size_t align) { - if(0 == align){ + if (0 == align) { return mca_allocator_bucket_alloc(allocator, size); } return mca_allocator_bucket_alloc_align(allocator, size, align); } - mca_allocator_base_component_t mca_allocator_bucket_component = { - /* First, the mca_base_module_t struct containing meta information - about the module itself */ - - { - MCA_ALLOCATOR_BASE_VERSION_2_0_0, - - "bucket", /* MCA module name */ - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - mca_allocator_bucket_module_open, /* module open */ - mca_allocator_bucket_module_close, /* module close */ - NULL, - mca_allocator_bucket_module_register - }, - { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - mca_allocator_bucket_module_init -}; + /* First, the mca_base_module_t struct containing meta information + about the module itself */ + + {MCA_ALLOCATOR_BASE_VERSION_2_0_0, + "bucket", /* MCA module name */ + OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + mca_allocator_bucket_module_open, /* module open */ + mca_allocator_bucket_module_close, /* module close */ + NULL, mca_allocator_bucket_module_register}, + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + mca_allocator_bucket_module_init}; diff --git a/opal/mca/allocator/bucket/allocator_bucket_alloc.c b/opal/mca/allocator/bucket/allocator_bucket_alloc.c index be3db944d06..ab2da50a33e 100644 --- a/opal/mca/allocator/bucket/allocator_bucket_alloc.c +++ b/opal/mca/allocator/bucket/allocator_bucket_alloc.c @@ -18,43 +18,42 @@ */ #include "opal_config.h" -#include "opal/constants.h" #include "opal/mca/allocator/bucket/allocator_bucket_alloc.h" +#include "opal/constants.h" /** - * The define controls the size in bytes of the 1st bucket and hence every one - * afterwards. - */ + * The define controls the size in bytes of the 1st bucket and hence every one + * afterwards. + */ #define MCA_ALLOCATOR_BUCKET_1_SIZE 8 /** - * This is the number of left bit shifts from 1 needed to get to the number of - * bytes in the initial memory buckets - */ + * This is the number of left bit shifts from 1 needed to get to the number of + * bytes in the initial memory buckets + */ #define MCA_ALLOCATOR_BUCKET_1_BITSHIFTS 3 - /* - * Initializes the mca_allocator_bucket_options_t data structure for the passed - * parameters. - */ -mca_allocator_bucket_t * mca_allocator_bucket_init( - mca_allocator_base_module_t * mem, - int num_buckets, - mca_allocator_base_component_segment_alloc_fn_t get_mem_funct, - mca_allocator_base_component_segment_free_fn_t free_mem_funct) +/* + * Initializes the mca_allocator_bucket_options_t data structure for the passed + * parameters. + */ +mca_allocator_bucket_t * +mca_allocator_bucket_init(mca_allocator_base_module_t *mem, int num_buckets, + mca_allocator_base_component_segment_alloc_fn_t get_mem_funct, + mca_allocator_base_component_segment_free_fn_t free_mem_funct) { - mca_allocator_bucket_t * mem_options = (mca_allocator_bucket_t *) mem; + mca_allocator_bucket_t *mem_options = (mca_allocator_bucket_t *) mem; int i; size_t size; /* if a bad value is used for the number of buckets, default to 30 */ - if(num_buckets <= 0) { + if (num_buckets <= 0) { num_buckets = 30; } /* initialize the array of buckets */ size = sizeof(mca_allocator_bucket_bucket_t) * num_buckets; - mem_options->buckets = (mca_allocator_bucket_bucket_t*) malloc(size); - if(NULL == mem_options->buckets) { - return(NULL); + mem_options->buckets = (mca_allocator_bucket_bucket_t *) malloc(size); + if (NULL == mem_options->buckets) { + return (NULL); } - for(i = 0; i < num_buckets; i++) { + for (i = 0; i < num_buckets; i++) { mem_options->buckets[i].free_chunk = NULL; mem_options->buckets[i].segment_head = NULL; OBJ_CONSTRUCT(&(mem_options->buckets[i].lock), opal_mutex_t); @@ -62,31 +61,30 @@ mca_allocator_bucket_t * mca_allocator_bucket_init( mem_options->num_buckets = num_buckets; mem_options->get_mem_fn = get_mem_funct; mem_options->free_mem_fn = free_mem_funct; - return(mem_options); + return (mem_options); } /* - * Accepts a request for memory in a specific region defined by the - * mca_allocator_bucket_options_t struct and returns a pointer to memory in that - * region or NULL if there was an error - * - */ -void * mca_allocator_bucket_alloc(mca_allocator_base_module_t * mem, - size_t size) + * Accepts a request for memory in a specific region defined by the + * mca_allocator_bucket_options_t struct and returns a pointer to memory in that + * region or NULL if there was an error + * + */ +void *mca_allocator_bucket_alloc(mca_allocator_base_module_t *mem, size_t size) { - mca_allocator_bucket_t * mem_options = (mca_allocator_bucket_t *) mem; + mca_allocator_bucket_t *mem_options = (mca_allocator_bucket_t *) mem; /* initialize for the later bit shifts */ int bucket_num = 0; size_t bucket_size = MCA_ALLOCATOR_BUCKET_1_SIZE; size_t allocated_size; - mca_allocator_bucket_chunk_header_t * chunk; - mca_allocator_bucket_chunk_header_t * first_chunk; - mca_allocator_bucket_segment_head_t * segment_header; + mca_allocator_bucket_chunk_header_t *chunk; + mca_allocator_bucket_chunk_header_t *first_chunk; + mca_allocator_bucket_segment_head_t *segment_header; /* add the size of the header into the amount we need to request */ size += sizeof(mca_allocator_bucket_chunk_header_t); /* figure out which bucket it will come from. */ - while(size > bucket_size) { + while (size > bucket_size) { bucket_num++; bucket_size <<= 1; } @@ -94,7 +92,7 @@ void * mca_allocator_bucket_alloc(mca_allocator_base_module_t * mem, /* now that we know what bucket it will come from, we must get the lock */ OPAL_THREAD_LOCK(&(mem_options->buckets[bucket_num].lock)); /* see if there is already a free chunk */ - if(NULL != mem_options->buckets[bucket_num].free_chunk) { + if (NULL != mem_options->buckets[bucket_num].free_chunk) { chunk = mem_options->buckets[bucket_num].free_chunk; mem_options->buckets[bucket_num].free_chunk = chunk->u.next_free; chunk->u.bucket = bucket_num; @@ -102,7 +100,7 @@ void * mca_allocator_bucket_alloc(mca_allocator_base_module_t * mem, chunk += 1; /*release the lock */ OPAL_THREAD_UNLOCK(&(mem_options->buckets[bucket_num].lock)); - return((void *) chunk); + return ((void *) chunk); } /* figure out the size of bucket we need */ allocated_size = bucket_size; @@ -111,29 +109,29 @@ void * mca_allocator_bucket_alloc(mca_allocator_base_module_t * mem, allocated_size += sizeof(mca_allocator_bucket_segment_head_t); /* attempt to get the memory */ segment_header = (mca_allocator_bucket_segment_head_t *) - mem_options->get_mem_fn(mem_options->super.alc_context, &allocated_size); - if(NULL == segment_header) { + mem_options->get_mem_fn(mem_options->super.alc_context, &allocated_size); + if (NULL == segment_header) { /* release the lock */ OPAL_THREAD_UNLOCK(&(mem_options->buckets[bucket_num].lock)); - return(NULL); + return (NULL); } /* if were allocated more memory then we actually need, then we will try to * break it up into multiple chunks in the current bucket */ allocated_size -= (sizeof(mca_allocator_bucket_segment_head_t) + bucket_size); - chunk = first_chunk = segment_header->first_chunk = - (mca_allocator_bucket_chunk_header_t *) (segment_header + 1); + chunk = first_chunk = segment_header->first_chunk = (mca_allocator_bucket_chunk_header_t + *) (segment_header + 1); /* add the segment into the segment list */ segment_header->next_segment = mem_options->buckets[bucket_num].segment_head; mem_options->buckets[bucket_num].segment_head = segment_header; - if(allocated_size >= bucket_size) { - mem_options->buckets[bucket_num].free_chunk = - (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + bucket_size); - chunk->next_in_segment = (mca_allocator_bucket_chunk_header_t *) - ((char *)chunk + bucket_size); - while(allocated_size >= bucket_size) { + if (allocated_size >= bucket_size) { + mem_options->buckets[bucket_num].free_chunk = (mca_allocator_bucket_chunk_header_t + *) ((char *) chunk + bucket_size); + chunk->next_in_segment = (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + + bucket_size); + while (allocated_size >= bucket_size) { chunk = (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + bucket_size); - chunk->u.next_free = (mca_allocator_bucket_chunk_header_t *) - ((char *) chunk + bucket_size); + chunk->u.next_free = (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + + bucket_size); chunk->next_in_segment = chunk->u.next_free; allocated_size -= bucket_size; } @@ -145,24 +143,24 @@ void * mca_allocator_bucket_alloc(mca_allocator_base_module_t * mem, first_chunk->u.bucket = bucket_num; OPAL_THREAD_UNLOCK(&(mem_options->buckets[bucket_num].lock)); /* return the memory moved past the header */ - return((void *) (first_chunk + 1)); + return ((void *) (first_chunk + 1)); } /* - * allocates an aligned region of memory - */ -void * mca_allocator_bucket_alloc_align(mca_allocator_base_module_t * mem, - size_t size, size_t alignment) + * allocates an aligned region of memory + */ +void *mca_allocator_bucket_alloc_align(mca_allocator_base_module_t *mem, size_t size, + size_t alignment) { - mca_allocator_bucket_t * mem_options = (mca_allocator_bucket_t *) mem; + mca_allocator_bucket_t *mem_options = (mca_allocator_bucket_t *) mem; int bucket_num = 1; - void * ptr; + void *ptr; size_t aligned_max_size, bucket_size; size_t alignment_off, allocated_size; - mca_allocator_bucket_chunk_header_t * chunk; - mca_allocator_bucket_chunk_header_t * first_chunk; - mca_allocator_bucket_segment_head_t * segment_header; - char * aligned_memory; + mca_allocator_bucket_chunk_header_t *chunk; + mca_allocator_bucket_chunk_header_t *first_chunk; + mca_allocator_bucket_segment_head_t *segment_header; + char *aligned_memory; /* since we do not have a way to get pre aligned memory, we need to request * a chunk then return an aligned spot in it. In the worst case we need @@ -173,8 +171,8 @@ void * mca_allocator_bucket_alloc_align(mca_allocator_base_module_t * mem, allocated_size = aligned_max_size; /* get some memory */ ptr = mem_options->get_mem_fn(mem_options->super.alc_context, &allocated_size); - if(NULL == ptr) { - return(NULL); + if (NULL == ptr) { + return (NULL); } /* the first part of the memory is the segment header */ segment_header = (mca_allocator_bucket_segment_head_t *) ptr; @@ -184,12 +182,12 @@ void * mca_allocator_bucket_alloc_align(mca_allocator_base_module_t * mem, /* we want to align the memory right after the header, so we go past the header */ aligned_memory = (char *) (first_chunk + 1); /* figure out how much the alignment is off by */ - alignment_off = ((size_t) aligned_memory) % alignment; + alignment_off = ((size_t) aligned_memory) % alignment; aligned_memory += (alignment - alignment_off); /* we now have an aligned piece of memory. Now we have to put the chunk * header right before the aligned memory */ first_chunk = (mca_allocator_bucket_chunk_header_t *) aligned_memory - 1; - while(bucket_size > MCA_ALLOCATOR_BUCKET_1_SIZE) { + while (bucket_size > MCA_ALLOCATOR_BUCKET_1_SIZE) { bucket_size >>= 1; bucket_num++; } @@ -205,15 +203,15 @@ void * mca_allocator_bucket_alloc_align(mca_allocator_base_module_t * mem, /* add the segment into the segment list */ segment_header->next_segment = mem_options->buckets[bucket_num].segment_head; mem_options->buckets[bucket_num].segment_head = segment_header; - if(allocated_size >= bucket_size) { - mem_options->buckets[bucket_num].free_chunk = - (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + bucket_size); - chunk->next_in_segment = (mca_allocator_bucket_chunk_header_t *) - ((char *)chunk + bucket_size); - while(allocated_size >= bucket_size) { + if (allocated_size >= bucket_size) { + mem_options->buckets[bucket_num].free_chunk = (mca_allocator_bucket_chunk_header_t + *) ((char *) chunk + bucket_size); + chunk->next_in_segment = (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + + bucket_size); + while (allocated_size >= bucket_size) { chunk = (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + bucket_size); - chunk->u.next_free = (mca_allocator_bucket_chunk_header_t *) - ((char *) chunk + bucket_size); + chunk->u.next_free = (mca_allocator_bucket_chunk_header_t *) ((char *) chunk + + bucket_size); chunk->next_in_segment = chunk->u.next_free; allocated_size -= bucket_size; } @@ -225,22 +223,21 @@ void * mca_allocator_bucket_alloc_align(mca_allocator_base_module_t * mem, first_chunk->u.bucket = bucket_num; OPAL_THREAD_UNLOCK(&(mem_options->buckets[bucket_num].lock)); /* return the aligned memory */ - return((void *) (aligned_memory)); + return ((void *) (aligned_memory)); } /* - * function to reallocate the segment of memory - */ -void * mca_allocator_bucket_realloc(mca_allocator_base_module_t * mem, - void * ptr, size_t size) + * function to reallocate the segment of memory + */ +void *mca_allocator_bucket_realloc(mca_allocator_base_module_t *mem, void *ptr, size_t size) { - mca_allocator_bucket_t * mem_options = (mca_allocator_bucket_t *) mem; + mca_allocator_bucket_t *mem_options = (mca_allocator_bucket_t *) mem; /* initialize for later bit shifts */ size_t bucket_size = 1; int bucket_num; - void * ret_ptr; + void *ret_ptr; /* get the header of the chunk */ - mca_allocator_bucket_chunk_header_t * chunk = (mca_allocator_bucket_chunk_header_t *) ptr - 1; + mca_allocator_bucket_chunk_header_t *chunk = (mca_allocator_bucket_chunk_header_t *) ptr - 1; bucket_num = chunk->u.bucket; bucket_size <<= (bucket_num + MCA_ALLOCATOR_BUCKET_1_BITSHIFTS); @@ -249,31 +246,30 @@ void * mca_allocator_bucket_realloc(mca_allocator_base_module_t * mem, bucket_size -= sizeof(mca_allocator_bucket_chunk_header_t); /* if the requested size is less than or equal to what they ask for, * just give them back what they passed in */ - if(size <= bucket_size) { - return(ptr); + if (size <= bucket_size) { + return (ptr); } /* we need a new space in memory, so let's get it */ ret_ptr = mca_allocator_bucket_alloc((mca_allocator_base_module_t *) mem_options, size); - if(NULL == ret_ptr) { + if (NULL == ret_ptr) { /* we were unable to get a larger area of memory */ - return(NULL); + return (NULL); } /* copy what they have in memory to the new spot */ memcpy(ret_ptr, ptr, bucket_size); /* free the old area in memory */ mca_allocator_bucket_free((mca_allocator_base_module_t *) mem_options, ptr); - return(ret_ptr); + return (ret_ptr); } - /* - * Frees the passed region of memory - * - */ -void mca_allocator_bucket_free(mca_allocator_base_module_t * mem, void * ptr) + * Frees the passed region of memory + * + */ +void mca_allocator_bucket_free(mca_allocator_base_module_t *mem, void *ptr) { - mca_allocator_bucket_t * mem_options = (mca_allocator_bucket_t *) mem; - mca_allocator_bucket_chunk_header_t * chunk = (mca_allocator_bucket_chunk_header_t *) ptr - 1; + mca_allocator_bucket_t *mem_options = (mca_allocator_bucket_t *) mem; + mca_allocator_bucket_chunk_header_t *chunk = (mca_allocator_bucket_chunk_header_t *) ptr - 1; int bucket_num = chunk->u.bucket; OPAL_THREAD_LOCK(&(mem_options->buckets[bucket_num].lock)); chunk->u.next_free = mem_options->buckets[bucket_num].free_chunk; @@ -282,26 +278,26 @@ void mca_allocator_bucket_free(mca_allocator_base_module_t * mem, void * ptr) } /* - * Frees all the memory from all the buckets back to the system. Note that - * this function only frees memory that was previously freed with - * mca_allocator_bucket_free(). - * - */ -int mca_allocator_bucket_cleanup(mca_allocator_base_module_t * mem) + * Frees all the memory from all the buckets back to the system. Note that + * this function only frees memory that was previously freed with + * mca_allocator_bucket_free(). + * + */ +int mca_allocator_bucket_cleanup(mca_allocator_base_module_t *mem) { - mca_allocator_bucket_t * mem_options = (mca_allocator_bucket_t *) mem; + mca_allocator_bucket_t *mem_options = (mca_allocator_bucket_t *) mem; int i; - mca_allocator_bucket_chunk_header_t * next_chunk; - mca_allocator_bucket_chunk_header_t * chunk; - mca_allocator_bucket_chunk_header_t * first_chunk; - mca_allocator_bucket_segment_head_t ** segment_header; - mca_allocator_bucket_segment_head_t * segment; + mca_allocator_bucket_chunk_header_t *next_chunk; + mca_allocator_bucket_chunk_header_t *chunk; + mca_allocator_bucket_chunk_header_t *first_chunk; + mca_allocator_bucket_segment_head_t **segment_header; + mca_allocator_bucket_segment_head_t *segment; bool empty = true; - for(i = 0; i < mem_options->num_buckets; i++) { + for (i = 0; i < mem_options->num_buckets; i++) { OPAL_THREAD_LOCK(&(mem_options->buckets[i].lock)); segment_header = &(mem_options->buckets[i].segment_head); - if( NULL == (*segment_header) ) { + if (NULL == (*segment_header)) { OPAL_THREAD_UNLOCK(&(mem_options->buckets[i].lock)); continue; } @@ -312,65 +308,67 @@ int mca_allocator_bucket_cleanup(mca_allocator_base_module_t * mem) */ empty = true; segment = mem_options->buckets[i].segment_head; - while( (true == empty) && (NULL != segment) ) { + while ((true == empty) && (NULL != segment)) { first_chunk = segment->first_chunk; chunk = first_chunk; /* determine if the segment is free */ do { - if(chunk->u.bucket == i) { + if (chunk->u.bucket == i) { empty = false; break; } chunk = chunk->next_in_segment; - } while(chunk != first_chunk); + } while (chunk != first_chunk); /* go to next segment */ segment = segment->next_segment; } - if( true == empty ) { /* all segments ready for release */ - mca_allocator_bucket_segment_head_t* next_segment; + if (true == empty) { /* all segments ready for release */ + mca_allocator_bucket_segment_head_t *next_segment; segment = mem_options->buckets[i].segment_head; - while( NULL != segment ) { + while (NULL != segment) { next_segment = segment->next_segment; /* free the memory */ - if(mem_options->free_mem_fn) + if (mem_options->free_mem_fn) { mem_options->free_mem_fn(mem->alc_context, segment); + } segment = next_segment; } mem_options->buckets[i].free_chunk = NULL; mem_options->buckets[i].segment_head = NULL; } else { /* traverse the list of segment headers until we hit NULL */ - while(NULL != *segment_header) { + while (NULL != *segment_header) { first_chunk = (*segment_header)->first_chunk; chunk = first_chunk; empty = true; /* determine if the segment is free */ do { - if(chunk->u.bucket == i) { + if (chunk->u.bucket == i) { empty = false; } chunk = chunk->next_in_segment; - } while(empty && (chunk != first_chunk)); - if(empty) { + } while (empty && (chunk != first_chunk)); + if (empty) { chunk = first_chunk; /* remove the chunks from the free list */ do { - if(mem_options->buckets[i].free_chunk == chunk) { + if (mem_options->buckets[i].free_chunk == chunk) { mem_options->buckets[i].free_chunk = chunk->u.next_free; } else { next_chunk = mem_options->buckets[i].free_chunk; - while(next_chunk->u.next_free != chunk) { + while (next_chunk->u.next_free != chunk) { next_chunk = next_chunk->u.next_free; } next_chunk->u.next_free = chunk->u.next_free; } - } while((chunk = chunk->next_in_segment) != first_chunk); + } while ((chunk = chunk->next_in_segment) != first_chunk); /* set the segment list to point to the next segment */ segment = *segment_header; *segment_header = segment->next_segment; /* free the memory */ - if(mem_options->free_mem_fn) + if (mem_options->free_mem_fn) { mem_options->free_mem_fn(mem->alc_context, segment); + } } else { /* go to next segment */ segment_header = &((*segment_header)->next_segment); @@ -380,5 +378,5 @@ int mca_allocator_bucket_cleanup(mca_allocator_base_module_t * mem) /* relese the lock on the bucket */ OPAL_THREAD_UNLOCK(&(mem_options->buckets[i].lock)); } - return(OPAL_SUCCESS); + return (OPAL_SUCCESS); } diff --git a/opal/mca/allocator/bucket/allocator_bucket_alloc.h b/opal/mca/allocator/bucket/allocator_bucket_alloc.h index 103b611d7b4..284aa63ab91 100644 --- a/opal/mca/allocator/bucket/allocator_bucket_alloc.h +++ b/opal/mca/allocator/bucket/allocator_bucket_alloc.h @@ -27,190 +27,182 @@ #define ALLOCATOR_BUCKET_ALLOC_H #include "opal_config.h" +#include "opal/mca/allocator/allocator.h" +#include "opal/mca/threads/mutex.h" #include #include -#include "opal/mca/threads/mutex.h" -#include "opal/mca/allocator/allocator.h" BEGIN_C_DECLS /** - * Structure for the header of each memory chunk - */ + * Structure for the header of each memory chunk + */ struct mca_allocator_bucket_chunk_header_t { - struct mca_allocator_bucket_chunk_header_t * next_in_segment; - /**< The next chunk in the memory segment */ + struct mca_allocator_bucket_chunk_header_t *next_in_segment; + /**< The next chunk in the memory segment */ /** - * Union which holds either a pointer to the next free chunk - * or the bucket number. Based on the current location of the chunk - * we use one or the other of these fields. If the chunk is owned - * by the user, then the bucket field is set, which allow us to know - * in which specific bucket we have to put it back on free (as the - * chunk don't have the size attached). When the allocator own the - * chunk, the next_free fild is used, which allow us to put these - * chunks a list of free elements. - */ + * Union which holds either a pointer to the next free chunk + * or the bucket number. Based on the current location of the chunk + * we use one or the other of these fields. If the chunk is owned + * by the user, then the bucket field is set, which allow us to know + * in which specific bucket we have to put it back on free (as the + * chunk don't have the size attached). When the allocator own the + * chunk, the next_free fild is used, which allow us to put these + * chunks a list of free elements. + */ union u { - struct mca_allocator_bucket_chunk_header_t * next_free; + struct mca_allocator_bucket_chunk_header_t *next_free; /**< if the chunk is free this will point to the next free chunk in the bucket */ - int bucket; /**< the bucket number it belongs to */ - } u; /**< the union */ + int bucket; /**< the bucket number it belongs to */ + } u; /**< the union */ }; - /** - * Typedef so we don't have to use struct - */ +/** + * Typedef so we don't have to use struct + */ typedef struct mca_allocator_bucket_chunk_header_t mca_allocator_bucket_chunk_header_t; /** - * Structure that heads each segment - */ + * Structure that heads each segment + */ struct mca_allocator_bucket_segment_head_t { - struct mca_allocator_bucket_chunk_header_t * first_chunk; /**< the first chunk of the header */ - struct mca_allocator_bucket_segment_head_t * next_segment; /**< the next segment in the - bucket */ + struct mca_allocator_bucket_chunk_header_t *first_chunk; /**< the first chunk of the header */ + struct mca_allocator_bucket_segment_head_t *next_segment; /**< the next segment in the + bucket */ }; /** - * Typedef so we don't have to use struct - */ + * Typedef so we don't have to use struct + */ typedef struct mca_allocator_bucket_segment_head_t mca_allocator_bucket_segment_head_t; /** - * Structure for each bucket - */ + * Structure for each bucket + */ struct mca_allocator_bucket_bucket_t { - mca_allocator_bucket_chunk_header_t * free_chunk; /**< the first free chunk of memory */ - opal_mutex_t lock; /**< the lock on the bucket */ - mca_allocator_bucket_segment_head_t * segment_head; /**< the list of segment headers */ + mca_allocator_bucket_chunk_header_t *free_chunk; /**< the first free chunk of memory */ + opal_mutex_t lock; /**< the lock on the bucket */ + mca_allocator_bucket_segment_head_t *segment_head; /**< the list of segment headers */ }; /** - * Typedef so we don't have to use struct - */ + * Typedef so we don't have to use struct + */ typedef struct mca_allocator_bucket_bucket_t mca_allocator_bucket_bucket_t; /** - * Structure that holds the necessary information for each area of memory - */ + * Structure that holds the necessary information for each area of memory + */ struct mca_allocator_bucket_t { - mca_allocator_base_module_t super; /**< makes this a child of class mca_allocator_t */ - mca_allocator_bucket_bucket_t * buckets; /**< the array of buckets */ - int num_buckets; /**< the number of buckets */ + mca_allocator_base_module_t super; /**< makes this a child of class mca_allocator_t */ + mca_allocator_bucket_bucket_t *buckets; /**< the array of buckets */ + int num_buckets; /**< the number of buckets */ mca_allocator_base_component_segment_alloc_fn_t get_mem_fn; /**< pointer to the function to get more memory */ mca_allocator_base_component_segment_free_fn_t free_mem_fn; /**< pointer to the function to free memory */ }; /** - * Typedef so we don't have to use struct - */ + * Typedef so we don't have to use struct + */ typedef struct mca_allocator_bucket_t mca_allocator_bucket_t; - /** - * Initializes the mca_allocator_bucket_options_t data structure for the passed - * parameters. - * @param mem a pointer to the mca_allocator_t struct to be filled in - * @param num_buckets The number of buckets the allocator will use - * @param get_mem_funct A pointer to the function that the allocator - * will use to get more memory - * @param free_mem_funct A pointer to the function that the allocator - * will use to free memory - * - * @retval Pointer to the initialized mca_allocator_bucket_options_t structure - * @retval NULL if there was an error - */ - mca_allocator_bucket_t *mca_allocator_bucket_init(mca_allocator_base_module_t * mem, - int num_buckets, - mca_allocator_base_component_segment_alloc_fn_t get_mem_funct, - mca_allocator_base_component_segment_free_fn_t free_mem_funct); /** - * Accepts a request for memory in a specific region defined by the - * mca_allocator_bucket_options_t struct and returns a pointer to memory in that - * region or NULL if there was an error - * - * @param mem A pointer to the appropriate struct for the area of memory. - * @param size The size of the requested area of memory - * - * @retval Pointer to the area of memory if the allocation was successful - * @retval NULL if the allocation was unsuccessful - */ - void * mca_allocator_bucket_alloc( - mca_allocator_base_module_t * mem, - size_t size); + * Initializes the mca_allocator_bucket_options_t data structure for the passed + * parameters. + * @param mem a pointer to the mca_allocator_t struct to be filled in + * @param num_buckets The number of buckets the allocator will use + * @param get_mem_funct A pointer to the function that the allocator + * will use to get more memory + * @param free_mem_funct A pointer to the function that the allocator + * will use to free memory + * + * @retval Pointer to the initialized mca_allocator_bucket_options_t structure + * @retval NULL if there was an error + */ +mca_allocator_bucket_t * +mca_allocator_bucket_init(mca_allocator_base_module_t *mem, int num_buckets, + mca_allocator_base_component_segment_alloc_fn_t get_mem_funct, + mca_allocator_base_component_segment_free_fn_t free_mem_funct); +/** + * Accepts a request for memory in a specific region defined by the + * mca_allocator_bucket_options_t struct and returns a pointer to memory in that + * region or NULL if there was an error + * + * @param mem A pointer to the appropriate struct for the area of memory. + * @param size The size of the requested area of memory + * + * @retval Pointer to the area of memory if the allocation was successful + * @retval NULL if the allocation was unsuccessful + */ +void *mca_allocator_bucket_alloc(mca_allocator_base_module_t *mem, size_t size); /** - * Accepts a request for memory in a specific region defined by the - * mca_allocator_bucket_options_t struct and aligned by the specified amount and - * returns a pointer to memory in that region or NULL if there was an error - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param size The size of the requested area of memory - * @param alignment The requested alignment of the new area of memory. This - * MUST be a power of 2. - * - * @retval Pointer to the area of memory if the allocation was successful - * @retval NULL if the allocation was unsuccessful - * - */ - void * mca_allocator_bucket_alloc_align( - mca_allocator_base_module_t * mem, - size_t size, - size_t alignment); + * Accepts a request for memory in a specific region defined by the + * mca_allocator_bucket_options_t struct and aligned by the specified amount and + * returns a pointer to memory in that region or NULL if there was an error + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param size The size of the requested area of memory + * @param alignment The requested alignment of the new area of memory. This + * MUST be a power of 2. + * + * @retval Pointer to the area of memory if the allocation was successful + * @retval NULL if the allocation was unsuccessful + * + */ +void *mca_allocator_bucket_alloc_align(mca_allocator_base_module_t *mem, size_t size, + size_t alignment); /** - * Attempts to resize the passed region of memory into a larger or a smaller - * region. If it is unsuccessful, it will return NULL and the passed area of - * memory will be untouched. - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param size The size of the requested area of memory - * @param ptr A pointer to the region of memory to be resized - * - * @retval Pointer to the area of memory if the reallocation was successful - * @retval NULL if the allocation was unsuccessful - * - */ - void * mca_allocator_bucket_realloc( - mca_allocator_base_module_t * mem, - void * ptr, - size_t size); + * Attempts to resize the passed region of memory into a larger or a smaller + * region. If it is unsuccessful, it will return NULL and the passed area of + * memory will be untouched. + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param size The size of the requested area of memory + * @param ptr A pointer to the region of memory to be resized + * + * @retval Pointer to the area of memory if the reallocation was successful + * @retval NULL if the allocation was unsuccessful + * + */ +void *mca_allocator_bucket_realloc(mca_allocator_base_module_t *mem, void *ptr, size_t size); /** - * Frees the passed region of memory - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * @param ptr A pointer to the region of memory to be freed - * - * @retval None - * - */ - void mca_allocator_bucket_free(mca_allocator_base_module_t * mem, - void * ptr); + * Frees the passed region of memory + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * @param ptr A pointer to the region of memory to be freed + * + * @retval None + * + */ +void mca_allocator_bucket_free(mca_allocator_base_module_t *mem, void *ptr); /** - * Frees all the memory from all the buckets back to the system. Note that - * this function only frees memory that was previously freed with - * mca_allocator_bucket_free(). - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * - * @retval None - * - */ - int mca_allocator_bucket_cleanup(mca_allocator_base_module_t * mem); + * Frees all the memory from all the buckets back to the system. Note that + * this function only frees memory that was previously freed with + * mca_allocator_bucket_free(). + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * + * @retval None + * + */ +int mca_allocator_bucket_cleanup(mca_allocator_base_module_t *mem); /** - * Cleanup all resources held by this allocator. - * - * @param mem A pointer to the appropriate struct for the area of - * memory. - * - * @retval None - * - */ - int mca_allocator_bucket_finalize(mca_allocator_base_module_t * mem); + * Cleanup all resources held by this allocator. + * + * @param mem A pointer to the appropriate struct for the area of + * memory. + * + * @retval None + * + */ +int mca_allocator_bucket_finalize(mca_allocator_base_module_t *mem); OPAL_DECLSPEC extern mca_allocator_base_component_t mca_allocator_bucket_component; diff --git a/opal/mca/backtrace/backtrace.h b/opal/mca/backtrace/backtrace.h index 9ca5658cdea..7ab82c495fc 100644 --- a/opal/mca/backtrace/backtrace.h +++ b/opal/mca/backtrace/backtrace.h @@ -25,8 +25,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/util/stacktrace.h" BEGIN_C_DECLS @@ -37,7 +37,6 @@ BEGIN_C_DECLS * components. */ - /* * Print back trace to FILE file with a prefix for each line. * First strip lines are not printed. @@ -55,8 +54,7 @@ OPAL_DECLSPEC int opal_backtrace_print(FILE *file, char *prefix, int strip); * \note Probably bad to call this from a signal handler. * */ -OPAL_DECLSPEC int opal_backtrace_buffer(char*** messages, int *len); - +OPAL_DECLSPEC int opal_backtrace_buffer(char ***messages, int *len); /** * Structure for backtrace components. @@ -75,8 +73,7 @@ typedef struct opal_backtrace_base_component_2_0_0_t opal_backtrace_base_compone /* * Macro for use in components that are of type backtrace */ -#define OPAL_BACKTRACE_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("backtrace", 2, 0, 0) +#define OPAL_BACKTRACE_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("backtrace", 2, 0, 0) END_C_DECLS diff --git a/opal/mca/backtrace/base/backtrace_component.c b/opal/mca/backtrace/base/backtrace_component.c index 995fa2328c6..18811e27743 100644 --- a/opal/mca/backtrace/base/backtrace_component.c +++ b/opal/mca/backtrace/base/backtrace_component.c @@ -18,7 +18,6 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/mca/backtrace/base/base.h" @@ -30,11 +29,10 @@ */ #include "opal/mca/backtrace/base/static-components.h" - /* * Globals */ /* Uses default register/open/close functions */ MCA_BASE_FRAMEWORK_DECLARE(opal, backtrace, NULL, NULL, NULL, NULL, - mca_backtrace_base_static_components, 0); + mca_backtrace_base_static_components, 0); diff --git a/opal/mca/backtrace/execinfo/backtrace_execinfo.c b/opal/mca/backtrace/execinfo/backtrace_execinfo.c index 0f17c514c1d..1e299676e30 100644 --- a/opal/mca/backtrace/execinfo/backtrace_execinfo.c +++ b/opal/mca/backtrace/execinfo/backtrace_execinfo.c @@ -23,25 +23,24 @@ #include #include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_EXECINFO_H -#include +# include #endif #include "opal/constants.h" #include "opal/mca/backtrace/backtrace.h" -int -opal_backtrace_print(FILE *file, char *prefix, int strip) +int opal_backtrace_print(FILE *file, char *prefix, int strip) { int i, len; int trace_size; - void * trace[32]; + void *trace[32]; char buf[6]; int fd = opal_stacktrace_output_fileno; - if( NULL != file ) { + if (NULL != file) { fd = fileno(file); } @@ -49,30 +48,28 @@ opal_backtrace_print(FILE *file, char *prefix, int strip) return OPAL_ERR_BAD_PARAM; } - trace_size = backtrace (trace, 32); + trace_size = backtrace(trace, 32); for (i = strip; i < trace_size; i++) { if (NULL != prefix) { - write (fd, prefix, strlen (prefix)); + write(fd, prefix, strlen(prefix)); } - len = snprintf (buf, sizeof(buf), "[%2d] ", i - strip); - write (fd, buf, len); - backtrace_symbols_fd (&trace[i], 1, fd); + len = snprintf(buf, sizeof(buf), "[%2d] ", i - strip); + write(fd, buf, len); + backtrace_symbols_fd(&trace[i], 1, fd); } return OPAL_SUCCESS; } - -int -opal_backtrace_buffer(char ***message_out, int *len_out) +int opal_backtrace_buffer(char ***message_out, int *len_out) { int trace_size; - void * trace[32]; - char ** funcs = (char **)NULL; + void *trace[32]; + char **funcs = (char **) NULL; - trace_size = backtrace (trace, 32); - funcs = backtrace_symbols (trace, trace_size); + trace_size = backtrace(trace, 32); + funcs = backtrace_symbols(trace, trace_size); *message_out = funcs; *len_out = trace_size; diff --git a/opal/mca/backtrace/execinfo/backtrace_execinfo_component.c b/opal/mca/backtrace/execinfo/backtrace_execinfo_component.c index cb44d2ce692..fd36bbffe0c 100644 --- a/opal/mca/backtrace/execinfo/backtrace_execinfo_component.c +++ b/opal/mca/backtrace/execinfo/backtrace_execinfo_component.c @@ -26,16 +26,16 @@ const opal_backtrace_base_component_2_0_0_t mca_backtrace_execinfo_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .backtracec_version = { - OPAL_BACKTRACE_BASE_VERSION_2_0_0, + .backtracec_version = + { + OPAL_BACKTRACE_BASE_VERSION_2_0_0, - /* Component name and version */ - .mca_component_name = "execinfo", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - }, - .backtracec_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component name and version */ + .mca_component_name = "execinfo", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + }, + .backtracec_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; diff --git a/opal/mca/backtrace/none/backtrace_none.c b/opal/mca/backtrace/none/backtrace_none.c index ba343f22dbf..57b8baba456 100644 --- a/opal/mca/backtrace/none/backtrace_none.c +++ b/opal/mca/backtrace/none/backtrace_none.c @@ -23,15 +23,12 @@ #include "opal/constants.h" #include "opal/mca/backtrace/backtrace.h" -int -opal_backtrace_print(FILE *file, char *prefix, int strip) +int opal_backtrace_print(FILE *file, char *prefix, int strip) { return OPAL_ERR_NOT_IMPLEMENTED; } - -int -opal_backtrace_buffer(char ***message_out, int *len_out) +int opal_backtrace_buffer(char ***message_out, int *len_out) { *message_out = NULL; *len_out = 0; diff --git a/opal/mca/backtrace/none/backtrace_none_component.c b/opal/mca/backtrace/none/backtrace_none_component.c index 9f820ea695a..a5021183b86 100644 --- a/opal/mca/backtrace/none/backtrace_none_component.c +++ b/opal/mca/backtrace/none/backtrace_none_component.c @@ -24,22 +24,22 @@ #include "opal/mca/backtrace/backtrace.h" BEGIN_C_DECLS - OPAL_DECLSPEC extern const opal_backtrace_base_component_2_0_0_t mca_backtrace_none_component; +OPAL_DECLSPEC extern const opal_backtrace_base_component_2_0_0_t mca_backtrace_none_component; END_C_DECLS const opal_backtrace_base_component_2_0_0_t mca_backtrace_none_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .backtracec_version = { - OPAL_BACKTRACE_BASE_VERSION_2_0_0, + .backtracec_version = + { + OPAL_BACKTRACE_BASE_VERSION_2_0_0, - /* Component name and version */ - .mca_component_name = "none", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - }, - .backtracec_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component name and version */ + .mca_component_name = "none", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + }, + .backtracec_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; diff --git a/opal/mca/backtrace/printstack/backtrace_printstack.c b/opal/mca/backtrace/printstack/backtrace_printstack.c index 214cacfb14b..e95335b6cf4 100644 --- a/opal/mca/backtrace/printstack/backtrace_printstack.c +++ b/opal/mca/backtrace/printstack/backtrace_printstack.c @@ -25,12 +25,11 @@ #include "opal/constants.h" #include "opal/mca/backtrace/backtrace.h" -int -opal_backtrace_print(FILE *file, char *prefix, int strip) +int opal_backtrace_print(FILE *file, char *prefix, int strip) { int fd = opal_stacktrace_output_fileno; - if( NULL != file ) { + if (NULL != file) { fd = fileno(file); } @@ -39,9 +38,7 @@ opal_backtrace_print(FILE *file, char *prefix, int strip) return OPAL_SUCCESS; } - -int -opal_backtrace_buffer(char ***message_out, int *len_out) +int opal_backtrace_buffer(char ***message_out, int *len_out) { *message_out = NULL; *len_out = 0; diff --git a/opal/mca/backtrace/printstack/backtrace_printstack_component.c b/opal/mca/backtrace/printstack/backtrace_printstack_component.c index 3a37269969d..7174383bb72 100644 --- a/opal/mca/backtrace/printstack/backtrace_printstack_component.c +++ b/opal/mca/backtrace/printstack/backtrace_printstack_component.c @@ -26,16 +26,16 @@ const opal_backtrace_base_component_2_0_0_t mca_backtrace_printstack_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .backtracec_version = { - OPAL_BACKTRACE_BASE_VERSION_2_0_0, + .backtracec_version = + { + OPAL_BACKTRACE_BASE_VERSION_2_0_0, - /* Component name and version */ - .mca_component_name = "printstack", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - }, - .backtracec_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component name and version */ + .mca_component_name = "printstack", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + }, + .backtracec_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; diff --git a/opal/mca/base/base.h b/opal/mca/base/base.h index d180d17961d..dce439ab104 100644 --- a/opal/mca/base/base.h +++ b/opal/mca/base/base.h @@ -30,15 +30,15 @@ #include "opal_config.h" -#include "opal/class/opal_object.h" #include "opal/class/opal_list.h" +#include "opal/class/opal_object.h" /* * These units are large enough to warrant their own .h files */ -#include "opal/mca/mca.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/base/mca_base_var.h" +#include "opal/mca/mca.h" #include "opal/util/cmd_line.h" #include "opal/util/output.h" @@ -61,8 +61,7 @@ struct mca_base_component_priority_list_item_t { mca_base_component_list_item_t super; int cpli_priority; }; -typedef struct mca_base_component_priority_list_item_t - mca_base_component_priority_list_item_t; +typedef struct mca_base_component_priority_list_item_t mca_base_component_priority_list_item_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_base_component_priority_list_item_t); @@ -81,23 +80,23 @@ OPAL_DECLSPEC extern char *mca_base_user_default_path; */ enum { /** total silence */ - MCA_BASE_VERBOSE_NONE = -1, + MCA_BASE_VERBOSE_NONE = -1, /** only errors are printed */ MCA_BASE_VERBOSE_ERROR = 0, /** emit messages about component selection, open, and unloading */ MCA_BASE_VERBOSE_COMPONENT = 10, /** also emit warnings */ - MCA_BASE_VERBOSE_WARN = 20, + MCA_BASE_VERBOSE_WARN = 20, /** also emit general, user-relevant information, such as rationale as to why certain choices * or code paths were taken, information gleaned from probing the local system, etc. */ - MCA_BASE_VERBOSE_INFO = 40, + MCA_BASE_VERBOSE_INFO = 40, /** also emit relevant tracing information (e.g., which functions were invoked / * call stack entry/exit info) */ MCA_BASE_VERBOSE_TRACE = 60, /** also emit Open MPI-developer-level (i.e,. highly detailed) information */ MCA_BASE_VERBOSE_DEBUG = 80, /** also output anything else that might be useful */ - MCA_BASE_VERBOSE_MAX = 100, + MCA_BASE_VERBOSE_MAX = 100, }; /* @@ -141,8 +140,7 @@ OPAL_DECLSPEC void mca_base_close(void); OPAL_DECLSPEC int mca_base_select(const char *type_name, int output_id, opal_list_t *components_available, mca_base_module_t **best_module, - mca_base_component_t **best_component, - int *priority_out); + mca_base_component_t **best_component, int *priority_out); /** * A function for component query functions to discover if they have @@ -153,15 +151,13 @@ OPAL_DECLSPEC int mca_base_select(const char *type_name, int output_id, * */ OPAL_DECLSPEC int mca_base_is_component_required(opal_list_t *components_available, - mca_base_component_t *component, - bool exclusive, + mca_base_component_t *component, bool exclusive, bool *is_required); /* mca_base_cmd_line.c */ OPAL_DECLSPEC int mca_base_cmd_line_setup(opal_cmd_line_t *cmd); -OPAL_DECLSPEC int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, - char ***app_env, +OPAL_DECLSPEC int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***app_env, char ***global_env); OPAL_DECLSPEC void mca_base_cmd_line_wrap_args(char **args); @@ -173,19 +169,19 @@ OPAL_DECLSPEC int mca_base_component_compare(const mca_base_component_t *a, const mca_base_component_t *b); OPAL_DECLSPEC int mca_base_component_compatible(const mca_base_component_t *a, const mca_base_component_t *b); -OPAL_DECLSPEC char * mca_base_component_to_string(const mca_base_component_t *a); +OPAL_DECLSPEC char *mca_base_component_to_string(const mca_base_component_t *a); /* mca_base_component_find.c */ -OPAL_DECLSPEC int mca_base_component_find (const char *directory, mca_base_framework_t *framework, - bool ignore_requested, bool open_dso_components); +OPAL_DECLSPEC int mca_base_component_find(const char *directory, mca_base_framework_t *framework, + bool ignore_requested, bool open_dso_components); /** * Parse the requested component string and return an opal_argv of the requested * (or not requested) components. */ -int mca_base_component_parse_requested (const char *requested, bool *include_mode, - char ***requested_component_names); +int mca_base_component_parse_requested(const char *requested, bool *include_mode, + char ***requested_component_names); /** * Filter a list of components based on a comma-delimted list of names and/or @@ -205,9 +201,8 @@ int mca_base_component_parse_requested (const char *requested, bool *include_mod * This function closes and releases any components that do not match the filter_name and * filter flags. */ -OPAL_DECLSPEC int mca_base_components_filter (mca_base_framework_t *framework, uint32_t filter_flags); - - +OPAL_DECLSPEC int mca_base_components_filter(mca_base_framework_t *framework, + uint32_t filter_flags); /* Safely release some memory allocated by mca_base_component_find() (i.e., is safe to call even if you never called @@ -215,12 +210,12 @@ OPAL_DECLSPEC int mca_base_components_filter (mca_base_framework_t *framework, u OPAL_DECLSPEC int mca_base_component_find_finalize(void); /* mca_base_components_register.c */ -OPAL_DECLSPEC int mca_base_framework_components_register (struct mca_base_framework_t *framework, - mca_base_register_flag_t flags); +OPAL_DECLSPEC int mca_base_framework_components_register(struct mca_base_framework_t *framework, + mca_base_register_flag_t flags); /* mca_base_components_open.c */ -OPAL_DECLSPEC int mca_base_framework_components_open (struct mca_base_framework_t *framework, - mca_base_open_flag_t flags); +OPAL_DECLSPEC int mca_base_framework_components_open(struct mca_base_framework_t *framework, + mca_base_open_flag_t flags); OPAL_DECLSPEC int mca_base_components_open(const char *type_name, int output_id, const mca_base_component_t **static_components, @@ -236,7 +231,7 @@ OPAL_DECLSPEC int mca_base_components_open(const char *type_name, int output_id, * * After calling this function the component may no longer be used. */ -OPAL_DECLSPEC void mca_base_component_close (const mca_base_component_t *component, int output_id); +OPAL_DECLSPEC void mca_base_component_close(const mca_base_component_t *component, int output_id); /** * Release a component without closing it. @@ -245,13 +240,13 @@ OPAL_DECLSPEC void mca_base_component_close (const mca_base_component_t *compone * * After calling this function the component may no longer be used. */ -void mca_base_component_unload (const mca_base_component_t *component, int output_id); +void mca_base_component_unload(const mca_base_component_t *component, int output_id); OPAL_DECLSPEC int mca_base_components_close(int output_id, opal_list_t *components_available, const mca_base_component_t *skip); -OPAL_DECLSPEC int mca_base_framework_components_close (struct mca_base_framework_t *framework, - const mca_base_component_t *skip); +OPAL_DECLSPEC int mca_base_framework_components_close(struct mca_base_framework_t *framework, + const mca_base_component_t *skip); END_C_DECLS diff --git a/opal/mca/base/mca_base_alias.c b/opal/mca/base/mca_base_alias.c index ad5e557d18d..564ea07a24c 100644 --- a/opal/mca/base/mca_base_alias.c +++ b/opal/mca/base/mca_base_alias.c @@ -12,25 +12,26 @@ #include "opal/class/opal_hash_table.h" #include "opal/runtime/opal.h" -static void mca_base_alias_init (mca_base_alias_t *alias) +static void mca_base_alias_init(mca_base_alias_t *alias) { OBJ_CONSTRUCT(&alias->component_aliases, opal_list_t); } -static void mca_base_alias_fini (mca_base_alias_t *alias) +static void mca_base_alias_fini(mca_base_alias_t *alias) { OPAL_LIST_DESTRUCT(&alias->component_aliases); } -OBJ_CLASS_INSTANCE(mca_base_alias_t, opal_object_t, mca_base_alias_init, - mca_base_alias_fini); +OBJ_CLASS_INSTANCE(mca_base_alias_t, opal_object_t, mca_base_alias_init, mca_base_alias_fini); -static void mca_base_alias_item_init (mca_base_alias_item_t *alias_item) { +static void mca_base_alias_item_init(mca_base_alias_item_t *alias_item) +{ alias_item->component_alias = NULL; } -static void mca_base_alias_item_fini (mca_base_alias_item_t *alias_item) { - free (alias_item->component_alias); +static void mca_base_alias_item_fini(mca_base_alias_item_t *alias_item) +{ + free(alias_item->component_alias); } OBJ_CLASS_INSTANCE(mca_base_alias_item_t, opal_list_item_t, mca_base_alias_item_init, @@ -41,7 +42,7 @@ OBJ_CLASS_INSTANCE(mca_base_alias_item_t, opal_list_item_t, mca_base_alias_item_ */ static opal_hash_table_t *alias_hash_table; -static void mca_base_alias_cleanup (void) +static void mca_base_alias_cleanup(void) { if (!alias_hash_table) { return; @@ -49,28 +50,27 @@ static void mca_base_alias_cleanup (void) void *key; opal_object_t *value; - OPAL_HASH_TABLE_FOREACH_PTR(key, value, alias_hash_table, { - OBJ_RELEASE(value); - }); + OPAL_HASH_TABLE_FOREACH_PTR (key, value, alias_hash_table, { OBJ_RELEASE(value); }) + ; OBJ_RELEASE(alias_hash_table); alias_hash_table = NULL; } -static int mca_base_alias_setup (void) +static int mca_base_alias_setup(void) { if (NULL != alias_hash_table) { return OPAL_SUCCESS; } - opal_finalize_register_cleanup (mca_base_alias_cleanup); + opal_finalize_register_cleanup(mca_base_alias_cleanup); alias_hash_table = OBJ_NEW(opal_hash_table_t); if (NULL == alias_hash_table) { return OPAL_ERR_OUT_OF_RESOURCE; } - int ret = opal_hash_table_init (alias_hash_table, 32); + int ret = opal_hash_table_init(alias_hash_table, 32); if (OPAL_SUCCESS != ret) { OBJ_RELEASE(alias_hash_table); alias_hash_table = NULL; @@ -80,19 +80,20 @@ static int mca_base_alias_setup (void) return OPAL_SUCCESS; } -static char *mca_base_alias_generate_name (const char *project, const char *framework, const char *component_name) +static char *mca_base_alias_generate_name(const char *project, const char *framework, + const char *component_name) { - size_t project_length = project ? strlen (project) : 0; - size_t framework_length = framework ? strlen (framework) : 0; - size_t component_name_length = strlen (component_name); + size_t project_length = project ? strlen(project) : 0; + size_t framework_length = framework ? strlen(framework) : 0; + size_t component_name_length = strlen(component_name); size_t length = project_length + framework_length + component_name_length + 2; - char *tmp = calloc (1, length + 1); + char *tmp = calloc(1, length + 1); if (NULL == tmp) { return tmp; } if (project_length) { - strncat (tmp, project, length); + strncat(tmp, project, length); // NOTE: We use strcat() here (and not strncat()) because // we're appending a constant string with a fixed/hard-coded // length. It's the exact equivalent of strncat(tmp, "_", 1), @@ -101,85 +102,88 @@ static char *mca_base_alias_generate_name (const char *project, const char *fram // constant string as the source and a hard-coded length that // is equivalent to the length of that compile-time constant // string. So avoid the warning and use strcat(). - strcat (tmp, "_"); + strcat(tmp, "_"); length -= project_length + 1; } if (framework_length) { - strncat (tmp, framework, length); + strncat(tmp, framework, length); // Use strcat() here instead of strncat(); see the comment // above for an explanation. - strcat (tmp, "_"); + strcat(tmp, "_"); length -= framework_length + 1; } - strncat (tmp, component_name, length); + strncat(tmp, component_name, length); return tmp; } -static mca_base_alias_t *mca_base_alias_lookup_internal (const char *name) +static mca_base_alias_t *mca_base_alias_lookup_internal(const char *name) { mca_base_alias_t *alias = NULL; if (NULL == alias_hash_table) { return NULL; } - (void) opal_hash_table_get_value_ptr (alias_hash_table, name, strlen (name), (void **) &alias); + (void) opal_hash_table_get_value_ptr(alias_hash_table, name, strlen(name), (void **) &alias); return alias; } -int mca_base_alias_register (const char *project, const char *framework, const char *component_name, - const char *component_alias, uint32_t alias_flags) +int mca_base_alias_register(const char *project, const char *framework, const char *component_name, + const char *component_alias, uint32_t alias_flags) { if (NULL == component_name) { return OPAL_ERR_BAD_PARAM; } - int ret = mca_base_alias_setup (); + int ret = mca_base_alias_setup(); if (OPAL_SUCCESS != ret) { return ret; } - char *name = mca_base_alias_generate_name (project, framework, component_name); - assert (NULL != name); + char *name = mca_base_alias_generate_name(project, framework, component_name); + assert(NULL != name); - mca_base_alias_t *alias = mca_base_alias_lookup_internal (name); + mca_base_alias_t *alias = mca_base_alias_lookup_internal(name); if (NULL == alias) { alias = OBJ_NEW(mca_base_alias_t); if (NULL == alias) { return OPAL_ERR_OUT_OF_RESOURCE; } - opal_hash_table_set_value_ptr (alias_hash_table, name, strlen(name), alias); - free (name); + opal_hash_table_set_value_ptr(alias_hash_table, name, strlen(name), alias); + free(name); name = NULL; } mca_base_alias_item_t *alias_item = OBJ_NEW(mca_base_alias_item_t); if (NULL == alias_item) { - if (NULL != name) free(name); + if (NULL != name) { + free(name); + } return OPAL_ERR_OUT_OF_RESOURCE; } - - alias_item->component_alias = strdup (component_alias); + + alias_item->component_alias = strdup(component_alias); alias_item->alias_flags = alias_flags; - opal_list_append (&alias->component_aliases, &alias_item->super); + opal_list_append(&alias->component_aliases, &alias_item->super); return OPAL_SUCCESS; } -const mca_base_alias_t *mca_base_alias_lookup(const char *project, const char *framework, const char *component_name) +const mca_base_alias_t *mca_base_alias_lookup(const char *project, const char *framework, + const char *component_name) { if (NULL == component_name) { return NULL; } - char *name = mca_base_alias_generate_name (project, framework, component_name); - assert (NULL != name); - const mca_base_alias_t *alias = mca_base_alias_lookup_internal (name); - free (name); + char *name = mca_base_alias_generate_name(project, framework, component_name); + assert(NULL != name); + const mca_base_alias_t *alias = mca_base_alias_lookup_internal(name); + free(name); return alias; } diff --git a/opal/mca/base/mca_base_alias.h b/opal/mca/base/mca_base_alias.h index 552464ce6da..83bcbafbd95 100644 --- a/opal/mca/base/mca_base_alias.h +++ b/opal/mca/base/mca_base_alias.h @@ -17,9 +17,9 @@ BEGIN_C_DECLS enum mca_base_alias_flags_t { - MCA_BASE_ALIAS_FLAG_NONE = 0, - /** The aliased name has been deprecated. */ - MCA_BASE_ALIAS_FLAG_DEPRECATED = 1, + MCA_BASE_ALIAS_FLAG_NONE = 0, + /** The aliased name has been deprecated. */ + MCA_BASE_ALIAS_FLAG_DEPRECATED = 1, }; typedef enum mca_base_alias_flags_t mca_base_alias_flags_t; @@ -67,10 +67,9 @@ OBJ_CLASS_DECLARATION(mca_base_alias_t); * component if the synonym is registered in the btl framework * registration function. */ -OPAL_DECLSPEC int mca_base_alias_register (const char *project, const char *framework, - const char *component_name, - const char *component_alias, - uint32_t alias_flags); +OPAL_DECLSPEC int mca_base_alias_register(const char *project, const char *framework, + const char *component_name, const char *component_alias, + uint32_t alias_flags); /** * @brief Check for aliases for a component. @@ -79,8 +78,7 @@ OPAL_DECLSPEC int mca_base_alias_register (const char *project, const char *fram * @param[in] frameworek Framework name (may be NULL) * @param[in] component_name Component name (may not be NULL) */ -OPAL_DECLSPEC const mca_base_alias_t *mca_base_alias_lookup(const char *project, - const char *framework, - const char *component_name); +OPAL_DECLSPEC const mca_base_alias_t * +mca_base_alias_lookup(const char *project, const char *framework, const char *component_name); #endif /* OPAL_MCA_BASE_ALIAS_H */ diff --git a/opal/mca/base/mca_base_close.c b/opal/mca/base/mca_base_close.c index ef4929e9a5d..2ffd5ae6568 100644 --- a/opal/mca/base/mca_base_close.c +++ b/opal/mca/base/mca_base_close.c @@ -22,11 +22,11 @@ #include "opal_config.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_component_repository.h" -#include "opal/constants.h" +#include "opal/mca/mca.h" +#include "opal/util/output.h" extern int mca_base_opened; @@ -34,25 +34,25 @@ extern int mca_base_opened; * Main MCA shutdown. */ -void mca_base_close (void) +void mca_base_close(void) { - assert (mca_base_opened); + assert(mca_base_opened); if (--mca_base_opened) { return; } /* deregister all MCA base parameters */ - int group_id = mca_base_var_group_find ("opal", "mca", "base"); + int group_id = mca_base_var_group_find("opal", "mca", "base"); if (-1 < group_id) { - mca_base_var_group_deregister (group_id); + mca_base_var_group_deregister(group_id); } /* release the default paths */ - free (mca_base_system_default_path); + free(mca_base_system_default_path); mca_base_system_default_path = NULL; - free (mca_base_user_default_path); + free(mca_base_user_default_path); mca_base_user_default_path = NULL; /* Close down the component repository */ diff --git a/opal/mca/base/mca_base_cmd_line.c b/opal/mca/base/mca_base_cmd_line.c index dae1dac3e5d..08fe29e62f1 100644 --- a/opal/mca/base/mca_base_cmd_line.c +++ b/opal/mca/base/mca_base_cmd_line.c @@ -24,14 +24,13 @@ #include #include -#include "opal/util/cmd_line.h" +#include "opal/constants.h" +#include "opal/mca/base/base.h" #include "opal/util/argv.h" +#include "opal/util/cmd_line.h" #include "opal/util/opal_environ.h" -#include "opal/util/show_help.h" #include "opal/util/printf.h" -#include "opal/mca/base/base.h" -#include "opal/constants.h" - +#include "opal/util/show_help.h" /* * Private variables @@ -40,11 +39,9 @@ /* * Private functions */ -static int process_arg(const char *param, const char *value, - char ***params, char ***values); +static int process_arg(const char *param, const char *value, char ***params, char ***values); static void add_to_env(char **params, char **values, char ***env); - /* * Add -mca to the possible command line options list */ @@ -53,25 +50,32 @@ int mca_base_cmd_line_setup(opal_cmd_line_t *cmd) int ret = OPAL_SUCCESS; ret = opal_cmd_line_make_opt3(cmd, '\0', OPAL_MCA_CMD_LINE_ID, OPAL_MCA_CMD_LINE_ID, 2, - "Pass context-specific MCA parameters; they are considered global if --g"OPAL_MCA_CMD_LINE_ID" is not used and only one context is specified (arg0 is the parameter name; arg1 is the parameter value)"); + "Pass context-specific MCA parameters; they are considered " + "global if --g" OPAL_MCA_CMD_LINE_ID + " is not used and only one context is specified (arg0 is the " + "parameter name; arg1 is the parameter value)"); if (OPAL_SUCCESS != ret) { return ret; } - ret = opal_cmd_line_make_opt3(cmd, '\0', "g"OPAL_MCA_CMD_LINE_ID, "g"OPAL_MCA_CMD_LINE_ID, 2, - "Pass global MCA parameters that are applicable to all contexts (arg0 is the parameter name; arg1 is the parameter value)"); + ret = opal_cmd_line_make_opt3(cmd, '\0', "g" OPAL_MCA_CMD_LINE_ID, "g" OPAL_MCA_CMD_LINE_ID, 2, + "Pass global MCA parameters that are applicable to all contexts " + "(arg0 is the parameter name; arg1 is the parameter value)"); if (OPAL_SUCCESS != ret) { return ret; } { - opal_cmd_line_init_t entry = - {"mca_base_param_file_prefix", '\0', "am", NULL, 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, - "Aggregate MCA parameter set file list", - OPAL_CMD_LINE_OTYPE_LAUNCH - }; + opal_cmd_line_init_t entry = {"mca_base_param_file_prefix", + '\0', + "am", + NULL, + 1, + NULL, + OPAL_CMD_LINE_TYPE_STRING, + "Aggregate MCA parameter set file list", + OPAL_CMD_LINE_OTYPE_LAUNCH}; ret = opal_cmd_line_make_opt_mca(cmd, entry); if (OPAL_SUCCESS != ret) { return ret; @@ -79,12 +83,15 @@ int mca_base_cmd_line_setup(opal_cmd_line_t *cmd) } { - opal_cmd_line_init_t entry = - {"mca_base_envar_file_prefix", '\0', "tune", NULL, 1, - NULL, OPAL_CMD_LINE_TYPE_STRING, - "Application profile options file list", - OPAL_CMD_LINE_OTYPE_DEBUG - }; + opal_cmd_line_init_t entry = {"mca_base_envar_file_prefix", + '\0', + "tune", + NULL, + 1, + NULL, + OPAL_CMD_LINE_TYPE_STRING, + "Application profile options file list", + OPAL_CMD_LINE_OTYPE_DEBUG}; ret = opal_cmd_line_make_opt_mca(cmd, entry); if (OPAL_SUCCESS != ret) { return ret; @@ -94,12 +101,10 @@ int mca_base_cmd_line_setup(opal_cmd_line_t *cmd) return ret; } - /* * Look for and handle any -mca options on the command line */ -int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, - char ***context_env, char ***global_env) +int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***context_env, char ***global_env) { int i, num_insts, rc; char **params; @@ -107,8 +112,8 @@ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, /* If no relevant parameters were given, just return */ - if (!opal_cmd_line_is_taken(cmd, OPAL_MCA_CMD_LINE_ID) && - !opal_cmd_line_is_taken(cmd, "g"OPAL_MCA_CMD_LINE_ID)) { + if (!opal_cmd_line_is_taken(cmd, OPAL_MCA_CMD_LINE_ID) + && !opal_cmd_line_is_taken(cmd, "g" OPAL_MCA_CMD_LINE_ID)) { return OPAL_SUCCESS; } @@ -117,9 +122,10 @@ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, num_insts = opal_cmd_line_get_ninsts(cmd, OPAL_MCA_CMD_LINE_ID); params = values = NULL; for (i = 0; i < num_insts; ++i) { - if (OPAL_SUCCESS != (rc = process_arg(opal_cmd_line_get_param(cmd, OPAL_MCA_CMD_LINE_ID, i, 0), - opal_cmd_line_get_param(cmd, OPAL_MCA_CMD_LINE_ID, i, 1), - ¶ms, &values))) { + if (OPAL_SUCCESS + != (rc = process_arg(opal_cmd_line_get_param(cmd, OPAL_MCA_CMD_LINE_ID, i, 0), + opal_cmd_line_get_param(cmd, OPAL_MCA_CMD_LINE_ID, i, 1), ¶ms, + &values))) { return rc; } } @@ -131,12 +137,13 @@ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, /* Handle global parameters */ - num_insts = opal_cmd_line_get_ninsts(cmd, "g"OPAL_MCA_CMD_LINE_ID); + num_insts = opal_cmd_line_get_ninsts(cmd, "g" OPAL_MCA_CMD_LINE_ID); params = values = NULL; for (i = 0; i < num_insts; ++i) { - if (OPAL_SUCCESS != (rc = process_arg(opal_cmd_line_get_param(cmd, "g"OPAL_MCA_CMD_LINE_ID, i, 0), - opal_cmd_line_get_param(cmd, "g"OPAL_MCA_CMD_LINE_ID, i, 1), - ¶ms, &values))) { + if (OPAL_SUCCESS + != (rc = process_arg(opal_cmd_line_get_param(cmd, "g" OPAL_MCA_CMD_LINE_ID, i, 0), + opal_cmd_line_get_param(cmd, "g" OPAL_MCA_CMD_LINE_ID, i, 1), + ¶ms, &values))) { return rc; } } @@ -151,21 +158,18 @@ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, return OPAL_SUCCESS; } - - /* * Process a single MCA argument. */ -static int process_arg(const char *param, const char *value, - char ***params, char ***values) +static int process_arg(const char *param, const char *value, char ***params, char ***values) { int i; char *p1; /* check for quoted value */ - if ('\"' == value[0] && '\"' == value[strlen(value)-1]) { + if ('\"' == value[0] && '\"' == value[strlen(value) - 1]) { p1 = strdup(&value[1]); - p1[strlen(p1)-1] = '\0'; + p1[strlen(p1) - 1] = '\0'; } else { p1 = strdup(value); } @@ -202,7 +206,6 @@ static int process_arg(const char *param, const char *value, return OPAL_SUCCESS; } - static void add_to_env(char **params, char **values, char ***env) { int i; @@ -212,7 +215,7 @@ static void add_to_env(char **params, char **values, char ***env) vars of the form OPAL_MCA_PREFIX*=value. */ for (i = 0; NULL != params && NULL != params[i]; ++i) { - (void) mca_base_var_env_name (params[i], &name); + (void) mca_base_var_env_name(params[i], &name); opal_setenv(name, values[i], true, env); free(name); } @@ -223,10 +226,10 @@ void mca_base_cmd_line_wrap_args(char **args) int i; char *tstr; - for (i=0; NULL != args && NULL != args[i]; i++) { - if (0 == strcmp(args[i], "-"OPAL_MCA_CMD_LINE_ID) || - 0 == strcmp(args[i], "--"OPAL_MCA_CMD_LINE_ID)) { - if (NULL == args[i+1] || NULL == args[i+2]) { + for (i = 0; NULL != args && NULL != args[i]; i++) { + if (0 == strcmp(args[i], "-" OPAL_MCA_CMD_LINE_ID) + || 0 == strcmp(args[i], "--" OPAL_MCA_CMD_LINE_ID)) { + if (NULL == args[i + 1] || NULL == args[i + 2]) { /* this should be impossible as the error would * have been detected well before here, but just * be safe */ diff --git a/opal/mca/base/mca_base_component_compare.c b/opal/mca/base/mca_base_component_compare.c index ee385ad57a7..9b3267ef3ad 100644 --- a/opal/mca/base/mca_base_component_compare.c +++ b/opal/mca/base/mca_base_component_compare.c @@ -21,8 +21,8 @@ #include -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/util/printf.h" /* @@ -37,102 +37,81 @@ * may help the gentle reader to consider this an inverse comparison. * :-) */ -int -mca_base_component_compare_priority(mca_base_component_priority_list_item_t *a, - mca_base_component_priority_list_item_t *b) +int mca_base_component_compare_priority(mca_base_component_priority_list_item_t *a, + mca_base_component_priority_list_item_t *b) { - /* First, compare the priorties */ - - if (a->cpli_priority > b->cpli_priority) { - return -1; - } else if (a->cpli_priority < b->cpli_priority) { - return 1; - } else { - return mca_base_component_compare(a->super.cli_component, - b->super.cli_component); - } + /* First, compare the priorties */ + + if (a->cpli_priority > b->cpli_priority) { + return -1; + } else if (a->cpli_priority < b->cpli_priority) { + return 1; + } else { + return mca_base_component_compare(a->super.cli_component, b->super.cli_component); + } } - -int mca_base_component_compare(const mca_base_component_t* aa, - const mca_base_component_t* bb) +int mca_base_component_compare(const mca_base_component_t *aa, const mca_base_component_t *bb) { int val; - val = strncmp(aa->mca_type_name, bb->mca_type_name, - MCA_BASE_MAX_TYPE_NAME_LEN); + val = strncmp(aa->mca_type_name, bb->mca_type_name, MCA_BASE_MAX_TYPE_NAME_LEN); if (val != 0) { - return -val; + return -val; } - val = strncmp(aa->mca_component_name, bb->mca_component_name, - MCA_BASE_MAX_COMPONENT_NAME_LEN); + val = strncmp(aa->mca_component_name, bb->mca_component_name, MCA_BASE_MAX_COMPONENT_NAME_LEN); if (val != 0) { - return -val; + return -val; } /* The names were equal, so compare the versions */ - if (aa->mca_component_major_version > - bb->mca_component_major_version) { - return -1; - } else if (aa->mca_component_major_version < - bb->mca_component_major_version) { - return 1; - } else if (aa->mca_component_minor_version > - bb->mca_component_minor_version) { - return -1; - } else if (aa->mca_component_minor_version < - bb->mca_component_minor_version) { - return 1; - } else if (aa->mca_component_release_version > - bb->mca_component_release_version) { - return -1; - } else if (aa->mca_component_release_version < - bb->mca_component_release_version) { - return 1; + if (aa->mca_component_major_version > bb->mca_component_major_version) { + return -1; + } else if (aa->mca_component_major_version < bb->mca_component_major_version) { + return 1; + } else if (aa->mca_component_minor_version > bb->mca_component_minor_version) { + return -1; + } else if (aa->mca_component_minor_version < bb->mca_component_minor_version) { + return 1; + } else if (aa->mca_component_release_version > bb->mca_component_release_version) { + return -1; + } else if (aa->mca_component_release_version < bb->mca_component_release_version) { + return 1; } return 0; } - /** * compare but exclude the release version - declare compatible * if the major/minor version are the same. */ -int mca_base_component_compatible( - const mca_base_component_t* aa, - const mca_base_component_t* bb) +int mca_base_component_compatible(const mca_base_component_t *aa, const mca_base_component_t *bb) { int val; - val = strncmp(aa->mca_type_name, bb->mca_type_name, - MCA_BASE_MAX_TYPE_NAME_LEN); + val = strncmp(aa->mca_type_name, bb->mca_type_name, MCA_BASE_MAX_TYPE_NAME_LEN); if (val != 0) { - return -val; + return -val; } - val = strncmp(aa->mca_component_name, bb->mca_component_name, - MCA_BASE_MAX_COMPONENT_NAME_LEN); + val = strncmp(aa->mca_component_name, bb->mca_component_name, MCA_BASE_MAX_COMPONENT_NAME_LEN); if (val != 0) { - return -val; + return -val; } /* The names were equal, so compare the versions */ - if (aa->mca_component_major_version > - bb->mca_component_major_version) { - return -1; - } else if (aa->mca_component_major_version < - bb->mca_component_major_version) { - return 1; - } else if (aa->mca_component_minor_version > - bb->mca_component_minor_version) { - return -1; - } else if (aa->mca_component_minor_version < - bb->mca_component_minor_version) { - return 1; + if (aa->mca_component_major_version > bb->mca_component_major_version) { + return -1; + } else if (aa->mca_component_major_version < bb->mca_component_major_version) { + return 1; + } else if (aa->mca_component_minor_version > bb->mca_component_minor_version) { + return -1; + } else if (aa->mca_component_minor_version < bb->mca_component_minor_version) { + return 1; } return 0; } @@ -141,13 +120,12 @@ int mca_base_component_compatible( * Returns a string which represents the component name and version. * Has the form: comp_type.comp_name.major_version.minor_version */ -char * mca_base_component_to_string(const mca_base_component_t *a) { - char * str = NULL; - if(0 > opal_asprintf(&str, "%s.%s.%d.%d", a->mca_type_name, - a->mca_component_name, a->mca_component_major_version, - a->mca_component_minor_version)) { +char *mca_base_component_to_string(const mca_base_component_t *a) +{ + char *str = NULL; + if (0 > opal_asprintf(&str, "%s.%s.%d.%d", a->mca_type_name, a->mca_component_name, + a->mca_component_major_version, a->mca_component_minor_version)) { return NULL; } return str; } - diff --git a/opal/mca/base/mca_base_component_find.c b/opal/mca/base/mca_base_component_find.c index 477fd3f16c4..3f22f57a4d8 100644 --- a/opal/mca/base/mca_base_component_find.c +++ b/opal/mca/base/mca_base_component_find.c @@ -28,39 +28,39 @@ #include "opal_config.h" -#include -#include #include +#include #include +#include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_STAT_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #ifdef HAVE_NETDB_H -#include +# include #endif -#include "opal/runtime/opal.h" -#include "opal/mca/installdirs/installdirs.h" -#include "opal/util/opal_environ.h" -#include "opal/util/output.h" -#include "opal/util/argv.h" -#include "opal/util/show_help.h" #include "opal/class/opal_list.h" -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_alias.h" #include "opal/mca/base/mca_base_component_repository.h" -#include "opal/constants.h" #include "opal/mca/dl/base/base.h" +#include "opal/mca/installdirs/installdirs.h" +#include "opal/mca/mca.h" +#include "opal/runtime/opal.h" +#include "opal/util/argv.h" +#include "opal/util/opal_environ.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" #if OPAL_HAVE_DL_SUPPORT /* @@ -71,7 +71,7 @@ static void find_dyn_components(const char *path, mca_base_framework_t *framewor #endif /* OPAL_HAVE_DL_SUPPORT */ -static int component_find_check (mca_base_framework_t *framework, char **requested_component_names); +static int component_find_check(mca_base_framework_t *framework, char **requested_component_names); /* * Dummy structure for casting for open_only logic @@ -86,11 +86,8 @@ typedef struct mca_base_open_only_dummy_component_t mca_base_open_only_dummy_com static char negate[] = "^"; -static bool use_component(const mca_base_framework_t *framework, - const bool include_mode, - const char **requested_component_names, - const char *component_name); - +static bool use_component(const mca_base_framework_t *framework, const bool include_mode, + const char **requested_component_names, const char *component_name); /* * Function to find as many components of a given type as possible. This @@ -101,8 +98,8 @@ static bool use_component(const mca_base_framework_t *framework, * Return one consolidated array of (mca_base_component_t*) pointing to all * available components. */ -int mca_base_component_find (const char *directory, mca_base_framework_t *framework, - bool ignore_requested, bool open_dso_components) +int mca_base_component_find(const char *directory, mca_base_framework_t *framework, + bool ignore_requested, bool open_dso_components) { const mca_base_component_t **static_components = framework->framework_static_components; char **requested_component_names = NULL; @@ -111,8 +108,8 @@ int mca_base_component_find (const char *directory, mca_base_framework_t *framew int ret; if (!ignore_requested) { - ret = mca_base_component_parse_requested (framework->framework_selection, &include_mode, - &requested_component_names); + ret = mca_base_component_parse_requested(framework->framework_selection, &include_mode, + &requested_component_names); if (OPAL_SUCCESS != ret) { return ret; } @@ -120,10 +117,9 @@ int mca_base_component_find (const char *directory, mca_base_framework_t *framew /* Find all the components that were statically linked in */ if (static_components) { - for (int i = 0 ; NULL != static_components[i]; ++i) { - if ( use_component(framework, include_mode, - (const char**)requested_component_names, - static_components[i]->mca_component_name) ) { + for (int i = 0; NULL != static_components[i]; ++i) { + if (use_component(framework, include_mode, (const char **) requested_component_names, + static_components[i]->mca_component_name)) { cli = OBJ_NEW(mca_base_component_list_item_t); if (NULL == cli) { ret = OPAL_ERR_OUT_OF_RESOURCE; @@ -138,17 +134,17 @@ int mca_base_component_find (const char *directory, mca_base_framework_t *framew #if OPAL_HAVE_DL_SUPPORT /* Find any available dynamic components in the specified directory */ if (open_dso_components && !mca_base_component_disable_dlopen) { - find_dyn_components(directory, framework, (const char**)requested_component_names, + find_dyn_components(directory, framework, (const char **) requested_component_names, include_mode); } else { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, 0, + opal_output_verbose(MCA_BASE_VERBOSE_INFO, 0, "mca: base: component_find: dso loading for %s MCA components disabled", framework->framework_name); } #endif if (include_mode) { - ret = component_find_check (framework, requested_component_names); + ret = component_find_check(framework, requested_component_names); } else { ret = OPAL_SUCCESS; } @@ -169,7 +165,7 @@ int mca_base_component_find_finalize(void) return OPAL_SUCCESS; } -int mca_base_components_filter (mca_base_framework_t *framework, uint32_t filter_flags) +int mca_base_components_filter(mca_base_framework_t *framework, uint32_t filter_flags) { opal_list_t *components = &framework->framework_components; int output_id = framework->framework_output; @@ -178,58 +174,56 @@ int mca_base_components_filter (mca_base_framework_t *framework, uint32_t filter bool include_mode, can_use; int ret; - assert (NULL != components); + assert(NULL != components); if (0 == filter_flags && NULL == framework->framework_selection) { return OPAL_SUCCESS; } - ret = mca_base_component_parse_requested (framework->framework_selection, &include_mode, - &requested_component_names); + ret = mca_base_component_parse_requested(framework->framework_selection, &include_mode, + &requested_component_names); if (OPAL_SUCCESS != ret) { return ret; } - OPAL_LIST_FOREACH_SAFE(cli, next, components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH_SAFE (cli, next, components, mca_base_component_list_item_t) { const mca_base_component_t *component = cli->cli_component; - mca_base_open_only_dummy_component_t *dummy = - (mca_base_open_only_dummy_component_t *) cli->cli_component; + mca_base_open_only_dummy_component_t *dummy = (mca_base_open_only_dummy_component_t *) + cli->cli_component; - can_use = use_component (framework, include_mode, (const char **) requested_component_names, - cli->cli_component->mca_component_name); + can_use = use_component(framework, include_mode, (const char **) requested_component_names, + cli->cli_component->mca_component_name); if (!can_use || (filter_flags & dummy->data.param_field) != filter_flags) { - if (can_use && (filter_flags & MCA_BASE_METADATA_PARAM_CHECKPOINT) && - !(MCA_BASE_METADATA_PARAM_CHECKPOINT & dummy->data.param_field)) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_filter: " - "(%s) Component %s is *NOT* Checkpointable - Disabled", - component->reserved, - component->mca_component_name); + if (can_use && (filter_flags & MCA_BASE_METADATA_PARAM_CHECKPOINT) + && !(MCA_BASE_METADATA_PARAM_CHECKPOINT & dummy->data.param_field)) { + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_filter: " + "(%s) Component %s is *NOT* Checkpointable - Disabled", + component->reserved, component->mca_component_name); } - opal_list_remove_item (components, &cli->super); + opal_list_remove_item(components, &cli->super); - mca_base_component_unload (component, output_id); + mca_base_component_unload(component, output_id); OBJ_RELEASE(cli); } else if (filter_flags & MCA_BASE_METADATA_PARAM_CHECKPOINT) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_filter: " - "(%s) Component %s is Checkpointable", - component->reserved, - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_filter: " + "(%s) Component %s is Checkpointable", + component->reserved, component->mca_component_name); } } if (include_mode) { - ret = component_find_check (framework, requested_component_names); + ret = component_find_check(framework, requested_component_names); } else { ret = OPAL_SUCCESS; } if (NULL != requested_component_names) { - opal_argv_free (requested_component_names); + opal_argv_free(requested_component_names); } return ret; @@ -253,31 +247,30 @@ static void find_dyn_components(const char *path, mca_base_framework_t *framewor int ret; if (NULL != path) { - ret = mca_base_component_repository_add (path); + ret = mca_base_component_repository_add(path); if (OPAL_SUCCESS != ret) { return; } } - ret = mca_base_component_repository_get_components (framework, &dy_components); + ret = mca_base_component_repository_get_components(framework, &dy_components); if (OPAL_SUCCESS != ret) { return; } /* Iterate through the repository and find components that can be included */ - OPAL_LIST_FOREACH(ri, dy_components, mca_base_component_repository_item_t) { + OPAL_LIST_FOREACH (ri, dy_components, mca_base_component_repository_item_t) { if (use_component(framework, include_mode, names, ri->ri_name)) { - mca_base_component_repository_open (framework, ri); + mca_base_component_repository_open(framework, ri); } } } #endif /* OPAL_HAVE_DL_SUPPORT */ -static bool component_in_list (const char **requested_component_names, - const char *component_name) +static bool component_in_list(const char **requested_component_names, const char *component_name) { - for (int i = 0 ; requested_component_names[i] ; ++i) { + for (int i = 0; requested_component_names[i]; ++i) { if (strcmp(component_name, requested_component_names[i]) == 0) { return true; } @@ -286,10 +279,8 @@ static bool component_in_list (const char **requested_component_names, return false; } -static bool use_component(const mca_base_framework_t *framework, - const bool include_mode, - const char **requested_component_names, - const char *component_name) +static bool use_component(const mca_base_framework_t *framework, const bool include_mode, + const char **requested_component_names, const char *component_name) { /* * If no selection is specified then we use all components @@ -299,14 +290,15 @@ static bool use_component(const mca_base_framework_t *framework, return true; } - bool found = component_in_list (requested_component_names, component_name); + bool found = component_in_list(requested_component_names, component_name); if (!found) { - const mca_base_alias_t *alias = mca_base_alias_lookup (framework->framework_project, - framework->framework_name, component_name); + const mca_base_alias_t *alias = mca_base_alias_lookup(framework->framework_project, + framework->framework_name, + component_name); if (alias) { - OPAL_LIST_FOREACH_DECL(alias_item, &alias->component_aliases, mca_base_alias_item_t) { - found = component_in_list (requested_component_names, alias_item->component_alias); + OPAL_LIST_FOREACH_DECL (alias_item, &alias->component_aliases, mca_base_alias_item_t) { + found = component_in_list(requested_component_names, alias_item->component_alias); if (found) { break; } @@ -332,7 +324,7 @@ static bool use_component(const mca_base_framework_t *framework, /* Ensure that *all* requested components exist. Print a warning and abort if they do not. */ -static int component_find_check (mca_base_framework_t *framework, char **requested_component_names) +static int component_find_check(mca_base_framework_t *framework, char **requested_component_names) { opal_list_t *components = &framework->framework_components; @@ -340,21 +332,23 @@ static int component_find_check (mca_base_framework_t *framework, char **request return OPAL_SUCCESS; } - for (int i = 0 ; requested_component_names[i] ; ++i) { + for (int i = 0; requested_component_names[i]; ++i) { bool found = false; - OPAL_LIST_FOREACH_DECL(cli, components, mca_base_component_list_item_t) { - if (0 == strcmp (requested_component_names[i], cli->cli_component->mca_component_name)) { + OPAL_LIST_FOREACH_DECL (cli, components, mca_base_component_list_item_t) { + if (0 == strcmp(requested_component_names[i], cli->cli_component->mca_component_name)) { found = true; break; } - const mca_base_alias_t *alias = mca_base_alias_lookup (framework->framework_project, - framework->framework_name, - cli->cli_component->mca_component_name); + const mca_base_alias_t *alias = mca_base_alias_lookup(framework->framework_project, + framework->framework_name, + cli->cli_component + ->mca_component_name); if (alias) { - OPAL_LIST_FOREACH_DECL(alias_item, &alias->component_aliases, mca_base_alias_item_t) { - if (0 == strcmp (requested_component_names[i], alias_item->component_alias)) { + OPAL_LIST_FOREACH_DECL (alias_item, &alias->component_aliases, + mca_base_alias_item_t) { + if (0 == strcmp(requested_component_names[i], alias_item->component_alias)) { found = true; break; } @@ -368,9 +362,8 @@ static int component_find_check (mca_base_framework_t *framework, char **request if (!found) { const char *h; h = opal_gethostname(); - opal_show_help("help-mca-base.txt", - "find-available:not-valid", true, - h, framework->framework_name, requested_component_names[i]); + opal_show_help("help-mca-base.txt", "find-available:not-valid", true, h, + framework->framework_name, requested_component_names[i]); return OPAL_ERR_NOT_FOUND; } } @@ -378,8 +371,8 @@ static int component_find_check (mca_base_framework_t *framework, char **request return OPAL_SUCCESS; } -int mca_base_component_parse_requested (const char *requested, bool *include_mode, - char ***requested_component_names) +int mca_base_component_parse_requested(const char *requested, bool *include_mode, + char ***requested_component_names) { const char *requested_orig = requested; @@ -387,7 +380,7 @@ int mca_base_component_parse_requested (const char *requested, bool *include_mod *include_mode = true; /* See if the user requested anything */ - if (NULL == requested || 0 == strlen (requested)) { + if (NULL == requested || 0 == strlen(requested)) { return OPAL_SUCCESS; } @@ -397,14 +390,13 @@ int mca_base_component_parse_requested (const char *requested, bool *include_mod *include_mode = requested[0] != negate[0]; /* skip over all negate symbols at the beginning */ - requested += strspn (requested, negate); + requested += strspn(requested, negate); /* Double check to ensure that the user did not specify the negate character anywhere else in the value. */ - if (NULL != strstr (requested, negate)) { - opal_show_help("help-mca-base.txt", - "framework-param:too-many-negates", - true, requested_orig); + if (NULL != strstr(requested, negate)) { + opal_show_help("help-mca-base.txt", "framework-param:too-many-negates", true, + requested_orig); return OPAL_ERROR; } diff --git a/opal/mca/base/mca_base_component_repository.c b/opal/mca/base/mca_base_component_repository.c index 7c677ea186f..34c50d639af 100644 --- a/opal/mca/base/mca_base_component_repository.c +++ b/opal/mca/base/mca_base_component_repository.c @@ -24,28 +24,27 @@ * $HEADER$ */ - #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif -#include -#include #include +#include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif +#include "opal/class/opal_hash_table.h" #include "opal/class/opal_list.h" -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_component_repository.h" #include "opal/mca/dl/base/base.h" -#include "opal/constants.h" -#include "opal/class/opal_hash_table.h" +#include "opal/mca/mca.h" #include "opal/util/basename.h" -#include "opal/util/string_copy.h" #include "opal/util/printf.h" +#include "opal/util/string_copy.h" #if OPAL_HAVE_DL_SUPPORT @@ -54,17 +53,15 @@ */ static void ri_constructor(mca_base_component_repository_item_t *ri); static void ri_destructor(mca_base_component_repository_item_t *ri); -OBJ_CLASS_INSTANCE(mca_base_component_repository_item_t, opal_list_item_t, - ri_constructor, ri_destructor); +OBJ_CLASS_INSTANCE(mca_base_component_repository_item_t, opal_list_item_t, ri_constructor, + ri_destructor); #endif /* OPAL_HAVE_DL_SUPPORT */ static void clf_constructor(opal_object_t *obj); static void clf_destructor(opal_object_t *obj); -OBJ_CLASS_INSTANCE(mca_base_failed_component_t, opal_list_item_t, - clf_constructor, clf_destructor); - +OBJ_CLASS_INSTANCE(mca_base_failed_component_t, opal_list_item_t, clf_constructor, clf_destructor); static void clf_constructor(opal_object_t *obj) { @@ -77,7 +74,7 @@ static void clf_destructor(opal_object_t *obj) { mca_base_failed_component_t *cli = (mca_base_failed_component_t *) obj; cli->comp = NULL; - if( NULL != cli->error_msg ) { + if (NULL != cli->error_msg) { free(cli->error_msg); cli->error_msg = NULL; } @@ -88,16 +85,15 @@ static void clf_destructor(opal_object_t *obj) */ static bool initialized = false; - #if OPAL_HAVE_DL_SUPPORT static opal_hash_table_t mca_base_component_repository; /* two-level macro for stringifying a number */ -#define STRINGIFYX(x) #x -#define STRINGIFY(x) STRINGIFYX(x) +# define STRINGIFYX(x) # x +# define STRINGIFY(x) STRINGIFYX(x) -static int process_repository_item (const char *filename, void *data) +static int process_repository_item(const char *filename, void *data) { char name[MCA_BASE_MAX_COMPONENT_NAME_LEN + 1]; char type[MCA_BASE_MAX_TYPE_NAME_LEN + 1]; @@ -106,21 +102,23 @@ static int process_repository_item (const char *filename, void *data) char *base; int ret; - base = opal_basename (filename); + base = opal_basename(filename); if (NULL == base) { return OPAL_ERROR; } /* check if the plugin has the appropriate prefix */ - if (0 != strncmp (base, "mca_", 4)) { - free (base); + if (0 != strncmp(base, "mca_", 4)) { + free(base); return OPAL_SUCCESS; } /* read framework and component names. framework names may not include an _ * but component names may */ - ret = sscanf (base, "mca_%" STRINGIFY(MCA_BASE_MAX_TYPE_NAME_LEN) "[^_]_%" - STRINGIFY(MCA_BASE_MAX_COMPONENT_NAME_LEN) "s", type, name); + ret = sscanf(base, + "mca_%" STRINGIFY(MCA_BASE_MAX_TYPE_NAME_LEN) "[^_]_%" STRINGIFY( + MCA_BASE_MAX_COMPONENT_NAME_LEN) "s", + type, name); if (0 > ret) { /* does not patch the expected template. skip */ free(base); @@ -128,52 +126,52 @@ static int process_repository_item (const char *filename, void *data) } /* lookup the associated framework list and create if it doesn't already exist */ - ret = opal_hash_table_get_value_ptr (&mca_base_component_repository, type, - strlen (type), (void **) &component_list); + ret = opal_hash_table_get_value_ptr(&mca_base_component_repository, type, strlen(type), + (void **) &component_list); if (OPAL_SUCCESS != ret) { component_list = OBJ_NEW(opal_list_t); if (NULL == component_list) { - free (base); + free(base); /* OOM. nothing to do but fail */ return OPAL_ERR_OUT_OF_RESOURCE; } - ret = opal_hash_table_set_value_ptr (&mca_base_component_repository, type, - strlen (type), (void *) component_list); + ret = opal_hash_table_set_value_ptr(&mca_base_component_repository, type, strlen(type), + (void *) component_list); if (OPAL_SUCCESS != ret) { - free (base); + free(base); OBJ_RELEASE(component_list); return ret; } } /* check for duplicate components */ - OPAL_LIST_FOREACH(ri, component_list, mca_base_component_repository_item_t) { - if (0 == strcmp (ri->ri_name, name)) { + OPAL_LIST_FOREACH (ri, component_list, mca_base_component_repository_item_t) { + if (0 == strcmp(ri->ri_name, name)) { /* already scanned this component */ - free (base); + free(base); return OPAL_SUCCESS; } } ri = OBJ_NEW(mca_base_component_repository_item_t); if (NULL == ri) { - free (base); + free(base); return OPAL_ERR_OUT_OF_RESOURCE; } ri->ri_base = base; - ri->ri_path = strdup (filename); + ri->ri_path = strdup(filename); if (NULL == ri->ri_path) { OBJ_RELEASE(ri); return OPAL_ERR_OUT_OF_RESOURCE; } - opal_string_copy (ri->ri_type, type, MCA_BASE_MAX_TYPE_NAME_LEN); - opal_string_copy (ri->ri_name, name, MCA_BASE_MAX_COMPONENT_NAME_LEN); + opal_string_copy(ri->ri_type, type, MCA_BASE_MAX_TYPE_NAME_LEN); + opal_string_copy(ri->ri_name, name, MCA_BASE_MAX_COMPONENT_NAME_LEN); - opal_list_append (component_list, &ri->super); + opal_list_append(component_list, &ri->super); return OPAL_SUCCESS; } @@ -184,7 +182,7 @@ static int file_exists(const char *filename, const char *ext) int ret; if (NULL == ext) { - return access (filename, F_OK) == 0; + return access(filename, F_OK) == 0; } ret = opal_asprintf(&final, "%s.%s", filename, ext); @@ -192,14 +190,14 @@ static int file_exists(const char *filename, const char *ext) return 0; } - ret = access (final, F_OK); + ret = access(final, F_OK); free(final); return (0 == ret); } #endif /* OPAL_HAVE_DL_SUPPORT */ -int mca_base_component_repository_add (const char *path) +int mca_base_component_repository_add(const char *path) { #if OPAL_HAVE_DL_SUPPORT char *path_to_use = NULL, *dir, *ctx; @@ -210,92 +208,94 @@ int mca_base_component_repository_add (const char *path) return OPAL_SUCCESS; } - path_to_use = strdup (path); + path_to_use = strdup(path); - dir = strtok_r (path_to_use, sep, &ctx); + dir = strtok_r(path_to_use, sep, &ctx); do { if ((0 == strcmp(dir, "USER_DEFAULT") || 0 == strcmp(dir, "USR_DEFAULT")) && NULL != mca_base_user_default_path) { dir = mca_base_user_default_path; - } else if (0 == strcmp(dir, "SYS_DEFAULT") || - 0 == strcmp(dir, "SYSTEM_DEFAULT")) { + } else if (0 == strcmp(dir, "SYS_DEFAULT") || 0 == strcmp(dir, "SYSTEM_DEFAULT")) { dir = mca_base_system_default_path; } if (0 != opal_dl_foreachfile(dir, process_repository_item, NULL)) { break; } - } while (NULL != (dir = strtok_r (NULL, sep, &ctx))); + } while (NULL != (dir = strtok_r(NULL, sep, &ctx))); - free (path_to_use); + free(path_to_use); #endif /* OPAL_HAVE_DL_SUPPORT */ return OPAL_SUCCESS; } - /* * Initialize the repository */ int mca_base_component_repository_init(void) { - /* Setup internal structures */ + /* Setup internal structures */ - if (!initialized) { + if (!initialized) { #if OPAL_HAVE_DL_SUPPORT - /* Initialize the dl framework */ - int ret = mca_base_framework_open(&opal_dl_base_framework, 0); - if (OPAL_SUCCESS != ret) { - opal_output(0, "%s %d:%s failed -- process will likely abort (open the dl framework returned %d instead of OPAL_SUCCESS)\n", - __FILE__, __LINE__, __func__, ret); - return ret; - } - opal_dl_base_select(); + /* Initialize the dl framework */ + int ret = mca_base_framework_open(&opal_dl_base_framework, 0); + if (OPAL_SUCCESS != ret) { + opal_output(0, + "%s %d:%s failed -- process will likely abort (open the dl framework " + "returned %d instead of OPAL_SUCCESS)\n", + __FILE__, __LINE__, __func__, ret); + return ret; + } + opal_dl_base_select(); - OBJ_CONSTRUCT(&mca_base_component_repository, opal_hash_table_t); - ret = opal_hash_table_init (&mca_base_component_repository, 128); - if (OPAL_SUCCESS != ret) { - (void) mca_base_framework_close (&opal_dl_base_framework); - return ret; - } + OBJ_CONSTRUCT(&mca_base_component_repository, opal_hash_table_t); + ret = opal_hash_table_init(&mca_base_component_repository, 128); + if (OPAL_SUCCESS != ret) { + (void) mca_base_framework_close(&opal_dl_base_framework); + return ret; + } - ret = mca_base_component_repository_add (mca_base_component_path); - if (OPAL_SUCCESS != ret) { - OBJ_DESTRUCT(&mca_base_component_repository); - (void) mca_base_framework_close (&opal_dl_base_framework); - return ret; - } + ret = mca_base_component_repository_add(mca_base_component_path); + if (OPAL_SUCCESS != ret) { + OBJ_DESTRUCT(&mca_base_component_repository); + (void) mca_base_framework_close(&opal_dl_base_framework); + return ret; + } #endif - initialized = true; - } + initialized = true; + } - /* All done */ + /* All done */ - return OPAL_SUCCESS; + return OPAL_SUCCESS; } -int mca_base_component_repository_get_components (mca_base_framework_t *framework, - opal_list_t **framework_components) +int mca_base_component_repository_get_components(mca_base_framework_t *framework, + opal_list_t **framework_components) { *framework_components = NULL; #if OPAL_HAVE_DL_SUPPORT - return opal_hash_table_get_value_ptr (&mca_base_component_repository, framework->framework_name, - strlen (framework->framework_name), (void **) framework_components); + return opal_hash_table_get_value_ptr(&mca_base_component_repository, framework->framework_name, + strlen(framework->framework_name), + (void **) framework_components); #endif return OPAL_ERR_NOT_FOUND; } #if OPAL_HAVE_DL_SUPPORT -static void mca_base_component_repository_release_internal (mca_base_component_repository_item_t *ri) { +static void mca_base_component_repository_release_internal(mca_base_component_repository_item_t *ri) +{ int group_id; - group_id = mca_base_var_group_find (NULL, ri->ri_type, ri->ri_name); + group_id = mca_base_var_group_find(NULL, ri->ri_type, ri->ri_name); if (0 <= group_id) { /* ensure all variables are deregistered before we dlclose the component */ - mca_base_var_group_deregister (group_id); + mca_base_var_group_deregister(group_id); } /* Close the component (and potentially unload it from memory */ @@ -307,21 +307,21 @@ static void mca_base_component_repository_release_internal (mca_base_component_r #endif #if OPAL_HAVE_DL_SUPPORT -static mca_base_component_repository_item_t *find_component (const char *type, const char *name) +static mca_base_component_repository_item_t *find_component(const char *type, const char *name) { mca_base_component_repository_item_t *ri; opal_list_t *component_list; int ret; - ret = opal_hash_table_get_value_ptr (&mca_base_component_repository, type, - strlen (type), (void **) &component_list); + ret = opal_hash_table_get_value_ptr(&mca_base_component_repository, type, strlen(type), + (void **) &component_list); if (OPAL_SUCCESS != ret) { /* component does not exist in the repository */ return NULL; } - OPAL_LIST_FOREACH(ri, component_list, mca_base_component_repository_item_t) { - if (0 == strcmp (ri->ri_name, name)) { + OPAL_LIST_FOREACH (ri, component_list, mca_base_component_repository_item_t) { + if (0 == strcmp(ri->ri_name, name)) { return ri; } } @@ -335,14 +335,14 @@ void mca_base_component_repository_release(const mca_base_component_t *component #if OPAL_HAVE_DL_SUPPORT mca_base_component_repository_item_t *ri; - ri = find_component (component->mca_type_name, component->mca_component_name); + ri = find_component(component->mca_type_name, component->mca_component_name); if (NULL != ri && !(--ri->ri_refcnt)) { - mca_base_component_repository_release_internal (ri); + mca_base_component_repository_release_internal(ri); } #endif } -int mca_base_component_repository_retain_component (const char *type, const char *name) +int mca_base_component_repository_retain_component(const char *type, const char *name) { #if OPAL_HAVE_DL_SUPPORT mca_base_component_repository_item_t *ri = find_component(type, name); @@ -358,8 +358,8 @@ int mca_base_component_repository_retain_component (const char *type, const char #endif } -int mca_base_component_repository_open (mca_base_framework_t *framework, - mca_base_component_repository_item_t *ri) +int mca_base_component_repository_open(mca_base_framework_t *framework, + mca_base_component_repository_item_t *ri) { #if OPAL_HAVE_DL_SUPPORT mca_base_component_t *component_struct; @@ -367,8 +367,10 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, char *struct_name = NULL; int vl, ret; - opal_output_verbose(MCA_BASE_VERBOSE_INFO, 0, "mca_base_component_repository_open: examining dynamic " - "%s MCA component \"%s\" at path %s", ri->ri_type, ri->ri_name, ri->ri_path); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, 0, + "mca_base_component_repository_open: examining dynamic " + "%s MCA component \"%s\" at path %s", + ri->ri_type, ri->ri_name, ri->ri_path); vl = mca_base_component_show_load_errors ? MCA_BASE_VERBOSE_ERROR : MCA_BASE_VERBOSE_INFO; @@ -378,9 +380,10 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, Hence, returning OPAL_ERR_PARAM indicates that the *file* failed to load, not the component. */ - OPAL_LIST_FOREACH(mitem, &framework->framework_components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH (mitem, &framework->framework_components, mca_base_component_list_item_t) { if (0 == strcmp(mitem->cli_component->mca_component_name, ri->ri_name)) { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, 0, "mca_base_component_repository_open: already loaded (ignored)"); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, 0, + "mca_base_component_repository_open: already loaded (ignored)"); return OPAL_ERR_BAD_PARAM; } } @@ -389,23 +392,25 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, mitem = NULL; if (NULL != ri->ri_dlhandle) { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, 0, "mca_base_component_repository_open: already loaded. returning cached component"); + opal_output_verbose( + MCA_BASE_VERBOSE_INFO, 0, + "mca_base_component_repository_open: already loaded. returning cached component"); mitem = OBJ_NEW(mca_base_component_list_item_t); if (NULL == mitem) { return OPAL_ERR_OUT_OF_RESOURCE; } mitem->cli_component = ri->ri_component_struct; - opal_list_append (&framework->framework_components, &mitem->super); + opal_list_append(&framework->framework_components, &mitem->super); return OPAL_SUCCESS; } - if (0 != strcmp (ri->ri_type, framework->framework_name)) { + if (0 != strcmp(ri->ri_type, framework->framework_name)) { /* shouldn't happen. attempting to open a component belonging to * another framework. if this happens it is likely a MCA base * bug so assert */ - assert (0); + assert(0); return OPAL_ERR_NOT_SUPPORTED; } @@ -422,17 +427,16 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, (e.g., missing symbol) -- do some simple huersitics and if the file [probably] does exist, print a slightly better error message. */ - if (0 == strcasecmp("file not found", err_msg) && - (file_exists(ri->ri_path, "lo") || - file_exists(ri->ri_path, "so") || - file_exists(ri->ri_path, "dylib") || - file_exists(ri->ri_path, "dll"))) { + if (0 == strcasecmp("file not found", err_msg) + && (file_exists(ri->ri_path, "lo") || file_exists(ri->ri_path, "so") + || file_exists(ri->ri_path, "dylib") || file_exists(ri->ri_path, "dll"))) { err_msg = "perhaps a missing symbol, or compiled for a different version of Open MPI?"; } - opal_output_verbose(vl, 0, "mca_base_component_repository_open: unable to open %s: %s (ignored)", + opal_output_verbose(vl, 0, + "mca_base_component_repository_open: unable to open %s: %s (ignored)", ri->ri_base, err_msg); - if( mca_base_component_track_load_errors ) { + if (mca_base_component_track_load_errors) { mca_base_failed_component_t *f_comp = OBJ_NEW(mca_base_failed_component_t); f_comp->comp = ri; opal_asprintf(&(f_comp->error_msg), "%s", err_msg); @@ -446,7 +450,7 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, Malloc out enough space for it. */ do { - ret = opal_asprintf (&struct_name, "mca_%s_%s_component", ri->ri_type, ri->ri_name); + ret = opal_asprintf(&struct_name, "mca_%s_%s_component", ri->ri_type, ri->ri_name); if (0 > ret) { ret = OPAL_ERR_OUT_OF_RESOURCE; break; @@ -459,43 +463,49 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, } err_msg = NULL; - ret = opal_dl_lookup(ri->ri_dlhandle, struct_name, (void**) &component_struct, &err_msg); + ret = opal_dl_lookup(ri->ri_dlhandle, struct_name, (void **) &component_struct, &err_msg); if (OPAL_SUCCESS != ret || NULL == component_struct) { if (NULL == err_msg) { err_msg = "opal_dl_loookup() error message was NULL!"; } - opal_output_verbose(vl, 0, "mca_base_component_repository_open: \"%s\" does not appear to be a valid " - "%s MCA dynamic component (ignored): %s. ret %d", ri->ri_base, ri->ri_type, err_msg, ret); + opal_output_verbose( + vl, 0, + "mca_base_component_repository_open: \"%s\" does not appear to be a valid " + "%s MCA dynamic component (ignored): %s. ret %d", + ri->ri_base, ri->ri_type, err_msg, ret); ret = OPAL_ERR_BAD_PARAM; break; } /* done with the structure name */ - free (struct_name); + free(struct_name); struct_name = NULL; /* We found the public struct. Make sure its MCA major.minor version is the same as ours. TODO -- add checks for project version (from framework) */ - if (!(MCA_BASE_VERSION_MAJOR == component_struct->mca_major_version && - MCA_BASE_VERSION_MINOR == component_struct->mca_minor_version)) { - opal_output_verbose(vl, 0, "mca_base_component_repository_open: %s \"%s\" uses an MCA interface that is " - "not recognized (component MCA v%d.%d.%d != supported MCA v%d.%d.%d) -- ignored", - ri->ri_type, ri->ri_path, component_struct->mca_major_version, - component_struct->mca_minor_version, component_struct->mca_release_version, - MCA_BASE_VERSION_MAJOR, MCA_BASE_VERSION_MINOR, MCA_BASE_VERSION_RELEASE); + if (!(MCA_BASE_VERSION_MAJOR == component_struct->mca_major_version + && MCA_BASE_VERSION_MINOR == component_struct->mca_minor_version)) { + opal_output_verbose( + vl, 0, + "mca_base_component_repository_open: %s \"%s\" uses an MCA interface that is " + "not recognized (component MCA v%d.%d.%d != supported MCA v%d.%d.%d) -- ignored", + ri->ri_type, ri->ri_path, component_struct->mca_major_version, + component_struct->mca_minor_version, component_struct->mca_release_version, + MCA_BASE_VERSION_MAJOR, MCA_BASE_VERSION_MINOR, MCA_BASE_VERSION_RELEASE); ret = OPAL_ERR_BAD_PARAM; break; } /* Also check that the component struct framework and component names match the expected names from the filename */ - if (0 != strcmp(component_struct->mca_type_name, ri->ri_type) || - 0 != strcmp(component_struct->mca_component_name, ri->ri_name)) { - opal_output_verbose(vl, 0, "Component file data does not match filename: %s (%s / %s) != %s %s -- ignored", - ri->ri_path, ri->ri_type, ri->ri_name, - component_struct->mca_type_name, - component_struct->mca_component_name); + if (0 != strcmp(component_struct->mca_type_name, ri->ri_type) + || 0 != strcmp(component_struct->mca_component_name, ri->ri_name)) { + opal_output_verbose( + vl, 0, + "Component file data does not match filename: %s (%s / %s) != %s %s -- ignored", + ri->ri_path, ri->ri_type, ri->ri_name, component_struct->mca_type_name, + component_struct->mca_component_name); ret = OPAL_ERR_BAD_PARAM; break; } @@ -507,8 +517,10 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, ri->ri_refcnt = 1; opal_list_append(&framework->framework_components, &mitem->super); - opal_output_verbose (MCA_BASE_VERBOSE_INFO, 0, "mca_base_component_repository_open: opened dynamic %s MCA " - "component \"%s\"", ri->ri_type, ri->ri_name); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, 0, + "mca_base_component_repository_open: opened dynamic %s MCA " + "component \"%s\"", + ri->ri_type, ri->ri_name); return OPAL_SUCCESS; } while (0); @@ -518,10 +530,10 @@ int mca_base_component_repository_open (mca_base_framework_t *framework, } if (struct_name) { - free (struct_name); + free(struct_name); } - opal_dl_close (ri->ri_dlhandle); + opal_dl_close(ri->ri_dlhandle); ri->ri_dlhandle = NULL; return ret; @@ -549,13 +561,12 @@ void mca_base_component_repository_finalize(void) size_t key_size; int ret; - ret = opal_hash_table_get_first_key_ptr (&mca_base_component_repository, &key, &key_size, - (void **) &component_list, &node); + ret = opal_hash_table_get_first_key_ptr(&mca_base_component_repository, &key, &key_size, + (void **) &component_list, &node); while (OPAL_SUCCESS == ret) { OPAL_LIST_RELEASE(component_list); - ret = opal_hash_table_get_next_key_ptr (&mca_base_component_repository, &key, - &key_size, (void **) &component_list, - node, &node); + ret = opal_hash_table_get_next_key_ptr(&mca_base_component_repository, &key, &key_size, + (void **) &component_list, node, &node); } (void) mca_base_framework_close(&opal_dl_base_framework); @@ -568,7 +579,7 @@ void mca_base_component_repository_finalize(void) /* * Basic sentinel values, and construct the inner list */ -static void ri_constructor (mca_base_component_repository_item_t *ri) +static void ri_constructor(mca_base_component_repository_item_t *ri) { memset(ri->ri_type, 0, sizeof(ri->ri_type)); ri->ri_dlhandle = NULL; @@ -576,14 +587,13 @@ static void ri_constructor (mca_base_component_repository_item_t *ri) ri->ri_path = NULL; } - /* * Close a component */ -static void ri_destructor (mca_base_component_repository_item_t *ri) +static void ri_destructor(mca_base_component_repository_item_t *ri) { /* dlclose the component if it is still open */ - mca_base_component_repository_release_internal (ri); + mca_base_component_repository_release_internal(ri); /* It should be obvious, but I'll state it anyway because it bit me during debugging: after the dlclose(), the mca_base_component_t @@ -591,11 +601,11 @@ static void ri_destructor (mca_base_component_repository_item_t *ri) unloaded from memory. So don't try to use it. :-) */ if (ri->ri_path) { - free (ri->ri_path); + free(ri->ri_path); } if (ri->ri_base) { - free (ri->ri_base); + free(ri->ri_base); } } diff --git a/opal/mca/base/mca_base_component_repository.h b/opal/mca/base/mca_base_component_repository.h index 08babe70511..66822edcb43 100644 --- a/opal/mca/base/mca_base_component_repository.h +++ b/opal/mca/base/mca_base_component_repository.h @@ -39,8 +39,8 @@ #include "opal_config.h" -#include "opal/mca/dl/dl.h" #include "opal/mca/dl/base/base.h" +#include "opal/mca/dl/dl.h" BEGIN_C_DECLS struct mca_base_component_repository_item_t { @@ -88,8 +88,7 @@ OPAL_DECLSPEC int mca_base_component_repository_init(void); * * @param[in] path delimited list of search paths to add */ -OPAL_DECLSPEC int mca_base_component_repository_add (const char *path); - +OPAL_DECLSPEC int mca_base_component_repository_add(const char *path); /** * @brief return the list of components that match a given framework @@ -100,8 +99,8 @@ OPAL_DECLSPEC int mca_base_component_repository_add (const char *path); * The list returned in {framework_components} is owned by the component * repository and CAN NOT be modified by the caller. */ -OPAL_DECLSPEC int mca_base_component_repository_get_components (mca_base_framework_t *framework, - opal_list_t **framework_components); +OPAL_DECLSPEC int mca_base_component_repository_get_components(mca_base_framework_t *framework, + opal_list_t **framework_components); /** * @brief finalize the mca component repository @@ -115,14 +114,13 @@ OPAL_DECLSPEC void mca_base_component_repository_finalize(void); * @param[in] framework framework that matches the component * @param[in] ri dynamic component to open */ -int mca_base_component_repository_open (mca_base_framework_t *framework, - mca_base_component_repository_item_t *ri); - +int mca_base_component_repository_open(mca_base_framework_t *framework, + mca_base_component_repository_item_t *ri); /** * @brief Reduce the reference count of a component and dlclose it if necessary */ -void mca_base_component_repository_release (const mca_base_component_t *component); +void mca_base_component_repository_release(const mca_base_component_t *component); /** * @brief Increase the reference count of a component @@ -137,7 +135,7 @@ void mca_base_component_repository_release (const mca_base_component_t *componen * @note all components are automatically unloaded by the * mca_base_component_repository_finalize() call. */ -int mca_base_component_repository_retain_component (const char *type, const char *name); +int mca_base_component_repository_retain_component(const char *type, const char *name); END_C_DECLS diff --git a/opal/mca/base/mca_base_components_close.c b/opal/mca/base/mca_base_components_close.c index 0239df3b61e..9dbb24cf296 100644 --- a/opal/mca/base/mca_base_components_close.c +++ b/opal/mca/base/mca_base_components_close.c @@ -22,55 +22,53 @@ #include "opal_config.h" #include "opal/class/opal_list.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_component_repository.h" -#include "opal/constants.h" +#include "opal/mca/mca.h" +#include "opal/util/output.h" -void mca_base_component_unload (const mca_base_component_t *component, int output_id) +void mca_base_component_unload(const mca_base_component_t *component, int output_id) { int ret; /* Unload */ - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: close: unloading component %s", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: close: unloading component %s", component->mca_component_name); - ret = mca_base_var_group_find (component->mca_project_name, component->mca_type_name, - component->mca_component_name); + ret = mca_base_var_group_find(component->mca_project_name, component->mca_type_name, + component->mca_component_name); if (0 <= ret) { - mca_base_var_group_deregister (ret); + mca_base_var_group_deregister(ret); } - mca_base_component_repository_release (component); + mca_base_component_repository_release(component); } -void mca_base_component_close (const mca_base_component_t *component, int output_id) +void mca_base_component_close(const mca_base_component_t *component, int output_id) { /* Close */ if (NULL != component->mca_close_component) { - if( OPAL_SUCCESS == component->mca_close_component() ) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: close: component %s closed", - component->mca_component_name); + if (OPAL_SUCCESS == component->mca_close_component()) { + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: close: component %s closed", + component->mca_component_name); } else { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: close: component %s refused to close [drop it]", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: close: component %s refused to close [drop it]", + component->mca_component_name); return; } } - mca_base_component_unload (component, output_id); + mca_base_component_unload(component, output_id); } -int mca_base_framework_components_close (mca_base_framework_t *framework, - const mca_base_component_t *skip) +int mca_base_framework_components_close(mca_base_framework_t *framework, + const mca_base_component_t *skip) { - return mca_base_components_close (framework->framework_output, - &framework->framework_components, - skip); + return mca_base_components_close(framework->framework_output, &framework->framework_components, + skip); } int mca_base_components_close(int output_id, opal_list_t *components, @@ -83,13 +81,13 @@ int mca_base_components_close(int output_id, opal_list_t *components, components. It's easier to simply remove the entire list and then simply re-add the skip entry when done. */ - OPAL_LIST_FOREACH_SAFE(cli, next, components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH_SAFE (cli, next, components, mca_base_component_list_item_t) { if (skip == cli->cli_component) { continue; } - mca_base_component_close (cli->cli_component, output_id); - opal_list_remove_item (components, &cli->super); + mca_base_component_close(cli->cli_component, output_id); + opal_list_remove_item(components, &cli->super); OBJ_RELEASE(cli); } diff --git a/opal/mca/base/mca_base_components_open.c b/opal/mca/base/mca_base_components_open.c index b18540d2068..ffad7caaa3c 100644 --- a/opal/mca/base/mca_base_components_open.c +++ b/opal/mca/base/mca_base_components_open.c @@ -24,15 +24,15 @@ #include "opal_config.h" #include -#include #include +#include #include "opal/class/opal_list.h" +#include "opal/constants.h" +#include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/util/argv.h" #include "opal/util/output.h" -#include "opal/mca/mca.h" -#include "opal/mca/base/base.h" -#include "opal/constants.h" /* * Local functions @@ -48,8 +48,7 @@ struct mca_base_dummy_framework_list_item_t { * Function for finding and opening either all MCA components, or the * one that was specifically requested via a MCA parameter. */ -int mca_base_framework_components_open (mca_base_framework_t *framework, - mca_base_open_flag_t flags) +int mca_base_framework_components_open(mca_base_framework_t *framework, mca_base_open_flag_t flags) { /* Open flags are not used at this time. Suppress compiler warning. */ if (flags & MCA_BASE_OPEN_FIND_COMPONENTS) { @@ -62,7 +61,7 @@ int mca_base_framework_components_open (mca_base_framework_t *framework, } /* Open all registered components */ - return open_components (framework); + return open_components(framework); } /* @@ -95,64 +94,65 @@ static int open_components(mca_base_framework_t *framework) /* If mca_base_framework_register_components was called with the MCA_BASE_COMPONENTS_ALL flag we need to trim down and close any extra components we do not want open */ - ret = mca_base_components_filter (framework, open_only_flags); + ret = mca_base_components_filter(framework, open_only_flags); if (OPAL_SUCCESS != ret) { return ret; } /* Announce */ - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, "mca: base: components_open: opening %s components", - framework->framework_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_open: opening %s components", + framework->framework_name); /* Traverse the list of components */ - OPAL_LIST_FOREACH_SAFE(cli, next, components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH_SAFE (cli, next, components, mca_base_component_list_item_t) { const mca_base_component_t *component = cli->cli_component; - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_open: found loaded component %s", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_open: found loaded component %s", + component->mca_component_name); - if (NULL != component->mca_open_component) { - /* Call open if register didn't call it already */ + if (NULL != component->mca_open_component) { + /* Call open if register didn't call it already */ ret = component->mca_open_component(); if (OPAL_SUCCESS == ret) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_open: " - "component %s open function successful", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_open: " + "component %s open function successful", + component->mca_component_name); } else { - if (OPAL_ERR_NOT_AVAILABLE != ret) { - /* If the component returns OPAL_ERR_NOT_AVAILABLE, - it's a cue to "silently ignore me" -- it's not a - failure, it's just a way for the component to say - "nope!". - - Otherwise, however, display an error. We may end - up displaying this twice, but it may go to separate - streams. So better to be redundant than to not - display the error in the stream where it was - expected. */ - - if (mca_base_component_show_load_errors) { - opal_output_verbose (MCA_BASE_VERBOSE_ERROR, output_id, - "mca: base: components_open: component %s " - "/ %s open function failed", - component->mca_type_name, - component->mca_component_name); - } - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_open: " - "component %s open function failed", - component->mca_component_name); - } - - mca_base_component_close (component, output_id); - - opal_list_remove_item (components, &cli->super); - OBJ_RELEASE(cli); - } - } + if (OPAL_ERR_NOT_AVAILABLE != ret) { + /* If the component returns OPAL_ERR_NOT_AVAILABLE, + it's a cue to "silently ignore me" -- it's not a + failure, it's just a way for the component to say + "nope!". + + Otherwise, however, display an error. We may end + up displaying this twice, but it may go to separate + streams. So better to be redundant than to not + display the error in the stream where it was + expected. */ + + if (mca_base_component_show_load_errors) { + opal_output_verbose(MCA_BASE_VERBOSE_ERROR, output_id, + "mca: base: components_open: component %s " + "/ %s open function failed", + component->mca_type_name, + component->mca_component_name); + } + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_open: " + "component %s open function failed", + component->mca_component_name); + } + + mca_base_component_close(component, output_id); + + opal_list_remove_item(components, &cli->super); + OBJ_RELEASE(cli); + } + } } /* All done */ diff --git a/opal/mca/base/mca_base_components_register.c b/opal/mca/base/mca_base_components_register.c index 1598a533030..eb40c7e5197 100644 --- a/opal/mca/base/mca_base_components_register.c +++ b/opal/mca/base/mca_base_components_register.c @@ -23,18 +23,18 @@ #include "opal_config.h" #include -#include #include +#include #include "opal/class/opal_list.h" +#include "opal/constants.h" +#include "opal/mca/base/base.h" +#include "opal/mca/base/mca_base_component_repository.h" +#include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/mca.h" #include "opal/util/argv.h" #include "opal/util/output.h" #include "opal/util/show_help.h" -#include "opal/mca/mca.h" -#include "opal/mca/base/base.h" -#include "opal/mca/base/mca_base_framework.h" -#include "opal/mca/base/mca_base_component_repository.h" -#include "opal/constants.h" /* * Local functions @@ -44,8 +44,8 @@ static int register_components(mca_base_framework_t *framework); * Function for finding and opening either all MCA components, or the * one that was specifically requested via a MCA parameter. */ -int mca_base_framework_components_register (mca_base_framework_t *framework, - mca_base_register_flag_t flags) +int mca_base_framework_components_register(mca_base_framework_t *framework, + mca_base_register_flag_t flags) { bool open_dso_components = !(flags & MCA_BASE_REGISTER_STATIC_ONLY); bool ignore_requested = !!(flags & MCA_BASE_REGISTER_ALL); @@ -76,25 +76,27 @@ static int register_components(mca_base_framework_t *framework) int output_id = framework->framework_output; /* Announce */ - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_register: registering framework %s components", - framework->framework_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_register: registering framework %s components", + framework->framework_name); /* Traverse the list of found components */ - OPAL_LIST_FOREACH_SAFE(cli, next, &framework->framework_components, mca_base_component_list_item_t) { - component = (mca_base_component_t *)cli->cli_component; + OPAL_LIST_FOREACH_SAFE (cli, next, &framework->framework_components, + mca_base_component_list_item_t) { + component = (mca_base_component_t *) cli->cli_component; opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, "mca: base: components_register: found loaded component %s", component->mca_component_name); - /* Call the component's MCA parameter registration function (or open if register doesn't exist) */ + /* Call the component's MCA parameter registration function (or open if register doesn't + * exist) */ if (NULL == component->mca_register_component_params) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_register: " - "component %s has no register or open function", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_register: " + "component %s has no register or open function", + component->mca_component_name); ret = OPAL_SUCCESS; } else { ret = component->mca_register_component_params(); @@ -114,20 +116,19 @@ static int register_components(mca_base_framework_t *framework) expected. */ if (mca_base_component_show_load_errors) { - opal_output_verbose (MCA_BASE_VERBOSE_ERROR, output_id, - "mca: base: components_register: component %s " - "/ %s register function failed", - component->mca_type_name, - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_ERROR, output_id, + "mca: base: components_register: component %s " + "/ %s register function failed", + component->mca_type_name, component->mca_component_name); } - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca: base: components_register: " - "component %s register function failed", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_register: " + "component %s register function failed", + component->mca_component_name); } - opal_list_remove_item (&framework->framework_components, &cli->super); + opal_list_remove_item(&framework->framework_components, &cli->super); /* Release this list item */ OBJ_RELEASE(cli); @@ -135,24 +136,28 @@ static int register_components(mca_base_framework_t *framework) } if (NULL != component->mca_register_component_params) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, "mca: base: components_register: " - "component %s register function successful", - component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca: base: components_register: " + "component %s register function successful", + component->mca_component_name); } /* Register this component's version */ - mca_base_component_var_register (component, "major_version", NULL, MCA_BASE_VAR_TYPE_INT, NULL, - 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY | MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_CONSTANT, - &component->mca_component_major_version); - mca_base_component_var_register (component, "minor_version", NULL, MCA_BASE_VAR_TYPE_INT, NULL, - 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY | MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_CONSTANT, - &component->mca_component_minor_version); - mca_base_component_var_register (component, "release_version", NULL, MCA_BASE_VAR_TYPE_INT, NULL, - 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY | MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_CONSTANT, - &component->mca_component_release_version); + mca_base_component_var_register(component, "major_version", NULL, MCA_BASE_VAR_TYPE_INT, + NULL, 0, + MCA_BASE_VAR_FLAG_DEFAULT_ONLY | MCA_BASE_VAR_FLAG_INTERNAL, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_CONSTANT, + &component->mca_component_major_version); + mca_base_component_var_register(component, "minor_version", NULL, MCA_BASE_VAR_TYPE_INT, + NULL, 0, + MCA_BASE_VAR_FLAG_DEFAULT_ONLY | MCA_BASE_VAR_FLAG_INTERNAL, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_CONSTANT, + &component->mca_component_minor_version); + mca_base_component_var_register(component, "release_version", NULL, MCA_BASE_VAR_TYPE_INT, + NULL, 0, + MCA_BASE_VAR_FLAG_DEFAULT_ONLY | MCA_BASE_VAR_FLAG_INTERNAL, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_CONSTANT, + &component->mca_component_release_version); } /* All done */ diff --git a/opal/mca/base/mca_base_components_select.c b/opal/mca/base/mca_base_components_select.c index cf45bf903ec..d2bc2d22af5 100644 --- a/opal/mca/base/mca_base_components_select.c +++ b/opal/mca/base/mca_base_components_select.c @@ -16,25 +16,22 @@ #include "opal_config.h" #include -#include #include +#include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif -#include "opal/runtime/opal.h" #include "opal/class/opal_list.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_component_repository.h" -#include "opal/constants.h" - +#include "opal/mca/mca.h" +#include "opal/runtime/opal.h" +#include "opal/util/output.h" -int mca_base_select(const char *type_name, int output_id, - opal_list_t *components_available, - mca_base_module_t **best_module, - mca_base_component_t **best_component, +int mca_base_select(const char *type_name, int output_id, opal_list_t *components_available, + mca_base_module_t **best_module, mca_base_component_t **best_component, int *priority_out) { mca_base_component_list_item_t *cli = NULL; @@ -46,33 +43,33 @@ int mca_base_select(const char *type_name, int output_id, *best_module = NULL; *best_component = NULL; - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select: Auto-selecting %s components", - type_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select: Auto-selecting %s components", type_name); /* * Traverse the list of available components. * For each call their 'query' functions to determine relative priority. */ - OPAL_LIST_FOREACH(cli, components_available, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH (cli, components_available, mca_base_component_list_item_t) { component = (mca_base_component_t *) cli->cli_component; /* * If there is a query function then use it. */ if (NULL == component->mca_query_component) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select:(%5s) Skipping component [%s]. It does not implement a query function", - type_name, component->mca_component_name ); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select:(%5s) Skipping component [%s]. It does not " + "implement a query function", + type_name, component->mca_component_name); continue; } /* * Query this component for the module and priority */ - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select:(%5s) Querying component [%s]", - type_name, component->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select:(%5s) Querying component [%s]", type_name, + component->mca_component_name); rc = component->mca_query_component(&module, &priority); if (OPAL_ERR_FATAL == rc) { @@ -81,7 +78,7 @@ int mca_base_select(const char *type_name, int output_id, * not find it. In this case, we must not continue as we might * find some other component that could run, causing us to do * something the user didn't want */ - return rc; + return rc; } else if (OPAL_SUCCESS != rc) { /* silently skip this component */ continue; @@ -91,22 +88,23 @@ int mca_base_select(const char *type_name, int output_id, * If no module was returned, then skip component */ if (NULL == module) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select:(%5s) Skipping component [%s]. Query failed to return a module", - type_name, component->mca_component_name ); + opal_output_verbose( + MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select:(%5s) Skipping component [%s]. Query failed to return a module", + type_name, component->mca_component_name); continue; } /* * Determine if this is the best module we have seen by looking the priority */ - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select:(%5s) Query of component [%s] set priority to %d", - type_name, component->mca_component_name, priority); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select:(%5s) Query of component [%s] set priority to %d", + type_name, component->mca_component_name, priority); if (priority > best_priority) { - best_priority = priority; + best_priority = priority; *best_component = component; - *best_module = module; + *best_module = module; } } @@ -119,29 +117,25 @@ int mca_base_select(const char *type_name, int output_id, * Make sure we found something in the process. */ if (NULL == *best_component) { - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select:(%5s) No component selected!", - type_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select:(%5s) No component selected!", type_name); /* * Still close the non-selected components */ mca_base_components_close(0, /* Pass 0 to keep this from closing the output handle */ - components_available, - NULL); + components_available, NULL); return OPAL_ERR_NOT_FOUND; } - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, - "mca:base:select:(%5s) Selected component [%s]", - type_name, (*best_component)->mca_component_name); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, output_id, + "mca:base:select:(%5s) Selected component [%s]", type_name, + (*best_component)->mca_component_name); /* * Close the non-selected components */ - mca_base_components_close(output_id, - components_available, + mca_base_components_close(output_id, components_available, (mca_base_component_t *) (*best_component)); - return OPAL_SUCCESS; } diff --git a/opal/mca/base/mca_base_framework.c b/opal/mca/base/mca_base_framework.c index 54edc9b552c..a91260fb9f7 100644 --- a/opal/mca/base/mca_base_framework.c +++ b/opal/mca/base/mca_base_framework.c @@ -24,49 +24,48 @@ #include "mca_base_var.h" #include "opal/mca/base/base.h" -bool mca_base_framework_is_registered (struct mca_base_framework_t *framework) +bool mca_base_framework_is_registered(struct mca_base_framework_t *framework) { return !!(framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_REGISTERED); } -bool mca_base_framework_is_open (struct mca_base_framework_t *framework) +bool mca_base_framework_is_open(struct mca_base_framework_t *framework) { return !!(framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_OPEN); } -static void framework_open_output (struct mca_base_framework_t *framework) +static void framework_open_output(struct mca_base_framework_t *framework) { if (0 < framework->framework_verbose) { if (-1 == framework->framework_output) { - framework->framework_output = opal_output_open (NULL); + framework->framework_output = opal_output_open(NULL); } - opal_output_set_verbosity(framework->framework_output, - framework->framework_verbose); + opal_output_set_verbosity(framework->framework_output, framework->framework_verbose); } else if (-1 != framework->framework_output) { - opal_output_close (framework->framework_output); + opal_output_close(framework->framework_output); framework->framework_output = -1; } } -static void framework_close_output (struct mca_base_framework_t *framework) +static void framework_close_output(struct mca_base_framework_t *framework) { if (-1 != framework->framework_output) { - opal_output_close (framework->framework_output); + opal_output_close(framework->framework_output); framework->framework_output = -1; } } -int mca_base_framework_register (struct mca_base_framework_t *framework, - mca_base_register_flag_t flags) +int mca_base_framework_register(struct mca_base_framework_t *framework, + mca_base_register_flag_t flags) { char *desc; int ret; - assert (NULL != framework); + assert(NULL != framework); framework->framework_refcnt++; - if (mca_base_framework_is_registered (framework)) { + if (mca_base_framework_is_registered(framework)) { return OPAL_SUCCESS; } @@ -79,39 +78,38 @@ int mca_base_framework_register (struct mca_base_framework_t *framework, if (!(MCA_BASE_FRAMEWORK_FLAG_NOREGISTER & framework->framework_flags)) { /* register this framework with the MCA variable system */ - ret = mca_base_var_group_register (framework->framework_project, - framework->framework_name, - NULL, framework->framework_description); + ret = mca_base_var_group_register(framework->framework_project, framework->framework_name, + NULL, framework->framework_description); if (0 > ret) { return ret; } - opal_asprintf (&desc, "Default selection set of components for the %s framework (" - " means use all components that can be found)", framework->framework_name); - ret = mca_base_var_register (framework->framework_project, framework->framework_name, - NULL, NULL, desc, MCA_BASE_VAR_TYPE_STRING, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_2, - MCA_BASE_VAR_SCOPE_ALL_EQ, &framework->framework_selection); - free (desc); + opal_asprintf(&desc, + "Default selection set of components for the %s framework (" + " means use all components that can be found)", + framework->framework_name); + ret = mca_base_var_register(framework->framework_project, framework->framework_name, NULL, + NULL, desc, MCA_BASE_VAR_TYPE_STRING, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_2, + MCA_BASE_VAR_SCOPE_ALL_EQ, &framework->framework_selection); + free(desc); if (0 > ret) { return ret; } /* register a verbosity variable for this framework */ - ret = opal_asprintf (&desc, "Verbosity level for the %s framework (default: 0)", - framework->framework_name); + ret = opal_asprintf(&desc, "Verbosity level for the %s framework (default: 0)", + framework->framework_name); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } framework->framework_verbose = MCA_BASE_VERBOSE_ERROR; - ret = mca_base_framework_var_register (framework, "verbose", desc, - MCA_BASE_VAR_TYPE_INT, - &mca_base_var_enum_verbose, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_8, - MCA_BASE_VAR_SCOPE_LOCAL, - &framework->framework_verbose); + ret = mca_base_framework_var_register(framework, "verbose", desc, MCA_BASE_VAR_TYPE_INT, + &mca_base_var_enum_verbose, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_8, + MCA_BASE_VAR_SCOPE_LOCAL, + &framework->framework_verbose); free(desc); if (0 > ret) { return ret; @@ -119,18 +117,18 @@ int mca_base_framework_register (struct mca_base_framework_t *framework, /* check the initial verbosity and open the output if necessary. we will recheck this on open */ - framework_open_output (framework); + framework_open_output(framework); /* register framework variables */ if (NULL != framework->framework_register) { - ret = framework->framework_register (flags); + ret = framework->framework_register(flags); if (OPAL_SUCCESS != ret) { return ret; } } /* register components variables */ - ret = mca_base_framework_components_register (framework, flags); + ret = mca_base_framework_components_register(framework, flags); if (OPAL_SUCCESS != ret) { return ret; } @@ -142,14 +140,15 @@ int mca_base_framework_register (struct mca_base_framework_t *framework, return OPAL_SUCCESS; } -int mca_base_framework_register_list (mca_base_framework_t **frameworks, mca_base_register_flag_t flags) +int mca_base_framework_register_list(mca_base_framework_t **frameworks, + mca_base_register_flag_t flags) { if (NULL == frameworks) { return OPAL_ERR_BAD_PARAM; } - for (int i = 0 ; frameworks[i] ; ++i) { - int ret = mca_base_framework_register (frameworks[i], flags); + for (int i = 0; frameworks[i]; ++i) { + int ret = mca_base_framework_register(frameworks[i], flags); if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) { return ret; } @@ -158,20 +157,20 @@ int mca_base_framework_register_list (mca_base_framework_t **frameworks, mca_bas return OPAL_SUCCESS; } -int mca_base_framework_open (struct mca_base_framework_t *framework, - mca_base_open_flag_t flags) { +int mca_base_framework_open(struct mca_base_framework_t *framework, mca_base_open_flag_t flags) +{ int ret; - assert (NULL != framework); + assert(NULL != framework); /* register this framework before opening it */ - ret = mca_base_framework_register (framework, MCA_BASE_REGISTER_DEFAULT); + ret = mca_base_framework_register(framework, MCA_BASE_REGISTER_DEFAULT); if (OPAL_SUCCESS != ret) { return ret; } /* check if this framework is already open */ - if (mca_base_framework_is_open (framework)) { + if (mca_base_framework_is_open(framework)) { return OPAL_SUCCESS; } @@ -184,18 +183,16 @@ int mca_base_framework_open (struct mca_base_framework_t *framework, } /* lock all of this frameworks's variables */ - ret = mca_base_var_group_find (framework->framework_project, - framework->framework_name, - NULL); - mca_base_var_group_set_var_flag (ret, MCA_BASE_VAR_FLAG_SETTABLE, false); + ret = mca_base_var_group_find(framework->framework_project, framework->framework_name, NULL); + mca_base_var_group_set_var_flag(ret, MCA_BASE_VAR_FLAG_SETTABLE, false); /* check the verbosity level and open (or close) the output */ - framework_open_output (framework); + framework_open_output(framework); if (NULL != framework->framework_open) { - ret = framework->framework_open (flags); + ret = framework->framework_open(flags); } else { - ret = mca_base_framework_components_open (framework, flags); + ret = mca_base_framework_components_open(framework, flags); } if (OPAL_SUCCESS != ret) { @@ -207,14 +204,14 @@ int mca_base_framework_open (struct mca_base_framework_t *framework, return ret; } -int mca_base_framework_open_list (mca_base_framework_t **frameworks, mca_base_open_flag_t flags) +int mca_base_framework_open_list(mca_base_framework_t **frameworks, mca_base_open_flag_t flags) { if (NULL == frameworks) { return OPAL_ERR_BAD_PARAM; } - for (int i = 0 ; frameworks[i] ; ++i) { - int ret = mca_base_framework_open (frameworks[i], flags); + for (int i = 0; frameworks[i]; ++i) { + int ret = mca_base_framework_open(frameworks[i], flags); if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) { return ret; } @@ -223,35 +220,36 @@ int mca_base_framework_open_list (mca_base_framework_t **frameworks, mca_base_op return OPAL_SUCCESS; } -int mca_base_framework_close (struct mca_base_framework_t *framework) { - bool is_open = mca_base_framework_is_open (framework); - bool is_registered = mca_base_framework_is_registered (framework); +int mca_base_framework_close(struct mca_base_framework_t *framework) +{ + bool is_open = mca_base_framework_is_open(framework); + bool is_registered = mca_base_framework_is_registered(framework); int ret, group_id; - assert (NULL != framework); + assert(NULL != framework); if (!(is_open || is_registered)) { return OPAL_SUCCESS; } - assert (framework->framework_refcnt); + assert(framework->framework_refcnt); if (--framework->framework_refcnt) { return OPAL_SUCCESS; } /* find and deregister all component groups and variables */ - group_id = mca_base_var_group_find (framework->framework_project, - framework->framework_name, NULL); + group_id = mca_base_var_group_find(framework->framework_project, framework->framework_name, + NULL); if (0 <= group_id) { - (void) mca_base_var_group_deregister (group_id); + (void) mca_base_var_group_deregister(group_id); } /* close the framework and all of its components */ if (is_open) { if (NULL != framework->framework_close) { - ret = framework->framework_close (); + ret = framework->framework_close(); } else { - ret = mca_base_framework_components_close (framework, NULL); + ret = mca_base_framework_components_close(framework, NULL); } if (OPAL_SUCCESS != ret) { @@ -259,37 +257,37 @@ int mca_base_framework_close (struct mca_base_framework_t *framework) { } } else { opal_list_item_t *item; - while (NULL != (item = opal_list_remove_first (&framework->framework_components))) { + while (NULL != (item = opal_list_remove_first(&framework->framework_components))) { mca_base_component_list_item_t *cli; - cli = (mca_base_component_list_item_t*) item; - mca_base_component_unload(cli->cli_component, - framework->framework_output); + cli = (mca_base_component_list_item_t *) item; + mca_base_component_unload(cli->cli_component, framework->framework_output); OBJ_RELEASE(item); } - while (NULL != (item = opal_list_remove_first (&framework->framework_failed_components))) { + while (NULL != (item = opal_list_remove_first(&framework->framework_failed_components))) { OBJ_RELEASE(item); } ret = OPAL_SUCCESS; } - framework->framework_flags &= ~(MCA_BASE_FRAMEWORK_FLAG_REGISTERED | MCA_BASE_FRAMEWORK_FLAG_OPEN); + framework->framework_flags &= ~(MCA_BASE_FRAMEWORK_FLAG_REGISTERED + | MCA_BASE_FRAMEWORK_FLAG_OPEN); OBJ_DESTRUCT(&framework->framework_components); OBJ_DESTRUCT(&framework->framework_failed_components); - framework_close_output (framework); + framework_close_output(framework); return ret; } -int mca_base_framework_close_list (mca_base_framework_t **frameworks) +int mca_base_framework_close_list(mca_base_framework_t **frameworks) { if (NULL == frameworks) { return OPAL_ERR_BAD_PARAM; } - for (int i = 0 ; frameworks[i] ; ++i) { - int ret = mca_base_framework_close (frameworks[i]); + for (int i = 0; frameworks[i]; ++i) { + int ret = mca_base_framework_close(frameworks[i]); if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) { return ret; } diff --git a/opal/mca/base/mca_base_framework.h b/opal/mca/base/mca_base_framework.h index a5187d7dd3c..d79428cb43d 100644 --- a/opal/mca/base/mca_base_framework.h +++ b/opal/mca/base/mca_base_framework.h @@ -13,18 +13,18 @@ */ #if !defined(OPAL_MCA_BASE_FRAMEWORK_H) -#define OPAL_MCA_BASE_FRAMEWORK_H +# define OPAL_MCA_BASE_FRAMEWORK_H -#include "opal/mca/mca.h" -#include "opal/class/opal_list.h" +# include "opal/class/opal_list.h" +# include "opal/mca/mca.h" /* * Register and open flags */ enum mca_base_register_flag_t { - MCA_BASE_REGISTER_DEFAULT = 0, + MCA_BASE_REGISTER_DEFAULT = 0, /** Register all components (ignore selection MCA variables) */ - MCA_BASE_REGISTER_ALL = 1, + MCA_BASE_REGISTER_ALL = 1, /** Do not register DSO components */ MCA_BASE_REGISTER_STATIC_ONLY = 2 }; @@ -32,18 +32,17 @@ enum mca_base_register_flag_t { typedef enum mca_base_register_flag_t mca_base_register_flag_t; enum mca_base_open_flag_t { - MCA_BASE_OPEN_DEFAULT = 0, + MCA_BASE_OPEN_DEFAULT = 0, /** Find components in mca_base_components_find. Used by mca_base_framework_open() when NOREGISTER is specified by the framework */ MCA_BASE_OPEN_FIND_COMPONENTS = 1, /** Do not open DSO components */ - MCA_BASE_OPEN_STATIC_ONLY = 2, + MCA_BASE_OPEN_STATIC_ONLY = 2, }; typedef enum mca_base_open_flag_t mca_base_open_flag_t; - /** * Register the MCA framework parameters * @@ -58,7 +57,7 @@ typedef enum mca_base_open_flag_t mca_base_open_flag_t; * Frameworks are NOT required to provide this function. It * may be NULL. */ -typedef int (*mca_base_framework_register_params_fn_t) (mca_base_register_flag_t flags); +typedef int (*mca_base_framework_register_params_fn_t)(mca_base_register_flag_t flags); /** * Initialize the MCA framework @@ -89,7 +88,7 @@ typedef int (*mca_base_framework_register_params_fn_t) (mca_base_register_flag_t * an open function it will need to call mca_base_framework_components_open() * if it needs to open any components. */ -typedef int (*mca_base_framework_open_fn_t) (mca_base_open_flag_t flags); +typedef int (*mca_base_framework_open_fn_t)(mca_base_open_flag_t flags); /** * Shut down the MCA framework. @@ -109,18 +108,18 @@ typedef int (*mca_base_framework_open_fn_t) (mca_base_open_flag_t flags); * a close function it will need to call mca_base_framework_components_close() * if any components were opened. */ -typedef int (*mca_base_framework_close_fn_t) (void); +typedef int (*mca_base_framework_close_fn_t)(void); typedef enum { - MCA_BASE_FRAMEWORK_FLAG_DEFAULT = 0, + MCA_BASE_FRAMEWORK_FLAG_DEFAULT = 0, /** Don't register any variables for this framework */ MCA_BASE_FRAMEWORK_FLAG_NOREGISTER = 1, /** Internal. Don't set outside mca_base_framework.h */ MCA_BASE_FRAMEWORK_FLAG_REGISTERED = 2, /** Framework does not have any DSO components */ - MCA_BASE_FRAMEWORK_FLAG_NO_DSO = 4, + MCA_BASE_FRAMEWORK_FLAG_NO_DSO = 4, /** Internal. Don't set outside mca_base_framework.h */ - MCA_BASE_FRAMEWORK_FLAG_OPEN = 8, + MCA_BASE_FRAMEWORK_FLAG_OPEN = 8, /** * The upper 16 bits are reserved for project specific flags. */ @@ -128,40 +127,39 @@ typedef enum { typedef struct mca_base_framework_t { /** Project name for this component (ex "opal") */ - char *framework_project; + char *framework_project; /** Framework name */ - char *framework_name; + char *framework_name; /** Description of this framework or NULL */ - const char *framework_description; + const char *framework_description; /** Framework register function or NULL if the framework and all its components have nothing to register */ - mca_base_framework_register_params_fn_t framework_register; + mca_base_framework_register_params_fn_t framework_register; /** Framework open function or NULL */ - mca_base_framework_open_fn_t framework_open; + mca_base_framework_open_fn_t framework_open; /** Framework close function or NULL */ - mca_base_framework_close_fn_t framework_close; + mca_base_framework_close_fn_t framework_close; /** Framework flags (future use) set to 0 */ - mca_base_framework_flags_t framework_flags; + mca_base_framework_flags_t framework_flags; /** Framework open count */ - int framework_refcnt; + int framework_refcnt; /** List of static components */ - const mca_base_component_t **framework_static_components; + const mca_base_component_t **framework_static_components; /** Component selection. This will be registered with the MCA variable system and should be either NULL (all components) or a heap allocated, comma-delimited list of components. */ - char *framework_selection; + char *framework_selection; /** Verbosity level (0-100) */ - int framework_verbose; + int framework_verbose; /** Opal output for this framework (or -1) */ - int framework_output; + int framework_output; /** List of selected components (filled in by mca_base_framework_register() or mca_base_framework_open() */ - opal_list_t framework_components; + opal_list_t framework_components; /** List of components that failed to load */ - opal_list_t framework_failed_components; + opal_list_t framework_failed_components; } mca_base_framework_t; - /** * Register a framework with MCA. * @@ -172,8 +170,8 @@ typedef struct mca_base_framework_t { * * Call a framework's register function. */ -OPAL_DECLSPEC int mca_base_framework_register (mca_base_framework_t *framework, - mca_base_register_flag_t flags); +OPAL_DECLSPEC int mca_base_framework_register(mca_base_framework_t *framework, + mca_base_register_flag_t flags); /** * Register frameworks with MCA. @@ -186,8 +184,8 @@ OPAL_DECLSPEC int mca_base_framework_register (mca_base_framework_t *framework, * Call the MCA variable registration functions of each framework in the * frameworks array. */ -OPAL_DECLSPEC int mca_base_framework_register_list (mca_base_framework_t **frameworks, - mca_base_register_flag_t flags); +OPAL_DECLSPEC int mca_base_framework_register_list(mca_base_framework_t **frameworks, + mca_base_register_flag_t flags); /** * Open a framework @@ -199,8 +197,8 @@ OPAL_DECLSPEC int mca_base_framework_register_list (mca_base_framework_t **frame * * Call a framework's open function. */ -OPAL_DECLSPEC int mca_base_framework_open (mca_base_framework_t *framework, - mca_base_open_flag_t flags); +OPAL_DECLSPEC int mca_base_framework_open(mca_base_framework_t *framework, + mca_base_open_flag_t flags); /** * Open frameworks @@ -212,8 +210,8 @@ OPAL_DECLSPEC int mca_base_framework_open (mca_base_framework_t *framework, * * Call the open function on multiple frameworks */ -OPAL_DECLSPEC int mca_base_framework_open_list (mca_base_framework_t **frameworks, - mca_base_open_flag_t flags); +OPAL_DECLSPEC int mca_base_framework_open_list(mca_base_framework_t **frameworks, + mca_base_open_flag_t flags); /** * Close a framework @@ -225,7 +223,7 @@ OPAL_DECLSPEC int mca_base_framework_open_list (mca_base_framework_t **framework * * Call a framework's close function. */ -OPAL_DECLSPEC int mca_base_framework_close (mca_base_framework_t *framework); +OPAL_DECLSPEC int mca_base_framework_close(mca_base_framework_t *framework); /** * Close frameworks @@ -237,7 +235,7 @@ OPAL_DECLSPEC int mca_base_framework_close (mca_base_framework_t *framework); * * Call the close function on multiple frameworks */ -OPAL_DECLSPEC int mca_base_framework_close_list (mca_base_framework_t **frameworks); +OPAL_DECLSPEC int mca_base_framework_close_list(mca_base_framework_t **frameworks); /** * Check if a framework is already registered @@ -247,8 +245,7 @@ OPAL_DECLSPEC int mca_base_framework_close_list (mca_base_framework_t **framewor * @retval true if the framework's mca variables are registered * @retval false if not */ -OPAL_DECLSPEC bool mca_base_framework_is_registered (struct mca_base_framework_t *framework); - +OPAL_DECLSPEC bool mca_base_framework_is_registered(struct mca_base_framework_t *framework); /** * Check if a framework is already open @@ -258,28 +255,29 @@ OPAL_DECLSPEC bool mca_base_framework_is_registered (struct mca_base_framework_t * @retval true if the framework is open * @retval false if not */ -OPAL_DECLSPEC bool mca_base_framework_is_open (struct mca_base_framework_t *framework); - +OPAL_DECLSPEC bool mca_base_framework_is_open(struct mca_base_framework_t *framework); /** * Macro to declare an MCA framework * * Example: - * MCA_BASE_FRAMEWORK_DECLARE(opal, foo, NULL, opal_foo_open, opal_foo_close, MCA_BASE_FRAMEWORK_FLAG_LAZY) + * MCA_BASE_FRAMEWORK_DECLARE(opal, foo, NULL, opal_foo_open, opal_foo_close, + * MCA_BASE_FRAMEWORK_FLAG_LAZY) */ -#define MCA_BASE_FRAMEWORK_DECLARE(project, name, description, registerfn, openfn, closefn, static_components, flags) \ - mca_base_framework_t project##_##name##_base_framework = { \ - .framework_project = #project, \ - .framework_name = #name, \ - .framework_description = description, \ - .framework_register = registerfn, \ - .framework_open = openfn, \ - .framework_close = closefn, \ - .framework_flags = flags, \ - .framework_refcnt = 0, \ - .framework_static_components = static_components, \ - .framework_selection = NULL, \ - .framework_verbose = 0, \ - .framework_output = -1} +# define MCA_BASE_FRAMEWORK_DECLARE(project, name, description, registerfn, openfn, closefn, \ + static_components, flags) \ + mca_base_framework_t project##_##name##_base_framework \ + = {.framework_project = #project, \ + .framework_name = #name, \ + .framework_description = description, \ + .framework_register = registerfn, \ + .framework_open = openfn, \ + .framework_close = closefn, \ + .framework_flags = flags, \ + .framework_refcnt = 0, \ + .framework_static_components = static_components, \ + .framework_selection = NULL, \ + .framework_verbose = 0, \ + .framework_output = -1} #endif /* OPAL_MCA_BASE_FRAMEWORK_H */ diff --git a/opal/mca/base/mca_base_list.c b/opal/mca/base/mca_base_list.c index 0c97e69a0ce..3a4d58def5b 100644 --- a/opal/mca/base/mca_base_list.c +++ b/opal/mca/base/mca_base_list.c @@ -21,44 +21,37 @@ #include "opal/class/opal_list.h" #include "opal/mca/base/base.h" - /* * Local functions */ static void cl_constructor(opal_object_t *obj); static void cpl_constructor(opal_object_t *obj); - /* * Class instance of the mca_base_component_list_item_t class */ -OBJ_CLASS_INSTANCE(mca_base_component_list_item_t, - opal_list_item_t, cl_constructor, NULL); - +OBJ_CLASS_INSTANCE(mca_base_component_list_item_t, opal_list_item_t, cl_constructor, NULL); /* * Class instance of the mca_base_component_priority_list_item_t class */ -OBJ_CLASS_INSTANCE(mca_base_component_priority_list_item_t, - mca_base_component_list_item_t, cpl_constructor, NULL); - +OBJ_CLASS_INSTANCE(mca_base_component_priority_list_item_t, mca_base_component_list_item_t, + cpl_constructor, NULL); /* * Just do basic sentinel intialization */ static void cl_constructor(opal_object_t *obj) { - mca_base_component_list_item_t *cli = (mca_base_component_list_item_t *) obj; - cli->cli_component = NULL; + mca_base_component_list_item_t *cli = (mca_base_component_list_item_t *) obj; + cli->cli_component = NULL; } - /* * Just do basic sentinel intialization */ static void cpl_constructor(opal_object_t *obj) { - mca_base_component_priority_list_item_t *cpli = - (mca_base_component_priority_list_item_t *) obj; - cpli->cpli_priority = -1; + mca_base_component_priority_list_item_t *cpli = (mca_base_component_priority_list_item_t *) obj; + cpli->cpli_priority = -1; } diff --git a/opal/mca/base/mca_base_open.c b/opal/mca/base/mca_base_open.c index 282cfd26424..8389ba76c60 100644 --- a/opal/mca/base/mca_base_open.c +++ b/opal/mca/base/mca_base_open.c @@ -29,21 +29,21 @@ #include #include #ifdef HAVE_SYSLOG_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif -#include "opal/runtime/opal.h" -#include "opal/mca/installdirs/installdirs.h" -#include "opal/util/output.h" -#include "opal/util/printf.h" -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_component_repository.h" -#include "opal/constants.h" +#include "opal/mca/installdirs/installdirs.h" +#include "opal/mca/mca.h" +#include "opal/runtime/opal.h" #include "opal/util/opal_environ.h" +#include "opal/util/output.h" +#include "opal/util/printf.h" /* * Public variables @@ -52,8 +52,7 @@ char *mca_base_component_path = NULL; int mca_base_opened = 0; char *mca_base_system_default_path = NULL; char *mca_base_user_default_path = NULL; -bool mca_base_component_show_load_errors = - (bool) OPAL_SHOW_LOAD_ERRORS_DEFAULT; +bool mca_base_component_show_load_errors = (bool) OPAL_SHOW_LOAD_ERRORS_DEFAULT; bool mca_base_component_track_load_errors = false; bool mca_base_component_disable_dlopen = false; @@ -65,7 +64,6 @@ static char *mca_base_verbose = NULL; static void set_defaults(opal_output_stream_t *lds); static void parse_verbose(char *e, opal_output_stream_t *lds); - /* * Main MCA initialization. */ @@ -83,7 +81,8 @@ int mca_base_open(void) /* define the system and user default paths */ #if OPAL_WANT_HOME_CONFIG_FILES mca_base_system_default_path = strdup(opal_install_dirs.opallibdir); - opal_asprintf(&mca_base_user_default_path, "%s"OPAL_PATH_SEP".openmpi"OPAL_PATH_SEP"components", opal_home_directory()); + opal_asprintf(&mca_base_user_default_path, + "%s" OPAL_PATH_SEP ".openmpi" OPAL_PATH_SEP "components", opal_home_directory()); #else opal_asprintf(&mca_base_system_default_path, "%s", opal_install_dirs.opallibdir); #endif @@ -92,47 +91,41 @@ int mca_base_open(void) if (NULL == mca_base_user_default_path) { value = strdup(mca_base_system_default_path); } else { - opal_asprintf(&value, "%s%c%s", mca_base_system_default_path, - OPAL_ENV_SEP, mca_base_user_default_path); + opal_asprintf(&value, "%s%c%s", mca_base_system_default_path, OPAL_ENV_SEP, + mca_base_user_default_path); } mca_base_component_path = value; var_id = mca_base_var_register("opal", "mca", "base", "component_path", "Path where to look for additional components", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_base_component_path); + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_base_component_path); (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "component_path", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); free(value); - mca_base_component_show_load_errors = - (bool) OPAL_SHOW_LOAD_ERRORS_DEFAULT; - var_id = mca_base_var_register("opal", "mca", "base", "component_show_load_errors", - "Whether to show errors for components that failed to load or not", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_base_component_show_load_errors); + mca_base_component_show_load_errors = (bool) OPAL_SHOW_LOAD_ERRORS_DEFAULT; + var_id + = mca_base_var_register("opal", "mca", "base", "component_show_load_errors", + "Whether to show errors for components that failed to load or not", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_base_component_show_load_errors); (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "component_show_load_errors", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); mca_base_component_track_load_errors = false; - var_id = mca_base_var_register("opal", "mca", "base", "component_track_load_errors", - "Whether to track errors for components that failed to load or not", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_base_component_track_load_errors); + var_id + = mca_base_var_register("opal", "mca", "base", "component_track_load_errors", + "Whether to track errors for components that failed to load or not", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_base_component_track_load_errors); mca_base_component_disable_dlopen = false; - var_id = mca_base_var_register("opal", "mca", "base", "component_disable_dlopen", - "Whether to attempt to disable opening dynamic components or not", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_base_component_disable_dlopen); + var_id + = mca_base_var_register("opal", "mca", "base", "component_disable_dlopen", + "Whether to attempt to disable opening dynamic components or not", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_base_component_disable_dlopen); (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "component_disable_dlopen", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); @@ -140,16 +133,19 @@ int mca_base_open(void) char *str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT"); if (NULL != str && str[0] == '1') { mca_base_verbose = "stdout"; - } - else { + } else { mca_base_verbose = "stderr"; } - var_id = mca_base_var_register("opal", "mca", "base", "verbose", - "Specifies where the default error output stream goes (this is separate from distinct help messages). Accepts a comma-delimited list of: stderr, stdout, syslog, syslogpri:, syslogid: (where str is the prefix string for all syslog notices), file[:filename] (if filename is not specified, a default filename is used), fileappend (if not specified, the file is opened for truncation), level[:N] (if specified, integer verbose level; otherwise, 0 is implied)", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_base_verbose); + var_id = mca_base_var_register( + "opal", "mca", "base", "verbose", + "Specifies where the default error output stream goes (this is separate from distinct help " + "messages). Accepts a comma-delimited list of: stderr, stdout, syslog, " + "syslogpri:, syslogid: (where str is the prefix string for all " + "syslog notices), file[:filename] (if filename is not specified, a default filename is " + "used), fileappend (if not specified, the file is opened for truncation), level[:N] (if " + "specified, integer verbose level; otherwise, 0 is implied)", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &mca_base_verbose); (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "verbose", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); @@ -162,17 +158,16 @@ int mca_base_open(void) hostname = opal_gethostname(); opal_asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid()); opal_output_reopen(0, &lds); - opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, 0, "mca: base: opening components"); + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, 0, "mca: base: opening components"); free(lds.lds_prefix); /* Open up the component repository */ - opal_finalize_register_cleanup (mca_base_close); + opal_finalize_register_cleanup(mca_base_close); return mca_base_component_repository_init(); } - /* * Set sane default values for the lds */ @@ -189,7 +184,6 @@ static void set_defaults(opal_output_stream_t *lds) lds->lds_want_stderr = true; } - /* * Parse the value of an environment variable describing verbosity */ @@ -220,28 +214,28 @@ static void parse_verbose(char *e, opal_output_stream_t *lds) have_output = true; #else opal_output(0, "syslog support requested but not available on this system"); -#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */ - } - else if (strncasecmp(ptr, "syslogpri:", 10) == 0) { +#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */ + } else if (strncasecmp(ptr, "syslogpri:", 10) == 0) { #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) lds->lds_want_syslog = true; have_output = true; - if (strcasecmp(ptr + 10, "notice") == 0) + if (strcasecmp(ptr + 10, "notice") == 0) { lds->lds_syslog_priority = LOG_NOTICE; - else if (strcasecmp(ptr + 10, "INFO") == 0) + } else if (strcasecmp(ptr + 10, "INFO") == 0) { lds->lds_syslog_priority = LOG_INFO; - else if (strcasecmp(ptr + 10, "DEBUG") == 0) + } else if (strcasecmp(ptr + 10, "DEBUG") == 0) { lds->lds_syslog_priority = LOG_DEBUG; + } #else opal_output(0, "syslog support requested but not available on this system"); -#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */ +#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */ } else if (strncasecmp(ptr, "syslogid:", 9) == 0) { #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) lds->lds_want_syslog = true; lds->lds_syslog_ident = ptr + 9; #else opal_output(0, "syslog support requested but not available on this system"); -#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */ +#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */ } else if (strcasecmp(ptr, "stdout") == 0) { @@ -267,8 +261,9 @@ static void parse_verbose(char *e, opal_output_stream_t *lds) else if (strncasecmp(ptr, "level", 5) == 0) { lds->lds_verbose_level = 0; - if (ptr[5] == OPAL_ENV_SEP) + if (ptr[5] == OPAL_ENV_SEP) { lds->lds_verbose_level = atoi(ptr + 6); + } } if (NULL == next) { diff --git a/opal/mca/base/mca_base_parse_paramfile.c b/opal/mca/base/mca_base_parse_paramfile.c index db19d143a2d..81561818885 100644 --- a/opal/mca/base/mca_base_parse_paramfile.c +++ b/opal/mca/base/mca_base_parse_paramfile.c @@ -25,19 +25,19 @@ #include #include "opal/class/opal_list.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_vari.h" +#include "opal/mca/mca.h" #include "opal/util/keyval_parse.h" #include "opal/util/output.h" static void save_value(const char *name, const char *value); -static char * file_being_read; -static opal_list_t * _param_list; +static char *file_being_read; +static opal_list_t *_param_list; int mca_base_parse_paramfile(const char *paramfile, opal_list_t *list) { - file_being_read = (char*)paramfile; + file_being_read = (char *) paramfile; _param_list = list; return opal_util_keyval_parse(paramfile, save_value); @@ -57,10 +57,10 @@ static void save_value(const char *name, const char *value) already have a param of this name. If we do, just replace the value. */ - OPAL_LIST_FOREACH(fv, _param_list, mca_base_var_file_value_t) { + OPAL_LIST_FOREACH (fv, _param_list, mca_base_var_file_value_t) { if (0 == strcmp(name, fv->mbvfv_var)) { if (NULL != fv->mbvfv_value) { - free (fv->mbvfv_value); + free(fv->mbvfv_value); } found = true; break; @@ -79,6 +79,6 @@ static void save_value(const char *name, const char *value) } fv->mbvfv_value = value ? strdup(value) : NULL; - fv->mbvfv_file = file_being_read; + fv->mbvfv_file = file_being_read; fv->mbvfv_lineno = opal_util_keyval_parse_lineno; } diff --git a/opal/mca/base/mca_base_pvar.c b/opal/mca/base/mca_base_pvar.c index 1bc71161743..001aa036ff0 100644 --- a/opal/mca/base/mca_base_pvar.c +++ b/opal/mca/base/mca_base_pvar.c @@ -20,11 +20,11 @@ #include "opal/mca/base/mca_base_vari.h" #include -#include #include +#include -#include "opal/class/opal_pointer_array.h" #include "opal/class/opal_hash_table.h" +#include "opal/class/opal_pointer_array.h" #include "opal/util/minmax.h" #include "opal/util/printf.h" @@ -33,23 +33,14 @@ static opal_pointer_array_t registered_pvars; static bool mca_base_pvar_initialized = false; static int pvar_count = 0; -static int mca_base_pvar_get_internal (int index, mca_base_pvar_t **pvar, bool invalidok); +static int mca_base_pvar_get_internal(int index, mca_base_pvar_t **pvar, bool invalidok); /* string representations of class names */ -static const char *pvar_class_names[] = { - "state", - "level", - "size", - "percentage", - "high watermark", - "low watermark", - "counter", - "aggregate", - "timer", - "generic" -}; - -int mca_base_pvar_init (void) +static const char *pvar_class_names[] = {"state", "level", "size", "percentage", + "high watermark", "low watermark", "counter", "aggregate", + "timer", "generic"}; + +int mca_base_pvar_init(void) { int ret = OPAL_SUCCESS; @@ -60,7 +51,7 @@ int mca_base_pvar_init (void) opal_pointer_array_init(®istered_pvars, 128, 2048, 128); OBJ_CONSTRUCT(&mca_base_pvar_index_hash, opal_hash_table_t); - ret = opal_hash_table_init (&mca_base_pvar_index_hash, 1024); + ret = opal_hash_table_init(&mca_base_pvar_index_hash, 1024); if (OPAL_SUCCESS != ret) { mca_base_pvar_initialized = false; OBJ_DESTRUCT(®istered_pvars); @@ -71,37 +62,38 @@ int mca_base_pvar_init (void) return ret; } -int mca_base_pvar_find (const char *project, const char *framework, const char *component, const char *name) +int mca_base_pvar_find(const char *project, const char *framework, const char *component, + const char *name) { char *full_name; int ret, index; - ret = mca_base_var_generate_full_name4 (NULL, framework, component, name, &full_name); + ret = mca_base_var_generate_full_name4(NULL, framework, component, name, &full_name); if (OPAL_SUCCESS != ret) { return OPAL_ERROR; } - ret = mca_base_pvar_find_by_name (full_name, MCA_BASE_PVAR_CLASS_ANY, &index); - free (full_name); + ret = mca_base_pvar_find_by_name(full_name, MCA_BASE_PVAR_CLASS_ANY, &index); + free(full_name); /* NTH: should we verify the name components match the returned variable? */ return (OPAL_SUCCESS != ret) ? ret : index; } -int mca_base_pvar_find_by_name (const char *full_name, int var_class, int *index) +int mca_base_pvar_find_by_name(const char *full_name, int var_class, int *index) { mca_base_pvar_t *pvar; void *tmp; int rc; - rc = opal_hash_table_get_value_ptr (&mca_base_pvar_index_hash, full_name, strlen (full_name), - &tmp); + rc = opal_hash_table_get_value_ptr(&mca_base_pvar_index_hash, full_name, strlen(full_name), + &tmp); if (OPAL_SUCCESS != rc) { return rc; } - rc = mca_base_pvar_get_internal ((int)(uintptr_t) tmp, &pvar, false); + rc = mca_base_pvar_get_internal((int) (uintptr_t) tmp, &pvar, false); if (OPAL_SUCCESS != rc) { return rc; } @@ -110,20 +102,20 @@ int mca_base_pvar_find_by_name (const char *full_name, int var_class, int *index return OPAL_ERR_NOT_FOUND; } - *index = (int)(uintptr_t) tmp; + *index = (int) (uintptr_t) tmp; return OPAL_SUCCESS; } -int mca_base_pvar_finalize (void) +int mca_base_pvar_finalize(void) { int i; - if (mca_base_pvar_initialized) { + if (mca_base_pvar_initialized) { mca_base_pvar_initialized = false; - for (i = 0 ; i < pvar_count ; ++i) { - mca_base_pvar_t *pvar = opal_pointer_array_get_item (®istered_pvars, i); + for (i = 0; i < pvar_count; ++i) { + mca_base_pvar_t *pvar = opal_pointer_array_get_item(®istered_pvars, i); if (pvar) { OBJ_RELEASE(pvar); } @@ -138,33 +130,36 @@ int mca_base_pvar_finalize (void) return OPAL_SUCCESS; } -int mca_base_pvar_get_count (int *count) +int mca_base_pvar_get_count(int *count) { *count = pvar_count; return OPAL_SUCCESS; } -static int mca_base_pvar_default_get_value (const mca_base_pvar_t *pvar, void *value, void *obj_handle) +static int mca_base_pvar_default_get_value(const mca_base_pvar_t *pvar, void *value, + void *obj_handle) { /* not used */ (void) obj_handle; - memmove (value, pvar->ctx, ompi_var_type_sizes[pvar->type]); + memmove(value, pvar->ctx, ompi_var_type_sizes[pvar->type]); return OPAL_SUCCESS; } -static int mca_base_pvar_default_set_value (mca_base_pvar_t *pvar, const void *value, void *obj_handle) +static int mca_base_pvar_default_set_value(mca_base_pvar_t *pvar, const void *value, + void *obj_handle) { /* not used */ (void) obj_handle; - memmove (pvar->ctx, value, ompi_var_type_sizes[pvar->type]); + memmove(pvar->ctx, value, ompi_var_type_sizes[pvar->type]); return OPAL_SUCCESS; } -static int mca_base_pvar_notify_ignore (mca_base_pvar_t *pvar, mca_base_pvar_event_t event, void *obj_handle, int *count) +static int mca_base_pvar_notify_ignore(mca_base_pvar_t *pvar, mca_base_pvar_event_t event, + void *obj_handle, int *count) { /* silence compiler warnings */ (void) pvar; @@ -178,11 +173,13 @@ static int mca_base_pvar_notify_ignore (mca_base_pvar_t *pvar, mca_base_pvar_eve return OPAL_SUCCESS; } -int mca_base_pvar_register (const char *project, const char *framework, const char *component, const char *name, - const char *description, mca_base_var_info_lvl_t verbosity, - int var_class, mca_base_var_type_t type, mca_base_var_enum_t *enumerator, - int bind, mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, - mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, void *ctx) +int mca_base_pvar_register(const char *project, const char *framework, const char *component, + const char *name, const char *description, + mca_base_var_info_lvl_t verbosity, int var_class, + mca_base_var_type_t type, mca_base_var_enum_t *enumerator, int bind, + mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, + mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, + void *ctx) { int ret, group_index, pvar_index; mca_base_pvar_t *pvar; @@ -193,7 +190,7 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch } /* ensure the caller did not set an invalid flag */ - assert (!(flags & 0x3f)); + assert(!(flags & 0x3f)); flags &= ~MCA_BASE_PVAR_FLAG_INVALID; @@ -217,10 +214,8 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch case MCA_BASE_PVAR_CLASS_LOWWATERMARK: case MCA_BASE_PVAR_CLASS_AGGREGATE: case MCA_BASE_PVAR_CLASS_TIMER: - if (MCA_BASE_VAR_TYPE_UNSIGNED_INT != type && - MCA_BASE_VAR_TYPE_UNSIGNED_LONG != type && - MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG != type && - MCA_BASE_VAR_TYPE_DOUBLE != type) { + if (MCA_BASE_VAR_TYPE_UNSIGNED_INT != type && MCA_BASE_VAR_TYPE_UNSIGNED_LONG != type + && MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG != type && MCA_BASE_VAR_TYPE_DOUBLE != type) { return OPAL_ERR_BAD_PARAM; } break; @@ -239,12 +234,12 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch } /* update this assert if more MPIT verbosity levels are added */ - assert (verbosity >= OPAL_INFO_LVL_1 && verbosity <= OPAL_INFO_LVL_9); + assert(verbosity >= OPAL_INFO_LVL_1 && verbosity <= OPAL_INFO_LVL_9); /* check if this variable is already registered */ - ret = mca_base_pvar_find (project, framework, component, name); + ret = mca_base_pvar_find(project, framework, component, name); if (OPAL_SUCCESS <= ret) { - ret = mca_base_pvar_get_internal (ret, &pvar, true); + ret = mca_base_pvar_get_internal(ret, &pvar, true); if (OPAL_SUCCESS != ret) { /* inconsistent internal state */ return OPAL_ERROR; @@ -255,7 +250,7 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch } } else { /* find/register an MCA parameter group for this performance variable */ - group_index = mca_base_var_group_register (project, framework, component, NULL); + group_index = mca_base_var_group_register(project, framework, component, NULL); if (-1 > group_index) { return group_index; } @@ -268,7 +263,7 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch do { /* generate the variable's full name */ - ret = mca_base_var_generate_full_name4 (NULL, framework, component, name, &pvar->name); + ret = mca_base_var_generate_full_name4(NULL, framework, component, name, &pvar->name); if (OPAL_SUCCESS != ret) { ret = OPAL_ERR_OUT_OF_RESOURCE; break; @@ -282,7 +277,7 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch } } - pvar_index = opal_pointer_array_add (®istered_pvars, pvar); + pvar_index = opal_pointer_array_add(®istered_pvars, pvar); if (0 > pvar_index) { break; } @@ -290,15 +285,15 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch /* add this performance variable to the MCA variable group */ if (0 <= group_index) { - ret = mca_base_var_group_add_pvar (group_index, pvar_index); + ret = mca_base_var_group_add_pvar(group_index, pvar_index); if (0 > ret) { break; } } pvar->pvar_index = pvar_count; - opal_hash_table_set_value_ptr (&mca_base_pvar_index_hash, pvar->name, strlen (pvar->name), - (void *)(uintptr_t) pvar->pvar_index); + opal_hash_table_set_value_ptr(&mca_base_pvar_index_hash, pvar->name, strlen(pvar->name), + (void *) (uintptr_t) pvar->pvar_index); pvar_count++; ret = OPAL_SUCCESS; @@ -312,10 +307,10 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch pvar->group_index = group_index; } - pvar->verbosity = verbosity; - pvar->var_class = var_class; - pvar->type = type; - pvar->enumerator = enumerator; + pvar->verbosity = verbosity; + pvar->var_class = var_class; + pvar->type = type; + pvar->enumerator = enumerator; if (enumerator) { OBJ_RETAIN(enumerator); } @@ -330,33 +325,36 @@ int mca_base_pvar_register (const char *project, const char *framework, const ch pvar->set_value = set_value ? set_value : mca_base_pvar_default_set_value; } - pvar->ctx = ctx; + pvar->ctx = ctx; return pvar->pvar_index; } -int mca_base_component_pvar_register (const mca_base_component_t *component, const char *name, - const char *description, mca_base_var_info_lvl_t verbosity, - int var_class, mca_base_var_type_t type, mca_base_var_enum_t *enumerator, - int bind, mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, - mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, void *ctx) +int mca_base_component_pvar_register(const mca_base_component_t *component, const char *name, + const char *description, mca_base_var_info_lvl_t verbosity, + int var_class, mca_base_var_type_t type, + mca_base_var_enum_t *enumerator, int bind, + mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, + mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, + void *ctx) { /* invalidate this variable if the component's group is deregistered */ - return mca_base_pvar_register(component->mca_project_name, component->mca_type_name, component->mca_component_name, - name, description, verbosity, var_class, type, enumerator, bind, - flags | MCA_BASE_PVAR_FLAG_IWG, get_value, set_value, notify, ctx); + return mca_base_pvar_register(component->mca_project_name, component->mca_type_name, + component->mca_component_name, name, description, verbosity, + var_class, type, enumerator, bind, flags | MCA_BASE_PVAR_FLAG_IWG, + get_value, set_value, notify, ctx); } -static int mca_base_pvar_get_internal (int index, mca_base_pvar_t **pvar, bool invalidok) +static int mca_base_pvar_get_internal(int index, mca_base_pvar_t **pvar, bool invalidok) { if (index >= pvar_count) { return OPAL_ERR_VALUE_OUT_OF_BOUNDS; } - *pvar = opal_pointer_array_get_item (®istered_pvars, index); + *pvar = opal_pointer_array_get_item(®istered_pvars, index); /* variables should never be removed per MPI 3.0 § 14.3.7 */ - assert (*pvar); + assert(*pvar); if (((*pvar)->flags & MCA_BASE_PVAR_FLAG_INVALID) && !invalidok) { *pvar = NULL; @@ -366,17 +364,17 @@ static int mca_base_pvar_get_internal (int index, mca_base_pvar_t **pvar, bool i return OPAL_SUCCESS; } -int mca_base_pvar_get (int index, const mca_base_pvar_t **pvar) +int mca_base_pvar_get(int index, const mca_base_pvar_t **pvar) { - return mca_base_pvar_get_internal (index, (mca_base_pvar_t **) pvar, false); + return mca_base_pvar_get_internal(index, (mca_base_pvar_t **) pvar, false); } -int mca_base_pvar_mark_invalid (int index) +int mca_base_pvar_mark_invalid(int index) { mca_base_pvar_t *pvar; int ret; - ret = mca_base_pvar_get_internal (index, &pvar, false); + ret = mca_base_pvar_get_internal(index, &pvar, false); if (OPAL_SUCCESS != ret) { return ret; } @@ -386,47 +384,48 @@ int mca_base_pvar_mark_invalid (int index) return OPAL_SUCCESS; } -int mca_base_pvar_notify (mca_base_pvar_handle_t *handle, mca_base_pvar_event_t event, int *count) +int mca_base_pvar_notify(mca_base_pvar_handle_t *handle, mca_base_pvar_event_t event, int *count) { - if (mca_base_pvar_is_invalid (handle->pvar)) { + if (mca_base_pvar_is_invalid(handle->pvar)) { return OPAL_ERR_NOT_BOUND; } - return handle->pvar->notify (handle->pvar, event, handle->obj_handle, count); + return handle->pvar->notify(handle->pvar, event, handle->obj_handle, count); } -int mca_base_pvar_update_all_handles (int index, const void *obj) +int mca_base_pvar_update_all_handles(int index, const void *obj) { mca_base_pvar_handle_t *handle, *next; mca_base_pvar_t *pvar; int ret; - ret = mca_base_pvar_get_internal (index, &pvar, false); + ret = mca_base_pvar_get_internal(index, &pvar, false); if (OPAL_SUCCESS != ret) { return ret; } - if (0 == opal_list_get_size (&pvar->bound_handles)) { + if (0 == opal_list_get_size(&pvar->bound_handles)) { /* nothing to do */ return OPAL_SUCCESS; } /* TODO -- probably need to add a handle/variable lock */ - OPAL_LIST_FOREACH_SAFE(handle, next, &pvar->bound_handles, mca_base_pvar_handle_t) { - handle = (mca_base_pvar_handle_t *)((char *) handle - offsetof (mca_base_pvar_handle_t, list2)); + OPAL_LIST_FOREACH_SAFE (handle, next, &pvar->bound_handles, mca_base_pvar_handle_t) { + handle = (mca_base_pvar_handle_t *) ((char *) handle + - offsetof(mca_base_pvar_handle_t, list2)); if (handle->obj_handle != obj) { continue; } - (void) mca_base_pvar_handle_update (handle); + (void) mca_base_pvar_handle_update(handle); } return OPAL_SUCCESS; } -int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, void *obj_handle, - mca_base_pvar_handle_t **handle, int *count) +int mca_base_pvar_handle_alloc(mca_base_pvar_session_t *session, int index, void *obj_handle, + mca_base_pvar_handle_t **handle, int *count) { mca_base_pvar_handle_t *pvar_handle = NULL; size_t datatype_size; @@ -435,7 +434,7 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi do { /* find the requested performance variable */ - ret = mca_base_pvar_get_internal (index, &pvar, false); + ret = mca_base_pvar_get_internal(index, &pvar, false); if (OPAL_SUCCESS != ret) { break; } @@ -456,7 +455,7 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi break; } - pvar_handle->obj_handle = (NULL == obj_handle ? NULL : *(void**)obj_handle); + pvar_handle->obj_handle = (NULL == obj_handle ? NULL : *(void **) obj_handle); pvar_handle->pvar = pvar; *handle = pvar_handle; @@ -464,7 +463,7 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi /* notify the variable that a handle has been bound and determine how many values this handle has. NTH: finding the count should probably be pushed into a separate function. */ - ret = mca_base_pvar_notify (pvar_handle, MCA_BASE_PVAR_HANDLE_BIND, count); + ret = mca_base_pvar_notify(pvar_handle, MCA_BASE_PVAR_HANDLE_BIND, count); if (0 > ret) { ret = OPAL_ERROR; break; @@ -480,30 +479,30 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi break; } - if (!mca_base_pvar_is_continuous (pvar) || mca_base_pvar_is_sum (pvar) || - mca_base_pvar_is_watermark (pvar)) { + if (!mca_base_pvar_is_continuous(pvar) || mca_base_pvar_is_sum(pvar) + || mca_base_pvar_is_watermark(pvar)) { /* if a variable is not continuous we will need to keep track of its last value to support start->stop->read correctly. use calloc to initialize the current value to 0. */ - pvar_handle->current_value = calloc (*count, datatype_size); + pvar_handle->current_value = calloc(*count, datatype_size); if (NULL == pvar_handle->current_value) { ret = OPAL_ERR_OUT_OF_RESOURCE; break; } } - if (mca_base_pvar_is_sum (pvar) || mca_base_pvar_is_watermark (pvar)) { + if (mca_base_pvar_is_sum(pvar) || mca_base_pvar_is_watermark(pvar)) { /* for sums (counters, timers, etc) we need to keep track of what the last value of the underlying counter was. this allows us to push the computation of handle values from the event(s) (which could be in a critical path) to pvar read/stop/reset/etc */ - pvar_handle->tmp_value = calloc (*count, datatype_size); + pvar_handle->tmp_value = calloc(*count, datatype_size); if (NULL == pvar_handle->tmp_value) { ret = OPAL_ERR_OUT_OF_RESOURCE; break; } - pvar_handle->last_value = calloc (*count, datatype_size); + pvar_handle->last_value = calloc(*count, datatype_size); if (NULL == pvar_handle->last_value) { ret = OPAL_ERR_OUT_OF_RESOURCE; break; @@ -512,12 +511,13 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi /* get the current value of the performance variable if this is a continuous sum or watermark. if this variable needs to be started first the current value is not relevant. */ - if (mca_base_pvar_is_continuous (pvar)) { - if (mca_base_pvar_is_sum (pvar)) { - ret = pvar->get_value (pvar, pvar_handle->last_value, pvar_handle->obj_handle); + if (mca_base_pvar_is_continuous(pvar)) { + if (mca_base_pvar_is_sum(pvar)) { + ret = pvar->get_value(pvar, pvar_handle->last_value, pvar_handle->obj_handle); } else { /* the initial value of a watermark is the current value of the variable */ - ret = pvar->get_value (pvar, pvar_handle->current_value, pvar_handle->obj_handle); + ret = pvar->get_value(pvar, pvar_handle->current_value, + pvar_handle->obj_handle); } if (OPAL_SUCCESS != ret) { @@ -529,10 +529,10 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi pvar_handle->session = session; /* the handle is ready. add it to the appropriate lists */ - opal_list_append (&session->handles, &pvar_handle->super); - opal_list_append (&pvar->bound_handles, &pvar_handle->list2); + opal_list_append(&session->handles, &pvar_handle->super); + opal_list_append(&pvar->bound_handles, &pvar_handle->list2); - if (mca_base_pvar_is_continuous (pvar)) { + if (mca_base_pvar_is_continuous(pvar)) { /* mark this variable as started */ pvar_handle->started = true; } @@ -547,52 +547,56 @@ int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, voi return ret; } -int mca_base_pvar_handle_free (mca_base_pvar_handle_t *handle) +int mca_base_pvar_handle_free(mca_base_pvar_handle_t *handle) { OBJ_RELEASE(handle); return OPAL_SUCCESS; } -int mca_base_pvar_handle_update (mca_base_pvar_handle_t *handle) +int mca_base_pvar_handle_update(mca_base_pvar_handle_t *handle) { int i, ret; void *tmp; - if (mca_base_pvar_is_invalid (handle->pvar)) { + if (mca_base_pvar_is_invalid(handle->pvar)) { return OPAL_ERR_NOT_BOUND; } - if (!mca_base_pvar_handle_is_running (handle)) { + if (!mca_base_pvar_handle_is_running(handle)) { return OPAL_SUCCESS; } - if (mca_base_pvar_is_sum (handle->pvar) || mca_base_pvar_is_watermark (handle->pvar)) { - ret = handle->pvar->get_value (handle->pvar, handle->tmp_value, handle->obj_handle); + if (mca_base_pvar_is_sum(handle->pvar) || mca_base_pvar_is_watermark(handle->pvar)) { + ret = handle->pvar->get_value(handle->pvar, handle->tmp_value, handle->obj_handle); if (OPAL_SUCCESS != ret) { return OPAL_ERROR; } - if (mca_base_pvar_is_sum (handle->pvar)) { - for (i = 0 ; i < handle->count ; ++i) { + if (mca_base_pvar_is_sum(handle->pvar)) { + for (i = 0; i < handle->count; ++i) { /* the instance started at 0. need to subract the initial value off the result. */ switch (handle->pvar->type) { case MCA_BASE_VAR_TYPE_UNSIGNED_INT: - ((unsigned *) handle->current_value)[i] += ((unsigned *) handle->tmp_value)[i] - - ((unsigned *) handle->last_value)[i]; + ((unsigned *) handle->current_value)[i] += ((unsigned *) handle->tmp_value)[i] + - ((unsigned *) + handle->last_value)[i]; break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG: - ((unsigned long *) handle->current_value)[i] += ((unsigned long *) handle->tmp_value)[i] - - ((unsigned long *) handle->last_value)[i]; + ((unsigned long *) handle->current_value)[i] += ((unsigned long *) + handle->tmp_value)[i] + - ((unsigned long *) + handle->last_value)[i]; break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG: - ((unsigned long long *) handle->current_value)[i] += ((unsigned long long *) handle->tmp_value)[i] - - ((unsigned long long *) handle->last_value)[i]; + ((unsigned long long *) handle->current_value)[i] + += ((unsigned long long *) handle->tmp_value)[i] + - ((unsigned long long *) handle->last_value)[i]; break; case MCA_BASE_VAR_TYPE_DOUBLE: - ((double *) handle->current_value)[i] += ((double *) handle->tmp_value)[i] - - ((double *) handle->last_value)[i]; + ((double *) handle->current_value)[i] += ((double *) handle->tmp_value)[i] + - ((double *) handle->last_value)[i]; break; default: /* shouldn't happen */ @@ -604,24 +608,28 @@ int mca_base_pvar_handle_update (mca_base_pvar_handle_t *handle) handle->tmp_value = handle->last_value; handle->last_value = tmp; } else { - for (i = 0 ; i < handle->count ; ++i) { + for (i = 0; i < handle->count; ++i) { if (MCA_BASE_PVAR_CLASS_LOWWATERMARK == handle->pvar->var_class) { switch (handle->pvar->type) { case MCA_BASE_VAR_TYPE_UNSIGNED_INT: - ((unsigned *) handle->current_value)[i] = opal_min(((unsigned *) handle->tmp_value)[i], - ((unsigned *) handle->current_value)[i]); + ((unsigned *) handle->current_value)[i] + = opal_min(((unsigned *) handle->tmp_value)[i], + ((unsigned *) handle->current_value)[i]); break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG: - ((unsigned long *) handle->current_value)[i] = opal_min(((unsigned long *) handle->tmp_value)[i], - ((unsigned long *) handle->current_value)[i]); + ((unsigned long *) handle->current_value)[i] + = opal_min(((unsigned long *) handle->tmp_value)[i], + ((unsigned long *) handle->current_value)[i]); break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG: - ((unsigned long long *) handle->current_value)[i] = opal_min(((unsigned long long *) handle->tmp_value)[i], - ((unsigned long long *) handle->current_value)[i]); + ((unsigned long long *) handle->current_value)[i] + = opal_min(((unsigned long long *) handle->tmp_value)[i], + ((unsigned long long *) handle->current_value)[i]); break; case MCA_BASE_VAR_TYPE_DOUBLE: - ((double *) handle->current_value)[i] = opal_min(((double *) handle->tmp_value)[i], - ((double *) handle->current_value)[i]); + ((double *) handle->current_value)[i] + = opal_min(((double *) handle->tmp_value)[i], + ((double *) handle->current_value)[i]); break; default: /* shouldn't happen */ @@ -630,20 +638,24 @@ int mca_base_pvar_handle_update (mca_base_pvar_handle_t *handle) } else { switch (handle->pvar->type) { case MCA_BASE_VAR_TYPE_UNSIGNED_INT: - ((unsigned *) handle->current_value)[i] = opal_max(((unsigned *) handle->tmp_value)[i], - ((unsigned *) handle->current_value)[i]); + ((unsigned *) handle->current_value)[i] + = opal_max(((unsigned *) handle->tmp_value)[i], + ((unsigned *) handle->current_value)[i]); break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG: - ((unsigned long *) handle->current_value)[i] = opal_max(((unsigned long *) handle->tmp_value)[i], - ((unsigned long *) handle->current_value)[i]); + ((unsigned long *) handle->current_value)[i] + = opal_max(((unsigned long *) handle->tmp_value)[i], + ((unsigned long *) handle->current_value)[i]); break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG: - ((unsigned long long *) handle->current_value)[i] = opal_max(((unsigned long long *) handle->tmp_value)[i], - ((unsigned long long *) handle->current_value)[i]); + ((unsigned long long *) handle->current_value)[i] + = opal_max(((unsigned long long *) handle->tmp_value)[i], + ((unsigned long long *) handle->current_value)[i]); break; case MCA_BASE_VAR_TYPE_DOUBLE: - ((double *) handle->current_value)[i] = opal_max(((double *) handle->tmp_value)[i], - ((double *) handle->current_value)[i]); + ((double *) handle->current_value)[i] + = opal_max(((double *) handle->tmp_value)[i], + ((double *) handle->current_value)[i]); break; default: /* shouldn't happen */ @@ -652,100 +664,101 @@ int mca_base_pvar_handle_update (mca_base_pvar_handle_t *handle) } } } - } else if (!mca_base_pvar_is_continuous (handle->pvar)) { + } else if (!mca_base_pvar_is_continuous(handle->pvar)) { /* cache the current value */ - ret = handle->pvar->get_value (handle->pvar, handle->current_value, handle->obj_handle); + ret = handle->pvar->get_value(handle->pvar, handle->current_value, handle->obj_handle); if (OPAL_SUCCESS != ret) { return ret; } } - /* XXX -- TODO -- For watermarks this function will have to be invoked for each handle whenever the underlying value is updated. */ + /* XXX -- TODO -- For watermarks this function will have to be invoked for each handle whenever + * the underlying value is updated. */ return OPAL_SUCCESS; } -int mca_base_pvar_handle_read_value (mca_base_pvar_handle_t *handle, void *value) +int mca_base_pvar_handle_read_value(mca_base_pvar_handle_t *handle, void *value) { int ret; - if (mca_base_pvar_is_invalid (handle->pvar)) { + if (mca_base_pvar_is_invalid(handle->pvar)) { return OPAL_ERR_NOT_BOUND; } /* ensure this handle's value is up to date. */ - ret = mca_base_pvar_handle_update (handle); + ret = mca_base_pvar_handle_update(handle); if (OPAL_SUCCESS != ret) { return ret; } - if (mca_base_pvar_is_sum (handle->pvar) || mca_base_pvar_is_watermark (handle->pvar) || - !mca_base_pvar_handle_is_running (handle)) { + if (mca_base_pvar_is_sum(handle->pvar) || mca_base_pvar_is_watermark(handle->pvar) + || !mca_base_pvar_handle_is_running(handle)) { /* read the value cached in the handle. */ - memmove (value, handle->current_value, handle->count * ompi_var_type_sizes[handle->pvar->type]); + memmove(value, handle->current_value, + handle->count * ompi_var_type_sizes[handle->pvar->type]); } else { /* read the value directly from the variable. */ - ret = handle->pvar->get_value (handle->pvar, value, handle->obj_handle); + ret = handle->pvar->get_value(handle->pvar, value, handle->obj_handle); } return ret; } -int mca_base_pvar_handle_write_value (mca_base_pvar_handle_t *handle, const void *value) +int mca_base_pvar_handle_write_value(mca_base_pvar_handle_t *handle, const void *value) { int ret; - if (mca_base_pvar_is_invalid (handle->pvar)) { + if (mca_base_pvar_is_invalid(handle->pvar)) { return OPAL_ERR_NOT_BOUND; } - if (mca_base_pvar_is_readonly (handle->pvar)) { + if (mca_base_pvar_is_readonly(handle->pvar)) { return OPAL_ERR_PERM; } /* write the value directly from the variable. */ - ret = handle->pvar->set_value (handle->pvar, value, handle->obj_handle); + ret = handle->pvar->set_value(handle->pvar, value, handle->obj_handle); - ret = mca_base_pvar_handle_update (handle); + ret = mca_base_pvar_handle_update(handle); if (OPAL_SUCCESS != ret) { return ret; } - memmove (handle->current_value, value, handle->count * ompi_var_type_sizes[handle->pvar->type]); + memmove(handle->current_value, value, handle->count * ompi_var_type_sizes[handle->pvar->type]); /* read the value directly from the variable. */ - ret = handle->pvar->set_value (handle->pvar, value, handle->obj_handle); + ret = handle->pvar->set_value(handle->pvar, value, handle->obj_handle); return OPAL_SUCCESS; } -int mca_base_pvar_handle_start (mca_base_pvar_handle_t *handle) +int mca_base_pvar_handle_start(mca_base_pvar_handle_t *handle) { int ret; /* Can't start a continuous or an already started variable */ - if ((handle->pvar->flags & MCA_BASE_PVAR_FLAG_CONTINUOUS) || - handle->started) { + if ((handle->pvar->flags & MCA_BASE_PVAR_FLAG_CONTINUOUS) || handle->started) { return OPAL_ERR_NOT_SUPPORTED; } /* Notify the variable that a handle has started */ - ret = mca_base_pvar_notify (handle, MCA_BASE_PVAR_HANDLE_START, NULL); + ret = mca_base_pvar_notify(handle, MCA_BASE_PVAR_HANDLE_START, NULL); if (OPAL_SUCCESS != ret) { return ret; } handle->started = true; - if (mca_base_pvar_is_sum (handle->pvar)) { + if (mca_base_pvar_is_sum(handle->pvar)) { /* Keep track of the counter value from when this counter started. */ - ret = handle->pvar->get_value (handle->pvar, handle->last_value, handle->obj_handle); + ret = handle->pvar->get_value(handle->pvar, handle->last_value, handle->obj_handle); if (OPAL_SUCCESS != ret) { return ret; } - } else if (mca_base_pvar_is_watermark (handle->pvar)) { - /* Find the current watermark. is this correct in the case where a watermark is started, stopped, - then restarted? Probably will need to add a check. */ - ret = handle->pvar->get_value (handle->pvar, handle->current_value, handle->obj_handle); + } else if (mca_base_pvar_is_watermark(handle->pvar)) { + /* Find the current watermark. is this correct in the case where a watermark is started, + stopped, then restarted? Probably will need to add a check. */ + ret = handle->pvar->get_value(handle->pvar, handle->current_value, handle->obj_handle); if (OPAL_SUCCESS != ret) { return ret; } @@ -754,26 +767,26 @@ int mca_base_pvar_handle_start (mca_base_pvar_handle_t *handle) return OPAL_SUCCESS; } -int mca_base_pvar_handle_stop (mca_base_pvar_handle_t *handle) +int mca_base_pvar_handle_stop(mca_base_pvar_handle_t *handle) { int ret; - if (mca_base_pvar_is_invalid (handle->pvar)) { + if (mca_base_pvar_is_invalid(handle->pvar)) { return OPAL_ERR_NOT_BOUND; } /* Can't stop a continuous or an already stopped variable */ - if (!mca_base_pvar_handle_is_running (handle) || mca_base_pvar_is_continuous (handle->pvar)) { + if (!mca_base_pvar_handle_is_running(handle) || mca_base_pvar_is_continuous(handle->pvar)) { return OPAL_ERR_NOT_SUPPORTED; } - ret = mca_base_pvar_handle_update (handle); + ret = mca_base_pvar_handle_update(handle); if (OPAL_SUCCESS != ret) { return ret; } /* Notify the variable that a handle has stopped */ - (void) mca_base_pvar_notify (handle, MCA_BASE_PVAR_HANDLE_STOP, NULL); + (void) mca_base_pvar_notify(handle, MCA_BASE_PVAR_HANDLE_STOP, NULL); /* Handle is stopped */ handle->started = false; @@ -781,27 +794,28 @@ int mca_base_pvar_handle_stop (mca_base_pvar_handle_t *handle) return OPAL_SUCCESS; } -int mca_base_pvar_handle_reset (mca_base_pvar_handle_t *handle) +int mca_base_pvar_handle_reset(mca_base_pvar_handle_t *handle) { int ret = OPAL_SUCCESS; - if (mca_base_pvar_is_invalid (handle->pvar)) { + if (mca_base_pvar_is_invalid(handle->pvar)) { return OPAL_ERR_NOT_BOUND; } /* reset this handle to a state analagous to when it was created */ - if (mca_base_pvar_is_sum (handle->pvar)) { + if (mca_base_pvar_is_sum(handle->pvar)) { /* reset the running sum to 0 */ - memset (handle->current_value, 0, handle->count * ompi_var_type_sizes[handle->pvar->type]); + memset(handle->current_value, 0, handle->count * ompi_var_type_sizes[handle->pvar->type]); - if (mca_base_pvar_handle_is_running (handle)) { - ret = handle->pvar->get_value (handle->pvar, handle->last_value, handle->obj_handle); + if (mca_base_pvar_handle_is_running(handle)) { + ret = handle->pvar->get_value(handle->pvar, handle->last_value, handle->obj_handle); } - } else if (mca_base_pvar_handle_is_running (handle) && mca_base_pvar_is_watermark (handle->pvar)) { - /* watermarks should get set to the current value if runnning. */ + } else if (mca_base_pvar_handle_is_running(handle) + && mca_base_pvar_is_watermark(handle->pvar)) { + /* watermarks should get set to the current value if runnning. */ - ret = handle->pvar->get_value (handle->pvar, handle->current_value, handle->obj_handle); - } else if (mca_base_pvar_is_readonly (handle->pvar)) { + ret = handle->pvar->get_value(handle->pvar, handle->current_value, handle->obj_handle); + } else if (mca_base_pvar_is_readonly(handle->pvar)) { return OPAL_ERR_PERM; } /* NTH: TODO -- Actually write the value for variable of other types */ @@ -818,12 +832,12 @@ int mca_base_pvar_dump(int index, char ***out, mca_base_var_dump_type_t output_t int ret, enum_count = 0; char *tmp; - ret = mca_base_pvar_get (index, &pvar); + ret = mca_base_pvar_get(index, &pvar); if (OPAL_SUCCESS != ret) { return ret; } - ret = mca_base_var_group_get_internal (pvar->group_index, &group, true); + ret = mca_base_var_group_get_internal(pvar->group_index, &group, true); if (OPAL_SUCCESS != ret) { return ret; } @@ -839,53 +853,56 @@ int mca_base_pvar_dump(int index, char ***out, mca_base_var_dump_type_t output_t if (MCA_BASE_VAR_DUMP_PARSABLE == output_type) { line_count = 5 + !!(pvar->description) + enum_count; - *out = (char **) calloc (line_count + 1, sizeof (char *)); + *out = (char **) calloc(line_count + 1, sizeof(char *)); if (NULL == *out) { return OPAL_ERR_OUT_OF_RESOURCE; } /* build the message*/ - (void)opal_asprintf(&tmp, "mca:%s:%s:pvar:%s:", framework, component, full_name); + (void) opal_asprintf(&tmp, "mca:%s:%s:pvar:%s:", framework, component, full_name); - (void)opal_asprintf(out[0] + line++, "%sclass:%s", tmp, pvar_class_names[pvar->var_class]); - (void)opal_asprintf(out[0] + line++, "%sread-only:%s", tmp, mca_base_pvar_is_readonly(pvar) ? "true" : "false"); - (void)opal_asprintf(out[0] + line++, "%scontinuous:%s", tmp, mca_base_pvar_is_continuous(pvar) ? "true" : "false"); - (void)opal_asprintf(out[0] + line++, "%satomic:%s", tmp, mca_base_pvar_is_atomic(pvar) ? "true" : "false"); + (void) opal_asprintf(out[0] + line++, "%sclass:%s", tmp, pvar_class_names[pvar->var_class]); + (void) opal_asprintf(out[0] + line++, "%sread-only:%s", tmp, + mca_base_pvar_is_readonly(pvar) ? "true" : "false"); + (void) opal_asprintf(out[0] + line++, "%scontinuous:%s", tmp, + mca_base_pvar_is_continuous(pvar) ? "true" : "false"); + (void) opal_asprintf(out[0] + line++, "%satomic:%s", tmp, + mca_base_pvar_is_atomic(pvar) ? "true" : "false"); /* if it has a help message, output the help message */ if (pvar->description) { - (void)opal_asprintf(out[0] + line++, "%shelp:%s", tmp, pvar->description); + (void) opal_asprintf(out[0] + line++, "%shelp:%s", tmp, pvar->description); } if (NULL != pvar->enumerator) { - for (i = 0 ; i < enum_count ; ++i) { + for (i = 0; i < enum_count; ++i) { const char *enum_string = NULL; int enum_value; - ret = pvar->enumerator->get_value(pvar->enumerator, i, &enum_value, - &enum_string); + ret = pvar->enumerator->get_value(pvar->enumerator, i, &enum_value, &enum_string); if (OPAL_SUCCESS != ret) { continue; } - (void)opal_asprintf(out[0] + line++, "%senumerator:value:%d:%s", tmp, enum_value, enum_string); + (void) opal_asprintf(out[0] + line++, "%senumerator:value:%d:%s", tmp, enum_value, + enum_string); } } - (void)opal_asprintf(out[0] + line++, "%stype:%s", tmp, ompi_var_type_names[pvar->type]); - free(tmp); // release tmp storage + (void) opal_asprintf(out[0] + line++, "%stype:%s", tmp, ompi_var_type_names[pvar->type]); + free(tmp); // release tmp storage } else { /* there will be at most three lines in the pretty print case */ - *out = (char **) calloc (3, sizeof (char *)); + *out = (char **) calloc(3, sizeof(char *)); if (NULL == *out) { return OPAL_ERR_OUT_OF_RESOURCE; } - (void)opal_asprintf (out[0] + line++, "performance \"%s\" (type: %s, class: %s)", full_name, - ompi_var_type_names[pvar->type], pvar_class_names[pvar->var_class]); + (void) opal_asprintf(out[0] + line++, "performance \"%s\" (type: %s, class: %s)", full_name, + ompi_var_type_names[pvar->type], pvar_class_names[pvar->var_class]); if (pvar->description) { - (void)opal_asprintf(out[0] + line++, "%s", pvar->description); + (void) opal_asprintf(out[0] + line++, "%s", pvar->description); } if (NULL != pvar->enumerator) { @@ -893,8 +910,8 @@ int mca_base_pvar_dump(int index, char ***out, mca_base_var_dump_type_t output_t ret = pvar->enumerator->dump(pvar->enumerator, &values); if (OPAL_SUCCESS == ret) { - (void)opal_asprintf (out[0] + line++, "Values: %s", values); - free (values); + (void) opal_asprintf(out[0] + line++, "Values: %s", values); + free(values); } } } @@ -903,20 +920,20 @@ int mca_base_pvar_dump(int index, char ***out, mca_base_var_dump_type_t output_t } /* mca_base_pvar_t class */ -static void mca_base_pvar_contructor (mca_base_pvar_t *pvar) +static void mca_base_pvar_contructor(mca_base_pvar_t *pvar) { - memset ((char *) pvar + sizeof (pvar->super), 0, sizeof (*pvar) - sizeof (pvar->super)); + memset((char *) pvar + sizeof(pvar->super), 0, sizeof(*pvar) - sizeof(pvar->super)); OBJ_CONSTRUCT(&pvar->bound_handles, opal_list_t); } -static void mca_base_pvar_destructor (mca_base_pvar_t *pvar) +static void mca_base_pvar_destructor(mca_base_pvar_t *pvar) { if (pvar->name) { - free (pvar->name); + free(pvar->name); } if (pvar->description) { - free (pvar->description); + free(pvar->description); } if (NULL != pvar->enumerator) { @@ -926,22 +943,23 @@ static void mca_base_pvar_destructor (mca_base_pvar_t *pvar) OBJ_DESTRUCT(&pvar->bound_handles); } -OBJ_CLASS_INSTANCE(mca_base_pvar_t, opal_object_t, mca_base_pvar_contructor, mca_base_pvar_destructor); +OBJ_CLASS_INSTANCE(mca_base_pvar_t, opal_object_t, mca_base_pvar_contructor, + mca_base_pvar_destructor); /* mca_base_pvar_session_t class */ -static void opal_mpi_pvar_session_constructor (mca_base_pvar_session_t *session) +static void opal_mpi_pvar_session_constructor(mca_base_pvar_session_t *session) { OBJ_CONSTRUCT(&session->handles, opal_list_t); } -static void opal_mpi_pvar_session_destructor (mca_base_pvar_session_t *session) +static void opal_mpi_pvar_session_destructor(mca_base_pvar_session_t *session) { mca_base_pvar_handle_t *handle, *next; /* it is likely a user error if there are any allocated handles when the session * is freed. clean it up anyway. The handle destructor will remove the handle from * the session's handle list. */ - OPAL_LIST_FOREACH_SAFE(handle, next, &session->handles, mca_base_pvar_handle_t) { + OPAL_LIST_FOREACH_SAFE (handle, next, &session->handles, mca_base_pvar_handle_t) { OBJ_DESTRUCT(handle); } @@ -952,41 +970,41 @@ OBJ_CLASS_INSTANCE(mca_base_pvar_session_t, opal_object_t, opal_mpi_pvar_session opal_mpi_pvar_session_destructor); /* mca_base_pvar_handle_t class */ -static void mca_base_pvar_handle_constructor (mca_base_pvar_handle_t *handle) +static void mca_base_pvar_handle_constructor(mca_base_pvar_handle_t *handle) { - memset ((char *) handle + sizeof (handle->super), 0, sizeof (*handle) - sizeof (handle->super)); + memset((char *) handle + sizeof(handle->super), 0, sizeof(*handle) - sizeof(handle->super)); OBJ_CONSTRUCT(&handle->list2, opal_list_item_t); } -static void mca_base_pvar_handle_destructor (mca_base_pvar_handle_t *handle) +static void mca_base_pvar_handle_destructor(mca_base_pvar_handle_t *handle) { if (handle->pvar) { - (void) mca_base_pvar_notify (handle, MCA_BASE_PVAR_HANDLE_UNBIND, NULL); + (void) mca_base_pvar_notify(handle, MCA_BASE_PVAR_HANDLE_UNBIND, NULL); } if (NULL != handle->last_value) { - free (handle->last_value); + free(handle->last_value); } if (NULL != handle->current_value) { - free (handle->current_value); + free(handle->current_value); } if (NULL != handle->tmp_value) { - free (handle->tmp_value); + free(handle->tmp_value); } /* remove this handle from the pvar list */ if (handle->pvar) { - opal_list_remove_item (&handle->pvar->bound_handles, &handle->list2); + opal_list_remove_item(&handle->pvar->bound_handles, &handle->list2); } OBJ_DESTRUCT(&handle->list2); /* remove this handle from the session */ if (handle->session) { - opal_list_remove_item (&handle->session->handles, &handle->super); + opal_list_remove_item(&handle->session->handles, &handle->super); } } diff --git a/opal/mca/base/mca_base_pvar.h b/opal/mca/base/mca_base_pvar.h index 03ff53b98f8..ff50b9d44c1 100644 --- a/opal/mca/base/mca_base_pvar.h +++ b/opal/mca/base/mca_base_pvar.h @@ -12,9 +12,9 @@ */ #if !defined(OPAL_MPIT_PVAR_H) -#define OPAL_MPIT_PVAR_H +# define OPAL_MPIT_PVAR_H -#include "opal/mca/base/mca_base_var.h" +# include "opal/mca/base/mca_base_var.h" /* * These flags are used when registering a new pvar. @@ -27,20 +27,20 @@ typedef enum { manually when you register a variable with mca_base_pvar_register(). Analogous to the MCA_BASE_VAR_FLAG_DWG flag. */ - MCA_BASE_PVAR_FLAG_IWG = 0x040, + MCA_BASE_PVAR_FLAG_IWG = 0x040, /** This variable can not be written. Will be ignored for counter, timer, and aggregate variables. These variable handles will be updated relative to the value reported by the get_value() function provided at registration time. */ - MCA_BASE_PVAR_FLAG_READONLY = 0x080, + MCA_BASE_PVAR_FLAG_READONLY = 0x080, /** This variable runs continuously after being bound to a handle. */ MCA_BASE_PVAR_FLAG_CONTINUOUS = 0x100, /** This variable can be updated atomically. This flag is ignored by mca_base_pvar_register() at this time. */ - MCA_BASE_PVAR_FLAG_ATOMIC = 0x200, + MCA_BASE_PVAR_FLAG_ATOMIC = 0x200, /** This variable has been marked as invalid. This flag is ignored by mca_base_pvar_register(). */ - MCA_BASE_PVAR_FLAG_INVALID = 0x400, + MCA_BASE_PVAR_FLAG_INVALID = 0x400, } mca_base_pvar_flag_t; /* @@ -94,7 +94,7 @@ enum { MCA_BASE_PVAR_CLASS_GENERIC }; -#define MCA_BASE_PVAR_CLASS_ANY -1 +# define MCA_BASE_PVAR_CLASS_ANY -1 /* * Reserved bindings; passed when registering a new pvar. OPAL will @@ -128,7 +128,7 @@ struct mca_base_pvar_t; * pointer will be large enough to hold the datatype and count specified when this * variable was created and bound. */ -typedef int (*mca_base_get_value_fn_t) (const struct mca_base_pvar_t *pvar, void *value, void *obj); +typedef int (*mca_base_get_value_fn_t)(const struct mca_base_pvar_t *pvar, void *value, void *obj); /** * Function to set the current value of a variable. @@ -142,7 +142,7 @@ typedef int (*mca_base_get_value_fn_t) (const struct mca_base_pvar_t *pvar, void * variable was created and bound. Read-only variables are not expected to provide * this function. */ -typedef int (*mca_base_set_value_fn_t) (struct mca_base_pvar_t *pvar, const void *value, void *obj); +typedef int (*mca_base_set_value_fn_t)(struct mca_base_pvar_t *pvar, const void *value, void *obj); /** * Function to notify of a pvar handle event. @@ -158,7 +158,8 @@ typedef int (*mca_base_set_value_fn_t) (struct mca_base_pvar_t *pvar, const void * On MCA_BASE_PVAR_HANDLE_START: enable the performance variable. * On MCA_BASE_PVAR_HANDLE_STOP: XXX -- TODO -- finish me */ -typedef int (*mca_base_notify_fn_t) (struct mca_base_pvar_t *pvar, mca_base_pvar_event_t event, void *obj, int *count); +typedef int (*mca_base_notify_fn_t)(struct mca_base_pvar_t *pvar, mca_base_pvar_event_t event, + void *obj, int *count); /** * Structure representing an OPAL performance variable. @@ -311,11 +312,12 @@ OBJ_CLASS_DECLARATION(mca_base_pvar_handle_t); * Note: if used incorrectly this function may fail an assert(); see * MPI 3.0 14.3 to see acceptable values for datatype given the class. */ -OPAL_DECLSPEC int mca_base_pvar_register (const char *project, const char *framework, const char *component, const char *name, - const char *description, mca_base_var_info_lvl_t verbosity, - int var_class, mca_base_var_type_t type, mca_base_var_enum_t *enumerator, - int bind, mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, - mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, void *ctx); +OPAL_DECLSPEC int +mca_base_pvar_register(const char *project, const char *framework, const char *component, + const char *name, const char *description, mca_base_var_info_lvl_t verbosity, + int var_class, mca_base_var_type_t type, mca_base_var_enum_t *enumerator, + int bind, mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, + mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, void *ctx); /** * Convinience function for registering a performance variable @@ -326,12 +328,12 @@ OPAL_DECLSPEC int mca_base_pvar_register (const char *project, const char *frame * be unregistered / made unavailable when that component is closed by * its framework. */ -OPAL_DECLSPEC int mca_base_component_pvar_register (const mca_base_component_t *component, const char *name, - const char *description, mca_base_var_info_lvl_t verbosity, int var_class, - mca_base_var_type_t type, mca_base_var_enum_t *enumerator, int bind, - mca_base_pvar_flag_t flags, mca_base_get_value_fn_t get_value, - mca_base_set_value_fn_t set_value, mca_base_notify_fn_t notify, void *ctx); - +OPAL_DECLSPEC int mca_base_component_pvar_register( + const mca_base_component_t *component, const char *name, const char *description, + mca_base_var_info_lvl_t verbosity, int var_class, mca_base_var_type_t type, + mca_base_var_enum_t *enumerator, int bind, mca_base_pvar_flag_t flags, + mca_base_get_value_fn_t get_value, mca_base_set_value_fn_t set_value, + mca_base_notify_fn_t notify, void *ctx); /** * Find the index for an MCA performance variable based on its names. @@ -351,7 +353,8 @@ OPAL_DECLSPEC int mca_base_component_pvar_register (const mca_base_component_t * * mca_base_pvar_get(), mca_base_pvar_handle_alloc(), and * mca_base_pvar_dump(). */ -OPAL_DECLSPEC int mca_base_pvar_find (const char *project, const char *framework, const char *component, const char *name); +OPAL_DECLSPEC int mca_base_pvar_find(const char *project, const char *framework, + const char *component, const char *name); /** * Find the index for a performance variable based on its full name @@ -361,7 +364,7 @@ OPAL_DECLSPEC int mca_base_pvar_find (const char *project, const char *framework * * See mca_base_pvar_find(). */ -OPAL_DECLSPEC int mca_base_pvar_find_by_name (const char *full_name, int var_class, int *index); +OPAL_DECLSPEC int mca_base_pvar_find_by_name(const char *full_name, int var_class, int *index); /**************************************************************************** * The following functions are the back-end to the MPI_T API functions @@ -376,7 +379,7 @@ OPAL_DECLSPEC int mca_base_pvar_find_by_name (const char *full_name, int var_cla * This function can be called before mca_base_pvar_init() and after * mca_base_pvar_finalize(). */ -OPAL_DECLSPEC int mca_base_pvar_get_count (int *count); +OPAL_DECLSPEC int mca_base_pvar_get_count(int *count); /** * Update the handles associated with the specified performance variable and MPI object @@ -389,7 +392,7 @@ OPAL_DECLSPEC int mca_base_pvar_get_count (int *count); * is recommended this function not be called from within any critical code path. Calling * this function should only be necessary to update watermarks. */ -OPAL_DECLSPEC int mca_base_pvar_update_all_handles (int index, const void *obj); +OPAL_DECLSPEC int mca_base_pvar_update_all_handles(int index, const void *obj); /** * Get the variable at an index @@ -400,7 +403,7 @@ OPAL_DECLSPEC int mca_base_pvar_update_all_handles (int index, const void *obj); * @returns OPAL_SUCCESS on success * @returns OPAL_ERR_VALUE_OUT_OF_BOUNDS on if index is out of range */ -OPAL_DECLSPEC int mca_base_pvar_get (int index, const mca_base_pvar_t **pvar); +OPAL_DECLSPEC int mca_base_pvar_get(int index, const mca_base_pvar_t **pvar); /** * Dump strings describing the performance variable at an index @@ -423,40 +426,40 @@ OPAL_DECLSPEC int mca_base_pvar_dump(int index, char ***out, mca_base_var_dump_t * A performance variable that has been marked as invalid will not be available. To * restore a performance variable it has to be re-registered using mca_base_pvar_register(). */ -int mca_base_pvar_mark_invalid (int index); +int mca_base_pvar_mark_invalid(int index); /** * Convienience functions for performance variables */ -static inline bool mca_base_pvar_is_sum (const mca_base_pvar_t *pvar) +static inline bool mca_base_pvar_is_sum(const mca_base_pvar_t *pvar) { - return (MCA_BASE_PVAR_CLASS_COUNTER == pvar->var_class || - MCA_BASE_PVAR_CLASS_TIMER == pvar->var_class || - MCA_BASE_PVAR_CLASS_AGGREGATE == pvar->var_class); + return (MCA_BASE_PVAR_CLASS_COUNTER == pvar->var_class + || MCA_BASE_PVAR_CLASS_TIMER == pvar->var_class + || MCA_BASE_PVAR_CLASS_AGGREGATE == pvar->var_class); } -static inline bool mca_base_pvar_is_watermark (const mca_base_pvar_t *pvar) +static inline bool mca_base_pvar_is_watermark(const mca_base_pvar_t *pvar) { - return (MCA_BASE_PVAR_CLASS_HIGHWATERMARK == pvar->var_class || - MCA_BASE_PVAR_CLASS_LOWWATERMARK == pvar->var_class); + return (MCA_BASE_PVAR_CLASS_HIGHWATERMARK == pvar->var_class + || MCA_BASE_PVAR_CLASS_LOWWATERMARK == pvar->var_class); } -static inline bool mca_base_pvar_is_readonly (const mca_base_pvar_t *pvar) +static inline bool mca_base_pvar_is_readonly(const mca_base_pvar_t *pvar) { return !!(pvar->flags & MCA_BASE_PVAR_FLAG_READONLY); } -static inline bool mca_base_pvar_is_continuous (const mca_base_pvar_t *pvar) +static inline bool mca_base_pvar_is_continuous(const mca_base_pvar_t *pvar) { return !!(pvar->flags & MCA_BASE_PVAR_FLAG_CONTINUOUS); } -static inline bool mca_base_pvar_is_atomic (const mca_base_pvar_t *pvar) +static inline bool mca_base_pvar_is_atomic(const mca_base_pvar_t *pvar) { return !!(pvar->flags & MCA_BASE_PVAR_FLAG_ATOMIC); } -static inline bool mca_base_pvar_is_invalid (const mca_base_pvar_t *pvar) +static inline bool mca_base_pvar_is_invalid(const mca_base_pvar_t *pvar) { return !!(pvar->flags & MCA_BASE_PVAR_FLAG_INVALID); } @@ -479,8 +482,9 @@ static inline bool mca_base_pvar_is_invalid (const mca_base_pvar_t *pvar) * hold \count values of the type of the performance variable specified by * \index. */ -OPAL_DECLSPEC int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, int index, void *obj_handle, - mca_base_pvar_handle_t **handle, int *count); +OPAL_DECLSPEC int mca_base_pvar_handle_alloc(mca_base_pvar_session_t *session, int index, + void *obj_handle, mca_base_pvar_handle_t **handle, + int *count); /** * Free an allocated performance variable handle @@ -489,7 +493,7 @@ OPAL_DECLSPEC int mca_base_pvar_handle_alloc (mca_base_pvar_session_t *session, * * After calling this function the performance variable will no longer be valid. */ -OPAL_DECLSPEC int mca_base_pvar_handle_free (mca_base_pvar_handle_t *handle); +OPAL_DECLSPEC int mca_base_pvar_handle_free(mca_base_pvar_handle_t *handle); /** * Update a performance variable handle. @@ -502,7 +506,7 @@ OPAL_DECLSPEC int mca_base_pvar_handle_free (mca_base_pvar_handle_t *handle); * the new value will be the greater/lesser of the current handle value and the * current variable value. This call does not update other types of handles. */ -OPAL_DECLSPEC int mca_base_pvar_handle_update (mca_base_pvar_handle_t *handle); +OPAL_DECLSPEC int mca_base_pvar_handle_update(mca_base_pvar_handle_t *handle); /** * Read the current value of a handle @@ -514,7 +518,7 @@ OPAL_DECLSPEC int mca_base_pvar_handle_update (mca_base_pvar_handle_t *handle); * and return it in the buffer specified by value. The buffer must be large enough to * hold the correct number and type of this handle's value (see mca_base_pvar_handle_update()). */ -OPAL_DECLSPEC int mca_base_pvar_handle_read_value (mca_base_pvar_handle_t *handle, void *value); +OPAL_DECLSPEC int mca_base_pvar_handle_read_value(mca_base_pvar_handle_t *handle, void *value); /** * Write a value to a read-write handle @@ -524,7 +528,8 @@ OPAL_DECLSPEC int mca_base_pvar_handle_read_value (mca_base_pvar_handle_t *handl * * If the underlying variable is read-only this function will fail with OPAL_ERR_PERM. */ -OPAL_DECLSPEC int mca_base_pvar_handle_write_value (mca_base_pvar_handle_t *handle, const void *value); +OPAL_DECLSPEC int mca_base_pvar_handle_write_value(mca_base_pvar_handle_t *handle, + const void *value); /** * Convienience function for sending notification of a handle change @@ -533,7 +538,8 @@ OPAL_DECLSPEC int mca_base_pvar_handle_write_value (mca_base_pvar_handle_t *hand * @param[in] event Event that occurred * @param[out] count Value count returned when binding a handle */ -OPAL_DECLSPEC int mca_base_pvar_notify (mca_base_pvar_handle_t *handle, mca_base_pvar_event_t event, int *count); +OPAL_DECLSPEC int mca_base_pvar_notify(mca_base_pvar_handle_t *handle, mca_base_pvar_event_t event, + int *count); /** * Start a performance variable handle @@ -543,7 +549,7 @@ OPAL_DECLSPEC int mca_base_pvar_notify (mca_base_pvar_handle_t *handle, mca_base * @returns OPAL_SUCCESS on success * @returns OPAL_ERR_NOT_SUPPORTED if the handle could not be started */ -OPAL_DECLSPEC int mca_base_pvar_handle_start (mca_base_pvar_handle_t *handle); +OPAL_DECLSPEC int mca_base_pvar_handle_start(mca_base_pvar_handle_t *handle); /** * Stop a performance variable handle @@ -553,7 +559,7 @@ OPAL_DECLSPEC int mca_base_pvar_handle_start (mca_base_pvar_handle_t *handle); * @return OPAL_SUCCESS on success * @returns OPAL_ERR_NOT_SUPPORTED if the handle could not be started */ -OPAL_DECLSPEC int mca_base_pvar_handle_stop (mca_base_pvar_handle_t *handle); +OPAL_DECLSPEC int mca_base_pvar_handle_stop(mca_base_pvar_handle_t *handle); /** * Reset a performance variable handle @@ -562,9 +568,9 @@ OPAL_DECLSPEC int mca_base_pvar_handle_stop (mca_base_pvar_handle_t *handle); * * Reset the handle to a value equivalent to when the handle was first allocated. */ -OPAL_DECLSPEC int mca_base_pvar_handle_reset (mca_base_pvar_handle_t *handle); +OPAL_DECLSPEC int mca_base_pvar_handle_reset(mca_base_pvar_handle_t *handle); -static inline bool mca_base_pvar_handle_is_running (mca_base_pvar_handle_t *handle) +static inline bool mca_base_pvar_handle_is_running(mca_base_pvar_handle_t *handle) { return handle->started || !!(handle->pvar->flags & MCA_BASE_PVAR_FLAG_CONTINUOUS); } diff --git a/opal/mca/base/mca_base_var.c b/opal/mca/base/mca_base_var.c index 71203421d7d..28a6a5541ba 100644 --- a/opal/mca/base/mca_base_var.c +++ b/opal/mca/base/mca_base_var.c @@ -32,30 +32,30 @@ #include "opal_config.h" #include -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #include +#include "opal/constants.h" #include "opal/include/opal_stdint.h" +#include "opal/mca/base/mca_base_alias.h" +#include "opal/mca/base/mca_base_vari.h" #include "opal/mca/installdirs/installdirs.h" +#include "opal/mca/mca.h" +#include "opal/runtime/opal.h" +#include "opal/util/argv.h" +#include "opal/util/opal_environ.h" #include "opal/util/os_path.h" +#include "opal/util/output.h" #include "opal/util/path.h" -#include "opal/util/show_help.h" #include "opal/util/printf.h" -#include "opal/util/argv.h" -#include "opal/mca/mca.h" -#include "opal/mca/base/mca_base_vari.h" -#include "opal/mca/base/mca_base_alias.h" -#include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/util/opal_environ.h" -#include "opal/runtime/opal.h" +#include "opal/util/show_help.h" /* * local variables @@ -63,9 +63,9 @@ static opal_pointer_array_t mca_base_vars; static const char *mca_prefix = OPAL_MCA_PREFIX; static char *home = NULL; -static char *cwd = NULL; +static char *cwd = NULL; bool mca_base_var_initialized = false; -static char * force_agg_path = NULL; +static char *force_agg_path = NULL; static char *mca_base_var_files = NULL; static char *mca_base_envar_files = NULL; static char **mca_base_var_file_list = NULL; @@ -85,92 +85,56 @@ static int mca_base_var_count = 0; static opal_hash_table_t mca_base_var_index_hash; -#define OPAL_MCA_VAR_MBV_ENUMERATOR_FREE(mbv_enumerator) { \ - if(mbv_enumerator && !mbv_enumerator->enum_is_static) { \ - OBJ_RELEASE(mbv_enumerator); \ - } \ -} +#define OPAL_MCA_VAR_MBV_ENUMERATOR_FREE(mbv_enumerator) \ + { \ + if (mbv_enumerator && !mbv_enumerator->enum_is_static) { \ + OBJ_RELEASE(mbv_enumerator); \ + } \ + } const char *ompi_var_type_names[] = { - "int", - "unsigned_int", - "unsigned_long", - "unsigned_long_long", - "size_t", - "string", - "version_string", - "bool", - "double", - "long", - "int32_t", - "uint32_t", - "int64_t", - "uint64_t", + "int", "unsigned_int", "unsigned_long", "unsigned_long_long", + "size_t", "string", "version_string", "bool", + "double", "long", "int32_t", "uint32_t", + "int64_t", "uint64_t", }; const size_t ompi_var_type_sizes[] = { - sizeof (int), - sizeof (unsigned), - sizeof (unsigned long), - sizeof (unsigned long long), - sizeof (size_t), - sizeof (char), - sizeof (char), - sizeof (bool), - sizeof (double), - sizeof (long), - sizeof (int32_t), - sizeof (uint32_t), - sizeof (int64_t), - sizeof (uint64_t), -}; - -static const char *var_source_names[] = { - "default", - "command line", - "environment", - "file", - "set", - "override" + sizeof(int), sizeof(unsigned), sizeof(unsigned long), sizeof(unsigned long long), + sizeof(size_t), sizeof(char), sizeof(char), sizeof(bool), + sizeof(double), sizeof(long), sizeof(int32_t), sizeof(uint32_t), + sizeof(int64_t), sizeof(uint64_t), }; +static const char *var_source_names[] = {"default", "command line", "environment", + "file", "set", "override"}; -static const char *info_lvl_strings[] = { - "user/basic", - "user/detail", - "user/all", - "tuner/basic", - "tuner/detail", - "tuner/all", - "dev/basic", - "dev/detail", - "dev/all" -}; +static const char *info_lvl_strings[] = {"user/basic", "user/detail", "user/all", + "tuner/basic", "tuner/detail", "tuner/all", + "dev/basic", "dev/detail", "dev/all"}; /* * local functions */ -static int fixup_files(char **file_list, char * path, bool rel_path_search, char sep); -static int read_files (char *file_list, opal_list_t *file_values, char sep); -static int var_set_initial (mca_base_var_t *var, mca_base_var_t *original); -static int var_get (int vari, mca_base_var_t **var_out, bool original); -static int var_value_string (mca_base_var_t *var, char **value_string); -static void mca_base_var_finalize (void); +static int fixup_files(char **file_list, char *path, bool rel_path_search, char sep); +static int read_files(char *file_list, opal_list_t *file_values, char sep); +static int var_set_initial(mca_base_var_t *var, mca_base_var_t *original); +static int var_get(int vari, mca_base_var_t **var_out, bool original); +static int var_value_string(mca_base_var_t *var, char **value_string); +static void mca_base_var_finalize(void); /* * classes */ -static void var_constructor (mca_base_var_t *p); -static void var_destructor (mca_base_var_t *p); -OBJ_CLASS_INSTANCE(mca_base_var_t, opal_object_t, - var_constructor, var_destructor); +static void var_constructor(mca_base_var_t *p); +static void var_destructor(mca_base_var_t *p); +OBJ_CLASS_INSTANCE(mca_base_var_t, opal_object_t, var_constructor, var_destructor); -static void fv_constructor (mca_base_var_file_value_t *p); -static void fv_destructor (mca_base_var_file_value_t *p); -OBJ_CLASS_INSTANCE(mca_base_var_file_value_t, opal_list_item_t, - fv_constructor, fv_destructor); +static void fv_constructor(mca_base_var_file_value_t *p); +static void fv_destructor(mca_base_var_file_value_t *p); +OBJ_CLASS_INSTANCE(mca_base_var_file_value_t, opal_list_item_t, fv_constructor, fv_destructor); -static const char *mca_base_var_source_file (const mca_base_var_t *var) +static const char *mca_base_var_source_file(const mca_base_var_t *var) { mca_base_var_file_value_t *fv = (mca_base_var_file_value_t *) var->mbv_file_value; @@ -188,34 +152,34 @@ static const char *mca_base_var_source_file (const mca_base_var_t *var) /* * Generate a full name from three names */ -int mca_base_var_generate_full_name4 (const char *project, const char *framework, const char *component, - const char *variable, char **full_name) +int mca_base_var_generate_full_name4(const char *project, const char *framework, + const char *component, const char *variable, char **full_name) { - const char * const names[] = {project, framework, component, variable}; + const char *const names[] = {project, framework, component, variable}; char *name, *tmp; size_t i, len; *full_name = NULL; - for (i = 0, len = 0 ; i < 4 ; ++i) { + for (i = 0, len = 0; i < 4; ++i) { if (NULL != names[i]) { /* Add space for the string + _ or \0 */ - len += strlen (names[i]) + 1; + len += strlen(names[i]) + 1; } } - name = calloc (1, len); + name = calloc(1, len); if (NULL == name) { return OPAL_ERR_OUT_OF_RESOURCE; } - for (i = 0, tmp = name ; i < 4 ; ++i) { + for (i = 0, tmp = name; i < 4; ++i) { if (NULL != names[i]) { if (name != tmp) { *tmp++ = '_'; } - strncat (name, names[i], len - (size_t)(uintptr_t)(tmp - name)); - tmp += strlen (names[i]); + strncat(name, names[i], len - (size_t)(uintptr_t)(tmp - name)); + tmp += strlen(names[i]); } } @@ -223,14 +187,14 @@ int mca_base_var_generate_full_name4 (const char *project, const char *framework return OPAL_SUCCESS; } -static int compare_strings (const char *str1, const char *str2) { - if ((NULL != str1 && 0 == strcmp (str1, "*")) || - (NULL == str1 && NULL == str2)) { +static int compare_strings(const char *str1, const char *str2) +{ + if ((NULL != str1 && 0 == strcmp(str1, "*")) || (NULL == str1 && NULL == str2)) { return 0; } if (NULL != str1 && NULL != str2) { - return strcmp (str1, str2); + return strcmp(str1, str2); } return 1; @@ -249,7 +213,7 @@ static char *append_filename_to_list(const char *filename) count = opal_argv_count(mca_base_var_file_list); for (i = count - 1; i >= 0; --i) { - if (0 == strcmp (mca_base_var_file_list[i], filename)) { + if (0 == strcmp(mca_base_var_file_list[i], filename)) { return mca_base_var_file_list[i]; } } @@ -270,7 +234,7 @@ int mca_base_var_init(void) OBJ_CONSTRUCT(&mca_base_vars, opal_pointer_array_t); /* These values are arbitrary */ - ret = opal_pointer_array_init (&mca_base_vars, 128, 16384, 128); + ret = opal_pointer_array_init(&mca_base_vars, 128, 16384, 128); if (OPAL_SUCCESS != ret) { return ret; } @@ -284,29 +248,29 @@ int mca_base_var_init(void) OBJ_CONSTRUCT(&mca_base_var_override_values, opal_list_t); OBJ_CONSTRUCT(&mca_base_var_index_hash, opal_hash_table_t); - ret = opal_hash_table_init (&mca_base_var_index_hash, 1024); + ret = opal_hash_table_init(&mca_base_var_index_hash, 1024); if (OPAL_SUCCESS != ret) { return ret; } - ret = mca_base_var_group_init (); - if (OPAL_SUCCESS != ret) { + ret = mca_base_var_group_init(); + if (OPAL_SUCCESS != ret) { return ret; } - ret = mca_base_pvar_init (); + ret = mca_base_pvar_init(); if (OPAL_SUCCESS != ret) { return ret; } /* We may need this later */ - home = (char*)opal_home_directory(); + home = (char *) opal_home_directory(); if (NULL == home) { opal_output(0, "Error: Unable to get the user home directory\n"); return OPAL_ERROR; } - if( NULL == (cwd = getcwd(NULL, 0) )) { + if (NULL == (cwd = getcwd(NULL, 0))) { opal_output(0, "Error: Unable to get the current working directory\n"); cwd = strdup("."); } @@ -314,35 +278,34 @@ int mca_base_var_init(void) /* Set this before we register the parameter, below */ mca_base_var_initialized = true; - } - opal_finalize_register_cleanup (mca_base_var_finalize); + opal_finalize_register_cleanup(mca_base_var_finalize); return OPAL_SUCCESS; } static void process_env_list(char *env_list, char ***argv, char sep) { - char** tokens; + char **tokens; char *ptr, *value; - tokens = opal_argv_split(env_list, (int)sep); + tokens = opal_argv_split(env_list, (int) sep); if (NULL == tokens) { return; } - for (int i = 0 ; NULL != tokens[i] ; ++i) { + for (int i = 0; NULL != tokens[i]; ++i) { if (NULL == (ptr = strchr(tokens[i], '='))) { value = getenv(tokens[i]); if (NULL == value) { - opal_show_help("help-mca-var.txt", "incorrect-env-list-param", - true, tokens[i], env_list); + opal_show_help("help-mca-var.txt", "incorrect-env-list-param", true, tokens[i], + env_list); break; } /* duplicate the value to silence tainted string coverity issue */ - value = strdup (value); + value = strdup(value); if (NULL == value) { /* out of memory */ break; @@ -355,7 +318,7 @@ static void process_env_list(char *env_list, char ***argv, char sep) opal_setenv(tokens[i], value, true, argv); } - free (value); + free(value); } else { *ptr = '\0'; opal_setenv(tokens[i], ptr + 1, true, argv); @@ -374,8 +337,8 @@ int mca_base_var_process_env_list(char *list, char ***argv) if (1 == strlen(mca_base_env_list_sep)) { sep = mca_base_env_list_sep[0]; } else { - opal_show_help("help-mca-var.txt", "incorrect-env-list-sep", - true, mca_base_env_list_sep); + opal_show_help("help-mca-var.txt", "incorrect-env-list-sep", true, + mca_base_env_list_sep); return OPAL_SUCCESS; } } @@ -396,33 +359,35 @@ int mca_base_var_process_env_list_from_file(char ***argv) return OPAL_SUCCESS; } -static void resolve_relative_paths(char **file_prefix, char *file_path, bool rel_path_search, char **files, char sep) +static void resolve_relative_paths(char **file_prefix, char *file_path, bool rel_path_search, + char **files, char sep) { char *tmp_str; /* * Resolve all relative paths. * the file list returned will contain only absolute paths */ - if( OPAL_SUCCESS != fixup_files(file_prefix, file_path, rel_path_search, sep) ) { + if (OPAL_SUCCESS != fixup_files(file_prefix, file_path, rel_path_search, sep)) { #if 0 /* JJH We need to die! */ abort(); #else ; #endif - } - else { + } else { /* Prepend the files to the search list */ opal_asprintf(&tmp_str, "%s%c%s", *file_prefix, sep, *files); - free (*files); + free(*files); *files = tmp_str; } } -int mca_base_var_load_extra_files(char* files, bool rel_path_search) { - char *tmp1=strdup(files); - resolve_relative_paths(&tmp1, mca_base_param_file_path, rel_path_search, &mca_base_var_files, OPAL_ENV_SEP); - read_files (tmp1, &mca_base_var_file_values, ','); +int mca_base_var_load_extra_files(char *files, bool rel_path_search) +{ + char *tmp1 = strdup(files); + resolve_relative_paths(&tmp1, mca_base_param_file_path, rel_path_search, &mca_base_var_files, + OPAL_ENV_SEP); + read_files(tmp1, &mca_base_var_file_values, ','); free(tmp1); return OPAL_SUCCESS; } @@ -434,19 +399,18 @@ int mca_base_var_cache_files(bool rel_path_search) #if OPAL_WANT_HOME_CONFIG_FILES if (NULL == getenv("OPAL_USER_PARAMS_GIVEN")) { - opal_asprintf(&tmp, "%s"OPAL_PATH_SEP".openmpi" OPAL_PATH_SEP - "mca-params.conf", home); + opal_asprintf(&tmp, "%s" OPAL_PATH_SEP ".openmpi" OPAL_PATH_SEP "mca-params.conf", home); } #endif if (NULL == getenv("OPAL_SYS_PARAMS_GIVEN")) { if (NULL != tmp) { - opal_asprintf(&mca_base_var_files, "%s,%s" OPAL_PATH_SEP "openmpi-mca-params.conf", - tmp, opal_install_dirs.sysconfdir); + opal_asprintf(&mca_base_var_files, "%s,%s" OPAL_PATH_SEP "openmpi-mca-params.conf", tmp, + opal_install_dirs.sysconfdir); free(tmp); } else { opal_asprintf(&mca_base_var_files, "%s" OPAL_PATH_SEP "openmpi-mca-params.conf", - opal_install_dirs.sysconfdir); + opal_install_dirs.sysconfdir); } } else { mca_base_var_files = strdup("none"); @@ -455,48 +419,51 @@ int mca_base_var_cache_files(bool rel_path_search) /* Initialize a parameter that says where MCA param files can be found. We may change this value so set the scope to MCA_BASE_VAR_SCOPE_READONLY */ tmp = mca_base_var_files; - ret = mca_base_var_register ("opal", "mca", "base", "param_files", "Path for MCA " - "configuration files containing variable values", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_2, - MCA_BASE_VAR_SCOPE_READONLY, &mca_base_var_files); - free (tmp); + ret = mca_base_var_register("opal", "mca", "base", "param_files", + "Path for MCA " + "configuration files containing variable values", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_2, + MCA_BASE_VAR_SCOPE_READONLY, &mca_base_var_files); + free(tmp); if (0 > ret) { return ret; } mca_base_envar_files = strdup(mca_base_var_files); - (void) mca_base_var_register_synonym (ret, "opal", "mca", NULL, "param_files", - MCA_BASE_VAR_SYN_FLAG_DEPRECATED); + (void) mca_base_var_register_synonym(ret, "opal", "mca", NULL, "param_files", + MCA_BASE_VAR_SYN_FLAG_DEPRECATED); - ret = opal_asprintf(&mca_base_var_override_file, "%s" OPAL_PATH_SEP "openmpi-mca-params-override.conf", - opal_install_dirs.sysconfdir); + ret = opal_asprintf(&mca_base_var_override_file, + "%s" OPAL_PATH_SEP "openmpi-mca-params-override.conf", + opal_install_dirs.sysconfdir); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } tmp = mca_base_var_override_file; - ret = mca_base_var_register ("opal", "mca", "base", "override_param_file", - "Variables set in this file will override any value set in" - "the environment or another configuration file", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY, - OPAL_INFO_LVL_2, MCA_BASE_VAR_SCOPE_CONSTANT, - &mca_base_var_override_file); - free (tmp); + ret = mca_base_var_register("opal", "mca", "base", "override_param_file", + "Variables set in this file will override any value set in" + "the environment or another configuration file", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY, + OPAL_INFO_LVL_2, MCA_BASE_VAR_SCOPE_CONSTANT, + &mca_base_var_override_file); + free(tmp); if (0 > ret) { return ret; } /* Disable reading MCA parameter files. */ - if (0 == strcmp (mca_base_var_files, "none")) { + if (0 == strcmp(mca_base_var_files, "none")) { return OPAL_SUCCESS; } mca_base_var_suppress_override_warning = false; - ret = mca_base_var_register ("opal", "mca", "base", "suppress_override_warning", - "Suppress warnings when attempting to set an overridden value (default: false)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_2, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_base_var_suppress_override_warning); + ret = mca_base_var_register( + "opal", "mca", "base", "suppress_override_warning", + "Suppress warnings when attempting to set an overridden value (default: false)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_2, MCA_BASE_VAR_SCOPE_LOCAL, + &mca_base_var_suppress_override_warning); if (0 > ret) { return ret; } @@ -506,44 +473,44 @@ int mca_base_var_cache_files(bool rel_path_search) * requests that do not specify an absolute path */ mca_base_var_file_prefix = NULL; - ret = mca_base_var_register ("opal", "mca", "base", "param_file_prefix", - "Aggregate MCA parameter file sets", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_READONLY, &mca_base_var_file_prefix); + ret = mca_base_var_register("opal", "mca", "base", "param_file_prefix", + "Aggregate MCA parameter file sets", MCA_BASE_VAR_TYPE_STRING, NULL, + 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY, + &mca_base_var_file_prefix); if (0 > ret) { return ret; } mca_base_envar_file_prefix = NULL; - ret = mca_base_var_register ("opal", "mca", "base", "envar_file_prefix", - "Aggregate MCA parameter file set for env variables", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_READONLY, &mca_base_envar_file_prefix); + ret = mca_base_var_register("opal", "mca", "base", "envar_file_prefix", + "Aggregate MCA parameter file set for env variables", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_READONLY, &mca_base_envar_file_prefix); if (0 > ret) { return ret; } ret = opal_asprintf(&mca_base_param_file_path, "%s" OPAL_PATH_SEP "amca-param-sets%c%s", - opal_install_dirs.opaldatadir, OPAL_ENV_SEP, cwd); + opal_install_dirs.opaldatadir, OPAL_ENV_SEP, cwd); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } tmp = mca_base_param_file_path; - ret = mca_base_var_register ("opal", "mca", "base", "param_file_path", - "Aggregate MCA parameter Search path", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_READONLY, &mca_base_param_file_path); - free (tmp); + ret = mca_base_var_register("opal", "mca", "base", "param_file_path", + "Aggregate MCA parameter Search path", MCA_BASE_VAR_TYPE_STRING, + NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY, + &mca_base_param_file_path); + free(tmp); if (0 > ret) { return ret; } force_agg_path = NULL; - ret = mca_base_var_register ("opal", "mca", "base", "param_file_path_force", - "Forced Aggregate MCA parameter Search path", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_READONLY, &force_agg_path); + ret = mca_base_var_register("opal", "mca", "base", "param_file_path_force", + "Forced Aggregate MCA parameter Search path", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_READONLY, &force_agg_path); if (0 > ret) { return ret; } @@ -552,7 +519,8 @@ int mca_base_var_cache_files(bool rel_path_search) if (NULL != mca_base_param_file_path) { char *tmp_str = mca_base_param_file_path; - opal_asprintf(&mca_base_param_file_path, "%s%c%s", force_agg_path, OPAL_ENV_SEP, tmp_str); + opal_asprintf(&mca_base_param_file_path, "%s%c%s", force_agg_path, OPAL_ENV_SEP, + tmp_str); free(tmp_str); } else { mca_base_param_file_path = strdup(force_agg_path); @@ -560,17 +528,19 @@ int mca_base_var_cache_files(bool rel_path_search) } if (NULL != mca_base_var_file_prefix) { - resolve_relative_paths(&mca_base_var_file_prefix, mca_base_param_file_path, rel_path_search, &mca_base_var_files, OPAL_ENV_SEP); + resolve_relative_paths(&mca_base_var_file_prefix, mca_base_param_file_path, rel_path_search, + &mca_base_var_files, OPAL_ENV_SEP); } - read_files (mca_base_var_files, &mca_base_var_file_values, ','); + read_files(mca_base_var_files, &mca_base_var_file_values, ','); if (NULL != mca_base_envar_file_prefix) { - resolve_relative_paths(&mca_base_envar_file_prefix, mca_base_param_file_path, rel_path_search, &mca_base_envar_files, ','); + resolve_relative_paths(&mca_base_envar_file_prefix, mca_base_param_file_path, + rel_path_search, &mca_base_envar_files, ','); } - read_files (mca_base_envar_files, &mca_base_envar_file_values, ','); + read_files(mca_base_envar_files, &mca_base_envar_file_values, ','); if (0 == access(mca_base_var_override_file, F_OK)) { - read_files (mca_base_var_override_file, &mca_base_var_override_values, OPAL_ENV_SEP); + read_files(mca_base_var_override_file, &mca_base_var_override_values, OPAL_ENV_SEP); } return OPAL_SUCCESS; @@ -579,15 +549,14 @@ int mca_base_var_cache_files(bool rel_path_search) /* * Look up an integer MCA parameter. */ -int mca_base_var_get_value (int vari, const void *value, - mca_base_var_source_t *source, - const char **source_file) +int mca_base_var_get_value(int vari, const void *value, mca_base_var_source_t *source, + const char **source_file) { mca_base_var_t *var; void **tmp = (void **) value; int ret; - ret = var_get (vari, &var, true); + ret = var_get(vari, &var, true); if (OPAL_SUCCESS != ret) { return ret; } @@ -607,55 +576,54 @@ int mca_base_var_get_value (int vari, const void *value, } if (NULL != source_file) { - *source_file = mca_base_var_source_file (var); + *source_file = mca_base_var_source_file(var); } return OPAL_SUCCESS; } -static int var_set_string (mca_base_var_t *var, char *value) +static int var_set_string(mca_base_var_t *var, char *value) { char *tmp; int ret; if (NULL != var->mbv_storage->stringval) { - free (var->mbv_storage->stringval); + free(var->mbv_storage->stringval); } var->mbv_storage->stringval = NULL; - if (NULL == value || 0 == strlen (value)) { + if (NULL == value || 0 == strlen(value)) { return OPAL_SUCCESS; } /* Replace all instances of ~/ in a path-style string with the user's home directory. This may be handled by the enumerator in the future. */ - if (0 == strncmp (value, "~/", 2)) { + if (0 == strncmp(value, "~/", 2)) { if (NULL != home) { - ret = opal_asprintf (&value, "%s/%s", home, value + 2); + ret = opal_asprintf(&value, "%s/%s", home, value + 2); if (0 > ret) { return OPAL_ERROR; } } else { - value = strdup (value + 2); + value = strdup(value + 2); } } else { - value = strdup (value); + value = strdup(value); } if (NULL == value) { return OPAL_ERR_OUT_OF_RESOURCE; } - while (NULL != (tmp = strstr (value, ":~/"))) { + while (NULL != (tmp = strstr(value, ":~/"))) { tmp[0] = '\0'; tmp += 3; - ret = opal_asprintf (&tmp, "%s:%s%s%s", value, - home ? home : "", home ? "/" : "", tmp); + ret = opal_asprintf(&tmp, "%s:%s%s%s", value, home ? home : "", home ? "/" : "", tmp); - free (value); + free(value); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; @@ -675,7 +643,7 @@ static int int_from_string(const char *src, mca_base_var_enum_t *enumerator, uin bool is_int; char *tmp; - if (NULL == src || 0 == strlen (src)) { + if (NULL == src || 0 == strlen(src)) { if (NULL == enumerator) { *value_out = 0; } @@ -695,7 +663,7 @@ static int int_from_string(const char *src, mca_base_var_enum_t *enumerator, uin } /* Check for an integer value */ - value = strtoull (src, &tmp, 0); + value = strtoull(src, &tmp, 0); is_int = tmp[0] == '\0'; if (!is_int && tmp != src) { @@ -720,7 +688,7 @@ static int int_from_string(const char *src, mca_base_var_enum_t *enumerator, uin return OPAL_SUCCESS; } -static int var_set_from_string (mca_base_var_t *var, char *src) +static int var_set_from_string(mca_base_var_t *var, char *src) { mca_base_var_storage_t *dst = var->mbv_storage; uint64_t int_value = 0; @@ -739,59 +707,59 @@ static int var_set_from_string (mca_base_var_t *var, char *src) case MCA_BASE_VAR_TYPE_BOOL: case MCA_BASE_VAR_TYPE_SIZE_T: ret = int_from_string(src, var->mbv_enumerator, &int_value); - if (OPAL_SUCCESS != ret || - (MCA_BASE_VAR_TYPE_INT == var->mbv_type && ((int) int_value != (int64_t) int_value)) || - (MCA_BASE_VAR_TYPE_UNSIGNED_INT == var->mbv_type && ((unsigned int) int_value != int_value))) { + if (OPAL_SUCCESS != ret + || (MCA_BASE_VAR_TYPE_INT == var->mbv_type && ((int) int_value != (int64_t) int_value)) + || (MCA_BASE_VAR_TYPE_UNSIGNED_INT == var->mbv_type + && ((unsigned int) int_value != int_value))) { if (var->mbv_enumerator) { char *valid_values; (void) var->mbv_enumerator->dump(var->mbv_enumerator, &valid_values); - opal_show_help("help-mca-var.txt", "invalid-value-enum", - true, var->mbv_full_name, src, valid_values); + opal_show_help("help-mca-var.txt", "invalid-value-enum", true, var->mbv_full_name, + src, valid_values); free(valid_values); } else { - opal_show_help("help-mca-var.txt", "invalid-value", - true, var->mbv_full_name, src); + opal_show_help("help-mca-var.txt", "invalid-value", true, var->mbv_full_name, src); } return OPAL_ERR_VALUE_OUT_OF_BOUNDS; } - if (MCA_BASE_VAR_TYPE_INT == var->mbv_type || - MCA_BASE_VAR_TYPE_UNSIGNED_INT == var->mbv_type) { - int *castme = (int*) var->mbv_storage; + if (MCA_BASE_VAR_TYPE_INT == var->mbv_type + || MCA_BASE_VAR_TYPE_UNSIGNED_INT == var->mbv_type) { + int *castme = (int *) var->mbv_storage; *castme = int_value; - } else if (MCA_BASE_VAR_TYPE_INT32_T == var->mbv_type || - MCA_BASE_VAR_TYPE_UINT32_T == var->mbv_type) { + } else if (MCA_BASE_VAR_TYPE_INT32_T == var->mbv_type + || MCA_BASE_VAR_TYPE_UINT32_T == var->mbv_type) { int32_t *castme = (int32_t *) var->mbv_storage; *castme = int_value; - } else if (MCA_BASE_VAR_TYPE_INT64_T == var->mbv_type || - MCA_BASE_VAR_TYPE_UINT64_T == var->mbv_type) { + } else if (MCA_BASE_VAR_TYPE_INT64_T == var->mbv_type + || MCA_BASE_VAR_TYPE_UINT64_T == var->mbv_type) { int64_t *castme = (int64_t *) var->mbv_storage; *castme = int_value; } else if (MCA_BASE_VAR_TYPE_LONG == var->mbv_type) { - long *castme = (long*) var->mbv_storage; + long *castme = (long *) var->mbv_storage; *castme = (long) int_value; } else if (MCA_BASE_VAR_TYPE_UNSIGNED_LONG == var->mbv_type) { - unsigned long *castme = (unsigned long*) var->mbv_storage; + unsigned long *castme = (unsigned long *) var->mbv_storage; *castme = (unsigned long) int_value; } else if (MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG == var->mbv_type) { - unsigned long long *castme = (unsigned long long*) var->mbv_storage; + unsigned long long *castme = (unsigned long long *) var->mbv_storage; *castme = (unsigned long long) int_value; } else if (MCA_BASE_VAR_TYPE_SIZE_T == var->mbv_type) { - size_t *castme = (size_t*) var->mbv_storage; + size_t *castme = (size_t *) var->mbv_storage; *castme = (size_t) int_value; } else if (MCA_BASE_VAR_TYPE_BOOL == var->mbv_type) { - bool *castme = (bool*) var->mbv_storage; + bool *castme = (bool *) var->mbv_storage; *castme = !!int_value; } return ret; case MCA_BASE_VAR_TYPE_DOUBLE: - dst->lfval = strtod (src, NULL); + dst->lfval = strtod(src, NULL); break; case MCA_BASE_VAR_TYPE_STRING: case MCA_BASE_VAR_TYPE_VERSION_STRING: - var_set_string (var, src); + var_set_string(var, src); break; case MCA_BASE_VAR_TYPE_MAX: return OPAL_ERROR; @@ -803,13 +771,13 @@ static int var_set_from_string (mca_base_var_t *var, char *src) /* * Set a variable */ -int mca_base_var_set_value (int vari, const void *value, size_t size, mca_base_var_source_t source, - const char *source_file) +int mca_base_var_set_value(int vari, const void *value, size_t size, mca_base_var_source_t source, + const char *source_file) { mca_base_var_t *var; int ret; - ret = var_get (vari, &var, true); + ret = var_get(vari, &var, true); if (OPAL_SUCCESS != ret) { return ret; } @@ -824,17 +792,17 @@ int mca_base_var_set_value (int vari, const void *value, size_t size, mca_base_v if (NULL != var->mbv_enumerator) { /* Validate */ - ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, - ((int *) value)[0], NULL); + ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, ((int *) value)[0], NULL); if (OPAL_SUCCESS != ret) { return ret; } } - if (MCA_BASE_VAR_TYPE_STRING != var->mbv_type && MCA_BASE_VAR_TYPE_VERSION_STRING != var->mbv_type) { - memmove (var->mbv_storage, value, ompi_var_type_sizes[var->mbv_type]); + if (MCA_BASE_VAR_TYPE_STRING != var->mbv_type + && MCA_BASE_VAR_TYPE_VERSION_STRING != var->mbv_type) { + memmove(var->mbv_storage, value, ompi_var_type_sizes[var->mbv_type]); } else { - var_set_string (var, (char *) value); + var_set_string(var, (char *) value); } var->mbv_source = source; @@ -855,7 +823,7 @@ int mca_base_var_deregister(int vari) mca_base_var_t *var; int ret; - ret = var_get (vari, &var, false); + ret = var_get(vari, &var, false); if (OPAL_SUCCESS != ret) { return ret; } @@ -874,12 +842,13 @@ int mca_base_var_deregister(int vari) } /* Release the current value if it is a string. */ - if ((MCA_BASE_VAR_TYPE_STRING == var->mbv_type || MCA_BASE_VAR_TYPE_VERSION_STRING == var->mbv_type) && - var->mbv_storage->stringval) { - free (var->mbv_storage->stringval); + if ((MCA_BASE_VAR_TYPE_STRING == var->mbv_type + || MCA_BASE_VAR_TYPE_VERSION_STRING == var->mbv_type) + && var->mbv_storage->stringval) { + free(var->mbv_storage->stringval); var->mbv_storage->stringval = NULL; } else { - OPAL_MCA_VAR_MBV_ENUMERATOR_FREE(var -> mbv_enumerator); + OPAL_MCA_VAR_MBV_ENUMERATOR_FREE(var->mbv_enumerator); } var->mbv_enumerator = NULL; @@ -889,7 +858,7 @@ int mca_base_var_deregister(int vari) return OPAL_SUCCESS; } -static int var_get (int vari, mca_base_var_t **var_out, bool original) +static int var_get(int vari, mca_base_var_t **var_out, bool original) { mca_base_var_t *var; @@ -906,7 +875,7 @@ static int var_get (int vari, mca_base_var_t **var_out, bool original) return OPAL_ERR_BAD_PARAM; } - var = opal_pointer_array_get_item (&mca_base_vars, vari); + var = opal_pointer_array_get_item(&mca_base_vars, vari); if (NULL == var) { return OPAL_ERR_BAD_PARAM; } @@ -922,12 +891,11 @@ static int var_get (int vari, mca_base_var_t **var_out, bool original) return OPAL_SUCCESS; } -int mca_base_var_env_name(const char *param_name, - char **env_name) +int mca_base_var_env_name(const char *param_name, char **env_name) { int ret; - assert (NULL != env_name); + assert(NULL != env_name); ret = opal_asprintf(env_name, "%s%s", mca_prefix, param_name); if (0 > ret) { @@ -940,37 +908,36 @@ int mca_base_var_env_name(const char *param_name, /* * Find the index for an MCA parameter based on its names. */ -static int var_find_by_name (const char *full_name, int *vari, bool invalidok) +static int var_find_by_name(const char *full_name, int *vari, bool invalidok) { mca_base_var_t *var = NULL; void *tmp; int rc; - rc = opal_hash_table_get_value_ptr (&mca_base_var_index_hash, full_name, strlen (full_name), - &tmp); + rc = opal_hash_table_get_value_ptr(&mca_base_var_index_hash, full_name, strlen(full_name), + &tmp); if (OPAL_SUCCESS != rc) { return rc; } - (void) var_get ((int)(uintptr_t) tmp, &var, false); + (void) var_get((int) (uintptr_t) tmp, &var, false); if (invalidok || (var && VAR_IS_VALID(var[0]))) { - *vari = (int)(uintptr_t) tmp; + *vari = (int) (uintptr_t) tmp; return OPAL_SUCCESS; } return OPAL_ERR_NOT_FOUND; } -static int var_find (const char *project_name, const char *framework_name, - const char *component_name, const char *variable_name, - bool invalidok) +static int var_find(const char *project_name, const char *framework_name, + const char *component_name, const char *variable_name, bool invalidok) { char *full_name; int ret, vari; - ret = mca_base_var_generate_full_name4 (NULL, framework_name, component_name, - variable_name, &full_name); + ret = mca_base_var_generate_full_name4(NULL, framework_name, component_name, variable_name, + &full_name); if (OPAL_SUCCESS != ret) { return OPAL_ERROR; } @@ -979,7 +946,7 @@ static int var_find (const char *project_name, const char *framework_name, /* NTH: should we verify the name components match? */ - free (full_name); + free(full_name); if (OPAL_SUCCESS != ret) { return ret; @@ -991,26 +958,26 @@ static int var_find (const char *project_name, const char *framework_name, /* * Find the index for an MCA parameter based on its name components. */ -int mca_base_var_find (const char *project_name, const char *framework_name, - const char *component_name, const char *variable_name) +int mca_base_var_find(const char *project_name, const char *framework_name, + const char *component_name, const char *variable_name) { - return var_find (project_name, framework_name, component_name, variable_name, false); + return var_find(project_name, framework_name, component_name, variable_name, false); } /* * Find the index for an MCA parameter based on full name. */ -int mca_base_var_find_by_name (const char *full_name, int *vari) +int mca_base_var_find_by_name(const char *full_name, int *vari) { - return var_find_by_name (full_name, vari, false); + return var_find_by_name(full_name, vari, false); } -int mca_base_var_set_flag (int vari, mca_base_var_flag_t flag, bool set) +int mca_base_var_set_flag(int vari, mca_base_var_flag_t flag, bool set) { mca_base_var_t *var; int ret; - ret = var_get (vari, &var, true); + ret = var_get(vari, &var, true); if (OPAL_SUCCESS != ret || VAR_IS_SYNONYM(var[0])) { return OPAL_ERR_BAD_PARAM; } @@ -1024,10 +991,10 @@ int mca_base_var_set_flag (int vari, mca_base_var_flag_t flag, bool set) /* * Return info on a parameter at an index */ -int mca_base_var_get (int vari, const mca_base_var_t **var) +int mca_base_var_get(int vari, const mca_base_var_t **var) { int ret; - ret = var_get (vari, (mca_base_var_t **) var, false); + ret = var_get(vari, (mca_base_var_t **) var, false); if (OPAL_SUCCESS != ret) { return ret; @@ -1062,31 +1029,31 @@ int mca_base_var_build_env(char ***env, int *num_env, bool internal) char *value_string; char *str = NULL; - var = opal_pointer_array_get_item (&mca_base_vars, i); + var = opal_pointer_array_get_item(&mca_base_vars, i); if (NULL == var) { continue; } /* Don't output default values or internal variables (unless requested) */ - if (MCA_BASE_VAR_SOURCE_DEFAULT == var->mbv_source || - (!internal && VAR_IS_INTERNAL(var[0]))) { + if (MCA_BASE_VAR_SOURCE_DEFAULT == var->mbv_source + || (!internal && VAR_IS_INTERNAL(var[0]))) { continue; } - if ((MCA_BASE_VAR_TYPE_STRING == var->mbv_type || MCA_BASE_VAR_TYPE_VERSION_STRING == var->mbv_type) && - NULL == var->mbv_storage->stringval) { + if ((MCA_BASE_VAR_TYPE_STRING == var->mbv_type + || MCA_BASE_VAR_TYPE_VERSION_STRING == var->mbv_type) + && NULL == var->mbv_storage->stringval) { continue; } - ret = var_value_string (var, &value_string); + ret = var_value_string(var, &value_string); if (OPAL_SUCCESS != ret) { goto cleanup; } - ret = opal_asprintf (&str, "%s%s=%s", mca_prefix, var->mbv_full_name, - value_string); - free (value_string); + ret = opal_asprintf(&str, "%s%s=%s", mca_prefix, var->mbv_full_name, value_string); + free(value_string); if (0 > ret) { goto cleanup; } @@ -1097,11 +1064,11 @@ int mca_base_var_build_env(char ***env, int *num_env, bool internal) switch (var->mbv_source) { case MCA_BASE_VAR_SOURCE_FILE: case MCA_BASE_VAR_SOURCE_OVERRIDE: - opal_asprintf (&str, "%sSOURCE_%s=FILE:%s", mca_prefix, var->mbv_full_name, - mca_base_var_source_file (var)); + opal_asprintf(&str, "%sSOURCE_%s=FILE:%s", mca_prefix, var->mbv_full_name, + mca_base_var_source_file(var)); break; case MCA_BASE_VAR_SOURCE_COMMAND_LINE: - opal_asprintf (&str, "%sSOURCE_%s=COMMAND_LINE", mca_prefix, var->mbv_full_name); + opal_asprintf(&str, "%sSOURCE_%s=COMMAND_LINE", mca_prefix, var->mbv_full_name); break; case MCA_BASE_VAR_SOURCE_ENV: case MCA_BASE_VAR_SOURCE_SET: @@ -1124,7 +1091,7 @@ int mca_base_var_build_env(char ***env, int *num_env, bool internal) /* Error condition */ - cleanup: +cleanup: if (*num_env > 0) { opal_argv_free(*env); *num_env = 0; @@ -1137,7 +1104,7 @@ int mca_base_var_build_env(char ***env, int *num_env, bool internal) * Shut down the MCA parameter system (normally only invoked by the * MCA framework itself). */ -static void mca_base_var_finalize (void) +static void mca_base_var_finalize(void) { opal_object_t *object; opal_list_item_t *item; @@ -1145,33 +1112,30 @@ static void mca_base_var_finalize (void) if (mca_base_var_initialized) { size = opal_pointer_array_get_size(&mca_base_vars); - for (i = 0 ; i < size ; ++i) { - object = opal_pointer_array_get_item (&mca_base_vars, i); + for (i = 0; i < size; ++i) { + object = opal_pointer_array_get_item(&mca_base_vars, i); if (NULL != object) { OBJ_RELEASE(object); } } OBJ_DESTRUCT(&mca_base_vars); - while (NULL != - (item = opal_list_remove_first(&mca_base_var_file_values))) { + while (NULL != (item = opal_list_remove_first(&mca_base_var_file_values))) { OBJ_RELEASE(item); } OBJ_DESTRUCT(&mca_base_var_file_values); - while (NULL != - (item = opal_list_remove_first(&mca_base_envar_file_values))) { + while (NULL != (item = opal_list_remove_first(&mca_base_envar_file_values))) { OBJ_RELEASE(item); } OBJ_DESTRUCT(&mca_base_envar_file_values); - while (NULL != - (item = opal_list_remove_first(&mca_base_var_override_values))) { + while (NULL != (item = opal_list_remove_first(&mca_base_var_override_values))) { OBJ_RELEASE(item); } OBJ_DESTRUCT(&mca_base_var_override_values); - if( NULL != cwd ) { + if (NULL != cwd) { free(cwd); cwd = NULL; } @@ -1184,23 +1148,23 @@ static void mca_base_var_finalize (void) } mca_base_var_file_list = NULL; - (void) mca_base_var_group_finalize (); - (void) mca_base_pvar_finalize (); + (void) mca_base_var_group_finalize(); + (void) mca_base_pvar_finalize(); OBJ_DESTRUCT(&mca_base_var_index_hash); - free (mca_base_envar_files); + free(mca_base_envar_files); mca_base_envar_files = NULL; } } - /*************************************************************************/ -static int fixup_files(char **file_list, char * path, bool rel_path_search, char sep) { +static int fixup_files(char **file_list, char *path, bool rel_path_search, char sep) +{ int exit_status = OPAL_SUCCESS; char **files = NULL; char **search_path = NULL; - char * tmp_file = NULL; + char *tmp_file = NULL; char **argv = NULL; char *rel_path; int mode = R_OK; /* The file exists, and we can read it */ @@ -1213,7 +1177,7 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search, char rel_path = force_agg_path ? force_agg_path : cwd; /* Read in reverse order, so we can preserve the original ordering */ - for (i = 0 ; i < count; ++i) { + for (i = 0; i < count; ++i) { char *msg_path = path; if (opal_path_is_absolute(files[i])) { /* Absolute paths preserved */ @@ -1233,12 +1197,12 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search, char * - if found and readable, use it * - otherwise, warn/error */ - tmp_file = opal_path_find (files[i], search_path, mode, NULL); + tmp_file = opal_path_find(files[i], search_path, mode, NULL); } if (NULL == tmp_file) { - opal_show_help("help-mca-var.txt", "missing-param-file", - true, getpid(), files[i], msg_path); + opal_show_help("help-mca-var.txt", "missing-param-file", true, getpid(), files[i], + msg_path); exit_status = OPAL_ERROR; break; } @@ -1254,17 +1218,17 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search, char *file_list = opal_argv_join(argv, sep); } - if( NULL != files ) { + if (NULL != files) { opal_argv_free(files); files = NULL; } - if( NULL != argv ) { + if (NULL != argv) { opal_argv_free(argv); argv = NULL; } - if( NULL != search_path ) { + if (NULL != search_path) { opal_argv_free(search_path); search_path = NULL; } @@ -1288,11 +1252,11 @@ static int read_files(char *file_list, opal_list_t *file_values, char sep) the entries farthest to the left get precedence) */ for (i = count - 1; i >= 0; --i) { - char *file_name = append_filename_to_list (tmp[i]); + char *file_name = append_filename_to_list(tmp[i]); mca_base_parse_paramfile(file_name, file_values); } - opal_argv_free (tmp); + opal_argv_free(tmp); mca_base_internal_env_store(); @@ -1300,36 +1264,32 @@ static int read_files(char *file_list, opal_list_t *file_values, char sep) } /******************************************************************************/ -static int register_variable (const char *project_name, const char *framework_name, - const char *component_name, const char *variable_name, - const char *description, mca_base_var_type_t type, - mca_base_var_enum_t *enumerator, int bind, - mca_base_var_flag_t flags, mca_base_var_info_lvl_t info_lvl, - mca_base_var_scope_t scope, int synonym_for, - void *storage) +static int register_variable(const char *project_name, const char *framework_name, + const char *component_name, const char *variable_name, + const char *description, mca_base_var_type_t type, + mca_base_var_enum_t *enumerator, int bind, mca_base_var_flag_t flags, + mca_base_var_info_lvl_t info_lvl, mca_base_var_scope_t scope, + int synonym_for, void *storage) { int ret, var_index, group_index, tmp; mca_base_var_group_t *group; mca_base_var_t *var, *original = NULL; /* Developer error. Storage can not be NULL and type must exist */ - assert (((flags & MCA_BASE_VAR_FLAG_SYNONYM) || NULL != storage) && type >= 0 && type < MCA_BASE_VAR_TYPE_MAX); + assert(((flags & MCA_BASE_VAR_FLAG_SYNONYM) || NULL != storage) && type >= 0 + && type < MCA_BASE_VAR_TYPE_MAX); /* Developer error: check max length of strings */ - if (NULL != project_name && - strlen(project_name) > MCA_BASE_MAX_PROJECT_NAME_LEN) { + if (NULL != project_name && strlen(project_name) > MCA_BASE_MAX_PROJECT_NAME_LEN) { return OPAL_ERR_BAD_PARAM; } - if (NULL != framework_name && - strlen(framework_name) > MCA_BASE_MAX_TYPE_NAME_LEN) { + if (NULL != framework_name && strlen(framework_name) > MCA_BASE_MAX_TYPE_NAME_LEN) { return OPAL_ERR_BAD_PARAM; } - if (NULL != component_name && - strlen(component_name) > MCA_BASE_MAX_COMPONENT_NAME_LEN) { + if (NULL != component_name && strlen(component_name) > MCA_BASE_MAX_COMPONENT_NAME_LEN) { return OPAL_ERR_BAD_PARAM; } - if (NULL != variable_name && - strlen(variable_name) > MCA_BASE_MAX_VARIABLE_NAME_LEN) { + if (NULL != variable_name && strlen(variable_name) > MCA_BASE_MAX_VARIABLE_NAME_LEN) { return OPAL_ERR_BAD_PARAM; } @@ -1384,11 +1344,11 @@ static int register_variable (const char *project_name, const char *framework_na #endif if (flags & MCA_BASE_VAR_FLAG_SYNONYM) { - original = opal_pointer_array_get_item (&mca_base_vars, synonym_for); + original = opal_pointer_array_get_item(&mca_base_vars, synonym_for); if (NULL == original) { /* Attempting to create a synonym for a non-existent variable. probably a * developer error. */ - assert (NULL != original); + assert(NULL != original); return OPAL_ERR_NOT_FOUND; } } @@ -1402,13 +1362,12 @@ static int register_variable (const char *project_name, const char *framework_na } /* See if this entry is already in the array */ - var_index = var_find (project_name, framework_name, component_name, variable_name, - true); + var_index = var_find(project_name, framework_name, component_name, variable_name, true); if (0 > var_index) { /* Create a new parameter entry */ - group_index = mca_base_var_group_register (project_name, framework_name, component_name, - NULL); + group_index = mca_base_var_group_register(project_name, framework_name, component_name, + NULL); if (-1 > group_index) { return group_index; } @@ -1416,8 +1375,8 @@ static int register_variable (const char *project_name, const char *framework_na /* Read-only and constant variables can't be settable */ if (scope < MCA_BASE_VAR_SCOPE_LOCAL || (flags & MCA_BASE_VAR_FLAG_DEFAULT_ONLY)) { if ((flags & MCA_BASE_VAR_FLAG_DEFAULT_ONLY) && (flags & MCA_BASE_VAR_FLAG_SETTABLE)) { - opal_show_help("help-mca-var.txt", "invalid-flag-combination", - true, "MCA_BASE_VAR_FLAG_DEFAULT_ONLY", "MCA_BASE_VAR_FLAG_SETTABLE"); + opal_show_help("help-mca-var.txt", "invalid-flag-combination", true, + "MCA_BASE_VAR_FLAG_DEFAULT_ONLY", "MCA_BASE_VAR_FLAG_SETTABLE"); return OPAL_ERROR; } @@ -1427,20 +1386,20 @@ static int register_variable (const char *project_name, const char *framework_na var = OBJ_NEW(mca_base_var_t); - var->mbv_type = type; - var->mbv_flags = flags; + var->mbv_type = type; + var->mbv_flags = flags; var->mbv_group_index = group_index; - var->mbv_info_lvl = info_lvl; - var->mbv_scope = scope; + var->mbv_info_lvl = info_lvl; + var->mbv_scope = scope; var->mbv_synonym_for = synonym_for; - var->mbv_bind = bind; + var->mbv_bind = bind; if (NULL != description) { var->mbv_description = strdup(description); } - ret = mca_base_var_generate_full_name4 (project_name, framework_name, component_name, - variable_name, &var->mbv_long_name); + ret = mca_base_var_generate_full_name4(project_name, framework_name, component_name, + variable_name, &var->mbv_long_name); if (OPAL_SUCCESS != ret) { OBJ_RELEASE(var); return OPAL_ERROR; @@ -1449,19 +1408,20 @@ static int register_variable (const char *project_name, const char *framework_na * so instead of allocating them we can just point into the var mbv_long_name * at the right location. */ - var->mbv_full_name = var->mbv_long_name + - (NULL == project_name ? 0 : (strlen(project_name)+1)); /* 1 for _ */ - if( NULL != variable_name ) { - var->mbv_variable_name = var->mbv_full_name + - (NULL == framework_name ? 0 : (strlen(framework_name)+1)) + - (NULL == component_name ? 0 : (strlen(component_name)+1)); + var->mbv_full_name = var->mbv_long_name + + (NULL == project_name ? 0 + : (strlen(project_name) + 1)); /* 1 for _ */ + if (NULL != variable_name) { + var->mbv_variable_name = var->mbv_full_name + + (NULL == framework_name ? 0 : (strlen(framework_name) + 1)) + + (NULL == component_name ? 0 : (strlen(component_name) + 1)); } /* Add it to the array. Note that we copy the mca_var_t by value, so the entire contents of the struct is copied. The synonym list will always be empty at this point, so there's no need for an extra RETAIN or RELEASE. */ - var_index = opal_pointer_array_add (&mca_base_vars, var); + var_index = opal_pointer_array_add(&mca_base_vars, var); if (0 > var_index) { OBJ_RELEASE(var); return OPAL_ERROR; @@ -1470,25 +1430,26 @@ static int register_variable (const char *project_name, const char *framework_na var->mbv_index = var_index; if (0 <= group_index) { - mca_base_var_group_add_var (group_index, var_index); + mca_base_var_group_add_var(group_index, var_index); } mca_base_var_count++; - if (0 <= var_find_by_name (var->mbv_full_name, &tmp, 0)) { - /* XXX --- FIXME: variable overshadows an existing variable. this is difficult to support */ - assert (0); + if (0 <= var_find_by_name(var->mbv_full_name, &tmp, 0)) { + /* XXX --- FIXME: variable overshadows an existing variable. this is difficult to + * support */ + assert(0); } - opal_hash_table_set_value_ptr (&mca_base_var_index_hash, var->mbv_full_name, strlen (var->mbv_full_name), - (void *)(uintptr_t) var_index); + opal_hash_table_set_value_ptr(&mca_base_var_index_hash, var->mbv_full_name, + strlen(var->mbv_full_name), (void *) (uintptr_t) var_index); } else { - ret = var_get (var_index, &var, false); + ret = var_get(var_index, &var, false); if (OPAL_SUCCESS != ret) { /* Shouldn't ever happen */ return OPAL_ERROR; } - ret = mca_base_var_group_get_internal (var->mbv_group_index, &group, true); + ret = mca_base_var_group_get_internal(var->mbv_group_index, &group, true); if (OPAL_SUCCESS != ret) { /* Shouldn't ever happen */ return OPAL_ERROR; @@ -1499,24 +1460,21 @@ static int register_variable (const char *project_name, const char *framework_na } /* Verify the name components match */ - if (0 != compare_strings(framework_name, group->group_framework) || - 0 != compare_strings(component_name, group->group_component) || - 0 != compare_strings(variable_name, var->mbv_variable_name)) { - opal_show_help("help-mca-var.txt", "var-name-conflict", - true, var->mbv_full_name, framework_name, - component_name, variable_name, - group->group_framework, group->group_component, - var->mbv_variable_name); + if (0 != compare_strings(framework_name, group->group_framework) + || 0 != compare_strings(component_name, group->group_component) + || 0 != compare_strings(variable_name, var->mbv_variable_name)) { + opal_show_help("help-mca-var.txt", "var-name-conflict", true, var->mbv_full_name, + framework_name, component_name, variable_name, group->group_framework, + group->group_component, var->mbv_variable_name); /* This is developer error. abort! */ - assert (0); + assert(0); return OPAL_ERROR; } if (var->mbv_type != type) { #if OPAL_ENABLE_DEBUG - opal_show_help("help-mca-var.txt", - "re-register-with-different-type", - true, var->mbv_full_name); + opal_show_help("help-mca-var.txt", "re-register-with-different-type", true, + var->mbv_full_name); #endif return OPAL_ERR_VALUE_OUT_OF_BOUNDS; } @@ -1537,8 +1495,9 @@ static int register_variable (const char *project_name, const char *framework_na var->mbv_storage = storage; /* make a copy of the default string value */ - if ((MCA_BASE_VAR_TYPE_STRING == type || MCA_BASE_VAR_TYPE_VERSION_STRING == type) && NULL != ((char **)storage)[0]) { - ((char **)storage)[0] = strdup (((char **)storage)[0]); + if ((MCA_BASE_VAR_TYPE_STRING == type || MCA_BASE_VAR_TYPE_VERSION_STRING == type) + && NULL != ((char **) storage)[0]) { + ((char **) storage)[0] = strdup(((char **) storage)[0]); } } else { /* synonym variable */ @@ -1548,7 +1507,7 @@ static int register_variable (const char *project_name, const char *framework_na /* go ahead and mark this variable as valid */ var->mbv_flags |= MCA_BASE_VAR_FLAG_VALID; - ret = var_set_initial (var, original); + ret = var_set_initial(var, original); if (OPAL_SUCCESS != ret) { return ret; } @@ -1557,81 +1516,78 @@ static int register_variable (const char *project_name, const char *framework_na return var_index; } -int mca_base_var_register (const char *project_name, const char *framework_name, - const char *component_name, const char *variable_name, - const char *description, mca_base_var_type_t type, - mca_base_var_enum_t *enumerator, int bind, - mca_base_var_flag_t flags, - mca_base_var_info_lvl_t info_lvl, - mca_base_var_scope_t scope, void *storage) +int mca_base_var_register(const char *project_name, const char *framework_name, + const char *component_name, const char *variable_name, + const char *description, mca_base_var_type_t type, + mca_base_var_enum_t *enumerator, int bind, mca_base_var_flag_t flags, + mca_base_var_info_lvl_t info_lvl, mca_base_var_scope_t scope, + void *storage) { int ret; /* Only integer variables can have enumerator */ - assert (NULL == enumerator || (MCA_BASE_VAR_TYPE_INT == type || MCA_BASE_VAR_TYPE_UNSIGNED_INT == type)); + assert(NULL == enumerator + || (MCA_BASE_VAR_TYPE_INT == type || MCA_BASE_VAR_TYPE_UNSIGNED_INT == type)); - ret = register_variable (project_name, framework_name, component_name, - variable_name, description, type, enumerator, - bind, flags, info_lvl, scope, -1, storage); + ret = register_variable(project_name, framework_name, component_name, variable_name, + description, type, enumerator, bind, flags, info_lvl, scope, -1, + storage); if (OPAL_UNLIKELY(0 > ret)) { return ret; } /* Register aliases if any exist */ - const mca_base_alias_t *alias = mca_base_alias_lookup (project_name, framework_name, component_name); + const mca_base_alias_t *alias = mca_base_alias_lookup(project_name, framework_name, + component_name); if (NULL == alias) { return ret; } - OPAL_LIST_FOREACH_DECL(alias_item, &alias->component_aliases, mca_base_alias_item_t) { + OPAL_LIST_FOREACH_DECL (alias_item, &alias->component_aliases, mca_base_alias_item_t) { mca_base_var_syn_flag_t flags = 0; if (alias_item->alias_flags & MCA_BASE_ALIAS_FLAG_DEPRECATED) { flags = MCA_BASE_VAR_SYN_FLAG_DEPRECATED; } - (void) mca_base_var_register_synonym (ret, project_name, framework_name, alias_item->component_alias, - variable_name, flags); + (void) mca_base_var_register_synonym(ret, project_name, framework_name, + alias_item->component_alias, variable_name, flags); } return ret; } -int mca_base_component_var_register (const mca_base_component_t *component, - const char *variable_name, const char *description, - mca_base_var_type_t type, mca_base_var_enum_t *enumerator, - int bind, mca_base_var_flag_t flags, - mca_base_var_info_lvl_t info_lvl, - mca_base_var_scope_t scope, void *storage) +int mca_base_component_var_register(const mca_base_component_t *component, + const char *variable_name, const char *description, + mca_base_var_type_t type, mca_base_var_enum_t *enumerator, + int bind, mca_base_var_flag_t flags, + mca_base_var_info_lvl_t info_lvl, mca_base_var_scope_t scope, + void *storage) { - return mca_base_var_register (component->mca_project_name, component->mca_type_name, - component->mca_component_name, - variable_name, description, type, enumerator, - bind, flags | MCA_BASE_VAR_FLAG_DWG, - info_lvl, scope, storage); + return mca_base_var_register(component->mca_project_name, component->mca_type_name, + component->mca_component_name, variable_name, description, type, + enumerator, bind, flags | MCA_BASE_VAR_FLAG_DWG, info_lvl, scope, + storage); } -int mca_base_framework_var_register (const mca_base_framework_t *framework, - const char *variable_name, - const char *help_msg, mca_base_var_type_t type, - mca_base_var_enum_t *enumerator, int bind, - mca_base_var_flag_t flags, - mca_base_var_info_lvl_t info_level, - mca_base_var_scope_t scope, void *storage) +int mca_base_framework_var_register(const mca_base_framework_t *framework, + const char *variable_name, const char *help_msg, + mca_base_var_type_t type, mca_base_var_enum_t *enumerator, + int bind, mca_base_var_flag_t flags, + mca_base_var_info_lvl_t info_level, mca_base_var_scope_t scope, + void *storage) { - return mca_base_var_register (framework->framework_project, framework->framework_name, - "base", variable_name, help_msg, type, enumerator, bind, - flags | MCA_BASE_VAR_FLAG_DWG, info_level, scope, storage); + return mca_base_var_register(framework->framework_project, framework->framework_name, "base", + variable_name, help_msg, type, enumerator, bind, + flags | MCA_BASE_VAR_FLAG_DWG, info_level, scope, storage); } -int mca_base_var_register_synonym (int synonym_for, const char *project_name, - const char *framework_name, - const char *component_name, - const char *synonym_name, - mca_base_var_syn_flag_t flags) +int mca_base_var_register_synonym(int synonym_for, const char *project_name, + const char *framework_name, const char *component_name, + const char *synonym_name, mca_base_var_syn_flag_t flags) { mca_base_var_flag_t var_flags = (mca_base_var_flag_t) MCA_BASE_VAR_FLAG_SYNONYM; mca_base_var_t *var; int ret; - ret = var_get (synonym_for, &var, false); + ret = var_get(synonym_for, &var, false); if (OPAL_SUCCESS != ret || VAR_IS_SYNONYM(var[0])) { return OPAL_ERR_BAD_PARAM; } @@ -1643,17 +1599,16 @@ int mca_base_var_register_synonym (int synonym_for, const char *project_name, var_flags |= MCA_BASE_VAR_FLAG_INTERNAL; } - return register_variable (project_name, framework_name, component_name, - synonym_name, var->mbv_description, var->mbv_type, var->mbv_enumerator, - var->mbv_bind, var_flags, var->mbv_info_lvl, var->mbv_scope, - synonym_for, NULL); + return register_variable(project_name, framework_name, component_name, synonym_name, + var->mbv_description, var->mbv_type, var->mbv_enumerator, + var->mbv_bind, var_flags, var->mbv_info_lvl, var->mbv_scope, + synonym_for, NULL); } -static int var_get_env (mca_base_var_t *var, const char *name, char **source, char **value) +static int var_get_env(mca_base_var_t *var, const char *name, char **source, char **value) { const char source_prefix[] = "SOURCE_"; - const int max_len = strlen(mca_prefix) + strlen(source_prefix) + - strlen(name) + 1; + const int max_len = strlen(mca_prefix) + strlen(source_prefix) + strlen(name) + 1; char *envvar = alloca(max_len); if (NULL == envvar) { return OPAL_ERR_OUT_OF_RESOURCE; @@ -1665,14 +1620,13 @@ static int var_get_env (mca_base_var_t *var, const char *name, char **source, ch return OPAL_ERROR; } *value = getenv(envvar); - if( NULL == *value ) { + if (NULL == *value) { *source = NULL; return OPAL_ERR_NOT_FOUND; } - ret = snprintf(envvar, max_len, "%s%s%s", mca_prefix, - source_prefix, name); - if( 0 > ret ) { + ret = snprintf(envvar, max_len, "%s%s%s", mca_prefix, source_prefix, name); + if (0 > ret) { return OPAL_ERROR; } *source = getenv(envvar); @@ -1683,7 +1637,7 @@ static int var_get_env (mca_base_var_t *var, const char *name, char **source, ch /* * Lookup a param in the environment */ -static int var_set_from_env (mca_base_var_t *var, mca_base_var_t *original) +static int var_set_from_env(mca_base_var_t *var, mca_base_var_t *original) { const char *var_full_name = var->mbv_full_name; const char *var_long_name = var->mbv_long_name; @@ -1692,9 +1646,9 @@ static int var_set_from_env (mca_base_var_t *var, mca_base_var_t *original) char *source_env, *value_env; int ret; - ret = var_get_env (var, var_long_name, &source_env, &value_env); + ret = var_get_env(var, var_long_name, &source_env, &value_env); if (OPAL_SUCCESS != ret) { - ret = var_get_env (var, var_full_name, &source_env, &value_env); + ret = var_get_env(var, var_full_name, &source_env, &value_env); } if (OPAL_SUCCESS != ret) { @@ -1704,16 +1658,14 @@ static int var_set_from_env (mca_base_var_t *var, mca_base_var_t *original) /* we found an environment variable but this variable is default-only. print a warning. */ if (VAR_IS_DEFAULT_ONLY(original[0])) { - opal_show_help("help-mca-var.txt", "default-only-param-set", - true, var_full_name); + opal_show_help("help-mca-var.txt", "default-only-param-set", true, var_full_name); return OPAL_ERR_NOT_FOUND; } if (MCA_BASE_VAR_SOURCE_OVERRIDE == original->mbv_source) { if (!mca_base_var_suppress_override_warning) { - opal_show_help("help-mca-var.txt", "overridden-param-set", - true, var_full_name); + opal_show_help("help-mca-var.txt", "overridden-param-set", true, var_full_name); } return OPAL_ERR_NOT_FOUND; @@ -1722,14 +1674,14 @@ static int var_set_from_env (mca_base_var_t *var, mca_base_var_t *original) original->mbv_source = MCA_BASE_VAR_SOURCE_ENV; if (NULL != source_env) { - if (0 == strncasecmp (source_env, "file:", 5)) { + if (0 == strncasecmp(source_env, "file:", 5)) { original->mbv_source_file = append_filename_to_list(source_env + 5); - if (0 == strcmp (var->mbv_source_file, mca_base_var_override_file)) { + if (0 == strcmp(var->mbv_source_file, mca_base_var_override_file)) { original->mbv_source = MCA_BASE_VAR_SOURCE_OVERRIDE; } else { original->mbv_source = MCA_BASE_VAR_SOURCE_FILE; } - } else if (0 == strcasecmp (source_env, "command")) { + } else if (0 == strcasecmp(source_env, "command")) { var->mbv_source = MCA_BASE_VAR_SOURCE_COMMAND_LINE; } } @@ -1743,18 +1695,17 @@ static int var_set_from_env (mca_base_var_t *var, mca_base_var_t *original) switch (var->mbv_source) { case MCA_BASE_VAR_SOURCE_ENV: - opal_show_help("help-mca-var.txt", "deprecated-mca-env", - true, var_full_name, new_variable); + opal_show_help("help-mca-var.txt", "deprecated-mca-env", true, var_full_name, + new_variable); break; case MCA_BASE_VAR_SOURCE_COMMAND_LINE: - opal_show_help("help-mca-var.txt", "deprecated-mca-cli", - true, var_full_name, new_variable); + opal_show_help("help-mca-var.txt", "deprecated-mca-cli", true, var_full_name, + new_variable); break; case MCA_BASE_VAR_SOURCE_FILE: case MCA_BASE_VAR_SOURCE_OVERRIDE: - opal_show_help("help-mca-var.txt", "deprecated-mca-file", - true, var_full_name, mca_base_var_source_file (var), - new_variable); + opal_show_help("help-mca-var.txt", "deprecated-mca-file", true, var_full_name, + mca_base_var_source_file(var), new_variable); break; case MCA_BASE_VAR_SOURCE_DEFAULT: @@ -1765,13 +1716,14 @@ static int var_set_from_env (mca_base_var_t *var, mca_base_var_t *original) } } - return var_set_from_string (original, value_env); + return var_set_from_string(original, value_env); } /* * Lookup a param in the files */ -static int var_set_from_file (mca_base_var_t *var, mca_base_var_t *original, opal_list_t *file_values) +static int var_set_from_file(mca_base_var_t *var, mca_base_var_t *original, + opal_list_t *file_values) { const char *var_full_name = var->mbv_full_name; const char *var_long_name = var->mbv_long_name; @@ -1783,32 +1735,29 @@ static int var_set_from_file (mca_base_var_t *var, mca_base_var_t *original, opa find a match. If we do, cache it on the param (for future lookups) and save it in the storage. */ - OPAL_LIST_FOREACH(fv, file_values, mca_base_var_file_value_t) { - if (0 != strcmp(fv->mbvfv_var, var_full_name) && - 0 != strcmp(fv->mbvfv_var, var_long_name)) { + OPAL_LIST_FOREACH (fv, file_values, mca_base_var_file_value_t) { + if (0 != strcmp(fv->mbvfv_var, var_full_name) + && 0 != strcmp(fv->mbvfv_var, var_long_name)) { continue; } /* found it */ if (VAR_IS_DEFAULT_ONLY(var[0])) { - opal_show_help("help-mca-var.txt", "default-only-param-set", - true, var_full_name); + opal_show_help("help-mca-var.txt", "default-only-param-set", true, var_full_name); return OPAL_ERR_NOT_FOUND; } if (MCA_BASE_VAR_FLAG_ENVIRONMENT_ONLY & original->mbv_flags) { - opal_show_help("help-mca-var.txt", "environment-only-param", - true, var_full_name, fv->mbvfv_value, - fv->mbvfv_file); + opal_show_help("help-mca-var.txt", "environment-only-param", true, var_full_name, + fv->mbvfv_value, fv->mbvfv_file); return OPAL_ERR_NOT_FOUND; } if (MCA_BASE_VAR_SOURCE_OVERRIDE == original->mbv_source) { if (!mca_base_var_suppress_override_warning) { - opal_show_help("help-mca-var.txt", "overridden-param-set", - true, var_full_name); + opal_show_help("help-mca-var.txt", "overridden-param-set", true, var_full_name); } return OPAL_ERR_NOT_FOUND; @@ -1821,9 +1770,8 @@ static int var_set_from_file (mca_base_var_t *var, mca_base_var_t *original, opa new_variable = original->mbv_full_name; } - opal_show_help("help-mca-var.txt", "deprecated-mca-file", - true, var_full_name, fv->mbvfv_file, - new_variable); + opal_show_help("help-mca-var.txt", "deprecated-mca-file", true, var_full_name, + fv->mbvfv_file, new_variable); } original->mbv_file_value = (void *) fv; @@ -1833,7 +1781,7 @@ static int var_set_from_file (mca_base_var_t *var, mca_base_var_t *original, opa var->mbv_source = MCA_BASE_VAR_SOURCE_FILE; } - return var_set_from_string (original, fv->mbvfv_value); + return var_set_from_string(original, fv->mbvfv_value); } return OPAL_ERR_NOT_FOUND; @@ -1842,7 +1790,7 @@ static int var_set_from_file (mca_base_var_t *var, mca_base_var_t *original, opa /* * Lookup the initial value for a parameter */ -static int var_set_initial (mca_base_var_t *var, mca_base_var_t *original) +static int var_set_initial(mca_base_var_t *var, mca_base_var_t *original) { int ret; @@ -1860,23 +1808,24 @@ static int var_set_initial (mca_base_var_t *var, mca_base_var_t *original) order. If the default only flag is set the user will get a warning if they try to set a value from the environment or a file. */ - ret = var_set_from_file (var, original, &mca_base_var_override_values); + ret = var_set_from_file(var, original, &mca_base_var_override_values); if (OPAL_SUCCESS == ret) { - var->mbv_flags = ~MCA_BASE_VAR_FLAG_SETTABLE & (var->mbv_flags | MCA_BASE_VAR_FLAG_OVERRIDE); + var->mbv_flags = ~MCA_BASE_VAR_FLAG_SETTABLE + & (var->mbv_flags | MCA_BASE_VAR_FLAG_OVERRIDE); var->mbv_source = MCA_BASE_VAR_SOURCE_OVERRIDE; } - ret = var_set_from_env (var, original); + ret = var_set_from_env(var, original); if (OPAL_ERR_NOT_FOUND != ret) { return ret; } - ret = var_set_from_file (var, original, &mca_base_envar_file_values); + ret = var_set_from_file(var, original, &mca_base_envar_file_values); if (OPAL_ERR_NOT_FOUND != ret) { return ret; } - ret = var_set_from_file (var, original, &mca_base_var_file_values); + ret = var_set_from_file(var, original, &mca_base_var_file_values); if (OPAL_ERR_NOT_FOUND != ret) { return ret; } @@ -1889,24 +1838,22 @@ static int var_set_initial (mca_base_var_t *var, mca_base_var_t *original) */ static void var_constructor(mca_base_var_t *var) { - memset ((char *) var + sizeof (var->super), 0, sizeof (*var) - sizeof (var->super)); + memset((char *) var + sizeof(var->super), 0, sizeof(*var) - sizeof(var->super)); var->mbv_type = MCA_BASE_VAR_TYPE_MAX; OBJ_CONSTRUCT(&var->mbv_synonyms, opal_value_array_t); - opal_value_array_init (&var->mbv_synonyms, sizeof (int)); + opal_value_array_init(&var->mbv_synonyms, sizeof(int)); } - /* * Free all the contents of a param container */ static void var_destructor(mca_base_var_t *var) { - if ((MCA_BASE_VAR_TYPE_STRING == var->mbv_type || - MCA_BASE_VAR_TYPE_VERSION_STRING == var->mbv_type) && - NULL != var->mbv_storage && - NULL != var->mbv_storage->stringval) { - free (var->mbv_storage->stringval); + if ((MCA_BASE_VAR_TYPE_STRING == var->mbv_type + || MCA_BASE_VAR_TYPE_VERSION_STRING == var->mbv_type) + && NULL != var->mbv_storage && NULL != var->mbv_storage->stringval) { + free(var->mbv_storage->stringval); var->mbv_storage->stringval = NULL; } @@ -1931,17 +1878,15 @@ static void var_destructor(mca_base_var_t *var) #if OPAL_ENABLE_DEBUG /* Cheap trick to reset everything to NULL */ - memset ((char *) var + sizeof (var->super), 0, sizeof (*var) - sizeof (var->super)); + memset((char *) var + sizeof(var->super), 0, sizeof(*var) - sizeof(var->super)); #endif } - static void fv_constructor(mca_base_var_file_value_t *f) { - memset ((char *) f + sizeof (f->super), 0, sizeof (*f) - sizeof (f->super)); + memset((char *) f + sizeof(f->super), 0, sizeof(*f) - sizeof(f->super)); } - static void fv_destructor(mca_base_var_file_value_t *f) { if (NULL != f->mbvfv_var) { @@ -1958,7 +1903,8 @@ static char *source_name(mca_base_var_t *var) { char *ret; - if (MCA_BASE_VAR_SOURCE_FILE == var->mbv_source || MCA_BASE_VAR_SOURCE_OVERRIDE == var->mbv_source) { + if (MCA_BASE_VAR_SOURCE_FILE == var->mbv_source + || MCA_BASE_VAR_SOURCE_OVERRIDE == var->mbv_source) { struct mca_base_var_file_value_t *fv = var->mbv_file_value; int rc; @@ -1968,30 +1914,31 @@ static char *source_name(mca_base_var_t *var) rc = opal_asprintf(&ret, "file (%s)", var->mbv_source_file); } - /* some compilers will warn if the return code of opal_asprintf is not checked (even if it is cast to void) */ + /* some compilers will warn if the return code of opal_asprintf is not checked (even if it + * is cast to void) */ if (0 > rc) { return NULL; } return ret; } else if (MCA_BASE_VAR_SOURCE_MAX <= var->mbv_source) { - return strdup ("unknown(!!)"); + return strdup("unknown(!!)"); } - return strdup (var_source_names[var->mbv_source]); + return strdup(var_source_names[var->mbv_source]); } -static int var_value_string (mca_base_var_t *var, char **value_string) +static int var_value_string(mca_base_var_t *var, char **value_string) { - const mca_base_var_storage_t *value=NULL; + const mca_base_var_storage_t *value = NULL; int ret; - assert (MCA_BASE_VAR_TYPE_MAX > var->mbv_type); + assert(MCA_BASE_VAR_TYPE_MAX > var->mbv_type); /** Parameters with MCA_BASE_VAR_FLAG_DEF_UNSET flag should be shown * as "unset" by default. */ - if ((var->mbv_flags & MCA_BASE_VAR_FLAG_DEF_UNSET) && - (MCA_BASE_VAR_SOURCE_DEFAULT == var->mbv_source)){ - opal_asprintf (value_string, "%s", "unset"); + if ((var->mbv_flags & MCA_BASE_VAR_FLAG_DEF_UNSET) + && (MCA_BASE_VAR_SOURCE_DEFAULT == var->mbv_source)) { + opal_asprintf(value_string, "%s", "unset"); return OPAL_SUCCESS; } @@ -2003,45 +1950,44 @@ static int var_value_string (mca_base_var_t *var, char **value_string) if (NULL == var->mbv_enumerator) { switch (var->mbv_type) { case MCA_BASE_VAR_TYPE_INT: - ret = opal_asprintf (value_string, "%d", value->intval); + ret = opal_asprintf(value_string, "%d", value->intval); break; case MCA_BASE_VAR_TYPE_INT32_T: - ret = opal_asprintf (value_string, "%" PRId32, value->int32tval); + ret = opal_asprintf(value_string, "%" PRId32, value->int32tval); break; case MCA_BASE_VAR_TYPE_UINT32_T: - ret = opal_asprintf (value_string, "%" PRIu32, value->uint32tval); + ret = opal_asprintf(value_string, "%" PRIu32, value->uint32tval); break; case MCA_BASE_VAR_TYPE_INT64_T: - ret = opal_asprintf (value_string, "%" PRId64, value->int64tval); + ret = opal_asprintf(value_string, "%" PRId64, value->int64tval); break; case MCA_BASE_VAR_TYPE_UINT64_T: - ret = opal_asprintf (value_string, "%" PRIu64, value->uint64tval); + ret = opal_asprintf(value_string, "%" PRIu64, value->uint64tval); break; case MCA_BASE_VAR_TYPE_LONG: - ret = opal_asprintf (value_string, "%ld", value->longval); + ret = opal_asprintf(value_string, "%ld", value->longval); break; case MCA_BASE_VAR_TYPE_UNSIGNED_INT: - ret = opal_asprintf (value_string, "%u", value->uintval); + ret = opal_asprintf(value_string, "%u", value->uintval); break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG: - ret = opal_asprintf (value_string, "%lu", value->ulval); + ret = opal_asprintf(value_string, "%lu", value->ulval); break; case MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG: - ret = opal_asprintf (value_string, "%llu", value->ullval); + ret = opal_asprintf(value_string, "%llu", value->ullval); break; case MCA_BASE_VAR_TYPE_SIZE_T: - ret = opal_asprintf (value_string, "%" PRIsize_t, value->sizetval); + ret = opal_asprintf(value_string, "%" PRIsize_t, value->sizetval); break; case MCA_BASE_VAR_TYPE_STRING: case MCA_BASE_VAR_TYPE_VERSION_STRING: - ret = opal_asprintf (value_string, "%s", - value->stringval ? value->stringval : ""); + ret = opal_asprintf(value_string, "%s", value->stringval ? value->stringval : ""); break; case MCA_BASE_VAR_TYPE_BOOL: - ret = opal_asprintf (value_string, "%d", value->boolval); + ret = opal_asprintf(value_string, "%d", value->boolval); break; case MCA_BASE_VAR_TYPE_DOUBLE: - ret = opal_asprintf (value_string, "%lf", value->lfval); + ret = opal_asprintf(value_string, "%lf", value->lfval); break; default: ret = -1; @@ -2052,22 +1998,20 @@ static int var_value_string (mca_base_var_t *var, char **value_string) } else { /* we use an enumerator to handle string->bool and bool->string conversion */ if (MCA_BASE_VAR_TYPE_BOOL == var->mbv_type) { - ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, value->boolval, value_string); + ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, value->boolval, + value_string); } else { - ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, value->intval, value_string); + ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, value->intval, + value_string); } } return ret; } -int mca_base_var_check_exclusive (const char *project, - const char *type_a, - const char *component_a, - const char *param_a, - const char *type_b, - const char *component_b, - const char *param_b) +int mca_base_var_check_exclusive(const char *project, const char *type_a, const char *component_a, + const char *param_a, const char *type_b, const char *component_b, + const char *param_b) { mca_base_var_t *var_a = NULL, *var_b = NULL; int var_ai, var_bi; @@ -2075,20 +2019,20 @@ int mca_base_var_check_exclusive (const char *project, /* XXX -- Remove me once the project name is in the componennt */ project = NULL; - var_ai = mca_base_var_find (project, type_a, component_a, param_a); - var_bi = mca_base_var_find (project, type_b, component_b, param_b); + var_ai = mca_base_var_find(project, type_a, component_a, param_a); + var_bi = mca_base_var_find(project, type_b, component_b, param_b); if (var_bi < 0 || var_ai < 0) { return OPAL_ERR_NOT_FOUND; } - (void) var_get (var_ai, &var_a, true); - (void) var_get (var_bi, &var_b, true); + (void) var_get(var_ai, &var_a, true); + (void) var_get(var_bi, &var_b, true); if (NULL == var_a || NULL == var_b) { return OPAL_ERR_NOT_FOUND; } - if (MCA_BASE_VAR_SOURCE_DEFAULT != var_a->mbv_source && - MCA_BASE_VAR_SOURCE_DEFAULT != var_b->mbv_source) { + if (MCA_BASE_VAR_SOURCE_DEFAULT != var_a->mbv_source + && MCA_BASE_VAR_SOURCE_DEFAULT != var_b->mbv_source) { char *str_a, *str_b; /* Form cosmetic string names for A */ @@ -2098,11 +2042,8 @@ int mca_base_var_check_exclusive (const char *project, str_b = source_name(var_b); /* Print it all out */ - opal_show_help("help-mca-var.txt", - "mutually-exclusive-vars", - true, var_a->mbv_full_name, - str_a, var_b->mbv_full_name, - str_b); + opal_show_help("help-mca-var.txt", "mutually-exclusive-vars", true, var_a->mbv_full_name, + str_a, var_b->mbv_full_name, str_b); /* Free the temp strings */ free(str_a); @@ -2114,7 +2055,7 @@ int mca_base_var_check_exclusive (const char *project, return OPAL_SUCCESS; } -int mca_base_var_get_count (void) +int mca_base_var_get_count(void) { return mca_base_var_count; } @@ -2125,7 +2066,7 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ int i, line_count, line = 0, enum_count = 0; char *value_string, *source_string, *tmp; int synonym_count, ret, *synonyms = NULL; - mca_base_var_t *var, *original=NULL; + mca_base_var_t *var, *original = NULL; mca_base_var_group_t *group; ret = var_get(vari, &var, false); @@ -2158,14 +2099,14 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ synonyms = OPAL_VALUE_ARRAY_GET_BASE(&var->mbv_synonyms, int); } - ret = var_value_string (var, &value_string); + ret = var_value_string(var, &value_string); if (OPAL_SUCCESS != ret) { return ret; } source_string = source_name(var); if (NULL == source_string) { - free (value_string); + free(value_string); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -2174,19 +2115,18 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ (void) var->mbv_enumerator->get_count(var->mbv_enumerator, &enum_count); } - line_count = 8 + (var->mbv_description ? 1 : 0) + (VAR_IS_SYNONYM(var[0]) ? 1 : synonym_count) + - enum_count; + line_count = 8 + (var->mbv_description ? 1 : 0) + + (VAR_IS_SYNONYM(var[0]) ? 1 : synonym_count) + enum_count; - *out = (char **) calloc (line_count + 1, sizeof (char *)); + *out = (char **) calloc(line_count + 1, sizeof(char *)); if (NULL == *out) { - free (value_string); - free (source_string); + free(value_string); + free(source_string); return OPAL_ERR_OUT_OF_RESOURCE; } /* build the message*/ - opal_asprintf(&tmp, "mca:%s:%s:param:%s:", framework, component, - full_name); + opal_asprintf(&tmp, "mca:%s:%s:param:%s:", framework, component, full_name); /* Output the value */ char *colon = strchr(value_string, ':'); @@ -2212,7 +2152,7 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ } if (NULL != var->mbv_enumerator) { - for (i = 0 ; i < enum_count ; ++i) { + for (i = 0; i < enum_count; ++i) { const char *enum_string = NULL; int enum_value; @@ -2222,12 +2162,14 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ continue; } - opal_asprintf(out[0] + line++, "%senumerator:value:%d:%s", tmp, enum_value, enum_string); + opal_asprintf(out[0] + line++, "%senumerator:value:%d:%s", tmp, enum_value, + enum_string); } } /* Is this variable deprecated? */ - opal_asprintf(out[0] + line++, "%sdeprecated:%s", tmp, VAR_IS_DEPRECATED(var[0]) ? "yes" : "no"); + opal_asprintf(out[0] + line++, "%sdeprecated:%s", tmp, + VAR_IS_DEPRECATED(var[0]) ? "yes" : "no"); opal_asprintf(out[0] + line++, "%stype:%s", tmp, ompi_var_type_names[var->mbv_type]); @@ -2235,7 +2177,7 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ if (VAR_IS_SYNONYM(var[0])) { opal_asprintf(out[0] + line++, "%ssynonym_of:name:%s", tmp, original->mbv_full_name); } else if (opal_value_array_get_size(&var->mbv_synonyms)) { - for (i = 0 ; i < synonym_count ; ++i) { + for (i = 0; i < synonym_count; ++i) { mca_base_var_t *synonym; ret = var_get(synonyms[i], &synonym, false); @@ -2247,37 +2189,38 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ } } - free (tmp); + free(tmp); } else if (MCA_BASE_VAR_DUMP_READABLE == output_type) { /* There will be at most three lines in the pretty print case */ - *out = (char **) calloc (4, sizeof (char *)); + *out = (char **) calloc(4, sizeof(char *)); if (NULL == *out) { - free (value_string); - free (source_string); + free(value_string); + free(source_string); return OPAL_ERR_OUT_OF_RESOURCE; } - opal_asprintf (out[0], "%s \"%s\" (current value: \"%s\", data source: %s, level: %d %s, type: %s", - VAR_IS_DEFAULT_ONLY(var[0]) ? "informational" : "parameter", - full_name, value_string, source_string, var->mbv_info_lvl + 1, - info_lvl_strings[var->mbv_info_lvl], ompi_var_type_names[var->mbv_type]); + opal_asprintf(out[0], + "%s \"%s\" (current value: \"%s\", data source: %s, level: %d %s, type: %s", + VAR_IS_DEFAULT_ONLY(var[0]) ? "informational" : "parameter", full_name, + value_string, source_string, var->mbv_info_lvl + 1, + info_lvl_strings[var->mbv_info_lvl], ompi_var_type_names[var->mbv_type]); tmp = out[0][0]; if (VAR_IS_DEPRECATED(var[0])) { - opal_asprintf (out[0], "%s, deprecated", tmp); - free (tmp); + opal_asprintf(out[0], "%s, deprecated", tmp); + free(tmp); tmp = out[0][0]; } /* Does this parameter have any synonyms or is it a synonym? */ if (VAR_IS_SYNONYM(var[0])) { opal_asprintf(out[0], "%s, synonym of: %s)", tmp, original->mbv_full_name); - free (tmp); + free(tmp); } else if (synonym_count) { opal_asprintf(out[0], "%s, synonyms: ", tmp); - free (tmp); + free(tmp); - for (i = 0 ; i < synonym_count ; ++i) { + for (i = 0; i < synonym_count; ++i) { mca_base_var_t *synonym; ret = var_get(synonyms[i], &synonym, false); @@ -2286,7 +2229,7 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ } tmp = out[0][0]; - if (synonym_count == i+1) { + if (synonym_count == i + 1) { opal_asprintf(out[0], "%s%s)", tmp, synonym->mbv_full_name); } else { opal_asprintf(out[0], "%s%s, ", tmp, synonym->mbv_full_name); @@ -2309,24 +2252,23 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ ret = var->mbv_enumerator->dump(var->mbv_enumerator, &values); if (OPAL_SUCCESS == ret) { - opal_asprintf (out[0] + line++, "Valid values: %s", values); - free (values); + opal_asprintf(out[0] + line++, "Valid values: %s", values); + free(values); } } } else if (MCA_BASE_VAR_DUMP_SIMPLE == output_type) { - *out = (char **) calloc (2, sizeof (char *)); + *out = (char **) calloc(2, sizeof(char *)); if (NULL == *out) { - free (value_string); - free (source_string); + free(value_string); + free(source_string); return OPAL_ERR_OUT_OF_RESOURCE; } opal_asprintf(out[0], "%s=%s (%s)", var->mbv_full_name, value_string, source_string); } - free (value_string); - free (source_string); + free(value_string); + free(source_string); return OPAL_SUCCESS; } - diff --git a/opal/mca/base/mca_base_var.h b/opal/mca/base/mca_base_var.h index 5719266cfd2..4f82f825195 100644 --- a/opal/mca/base/mca_base_var.h +++ b/opal/mca/base/mca_base_var.h @@ -67,9 +67,9 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_value_array.h" +#include "opal/mca/base/mca_base_framework.h" #include "opal/mca/base/mca_base_var_enum.h" #include "opal/mca/base/mca_base_var_group.h" -#include "opal/mca/base/mca_base_framework.h" #include "opal/mca/mca.h" /** @@ -180,21 +180,21 @@ typedef enum { typedef enum { MCA_BASE_VAR_SYN_FLAG_DEPRECATED = 0x0001, - MCA_BASE_VAR_SYN_FLAG_INTERNAL = 0x0002 + MCA_BASE_VAR_SYN_FLAG_INTERNAL = 0x0002 } mca_base_var_syn_flag_t; typedef enum { /** Variable is internal (hidden from *_info/MPIT) */ - MCA_BASE_VAR_FLAG_INTERNAL = 0x0001, + MCA_BASE_VAR_FLAG_INTERNAL = 0x0001, /** Variable will always be the default value. Implies !MCA_BASE_VAR_FLAG_SETTABLE */ MCA_BASE_VAR_FLAG_DEFAULT_ONLY = 0x0002, /** Variable can be set with mca_base_var_set() */ - MCA_BASE_VAR_FLAG_SETTABLE = 0x0004, + MCA_BASE_VAR_FLAG_SETTABLE = 0x0004, /** Variable is deprecated */ - MCA_BASE_VAR_FLAG_DEPRECATED = 0x0008, + MCA_BASE_VAR_FLAG_DEPRECATED = 0x0008, /** Variable has been overridden */ - MCA_BASE_VAR_FLAG_OVERRIDE = 0x0010, + MCA_BASE_VAR_FLAG_OVERRIDE = 0x0010, /** Variable may not be set from a file */ MCA_BASE_VAR_FLAG_ENVIRONMENT_ONLY = 0x0020, /** Variable should be deregistered when the group is deregistered @@ -204,13 +204,12 @@ typedef enum { manually when you register a variable with mca_base_var_register(). Analogous to the MCA_BASE_PVAR_FLAG_IWG. */ - MCA_BASE_VAR_FLAG_DWG = 0x0040, + MCA_BASE_VAR_FLAG_DWG = 0x0040, /** Variable has a default value of "unset". Meaning to only * be set when the user explicitly asks for it */ - MCA_BASE_VAR_FLAG_DEF_UNSET = 0x0080, + MCA_BASE_VAR_FLAG_DEF_UNSET = 0x0080, } mca_base_var_flag_t; - /** * Types for MCA parameters. */ @@ -243,7 +242,6 @@ typedef union { double lfval; } mca_base_var_storage_t; - /** * Entry for holding information about an MCA variable. */ @@ -263,7 +261,7 @@ struct mca_base_var_t { mca_base_var_info_lvl_t mbv_info_lvl; /** Enum indicating the type of the variable (integer, string, boolean) */ - mca_base_var_type_t mbv_type; + mca_base_var_type_t mbv_type; /** String of the variable name */ char *mbv_variable_name; @@ -282,10 +280,10 @@ struct mca_base_var_t { opal_value_array_t mbv_synonyms; /** Variable flags */ - mca_base_var_flag_t mbv_flags; + mca_base_var_flag_t mbv_flags; /** Variable scope */ - mca_base_var_scope_t mbv_scope; + mca_base_var_scope_t mbv_scope; /** Source of the current value */ mca_base_var_source_t mbv_source; @@ -427,12 +425,12 @@ OPAL_DECLSPEC int mca_base_var_init(void); * the caller may free the original string after this function returns * successfully. */ -OPAL_DECLSPEC int mca_base_var_register (const char *project_name, const char *framework_name, - const char *component_name, const char *variable_name, - const char *description, mca_base_var_type_t type, - mca_base_var_enum_t *enumerator, int bind, mca_base_var_flag_t flags, - mca_base_var_info_lvl_t info_lvl, - mca_base_var_scope_t scope, void *storage); +OPAL_DECLSPEC int mca_base_var_register(const char *project_name, const char *framework_name, + const char *component_name, const char *variable_name, + const char *description, mca_base_var_type_t type, + mca_base_var_enum_t *enumerator, int bind, + mca_base_var_flag_t flags, mca_base_var_info_lvl_t info_lvl, + mca_base_var_scope_t scope, void *storage); /** * Convenience function for registering a variable associated with a @@ -443,25 +441,20 @@ OPAL_DECLSPEC int mca_base_var_register (const char *project_name, const char *f * be unregistered / made unavailable when that component is closed by * its framework. */ -OPAL_DECLSPEC int mca_base_component_var_register (const mca_base_component_t *component, - const char *variable_name, const char *description, - mca_base_var_type_t type, mca_base_var_enum_t *enumerator, - int bind, mca_base_var_flag_t flags, - mca_base_var_info_lvl_t info_lvl, - mca_base_var_scope_t scope, void *storage); +OPAL_DECLSPEC int mca_base_component_var_register( + const mca_base_component_t *component, const char *variable_name, const char *description, + mca_base_var_type_t type, mca_base_var_enum_t *enumerator, int bind, mca_base_var_flag_t flags, + mca_base_var_info_lvl_t info_lvl, mca_base_var_scope_t scope, void *storage); /** * Convenience function for registering a variable associated with a framework. This * function is equivalent to mca_base_var_register with component_name = "base" and * with the MCA_BASE_VAR_FLAG_DWG set. See mca_base_var_register(). */ -OPAL_DECLSPEC int mca_base_framework_var_register (const mca_base_framework_t *framework, - const char *variable_name, - const char *help_msg, mca_base_var_type_t type, - mca_base_var_enum_t *enumerator, int bind, - mca_base_var_flag_t flags, - mca_base_var_info_lvl_t info_level, - mca_base_var_scope_t scope, void *storage); +OPAL_DECLSPEC int mca_base_framework_var_register( + const mca_base_framework_t *framework, const char *variable_name, const char *help_msg, + mca_base_var_type_t type, mca_base_var_enum_t *enumerator, int bind, mca_base_var_flag_t flags, + mca_base_var_info_lvl_t info_level, mca_base_var_scope_t scope, void *storage); /** * Register a synonym name for an MCA variable. @@ -498,11 +491,11 @@ OPAL_DECLSPEC int mca_base_framework_var_register (const mca_base_framework_t *f * variable names "B" and "C" (and does *not* set a value for * "A"), it is undefined as to which value will be used. */ -OPAL_DECLSPEC int mca_base_var_register_synonym (int synonym_for, const char *project_name, - const char *framework_name, - const char *component_name, - const char *synonym_name, - mca_base_var_syn_flag_t flags); +OPAL_DECLSPEC int mca_base_var_register_synonym(int synonym_for, const char *project_name, + const char *framework_name, + const char *component_name, + const char *synonym_name, + mca_base_var_syn_flag_t flags); /** * Deregister a MCA variable or synonym @@ -518,7 +511,6 @@ OPAL_DECLSPEC int mca_base_var_register_synonym (int synonym_for, const char *pr */ OPAL_DECLSPEC int mca_base_var_deregister(int vari); - /** * Get the current value of an MCA variable. * @@ -537,9 +529,8 @@ OPAL_DECLSPEC int mca_base_var_deregister(int vari); * Note: The value can be changed by the registering code without using * the mca_base_var_* interface so the source may be incorrect. */ -OPAL_DECLSPEC int mca_base_var_get_value (int vari, const void *value, - mca_base_var_source_t *source, - const char **source_file); +OPAL_DECLSPEC int mca_base_var_get_value(int vari, const void *value, mca_base_var_source_t *source, + const char **source_file); /** * Sets an "override" value for an integer MCA variable. @@ -562,9 +553,8 @@ OPAL_DECLSPEC int mca_base_var_get_value (int vari, const void *value, * a synonym the variable the synonym represents) if the value is * settable. */ -OPAL_DECLSPEC int mca_base_var_set_value (int vari, const void *value, size_t size, - mca_base_var_source_t source, - const char *source_file); +OPAL_DECLSPEC int mca_base_var_set_value(int vari, const void *value, size_t size, + mca_base_var_source_t source, const char *source_file); /** * Get the string name corresponding to the MCA variable @@ -579,8 +569,7 @@ OPAL_DECLSPEC int mca_base_var_set_value (int vari, const void *value, size_t si * The string that is returned is owned by the caller; if * appropriate, it must be eventually freed by the caller. */ -OPAL_DECLSPEC int mca_base_var_env_name(const char *param_name, - char **env_name); +OPAL_DECLSPEC int mca_base_var_env_name(const char *param_name, char **env_name); /** * Find the index for an MCA variable based on its names. @@ -599,10 +588,8 @@ OPAL_DECLSPEC int mca_base_var_env_name(const char *param_name, * of any registered variable. The returned index can be used with * mca_base_var_get() and mca_base_var_get_value(). */ -OPAL_DECLSPEC int mca_base_var_find (const char *project_name, - const char *type_name, - const char *component_name, - const char *param_name); +OPAL_DECLSPEC int mca_base_var_find(const char *project_name, const char *type_name, + const char *component_name, const char *param_name); /** * Find the index for a variable based on its full name @@ -612,7 +599,7 @@ OPAL_DECLSPEC int mca_base_var_find (const char *project_name, * * See mca_base_var_find(). */ -OPAL_DECLSPEC int mca_base_var_find_by_name (const char *full_name, int *vari); +OPAL_DECLSPEC int mca_base_var_find_by_name(const char *full_name, int *vari); /** * Check that two MCA variables were not both set to non-default @@ -642,13 +629,10 @@ OPAL_DECLSPEC int mca_base_var_find_by_name (const char *full_name, int *vari); * are not MCA_BASE_VAR_SOURCE_DEFAULT. * @returns OPAL_SUCCESS otherwise. */ -OPAL_DECLSPEC int mca_base_var_check_exclusive (const char *project, - const char *type_a, - const char *component_a, - const char *param_a, - const char *type_b, - const char *component_b, - const char *param_b); +OPAL_DECLSPEC int mca_base_var_check_exclusive(const char *project, const char *type_a, + const char *component_a, const char *param_a, + const char *type_b, const char *component_b, + const char *param_b); /** * Set or unset a flag on a variable. @@ -661,8 +645,7 @@ OPAL_DECLSPEC int mca_base_var_check_exclusive (const char *project, * @returns OPAL_ERR_BAD_PARAM If the variable is not registered. * @returns OPAL_ERROR Otherwise */ -OPAL_DECLSPEC int mca_base_var_set_flag(int vari, mca_base_var_flag_t flag, - bool set); +OPAL_DECLSPEC int mca_base_var_set_flag(int vari, mca_base_var_flag_t flag, bool set); /** * Obtain basic info on a single variable (name, help message, etc) @@ -676,7 +659,7 @@ OPAL_DECLSPEC int mca_base_var_set_flag(int vari, mca_base_var_flag_t flag, * The returned pointer belongs to the MCA variable system. Do not * modify/free/retain the pointer. */ -OPAL_DECLSPEC int mca_base_var_get (int vari, const mca_base_var_t **var); +OPAL_DECLSPEC int mca_base_var_get(int vari, const mca_base_var_t **var); /** * Obtain the number of variables that have been registered. @@ -689,7 +672,7 @@ OPAL_DECLSPEC int mca_base_var_get (int vari, const mca_base_var_t **var); * returned is equal to the number of calls to mca_base_var_register with * unique names. ie. two calls with the same name will not affect the count. */ -OPAL_DECLSPEC int mca_base_var_get_count (void); +OPAL_DECLSPEC int mca_base_var_get_count(void); /** * Obtain a list of enironment variables describing the all @@ -708,8 +691,7 @@ OPAL_DECLSPEC int mca_base_var_get_count (void); * its output is in terms of an argv-style array of key=value * strings, suitable for using in an environment. */ -OPAL_DECLSPEC int mca_base_var_build_env(char ***env, int *num_env, - bool internal); +OPAL_DECLSPEC int mca_base_var_build_env(char ***env, int *num_env, bool internal); typedef enum { /* Dump human-readable strings */ @@ -717,7 +699,7 @@ typedef enum { /* Dump easily parsable strings */ MCA_BASE_VAR_DUMP_PARSABLE = 1, /* Dump simple name=value string */ - MCA_BASE_VAR_DUMP_SIMPLE = 2 + MCA_BASE_VAR_DUMP_SIMPLE = 2 } mca_base_var_dump_type_t; /** @@ -733,7 +715,7 @@ typedef enum { OPAL_DECLSPEC int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_type); #define MCA_COMPILETIME_VER "print_compiletime_version" -#define MCA_RUNTIME_VER "print_runtime_version" +#define MCA_RUNTIME_VER "print_runtime_version" /* * Parse a provided list of envars and add their local value, or @@ -746,8 +728,7 @@ OPAL_DECLSPEC int mca_base_var_process_env_list_from_file(char ***argv); * Initialize any file-based params */ OPAL_DECLSPEC int mca_base_var_cache_files(bool rel_path_search); -OPAL_DECLSPEC int mca_base_var_load_extra_files(char* files, bool rel_path_search); - +OPAL_DECLSPEC int mca_base_var_load_extra_files(char *files, bool rel_path_search); extern char *mca_base_env_list; #define MCA_BASE_ENV_LIST_SEP_DEFAULT ";" diff --git a/opal/mca/base/mca_base_var_enum.c b/opal/mca/base/mca_base_var_enum.c index 67aa875f5f9..532b828a5dc 100644 --- a/opal/mca/base/mca_base_var_enum.c +++ b/opal/mca/base/mca_base_var_enum.c @@ -26,38 +26,39 @@ #include "opal_config.h" +#include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_var_enum.h" #include "opal/mca/base/mca_base_vari.h" -#include "opal/mca/base/base.h" #include "opal/util/argv.h" #include "opal/util/printf.h" +#include #include #include -#include -static void mca_base_var_enum_constructor (mca_base_var_enum_t *enumerator); -static void mca_base_var_enum_destructor (mca_base_var_enum_t *enumerator); +static void mca_base_var_enum_constructor(mca_base_var_enum_t *enumerator); +static void mca_base_var_enum_destructor(mca_base_var_enum_t *enumerator); OBJ_CLASS_INSTANCE(mca_base_var_enum_t, opal_object_t, mca_base_var_enum_constructor, mca_base_var_enum_destructor); -static void mca_base_var_enum_flag_constructor (mca_base_var_enum_flag_t *enumerator); -static void mca_base_var_enum_flag_destructor (mca_base_var_enum_flag_t *enumerator); -static OBJ_CLASS_INSTANCE(mca_base_var_enum_flag_t, opal_object_t, mca_base_var_enum_flag_constructor, - mca_base_var_enum_flag_destructor); +static void mca_base_var_enum_flag_constructor(mca_base_var_enum_flag_t *enumerator); +static void mca_base_var_enum_flag_destructor(mca_base_var_enum_flag_t *enumerator); +static OBJ_CLASS_INSTANCE(mca_base_var_enum_flag_t, opal_object_t, + mca_base_var_enum_flag_constructor, mca_base_var_enum_flag_destructor); -static int enum_dump (mca_base_var_enum_t *self, char **out); -static int enum_get_count (mca_base_var_enum_t *self, int *count); -static int enum_get_value (mca_base_var_enum_t *self, int index, int *value, const char **string_value); +static int enum_dump(mca_base_var_enum_t *self, char **out); +static int enum_get_count(mca_base_var_enum_t *self, int *count); +static int enum_get_value(mca_base_var_enum_t *self, int index, int *value, + const char **string_value); -static int mca_base_var_enum_bool_get_count (mca_base_var_enum_t *enumerator, int *count) +static int mca_base_var_enum_bool_get_count(mca_base_var_enum_t *enumerator, int *count) { *count = 2; return OPAL_SUCCESS; } -static int mca_base_var_enum_bool_get_value (mca_base_var_enum_t *self, int index, - int *value, const char **string_value) +static int mca_base_var_enum_bool_get_value(mca_base_var_enum_t *self, int index, int *value, + const char **string_value) { if (1 < index) { return OPAL_ERR_VALUE_OUT_OF_BOUNDS; @@ -69,24 +70,24 @@ static int mca_base_var_enum_bool_get_value (mca_base_var_enum_t *self, int inde return OPAL_SUCCESS; } -static int mca_base_var_enum_bool_vfs (mca_base_var_enum_t *self, const char *string_value, - int *value) +static int mca_base_var_enum_bool_vfs(mca_base_var_enum_t *self, const char *string_value, + int *value) { char *tmp; long v; /* skip whitespace */ - string_value += strspn (string_value, " \t\n\v\f\r"); + string_value += strspn(string_value, " \t\n\v\f\r"); - v = strtol (string_value, &tmp, 10); + v = strtol(string_value, &tmp, 10); if (*tmp != '\0') { - if (0 == strcmp (string_value, "true") || 0 == strcmp (string_value, "t") || - 0 == strcmp (string_value, "enabled") || 0 == strcmp (string_value, "yes") || - 0 == strcmp (string_value, "y")) { + if (0 == strcmp(string_value, "true") || 0 == strcmp(string_value, "t") + || 0 == strcmp(string_value, "enabled") || 0 == strcmp(string_value, "yes") + || 0 == strcmp(string_value, "y")) { v = 1; - } else if (0 == strcmp (string_value, "false") || 0 == strcmp (string_value, "f") || - 0 == strcmp (string_value, "disabled") || 0 == strcmp (string_value, "no") || - 0 == strcmp (string_value, "n")) { + } else if (0 == strcmp(string_value, "false") || 0 == strcmp(string_value, "f") + || 0 == strcmp(string_value, "disabled") || 0 == strcmp(string_value, "no") + || 0 == strcmp(string_value, "n")) { v = 0; } else { return OPAL_ERR_VALUE_OUT_OF_BOUNDS; @@ -98,41 +99,39 @@ static int mca_base_var_enum_bool_vfs (mca_base_var_enum_t *self, const char *st return OPAL_SUCCESS; } -static int mca_base_var_enum_bool_sfv (mca_base_var_enum_t *self, const int value, - char **string_value) +static int mca_base_var_enum_bool_sfv(mca_base_var_enum_t *self, const int value, + char **string_value) { if (string_value) { - *string_value = strdup (value ? "true" : "false"); + *string_value = strdup(value ? "true" : "false"); } return OPAL_SUCCESS; } -static int mca_base_var_enum_bool_dump (mca_base_var_enum_t *self, char **out) +static int mca_base_var_enum_bool_dump(mca_base_var_enum_t *self, char **out) { - *out = strdup ("0: f|false|disabled|no|n, 1: t|true|enabled|yes|y"); + *out = strdup("0: f|false|disabled|no|n, 1: t|true|enabled|yes|y"); return *out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE; } -mca_base_var_enum_t mca_base_var_enum_bool = { - .super = OPAL_OBJ_STATIC_INIT(opal_object_t), - .enum_is_static = true, - .enum_name = "boolean", - .get_count = mca_base_var_enum_bool_get_count, - .get_value = mca_base_var_enum_bool_get_value, - .value_from_string = mca_base_var_enum_bool_vfs, - .string_from_value = mca_base_var_enum_bool_sfv, - .dump = mca_base_var_enum_bool_dump -}; +mca_base_var_enum_t mca_base_var_enum_bool = {.super = OPAL_OBJ_STATIC_INIT(opal_object_t), + .enum_is_static = true, + .enum_name = "boolean", + .get_count = mca_base_var_enum_bool_get_count, + .get_value = mca_base_var_enum_bool_get_value, + .value_from_string = mca_base_var_enum_bool_vfs, + .string_from_value = mca_base_var_enum_bool_sfv, + .dump = mca_base_var_enum_bool_dump}; -static int mca_base_var_enum_auto_bool_get_count (mca_base_var_enum_t *enumerator, int *count) +static int mca_base_var_enum_auto_bool_get_count(mca_base_var_enum_t *enumerator, int *count) { *count = 3; return OPAL_SUCCESS; } -static int mca_base_var_enum_auto_bool_get_value (mca_base_var_enum_t *self, int index, - int *value, const char **string_value) +static int mca_base_var_enum_auto_bool_get_value(mca_base_var_enum_t *self, int index, int *value, + const char **string_value) { const int values[3] = {0, 1, -1}; const char *strings[3] = {"false", "true", "auto"}; @@ -147,26 +146,26 @@ static int mca_base_var_enum_auto_bool_get_value (mca_base_var_enum_t *self, int return OPAL_SUCCESS; } -static int mca_base_var_enum_auto_bool_vfs (mca_base_var_enum_t *self, const char *string_value, - int *value) +static int mca_base_var_enum_auto_bool_vfs(mca_base_var_enum_t *self, const char *string_value, + int *value) { char *tmp; long v; /* skip whitespace */ - string_value += strspn (string_value, " \t\n\v\f\r"); + string_value += strspn(string_value, " \t\n\v\f\r"); - v = strtol (string_value, &tmp, 10); + v = strtol(string_value, &tmp, 10); if (*tmp != '\0') { - if (0 == strcasecmp (string_value, "true") || 0 == strcasecmp (string_value, "t") || - 0 == strcasecmp (string_value, "enabled") || 0 == strcasecmp (string_value, "yes") || - 0 == strcasecmp (string_value, "y")) { + if (0 == strcasecmp(string_value, "true") || 0 == strcasecmp(string_value, "t") + || 0 == strcasecmp(string_value, "enabled") || 0 == strcasecmp(string_value, "yes") + || 0 == strcasecmp(string_value, "y")) { v = 1; - } else if (0 == strcasecmp (string_value, "false") || 0 == strcasecmp (string_value, "f") || - 0 == strcasecmp (string_value, "disabled") || 0 == strcasecmp (string_value, "no") || - 0 == strcasecmp (string_value, "n")) { + } else if (0 == strcasecmp(string_value, "false") || 0 == strcasecmp(string_value, "f") + || 0 == strcasecmp(string_value, "disabled") + || 0 == strcasecmp(string_value, "no") || 0 == strcasecmp(string_value, "n")) { v = 0; - } else if (0 == strcasecmp (string_value, "auto")) { + } else if (0 == strcasecmp(string_value, "auto")) { v = -1; } else { return OPAL_ERR_VALUE_OUT_OF_BOUNDS; @@ -184,65 +183,62 @@ static int mca_base_var_enum_auto_bool_vfs (mca_base_var_enum_t *self, const cha return OPAL_SUCCESS; } -static int mca_base_var_enum_auto_bool_sfv (mca_base_var_enum_t *self, const int value, - char **string_value) +static int mca_base_var_enum_auto_bool_sfv(mca_base_var_enum_t *self, const int value, + char **string_value) { if (string_value) { if (value < 0) { - *string_value = strdup ("auto"); + *string_value = strdup("auto"); } else if (value > 0) { - *string_value = strdup ("true"); + *string_value = strdup("true"); } else { - *string_value = strdup ("false"); + *string_value = strdup("false"); } } return OPAL_SUCCESS; } -static int mca_base_var_enum_auto_bool_dump (mca_base_var_enum_t *self, char **out) +static int mca_base_var_enum_auto_bool_dump(mca_base_var_enum_t *self, char **out) { - *out = strdup ("-1: auto, 0: f|false|disabled|no|n, 1: t|true|enabled|yes|y"); + *out = strdup("-1: auto, 0: f|false|disabled|no|n, 1: t|true|enabled|yes|y"); return *out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE; } -mca_base_var_enum_t mca_base_var_enum_auto_bool = { - .super = OPAL_OBJ_STATIC_INIT(opal_object_t), - .enum_is_static = true, - .enum_name = "auto_boolean", - .get_count = mca_base_var_enum_auto_bool_get_count, - .get_value = mca_base_var_enum_auto_bool_get_value, - .value_from_string = mca_base_var_enum_auto_bool_vfs, - .string_from_value = mca_base_var_enum_auto_bool_sfv, - .dump = mca_base_var_enum_auto_bool_dump -}; +mca_base_var_enum_t mca_base_var_enum_auto_bool + = {.super = OPAL_OBJ_STATIC_INIT(opal_object_t), + .enum_is_static = true, + .enum_name = "auto_boolean", + .get_count = mca_base_var_enum_auto_bool_get_count, + .get_value = mca_base_var_enum_auto_bool_get_value, + .value_from_string = mca_base_var_enum_auto_bool_vfs, + .string_from_value = mca_base_var_enum_auto_bool_sfv, + .dump = mca_base_var_enum_auto_bool_dump}; /* verbosity enumerator */ -static mca_base_var_enum_value_t verbose_values[] = { - {MCA_BASE_VERBOSE_NONE, "none"}, - {MCA_BASE_VERBOSE_ERROR, "error"}, - {MCA_BASE_VERBOSE_COMPONENT, "component"}, - {MCA_BASE_VERBOSE_WARN, "warn"}, - {MCA_BASE_VERBOSE_INFO, "info"}, - {MCA_BASE_VERBOSE_TRACE, "trace"}, - {MCA_BASE_VERBOSE_DEBUG, "debug"}, - {MCA_BASE_VERBOSE_MAX, "max"}, - {-1, NULL} -}; - -static int mca_base_var_enum_verbose_vfs (mca_base_var_enum_t *self, const char *string_value, - int *value) +static mca_base_var_enum_value_t verbose_values[] = {{MCA_BASE_VERBOSE_NONE, "none"}, + {MCA_BASE_VERBOSE_ERROR, "error"}, + {MCA_BASE_VERBOSE_COMPONENT, "component"}, + {MCA_BASE_VERBOSE_WARN, "warn"}, + {MCA_BASE_VERBOSE_INFO, "info"}, + {MCA_BASE_VERBOSE_TRACE, "trace"}, + {MCA_BASE_VERBOSE_DEBUG, "debug"}, + {MCA_BASE_VERBOSE_MAX, "max"}, + {-1, NULL}}; + +static int mca_base_var_enum_verbose_vfs(mca_base_var_enum_t *self, const char *string_value, + int *value) { char *tmp; int v; /* skip whitespace */ - string_value += strspn (string_value, " \t\n\v\f\r"); + string_value += strspn(string_value, " \t\n\v\f\r"); - v = strtol (string_value, &tmp, 10); + v = strtol(string_value, &tmp, 10); if (*tmp != '\0') { - for (int i = 0 ; verbose_values[i].string ; ++i) { - if (0 == strcmp (verbose_values[i].string, string_value)) { + for (int i = 0; verbose_values[i].string; ++i) { + if (0 == strcmp(verbose_values[i].string, string_value)) { *value = verbose_values[i].value; return OPAL_SUCCESS; } @@ -260,8 +256,8 @@ static int mca_base_var_enum_verbose_vfs (mca_base_var_enum_t *self, const char return OPAL_SUCCESS; } -static int mca_base_var_enum_verbose_sfv (mca_base_var_enum_t *self, const int value, - char **string_value) +static int mca_base_var_enum_verbose_sfv(mca_base_var_enum_t *self, const int value, + char **string_value) { int ret; @@ -269,17 +265,17 @@ static int mca_base_var_enum_verbose_sfv (mca_base_var_enum_t *self, const int v return OPAL_ERR_VALUE_OUT_OF_BOUNDS; } - for (int i = 0 ; verbose_values[i].string ; ++i) { + for (int i = 0; verbose_values[i].string; ++i) { if (verbose_values[i].value == value) { if (string_value) { - *string_value = strdup (verbose_values[i].string); + *string_value = strdup(verbose_values[i].string); } return OPAL_SUCCESS; } } if (string_value) { - ret = opal_asprintf (string_value, "%d", value); + ret = opal_asprintf(string_value, "%d", value); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -288,18 +284,18 @@ static int mca_base_var_enum_verbose_sfv (mca_base_var_enum_t *self, const int v return OPAL_SUCCESS; } -static int mca_base_var_enum_verbose_dump (mca_base_var_enum_t *self, char **out) +static int mca_base_var_enum_verbose_dump(mca_base_var_enum_t *self, char **out) { char *tmp; int ret; - ret = enum_dump (self, out); + ret = enum_dump(self, out); if (OPAL_SUCCESS != ret) { return ret; } - ret = opal_asprintf (&tmp, "%s, 0 - 100", *out); - free (*out); + ret = opal_asprintf(&tmp, "%s, 0 - 100", *out); + free(*out); if (0 > ret) { *out = NULL; return OPAL_ERR_OUT_OF_RESOURCE; @@ -311,20 +307,20 @@ static int mca_base_var_enum_verbose_dump (mca_base_var_enum_t *self, char **out } mca_base_var_enum_t mca_base_var_enum_verbose = { - .super = OPAL_OBJ_STATIC_INIT(opal_object_t), + .super = OPAL_OBJ_STATIC_INIT(opal_object_t), .enum_is_static = true, .enum_name = "verbosity", .get_count = enum_get_count, .get_value = enum_get_value, .value_from_string = mca_base_var_enum_verbose_vfs, .string_from_value = mca_base_var_enum_verbose_sfv, - .dump = mca_base_var_enum_verbose_dump, + .dump = mca_base_var_enum_verbose_dump, .enum_value_count = 8, .enum_values = verbose_values, }; - -int mca_base_var_enum_create (const char *name, const mca_base_var_enum_value_t *values, mca_base_var_enum_t **enumerator) +int mca_base_var_enum_create(const char *name, const mca_base_var_enum_value_t *values, + mca_base_var_enum_t **enumerator) { mca_base_var_enum_t *new_enum; int i; @@ -336,24 +332,25 @@ int mca_base_var_enum_create (const char *name, const mca_base_var_enum_value_t return OPAL_ERR_OUT_OF_RESOURCE; } - new_enum->enum_name = strdup (name); + new_enum->enum_name = strdup(name); if (NULL == new_enum->enum_name) { return OPAL_ERR_OUT_OF_RESOURCE; } - for (i = 0 ; values[i].string ; ++i); + for (i = 0; values[i].string; ++i) { + } new_enum->enum_value_count = i; /* make a copy of the values */ - new_enum->enum_values = calloc (new_enum->enum_value_count + 1, sizeof (*new_enum->enum_values)); + new_enum->enum_values = calloc(new_enum->enum_value_count + 1, sizeof(*new_enum->enum_values)); if (NULL == new_enum->enum_values) { OBJ_RELEASE(new_enum); return OPAL_ERR_OUT_OF_RESOURCE; } - for (i = 0 ; i < new_enum->enum_value_count ; ++i) { + for (i = 0; i < new_enum->enum_value_count; ++i) { new_enum->enum_values[i].value = values[i].value; - new_enum->enum_values[i].string = strdup (values[i].string); + new_enum->enum_values[i].string = strdup(values[i].string); } *enumerator = new_enum; @@ -361,7 +358,8 @@ int mca_base_var_enum_create (const char *name, const mca_base_var_enum_value_t return OPAL_SUCCESS; } -int mca_base_var_enum_create_flag (const char *name, const mca_base_var_enum_value_flag_t *flags, mca_base_var_enum_flag_t **enumerator) +int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_value_flag_t *flags, + mca_base_var_enum_flag_t **enumerator) { mca_base_var_enum_flag_t *new_enum; int i; @@ -373,32 +371,34 @@ int mca_base_var_enum_create_flag (const char *name, const mca_base_var_enum_val return OPAL_ERR_OUT_OF_RESOURCE; } - new_enum->super.enum_name = strdup (name); + new_enum->super.enum_name = strdup(name); if (NULL == new_enum->super.enum_name) { return OPAL_ERR_OUT_OF_RESOURCE; } - for (i = 0 ; flags[i].string ; ++i); + for (i = 0; flags[i].string; ++i) { + } new_enum->super.enum_value_count = i; /* make a copy of the values */ - new_enum->enum_flags = calloc (new_enum->super.enum_value_count + 1, sizeof (*new_enum->enum_flags)); + new_enum->enum_flags = calloc(new_enum->super.enum_value_count + 1, + sizeof(*new_enum->enum_flags)); if (NULL == new_enum->enum_flags) { OBJ_RELEASE(new_enum); return OPAL_ERR_OUT_OF_RESOURCE; } int all_flags = 0; - for (i = 0 ; i < new_enum->super.enum_value_count ; ++i) { + for (i = 0; i < new_enum->super.enum_value_count; ++i) { new_enum->enum_flags[i].flag = flags[i].flag; - new_enum->enum_flags[i].string = strdup (flags[i].string); + new_enum->enum_flags[i].string = strdup(flags[i].string); new_enum->enum_flags[i].conflicting_flag = flags[i].conflicting_flag; /* ensure flags are only set a single bit, doesn't conflict with itself, and * hasn't already been specified. */ - assert (!(flags[i].flag & (flags[i].flag - 1))); - assert (!(flags[i].flag & flags[i].conflicting_flag)); - assert (!(all_flags & flags[i].flag)); - assert (flags[i].flag); + assert(!(flags[i].flag & (flags[i].flag - 1))); + assert(!(flags[i].flag & flags[i].conflicting_flag)); + assert(!(all_flags & flags[i].flag)); + assert(flags[i].flag); all_flags |= flags[i].flag; } @@ -407,7 +407,7 @@ int mca_base_var_enum_create_flag (const char *name, const mca_base_var_enum_val return OPAL_SUCCESS; } -static int enum_dump (mca_base_var_enum_t *self, char **out) +static int enum_dump(mca_base_var_enum_t *self, char **out) { int i; char *tmp; @@ -420,10 +420,12 @@ static int enum_dump (mca_base_var_enum_t *self, char **out) } tmp = NULL; - for (i = 0; i < self->enum_value_count && self->enum_values[i].string ; ++i) { - ret = opal_asprintf (out, "%s%s%d:\"%s\"", tmp ? tmp : "", tmp ? ", " : "", self->enum_values[i].value, - self->enum_values[i].string); - if (tmp) free (tmp); + for (i = 0; i < self->enum_value_count && self->enum_values[i].string; ++i) { + ret = opal_asprintf(out, "%s%s%d:\"%s\"", tmp ? tmp : "", tmp ? ", " : "", + self->enum_values[i].value, self->enum_values[i].string); + if (tmp) { + free(tmp); + } if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -433,13 +435,14 @@ static int enum_dump (mca_base_var_enum_t *self, char **out) return OPAL_SUCCESS; } -static int enum_get_count (mca_base_var_enum_t *self, int *count) +static int enum_get_count(mca_base_var_enum_t *self, int *count) { *count = self->enum_value_count; return OPAL_SUCCESS; } -static int enum_get_value (mca_base_var_enum_t *self, int index, int *value, const char **string_value) +static int enum_get_value(mca_base_var_enum_t *self, int index, int *value, + const char **string_value) { int count, ret; @@ -457,13 +460,15 @@ static int enum_get_value (mca_base_var_enum_t *self, int index, int *value, con } if (string_value) { - *string_value = strdup (self->enum_values[index].string); + *string_value = strdup(self->enum_values[index].string); } return OPAL_SUCCESS; } -static int enum_value_from_string(mca_base_var_enum_t *self, const char *string_value, int *value_out) { +static int enum_value_from_string(mca_base_var_enum_t *self, const char *string_value, + int *value_out) +{ int value, count, ret, i; bool is_int; char *tmp; @@ -478,9 +483,9 @@ static int enum_value_from_string(mca_base_var_enum_t *self, const char *string_ /* Check if the string is an integer */ is_int = tmp[0] == '\0'; - for (i = 0 ; i < count ; ++i) { - if ((is_int && value == self->enum_values[i].value) || - 0 == strcasecmp (string_value, self->enum_values[i].string)) { + for (i = 0; i < count; ++i) { + if ((is_int && value == self->enum_values[i].value) + || 0 == strcasecmp(string_value, self->enum_values[i].string)) { break; } } @@ -494,7 +499,8 @@ static int enum_value_from_string(mca_base_var_enum_t *self, const char *string_ return OPAL_SUCCESS; } -static int enum_string_from_value(mca_base_var_enum_t *self, const int value, char **string_value) { +static int enum_string_from_value(mca_base_var_enum_t *self, const int value, char **string_value) +{ int count, ret, i; ret = self->get_count(self, &count); @@ -502,7 +508,7 @@ static int enum_string_from_value(mca_base_var_enum_t *self, const int value, ch return ret; } - for (i = 0 ; i < count ; ++i) { + for (i = 0; i < count; ++i) { if (value == self->enum_values[i].value) { break; } @@ -513,40 +519,42 @@ static int enum_string_from_value(mca_base_var_enum_t *self, const int value, ch } if (string_value) { - *string_value = strdup (self->enum_values[i].string); + *string_value = strdup(self->enum_values[i].string); } return OPAL_SUCCESS; } -static void mca_base_var_enum_constructor (mca_base_var_enum_t *enumerator) +static void mca_base_var_enum_constructor(mca_base_var_enum_t *enumerator) { - memset ((char *) enumerator + sizeof (enumerator->super), 0 , sizeof(*enumerator) - sizeof(enumerator->super)); + memset((char *) enumerator + sizeof(enumerator->super), 0, + sizeof(*enumerator) - sizeof(enumerator->super)); enumerator->get_value = enum_get_value; enumerator->get_count = enum_get_count; enumerator->value_from_string = enum_value_from_string; enumerator->string_from_value = enum_string_from_value; - enumerator->dump = enum_dump; + enumerator->dump = enum_dump; enumerator->enum_is_static = false; } -static void mca_base_var_enum_destructor (mca_base_var_enum_t *enumerator) +static void mca_base_var_enum_destructor(mca_base_var_enum_t *enumerator) { if (enumerator->enum_name) { - free (enumerator->enum_name); + free(enumerator->enum_name); } /* release the copy of the values */ if (enumerator->enum_values) { - for (int i = 0 ; i < enumerator->enum_value_count ; ++i) { - free ((void *) enumerator->enum_values[i].string); + for (int i = 0; i < enumerator->enum_value_count; ++i) { + free((void *) enumerator->enum_values[i].string); } - free (enumerator->enum_values); + free(enumerator->enum_values); } } -static int enum_get_value_flag (mca_base_var_enum_t *self, int index, int *value, const char **string_value) +static int enum_get_value_flag(mca_base_var_enum_t *self, int index, int *value, + const char **string_value) { mca_base_var_enum_flag_t *flag_enum = (mca_base_var_enum_flag_t *) self; int count, ret; @@ -565,13 +573,15 @@ static int enum_get_value_flag (mca_base_var_enum_t *self, int index, int *value } if (string_value) { - *string_value = strdup (flag_enum->enum_flags[index].string); + *string_value = strdup(flag_enum->enum_flags[index].string); } return OPAL_SUCCESS; } -static int enum_value_from_string_flag (mca_base_var_enum_t *self, const char *string_value, int *value_out) { +static int enum_value_from_string_flag(mca_base_var_enum_t *self, const char *string_value, + int *value_out) +{ mca_base_var_enum_flag_t *flag_enum = (mca_base_var_enum_flag_t *) self; int value, count, ret, flag; char **flags; @@ -583,21 +593,21 @@ static int enum_value_from_string_flag (mca_base_var_enum_t *self, const char *s return ret; } - flags = opal_argv_split (string_value, ','); + flags = opal_argv_split(string_value, ','); if (NULL == flags) { return OPAL_ERR_BAD_PARAM; } flag = 0; - for (int i = 0 ; flags[i] ; ++i) { - value = strtol (flags[i], &tmp, 0); + for (int i = 0; flags[i]; ++i) { + value = strtol(flags[i], &tmp, 0); is_int = tmp[0] == '\0'; bool found = false, conflict = false; - for (int j = 0 ; j < count ; ++j) { - if ((is_int && (value & flag_enum->enum_flags[j].flag)) || - 0 == strcasecmp (flags[i], flag_enum->enum_flags[j].string)) { + for (int j = 0; j < count; ++j) { + if ((is_int && (value & flag_enum->enum_flags[j].flag)) + || 0 == strcasecmp(flags[i], flag_enum->enum_flags[j].string)) { found = true; if (flag & flag_enum->enum_flags[j].conflicting_flag) { @@ -618,19 +628,21 @@ static int enum_value_from_string_flag (mca_base_var_enum_t *self, const char *s } if (!found || conflict || (is_int && value)) { - opal_argv_free (flags); + opal_argv_free(flags); return !found ? OPAL_ERR_VALUE_OUT_OF_BOUNDS : OPAL_ERR_BAD_PARAM; } } - opal_argv_free (flags); + opal_argv_free(flags); *value_out = flag; return OPAL_SUCCESS; } -static int enum_string_from_value_flag (mca_base_var_enum_t *self, const int value, char **string_value) { +static int enum_string_from_value_flag(mca_base_var_enum_t *self, const int value, + char **string_value) +{ mca_base_var_enum_flag_t *flag_enum = (mca_base_var_enum_flag_t *) self; int count, ret, current; char *out = NULL, *tmp; @@ -641,22 +653,23 @@ static int enum_string_from_value_flag (mca_base_var_enum_t *self, const int val } current = value; - for (int i = 0 ; i < count ; ++i) { + for (int i = 0; i < count; ++i) { if (!(flag_enum->enum_flags[i].flag & current)) { continue; } tmp = out; - ret = opal_asprintf (&out, "%s%s%s", tmp ? tmp : "", tmp ? "," : "", flag_enum->enum_flags[i].string); - free (tmp); + ret = opal_asprintf(&out, "%s%s%s", tmp ? tmp : "", tmp ? "," : "", + flag_enum->enum_flags[i].string); + free(tmp); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } if (value & flag_enum->enum_flags[i].conflicting_flag) { - free (out); + free(out); return OPAL_ERR_BAD_PARAM; } @@ -664,20 +677,20 @@ static int enum_string_from_value_flag (mca_base_var_enum_t *self, const int val } if (current) { - free (out); + free(out); return OPAL_ERR_VALUE_OUT_OF_BOUNDS; } if (string_value) { - *string_value = out ? out : strdup (""); + *string_value = out ? out : strdup(""); } else { - free (out); + free(out); } return OPAL_SUCCESS; } -static int enum_dump_flag (mca_base_var_enum_t *self, char **out) +static int enum_dump_flag(mca_base_var_enum_t *self, char **out) { mca_base_var_enum_flag_t *flag_enum = (mca_base_var_enum_flag_t *) self; char *tmp; @@ -689,17 +702,17 @@ static int enum_dump_flag (mca_base_var_enum_t *self, char **out) return OPAL_ERROR; } - *out = strdup ("Comma-delimited list of: "); + *out = strdup("Comma-delimited list of: "); if (NULL == *out) { return OPAL_ERR_OUT_OF_RESOURCE; } - for (int i = 0; i < self->enum_value_count ; ++i) { + for (int i = 0; i < self->enum_value_count; ++i) { tmp = *out; - ret = opal_asprintf (out, "%s%s0x%x:\"%s\"", tmp, i ? ", " : " ", flag_enum->enum_flags[i].flag, - flag_enum->enum_flags[i].string); - free (tmp); + ret = opal_asprintf(out, "%s%s0x%x:\"%s\"", tmp, i ? ", " : " ", + flag_enum->enum_flags[i].flag, flag_enum->enum_flags[i].string); + free(tmp); if (0 > ret) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -708,7 +721,7 @@ static int enum_dump_flag (mca_base_var_enum_t *self, char **out) return OPAL_SUCCESS; } -static void mca_base_var_enum_flag_constructor (mca_base_var_enum_flag_t *enumerator) +static void mca_base_var_enum_flag_constructor(mca_base_var_enum_flag_t *enumerator) { enumerator->enum_flags = NULL; enumerator->super.get_value = enum_get_value_flag; @@ -720,38 +733,36 @@ static void mca_base_var_enum_flag_constructor (mca_base_var_enum_flag_t *enumer enumerator->super.enum_name = NULL; } -static void mca_base_var_enum_flag_destructor (mca_base_var_enum_flag_t *enumerator) +static void mca_base_var_enum_flag_destructor(mca_base_var_enum_flag_t *enumerator) { /* release the copy of the values */ if (enumerator->enum_flags) { - for (int i = 0 ; i < enumerator->super.enum_value_count ; ++i) { - free ((void *) enumerator->enum_flags[i].string); + for (int i = 0; i < enumerator->super.enum_value_count; ++i) { + free((void *) enumerator->enum_flags[i].string); } - free (enumerator->enum_flags); + free(enumerator->enum_flags); } if (NULL != enumerator->super.enum_name) { - free (enumerator->super.enum_name); + free(enumerator->super.enum_name); } } int mca_base_var_enum_register(const char *project_name, const char *framework_name, - const char *component_name, const char *enum_name, - void *storage) + const char *component_name, const char *enum_name, void *storage) { int group_index; /* Developer error. Storage can not be NULL */ - assert (NULL != storage); + assert(NULL != storage); /* Create a new parameter entry */ - group_index = mca_base_var_group_register (project_name, framework_name, component_name, - NULL); + group_index = mca_base_var_group_register(project_name, framework_name, component_name, NULL); if (-1 > group_index) { return group_index; } if (0 <= group_index) { - mca_base_var_group_add_enum (group_index, storage); + mca_base_var_group_add_enum(group_index, storage); } return OPAL_SUCCESS; diff --git a/opal/mca/base/mca_base_var_enum.h b/opal/mca/base/mca_base_var_enum.h index 52ff045fc48..405dd5e313d 100644 --- a/opal/mca/base/mca_base_var_enum.h +++ b/opal/mca/base/mca_base_var_enum.h @@ -23,12 +23,12 @@ */ #if !defined(MCA_BASE_VAR_ENUM_H) -#define MCA_BASE_VAR_ENUM_H +# define MCA_BASE_VAR_ENUM_H -#include "opal_config.h" +# include "opal_config.h" -#include "opal/class/opal_object.h" -#include "opal/constants.h" +# include "opal/class/opal_object.h" +# include "opal/constants.h" typedef struct mca_base_var_enum_t mca_base_var_enum_t; @@ -48,8 +48,8 @@ typedef int (*mca_base_var_enum_get_count_fn_t)(mca_base_var_enum_t *self, int * * @param[out] value integer value * @param[out] string_value string value */ -typedef int (*mca_base_var_enum_get_value_fn_t)(mca_base_var_enum_t *self, int index, - int *value, const char **string_value); +typedef int (*mca_base_var_enum_get_value_fn_t)(mca_base_var_enum_t *self, int index, int *value, + const char **string_value); /** * Look up the integer value of a string @@ -140,7 +140,6 @@ struct mca_base_var_enum_t { mca_base_var_enum_value_t *enum_values; }; - /** * The default flag enumerator class takes in a list of integer-string pairs. If a * string is read from an environment variable or a file value the matching @@ -199,8 +198,9 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_base_var_enum_t); * strings passed in values[] after mca_base_var_enum_create() * returns. */ -OPAL_DECLSPEC int mca_base_var_enum_create (const char *name, const mca_base_var_enum_value_t values[], - mca_base_var_enum_t **enumerator); +OPAL_DECLSPEC int mca_base_var_enum_create(const char *name, + const mca_base_var_enum_value_t values[], + mca_base_var_enum_t **enumerator); /** * Create a new default flag enumerator @@ -226,8 +226,9 @@ OPAL_DECLSPEC int mca_base_var_enum_create (const char *name, const mca_base_var * strings passed in values[] after mca_base_var_enum_create() * returns. */ -OPAL_DECLSPEC int mca_base_var_enum_create_flag (const char *name, const mca_base_var_enum_value_flag_t flags[], - mca_base_var_enum_flag_t **enumerator); +OPAL_DECLSPEC int mca_base_var_enum_create_flag(const char *name, + const mca_base_var_enum_value_flag_t flags[], + mca_base_var_enum_flag_t **enumerator); OPAL_DECLSPEC int mca_base_var_enum_register(const char *project_name, const char *framework_name, const char *component_name, const char *enum_name, diff --git a/opal/mca/base/mca_base_var_group.c b/opal/mca/base/mca_base_var_group.c index d009e19c2a2..7bdb656b09c 100644 --- a/opal/mca/base/mca_base_var_group.c +++ b/opal/mca/base/mca_base_var_group.c @@ -25,25 +25,25 @@ #include "opal_config.h" #include -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #include +#include "opal/constants.h" #include "opal/include/opal_stdint.h" -#include "opal/util/show_help.h" -#include "opal/mca/mca.h" -#include "opal/mca/base/mca_base_vari.h" #include "opal/mca/base/mca_base_pvar.h" -#include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/util/opal_environ.h" +#include "opal/mca/base/mca_base_vari.h" +#include "opal/mca/mca.h" #include "opal/runtime/opal.h" +#include "opal/util/opal_environ.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" static opal_pointer_array_t mca_base_var_groups; static opal_hash_table_t mca_base_var_group_index_hash; @@ -51,13 +51,12 @@ static int mca_base_var_group_count = 0; static int mca_base_var_groups_timestamp = 0; static bool mca_base_var_group_initialized = false; -static void mca_base_var_group_constructor (mca_base_var_group_t *group); -static void mca_base_var_group_destructor (mca_base_var_group_t *group); -OBJ_CLASS_INSTANCE(mca_base_var_group_t, opal_object_t, - mca_base_var_group_constructor, +static void mca_base_var_group_constructor(mca_base_var_group_t *group); +static void mca_base_var_group_destructor(mca_base_var_group_t *group); +OBJ_CLASS_INSTANCE(mca_base_var_group_t, opal_object_t, mca_base_var_group_constructor, mca_base_var_group_destructor); -int mca_base_var_group_init (void) +int mca_base_var_group_init(void) { int ret; @@ -65,13 +64,13 @@ int mca_base_var_group_init (void) OBJ_CONSTRUCT(&mca_base_var_groups, opal_pointer_array_t); /* These values are arbitrary */ - ret = opal_pointer_array_init (&mca_base_var_groups, 128, 16384, 128); + ret = opal_pointer_array_init(&mca_base_var_groups, 128, 16384, 128); if (OPAL_SUCCESS != ret) { return ret; } OBJ_CONSTRUCT(&mca_base_var_group_index_hash, opal_hash_table_t); - ret = opal_hash_table_init (&mca_base_var_group_index_hash, 256); + ret = opal_hash_table_init(&mca_base_var_group_index_hash, 256); if (OPAL_SUCCESS != ret) { return ret; } @@ -83,15 +82,15 @@ int mca_base_var_group_init (void) return OPAL_SUCCESS; } -int mca_base_var_group_finalize (void) +int mca_base_var_group_finalize(void) { opal_object_t *object; int size, i; if (mca_base_var_group_initialized) { size = opal_pointer_array_get_size(&mca_base_var_groups); - for (i = 0 ; i < size ; ++i) { - object = opal_pointer_array_get_item (&mca_base_var_groups, i); + for (i = 0; i < size; ++i) { + object = opal_pointer_array_get_item(&mca_base_var_groups, i); if (NULL != object) { OBJ_RELEASE(object); } @@ -105,14 +104,15 @@ int mca_base_var_group_finalize (void) return OPAL_SUCCESS; } -int mca_base_var_group_get_internal (const int group_index, mca_base_var_group_t **group, bool invalidok) +int mca_base_var_group_get_internal(const int group_index, mca_base_var_group_t **group, + bool invalidok) { if (group_index < 0) { return OPAL_ERR_NOT_FOUND; } - *group = (mca_base_var_group_t *) opal_pointer_array_get_item (&mca_base_var_groups, - group_index); + *group = (mca_base_var_group_t *) opal_pointer_array_get_item(&mca_base_var_groups, + group_index); if (NULL == *group || (!invalidok && !(*group)->group_isvalid)) { *group = NULL; return OPAL_ERR_NOT_FOUND; @@ -121,58 +121,58 @@ int mca_base_var_group_get_internal (const int group_index, mca_base_var_group_t return OPAL_SUCCESS; } -static int group_find_by_name (const char *full_name, int *index, bool invalidok) +static int group_find_by_name(const char *full_name, int *index, bool invalidok) { mca_base_var_group_t *group; void *tmp; int rc; - rc = opal_hash_table_get_value_ptr (&mca_base_var_group_index_hash, full_name, - strlen (full_name), &tmp); + rc = opal_hash_table_get_value_ptr(&mca_base_var_group_index_hash, full_name, strlen(full_name), + &tmp); if (OPAL_SUCCESS != rc) { return rc; } - rc = mca_base_var_group_get_internal ((int)(uintptr_t) tmp, &group, invalidok); + rc = mca_base_var_group_get_internal((int) (uintptr_t) tmp, &group, invalidok); if (OPAL_SUCCESS != rc) { return rc; } if (invalidok || group->group_isvalid) { - *index = (int)(uintptr_t) tmp; + *index = (int) (uintptr_t) tmp; return OPAL_SUCCESS; } return OPAL_ERR_NOT_FOUND; } -static bool compare_strings (const char *str1, const char *str2) { - if ((NULL != str1 && 0 == strcmp (str1, "*")) || - (NULL == str1 && NULL == str2)) { +static bool compare_strings(const char *str1, const char *str2) +{ + if ((NULL != str1 && 0 == strcmp(str1, "*")) || (NULL == str1 && NULL == str2)) { return true; } if (NULL != str1 && NULL != str2) { - return 0 == strcmp (str1, str2); + return 0 == strcmp(str1, str2); } return false; } -static int group_find_linear (const char *project_name, const char *framework_name, - const char *component_name, bool invalidok) +static int group_find_linear(const char *project_name, const char *framework_name, + const char *component_name, bool invalidok) { - for (int i = 0 ; i < mca_base_var_group_count ; ++i) { + for (int i = 0; i < mca_base_var_group_count; ++i) { mca_base_var_group_t *group; - int rc = mca_base_var_group_get_internal (i, &group, invalidok); + int rc = mca_base_var_group_get_internal(i, &group, invalidok); if (OPAL_SUCCESS != rc) { continue; } - if (compare_strings (project_name, group->group_project) && - compare_strings (framework_name, group->group_framework) && - compare_strings (component_name, group->group_component)) { + if (compare_strings(project_name, group->group_project) + && compare_strings(framework_name, group->group_framework) + && compare_strings(component_name, group->group_component)) { return i; } } @@ -180,36 +180,36 @@ static int group_find_linear (const char *project_name, const char *framework_na return OPAL_ERR_NOT_FOUND; } -static int group_find (const char *project_name, const char *framework_name, - const char *component_name, bool invalidok) +static int group_find(const char *project_name, const char *framework_name, + const char *component_name, bool invalidok) { char *full_name; - int ret, index=0; + int ret, index = 0; if (!mca_base_var_initialized) { return OPAL_ERR_NOT_FOUND; } /* check for wildcards */ - if ((project_name && '*' == project_name[0]) || (framework_name && '*' == framework_name[0]) || - (component_name && '*' == component_name[0])) { - return group_find_linear (project_name, framework_name, component_name, invalidok); + if ((project_name && '*' == project_name[0]) || (framework_name && '*' == framework_name[0]) + || (component_name && '*' == component_name[0])) { + return group_find_linear(project_name, framework_name, component_name, invalidok); } - ret = mca_base_var_generate_full_name4(project_name, framework_name, component_name, - NULL, &full_name); + ret = mca_base_var_generate_full_name4(project_name, framework_name, component_name, NULL, + &full_name); if (OPAL_SUCCESS != ret) { return OPAL_ERROR; } ret = group_find_by_name(full_name, &index, invalidok); - free (full_name); + free(full_name); return (0 > ret) ? ret : index; } -static int group_register (const char *project_name, const char *framework_name, - const char *component_name, const char *description) +static int group_register(const char *project_name, const char *framework_name, + const char *component_name, const char *description) { mca_base_var_group_t *group; int group_id, parent_id = -1; @@ -221,17 +221,17 @@ static int group_register (const char *project_name, const char *framework_name, } /* avoid groups of the form opal_opal, ompi_ompi, etc */ - if (NULL != project_name && NULL != framework_name && - (0 == strcmp (project_name, framework_name))) { + if (NULL != project_name && NULL != framework_name + && (0 == strcmp(project_name, framework_name))) { project_name = NULL; } - group_id = group_find (project_name, framework_name, component_name, true); + group_id = group_find(project_name, framework_name, component_name, true); if (0 <= group_id) { - ret = mca_base_var_group_get_internal (group_id, &group, true); + ret = mca_base_var_group_get_internal(group_id, &group, true); if (OPAL_SUCCESS != ret) { /* something went horribly wrong */ - assert (NULL != group); + assert(NULL != group); return ret; } group->group_isvalid = true; @@ -246,28 +246,28 @@ static int group_register (const char *project_name, const char *framework_name, group->group_isvalid = true; if (NULL != project_name) { - group->group_project = strdup (project_name); + group->group_project = strdup(project_name); if (NULL == group->group_project) { OBJ_RELEASE(group); return OPAL_ERR_OUT_OF_RESOURCE; } } if (NULL != framework_name) { - group->group_framework = strdup (framework_name); + group->group_framework = strdup(framework_name); if (NULL == group->group_framework) { OBJ_RELEASE(group); return OPAL_ERR_OUT_OF_RESOURCE; } } if (NULL != component_name) { - group->group_component = strdup (component_name); + group->group_component = strdup(component_name); if (NULL == group->group_component) { OBJ_RELEASE(group); return OPAL_ERR_OUT_OF_RESOURCE; } } if (NULL != description) { - group->group_description = strdup (description); + group->group_description = strdup(description); if (NULL == group->group_description) { OBJ_RELEASE(group); return OPAL_ERR_OUT_OF_RESOURCE; @@ -276,28 +276,28 @@ static int group_register (const char *project_name, const char *framework_name, if (NULL != framework_name && NULL != component_name) { if (component_name) { - parent_id = group_register (project_name, framework_name, NULL, NULL); + parent_id = group_register(project_name, framework_name, NULL, NULL); } else if (framework_name && project_name) { - parent_id = group_register (project_name, NULL, NULL, NULL); + parent_id = group_register(project_name, NULL, NULL, NULL); } } /* build the group name */ - ret = mca_base_var_generate_full_name4 (NULL, project_name, framework_name, component_name, - &group->group_full_name); + ret = mca_base_var_generate_full_name4(NULL, project_name, framework_name, component_name, + &group->group_full_name); if (OPAL_SUCCESS != ret) { OBJ_RELEASE(group); return ret; } - group_id = opal_pointer_array_add (&mca_base_var_groups, group); + group_id = opal_pointer_array_add(&mca_base_var_groups, group); if (0 > group_id) { OBJ_RELEASE(group); return OPAL_ERROR; } - opal_hash_table_set_value_ptr (&mca_base_var_group_index_hash, group->group_full_name, - strlen (group->group_full_name), (void *)(uintptr_t) group_id); + opal_hash_table_set_value_ptr(&mca_base_var_group_index_hash, group->group_full_name, + strlen(group->group_full_name), (void *) (uintptr_t) group_id); mca_base_var_group_count++; mca_base_var_groups_timestamp++; @@ -306,34 +306,33 @@ static int group_register (const char *project_name, const char *framework_name, mca_base_var_group_t *parent_group; (void) mca_base_var_group_get_internal(parent_id, &parent_group, false); - opal_value_array_append_item (&parent_group->group_subgroups, &group_id); + opal_value_array_append_item(&parent_group->group_subgroups, &group_id); } return group_id; } -int mca_base_var_group_register (const char *project_name, const char *framework_name, - const char *component_name, const char *description) +int mca_base_var_group_register(const char *project_name, const char *framework_name, + const char *component_name, const char *description) { - return group_register (project_name, framework_name, component_name, description); + return group_register(project_name, framework_name, component_name, description); } -int mca_base_var_group_component_register (const mca_base_component_t *component, - const char *description) +int mca_base_var_group_component_register(const mca_base_component_t *component, + const char *description) { - return group_register (component->mca_project_name, component->mca_type_name, - component->mca_component_name, description); + return group_register(component->mca_project_name, component->mca_type_name, + component->mca_component_name, description); } - -int mca_base_var_group_deregister (int group_index) +int mca_base_var_group_deregister(int group_index) { mca_base_var_group_t *group; int size, ret; int *params, *subgroups; - opal_object_t ** enums; + opal_object_t **enums; - ret = mca_base_var_group_get_internal (group_index, &group, false); + ret = mca_base_var_group_get_internal(group_index, &group, false); if (OPAL_SUCCESS != ret) { return ret; } @@ -344,42 +343,42 @@ int mca_base_var_group_deregister (int group_index) size = opal_value_array_get_size(&group->group_vars); params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, int); - for (int i = 0 ; i < size ; ++i) { + for (int i = 0; i < size; ++i) { const mca_base_var_t *var; - ret = mca_base_var_get (params[i], &var); + ret = mca_base_var_get(params[i], &var); if (OPAL_SUCCESS != ret || !(var->mbv_flags & MCA_BASE_VAR_FLAG_DWG)) { continue; } - (void) mca_base_var_deregister (params[i]); + (void) mca_base_var_deregister(params[i]); } /* invalidate all associated mca performance variables */ size = opal_value_array_get_size(&group->group_pvars); params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_pvars, int); - for (int i = 0 ; i < size ; ++i) { + for (int i = 0; i < size; ++i) { const mca_base_pvar_t *var; - ret = mca_base_pvar_get (params[i], &var); + ret = mca_base_pvar_get(params[i], &var); if (OPAL_SUCCESS != ret || !(var->flags & MCA_BASE_PVAR_FLAG_IWG)) { continue; } - (void) mca_base_pvar_mark_invalid (params[i]); + (void) mca_base_pvar_mark_invalid(params[i]); } size = opal_value_array_get_size(&group->group_enums); enums = OPAL_VALUE_ARRAY_GET_BASE(&group->group_enums, opal_object_t *); - for (int i = 0 ; i < size ; ++i) { - OBJ_RELEASE (enums[i]); + for (int i = 0; i < size; ++i) { + OBJ_RELEASE(enums[i]); } size = opal_value_array_get_size(&group->group_subgroups); subgroups = OPAL_VALUE_ARRAY_GET_BASE(&group->group_subgroups, int); - for (int i = 0 ; i < size ; ++i) { - (void) mca_base_var_group_deregister (subgroups[i]); + for (int i = 0; i < size; ++i) { + (void) mca_base_var_group_deregister(subgroups[i]); } /* ordering of variables and subgroups must be the same if the * group is re-registered */ @@ -389,118 +388,114 @@ int mca_base_var_group_deregister (int group_index) return OPAL_SUCCESS; } -int mca_base_var_group_find (const char *project_name, - const char *framework_name, - const char *component_name) +int mca_base_var_group_find(const char *project_name, const char *framework_name, + const char *component_name) { - return group_find (project_name, framework_name, component_name, false); + return group_find(project_name, framework_name, component_name, false); } -int mca_base_var_group_find_by_name (const char *full_name, int *index) +int mca_base_var_group_find_by_name(const char *full_name, int *index) { - return group_find_by_name (full_name, index, false); + return group_find_by_name(full_name, index, false); } -int mca_base_var_group_add_var (const int group_index, const int param_index) +int mca_base_var_group_add_var(const int group_index, const int param_index) { mca_base_var_group_t *group; int size, i, ret; int *params; - ret = mca_base_var_group_get_internal (group_index, &group, false); + ret = mca_base_var_group_get_internal(group_index, &group, false); if (OPAL_SUCCESS != ret) { return ret; } size = opal_value_array_get_size(&group->group_vars); params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, int); - for (i = 0 ; i < size ; ++i) { + for (i = 0; i < size; ++i) { if (params[i] == param_index) { return i; } } - if (OPAL_SUCCESS != - (ret = opal_value_array_append_item (&group->group_vars, ¶m_index))) { + if (OPAL_SUCCESS != (ret = opal_value_array_append_item(&group->group_vars, ¶m_index))) { return ret; } mca_base_var_groups_timestamp++; /* return the group index */ - return (int) opal_value_array_get_size (&group->group_vars) - 1; + return (int) opal_value_array_get_size(&group->group_vars) - 1; } -int mca_base_var_group_add_pvar (const int group_index, const int param_index) +int mca_base_var_group_add_pvar(const int group_index, const int param_index) { mca_base_var_group_t *group; int size, i, ret; int *params; - ret = mca_base_var_group_get_internal (group_index, &group, false); + ret = mca_base_var_group_get_internal(group_index, &group, false); if (OPAL_SUCCESS != ret) { return ret; } size = opal_value_array_get_size(&group->group_pvars); params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_pvars, int); - for (i = 0 ; i < size ; ++i) { + for (i = 0; i < size; ++i) { if (params[i] == param_index) { return i; } } - if (OPAL_SUCCESS != - (ret = opal_value_array_append_item (&group->group_pvars, ¶m_index))) { + if (OPAL_SUCCESS != (ret = opal_value_array_append_item(&group->group_pvars, ¶m_index))) { return ret; } mca_base_var_groups_timestamp++; /* return the group index */ - return (int) opal_value_array_get_size (&group->group_pvars) - 1; + return (int) opal_value_array_get_size(&group->group_pvars) - 1; } -int mca_base_var_group_add_enum (const int group_index, const void * storage) +int mca_base_var_group_add_enum(const int group_index, const void *storage) { mca_base_var_group_t *group; int size, i, ret; void **params; - ret = mca_base_var_group_get_internal (group_index, &group, false); + ret = mca_base_var_group_get_internal(group_index, &group, false); if (OPAL_SUCCESS != ret) { return ret; } size = opal_value_array_get_size(&group->group_enums); params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_enums, void *); - for (i = 0 ; i < size ; ++i) { + for (i = 0; i < size; ++i) { if (params[i] == storage) { return i; } } - if (OPAL_SUCCESS != - (ret = opal_value_array_append_item (&group->group_enums, storage))) { + if (OPAL_SUCCESS != (ret = opal_value_array_append_item(&group->group_enums, storage))) { return ret; } /* return the group index */ - return (int) opal_value_array_get_size (&group->group_enums) - 1; + return (int) opal_value_array_get_size(&group->group_enums) - 1; } -int mca_base_var_group_get (const int group_index, const mca_base_var_group_t **group) +int mca_base_var_group_get(const int group_index, const mca_base_var_group_t **group) { - return mca_base_var_group_get_internal (group_index, (mca_base_var_group_t **) group, false); + return mca_base_var_group_get_internal(group_index, (mca_base_var_group_t **) group, false); } -int mca_base_var_group_set_var_flag (const int group_index, int flags, bool set) +int mca_base_var_group_set_var_flag(const int group_index, int flags, bool set) { mca_base_var_group_t *group; int size, i, ret; int *vars; - ret = mca_base_var_group_get_internal (group_index, &group, false); + ret = mca_base_var_group_get_internal(group_index, &group, false); if (OPAL_SUCCESS != ret) { return ret; } @@ -509,48 +504,47 @@ int mca_base_var_group_set_var_flag (const int group_index, int flags, bool set) size = opal_value_array_get_size(&group->group_vars); vars = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, int); - for (i = 0 ; i < size ; ++i) { + for (i = 0; i < size; ++i) { if (0 <= vars[i]) { - (void) mca_base_var_set_flag (vars[i], flags, set); + (void) mca_base_var_set_flag(vars[i], flags, set); } } return OPAL_SUCCESS; } - -static void mca_base_var_group_constructor (mca_base_var_group_t *group) +static void mca_base_var_group_constructor(mca_base_var_group_t *group) { - memset ((char *) group + sizeof (group->super), 0, sizeof (*group) - sizeof (group->super)); + memset((char *) group + sizeof(group->super), 0, sizeof(*group) - sizeof(group->super)); OBJ_CONSTRUCT(&group->group_subgroups, opal_value_array_t); - opal_value_array_init (&group->group_subgroups, sizeof (int)); + opal_value_array_init(&group->group_subgroups, sizeof(int)); OBJ_CONSTRUCT(&group->group_vars, opal_value_array_t); - opal_value_array_init (&group->group_vars, sizeof (int)); + opal_value_array_init(&group->group_vars, sizeof(int)); OBJ_CONSTRUCT(&group->group_pvars, opal_value_array_t); - opal_value_array_init (&group->group_pvars, sizeof (int)); + opal_value_array_init(&group->group_pvars, sizeof(int)); OBJ_CONSTRUCT(&group->group_enums, opal_value_array_t); - opal_value_array_init (&group->group_enums, sizeof(void *)); + opal_value_array_init(&group->group_enums, sizeof(void *)); } -static void mca_base_var_group_destructor (mca_base_var_group_t *group) +static void mca_base_var_group_destructor(mca_base_var_group_t *group) { - free (group->group_full_name); + free(group->group_full_name); group->group_full_name = NULL; - free (group->group_description); + free(group->group_description); group->group_description = NULL; - free (group->group_project); + free(group->group_project); group->group_project = NULL; - free (group->group_framework); + free(group->group_framework); group->group_framework = NULL; - free (group->group_component); + free(group->group_component); group->group_component = NULL; OBJ_DESTRUCT(&group->group_subgroups); @@ -559,12 +553,12 @@ static void mca_base_var_group_destructor (mca_base_var_group_t *group) OBJ_DESTRUCT(&group->group_enums); } -int mca_base_var_group_get_count (void) +int mca_base_var_group_get_count(void) { return mca_base_var_group_count; } -int mca_base_var_group_get_stamp (void) +int mca_base_var_group_get_stamp(void) { return mca_base_var_groups_timestamp; } diff --git a/opal/mca/base/mca_base_var_group.h b/opal/mca/base/mca_base_var_group.h index e0cdbae5e6e..c68d52e7386 100644 --- a/opal/mca/base/mca_base_var_group.h +++ b/opal/mca/base/mca_base_var_group.h @@ -80,10 +80,8 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_base_var_group_t); * Create an MCA variable group. If the group already exists * this call is equivalent to mca_base_ver_find_group(). */ -OPAL_DECLSPEC int mca_base_var_group_register(const char *project_name, - const char *framework_name, - const char *component_name, - const char *description); +OPAL_DECLSPEC int mca_base_var_group_register(const char *project_name, const char *framework_name, + const char *component_name, const char *description); /** * Register an MCA variable group for a component @@ -95,8 +93,8 @@ OPAL_DECLSPEC int mca_base_var_group_register(const char *project_name, * @retval index Unique group index * @return opal error code on Error */ -OPAL_DECLSPEC int mca_base_var_group_component_register (const mca_base_component_t *component, - const char *description); +OPAL_DECLSPEC int mca_base_var_group_component_register(const mca_base_component_t *component, + const char *description); /** * Deregister an MCA param group @@ -106,7 +104,7 @@ OPAL_DECLSPEC int mca_base_var_group_component_register (const mca_base_componen * * This call deregisters all associated variables and subgroups. */ -OPAL_DECLSPEC int mca_base_var_group_deregister (int group_index); +OPAL_DECLSPEC int mca_base_var_group_deregister(int group_index); /** * Find an MCA group @@ -118,9 +116,8 @@ OPAL_DECLSPEC int mca_base_var_group_deregister (int group_index); * @returns OPAL_SUCCESS if found * @returns OPAL_ERR_NOT_FOUND if not found */ -OPAL_DECLSPEC int mca_base_var_group_find (const char *project_name, - const char *framework_name, - const char *component_name); +OPAL_DECLSPEC int mca_base_var_group_find(const char *project_name, const char *framework_name, + const char *component_name); /** * Find an MCA group by its full name @@ -131,7 +128,7 @@ OPAL_DECLSPEC int mca_base_var_group_find (const char *project_name, * @returns OPAL_SUCCESS if found * @returns OPAL_ERR_NOT_FOUND if not found */ -OPAL_DECLSPEC int mca_base_var_group_find_by_name (const char *full_name, int *index); +OPAL_DECLSPEC int mca_base_var_group_find_by_name(const char *full_name, int *index); /** * Get the group at a specified index @@ -145,8 +142,7 @@ OPAL_DECLSPEC int mca_base_var_group_find_by_name (const char *full_name, int *i * The returned pointer belongs to the MCA variable system. Do not modify/release/retain * the pointer. */ -OPAL_DECLSPEC int mca_base_var_group_get (const int group_index, - const mca_base_var_group_t **group); +OPAL_DECLSPEC int mca_base_var_group_get(const int group_index, const mca_base_var_group_t **group); /** * Set/unset a flags for all variables in a group. @@ -157,15 +153,14 @@ OPAL_DECLSPEC int mca_base_var_group_get (const int group_index, * * Set a flag for every variable in a group. See mca_base_var_set_flag() for more info. */ -OPAL_DECLSPEC int mca_base_var_group_set_var_flag (const int group_index, int flags, - bool set); +OPAL_DECLSPEC int mca_base_var_group_set_var_flag(const int group_index, int flags, bool set); /** * Get the number of registered MCA groups * * @retval count Number of registered MCA groups */ -OPAL_DECLSPEC int mca_base_var_group_get_count (void); +OPAL_DECLSPEC int mca_base_var_group_get_count(void); /** * Get a relative timestamp for the MCA group system @@ -174,6 +169,6 @@ OPAL_DECLSPEC int mca_base_var_group_get_count (void); * * This value will change if groups or variables are either added or removed. */ -OPAL_DECLSPEC int mca_base_var_group_get_stamp (void); +OPAL_DECLSPEC int mca_base_var_group_get_stamp(void); #endif /* OPAL_MCA_BASE_VAR_GROUP_H */ diff --git a/opal/mca/base/mca_base_vari.h b/opal/mca/base/mca_base_vari.h index 51f879dfda9..cc89842fdd8 100644 --- a/opal/mca/base/mca_base_vari.h +++ b/opal/mca/base/mca_base_vari.h @@ -41,13 +41,13 @@ #include "opal_config.h" -#include "opal/class/opal_object.h" +#include "opal/class/opal_hash_table.h" #include "opal/class/opal_list.h" -#include "opal/class/opal_value_array.h" +#include "opal/class/opal_object.h" #include "opal/class/opal_pointer_array.h" -#include "opal/class/opal_hash_table.h" -#include "opal/mca/base/mca_base_var.h" +#include "opal/class/opal_value_array.h" #include "opal/mca/base/mca_base_pvar.h" +#include "opal/mca/base/mca_base_var.h" BEGIN_C_DECLS @@ -56,7 +56,7 @@ BEGIN_C_DECLS typedef enum { /** Variable is valid */ - MCA_BASE_VAR_FLAG_VALID = 0x00010000, + MCA_BASE_VAR_FLAG_VALID = 0x00010000, /** Variable is a synonym */ MCA_BASE_VAR_FLAG_SYNONYM = 0x00020000, /** mbv_source_file needs to be freed */ @@ -65,12 +65,12 @@ typedef enum { #define VAR_FLAG_ISSET(var, flag) (!!((var).mbp_flags & (flag))) -#define VAR_IS_VALID(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_VALID)) -#define VAR_IS_SYNONYM(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_SYNONYM)) -#define VAR_IS_INTERNAL(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_INTERNAL)) +#define VAR_IS_VALID(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_VALID)) +#define VAR_IS_SYNONYM(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_SYNONYM)) +#define VAR_IS_INTERNAL(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_INTERNAL)) #define VAR_IS_DEFAULT_ONLY(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_DEFAULT_ONLY)) -#define VAR_IS_SETTABLE(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_SETTABLE)) -#define VAR_IS_DEPRECATED(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_DEPRECATED)) +#define VAR_IS_SETTABLE(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_SETTABLE)) +#define VAR_IS_DEPRECATED(var) (!!((var).mbv_flags & MCA_BASE_VAR_FLAG_DEPRECATED)) extern const char *ompi_var_type_names[]; extern const size_t ompi_var_type_sizes[]; @@ -116,7 +116,8 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_base_var_file_value_t); * @param[out] group Returned group if it exists * @param[in] invalidok Return group even if it has been deregistered */ -OPAL_DECLSPEC int mca_base_var_group_get_internal (const int group_index, mca_base_var_group_t **group, bool invalidok); +OPAL_DECLSPEC int mca_base_var_group_get_internal(const int group_index, + mca_base_var_group_t **group, bool invalidok); /** * \internal @@ -130,30 +131,30 @@ OPAL_DECLSPEC int mca_base_parse_paramfile(const char *paramfile, opal_list_t *l * * Add a variable to a group */ -OPAL_DECLSPEC int mca_base_var_group_add_var (const int group_index, const int param_index); +OPAL_DECLSPEC int mca_base_var_group_add_var(const int group_index, const int param_index); /** * \internal * * Add a performance variable to a group */ -OPAL_DECLSPEC int mca_base_var_group_add_pvar (const int group_index, const int param_index); +OPAL_DECLSPEC int mca_base_var_group_add_pvar(const int group_index, const int param_index); /** * \internal * * Add an enum to a group */ -OPAL_DECLSPEC int mca_base_var_group_add_enum (const int group_index, const void *storage); +OPAL_DECLSPEC int mca_base_var_group_add_enum(const int group_index, const void *storage); /** * \internal * * Generate a full name with _ between all of the non-NULL arguments */ -OPAL_DECLSPEC int mca_base_var_generate_full_name4 (const char *project, const char *framework, - const char *component, const char *variable, - char **full_name); +OPAL_DECLSPEC int mca_base_var_generate_full_name4(const char *project, const char *framework, + const char *component, const char *variable, + char **full_name); /** * \internal @@ -167,16 +168,16 @@ OPAL_DECLSPEC int mca_base_internal_env_store(void); * * Initialize/finalize MCA variable groups */ -OPAL_DECLSPEC int mca_base_var_group_init (void); -OPAL_DECLSPEC int mca_base_var_group_finalize (void); +OPAL_DECLSPEC int mca_base_var_group_init(void); +OPAL_DECLSPEC int mca_base_var_group_finalize(void); /** * \internal * * Initialize MCA performance variables */ -OPAL_DECLSPEC int mca_base_pvar_init (void); -OPAL_DECLSPEC int mca_base_pvar_finalize (void); +OPAL_DECLSPEC int mca_base_pvar_init(void); +OPAL_DECLSPEC int mca_base_pvar_finalize(void); END_C_DECLS diff --git a/opal/mca/btl/base/base.h b/opal/mca/btl/base/base.h index 76d3d8b9b9c..09c4502ef85 100644 --- a/opal/mca/btl/base/base.h +++ b/opal/mca/btl/base/base.h @@ -26,8 +26,8 @@ #include "opal_config.h" #include "opal/class/opal_list.h" -#include "opal/mca/mca.h" #include "opal/mca/btl/btl.h" +#include "opal/mca/mca.h" #define MCA_BTL_BASE_TAG_RDMA MCA_BTL_TAG_BTL_BASE #define MCA_BTL_BASE_TAG_ATOMIC (MCA_BTL_TAG_BTL_BASE + 1) @@ -36,43 +36,39 @@ BEGIN_C_DECLS struct mca_btl_base_selected_module_t { - opal_list_item_t super; - mca_btl_base_component_t *btl_component; - mca_btl_base_module_t *btl_module; + opal_list_item_t super; + mca_btl_base_component_t *btl_component; + mca_btl_base_module_t *btl_module; }; typedef struct mca_btl_base_selected_module_t mca_btl_base_selected_module_t; - /* holds the recv call back function to be called by the btl on * a receive. */ struct mca_btl_base_recv_reg_t { mca_btl_base_module_recv_cb_fn_t cbfunc; - void* cbdata; + void *cbdata; }; typedef struct mca_btl_base_recv_reg_t mca_btl_base_recv_reg_t; - OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_btl_base_selected_module_t); /* * Global functions for MCA: overall BTL open and close */ -OPAL_DECLSPEC int mca_btl_base_select(bool enable_progress_threads, bool enable_mpi_threads); -OPAL_DECLSPEC void mca_btl_base_dump( - struct mca_btl_base_module_t*, - struct mca_btl_base_endpoint_t*, - int verbose); -OPAL_DECLSPEC int mca_btl_base_param_register(mca_base_component_t *version, - mca_btl_base_module_t *module); -OPAL_DECLSPEC int mca_btl_base_param_verify(mca_btl_base_module_t *module); +OPAL_DECLSPEC int mca_btl_base_select(bool enable_progress_threads, bool enable_mpi_threads); +OPAL_DECLSPEC void mca_btl_base_dump(struct mca_btl_base_module_t *, + struct mca_btl_base_endpoint_t *, int verbose); +OPAL_DECLSPEC int mca_btl_base_param_register(mca_base_component_t *version, + mca_btl_base_module_t *module); +OPAL_DECLSPEC int mca_btl_base_param_verify(mca_btl_base_module_t *module); /* * Globals */ -extern char* mca_btl_base_include; -extern char* mca_btl_base_exclude; +extern char *mca_btl_base_include; +extern char *mca_btl_base_exclude; extern int mca_btl_base_warn_component_unused; extern int mca_btl_base_already_opened; OPAL_DECLSPEC extern opal_list_t mca_btl_base_modules_initialized; diff --git a/opal/mca/btl/base/btl_base_am_rdma.c b/opal/mca/btl/base/btl_base_am_rdma.c index 80b6af6add5..b1195b467ec 100644 --- a/opal/mca/btl/base/btl_base_am_rdma.c +++ b/opal/mca/btl/base/btl_base_am_rdma.c @@ -32,22 +32,22 @@ struct mca_btl_base_am_rdma_module_t { }; typedef struct mca_btl_base_am_rdma_module_t mca_btl_base_am_rdma_module_t; -static void mca_btl_base_am_rdma_module_init (mca_btl_base_am_rdma_module_t *module) +static void mca_btl_base_am_rdma_module_init(mca_btl_base_am_rdma_module_t *module) { - OBJ_CONSTRUCT (&module->mutex, opal_mutex_t); - OBJ_CONSTRUCT (&module->queued_responses, opal_list_t); - OBJ_CONSTRUCT (&module->queued_initiator_descriptors, opal_list_t); + OBJ_CONSTRUCT(&module->mutex, opal_mutex_t); + OBJ_CONSTRUCT(&module->queued_responses, opal_list_t); + OBJ_CONSTRUCT(&module->queued_initiator_descriptors, opal_list_t); } -static void mca_btl_base_am_rdma_module_fini (mca_btl_base_am_rdma_module_t *module) +static void mca_btl_base_am_rdma_module_fini(mca_btl_base_am_rdma_module_t *module) { - OBJ_DESTRUCT (&module->mutex); - OBJ_DESTRUCT (&module->queued_responses); - OBJ_DESTRUCT (&module->queued_initiator_descriptors); + OBJ_DESTRUCT(&module->mutex); + OBJ_DESTRUCT(&module->queued_responses); + OBJ_DESTRUCT(&module->queued_initiator_descriptors); } -static OBJ_CLASS_INSTANCE (mca_btl_base_am_rdma_module_t, opal_object_t, - mca_btl_base_am_rdma_module_init, mca_btl_base_am_rdma_module_fini); +static OBJ_CLASS_INSTANCE(mca_btl_base_am_rdma_module_t, opal_object_t, + mca_btl_base_am_rdma_module_init, mca_btl_base_am_rdma_module_fini); /** * @brief response header for an active-message RDMA/atomic operation @@ -111,15 +111,15 @@ struct mca_btl_base_rdma_context_t { }; typedef struct mca_btl_base_rdma_context_t mca_btl_base_rdma_context_t; -static void mca_btl_base_rdma_context_init (mca_btl_base_rdma_context_t *context) +static void mca_btl_base_rdma_context_init(mca_btl_base_rdma_context_t *context) { - context->sent = 0; + context->sent = 0; context->acknowledged = 0; - context->descriptor = NULL; + context->descriptor = NULL; } -static OBJ_CLASS_INSTANCE (mca_btl_base_rdma_context_t, opal_object_t, - mca_btl_base_rdma_context_init, NULL); +static OBJ_CLASS_INSTANCE(mca_btl_base_rdma_context_t, opal_object_t, + mca_btl_base_rdma_context_init, NULL); /** * @brief queued initiator descriptor @@ -132,7 +132,7 @@ struct mca_btl_base_am_rdma_queued_descriptor_t { }; typedef struct mca_btl_base_am_rdma_queued_descriptor_t mca_btl_base_am_rdma_queued_descriptor_t; -static OBJ_CLASS_INSTANCE (mca_btl_base_am_rdma_queued_descriptor_t, opal_list_item_t, NULL, NULL); +static OBJ_CLASS_INSTANCE(mca_btl_base_am_rdma_queued_descriptor_t, opal_list_item_t, NULL, NULL); /** * @brief header for an active-message atomic/RDMA operation @@ -210,42 +210,48 @@ struct mca_btl_base_rdma_operation_t { }; typedef struct mca_btl_base_rdma_operation_t mca_btl_base_rdma_operation_t; -static OBJ_CLASS_INSTANCE (mca_btl_base_rdma_operation_t, opal_list_item_t, NULL, NULL); +static OBJ_CLASS_INSTANCE(mca_btl_base_rdma_operation_t, opal_list_item_t, NULL, NULL); -static inline size_t size_t_min (size_t a, size_t b) { return (a < b) ? a : b; } +static inline size_t size_t_min(size_t a, size_t b) +{ + return (a < b) ? a : b; +} -static inline size_t size_t_max (size_t a, size_t b) { return (a > b) ? a : b; } +static inline size_t size_t_max(size_t a, size_t b) +{ + return (a > b) ? a : b; +} static mca_btl_base_am_rdma_module_t default_module; -static inline bool mca_btl_base_rdma_use_rdma_get (mca_btl_base_module_t *btl) +static inline bool mca_btl_base_rdma_use_rdma_get(mca_btl_base_module_t *btl) { return !!(btl->btl_flags & MCA_BTL_FLAGS_GET); } -static inline bool mca_btl_base_rdma_use_rdma_put (mca_btl_base_module_t *btl) +static inline bool mca_btl_base_rdma_use_rdma_put(mca_btl_base_module_t *btl) { return !!(btl->btl_flags & MCA_BTL_FLAGS_PUT); } -static inline bool mca_btl_base_rdma_is_atomic (mca_btl_base_rdma_type_t type) +static inline bool mca_btl_base_rdma_is_atomic(mca_btl_base_rdma_type_t type) { return (MCA_BTL_BASE_AM_PUT != type && MCA_BTL_BASE_AM_GET != type); } -static inline size_t mca_btl_base_rdma_operation_size (mca_btl_base_module_t *btl, - mca_btl_base_rdma_type_t type, - size_t remaining) +static inline size_t mca_btl_base_rdma_operation_size(mca_btl_base_module_t *btl, + mca_btl_base_rdma_type_t type, + size_t remaining) { switch (type) { case MCA_BTL_BASE_AM_PUT: - if (mca_btl_base_rdma_use_rdma_get (btl)) { - return size_t_min (remaining, btl->btl_get_limit); + if (mca_btl_base_rdma_use_rdma_get(btl)) { + return size_t_min(remaining, btl->btl_get_limit); } break; case MCA_BTL_BASE_AM_GET: - if (mca_btl_base_rdma_use_rdma_put (btl)) { - return size_t_min (remaining, btl->btl_put_limit); + if (mca_btl_base_rdma_use_rdma_put(btl)) { + return size_t_min(remaining, btl->btl_put_limit); } break; case MCA_BTL_BASE_AM_ATOMIC: @@ -254,12 +260,12 @@ static inline size_t mca_btl_base_rdma_operation_size (mca_btl_base_module_t *bt return remaining; } - return size_t_min (remaining, btl->btl_max_send_size - sizeof (mca_btl_base_rdma_hdr_t)); + return size_t_min(remaining, btl->btl_max_send_size - sizeof(mca_btl_base_rdma_hdr_t)); } -static inline int mca_btl_base_rdma_tag (mca_btl_base_rdma_type_t type) +static inline int mca_btl_base_rdma_tag(mca_btl_base_rdma_type_t type) { - (void)type; + (void) type; switch (type) { case MCA_BTL_BASE_AM_PUT: case MCA_BTL_BASE_AM_GET: @@ -271,7 +277,10 @@ static inline int mca_btl_base_rdma_tag (mca_btl_base_rdma_type_t type) return MCA_BTL_BASE_TAG_RDMA_RESP; } -static inline int mca_btl_base_rdma_resp_tag (void) { return MCA_BTL_BASE_TAG_RDMA_RESP; } +static inline int mca_btl_base_rdma_resp_tag(void) +{ + return MCA_BTL_BASE_TAG_RDMA_RESP; +} /** * @brief copy data from a segment to a local address @@ -281,25 +290,25 @@ static inline int mca_btl_base_rdma_resp_tag (void) { return MCA_BTL_BASE_TAG_RD * @in segments segments to copy data from * @in segment_count number of segments */ -static void mca_btl_base_copy_from_segments (uint64_t addr, size_t skip_bytes, - const mca_btl_base_segment_t *segments, - size_t segment_count) +static void mca_btl_base_copy_from_segments(uint64_t addr, size_t skip_bytes, + const mca_btl_base_segment_t *segments, + size_t segment_count) { - const void *seg0_data = (const void *)((uintptr_t)segments[0].seg_addr.pval + skip_bytes); - size_t seg0_len = segments[0].seg_len - skip_bytes; + const void *seg0_data = (const void *) ((uintptr_t) segments[0].seg_addr.pval + skip_bytes); + size_t seg0_len = segments[0].seg_len - skip_bytes; if (seg0_len > 0) { - BTL_VERBOSE ( - ("unpacking %" PRIsize_t " bytes from segment 0 to %p", seg0_len, (void *)addr)); - memcpy ((void *)addr, seg0_data, seg0_len); + BTL_VERBOSE( + ("unpacking %" PRIsize_t " bytes from segment 0 to %p", seg0_len, (void *) addr)); + memcpy((void *) addr, seg0_data, seg0_len); addr += seg0_len; } for (size_t i = 1; i < segment_count; ++i) { size_t seg_len = segments[i].seg_len; - BTL_VERBOSE (("unpacking %" PRIsize_t " bytes from segment %" PRIsize_t " to %p", seg_len, - i, (void *)addr)); - memcpy ((void *)addr, segments[i].seg_addr.pval, seg_len); + BTL_VERBOSE(("unpacking %" PRIsize_t " bytes from segment %" PRIsize_t " to %p", seg_len, i, + (void *) addr)); + memcpy((void *) addr, segments[i].seg_addr.pval, seg_len); addr += seg_len; } } @@ -312,28 +321,28 @@ static void mca_btl_base_copy_from_segments (uint64_t addr, size_t skip_bytes, * @in segments segments to copy data to * @in segment_count number of segments */ -static void mca_btl_base_copy_to_segments (uint64_t addr, size_t max_len, size_t skip_bytes, - mca_btl_base_segment_t *segments, size_t segment_count) +static void mca_btl_base_copy_to_segments(uint64_t addr, size_t max_len, size_t skip_bytes, + mca_btl_base_segment_t *segments, size_t segment_count) { - void *seg0_data = (void *)((uintptr_t)segments[0].seg_addr.pval + skip_bytes); - size_t seg0_len = size_t_min (max_len, segments[0].seg_len - skip_bytes); + void *seg0_data = (void *) ((uintptr_t) segments[0].seg_addr.pval + skip_bytes); + size_t seg0_len = size_t_min(max_len, segments[0].seg_len - skip_bytes); if (seg0_len > 0) { - BTL_VERBOSE ( + BTL_VERBOSE( ("packing %" PRIsize_t " bytes from 0x%" PRIx64 " to segment 0", seg0_len, addr)); - memcpy (seg0_data, (const void *)addr, seg0_len); + memcpy(seg0_data, (const void *) addr, seg0_len); addr += seg0_len; max_len -= seg0_len; segments[0].seg_len = seg0_len + skip_bytes; } for (size_t i = 1; i < segment_count && max_len; ++i) { - size_t seg_len = size_t_min (segments[i].seg_len, max_len); + size_t seg_len = size_t_min(segments[i].seg_len, max_len); - BTL_VERBOSE (("packing %" PRIsize_t " bytes from 0x%" PRIx64 " to segment %" PRIsize_t, - seg_len, addr, i)); + BTL_VERBOSE(("packing %" PRIsize_t " bytes from 0x%" PRIx64 " to segment %" PRIsize_t, + seg_len, addr, i)); - memcpy (segments[i].seg_addr.pval, (const void *)addr, seg_len); + memcpy(segments[i].seg_addr.pval, (const void *) addr, seg_len); segments[i].seg_len = seg_len; addr += seg_len; @@ -341,49 +350,49 @@ static void mca_btl_base_copy_to_segments (uint64_t addr, size_t max_len, size_t } } -static void mca_btl_base_am_queue_initiator_descriptor (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t *descriptor) +static void mca_btl_base_am_queue_initiator_descriptor(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor) { - mca_btl_base_am_rdma_queued_descriptor_t *queued_descriptor = - OBJ_NEW (mca_btl_base_am_rdma_queued_descriptor_t); + mca_btl_base_am_rdma_queued_descriptor_t *queued_descriptor = OBJ_NEW( + mca_btl_base_am_rdma_queued_descriptor_t); - queued_descriptor->btl = btl; - queued_descriptor->endpoint = endpoint; + queued_descriptor->btl = btl; + queued_descriptor->endpoint = endpoint; queued_descriptor->descriptor = descriptor; - OPAL_THREAD_SCOPED_LOCK ( - &default_module.mutex, - opal_list_append (&default_module.queued_initiator_descriptors, &queued_descriptor->super)); + OPAL_THREAD_SCOPED_LOCK(&default_module.mutex, + opal_list_append(&default_module.queued_initiator_descriptors, + &queued_descriptor->super)); } -static inline int mca_btl_base_am_rdma_advance (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_rdma_context_t *context, - bool send_descriptor) +static inline int mca_btl_base_am_rdma_advance(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_rdma_context_t *context, + bool send_descriptor) { const size_t remaining = context->total_size - context->sent; if (0 == remaining) { if (context->descriptor) { - btl->btl_free (btl, context->descriptor); + btl->btl_free(btl, context->descriptor); context->descriptor = NULL; } /* release the reference retained at context creation */ - OBJ_RELEASE (context); + OBJ_RELEASE(context); /* nothing more needs to be done */ return OPAL_SUCCESS; } mca_btl_base_descriptor_t *descriptor = context->descriptor; - mca_btl_base_rdma_hdr_t *hdr = - (mca_btl_base_rdma_hdr_t *)descriptor->des_segments[0].seg_addr.pval; - const size_t packet_size = mca_btl_base_rdma_operation_size (btl, hdr->type, remaining); + mca_btl_base_rdma_hdr_t *hdr = (mca_btl_base_rdma_hdr_t *) descriptor->des_segments[0] + .seg_addr.pval; + const size_t packet_size = mca_btl_base_rdma_operation_size(btl, hdr->type, remaining); - if (!mca_btl_base_rdma_is_atomic (hdr->type)) { - hdr->data.rdma.size = packet_size; - hdr->data.rdma.initiator_address = (uint64_t)context->local_address + context->sent; + if (!mca_btl_base_rdma_is_atomic(hdr->type)) { + hdr->data.rdma.size = packet_size; + hdr->data.rdma.initiator_address = (uint64_t) context->local_address + context->sent; } else { hdr->data.atomic.size = packet_size; } @@ -394,76 +403,76 @@ static inline int mca_btl_base_am_rdma_advance (mca_btl_base_module_t *btl, if (MCA_BTL_BASE_AM_PUT == hdr->type && !hdr->data.rdma.use_rdma) { /* copy the next block into the fragment buffer */ - mca_btl_base_copy_to_segments (hdr->data.rdma.initiator_address, packet_size, sizeof (*hdr), - descriptor->des_segments, descriptor->des_segment_count); + mca_btl_base_copy_to_segments(hdr->data.rdma.initiator_address, packet_size, sizeof(*hdr), + descriptor->des_segments, descriptor->des_segment_count); } if (send_descriptor) { - return btl->btl_send (btl, endpoint, descriptor, mca_btl_base_rdma_tag (hdr->type)); + return btl->btl_send(btl, endpoint, descriptor, mca_btl_base_rdma_tag(hdr->type)); } /* queue for later to avoid btl_send in callback */ - mca_btl_base_am_queue_initiator_descriptor (btl, endpoint, descriptor); + mca_btl_base_am_queue_initiator_descriptor(btl, endpoint, descriptor); return OPAL_SUCCESS; } -static void mca_btl_base_am_descriptor_complete (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t *descriptor, int status) +static void mca_btl_base_am_descriptor_complete(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor, int status) { - mca_btl_base_rdma_context_t *context = (mca_btl_base_rdma_context_t *)descriptor->des_context; + mca_btl_base_rdma_context_t *context = (mca_btl_base_rdma_context_t *) descriptor->des_context; - (void)mca_btl_base_am_rdma_advance (btl, endpoint, - (mca_btl_base_rdma_context_t *)descriptor->des_context, + (void) mca_btl_base_am_rdma_advance(btl, endpoint, + (mca_btl_base_rdma_context_t *) descriptor->des_context, /*send_descriptor=*/false); } static inline int -mca_btl_base_rdma_start (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - int type, uint64_t operand1, uint64_t operand2, - mca_btl_base_atomic_op_t op, int order, int flags, size_t size, - void *local_address, mca_btl_base_registration_handle_t *local_handle, - int64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +mca_btl_base_rdma_start(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + int type, uint64_t operand1, uint64_t operand2, mca_btl_base_atomic_op_t op, + int order, int flags, size_t size, void *local_address, + mca_btl_base_registration_handle_t *local_handle, int64_t remote_address, + mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { mca_btl_base_rdma_hdr_t *hdr; - size_t packet_size = sizeof (*hdr); + size_t packet_size = sizeof(*hdr); mca_btl_base_descriptor_t *descriptor; - mca_btl_base_rdma_context_t *context = OBJ_NEW (mca_btl_base_rdma_context_t); + mca_btl_base_rdma_context_t *context = OBJ_NEW(mca_btl_base_rdma_context_t); - if (OPAL_UNLIKELY (NULL == context)) { + if (OPAL_UNLIKELY(NULL == context)) { return OPAL_ERR_OUT_OF_RESOURCE; } - context->type = type; - context->cbfunc = cbfunc; - context->cbcontext = cbcontext; - context->cbdata = cbdata; - context->local_address = local_address; + context->type = type; + context->cbfunc = cbfunc; + context->cbcontext = cbcontext; + context->cbdata = cbdata; + context->local_address = local_address; context->remote_address = remote_address; - context->local_handle = local_handle; - context->total_size = size; + context->local_handle = local_handle; + context->total_size = size; size_t send_size = 0; size_t recv_size = 0; - bool use_rdma = false; + bool use_rdma = false; if (MCA_BTL_BASE_AM_PUT == type) { - if (sizeof (*hdr) + size <= btl->btl_eager_limit) { + if (sizeof(*hdr) + size <= btl->btl_eager_limit) { /* just go ahead and send the data */ send_size = size; - } else if (!mca_btl_base_rdma_use_rdma_get (btl)) { - send_size = size_t_min (size, btl->btl_max_send_size - sizeof (*hdr)); + } else if (!mca_btl_base_rdma_use_rdma_get(btl)) { + send_size = size_t_min(size, btl->btl_max_send_size - sizeof(*hdr)); } else { use_rdma = true; } } else if (MCA_BTL_BASE_AM_GET == type) { - if (sizeof (mca_btl_base_rdma_response_hdr_t) + size <= btl->btl_eager_limit) { + if (sizeof(mca_btl_base_rdma_response_hdr_t) + size <= btl->btl_eager_limit) { recv_size = size; - } else if (!mca_btl_base_rdma_use_rdma_put (btl)) { - recv_size = size_t_min (size, btl->btl_max_send_size - - sizeof (mca_btl_base_rdma_response_hdr_t)); + } else if (!mca_btl_base_rdma_use_rdma_put(btl)) { + recv_size = size_t_min(size, btl->btl_max_send_size + - sizeof(mca_btl_base_rdma_response_hdr_t)); } else { use_rdma = true; } @@ -478,14 +487,14 @@ mca_btl_base_rdma_start (mca_btl_base_module_t *btl, struct mca_btl_base_endpoin packet_size += send_size; - BTL_VERBOSE (("Initiating RDMA operation. context=%p, size=%" PRIsize_t - ", packet_size=%" PRIsize_t, - context, size, packet_size)); + BTL_VERBOSE(("Initiating RDMA operation. context=%p, size=%" PRIsize_t + ", packet_size=%" PRIsize_t, + context, size, packet_size)); - descriptor = btl->btl_alloc (btl, endpoint, order, packet_size, - MCA_BTL_DES_SEND_ALWAYS_CALLBACK | MCA_BTL_DES_FLAGS_SIGNAL); - if (OPAL_UNLIKELY (NULL == descriptor)) { - OBJ_RELEASE (context); + descriptor = btl->btl_alloc(btl, endpoint, order, packet_size, + MCA_BTL_DES_SEND_ALWAYS_CALLBACK | MCA_BTL_DES_FLAGS_SIGNAL); + if (OPAL_UNLIKELY(NULL == descriptor)) { + OBJ_RELEASE(context); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -493,107 +502,106 @@ mca_btl_base_rdma_start (mca_btl_base_module_t *btl, struct mca_btl_base_endpoin /* keep a reference around until the descriptor callback is complete. the initial reference may * be released on response before the descriptor callback has completed. */ - OBJ_RETAIN (context); + OBJ_RETAIN(context); - descriptor->des_cbfunc = mca_btl_base_am_descriptor_complete; - descriptor->des_cbdata = local_handle; + descriptor->des_cbfunc = mca_btl_base_am_descriptor_complete; + descriptor->des_cbdata = local_handle; descriptor->des_context = context; - hdr = (mca_btl_base_rdma_hdr_t *)descriptor->des_segments[0].seg_addr.pval; + hdr = (mca_btl_base_rdma_hdr_t *) descriptor->des_segments[0].seg_addr.pval; hdr->type = type; - if (!mca_btl_base_rdma_is_atomic (type)) { + if (!mca_btl_base_rdma_is_atomic(type)) { hdr->data.rdma.use_rdma = use_rdma; } else { - hdr->data.atomic.op = op; + hdr->data.atomic.op = op; hdr->data.atomic.operand[0] = operand1; hdr->data.atomic.operand[1] = operand2; } - hdr->context = (uintptr_t)context; + hdr->context = (uintptr_t) context; if (use_rdma && btl->btl_register_mem) { - uint8_t *handle_buffer = (uint8_t *)(hdr + 1); - memcpy (handle_buffer, local_handle, btl->btl_registration_handle_size); + uint8_t *handle_buffer = (uint8_t *) (hdr + 1); + memcpy(handle_buffer, local_handle, btl->btl_registration_handle_size); handle_buffer += btl->btl_registration_handle_size; - memcpy (handle_buffer, remote_handle, btl->btl_registration_handle_size); + memcpy(handle_buffer, remote_handle, btl->btl_registration_handle_size); } - return mca_btl_base_am_rdma_advance (btl, endpoint, context, /*send_descriptor=*/true); + return mca_btl_base_am_rdma_advance(btl, endpoint, context, /*send_descriptor=*/true); } -static mca_btl_base_rdma_operation_t *mca_btl_base_rdma_alloc_operation ( +static mca_btl_base_rdma_operation_t *mca_btl_base_rdma_alloc_operation( mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, mca_btl_base_descriptor_t *descriptor, const mca_btl_base_rdma_hdr_t *hdr) { - mca_btl_base_rdma_operation_t *operation = OBJ_NEW (mca_btl_base_rdma_operation_t); + mca_btl_base_rdma_operation_t *operation = OBJ_NEW(mca_btl_base_rdma_operation_t); if (NULL == operation) { return NULL; } - operation->btl = btl; - operation->endpoint = endpoint; - operation->descriptor = descriptor; + operation->btl = btl; + operation->endpoint = endpoint; + operation->descriptor = descriptor; operation->is_completed = false; - operation->is_queued = false; - memcpy (&operation->hdr, hdr, sizeof (*hdr)); + operation->is_queued = false; + memcpy(&operation->hdr, hdr, sizeof(*hdr)); - if (!mca_btl_base_rdma_is_atomic (hdr->type) && hdr->data.rdma.use_rdma && - btl->btl_register_mem) { - const uint8_t *handle_data = (const uint8_t *)(hdr + 1); + if (!mca_btl_base_rdma_is_atomic(hdr->type) && hdr->data.rdma.use_rdma + && btl->btl_register_mem) { + const uint8_t *handle_data = (const uint8_t *) (hdr + 1); /* the initiator packs these in order of their local and then remote. */ - memcpy (operation->remote_handle_data, handle_data, btl->btl_registration_handle_size); + memcpy(operation->remote_handle_data, handle_data, btl->btl_registration_handle_size); handle_data += btl->btl_registration_handle_size; - memcpy (operation->local_handle_data, handle_data, btl->btl_registration_handle_size); + memcpy(operation->local_handle_data, handle_data, btl->btl_registration_handle_size); } return operation; } -static void mca_btl_base_rdma_queue_operation (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t *descriptor, - uint64_t atomic_response, - const mca_btl_base_rdma_hdr_t *hdr, - mca_btl_base_rdma_operation_t *operation) +static void mca_btl_base_rdma_queue_operation(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor, + uint64_t atomic_response, + const mca_btl_base_rdma_hdr_t *hdr, + mca_btl_base_rdma_operation_t *operation) { if (NULL == operation) { - operation = mca_btl_base_rdma_alloc_operation (btl, endpoint, descriptor, hdr); + operation = mca_btl_base_rdma_alloc_operation(btl, endpoint, descriptor, hdr); if (NULL == operation) { /* couldn't even allocate a small amount of memory. not much else can be done. */ - BTL_ERROR (("could not allocate memory to queue active-message RDMA operation")); - abort (); + BTL_ERROR(("could not allocate memory to queue active-message RDMA operation")); + abort(); } } - operation->is_queued = true; + operation->is_queued = true; operation->atomic_response = atomic_response; - OPAL_THREAD_SCOPED_LOCK ( - &default_module.mutex, - opal_list_append (&default_module.queued_responses, &operation->super)); + OPAL_THREAD_SCOPED_LOCK(&default_module.mutex, + opal_list_append(&default_module.queued_responses, &operation->super)); } -static int mca_btl_base_am_rdma_respond (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t **descriptor, void *addr, - const mca_btl_base_rdma_hdr_t *hdr) +static int mca_btl_base_am_rdma_respond(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t **descriptor, void *addr, + const mca_btl_base_rdma_hdr_t *hdr) { mca_btl_base_descriptor_t *send_descriptor = *descriptor; - *descriptor = NULL; + *descriptor = NULL; if (NULL == send_descriptor) { mca_btl_base_rdma_response_hdr_t *resp_hdr; - size_t data_size = - mca_btl_base_rdma_is_atomic (hdr->type) ? hdr->data.atomic.size : hdr->data.rdma.size; - size_t packet_size = sizeof (*resp_hdr) + (addr ? data_size : 0); - send_descriptor = btl->btl_alloc (btl, endpoint, MCA_BTL_NO_ORDER, packet_size, - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); + size_t data_size = mca_btl_base_rdma_is_atomic(hdr->type) ? hdr->data.atomic.size + : hdr->data.rdma.size; + size_t packet_size = sizeof(*resp_hdr) + (addr ? data_size : 0); + send_descriptor = btl->btl_alloc(btl, endpoint, MCA_BTL_NO_ORDER, packet_size, + MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); if (NULL == send_descriptor) { return OPAL_ERR_OUT_OF_RESOURCE; } - resp_hdr = - (mca_btl_base_rdma_response_hdr_t *)send_descriptor->des_segments[0].seg_addr.pval; + resp_hdr = (mca_btl_base_rdma_response_hdr_t *) send_descriptor->des_segments[0] + .seg_addr.pval; resp_hdr->context = hdr->context; if (MCA_BTL_BASE_AM_GET == hdr->type) { resp_hdr->initiator_address = hdr->data.rdma.initiator_address; @@ -604,222 +612,219 @@ static int mca_btl_base_am_rdma_respond (mca_btl_base_module_t *btl, resp_hdr->response_size = data_size; if (NULL != addr) { - mca_btl_base_copy_to_segments ((uint64_t) (uintptr_t)addr, packet_size, - sizeof (*resp_hdr), send_descriptor->des_segments, - send_descriptor->des_segment_count); + mca_btl_base_copy_to_segments((uint64_t)(uintptr_t) addr, packet_size, + sizeof(*resp_hdr), send_descriptor->des_segments, + send_descriptor->des_segment_count); } } - BTL_VERBOSE (("sending descriptor %p", send_descriptor)); + BTL_VERBOSE(("sending descriptor %p", send_descriptor)); send_descriptor->des_cbfunc = NULL; - int ret = btl->btl_send (btl, endpoint, send_descriptor, mca_btl_base_rdma_resp_tag ()); - if (OPAL_UNLIKELY (OPAL_SUCCESS != ret)) { + int ret = btl->btl_send(btl, endpoint, send_descriptor, mca_btl_base_rdma_resp_tag()); + if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) { *descriptor = send_descriptor; } return ret; } static void -mca_btl_base_am_rmda_rdma_complete (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - struct mca_btl_base_registration_handle_t *local_handle, - void *context, void *cbdata, int status) +mca_btl_base_am_rmda_rdma_complete(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + struct mca_btl_base_registration_handle_t *local_handle, + void *context, void *cbdata, int status) { - mca_btl_base_rdma_operation_t *operation = (mca_btl_base_rdma_operation_t *)context; + mca_btl_base_rdma_operation_t *operation = (mca_btl_base_rdma_operation_t *) context; - BTL_VERBOSE (("BTL RDMA operation complete. status=%d", status)); + BTL_VERBOSE(("BTL RDMA operation complete. status=%d", status)); - assert (OPAL_SUCCESS == status); + assert(OPAL_SUCCESS == status); operation->is_completed = true; - int ret = mca_btl_base_am_rdma_respond (operation->btl, operation->endpoint, - &operation->descriptor, NULL, &operation->hdr); - if (OPAL_UNLIKELY (OPAL_SUCCESS != ret)) { - BTL_VERBOSE ( + int ret = mca_btl_base_am_rdma_respond(operation->btl, operation->endpoint, + &operation->descriptor, NULL, &operation->hdr); + if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) { + BTL_VERBOSE( ("could not send a response. queueing the response for later. endpoint=%p, ret=%d", endpoint, ret)); - mca_btl_base_rdma_queue_operation (btl, NULL, NULL, 0, NULL, operation); + mca_btl_base_rdma_queue_operation(btl, NULL, NULL, 0, NULL, operation); } - OBJ_RELEASE (operation); + OBJ_RELEASE(operation); } -static int mca_btl_base_am_rdma_target_get (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t **descriptor, - void *target_address, - const mca_btl_base_rdma_hdr_t *hdr, - mca_btl_base_rdma_operation_t **operation) +static int mca_btl_base_am_rdma_target_get(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t **descriptor, + void *target_address, const mca_btl_base_rdma_hdr_t *hdr, + mca_btl_base_rdma_operation_t **operation) { if (hdr->data.rdma.use_rdma) { if (NULL == *operation) { - *operation = mca_btl_base_rdma_alloc_operation (btl, endpoint, *descriptor, hdr); + *operation = mca_btl_base_rdma_alloc_operation(btl, endpoint, *descriptor, hdr); if (NULL == *operation) { return OPAL_ERR_OUT_OF_RESOURCE; } } /* btl supports put but not get. emulating get with put */ - OBJ_RETAIN (*operation); - int ret = btl->btl_put ( + OBJ_RETAIN(*operation); + int ret = btl->btl_put( btl, endpoint, target_address, hdr->data.rdma.initiator_address, - (struct mca_btl_base_registration_handle_t *)(*operation)->local_handle_data, - (struct mca_btl_base_registration_handle_t *)(*operation)->remote_handle_data, + (struct mca_btl_base_registration_handle_t *) (*operation)->local_handle_data, + (struct mca_btl_base_registration_handle_t *) (*operation)->remote_handle_data, hdr->data.rdma.size, /*flags=*/0, MCA_BTL_NO_ORDER, mca_btl_base_am_rmda_rdma_complete, *operation, NULL); if (OPAL_SUCCESS != ret) { - OBJ_RELEASE (*operation); + OBJ_RELEASE(*operation); } if (OPAL_ERR_NOT_AVAILABLE != ret) { return ret; } } - return mca_btl_base_am_rdma_respond (btl, endpoint, descriptor, target_address, hdr); + return mca_btl_base_am_rdma_respond(btl, endpoint, descriptor, target_address, hdr); } -static int mca_btl_base_am_rdma_target_put (mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t **descriptor, - const mca_btl_base_segment_t *segments, - size_t segment_count, void *target_address, - const mca_btl_base_rdma_hdr_t *hdr, - mca_btl_base_rdma_operation_t **operation) +static int mca_btl_base_am_rdma_target_put(mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t **descriptor, + const mca_btl_base_segment_t *segments, + size_t segment_count, void *target_address, + const mca_btl_base_rdma_hdr_t *hdr, + mca_btl_base_rdma_operation_t **operation) { if (hdr->data.rdma.use_rdma) { if (NULL == *operation) { - *operation = mca_btl_base_rdma_alloc_operation (btl, endpoint, *descriptor, hdr); + *operation = mca_btl_base_rdma_alloc_operation(btl, endpoint, *descriptor, hdr); if (NULL == *operation) { return OPAL_ERR_OUT_OF_RESOURCE; } } /* btl supports put but not get. emulating get with put */ - OBJ_RETAIN (*operation); - int ret = btl->btl_get ( + OBJ_RETAIN(*operation); + int ret = btl->btl_get( btl, endpoint, target_address, hdr->data.rdma.initiator_address, - (struct mca_btl_base_registration_handle_t *)(*operation)->local_handle_data, - (struct mca_btl_base_registration_handle_t *)(*operation)->remote_handle_data, + (struct mca_btl_base_registration_handle_t *) (*operation)->local_handle_data, + (struct mca_btl_base_registration_handle_t *) (*operation)->remote_handle_data, hdr->data.rdma.size, /*flags=*/0, MCA_BTL_NO_ORDER, mca_btl_base_am_rmda_rdma_complete, operation, NULL); if (OPAL_SUCCESS != ret) { - OBJ_RELEASE (*operation); + OBJ_RELEASE(*operation); } if (OPAL_ERR_NOT_AVAILABLE != ret) { return ret; } } else if (NULL != segments) { - mca_btl_base_copy_from_segments (hdr->target_address, sizeof (*hdr), segments, - segment_count); + mca_btl_base_copy_from_segments(hdr->target_address, sizeof(*hdr), segments, segment_count); } - return mca_btl_base_am_rdma_respond (btl, endpoint, descriptor, NULL, hdr); + return mca_btl_base_am_rdma_respond(btl, endpoint, descriptor, NULL, hdr); } -static void mca_btl_base_rdma_retry_operation (mca_btl_base_rdma_operation_t *operation) +static void mca_btl_base_rdma_retry_operation(mca_btl_base_rdma_operation_t *operation) { mca_btl_base_module_t *btl = operation->btl; - void *target_address = (void *)(intptr_t)operation->hdr.target_address; + void *target_address = (void *) (intptr_t) operation->hdr.target_address; int ret; if (!operation->descriptor && !operation->is_completed) { switch (operation->hdr.type) { case MCA_BTL_BASE_AM_GET: - ret = mca_btl_base_am_rdma_target_get (operation->btl, operation->endpoint, - &operation->descriptor, target_address, - &operation->hdr, &operation); + ret = mca_btl_base_am_rdma_target_get(operation->btl, operation->endpoint, + &operation->descriptor, target_address, + &operation->hdr, &operation); break; case MCA_BTL_BASE_AM_PUT: - ret = mca_btl_base_am_rdma_target_put ( - operation->btl, operation->endpoint, &operation->descriptor, - /*segments=*/NULL, - /*segment_count=*/0, target_address, &operation->hdr, &operation); + ret = mca_btl_base_am_rdma_target_put(operation->btl, operation->endpoint, + &operation->descriptor, + /*segments=*/NULL, + /*segment_count=*/0, target_address, + &operation->hdr, &operation); break; case MCA_BTL_BASE_AM_ATOMIC: /* atomic operation was completed */ - ret = mca_btl_base_am_rdma_respond (operation->btl, operation->endpoint, - &operation->descriptor, &operation->atomic_response, - &operation->hdr); + ret = mca_btl_base_am_rdma_respond(operation->btl, operation->endpoint, + &operation->descriptor, &operation->atomic_response, + &operation->hdr); break; } } else { - ret = mca_btl_base_am_rdma_respond (operation->btl, operation->endpoint, - &operation->descriptor, - /*addr=*/NULL, /*hdr=*/NULL); + ret = mca_btl_base_am_rdma_respond(operation->btl, operation->endpoint, + &operation->descriptor, + /*addr=*/NULL, /*hdr=*/NULL); } if (OPAL_SUCCESS == ret) { if (operation->is_queued) { - opal_list_remove_item (&default_module.queued_responses, &operation->super); + opal_list_remove_item(&default_module.queued_responses, &operation->super); } - OBJ_RELEASE (operation); + OBJ_RELEASE(operation); } } -static int mca_btl_base_am_rdma_progress (void) +static int mca_btl_base_am_rdma_progress(void) { - if (0 == opal_list_get_size (&default_module.queued_responses) && - 0 == opal_list_get_size (&default_module.queued_initiator_descriptors)) { + if (0 == opal_list_get_size(&default_module.queued_responses) + && 0 == opal_list_get_size(&default_module.queued_initiator_descriptors)) { return 0; } - OPAL_THREAD_SCOPED_LOCK (&default_module.mutex, ({ + OPAL_THREAD_SCOPED_LOCK(&default_module.mutex, ({ mca_btl_base_rdma_operation_t *operation, *next; OPAL_LIST_FOREACH_SAFE (operation, next, &default_module.queued_responses, - mca_btl_base_rdma_operation_t) - { - mca_btl_base_rdma_retry_operation (operation); + mca_btl_base_rdma_operation_t) { + mca_btl_base_rdma_retry_operation(operation); } })); - OPAL_THREAD_SCOPED_LOCK (&default_module.mutex, ({ + OPAL_THREAD_SCOPED_LOCK(&default_module.mutex, ({ mca_btl_base_am_rdma_queued_descriptor_t *descriptor, *next; OPAL_LIST_FOREACH_SAFE (descriptor, next, &default_module.queued_initiator_descriptors, - mca_btl_base_am_rdma_queued_descriptor_t) - { - mca_btl_base_rdma_context_t *context = - (mca_btl_base_rdma_context_t *)descriptor->descriptor->des_context; - int ret = descriptor->btl->btl_send (descriptor->btl, descriptor->endpoint, - descriptor->descriptor, - mca_btl_base_rdma_tag (context->type)); + mca_btl_base_am_rdma_queued_descriptor_t) { + mca_btl_base_rdma_context_t *context = (mca_btl_base_rdma_context_t *) + descriptor->descriptor->des_context; + int ret = descriptor->btl->btl_send(descriptor->btl, descriptor->endpoint, + descriptor->descriptor, + mca_btl_base_rdma_tag(context->type)); if (OPAL_SUCCESS == ret) { - opal_list_remove_item (&default_module.queued_initiator_descriptors, - &descriptor->super); + opal_list_remove_item(&default_module.queued_initiator_descriptors, + &descriptor->super); } } })); } -static int mca_btl_base_am_atomic_64 (int64_t *operand, opal_atomic_int64_t *addr, - mca_btl_base_atomic_op_t op) +static int mca_btl_base_am_atomic_64(int64_t *operand, opal_atomic_int64_t *addr, + mca_btl_base_atomic_op_t op) { int64_t result = 0; switch (op) { case MCA_BTL_ATOMIC_ADD: - result = opal_atomic_fetch_add_64 (addr, *operand); + result = opal_atomic_fetch_add_64(addr, *operand); break; case MCA_BTL_ATOMIC_AND: - result = opal_atomic_fetch_and_64 (addr, *operand); + result = opal_atomic_fetch_and_64(addr, *operand); break; case MCA_BTL_ATOMIC_OR: - result = opal_atomic_fetch_or_64 (addr, *operand); + result = opal_atomic_fetch_or_64(addr, *operand); break; case MCA_BTL_ATOMIC_XOR: - result = opal_atomic_fetch_xor_64 (addr, *operand); + result = opal_atomic_fetch_xor_64(addr, *operand); break; case MCA_BTL_ATOMIC_SWAP: - result = opal_atomic_swap_64 (addr, *operand); + result = opal_atomic_swap_64(addr, *operand); break; case MCA_BTL_ATOMIC_MIN: - result = opal_atomic_fetch_min_64 (addr, *operand); + result = opal_atomic_fetch_min_64(addr, *operand); break; case MCA_BTL_ATOMIC_MAX: - result = opal_atomic_fetch_max_64 (addr, *operand); + result = opal_atomic_fetch_max_64(addr, *operand); break; default: return OPAL_ERR_BAD_PARAM; @@ -829,32 +834,32 @@ static int mca_btl_base_am_atomic_64 (int64_t *operand, opal_atomic_int64_t *add return OPAL_SUCCESS; } -static int mca_btl_base_am_atomic_32 (int32_t *operand, opal_atomic_int32_t *addr, - mca_btl_base_atomic_op_t op) +static int mca_btl_base_am_atomic_32(int32_t *operand, opal_atomic_int32_t *addr, + mca_btl_base_atomic_op_t op) { int32_t result = 0; switch (op) { case MCA_BTL_ATOMIC_ADD: - result = opal_atomic_fetch_add_32 (addr, *operand); + result = opal_atomic_fetch_add_32(addr, *operand); break; case MCA_BTL_ATOMIC_AND: - result = opal_atomic_fetch_and_32 (addr, *operand); + result = opal_atomic_fetch_and_32(addr, *operand); break; case MCA_BTL_ATOMIC_OR: - result = opal_atomic_fetch_or_32 (addr, *operand); + result = opal_atomic_fetch_or_32(addr, *operand); break; case MCA_BTL_ATOMIC_XOR: - result = opal_atomic_fetch_xor_32 (addr, *operand); + result = opal_atomic_fetch_xor_32(addr, *operand); break; case MCA_BTL_ATOMIC_SWAP: - result = opal_atomic_swap_32 (addr, *operand); + result = opal_atomic_swap_32(addr, *operand); break; case MCA_BTL_ATOMIC_MIN: - result = opal_atomic_fetch_min_32 (addr, *operand); + result = opal_atomic_fetch_min_32(addr, *operand); break; case MCA_BTL_ATOMIC_MAX: - result = opal_atomic_fetch_max_32 (addr, *operand); + result = opal_atomic_fetch_max_32(addr, *operand); break; default: return OPAL_ERR_BAD_PARAM; @@ -864,271 +869,271 @@ static int mca_btl_base_am_atomic_32 (int32_t *operand, opal_atomic_int32_t *add return OPAL_SUCCESS; } -static void mca_btl_base_am_rdma_response (mca_btl_base_module_t *btl, - const mca_btl_base_receive_descriptor_t *desc) +static void mca_btl_base_am_rdma_response(mca_btl_base_module_t *btl, + const mca_btl_base_receive_descriptor_t *desc) { - mca_btl_base_rdma_response_hdr_t *resp_hdr = - (mca_btl_base_rdma_response_hdr_t *)desc->des_segments[0].seg_addr.pval; + mca_btl_base_rdma_response_hdr_t *resp_hdr = (mca_btl_base_rdma_response_hdr_t *) desc + ->des_segments[0] + .seg_addr.pval; - assert (desc->des_segments[0].seg_len >= sizeof (*resp_hdr)); + assert(desc->des_segments[0].seg_len >= sizeof(*resp_hdr)); - mca_btl_base_rdma_context_t *context = - (mca_btl_base_rdma_context_t *)(uintptr_t)resp_hdr->context; + mca_btl_base_rdma_context_t *context = (mca_btl_base_rdma_context_t *) (uintptr_t) + resp_hdr->context; - BTL_VERBOSE (("received response for RDMA operation. context=%p, size=%" PRIu64, context, - resp_hdr->response_size)); + BTL_VERBOSE(("received response for RDMA operation. context=%p, size=%" PRIu64, context, + resp_hdr->response_size)); if (MCA_BTL_BASE_AM_PUT != context->type) { uint64_t local_address = resp_hdr->initiator_address ? resp_hdr->initiator_address - : (uintptr_t)context->local_address; + : (uintptr_t) context->local_address; if (local_address && MCA_BTL_BASE_AM_PUT != context->type) { - BTL_VERBOSE (("unpacking response from packet")); + BTL_VERBOSE(("unpacking response from packet")); /* if there is a result copy it out of the incoming buffer. if RDMA is being used * (get/put or put/get) then the header should be the only thing in the incoming * message. */ - mca_btl_base_copy_from_segments (local_address, sizeof (*resp_hdr), desc->des_segments, - desc->des_segment_count); + mca_btl_base_copy_from_segments(local_address, sizeof(*resp_hdr), desc->des_segments, + desc->des_segment_count); } } - if (context->total_size == - opal_atomic_add_fetch_64 (&context->acknowledged, resp_hdr->response_size)) { - context->cbfunc (btl, desc->endpoint, context->local_address, context->local_handle, - context->cbcontext, context->cbdata, OPAL_SUCCESS); - OBJ_RELEASE (context); + if (context->total_size + == opal_atomic_add_fetch_64(&context->acknowledged, resp_hdr->response_size)) { + context->cbfunc(btl, desc->endpoint, context->local_address, context->local_handle, + context->cbcontext, context->cbdata, OPAL_SUCCESS); + OBJ_RELEASE(context); } } -static void mca_btl_base_am_process_rdma (mca_btl_base_module_t *btl, - const mca_btl_base_receive_descriptor_t *desc) +static void mca_btl_base_am_process_rdma(mca_btl_base_module_t *btl, + const mca_btl_base_receive_descriptor_t *desc) { /* not all btls work with these active message atomics. at this time * all of the affected btls already have atomic support so there is * no need to attempt to get the endpoint here. */ if (NULL == desc->endpoint) { - BTL_ERROR (("BTL is not compatible with active-message RDMA")); - abort (); + BTL_ERROR(("BTL is not compatible with active-message RDMA")); + abort(); } - const mca_btl_base_rdma_hdr_t *hdr = - (mca_btl_base_rdma_hdr_t *)desc->des_segments[0].seg_addr.pval; - void *target_address = (void *)(intptr_t)hdr->target_address; - mca_btl_base_descriptor_t *descriptor = NULL; + const mca_btl_base_rdma_hdr_t *hdr = (mca_btl_base_rdma_hdr_t *) desc->des_segments[0] + .seg_addr.pval; + void *target_address = (void *) (intptr_t) hdr->target_address; + mca_btl_base_descriptor_t *descriptor = NULL; mca_btl_base_rdma_operation_t *operation = NULL; int ret; - BTL_VERBOSE (("got active-message \"RDMA\" request. hdr->context=0x%" PRIx64 - ", target_address=%p, " - "segment 0 size=%" PRIu64, - hdr->context, target_address, desc->des_segments[0].seg_len)); + BTL_VERBOSE(("got active-message \"RDMA\" request. hdr->context=0x%" PRIx64 + ", target_address=%p, " + "segment 0 size=%" PRIu64, + hdr->context, target_address, desc->des_segments[0].seg_len)); if (MCA_BTL_BASE_AM_PUT == hdr->type) { - ret = mca_btl_base_am_rdma_target_put (btl, desc->endpoint, &descriptor, desc->des_segments, - desc->des_segment_count, target_address, hdr, - &operation); + ret = mca_btl_base_am_rdma_target_put(btl, desc->endpoint, &descriptor, desc->des_segments, + desc->des_segment_count, target_address, hdr, + &operation); } else if (MCA_BTL_BASE_AM_GET == hdr->type) { - ret = mca_btl_base_am_rdma_target_get (btl, desc->endpoint, &descriptor, target_address, - hdr, &operation); + ret = mca_btl_base_am_rdma_target_get(btl, desc->endpoint, &descriptor, target_address, hdr, + &operation); } else { - BTL_ERROR (("Unexpected tag when processing active-message RDMA request")); - abort (); + BTL_ERROR(("Unexpected tag when processing active-message RDMA request")); + abort(); } if (OPAL_SUCCESS != ret) { - mca_btl_base_rdma_queue_operation (btl, desc->endpoint, descriptor, 0, hdr, operation); + mca_btl_base_rdma_queue_operation(btl, desc->endpoint, descriptor, 0, hdr, operation); } } -static void mca_btl_base_am_process_atomic (mca_btl_base_module_t *btl, - const mca_btl_base_receive_descriptor_t *desc) +static void mca_btl_base_am_process_atomic(mca_btl_base_module_t *btl, + const mca_btl_base_receive_descriptor_t *desc) { /* not all btls work with these active message atomics. at this time * all of the affected btls already have atomic support so there is * no need to attempt to get the endpoint here. */ if (NULL == desc->endpoint) { - BTL_ERROR (("BTL is not compatible with active-message RDMA")); - abort (); + BTL_ERROR(("BTL is not compatible with active-message RDMA")); + abort(); } - const mca_btl_base_rdma_hdr_t *hdr = - (mca_btl_base_rdma_hdr_t *)desc->des_segments[0].seg_addr.pval; - void *target_address = (void *)(intptr_t)hdr->target_address; + const mca_btl_base_rdma_hdr_t *hdr = (mca_btl_base_rdma_hdr_t *) desc->des_segments[0] + .seg_addr.pval; + void *target_address = (void *) (intptr_t) hdr->target_address; uint64_t atomic_response = hdr->data.atomic.operand[0]; if (4 != hdr->data.atomic.size && 8 != hdr->data.atomic.size) { - BTL_ERROR (("Unexpected atomic operation size: %hu", hdr->data.atomic.size)); - abort (); + BTL_ERROR(("Unexpected atomic operation size: %hu", hdr->data.atomic.size)); + abort(); } - BTL_VERBOSE (("got active-message atomic request. hdr->context=0x%" PRIx64 - ", target_address=%p, " - "segment 0 size=%" PRIu64, - hdr->context, target_address, desc->des_segments[0].seg_len)); + BTL_VERBOSE(("got active-message atomic request. hdr->context=0x%" PRIx64 + ", target_address=%p, " + "segment 0 size=%" PRIu64, + hdr->context, target_address, desc->des_segments[0].seg_len)); switch (hdr->type) { case MCA_BTL_BASE_AM_ATOMIC: if (4 == hdr->data.atomic.size) { - uint32_t tmp = (uint32_t)atomic_response; - mca_btl_base_am_atomic_32 (&tmp, (opal_atomic_int32_t *)(uintptr_t)hdr->target_address, - hdr->data.atomic.op); + uint32_t tmp = (uint32_t) atomic_response; + mca_btl_base_am_atomic_32(&tmp, (opal_atomic_int32_t *) (uintptr_t) hdr->target_address, + hdr->data.atomic.op); atomic_response = tmp; } if (8 == hdr->data.atomic.size) { - mca_btl_base_am_atomic_64 ((int64_t *)hdr->target_address, - (opal_atomic_int64_t *)(uintptr_t)hdr->target_address, - hdr->data.atomic.op); + mca_btl_base_am_atomic_64((int64_t *) hdr->target_address, + (opal_atomic_int64_t *) (uintptr_t) hdr->target_address, + hdr->data.atomic.op); } break; case MCA_BTL_BASE_AM_CAS: if (4 == hdr->data.atomic.size) { - int32_t tmp = (int32_t)atomic_response; - opal_atomic_compare_exchange_strong_32 ((opal_atomic_int32_t *)hdr->target_address, - &tmp, (int32_t)hdr->data.atomic.operand[1]); + int32_t tmp = (int32_t) atomic_response; + opal_atomic_compare_exchange_strong_32((opal_atomic_int32_t *) hdr->target_address, + &tmp, (int32_t) hdr->data.atomic.operand[1]); atomic_response = tmp; } if (8 == hdr->data.atomic.size) { - opal_atomic_compare_exchange_strong_64 ((opal_atomic_int64_t *)hdr->target_address, - &atomic_response, hdr->data.atomic.operand[1]); + opal_atomic_compare_exchange_strong_64((opal_atomic_int64_t *) hdr->target_address, + &atomic_response, hdr->data.atomic.operand[1]); } break; default: - BTL_ERROR (("Unexpected AM atomic request type")); - abort (); + BTL_ERROR(("Unexpected AM atomic request type")); + abort(); } mca_btl_base_descriptor_t *descriptor = NULL; - int ret = - mca_btl_base_am_rdma_respond (btl, desc->endpoint, &descriptor, &atomic_response, hdr); + int ret = mca_btl_base_am_rdma_respond(btl, desc->endpoint, &descriptor, &atomic_response, hdr); if (OPAL_SUCCESS != ret) { - mca_btl_base_rdma_queue_operation (btl, desc->endpoint, descriptor, atomic_response, hdr, - NULL); + mca_btl_base_rdma_queue_operation(btl, desc->endpoint, descriptor, atomic_response, hdr, + NULL); } } -void mca_btl_sm_sc_emu_init (void) +void mca_btl_sm_sc_emu_init(void) { - mca_btl_base_active_message_trigger[MCA_BTL_BASE_TAG_RDMA].cbfunc = - mca_btl_base_am_process_rdma; - mca_btl_base_active_message_trigger[MCA_BTL_BASE_TAG_ATOMIC].cbfunc = - mca_btl_base_am_process_atomic; - mca_btl_base_active_message_trigger[MCA_BTL_BASE_TAG_RDMA_RESP].cbfunc = - mca_btl_base_am_rdma_response; + mca_btl_base_active_message_trigger[MCA_BTL_BASE_TAG_RDMA].cbfunc + = mca_btl_base_am_process_rdma; + mca_btl_base_active_message_trigger[MCA_BTL_BASE_TAG_ATOMIC].cbfunc + = mca_btl_base_am_process_atomic; + mca_btl_base_active_message_trigger[MCA_BTL_BASE_TAG_RDMA_RESP].cbfunc + = mca_btl_base_am_rdma_response; } -static int mca_btl_base_am_fop (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, - mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, - void *cbdata) +static int mca_btl_base_am_fop(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { size_t size = (flags & MCA_BTL_ATOMIC_FLAG_32BIT) ? 4 : 8; - return mca_btl_base_rdma_start (btl, endpoint, MCA_BTL_BASE_AM_ATOMIC, operand, 0, op, order, - flags, size, local_address, local_handle, remote_address, - remote_handle, cbfunc, cbcontext, cbdata); + return mca_btl_base_rdma_start(btl, endpoint, MCA_BTL_BASE_AM_ATOMIC, operand, 0, op, order, + flags, size, local_address, local_handle, remote_address, + remote_handle, cbfunc, cbcontext, cbdata); } -static int mca_btl_base_am_cswap ( +static int mca_btl_base_am_cswap( struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { size_t size = (flags & MCA_BTL_ATOMIC_FLAG_32BIT) ? 4 : 8; - return mca_btl_base_rdma_start (btl, endpoint, MCA_BTL_BASE_AM_CAS, compare, value, 0, order, - flags, size, local_address, local_handle, remote_address, - remote_handle, cbfunc, cbcontext, cbdata); + return mca_btl_base_rdma_start(btl, endpoint, MCA_BTL_BASE_AM_CAS, compare, value, 0, order, + flags, size, local_address, local_handle, remote_address, + remote_handle, cbfunc, cbcontext, cbdata); } -static int mca_btl_base_am_rdma_get (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, - struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, - size_t size, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, - void *cbdata) +static int mca_btl_base_am_rdma_get(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, + size_t size, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { - return mca_btl_base_rdma_start (btl, endpoint, MCA_BTL_BASE_AM_GET, 0, 0, 0, order, flags, size, - local_address, local_handle, remote_address, remote_handle, - cbfunc, cbcontext, cbdata); + return mca_btl_base_rdma_start(btl, endpoint, MCA_BTL_BASE_AM_GET, 0, 0, 0, order, flags, size, + local_address, local_handle, remote_address, remote_handle, + cbfunc, cbcontext, cbdata); } -static int mca_btl_base_am_rdma_put (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, - struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, - size_t size, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, - void *cbdata) +static int mca_btl_base_am_rdma_put(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, + size_t size, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { - return mca_btl_base_rdma_start (btl, endpoint, MCA_BTL_BASE_AM_PUT, 0, 0, 0, order, flags, size, - local_address, local_handle, remote_address, remote_handle, - cbfunc, cbcontext, cbdata); + return mca_btl_base_rdma_start(btl, endpoint, MCA_BTL_BASE_AM_PUT, 0, 0, 0, order, flags, size, + local_address, local_handle, remote_address, remote_handle, + cbfunc, cbcontext, cbdata); } -int mca_btl_base_am_rdma_init (mca_btl_base_module_t *btl) +int mca_btl_base_am_rdma_init(mca_btl_base_module_t *btl) { static bool progress_registered = false; - if ((btl->btl_flags & (MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_ATOMIC_FOPS)) == - (MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_ATOMIC_FOPS)) { + if ((btl->btl_flags & (MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_ATOMIC_FOPS)) + == (MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_ATOMIC_FOPS)) { /* nothing to do */ return OPAL_SUCCESS; } - size_t max_operation_size = btl->btl_max_send_size; + size_t max_operation_size = btl->btl_max_send_size; size_t operation_alignment = 1; - if (mca_btl_base_rdma_use_rdma_get (btl)) { + if (mca_btl_base_rdma_use_rdma_get(btl)) { /* implement put over get. */ - max_operation_size = btl->btl_get_limit; + max_operation_size = btl->btl_get_limit; operation_alignment = btl->btl_get_alignment; - } else if (mca_btl_base_rdma_use_rdma_put (btl)) { + } else if (mca_btl_base_rdma_use_rdma_put(btl)) { /* implement get over put. */ - max_operation_size = btl->btl_put_limit; + max_operation_size = btl->btl_put_limit; operation_alignment = btl->btl_put_alignment; } if (!(btl->btl_flags & MCA_BTL_FLAGS_PUT)) { - BTL_VERBOSE (("Enabling AM-based RDMA put for BTL %p", btl)); + BTL_VERBOSE(("Enabling AM-based RDMA put for BTL %p", btl)); btl->btl_flags |= MCA_BTL_FLAGS_PUT_AM; - btl->btl_put_limit = max_operation_size; + btl->btl_put_limit = max_operation_size; btl->btl_put_alignment = operation_alignment; - btl->btl_put = mca_btl_base_am_rdma_put; + btl->btl_put = mca_btl_base_am_rdma_put; } if (!(btl->btl_flags & MCA_BTL_FLAGS_GET)) { - BTL_VERBOSE (("Enabling AM-based RDMA get for BTL %p", btl)); + BTL_VERBOSE(("Enabling AM-based RDMA get for BTL %p", btl)); btl->btl_flags |= MCA_BTL_FLAGS_GET_AM; - btl->btl_get_limit = max_operation_size; + btl->btl_get_limit = max_operation_size; btl->btl_get_alignment = operation_alignment; - btl->btl_get = mca_btl_base_am_rdma_get; + btl->btl_get = mca_btl_base_am_rdma_get; } if (!(btl->btl_flags & MCA_BTL_FLAGS_ATOMIC_FOPS)) { - BTL_VERBOSE (("Enabling AM-based FOPs get for BTL %p", btl)); + BTL_VERBOSE(("Enabling AM-based FOPs get for BTL %p", btl)); btl->btl_flags |= MCA_BTL_FLAGS_ATOMIC_AM_FOP; - btl->btl_atomic_fop = mca_btl_base_am_fop; + btl->btl_atomic_fop = mca_btl_base_am_fop; btl->btl_atomic_cswap = mca_btl_base_am_cswap; /* emulated RDMA atomics can support the full range of atomics. for * now only a handful are supported. */ - btl->btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_GLOB | MCA_BTL_ATOMIC_SUPPORTS_CSWAP | - MCA_BTL_ATOMIC_SUPPORTS_32BIT | MCA_BTL_ATOMIC_SUPPORTS_ADD | - MCA_BTL_ATOMIC_SUPPORTS_AND | MCA_BTL_ATOMIC_SUPPORTS_OR | - MCA_BTL_ATOMIC_SUPPORTS_XOR | MCA_BTL_ATOMIC_SUPPORTS_SWAP | - MCA_BTL_ATOMIC_SUPPORTS_MIN | MCA_BTL_ATOMIC_SUPPORTS_MAX; + btl->btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_GLOB | MCA_BTL_ATOMIC_SUPPORTS_CSWAP + | MCA_BTL_ATOMIC_SUPPORTS_32BIT | MCA_BTL_ATOMIC_SUPPORTS_ADD + | MCA_BTL_ATOMIC_SUPPORTS_AND | MCA_BTL_ATOMIC_SUPPORTS_OR + | MCA_BTL_ATOMIC_SUPPORTS_XOR | MCA_BTL_ATOMIC_SUPPORTS_SWAP + | MCA_BTL_ATOMIC_SUPPORTS_MIN | MCA_BTL_ATOMIC_SUPPORTS_MAX; } if (!progress_registered) { progress_registered = true; - opal_progress_register (mca_btl_base_am_rdma_progress); - mca_btl_sm_sc_emu_init (); - OBJ_CONSTRUCT (&default_module, mca_btl_base_am_rdma_module_t); + opal_progress_register(mca_btl_base_am_rdma_progress); + mca_btl_sm_sc_emu_init(); + OBJ_CONSTRUCT(&default_module, mca_btl_base_am_rdma_module_t); } return OPAL_SUCCESS; diff --git a/opal/mca/btl/base/btl_base_am_rdma.h b/opal/mca/btl/base/btl_base_am_rdma.h index 140f858d488..9842f5a8a49 100644 --- a/opal/mca/btl/base/btl_base_am_rdma.h +++ b/opal/mca/btl/base/btl_base_am_rdma.h @@ -19,11 +19,11 @@ * mca_btl_base_am_rdma_init. */ -#include "opal/mca/btl/btl.h" #include "opal_config.h" +#include "opal/mca/btl/btl.h" #if !defined(OPAL_MCA_BTL_BASE_AM_RDMA_H) -#define OPAL_MCA_BTL_BASE_AM_RDMA_H +# define OPAL_MCA_BTL_BASE_AM_RDMA_H /** * @brief initialize active-message RDMA/atomic support @@ -36,6 +36,6 @@ * support will use either send/recv or get (for put)/put (for get) (if * available). */ -int mca_btl_base_am_rdma_init (mca_btl_base_module_t *btl); +int mca_btl_base_am_rdma_init(mca_btl_base_module_t *btl); #endif /* OPAL_MCA_BTL_BASE_AM_RDMA_H */ diff --git a/opal/mca/btl/base/btl_base_error.c b/opal/mca/btl/base/btl_base_error.c index 3be2a3a8e04..da7363b8b98 100644 --- a/opal/mca/btl/base/btl_base_error.c +++ b/opal/mca/btl/base/btl_base_error.c @@ -21,21 +21,20 @@ * $HEADER$ */ - #include "opal_config.h" -#include #include +#include -#include "opal/util/show_help.h" -#include "opal/util/proc.h" #include "opal/util/printf.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" #include "base.h" #include "btl_base_error.h" int mca_btl_base_verbose = -1; -int mca_btl_base_err(const char* fmt, ...) +int mca_btl_base_err(const char *fmt, ...) { va_list list; int ret; @@ -46,8 +45,7 @@ int mca_btl_base_err(const char* fmt, ...) return ret; } - -int mca_btl_base_out(const char* fmt, ...) +int mca_btl_base_out(const char *fmt, ...) { va_list list; int ret; @@ -58,26 +56,20 @@ int mca_btl_base_out(const char* fmt, ...) return ret; } - -void mca_btl_base_error_no_nics(const char* transport, - const char* nic_name) +void mca_btl_base_error_no_nics(const char *transport, const char *nic_name) { char *procid; if (mca_btl_base_warn_component_unused) { /* print out no-nic warning if user told us to */ opal_asprintf(&procid, "%s", OPAL_NAME_PRINT(OPAL_PROC_MY_NAME)); - opal_show_help("help-mpi-btl-base.txt", "btl:no-nics", - true, procid, transport, opal_process_info.nodename, - nic_name); + opal_show_help("help-mpi-btl-base.txt", "btl:no-nics", true, procid, transport, + opal_process_info.nodename, nic_name); free(procid); } } - -void mca_btl_base_dump( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - int verbose) +void mca_btl_base_dump(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + int verbose) { } diff --git a/opal/mca/btl/base/btl_base_error.h b/opal/mca/btl/base/btl_base_error.h index fcebc6000f4..dac88471f03 100644 --- a/opal/mca/btl/base/btl_base_error.h +++ b/opal/mca/btl/base/btl_base_error.h @@ -22,84 +22,75 @@ */ #ifndef MCA_BTL_BASE_ERROR_H -#define MCA_BTL_BASE_ERROR_H +# define MCA_BTL_BASE_ERROR_H -#include "opal_config.h" +# include "opal_config.h" -#include -#include +# include +# include -#include "opal/util/proc.h" +# include "opal/util/proc.h" OPAL_DECLSPEC extern int mca_btl_base_verbose; OPAL_DECLSPEC extern int mca_btl_base_warn_peer_error; -OPAL_DECLSPEC extern int mca_btl_base_err(const char*, ...) __opal_attribute_format__(__printf__, 1, 2); -OPAL_DECLSPEC extern int mca_btl_base_out(const char*, ...) __opal_attribute_format__(__printf__, 1, 2); - -#define BTL_OUTPUT(args) \ - do { \ - mca_btl_base_out("[%s]%s[%s:%d:%s] ", \ - opal_process_info.nodename, \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, __func__); \ - mca_btl_base_out args; \ - mca_btl_base_out("\n"); \ - } while(0); - - -#define BTL_ERROR(args) \ - do { \ - mca_btl_base_err("[%s]%s[%s:%d:%s] ", \ - opal_process_info.nodename, \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, __func__); \ - mca_btl_base_err args; \ - mca_btl_base_err("\n"); \ - } while(0); - -#define BTL_PEER_ERROR(proc, args) \ - do { \ - if( mca_btl_base_warn_peer_error \ - || mca_btl_base_verbose > 0 ) { /* warn if verbose */ \ - char *errhost; \ - mca_btl_base_err("[%s]%s[%s:%d:%s] ", \ - opal_process_info.nodename, \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, __func__); \ - if (proc) { \ - errhost = opal_get_proc_hostname(proc); \ - mca_btl_base_err("peer: %s ", errhost); \ - free(errhost); \ - } \ - mca_btl_base_err args; \ - mca_btl_base_err("\n"); \ - } \ - } while(0); - - -#if OPAL_ENABLE_DEBUG -#define BTL_VERBOSE(args) \ - do { \ - if(mca_btl_base_verbose > 0) { \ - mca_btl_base_err("[%s]%s[%s:%d:%s] ", \ - opal_process_info.nodename, \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, __func__); \ - mca_btl_base_err args; \ - mca_btl_base_err("\n"); \ - } \ - } while(0); -#else -#define BTL_VERBOSE(args) -#endif +OPAL_DECLSPEC extern int mca_btl_base_err(const char *, ...) + __opal_attribute_format__(__printf__, 1, 2); +OPAL_DECLSPEC extern int mca_btl_base_out(const char *, ...) + __opal_attribute_format__(__printf__, 1, 2); + +# define BTL_OUTPUT(args) \ + do { \ + mca_btl_base_out("[%s]%s[%s:%d:%s] ", opal_process_info.nodename, \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, __func__); \ + mca_btl_base_out args; \ + mca_btl_base_out("\n"); \ + } while (0); + +# define BTL_ERROR(args) \ + do { \ + mca_btl_base_err("[%s]%s[%s:%d:%s] ", opal_process_info.nodename, \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, __func__); \ + mca_btl_base_err args; \ + mca_btl_base_err("\n"); \ + } while (0); + +# define BTL_PEER_ERROR(proc, args) \ + do { \ + if (mca_btl_base_warn_peer_error || mca_btl_base_verbose > 0) { /* warn if verbose */ \ + char *errhost; \ + mca_btl_base_err("[%s]%s[%s:%d:%s] ", opal_process_info.nodename, \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + __func__); \ + if (proc) { \ + errhost = opal_get_proc_hostname(proc); \ + mca_btl_base_err("peer: %s ", errhost); \ + free(errhost); \ + } \ + mca_btl_base_err args; \ + mca_btl_base_err("\n"); \ + } \ + } while (0); + +# if OPAL_ENABLE_DEBUG +# define BTL_VERBOSE(args) \ + do { \ + if (mca_btl_base_verbose > 0) { \ + mca_btl_base_err("[%s]%s[%s:%d:%s] ", opal_process_info.nodename, \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + __func__); \ + mca_btl_base_err args; \ + mca_btl_base_err("\n"); \ + } \ + } while (0); +# else +# define BTL_VERBOSE(args) +# endif #endif - BEGIN_C_DECLS -OPAL_DECLSPEC extern void mca_btl_base_error_no_nics(const char* transport, - const char* nic_name); +OPAL_DECLSPEC extern void mca_btl_base_error_no_nics(const char *transport, const char *nic_name); END_C_DECLS diff --git a/opal/mca/btl/base/btl_base_frame.c b/opal/mca/btl/base/btl_base_frame.c index 7be1c5dcbd3..87abdf42276 100644 --- a/opal/mca/btl/base/btl_base_frame.c +++ b/opal/mca/btl/base/btl_base_frame.c @@ -24,59 +24,56 @@ * $HEADER$ */ - #include "opal_config.h" #include -#include "opal/mca/mca.h" -#include "opal/util/output.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_alias.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" +#include "opal/mca/mca.h" +#include "opal/util/output.h" mca_base_var_enum_flag_t *mca_btl_base_flag_enum = NULL; mca_base_var_enum_flag_t *mca_btl_base_atomic_enum = NULL; -mca_base_var_enum_value_flag_t mca_btl_base_flag_enum_flags[] = { - {MCA_BTL_FLAGS_SEND, "send", 0}, - {MCA_BTL_FLAGS_PUT, "put", MCA_BTL_FLAGS_PUT_AM}, - {MCA_BTL_FLAGS_GET, "get", MCA_BTL_FLAGS_GET_AM}, - {MCA_BTL_FLAGS_SEND_INPLACE, "inplace", 0}, - {MCA_BTL_FLAGS_SIGNALED, "signaled", 0}, - {MCA_BTL_FLAGS_ATOMIC_OPS, "atomics", MCA_BTL_FLAGS_ATOMIC_AM_FOP}, - {MCA_BTL_FLAGS_ATOMIC_FOPS, "fetching-atomics", MCA_BTL_FLAGS_ATOMIC_AM_FOP}, - {MCA_BTL_FLAGS_SINGLE_ADD_PROCS, "static", 0}, - {MCA_BTL_FLAGS_CUDA_PUT, "cuda-put", 0}, - {MCA_BTL_FLAGS_CUDA_GET, "cuda-get", 0}, - {MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND, "cuda-async-send", 0}, - {MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV, "cuda-async-recv", 0}, - {MCA_BTL_FLAGS_FAILOVER_SUPPORT, "failover", 0}, - {MCA_BTL_FLAGS_NEED_ACK, "need-ack", 0}, - {MCA_BTL_FLAGS_NEED_CSUM, "need-csum", 0}, - {MCA_BTL_FLAGS_HETEROGENEOUS_RDMA, "hetero-rdma", 0}, - {MCA_BTL_FLAGS_RDMA_FLUSH, "rdma-flush", 0}, - {MCA_BTL_FLAGS_PUT_AM, "put-am", MCA_BTL_FLAGS_PUT}, - {MCA_BTL_FLAGS_GET_AM, "get_am", MCA_BTL_FLAGS_GET}, - {MCA_BTL_FLAGS_ATOMIC_AM_FOP, "atomic-am", MCA_BTL_FLAGS_ATOMIC_FOPS}, - {0, NULL, 0} -}; - -mca_base_var_enum_value_flag_t mca_btl_base_atomic_enum_flags[] = { - {MCA_BTL_ATOMIC_SUPPORTS_ADD, "add", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_AND, "and", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_OR, "or", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_XOR, "xor", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_LAND, "land", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_LOR, "lor", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_LXOR, "lxor", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_SWAP, "swap", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_MIN, "min", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_MAX, "max", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_CSWAP, "compare-and-swap", 0}, - {MCA_BTL_ATOMIC_SUPPORTS_GLOB, "global"}, - {0, NULL, 0} -}; +mca_base_var_enum_value_flag_t mca_btl_base_flag_enum_flags[] + = {{MCA_BTL_FLAGS_SEND, "send", 0}, + {MCA_BTL_FLAGS_PUT, "put", MCA_BTL_FLAGS_PUT_AM}, + {MCA_BTL_FLAGS_GET, "get", MCA_BTL_FLAGS_GET_AM}, + {MCA_BTL_FLAGS_SEND_INPLACE, "inplace", 0}, + {MCA_BTL_FLAGS_SIGNALED, "signaled", 0}, + {MCA_BTL_FLAGS_ATOMIC_OPS, "atomics", MCA_BTL_FLAGS_ATOMIC_AM_FOP}, + {MCA_BTL_FLAGS_ATOMIC_FOPS, "fetching-atomics", MCA_BTL_FLAGS_ATOMIC_AM_FOP}, + {MCA_BTL_FLAGS_SINGLE_ADD_PROCS, "static", 0}, + {MCA_BTL_FLAGS_CUDA_PUT, "cuda-put", 0}, + {MCA_BTL_FLAGS_CUDA_GET, "cuda-get", 0}, + {MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND, "cuda-async-send", 0}, + {MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV, "cuda-async-recv", 0}, + {MCA_BTL_FLAGS_FAILOVER_SUPPORT, "failover", 0}, + {MCA_BTL_FLAGS_NEED_ACK, "need-ack", 0}, + {MCA_BTL_FLAGS_NEED_CSUM, "need-csum", 0}, + {MCA_BTL_FLAGS_HETEROGENEOUS_RDMA, "hetero-rdma", 0}, + {MCA_BTL_FLAGS_RDMA_FLUSH, "rdma-flush", 0}, + {MCA_BTL_FLAGS_PUT_AM, "put-am", MCA_BTL_FLAGS_PUT}, + {MCA_BTL_FLAGS_GET_AM, "get_am", MCA_BTL_FLAGS_GET}, + {MCA_BTL_FLAGS_ATOMIC_AM_FOP, "atomic-am", MCA_BTL_FLAGS_ATOMIC_FOPS}, + {0, NULL, 0}}; + +mca_base_var_enum_value_flag_t mca_btl_base_atomic_enum_flags[] + = {{MCA_BTL_ATOMIC_SUPPORTS_ADD, "add", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_AND, "and", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_OR, "or", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_XOR, "xor", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_LAND, "land", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_LOR, "lor", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_LXOR, "lxor", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_SWAP, "swap", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_MIN, "min", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_MAX, "max", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_CSWAP, "compare-and-swap", 0}, + {MCA_BTL_ATOMIC_SUPPORTS_GLOB, "global"}, + {0, NULL, 0}}; mca_btl_active_message_callback_t mca_btl_base_active_message_trigger[MCA_BTL_TAG_MAX] = {{0}}; @@ -84,7 +81,7 @@ mca_btl_active_message_callback_t mca_btl_base_active_message_trigger[MCA_BTL_TA * mca_btl_base_descriptor_t */ -static void mca_btl_base_descriptor_constructor(mca_btl_base_descriptor_t* des) +static void mca_btl_base_descriptor_constructor(mca_btl_base_descriptor_t *des) { des->des_segments = NULL; des->des_segment_count = 0; @@ -93,16 +90,12 @@ static void mca_btl_base_descriptor_constructor(mca_btl_base_descriptor_t* des) des->des_flags = 0; } -static void mca_btl_base_descriptor_destructor(mca_btl_base_descriptor_t* des) +static void mca_btl_base_descriptor_destructor(mca_btl_base_descriptor_t *des) { } -OBJ_CLASS_INSTANCE( - mca_btl_base_descriptor_t, - opal_list_item_t, - mca_btl_base_descriptor_constructor, - mca_btl_base_descriptor_destructor); - +OBJ_CLASS_INSTANCE(mca_btl_base_descriptor_t, opal_list_item_t, mca_btl_base_descriptor_constructor, + mca_btl_base_descriptor_destructor); /* * The following file was created by configure. It contains extern @@ -110,14 +103,14 @@ OBJ_CLASS_INSTANCE( * component's public mca_base_component_t struct. */ -#include "opal/mca/btl/base/static-components.h" #include "btl_base_error.h" +#include "opal/mca/btl/base/static-components.h" /* * Global variables */ -char* mca_btl_base_include = NULL; -char* mca_btl_base_exclude = NULL; +char *mca_btl_base_include = NULL; +char *mca_btl_base_exclude = NULL; int mca_btl_base_warn_component_unused = 1; int mca_btl_base_warn_peer_error = true; opal_list_t mca_btl_base_modules_initialized = {{0}}; @@ -128,43 +121,37 @@ static int mca_btl_base_register(mca_base_register_flag_t flags) /* Override the per-BTL "don't run if THREAD_MULTIPLE selected" embargo? */ mca_btl_base_thread_multiple_override = false; - (void) mca_base_var_register("opal", "btl", "base", "thread_multiple_override", - "Enable BTLs that are not normally enabled when MPI_THREAD_MULTIPLE is enabled (THIS IS FOR DEVELOPERS ONLY! SHOULD NOT BE USED BY END USERS!)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, - MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_base_thread_multiple_override); - - (void) mca_base_var_register("opal", "btl", "base", "include", NULL, - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + (void) mca_base_var_register( + "opal", "btl", "base", "thread_multiple_override", + "Enable BTLs that are not normally enabled when MPI_THREAD_MULTIPLE is enabled (THIS IS " + "FOR DEVELOPERS ONLY! SHOULD NOT BE USED BY END USERS!)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_base_thread_multiple_override); + + (void) mca_base_var_register("opal", "btl", "base", "include", NULL, MCA_BASE_VAR_TYPE_STRING, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_base_include); - (void) mca_base_var_register("opal", "btl", "base", "exclude", NULL, - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + (void) mca_base_var_register("opal", "btl", "base", "exclude", NULL, MCA_BASE_VAR_TYPE_STRING, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_base_exclude); - (void) mca_base_var_register("opal", "btl", "base", "warn_peer_error", - "This parameter is used to turn on warning messages when peers disconnect unexpectedly", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_base_warn_peer_error); - (void) mca_base_var_register("opal", "btl", "base", "warn_component_unused", - "This parameter is used to turn on warning messages when certain NICs are not used", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_base_warn_component_unused); - - (void) mca_base_var_enum_create_flag ("btl_flags", mca_btl_base_flag_enum_flags, &mca_btl_base_flag_enum); - (void) mca_base_var_enum_register("opal", "btl", "base", "btl_flags", - &mca_btl_base_flag_enum); - (void) mca_base_var_enum_create_flag ("btl_atomic_flags", mca_btl_base_atomic_enum_flags, &mca_btl_base_atomic_enum); + (void) mca_base_var_register( + "opal", "btl", "base", "warn_peer_error", + "This parameter is used to turn on warning messages when peers disconnect unexpectedly", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_base_warn_peer_error); + (void) mca_base_var_register( + "opal", "btl", "base", "warn_component_unused", + "This parameter is used to turn on warning messages when certain NICs are not used", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_base_warn_component_unused); + + (void) mca_base_var_enum_create_flag("btl_flags", mca_btl_base_flag_enum_flags, + &mca_btl_base_flag_enum); + (void) mca_base_var_enum_register("opal", "btl", "base", "btl_flags", &mca_btl_base_flag_enum); + (void) mca_base_var_enum_create_flag("btl_atomic_flags", mca_btl_base_atomic_enum_flags, + &mca_btl_base_atomic_enum); (void) mca_base_var_enum_register("opal", "btl", "base", "btl_atomic_flags", - &mca_btl_base_atomic_enum); + &mca_btl_base_atomic_enum); /* Note that we break abstraction rules here by listing two specific BTLs here in the base. This is necessary, however, @@ -187,7 +174,7 @@ static int mca_btl_base_register(mca_base_register_flag_t flags) This is why we tolerate this abstraction break up here in the BTL component base. */ - (void) mca_base_alias_register ("opal", "btl", "sm", "vader", MCA_BASE_ALIAS_FLAG_NONE); + (void) mca_base_alias_register("opal", "btl", "sm", "vader", MCA_BASE_ALIAS_FLAG_NONE); return OPAL_SUCCESS; } @@ -202,22 +189,22 @@ static int mca_btl_base_open(mca_base_open_flag_t flags) /* Open up all available components */ - if (OPAL_SUCCESS != - (ret = mca_base_framework_components_open(&opal_btl_base_framework, flags))) { + if (OPAL_SUCCESS + != (ret = mca_base_framework_components_open(&opal_btl_base_framework, flags))) { return ret; } - /* Initialize the list so that in mca_btl_base_close(), we can - iterate over it (even if it's empty, as in the case of - opal_info) */ + /* Initialize the list so that in mca_btl_base_close(), we can + iterate over it (even if it's empty, as in the case of + opal_info) */ - OBJ_CONSTRUCT(&mca_btl_base_modules_initialized, opal_list_t); + OBJ_CONSTRUCT(&mca_btl_base_modules_initialized, opal_list_t); - /* get the verbosity so that BTL_VERBOSE will work */ - mca_btl_base_verbose = opal_output_get_verbosity(opal_btl_base_framework.framework_output); + /* get the verbosity so that BTL_VERBOSE will work */ + mca_btl_base_verbose = opal_output_get_verbosity(opal_btl_base_framework.framework_output); - /* All done */ - return OPAL_SUCCESS; + /* All done */ + return OPAL_SUCCESS; } static int mca_btl_base_close(void) @@ -230,7 +217,8 @@ static int mca_btl_base_close(void) #endif /* Finalize all the btl components and free their list items */ - OPAL_LIST_FOREACH_SAFE(sm, next, &mca_btl_base_modules_initialized, mca_btl_base_selected_module_t) { + OPAL_LIST_FOREACH_SAFE (sm, next, &mca_btl_base_modules_initialized, + mca_btl_base_selected_module_t) { /* Blatently ignore the return code (what would we do to recover, anyway? This component is going away, so errors don't matter anymore) */ diff --git a/opal/mca/btl/base/btl_base_mca.c b/opal/mca/btl/base/btl_base_mca.c index c65c0a3b5c2..8e7bc0afb9c 100644 --- a/opal/mca/btl/base/btl_base_mca.c +++ b/opal/mca/btl/base/btl_base_mca.c @@ -28,138 +28,160 @@ #include -#include "opal/util/output.h" #include "opal/constants.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" +#include "opal/util/output.h" -int mca_btl_base_param_register(mca_base_component_t *version, - mca_btl_base_module_t *module) +int mca_btl_base_param_register(mca_base_component_t *version, mca_btl_base_module_t *module) { /* If this is ever triggered change the uint32_ts in mca_btl_base_module_t to unsigned ints */ assert(sizeof(unsigned int) == sizeof(uint32_t)); - (void) mca_base_component_var_register(version, "exclusivity", - "BTL exclusivity (must be >= 0)", + (void) mca_base_component_var_register(version, "exclusivity", "BTL exclusivity (must be >= 0)", MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, - OPAL_INFO_LVL_7, - MCA_BASE_VAR_SCOPE_READONLY, + OPAL_INFO_LVL_7, MCA_BASE_VAR_SCOPE_READONLY, &module->btl_exclusivity); - (void) mca_base_component_var_register(version, "flags", "BTL bit flags (general flags: send, put, get, in-place, hetero-rdma, " - "atomics, fetching-atomics)", MCA_BASE_VAR_TYPE_UNSIGNED_INT, - &mca_btl_base_flag_enum->super, 0, 0, OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, &module->btl_flags); - - (void) mca_base_component_var_register(version, "atomic_flags", "BTL atomic support flags", MCA_BASE_VAR_TYPE_UNSIGNED_INT, - &mca_btl_base_atomic_enum->super, 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY, OPAL_INFO_LVL_5, + (void) mca_base_component_var_register( + version, "flags", + "BTL bit flags (general flags: send, put, get, in-place, hetero-rdma, " + "atomics, fetching-atomics)", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, &mca_btl_base_flag_enum->super, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, &module->btl_flags); + + (void) mca_base_component_var_register(version, "atomic_flags", "BTL atomic support flags", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, + &mca_btl_base_atomic_enum->super, 0, + MCA_BASE_VAR_FLAG_DEFAULT_ONLY, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_CONSTANT, &module->btl_atomic_flags); - (void) mca_base_component_var_register(version, "rndv_eager_limit", "Size (in bytes, including header) of \"phase 1\" fragment sent for all large messages (must be >= 0 and <= eager_limit)", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_rndv_eager_limit); + (void) mca_base_component_var_register( + version, "rndv_eager_limit", + "Size (in bytes, including header) of \"phase 1\" fragment sent for all large messages " + "(must be >= 0 and <= eager_limit)", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_rndv_eager_limit); - (void) mca_base_component_var_register(version, "eager_limit", "Maximum size (in bytes, including header) of \"short\" messages (must be >= 1).", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_eager_limit); + (void) mca_base_component_var_register( + version, "eager_limit", + "Maximum size (in bytes, including header) of \"short\" messages (must be >= 1).", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_eager_limit); if ((module->btl_flags & MCA_BTL_FLAGS_GET) && module->btl_get) { - if (0 == module->btl_get_limit) { - module->btl_get_limit = SIZE_MAX; - } - - (void) mca_base_component_var_register(version, "get_limit", "Maximum size (in bytes) for btl get", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, &module->btl_get_limit); - - /* Allow the user to set the alignment. The BTL should double-check the alignment in its open - * function. */ - (void) mca_base_component_var_register(version, "get_alignment", "Alignment required for btl get", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_6, - MCA_BASE_VAR_SCOPE_CONSTANT, &module->btl_get_alignment); + if (0 == module->btl_get_limit) { + module->btl_get_limit = SIZE_MAX; + } + + (void) mca_base_component_var_register(version, "get_limit", + "Maximum size (in bytes) for btl get", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, + OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_get_limit); + + /* Allow the user to set the alignment. The BTL should double-check the alignment in its + * open function. */ + (void) mca_base_component_var_register(version, "get_alignment", + "Alignment required for btl get", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, + OPAL_INFO_LVL_6, MCA_BASE_VAR_SCOPE_CONSTANT, + &module->btl_get_alignment); } if ((module->btl_flags & MCA_BTL_FLAGS_PUT) && module->btl_put) { - if (0 == module->btl_put_limit) { - module->btl_put_limit = SIZE_MAX; - } - (void) mca_base_component_var_register(version, "put_limit", "Maximum size (in bytes) for btl put", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, &module->btl_put_limit); - - /* Allow the user to set the alignment. The BTL should double-check the alignment in its open - * function. */ - (void) mca_base_component_var_register(version, "put_alignment", "Alignment required for btl put", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_6, - MCA_BASE_VAR_SCOPE_CONSTANT, &module->btl_put_alignment); + if (0 == module->btl_put_limit) { + module->btl_put_limit = SIZE_MAX; + } + (void) mca_base_component_var_register(version, "put_limit", + "Maximum size (in bytes) for btl put", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, + OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_put_limit); + + /* Allow the user to set the alignment. The BTL should double-check the alignment in its + * open function. */ + (void) mca_base_component_var_register(version, "put_alignment", + "Alignment required for btl put", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, + OPAL_INFO_LVL_6, MCA_BASE_VAR_SCOPE_CONSTANT, + &module->btl_put_alignment); } - #if OPAL_CUDA_GDR_SUPPORT /* If no CUDA RDMA support, zero them out */ if (!(MCA_BTL_FLAGS_CUDA_GET & module->btl_flags)) { module->btl_cuda_eager_limit = 0; module->btl_cuda_rdma_limit = SIZE_MAX; } - (void) mca_base_component_var_register(version, "cuda_eager_limit", "Maximum size (in bytes, including header) of \"GPU short\" messages (must be >= 1).", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_cuda_eager_limit); - (void) mca_base_component_var_register(version, "cuda_rdma_limit", "Size (in bytes, including header) of GPU buffer when switch to rndv protocol and pipeline.", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_5, + (void) mca_base_component_var_register( + version, "cuda_eager_limit", + "Maximum size (in bytes, including header) of \"GPU short\" messages (must be >= 1).", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_cuda_eager_limit); + (void) mca_base_component_var_register(version, "cuda_rdma_limit", + "Size (in bytes, including header) of GPU buffer when " + "switch to rndv protocol and pipeline.", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, &module->btl_cuda_rdma_limit); #endif /* OPAL_CUDA_GDR_SUPPORT */ #if OPAL_CUDA_SUPPORT module->btl_cuda_max_send_size = 0; - (void) mca_base_component_var_register(version, "cuda_max_send_size", "Maximum size (in bytes) of a single GPU \"phase 2\" fragment of a long message when using the pipeline protocol (must be >= 1) (only valid on smcuda btl)", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_cuda_max_send_size); + (void) mca_base_component_var_register( + version, "cuda_max_send_size", + "Maximum size (in bytes) of a single GPU \"phase 2\" fragment of a long message when using " + "the pipeline protocol (must be >= 1) (only valid on smcuda btl)", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_cuda_max_send_size); #endif /* OPAL_CUDA_SUPPORT */ - (void) mca_base_component_var_register(version, "max_send_size", "Maximum size (in bytes) of a single \"phase 2\" fragment of a long message when using the pipeline protocol (must be >= 1)", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_max_send_size); + (void) mca_base_component_var_register( + version, "max_send_size", + "Maximum size (in bytes) of a single \"phase 2\" fragment of a long message when using the " + "pipeline protocol (must be >= 1)", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_max_send_size); if (NULL != module->btl_put) { - (void) mca_base_component_var_register(version, "rdma_pipeline_send_length", "Length of the \"phase 2\" portion of a large message (in bytes) when using the pipeline protocol. This part of the message will be split into fragments of size max_send_size and sent using send/receive semantics (must be >= 0; only relevant when the PUT flag is set)", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_rdma_pipeline_send_length); - - (void) mca_base_component_var_register(version, "rdma_pipeline_frag_size", "Maximum size (in bytes) of a single \"phase 3\" fragment from a long message when using the pipeline protocol. These fragments will be sent using RDMA semantics (must be >= 1; only relevant when the PUT flag is set)", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_rdma_pipeline_frag_size); - - (void) mca_base_component_var_register(version, "min_rdma_pipeline_size", "Messages smaller than this size (in bytes) will not use the RDMA pipeline protocol. Instead, they will be split into fragments of max_send_size and sent using send/receive semantics (must be >=0, and is automatically adjusted up to at least (eager_limit+btl_rdma_pipeline_send_length); only relevant when the PUT flag is set)", - MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, - OPAL_INFO_LVL_4, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_min_rdma_pipeline_size); - - (void) mca_base_component_var_register(version, "latency", "Approximate latency of interconnect (0 = auto-detect value at run-time [not supported in all BTL modules], >= 1 = latency in microseconds)", - MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_latency); - (void) mca_base_component_var_register(version, "bandwidth", "Approximate maximum bandwidth of interconnect (0 = auto-detect value at run-time [not supported in all BTL modules], >= 1 = bandwidth in Mbps)", - MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &module->btl_bandwidth); + (void) mca_base_component_var_register( + version, "rdma_pipeline_send_length", + "Length of the \"phase 2\" portion of a large message (in bytes) when using the " + "pipeline protocol. This part of the message will be split into fragments of size " + "max_send_size and sent using send/receive semantics (must be >= 0; only relevant when " + "the PUT flag is set)", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_rdma_pipeline_send_length); + + (void) mca_base_component_var_register( + version, "rdma_pipeline_frag_size", + "Maximum size (in bytes) of a single \"phase 3\" fragment from a long message when " + "using the pipeline protocol. These fragments will be sent using RDMA semantics (must " + "be >= 1; only relevant when the PUT flag is set)", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_rdma_pipeline_frag_size); + + (void) mca_base_component_var_register( + version, "min_rdma_pipeline_size", + "Messages smaller than this size (in bytes) will not use the RDMA pipeline protocol. " + "Instead, they will be split into fragments of max_send_size and sent using " + "send/receive semantics (must be >=0, and is automatically adjusted up to at least " + "(eager_limit+btl_rdma_pipeline_send_length); only relevant when the PUT flag is set)", + MCA_BASE_VAR_TYPE_SIZE_T, NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY, + &module->btl_min_rdma_pipeline_size); + + (void) mca_base_component_var_register( + version, "latency", + "Approximate latency of interconnect (0 = auto-detect value at run-time [not supported " + "in all BTL modules], >= 1 = latency in microseconds)", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, &module->btl_latency); + (void) mca_base_component_var_register( + version, "bandwidth", + "Approximate maximum bandwidth of interconnect (0 = auto-detect value at run-time [not " + "supported in all BTL modules], >= 1 = bandwidth in Mbps)", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, &module->btl_bandwidth); } return mca_btl_base_param_verify(module); @@ -168,10 +190,10 @@ int mca_btl_base_param_register(mca_base_component_t *version, /* Verify btl parameters make sense */ int mca_btl_base_param_verify(mca_btl_base_module_t *module) { - if (module->btl_min_rdma_pipeline_size < - (module->btl_eager_limit + module->btl_rdma_pipeline_send_length)) { - module->btl_min_rdma_pipeline_size = - module->btl_eager_limit + module->btl_rdma_pipeline_send_length; + if (module->btl_min_rdma_pipeline_size + < (module->btl_eager_limit + module->btl_rdma_pipeline_send_length)) { + module->btl_min_rdma_pipeline_size = module->btl_eager_limit + + module->btl_rdma_pipeline_send_length; } if (NULL == module->btl_put) { @@ -191,11 +213,11 @@ int mca_btl_base_param_verify(mca_btl_base_module_t *module) } if (0 == module->btl_get_limit) { - module->btl_get_limit = SIZE_MAX; + module->btl_get_limit = SIZE_MAX; } if (0 == module->btl_put_limit) { - module->btl_put_limit = SIZE_MAX; + module->btl_put_limit = SIZE_MAX; } return OPAL_SUCCESS; diff --git a/opal/mca/btl/base/btl_base_select.c b/opal/mca/btl/base/btl_base_select.c index 642901fecdb..028655f0011 100644 --- a/opal/mca/btl/base/btl_base_select.c +++ b/opal/mca/btl/base/btl_base_select.c @@ -25,21 +25,18 @@ #include "opal_config.h" -#include "opal/util/argv.h" -#include "opal/util/output.h" -#include "opal/util/show_help.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_component_repository.h" -#include "opal/runtime/opal.h" -#include "opal/mca/btl/btl.h" -#include "opal/mca/btl/base/btl_base_error.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" +#include "opal/mca/mca.h" +#include "opal/runtime/opal.h" +#include "opal/util/argv.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" -OBJ_CLASS_INSTANCE( mca_btl_base_selected_module_t, - opal_list_item_t, - NULL, - NULL ); +OBJ_CLASS_INSTANCE(mca_btl_base_selected_module_t, opal_list_item_t, NULL, NULL); /** * Function for weeding out btl components that don't want to run. @@ -49,8 +46,7 @@ OBJ_CLASS_INSTANCE( mca_btl_base_selected_module_t, * components will be closed and unloaded. The selected modules will * be returned to the caller in a opal_list_t. */ -int mca_btl_base_select(bool enable_progress_threads, - bool enable_mpi_threads) +int mca_btl_base_select(bool enable_progress_threads, bool enable_mpi_threads) { int i, num_btls; mca_base_component_list_item_t *cli, *next; @@ -58,42 +54,44 @@ int mca_btl_base_select(bool enable_progress_threads, mca_btl_base_module_t **modules; mca_btl_base_selected_module_t *sm; - char** include = opal_argv_split(mca_btl_base_include, ','); - char** exclude = opal_argv_split(mca_btl_base_exclude, ','); + char **include = opal_argv_split(mca_btl_base_include, ','); + char **exclude = opal_argv_split(mca_btl_base_exclude, ','); /* Traverse the list of opened modules; call their init functions. */ - OPAL_LIST_FOREACH_SAFE(cli, next, &opal_btl_base_framework.framework_components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH_SAFE (cli, next, &opal_btl_base_framework.framework_components, + mca_base_component_list_item_t) { component = (mca_btl_base_component_t *) cli->cli_component; /* if there is an include list - item must be in the list to be included */ - if ( NULL != include ) { - char** argv = include; + if (NULL != include) { + char **argv = include; bool found = false; - while(argv && *argv) { - if(strcmp(component->btl_version.mca_component_name,*argv) == 0) { + while (argv && *argv) { + if (strcmp(component->btl_version.mca_component_name, *argv) == 0) { found = true; break; } argv++; } - if(found == false) { + if (found == false) { continue; } - /* otherwise - check the exclude list to see if this item has been specifically excluded */ - } else if ( NULL != exclude ) { - char** argv = exclude; + /* otherwise - check the exclude list to see if this item has been specifically excluded + */ + } else if (NULL != exclude) { + char **argv = exclude; bool found = false; - while(argv && *argv) { - if(strcmp(component->btl_version.mca_component_name,*argv) == 0) { + while (argv && *argv) { + if (strcmp(component->btl_version.mca_component_name, *argv) == 0) { found = true; break; } argv++; } - if(found == true) { + if (found == true) { continue; } } @@ -107,8 +105,7 @@ int mca_btl_base_select(bool enable_progress_threads, "select: no init function; ignoring component %s", component->btl_version.mca_component_name); } else { - modules = component->btl_init(&num_btls, enable_progress_threads, - enable_mpi_threads); + modules = component->btl_init(&num_btls, enable_progress_threads, enable_mpi_threads); /* If the component didn't initialize, remove it from the opened list and remove it from the component repository */ @@ -134,8 +131,10 @@ int mca_btl_base_select(bool enable_progress_threads, for (i = 0; i < num_btls; ++i) { /* If modules[i] is NULL, it's a developer error */ if (NULL == modules[i]) { - BTL_ERROR(("BTL module init of %s returned a NULL -- this should never happen, and is a developer error. Contact the Open MPI developers.", - component->btl_version.mca_component_name)); + BTL_ERROR( + ("BTL module init of %s returned a NULL -- this should never happen, " + "and is a developer error. Contact the Open MPI developers.", + component->btl_version.mca_component_name)); exit(1); } sm = OBJ_NEW(mca_btl_base_selected_module_t); @@ -150,8 +149,7 @@ int mca_btl_base_select(bool enable_progress_threads, } sm->btl_component = component; sm->btl_module = modules[i]; - opal_list_append(&mca_btl_base_modules_initialized, - (opal_list_item_t*) sm); + opal_list_append(&mca_btl_base_modules_initialized, (opal_list_item_t *) sm); } free(modules); } @@ -168,11 +166,8 @@ int mca_btl_base_select(bool enable_progress_threads, /* Finished querying all components. Check for the bozo case. */ if (0 == opal_list_get_size(&mca_btl_base_modules_initialized)) { - opal_show_help("help-mca-base.txt", "find-available:none found", - true, - "btl", - opal_process_info.nodename, - "btl"); + opal_show_help("help-mca-base.txt", "find-available:none found", true, "btl", + opal_process_info.nodename, "btl"); return OPAL_ERROR; } return OPAL_SUCCESS; diff --git a/opal/mca/btl/btl.h b/opal/mca/btl/btl.h index d86ab6b10f1..0fe8f806f5f 100644 --- a/opal/mca/btl/btl.h +++ b/opal/mca/btl/btl.h @@ -118,13 +118,13 @@ #define OPAL_MCA_BTL_H #include "opal_config.h" -#include "opal/types.h" -#include "opal/prefetch.h" /* For OPAL_LIKELY */ #include "opal/class/opal_bitmap.h" #include "opal/datatype/opal_convertor.h" #include "opal/mca/mca.h" #include "opal/mca/mpool/mpool.h" #include "opal/mca/rcache/rcache.h" +#include "opal/prefetch.h" /* For OPAL_LIKELY */ +#include "opal/types.h" BEGIN_C_DECLS @@ -152,14 +152,13 @@ struct opal_proc_t; struct mca_btl_base_registration_handle_t; typedef struct mca_btl_base_registration_handle_t mca_btl_base_registration_handle_t; - /* Wildcard endpoint for use in the register_mem function */ #define MCA_BTL_ENDPOINT_ANY (struct mca_btl_base_endpoint_t *) -1 /* send/recv operations require tag matching */ typedef uint8_t mca_btl_base_tag_t; -#define MCA_BTL_NO_ORDER 255 +#define MCA_BTL_NO_ORDER 255 /* * Communication specific defines. There are a number of active message ID @@ -175,58 +174,58 @@ typedef uint8_t mca_btl_base_tag_t; * information about how these framework ID are defined, take a look in the * header file associated with the framework. */ -#define MCA_BTL_AM_FRAMEWORK_MASK 0xD0 -#define MCA_BTL_TAG_BTL_BASE 0x10 -#define MCA_BTL_TAG_BTL 0x20 +#define MCA_BTL_AM_FRAMEWORK_MASK 0xD0 +#define MCA_BTL_TAG_BTL_BASE 0x10 +#define MCA_BTL_TAG_BTL 0x20 #if OPAL_ENABLE_FT_MPI -#define MCA_BTL_TAG_FT_RBCAST 0x30 -#define MCA_BTL_TAG_FT_AGREE 0x31 +# define MCA_BTL_TAG_FT_RBCAST 0x30 +# define MCA_BTL_TAG_FT_AGREE 0x31 #endif -#define MCA_BTL_TAG_PML 0x40 -#define MCA_BTL_TAG_OSC_RDMA 0x60 -#define MCA_BTL_TAG_USR 0x80 -#define MCA_BTL_TAG_MAX 255 /* 1 + highest allowed tag num */ +#define MCA_BTL_TAG_PML 0x40 +#define MCA_BTL_TAG_OSC_RDMA 0x60 +#define MCA_BTL_TAG_USR 0x80 +#define MCA_BTL_TAG_MAX 255 /* 1 + highest allowed tag num */ /* * Reserved tags for specific BTLs. As multiple BTLs can be active * simultaneously, their tags should not collide. */ -#define MCA_BTL_TAG_IB (MCA_BTL_TAG_BTL + 0) -#define MCA_BTL_TAG_UDAPL (MCA_BTL_TAG_BTL + 1) -#define MCA_BTL_TAG_SMCUDA (MCA_BTL_TAG_BTL + 2) -#define MCA_BTL_TAG_SM (MCA_BTL_TAG_BTL + 3) +#define MCA_BTL_TAG_IB (MCA_BTL_TAG_BTL + 0) +#define MCA_BTL_TAG_UDAPL (MCA_BTL_TAG_BTL + 1) +#define MCA_BTL_TAG_SMCUDA (MCA_BTL_TAG_BTL + 2) +#define MCA_BTL_TAG_SM (MCA_BTL_TAG_BTL + 3) /* prefered protocol */ -#define MCA_BTL_FLAGS_SEND 0x0001 -#define MCA_BTL_FLAGS_PUT 0x0002 -#define MCA_BTL_FLAGS_GET 0x0004 +#define MCA_BTL_FLAGS_SEND 0x0001 +#define MCA_BTL_FLAGS_PUT 0x0002 +#define MCA_BTL_FLAGS_GET 0x0004 /* btls that set the MCA_BTL_FLAGS_RDMA will always get added to the BML * rdma_btls list. This allows the updated one-sided component to * use btls that are not otherwise used for send/recv. */ -#define MCA_BTL_FLAGS_RDMA (MCA_BTL_FLAGS_GET|MCA_BTL_FLAGS_PUT) +#define MCA_BTL_FLAGS_RDMA (MCA_BTL_FLAGS_GET | MCA_BTL_FLAGS_PUT) /* btl can send directly from user buffer w/out registration */ -#define MCA_BTL_FLAGS_SEND_INPLACE 0x0008 +#define MCA_BTL_FLAGS_SEND_INPLACE 0x0008 /* btl transport reliability flags - currently used only by the DR PML */ -#define MCA_BTL_FLAGS_NEED_ACK 0x0010 -#define MCA_BTL_FLAGS_NEED_CSUM 0x0020 +#define MCA_BTL_FLAGS_NEED_ACK 0x0010 +#define MCA_BTL_FLAGS_NEED_CSUM 0x0020 /** deprecated (BTL 3.0) */ -#define MCA_BTL_FLAGS_RDMA_MATCHED 0x0040 +#define MCA_BTL_FLAGS_RDMA_MATCHED 0x0040 /* btl needs local rdma completion */ #define MCA_BTL_FLAGS_RDMA_COMPLETION 0x0080 - /* btl can do heterogeneous rdma operations on byte buffers */ +/* btl can do heterogeneous rdma operations on byte buffers */ #define MCA_BTL_FLAGS_HETEROGENEOUS_RDMA 0x0100 /* btl can support failover if enabled */ #define MCA_BTL_FLAGS_FAILOVER_SUPPORT 0x0200 -#define MCA_BTL_FLAGS_CUDA_PUT 0x0400 -#define MCA_BTL_FLAGS_CUDA_GET 0x0800 -#define MCA_BTL_FLAGS_CUDA_RDMA (MCA_BTL_FLAGS_CUDA_GET|MCA_BTL_FLAGS_CUDA_PUT) +#define MCA_BTL_FLAGS_CUDA_PUT 0x0400 +#define MCA_BTL_FLAGS_CUDA_GET 0x0800 +#define MCA_BTL_FLAGS_CUDA_RDMA (MCA_BTL_FLAGS_CUDA_GET | MCA_BTL_FLAGS_CUDA_PUT) #define MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND 0x1000 #define MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV 0x2000 @@ -236,12 +235,12 @@ typedef uint8_t mca_btl_base_tag_t; * (and probably will) turn this flag on and off using the MCA variable * system. */ -#define MCA_BTL_FLAGS_SIGNALED 0x4000 +#define MCA_BTL_FLAGS_SIGNALED 0x4000 /** The BTL supports network atomic operations */ -#define MCA_BTL_FLAGS_ATOMIC_OPS 0x08000 +#define MCA_BTL_FLAGS_ATOMIC_OPS 0x08000 /** The BTL supports fetching network atomic operations */ -#define MCA_BTL_FLAGS_ATOMIC_FOPS 0x10000 +#define MCA_BTL_FLAGS_ATOMIC_FOPS 0x10000 /** The BTL requires add_procs to be with all procs including non-local. Shared-memory * BTLs should not set this flag. */ @@ -251,25 +250,25 @@ typedef uint8_t mca_btl_base_tag_t; #define MCA_BTL_FLAGS_BTL_PROGRESS_THREAD_ENABLED 0x40000 /* The BTL supports RMDA flush */ -#define MCA_BTL_FLAGS_RDMA_FLUSH 0x80000 +#define MCA_BTL_FLAGS_RDMA_FLUSH 0x80000 /* The BTL has an active-message based put */ -#define MCA_BTL_FLAGS_PUT_AM 0x100000 +#define MCA_BTL_FLAGS_PUT_AM 0x100000 /* The BTL has an active-message based get */ -#define MCA_BTL_FLAGS_GET_AM 0x200000 +#define MCA_BTL_FLAGS_GET_AM 0x200000 /* The BTL has active-message based atomics */ -#define MCA_BTL_FLAGS_ATOMIC_AM_FOP 0x400000 +#define MCA_BTL_FLAGS_ATOMIC_AM_FOP 0x400000 /* Default exclusivity levels */ -#define MCA_BTL_EXCLUSIVITY_HIGH (64*1024) /* internal loopback */ -#define MCA_BTL_EXCLUSIVITY_DEFAULT 1024 /* GM/IB/etc. */ -#define MCA_BTL_EXCLUSIVITY_LOW 0 /* TCP used as a last resort */ +#define MCA_BTL_EXCLUSIVITY_HIGH (64 * 1024) /* internal loopback */ +#define MCA_BTL_EXCLUSIVITY_DEFAULT 1024 /* GM/IB/etc. */ +#define MCA_BTL_EXCLUSIVITY_LOW 0 /* TCP used as a last resort */ /* error callback flags */ -#define MCA_BTL_ERROR_FLAGS_FATAL 0x1 -#define MCA_BTL_ERROR_FLAGS_NONFATAL 0x2 +#define MCA_BTL_ERROR_FLAGS_FATAL 0x1 +#define MCA_BTL_ERROR_FLAGS_NONFATAL 0x2 #define MCA_BTL_ERROR_FLAGS_ADD_CUDA_IPC 0x4 /** registration flags. the access flags are a 1-1 mapping with the mpool @@ -278,15 +277,15 @@ enum { /** Allow local write on the registered region. If a region is registered * with this flag the registration can be used as the local handle for a * btl_get operation. */ - MCA_BTL_REG_FLAG_LOCAL_WRITE = MCA_RCACHE_ACCESS_LOCAL_WRITE, + MCA_BTL_REG_FLAG_LOCAL_WRITE = MCA_RCACHE_ACCESS_LOCAL_WRITE, /** Allow remote read on the registered region. If a region is registered * with this flag the registration can be used as the remote handle for a * btl_get operation. */ - MCA_BTL_REG_FLAG_REMOTE_READ = MCA_RCACHE_ACCESS_REMOTE_READ, + MCA_BTL_REG_FLAG_REMOTE_READ = MCA_RCACHE_ACCESS_REMOTE_READ, /** Allow remote write on the registered region. If a region is registered * with this flag the registration can be used as the remote handle for a * btl_put operation. */ - MCA_BTL_REG_FLAG_REMOTE_WRITE = MCA_RCACHE_ACCESS_REMOTE_WRITE, + MCA_BTL_REG_FLAG_REMOTE_WRITE = MCA_RCACHE_ACCESS_REMOTE_WRITE, /** Allow remote atomic operations on the registered region. If a region is * registered with this flag the registration can be used as the remote * handle for a btl_atomic_op or btl_atomic_fop operation. */ @@ -294,53 +293,53 @@ enum { /** Allow any btl operation on the registered region. If a region is registered * with this flag the registration can be used as the local or remote handle for * any btl operation. */ - MCA_BTL_REG_FLAG_ACCESS_ANY = MCA_RCACHE_ACCESS_ANY, + MCA_BTL_REG_FLAG_ACCESS_ANY = MCA_RCACHE_ACCESS_ANY, #if OPAL_CUDA_GDR_SUPPORT /** Region is in GPU memory */ - MCA_BTL_REG_FLAG_CUDA_GPU_MEM = 0x00010000, + MCA_BTL_REG_FLAG_CUDA_GPU_MEM = 0x00010000, #endif }; /** supported atomic operations */ enum { /** The btl supports atomic add */ - MCA_BTL_ATOMIC_SUPPORTS_ADD = 0x00000001, + MCA_BTL_ATOMIC_SUPPORTS_ADD = 0x00000001, /** The btl supports atomic bitwise and */ - MCA_BTL_ATOMIC_SUPPORTS_AND = 0x00000200, + MCA_BTL_ATOMIC_SUPPORTS_AND = 0x00000200, /** The btl supports atomic bitwise or */ - MCA_BTL_ATOMIC_SUPPORTS_OR = 0x00000400, + MCA_BTL_ATOMIC_SUPPORTS_OR = 0x00000400, /** The btl supports atomic bitwise exclusive or */ - MCA_BTL_ATOMIC_SUPPORTS_XOR = 0x00000800, + MCA_BTL_ATOMIC_SUPPORTS_XOR = 0x00000800, /** The btl supports logical and */ - MCA_BTL_ATOMIC_SUPPORTS_LAND = 0x00001000, + MCA_BTL_ATOMIC_SUPPORTS_LAND = 0x00001000, /** The btl supports logical or */ - MCA_BTL_ATOMIC_SUPPORTS_LOR = 0x00002000, + MCA_BTL_ATOMIC_SUPPORTS_LOR = 0x00002000, /** The btl supports logical exclusive or */ - MCA_BTL_ATOMIC_SUPPORTS_LXOR = 0x00004000, + MCA_BTL_ATOMIC_SUPPORTS_LXOR = 0x00004000, /** The btl supports atomic swap */ - MCA_BTL_ATOMIC_SUPPORTS_SWAP = 0x00010000, + MCA_BTL_ATOMIC_SUPPORTS_SWAP = 0x00010000, /** The btl supports atomic min */ - MCA_BTL_ATOMIC_SUPPORTS_MIN = 0x00100000, + MCA_BTL_ATOMIC_SUPPORTS_MIN = 0x00100000, /** The btl supports atomic min */ - MCA_BTL_ATOMIC_SUPPORTS_MAX = 0x00200000, + MCA_BTL_ATOMIC_SUPPORTS_MAX = 0x00200000, /** The btl supports 32-bit integer operations. Keep in mind the btl may * support only a subset of the available atomics. */ - MCA_BTL_ATOMIC_SUPPORTS_32BIT = 0x01000000, + MCA_BTL_ATOMIC_SUPPORTS_32BIT = 0x01000000, /** The btl supports floating-point operations. Keep in mind the btl may * support only a subset of the available atomics and may not support * both 64 or 32-bit floating point. */ - MCA_BTL_ATOMIC_SUPPORTS_FLOAT = 0x02000000, + MCA_BTL_ATOMIC_SUPPORTS_FLOAT = 0x02000000, /** The btl supports atomic compare-and-swap */ - MCA_BTL_ATOMIC_SUPPORTS_CSWAP = 0x10000000, + MCA_BTL_ATOMIC_SUPPORTS_CSWAP = 0x10000000, /** The btl guarantees global atomicity (can mix btl atomics with cpu atomics) */ - MCA_BTL_ATOMIC_SUPPORTS_GLOB = 0x20000000, + MCA_BTL_ATOMIC_SUPPORTS_GLOB = 0x20000000, }; enum { @@ -356,7 +355,7 @@ enum mca_btl_base_atomic_op_t { /** Atomic and: (*remote_address) = (*remote_address) & operand */ MCA_BTL_ATOMIC_AND = 0x0011, /** Atomic or: (*remote_address) = (*remote_address) | operand */ - MCA_BTL_ATOMIC_OR = 0x0012, + MCA_BTL_ATOMIC_OR = 0x0012, /** Atomic xor: (*remote_address) = (*remote_address) ^ operand */ MCA_BTL_ATOMIC_XOR = 0x0014, /** Atomic logical and: (*remote_address) = (*remote_address) && operand */ @@ -388,12 +387,10 @@ typedef enum mca_btl_base_atomic_op_t mca_btl_base_atomic_op_t; * @param[IN] descriptor the BTL descriptor * */ -typedef void (*mca_btl_base_completion_fn_t)( - struct mca_btl_base_module_t* module, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - int status); - +typedef void (*mca_btl_base_completion_fn_t)(struct mca_btl_base_module_t *module, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, + int status); /** * Asynchronous callback function on completion of an rdma or atomic operation. @@ -411,14 +408,9 @@ typedef void (*mca_btl_base_completion_fn_t)( * */ typedef void (*mca_btl_base_rdma_completion_fn_t)( - struct mca_btl_base_module_t* module, - struct mca_btl_base_endpoint_t* endpoint, - void *local_address, - struct mca_btl_base_registration_handle_t *local_handle, - void *context, - void *cbdata, - int status); - + struct mca_btl_base_module_t *module, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, struct mca_btl_base_registration_handle_t *local_handle, void *context, + void *cbdata, int status); /** * Describes a region/segment of memory that is addressable @@ -440,26 +432,25 @@ typedef void (*mca_btl_base_rdma_completion_fn_t)( struct mca_btl_base_segment_t { /** Address of the memory */ opal_ptr_t seg_addr; - /** Length in bytes */ - uint64_t seg_len; + /** Length in bytes */ + uint64_t seg_len; }; typedef struct mca_btl_base_segment_t mca_btl_base_segment_t; - #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT && !defined(WORDS_BIGENDIAN) -#define MCA_BTL_BASE_SEGMENT_HTON(s) \ - do { \ - (s).seg_addr.lval = hton64((s).seg_addr.lval); \ - (s).seg_len = hton64((s).seg_len); \ - } while(0) -#define MCA_BTL_BASE_SEGMENT_NTOH(s) \ - do { \ - (s).seg_addr.lval = ntoh64((s).seg_addr.lval); \ - (s).seg_len = ntoh64((s).seg_len); \ - } while(0) +# define MCA_BTL_BASE_SEGMENT_HTON(s) \ + do { \ + (s).seg_addr.lval = hton64((s).seg_addr.lval); \ + (s).seg_len = hton64((s).seg_len); \ + } while (0) +# define MCA_BTL_BASE_SEGMENT_NTOH(s) \ + do { \ + (s).seg_addr.lval = ntoh64((s).seg_addr.lval); \ + (s).seg_len = ntoh64((s).seg_len); \ + } while (0) #else -#define MCA_BTL_BASE_SEGMENT_HTON(s) -#define MCA_BTL_BASE_SEGMENT_NTOH(s) +# define MCA_BTL_BASE_SEGMENT_HTON(s) +# define MCA_BTL_BASE_SEGMENT_NTOH(s) #endif /** * @brief Descriptor to hold outgoing send messages @@ -470,12 +461,12 @@ typedef struct mca_btl_base_segment_t mca_btl_base_segment_t; */ struct mca_btl_base_descriptor_t { opal_free_list_item_t super; - mca_btl_base_segment_t *des_segments; /**< local segments */ - size_t des_segment_count; /**< number of local segments */ - mca_btl_base_completion_fn_t des_cbfunc; /**< local callback function */ - void* des_cbdata; /**< opaque callback data */ - void* des_context; /**< more opaque callback data */ - uint32_t des_flags; /**< hints to BTL */ + mca_btl_base_segment_t *des_segments; /**< local segments */ + size_t des_segment_count; /**< number of local segments */ + mca_btl_base_completion_fn_t des_cbfunc; /**< local callback function */ + void *des_cbdata; /**< opaque callback data */ + void *des_context; /**< more opaque callback data */ + uint32_t des_flags; /**< hints to BTL */ /** order value, this is only valid in the local completion callback and may be used in subsequent calls to @@ -489,25 +480,25 @@ typedef struct mca_btl_base_descriptor_t mca_btl_base_descriptor_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_btl_base_descriptor_t); -#define MCA_BTL_DES_FLAGS_PRIORITY 0x0001 +#define MCA_BTL_DES_FLAGS_PRIORITY 0x0001 /* Allow the BTL to dispose the descriptor once the callback * associated was triggered. */ -#define MCA_BTL_DES_FLAGS_BTL_OWNERSHIP 0x0002 +#define MCA_BTL_DES_FLAGS_BTL_OWNERSHIP 0x0002 /* Allow the BTL to avoid calling the descriptor callback * if the send succeded in the btl_send (i.e in the fast path). */ -#define MCA_BTL_DES_SEND_ALWAYS_CALLBACK 0x0004 +#define MCA_BTL_DES_SEND_ALWAYS_CALLBACK 0x0004 /* Tell the PML that the copy is being done asynchronously */ -#define MCA_BTL_DES_FLAGS_CUDA_COPY_ASYNC 0x0008 +#define MCA_BTL_DES_FLAGS_CUDA_COPY_ASYNC 0x0008 /* Ask the BTL to wake the remote process (send/sendi) or local process * (put/get) to handle this message. The BTL may ignore this flag if * signaled operations are not supported. */ -#define MCA_BTL_DES_FLAGS_SIGNAL 0x0040 +#define MCA_BTL_DES_FLAGS_SIGNAL 0x0040 /** * Maximum number of allowed segments in src/dst fields of a descriptor. @@ -546,11 +537,10 @@ struct mca_btl_base_receive_descriptor_t { }; typedef struct mca_btl_base_receive_descriptor_t mca_btl_base_receive_descriptor_t; - /* * BTL base header, stores the tag at a minimum */ -struct mca_btl_base_header_t{ +struct mca_btl_base_header_t { mca_btl_base_tag_t tag; }; typedef struct mca_btl_base_header_t mca_btl_base_header_t; @@ -588,11 +578,8 @@ typedef struct mca_btl_base_header_t mca_btl_base_header_t; * */ -typedef struct mca_btl_base_module_t** (*mca_btl_base_component_init_fn_t)( - int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads -); +typedef struct mca_btl_base_module_t **(*mca_btl_base_component_init_fn_t)( + int *num_btls, bool enable_progress_threads, bool enable_mpi_threads); /** * MCA->BTL Called to progress outstanding requests for @@ -605,7 +592,6 @@ typedef struct mca_btl_base_module_t** (*mca_btl_base_component_init_fn_t)( typedef int (*mca_btl_base_component_progress_fn_t)(void); - /** * Callback function that is called asynchronously on receipt * of data by the transport layer. @@ -621,16 +607,15 @@ typedef int (*mca_btl_base_component_progress_fn_t)(void); */ typedef void (*mca_btl_base_module_recv_cb_fn_t)( - struct mca_btl_base_module_t *btl, - const mca_btl_base_receive_descriptor_t *descriptor); + struct mca_btl_base_module_t *btl, const mca_btl_base_receive_descriptor_t *descriptor); typedef struct mca_btl_active_message_callback_t { mca_btl_base_module_recv_cb_fn_t cbfunc; - void* cbdata; + void *cbdata; } mca_btl_active_message_callback_t; -OPAL_DECLSPEC extern -mca_btl_active_message_callback_t mca_btl_base_active_message_trigger[MCA_BTL_TAG_MAX]; +OPAL_DECLSPEC extern mca_btl_active_message_callback_t + mca_btl_base_active_message_trigger[MCA_BTL_TAG_MAX]; /** * BTL component descriptor. Contains component version information @@ -638,10 +623,10 @@ mca_btl_active_message_callback_t mca_btl_base_active_message_trigger[MCA_BTL_TA */ struct mca_btl_base_component_3_0_0_t { - mca_base_component_t btl_version; - mca_base_component_data_t btl_data; - mca_btl_base_component_init_fn_t btl_init; - mca_btl_base_component_progress_fn_t btl_progress; + mca_base_component_t btl_version; + mca_base_component_data_t btl_data; + mca_btl_base_component_init_fn_t btl_init; + mca_btl_base_component_progress_fn_t btl_progress; }; typedef struct mca_btl_base_component_3_0_0_t mca_btl_base_component_3_0_0_t; typedef struct mca_btl_base_component_3_0_0_t mca_btl_base_component_t; @@ -654,7 +639,6 @@ typedef struct mca_btl_base_component_3_0_0_t mca_btl_base_component_t; */ typedef struct mca_btl_base_component_3_0_0_t mca_btl_base_component_2_0_0_t; - /* * BTL module interface functions and datatype. */ @@ -672,9 +656,7 @@ typedef struct mca_btl_base_component_3_0_0_t mca_btl_base_component_2_0_0_t; * to the BTL module freed. * */ -typedef int (*mca_btl_base_module_finalize_fn_t)( - struct mca_btl_base_module_t* btl -); +typedef int (*mca_btl_base_module_finalize_fn_t)(struct mca_btl_base_module_t *btl); /** * BML->BTL notification of change in the process list. @@ -683,7 +665,8 @@ typedef int (*mca_btl_base_module_finalize_fn_t)( * @param nprocs (IN) Number of processes * @param procs (IN) Array of processes * @param endpoint (OUT) Array of mca_btl_base_endpoint_t structures by BTL. - * @param reachable (OUT) Bitmask indicating set of peer processes that are reachable by this BTL. + * @param reachable (OUT) Bitmask indicating set of peer processes that are reachable by this + * BTL. * @return OPAL_SUCCESS or error status on failure. * * The mca_btl_base_module_add_procs_fn_t() is called by the BML to @@ -703,13 +686,10 @@ typedef int (*mca_btl_base_module_finalize_fn_t)( * addressing or connection information (e.g. TCP socket, IB queue * pair). */ -typedef int (*mca_btl_base_module_add_procs_fn_t)( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t** procs, - struct mca_btl_base_endpoint_t** endpoints, - struct opal_bitmap_t* reachable -); +typedef int (*mca_btl_base_module_add_procs_fn_t)(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **endpoints, + struct opal_bitmap_t *reachable); /** * Notification of change to the process list. @@ -724,12 +704,9 @@ typedef int (*mca_btl_base_module_add_procs_fn_t)( * change, to provide the opportunity to cleanup or release any * resources associated with the peer. */ -typedef int (*mca_btl_base_module_del_procs_fn_t)( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t** procs, - struct mca_btl_base_endpoint_t** peer -); +typedef int (*mca_btl_base_module_del_procs_fn_t)(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peer); /** * Register a callback function that is called on receipt @@ -745,13 +722,10 @@ typedef int (*mca_btl_base_module_del_procs_fn_t)( * @return OPAL_ERROR The callback was NOT registered successfully * */ -typedef int (*mca_btl_base_module_register_fn_t)( - struct mca_btl_base_module_t* btl, - mca_btl_base_tag_t tag, - mca_btl_base_module_recv_cb_fn_t cbfunc, - void* cbdata -); - +typedef int (*mca_btl_base_module_register_fn_t)(struct mca_btl_base_module_t *btl, + mca_btl_base_tag_t tag, + mca_btl_base_module_recv_cb_fn_t cbfunc, + void *cbdata); /** * Callback function that is called asynchronously on receipt @@ -763,13 +737,8 @@ typedef int (*mca_btl_base_module_register_fn_t)( * @param[IN] btlinfo descriptive string from the BTL */ -typedef void (*mca_btl_base_module_error_cb_fn_t)( - struct mca_btl_base_module_t* btl, - int32_t flags, - struct opal_proc_t* errproc, - char* btlinfo -); - +typedef void (*mca_btl_base_module_error_cb_fn_t)(struct mca_btl_base_module_t *btl, int32_t flags, + struct opal_proc_t *errproc, char *btlinfo); /** * Register a callback function that is called on receipt @@ -782,11 +751,8 @@ typedef void (*mca_btl_base_module_error_cb_fn_t)( * @return OPAL_ERROR The callback was NOT registered successfully * */ -typedef int (*mca_btl_base_module_register_error_fn_t)( - struct mca_btl_base_module_t* btl, - mca_btl_base_module_error_cb_fn_t cbfunc -); - +typedef int (*mca_btl_base_module_register_error_fn_t)(struct mca_btl_base_module_t *btl, + mca_btl_base_module_error_cb_fn_t cbfunc); /** * Allocate a descriptor with a segment of the requested size. @@ -804,13 +770,9 @@ typedef int (*mca_btl_base_module_register_error_fn_t)( * @param order (IN) The ordering tag (may be MCA_BTL_NO_ORDER) */ -typedef mca_btl_base_descriptor_t* (*mca_btl_base_module_alloc_fn_t)( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags -); +typedef mca_btl_base_descriptor_t *(*mca_btl_base_module_alloc_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, uint8_t order, + size_t size, uint32_t flags); /** * Return a descriptor allocated from this BTL via alloc/prepare. @@ -820,11 +782,8 @@ typedef mca_btl_base_descriptor_t* (*mca_btl_base_module_alloc_fn_t)( * @param btl (IN) BTL module * @param segment (IN) Descriptor allocated from the BTL */ -typedef int (*mca_btl_base_module_free_fn_t)( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* descriptor -); - +typedef int (*mca_btl_base_module_free_fn_t)(struct mca_btl_base_module_t *btl, + mca_btl_base_descriptor_t *descriptor); /** * Prepare a descriptor for send using the supplied convertor. If the convertor @@ -849,15 +808,10 @@ typedef int (*mca_btl_base_module_free_fn_t)( * number of bytes actually prepared (OUT) * */ -typedef struct mca_btl_base_descriptor_t* (*mca_btl_base_module_prepare_fn_t)( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags -); +typedef struct mca_btl_base_descriptor_t *(*mca_btl_base_module_prepare_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, + uint32_t flags); /** * @brief Register a memory region for put/get/atomic operations. @@ -882,7 +836,7 @@ typedef struct mca_btl_base_descriptor_t* (*mca_btl_base_module_prepare_fn_t)( * the mca_btl_base_module_deregister_mem_fn_t function. */ typedef struct mca_btl_base_registration_handle_t *(*mca_btl_base_module_register_mem_fn_t)( - struct mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t *endpoint, void *base, + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, uint32_t flags); /** @@ -902,7 +856,7 @@ typedef struct mca_btl_base_registration_handle_t *(*mca_btl_base_module_registe * is now is allowed to free the memory, return it to a freelist, etc. */ typedef int (*mca_btl_base_module_deregister_mem_fn_t)( - struct mca_btl_base_module_t* btl, struct mca_btl_base_registration_handle_t *handle); + struct mca_btl_base_module_t *btl, struct mca_btl_base_registration_handle_t *handle); /** * Initiate an asynchronous send. @@ -921,12 +875,10 @@ typedef int (*mca_btl_base_module_deregister_mem_fn_t)( * @retval OPAL_ERROR The descriptor was NOT successfully queued for a send * @retval OPAL_ERR_UNREACH The endpoint is not reachable */ -typedef int (*mca_btl_base_module_send_fn_t)( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag -); +typedef int (*mca_btl_base_module_send_fn_t)(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, + mca_btl_base_tag_t tag); /** * Initiate an immediate blocking send. @@ -956,18 +908,12 @@ typedef int (*mca_btl_base_module_send_fn_t)( * (via the OUT param) if descriptors are available */ -typedef int (*mca_btl_base_module_sendi_fn_t)( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - void* header, - size_t header_size, - size_t payload_size, - uint8_t order, - uint32_t flags, - mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t** descriptor - ); +typedef int (*mca_btl_base_module_sendi_fn_t)(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, + size_t header_size, size_t payload_size, + uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor); /** * Initiate an asynchronous put. @@ -1000,11 +946,12 @@ typedef int (*mca_btl_base_module_sendi_fn_t)( * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -typedef int (*mca_btl_base_module_put_fn_t) (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +typedef int (*mca_btl_base_module_put_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); /** * Initiate an asynchronous get. @@ -1037,11 +984,12 @@ typedef int (*mca_btl_base_module_put_fn_t) (struct mca_btl_base_module_t *btl, * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -typedef int (*mca_btl_base_module_get_fn_t) (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +typedef int (*mca_btl_base_module_get_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); /** * Initiate an asynchronous atomic operation. @@ -1078,11 +1026,11 @@ typedef int (*mca_btl_base_module_get_fn_t) (struct mca_btl_base_module_t *btl, * however, that not all btls will provide consistency between btl atomic operations and * cpu or other btl atomics. */ -typedef int (*mca_btl_base_module_atomic_op64_fn_t) (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, uint64_t remote_address, - struct mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); +typedef int (*mca_btl_base_module_atomic_op64_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, struct mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); /** * Initiate an asynchronous fetching atomic operation. @@ -1123,8 +1071,9 @@ typedef int (*mca_btl_base_module_atomic_op64_fn_t) (struct mca_btl_base_module_ * however, that not all btls will provide consistency between btl atomic operations and * cpu or other btl atomics. */ -typedef int (*mca_btl_base_module_atomic_fop64_fn_t) (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, uint64_t remote_address, +typedef int (*mca_btl_base_module_atomic_fop64_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, struct mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, @@ -1169,12 +1118,12 @@ typedef int (*mca_btl_base_module_atomic_fop64_fn_t) (struct mca_btl_base_module * however, that not all btls will provide consistency between btl atomic operations and * cpu atomics. */ -typedef int (*mca_btl_base_module_atomic_cswap64_fn_t) (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, uint64_t remote_address, +typedef int (*mca_btl_base_module_atomic_cswap64_fn_t)( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, - uint64_t value, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); + struct mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); /** * Diagnostic dump of btl state. @@ -1184,11 +1133,9 @@ typedef int (*mca_btl_base_module_atomic_cswap64_fn_t) (struct mca_btl_base_modu * @param verbose (IN) Verbosity level */ -typedef void (*mca_btl_base_module_dump_fn_t)( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - int verbose -); +typedef void (*mca_btl_base_module_dump_fn_t)(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + int verbose); /** * Flush all outstanding RDMA operations on an endpoint or all endpoints. @@ -1202,7 +1149,8 @@ typedef void (*mca_btl_base_module_dump_fn_t)( * * The BTL is allowed to ignore the endpoint parameter and flush *all* endpoints. */ -typedef int (*mca_btl_base_module_flush_fn_t) (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); +typedef int (*mca_btl_base_module_flush_fn_t)(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint); /** * BTL module interface functions and attributes. @@ -1210,64 +1158,69 @@ typedef int (*mca_btl_base_module_flush_fn_t) (struct mca_btl_base_module_t *btl struct mca_btl_base_module_t { /* BTL common attributes */ - mca_btl_base_component_t* btl_component; /**< pointer back to the BTL component structure */ - size_t btl_eager_limit; /**< maximum size of first fragment -- eager send */ - size_t btl_rndv_eager_limit; /**< the size of a data sent in a first fragment of rendezvous protocol */ - size_t btl_max_send_size; /**< maximum send fragment size supported by the BTL */ - size_t btl_rdma_pipeline_send_length; /**< amount of bytes that should be send by pipeline protocol */ - size_t btl_rdma_pipeline_frag_size; /**< maximum rdma fragment size supported by the BTL */ - size_t btl_min_rdma_pipeline_size; /**< minimum packet size for pipeline protocol */ - uint32_t btl_exclusivity; /**< indicates this BTL should be used exclusively */ - uint32_t btl_latency; /**< relative ranking of latency used to prioritize btls */ - uint32_t btl_bandwidth; /**< bandwidth (Mbytes/sec) supported by each endpoint */ - uint32_t btl_flags; /**< flags (put/get...) */ - uint32_t btl_atomic_flags; /**< atomic operations supported (add, and, xor, etc) */ - size_t btl_registration_handle_size; /**< size of the BTLs registration handles */ + mca_btl_base_component_t *btl_component; /**< pointer back to the BTL component structure */ + size_t btl_eager_limit; /**< maximum size of first fragment -- eager send */ + size_t btl_rndv_eager_limit; /**< the size of a data sent in a first fragment of rendezvous + protocol */ + size_t btl_max_send_size; /**< maximum send fragment size supported by the BTL */ + size_t btl_rdma_pipeline_send_length; /**< amount of bytes that should be send by pipeline + protocol */ + size_t btl_rdma_pipeline_frag_size; /**< maximum rdma fragment size supported by the BTL */ + size_t btl_min_rdma_pipeline_size; /**< minimum packet size for pipeline protocol */ + uint32_t btl_exclusivity; /**< indicates this BTL should be used exclusively */ + uint32_t btl_latency; /**< relative ranking of latency used to prioritize btls */ + uint32_t btl_bandwidth; /**< bandwidth (Mbytes/sec) supported by each endpoint */ + uint32_t btl_flags; /**< flags (put/get...) */ + uint32_t btl_atomic_flags; /**< atomic operations supported (add, and, xor, etc) */ + size_t btl_registration_handle_size; /**< size of the BTLs registration handles */ /* One-sided limitations (0 for no alignment, SIZE_MAX for no limit ) */ - size_t btl_get_limit; /**< maximum size supported by the btl_get function */ - size_t btl_get_alignment; /**< minimum alignment/size needed by btl_get (power of 2) */ - size_t btl_put_limit; /**< maximum size supported by the btl_put function */ - size_t btl_put_alignment; /**< minimum alignment/size needed by btl_put (power of 2) */ + size_t btl_get_limit; /**< maximum size supported by the btl_get function */ + size_t btl_get_alignment; /**< minimum alignment/size needed by btl_get (power of 2) */ + size_t btl_put_limit; /**< maximum size supported by the btl_put function */ + size_t btl_put_alignment; /**< minimum alignment/size needed by btl_put (power of 2) */ /* minimum transaction sizes for which registration is required for local memory */ - size_t btl_get_local_registration_threshold; - size_t btl_put_local_registration_threshold; + size_t btl_get_local_registration_threshold; + size_t btl_put_local_registration_threshold; /* BTL function table */ - mca_btl_base_module_add_procs_fn_t btl_add_procs; - mca_btl_base_module_del_procs_fn_t btl_del_procs; - mca_btl_base_module_register_fn_t btl_register; - mca_btl_base_module_finalize_fn_t btl_finalize; - - mca_btl_base_module_alloc_fn_t btl_alloc; - mca_btl_base_module_free_fn_t btl_free; - mca_btl_base_module_prepare_fn_t btl_prepare_src; - mca_btl_base_module_send_fn_t btl_send; - mca_btl_base_module_sendi_fn_t btl_sendi; - mca_btl_base_module_put_fn_t btl_put; - mca_btl_base_module_get_fn_t btl_get; - mca_btl_base_module_dump_fn_t btl_dump; + mca_btl_base_module_add_procs_fn_t btl_add_procs; + mca_btl_base_module_del_procs_fn_t btl_del_procs; + mca_btl_base_module_register_fn_t btl_register; + mca_btl_base_module_finalize_fn_t btl_finalize; + + mca_btl_base_module_alloc_fn_t btl_alloc; + mca_btl_base_module_free_fn_t btl_free; + mca_btl_base_module_prepare_fn_t btl_prepare_src; + mca_btl_base_module_send_fn_t btl_send; + mca_btl_base_module_sendi_fn_t btl_sendi; + mca_btl_base_module_put_fn_t btl_put; + mca_btl_base_module_get_fn_t btl_get; + mca_btl_base_module_dump_fn_t btl_dump; /* atomic operations */ - mca_btl_base_module_atomic_op64_fn_t btl_atomic_op; - mca_btl_base_module_atomic_fop64_fn_t btl_atomic_fop; + mca_btl_base_module_atomic_op64_fn_t btl_atomic_op; + mca_btl_base_module_atomic_fop64_fn_t btl_atomic_fop; mca_btl_base_module_atomic_cswap64_fn_t btl_atomic_cswap; /* new memory registration functions */ - mca_btl_base_module_register_mem_fn_t btl_register_mem; /**< memory registration function (NULL if not needed) */ - mca_btl_base_module_deregister_mem_fn_t btl_deregister_mem; /**< memory deregistration function (NULL if not needed) */ + mca_btl_base_module_register_mem_fn_t + btl_register_mem; /**< memory registration function (NULL if not needed) */ + mca_btl_base_module_deregister_mem_fn_t + btl_deregister_mem; /**< memory deregistration function (NULL if not needed) */ /** the mpool associated with this btl (optional) */ - mca_mpool_base_module_t* btl_mpool; + mca_mpool_base_module_t *btl_mpool; /** register a default error handler */ mca_btl_base_module_register_error_fn_t btl_register_error; #if OPAL_CUDA_GDR_SUPPORT - size_t btl_cuda_eager_limit; /**< switch from eager to RDMA */ - size_t btl_cuda_rdma_limit; /**< switch from RDMA to rndv pipeline */ + size_t btl_cuda_eager_limit; /**< switch from eager to RDMA */ + size_t btl_cuda_rdma_limit; /**< switch from RDMA to rndv pipeline */ #endif /* OPAL_CUDA_GDR_SUPPORT */ #if OPAL_CUDA_SUPPORT - size_t btl_cuda_max_send_size; /**< set if CUDA max send_size is different from host max send size */ + size_t btl_cuda_max_send_size; /**< set if CUDA max send_size is different from host max send + size */ #endif /* OPAL_CUDA_SUPPORT */ mca_btl_base_module_flush_fn_t btl_flush; /**< flush all previous operations on an endpoint */ @@ -1283,17 +1236,14 @@ typedef struct mca_btl_base_module_t mca_btl_base_module_t; /* * Macro for use in modules that are of type btl v3.2.0 */ -#define MCA_BTL_BASE_VERSION_3_3_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("btl", \ - MCA_BTL_BASE_MAJOR_VERSION, \ - MCA_BTL_BASE_MINOR_VERSION, \ +#define MCA_BTL_BASE_VERSION_3_3_0 \ + OPAL_MCA_BASE_VERSION_2_1_0("btl", MCA_BTL_BASE_MAJOR_VERSION, MCA_BTL_BASE_MINOR_VERSION, \ MCA_BTL_BASE_PATCH_VERSION) -#define MCA_BTL_DEFAULT_VERSION(name) \ - MCA_BTL_BASE_VERSION_3_3_0, \ - .mca_component_name = name, \ - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, \ - OPAL_RELEASE_VERSION) +#define MCA_BTL_DEFAULT_VERSION(name) \ + MCA_BTL_BASE_VERSION_3_3_0, .mca_component_name = name, \ + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, \ + OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION) /** * Convenience macro for detecting the BTL interface version. diff --git a/opal/mca/btl/ofi/btl_ofi.h b/opal/mca/btl/ofi/btl_ofi.h index 61e654c6772..68aab6dac4e 100644 --- a/opal/mca/btl/ofi/btl_ofi.h +++ b/opal/mca/btl/ofi/btl_ofi.h @@ -28,38 +28,38 @@ #define MCA_BTL_OFI_H #include "opal_config.h" -#include #include +#include /* Open MPI includes */ -#include "opal/util/event.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" -#include "opal/mca/mpool/mpool.h" #include "opal/mca/btl/base/btl_base_error.h" -#include "opal/mca/rcache/base/base.h" +#include "opal/mca/btl/btl.h" +#include "opal/mca/mpool/mpool.h" #include "opal/mca/pmix/pmix-internal.h" +#include "opal/mca/rcache/base/base.h" +#include "opal/util/event.h" #include "opal/class/opal_hash_table.h" #include -#include -#include #include +#include #include +#include #include BEGIN_C_DECLS -#define MCA_BTL_OFI_MAX_MODULES 16 -#define MCA_BTL_OFI_NUM_CQE_READ 64 +#define MCA_BTL_OFI_MAX_MODULES 16 +#define MCA_BTL_OFI_NUM_CQE_READ 64 -#define MCA_BTL_OFI_DEFAULT_RD_NUM 10 -#define MCA_BTL_OFI_DEFAULT_MAX_CQE 128 -#define MCA_BTL_OFI_DEFAULT_PROGRESS_THRESHOLD 64 +#define MCA_BTL_OFI_DEFAULT_RD_NUM 10 +#define MCA_BTL_OFI_DEFAULT_MAX_CQE 128 +#define MCA_BTL_OFI_DEFAULT_PROGRESS_THRESHOLD 64 -#define MCA_BTL_OFI_ABORT(args) mca_btl_ofi_exit(args) +#define MCA_BTL_OFI_ABORT(args) mca_btl_ofi_exit(args) -#define TWO_SIDED_ENABLED mca_btl_ofi_component.two_sided_enabled +#define TWO_SIDED_ENABLED mca_btl_ofi_component.two_sided_enabled enum mca_btl_ofi_mode { MCA_BTL_OFI_MODE_ONE_SIDED = 0, @@ -146,7 +146,7 @@ extern mca_btl_ofi_module_t mca_btl_ofi_module_template; * @brief OFI BTL component */ struct mca_btl_ofi_component_t { - mca_btl_base_component_3_0_0_t super; /**< base BTL component */ + mca_btl_base_component_3_0_0_t super; /**< base BTL component */ /** number of TL modules */ int module_count; @@ -161,7 +161,6 @@ struct mca_btl_ofi_component_t { /** All BTL OFI modules (1 per tl) */ mca_btl_ofi_module_t *modules[MCA_BTL_OFI_MAX_MODULES]; - }; typedef struct mca_btl_ofi_component_t mca_btl_ofi_component_t; @@ -205,7 +204,6 @@ typedef struct mca_btl_ofi_base_frag_t mca_btl_ofi_base_frag_t; OBJ_CLASS_DECLARATION(mca_btl_ofi_base_frag_t); - struct mca_btl_ofi_completion_context_t { struct fi_context ctx; void *comp; @@ -283,11 +281,12 @@ OBJ_CLASS_DECLARATION(mca_btl_ofi_frag_completion_t); * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -int mca_btl_ofi_put (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_ofi_put(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); /** * Initiate an asynchronous get. @@ -320,54 +319,59 @@ int mca_btl_ofi_put (struct mca_btl_base_module_t *btl, * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -int mca_btl_ofi_get (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - -int mca_btl_ofi_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, +int mca_btl_ofi_get(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); + +int mca_btl_ofi_aop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); + +int mca_btl_ofi_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, + uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); -int mca_btl_ofi_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); - -int mca_btl_ofi_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - +int mca_btl_ofi_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, + uint64_t value, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); -int mca_btl_ofi_flush (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); +int mca_btl_ofi_flush(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); -int mca_btl_ofi_finalize (mca_btl_base_module_t *btl); +int mca_btl_ofi_finalize(mca_btl_base_module_t *btl); -void mca_btl_ofi_rcache_init (mca_btl_ofi_module_t *module); -int mca_btl_ofi_reg_mem (void *reg_data, void *base, size_t size, - mca_rcache_base_registration_t *reg); -int mca_btl_ofi_dereg_mem (void *reg_data, mca_rcache_base_registration_t *reg); +void mca_btl_ofi_rcache_init(mca_btl_ofi_module_t *module); +int mca_btl_ofi_reg_mem(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg); +int mca_btl_ofi_dereg_mem(void *reg_data, mca_rcache_base_registration_t *reg); int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context); -mca_btl_ofi_module_t * mca_btl_ofi_module_alloc (int mode); +mca_btl_ofi_module_t *mca_btl_ofi_module_alloc(int mode); -int mca_btl_ofi_post_recvs(mca_btl_base_module_t* module, mca_btl_ofi_context_t *context, int count); +int mca_btl_ofi_post_recvs(mca_btl_base_module_t *module, mca_btl_ofi_context_t *context, + int count); void mca_btl_ofi_exit(void); /* thread atomics */ -static inline bool mca_btl_ofi_context_trylock (mca_btl_ofi_context_t *context) +static inline bool mca_btl_ofi_context_trylock(mca_btl_ofi_context_t *context) { return (context->lock || OPAL_ATOMIC_SWAP_32(&context->lock, 1)); } static inline void mca_btl_ofi_context_lock(mca_btl_ofi_context_t *context) { - while (mca_btl_ofi_context_trylock(context)); + while (mca_btl_ofi_context_trylock(context)) + ; } static inline void mca_btl_ofi_context_unlock(mca_btl_ofi_context_t *context) diff --git a/opal/mca/btl/ofi/btl_ofi_atomics.c b/opal/mca/btl/ofi/btl_ofi_atomics.c index f9b2447130b..17dd9804b27 100644 --- a/opal/mca/btl/ofi/btl_ofi_atomics.c +++ b/opal/mca/btl/ofi/btl_ofi_atomics.c @@ -11,8 +11,8 @@ * $HEADER$ */ -#include #include "btl_ofi_rdma.h" +#include static inline int to_fi_op(mca_btl_base_atomic_op_t op) { @@ -30,18 +30,19 @@ static inline int to_fi_op(mca_btl_base_atomic_op_t op) } } -int mca_btl_ofi_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +int mca_btl_ofi_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, + uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { int rc; int fi_datatype = FI_UINT64; int fi_op; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint; + mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t *) endpoint; mca_btl_ofi_rdma_completion_t *comp = NULL; mca_btl_ofi_context_t *ofi_context; @@ -53,11 +54,8 @@ int mca_btl_ofi_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end fi_op = to_fi_op(op); - comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, - ofi_context, - local_address, - local_handle, - cbfunc, cbcontext, cbdata, + comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, ofi_context, local_address, + local_handle, cbfunc, cbcontext, cbdata, MCA_BTL_OFI_TYPE_AFOP); /* copy the operand because it might get freed from upper layer */ @@ -65,18 +63,17 @@ int mca_btl_ofi_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end remote_address = (remote_address - (uint64_t) remote_handle->base_addr); - rc = fi_fetch_atomic(ofi_context->tx_ctx, - (void*) &comp->operand, 1, NULL, /* operand */ - local_address, local_handle->desc, /* results */ - btl_endpoint->peer_addr, /* remote addr */ - remote_address, remote_handle->rkey, /* remote buffer */ + rc = fi_fetch_atomic(ofi_context->tx_ctx, (void *) &comp->operand, 1, NULL, /* operand */ + local_address, local_handle->desc, /* results */ + btl_endpoint->peer_addr, /* remote addr */ + remote_address, remote_handle->rkey, /* remote buffer */ fi_datatype, fi_op, &comp->comp_ctx); if (rc == -FI_EAGAIN) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); return OPAL_ERR_OUT_OF_RESOURCE; } else if (rc < 0) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); BTL_ERROR(("fi_fetch_atomic failed with rc=%d (%s)", rc, fi_strerror(-rc))); MCA_BTL_OFI_ABORT(); } @@ -86,17 +83,17 @@ int mca_btl_ofi_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end return OPAL_SUCCESS; } -int mca_btl_ofi_aop (struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, - uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ofi_aop(struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { int rc; int fi_datatype = FI_UINT64; int fi_op; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint; + mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t *) endpoint; mca_btl_ofi_rdma_completion_t *comp = NULL; mca_btl_ofi_context_t *ofi_context; @@ -108,29 +105,24 @@ int mca_btl_ofi_aop (struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t fi_op = to_fi_op(op); - comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, - ofi_context, - NULL, - NULL, - cbfunc, cbcontext, cbdata, - MCA_BTL_OFI_TYPE_AOP); + comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, ofi_context, NULL, NULL, cbfunc, + cbcontext, cbdata, MCA_BTL_OFI_TYPE_AOP); /* copy the operand because it might get freed from upper layer */ comp->operand = (uint64_t) operand; remote_address = (remote_address - (uint64_t) remote_handle->base_addr); - rc = fi_atomic(ofi_context->tx_ctx, - (void*) &comp->operand, 1, NULL, /* operand */ - btl_endpoint->peer_addr, /* remote addr */ - remote_address, remote_handle->rkey, /* remote buffer */ + rc = fi_atomic(ofi_context->tx_ctx, (void *) &comp->operand, 1, NULL, /* operand */ + btl_endpoint->peer_addr, /* remote addr */ + remote_address, remote_handle->rkey, /* remote buffer */ fi_datatype, fi_op, &comp->comp_ctx); if (rc == -FI_EAGAIN) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); return OPAL_ERR_OUT_OF_RESOURCE; } else if (rc < 0) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); BTL_ERROR(("fi_atomic failed with rc=%d (%s)", rc, fi_strerror(-rc))); MCA_BTL_OFI_ABORT(); } @@ -140,10 +132,12 @@ int mca_btl_ofi_aop (struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t return OPAL_SUCCESS; } -int mca_btl_ofi_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ofi_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, + uint64_t value, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { int rc; int fi_datatype = FI_UINT64; @@ -151,7 +145,7 @@ int mca_btl_ofi_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_e mca_btl_ofi_rdma_completion_t *comp = NULL; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint; + mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t *) endpoint; mca_btl_ofi_context_t *ofi_context; ofi_context = get_ofi_context(ofi_btl); @@ -160,11 +154,8 @@ int mca_btl_ofi_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_e fi_datatype = FI_UINT32; } - comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, - ofi_context, - local_address, - local_handle, - cbfunc, cbcontext, cbdata, + comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, ofi_context, local_address, + local_handle, cbfunc, cbcontext, cbdata, MCA_BTL_OFI_TYPE_CSWAP); /* copy the operand because it might get freed from upper layer */ @@ -174,21 +165,16 @@ int mca_btl_ofi_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_e remote_address = (remote_address - (uint64_t) remote_handle->base_addr); /* perform atomic */ - rc = fi_compare_atomic(ofi_context->tx_ctx, - (void*) &comp->operand, 1, NULL, - (void*) &comp->compare, NULL, - local_address, local_handle->desc, - btl_endpoint->peer_addr, - remote_address, remote_handle->rkey, - fi_datatype, - FI_CSWAP, - &comp->comp_ctx); + rc = fi_compare_atomic(ofi_context->tx_ctx, (void *) &comp->operand, 1, NULL, + (void *) &comp->compare, NULL, local_address, local_handle->desc, + btl_endpoint->peer_addr, remote_address, remote_handle->rkey, + fi_datatype, FI_CSWAP, &comp->comp_ctx); if (rc == -FI_EAGAIN) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); return OPAL_ERR_OUT_OF_RESOURCE; } else if (rc < 0) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); BTL_ERROR(("fi_compare_atomic failed with rc=%d (%s)", rc, fi_strerror(-rc))); MCA_BTL_OFI_ABORT(); } diff --git a/opal/mca/btl/ofi/btl_ofi_component.c b/opal/mca/btl/ofi/btl_ofi_component.c index 326d4fe69c2..fe22fa18e9b 100644 --- a/opal/mca/btl/ofi/btl_ofi_component.c +++ b/opal/mca/btl/ofi/btl_ofi_component.c @@ -24,28 +24,27 @@ * $HEADER$ */ - #include "opal_config.h" -#include "opal/util/printf.h" #include "opal/util/argv.h" +#include "opal/util/printf.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" -#include "opal/mca/hwloc/base/base.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/common/ofi/common_ofi.h" +#include "opal/mca/hwloc/base/base.h" #include #include "btl_ofi.h" #include "btl_ofi_endpoint.h" -#include "btl_ofi_rdma.h" #include "btl_ofi_frag.h" +#include "btl_ofi_rdma.h" -#define MCA_BTL_OFI_ONE_SIDED_REQUIRED_CAPS (FI_RMA | FI_ATOMIC) -#define MCA_BTL_OFI_TWO_SIDED_REQUIRED_CAPS (FI_MSG) +#define MCA_BTL_OFI_ONE_SIDED_REQUIRED_CAPS (FI_RMA | FI_ATOMIC) +#define MCA_BTL_OFI_TWO_SIDED_REQUIRED_CAPS (FI_MSG) -#define MCA_BTL_OFI_REQUESTED_MR_MODE (FI_MR_ALLOCATED | FI_MR_PROV_KEY | FI_MR_VIRT_ADDR) +#define MCA_BTL_OFI_REQUESTED_MR_MODE (FI_MR_ALLOCATED | FI_MR_PROV_KEY | FI_MR_VIRT_ADDR) static char *ofi_progress_mode; static bool disable_sep; @@ -53,22 +52,21 @@ static int mca_btl_ofi_init_device(struct fi_info *info); /* validate information returned from fi_getinfo(). * return OPAL_ERROR if we dont have what we need. */ -static int validate_info(struct fi_info *info, uint64_t required_caps, - char **include_list, char **exclude_list) +static int validate_info(struct fi_info *info, uint64_t required_caps, char **include_list, + char **exclude_list) { int mr_mode; - if (NULL != include_list && !opal_common_ofi_is_in_list(include_list, info->fabric_attr->prov_name)) { + if (NULL != include_list + && !opal_common_ofi_is_in_list(include_list, info->fabric_attr->prov_name)) { opal_output_verbose(1, opal_common_ofi.output, - "%s:%d: btl:ofi: \"%s\" not in include list\n", - __FILE__, __LINE__, + "%s:%d: btl:ofi: \"%s\" not in include list\n", __FILE__, __LINE__, info->fabric_attr->prov_name); return OPAL_ERROR; - } else if (NULL != exclude_list && opal_common_ofi_is_in_list(exclude_list, info->fabric_attr->prov_name)) { - opal_output_verbose(1, opal_common_ofi.output, - "%s:%d: btl:ofi: \"%s\" in exclude list\n", - __FILE__, __LINE__, - info->fabric_attr->prov_name); + } else if (NULL != exclude_list + && opal_common_ofi_is_in_list(exclude_list, info->fabric_attr->prov_name)) { + opal_output_verbose(1, opal_common_ofi.output, "%s:%d: btl:ofi: \"%s\" in exclude list\n", + __FILE__, __LINE__, info->fabric_attr->prov_name); return OPAL_ERROR; } @@ -80,7 +78,7 @@ static int validate_info(struct fi_info *info, uint64_t required_caps, * Thus, FI_VERSION(112,0) corresponds to libfabric 1.12.0 */ if (!strncasecmp(info->fabric_attr->prov_name, "efa", 3) - && FI_VERSION_LT(info->fabric_attr->prov_version, FI_VERSION(112,0))) { + && FI_VERSION_LT(info->fabric_attr->prov_version, FI_VERSION(112, 0))) { BTL_VERBOSE(("unsupported libfabric efa version")); return OPAL_ERROR; } @@ -107,8 +105,8 @@ static int validate_info(struct fi_info *info, uint64_t required_caps, mr_mode = info->domain_attr->mr_mode; - if (!(mr_mode == FI_MR_BASIC || mr_mode == FI_MR_SCALABLE || - (mr_mode & ~(FI_MR_VIRT_ADDR | FI_MR_ALLOCATED | FI_MR_PROV_KEY)) == 0)) { + if (!(mr_mode == FI_MR_BASIC || mr_mode == FI_MR_SCALABLE + || (mr_mode & ~(FI_MR_VIRT_ADDR | FI_MR_ALLOCATED | FI_MR_PROV_KEY)) == 0)) { BTL_VERBOSE(("unsupported MR mode")); return OPAL_ERROR; } @@ -128,92 +126,74 @@ static int mca_btl_ofi_component_register(void) char *msg; mca_btl_ofi_module_t *module = &mca_btl_ofi_module_template; - opal_asprintf(&msg, "BTL OFI mode of operation. Valid values are: %d = One-Sided only, %d=Two-Sided only, " - "%d = Both one and two sided. BTL OFI is only optimized for one-sided communication", - MCA_BTL_OFI_MODE_ONE_SIDED, - MCA_BTL_OFI_MODE_TWO_SIDED, - MCA_BTL_OFI_MODE_FULL_SUPPORT); + opal_asprintf( + &msg, + "BTL OFI mode of operation. Valid values are: %d = One-Sided only, %d=Two-Sided only, " + "%d = Both one and two sided. BTL OFI is only optimized for one-sided communication", + MCA_BTL_OFI_MODE_ONE_SIDED, MCA_BTL_OFI_MODE_TWO_SIDED, MCA_BTL_OFI_MODE_FULL_SUPPORT); if (NULL == msg) { return OPAL_ERR_OUT_OF_RESOURCE; } mca_btl_ofi_component.mode = MCA_BTL_OFI_MODE_ONE_SIDED; - (void)mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "mode", - msg, - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_ofi_component.mode); - + (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, "mode", msg, + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_ofi_component.mode); mca_btl_ofi_component.num_cqe_read = MCA_BTL_OFI_NUM_CQE_READ; - (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "num_cq_read", - "Number of completion entries to read from a single cq_read. ", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_ofi_component.num_cqe_read); + (void) mca_base_component_var_register( + &mca_btl_ofi_component.super.btl_version, "num_cq_read", + "Number of completion entries to read from a single cq_read. ", MCA_BASE_VAR_TYPE_INT, NULL, + 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_ofi_component.num_cqe_read); ofi_progress_mode = "unspec"; - (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "progress_mode", - "requested provider progress mode. [unspec, auto, manual]" - "(default: unspec)", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &ofi_progress_mode); + (void) + mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, "progress_mode", + "requested provider progress mode. [unspec, auto, manual]" + "(default: unspec)", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, &ofi_progress_mode); mca_btl_ofi_component.num_contexts_per_module = 1; - (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "num_contexts_per_module", - "number of communication context per module to create. " - "This should increase multithreaded performance but it is " - "advised that this number should be lower than total cores.", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_ofi_component.num_contexts_per_module); + (void) mca_base_component_var_register( + &mca_btl_ofi_component.super.btl_version, "num_contexts_per_module", + "number of communication context per module to create. " + "This should increase multithreaded performance but it is " + "advised that this number should be lower than total cores.", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_ofi_component.num_contexts_per_module); disable_sep = false; - (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "disable_sep", - "force btl/ofi to never use scalable endpoint.", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &disable_sep); + (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, "disable_sep", + "force btl/ofi to never use scalable endpoint.", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, &disable_sep); mca_btl_ofi_component.progress_threshold = MCA_BTL_OFI_DEFAULT_PROGRESS_THRESHOLD; - (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "progress_threshold", - "number of outstanding operation before btl will progress " - "automatically. Tuning this might improve performance on " - "certain type of application.", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_ofi_component.progress_threshold); + (void) + mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, + "progress_threshold", + "number of outstanding operation before btl will progress " + "automatically. Tuning this might improve performance on " + "certain type of application.", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_ofi_component.progress_threshold); mca_btl_ofi_component.rd_num = MCA_BTL_OFI_DEFAULT_RD_NUM; - (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, - "rd_num", - "Number of receive descriptor posted per context.", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_ofi_component.rd_num); - + (void) mca_base_component_var_register(&mca_btl_ofi_component.super.btl_version, "rd_num", + "Number of receive descriptor posted per context.", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_ofi_component.rd_num); /* for now we want this component to lose to the MTL. */ module->super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH - 50; opal_common_ofi_register_mca_variables(&mca_btl_ofi_component.super.btl_version); - return mca_btl_base_param_register (&mca_btl_ofi_component.super.btl_version, - &module->super); + return mca_btl_base_param_register(&mca_btl_ofi_component.super.btl_version, &module->super); } static int mca_btl_ofi_component_open(void) @@ -245,10 +225,12 @@ void mca_btl_ofi_exit(void) * then create a BTL instance for selected interfaces */ -static mca_btl_base_module_t **mca_btl_ofi_component_init (int *num_btl_modules, bool enable_progress_threads, - bool enable_mpi_threads) +static mca_btl_base_module_t **mca_btl_ofi_component_init(int *num_btl_modules, + bool enable_progress_threads, + bool enable_mpi_threads) { - /* for this BTL to be useful the interface needs to support RDMA and certain atomic operations */ + /* for this BTL to be useful the interface needs to support RDMA and certain atomic operations + */ int rc; uint64_t progress_mode; unsigned resource_count = 0; @@ -280,30 +262,27 @@ static mca_btl_base_module_t **mca_btl_ofi_component_init (int *num_btl_modules, switch (mca_btl_ofi_component.mode) { - case MCA_BTL_OFI_MODE_TWO_SIDED: - mca_btl_ofi_component.two_sided_enabled = true; - required_caps = MCA_BTL_OFI_TWO_SIDED_REQUIRED_CAPS; - break; + case MCA_BTL_OFI_MODE_TWO_SIDED: + mca_btl_ofi_component.two_sided_enabled = true; + required_caps = MCA_BTL_OFI_TWO_SIDED_REQUIRED_CAPS; + break; - case MCA_BTL_OFI_MODE_FULL_SUPPORT: - mca_btl_ofi_component.two_sided_enabled = true; - required_caps = MCA_BTL_OFI_ONE_SIDED_REQUIRED_CAPS | - MCA_BTL_OFI_TWO_SIDED_REQUIRED_CAPS; - break; + case MCA_BTL_OFI_MODE_FULL_SUPPORT: + mca_btl_ofi_component.two_sided_enabled = true; + required_caps = MCA_BTL_OFI_ONE_SIDED_REQUIRED_CAPS | MCA_BTL_OFI_TWO_SIDED_REQUIRED_CAPS; + break; - default: - /* default to only one sided. */ - required_caps = MCA_BTL_OFI_ONE_SIDED_REQUIRED_CAPS; - break; + default: + /* default to only one sided. */ + required_caps = MCA_BTL_OFI_ONE_SIDED_REQUIRED_CAPS; + break; } fabric_attr.prov_name = NULL; - opal_output_verbose(1, opal_common_ofi.output, - "%s:%d: btl:ofi:provider_include = \"%s\"\n", + opal_output_verbose(1, opal_common_ofi.output, "%s:%d: btl:ofi:provider_include = \"%s\"\n", __FILE__, __LINE__, *opal_common_ofi.prov_include); - opal_output_verbose(1, opal_common_ofi.output, - "%s:%d: btl:ofi:provider_exclude = \"%s\"\n", + opal_output_verbose(1, opal_common_ofi.output, "%s:%d: btl:ofi:provider_exclude = \"%s\"\n", __FILE__, __LINE__, *opal_common_ofi.prov_exclude); if (NULL != *opal_common_ofi.prov_include) { @@ -354,17 +333,16 @@ static mca_btl_base_module_t **mca_btl_ofi_component_init (int *num_btl_modules, /* do the query. */ rc = fi_getinfo(FI_VERSION(1, 5), NULL, NULL, 0, &hints, &info_list); if (0 != rc) { - BTL_VERBOSE(("fi_getinfo failed with code %d: %s",rc, fi_strerror(-rc))); + BTL_VERBOSE(("fi_getinfo failed with code %d: %s", rc, fi_strerror(-rc))); if (NULL != include_list) { opal_argv_free(include_list); } return NULL; } - /* count the number of resources/ */ info = info_list; - while(info) { + while (info) { resource_count++; info = info->next; } @@ -372,7 +350,7 @@ static mca_btl_base_module_t **mca_btl_ofi_component_init (int *num_btl_modules, info = info_list; - while(info) { + while (info) { rc = validate_info(info, required_caps, include_list, exclude_list); if (OPAL_SUCCESS == rc) { /* Device passed sanity check, let's make a module. @@ -408,13 +386,13 @@ static mca_btl_base_module_t **mca_btl_ofi_component_init (int *num_btl_modules, } /* pass module array back to caller */ - base_modules = calloc (mca_btl_ofi_component.module_count, sizeof (*base_modules)); + base_modules = calloc(mca_btl_ofi_component.module_count, sizeof(*base_modules)); if (NULL == base_modules) { return NULL; } memcpy(base_modules, mca_btl_ofi_component.modules, - mca_btl_ofi_component.module_count *sizeof (mca_btl_ofi_component.modules[0])); + mca_btl_ofi_component.module_count * sizeof(mca_btl_ofi_component.modules[0])); BTL_VERBOSE(("ofi btl initialization complete. found %d suitable transports", mca_btl_ofi_component.module_count)); @@ -453,7 +431,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) /* If the user ask for two sided support, something bad is happening * to the MTL, so we will take maximum priority to supersede the MTL. */ - module->super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_DEFAULT; + module->super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_DEFAULT; /* make a copy of the given info to store on the module */ ofi_info = fi_dupinfo(info); @@ -467,27 +445,20 @@ static int mca_btl_ofi_init_device(struct fi_info *info) mca_btl_ofi_rcache_init(module); linux_device_name = info->domain_attr->name; - BTL_VERBOSE(("initializing dev:%s provider:%s", - linux_device_name, - info->fabric_attr->prov_name)); + BTL_VERBOSE( + ("initializing dev:%s provider:%s", linux_device_name, info->fabric_attr->prov_name)); /* fabric */ rc = fi_fabric(ofi_info->fabric_attr, &fabric, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_fabric with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_fabric with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } /* domain */ rc = fi_domain(fabric, ofi_info, &domain, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_domain with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_domain with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } @@ -495,10 +466,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) av_attr.type = FI_AV_MAP; rc = fi_av_open(domain, &av_attr, &av, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_av_open with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_av_open with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } @@ -511,10 +479,9 @@ static int mca_btl_ofi_init_device(struct fi_info *info) if (num_contexts_to_create > domain_attr->max_ep_tx_ctx) { BTL_VERBOSE(("cannot create requested %u contexts. (node max=%zu)", - module->num_contexts, - domain_attr->max_ep_tx_ctx)); + module->num_contexts, domain_attr->max_ep_tx_ctx)); goto fail; - } + } /* modify the info to let the provider know we are creating x contexts */ ep_attr->tx_ctx_cnt = num_contexts_to_create; @@ -523,10 +490,8 @@ static int mca_btl_ofi_init_device(struct fi_info *info) /* create scalable endpoint */ rc = fi_scalable_ep(domain, ofi_info, &ep, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_scalable_ep with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE( + ("%s failed fi_scalable_ep with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } @@ -534,26 +499,22 @@ static int mca_btl_ofi_init_device(struct fi_info *info) module->is_scalable_ep = true; /* create contexts */ - module->contexts = mca_btl_ofi_context_alloc_scalable(ofi_info, - domain, ep, av, - num_contexts_to_create); + module->contexts = mca_btl_ofi_context_alloc_scalable(ofi_info, domain, ep, av, + num_contexts_to_create); - } else { + } else { /* warn the user if they want more than 1 context */ if (num_contexts_to_create > 1) { BTL_ERROR(("cannot create %zu contexts as the provider does not support " - "scalable endpoint. Falling back to single context endpoint.", - num_contexts_to_create)); + "scalable endpoint. Falling back to single context endpoint.", + num_contexts_to_create)); } BTL_VERBOSE(("btl/ofi using normal endpoint.")); rc = fi_endpoint(domain, ofi_info, &ep, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_endpoint with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_endpoint with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } @@ -561,8 +522,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) module->is_scalable_ep = false; /* create contexts */ - module->contexts = mca_btl_ofi_context_alloc_normal(ofi_info, - domain, ep, av); + module->contexts = mca_btl_ofi_context_alloc_normal(ofi_info, domain, ep, av); } if (NULL == module->contexts) { @@ -573,10 +533,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) /* enable the endpoint for using */ rc = fi_enable(ep); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_enable with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_enable with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } @@ -591,8 +548,8 @@ static int mca_btl_ofi_init_device(struct fi_info *info) module->outstanding_rdma = 0; module->use_virt_addr = false; - if (ofi_info->domain_attr->mr_mode == FI_MR_BASIC || - ofi_info->domain_attr->mr_mode & FI_MR_VIRT_ADDR) { + if (ofi_info->domain_attr->mr_mode == FI_MR_BASIC + || ofi_info->domain_attr->mr_mode & FI_MR_VIRT_ADDR) { module->use_virt_addr = true; } @@ -601,7 +558,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) OBJ_CONSTRUCT(&module->module_lock, opal_mutex_t); OBJ_CONSTRUCT(&module->id_to_endpoint, opal_hash_table_t); - rc = opal_hash_table_init (&module->id_to_endpoint, 512); + rc = opal_hash_table_init(&module->id_to_endpoint, 512); if (OPAL_SUCCESS != rc) { BTL_ERROR(("error initializing hash table.")); goto fail; @@ -609,23 +566,18 @@ static int mca_btl_ofi_init_device(struct fi_info *info) /* create and send the modex for this device */ namelen = sizeof(ep_name); - rc = fi_getname((fid_t)ep, &ep_name[0], &namelen); + rc = fi_getname((fid_t) ep, &ep_name[0], &namelen); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_getname with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_getname with err=%s", linux_device_name, fi_strerror(-rc))); goto fail; } - /* If we have two-sided support. */ if (TWO_SIDED_ENABLED) { /* post wildcard recvs */ - for (int i=0; i < module->num_contexts; i++) { - rc = mca_btl_ofi_post_recvs((mca_btl_base_module_t*) module, - &module->contexts[i], + for (int i = 0; i < module->num_contexts; i++) { + rc = mca_btl_ofi_post_recvs((mca_btl_base_module_t *) module, &module->contexts[i], mca_btl_ofi_component.rd_num); if (OPAL_SUCCESS != rc) { goto fail; @@ -634,11 +586,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) } /* post our endpoint name so peer can use it to connect to us */ - OPAL_MODEX_SEND(rc, - PMIX_GLOBAL, - &mca_btl_ofi_component.super.btl_version, - &ep_name, - namelen); + OPAL_MODEX_SEND(rc, PMIX_GLOBAL, &mca_btl_ofi_component.super.btl_version, &ep_name, namelen); mca_btl_ofi_component.namelen = namelen; /* add this module to the list */ @@ -657,7 +605,7 @@ static int mca_btl_ofi_init_device(struct fi_info *info) /* if the contexts have not been initiated, num_contexts should * be zero and we skip this. */ - for (int i=0; i < module->num_contexts; i++) { + for (int i = 0; i < module->num_contexts; i++) { mca_btl_ofi_context_finalize(&module->contexts[i], module->is_scalable_ep); } free(module->contexts); @@ -690,12 +638,12 @@ static int mca_btl_ofi_init_device(struct fi_info *info) * * This function explictly progresses all workers. */ -static int mca_btl_ofi_component_progress (void) +static int mca_btl_ofi_component_progress(void) { int events = 0; mca_btl_ofi_context_t *context; - for (int i = 0 ; i < mca_btl_ofi_component.module_count ; ++i) { + for (int i = 0; i < mca_btl_ofi_component.module_count; ++i) { mca_btl_ofi_module_t *module = mca_btl_ofi_component.modules[i]; /* progress context we own first. */ @@ -708,7 +656,7 @@ static int mca_btl_ofi_component_progress (void) /* if there is nothing to do, try progress other's. */ if (events == 0) { - for (int j = 0 ; j < module->num_contexts ; j++ ) { + for (int j = 0; j < module->num_contexts; j++) { context = get_ofi_context_rr(module); @@ -731,19 +679,20 @@ static int mca_btl_ofi_component_progress (void) /** OFI btl component */ mca_btl_ofi_component_t mca_btl_ofi_component = { - .super = { - .btl_version = { - MCA_BTL_DEFAULT_VERSION("ofi"), - .mca_open_component = mca_btl_ofi_component_open, - .mca_close_component = mca_btl_ofi_component_close, - .mca_register_component_params = mca_btl_ofi_component_register, + .super = + { + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("ofi"), + .mca_open_component = mca_btl_ofi_component_open, + .mca_close_component = mca_btl_ofi_component_close, + .mca_register_component_params = mca_btl_ofi_component_register, + }, + .btl_data = + {/* The component is not checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_NONE}, + + .btl_init = mca_btl_ofi_component_init, + .btl_progress = mca_btl_ofi_component_progress, }, - .btl_data = { - /* The component is not checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_NONE - }, - - .btl_init = mca_btl_ofi_component_init, - .btl_progress = mca_btl_ofi_component_progress, - }, }; diff --git a/opal/mca/btl/ofi/btl_ofi_context.c b/opal/mca/btl/ofi/btl_ofi_context.c index bd399c62280..518bacbe20b 100644 --- a/opal/mca/btl/ofi/btl_ofi_context.c +++ b/opal/mca/btl/ofi/btl_ofi_context.c @@ -21,20 +21,9 @@ int init_context_freelists(mca_btl_ofi_context_t *context) { int rc; OBJ_CONSTRUCT(&context->rdma_comp_list, opal_free_list_t); - rc = opal_free_list_init(&context->rdma_comp_list, - sizeof(mca_btl_ofi_rdma_completion_t), - opal_cache_line_size, - OBJ_CLASS(mca_btl_ofi_rdma_completion_t), - 0, - 0, - 512, - -1, - 512, - NULL, - 0, - NULL, - NULL, - NULL); + rc = opal_free_list_init(&context->rdma_comp_list, sizeof(mca_btl_ofi_rdma_completion_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_ofi_rdma_completion_t), 0, 0, + 512, -1, 512, NULL, 0, NULL, NULL, NULL); if (rc != OPAL_SUCCESS) { BTL_VERBOSE(("cannot allocate completion freelist")); return rc; @@ -42,20 +31,9 @@ int init_context_freelists(mca_btl_ofi_context_t *context) if (TWO_SIDED_ENABLED) { OBJ_CONSTRUCT(&context->frag_comp_list, opal_free_list_t); - rc = opal_free_list_init(&context->frag_comp_list, - sizeof(mca_btl_ofi_frag_completion_t), - opal_cache_line_size, - OBJ_CLASS(mca_btl_ofi_frag_completion_t), - 0, - 0, - 512, - -1, - 512, - NULL, - 0, - NULL, - NULL, - NULL); + rc = opal_free_list_init(&context->frag_comp_list, sizeof(mca_btl_ofi_frag_completion_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_ofi_frag_completion_t), 0, + 0, 512, -1, 512, NULL, 0, NULL, NULL, NULL); if (rc != OPAL_SUCCESS) { BTL_VERBOSE(("cannot allocate completion freelist")); return rc; @@ -64,20 +42,9 @@ int init_context_freelists(mca_btl_ofi_context_t *context) /* Initialize frag pool */ OBJ_CONSTRUCT(&context->frag_list, opal_free_list_t); rc = opal_free_list_init(&context->frag_list, - sizeof(mca_btl_ofi_base_frag_t) + - MCA_BTL_OFI_FRAG_SIZE, - opal_cache_line_size, - OBJ_CLASS(mca_btl_ofi_base_frag_t), - 0, - 0, - 1024, - -1, - 1024, - NULL, - 0, - NULL, - NULL, - NULL); + sizeof(mca_btl_ofi_base_frag_t) + MCA_BTL_OFI_FRAG_SIZE, + opal_cache_line_size, OBJ_CLASS(mca_btl_ofi_base_frag_t), 0, 0, + 1024, -1, 1024, NULL, 0, NULL, NULL, NULL); if (OPAL_SUCCESS != rc) { BTL_VERBOSE(("failed to init frag pool (free_list)")); } @@ -93,8 +60,7 @@ int init_context_freelists(mca_btl_ofi_context_t *context) * USE WITH NORMAL ENDPOINT ONLY */ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_normal(struct fi_info *info, struct fid_domain *domain, - struct fid_ep *ep, - struct fid_av *av) + struct fid_ep *ep, struct fid_av *av) { int rc; uint32_t cq_flags = FI_TRANSMIT | FI_SEND | FI_RECV; @@ -104,7 +70,7 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_normal(struct fi_info *info, mca_btl_ofi_context_t *context; - context = (mca_btl_ofi_context_t*) calloc(1, sizeof(*context)); + context = (mca_btl_ofi_context_t *) calloc(1, sizeof(*context)); if (NULL == context) { BTL_VERBOSE(("cannot allocate context")); return NULL; @@ -122,28 +88,20 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_normal(struct fi_info *info, cq_attr.wait_obj = FI_WAIT_NONE; rc = fi_cq_open(domain, &cq_attr, &context->cq, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_cq_open with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_cq_open with err=%s", linux_device_name, fi_strerror(-rc))); goto single_fail; } - rc = fi_ep_bind(ep, (fid_t)av, 0); + rc = fi_ep_bind(ep, (fid_t) av, 0); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_ep_bind with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_ep_bind with err=%s", linux_device_name, fi_strerror(-rc))); goto single_fail; } - rc = fi_ep_bind(ep, (fid_t)context->cq, cq_flags); + rc = fi_ep_bind(ep, (fid_t) context->cq, cq_flags); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_scalable_ep_bind with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE( + ("%s failed fi_scalable_ep_bind with err=%s", linux_device_name, fi_strerror(-rc))); goto single_fail; } @@ -170,8 +128,7 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_normal(struct fi_info *info, * USE WITH SCALABLE ENDPOINT ONLY */ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, struct fid_domain *domain, - struct fid_ep *sep, - struct fid_av *av, + struct fid_ep *sep, struct fid_av *av, size_t num_contexts) { BTL_VERBOSE(("creating %zu contexts", num_contexts)); @@ -187,7 +144,7 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, mca_btl_ofi_context_t *contexts; tx_attr.op_flags = FI_DELIVERY_COMPLETE; - contexts = (mca_btl_ofi_context_t*) calloc(num_contexts, sizeof(*contexts)); + contexts = (mca_btl_ofi_context_t *) calloc(num_contexts, sizeof(*contexts)); if (NULL == contexts) { BTL_VERBOSE(("cannot allocate communication contexts.")); return NULL; @@ -201,23 +158,19 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, goto scalable_fail; } - /* bind AV to endpoint */ - rc = fi_scalable_ep_bind(sep, (fid_t)av, 0); + /* bind AV to endpoint */ + rc = fi_scalable_ep_bind(sep, (fid_t) av, 0); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_scalable_ep_bind with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE( + ("%s failed fi_scalable_ep_bind with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } - for (i=0; i < num_contexts; i++) { + for (i = 0; i < num_contexts; i++) { rc = fi_tx_context(sep, i, &tx_attr, &contexts[i].tx_ctx, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_tx_context with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE( + ("%s failed fi_tx_context with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } @@ -226,10 +179,8 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, * also nice to have equal number of tx/rx context. */ rc = fi_rx_context(sep, i, &rx_attr, &contexts[i].rx_ctx, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_rx_context with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE( + ("%s failed fi_rx_context with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } @@ -238,31 +189,23 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, cq_attr.wait_obj = FI_WAIT_NONE; rc = fi_cq_open(domain, &cq_attr, &contexts[i].cq, NULL); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_cq_open with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_cq_open with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } /* bind cq to transmit context */ - rc = fi_ep_bind(contexts[i].tx_ctx, (fid_t)contexts[i].cq, FI_TRANSMIT); + rc = fi_ep_bind(contexts[i].tx_ctx, (fid_t) contexts[i].cq, FI_TRANSMIT); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_ep_bind with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_ep_bind with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } /* bind cq to receiving context */ if (TWO_SIDED_ENABLED) { - rc = fi_ep_bind(contexts[i].rx_ctx, (fid_t)contexts[i].cq, FI_RECV); + rc = fi_ep_bind(contexts[i].rx_ctx, (fid_t) contexts[i].cq, FI_RECV); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_ep_bind with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE( + ("%s failed fi_ep_bind with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } } @@ -270,19 +213,13 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, /* enable the context. */ rc = fi_enable(contexts[i].tx_ctx); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_enable with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_enable with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } rc = fi_enable(contexts[i].rx_ctx); if (0 != rc) { - BTL_VERBOSE(("%s failed fi_enable with err=%s", - linux_device_name, - fi_strerror(-rc) - )); + BTL_VERBOSE(("%s failed fi_enable with err=%s", linux_device_name, fi_strerror(-rc))); goto scalable_fail; } @@ -300,7 +237,7 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, scalable_fail: /* close and free */ - for(i=0; i < num_contexts; i++) { + for (i = 0; i < num_contexts; i++) { mca_btl_ofi_context_finalize(&contexts[i], true); } free(contexts); @@ -308,7 +245,8 @@ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, return NULL; } -void mca_btl_ofi_context_finalize(mca_btl_ofi_context_t *context, bool scalable_ep) { +void mca_btl_ofi_context_finalize(mca_btl_ofi_context_t *context, bool scalable_ep) +{ /* if it is a scalable ep, we have to close all contexts. */ if (scalable_ep) { @@ -321,7 +259,7 @@ void mca_btl_ofi_context_finalize(mca_btl_ofi_context_t *context, bool scalable_ } } - if( NULL != context->cq) { + if (NULL != context->cq) { fi_close(&context->cq->fid); } @@ -347,12 +285,12 @@ mca_btl_ofi_context_t *get_ofi_context(mca_btl_ofi_module_t *btl) OPAL_THREAD_LOCK(&btl->module_lock); my_context = &btl->contexts[cur_num]; - cur_num = (cur_num + 1) %btl->num_contexts; + cur_num = (cur_num + 1) % btl->num_contexts; OPAL_THREAD_UNLOCK(&btl->module_lock); } - assert (my_context); + assert(my_context); return my_context; #else return get_ofi_context_rr(btl); @@ -364,10 +302,11 @@ mca_btl_ofi_context_t *get_ofi_context(mca_btl_ofi_module_t *btl) mca_btl_ofi_context_t *get_ofi_context_rr(mca_btl_ofi_module_t *btl) { static volatile uint64_t rr_num = 0; - return &btl->contexts[rr_num++%btl->num_contexts]; + return &btl->contexts[rr_num++ % btl->num_contexts]; } -int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) { +int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) +{ int ret = 0; int events_read; @@ -388,12 +327,12 @@ int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) { if (NULL != cq_entry[i].op_context) { ++events; - c_ctx = (mca_btl_ofi_completion_context_t*) cq_entry[i].op_context; + c_ctx = (mca_btl_ofi_completion_context_t *) cq_entry[i].op_context; /* We are casting to every type here just for simplicity. */ - comp = (mca_btl_ofi_base_completion_t*) c_ctx->comp; - frag_comp = (mca_btl_ofi_frag_completion_t*) c_ctx->comp; - rdma_comp = (mca_btl_ofi_rdma_completion_t*) c_ctx->comp; + comp = (mca_btl_ofi_base_completion_t *) c_ctx->comp; + frag_comp = (mca_btl_ofi_frag_completion_t *) c_ctx->comp; + rdma_comp = (mca_btl_ofi_rdma_completion_t *) c_ctx->comp; switch (comp->type) { case MCA_BTL_OFI_TYPE_GET: @@ -403,22 +342,22 @@ int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) { case MCA_BTL_OFI_TYPE_CSWAP: /* call the callback */ if (rdma_comp->cbfunc) { - rdma_comp->cbfunc (comp->btl, comp->endpoint, - rdma_comp->local_address, rdma_comp->local_handle, - rdma_comp->cbcontext, rdma_comp->cbdata, OPAL_SUCCESS); + rdma_comp->cbfunc(comp->btl, comp->endpoint, rdma_comp->local_address, + rdma_comp->local_handle, rdma_comp->cbcontext, + rdma_comp->cbdata, OPAL_SUCCESS); } - MCA_BTL_OFI_NUM_RDMA_DEC((mca_btl_ofi_module_t*) comp->btl); + MCA_BTL_OFI_NUM_RDMA_DEC((mca_btl_ofi_module_t *) comp->btl); break; case MCA_BTL_OFI_TYPE_RECV: - mca_btl_ofi_recv_frag((mca_btl_ofi_module_t*) comp->btl, - (mca_btl_ofi_endpoint_t*) comp->endpoint, - context, frag_comp->frag); + mca_btl_ofi_recv_frag((mca_btl_ofi_module_t *) comp->btl, + (mca_btl_ofi_endpoint_t *) comp->endpoint, context, + frag_comp->frag); break; case MCA_BTL_OFI_TYPE_SEND: - MCA_BTL_OFI_NUM_SEND_DEC((mca_btl_ofi_module_t*) comp->btl); + MCA_BTL_OFI_NUM_SEND_DEC((mca_btl_ofi_module_t *) comp->btl); mca_btl_ofi_frag_complete(frag_comp->frag, OPAL_SUCCESS); break; @@ -429,7 +368,7 @@ int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) { } /* return the completion handler */ - opal_free_list_return(comp->my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->my_list, (opal_free_list_item_t *) comp); } } } else if (OPAL_UNLIKELY(ret == -FI_EAVAIL)) { @@ -437,11 +376,10 @@ int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) { /* cq readerr failed!? */ if (0 > ret) { - BTL_ERROR(("%s:%d: Error returned from fi_cq_readerr: %s(%d)", - __FILE__, __LINE__, fi_strerror(-ret), ret)); + BTL_ERROR(("%s:%d: Error returned from fi_cq_readerr: %s(%d)", __FILE__, __LINE__, + fi_strerror(-ret), ret)); } else { - BTL_ERROR(("fi_cq_readerr: (provider err_code = %d)\n", - cqerr.prov_errno)); + BTL_ERROR(("fi_cq_readerr: (provider err_code = %d)\n", cqerr.prov_errno)); } MCA_BTL_OFI_ABORT(); } @@ -459,5 +397,3 @@ int mca_btl_ofi_context_progress(mca_btl_ofi_context_t *context) { return events; } - - diff --git a/opal/mca/btl/ofi/btl_ofi_endpoint.c b/opal/mca/btl/ofi/btl_ofi_endpoint.c index a374946cb00..f56a8741049 100644 --- a/opal/mca/btl/ofi/btl_ofi_endpoint.c +++ b/opal/mca/btl/ofi/btl_ofi_endpoint.c @@ -11,17 +11,17 @@ * $HEADER$ */ -#include "btl_ofi.h" #include "btl_ofi_endpoint.h" +#include "btl_ofi.h" #include "opal/util/proc.h" -static void mca_btl_ofi_endpoint_construct (mca_btl_ofi_endpoint_t *endpoint) +static void mca_btl_ofi_endpoint_construct(mca_btl_ofi_endpoint_t *endpoint) { endpoint->peer_addr = 0; OBJ_CONSTRUCT(&endpoint->ep_lock, opal_mutex_t); } -static void mca_btl_ofi_endpoint_destruct (mca_btl_ofi_endpoint_t *endpoint) +static void mca_btl_ofi_endpoint_destruct(mca_btl_ofi_endpoint_t *endpoint) { endpoint->peer_addr = 0; @@ -31,11 +31,10 @@ static void mca_btl_ofi_endpoint_destruct (mca_btl_ofi_endpoint_t *endpoint) OBJ_DESTRUCT(&endpoint->ep_lock); } -OBJ_CLASS_INSTANCE(mca_btl_ofi_endpoint_t, opal_list_item_t, - mca_btl_ofi_endpoint_construct, +OBJ_CLASS_INSTANCE(mca_btl_ofi_endpoint_t, opal_list_item_t, mca_btl_ofi_endpoint_construct, mca_btl_ofi_endpoint_destruct); -mca_btl_base_endpoint_t *mca_btl_ofi_endpoint_create (opal_proc_t *proc, struct fid_ep *ep) +mca_btl_base_endpoint_t *mca_btl_ofi_endpoint_create(opal_proc_t *proc, struct fid_ep *ep) { mca_btl_ofi_endpoint_t *endpoint = OBJ_NEW(mca_btl_ofi_endpoint_t); diff --git a/opal/mca/btl/ofi/btl_ofi_endpoint.h b/opal/mca/btl/ofi/btl_ofi_endpoint.h index af8a08d7795..e4bd17eb264 100644 --- a/opal/mca/btl/ofi/btl_ofi_endpoint.h +++ b/opal/mca/btl/ofi/btl_ofi_endpoint.h @@ -33,7 +33,7 @@ BEGIN_C_DECLS #if OPAL_HAVE_THREAD_LOCAL -extern opal_thread_local mca_btl_ofi_context_t *my_context; +extern opal_thread_local mca_btl_ofi_context_t *my_context; #endif /* OPAL_HAVE_THREAD_LOCAL */ struct mca_btl_base_endpoint_t { @@ -55,19 +55,17 @@ OBJ_CLASS_DECLARATION(mca_btl_ofi_endpoint_t); int init_context_freelists(mca_btl_ofi_context_t *context); -mca_btl_base_endpoint_t *mca_btl_ofi_endpoint_create (opal_proc_t *proc, struct fid_ep *ep); +mca_btl_base_endpoint_t *mca_btl_ofi_endpoint_create(opal_proc_t *proc, struct fid_ep *ep); /* contexts */ mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_scalable(struct fi_info *info, struct fid_domain *domain, - struct fid_ep *sep, - struct fid_av *av, + struct fid_ep *sep, struct fid_av *av, size_t num_contexts); mca_btl_ofi_context_t *mca_btl_ofi_context_alloc_normal(struct fi_info *info, struct fid_domain *domain, - struct fid_ep *ep, - struct fid_av *av); + struct fid_ep *ep, struct fid_av *av); void mca_btl_ofi_context_finalize(mca_btl_ofi_context_t *context, bool scalable_ep); mca_btl_ofi_context_t *get_ofi_context(mca_btl_ofi_module_t *btl); diff --git a/opal/mca/btl/ofi/btl_ofi_frag.c b/opal/mca/btl/ofi/btl_ofi_frag.c index 203da3197d1..9d9c3431609 100644 --- a/opal/mca/btl/ofi/btl_ofi_frag.c +++ b/opal/mca/btl/ofi/btl_ofi_frag.c @@ -12,44 +12,37 @@ * $HEADER$ */ -#include "btl_ofi.h" #include "btl_ofi_frag.h" -#include "btl_ofi_rdma.h" +#include "btl_ofi.h" #include "btl_ofi_endpoint.h" +#include "btl_ofi_rdma.h" -static void mca_btl_ofi_base_frag_constructor (mca_btl_ofi_base_frag_t *frag) +static void mca_btl_ofi_base_frag_constructor(mca_btl_ofi_base_frag_t *frag) { /* zero everything out */ - memset ((char *) frag + sizeof (frag->base), 0, sizeof (*frag) - sizeof (frag->base)); + memset((char *) frag + sizeof(frag->base), 0, sizeof(*frag) - sizeof(frag->base)); frag->base.des_segments = frag->segments; frag->base.des_segment_count = 1; } -static void mca_btl_ofi_base_frag_destructor (mca_btl_ofi_base_frag_t *frag) +static void mca_btl_ofi_base_frag_destructor(mca_btl_ofi_base_frag_t *frag) { - } -OBJ_CLASS_INSTANCE(mca_btl_ofi_base_frag_t, - mca_btl_base_descriptor_t, - mca_btl_ofi_base_frag_constructor, - mca_btl_ofi_base_frag_destructor); - -OBJ_CLASS_INSTANCE(mca_btl_ofi_frag_completion_t, - opal_free_list_item_t, - NULL, - NULL); - -mca_btl_ofi_frag_completion_t *mca_btl_ofi_frag_completion_alloc - (mca_btl_base_module_t *btl, - mca_btl_ofi_context_t *context, - mca_btl_ofi_base_frag_t *frag, - int type) +OBJ_CLASS_INSTANCE(mca_btl_ofi_base_frag_t, mca_btl_base_descriptor_t, + mca_btl_ofi_base_frag_constructor, mca_btl_ofi_base_frag_destructor); + +OBJ_CLASS_INSTANCE(mca_btl_ofi_frag_completion_t, opal_free_list_item_t, NULL, NULL); + +mca_btl_ofi_frag_completion_t *mca_btl_ofi_frag_completion_alloc(mca_btl_base_module_t *btl, + mca_btl_ofi_context_t *context, + mca_btl_ofi_base_frag_t *frag, + int type) { mca_btl_ofi_frag_completion_t *comp; - comp = (mca_btl_ofi_frag_completion_t*) opal_free_list_get(&context->frag_comp_list); + comp = (mca_btl_ofi_frag_completion_t *) opal_free_list_get(&context->frag_comp_list); comp->base.btl = btl; comp->base.my_context = context; comp->base.my_list = &context->frag_comp_list; @@ -61,13 +54,11 @@ mca_btl_ofi_frag_completion_t *mca_btl_ofi_frag_completion_alloc return comp; } - -mca_btl_base_descriptor_t *mca_btl_ofi_alloc( - mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_ofi_alloc(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, uint8_t order, + size_t size, uint32_t flags) { - mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t*) btl; + mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; mca_btl_ofi_base_frag_t *frag = NULL; mca_btl_ofi_context_t *context = get_ofi_context(ofi_btl); @@ -80,30 +71,28 @@ mca_btl_base_descriptor_t *mca_btl_ofi_alloc( frag->base.des_segment_count = 1; frag->base.des_segments = &frag->segments[0]; frag->base.des_flags = flags; - frag->base.order = order; - frag->hdr.len = size; + frag->base.order = order; + frag->hdr.len = size; } - return (mca_btl_base_descriptor_t*) frag; + return (mca_btl_base_descriptor_t *) frag; } -int mca_btl_ofi_free (mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) +int mca_btl_ofi_free(mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { /* return the frag to the free list. */ - mca_btl_ofi_frag_return ((mca_btl_ofi_base_frag_t*) des); + mca_btl_ofi_frag_return((mca_btl_ofi_base_frag_t *) des); return OPAL_SUCCESS; } -int mca_btl_ofi_send (mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t *descriptor, - mca_btl_base_tag_t tag) +int mca_btl_ofi_send(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { int rc = 0; mca_btl_ofi_context_t *context; - mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t*) btl; - mca_btl_ofi_endpoint_t *ofi_ep = (mca_btl_ofi_endpoint_t*) endpoint; - mca_btl_ofi_base_frag_t *frag = (mca_btl_ofi_base_frag_t*) descriptor; + mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; + mca_btl_ofi_endpoint_t *ofi_ep = (mca_btl_ofi_endpoint_t *) endpoint; + mca_btl_ofi_base_frag_t *frag = (mca_btl_ofi_base_frag_t *) descriptor; mca_btl_ofi_frag_completion_t *comp; frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; @@ -113,17 +102,12 @@ int mca_btl_ofi_send (mca_btl_base_module_t *btl, /* create completion context */ context = get_ofi_context(ofi_btl); - comp = mca_btl_ofi_frag_completion_alloc(btl, context, frag, - MCA_BTL_OFI_TYPE_SEND); + comp = mca_btl_ofi_frag_completion_alloc(btl, context, frag, MCA_BTL_OFI_TYPE_SEND); /* send the frag. Note that we start sending from BTL header + payload * because we need the other side to have this header information. */ - rc = fi_send(context->tx_ctx, - &frag->hdr, - sizeof(mca_btl_ofi_header_t) + frag->hdr.len, - NULL, - ofi_ep->peer_addr, - &comp->comp_ctx); + rc = fi_send(context->tx_ctx, &frag->hdr, sizeof(mca_btl_ofi_header_t) + frag->hdr.len, NULL, + ofi_ep->peer_addr, &comp->comp_ctx); if (OPAL_UNLIKELY(FI_SUCCESS != rc)) { return OPAL_ERR_OUT_OF_RESOURCE; @@ -133,14 +117,12 @@ int mca_btl_ofi_send (mca_btl_base_module_t *btl, return OPAL_SUCCESS; } -int mca_btl_ofi_recv_frag (mca_btl_ofi_module_t *ofi_btl, - mca_btl_base_endpoint_t *endpoint, - mca_btl_ofi_context_t *context, - mca_btl_ofi_base_frag_t *frag) +int mca_btl_ofi_recv_frag(mca_btl_ofi_module_t *ofi_btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_ofi_context_t *context, mca_btl_ofi_base_frag_t *frag) { int rc; mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + frag->hdr.tag; - mca_btl_base_segment_t segment = {.seg_addr.pval = (void *)(frag + 1), + mca_btl_base_segment_t segment = {.seg_addr.pval = (void *) (frag + 1), .seg_len = frag->hdr.len}; /* Tell PML where the payload is */ mca_btl_base_receive_descriptor_t recv_desc = {.endpoint = endpoint, @@ -150,11 +132,11 @@ int mca_btl_ofi_recv_frag (mca_btl_ofi_module_t *ofi_btl, .cbdata = reg->cbdata}; /* call the callback */ - reg->cbfunc (&ofi_btl->super, &recv_desc); + reg->cbfunc(&ofi_btl->super, &recv_desc); mca_btl_ofi_frag_complete(frag, OPAL_SUCCESS); /* repost the recv */ - rc = mca_btl_ofi_post_recvs((mca_btl_base_module_t*) ofi_btl, context, 1); + rc = mca_btl_ofi_post_recvs((mca_btl_base_module_t *) ofi_btl, context, 1); if (OPAL_SUCCESS != rc) { /* might not be that bad but let's just fail here. */ BTL_ERROR(("failed reposting receive.")); @@ -164,12 +146,11 @@ int mca_btl_ofi_recv_frag (mca_btl_ofi_module_t *ofi_btl, return OPAL_SUCCESS; } -struct mca_btl_base_descriptor_t *mca_btl_ofi_prepare_src ( - mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - opal_convertor_t *convertor, - uint8_t order, size_t reserve, - size_t *size, uint32_t flags) +struct mca_btl_base_descriptor_t *mca_btl_ofi_prepare_src(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, + opal_convertor_t *convertor, + uint8_t order, size_t reserve, + size_t *size, uint32_t flags) { struct iovec iov; size_t length; @@ -177,15 +158,15 @@ struct mca_btl_base_descriptor_t *mca_btl_ofi_prepare_src ( mca_btl_ofi_base_frag_t *frag; /* allocate the frag with reserve. */ - frag = (mca_btl_ofi_base_frag_t*) mca_btl_ofi_alloc(btl, endpoint, - order, reserve, flags); + frag = (mca_btl_ofi_base_frag_t *) mca_btl_ofi_alloc(btl, endpoint, order, reserve, flags); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } /* pack the data after the reserve */ iov.iov_len = *size; - iov.iov_base = (IOVBASE_TYPE*)(((unsigned char*)(frag->segments[0].seg_addr.pval)) + reserve); + iov.iov_base = (IOVBASE_TYPE *) (((unsigned char *) (frag->segments[0].seg_addr.pval)) + + reserve); opal_convertor_pack(convertor, &iov, &iov_count, &length); /* pass on frag information */ diff --git a/opal/mca/btl/ofi/btl_ofi_frag.h b/opal/mca/btl/ofi/btl_ofi_frag.h index 7e87a895b87..3afa8866265 100644 --- a/opal/mca/btl/ofi/btl_ofi_frag.h +++ b/opal/mca/btl/ofi/btl_ofi_frag.h @@ -10,59 +10,52 @@ */ #if !defined(MCA_BTL_OFI_FRAG_H) -#define MCA_BTL_OFI_FRAG_H +# define MCA_BTL_OFI_FRAG_H -#include "btl_ofi.h" -#include "btl_ofi_endpoint.h" +# include "btl_ofi.h" +# include "btl_ofi_endpoint.h" +# define MCA_BTL_OFI_HDR_SIZE sizeof(mca_btl_ofi_header_t) +# define MCA_BTL_OFI_FRAG_SIZE 4096 +# define MCA_BTL_OFI_RECV_SIZE MCA_BTL_OFI_FRAG_SIZE + MCA_BTL_OFI_HDR_SIZE -#define MCA_BTL_OFI_HDR_SIZE sizeof(mca_btl_ofi_header_t) -#define MCA_BTL_OFI_FRAG_SIZE 4096 -#define MCA_BTL_OFI_RECV_SIZE MCA_BTL_OFI_FRAG_SIZE + MCA_BTL_OFI_HDR_SIZE +# define MCA_BTL_OFI_NUM_SEND_INC(module) \ + OPAL_ATOMIC_ADD_FETCH64(&(module)->outstanding_send, 1); \ + if (module->outstanding_send > mca_btl_ofi_component.progress_threshold) { \ + mca_btl_ofi_component.super.btl_progress(); \ + } -#define MCA_BTL_OFI_NUM_SEND_INC(module) \ - OPAL_ATOMIC_ADD_FETCH64(&(module)->outstanding_send, 1); \ - if (module->outstanding_send > mca_btl_ofi_component.progress_threshold) { \ - mca_btl_ofi_component.super.btl_progress(); \ - } +# define MCA_BTL_OFI_NUM_SEND_DEC(module) \ + OPAL_ATOMIC_ADD_FETCH64(&(module)->outstanding_send, -1); + +mca_btl_base_descriptor_t *mca_btl_ofi_alloc(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, uint8_t order, + size_t size, uint32_t flags); + +int mca_btl_ofi_free(mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); + +int mca_btl_ofi_send(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag); -#define MCA_BTL_OFI_NUM_SEND_DEC(module) \ - OPAL_ATOMIC_ADD_FETCH64(&(module)->outstanding_send, -1); - -mca_btl_base_descriptor_t *mca_btl_ofi_alloc( - mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags); - -int mca_btl_ofi_free (mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); - -int mca_btl_ofi_send (mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t *descriptor, - mca_btl_base_tag_t tag); - -int mca_btl_ofi_recv_frag (mca_btl_ofi_module_t *ofi_btl, - mca_btl_base_endpoint_t *endpoint, - mca_btl_ofi_context_t *context, - mca_btl_ofi_base_frag_t *frag); - -struct mca_btl_base_descriptor_t *mca_btl_ofi_prepare_src ( - mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - opal_convertor_t *convertor, - uint8_t order, size_t reserve, - size_t *size, uint32_t flags); - -mca_btl_ofi_frag_completion_t *mca_btl_ofi_frag_completion_alloc - (mca_btl_base_module_t *btl, - mca_btl_ofi_context_t *context, - mca_btl_ofi_base_frag_t *frag, - int type); - -static inline mca_btl_ofi_base_frag_t *mca_btl_ofi_frag_alloc (mca_btl_ofi_module_t *ofi_btl, opal_free_list_t *fl, - mca_btl_base_endpoint_t *endpoint) +int mca_btl_ofi_recv_frag(mca_btl_ofi_module_t *ofi_btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_ofi_context_t *context, mca_btl_ofi_base_frag_t *frag); + +struct mca_btl_base_descriptor_t *mca_btl_ofi_prepare_src(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, + opal_convertor_t *convertor, + uint8_t order, size_t reserve, + size_t *size, uint32_t flags); + +mca_btl_ofi_frag_completion_t *mca_btl_ofi_frag_completion_alloc(mca_btl_base_module_t *btl, + mca_btl_ofi_context_t *context, + mca_btl_ofi_base_frag_t *frag, + int type); + +static inline mca_btl_ofi_base_frag_t *mca_btl_ofi_frag_alloc(mca_btl_ofi_module_t *ofi_btl, + opal_free_list_t *fl, + mca_btl_base_endpoint_t *endpoint) { - mca_btl_ofi_base_frag_t *frag = (mca_btl_ofi_base_frag_t *) opal_free_list_get (fl); + mca_btl_ofi_base_frag_t *frag = (mca_btl_ofi_base_frag_t *) opal_free_list_get(fl); if (OPAL_LIKELY(NULL != frag)) { frag->free_list = fl; @@ -73,12 +66,13 @@ static inline mca_btl_ofi_base_frag_t *mca_btl_ofi_frag_alloc (mca_btl_ofi_modul return frag; } -static inline void mca_btl_ofi_frag_return (mca_btl_ofi_base_frag_t *frag) +static inline void mca_btl_ofi_frag_return(mca_btl_ofi_base_frag_t *frag) { - opal_free_list_return (frag->free_list, &frag->base.super); + opal_free_list_return(frag->free_list, &frag->base.super); } -static inline void mca_btl_ofi_frag_complete (mca_btl_ofi_base_frag_t *frag, int rc) { +static inline void mca_btl_ofi_frag_complete(mca_btl_ofi_base_frag_t *frag, int rc) +{ mca_btl_ofi_module_t *ofi_btl = frag->btl; /* call the local callback if specified */ @@ -88,7 +82,7 @@ static inline void mca_btl_ofi_frag_complete (mca_btl_ofi_base_frag_t *frag, int /* If the BTL has ownership, return it to the free list, */ if (OPAL_LIKELY(frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { - mca_btl_ofi_frag_return (frag); + mca_btl_ofi_frag_return(frag); } } diff --git a/opal/mca/btl/ofi/btl_ofi_module.c b/opal/mca/btl/ofi/btl_ofi_module.c index b32a1f106a7..cffa0c27317 100644 --- a/opal/mca/btl/ofi/btl_ofi_module.c +++ b/opal/mca/btl/ofi/btl_ofi_module.c @@ -24,22 +24,21 @@ */ #include "opal_config.h" -#include #include "opal/class/opal_bitmap.h" -#include "opal/util/printf.h" -#include "opal/mca/btl/btl.h" #include "opal/datatype/opal_convertor.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" #include "opal/mca/mpool/mpool.h" +#include "opal/util/printf.h" +#include #include "btl_ofi.h" #include "btl_ofi_endpoint.h" #include "btl_ofi_frag.h" -static int mca_btl_ofi_add_procs (mca_btl_base_module_t *btl, - size_t nprocs, opal_proc_t **opal_procs, - mca_btl_base_endpoint_t **peers, - opal_bitmap_t *reachable) +static int mca_btl_ofi_add_procs(mca_btl_base_module_t *btl, size_t nprocs, + opal_proc_t **opal_procs, mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable) { int rc; int count; @@ -51,48 +50,51 @@ static int mca_btl_ofi_add_procs (mca_btl_base_module_t *btl, mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - for (size_t i = 0 ; i < nprocs ; ++i) { + for (size_t i = 0; i < nprocs; ++i) { proc = opal_procs[i]; /* See if we already have an endpoint for this proc. */ - rc = opal_hash_table_get_value_uint64 (&ofi_btl->id_to_endpoint, (intptr_t) proc, (void **) &ep); + rc = opal_hash_table_get_value_uint64(&ofi_btl->id_to_endpoint, (intptr_t) proc, + (void **) &ep); if (OPAL_SUCCESS == rc) { - BTL_VERBOSE(("returning existing endpoint for proc %s", OPAL_NAME_PRINT(proc->proc_name))); + BTL_VERBOSE( + ("returning existing endpoint for proc %s", OPAL_NAME_PRINT(proc->proc_name))); peers[i] = ep; } else { /* We don't have this endpoint yet, create one */ - peers[i] = mca_btl_ofi_endpoint_create (proc, ofi_btl->ofi_endpoint); - BTL_VERBOSE(("creating peer %p", (void*) peers[i])); + peers[i] = mca_btl_ofi_endpoint_create(proc, ofi_btl->ofi_endpoint); + BTL_VERBOSE(("creating peer %p", (void *) peers[i])); if (OPAL_UNLIKELY(NULL == peers[i])) { return OPAL_ERR_OUT_OF_RESOURCE; } /* Add this endpoint to the lookup table */ - (void) opal_hash_table_set_value_uint64 (&ofi_btl->id_to_endpoint, (intptr_t) proc, (void**) &ep); + (void) opal_hash_table_set_value_uint64(&ofi_btl->id_to_endpoint, (intptr_t) proc, + (void **) &ep); } - OPAL_MODEX_RECV(rc, &mca_btl_ofi_component.super.btl_version, - &peers[i]->ep_proc->proc_name, (void **)&ep_name, &namelen); + OPAL_MODEX_RECV(rc, &mca_btl_ofi_component.super.btl_version, &peers[i]->ep_proc->proc_name, + (void **) &ep_name, &namelen); if (OPAL_SUCCESS != rc) { BTL_ERROR(("error receiving modex")); MCA_BTL_OFI_ABORT(); } /* get peer fi_addr */ - count = fi_av_insert(ofi_btl->av, /* Address vector to insert */ - ep_name, /* peer name */ - 1, /* amount to insert */ + count = fi_av_insert(ofi_btl->av, /* Address vector to insert */ + ep_name, /* peer name */ + 1, /* amount to insert */ &peers[i]->peer_addr, /* return peer address here */ - 0, /* flags */ - NULL); /* context */ + 0, /* flags */ + NULL); /* context */ /* if succeed, add this proc and mark reachable */ if (count == 1) { /* we inserted 1 address. */ - opal_list_append (&ofi_btl->endpoints, &peers[i]->super); + opal_list_append(&ofi_btl->endpoints, &peers[i]->super); opal_bitmap_set_bit(reachable, i); } else { BTL_VERBOSE(("fi_av_insert failed with rc = %d", count)); @@ -103,16 +105,17 @@ static int mca_btl_ofi_add_procs (mca_btl_base_module_t *btl, return OPAL_SUCCESS; } -static int mca_btl_ofi_del_procs (mca_btl_base_module_t *btl, size_t nprocs, - opal_proc_t **procs, mca_btl_base_endpoint_t **peers) +static int mca_btl_ofi_del_procs(mca_btl_base_module_t *btl, size_t nprocs, opal_proc_t **procs, + mca_btl_base_endpoint_t **peers) { int rc; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; mca_btl_base_endpoint_t *ep; - for (size_t i = 0 ; i < nprocs ; ++i) { + for (size_t i = 0; i < nprocs; ++i) { if (peers[i]) { - rc = opal_hash_table_get_value_uint64 (&ofi_btl->id_to_endpoint, (intptr_t) procs[i], (void **) &ep); + rc = opal_hash_table_get_value_uint64(&ofi_btl->id_to_endpoint, (intptr_t) procs[i], + (void **) &ep); if (OPAL_SUCCESS == rc) { /* remove the address from AV. */ @@ -120,37 +123,37 @@ static int mca_btl_ofi_del_procs (mca_btl_base_module_t *btl, size_t nprocs, if (rc < 0) { /* remove failed. this should not happen. */ /* Lets not crash because we failed to remove an address. */ - BTL_ERROR(("fi_av_remove failed with error %d:%s", - rc, fi_strerror(-rc))); + BTL_ERROR(("fi_av_remove failed with error %d:%s", rc, fi_strerror(-rc))); } /* remove and free MPI endpoint from the list. */ - opal_list_remove_item (&ofi_btl->endpoints, &peers[i]->super); - (void) opal_hash_table_remove_value_uint64 (&ofi_btl->id_to_endpoint, (intptr_t) procs[i]); + opal_list_remove_item(&ofi_btl->endpoints, &peers[i]->super); + (void) opal_hash_table_remove_value_uint64(&ofi_btl->id_to_endpoint, + (intptr_t) procs[i]); OBJ_RELEASE(peers[i]); - } + } } } return OPAL_SUCCESS; } -void mca_btl_ofi_rcache_init (mca_btl_ofi_module_t *module) +void mca_btl_ofi_rcache_init(mca_btl_ofi_module_t *module) { if (!module->initialized) { mca_rcache_base_resources_t rcache_resources; char *tmp; - (void) opal_asprintf (&tmp, "ofi.%s", module->linux_device_name); + (void) opal_asprintf(&tmp, "ofi.%s", module->linux_device_name); - rcache_resources.cache_name = tmp; - rcache_resources.reg_data = (void *) module; - rcache_resources.sizeof_reg = sizeof (mca_btl_ofi_reg_t); - rcache_resources.register_mem = mca_btl_ofi_reg_mem; + rcache_resources.cache_name = tmp; + rcache_resources.reg_data = (void *) module; + rcache_resources.sizeof_reg = sizeof(mca_btl_ofi_reg_t); + rcache_resources.register_mem = mca_btl_ofi_reg_mem; rcache_resources.deregister_mem = mca_btl_ofi_dereg_mem; - module->rcache = mca_rcache_base_module_create ("grdma", module, &rcache_resources); - free (tmp); + module->rcache = mca_rcache_base_module_create("grdma", module, &rcache_resources); + free(tmp); if (NULL == module->rcache) { /* something when horribly wrong */ @@ -162,7 +165,6 @@ void mca_btl_ofi_rcache_init (mca_btl_ofi_module_t *module) } } - /** * @brief Register a memory region for put/get/atomic operations. * @@ -182,16 +184,17 @@ void mca_btl_ofi_rcache_init (mca_btl_ofi_module_t *module) * as they may use limited system/NIC resources. */ static struct mca_btl_base_registration_handle_t * -mca_btl_ofi_register_mem (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags) +mca_btl_ofi_register_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, + uint32_t flags) { mca_btl_ofi_module_t *ofi_module = (mca_btl_ofi_module_t *) btl; mca_btl_ofi_reg_t *reg; int access_flags = flags & MCA_BTL_REG_FLAG_ACCESS_ANY; int rc; - rc = ofi_module->rcache->rcache_register (ofi_module->rcache, base, size, 0, access_flags, - (mca_rcache_base_registration_t **) ®); + rc = ofi_module->rcache->rcache_register(ofi_module->rcache, base, size, 0, access_flags, + (mca_rcache_base_registration_t **) ®); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return NULL; } @@ -210,27 +213,28 @@ mca_btl_ofi_register_mem (struct mca_btl_base_module_t *btl, struct mca_btl_base * after it is deregistered. It is erroneous to specify a memory handle associated with * a remote node. */ -static int mca_btl_ofi_deregister_mem (mca_btl_base_module_t *btl, mca_btl_base_registration_handle_t *handle) +static int mca_btl_ofi_deregister_mem(mca_btl_base_module_t *btl, + mca_btl_base_registration_handle_t *handle) { mca_btl_ofi_module_t *ofi_module = (mca_btl_ofi_module_t *) btl; - mca_btl_ofi_reg_t *reg = - (mca_btl_ofi_reg_t *)((intptr_t) handle - offsetof (mca_btl_ofi_reg_t, handle)); + mca_btl_ofi_reg_t *reg = (mca_btl_ofi_reg_t *) ((intptr_t) handle + - offsetof(mca_btl_ofi_reg_t, handle)); - (void) ofi_module->rcache->rcache_deregister (ofi_module->rcache, ®->base); + (void) ofi_module->rcache->rcache_deregister(ofi_module->rcache, ®->base); return OPAL_SUCCESS; } -int mca_btl_ofi_reg_mem (void *reg_data, void *base, size_t size, mca_rcache_base_registration_t *reg) +int mca_btl_ofi_reg_mem(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg) { int rc; static uint64_t access_flags = FI_REMOTE_WRITE | FI_REMOTE_READ | FI_READ | FI_WRITE; - mca_btl_ofi_module_t *btl = (mca_btl_ofi_module_t*) reg_data; - mca_btl_ofi_reg_t *ur = (mca_btl_ofi_reg_t*) reg; + mca_btl_ofi_module_t *btl = (mca_btl_ofi_module_t *) reg_data; + mca_btl_ofi_reg_t *ur = (mca_btl_ofi_reg_t *) reg; - rc = fi_mr_reg(btl->domain, base, size, access_flags, 0, - (uint64_t) reg, 0, &ur->ur_mr, NULL); + rc = fi_mr_reg(btl->domain, base, size, access_flags, 0, (uint64_t) reg, 0, &ur->ur_mr, NULL); if (0 != rc) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -250,14 +254,14 @@ int mca_btl_ofi_reg_mem (void *reg_data, void *base, size_t size, mca_rcache_bas return OPAL_SUCCESS; } -int mca_btl_ofi_dereg_mem (void *reg_data, mca_rcache_base_registration_t *reg) +int mca_btl_ofi_dereg_mem(void *reg_data, mca_rcache_base_registration_t *reg) { - mca_btl_ofi_reg_t *ur = (mca_btl_ofi_reg_t*)reg; + mca_btl_ofi_reg_t *ur = (mca_btl_ofi_reg_t *) reg; if (ur->ur_mr != NULL) { if (0 != fi_close(&ur->ur_mr->fid)) { - BTL_ERROR(("%s: error unpinning memory mr=%p: %s", - __func__, (void*) ur->ur_mr, strerror(errno))); + BTL_ERROR(("%s: error unpinning memory mr=%p: %s", __func__, (void *) ur->ur_mr, + strerror(errno))); return OPAL_ERROR; } } @@ -269,7 +273,7 @@ int mca_btl_ofi_dereg_mem (void *reg_data, mca_rcache_base_registration_t *reg) * Cleanup/release module resources. */ -int mca_btl_ofi_finalize (mca_btl_base_module_t* btl) +int mca_btl_ofi_finalize(mca_btl_base_module_t *btl) { int i; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; @@ -279,7 +283,7 @@ int mca_btl_ofi_finalize (mca_btl_base_module_t* btl) /* clear the rcache */ if (ofi_btl->rcache) { - mca_rcache_base_module_destroy (ofi_btl->rcache); + mca_rcache_base_module_destroy(ofi_btl->rcache); ofi_btl->rcache = NULL; } @@ -290,7 +294,7 @@ int mca_btl_ofi_finalize (mca_btl_base_module_t* btl) } /* loop over all the contexts */ - for (i=0; i < ofi_btl->num_contexts; i++) { + for (i = 0; i < ofi_btl->num_contexts; i++) { mca_btl_ofi_context_finalize(&ofi_btl->contexts[i], ofi_btl->is_scalable_ep); } free(ofi_btl->contexts); @@ -317,8 +321,8 @@ int mca_btl_ofi_finalize (mca_btl_base_module_t* btl) } /* clean up any leftover endpoints */ - OPAL_LIST_FOREACH_SAFE(endpoint, next, &ofi_btl->endpoints, mca_btl_ofi_endpoint_t) { - opal_list_remove_item (&ofi_btl->endpoints, &endpoint->super); + OPAL_LIST_FOREACH_SAFE (endpoint, next, &ofi_btl->endpoints, mca_btl_ofi_endpoint_t) { + opal_list_remove_item(&ofi_btl->endpoints, &endpoint->super); OBJ_RELEASE(endpoint); } @@ -326,39 +330,31 @@ int mca_btl_ofi_finalize (mca_btl_base_module_t* btl) OBJ_DESTRUCT(&ofi_btl->id_to_endpoint); OBJ_DESTRUCT(&ofi_btl->module_lock); - free (btl); + free(btl); return OPAL_SUCCESS; } /* Post wildcard recvs on the rx context. */ -int mca_btl_ofi_post_recvs (mca_btl_base_module_t *module, - mca_btl_ofi_context_t *context, - int count) +int mca_btl_ofi_post_recvs(mca_btl_base_module_t *module, mca_btl_ofi_context_t *context, int count) { int i; int rc; mca_btl_ofi_base_frag_t *frag; mca_btl_ofi_frag_completion_t *comp; - for (i=0; i < count; i++) { - frag = (mca_btl_ofi_base_frag_t*) mca_btl_ofi_alloc(module, - NULL, - 0, - MCA_BTL_OFI_FRAG_SIZE, - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); + for (i = 0; i < count; i++) { + frag = (mca_btl_ofi_base_frag_t *) mca_btl_ofi_alloc(module, NULL, 0, MCA_BTL_OFI_FRAG_SIZE, + MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); if (NULL == frag) { BTL_ERROR(("cannot allocate recv frag.")); return OPAL_ERROR; } - comp = mca_btl_ofi_frag_completion_alloc (module, - context, - frag, - MCA_BTL_OFI_TYPE_RECV); + comp = mca_btl_ofi_frag_completion_alloc(module, context, frag, MCA_BTL_OFI_TYPE_RECV); - rc = fi_recv (context->rx_ctx, &frag->hdr, MCA_BTL_OFI_RECV_SIZE, - NULL, FI_ADDR_UNSPEC, &comp->comp_ctx); + rc = fi_recv(context->rx_ctx, &frag->hdr, MCA_BTL_OFI_RECV_SIZE, NULL, FI_ADDR_UNSPEC, + &comp->comp_ctx); if (FI_SUCCESS != rc) { BTL_ERROR(("cannot post recvs")); @@ -369,12 +365,12 @@ int mca_btl_ofi_post_recvs (mca_btl_base_module_t *module, } /* Allocate and fill out the module capabilities according to operation mode. */ -mca_btl_ofi_module_t * mca_btl_ofi_module_alloc (int mode) +mca_btl_ofi_module_t *mca_btl_ofi_module_alloc(int mode) { mca_btl_ofi_module_t *module; /* allocate module */ - module = (mca_btl_ofi_module_t*) calloc(1, sizeof(mca_btl_ofi_module_t)); + module = (mca_btl_ofi_module_t *) calloc(1, sizeof(mca_btl_ofi_module_t)); if (NULL == module) { return NULL; } @@ -384,24 +380,22 @@ mca_btl_ofi_module_t * mca_btl_ofi_module_alloc (int mode) if (mode == MCA_BTL_OFI_MODE_ONE_SIDED || mode == MCA_BTL_OFI_MODE_FULL_SUPPORT) { - module->super.btl_put = mca_btl_ofi_put; - module->super.btl_get = mca_btl_ofi_get; - module->super.btl_atomic_op = mca_btl_ofi_aop; - module->super.btl_atomic_fop = mca_btl_ofi_afop; - module->super.btl_atomic_cswap = mca_btl_ofi_acswap; - module->super.btl_flush = mca_btl_ofi_flush; + module->super.btl_put = mca_btl_ofi_put; + module->super.btl_get = mca_btl_ofi_get; + module->super.btl_atomic_op = mca_btl_ofi_aop; + module->super.btl_atomic_fop = mca_btl_ofi_afop; + module->super.btl_atomic_cswap = mca_btl_ofi_acswap; + module->super.btl_flush = mca_btl_ofi_flush; - module->super.btl_register_mem = mca_btl_ofi_register_mem; + module->super.btl_register_mem = mca_btl_ofi_register_mem; module->super.btl_deregister_mem = mca_btl_ofi_deregister_mem; - module->super.btl_flags |= MCA_BTL_FLAGS_ATOMIC_FOPS | - MCA_BTL_FLAGS_ATOMIC_OPS | - MCA_BTL_FLAGS_RDMA; + module->super.btl_flags |= MCA_BTL_FLAGS_ATOMIC_FOPS | MCA_BTL_FLAGS_ATOMIC_OPS + | MCA_BTL_FLAGS_RDMA; - module->super.btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_ADD | - MCA_BTL_ATOMIC_SUPPORTS_SWAP | - MCA_BTL_ATOMIC_SUPPORTS_CSWAP | - MCA_BTL_ATOMIC_SUPPORTS_32BIT ; + module->super.btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_ADD | MCA_BTL_ATOMIC_SUPPORTS_SWAP + | MCA_BTL_ATOMIC_SUPPORTS_CSWAP + | MCA_BTL_ATOMIC_SUPPORTS_32BIT; module->super.btl_put_limit = 1 << 23; module->super.btl_put_alignment = 0; @@ -409,26 +403,25 @@ mca_btl_ofi_module_t * mca_btl_ofi_module_alloc (int mode) module->super.btl_get_limit = 1 << 23; module->super.btl_get_alignment = 0; - module->super.btl_registration_handle_size = - sizeof(mca_btl_base_registration_handle_t); + module->super.btl_registration_handle_size = sizeof(mca_btl_base_registration_handle_t); } if (mode == MCA_BTL_OFI_MODE_TWO_SIDED || mode == MCA_BTL_OFI_MODE_FULL_SUPPORT) { - module->super.btl_alloc = mca_btl_ofi_alloc; - module->super.btl_free = mca_btl_ofi_free; - module->super.btl_prepare_src = mca_btl_ofi_prepare_src; + module->super.btl_alloc = mca_btl_ofi_alloc; + module->super.btl_free = mca_btl_ofi_free; + module->super.btl_prepare_src = mca_btl_ofi_prepare_src; - module->super.btl_send = mca_btl_ofi_send; + module->super.btl_send = mca_btl_ofi_send; - module->super.btl_flags |= MCA_BTL_FLAGS_SEND; - module->super.btl_eager_limit = MCA_BTL_OFI_FRAG_SIZE; - module->super.btl_max_send_size = MCA_BTL_OFI_FRAG_SIZE; + module->super.btl_flags |= MCA_BTL_FLAGS_SEND; + module->super.btl_eager_limit = MCA_BTL_OFI_FRAG_SIZE; + module->super.btl_max_send_size = MCA_BTL_OFI_FRAG_SIZE; module->super.btl_rndv_eager_limit = MCA_BTL_OFI_FRAG_SIZE; /* If two sided is enabled, we expected that the user knows exactly what * they want. We bump the priority to maximum, making this BTL the default. */ - module->super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH; + module->super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH; } if (mode == MCA_BTL_OFI_MODE_FULL_SUPPORT) { @@ -441,9 +434,8 @@ mca_btl_ofi_module_t * mca_btl_ofi_module_alloc (int mode) mca_btl_ofi_module_t mca_btl_ofi_module_template = { .super = { - .btl_component = &mca_btl_ofi_component.super, - .btl_add_procs = mca_btl_ofi_add_procs, - .btl_del_procs = mca_btl_ofi_del_procs, - .btl_finalize = mca_btl_ofi_finalize, - } -}; + .btl_component = &mca_btl_ofi_component.super, + .btl_add_procs = mca_btl_ofi_add_procs, + .btl_del_procs = mca_btl_ofi_del_procs, + .btl_finalize = mca_btl_ofi_finalize, + }}; diff --git a/opal/mca/btl/ofi/btl_ofi_rdma.c b/opal/mca/btl/ofi/btl_ofi_rdma.c index f2728e36dc0..8c5e5197261 100644 --- a/opal/mca/btl/ofi/btl_ofi_rdma.c +++ b/opal/mca/btl/ofi/btl_ofi_rdma.c @@ -13,20 +13,14 @@ #include "btl_ofi_rdma.h" -OBJ_CLASS_INSTANCE(mca_btl_ofi_rdma_completion_t, - opal_free_list_item_t, - NULL, - NULL); - -mca_btl_ofi_rdma_completion_t *mca_btl_ofi_rdma_completion_alloc ( - mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - mca_btl_ofi_context_t *ofi_context, - void *local_address, - mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata, - int type) +OBJ_CLASS_INSTANCE(mca_btl_ofi_rdma_completion_t, opal_free_list_item_t, NULL, NULL); + +mca_btl_ofi_rdma_completion_t * +mca_btl_ofi_rdma_completion_alloc(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_ofi_context_t *ofi_context, void *local_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata, int type) { assert(btl); assert(endpoint); @@ -34,7 +28,7 @@ mca_btl_ofi_rdma_completion_t *mca_btl_ofi_rdma_completion_alloc ( mca_btl_ofi_rdma_completion_t *comp; - comp = (mca_btl_ofi_rdma_completion_t*) opal_free_list_get(&ofi_context->rdma_comp_list); + comp = (mca_btl_ofi_rdma_completion_t *) opal_free_list_get(&ofi_context->rdma_comp_list); assert(comp); comp->base.btl = btl; @@ -54,46 +48,42 @@ mca_btl_ofi_rdma_completion_t *mca_btl_ofi_rdma_completion_alloc ( return comp; } -int mca_btl_ofi_get (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ofi_get(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { int rc; mca_btl_ofi_rdma_completion_t *comp; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint; + mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t *) endpoint; mca_btl_ofi_context_t *ofi_context; ofi_context = get_ofi_context(ofi_btl); /* create completion context */ - comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, - ofi_context, - local_address, - local_handle, - cbfunc, cbcontext, cbdata, + comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, ofi_context, local_address, + local_handle, cbfunc, cbcontext, cbdata, MCA_BTL_OFI_TYPE_GET); remote_address = (remote_address - (uint64_t) remote_handle->base_addr); /* Remote write data across the wire */ - rc = fi_read(ofi_context->tx_ctx, - local_address, size, /* payload */ - local_handle->desc, - btl_endpoint->peer_addr, - remote_address, remote_handle->rkey, - &comp->comp_ctx); /* completion context */ + rc = fi_read(ofi_context->tx_ctx, local_address, size, /* payload */ + local_handle->desc, btl_endpoint->peer_addr, remote_address, remote_handle->rkey, + &comp->comp_ctx); /* completion context */ if (-FI_EAGAIN == rc) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); return OPAL_ERR_OUT_OF_RESOURCE; } if (0 != rc) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); BTL_ERROR(("fi_read failed with %d:%s", rc, fi_strerror(-rc))); MCA_BTL_OFI_ABORT(); } @@ -103,44 +93,40 @@ int mca_btl_ofi_get (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoi return OPAL_SUCCESS; } -int mca_btl_ofi_put (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ofi_put(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { int rc; mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint; + mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t *) endpoint; mca_btl_ofi_context_t *ofi_context; ofi_context = get_ofi_context(ofi_btl); /* create completion context */ mca_btl_ofi_rdma_completion_t *comp; - comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, - ofi_context, - local_address, - local_handle, - cbfunc, cbcontext, cbdata, + comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint, ofi_context, local_address, + local_handle, cbfunc, cbcontext, cbdata, MCA_BTL_OFI_TYPE_PUT); remote_address = (remote_address - (uint64_t) remote_handle->base_addr); /* Remote write data across the wire */ - rc = fi_write(ofi_context->tx_ctx, - local_address, size, /* payload */ - local_handle->desc, - btl_endpoint->peer_addr, - remote_address, remote_handle->rkey, - &comp->comp_ctx); /* completion context */ + rc = fi_write(ofi_context->tx_ctx, local_address, size, /* payload */ + local_handle->desc, btl_endpoint->peer_addr, remote_address, remote_handle->rkey, + &comp->comp_ctx); /* completion context */ if (-FI_EAGAIN == rc) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); return OPAL_ERR_OUT_OF_RESOURCE; } if (0 != rc) { - opal_free_list_return(comp->base.my_list, (opal_free_list_item_t*) comp); + opal_free_list_return(comp->base.my_list, (opal_free_list_item_t *) comp); BTL_ERROR(("fi_write failed with %d:%s", rc, fi_strerror(-rc))); MCA_BTL_OFI_ABORT(); } @@ -148,14 +134,13 @@ int mca_btl_ofi_put (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoi MCA_BTL_OFI_NUM_RDMA_INC(ofi_btl); return OPAL_SUCCESS; - } -int mca_btl_ofi_flush (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint) +int mca_btl_ofi_flush(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint) { mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl; - while(ofi_btl->outstanding_rdma > 0) { + while (ofi_btl->outstanding_rdma > 0) { (void) mca_btl_ofi_component.super.btl_progress(); } diff --git a/opal/mca/btl/ofi/btl_ofi_rdma.h b/opal/mca/btl/ofi/btl_ofi_rdma.h index b4e1965081e..0091f7d398a 100644 --- a/opal/mca/btl/ofi/btl_ofi_rdma.h +++ b/opal/mca/btl/ofi/btl_ofi_rdma.h @@ -19,24 +19,19 @@ #include "btl_ofi.h" #include "btl_ofi_endpoint.h" -mca_btl_ofi_rdma_completion_t *mca_btl_ofi_rdma_completion_alloc ( - mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - mca_btl_ofi_context_t *ofi_context, - void *local_address, - mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata, - int type); +mca_btl_ofi_rdma_completion_t * +mca_btl_ofi_rdma_completion_alloc(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_ofi_context_t *ofi_context, void *local_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata, int type); -#define MCA_BTL_OFI_NUM_RDMA_INC(module) \ - OPAL_THREAD_ADD_FETCH64(&(module)->outstanding_rdma, 1); \ - if (module->outstanding_rdma > mca_btl_ofi_component.progress_threshold){ \ - mca_btl_ofi_component.super.btl_progress(); \ - } +#define MCA_BTL_OFI_NUM_RDMA_INC(module) \ + OPAL_THREAD_ADD_FETCH64(&(module)->outstanding_rdma, 1); \ + if (module->outstanding_rdma > mca_btl_ofi_component.progress_threshold) { \ + mca_btl_ofi_component.super.btl_progress(); \ + } -#define MCA_BTL_OFI_NUM_RDMA_DEC(module) \ - OPAL_THREAD_ADD_FETCH64(&(module)->outstanding_rdma, -1); +#define MCA_BTL_OFI_NUM_RDMA_DEC(module) OPAL_THREAD_ADD_FETCH64(&(module)->outstanding_rdma, -1); #endif /* !defined(BTL_OFI_RDMA_H) */ - diff --git a/opal/mca/btl/portals4/btl_portals4.c b/opal/mca/btl/portals4/btl_portals4.c index bf63bef119f..2827a96782b 100644 --- a/opal/mca/btl/portals4/btl_portals4.c +++ b/opal/mca/btl/portals4/btl_portals4.c @@ -24,119 +24,113 @@ #include "opal_config.h" +#include "opal_stdint.h" +#include #include #include -#include -#include "opal_stdint.h" #include "opal/class/opal_bitmap.h" #include "opal/constants.h" -#include "opal/mca/btl/btl.h" #include "opal/datatype/opal_convertor.h" -#include "opal/util/proc.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/pmix/pmix-internal.h" +#include "opal/util/proc.h" #include "btl_portals4.h" #include "btl_portals4_recv.h" - -mca_btl_base_registration_handle_t * -mca_btl_portals4_register_mem(mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - void *base, - size_t size, - uint32_t flags); +mca_btl_base_registration_handle_t *mca_btl_portals4_register_mem(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, + void *base, size_t size, + uint32_t flags); int mca_btl_portals4_deregister_mem(mca_btl_base_module_t *btl, mca_btl_base_registration_handle_t *handle); mca_btl_portals4_module_t mca_btl_portals4_module = { - .super = { - .btl_component = &mca_btl_portals4_component.super, - - /* NOTE: All the default values are set in - component_open() */ - - .btl_add_procs = mca_btl_portals4_add_procs, - .btl_del_procs = mca_btl_portals4_del_procs, - .btl_finalize = mca_btl_portals4_finalize, - .btl_alloc = mca_btl_portals4_alloc, - .btl_free = mca_btl_portals4_free, - .btl_prepare_src = mca_btl_portals4_prepare_src, - .btl_register_mem = mca_btl_portals4_register_mem, - .btl_deregister_mem = mca_btl_portals4_deregister_mem, - .btl_send = mca_btl_portals4_send, - .btl_get = mca_btl_portals4_get, - .btl_dump = mca_btl_base_dump, - }, + .super = + { + .btl_component = &mca_btl_portals4_component.super, + + /* NOTE: All the default values are set in + component_open() */ + + .btl_add_procs = mca_btl_portals4_add_procs, + .btl_del_procs = mca_btl_portals4_del_procs, + .btl_finalize = mca_btl_portals4_finalize, + .btl_alloc = mca_btl_portals4_alloc, + .btl_free = mca_btl_portals4_free, + .btl_prepare_src = mca_btl_portals4_prepare_src, + .btl_register_mem = mca_btl_portals4_register_mem, + .btl_deregister_mem = mca_btl_portals4_deregister_mem, + .btl_send = mca_btl_portals4_send, + .btl_get = mca_btl_portals4_get, + .btl_dump = mca_btl_base_dump, + }, }; -static int -btl_portals4_init_interface(void) +static int btl_portals4_init_interface(void) { mca_btl_portals4_module_t *portals4_btl; unsigned int ret, interface; ptl_md_t md; ptl_me_t me; -// The initialisation of EQ, PT and ME must be done after the SetMap ! - for (interface=0; interfaceportals_ni_h, - mca_btl_portals4_component.recv_queue_size, - &portals4_btl->recv_eq_h); + ret = PtlEQAlloc(portals4_btl->portals_ni_h, mca_btl_portals4_component.recv_queue_size, + &portals4_btl->recv_eq_h); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlEQAlloc failed for NI %d: %d", - __FILE__, __LINE__, interface, ret); + "%s:%d: PtlEQAlloc failed for NI %d: %d", __FILE__, __LINE__, + interface, ret); goto error; } mca_btl_portals4_component.eqs_h[interface] = portals4_btl->recv_eq_h; OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PtlEQAlloc (recv_eq=%d) OK for NI %d\n", portals4_btl->recv_eq_h, interface)); + "PtlEQAlloc (recv_eq=%d) OK for NI %d\n", portals4_btl->recv_eq_h, + interface)); /* Create recv_idx portal table entry */ - ret = PtlPTAlloc(portals4_btl->portals_ni_h, - PTL_PT_ONLY_TRUNCATE, - portals4_btl->recv_eq_h, - REQ_BTL_TABLE_ID, - &portals4_btl->recv_idx); + ret = PtlPTAlloc(portals4_btl->portals_ni_h, PTL_PT_ONLY_TRUNCATE, portals4_btl->recv_eq_h, + REQ_BTL_TABLE_ID, &portals4_btl->recv_idx); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlPTAlloc failed for NI %d: %d", - __FILE__, __LINE__, interface, ret); + "%s:%d: PtlPTAlloc failed for NI %d: %d", __FILE__, __LINE__, + interface, ret); goto error; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PtlPTAlloc (recv_idx) OK for NI %d recv_idx=%d", interface, portals4_btl->recv_idx)); + "PtlPTAlloc (recv_idx) OK for NI %d recv_idx=%d", interface, + portals4_btl->recv_idx)); if (portals4_btl->recv_idx != REQ_BTL_TABLE_ID) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlPTAlloc did not allocate the requested PT: %d", - __FILE__, __LINE__, portals4_btl->recv_idx); + "%s:%d: PtlPTAlloc did not allocate the requested PT: %d", __FILE__, + __LINE__, portals4_btl->recv_idx); goto error; } /* bind zero-length md for sending acks */ - md.start = NULL; - md.length = 0; - md.options = 0; + md.start = NULL; + md.length = 0; + md.options = 0; md.eq_handle = PTL_EQ_NONE; md.ct_handle = PTL_CT_NONE; - ret = PtlMDBind(portals4_btl->portals_ni_h, - &md, - &portals4_btl->zero_md_h); + ret = PtlMDBind(portals4_btl->portals_ni_h, &md, &portals4_btl->zero_md_h); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlMDBind failed for NI %d: %d", - __FILE__, __LINE__, interface, ret); + "%s:%d: PtlMDBind failed for NI %d: %d", __FILE__, __LINE__, + interface, ret); goto error; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PtlMDBind (zero-length md=%d) OK for NI %d", portals4_btl->zero_md_h, interface)); + "PtlMDBind (zero-length md=%d) OK for NI %d", portals4_btl->zero_md_h, + interface)); /* Bind MD across all memory */ md.start = 0; @@ -145,13 +139,11 @@ btl_portals4_init_interface(void) md.eq_handle = portals4_btl->recv_eq_h; md.ct_handle = PTL_CT_NONE; - ret = PtlMDBind(portals4_btl->portals_ni_h, - &md, - &portals4_btl->send_md_h); + ret = PtlMDBind(portals4_btl->portals_ni_h, &md, &portals4_btl->send_md_h); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlMDBind failed for NI %d: %d\n", - __FILE__, __LINE__, interface, ret); + "%s:%d: PtlMDBind failed for NI %d: %d\n", __FILE__, __LINE__, + interface, ret); goto error; } @@ -161,10 +153,8 @@ btl_portals4_init_interface(void) me.ct_handle = PTL_CT_NONE; me.min_free = 0; me.uid = PTL_UID_ANY; - me.options = PTL_ME_OP_PUT | - PTL_ME_EVENT_LINK_DISABLE | - PTL_ME_EVENT_COMM_DISABLE | - PTL_ME_EVENT_UNLINK_DISABLE; + me.options = PTL_ME_OP_PUT | PTL_ME_EVENT_LINK_DISABLE | PTL_ME_EVENT_COMM_DISABLE + | PTL_ME_EVENT_UNLINK_DISABLE; if (mca_btl_portals4_component.use_logical) { me.match_id.rank = PTL_RANK_ANY; } else { @@ -172,81 +162,80 @@ btl_portals4_init_interface(void) me.match_id.phys.pid = PTL_PID_ANY; } me.match_bits = BTL_PORTALS4_LONG_MSG; - me.ignore_bits = BTL_PORTALS4_CONTEXT_MASK | - BTL_PORTALS4_SOURCE_MASK | - BTL_PORTALS4_TAG_MASK; - ret = PtlMEAppend(portals4_btl->portals_ni_h, - portals4_btl->recv_idx, - &me, - PTL_OVERFLOW_LIST, - NULL, - &portals4_btl->long_overflow_me_h); + me.ignore_bits = BTL_PORTALS4_CONTEXT_MASK | BTL_PORTALS4_SOURCE_MASK + | BTL_PORTALS4_TAG_MASK; + ret = PtlMEAppend(portals4_btl->portals_ni_h, portals4_btl->recv_idx, &me, + PTL_OVERFLOW_LIST, NULL, &portals4_btl->long_overflow_me_h); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlMEAppend failed for NI %d: %d", - __FILE__, __LINE__, interface, ret); + "%s:%d: PtlMEAppend failed for NI %d: %d", __FILE__, __LINE__, + interface, ret); goto error; } - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlMEAppend (overflow list) OK for NI %d", interface)); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "PtlMEAppend (overflow list) OK for NI %d", interface)); } ret = mca_btl_portals4_recv_enable(portals4_btl); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: Initialization of recv buffer failed: %d", - __FILE__, __LINE__, ret); + "%s:%d: Initialization of recv buffer failed: %d", __FILE__, __LINE__, + ret); goto error; } return OPAL_SUCCESS; - error: - opal_output_verbose(1, opal_btl_base_framework.framework_output, "Error in btl_portals4_init_interface"); +error: + opal_output_verbose(1, opal_btl_base_framework.framework_output, + "Error in btl_portals4_init_interface"); - for (interface=0; interfaceproc_name, (void**) &id, &size); + OPAL_MODEX_RECV(ret, &mca_btl_portals4_component.super.btl_version, &proc->proc_name, + (void **) &id, &size); if (OPAL_ERR_NOT_FOUND == ret) { OPAL_OUTPUT_VERBOSE((30, opal_btl_base_framework.framework_output, - "btl/portals4: Portals 4 BTL not available on peer: %s", opal_strerror(ret))); + "btl/portals4: Portals 4 BTL not available on peer: %s", + opal_strerror(ret))); return ret; } else if (OPAL_SUCCESS != ret) { opal_output_verbose(0, opal_btl_base_framework.framework_output, - "btl/portals4: opal_modex_recv failed: %s", opal_strerror(ret)); + "btl/portals4: opal_modex_recv failed: %s", opal_strerror(ret)); return ret; } - if (size < sizeof(ptl_process_t)) { /* no available connection */ + if (size < sizeof(ptl_process_t)) { /* no available connection */ return OPAL_ERROR; } if ((size % sizeof(ptl_process_t)) != 0) { opal_output_verbose(0, opal_btl_base_framework.framework_output, - "btl/portals4: invalid format in modex"); + "btl/portals4: invalid format in modex"); return OPAL_ERROR; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "btl/portals4: %d NI(s) declared in the modex", (int) (size/sizeof(ptl_process_t)))); + "btl/portals4: %d NI(s) declared in the modex", + (int) (size / sizeof(ptl_process_t)))); *endpoint = malloc(sizeof(mca_btl_base_endpoint_t)); if (NULL == *endpoint) { @@ -258,38 +247,37 @@ create_endpoint(int interface, return OPAL_SUCCESS; } -static int -create_peer_and_endpoint(int interface, - opal_proc_t *proc, - ptl_process_t *phys_peer, - mca_btl_base_endpoint_t **endpoint) +static int create_peer_and_endpoint(int interface, opal_proc_t *proc, ptl_process_t *phys_peer, + mca_btl_base_endpoint_t **endpoint) { int ret; size_t size; ptl_process_t *id; - OPAL_MODEX_RECV(ret, &mca_btl_portals4_component.super.btl_version, - &proc->proc_name, (void**) &id, &size); + OPAL_MODEX_RECV(ret, &mca_btl_portals4_component.super.btl_version, &proc->proc_name, + (void **) &id, &size); if (OPAL_ERR_NOT_FOUND == ret) { OPAL_OUTPUT_VERBOSE((30, opal_btl_base_framework.framework_output, - "btl/portals4: Portals 4 BTL not available on peer: %s", opal_strerror(ret))); + "btl/portals4: Portals 4 BTL not available on peer: %s", + opal_strerror(ret))); return ret; } else if (OPAL_SUCCESS != ret) { opal_output_verbose(0, opal_btl_base_framework.framework_output, - "btl/portals4: opal_modex_recv failed: %s", opal_strerror(ret)); + "btl/portals4: opal_modex_recv failed: %s", opal_strerror(ret)); return ret; } - if (size < sizeof(ptl_process_t)) { /* no available connection */ + if (size < sizeof(ptl_process_t)) { /* no available connection */ return OPAL_ERROR; } if ((size % sizeof(ptl_process_t)) != 0) { opal_output_verbose(0, opal_btl_base_framework.framework_output, - "btl/portals4: invalid format in modex"); + "btl/portals4: invalid format in modex"); return OPAL_ERROR; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "btl/portals4: %d NI(s) declared in the modex", (int) (size/sizeof(ptl_process_t)))); + "btl/portals4: %d NI(s) declared in the modex", + (int) (size / sizeof(ptl_process_t)))); /* * check if create_endpoint() already created the endpoint. @@ -310,30 +298,26 @@ create_peer_and_endpoint(int interface, phys_peer->phys.pid = id[interface].phys.pid; phys_peer->phys.nid = id[interface].phys.nid; opal_output_verbose(50, opal_btl_base_framework.framework_output, - "logical: global rank=%d pid=%d nid=%d\n", - proc->proc_name.vpid, phys_peer->phys.pid, phys_peer->phys.nid); + "logical: global rank=%d pid=%d nid=%d\n", proc->proc_name.vpid, + phys_peer->phys.pid, phys_peer->phys.nid); return OPAL_SUCCESS; } -static int -create_maptable(struct mca_btl_portals4_module_t *portals4_btl, - size_t nprocs, - opal_proc_t **procs, - mca_btl_base_endpoint_t **endpoint) +static int create_maptable(struct mca_btl_portals4_module_t *portals4_btl, size_t nprocs, + opal_proc_t **procs, mca_btl_base_endpoint_t **endpoint) { int ret; ptl_process_t *maptable; maptable = malloc(sizeof(ptl_process_t) * nprocs); if (NULL == maptable) { - opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: malloc failed\n", + opal_output_verbose(1, opal_btl_base_framework.framework_output, "%s:%d: malloc failed\n", __FILE__, __LINE__); return OPAL_ERR_OUT_OF_RESOURCE; } - for (uint32_t i = 0 ; i < nprocs ; i++) { + for (uint32_t i = 0; i < nprocs; i++) { struct opal_proc_t *curr_proc; curr_proc = procs[i]; @@ -343,15 +327,13 @@ create_maptable(struct mca_btl_portals4_module_t *portals4_btl, opal_output_verbose(1, opal_btl_base_framework.framework_output, "Portals 4 BTL does not support heterogeneous operations."); opal_output_verbose(1, opal_btl_base_framework.framework_output, - "Proc %s architecture %x, mine %x.", - OPAL_NAME_PRINT(curr_proc->proc_name), - curr_proc->proc_arch, opal_proc_local_get()->proc_arch); + "Proc %s architecture %x, mine %x.", + OPAL_NAME_PRINT(curr_proc->proc_name), curr_proc->proc_arch, + opal_proc_local_get()->proc_arch); return OPAL_ERR_NOT_SUPPORTED; } - ret = create_peer_and_endpoint(portals4_btl->interface_num, - curr_proc, - &maptable[i], + ret = create_peer_and_endpoint(portals4_btl->interface_num, curr_proc, &maptable[i], &endpoint[i]); if (OPAL_SUCCESS != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, @@ -361,17 +343,13 @@ create_maptable(struct mca_btl_portals4_module_t *portals4_btl, } } - ret = PtlSetMap(portals4_btl->portals_ni_h, - nprocs, - maptable); + ret = PtlSetMap(portals4_btl->portals_ni_h, nprocs, maptable); if (OPAL_SUCCESS != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: logical mapping failed: %d\n", - __FILE__, __LINE__, ret); + "%s:%d: logical mapping failed: %d\n", __FILE__, __LINE__, ret); return ret; } - opal_output_verbose(90, opal_btl_base_framework.framework_output, - "logical mapping OK\n"); + opal_output_verbose(90, opal_btl_base_framework.framework_output, "logical mapping OK\n"); free(maptable); return OPAL_SUCCESS; @@ -379,28 +357,24 @@ create_maptable(struct mca_btl_portals4_module_t *portals4_btl, #define NEED_ALL_PROCS (mca_btl_portals4_component.use_logical) -int -mca_btl_portals4_add_procs(struct mca_btl_base_module_t* btl_base, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** btl_peer_data, - opal_bitmap_t* reachable) +int mca_btl_portals4_add_procs(struct mca_btl_base_module_t *btl_base, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **btl_peer_data, + opal_bitmap_t *reachable) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; int ret; size_t i; opal_output_verbose(50, opal_btl_base_framework.framework_output, - "mca_btl_portals4_add_procs: Adding %d procs (%d) for NI %d", - (int) nprocs, - (int) portals4_btl->portals_num_procs, - portals4_btl->interface_num); + "mca_btl_portals4_add_procs: Adding %d procs (%d) for NI %d", (int) nprocs, + (int) portals4_btl->portals_num_procs, portals4_btl->interface_num); /* * The PML handed us a list of procs that need Portals4 * peer info. Complete those procs here. */ - for (i = 0 ; i < nprocs ; ++i) { + for (i = 0; i < nprocs; ++i) { struct opal_proc_t *curr_proc = procs[i]; /* portals doesn't support heterogeneous yet... */ @@ -408,35 +382,32 @@ mca_btl_portals4_add_procs(struct mca_btl_base_module_t* btl_base, opal_output_verbose(1, opal_btl_base_framework.framework_output, "Portals 4 BTL does not support heterogeneous operations."); opal_output_verbose(1, opal_btl_base_framework.framework_output, - "Proc %s architecture %x, mine %x.", - OPAL_NAME_PRINT(curr_proc->proc_name), - curr_proc->proc_arch, opal_proc_local_get()->proc_arch); + "Proc %s architecture %x, mine %x.", + OPAL_NAME_PRINT(curr_proc->proc_name), curr_proc->proc_arch, + opal_proc_local_get()->proc_arch); return OPAL_ERR_NOT_SUPPORTED; } - ret = create_endpoint(portals4_btl->interface_num, - curr_proc, - &btl_peer_data[i]); + ret = create_endpoint(portals4_btl->interface_num, curr_proc, &btl_peer_data[i]); OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_num_procs, 1); /* and here we can reach */ opal_bitmap_set_bit(reachable, i); OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "add_procs: rank=%lx nid=%x pid=%x for NI %d", - i, - btl_peer_data[i]->ptl_proc.phys.nid, - btl_peer_data[i]->ptl_proc.phys.pid, - portals4_btl->interface_num)); + "add_procs: rank=%lx nid=%x pid=%x for NI %d", i, + btl_peer_data[i]->ptl_proc.phys.nid, + btl_peer_data[i]->ptl_proc.phys.pid, portals4_btl->interface_num)); } if (mca_btl_portals4_component.need_init && portals4_btl->portals_num_procs > 0) { if (mca_btl_portals4_component.use_logical) { ret = create_maptable(portals4_btl, nprocs, procs, btl_peer_data); if (OPAL_SUCCESS != ret) { - opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: mca_btl_portals4_add_procs::create_maptable() failed: %d\n", - __FILE__, __LINE__, ret); + opal_output_verbose( + 1, opal_btl_base_framework.framework_output, + "%s:%d: mca_btl_portals4_add_procs::create_maptable() failed: %d\n", __FILE__, + __LINE__, ret); return ret; } } @@ -444,8 +415,8 @@ mca_btl_portals4_add_procs(struct mca_btl_base_module_t* btl_base, ret = btl_portals4_init_interface(); if (OPAL_SUCCESS != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: portals4 interface initialization failed: %d", - __FILE__, __LINE__, ret); + "%s:%d: portals4 interface initialization failed: %d", __FILE__, + __LINE__, ret); return ret; } mca_btl_portals4_component.need_init = 0; @@ -454,14 +425,11 @@ mca_btl_portals4_add_procs(struct mca_btl_base_module_t* btl_base, return OPAL_SUCCESS; } - -int -mca_btl_portals4_del_procs(struct mca_btl_base_module_t *btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **btl_peer_data) +int mca_btl_portals4_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **btl_peer_data) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl; size_t i; opal_output_verbose(50, opal_btl_base_framework.framework_output, @@ -470,7 +438,7 @@ mca_btl_portals4_del_procs(struct mca_btl_base_module_t *btl, /* See comment in btl_portals4_endpoint.h about why we look at the portals4 entry in proc_endpoints instead of the peer_data */ - for (i = 0 ; i < nprocs ; ++i) { + for (i = 0; i < nprocs; ++i) { free(btl_peer_data[i]); OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_num_procs, -1); } @@ -478,26 +446,25 @@ mca_btl_portals4_del_procs(struct mca_btl_base_module_t *btl, return OPAL_SUCCESS; } -mca_btl_base_descriptor_t* -mca_btl_portals4_alloc(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_portals4_alloc(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; - mca_btl_portals4_frag_t* frag; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; + mca_btl_portals4_frag_t *frag; if (size <= portals4_btl->super.btl_eager_limit) { OPAL_BTL_PORTALS4_FRAG_ALLOC_EAGER(portals4_btl, frag); - if (NULL == frag) return NULL; + if (NULL == frag) + return NULL; frag->segments[0].base.seg_len = size; } else { OPAL_BTL_PORTALS4_FRAG_ALLOC_MAX(portals4_btl, frag); - if (NULL == frag) return NULL; - frag->segments[0].base.seg_len = - size <= portals4_btl->super.btl_max_send_size ? - size : portals4_btl->super.btl_max_send_size ; + if (NULL == frag) + return NULL; + frag->segments[0].base.seg_len = size <= portals4_btl->super.btl_max_send_size + ? size + : portals4_btl->super.btl_max_send_size; } frag->base.des_segment_count = 1; @@ -505,16 +472,14 @@ mca_btl_portals4_alloc(struct mca_btl_base_module_t* btl_base, frag->base.order = MCA_BTL_NO_ORDER; OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_alloc: %p\n", (void *) &frag->base)); + "mca_btl_portals4_alloc: %p\n", (void *) &frag->base)); return &frag->base; } -int -mca_btl_portals4_free(struct mca_btl_base_module_t* btl_base, - mca_btl_base_descriptor_t* des) +int mca_btl_portals4_free(struct mca_btl_base_module_t *btl_base, mca_btl_base_descriptor_t *des) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; - mca_btl_portals4_frag_t* frag = (mca_btl_portals4_frag_t*) des; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; + mca_btl_portals4_frag_t *frag = (mca_btl_portals4_frag_t *) des; if (BTL_PORTALS4_FRAG_TYPE_EAGER == frag->type) { /* don't ever unlink eager frags */ @@ -532,7 +497,8 @@ mca_btl_portals4_free(struct mca_btl_base_module_t* btl_base, } OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_free: Decrementing portals_outstanding_ops=%d\n", portals4_btl->portals_outstanding_ops)); + "mca_btl_portals4_free: Decrementing portals_outstanding_ops=%d\n", + portals4_btl->portals_outstanding_ops)); OPAL_BTL_PORTALS4_FRAG_RETURN_USER(portals4_btl, frag); } else { return OPAL_ERR_BAD_PARAM; @@ -549,29 +515,29 @@ mca_btl_portals4_free(struct mca_btl_base_module_t* btl_base, * @param peer (IN) BTL peer addressing */ -mca_btl_base_descriptor_t* -mca_btl_portals4_prepare_src(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* peer, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_portals4_prepare_src(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *peer, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; - mca_btl_portals4_frag_t* frag; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; + mca_btl_portals4_frag_t *frag; size_t max_data = *size; struct iovec iov; uint32_t iov_count = 1; int ret; OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_prepare_src NI=%d reserve=%ld size=%ld max_data=%ld\n", portals4_btl->interface_num, reserve, *size, max_data)); + "mca_btl_portals4_prepare_src NI=%d reserve=%ld size=%ld max_data=%ld\n", + portals4_btl->interface_num, reserve, *size, max_data)); if (0 != reserve || 0 != opal_convertor_need_buffers(convertor)) { - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "mca_btl_portals4_prepare_src NEED BUFFERS or RESERVE\n")); - frag = (mca_btl_portals4_frag_t*) mca_btl_portals4_alloc(btl_base, peer, MCA_BTL_NO_ORDER, max_data + reserve, flags); - if (NULL == frag) { + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "mca_btl_portals4_prepare_src NEED BUFFERS or RESERVE\n")); + frag = (mca_btl_portals4_frag_t *) mca_btl_portals4_alloc(btl_base, peer, MCA_BTL_NO_ORDER, + max_data + reserve, flags); + if (NULL == frag) { return NULL; } @@ -579,10 +545,10 @@ mca_btl_portals4_prepare_src(struct mca_btl_base_module_t* btl_base, max_data = frag->size - reserve; } iov.iov_len = max_data; - iov.iov_base = (unsigned char*) frag->segments[0].base.seg_addr.pval + reserve; - ret = opal_convertor_pack(convertor, &iov, &iov_count, &max_data ); + iov.iov_base = (unsigned char *) frag->segments[0].base.seg_addr.pval + reserve; + ret = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); - *size = max_data; + *size = max_data; if (ret < 0) { mca_btl_portals4_free(btl_base, (mca_btl_base_descriptor_t *) frag); return NULL; @@ -598,19 +564,18 @@ mca_btl_portals4_prepare_src(struct mca_btl_base_module_t* btl_base, return &frag->base; } -mca_btl_base_registration_handle_t * -mca_btl_portals4_register_mem(mca_btl_base_module_t *btl_base, - mca_btl_base_endpoint_t *endpoint, - void *base, - size_t size, - uint32_t flags) +mca_btl_base_registration_handle_t *mca_btl_portals4_register_mem(mca_btl_base_module_t *btl_base, + mca_btl_base_endpoint_t *endpoint, + void *base, size_t size, + uint32_t flags) { - struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; mca_btl_base_registration_handle_t *handle = NULL; ptl_me_t me; int ret; - handle = (mca_btl_base_registration_handle_t *)malloc(sizeof(mca_btl_base_registration_handle_t)); + handle = (mca_btl_base_registration_handle_t *) malloc( + sizeof(mca_btl_base_registration_handle_t)); if (!handle) { return NULL; } @@ -618,9 +583,10 @@ mca_btl_portals4_register_mem(mca_btl_base_module_t *btl_base, handle->key = OPAL_THREAD_ADD_FETCH64(&(portals4_btl->portals_rdma_key), 1); handle->remote_offset = 0; - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_register_mem NI=%d base=%p size=%ld handle=%p key=%ld flags=%d", - portals4_btl->interface_num, base, size, (void *)handle, handle->key, flags)); + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, + "mca_btl_portals4_register_mem NI=%d base=%p size=%ld handle=%p key=%ld flags=%d", + portals4_btl->interface_num, base, size, (void *) handle, handle->key, flags)); /* create a match entry */ me.start = base; @@ -628,10 +594,8 @@ mca_btl_portals4_register_mem(mca_btl_base_module_t *btl_base, me.ct_handle = PTL_CT_NONE; me.min_free = 0; me.uid = PTL_UID_ANY; - me.options = PTL_ME_OP_GET | - PTL_ME_EVENT_LINK_DISABLE | - PTL_ME_EVENT_COMM_DISABLE | - PTL_ME_EVENT_UNLINK_DISABLE; + me.options = PTL_ME_OP_GET | PTL_ME_EVENT_LINK_DISABLE | PTL_ME_EVENT_COMM_DISABLE + | PTL_ME_EVENT_UNLINK_DISABLE; if (mca_btl_portals4_component.use_logical) { me.match_id.rank = endpoint->ptl_proc.rank; @@ -640,47 +604,41 @@ mca_btl_portals4_register_mem(mca_btl_base_module_t *btl_base, me.match_id.phys.pid = endpoint->ptl_proc.phys.pid; } me.match_bits = handle->key; - me.ignore_bits = BTL_PORTALS4_PROTOCOL_MASK | - BTL_PORTALS4_CONTEXT_MASK | - BTL_PORTALS4_SOURCE_MASK; + me.ignore_bits = BTL_PORTALS4_PROTOCOL_MASK | BTL_PORTALS4_CONTEXT_MASK + | BTL_PORTALS4_SOURCE_MASK; me.ignore_bits = 0; - ret = PtlMEAppend(portals4_btl->portals_ni_h, - portals4_btl->recv_idx, - &me, - PTL_PRIORITY_LIST, - handle, - &(handle->me_h)); + ret = PtlMEAppend(portals4_btl->portals_ni_h, portals4_btl->recv_idx, &me, PTL_PRIORITY_LIST, + handle, &(handle->me_h)); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlMEAppend failed: %d\n", - __FILE__, __LINE__, ret); + "%s:%d: PtlMEAppend failed: %d\n", __FILE__, __LINE__, ret); OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); return NULL; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PtlMEAppend (mca_btl_portals4_register_mem) handle=%p, me_h=%d start=%p length=%ld rank=%x nid=%x pid=%x match_bits=%lx\n", - (void *)handle, handle->me_h, me.start, me.length, - me.match_id.rank, me.match_id.phys.nid, me.match_id.phys.pid, me.match_bits)); + "PtlMEAppend (mca_btl_portals4_register_mem) handle=%p, me_h=%d start=%p " + "length=%ld rank=%x nid=%x pid=%x match_bits=%lx\n", + (void *) handle, handle->me_h, me.start, me.length, me.match_id.rank, + me.match_id.phys.nid, me.match_id.phys.pid, me.match_bits)); return handle; } -int -mca_btl_portals4_deregister_mem(mca_btl_base_module_t *btl_base, - mca_btl_base_registration_handle_t *handle) +int mca_btl_portals4_deregister_mem(mca_btl_base_module_t *btl_base, + mca_btl_base_registration_handle_t *handle) { int ret; - struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_deregister_mem NI=%d handle=%p key=%ld me_h=%d\n", - portals4_btl->interface_num, (void *)handle, handle->key, handle->me_h)); + "mca_btl_portals4_deregister_mem NI=%d handle=%p key=%ld me_h=%d\n", + portals4_btl->interface_num, (void *) handle, handle->key, handle->me_h)); if (!PtlHandleIsEqual(handle->me_h, PTL_INVALID_HANDLE)) { ret = PtlMEUnlink(handle->me_h); - if (PTL_OK != ret) { + if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlMEUnlink failed: %d\n",__FILE__, __LINE__, ret); + "%s:%d: PtlMEUnlink failed: %d\n", __FILE__, __LINE__, ret); return OPAL_ERROR; } handle->me_h = PTL_INVALID_HANDLE; @@ -691,10 +649,9 @@ mca_btl_portals4_deregister_mem(mca_btl_base_module_t *btl_base, return OPAL_SUCCESS; } -int -mca_btl_portals4_finalize(struct mca_btl_base_module_t *btl) +int mca_btl_portals4_finalize(struct mca_btl_base_module_t *btl) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl; mca_btl_portals4_free_module(portals4_btl); @@ -706,7 +663,7 @@ mca_btl_portals4_finalize(struct mca_btl_base_module_t *btl) free(portals4_btl); OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_finalize NI %d: OK\n", portals4_btl->interface_num)); + "mca_btl_portals4_finalize NI %d: OK\n", portals4_btl->interface_num)); return OPAL_SUCCESS; } @@ -716,18 +673,20 @@ void mca_btl_portals4_free_module(mca_btl_portals4_module_t *portals4_btl) int ret; OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_free_module portals_outstanding_ops=%d\n", portals4_btl->portals_outstanding_ops)); + "mca_btl_portals4_free_module portals_outstanding_ops=%d\n", + portals4_btl->portals_outstanding_ops)); /* sanity check */ - assert(portals4_btl->portals_outstanding_ops >= 0); + assert(portals4_btl->portals_outstanding_ops >= 0); /* finalize all communication */ while (portals4_btl->portals_outstanding_ops > 0) { OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_free_module portals_outstanding_ops: %d", - portals4_btl->portals_outstanding_ops)); + "mca_btl_portals4_free_module portals_outstanding_ops: %d", + portals4_btl->portals_outstanding_ops)); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "Call to mca_btl_portals4_component_progress (3)\n")); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "Call to mca_btl_portals4_component_progress (3)\n")); mca_btl_portals4_component_progress(); } @@ -747,25 +706,33 @@ void mca_btl_portals4_free_module(mca_btl_portals4_module_t *portals4_btl) if ((ptl_pt_index_t) ~0UL != mca_btl_portals4_module.recv_idx) { PtlPTFree(portals4_btl->portals_ni_h, portals4_btl->recv_idx); - portals4_btl->recv_idx= (ptl_pt_index_t) ~0UL; + portals4_btl->recv_idx = (ptl_pt_index_t) ~0UL; } if (PTL_EQ_NONE != portals4_btl->recv_eq_h) { ret = PtlEQFree(portals4_btl->recv_eq_h); - if (PTL_OK != ret) OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "Error freeing EQ recv: %d", ret)); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlEQFree: recv_eq_h=%d portals4_btl=%p", - portals4_btl->recv_eq_h, (void*)portals4_btl)); + if (PTL_OK != ret) + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, "Error freeing EQ recv: %d", ret)); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "PtlEQFree: recv_eq_h=%d portals4_btl=%p", portals4_btl->recv_eq_h, + (void *) portals4_btl)); portals4_btl->recv_eq_h = PTL_EQ_NONE; } if (!PtlHandleIsEqual(portals4_btl->portals_ni_h, PTL_INVALID_HANDLE)) { ret = PtlNIFini(portals4_btl->portals_ni_h); - if (PTL_OK != ret) OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "Error returned by PtlNIFini: %d\n", ret)); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlNIFini: portals_ni_h=%d portals4_btl=%p", - portals4_btl->portals_ni_h, (void*)portals4_btl)); + if (PTL_OK != ret) + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "Error returned by PtlNIFini: %d\n", ret)); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "PtlNIFini: portals_ni_h=%d portals4_btl=%p", + portals4_btl->portals_ni_h, (void *) portals4_btl)); portals4_btl->portals_ni_h = PTL_INVALID_HANDLE; } ret = mca_btl_portals4_recv_disable(portals4_btl); - if (PTL_OK != ret) OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "Error freeing recv list: %d", ret)); + if (PTL_OK != ret) + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, "Error freeing recv list: %d", ret)); } diff --git a/opal/mca/btl/portals4/btl_portals4.h b/opal/mca/btl/portals4/btl_portals4.h index 41e7da7a743..14dd0a20cd7 100644 --- a/opal/mca/btl/portals4/btl_portals4.h +++ b/opal/mca/btl/portals4/btl_portals4.h @@ -24,15 +24,15 @@ #ifndef BTL_PORTALS_H_HAS_BEEN_INCLUDED #define BTL_PORTALS_H_HAS_BEEN_INCLUDED -#include #include +#include #include "opal/class/opal_free_list.h" #include "opal/class/opal_list.h" #include "opal/datatype/opal_convertor.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" #include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" BEGIN_C_DECLS @@ -46,9 +46,10 @@ struct mca_btl_portals4_component_t { unsigned int num_btls; unsigned int max_btls; /* Maximum number of accepted Portals4 cards */ - struct mca_btl_portals4_module_t** btls; /* array of available BTL modules */ + struct mca_btl_portals4_module_t **btls; /* array of available BTL modules */ - /* add_procs() can get called multiple times. this prevents multiple calls to portals4_init_interface(). */ + /* add_procs() can get called multiple times. this prevents multiple calls to + * portals4_init_interface(). */ int need_init; /* Use the logical to physical table to accelerate portals4 adressing: 1 (true) : 0 (false) */ @@ -145,111 +146,86 @@ typedef struct mca_btl_portals4_module_t mca_btl_portals4_module_t; * +---- protocol */ -#define BTL_PORTALS4_PROTOCOL_MASK 0xF000000000000000ULL -#define BTL_PORTALS4_CONTEXT_MASK 0x0FFF000000000000ULL -#define BTL_PORTALS4_SOURCE_MASK 0x0000FFFF00000000ULL -#define BTL_PORTALS4_TAG_MASK 0x00000000FFFFFFFFULL +#define BTL_PORTALS4_PROTOCOL_MASK 0xF000000000000000ULL +#define BTL_PORTALS4_CONTEXT_MASK 0x0FFF000000000000ULL +#define BTL_PORTALS4_SOURCE_MASK 0x0000FFFF00000000ULL +#define BTL_PORTALS4_TAG_MASK 0x00000000FFFFFFFFULL -#define BTL_PORTALS4_PROTOCOL_IGNR BTL_PORTALS4_PROTOCOL_MASK -#define BTL_PORTALS4_CONTEXT_IGNR BTL_PORTALS4_CONTEXT_MASK -#define BTL_PORTALS4_SOURCE_IGNR BTL_PORTALS4_SOURCE_MASK -#define BTL_PORTALS4_TAG_IGNR 0x000000007FFFFFFFULL +#define BTL_PORTALS4_PROTOCOL_IGNR BTL_PORTALS4_PROTOCOL_MASK +#define BTL_PORTALS4_CONTEXT_IGNR BTL_PORTALS4_CONTEXT_MASK +#define BTL_PORTALS4_SOURCE_IGNR BTL_PORTALS4_SOURCE_MASK +#define BTL_PORTALS4_TAG_IGNR 0x000000007FFFFFFFULL -#define BTL_PORTALS4_SHORT_MSG 0x1000000000000000ULL -#define BTL_PORTALS4_LONG_MSG 0x2000000000000000ULL +#define BTL_PORTALS4_SHORT_MSG 0x1000000000000000ULL +#define BTL_PORTALS4_LONG_MSG 0x2000000000000000ULL /* send posting */ #define BTL_PORTALS4_SET_SEND_BITS(match_bits, contextid, source, tag, type) \ - { \ - match_bits = contextid; \ - match_bits = (match_bits << 16); \ - match_bits |= source; \ - match_bits = (match_bits << 32); \ - match_bits |= (BTL_PORTALS4_TAG_MASK & tag) | type; \ + { \ + match_bits = contextid; \ + match_bits = (match_bits << 16); \ + match_bits |= source; \ + match_bits = (match_bits << 32); \ + match_bits |= (BTL_PORTALS4_TAG_MASK & tag) | type; \ } -#define BTL_PORTALS4_SET_HDR_DATA(hdr_data, opcount, length, sync) \ - { \ - hdr_data = (sync) ? 1 : 0; \ - hdr_data = (hdr_data << 15); \ - hdr_data |= opcount & 0x7FFFULL; \ - hdr_data = (hdr_data << 48); \ - hdr_data |= (length & 0xFFFFFFFFFFFFULL); \ +#define BTL_PORTALS4_SET_HDR_DATA(hdr_data, opcount, length, sync) \ + { \ + hdr_data = (sync) ? 1 : 0; \ + hdr_data = (hdr_data << 15); \ + hdr_data |= opcount & 0x7FFFULL; \ + hdr_data = (hdr_data << 48); \ + hdr_data |= (length & 0xFFFFFFFFFFFFULL); \ } -#define REQ_BTL_TABLE_ID 2 +#define REQ_BTL_TABLE_ID 2 int mca_btl_portals4_component_progress(void); void mca_btl_portals4_free_module(mca_btl_portals4_module_t *portals4_btl); /* BTL interface functions */ -int mca_btl_portals4_finalize(struct mca_btl_base_module_t* btl_base); - - -int mca_btl_portals4_add_procs(struct mca_btl_base_module_t* btl_base, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers, - opal_bitmap_t* reachable); - -int mca_btl_portals4_del_procs(struct mca_btl_base_module_t* btl_base, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers); - -mca_btl_base_descriptor_t* -mca_btl_portals4_alloc(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags); - -int mca_btl_portals4_free(struct mca_btl_base_module_t* btl_base, - mca_btl_base_descriptor_t* des); - -mca_btl_base_descriptor_t* -mca_btl_portals4_prepare_src(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* peer, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags); - -int mca_btl_portals4_send(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* btl_peer, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag); - - -int mca_btl_portals4_sendi(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - void* header, - size_t header_size, - size_t payload_size, - uint8_t order, - uint32_t flags, - mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t** des); - -int mca_btl_portals4_put(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* btl_peer, - struct mca_btl_base_descriptor_t* decriptor); - - -int mca_btl_portals4_get(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* btl_peer, - void *local_address, - uint64_t remote_address, - struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, - size_t size, - int flags, - int order, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, - void *cbdata); +int mca_btl_portals4_finalize(struct mca_btl_base_module_t *btl_base); + +int mca_btl_portals4_add_procs(struct mca_btl_base_module_t *btl_base, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable); + +int mca_btl_portals4_del_procs(struct mca_btl_base_module_t *btl_base, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers); + +mca_btl_base_descriptor_t *mca_btl_portals4_alloc(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags); + +int mca_btl_portals4_free(struct mca_btl_base_module_t *btl_base, mca_btl_base_descriptor_t *des); + +mca_btl_base_descriptor_t *mca_btl_portals4_prepare_src(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *peer, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags); + +int mca_btl_portals4_send(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *btl_peer, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag); + +int mca_btl_portals4_sendi(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, + mca_btl_base_tag_t tag, mca_btl_base_descriptor_t **des); + +int mca_btl_portals4_put(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *btl_peer, + struct mca_btl_base_descriptor_t *decriptor); + +int mca_btl_portals4_get(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *btl_peer, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata); int mca_btl_portals4_get_error(int ptl_error); @@ -281,4 +257,4 @@ typedef struct mca_btl_base_endpoint_t mca_btl_base_endpoint_t; END_C_DECLS -#endif /* BTL_PORTALS_H_HAS_BEEN_INCLUDED */ +#endif /* BTL_PORTALS_H_HAS_BEEN_INCLUDED */ diff --git a/opal/mca/btl/portals4/btl_portals4_component.c b/opal/mca/btl/portals4/btl_portals4_component.c index 06b1312aed6..697728073e2 100644 --- a/opal/mca/btl/portals4/btl_portals4_component.c +++ b/opal/mca/btl/portals4/btl_portals4_component.c @@ -27,202 +27,148 @@ #include "opal_config.h" +#include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" +#include "opal/mca/mpool/base/base.h" +#include "opal/mca/pmix/pmix-internal.h" #include "opal/util/event.h" #include "opal/util/output.h" -#include "opal/mca/pmix/pmix-internal.h" #include "opal/util/show_help.h" -#include "opal/mca/btl/btl.h" -#include "opal/mca/btl/base/base.h" -#include "opal/mca/mpool/base/base.h" -#include "portals4.h" #include "btl_portals4.h" #include "btl_portals4_frag.h" #include "btl_portals4_recv.h" +#include "portals4.h" static int mca_btl_portals4_component_register(void); static int mca_btl_portals4_component_open(void); static int mca_btl_portals4_component_close(void); -static mca_btl_base_module_t** mca_btl_portals4_component_init(int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads); +static mca_btl_base_module_t **mca_btl_portals4_component_init(int *num_btls, + bool enable_progress_threads, + bool enable_mpi_threads); int mca_btl_portals4_component_progress(void); OPAL_MODULE_DECLSPEC extern mca_btl_portals4_component_t mca_btl_portals4_component; -mca_btl_portals4_component_t mca_btl_portals4_component = { - { - /* First, the mca_base_module_t struct containing meta - information about the module itself */ - .btl_version = { - MCA_BTL_DEFAULT_VERSION("portals4"), - .mca_open_component = mca_btl_portals4_component_open, - .mca_close_component = mca_btl_portals4_component_close, - .mca_register_component_params = mca_btl_portals4_component_register, - }, - .btl_data = { - /* The component is not checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_NONE - }, - - .btl_init = mca_btl_portals4_component_init, - .btl_progress = mca_btl_portals4_component_progress, - } -}; - -static int -mca_btl_portals4_component_register(void) +mca_btl_portals4_component_t mca_btl_portals4_component = {{ + /* First, the mca_base_module_t struct containing meta + information about the module itself */ + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("portals4"), + .mca_open_component = mca_btl_portals4_component_open, + .mca_close_component = mca_btl_portals4_component_close, + .mca_register_component_params = mca_btl_portals4_component_register, + }, + .btl_data = + {/* The component is not checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_NONE}, + + .btl_init = mca_btl_portals4_component_init, + .btl_progress = mca_btl_portals4_component_progress, +}}; + +static int mca_btl_portals4_component_register(void) { mca_btl_portals4_component.use_logical = 0; - (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "use_logical", - "Use the logical to physical table to accelerate portals4 adressing: 1 (true) : 0 (false)", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_portals4_component.use_logical); + (void) mca_base_component_var_register( + &mca_btl_portals4_component.super.btl_version, "use_logical", + "Use the logical to physical table to accelerate portals4 adressing: 1 (true) : 0 (false)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_portals4_component.use_logical); mca_btl_portals4_component.max_btls = 1; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "max_btls", - "Maximum number of accepted Portals4 cards", - MCA_BASE_VAR_TYPE_UNSIGNED_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_btl_portals4_component.max_btls); + "max_btls", "Maximum number of accepted Portals4 cards", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, + OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_portals4_component.max_btls); mca_btl_portals4_component.portals_free_list_init_num = 16; - (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "free_list_init_num", - "Initial number of elements to initialize in free lists", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_free_list_init_num)); + (void) + mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, + "free_list_init_num", + "Initial number of elements to initialize in free lists", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_free_list_init_num)); mca_btl_portals4_component.portals_free_list_max_num = 1024; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "free_list_max_num", - "Max number of elements to initialize in free lists", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_free_list_max_num)); + "free_list_max_num", + "Max number of elements to initialize in free lists", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_free_list_max_num)); mca_btl_portals4_component.portals_free_list_inc_num = 16; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "free_list_inc_num", - "Increment count for free lists", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_free_list_inc_num)); + "free_list_inc_num", "Increment count for free lists", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_free_list_inc_num)); mca_btl_portals4_component.portals_free_list_eager_max_num = 32; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "eager_frag_limit", - "Maximum number of pre-pinned eager fragments", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_free_list_eager_max_num)); - - mca_btl_portals4_component.portals_need_ack = 1; /* default to true.. */ + "eager_frag_limit", + "Maximum number of pre-pinned eager fragments", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component + .portals_free_list_eager_max_num)); + + mca_btl_portals4_component.portals_need_ack = 1; /* default to true.. */ (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "needs_ack", - "Require a portals level ACK", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_need_ack)); + "needs_ack", "Require a portals level ACK", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_need_ack)); mca_btl_portals4_component.recv_queue_size = 4 * 1024; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "eq_recv_size", - "Size of the receive event queue", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.recv_queue_size)); + "eq_recv_size", "Size of the receive event queue", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.recv_queue_size)); mca_btl_portals4_component.portals_max_outstanding_ops = 8 * 1024; - (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "max_pending_ops", - "Maximum number of pending send/rdma frags", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_max_outstanding_ops)); + (void) + mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, + "max_pending_ops", + "Maximum number of pending send/rdma frags", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_max_outstanding_ops)); mca_btl_portals4_component.portals_recv_mds_num = 8; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "recv_md_num", - "Number of send frag receive descriptors", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_recv_mds_num)); + "recv_md_num", "Number of send frag receive descriptors", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_recv_mds_num)); mca_btl_portals4_component.portals_recv_mds_size = 256 * 1024; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "recv_md_size", - "Size of send frag receive descriptors", - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_recv_mds_size)); + "recv_md_size", "Size of send frag receive descriptors", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_recv_mds_size)); mca_btl_portals4_component.portals_max_msg_size = PTL_SIZE_MAX; (void) mca_base_component_var_register(&mca_btl_portals4_component.super.btl_version, - "max_msg_size", - "Max size supported by portals4 (above that, a message is cut into messages less than that size)", - MCA_BASE_VAR_TYPE_UNSIGNED_LONG, - NULL, - 0, - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &(mca_btl_portals4_component.portals_max_msg_size)); + "max_msg_size", + "Max size supported by portals4 (above that, a message " + "is cut into messages less than that size)", + MCA_BASE_VAR_TYPE_UNSIGNED_LONG, NULL, 0, 0, + OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &(mca_btl_portals4_component.portals_max_msg_size)); return OPAL_SUCCESS; } -static int -mca_btl_portals4_component_open(void) +static int mca_btl_portals4_component_open(void) { - OPAL_OUTPUT_VERBOSE((1, opal_btl_base_framework.framework_output, "mca_btl_portals4_component_open\n")); + OPAL_OUTPUT_VERBOSE( + (1, opal_btl_base_framework.framework_output, "mca_btl_portals4_component_open\n")); /* * fill default module state @@ -231,22 +177,25 @@ mca_btl_portals4_component_open(void) mca_btl_portals4_module.super.btl_eager_limit = 32 * 1024; mca_btl_portals4_module.super.btl_rndv_eager_limit = 32 * 1024; mca_btl_portals4_module.super.btl_max_send_size = 64 * 1024; - if (mca_btl_portals4_module.super.btl_max_send_size > mca_btl_portals4_component.portals_max_msg_size) - mca_btl_portals4_module.super.btl_max_send_size = mca_btl_portals4_component.portals_max_msg_size; + if (mca_btl_portals4_module.super.btl_max_send_size + > mca_btl_portals4_component.portals_max_msg_size) + mca_btl_portals4_module.super.btl_max_send_size = mca_btl_portals4_component + .portals_max_msg_size; mca_btl_portals4_module.super.btl_rdma_pipeline_send_length = 64 * 1024; mca_btl_portals4_module.super.btl_rdma_pipeline_frag_size = INT_MAX; mca_btl_portals4_module.super.btl_min_rdma_pipeline_size = 0; - mca_btl_portals4_module.super.btl_flags = - MCA_BTL_FLAGS_RDMA | - MCA_BTL_FLAGS_RDMA_MATCHED | - MCA_BTL_FLAGS_SEND; + mca_btl_portals4_module.super.btl_flags = MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_RDMA_MATCHED + | MCA_BTL_FLAGS_SEND; - mca_btl_portals4_module.super.btl_registration_handle_size = sizeof (mca_btl_base_registration_handle_t); + mca_btl_portals4_module.super.btl_registration_handle_size = sizeof( + mca_btl_base_registration_handle_t); mca_btl_portals4_module.super.btl_get_limit = SIZE_MAX; - if (mca_btl_portals4_module.super.btl_get_limit > mca_btl_portals4_component.portals_max_msg_size) - mca_btl_portals4_module.super.btl_get_limit = mca_btl_portals4_component.portals_max_msg_size; - mca_btl_portals4_module.super.btl_put_limit = 0; /* not implemented */ + if (mca_btl_portals4_module.super.btl_get_limit + > mca_btl_portals4_component.portals_max_msg_size) + mca_btl_portals4_module.super.btl_get_limit = mca_btl_portals4_component + .portals_max_msg_size; + mca_btl_portals4_module.super.btl_put_limit = 0; /* not implemented */ mca_btl_portals4_module.super.btl_get_alignment = 0; mca_btl_portals4_module.super.btl_put_alignment = 0; @@ -256,7 +205,8 @@ mca_btl_portals4_component_open(void) mca_btl_portals4_module.super.btl_bandwidth = 1000; mca_btl_portals4_module.super.btl_latency = 0; - mca_btl_base_param_register(&mca_btl_portals4_component.super.btl_version, &mca_btl_portals4_module.super); + mca_btl_base_param_register(&mca_btl_portals4_component.super.btl_version, + &mca_btl_portals4_module.super); mca_btl_portals4_module.portals_num_procs = 0; @@ -283,19 +233,20 @@ mca_btl_portals4_component_open(void) return OPAL_SUCCESS; } - -static int -mca_btl_portals4_component_close(void) +static int mca_btl_portals4_component_close(void) { - opal_output_verbose(50, opal_btl_base_framework.framework_output, "mca_btl_portals4_component_close\n"); + opal_output_verbose(50, opal_btl_base_framework.framework_output, + "mca_btl_portals4_component_close\n"); /* release resources */ /* close debugging stream */ opal_output_close(opal_btl_base_framework.framework_output); opal_btl_base_framework.framework_output = -1; - if (NULL != mca_btl_portals4_component.btls) free(mca_btl_portals4_component.btls); - if (NULL != mca_btl_portals4_component.eqs_h) free(mca_btl_portals4_component.eqs_h); + if (NULL != mca_btl_portals4_component.btls) + free(mca_btl_portals4_component.btls); + if (NULL != mca_btl_portals4_component.eqs_h) + free(mca_btl_portals4_component.eqs_h); mca_btl_portals4_component.btls = NULL; mca_btl_portals4_component.eqs_h = NULL; @@ -304,18 +255,19 @@ mca_btl_portals4_component_close(void) return OPAL_SUCCESS; } -static mca_btl_base_module_t** mca_btl_portals4_component_init(int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads) +static mca_btl_base_module_t **mca_btl_portals4_component_init(int *num_btls, + bool enable_progress_threads, + bool enable_mpi_threads) { mca_btl_portals4_module_t *portals4_btl = NULL; mca_btl_base_module_t **btls = NULL; unsigned int ret, interface; ptl_handle_ni_t *portals4_nis_h = NULL; - ptl_ni_limits_t portals4_ni_limits ; + ptl_ni_limits_t portals4_ni_limits; ptl_process_t *ptl_process_ids = NULL; - opal_output_verbose(50, opal_btl_base_framework.framework_output, "mca_btl_portals4_component_init\n"); + opal_output_verbose(50, opal_btl_base_framework.framework_output, + "mca_btl_portals4_component_init\n"); if (enable_mpi_threads && !mca_btl_base_thread_multiple_override) { opal_output_verbose(1, opal_btl_base_framework.framework_output, @@ -327,8 +279,7 @@ static mca_btl_base_module_t** mca_btl_portals4_component_init(int *num_btls, ret = PtlInit(); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlInit failed: %d\n", - __FILE__, __LINE__, ret); + "%s:%d: PtlInit failed: %d\n", __FILE__, __LINE__, ret); goto error; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlInit OK\n")); @@ -338,55 +289,62 @@ static mca_btl_base_module_t** mca_btl_portals4_component_init(int *num_btls, */ *num_btls = 0; portals4_nis_h = malloc(mca_btl_portals4_component.max_btls * sizeof(ptl_handle_ni_t)); - for (interface=0; interface portals4_ni_limits.max_msg_size) mca_btl_portals4_component.portals_max_msg_size = portals4_ni_limits.max_msg_size; if (mca_btl_portals4_module.super.btl_max_send_size > portals4_ni_limits.max_msg_size) mca_btl_portals4_module.super.btl_max_send_size = portals4_ni_limits.max_msg_size; if (mca_btl_portals4_module.super.btl_get_limit > portals4_ni_limits.max_msg_size) mca_btl_portals4_module.super.btl_get_limit = portals4_ni_limits.max_msg_size; - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlNIInit OK for NI %d max_msg_size=%ld", - *num_btls, mca_btl_portals4_component.portals_max_msg_size)); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "PtlNIInit OK for NI %d max_msg_size=%ld", *num_btls, + mca_btl_portals4_component.portals_max_msg_size)); (*num_btls)++; } } - if (0 == *num_btls) goto error; + if (0 == *num_btls) + goto error; /* * Configure the different network interfaces and the associated btl modules */ mca_btl_portals4_component.num_btls = *num_btls; - mca_btl_portals4_component.btls = malloc(mca_btl_portals4_component.num_btls * sizeof(mca_btl_portals4_module_t*) ); - mca_btl_portals4_component.eqs_h = malloc(mca_btl_portals4_component.num_btls * sizeof(ptl_handle_eq_t)); - ptl_process_ids = malloc(mca_btl_portals4_component.num_btls * sizeof(ptl_process_t) ); + mca_btl_portals4_component.btls = malloc(mca_btl_portals4_component.num_btls + * sizeof(mca_btl_portals4_module_t *)); + mca_btl_portals4_component.eqs_h = malloc(mca_btl_portals4_component.num_btls + * sizeof(ptl_handle_eq_t)); + ptl_process_ids = malloc(mca_btl_portals4_component.num_btls * sizeof(ptl_process_t)); - for (interface=0; interfaceinterface_num = interface; portals4_btl->portals_ni_h = portals4_nis_h[interface]; - portals4_btl->portals_max_outstanding_ops = mca_btl_portals4_component.portals_max_outstanding_ops; + portals4_btl->portals_max_outstanding_ops = mca_btl_portals4_component + .portals_max_outstanding_ops; OBJ_CONSTRUCT(&(portals4_btl->portals_frag_eager), opal_free_list_t); OBJ_CONSTRUCT(&(portals4_btl->portals_frag_max), opal_free_list_t); OBJ_CONSTRUCT(&(portals4_btl->portals_frag_user), opal_free_list_t); /* eager frags */ - opal_free_list_init (&(portals4_btl->portals_frag_eager), - sizeof(mca_btl_portals4_frag_eager_t) + - portals4_btl->super.btl_eager_limit, - opal_cache_line_size, - OBJ_CLASS(mca_btl_portals4_frag_eager_t), - 0,opal_cache_line_size, - mca_btl_portals4_component.portals_free_list_init_num, - mca_btl_portals4_component.portals_free_list_eager_max_num, - mca_btl_portals4_component.portals_free_list_inc_num, - NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&(portals4_btl->portals_frag_eager), + sizeof(mca_btl_portals4_frag_eager_t) + + portals4_btl->super.btl_eager_limit, + opal_cache_line_size, OBJ_CLASS(mca_btl_portals4_frag_eager_t), 0, + opal_cache_line_size, + mca_btl_portals4_component.portals_free_list_init_num, + mca_btl_portals4_component.portals_free_list_eager_max_num, + mca_btl_portals4_component.portals_free_list_inc_num, NULL, 0, NULL, + NULL, NULL); /* send frags */ - opal_free_list_init (&(portals4_btl->portals_frag_max), - sizeof(mca_btl_portals4_frag_max_t) + - portals4_btl->super.btl_max_send_size, - opal_cache_line_size, - OBJ_CLASS(mca_btl_portals4_frag_max_t), - 0,opal_cache_line_size, - mca_btl_portals4_component.portals_free_list_init_num, - mca_btl_portals4_component.portals_free_list_max_num, - mca_btl_portals4_component.portals_free_list_inc_num, - NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&(portals4_btl->portals_frag_max), + sizeof(mca_btl_portals4_frag_max_t) + + portals4_btl->super.btl_max_send_size, + opal_cache_line_size, OBJ_CLASS(mca_btl_portals4_frag_max_t), 0, + opal_cache_line_size, + mca_btl_portals4_component.portals_free_list_init_num, + mca_btl_portals4_component.portals_free_list_max_num, + mca_btl_portals4_component.portals_free_list_inc_num, NULL, 0, NULL, + NULL, NULL); /* user frags */ - opal_free_list_init (&(portals4_btl->portals_frag_user), - sizeof(mca_btl_portals4_frag_user_t), - opal_cache_line_size, - OBJ_CLASS(mca_btl_portals4_frag_user_t), - 0,opal_cache_line_size, - mca_btl_portals4_component.portals_free_list_init_num, - mca_btl_portals4_component.portals_free_list_max_num, - mca_btl_portals4_component.portals_free_list_inc_num, - NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&(portals4_btl->portals_frag_user), + sizeof(mca_btl_portals4_frag_user_t), opal_cache_line_size, + OBJ_CLASS(mca_btl_portals4_frag_user_t), 0, opal_cache_line_size, + mca_btl_portals4_component.portals_free_list_init_num, + mca_btl_portals4_component.portals_free_list_max_num, + mca_btl_portals4_component.portals_free_list_inc_num, NULL, 0, NULL, + NULL, NULL); /* receive block list */ OBJ_CONSTRUCT(&(portals4_btl->portals_recv_blocks), opal_list_t); @@ -443,70 +398,73 @@ static mca_btl_base_module_t** mca_btl_portals4_component_init(int *num_btls, portals4_nis_h = NULL; /* Publish our NID(s)/PID(s) in the modex */ - for (interface=0; interfaceportals_ni_h ,&ptl_process_ids[interface]); + ret = PtlGetPhysId(portals4_btl->portals_ni_h, &ptl_process_ids[interface]); if (PTL_OK != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlGetPhysId for NI %d failed: %d\n", - __FILE__, __LINE__, interface, ret); + "%s:%d: PtlGetPhysId for NI %d failed: %d\n", __FILE__, __LINE__, + interface, ret); goto error; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PtlGetPhysId NI number %d: ni_h=%d rank=%x nid=%x pid=%x\n", - interface, portals4_btl->portals_ni_h, - ptl_process_ids[interface].rank, - ptl_process_ids[interface].phys.nid, ptl_process_ids[interface].phys.pid)); + "PtlGetPhysId NI number %d: ni_h=%d rank=%x nid=%x pid=%x\n", + interface, portals4_btl->portals_ni_h, ptl_process_ids[interface].rank, + ptl_process_ids[interface].phys.nid, + ptl_process_ids[interface].phys.pid)); } - OPAL_MODEX_SEND(ret, PMIX_GLOBAL, - &mca_btl_portals4_component.super.btl_version, + OPAL_MODEX_SEND(ret, PMIX_GLOBAL, &mca_btl_portals4_component.super.btl_version, ptl_process_ids, mca_btl_portals4_component.num_btls * sizeof(ptl_process_t)); if (OPAL_SUCCESS != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: opal_modex_send failed: %d\n", - __FILE__, __LINE__, ret); + "%s:%d: opal_modex_send failed: %d\n", __FILE__, __LINE__, ret); goto error; } free(ptl_process_ids); ptl_process_ids = NULL; - btls = malloc(mca_btl_portals4_component.num_btls * sizeof(mca_btl_portals4_module_t*) ); - memcpy(btls , mca_btl_portals4_component.btls, - mca_btl_portals4_component.num_btls*sizeof(mca_btl_portals4_module_t*) ); + btls = malloc(mca_btl_portals4_component.num_btls * sizeof(mca_btl_portals4_module_t *)); + memcpy(btls, mca_btl_portals4_component.btls, + mca_btl_portals4_component.num_btls * sizeof(mca_btl_portals4_module_t *)); - opal_output_verbose(1, opal_btl_base_framework.framework_output, "The btl portals4 component has been initialized and uses %d NI(s)", - mca_btl_portals4_component.num_btls); + opal_output_verbose(1, opal_btl_base_framework.framework_output, + "The btl portals4 component has been initialized and uses %d NI(s)", + mca_btl_portals4_component.num_btls); mca_btl_portals4_component.need_init = 1; return btls; - error: - opal_output_verbose(1, opal_btl_base_framework.framework_output, "Error in mca_btl_portals4_component_init\n"); +error: + opal_output_verbose(1, opal_btl_base_framework.framework_output, + "Error in mca_btl_portals4_component_init\n"); if (*num_btls) { - if (NULL != portals4_nis_h) free(portals4_nis_h); - if (NULL != ptl_process_ids) free(ptl_process_ids); + if (NULL != portals4_nis_h) + free(portals4_nis_h); + if (NULL != ptl_process_ids) + free(ptl_process_ids); - for (interface=0; interfacebase.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); if (!mca_btl_portals4_component.portals_need_ack) { /* my part's done, in portals we trust! */ - if( MCA_BTL_DES_SEND_ALWAYS_CALLBACK & frag->base.des_flags ){ + if (MCA_BTL_DES_SEND_ALWAYS_CALLBACK & frag->base.des_flags) { OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_SEND: Direct call to des_cbfunc: %lx\n", (uint64_t)frag->base.des_cbfunc)); - frag->base.des_cbfunc(&portals4_btl->super, - frag->endpoint, - &frag->base, + "PTL_EVENT_SEND: Direct call to des_cbfunc: %lx\n", + (uint64_t) frag->base.des_cbfunc)); + frag->base.des_cbfunc(&portals4_btl->super, frag->endpoint, &frag->base, OPAL_SUCCESS); } if (btl_ownership) { @@ -613,35 +573,39 @@ mca_btl_portals4_component_progress(void) } if (0 != frag->size) { OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_SEND: Decrementing portals_outstanding_ops=%d (1)\n", - portals4_btl->portals_outstanding_ops)); + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, + "PTL_EVENT_SEND: Decrementing portals_outstanding_ops=%d (1)\n", + portals4_btl->portals_outstanding_ops)); } } goto done; break; - case PTL_EVENT_ACK: /* Ack that a put as completed on other side. We just call the callback function */ + case PTL_EVENT_ACK: /* Ack that a put as completed on other side. We just call the + callback function */ frag = ev.user_ptr; if (NULL == frag) { - opal_output(opal_btl_base_framework.framework_output, "btl/portals4: PTL_EVENT_ACK event with NULL user_ptr"); + opal_output(opal_btl_base_framework.framework_output, + "btl/portals4: PTL_EVENT_ACK event with NULL user_ptr"); break; } - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_ACK received rlength=%ld mlength=%ld des_flags=%d\n", ev.rlength, ev.mlength, frag->base.des_flags)); + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, + "PTL_EVENT_ACK received rlength=%ld mlength=%ld des_flags=%d\n", ev.rlength, + ev.mlength, frag->base.des_flags)); btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); /* other side received the message. should have received entire thing */ /* let the PML know we're done */ - if (MCA_BTL_DES_SEND_ALWAYS_CALLBACK & frag->base.des_flags ) { + if (MCA_BTL_DES_SEND_ALWAYS_CALLBACK & frag->base.des_flags) { OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_ACK: Call to des_cbfunc %lx\n", (uint64_t)frag->base.des_cbfunc)); - frag->base.des_cbfunc(&portals4_btl->super, - frag->endpoint, - &frag->base, + "PTL_EVENT_ACK: Call to des_cbfunc %lx\n", + (uint64_t) frag->base.des_cbfunc)); + frag->base.des_cbfunc(&portals4_btl->super, frag->endpoint, &frag->base, OPAL_SUCCESS); } if (btl_ownership) { @@ -650,14 +614,16 @@ mca_btl_portals4_component_progress(void) if (0 != frag->size) { OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_ACK: Decrementing portals_outstanding_ops=%d (2)\n", portals4_btl->portals_outstanding_ops)); + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, + "PTL_EVENT_ACK: Decrementing portals_outstanding_ops=%d (2)\n", + portals4_btl->portals_outstanding_ops)); } goto done; break; - case PTL_EVENT_PUT: /* Generated on destination (target) when a put into memory ends */ + case PTL_EVENT_PUT: /* Generated on destination (target) when a put into memory ends */ tag = (unsigned char) (ev.hdr_data); @@ -671,7 +637,8 @@ mca_btl_portals4_component_progress(void) recv_descriptor.cbdata = reg->cbdata; OPAL_OUTPUT_VERBOSE((50, opal_btl_base_framework.framework_output, - "PTL_EVENT_PUT: tag=%x base_descriptor=%p cbfunc: %lx\n", tag, (void*)&btl_base_descriptor, (uint64_t)reg->cbfunc)); + "PTL_EVENT_PUT: tag=%x base_descriptor=%p cbfunc: %lx\n", tag, + (void *) &btl_base_descriptor, (uint64_t) reg->cbfunc)); reg->cbfunc(&portals4_btl->super, &recv_descriptor); goto done; @@ -680,7 +647,7 @@ mca_btl_portals4_component_progress(void) case PTL_EVENT_PUT_OVERFLOW: /* */ OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_OVERFLOW received\n")); + "PTL_EVENT_OVERFLOW received\n")); goto done; break; @@ -688,7 +655,8 @@ mca_btl_portals4_component_progress(void) /* */ frag = ev.user_ptr; if (NULL == frag) { - opal_output(opal_btl_base_framework.framework_output, "btl/portals4: PTL_EVENT_LINK event with NULL user_ptr"); + opal_output(opal_btl_base_framework.framework_output, + "btl/portals4: PTL_EVENT_LINK event with NULL user_ptr"); break; } goto done; @@ -696,7 +664,8 @@ mca_btl_portals4_component_progress(void) case PTL_EVENT_AUTO_UNLINK: /* */ - /* The Priority List is used, so PTL_EVENT_AUTO_FREE will never be received. So, we have to reactivate the block here */ + /* The Priority List is used, so PTL_EVENT_AUTO_FREE will never be received. So, we + * have to reactivate the block here */ mca_btl_portals4_activate_block(ev.user_ptr); goto done; break; @@ -706,10 +675,11 @@ mca_btl_portals4_component_progress(void) goto done; break; - case PTL_EVENT_GET: /* Generated on source (target) when a get from memory ends */ + case PTL_EVENT_GET: /* Generated on source (target) when a get from memory ends */ /* */ OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_GET received at target rlength=%ld mlength=%ld\n", ev.rlength, ev.mlength)); + "PTL_EVENT_GET received at target rlength=%ld mlength=%ld\n", + ev.rlength, ev.mlength)); goto done; break; @@ -718,46 +688,45 @@ mca_btl_portals4_component_progress(void) frag = ev.user_ptr; if (PTL_NI_PERM_VIOLATION == ev.ni_fail_type) { - opal_output_verbose(1, opal_btl_base_framework.framework_output, - "Warning : PTL_EVENT_REPLY with PTL_NI_PERM_VIOLATION received, try to re-issue a PtlGet"); + opal_output_verbose(1, opal_btl_base_framework.framework_output, + "Warning : PTL_EVENT_REPLY with PTL_NI_PERM_VIOLATION " + "received, try to re-issue a PtlGet"); - /* The distant PtlMEAppend is not finished (distant PTL_EVENT_LINK not received) */ + /* The distant PtlMEAppend is not finished (distant PTL_EVENT_LINK not received) + */ /* Re-issue the PtlGet (see btl_portals4_rdma.c) */ - ret = PtlGet(portals4_btl->send_md_h, - (ptl_size_t) frag->addr, - frag->length, - frag->peer_proc, - portals4_btl->recv_idx, + ret = PtlGet(portals4_btl->send_md_h, (ptl_size_t) frag->addr, frag->length, + frag->peer_proc, portals4_btl->recv_idx, frag->match_bits, /* match bits */ 0, // Warning : should be ev.remote_offset but it is not defined, frag); if (OPAL_UNLIKELY(PTL_OK != ret)) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: Re-issued PtlGet failed: %d", - __FILE__, __LINE__, ret); + "%s:%d: Re-issued PtlGet failed: %d", __FILE__, + __LINE__, ret); return OPAL_ERROR; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "Re-issued PtlGet length=%ld recv_idx=%d rank=%x pid=%x nid=%x match_bits=%lx\n", - frag->length, portals4_btl->recv_idx, - frag->peer_proc.rank, frag->peer_proc.phys.pid, frag->peer_proc.phys.nid, frag->match_bits)); - } - else { + "Re-issued PtlGet length=%ld recv_idx=%d rank=%x pid=%x " + "nid=%x match_bits=%lx\n", + frag->length, portals4_btl->recv_idx, frag->peer_proc.rank, + frag->peer_proc.phys.pid, frag->peer_proc.phys.nid, + frag->match_bits)); + } else { OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_REPLY: Call to rdma_cbfunc=%lx\n", (uint64_t)frag->rdma_cb.func)); - frag->rdma_cb.func(&portals4_btl->super, - frag->endpoint, - ev.start, - frag->rdma_cb.local_handle, - frag->rdma_cb.context, - frag->rdma_cb.data, - OPAL_SUCCESS); + "PTL_EVENT_REPLY: Call to rdma_cbfunc=%lx\n", + (uint64_t) frag->rdma_cb.func)); + frag->rdma_cb.func(&portals4_btl->super, frag->endpoint, ev.start, + frag->rdma_cb.local_handle, frag->rdma_cb.context, + frag->rdma_cb.data, OPAL_SUCCESS); OPAL_BTL_PORTALS4_FRAG_RETURN_USER(&portals4_btl->super, frag); OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PTL_EVENT_REPLY: Decrementing portals_outstanding_ops=%d\n", portals4_btl->portals_outstanding_ops)); + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, + "PTL_EVENT_REPLY: Decrementing portals_outstanding_ops=%d\n", + portals4_btl->portals_outstanding_ops)); goto done; } break; @@ -785,6 +754,6 @@ mca_btl_portals4_component_progress(void) break; } } - done: +done: return num_progressed; } diff --git a/opal/mca/btl/portals4/btl_portals4_frag.c b/opal/mca/btl/portals4/btl_portals4_frag.c index 6aa20a14af4..cbe765d0073 100644 --- a/opal/mca/btl/portals4/btl_portals4_frag.c +++ b/opal/mca/btl/portals4/btl_portals4_frag.c @@ -23,8 +23,7 @@ #include "btl_portals4.h" #include "btl_portals4_frag.h" -static void -mca_btl_portals4_frag_common_send_constructor(mca_btl_portals4_frag_t* frag) +static void mca_btl_portals4_frag_common_send_constructor(mca_btl_portals4_frag_t *frag) { frag->base.des_flags = 0; frag->base.des_segments = &frag->segments[0].base; @@ -37,16 +36,14 @@ mca_btl_portals4_frag_common_send_constructor(mca_btl_portals4_frag_t* frag) frag->me_h = PTL_INVALID_HANDLE; } -static void -mca_btl_portals4_frag_eager_constructor(mca_btl_portals4_frag_t* frag) +static void mca_btl_portals4_frag_eager_constructor(mca_btl_portals4_frag_t *frag) { frag->size = mca_btl_portals4_module.super.btl_eager_limit; mca_btl_portals4_frag_common_send_constructor(frag); frag->type = BTL_PORTALS4_FRAG_TYPE_EAGER; } -static void -mca_btl_portals4_frag_eager_destructor(mca_btl_portals4_frag_t* frag) +static void mca_btl_portals4_frag_eager_destructor(mca_btl_portals4_frag_t *frag) { if (PTL_INVALID_HANDLE != frag->me_h) { PtlMEUnlink(frag->me_h); @@ -54,42 +51,27 @@ mca_btl_portals4_frag_eager_destructor(mca_btl_portals4_frag_t* frag) } } -static void -mca_btl_portals4_frag_max_constructor(mca_btl_portals4_frag_t* frag) +static void mca_btl_portals4_frag_max_constructor(mca_btl_portals4_frag_t *frag) { frag->size = mca_btl_portals4_module.super.btl_max_send_size; mca_btl_portals4_frag_common_send_constructor(frag); frag->type = BTL_PORTALS4_FRAG_TYPE_MAX; } -static void -mca_btl_portals4_frag_user_constructor(mca_btl_portals4_frag_t* frag) +static void mca_btl_portals4_frag_user_constructor(mca_btl_portals4_frag_t *frag) { frag->base.des_flags = 0; frag->size = 0; frag->type = BTL_PORTALS4_FRAG_TYPE_USER; } -OBJ_CLASS_INSTANCE( - mca_btl_portals4_frag_t, - mca_btl_base_descriptor_t, - NULL, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_portals4_frag_t, mca_btl_base_descriptor_t, NULL, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_portals4_frag_eager_t, - mca_btl_base_descriptor_t, - mca_btl_portals4_frag_eager_constructor, - mca_btl_portals4_frag_eager_destructor); +OBJ_CLASS_INSTANCE(mca_btl_portals4_frag_eager_t, mca_btl_base_descriptor_t, + mca_btl_portals4_frag_eager_constructor, mca_btl_portals4_frag_eager_destructor); -OBJ_CLASS_INSTANCE( - mca_btl_portals4_frag_max_t, - mca_btl_base_descriptor_t, - mca_btl_portals4_frag_max_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_portals4_frag_max_t, mca_btl_base_descriptor_t, + mca_btl_portals4_frag_max_constructor, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_portals4_frag_user_t, - mca_btl_base_descriptor_t, - mca_btl_portals4_frag_user_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_portals4_frag_user_t, mca_btl_base_descriptor_t, + mca_btl_portals4_frag_user_constructor, NULL); diff --git a/opal/mca/btl/portals4/btl_portals4_frag.h b/opal/mca/btl/portals4/btl_portals4_frag.h index 8f3c6e49ac3..0dffb6a0331 100644 --- a/opal/mca/btl/portals4/btl_portals4_frag.h +++ b/opal/mca/btl/portals4/btl_portals4_frag.h @@ -28,8 +28,8 @@ BEGIN_C_DECLS struct mca_btl_portals4_segment_t { - mca_btl_base_segment_t base; - ptl_match_bits_t key; + mca_btl_base_segment_t base; + ptl_match_bits_t key; }; typedef struct mca_btl_portals4_segment_t mca_btl_portals4_segment_t; @@ -40,7 +40,7 @@ struct mca_btl_portals4_frag_t { mca_btl_base_descriptor_t base; mca_btl_portals4_segment_t segments[1]; /* needed for retransmit case */ - struct mca_btl_base_endpoint_t *endpoint; + struct mca_btl_base_endpoint_t *endpoint; /* needed for retransmit case */ mca_btl_base_header_t hdr; /* handle to use for communication */ @@ -64,10 +64,12 @@ struct mca_btl_portals4_frag_t { mca_btl_base_registration_handle_t *local_handle; } rdma_cb; - enum { BTL_PORTALS4_FRAG_TYPE_EAGER, - BTL_PORTALS4_FRAG_TYPE_MAX, - BTL_PORTALS4_FRAG_TYPE_USER } type; - unsigned char data[16]; + enum { + BTL_PORTALS4_FRAG_TYPE_EAGER, + BTL_PORTALS4_FRAG_TYPE_MAX, + BTL_PORTALS4_FRAG_TYPE_USER + } type; + unsigned char data[16]; }; typedef struct mca_btl_portals4_frag_t mca_btl_portals4_frag_t; OBJ_CLASS_DECLARATION(mca_btl_portals4_frag_t); @@ -85,54 +87,48 @@ OBJ_CLASS_DECLARATION(mca_btl_portals4_frag_user_t); * Macros to allocate/return descriptors from module specific * free list(s). */ -#define OPAL_BTL_PORTALS4_FRAG_ALLOC_EAGER(btl_macro, frag) \ -{ \ - frag = (mca_btl_portals4_frag_t *) \ - opal_free_list_get (&((mca_btl_portals4_module_t*)btl_macro)->portals_frag_eager); \ - if (NULL == frag) { \ - OPAL_BTL_PORTALS4_FRAG_ALLOC_MAX(btl_macro, frag); \ - } \ -} - - -#define OPAL_BTL_PORTALS4_FRAG_RETURN_EAGER(btl_macro, frag) \ -{ \ - assert(BTL_PORTALS4_FRAG_TYPE_EAGER == frag->type); \ - opal_free_list_return (&((mca_btl_portals4_module_t*)btl_macro)->portals_frag_eager, \ - (opal_free_list_item_t*)(frag)); \ -} - - -#define OPAL_BTL_PORTALS4_FRAG_ALLOC_MAX(btl_macro, frag) \ -{ \ - frag = (mca_btl_portals4_frag_t*) \ - opal_free_list_get (&((mca_btl_portals4_module_t*)btl_macro)->portals_frag_max); \ -} - - -#define OPAL_BTL_PORTALS4_FRAG_RETURN_MAX(btl_macro, frag) \ -{ \ - assert(BTL_PORTALS4_FRAG_TYPE_MAX == frag->type); \ - opal_free_list_return (&((mca_btl_portals4_module_t*)btl_macro)->portals_frag_max, \ - (opal_free_list_item_t*)(frag)); \ -} - - -#define OPAL_BTL_PORTALS4_FRAG_ALLOC_USER(btl_macro, frag) \ -{ \ - frag = (mca_btl_portals4_frag_t*) \ - opal_free_list_get (&((mca_btl_portals4_module_t*)btl_macro)->portals_frag_user); \ - frag->base.des_cbfunc = NULL; \ -} - - -#define OPAL_BTL_PORTALS4_FRAG_RETURN_USER(btl_macro, frag) \ -{ \ - assert(BTL_PORTALS4_FRAG_TYPE_USER == frag->type); \ - opal_free_list_return (&((mca_btl_portals4_module_t*)btl_macro)->portals_frag_user, \ - (opal_free_list_item_t*)(frag)); \ -} - +#define OPAL_BTL_PORTALS4_FRAG_ALLOC_EAGER(btl_macro, frag) \ + { \ + frag = (mca_btl_portals4_frag_t *) opal_free_list_get( \ + &((mca_btl_portals4_module_t *) btl_macro)->portals_frag_eager); \ + if (NULL == frag) { \ + OPAL_BTL_PORTALS4_FRAG_ALLOC_MAX(btl_macro, frag); \ + } \ + } + +#define OPAL_BTL_PORTALS4_FRAG_RETURN_EAGER(btl_macro, frag) \ + { \ + assert(BTL_PORTALS4_FRAG_TYPE_EAGER == frag->type); \ + opal_free_list_return(&((mca_btl_portals4_module_t *) btl_macro)->portals_frag_eager, \ + (opal_free_list_item_t *) (frag)); \ + } + +#define OPAL_BTL_PORTALS4_FRAG_ALLOC_MAX(btl_macro, frag) \ + { \ + frag = (mca_btl_portals4_frag_t *) opal_free_list_get( \ + &((mca_btl_portals4_module_t *) btl_macro)->portals_frag_max); \ + } + +#define OPAL_BTL_PORTALS4_FRAG_RETURN_MAX(btl_macro, frag) \ + { \ + assert(BTL_PORTALS4_FRAG_TYPE_MAX == frag->type); \ + opal_free_list_return(&((mca_btl_portals4_module_t *) btl_macro)->portals_frag_max, \ + (opal_free_list_item_t *) (frag)); \ + } + +#define OPAL_BTL_PORTALS4_FRAG_ALLOC_USER(btl_macro, frag) \ + { \ + frag = (mca_btl_portals4_frag_t *) opal_free_list_get( \ + &((mca_btl_portals4_module_t *) btl_macro)->portals_frag_user); \ + frag->base.des_cbfunc = NULL; \ + } + +#define OPAL_BTL_PORTALS4_FRAG_RETURN_USER(btl_macro, frag) \ + { \ + assert(BTL_PORTALS4_FRAG_TYPE_USER == frag->type); \ + opal_free_list_return(&((mca_btl_portals4_module_t *) btl_macro)->portals_frag_user, \ + (opal_free_list_item_t *) (frag)); \ + } END_C_DECLS #endif diff --git a/opal/mca/btl/portals4/btl_portals4_rdma.c b/opal/mca/btl/portals4/btl_portals4_rdma.c index 9237b30fce2..c0dfd65fc4a 100644 --- a/opal/mca/btl/portals4/btl_portals4_rdma.c +++ b/opal/mca/btl/portals4/btl_portals4_rdma.c @@ -19,13 +19,12 @@ */ #include "opal_config.h" -#include "opal/constants.h" #include "btl_portals4.h" +#include "opal/constants.h" -int -mca_btl_portals4_put(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* btl_peer, - struct mca_btl_base_descriptor_t* descriptor) +int mca_btl_portals4_put(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *btl_peer, + struct mca_btl_base_descriptor_t *descriptor) { opal_output(opal_btl_base_framework.framework_output, "mca_btl_portals4_put not implemented\n"); @@ -33,45 +32,39 @@ mca_btl_portals4_put(struct mca_btl_base_module_t* btl_base, return OPAL_SUCCESS; } - -int -mca_btl_portals4_get(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* btl_peer, - void *local_address, - uint64_t remote_address, - struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, - size_t size, - int flags, - int order, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, - void *cbdata) +int mca_btl_portals4_get(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *btl_peer, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { mca_btl_portals4_module_t *portals4_btl = (mca_btl_portals4_module_t *) btl_base; - mca_btl_portals4_frag_t *frag = NULL; + mca_btl_portals4_frag_t *frag = NULL; int ret; /* reserve space in the event queue for rdma operations immediately */ - while (OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, 1) > - portals4_btl->portals_max_outstanding_ops) { + while (OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, 1) + > portals4_btl->portals_max_outstanding_ops) { OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "Call to mca_btl_portals4_component_progress (1)\n")); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "Call to mca_btl_portals4_component_progress (1)\n")); mca_btl_portals4_component_progress(); } OPAL_BTL_PORTALS4_FRAG_ALLOC_USER(portals4_btl, frag); - if (NULL == frag){ + if (NULL == frag) { OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); return OPAL_ERROR; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "mca_btl_portals4_get: Incrementing portals_outstanding_ops=%d frag=%p", - portals4_btl->portals_outstanding_ops, (void *)frag)); + "mca_btl_portals4_get: Incrementing portals_outstanding_ops=%d frag=%p", + portals4_btl->portals_outstanding_ops, (void *) frag)); - frag->rdma_cb.func = cbfunc; - frag->rdma_cb.context = cbcontext; - frag->rdma_cb.data = cbdata; + frag->rdma_cb.func = cbfunc; + frag->rdma_cb.context = cbcontext; + frag->rdma_cb.data = cbdata; frag->rdma_cb.local_handle = local_handle; frag->endpoint = btl_peer; @@ -82,20 +75,17 @@ mca_btl_portals4_get(struct mca_btl_base_module_t* btl_base, frag->length = size; frag->peer_proc = btl_peer->ptl_proc; - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlGet offset=%p length=%ld remote_offset=%p nid=%x pid=%x match_bits=%lx", - local_address, size, (void*)local_handle->remote_offset, btl_peer->ptl_proc.phys.nid, btl_peer->ptl_proc.phys.pid, frag->match_bits)); + OPAL_OUTPUT_VERBOSE( + (90, opal_btl_base_framework.framework_output, + "PtlGet offset=%p length=%ld remote_offset=%p nid=%x pid=%x match_bits=%lx", local_address, + size, (void *) local_handle->remote_offset, btl_peer->ptl_proc.phys.nid, + btl_peer->ptl_proc.phys.pid, frag->match_bits)); - ret = PtlGet(portals4_btl->send_md_h, - (ptl_size_t) local_address, - size, - btl_peer->ptl_proc, - portals4_btl->recv_idx, - frag->match_bits, /* match bits */ - local_handle->remote_offset, - frag); + ret = PtlGet(portals4_btl->send_md_h, (ptl_size_t) local_address, size, btl_peer->ptl_proc, + portals4_btl->recv_idx, frag->match_bits, /* match bits */ + local_handle->remote_offset, frag); if (OPAL_UNLIKELY(PTL_OK != ret)) { - opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlGet failed: %d", + opal_output_verbose(1, opal_btl_base_framework.framework_output, "%s:%d: PtlGet failed: %d", __FILE__, __LINE__, ret); return OPAL_ERROR; } diff --git a/opal/mca/btl/portals4/btl_portals4_recv.c b/opal/mca/btl/portals4/btl_portals4_recv.c index c8dbfa3cc26..1bd9e4279ee 100644 --- a/opal/mca/btl/portals4/btl_portals4_recv.c +++ b/opal/mca/btl/portals4/btl_portals4_recv.c @@ -17,50 +17,40 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" #include "btl_portals4.h" -#include "btl_portals4_recv.h" #include "btl_portals4_frag.h" +#include "btl_portals4_recv.h" +OBJ_CLASS_INSTANCE(mca_btl_portals4_recv_block_t, opal_list_item_t, NULL, NULL); -OBJ_CLASS_INSTANCE(mca_btl_portals4_recv_block_t, - opal_list_item_t, - NULL, NULL); - -int -mca_btl_portals4_recv_enable(mca_btl_portals4_module_t *btl) +int mca_btl_portals4_recv_enable(mca_btl_portals4_module_t *btl) { int i; /* create the recv blocks */ - for (i = 0 ; i < mca_btl_portals4_component.portals_recv_mds_num ; ++i) { - mca_btl_portals4_recv_block_t *block = - mca_btl_portals4_recv_block_init(btl); + for (i = 0; i < mca_btl_portals4_component.portals_recv_mds_num; ++i) { + mca_btl_portals4_recv_block_t *block = mca_btl_portals4_recv_block_init(btl); if (NULL == block) { mca_btl_portals4_recv_disable(btl); return OPAL_ERROR; } - opal_list_append(&(btl->portals_recv_blocks), - (opal_list_item_t*) block); + opal_list_append(&(btl->portals_recv_blocks), (opal_list_item_t *) block); mca_btl_portals4_activate_block(block); } return OPAL_SUCCESS; } -int -mca_btl_portals4_recv_disable(mca_btl_portals4_module_t *btl) +int mca_btl_portals4_recv_disable(mca_btl_portals4_module_t *btl) { opal_list_item_t *item; if (opal_list_get_size(&btl->portals_recv_blocks) > 0) { - while (NULL != - (item = opal_list_remove_first(&btl->portals_recv_blocks))) { - mca_btl_portals4_recv_block_t *block = - (mca_btl_portals4_recv_block_t*) item; + while (NULL != (item = opal_list_remove_first(&btl->portals_recv_blocks))) { + mca_btl_portals4_recv_block_t *block = (mca_btl_portals4_recv_block_t *) item; mca_btl_portals4_recv_block_free(block); } } @@ -68,8 +58,7 @@ mca_btl_portals4_recv_disable(mca_btl_portals4_module_t *btl) return OPAL_SUCCESS; } -mca_btl_portals4_recv_block_t* -mca_btl_portals4_recv_block_init(mca_btl_portals4_module_t *btl) +mca_btl_portals4_recv_block_t *mca_btl_portals4_recv_block_init(mca_btl_portals4_module_t *btl) { mca_btl_portals4_recv_block_t *block; @@ -77,7 +66,8 @@ mca_btl_portals4_recv_block_init(mca_btl_portals4_module_t *btl) block->btl = btl; block->length = mca_btl_portals4_component.portals_recv_mds_size; block->start = malloc(block->length); - if (block->start == NULL) return NULL; + if (block->start == NULL) + return NULL; block->me_h = PTL_INVALID_HANDLE; @@ -87,9 +77,7 @@ mca_btl_portals4_recv_block_init(mca_btl_portals4_module_t *btl) return block; } - -int -mca_btl_portals4_recv_block_free(mca_btl_portals4_recv_block_t *block) +int mca_btl_portals4_recv_block_free(mca_btl_portals4_recv_block_t *block) { if (NULL != block->start) { free(block->start); diff --git a/opal/mca/btl/portals4/btl_portals4_recv.h b/opal/mca/btl/portals4/btl_portals4_recv.h index be7e98ca7cf..4e5703aaa30 100644 --- a/opal/mca/btl/portals4/btl_portals4_recv.h +++ b/opal/mca/btl/portals4/btl_portals4_recv.h @@ -37,7 +37,6 @@ struct mca_btl_portals4_recv_block_t { typedef struct mca_btl_portals4_recv_block_t mca_btl_portals4_recv_block_t; OBJ_CLASS_DECLARATION(mca_btl_portals4_recv_block_t); - int mca_btl_portals4_recv_enable(mca_btl_portals4_module_t *btl); int mca_btl_portals4_recv_disable(mca_btl_portals4_module_t *btl); @@ -55,16 +54,14 @@ int mca_btl_portals4_recv_block_free(mca_btl_portals4_recv_block_t *block); * * Module lock must be held before calling this function */ -mca_btl_portals4_recv_block_t* -mca_btl_portals4_recv_block_init(mca_btl_portals4_module_t *btl); +mca_btl_portals4_recv_block_t *mca_btl_portals4_recv_block_init(mca_btl_portals4_module_t *btl); /** * activate a block. Blocks that are full (have gone inactive) can be * re-activated with this call. There is no need to hold the lock * before calling this function */ -static inline int -mca_btl_portals4_activate_block(mca_btl_portals4_recv_block_t *block) +static inline int mca_btl_portals4_activate_block(mca_btl_portals4_recv_block_t *block) { int ret; ptl_me_t me; @@ -72,7 +69,8 @@ mca_btl_portals4_activate_block(mca_btl_portals4_recv_block_t *block) ptl_match_bits_t match_bits, ignore_bits; mca_btl_portals4_module_t *btl = block->btl; - if (NULL == block->start) return OPAL_ERROR; + if (NULL == block->start) + return OPAL_ERROR; ignore_bits = BTL_PORTALS4_CONTEXT_MASK | BTL_PORTALS4_SOURCE_MASK | BTL_PORTALS4_TAG_MASK; match_bits = BTL_PORTALS4_SHORT_MSG; @@ -82,11 +80,7 @@ mca_btl_portals4_activate_block(mca_btl_portals4_recv_block_t *block) me.ct_handle = PTL_CT_NONE; me.min_free = btl->super.btl_eager_limit; me.uid = PTL_UID_ANY; - me.options = - PTL_ME_OP_PUT | - PTL_ME_MANAGE_LOCAL | - PTL_ME_EVENT_LINK_DISABLE | - PTL_ME_MAY_ALIGN; + me.options = PTL_ME_OP_PUT | PTL_ME_MANAGE_LOCAL | PTL_ME_EVENT_LINK_DISABLE | PTL_ME_MAY_ALIGN; if (mca_btl_portals4_component.use_logical) { remote_proc.rank = PTL_RANK_ANY; @@ -103,20 +97,18 @@ mca_btl_portals4_activate_block(mca_btl_portals4_recv_block_t *block) block->full = false; opal_atomic_mb(); - ret = PtlMEAppend(btl->portals_ni_h, - btl->recv_idx, - &me, - PTL_PRIORITY_LIST, - block, + ret = PtlMEAppend(btl->portals_ni_h, btl->recv_idx, &me, PTL_PRIORITY_LIST, block, &block->me_h); if (OPAL_UNLIKELY(PTL_OK != ret)) { opal_output_verbose(1, opal_btl_base_framework.framework_output, - "%s:%d: PtlMEAppend failed on NI %d: %d", - __FILE__, __LINE__, btl->interface_num, ret); + "%s:%d: PtlMEAppend failed on NI %d: %d", __FILE__, __LINE__, + btl->interface_num, ret); return OPAL_ERROR; } - OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "PtlMEAppend (recv) block=%p me_h=%d start=%p len=%x NI=%d\n", - (void *)block, block->me_h, block->start, (unsigned int) block->length, btl->interface_num)); + OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, + "PtlMEAppend (recv) block=%p me_h=%d start=%p len=%x NI=%d\n", + (void *) block, block->me_h, block->start, (unsigned int) block->length, + btl->interface_num)); return OPAL_SUCCESS; } diff --git a/opal/mca/btl/portals4/btl_portals4_send.c b/opal/mca/btl/portals4/btl_portals4_send.c index 218ed877803..eda155d45ff 100644 --- a/opal/mca/btl/portals4/btl_portals4_send.c +++ b/opal/mca/btl/portals4/btl_portals4_send.c @@ -27,13 +27,12 @@ #include "btl_portals4.h" -int mca_btl_portals4_send(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag) +int mca_btl_portals4_send(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { - struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; - mca_btl_portals4_frag_t *frag = (mca_btl_portals4_frag_t*) descriptor; + struct mca_btl_portals4_module_t *portals4_btl = (struct mca_btl_portals4_module_t *) btl_base; + mca_btl_portals4_frag_t *frag = (mca_btl_portals4_frag_t *) descriptor; ptl_match_bits_t match_bits, msglen_type; ptl_size_t put_length; int ret; @@ -41,16 +40,17 @@ int mca_btl_portals4_send(struct mca_btl_base_module_t* btl_base, frag->endpoint = endpoint; frag->hdr.tag = tag; - put_length = frag->segments[0].base.seg_len; + put_length = frag->segments[0].base.seg_len; if (put_length > portals4_btl->super.btl_eager_limit) - msglen_type = BTL_PORTALS4_LONG_MSG; - else msglen_type = BTL_PORTALS4_SHORT_MSG; + msglen_type = BTL_PORTALS4_LONG_MSG; + else + msglen_type = BTL_PORTALS4_SHORT_MSG; BTL_PORTALS4_SET_SEND_BITS(match_bits, 0, 0, tag, msglen_type); /* reserve space in the event queue for rdma operations immediately */ - while (OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, 1) > - portals4_btl->portals_max_outstanding_ops) { + while (OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, 1) + > portals4_btl->portals_max_outstanding_ops) { OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_outstanding_ops, -1); OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "Call to mca_btl_portals4_component_progress (4)\n")); @@ -58,48 +58,43 @@ int mca_btl_portals4_send(struct mca_btl_base_module_t* btl_base, } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "mca_btl_portals4_send: Incrementing portals_outstanding_ops=%d\n", - portals4_btl->portals_outstanding_ops)); + portals4_btl->portals_outstanding_ops)); OPAL_OUTPUT_VERBOSE((50, opal_btl_base_framework.framework_output, "PtlPut frag=%p rank=%x pid=%x tag=%x len=%ld match_bits=%lx\n", - (void*)frag, endpoint->ptl_proc.rank, endpoint->ptl_proc.phys.pid, tag, - put_length, (uint64_t)match_bits)); + (void *) frag, endpoint->ptl_proc.rank, endpoint->ptl_proc.phys.pid, tag, + put_length, (uint64_t) match_bits)); - ret = PtlPut(portals4_btl->send_md_h, - (ptl_size_t) frag->segments[0].base.seg_addr.pval, + ret = PtlPut(portals4_btl->send_md_h, (ptl_size_t) frag->segments[0].base.seg_addr.pval, put_length, /* fragment length */ (mca_btl_portals4_component.portals_need_ack ? PTL_ACK_REQ : PTL_NO_ACK_REQ), - endpoint->ptl_proc, - portals4_btl->recv_idx, - match_bits, /* match bits */ - 0, /* remote offset - not used */ - (void *) frag, /* user ptr */ - tag); /* hdr_data: tag */ + endpoint->ptl_proc, portals4_btl->recv_idx, match_bits, /* match bits */ + 0, /* remote offset - not used */ + (void *) frag, /* user ptr */ + tag); /* hdr_data: tag */ if (ret != PTL_OK) { - opal_output(opal_btl_base_framework.framework_output, "mca_btl_portals4_send: PtlPut failed with error %d", ret); + opal_output(opal_btl_base_framework.framework_output, + "mca_btl_portals4_send: PtlPut failed with error %d", ret); return OPAL_ERROR; } OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, - "PtlPut frag=%p rank=%x pid=%x tag=%x addr=%p len=%ld match_bits=%lx", - (void*)frag, endpoint->ptl_proc.rank, endpoint->ptl_proc.phys.pid, tag, - (void *)frag->segments[0].base.seg_addr.pval, put_length, (uint64_t)match_bits)); + "PtlPut frag=%p rank=%x pid=%x tag=%x addr=%p len=%ld match_bits=%lx", + (void *) frag, endpoint->ptl_proc.rank, endpoint->ptl_proc.phys.pid, tag, + (void *) frag->segments[0].base.seg_addr.pval, put_length, + (uint64_t) match_bits)); return OPAL_SUCCESS; } /* NOT IMPLEMENTED */ -int mca_btl_portals4_sendi(struct mca_btl_base_module_t* btl_base, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - void* header, - size_t header_size, - size_t payload_size, - uint8_t order, - uint32_t flags, - mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t** des) +int mca_btl_portals4_sendi(struct mca_btl_base_module_t *btl_base, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, + mca_btl_base_tag_t tag, mca_btl_base_descriptor_t **des) { - opal_output(opal_btl_base_framework.framework_output, "mca_btl_portals_sendi is not implemented"); + opal_output(opal_btl_base_framework.framework_output, + "mca_btl_portals_sendi is not implemented"); BTL_ERROR(("mca_btl_portals_sendi is not implemented")); return OPAL_SUCCESS; } diff --git a/opal/mca/btl/self/btl_self.c b/opal/mca/btl/self/btl_self.c index 1b247a78480..0e8b5299d06 100644 --- a/opal/mca/btl/self/btl_self.c +++ b/opal/mca/btl/self/btl_self.c @@ -25,13 +25,13 @@ #include "opal_config.h" -#include #include +#include -#include "opal/class/opal_bitmap.h" -#include "opal/datatype/opal_convertor.h" #include "btl_self.h" #include "btl_self_frag.h" +#include "opal/class/opal_bitmap.h" +#include "opal/datatype/opal_convertor.h" #include "opal/util/proc.h" /** @@ -47,17 +47,17 @@ * @return OPAL_SUCCESS or error status on failure. * */ -static int mca_btl_self_add_procs (struct mca_btl_base_module_t *btl, size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers, - opal_bitmap_t* reachability) +static int mca_btl_self_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachability) { - for (int i = 0; i < (int)nprocs; i++ ) { - if( 0 == opal_compare_proc(procs[i]->proc_name, OPAL_PROC_MY_NAME) ) { - opal_bitmap_set_bit( reachability, i ); + for (int i = 0; i < (int) nprocs; i++) { + if (0 == opal_compare_proc(procs[i]->proc_name, OPAL_PROC_MY_NAME)) { + opal_bitmap_set_bit(reachability, i); /* need to return something to keep the bml from ignoring us */ peers[i] = (struct mca_btl_base_endpoint_t *) 1; - break; /* there will always be only one ... */ + break; /* there will always be only one ... */ } } @@ -73,14 +73,13 @@ static int mca_btl_self_add_procs (struct mca_btl_base_module_t *btl, size_t npr * @return Status indicating if cleanup was successful * */ -static int mca_btl_self_del_procs (struct mca_btl_base_module_t *btl, size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers) +static int mca_btl_self_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers) { return OPAL_SUCCESS; } - /** * MCA->BTL Clean up any resources held by BTL module * before the module is unloaded. @@ -94,21 +93,20 @@ static int mca_btl_self_del_procs (struct mca_btl_base_module_t *btl, size_t npr * */ -static int mca_btl_self_finalize(struct mca_btl_base_module_t* btl) +static int mca_btl_self_finalize(struct mca_btl_base_module_t *btl) { return OPAL_SUCCESS; } - /** * Allocate a segment. * * @param btl (IN) BTL module * @param size (IN) Request segment size. */ -static mca_btl_base_descriptor_t *mca_btl_self_alloc (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags) +static mca_btl_base_descriptor_t *mca_btl_self_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { mca_btl_self_frag_t *frag = NULL; @@ -120,13 +118,13 @@ static mca_btl_base_descriptor_t *mca_btl_self_alloc (struct mca_btl_base_module MCA_BTL_SELF_FRAG_ALLOC_SEND(frag); } - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } frag->segments[0].seg_len = size; frag->base.des_segment_count = 1; - frag->base.des_flags = flags; + frag->base.des_flags = flags; return &frag->base; } @@ -137,44 +135,42 @@ static mca_btl_base_descriptor_t *mca_btl_self_alloc (struct mca_btl_base_module * @param btl (IN) BTL module * @param segment (IN) Allocated segment. */ -static int mca_btl_self_free (struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) +static int mca_btl_self_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { MCA_BTL_SELF_FRAG_RETURN((mca_btl_self_frag_t *) des); return OPAL_SUCCESS; } - /** * Prepare data for send * * @param btl (IN) BTL module */ -static struct mca_btl_base_descriptor_t *mca_btl_self_prepare_src (struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, size_t reserve, - size_t *size, uint32_t flags) +static struct mca_btl_base_descriptor_t *mca_btl_self_prepare_src( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, uint32_t flags) { bool inline_send = !opal_convertor_need_buffers(convertor); size_t buffer_len = reserve + (inline_send ? 0 : *size); mca_btl_self_frag_t *frag; - frag = (mca_btl_self_frag_t *) mca_btl_self_alloc (btl, endpoint, order, buffer_len, flags); + frag = (mca_btl_self_frag_t *) mca_btl_self_alloc(btl, endpoint, order, buffer_len, flags); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } /* non-contigous data */ if (OPAL_UNLIKELY(!inline_send)) { - struct iovec iov = {.iov_len = *size, .iov_base = (IOVBASE_TYPE *) ((uintptr_t) frag->data + reserve)}; + struct iovec iov = {.iov_len = *size, + .iov_base = (IOVBASE_TYPE *) ((uintptr_t) frag->data + reserve)}; size_t max_data = *size; uint32_t iov_count = 1; int rc; - rc = opal_convertor_pack (convertor, &iov, &iov_count, &max_data); - if(rc < 0) { - mca_btl_self_free (btl, &frag->base); + rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); + if (rc < 0) { + mca_btl_self_free(btl, &frag->base); return NULL; } @@ -183,7 +179,7 @@ static struct mca_btl_base_descriptor_t *mca_btl_self_prepare_src (struct mca_bt } else { void *data_ptr; - opal_convertor_get_current_pointer (convertor, &data_ptr); + opal_convertor_get_current_pointer(convertor, &data_ptr); frag->segments[1].seg_addr.pval = data_ptr; frag->segments[1].seg_len = *size; @@ -200,10 +196,9 @@ static struct mca_btl_base_descriptor_t *mca_btl_self_prepare_src (struct mca_bt * @param peer (IN) BTL peer addressing */ -static int mca_btl_self_send (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - struct mca_btl_base_descriptor_t *des, - mca_btl_base_tag_t tag) +static int mca_btl_self_send(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *des, mca_btl_base_tag_t tag) { mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + tag; mca_btl_base_receive_descriptor_t recv_desc = {.endpoint = endpoint, @@ -214,88 +209,92 @@ static int mca_btl_self_send (struct mca_btl_base_module_t *btl, int btl_ownership = (des->des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); /* upcall */ - reg->cbfunc (btl, &recv_desc); + reg->cbfunc(btl, &recv_desc); /* send completion */ - if( des->des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK ) { - des->des_cbfunc( btl, endpoint, des, OPAL_SUCCESS ); + if (des->des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) { + des->des_cbfunc(btl, endpoint, des, OPAL_SUCCESS); } - if( btl_ownership ) { - mca_btl_self_free( btl, des ); + if (btl_ownership) { + mca_btl_self_free(btl, des); } return 1; } -static int mca_btl_self_sendi (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, void *header, size_t header_size, - size_t payload_size, uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t **descriptor) +static int mca_btl_self_sendi(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, + mca_btl_base_tag_t tag, mca_btl_base_descriptor_t **descriptor) { mca_btl_base_descriptor_t *frag; if (!payload_size || !opal_convertor_need_buffers(convertor)) { void *data_ptr = NULL; if (payload_size) { - opal_convertor_get_current_pointer (convertor, &data_ptr); + opal_convertor_get_current_pointer(convertor, &data_ptr); } mca_btl_base_segment_t segments[2] = {{.seg_addr.pval = header, .seg_len = header_size}, {.seg_addr.pval = data_ptr, .seg_len = payload_size}}; - mca_btl_base_descriptor_t des = {.des_segments = segments, .des_segment_count = payload_size ? 2 : 1, + mca_btl_base_descriptor_t des = {.des_segments = segments, + .des_segment_count = payload_size ? 2 : 1, .des_flags = 0}; - (void) mca_btl_self_send (btl, endpoint, &des, tag); + (void) mca_btl_self_send(btl, endpoint, &des, tag); return OPAL_SUCCESS; } - frag = mca_btl_self_prepare_src (btl, endpoint, convertor, order, header_size, &payload_size, - flags | MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); + frag = mca_btl_self_prepare_src(btl, endpoint, convertor, order, header_size, &payload_size, + flags | MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); if (NULL == frag) { *descriptor = NULL; return OPAL_ERR_OUT_OF_RESOURCE; } - memcpy (frag->des_segments[0].seg_addr.pval, header, header_size); - (void) mca_btl_self_send (btl, endpoint, frag, tag); + memcpy(frag->des_segments[0].seg_addr.pval, header, header_size); + (void) mca_btl_self_send(btl, endpoint, frag, tag); return OPAL_SUCCESS; } -static int mca_btl_self_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +static int mca_btl_self_put(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { - memcpy ((void *)(intptr_t) remote_address, local_address, size); + memcpy((void *) (intptr_t) remote_address, local_address, size); - cbfunc (btl, endpoint, local_address, NULL, cbcontext, cbdata, OPAL_SUCCESS); + cbfunc(btl, endpoint, local_address, NULL, cbcontext, cbdata, OPAL_SUCCESS); return OPAL_SUCCESS; } -static int mca_btl_self_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +static int mca_btl_self_get(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { - memcpy (local_address, (void *)(intptr_t) remote_address, size); + memcpy(local_address, (void *) (intptr_t) remote_address, size); - cbfunc (btl, endpoint, local_address, NULL, cbcontext, cbdata, OPAL_SUCCESS); + cbfunc(btl, endpoint, local_address, NULL, cbcontext, cbdata, OPAL_SUCCESS); return OPAL_SUCCESS; } /* btl self module */ -mca_btl_base_module_t mca_btl_self = { - .btl_component = &mca_btl_self_component.super, - .btl_add_procs = mca_btl_self_add_procs, - .btl_del_procs = mca_btl_self_del_procs, - .btl_finalize = mca_btl_self_finalize, - .btl_alloc = mca_btl_self_alloc, - .btl_free = mca_btl_self_free, - .btl_prepare_src = mca_btl_self_prepare_src, - .btl_send = mca_btl_self_send, - .btl_sendi = mca_btl_self_sendi, - .btl_put = mca_btl_self_put, - .btl_get = mca_btl_self_get, - .btl_dump = mca_btl_base_dump -}; +mca_btl_base_module_t mca_btl_self = {.btl_component = &mca_btl_self_component.super, + .btl_add_procs = mca_btl_self_add_procs, + .btl_del_procs = mca_btl_self_del_procs, + .btl_finalize = mca_btl_self_finalize, + .btl_alloc = mca_btl_self_alloc, + .btl_free = mca_btl_self_free, + .btl_prepare_src = mca_btl_self_prepare_src, + .btl_send = mca_btl_self_send, + .btl_sendi = mca_btl_self_sendi, + .btl_put = mca_btl_self_put, + .btl_get = mca_btl_self_get, + .btl_dump = mca_btl_base_dump}; diff --git a/opal/mca/btl/self/btl_self.h b/opal/mca/btl/self/btl_self.h index ac4cab6eb6a..1f7e40d6470 100644 --- a/opal/mca/btl/self/btl_self.h +++ b/opal/mca/btl/self/btl_self.h @@ -28,11 +28,11 @@ #include #ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ +# include +#endif /* HAVE_SYS_TYPES_H */ -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" BEGIN_C_DECLS @@ -42,13 +42,13 @@ BEGIN_C_DECLS * Shared Memory (SELF) BTL module. */ struct mca_btl_self_component_t { - mca_btl_base_component_3_0_0_t super; /**< base BTL component */ - int free_list_num; /**< initial size of free lists */ - int free_list_max; /**< maximum size of free lists */ - int free_list_inc; /**< number of elements to alloc when growing free lists */ - opal_free_list_t self_frags_eager; /**< free list of self first */ - opal_free_list_t self_frags_send; /**< free list of self second */ - opal_free_list_t self_frags_rdma; /**< free list of self second */ + mca_btl_base_component_3_0_0_t super; /**< base BTL component */ + int free_list_num; /**< initial size of free lists */ + int free_list_max; /**< maximum size of free lists */ + int free_list_inc; /**< number of elements to alloc when growing free lists */ + opal_free_list_t self_frags_eager; /**< free list of self first */ + opal_free_list_t self_frags_send; /**< free list of self second */ + opal_free_list_t self_frags_rdma; /**< free list of self second */ }; typedef struct mca_btl_self_component_t mca_btl_self_component_t; OPAL_MODULE_DECLSPEC extern mca_btl_self_component_t mca_btl_self_component; @@ -58,4 +58,3 @@ extern mca_btl_base_module_t mca_btl_self; END_C_DECLS #endif - diff --git a/opal/mca/btl/self/btl_self_component.c b/opal/mca/btl/self/btl_self_component.c index 271d28215e6..576716e4d73 100644 --- a/opal/mca/btl/self/btl_self_component.c +++ b/opal/mca/btl/self/btl_self_component.c @@ -32,35 +32,39 @@ static int mca_btl_self_component_close(void); * SELF module initialization. * * @param num_btls (OUT) Number of BTLs returned in BTL array. - * @param enable_progress_threads (IN) Flag indicating whether BTL is allowed to have progress threads - * @param enable_mpi_threads (IN) Flag indicating whether BTL must support multilple simultaneous invocations from different threads + * @param enable_progress_threads (IN) Flag indicating whether BTL is allowed to have progress + * threads + * @param enable_mpi_threads (IN) Flag indicating whether BTL must support multilple + * simultaneous invocations from different threads * */ -static mca_btl_base_module_t **mca_btl_self_component_init (int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads); +static mca_btl_base_module_t ** +mca_btl_self_component_init(int *num_btls, bool enable_progress_threads, bool enable_mpi_threads); /* * Shared Memory (SELF) component instance. */ mca_btl_self_component_t mca_btl_self_component = { - .super = { - /* First, the mca_base_component_t struct containing meta information - about the component itself */ - .btl_version = { - MCA_BTL_DEFAULT_VERSION("self"), - .mca_open_component = mca_btl_self_component_open, - .mca_close_component = mca_btl_self_component_close, - .mca_register_component_params = mca_btl_self_component_register, - }, - .btl_data = { - /* The component is checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT, - }, - - .btl_init = mca_btl_self_component_init, - } /* end super */ + .super = + { + /* First, the mca_base_component_t struct containing meta information + about the component itself */ + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("self"), + .mca_open_component = mca_btl_self_component_open, + .mca_close_component = mca_btl_self_component_close, + .mca_register_component_params = mca_btl_self_component_register, + }, + .btl_data = + { + /* The component is checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT, + }, + + .btl_init = mca_btl_self_component_init, + } /* end super */ }; /* @@ -75,25 +79,23 @@ static int mca_btl_self_component_register(void) /* register SELF component parameters */ mca_btl_self_component.free_list_num = 0; - (void) mca_base_component_var_register(&mca_btl_self_component.super.btl_version, "free_list_num", - "Number of fragments by default", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, + (void) mca_base_component_var_register(&mca_btl_self_component.super.btl_version, + "free_list_num", "Number of fragments by default", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_self_component.free_list_num); - /* NTH: free list buffers are not released until we tear down so DO NOT make them unlimited here */ + /* NTH: free list buffers are not released until we tear down so DO NOT make them unlimited here + */ mca_btl_self_component.free_list_max = 64; - (void) mca_base_component_var_register(&mca_btl_self_component.super.btl_version, "free_list_max", - "Maximum number of fragments", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, + (void) mca_base_component_var_register(&mca_btl_self_component.super.btl_version, + "free_list_max", "Maximum number of fragments", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_self_component.free_list_max); mca_btl_self_component.free_list_inc = 8; - (void) mca_base_component_var_register(&mca_btl_self_component.super.btl_version, "free_list_inc", - "Increment by this number of fragments", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, + (void) mca_base_component_var_register(&mca_btl_self_component.super.btl_version, + "free_list_inc", "Increment by this number of fragments", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_self_component.free_list_inc); @@ -107,7 +109,7 @@ static int mca_btl_self_component_register(void) mca_btl_self.btl_flags = MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_SEND_INPLACE | MCA_BTL_FLAGS_SEND; mca_btl_self.btl_bandwidth = 100; mca_btl_self.btl_latency = 0; - mca_btl_base_param_register (&mca_btl_self_component.super.btl_version, &mca_btl_self); + mca_btl_base_param_register(&mca_btl_self_component.super.btl_version, &mca_btl_self); return OPAL_SUCCESS; } @@ -122,7 +124,6 @@ static int mca_btl_self_component_open(void) return OPAL_SUCCESS; } - /* * component cleanup - sanity checking of queue lengths */ @@ -138,49 +139,45 @@ static int mca_btl_self_component_close(void) /* * SELF component initialization */ -static mca_btl_base_module_t **mca_btl_self_component_init (int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads) +static mca_btl_base_module_t ** +mca_btl_self_component_init(int *num_btls, bool enable_progress_threads, bool enable_mpi_threads) { mca_btl_base_module_t **btls = NULL; int ret; /* initialize free lists */ - ret = opal_free_list_init (&mca_btl_self_component.self_frags_eager, - sizeof (mca_btl_self_frag_eager_t) + mca_btl_self.btl_eager_limit, - opal_cache_line_size, OBJ_CLASS(mca_btl_self_frag_eager_t), 0, - opal_cache_line_size, mca_btl_self_component.free_list_num, - mca_btl_self_component.free_list_max, - mca_btl_self_component.free_list_inc, - NULL, 0, NULL, NULL, NULL); + ret = opal_free_list_init(&mca_btl_self_component.self_frags_eager, + sizeof(mca_btl_self_frag_eager_t) + mca_btl_self.btl_eager_limit, + opal_cache_line_size, OBJ_CLASS(mca_btl_self_frag_eager_t), 0, + opal_cache_line_size, mca_btl_self_component.free_list_num, + mca_btl_self_component.free_list_max, + mca_btl_self_component.free_list_inc, NULL, 0, NULL, NULL, NULL); if (OPAL_SUCCESS != ret) { return NULL; } - ret = opal_free_list_init (&mca_btl_self_component.self_frags_send, - sizeof (mca_btl_self_frag_send_t) + mca_btl_self.btl_max_send_size, - opal_cache_line_size, OBJ_CLASS(mca_btl_self_frag_send_t), 0, - opal_cache_line_size, mca_btl_self_component.free_list_num, - mca_btl_self_component.free_list_max, - mca_btl_self_component.free_list_inc, - NULL, 0, NULL, NULL, NULL); + ret = opal_free_list_init(&mca_btl_self_component.self_frags_send, + sizeof(mca_btl_self_frag_send_t) + mca_btl_self.btl_max_send_size, + opal_cache_line_size, OBJ_CLASS(mca_btl_self_frag_send_t), 0, + opal_cache_line_size, mca_btl_self_component.free_list_num, + mca_btl_self_component.free_list_max, + mca_btl_self_component.free_list_inc, NULL, 0, NULL, NULL, NULL); if (OPAL_SUCCESS != ret) { return NULL; } - ret = opal_free_list_init (&mca_btl_self_component.self_frags_rdma, - sizeof (mca_btl_self_frag_rdma_t) + MCA_BTL_SELF_MAX_INLINE_SIZE, - opal_cache_line_size, OBJ_CLASS(mca_btl_self_frag_rdma_t), 0, - opal_cache_line_size, mca_btl_self_component.free_list_num, - mca_btl_self_component.free_list_max, - mca_btl_self_component.free_list_inc, - NULL, 0, NULL, NULL, NULL); + ret = opal_free_list_init(&mca_btl_self_component.self_frags_rdma, + sizeof(mca_btl_self_frag_rdma_t) + MCA_BTL_SELF_MAX_INLINE_SIZE, + opal_cache_line_size, OBJ_CLASS(mca_btl_self_frag_rdma_t), 0, + opal_cache_line_size, mca_btl_self_component.free_list_num, + mca_btl_self_component.free_list_max, + mca_btl_self_component.free_list_inc, NULL, 0, NULL, NULL, NULL); if (OPAL_SUCCESS != ret) { return NULL; } /* get pointer to the btls */ - btls = (mca_btl_base_module_t **) malloc (sizeof (mca_btl_base_module_t *)); + btls = (mca_btl_base_module_t **) malloc(sizeof(mca_btl_base_module_t *)); if (NULL == btls) { return NULL; } @@ -190,4 +187,3 @@ static mca_btl_base_module_t **mca_btl_self_component_init (int *num_btls, return btls; } - diff --git a/opal/mca/btl/self/btl_self_frag.c b/opal/mca/btl/self/btl_self_frag.c index eff0fbc4bec..00f2e62528a 100644 --- a/opal/mca/btl/self/btl_self_frag.c +++ b/opal/mca/btl/self/btl_self_frag.c @@ -22,7 +22,7 @@ #include "opal_config.h" #include "btl_self_frag.h" -static inline void mca_btl_self_frag_constructor(mca_btl_self_frag_t* frag) +static inline void mca_btl_self_frag_constructor(mca_btl_self_frag_t *frag) { frag->base.des_flags = 0; frag->segments[0].seg_addr.pval = (void *) frag->data; @@ -31,38 +31,32 @@ static inline void mca_btl_self_frag_constructor(mca_btl_self_frag_t* frag) frag->base.des_segment_count = 1; } -static void mca_btl_self_frag_eager_constructor(mca_btl_self_frag_t* frag) +static void mca_btl_self_frag_eager_constructor(mca_btl_self_frag_t *frag) { frag->list = &mca_btl_self_component.self_frags_eager; frag->size = mca_btl_self.btl_eager_limit; mca_btl_self_frag_constructor(frag); } -static void mca_btl_self_frag_send_constructor(mca_btl_self_frag_t* frag) +static void mca_btl_self_frag_send_constructor(mca_btl_self_frag_t *frag) { frag->list = &mca_btl_self_component.self_frags_send; frag->size = mca_btl_self.btl_max_send_size; mca_btl_self_frag_constructor(frag); } -static void mca_btl_self_frag_rdma_constructor(mca_btl_self_frag_t* frag) +static void mca_btl_self_frag_rdma_constructor(mca_btl_self_frag_t *frag) { frag->list = &mca_btl_self_component.self_frags_rdma; frag->size = MCA_BTL_SELF_MAX_INLINE_SIZE; mca_btl_self_frag_constructor(frag); } -OBJ_CLASS_INSTANCE( mca_btl_self_frag_eager_t, - mca_btl_base_descriptor_t, - mca_btl_self_frag_eager_constructor, - NULL ); +OBJ_CLASS_INSTANCE(mca_btl_self_frag_eager_t, mca_btl_base_descriptor_t, + mca_btl_self_frag_eager_constructor, NULL); -OBJ_CLASS_INSTANCE( mca_btl_self_frag_send_t, - mca_btl_base_descriptor_t, - mca_btl_self_frag_send_constructor, - NULL ); +OBJ_CLASS_INSTANCE(mca_btl_self_frag_send_t, mca_btl_base_descriptor_t, + mca_btl_self_frag_send_constructor, NULL); -OBJ_CLASS_INSTANCE( mca_btl_self_frag_rdma_t, - mca_btl_base_descriptor_t, - mca_btl_self_frag_rdma_constructor, - NULL ); +OBJ_CLASS_INSTANCE(mca_btl_self_frag_rdma_t, mca_btl_base_descriptor_t, + mca_btl_self_frag_rdma_constructor, NULL); diff --git a/opal/mca/btl/self/btl_self_frag.h b/opal/mca/btl/self/btl_self_frag.h index 38236f1d7f5..9f59d6ed2b8 100644 --- a/opal/mca/btl/self/btl_self_frag.h +++ b/opal/mca/btl/self/btl_self_frag.h @@ -24,9 +24,8 @@ #ifndef MCA_BTL_SELF_SEND_FRAG_H #define MCA_BTL_SELF_SEND_FRAG_H -#include #include "btl_self.h" - +#include /** * shared memory send fragment derived type. @@ -48,28 +47,27 @@ OBJ_CLASS_DECLARATION(mca_btl_self_frag_eager_t); OBJ_CLASS_DECLARATION(mca_btl_self_frag_send_t); OBJ_CLASS_DECLARATION(mca_btl_self_frag_rdma_t); -#define MCA_BTL_SELF_FRAG_ALLOC_EAGER(frag) \ - { \ - frag = (mca_btl_self_frag_t *) \ - opal_free_list_get (&mca_btl_self_component.self_frags_eager); \ +#define MCA_BTL_SELF_FRAG_ALLOC_EAGER(frag) \ + { \ + frag = (mca_btl_self_frag_t *) opal_free_list_get( \ + &mca_btl_self_component.self_frags_eager); \ } - -#define MCA_BTL_SELF_FRAG_ALLOC_RDMA(frag) \ - { \ - frag = (mca_btl_self_frag_t *) \ - opal_free_list_get (&mca_btl_self_component.self_frags_rdma); \ +#define MCA_BTL_SELF_FRAG_ALLOC_RDMA(frag) \ + { \ + frag = (mca_btl_self_frag_t *) opal_free_list_get( \ + &mca_btl_self_component.self_frags_rdma); \ } -#define MCA_BTL_SELF_FRAG_ALLOC_SEND(frag) \ - { \ - frag = (mca_btl_self_frag_t *) \ - opal_free_list_get (&mca_btl_self_component.self_frags_send); \ +#define MCA_BTL_SELF_FRAG_ALLOC_SEND(frag) \ + { \ + frag = (mca_btl_self_frag_t *) opal_free_list_get( \ + &mca_btl_self_component.self_frags_send); \ } -#define MCA_BTL_SELF_FRAG_RETURN(frag) \ - { \ - opal_free_list_return ((frag)->list, (opal_free_list_item_t*)(frag)); \ +#define MCA_BTL_SELF_FRAG_RETURN(frag) \ + { \ + opal_free_list_return((frag)->list, (opal_free_list_item_t *) (frag)); \ } #endif /* MCA_BTL_SELF_SEND_FRAG_H */ diff --git a/opal/mca/btl/sm/btl_sm_component.c b/opal/mca/btl/sm/btl_sm_component.c index bc2ded26a59..da9b3632a5f 100644 --- a/opal/mca/btl/sm/btl_sm_component.c +++ b/opal/mca/btl/sm/btl_sm_component.c @@ -322,8 +322,8 @@ static int mca_btl_sm_component_close(void) OBJ_DESTRUCT(&mca_btl_sm_component.pending_endpoints); OBJ_DESTRUCT(&mca_btl_sm_component.pending_fragments); - if (MCA_BTL_SM_XPMEM == mca_btl_sm_component.single_copy_mechanism && - NULL != mca_btl_sm_component.my_segment) { + if (MCA_BTL_SM_XPMEM == mca_btl_sm_component.single_copy_mechanism + && NULL != mca_btl_sm_component.my_segment) { munmap(mca_btl_sm_component.my_segment, mca_btl_sm_component.segment_size); } @@ -531,8 +531,8 @@ mca_btl_sm_component_init(int *num_btls, bool enable_progress_threads, bool enab component->segment_size = (2 << 20); } - component->fbox_size = (component->fbox_size + MCA_BTL_SM_FBOX_ALIGNMENT_MASK) & - ~MCA_BTL_SM_FBOX_ALIGNMENT_MASK; + component->fbox_size = (component->fbox_size + MCA_BTL_SM_FBOX_ALIGNMENT_MASK) + & ~MCA_BTL_SM_FBOX_ALIGNMENT_MASK; if (component->segment_size > (1ul << MCA_BTL_SM_OFFSET_BITS)) { component->segment_size = 2ul << MCA_BTL_SM_OFFSET_BITS; @@ -652,8 +652,8 @@ void mca_btl_sm_poll_handle_frag(mca_btl_sm_hdr_t *hdr, struct mca_btl_base_endp if (OPAL_UNLIKELY(MCA_BTL_SM_FLAG_SETUP_FBOX & hdr->flags)) { mca_btl_sm_endpoint_setup_fbox_recv(endpoint, relative2virtual(hdr->fbox_base)); - mca_btl_sm_component - .fbox_in_endpoints[mca_btl_sm_component.num_fbox_in_endpoints++] = endpoint; + mca_btl_sm_component.fbox_in_endpoints[mca_btl_sm_component.num_fbox_in_endpoints++] + = endpoint; } hdr->flags = MCA_BTL_SM_FLAG_COMPLETE; diff --git a/opal/mca/btl/sm/btl_sm_fbox.h b/opal/mca/btl/sm/btl_sm_fbox.h index fb50851e526..dc3dc68eb31 100644 --- a/opal/mca/btl/sm/btl_sm_fbox.h +++ b/opal/mca/btl/sm/btl_sm_fbox.h @@ -143,8 +143,8 @@ static inline bool mca_btl_sm_fbox_sendi(mca_btl_base_endpoint_t *ep, unsigned c buffer_free = BUFFER_FREE(start, end, hbm, fbox_size); /* need space for the fragment + the header */ - size = (size + sizeof(mca_btl_sm_fbox_hdr_t) + MCA_BTL_SM_FBOX_ALIGNMENT_MASK) & - ~MCA_BTL_SM_FBOX_ALIGNMENT_MASK; + size = (size + sizeof(mca_btl_sm_fbox_hdr_t) + MCA_BTL_SM_FBOX_ALIGNMENT_MASK) + & ~MCA_BTL_SM_FBOX_ALIGNMENT_MASK; dst = ep->fbox_out.buffer + end; @@ -258,8 +258,8 @@ static inline bool mca_btl_sm_check_fboxes(void) /* the 0xff tag indicates we should skip the rest of the buffer */ if (OPAL_LIKELY((0xfe & hdr.data.tag) != 0xfe)) { mca_btl_base_segment_t segment; - const mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + - hdr.data.tag; + const mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + + hdr.data.tag; mca_btl_base_receive_descriptor_t desc = {.endpoint = ep, .des_segments = &segment, .des_segment_count = 1, @@ -283,8 +283,8 @@ static inline bool mca_btl_sm_check_fboxes(void) mca_btl_sm_poll_handle_frag(hdr, ep); } - start = (start + hdr.data.size + sizeof(hdr) + MCA_BTL_SM_FBOX_ALIGNMENT_MASK) & - ~MCA_BTL_SM_FBOX_ALIGNMENT_MASK; + start = (start + hdr.data.size + sizeof(hdr) + MCA_BTL_SM_FBOX_ALIGNMENT_MASK) + & ~MCA_BTL_SM_FBOX_ALIGNMENT_MASK; if (OPAL_UNLIKELY(fbox_size == start)) { /* jump to the beginning of the buffer */ start = MCA_BTL_SM_FBOX_ALIGNMENT; @@ -310,9 +310,9 @@ static inline bool mca_btl_sm_check_fboxes(void) static inline void mca_btl_sm_try_fbox_setup(mca_btl_base_endpoint_t *ep, mca_btl_sm_hdr_t *hdr) { - if (OPAL_UNLIKELY(NULL == ep->fbox_out.buffer && - mca_btl_sm_component.fbox_threshold == - OPAL_THREAD_ADD_FETCH_SIZE_T(&ep->send_count, 1))) { + if (OPAL_UNLIKELY(NULL == ep->fbox_out.buffer + && mca_btl_sm_component.fbox_threshold + == OPAL_THREAD_ADD_FETCH_SIZE_T(&ep->send_count, 1))) { /* protect access to mca_btl_sm_component.segment_offset */ OPAL_THREAD_LOCK(&mca_btl_sm_component.lock); diff --git a/opal/mca/btl/sm/btl_sm_frag.h b/opal/mca/btl/sm/btl_sm_frag.h index 6d31bd43ebf..7d31fa8ed7d 100644 --- a/opal/mca/btl/sm/btl_sm_frag.h +++ b/opal/mca/btl/sm/btl_sm_frag.h @@ -94,8 +94,8 @@ static inline void mca_btl_sm_rdma_frag_advance(mca_btl_base_module_t *btl, if (frag->rdma.sent) { if (MCA_BTL_SM_OP_GET == hdr->type) { memcpy(frag->rdma.local_address, data, len); - } else if ((MCA_BTL_SM_OP_ATOMIC == hdr->type || MCA_BTL_SM_OP_CSWAP == hdr->type) && - frag->rdma.local_address) { + } else if ((MCA_BTL_SM_OP_ATOMIC == hdr->type || MCA_BTL_SM_OP_CSWAP == hdr->type) + && frag->rdma.local_address) { if (8 == len) { *((int64_t *) frag->rdma.local_address) = hdr->operand[0]; } else { diff --git a/opal/mca/btl/sm/btl_sm_knem.c b/opal/mca/btl/sm/btl_sm_knem.c index e865c319c1c..dc5cd927d6b 100644 --- a/opal/mca/btl/sm/btl_sm_knem.c +++ b/opal/mca/btl/sm/btl_sm_knem.c @@ -93,10 +93,10 @@ static int mca_btl_sm_deregister_mem_knem(struct mca_btl_base_module_t *btl, struct mca_btl_base_registration_handle_t *handle) { mca_btl_sm_t *sm_module = (mca_btl_sm_t *) btl; - mca_btl_sm_registration_handle_t - *reg = (mca_btl_sm_registration_handle_t *) ((intptr_t) handle - - offsetof(mca_btl_sm_registration_handle_t, - btl_handle)); + mca_btl_sm_registration_handle_t *reg = (mca_btl_sm_registration_handle_t + *) ((intptr_t) handle + - offsetof(mca_btl_sm_registration_handle_t, + btl_handle)); sm_module->knem_rcache->rcache_deregister(sm_module->knem_rcache, ®->base); diff --git a/opal/mca/btl/sm/btl_sm_module.c b/opal/mca/btl/sm/btl_sm_module.c index ad455720ff1..8720f17f317 100644 --- a/opal/mca/btl/sm/btl_sm_module.c +++ b/opal/mca/btl/sm/btl_sm_module.c @@ -104,10 +104,10 @@ static int sm_btl_first_time_init(mca_btl_sm_t *sm_btl, int n) return OPAL_ERR_OUT_OF_RESOURCE; } - component->mpool = mca_mpool_basic_create((void *) (component->my_segment + - MCA_BTL_SM_FIFO_SIZE), - (unsigned long) (mca_btl_sm_component.segment_size - - MCA_BTL_SM_FIFO_SIZE), + component->mpool = mca_mpool_basic_create((void *) (component->my_segment + + MCA_BTL_SM_FIFO_SIZE), + (unsigned long) (mca_btl_sm_component.segment_size + - MCA_BTL_SM_FIFO_SIZE), 64); if (NULL == component->mpool) { free(component->endpoints); @@ -334,8 +334,8 @@ static int sm_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, for (int32_t proc = 0; proc < (int32_t) nprocs; ++proc) { /* check to see if this proc can be reached via shmem (i.e., if they're on my local host and in my job) */ - if (procs[proc]->proc_name.jobid != my_proc->proc_name.jobid || - !OPAL_PROC_ON_LOCAL_NODE(procs[proc]->proc_flags)) { + if (procs[proc]->proc_name.jobid != my_proc->proc_name.jobid + || !OPAL_PROC_ON_LOCAL_NODE(procs[proc]->proc_flags)) { peers[proc] = NULL; continue; } @@ -459,8 +459,8 @@ mca_btl_base_descriptor_t *mca_btl_sm_alloc(struct mca_btl_base_module_t *btl, MCA_BTL_SM_FRAG_ALLOC_USER(frag, endpoint); } else if (size <= mca_btl_sm.super.btl_eager_limit) { MCA_BTL_SM_FRAG_ALLOC_EAGER(frag, endpoint); - } else if (MCA_BTL_SM_XPMEM != mca_btl_sm_component.single_copy_mechanism && - size <= mca_btl_sm.super.btl_max_send_size) { + } else if (MCA_BTL_SM_XPMEM != mca_btl_sm_component.single_copy_mechanism + && size <= mca_btl_sm.super.btl_max_send_size) { MCA_BTL_SM_FRAG_ALLOC_MAX(frag, endpoint); } @@ -512,8 +512,8 @@ static struct mca_btl_base_descriptor_t *sm_prepare_src(struct mca_btl_base_modu struct iovec iov; /* non-contiguous data requires the convertor */ - if (MCA_BTL_SM_XPMEM != mca_btl_sm_component.single_copy_mechanism && - total_size > mca_btl_sm.super.btl_eager_limit) { + if (MCA_BTL_SM_XPMEM != mca_btl_sm_component.single_copy_mechanism + && total_size > mca_btl_sm.super.btl_eager_limit) { MCA_BTL_SM_FRAG_ALLOC_MAX(frag, endpoint); } else { MCA_BTL_SM_FRAG_ALLOC_EAGER(frag, endpoint); @@ -550,8 +550,8 @@ static struct mca_btl_base_descriptor_t *sm_prepare_src(struct mca_btl_base_modu #if OPAL_BTL_SM_HAVE_XPMEM /* use xpmem to send this segment if it is above the max inline send size */ - if (OPAL_UNLIKELY(MCA_BTL_SM_XPMEM == mca_btl_sm_component.single_copy_mechanism && - total_size > (size_t) mca_btl_sm_component.max_inline_send)) { + if (OPAL_UNLIKELY(MCA_BTL_SM_XPMEM == mca_btl_sm_component.single_copy_mechanism + && total_size > (size_t) mca_btl_sm_component.max_inline_send)) { /* single copy send */ frag->hdr->flags = MCA_BTL_SM_FLAG_SINGLE_COPY; diff --git a/opal/mca/btl/sm/btl_sm_sendi.c b/opal/mca/btl/sm/btl_sm_sendi.c index efda4ffe67c..37df000c731 100644 --- a/opal/mca/btl/sm/btl_sm_sendi.c +++ b/opal/mca/btl/sm/btl_sm_sendi.c @@ -59,8 +59,8 @@ int mca_btl_sm_sendi(struct mca_btl_base_module_t *btl, struct mca_btl_base_endp opal_convertor_get_current_pointer(convertor, &data_ptr); } - if (!(payload_size && opal_convertor_need_buffers(convertor)) && - mca_btl_sm_fbox_sendi(endpoint, tag, header, header_size, data_ptr, payload_size)) { + if (!(payload_size && opal_convertor_need_buffers(convertor)) + && mca_btl_sm_fbox_sendi(endpoint, tag, header, header_size, data_ptr, payload_size)) { return OPAL_SUCCESS; } diff --git a/opal/mca/btl/sm/btl_sm_virtual.h b/opal/mca/btl/sm/btl_sm_virtual.h index 20c86160448..320e6f69a6c 100644 --- a/opal/mca/btl/sm/btl_sm_virtual.h +++ b/opal/mca/btl/sm/btl_sm_virtual.h @@ -53,22 +53,22 @@ /* This only works for finding the relative address for a pointer within my_segment */ static inline fifo_value_t virtual2relative(char *addr) { - return (fifo_value_t)((intptr_t)(addr - mca_btl_sm_component.my_segment)) | - ((fifo_value_t) MCA_BTL_SM_LOCAL_RANK << MCA_BTL_SM_OFFSET_BITS); + return (fifo_value_t)((intptr_t)(addr - mca_btl_sm_component.my_segment)) + | ((fifo_value_t) MCA_BTL_SM_LOCAL_RANK << MCA_BTL_SM_OFFSET_BITS); } static inline fifo_value_t virtual2relativepeer(struct mca_btl_base_endpoint_t *endpoint, char *addr) { - return (fifo_value_t)((intptr_t)(addr - endpoint->segment_base)) | - ((fifo_value_t) endpoint->peer_smp_rank << MCA_BTL_SM_OFFSET_BITS); + return (fifo_value_t)((intptr_t)(addr - endpoint->segment_base)) + | ((fifo_value_t) endpoint->peer_smp_rank << MCA_BTL_SM_OFFSET_BITS); } static inline void *relative2virtual(fifo_value_t offset) { return (void *) (intptr_t)( - (offset & MCA_BTL_SM_OFFSET_MASK) + - mca_btl_sm_component.endpoints[offset >> MCA_BTL_SM_OFFSET_BITS].segment_base); + (offset & MCA_BTL_SM_OFFSET_MASK) + + mca_btl_sm_component.endpoints[offset >> MCA_BTL_SM_OFFSET_BITS].segment_base); } #endif /* MCA_BTL_SM_VIRTUAL_H */ diff --git a/opal/mca/btl/sm/btl_sm_xpmem.c b/opal/mca/btl/sm/btl_sm_xpmem.c index 3fe37021d6b..eda6fbd85a2 100644 --- a/opal/mca/btl/sm/btl_sm_xpmem.c +++ b/opal/mca/btl/sm/btl_sm_xpmem.c @@ -201,8 +201,8 @@ mca_rcache_base_registration_t *sm_get_registation(struct mca_btl_base_endpoint_ } opal_atomic_wmb(); - *local_ptr = (void *) ((uintptr_t) reg->rcache_context + - (ptrdiff_t)((uintptr_t) rem_ptr - (uintptr_t) reg->base)); + *local_ptr = (void *) ((uintptr_t) reg->rcache_context + + (ptrdiff_t)((uintptr_t) rem_ptr - (uintptr_t) reg->base)); return reg; } @@ -234,8 +234,8 @@ void mca_btl_sm_xpmem_cleanup_endpoint(struct mca_btl_base_endpoint_t *ep) (void) mca_rcache_base_vma_iterate(mca_btl_sm_component.vma_module, NULL, (size_t) -1, true, mca_btl_sm_endpoint_xpmem_rcache_cleanup, (void *) &cleanup_ctx); - while (NULL != - (reg = (mca_rcache_base_registration_t *) opal_list_remove_first(®istrations))) { + while (NULL + != (reg = (mca_rcache_base_registration_t *) opal_list_remove_first(®istrations))) { sm_return_registration(reg, ep); } OBJ_DESTRUCT(®istrations); diff --git a/opal/mca/btl/smcuda/btl_smcuda.c b/opal/mca/btl/smcuda/btl_smcuda.c index ad155ae7f69..5784e79bdde 100644 --- a/opal/mca/btl/smcuda/btl_smcuda.c +++ b/opal/mca/btl/smcuda/btl_smcuda.c @@ -28,88 +28,87 @@ #include "opal_config.h" -#include #include +#include #ifdef HAVE_FCNTL_H -#include -#endif /* HAVE_FCNTL_H */ +# include +#endif /* HAVE_FCNTL_H */ #include #ifdef HAVE_SYS_MMAN_H -#include -#endif /* HAVE_SYS_MMAN_H */ +# include +#endif /* HAVE_SYS_MMAN_H */ #ifdef OPAL_BTL_SM_CMA_NEED_SYSCALL_DEFS -#include "opal/sys/cma.h" +# include "opal/sys/cma.h" #endif /* OPAL_BTL_SM_CMA_NEED_SYSCALL_DEFS */ -#include "opal/sys/atomic.h" #include "opal/class/opal_bitmap.h" -#include "opal/util/output.h" -#include "opal/util/show_help.h" -#include "opal/util/printf.h" +#include "opal/datatype/opal_convertor.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/hwloc/base/base.h" #include "opal/mca/pmix/base/base.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/shmem/shmem.h" -#include "opal/datatype/opal_convertor.h" -#include "opal/mca/btl/btl.h" +#include "opal/sys/atomic.h" +#include "opal/util/output.h" +#include "opal/util/printf.h" +#include "opal/util/show_help.h" #include "opal/mca/common/sm/common_sm_mpool.h" #if OPAL_CUDA_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" +# include "opal/mca/common/cuda/common_cuda.h" #endif /* OPAL_CUDA_SUPPORT */ #include "opal/mca/mpool/base/base.h" #include "opal/mca/rcache/base/base.h" #include "btl_smcuda.h" #include "btl_smcuda_endpoint.h" -#include "btl_smcuda_frag.h" #include "btl_smcuda_fifo.h" +#include "btl_smcuda_frag.h" #if OPAL_CUDA_SUPPORT -static struct mca_btl_base_registration_handle_t *mca_btl_smcuda_register_mem ( - struct mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags); +static struct mca_btl_base_registration_handle_t * +mca_btl_smcuda_register_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, + uint32_t flags); -static int mca_btl_smcuda_deregister_mem (struct mca_btl_base_module_t* btl, - struct mca_btl_base_registration_handle_t *handle); +static int mca_btl_smcuda_deregister_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_registration_handle_t *handle); #endif -mca_btl_smcuda_t mca_btl_smcuda = { - .super = { - .btl_component = &mca_btl_smcuda_component.super, - .btl_add_procs = mca_btl_smcuda_add_procs, - .btl_del_procs = mca_btl_smcuda_del_procs, - .btl_finalize = mca_btl_smcuda_finalize, - .btl_alloc = mca_btl_smcuda_alloc, - .btl_free = mca_btl_smcuda_free, - .btl_prepare_src = mca_btl_smcuda_prepare_src, +mca_btl_smcuda_t mca_btl_smcuda = {.super = { + .btl_component = &mca_btl_smcuda_component.super, + .btl_add_procs = mca_btl_smcuda_add_procs, + .btl_del_procs = mca_btl_smcuda_del_procs, + .btl_finalize = mca_btl_smcuda_finalize, + .btl_alloc = mca_btl_smcuda_alloc, + .btl_free = mca_btl_smcuda_free, + .btl_prepare_src = mca_btl_smcuda_prepare_src, #if OPAL_CUDA_SUPPORT - .btl_register_mem = mca_btl_smcuda_register_mem, - .btl_deregister_mem = mca_btl_smcuda_deregister_mem, + .btl_register_mem = mca_btl_smcuda_register_mem, + .btl_deregister_mem = mca_btl_smcuda_deregister_mem, #endif /* OPAL_CUDA_SUPPORT */ - .btl_send = mca_btl_smcuda_send, - .btl_sendi = mca_btl_smcuda_sendi, - .btl_dump = mca_btl_smcuda_dump, - .btl_register_error = mca_btl_smcuda_register_error_cb, - } -}; + .btl_send = mca_btl_smcuda_send, + .btl_sendi = mca_btl_smcuda_sendi, + .btl_dump = mca_btl_smcuda_dump, + .btl_register_error = mca_btl_smcuda_register_error_cb, + }}; #if OPAL_CUDA_SUPPORT -static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint); +static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint); #endif /* OPAL_CUDA_SUPPORT */ /* * calculate offset of an address from the beginning of a shared memory segment */ -#define ADDR2OFFSET(ADDR, BASE) ((char*)(ADDR) - (char*)(BASE)) +#define ADDR2OFFSET(ADDR, BASE) ((char *) (ADDR) - (char *) (BASE)) /* * calculate an absolute address in a local address space given an offset and * a base address of a shared memory segment */ -#define OFFSET2ADDR(OFFSET, BASE) ((ptrdiff_t)(OFFSET) + (char*)(BASE)) +#define OFFSET2ADDR(OFFSET, BASE) ((ptrdiff_t)(OFFSET) + (char *) (BASE)) static void *mpool_calloc(size_t nmemb, size_t size) { @@ -126,9 +125,8 @@ static void *mpool_calloc(size_t nmemb, size_t size) return buf; } -static int -setup_mpool_base_resources(mca_btl_smcuda_component_t *comp_ptr, - mca_common_sm_mpool_resources_t *out_res) +static int setup_mpool_base_resources(mca_btl_smcuda_component_t *comp_ptr, + mca_common_sm_mpool_resources_t *out_res) { int rc = OPAL_SUCCESS; int fd = -1; @@ -136,39 +134,37 @@ setup_mpool_base_resources(mca_btl_smcuda_component_t *comp_ptr, if (-1 == (fd = open(comp_ptr->sm_mpool_rndv_file_name, O_RDONLY))) { int err = errno; - opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, - "open(2)", strerror(err), err); + opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, "open(2)", strerror(err), + err); rc = OPAL_ERR_IN_ERRNO; goto out; } - if ((ssize_t)sizeof(opal_shmem_ds_t) != (bread = - read(fd, &out_res->bs_meta_buf, sizeof(opal_shmem_ds_t)))) { - opal_output(0, "setup_mpool_base_resources: " + if ((ssize_t) sizeof(opal_shmem_ds_t) + != (bread = read(fd, &out_res->bs_meta_buf, sizeof(opal_shmem_ds_t)))) { + opal_output(0, + "setup_mpool_base_resources: " "Read inconsistency -- read: %lu, but expected: %lu!\n", - (unsigned long)bread, - (unsigned long)sizeof(opal_shmem_ds_t)); + (unsigned long) bread, (unsigned long) sizeof(opal_shmem_ds_t)); rc = OPAL_ERROR; goto out; } - if ((ssize_t)sizeof(out_res->size) != (bread = - read(fd, &out_res->size, sizeof(size_t)))) { - opal_output(0, "setup_mpool_base_resources: " + if ((ssize_t) sizeof(out_res->size) != (bread = read(fd, &out_res->size, sizeof(size_t)))) { + opal_output(0, + "setup_mpool_base_resources: " "Read inconsistency -- read: %lu, but expected: %lu!\n", - (unsigned long)bread, - (unsigned long)sizeof(opal_shmem_ds_t)); + (unsigned long) bread, (unsigned long) sizeof(opal_shmem_ds_t)); rc = OPAL_ERROR; goto out; } out: if (-1 != fd) { - (void)close(fd); + (void) close(fd); } return rc; } -static int -sm_segment_attach(mca_btl_smcuda_component_t *comp_ptr) +static int sm_segment_attach(mca_btl_smcuda_component_t *comp_ptr) { int rc = OPAL_SUCCESS; int fd = -1; @@ -180,34 +176,34 @@ sm_segment_attach(mca_btl_smcuda_component_t *comp_ptr) } if (-1 == (fd = open(comp_ptr->sm_rndv_file_name, O_RDONLY))) { int err = errno; - opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, - "open(2)", strerror(err), err); + opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, "open(2)", strerror(err), + err); rc = OPAL_ERR_IN_ERRNO; goto out; } - if ((ssize_t)sizeof(opal_shmem_ds_t) != (bread = - read(fd, tmp_shmem_ds, sizeof(opal_shmem_ds_t)))) { - opal_output(0, "sm_segment_attach: " + if ((ssize_t) sizeof(opal_shmem_ds_t) + != (bread = read(fd, tmp_shmem_ds, sizeof(opal_shmem_ds_t)))) { + opal_output(0, + "sm_segment_attach: " "Read inconsistency -- read: %lu, but expected: %lu!\n", - (unsigned long)bread, - (unsigned long)sizeof(opal_shmem_ds_t)); + (unsigned long) bread, (unsigned long) sizeof(opal_shmem_ds_t)); rc = OPAL_ERROR; goto out; } - if (NULL == (comp_ptr->sm_seg = - mca_common_sm_module_attach(tmp_shmem_ds, - sizeof(mca_common_sm_seg_header_t), - opal_cache_line_size))) { + if (NULL + == (comp_ptr->sm_seg = mca_common_sm_module_attach(tmp_shmem_ds, + sizeof(mca_common_sm_seg_header_t), + opal_cache_line_size))) { /* don't have to detach here, because module_attach cleans up after * itself on failure. */ opal_output(0, "sm_segment_attach: " - "mca_common_sm_module_attach failure!\n"); + "mca_common_sm_module_attach failure!\n"); rc = OPAL_ERROR; } out: if (-1 != fd) { - (void)close(fd); + (void) close(fd); } if (tmp_shmem_ds) { free(tmp_shmem_ds); @@ -215,16 +211,13 @@ sm_segment_attach(mca_btl_smcuda_component_t *comp_ptr) return rc; } -static int -smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, - int32_t my_smp_rank, - int n) +static int smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, int32_t my_smp_rank, int n) { size_t length, length_payload; sm_fifo_t *my_fifos; int my_mem_node, num_mem_nodes, i, rc; mca_common_sm_mpool_resources_t *res = NULL; - mca_btl_smcuda_component_t* m = &mca_btl_smcuda_component; + mca_btl_smcuda_component_t *m = &mca_btl_smcuda_component; char *loc, *mynuma; opal_process_name_t wildcard_rank; @@ -235,8 +228,7 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, /* see if we were given a topology signature */ wildcard_rank.jobid = OPAL_PROC_MY_NAME.jobid; wildcard_rank.vpid = OPAL_VPID_WILDCARD; - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_TOPOLOGY_SIGNATURE, - &wildcard_rank, &loc, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_TOPOLOGY_SIGNATURE, &wildcard_rank, &loc, PMIX_STRING); if (OPAL_SUCCESS == rc) { /* the number of NUMA nodes is right at the front */ mca_btl_smcuda_component.num_mem_nodes = num_mem_nodes = strtoul(loc, NULL, 10); @@ -245,8 +237,7 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, /* If we have hwloc support, then get accurate information */ loc = NULL; if (OPAL_SUCCESS == opal_hwloc_base_get_topology()) { - i = opal_hwloc_base_get_nbobjs_by_type(opal_hwloc_topology, - HWLOC_OBJ_NODE, 0, + i = opal_hwloc_base_get_nbobjs_by_type(opal_hwloc_topology, HWLOC_OBJ_NODE, 0, OPAL_HWLOC_AVAILABLE); /* JMS This tells me how many numa nodes are *available*, @@ -259,17 +250,14 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, } } /* see if we were given our location */ - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCALITY_STRING, - &OPAL_PROC_MY_NAME, &loc, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCALITY_STRING, &OPAL_PROC_MY_NAME, &loc, PMIX_STRING); if (OPAL_SUCCESS == rc) { if (NULL == loc) { mca_btl_smcuda_component.mem_node = my_mem_node = -1; } else { /* get our NUMA location */ mynuma = opal_hwloc_base_get_location(loc, HWLOC_OBJ_NODE, 0); - if (NULL == mynuma || - NULL != strchr(mynuma, ',') || - NULL != strchr(mynuma, '-')) { + if (NULL == mynuma || NULL != strchr(mynuma, ',') || NULL != strchr(mynuma, '-')) { /* we either have no idea what NUMA we are on, or we * are on multiple NUMA nodes */ mca_btl_smcuda_component.mem_node = my_mem_node = -1; @@ -285,17 +273,17 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, } } else { /* If we have hwloc support, then get accurate information */ - if (OPAL_SUCCESS == opal_hwloc_base_get_topology() && - num_mem_nodes > 0 && NULL != opal_process_info.cpuset) { - int numa=0, w; - unsigned n_bound=0; + if (OPAL_SUCCESS == opal_hwloc_base_get_topology() && num_mem_nodes > 0 + && NULL != opal_process_info.cpuset) { + int numa = 0, w; + unsigned n_bound = 0; hwloc_obj_t obj; /* count the number of NUMA nodes to which we are bound */ - for (w=0; w < i; w++) { - if (NULL == (obj = opal_hwloc_base_get_obj_by_type(opal_hwloc_topology, - HWLOC_OBJ_NODE, 0, w, - OPAL_HWLOC_AVAILABLE))) { + for (w = 0; w < i; w++) { + if (NULL + == (obj = opal_hwloc_base_get_obj_by_type(opal_hwloc_topology, HWLOC_OBJ_NODE, + 0, w, OPAL_HWLOC_AVAILABLE))) { continue; } /* see if we intersect with that NUMA node's cpus */ @@ -320,9 +308,8 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, } /* lookup shared memory pool */ - mca_btl_smcuda_component.sm_mpools = - (mca_mpool_base_module_t **)calloc(num_mem_nodes, - sizeof(mca_mpool_base_module_t *)); + mca_btl_smcuda_component.sm_mpools = (mca_mpool_base_module_t **) + calloc(num_mem_nodes, sizeof(mca_mpool_base_module_t *)); /* Disable memory binding, because each MPI process will claim pages in the * mpool for their local NUMA node */ @@ -334,7 +321,7 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, return rc; } /* now that res is fully populated, create the thing */ - mca_btl_smcuda_component.sm_mpools[0] = common_sm_mpool_create (res); + mca_btl_smcuda_component.sm_mpools[0] = common_sm_mpool_create(res); /* Sanity check to ensure that we found it */ if (NULL == mca_btl_smcuda_component.sm_mpools[0]) { free(res); @@ -343,12 +330,12 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, mca_btl_smcuda_component.sm_mpool = mca_btl_smcuda_component.sm_mpools[0]; - mca_btl_smcuda_component.sm_mpool_base = - mca_btl_smcuda_component.sm_mpools[0]->mpool_base(mca_btl_smcuda_component.sm_mpools[0]); + mca_btl_smcuda_component.sm_mpool_base = mca_btl_smcuda_component.sm_mpools[0]->mpool_base( + mca_btl_smcuda_component.sm_mpools[0]); /* create a list of peers */ - mca_btl_smcuda_component.sm_peers = (struct mca_btl_base_endpoint_t**) - calloc(n, sizeof(struct mca_btl_base_endpoint_t*)); + mca_btl_smcuda_component.sm_peers = (struct mca_btl_base_endpoint_t **) + calloc(n, sizeof(struct mca_btl_base_endpoint_t *)); if (NULL == mca_btl_smcuda_component.sm_peers) { free(res); return OPAL_ERR_OUT_OF_RESOURCE; @@ -368,7 +355,7 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, * remote process. */ opal_output_verbose(10, opal_btl_base_framework.framework_output, "btl:smcuda: CUDA cuMemHostRegister address=%p, size=%d", - mca_btl_smcuda_component.sm_mpool_base, (int)res->size); + mca_btl_smcuda_component.sm_mpool_base, (int) res->size); mca_common_cuda_register(mca_btl_smcuda_component.sm_mpool_base, res->size, "smcuda"); /* Create a local memory pool that sends handles to the remote @@ -386,89 +373,84 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, /* check to make sure number of local procs is within the * specified limits */ - if(mca_btl_smcuda_component.sm_max_procs > 0 && - mca_btl_smcuda_component.num_smp_procs + n > - mca_btl_smcuda_component.sm_max_procs) { + if (mca_btl_smcuda_component.sm_max_procs > 0 + && mca_btl_smcuda_component.num_smp_procs + n > mca_btl_smcuda_component.sm_max_procs) { return OPAL_ERROR; } - mca_btl_smcuda_component.shm_fifo = (volatile sm_fifo_t **)mca_btl_smcuda_component.sm_seg->module_data_addr; - mca_btl_smcuda_component.shm_bases = (char**)(mca_btl_smcuda_component.shm_fifo + n); - mca_btl_smcuda_component.shm_mem_nodes = (uint16_t*)(mca_btl_smcuda_component.shm_bases + n); + mca_btl_smcuda_component.shm_fifo = (volatile sm_fifo_t **) + mca_btl_smcuda_component.sm_seg->module_data_addr; + mca_btl_smcuda_component.shm_bases = (char **) (mca_btl_smcuda_component.shm_fifo + n); + mca_btl_smcuda_component.shm_mem_nodes = (uint16_t *) (mca_btl_smcuda_component.shm_bases + n); /* set the base of the shared memory segment */ - mca_btl_smcuda_component.shm_bases[mca_btl_smcuda_component.my_smp_rank] = - (char*)mca_btl_smcuda_component.sm_mpool_base; - mca_btl_smcuda_component.shm_mem_nodes[mca_btl_smcuda_component.my_smp_rank] = - (uint16_t)my_mem_node; + mca_btl_smcuda_component.shm_bases[mca_btl_smcuda_component.my_smp_rank] + = (char *) mca_btl_smcuda_component.sm_mpool_base; + mca_btl_smcuda_component.shm_mem_nodes[mca_btl_smcuda_component.my_smp_rank] = (uint16_t) + my_mem_node; /* initialize the array of fifo's "owned" by this process */ - if(NULL == (my_fifos = (sm_fifo_t*)mpool_calloc(FIFO_MAP_NUM(n), sizeof(sm_fifo_t)))) + if (NULL == (my_fifos = (sm_fifo_t *) mpool_calloc(FIFO_MAP_NUM(n), sizeof(sm_fifo_t)))) return OPAL_ERR_OUT_OF_RESOURCE; mca_btl_smcuda_component.shm_fifo[mca_btl_smcuda_component.my_smp_rank] = my_fifos; /* cache the pointer to the 2d fifo array. These addresses * are valid in the current process space */ - mca_btl_smcuda_component.fifo = (sm_fifo_t**)malloc(sizeof(sm_fifo_t*) * n); + mca_btl_smcuda_component.fifo = (sm_fifo_t **) malloc(sizeof(sm_fifo_t *) * n); - if(NULL == mca_btl_smcuda_component.fifo) + if (NULL == mca_btl_smcuda_component.fifo) return OPAL_ERR_OUT_OF_RESOURCE; mca_btl_smcuda_component.fifo[mca_btl_smcuda_component.my_smp_rank] = my_fifos; mca_btl_smcuda_component.mem_nodes = (uint16_t *) malloc(sizeof(uint16_t) * n); - if(NULL == mca_btl_smcuda_component.mem_nodes) + if (NULL == mca_btl_smcuda_component.mem_nodes) return OPAL_ERR_OUT_OF_RESOURCE; /* initialize fragment descriptor free lists */ /* allocation will be for the fragment descriptor and payload buffer */ length = sizeof(mca_btl_smcuda_frag1_t); - length_payload = - sizeof(mca_btl_smcuda_hdr_t) + mca_btl_smcuda_component.eager_limit; - i = opal_free_list_init (&mca_btl_smcuda_component.sm_frags_eager, length, - opal_cache_line_size, OBJ_CLASS(mca_btl_smcuda_frag1_t), - length_payload, opal_cache_line_size, - mca_btl_smcuda_component.sm_free_list_num, - mca_btl_smcuda_component.sm_free_list_max, - mca_btl_smcuda_component.sm_free_list_inc, - mca_btl_smcuda_component.sm_mpool, 0, NULL, NULL, NULL); - if ( OPAL_SUCCESS != i ) + length_payload = sizeof(mca_btl_smcuda_hdr_t) + mca_btl_smcuda_component.eager_limit; + i = opal_free_list_init(&mca_btl_smcuda_component.sm_frags_eager, length, opal_cache_line_size, + OBJ_CLASS(mca_btl_smcuda_frag1_t), length_payload, opal_cache_line_size, + mca_btl_smcuda_component.sm_free_list_num, + mca_btl_smcuda_component.sm_free_list_max, + mca_btl_smcuda_component.sm_free_list_inc, + mca_btl_smcuda_component.sm_mpool, 0, NULL, NULL, NULL); + if (OPAL_SUCCESS != i) return i; length = sizeof(mca_btl_smcuda_frag2_t); - length_payload = - sizeof(mca_btl_smcuda_hdr_t) + mca_btl_smcuda_component.max_frag_size; - i = opal_free_list_init (&mca_btl_smcuda_component.sm_frags_max, length, - opal_cache_line_size, OBJ_CLASS(mca_btl_smcuda_frag2_t), - length_payload, opal_cache_line_size, - mca_btl_smcuda_component.sm_free_list_num, - mca_btl_smcuda_component.sm_free_list_max, - mca_btl_smcuda_component.sm_free_list_inc, - mca_btl_smcuda_component.sm_mpool, 0, NULL, NULL, NULL); - if ( OPAL_SUCCESS != i ) + length_payload = sizeof(mca_btl_smcuda_hdr_t) + mca_btl_smcuda_component.max_frag_size; + i = opal_free_list_init(&mca_btl_smcuda_component.sm_frags_max, length, opal_cache_line_size, + OBJ_CLASS(mca_btl_smcuda_frag2_t), length_payload, opal_cache_line_size, + mca_btl_smcuda_component.sm_free_list_num, + mca_btl_smcuda_component.sm_free_list_max, + mca_btl_smcuda_component.sm_free_list_inc, + mca_btl_smcuda_component.sm_mpool, 0, NULL, NULL, NULL); + if (OPAL_SUCCESS != i) return i; - i = opal_free_list_init (&mca_btl_smcuda_component.sm_frags_user, - sizeof(mca_btl_smcuda_user_t), - opal_cache_line_size, OBJ_CLASS(mca_btl_smcuda_user_t), - sizeof(mca_btl_smcuda_hdr_t), opal_cache_line_size, - mca_btl_smcuda_component.sm_free_list_num, - mca_btl_smcuda_component.sm_free_list_max, - mca_btl_smcuda_component.sm_free_list_inc, - mca_btl_smcuda_component.sm_mpool, 0, NULL, NULL, NULL); - if ( OPAL_SUCCESS != i ) - return i; + i = opal_free_list_init(&mca_btl_smcuda_component.sm_frags_user, sizeof(mca_btl_smcuda_user_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_smcuda_user_t), + sizeof(mca_btl_smcuda_hdr_t), opal_cache_line_size, + mca_btl_smcuda_component.sm_free_list_num, + mca_btl_smcuda_component.sm_free_list_max, + mca_btl_smcuda_component.sm_free_list_inc, + mca_btl_smcuda_component.sm_mpool, 0, NULL, NULL, NULL); + if (OPAL_SUCCESS != i) + return i; mca_btl_smcuda_component.num_outstanding_frags = 0; mca_btl_smcuda_component.num_pending_sends = 0; - i = opal_free_list_init (&mca_btl_smcuda_component.pending_send_fl, - sizeof(btl_smcuda_pending_send_item_t), 8, - OBJ_CLASS(opal_free_list_item_t), - 0, 0, 16, -1, 32, NULL, 0, NULL, NULL, NULL); - if ( OPAL_SUCCESS != i ) + i = opal_free_list_init(&mca_btl_smcuda_component.pending_send_fl, + sizeof(btl_smcuda_pending_send_item_t), 8, + OBJ_CLASS(opal_free_list_item_t), 0, 0, 16, -1, 32, NULL, 0, NULL, NULL, + NULL); + if (OPAL_SUCCESS != i) return i; /* set flag indicating btl has been inited */ @@ -477,8 +459,7 @@ smcuda_btl_first_time_init(mca_btl_smcuda_t *smcuda_btl, return OPAL_SUCCESS; } -static struct mca_btl_base_endpoint_t * -create_sm_endpoint(int local_proc, struct opal_proc_t *proc) +static struct mca_btl_base_endpoint_t *create_sm_endpoint(int local_proc, struct opal_proc_t *proc) { struct mca_btl_base_endpoint_t *ep; @@ -486,22 +467,19 @@ create_sm_endpoint(int local_proc, struct opal_proc_t *proc) char path[PATH_MAX]; #endif - ep = (struct mca_btl_base_endpoint_t*) - malloc(sizeof(struct mca_btl_base_endpoint_t)); - if(NULL == ep) + ep = (struct mca_btl_base_endpoint_t *) malloc(sizeof(struct mca_btl_base_endpoint_t)); + if (NULL == ep) return NULL; ep->peer_smp_rank = local_proc + mca_btl_smcuda_component.num_smp_procs; OBJ_CONSTRUCT(&ep->pending_sends, opal_list_t); OBJ_CONSTRUCT(&ep->endpoint_lock, opal_mutex_t); #if OPAL_ENABLE_PROGRESS_THREADS == 1 - sprintf(path, "%s"OPAL_PATH_SEP"sm_fifo.%lu", - opal_process_info.job_session_dir, - (unsigned long)proc->proc_name); + sprintf(path, "%s" OPAL_PATH_SEP "sm_fifo.%lu", opal_process_info.job_session_dir, + (unsigned long) proc->proc_name); ep->fifo_fd = open(path, O_WRONLY); - if(ep->fifo_fd < 0) { - opal_output(0, "mca_btl_smcuda_add_procs: open(%s) failed with errno=%d\n", - path, errno); + if (ep->fifo_fd < 0) { + opal_output(0, "mca_btl_smcuda_add_procs: open(%s) failed with errno=%d\n", path, errno); free(ep); return NULL; } @@ -509,21 +487,18 @@ create_sm_endpoint(int local_proc, struct opal_proc_t *proc) #if OPAL_CUDA_SUPPORT /* Create a remote memory pool on the endpoint. The rgpusm component * does not take any resources. They are filled in internally. */ - ep->rcache = mca_rcache_base_module_create ("rgpusm", NULL, NULL); + ep->rcache = mca_rcache_base_module_create("rgpusm", NULL, NULL); #endif /* OPAL_CUDA_SUPPORT */ return ep; } -int mca_btl_smcuda_add_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers, - opal_bitmap_t* reachability) +int mca_btl_smcuda_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachability) { int return_code = OPAL_SUCCESS; int32_t n_local_procs = 0, proc, j, my_smp_rank = -1; - const opal_proc_t* my_proc; /* pointer to caller's proc structure */ + const opal_proc_t *my_proc; /* pointer to caller's proc structure */ mca_btl_smcuda_t *smcuda_btl; bool have_connected_peer = false; char **bases; @@ -532,26 +507,26 @@ int mca_btl_smcuda_add_procs( /* initializion */ - smcuda_btl = (mca_btl_smcuda_t *)btl; + smcuda_btl = (mca_btl_smcuda_t *) btl; /* get pointer to my proc structure */ - if(NULL == (my_proc = opal_proc_local_get())) + if (NULL == (my_proc = opal_proc_local_get())) return OPAL_ERR_OUT_OF_RESOURCE; /* Get unique host identifier for each process in the list, * and idetify procs that are on this host. Add procs on this * host to shared memory reachbility list. Also, get number * of local procs in the procs list. */ - for (proc = 0; proc < (int32_t)nprocs; proc++) { + for (proc = 0; proc < (int32_t) nprocs; proc++) { /* check to see if this proc can be reached via shmem (i.e., if they're on my local host and in my job) */ - if (procs[proc]->proc_name.jobid != my_proc->proc_name.jobid || - !OPAL_PROC_ON_LOCAL_NODE(procs[proc]->proc_flags)) { + if (procs[proc]->proc_name.jobid != my_proc->proc_name.jobid + || !OPAL_PROC_ON_LOCAL_NODE(procs[proc]->proc_flags)) { peers[proc] = NULL; continue; } /* check to see if this is me */ - if(my_proc == procs[proc]) { + if (my_proc == procs[proc]) { my_smp_rank = mca_btl_smcuda_component.my_smp_rank = n_local_procs++; continue; } @@ -559,7 +534,7 @@ int mca_btl_smcuda_add_procs( /* we have someone to talk to */ have_connected_peer = true; - if(!(peers[proc] = create_sm_endpoint(n_local_procs, procs[proc]))) { + if (!(peers[proc] = create_sm_endpoint(n_local_procs, procs[proc]))) { return_code = OPAL_ERROR; goto CLEANUP; } @@ -572,7 +547,7 @@ int mca_btl_smcuda_add_procs( /* add this proc to shared memory accessibility list */ return_code = opal_bitmap_set_bit(reachability, proc); - if(OPAL_SUCCESS != return_code) + if (OPAL_SUCCESS != return_code) goto CLEANUP; } @@ -587,9 +562,8 @@ int mca_btl_smcuda_add_procs( } if (!smcuda_btl->btl_inited) { - return_code = - smcuda_btl_first_time_init(smcuda_btl, my_smp_rank, - mca_btl_smcuda_component.sm_max_procs); + return_code = smcuda_btl_first_time_init(smcuda_btl, my_smp_rank, + mca_btl_smcuda_component.sm_max_procs); if (return_code != OPAL_SUCCESS) { goto CLEANUP; } @@ -597,15 +571,15 @@ int mca_btl_smcuda_add_procs( /* set local proc's smp rank in the peers structure for * rapid access and calculate reachability */ - for(proc = 0; proc < (int32_t)nprocs; proc++) { - if(NULL == peers[proc]) + for (proc = 0; proc < (int32_t) nprocs; proc++) { + if (NULL == peers[proc]) continue; mca_btl_smcuda_component.sm_peers[peers[proc]->peer_smp_rank] = peers[proc]; peers[proc]->my_smp_rank = my_smp_rank; } bases = mca_btl_smcuda_component.shm_bases; - sm_mpool_modp = (mca_common_sm_mpool_module_t *)mca_btl_smcuda_component.sm_mpool; + sm_mpool_modp = (mca_common_sm_mpool_module_t *) mca_btl_smcuda_component.sm_mpool; /* initialize own FIFOs */ /* @@ -613,14 +587,14 @@ int mca_btl_smcuda_add_procs( * be allocated near the receiver. Nothing will be local to * "the sender" since there will be many senders. */ - for(j = mca_btl_smcuda_component.num_smp_procs; - j < mca_btl_smcuda_component.num_smp_procs + FIFO_MAP_NUM(n_local_procs); j++) { + for (j = mca_btl_smcuda_component.num_smp_procs; + j < mca_btl_smcuda_component.num_smp_procs + FIFO_MAP_NUM(n_local_procs); j++) { - return_code = sm_fifo_init( mca_btl_smcuda_component.fifo_size, - mca_btl_smcuda_component.sm_mpool, + return_code = sm_fifo_init(mca_btl_smcuda_component.fifo_size, + mca_btl_smcuda_component.sm_mpool, &mca_btl_smcuda_component.fifo[my_smp_rank][j], - mca_btl_smcuda_component.fifo_lazy_free); - if(return_code != OPAL_SUCCESS) + mca_btl_smcuda_component.fifo_lazy_free); + if (return_code != OPAL_SUCCESS) goto CLEANUP; } @@ -629,9 +603,8 @@ int mca_btl_smcuda_add_procs( /* Sync with other local procs. Force the FIFO initialization to always * happens before the readers access it. */ - (void)opal_atomic_add_fetch_32(&mca_btl_smcuda_component.sm_seg->module_seg->seg_inited, 1); - while( n_local_procs > - mca_btl_smcuda_component.sm_seg->module_seg->seg_inited) { + (void) opal_atomic_add_fetch_32(&mca_btl_smcuda_component.sm_seg->module_seg->seg_inited, 1); + while (n_local_procs > mca_btl_smcuda_component.sm_seg->module_seg->seg_inited) { opal_progress(); opal_atomic_rmb(); } @@ -639,8 +612,7 @@ int mca_btl_smcuda_add_procs( /* it is now safe to unlink the shared memory segment. only one process * needs to do this, so just let smp rank zero take care of it. */ if (0 == my_smp_rank) { - if (OPAL_SUCCESS != - mca_common_sm_module_unlink(mca_btl_smcuda_component.sm_seg)) { + if (OPAL_SUCCESS != mca_common_sm_module_unlink(mca_btl_smcuda_component.sm_seg)) { /* it is "okay" if this fails at this point. we have gone this far, * so just warn about the failure and continue. this is probably * only triggered by a programming error. */ @@ -651,8 +623,7 @@ int mca_btl_smcuda_add_procs( /* at this point, all processes have attached to the mpool segment. so * it is safe to unlink it here. */ - if (OPAL_SUCCESS != - mca_common_sm_module_unlink(sm_mpool_modp->sm_common_module)) { + if (OPAL_SUCCESS != mca_common_sm_module_unlink(sm_mpool_modp->sm_common_module)) { opal_output(0, "WARNING: common_sm_module_unlink failed.\n"); } if (-1 == unlink(mca_btl_smcuda_component.sm_mpool_rndv_file_name)) { @@ -672,14 +643,14 @@ int mca_btl_smcuda_add_procs( free(mca_btl_smcuda_component.sm_rndv_file_name); /* coordinate with other processes */ - for(j = mca_btl_smcuda_component.num_smp_procs; - j < mca_btl_smcuda_component.num_smp_procs + n_local_procs; j++) { + for (j = mca_btl_smcuda_component.num_smp_procs; + j < mca_btl_smcuda_component.num_smp_procs + n_local_procs; j++) { ptrdiff_t diff; /* spin until this element is allocated */ /* doesn't really wait for that process... FIFO might be allocated, but not initialized */ opal_atomic_rmb(); - while(NULL == mca_btl_smcuda_component.shm_fifo[j]) { + while (NULL == mca_btl_smcuda_component.shm_fifo[j]) { opal_progress(); opal_atomic_rmb(); } @@ -688,8 +659,8 @@ int mca_btl_smcuda_add_procs( diff = ADDR2OFFSET(bases[my_smp_rank], bases[j]); /* store local address of remote fifos */ - mca_btl_smcuda_component.fifo[j] = - (sm_fifo_t*)OFFSET2ADDR(diff, mca_btl_smcuda_component.shm_fifo[j]); + mca_btl_smcuda_component.fifo[j] = (sm_fifo_t *) + OFFSET2ADDR(diff, mca_btl_smcuda_component.shm_fifo[j]); /* cache local copy of peer memory node number */ mca_btl_smcuda_component.mem_nodes[j] = mca_btl_smcuda_component.shm_mem_nodes[j]; @@ -699,8 +670,8 @@ int mca_btl_smcuda_add_procs( mca_btl_smcuda_component.num_smp_procs += n_local_procs; /* make sure we have enough eager fragmnents for each process */ - return_code = opal_free_list_resize_mt (&mca_btl_smcuda_component.sm_frags_eager, - mca_btl_smcuda_component.num_smp_procs * 2); + return_code = opal_free_list_resize_mt(&mca_btl_smcuda_component.sm_frags_eager, + mca_btl_smcuda_component.num_smp_procs * 2); if (OPAL_SUCCESS != return_code) goto CLEANUP; @@ -708,15 +679,12 @@ int mca_btl_smcuda_add_procs( return return_code; } -int mca_btl_smcuda_del_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers) +int mca_btl_smcuda_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers) { - for (size_t i = 0 ; i < nprocs ; ++i) { + for (size_t i = 0; i < nprocs; ++i) { if (peers[i]->rcache) { - mca_rcache_base_module_destroy (peers[i]->rcache); + mca_rcache_base_module_destroy(peers[i]->rcache); peers[i]->rcache = NULL; } } @@ -724,7 +692,6 @@ int mca_btl_smcuda_del_procs( return OPAL_SUCCESS; } - /** * MCA->BTL Clean up any resources held by BTL module * before the module is unloaded. @@ -738,20 +705,18 @@ int mca_btl_smcuda_del_procs( * */ -int mca_btl_smcuda_finalize(struct mca_btl_base_module_t* btl) +int mca_btl_smcuda_finalize(struct mca_btl_base_module_t *btl) { return OPAL_SUCCESS; } - /* * Register callback function for error handling.. */ -int mca_btl_smcuda_register_error_cb( - struct mca_btl_base_module_t* btl, - mca_btl_base_module_error_cb_fn_t cbfunc) +int mca_btl_smcuda_register_error_cb(struct mca_btl_base_module_t *btl, + mca_btl_base_module_error_cb_fn_t cbfunc) { - mca_btl_smcuda_t *smcuda_btl = (mca_btl_smcuda_t *)btl; + mca_btl_smcuda_t *smcuda_btl = (mca_btl_smcuda_t *) btl; smcuda_btl->error_cb = cbfunc; return OPAL_SUCCESS; } @@ -762,15 +727,12 @@ int mca_btl_smcuda_register_error_cb( * @param btl (IN) BTL module * @param size (IN) Request segment size. */ -extern mca_btl_base_descriptor_t* mca_btl_smcuda_alloc( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags) +extern mca_btl_base_descriptor_t *mca_btl_smcuda_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { - mca_btl_smcuda_frag_t* frag = NULL; - if(size <= mca_btl_smcuda_component.eager_limit) { + mca_btl_smcuda_frag_t *frag = NULL; + if (size <= mca_btl_smcuda_component.eager_limit) { MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag); } else if (size <= mca_btl_smcuda_component.max_frag_size) { MCA_BTL_SMCUDA_FRAG_ALLOC_MAX(frag); @@ -780,7 +742,7 @@ extern mca_btl_base_descriptor_t* mca_btl_smcuda_alloc( frag->segment.seg_len = size; frag->base.des_flags = flags; } - return (mca_btl_base_descriptor_t*)frag; + return (mca_btl_base_descriptor_t *) frag; } /** @@ -789,55 +751,46 @@ extern mca_btl_base_descriptor_t* mca_btl_smcuda_alloc( * @param btl (IN) BTL module * @param segment (IN) Allocated segment. */ -extern int mca_btl_smcuda_free( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* des) +extern int mca_btl_smcuda_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { - mca_btl_smcuda_frag_t* frag = (mca_btl_smcuda_frag_t*)des; + mca_btl_smcuda_frag_t *frag = (mca_btl_smcuda_frag_t *) des; MCA_BTL_SMCUDA_FRAG_RETURN(frag); return OPAL_SUCCESS; } - /** * Pack data * * @param btl (IN) BTL module */ -struct mca_btl_base_descriptor_t* mca_btl_smcuda_prepare_src( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags) +struct mca_btl_base_descriptor_t *mca_btl_smcuda_prepare_src( + struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, uint32_t flags) { - mca_btl_smcuda_frag_t* frag; + mca_btl_smcuda_frag_t *frag; struct iovec iov; uint32_t iov_count = 1; size_t max_data = *size; int rc; - if ( reserve + max_data <= mca_btl_smcuda_component.eager_limit ) { + if (reserve + max_data <= mca_btl_smcuda_component.eager_limit) { MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag); } else { MCA_BTL_SMCUDA_FRAG_ALLOC_MAX(frag); } - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } - if( OPAL_UNLIKELY(reserve + max_data > frag->size) ) { + if (OPAL_UNLIKELY(reserve + max_data > frag->size)) { max_data = frag->size - reserve; } iov.iov_len = max_data; - iov.iov_base = - (IOVBASE_TYPE*)(((unsigned char*)(frag->segment.seg_addr.pval)) + reserve); + iov.iov_base = (IOVBASE_TYPE *) (((unsigned char *) (frag->segment.seg_addr.pval)) + reserve); - rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data ); - if( OPAL_UNLIKELY(rc < 0) ) { + rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); + if (OPAL_UNLIKELY(rc < 0)) { MCA_BTL_SMCUDA_FRAG_RETURN(frag); return NULL; } @@ -852,34 +805,46 @@ struct mca_btl_base_descriptor_t* mca_btl_smcuda_prepare_src( } #if 0 -#define MCA_BTL_SMCUDA_TOUCH_DATA_TILL_CACHELINE_BOUNDARY(sm_frag) \ - do { \ - char* _memory = (char*)(sm_frag)->segment.seg_addr.pval + \ - (sm_frag)->segment.seg_len; \ - int* _intmem; \ - size_t align = (intptr_t)_memory & 0xFUL; \ - switch( align & 0x3 ) { \ - case 3: *_memory = 0; _memory++; \ - case 2: *_memory = 0; _memory++; \ - case 1: *_memory = 0; _memory++; \ - } \ - align >>= 2; \ - _intmem = (int*)_memory; \ - switch( align ) { \ - case 3: *_intmem = 0; _intmem++; \ - case 2: *_intmem = 0; _intmem++; \ - case 1: *_intmem = 0; _intmem++; \ - } \ - } while(0) +# define MCA_BTL_SMCUDA_TOUCH_DATA_TILL_CACHELINE_BOUNDARY(sm_frag) \ + do { \ + char *_memory = (char *) (sm_frag)->segment.seg_addr.pval \ + + (sm_frag)->segment.seg_len; \ + int *_intmem; \ + size_t align = (intptr_t) _memory & 0xFUL; \ + switch (align & 0x3) { \ + case 3: \ + *_memory = 0; \ + _memory++; \ + case 2: \ + *_memory = 0; \ + _memory++; \ + case 1: \ + *_memory = 0; \ + _memory++; \ + } \ + align >>= 2; \ + _intmem = (int *) _memory; \ + switch (align) { \ + case 3: \ + *_intmem = 0; \ + _intmem++; \ + case 2: \ + *_intmem = 0; \ + _intmem++; \ + case 1: \ + *_intmem = 0; \ + _intmem++; \ + } \ + } while (0) #else -#define MCA_BTL_SMCUDA_TOUCH_DATA_TILL_CACHELINE_BOUNDARY(sm_frag) +# define MCA_BTL_SMCUDA_TOUCH_DATA_TILL_CACHELINE_BOUNDARY(sm_frag) #endif #if 0 if( OPAL_LIKELY(align > 0) ) { \ align = 0xFUL - align; \ memset( _memory, 0, align ); \ - } \ + } #endif @@ -889,74 +854,75 @@ struct mca_btl_base_descriptor_t* mca_btl_smcuda_prepare_src( * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -int mca_btl_smcuda_sendi( struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - void* header, - size_t header_size, - size_t payload_size, - uint8_t order, - uint32_t flags, - mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t** descriptor ) +int mca_btl_smcuda_sendi(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor) { size_t length = (header_size + payload_size); - mca_btl_smcuda_frag_t* frag; + mca_btl_smcuda_frag_t *frag; int rc; - if ( mca_btl_smcuda_component.num_outstanding_frags * 2 > (int) mca_btl_smcuda_component.fifo_size ) { + if (mca_btl_smcuda_component.num_outstanding_frags * 2 + > (int) mca_btl_smcuda_component.fifo_size) { mca_btl_smcuda_component_progress(); } #if OPAL_CUDA_SUPPORT /* Initiate setting up CUDA IPC support. */ - if (mca_common_cuda_enabled && (IPC_INIT == endpoint->ipcstate) && mca_btl_smcuda_component.use_cuda_ipc) { + if (mca_common_cuda_enabled && (IPC_INIT == endpoint->ipcstate) + && mca_btl_smcuda_component.use_cuda_ipc) { mca_btl_smcuda_send_cuda_ipc_request(btl, endpoint); } /* We do not want to use this path when we have CUDA IPC support */ if ((convertor->flags & CONVERTOR_CUDA) && (IPC_ACKED == endpoint->ipcstate)) { if (NULL != descriptor) { - *descriptor = mca_btl_smcuda_alloc(btl, endpoint, order, payload_size+header_size, flags); + *descriptor = mca_btl_smcuda_alloc(btl, endpoint, order, payload_size + header_size, + flags); } return OPAL_ERR_RESOURCE_BUSY; } #endif /* OPAL_CUDA_SUPPORT */ /* this check should be unnecessary... turn into an assertion? */ - if( length < mca_btl_smcuda_component.eager_limit ) { + if (length < mca_btl_smcuda_component.eager_limit) { /* allocate a fragment, giving up if we can't get one */ /* note that frag==NULL is equivalent to rc returning an error code */ MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag); - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { *descriptor = NULL; return OPAL_ERR_OUT_OF_RESOURCE; } /* fill in fragment fields */ frag->segment.seg_len = length; - frag->hdr->len = length; - assert( 0 == (flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) ); - frag->base.des_flags = flags | MCA_BTL_DES_FLAGS_BTL_OWNERSHIP; /* why do any flags matter here other than OWNERSHIP? */ + frag->hdr->len = length; + assert(0 == (flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK)); + frag->base.des_flags = flags + | MCA_BTL_DES_FLAGS_BTL_OWNERSHIP; /* why do any flags matter here + other than OWNERSHIP? */ frag->hdr->tag = tag; frag->endpoint = endpoint; /* write the match header (with MPI comm/tag/etc. info) */ - memcpy( frag->segment.seg_addr.pval, header, header_size ); + memcpy(frag->segment.seg_addr.pval, header, header_size); /* write the message data if there is any */ /* We can add MEMCHECKER calls before and after the packing. */ - if( payload_size ) { + if (payload_size) { size_t max_data; struct iovec iov; uint32_t iov_count; /* pack the data into the supplied buffer */ - iov.iov_base = (IOVBASE_TYPE*)((unsigned char*)frag->segment.seg_addr.pval + header_size); - iov.iov_len = max_data = payload_size; - iov_count = 1; + iov.iov_base = (IOVBASE_TYPE *) ((unsigned char *) frag->segment.seg_addr.pval + + header_size); + iov.iov_len = max_data = payload_size; + iov_count = 1; - (void)opal_convertor_pack( convertor, &iov, &iov_count, &max_data); + (void) opal_convertor_pack(convertor, &iov, &iov_count, &max_data); assert(max_data == payload_size); } @@ -970,15 +936,14 @@ int mca_btl_smcuda_sendi( struct mca_btl_base_module_t* btl, * our point of view: it has been posted to a "pending send" queue. */ OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_outstanding_frags, +1); - MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, - endpoint->peer_smp_rank, (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); - (void)rc; /* this is safe to ignore as the message is requeued till success */ + MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, endpoint->peer_smp_rank, + (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); + (void) rc; /* this is safe to ignore as the message is requeued till success */ return OPAL_SUCCESS; } /* presumably, this code path will never get executed */ - *descriptor = mca_btl_smcuda_alloc( btl, endpoint, order, - payload_size + header_size, flags); + *descriptor = mca_btl_smcuda_alloc(btl, endpoint, order, payload_size + header_size, flags); return OPAL_ERR_RESOURCE_BUSY; } @@ -988,20 +953,20 @@ int mca_btl_smcuda_sendi( struct mca_btl_base_module_t* btl, * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -int mca_btl_smcuda_send( struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag ) +int mca_btl_smcuda_send(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { - mca_btl_smcuda_frag_t* frag = (mca_btl_smcuda_frag_t*)descriptor; + mca_btl_smcuda_frag_t *frag = (mca_btl_smcuda_frag_t *) descriptor; int rc; - if ( mca_btl_smcuda_component.num_outstanding_frags * 2 > (int) mca_btl_smcuda_component.fifo_size ) { + if (mca_btl_smcuda_component.num_outstanding_frags * 2 + > (int) mca_btl_smcuda_component.fifo_size) { mca_btl_smcuda_component_progress(); } #if OPAL_CUDA_SUPPORT /* Initiate setting up CUDA IPC support */ - if (mca_common_cuda_enabled && (IPC_INIT == endpoint->ipcstate) && mca_btl_smcuda_component.use_cuda_ipc) { + if (mca_common_cuda_enabled && (IPC_INIT == endpoint->ipcstate) + && mca_btl_smcuda_component.use_cuda_ipc) { mca_btl_smcuda_send_cuda_ipc_request(btl, endpoint); } #endif /* OPAL_CUDA_SUPPORT */ @@ -1020,10 +985,10 @@ int mca_btl_smcuda_send( struct mca_btl_base_module_t* btl, * address */ OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_outstanding_frags, +1); - MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, - endpoint->peer_smp_rank, (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); - if( OPAL_LIKELY(0 == rc) ) { - return 1; /* the data is completely gone */ + MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, endpoint->peer_smp_rank, + (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); + if (OPAL_LIKELY(0 == rc)) { + return 1; /* the data is completely gone */ } frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; /* not yet gone, but pending. Let the upper level knows that @@ -1033,9 +998,10 @@ int mca_btl_smcuda_send( struct mca_btl_base_module_t* btl, } #if OPAL_CUDA_SUPPORT -static struct mca_btl_base_registration_handle_t *mca_btl_smcuda_register_mem ( - struct mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags) +static struct mca_btl_base_registration_handle_t * +mca_btl_smcuda_register_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, + uint32_t flags) { mca_btl_smcuda_t *smcuda_module = (mca_btl_smcuda_t *) btl; mca_rcache_common_cuda_reg_t *reg; @@ -1046,8 +1012,8 @@ static struct mca_btl_base_registration_handle_t *mca_btl_smcuda_register_mem ( rcache_flags |= MCA_RCACHE_FLAGS_CUDA_GPU_MEM; } - smcuda_module->rcache->rcache_register (smcuda_module->rcache, base, size, rcache_flags, - access_flags, (mca_rcache_base_registration_t **) ®); + smcuda_module->rcache->rcache_register(smcuda_module->rcache, base, size, rcache_flags, + access_flags, (mca_rcache_base_registration_t **) ®); if (OPAL_UNLIKELY(NULL == reg)) { return NULL; } @@ -1055,23 +1021,25 @@ static struct mca_btl_base_registration_handle_t *mca_btl_smcuda_register_mem ( return (mca_btl_base_registration_handle_t *) ®->data; } -static int mca_btl_smcuda_deregister_mem (struct mca_btl_base_module_t* btl, - struct mca_btl_base_registration_handle_t *handle) +static int mca_btl_smcuda_deregister_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_registration_handle_t *handle) { mca_btl_smcuda_t *smcuda_module = (mca_btl_smcuda_t *) btl; - mca_rcache_common_cuda_reg_t *reg = (mca_rcache_common_cuda_reg_t *) - ((intptr_t) handle - offsetof (mca_rcache_common_cuda_reg_t, data)); + mca_rcache_common_cuda_reg_t *reg = (mca_rcache_common_cuda_reg_t + *) ((intptr_t) handle + - offsetof(mca_rcache_common_cuda_reg_t, data)); - smcuda_module->rcache->rcache_deregister (smcuda_module->rcache, ®->base); + smcuda_module->rcache->rcache_deregister(smcuda_module->rcache, ®->base); return OPAL_SUCCESS; } -int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *ep, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_smcuda_get_cuda(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *ep, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { mca_rcache_common_cuda_reg_t rget_reg; mca_rcache_common_cuda_reg_t *reg_ptr = &rget_reg; @@ -1082,7 +1050,7 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, /* NTH: copied from old prepare_dst function */ MCA_BTL_SMCUDA_FRAG_ALLOC_USER(frag); - if(OPAL_UNLIKELY(NULL == frag)) { + if (OPAL_UNLIKELY(NULL == frag)) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1104,11 +1072,11 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, memset(&rget_reg, 0, sizeof(rget_reg)); memcpy(&rget_reg.data.memHandle, remote_handle->reg_data.memHandle, sizeof(remote_handle->reg_data.memHandle)); -#if !OPAL_CUDA_SYNC_MEMOPS +# if !OPAL_CUDA_SYNC_MEMOPS /* Only need the remote event handle when syncing with remote events */ memcpy(&rget_reg.data.evtHandle, remote_handle->reg_data.evtHandle, sizeof(remote_handle->reg_data.evtHandle)); -#endif +# endif /* Open the memory handle to the remote memory. If it is cached, then * we just retrieve it from cache and avoid a call to open the handle. That @@ -1117,16 +1085,16 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, * remote memory which may lie somewhere in the middle. This is taken care of * a few lines down. Note that we hand in the peer rank just for debugging * support. */ - rc = ep->rcache->rcache_register (ep->rcache, remote_handle->reg_data.memh_seg_addr.pval, - remote_handle->reg_data.memh_seg_len, ep->peer_smp_rank, - MCA_RCACHE_ACCESS_LOCAL_WRITE, - (mca_rcache_base_registration_t **)®_ptr); + rc = ep->rcache->rcache_register(ep->rcache, remote_handle->reg_data.memh_seg_addr.pval, + remote_handle->reg_data.memh_seg_len, ep->peer_smp_rank, + MCA_RCACHE_ACCESS_LOCAL_WRITE, + (mca_rcache_base_registration_t **) ®_ptr); if (OPAL_SUCCESS != rc) { opal_output(0, "Failed to register remote memory, rc=%d", rc); return rc; } - frag->registration = (mca_rcache_base_registration_t *)reg_ptr; + frag->registration = (mca_rcache_base_registration_t *) reg_ptr; frag->endpoint = ep; /* The registration has given us back the memory block that this @@ -1134,10 +1102,10 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, * not equal the address that was used to retrieve the block. * Therefore, compute the offset and add it to the address of the * memory handle. */ - offset = (size_t) ((intptr_t) remote_address - (intptr_t) reg_ptr->base.base); - remote_memory_address = (unsigned char *)reg_ptr->base.alloc_base + offset; + offset = (size_t)((intptr_t) remote_address - (intptr_t) reg_ptr->base.base); + remote_memory_address = (unsigned char *) reg_ptr->base.alloc_base + offset; if (0 != offset) { - opal_output(-1, "OFFSET=%d", (int)offset); + opal_output(-1, "OFFSET=%d", (int) offset); } /* The remote side posted an IPC event to make sure we do not start our @@ -1147,9 +1115,8 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, * rget_reg, not reg_ptr, as we do not cache the event. */ mca_common_wait_stream_synchronize(&rget_reg); - rc = mca_common_cuda_memcpy(local_address, remote_memory_address, size, - "mca_btl_smcuda_get", (mca_btl_base_descriptor_t *)frag, - &done); + rc = mca_common_cuda_memcpy(local_address, remote_memory_address, size, "mca_btl_smcuda_get", + (mca_btl_base_descriptor_t *) frag, &done); if (OPAL_SUCCESS != rc) { /* Out of resources can be handled by upper layers. */ if (OPAL_ERR_OUT_OF_RESOURCE != rc) { @@ -1159,12 +1126,11 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, } if (OPAL_UNLIKELY(1 == done)) { - cbfunc (btl, ep, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS); - mca_btl_smcuda_free(btl, (mca_btl_base_descriptor_t *)frag); + cbfunc(btl, ep, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS); + mca_btl_smcuda_free(btl, (mca_btl_base_descriptor_t *) frag); } return OPAL_SUCCESS; - } /** @@ -1176,11 +1142,11 @@ int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -#define MAXTRIES 5 -static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint) +# define MAXTRIES 5 +static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint) { - mca_btl_smcuda_frag_t* frag; + mca_btl_smcuda_frag_t *frag; int rc, mydevnum, res; ctrlhdr_t ctrlhdr; @@ -1201,7 +1167,8 @@ static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t* b endpoint->ipcstate = IPC_SENT; OPAL_THREAD_UNLOCK(&endpoint->endpoint_lock); - if ( mca_btl_smcuda_component.num_outstanding_frags * 2 > (int) mca_btl_smcuda_component.fifo_size ) { + if (mca_btl_smcuda_component.num_outstanding_frags * 2 + > (int) mca_btl_smcuda_component.fifo_size) { mca_btl_smcuda_component_progress(); } @@ -1213,7 +1180,7 @@ static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t* b /* allocate a fragment, giving up if we can't get one */ MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag); - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { endpoint->ipcstate = IPC_BAD; return; } @@ -1236,14 +1203,12 @@ static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t* b OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_outstanding_frags, +1); opal_output_verbose(10, mca_btl_smcuda_component.cuda_ipc_output, "Sending CUDA IPC REQ (try=%d): myrank=%d, mydev=%d, peerrank=%d", - endpoint->ipctries, - mca_btl_smcuda_component.my_smp_rank, - mydevnum, endpoint->peer_smp_rank); + endpoint->ipctries, mca_btl_smcuda_component.my_smp_rank, mydevnum, + endpoint->peer_smp_rank); - MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, - endpoint->peer_smp_rank, (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); + MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, endpoint->peer_smp_rank, + (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); return; - } #endif /* OPAL_CUDA_SUPPORT */ @@ -1251,21 +1216,18 @@ static void mca_btl_smcuda_send_cuda_ipc_request(struct mca_btl_base_module_t* b /** * */ -void mca_btl_smcuda_dump(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - int verbose) +void mca_btl_smcuda_dump(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, int verbose) { - mca_btl_smcuda_frag_t* frag; + mca_btl_smcuda_frag_t *frag; - mca_btl_base_err("BTL SM %p endpoint %p [smp_rank %d] [peer_rank %d]\n", - (void*) btl, (void*) endpoint, - endpoint->my_smp_rank, endpoint->peer_smp_rank); - if( NULL != endpoint ) { - OPAL_LIST_FOREACH(frag, &endpoint->pending_sends, mca_btl_smcuda_frag_t) { + mca_btl_base_err("BTL SM %p endpoint %p [smp_rank %d] [peer_rank %d]\n", (void *) btl, + (void *) endpoint, endpoint->my_smp_rank, endpoint->peer_smp_rank); + if (NULL != endpoint) { + OPAL_LIST_FOREACH (frag, &endpoint->pending_sends, mca_btl_smcuda_frag_t) { mca_btl_base_err(" | frag %p size %lu (hdr frag %p len %lu rank %d tag %d)\n", - (void*) frag, frag->size, (void*) frag->hdr->frag, - frag->hdr->len, frag->hdr->my_smp_rank, - frag->hdr->tag); + (void *) frag, frag->size, (void *) frag->hdr->frag, frag->hdr->len, + frag->hdr->my_smp_rank, frag->hdr->tag); } } } diff --git a/opal/mca/btl/smcuda/btl_smcuda.h b/opal/mca/btl/smcuda/btl_smcuda.h index e930e15381a..f91d06a5c7c 100644 --- a/opal/mca/btl/smcuda/btl_smcuda.h +++ b/opal/mca/btl/smcuda/btl_smcuda.h @@ -29,17 +29,17 @@ #include "opal_config.h" #include +#include #include #include -#include #ifdef HAVE_SCHED_H -#include -#endif /* HAVE_SCHED_H */ +# include +#endif /* HAVE_SCHED_H */ -#include "opal/util/bit_ops.h" #include "opal/class/opal_free_list.h" #include "opal/mca/btl/btl.h" #include "opal/mca/common/sm/common_sm.h" +#include "opal/util/bit_ops.h" BEGIN_C_DECLS @@ -71,7 +71,7 @@ BEGIN_C_DECLS * cachelines. */ -#define SM_FIFO_FREE (void *) (-2) +#define SM_FIFO_FREE (void *) (-2) /* We can't use opal_cache_line_size here because we need a compile-time constant for padding the struct. We can't really have a compile-time constant that is portable, either (e.g., compile on @@ -98,9 +98,7 @@ struct sm_fifo_t { volatile int tail; int num_to_clear; int lazy_free; - char pad4[SM_CACHE_LINE_PAD - sizeof(void **) - - sizeof(opal_atomic_lock_t) - - sizeof(int) * 3]; + char pad4[SM_CACHE_LINE_PAD - sizeof(void **) - sizeof(opal_atomic_lock_t) - sizeof(int) * 3]; }; typedef struct sm_fifo_t sm_fifo_t; @@ -109,72 +107,72 @@ typedef struct sm_fifo_t sm_fifo_t; */ #if OPAL_ENABLE_PROGRESS_THREADS == 1 -#define DATA (char)0 -#define DONE (char)1 +# define DATA (char) 0 +# define DONE (char) 1 #endif typedef struct mca_btl_smcuda_mem_node_t { - mca_mpool_base_module_t* sm_mpool; /**< shared memory pool */ + mca_mpool_base_module_t *sm_mpool; /**< shared memory pool */ } mca_btl_smcuda_mem_node_t; /** * Shared Memory (SM) BTL module. */ struct mca_btl_smcuda_component_t { - mca_btl_base_component_2_0_0_t super; /**< base BTL component */ - int sm_free_list_num; /**< initial size of free lists */ - int sm_free_list_max; /**< maximum size of free lists */ - int sm_free_list_inc; /**< number of elements to alloc when growing free lists */ - int sm_max_procs; /**< upper limit on the number of processes using the shared memory pool */ - int sm_extra_procs; /**< number of extra procs to allow */ - char* sm_mpool_name; /**< name of shared memory pool module */ + mca_btl_base_component_2_0_0_t super; /**< base BTL component */ + int sm_free_list_num; /**< initial size of free lists */ + int sm_free_list_max; /**< maximum size of free lists */ + int sm_free_list_inc; /**< number of elements to alloc when growing free lists */ + int sm_max_procs; /**< upper limit on the number of processes using the shared memory pool */ + int sm_extra_procs; /**< number of extra procs to allow */ + char *sm_mpool_name; /**< name of shared memory pool module */ mca_mpool_base_module_t **sm_mpools; /**< shared memory pools (one for each memory node) */ - mca_mpool_base_module_t *sm_mpool; /**< mpool on local node */ - void* sm_mpool_base; /**< base address of shared memory pool */ - size_t eager_limit; /**< first fragment size */ - size_t max_frag_size; /**< maximum (second and beyone) fragment size */ + mca_mpool_base_module_t *sm_mpool; /**< mpool on local node */ + void *sm_mpool_base; /**< base address of shared memory pool */ + size_t eager_limit; /**< first fragment size */ + size_t max_frag_size; /**< maximum (second and beyone) fragment size */ opal_mutex_t sm_lock; - mca_common_sm_module_t *sm_seg; /**< description of shared memory segment */ - volatile sm_fifo_t **shm_fifo; /**< pointer to fifo 2D array in shared memory */ - char **shm_bases; /**< pointer to base pointers in shared memory */ - uint16_t *shm_mem_nodes; /**< pointer to mem noded in shared memory */ - sm_fifo_t **fifo; /**< cached copy of the pointer to the 2D - fifo array. The address in the shared - memory segment sm_ctl_header is a relative, - but this one, in process private memory, is - a real virtual address */ - uint16_t *mem_nodes; /**< cached copy of mem nodes of each local rank */ - unsigned int fifo_size; /**< number of FIFO queue entries */ - unsigned int fifo_lazy_free; /**< number of reads before lazy fifo free is triggered */ - int nfifos; /**< number of FIFOs per receiver */ - int32_t num_smp_procs; /**< current number of smp procs on this host */ - int32_t my_smp_rank; /**< My SMP process rank. Used for accessing - * SMP specfic data structures. */ - opal_free_list_t sm_frags_eager; /**< free list of sm first */ - opal_free_list_t sm_frags_max; /**< free list of sm second */ + mca_common_sm_module_t *sm_seg; /**< description of shared memory segment */ + volatile sm_fifo_t **shm_fifo; /**< pointer to fifo 2D array in shared memory */ + char **shm_bases; /**< pointer to base pointers in shared memory */ + uint16_t *shm_mem_nodes; /**< pointer to mem noded in shared memory */ + sm_fifo_t **fifo; /**< cached copy of the pointer to the 2D + fifo array. The address in the shared + memory segment sm_ctl_header is a relative, + but this one, in process private memory, is + a real virtual address */ + uint16_t *mem_nodes; /**< cached copy of mem nodes of each local rank */ + unsigned int fifo_size; /**< number of FIFO queue entries */ + unsigned int fifo_lazy_free; /**< number of reads before lazy fifo free is triggered */ + int nfifos; /**< number of FIFOs per receiver */ + int32_t num_smp_procs; /**< current number of smp procs on this host */ + int32_t my_smp_rank; /**< My SMP process rank. Used for accessing + * SMP specfic data structures. */ + opal_free_list_t sm_frags_eager; /**< free list of sm first */ + opal_free_list_t sm_frags_max; /**< free list of sm second */ opal_free_list_t sm_frags_user; - opal_free_list_t sm_first_frags_to_progress; /**< list of first - fragments that are - awaiting resources */ + opal_free_list_t sm_first_frags_to_progress; /**< list of first + fragments that are + awaiting resources */ struct mca_btl_base_endpoint_t **sm_peers; opal_free_list_t pending_send_fl; - opal_atomic_int32_t num_outstanding_frags; /**< number of fragments sent but not yet returned to free list */ - opal_atomic_int32_t num_pending_sends; /**< total number on all of my pending-send queues */ + opal_atomic_int32_t + num_outstanding_frags; /**< number of fragments sent but not yet returned to free list */ + opal_atomic_int32_t num_pending_sends; /**< total number on all of my pending-send queues */ int mem_node; int num_mem_nodes; #if OPAL_ENABLE_PROGRESS_THREADS == 1 - char sm_fifo_path[PATH_MAX]; /**< path to fifo used to signal this process */ - int sm_fifo_fd; /**< file descriptor corresponding to opened fifo */ + char sm_fifo_path[PATH_MAX]; /**< path to fifo used to signal this process */ + int sm_fifo_fd; /**< file descriptor corresponding to opened fifo */ opal_thread_t sm_fifo_thread; #endif - struct mca_btl_smcuda_t **sm_btls; + struct mca_btl_smcuda_t **sm_btls; struct mca_btl_smcuda_frag_t **table; size_t sm_num_btls; size_t sm_max_btls; - /** MCA: should we be using knem or not? neg=try but continue if not available, 0=don't try, 1=try and fail if not available */ int use_knem; @@ -216,16 +214,15 @@ OPAL_MODULE_DECLSPEC extern mca_btl_smcuda_component_t mca_btl_smcuda_component; * SM BTL Interface */ struct mca_btl_smcuda_t { - mca_btl_base_module_t super; /**< base BTL interface */ - bool btl_inited; /**< flag indicating if btl has been inited */ + mca_btl_base_module_t super; /**< base BTL interface */ + bool btl_inited; /**< flag indicating if btl has been inited */ mca_btl_base_module_error_cb_fn_t error_cb; mca_rcache_base_module_t *rcache; }; typedef struct mca_btl_smcuda_t mca_btl_smcuda_t; OPAL_MODULE_DECLSPEC extern mca_btl_smcuda_t mca_btl_smcuda; -struct btl_smcuda_pending_send_item_t -{ +struct btl_smcuda_pending_send_item_t { opal_free_list_item_t super; void *data; }; @@ -243,26 +240,30 @@ typedef struct btl_smcuda_pending_send_item_t btl_smcuda_pending_send_item_t; * we define macros to translate between relative addresses and * virtual addresses. */ -#define VIRTUAL2RELATIVE(VADDR ) ((long)(VADDR) - (long)mca_btl_smcuda_component.shm_bases[mca_btl_smcuda_component.my_smp_rank]) -#define RELATIVE2VIRTUAL(OFFSET) ((long)(OFFSET) + (long)mca_btl_smcuda_component.shm_bases[mca_btl_smcuda_component.my_smp_rank]) - -static inline int sm_fifo_init(int fifo_size, mca_mpool_base_module_t *mpool, - sm_fifo_t *fifo, int lazy_free) +#define VIRTUAL2RELATIVE(VADDR) \ + ((long) (VADDR) \ + - (long) mca_btl_smcuda_component.shm_bases[mca_btl_smcuda_component.my_smp_rank]) +#define RELATIVE2VIRTUAL(OFFSET) \ + ((long) (OFFSET) \ + + (long) mca_btl_smcuda_component.shm_bases[mca_btl_smcuda_component.my_smp_rank]) + +static inline int sm_fifo_init(int fifo_size, mca_mpool_base_module_t *mpool, sm_fifo_t *fifo, + int lazy_free) { int i, qsize; /* figure out the queue size (a power of two that is at least 1) */ - qsize = opal_next_poweroftwo_inclusive (fifo_size); + qsize = opal_next_poweroftwo_inclusive(fifo_size); /* allocate the queue in the receiver's address space */ - fifo->queue_recv = (volatile void **)mpool->mpool_alloc( - mpool, sizeof(void *) * qsize, opal_cache_line_size, 0); - if(NULL == fifo->queue_recv) { + fifo->queue_recv = (volatile void **) mpool->mpool_alloc(mpool, sizeof(void *) * qsize, + opal_cache_line_size, 0); + if (NULL == fifo->queue_recv) { return OPAL_ERR_OUT_OF_RESOURCE; } /* initialize the queue */ - for ( i = 0; i < qsize; i++ ) + for (i = 0; i < qsize; i++) fifo->queue_recv[i] = SM_FIFO_FREE; /* shift queue address to be relative */ @@ -271,8 +272,8 @@ static inline int sm_fifo_init(int fifo_size, mca_mpool_base_module_t *mpool, /* initialize the locks */ opal_atomic_lock_init(&(fifo->head_lock), OPAL_ATOMIC_LOCK_UNLOCKED); opal_atomic_lock_init(&(fifo->tail_lock), OPAL_ATOMIC_LOCK_UNLOCKED); - opal_atomic_unlock(&(fifo->head_lock)); /* should be unnecessary */ - opal_atomic_unlock(&(fifo->tail_lock)); /* should be unnecessary */ + opal_atomic_unlock(&(fifo->head_lock)); /* should be unnecessary */ + opal_atomic_unlock(&(fifo->tail_lock)); /* should be unnecessary */ /* other initializations */ fifo->head = 0; @@ -284,14 +285,13 @@ static inline int sm_fifo_init(int fifo_size, mca_mpool_base_module_t *mpool, return OPAL_SUCCESS; } - static inline int sm_fifo_write(void *value, sm_fifo_t *fifo) { volatile void **q = (volatile void **) RELATIVE2VIRTUAL(fifo->queue); /* if there is no free slot to write, report exhausted resource */ opal_atomic_rmb(); - if ( SM_FIFO_FREE != q[fifo->head] ) + if (SM_FIFO_FREE != q[fifo->head]) return OPAL_ERR_OUT_OF_RESOURCE; /* otherwise, write to the slot and advance the head index */ @@ -301,7 +301,6 @@ static inline int sm_fifo_write(void *value, sm_fifo_t *fifo) return OPAL_SUCCESS; } - static inline void *sm_fifo_read(sm_fifo_t *fifo) { void *value; @@ -312,18 +311,18 @@ static inline void *sm_fifo_read(sm_fifo_t *fifo) opal_atomic_rmb(); /* if you read a non-empty slot, advance the tail pointer */ - if ( SM_FIFO_FREE != value ) { + if (SM_FIFO_FREE != value) { - fifo->tail = ( fifo->tail + 1 ) & fifo->mask; + fifo->tail = (fifo->tail + 1) & fifo->mask; fifo->num_to_clear += 1; /* check if it's time to free slots, which we do lazily */ - if ( fifo->num_to_clear >= fifo->lazy_free ) { - int i = (fifo->tail - fifo->num_to_clear ) & fifo->mask; + if (fifo->num_to_clear >= fifo->lazy_free) { + int i = (fifo->tail - fifo->num_to_clear) & fifo->mask; - while ( fifo->num_to_clear > 0 ) { + while (fifo->num_to_clear > 0) { fifo->queue_recv[i] = SM_FIFO_FREE; - i = (i+1) & fifo->mask; + i = (i + 1) & fifo->mask; fifo->num_to_clear -= 1; } opal_atomic_wmb(); @@ -338,8 +337,6 @@ static inline void *sm_fifo_read(sm_fifo_t *fifo) */ extern int mca_btl_smcuda_component_progress(void); - - /** * Register a callback function that is called on error.. * @@ -347,10 +344,8 @@ extern int mca_btl_smcuda_component_progress(void); * @return Status indicating if cleanup was successful */ -int mca_btl_smcuda_register_error_cb( - struct mca_btl_base_module_t* btl, - mca_btl_base_module_error_cb_fn_t cbfunc -); +int mca_btl_smcuda_register_error_cb(struct mca_btl_base_module_t *btl, + mca_btl_base_module_error_cb_fn_t cbfunc); /** * Cleanup any resources held by the BTL. @@ -359,10 +354,7 @@ int mca_btl_smcuda_register_error_cb( * @return OPAL_SUCCESS or error status on failure. */ -extern int mca_btl_smcuda_finalize( - struct mca_btl_base_module_t* btl -); - +extern int mca_btl_smcuda_finalize(struct mca_btl_base_module_t *btl); /** * PML->BTL notification of change in the process list. @@ -378,14 +370,10 @@ extern int mca_btl_smcuda_finalize( * */ -extern int mca_btl_smcuda_add_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers, - struct opal_bitmap_t* reachability -); - +extern int mca_btl_smcuda_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers, + struct opal_bitmap_t *reachability); /** * PML->BTL notification of change in the process list. @@ -396,13 +384,9 @@ extern int mca_btl_smcuda_add_procs( * @return Status indicating if cleanup was successful * */ -extern int mca_btl_smcuda_del_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers -); - +extern int mca_btl_smcuda_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers); /** * Allocate a segment. @@ -410,13 +394,9 @@ extern int mca_btl_smcuda_del_procs( * @param btl (IN) BTL module * @param size (IN) Request segment size. */ -extern mca_btl_base_descriptor_t* mca_btl_smcuda_alloc( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags -); +extern mca_btl_base_descriptor_t *mca_btl_smcuda_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags); /** * Return a segment allocated by this BTL. @@ -424,11 +404,8 @@ extern mca_btl_base_descriptor_t* mca_btl_smcuda_alloc( * @param btl (IN) BTL module * @param segment (IN) Allocated segment. */ -extern int mca_btl_smcuda_free( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* segment -); - +extern int mca_btl_smcuda_free(struct mca_btl_base_module_t *btl, + mca_btl_base_descriptor_t *segment); /** * Pack data @@ -436,16 +413,11 @@ extern int mca_btl_smcuda_free( * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -struct mca_btl_base_descriptor_t* mca_btl_smcuda_prepare_src( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags -); - +struct mca_btl_base_descriptor_t * +mca_btl_smcuda_prepare_src(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, + size_t *size, uint32_t flags); /** * Initiate an inlined send to the peer or return a descriptor. @@ -453,16 +425,12 @@ struct mca_btl_base_descriptor_t* mca_btl_smcuda_prepare_src( * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -extern int mca_btl_smcuda_sendi( struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - void* header, - size_t header_size, - size_t payload_size, - uint8_t order, - uint32_t flags, - mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t** descriptor ); +extern int mca_btl_smcuda_sendi(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, + size_t header_size, size_t payload_size, uint8_t order, + uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor); /** * Initiate a send to the peer. @@ -470,22 +438,21 @@ extern int mca_btl_smcuda_sendi( struct mca_btl_base_module_t* btl, * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -extern int mca_btl_smcuda_send( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag -); +extern int mca_btl_smcuda_send(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, + mca_btl_base_tag_t tag); #if OPAL_CUDA_SUPPORT /** * Remote get using device memory. */ -int mca_btl_smcuda_get_cuda (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *ep, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_smcuda_get_cuda(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *ep, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata); /* CUDA IPC control message tags */ enum ipcCtrlMsg { @@ -496,44 +463,34 @@ enum ipcCtrlMsg { /* CUDA IPC control message */ typedef struct ctrlhdr_st { - enum ipcCtrlMsg ctag; - int cudev; + enum ipcCtrlMsg ctag; + int cudev; } ctrlhdr_t; /* State of setting up CUDA IPC on an endpoint */ -enum ipcState { - IPC_INIT = 1, - IPC_SENT, - IPC_ACKING, - IPC_ACKED, - IPC_OK, - IPC_BAD -}; +enum ipcState { IPC_INIT = 1, IPC_SENT, IPC_ACKING, IPC_ACKED, IPC_OK, IPC_BAD }; #endif /* OPAL_CUDA_SUPPORT */ - -extern void mca_btl_smcuda_dump(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - int verbose); +extern void mca_btl_smcuda_dump(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, int verbose); #if OPAL_ENABLE_PROGRESS_THREADS == 1 -void mca_btl_smcuda_component_event_thread(opal_object_t*); +void mca_btl_smcuda_component_event_thread(opal_object_t *); #endif #if OPAL_ENABLE_PROGRESS_THREADS == 1 -#define MCA_BTL_SMCUDA_SIGNAL_PEER(peer) \ -{ \ - unsigned char cmd = DATA; \ - if(write(peer->fifo_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { \ - opal_output(0, "mca_btl_smcuda_send: write fifo failed: errno=%d\n", errno); \ - } \ -} +# define MCA_BTL_SMCUDA_SIGNAL_PEER(peer) \ + { \ + unsigned char cmd = DATA; \ + if (write(peer->fifo_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { \ + opal_output(0, "mca_btl_smcuda_send: write fifo failed: errno=%d\n", errno); \ + } \ + } #else -#define MCA_BTL_SMCUDA_SIGNAL_PEER(peer) +# define MCA_BTL_SMCUDA_SIGNAL_PEER(peer) #endif END_C_DECLS #endif - diff --git a/opal/mca/btl/smcuda/btl_smcuda_component.c b/opal/mca/btl/smcuda/btl_smcuda_component.c index 9fa7db4430f..a123265caec 100644 --- a/opal/mca/btl/smcuda/btl_smcuda_component.c +++ b/opal/mca/btl/smcuda/btl_smcuda_component.c @@ -26,51 +26,48 @@ #include "opal_config.h" #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ #include #ifdef HAVE_FCNTL_H -#include -#endif /* HAVE_FCNTL_H */ +# include +#endif /* HAVE_FCNTL_H */ #ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ +# include +#endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_SYS_MMAN_H -#include -#endif /* HAVE_SYS_MMAN_H */ +# include +#endif /* HAVE_SYS_MMAN_H */ #ifdef HAVE_SYS_STAT_H -#include /* for mkfifo */ -#endif /* HAVE_SYS_STAT_H */ +# include /* for mkfifo */ +#endif /* HAVE_SYS_STAT_H */ #include "opal/mca/hwloc/base/base.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/shmem/shmem.h" #include "opal/util/bit_ops.h" #include "opal/util/output.h" -#include "opal/util/show_help.h" #include "opal/util/printf.h" +#include "opal/util/show_help.h" -#include "opal/mca/mpool/base/base.h" -#include "opal/mca/common/sm/common_sm.h" #include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/common/sm/common_sm.h" +#include "opal/mca/mpool/base/base.h" #include "opal/runtime/opal_params.h" #if OPAL_CUDA_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" +# include "opal/mca/common/cuda/common_cuda.h" #endif /* OPAL_CUDA_SUPPORT */ #include "btl_smcuda.h" -#include "btl_smcuda_frag.h" #include "btl_smcuda_fifo.h" +#include "btl_smcuda_frag.h" static int mca_btl_smcuda_component_open(void); static int mca_btl_smcuda_component_close(void); static int smcuda_register(void); -static mca_btl_base_module_t** mca_btl_smcuda_component_init( - int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads -); +static mca_btl_base_module_t ** +mca_btl_smcuda_component_init(int *num_btls, bool enable_progress_threads, bool enable_mpi_threads); typedef enum { MCA_BTL_SM_RNDV_MOD_SM = 0, @@ -81,67 +78,61 @@ typedef enum { * Shared Memory (SM) component instance. */ mca_btl_smcuda_component_t mca_btl_smcuda_component = { - .super = { - /* First, the mca_base_component_t struct containing meta information - about the component itself */ - .btl_version = { - MCA_BTL_DEFAULT_VERSION("smcuda"), - .mca_open_component = mca_btl_smcuda_component_open, - .mca_close_component = mca_btl_smcuda_component_close, - .mca_register_component_params = smcuda_register, - }, - .btl_data = { - /* The component is checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - - .btl_init = mca_btl_smcuda_component_init, - .btl_progress = mca_btl_smcuda_component_progress, - } /* end super */ + .super = + { + /* First, the mca_base_component_t struct containing meta information + about the component itself */ + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("smcuda"), + .mca_open_component = mca_btl_smcuda_component_open, + .mca_close_component = mca_btl_smcuda_component_close, + .mca_register_component_params = smcuda_register, + }, + .btl_data = + {/* The component is checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + .btl_init = mca_btl_smcuda_component_init, + .btl_progress = mca_btl_smcuda_component_progress, + } /* end super */ }; - /* * utility routines for parameter registration */ -static inline int mca_btl_smcuda_param_register_int( - const char* param_name, - int default_value, - int level, - int *storage) +static inline int mca_btl_smcuda_param_register_int(const char *param_name, int default_value, + int level, int *storage) { *storage = default_value; - (void) mca_base_component_var_register (&mca_btl_smcuda_component.super.btl_version, - param_name, NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, 0, level, - MCA_BASE_VAR_SCOPE_READONLY, storage); + (void) mca_base_component_var_register(&mca_btl_smcuda_component.super.btl_version, param_name, + NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, level, + MCA_BASE_VAR_SCOPE_READONLY, storage); return *storage; } -static inline unsigned int mca_btl_smcuda_param_register_uint( - const char* param_name, - unsigned int default_value, - int level, - unsigned int *storage) +static inline unsigned int mca_btl_smcuda_param_register_uint(const char *param_name, + unsigned int default_value, int level, + unsigned int *storage) { *storage = default_value; - (void) mca_base_component_var_register (&mca_btl_smcuda_component.super.btl_version, - param_name, NULL, MCA_BASE_VAR_TYPE_UNSIGNED_INT, - NULL, 0, 0, level, - MCA_BASE_VAR_SCOPE_READONLY, storage); + (void) mca_base_component_var_register(&mca_btl_smcuda_component.super.btl_version, param_name, + NULL, MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, level, + MCA_BASE_VAR_SCOPE_READONLY, storage); return *storage; } static int mca_btl_smcuda_component_verify(void) { /* We canot support async memcpy right now */ - if( (mca_btl_smcuda.super.btl_flags & MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV) || - (mca_btl_smcuda.super.btl_flags & MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND) ) { + if ((mca_btl_smcuda.super.btl_flags & MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV) + || (mca_btl_smcuda.super.btl_flags & MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND)) { opal_output_verbose(10, opal_btl_base_framework.framework_output, "btl: smcuda: disable all asynchronous memcpy support"); } - mca_btl_smcuda.super.btl_flags &= ~(MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV | MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND); + mca_btl_smcuda.super.btl_flags &= ~(MCA_BTL_FLAGS_CUDA_COPY_ASYNC_RECV + | MCA_BTL_FLAGS_CUDA_COPY_ASYNC_SEND); return mca_btl_base_param_verify(&mca_btl_smcuda.super); } @@ -155,63 +146,74 @@ static int smcuda_register(void) OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_smcuda_component.mpool_min_size); - mca_btl_smcuda_param_register_int("free_list_num", 8, OPAL_INFO_LVL_5, &mca_btl_smcuda_component.sm_free_list_num); - mca_btl_smcuda_param_register_int("free_list_max", -1, OPAL_INFO_LVL_5, &mca_btl_smcuda_component.sm_free_list_max); - mca_btl_smcuda_param_register_int("free_list_inc", 64, OPAL_INFO_LVL_5, &mca_btl_smcuda_component.sm_free_list_inc); - mca_btl_smcuda_param_register_int("max_procs", -1, OPAL_INFO_LVL_5, &mca_btl_smcuda_component.sm_max_procs); + mca_btl_smcuda_param_register_int("free_list_num", 8, OPAL_INFO_LVL_5, + &mca_btl_smcuda_component.sm_free_list_num); + mca_btl_smcuda_param_register_int("free_list_max", -1, OPAL_INFO_LVL_5, + &mca_btl_smcuda_component.sm_free_list_max); + mca_btl_smcuda_param_register_int("free_list_inc", 64, OPAL_INFO_LVL_5, + &mca_btl_smcuda_component.sm_free_list_inc); + mca_btl_smcuda_param_register_int("max_procs", -1, OPAL_INFO_LVL_5, + &mca_btl_smcuda_component.sm_max_procs); /* there is no practical use for the mpool name parameter since mpool resources differ between components */ mca_btl_smcuda_component.sm_mpool_name = "sm"; - mca_btl_smcuda_param_register_uint("fifo_size", 4096, OPAL_INFO_LVL_4, &mca_btl_smcuda_component.fifo_size); - mca_btl_smcuda_param_register_int("num_fifos", 1, OPAL_INFO_LVL_4, &mca_btl_smcuda_component.nfifos); + mca_btl_smcuda_param_register_uint("fifo_size", 4096, OPAL_INFO_LVL_4, + &mca_btl_smcuda_component.fifo_size); + mca_btl_smcuda_param_register_int("num_fifos", 1, OPAL_INFO_LVL_4, + &mca_btl_smcuda_component.nfifos); - mca_btl_smcuda_param_register_uint("fifo_lazy_free", 120, OPAL_INFO_LVL_5, &mca_btl_smcuda_component.fifo_lazy_free); + mca_btl_smcuda_param_register_uint("fifo_lazy_free", 120, OPAL_INFO_LVL_5, + &mca_btl_smcuda_component.fifo_lazy_free); /* default number of extra procs to allow for future growth */ - mca_btl_smcuda_param_register_int("sm_extra_procs", 0, OPAL_INFO_LVL_9, &mca_btl_smcuda_component.sm_extra_procs); + mca_btl_smcuda_param_register_int("sm_extra_procs", 0, OPAL_INFO_LVL_9, + &mca_btl_smcuda_component.sm_extra_procs); mca_btl_smcuda_component.allocator = "bucket"; - (void) mca_base_component_var_register (&mca_btl_smcuda_component.super.btl_version, "allocator", - "Name of allocator component to use for btl/smcuda allocations", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_smcuda_component.allocator); + (void) mca_base_component_var_register( + &mca_btl_smcuda_component.super.btl_version, "allocator", + "Name of allocator component to use for btl/smcuda allocations", MCA_BASE_VAR_TYPE_STRING, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_smcuda_component.allocator); #if OPAL_CUDA_SUPPORT /* Lower priority when CUDA support is not requested */ if (opal_cuda_support) { - mca_btl_smcuda.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH+1; + mca_btl_smcuda.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH + 1; } else { mca_btl_smcuda.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_LOW; } - mca_btl_smcuda_param_register_int("use_cuda_ipc", 1, OPAL_INFO_LVL_4, &mca_btl_smcuda_component.use_cuda_ipc); - mca_btl_smcuda_param_register_int("use_cuda_ipc_same_gpu", 1, OPAL_INFO_LVL_4,&mca_btl_smcuda_component.use_cuda_ipc_same_gpu); - mca_btl_smcuda_param_register_int("cuda_ipc_verbose", 0, OPAL_INFO_LVL_4, &mca_btl_smcuda_component.cuda_ipc_verbose); + mca_btl_smcuda_param_register_int("use_cuda_ipc", 1, OPAL_INFO_LVL_4, + &mca_btl_smcuda_component.use_cuda_ipc); + mca_btl_smcuda_param_register_int("use_cuda_ipc_same_gpu", 1, OPAL_INFO_LVL_4, + &mca_btl_smcuda_component.use_cuda_ipc_same_gpu); + mca_btl_smcuda_param_register_int("cuda_ipc_verbose", 0, OPAL_INFO_LVL_4, + &mca_btl_smcuda_component.cuda_ipc_verbose); mca_btl_smcuda_component.cuda_ipc_output = opal_output_open(NULL); - opal_output_set_verbosity(mca_btl_smcuda_component.cuda_ipc_output, mca_btl_smcuda_component.cuda_ipc_verbose); + opal_output_set_verbosity(mca_btl_smcuda_component.cuda_ipc_output, + mca_btl_smcuda_component.cuda_ipc_verbose); #else /* OPAL_CUDA_SUPPORT */ mca_btl_smcuda.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_LOW; #endif /* OPAL_CUDA_SUPPORT */ - mca_btl_smcuda.super.btl_eager_limit = 4*1024; - mca_btl_smcuda.super.btl_rndv_eager_limit = 4*1024; - mca_btl_smcuda.super.btl_max_send_size = 32*1024; - mca_btl_smcuda.super.btl_rdma_pipeline_send_length = 64*1024; - mca_btl_smcuda.super.btl_rdma_pipeline_frag_size = 64*1024; - mca_btl_smcuda.super.btl_min_rdma_pipeline_size = 64*1024; + mca_btl_smcuda.super.btl_eager_limit = 4 * 1024; + mca_btl_smcuda.super.btl_rndv_eager_limit = 4 * 1024; + mca_btl_smcuda.super.btl_max_send_size = 32 * 1024; + mca_btl_smcuda.super.btl_rdma_pipeline_send_length = 64 * 1024; + mca_btl_smcuda.super.btl_rdma_pipeline_frag_size = 64 * 1024; + mca_btl_smcuda.super.btl_min_rdma_pipeline_size = 64 * 1024; mca_btl_smcuda.super.btl_flags = MCA_BTL_FLAGS_SEND; - mca_btl_smcuda.super.btl_registration_handle_size = sizeof (mca_btl_base_registration_handle_t); - mca_btl_smcuda.super.btl_bandwidth = 9000; /* Mbs */ - mca_btl_smcuda.super.btl_latency = 1; /* Microsecs */ + mca_btl_smcuda.super.btl_registration_handle_size = sizeof(mca_btl_base_registration_handle_t); + mca_btl_smcuda.super.btl_bandwidth = 9000; /* Mbs */ + mca_btl_smcuda.super.btl_latency = 1; /* Microsecs */ /* Call the BTL based to register its MCA params */ - mca_btl_base_param_register(&mca_btl_smcuda_component.super.btl_version, - &mca_btl_smcuda.super); + mca_btl_base_param_register(&mca_btl_smcuda_component.super.btl_version, &mca_btl_smcuda.super); #if OPAL_CUDA_SUPPORT /* If user has not set the value, then set to the defalt */ if (0 == mca_btl_smcuda.super.btl_cuda_max_send_size) { - mca_btl_smcuda.super.btl_cuda_max_send_size = 128*1024; + mca_btl_smcuda.super.btl_cuda_max_send_size = 128 * 1024; } - /* If user has not set the value, then set to magic number which will be converted to the minimum - * size needed to fit the PML header (see pml_ob1.c) */ + /* If user has not set the value, then set to magic number which will be converted to the + * minimum size needed to fit the PML header (see pml_ob1.c) */ if (0 == mca_btl_smcuda.super.btl_cuda_eager_limit) { mca_btl_smcuda.super.btl_cuda_eager_limit = SIZE_MAX; /* magic number */ } @@ -234,13 +236,14 @@ static int mca_btl_smcuda_component_open(void) mca_btl_smcuda_component.sm_max_btls = 1; /* make sure the number of fifos is a power of 2 */ - mca_btl_smcuda_component.nfifos = opal_next_poweroftwo_inclusive (mca_btl_smcuda_component.nfifos); + mca_btl_smcuda_component.nfifos = opal_next_poweroftwo_inclusive( + mca_btl_smcuda_component.nfifos); /* make sure that queue size and lazy free parameter are compatible */ - if (mca_btl_smcuda_component.fifo_lazy_free >= (mca_btl_smcuda_component.fifo_size >> 1) ) - mca_btl_smcuda_component.fifo_lazy_free = (mca_btl_smcuda_component.fifo_size >> 1); + if (mca_btl_smcuda_component.fifo_lazy_free >= (mca_btl_smcuda_component.fifo_size >> 1)) + mca_btl_smcuda_component.fifo_lazy_free = (mca_btl_smcuda_component.fifo_size >> 1); if (mca_btl_smcuda_component.fifo_lazy_free <= 0) - mca_btl_smcuda_component.fifo_lazy_free = 1; + mca_btl_smcuda_component.fifo_lazy_free = 1; mca_btl_smcuda_component.max_frag_size = mca_btl_smcuda.super.btl_max_send_size; mca_btl_smcuda_component.eager_limit = mca_btl_smcuda.super.btl_eager_limit; @@ -252,8 +255,9 @@ static int mca_btl_smcuda_component_open(void) } opal_output_verbose(10, opal_btl_base_framework.framework_output, "btl: smcuda: cuda_max_send_size=%d, max_send_size=%d, max_frag_size=%d", - (int)mca_btl_smcuda.super.btl_cuda_max_send_size, (int)mca_btl_smcuda.super.btl_max_send_size, - (int)mca_btl_smcuda_component.max_frag_size); + (int) mca_btl_smcuda.super.btl_cuda_max_send_size, + (int) mca_btl_smcuda.super.btl_max_send_size, + (int) mca_btl_smcuda_component.max_frag_size); #endif /* OPAL_CUDA_SUPPORT */ /* initialize objects */ @@ -265,7 +269,6 @@ static int mca_btl_smcuda_component_open(void) return OPAL_SUCCESS; } - /* * component cleanup - sanity checking of queue lengths */ @@ -274,7 +277,6 @@ static int mca_btl_smcuda_component_close(void) { int return_value = OPAL_SUCCESS; - OBJ_DESTRUCT(&mca_btl_smcuda_component.sm_lock); /** * We don't have to destroy the fragment lists. They are allocated @@ -285,11 +287,11 @@ static int mca_btl_smcuda_component_close(void) /*OBJ_DESTRUCT(&mca_btl_smcuda_component.sm_frags_max);*/ /* unmap the shared memory control structure */ - if(mca_btl_smcuda_component.sm_seg != NULL) { - return_value = mca_common_sm_fini( mca_btl_smcuda_component.sm_seg ); - if( OPAL_SUCCESS != return_value ) { + if (mca_btl_smcuda_component.sm_seg != NULL) { + return_value = mca_common_sm_fini(mca_btl_smcuda_component.sm_seg); + if (OPAL_SUCCESS != return_value) { return_value = OPAL_ERROR; - opal_output(0," mca_common_sm_fini failed\n"); + opal_output(0, " mca_common_sm_fini failed\n"); goto CLEANUP; } @@ -303,13 +305,11 @@ static int mca_btl_smcuda_component_close(void) #if OPAL_ENABLE_PROGRESS_THREADS == 1 /* close/cleanup fifo create for event notification */ - if(mca_btl_smcuda_component.sm_fifo_fd > 0) { + if (mca_btl_smcuda_component.sm_fifo_fd > 0) { /* write a done message down the pipe */ unsigned char cmd = DONE; - if( write(mca_btl_smcuda_component.sm_fifo_fd,&cmd,sizeof(cmd)) != - sizeof(cmd)){ - opal_output(0, "mca_btl_smcuda_component_close: write fifo failed: errno=%d\n", - errno); + if (write(mca_btl_smcuda_component.sm_fifo_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { + opal_output(0, "mca_btl_smcuda_component_close: write fifo failed: errno=%d\n", errno); } opal_thread_join(&mca_btl_smcuda_component.sm_fifo_thread, NULL); close(mca_btl_smcuda_component.sm_fifo_fd); @@ -330,24 +330,21 @@ static int mca_btl_smcuda_component_close(void) /* * Returns the number of processes on the node. */ -static inline int -get_num_local_procs(void) +static inline int get_num_local_procs(void) { /* num_local_peers does not include us in * its calculation, so adjust for that */ - return (int)(1 + opal_process_info.num_local_peers); + return (int) (1 + opal_process_info.num_local_peers); } -static void -calc_sm_max_procs(int n) +static void calc_sm_max_procs(int n) { /* see if need to allocate space for extra procs */ if (0 > mca_btl_smcuda_component.sm_max_procs) { /* no limit */ if (0 <= mca_btl_smcuda_component.sm_extra_procs) { /* limit */ - mca_btl_smcuda_component.sm_max_procs = - n + mca_btl_smcuda_component.sm_extra_procs; + mca_btl_smcuda_component.sm_max_procs = n + mca_btl_smcuda_component.sm_extra_procs; } else { /* no limit */ mca_btl_smcuda_component.sm_max_procs = 2 * n; @@ -355,30 +352,24 @@ calc_sm_max_procs(int n) } } -static int -create_and_attach(mca_btl_smcuda_component_t *comp_ptr, - size_t size, - char *file_name, - size_t size_ctl_structure, - size_t data_seg_alignment, - mca_common_sm_module_t **out_modp) +static int create_and_attach(mca_btl_smcuda_component_t *comp_ptr, size_t size, char *file_name, + size_t size_ctl_structure, size_t data_seg_alignment, + mca_common_sm_module_t **out_modp) { - if (NULL == (*out_modp = - mca_common_sm_module_create_and_attach(size, file_name, - size_ctl_structure, - data_seg_alignment))) { - opal_output(0, "create_and_attach: unable to create shared memory " + if (NULL + == (*out_modp = mca_common_sm_module_create_and_attach(size, file_name, size_ctl_structure, + data_seg_alignment))) { + opal_output(0, + "create_and_attach: unable to create shared memory " "BTL coordinating strucure :: size %lu \n", - (unsigned long)size); + (unsigned long) size); return OPAL_ERROR; } return OPAL_SUCCESS; } -static int -get_mpool_res_size(int32_t max_procs, - size_t *out_res_size) +static int get_mpool_res_size(int32_t max_procs, size_t *out_res_size) { size_t size = 0; @@ -396,13 +387,13 @@ get_mpool_res_size(int32_t max_procs, * "opal_cache_line_size" additions to account for some * padding and edge effects that may lie in the allocator. */ - size = FIFO_MAP_NUM(max_procs) * - (sizeof(sm_fifo_t) + sizeof(void *) * - mca_btl_smcuda_component.fifo_size + 4 * opal_cache_line_size) + - (2 * max_procs + mca_btl_smcuda_component.sm_free_list_inc) * - (mca_btl_smcuda_component.eager_limit + 2 * opal_cache_line_size) + - mca_btl_smcuda_component.sm_free_list_num * - (mca_btl_smcuda_component.max_frag_size + 2 * opal_cache_line_size); + size = FIFO_MAP_NUM(max_procs) + * (sizeof(sm_fifo_t) + sizeof(void *) * mca_btl_smcuda_component.fifo_size + + 4 * opal_cache_line_size) + + (2 * max_procs + mca_btl_smcuda_component.sm_free_list_inc) + * (mca_btl_smcuda_component.eager_limit + 2 * opal_cache_line_size) + + mca_btl_smcuda_component.sm_free_list_num + * (mca_btl_smcuda_component.max_frag_size + 2 * opal_cache_line_size); /* add something for the control structure */ size += sizeof(mca_common_sm_module_t); @@ -413,19 +404,17 @@ get_mpool_res_size(int32_t max_procs, * mpool_sm_component.c when sizeof(mca_common_sm_module_t) is * added. */ - if (((double)size) * max_procs > LONG_MAX - 4096) { + if (((double) size) * max_procs > LONG_MAX - 4096) { return OPAL_ERR_VALUE_OUT_OF_BOUNDS; } - size *= (size_t)max_procs; + size *= (size_t) max_procs; *out_res_size = size; return OPAL_SUCCESS; } - /* Generates all the unique paths for the shared-memory segments that this BTL * needs along with other file paths used to share "connection information". */ -static int -set_uniq_paths_for_init_rndv(mca_btl_smcuda_component_t *comp_ptr) +static int set_uniq_paths_for_init_rndv(mca_btl_smcuda_component_t *comp_ptr) { int rc = OPAL_ERR_OUT_OF_RESOURCE; @@ -436,30 +425,30 @@ set_uniq_paths_for_init_rndv(mca_btl_smcuda_component_t *comp_ptr) comp_ptr->sm_rndv_file_name = NULL; if (opal_asprintf(&comp_ptr->sm_mpool_ctl_file_name, - "%s"OPAL_PATH_SEP"shared_mem_cuda_pool.%s", - opal_process_info.job_session_dir, - opal_process_info.nodename) < 0) { + "%s" OPAL_PATH_SEP "shared_mem_cuda_pool.%s", + opal_process_info.job_session_dir, opal_process_info.nodename) + < 0) { /* rc set */ goto out; } if (opal_asprintf(&comp_ptr->sm_mpool_rndv_file_name, - "%s"OPAL_PATH_SEP"shared_mem_cuda_pool_rndv.%s", - opal_process_info.job_session_dir, - opal_process_info.nodename) < 0) { + "%s" OPAL_PATH_SEP "shared_mem_cuda_pool_rndv.%s", + opal_process_info.job_session_dir, opal_process_info.nodename) + < 0) { /* rc set */ goto out; } if (opal_asprintf(&comp_ptr->sm_ctl_file_name, - "%s"OPAL_PATH_SEP"shared_mem_cuda_btl_module.%s", - opal_process_info.job_session_dir, - opal_process_info.nodename) < 0) { + "%s" OPAL_PATH_SEP "shared_mem_cuda_btl_module.%s", + opal_process_info.job_session_dir, opal_process_info.nodename) + < 0) { /* rc set */ goto out; } if (opal_asprintf(&comp_ptr->sm_rndv_file_name, - "%s"OPAL_PATH_SEP"shared_mem_cuda_btl_rndv.%s", - opal_process_info.job_session_dir, - opal_process_info.nodename) < 0) { + "%s" OPAL_PATH_SEP "shared_mem_cuda_btl_rndv.%s", + opal_process_info.job_session_dir, opal_process_info.nodename) + < 0) { /* rc set */ goto out; } @@ -484,9 +473,8 @@ set_uniq_paths_for_init_rndv(mca_btl_smcuda_component_t *comp_ptr) return rc; } -static int -create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, - mca_btl_sm_rndv_module_type_t type) +static int create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, + mca_btl_sm_rndv_module_type_t type) { size_t size = 0; int rc = OPAL_SUCCESS; @@ -497,8 +485,7 @@ create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, if (MCA_BTL_SM_RNDV_MOD_MPOOL == type) { /* get the segment size for the sm mpool. */ - if (OPAL_SUCCESS != (rc = get_mpool_res_size(comp_ptr->sm_max_procs, - &size))) { + if (OPAL_SUCCESS != (rc = get_mpool_res_size(comp_ptr->sm_max_procs, &size))) { /* rc is already set */ goto out; } @@ -511,33 +498,29 @@ create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, /* we only need the shmem_ds info at this point. initilization will be * completed in the mpool module code. the idea is that we just need this * info so we can populate the rndv file (or modex when we have it). */ - if (OPAL_SUCCESS != (rc = - create_and_attach(comp_ptr, size, comp_ptr->sm_mpool_ctl_file_name, - sizeof(mca_common_sm_module_t), 8, &tmp_modp))) { + if (OPAL_SUCCESS + != (rc = create_and_attach(comp_ptr, size, comp_ptr->sm_mpool_ctl_file_name, + sizeof(mca_common_sm_module_t), 8, &tmp_modp))) { /* rc is set */ goto out; } fname = comp_ptr->sm_mpool_rndv_file_name; - } - else if (MCA_BTL_SM_RNDV_MOD_SM == type) { + } else if (MCA_BTL_SM_RNDV_MOD_SM == type) { /* calculate the segment size. */ - size = sizeof(mca_common_sm_seg_header_t) + - comp_ptr->sm_max_procs * - (sizeof(sm_fifo_t *) + - sizeof(char *) + sizeof(uint16_t)) + - opal_cache_line_size; - - if (OPAL_SUCCESS != (rc = - create_and_attach(comp_ptr, size, comp_ptr->sm_ctl_file_name, - sizeof(mca_common_sm_seg_header_t), - opal_cache_line_size, &comp_ptr->sm_seg))) { + size = sizeof(mca_common_sm_seg_header_t) + + comp_ptr->sm_max_procs * (sizeof(sm_fifo_t *) + sizeof(char *) + sizeof(uint16_t)) + + opal_cache_line_size; + + if (OPAL_SUCCESS + != (rc = create_and_attach(comp_ptr, size, comp_ptr->sm_ctl_file_name, + sizeof(mca_common_sm_seg_header_t), opal_cache_line_size, + &comp_ptr->sm_seg))) { /* rc is set */ goto out; } fname = comp_ptr->sm_rndv_file_name; tmp_modp = comp_ptr->sm_seg; - } - else { + } else { return OPAL_ERR_BAD_PARAM; } @@ -548,24 +531,24 @@ create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, * sizeof(opal_shmem_ds_t), so we know where the mpool_res_size starts. */ if (-1 == (fd = open(fname, O_CREAT | O_RDWR, 0600))) { int err = errno; - opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, - "open(2)", strerror(err), err); + opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, "open(2)", strerror(err), + err); rc = OPAL_ERR_IN_ERRNO; goto out; } - if ((ssize_t)sizeof(opal_shmem_ds_t) != write(fd, &(tmp_modp->shmem_ds), - sizeof(opal_shmem_ds_t))) { + if ((ssize_t) sizeof(opal_shmem_ds_t) + != write(fd, &(tmp_modp->shmem_ds), sizeof(opal_shmem_ds_t))) { int err = errno; - opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, - "write(2)", strerror(err), err); + opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, "write(2)", strerror(err), + err); rc = OPAL_ERR_IN_ERRNO; goto out; } if (MCA_BTL_SM_RNDV_MOD_MPOOL == type) { - if ((ssize_t)sizeof(size) != write(fd, &size, sizeof(size))) { + if ((ssize_t) sizeof(size) != write(fd, &size, sizeof(size))) { int err = errno; - opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, - "write(2)", strerror(err), err); + opal_show_help("help-mpi-btl-smcuda.txt", "sys call fail", true, "write(2)", + strerror(err), err); rc = OPAL_ERR_IN_ERRNO; goto out; } @@ -575,7 +558,7 @@ create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, out: if (-1 != fd) { - (void)close(fd); + (void) close(fd); } return rc; } @@ -583,9 +566,7 @@ create_rndv_file(mca_btl_smcuda_component_t *comp_ptr, /* * Creates information required for the sm modex and modex sends it. */ -static int -backing_store_init(mca_btl_smcuda_component_t *comp_ptr, - uint32_t local_rank) +static int backing_store_init(mca_btl_smcuda_component_t *comp_ptr, uint32_t local_rank) { int rc = OPAL_SUCCESS; @@ -595,13 +576,11 @@ backing_store_init(mca_btl_smcuda_component_t *comp_ptr, /* only let the lowest rank setup the metadata */ if (0 == local_rank) { /* === sm mpool === */ - if (OPAL_SUCCESS != (rc = - create_rndv_file(comp_ptr, MCA_BTL_SM_RNDV_MOD_MPOOL))) { + if (OPAL_SUCCESS != (rc = create_rndv_file(comp_ptr, MCA_BTL_SM_RNDV_MOD_MPOOL))) { goto out; } /* === sm === */ - if (OPAL_SUCCESS != (rc = - create_rndv_file(comp_ptr, MCA_BTL_SM_RNDV_MOD_SM))) { + if (OPAL_SUCCESS != (rc = create_rndv_file(comp_ptr, MCA_BTL_SM_RNDV_MOD_SM))) { goto out; } } @@ -619,20 +598,21 @@ backing_store_init(mca_btl_smcuda_component_t *comp_ptr, * @param peer (IN) BTL peer addressing * @param peer (IN) If ready, then send ACK */ -static void mca_btl_smcuda_send_cuda_ipc_ack(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, int ready) +static void mca_btl_smcuda_send_cuda_ipc_ack(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, int ready) { - mca_btl_smcuda_frag_t* frag; + mca_btl_smcuda_frag_t *frag; ctrlhdr_t ctrlhdr; int rc; - if ( mca_btl_smcuda_component.num_outstanding_frags * 2 > (int) mca_btl_smcuda_component.fifo_size ) { + if (mca_btl_smcuda_component.num_outstanding_frags * 2 + > (int) mca_btl_smcuda_component.fifo_size) { mca_btl_smcuda_component_progress(); } /* allocate a fragment, giving up if we can't get one */ MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag); - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { endpoint->ipcstate = IPC_BAD; return; } @@ -657,8 +637,8 @@ static void mca_btl_smcuda_send_cuda_ipc_ack(struct mca_btl_base_module_t* btl, */ OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_outstanding_frags, +1); - MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, - endpoint->peer_smp_rank, (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); + MCA_BTL_SMCUDA_FIFO_WRITE(endpoint, endpoint->my_smp_rank, endpoint->peer_smp_rank, + (void *) VIRTUAL2RELATIVE(frag->hdr), false, true, rc); /* Set state now that we have sent message */ if (ready) { @@ -668,19 +648,18 @@ static void mca_btl_smcuda_send_cuda_ipc_ack(struct mca_btl_base_module_t* btl, } return; - } /* This function is utilized to set up CUDA IPC support within the smcuda * BTL. It handles smcuda specific control messages that are triggered * when GPU memory transfers are initiated. */ -static void btl_smcuda_control(mca_btl_base_module_t* btl, +static void btl_smcuda_control(mca_btl_base_module_t *btl, const mca_btl_base_receive_descriptor_t *descriptor) { int mydevnum, ipcaccess, res; ctrlhdr_t ctrlhdr; opal_proc_t *ep_proc; - mca_btl_smcuda_t *smcuda_btl = (mca_btl_smcuda_t *)btl; - const mca_btl_base_segment_t* segments = descriptor->des_segments; + mca_btl_smcuda_t *smcuda_btl = (mca_btl_smcuda_t *) btl; + const mca_btl_base_segment_t *segments = descriptor->des_segments; struct mca_btl_base_endpoint_t *endpoint = descriptor->endpoint; ep_proc = endpoint->proc_opal; @@ -699,17 +678,18 @@ static void btl_smcuda_control(mca_btl_base_module_t* btl, * accordingly. Otherwise, drop the request and let the other * side continue the handshake. */ OPAL_THREAD_LOCK(&endpoint->endpoint_lock); - if ((IPC_INIT == endpoint->ipcstate) || - ((IPC_SENT == endpoint->ipcstate) && (endpoint->my_smp_rank > endpoint->peer_smp_rank))) { - endpoint->ipcstate = IPC_ACKING; /* Move into new state to prevent any new connection attempts */ + if ((IPC_INIT == endpoint->ipcstate) + || ((IPC_SENT == endpoint->ipcstate) + && (endpoint->my_smp_rank > endpoint->peer_smp_rank))) { + endpoint->ipcstate = IPC_ACKING; /* Move into new state to prevent any new connection + attempts */ OPAL_THREAD_UNLOCK(&endpoint->endpoint_lock); /* If not yet CUDA ready, send a NOTREADY message back. */ if (!mca_common_cuda_enabled) { opal_output_verbose(10, mca_btl_smcuda_component.cuda_ipc_output, "Sending CUDA IPC NOTREADY: myrank=%d, peerrank=%d", - mca_btl_smcuda_component.my_smp_rank, - endpoint->peer_smp_rank); + mca_btl_smcuda_component.my_smp_rank, endpoint->peer_smp_rank); mca_btl_smcuda_send_cuda_ipc_ack(btl, endpoint, 0); return; } @@ -733,22 +713,23 @@ static void btl_smcuda_control(mca_btl_base_module_t* btl, if (mca_btl_smcuda_component.use_cuda_ipc_same_gpu) { ipcaccess = 1; } else { - opal_output_verbose(10, mca_btl_smcuda_component.cuda_ipc_output, - "Analyzed CUDA IPC request: myrank=%d, mydev=%d, peerrank=%d, " - "peerdev=%d --> Access is disabled by btl_smcuda_use_cuda_ipc_same_gpu", - endpoint->my_smp_rank, mydevnum, endpoint->peer_smp_rank, - ctrlhdr.cudev); + opal_output_verbose( + 10, mca_btl_smcuda_component.cuda_ipc_output, + "Analyzed CUDA IPC request: myrank=%d, mydev=%d, peerrank=%d, " + "peerdev=%d --> Access is disabled by btl_smcuda_use_cuda_ipc_same_gpu", + endpoint->my_smp_rank, mydevnum, endpoint->peer_smp_rank, ctrlhdr.cudev); endpoint->ipcstate = IPC_BAD; return; } } else { res = mca_common_cuda_device_can_access_peer(&ipcaccess, mydevnum, ctrlhdr.cudev); if (0 != res) { - opal_output_verbose(10, mca_btl_smcuda_component.cuda_ipc_output, - "Analyzed CUDA IPC request: myrank=%d, mydev=%d, peerrank=%d, " - "peerdev=%d --> Access is disabled because peer check failed with err=%d", - endpoint->my_smp_rank, mydevnum, endpoint->peer_smp_rank, - ctrlhdr.cudev, res); + opal_output_verbose( + 10, mca_btl_smcuda_component.cuda_ipc_output, + "Analyzed CUDA IPC request: myrank=%d, mydev=%d, peerrank=%d, " + "peerdev=%d --> Access is disabled because peer check failed with err=%d", + endpoint->my_smp_rank, mydevnum, endpoint->peer_smp_rank, ctrlhdr.cudev, + res); endpoint->ipcstate = IPC_BAD; return; } @@ -767,12 +748,12 @@ static void btl_smcuda_control(mca_btl_base_module_t* btl, endpoint->ipcstate = IPC_BAD; } else { /* CUDA IPC works */ - smcuda_btl->error_cb(&smcuda_btl->super, MCA_BTL_ERROR_FLAGS_ADD_CUDA_IPC, - ep_proc, (char *)&mca_btl_smcuda_component.cuda_ipc_output); - opal_output_verbose(10, mca_btl_smcuda_component.cuda_ipc_output, - "Sending CUDA IPC ACK: myrank=%d, mydev=%d, peerrank=%d, peerdev=%d", - endpoint->my_smp_rank, mydevnum, endpoint->peer_smp_rank, - ctrlhdr.cudev); + smcuda_btl->error_cb(&smcuda_btl->super, MCA_BTL_ERROR_FLAGS_ADD_CUDA_IPC, ep_proc, + (char *) &mca_btl_smcuda_component.cuda_ipc_output); + opal_output_verbose( + 10, mca_btl_smcuda_component.cuda_ipc_output, + "Sending CUDA IPC ACK: myrank=%d, mydev=%d, peerrank=%d, peerdev=%d", + endpoint->my_smp_rank, mydevnum, endpoint->peer_smp_rank, ctrlhdr.cudev); mca_btl_smcuda_send_cuda_ipc_ack(btl, endpoint, 1); } } else { @@ -787,8 +768,8 @@ static void btl_smcuda_control(mca_btl_base_module_t* btl, "Received CUDA IPC ACK, notifying PML: myrank=%d, peerrank=%d", endpoint->my_smp_rank, endpoint->peer_smp_rank); - smcuda_btl->error_cb(&smcuda_btl->super, MCA_BTL_ERROR_FLAGS_ADD_CUDA_IPC, - ep_proc, (char *)&mca_btl_smcuda_component.cuda_ipc_output); + smcuda_btl->error_cb(&smcuda_btl->super, MCA_BTL_ERROR_FLAGS_ADD_CUDA_IPC, ep_proc, + (char *) &mca_btl_smcuda_component.cuda_ipc_output); assert(endpoint->ipcstate == IPC_SENT); endpoint->ipcstate = IPC_ACKED; break; @@ -818,9 +799,7 @@ static void btl_smcuda_control(mca_btl_base_module_t* btl, * SM component initialization */ static mca_btl_base_module_t ** -mca_btl_smcuda_component_init(int *num_btls, - bool enable_progress_threads, - bool enable_mpi_threads) +mca_btl_smcuda_component_init(int *num_btls, bool enable_progress_threads, bool enable_mpi_threads) { int num_local_procs = 0; mca_btl_base_module_t **btls = NULL; @@ -837,9 +816,9 @@ mca_btl_smcuda_component_init(int *num_btls, /* if no session directory was created, then we cannot be used */ if (NULL == opal_process_info.job_session_dir) { - /* SKG - this isn't true anymore. Some backing facilities don't require a - * file-backed store. Extend shmem to provide this info one day. Especially - * when we use a proper modex for init. */ + /* SKG - this isn't true anymore. Some backing facilities don't require a + * file-backed store. Extend shmem to provide this info one day. Especially + * when we use a proper modex for init. */ return NULL; } /* if we don't have locality information, then we cannot be used because we @@ -848,8 +827,7 @@ mca_btl_smcuda_component_init(int *num_btls, * the spawn case we need to designate a metadata creator rank within the * set of processes that are initializing the btl, and my_local_rank seems * to provide that for us. */ - if (UINT32_MAX == - (my_local_rank = opal_process_info.my_local_rank)) { + if (UINT32_MAX == (my_local_rank = opal_process_info.my_local_rank)) { opal_show_help("help-mpi-btl-smcuda.txt", "no locality", true); return NULL; } @@ -872,58 +850,55 @@ mca_btl_smcuda_component_init(int *num_btls, * 0 create a rendezvous file containing the backing store info, so the * other local procs can read from it during add_procs. The rest will just * stash the known paths for use later in init. */ - if (OPAL_SUCCESS != backing_store_init(&mca_btl_smcuda_component, - my_local_rank)) { + if (OPAL_SUCCESS != backing_store_init(&mca_btl_smcuda_component, my_local_rank)) { return NULL; } #if OPAL_ENABLE_PROGRESS_THREADS == 1 /* create a named pipe to receive events */ - sprintf( mca_btl_smcuda_component.sm_fifo_path, - "%s"OPAL_PATH_SEP"sm_fifo.%lu", opal_process_info.job_session_dir, - (unsigned long)OPAL_PROC_MY_NAME->vpid ); - if(mkfifo(mca_btl_smcuda_component.sm_fifo_path, 0660) < 0) { - opal_output(0, "mca_btl_smcuda_component_init: mkfifo failed with errno=%d\n",errno); + sprintf(mca_btl_smcuda_component.sm_fifo_path, "%s" OPAL_PATH_SEP "sm_fifo.%lu", + opal_process_info.job_session_dir, (unsigned long) OPAL_PROC_MY_NAME->vpid); + if (mkfifo(mca_btl_smcuda_component.sm_fifo_path, 0660) < 0) { + opal_output(0, "mca_btl_smcuda_component_init: mkfifo failed with errno=%d\n", errno); return NULL; } - mca_btl_smcuda_component.sm_fifo_fd = open(mca_btl_smcuda_component.sm_fifo_path, - O_RDWR); - if(mca_btl_smcuda_component.sm_fifo_fd < 0) { - opal_output(0, "mca_btl_smcuda_component_init: " - "open(%s) failed with errno=%d\n", + mca_btl_smcuda_component.sm_fifo_fd = open(mca_btl_smcuda_component.sm_fifo_path, O_RDWR); + if (mca_btl_smcuda_component.sm_fifo_fd < 0) { + opal_output(0, + "mca_btl_smcuda_component_init: " + "open(%s) failed with errno=%d\n", mca_btl_smcuda_component.sm_fifo_path, errno); return NULL; } OBJ_CONSTRUCT(&mca_btl_smcuda_component.sm_fifo_thread, opal_thread_t); - mca_btl_smcuda_component.sm_fifo_thread.t_run = - (opal_thread_fn_t)mca_btl_smcuda_component_event_thread; + mca_btl_smcuda_component.sm_fifo_thread.t_run = (opal_thread_fn_t) + mca_btl_smcuda_component_event_thread; opal_thread_start(&mca_btl_smcuda_component.sm_fifo_thread); #endif - mca_btl_smcuda_component.sm_btls = - (mca_btl_smcuda_t **)malloc(mca_btl_smcuda_component.sm_max_btls * - sizeof(mca_btl_smcuda_t *)); + mca_btl_smcuda_component.sm_btls = (mca_btl_smcuda_t **) malloc( + mca_btl_smcuda_component.sm_max_btls * sizeof(mca_btl_smcuda_t *)); if (NULL == mca_btl_smcuda_component.sm_btls) { return NULL; } /* allocate the Shared Memory BTL */ *num_btls = 1; - btls = (mca_btl_base_module_t**)malloc(sizeof(mca_btl_base_module_t*)); + btls = (mca_btl_base_module_t **) malloc(sizeof(mca_btl_base_module_t *)); if (NULL == btls) { return NULL; } /* get pointer to the btls */ - btls[0] = (mca_btl_base_module_t*)(&(mca_btl_smcuda)); - mca_btl_smcuda_component.sm_btls[0] = (mca_btl_smcuda_t*)(&(mca_btl_smcuda)); + btls[0] = (mca_btl_base_module_t *) (&(mca_btl_smcuda)); + mca_btl_smcuda_component.sm_btls[0] = (mca_btl_smcuda_t *) (&(mca_btl_smcuda)); /* initialize some BTL data */ /* start with no SM procs */ mca_btl_smcuda_component.num_smp_procs = 0; - mca_btl_smcuda_component.my_smp_rank = -1; /* not defined */ - mca_btl_smcuda_component.sm_num_btls = 1; + mca_btl_smcuda_component.my_smp_rank = -1; /* not defined */ + mca_btl_smcuda_component.sm_num_btls = 1; /* set flag indicating btl not inited */ mca_btl_smcuda.btl_inited = false; @@ -936,24 +911,22 @@ mca_btl_smcuda_component_init(int *num_btls, #endif /* OPAL_CUDA_SUPPORT */ return btls; - } - /* * SM component progress. */ #if OPAL_ENABLE_PROGRESS_THREADS == 1 -void mca_btl_smcuda_component_event_thread(opal_object_t* thread) +void mca_btl_smcuda_component_event_thread(opal_object_t *thread) { - while(1) { + while (1) { unsigned char cmd; - if(read(mca_btl_smcuda_component.sm_fifo_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { + if (read(mca_btl_smcuda_component.sm_fifo_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { /* error condition */ return; } - if( DONE == cmd ){ + if (DONE == cmd) { /* return when done message received */ return; } @@ -967,25 +940,27 @@ void btl_smcuda_process_pending_sends(struct mca_btl_base_endpoint_t *ep) btl_smcuda_pending_send_item_t *si; int rc; - while ( 0 < opal_list_get_size(&ep->pending_sends) ) { + while (0 < opal_list_get_size(&ep->pending_sends)) { /* Note that we access the size of ep->pending_sends unlocked as it doesn't really matter if the result is wrong as opal_list_remove_first is called with a lock and we handle it not finding an item to process */ OPAL_THREAD_LOCK(&ep->endpoint_lock); - si = (btl_smcuda_pending_send_item_t*)opal_list_remove_first(&ep->pending_sends); + si = (btl_smcuda_pending_send_item_t *) opal_list_remove_first(&ep->pending_sends); OPAL_THREAD_UNLOCK(&ep->endpoint_lock); - if(NULL == si) return; /* Another thread got in before us. Thats ok. */ + if (NULL == si) + return; /* Another thread got in before us. Thats ok. */ OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_pending_sends, -1); - MCA_BTL_SMCUDA_FIFO_WRITE(ep, ep->my_smp_rank, ep->peer_smp_rank, si->data, - true, false, rc); + MCA_BTL_SMCUDA_FIFO_WRITE(ep, ep->my_smp_rank, ep->peer_smp_rank, si->data, true, false, + rc); - opal_free_list_return (&mca_btl_smcuda_component.pending_send_fl, (opal_free_list_item_t*)si); + opal_free_list_return(&mca_btl_smcuda_component.pending_send_fl, + (opal_free_list_item_t *) si); - if ( OPAL_SUCCESS != rc ) + if (OPAL_SUCCESS != rc) return; } } @@ -1002,98 +977,98 @@ int mca_btl_smcuda_component_progress(void) /* first, deal with any pending sends */ /* This check should be fast since we only need to check one variable. */ - if ( 0 < mca_btl_smcuda_component.num_pending_sends ) { + if (0 < mca_btl_smcuda_component.num_pending_sends) { /* perform a loop to find the endpoints that have pending sends */ /* This can take a while longer if there are many endpoints to check. */ - for ( peer_smp_rank = 0; peer_smp_rank < mca_btl_smcuda_component.num_smp_procs; peer_smp_rank++) { - struct mca_btl_base_endpoint_t* endpoint; - if ( peer_smp_rank == my_smp_rank ) + for (peer_smp_rank = 0; peer_smp_rank < mca_btl_smcuda_component.num_smp_procs; + peer_smp_rank++) { + struct mca_btl_base_endpoint_t *endpoint; + if (peer_smp_rank == my_smp_rank) continue; endpoint = mca_btl_smcuda_component.sm_peers[peer_smp_rank]; - if ( 0 < opal_list_get_size(&endpoint->pending_sends) ) + if (0 < opal_list_get_size(&endpoint->pending_sends)) btl_smcuda_process_pending_sends(endpoint); } } /* poll each fifo */ - for(j = 0; j < FIFO_MAP_NUM(mca_btl_smcuda_component.num_smp_procs); j++) { + for (j = 0; j < FIFO_MAP_NUM(mca_btl_smcuda_component.num_smp_procs); j++) { fifo = &(mca_btl_smcuda_component.fifo[my_smp_rank][j]); - recheck_peer: + recheck_peer: /* aquire thread lock */ - if(opal_using_threads()) { + if (opal_using_threads()) { opal_atomic_lock(&(fifo->tail_lock)); } - hdr = (mca_btl_smcuda_hdr_t *)sm_fifo_read(fifo); + hdr = (mca_btl_smcuda_hdr_t *) sm_fifo_read(fifo); /* release thread lock */ - if(opal_using_threads()) { + if (opal_using_threads()) { opal_atomic_unlock(&(fifo->tail_lock)); } - if(SM_FIFO_FREE == hdr) { + if (SM_FIFO_FREE == hdr) { continue; } nevents++; /* dispatch fragment by type */ - switch(((uintptr_t)hdr) & MCA_BTL_SMCUDA_FRAG_TYPE_MASK) { - case MCA_BTL_SMCUDA_FRAG_SEND: - { - /* change the address from address relative to the shared - * memory address, to a true virtual address */ - hdr = (mca_btl_smcuda_hdr_t *) RELATIVE2VIRTUAL(hdr); - peer_smp_rank = hdr->my_smp_rank; + switch (((uintptr_t) hdr) & MCA_BTL_SMCUDA_FRAG_TYPE_MASK) { + case MCA_BTL_SMCUDA_FRAG_SEND: { + /* change the address from address relative to the shared + * memory address, to a true virtual address */ + hdr = (mca_btl_smcuda_hdr_t *) RELATIVE2VIRTUAL(hdr); + peer_smp_rank = hdr->my_smp_rank; #if OPAL_ENABLE_DEBUG - if ( FIFO_MAP(peer_smp_rank) != j ) { - opal_output(0, "mca_btl_smcuda_component_progress: " - "rank %d got %d on FIFO %d, but this sender should send to FIFO %d\n", - my_smp_rank, peer_smp_rank, j, FIFO_MAP(peer_smp_rank)); - } + if (FIFO_MAP(peer_smp_rank) != j) { + opal_output(0, + "mca_btl_smcuda_component_progress: " + "rank %d got %d on FIFO %d, but this sender should send to FIFO %d\n", + my_smp_rank, peer_smp_rank, j, FIFO_MAP(peer_smp_rank)); + } #endif - seg.seg_addr.pval = ((char *)hdr) + sizeof(mca_btl_smcuda_hdr_t); - seg.seg_len = hdr->len; - - mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + hdr->tag; - mca_btl_base_receive_descriptor_t recv_desc = {.endpoint = mca_btl_smcuda_component.sm_peers[peer_smp_rank], - .des_segments = &seg, - .des_segment_count = 1, - .tag = hdr->tag, - .cbdata = reg->cbdata}; - reg->cbfunc(&mca_btl_smcuda.super, &recv_desc); - /* return the fragment */ - MCA_BTL_SMCUDA_FIFO_WRITE( - mca_btl_smcuda_component.sm_peers[peer_smp_rank], - my_smp_rank, peer_smp_rank, hdr->frag, false, true, rc); - break; + seg.seg_addr.pval = ((char *) hdr) + sizeof(mca_btl_smcuda_hdr_t); + seg.seg_len = hdr->len; + + mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + hdr->tag; + mca_btl_base_receive_descriptor_t recv_desc = {.endpoint = mca_btl_smcuda_component + .sm_peers[peer_smp_rank], + .des_segments = &seg, + .des_segment_count = 1, + .tag = hdr->tag, + .cbdata = reg->cbdata}; + reg->cbfunc(&mca_btl_smcuda.super, &recv_desc); + /* return the fragment */ + MCA_BTL_SMCUDA_FIFO_WRITE(mca_btl_smcuda_component.sm_peers[peer_smp_rank], my_smp_rank, + peer_smp_rank, hdr->frag, false, true, rc); + break; + } + case MCA_BTL_SMCUDA_FRAG_ACK: { + int status = (uintptr_t) hdr & MCA_BTL_SMCUDA_FRAG_STATUS_MASK; + int btl_ownership; + struct mca_btl_base_endpoint_t *endpoint; + + frag = (mca_btl_smcuda_frag_t *) (( + char *) ((uintptr_t) hdr + & (~(MCA_BTL_SMCUDA_FRAG_TYPE_MASK | MCA_BTL_SMCUDA_FRAG_STATUS_MASK)))); + + endpoint = frag->endpoint; + btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); + if (MCA_BTL_DES_SEND_ALWAYS_CALLBACK & frag->base.des_flags) { + /* completion callback */ + frag->base.des_cbfunc(&mca_btl_smcuda.super, frag->endpoint, &frag->base, + status ? OPAL_ERROR : OPAL_SUCCESS); } - case MCA_BTL_SMCUDA_FRAG_ACK: - { - int status = (uintptr_t)hdr & MCA_BTL_SMCUDA_FRAG_STATUS_MASK; - int btl_ownership; - struct mca_btl_base_endpoint_t* endpoint; - - frag = (mca_btl_smcuda_frag_t *)((char*)((uintptr_t)hdr & - (~(MCA_BTL_SMCUDA_FRAG_TYPE_MASK | - MCA_BTL_SMCUDA_FRAG_STATUS_MASK)))); - - endpoint = frag->endpoint; - btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); - if( MCA_BTL_DES_SEND_ALWAYS_CALLBACK & frag->base.des_flags ) { - /* completion callback */ - frag->base.des_cbfunc(&mca_btl_smcuda.super, frag->endpoint, - &frag->base, status?OPAL_ERROR:OPAL_SUCCESS); - } - if( btl_ownership ) { - MCA_BTL_SMCUDA_FRAG_RETURN(frag); - } - OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_outstanding_frags, -1); - if ( 0 < opal_list_get_size(&endpoint->pending_sends) ) { - btl_smcuda_process_pending_sends(endpoint); - } - goto recheck_peer; + if (btl_ownership) { + MCA_BTL_SMCUDA_FRAG_RETURN(frag); + } + OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_outstanding_frags, -1); + if (0 < opal_list_get_size(&endpoint->pending_sends)) { + btl_smcuda_process_pending_sends(endpoint); } + goto recheck_peer; + } default: /* unknown */ /* @@ -1109,30 +1084,30 @@ int mca_btl_smcuda_component_progress(void) opal_output(0, "mca_btl_smcuda_component_progress read an unknown type of header"); hdr = (mca_btl_smcuda_hdr_t *) RELATIVE2VIRTUAL(hdr); peer_smp_rank = hdr->my_smp_rank; - hdr = (mca_btl_smcuda_hdr_t*)((uintptr_t)hdr->frag | - MCA_BTL_SMCUDA_FRAG_STATUS_MASK); - MCA_BTL_SMCUDA_FIFO_WRITE( - mca_btl_smcuda_component.sm_peers[peer_smp_rank], - my_smp_rank, peer_smp_rank, hdr, false, true, rc); + hdr = (mca_btl_smcuda_hdr_t *) ((uintptr_t) hdr->frag + | MCA_BTL_SMCUDA_FRAG_STATUS_MASK); + MCA_BTL_SMCUDA_FIFO_WRITE(mca_btl_smcuda_component.sm_peers[peer_smp_rank], my_smp_rank, + peer_smp_rank, hdr, false, true, rc); break; } } - (void)rc; /* this is safe to ignore as the message is requeued till success */ + (void) rc; /* this is safe to ignore as the message is requeued till success */ #if OPAL_CUDA_SUPPORT /* Check to see if there are any outstanding CUDA events that have * completed. If so, issue the PML callbacks on the fragments. */ - while (1 == progress_one_cuda_ipc_event((mca_btl_base_descriptor_t **)&frag)) { - mca_btl_base_rdma_completion_fn_t cbfunc = (mca_btl_base_rdma_completion_fn_t) frag->base.des_cbfunc; + while (1 == progress_one_cuda_ipc_event((mca_btl_base_descriptor_t **) &frag)) { + mca_btl_base_rdma_completion_fn_t cbfunc = (mca_btl_base_rdma_completion_fn_t) + frag->base.des_cbfunc; - cbfunc (&mca_btl_smcuda.super, frag->endpoint, frag->segment.seg_addr.pval, - frag->local_handle, frag->base.des_context, frag->base.des_cbdata, - OPAL_SUCCESS); + cbfunc(&mca_btl_smcuda.super, frag->endpoint, frag->segment.seg_addr.pval, + frag->local_handle, frag->base.des_context, frag->base.des_cbdata, OPAL_SUCCESS); - if(frag->registration != NULL) { - frag->endpoint->rcache->rcache_deregister (frag->endpoint->rcache, - (mca_rcache_base_registration_t*)frag->registration); + if (frag->registration != NULL) { + frag->endpoint->rcache->rcache_deregister(frag->endpoint->rcache, + (mca_rcache_base_registration_t *) + frag->registration); frag->registration = NULL; MCA_BTL_SMCUDA_FRAG_RETURN(frag); } diff --git a/opal/mca/btl/smcuda/btl_smcuda_endpoint.h b/opal/mca/btl/smcuda/btl_smcuda_endpoint.h index 1dfb359e17f..cf2c77aadb7 100644 --- a/opal/mca/btl/smcuda/btl_smcuda_endpoint.h +++ b/opal/mca/btl/smcuda/btl_smcuda_endpoint.h @@ -33,15 +33,15 @@ */ struct mca_btl_base_endpoint_t { - int my_smp_rank; /**< My SMP process rank. Used for accessing - * SMP specfic data structures. */ - int peer_smp_rank; /**< My peer's SMP process rank. Used for accessing - * SMP specfic data structures. */ + int my_smp_rank; /**< My SMP process rank. Used for accessing + * SMP specfic data structures. */ + int peer_smp_rank; /**< My peer's SMP process rank. Used for accessing + * SMP specfic data structures. */ #if OPAL_CUDA_SUPPORT mca_rcache_base_module_t *rcache; /**< rcache for remotely registered memory */ -#endif /* OPAL_CUDA_SUPPORT */ +#endif /* OPAL_CUDA_SUPPORT */ #if OPAL_ENABLE_PROGRESS_THREADS == 1 - int fifo_fd; /**< pipe/fifo used to signal endpoint that data is queued */ + int fifo_fd; /**< pipe/fifo used to signal endpoint that data is queued */ #endif opal_list_t pending_sends; /**< pending data to send */ @@ -49,10 +49,10 @@ struct mca_btl_base_endpoint_t { opal_mutex_t endpoint_lock; #if OPAL_CUDA_SUPPORT - opal_proc_t *proc_opal; /**< Needed for adding CUDA IPC support dynamically */ - enum ipcState ipcstate; /**< CUDA IPC connection status */ - int ipctries; /**< Number of times CUDA IPC connect was sent */ -#endif /* OPAL_CUDA_SUPPORT */ + opal_proc_t *proc_opal; /**< Needed for adding CUDA IPC support dynamically */ + enum ipcState ipcstate; /**< CUDA IPC connection status */ + int ipctries; /**< Number of times CUDA IPC connect was sent */ +#endif /* OPAL_CUDA_SUPPORT */ }; void btl_smcuda_process_pending_sends(struct mca_btl_base_endpoint_t *ep); diff --git a/opal/mca/btl/smcuda/btl_smcuda_fifo.h b/opal/mca/btl/smcuda/btl_smcuda_fifo.h index c4db00d10a8..ca1257b5c56 100644 --- a/opal/mca/btl/smcuda/btl_smcuda_fifo.h +++ b/opal/mca/btl/smcuda/btl_smcuda_fifo.h @@ -27,17 +27,16 @@ #include "btl_smcuda.h" #include "btl_smcuda_endpoint.h" -static void -add_pending(struct mca_btl_base_endpoint_t *ep, void *data, bool resend) +static void add_pending(struct mca_btl_base_endpoint_t *ep, void *data, bool resend) { btl_smcuda_pending_send_item_t *si; opal_free_list_item_t *i; - i = opal_free_list_get (&mca_btl_smcuda_component.pending_send_fl); + i = opal_free_list_get(&mca_btl_smcuda_component.pending_send_fl); /* don't handle error for now */ assert(i != NULL); - si = (btl_smcuda_pending_send_item_t*)i; + si = (btl_smcuda_pending_send_item_t *) i; si->data = data; OPAL_THREAD_ADD_FETCH32(&mca_btl_smcuda_component.num_pending_sends, +1); @@ -46,9 +45,9 @@ add_pending(struct mca_btl_base_endpoint_t *ep, void *data, bool resend) * minimize reordering */ OPAL_THREAD_LOCK(&ep->endpoint_lock); if (resend) - opal_list_prepend(&ep->pending_sends, (opal_list_item_t*)si); + opal_list_prepend(&ep->pending_sends, (opal_list_item_t *) si); else - opal_list_append(&ep->pending_sends, (opal_list_item_t*)si); + opal_list_append(&ep->pending_sends, (opal_list_item_t *) si); OPAL_THREAD_UNLOCK(&ep->endpoint_lock); } @@ -79,31 +78,31 @@ add_pending(struct mca_btl_base_endpoint_t *ep, void *data, bool resend) * nfifos == 1: In this case, all senders use the same * FIFO and each receiver has just one FIFO for all senders. */ -#define FIFO_MAP(x) ((x) & (mca_btl_smcuda_component.nfifos - 1)) -#define FIFO_MAP_NUM(n) ( (mca_btl_smcuda_component.nfifos) < (n) ? (mca_btl_smcuda_component.nfifos) : (n) ) +#define FIFO_MAP(x) ((x) & (mca_btl_smcuda_component.nfifos - 1)) +#define FIFO_MAP_NUM(n) \ + ((mca_btl_smcuda_component.nfifos) < (n) ? (mca_btl_smcuda_component.nfifos) : (n)) - -#define MCA_BTL_SMCUDA_FIFO_WRITE(endpoint_peer, my_smp_rank, \ - peer_smp_rank, hdr, resend, retry_pending_sends, rc) \ -do { \ - sm_fifo_t* fifo = &(mca_btl_smcuda_component.fifo[peer_smp_rank][FIFO_MAP(my_smp_rank)]); \ - \ - if ( retry_pending_sends ) { \ - if ( 0 < opal_list_get_size(&endpoint_peer->pending_sends) ) { \ - btl_smcuda_process_pending_sends(endpoint_peer); \ - } \ - } \ - \ - opal_atomic_lock(&(fifo->head_lock)); \ - /* post fragment */ \ - if(sm_fifo_write(hdr, fifo) != OPAL_SUCCESS) { \ - add_pending(endpoint_peer, hdr, resend); \ - rc = OPAL_ERR_RESOURCE_BUSY; \ - } else { \ - MCA_BTL_SMCUDA_SIGNAL_PEER(endpoint_peer); \ - rc = OPAL_SUCCESS; \ - } \ - opal_atomic_unlock(&(fifo->head_lock)); \ -} while(0) +#define MCA_BTL_SMCUDA_FIFO_WRITE(endpoint_peer, my_smp_rank, peer_smp_rank, hdr, resend, \ + retry_pending_sends, rc) \ + do { \ + sm_fifo_t *fifo = &(mca_btl_smcuda_component.fifo[peer_smp_rank][FIFO_MAP(my_smp_rank)]); \ + \ + if (retry_pending_sends) { \ + if (0 < opal_list_get_size(&endpoint_peer->pending_sends)) { \ + btl_smcuda_process_pending_sends(endpoint_peer); \ + } \ + } \ + \ + opal_atomic_lock(&(fifo->head_lock)); \ + /* post fragment */ \ + if (sm_fifo_write(hdr, fifo) != OPAL_SUCCESS) { \ + add_pending(endpoint_peer, hdr, resend); \ + rc = OPAL_ERR_RESOURCE_BUSY; \ + } else { \ + MCA_BTL_SMCUDA_SIGNAL_PEER(endpoint_peer); \ + rc = OPAL_SUCCESS; \ + } \ + opal_atomic_unlock(&(fifo->head_lock)); \ + } while (0) #endif diff --git a/opal/mca/btl/smcuda/btl_smcuda_frag.c b/opal/mca/btl/smcuda/btl_smcuda_frag.c index 3f28e7cdbaf..e4583e95e11 100644 --- a/opal/mca/btl/smcuda/btl_smcuda_frag.c +++ b/opal/mca/btl/smcuda/btl_smcuda_frag.c @@ -23,15 +23,12 @@ #include "opal_config.h" #include "btl_smcuda_frag.h" - -static inline void mca_btl_smcuda_frag_common_constructor(mca_btl_smcuda_frag_t* frag) +static inline void mca_btl_smcuda_frag_common_constructor(mca_btl_smcuda_frag_t *frag) { - frag->hdr = (mca_btl_smcuda_hdr_t*)frag->base.super.ptr; - if(frag->hdr != NULL) { - frag->hdr->frag = (mca_btl_smcuda_frag_t*)((uintptr_t)frag | - MCA_BTL_SMCUDA_FRAG_ACK); - frag->segment.seg_addr.pval = ((char*)frag->hdr) + - sizeof(mca_btl_smcuda_hdr_t); + frag->hdr = (mca_btl_smcuda_hdr_t *) frag->base.super.ptr; + if (frag->hdr != NULL) { + frag->hdr->frag = (mca_btl_smcuda_frag_t *) ((uintptr_t) frag | MCA_BTL_SMCUDA_FRAG_ACK); + frag->segment.seg_addr.pval = ((char *) frag->hdr) + sizeof(mca_btl_smcuda_hdr_t); frag->hdr->my_smp_rank = mca_btl_smcuda_component.my_smp_rank; } frag->segment.seg_len = frag->size; @@ -43,41 +40,32 @@ static inline void mca_btl_smcuda_frag_common_constructor(mca_btl_smcuda_frag_t* #endif /* OPAL_CUDA_SUPPORT */ } -static void mca_btl_smcuda_frag1_constructor(mca_btl_smcuda_frag_t* frag) +static void mca_btl_smcuda_frag1_constructor(mca_btl_smcuda_frag_t *frag) { frag->size = mca_btl_smcuda_component.eager_limit; frag->my_list = &mca_btl_smcuda_component.sm_frags_eager; mca_btl_smcuda_frag_common_constructor(frag); } -static void mca_btl_smcuda_frag2_constructor(mca_btl_smcuda_frag_t* frag) +static void mca_btl_smcuda_frag2_constructor(mca_btl_smcuda_frag_t *frag) { frag->size = mca_btl_smcuda_component.max_frag_size; frag->my_list = &mca_btl_smcuda_component.sm_frags_max; mca_btl_smcuda_frag_common_constructor(frag); } -static void mca_btl_smcuda_user_constructor(mca_btl_smcuda_frag_t* frag) +static void mca_btl_smcuda_user_constructor(mca_btl_smcuda_frag_t *frag) { - frag->size = 0; - frag->my_list = &mca_btl_smcuda_component.sm_frags_user; - mca_btl_smcuda_frag_common_constructor(frag); + frag->size = 0; + frag->my_list = &mca_btl_smcuda_component.sm_frags_user; + mca_btl_smcuda_frag_common_constructor(frag); } -OBJ_CLASS_INSTANCE( - mca_btl_smcuda_frag1_t, - mca_btl_base_descriptor_t, - mca_btl_smcuda_frag1_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_smcuda_frag1_t, mca_btl_base_descriptor_t, + mca_btl_smcuda_frag1_constructor, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_smcuda_frag2_t, - mca_btl_base_descriptor_t, - mca_btl_smcuda_frag2_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_smcuda_frag2_t, mca_btl_base_descriptor_t, + mca_btl_smcuda_frag2_constructor, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_smcuda_user_t, - mca_btl_base_descriptor_t, - mca_btl_smcuda_user_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_smcuda_user_t, mca_btl_base_descriptor_t, + mca_btl_smcuda_user_constructor, NULL); diff --git a/opal/mca/btl/smcuda/btl_smcuda_frag.h b/opal/mca/btl/smcuda/btl_smcuda_frag.h index 78cc9c39012..7f367c85bf7 100644 --- a/opal/mca/btl/smcuda/btl_smcuda_frag.h +++ b/opal/mca/btl/smcuda/btl_smcuda_frag.h @@ -31,16 +31,16 @@ #include "btl_smcuda.h" #if OPAL_CUDA_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" +# include "opal/mca/common/cuda/common_cuda.h" #endif -#define MCA_BTL_SMCUDA_FRAG_TYPE_MASK ((uintptr_t)0x3) -#define MCA_BTL_SMCUDA_FRAG_SEND ((uintptr_t)0x0) -#define MCA_BTL_SMCUDA_FRAG_ACK ((uintptr_t)0x1) -#define MCA_BTL_SMCUDA_FRAG_PUT ((uintptr_t)0x2) -#define MCA_BTL_SMCUDA_FRAG_GET ((uintptr_t)0x3) +#define MCA_BTL_SMCUDA_FRAG_TYPE_MASK ((uintptr_t) 0x3) +#define MCA_BTL_SMCUDA_FRAG_SEND ((uintptr_t) 0x0) +#define MCA_BTL_SMCUDA_FRAG_ACK ((uintptr_t) 0x1) +#define MCA_BTL_SMCUDA_FRAG_PUT ((uintptr_t) 0x2) +#define MCA_BTL_SMCUDA_FRAG_GET ((uintptr_t) 0x3) -#define MCA_BTL_SMCUDA_FRAG_STATUS_MASK ((uintptr_t)0x4) +#define MCA_BTL_SMCUDA_FRAG_STATUS_MASK ((uintptr_t) 0x4) struct mca_btl_smcuda_frag_t; @@ -64,7 +64,7 @@ struct mca_btl_smcuda_segment_t { uint8_t key[128]; /* 64 bytes for CUDA mem handle, 64 bytes for CUDA event handle */ /** Address of the entire memory handle */ opal_ptr_t memh_seg_addr; - /** Length in bytes of entire memory handle */ + /** Length in bytes of entire memory handle */ uint32_t memh_seg_len; #endif /* OPAL_CUDA_SUPPORT */ }; @@ -84,39 +84,38 @@ struct mca_btl_smcuda_frag_t { size_t size; /* pointer written to the FIFO, this is the base of the shared memory region */ mca_btl_smcuda_hdr_t *hdr; - opal_free_list_t* my_list; + opal_free_list_t *my_list; }; typedef struct mca_btl_smcuda_frag_t mca_btl_smcuda_frag_t; typedef struct mca_btl_smcuda_frag_t mca_btl_smcuda_frag1_t; typedef struct mca_btl_smcuda_frag_t mca_btl_smcuda_frag2_t; typedef struct mca_btl_smcuda_frag_t mca_btl_smcuda_user_t; - OBJ_CLASS_DECLARATION(mca_btl_smcuda_frag_t); OBJ_CLASS_DECLARATION(mca_btl_smcuda_frag1_t); OBJ_CLASS_DECLARATION(mca_btl_smcuda_frag2_t); OBJ_CLASS_DECLARATION(mca_btl_smcuda_user_t); -#define MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag) \ -{ \ - frag = (mca_btl_smcuda_frag_t *) \ - opal_free_list_get (&mca_btl_smcuda_component.sm_frags_eager); \ -} +#define MCA_BTL_SMCUDA_FRAG_ALLOC_EAGER(frag) \ + { \ + frag = (mca_btl_smcuda_frag_t *) opal_free_list_get( \ + &mca_btl_smcuda_component.sm_frags_eager); \ + } -#define MCA_BTL_SMCUDA_FRAG_ALLOC_MAX(frag) \ -{ \ - frag = (mca_btl_smcuda_frag_t *) \ - opal_free_list_get (&mca_btl_smcuda_component.sm_frags_max); \ -} +#define MCA_BTL_SMCUDA_FRAG_ALLOC_MAX(frag) \ + { \ + frag = (mca_btl_smcuda_frag_t *) opal_free_list_get( \ + &mca_btl_smcuda_component.sm_frags_max); \ + } -#define MCA_BTL_SMCUDA_FRAG_ALLOC_USER(frag) \ -{ \ - frag = (mca_btl_smcuda_frag_t *) \ - opal_free_list_get (&mca_btl_smcuda_component.sm_frags_user); \ -} +#define MCA_BTL_SMCUDA_FRAG_ALLOC_USER(frag) \ + { \ + frag = (mca_btl_smcuda_frag_t *) opal_free_list_get( \ + &mca_btl_smcuda_component.sm_frags_user); \ + } -#define MCA_BTL_SMCUDA_FRAG_RETURN(frag) \ -{ \ - opal_free_list_return (frag->my_list, (opal_free_list_item_t*)(frag)); \ -} +#define MCA_BTL_SMCUDA_FRAG_RETURN(frag) \ + { \ + opal_free_list_return(frag->my_list, (opal_free_list_item_t *) (frag)); \ + } #endif diff --git a/opal/mca/btl/tcp/btl_tcp.c b/opal/mca/btl/tcp/btl_tcp.c index d800c563f47..4fe37f566bb 100644 --- a/opal/mca/btl/tcp/btl_tcp.c +++ b/opal/mca/btl/tcp/btl_tcp.c @@ -26,44 +26,44 @@ */ #include "opal_config.h" -#include #include "opal/class/opal_bitmap.h" -#include "opal/mca/btl/btl.h" #include "opal/datatype/opal_convertor.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" #include "opal/mca/mpool/mpool.h" -#include "opal/mca/btl/base/btl_base_error.h" #include "opal/opal_socket_errno.h" +#include #include "btl_tcp.h" +#include "btl_tcp_endpoint.h" #include "btl_tcp_frag.h" #include "btl_tcp_proc.h" -#include "btl_tcp_endpoint.h" -static int mca_btl_tcp_register_error_cb(struct mca_btl_base_module_t* btl, +static int mca_btl_tcp_register_error_cb(struct mca_btl_base_module_t *btl, mca_btl_base_module_error_cb_fn_t cbfunc); -mca_btl_tcp_module_t mca_btl_tcp_module = { - .super = { - .btl_component = &mca_btl_tcp_component.super, - .btl_add_procs = mca_btl_tcp_add_procs, - .btl_del_procs = mca_btl_tcp_del_procs, - .btl_finalize = mca_btl_tcp_finalize, - .btl_alloc = mca_btl_tcp_alloc, - .btl_free = mca_btl_tcp_free, - .btl_prepare_src = mca_btl_tcp_prepare_src, - .btl_send = mca_btl_tcp_send, - .btl_put = mca_btl_tcp_put, - .btl_dump = mca_btl_base_dump, - .btl_register_error = mca_btl_tcp_register_error_cb, /* register error */ - }, - .tcp_endpoints_mutex = OPAL_MUTEX_STATIC_INIT -}; - -static int mca_btl_tcp_register_error_cb(struct mca_btl_base_module_t* btl, +mca_btl_tcp_module_t mca_btl_tcp_module = + {.super = + { + .btl_component = &mca_btl_tcp_component.super, + .btl_add_procs = mca_btl_tcp_add_procs, + .btl_del_procs = mca_btl_tcp_del_procs, + .btl_finalize = mca_btl_tcp_finalize, + .btl_alloc = mca_btl_tcp_alloc, + .btl_free = mca_btl_tcp_free, + .btl_prepare_src = mca_btl_tcp_prepare_src, + .btl_send = mca_btl_tcp_send, + .btl_put = mca_btl_tcp_put, + .btl_dump = mca_btl_base_dump, + .btl_register_error = mca_btl_tcp_register_error_cb, /* register error */ + }, + .tcp_endpoints_mutex = OPAL_MUTEX_STATIC_INIT}; + +static int mca_btl_tcp_register_error_cb(struct mca_btl_base_module_t *btl, mca_btl_base_module_error_cb_fn_t cbfunc) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*)btl; + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; tcp_btl->tcp_error_cb = cbfunc; return OPAL_SUCCESS; } @@ -72,39 +72,38 @@ static int mca_btl_tcp_register_error_cb(struct mca_btl_base_module_t* btl, * */ -int mca_btl_tcp_add_procs( struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers, - opal_bitmap_t* reachable ) +int mca_btl_tcp_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*)btl; - const opal_proc_t* my_proc; /* pointer to caller's proc structure */ + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; + const opal_proc_t *my_proc; /* pointer to caller's proc structure */ int i, rc; /* get pointer to my proc structure */ - if( NULL == (my_proc = opal_proc_local_get()) ) + if (NULL == (my_proc = opal_proc_local_get())) { return OPAL_ERR_OUT_OF_RESOURCE; + } - for(i = 0; i < (int) nprocs; i++) { + for (i = 0; i < (int) nprocs; i++) { - struct opal_proc_t* opal_proc = procs[i]; - mca_btl_tcp_proc_t* tcp_proc; - mca_btl_base_endpoint_t* tcp_endpoint; + struct opal_proc_t *opal_proc = procs[i]; + mca_btl_tcp_proc_t *tcp_proc; + mca_btl_base_endpoint_t *tcp_endpoint; bool existing_found = false; /* Do not create loopback TCP connections */ - if( my_proc == opal_proc ) { + if (my_proc == opal_proc) { continue; } - if(NULL == (tcp_proc = mca_btl_tcp_proc_create(opal_proc))) { + if (NULL == (tcp_proc = mca_btl_tcp_proc_create(opal_proc))) { continue; } OPAL_THREAD_LOCK(&tcp_proc->proc_lock); - for (uint32_t j = 0 ; j < (uint32_t)tcp_proc->proc_endpoint_count ; ++j) { + for (uint32_t j = 0; j < (uint32_t) tcp_proc->proc_endpoint_count; ++j) { tcp_endpoint = tcp_proc->proc_endpoints[j]; if (tcp_endpoint->endpoint_btl == tcp_btl) { existing_found = true; @@ -118,21 +117,21 @@ int mca_btl_tcp_add_procs( struct mca_btl_base_module_t* btl, * Cache the peer instance on the btl_proc. */ tcp_endpoint = OBJ_NEW(mca_btl_tcp_endpoint_t); - if(NULL == tcp_endpoint) { + if (NULL == tcp_endpoint) { OPAL_THREAD_UNLOCK(&tcp_proc->proc_lock); return OPAL_ERR_OUT_OF_RESOURCE; } tcp_endpoint->endpoint_btl = tcp_btl; rc = mca_btl_tcp_proc_insert(tcp_proc, tcp_endpoint); - if(rc != OPAL_SUCCESS) { + if (rc != OPAL_SUCCESS) { OPAL_THREAD_UNLOCK(&tcp_proc->proc_lock); OBJ_RELEASE(tcp_endpoint); continue; } OPAL_THREAD_LOCK(&tcp_btl->tcp_endpoints_mutex); - opal_list_append(&tcp_btl->tcp_endpoints, (opal_list_item_t*)tcp_endpoint); + opal_list_append(&tcp_btl->tcp_endpoints, (opal_list_item_t *) tcp_endpoint); OPAL_THREAD_UNLOCK(&tcp_btl->tcp_endpoints_mutex); } @@ -148,25 +147,22 @@ int mca_btl_tcp_add_procs( struct mca_btl_base_module_t* btl, return OPAL_SUCCESS; } -int mca_btl_tcp_del_procs(struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t ** endpoints) +int mca_btl_tcp_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **endpoints) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*)btl; + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; size_t i; OPAL_THREAD_LOCK(&tcp_btl->tcp_endpoints_mutex); - for( i = 0; i < nprocs; i++ ) { - mca_btl_tcp_endpoint_t* tcp_endpoint = endpoints[i]; - opal_list_remove_item(&tcp_btl->tcp_endpoints, (opal_list_item_t*)tcp_endpoint); + for (i = 0; i < nprocs; i++) { + mca_btl_tcp_endpoint_t *tcp_endpoint = endpoints[i]; + opal_list_remove_item(&tcp_btl->tcp_endpoints, (opal_list_item_t *) tcp_endpoint); OBJ_RELEASE(tcp_endpoint); } OPAL_THREAD_UNLOCK(&tcp_btl->tcp_endpoints_mutex); return OPAL_SUCCESS; } - /** * Allocate a segment. * @@ -174,45 +170,39 @@ int mca_btl_tcp_del_procs(struct mca_btl_base_module_t* btl, * @param size (IN) Request segment size. */ -mca_btl_base_descriptor_t* mca_btl_tcp_alloc( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_tcp_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { - mca_btl_tcp_frag_t* frag = NULL; + mca_btl_tcp_frag_t *frag = NULL; - if(size <= btl->btl_eager_limit) { + if (size <= btl->btl_eager_limit) { MCA_BTL_TCP_FRAG_ALLOC_EAGER(frag); } else if (size <= btl->btl_max_send_size) { MCA_BTL_TCP_FRAG_ALLOC_MAX(frag); } - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } frag->segments[0].seg_len = size; - frag->segments[0].seg_addr.pval = frag+1; + frag->segments[0].seg_addr.pval = frag + 1; frag->base.des_segments = frag->segments; frag->base.des_segment_count = 1; frag->base.des_flags = flags; frag->base.order = MCA_BTL_NO_ORDER; - frag->btl = (mca_btl_tcp_module_t*)btl; - return (mca_btl_base_descriptor_t*)frag; + frag->btl = (mca_btl_tcp_module_t *) btl; + return (mca_btl_base_descriptor_t *) frag; } - /** * Return a segment */ -int mca_btl_tcp_free( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* des) +int mca_btl_tcp_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { - mca_btl_tcp_frag_t* frag = (mca_btl_tcp_frag_t*)des; + mca_btl_tcp_frag_t *frag = (mca_btl_tcp_frag_t *) des; MCA_BTL_TCP_FRAG_RETURN(frag); return OPAL_SUCCESS; } @@ -224,29 +214,26 @@ int mca_btl_tcp_free( * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_tcp_prepare_src(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags) { - mca_btl_tcp_frag_t* frag; + mca_btl_tcp_frag_t *frag; struct iovec iov; uint32_t iov_count = 1; size_t max_data = *size; int rc; - if( OPAL_UNLIKELY(max_data > UINT32_MAX) ) { /* limit the size to what we support */ - max_data = (size_t)UINT32_MAX; + if (OPAL_UNLIKELY(max_data > UINT32_MAX)) { /* limit the size to what we support */ + max_data = (size_t) UINT32_MAX; } /* * if we aren't pinning the data and the requested size is less * than the eager limit pack into a fragment from the eager pool */ - if (max_data+reserve <= btl->btl_eager_limit) { + if (max_data + reserve <= btl->btl_eager_limit) { MCA_BTL_TCP_FRAG_ALLOC_EAGER(frag); } else { /* @@ -255,7 +242,7 @@ mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src( */ MCA_BTL_TCP_FRAG_ALLOC_MAX(frag); } - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } @@ -263,16 +250,17 @@ mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src( frag->segments[0].seg_len = reserve; frag->base.des_segment_count = 1; - if(opal_convertor_need_buffers(convertor)) { + if (opal_convertor_need_buffers(convertor)) { if (max_data + reserve > frag->size) { max_data = frag->size - reserve; } iov.iov_len = max_data; - iov.iov_base = (IOVBASE_TYPE*)(((unsigned char*)(frag->segments[0].seg_addr.pval)) + reserve); + iov.iov_base = (IOVBASE_TYPE *) (((unsigned char *) (frag->segments[0].seg_addr.pval)) + + reserve); - rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data ); - if( OPAL_UNLIKELY(rc < 0) ) { + rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); + if (OPAL_UNLIKELY(rc < 0)) { mca_btl_tcp_free(btl, &frag->base); return NULL; } @@ -284,8 +272,8 @@ mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src( iov.iov_len = max_data; iov.iov_base = NULL; - rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data ); - if( OPAL_UNLIKELY(rc < 0) ) { + rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); + if (OPAL_UNLIKELY(rc < 0)) { mca_btl_tcp_free(btl, &frag->base); return NULL; } @@ -311,13 +299,11 @@ mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src( * @param tag (IN) The tag value used to notify the peer. */ -int mca_btl_tcp_send( struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag ) +int mca_btl_tcp_send(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*) btl; - mca_btl_tcp_frag_t* frag = (mca_btl_tcp_frag_t*)descriptor; + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; + mca_btl_tcp_frag_t *frag = (mca_btl_tcp_frag_t *) descriptor; int i; frag->btl = tcp_btl; @@ -326,46 +312,50 @@ int mca_btl_tcp_send( struct mca_btl_base_module_t* btl, frag->iov_idx = 0; frag->iov_cnt = 1; frag->iov_ptr = frag->iov; - frag->iov[0].iov_base = (IOVBASE_TYPE*)&frag->hdr; + frag->iov[0].iov_base = (IOVBASE_TYPE *) &frag->hdr; frag->iov[0].iov_len = sizeof(frag->hdr); frag->hdr.size = 0; - for( i = 0; i < (int)frag->base.des_segment_count; i++) { + for (i = 0; i < (int) frag->base.des_segment_count; i++) { frag->hdr.size += frag->segments[i].seg_len; - frag->iov[i+1].iov_len = frag->segments[i].seg_len; - frag->iov[i+1].iov_base = (IOVBASE_TYPE*)frag->segments[i].seg_addr.pval; + frag->iov[i + 1].iov_len = frag->segments[i].seg_len; + frag->iov[i + 1].iov_base = (IOVBASE_TYPE *) frag->segments[i].seg_addr.pval; frag->iov_cnt++; } frag->hdr.base.tag = tag; frag->hdr.type = MCA_BTL_TCP_HDR_TYPE_SEND; frag->hdr.count = 0; - if (endpoint->endpoint_nbo) MCA_BTL_TCP_HDR_HTON(frag->hdr); - return mca_btl_tcp_endpoint_send(endpoint,frag); + if (endpoint->endpoint_nbo) { + MCA_BTL_TCP_HDR_HTON(frag->hdr); + } + return mca_btl_tcp_endpoint_send(endpoint, frag); } -static void fake_rdma_complete (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, - mca_btl_base_descriptor_t *desc, int rc) +static void fake_rdma_complete(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *desc, int rc) { mca_btl_tcp_frag_t *frag = (mca_btl_tcp_frag_t *) desc; - frag->cb.func (btl, endpoint, frag->segments[0].seg_addr.pval, NULL, frag->cb.context, frag->cb.data, - rc); + frag->cb.func(btl, endpoint, frag->segments[0].seg_addr.pval, NULL, frag->cb.context, + frag->cb.data, rc); } /** * Initiate an asynchronous put. */ -int mca_btl_tcp_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_tcp_put(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*) btl; + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; mca_btl_tcp_frag_t *frag = NULL; int i; MCA_BTL_TCP_FRAG_ALLOC_USER(frag); - if( OPAL_UNLIKELY(NULL == frag) ) { + if (OPAL_UNLIKELY(NULL == frag)) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -383,7 +373,9 @@ int mca_btl_tcp_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t frag->segments[1].seg_addr.lval = remote_address; frag->segments[1].seg_len = size; - if (endpoint->endpoint_nbo) MCA_BTL_BASE_SEGMENT_HTON(frag->segments[1]); + if (endpoint->endpoint_nbo) { + MCA_BTL_BASE_SEGMENT_HTON(frag->segments[1]); + } frag->base.des_flags = MCA_BTL_DES_FLAGS_BTL_OWNERSHIP | MCA_BTL_DES_SEND_ALWAYS_CALLBACK; frag->base.des_cbfunc = fake_rdma_complete; @@ -399,40 +391,44 @@ int mca_btl_tcp_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t frag->hdr.size = 0; frag->iov_cnt = 2; frag->iov_ptr = frag->iov; - frag->iov[0].iov_base = (IOVBASE_TYPE*)&frag->hdr; + frag->iov[0].iov_base = (IOVBASE_TYPE *) &frag->hdr; frag->iov[0].iov_len = sizeof(frag->hdr); - frag->iov[1].iov_base = (IOVBASE_TYPE*) (frag->segments + 1); + frag->iov[1].iov_base = (IOVBASE_TYPE *) (frag->segments + 1); frag->iov[1].iov_len = sizeof(mca_btl_base_segment_t); - for( i = 0; i < (int)frag->base.des_segment_count; i++ ) { + for (i = 0; i < (int) frag->base.des_segment_count; i++) { frag->hdr.size += frag->segments[i].seg_len; - frag->iov[i+2].iov_len = frag->segments[i].seg_len; - frag->iov[i+2].iov_base = (IOVBASE_TYPE*)frag->segments[i].seg_addr.pval; + frag->iov[i + 2].iov_len = frag->segments[i].seg_len; + frag->iov[i + 2].iov_base = (IOVBASE_TYPE *) frag->segments[i].seg_addr.pval; frag->iov_cnt++; } frag->hdr.base.tag = MCA_BTL_TAG_BTL; frag->hdr.type = MCA_BTL_TCP_HDR_TYPE_PUT; frag->hdr.count = 1; - if (endpoint->endpoint_nbo) MCA_BTL_TCP_HDR_HTON(frag->hdr); - return ((i = mca_btl_tcp_endpoint_send(endpoint,frag)) >= 0 ? OPAL_SUCCESS : i); + if (endpoint->endpoint_nbo) { + MCA_BTL_TCP_HDR_HTON(frag->hdr); + } + return ((i = mca_btl_tcp_endpoint_send(endpoint, frag)) >= 0 ? OPAL_SUCCESS : i); } - /** * Initiate an asynchronous get. */ -int mca_btl_tcp_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_tcp_get(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*) btl; - mca_btl_tcp_frag_t* frag = NULL; + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; + mca_btl_tcp_frag_t *frag = NULL; int rc; MCA_BTL_TCP_FRAG_ALLOC_USER(frag); - if( OPAL_UNLIKELY(NULL == frag) ) { - return OPAL_ERR_OUT_OF_RESOURCE;; + if (OPAL_UNLIKELY(NULL == frag)) { + return OPAL_ERR_OUT_OF_RESOURCE; + ; } frag->endpoint = endpoint; @@ -466,103 +462,101 @@ int mca_btl_tcp_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t frag->hdr.size = 0; frag->iov_cnt = 2; frag->iov_ptr = frag->iov; - frag->iov[0].iov_base = (IOVBASE_TYPE*)&frag->hdr; + frag->iov[0].iov_base = (IOVBASE_TYPE *) &frag->hdr; frag->iov[0].iov_len = sizeof(frag->hdr); - frag->iov[1].iov_base = (IOVBASE_TYPE*) &frag->segments[1]; + frag->iov[1].iov_base = (IOVBASE_TYPE *) &frag->segments[1]; frag->iov[1].iov_len = sizeof(mca_btl_base_segment_t); frag->hdr.base.tag = MCA_BTL_TAG_BTL; frag->hdr.type = MCA_BTL_TCP_HDR_TYPE_GET; frag->hdr.count = 1; - if (endpoint->endpoint_nbo) MCA_BTL_TCP_HDR_HTON(frag->hdr); - return ((rc = mca_btl_tcp_endpoint_send(endpoint,frag)) >= 0 ? OPAL_SUCCESS : rc); + if (endpoint->endpoint_nbo) { + MCA_BTL_TCP_HDR_HTON(frag->hdr); + } + return ((rc = mca_btl_tcp_endpoint_send(endpoint, frag)) >= 0 ? OPAL_SUCCESS : rc); } - /* * Cleanup/release module resources. */ -int mca_btl_tcp_finalize(struct mca_btl_base_module_t* btl) +int mca_btl_tcp_finalize(struct mca_btl_base_module_t *btl) { - mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*) btl; - opal_list_item_t* item; + mca_btl_tcp_module_t *tcp_btl = (mca_btl_tcp_module_t *) btl; + opal_list_item_t *item; /* Don't lock the tcp_endpoints_mutex, at this point a single * thread should be active. */ - for( item = opal_list_remove_first(&tcp_btl->tcp_endpoints); - item != NULL; + for (item = opal_list_remove_first(&tcp_btl->tcp_endpoints); item != NULL; item = opal_list_remove_first(&tcp_btl->tcp_endpoints)) { - mca_btl_tcp_endpoint_t *endpoint = (mca_btl_tcp_endpoint_t*)item; + mca_btl_tcp_endpoint_t *endpoint = (mca_btl_tcp_endpoint_t *) item; OBJ_RELEASE(endpoint); } free(tcp_btl); return OPAL_SUCCESS; } -void mca_btl_tcp_dump(struct mca_btl_base_module_t* base_btl, - struct mca_btl_base_endpoint_t* endpoint, - int verbose) +void mca_btl_tcp_dump(struct mca_btl_base_module_t *base_btl, + struct mca_btl_base_endpoint_t *endpoint, int verbose) { - mca_btl_tcp_module_t* btl = (mca_btl_tcp_module_t*)base_btl; + mca_btl_tcp_module_t *btl = (mca_btl_tcp_module_t *) base_btl; mca_btl_base_err("%s TCP %p kernel_id %d\n" #if MCA_BTL_TCP_STATISTICS " | statistics: sent %lu recv %lu\n" -#endif /* MCA_BTL_TCP_STATISTICS */ +#endif /* MCA_BTL_TCP_STATISTICS */ " | latency %u bandwidth %u\n", - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), (void*)btl, btl->tcp_ifkindex, + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), (void *) btl, btl->tcp_ifkindex, #if MCA_BTL_TCP_STATISTICS btl->tcp_bytes_sent, btl->btl_bytes_recv, -#endif /* MCA_BTL_TCP_STATISTICS */ +#endif /* MCA_BTL_TCP_STATISTICS */ btl->super.btl_latency, btl->super.btl_bandwidth); #if OPAL_ENABLE_DEBUG && WANT_PEER_DUMP - if( NULL != endpoint ) { + if (NULL != endpoint) { MCA_BTL_TCP_ENDPOINT_DUMP(10, endpoint, false, "TCP"); - } else if( verbose ) { + } else if (verbose) { opal_list_item_t *item; OPAL_THREAD_LOCK(&btl->tcp_endpoints_mutex); - for(item = opal_list_get_first(&btl->tcp_endpoints); - item != opal_list_get_end(&btl->tcp_endpoints); - item = opal_list_get_next(item)) { - MCA_BTL_TCP_ENDPOINT_DUMP(10, (mca_btl_base_endpoint_t*)item, false, "TCP"); + for (item = opal_list_get_first(&btl->tcp_endpoints); + item != opal_list_get_end(&btl->tcp_endpoints); item = opal_list_get_next(item)) { + MCA_BTL_TCP_ENDPOINT_DUMP(10, (mca_btl_base_endpoint_t *) item, false, "TCP"); } OPAL_THREAD_UNLOCK(&btl->tcp_endpoints_mutex); } #endif /* OPAL_ENABLE_DEBUG && WANT_PEER_DUMP */ } - /* - * A blocking recv for both blocking and non-blocking socket. - * Used to receive the small amount of connection information + * A blocking recv for both blocking and non-blocking socket. + * Used to receive the small amount of connection information * that identifies the endpoints - * - * when the socket is blocking (the caller introduces timeout) - * which happens during initial handshake otherwise socket is + * + * when the socket is blocking (the caller introduces timeout) + * which happens during initial handshake otherwise socket is * non-blocking most of the time. */ -int mca_btl_tcp_recv_blocking(int sd, void* data, size_t size) +int mca_btl_tcp_recv_blocking(int sd, void *data, size_t size) { - unsigned char* ptr = (unsigned char*)data; + unsigned char *ptr = (unsigned char *) data; size_t cnt = 0; while (cnt < size) { - int retval = recv(sd, ((char *)ptr) + cnt, size - cnt, 0); + int retval = recv(sd, ((char *) ptr) + cnt, size - cnt, 0); /* remote closed connection */ if (0 == retval) { OPAL_OUTPUT_VERBOSE((100, opal_btl_base_framework.framework_output, - "remote peer unexpectedly closed connection while I was waiting for a blocking message")); + "remote peer unexpectedly closed connection while I was waiting " + "for a blocking message")); break; } /* socket is non-blocking so handle errors */ if (retval < 0) { - if (opal_socket_errno != EINTR && - opal_socket_errno != EAGAIN && - opal_socket_errno != EWOULDBLOCK) { - BTL_VERBOSE(("recv(%d) failed: %s (%d)", sd, strerror(opal_socket_errno), opal_socket_errno)); + if (opal_socket_errno != EINTR && opal_socket_errno != EAGAIN + && opal_socket_errno != EWOULDBLOCK) { + BTL_VERBOSE(("recv(%d) failed: %s (%d)", sd, strerror(opal_socket_errno), + opal_socket_errno)); break; } continue; @@ -572,24 +566,23 @@ int mca_btl_tcp_recv_blocking(int sd, void* data, size_t size) return cnt; } - /* * A blocking send on a non-blocking socket. Used to send the small * amount of connection information used during the initial handshake * (magic string plus process guid) */ -int mca_btl_tcp_send_blocking(int sd, const void* data, size_t size) +int mca_btl_tcp_send_blocking(int sd, const void *data, size_t size) { - unsigned char* ptr = (unsigned char*)data; + unsigned char *ptr = (unsigned char *) data; size_t cnt = 0; - while(cnt < size) { - int retval = send(sd, ((const char *)ptr) + cnt, size - cnt, 0); + while (cnt < size) { + int retval = send(sd, ((const char *) ptr) + cnt, size - cnt, 0); if (retval < 0) { - if (opal_socket_errno != EINTR && - opal_socket_errno != EAGAIN && - opal_socket_errno != EWOULDBLOCK) { - BTL_VERBOSE(("send() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); + if (opal_socket_errno != EINTR && opal_socket_errno != EAGAIN + && opal_socket_errno != EWOULDBLOCK) { + BTL_VERBOSE( + ("send() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); return -1; } continue; diff --git a/opal/mca/btl/tcp/btl_tcp.h b/opal/mca/btl/tcp/btl_tcp.h index a73970a8550..55fed24398b 100644 --- a/opal/mca/btl/tcp/btl_tcp.h +++ b/opal/mca/btl/tcp/btl_tcp.h @@ -31,42 +31,42 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif /* Open MPI includes */ -#include "opal/util/event.h" #include "opal/class/opal_free_list.h" -#include "opal/mca/btl/btl.h" +#include "opal/class/opal_hash_table.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/mpool.h" -#include "opal/class/opal_hash_table.h" +#include "opal/util/event.h" #include "opal/util/fd.h" #define MCA_BTL_TCP_STATISTICS 0 BEGIN_C_DECLS -extern opal_event_base_t* mca_btl_tcp_event_base; +extern opal_event_base_t *mca_btl_tcp_event_base; -#define MCA_BTL_TCP_COMPLETE_FRAG_SEND(frag) \ - do { \ - int btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); \ - if( frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK ) { \ +#define MCA_BTL_TCP_COMPLETE_FRAG_SEND(frag) \ + do { \ + int btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); \ + if (frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) { \ frag->base.des_cbfunc(&frag->endpoint->endpoint_btl->super, frag->endpoint, \ - &frag->base, frag->rc); \ - } \ - if( btl_ownership ) { \ - MCA_BTL_TCP_FRAG_RETURN(frag); \ - } \ + &frag->base, frag->rc); \ + } \ + if (btl_ownership) { \ + MCA_BTL_TCP_FRAG_RETURN(frag); \ + } \ } while (0) extern opal_list_t mca_btl_tcp_ready_frag_pending_queue; @@ -74,21 +74,18 @@ extern opal_mutex_t mca_btl_tcp_ready_frag_mutex; extern int mca_btl_tcp_pipe_to_progress[2]; extern int mca_btl_tcp_progress_thread_trigger; -#define MCA_BTL_TCP_CRITICAL_SECTION_ENTER(name) \ - opal_mutex_atomic_lock((name)) -#define MCA_BTL_TCP_CRITICAL_SECTION_LEAVE(name) \ - opal_mutex_atomic_unlock((name)) - -#define MCA_BTL_TCP_ACTIVATE_EVENT(event, value) \ - do { \ - if(0 < mca_btl_tcp_progress_thread_trigger) { \ - opal_event_t* _event = (opal_event_t*)(event); \ - (void) opal_fd_write( mca_btl_tcp_pipe_to_progress[1], sizeof(opal_event_t*), \ - &_event); \ - } \ - else { \ - opal_event_add(event, (value)); \ - } \ +#define MCA_BTL_TCP_CRITICAL_SECTION_ENTER(name) opal_mutex_atomic_lock((name)) +#define MCA_BTL_TCP_CRITICAL_SECTION_LEAVE(name) opal_mutex_atomic_unlock((name)) + +#define MCA_BTL_TCP_ACTIVATE_EVENT(event, value) \ + do { \ + if (0 < mca_btl_tcp_progress_thread_trigger) { \ + opal_event_t *_event = (opal_event_t *) (event); \ + (void) opal_fd_write(mca_btl_tcp_pipe_to_progress[1], sizeof(opal_event_t *), \ + &_event); \ + } else { \ + opal_event_add(event, (value)); \ + } \ } while (0) /** @@ -96,53 +93,53 @@ extern int mca_btl_tcp_progress_thread_trigger; */ struct mca_btl_tcp_component_t { - mca_btl_base_component_3_0_0_t super; /**< base BTL component */ - uint32_t tcp_addr_count; /**< total number of addresses */ - uint32_t tcp_num_btls; /**< number of interfaces available to the TCP component */ - unsigned int tcp_num_links; /**< number of logical links per physical device */ + mca_btl_base_component_3_0_0_t super; /**< base BTL component */ + uint32_t tcp_addr_count; /**< total number of addresses */ + uint32_t tcp_num_btls; /**< number of interfaces available to the TCP component */ + unsigned int tcp_num_links; /**< number of logical links per physical device */ struct mca_btl_tcp_module_t **tcp_btls; /**< array of available BTL modules */ - opal_list_t local_ifs; /**< opal list of local opal_if_t interfaces */ + opal_list_t local_ifs; /**< opal list of local opal_if_t interfaces */ int tcp_free_list_num; /**< initial size of free lists */ int tcp_free_list_max; /**< maximum size of free lists */ - int tcp_free_list_inc; /**< number of elements to alloc when growing free lists */ - int tcp_endpoint_cache; /**< amount of cache on each endpoint */ - opal_proc_table_t tcp_procs; /**< hash table of tcp proc structures */ - opal_mutex_t tcp_lock; /**< lock for accessing module state */ + int tcp_free_list_inc; /**< number of elements to alloc when growing free lists */ + int tcp_endpoint_cache; /**< amount of cache on each endpoint */ + opal_proc_table_t tcp_procs; /**< hash table of tcp proc structures */ + opal_mutex_t tcp_lock; /**< lock for accessing module state */ opal_list_t tcp_events; - opal_event_t tcp_recv_event; /**< recv event for IPv4 listen socket */ - int tcp_listen_sd; /**< IPv4 listen socket for incoming connection requests */ - unsigned short tcp_listen_port; /**< IPv4 listen port */ - int tcp_port_min; /**< IPv4 minimum port */ - int tcp_port_range; /**< IPv4 port range */ + opal_event_t tcp_recv_event; /**< recv event for IPv4 listen socket */ + int tcp_listen_sd; /**< IPv4 listen socket for incoming connection requests */ + unsigned short tcp_listen_port; /**< IPv4 listen port */ + int tcp_port_min; /**< IPv4 minimum port */ + int tcp_port_range; /**< IPv4 port range */ #if OPAL_ENABLE_IPV6 - opal_event_t tcp6_recv_event; /**< recv event for IPv6 listen socket */ - int tcp6_listen_sd; /**< IPv6 listen socket for incoming connection requests */ - unsigned short tcp6_listen_port; /**< IPv6 listen port */ - int tcp6_port_min; /**< IPv4 minimum port */ - int tcp6_port_range; /**< IPv4 port range */ + opal_event_t tcp6_recv_event; /**< recv event for IPv6 listen socket */ + int tcp6_listen_sd; /**< IPv6 listen socket for incoming connection requests */ + unsigned short tcp6_listen_port; /**< IPv6 listen port */ + int tcp6_port_min; /**< IPv4 minimum port */ + int tcp6_port_range; /**< IPv4 port range */ #endif /* Port range restriction */ - char* tcp_if_include; /**< comma seperated list of interface to include */ - char* tcp_if_exclude; /**< comma seperated list of interface to exclude */ - int tcp_sndbuf; /**< socket sndbuf size */ - int tcp_rcvbuf; /**< socket rcvbuf size */ - int tcp_disable_family; /**< disabled AF_family */ + char *tcp_if_include; /**< comma seperated list of interface to include */ + char *tcp_if_exclude; /**< comma seperated list of interface to exclude */ + int tcp_sndbuf; /**< socket sndbuf size */ + int tcp_rcvbuf; /**< socket rcvbuf size */ + int tcp_disable_family; /**< disabled AF_family */ /* free list of fragment descriptors */ opal_free_list_t tcp_frag_eager; opal_free_list_t tcp_frag_max; opal_free_list_t tcp_frag_user; - int tcp_enable_progress_thread; /** Support for tcp progress thread flag */ + int tcp_enable_progress_thread; /** Support for tcp progress thread flag */ opal_event_t tcp_recv_thread_async_event; opal_mutex_t tcp_frag_eager_mutex; opal_mutex_t tcp_frag_max_mutex; opal_mutex_t tcp_frag_user_mutex; /* Do we want to use TCP_NODELAY? */ - int tcp_not_use_nodelay; + int tcp_not_use_nodelay; /* do we want to warn on all excluded interfaces * that are not found? @@ -157,22 +154,22 @@ OPAL_MODULE_DECLSPEC extern mca_btl_tcp_component_t mca_btl_tcp_component; * BTL Module Interface */ struct mca_btl_tcp_module_t { - mca_btl_base_module_t super; /**< base BTL interface */ - uint32_t btl_index; /**< Local BTL module index, used for vertex - data and used as a hash key when - solving module matching problem */ - uint16_t tcp_ifkindex; /** BTL notification of change in the process list. @@ -222,13 +219,9 @@ extern int mca_btl_tcp_finalize( * */ -extern int mca_btl_tcp_add_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers, - opal_bitmap_t* reachable -); +extern int mca_btl_tcp_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable); /** * PML->BTL notification of change in the process list. @@ -241,13 +234,9 @@ extern int mca_btl_tcp_add_procs( * */ -extern int mca_btl_tcp_del_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers -); - +extern int mca_btl_tcp_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers); /** * Initiate an asynchronous send. @@ -258,32 +247,31 @@ extern int mca_btl_tcp_del_procs( * @param tag (IN) The tag value used to notify the peer. */ -extern int mca_btl_tcp_send( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* btl_peer, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag -); - +extern int mca_btl_tcp_send(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *btl_peer, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag); /** * Initiate an asynchronous put. */ -int mca_btl_tcp_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - +int mca_btl_tcp_put(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); /** * Initiate an asynchronous get. */ -int mca_btl_tcp_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_tcp_get(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); /** * Allocate a descriptor with a segment of the requested size. @@ -294,13 +282,9 @@ int mca_btl_tcp_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t * @param size (IN) Request segment size. */ -extern mca_btl_base_descriptor_t* mca_btl_tcp_alloc( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags); - +extern mca_btl_base_descriptor_t *mca_btl_tcp_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags); /** * Return a segment allocated by this BTL. @@ -309,10 +293,7 @@ extern mca_btl_base_descriptor_t* mca_btl_tcp_alloc( * @param descriptor (IN) Allocated descriptor. */ -extern int mca_btl_tcp_free( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* des); - +extern int mca_btl_tcp_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); /** * Prepare a descriptor for send/rdma using the supplied @@ -326,29 +307,23 @@ extern int mca_btl_tcp_free( * @param convertor (IN) Data type convertor * @param reserve (IN) Additional bytes requested by upper layer to precede user data * @param size (IN/OUT) Number of bytes to prepare (IN), number of bytes actually prepared (OUT) -*/ - -mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* peer, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags -); - -extern void -mca_btl_tcp_dump(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - int verbose); + */ + +mca_btl_base_descriptor_t *mca_btl_tcp_prepare_src(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *peer, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags); + +extern void mca_btl_tcp_dump(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, int verbose); /* * A blocking send on a non-blocking socket. Used to send the small * amount of connection information that identifies the endpoints * endpoint. */ -int mca_btl_tcp_send_blocking(int sd, const void* data, size_t size); +int mca_btl_tcp_send_blocking(int sd, const void *data, size_t size); /* * A blocking recv for both blocking and non-blocking socket. @@ -359,7 +334,7 @@ int mca_btl_tcp_send_blocking(int sd, const void* data, size_t size); * which happens during initial handshake otherwise socket is * non-blocking most of the time. */ -int mca_btl_tcp_recv_blocking(int sd, void* data, size_t size); +int mca_btl_tcp_recv_blocking(int sd, void *data, size_t size); END_C_DECLS #endif diff --git a/opal/mca/btl/tcp/btl_tcp_addr.h b/opal/mca/btl/tcp/btl_tcp_addr.h index d714df36bce..f456970a318 100644 --- a/opal/mca/btl/tcp/btl_tcp_addr.h +++ b/opal/mca/btl/tcp/btl_tcp_addr.h @@ -25,13 +25,13 @@ #define MCA_BTL_TCP_ADDR_H #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #include @@ -46,19 +46,19 @@ * structure. */ struct mca_btl_tcp_modex_addr_t { - uint8_t addr[16]; /* endpoint address. for addr_family - of MCA_BTL_TCP_AF_INET, only the - first 4 bytes have meaning. */ - uint32_t addr_ifkindex; /* endpoint kernel index */ - uint32_t addr_mask; /* ip mask */ - uint32_t addr_bandwidth; /* interface bandwidth */ - uint16_t addr_port; /* endpoint listen port */ - uint8_t addr_family; /* endpoint address family. Note that - this is - MCA_BTL_TCP_AF_{INET,INET6}, not - the traditional - AF_INET/AF_INET6. */ - uint8_t padding[1]; /* pad out to an 8-byte word */ + uint8_t addr[16]; /* endpoint address. for addr_family + of MCA_BTL_TCP_AF_INET, only the + first 4 bytes have meaning. */ + uint32_t addr_ifkindex; /* endpoint kernel index */ + uint32_t addr_mask; /* ip mask */ + uint32_t addr_bandwidth; /* interface bandwidth */ + uint16_t addr_port; /* endpoint listen port */ + uint8_t addr_family; /* endpoint address family. Note that + this is + MCA_BTL_TCP_AF_{INET,INET6}, not + the traditional + AF_INET/AF_INET6. */ + uint8_t padding[1]; /* pad out to an 8-byte word */ }; typedef struct mca_btl_tcp_modex_addr_t mca_btl_tcp_modex_addr_t; @@ -75,20 +75,19 @@ _Static_assert(sizeof(struct mca_btl_tcp_modex_addr_t) == 32, "mca_btl_tcp_modex */ struct mca_btl_tcp_addr_t { union { - struct in_addr addr_inet; /* IPv6 listen address */ + struct in_addr addr_inet; /* IPv6 listen address */ #if OPAL_ENABLE_IPV6 - struct in6_addr addr_inet6; /* IPv6 listen address */ + struct in6_addr addr_inet6; /* IPv6 listen address */ #endif } addr_union; - in_port_t addr_port; /**< listen port */ - int addr_ifkindex; /**< remote interface index assigned with - this address */ - uint8_t addr_family; /**< AF_INET or AF_INET6 */ + in_port_t addr_port; /**< listen port */ + int addr_ifkindex; /**< remote interface index assigned with + this address */ + uint8_t addr_family; /**< AF_INET or AF_INET6 */ }; typedef struct mca_btl_tcp_addr_t mca_btl_tcp_addr_t; -#define MCA_BTL_TCP_AF_INET 0 -#define MCA_BTL_TCP_AF_INET6 1 +#define MCA_BTL_TCP_AF_INET 0 +#define MCA_BTL_TCP_AF_INET6 1 #endif - diff --git a/opal/mca/btl/tcp/btl_tcp_component.c b/opal/mca/btl/tcp/btl_tcp_component.c index fe08760a957..55a0bb471fc 100644 --- a/opal/mca/btl/tcp/btl_tcp_component.c +++ b/opal/mca/btl/tcp/btl_tcp_component.c @@ -33,69 +33,68 @@ #include "opal/opal_socket_errno.h" #ifdef HAVE_UNISTD_H -#include +# include #endif -#include #include +#include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #if OPAL_ENABLE_IPV6 -# ifdef HAVE_NETDB_H -# include -# endif +# ifdef HAVE_NETDB_H +# include +# endif #endif #include #include #ifdef HAVE_SYS_TIME_H -#include +# include #endif -#include "opal/util/event.h" +#include "opal/constants.h" +#include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" +#include "opal/mca/mpool/base/base.h" +#include "opal/mca/pmix/pmix-internal.h" +#include "opal/mca/reachable/base/base.h" +#include "opal/mca/threads/threads.h" +#include "opal/util/argv.h" #include "opal/util/ethtool.h" +#include "opal/util/event.h" +#include "opal/util/fd.h" #include "opal/util/if.h" -#include "opal/util/output.h" -#include "opal/util/argv.h" #include "opal/util/net.h" +#include "opal/util/output.h" +#include "opal/util/printf.h" #include "opal/util/proc.h" -#include "opal/util/net.h" -#include "opal/util/fd.h" #include "opal/util/show_help.h" #include "opal/util/string_copy.h" -#include "opal/util/printf.h" -#include "opal/constants.h" -#include "opal/mca/btl/btl.h" -#include "opal/mca/btl/base/base.h" -#include "opal/mca/mpool/base/base.h" -#include "opal/mca/btl/base/btl_base_error.h" -#include "opal/mca/reachable/base/base.h" -#include "opal/mca/pmix/pmix-internal.h" -#include "opal/mca/threads/threads.h" -#include "opal/constants.h" -#include "opal/mca/btl/btl.h" -#include "opal/mca/btl/base/base.h" -#include "opal/mca/btl/base/btl_base_error.h" #include "btl_tcp.h" #include "btl_tcp_addr.h" -#include "btl_tcp_proc.h" -#include "btl_tcp_frag.h" #include "btl_tcp_endpoint.h" +#include "btl_tcp_frag.h" +#include "btl_tcp_proc.h" +#include "opal/constants.h" +#include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" #if OPAL_CUDA_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" +# include "opal/mca/common/cuda/common_cuda.h" #endif /* OPAL_CUDA_SUPPORT */ #define MCA_BTL_TCP_BTL_BANDWIDTH 100 -#define MCA_BTL_TCP_BTL_LATENCY 100 +#define MCA_BTL_TCP_BTL_LATENCY 100 /* * Local functions @@ -104,11 +103,11 @@ static int mca_btl_tcp_component_register(void); static int mca_btl_tcp_component_open(void); static int mca_btl_tcp_component_close(void); -opal_event_base_t* mca_btl_tcp_event_base = NULL; +opal_event_base_t *mca_btl_tcp_event_base = NULL; int mca_btl_tcp_progress_thread_trigger = -1; -int mca_btl_tcp_pipe_to_progress[2] = { -1, -1 }; -static opal_thread_t mca_btl_tcp_progress_thread = { { 0 } }; -opal_list_t mca_btl_tcp_ready_frag_pending_queue = { { 0 } }; +int mca_btl_tcp_pipe_to_progress[2] = {-1, -1}; +static opal_thread_t mca_btl_tcp_progress_thread = {{0}}; +opal_list_t mca_btl_tcp_ready_frag_pending_queue = {{0}}; opal_mutex_t mca_btl_tcp_ready_frag_mutex = OPAL_MUTEX_STATIC_INIT; mca_btl_tcp_component_t mca_btl_tcp_component = { @@ -116,72 +115,59 @@ mca_btl_tcp_component_t mca_btl_tcp_component = { /* First, the mca_base_component_t struct containing meta information about the component itself */ - .btl_version = { - MCA_BTL_DEFAULT_VERSION("tcp"), - .mca_open_component = mca_btl_tcp_component_open, - .mca_close_component = mca_btl_tcp_component_close, - .mca_register_component_params = mca_btl_tcp_component_register, - }, - .btl_data = { - /* The component is checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("tcp"), + .mca_open_component = mca_btl_tcp_component_open, + .mca_close_component = mca_btl_tcp_component_close, + .mca_register_component_params = mca_btl_tcp_component_register, + }, + .btl_data = + {/* The component is checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT}, .btl_init = mca_btl_tcp_component_init, .btl_progress = NULL, - } -}; + }}; /* * utility routines for parameter registration */ -static inline char* mca_btl_tcp_param_register_string( - const char* param_name, - const char* help_string, - const char* default_value, - int level, - char **storage) +static inline char *mca_btl_tcp_param_register_string(const char *param_name, + const char *help_string, + const char *default_value, int level, + char **storage) { *storage = (char *) default_value; - (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, - param_name, help_string, MCA_BASE_VAR_TYPE_STRING, - NULL, 0, 0, level, + (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, param_name, + help_string, MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, level, MCA_BASE_VAR_SCOPE_READONLY, storage); return *storage; } -static inline int mca_btl_tcp_param_register_int( - const char* param_name, - const char* help_string, - int default_value, - int level, - int *storage) +static inline int mca_btl_tcp_param_register_int(const char *param_name, const char *help_string, + int default_value, int level, int *storage) { *storage = default_value; - (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, - param_name, help_string, MCA_BASE_VAR_TYPE_INT, - NULL, 0, 0, level, + (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, param_name, + help_string, MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, level, MCA_BASE_VAR_SCOPE_READONLY, storage); return *storage; } -static inline unsigned int mca_btl_tcp_param_register_uint( - const char* param_name, - const char* help_string, - unsigned int default_value, - int level, - unsigned int *storage) +static inline unsigned int mca_btl_tcp_param_register_uint(const char *param_name, + const char *help_string, + unsigned int default_value, int level, + unsigned int *storage) { *storage = default_value; - (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, - param_name, help_string, MCA_BASE_VAR_TYPE_UNSIGNED_INT, - NULL, 0, 0, level, - MCA_BASE_VAR_SCOPE_READONLY, storage); + (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, param_name, + help_string, MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, 0, + level, MCA_BASE_VAR_SCOPE_READONLY, storage); return *storage; } - /* * Data structure for accepting connections. */ @@ -192,46 +178,40 @@ struct mca_btl_tcp_event_t { }; typedef struct mca_btl_tcp_event_t mca_btl_tcp_event_t; -static void mca_btl_tcp_event_construct(mca_btl_tcp_event_t* event) +static void mca_btl_tcp_event_construct(mca_btl_tcp_event_t *event) { MCA_BTL_TCP_CRITICAL_SECTION_ENTER(&mca_btl_tcp_component.tcp_lock); opal_list_append(&mca_btl_tcp_component.tcp_events, &event->item); MCA_BTL_TCP_CRITICAL_SECTION_LEAVE(&mca_btl_tcp_component.tcp_lock); } -static void mca_btl_tcp_event_destruct(mca_btl_tcp_event_t* event) +static void mca_btl_tcp_event_destruct(mca_btl_tcp_event_t *event) { MCA_BTL_TCP_CRITICAL_SECTION_ENTER(&mca_btl_tcp_component.tcp_lock); opal_list_remove_item(&mca_btl_tcp_component.tcp_events, &event->item); MCA_BTL_TCP_CRITICAL_SECTION_LEAVE(&mca_btl_tcp_component.tcp_lock); } -OBJ_CLASS_INSTANCE( - mca_btl_tcp_event_t, - opal_list_item_t, - mca_btl_tcp_event_construct, - mca_btl_tcp_event_destruct); - +OBJ_CLASS_INSTANCE(mca_btl_tcp_event_t, opal_list_item_t, mca_btl_tcp_event_construct, + mca_btl_tcp_event_destruct); /* * functions for receiving event callbacks */ -static void mca_btl_tcp_component_recv_handler(int, short, void*); -static void mca_btl_tcp_component_accept_handler(int, short, void*); +static void mca_btl_tcp_component_recv_handler(int, short, void *); +static void mca_btl_tcp_component_accept_handler(int, short, void *); static int mca_btl_tcp_component_verify(void) { - if( mca_btl_tcp_component.tcp_port_min > USHRT_MAX ) { - opal_show_help("help-mpi-btl-tcp.txt", "invalid minimum port", - true, "v4", opal_process_info.nodename, - mca_btl_tcp_component.tcp_port_min ); + if (mca_btl_tcp_component.tcp_port_min > USHRT_MAX) { + opal_show_help("help-mpi-btl-tcp.txt", "invalid minimum port", true, "v4", + opal_process_info.nodename, mca_btl_tcp_component.tcp_port_min); mca_btl_tcp_component.tcp_port_min = 1024; } #if OPAL_ENABLE_IPV6 - if( mca_btl_tcp_component.tcp6_port_min > USHRT_MAX ) { - opal_show_help("help-mpi-btl-tcp.txt", "invalid minimum port", - true, "v6", opal_process_info.nodename, - mca_btl_tcp_component.tcp6_port_min ); + if (mca_btl_tcp_component.tcp6_port_min > USHRT_MAX) { + opal_show_help("help-mpi-btl-tcp.txt", "invalid minimum port", true, "v6", + opal_process_info.nodename, mca_btl_tcp_component.tcp6_port_min); mca_btl_tcp_component.tcp6_port_min = 1024; } #endif @@ -246,96 +226,111 @@ static int mca_btl_tcp_component_verify(void) static int mca_btl_tcp_component_register(void) { - char* message; + char *message; /* register TCP component parameters */ - mca_btl_tcp_param_register_uint("links", NULL, 1, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_num_links); - mca_btl_tcp_param_register_string("if_include", "Comma-delimited list of devices and/or CIDR notation of networks to use for MPI communication (e.g., \"eth0,192.168.0.0/16\"). Mutually exclusive with btl_tcp_if_exclude.", "", OPAL_INFO_LVL_1, &mca_btl_tcp_component.tcp_if_include); - mca_btl_tcp_param_register_string("if_exclude", "Comma-delimited list of devices and/or CIDR notation of networks to NOT use for MPI communication -- all devices not matching these specifications will be used (e.g., \"eth0,192.168.0.0/16\"). If set to a non-default value, it is mutually exclusive with btl_tcp_if_include.", - "127.0.0.1/8,sppp", - OPAL_INFO_LVL_1, &mca_btl_tcp_component.tcp_if_exclude); - - mca_btl_tcp_param_register_int ("free_list_num", NULL, 8, OPAL_INFO_LVL_5, &mca_btl_tcp_component.tcp_free_list_num); - mca_btl_tcp_param_register_int ("free_list_max", NULL, -1, OPAL_INFO_LVL_5, &mca_btl_tcp_component.tcp_free_list_max); - mca_btl_tcp_param_register_int ("free_list_inc", NULL, 32, OPAL_INFO_LVL_5, &mca_btl_tcp_component.tcp_free_list_inc); - mca_btl_tcp_param_register_int ("sndbuf", - "The size of the send buffer socket option for each connection. " - "Modern TCP stacks generally are smarter than a fixed size and in some " - "situations setting a buffer size explicitly can actually lower " - "performance. 0 means the tcp btl will not try to set a send buffer " - "size.", - 0, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_sndbuf); - mca_btl_tcp_param_register_int ("rcvbuf", - "The size of the receive buffer socket option for each connection. " - "Modern TCP stacks generally are smarter than a fixed size and in some " - "situations setting a buffer size explicitly can actually lower " - "performance. 0 means the tcp btl will not try to set a receive buffer " - "size.", - 0, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_rcvbuf); - mca_btl_tcp_param_register_int ("endpoint_cache", + mca_btl_tcp_param_register_uint("links", NULL, 1, OPAL_INFO_LVL_4, + &mca_btl_tcp_component.tcp_num_links); + mca_btl_tcp_param_register_string( + "if_include", + "Comma-delimited list of devices and/or CIDR notation of networks to use for MPI " + "communication (e.g., \"eth0,192.168.0.0/16\"). Mutually exclusive with " + "btl_tcp_if_exclude.", + "", OPAL_INFO_LVL_1, &mca_btl_tcp_component.tcp_if_include); + mca_btl_tcp_param_register_string( + "if_exclude", + "Comma-delimited list of devices and/or CIDR notation of networks to NOT use for MPI " + "communication -- all devices not matching these specifications will be used (e.g., " + "\"eth0,192.168.0.0/16\"). If set to a non-default value, it is mutually exclusive with " + "btl_tcp_if_include.", + "127.0.0.1/8,sppp", OPAL_INFO_LVL_1, &mca_btl_tcp_component.tcp_if_exclude); + + mca_btl_tcp_param_register_int("free_list_num", NULL, 8, OPAL_INFO_LVL_5, + &mca_btl_tcp_component.tcp_free_list_num); + mca_btl_tcp_param_register_int("free_list_max", NULL, -1, OPAL_INFO_LVL_5, + &mca_btl_tcp_component.tcp_free_list_max); + mca_btl_tcp_param_register_int("free_list_inc", NULL, 32, OPAL_INFO_LVL_5, + &mca_btl_tcp_component.tcp_free_list_inc); + mca_btl_tcp_param_register_int( + "sndbuf", + "The size of the send buffer socket option for each connection. " + "Modern TCP stacks generally are smarter than a fixed size and in some " + "situations setting a buffer size explicitly can actually lower " + "performance. 0 means the tcp btl will not try to set a send buffer " + "size.", + 0, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_sndbuf); + mca_btl_tcp_param_register_int( + "rcvbuf", + "The size of the receive buffer socket option for each connection. " + "Modern TCP stacks generally are smarter than a fixed size and in some " + "situations setting a buffer size explicitly can actually lower " + "performance. 0 means the tcp btl will not try to set a receive buffer " + "size.", + 0, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_rcvbuf); + mca_btl_tcp_param_register_int( + "endpoint_cache", "The size of the internal cache for each TCP connection. This cache is" " used to reduce the number of syscalls, by replacing them with memcpy." " Every read will read the expected data plus the amount of the" - " endpoint_cache", 30*1024, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_endpoint_cache); - mca_btl_tcp_param_register_int ("use_nagle", "Whether to use Nagle's algorithm or not (using Nagle's algorithm may increase short message latency)", - 0, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_not_use_nodelay); - mca_btl_tcp_param_register_int( "port_min_v4", - "The minimum port where the TCP BTL will try to bind (default 1024)", - 1024, OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp_port_min); - - opal_asprintf( &message, - "The number of ports where the TCP BTL will try to bind (default %d)." - " This parameter together with the port min, define a range of ports" - " where Open MPI will open sockets.", - (0x1 << 16) - mca_btl_tcp_component.tcp_port_min - 1 ); - mca_btl_tcp_param_register_int( "port_range_v4", message, - (0x1 << 16) - mca_btl_tcp_component.tcp_port_min - 1, - OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp_port_range); + " endpoint_cache", + 30 * 1024, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_endpoint_cache); + mca_btl_tcp_param_register_int("use_nagle", + "Whether to use Nagle's algorithm or not (using Nagle's " + "algorithm may increase short message latency)", + 0, OPAL_INFO_LVL_4, &mca_btl_tcp_component.tcp_not_use_nodelay); + mca_btl_tcp_param_register_int( + "port_min_v4", "The minimum port where the TCP BTL will try to bind (default 1024)", 1024, + OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp_port_min); + + opal_asprintf(&message, + "The number of ports where the TCP BTL will try to bind (default %d)." + " This parameter together with the port min, define a range of ports" + " where Open MPI will open sockets.", + (0x1 << 16) - mca_btl_tcp_component.tcp_port_min - 1); + mca_btl_tcp_param_register_int("port_range_v4", message, + (0x1 << 16) - mca_btl_tcp_component.tcp_port_min - 1, + OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp_port_range); free(message); #if OPAL_ENABLE_IPV6 - mca_btl_tcp_param_register_int( "port_min_v6", - "The minimum port where the TCP BTL will try to bind (default 1024)", 1024, - OPAL_INFO_LVL_2, & mca_btl_tcp_component.tcp6_port_min ); - opal_asprintf( &message, - "The number of ports where the TCP BTL will try to bind (default %d)." - " This parameter together with the port min, define a range of ports" - " where Open MPI will open sockets.", - (0x1 << 16) - mca_btl_tcp_component.tcp6_port_min - 1 ); - mca_btl_tcp_param_register_int( "port_range_v6", message, - (0x1 << 16) - mca_btl_tcp_component.tcp6_port_min - 1, - OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp6_port_range ); + mca_btl_tcp_param_register_int( + "port_min_v6", "The minimum port where the TCP BTL will try to bind (default 1024)", 1024, + OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp6_port_min); + opal_asprintf(&message, + "The number of ports where the TCP BTL will try to bind (default %d)." + " This parameter together with the port min, define a range of ports" + " where Open MPI will open sockets.", + (0x1 << 16) - mca_btl_tcp_component.tcp6_port_min - 1); + mca_btl_tcp_param_register_int("port_range_v6", message, + (0x1 << 16) - mca_btl_tcp_component.tcp6_port_min - 1, + OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp6_port_range); free(message); #endif /* Check if we should support async progress */ - mca_btl_tcp_param_register_int ("progress_thread", NULL, 0, OPAL_INFO_LVL_1, - &mca_btl_tcp_component.tcp_enable_progress_thread); + mca_btl_tcp_param_register_int("progress_thread", NULL, 0, OPAL_INFO_LVL_1, + &mca_btl_tcp_component.tcp_enable_progress_thread); mca_btl_tcp_component.report_all_unfound_interfaces = false; - (void) mca_base_component_var_register(&mca_btl_tcp_component.super.btl_version, - "warn_all_unfound_interfaces", - "Issue a warning for all unfound interfaces included in if_exclude", - MCA_BASE_VAR_TYPE_BOOL, - NULL, 0, 0, OPAL_INFO_LVL_2, - MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_tcp_component.report_all_unfound_interfaces); - - mca_btl_tcp_module.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_LOW + 100; - mca_btl_tcp_module.super.btl_eager_limit = 64*1024; - mca_btl_tcp_module.super.btl_rndv_eager_limit = 64*1024; - mca_btl_tcp_module.super.btl_max_send_size = 128*1024; - mca_btl_tcp_module.super.btl_rdma_pipeline_send_length = 128*1024; + (void) mca_base_component_var_register( + &mca_btl_tcp_component.super.btl_version, "warn_all_unfound_interfaces", + "Issue a warning for all unfound interfaces included in if_exclude", MCA_BASE_VAR_TYPE_BOOL, + NULL, 0, 0, OPAL_INFO_LVL_2, MCA_BASE_VAR_SCOPE_READONLY, + &mca_btl_tcp_component.report_all_unfound_interfaces); + + mca_btl_tcp_module.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_LOW + 100; + mca_btl_tcp_module.super.btl_eager_limit = 64 * 1024; + mca_btl_tcp_module.super.btl_rndv_eager_limit = 64 * 1024; + mca_btl_tcp_module.super.btl_max_send_size = 128 * 1024; + mca_btl_tcp_module.super.btl_rdma_pipeline_send_length = 128 * 1024; /* Some OSes have hard coded limits on how many bytes can be manipulated * by each writev operation. Force a reasonable limit, to prevent overflowing * a signed 32-bit integer (limit comes from BSD and OS X). We remove 1k to * make some room for our internal headers. */ - mca_btl_tcp_module.super.btl_rdma_pipeline_frag_size = ((1UL<<31) - 1024); + mca_btl_tcp_module.super.btl_rdma_pipeline_frag_size = ((1UL << 31) - 1024); mca_btl_tcp_module.super.btl_min_rdma_pipeline_size = 0; - mca_btl_tcp_module.super.btl_flags = MCA_BTL_FLAGS_PUT | - MCA_BTL_FLAGS_SEND_INPLACE | - MCA_BTL_FLAGS_NEED_CSUM | - MCA_BTL_FLAGS_NEED_ACK | - MCA_BTL_FLAGS_HETEROGENEOUS_RDMA | - MCA_BTL_FLAGS_SEND; + mca_btl_tcp_module.super.btl_flags = MCA_BTL_FLAGS_PUT | MCA_BTL_FLAGS_SEND_INPLACE + | MCA_BTL_FLAGS_NEED_CSUM | MCA_BTL_FLAGS_NEED_ACK + | MCA_BTL_FLAGS_HETEROGENEOUS_RDMA | MCA_BTL_FLAGS_SEND; /* Bandwidth and latency initially set to 0. May be overridden during * mca_btl_tcp_create(). @@ -345,12 +340,13 @@ static int mca_btl_tcp_component_register(void) mca_btl_base_param_register(&mca_btl_tcp_component.super.btl_version, &mca_btl_tcp_module.super); - if (mca_btl_tcp_module.super.btl_rdma_pipeline_frag_size > ((1UL<<31) - 1024) ) { + if (mca_btl_tcp_module.super.btl_rdma_pipeline_frag_size > ((1UL << 31) - 1024)) { /* Assume a hard limit. A test in configure would be a better solution, but until then * kicking-in the pipeline RDMA for extremely large data is good enough. */ - mca_btl_tcp_module.super.btl_rdma_pipeline_frag_size = ((1UL<<31) - 1024); + mca_btl_tcp_module.super.btl_rdma_pipeline_frag_size = ((1UL << 31) - 1024); } - mca_btl_tcp_param_register_int ("disable_family", NULL, 0, OPAL_INFO_LVL_2, &mca_btl_tcp_component.tcp_disable_family); + mca_btl_tcp_param_register_int("disable_family", NULL, 0, OPAL_INFO_LVL_2, + &mca_btl_tcp_component.tcp_disable_family); return mca_btl_tcp_component_verify(); } @@ -387,14 +383,14 @@ static int mca_btl_tcp_component_open(void) OBJ_CONSTRUCT(&mca_btl_tcp_ready_frag_pending_queue, opal_list_t); /* if_include and if_exclude need to be mutually exclusive */ - if (OPAL_SUCCESS != - mca_base_var_check_exclusive("opal", - mca_btl_tcp_component.super.btl_version.mca_type_name, - mca_btl_tcp_component.super.btl_version.mca_component_name, - "if_include", - mca_btl_tcp_component.super.btl_version.mca_type_name, - mca_btl_tcp_component.super.btl_version.mca_component_name, - "if_exclude")) { + if (OPAL_SUCCESS + != mca_base_var_check_exclusive("opal", + mca_btl_tcp_component.super.btl_version.mca_type_name, + mca_btl_tcp_component.super.btl_version.mca_component_name, + "if_include", + mca_btl_tcp_component.super.btl_version.mca_type_name, + mca_btl_tcp_component.super.btl_version.mca_component_name, + "if_exclude")) { /* Return ERR_NOT_AVAILABLE so that a warning message about "open" failing is not printed */ return OPAL_ERR_NOT_AVAILABLE; @@ -403,7 +399,6 @@ static int mca_btl_tcp_component_open(void) return OPAL_SUCCESS; } - /* * module cleanup - sanity checking of queue lengths */ @@ -416,28 +411,27 @@ static int mca_btl_tcp_component_close(void) * If we have a progress thread we should shut it down before * moving forward with the TCP tearing down process. */ - if( (NULL != mca_btl_tcp_event_base) && - (mca_btl_tcp_event_base != opal_sync_event_base) ) { + if ((NULL != mca_btl_tcp_event_base) && (mca_btl_tcp_event_base != opal_sync_event_base)) { /* Turn of the progress thread before moving forward */ - if( -1 != mca_btl_tcp_progress_thread_trigger ) { - void* ret = NULL; /* not currently used */ + if (-1 != mca_btl_tcp_progress_thread_trigger) { + void *ret = NULL; /* not currently used */ mca_btl_tcp_progress_thread_trigger = 0; /* Let the progress thread know that we're going away */ - if( -1 != mca_btl_tcp_pipe_to_progress[1] ) { + if (-1 != mca_btl_tcp_pipe_to_progress[1]) { close(mca_btl_tcp_pipe_to_progress[1]); mca_btl_tcp_pipe_to_progress[1] = -1; } /* wait until the TCP progress thread completes */ opal_thread_join(&mca_btl_tcp_progress_thread, &ret); - assert( -1 == mca_btl_tcp_progress_thread_trigger ); + assert(-1 == mca_btl_tcp_progress_thread_trigger); } opal_event_del(&mca_btl_tcp_component.tcp_recv_thread_async_event); opal_event_base_free(mca_btl_tcp_event_base); mca_btl_tcp_event_base = NULL; /* Close the remaining pipes */ - if( -1 != mca_btl_tcp_pipe_to_progress[0] ) { + if (-1 != mca_btl_tcp_pipe_to_progress[0]) { close(mca_btl_tcp_pipe_to_progress[0]); mca_btl_tcp_pipe_to_progress[0] = -1; } @@ -468,12 +462,13 @@ static int mca_btl_tcp_component_close(void) /* remove all pending events. Do not lock the tcp_events list as the event themselves will unregister during the destructor. */ - OPAL_LIST_FOREACH_SAFE(event, next, &mca_btl_tcp_component.tcp_events, mca_btl_tcp_event_t) { + OPAL_LIST_FOREACH_SAFE (event, next, &mca_btl_tcp_component.tcp_events, mca_btl_tcp_event_t) { opal_event_del(&event->event); OBJ_RELEASE(event); } - opal_proc_table_remove_value(&mca_btl_tcp_component.tcp_procs, opal_proc_local_get()->proc_name); + opal_proc_table_remove_value(&mca_btl_tcp_component.tcp_procs, + opal_proc_local_get()->proc_name); /* release resources */ OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_procs); @@ -490,14 +485,13 @@ static int mca_btl_tcp_component_close(void) return OPAL_SUCCESS; } - /* * Create a btl instance and add to modules list. */ -static int mca_btl_tcp_create(const int if_kindex, const char* if_name) +static int mca_btl_tcp_create(const int if_kindex, const char *if_name) { - struct mca_btl_tcp_module_t* btl; + struct mca_btl_tcp_module_t *btl; opal_if_t *copied_interface, *selected_interface; char param[256]; int i, if_index; @@ -521,22 +515,20 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name) * 10.1.0.1 as the one that is published in the modex and used for * connection. */ - OPAL_LIST_FOREACH(selected_interface, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (selected_interface, &opal_if_list, opal_if_t) { if (if_kindex != selected_interface->if_kernel_index) { continue; } if_index = selected_interface->if_index; - memcpy((struct sockaddr*)&addr, &selected_interface->if_addr, + memcpy((struct sockaddr *) &addr, &selected_interface->if_addr, MIN(sizeof(struct sockaddr_storage), sizeof(selected_interface->if_addr))); - if (addr.ss_family == AF_INET && - 4 != mca_btl_tcp_component.tcp_disable_family) { + if (addr.ss_family == AF_INET && 4 != mca_btl_tcp_component.tcp_disable_family) { found = true; break; - } else if (addr.ss_family == AF_INET6 && - 6 != mca_btl_tcp_component.tcp_disable_family) { + } else if (addr.ss_family == AF_INET6 && 6 != mca_btl_tcp_component.tcp_disable_family) { found = true; break; } @@ -547,10 +539,11 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name) return OPAL_SUCCESS; } - for( i = 0; i < (int)mca_btl_tcp_component.tcp_num_links; i++ ) { - btl = (struct mca_btl_tcp_module_t *)malloc(sizeof(mca_btl_tcp_module_t)); - if(NULL == btl) + for (i = 0; i < (int) mca_btl_tcp_component.tcp_num_links; i++) { + btl = (struct mca_btl_tcp_module_t *) malloc(sizeof(mca_btl_tcp_module_t)); + if (NULL == btl) { return OPAL_ERR_OUT_OF_RESOURCE; + } copied_interface = OBJ_NEW(opal_if_t); if (NULL == copied_interface) { free(btl); @@ -576,23 +569,27 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name) /* allow user to specify interface bandwidth */ sprintf(param, "bandwidth_%s", if_name); - mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, &btl->super.btl_bandwidth); + mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, + &btl->super.btl_bandwidth); /* allow user to override/specify latency ranking */ sprintf(param, "latency_%s", if_name); - mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_latency, OPAL_INFO_LVL_5, &btl->super.btl_latency); - if( i > 0 ) { + mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_latency, OPAL_INFO_LVL_5, + &btl->super.btl_latency); + if (i > 0) { btl->super.btl_bandwidth >>= 1; - btl->super.btl_latency <<= 1; + btl->super.btl_latency <<= 1; } /* allow user to specify interface bandwidth */ sprintf(param, "bandwidth_%s:%d", if_name, i); - mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, &btl->super.btl_bandwidth); + mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, + &btl->super.btl_bandwidth); /* allow user to override/specify latency ranking */ sprintf(param, "latency_%s:%d", if_name, i); - mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_latency, OPAL_INFO_LVL_5, &btl->super.btl_latency); + mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_latency, OPAL_INFO_LVL_5, + &btl->super.btl_latency); /* Only attempt to auto-detect bandwidth and/or latency if it is 0. * @@ -624,15 +621,16 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name) memcpy(&copied_interface->if_addr, &btl->tcp_ifaddr, sizeof(struct sockaddr_storage)); copied_interface->if_mask = selected_interface->if_mask; copied_interface->if_bandwidth = btl->super.btl_bandwidth; - memcpy(&copied_interface->if_mac, &selected_interface->if_mac, sizeof(copied_interface->if_mac)); + memcpy(&copied_interface->if_mac, &selected_interface->if_mac, + sizeof(copied_interface->if_mac)); copied_interface->ifmtu = selected_interface->ifmtu; opal_list_append(&mca_btl_tcp_component.local_ifs, &(copied_interface->super)); opal_output_verbose(5, opal_btl_base_framework.framework_output, "btl:tcp: %p: if %s kidx %d cnt %i addr %s %s bw %d lt %d\n", - (void*)btl, if_name, (int) btl->tcp_ifkindex, i, - opal_net_get_hostname((struct sockaddr*)&btl->tcp_ifaddr), + (void *) btl, if_name, (int) btl->tcp_ifkindex, i, + opal_net_get_hostname((struct sockaddr *) &btl->tcp_ifaddr), (btl->tcp_ifaddr.ss_family == AF_INET) ? "IPv4" : "IPv6", btl->super.btl_bandwidth, btl->super.btl_latency); } @@ -673,9 +671,9 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd) tmp = strdup(argv[i]); str = strchr(argv[i], '/'); if (NULL == str) { - opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", - true, name, opal_process_info.nodename, - tmp, "Invalid specification (missing \"/\")"); + opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", true, name, + opal_process_info.nodename, tmp, + "Invalid specification (missing \"/\")"); free(argv[i]); free(tmp); continue; @@ -684,33 +682,26 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd) argv_prefix = atoi(str + 1); /* Now convert the IPv4 address */ - ((struct sockaddr*) &argv_inaddr)->sa_family = AF_INET; - ret = inet_pton(AF_INET, argv[i], - &((struct sockaddr_in*) &argv_inaddr)->sin_addr); + ((struct sockaddr *) &argv_inaddr)->sa_family = AF_INET; + ret = inet_pton(AF_INET, argv[i], &((struct sockaddr_in *) &argv_inaddr)->sin_addr); free(argv[i]); if (1 != ret) { - opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", - true, name, opal_process_info.nodename, tmp, + opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", true, name, + opal_process_info.nodename, tmp, "Invalid specification (inet_pton() failed)"); free(tmp); continue; } opal_output_verbose(20, opal_btl_base_framework.framework_output, - "btl: tcp: Searching for %s address+prefix: %s / %u", - name, - opal_net_get_hostname((struct sockaddr*) &argv_inaddr), - argv_prefix); + "btl: tcp: Searching for %s address+prefix: %s / %u", name, + opal_net_get_hostname((struct sockaddr *) &argv_inaddr), argv_prefix); /* Go through all interfaces and see if we can find a match */ - for (if_index = opal_ifbegin(); if_index >= 0; - if_index = opal_ifnext(if_index)) { - opal_ifindextoaddr(if_index, - (struct sockaddr*) &if_inaddr, - sizeof(if_inaddr)); - if (opal_net_samenetwork((struct sockaddr*) &argv_inaddr, - (struct sockaddr*) &if_inaddr, - argv_prefix)) { + for (if_index = opal_ifbegin(); if_index >= 0; if_index = opal_ifnext(if_index)) { + opal_ifindextoaddr(if_index, (struct sockaddr *) &if_inaddr, sizeof(if_inaddr)); + if (opal_net_samenetwork((struct sockaddr *) &argv_inaddr, + (struct sockaddr *) &if_inaddr, argv_prefix)) { break; } } @@ -718,8 +709,8 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd) /* If we didn't find a match, keep trying */ if (if_index < 0) { if (reqd || mca_btl_tcp_component.report_all_unfound_interfaces) { - opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", - true, name, opal_process_info.nodename, tmp, + opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", true, name, + opal_process_info.nodename, tmp, "Did not find interface matching this subnet"); } free(tmp); @@ -731,8 +722,7 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd) opal_ifindextoname(if_index, if_name, sizeof(if_name)); opal_output_verbose(20, opal_btl_base_framework.framework_output, "btl: tcp: Found match: %s (%s)", - opal_net_get_hostname((struct sockaddr*) &if_inaddr), - if_name); + opal_net_get_hostname((struct sockaddr *) &if_inaddr), if_name); argv[save++] = strdup(if_name); free(tmp); } @@ -745,7 +735,6 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd) return argv; } - /* * Create a TCP BTL instance for either: * (1) all interfaces specified by the user @@ -764,7 +753,7 @@ static int mca_btl_tcp_component_create_instances(void) char **argv; int ret = OPAL_SUCCESS; - if(if_count <= 0) { + if (if_count <= 0) { return OPAL_ERROR; } @@ -779,13 +768,13 @@ static int mca_btl_tcp_component_create_instances(void) /* initialize array to 0. Assumption: 0 isn't a valid kernel index */ - memset (kindexes, 0, sizeof(int) * if_count); + memset(kindexes, 0, sizeof(int) * if_count); /* assign the corresponding kernel indexes for all opal_list * indexes (loop over all addresses) */ - for(if_index = opal_ifbegin(); if_index >= 0; if_index = opal_ifnext(if_index)){ - int index = opal_ifindextokindex (if_index); + for (if_index = opal_ifbegin(); if_index >= 0; if_index = opal_ifnext(if_index)) { + int index = opal_ifindextokindex(if_index); if (index > 0) { bool want_this_if = true; @@ -806,9 +795,9 @@ static int mca_btl_tcp_component_create_instances(void) } /* allocate memory for btls */ - mca_btl_tcp_component.tcp_btls = (mca_btl_tcp_module_t**)malloc(mca_btl_tcp_component.tcp_num_links * - kif_count * sizeof(mca_btl_tcp_module_t*)); - if(NULL == mca_btl_tcp_component.tcp_btls) { + mca_btl_tcp_component.tcp_btls = (mca_btl_tcp_module_t **) malloc( + mca_btl_tcp_component.tcp_num_links * kif_count * sizeof(mca_btl_tcp_module_t *)); + if (NULL == mca_btl_tcp_component.tcp_btls) { ret = OPAL_ERR_OUT_OF_RESOURCE; goto cleanup; } @@ -816,15 +805,13 @@ static int mca_btl_tcp_component_create_instances(void) mca_btl_tcp_component.tcp_addr_count = if_count; /* if the user specified an interface list - use these exclusively */ - argv = include = split_and_resolve(&mca_btl_tcp_component.tcp_if_include, - "include", true); - while(argv && *argv) { - char* if_name = *argv; + argv = include = split_and_resolve(&mca_btl_tcp_component.tcp_if_include, "include", true); + while (argv && *argv) { + char *if_name = *argv; int if_index = opal_ifnametokindex(if_name); - if(if_index < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", - true, "include", opal_process_info.nodename, - if_name, "Unknown interface name"); + if (if_index < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude", true, "include", + opal_process_info.nodename, if_name, "Unknown interface name"); ret = OPAL_ERR_NOT_FOUND; goto cleanup; } @@ -841,12 +828,11 @@ static int mca_btl_tcp_component_create_instances(void) /* if the interface list was not specified by the user, create * a BTL for each interface that was not excluded. - */ - exclude = split_and_resolve(&mca_btl_tcp_component.tcp_if_exclude, - "exclude", false); + */ + exclude = split_and_resolve(&mca_btl_tcp_component.tcp_if_exclude, "exclude", false); { int i; - for(i = 0; i < kif_count; i++) { + for (i = 0; i < kif_count; i++) { /* OPAL_IF_NAMESIZE is defined in opal/util/if.h */ char if_name[OPAL_IF_NAMESIZE]; if_index = kindexes[i]; @@ -855,19 +841,20 @@ static int mca_btl_tcp_component_create_instances(void) /* check to see if this interface exists in the exclude list */ argv = exclude; - while(argv && *argv) { - if(strncmp(*argv,if_name,strlen(*argv)) == 0) + while (argv && *argv) { + if (strncmp(*argv, if_name, strlen(*argv)) == 0) { break; + } argv++; } /* if this interface was not found in the excluded list, create a BTL */ - if(argv == 0 || *argv == 0) { + if (argv == 0 || *argv == 0) { mca_btl_tcp_create(if_index, if_name); } } } - cleanup: +cleanup: if (NULL != include) { opal_argv_free(include); } @@ -880,28 +867,28 @@ static int mca_btl_tcp_component_create_instances(void) return ret; } -static void* mca_btl_tcp_progress_thread_engine(opal_object_t *obj) +static void *mca_btl_tcp_progress_thread_engine(opal_object_t *obj) { - opal_thread_t* current_thread = (opal_thread_t*)obj; + opal_thread_t *current_thread = (opal_thread_t *) obj; - while( 1 == (*((int*)current_thread->t_arg)) ) { + while (1 == (*((int *) current_thread->t_arg))) { opal_event_loop(mca_btl_tcp_event_base, OPAL_EVLOOP_ONCE); } - (*((int*)current_thread->t_arg)) = -1; + (*((int *) current_thread->t_arg)) = -1; return NULL; } static void mca_btl_tcp_component_event_async_handler(int fd, short unused, void *context) { - opal_event_t* event; + opal_event_t *event; int rc; - rc = read(fd, (void*)&event, sizeof(opal_event_t*)); - assert( fd == mca_btl_tcp_pipe_to_progress[0] ); - if( 0 == rc ) { + rc = read(fd, (void *) &event, sizeof(opal_event_t *)); + assert(fd == mca_btl_tcp_pipe_to_progress[0]); + if (0 == rc) { /* The main thread closed the pipe to trigger the shutdown procedure */ - opal_thread_t* current_thread = (opal_thread_t*)context; - (*((int*)current_thread->t_arg)) = 0; + opal_thread_t *current_thread = (opal_thread_t *) context; + (*((int *) current_thread->t_arg)) = 0; } else { opal_event_add(event, 0); } @@ -919,10 +906,9 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) /* create a listen socket for incoming connections */ sd = socket(af_family, SOCK_STREAM, 0); - if(sd < 0) { + if (sd < 0) { if (EAFNOSUPPORT != opal_socket_errno) { - BTL_ERROR(("socket() failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + BTL_ERROR(("socket() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); } return OPAL_ERR_IN_ERRNO; } @@ -933,24 +919,22 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) { struct addrinfo hints, *res = NULL; - memset (&hints, 0, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); hints.ai_family = af_family; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if ((rc = getaddrinfo(NULL, "0", &hints, &res))) { - opal_output (0, - "mca_btl_tcp_create_listen: unable to resolve. %s\n", - gai_strerror (rc)); + opal_output(0, "mca_btl_tcp_create_listen: unable to resolve. %s\n", gai_strerror(rc)); CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } - memcpy (&inaddr, res->ai_addr, res->ai_addrlen); + memcpy(&inaddr, res->ai_addr, res->ai_addrlen); addrlen = res->ai_addrlen; - freeaddrinfo (res); + freeaddrinfo(res); -#ifdef IPV6_V6ONLY +# ifdef IPV6_V6ONLY /* If this OS supports the "IPV6_V6ONLY" constant, then set it on this socket. It specifies that *only* V6 connections should be accepted on this socket (vs. allowing incoming @@ -960,22 +944,21 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) more details. */ if (AF_INET6 == af_family) { int flg = 1; - if (setsockopt (sd, IPPROTO_IPV6, IPV6_V6ONLY, - (char *) &flg, sizeof (flg)) < 0) { + if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &flg, sizeof(flg)) < 0) { BTL_ERROR(("mca_btl_tcp_create_listen: unable to set IPV6_V6ONLY\n")); } } -#endif /* IPV6_V6ONLY */ +# endif /* IPV6_V6ONLY */ } #else - ((struct sockaddr_in*) &inaddr)->sin_family = AF_INET; - ((struct sockaddr_in*) &inaddr)->sin_addr.s_addr = INADDR_ANY; + ((struct sockaddr_in *) &inaddr)->sin_family = AF_INET; + ((struct sockaddr_in *) &inaddr)->sin_addr.s_addr = INADDR_ANY; addrlen = sizeof(struct sockaddr_in); #endif - { /* Don't reuse ports */ + { /* Don't reuse ports */ int flg = 0; - if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR, (const char *)&flg, sizeof (flg)) < 0) { + if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const char *) &flg, sizeof(flg)) < 0) { BTL_ERROR(("mca_btl_tcp_create_listen: unable to unset the " "SO_REUSEADDR option (%s:%d)\n", strerror(opal_socket_errno), opal_socket_errno)); @@ -992,35 +975,33 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) range = mca_btl_tcp_component.tcp6_port_range; port = mca_btl_tcp_component.tcp6_port_min; } else -#endif /* OPAL_ENABLE_IPV6 */ +#endif /* OPAL_ENABLE_IPV6 */ { range = mca_btl_tcp_component.tcp_port_range; port = mca_btl_tcp_component.tcp_port_min; } - for( index = 0; index < range; index++ ) { + for (index = 0; index < range; index++) { #if OPAL_ENABLE_IPV6 - ((struct sockaddr_in6*) &inaddr)->sin6_port = htons(port + index); + ((struct sockaddr_in6 *) &inaddr)->sin6_port = htons(port + index); #else - ((struct sockaddr_in*) &inaddr)->sin_port = htons(port + index); -#endif /* OPAL_ENABLE_IPV6 */ + ((struct sockaddr_in *) &inaddr)->sin_port = htons(port + index); +#endif /* OPAL_ENABLE_IPV6 */ opal_output_verbose(30, opal_btl_base_framework.framework_output, "btl:tcp: Attempting to bind to %s port %d", - (AF_INET == af_family) ? "AF_INET" : "AF_INET6", - port + index); - if(bind(sd, (struct sockaddr*)&inaddr, addrlen) < 0) { - if( (EADDRINUSE == opal_socket_errno) || (EADDRNOTAVAIL == opal_socket_errno) ) { + (AF_INET == af_family) ? "AF_INET" : "AF_INET6", port + index); + if (bind(sd, (struct sockaddr *) &inaddr, addrlen) < 0) { + if ((EADDRINUSE == opal_socket_errno) || (EADDRNOTAVAIL == opal_socket_errno)) { continue; } - BTL_ERROR(("bind() failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + BTL_ERROR( + ("bind() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } opal_output_verbose(30, opal_btl_base_framework.framework_output, "btl:tcp: Successfully bound to %s port %d", - (AF_INET == af_family) ? "AF_INET" : "AF_INET6", - port + index); + (AF_INET == af_family) ? "AF_INET" : "AF_INET6", port + index); goto socket_binded; } #if OPAL_ENABLE_IPV6 @@ -1029,7 +1010,7 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) mca_btl_tcp_component.tcp6_port_min, mca_btl_tcp_component.tcp6_port_min + range)); } else -#endif /* OPAL_ENABLE_IPV6 */ +#endif /* OPAL_ENABLE_IPV6 */ { BTL_ERROR(("bind() failed: no port available in the range [%d..%d]", mca_btl_tcp_component.tcp_port_min, @@ -1038,18 +1019,18 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } - socket_binded: +socket_binded: /* resolve system assignend port */ - if(getsockname(sd, (struct sockaddr*)&inaddr, &addrlen) < 0) { - BTL_ERROR(("getsockname() failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (getsockname(sd, (struct sockaddr *) &inaddr, &addrlen) < 0) { + BTL_ERROR( + ("getsockname() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } #if OPAL_ENABLE_IPV6 if (AF_INET6 == af_family) { - mca_btl_tcp_component.tcp6_listen_port = ((struct sockaddr_in6*) &inaddr)->sin6_port; + mca_btl_tcp_component.tcp6_listen_port = ((struct sockaddr_in6 *) &inaddr)->sin6_port; mca_btl_tcp_component.tcp6_listen_sd = sd; opal_output_verbose(30, opal_btl_base_framework.framework_output, "btl:tcp: my listening v6 socket port is %d", @@ -1058,50 +1039,47 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) #endif { char str[16]; - mca_btl_tcp_component.tcp_listen_port = ((struct sockaddr_in*) &inaddr)->sin_port; + mca_btl_tcp_component.tcp_listen_port = ((struct sockaddr_in *) &inaddr)->sin_port; mca_btl_tcp_component.tcp_listen_sd = sd; - inet_ntop(AF_INET, &(((struct sockaddr_in*)&inaddr)->sin_addr), str, sizeof(str)); + inet_ntop(AF_INET, &(((struct sockaddr_in *) &inaddr)->sin_addr), str, sizeof(str)); opal_output_verbose(30, opal_btl_base_framework.framework_output, - "btl:tcp: my listening v4 socket is %s:%u", - str, ntohs(mca_btl_tcp_component.tcp_listen_port)); + "btl:tcp: my listening v4 socket is %s:%u", str, + ntohs(mca_btl_tcp_component.tcp_listen_port)); } /* setup listen backlog to maximum allowed by kernel */ - if(listen(sd, SOMAXCONN) < 0) { - BTL_ERROR(("listen() failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (listen(sd, SOMAXCONN) < 0) { + BTL_ERROR(("listen() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } /* set socket up to be non-blocking, otherwise accept could block */ - if((flags = fcntl(sd, F_GETFL, 0)) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), "fcntl(sd, F_GETFL, 0)", - strerror(opal_socket_errno), opal_socket_errno); + if ((flags = fcntl(sd, F_GETFL, 0)) < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, opal_process_info.nodename, + getpid(), "fcntl(sd, F_GETFL, 0)", strerror(opal_socket_errno), + opal_socket_errno); CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } else { flags |= O_NONBLOCK; - if(fcntl(sd, F_SETFL, flags) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), - "fcntl(sd, F_SETFL, flags & O_NONBLOCK)", - strerror(opal_socket_errno), opal_socket_errno); + if (fcntl(sd, F_SETFL, flags) < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, + opal_process_info.nodename, getpid(), + "fcntl(sd, F_SETFL, flags & O_NONBLOCK)", strerror(opal_socket_errno), + opal_socket_errno); CLOSE_THE_SOCKET(sd); return OPAL_ERROR; } } - if(mca_btl_tcp_component.tcp_enable_progress_thread){ + if (mca_btl_tcp_component.tcp_enable_progress_thread) { /* Declare our intent to use threads. */ opal_event_use_threads(); - if( NULL == mca_btl_tcp_event_base ) { + if (NULL == mca_btl_tcp_event_base) { /* fall back to only one event base (the one shared by the entire Open MPI framework) */ - if( NULL == (mca_btl_tcp_event_base = opal_event_base_create()) ) { + if (NULL == (mca_btl_tcp_event_base = opal_event_base_create())) { BTL_ERROR(("BTL TCP failed to create progress event base")); goto move_forward_with_no_thread; } @@ -1115,65 +1093,62 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) */ if (0 != pipe(mca_btl_tcp_pipe_to_progress)) { opal_event_base_free(mca_btl_tcp_event_base); - /* fall back to only one event base (the one shared by the entire Open MPI framework */ + /* fall back to only one event base (the one shared by the entire Open MPI framework + */ mca_btl_tcp_event_base = opal_sync_event_base; - mca_btl_tcp_progress_thread_trigger = -1; /* thread not started */ + mca_btl_tcp_progress_thread_trigger = -1; /* thread not started */ goto move_forward_with_no_thread; } /* setup the receiving end of the pipe as non-blocking */ - if((flags = fcntl(mca_btl_tcp_pipe_to_progress[0], F_GETFL, 0)) < 0) { - BTL_ERROR(("fcntl(F_GETFL) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if ((flags = fcntl(mca_btl_tcp_pipe_to_progress[0], F_GETFL, 0)) < 0) { + BTL_ERROR(("fcntl(F_GETFL) failed: %s (%d)", strerror(opal_socket_errno), + opal_socket_errno)); } else { flags |= O_NONBLOCK; - if(fcntl(mca_btl_tcp_pipe_to_progress[0], F_SETFL, flags) < 0) - BTL_ERROR(("fcntl(F_SETFL) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (fcntl(mca_btl_tcp_pipe_to_progress[0], F_SETFL, flags) < 0) + BTL_ERROR(("fcntl(F_SETFL) failed: %s (%d)", strerror(opal_socket_errno), + opal_socket_errno)); } /* Progress thread event */ - opal_event_set(mca_btl_tcp_event_base, &mca_btl_tcp_component.tcp_recv_thread_async_event, - mca_btl_tcp_pipe_to_progress[0], - OPAL_EV_READ|OPAL_EV_PERSIST, - mca_btl_tcp_component_event_async_handler, - &mca_btl_tcp_progress_thread ); + opal_event_set(mca_btl_tcp_event_base, + &mca_btl_tcp_component.tcp_recv_thread_async_event, + mca_btl_tcp_pipe_to_progress[0], OPAL_EV_READ | OPAL_EV_PERSIST, + mca_btl_tcp_component_event_async_handler, &mca_btl_tcp_progress_thread); opal_event_add(&mca_btl_tcp_component.tcp_recv_thread_async_event, 0); /* fork off a thread to progress it */ mca_btl_tcp_progress_thread.t_run = mca_btl_tcp_progress_thread_engine; mca_btl_tcp_progress_thread.t_arg = &mca_btl_tcp_progress_thread_trigger; - mca_btl_tcp_progress_thread_trigger = 1; /* thread up and running */ - if( OPAL_SUCCESS != (rc = opal_thread_start(&mca_btl_tcp_progress_thread)) ) { + mca_btl_tcp_progress_thread_trigger = 1; /* thread up and running */ + if (OPAL_SUCCESS != (rc = opal_thread_start(&mca_btl_tcp_progress_thread))) { BTL_ERROR(("BTL TCP progress thread initialization failed (%d)", rc)); opal_event_base_free(mca_btl_tcp_event_base); - /* fall back to only one event base (the one shared by the entire Open MPI framework */ + /* fall back to only one event base (the one shared by the entire Open MPI framework + */ mca_btl_tcp_event_base = opal_sync_event_base; - mca_btl_tcp_progress_thread_trigger = -1; /* thread not started */ + mca_btl_tcp_progress_thread_trigger = -1; /* thread not started */ goto move_forward_with_no_thread; } - /* We have async progress, the rest of the library should now protect itself against races */ + /* We have async progress, the rest of the library should now protect itself against + * races */ opal_set_using_threads(true); } - } - else { - move_forward_with_no_thread: - mca_btl_tcp_event_base = opal_sync_event_base; + } else { + move_forward_with_no_thread: + mca_btl_tcp_event_base = opal_sync_event_base; } if (AF_INET == af_family) { opal_event_set(mca_btl_tcp_event_base, &mca_btl_tcp_component.tcp_recv_event, - mca_btl_tcp_component.tcp_listen_sd, - OPAL_EV_READ|OPAL_EV_PERSIST, - mca_btl_tcp_component_accept_handler, - 0 ); + mca_btl_tcp_component.tcp_listen_sd, OPAL_EV_READ | OPAL_EV_PERSIST, + mca_btl_tcp_component_accept_handler, 0); MCA_BTL_TCP_ACTIVATE_EVENT(&mca_btl_tcp_component.tcp_recv_event, 0); } #if OPAL_ENABLE_IPV6 if (AF_INET6 == af_family) { opal_event_set(mca_btl_tcp_event_base, &mca_btl_tcp_component.tcp6_recv_event, - mca_btl_tcp_component.tcp6_listen_sd, - OPAL_EV_READ|OPAL_EV_PERSIST, - mca_btl_tcp_component_accept_handler, - 0 ); + mca_btl_tcp_component.tcp6_listen_sd, OPAL_EV_READ | OPAL_EV_PERSIST, + mca_btl_tcp_component_accept_handler, 0); MCA_BTL_TCP_ACTIVATE_EVENT(&mca_btl_tcp_component.tcp6_recv_event, 0); } #endif @@ -1187,68 +1162,62 @@ static int mca_btl_tcp_component_create_listen(uint16_t af_family) static int mca_btl_tcp_component_exchange(void) { - int rc; - size_t i; - size_t num_btls = mca_btl_tcp_component.tcp_num_btls; - size_t size = num_btls * sizeof(mca_btl_tcp_modex_addr_t); - mca_btl_tcp_modex_addr_t *addrs; - - if (num_btls <= 0) { - return 0; - } - - addrs = (mca_btl_tcp_modex_addr_t*)malloc(size); - if (NULL == addrs) { - return OPAL_ERR_OUT_OF_RESOURCE; - } - memset(addrs, 0, size); - - for (i = 0 ; i < num_btls ; i++) { - struct mca_btl_tcp_module_t *btl = mca_btl_tcp_component.tcp_btls[i]; - struct sockaddr *addr = (struct sockaddr*)&(btl->tcp_ifaddr); + int rc; + size_t i; + size_t num_btls = mca_btl_tcp_component.tcp_num_btls; + size_t size = num_btls * sizeof(mca_btl_tcp_modex_addr_t); + mca_btl_tcp_modex_addr_t *addrs; + + if (num_btls <= 0) { + return 0; + } + + addrs = (mca_btl_tcp_modex_addr_t *) malloc(size); + if (NULL == addrs) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + memset(addrs, 0, size); + + for (i = 0; i < num_btls; i++) { + struct mca_btl_tcp_module_t *btl = mca_btl_tcp_component.tcp_btls[i]; + struct sockaddr *addr = (struct sockaddr *) &(btl->tcp_ifaddr); #if OPAL_ENABLE_IPV6 - if (AF_INET6 == addr->sa_family) { - struct sockaddr_in6 *inaddr6 = (struct sockaddr_in6*)addr; - - memcpy(&addrs[i].addr, &(inaddr6->sin6_addr), - sizeof(struct in6_addr)); - addrs[i].addr_port = mca_btl_tcp_component.tcp6_listen_port; - addrs[i].addr_family = MCA_BTL_TCP_AF_INET6; - opal_output_verbose(5, opal_btl_base_framework.framework_output, - "btl: tcp: exchange: %d %d IPv6 %s", - (int)i, btl->tcp_ifkindex, - opal_net_get_hostname(addr)); - } else + if (AF_INET6 == addr->sa_family) { + struct sockaddr_in6 *inaddr6 = (struct sockaddr_in6 *) addr; + + memcpy(&addrs[i].addr, &(inaddr6->sin6_addr), sizeof(struct in6_addr)); + addrs[i].addr_port = mca_btl_tcp_component.tcp6_listen_port; + addrs[i].addr_family = MCA_BTL_TCP_AF_INET6; + opal_output_verbose(5, opal_btl_base_framework.framework_output, + "btl: tcp: exchange: %d %d IPv6 %s", (int) i, btl->tcp_ifkindex, + opal_net_get_hostname(addr)); + } else #endif - if (AF_INET == addr->sa_family) { - struct sockaddr_in *inaddr = (struct sockaddr_in*)addr; - - memcpy(&addrs[i].addr, &(inaddr->sin_addr), - sizeof(struct in_addr)); - addrs[i].addr_port = mca_btl_tcp_component.tcp_listen_port; - addrs[i].addr_family = MCA_BTL_TCP_AF_INET; - opal_output_verbose(5, opal_btl_base_framework.framework_output, - "btl: tcp: exchange: %d %d IPv4 %s", - (int)i, btl->tcp_ifkindex, - opal_net_get_hostname(addr)); - } else { - BTL_ERROR(("Unexpected address family: %d", addr->sa_family)); - free(addrs); - return OPAL_ERR_BAD_PARAM; - } - - addrs[i].addr_ifkindex = btl->tcp_ifkindex; - addrs[i].addr_mask = btl->tcp_ifmask; - addrs[i].addr_bandwidth = btl->super.btl_bandwidth; - } - - OPAL_MODEX_SEND(rc, PMIX_GLOBAL, - &mca_btl_tcp_component.super.btl_version, - addrs, size); - free(addrs); - - return rc; + if (AF_INET == addr->sa_family) { + struct sockaddr_in *inaddr = (struct sockaddr_in *) addr; + + memcpy(&addrs[i].addr, &(inaddr->sin_addr), sizeof(struct in_addr)); + addrs[i].addr_port = mca_btl_tcp_component.tcp_listen_port; + addrs[i].addr_family = MCA_BTL_TCP_AF_INET; + opal_output_verbose(5, opal_btl_base_framework.framework_output, + "btl: tcp: exchange: %d %d IPv4 %s", (int) i, btl->tcp_ifkindex, + opal_net_get_hostname(addr)); + } else { + BTL_ERROR(("Unexpected address family: %d", addr->sa_family)); + free(addrs); + return OPAL_ERR_BAD_PARAM; + } + + addrs[i].addr_ifkindex = btl->tcp_ifkindex; + addrs[i].addr_mask = btl->tcp_ifmask; + addrs[i].addr_bandwidth = btl->super.btl_bandwidth; + } + + OPAL_MODEX_SEND(rc, PMIX_GLOBAL, &mca_btl_tcp_component.super.btl_version, addrs, size); + free(addrs); + + return rc; } /* @@ -1258,7 +1227,7 @@ static int mca_btl_tcp_component_exchange(void) * (2) setup TCP listen socket for incoming connection attempts * (3) register BTL parameters with the MCA */ -mca_btl_base_module_t** mca_btl_tcp_component_init(int *num_btl_modules, +mca_btl_base_module_t **mca_btl_tcp_component_init(int *num_btl_modules, bool enable_progress_threads, bool enable_mpi_threads) { @@ -1268,71 +1237,59 @@ mca_btl_base_module_t** mca_btl_tcp_component_init(int *num_btl_modules, *num_btl_modules = 0; /* initialize free lists */ - opal_free_list_init( &mca_btl_tcp_component.tcp_frag_eager, - sizeof (mca_btl_tcp_frag_eager_t) + - mca_btl_tcp_module.super.btl_eager_limit, - opal_cache_line_size, - OBJ_CLASS (mca_btl_tcp_frag_eager_t), - 0,opal_cache_line_size, - mca_btl_tcp_component.tcp_free_list_num, - mca_btl_tcp_component.tcp_free_list_max, - mca_btl_tcp_component.tcp_free_list_inc, - NULL, 0, NULL, NULL, NULL ); - - opal_free_list_init( &mca_btl_tcp_component.tcp_frag_max, - sizeof (mca_btl_tcp_frag_max_t) + - mca_btl_tcp_module.super.btl_max_send_size, - opal_cache_line_size, - OBJ_CLASS (mca_btl_tcp_frag_max_t), - 0,opal_cache_line_size, - mca_btl_tcp_component.tcp_free_list_num, - mca_btl_tcp_component.tcp_free_list_max, - mca_btl_tcp_component.tcp_free_list_inc, - NULL, 0, NULL, NULL, NULL ); - - opal_free_list_init( &mca_btl_tcp_component.tcp_frag_user, - sizeof (mca_btl_tcp_frag_user_t), - opal_cache_line_size, - OBJ_CLASS (mca_btl_tcp_frag_user_t), - 0,opal_cache_line_size, - mca_btl_tcp_component.tcp_free_list_num, - mca_btl_tcp_component.tcp_free_list_max, - mca_btl_tcp_component.tcp_free_list_inc, - NULL, 0, NULL, NULL, NULL ); + opal_free_list_init(&mca_btl_tcp_component.tcp_frag_eager, + sizeof(mca_btl_tcp_frag_eager_t) + mca_btl_tcp_module.super.btl_eager_limit, + opal_cache_line_size, OBJ_CLASS(mca_btl_tcp_frag_eager_t), 0, + opal_cache_line_size, mca_btl_tcp_component.tcp_free_list_num, + mca_btl_tcp_component.tcp_free_list_max, + mca_btl_tcp_component.tcp_free_list_inc, NULL, 0, NULL, NULL, NULL); + + opal_free_list_init(&mca_btl_tcp_component.tcp_frag_max, + sizeof(mca_btl_tcp_frag_max_t) + mca_btl_tcp_module.super.btl_max_send_size, + opal_cache_line_size, OBJ_CLASS(mca_btl_tcp_frag_max_t), 0, + opal_cache_line_size, mca_btl_tcp_component.tcp_free_list_num, + mca_btl_tcp_component.tcp_free_list_max, + mca_btl_tcp_component.tcp_free_list_inc, NULL, 0, NULL, NULL, NULL); + + opal_free_list_init(&mca_btl_tcp_component.tcp_frag_user, sizeof(mca_btl_tcp_frag_user_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_tcp_frag_user_t), 0, + opal_cache_line_size, mca_btl_tcp_component.tcp_free_list_num, + mca_btl_tcp_component.tcp_free_list_max, + mca_btl_tcp_component.tcp_free_list_inc, NULL, 0, NULL, NULL, NULL); /* create a BTL TCP module for selected interfaces */ - if(OPAL_SUCCESS != (ret = mca_btl_tcp_component_create_instances() )) { + if (OPAL_SUCCESS != (ret = mca_btl_tcp_component_create_instances())) { return 0; } /* create a TCP listen socket for incoming connection attempts */ - if(OPAL_SUCCESS != (ret = mca_btl_tcp_component_create_listen(AF_INET) )) { + if (OPAL_SUCCESS != (ret = mca_btl_tcp_component_create_listen(AF_INET))) { return 0; } #if OPAL_ENABLE_IPV6 - if((ret = mca_btl_tcp_component_create_listen(AF_INET6)) != OPAL_SUCCESS) { - if (!(OPAL_ERR_IN_ERRNO == ret && - EAFNOSUPPORT == opal_socket_errno)) { - opal_output (0, "mca_btl_tcp_component: IPv6 listening socket failed\n"); + if ((ret = mca_btl_tcp_component_create_listen(AF_INET6)) != OPAL_SUCCESS) { + if (!(OPAL_ERR_IN_ERRNO == ret && EAFNOSUPPORT == opal_socket_errno)) { + opal_output(0, "mca_btl_tcp_component: IPv6 listening socket failed\n"); return 0; } } #endif /* publish TCP parameters with the MCA framework */ - if(OPAL_SUCCESS != (ret = mca_btl_tcp_component_exchange() )) { + if (OPAL_SUCCESS != (ret = mca_btl_tcp_component_exchange())) { return 0; } - btls = (mca_btl_base_module_t **)malloc(mca_btl_tcp_component.tcp_num_btls * - sizeof(mca_btl_base_module_t*)); - if(NULL == btls) { + btls = (mca_btl_base_module_t **) malloc(mca_btl_tcp_component.tcp_num_btls + * sizeof(mca_btl_base_module_t *)); + if (NULL == btls) { return NULL; } /* Register the btl to support the progress_thread */ if (0 < mca_btl_tcp_progress_thread_trigger) { - for( i = 0; i < mca_btl_tcp_component.tcp_num_btls; i++) { - mca_btl_tcp_component.tcp_btls[i]->super.btl_flags |= MCA_BTL_FLAGS_BTL_PROGRESS_THREAD_ENABLED; + for (i = 0; i < mca_btl_tcp_component.tcp_num_btls; i++) { + mca_btl_tcp_component.tcp_btls[i]->super.btl_flags + |= MCA_BTL_FLAGS_BTL_PROGRESS_THREAD_ENABLED; } } @@ -1347,9 +1304,9 @@ mca_btl_base_module_t** mca_btl_tcp_component_init(int *num_btl_modules, isn't a proper fix, but will solve the "dropped connection" problem until we can come up with a more complete fix to how we initialize procs, endpoints, and modules in the TCP BTL. */ - if (mca_btl_tcp_component.tcp_num_btls > 1 && - (enable_mpi_threads || 0 < mca_btl_tcp_progress_thread_trigger)) { - for( i = 0; i < mca_btl_tcp_component.tcp_num_btls; i++) { + if (mca_btl_tcp_component.tcp_num_btls > 1 + && (enable_mpi_threads || 0 < mca_btl_tcp_progress_thread_trigger)) { + for (i = 0; i < mca_btl_tcp_component.tcp_num_btls; i++) { mca_btl_tcp_component.tcp_btls[i]->super.btl_flags |= MCA_BTL_FLAGS_SINGLE_ADD_PROCS; } } @@ -1358,22 +1315,20 @@ mca_btl_base_module_t** mca_btl_tcp_component_init(int *num_btl_modules, mca_common_cuda_stage_one_init(); #endif /* OPAL_CUDA_SUPPORT */ - memcpy(btls, mca_btl_tcp_component.tcp_btls, mca_btl_tcp_component.tcp_num_btls*sizeof(mca_btl_tcp_module_t*)); + memcpy(btls, mca_btl_tcp_component.tcp_btls, + mca_btl_tcp_component.tcp_num_btls * sizeof(mca_btl_tcp_module_t *)); *num_btl_modules = mca_btl_tcp_component.tcp_num_btls; return btls; } - /** * Called by the event engine when the listening socket has * a connection event. Accept the incoming connection request * and queue them for completion of the connection handshake. */ -static void mca_btl_tcp_component_accept_handler( int incoming_sd, - short ignored, - void* unused ) +static void mca_btl_tcp_component_accept_handler(int incoming_sd, short ignored, void *unused) { - while(true) { + while (true) { #if OPAL_ENABLE_IPV6 struct sockaddr_in6 addr; #else @@ -1382,45 +1337,42 @@ static void mca_btl_tcp_component_accept_handler( int incoming_sd, opal_socklen_t addrlen = sizeof(addr); mca_btl_tcp_event_t *event; - int sd = accept(incoming_sd, (struct sockaddr*)&addr, &addrlen); - if(sd < 0) { - if(opal_socket_errno == EINTR) + int sd = accept(incoming_sd, (struct sockaddr *) &addr, &addrlen); + if (sd < 0) { + if (opal_socket_errno == EINTR) { continue; - if (opal_socket_errno != EAGAIN && - opal_socket_errno != EWOULDBLOCK) { - opal_show_help("help-mpi-btl-tcp.txt", "accept failed", - true, opal_process_info.nodename, - getpid(), - opal_socket_errno, + } + if (opal_socket_errno != EAGAIN && opal_socket_errno != EWOULDBLOCK) { + opal_show_help("help-mpi-btl-tcp.txt", "accept failed", true, + opal_process_info.nodename, getpid(), opal_socket_errno, strerror(opal_socket_errno)); } return; } mca_btl_tcp_set_socket_options(sd); - assert( NULL != mca_btl_tcp_event_base ); + assert(NULL != mca_btl_tcp_event_base); /* wait for receipt of peers process identifier to complete this connection */ event = OBJ_NEW(mca_btl_tcp_event_t); - opal_event_set(mca_btl_tcp_event_base, &(event->event), sd, - OPAL_EV_READ, mca_btl_tcp_component_recv_handler, event); + opal_event_set(mca_btl_tcp_event_base, &(event->event), sd, OPAL_EV_READ, + mca_btl_tcp_component_recv_handler, event); opal_event_add(&event->event, 0); } } - /** * Event callback when there is data available on the registered * socket to recv. This callback is triggered only once per lifetime * for any socket, in the beginning when we setup the handshake * protocol. */ -static void mca_btl_tcp_component_recv_handler(int sd, short flags, void* user) +static void mca_btl_tcp_component_recv_handler(int sd, short flags, void *user) { - mca_btl_tcp_event_t *event = (mca_btl_tcp_event_t *)user; + mca_btl_tcp_event_t *event = (mca_btl_tcp_event_t *) user; opal_process_name_t guid; struct sockaddr_storage addr; opal_socklen_t addr_len = sizeof(addr); - mca_btl_tcp_proc_t* btl_proc; + mca_btl_tcp_proc_t *btl_proc; bool sockopt = true; size_t retval, len = strlen(mca_btl_tcp_magic_id_string); mca_btl_tcp_endpoint_hs_msg_t hs_msg; @@ -1434,13 +1386,12 @@ static void mca_btl_tcp_component_recv_handler(int sd, short flags, void* user) */ /* get the current timeout value so we can reset to it */ - if (0 != getsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (void*)&save, &rcvtimeo_save_len)) { + if (0 != getsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (void *) &save, &rcvtimeo_save_len)) { if (ENOPROTOOPT == errno || EOPNOTSUPP == errno) { sockopt = false; } else { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, + opal_process_info.nodename, getpid(), "getsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, ...)", strerror(opal_socket_errno), opal_socket_errno); return; @@ -1449,17 +1400,16 @@ static void mca_btl_tcp_component_recv_handler(int sd, short flags, void* user) tv.tv_sec = 2; tv.tv_usec = 0; if (0 != setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, + opal_process_info.nodename, getpid(), "setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, ...)", strerror(opal_socket_errno), opal_socket_errno); - return; - } + return; + } } OBJ_RELEASE(event); - retval = mca_btl_tcp_recv_blocking(sd, (void *)&hs_msg, sizeof(hs_msg)); + retval = mca_btl_tcp_recv_blocking(sd, (void *) &hs_msg, sizeof(hs_msg)); /* If we get a zero-length message back, it's likely that we connected to Open MPI peer process X simultaneously, and the @@ -1471,13 +1421,15 @@ static void mca_btl_tcp_component_recv_handler(int sd, short flags, void* user) because the peer closed the socket. So just close it and move on. */ if (retval < sizeof(hs_msg)) { - const char *peer = opal_fd_get_peer_name(sd); - opal_output_verbose(20, opal_btl_base_framework.framework_output, - "Peer %s closed socket without sending BTL TCP magic ID handshake (we received %d bytes out of the expected %d) -- closing/ignoring this connection", - peer, (int) retval, (int) sizeof(hs_msg)); - free((char*) peer); - CLOSE_THE_SOCKET(sd); - return; + const char *peer = opal_fd_get_peer_name(sd); + opal_output_verbose( + 20, opal_btl_base_framework.framework_output, + "Peer %s closed socket without sending BTL TCP magic ID handshake (we received %d " + "bytes out of the expected %d) -- closing/ignoring this connection", + peer, (int) retval, (int) sizeof(hs_msg)); + free((char *) peer); + CLOSE_THE_SOCKET(sd); + return; } /* Open MPI uses a "magic" string to trivially verify that the @@ -1485,13 +1437,13 @@ static void mca_btl_tcp_component_recv_handler(int sd, short flags, void* user) the correct magic string. */ guid = hs_msg.guid; if (0 != strncmp(hs_msg.magic_id, mca_btl_tcp_magic_id_string, len)) { - const char *peer = opal_fd_get_peer_name(sd); - opal_output_verbose(20, opal_btl_base_framework.framework_output, - "Peer %s send us an incorrect Open MPI magic ID string (i.e., this was not a connection from the same version of Open MPI; expected \"%s\", received \"%s\")", - peer, - mca_btl_tcp_magic_id_string, - hs_msg.magic_id); - free((char*) peer); + const char *peer = opal_fd_get_peer_name(sd); + opal_output_verbose( + 20, opal_btl_base_framework.framework_output, + "Peer %s send us an incorrect Open MPI magic ID string (i.e., this was not a " + "connection from the same version of Open MPI; expected \"%s\", received \"%s\")", + peer, mca_btl_tcp_magic_id_string, hs_msg.magic_id); + free((char *) peer); /* The other side probably isn't OMPI, so just hang up */ CLOSE_THE_SOCKET(sd); @@ -1499,68 +1451,61 @@ static void mca_btl_tcp_component_recv_handler(int sd, short flags, void* user) } if (sockopt) { - /* reset RECVTIMEO option to its original state */ - if (0 != setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &save, sizeof(save))) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), - "setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, ...)", - strerror(opal_socket_errno), opal_socket_errno); - return; - } + /* reset RECVTIMEO option to its original state */ + if (0 != setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &save, sizeof(save))) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, + opal_process_info.nodename, getpid(), + "setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, ...)", + strerror(opal_socket_errno), opal_socket_errno); + return; + } } OPAL_PROCESS_NAME_NTOH(guid); /* now set socket up to be non-blocking */ - if((flags = fcntl(sd, F_GETFL, 0)) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), "fcntl(sd, F_GETFL, 0)", - strerror(opal_socket_errno), opal_socket_errno); + if ((flags = fcntl(sd, F_GETFL, 0)) < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, opal_process_info.nodename, + getpid(), "fcntl(sd, F_GETFL, 0)", strerror(opal_socket_errno), + opal_socket_errno); CLOSE_THE_SOCKET(sd); } else { flags |= O_NONBLOCK; - if(fcntl(sd, F_SETFL, flags) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), - "fcntl(sd, F_SETFL, flags & O_NONBLOCK)", - strerror(opal_socket_errno), opal_socket_errno); + if (fcntl(sd, F_SETFL, flags) < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, + opal_process_info.nodename, getpid(), + "fcntl(sd, F_SETFL, flags & O_NONBLOCK)", strerror(opal_socket_errno), + opal_socket_errno); CLOSE_THE_SOCKET(sd); } } /* lookup the corresponding process */ btl_proc = mca_btl_tcp_proc_lookup(&guid); - if(NULL == btl_proc) { - opal_show_help("help-mpi-btl-tcp.txt", - "server accept cannot find guid", - true, opal_process_info.nodename, - getpid()); + if (NULL == btl_proc) { + opal_show_help("help-mpi-btl-tcp.txt", "server accept cannot find guid", true, + opal_process_info.nodename, getpid()); CLOSE_THE_SOCKET(sd); return; } /* lookup peer address */ - if(getpeername(sd, (struct sockaddr*)&addr, &addr_len) != 0) { + if (getpeername(sd, (struct sockaddr *) &addr, &addr_len) != 0) { if (ENOTCONN != opal_socket_errno) { - opal_show_help("help-mpi-btl-tcp.txt", - "server getpeername failed", - true, opal_process_info.nodename, - getpid(), - strerror(opal_socket_errno), opal_socket_errno); + opal_show_help("help-mpi-btl-tcp.txt", "server getpeername failed", true, + opal_process_info.nodename, getpid(), strerror(opal_socket_errno), + opal_socket_errno); } CLOSE_THE_SOCKET(sd); return; } /* are there any existing peer instances willing to accept this connection */ - (void)mca_btl_tcp_proc_accept(btl_proc, (struct sockaddr*)&addr, sd); + (void) mca_btl_tcp_proc_accept(btl_proc, (struct sockaddr *) &addr, sd); const char *str = opal_fd_get_peer_name(sd); opal_output_verbose(10, opal_btl_base_framework.framework_output, "btl:tcp: now connected to %s, process %s", str, OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name)); - free((char*) str); + free((char *) str); } diff --git a/opal/mca/btl/tcp/btl_tcp_endpoint.c b/opal/mca/btl/tcp/btl_tcp_endpoint.c index f5ad7f51b81..1aa7031c0ac 100644 --- a/opal/mca/btl/tcp/btl_tcp_endpoint.c +++ b/opal/mca/btl/tcp/btl_tcp_endpoint.c @@ -30,42 +30,42 @@ #include #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include "opal/opal_socket_errno.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_FCNTL_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_NETINET_TCP_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_SYS_TIME_H -#include -#endif /* HAVE_SYS_TIME_H */ +# include +#endif /* HAVE_SYS_TIME_H */ #include +#include "opal/mca/btl/base/btl_base_error.h" #include "opal/util/event.h" #include "opal/util/net.h" -#include "opal/util/show_help.h" -#include "opal/util/proc.h" #include "opal/util/printf.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" #include "opal/util/string_copy.h" -#include "opal/mca/btl/base/btl_base_error.h" #include "btl_tcp.h" +#include "btl_tcp_addr.h" #include "btl_tcp_endpoint.h" -#include "btl_tcp_proc.h" #include "btl_tcp_frag.h" -#include "btl_tcp_addr.h" +#include "btl_tcp_proc.h" /* * Magic ID string send during connect/accept handshake @@ -77,7 +77,7 @@ const char mca_btl_tcp_magic_id_string[MCA_BTL_TCP_MAGIC_STRING_LENGTH] = "OPAL- * Initialize state of the endpoint instance. * */ -static void mca_btl_tcp_endpoint_construct(mca_btl_tcp_endpoint_t* endpoint) +static void mca_btl_tcp_endpoint_construct(mca_btl_tcp_endpoint_t *endpoint) { endpoint->endpoint_btl = NULL; endpoint->endpoint_proc = NULL; @@ -90,10 +90,10 @@ static void mca_btl_tcp_endpoint_construct(mca_btl_tcp_endpoint_t* endpoint) endpoint->endpoint_retries = 0; endpoint->endpoint_nbo = false; #if MCA_BTL_TCP_ENDPOINT_CACHE - endpoint->endpoint_cache = NULL; - endpoint->endpoint_cache_pos = NULL; + endpoint->endpoint_cache = NULL; + endpoint->endpoint_cache_pos = NULL; endpoint->endpoint_cache_length = 0; -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ OBJ_CONSTRUCT(&endpoint->endpoint_frags, opal_list_t); OBJ_CONSTRUCT(&endpoint->endpoint_send_lock, opal_mutex_t); OBJ_CONSTRUCT(&endpoint->endpoint_recv_lock, opal_mutex_t); @@ -103,7 +103,7 @@ static void mca_btl_tcp_endpoint_construct(mca_btl_tcp_endpoint_t* endpoint) * Destroy a endpoint * */ -static void mca_btl_tcp_endpoint_destruct(mca_btl_tcp_endpoint_t* endpoint) +static void mca_btl_tcp_endpoint_destruct(mca_btl_tcp_endpoint_t *endpoint) { mca_btl_tcp_endpoint_close(endpoint); mca_btl_tcp_proc_remove(endpoint->endpoint_proc, endpoint); @@ -112,19 +112,15 @@ static void mca_btl_tcp_endpoint_destruct(mca_btl_tcp_endpoint_t* endpoint) OBJ_DESTRUCT(&endpoint->endpoint_recv_lock); } -OBJ_CLASS_INSTANCE( - mca_btl_tcp_endpoint_t, - opal_list_item_t, - mca_btl_tcp_endpoint_construct, - mca_btl_tcp_endpoint_destruct); +OBJ_CLASS_INSTANCE(mca_btl_tcp_endpoint_t, opal_list_item_t, mca_btl_tcp_endpoint_construct, + mca_btl_tcp_endpoint_destruct); - -static void mca_btl_tcp_endpoint_construct(mca_btl_base_endpoint_t* btl_endpoint); -static void mca_btl_tcp_endpoint_destruct(mca_btl_base_endpoint_t* btl_endpoint); -static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t*); -static void mca_btl_tcp_endpoint_connected(mca_btl_base_endpoint_t*); -static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void* user); -static void mca_btl_tcp_endpoint_send_handler(int sd, short flags, void* user); +static void mca_btl_tcp_endpoint_construct(mca_btl_base_endpoint_t *btl_endpoint); +static void mca_btl_tcp_endpoint_destruct(mca_btl_base_endpoint_t *btl_endpoint); +static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t *); +static void mca_btl_tcp_endpoint_connected(mca_btl_base_endpoint_t *); +static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void *user); +static void mca_btl_tcp_endpoint_send_handler(int sd, short flags, void *user); /* * diagnostics @@ -132,7 +128,7 @@ static void mca_btl_tcp_endpoint_send_handler(int sd, short flags, void* user); #if OPAL_ENABLE_DEBUG && WANT_PEER_DUMP -#define DEBUG_LENGTH 1024 +# define DEBUG_LENGTH 1024 /** * The lack of protection in the mca_btl_tcp_endpoint_dump function is voluntary * so that it can be called regardless of the state of the mutexes. As a result, @@ -141,156 +137,178 @@ static void mca_btl_tcp_endpoint_send_handler(int sd, short flags, void* user); * might access freed memory. Thus, the caller should lock the endpoint prior * to the call. */ -void -mca_btl_tcp_endpoint_dump(int level, - const char* fname, - int lineno, - const char* funcname, - mca_btl_base_endpoint_t* btl_endpoint, - bool full_info, - const char* msg) +void mca_btl_tcp_endpoint_dump(int level, const char *fname, int lineno, const char *funcname, + mca_btl_base_endpoint_t *btl_endpoint, bool full_info, + const char *msg) { char outmsg[DEBUG_LENGTH]; int sndbuf, rcvbuf, nodelay, flags, used = 0; -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 struct sockaddr_storage inaddr; -#else +# else struct sockaddr_in inaddr; -#endif +# endif opal_socklen_t obtlen; opal_socklen_t addrlen = sizeof(inaddr); - mca_btl_tcp_frag_t* item; + mca_btl_tcp_frag_t *item; used += snprintf(&outmsg[used], DEBUG_LENGTH - used, "%s: ", msg); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; - getsockname(btl_endpoint->endpoint_sd, (struct sockaddr*)&inaddr, &addrlen); -#if OPAL_ENABLE_IPV6 + getsockname(btl_endpoint->endpoint_sd, (struct sockaddr *) &inaddr, &addrlen); +# if OPAL_ENABLE_IPV6 { char *address; - address = (char *) opal_net_get_hostname((struct sockaddr*) &inaddr); + address = (char *) opal_net_get_hostname((struct sockaddr *) &inaddr); if (NULL != address) { used += snprintf(&outmsg[used], DEBUG_LENGTH - used, "%s -", address); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; } } -#else +# else used += snprintf(&outmsg[used], DEBUG_LENGTH - used, "%s -", inet_ntoa(inaddr.sin_addr)); - if (used >= DEBUG_LENGTH) goto out; -#endif - getpeername(btl_endpoint->endpoint_sd, (struct sockaddr*)&inaddr, &addrlen); -#if OPAL_ENABLE_IPV6 + if (used >= DEBUG_LENGTH) + goto out; +# endif + getpeername(btl_endpoint->endpoint_sd, (struct sockaddr *) &inaddr, &addrlen); +# if OPAL_ENABLE_IPV6 { char *address; - address = (char *) opal_net_get_hostname ((struct sockaddr*) &inaddr); + address = (char *) opal_net_get_hostname((struct sockaddr *) &inaddr); if (NULL != address) { used += snprintf(&outmsg[used], DEBUG_LENGTH - used, " %s", address); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; } } -#else +# else used += snprintf(&outmsg[used], DEBUG_LENGTH - used, " %s", inet_ntoa(inaddr.sin_addr)); - if (used >= DEBUG_LENGTH) goto out; -#endif + if (used >= DEBUG_LENGTH) + goto out; +# endif used = snprintf(outmsg, DEBUG_LENGTH, "[%d", btl_endpoint->endpoint_sd); - if (used >= DEBUG_LENGTH) goto out; - switch(btl_endpoint->endpoint_state) { + if (used >= DEBUG_LENGTH) + goto out; + switch (btl_endpoint->endpoint_state) { case MCA_BTL_TCP_CONNECTING: used += snprintf(&outmsg[used], DEBUG_LENGTH - used, ":%s]", "connecting"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; break; case MCA_BTL_TCP_CONNECT_ACK: used += snprintf(&outmsg[used], DEBUG_LENGTH - used, ":%s]", "ack"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; break; case MCA_BTL_TCP_CLOSED: used += snprintf(&outmsg[used], DEBUG_LENGTH - used, ":%s]", "close"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; break; case MCA_BTL_TCP_FAILED: used += snprintf(&outmsg[used], DEBUG_LENGTH - used, ":%s]", "failed"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; break; case MCA_BTL_TCP_CONNECTED: used += snprintf(&outmsg[used], DEBUG_LENGTH - used, ":%s]", "connected"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; break; default: used += snprintf(&outmsg[used], DEBUG_LENGTH - used, ":%s]", "unknown"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; break; } - if( full_info ) { - if((flags = fcntl(btl_endpoint->endpoint_sd, F_GETFL, 0)) < 0) { - BTL_ERROR(("fcntl(F_GETFL) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (full_info) { + if ((flags = fcntl(btl_endpoint->endpoint_sd, F_GETFL, 0)) < 0) { + BTL_ERROR( + ("fcntl(F_GETFL) failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); } -#if defined(SO_SNDBUF) +# if defined(SO_SNDBUF) obtlen = sizeof(sndbuf); - if(getsockopt(btl_endpoint->endpoint_sd, SOL_SOCKET, SO_SNDBUF, (char *)&sndbuf, &obtlen) < 0) { - BTL_ERROR(("SO_SNDBUF option: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (getsockopt(btl_endpoint->endpoint_sd, SOL_SOCKET, SO_SNDBUF, (char *) &sndbuf, &obtlen) + < 0) { + BTL_ERROR( + ("SO_SNDBUF option: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); } -#else +# else sndbuf = -1; -#endif -#if defined(SO_RCVBUF) +# endif +# if defined(SO_RCVBUF) obtlen = sizeof(rcvbuf); - if(getsockopt(btl_endpoint->endpoint_sd, SOL_SOCKET, SO_RCVBUF, (char *)&rcvbuf, &obtlen) < 0) { - BTL_ERROR(("SO_RCVBUF option: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (getsockopt(btl_endpoint->endpoint_sd, SOL_SOCKET, SO_RCVBUF, (char *) &rcvbuf, &obtlen) + < 0) { + BTL_ERROR( + ("SO_RCVBUF option: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); } -#else +# else rcvbuf = -1; -#endif -#if defined(TCP_NODELAY) +# endif +# if defined(TCP_NODELAY) obtlen = sizeof(nodelay); - if(getsockopt(btl_endpoint->endpoint_sd, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, &obtlen) < 0) { - BTL_ERROR(("TCP_NODELAY option: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (getsockopt(btl_endpoint->endpoint_sd, IPPROTO_TCP, TCP_NODELAY, (char *) &nodelay, + &obtlen) + < 0) { + BTL_ERROR( + ("TCP_NODELAY option: %s (%d)", strerror(opal_socket_errno), opal_socket_errno)); } -#else +# else nodelay = 0; -#endif - used += snprintf(&outmsg[used], DEBUG_LENGTH - used, " nodelay %d sndbuf %d rcvbuf %d flags %08x", - nodelay, sndbuf, rcvbuf, flags); - if (used >= DEBUG_LENGTH) goto out; -#if MCA_BTL_TCP_ENDPOINT_CACHE +# endif + used += snprintf(&outmsg[used], DEBUG_LENGTH - used, + " nodelay %d sndbuf %d rcvbuf %d flags %08x", nodelay, sndbuf, rcvbuf, + flags); + if (used >= DEBUG_LENGTH) + goto out; +# if MCA_BTL_TCP_ENDPOINT_CACHE used += snprintf(&outmsg[used], DEBUG_LENGTH - used, "\n\t[cache %p used %lu/%lu]", - (void*)btl_endpoint->endpoint_cache, btl_endpoint->endpoint_cache_pos - btl_endpoint->endpoint_cache, + (void *) btl_endpoint->endpoint_cache, + btl_endpoint->endpoint_cache_pos - btl_endpoint->endpoint_cache, btl_endpoint->endpoint_cache_length); - if (used >= DEBUG_LENGTH) goto out; -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ + if (used >= DEBUG_LENGTH) + goto out; +# endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ used += snprintf(&outmsg[used], DEBUG_LENGTH - used, "{%s - retries %d}", - (btl_endpoint->endpoint_nbo ? "NBO" : ""), (int)btl_endpoint->endpoint_retries); - if (used >= DEBUG_LENGTH) goto out; + (btl_endpoint->endpoint_nbo ? "NBO" : ""), + (int) btl_endpoint->endpoint_retries); + if (used >= DEBUG_LENGTH) + goto out; } used += snprintf(&outmsg[used], DEBUG_LENGTH - used, "\n"); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; - if( NULL != btl_endpoint->endpoint_recv_frag ) + if (NULL != btl_endpoint->endpoint_recv_frag) used += mca_btl_tcp_frag_dump(btl_endpoint->endpoint_recv_frag, "active recv", &outmsg[used], DEBUG_LENGTH - used); - if (used >= DEBUG_LENGTH) goto out; - - if( NULL != btl_endpoint->endpoint_send_frag ) - used += mca_btl_tcp_frag_dump(btl_endpoint->endpoint_send_frag, "active send (inaccurate iov)", - &outmsg[used], DEBUG_LENGTH - used); - if (used >= DEBUG_LENGTH) goto out; - OPAL_LIST_FOREACH(item, &btl_endpoint->endpoint_frags, mca_btl_tcp_frag_t) { + if (used >= DEBUG_LENGTH) + goto out; + + if (NULL != btl_endpoint->endpoint_send_frag) + used += mca_btl_tcp_frag_dump(btl_endpoint->endpoint_send_frag, + "active send (inaccurate iov)", &outmsg[used], + DEBUG_LENGTH - used); + if (used >= DEBUG_LENGTH) + goto out; + OPAL_LIST_FOREACH (item, &btl_endpoint->endpoint_frags, mca_btl_tcp_frag_t) { used += mca_btl_tcp_frag_dump(item, "pending send", &outmsg[used], DEBUG_LENGTH - used); - if (used >= DEBUG_LENGTH) goto out; + if (used >= DEBUG_LENGTH) + goto out; } out: - outmsg[ used >= DEBUG_LENGTH ? (DEBUG_LENGTH-1) : used ] = '\0'; - opal_output_verbose(level, opal_btl_base_framework.framework_output, - "[%s:%d:%s][%s -> %s] %s", - fname, lineno, funcname, - OPAL_NAME_PRINT(opal_proc_local_get()->proc_name), - (NULL != btl_endpoint->endpoint_proc ? OPAL_NAME_PRINT(btl_endpoint->endpoint_proc->proc_opal->proc_name) : "unknown remote"), + outmsg[used >= DEBUG_LENGTH ? (DEBUG_LENGTH - 1) : used] = '\0'; + opal_output_verbose(level, opal_btl_base_framework.framework_output, "[%s:%d:%s][%s -> %s] %s", + fname, lineno, funcname, OPAL_NAME_PRINT(opal_proc_local_get()->proc_name), + (NULL != btl_endpoint->endpoint_proc + ? OPAL_NAME_PRINT(btl_endpoint->endpoint_proc->proc_opal->proc_name) + : "unknown remote"), outmsg); } #endif /* OPAL_ENABLE_DEBUG && WANT_PEER_DUMP */ @@ -299,79 +317,78 @@ mca_btl_tcp_endpoint_dump(int level, * Initialize events to be used by the endpoint instance for TCP select/poll callbacks. */ -static inline void mca_btl_tcp_endpoint_event_init(mca_btl_base_endpoint_t* btl_endpoint) +static inline void mca_btl_tcp_endpoint_event_init(mca_btl_base_endpoint_t *btl_endpoint) { #if MCA_BTL_TCP_ENDPOINT_CACHE assert(NULL == btl_endpoint->endpoint_cache); - btl_endpoint->endpoint_cache = (char*)malloc(mca_btl_tcp_component.tcp_endpoint_cache); + btl_endpoint->endpoint_cache = (char *) malloc(mca_btl_tcp_component.tcp_endpoint_cache); btl_endpoint->endpoint_cache_pos = btl_endpoint->endpoint_cache; -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ opal_event_set(mca_btl_tcp_event_base, &btl_endpoint->endpoint_recv_event, - btl_endpoint->endpoint_sd, - OPAL_EV_READ | OPAL_EV_PERSIST, - mca_btl_tcp_endpoint_recv_handler, - btl_endpoint ); + btl_endpoint->endpoint_sd, OPAL_EV_READ | OPAL_EV_PERSIST, + mca_btl_tcp_endpoint_recv_handler, btl_endpoint); /** * In the multi-threaded case, the send event must be persistent in order * to avoid missing the connection notification in send_handler due to * a local handling of the peer process (which holds the lock). */ opal_event_set(mca_btl_tcp_event_base, &btl_endpoint->endpoint_send_event, - btl_endpoint->endpoint_sd, - OPAL_EV_WRITE | OPAL_EV_PERSIST, - mca_btl_tcp_endpoint_send_handler, - btl_endpoint); + btl_endpoint->endpoint_sd, OPAL_EV_WRITE | OPAL_EV_PERSIST, + mca_btl_tcp_endpoint_send_handler, btl_endpoint); } - /* * Attempt to send a fragment using a given endpoint. If the endpoint is not connected, * queue the fragment and start the connection as required. */ -int mca_btl_tcp_endpoint_send(mca_btl_base_endpoint_t* btl_endpoint, mca_btl_tcp_frag_t* frag) +int mca_btl_tcp_endpoint_send(mca_btl_base_endpoint_t *btl_endpoint, mca_btl_tcp_frag_t *frag) { int rc = OPAL_SUCCESS; OPAL_THREAD_LOCK(&btl_endpoint->endpoint_send_lock); - switch(btl_endpoint->endpoint_state) { + switch (btl_endpoint->endpoint_state) { case MCA_BTL_TCP_CONNECTING: case MCA_BTL_TCP_CONNECT_ACK: case MCA_BTL_TCP_CLOSED: - opal_list_append(&btl_endpoint->endpoint_frags, (opal_list_item_t*)frag); + opal_list_append(&btl_endpoint->endpoint_frags, (opal_list_item_t *) frag); frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; - if(btl_endpoint->endpoint_state == MCA_BTL_TCP_CLOSED) + if (btl_endpoint->endpoint_state == MCA_BTL_TCP_CLOSED) { rc = mca_btl_tcp_endpoint_start_connect(btl_endpoint); + } break; case MCA_BTL_TCP_FAILED: rc = OPAL_ERR_UNREACH; break; case MCA_BTL_TCP_CONNECTED: if (NULL == btl_endpoint->endpoint_send_frag) { - if(frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY && - mca_btl_tcp_frag_send(frag, btl_endpoint->endpoint_sd)) { + if (frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY + && mca_btl_tcp_frag_send(frag, btl_endpoint->endpoint_sd)) { int btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); - if( frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK ) { + if (frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) { frag->base.des_cbfunc(&frag->btl->super, frag->endpoint, &frag->base, frag->rc); } - if( btl_ownership ) { + if (btl_ownership) { MCA_BTL_TCP_FRAG_RETURN(frag); } - MCA_BTL_TCP_ENDPOINT_DUMP(50, btl_endpoint, true, "complete send fragment [endpoint_send]"); + MCA_BTL_TCP_ENDPOINT_DUMP(50, btl_endpoint, true, + "complete send fragment [endpoint_send]"); return 1; } else { btl_endpoint->endpoint_send_frag = frag; - MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "event_add(send) [endpoint_send]"); + MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, + "event_add(send) [endpoint_send]"); frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; MCA_BTL_TCP_ACTIVATE_EVENT(&btl_endpoint->endpoint_send_event, 0); } } else { - MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "send fragment enqueued [endpoint_send]"); + MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, + "send fragment enqueued [endpoint_send]"); frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; - opal_list_append(&btl_endpoint->endpoint_frags, (opal_list_item_t*)frag); + opal_list_append(&btl_endpoint->endpoint_frags, (opal_list_item_t *) frag); } break; } @@ -379,14 +396,12 @@ int mca_btl_tcp_endpoint_send(mca_btl_base_endpoint_t* btl_endpoint, mca_btl_tcp return rc; } - /* * A blocking send on a non-blocking socket. Used to send the small * amount of connection information that identifies the endpoints endpoint. */ -static int -mca_btl_tcp_endpoint_send_blocking(mca_btl_base_endpoint_t* btl_endpoint, - const void* data, size_t size) +static int mca_btl_tcp_endpoint_send_blocking(mca_btl_base_endpoint_t *btl_endpoint, + const void *data, size_t size) { int ret = mca_btl_tcp_send_blocking(btl_endpoint->endpoint_sd, data, size); if (ret < 0) { @@ -402,68 +417,64 @@ mca_btl_tcp_endpoint_send_blocking(mca_btl_base_endpoint_t* btl_endpoint, * Send the globally unique identifier for this process to a endpoint on * a newly connected socket. */ -static int -mca_btl_tcp_endpoint_send_connect_ack(mca_btl_base_endpoint_t* btl_endpoint) +static int mca_btl_tcp_endpoint_send_connect_ack(mca_btl_base_endpoint_t *btl_endpoint) { opal_process_name_t guid = opal_proc_local_get()->proc_name; OPAL_PROCESS_NAME_HTON(guid); mca_btl_tcp_endpoint_hs_msg_t hs_msg; - opal_string_copy(hs_msg.magic_id, mca_btl_tcp_magic_id_string, - sizeof(hs_msg.magic_id)); + opal_string_copy(hs_msg.magic_id, mca_btl_tcp_magic_id_string, sizeof(hs_msg.magic_id)); hs_msg.guid = guid; - if(sizeof(hs_msg) != - mca_btl_tcp_endpoint_send_blocking(btl_endpoint, - &hs_msg, sizeof(hs_msg))) { - opal_show_help("help-mpi-btl-tcp.txt", "client handshake fail", - true, opal_process_info.nodename, - sizeof(hs_msg), + if (sizeof(hs_msg) + != mca_btl_tcp_endpoint_send_blocking(btl_endpoint, &hs_msg, sizeof(hs_msg))) { + opal_show_help("help-mpi-btl-tcp.txt", "client handshake fail", true, + opal_process_info.nodename, sizeof(hs_msg), "connect ACK failed to send magic-id and guid"); - return OPAL_ERR_UNREACH; + return OPAL_ERR_UNREACH; } return OPAL_SUCCESS; } static void *mca_btl_tcp_endpoint_complete_accept(int fd, int flags, void *context) { - mca_btl_base_endpoint_t* btl_endpoint = (mca_btl_base_endpoint_t*)context; + mca_btl_base_endpoint_t *btl_endpoint = (mca_btl_base_endpoint_t *) context; struct timeval now = {0, 0}; int cmpval; - if( OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_recv_lock) ) { + if (OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_recv_lock)) { opal_event_add(&btl_endpoint->endpoint_accept_event, &now); return NULL; } - if( OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_send_lock) ) { + if (OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_send_lock)) { OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); opal_event_add(&btl_endpoint->endpoint_accept_event, &now); return NULL; } - if(NULL == btl_endpoint->endpoint_addr) { - CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd_next); /* No further use of this socket. Close it */ + if (NULL == btl_endpoint->endpoint_addr) { + CLOSE_THE_SOCKET( + btl_endpoint->endpoint_sd_next); /* No further use of this socket. Close it */ btl_endpoint->endpoint_sd_next = -1; OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); - if( NULL != btl_endpoint->endpoint_btl->tcp_error_cb ) { - btl_endpoint->endpoint_btl->tcp_error_cb( - &btl_endpoint->endpoint_btl->super, MCA_BTL_ERROR_FLAGS_NONFATAL, - btl_endpoint->endpoint_proc->proc_opal, - "The endpoint addr is set to NULL (unsettling)"); + if (NULL != btl_endpoint->endpoint_btl->tcp_error_cb) { + btl_endpoint->endpoint_btl + ->tcp_error_cb(&btl_endpoint->endpoint_btl->super, MCA_BTL_ERROR_FLAGS_NONFATAL, + btl_endpoint->endpoint_proc->proc_opal, + "The endpoint addr is set to NULL (unsettling)"); } return NULL; } cmpval = opal_compare_proc(btl_endpoint->endpoint_proc->proc_opal->proc_name, opal_proc_local_get()->proc_name); - if((btl_endpoint->endpoint_sd < 0) || - (btl_endpoint->endpoint_state != MCA_BTL_TCP_CONNECTED && - cmpval < 0)) { + if ((btl_endpoint->endpoint_sd < 0) + || (btl_endpoint->endpoint_state != MCA_BTL_TCP_CONNECTED && cmpval < 0)) { mca_btl_tcp_endpoint_close(btl_endpoint); btl_endpoint->endpoint_sd = btl_endpoint->endpoint_sd_next; btl_endpoint->endpoint_sd_next = -1; - if(mca_btl_tcp_endpoint_send_connect_ack(btl_endpoint) != OPAL_SUCCESS) { + if (mca_btl_tcp_endpoint_send_connect_ack(btl_endpoint) != OPAL_SUCCESS) { MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, " [endpoint_accept]"); btl_endpoint->endpoint_state = MCA_BTL_TCP_FAILED; mca_btl_tcp_endpoint_close(btl_endpoint); @@ -472,7 +483,7 @@ static void *mca_btl_tcp_endpoint_complete_accept(int fd, int flags, void *conte mca_btl_tcp_endpoint_event_init(btl_endpoint); MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "event_add(recv) [endpoint_accept]"); opal_event_add(&btl_endpoint->endpoint_recv_event, 0); - if( mca_btl_tcp_event_base == opal_sync_event_base ) { + if (mca_btl_tcp_event_base == opal_sync_event_base) { /* If no progress thread then raise the awarness of the default progress engine */ opal_progress_event_users_increment(); } @@ -483,7 +494,7 @@ static void *mca_btl_tcp_endpoint_complete_accept(int fd, int flags, void *conte } CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd_next); /* No further use of this socket. Close it */ btl_endpoint->endpoint_sd_next = -1; - unlock_and_return: +unlock_and_return: OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); return NULL; @@ -498,8 +509,8 @@ static void *mca_btl_tcp_endpoint_complete_accept(int fd, int flags, void *conte * otherwise, reject the connection and continue with the current connection */ -void mca_btl_tcp_endpoint_accept(mca_btl_base_endpoint_t* btl_endpoint, - struct sockaddr* addr, int sd) +void mca_btl_tcp_endpoint_accept(mca_btl_base_endpoint_t *btl_endpoint, struct sockaddr *addr, + int sd) { struct timeval now = {0, 0}; @@ -511,21 +522,21 @@ void mca_btl_tcp_endpoint_accept(mca_btl_base_endpoint_t* btl_endpoint, opal_event_add(&btl_endpoint->endpoint_accept_event, &now); } - /* * Remove any event registrations associated with the socket * and update the endpoint state to reflect the connection has * been closed. */ -void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t* btl_endpoint) +void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t *btl_endpoint) { MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, false, "[close]"); - if(btl_endpoint->endpoint_sd < 0) + if (btl_endpoint->endpoint_sd < 0) { return; + } btl_endpoint->endpoint_retries++; MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, false, "event_del(recv) [close]"); opal_event_del(&btl_endpoint->endpoint_recv_event); - if( mca_btl_tcp_event_base == opal_sync_event_base ) { + if (mca_btl_tcp_event_base == opal_sync_event_base) { /* If no progress thread then lower the awarness of the default progress engine */ opal_progress_event_users_decrement(); } @@ -533,23 +544,22 @@ void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t* btl_endpoint) opal_event_del(&btl_endpoint->endpoint_send_event); #if MCA_BTL_TCP_ENDPOINT_CACHE - free( btl_endpoint->endpoint_cache ); - btl_endpoint->endpoint_cache = NULL; - btl_endpoint->endpoint_cache_pos = NULL; + free(btl_endpoint->endpoint_cache); + btl_endpoint->endpoint_cache = NULL; + btl_endpoint->endpoint_cache_pos = NULL; btl_endpoint->endpoint_cache_length = 0; -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ /* send a message before closing to differentiate between failures and * clean disconnect during finalize */ - if( MCA_BTL_TCP_CONNECTED == btl_endpoint->endpoint_state ) { + if (MCA_BTL_TCP_CONNECTED == btl_endpoint->endpoint_state) { mca_btl_tcp_hdr_t fin_msg = { .base.tag = 0, .type = MCA_BTL_TCP_HDR_TYPE_FIN, .count = 0, .size = 0, }; - mca_btl_tcp_endpoint_send_blocking(btl_endpoint, - &fin_msg, sizeof(fin_msg)); + mca_btl_tcp_endpoint_send_blocking(btl_endpoint, &fin_msg, sizeof(fin_msg)); } CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd); @@ -560,22 +570,24 @@ void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t* btl_endpoint) * reporting the error. The upper layer has then the opportunity to * re-route or re-schedule the fragments. */ - if( MCA_BTL_TCP_FAILED == btl_endpoint->endpoint_state ) { - mca_btl_tcp_frag_t* frag = btl_endpoint->endpoint_send_frag; - if( NULL == frag ) - frag = (mca_btl_tcp_frag_t*)opal_list_remove_first(&btl_endpoint->endpoint_frags); - while(NULL != frag) { + if (MCA_BTL_TCP_FAILED == btl_endpoint->endpoint_state) { + mca_btl_tcp_frag_t *frag = btl_endpoint->endpoint_send_frag; + if (NULL == frag) { + frag = (mca_btl_tcp_frag_t *) opal_list_remove_first(&btl_endpoint->endpoint_frags); + } + while (NULL != frag) { frag->base.des_cbfunc(&frag->btl->super, frag->endpoint, &frag->base, OPAL_ERR_UNREACH); - if( frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP ) { + if (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP) { MCA_BTL_TCP_FRAG_RETURN(frag); } - frag = (mca_btl_tcp_frag_t*)opal_list_remove_first(&btl_endpoint->endpoint_frags); + frag = (mca_btl_tcp_frag_t *) opal_list_remove_first(&btl_endpoint->endpoint_frags); } btl_endpoint->endpoint_send_frag = NULL; /* Let's report the error upstream */ - if(NULL != btl_endpoint->endpoint_btl->tcp_error_cb) { - btl_endpoint->endpoint_btl->tcp_error_cb((mca_btl_base_module_t*)btl_endpoint->endpoint_btl, 0, - btl_endpoint->endpoint_proc->proc_opal, "Socket closed"); + if (NULL != btl_endpoint->endpoint_btl->tcp_error_cb) { + btl_endpoint->endpoint_btl + ->tcp_error_cb((mca_btl_base_module_t *) btl_endpoint->endpoint_btl, 0, + btl_endpoint->endpoint_proc->proc_opal, "Socket closed"); } } else { btl_endpoint->endpoint_state = MCA_BTL_TCP_CLOSED; @@ -588,24 +600,24 @@ void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t* btl_endpoint) * send lock locked. */ -static void mca_btl_tcp_endpoint_connected(mca_btl_base_endpoint_t* btl_endpoint) +static void mca_btl_tcp_endpoint_connected(mca_btl_base_endpoint_t *btl_endpoint) { /* setup socket options */ - assert( MCA_BTL_TCP_CONNECTED != btl_endpoint->endpoint_state ); + assert(MCA_BTL_TCP_CONNECTED != btl_endpoint->endpoint_state); btl_endpoint->endpoint_state = MCA_BTL_TCP_CONNECTED; btl_endpoint->endpoint_retries = 0; MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, "READY [endpoint_connected]"); - if(opal_list_get_size(&btl_endpoint->endpoint_frags) > 0) { - if(NULL == btl_endpoint->endpoint_send_frag) - btl_endpoint->endpoint_send_frag = (mca_btl_tcp_frag_t*) - opal_list_remove_first(&btl_endpoint->endpoint_frags); + if (opal_list_get_size(&btl_endpoint->endpoint_frags) > 0) { + if (NULL == btl_endpoint->endpoint_send_frag) { + btl_endpoint->endpoint_send_frag = (mca_btl_tcp_frag_t *) opal_list_remove_first( + &btl_endpoint->endpoint_frags); + } MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "event_add(send) [endpoint_connected]"); opal_event_add(&btl_endpoint->endpoint_send_event, 0); } } - /* * Receive the endpoints globally unique process identification from a newly * connected socket and verify the expected response. If so, move the @@ -615,10 +627,11 @@ static void mca_btl_tcp_endpoint_connected(mca_btl_base_endpoint_t* btl_endpoint * mca_btl_tcp_endpoint_recv_handler(). Don't change them here * without also changing the handling in _recv_handler()! */ -static int mca_btl_tcp_endpoint_recv_connect_ack(mca_btl_base_endpoint_t* btl_endpoint) +static int mca_btl_tcp_endpoint_recv_connect_ack(mca_btl_base_endpoint_t *btl_endpoint) { - size_t retval, len = strlen(mca_btl_tcp_magic_id_string);; - mca_btl_tcp_proc_t* btl_proc = btl_endpoint->endpoint_proc; + size_t retval, len = strlen(mca_btl_tcp_magic_id_string); + ; + mca_btl_tcp_proc_t *btl_proc = btl_endpoint->endpoint_proc; opal_process_name_t guid; mca_btl_tcp_endpoint_hs_msg_t hs_msg; @@ -633,15 +646,14 @@ static int mca_btl_tcp_endpoint_recv_connect_ack(mca_btl_base_endpoint_t* btl_en upstream. */ return OPAL_ERROR; } - opal_show_help("help-mpi-btl-tcp.txt", "client handshake fail", - true, opal_process_info.nodename, - getpid(), "did not receive entire connect ACK from peer"); + opal_show_help("help-mpi-btl-tcp.txt", "client handshake fail", true, + opal_process_info.nodename, getpid(), + "did not receive entire connect ACK from peer"); return OPAL_ERR_BAD_PARAM; } if (0 != strncmp(hs_msg.magic_id, mca_btl_tcp_magic_id_string, len)) { - opal_show_help("help-mpi-btl-tcp.txt", "server did not receive magic string", - true, opal_process_info.nodename, - getpid(), "client", hs_msg.magic_id, + opal_show_help("help-mpi-btl-tcp.txt", "server did not receive magic string", true, + opal_process_info.nodename, getpid(), "client", hs_msg.magic_id, "string value"); return OPAL_ERR_BAD_PARAM; } @@ -663,29 +675,32 @@ static int mca_btl_tcp_endpoint_recv_connect_ack(mca_btl_base_endpoint_t* btl_en return OPAL_SUCCESS; } - void mca_btl_tcp_set_socket_options(int sd) { #if defined(TCP_NODELAY) int optval; optval = !mca_btl_tcp_component.tcp_not_use_nodelay; - if(setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char *)&optval, sizeof(optval)) < 0) { - BTL_ERROR(("setsockopt(TCP_NODELAY) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char *) &optval, sizeof(optval)) < 0) { + BTL_ERROR(("setsockopt(TCP_NODELAY) failed: %s (%d)", strerror(opal_socket_errno), + opal_socket_errno)); } #endif #if defined(SO_SNDBUF) - if(mca_btl_tcp_component.tcp_sndbuf > 0 && - setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *)&mca_btl_tcp_component.tcp_sndbuf, sizeof(int)) < 0) { - BTL_ERROR(("setsockopt(SO_SNDBUF) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (mca_btl_tcp_component.tcp_sndbuf > 0 + && setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *) &mca_btl_tcp_component.tcp_sndbuf, + sizeof(int)) + < 0) { + BTL_ERROR(("setsockopt(SO_SNDBUF) failed: %s (%d)", strerror(opal_socket_errno), + opal_socket_errno)); } #endif #if defined(SO_RCVBUF) - if(mca_btl_tcp_component.tcp_rcvbuf > 0 && - setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *)&mca_btl_tcp_component.tcp_rcvbuf, sizeof(int)) < 0) { - BTL_ERROR(("setsockopt(SO_RCVBUF) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (mca_btl_tcp_component.tcp_rcvbuf > 0 + && setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *) &mca_btl_tcp_component.tcp_rcvbuf, + sizeof(int)) + < 0) { + BTL_ERROR(("setsockopt(SO_RCVBUF) failed: %s (%d)", strerror(opal_socket_errno), + opal_socket_errno)); } #endif #if defined(SO_NOSIGPIPE) @@ -694,15 +709,13 @@ void mca_btl_tcp_set_socket_options(int sd) * the endpoint. */ int optval2 = 1; - if(setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (char *)&optval2, sizeof(optval2)) < 0) { - BTL_ERROR(("setsockopt(SO_NOSIGPIPE) failed: %s (%d)", - strerror(opal_socket_errno), opal_socket_errno)); + if (setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (char *) &optval2, sizeof(optval2)) < 0) { + BTL_ERROR(("setsockopt(SO_NOSIGPIPE) failed: %s (%d)", strerror(opal_socket_errno), + opal_socket_errno)); } #endif } - - /* * Start a connection to the endpoint. This will likely not complete, * as the socket is set to non-blocking, so register for event @@ -710,9 +723,9 @@ void mca_btl_tcp_set_socket_options(int sd) * globally unique process identifier to the endpoint and wait for * the endpoint response. */ -static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpoint) +static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t *btl_endpoint) { - int rc,flags; + int rc, flags; struct sockaddr_storage endpoint_addr; /* By default consider a IPv4 connection */ uint16_t af_family = AF_INET; @@ -721,10 +734,10 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo #if OPAL_ENABLE_IPV6 if (AF_INET6 == btl_endpoint->endpoint_addr->addr_family) { af_family = AF_INET6; - addrlen = sizeof (struct sockaddr_in6); + addrlen = sizeof(struct sockaddr_in6); } #endif - assert( btl_endpoint->endpoint_sd < 0 ); + assert(btl_endpoint->endpoint_sd < 0); btl_endpoint->endpoint_sd = socket(af_family, SOCK_STREAM, 0); if (btl_endpoint->endpoint_sd < 0) { btl_endpoint->endpoint_retries++; @@ -738,21 +751,19 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo mca_btl_tcp_endpoint_event_init(btl_endpoint); /* setup the socket as non-blocking */ - if((flags = fcntl(btl_endpoint->endpoint_sd, F_GETFL, 0)) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), "fcntl(sd, F_GETFL, 0)", - strerror(opal_socket_errno), opal_socket_errno); + if ((flags = fcntl(btl_endpoint->endpoint_sd, F_GETFL, 0)) < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, opal_process_info.nodename, + getpid(), "fcntl(sd, F_GETFL, 0)", strerror(opal_socket_errno), + opal_socket_errno); /* Upper layer will handler the error */ return OPAL_ERR_UNREACH; } else { flags |= O_NONBLOCK; - if(fcntl(btl_endpoint->endpoint_sd, F_SETFL, flags) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), - "fcntl(sd, F_SETFL, flags & O_NONBLOCK)", - strerror(opal_socket_errno), opal_socket_errno); + if (fcntl(btl_endpoint->endpoint_sd, F_SETFL, flags) < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, + opal_process_info.nodename, getpid(), + "fcntl(sd, F_SETFL, flags & O_NONBLOCK)", strerror(opal_socket_errno), + opal_socket_errno); /* Upper layer will handler the error */ return OPAL_ERR_UNREACH; } @@ -768,12 +779,15 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo * might do something unexpected with routing */ if (endpoint_addr.ss_family == AF_INET) { assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr); - if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr, - sizeof(struct sockaddr_in)) < 0) { - BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)", - opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr), - htons(((struct sockaddr_in*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port), - strerror(opal_socket_errno), opal_socket_errno)); + if (bind(btl_endpoint->endpoint_sd, + (struct sockaddr *) &btl_endpoint->endpoint_btl->tcp_ifaddr, + sizeof(struct sockaddr_in)) + < 0) { + BTL_ERROR( + ("bind on local address (%s:%d) failed: %s (%d)", + opal_net_get_hostname((struct sockaddr *) &btl_endpoint->endpoint_btl->tcp_ifaddr), + htons(((struct sockaddr_in *) &btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port), + strerror(opal_socket_errno), opal_socket_errno)); CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd); return OPAL_ERROR; @@ -782,12 +796,16 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo #if OPAL_ENABLE_IPV6 if (endpoint_addr.ss_family == AF_INET6) { assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr); - if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr, - sizeof(struct sockaddr_in6)) < 0) { - BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)", - opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr), - htons(((struct sockaddr_in6*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin6_port), - strerror(opal_socket_errno), opal_socket_errno)); + if (bind(btl_endpoint->endpoint_sd, + (struct sockaddr *) &btl_endpoint->endpoint_btl->tcp_ifaddr, + sizeof(struct sockaddr_in6)) + < 0) { + BTL_ERROR( + ("bind on local address (%s:%d) failed: %s (%d)", + opal_net_get_hostname((struct sockaddr *) &btl_endpoint->endpoint_btl->tcp_ifaddr), + htons( + ((struct sockaddr_in6 *) &btl_endpoint->endpoint_btl->tcp_ifaddr)->sin6_port), + strerror(opal_socket_errno), opal_socket_errno)); CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd); return OPAL_ERROR; @@ -797,30 +815,31 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo opal_output_verbose(10, opal_btl_base_framework.framework_output, "btl: tcp: attempting to connect() to %s address %s on port %d", OPAL_NAME_PRINT(btl_endpoint->endpoint_proc->proc_opal->proc_name), - opal_net_get_hostname((struct sockaddr*) &endpoint_addr), + opal_net_get_hostname((struct sockaddr *) &endpoint_addr), ntohs(btl_endpoint->endpoint_addr->addr_port)); - if(0 == connect(btl_endpoint->endpoint_sd, (struct sockaddr*)&endpoint_addr, addrlen)) { + if (0 == connect(btl_endpoint->endpoint_sd, (struct sockaddr *) &endpoint_addr, addrlen)) { opal_output_verbose(10, opal_btl_base_framework.framework_output, "btl:tcp: connect() to %s:%d completed", - opal_net_get_hostname((struct sockaddr*) &endpoint_addr), - ntohs(((struct sockaddr_in*) &endpoint_addr)->sin_port)); + opal_net_get_hostname((struct sockaddr *) &endpoint_addr), + ntohs(((struct sockaddr_in *) &endpoint_addr)->sin_port)); /* send our globally unique process identifier to the endpoint */ - if((rc = mca_btl_tcp_endpoint_send_connect_ack(btl_endpoint)) == OPAL_SUCCESS) { + if ((rc = mca_btl_tcp_endpoint_send_connect_ack(btl_endpoint)) == OPAL_SUCCESS) { btl_endpoint->endpoint_state = MCA_BTL_TCP_CONNECT_ACK; MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "event_add(recv) [start_connect]"); opal_event_add(&btl_endpoint->endpoint_recv_event, 0); - if( mca_btl_tcp_event_base == opal_sync_event_base ) { + if (mca_btl_tcp_event_base == opal_sync_event_base) { /* If no progress thread then raise the awarness of the default progress engine */ opal_progress_event_users_increment(); } return OPAL_SUCCESS; } - /* We connected to the peer, but he close the socket before we got a chance to send our guid */ + /* We connected to the peer, but he close the socket before we got a chance to send our guid + */ MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, "dropped connection [start_connect]"); } else { /* non-blocking so wait for completion */ - if(opal_socket_errno == EINPROGRESS || opal_socket_errno == EWOULDBLOCK) { + if (opal_socket_errno == EINPROGRESS || opal_socket_errno == EWOULDBLOCK) { btl_endpoint->endpoint_state = MCA_BTL_TCP_CONNECTING; MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "event_add(send) [start_connect]"); MCA_BTL_TCP_ACTIVATE_EVENT(&btl_endpoint->endpoint_send_event, 0); @@ -832,24 +851,23 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo { char *address; - address = opal_net_get_hostname((struct sockaddr*) &endpoint_addr); - BTL_PEER_ERROR( btl_endpoint->endpoint_proc->proc_opal, - ( "Unable to connect to the peer %s on port %d: %s\n", - address, - ntohs(btl_endpoint->endpoint_addr->addr_port), strerror(opal_socket_errno) ) ); + address = opal_net_get_hostname((struct sockaddr *) &endpoint_addr); + BTL_PEER_ERROR(btl_endpoint->endpoint_proc->proc_opal, + ("Unable to connect to the peer %s on port %d: %s\n", address, + ntohs(btl_endpoint->endpoint_addr->addr_port), + strerror(opal_socket_errno))); } btl_endpoint->endpoint_state = MCA_BTL_TCP_FAILED; mca_btl_tcp_endpoint_close(btl_endpoint); return OPAL_ERR_UNREACH; } - /* * Check the status of the connection. If the connection failed, will retry * later. Otherwise, send this processes identifier to the endpoint on the * newly connected socket. */ -static int mca_btl_tcp_endpoint_complete_connect(mca_btl_base_endpoint_t* btl_endpoint) +static int mca_btl_tcp_endpoint_complete_connect(mca_btl_base_endpoint_t *btl_endpoint) { int so_error = 0; opal_socklen_t so_length = sizeof(so_error); @@ -864,33 +882,30 @@ static int mca_btl_tcp_endpoint_complete_connect(mca_btl_base_endpoint_t* btl_en mca_btl_tcp_proc_tosocks(btl_endpoint->endpoint_addr, &endpoint_addr); /* check connect completion status */ - if(getsockopt(btl_endpoint->endpoint_sd, SOL_SOCKET, SO_ERROR, (char *)&so_error, &so_length) < 0) { - opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", - true, opal_process_info.nodename, - getpid(), "fcntl(sd, F_GETFL, 0)", - strerror(opal_socket_errno), opal_socket_errno); + if (getsockopt(btl_endpoint->endpoint_sd, SOL_SOCKET, SO_ERROR, (char *) &so_error, &so_length) + < 0) { + opal_show_help("help-mpi-btl-tcp.txt", "socket flag fail", true, opal_process_info.nodename, + getpid(), "fcntl(sd, F_GETFL, 0)", strerror(opal_socket_errno), + opal_socket_errno); BTL_ERROR(("getsockopt() to %s:%d failed: %s (%d)", - opal_net_get_hostname((struct sockaddr*) &endpoint_addr), - ((struct sockaddr_in*) &endpoint_addr)->sin_port, - strerror(opal_socket_errno), opal_socket_errno)); + opal_net_get_hostname((struct sockaddr *) &endpoint_addr), + ((struct sockaddr_in *) &endpoint_addr)->sin_port, strerror(opal_socket_errno), + opal_socket_errno)); btl_endpoint->endpoint_state = MCA_BTL_TCP_FAILED; mca_btl_tcp_endpoint_close(btl_endpoint); return OPAL_ERROR; } - if(so_error == EINPROGRESS || so_error == EWOULDBLOCK) { + if (so_error == EINPROGRESS || so_error == EWOULDBLOCK) { return OPAL_SUCCESS; } - if(so_error != 0) { - if( mca_btl_base_warn_peer_error - || mca_btl_base_verbose > 0 ) { + if (so_error != 0) { + if (mca_btl_base_warn_peer_error || mca_btl_base_verbose > 0) { char *msg; opal_asprintf(&msg, "connect() to %s:%d failed", - opal_net_get_hostname((struct sockaddr*) &endpoint_addr), - ntohs(((struct sockaddr_in*) &endpoint_addr)->sin_port)); - opal_show_help("help-mpi-btl-tcp.txt", "client connect fail", - true, opal_process_info.nodename, - getpid(), msg, - strerror(so_error), so_error); + opal_net_get_hostname((struct sockaddr *) &endpoint_addr), + ntohs(((struct sockaddr_in *) &endpoint_addr)->sin_port)); + opal_show_help("help-mpi-btl-tcp.txt", "client connect fail", true, + opal_process_info.nodename, getpid(), msg, strerror(so_error), so_error); free(msg); } btl_endpoint->endpoint_state = MCA_BTL_TCP_FAILED; @@ -898,15 +913,16 @@ static int mca_btl_tcp_endpoint_complete_connect(mca_btl_base_endpoint_t* btl_en return OPAL_ERROR; } - opal_output_verbose(10, opal_btl_base_framework.framework_output, - "btl:tcp: connect() to %s:%d completed (complete_connect), sending connect ACK", - opal_net_get_hostname((struct sockaddr*) &endpoint_addr), - ntohs(((struct sockaddr_in*) &endpoint_addr)->sin_port)); + opal_output_verbose( + 10, opal_btl_base_framework.framework_output, + "btl:tcp: connect() to %s:%d completed (complete_connect), sending connect ACK", + opal_net_get_hostname((struct sockaddr *) &endpoint_addr), + ntohs(((struct sockaddr_in *) &endpoint_addr)->sin_port)); - if(mca_btl_tcp_endpoint_send_connect_ack(btl_endpoint) == OPAL_SUCCESS) { + if (mca_btl_tcp_endpoint_send_connect_ack(btl_endpoint) == OPAL_SUCCESS) { btl_endpoint->endpoint_state = MCA_BTL_TCP_CONNECT_ACK; opal_event_add(&btl_endpoint->endpoint_recv_event, 0); - if( mca_btl_tcp_event_base == opal_sync_event_base ) { + if (mca_btl_tcp_event_base == opal_sync_event_base) { /* If no progress thread then raise the awarness of the default progress engine */ opal_progress_event_users_increment(); } @@ -919,21 +935,21 @@ static int mca_btl_tcp_endpoint_complete_connect(mca_btl_base_endpoint_t* btl_en return OPAL_ERROR; } - /* * A file descriptor is available/ready for recv. Check the state * of the socket and take the appropriate action. */ -static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void* user) +static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void *user) { - mca_btl_base_endpoint_t* btl_endpoint = (mca_btl_base_endpoint_t *)user; + mca_btl_base_endpoint_t *btl_endpoint = (mca_btl_base_endpoint_t *) user; /* Make sure we don't have a race between a thread that remove the * recv event, and one event already scheduled. */ - if( sd != btl_endpoint->endpoint_sd ) + if (sd != btl_endpoint->endpoint_sd) { return; + } /** * There is an extremely rare race condition here, that can only be @@ -951,103 +967,100 @@ static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void* user) * If we can't lock this mutex, it is OK to cancel the receive operation, it * will be eventually triggered again shorthly. */ - if( OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_recv_lock) ) + if (OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_recv_lock)) { return; + } - switch(btl_endpoint->endpoint_state) { - case MCA_BTL_TCP_CONNECT_ACK: - { - int rc = mca_btl_tcp_endpoint_recv_connect_ack(btl_endpoint); - if( OPAL_SUCCESS == rc ) { - /* we are now connected. Start sending the data */ - OPAL_THREAD_LOCK(&btl_endpoint->endpoint_send_lock); - mca_btl_tcp_endpoint_connected(btl_endpoint); - OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); - MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "connected"); - } - else if (OPAL_ERR_BAD_PARAM == rc - || OPAL_ERROR == rc) { - /* If we get a BAD_PARAM, it means that it probably wasn't - an OMPI process on the other end of the socket (e.g., - the magic string ID failed). recv_connect_ack already cleaned - up the socket. */ - /* If we get OPAL_ERROR, the other end closed the connection - * because it has initiated a symetrical connexion on its end. - * recv_connect_ack already cleaned up the socket. */ - } - else { - /* Otherwise, it probably *was* an OMPI peer process on - the other end, and something bad has probably - happened. */ - mca_btl_tcp_module_t *m = btl_endpoint->endpoint_btl; - - /* Fail up to the PML */ - if (NULL != m->tcp_error_cb) { - m->tcp_error_cb((mca_btl_base_module_t*) m, MCA_BTL_ERROR_FLAGS_FATAL, - btl_endpoint->endpoint_proc->proc_opal, - "TCP ACK is neither SUCCESS nor ERR (something bad has probably happened)"); - } + switch (btl_endpoint->endpoint_state) { + case MCA_BTL_TCP_CONNECT_ACK: { + int rc = mca_btl_tcp_endpoint_recv_connect_ack(btl_endpoint); + if (OPAL_SUCCESS == rc) { + /* we are now connected. Start sending the data */ + OPAL_THREAD_LOCK(&btl_endpoint->endpoint_send_lock); + mca_btl_tcp_endpoint_connected(btl_endpoint); + OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); + MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, true, "connected"); + } else if (OPAL_ERR_BAD_PARAM == rc || OPAL_ERROR == rc) { + /* If we get a BAD_PARAM, it means that it probably wasn't + an OMPI process on the other end of the socket (e.g., + the magic string ID failed). recv_connect_ack already cleaned + up the socket. */ + /* If we get OPAL_ERROR, the other end closed the connection + * because it has initiated a symetrical connexion on its end. + * recv_connect_ack already cleaned up the socket. */ + } else { + /* Otherwise, it probably *was* an OMPI peer process on + the other end, and something bad has probably + happened. */ + mca_btl_tcp_module_t *m = btl_endpoint->endpoint_btl; + + /* Fail up to the PML */ + if (NULL != m->tcp_error_cb) { + m->tcp_error_cb( + (mca_btl_base_module_t *) m, MCA_BTL_ERROR_FLAGS_FATAL, + btl_endpoint->endpoint_proc->proc_opal, + "TCP ACK is neither SUCCESS nor ERR (something bad has probably happened)"); } - OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); - return; } - case MCA_BTL_TCP_CONNECTED: - { - mca_btl_tcp_frag_t* frag; - - frag = btl_endpoint->endpoint_recv_frag; - if(NULL == frag) { - if(mca_btl_tcp_module.super.btl_max_send_size > - mca_btl_tcp_module.super.btl_eager_limit) { - MCA_BTL_TCP_FRAG_ALLOC_MAX(frag); - } else { - MCA_BTL_TCP_FRAG_ALLOC_EAGER(frag); - } + OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); + return; + } + case MCA_BTL_TCP_CONNECTED: { + mca_btl_tcp_frag_t *frag; + + frag = btl_endpoint->endpoint_recv_frag; + if (NULL == frag) { + if (mca_btl_tcp_module.super.btl_max_send_size + > mca_btl_tcp_module.super.btl_eager_limit) { + MCA_BTL_TCP_FRAG_ALLOC_MAX(frag); + } else { + MCA_BTL_TCP_FRAG_ALLOC_EAGER(frag); + } - if(NULL == frag) { - OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); - return; - } - MCA_BTL_TCP_FRAG_INIT_DST(frag, btl_endpoint); + if (NULL == frag) { + OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); + return; } + MCA_BTL_TCP_FRAG_INIT_DST(frag, btl_endpoint); + } #if MCA_BTL_TCP_ENDPOINT_CACHE - assert( 0 == btl_endpoint->endpoint_cache_length ); - data_still_pending_on_endpoint: -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ - /* check for completion of non-blocking recv on the current fragment */ - if(mca_btl_tcp_frag_recv(frag, btl_endpoint->endpoint_sd) == false) { - btl_endpoint->endpoint_recv_frag = frag; - } else { - btl_endpoint->endpoint_recv_frag = NULL; - if( MCA_BTL_TCP_HDR_TYPE_SEND == frag->hdr.type ) { - mca_btl_active_message_callback_t *reg = - mca_btl_base_active_message_trigger + frag->hdr.base.tag; - const mca_btl_base_receive_descriptor_t desc = - {.endpoint = btl_endpoint, + assert(0 == btl_endpoint->endpoint_cache_length); + data_still_pending_on_endpoint: +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ + /* check for completion of non-blocking recv on the current fragment */ + if (mca_btl_tcp_frag_recv(frag, btl_endpoint->endpoint_sd) == false) { + btl_endpoint->endpoint_recv_frag = frag; + } else { + btl_endpoint->endpoint_recv_frag = NULL; + if (MCA_BTL_TCP_HDR_TYPE_SEND == frag->hdr.type) { + mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + + frag->hdr.base.tag; + const mca_btl_base_receive_descriptor_t desc + = {.endpoint = btl_endpoint, .des_segments = frag->base.des_segments, .des_segment_count = frag->base.des_segment_count, .tag = frag->hdr.base.tag, .cbdata = reg->cbdata}; - reg->cbfunc(&frag->btl->super, &desc); - } -#if MCA_BTL_TCP_ENDPOINT_CACHE - if( 0 != btl_endpoint->endpoint_cache_length ) { - /* If the cache still contain some data we can reuse the same fragment - * until we flush it completly. - */ - MCA_BTL_TCP_FRAG_INIT_DST(frag, btl_endpoint); - goto data_still_pending_on_endpoint; - } -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ - MCA_BTL_TCP_FRAG_RETURN(frag); + reg->cbfunc(&frag->btl->super, &desc); } #if MCA_BTL_TCP_ENDPOINT_CACHE - assert( 0 == btl_endpoint->endpoint_cache_length ); -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ - OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); - break; + if (0 != btl_endpoint->endpoint_cache_length) { + /* If the cache still contain some data we can reuse the same fragment + * until we flush it completly. + */ + MCA_BTL_TCP_FRAG_INIT_DST(frag, btl_endpoint); + goto data_still_pending_on_endpoint; + } +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ + MCA_BTL_TCP_FRAG_RETURN(frag); } +#if MCA_BTL_TCP_ENDPOINT_CACHE + assert(0 == btl_endpoint->endpoint_cache_length); +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ + OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_recv_lock); + break; + } case MCA_BTL_TCP_CLOSED: /* This is a thread-safety issue. As multiple threads are allowed * to generate events (in the lib event) we endup with several @@ -1066,68 +1079,72 @@ static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void* user) } } - /* * A file descriptor is available/ready for send. Check the state * of the socket and take the appropriate action. */ -static void mca_btl_tcp_endpoint_send_handler(int sd, short flags, void* user) +static void mca_btl_tcp_endpoint_send_handler(int sd, short flags, void *user) { - mca_btl_tcp_endpoint_t* btl_endpoint = (mca_btl_tcp_endpoint_t *)user; + mca_btl_tcp_endpoint_t *btl_endpoint = (mca_btl_tcp_endpoint_t *) user; /* if another thread is already here, give up */ - if( OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_send_lock) ) + if (OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_send_lock)) { return; + } - switch(btl_endpoint->endpoint_state) { + switch (btl_endpoint->endpoint_state) { case MCA_BTL_TCP_CONNECTING: mca_btl_tcp_endpoint_complete_connect(btl_endpoint); break; case MCA_BTL_TCP_CONNECTED: /* complete the current send */ while (NULL != btl_endpoint->endpoint_send_frag) { - mca_btl_tcp_frag_t* frag = btl_endpoint->endpoint_send_frag; + mca_btl_tcp_frag_t *frag = btl_endpoint->endpoint_send_frag; int btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); assert(btl_endpoint->endpoint_state == MCA_BTL_TCP_CONNECTED); - if(mca_btl_tcp_frag_send(frag, btl_endpoint->endpoint_sd) == false) { + if (mca_btl_tcp_frag_send(frag, btl_endpoint->endpoint_sd) == false) { break; } /* progress any pending sends */ - btl_endpoint->endpoint_send_frag = (mca_btl_tcp_frag_t*) - opal_list_remove_first(&btl_endpoint->endpoint_frags); + btl_endpoint->endpoint_send_frag = (mca_btl_tcp_frag_t *) opal_list_remove_first( + &btl_endpoint->endpoint_frags); /* if required - update request status and release fragment */ OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); - assert( frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK ); + assert(frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK); if (NULL != frag->base.des_cbfunc) { frag->base.des_cbfunc(&frag->btl->super, frag->endpoint, &frag->base, frag->rc); } - if( btl_ownership ) { + if (btl_ownership) { MCA_BTL_TCP_FRAG_RETURN(frag); } /* if we fail to take the lock simply return. In the worst case the * send_handler will be triggered once more, and as there will be * nothing to send the handler will be deleted. */ - if( OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_send_lock) ) + if (OPAL_THREAD_TRYLOCK(&btl_endpoint->endpoint_send_lock)) { return; + } } /* if nothing else to do unregister for send event notifications */ - if(NULL == btl_endpoint->endpoint_send_frag) { - MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, false, "event_del(send) [endpoint_send_handler]"); + if (NULL == btl_endpoint->endpoint_send_frag) { + MCA_BTL_TCP_ENDPOINT_DUMP(10, btl_endpoint, false, + "event_del(send) [endpoint_send_handler]"); opal_event_del(&btl_endpoint->endpoint_send_event); } break; case MCA_BTL_TCP_FAILED: - MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, "event_del(send) [endpoint_send_handler:error]"); + MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, + "event_del(send) [endpoint_send_handler:error]"); opal_event_del(&btl_endpoint->endpoint_send_event); break; default: BTL_ERROR(("invalid connection state (%d)", btl_endpoint->endpoint_state)); - MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, "event_del(send) [endpoint_send_handler:error]"); + MCA_BTL_TCP_ENDPOINT_DUMP(1, btl_endpoint, true, + "event_del(send) [endpoint_send_handler:error]"); opal_event_del(&btl_endpoint->endpoint_send_event); break; } diff --git a/opal/mca/btl/tcp/btl_tcp_endpoint.h b/opal/mca/btl/tcp/btl_tcp_endpoint.h index 05318f393d6..8eaff79e8f3 100644 --- a/opal/mca/btl/tcp/btl_tcp_endpoint.h +++ b/opal/mca/btl/tcp/btl_tcp_endpoint.h @@ -21,13 +21,13 @@ #ifndef MCA_BTL_TCP_ENDPOINT_H #define MCA_BTL_TCP_ENDPOINT_H +#include "btl_tcp.h" +#include "btl_tcp_frag.h" #include "opal/class/opal_list.h" #include "opal/util/event.h" -#include "btl_tcp_frag.h" -#include "btl_tcp.h" BEGIN_C_DECLS -#define MCA_BTL_TCP_ENDPOINT_CACHE 1 +#define MCA_BTL_TCP_ENDPOINT_CACHE 1 #define MCA_BTL_TCP_MAGIC_STRING_LENGTH 16 /** * State of TCP endpoint connection. @@ -49,47 +49,48 @@ typedef enum { */ struct mca_btl_base_endpoint_t { - opal_list_item_t super; - struct mca_btl_tcp_module_t* endpoint_btl; /**< BTL instance that created this connection */ - struct mca_btl_tcp_proc_t* endpoint_proc; /**< proc structure corresponding to endpoint */ - struct mca_btl_tcp_addr_t* endpoint_addr; /**< address of endpoint */ - int endpoint_sd; /**< socket connection to endpoint */ - int endpoint_sd_next; /**< deadlock avoidance: socket connection to endpoint to set once the endpoint_sd has been correctly closed */ + opal_list_item_t super; + struct mca_btl_tcp_module_t *endpoint_btl; /**< BTL instance that created this connection */ + struct mca_btl_tcp_proc_t *endpoint_proc; /**< proc structure corresponding to endpoint */ + struct mca_btl_tcp_addr_t *endpoint_addr; /**< address of endpoint */ + int endpoint_sd; /**< socket connection to endpoint */ + int endpoint_sd_next; /**< deadlock avoidance: socket connection to endpoint to set once the + endpoint_sd has been correctly closed */ #if MCA_BTL_TCP_ENDPOINT_CACHE - char* endpoint_cache; /**< cache for the recv (reduce the number of recv syscall) */ - char* endpoint_cache_pos; /**< current position in the cache */ - size_t endpoint_cache_length; /**< length of the data in the cache */ -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ - struct mca_btl_tcp_frag_t* endpoint_send_frag; /**< current send frag being processed */ - struct mca_btl_tcp_frag_t* endpoint_recv_frag; /**< current recv frag being processed */ - mca_btl_tcp_state_t endpoint_state; /**< current state of the connection */ - uint32_t endpoint_retries; /**< number of connection retries attempted */ - opal_list_t endpoint_frags; /**< list of pending frags to send */ - opal_mutex_t endpoint_send_lock; /**< lock for concurrent access to endpoint state */ - opal_mutex_t endpoint_recv_lock; /**< lock for concurrent access to endpoint state */ - opal_event_t endpoint_accept_event; /**< event for async processing of accept requests */ - opal_event_t endpoint_send_event; /**< event for async processing of send frags */ - opal_event_t endpoint_recv_event; /**< event for async processing of recv frags */ - bool endpoint_nbo; /**< convert headers to network byte order? */ + char *endpoint_cache; /**< cache for the recv (reduce the number of recv syscall) */ + char *endpoint_cache_pos; /**< current position in the cache */ + size_t endpoint_cache_length; /**< length of the data in the cache */ +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ + struct mca_btl_tcp_frag_t *endpoint_send_frag; /**< current send frag being processed */ + struct mca_btl_tcp_frag_t *endpoint_recv_frag; /**< current recv frag being processed */ + mca_btl_tcp_state_t endpoint_state; /**< current state of the connection */ + uint32_t endpoint_retries; /**< number of connection retries attempted */ + opal_list_t endpoint_frags; /**< list of pending frags to send */ + opal_mutex_t endpoint_send_lock; /**< lock for concurrent access to endpoint state */ + opal_mutex_t endpoint_recv_lock; /**< lock for concurrent access to endpoint state */ + opal_event_t endpoint_accept_event; /**< event for async processing of accept requests */ + opal_event_t endpoint_send_event; /**< event for async processing of send frags */ + opal_event_t endpoint_recv_event; /**< event for async processing of recv frags */ + bool endpoint_nbo; /**< convert headers to network byte order? */ }; typedef struct mca_btl_base_endpoint_t mca_btl_base_endpoint_t; -typedef mca_btl_base_endpoint_t mca_btl_tcp_endpoint_t; +typedef mca_btl_base_endpoint_t mca_btl_tcp_endpoint_t; OBJ_CLASS_DECLARATION(mca_btl_tcp_endpoint_t); /* Magic socket handshake string */ extern const char mca_btl_tcp_magic_id_string[MCA_BTL_TCP_MAGIC_STRING_LENGTH]; -typedef struct { +typedef struct { opal_process_name_t guid; char magic_id[MCA_BTL_TCP_MAGIC_STRING_LENGTH]; } mca_btl_tcp_endpoint_hs_msg_t; void mca_btl_tcp_set_socket_options(int sd); -void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t*); -int mca_btl_tcp_endpoint_send(mca_btl_base_endpoint_t*, struct mca_btl_tcp_frag_t*); -void mca_btl_tcp_endpoint_accept(mca_btl_base_endpoint_t*, struct sockaddr*, int); -void mca_btl_tcp_endpoint_shutdown(mca_btl_base_endpoint_t*); +void mca_btl_tcp_endpoint_close(mca_btl_base_endpoint_t *); +int mca_btl_tcp_endpoint_send(mca_btl_base_endpoint_t *, struct mca_btl_tcp_frag_t *); +void mca_btl_tcp_endpoint_accept(mca_btl_base_endpoint_t *, struct sockaddr *, int); +void mca_btl_tcp_endpoint_shutdown(mca_btl_base_endpoint_t *); /* * Diagnostics: change this to "1" to enable the function @@ -98,12 +99,14 @@ void mca_btl_tcp_endpoint_shutdown(mca_btl_base_endpoint_t*); #define WANT_PEER_DUMP 0 #if OPAL_ENABLE_DEBUG && WANT_PEER_DUMP -#define MCA_BTL_TCP_ENDPOINT_DUMP(LEVEL, ENDPOINT, INFO, MSG) mca_btl_tcp_endpoint_dump((LEVEL), __FILE__, __LINE__, __func__, (ENDPOINT), (INFO), (MSG)) -void mca_btl_tcp_endpoint_dump(int level, const char* fname, int lineno, const char* funcname, - mca_btl_base_endpoint_t* btl_endpoint, bool full_info, const char* msg); +# define MCA_BTL_TCP_ENDPOINT_DUMP(LEVEL, ENDPOINT, INFO, MSG) \ + mca_btl_tcp_endpoint_dump((LEVEL), __FILE__, __LINE__, __func__, (ENDPOINT), (INFO), (MSG)) +void mca_btl_tcp_endpoint_dump(int level, const char *fname, int lineno, const char *funcname, + mca_btl_base_endpoint_t *btl_endpoint, bool full_info, + const char *msg); #else -#define MCA_BTL_TCP_ENDPOINT_DUMP(LEVEL, ENDPOINT, INFO, MSG) -#endif /* OPAL_ENABLE_DEBUG && WANT_PEER_DUMP */ +# define MCA_BTL_TCP_ENDPOINT_DUMP(LEVEL, ENDPOINT, INFO, MSG) +#endif /* OPAL_ENABLE_DEBUG && WANT_PEER_DUMP */ END_C_DECLS diff --git a/opal/mca/btl/tcp/btl_tcp_frag.c b/opal/mca/btl/tcp/btl_tcp_frag.c index 6e0ead7a386..e401a48b81e 100644 --- a/opal/mca/btl/tcp/btl_tcp_frag.c +++ b/opal/mca/btl/tcp/btl_tcp_frag.c @@ -31,89 +31,77 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_UIO_H -#include +# include #endif #ifdef HAVE_NET_UIO_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ -#include "opal/opal_socket_errno.h" #include "opal/mca/btl/base/btl_base_error.h" +#include "opal/opal_socket_errno.h" #include "opal/util/proc.h" #include "opal/util/show_help.h" -#include "btl_tcp_frag.h" -#include "btl_tcp_proc.h" #include "btl_tcp_endpoint.h" +#include "btl_tcp_frag.h" #include "btl_tcp_proc.h" - -static void mca_btl_tcp_frag_eager_constructor(mca_btl_tcp_frag_t* frag) +static void mca_btl_tcp_frag_eager_constructor(mca_btl_tcp_frag_t *frag) { frag->size = mca_btl_tcp_module.super.btl_eager_limit; frag->my_list = &mca_btl_tcp_component.tcp_frag_eager; } -static void mca_btl_tcp_frag_max_constructor(mca_btl_tcp_frag_t* frag) +static void mca_btl_tcp_frag_max_constructor(mca_btl_tcp_frag_t *frag) { frag->size = mca_btl_tcp_module.super.btl_max_send_size; frag->my_list = &mca_btl_tcp_component.tcp_frag_max; } -static void mca_btl_tcp_frag_user_constructor(mca_btl_tcp_frag_t* frag) +static void mca_btl_tcp_frag_user_constructor(mca_btl_tcp_frag_t *frag) { frag->size = 0; frag->my_list = &mca_btl_tcp_component.tcp_frag_user; } +OBJ_CLASS_INSTANCE(mca_btl_tcp_frag_t, mca_btl_base_descriptor_t, NULL, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_tcp_frag_t, - mca_btl_base_descriptor_t, - NULL, - NULL); - -OBJ_CLASS_INSTANCE( - mca_btl_tcp_frag_eager_t, - mca_btl_base_descriptor_t, - mca_btl_tcp_frag_eager_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_tcp_frag_eager_t, mca_btl_base_descriptor_t, + mca_btl_tcp_frag_eager_constructor, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_tcp_frag_max_t, - mca_btl_base_descriptor_t, - mca_btl_tcp_frag_max_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_tcp_frag_max_t, mca_btl_base_descriptor_t, + mca_btl_tcp_frag_max_constructor, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_tcp_frag_user_t, - mca_btl_base_descriptor_t, - mca_btl_tcp_frag_user_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_tcp_frag_user_t, mca_btl_base_descriptor_t, + mca_btl_tcp_frag_user_constructor, NULL); -size_t mca_btl_tcp_frag_dump(mca_btl_tcp_frag_t* frag, char* msg, char* buf, size_t length) +size_t mca_btl_tcp_frag_dump(mca_btl_tcp_frag_t *frag, char *msg, char *buf, size_t length) { int i, used; - used = snprintf(buf, length, "%s frag %p iov_cnt %d iov_idx %d size %lu\n", - msg, (void*)frag, (int)frag->iov_cnt, (int)frag->iov_idx, frag->size); - if ((size_t)used >= length) return length; - for( i = 0; i < (int)frag->iov_cnt; i++ ) { + used = snprintf(buf, length, "%s frag %p iov_cnt %d iov_idx %d size %lu\n", msg, (void *) frag, + (int) frag->iov_cnt, (int) frag->iov_idx, frag->size); + if ((size_t) used >= length) { + return length; + } + for (i = 0; i < (int) frag->iov_cnt; i++) { used += snprintf(&buf[used], length - used, "[%s%p:%lu] ", - (i < (int)frag->iov_idx ? "*" : ""), - frag->iov[i].iov_base, frag->iov[i].iov_len); - if ((size_t)used >= length) return length; + (i < (int) frag->iov_idx ? "*" : ""), frag->iov[i].iov_base, + frag->iov[i].iov_len); + if ((size_t) used >= length) { + return length; + } } return used; } -bool mca_btl_tcp_frag_send(mca_btl_tcp_frag_t* frag, int sd) +bool mca_btl_tcp_frag_send(mca_btl_tcp_frag_t *frag, int sd) { ssize_t cnt; size_t i, num_vecs; @@ -121,75 +109,76 @@ bool mca_btl_tcp_frag_send(mca_btl_tcp_frag_t* frag, int sd) /* non-blocking write, but continue if interrupted */ do { cnt = writev(sd, frag->iov_ptr, frag->iov_cnt); - if(cnt < 0) { - switch(opal_socket_errno) { + if (cnt < 0) { + switch (opal_socket_errno) { case EINTR: continue; case EWOULDBLOCK: return false; case EFAULT: BTL_ERROR(("mca_btl_tcp_frag_send: writev error (%p, %lu)\n\t%s(%lu)\n", - frag->iov_ptr[0].iov_base, (unsigned long) frag->iov_ptr[0].iov_len, - strerror(opal_socket_errno), (unsigned long) frag->iov_cnt)); + frag->iov_ptr[0].iov_base, (unsigned long) frag->iov_ptr[0].iov_len, + strerror(opal_socket_errno), (unsigned long) frag->iov_cnt)); /* send_lock held by caller */ frag->endpoint->endpoint_state = MCA_BTL_TCP_FAILED; mca_btl_tcp_endpoint_close(frag->endpoint); return false; default: - BTL_PEER_ERROR(frag->endpoint->endpoint_proc->proc_opal, ("mca_btl_tcp_frag_send: writev failed: %s (%d)", - strerror(opal_socket_errno), - opal_socket_errno)); + BTL_PEER_ERROR(frag->endpoint->endpoint_proc->proc_opal, + ("mca_btl_tcp_frag_send: writev failed: %s (%d)", + strerror(opal_socket_errno), opal_socket_errno)); /* send_lock held by caller */ frag->endpoint->endpoint_state = MCA_BTL_TCP_FAILED; mca_btl_tcp_endpoint_close(frag->endpoint); return false; } } - } while(cnt < 0); + } while (cnt < 0); /* if the write didn't complete - update the iovec state */ num_vecs = frag->iov_cnt; - for( i = 0; i < num_vecs; i++) { - if(cnt >= (ssize_t)frag->iov_ptr->iov_len) { + for (i = 0; i < num_vecs; i++) { + if (cnt >= (ssize_t) frag->iov_ptr->iov_len) { cnt -= frag->iov_ptr->iov_len; frag->iov_ptr++; frag->iov_idx++; frag->iov_cnt--; } else { - frag->iov_ptr->iov_base = (opal_iov_base_ptr_t) - (((unsigned char*)frag->iov_ptr->iov_base) + cnt); + frag->iov_ptr->iov_base = (opal_iov_base_ptr_t)( + ((unsigned char *) frag->iov_ptr->iov_base) + cnt); frag->iov_ptr->iov_len -= cnt; OPAL_OUTPUT_VERBOSE((100, opal_btl_base_framework.framework_output, - "%s:%d write %ld bytes on socket %d\n", - __FILE__, __LINE__, cnt, sd)); + "%s:%d write %ld bytes on socket %d\n", __FILE__, __LINE__, cnt, + sd)); break; } } return (frag->iov_cnt == 0); } -bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) +bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t *frag, int sd) { - mca_btl_base_endpoint_t* btl_endpoint = frag->endpoint; + mca_btl_base_endpoint_t *btl_endpoint = frag->endpoint; ssize_t cnt; int32_t i, num_vecs, dont_copy_data = 0; char *errhost; - repeat: +repeat: num_vecs = frag->iov_cnt; #if MCA_BTL_TCP_ENDPOINT_CACHE - if( 0 != btl_endpoint->endpoint_cache_length ) { + if (0 != btl_endpoint->endpoint_cache_length) { size_t length; /* It's strange at the first look but cnt have to be set to the full amount of data * available. After going to advance_iov_position we will use cnt to detect if there * is still some data pending. */ cnt = length = btl_endpoint->endpoint_cache_length; - for( i = 0; i < (int)frag->iov_cnt; i++ ) { - if( length > frag->iov_ptr[i].iov_len ) + for (i = 0; i < (int) frag->iov_cnt; i++) { + if (length > frag->iov_ptr[i].iov_len) { length = frag->iov_ptr[i].iov_len; - if( (0 == dont_copy_data) || (length < frag->iov_ptr[i].iov_len) ) { - memcpy( frag->iov_ptr[i].iov_base, btl_endpoint->endpoint_cache_pos, length ); + } + if ((0 == dont_copy_data) || (length < frag->iov_ptr[i].iov_len)) { + memcpy(frag->iov_ptr[i].iov_base, btl_endpoint->endpoint_cache_pos, length); } else { frag->segments[0].seg_addr.pval = btl_endpoint->endpoint_cache_pos; frag->iov_ptr[i].iov_base = btl_endpoint->endpoint_cache_pos; @@ -197,7 +186,7 @@ bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) btl_endpoint->endpoint_cache_pos += length; btl_endpoint->endpoint_cache_length -= length; length = btl_endpoint->endpoint_cache_length; - if( 0 == length ) { + if (0 == length) { btl_endpoint->endpoint_cache_pos = btl_endpoint->endpoint_cache; break; } @@ -208,24 +197,27 @@ bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) * iovec for the caching in the fragment structure (the +1). */ frag->iov_ptr[num_vecs].iov_base = btl_endpoint->endpoint_cache_pos; - frag->iov_ptr[num_vecs].iov_len = - mca_btl_tcp_component.tcp_endpoint_cache - btl_endpoint->endpoint_cache_length; + frag->iov_ptr[num_vecs].iov_len = mca_btl_tcp_component.tcp_endpoint_cache + - btl_endpoint->endpoint_cache_length; num_vecs++; -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ /* non-blocking read, but continue if interrupted */ do { cnt = readv(sd, frag->iov_ptr, num_vecs); - if( 0 < cnt ) goto advance_iov_position; - if( cnt == 0 ) { + if (0 < cnt) { + goto advance_iov_position; + } + if (cnt == 0) { OPAL_THREAD_LOCK(&btl_endpoint->endpoint_send_lock); - if(MCA_BTL_TCP_CONNECTED == btl_endpoint->endpoint_state) + if (MCA_BTL_TCP_CONNECTED == btl_endpoint->endpoint_state) { btl_endpoint->endpoint_state = MCA_BTL_TCP_FAILED; + } mca_btl_tcp_endpoint_close(btl_endpoint); OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); return false; } - switch(opal_socket_errno) { + switch (opal_socket_errno) { case EINTR: continue; case EWOULDBLOCK: @@ -236,19 +228,17 @@ bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) strerror(opal_socket_errno), (unsigned long) frag->iov_cnt)); break; case ECONNRESET: - if( mca_btl_base_warn_peer_error - || mca_btl_base_verbose > 0 ) { + if (mca_btl_base_warn_peer_error || mca_btl_base_verbose > 0) { errhost = opal_get_proc_hostname(btl_endpoint->endpoint_proc->proc_opal); - opal_show_help("help-mpi-btl-tcp.txt", "peer hung up", - true, opal_process_info.nodename, - getpid(), errhost); + opal_show_help("help-mpi-btl-tcp.txt", "peer hung up", true, + opal_process_info.nodename, getpid(), errhost); free(errhost); } break; default: - BTL_PEER_ERROR(frag->endpoint->endpoint_proc->proc_opal, ("mca_btl_tcp_frag_recv: readv failed: %s (%d)", - strerror(opal_socket_errno), - opal_socket_errno)); + BTL_PEER_ERROR(frag->endpoint->endpoint_proc->proc_opal, + ("mca_btl_tcp_frag_recv: readv failed: %s (%d)", + strerror(opal_socket_errno), opal_socket_errno)); break; } OPAL_THREAD_LOCK(&btl_endpoint->endpoint_send_lock); @@ -256,15 +246,15 @@ bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) mca_btl_tcp_endpoint_close(btl_endpoint); OPAL_THREAD_UNLOCK(&btl_endpoint->endpoint_send_lock); return false; - } while( cnt < 0 ); + } while (cnt < 0); - advance_iov_position: +advance_iov_position: /* if the read didn't complete - update the iovec state */ num_vecs = frag->iov_cnt; - for( i = 0; i < num_vecs; i++ ) { - if( cnt < (ssize_t)frag->iov_ptr->iov_len ) { - frag->iov_ptr->iov_base = (opal_iov_base_ptr_t) - (((unsigned char*)frag->iov_ptr->iov_base) + cnt); + for (i = 0; i < num_vecs; i++) { + if (cnt < (ssize_t) frag->iov_ptr->iov_len) { + frag->iov_ptr->iov_base = (opal_iov_base_ptr_t)( + ((unsigned char *) frag->iov_ptr->iov_base) + cnt); frag->iov_ptr->iov_len -= cnt; cnt = 0; break; @@ -276,37 +266,41 @@ bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) } #if MCA_BTL_TCP_ENDPOINT_CACHE btl_endpoint->endpoint_cache_length = cnt; -#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ +#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */ /* read header */ - if(frag->iov_cnt == 0) { - if (btl_endpoint->endpoint_nbo && frag->iov_idx == 1) MCA_BTL_TCP_HDR_NTOH(frag->hdr); - switch(frag->hdr.type) { + if (frag->iov_cnt == 0) { + if (btl_endpoint->endpoint_nbo && frag->iov_idx == 1) { + MCA_BTL_TCP_HDR_NTOH(frag->hdr); + } + switch (frag->hdr.type) { case MCA_BTL_TCP_HDR_TYPE_FIN: frag->endpoint->endpoint_state = MCA_BTL_TCP_CLOSED; mca_btl_tcp_endpoint_close(frag->endpoint); break; case MCA_BTL_TCP_HDR_TYPE_SEND: - if(frag->iov_idx == 1 && frag->hdr.size) { - frag->segments[0].seg_addr.pval = frag+1; + if (frag->iov_idx == 1 && frag->hdr.size) { + frag->segments[0].seg_addr.pval = frag + 1; frag->segments[0].seg_len = frag->hdr.size; - frag->iov[1].iov_base = (IOVBASE_TYPE*)(frag->segments[0].seg_addr.pval); + frag->iov[1].iov_base = (IOVBASE_TYPE *) (frag->segments[0].seg_addr.pval); frag->iov[1].iov_len = frag->hdr.size; frag->iov_cnt++; goto repeat; } break; case MCA_BTL_TCP_HDR_TYPE_PUT: - if(frag->iov_idx == 1) { - frag->iov[1].iov_base = (IOVBASE_TYPE*)frag->segments; + if (frag->iov_idx == 1) { + frag->iov[1].iov_base = (IOVBASE_TYPE *) frag->segments; frag->iov[1].iov_len = frag->hdr.count * sizeof(mca_btl_base_segment_t); frag->iov_cnt++; goto repeat; } else if (frag->iov_idx == 2) { - for( i = 0; i < frag->hdr.count; i++ ) { - if (btl_endpoint->endpoint_nbo) MCA_BTL_BASE_SEGMENT_NTOH(frag->segments[i]); - frag->iov[i+2].iov_base = (IOVBASE_TYPE*)frag->segments[i].seg_addr.pval; - frag->iov[i+2].iov_len = frag->segments[i].seg_len; + for (i = 0; i < frag->hdr.count; i++) { + if (btl_endpoint->endpoint_nbo) { + MCA_BTL_BASE_SEGMENT_NTOH(frag->segments[i]); + } + frag->iov[i + 2].iov_base = (IOVBASE_TYPE *) frag->segments[i].seg_addr.pval; + frag->iov[i + 2].iov_len = frag->segments[i].seg_len; } frag->iov_cnt += frag->hdr.count; goto repeat; @@ -320,4 +314,3 @@ bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd) } return false; } - diff --git a/opal/mca/btl/tcp/btl_tcp_frag.h b/opal/mca/btl/tcp/btl_tcp_frag.h index e1b068502f9..d26abbfbe08 100644 --- a/opal/mca/btl/tcp/btl_tcp_frag.h +++ b/opal/mca/btl/tcp/btl_tcp_frag.h @@ -22,17 +22,16 @@ #ifndef MCA_BTL_TCP_FRAG_H #define MCA_BTL_TCP_FRAG_H - #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_UIO_H -#include +# include #endif #ifdef HAVE_NET_UIO_H -#include +# include #endif #include "btl_tcp.h" @@ -40,7 +39,7 @@ BEGIN_C_DECLS -#define MCA_BTL_TCP_FRAG_IOVEC_NUMBER 4 +#define MCA_BTL_TCP_FRAG_IOVEC_NUMBER 4 /** * TCP fragment derived type. @@ -49,7 +48,7 @@ struct mca_btl_tcp_frag_t { mca_btl_base_descriptor_t base; mca_btl_base_segment_t segments[2]; struct mca_btl_base_endpoint_t *endpoint; - struct mca_btl_tcp_module_t* btl; + struct mca_btl_tcp_module_t *btl; mca_btl_tcp_hdr_t hdr; struct iovec iov[MCA_BTL_TCP_FRAG_IOVEC_NUMBER + 1]; struct iovec *iov_ptr; @@ -58,7 +57,7 @@ struct mca_btl_tcp_frag_t { size_t size; uint16_t next_step; int rc; - opal_free_list_t* my_list; + opal_free_list_t *my_list; /* fake rdma completion */ struct { mca_btl_base_rdma_completion_fn_t func; @@ -81,52 +80,47 @@ typedef struct mca_btl_tcp_frag_t mca_btl_tcp_frag_user_t; OBJ_CLASS_DECLARATION(mca_btl_tcp_frag_user_t); - /* * Macros to allocate/return descriptors from module specific * free list(s). */ -#define MCA_BTL_TCP_FRAG_ALLOC_EAGER(frag) \ -{ \ - frag = (mca_btl_tcp_frag_t*) \ - opal_free_list_get (&mca_btl_tcp_component.tcp_frag_eager); \ -} - -#define MCA_BTL_TCP_FRAG_ALLOC_MAX(frag) \ -{ \ - frag = (mca_btl_tcp_frag_t*) \ - opal_free_list_get (&mca_btl_tcp_component.tcp_frag_max); \ -} - -#define MCA_BTL_TCP_FRAG_ALLOC_USER(frag) \ -{ \ - frag = (mca_btl_tcp_frag_t*) \ - opal_free_list_get (&mca_btl_tcp_component.tcp_frag_user); \ -} - -#define MCA_BTL_TCP_FRAG_RETURN(frag) \ -{ \ - opal_free_list_return (frag->my_list, (opal_free_list_item_t*)(frag)); \ -} - -#define MCA_BTL_TCP_FRAG_INIT_DST(frag,ep) \ -do { \ - frag->rc = 0; \ - frag->btl = ep->endpoint_btl; \ - frag->endpoint = ep; \ - frag->iov[0].iov_len = sizeof(frag->hdr); \ - frag->iov[0].iov_base = (IOVBASE_TYPE*)&frag->hdr; \ - frag->iov_cnt = 1; \ - frag->iov_idx = 0; \ - frag->iov_ptr = frag->iov; \ - frag->base.des_segments = frag->segments; \ - frag->base.des_segment_count = 1; \ -} while(0) - - -bool mca_btl_tcp_frag_send(mca_btl_tcp_frag_t*, int sd); -bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t*, int sd); -size_t mca_btl_tcp_frag_dump(mca_btl_tcp_frag_t* frag, char* msg, char* buf, size_t length); +#define MCA_BTL_TCP_FRAG_ALLOC_EAGER(frag) \ + { \ + frag = (mca_btl_tcp_frag_t *) opal_free_list_get(&mca_btl_tcp_component.tcp_frag_eager); \ + } + +#define MCA_BTL_TCP_FRAG_ALLOC_MAX(frag) \ + { \ + frag = (mca_btl_tcp_frag_t *) opal_free_list_get(&mca_btl_tcp_component.tcp_frag_max); \ + } + +#define MCA_BTL_TCP_FRAG_ALLOC_USER(frag) \ + { \ + frag = (mca_btl_tcp_frag_t *) opal_free_list_get(&mca_btl_tcp_component.tcp_frag_user); \ + } + +#define MCA_BTL_TCP_FRAG_RETURN(frag) \ + { \ + opal_free_list_return(frag->my_list, (opal_free_list_item_t *) (frag)); \ + } + +#define MCA_BTL_TCP_FRAG_INIT_DST(frag, ep) \ + do { \ + frag->rc = 0; \ + frag->btl = ep->endpoint_btl; \ + frag->endpoint = ep; \ + frag->iov[0].iov_len = sizeof(frag->hdr); \ + frag->iov[0].iov_base = (IOVBASE_TYPE *) &frag->hdr; \ + frag->iov_cnt = 1; \ + frag->iov_idx = 0; \ + frag->iov_ptr = frag->iov; \ + frag->base.des_segments = frag->segments; \ + frag->base.des_segment_count = 1; \ + } while (0) + +bool mca_btl_tcp_frag_send(mca_btl_tcp_frag_t *, int sd); +bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t *, int sd); +size_t mca_btl_tcp_frag_dump(mca_btl_tcp_frag_t *frag, char *msg, char *buf, size_t length); END_C_DECLS #endif diff --git a/opal/mca/btl/tcp/btl_tcp_hdr.h b/opal/mca/btl/tcp/btl_tcp_hdr.h index cd907cb3b99..69ec22f6fdf 100644 --- a/opal/mca/btl/tcp/btl_tcp_hdr.h +++ b/opal/mca/btl/tcp/btl_tcp_hdr.h @@ -19,10 +19,9 @@ #ifndef MCA_BTL_TCP_HDR_H #define MCA_BTL_TCP_HDR_H - #include "opal_config.h" -#include "opal/mca/btl/base/base.h" #include "btl_tcp.h" +#include "opal/mca/btl/base/base.h" BEGIN_C_DECLS @@ -48,7 +47,7 @@ BEGIN_C_DECLS struct mca_btl_tcp_hdr_t { mca_btl_base_header_t base; - uint8_t type; + uint8_t type; uint16_t count; uint32_t size; }; diff --git a/opal/mca/btl/tcp/btl_tcp_proc.c b/opal/mca/btl/tcp/btl_tcp_proc.c index 20c7e22d85b..24129c8c633 100644 --- a/opal/mca/btl/tcp/btl_tcp_proc.c +++ b/opal/mca/btl/tcp/btl_tcp_proc.c @@ -31,44 +31,41 @@ #include "opal_config.h" #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #include "opal/class/opal_hash_table.h" #include "opal/mca/btl/base/btl_base_error.h" -#include "opal/mca/reachable/base/base.h" #include "opal/mca/pmix/pmix-internal.h" +#include "opal/mca/reachable/base/base.h" #include "opal/util/arch.h" #include "opal/util/argv.h" +#include "opal/util/bipartite_graph.h" #include "opal/util/if.h" #include "opal/util/net.h" -#include "opal/util/proc.h" -#include "opal/util/show_help.h" #include "opal/util/printf.h" #include "opal/util/proc.h" +#include "opal/util/show_help.h" #include "opal/util/string_copy.h" -#include "opal/util/bipartite_graph.h" #include "btl_tcp.h" #include "btl_tcp_proc.h" -static void mca_btl_tcp_proc_construct(mca_btl_tcp_proc_t* proc); -static void mca_btl_tcp_proc_destruct(mca_btl_tcp_proc_t* proc); +static void mca_btl_tcp_proc_construct(mca_btl_tcp_proc_t *proc); +static void mca_btl_tcp_proc_destruct(mca_btl_tcp_proc_t *proc); -OBJ_CLASS_INSTANCE( mca_btl_tcp_proc_t, - opal_list_item_t, - mca_btl_tcp_proc_construct, - mca_btl_tcp_proc_destruct ); +OBJ_CLASS_INSTANCE(mca_btl_tcp_proc_t, opal_list_item_t, mca_btl_tcp_proc_construct, + mca_btl_tcp_proc_destruct); -void mca_btl_tcp_proc_construct(mca_btl_tcp_proc_t* tcp_proc) +void mca_btl_tcp_proc_construct(mca_btl_tcp_proc_t *tcp_proc) { - tcp_proc->proc_opal = NULL; - tcp_proc->proc_addrs = NULL; - tcp_proc->proc_addr_count = 0; - tcp_proc->proc_endpoints = NULL; + tcp_proc->proc_opal = NULL; + tcp_proc->proc_addrs = NULL; + tcp_proc->proc_addr_count = 0; + tcp_proc->proc_endpoints = NULL; tcp_proc->proc_endpoint_count = 0; OBJ_CONSTRUCT(&tcp_proc->proc_lock, opal_mutex_t); OBJ_CONSTRUCT(&tcp_proc->btl_index_to_endpoint, opal_hash_table_t); @@ -79,9 +76,9 @@ void mca_btl_tcp_proc_construct(mca_btl_tcp_proc_t* tcp_proc) * Cleanup ib proc instance */ -void mca_btl_tcp_proc_destruct(mca_btl_tcp_proc_t* tcp_proc) +void mca_btl_tcp_proc_destruct(mca_btl_tcp_proc_t *tcp_proc) { - if( NULL != tcp_proc->proc_opal ) { + if (NULL != tcp_proc->proc_opal) { /* remove from list of all proc instances */ OPAL_THREAD_LOCK(&mca_btl_tcp_component.tcp_lock); opal_proc_table_remove_value(&mca_btl_tcp_component.tcp_procs, @@ -91,18 +88,17 @@ void mca_btl_tcp_proc_destruct(mca_btl_tcp_proc_t* tcp_proc) tcp_proc->proc_opal = NULL; } /* release resources */ - if(NULL != tcp_proc->proc_endpoints) { + if (NULL != tcp_proc->proc_endpoints) { free(tcp_proc->proc_endpoints); } - if(NULL != tcp_proc->proc_addrs) { + if (NULL != tcp_proc->proc_addrs) { free(tcp_proc->proc_addrs); } OBJ_DESTRUCT(&tcp_proc->btl_index_to_endpoint); OBJ_DESTRUCT(&tcp_proc->proc_lock); } -static inline int mca_btl_tcp_proc_is_proc_left(opal_process_name_t a, - opal_process_name_t b) +static inline int mca_btl_tcp_proc_is_proc_left(opal_process_name_t a, opal_process_name_t b) { if (a.jobid != b.jobid) { return (a.jobid < b.jobid); @@ -111,7 +107,7 @@ static inline int mca_btl_tcp_proc_is_proc_left(opal_process_name_t a, } } -#define MCA_BTL_TCP_PROC_LOCAL_VERTEX(index) (index) +#define MCA_BTL_TCP_PROC_LOCAL_VERTEX(index) (index) #define MCA_BTL_TCP_PROC_REMOTE_VERTEX(index) (index + mca_btl_tcp_component.tcp_num_btls) /* This function builds a graph to match local and remote interfaces @@ -142,8 +138,8 @@ static inline int mca_btl_tcp_proc_is_proc_left(opal_process_name_t a, * This allows us to pass the correct pointers to the vertex data for storage. * */ -static int mca_btl_tcp_proc_create_interface_graph(mca_btl_tcp_proc_t* btl_proc, - mca_btl_tcp_modex_addr_t* remote_addrs, +static int mca_btl_tcp_proc_create_interface_graph(mca_btl_tcp_proc_t *btl_proc, + mca_btl_tcp_modex_addr_t *remote_addrs, int local_proc_is_left, opal_bp_graph_t **graph_out) { @@ -162,7 +158,7 @@ static int mca_btl_tcp_proc_create_interface_graph(mca_btl_tcp_proc_t* btl_proc, /* the modex and proc structures differ slightly, so copy the fields needed in the proc version */ - for (i = 0 ; i < btl_proc->proc_addr_count ; i++) { + for (i = 0; i < btl_proc->proc_addr_count; i++) { /* Construct opal_if_t objects for the remote interfaces */ opal_if_t *interface = OBJ_NEW(opal_if_t); if (NULL == interface) { @@ -171,32 +167,31 @@ static int mca_btl_tcp_proc_create_interface_graph(mca_btl_tcp_proc_t* btl_proc, } if (MCA_BTL_TCP_AF_INET == remote_addrs[i].addr_family) { - memcpy(&btl_proc->proc_addrs[i].addr_union.addr_inet, - remote_addrs[i].addr, sizeof(struct in_addr)); + memcpy(&btl_proc->proc_addrs[i].addr_union.addr_inet, remote_addrs[i].addr, + sizeof(struct in_addr)); btl_proc->proc_addrs[i].addr_family = AF_INET; - memcpy(&((struct sockaddr_in *)&(interface->if_addr))->sin_addr, - remote_addrs[i].addr, sizeof(struct in_addr)); - ((struct sockaddr *)&(interface->if_addr))->sa_family = AF_INET; - interface->af_family = AF_INET; + memcpy(&((struct sockaddr_in *) &(interface->if_addr))->sin_addr, remote_addrs[i].addr, + sizeof(struct in_addr)); + ((struct sockaddr *) &(interface->if_addr))->sa_family = AF_INET; + interface->af_family = AF_INET; } else if (MCA_BTL_TCP_AF_INET6 == remote_addrs[i].addr_family) { #if OPAL_ENABLE_IPV6 - memcpy(&btl_proc->proc_addrs[i].addr_union.addr_inet6, - remote_addrs[i].addr, sizeof(struct in6_addr)); + memcpy(&btl_proc->proc_addrs[i].addr_union.addr_inet6, remote_addrs[i].addr, + sizeof(struct in6_addr)); btl_proc->proc_addrs[i].addr_family = AF_INET6; - memcpy(&((struct sockaddr_in6 *)&(interface->if_addr))->sin6_addr, + memcpy(&((struct sockaddr_in6 *) &(interface->if_addr))->sin6_addr, remote_addrs[i].addr, sizeof(struct in6_addr)); - ((struct sockaddr *)&(interface->if_addr))->sa_family = AF_INET6; - interface->af_family = AF_INET6; + ((struct sockaddr *) &(interface->if_addr))->sa_family = AF_INET6; + interface->af_family = AF_INET6; #else rc = OPAL_ERR_NOT_SUPPORTED; OBJ_RELEASE(interface); goto out; #endif } else { - BTL_ERROR(("Unexpected address family %d", - (int)remote_addrs[i].addr_family)); + BTL_ERROR(("Unexpected address family %d", (int) remote_addrs[i].addr_family)); rc = OPAL_ERR_BAD_PARAM; OBJ_RELEASE(interface); goto out; @@ -223,7 +218,8 @@ static int mca_btl_tcp_proc_create_interface_graph(mca_btl_tcp_proc_t* btl_proc, /* Add vertices for each local node. These will store the btl index */ for (x = 0; x < results->num_local; x++) { - rc = opal_bp_graph_add_vertex(graph, &mca_btl_tcp_component.tcp_btls[x]->btl_index, &v_index); + rc = opal_bp_graph_add_vertex(graph, &mca_btl_tcp_component.tcp_btls[x]->btl_index, + &v_index); if (OPAL_SUCCESS != rc) { goto err_graph; } @@ -292,45 +288,45 @@ static int mca_btl_tcp_proc_create_interface_graph(mca_btl_tcp_proc_t* btl_proc, * a pointer to a mca_btl_tcp_addr_t struct. */ static int mca_btl_tcp_proc_store_matched_interfaces(mca_btl_tcp_proc_t *btl_proc, - int local_proc_is_left, - opal_bp_graph_t *graph, + int local_proc_is_left, opal_bp_graph_t *graph, int num_matched, int *matched_edges) { int rc = OPAL_SUCCESS; int i, left, right; - uint32_t* local_index; + uint32_t *local_index; struct mca_btl_tcp_addr_t *remote_addr; for (i = 0; i < num_matched; i++) { - left = matched_edges[2 * i + 0]; + left = matched_edges[2 * i + 0]; right = matched_edges[2 * i + 1]; if (local_proc_is_left) { - rc = opal_bp_graph_get_vertex_data(graph, left, (void *)&local_index); + rc = opal_bp_graph_get_vertex_data(graph, left, (void *) &local_index); if (OPAL_SUCCESS != rc) { goto out; } - rc = opal_bp_graph_get_vertex_data(graph, right, (void *)&remote_addr); + rc = opal_bp_graph_get_vertex_data(graph, right, (void *) &remote_addr); if (OPAL_SUCCESS != rc) { goto out; } } else { - rc = opal_bp_graph_get_vertex_data(graph, right, (void *)&local_index); + rc = opal_bp_graph_get_vertex_data(graph, right, (void *) &local_index); if (OPAL_SUCCESS != rc) { goto out; } - rc = opal_bp_graph_get_vertex_data(graph, left, (void *)&remote_addr); + rc = opal_bp_graph_get_vertex_data(graph, left, (void *) &remote_addr); if (OPAL_SUCCESS != rc) { goto out; } } - opal_hash_table_set_value_uint32(&btl_proc->btl_index_to_endpoint, *local_index, (void *)remote_addr); + opal_hash_table_set_value_uint32(&btl_proc->btl_index_to_endpoint, *local_index, + (void *) remote_addr); } out: return rc; } -static int mca_btl_tcp_proc_handle_modex_addresses(mca_btl_tcp_proc_t* btl_proc, - mca_btl_tcp_modex_addr_t* remote_addrs, +static int mca_btl_tcp_proc_handle_modex_addresses(mca_btl_tcp_proc_t *btl_proc, + mca_btl_tcp_modex_addr_t *remote_addrs, int local_proc_is_left) { opal_bp_graph_t *graph = NULL; @@ -338,7 +334,8 @@ static int mca_btl_tcp_proc_handle_modex_addresses(mca_btl_tcp_proc_t* btl_proc, int num_matched = 0; int *matched_edges = NULL; - rc = mca_btl_tcp_proc_create_interface_graph(btl_proc, remote_addrs, local_proc_is_left, &graph); + rc = mca_btl_tcp_proc_create_interface_graph(btl_proc, remote_addrs, local_proc_is_left, + &graph); if (rc) { goto cleanup; } @@ -348,8 +345,8 @@ static int mca_btl_tcp_proc_handle_modex_addresses(mca_btl_tcp_proc_t* btl_proc, goto cleanup; } - rc = mca_btl_tcp_proc_store_matched_interfaces(btl_proc, local_proc_is_left, - graph, num_matched, matched_edges); + rc = mca_btl_tcp_proc_store_matched_interfaces(btl_proc, local_proc_is_left, graph, num_matched, + matched_edges); if (rc) { goto cleanup; } @@ -369,16 +366,16 @@ static int mca_btl_tcp_proc_handle_modex_addresses(mca_btl_tcp_proc_t* btl_proc, * datastructure. */ -mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) +mca_btl_tcp_proc_t *mca_btl_tcp_proc_create(opal_proc_t *proc) { - mca_btl_tcp_proc_t* btl_proc; + mca_btl_tcp_proc_t *btl_proc; int rc, local_proc_is_left; mca_btl_tcp_modex_addr_t *remote_addrs = NULL; size_t size; OPAL_THREAD_LOCK(&mca_btl_tcp_component.tcp_lock); - rc = opal_proc_table_get_value(&mca_btl_tcp_component.tcp_procs, - proc->proc_name, (void**)&btl_proc); + rc = opal_proc_table_get_value(&mca_btl_tcp_component.tcp_procs, proc->proc_name, + (void **) &btl_proc); if (OPAL_SUCCESS == rc) { OPAL_THREAD_UNLOCK(&mca_btl_tcp_component.tcp_lock); return btl_proc; @@ -398,8 +395,8 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) OBJ_RETAIN(proc); /* lookup tcp parameters exported by this proc */ - OPAL_MODEX_RECV(rc, &mca_btl_tcp_component.super.btl_version, - &proc->proc_name, (uint8_t**)&remote_addrs, &size); + OPAL_MODEX_RECV(rc, &mca_btl_tcp_component.super.btl_version, &proc->proc_name, + (uint8_t **) &remote_addrs, &size); if (OPAL_SUCCESS != rc) { if (OPAL_ERR_NOT_FOUND != rc) { BTL_ERROR(("opal_modex_recv: failed with return value=%d", rc)); @@ -408,16 +405,14 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) } if (0 != (size % sizeof(mca_btl_tcp_modex_addr_t))) { - BTL_ERROR(("opal_modex_recv: invalid size %lu: btl-size: %lu\n", - (unsigned long)size, - (unsigned long)sizeof(mca_btl_tcp_modex_addr_t))); + BTL_ERROR(("opal_modex_recv: invalid size %lu: btl-size: %lu\n", (unsigned long) size, + (unsigned long) sizeof(mca_btl_tcp_modex_addr_t))); rc = OPAL_ERROR; goto cleanup; } btl_proc->proc_addr_count = size / sizeof(mca_btl_tcp_modex_addr_t); - btl_proc->proc_addrs = malloc(btl_proc->proc_addr_count * - sizeof(mca_btl_tcp_addr_t)); + btl_proc->proc_addrs = malloc(btl_proc->proc_addr_count * sizeof(mca_btl_tcp_addr_t)); if (NULL == btl_proc->proc_addrs) { rc = OPAL_ERR_OUT_OF_RESOURCE; goto cleanup; @@ -432,7 +427,8 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) * The concept of mirroring the local and remote sides is borrowed * from the usnic btl implementation of its bipartite assignment solver. */ - local_proc_is_left = mca_btl_tcp_proc_is_proc_left(proc->proc_name, opal_proc_local_get()->proc_name); + local_proc_is_left = mca_btl_tcp_proc_is_proc_left(proc->proc_name, + opal_proc_local_get()->proc_name); rc = mca_btl_tcp_proc_handle_modex_addresses(btl_proc, remote_addrs, local_proc_is_left); if (OPAL_SUCCESS != rc) { @@ -440,9 +436,8 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) } /* allocate space for endpoint array - one for each exported address */ - btl_proc->proc_endpoints = (mca_btl_base_endpoint_t**) - malloc((1 + btl_proc->proc_addr_count) * - sizeof(mca_btl_base_endpoint_t*)); + btl_proc->proc_endpoints = (mca_btl_base_endpoint_t **) malloc( + (1 + btl_proc->proc_addr_count) * sizeof(mca_btl_base_endpoint_t *)); if (NULL == btl_proc->proc_endpoints) { rc = OPAL_ERR_OUT_OF_RESOURCE; goto cleanup; @@ -450,14 +445,13 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) cleanup: if (OPAL_SUCCESS == rc) { - btl_proc->proc_opal = proc; /* link with the proc */ + btl_proc->proc_opal = proc; /* link with the proc */ /* add to hash table of all proc instance. */ - opal_proc_table_set_value(&mca_btl_tcp_component.tcp_procs, - proc->proc_name, btl_proc); + opal_proc_table_set_value(&mca_btl_tcp_component.tcp_procs, proc->proc_name, btl_proc); } else { if (btl_proc) { - OBJ_RELEASE(btl_proc); /* release the local proc */ - OBJ_RELEASE(proc); /* and the ref on the OMPI proc */ + OBJ_RELEASE(btl_proc); /* release the local proc */ + OBJ_RELEASE(proc); /* and the ref on the OMPI proc */ btl_proc = NULL; } } @@ -476,19 +470,18 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc) * already held. Insert a btl instance into the proc array and assign * it an address. */ -int mca_btl_tcp_proc_insert(mca_btl_tcp_proc_t* btl_proc, - mca_btl_base_endpoint_t* btl_endpoint) +int mca_btl_tcp_proc_insert(mca_btl_tcp_proc_t *btl_proc, mca_btl_base_endpoint_t *btl_endpoint) { - mca_btl_tcp_module_t* tcp_btl = btl_endpoint->endpoint_btl; + mca_btl_tcp_module_t *tcp_btl = btl_endpoint->endpoint_btl; mca_btl_tcp_addr_t *remote_addr; int rc = OPAL_SUCCESS; - rc = opal_hash_table_get_value_uint32(&btl_proc->btl_index_to_endpoint, tcp_btl->btl_index, (void **)&remote_addr); + rc = opal_hash_table_get_value_uint32(&btl_proc->btl_index_to_endpoint, tcp_btl->btl_index, + (void **) &remote_addr); if (OPAL_SUCCESS != rc) { if (9 < opal_output_get_verbosity(opal_btl_base_framework.framework_output)) { char *proc_hostname = opal_get_proc_hostname(btl_proc->proc_opal); - opal_output(0, "btl:tcp: host %s, process %s UNREACHABLE", - proc_hostname, + opal_output(0, "btl:tcp: host %s, process %s UNREACHABLE", proc_hostname, OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name)); free(proc_hostname); } @@ -520,16 +513,17 @@ int mca_btl_tcp_proc_insert(mca_btl_tcp_proc_t* btl_proc, * no longer in use. */ -int mca_btl_tcp_proc_remove(mca_btl_tcp_proc_t* btl_proc, mca_btl_base_endpoint_t* btl_endpoint) +int mca_btl_tcp_proc_remove(mca_btl_tcp_proc_t *btl_proc, mca_btl_base_endpoint_t *btl_endpoint) { size_t i; if (NULL != btl_proc) { OPAL_THREAD_LOCK(&btl_proc->proc_lock); - for(i = 0; i < btl_proc->proc_endpoint_count; i++) { - if(btl_proc->proc_endpoints[i] == btl_endpoint) { - memmove(btl_proc->proc_endpoints+i, btl_proc->proc_endpoints+i+1, - (btl_proc->proc_endpoint_count-i-1)*sizeof(mca_btl_base_endpoint_t*)); - if(--btl_proc->proc_endpoint_count == 0) { + for (i = 0; i < btl_proc->proc_endpoint_count; i++) { + if (btl_proc->proc_endpoints[i] == btl_endpoint) { + memmove(btl_proc->proc_endpoints + i, btl_proc->proc_endpoints + i + 1, + (btl_proc->proc_endpoint_count - i - 1) + * sizeof(mca_btl_base_endpoint_t *)); + if (--btl_proc->proc_endpoint_count == 0) { OPAL_THREAD_UNLOCK(&btl_proc->proc_lock); OBJ_RELEASE(btl_proc); return OPAL_SUCCESS; @@ -546,31 +540,29 @@ int mca_btl_tcp_proc_remove(mca_btl_tcp_proc_t* btl_proc, mca_btl_base_endpoint_ * Look for an existing TCP process instance based on the globally unique * process identifier. */ -mca_btl_tcp_proc_t* mca_btl_tcp_proc_lookup(const opal_process_name_t *name) +mca_btl_tcp_proc_t *mca_btl_tcp_proc_lookup(const opal_process_name_t *name) { - mca_btl_tcp_proc_t* proc = NULL; + mca_btl_tcp_proc_t *proc = NULL; OPAL_THREAD_LOCK(&mca_btl_tcp_component.tcp_lock); - opal_proc_table_get_value(&mca_btl_tcp_component.tcp_procs, - *name, (void**)&proc); + opal_proc_table_get_value(&mca_btl_tcp_component.tcp_procs, *name, (void **) &proc); OPAL_THREAD_UNLOCK(&mca_btl_tcp_component.tcp_lock); if (OPAL_UNLIKELY(NULL == proc)) { mca_btl_base_endpoint_t *endpoint; opal_proc_t *opal_proc; - BTL_VERBOSE(("adding tcp proc for peer {%s}", - OPAL_NAME_PRINT(*name))); + BTL_VERBOSE(("adding tcp proc for peer {%s}", OPAL_NAME_PRINT(*name))); - opal_proc = opal_proc_for_name (*name); + opal_proc = opal_proc_for_name(*name); if (NULL == opal_proc) { return NULL; } /* try adding this proc to each btl until */ - for( uint32_t i = 0; i < mca_btl_tcp_component.tcp_num_btls; ++i ) { + for (uint32_t i = 0; i < mca_btl_tcp_component.tcp_num_btls; ++i) { endpoint = NULL; - (void) mca_btl_tcp_add_procs (&mca_btl_tcp_component.tcp_btls[i]->super, 1, &opal_proc, - &endpoint, NULL); + (void) mca_btl_tcp_add_procs(&mca_btl_tcp_component.tcp_btls[i]->super, 1, &opal_proc, + &endpoint, NULL); if (NULL != endpoint && NULL == proc) { /* construct all the endpoints and get the proc */ proc = endpoint->endpoint_proc; @@ -585,78 +577,84 @@ mca_btl_tcp_proc_t* mca_btl_tcp_proc_lookup(const opal_process_name_t *name) * loop through all available BTLs for one matching the source address * of the request. */ -void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t* btl_proc, struct sockaddr* addr, int sd) +void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t *btl_proc, struct sockaddr *addr, int sd) { OPAL_THREAD_LOCK(&btl_proc->proc_lock); int found_match = 0; - mca_btl_base_endpoint_t* match_btl_endpoint; + mca_btl_base_endpoint_t *match_btl_endpoint; - for( size_t i = 0; i < btl_proc->proc_endpoint_count; i++ ) { - mca_btl_base_endpoint_t* btl_endpoint = btl_proc->proc_endpoints[i]; + for (size_t i = 0; i < btl_proc->proc_endpoint_count; i++) { + mca_btl_base_endpoint_t *btl_endpoint = btl_proc->proc_endpoints[i]; /* We are not here to make a decision about what is good socket * and what is not. We simply check that this socket fit the endpoint * end we prepare for the real decision function mca_btl_tcp_endpoint_accept. */ - if( btl_endpoint->endpoint_addr->addr_family != addr->sa_family) { + if (btl_endpoint->endpoint_addr->addr_family != addr->sa_family) { continue; } switch (addr->sa_family) { case AF_INET: - if( memcmp( &btl_endpoint->endpoint_addr->addr_union.addr_inet, - &(((struct sockaddr_in*)addr)->sin_addr), - sizeof(struct in_addr) ) ) { + if (memcmp(&btl_endpoint->endpoint_addr->addr_union.addr_inet, + &(((struct sockaddr_in *) addr)->sin_addr), sizeof(struct in_addr))) { char tmp[2][16]; opal_output_verbose(20, opal_btl_base_framework.framework_output, - "btl: tcp: Match incoming connection from %s %s with locally known IP %s failed (iface %d/%d)!\n", + "btl: tcp: Match incoming connection from %s %s with locally " + "known IP %s failed (iface %d/%d)!\n", OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name), - inet_ntop(AF_INET, (void*)&((struct sockaddr_in*)addr)->sin_addr, + inet_ntop(AF_INET, + (void *) &((struct sockaddr_in *) addr)->sin_addr, tmp[0], 16), - inet_ntop(AF_INET, (void*)(struct in_addr*)&btl_endpoint->endpoint_addr->addr_union.addr_inet, + inet_ntop(AF_INET, + (void *) (struct in_addr *) &btl_endpoint + ->endpoint_addr->addr_union.addr_inet, tmp[1], 16), - (int)i, (int)btl_proc->proc_endpoint_count); + (int) i, (int) btl_proc->proc_endpoint_count); continue; } else if (btl_endpoint->endpoint_state != MCA_BTL_TCP_CLOSED) { - found_match = 1; - match_btl_endpoint = btl_endpoint; - continue; + found_match = 1; + match_btl_endpoint = btl_endpoint; + continue; } break; #if OPAL_ENABLE_IPV6 case AF_INET6: - if( memcmp( &btl_endpoint->endpoint_addr->addr_union.addr_inet, - &(((struct sockaddr_in6*)addr)->sin6_addr), - sizeof(struct in6_addr) ) ) { + if (memcmp(&btl_endpoint->endpoint_addr->addr_union.addr_inet, + &(((struct sockaddr_in6 *) addr)->sin6_addr), sizeof(struct in6_addr))) { char tmp[2][INET6_ADDRSTRLEN]; opal_output_verbose(20, opal_btl_base_framework.framework_output, - "btl: tcp: Match incoming connection from %s %s with locally known IP %s failed (iface %d/%d)!\n", + "btl: tcp: Match incoming connection from %s %s with locally " + "known IP %s failed (iface %d/%d)!\n", OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name), - inet_ntop(AF_INET6, (void*)&((struct sockaddr_in6*)addr)->sin6_addr, + inet_ntop(AF_INET6, + (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, tmp[0], INET6_ADDRSTRLEN), - inet_ntop(AF_INET6, (void*)(struct in6_addr*)&btl_endpoint->endpoint_addr->addr_union.addr_inet, + inet_ntop(AF_INET6, + (void *) (struct in6_addr *) &btl_endpoint + ->endpoint_addr->addr_union.addr_inet, tmp[1], INET6_ADDRSTRLEN), - (int)i, (int)btl_proc->proc_endpoint_count); + (int) i, (int) btl_proc->proc_endpoint_count); continue; } else if (btl_endpoint->endpoint_state != MCA_BTL_TCP_CLOSED) { - found_match = 1; - match_btl_endpoint = btl_endpoint; - continue; + found_match = 1; + match_btl_endpoint = btl_endpoint; + continue; } break; #endif - default: - ; + default:; } - /* Set state to CONNECTING to ensure that subsequent conenctions do not attempt to re-use endpoint in the num_links > 1 case*/ + /* Set state to CONNECTING to ensure that subsequent conenctions do not attempt to re-use + * endpoint in the num_links > 1 case*/ btl_endpoint->endpoint_state = MCA_BTL_TCP_CONNECTING; - (void)mca_btl_tcp_endpoint_accept(btl_endpoint, addr, sd); + (void) mca_btl_tcp_endpoint_accept(btl_endpoint, addr, sd); OPAL_THREAD_UNLOCK(&btl_proc->proc_lock); return; } - /* In this case the connection was inbound to an address exported, but was not in a CLOSED state. - * mca_btl_tcp_endpoint_accept() has logic to deal with the race condition that has likely caused this - * scenario, so call it here.*/ + /* In this case the connection was inbound to an address exported, but was not in a CLOSED + * state. mca_btl_tcp_endpoint_accept() has logic to deal with the race condition that has + * likely caused this scenario, so call it here.*/ if (found_match) { - (void)mca_btl_tcp_endpoint_accept(match_btl_endpoint, addr, sd); + (void) mca_btl_tcp_endpoint_accept(match_btl_endpoint, addr, sd); OPAL_THREAD_UNLOCK(&btl_proc->proc_lock); return; } @@ -668,13 +666,13 @@ void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t* btl_proc, struct sockaddr* addr ip[sizeof(ip) - 1] = '\0'; for (size_t i = 0; i < btl_proc->proc_endpoint_count; i++) { - mca_btl_base_endpoint_t* btl_endpoint = btl_proc->proc_endpoints[i]; + mca_btl_base_endpoint_t *btl_endpoint = btl_proc->proc_endpoints[i]; if (btl_endpoint->endpoint_addr->addr_family != addr->sa_family) { continue; } inet_ntop(btl_endpoint->endpoint_addr->addr_family, - (void*) &(btl_endpoint->endpoint_addr->addr_union.addr_inet), - ip, sizeof(ip) - 1); + (void *) &(btl_endpoint->endpoint_addr->addr_union.addr_inet), ip, + sizeof(ip) - 1); if (NULL == addr_str) { opal_asprintf(&tmp, "\n\t%s", ip); } else { @@ -684,13 +682,11 @@ void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t* btl_proc, struct sockaddr* addr addr_str = tmp; } tmp = opal_get_proc_hostname(btl_proc->proc_opal); - opal_show_help("help-mpi-btl-tcp.txt", "dropped inbound connection", - true, opal_process_info.nodename, - getpid(), tmp, + opal_show_help("help-mpi-btl-tcp.txt", "dropped inbound connection", true, + opal_process_info.nodename, getpid(), tmp, OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name), - opal_net_get_hostname((struct sockaddr*)addr), - btl_proc->proc_endpoint_count, - (NULL == addr_str) ? "NONE" : addr_str); + opal_net_get_hostname((struct sockaddr *) addr), + btl_proc->proc_endpoint_count, (NULL == addr_str) ? "NONE" : addr_str); free(tmp); if (NULL != addr_str) { free(addr_str); @@ -703,35 +699,31 @@ void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t* btl_proc, struct sockaddr* addr * convert internal data structure (mca_btl_tcp_addr_t) to sockaddr_storage * */ -bool mca_btl_tcp_proc_tosocks(mca_btl_tcp_addr_t* proc_addr, - struct sockaddr_storage* output) +bool mca_btl_tcp_proc_tosocks(mca_btl_tcp_addr_t *proc_addr, struct sockaddr_storage *output) { - memset(output, 0, sizeof (*output)); + memset(output, 0, sizeof(*output)); switch (proc_addr->addr_family) { case AF_INET: output->ss_family = AF_INET; - memcpy(&((struct sockaddr_in*)output)->sin_addr, - &proc_addr->addr_union.addr_inet, sizeof(struct in_addr)); - ((struct sockaddr_in*)output)->sin_port = proc_addr->addr_port; + memcpy(&((struct sockaddr_in *) output)->sin_addr, &proc_addr->addr_union.addr_inet, + sizeof(struct in_addr)); + ((struct sockaddr_in *) output)->sin_port = proc_addr->addr_port; break; #if OPAL_ENABLE_IPV6 - case AF_INET6: - { - struct sockaddr_in6* inaddr = (struct sockaddr_in6*)output; - output->ss_family = AF_INET6; - memcpy(&inaddr->sin6_addr, &proc_addr->addr_union.addr_inet6, - sizeof (proc_addr->addr_union.addr_inet6)); - inaddr->sin6_port = proc_addr->addr_port; - inaddr->sin6_scope_id = 0; - inaddr->sin6_flowinfo = 0; - } - break; + case AF_INET6: { + struct sockaddr_in6 *inaddr = (struct sockaddr_in6 *) output; + output->ss_family = AF_INET6; + memcpy(&inaddr->sin6_addr, &proc_addr->addr_union.addr_inet6, + sizeof(proc_addr->addr_union.addr_inet6)); + inaddr->sin6_port = proc_addr->addr_port; + inaddr->sin6_scope_id = 0; + inaddr->sin6_flowinfo = 0; + } break; #endif default: - opal_output( 0, "mca_btl_tcp_proc: unknown af_family received: %d\n", - proc_addr->addr_family ); + opal_output(0, "mca_btl_tcp_proc: unknown af_family received: %d\n", + proc_addr->addr_family); return false; } return true; } - diff --git a/opal/mca/btl/tcp/btl_tcp_proc.h b/opal/mca/btl/tcp/btl_tcp_proc.h index abbb9baf864..45bd3849bdb 100644 --- a/opal/mca/btl/tcp/btl_tcp_proc.h +++ b/opal/mca/btl/tcp/btl_tcp_proc.h @@ -22,11 +22,11 @@ #ifndef MCA_BTL_TCP_PROC_H #define MCA_BTL_TCP_PROC_H -#include "opal/class/opal_object.h" -#include "opal/util/proc.h" #include "btl_tcp.h" #include "btl_tcp_addr.h" #include "btl_tcp_endpoint.h" +#include "opal/class/opal_object.h" +#include "opal/util/proc.h" BEGIN_C_DECLS @@ -43,7 +43,7 @@ struct mca_btl_tcp_proc_t { opal_proc_t *proc_opal; /**< pointer to corresponding opal_proc_t */ - struct mca_btl_tcp_addr_t* proc_addrs; + struct mca_btl_tcp_addr_t *proc_addrs; /**< array of addresses exported by peer */ size_t proc_addr_count; @@ -64,12 +64,12 @@ struct mca_btl_tcp_proc_t { typedef struct mca_btl_tcp_proc_t mca_btl_tcp_proc_t; OBJ_CLASS_DECLARATION(mca_btl_tcp_proc_t); -mca_btl_tcp_proc_t* mca_btl_tcp_proc_create(opal_proc_t* proc); -mca_btl_tcp_proc_t* mca_btl_tcp_proc_lookup(const opal_process_name_t* name); -int mca_btl_tcp_proc_insert(mca_btl_tcp_proc_t*, mca_btl_base_endpoint_t*); -int mca_btl_tcp_proc_remove(mca_btl_tcp_proc_t*, mca_btl_base_endpoint_t*); -void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t*, struct sockaddr*, int); -bool mca_btl_tcp_proc_tosocks(mca_btl_tcp_addr_t*, struct sockaddr_storage*); +mca_btl_tcp_proc_t *mca_btl_tcp_proc_create(opal_proc_t *proc); +mca_btl_tcp_proc_t *mca_btl_tcp_proc_lookup(const opal_process_name_t *name); +int mca_btl_tcp_proc_insert(mca_btl_tcp_proc_t *, mca_btl_base_endpoint_t *); +int mca_btl_tcp_proc_remove(mca_btl_tcp_proc_t *, mca_btl_base_endpoint_t *); +void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t *, struct sockaddr *, int); +bool mca_btl_tcp_proc_tosocks(mca_btl_tcp_addr_t *, struct sockaddr_storage *); END_C_DECLS #endif diff --git a/opal/mca/btl/template/btl_template.c b/opal/mca/btl/template/btl_template.c index 1d0bd1183ca..4cbca571d7d 100644 --- a/opal/mca/btl/template/btl_template.c +++ b/opal/mca/btl/template/btl_template.c @@ -21,18 +21,17 @@ */ #include "opal_config.h" -#include #include "opal/class/opal_bitmap.h" -#include "opal/mca/btl/btl.h" #include "opal/datatype/opal_convertor.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" #include "opal/mca/mpool/mpool.h" +#include #include "btl_template.h" +#include "btl_template_endpoint.h" #include "btl_template_frag.h" #include "btl_template_proc.h" -#include "btl_template_endpoint.h" - mca_btl_template_module_t mca_btl_template_module = { .super = { @@ -49,28 +48,24 @@ mca_btl_template_module_t mca_btl_template_module = { .btl_get = mca_btl_template_get, .btl_register_mem = mca_btl_template_register_mem, .btl_deregister_mem = mca_btl_template_deregister_mem, - } -}; + }}; /** * */ -int mca_btl_template_add_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **opal_procs, - struct mca_btl_base_endpoint_t** peers, - opal_bitmap_t* reachable) +int mca_btl_template_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **opal_procs, + struct mca_btl_base_endpoint_t **peers, opal_bitmap_t *reachable) { - mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*)btl; + mca_btl_template_module_t *template_btl = (mca_btl_template_module_t *) btl; int i, rc; - for(i = 0; i < (int) nprocs; i++) { + for (i = 0; i < (int) nprocs; i++) { - struct opal_proc_t* opal_proc = opal_procs[i]; - mca_btl_template_proc_t* template_proc; - mca_btl_base_endpoint_t* template_endpoint; + struct opal_proc_t *opal_proc = opal_procs[i]; + mca_btl_template_proc_t *template_proc; + mca_btl_base_endpoint_t *template_endpoint; #if 0 /* If the BTL doesn't support heterogeneous operations, be @@ -80,7 +75,7 @@ int mca_btl_template_add_procs( } #endif - if(NULL == (template_proc = mca_btl_template_proc_create(opal_proc))) { + if (NULL == (template_proc = mca_btl_template_proc_create(opal_proc))) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -97,14 +92,14 @@ int mca_btl_template_add_procs( * Cache the peer instance on the btl_proc. */ template_endpoint = OBJ_NEW(mca_btl_template_endpoint_t); - if(NULL == template_endpoint) { + if (NULL == template_endpoint) { OPAL_THREAD_UNLOCK(&template_proc->proc_lock); return OPAL_ERR_OUT_OF_RESOURCE; } template_endpoint->endpoint_btl = template_btl; rc = mca_btl_template_proc_insert(template_proc, template_endpoint); - if(rc != OPAL_SUCCESS) { + if (rc != OPAL_SUCCESS) { OBJ_RELEASE(template_endpoint); OPAL_THREAD_UNLOCK(&template_proc->proc_lock); continue; @@ -118,30 +113,23 @@ int mca_btl_template_add_procs( return OPAL_SUCCESS; } -int mca_btl_template_del_procs(struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t ** peers) +int mca_btl_template_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers) { /* TODO */ return OPAL_SUCCESS; } - /** * Register callback function to support send/recv semantics */ -int mca_btl_template_register( - struct mca_btl_base_module_t* btl, - mca_btl_base_tag_t tag, - mca_btl_base_module_recv_cb_fn_t cbfunc, - void* cbdata) +int mca_btl_template_register(struct mca_btl_base_module_t *btl, mca_btl_base_tag_t tag, + mca_btl_base_module_recv_cb_fn_t cbfunc, void *cbdata) { return OPAL_SUCCESS; } - /** * Allocate a segment. * @@ -149,50 +137,44 @@ int mca_btl_template_register( * @param size (IN) Request segment size. */ -mca_btl_base_descriptor_t* mca_btl_template_alloc( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_template_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { - mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; - mca_btl_template_frag_t* frag = NULL; + mca_btl_template_module_t *template_btl = (mca_btl_template_module_t *) btl; + mca_btl_template_frag_t *frag = NULL; - if(size <= btl->btl_eager_limit){ + if (size <= btl->btl_eager_limit) { MCA_BTL_TEMPLATE_FRAG_ALLOC_EAGER(template_btl, frag); } else { MCA_BTL_TEMPLATE_FRAG_ALLOC_MAX(template_btl, frag); } - if( OPAL_UNLIKELY(NULL != frag) ) { + if (OPAL_UNLIKELY(NULL != frag)) { return NULL; } frag->segment.seg_len = size; frag->base.des_flags = 0; - return (mca_btl_base_descriptor_t*)frag; + return (mca_btl_base_descriptor_t *) frag; } - /** * Return a segment */ -int mca_btl_template_free( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* des) +int mca_btl_template_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { - mca_btl_template_frag_t* frag = (mca_btl_template_frag_t*)des; - if(frag->size == 0) { + mca_btl_template_frag_t *frag = (mca_btl_template_frag_t *) des; + if (frag->size == 0) { #if MCA_BTL_HAS_MPOOL OBJ_RELEASE(frag->registration); #endif MCA_BTL_TEMPLATE_FRAG_RETURN_USER(btl, frag); - } else if(frag->size == btl->btl_eager_limit){ + } else if (frag->size == btl->btl_eager_limit) { MCA_BTL_TEMPLATE_FRAG_RETURN_EAGER(btl, frag); - } else if(frag->size == btl->btl_max_send_size) { + } else if (frag->size == btl->btl_max_send_size) { MCA_BTL_TEMPLATE_FRAG_RETURN_EAGER(btl, frag); - } else { + } else { return OPAL_ERR_BAD_PARAM; } return OPAL_SUCCESS; @@ -205,40 +187,35 @@ int mca_btl_template_free( * @param btl (IN) BTL module * @param peer (IN) BTL peer addressing */ -mca_btl_base_descriptor_t* mca_btl_template_prepare_src( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags -) +mca_btl_base_descriptor_t *mca_btl_template_prepare_src(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags) { - mca_btl_template_frag_t* frag; + mca_btl_template_frag_t *frag; struct iovec iov; uint32_t iov_count = 1; size_t max_data = *size; int rc; - /* * if we aren't pinning the data and the requested size is less * than the eager limit pack into a fragment from the eager pool - */ - if (max_data+reserve <= btl->btl_eager_limit) { + */ + if (max_data + reserve <= btl->btl_eager_limit) { MCA_BTL_TEMPLATE_FRAG_ALLOC_EAGER(btl, frag); - if(OPAL_UNLIKELY(NULL == frag)) { + if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } iov.iov_len = max_data; - iov.iov_base = (unsigned char*) frag->segment.seg_addr.pval + reserve; + iov.iov_base = (unsigned char *) frag->segment.seg_addr.pval + reserve; - rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data ); - *size = max_data; - if( rc < 0 ) { + rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); + *size = max_data; + if (rc < 0) { MCA_BTL_TEMPLATE_FRAG_RETURN_EAGER(btl, frag); return NULL; } @@ -252,19 +229,19 @@ mca_btl_base_descriptor_t* mca_btl_template_prepare_src( else { MCA_BTL_TEMPLATE_FRAG_ALLOC_MAX(btl, frag); - if(OPAL_UNLIKELY(NULL == frag)) { + if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } - if(max_data + reserve > frag->size){ + if (max_data + reserve > frag->size) { max_data = frag->size - reserve; } iov.iov_len = max_data; - iov.iov_base = (unsigned char*) frag->segment.seg_addr.pval + reserve; + iov.iov_base = (unsigned char *) frag->segment.seg_addr.pval + reserve; - rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data ); - *size = max_data; + rc = opal_convertor_pack(convertor, &iov, &iov_count, &max_data); + *size = max_data; - if( rc < 0 ) { + if (rc < 0) { MCA_BTL_TEMPLATE_FRAG_RETURN_MAX(btl, frag); return NULL; } @@ -277,7 +254,6 @@ mca_btl_base_descriptor_t* mca_btl_template_prepare_src( return &frag->base; } - /** * Initiate an asynchronous send. * @@ -287,21 +263,18 @@ mca_btl_base_descriptor_t* mca_btl_template_prepare_src( * @param tag (IN) The tag value used to notify the peer. */ -int mca_btl_template_send( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag) +int mca_btl_template_send(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { /* mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; */ - mca_btl_template_frag_t* frag = (mca_btl_template_frag_t*)descriptor; + mca_btl_template_frag_t *frag = (mca_btl_template_frag_t *) descriptor; frag->endpoint = endpoint; /* TODO */ return OPAL_ERR_NOT_IMPLEMENTED; } - /** * Initiate an asynchronous put. * @@ -310,18 +283,19 @@ int mca_btl_template_send( * @param descriptor (IN) Description of the data to be transferred */ -int mca_btl_template_put (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_template_put(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { /* mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; */ /* TODO */ return OPAL_ERR_NOT_IMPLEMENTED; } - /** * Initiate an asynchronous get. * @@ -331,11 +305,13 @@ int mca_btl_template_put (struct mca_btl_base_module_t *btl, * */ -int mca_btl_template_get (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_template_get(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { /* mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; */ /* TODO */ @@ -360,9 +336,10 @@ int mca_btl_template_get (struct mca_btl_base_module_t *btl, * functions. Care should be taken to not hold an excessive number of registrations * as they may use limited system/NIC resources. */ -struct mca_btl_base_registration_handle_t *mca_btl_template_register_mem ( - struct mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags) +struct mca_btl_base_registration_handle_t * +mca_btl_template_register_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, + uint32_t flags) { /* mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; */ /* TODO */ @@ -380,22 +357,21 @@ struct mca_btl_base_registration_handle_t *mca_btl_template_register_mem ( * after it is deregistered. It is erroneous to specify a memory handle associated with * a remote node. */ -int mca_btl_template_deregister_mem (struct mca_btl_base_module_t* btl, - struct mca_btl_base_registration_handle_t *handle) +int mca_btl_template_deregister_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_registration_handle_t *handle) { /* mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; */ /* TODO */ return OPAL_ERR_NOT_IMPLEMENTED; } - /* * Cleanup/release module resources. */ -int mca_btl_template_finalize(struct mca_btl_base_module_t* btl) +int mca_btl_template_finalize(struct mca_btl_base_module_t *btl) { - mca_btl_template_module_t* template_btl = (mca_btl_template_module_t*) btl; + mca_btl_template_module_t *template_btl = (mca_btl_template_module_t *) btl; OBJ_DESTRUCT(&template_btl->template_lock); OBJ_DESTRUCT(&template_btl->template_frag_eager); OBJ_DESTRUCT(&template_btl->template_frag_max); diff --git a/opal/mca/btl/template/btl_template.h b/opal/mca/btl/template/btl_template.h index 260f972b48d..0f7ed3f41fb 100644 --- a/opal/mca/btl/template/btl_template.h +++ b/opal/mca/btl/template/btl_template.h @@ -28,14 +28,14 @@ #define MCA_BTL_TEMPLATE_H #include "opal_config.h" -#include #include +#include /* Open MPI includes */ -#include "opal/util/event.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/mpool.h" +#include "opal/util/event.h" BEGIN_C_DECLS @@ -46,12 +46,12 @@ BEGIN_C_DECLS */ struct mca_btl_template_component_t { - mca_btl_base_component_3_0_0_t super; /**< base BTL component */ + mca_btl_base_component_3_0_0_t super; /**< base BTL component */ - uint32_t template_num_btls; + uint32_t template_num_btls; /**< number of hcas available to the TEMPLATE component */ - struct mca_btl_template_module_t *template_btls; + struct mca_btl_template_module_t *template_btls; /**< array of available BTL modules */ int template_free_list_num; @@ -69,7 +69,7 @@ struct mca_btl_template_component_t { opal_mutex_t template_lock; /**< lock for accessing module state */ - char* template_mpool_name; + char *template_mpool_name; /**< name of memory pool */ bool leave_pinned; @@ -83,7 +83,7 @@ OPAL_MODULE_DECLSPEC extern mca_btl_template_component_t mca_btl_template_compon * BTL Module Interface */ struct mca_btl_template_module_t { - mca_btl_base_module_t super; /**< base BTL interface */ + mca_btl_base_module_t super; /**< base BTL interface */ /* free list of fragment descriptors */ opal_free_list_t template_frag_eager; @@ -94,13 +94,12 @@ struct mca_btl_template_module_t { opal_mutex_t template_lock; #if MCA_BTL_HAS_MPOOL - struct mca_mpool_base_module_t* template_mpool; + struct mca_mpool_base_module_t *template_mpool; #endif }; typedef struct mca_btl_template_module_t mca_btl_template_module_t; extern mca_btl_template_module_t mca_btl_template_module; - /** * TEMPLATE component initialization. * @@ -108,20 +107,15 @@ extern mca_btl_template_module_t mca_btl_template_module; * @param allow_multi_user_threads (OUT) Flag indicating wether BTL supports user threads (TRUE) * @param have_hidden_threads (OUT) Flag indicating wether BTL uses threads (TRUE) */ -extern mca_btl_base_module_t** mca_btl_template_component_init( - int *num_btl_modules, - bool allow_multi_user_threads, - bool have_hidden_threads -); - +extern mca_btl_base_module_t **mca_btl_template_component_init(int *num_btl_modules, + bool allow_multi_user_threads, + bool have_hidden_threads); /** * TEMPLATE component progress. */ extern int mca_btl_template_component_progress(void); - - /** * Cleanup any resources held by the BTL. * @@ -129,10 +123,7 @@ extern int mca_btl_template_component_progress(void); * @return OPAL_SUCCESS or error status on failure. */ -extern int mca_btl_template_finalize( - struct mca_btl_base_module_t* btl -); - +extern int mca_btl_template_finalize(struct mca_btl_base_module_t *btl); /** * PML->BTL notification of change in the process list. @@ -146,13 +137,10 @@ extern int mca_btl_template_finalize( * */ -extern int mca_btl_template_add_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers, - opal_bitmap_t* reachable -); +extern int mca_btl_template_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable); /** * PML->BTL notification of change in the process list. @@ -165,13 +153,9 @@ extern int mca_btl_template_add_procs( * */ -extern int mca_btl_template_del_procs( - struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** peers -); - +extern int mca_btl_template_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, + struct mca_btl_base_endpoint_t **peers); /** * Initiate an asynchronous send. @@ -182,13 +166,10 @@ extern int mca_btl_template_del_procs( * @param tag (IN) The tag value used to notify the peer. */ -extern int mca_btl_template_send( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* btl_peer, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag -); - +extern int mca_btl_template_send(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *btl_peer, + struct mca_btl_base_descriptor_t *descriptor, + mca_btl_base_tag_t tag); /** * Initiate an asynchronous put. @@ -221,11 +202,13 @@ extern int mca_btl_template_send( * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -int mca_btl_template_put (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_template_put(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata); /** * Initiate an asynchronous get. @@ -258,11 +241,13 @@ int mca_btl_template_put (struct mca_btl_base_module_t *btl, * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -int mca_btl_template_get (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_template_get(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata); /** * @brief Register a memory region for put/get/atomic operations. @@ -282,9 +267,10 @@ int mca_btl_template_get (struct mca_btl_base_module_t *btl, * functions. Care should be taken to not hold an excessive number of registrations * as they may use limited system/NIC resources. */ -struct mca_btl_base_registration_handle_t *mca_btl_template_register_mem ( - struct mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags); +struct mca_btl_base_registration_handle_t * +mca_btl_template_register_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, + uint32_t flags); /** * @brief Deregister a memory region @@ -297,8 +283,8 @@ struct mca_btl_base_registration_handle_t *mca_btl_template_register_mem ( * after it is deregistered. It is erroneous to specify a memory handle associated with * a remote node. */ -int mca_btl_template_deregister_mem (struct mca_btl_base_module_t* btl, - struct mca_btl_base_registration_handle_t *handle); +int mca_btl_template_deregister_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_registration_handle_t *handle); /** * Register a callback function that is called on receipt @@ -309,11 +295,8 @@ int mca_btl_template_deregister_mem (struct mca_btl_base_module_t* btl, * */ -extern int mca_btl_template_register( - struct mca_btl_base_module_t* btl, - mca_btl_base_tag_t tag, - mca_btl_base_module_recv_cb_fn_t cbfunc, - void* cbdata); +extern int mca_btl_template_register(struct mca_btl_base_module_t *btl, mca_btl_base_tag_t tag, + mca_btl_base_module_recv_cb_fn_t cbfunc, void *cbdata); /** * Allocate a descriptor with a segment of the requested size. @@ -324,13 +307,10 @@ extern int mca_btl_template_register( * @param size (IN) Request segment size. */ -extern mca_btl_base_descriptor_t* mca_btl_template_alloc( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags); - +extern mca_btl_base_descriptor_t *mca_btl_template_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, + uint32_t flags); /** * Return a segment allocated by this BTL. @@ -339,10 +319,7 @@ extern mca_btl_base_descriptor_t* mca_btl_template_alloc( * @param descriptor (IN) Allocated descriptor. */ -extern int mca_btl_template_free( - struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* des); - +extern int mca_btl_template_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); /** * Prepare a descriptor for send/rdma using the supplied @@ -356,17 +333,13 @@ extern int mca_btl_template_free( * @param convertor (IN) Data type convertor * @param reserve (IN) Additional bytes requested by upper layer to precede user data * @param size (IN/OUT) Number of bytes to prepare (IN), number of bytes actually prepared (OUT) -*/ - -mca_btl_base_descriptor_t* mca_btl_template_prepare_src( - struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* peer, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags -); + */ + +mca_btl_base_descriptor_t *mca_btl_template_prepare_src(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *peer, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags); END_C_DECLS #endif diff --git a/opal/mca/btl/template/btl_template_component.c b/opal/mca/btl/template/btl_template_component.c index 3b09fc9ca46..3d94c1ae32f 100644 --- a/opal/mca/btl/template/btl_template_component.c +++ b/opal/mca/btl/template/btl_template_component.c @@ -21,17 +21,16 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/util/event.h" +#include "opal/mca/btl/base/base.h" #include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" -#include "opal/mca/btl/base/base.h" +#include "opal/util/event.h" #include "btl_template.h" -#include "btl_template_frag.h" #include "btl_template_endpoint.h" +#include "btl_template_frag.h" /** * Register any MCA parameters associated with this component @@ -48,27 +47,25 @@ static int mca_btl_template_component_open(void); */ static int mca_btl_template_component_close(void); - mca_btl_template_component_t mca_btl_template_component = { .super = { /* First, the mca_base_component_t struct containing meta information about the component itself */ - .btl_version = { - MCA_BTL_DEFAULT_VERSION("template"), - .mca_open_component = mca_btl_template_component_open, - .mca_close_component = mca_btl_template_component_close, - .mca_register_component_params = mca_btl_template_component_register, - }, - .btl_data = { - /* The component is not checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_NONE - }, + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("template"), + .mca_open_component = mca_btl_template_component_open, + .mca_close_component = mca_btl_template_component_close, + .mca_register_component_params = mca_btl_template_component_register, + }, + .btl_data = + {/* The component is not checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_NONE}, .btl_init = mca_btl_template_component_init, .btl_progress = mca_btl_template_component_progress, - } -}; + }}; static int mca_btl_template_component_open(void) { @@ -78,8 +75,8 @@ static int mca_btl_template_component_open(void) static int mca_btl_template_component_register(void) { /* initialize state */ - mca_btl_template_component.template_num_btls=0; - mca_btl_template_component.template_btls=NULL; + mca_btl_template_component.template_num_btls = 0; + mca_btl_template_component.template_btls = NULL; /* initialize objects */ OBJ_CONSTRUCT(&mca_btl_template_component.template_procs, opal_list_t); @@ -87,36 +84,32 @@ static int mca_btl_template_component_register(void) /* register TEMPLATE component parameters */ mca_btl_template_component.template_free_list_num = 8; (void) mca_base_component_var_register(&mca_btl_template_component.super.btl_version, - "free_list_num", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + "free_list_num", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_template_component.template_free_list_num); (void) mca_base_component_var_register(&mca_btl_template_component.super.btl_version, - "free_list_max", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + "free_list_max", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_template_component.template_free_list_max); (void) mca_base_component_var_register(&mca_btl_template_component.super.btl_version, - "free_list_inc", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + "free_list_inc", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_template_component.template_free_list_inc); mca_btl_template_component.template_mpool_name = "grdma"; - (void) mca_base_component_var_register(&mca_btl_template_component.super.btl_version, - "mpool", NULL, MCA_BASE_VAR_TYPE_STRING, - NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + (void) mca_base_component_var_register(&mca_btl_template_component.super.btl_version, "mpool", + NULL, MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_btl_template_component.template_mpool_name); mca_btl_template_module.super.btl_exclusivity = 0; - mca_btl_template_module.super.btl_eager_limit = 64*1024; - mca_btl_template_module.super.btl_rndv_eager_limit = 64*1024; - mca_btl_template_module.super.btl_max_send_size = 128*1024; - mca_btl_template_module.super.btl_min_rdma_pipeline_size = 1024*1024; - mca_btl_template_module.super.btl_rdma_pipeline_frag_size = 1024*1024; - mca_btl_template_module.super.btl_rdma_pipeline_send_length = 1024*1024; - mca_btl_template_module.super.btl_flags = MCA_BTL_FLAGS_PUT; + mca_btl_template_module.super.btl_eager_limit = 64 * 1024; + mca_btl_template_module.super.btl_rndv_eager_limit = 64 * 1024; + mca_btl_template_module.super.btl_max_send_size = 128 * 1024; + mca_btl_template_module.super.btl_min_rdma_pipeline_size = 1024 * 1024; + mca_btl_template_module.super.btl_rdma_pipeline_frag_size = 1024 * 1024; + mca_btl_template_module.super.btl_rdma_pipeline_send_length = 1024 * 1024; + mca_btl_template_module.super.btl_flags = MCA_BTL_FLAGS_PUT; return mca_btl_base_param_register(&mca_btl_template_component.super.btl_version, &mca_btl_template_module.super); @@ -139,9 +132,9 @@ static int mca_btl_template_component_close(void) * (3) register BTL parameters with the MCA */ -mca_btl_base_module_t** mca_btl_template_component_init(int *num_btl_modules, - bool enable_progress_threads, - bool enable_mpi_threads) +mca_btl_base_module_t **mca_btl_template_component_init(int *num_btl_modules, + bool enable_progress_threads, + bool enable_mpi_threads) { return NULL; } @@ -150,9 +143,7 @@ mca_btl_base_module_t** mca_btl_template_component_init(int *num_btl_modules, * TEMPLATE component progress. */ - int mca_btl_template_component_progress() { return 0; } - diff --git a/opal/mca/btl/template/btl_template_endpoint.c b/opal/mca/btl/template/btl_template_endpoint.c index 71d205de07e..faa3b55d775 100644 --- a/opal/mca/btl/template/btl_template_endpoint.c +++ b/opal/mca/btl/template/btl_template_endpoint.c @@ -16,22 +16,20 @@ * $HEADER$ */ - #include "opal_config.h" -#include -#include -#include "btl_template.h" #include "btl_template_endpoint.h" -#include "btl_template_proc.h" +#include "btl_template.h" #include "btl_template_frag.h" - +#include "btl_template_proc.h" +#include +#include /* * Initialize state of the endpoint instance. * */ -static void mca_btl_template_endpoint_construct(mca_btl_base_endpoint_t* endpoint) +static void mca_btl_template_endpoint_construct(mca_btl_base_endpoint_t *endpoint) { endpoint->endpoint_btl = 0; endpoint->endpoint_proc = 0; @@ -42,14 +40,9 @@ static void mca_btl_template_endpoint_construct(mca_btl_base_endpoint_t* endpoin * */ -static void mca_btl_template_endpoint_destruct(mca_btl_base_endpoint_t* endpoint) +static void mca_btl_template_endpoint_destruct(mca_btl_base_endpoint_t *endpoint) { } - -OBJ_CLASS_INSTANCE( - mca_btl_template_endpoint_t, - opal_list_item_t, - mca_btl_template_endpoint_construct, - mca_btl_template_endpoint_destruct); - +OBJ_CLASS_INSTANCE(mca_btl_template_endpoint_t, opal_list_item_t, + mca_btl_template_endpoint_construct, mca_btl_template_endpoint_destruct); diff --git a/opal/mca/btl/template/btl_template_endpoint.h b/opal/mca/btl/template/btl_template_endpoint.h index 5ab253b2ab8..9828e56d814 100644 --- a/opal/mca/btl/template/btl_template_endpoint.h +++ b/opal/mca/btl/template/btl_template_endpoint.h @@ -21,10 +21,10 @@ #ifndef MCA_BTL_TEMPLATE_ENDPOINT_H #define MCA_BTL_TEMPLATE_ENDPOINT_H +#include "btl_template.h" +#include "btl_template_frag.h" #include "opal/class/opal_list.h" #include "opal/util/event.h" -#include "btl_template_frag.h" -#include "btl_template.h" BEGIN_C_DECLS /** @@ -35,17 +35,17 @@ BEGIN_C_DECLS */ struct mca_btl_base_endpoint_t { - opal_list_item_t super; + opal_list_item_t super; - struct mca_btl_template_module_t* endpoint_btl; + struct mca_btl_template_module_t *endpoint_btl; /**< BTL instance that created this connection */ - struct mca_btl_template_proc_t* endpoint_proc; + struct mca_btl_template_proc_t *endpoint_proc; /**< proc structure corresponding to endpoint */ }; typedef struct mca_btl_base_endpoint_t mca_btl_base_endpoint_t; -typedef mca_btl_base_endpoint_t mca_btl_template_endpoint_t; +typedef mca_btl_base_endpoint_t mca_btl_template_endpoint_t; OBJ_CLASS_DECLARATION(mca_btl_template_endpoint_t); END_C_DECLS diff --git a/opal/mca/btl/template/btl_template_frag.c b/opal/mca/btl/template/btl_template_frag.c index b22d38138ce..1859ecb903f 100644 --- a/opal/mca/btl/template/btl_template_frag.c +++ b/opal/mca/btl/template/btl_template_frag.c @@ -1,47 +1,30 @@ #include "btl_template_frag.h" - - -static void mca_btl_template_frag_eager_constructor(mca_btl_template_frag_t* frag) +static void mca_btl_template_frag_eager_constructor(mca_btl_template_frag_t *frag) { frag->registration = NULL; frag->size = mca_btl_template_module.super.btl_eager_limit; } -static void mca_btl_template_frag_max_constructor(mca_btl_template_frag_t* frag) +static void mca_btl_template_frag_max_constructor(mca_btl_template_frag_t *frag) { frag->registration = NULL; frag->size = mca_btl_template_module.super.btl_max_send_size; } -static void mca_btl_template_frag_user_constructor(mca_btl_template_frag_t* frag) +static void mca_btl_template_frag_user_constructor(mca_btl_template_frag_t *frag) { frag->size = 0; frag->registration = NULL; } +OBJ_CLASS_INSTANCE(mca_btl_template_frag_t, mca_btl_base_descriptor_t, NULL, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_template_frag_t, - mca_btl_base_descriptor_t, - NULL, - NULL); - -OBJ_CLASS_INSTANCE( - mca_btl_template_frag_eager_t, - mca_btl_base_descriptor_t, - mca_btl_template_frag_eager_constructor, - NULL); - -OBJ_CLASS_INSTANCE( - mca_btl_template_frag_max_t, - mca_btl_base_descriptor_t, - mca_btl_template_frag_max_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_template_frag_eager_t, mca_btl_base_descriptor_t, + mca_btl_template_frag_eager_constructor, NULL); -OBJ_CLASS_INSTANCE( - mca_btl_template_frag_user_t, - mca_btl_base_descriptor_t, - mca_btl_template_frag_user_constructor, - NULL); +OBJ_CLASS_INSTANCE(mca_btl_template_frag_max_t, mca_btl_base_descriptor_t, + mca_btl_template_frag_max_constructor, NULL); +OBJ_CLASS_INSTANCE(mca_btl_template_frag_user_t, mca_btl_base_descriptor_t, + mca_btl_template_frag_user_constructor, NULL); diff --git a/opal/mca/btl/template/btl_template_frag.h b/opal/mca/btl/template/btl_template_frag.h index aab1f1502ca..5f53e01dc74 100644 --- a/opal/mca/btl/template/btl_template_frag.h +++ b/opal/mca/btl/template/btl_template_frag.h @@ -22,7 +22,6 @@ #ifndef MCA_BTL_TEMPLATE_FRAG_H #define MCA_BTL_TEMPLATE_FRAG_H - #define MCA_BTL_TEMPLATE_FRAG_ALIGN (8) #include "opal_config.h" #include "btl_template.h" @@ -39,7 +38,7 @@ struct mca_btl_template_frag_t { mca_btl_base_header_t *hdr; size_t size; #if MCA_BTL_HAS_MPOOL - struct mca_mpool_base_registration_t* registration; + struct mca_mpool_base_registration_t *registration; #endif }; typedef struct mca_btl_template_frag_t mca_btl_template_frag_t; @@ -57,50 +56,46 @@ typedef struct mca_btl_template_frag_t mca_btl_template_frag_user_t; OBJ_CLASS_DECLARATION(mca_btl_template_frag_user_t); - /* * Macros to allocate/return descriptors from module specific * free list(s). */ #define MCA_BTL_TEMPLATE_FRAG_ALLOC_EAGER(btl, frag) \ -{ \ - frag = (mca_btl_template_frag_t *) \ - opal_free_list_get (&((mca_btl_template_module_t*)btl)->template_frag_eager); \ -} - -#define MCA_BTL_TEMPLATE_FRAG_RETURN_EAGER(btl, frag) \ -{ \ - opal_free_list_return (&((mca_btl_template_module_t*)btl)->template_frag_eager, \ - (opal_free_list_item_t*)(frag)); \ -} - -#define MCA_BTL_TEMPLATE_FRAG_ALLOC_MAX(btl, frag) \ -{ \ - frag = (mca_btl_template_frag_t *) \ - opal_free_list_get (&((mca_btl_template_module_t*)btl)->template_frag_max); \ -} - -#define MCA_BTL_TEMPLATE_FRAG_RETURN_MAX(btl, frag) \ -{ \ - opal_free_list_return (&((mca_btl_template_module_t*)btl)->template_frag_max, \ - (opal_free_list_item_t*)(frag)); \ -} - - -#define MCA_BTL_TEMPLATE_FRAG_ALLOC_USER(btl, frag) \ -{ \ - frag = (mca_btl_template_frag_t*) \ - opal_free_list_get (&((mca_btl_template_module_t*)btl)->template_frag_user); \ -} - -#define MCA_BTL_TEMPLATE_FRAG_RETURN_USER(btl, frag) \ -{ \ - opal_free_list_return (&((mca_btl_template_module_t*)btl)->template_frag_user, \ - (opal_free_list_item_t*)(frag)); \ -} - - + { \ + frag = (mca_btl_template_frag_t *) opal_free_list_get( \ + &((mca_btl_template_module_t *) btl)->template_frag_eager); \ + } + +#define MCA_BTL_TEMPLATE_FRAG_RETURN_EAGER(btl, frag) \ + { \ + opal_free_list_return(&((mca_btl_template_module_t *) btl)->template_frag_eager, \ + (opal_free_list_item_t *) (frag)); \ + } + +#define MCA_BTL_TEMPLATE_FRAG_ALLOC_MAX(btl, frag) \ + { \ + frag = (mca_btl_template_frag_t *) opal_free_list_get( \ + &((mca_btl_template_module_t *) btl)->template_frag_max); \ + } + +#define MCA_BTL_TEMPLATE_FRAG_RETURN_MAX(btl, frag) \ + { \ + opal_free_list_return(&((mca_btl_template_module_t *) btl)->template_frag_max, \ + (opal_free_list_item_t *) (frag)); \ + } + +#define MCA_BTL_TEMPLATE_FRAG_ALLOC_USER(btl, frag) \ + { \ + frag = (mca_btl_template_frag_t *) opal_free_list_get( \ + &((mca_btl_template_module_t *) btl)->template_frag_user); \ + } + +#define MCA_BTL_TEMPLATE_FRAG_RETURN_USER(btl, frag) \ + { \ + opal_free_list_return(&((mca_btl_template_module_t *) btl)->template_frag_user, \ + (opal_free_list_item_t *) (frag)); \ + } END_C_DECLS #endif diff --git a/opal/mca/btl/template/btl_template_proc.c b/opal/mca/btl/template/btl_template_proc.c index 76f6f52f677..8c70cd3ffe9 100644 --- a/opal/mca/btl/template/btl_template_proc.c +++ b/opal/mca/btl/template/btl_template_proc.c @@ -18,18 +18,16 @@ #include "opal_config.h" - #include "btl_template.h" #include "btl_template_proc.h" -static void mca_btl_template_proc_construct(mca_btl_template_proc_t* proc); -static void mca_btl_template_proc_destruct(mca_btl_template_proc_t* proc); +static void mca_btl_template_proc_construct(mca_btl_template_proc_t *proc); +static void mca_btl_template_proc_destruct(mca_btl_template_proc_t *proc); -OBJ_CLASS_INSTANCE(mca_btl_template_proc_t, - opal_list_item_t, mca_btl_template_proc_construct, - mca_btl_template_proc_destruct); +OBJ_CLASS_INSTANCE(mca_btl_template_proc_t, opal_list_item_t, mca_btl_template_proc_construct, + mca_btl_template_proc_destruct); -void mca_btl_template_proc_construct(mca_btl_template_proc_t* template_proc) +void mca_btl_template_proc_construct(mca_btl_template_proc_t *template_proc) { template_proc->proc_opal = 0; template_proc->proc_addr_count = 0; @@ -46,43 +44,41 @@ void mca_btl_template_proc_construct(mca_btl_template_proc_t* template_proc) * Cleanup ib proc instance */ -void mca_btl_template_proc_destruct(mca_btl_template_proc_t* template_proc) +void mca_btl_template_proc_destruct(mca_btl_template_proc_t *template_proc) { /* remove from list of all proc instances */ OPAL_THREAD_LOCK(&mca_btl_template_component.template_lock); - opal_list_remove_item(&mca_btl_template_component.template_procs, - &template_proc->super); + opal_list_remove_item(&mca_btl_template_component.template_procs, &template_proc->super); OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock); /* release resources */ - if(NULL != template_proc->proc_endpoints) { + if (NULL != template_proc->proc_endpoints) { free(template_proc->proc_endpoints); } OBJ_DESTRUCT(&template_proc->proc_lock); } - /* * Look for an existing TEMPLATE process instances based on the associated * opal_proc_t instance. */ -static mca_btl_template_proc_t* mca_btl_template_proc_lookup_opal(opal_proc_t* opal_proc) +static mca_btl_template_proc_t *mca_btl_template_proc_lookup_opal(opal_proc_t *opal_proc) { - mca_btl_template_proc_t* template_proc; + mca_btl_template_proc_t *template_proc; OPAL_THREAD_LOCK(&mca_btl_template_component.template_lock); - for(template_proc = (mca_btl_template_proc_t*) - opal_list_get_first(&mca_btl_template_component.template_procs); - template_proc != (mca_btl_template_proc_t*) - opal_list_get_end(&mca_btl_template_component.template_procs); - template_proc = (mca_btl_template_proc_t*)opal_list_get_next(template_proc)) { + for (template_proc = (mca_btl_template_proc_t *) opal_list_get_first( + &mca_btl_template_component.template_procs); + template_proc + != (mca_btl_template_proc_t *) opal_list_get_end( + &mca_btl_template_component.template_procs); + template_proc = (mca_btl_template_proc_t *) opal_list_get_next(template_proc)) { - if(template_proc->proc_opal == opal_proc) { + if (template_proc->proc_opal == opal_proc) { OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock); return template_proc; } - } OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock); @@ -98,15 +94,15 @@ static mca_btl_template_proc_t* mca_btl_template_proc_lookup_opal(opal_proc_t* o * datastructure. */ -mca_btl_template_proc_t* mca_btl_template_proc_create(opal_proc_t* opal_proc) +mca_btl_template_proc_t *mca_btl_template_proc_create(opal_proc_t *opal_proc) { - mca_btl_template_proc_t* module_proc = NULL; + mca_btl_template_proc_t *module_proc = NULL; /* Check if we have already created a TEMPLATE proc * structure for this process */ module_proc = mca_btl_template_proc_lookup_opal(opal_proc); - if(module_proc != NULL) { + if (module_proc != NULL) { /* Gotcha! */ return module_proc; @@ -131,24 +127,23 @@ mca_btl_template_proc_t* mca_btl_template_proc_create(opal_proc_t* opal_proc) * mca_btl_template_proc_t to allow on demand increasing of * number of endpoints for this proc */ - module_proc->proc_endpoints = (mca_btl_base_endpoint_t**) - malloc(module_proc->proc_addr_count * sizeof(mca_btl_base_endpoint_t*)); + module_proc->proc_endpoints = (mca_btl_base_endpoint_t **) malloc( + module_proc->proc_addr_count * sizeof(mca_btl_base_endpoint_t *)); - if(NULL == module_proc->proc_endpoints) { + if (NULL == module_proc->proc_endpoints) { OBJ_RELEASE(module_proc); return NULL; } return module_proc; } - /* * Note that this routine must be called with the lock on the process * already held. Insert a btl instance into the proc array and assign * it an address. */ -int mca_btl_template_proc_insert(mca_btl_template_proc_t* module_proc, - mca_btl_base_endpoint_t* module_endpoint) +int mca_btl_template_proc_insert(mca_btl_template_proc_t *module_proc, + mca_btl_base_endpoint_t *module_endpoint) { /* insert into endpoint array */ module_endpoint->endpoint_proc = module_proc; diff --git a/opal/mca/btl/template/btl_template_proc.h b/opal/mca/btl/template/btl_template_proc.h index 5e19d8400c8..35669c7ea46 100644 --- a/opal/mca/btl/template/btl_template_proc.h +++ b/opal/mca/btl/template/btl_template_proc.h @@ -19,10 +19,10 @@ #ifndef MCA_BTL_TEMPLATE_PROC_H #define MCA_BTL_TEMPLATE_PROC_H -#include "opal/class/opal_object.h" -#include "opal/util/proc.h" #include "btl_template.h" #include "btl_template_endpoint.h" +#include "opal/class/opal_object.h" +#include "opal/util/proc.h" BEGIN_C_DECLS @@ -54,8 +54,8 @@ struct mca_btl_template_proc_t { typedef struct mca_btl_template_proc_t mca_btl_template_proc_t; OBJ_CLASS_DECLARATION(mca_btl_template_proc_t); -mca_btl_template_proc_t* mca_btl_template_proc_create(opal_proc_t* proc); -int mca_btl_template_proc_insert(mca_btl_template_proc_t*, mca_btl_base_endpoint_t*); +mca_btl_template_proc_t *mca_btl_template_proc_create(opal_proc_t *proc); +int mca_btl_template_proc_insert(mca_btl_template_proc_t *, mca_btl_base_endpoint_t *); END_C_DECLS #endif diff --git a/opal/mca/btl/uct/btl_uct.h b/opal/mca/btl/uct/btl_uct.h index 2a38138c00a..0e5afbad6df 100644 --- a/opal/mca/btl/uct/btl_uct.h +++ b/opal/mca/btl/uct/btl_uct.h @@ -29,19 +29,19 @@ #define MCA_BTL_UCT_H #include "opal_config.h" -#include #include +#include /* Open MPI includes */ -#include "opal/util/event.h" -#include "opal/mca/btl/base/base.h" -#include "opal/mca/mpool/mpool.h" -#include "opal/mca/btl/base/btl_base_error.h" -#include "opal/mca/rcache/base/base.h" #include "opal/class/opal_fifo.h" #include "opal/class/opal_hash_table.h" +#include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/mpool/mpool.h" #include "opal/mca/pmix/pmix-internal.h" +#include "opal/mca/rcache/base/base.h" #include "opal/mca/threads/tsd.h" +#include "opal/util/event.h" #include #include "btl_uct_types.h" @@ -50,9 +50,9 @@ BEGIN_C_DECLS /* detection for old vs new atomic flags */ #if defined(UCT_IFACE_FLAG_ATOMIC_ADD32) -#define OPAL_HAVE_UCT_EP_ATOMIC64_POST 0 +# define OPAL_HAVE_UCT_EP_ATOMIC64_POST 0 #else -#define OPAL_HAVE_UCT_EP_ATOMIC64_POST 1 +# define OPAL_HAVE_UCT_EP_ATOMIC64_POST 1 #endif /** @@ -176,7 +176,8 @@ typedef struct mca_btl_uct_reg_t mca_btl_uct_reg_t; OBJ_CLASS_DECLARATION(mca_btl_uct_reg_t); -#define MCA_BTL_UCT_REG_REMOTE_TO_LOCAL(reg) ((mca_btl_uct_reg_t *)((intptr_t) (reg) - offsetof (mca_btl_uct_reg_t, handle))) +#define MCA_BTL_UCT_REG_REMOTE_TO_LOCAL(reg) \ + ((mca_btl_uct_reg_t *) ((intptr_t)(reg) -offsetof(mca_btl_uct_reg_t, handle))) /** * Initiate an asynchronous put. @@ -209,11 +210,12 @@ OBJ_CLASS_DECLARATION(mca_btl_uct_reg_t); * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -int mca_btl_uct_put (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_uct_put(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); /** * Initiate an asynchronous get. @@ -246,61 +248,70 @@ int mca_btl_uct_put (struct mca_btl_base_module_t *btl, * @retval OPAL_ERR_NOT_AVAILABLE Put can not be performed due to size or * alignment restrictions. */ -int mca_btl_uct_get (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - -int mca_btl_uct_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, +int mca_btl_uct_get(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); + +int mca_btl_uct_aop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); + +int mca_btl_uct_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, + uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); -int mca_btl_uct_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); - -int mca_btl_uct_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - +int mca_btl_uct_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, + uint64_t value, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); -int mca_btl_uct_flush (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); -int mca_btl_uct_flush_thread (mca_btl_base_module_t *btl); +int mca_btl_uct_flush(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); +int mca_btl_uct_flush_thread(mca_btl_base_module_t *btl); -int mca_btl_uct_finalize (mca_btl_base_module_t *btl); +int mca_btl_uct_finalize(mca_btl_base_module_t *btl); -int mca_btl_uct_reg_mem (void *reg_data, void *base, size_t size, mca_rcache_base_registration_t *reg); -int mca_btl_uct_dereg_mem (void *reg_data, mca_rcache_base_registration_t *reg); +int mca_btl_uct_reg_mem(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg); +int mca_btl_uct_dereg_mem(void *reg_data, mca_rcache_base_registration_t *reg); -ucs_status_t mca_btl_uct_am_handler (void *arg, void *data, size_t length, unsigned flags); +ucs_status_t mca_btl_uct_am_handler(void *arg, void *data, size_t length, unsigned flags); -struct mca_btl_base_endpoint_t *mca_btl_uct_get_ep (struct mca_btl_base_module_t *module, opal_proc_t *proc); +struct mca_btl_base_endpoint_t *mca_btl_uct_get_ep(struct mca_btl_base_module_t *module, + opal_proc_t *proc); -int mca_btl_uct_query_tls (mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, uct_tl_resource_desc_t *tl_descs, unsigned tl_count); -int mca_btl_uct_process_connection_request (mca_btl_uct_module_t *module, mca_btl_uct_conn_req_t *req); +int mca_btl_uct_query_tls(mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, + uct_tl_resource_desc_t *tl_descs, unsigned tl_count); +int mca_btl_uct_process_connection_request(mca_btl_uct_module_t *module, + mca_btl_uct_conn_req_t *req); /** * @brief Checks if a tl is suitable for using for RDMA * * @param[in] tl btl/uct tl pointer */ -static inline bool mca_btl_uct_tl_supports_rdma (mca_btl_uct_tl_t *tl) +static inline bool mca_btl_uct_tl_supports_rdma(mca_btl_uct_tl_t *tl) { - return (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & (UCT_IFACE_FLAG_PUT_ZCOPY | UCT_IFACE_FLAG_GET_ZCOPY)) == - (UCT_IFACE_FLAG_PUT_ZCOPY | UCT_IFACE_FLAG_GET_ZCOPY); + return (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags + & (UCT_IFACE_FLAG_PUT_ZCOPY | UCT_IFACE_FLAG_GET_ZCOPY)) + == (UCT_IFACE_FLAG_PUT_ZCOPY | UCT_IFACE_FLAG_GET_ZCOPY); } /** * @brief Checks if a tl is suitable for using for active messaging */ -static inline bool mca_btl_uct_tl_support_am (mca_btl_uct_tl_t *tl) +static inline bool mca_btl_uct_tl_support_am(mca_btl_uct_tl_t *tl) { - return (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & (UCT_IFACE_FLAG_AM_SHORT | UCT_IFACE_FLAG_AM_BCOPY | UCT_IFACE_FLAG_AM_ZCOPY)); + return (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags + & (UCT_IFACE_FLAG_AM_SHORT | UCT_IFACE_FLAG_AM_BCOPY | UCT_IFACE_FLAG_AM_ZCOPY)); } /** @@ -308,10 +319,11 @@ static inline bool mca_btl_uct_tl_support_am (mca_btl_uct_tl_t *tl) * * @param[in] tl btl/uct tl pointer */ -static inline bool mca_btl_uct_tl_supports_conn (mca_btl_uct_tl_t *tl) +static inline bool mca_btl_uct_tl_supports_conn(mca_btl_uct_tl_t *tl) { - return (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & (UCT_IFACE_FLAG_AM_SHORT | UCT_IFACE_FLAG_CONNECT_TO_IFACE)) == - (UCT_IFACE_FLAG_AM_SHORT | UCT_IFACE_FLAG_CONNECT_TO_IFACE); + return (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags + & (UCT_IFACE_FLAG_AM_SHORT | UCT_IFACE_FLAG_CONNECT_TO_IFACE)) + == (UCT_IFACE_FLAG_AM_SHORT | UCT_IFACE_FLAG_CONNECT_TO_IFACE); } /** @@ -319,7 +331,7 @@ static inline bool mca_btl_uct_tl_supports_conn (mca_btl_uct_tl_t *tl) * * @param[in] tl btl/uct tl pointer */ -static inline bool mca_btl_uct_tl_requires_connection_tl (mca_btl_uct_tl_t *tl) +static inline bool mca_btl_uct_tl_requires_connection_tl(mca_btl_uct_tl_t *tl) { return !(MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & UCT_IFACE_FLAG_CONNECT_TO_IFACE); } diff --git a/opal/mca/btl/uct/btl_uct_am.c b/opal/mca/btl/uct/btl_uct_am.c index 08f2b21ba8a..312c85e83e5 100644 --- a/opal/mca/btl/uct/btl_uct_am.c +++ b/opal/mca/btl/uct/btl_uct_am.c @@ -10,8 +10,8 @@ */ #include "btl_uct_am.h" -#include "btl_uct_rdma.h" #include "btl_uct_device_context.h" +#include "btl_uct_rdma.h" /** * Allocate a segment. @@ -19,26 +19,27 @@ * @param btl (IN) BTL module * @param size (IN) Request segment size. */ -mca_btl_base_descriptor_t *mca_btl_uct_alloc (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_uct_alloc(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, uint8_t order, + size_t size, uint32_t flags) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; mca_btl_uct_base_frag_t *frag = NULL; if (size <= (size_t) MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, 0).cap.am.max_short) { - frag = mca_btl_uct_frag_alloc_short (uct_btl, endpoint); + frag = mca_btl_uct_frag_alloc_short(uct_btl, endpoint); } else if (size <= uct_btl->super.btl_eager_limit) { - frag = mca_btl_uct_frag_alloc_eager (uct_btl, endpoint); + frag = mca_btl_uct_frag_alloc_eager(uct_btl, endpoint); } else { - frag = mca_btl_uct_frag_alloc_max (uct_btl, endpoint); + frag = mca_btl_uct_frag_alloc_max(uct_btl, endpoint); } if (OPAL_LIKELY(frag != NULL)) { - frag->segments[0].seg_len = size; + frag->segments[0].seg_len = size; frag->base.des_segment_count = 1; - frag->base.des_flags = flags; - frag->base.order = order; + frag->base.des_flags = flags; + frag->base.order = order; frag->uct_iov.length = size; if (NULL != frag->base.super.registration) { /* zero-copy fragments will need callbacks */ @@ -49,32 +50,32 @@ mca_btl_base_descriptor_t *mca_btl_uct_alloc (mca_btl_base_module_t *btl, mca_bt return (mca_btl_base_descriptor_t *) frag; } -static inline void _mca_btl_uct_send_pack (void *data, void *header, size_t header_size, opal_convertor_t *convertor, - size_t payload_size) +static inline void _mca_btl_uct_send_pack(void *data, void *header, size_t header_size, + opal_convertor_t *convertor, size_t payload_size) { uint32_t iov_count = 1; struct iovec iov; size_t length; if (header_size > 0) { - assert (NULL != header); - memcpy (data, header, header_size); + assert(NULL != header); + memcpy(data, header, header_size); } /* pack the data into the supplied buffer */ iov.iov_base = (IOVBASE_TYPE *) ((intptr_t) data + header_size); - iov.iov_len = length = payload_size; + iov.iov_len = length = payload_size; - (void) opal_convertor_pack (convertor, &iov, &iov_count, &length); + (void) opal_convertor_pack(convertor, &iov, &iov_count, &length); - assert (length == payload_size); + assert(length == payload_size); } -struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src (mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - opal_convertor_t *convertor, - uint8_t order, size_t reserve, - size_t *size, uint32_t flags) +struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, + opal_convertor_t *convertor, + uint8_t order, size_t reserve, + size_t *size, uint32_t flags) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; const size_t total_size = reserve + *size; @@ -82,26 +83,28 @@ struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src (mca_btl_base_module_t void *data_ptr; /* in place send fragment */ - if (OPAL_UNLIKELY(opal_convertor_need_buffers(convertor) || total_size > uct_btl->super.btl_eager_limit)) { - frag = (mca_btl_uct_base_frag_t *) mca_btl_uct_alloc (btl, endpoint, order, total_size, flags); + if (OPAL_UNLIKELY(opal_convertor_need_buffers(convertor) + || total_size > uct_btl->super.btl_eager_limit)) { + frag = (mca_btl_uct_base_frag_t *) mca_btl_uct_alloc(btl, endpoint, order, total_size, + flags); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } - _mca_btl_uct_send_pack ((void *) ((intptr_t) frag->uct_iov.buffer + reserve), NULL, 0, - convertor, *size); + _mca_btl_uct_send_pack((void *) ((intptr_t) frag->uct_iov.buffer + reserve), NULL, 0, + convertor, *size); } else { - opal_convertor_get_current_pointer (convertor, &data_ptr); - assert (NULL != data_ptr); + opal_convertor_get_current_pointer(convertor, &data_ptr); + assert(NULL != data_ptr); - frag = mca_btl_uct_frag_alloc_short (uct_btl, endpoint); + frag = mca_btl_uct_frag_alloc_short(uct_btl, endpoint); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } - frag->uct_iov.length = total_size; - frag->base.order = order; - frag->base.des_flags = flags; + frag->uct_iov.length = total_size; + frag->base.order = order; + frag->base.des_flags = flags; if (total_size > (size_t) MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, 0).cap.am.max_short) { frag->segments[0].seg_len = reserve; frag->segments[1].seg_len = *size; @@ -109,7 +112,8 @@ struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src (mca_btl_base_module_t frag->base.des_segment_count = 2; } else { frag->segments[0].seg_len = total_size; - memcpy ((void *)((intptr_t) frag->segments[0].seg_addr.pval + reserve), data_ptr, *size); + memcpy((void *) ((intptr_t) frag->segments[0].seg_addr.pval + reserve), data_ptr, + *size); frag->base.des_segment_count = 1; } } @@ -123,42 +127,43 @@ struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src (mca_btl_base_module_t * @param btl (IN) BTL module * @param segment (IN) Allocated segment. */ -int mca_btl_uct_free (mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) +int mca_btl_uct_free(mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { - mca_btl_uct_frag_return ((mca_btl_uct_base_frag_t *) des); + mca_btl_uct_frag_return((mca_btl_uct_base_frag_t *) des); return OPAL_SUCCESS; } -static size_t mca_btl_uct_send_frag_pack (void *data, void *arg) +static size_t mca_btl_uct_send_frag_pack(void *data, void *arg) { mca_btl_uct_base_frag_t *frag = (mca_btl_uct_base_frag_t *) arg; size_t length = 8; - memcpy (data, &frag->header, sizeof (frag->header)); - data = (void *)((intptr_t) data + 8); + memcpy(data, &frag->header, sizeof(frag->header)); + data = (void *) ((intptr_t) data + 8); /* this function should only ever get called with fragments with two segments */ - for (size_t i = 0 ; i < frag->base.des_segment_count ; ++i) { + for (size_t i = 0; i < frag->base.des_segment_count; ++i) { const size_t seg_len = frag->segments[i].seg_len; - memcpy (data, frag->segments[i].seg_addr.pval, seg_len); - data = (void *)((intptr_t) data + seg_len); + memcpy(data, frag->segments[i].seg_addr.pval, seg_len); + data = (void *) ((intptr_t) data + seg_len); length += seg_len; } return length; } -static void mca_btl_uct_append_pending_frag (mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_t *frag, - mca_btl_uct_device_context_t *context, bool ready) +static void mca_btl_uct_append_pending_frag(mca_btl_uct_module_t *uct_btl, + mca_btl_uct_base_frag_t *frag, + mca_btl_uct_device_context_t *context, bool ready) { frag->ready = ready; frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; - opal_atomic_wmb (); + opal_atomic_wmb(); - opal_list_append (&uct_btl->pending_frags, (opal_list_item_t *) frag); + opal_list_append(&uct_btl->pending_frags, (opal_list_item_t *) frag); } -int mca_btl_uct_send_frag (mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_t *frag, bool append) +int mca_btl_uct_send_frag(mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_t *frag, bool append) { mca_btl_uct_device_context_t *context = frag->context; const ssize_t msg_size = frag->uct_iov.length + 8; @@ -167,55 +172,59 @@ int mca_btl_uct_send_frag (mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_ uct_ep_h ep_handle = NULL; /* if we get here then we must have an endpoint handle for this context/endpoint pair */ - (void) mca_btl_uct_endpoint_test_am (uct_btl, frag->endpoint, frag->context, &ep_handle); - assert (NULL != ep_handle); + (void) mca_btl_uct_endpoint_test_am(uct_btl, frag->endpoint, frag->context, &ep_handle); + assert(NULL != ep_handle); /* if another thread set this we really don't care too much as this flag is only meant * to protect against deep recursion */ if (!context->in_am_callback) { - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); /* attempt to post the fragment */ - if (NULL != frag->base.super.registration && - (context->uct_iface_attr.cap.flags & UCT_IFACE_FLAG_AM_ZCOPY)) { + if (NULL != frag->base.super.registration + && (context->uct_iface_attr.cap.flags & UCT_IFACE_FLAG_AM_ZCOPY)) { frag->comp.dev_context = context; - ucs_status = uct_ep_am_zcopy (ep_handle, MCA_BTL_UCT_FRAG, &frag->header, sizeof (frag->header), - &frag->uct_iov, 1, 0, &frag->comp.uct_comp); + ucs_status = uct_ep_am_zcopy(ep_handle, MCA_BTL_UCT_FRAG, &frag->header, + sizeof(frag->header), &frag->uct_iov, 1, 0, + &frag->comp.uct_comp); if (OPAL_LIKELY(UCS_INPROGRESS == ucs_status)) { - uct_worker_progress (context->uct_worker); - mca_btl_uct_context_unlock (context); + uct_worker_progress(context->uct_worker); + mca_btl_uct_context_unlock(context); return OPAL_SUCCESS; } } else { /* short message */ - if (1 == frag->base.des_segment_count && (frag->uct_iov.length + 8) < MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, 0).cap.am.max_short) { - ucs_status = uct_ep_am_short (ep_handle, MCA_BTL_UCT_FRAG, frag->header.value, frag->uct_iov.buffer, - frag->uct_iov.length); + if (1 == frag->base.des_segment_count + && (frag->uct_iov.length + 8) + < MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, 0).cap.am.max_short) { + ucs_status = uct_ep_am_short(ep_handle, MCA_BTL_UCT_FRAG, frag->header.value, + frag->uct_iov.buffer, frag->uct_iov.length); if (OPAL_LIKELY(UCS_OK == ucs_status)) { - uct_worker_progress (context->uct_worker); - mca_btl_uct_context_unlock (context); + uct_worker_progress(context->uct_worker); + mca_btl_uct_context_unlock(context); /* send is complete */ - mca_btl_uct_frag_complete (frag, OPAL_SUCCESS); + mca_btl_uct_frag_complete(frag, OPAL_SUCCESS); return 1; } } - size = uct_ep_am_bcopy (ep_handle, MCA_BTL_UCT_FRAG, mca_btl_uct_send_frag_pack, frag, 0); + size = uct_ep_am_bcopy(ep_handle, MCA_BTL_UCT_FRAG, mca_btl_uct_send_frag_pack, frag, + 0); if (OPAL_LIKELY(size == msg_size)) { - uct_worker_progress (context->uct_worker); - mca_btl_uct_context_unlock (context); + uct_worker_progress(context->uct_worker); + mca_btl_uct_context_unlock(context); /* send is complete */ - mca_btl_uct_frag_complete (frag, OPAL_SUCCESS); + mca_btl_uct_frag_complete(frag, OPAL_SUCCESS); return 1; } } /* wait for something to happen */ - uct_worker_progress (context->uct_worker); - mca_btl_uct_context_unlock (context); + uct_worker_progress(context->uct_worker); + mca_btl_uct_context_unlock(context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); } if (!append) { @@ -223,41 +232,41 @@ int mca_btl_uct_send_frag (mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_ } OPAL_THREAD_LOCK(&uct_btl->lock); - mca_btl_uct_append_pending_frag (uct_btl, frag, context, true); + mca_btl_uct_append_pending_frag(uct_btl, frag, context, true); OPAL_THREAD_UNLOCK(&uct_btl->lock); return OPAL_SUCCESS; } -int mca_btl_uct_send (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, mca_btl_base_descriptor_t *descriptor, - mca_btl_base_tag_t tag) +int mca_btl_uct_send(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_am_context (uct_btl); + mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_am_context(uct_btl); mca_btl_uct_base_frag_t *frag = (mca_btl_uct_base_frag_t *) descriptor; uct_ep_h ep_handle; int rc; - BTL_VERBOSE(("btl/uct sending descriptor %p from %d -> %d. length = %" PRIu64, (void *)descriptor, - OPAL_PROC_MY_NAME.vpid, endpoint->ep_proc->proc_name.vpid, frag->uct_iov.length)); - + BTL_VERBOSE(("btl/uct sending descriptor %p from %d -> %d. length = %" PRIu64, + (void *) descriptor, OPAL_PROC_MY_NAME.vpid, endpoint->ep_proc->proc_name.vpid, + frag->uct_iov.length)); frag->header.data.tag = tag; frag->context = context; - rc = mca_btl_uct_endpoint_check_am (uct_btl, endpoint, context, &ep_handle); + rc = mca_btl_uct_endpoint_check_am(uct_btl, endpoint, context, &ep_handle); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { OPAL_THREAD_LOCK(&uct_btl->lock); /* check one more time in case another thread is completing the connection now */ - if (OPAL_SUCCESS != mca_btl_uct_endpoint_test_am (uct_btl, endpoint, context, &ep_handle)) { - mca_btl_uct_append_pending_frag (uct_btl, frag, context, false); + if (OPAL_SUCCESS != mca_btl_uct_endpoint_test_am(uct_btl, endpoint, context, &ep_handle)) { + mca_btl_uct_append_pending_frag(uct_btl, frag, context, false); OPAL_THREAD_UNLOCK(&uct_btl->lock); return OPAL_SUCCESS; } OPAL_THREAD_UNLOCK(&uct_btl->lock); } - return mca_btl_uct_send_frag (uct_btl, frag, true); + return mca_btl_uct_send_frag(uct_btl, frag, true); } struct mca_btl_uct_sendi_pack_args_t { @@ -270,28 +279,29 @@ struct mca_btl_uct_sendi_pack_args_t { typedef struct mca_btl_uct_sendi_pack_args_t mca_btl_uct_sendi_pack_args_t; -static size_t mca_btl_uct_sendi_pack (void *data, void *arg) +static size_t mca_btl_uct_sendi_pack(void *data, void *arg) { mca_btl_uct_sendi_pack_args_t *args = (mca_btl_uct_sendi_pack_args_t *) arg; mca_btl_uct_am_header_t *am_header = (mca_btl_uct_am_header_t *) data; am_header->value = args->am_header; - _mca_btl_uct_send_pack ((void *)((intptr_t)data + 8), args->header, args->header_size, args->convertor, - args->payload_size); + _mca_btl_uct_send_pack((void *) ((intptr_t) data + 8), args->header, args->header_size, + args->convertor, args->payload_size); return args->header_size + args->payload_size + 8; } -static inline size_t mca_btl_uct_max_sendi (mca_btl_uct_module_t *uct_btl, int context_id) +static inline size_t mca_btl_uct_max_sendi(mca_btl_uct_module_t *uct_btl, int context_id) { return MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, context_id).cap.am.max_bcopy; } -int mca_btl_uct_sendi (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, opal_convertor_t *convertor, - void *header, size_t header_size, size_t payload_size, uint8_t order, uint32_t flags, - mca_btl_base_tag_t tag, mca_btl_base_descriptor_t **descriptor) +int mca_btl_uct_sendi(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_am_context (uct_btl); + mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_am_context(uct_btl); const size_t total_size = header_size + payload_size; /* message with header */ const size_t msg_size = total_size + 8; @@ -300,10 +310,11 @@ int mca_btl_uct_sendi (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endp uct_ep_h ep_handle; int rc; - rc = mca_btl_uct_endpoint_check_am (uct_btl, endpoint, context, &ep_handle); - if (OPAL_UNLIKELY(OPAL_SUCCESS != rc || msg_size > mca_btl_uct_max_sendi (uct_btl, context->context_id))) { + rc = mca_btl_uct_endpoint_check_am(uct_btl, endpoint, context, &ep_handle); + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc + || msg_size > mca_btl_uct_max_sendi(uct_btl, context->context_id))) { if (descriptor) { - *descriptor = mca_btl_uct_alloc (btl, endpoint, order, total_size, flags); + *descriptor = mca_btl_uct_alloc(btl, endpoint, order, total_size, flags); } return OPAL_ERR_OUT_OF_RESOURCE; @@ -311,30 +322,36 @@ int mca_btl_uct_sendi (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endp am_header.data.tag = tag; - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); if (0 == payload_size) { - ucs_status = uct_ep_am_short (ep_handle, MCA_BTL_UCT_FRAG, am_header.value, header, header_size); - } else if (msg_size < (size_t) MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, context->context_id).cap.am.max_short) { - int8_t *data = alloca (total_size); - _mca_btl_uct_send_pack (data, header, header_size, convertor, payload_size); - ucs_status = uct_ep_am_short (ep_handle, MCA_BTL_UCT_FRAG, am_header.value, data, total_size); + ucs_status = uct_ep_am_short(ep_handle, MCA_BTL_UCT_FRAG, am_header.value, header, + header_size); + } else if (msg_size < (size_t) MCA_BTL_UCT_TL_ATTR(uct_btl->am_tl, context->context_id) + .cap.am.max_short) { + int8_t *data = alloca(total_size); + _mca_btl_uct_send_pack(data, header, header_size, convertor, payload_size); + ucs_status = uct_ep_am_short(ep_handle, MCA_BTL_UCT_FRAG, am_header.value, data, + total_size); } else { ssize_t size; - size = uct_ep_am_bcopy (ep_handle, MCA_BTL_UCT_FRAG, mca_btl_uct_sendi_pack, - &(mca_btl_uct_sendi_pack_args_t) {.am_header = am_header.value, - .header = header, .header_size = header_size, - .convertor = convertor, .payload_size = payload_size}, 0); + size = uct_ep_am_bcopy(ep_handle, MCA_BTL_UCT_FRAG, mca_btl_uct_sendi_pack, + &(mca_btl_uct_sendi_pack_args_t){.am_header = am_header.value, + .header = header, + .header_size = header_size, + .convertor = convertor, + .payload_size = payload_size}, + 0); if (OPAL_LIKELY(size == (ssize_t) msg_size)) { ucs_status = UCS_OK; } } - mca_btl_uct_context_unlock (context); + mca_btl_uct_context_unlock(context); if (OPAL_UNLIKELY(UCS_OK != ucs_status)) { if (descriptor) { - *descriptor = mca_btl_uct_alloc (btl, endpoint, order, total_size, flags); + *descriptor = mca_btl_uct_alloc(btl, endpoint, order, total_size, flags); } return OPAL_ERR_OUT_OF_RESOURCE; diff --git a/opal/mca/btl/uct/btl_uct_am.h b/opal/mca/btl/uct/btl_uct_am.h index 9035540e710..695cc0b5e0a 100644 --- a/opal/mca/btl/uct/btl_uct_am.h +++ b/opal/mca/btl/uct/btl_uct_am.h @@ -10,29 +10,31 @@ */ #if !defined(MCA_BTL_UCT_AM_H) -#define MCA_BTL_UCT_AM_H +# define MCA_BTL_UCT_AM_H -#include "btl_uct_frag.h" +# include "btl_uct_frag.h" -struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src (mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - opal_convertor_t *convertor, - uint8_t order, size_t reserve, - size_t *size, uint32_t flags); +struct mca_btl_base_descriptor_t *mca_btl_uct_prepare_src(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, + opal_convertor_t *convertor, + uint8_t order, size_t reserve, + size_t *size, uint32_t flags); -int mca_btl_uct_sendi (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, opal_convertor_t *convertor, - void *header, size_t header_size, size_t payload_size, uint8_t order, uint32_t flags, - mca_btl_base_tag_t tag, mca_btl_base_descriptor_t **descriptor); +int mca_btl_uct_sendi(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor); -int mca_btl_uct_send (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, mca_btl_base_descriptor_t *descriptor, - mca_btl_base_tag_t tag); +int mca_btl_uct_send(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag); -int mca_btl_uct_send_frag (mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_t *frag, bool append); +int mca_btl_uct_send_frag(mca_btl_uct_module_t *uct_btl, mca_btl_uct_base_frag_t *frag, + bool append); -mca_btl_base_descriptor_t *mca_btl_uct_alloc (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags); - -int mca_btl_uct_free (mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); +mca_btl_base_descriptor_t *mca_btl_uct_alloc(mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, uint8_t order, + size_t size, uint32_t flags); +int mca_btl_uct_free(mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); #endif /* !defined(MCA_BTL_UCT_AM_H) */ diff --git a/opal/mca/btl/uct/btl_uct_amo.c b/opal/mca/btl/uct/btl_uct_amo.c index 72398ce7369..01e195274b2 100644 --- a/opal/mca/btl/uct/btl_uct_amo.c +++ b/opal/mca/btl/uct/btl_uct_amo.c @@ -15,22 +15,21 @@ /* we add 1 to the ops to differentiate between unsupported and supported ops since * UCT_ATOMIC_OP_ADD == 0. otherwise we would have to fill in this table completely. */ static int mca_btl_uct_btl_to_uct_atomic[MCA_BTL_ATOMIC_LAST] = { - [MCA_BTL_ATOMIC_ADD] = UCT_ATOMIC_OP_ADD + 1, - [MCA_BTL_ATOMIC_AND] = UCT_ATOMIC_OP_AND + 1, - [MCA_BTL_ATOMIC_OR] = UCT_ATOMIC_OP_OR + 1, - [MCA_BTL_ATOMIC_XOR] = UCT_ATOMIC_OP_XOR + 1, + [MCA_BTL_ATOMIC_ADD] = UCT_ATOMIC_OP_ADD + 1, [MCA_BTL_ATOMIC_AND] = UCT_ATOMIC_OP_AND + 1, + [MCA_BTL_ATOMIC_OR] = UCT_ATOMIC_OP_OR + 1, [MCA_BTL_ATOMIC_XOR] = UCT_ATOMIC_OP_XOR + 1, [MCA_BTL_ATOMIC_SWAP] = UCT_ATOMIC_OP_SWAP + 1, }; #endif -int mca_btl_uct_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +int mca_btl_uct_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, + uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context (uct_btl); + mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context(uct_btl); mca_btl_uct_uct_completion_t *comp = NULL; ucs_status_t ucs_status; uct_rkey_bundle_t rkey; @@ -50,75 +49,77 @@ int mca_btl_uct_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end #endif if (cbfunc) { - comp = mca_btl_uct_uct_completion_alloc (uct_btl, endpoint, local_address, local_handle, context, - cbfunc, cbcontext, cbdata); + comp = mca_btl_uct_uct_completion_alloc(uct_btl, endpoint, local_address, local_handle, + context, cbfunc, cbcontext, cbdata); if (OPAL_UNLIKELY(NULL == comp)) { return OPAL_ERR_OUT_OF_RESOURCE; } } - rc = mca_btl_uct_get_rkey (uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); + rc = mca_btl_uct_get_rkey(uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); return rc; } - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); #if OPAL_HAVE_UCT_EP_ATOMIC64_POST if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) { - ucs_status = uct_ep_atomic32_fetch (ep_handle, uct_op, operand, (uint32_t *) local_address, remote_address, - rkey.rkey, &comp->uct_comp); + ucs_status = uct_ep_atomic32_fetch(ep_handle, uct_op, operand, (uint32_t *) local_address, + remote_address, rkey.rkey, &comp->uct_comp); } else { - ucs_status = uct_ep_atomic64_fetch (ep_handle, uct_op, operand, (uint64_t *) local_address, remote_address, - rkey.rkey, &comp->uct_comp); + ucs_status = uct_ep_atomic64_fetch(ep_handle, uct_op, operand, (uint64_t *) local_address, + remote_address, rkey.rkey, &comp->uct_comp); } #else if (MCA_BTL_ATOMIC_ADD == op) { if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) { - ucs_status = uct_ep_atomic_fadd32 (ep_handle, (uint32_t) operand, remote_address, - rkey.rkey, (uint32_t *) local_address, &comp->uct_comp); + ucs_status = uct_ep_atomic_fadd32(ep_handle, (uint32_t) operand, remote_address, + rkey.rkey, (uint32_t *) local_address, + &comp->uct_comp); } else { - ucs_status = uct_ep_atomic_fadd64 (ep_handle, operand, remote_address, rkey.rkey, - (uint64_t *) local_address, &comp->uct_comp); + ucs_status = uct_ep_atomic_fadd64(ep_handle, operand, remote_address, rkey.rkey, + (uint64_t *) local_address, &comp->uct_comp); } } else { if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) { - ucs_status = uct_ep_atomic_swap32 (ep_handle, (uint32_t) operand, remote_address, - rkey.rkey, (uint32_t *) local_address, &comp->uct_comp); + ucs_status = uct_ep_atomic_swap32(ep_handle, (uint32_t) operand, remote_address, + rkey.rkey, (uint32_t *) local_address, + &comp->uct_comp); } else { - ucs_status = uct_ep_atomic_swap64 (ep_handle, operand, remote_address, rkey.rkey, - (uint64_t *) local_address, &comp->uct_comp); + ucs_status = uct_ep_atomic_swap64(ep_handle, operand, remote_address, rkey.rkey, + (uint64_t *) local_address, &comp->uct_comp); } } #endif /* go ahead and progress the worker while we have the lock */ - (void) uct_worker_progress (context->uct_worker); + (void) uct_worker_progress(context->uct_worker); - mca_btl_uct_context_unlock (context); + mca_btl_uct_context_unlock(context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); if (UCS_INPROGRESS == ucs_status) { rc = OPAL_SUCCESS; } else if (UCS_OK == ucs_status) { rc = 1; - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); } else { rc = OPAL_ERR_OUT_OF_RESOURCE; - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); } - mca_btl_uct_rkey_release (uct_btl, &rkey); + mca_btl_uct_rkey_release(uct_btl, &rkey); return rc; } -int mca_btl_uct_aop (struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, - uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_uct_aop(struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { /* this is static so it survives after this function returns. we don't care about the result */ static uint64_t result; @@ -126,17 +127,19 @@ int mca_btl_uct_aop (struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t /* just use the fetching ops for now. there probably is a performance benefit to using * the non-fetching on some platforms but this is easier to implement quickly and it * guarantees remote completion. */ - return mca_btl_uct_afop (btl, endpoint, &result, remote_address, NULL, remote_handle, op, - operand, flags, order, cbfunc, cbcontext, cbdata); + return mca_btl_uct_afop(btl, endpoint, &result, remote_address, NULL, remote_handle, op, + operand, flags, order, cbfunc, cbcontext, cbdata); } -int mca_btl_uct_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_uct_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, + uint64_t value, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context (uct_btl); + mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context(uct_btl); mca_btl_uct_uct_completion_t *comp = NULL; ucs_status_t ucs_status; uct_rkey_bundle_t rkey; @@ -144,47 +147,48 @@ int mca_btl_uct_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_e int rc; if (cbfunc) { - comp = mca_btl_uct_uct_completion_alloc (uct_btl, endpoint, local_address, local_handle, context, - cbfunc, cbcontext, cbdata); + comp = mca_btl_uct_uct_completion_alloc(uct_btl, endpoint, local_address, local_handle, + context, cbfunc, cbcontext, cbdata); if (OPAL_UNLIKELY(NULL == comp)) { return OPAL_ERR_OUT_OF_RESOURCE; } } - rc = mca_btl_uct_get_rkey (uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); + rc = mca_btl_uct_get_rkey(uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); return rc; } - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) { - ucs_status = uct_ep_atomic_cswap32 (ep_handle, (uint32_t) compare, (uint32_t) value, remote_address, - rkey.rkey, (uint32_t *) local_address, &comp->uct_comp); + ucs_status = uct_ep_atomic_cswap32(ep_handle, (uint32_t) compare, (uint32_t) value, + remote_address, rkey.rkey, (uint32_t *) local_address, + &comp->uct_comp); } else { - ucs_status = uct_ep_atomic_cswap64 (ep_handle, compare, value, remote_address, rkey.rkey, - (uint64_t *) local_address, &comp->uct_comp); + ucs_status = uct_ep_atomic_cswap64(ep_handle, compare, value, remote_address, rkey.rkey, + (uint64_t *) local_address, &comp->uct_comp); } /* go ahead and progress the worker while we have the lock */ - (void) uct_worker_progress (context->uct_worker); + (void) uct_worker_progress(context->uct_worker); - mca_btl_uct_context_unlock (context); + mca_btl_uct_context_unlock(context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); if (UCS_INPROGRESS == ucs_status) { rc = OPAL_SUCCESS; } else if (UCS_OK == ucs_status) { rc = 1; - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); } else { rc = OPAL_ERR_OUT_OF_RESOURCE; - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); } - mca_btl_uct_rkey_release (uct_btl, &rkey); + mca_btl_uct_rkey_release(uct_btl, &rkey); return rc; } diff --git a/opal/mca/btl/uct/btl_uct_component.c b/opal/mca/btl/uct/btl_uct_component.c index baf4e11f124..0de76088154 100644 --- a/opal/mca/btl/uct/btl_uct_component.c +++ b/opal/mca/btl/uct/btl_uct_component.c @@ -26,81 +26,85 @@ * $HEADER$ */ - #include "opal_config.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/hwloc/base/base.h" -#include "opal/util/argv.h" -#include "opal/memoryhooks/memory.h" #include "opal/mca/memory/base/base.h" +#include "opal/memoryhooks/memory.h" +#include "opal/util/argv.h" #include #include "opal/util/printf.h" #include -#include "btl_uct_device_context.h" #include "btl_uct_am.h" +#include "btl_uct_device_context.h" static int mca_btl_uct_component_register(void) { mca_btl_uct_module_t *module = &mca_btl_uct_module_template; mca_btl_uct_component.memory_domains = "none"; - (void) mca_base_component_var_register(&mca_btl_uct_component.super.btl_version, - "memory_domains", "Comma-delimited list of memory domains of the form " - "to use for communication. Memory domains MUST provide transports that " - "support put, get, and amos. Special values: all (all available), none." - " (default: none)", MCA_BASE_VAR_TYPE_STRING, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, - &mca_btl_uct_component.memory_domains); + (void) mca_base_component_var_register( + &mca_btl_uct_component.super.btl_version, "memory_domains", + "Comma-delimited list of memory domains of the form " + "to use for communication. Memory domains MUST provide transports that " + "support put, get, and amos. Special values: all (all available), none." + " (default: none)", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_uct_component.memory_domains); mca_btl_uct_component.allowed_transports = "dc_mlx5,rc_mlx5,ud,ugni_rdma,ugni_smsg,any"; - (void) mca_base_component_var_register(&mca_btl_uct_component.super.btl_version, - "transports", "Comma-delimited list of transports to use sorted by increasing " - "priority. The list of transports available can be queried using ucx_info. Special" - "values: any (any available) (default: dc_mlx5,rc_mlx5,ud,any)", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_uct_component.allowed_transports); + (void) mca_base_component_var_register( + &mca_btl_uct_component.super.btl_version, "transports", + "Comma-delimited list of transports to use sorted by increasing " + "priority. The list of transports available can be queried using ucx_info. Special" + "values: any (any available) (default: dc_mlx5,rc_mlx5,ud,any)", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_uct_component.allowed_transports); mca_btl_uct_component.num_contexts_per_module = 0; - (void) mca_base_component_var_register(&mca_btl_uct_component.super.btl_version, - "num_contexts_per_module", "Number of UCT worker contexts " - "to create for each BTL module. Larger numbers will improve " - "multi-threaded performance but may increase memory usage. " - "A good rule of thumb is one context per application thread " - "that will be calling into MPI. (default: 0 -- autoselect " - "based on the number of cores)", MCA_BASE_VAR_TYPE_INT, - NULL, 0 ,MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_ALL, &mca_btl_uct_component.num_contexts_per_module); + (void) mca_base_component_var_register( + &mca_btl_uct_component.super.btl_version, "num_contexts_per_module", + "Number of UCT worker contexts " + "to create for each BTL module. Larger numbers will improve " + "multi-threaded performance but may increase memory usage. " + "A good rule of thumb is one context per application thread " + "that will be calling into MPI. (default: 0 -- autoselect " + "based on the number of cores)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL, &mca_btl_uct_component.num_contexts_per_module); mca_btl_uct_component.disable_ucx_memory_hooks = true; - (void) mca_base_component_var_register(&mca_btl_uct_component.super.btl_version, - "disable_ucx_memory_hooks", "Disable the munmap memory hook " - "inside UCX. These hooks are not necessary when using the " - "uct btl and tend to cause performance problems when using " - "multiple threads (default: true)", MCA_BASE_VAR_TYPE_BOOL, - NULL, 0 ,MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_ALL, &mca_btl_uct_component.disable_ucx_memory_hooks); - + (void) + mca_base_component_var_register(&mca_btl_uct_component.super.btl_version, + "disable_ucx_memory_hooks", + "Disable the munmap memory hook " + "inside UCX. These hooks are not necessary when using the " + "uct btl and tend to cause performance problems when using " + "multiple threads (default: true)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, + OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL, + &mca_btl_uct_component.disable_ucx_memory_hooks); #if OPAL_C_HAVE__THREAD_LOCAL mca_btl_uct_component.bind_threads_to_contexts = true; - (void) mca_base_component_var_register(&mca_btl_uct_component.super.btl_version, - "bind_threads_to_contexts", "Bind threads to device contexts. " - "In general this should improve the multi-threaded performance " - "when threads are used. (default: true)", MCA_BASE_VAR_TYPE_BOOL, - NULL, 0 ,MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_ALL, &mca_btl_uct_component.bind_threads_to_contexts); + (void) mca_base_component_var_register( + &mca_btl_uct_component.super.btl_version, "bind_threads_to_contexts", + "Bind threads to device contexts. " + "In general this should improve the multi-threaded performance " + "when threads are used. (default: true)", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL, &mca_btl_uct_component.bind_threads_to_contexts); #endif /* for now we want this component to lose to btl/ugni and btl/vader */ module->super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH; - return mca_btl_base_param_register (&mca_btl_uct_component.super.btl_version, - &module->super); + return mca_btl_base_param_register(&mca_btl_uct_component.super.btl_version, &module->super); } static void mca_btl_uct_mem_release_cb(void *buf, size_t length, void *cbdata, bool from_alloc) @@ -115,15 +119,17 @@ static int mca_btl_uct_component_open(void) * how many UCT workers to create */ int core_count = 36; - (void) opal_hwloc_base_get_topology (); - core_count = hwloc_get_nbobjs_by_type (opal_hwloc_topology, HWLOC_OBJ_CORE); + (void) opal_hwloc_base_get_topology(); + core_count = hwloc_get_nbobjs_by_type(opal_hwloc_topology, HWLOC_OBJ_CORE); if (core_count <= opal_process_info.num_local_peers || !opal_using_threads()) { /* there is probably no benefit to using multiple device contexts when not * using threads or oversubscribing the node with mpi processes. */ mca_btl_uct_component.num_contexts_per_module = 1; } else { - mca_btl_uct_component.num_contexts_per_module = core_count / (opal_process_info.num_local_peers + 1); + mca_btl_uct_component.num_contexts_per_module = core_count + / (opal_process_info.num_local_peers + + 1); } } @@ -131,10 +137,10 @@ static int mca_btl_uct_component_open(void) mca_btl_uct_component.num_contexts_per_module = MCA_BTL_UCT_MAX_WORKERS; } - if (mca_btl_uct_component.disable_ucx_memory_hooks && - ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) == - ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & - opal_mem_hooks_support_level()))) { + if (mca_btl_uct_component.disable_ucx_memory_hooks + && ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) + == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) + & opal_mem_hooks_support_level()))) { ucm_set_external_event(UCM_EVENT_VM_UNMAPPED); opal_mem_hooks_register_release(mca_btl_uct_mem_release_cb, NULL); } @@ -142,60 +148,61 @@ static int mca_btl_uct_component_open(void) return OPAL_SUCCESS; } - /* * component cleanup - sanity checking of queue lengths */ static int mca_btl_uct_component_close(void) { if (mca_btl_uct_component.disable_ucx_memory_hooks) { - opal_mem_hooks_unregister_release (mca_btl_uct_mem_release_cb); + opal_mem_hooks_unregister_release(mca_btl_uct_mem_release_cb); } return OPAL_SUCCESS; } -static size_t mca_btl_uct_tl_modex_size (mca_btl_uct_tl_t *tl) +static size_t mca_btl_uct_tl_modex_size(mca_btl_uct_tl_t *tl) { - const size_t size = strlen (tl->uct_tl_name) + 1; + const size_t size = strlen(tl->uct_tl_name) + 1; if (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & UCT_IFACE_FLAG_CONNECT_TO_IFACE) { /* pad out to a multiple of 4 bytes */ - return (4 + 3 + size + MCA_BTL_UCT_TL_ATTR(tl, 0).device_addr_len + MCA_BTL_UCT_TL_ATTR(tl, 0).iface_addr_len) & ~3; + return (4 + 3 + size + MCA_BTL_UCT_TL_ATTR(tl, 0).device_addr_len + + MCA_BTL_UCT_TL_ATTR(tl, 0).iface_addr_len) + & ~3; } return (4 + 3 + size + MCA_BTL_UCT_TL_ATTR(tl, 0).device_addr_len) & ~3; } -static size_t mca_btl_uct_module_modex_size (mca_btl_uct_module_t *module) +static size_t mca_btl_uct_module_modex_size(mca_btl_uct_module_t *module) { - size_t modex_size = 4 + strlen (module->md_name) + 1; + size_t modex_size = 4 + strlen(module->md_name) + 1; if (module->rdma_tl) { - modex_size += mca_btl_uct_tl_modex_size (module->rdma_tl); + modex_size += mca_btl_uct_tl_modex_size(module->rdma_tl); } if (module->am_tl && module->am_tl != module->rdma_tl) { - modex_size += mca_btl_uct_tl_modex_size (module->am_tl); + modex_size += mca_btl_uct_tl_modex_size(module->am_tl); } if (module->conn_tl && module->conn_tl != module->rdma_tl && module->conn_tl != module->am_tl) { - modex_size += mca_btl_uct_tl_modex_size (module->conn_tl); + modex_size += mca_btl_uct_tl_modex_size(module->conn_tl); } return modex_size; } -static size_t mca_btl_uct_tl_modex_pack (mca_btl_uct_tl_t *tl, uint8_t *modex_data) +static size_t mca_btl_uct_tl_modex_pack(mca_btl_uct_tl_t *tl, uint8_t *modex_data) { mca_btl_uct_device_context_t *dev_context = tl->uct_dev_contexts[0]; - size_t modex_size = mca_btl_uct_tl_modex_size (tl); + size_t modex_size = mca_btl_uct_tl_modex_size(tl); *((uint32_t *) modex_data) = (uint32_t) modex_size; modex_data += 4; - strcpy ((char *) modex_data, tl->uct_tl_name); - modex_data += strlen (tl->uct_tl_name) + 1; + strcpy((char *) modex_data, tl->uct_tl_name); + modex_data += strlen(tl->uct_tl_name) + 1; /* NTH: only the first context is available. i assume the device addresses of the * contexts will be the same but they will have different iface addresses. i also @@ -204,54 +211,55 @@ static size_t mca_btl_uct_tl_modex_pack (mca_btl_uct_tl_t *tl, uint8_t *modex_da * wrong then we can't delay creating the other contexts and must include their * information in the modex. */ if (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & UCT_IFACE_FLAG_CONNECT_TO_IFACE) { - uct_iface_get_address (dev_context->uct_iface, (uct_iface_addr_t *) modex_data); + uct_iface_get_address(dev_context->uct_iface, (uct_iface_addr_t *) modex_data); modex_data += MCA_BTL_UCT_TL_ATTR(tl, 0).iface_addr_len; } - uct_iface_get_device_address (dev_context->uct_iface, (uct_device_addr_t *) modex_data); + uct_iface_get_device_address(dev_context->uct_iface, (uct_device_addr_t *) modex_data); modex_data += MCA_BTL_UCT_TL_ATTR(tl, 0).device_addr_len; return modex_size; } -static int mca_btl_uct_modex_send (void) +static int mca_btl_uct_modex_send(void) { - size_t modex_size = sizeof (mca_btl_uct_modex_t); + size_t modex_size = sizeof(mca_btl_uct_modex_t); mca_btl_uct_modex_t *modex; uint8_t *modex_data; int rc; - for (int i = 0 ; i < mca_btl_uct_component.module_count ; ++i) { - modex_size += mca_btl_uct_module_modex_size (mca_btl_uct_component.modules[i]); + for (int i = 0; i < mca_btl_uct_component.module_count; ++i) { + modex_size += mca_btl_uct_module_modex_size(mca_btl_uct_component.modules[i]); } - modex = alloca (modex_size); + modex = alloca(modex_size); modex_data = modex->data; modex->module_count = mca_btl_uct_component.module_count; - for (int i = 0 ; i < mca_btl_uct_component.module_count ; ++i) { + for (int i = 0; i < mca_btl_uct_component.module_count; ++i) { mca_btl_uct_module_t *module = mca_btl_uct_component.modules[i]; - size_t name_len = strlen (module->md_name); + size_t name_len = strlen(module->md_name); /* pack the size */ - *((uint32_t *) modex_data) = (uint32_t) mca_btl_uct_module_modex_size (module); + *((uint32_t *) modex_data) = (uint32_t) mca_btl_uct_module_modex_size(module); modex_data += 4; - strcpy ((char *) modex_data, module->md_name); + strcpy((char *) modex_data, module->md_name); modex_data += name_len + 1; if (module->rdma_tl) { - modex_data += mca_btl_uct_tl_modex_pack (module->rdma_tl, modex_data); + modex_data += mca_btl_uct_tl_modex_pack(module->rdma_tl, modex_data); } if (module->am_tl && module->am_tl != module->rdma_tl) { - modex_data += mca_btl_uct_tl_modex_pack (module->am_tl, modex_data); + modex_data += mca_btl_uct_tl_modex_pack(module->am_tl, modex_data); } - if (module->conn_tl && module->conn_tl != module->rdma_tl && module->conn_tl != module->am_tl) { - modex_data += mca_btl_uct_tl_modex_pack (module->conn_tl, modex_data); + if (module->conn_tl && module->conn_tl != module->rdma_tl + && module->conn_tl != module->am_tl) { + modex_data += mca_btl_uct_tl_modex_pack(module->conn_tl, modex_data); } } @@ -259,13 +267,13 @@ static int mca_btl_uct_modex_send (void) return rc; } -static mca_btl_uct_module_t *mca_btl_uct_alloc_module (const char *md_name, mca_btl_uct_md_t *md, - size_t registration_size) +static mca_btl_uct_module_t *mca_btl_uct_alloc_module(const char *md_name, mca_btl_uct_md_t *md, + size_t registration_size) { mca_btl_uct_module_t *module; ucs_status_t ucs_status; - module = malloc (sizeof (*module)); + module = malloc(sizeof(*module)); if (NULL == module) { return NULL; } @@ -283,43 +291,49 @@ static mca_btl_uct_module_t *mca_btl_uct_alloc_module (const char *md_name, mca_ OBJ_CONSTRUCT(&module->pending_connection_reqs, opal_fifo_t); module->md = md; - module->md_name = strdup (md_name); + module->md_name = strdup(md_name); module->super.btl_registration_handle_size = registration_size; - ucs_status = ucs_async_context_create (UCS_ASYNC_MODE_THREAD, &module->ucs_async); + ucs_status = ucs_async_context_create(UCS_ASYNC_MODE_THREAD, &module->ucs_async); if (UCS_OK != ucs_status) { BTL_VERBOSE(("Could not create a UCT async context")); - mca_btl_uct_finalize (&module->super); + mca_btl_uct_finalize(&module->super); return NULL; } return module; } -ucs_status_t mca_btl_uct_am_handler (void *arg, void *data, size_t length, unsigned flags) +ucs_status_t mca_btl_uct_am_handler(void *arg, void *data, size_t length, unsigned flags) { mca_btl_uct_device_context_t *tl_context = (mca_btl_uct_device_context_t *) arg; mca_btl_uct_module_t *uct_btl = tl_context->uct_btl; mca_btl_uct_am_header_t *header = (mca_btl_uct_am_header_t *) data; mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + header->data.tag; - mca_btl_base_segment_t seg = {.seg_addr = {.pval = (void *) ((intptr_t) data + sizeof (*header))}, - .seg_len = length - sizeof (*header)}; - mca_btl_base_receive_descriptor_t desc = {.endpoint = NULL, .des_segments = &seg, .des_segment_count = 1, - .tag = header->data.tag, .cbdata = reg->cbdata}; + mca_btl_base_segment_t seg = {.seg_addr = {.pval = (void *) ((intptr_t) data + + sizeof(*header))}, + .seg_len = length - sizeof(*header)}; + mca_btl_base_receive_descriptor_t desc = {.endpoint = NULL, + .des_segments = &seg, + .des_segment_count = 1, + .tag = header->data.tag, + .cbdata = reg->cbdata}; /* prevent recursion */ tl_context->in_am_callback = true; - reg->cbfunc (&uct_btl->super, &desc); + reg->cbfunc(&uct_btl->super, &desc); tl_context->in_am_callback = false; return UCS_OK; } #if UCT_API >= UCT_VERSION(1, 7) -static int mca_btl_uct_component_process_uct_md (uct_component_h component, uct_md_resource_desc_t *md_desc, - char **allowed_ifaces) +static int mca_btl_uct_component_process_uct_md(uct_component_h component, + uct_md_resource_desc_t *md_desc, + char **allowed_ifaces) #else -static int mca_btl_uct_component_process_uct_md (uct_md_resource_desc_t *md_desc, char **allowed_ifaces) +static int mca_btl_uct_component_process_uct_md(uct_md_resource_desc_t *md_desc, + char **allowed_ifaces) #endif { mca_rcache_base_resources_t rcache_resources; @@ -339,9 +353,9 @@ static int mca_btl_uct_component_process_uct_md (uct_md_resource_desc_t *md_desc BTL_VERBOSE(("processing memory domain %s", md_desc->md_name)); - for (int j = 0 ; allowed_ifaces[j] ; ++j) { - if (0 == strncmp (allowed_ifaces[j], md_desc->md_name, strlen (md_desc->md_name)) || - 0 == strcmp (allowed_ifaces[j], "all")) { + for (int j = 0; allowed_ifaces[j]; ++j) { + if (0 == strncmp(allowed_ifaces[j], md_desc->md_name, strlen(md_desc->md_name)) + || 0 == strcmp(allowed_ifaces[j], "all")) { found = true; break; } @@ -354,36 +368,35 @@ static int mca_btl_uct_component_process_uct_md (uct_md_resource_desc_t *md_desc md = OBJ_NEW(mca_btl_uct_md_t); - #if UCT_API >= UCT_VERSION(1, 7) - uct_md_config_read (component, NULL, NULL, &uct_config); - uct_md_open (component, md_desc->md_name, uct_config, &md->uct_md); + uct_md_config_read(component, NULL, NULL, &uct_config); + uct_md_open(component, md_desc->md_name, uct_config, &md->uct_md); #else - uct_md_config_read (md_desc->md_name, NULL, NULL, &uct_config); - uct_md_open (md_desc->md_name, uct_config, &md->uct_md); + uct_md_config_read(md_desc->md_name, NULL, NULL, &uct_config); + uct_md_open(md_desc->md_name, uct_config, &md->uct_md); #endif - uct_config_release (uct_config); + uct_config_release(uct_config); - uct_md_query (md->uct_md, &md_attr); - uct_md_query_tl_resources (md->uct_md, &tl_desc, &num_tls); + uct_md_query(md->uct_md, &md_attr); + uct_md_query_tl_resources(md->uct_md, &tl_desc, &num_tls); - module = mca_btl_uct_alloc_module (md_desc->md_name, md, md_attr.rkey_packed_size); + module = mca_btl_uct_alloc_module(md_desc->md_name, md, md_attr.rkey_packed_size); if (NULL == module) { - uct_release_tl_resource_list (tl_desc); + uct_release_tl_resource_list(tl_desc); return OPAL_ERR_OUT_OF_RESOURCE; } - (void) mca_btl_uct_query_tls (module, md, tl_desc, num_tls); + (void) mca_btl_uct_query_tls(module, md, tl_desc, num_tls); - uct_release_tl_resource_list (tl_desc); + uct_release_tl_resource_list(tl_desc); - /* release the initial reference to the md object. if any modules were created the UCT md will remain - * open until those modules are finalized. */ + /* release the initial reference to the md object. if any modules were created the UCT md will + * remain open until those modules are finalized. */ OBJ_RELEASE(md); if (NULL == module->am_tl && NULL == module->rdma_tl) { BTL_VERBOSE(("uct memory domain %s does not have any appropriate tls", md_desc->md_name)); - mca_btl_uct_finalize (&module->super); + mca_btl_uct_finalize(&module->super); return OPAL_ERR_NOT_AVAILABLE; } @@ -396,20 +409,21 @@ static int mca_btl_uct_component_process_uct_md (uct_md_resource_desc_t *md_desc /* NTH: a registration cache shouldn't be necessary when using UCT but there are measurable * performance benefits to using rcache/grdma instead of assuming UCT will do the right * thing. */ - (void) opal_asprintf (&tmp, "uct.%s", module->md_name); + (void) opal_asprintf(&tmp, "uct.%s", module->md_name); - rcache_resources.cache_name = tmp; - rcache_resources.reg_data = (void *) module; - rcache_resources.sizeof_reg = sizeof (mca_btl_uct_reg_t) + module->super.btl_registration_handle_size; - rcache_resources.register_mem = mca_btl_uct_reg_mem; + rcache_resources.cache_name = tmp; + rcache_resources.reg_data = (void *) module; + rcache_resources.sizeof_reg = sizeof(mca_btl_uct_reg_t) + + module->super.btl_registration_handle_size; + rcache_resources.register_mem = mca_btl_uct_reg_mem; rcache_resources.deregister_mem = mca_btl_uct_dereg_mem; - module->rcache = mca_rcache_base_module_create ("grdma", module, &rcache_resources); - free (tmp); + module->rcache = mca_rcache_base_module_create("grdma", module, &rcache_resources); + free(tmp); if (NULL == module->rcache) { /* something when horribly wrong */ BTL_VERBOSE(("could not allocate a registration cache for this btl module")); - mca_btl_uct_finalize (&module->super); + mca_btl_uct_finalize(&module->super); return OPAL_ERROR; } @@ -417,36 +431,36 @@ static int mca_btl_uct_component_process_uct_md (uct_md_resource_desc_t *md_desc } #if UCT_API >= UCT_VERSION(1, 7) -static int mca_btl_uct_component_process_uct_component (uct_component_h component, char **allowed_ifaces) +static int mca_btl_uct_component_process_uct_component(uct_component_h component, + char **allowed_ifaces) { - uct_component_attr_t attr = {.field_mask = UCT_COMPONENT_ATTR_FIELD_NAME | - UCT_COMPONENT_ATTR_FIELD_MD_RESOURCE_COUNT}; + uct_component_attr_t attr = {.field_mask = UCT_COMPONENT_ATTR_FIELD_NAME + | UCT_COMPONENT_ATTR_FIELD_MD_RESOURCE_COUNT}; ucs_status_t ucs_status; int rc; - ucs_status = uct_component_query (component, &attr); + ucs_status = uct_component_query(component, &attr); if (UCS_OK != ucs_status) { return OPAL_ERROR; } BTL_VERBOSE(("processing uct component %s", attr.name)); - attr.md_resources = calloc (attr.md_resource_count, sizeof (*attr.md_resources)); + attr.md_resources = calloc(attr.md_resource_count, sizeof(*attr.md_resources)); attr.field_mask |= UCT_COMPONENT_ATTR_FIELD_MD_RESOURCES; - ucs_status = uct_component_query (component, &attr); + ucs_status = uct_component_query(component, &attr); if (UCS_OK != ucs_status) { return OPAL_ERROR; } - for (int i = 0 ; i < attr.md_resource_count ; ++i) { - rc = mca_btl_uct_component_process_uct_md (component, attr.md_resources + i, - allowed_ifaces); + for (int i = 0; i < attr.md_resource_count; ++i) { + rc = mca_btl_uct_component_process_uct_md(component, attr.md_resources + i, allowed_ifaces); if (OPAL_SUCCESS != rc) { break; } } - free (attr.md_resources); + free(attr.md_resources); return OPAL_SUCCESS; } @@ -460,10 +474,12 @@ static int mca_btl_uct_component_process_uct_component (uct_component_h componen * (3) register BTL parameters with the MCA */ -static mca_btl_base_module_t **mca_btl_uct_component_init (int *num_btl_modules, bool enable_progress_threads, - bool enable_mpi_threads) +static mca_btl_base_module_t **mca_btl_uct_component_init(int *num_btl_modules, + bool enable_progress_threads, + bool enable_mpi_threads) { - /* for this BTL to be useful the interface needs to support RDMA and certain atomic operations */ + /* for this BTL to be useful the interface needs to support RDMA and certain atomic operations + */ struct mca_btl_base_module_t **base_modules; uct_md_resource_desc_t *resources; unsigned resource_count; @@ -473,13 +489,14 @@ static mca_btl_base_module_t **mca_btl_uct_component_init (int *num_btl_modules, BTL_VERBOSE(("initializing uct btl")); - if (NULL == mca_btl_uct_component.memory_domains || 0 == strlen (mca_btl_uct_component.memory_domains) || - 0 == strcmp (mca_btl_uct_component.memory_domains, "none")) { + if (NULL == mca_btl_uct_component.memory_domains + || 0 == strlen(mca_btl_uct_component.memory_domains) + || 0 == strcmp(mca_btl_uct_component.memory_domains, "none")) { BTL_VERBOSE(("no uct memory domains specified")); return NULL; } - allowed_ifaces = opal_argv_split (mca_btl_uct_component.memory_domains, ','); + allowed_ifaces = opal_argv_split(mca_btl_uct_component.memory_domains, ','); if (NULL == allowed_ifaces) { return NULL; } @@ -497,42 +514,42 @@ static mca_btl_base_module_t **mca_btl_uct_component_init (int *num_btl_modules, } /* generate all suitable btl modules */ - for (unsigned i = 0 ; i < num_components ; ++i) { - rc = mca_btl_uct_component_process_uct_component (components[i], allowed_ifaces); + for (unsigned i = 0; i < num_components; ++i) { + rc = mca_btl_uct_component_process_uct_component(components[i], allowed_ifaces); if (OPAL_SUCCESS != rc) { break; } } - uct_release_component_list (components); + uct_release_component_list(components); #else /* UCT 1.6 and older */ - uct_query_md_resources (&resources, &resource_count); + uct_query_md_resources(&resources, &resource_count); /* generate all suitable btl modules */ - for (unsigned i = 0 ; i < resource_count ; ++i) { - rc = mca_btl_uct_component_process_uct_md (resources + i, allowed_ifaces); + for (unsigned i = 0; i < resource_count; ++i) { + rc = mca_btl_uct_component_process_uct_md(resources + i, allowed_ifaces); if (OPAL_SUCCESS != rc) { break; } } - uct_release_md_resource_list (resources); + uct_release_md_resource_list(resources); #endif /* UCT_API >= UCT_VERSION(1, 7) */ - opal_argv_free (allowed_ifaces); - mca_btl_uct_modex_send (); + opal_argv_free(allowed_ifaces); + mca_btl_uct_modex_send(); /* pass module array back to caller */ - base_modules = calloc (mca_btl_uct_component.module_count, sizeof (*base_modules)); + base_modules = calloc(mca_btl_uct_component.module_count, sizeof(*base_modules)); if (NULL == base_modules) { return NULL; } - memcpy (base_modules, mca_btl_uct_component.modules, mca_btl_uct_component.module_count * - sizeof (mca_btl_uct_component.modules[0])); + memcpy(base_modules, mca_btl_uct_component.modules, + mca_btl_uct_component.module_count * sizeof(mca_btl_uct_component.modules[0])); *num_btl_modules = mca_btl_uct_component.module_count; @@ -542,7 +559,7 @@ static mca_btl_base_module_t **mca_btl_uct_component_init (int *num_btl_modules, return base_modules; } -static int mca_btl_uct_tl_progress (mca_btl_uct_tl_t *tl, int starting_index) +static int mca_btl_uct_tl_progress(mca_btl_uct_tl_t *tl, int starting_index) { unsigned int ret = 0; @@ -550,35 +567,35 @@ static int mca_btl_uct_tl_progress (mca_btl_uct_tl_t *tl, int starting_index) return 0; } - for (int j = 0 ; j < tl->max_device_contexts ; ++j) { + for (int j = 0; j < tl->max_device_contexts; ++j) { if (tl->uct_dev_contexts[j]) { - ret += mca_btl_uct_context_progress (tl->uct_dev_contexts[j]); + ret += mca_btl_uct_context_progress(tl->uct_dev_contexts[j]); } } return ret; } -static int mca_btl_uct_component_progress_pending (mca_btl_uct_module_t *uct_btl) +static int mca_btl_uct_component_progress_pending(mca_btl_uct_module_t *uct_btl) { mca_btl_uct_base_frag_t *frag, *next; int completed = 0; size_t count; - if (0 == (count = opal_list_get_size (&uct_btl->pending_frags))) { + if (0 == (count = opal_list_get_size(&uct_btl->pending_frags))) { return 0; } OPAL_THREAD_LOCK(&uct_btl->lock); - OPAL_LIST_FOREACH_SAFE(frag, next, &uct_btl->pending_frags, mca_btl_uct_base_frag_t) { + OPAL_LIST_FOREACH_SAFE (frag, next, &uct_btl->pending_frags, mca_btl_uct_base_frag_t) { if (!frag->ready) { continue; } - opal_list_remove_item (&uct_btl->pending_frags, (opal_list_item_t *) frag); + opal_list_remove_item(&uct_btl->pending_frags, (opal_list_item_t *) frag); - if (OPAL_SUCCESS > mca_btl_uct_send_frag (uct_btl, frag, false)) { - opal_list_prepend (&uct_btl->pending_frags, (opal_list_item_t *) frag); + if (OPAL_SUCCESS > mca_btl_uct_send_frag(uct_btl, frag, false)) { + opal_list_prepend(&uct_btl->pending_frags, (opal_list_item_t *) frag); } else { completed++; } @@ -593,37 +610,40 @@ static int mca_btl_uct_component_progress_pending (mca_btl_uct_module_t *uct_btl * * This function explictly progresses all workers. */ -static int mca_btl_uct_component_progress (void) +static int mca_btl_uct_component_progress(void) { - int starting_index = mca_btl_uct_get_context_index (); + int starting_index = mca_btl_uct_get_context_index(); unsigned ret = 0; - for (int i = 0 ; i < mca_btl_uct_component.module_count ; ++i) { + for (int i = 0; i < mca_btl_uct_component.module_count; ++i) { mca_btl_uct_module_t *module = mca_btl_uct_component.modules[i]; /* unlike ucp, uct actually tells us something useful! its almost like it was "inspired" * by the btl progress functions.... */ - ret += mca_btl_uct_tl_progress (module->rdma_tl, starting_index); + ret += mca_btl_uct_tl_progress(module->rdma_tl, starting_index); if (module->am_tl != module->rdma_tl) { - ret += mca_btl_uct_tl_progress (module->am_tl, starting_index); + ret += mca_btl_uct_tl_progress(module->am_tl, starting_index); } if (module->conn_tl) { mca_btl_uct_pending_connection_request_t *request; if (module->conn_tl != module->am_tl && module->conn_tl != module->rdma_tl) { - ret += mca_btl_uct_tl_progress (module->conn_tl, 0); + ret += mca_btl_uct_tl_progress(module->conn_tl, 0); } - while (NULL != (request = (mca_btl_uct_pending_connection_request_t *) opal_fifo_pop_atomic (&module->pending_connection_reqs))) { - mca_btl_uct_process_connection_request (module, (mca_btl_uct_conn_req_t *) request->request_data); + while (NULL + != (request = (mca_btl_uct_pending_connection_request_t *) opal_fifo_pop_atomic( + &module->pending_connection_reqs))) { + mca_btl_uct_process_connection_request(module, (mca_btl_uct_conn_req_t *) + request->request_data); OBJ_RELEASE(request); } } - if (0 != opal_list_get_size (&module->pending_frags)) { - mca_btl_uct_component_progress_pending (module); + if (0 != opal_list_get_size(&module->pending_frags)) { + mca_btl_uct_component_progress_pending(module); } } @@ -633,18 +653,17 @@ static int mca_btl_uct_component_progress (void) /** UCT btl component */ mca_btl_uct_component_t mca_btl_uct_component = { .super = { - .btl_version = { - MCA_BTL_DEFAULT_VERSION("uct"), - .mca_open_component = mca_btl_uct_component_open, - .mca_close_component = mca_btl_uct_component_close, - .mca_register_component_params = mca_btl_uct_component_register, - }, - .btl_data = { - /* The component is not checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_NONE - }, + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("uct"), + .mca_open_component = mca_btl_uct_component_open, + .mca_close_component = mca_btl_uct_component_close, + .mca_register_component_params = mca_btl_uct_component_register, + }, + .btl_data = + {/* The component is not checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_NONE}, .btl_init = mca_btl_uct_component_init, .btl_progress = mca_btl_uct_component_progress, - } -}; + }}; diff --git a/opal/mca/btl/uct/btl_uct_device_context.h b/opal/mca/btl/uct/btl_uct_device_context.h index f88e4314710..b394621c327 100644 --- a/opal/mca/btl/uct/btl_uct_device_context.h +++ b/opal/mca/btl/uct/btl_uct_device_context.h @@ -10,11 +10,11 @@ */ #if !defined(BTL_UCT_DEVICE_CONTEXT_H) -#define BTL_UCT_DEVICE_CONTEXT_H +# define BTL_UCT_DEVICE_CONTEXT_H -#include "btl_uct.h" -#include "btl_uct_rdma.h" -#include "btl_uct_frag.h" +# include "btl_uct.h" +# include "btl_uct_frag.h" +# include "btl_uct_rdma.h" /** * @brief Create a new device context for the given transport @@ -23,7 +23,9 @@ * @param[in] tl btl uct tl pointer * @param[in] context_id identifier for this context (0..MCA_BTL_UCT_MAX_WORKERS-1) */ -mca_btl_uct_device_context_t *mca_btl_uct_context_create (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl, int context_id, bool enable_progress); +mca_btl_uct_device_context_t *mca_btl_uct_context_create(mca_btl_uct_module_t *module, + mca_btl_uct_tl_t *tl, int context_id, + bool enable_progress); /** * @brief Destroy a device context and release all resources @@ -33,58 +35,61 @@ mca_btl_uct_device_context_t *mca_btl_uct_context_create (mca_btl_uct_module_t * * This call frees a device context and all assoicated resources. It is not * valid to use the device context after this returns. */ -void mca_btl_uct_context_destroy (mca_btl_uct_device_context_t *context); +void mca_btl_uct_context_destroy(mca_btl_uct_device_context_t *context); -static inline bool mca_btl_uct_context_trylock (mca_btl_uct_device_context_t *context) +static inline bool mca_btl_uct_context_trylock(mca_btl_uct_device_context_t *context) { return OPAL_THREAD_TRYLOCK(&context->mutex); } -static inline void mca_btl_uct_context_lock (mca_btl_uct_device_context_t *context) +static inline void mca_btl_uct_context_lock(mca_btl_uct_device_context_t *context) { - OPAL_THREAD_LOCK (&context->mutex); + OPAL_THREAD_LOCK(&context->mutex); } -static inline void mca_btl_uct_context_unlock (mca_btl_uct_device_context_t *context) +static inline void mca_btl_uct_context_unlock(mca_btl_uct_device_context_t *context) { - OPAL_THREAD_UNLOCK (&context->mutex); + OPAL_THREAD_UNLOCK(&context->mutex); } -#define MCA_BTL_UCT_CONTEXT_SERIALIZE(context,code) \ - do { \ - mca_btl_uct_context_lock (context); \ - code; \ - mca_btl_uct_context_unlock(context); \ - } while (0); +# define MCA_BTL_UCT_CONTEXT_SERIALIZE(context, code) \ + do { \ + mca_btl_uct_context_lock(context); \ + code; \ + mca_btl_uct_context_unlock(context); \ + } while (0); -static inline int mca_btl_uct_get_context_index (void) +static inline int mca_btl_uct_get_context_index(void) { static opal_atomic_uint32_t next_uct_index = 0; int context_id; -#if OPAL_C_HAVE__THREAD_LOCAL +# if OPAL_C_HAVE__THREAD_LOCAL if (mca_btl_uct_component.bind_threads_to_contexts) { static _Thread_local int uct_index = -1; context_id = uct_index; if (OPAL_UNLIKELY(-1 == context_id)) { - context_id = uct_index = opal_atomic_fetch_add_32 ((opal_atomic_int32_t *) &next_uct_index, 1) % - mca_btl_uct_component.num_contexts_per_module; + context_id = uct_index = opal_atomic_fetch_add_32((opal_atomic_int32_t + *) &next_uct_index, + 1) + % mca_btl_uct_component.num_contexts_per_module; } } else { -#endif - /* avoid using atomics in this. i doubt it improves performance to ensure atomicity on the next - * index in this case. */ +# endif + /* avoid using atomics in this. i doubt it improves performance to ensure atomicity on the + * next index in this case. */ context_id = next_uct_index++ % mca_btl_uct_component.num_contexts_per_module; -#if OPAL_C_HAVE__THREAD_LOCAL +# if OPAL_C_HAVE__THREAD_LOCAL } -#endif +# endif return context_id; } static inline mca_btl_uct_device_context_t * -mca_btl_uct_module_get_tl_context_specific (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl, int context_id) +mca_btl_uct_module_get_tl_context_specific(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl, + int context_id) { mca_btl_uct_device_context_t *context = tl->uct_dev_contexts[context_id]; @@ -92,7 +97,9 @@ mca_btl_uct_module_get_tl_context_specific (mca_btl_uct_module_t *module, mca_bt OPAL_THREAD_LOCK(&module->lock); context = tl->uct_dev_contexts[context_id]; if (OPAL_UNLIKELY(NULL == context)) { - context = tl->uct_dev_contexts[context_id] = mca_btl_uct_context_create (module, tl, context_id, true); + context = tl->uct_dev_contexts[context_id] = mca_btl_uct_context_create(module, tl, + context_id, + true); } OPAL_THREAD_UNLOCK(&module->lock); } @@ -100,32 +107,39 @@ mca_btl_uct_module_get_tl_context_specific (mca_btl_uct_module_t *module, mca_bt return context; } -static inline mca_btl_uct_device_context_t *mca_btl_uct_module_get_rdma_context (mca_btl_uct_module_t *module) +static inline mca_btl_uct_device_context_t * +mca_btl_uct_module_get_rdma_context(mca_btl_uct_module_t *module) { - return mca_btl_uct_module_get_tl_context_specific (module, module->rdma_tl, mca_btl_uct_get_context_index ()); + return mca_btl_uct_module_get_tl_context_specific(module, module->rdma_tl, + mca_btl_uct_get_context_index()); } -static inline mca_btl_uct_device_context_t *mca_btl_uct_module_get_rdma_context_specific (mca_btl_uct_module_t *module, int context_id) +static inline mca_btl_uct_device_context_t * +mca_btl_uct_module_get_rdma_context_specific(mca_btl_uct_module_t *module, int context_id) { - return mca_btl_uct_module_get_tl_context_specific (module, module->rdma_tl, context_id); + return mca_btl_uct_module_get_tl_context_specific(module, module->rdma_tl, context_id); } -static inline mca_btl_uct_device_context_t *mca_btl_uct_module_get_am_context (mca_btl_uct_module_t *module) +static inline mca_btl_uct_device_context_t * +mca_btl_uct_module_get_am_context(mca_btl_uct_module_t *module) { - return mca_btl_uct_module_get_tl_context_specific (module, module->am_tl, mca_btl_uct_get_context_index ()); + return mca_btl_uct_module_get_tl_context_specific(module, module->am_tl, + mca_btl_uct_get_context_index()); } -static inline void mca_btl_uct_device_handle_completions (mca_btl_uct_device_context_t *dev_context) +static inline void mca_btl_uct_device_handle_completions(mca_btl_uct_device_context_t *dev_context) { mca_btl_uct_uct_completion_t *comp; - while (NULL != (comp = (mca_btl_uct_uct_completion_t *) opal_fifo_pop (&dev_context->completion_fifo))) { + while ( + NULL + != (comp = (mca_btl_uct_uct_completion_t *) opal_fifo_pop(&dev_context->completion_fifo))) { int rc = UCS_OK == comp->status ? OPAL_SUCCESS : OPAL_ERROR; if (comp->frag) { /* reset the count */ comp->uct_comp.count = 1; - mca_btl_uct_frag_complete (comp->frag, rc); + mca_btl_uct_frag_complete(comp->frag, rc); continue; } @@ -133,13 +147,13 @@ static inline void mca_btl_uct_device_handle_completions (mca_btl_uct_device_con /* we may be calling the callback before remote completion. this is in violation of the * btl interface specification but should not hurt in non-ob1 use cases. if this ever * becomes a problem we can look at possible solutions. */ - comp->cbfunc (comp->btl, comp->endpoint, comp->local_address, comp->local_handle, - comp->cbcontext, comp->cbdata, rc); - mca_btl_uct_uct_completion_release (comp); + comp->cbfunc(comp->btl, comp->endpoint, comp->local_address, comp->local_handle, + comp->cbcontext, comp->cbdata, rc); + mca_btl_uct_uct_completion_release(comp); } } -static inline int mca_btl_uct_context_progress (mca_btl_uct_device_context_t *context) +static inline int mca_btl_uct_context_progress(mca_btl_uct_device_context_t *context) { int ret = 0; @@ -147,11 +161,11 @@ static inline int mca_btl_uct_context_progress (mca_btl_uct_device_context_t *co return 0; } - if (!mca_btl_uct_context_trylock (context)) { - ret = uct_worker_progress (context->uct_worker); - mca_btl_uct_context_unlock (context); + if (!mca_btl_uct_context_trylock(context)) { + ret = uct_worker_progress(context->uct_worker); + mca_btl_uct_context_unlock(context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); } return ret; diff --git a/opal/mca/btl/uct/btl_uct_endpoint.c b/opal/mca/btl/uct/btl_uct_endpoint.c index ccdbd4511a2..90f8f41cf97 100644 --- a/opal/mca/btl/uct/btl_uct_endpoint.c +++ b/opal/mca/btl/uct/btl_uct_endpoint.c @@ -12,25 +12,26 @@ * $HEADER$ */ -#include "btl_uct.h" #include "btl_uct_endpoint.h" -#include "btl_uct_device_context.h" +#include "btl_uct.h" #include "btl_uct_am.h" +#include "btl_uct_device_context.h" #include "opal/util/proc.h" -static void mca_btl_uct_endpoint_construct (mca_btl_uct_endpoint_t *endpoint) +static void mca_btl_uct_endpoint_construct(mca_btl_uct_endpoint_t *endpoint) { - memset (endpoint->uct_eps, 0, sizeof (endpoint->uct_eps[0]) * mca_btl_uct_component.num_contexts_per_module); + memset(endpoint->uct_eps, 0, + sizeof(endpoint->uct_eps[0]) * mca_btl_uct_component.num_contexts_per_module); endpoint->conn_ep = NULL; OBJ_CONSTRUCT(&endpoint->ep_lock, opal_recursive_mutex_t); } -static void mca_btl_uct_endpoint_destruct (mca_btl_uct_endpoint_t *endpoint) +static void mca_btl_uct_endpoint_destruct(mca_btl_uct_endpoint_t *endpoint) { - for (int tl_index = 0 ; tl_index < 2 ; ++tl_index) { - for (int i = 0 ; i < mca_btl_uct_component.num_contexts_per_module ; ++i) { + for (int tl_index = 0; tl_index < 2; ++tl_index) { + for (int i = 0; i < mca_btl_uct_component.num_contexts_per_module; ++i) { if (NULL != endpoint->uct_eps[i][tl_index].uct_ep) { - uct_ep_destroy (endpoint->uct_eps[i][tl_index].uct_ep); + uct_ep_destroy(endpoint->uct_eps[i][tl_index].uct_ep); } } } @@ -38,14 +39,15 @@ static void mca_btl_uct_endpoint_destruct (mca_btl_uct_endpoint_t *endpoint) OBJ_DESTRUCT(&endpoint->ep_lock); } -OBJ_CLASS_INSTANCE(mca_btl_uct_endpoint_t, opal_object_t, - mca_btl_uct_endpoint_construct, +OBJ_CLASS_INSTANCE(mca_btl_uct_endpoint_t, opal_object_t, mca_btl_uct_endpoint_construct, mca_btl_uct_endpoint_destruct); -mca_btl_base_endpoint_t *mca_btl_uct_endpoint_create (opal_proc_t *proc) +mca_btl_base_endpoint_t *mca_btl_uct_endpoint_create(opal_proc_t *proc) { - mca_btl_uct_endpoint_t *endpoint = calloc (1, sizeof (*endpoint) + sizeof (endpoint->uct_eps[0]) * - mca_btl_uct_component.num_contexts_per_module); + mca_btl_uct_endpoint_t *endpoint = calloc(1, sizeof(*endpoint) + + sizeof(endpoint->uct_eps[0]) + * mca_btl_uct_component + .num_contexts_per_module); if (OPAL_UNLIKELY(NULL == endpoint)) { return NULL; @@ -57,24 +59,25 @@ mca_btl_base_endpoint_t *mca_btl_uct_endpoint_create (opal_proc_t *proc) return (mca_btl_base_endpoint_t *) endpoint; } -static unsigned char *mca_btl_uct_process_modex_tl (unsigned char *modex_data) +static unsigned char *mca_btl_uct_process_modex_tl(unsigned char *modex_data) { - BTL_VERBOSE(("processing modex for tl %s. size: %u", modex_data + 4, *((uint32_t *) modex_data))); + BTL_VERBOSE( + ("processing modex for tl %s. size: %u", modex_data + 4, *((uint32_t *) modex_data))); /* skip size and name */ - return modex_data + 4 + strlen ((char *) modex_data + 4) + 1; + return modex_data + 4 + strlen((char *) modex_data + 4) + 1; } -static void mca_btl_uct_process_modex (mca_btl_uct_module_t *uct_btl, unsigned char *modex_data, - unsigned char **rdma_tl_data, unsigned char **am_tl_data, - unsigned char **conn_tl_data) +static void mca_btl_uct_process_modex(mca_btl_uct_module_t *uct_btl, unsigned char *modex_data, + unsigned char **rdma_tl_data, unsigned char **am_tl_data, + unsigned char **conn_tl_data) { BTL_VERBOSE(("processing remote modex data")); if (uct_btl->rdma_tl) { BTL_VERBOSE(("modex contains RDMA data")); if (rdma_tl_data) { - *rdma_tl_data = mca_btl_uct_process_modex_tl (modex_data); + *rdma_tl_data = mca_btl_uct_process_modex_tl(modex_data); } modex_data += *((uint32_t *) modex_data); } else if (rdma_tl_data) { @@ -84,17 +87,18 @@ static void mca_btl_uct_process_modex (mca_btl_uct_module_t *uct_btl, unsigned c if (uct_btl->am_tl && uct_btl->am_tl != uct_btl->rdma_tl) { BTL_VERBOSE(("modex contains active message data")); if (am_tl_data) { - *am_tl_data = mca_btl_uct_process_modex_tl (modex_data); + *am_tl_data = mca_btl_uct_process_modex_tl(modex_data); } modex_data += *((uint32_t *) modex_data); } else if (am_tl_data) { *am_tl_data = NULL; } - if (uct_btl->conn_tl && uct_btl->conn_tl != uct_btl->rdma_tl && uct_btl->conn_tl != uct_btl->am_tl) { + if (uct_btl->conn_tl && uct_btl->conn_tl != uct_btl->rdma_tl + && uct_btl->conn_tl != uct_btl->am_tl) { BTL_VERBOSE(("modex contains connection data")); if (conn_tl_data) { - *conn_tl_data = mca_btl_uct_process_modex_tl (modex_data); + *conn_tl_data = mca_btl_uct_process_modex_tl(modex_data); } modex_data += *((uint32_t *) modex_data); } else if (conn_tl_data) { @@ -102,31 +106,38 @@ static void mca_btl_uct_process_modex (mca_btl_uct_module_t *uct_btl, unsigned c } } -static inline ucs_status_t mca_btl_uct_ep_create_connected_compat (uct_iface_h iface, uct_device_addr_t *device_addr, - uct_iface_addr_t *iface_addr, uct_ep_h *uct_ep) +static inline ucs_status_t mca_btl_uct_ep_create_connected_compat(uct_iface_h iface, + uct_device_addr_t *device_addr, + uct_iface_addr_t *iface_addr, + uct_ep_h *uct_ep) { #if UCT_API >= UCT_VERSION(1, 6) - uct_ep_params_t ep_params = {.field_mask = UCT_EP_PARAM_FIELD_IFACE | UCT_EP_PARAM_FIELD_DEV_ADDR | UCT_EP_PARAM_FIELD_IFACE_ADDR, - .iface = iface, .dev_addr = device_addr, .iface_addr = iface_addr}; - return uct_ep_create (&ep_params, uct_ep); + uct_ep_params_t ep_params = {.field_mask = UCT_EP_PARAM_FIELD_IFACE + | UCT_EP_PARAM_FIELD_DEV_ADDR + | UCT_EP_PARAM_FIELD_IFACE_ADDR, + .iface = iface, + .dev_addr = device_addr, + .iface_addr = iface_addr}; + return uct_ep_create(&ep_params, uct_ep); #else - return uct_ep_create_connected (iface, device_addr, iface_addr, uct_ep); + return uct_ep_create_connected(iface, device_addr, iface_addr, uct_ep); #endif } -static inline ucs_status_t mca_btl_uct_ep_create_compat (uct_iface_h iface, uct_ep_h *uct_ep) +static inline ucs_status_t mca_btl_uct_ep_create_compat(uct_iface_h iface, uct_ep_h *uct_ep) { #if UCT_API >= UCT_VERSION(1, 6) uct_ep_params_t ep_params = {.field_mask = UCT_EP_PARAM_FIELD_IFACE, .iface = iface}; - return uct_ep_create (&ep_params, uct_ep); + return uct_ep_create(&ep_params, uct_ep); #else - return uct_ep_create (iface, uct_ep); + return uct_ep_create(iface, uct_ep); #endif } -static int mca_btl_uct_endpoint_connect_iface (mca_btl_uct_module_t *uct_btl, mca_btl_uct_tl_t *tl, - mca_btl_uct_device_context_t *tl_context, - mca_btl_uct_tl_endpoint_t *tl_endpoint, uint8_t *tl_data) +static int mca_btl_uct_endpoint_connect_iface(mca_btl_uct_module_t *uct_btl, mca_btl_uct_tl_t *tl, + mca_btl_uct_device_context_t *tl_context, + mca_btl_uct_tl_endpoint_t *tl_endpoint, + uint8_t *tl_data) { uct_device_addr_t *device_addr = NULL; uct_iface_addr_t *iface_addr; @@ -134,27 +145,30 @@ static int mca_btl_uct_endpoint_connect_iface (mca_btl_uct_module_t *uct_btl, mc /* easy case. just connect to the interface */ iface_addr = (uct_iface_addr_t *) tl_data; - device_addr = (uct_device_addr_t *) ((uintptr_t) iface_addr + MCA_BTL_UCT_TL_ATTR(tl, tl_context->context_id).iface_addr_len); + device_addr = (uct_device_addr_t *) ((uintptr_t) iface_addr + + MCA_BTL_UCT_TL_ATTR(tl, tl_context->context_id) + .iface_addr_len); BTL_VERBOSE(("connecting endpoint to interface")); - mca_btl_uct_context_lock (tl_context); - ucs_status = mca_btl_uct_ep_create_connected_compat (tl_context->uct_iface, device_addr, iface_addr, &tl_endpoint->uct_ep); + mca_btl_uct_context_lock(tl_context); + ucs_status = mca_btl_uct_ep_create_connected_compat(tl_context->uct_iface, device_addr, + iface_addr, &tl_endpoint->uct_ep); tl_endpoint->flags = MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY; - mca_btl_uct_context_unlock (tl_context); + mca_btl_uct_context_unlock(tl_context); return (UCS_OK == ucs_status) ? OPAL_SUCCESS : OPAL_ERROR; } -static void mca_btl_uct_connection_ep_construct (mca_btl_uct_connection_ep_t *ep) +static void mca_btl_uct_connection_ep_construct(mca_btl_uct_connection_ep_t *ep) { ep->uct_ep = NULL; } -static void mca_btl_uct_connection_ep_destruct (mca_btl_uct_connection_ep_t *ep) +static void mca_btl_uct_connection_ep_destruct(mca_btl_uct_connection_ep_t *ep) { if (ep->uct_ep) { - uct_ep_destroy (ep->uct_ep); + uct_ep_destroy(ep->uct_ep); ep->uct_ep = NULL; } } @@ -168,35 +182,38 @@ struct mca_btl_uct_conn_completion_t { }; typedef struct mca_btl_uct_conn_completion_t mca_btl_uct_conn_completion_t; -static void mca_btl_uct_endpoint_flush_complete (uct_completion_t *self, ucs_status_t status) +static void mca_btl_uct_endpoint_flush_complete(uct_completion_t *self, ucs_status_t status) { mca_btl_uct_conn_completion_t *completion = (mca_btl_uct_conn_completion_t *) self; BTL_VERBOSE(("connection flush complete")); completion->complete = true; } -static int mca_btl_uct_endpoint_send_conn_req (mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint, - mca_btl_uct_device_context_t *conn_tl_context, - mca_btl_uct_conn_req_t *request, size_t request_length) +static int mca_btl_uct_endpoint_send_conn_req(mca_btl_uct_module_t *uct_btl, + mca_btl_base_endpoint_t *endpoint, + mca_btl_uct_device_context_t *conn_tl_context, + mca_btl_uct_conn_req_t *request, + size_t request_length) { mca_btl_uct_connection_ep_t *conn_ep = endpoint->conn_ep; - mca_btl_uct_conn_completion_t completion = {.super = {.count = 1, .func = mca_btl_uct_endpoint_flush_complete}, - .complete = false}; + mca_btl_uct_conn_completion_t completion + = {.super = {.count = 1, .func = mca_btl_uct_endpoint_flush_complete}, .complete = false}; ucs_status_t ucs_status; - BTL_VERBOSE(("sending connection request to peer. context id: %d, type: %d, length: %" PRIsize_t, - request->context_id, request->type, request_length)); + BTL_VERBOSE( + ("sending connection request to peer. context id: %d, type: %d, length: %" PRIsize_t, + request->context_id, request->type, request_length)); OBJ_RETAIN(endpoint->conn_ep); /* need to drop the lock to avoid hold-and-wait */ - opal_mutex_unlock (&endpoint->ep_lock); + opal_mutex_unlock(&endpoint->ep_lock); do { MCA_BTL_UCT_CONTEXT_SERIALIZE(conn_tl_context, { - ucs_status = uct_ep_am_short (conn_ep->uct_ep, MCA_BTL_UCT_CONNECT_RDMA, request->type, request, - request_length); - }); + ucs_status = uct_ep_am_short(conn_ep->uct_ep, MCA_BTL_UCT_CONNECT_RDMA, request->type, + request, request_length); + }); if (OPAL_LIKELY(UCS_OK == ucs_status)) { break; } @@ -206,55 +223,57 @@ static int mca_btl_uct_endpoint_send_conn_req (mca_btl_uct_module_t *uct_btl, mc } /* some TLs (UD for example) need to be progressed to get resources */ - mca_btl_uct_context_progress (conn_tl_context); + mca_btl_uct_context_progress(conn_tl_context); } while (1); /* for now we just wait for the connection request to complete before continuing */ - ucs_status = uct_ep_flush (conn_ep->uct_ep, 0, &completion.super); + ucs_status = uct_ep_flush(conn_ep->uct_ep, 0, &completion.super); if (UCS_OK != ucs_status && UCS_INPROGRESS != ucs_status) { /* NTH: I don't know if this path is needed. For some networks we must use a completion. */ do { - ucs_status = uct_ep_flush (conn_ep->uct_ep, 0, NULL); - mca_btl_uct_context_progress (conn_tl_context); + ucs_status = uct_ep_flush(conn_ep->uct_ep, 0, NULL); + mca_btl_uct_context_progress(conn_tl_context); } while (UCS_INPROGRESS == ucs_status); } else { do { - mca_btl_uct_context_progress (conn_tl_context); + mca_btl_uct_context_progress(conn_tl_context); } while (!completion.complete); } - opal_mutex_lock (&endpoint->ep_lock); + opal_mutex_lock(&endpoint->ep_lock); OBJ_RELEASE(endpoint->conn_ep); return OPAL_SUCCESS; } -static int mca_btl_uct_endpoint_connect_endpoint (mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint, - mca_btl_uct_tl_t *tl, mca_btl_uct_device_context_t *tl_context, - mca_btl_uct_tl_endpoint_t *tl_endpoint, uint8_t *tl_data, - uint8_t *conn_tl_data, void *ep_addr) +static int mca_btl_uct_endpoint_connect_endpoint( + mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint, mca_btl_uct_tl_t *tl, + mca_btl_uct_device_context_t *tl_context, mca_btl_uct_tl_endpoint_t *tl_endpoint, + uint8_t *tl_data, uint8_t *conn_tl_data, void *ep_addr) { - size_t request_length = sizeof (mca_btl_uct_conn_req_t) + MCA_BTL_UCT_TL_ATTR(tl, tl_context->context_id).ep_addr_len; + size_t request_length = sizeof(mca_btl_uct_conn_req_t) + + MCA_BTL_UCT_TL_ATTR(tl, tl_context->context_id).ep_addr_len; mca_btl_uct_connection_ep_t *conn_ep = endpoint->conn_ep; mca_btl_uct_tl_t *conn_tl = uct_btl->conn_tl; mca_btl_uct_device_context_t *conn_tl_context = conn_tl->uct_dev_contexts[0]; - mca_btl_uct_conn_req_t *request = alloca (request_length); + mca_btl_uct_conn_req_t *request = alloca(request_length); uct_device_addr_t *device_addr = NULL; uct_iface_addr_t *iface_addr; ucs_status_t ucs_status; int rc; - assert (NULL != conn_tl); + assert(NULL != conn_tl); BTL_VERBOSE(("connecting endpoint to remote endpoint")); if (NULL == conn_ep) { BTL_VERBOSE(("creating a temporary endpoint for handling connections to %p", - opal_process_name_print (endpoint->ep_proc->proc_name))); + opal_process_name_print(endpoint->ep_proc->proc_name))); iface_addr = (uct_iface_addr_t *) conn_tl_data; - device_addr = (uct_device_addr_t *) ((uintptr_t) conn_tl_data + MCA_BTL_UCT_TL_ATTR(conn_tl, 0).iface_addr_len); + device_addr = (uct_device_addr_t *) ((uintptr_t) conn_tl_data + + MCA_BTL_UCT_TL_ATTR(conn_tl, 0).iface_addr_len); endpoint->conn_ep = conn_ep = OBJ_NEW(mca_btl_uct_connection_ep_t); if (OPAL_UNLIKELY(NULL == conn_ep)) { @@ -263,12 +282,14 @@ static int mca_btl_uct_endpoint_connect_endpoint (mca_btl_uct_module_t *uct_btl, /* create a temporary endpoint for setting up the rdma endpoint */ MCA_BTL_UCT_CONTEXT_SERIALIZE(conn_tl_context, { - ucs_status = mca_btl_uct_ep_create_connected_compat (conn_tl_context->uct_iface, device_addr, iface_addr, - &conn_ep->uct_ep); - }); + ucs_status = mca_btl_uct_ep_create_connected_compat(conn_tl_context->uct_iface, + device_addr, iface_addr, + &conn_ep->uct_ep); + }); if (UCS_OK != ucs_status) { - BTL_VERBOSE(("could not create an endpoint for forming connection to remote peer. code = %d", - ucs_status)); + BTL_VERBOSE( + ("could not create an endpoint for forming connection to remote peer. code = %d", + ucs_status)); return OPAL_ERROR; } } else { @@ -283,11 +304,11 @@ static int mca_btl_uct_endpoint_connect_endpoint (mca_btl_uct_module_t *uct_btl, if (NULL == tl_endpoint->uct_ep) { BTL_VERBOSE(("allocating endpoint for peer %s and sending connection data", - opal_process_name_print (endpoint->ep_proc->proc_name))); + opal_process_name_print(endpoint->ep_proc->proc_name))); MCA_BTL_UCT_CONTEXT_SERIALIZE(tl_context, { - ucs_status = mca_btl_uct_ep_create_compat (tl_context->uct_iface, &tl_endpoint->uct_ep); - }); + ucs_status = mca_btl_uct_ep_create_compat(tl_context->uct_iface, &tl_endpoint->uct_ep); + }); if (UCS_OK != ucs_status) { OBJ_RELEASE(endpoint->conn_ep); return OPAL_ERROR; @@ -295,46 +316,52 @@ static int mca_btl_uct_endpoint_connect_endpoint (mca_btl_uct_module_t *uct_btl, } if (ep_addr) { - BTL_VERBOSE(("using remote endpoint address to connect endpoint for tl %s, index %d. ep_addr = %p", - tl->uct_tl_name, tl_context->context_id, ep_addr)); + BTL_VERBOSE( + ("using remote endpoint address to connect endpoint for tl %s, index %d. ep_addr = %p", + tl->uct_tl_name, tl_context->context_id, ep_addr)); /* NTH: there is no need to lock the device context in this case */ - ucs_status = uct_ep_connect_to_ep (tl_endpoint->uct_ep, (uct_device_addr_t *) tl_data, ep_addr); + ucs_status = uct_ep_connect_to_ep(tl_endpoint->uct_ep, (uct_device_addr_t *) tl_data, + ep_addr); if (UCS_OK != ucs_status) { return OPAL_ERROR; } } /* fill in connection request */ - ucs_status = uct_ep_get_address (tl_endpoint->uct_ep, (uct_ep_addr_t *) request->ep_addr); + ucs_status = uct_ep_get_address(tl_endpoint->uct_ep, (uct_ep_addr_t *) request->ep_addr); if (UCS_OK != ucs_status) { /* this is a fatal a fatal error */ OBJ_RELEASE(endpoint->conn_ep); - uct_ep_destroy (tl_endpoint->uct_ep); + uct_ep_destroy(tl_endpoint->uct_ep); tl_endpoint->uct_ep = NULL; return OPAL_ERROR; } /* let the remote side know that the connection has been established and * wait for the message to be sent */ - rc = mca_btl_uct_endpoint_send_conn_req (uct_btl, endpoint, conn_tl_context, request, request_length); + rc = mca_btl_uct_endpoint_send_conn_req(uct_btl, endpoint, conn_tl_context, request, + request_length); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { OBJ_RELEASE(endpoint->conn_ep); - uct_ep_destroy (tl_endpoint->uct_ep); + uct_ep_destroy(tl_endpoint->uct_ep); tl_endpoint->uct_ep = NULL; return OPAL_ERROR; } - return (tl_endpoint->flags & MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY) ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE; + return (tl_endpoint->flags & MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY) ? OPAL_SUCCESS + : OPAL_ERR_OUT_OF_RESOURCE; } -int mca_btl_uct_endpoint_connect (mca_btl_uct_module_t *uct_btl, mca_btl_uct_endpoint_t *endpoint, int context_id, - void *ep_addr, int tl_index) +int mca_btl_uct_endpoint_connect(mca_btl_uct_module_t *uct_btl, mca_btl_uct_endpoint_t *endpoint, + int context_id, void *ep_addr, int tl_index) { mca_btl_uct_tl_endpoint_t *tl_endpoint = endpoint->uct_eps[context_id] + tl_index; - mca_btl_uct_tl_t *tl = (uct_btl->rdma_tl && tl_index == uct_btl->rdma_tl->tl_index) ? - uct_btl->rdma_tl : uct_btl->am_tl; - mca_btl_uct_device_context_t *tl_context = mca_btl_uct_module_get_tl_context_specific (uct_btl, tl, context_id); + mca_btl_uct_tl_t *tl = (uct_btl->rdma_tl && tl_index == uct_btl->rdma_tl->tl_index) + ? uct_btl->rdma_tl + : uct_btl->am_tl; + mca_btl_uct_device_context_t *tl_context + = mca_btl_uct_module_get_tl_context_specific(uct_btl, tl, context_id); uint8_t *rdma_tl_data = NULL, *conn_tl_data = NULL, *am_tl_data = NULL, *tl_data; mca_btl_uct_connection_ep_t *conn_ep = NULL; mca_btl_uct_modex_t *modex; @@ -343,85 +370,90 @@ int mca_btl_uct_endpoint_connect (mca_btl_uct_module_t *uct_btl, mca_btl_uct_end int rc; /* only two types of endpoints at this time */ - assert (tl_index < 2); + assert(tl_index < 2); if (OPAL_UNLIKELY(NULL == tl)) { return OPAL_ERR_UNREACH; } - BTL_VERBOSE(("checking endpoint %p with context id %d. cached uct ep: %p, ready: %d", (void *) endpoint, context_id, - (void *) tl_endpoint->uct_ep, !!(MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & tl_endpoint->flags))); + BTL_VERBOSE(("checking endpoint %p with context id %d. cached uct ep: %p, ready: %d", + (void *) endpoint, context_id, (void *) tl_endpoint->uct_ep, + !!(MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & tl_endpoint->flags))); - opal_mutex_lock (&endpoint->ep_lock); + opal_mutex_lock(&endpoint->ep_lock); if (MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & tl_endpoint->flags) { - opal_mutex_unlock (&endpoint->ep_lock); + opal_mutex_unlock(&endpoint->ep_lock); /* nothing more to do. someone else completed the connection */ return OPAL_SUCCESS; } /* dumpicate connection request. nothing to do until the endpoint data is received */ if (NULL != tl_endpoint->uct_ep && NULL == ep_addr) { - opal_mutex_unlock (&endpoint->ep_lock); + opal_mutex_unlock(&endpoint->ep_lock); return OPAL_ERR_OUT_OF_RESOURCE; } do { /* read the modex. this is done both to start the connection and to process endpoint data */ - OPAL_MODEX_RECV(rc, &mca_btl_uct_component.super.btl_version, - &endpoint->ep_proc->proc_name, (void **)&modex, &msg_size); + OPAL_MODEX_RECV(rc, &mca_btl_uct_component.super.btl_version, &endpoint->ep_proc->proc_name, + (void **) &modex, &msg_size); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error receiving modex")); break; } - BTL_VERBOSE(("received modex of size %lu for proc %s. module count %d", (unsigned long) msg_size, - OPAL_NAME_PRINT(endpoint->ep_proc->proc_name), modex->module_count)); + BTL_VERBOSE(("received modex of size %lu for proc %s. module count %d", + (unsigned long) msg_size, OPAL_NAME_PRINT(endpoint->ep_proc->proc_name), + modex->module_count)); modex_data = modex->data; /* look for matching transport in the modex */ - for (int i = 0 ; i < modex->module_count ; ++i) { + for (int i = 0; i < modex->module_count; ++i) { uint32_t modex_size = *((uint32_t *) modex_data); - BTL_VERBOSE(("found modex for md %s, searching for %s", modex_data + 4, uct_btl->md_name)); + BTL_VERBOSE( + ("found modex for md %s, searching for %s", modex_data + 4, uct_btl->md_name)); modex_data += 4; - if (0 != strcmp ((char *) modex_data, uct_btl->md_name)) { + if (0 != strcmp((char *) modex_data, uct_btl->md_name)) { /* modex belongs to a different module, skip it and continue */ modex_data += modex_size - 4; continue; } - modex_data += strlen ((char *) modex_data) + 1; + modex_data += strlen((char *) modex_data) + 1; - mca_btl_uct_process_modex (uct_btl, modex_data, &rdma_tl_data, &am_tl_data, &conn_tl_data); + mca_btl_uct_process_modex(uct_btl, modex_data, &rdma_tl_data, &am_tl_data, + &conn_tl_data); break; } tl_data = (tl == uct_btl->rdma_tl) ? rdma_tl_data : am_tl_data; if (NULL == tl_data) { - opal_mutex_unlock (&endpoint->ep_lock); + opal_mutex_unlock(&endpoint->ep_lock); return OPAL_ERR_UNREACH; } /* connect the endpoint */ - if (!mca_btl_uct_tl_requires_connection_tl (tl)) { - rc = mca_btl_uct_endpoint_connect_iface (uct_btl, tl, tl_context, tl_endpoint, tl_data); + if (!mca_btl_uct_tl_requires_connection_tl(tl)) { + rc = mca_btl_uct_endpoint_connect_iface(uct_btl, tl, tl_context, tl_endpoint, tl_data); } else { - rc = mca_btl_uct_endpoint_connect_endpoint (uct_btl, endpoint, tl, tl_context, tl_endpoint, - tl_data, conn_tl_data, ep_addr); + rc = mca_btl_uct_endpoint_connect_endpoint(uct_btl, endpoint, tl, tl_context, + tl_endpoint, tl_data, conn_tl_data, ep_addr); } } while (0); - /* to avoid a possible hold-and wait deadlock. destroy the endpoint after dropping the endpoint lock. */ + /* to avoid a possible hold-and wait deadlock. destroy the endpoint after dropping the endpoint + * lock. */ if (endpoint->conn_ep && 1 == endpoint->conn_ep->super.obj_reference_count) { conn_ep = endpoint->conn_ep; endpoint->conn_ep = NULL; } - opal_mutex_unlock (&endpoint->ep_lock); + opal_mutex_unlock(&endpoint->ep_lock); if (conn_ep) { OBJ_RELEASE(conn_ep); diff --git a/opal/mca/btl/uct/btl_uct_endpoint.h b/opal/mca/btl/uct/btl_uct_endpoint.h index 12d93b4192d..49d1b941457 100644 --- a/opal/mca/btl/uct/btl_uct_endpoint.h +++ b/opal/mca/btl/uct/btl_uct_endpoint.h @@ -24,22 +24,26 @@ #ifndef MCA_BTL_UCT_ENDPOINT_H #define MCA_BTL_UCT_ENDPOINT_H +#include "btl_uct.h" #include "opal/class/opal_list.h" #include "opal/util/event.h" -#include "btl_uct.h" BEGIN_C_DECLS -mca_btl_base_endpoint_t *mca_btl_uct_endpoint_create (opal_proc_t *proc); -int mca_btl_uct_endpoint_connect (mca_btl_uct_module_t *module, mca_btl_uct_endpoint_t *endpoint, int ep_index, void *ep_addr, int tl_index); +mca_btl_base_endpoint_t *mca_btl_uct_endpoint_create(opal_proc_t *proc); +int mca_btl_uct_endpoint_connect(mca_btl_uct_module_t *module, mca_btl_uct_endpoint_t *endpoint, + int ep_index, void *ep_addr, int tl_index); -static inline int mca_btl_uct_endpoint_test_am (mca_btl_uct_module_t *module, mca_btl_uct_endpoint_t *endpoint, - mca_btl_uct_device_context_t *context, uct_ep_h *ep_handle) +static inline int mca_btl_uct_endpoint_test_am(mca_btl_uct_module_t *module, + mca_btl_uct_endpoint_t *endpoint, + mca_btl_uct_device_context_t *context, + uct_ep_h *ep_handle) { int tl_index = module->am_tl->tl_index; int ep_index = context->context_id; - if (OPAL_LIKELY(MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & endpoint->uct_eps[ep_index][tl_index].flags)) { + if (OPAL_LIKELY(MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY + & endpoint->uct_eps[ep_index][tl_index].flags)) { *ep_handle = endpoint->uct_eps[ep_index][tl_index].uct_ep; return OPAL_SUCCESS; } @@ -60,37 +64,46 @@ static inline int mca_btl_uct_endpoint_test_am (mca_btl_uct_module_t *module, mc * @returns OPAL_ERR_RESOURCE_BUSY if the connection is underway * @returns OPAL_ERROR otherwise */ -static inline int mca_btl_uct_endpoint_check (mca_btl_uct_module_t *module, mca_btl_uct_endpoint_t *endpoint, - mca_btl_uct_device_context_t *context, uct_ep_h *ep_handle, - const int tl_index) +static inline int mca_btl_uct_endpoint_check(mca_btl_uct_module_t *module, + mca_btl_uct_endpoint_t *endpoint, + mca_btl_uct_device_context_t *context, + uct_ep_h *ep_handle, const int tl_index) { int ep_index = context->context_id; int rc; - if (OPAL_LIKELY(MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & endpoint->uct_eps[ep_index][tl_index].flags)) { + if (OPAL_LIKELY(MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY + & endpoint->uct_eps[ep_index][tl_index].flags)) { *ep_handle = endpoint->uct_eps[ep_index][tl_index].uct_ep; return OPAL_SUCCESS; } - rc = mca_btl_uct_endpoint_connect (module, endpoint, ep_index, NULL, tl_index); + rc = mca_btl_uct_endpoint_connect(module, endpoint, ep_index, NULL, tl_index); *ep_handle = endpoint->uct_eps[ep_index][tl_index].uct_ep; - BTL_VERBOSE(("mca_btl_uct_endpoint_connect returned %d. context id = %d, flags = 0x%x", rc, ep_index, - MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & endpoint->uct_eps[ep_index][tl_index].flags)); + BTL_VERBOSE( + ("mca_btl_uct_endpoint_connect returned %d. context id = %d, flags = 0x%x", rc, ep_index, + MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY & endpoint->uct_eps[ep_index][tl_index].flags)); return rc; } -static inline int mca_btl_uct_endpoint_check_rdma (mca_btl_uct_module_t *module, mca_btl_uct_endpoint_t *endpoint, - mca_btl_uct_device_context_t *context, uct_ep_h *ep_handle) +static inline int mca_btl_uct_endpoint_check_rdma(mca_btl_uct_module_t *module, + mca_btl_uct_endpoint_t *endpoint, + mca_btl_uct_device_context_t *context, + uct_ep_h *ep_handle) { - assert (NULL != module->rdma_tl); - return mca_btl_uct_endpoint_check (module, endpoint, context, ep_handle, module->rdma_tl->tl_index); + assert(NULL != module->rdma_tl); + return mca_btl_uct_endpoint_check(module, endpoint, context, ep_handle, + module->rdma_tl->tl_index); } -static inline int mca_btl_uct_endpoint_check_am (mca_btl_uct_module_t *module, mca_btl_uct_endpoint_t *endpoint, - mca_btl_uct_device_context_t *context, uct_ep_h *ep_handle) +static inline int mca_btl_uct_endpoint_check_am(mca_btl_uct_module_t *module, + mca_btl_uct_endpoint_t *endpoint, + mca_btl_uct_device_context_t *context, + uct_ep_h *ep_handle) { - assert (NULL != module->am_tl); - return mca_btl_uct_endpoint_check (module, endpoint, context, ep_handle, module->am_tl->tl_index); + assert(NULL != module->am_tl); + return mca_btl_uct_endpoint_check(module, endpoint, context, ep_handle, + module->am_tl->tl_index); } END_C_DECLS diff --git a/opal/mca/btl/uct/btl_uct_frag.c b/opal/mca/btl/uct/btl_uct_frag.c index 3e5622cac45..1153baea283 100644 --- a/opal/mca/btl/uct/btl_uct_frag.c +++ b/opal/mca/btl/uct/btl_uct_frag.c @@ -11,22 +11,25 @@ #include "btl_uct_frag.h" -static void mca_btl_uct_frag_completion (uct_completion_t *uct_comp, ucs_status_t status) +static void mca_btl_uct_frag_completion(uct_completion_t *uct_comp, ucs_status_t status) { - mca_btl_uct_uct_completion_t *comp = (mca_btl_uct_uct_completion_t *) ((uintptr_t) uct_comp - offsetof (mca_btl_uct_uct_completion_t, uct_comp)); + mca_btl_uct_uct_completion_t *comp = (mca_btl_uct_uct_completion_t + *) ((uintptr_t) uct_comp + - offsetof(mca_btl_uct_uct_completion_t, + uct_comp)); BTL_VERBOSE(("frag operation complete. frag = %p. status = %d", (void *) comp->frag, status)); comp->status = status; - opal_fifo_push (&comp->dev_context->completion_fifo, &comp->super.super); + opal_fifo_push(&comp->dev_context->completion_fifo, &comp->super.super); } -static void mca_btl_uct_base_frag_constructor (mca_btl_uct_base_frag_t *frag) +static void mca_btl_uct_base_frag_constructor(mca_btl_uct_base_frag_t *frag) { mca_btl_uct_reg_t *reg = (mca_btl_uct_reg_t *) frag->base.super.registration; /* zero everything out */ - memset ((char *) frag + sizeof (frag->base), 0, sizeof (*frag) - sizeof (frag->base)); + memset((char *) frag + sizeof(frag->base), 0, sizeof(*frag) - sizeof(frag->base)); OBJ_CONSTRUCT(&frag->comp, mca_btl_uct_uct_completion_t); @@ -46,7 +49,7 @@ static void mca_btl_uct_base_frag_constructor (mca_btl_uct_base_frag_t *frag) } } -static void mca_btl_uct_base_frag_destructor (mca_btl_uct_base_frag_t *frag) +static void mca_btl_uct_base_frag_destructor(mca_btl_uct_base_frag_t *frag) { OBJ_DESTRUCT(&frag->comp); } diff --git a/opal/mca/btl/uct/btl_uct_frag.h b/opal/mca/btl/uct/btl_uct_frag.h index 8aa8789d0e3..7907774cf42 100644 --- a/opal/mca/btl/uct/btl_uct_frag.h +++ b/opal/mca/btl/uct/btl_uct_frag.h @@ -10,14 +10,15 @@ */ #if !defined(MCA_BTL_UCT_FRAG_H) -#define MCA_BTL_UCT_FRAG_H +# define MCA_BTL_UCT_FRAG_H -#include "btl_uct.h" +# include "btl_uct.h" -static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc (mca_btl_uct_module_t *uct_btl, opal_free_list_t *fl, - mca_btl_base_endpoint_t *endpoint) +static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc(mca_btl_uct_module_t *uct_btl, + opal_free_list_t *fl, + mca_btl_base_endpoint_t *endpoint) { - mca_btl_uct_base_frag_t *frag = (mca_btl_uct_base_frag_t *) opal_free_list_get (fl); + mca_btl_uct_base_frag_t *frag = (mca_btl_uct_base_frag_t *) opal_free_list_get(fl); if (OPAL_LIKELY(NULL != frag)) { frag->free_list = fl; frag->endpoint = endpoint; @@ -27,12 +28,13 @@ static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc (mca_btl_uct_modul return frag; } -static inline void mca_btl_uct_frag_return (mca_btl_uct_base_frag_t *frag) +static inline void mca_btl_uct_frag_return(mca_btl_uct_base_frag_t *frag) { - opal_free_list_return (frag->free_list, &frag->base.super); + opal_free_list_return(frag->free_list, &frag->base.super); } -static inline void mca_btl_uct_frag_complete (mca_btl_uct_base_frag_t *frag, int rc) { +static inline void mca_btl_uct_frag_complete(mca_btl_uct_base_frag_t *frag, int rc) +{ mca_btl_uct_module_t *uct_btl = frag->btl; /* call callback if specified */ @@ -41,23 +43,26 @@ static inline void mca_btl_uct_frag_complete (mca_btl_uct_base_frag_t *frag, int } if (OPAL_LIKELY(frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { - mca_btl_uct_frag_return (frag); + mca_btl_uct_frag_return(frag); } } -static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc_short (mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint) +static inline mca_btl_uct_base_frag_t * +mca_btl_uct_frag_alloc_short(mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint) { - return mca_btl_uct_frag_alloc (uct_btl, &uct_btl->short_frags, endpoint); + return mca_btl_uct_frag_alloc(uct_btl, &uct_btl->short_frags, endpoint); } -static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc_eager (mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint) +static inline mca_btl_uct_base_frag_t * +mca_btl_uct_frag_alloc_eager(mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint) { - return mca_btl_uct_frag_alloc (uct_btl, &uct_btl->eager_frags, endpoint); + return mca_btl_uct_frag_alloc(uct_btl, &uct_btl->eager_frags, endpoint); } -static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc_max (mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint) +static inline mca_btl_uct_base_frag_t *mca_btl_uct_frag_alloc_max(mca_btl_uct_module_t *uct_btl, + mca_btl_base_endpoint_t *endpoint) { - return mca_btl_uct_frag_alloc (uct_btl, &uct_btl->max_frags, endpoint); + return mca_btl_uct_frag_alloc(uct_btl, &uct_btl->max_frags, endpoint); } #endif /* !defined(MCA_BTL_UCT_FRAG_H) */ diff --git a/opal/mca/btl/uct/btl_uct_module.c b/opal/mca/btl/uct/btl_uct_module.c index 53d1df3302f..6e80bab65f3 100644 --- a/opal/mca/btl/uct/btl_uct_module.c +++ b/opal/mca/btl/uct/btl_uct_module.c @@ -21,34 +21,37 @@ */ #include "opal_config.h" -#include #include "opal/class/opal_bitmap.h" -#include "opal/mca/btl/btl.h" #include "opal/datatype/opal_convertor.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" #include "opal/mca/mpool/mpool.h" +#include #include "btl_uct.h" -#include "btl_uct_endpoint.h" #include "btl_uct_am.h" +#include "btl_uct_endpoint.h" -struct mca_btl_base_endpoint_t *mca_btl_uct_get_ep (struct mca_btl_base_module_t *module, opal_proc_t *proc) +struct mca_btl_base_endpoint_t *mca_btl_uct_get_ep(struct mca_btl_base_module_t *module, + opal_proc_t *proc) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) module; mca_btl_base_endpoint_t *ep; int rc; - opal_mutex_lock (&uct_module->endpoint_lock); + opal_mutex_lock(&uct_module->endpoint_lock); do { - rc = opal_hash_table_get_value_uint64 (&uct_module->id_to_endpoint, (intptr_t) proc, (void **) &ep); + rc = opal_hash_table_get_value_uint64(&uct_module->id_to_endpoint, (intptr_t) proc, + (void **) &ep); if (OPAL_SUCCESS == rc) { - BTL_VERBOSE(("returning existing endpoint for proc %s", OPAL_NAME_PRINT(proc->proc_name))); + BTL_VERBOSE( + ("returning existing endpoint for proc %s", OPAL_NAME_PRINT(proc->proc_name))); break; } /* Create and Init endpoints */ - ep = mca_btl_uct_endpoint_create (proc); + ep = mca_btl_uct_endpoint_create(proc); if (OPAL_UNLIKELY(NULL == ep)) { BTL_ERROR(("btl/uct error initializing endpoint")); break; @@ -57,18 +60,17 @@ struct mca_btl_base_endpoint_t *mca_btl_uct_get_ep (struct mca_btl_base_module_t BTL_VERBOSE(("endpoint initialized. new endpoint: %p", (void *) ep)); /* add this endpoint to the connection lookup table */ - (void) opal_hash_table_set_value_uint64 (&uct_module->id_to_endpoint, (intptr_t) proc, ep); + (void) opal_hash_table_set_value_uint64(&uct_module->id_to_endpoint, (intptr_t) proc, ep); } while (0); - opal_mutex_unlock (&uct_module->endpoint_lock); + opal_mutex_unlock(&uct_module->endpoint_lock); return ep; } -static int mca_btl_uct_add_procs (mca_btl_base_module_t *btl, - size_t nprocs, opal_proc_t **opal_procs, - mca_btl_base_endpoint_t **peers, - opal_bitmap_t *reachable) +static int mca_btl_uct_add_procs(mca_btl_base_module_t *btl, size_t nprocs, + opal_proc_t **opal_procs, mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) btl; int rc; @@ -79,35 +81,35 @@ static int mca_btl_uct_add_procs (mca_btl_base_module_t *btl, /* NTH: might want to vary this size based off the universe size (if * one exists). the table is only used for connection lookup and * endpoint removal. */ - rc = opal_hash_table_init (&uct_module->id_to_endpoint, 512); + rc = opal_hash_table_init(&uct_module->id_to_endpoint, 512); if (OPAL_SUCCESS != rc) { BTL_ERROR(("error initializing the endpoint hash. rc = %d", rc)); return rc; } if (am_tl) { - rc = opal_free_list_init (&uct_module->short_frags, sizeof (mca_btl_uct_base_frag_t), - opal_cache_line_size, OBJ_CLASS(mca_btl_uct_base_frag_t), - MCA_BTL_UCT_TL_ATTR(am_tl, 0).cap.am.max_short, opal_cache_line_size, - 0, 1024, 64, NULL, 0, NULL, NULL, NULL); - - rc = opal_free_list_init (&uct_module->eager_frags, sizeof (mca_btl_uct_base_frag_t), - opal_cache_line_size, OBJ_CLASS(mca_btl_uct_base_frag_t), - btl->btl_eager_limit, opal_cache_line_size, - 0, 1024, 64, NULL, 0, uct_module->rcache, NULL, NULL); - - rc = opal_free_list_init (&uct_module->max_frags, sizeof (mca_btl_uct_base_frag_t), - opal_cache_line_size, OBJ_CLASS(mca_btl_uct_base_frag_t), - btl->btl_max_send_size, opal_cache_line_size, 0, 128, 8, - NULL, 0, uct_module->rcache, NULL, NULL); + rc = opal_free_list_init(&uct_module->short_frags, sizeof(mca_btl_uct_base_frag_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_uct_base_frag_t), + MCA_BTL_UCT_TL_ATTR(am_tl, 0).cap.am.max_short, + opal_cache_line_size, 0, 1024, 64, NULL, 0, NULL, NULL, NULL); + + rc = opal_free_list_init(&uct_module->eager_frags, sizeof(mca_btl_uct_base_frag_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_uct_base_frag_t), + btl->btl_eager_limit, opal_cache_line_size, 0, 1024, 64, NULL, + 0, uct_module->rcache, NULL, NULL); + + rc = opal_free_list_init(&uct_module->max_frags, sizeof(mca_btl_uct_base_frag_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_uct_base_frag_t), + btl->btl_max_send_size, opal_cache_line_size, 0, 128, 8, NULL, + 0, uct_module->rcache, NULL, NULL); } uct_module->initialized = true; } - for (size_t i = 0 ; i < nprocs ; ++i) { + for (size_t i = 0; i < nprocs; ++i) { /* all endpoints are reachable for uct */ - peers[i] = mca_btl_uct_get_ep (btl, opal_procs[i]); + peers[i] = mca_btl_uct_get_ep(btl, opal_procs[i]); if (OPAL_UNLIKELY(NULL == peers[i])) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -118,31 +120,32 @@ static int mca_btl_uct_add_procs (mca_btl_base_module_t *btl, return OPAL_SUCCESS; } -static int mca_btl_uct_del_procs (mca_btl_base_module_t *btl, size_t nprocs, - opal_proc_t **procs, mca_btl_base_endpoint_t **peers) +static int mca_btl_uct_del_procs(mca_btl_base_module_t *btl, size_t nprocs, opal_proc_t **procs, + mca_btl_base_endpoint_t **peers) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) btl; mca_btl_base_endpoint_t *ep; int rc; - for (size_t i = 0 ; i < nprocs ; ++i) { + for (size_t i = 0; i < nprocs; ++i) { if (NULL == procs[i]) { continue; } - rc = opal_hash_table_get_value_uint64 (&uct_module->id_to_endpoint, (intptr_t) procs[i], (void **) &ep); + rc = opal_hash_table_get_value_uint64(&uct_module->id_to_endpoint, (intptr_t) procs[i], + (void **) &ep); if (OPAL_SUCCESS != rc) { continue; } - (void) opal_hash_table_remove_value_uint64 (&uct_module->id_to_endpoint, (intptr_t) procs[i]); + (void) opal_hash_table_remove_value_uint64(&uct_module->id_to_endpoint, + (intptr_t) procs[i]); OBJ_RELEASE(ep); } return OPAL_SUCCESS; } - /** * @brief Register a memory region for put/get/atomic operations. * @@ -162,16 +165,17 @@ static int mca_btl_uct_del_procs (mca_btl_base_module_t *btl, size_t nprocs, * as they may use limited system/NIC resources. */ static struct mca_btl_base_registration_handle_t * -mca_btl_uct_register_mem (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags) +mca_btl_uct_register_mem(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, void *base, size_t size, + uint32_t flags) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) btl; mca_btl_uct_reg_t *reg; int access_flags = flags & MCA_BTL_REG_FLAG_ACCESS_ANY; int rc; - rc = uct_module->rcache->rcache_register (uct_module->rcache, base, size, 0, access_flags, - (mca_rcache_base_registration_t **) ®); + rc = uct_module->rcache->rcache_register(uct_module->rcache, base, size, 0, access_flags, + (mca_rcache_base_registration_t **) ®); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return NULL; } @@ -190,18 +194,20 @@ mca_btl_uct_register_mem (struct mca_btl_base_module_t *btl, struct mca_btl_base * after it is deregistered. It is erroneous to specify a memory handle associated with * a remote node. */ -static int mca_btl_uct_deregister_mem (mca_btl_base_module_t *btl, mca_btl_base_registration_handle_t *handle) +static int mca_btl_uct_deregister_mem(mca_btl_base_module_t *btl, + mca_btl_base_registration_handle_t *handle) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) btl; - mca_btl_uct_reg_t *reg = - (mca_btl_uct_reg_t *)((intptr_t) handle - offsetof (mca_btl_uct_reg_t, handle)); + mca_btl_uct_reg_t *reg = (mca_btl_uct_reg_t *) ((intptr_t) handle + - offsetof(mca_btl_uct_reg_t, handle)); - (void) uct_module->rcache->rcache_deregister (uct_module->rcache, ®->base); + (void) uct_module->rcache->rcache_deregister(uct_module->rcache, ®->base); return OPAL_SUCCESS; } -int mca_btl_uct_reg_mem (void *reg_data, void *base, size_t size, mca_rcache_base_registration_t *reg) +int mca_btl_uct_reg_mem(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) reg_data; mca_btl_uct_reg_t *uct_reg = (mca_btl_uct_reg_t *) reg; @@ -225,19 +231,22 @@ int mca_btl_uct_reg_mem (void *reg_data, void *base, size_t size, mca_rcache_bas uct_flags = UCT_MD_MEM_ACCESS_ALL; } - ucs_status = uct_md_mem_reg (uct_module->md->uct_md, base, size, uct_flags, &uct_reg->uct_memh); + ucs_status = uct_md_mem_reg(uct_module->md->uct_md, base, size, uct_flags, &uct_reg->uct_memh); if (UCS_OK != ucs_status) { BTL_VERBOSE(("Error registering memory with UCT. code: %d", ucs_status)); return OPAL_ERR_OUT_OF_RESOURCE; } - if (reg->access_flags & (MCA_BTL_REG_FLAG_REMOTE_READ | MCA_BTL_REG_FLAG_REMOTE_WRITE | MCA_BTL_REG_FLAG_REMOTE_ATOMIC)) { + if (reg->access_flags + & (MCA_BTL_REG_FLAG_REMOTE_READ | MCA_BTL_REG_FLAG_REMOTE_WRITE + | MCA_BTL_REG_FLAG_REMOTE_ATOMIC)) { /* requested registration may be used by a remote process so go ahead and pack * the registration handle */ - ucs_status = uct_md_mkey_pack (uct_module->md->uct_md, uct_reg->uct_memh, uct_reg->handle.packed_handle); + ucs_status = uct_md_mkey_pack(uct_module->md->uct_md, uct_reg->uct_memh, + uct_reg->handle.packed_handle); if (OPAL_UNLIKELY(UCS_OK != ucs_status)) { BTL_VERBOSE(("Could not pack remote key. code: %d", ucs_status)); - uct_md_mem_dereg (uct_module->md->uct_md, uct_reg->uct_memh); + uct_md_mem_dereg(uct_module->md->uct_md, uct_reg->uct_memh); return OPAL_ERR_OUT_OF_RESOURCE; } } @@ -245,29 +254,28 @@ int mca_btl_uct_reg_mem (void *reg_data, void *base, size_t size, mca_rcache_bas return OPAL_SUCCESS; } -int mca_btl_uct_dereg_mem (void *reg_data, mca_rcache_base_registration_t *reg) +int mca_btl_uct_dereg_mem(void *reg_data, mca_rcache_base_registration_t *reg) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) reg_data; mca_btl_uct_reg_t *uct_reg = (mca_btl_uct_reg_t *) reg; - uct_md_mem_dereg (uct_module->md->uct_md, uct_reg->uct_memh); + uct_md_mem_dereg(uct_module->md->uct_md, uct_reg->uct_memh); return OPAL_SUCCESS; } - /* * Cleanup/release module resources. */ -int mca_btl_uct_finalize (mca_btl_base_module_t* btl) +int mca_btl_uct_finalize(mca_btl_base_module_t *btl) { mca_btl_uct_module_t *uct_module = (mca_btl_uct_module_t *) btl; mca_btl_uct_endpoint_t *endpoint; uint64_t key; /* clean up any leftover endpoints */ - OPAL_HASH_TABLE_FOREACH(key, uint64, endpoint, &uct_module->id_to_endpoint) { + OPAL_HASH_TABLE_FOREACH (key, uint64, endpoint, &uct_module->id_to_endpoint) { OBJ_RELEASE(endpoint); } OBJ_DESTRUCT(&uct_module->id_to_endpoint); @@ -279,7 +287,7 @@ int mca_btl_uct_finalize (mca_btl_base_module_t* btl) OBJ_DESTRUCT(&uct_module->pending_connection_reqs); if (uct_module->rcache) { - mca_rcache_base_module_destroy (uct_module->rcache); + mca_rcache_base_module_destroy(uct_module->rcache); } if (NULL != uct_module->am_tl) { @@ -294,12 +302,12 @@ int mca_btl_uct_finalize (mca_btl_base_module_t* btl) OBJ_RELEASE(uct_module->rdma_tl); } - ucs_async_context_destroy (uct_module->ucs_async); + ucs_async_context_destroy(uct_module->ucs_async); OBJ_DESTRUCT(&uct_module->endpoint_lock); - free (uct_module->md_name); - free (uct_module); + free(uct_module->md_name); + free(uct_module); return OPAL_SUCCESS; } @@ -308,58 +316,58 @@ mca_btl_uct_module_t mca_btl_uct_module_template = { .super = { /* initialize functions. this btl only support RDMA and atomics * for now so it does not provide prepare_src, alloc, free, or send */ - .btl_component = &mca_btl_uct_component.super, - .btl_add_procs = mca_btl_uct_add_procs, - .btl_del_procs = mca_btl_uct_del_procs, - .btl_finalize = mca_btl_uct_finalize, - .btl_put = mca_btl_uct_put, - .btl_get = mca_btl_uct_get, - .btl_register_mem = mca_btl_uct_register_mem, + .btl_component = &mca_btl_uct_component.super, + .btl_add_procs = mca_btl_uct_add_procs, + .btl_del_procs = mca_btl_uct_del_procs, + .btl_finalize = mca_btl_uct_finalize, + .btl_put = mca_btl_uct_put, + .btl_get = mca_btl_uct_get, + .btl_register_mem = mca_btl_uct_register_mem, .btl_deregister_mem = mca_btl_uct_deregister_mem, - .btl_atomic_op = mca_btl_uct_aop, - .btl_atomic_fop = mca_btl_uct_afop, - .btl_atomic_cswap = mca_btl_uct_acswap, - .btl_flush = mca_btl_uct_flush, + .btl_atomic_op = mca_btl_uct_aop, + .btl_atomic_fop = mca_btl_uct_afop, + .btl_atomic_cswap = mca_btl_uct_acswap, + .btl_flush = mca_btl_uct_flush, - .btl_sendi = mca_btl_uct_sendi, - .btl_prepare_src = mca_btl_uct_prepare_src, - .btl_send = mca_btl_uct_send, - .btl_alloc = mca_btl_uct_alloc, - .btl_free = mca_btl_uct_free, + .btl_sendi = mca_btl_uct_sendi, + .btl_prepare_src = mca_btl_uct_prepare_src, + .btl_send = mca_btl_uct_send, + .btl_alloc = mca_btl_uct_alloc, + .btl_free = mca_btl_uct_free, /* set the default flags for this btl. uct provides us with rdma and both * fetching and non-fetching atomics (though limited to add and cswap) */ - .btl_flags = MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_ATOMIC_FOPS | MCA_BTL_FLAGS_ATOMIC_OPS, - .btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_ADD | MCA_BTL_ATOMIC_SUPPORTS_CSWAP | - MCA_BTL_ATOMIC_SUPPORTS_SWAP | MCA_BTL_ATOMIC_SUPPORTS_32BIT, + .btl_flags = MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_ATOMIC_FOPS | MCA_BTL_FLAGS_ATOMIC_OPS, + .btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_ADD | MCA_BTL_ATOMIC_SUPPORTS_CSWAP + | MCA_BTL_ATOMIC_SUPPORTS_SWAP | MCA_BTL_ATOMIC_SUPPORTS_32BIT, /* set the default limits on put and get */ - .btl_put_limit = 1 << 23, - .btl_put_alignment = 0, - .btl_get_limit = 1 << 23, - .btl_get_alignment = 0, + .btl_put_limit = 1 << 23, + .btl_put_alignment = 0, + .btl_get_limit = 1 << 23, + .btl_get_alignment = 0, .btl_rndv_eager_limit = 8192, .btl_rdma_pipeline_frag_size = 4 * 1024 * 1024, .btl_rdma_pipeline_send_length = 8192, - .btl_eager_limit = 8192, - .btl_max_send_size = 65536, - } -}; + .btl_eager_limit = 8192, + .btl_max_send_size = 65536, + }}; OBJ_CLASS_INSTANCE(mca_btl_uct_reg_t, opal_free_list_item_t, NULL, NULL); -static void mca_btl_uct_md_construct (mca_btl_uct_md_t *md) +static void mca_btl_uct_md_construct(mca_btl_uct_md_t *md) { md->uct_md = NULL; } -static void mca_btl_uct_md_destruct (mca_btl_uct_md_t *md) +static void mca_btl_uct_md_destruct(mca_btl_uct_md_t *md) { if (md->uct_md) { - uct_md_close (md->uct_md); + uct_md_close(md->uct_md); md->uct_md = NULL; } } -OBJ_CLASS_INSTANCE(mca_btl_uct_md_t, opal_object_t, mca_btl_uct_md_construct, mca_btl_uct_md_destruct); +OBJ_CLASS_INSTANCE(mca_btl_uct_md_t, opal_object_t, mca_btl_uct_md_construct, + mca_btl_uct_md_destruct); diff --git a/opal/mca/btl/uct/btl_uct_rdma.c b/opal/mca/btl/uct/btl_uct_rdma.c index 9ee9530f260..9b8bc2cb519 100644 --- a/opal/mca/btl/uct/btl_uct_rdma.c +++ b/opal/mca/btl/uct/btl_uct_rdma.c @@ -11,33 +11,35 @@ #include "btl_uct_device_context.h" -void mca_btl_uct_uct_completion (uct_completion_t *uct_comp, ucs_status_t status) +void mca_btl_uct_uct_completion(uct_completion_t *uct_comp, ucs_status_t status) { - mca_btl_uct_uct_completion_t *comp = (mca_btl_uct_uct_completion_t *) ((uintptr_t) uct_comp - offsetof (mca_btl_uct_uct_completion_t, uct_comp)); + mca_btl_uct_uct_completion_t *comp = (mca_btl_uct_uct_completion_t + *) ((uintptr_t) uct_comp + - offsetof(mca_btl_uct_uct_completion_t, + uct_comp)); BTL_VERBOSE(("network operation complete. status = %d", status)); comp->status = status; - opal_fifo_push (&comp->dev_context->completion_fifo, &comp->super.super); + opal_fifo_push(&comp->dev_context->completion_fifo, &comp->super.super); } - -static void mca_btl_uct_uct_completion_construct (mca_btl_uct_uct_completion_t *comp) +static void mca_btl_uct_uct_completion_construct(mca_btl_uct_uct_completion_t *comp) { comp->frag = NULL; comp->uct_comp.func = mca_btl_uct_uct_completion; } -OBJ_CLASS_INSTANCE(mca_btl_uct_uct_completion_t, opal_free_list_item_t, mca_btl_uct_uct_completion_construct, NULL); - +OBJ_CLASS_INSTANCE(mca_btl_uct_uct_completion_t, opal_free_list_item_t, + mca_btl_uct_uct_completion_construct, NULL); -mca_btl_uct_uct_completion_t * -mca_btl_uct_uct_completion_alloc (mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint, - void *local_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_uct_device_context_t *dev_context, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +mca_btl_uct_uct_completion_t *mca_btl_uct_uct_completion_alloc( + mca_btl_uct_module_t *uct_btl, mca_btl_base_endpoint_t *endpoint, void *local_address, + mca_btl_base_registration_handle_t *local_handle, mca_btl_uct_device_context_t *dev_context, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { - mca_btl_uct_uct_completion_t *comp = (mca_btl_uct_uct_completion_t *) opal_free_list_get (&dev_context->rdma_completions); + mca_btl_uct_uct_completion_t *comp = (mca_btl_uct_uct_completion_t *) opal_free_list_get( + &dev_context->rdma_completions); if (OPAL_LIKELY(NULL != comp)) { comp->uct_comp.count = 1; comp->btl = &uct_btl->super; @@ -53,86 +55,93 @@ mca_btl_uct_uct_completion_alloc (mca_btl_uct_module_t *uct_btl, mca_btl_base_en return comp; } -void mca_btl_uct_uct_completion_release (mca_btl_uct_uct_completion_t *comp) +void mca_btl_uct_uct_completion_release(mca_btl_uct_uct_completion_t *comp) { if (comp) { - opal_free_list_return (&comp->dev_context->rdma_completions, &comp->super); + opal_free_list_return(&comp->dev_context->rdma_completions, &comp->super); } } -static void mca_btl_uct_get_unpack (void *arg, const void *data, size_t length) +static void mca_btl_uct_get_unpack(void *arg, const void *data, size_t length) { - memcpy (arg, data, length); + memcpy(arg, data, length); } -int mca_btl_uct_get (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_uct_get(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context (uct_btl); + mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context(uct_btl); mca_btl_uct_uct_completion_t *comp = NULL; ucs_status_t ucs_status; uct_rkey_bundle_t rkey; uct_ep_h ep_handle; int rc; - BTL_VERBOSE(("performing get operation. local address: %p, length: %lu", local_address, (unsigned long) size)); + BTL_VERBOSE(("performing get operation. local address: %p, length: %lu", local_address, + (unsigned long) size)); if (cbfunc) { - comp = mca_btl_uct_uct_completion_alloc (uct_btl, endpoint, local_address, local_handle, context, - cbfunc, cbcontext, cbdata); + comp = mca_btl_uct_uct_completion_alloc(uct_btl, endpoint, local_address, local_handle, + context, cbfunc, cbcontext, cbdata); if (OPAL_UNLIKELY(NULL == comp)) { BTL_VERBOSE(("culd not allocate completion structure")); return OPAL_ERR_OUT_OF_RESOURCE; } } - rc = mca_btl_uct_get_rkey (uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); + rc = mca_btl_uct_get_rkey(uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_VERBOSE(("mca_btl_uct_get_rkey returned %d", rc)); - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); return rc; } - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); if (size <= MCA_BTL_UCT_TL_ATTR(uct_btl->rdma_tl, context->context_id).cap.get.max_bcopy) { - ucs_status = uct_ep_get_bcopy (ep_handle, mca_btl_uct_get_unpack, local_address, size, remote_address, - rkey.rkey, &comp->uct_comp); + ucs_status = uct_ep_get_bcopy(ep_handle, mca_btl_uct_get_unpack, local_address, size, + remote_address, rkey.rkey, &comp->uct_comp); } else { - uct_iov_t iov = {.buffer = local_address, .length = size, .stride = 0, .count = 1, + uct_iov_t iov = {.buffer = local_address, + .length = size, + .stride = 0, + .count = 1, .memh = MCA_BTL_UCT_REG_REMOTE_TO_LOCAL(local_handle)->uct_memh}; - ucs_status = uct_ep_get_zcopy (ep_handle, &iov, 1, remote_address, rkey.rkey, &comp->uct_comp); + ucs_status = uct_ep_get_zcopy(ep_handle, &iov, 1, remote_address, rkey.rkey, + &comp->uct_comp); } /* go ahead and progress the worker while we have the lock (if we are not in an AM callback) */ if (!context->in_am_callback) { - (void) uct_worker_progress (context->uct_worker); + (void) uct_worker_progress(context->uct_worker); } - mca_btl_uct_context_unlock (context); + mca_btl_uct_context_unlock(context); if (!context->in_am_callback) { - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); } if (UCS_OK == ucs_status && cbfunc) { /* if UCS_OK is returned the callback will never fire so we have to make the callback * ourselves */ - cbfunc (btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS); + cbfunc(btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS); } if (UCS_INPROGRESS == ucs_status) { ucs_status = UCS_OK; } else { - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); } BTL_VERBOSE(("get issued. status = %d", ucs_status)); - mca_btl_uct_rkey_release (uct_btl, &rkey); + mca_btl_uct_rkey_release(uct_btl, &rkey); return OPAL_LIKELY(UCS_OK == ucs_status) ? OPAL_SUCCESS : OPAL_ERR_RESOURCE_BUSY; } @@ -144,21 +153,23 @@ struct mca_btl_uct_put_pack_args_t { typedef struct mca_btl_uct_put_pack_args_t mca_btl_uct_put_pack_args_t; -static size_t mca_btl_uct_put_pack (void *dest, void *arg) +static size_t mca_btl_uct_put_pack(void *dest, void *arg) { mca_btl_uct_put_pack_args_t *args = (mca_btl_uct_put_pack_args_t *) arg; - memcpy (dest, args->local_address, args->size); + memcpy(dest, args->local_address, args->size); return args->size; } -int mca_btl_uct_put (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_uct_put(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context (uct_btl); + mca_btl_uct_device_context_t *context = mca_btl_uct_module_get_rdma_context(uct_btl); mca_btl_uct_uct_completion_t *comp = NULL; ucs_status_t ucs_status; uct_rkey_bundle_t rkey; @@ -167,82 +178,90 @@ int mca_btl_uct_put (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoi bool use_bcopy = false; int rc; - BTL_VERBOSE(("performing put operation. local address: %p, length: %lu", local_address, (unsigned long) size)); + BTL_VERBOSE(("performing put operation. local address: %p, length: %lu", local_address, + (unsigned long) size)); if (size > uct_btl->super.btl_put_local_registration_threshold && cbfunc) { - comp = mca_btl_uct_uct_completion_alloc (uct_btl, endpoint, local_address, local_handle, context, - cbfunc, cbcontext, cbdata); + comp = mca_btl_uct_uct_completion_alloc(uct_btl, endpoint, local_address, local_handle, + context, cbfunc, cbcontext, cbdata); if (OPAL_UNLIKELY(NULL == comp)) { return OPAL_ERR_OUT_OF_RESOURCE; } } - rc = mca_btl_uct_get_rkey (uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); + rc = mca_btl_uct_get_rkey(uct_btl, context, endpoint, remote_handle, &rkey, &ep_handle); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); return rc; } - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); /* determine what UCT prototol should be used */ if (size <= uct_btl->super.btl_put_local_registration_threshold) { - use_short = size <= MCA_BTL_UCT_TL_ATTR(uct_btl->rdma_tl, context->context_id).cap.put.max_short; + use_short = size + <= MCA_BTL_UCT_TL_ATTR(uct_btl->rdma_tl, context->context_id).cap.put.max_short; use_bcopy = !use_short; } do { if (use_short) { - ucs_status = uct_ep_put_short (ep_handle, local_address, size, remote_address, rkey.rkey); + ucs_status = uct_ep_put_short(ep_handle, local_address, size, remote_address, + rkey.rkey); } else if (use_bcopy) { - ssize_t tmp = uct_ep_put_bcopy (ep_handle, mca_btl_uct_put_pack, - &(mca_btl_uct_put_pack_args_t) {.local_address = local_address, - .size = size}, - remote_address, rkey.rkey); + ssize_t tmp = uct_ep_put_bcopy( + ep_handle, mca_btl_uct_put_pack, + &(mca_btl_uct_put_pack_args_t){.local_address = local_address, .size = size}, + remote_address, rkey.rkey); ucs_status = (tmp == (ssize_t) size) ? UCS_OK : UCS_ERR_NO_RESOURCE; } else { - uct_iov_t iov = {.buffer = local_address, .length = size, .stride = 0, .count = 1, - .memh = MCA_BTL_UCT_REG_REMOTE_TO_LOCAL(local_handle)->uct_memh}; - - ucs_status = uct_ep_put_zcopy (ep_handle, &iov, 1, remote_address, rkey.rkey, &comp->uct_comp); + uct_iov_t iov = {.buffer = local_address, + .length = size, + .stride = 0, + .count = 1, + .memh = MCA_BTL_UCT_REG_REMOTE_TO_LOCAL(local_handle)->uct_memh}; + + ucs_status = uct_ep_put_zcopy(ep_handle, &iov, 1, remote_address, rkey.rkey, + &comp->uct_comp); } /* go ahead and progress the worker while we have the lock */ if (UCS_ERR_NO_RESOURCE != ucs_status || context->in_am_callback) { if (!context->in_am_callback) { - (void) uct_worker_progress (context->uct_worker); + (void) uct_worker_progress(context->uct_worker); } break; } /* wait for something to complete */ - while (!uct_worker_progress (context->uct_worker)); + while (!uct_worker_progress(context->uct_worker)) + ; } while (1); - mca_btl_uct_context_unlock (context); + mca_btl_uct_context_unlock(context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); if (UCS_OK == ucs_status && cbfunc) { /* if UCS_OK is returned the callback will never fire so we have to make the callback * ourselves. this callback is possibly being made before the data is visible to the * remote process. */ - cbfunc (btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS); + cbfunc(btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS); } if (UCS_INPROGRESS == ucs_status) { ucs_status = UCS_OK; } else { - mca_btl_uct_uct_completion_release (comp); + mca_btl_uct_uct_completion_release(comp); } - mca_btl_uct_rkey_release (uct_btl, &rkey); + mca_btl_uct_rkey_release(uct_btl, &rkey); return OPAL_LIKELY(UCS_OK == ucs_status) ? OPAL_SUCCESS : OPAL_ERR_RESOURCE_BUSY; } -int mca_btl_uct_flush (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint) +int mca_btl_uct_flush(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; const int tl_index = uct_btl->rdma_tl->tl_index; @@ -251,37 +270,38 @@ int mca_btl_uct_flush (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endp BTL_VERBOSE(("mca_btl_uct_flush starting")); - for (int i = 0 ; i < context_count ; ++i) { + for (int i = 0; i < context_count; ++i) { mca_btl_uct_device_context_t *context = uct_btl->rdma_tl->uct_dev_contexts[i]; if (NULL == context) { continue; } - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); /* this loop is here because at least some of the TLs do no support a * completion callback. its a real PIA but has to be done for now. */ do { - uct_worker_progress (context->uct_worker); + uct_worker_progress(context->uct_worker); if (NULL != endpoint && endpoint->uct_eps[context->context_id][tl_index].uct_ep) { - ucs_status = uct_ep_flush (endpoint->uct_eps[context->context_id][tl_index].uct_ep, 0, NULL); + ucs_status = uct_ep_flush(endpoint->uct_eps[context->context_id][tl_index].uct_ep, + 0, NULL); } else { - ucs_status = uct_iface_flush (context->uct_iface, 0, NULL); + ucs_status = uct_iface_flush(context->uct_iface, 0, NULL); } } while (UCS_INPROGRESS == ucs_status); - mca_btl_uct_context_unlock (context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_context_unlock(context); + mca_btl_uct_device_handle_completions(context); } return OPAL_SUCCESS; } -int mca_btl_uct_flush_thread (mca_btl_base_module_t *btl) +int mca_btl_uct_flush_thread(mca_btl_base_module_t *btl) { mca_btl_uct_module_t *uct_btl = (mca_btl_uct_module_t *) btl; - const int context_id = mca_btl_uct_get_context_index (); + const int context_id = mca_btl_uct_get_context_index(); mca_btl_uct_device_context_t *context = uct_btl->rdma_tl->uct_dev_contexts[context_id]; ucs_status_t ucs_status; @@ -291,18 +311,18 @@ int mca_btl_uct_flush_thread (mca_btl_base_module_t *btl) return OPAL_SUCCESS; } - mca_btl_uct_context_lock (context); + mca_btl_uct_context_lock(context); /* this loop is here because at least some of the TLs do no support a * completion callback. its a real PIA but has to be done for now. */ do { - uct_worker_progress (context->uct_worker); - ucs_status = uct_iface_flush (context->uct_iface, 0, NULL); + uct_worker_progress(context->uct_worker); + ucs_status = uct_iface_flush(context->uct_iface, 0, NULL); } while (UCS_INPROGRESS == ucs_status); - mca_btl_uct_context_unlock (context); + mca_btl_uct_context_unlock(context); - mca_btl_uct_device_handle_completions (context); + mca_btl_uct_device_handle_completions(context); return OPAL_SUCCESS; } diff --git a/opal/mca/btl/uct/btl_uct_rdma.h b/opal/mca/btl/uct/btl_uct_rdma.h index ab790371afe..30e32abea60 100644 --- a/opal/mca/btl/uct/btl_uct_rdma.h +++ b/opal/mca/btl/uct/btl_uct_rdma.h @@ -10,25 +10,25 @@ */ #if !defined(BTL_UCT_RDMA_H) -#define BTL_UCT_RDMA_H +# define BTL_UCT_RDMA_H -#include "btl_uct.h" -#include "btl_uct_endpoint.h" -#include "btl_uct_frag.h" +# include "btl_uct.h" +# include "btl_uct_endpoint.h" +# include "btl_uct_frag.h" /** * @brief allocate a callback structure */ -mca_btl_uct_uct_completion_t *mca_btl_uct_uct_completion_alloc (mca_btl_uct_module_t *btl, mca_btl_base_endpoint_t *endpoint, - void *local_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_uct_device_context_t *dev_context, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); +mca_btl_uct_uct_completion_t *mca_btl_uct_uct_completion_alloc( + mca_btl_uct_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address, + mca_btl_base_registration_handle_t *local_handle, mca_btl_uct_device_context_t *dev_context, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); /** * @brief release a callback structure */ -void mca_btl_uct_uct_completion_release (mca_btl_uct_uct_completion_t *comp); +void mca_btl_uct_uct_completion_release(mca_btl_uct_uct_completion_t *comp); -void mca_btl_uct_uct_completion (uct_completion_t *uct_comp, ucs_status_t status); +void mca_btl_uct_uct_completion(uct_completion_t *uct_comp, ucs_status_t status); /** * @brief unpack the registration key and ensure the endpoint is connected @@ -40,37 +40,36 @@ void mca_btl_uct_uct_completion (uct_completion_t *uct_comp, ucs_status_t status * @param[inout] rkey uct registration key bundle * @param[out] ep_handle uct endpoint handle */ -static inline int mca_btl_uct_get_rkey (mca_btl_uct_module_t *module, - mca_btl_uct_device_context_t *context, - mca_btl_base_endpoint_t *endpoint, - mca_btl_base_registration_handle_t *remote_handle, - uct_rkey_bundle_t *rkey, - uct_ep_h *ep_handle) +static inline int mca_btl_uct_get_rkey(mca_btl_uct_module_t *module, + mca_btl_uct_device_context_t *context, + mca_btl_base_endpoint_t *endpoint, + mca_btl_base_registration_handle_t *remote_handle, + uct_rkey_bundle_t *rkey, uct_ep_h *ep_handle) { ucs_status_t ucs_status; int rc; - rc = mca_btl_uct_endpoint_check_rdma (module, endpoint, context, ep_handle); + rc = mca_btl_uct_endpoint_check_rdma(module, endpoint, context, ep_handle); if (OPAL_SUCCESS != rc) { return rc; } -#if UCT_API >= UCT_VERSION(1, 7) - ucs_status = uct_rkey_unpack (module->uct_component, (void *) remote_handle, rkey); -#else - ucs_status = uct_rkey_unpack ((void *) remote_handle, rkey); -#endif +# if UCT_API >= UCT_VERSION(1, 7) + ucs_status = uct_rkey_unpack(module->uct_component, (void *) remote_handle, rkey); +# else + ucs_status = uct_rkey_unpack((void *) remote_handle, rkey); +# endif return (UCS_OK == ucs_status) ? OPAL_SUCCESS : OPAL_ERROR; } -static inline void mca_btl_uct_rkey_release (mca_btl_uct_module_t *uct_btl, uct_rkey_bundle_t *rkey) +static inline void mca_btl_uct_rkey_release(mca_btl_uct_module_t *uct_btl, uct_rkey_bundle_t *rkey) { -#if UCT_API >= UCT_VERSION(1, 7) - uct_rkey_release (uct_btl->uct_component, rkey); -#else +# if UCT_API >= UCT_VERSION(1, 7) + uct_rkey_release(uct_btl->uct_component, rkey); +# else (void) uct_btl; - uct_rkey_release (rkey); -#endif + uct_rkey_release(rkey); +# endif } #endif /* !defined(BTL_UCT_RDMA_H) */ diff --git a/opal/mca/btl/uct/btl_uct_tl.c b/opal/mca/btl/uct/btl_uct_tl.c index 502fbba7567..d4c2f7ffda5 100644 --- a/opal/mca/btl/uct/btl_uct_tl.c +++ b/opal/mca/btl/uct/btl_uct_tl.c @@ -14,15 +14,15 @@ * $HEADER$ */ -#include "btl_uct_device_context.h" #include "btl_uct_am.h" -#include "opal/util/bit_ops.h" +#include "btl_uct_device_context.h" #include "opal/util/argv.h" +#include "opal/util/bit_ops.h" #if HAVE_DECL_UCT_CB_FLAG_SYNC -#define MCA_BTL_UCT_CB_FLAG_SYNC UCT_CB_FLAG_SYNC +# define MCA_BTL_UCT_CB_FLAG_SYNC UCT_CB_FLAG_SYNC #else -#define MCA_BTL_UCT_CB_FLAG_SYNC 0 +# define MCA_BTL_UCT_CB_FLAG_SYNC 0 #endif /** @@ -32,7 +32,7 @@ static uint64_t mca_btl_uct_cap_to_btl_flag[][2] = { {UCT_IFACE_FLAG_AM_SHORT, MCA_BTL_FLAGS_SEND}, {UCT_IFACE_FLAG_PUT_ZCOPY, MCA_BTL_FLAGS_PUT}, {UCT_IFACE_FLAG_GET_ZCOPY, MCA_BTL_FLAGS_GET}, - {0,0}, + {0, 0}, }; /** @@ -42,11 +42,11 @@ static uint64_t mca_btl_uct_cap_to_btl_flag[][2] = { * * @returns equivalent BTL flags */ -static int32_t mca_btl_uct_module_flags (uint64_t cap_flags) +static int32_t mca_btl_uct_module_flags(uint64_t cap_flags) { uint32_t flags = 0; - for (int i = 0 ; mca_btl_uct_cap_to_btl_flag[i][0] > 0 ; ++i) { + for (int i = 0; mca_btl_uct_cap_to_btl_flag[i][0] > 0; ++i) { if (cap_flags & mca_btl_uct_cap_to_btl_flag[i][0]) { flags |= (uint32_t) mca_btl_uct_cap_to_btl_flag[i][1]; } @@ -65,10 +65,12 @@ static uint64_t mca_btl_uct_cap_to_btl_atomic_flag[][2] = { {UCS_BIT(UCT_ATOMIC_OP_XOR), MCA_BTL_ATOMIC_SUPPORTS_XOR}, {UCS_BIT(UCT_ATOMIC_OP_SWAP), MCA_BTL_ATOMIC_SUPPORTS_SWAP}, {UCS_BIT(UCT_ATOMIC_OP_CSWAP), MCA_BTL_ATOMIC_SUPPORTS_CSWAP}, - {0, }, + { + 0, + }, }; -static void mca_btl_uct_module_set_atomic_flags (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) +static void mca_btl_uct_module_set_atomic_flags(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) { uint64_t cap_flags = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags; @@ -85,7 +87,7 @@ static void mca_btl_uct_module_set_atomic_flags (mca_btl_uct_module_t *module, m module->super.btl_atomic_flags |= MCA_BTL_ATOMIC_SUPPORTS_GLOB; } - for (int i = 0 ; mca_btl_uct_cap_to_btl_atomic_flag[i][0] ; ++i) { + for (int i = 0; mca_btl_uct_cap_to_btl_atomic_flag[i][0]; ++i) { if (all_flags & mca_btl_uct_cap_to_btl_atomic_flag[i][0]) { module->super.btl_atomic_flags |= mca_btl_uct_cap_to_btl_atomic_flag[i][1]; } @@ -107,7 +109,9 @@ static uint64_t mca_btl_uct_cap_to_btl_atomic_flag[][2] = { {UCT_IFACE_FLAG_ATOMIC_CSWAP64, MCA_BTL_ATOMIC_SUPPORTS_CSWAP}, {UCT_IFACE_FLAG_ATOMIC_SWAP64, MCA_BTL_ATOMIC_SUPPORTS_SWAP}, {UCT_IFACE_FLAG_ATOMIC_CPU, MCA_BTL_ATOMIC_SUPPORTS_GLOB}, - {0, }, + { + 0, + }, }; /** @@ -117,13 +121,13 @@ static uint64_t mca_btl_uct_cap_to_btl_atomic_flag[][2] = { * * @returns equivalent BTL atomic flags */ -static void mca_btl_uct_module_set_atomic_flags (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) +static void mca_btl_uct_module_set_atomic_flags(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) { uint64_t cap_flags = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags; module->super.btl_atomic_flags = 0; - for (int i = 0 ; mca_btl_uct_cap_to_btl_atomic_flag[i][0] > 0 ; ++i) { + for (int i = 0; mca_btl_uct_cap_to_btl_atomic_flag[i][0] > 0; ++i) { if (cap_flags & mca_btl_uct_cap_to_btl_atomic_flag[i][0]) { module->super.btl_atomic_flags |= (uint32_t) mca_btl_uct_cap_to_btl_atomic_flag[i][1]; } @@ -137,19 +141,19 @@ static void mca_btl_uct_module_set_atomic_flags (mca_btl_uct_module_t *module, m #endif -static void mca_btl_uct_tl_constructor (mca_btl_uct_tl_t *tl) +static void mca_btl_uct_tl_constructor(mca_btl_uct_tl_t *tl) { - memset ((void *)((uintptr_t) tl + sizeof (tl->super)), 0, sizeof (*tl) - sizeof (tl->super)); + memset((void *) ((uintptr_t) tl + sizeof(tl->super)), 0, sizeof(*tl) - sizeof(tl->super)); OBJ_CONSTRUCT(&tl->tl_lock, opal_mutex_t); } -static void mca_btl_uct_tl_destructor (mca_btl_uct_tl_t *tl) +static void mca_btl_uct_tl_destructor(mca_btl_uct_tl_t *tl) { - assert (((opal_object_t *) tl)->obj_reference_count == 0); + assert(((opal_object_t *) tl)->obj_reference_count == 0); - for (int context_id = 0 ; context_id < MCA_BTL_UCT_MAX_WORKERS ; ++context_id) { + for (int context_id = 0; context_id < MCA_BTL_UCT_MAX_WORKERS; ++context_id) { if (NULL != tl->uct_dev_contexts[context_id]) { - mca_btl_uct_context_destroy (tl->uct_dev_contexts[context_id]); + mca_btl_uct_context_destroy(tl->uct_dev_contexts[context_id]); } } @@ -157,39 +161,41 @@ static void mca_btl_uct_tl_destructor (mca_btl_uct_tl_t *tl) OBJ_RELEASE(tl->uct_md); } - free (tl->uct_dev_contexts); - free (tl->uct_tl_name); - free (tl->uct_dev_name); + free(tl->uct_dev_contexts); + free(tl->uct_tl_name); + free(tl->uct_dev_name); if (NULL != tl->uct_tl_config) { - uct_config_release (tl->uct_tl_config); + uct_config_release(tl->uct_tl_config); } OBJ_DESTRUCT(&tl->tl_lock); } -OBJ_CLASS_INSTANCE(mca_btl_uct_tl_t, opal_list_item_t, mca_btl_uct_tl_constructor, mca_btl_uct_tl_destructor); +OBJ_CLASS_INSTANCE(mca_btl_uct_tl_t, opal_list_item_t, mca_btl_uct_tl_constructor, + mca_btl_uct_tl_destructor); -static ucs_status_t mca_btl_uct_conn_req_cb (void *arg, void *data, size_t length, unsigned flags) +static ucs_status_t mca_btl_uct_conn_req_cb(void *arg, void *data, size_t length, unsigned flags) { mca_btl_uct_module_t *module = (mca_btl_uct_module_t *) arg; - mca_btl_uct_pending_connection_request_t *request = calloc (1, length + sizeof (request->super)); + mca_btl_uct_pending_connection_request_t *request = calloc(1, length + sizeof(request->super)); /* it is not safe to process the connection request from the callback so just save it for * later processing */ OBJ_CONSTRUCT(request, mca_btl_uct_pending_connection_request_t); - memcpy (&request->request_data, (void *) ((intptr_t) data + 8), length); - opal_fifo_push_atomic (&module->pending_connection_reqs, &request->super); + memcpy(&request->request_data, (void *) ((intptr_t) data + 8), length); + opal_fifo_push_atomic(&module->pending_connection_reqs, &request->super); return UCS_OK; } OBJ_CLASS_INSTANCE(mca_btl_uct_pending_connection_request_t, opal_list_item_t, NULL, NULL); -int mca_btl_uct_process_connection_request (mca_btl_uct_module_t *module, mca_btl_uct_conn_req_t *req) +int mca_btl_uct_process_connection_request(mca_btl_uct_module_t *module, + mca_btl_uct_conn_req_t *req) { - struct opal_proc_t *remote_proc = opal_proc_for_name (req->proc_name); - mca_btl_base_endpoint_t *endpoint = mca_btl_uct_get_ep (&module->super, remote_proc); + struct opal_proc_t *remote_proc = opal_proc_for_name(req->proc_name); + mca_btl_base_endpoint_t *endpoint = mca_btl_uct_get_ep(&module->super, remote_proc); mca_btl_uct_tl_endpoint_t *tl_endpoint = endpoint->uct_eps[req->context_id] + req->tl_index; int32_t ep_flags; int rc; @@ -202,13 +208,14 @@ int mca_btl_uct_process_connection_request (mca_btl_uct_module_t *module, mca_bt return UCS_ERR_UNREACHABLE; } - assert (req->type < 2); + assert(req->type < 2); - ep_flags = opal_atomic_fetch_or_32 (&tl_endpoint->flags, MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REC); + ep_flags = opal_atomic_fetch_or_32(&tl_endpoint->flags, MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REC); if (!(ep_flags & MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REC)) { /* create any necessary resources */ - rc = mca_btl_uct_endpoint_connect (module, endpoint, req->context_id, req->ep_addr, req->tl_index); + rc = mca_btl_uct_endpoint_connect(module, endpoint, req->context_id, req->ep_addr, + req->tl_index); if (OPAL_SUCCESS != rc && OPAL_ERR_OUT_OF_RESOURCE != rc) { BTL_ERROR(("could not setup rdma endpoint. rc = %d", rc)); return rc; @@ -223,23 +230,25 @@ int mca_btl_uct_process_connection_request (mca_btl_uct_module_t *module, mca_bt mca_btl_uct_base_frag_t *frag; /* to avoid a race with send adding pending frags grab the lock here */ - OPAL_THREAD_SCOPED_LOCK(&endpoint->ep_lock,{ - BTL_VERBOSE(("connection ready. sending %" PRIsize_t " frags", opal_list_get_size (&module->pending_frags))); - (void) opal_atomic_or_fetch_32 (&tl_endpoint->flags, MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY); - opal_atomic_wmb (); - - OPAL_LIST_FOREACH(frag, &module->pending_frags, mca_btl_uct_base_frag_t) { - if (frag->context->context_id == req->context_id && endpoint == frag->endpoint) { - frag->ready = true; - } + OPAL_THREAD_SCOPED_LOCK(&endpoint->ep_lock, { + BTL_VERBOSE(("connection ready. sending %" PRIsize_t " frags", + opal_list_get_size(&module->pending_frags))); + (void) opal_atomic_or_fetch_32(&tl_endpoint->flags, + MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY); + opal_atomic_wmb(); + + OPAL_LIST_FOREACH (frag, &module->pending_frags, mca_btl_uct_base_frag_t) { + if (frag->context->context_id == req->context_id && endpoint == frag->endpoint) { + frag->ready = true; } - }); + } + }); } return OPAL_SUCCESS; } -static int mca_btl_uct_setup_connection_tl (mca_btl_uct_module_t *module) +static int mca_btl_uct_setup_connection_tl(mca_btl_uct_module_t *module) { ucs_status_t ucs_status; @@ -247,8 +256,9 @@ static int mca_btl_uct_setup_connection_tl (mca_btl_uct_module_t *module) return OPAL_ERR_NOT_SUPPORTED; } - ucs_status = uct_iface_set_am_handler (module->conn_tl->uct_dev_contexts[0]->uct_iface, MCA_BTL_UCT_CONNECT_RDMA, - mca_btl_uct_conn_req_cb, module, UCT_CB_FLAG_ASYNC); + ucs_status = uct_iface_set_am_handler(module->conn_tl->uct_dev_contexts[0]->uct_iface, + MCA_BTL_UCT_CONNECT_RDMA, mca_btl_uct_conn_req_cb, module, + UCT_CB_FLAG_ASYNC); if (UCS_OK != ucs_status) { BTL_ERROR(("could not set active message handler for uct tl")); } @@ -256,30 +266,35 @@ static int mca_btl_uct_setup_connection_tl (mca_btl_uct_module_t *module) return UCS_OK == ucs_status ? OPAL_SUCCESS : OPAL_ERROR; } -static void mca_btl_uct_context_enable_progress (mca_btl_uct_device_context_t *context) +static void mca_btl_uct_context_enable_progress(mca_btl_uct_device_context_t *context) { if (!context->progress_enabled) { #if HAVE_DECL_UCT_PROGRESS_THREAD_SAFE - uct_iface_progress_enable (context->uct_iface, UCT_PROGRESS_THREAD_SAFE | UCT_PROGRESS_SEND | - UCT_PROGRESS_RECV); + uct_iface_progress_enable(context->uct_iface, + UCT_PROGRESS_THREAD_SAFE | UCT_PROGRESS_SEND | UCT_PROGRESS_RECV); #else - uct_iface_progress_enable (context->uct_iface, UCT_PROGRESS_SEND | UCT_PROGRESS_RECV); + uct_iface_progress_enable(context->uct_iface, UCT_PROGRESS_SEND | UCT_PROGRESS_RECV); #endif context->progress_enabled = true; } } -mca_btl_uct_device_context_t *mca_btl_uct_context_create (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl, int context_id, bool enable_progress) +mca_btl_uct_device_context_t *mca_btl_uct_context_create(mca_btl_uct_module_t *module, + mca_btl_uct_tl_t *tl, int context_id, + bool enable_progress) { #if UCT_API >= UCT_VERSION(1, 6) - uct_iface_params_t iface_params = {.field_mask = UCT_IFACE_PARAM_FIELD_OPEN_MODE | - UCT_IFACE_PARAM_FIELD_DEVICE, + uct_iface_params_t iface_params = {.field_mask = UCT_IFACE_PARAM_FIELD_OPEN_MODE + | UCT_IFACE_PARAM_FIELD_DEVICE, .open_mode = UCT_IFACE_OPEN_MODE_DEVICE, .mode = {.device = {.tl_name = tl->uct_tl_name, .dev_name = tl->uct_dev_name}}}; #else - uct_iface_params_t iface_params = {.rndv_cb = NULL, .eager_cb = NULL, .stats_root = NULL, - .rx_headroom = 0, .open_mode = UCT_IFACE_OPEN_MODE_DEVICE, + uct_iface_params_t iface_params = {.rndv_cb = NULL, + .eager_cb = NULL, + .stats_root = NULL, + .rx_headroom = 0, + .open_mode = UCT_IFACE_OPEN_MODE_DEVICE, .mode = {.device = {.tl_name = tl->uct_tl_name, .dev_name = tl->uct_dev_name}}}; #endif @@ -287,7 +302,7 @@ mca_btl_uct_device_context_t *mca_btl_uct_context_create (mca_btl_uct_module_t * ucs_status_t ucs_status; int rc; - context = calloc (1, sizeof (*context)); + context = calloc(1, sizeof(*context)); if (OPAL_UNLIKELY(NULL == context)) { return NULL; } @@ -298,12 +313,11 @@ mca_btl_uct_device_context_t *mca_btl_uct_context_create (mca_btl_uct_module_t * OBJ_CONSTRUCT(&context->mutex, opal_recursive_mutex_t); OBJ_CONSTRUCT(&context->rdma_completions, opal_free_list_t); - rc = opal_free_list_init (&context->rdma_completions, sizeof (mca_btl_uct_uct_completion_t), - opal_cache_line_size, OBJ_CLASS(mca_btl_uct_uct_completion_t), - 0, opal_cache_line_size, 0, 4096, 128, NULL, 0, NULL, NULL, - NULL); + rc = opal_free_list_init(&context->rdma_completions, sizeof(mca_btl_uct_uct_completion_t), + opal_cache_line_size, OBJ_CLASS(mca_btl_uct_uct_completion_t), 0, + opal_cache_line_size, 0, 4096, 128, NULL, 0, NULL, NULL, NULL); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - mca_btl_uct_context_destroy (context); + mca_btl_uct_context_destroy(context); return NULL; } @@ -311,61 +325,61 @@ mca_btl_uct_device_context_t *mca_btl_uct_context_create (mca_btl_uct_module_t * * use our own locks just go ahead and use UCS_THREAD_MODE_SINGLE. if they ever fix their * api then change this back to UCS_THREAD_MODE_MULTI and remove the locks around the * various UCT calls. */ - ucs_status = uct_worker_create (module->ucs_async, UCS_THREAD_MODE_SINGLE, &context->uct_worker); + ucs_status = uct_worker_create(module->ucs_async, UCS_THREAD_MODE_SINGLE, &context->uct_worker); if (OPAL_UNLIKELY(UCS_OK != ucs_status)) { BTL_VERBOSE(("could not create a UCT worker")); - mca_btl_uct_context_destroy (context); + mca_btl_uct_context_destroy(context); return NULL; } - ucs_status = uct_iface_open (tl->uct_md->uct_md, context->uct_worker, &iface_params, - tl->uct_tl_config, &context->uct_iface); + ucs_status = uct_iface_open(tl->uct_md->uct_md, context->uct_worker, &iface_params, + tl->uct_tl_config, &context->uct_iface); if (OPAL_UNLIKELY(UCS_OK != ucs_status)) { BTL_VERBOSE(("could not open UCT interface. error code: %d", ucs_status)); - mca_btl_uct_context_destroy (context); + mca_btl_uct_context_destroy(context); return NULL; } /* only need to query one of the interfaces to get the attributes */ - ucs_status = uct_iface_query (context->uct_iface, &context->uct_iface_attr); + ucs_status = uct_iface_query(context->uct_iface, &context->uct_iface_attr); if (UCS_OK != ucs_status) { BTL_VERBOSE(("Error querying UCT interface")); - mca_btl_uct_context_destroy (context); + mca_btl_uct_context_destroy(context); return NULL; } if (context_id > 0 && tl == module->am_tl) { - BTL_VERBOSE(("installing AM handler for tl %p context id %d", (void *) tl, context_id)); - uct_iface_set_am_handler (context->uct_iface, MCA_BTL_UCT_FRAG, mca_btl_uct_am_handler, - context, MCA_BTL_UCT_CB_FLAG_SYNC); + BTL_VERBOSE(("installing AM handler for tl %p context id %d", (void *) tl, context_id)); + uct_iface_set_am_handler(context->uct_iface, MCA_BTL_UCT_FRAG, mca_btl_uct_am_handler, + context, MCA_BTL_UCT_CB_FLAG_SYNC); } if (enable_progress) { BTL_VERBOSE(("enabling progress for tl %p context id %d", (void *) tl, context_id)); - mca_btl_uct_context_enable_progress (context); + mca_btl_uct_context_enable_progress(context); } return context; } -void mca_btl_uct_context_destroy (mca_btl_uct_device_context_t *context) +void mca_btl_uct_context_destroy(mca_btl_uct_device_context_t *context) { if (context->uct_iface) { - uct_iface_close (context->uct_iface); + uct_iface_close(context->uct_iface); context->uct_iface = NULL; } if (context->uct_worker) { - uct_worker_destroy (context->uct_worker); + uct_worker_destroy(context->uct_worker); context->uct_worker = NULL; } OBJ_DESTRUCT(&context->completion_fifo); OBJ_DESTRUCT(&context->rdma_completions); - free (context); + free(context); } -static int tl_compare (opal_list_item_t **a, opal_list_item_t **b) +static int tl_compare(opal_list_item_t **a, opal_list_item_t **b) { mca_btl_uct_tl_t *tl_a = (mca_btl_uct_tl_t *) *a; mca_btl_uct_tl_t *tl_b = (mca_btl_uct_tl_t *) *b; @@ -373,7 +387,8 @@ static int tl_compare (opal_list_item_t **a, opal_list_item_t **b) return tl_a->priority - tl_b->priority; } -static mca_btl_uct_tl_t *mca_btl_uct_create_tl (mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, uct_tl_resource_desc_t *tl_desc, int priority) +static mca_btl_uct_tl_t *mca_btl_uct_create_tl(mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, + uct_tl_resource_desc_t *tl_desc, int priority) { mca_btl_uct_tl_t *tl = OBJ_NEW(mca_btl_uct_tl_t); @@ -385,20 +400,20 @@ static mca_btl_uct_tl_t *mca_btl_uct_create_tl (mca_btl_uct_module_t *module, mc tl->uct_md = md; OBJ_RETAIN(md); - tl->uct_tl_name = strdup (tl_desc->tl_name); - tl->uct_dev_name = strdup (tl_desc->dev_name); + tl->uct_tl_name = strdup(tl_desc->tl_name); + tl->uct_dev_name = strdup(tl_desc->dev_name); tl->priority = priority; - tl->uct_dev_contexts = calloc (MCA_BTL_UCT_MAX_WORKERS, sizeof (tl->uct_dev_contexts[0])); + tl->uct_dev_contexts = calloc(MCA_BTL_UCT_MAX_WORKERS, sizeof(tl->uct_dev_contexts[0])); if (NULL == tl->uct_dev_contexts) { OBJ_RELEASE(tl); return NULL; } - (void) uct_md_iface_config_read (md->uct_md, tl_desc->tl_name, NULL, NULL, &tl->uct_tl_config); + (void) uct_md_iface_config_read(md->uct_md, tl_desc->tl_name, NULL, NULL, &tl->uct_tl_config); /* always create a 0 context (needed to query) */ - tl->uct_dev_contexts[0] = mca_btl_uct_context_create (module, tl, 0, false); + tl->uct_dev_contexts[0] = mca_btl_uct_context_create(module, tl, 0, false); if (NULL == tl->uct_dev_contexts[0]) { BTL_VERBOSE(("could not create a uct device context")); OBJ_RELEASE(tl); @@ -411,26 +426,30 @@ static mca_btl_uct_tl_t *mca_btl_uct_create_tl (mca_btl_uct_module_t *module, mc return tl; } -static void mca_btl_uct_set_tl_rdma (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) +static void mca_btl_uct_set_tl_rdma(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) { BTL_VERBOSE(("tl %s is suitable for RDMA", tl->uct_tl_name)); - mca_btl_uct_module_set_atomic_flags (module, tl); + mca_btl_uct_module_set_atomic_flags(module, tl); module->super.btl_get_limit = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.get.max_zcopy; if (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.get.max_bcopy) { module->super.btl_get_alignment = 0; - module->super.btl_get_local_registration_threshold = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.get.max_bcopy; + module->super.btl_get_local_registration_threshold = MCA_BTL_UCT_TL_ATTR(tl, 0) + .cap.get.max_bcopy; } else { - /* this is overkill in terms of alignment but we have no way to enforce a minimum get size */ - module->super.btl_get_alignment = opal_next_poweroftwo_inclusive (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.get.min_zcopy); + /* this is overkill in terms of alignment but we have no way to enforce a minimum get size + */ + module->super.btl_get_alignment = opal_next_poweroftwo_inclusive( + MCA_BTL_UCT_TL_ATTR(tl, 0).cap.get.min_zcopy); } module->super.btl_put_limit = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.put.max_zcopy; module->super.btl_put_alignment = 0; /* no registration needed when using short/bcopy put */ - module->super.btl_put_local_registration_threshold = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.put.max_bcopy; + module->super.btl_put_local_registration_threshold = MCA_BTL_UCT_TL_ATTR(tl, 0) + .cap.put.max_bcopy; module->rdma_tl = tl; OBJ_RETAIN(tl); @@ -438,47 +457,47 @@ static void mca_btl_uct_set_tl_rdma (mca_btl_uct_module_t *module, mca_btl_uct_t tl->tl_index = (module->am_tl && tl != module->am_tl) ? 1 : 0; module->comm_tls[tl->tl_index] = tl; if (tl->max_device_contexts <= 1) { - tl->max_device_contexts = mca_btl_uct_component.num_contexts_per_module; + tl->max_device_contexts = mca_btl_uct_component.num_contexts_per_module; } } -static void mca_btl_uct_set_tl_am (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) +static void mca_btl_uct_set_tl_am(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) { BTL_VERBOSE(("tl %s is suitable for active-messaging", tl->uct_tl_name)); if (module->rdma_tl == tl) { - module->shared_endpoints = true; + module->shared_endpoints = true; } module->am_tl = tl; OBJ_RETAIN(tl); - uct_iface_set_am_handler (tl->uct_dev_contexts[0]->uct_iface, MCA_BTL_UCT_FRAG, - mca_btl_uct_am_handler, tl->uct_dev_contexts[0], UCT_CB_FLAG_ASYNC); + uct_iface_set_am_handler(tl->uct_dev_contexts[0]->uct_iface, MCA_BTL_UCT_FRAG, + mca_btl_uct_am_handler, tl->uct_dev_contexts[0], UCT_CB_FLAG_ASYNC); tl->tl_index = (module->rdma_tl && tl != module->rdma_tl) ? 1 : 0; module->comm_tls[tl->tl_index] = tl; if (tl->max_device_contexts <= 1) { - tl->max_device_contexts = mca_btl_uct_component.num_contexts_per_module; + tl->max_device_contexts = mca_btl_uct_component.num_contexts_per_module; } - module->super.btl_eager_limit = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.am.max_bcopy - - sizeof (mca_btl_uct_am_header_t); + module->super.btl_eager_limit = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.am.max_bcopy + - sizeof(mca_btl_uct_am_header_t); if (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags & UCT_IFACE_FLAG_AM_ZCOPY) { - module->super.btl_max_send_size = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.am.max_zcopy - - sizeof (mca_btl_uct_am_header_t); + module->super.btl_max_send_size = MCA_BTL_UCT_TL_ATTR(tl, 0).cap.am.max_zcopy + - sizeof(mca_btl_uct_am_header_t); } else { module->super.btl_max_send_size = module->super.btl_eager_limit; } } -static int mca_btl_uct_set_tl_conn (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) +static int mca_btl_uct_set_tl_conn(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) { int rc; BTL_VERBOSE(("tl %s is suitable for making connections", tl->uct_tl_name)); module->conn_tl = tl; - rc = mca_btl_uct_setup_connection_tl (module); + rc = mca_btl_uct_setup_connection_tl(module); if (OPAL_SUCCESS != rc) { return rc; } @@ -486,29 +505,29 @@ static int mca_btl_uct_set_tl_conn (mca_btl_uct_module_t *module, mca_btl_uct_tl OBJ_RETAIN(tl); if (!tl->max_device_contexts) { - /* if a tl is only being used to create connections do not bother with multiple - * contexts */ - tl->max_device_contexts = 1; + /* if a tl is only being used to create connections do not bother with multiple + * contexts */ + tl->max_device_contexts = 1; } return OPAL_SUCCESS; } -static int mca_btl_uct_evaluate_tl (mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) +static int mca_btl_uct_evaluate_tl(mca_btl_uct_module_t *module, mca_btl_uct_tl_t *tl) { int rc; BTL_VERBOSE(("evaluating tl %s", tl->uct_tl_name)); - if (NULL == module->rdma_tl && mca_btl_uct_tl_supports_rdma (tl)) { - mca_btl_uct_set_tl_rdma (module, tl); + if (NULL == module->rdma_tl && mca_btl_uct_tl_supports_rdma(tl)) { + mca_btl_uct_set_tl_rdma(module, tl); } - if (NULL == module->am_tl && mca_btl_uct_tl_support_am (tl)) { - mca_btl_uct_set_tl_am (module, tl); + if (NULL == module->am_tl && mca_btl_uct_tl_support_am(tl)) { + mca_btl_uct_set_tl_am(module, tl); } - if (NULL == module->conn_tl && mca_btl_uct_tl_supports_conn (tl)) { - rc = mca_btl_uct_set_tl_conn (module, tl); + if (NULL == module->conn_tl && mca_btl_uct_tl_supports_conn(tl)) { + rc = mca_btl_uct_set_tl_conn(module, tl); if (OPAL_SUCCESS != rc) { return rc; } @@ -516,32 +535,35 @@ static int mca_btl_uct_evaluate_tl (mca_btl_uct_module_t *module, mca_btl_uct_tl if (tl == module->rdma_tl || tl == module->am_tl) { BTL_VERBOSE(("tl has flags 0x%" PRIx64, MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags)); - module->super.btl_flags |= mca_btl_uct_module_flags (MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags); + module->super.btl_flags |= mca_btl_uct_module_flags(MCA_BTL_UCT_TL_ATTR(tl, 0).cap.flags); - /* the bandwidth and latency numbers relate to both rdma and active messages. need to - * come up with a better estimate. */ + /* the bandwidth and latency numbers relate to both rdma and active messages. need to + * come up with a better estimate. */ - /* UCT bandwidth is in bytes/sec, BTL is in MB/sec */ + /* UCT bandwidth is in bytes/sec, BTL is in MB/sec */ #if UCT_API >= UCT_VERSION(1, 7) - module->super.btl_bandwidth = (uint32_t) ((MCA_BTL_UCT_TL_ATTR(tl, 0).bandwidth.dedicated + - MCA_BTL_UCT_TL_ATTR(tl, 0).bandwidth.shared / - (opal_process_info.num_local_peers + 1)) / 1048576.0); + module->super.btl_bandwidth = (uint32_t)((MCA_BTL_UCT_TL_ATTR(tl, 0).bandwidth.dedicated + + MCA_BTL_UCT_TL_ATTR(tl, 0).bandwidth.shared + / (opal_process_info.num_local_peers + 1)) + / 1048576.0); #else - module->super.btl_bandwidth = (uint32_t) (MCA_BTL_UCT_TL_ATTR(tl, 0).bandwidth / 1048576.0); + module->super.btl_bandwidth = (uint32_t)(MCA_BTL_UCT_TL_ATTR(tl, 0).bandwidth / 1048576.0); #endif - /* TODO -- figure out how to translate UCT latency to us */ - module->super.btl_latency = 1; + /* TODO -- figure out how to translate UCT latency to us */ + module->super.btl_latency = 1; } if (tl == module->rdma_tl || tl == module->am_tl || tl == module->conn_tl) { - /* make sure progress is enabled on the default context now that we know this TL will be used */ - mca_btl_uct_context_enable_progress (tl->uct_dev_contexts[0]); + /* make sure progress is enabled on the default context now that we know this TL will be + * used */ + mca_btl_uct_context_enable_progress(tl->uct_dev_contexts[0]); } return OPAL_SUCCESS; } -int mca_btl_uct_query_tls (mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, uct_tl_resource_desc_t *tl_descs, unsigned tl_count) +int mca_btl_uct_query_tls(mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, + uct_tl_resource_desc_t *tl_descs, unsigned tl_count) { bool include = true, any = false; mca_btl_uct_tl_t *tl; @@ -551,20 +573,20 @@ int mca_btl_uct_query_tls (mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, u OBJ_CONSTRUCT(&tl_list, opal_list_t); - tl_filter = opal_argv_split (mca_btl_uct_component.allowed_transports, ','); + tl_filter = opal_argv_split(mca_btl_uct_component.allowed_transports, ','); if ('^' == tl_filter[0][0]) { - /* user has negated the include list */ - char *tmp = strdup (tl_filter[0] + 1); + /* user has negated the include list */ + char *tmp = strdup(tl_filter[0] + 1); - free (tl_filter[0]); - tl_filter[0] = tmp; - include = false; + free(tl_filter[0]); + tl_filter[0] = tmp; + include = false; } /* check for the any keyword */ - for (unsigned j = 0 ; tl_filter[j] ; ++j) { - if (0 == strcmp (tl_filter[j], "any")) { + for (unsigned j = 0; tl_filter[j]; ++j) { + if (0 == strcmp(tl_filter[j], "any")) { any_priority = j; any = true; break; @@ -572,90 +594,92 @@ int mca_btl_uct_query_tls (mca_btl_uct_module_t *module, mca_btl_uct_md_t *md, u } if (any && !include) { - opal_argv_free (tl_filter); + opal_argv_free(tl_filter); return OPAL_ERR_NOT_AVAILABLE; } - for (unsigned i = 0 ; i < tl_count ; ++i) { - bool try_tl = any; - int priority = any_priority; + for (unsigned i = 0; i < tl_count; ++i) { + bool try_tl = any; + int priority = any_priority; - for (unsigned j = 0 ; tl_filter[j] ; ++j) { - if (0 == strcmp (tl_filter[j], tl_descs[i].tl_name)) { + for (unsigned j = 0; tl_filter[j]; ++j) { + if (0 == strcmp(tl_filter[j], tl_descs[i].tl_name)) { try_tl = include; priority = j; break; } - } + } - BTL_VERBOSE(("tl filter: tl_name = %s, use = %d, priority = %d", tl_descs[i].tl_name, try_tl, priority)); + BTL_VERBOSE(("tl filter: tl_name = %s, use = %d, priority = %d", tl_descs[i].tl_name, + try_tl, priority)); - if (!try_tl) { - continue; - } + if (!try_tl) { + continue; + } - if (0 == strcmp (tl_descs[i].tl_name, "ud")) { + if (0 == strcmp(tl_descs[i].tl_name, "ud")) { /* ud looks like any normal transport but we do not want to use it for anything other * than connection management so ensure it gets evaluated last */ priority = INT_MAX; } - tl = mca_btl_uct_create_tl (module, md, tl_descs + i, priority); + tl = mca_btl_uct_create_tl(module, md, tl_descs + i, priority); - if (tl) { - opal_list_append (&tl_list, &tl->super); - } + if (tl) { + opal_list_append(&tl_list, &tl->super); + } } - opal_argv_free (tl_filter); + opal_argv_free(tl_filter); - if (0 == opal_list_get_size (&tl_list)) { - BTL_VERBOSE(("no suitable tls match filter: %s", mca_btl_uct_component.allowed_transports)); - OBJ_DESTRUCT(&tl_list); - return OPAL_ERR_NOT_AVAILABLE; + if (0 == opal_list_get_size(&tl_list)) { + BTL_VERBOSE(("no suitable tls match filter: %s", mca_btl_uct_component.allowed_transports)); + OBJ_DESTRUCT(&tl_list); + return OPAL_ERR_NOT_AVAILABLE; } - opal_list_sort (&tl_list, tl_compare); + opal_list_sort(&tl_list, tl_compare); - OPAL_LIST_FOREACH(tl, &tl_list, mca_btl_uct_tl_t) { - mca_btl_uct_evaluate_tl (module, tl); - if (NULL != module->am_tl && NULL != module->rdma_tl && - (NULL != module->conn_tl || !(mca_btl_uct_tl_requires_connection_tl (module->am_tl) || - mca_btl_uct_tl_requires_connection_tl (module->rdma_tl)))) { - /* all done */ - break; - } + OPAL_LIST_FOREACH (tl, &tl_list, mca_btl_uct_tl_t) { + mca_btl_uct_evaluate_tl(module, tl); + if (NULL != module->am_tl && NULL != module->rdma_tl + && (NULL != module->conn_tl + || !(mca_btl_uct_tl_requires_connection_tl(module->am_tl) + || mca_btl_uct_tl_requires_connection_tl(module->rdma_tl)))) { + /* all done */ + break; + } } if (NULL == module->rdma_tl) { - /* no rdma tls */ - BTL_VERBOSE(("no rdma tl matched supplied filter. disabling RDMA support")); + /* no rdma tls */ + BTL_VERBOSE(("no rdma tl matched supplied filter. disabling RDMA support")); module->super.btl_flags &= ~MCA_BTL_FLAGS_RDMA; - module->super.btl_put = NULL; - module->super.btl_get = NULL; - module->super.btl_atomic_fop = NULL; - module->super.btl_atomic_op = NULL; + module->super.btl_put = NULL; + module->super.btl_get = NULL; + module->super.btl_atomic_fop = NULL; + module->super.btl_atomic_op = NULL; } if (NULL == module->am_tl) { - /* no active message tls == no send/recv */ - BTL_VERBOSE(("no active message tl matched supplied filter. disabling send/recv support")); + /* no active message tls == no send/recv */ + BTL_VERBOSE(("no active message tl matched supplied filter. disabling send/recv support")); - module->super.btl_send = NULL; - module->super.btl_sendi = NULL; - module->super.btl_alloc = NULL; - module->super.btl_free = NULL; + module->super.btl_send = NULL; + module->super.btl_sendi = NULL; + module->super.btl_alloc = NULL; + module->super.btl_free = NULL; } OPAL_LIST_DESTRUCT(&tl_list); - if (!(NULL != module->am_tl && mca_btl_uct_tl_requires_connection_tl (module->am_tl)) && - !(NULL != module->rdma_tl && mca_btl_uct_tl_requires_connection_tl (module->rdma_tl)) && - module->conn_tl) { - /* no connection tl needed for selected transports */ - OBJ_RELEASE(module->conn_tl); - module->conn_tl = NULL; + if (!(NULL != module->am_tl && mca_btl_uct_tl_requires_connection_tl(module->am_tl)) + && !(NULL != module->rdma_tl && mca_btl_uct_tl_requires_connection_tl(module->rdma_tl)) + && module->conn_tl) { + /* no connection tl needed for selected transports */ + OBJ_RELEASE(module->conn_tl); + module->conn_tl = NULL; } else if (NULL == module->conn_tl) { BTL_VERBOSE(("a connection tl is required but no tls match the filter %s", mca_btl_uct_component.allowed_transports)); diff --git a/opal/mca/btl/uct/btl_uct_types.h b/opal/mca/btl/uct/btl_uct_types.h index 4b0df21e2a7..f695632f931 100644 --- a/opal/mca/btl/uct/btl_uct_types.h +++ b/opal/mca/btl/uct/btl_uct_types.h @@ -10,9 +10,9 @@ */ #if !defined(BTL_UCT_TYPES_H) -#define BTL_UCT_TYPES_H +# define BTL_UCT_TYPES_H -#include "opal/mca/btl/btl.h" +# include "opal/mca/btl/btl.h" /* forward declarations */ struct mca_btl_uct_module_t; @@ -21,22 +21,22 @@ struct mca_btl_uct_base_frag_t; /* TL endpoint flags */ /** connection data was received */ -#define MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REC 0x1 +# define MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REC 0x1 /** remote endpoint read */ -#define MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REM_READY 0x2 +# define MCA_BTL_UCT_ENDPOINT_FLAG_CONN_REM_READY 0x2 /** connection was established */ -#define MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY 0x4 +# define MCA_BTL_UCT_ENDPOINT_FLAG_CONN_READY 0x4 /* AM tags */ /** BTL fragment */ -#define MCA_BTL_UCT_FRAG 0x0d +# define MCA_BTL_UCT_FRAG 0x0d /** connection request */ -#define MCA_BTL_UCT_CONNECT_RDMA 0x0e +# define MCA_BTL_UCT_CONNECT_RDMA 0x0e /** maximum number of modules supported by the btl component */ -#define MCA_BTL_UCT_MAX_MODULES 16 +# define MCA_BTL_UCT_MAX_MODULES 16 /** maximum number of UCT workers */ -#define MCA_BTL_UCT_MAX_WORKERS 64 +# define MCA_BTL_UCT_MAX_WORKERS 64 /** * @brief MODEx data @@ -69,7 +69,6 @@ typedef struct mca_btl_uct_md_t mca_btl_uct_md_t; OBJ_CLASS_DECLARATION(mca_btl_uct_md_t); - /** * @brief Connection request structure */ @@ -169,11 +168,11 @@ typedef struct mca_btl_uct_device_context_t mca_btl_uct_device_context_t; union mca_btl_uct_am_header_t { /** active message header data */ struct mca_btl_uct_am_header_data_t { - /** callback tag */ + /** callback tag */ mca_btl_base_tag_t tag; - /** padding */ - uint8_t padding[7]; + /** padding */ + uint8_t padding[7]; } data; /** header value. this is 64-bits to support using this with uct_ep_am_short */ @@ -330,7 +329,7 @@ struct mca_btl_uct_tl_t { typedef struct mca_btl_uct_tl_t mca_btl_uct_tl_t; OBJ_CLASS_DECLARATION(mca_btl_uct_tl_t); -#define MCA_BTL_UCT_TL_ATTR(tl, context_id) (tl)->uct_dev_contexts[(context_id)]->uct_iface_attr +# define MCA_BTL_UCT_TL_ATTR(tl, context_id) (tl)->uct_dev_contexts[(context_id)]->uct_iface_attr struct mca_btl_uct_pending_connection_request_t { opal_list_item_t super; diff --git a/opal/mca/btl/ugni/btl_ugni.h b/opal/mca/btl/ugni/btl_ugni.h index eaf5c4e5e24..ca9d5a50a92 100644 --- a/opal/mca/btl/ugni/btl_ugni.h +++ b/opal/mca/btl/ugni/btl_ugni.h @@ -24,26 +24,26 @@ #include "opal_config.h" -#include "opal/mca/mpool/mpool.h" +#include "opal/class/opal_free_list.h" +#include "opal/class/opal_hash_table.h" +#include "opal/class/opal_pointer_array.h" +#include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" +#include "opal/mca/mpool/mpool.h" +#include "opal/mca/pmix/pmix-internal.h" #include "opal/mca/rcache/base/base.h" #include "opal/mca/rcache/udreg/rcache_udreg.h" #include "opal/util/output.h" #include "opal_stdint.h" -#include "opal/mca/btl/btl.h" -#include "opal/mca/btl/base/base.h" -#include "opal/mca/btl/base/btl_base_error.h" -#include "opal/class/opal_hash_table.h" -#include "opal/class/opal_free_list.h" -#include "opal/class/opal_pointer_array.h" -#include "opal/mca/pmix/pmix-internal.h" +#include #include +#include #include -#include -#include #include -#include +#include /* datagram message ids */ #define MCA_BTL_UGNI_CONNECT_WILDCARD_ID 0x0000000000000000ull @@ -66,7 +66,7 @@ struct mca_btl_ugni_modex_t { /** GNI NIC address */ uint32_t addr; /** CDM identifier (base) */ - int id; + int id; }; typedef struct mca_btl_ugni_modex_t mca_btl_ugni_modex_t; @@ -78,10 +78,7 @@ typedef struct mca_btl_ugni_endpoint_attr_t { gni_mem_handle_t rmt_irq_mem_hndl; } mca_btl_ugni_endpoint_attr_t; -enum { - MCA_BTL_UGNI_RCACHE_UDREG, - MCA_BTL_UGNI_RCACHE_GRDMA -}; +enum { MCA_BTL_UGNI_RCACHE_UDREG, MCA_BTL_UGNI_RCACHE_GRDMA }; enum mca_btl_ugni_free_list_id_t { /* eager fragment list (registered) */ @@ -142,7 +139,7 @@ struct mca_btl_ugni_device_t { }; typedef struct mca_btl_ugni_device_t mca_btl_ugni_device_t; -typedef intptr_t (*mca_btl_ugni_device_serialize_fn_t) (mca_btl_ugni_device_t *device, void *arg); +typedef intptr_t (*mca_btl_ugni_device_serialize_fn_t)(mca_btl_ugni_device_t *device, void *arg); typedef struct mca_btl_ugni_module_t { mca_btl_base_module_t super; @@ -157,7 +154,7 @@ typedef struct mca_btl_ugni_module_t { opal_hash_table_t id_to_endpoint; /* lock for this list */ - opal_mutex_t failed_frags_lock; + opal_mutex_t failed_frags_lock; /** rdma frags waiting to be reposted */ opal_list_t failed_frags; @@ -166,7 +163,7 @@ typedef struct mca_btl_ugni_module_t { opal_list_t eager_get_pending; mca_mpool_base_module_t *mpool; - opal_free_list_t smsg_mboxes; + opal_free_list_t smsg_mboxes; gni_ep_handle_t wildcard_ep; struct mca_btl_base_endpoint_t *local_ep; @@ -183,9 +180,9 @@ typedef struct mca_btl_ugni_module_t { opal_free_list_t frags_lists[MCA_BTL_UGNI_LIST_MAX]; /* lock for this list */ - opal_mutex_t ep_wait_list_lock; + opal_mutex_t ep_wait_list_lock; /* endpoints waiting on credits */ - opal_list_t ep_wait_list; + opal_list_t ep_wait_list; /* fragment id bounce buffer (smsg msg ids are only 32 bits) */ opal_pointer_array_t pending_smsg_frags_bb; @@ -304,23 +301,24 @@ typedef struct mca_btl_ugni_component_t { OPAL_MODULE_DECLSPEC extern mca_btl_ugni_component_t mca_btl_ugni_component; OPAL_MODULE_DECLSPEC extern mca_btl_ugni_module_t mca_btl_ugni_module; -static inline uint32_t mca_btl_ugni_ep_get_device_index (mca_btl_ugni_module_t *ugni_module) +static inline uint32_t mca_btl_ugni_ep_get_device_index(mca_btl_ugni_module_t *ugni_module) { static opal_atomic_int64_t device_index = 0; /* don't really care if the device index is atomically updated */ - return (uint32_t) (opal_atomic_fetch_add_64 (&device_index, 1) % mca_btl_ugni_component.virtual_device_count); + return (uint32_t)(opal_atomic_fetch_add_64(&device_index, 1) + % mca_btl_ugni_component.virtual_device_count); } /** * Get a virtual device for communication */ -static inline mca_btl_ugni_device_t *mca_btl_ugni_ep_get_device (mca_btl_ugni_module_t *ugni_module) +static inline mca_btl_ugni_device_t *mca_btl_ugni_ep_get_device(mca_btl_ugni_module_t *ugni_module) { - return ugni_module->devices + mca_btl_ugni_ep_get_device_index (ugni_module); + return ugni_module->devices + mca_btl_ugni_ep_get_device_index(ugni_module); } -static inline int mca_btl_rc_ugni_to_opal (gni_return_t rc) +static inline int mca_btl_rc_ugni_to_opal(gni_return_t rc) { static int codes[] = {OPAL_SUCCESS, OPAL_ERR_RESOURCE_BUSY, @@ -339,8 +337,7 @@ static inline int mca_btl_rc_ugni_to_opal (gni_return_t rc) return codes[rc]; } - -int mca_btl_ugni_flush (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); +int mca_btl_ugni_flush(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint); /** * BML->BTL notification of change in the process list. @@ -351,15 +348,13 @@ int mca_btl_ugni_flush (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint * @param nprocs (IN) Number of processes * @param procs (IN) Array of processes * @param endpoint (OUT) Array of mca_btl_base_endpoint_t structures by BTL. - * @param reachable (OUT) Bitmask indicating set of peer processes that are reachable by this BTL. + * @param reachable (OUT) Bitmask indicating set of peer processes that are reachable by this + * BTL. * @return OPAL_SUCCESS or error status on failure. */ -int -mca_btl_ugni_add_procs (struct mca_btl_base_module_t* btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers, - opal_bitmap_t *reachable); +int mca_btl_ugni_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable); /** * Notification of change to the process list. @@ -372,13 +367,11 @@ mca_btl_ugni_add_procs (struct mca_btl_base_module_t* btl, * @param peer (IN) Set of peer addressing information. * @return Status indicating if cleanup was successful */ -int -mca_btl_ugni_del_procs (struct mca_btl_base_module_t *btl, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers); +int mca_btl_ugni_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers); -struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep (struct mca_btl_base_module_t *module, opal_proc_t *proc); +struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep(struct mca_btl_base_module_t *module, + opal_proc_t *proc); /** * Initiate an asynchronous send. @@ -390,11 +383,8 @@ struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep (struct mca_btl_base_module_ * @param descriptor (IN) Description of the data to be transfered * @param tag (IN) The tag value used to notify the peer. */ -int -mca_btl_ugni_send (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *btl_peer, - struct mca_btl_base_descriptor_t *descriptor, - mca_btl_base_tag_t tag); +int mca_btl_ugni_send(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *btl_peer, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag); /** * Initiate an immediate blocking send. @@ -412,48 +402,50 @@ mca_btl_ugni_send (struct mca_btl_base_module_t *btl, * @param tag (IN) The tag value used to notify the peer. * @param descriptor (OUT) The descriptor to be returned unable to be sent immediately */ -int -mca_btl_ugni_sendi (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - void *header, size_t header_size, - size_t payload_size, uint8_t order, - uint32_t flags, mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t **descriptor); - -int mca_btl_ugni_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - -int mca_btl_ugni_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); - -int mca_btl_ugni_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, +int mca_btl_ugni_sendi(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor); + +int mca_btl_ugni_get(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); + +int mca_btl_ugni_put(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata); + +int mca_btl_ugni_aop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); + +int mca_btl_ugni_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); -int mca_btl_ugni_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); - -int mca_btl_ugni_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, - int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); +int mca_btl_ugni_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, + uint64_t value, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata); -int mca_btl_ugni_progress_send_wait_list (struct mca_btl_base_endpoint_t *endpoint); -int mca_btl_ugni_progress_datagram (mca_btl_ugni_device_t *device); +int mca_btl_ugni_progress_send_wait_list(struct mca_btl_base_endpoint_t *endpoint); +int mca_btl_ugni_progress_datagram(mca_btl_ugni_device_t *device); -mca_btl_base_descriptor_t * -mca_btl_ugni_alloc(struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags); +mca_btl_base_descriptor_t *mca_btl_ugni_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags); struct mca_btl_base_registration_handle_t { /** uGNI memory handle */ @@ -468,14 +460,14 @@ typedef struct mca_btl_ugni_reg_t { /** * Initialize uGNI support. */ -int mca_btl_ugni_init (void); +int mca_btl_ugni_init(void); /** * Finalize uGNI support. */ -int mca_btl_ugni_fini (void); +int mca_btl_ugni_fini(void); -int mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module); +int mca_btl_ugni_module_init(mca_btl_ugni_module_t *ugni_module); /** * Intialize a virtual device for device index 0. @@ -483,58 +475,61 @@ int mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module); * @param[inout] device Device to initialize * @param[in] virtual_device_id Virtual device identified (up to max handles) */ -int mca_btl_ugni_device_init (mca_btl_ugni_device_t *device, int virtual_device_id); +int mca_btl_ugni_device_init(mca_btl_ugni_device_t *device, int virtual_device_id); /** * Finalize a virtual device. * * @param[in] device Device to finalize */ -int mca_btl_ugni_device_fini (mca_btl_ugni_device_t *dev); +int mca_btl_ugni_device_fini(mca_btl_ugni_device_t *dev); /* Get a unique 64-bit id for the process name */ -static inline uint64_t mca_btl_ugni_proc_name_to_id (opal_process_name_t name) { +static inline uint64_t mca_btl_ugni_proc_name_to_id(opal_process_name_t name) +{ /* Throw away the top bit of the jobid for the datagram type */ - return ((uint64_t) (name.jobid & 0x7fffffff) << 32 | name.vpid); + return ((uint64_t)(name.jobid & 0x7fffffff) << 32 | name.vpid); } -int mca_btl_ugni_spawn_progress_thread(struct mca_btl_base_module_t* btl); +int mca_btl_ugni_spawn_progress_thread(struct mca_btl_base_module_t *btl); int mca_btl_ugni_kill_progress_thread(void); struct mca_btl_ugni_post_descriptor_t; -void btl_ugni_dump_post_desc (struct mca_btl_ugni_post_descriptor_t *desc); - +void btl_ugni_dump_post_desc(struct mca_btl_ugni_post_descriptor_t *desc); struct mca_btl_ugni_post_descriptor_t; -void mca_btl_ugni_handle_rdma_completions (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_device_t *device, - struct mca_btl_ugni_post_descriptor_t *post_desc, const int count); +void mca_btl_ugni_handle_rdma_completions(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_device_t *device, + struct mca_btl_ugni_post_descriptor_t *post_desc, + const int count); /** * Try to lock a uGNI device for exclusive access */ -static inline int mca_btl_ugni_device_trylock (mca_btl_ugni_device_t *device) +static inline int mca_btl_ugni_device_trylock(mca_btl_ugni_device_t *device) { /* checking the lock non-atomically first can reduce the number of * unnecessary atomic operations. */ - return (device->lock || opal_atomic_swap_32 (&device->lock, 1)); + return (device->lock || opal_atomic_swap_32(&device->lock, 1)); } /** * Lock a uGNI device for exclusive access */ -static inline void mca_btl_ugni_device_lock (mca_btl_ugni_device_t *device) +static inline void mca_btl_ugni_device_lock(mca_btl_ugni_device_t *device) { - while (mca_btl_ugni_device_trylock (device)); + while (mca_btl_ugni_device_trylock(device)) + ; } /** * Release exclusive access to the device */ -static inline void mca_btl_ugni_device_unlock (mca_btl_ugni_device_t *device) +static inline void mca_btl_ugni_device_unlock(mca_btl_ugni_device_t *device) { - opal_atomic_wmb (); + opal_atomic_wmb(); device->lock = 0; } @@ -545,54 +540,57 @@ static inline void mca_btl_ugni_device_unlock (mca_btl_ugni_device_t *device) * @params[in] fn function to serialize * @params[in] arg function argument */ -static inline intptr_t mca_btl_ugni_device_serialize (mca_btl_ugni_device_t *device, - mca_btl_ugni_device_serialize_fn_t fn, void *arg) +static inline intptr_t mca_btl_ugni_device_serialize(mca_btl_ugni_device_t *device, + mca_btl_ugni_device_serialize_fn_t fn, + void *arg) { intptr_t rc; - if (!opal_using_threads ()) { - return fn (device, arg); + if (!opal_using_threads()) { + return fn(device, arg); } - /* NTH: for now the device is just protected by a spin lock but this will change in the future */ - mca_btl_ugni_device_lock (device); - rc = fn (device, arg); - mca_btl_ugni_device_unlock (device); + /* NTH: for now the device is just protected by a spin lock but this will change in the future + */ + mca_btl_ugni_device_lock(device); + rc = fn(device, arg); + mca_btl_ugni_device_unlock(device); return rc; } -static inline intptr_t mca_btl_ugni_device_serialize_any (mca_btl_ugni_module_t *ugni_module, - mca_btl_ugni_device_serialize_fn_t fn, void *arg) +static inline intptr_t mca_btl_ugni_device_serialize_any(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_device_serialize_fn_t fn, + void *arg) { mca_btl_ugni_device_t *device; intptr_t rc; - if (!opal_using_threads ()) { - return fn (ugni_module->devices, arg); + if (!opal_using_threads()) { + return fn(ugni_module->devices, arg); } #if OPAL_C_HAVE__THREAD_LOCAL if (mca_btl_ugni_component.bind_threads_to_devices) { - /* NTH: if we have C11 _Thread_local just go ahead and assign the devices round-robin to each - * thread. in testing this give much better performance than just picking any device */ + /* NTH: if we have C11 _Thread_local just go ahead and assign the devices round-robin to + * each thread. in testing this give much better performance than just picking any device */ static _Thread_local mca_btl_ugni_device_t *device_local = NULL; device = device_local; if (OPAL_UNLIKELY(NULL == device)) { /* assign device contexts round-robin */ - device_local = device = mca_btl_ugni_ep_get_device (ugni_module); + device_local = device = mca_btl_ugni_ep_get_device(ugni_module); } - mca_btl_ugni_device_lock (device); + mca_btl_ugni_device_lock(device); } else { #endif /* get the next starting index */ - uint32_t device_index = mca_btl_ugni_ep_get_device_index (ugni_module); + uint32_t device_index = mca_btl_ugni_ep_get_device_index(ugni_module); const int device_count = mca_btl_ugni_component.virtual_device_count; - for (int i = 0 ; i < device_count ; ++i) { + for (int i = 0; i < device_count; ++i) { device = ugni_module->devices + ((device_index + i) % device_count); - if (!mca_btl_ugni_device_trylock (device)) { + if (!mca_btl_ugni_device_trylock(device)) { break; } @@ -600,20 +598,19 @@ static inline intptr_t mca_btl_ugni_device_serialize_any (mca_btl_ugni_module_t } if (NULL == device) { - device = mca_btl_ugni_ep_get_device (ugni_module); - mca_btl_ugni_device_lock (device); + device = mca_btl_ugni_ep_get_device(ugni_module); + mca_btl_ugni_device_lock(device); } #if OPAL_C_HAVE__THREAD_LOCAL } #endif - rc = fn (device, arg); - mca_btl_ugni_device_unlock (device); + rc = fn(device, arg); + mca_btl_ugni_device_unlock(device); return rc; } - /** Number of times the progress thread has woken up */ extern unsigned int mca_btl_ugni_progress_thread_wakeups; diff --git a/opal/mca/btl/ugni/btl_ugni_add_procs.c b/opal/mca/btl/ugni/btl_ugni_add_procs.c index 664271c17a2..ccf89a60b05 100644 --- a/opal/mca/btl/ugni/btl_ugni_add_procs.c +++ b/opal/mca/btl/ugni/btl_ugni_add_procs.c @@ -23,16 +23,14 @@ #define INITIAL_GNI_EPS 1024 -static int -mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module); -static void -mca_btl_ugni_module_set_max_reg (mca_btl_ugni_module_t *ugni_module, int nlocal_procs); -static int mca_btl_ugni_smsg_setup (int nprocs); - -int mca_btl_ugni_add_procs (struct mca_btl_base_module_t* btl, size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers, - opal_bitmap_t *reachable) { +static int mca_btl_ugni_setup_mpools(mca_btl_ugni_module_t *ugni_module); +static void mca_btl_ugni_module_set_max_reg(mca_btl_ugni_module_t *ugni_module, int nlocal_procs); +static int mca_btl_ugni_smsg_setup(int nprocs); + +int mca_btl_ugni_add_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers, + opal_bitmap_t *reachable) +{ mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; int rc; void *mmap_start_addr; @@ -42,91 +40,92 @@ int mca_btl_ugni_add_procs (struct mca_btl_base_module_t* btl, size_t nprocs, /* TODO: need to think of something more elegant than this max array */ - rc = opal_pointer_array_init (&ugni_module->endpoints, INITIAL_GNI_EPS, 1 << 24, 512); + rc = opal_pointer_array_init(&ugni_module->endpoints, INITIAL_GNI_EPS, 1 << 24, 512); if (OPAL_SUCCESS != rc) { BTL_ERROR(("error inializing the endpoint array. rc = %d", rc)); return rc; } - /* NTH: might want to vary this size based off the universe size (if * one exists). the table is only used for connection lookup and * endpoint removal. */ - rc = opal_hash_table_init (&ugni_module->id_to_endpoint, INITIAL_GNI_EPS); + rc = opal_hash_table_init(&ugni_module->id_to_endpoint, INITIAL_GNI_EPS); if (OPAL_SUCCESS != rc) { BTL_ERROR(("error initializing the endpoint hash. rc = %d", rc)); return rc; } } - for (size_t i = 0 ; i < nprocs ; ++i) { - peers[i] = mca_btl_ugni_get_ep (btl, procs[i]); + for (size_t i = 0; i < nprocs; ++i) { + peers[i] = mca_btl_ugni_get_ep(btl, procs[i]); if (NULL == peers[i]) { continue; } - if (procs[i] == opal_proc_local_get ()) { + if (procs[i] == opal_proc_local_get()) { ugni_module->local_ep = peers[i]; } /* Set the reachable bit if necessary */ if (reachable) { - (void) opal_bitmap_set_bit (reachable, i); + (void) opal_bitmap_set_bit(reachable, i); } } - mca_btl_ugni_module_set_max_reg (ugni_module, ugni_module->nlocal_procs); + mca_btl_ugni_module_set_max_reg(ugni_module, ugni_module->nlocal_procs); if (false == ugni_module->initialized) { - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { mca_btl_ugni_device_t *device = ugni_module->devices + i; - rc = GNI_CqCreate (device->dev_handle, mca_btl_ugni_component.local_rdma_cq_size, 0, - GNI_CQ_NOBLOCK, NULL, NULL, &device->dev_rdma_local_cq.gni_handle); + rc = GNI_CqCreate(device->dev_handle, mca_btl_ugni_component.local_rdma_cq_size, 0, + GNI_CQ_NOBLOCK, NULL, NULL, &device->dev_rdma_local_cq.gni_handle); if (GNI_RC_SUCCESS != rc) { BTL_ERROR(("error creating local BTE/FMA CQ")); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } - rc = GNI_CqCreate (device->dev_handle, mca_btl_ugni_component.local_cq_size, - 0, GNI_CQ_NOBLOCK, NULL, NULL, &device->dev_smsg_local_cq.gni_handle); + rc = GNI_CqCreate(device->dev_handle, mca_btl_ugni_component.local_cq_size, 0, + GNI_CQ_NOBLOCK, NULL, NULL, &device->dev_smsg_local_cq.gni_handle); if (GNI_RC_SUCCESS != rc) { BTL_ERROR(("error creating local SMSG CQ")); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } if (mca_btl_ugni_component.progress_thread_enabled) { - rc = GNI_CqCreate (device->dev_handle, mca_btl_ugni_component.local_rdma_cq_size, - 0, GNI_CQ_BLOCKING, NULL, NULL, &device->dev_rdma_local_irq_cq.gni_handle); + rc = GNI_CqCreate(device->dev_handle, mca_btl_ugni_component.local_rdma_cq_size, 0, + GNI_CQ_BLOCKING, NULL, NULL, + &device->dev_rdma_local_irq_cq.gni_handle); if (GNI_RC_SUCCESS != rc) { BTL_ERROR(("error creating local BTE/FMA CQ")); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } } } - rc = GNI_CqCreate (ugni_module->devices[0].dev_handle, mca_btl_ugni_component.remote_cq_size, - 0, GNI_CQ_NOBLOCK, NULL, NULL, &ugni_module->smsg_remote_cq); + rc = GNI_CqCreate(ugni_module->devices[0].dev_handle, mca_btl_ugni_component.remote_cq_size, + 0, GNI_CQ_NOBLOCK, NULL, NULL, &ugni_module->smsg_remote_cq); if (GNI_RC_SUCCESS != rc) { BTL_ERROR(("error creating remote SMSG CQ")); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } if (mca_btl_ugni_component.progress_thread_enabled) { - rc = GNI_CqCreate (ugni_module->devices[0].dev_handle, mca_btl_ugni_component.remote_cq_size, - 0, GNI_CQ_BLOCKING, NULL, NULL, &ugni_module->smsg_remote_irq_cq); + rc = GNI_CqCreate(ugni_module->devices[0].dev_handle, + mca_btl_ugni_component.remote_cq_size, 0, GNI_CQ_BLOCKING, NULL, NULL, + &ugni_module->smsg_remote_irq_cq); if (GNI_RC_SUCCESS != rc) { BTL_ERROR(("error creating remote SMSG CQ")); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } } - rc = mca_btl_ugni_setup_mpools (ugni_module); + rc = mca_btl_ugni_setup_mpools(ugni_module); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("btl/ugni error setting up mpools/free lists")); return rc; } - rc = mca_btl_ugni_smsg_init (ugni_module); + rc = mca_btl_ugni_smsg_init(ugni_module); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("btl/ugni error initializing SMSG")); return rc; @@ -141,24 +140,22 @@ int mca_btl_ugni_add_procs (struct mca_btl_base_module_t* btl, size_t nprocs, * thread in the target rank to become schedulable. */ if (mca_btl_ugni_component.progress_thread_enabled) { - mmap_start_addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + mmap_start_addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, + -1, 0); if (NULL == mmap_start_addr) { BTL_ERROR(("btl/ugni mmap returned error")); return OPAL_ERR_OUT_OF_RESOURCE; } rc = GNI_MemRegister(ugni_module->devices[0].dev_handle, - (unsigned long)mmap_start_addr, - 4096, - ugni_module->smsg_remote_irq_cq, - GNI_MEM_READWRITE, - -1, - &ugni_module->devices[0].smsg_irq_mhndl); + (unsigned long) mmap_start_addr, 4096, + ugni_module->smsg_remote_irq_cq, GNI_MEM_READWRITE, -1, + &ugni_module->devices[0].smsg_irq_mhndl); mca_btl_ugni_spawn_progress_thread(btl); } - opal_event_evtimer_add (&ugni_module->connection_event, &tv); + opal_event_evtimer_add(&ugni_module->connection_event, &tv); ugni_module->initialized = true; } @@ -166,25 +163,27 @@ int mca_btl_ugni_add_procs (struct mca_btl_base_module_t* btl, size_t nprocs, return OPAL_SUCCESS; } -int mca_btl_ugni_del_procs (struct mca_btl_base_module_t *btl, - size_t nprocs, struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers) { +int mca_btl_ugni_del_procs(struct mca_btl_base_module_t *btl, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers) +{ mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; OPAL_THREAD_LOCK(&ugni_module->endpoint_lock); - for (size_t i = 0 ; i < nprocs ; ++i) { + for (size_t i = 0; i < nprocs; ++i) { struct opal_proc_t *opal_proc = procs[i]; uint64_t proc_id = mca_btl_ugni_proc_name_to_id(opal_proc->proc_name); mca_btl_base_endpoint_t *ep = NULL; /* lookup this proc in the hash table */ - (void) opal_hash_table_get_value_uint64 (&ugni_module->id_to_endpoint, proc_id, (void **) &ep); + (void) opal_hash_table_get_value_uint64(&ugni_module->id_to_endpoint, proc_id, + (void **) &ep); - BTL_VERBOSE(("deleting endpoint with proc id 0x%" PRIx64 ", ptr: %p", proc_id, (void *) ep)); + BTL_VERBOSE( + ("deleting endpoint with proc id 0x%" PRIx64 ", ptr: %p", proc_id, (void *) ep)); if (NULL != ep) { - mca_btl_ugni_release_ep (ep); + mca_btl_ugni_release_ep(ep); --ugni_module->endpoint_count; } @@ -193,18 +192,18 @@ int mca_btl_ugni_del_procs (struct mca_btl_base_module_t *btl, } /* remote the endpoint from the hash table */ - opal_hash_table_set_value_uint64 (&ugni_module->id_to_endpoint, proc_id, NULL); + opal_hash_table_set_value_uint64(&ugni_module->id_to_endpoint, proc_id, NULL); } OPAL_THREAD_UNLOCK(&ugni_module->endpoint_lock); - mca_btl_ugni_module_set_max_reg (ugni_module, ugni_module->nlocal_procs); + mca_btl_ugni_module_set_max_reg(ugni_module, ugni_module->nlocal_procs); return OPAL_SUCCESS; } - -struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep (struct mca_btl_base_module_t *module, opal_proc_t *proc) +struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep(struct mca_btl_base_module_t *module, + opal_proc_t *proc) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) module; uint64_t proc_id = mca_btl_ugni_proc_name_to_id(proc->proc_name); @@ -214,16 +213,18 @@ struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep (struct mca_btl_base_module_ OPAL_THREAD_LOCK(&ugni_module->endpoint_lock); do { - rc = opal_hash_table_get_value_uint64 (&ugni_module->id_to_endpoint, proc_id, (void **) &ep); + rc = opal_hash_table_get_value_uint64(&ugni_module->id_to_endpoint, proc_id, (void **) &ep); if (OPAL_SUCCESS == rc) { - BTL_VERBOSE(("returning existing endpoint for proc %s", OPAL_NAME_PRINT(proc->proc_name))); + BTL_VERBOSE( + ("returning existing endpoint for proc %s", OPAL_NAME_PRINT(proc->proc_name))); break; } - BTL_VERBOSE(("initialized uGNI endpoint for proc id: 0x%" PRIx64 " ptr: %p", proc_id, (void *) proc)); + BTL_VERBOSE(("initialized uGNI endpoint for proc id: 0x%" PRIx64 " ptr: %p", proc_id, + (void *) proc)); /* Create and Init endpoints */ - rc = mca_btl_ugni_init_ep (ugni_module, &ep, ugni_module, proc); + rc = mca_btl_ugni_init_ep(ugni_module, &ep, ugni_module, proc); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("btl/ugni error initializing endpoint")); break; @@ -236,7 +237,7 @@ struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep (struct mca_btl_base_module_ ++ugni_module->endpoint_count; /* add this endpoint to the connection lookup table */ - opal_hash_table_set_value_uint64 (&ugni_module->id_to_endpoint, proc_id, ep); + opal_hash_table_set_value_uint64(&ugni_module->id_to_endpoint, proc_id, ep); } while (0); OPAL_THREAD_UNLOCK(&ugni_module->endpoint_lock); @@ -244,9 +245,8 @@ struct mca_btl_base_endpoint_t *mca_btl_ugni_get_ep (struct mca_btl_base_module_ return ep; } - -static int ugni_reg_mem (void *reg_data, void *base, size_t size, - mca_rcache_base_registration_t *reg) +static int ugni_reg_mem(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) reg_data; gni_cq_handle_t cq = 0; @@ -256,8 +256,9 @@ static int ugni_reg_mem (void *reg_data, void *base, size_t size, return OPAL_ERR_OUT_OF_RESOURCE; } - if (reg->access_flags & (MCA_RCACHE_ACCESS_REMOTE_WRITE | MCA_RCACHE_ACCESS_LOCAL_WRITE | - MCA_RCACHE_ACCESS_REMOTE_ATOMIC)) { + if (reg->access_flags + & (MCA_RCACHE_ACCESS_REMOTE_WRITE | MCA_RCACHE_ACCESS_LOCAL_WRITE + | MCA_RCACHE_ACCESS_REMOTE_ATOMIC)) { flags = GNI_MEM_READWRITE; } else { flags = GNI_MEM_READ_ONLY; @@ -271,30 +272,28 @@ static int ugni_reg_mem (void *reg_data, void *base, size_t size, cq = ugni_module->smsg_remote_cq; } - rc = mca_btl_ugni_reg_mem (ugni_module, base, size, (mca_btl_ugni_reg_t *) reg, cq, flags); + rc = mca_btl_ugni_reg_mem(ugni_module, base, size, (mca_btl_ugni_reg_t *) reg, cq, flags); if (OPAL_LIKELY(OPAL_SUCCESS == rc)) { - opal_atomic_add_fetch_32(&ugni_module->reg_count,1); + opal_atomic_add_fetch_32(&ugni_module->reg_count, 1); } return rc; } -static int -ugni_dereg_mem (void *reg_data, mca_rcache_base_registration_t *reg) +static int ugni_dereg_mem(void *reg_data, mca_rcache_base_registration_t *reg) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) reg_data; int rc; - rc = mca_btl_ugni_dereg_mem (ugni_module, (mca_btl_ugni_reg_t *) reg); + rc = mca_btl_ugni_dereg_mem(ugni_module, (mca_btl_ugni_reg_t *) reg); if (OPAL_LIKELY(OPAL_SUCCESS == rc)) { - opal_atomic_add_fetch_32(&ugni_module->reg_count,-1); + opal_atomic_add_fetch_32(&ugni_module->reg_count, -1); } return rc; } -static int -mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module) +static int mca_btl_ugni_setup_mpools(mca_btl_ugni_module_t *ugni_module) { mca_rcache_udreg_resources_t rcache_resources; unsigned int mbox_increment; @@ -302,82 +301,78 @@ mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module) char *rcache_name; int rc; - rc = opal_pointer_array_init (&ugni_module->pending_smsg_frags_bb, 0, - 1 << 30, 32768); + rc = opal_pointer_array_init(&ugni_module->pending_smsg_frags_bb, 0, 1 << 30, 32768); if (OPAL_SUCCESS != rc) { return rc; } /* determine how many procs are in the job (might want to check universe size here) */ u32 = &nprocs; - OPAL_MODEX_RECV_VALUE(rc, PMIX_UNIV_SIZE, &OPAL_PROC_MY_NAME, - &u32, PMIX_UINT32); + OPAL_MODEX_RECV_VALUE(rc, PMIX_UNIV_SIZE, &OPAL_PROC_MY_NAME, &u32, PMIX_UINT32); if (OPAL_SUCCESS != rc) { /* take a wild conservative guess */ nprocs = 512; } - rc = mca_btl_ugni_smsg_setup (nprocs); + rc = mca_btl_ugni_smsg_setup(nprocs); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error setting up smsg")); return rc; } - rc = opal_free_list_init (ugni_module->frags_lists + MCA_BTL_UGNI_LIST_SMSG, - sizeof (mca_btl_ugni_smsg_frag_t), - opal_cache_line_size, OBJ_CLASS(mca_btl_ugni_smsg_frag_t), - mca_btl_ugni_component.ugni_smsg_limit, - opal_cache_line_size, - mca_btl_ugni_component.ugni_free_list_num, - mca_btl_ugni_component.ugni_free_list_max, - mca_btl_ugni_component.ugni_free_list_inc, - NULL, 0, NULL, (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, - (void *) (intptr_t) MCA_BTL_UGNI_LIST_SMSG); + rc = opal_free_list_init(ugni_module->frags_lists + MCA_BTL_UGNI_LIST_SMSG, + sizeof(mca_btl_ugni_smsg_frag_t), opal_cache_line_size, + OBJ_CLASS(mca_btl_ugni_smsg_frag_t), + mca_btl_ugni_component.ugni_smsg_limit, opal_cache_line_size, + mca_btl_ugni_component.ugni_free_list_num, + mca_btl_ugni_component.ugni_free_list_max, + mca_btl_ugni_component.ugni_free_list_inc, NULL, 0, NULL, + (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, + (void *) (intptr_t) MCA_BTL_UGNI_LIST_SMSG); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error creating smsg fragment free list")); return rc; } - rc = opal_free_list_init (ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA, - sizeof (mca_btl_ugni_rdma_frag_t), 64, - OBJ_CLASS(mca_btl_ugni_rdma_frag_t), - 0, opal_cache_line_size, - mca_btl_ugni_component.ugni_free_list_num, - mca_btl_ugni_component.ugni_free_list_max, - mca_btl_ugni_component.ugni_free_list_inc, - NULL, 0, NULL, (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, - (void *) (intptr_t) MCA_BTL_UGNI_LIST_RDMA); + rc = opal_free_list_init(ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA, + sizeof(mca_btl_ugni_rdma_frag_t), 64, + OBJ_CLASS(mca_btl_ugni_rdma_frag_t), 0, opal_cache_line_size, + mca_btl_ugni_component.ugni_free_list_num, + mca_btl_ugni_component.ugni_free_list_max, + mca_btl_ugni_component.ugni_free_list_inc, NULL, 0, NULL, + (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, + (void *) (intptr_t) MCA_BTL_UGNI_LIST_RDMA); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return rc; } - rc = opal_free_list_init (ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA_INT, - sizeof (mca_btl_ugni_rdma_frag_t), 8, - OBJ_CLASS(mca_btl_ugni_rdma_frag_t), - 0, opal_cache_line_size, 0, -1, 64, - NULL, 0, NULL, (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, - (void *) (intptr_t) MCA_BTL_UGNI_LIST_RDMA_INT); + rc = opal_free_list_init(ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA_INT, + sizeof(mca_btl_ugni_rdma_frag_t), 8, + OBJ_CLASS(mca_btl_ugni_rdma_frag_t), 0, opal_cache_line_size, 0, -1, + 64, NULL, 0, NULL, + (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, + (void *) (intptr_t) MCA_BTL_UGNI_LIST_RDMA_INT); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return rc; } - ugni_module->super.btl_mpool = mca_mpool_base_module_lookup (mca_btl_ugni_component.mpool_hints); + ugni_module->super.btl_mpool = mca_mpool_base_module_lookup(mca_btl_ugni_component.mpool_hints); if (NULL == ugni_module->super.btl_mpool) { BTL_ERROR(("could not find mpool matching hints %s", mca_btl_ugni_component.mpool_hints)); return OPAL_ERROR; } - rcache_resources.base.cache_name = "ompi.ugni"; - rcache_resources.base.reg_data = (void *) ugni_module; - rcache_resources.base.sizeof_reg = sizeof (mca_btl_ugni_reg_t); - rcache_resources.base.register_mem = ugni_reg_mem; + rcache_resources.base.cache_name = "ompi.ugni"; + rcache_resources.base.reg_data = (void *) ugni_module; + rcache_resources.base.sizeof_reg = sizeof(mca_btl_ugni_reg_t); + rcache_resources.base.register_mem = ugni_reg_mem; rcache_resources.base.deregister_mem = ugni_dereg_mem; if (MCA_BTL_UGNI_RCACHE_UDREG == mca_btl_ugni_component.rcache_type) { /* additional settings for the udreg mpool */ /* 4k should be large enough for any Gemini/Ares system */ - rcache_resources.max_entries = 4096; - rcache_resources.use_kernel_cache = true; + rcache_resources.max_entries = 4096; + rcache_resources.use_kernel_cache = true; rcache_resources.use_evict_w_unreg = false; rcache_name = "udreg"; @@ -385,39 +380,39 @@ mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module) rcache_name = "grdma"; } - ugni_module->rcache = - mca_rcache_base_module_create (rcache_name, ugni_module->devices, &rcache_resources.base); + ugni_module->rcache = mca_rcache_base_module_create(rcache_name, ugni_module->devices, + &rcache_resources.base); if (NULL == ugni_module->rcache) { BTL_ERROR(("error creating registration cache")); return OPAL_ERROR; } - rc = opal_free_list_init (ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_SEND, - sizeof (mca_btl_ugni_eager_frag_t), 8, - OBJ_CLASS(mca_btl_ugni_eager_frag_t), - ugni_module->super.btl_eager_limit, 64, - mca_btl_ugni_component.ugni_eager_num, - mca_btl_ugni_component.ugni_eager_max, - mca_btl_ugni_component.ugni_eager_inc, - ugni_module->super.btl_mpool, 0, ugni_module->rcache, - (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, - (void *) (intptr_t) MCA_BTL_UGNI_LIST_EAGER_SEND); + rc = opal_free_list_init(ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_SEND, + sizeof(mca_btl_ugni_eager_frag_t), 8, + OBJ_CLASS(mca_btl_ugni_eager_frag_t), + ugni_module->super.btl_eager_limit, 64, + mca_btl_ugni_component.ugni_eager_num, + mca_btl_ugni_component.ugni_eager_max, + mca_btl_ugni_component.ugni_eager_inc, ugni_module->super.btl_mpool, 0, + ugni_module->rcache, + (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, + (void *) (intptr_t) MCA_BTL_UGNI_LIST_EAGER_SEND); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error creating eager send fragment free list")); return rc; } - rc = opal_free_list_init (ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_RECV, - sizeof (mca_btl_ugni_eager_frag_t), 8, - OBJ_CLASS(mca_btl_ugni_eager_frag_t), - ugni_module->super.btl_eager_limit, 64, - mca_btl_ugni_component.ugni_eager_num, - mca_btl_ugni_component.ugni_eager_max, - mca_btl_ugni_component.ugni_eager_inc, - ugni_module->super.btl_mpool, 0, ugni_module->rcache, - (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, - (void *) (intptr_t) MCA_BTL_UGNI_LIST_EAGER_RECV); + rc = opal_free_list_init(ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_RECV, + sizeof(mca_btl_ugni_eager_frag_t), 8, + OBJ_CLASS(mca_btl_ugni_eager_frag_t), + ugni_module->super.btl_eager_limit, 64, + mca_btl_ugni_component.ugni_eager_num, + mca_btl_ugni_component.ugni_eager_max, + mca_btl_ugni_component.ugni_eager_inc, ugni_module->super.btl_mpool, 0, + ugni_module->rcache, + (opal_free_list_item_init_fn_t) mca_btl_ugni_frag_init, + (void *) (intptr_t) MCA_BTL_UGNI_LIST_EAGER_RECV); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error creating eager receive fragment free list")); return rc; @@ -426,10 +421,10 @@ mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module) if (0 == mca_btl_ugni_component.mbox_increment) { /* limit mailbox allocations to either 12.5% of available registrations or 2MiB per allocation */ - mbox_increment = (unsigned int) (2097152.0 / (float)mca_btl_ugni_component.smsg_mbox_size); + mbox_increment = (unsigned int) (2097152.0 / (float) mca_btl_ugni_component.smsg_mbox_size); /* we may end up using more */ - if (nprocs/mbox_increment > (unsigned int) ugni_module->reg_max / 8) { + if (nprocs / mbox_increment > (unsigned int) ugni_module->reg_max / 8) { mbox_increment = nprocs / (ugni_module->reg_max >> 3); } } else { @@ -437,13 +432,12 @@ mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module) } /* use the MCA_RCACHE_FLAGS_RESV0 to signal this is smsg memory */ - rc = opal_free_list_init (&ugni_module->smsg_mboxes, - sizeof (mca_btl_ugni_smsg_mbox_t), 8, - OBJ_CLASS(mca_btl_ugni_smsg_mbox_t), - mca_btl_ugni_component.smsg_mbox_size, 128, - 32, -1, mbox_increment, ugni_module->super.btl_mpool, - MCA_RCACHE_FLAGS_SO_MEM | MCA_RCACHE_FLAGS_RESV0, - ugni_module->rcache, NULL, NULL); + rc = opal_free_list_init(&ugni_module->smsg_mboxes, sizeof(mca_btl_ugni_smsg_mbox_t), 8, + OBJ_CLASS(mca_btl_ugni_smsg_mbox_t), + mca_btl_ugni_component.smsg_mbox_size, 128, 32, -1, mbox_increment, + ugni_module->super.btl_mpool, + MCA_RCACHE_FLAGS_SO_MEM | MCA_RCACHE_FLAGS_RESV0, ugni_module->rcache, + NULL, NULL); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error creating smsg mailbox free list")); return rc; @@ -452,8 +446,7 @@ mca_btl_ugni_setup_mpools (mca_btl_ugni_module_t *ugni_module) return OPAL_SUCCESS; } -static void -mca_btl_ugni_module_set_max_reg (mca_btl_ugni_module_t *ugni_module, int nlocal_procs) +static void mca_btl_ugni_module_set_max_reg(mca_btl_ugni_module_t *ugni_module, int nlocal_procs) { if (0 == mca_btl_ugni_component.max_mem_reg) { #if defined(HAVE_GNI_GETJOBRESINFO) @@ -461,8 +454,7 @@ mca_btl_ugni_module_set_max_reg (mca_btl_ugni_module_t *ugni_module, int nlocal_ gni_return_t grc; int fuzz = 20; - grc = GNI_GetJobResInfo (0, mca_btl_ugni_component.ptag, - GNI_JOB_RES_MDD, &res_des); + grc = GNI_GetJobResInfo(0, mca_btl_ugni_component.ptag, GNI_JOB_RES_MDD, &res_des); if (GNI_RC_SUCCESS == grc) { if (nlocal_procs) { ugni_module->reg_max = (res_des.limit - fuzz) / nlocal_procs; @@ -487,7 +479,7 @@ mca_btl_ugni_module_set_max_reg (mca_btl_ugni_module_t *ugni_module, int nlocal_ ugni_module->reg_count = 0; } -static int mca_btl_ugni_smsg_setup (int nprocs) +static int mca_btl_ugni_smsg_setup(int nprocs) { gni_smsg_attr_t tmp_smsg_attrib; unsigned int mbox_size; @@ -508,22 +500,22 @@ static int mca_btl_ugni_smsg_setup (int nprocs) } } - mca_btl_ugni_component.smsg_max_data = mca_btl_ugni_component.ugni_smsg_limit - - sizeof (mca_btl_ugni_send_frag_hdr_t); + mca_btl_ugni_component.smsg_max_data = mca_btl_ugni_component.ugni_smsg_limit + - sizeof(mca_btl_ugni_send_frag_hdr_t); if (mca_btl_ugni_component.ugni_smsg_limit == mca_btl_ugni_module.super.btl_eager_limit) { mca_btl_ugni_module.super.btl_eager_limit = mca_btl_ugni_component.smsg_max_data; } /* calculate mailbox size */ - tmp_smsg_attrib.msg_type = GNI_SMSG_TYPE_MBOX_AUTO_RETRANSMIT; - tmp_smsg_attrib.msg_maxsize = mca_btl_ugni_component.ugni_smsg_limit; + tmp_smsg_attrib.msg_type = GNI_SMSG_TYPE_MBOX_AUTO_RETRANSMIT; + tmp_smsg_attrib.msg_maxsize = mca_btl_ugni_component.ugni_smsg_limit; tmp_smsg_attrib.mbox_maxcredit = mca_btl_ugni_component.smsg_max_credits; - grc = GNI_SmsgBufferSizeNeeded (&tmp_smsg_attrib, &mbox_size); + grc = GNI_SmsgBufferSizeNeeded(&tmp_smsg_attrib, &mbox_size); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != grc)) { BTL_ERROR(("error in GNI_SmsgBufferSizeNeeded")); - return mca_btl_rc_ugni_to_opal (grc); + return mca_btl_rc_ugni_to_opal(grc); } mca_btl_ugni_component.smsg_mbox_size = OPAL_ALIGN(mbox_size, 64, unsigned int); diff --git a/opal/mca/btl/ugni/btl_ugni_atomic.c b/opal/mca/btl/ugni/btl_ugni_atomic.c index a4396837e2c..5f7ed253676 100644 --- a/opal/mca/btl/ugni/btl_ugni_atomic.c +++ b/opal/mca/btl/ugni/btl_ugni_atomic.c @@ -16,71 +16,79 @@ #include "btl_ugni_rdma.h" static gni_fma_cmd_type_t amo_cmds[][MCA_BTL_ATOMIC_LAST] = { - [PMIX_INT32] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_IADD_S, - [MCA_BTL_ATOMIC_LAND] = GNI_FMA_ATOMIC2_AND_S, - [MCA_BTL_ATOMIC_LOR] = GNI_FMA_ATOMIC2_OR_S, - [MCA_BTL_ATOMIC_LXOR] = GNI_FMA_ATOMIC2_XOR_S, - [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_SWAP_S, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_IMIN_S, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_IMAX_S, - }, - [PMIX_INT64] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC_ADD, - [MCA_BTL_ATOMIC_AND] = GNI_FMA_ATOMIC_AND, - [MCA_BTL_ATOMIC_OR] = GNI_FMA_ATOMIC_OR, - [MCA_BTL_ATOMIC_XOR] = GNI_FMA_ATOMIC_XOR, - [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_SWAP, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_IMIN, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_IMAX, - }, - [PMIX_FLOAT] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FPADD_S, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FPMIN_S, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FPMAX_S, - }, - [PMIX_DOUBLE] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FPADD, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FPMIN, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FPMAX, - }, + [PMIX_INT32] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_IADD_S, + [MCA_BTL_ATOMIC_LAND] = GNI_FMA_ATOMIC2_AND_S, + [MCA_BTL_ATOMIC_LOR] = GNI_FMA_ATOMIC2_OR_S, + [MCA_BTL_ATOMIC_LXOR] = GNI_FMA_ATOMIC2_XOR_S, + [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_SWAP_S, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_IMIN_S, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_IMAX_S, + }, + [PMIX_INT64] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC_ADD, + [MCA_BTL_ATOMIC_AND] = GNI_FMA_ATOMIC_AND, + [MCA_BTL_ATOMIC_OR] = GNI_FMA_ATOMIC_OR, + [MCA_BTL_ATOMIC_XOR] = GNI_FMA_ATOMIC_XOR, + [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_SWAP, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_IMIN, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_IMAX, + }, + [PMIX_FLOAT] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FPADD_S, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FPMIN_S, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FPMAX_S, + }, + [PMIX_DOUBLE] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FPADD, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FPMIN, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FPMAX, + }, }; static gni_fma_cmd_type_t famo_cmds[][MCA_BTL_ATOMIC_LAST] = { - [PMIX_INT32] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FIADD_S, - [MCA_BTL_ATOMIC_LAND] = GNI_FMA_ATOMIC2_FAND_S, - [MCA_BTL_ATOMIC_LOR] = GNI_FMA_ATOMIC2_FOR_S, - [MCA_BTL_ATOMIC_LXOR] = GNI_FMA_ATOMIC2_FXOR_S, - [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_FSWAP_S, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FIMIN_S, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FIMAX_S, - }, - [PMIX_INT64] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC_FADD, - [MCA_BTL_ATOMIC_AND] = GNI_FMA_ATOMIC_FAND, - [MCA_BTL_ATOMIC_OR] = GNI_FMA_ATOMIC_FOR, - [MCA_BTL_ATOMIC_XOR] = GNI_FMA_ATOMIC_FXOR, - [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_FSWAP, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FIMIN, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FIMAX, - }, - [PMIX_FLOAT] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FFPADD_S, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FFPMIN_S, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FFPMAX_S, - }, - [PMIX_DOUBLE] = { - [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FFPADD, - [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FFPMIN, - [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FFPMAX, - }, + [PMIX_INT32] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FIADD_S, + [MCA_BTL_ATOMIC_LAND] = GNI_FMA_ATOMIC2_FAND_S, + [MCA_BTL_ATOMIC_LOR] = GNI_FMA_ATOMIC2_FOR_S, + [MCA_BTL_ATOMIC_LXOR] = GNI_FMA_ATOMIC2_FXOR_S, + [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_FSWAP_S, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FIMIN_S, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FIMAX_S, + }, + [PMIX_INT64] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC_FADD, + [MCA_BTL_ATOMIC_AND] = GNI_FMA_ATOMIC_FAND, + [MCA_BTL_ATOMIC_OR] = GNI_FMA_ATOMIC_FOR, + [MCA_BTL_ATOMIC_XOR] = GNI_FMA_ATOMIC_FXOR, + [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_FSWAP, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FIMIN, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FIMAX, + }, + [PMIX_FLOAT] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FFPADD_S, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FFPMIN_S, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FFPMAX_S, + }, + [PMIX_DOUBLE] = + { + [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FFPADD, + [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FFPMIN, + [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FFPMAX, + }, }; -int mca_btl_ugni_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, - mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ugni_aop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { gni_mem_handle_t dummy = {0, 0}; mca_btl_ugni_post_descriptor_t post_desc; @@ -99,20 +107,20 @@ int mca_btl_ugni_aop (struct mca_btl_base_module_t *btl, struct mca_btl_base_end return OPAL_ERR_NOT_SUPPORTED; } - init_post_desc (&post_desc, endpoint, order, GNI_POST_AMO, 0, dummy, remote_address, - remote_handle->gni_handle, size, 0, cbfunc, cbcontext, cbdata, - NULL); + init_post_desc(&post_desc, endpoint, order, GNI_POST_AMO, 0, dummy, remote_address, + remote_handle->gni_handle, size, 0, cbfunc, cbcontext, cbdata, NULL); post_desc.gni_desc.amo_cmd = gni_op; post_desc.gni_desc.first_operand = operand; - return mca_btl_ugni_endpoint_post_fma (endpoint, &post_desc); + return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc); } -int mca_btl_ugni_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op, - uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +int mca_btl_ugni_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, + mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { mca_btl_ugni_post_descriptor_t post_desc; int gni_op, type; @@ -130,19 +138,21 @@ int mca_btl_ugni_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_en return OPAL_ERR_NOT_SUPPORTED; } - init_post_desc (&post_desc, endpoint, order, GNI_POST_AMO, (intptr_t) local_address, - local_handle->gni_handle, remote_address, remote_handle->gni_handle, - size, 0, cbfunc, cbcontext, cbdata, local_handle); + init_post_desc(&post_desc, endpoint, order, GNI_POST_AMO, (intptr_t) local_address, + local_handle->gni_handle, remote_address, remote_handle->gni_handle, size, 0, + cbfunc, cbcontext, cbdata, local_handle); post_desc.gni_desc.amo_cmd = gni_op; post_desc.gni_desc.first_operand = operand; - return mca_btl_ugni_endpoint_post_fma (endpoint, &post_desc); + return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc); } -int mca_btl_ugni_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ugni_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, + uint64_t value, int flags, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { mca_btl_ugni_post_descriptor_t post_desc; size_t size; @@ -151,12 +161,12 @@ int mca_btl_ugni_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_ gni_op = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? GNI_FMA_ATOMIC2_FCSWAP_S : GNI_FMA_ATOMIC_CSWAP; size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8; - init_post_desc (&post_desc, endpoint, order, GNI_POST_AMO, (intptr_t) local_address, - local_handle->gni_handle, remote_address, remote_handle->gni_handle, size, 0, - cbfunc, cbcontext, cbdata, local_handle); + init_post_desc(&post_desc, endpoint, order, GNI_POST_AMO, (intptr_t) local_address, + local_handle->gni_handle, remote_address, remote_handle->gni_handle, size, 0, + cbfunc, cbcontext, cbdata, local_handle); post_desc.gni_desc.amo_cmd = gni_op; post_desc.gni_desc.first_operand = compare; post_desc.gni_desc.second_operand = value; - return mca_btl_ugni_endpoint_post_fma (endpoint, &post_desc); + return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc); } diff --git a/opal/mca/btl/ugni/btl_ugni_component.c b/opal/mca/btl/ugni/btl_ugni_component.c index a974f29f03b..b9441b51b0d 100644 --- a/opal/mca/btl/ugni/btl_ugni_component.c +++ b/opal/mca/btl/ugni/btl_ugni_component.c @@ -17,12 +17,12 @@ #include "btl_ugni_rdma.h" #include "btl_ugni_smsg.h" -#include "opal/util/sys_limits.h" #include "opal/util/printf.h" +#include "opal/util/sys_limits.h" -#include -#include #include +#include +#include #include "opal/memoryhooks/memory.h" #include "opal/runtime/opal_params.h" @@ -40,19 +40,17 @@ mca_btl_ugni_component_t mca_btl_ugni_component = { .super = { /* First, the mca_base_component_t struct containing meta information about the component itself */ - .btl_version = { - MCA_BTL_DEFAULT_VERSION("ugni"), - .mca_open_component = btl_ugni_component_open, - .mca_close_component = btl_ugni_component_close, - .mca_register_component_params = btl_ugni_component_register, - }, - .btl_data = { - .param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .btl_version = + { + MCA_BTL_DEFAULT_VERSION("ugni"), + .mca_open_component = btl_ugni_component_open, + .mca_close_component = btl_ugni_component_close, + .mca_register_component_params = btl_ugni_component_register, + }, + .btl_data = {.param_field = MCA_BASE_METADATA_PARAM_CHECKPOINT}, .btl_init = mca_btl_ugni_component_init, .btl_progress = mca_btl_ugni_component_progress, - } -}; + }}; mca_base_var_enum_value_t rcache_values[] = { {MCA_BTL_UGNI_RCACHE_UDREG, "udreg"}, @@ -60,39 +58,65 @@ mca_base_var_enum_value_t rcache_values[] = { {-1, NULL} /* sentinal */ }; -mca_base_var_enum_value_flag_t cdm_flags[] = { - {.flag = GNI_CDM_MODE_FORK_NOCOPY, .string = "fork-no-copy", .conflicting_flag = GNI_CDM_MODE_FORK_FULLCOPY | GNI_CDM_MODE_FORK_PARTCOPY}, - {.flag = GNI_CDM_MODE_FORK_FULLCOPY, .string = "fork-full-copy", .conflicting_flag = GNI_CDM_MODE_FORK_NOCOPY | GNI_CDM_MODE_FORK_PARTCOPY}, - {.flag = GNI_CDM_MODE_FORK_PARTCOPY, .string = "fork-part-copy", .conflicting_flag = GNI_CDM_MODE_FORK_NOCOPY | GNI_CDM_MODE_FORK_FULLCOPY}, - {.flag = GNI_CDM_MODE_ERR_NO_KILL, .string = "err-no-kill", .conflicting_flag = GNI_CDM_MODE_ERR_ALL_KILL}, - {.flag = GNI_CDM_MODE_ERR_ALL_KILL, .string = "err-all-kill", .conflicting_flag = GNI_CDM_MODE_ERR_NO_KILL}, - {.flag = GNI_CDM_MODE_FAST_DATAGRAM_POLL, .string = "fast-datagram-poll", .conflicting_flag = 0}, - {.flag = GNI_CDM_MODE_BTE_SINGLE_CHANNEL, .string = "bte-single-channel", .conflicting_flag = 0}, - {.flag = GNI_CDM_MODE_USE_PCI_IOMMU, .string = "use-pci-iommu", .conflicting_flag = 0}, - {.flag = GNI_CDM_MODE_MDD_DEDICATED, .string = "mdd-dedicated", .conflicting_flag = GNI_CDM_MODE_MDD_SHARED}, - {.flag = GNI_CDM_MODE_MDD_SHARED, .string = "mdd-shared", .conflicting_flag = GNI_CDM_MODE_MDD_DEDICATED}, - {.flag = GNI_CDM_MODE_FMA_DEDICATED, .string = "fma-dedicated", .conflicting_flag = GNI_CDM_MODE_FMA_SHARED}, - {.flag = GNI_CDM_MODE_FMA_SHARED, .string = "fma-shared", .conflicting_flag = GNI_CDM_MODE_FMA_DEDICATED}, - {.flag = GNI_CDM_MODE_CACHED_AMO_ENABLED, .string = "cached-amo-enabled", .conflicting_flag = 0}, - {.flag = GNI_CDM_MODE_CQ_NIC_LOCAL_PLACEMENT, .string = "cq-nic-placement", .conflicting_flag = 0}, - {.flag = GNI_CDM_MODE_FMA_SMALL_WINDOW, .string = "fma-small-window", .conflicting_flag = 0}, - {.string = NULL} -}; - -static inline int mca_btl_ugni_get_stat (const mca_base_pvar_t *pvar, void *value, void *obj) +mca_base_var_enum_value_flag_t cdm_flags[] + = {{.flag = GNI_CDM_MODE_FORK_NOCOPY, + .string = "fork-no-copy", + .conflicting_flag = GNI_CDM_MODE_FORK_FULLCOPY | GNI_CDM_MODE_FORK_PARTCOPY}, + {.flag = GNI_CDM_MODE_FORK_FULLCOPY, + .string = "fork-full-copy", + .conflicting_flag = GNI_CDM_MODE_FORK_NOCOPY | GNI_CDM_MODE_FORK_PARTCOPY}, + {.flag = GNI_CDM_MODE_FORK_PARTCOPY, + .string = "fork-part-copy", + .conflicting_flag = GNI_CDM_MODE_FORK_NOCOPY | GNI_CDM_MODE_FORK_FULLCOPY}, + {.flag = GNI_CDM_MODE_ERR_NO_KILL, + .string = "err-no-kill", + .conflicting_flag = GNI_CDM_MODE_ERR_ALL_KILL}, + {.flag = GNI_CDM_MODE_ERR_ALL_KILL, + .string = "err-all-kill", + .conflicting_flag = GNI_CDM_MODE_ERR_NO_KILL}, + {.flag = GNI_CDM_MODE_FAST_DATAGRAM_POLL, + .string = "fast-datagram-poll", + .conflicting_flag = 0}, + {.flag = GNI_CDM_MODE_BTE_SINGLE_CHANNEL, + .string = "bte-single-channel", + .conflicting_flag = 0}, + {.flag = GNI_CDM_MODE_USE_PCI_IOMMU, .string = "use-pci-iommu", .conflicting_flag = 0}, + {.flag = GNI_CDM_MODE_MDD_DEDICATED, + .string = "mdd-dedicated", + .conflicting_flag = GNI_CDM_MODE_MDD_SHARED}, + {.flag = GNI_CDM_MODE_MDD_SHARED, + .string = "mdd-shared", + .conflicting_flag = GNI_CDM_MODE_MDD_DEDICATED}, + {.flag = GNI_CDM_MODE_FMA_DEDICATED, + .string = "fma-dedicated", + .conflicting_flag = GNI_CDM_MODE_FMA_SHARED}, + {.flag = GNI_CDM_MODE_FMA_SHARED, + .string = "fma-shared", + .conflicting_flag = GNI_CDM_MODE_FMA_DEDICATED}, + {.flag = GNI_CDM_MODE_CACHED_AMO_ENABLED, + .string = "cached-amo-enabled", + .conflicting_flag = 0}, + {.flag = GNI_CDM_MODE_CQ_NIC_LOCAL_PLACEMENT, + .string = "cq-nic-placement", + .conflicting_flag = 0}, + {.flag = GNI_CDM_MODE_FMA_SMALL_WINDOW, .string = "fma-small-window", .conflicting_flag = 0}, + {.string = NULL}}; + +static inline int mca_btl_ugni_get_stat(const mca_base_pvar_t *pvar, void *value, void *obj) { - gni_statistic_t statistic = (gni_statistic_t) (intptr_t) pvar->ctx; + gni_statistic_t statistic = (gni_statistic_t)(intptr_t) pvar->ctx; gni_return_t rc = GNI_RC_SUCCESS; - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { - rc = GNI_GetNicStat (mca_btl_ugni_component.modules[0].devices[i].dev_handle, statistic, - ((unsigned int *) value) + i); + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { + rc = GNI_GetNicStat(mca_btl_ugni_component.modules[0].devices[i].dev_handle, statistic, + ((unsigned int *) value) + i); } - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } -static inline int mca_btl_ugni_notify_stat (mca_base_pvar_t *pvar, mca_base_pvar_event_t event, void *obj, int *count) +static inline int mca_btl_ugni_notify_stat(mca_base_pvar_t *pvar, mca_base_pvar_event_t event, + void *obj, int *count) { if (MCA_BASE_PVAR_HANDLE_BIND == event) { /* one value for each virtual device handle */ @@ -114,273 +138,295 @@ static int btl_ugni_component_register(void) mca_btl_ugni_component.ugni_free_list_num = 8; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "free_list_num", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, + "free_list_num", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_free_list_num); mca_btl_ugni_component.ugni_free_list_max = 4096; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "free_list_max", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, + "free_list_max", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_free_list_max); mca_btl_ugni_component.ugni_free_list_inc = 64; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "free_list_inc", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, + "free_list_inc", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_free_list_inc); mca_btl_ugni_component.ugni_eager_num = 16; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "eager_num", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "eager_num", + NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_eager_num); mca_btl_ugni_component.ugni_eager_max = 128; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "eager_max", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "eager_max", + NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_eager_max); mca_btl_ugni_component.ugni_eager_inc = 16; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "eager_inc", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "eager_inc", + NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_eager_inc); mca_btl_ugni_component.remote_cq_size = 40000; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "remote_cq_size", "Remote SMSG completion queue " - "size (default 40000)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + "remote_cq_size", + "Remote SMSG completion queue " + "size (default 40000)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.remote_cq_size); mca_btl_ugni_component.local_cq_size = 8192; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "local_cq_size", "Local SMSG completion queue size " - "(default 8k)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + "local_cq_size", + "Local SMSG completion queue size " + "(default 8k)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.local_cq_size); mca_btl_ugni_component.local_rdma_cq_size = 1024; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "local_rdma_cq_size", "Local FMA/RDMA completion queue size " - "(default: 1024)",MCA_BASE_VAR_TYPE_INT, NULL, 0, + "local_rdma_cq_size", + "Local FMA/RDMA completion queue size " + "(default: 1024)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.local_rdma_cq_size); mca_btl_ugni_component.ugni_smsg_limit = 0; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "smsg_limit", "Maximum size message that " + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "smsg_limit", + "Maximum size message that " "will be sent using the SMSG/MSGQ protocol " "(0 - autoselect(default), 16k max)", MCA_BASE_VAR_TYPE_INT, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_smsg_limit); mca_btl_ugni_component.smsg_max_credits = 32; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "smsg_max_credits", "Maximum number of " + "smsg_max_credits", + "Maximum number of " "outstanding SMSG/MSGQ message (default 32)", MCA_BASE_VAR_TYPE_INT, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.smsg_max_credits); #if OPAL_C_HAVE__THREAD_LOCAL mca_btl_ugni_component.bind_threads_to_devices = true; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "bind_devices", "Bind threads to virtual " + "bind_devices", + "Bind threads to virtual " "devices. In general this should improve " "RDMA performance (default: true)", MCA_BASE_VAR_TYPE_BOOL, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.bind_threads_to_devices); #endif mca_btl_ugni_component.ugni_fma_limit = -1; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "fma_limit", "Default maximum size message that " + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "fma_limit", + "Default maximum size message that " "will be sent using the FMA (Fast Memory " "Access) protocol (default: -1 (don't use), 64k max)", MCA_BASE_VAR_TYPE_LONG, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE | MCA_BASE_VAR_FLAG_DEPRECATED, + MCA_BASE_VAR_FLAG_SETTABLE + | MCA_BASE_VAR_FLAG_DEPRECATED, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_fma_limit); mca_btl_ugni_component.ugni_fma_get_limit = 2048; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "fma_get_limit", "Maximum size message that " + "fma_get_limit", + "Maximum size message that " "will be sent using the FMA (Fast Memory " "Access) protocol for get (default 2k, " "64k max)", MCA_BASE_VAR_TYPE_LONG, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_fma_get_limit); mca_btl_ugni_component.ugni_fma_put_limit = 4096; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "fma_put_limit", "Maximum size message that " + "fma_put_limit", + "Maximum size message that " "will be sent using the FMA (Fast Memory " "Access) protocol for put (default: 4k, " "64k max)", MCA_BASE_VAR_TYPE_LONG, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.ugni_fma_put_limit); mca_btl_ugni_component.rdma_max_retries = 16; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "rdma_max_retries", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + "rdma_max_retries", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.rdma_max_retries); mca_btl_ugni_component.smsg_max_retries = 16; (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "smsg_max_retries", NULL, MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + "smsg_max_retries", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.smsg_max_retries); mca_btl_ugni_component.max_mem_reg = 0; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "max_mem_reg", "Maximum number of " + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "max_mem_reg", + "Maximum number of " "memory registrations a process can " "hold (0 - autoselect, -1 - unlimited)" - " (default 0)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, + " (default 0)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.max_mem_reg); mca_btl_ugni_component.mbox_increment = 0; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "mbox_inc", "Number of SMSG mailboxes to " + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "mbox_inc", + "Number of SMSG mailboxes to " "allocate in each block (0 - autoselect(default))", MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.mbox_increment); + MCA_BASE_VAR_SCOPE_LOCAL, + &mca_btl_ugni_component.mbox_increment); /* communication domain flags */ - rc = mca_base_var_enum_create_flag ("btl_ugni_cdm_flags", cdm_flags, (mca_base_var_enum_flag_t **) &new_enum); + rc = mca_base_var_enum_create_flag("btl_ugni_cdm_flags", cdm_flags, + (mca_base_var_enum_flag_t **) &new_enum); if (OPAL_SUCCESS != rc) { return rc; } - mca_btl_ugni_component.cdm_flags = GNI_CDM_MODE_FORK_PARTCOPY | GNI_CDM_MODE_ERR_NO_KILL | GNI_CDM_MODE_FAST_DATAGRAM_POLL | - GNI_CDM_MODE_MDD_SHARED | GNI_CDM_MODE_FMA_SHARED | GNI_CDM_MODE_FMA_SMALL_WINDOW; - mca_btl_ugni_component.cdm_flags_id = mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "cdm_flags", "Flags to set when creating a communication domain " - " (default: fork-full-copy,cached-amo-enabled,err-no-kill,fast-datagram-poll," - "fma-shared,fma-small-window)", - MCA_BASE_VAR_TYPE_UNSIGNED_INT, new_enum, 0, - MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.cdm_flags); + mca_btl_ugni_component.cdm_flags = GNI_CDM_MODE_FORK_PARTCOPY | GNI_CDM_MODE_ERR_NO_KILL + | GNI_CDM_MODE_FAST_DATAGRAM_POLL | GNI_CDM_MODE_MDD_SHARED + | GNI_CDM_MODE_FMA_SHARED | GNI_CDM_MODE_FMA_SMALL_WINDOW; + mca_btl_ugni_component.cdm_flags_id = mca_base_component_var_register( + &mca_btl_ugni_component.super.btl_version, "cdm_flags", + "Flags to set when creating a communication domain " + " (default: fork-full-copy,cached-amo-enabled,err-no-kill,fast-datagram-poll," + "fma-shared,fma-small-window)", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, new_enum, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.cdm_flags); OBJ_RELEASE(new_enum); mca_btl_ugni_component.virtual_device_count = 0; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "virtual_device_count", "Number of virtual devices to create. Higher numbers may " - "result in better performance when using threads. (default: 0 (auto), max: 128)", - MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.virtual_device_count); + (void) mca_base_component_var_register( + &mca_btl_ugni_component.super.btl_version, "virtual_device_count", + "Number of virtual devices to create. Higher numbers may " + "result in better performance when using threads. (default: 0 (auto), max: 128)", + MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.virtual_device_count); /* determine if there are get alignment restrictions */ - GNI_GetDeviceType (&device_type); - + GNI_GetDeviceType(&device_type); mca_btl_ugni_component.smsg_page_size = 2 << 20; if (GNI_DEVICE_GEMINI == device_type) { - if (access ("/sys/class/gemini/ghal0/mrt", R_OK)) { - int fd = open ("/sys/class/gemini/ghal0/mrt", O_RDONLY); + if (access("/sys/class/gemini/ghal0/mrt", R_OK)) { + int fd = open("/sys/class/gemini/ghal0/mrt", O_RDONLY); char buffer[10]; if (0 <= fd) { - memset (buffer, 0, sizeof (buffer)); - read (fd, buffer, sizeof (buffer) - 1); - close (fd); - mca_btl_ugni_ugni_page_size = strtol (buffer, NULL, 10) * 1024; + memset(buffer, 0, sizeof(buffer)); + read(fd, buffer, sizeof(buffer) - 1); + close(fd); + mca_btl_ugni_ugni_page_size = strtol(buffer, NULL, 10) * 1024; mca_btl_ugni_component.smsg_page_size = mca_btl_ugni_ugni_page_size; } } } - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "smsg_page_size", "Page size to use for SMSG mailbox allocation (default: detect)", - MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.smsg_page_size); + (void) mca_base_component_var_register( + &mca_btl_ugni_component.super.btl_version, "smsg_page_size", + "Page size to use for SMSG mailbox allocation (default: detect)", MCA_BASE_VAR_TYPE_INT, + NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, + &mca_btl_ugni_component.smsg_page_size); mca_btl_ugni_component.progress_thread_requested = 0; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "request_progress_thread", - "Enable to request ugni btl progress thread - requires MPI_THREAD_MULTIPLE support", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - &mca_btl_ugni_component.progress_thread_requested); + (void) mca_base_component_var_register( + &mca_btl_ugni_component.super.btl_version, "request_progress_thread", + "Enable to request ugni btl progress thread - requires MPI_THREAD_MULTIPLE support", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.progress_thread_requested); /* performance variables */ mca_btl_ugni_progress_thread_wakeups = 0; (void) mca_base_component_pvar_register(&mca_btl_ugni_component.super.btl_version, - "progress_thread_wakeups", "Number of times the progress thread " - "has been woken", OPAL_INFO_LVL_9, MCA_BASE_PVAR_CLASS_COUNTER, - MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, MCA_BASE_VAR_BIND_NO_OBJECT, - MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS, NULL, - NULL, NULL, &mca_btl_ugni_progress_thread_wakeups); + "progress_thread_wakeups", + "Number of times the progress thread " + "has been woken", + OPAL_INFO_LVL_9, MCA_BASE_PVAR_CLASS_COUNTER, + MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, + MCA_BASE_VAR_BIND_NO_OBJECT, + MCA_BASE_PVAR_FLAG_READONLY + | MCA_BASE_PVAR_FLAG_CONTINUOUS, + NULL, NULL, NULL, + &mca_btl_ugni_progress_thread_wakeups); /* register network statistics as performance variables */ - for (int i = 0 ; i < GNI_NUM_STATS ; ++i) { + for (int i = 0; i < GNI_NUM_STATS; ++i) { char name[128], desc[128]; - size_t str_len = strlen (gni_statistic_str[i]); + size_t str_len = strlen(gni_statistic_str[i]); - assert (str_len < sizeof (name)); + assert(str_len < sizeof(name)); - /* we can get an all-caps string for the variable from gni_statistic_str. need to make it lowercase - * to match ompi standards */ - for (size_t j = 0 ; j < str_len ; ++j) { - name[j] = tolower (gni_statistic_str[i][j]); + /* we can get an all-caps string for the variable from gni_statistic_str. need to make it + * lowercase to match ompi standards */ + for (size_t j = 0; j < str_len; ++j) { + name[j] = tolower(gni_statistic_str[i][j]); desc[j] = ('_' == name[j]) ? ' ' : name[j]; } name[str_len] = '\0'; desc[str_len] = '\0'; - (void) mca_base_component_pvar_register (&mca_btl_ugni_component.super.btl_version, name, desc, - OPAL_INFO_LVL_4, MCA_BASE_PVAR_CLASS_COUNTER, - MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, MCA_BASE_VAR_BIND_NO_OBJECT, - MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS, - mca_btl_ugni_get_stat, NULL, mca_btl_ugni_notify_stat, - (void *) (intptr_t) i); + (void) mca_base_component_pvar_register(&mca_btl_ugni_component.super.btl_version, name, + desc, OPAL_INFO_LVL_4, MCA_BASE_PVAR_CLASS_COUNTER, + MCA_BASE_VAR_TYPE_UNSIGNED_INT, NULL, + MCA_BASE_VAR_BIND_NO_OBJECT, + MCA_BASE_PVAR_FLAG_READONLY + | MCA_BASE_PVAR_FLAG_CONTINUOUS, + mca_btl_ugni_get_stat, NULL, + mca_btl_ugni_notify_stat, (void *) (intptr_t) i); } - /* btl/ugni can only support only a fixed set of rcache components (these rcache components have compatible resource - * structures) */ - rc = mca_base_var_enum_create ("btl_ugni_rcache", rcache_values, &new_enum); + /* btl/ugni can only support only a fixed set of rcache components (these rcache components have + * compatible resource structures) */ + rc = mca_base_var_enum_create("btl_ugni_rcache", rcache_values, &new_enum); if (OPAL_SUCCESS != rc) { return rc; } - /* NTH: there are known *serious* performance issues with udreg. if they are ever resolved it is the preferred rcache */ + /* NTH: there are known *serious* performance issues with udreg. if they are ever resolved it is + * the preferred rcache */ mca_btl_ugni_component.rcache_type = MCA_BTL_UGNI_RCACHE_GRDMA; - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "rcache", "registration cache to use (default: grdma)", MCA_BASE_VAR_TYPE_INT, new_enum, - 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.rcache_type); + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "rcache", + "registration cache to use (default: grdma)", + MCA_BASE_VAR_TYPE_INT, new_enum, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, + &mca_btl_ugni_component.rcache_type); OBJ_RELEASE(new_enum); if (mca_btl_ugni_ugni_page_size) { - rc = opal_asprintf (&mpool_hints_tmp, "page_size=%lu", mca_btl_ugni_ugni_page_size); + rc = opal_asprintf(&mpool_hints_tmp, "page_size=%lu", mca_btl_ugni_ugni_page_size); if (rc < 0) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -390,21 +436,23 @@ static int btl_ugni_component_register(void) mca_btl_ugni_component.mpool_hints = "page_size=2M"; } - (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, - "mpool_hints", "hints to use when selecting a memory pool (default: " - "\"page_size=2M\")", MCA_BASE_VAR_TYPE_STRING, NULL, 0, + (void) mca_base_component_var_register(&mca_btl_ugni_component.super.btl_version, "mpool_hints", + "hints to use when selecting a memory pool (default: " + "\"page_size=2M\")", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &mca_btl_ugni_component.mpool_hints); - free (mpool_hints_tmp); + MCA_BASE_VAR_SCOPE_LOCAL, + &mca_btl_ugni_component.mpool_hints); + free(mpool_hints_tmp); /* ensure we loose send exclusivity to sm and vader if they are enabled */ mca_btl_ugni_module.super.btl_exclusivity = MCA_BTL_EXCLUSIVITY_HIGH - 2; /* smsg threshold */ - mca_btl_ugni_module.super.btl_eager_limit = 8 * 1024; - mca_btl_ugni_module.super.btl_rndv_eager_limit = 8 * 1024; - mca_btl_ugni_module.super.btl_rdma_pipeline_frag_size = 4 * 1024 * 1024; - mca_btl_ugni_module.super.btl_max_send_size = 8 * 1024; + mca_btl_ugni_module.super.btl_eager_limit = 8 * 1024; + mca_btl_ugni_module.super.btl_rndv_eager_limit = 8 * 1024; + mca_btl_ugni_module.super.btl_rdma_pipeline_frag_size = 4 * 1024 * 1024; + mca_btl_ugni_module.super.btl_max_send_size = 8 * 1024; mca_btl_ugni_module.super.btl_rdma_pipeline_send_length = 8 * 1024; mca_btl_ugni_module.super.btl_get_limit = 1 * 1024 * 1024; @@ -416,29 +464,37 @@ static int btl_ugni_component_register(void) mca_btl_ugni_module.super.btl_get_alignment = 4; /* threshold for put */ - mca_btl_ugni_module.super.btl_min_rdma_pipeline_size = 8 * 1024; + mca_btl_ugni_module.super.btl_min_rdma_pipeline_size = 8 * 1024; - mca_btl_ugni_module.super.btl_flags = MCA_BTL_FLAGS_SEND | - MCA_BTL_FLAGS_RDMA | MCA_BTL_FLAGS_SEND_INPLACE | MCA_BTL_FLAGS_ATOMIC_OPS | - MCA_BTL_FLAGS_ATOMIC_FOPS; - mca_btl_ugni_module.super.btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_ADD | - MCA_BTL_ATOMIC_SUPPORTS_AND | MCA_BTL_ATOMIC_SUPPORTS_OR | MCA_BTL_ATOMIC_SUPPORTS_XOR | - MCA_BTL_ATOMIC_SUPPORTS_CSWAP; + mca_btl_ugni_module.super.btl_flags = MCA_BTL_FLAGS_SEND | MCA_BTL_FLAGS_RDMA + | MCA_BTL_FLAGS_SEND_INPLACE | MCA_BTL_FLAGS_ATOMIC_OPS + | MCA_BTL_FLAGS_ATOMIC_FOPS; + mca_btl_ugni_module.super.btl_atomic_flags = MCA_BTL_ATOMIC_SUPPORTS_ADD + | MCA_BTL_ATOMIC_SUPPORTS_AND + | MCA_BTL_ATOMIC_SUPPORTS_OR + | MCA_BTL_ATOMIC_SUPPORTS_XOR + | MCA_BTL_ATOMIC_SUPPORTS_CSWAP; if (GNI_DEVICE_ARIES == device_type) { /* aries supports additional atomic operations */ - mca_btl_ugni_module.super.btl_atomic_flags |= MCA_BTL_ATOMIC_SUPPORTS_MIN | MCA_BTL_ATOMIC_SUPPORTS_MAX | - MCA_BTL_ATOMIC_SUPPORTS_LAND | MCA_BTL_ATOMIC_SUPPORTS_LOR | MCA_BTL_ATOMIC_SUPPORTS_LXOR | - MCA_BTL_ATOMIC_SUPPORTS_32BIT | MCA_BTL_ATOMIC_SUPPORTS_FLOAT; + mca_btl_ugni_module.super.btl_atomic_flags |= MCA_BTL_ATOMIC_SUPPORTS_MIN + | MCA_BTL_ATOMIC_SUPPORTS_MAX + | MCA_BTL_ATOMIC_SUPPORTS_LAND + | MCA_BTL_ATOMIC_SUPPORTS_LOR + | MCA_BTL_ATOMIC_SUPPORTS_LXOR + | MCA_BTL_ATOMIC_SUPPORTS_32BIT + | MCA_BTL_ATOMIC_SUPPORTS_FLOAT; } - mca_btl_ugni_module.super.btl_registration_handle_size = sizeof (mca_btl_base_registration_handle_t); + mca_btl_ugni_module.super.btl_registration_handle_size = sizeof( + mca_btl_base_registration_handle_t); mca_btl_ugni_module.super.btl_bandwidth = 40000; /* Mbs */ - mca_btl_ugni_module.super.btl_latency = 2; /* Microsecs */ + mca_btl_ugni_module.super.btl_latency = 2; /* Microsecs */ mca_btl_ugni_module.super.btl_get_local_registration_threshold = 0; - mca_btl_ugni_module.super.btl_put_local_registration_threshold = mca_btl_ugni_component.ugni_fma_put_limit; + mca_btl_ugni_module.super.btl_put_local_registration_threshold = mca_btl_ugni_component + .ugni_fma_put_limit; /* Call the BTL based to register its MCA params */ mca_btl_base_param_register(&mca_btl_ugni_component.super.btl_version, @@ -447,8 +503,7 @@ static int btl_ugni_component_register(void) return OPAL_SUCCESS; } -static int -btl_ugni_component_open(void) +static int btl_ugni_component_open(void) { mca_btl_ugni_component.ugni_num_btls = 0; mca_btl_ugni_component.modules = NULL; @@ -459,21 +514,19 @@ btl_ugni_component_open(void) /* * component cleanup - sanity checking of queue lengths */ -static int -btl_ugni_component_close(void) +static int btl_ugni_component_close(void) { - mca_btl_ugni_fini (); + mca_btl_ugni_fini(); - free (mca_btl_ugni_component.modules); + free(mca_btl_ugni_component.modules); mca_btl_ugni_component.modules = NULL; return OPAL_SUCCESS; } -static mca_btl_base_module_t ** -mca_btl_ugni_component_init (int *num_btl_modules, - bool enable_progress_threads, - bool enable_mpi_threads) +static mca_btl_base_module_t **mca_btl_ugni_component_init(int *num_btl_modules, + bool enable_progress_threads, + bool enable_mpi_threads) { struct mca_btl_base_module_t **base_modules; mca_btl_ugni_module_t *ugni_modules; @@ -499,7 +552,8 @@ mca_btl_ugni_component_init (int *num_btl_modules, mca_btl_ugni_component.ugni_fma_put_limit = 65536; } - mca_btl_ugni_module.super.btl_put_local_registration_threshold = mca_btl_ugni_component.ugni_fma_put_limit; + mca_btl_ugni_module.super.btl_put_local_registration_threshold = mca_btl_ugni_component + .ugni_fma_put_limit; /* limit the number of outstanding RDMA operations over all devices */ mca_btl_ugni_component.active_rdma_threshold = mca_btl_ugni_component.local_rdma_cq_size; @@ -520,33 +574,32 @@ mca_btl_ugni_component_init (int *num_btl_modules, BTL_VERBOSE(("btl/ugni initializing")); ugni_modules = mca_btl_ugni_component.modules = (mca_btl_ugni_module_t *) - calloc (mca_btl_ugni_component.ugni_num_btls, sizeof (mca_btl_ugni_module_t)); + calloc(mca_btl_ugni_component.ugni_num_btls, sizeof(mca_btl_ugni_module_t)); if (OPAL_UNLIKELY(NULL == mca_btl_ugni_component.modules)) { BTL_ERROR(("Failed malloc: %s:%d", __FILE__, __LINE__)); return NULL; } - base_modules = (struct mca_btl_base_module_t **) - calloc (mca_btl_ugni_component.ugni_num_btls, - sizeof (struct mca_btl_base_module_t *)); + base_modules = (struct mca_btl_base_module_t **) calloc(mca_btl_ugni_component.ugni_num_btls, + sizeof(struct mca_btl_base_module_t *)); if (OPAL_UNLIKELY(NULL == base_modules)) { BTL_ERROR(("Malloc failed : %s:%d", __FILE__, __LINE__)); return NULL; } - if (mca_btl_ugni_component.smsg_page_size != (unsigned long) opal_getpagesize ()) { + if (mca_btl_ugni_component.smsg_page_size != (unsigned long) opal_getpagesize()) { if (mca_btl_ugni_ugni_page_size > mca_btl_ugni_component.smsg_page_size) { mca_btl_ugni_component.smsg_page_size = mca_btl_ugni_ugni_page_size; } } - mca_btl_ugni_module.super.btl_rdma_pipeline_send_length = mca_btl_ugni_module.super.btl_eager_limit; + mca_btl_ugni_module.super.btl_rdma_pipeline_send_length = mca_btl_ugni_module.super + .btl_eager_limit; - rc = mca_btl_ugni_module_init (ugni_modules); + rc = mca_btl_ugni_module_init(ugni_modules); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - BTL_ERROR(("Failed to initialize uGNI module @ %s:%d", __FILE__, - __LINE__)); + BTL_ERROR(("Failed to initialize uGNI module @ %s:%d", __FILE__, __LINE__)); return NULL; } @@ -559,111 +612,114 @@ mca_btl_ugni_component_init (int *num_btl_modules, return base_modules; } -int mca_btl_ugni_progress_datagram (mca_btl_ugni_device_t *device) +int mca_btl_ugni_progress_datagram(mca_btl_ugni_device_t *device) { mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_component.modules; mca_btl_base_endpoint_t *ep = NULL; gni_ep_handle_t handle; int count = 0, rc; - rc = mca_btl_ugni_get_datagram (ugni_module, device, &handle, &ep); + rc = mca_btl_ugni_get_datagram(ugni_module, device, &handle, &ep); if (1 != rc) { return rc; } - BTL_VERBOSE(("remote datagram completion on handle %p", (void*)handle)); + BTL_VERBOSE(("remote datagram completion on handle %p", (void *) handle)); /* if this is a wildcard endpoint lookup the remote peer by the proc id we received */ if (handle == ugni_module->wildcard_ep) { - struct opal_proc_t *remote_proc = opal_proc_for_name (ugni_module->wc_remote_attr.proc_name); + struct opal_proc_t *remote_proc = opal_proc_for_name(ugni_module->wc_remote_attr.proc_name); BTL_VERBOSE(("received connection attempt on wildcard endpoint from proc: %s", OPAL_NAME_PRINT(ugni_module->wc_remote_attr.proc_name))); - ep = mca_btl_ugni_get_ep (&ugni_module->super, remote_proc); + ep = mca_btl_ugni_get_ep(&ugni_module->super, remote_proc); if (OPAL_UNLIKELY(NULL == ep)) { /* there is no way to recover from this error so just abort() */ BTL_ERROR(("could not find/allocate a btl endpoint for peer %s", OPAL_NAME_PRINT(ugni_module->wc_remote_attr.proc_name))); - abort (); + abort(); return OPAL_ERR_NOT_FOUND; } } /* should not have gotten a NULL endpoint */ - assert (NULL != ep); + assert(NULL != ep); - BTL_VERBOSE(("got a datagram completion: ep = %p. wc = %d", (void *) ep, handle == ugni_module->wildcard_ep)); + BTL_VERBOSE(("got a datagram completion: ep = %p. wc = %d", (void *) ep, + handle == ugni_module->wildcard_ep)); /* NTH: TODO -- error handling */ - opal_mutex_lock (&ep->lock); + opal_mutex_lock(&ep->lock); if (handle != ugni_module->wildcard_ep) { /* directed post complete */ BTL_VERBOSE(("directed datagram complete for endpoint %p", (void *) ep)); ep->dg_posted = false; - (void) opal_atomic_add_fetch_32 (&ugni_module->active_datagrams, -1); + (void) opal_atomic_add_fetch_32(&ugni_module->active_datagrams, -1); } - (void) mca_btl_ugni_ep_connect_progress (ep); - opal_mutex_unlock (&ep->lock); + (void) mca_btl_ugni_ep_connect_progress(ep); + opal_mutex_unlock(&ep->lock); if (MCA_BTL_UGNI_EP_STATE_CONNECTED == ep->state) { /* process messages waiting in the endpoint's smsg mailbox */ - count = mca_btl_ugni_smsg_process (ep); + count = mca_btl_ugni_smsg_process(ep); } /* repost the wildcard datagram */ if (handle == ugni_module->wildcard_ep) { - mca_btl_ugni_wildcard_ep_post (ugni_module); + mca_btl_ugni_wildcard_ep_post(ugni_module); } return count; } -void mca_btl_ugni_handle_rdma_completions (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_device_t *device, - struct mca_btl_ugni_post_descriptor_t *post_desc, const int count) +void mca_btl_ugni_handle_rdma_completions(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_device_t *device, + struct mca_btl_ugni_post_descriptor_t *post_desc, + const int count) { int bte_complete = 0; - for (int i = 0 ; i < count ; ++i) { + for (int i = 0; i < count; ++i) { BTL_VERBOSE(("post descriptor complete. status: %d", post_desc[i].rc)); if (OPAL_UNLIKELY(OPAL_SUCCESS != post_desc[i].rc)) { /* dump the post descriptor if in a debug build */ - btl_ugni_dump_post_desc (post_desc + i); + btl_ugni_dump_post_desc(post_desc + i); } bte_complete += post_desc[i].use_bte == true; - mca_btl_ugni_post_desc_complete (ugni_module, post_desc + i, post_desc[i].rc); + mca_btl_ugni_post_desc_complete(ugni_module, post_desc + i, post_desc[i].rc); } - if (bte_complete > 0) { - (void) OPAL_THREAD_FETCH_ADD32 (&ugni_module->active_rdma_count, -bte_complete); + if (bte_complete > 0) { + (void) OPAL_THREAD_FETCH_ADD32(&ugni_module->active_rdma_count, -bte_complete); } } -static inline int mca_btl_ugni_progress_rdma (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_device_t *device, - mca_btl_ugni_cq_t *cq) +static inline int mca_btl_ugni_progress_rdma(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq) { mca_btl_ugni_post_descriptor_t post_desc[MCA_BTL_UGNI_COMPLETIONS_PER_LOOP]; int rc; - rc = mca_btl_ugni_cq_get_completed_desc (device, cq, post_desc, MCA_BTL_UGNI_COMPLETIONS_PER_LOOP); + rc = mca_btl_ugni_cq_get_completed_desc(device, cq, post_desc, + MCA_BTL_UGNI_COMPLETIONS_PER_LOOP); if (0 >= rc) { return rc; } BTL_VERBOSE(("got %d completed rdma descriptors", rc)); - mca_btl_ugni_handle_rdma_completions (ugni_module, device, post_desc, rc); + mca_btl_ugni_handle_rdma_completions(ugni_module, device, post_desc, rc); return rc; } -static inline int -mca_btl_ugni_progress_wait_list (mca_btl_ugni_module_t *ugni_module) +static inline int mca_btl_ugni_progress_wait_list(mca_btl_ugni_module_t *ugni_module) { int rc = OPAL_SUCCESS; opal_list_t tmplist; @@ -686,17 +742,17 @@ mca_btl_ugni_progress_wait_list (mca_btl_ugni_module_t *ugni_module) OPAL_THREAD_UNLOCK(&ugni_module->ep_wait_list_lock); count = opal_list_get_size(&tmplist); do { - endpoint = (mca_btl_base_endpoint_t *) opal_list_remove_first (&tmplist); + endpoint = (mca_btl_base_endpoint_t *) opal_list_remove_first(&tmplist); if (endpoint != NULL) { - rc = mca_btl_ugni_progress_send_wait_list (endpoint); + rc = mca_btl_ugni_progress_send_wait_list(endpoint); if (OPAL_SUCCESS != rc) { - opal_list_append (&tmplist, &endpoint->super); + opal_list_append(&tmplist, &endpoint->super); } else { endpoint->wait_listed = false; } } - } while (endpoint != NULL && --count > 0) ; + } while (endpoint != NULL && --count > 0); /* reinsert unfinished elements into the wait-list */ count = opal_list_get_size(&tmplist); @@ -710,49 +766,51 @@ mca_btl_ugni_progress_wait_list (mca_btl_ugni_module_t *ugni_module) return rc; } -static int mca_btl_ugni_component_progress (void) +static int mca_btl_ugni_component_progress(void) { mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_component.modules; int count = 0; - count += mca_btl_ugni_progress_remote_smsg (ugni_module); + count += mca_btl_ugni_progress_remote_smsg(ugni_module); if (ugni_module->active_datagrams) { - count += mca_btl_ugni_progress_datagram (ugni_module->devices); + count += mca_btl_ugni_progress_datagram(ugni_module->devices); } - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { mca_btl_ugni_device_t *device = ugni_module->devices + i; if (device->smsg_connections) { - count += mca_btl_ugni_progress_local_smsg (ugni_module, device); - mca_btl_ugni_progress_wait_list (ugni_module); + count += mca_btl_ugni_progress_local_smsg(ugni_module, device); + mca_btl_ugni_progress_wait_list(ugni_module); } if (device->dev_rdma_local_cq.active_operations) { - count += mca_btl_ugni_progress_rdma (ugni_module, device, &device->dev_rdma_local_cq); + count += mca_btl_ugni_progress_rdma(ugni_module, device, &device->dev_rdma_local_cq); } - if (mca_btl_ugni_component.progress_thread_enabled && device->dev_rdma_local_irq_cq.active_operations) { - count += mca_btl_ugni_progress_rdma (ugni_module, device, &device->dev_rdma_local_irq_cq); + if (mca_btl_ugni_component.progress_thread_enabled + && device->dev_rdma_local_irq_cq.active_operations) { + count += mca_btl_ugni_progress_rdma(ugni_module, device, + &device->dev_rdma_local_irq_cq); } } return count; } -int mca_btl_ugni_flush (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint) +int mca_btl_ugni_flush(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint) { mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_component.modules; - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { mca_btl_ugni_device_t *device = ugni_module->devices + i; /* spin on progress until all active operations are complete. it is tempting to * take an initial count then wait until that many operations have been completed * but it is impossible to tell if those are the operations the caller is waiting * on. */ while (device->dev_rdma_local_cq.active_operations) { - (void) mca_btl_ugni_progress_rdma (ugni_module, device, &device->dev_rdma_local_cq); + (void) mca_btl_ugni_progress_rdma(ugni_module, device, &device->dev_rdma_local_cq); } /* mark that the device was recently flushed */ @@ -762,22 +820,22 @@ int mca_btl_ugni_flush (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint return OPAL_SUCCESS; } -void btl_ugni_dump_post_desc (mca_btl_ugni_post_descriptor_t *desc) +void btl_ugni_dump_post_desc(mca_btl_ugni_post_descriptor_t *desc) { - fprintf (stderr, "desc->gni_desc.post_id = %" PRIx64 "\n", desc->gni_desc.post_id); - fprintf (stderr, "desc->gni_desc.status = %" PRIx64 "\n", desc->gni_desc.status); - fprintf (stderr, "desc->gni_desc.cq_mode_complete = %hu\n", desc->gni_desc.cq_mode_complete); - fprintf (stderr, "desc->gni_desc.type = %d\n", desc->gni_desc.type); - fprintf (stderr, "desc->gni_desc.cq_mode = %hu\n", desc->gni_desc.cq_mode); - fprintf (stderr, "desc->gni_desc.dlvr_mode = %hu\n", desc->gni_desc.dlvr_mode); - fprintf (stderr, "desc->gni_desc.local_addr = %" PRIx64 "\n", desc->gni_desc.local_addr); - fprintf (stderr, "desc->gni_desc.local_mem_hndl = {%" PRIx64 ", %" PRIx64 "}\n", desc->gni_desc.local_mem_hndl.qword1, - desc->gni_desc.local_mem_hndl.qword2); - fprintf (stderr, "desc->gni_desc.remote_addr = %" PRIx64 "\n", desc->gni_desc.remote_addr); - fprintf (stderr, "desc->gni_desc.remote_mem_hndl = {%" PRIx64 ", %" PRIx64 "}\n", desc->gni_desc.remote_mem_hndl.qword1, - desc->gni_desc.remote_mem_hndl.qword2); - fprintf (stderr, "desc->gni_desc.length = %" PRIu64 "\n", desc->gni_desc.length); - fprintf (stderr, "desc->gni_desc.rdma_mode = %hu\n", desc->gni_desc.rdma_mode); - fprintf (stderr, "desc->gni_desc.amo_cmd = %d\n", desc->gni_desc.amo_cmd); + fprintf(stderr, "desc->gni_desc.post_id = %" PRIx64 "\n", desc->gni_desc.post_id); + fprintf(stderr, "desc->gni_desc.status = %" PRIx64 "\n", desc->gni_desc.status); + fprintf(stderr, "desc->gni_desc.cq_mode_complete = %hu\n", desc->gni_desc.cq_mode_complete); + fprintf(stderr, "desc->gni_desc.type = %d\n", desc->gni_desc.type); + fprintf(stderr, "desc->gni_desc.cq_mode = %hu\n", desc->gni_desc.cq_mode); + fprintf(stderr, "desc->gni_desc.dlvr_mode = %hu\n", desc->gni_desc.dlvr_mode); + fprintf(stderr, "desc->gni_desc.local_addr = %" PRIx64 "\n", desc->gni_desc.local_addr); + fprintf(stderr, "desc->gni_desc.local_mem_hndl = {%" PRIx64 ", %" PRIx64 "}\n", + desc->gni_desc.local_mem_hndl.qword1, desc->gni_desc.local_mem_hndl.qword2); + fprintf(stderr, "desc->gni_desc.remote_addr = %" PRIx64 "\n", desc->gni_desc.remote_addr); + fprintf(stderr, "desc->gni_desc.remote_mem_hndl = {%" PRIx64 ", %" PRIx64 "}\n", + desc->gni_desc.remote_mem_hndl.qword1, desc->gni_desc.remote_mem_hndl.qword2); + fprintf(stderr, "desc->gni_desc.length = %" PRIu64 "\n", desc->gni_desc.length); + fprintf(stderr, "desc->gni_desc.rdma_mode = %hu\n", desc->gni_desc.rdma_mode); + fprintf(stderr, "desc->gni_desc.amo_cmd = %d\n", desc->gni_desc.amo_cmd); } diff --git a/opal/mca/btl/ugni/btl_ugni_device.h b/opal/mca/btl/ugni/btl_ugni_device.h index 0f58b06205a..8d73069349c 100644 --- a/opal/mca/btl/ugni/btl_ugni_device.h +++ b/opal/mca/btl/ugni/btl_ugni_device.h @@ -20,10 +20,10 @@ */ #if !defined(BTL_UGNI_DEVICE_H) -#define BTL_UGNI_DEVICE_H +# define BTL_UGNI_DEVICE_H -#include "btl_ugni_endpoint.h" -#include "btl_ugni_frag.h" +# include "btl_ugni_endpoint.h" +# include "btl_ugni_frag.h" /* helper functions */ /** @@ -35,7 +35,7 @@ * This is a small function to print out an error if an error * was detected on a CQ event. */ -int mca_btl_ugni_event_fatal_error (gni_return_t grc, gni_cq_entry_t event_data); +int mca_btl_ugni_event_fatal_error(gni_return_t grc, gni_cq_entry_t event_data); /** * @brief Attempt to re-post an rdma descriptor @@ -50,7 +50,8 @@ int mca_btl_ugni_event_fatal_error (gni_return_t grc, gni_cq_entry_t event_data) * descriptor if possible. The device lock MUST be held when this * function is called. */ -int mca_btl_ugni_device_handle_event_error (struct mca_btl_ugni_rdma_desc_t *rdma_desc, gni_cq_entry_t event_data); +int mca_btl_ugni_device_handle_event_error(struct mca_btl_ugni_rdma_desc_t *rdma_desc, + gni_cq_entry_t event_data); typedef struct mca_btl_ugni_smsg_send_wtag_arg_t { gni_ep_handle_t ep_handle; @@ -62,13 +63,13 @@ typedef struct mca_btl_ugni_smsg_send_wtag_arg_t { int tag; } mca_btl_ugni_smsg_send_wtag_arg_t; -static inline int mca_btl_ugni_smsg_send_wtag_device (mca_btl_ugni_device_t *device, void *arg) +static inline int mca_btl_ugni_smsg_send_wtag_device(mca_btl_ugni_device_t *device, void *arg) { mca_btl_ugni_smsg_send_wtag_arg_t *args = (mca_btl_ugni_smsg_send_wtag_arg_t *) arg; gni_return_t grc; - grc = GNI_SmsgSendWTag (args->ep_handle, args->hdr, args->hdr_len, args->payload, - args->payload_len, args->msg_id, args->tag); + grc = GNI_SmsgSendWTag(args->ep_handle, args->hdr, args->hdr_len, args->payload, + args->payload_len, args->msg_id, args->tag); device->dev_smsg_local_cq.active_operations += (GNI_RC_SUCCESS == grc); return grc; } @@ -79,17 +80,18 @@ typedef struct mca_btl_ugni_smsg_get_next_wtag_arg_t { uint8_t *tag; } mca_btl_ugni_smsg_get_next_wtag_arg_t; -static inline intptr_t mca_btl_ugni_smsg_get_next_wtag_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_smsg_get_next_wtag_device(mca_btl_ugni_device_t *device, + void *arg) { mca_btl_ugni_smsg_get_next_wtag_arg_t *args = (mca_btl_ugni_smsg_get_next_wtag_arg_t *) arg; return GNI_SmsgGetNextWTag(args->ep_handle, (void **) args->data_ptr, args->tag); } -static inline intptr_t mca_btl_ugni_smsg_release_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_smsg_release_device(mca_btl_ugni_device_t *device, void *arg) { mca_btl_ugni_endpoint_handle_t *ep_handle = (mca_btl_ugni_endpoint_handle_t *) arg; - return GNI_SmsgRelease (ep_handle->gni_handle); + return GNI_SmsgRelease(ep_handle->gni_handle); } typedef struct mca_btl_ugni_cq_get_event_args_t { @@ -97,24 +99,24 @@ typedef struct mca_btl_ugni_cq_get_event_args_t { gni_cq_entry_t *event_data; } mca_btl_ugni_cq_get_event_args_t; -static inline intptr_t mca_btl_ugni_cq_get_event_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_cq_get_event_device(mca_btl_ugni_device_t *device, void *arg) { mca_btl_ugni_cq_get_event_args_t *args = (mca_btl_ugni_cq_get_event_args_t *) arg; gni_return_t rc; - rc = GNI_CqGetEvent (args->cq->gni_handle, args->event_data); + rc = GNI_CqGetEvent(args->cq->gni_handle, args->event_data); args->cq->active_operations -= (GNI_RC_NOT_DONE != rc); return rc; } -static inline intptr_t mca_btl_ugni_cq_clear_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_cq_clear_device(mca_btl_ugni_device_t *device, void *arg) { - gni_cq_handle_t cq = (gni_cq_handle_t) (intptr_t) arg; + gni_cq_handle_t cq = (gni_cq_handle_t)(intptr_t) arg; gni_cq_entry_t event_data; int rc; do { - rc = GNI_CqGetEvent (cq, &event_data); + rc = GNI_CqGetEvent(cq, &event_data); } while (GNI_RC_NOT_DONE != rc); return OPAL_SUCCESS; @@ -125,11 +127,12 @@ typedef struct mca_btl_ugni_gni_cq_get_event_args_t { gni_cq_entry_t *event_data; } mca_btl_ugni_gni_cq_get_event_args_t; -static inline intptr_t mca_btl_ugni_gni_cq_get_event_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_gni_cq_get_event_device(mca_btl_ugni_device_t *device, + void *arg) { mca_btl_ugni_gni_cq_get_event_args_t *args = (mca_btl_ugni_gni_cq_get_event_args_t *) arg; - return GNI_CqGetEvent (args->cq, args->event_data); + return GNI_CqGetEvent(args->cq, args->event_data); } typedef struct mca_btl_ugni_cq_get_completed_desc_arg_t { @@ -138,80 +141,86 @@ typedef struct mca_btl_ugni_cq_get_completed_desc_arg_t { int count; } mca_btl_ugni_cq_get_completed_desc_arg_t; -__opal_attribute_always_inline__ -static inline int _mca_btl_ugni_repost_rdma_desc_device (mca_btl_ugni_device_t *device, mca_btl_ugni_rdma_desc_t *rdma_desc) +__opal_attribute_always_inline__ static inline int +_mca_btl_ugni_repost_rdma_desc_device(mca_btl_ugni_device_t *device, + mca_btl_ugni_rdma_desc_t *rdma_desc) { mca_btl_ugni_post_descriptor_t *post_desc = &rdma_desc->btl_ugni_desc; int rc; if (post_desc->use_bte) { - rc = GNI_PostRdma (rdma_desc->gni_handle, &post_desc->gni_desc); + rc = GNI_PostRdma(rdma_desc->gni_handle, &post_desc->gni_desc); } else { - rc = GNI_PostFma (rdma_desc->gni_handle, &post_desc->gni_desc); + rc = GNI_PostFma(rdma_desc->gni_handle, &post_desc->gni_desc); } - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } -static inline intptr_t _mca_btl_ugni_cq_get_completed_desc_device (mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq, - mca_btl_ugni_post_descriptor_t *post_desc, - const int count, bool block) +static inline intptr_t +_mca_btl_ugni_cq_get_completed_desc_device(mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq, + mca_btl_ugni_post_descriptor_t *post_desc, + const int count, bool block) { mca_btl_ugni_rdma_desc_t *rdma_desc; gni_post_descriptor_t *desc; gni_cq_entry_t event_data; int rc, desc_index = 0; - for (desc_index = 0 ; desc_index < count && cq->active_operations ; ) { + for (desc_index = 0; desc_index < count && cq->active_operations;) { int desc_rc = OPAL_SUCCESS; - rc = GNI_CqGetEvent (cq->gni_handle, &event_data); + rc = GNI_CqGetEvent(cq->gni_handle, &event_data); if (GNI_RC_NOT_DONE == rc) { - if (block) { - /* try again */ - continue; - } + if (block) { + /* try again */ + continue; + } break; } - block = false; + block = false; - rc = GNI_GetCompleted (cq->gni_handle, event_data, &desc); + rc = GNI_GetCompleted(cq->gni_handle, event_data, &desc); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc && GNI_RC_TRANSACTION_ERROR != rc)) { - return mca_btl_ugni_event_fatal_error (rc, event_data); + return mca_btl_ugni_event_fatal_error(rc, event_data); } rdma_desc = MCA_BTL_UGNI_GNI_DESC_TO_RDMA_DESC(desc); if (OPAL_UNLIKELY(!GNI_CQ_STATUS_OK(event_data))) { - desc_rc = mca_btl_ugni_device_handle_event_error (rdma_desc, event_data); + desc_rc = mca_btl_ugni_device_handle_event_error(rdma_desc, event_data); if (OPAL_LIKELY(OPAL_SUCCESS == desc_rc)) { /* descriptor was re-posted */ continue; } } - /* copy back the descriptor only if additional processing is needed. in this case more processing - * is needed if a user callback is specified or the bte was in use. */ - if (rdma_desc->btl_ugni_desc.cbfunc || rdma_desc->btl_ugni_desc.use_bte || OPAL_SUCCESS != desc_rc) { + /* copy back the descriptor only if additional processing is needed. in this case more + * processing is needed if a user callback is specified or the bte was in use. */ + if (rdma_desc->btl_ugni_desc.cbfunc || rdma_desc->btl_ugni_desc.use_bte + || OPAL_SUCCESS != desc_rc) { post_desc[desc_index] = rdma_desc->btl_ugni_desc; post_desc[desc_index++].rc = desc_rc; } /* return the descriptor while we have the lock. this is done so we can avoid using the * free list atomics (as both push and pop are done with the lock) */ - mca_btl_ugni_return_rdma_desc (rdma_desc); + mca_btl_ugni_return_rdma_desc(rdma_desc); --cq->active_operations; } return desc_index; } -static inline intptr_t mca_btl_ugni_cq_get_completed_desc_device (mca_btl_ugni_device_t *device, void *arg0) +static inline intptr_t mca_btl_ugni_cq_get_completed_desc_device(mca_btl_ugni_device_t *device, + void *arg0) { - mca_btl_ugni_cq_get_completed_desc_arg_t *args = (mca_btl_ugni_cq_get_completed_desc_arg_t *) arg0; + mca_btl_ugni_cq_get_completed_desc_arg_t *args = (mca_btl_ugni_cq_get_completed_desc_arg_t *) + arg0; - return _mca_btl_ugni_cq_get_completed_desc_device (device, args->cq, args->post_desc, args->count, false); + return _mca_btl_ugni_cq_get_completed_desc_device(device, args->cq, args->post_desc, + args->count, false); } /* NTH: When posting FMA or RDMA descriptors it makes sense to try and clear out a completion @@ -229,7 +238,7 @@ static inline intptr_t mca_btl_ugni_cq_get_completed_desc_device (mca_btl_ugni_d /** * @brief Number of events to clear after posting a descriptor */ -#define MCA_BTL_UGNI_DEVICE_REAP_COUNT 4 +# define MCA_BTL_UGNI_DEVICE_REAP_COUNT 4 struct mca_btl_ugni_post_device_args_t { mca_btl_ugni_post_descriptor_t *desc; @@ -239,7 +248,8 @@ struct mca_btl_ugni_post_device_args_t { }; static inline mca_btl_ugni_rdma_desc_t * -mca_btl_ugni_get_rdma_desc_device (mca_btl_ugni_device_t *device, struct mca_btl_ugni_post_device_args_t *args, bool use_bte) +mca_btl_ugni_get_rdma_desc_device(mca_btl_ugni_device_t *device, + struct mca_btl_ugni_post_device_args_t *args, bool use_bte) { mca_btl_ugni_post_descriptor_t *desc = args->desc; mca_btl_ugni_rdma_desc_t *rdma_desc; @@ -248,110 +258,122 @@ mca_btl_ugni_get_rdma_desc_device (mca_btl_ugni_device_t *device, struct mca_btl args->count = 0; do { - rdma_desc = mca_btl_ugni_alloc_rdma_desc (device, desc, use_bte); - if (OPAL_LIKELY(NULL != rdma_desc)) { - return rdma_desc; - } + rdma_desc = mca_btl_ugni_alloc_rdma_desc(device, desc, use_bte); + if (OPAL_LIKELY(NULL != rdma_desc)) { + return rdma_desc; + } if (OPAL_LIKELY(NULL == rdma_desc && !args->count)) { - args->count = _mca_btl_ugni_cq_get_completed_desc_device (device, &device->dev_rdma_local_cq, - args->completed, MCA_BTL_UGNI_DEVICE_REAP_COUNT, - true); - continue; + args->count = _mca_btl_ugni_cq_get_completed_desc_device(device, + &device->dev_rdma_local_cq, + args->completed, + MCA_BTL_UGNI_DEVICE_REAP_COUNT, + true); + continue; } - return NULL; + return NULL; } while (1); } - -static inline intptr_t mca_btl_ugni_post_fma_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_post_fma_device(mca_btl_ugni_device_t *device, void *arg) { struct mca_btl_ugni_post_device_args_t *args = (struct mca_btl_ugni_post_device_args_t *) arg; mca_btl_ugni_rdma_desc_t *rdma_desc; int rc; - rdma_desc = mca_btl_ugni_get_rdma_desc_device (device, args, false); + rdma_desc = mca_btl_ugni_get_rdma_desc_device(device, args, false); if (OPAL_UNLIKELY(NULL == rdma_desc)) { - return OPAL_ERR_TEMP_OUT_OF_RESOURCE; + return OPAL_ERR_TEMP_OUT_OF_RESOURCE; } BTL_VERBOSE(("Posting FMA descriptor %p with op_type %d, amo %d, remote_addr 0x%lx, " - "length %lu", (void*)rdma_desc, rdma_desc->btl_ugni_desc.gni_desc.type, rdma_desc->btl_ugni_desc.gni_desc.amo_cmd, - rdma_desc->btl_ugni_desc.gni_desc.remote_addr, rdma_desc->btl_ugni_desc.gni_desc.length)); + "length %lu", + (void *) rdma_desc, rdma_desc->btl_ugni_desc.gni_desc.type, + rdma_desc->btl_ugni_desc.gni_desc.amo_cmd, + rdma_desc->btl_ugni_desc.gni_desc.remote_addr, + rdma_desc->btl_ugni_desc.gni_desc.length)); - rc = GNI_PostFma (rdma_desc->gni_handle, &rdma_desc->btl_ugni_desc.gni_desc); + rc = GNI_PostFma(rdma_desc->gni_handle, &rdma_desc->btl_ugni_desc.gni_desc); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { - mca_btl_ugni_return_rdma_desc (rdma_desc); - return mca_btl_rc_ugni_to_opal (rc); + mca_btl_ugni_return_rdma_desc(rdma_desc); + return mca_btl_rc_ugni_to_opal(rc); } ++device->dev_rdma_local_cq.active_operations; - /* to improve bandwidth and latency it is ideal for all posting threads to also reap completions from - * the rdma completion queue. there are two optimizations here. 1) for bandwidth we only want to - * reap what is available now so more messages can be posted quickly, and 2) for latency (single - * put/get before flushing) we want to ensure the operation is complete. To some degree this is - * gaming the benchmark but it may benefit some application communication patterns without really - * hurting others (in theory). */ - if (opal_using_threads ()) { - int count = args->count; - args->count += _mca_btl_ugni_cq_get_completed_desc_device (device, &device->dev_rdma_local_cq, - args->completed + count, - MCA_BTL_UGNI_DEVICE_REAP_COUNT - count, - device->flushed); - device->flushed = false; + /* to improve bandwidth and latency it is ideal for all posting threads to also reap completions + * from the rdma completion queue. there are two optimizations here. 1) for bandwidth we only + * want to reap what is available now so more messages can be posted quickly, and 2) for latency + * (single put/get before flushing) we want to ensure the operation is complete. To some degree + * this is gaming the benchmark but it may benefit some application communication patterns + * without really hurting others (in theory). */ + if (opal_using_threads()) { + int count = args->count; + args->count += _mca_btl_ugni_cq_get_completed_desc_device(device, + &device->dev_rdma_local_cq, + args->completed + count, + MCA_BTL_UGNI_DEVICE_REAP_COUNT + - count, + device->flushed); + device->flushed = false; } return OPAL_SUCCESS; } -static inline intptr_t mca_btl_ugni_post_rdma_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_post_rdma_device(mca_btl_ugni_device_t *device, void *arg) { struct mca_btl_ugni_post_device_args_t *args = (struct mca_btl_ugni_post_device_args_t *) arg; mca_btl_ugni_rdma_desc_t *rdma_desc; int rc; - rdma_desc = mca_btl_ugni_get_rdma_desc_device (device, args, true); + rdma_desc = mca_btl_ugni_get_rdma_desc_device(device, args, true); if (OPAL_UNLIKELY(NULL == rdma_desc)) { - return OPAL_ERR_TEMP_OUT_OF_RESOURCE; + return OPAL_ERR_TEMP_OUT_OF_RESOURCE; } /* pick the appropriate CQ */ - rdma_desc->btl_ugni_desc.cq = mca_btl_ugni_component.progress_thread_enabled ? &device->dev_rdma_local_irq_cq : - &device->dev_rdma_local_cq; + rdma_desc->btl_ugni_desc.cq = mca_btl_ugni_component.progress_thread_enabled + ? &device->dev_rdma_local_irq_cq + : &device->dev_rdma_local_cq; BTL_VERBOSE(("Posting RDMA descriptor %p with op_type %d, amo %d, remote_addr 0x%lx, " - "length %lu", (void*)rdma_desc, rdma_desc->btl_ugni_desc.gni_desc.type, rdma_desc->btl_ugni_desc.gni_desc.amo_cmd, - rdma_desc->btl_ugni_desc.gni_desc.remote_addr, rdma_desc->btl_ugni_desc.gni_desc.length)); + "length %lu", + (void *) rdma_desc, rdma_desc->btl_ugni_desc.gni_desc.type, + rdma_desc->btl_ugni_desc.gni_desc.amo_cmd, + rdma_desc->btl_ugni_desc.gni_desc.remote_addr, + rdma_desc->btl_ugni_desc.gni_desc.length)); - rc = GNI_PostRdma (rdma_desc->gni_handle, &rdma_desc->btl_ugni_desc.gni_desc); + rc = GNI_PostRdma(rdma_desc->gni_handle, &rdma_desc->btl_ugni_desc.gni_desc); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { - mca_btl_ugni_return_rdma_desc (rdma_desc); - return mca_btl_rc_ugni_to_opal (rc); + mca_btl_ugni_return_rdma_desc(rdma_desc); + return mca_btl_rc_ugni_to_opal(rc); } ++rdma_desc->btl_ugni_desc.cq->active_operations; - /* to improve bandwidth and latency it is ideal for all posting threads to also reap completions from - * the rdma completion queue. there are two optimizations here. 1) for bandwidth we only want to - * reap what is available now so more messages can be posted quickly, and 2) for latency (single - * put/get before flushing) we want to ensure the operation is complete. To some degree this is - * gaming the benchmark but it may benefit some application communication patterns without really - * hurting others (in theory). */ - if (opal_using_threads ()) { - int count = args->count; - args->count += _mca_btl_ugni_cq_get_completed_desc_device (device, &device->dev_rdma_local_cq, - args->completed + count, - MCA_BTL_UGNI_DEVICE_REAP_COUNT - count, - device->flushed); - device->flushed = false; + /* to improve bandwidth and latency it is ideal for all posting threads to also reap completions + * from the rdma completion queue. there are two optimizations here. 1) for bandwidth we only + * want to reap what is available now so more messages can be posted quickly, and 2) for latency + * (single put/get before flushing) we want to ensure the operation is complete. To some degree + * this is gaming the benchmark but it may benefit some application communication patterns + * without really hurting others (in theory). */ + if (opal_using_threads()) { + int count = args->count; + args->count += _mca_btl_ugni_cq_get_completed_desc_device(device, + &device->dev_rdma_local_cq, + args->completed + count, + MCA_BTL_UGNI_DEVICE_REAP_COUNT + - count, + device->flushed); + device->flushed = false; } return OPAL_SUCCESS; } -static inline intptr_t mca_btl_ugni_post_cqwrite_device (mca_btl_ugni_device_t *device, void *arg) +static inline intptr_t mca_btl_ugni_post_cqwrite_device(mca_btl_ugni_device_t *device, void *arg) { mca_btl_ugni_post_descriptor_t *desc = (mca_btl_ugni_post_descriptor_t *) arg; mca_btl_ugni_rdma_desc_t *rdma_desc; @@ -359,17 +381,17 @@ static inline intptr_t mca_btl_ugni_post_cqwrite_device (mca_btl_ugni_device_t * desc->gni_desc.src_cq_hndl = device->dev_rdma_local_cq.gni_handle; - rdma_desc = mca_btl_ugni_alloc_rdma_desc (device, desc, false); + rdma_desc = mca_btl_ugni_alloc_rdma_desc(device, desc, false); if (OPAL_UNLIKELY(NULL == rdma_desc)) { return OPAL_ERR_OUT_OF_RESOURCE; } - rc = GNI_PostCqWrite (rdma_desc->gni_handle, &rdma_desc->btl_ugni_desc.gni_desc); + rc = GNI_PostCqWrite(rdma_desc->gni_handle, &rdma_desc->btl_ugni_desc.gni_desc); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { - mca_btl_ugni_return_rdma_desc (rdma_desc); + mca_btl_ugni_return_rdma_desc(rdma_desc); } - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } typedef struct mca_btl_ugni_get_datagram_args_t { @@ -378,7 +400,7 @@ typedef struct mca_btl_ugni_get_datagram_args_t { mca_btl_base_endpoint_t **ep; } mca_btl_ugni_get_datagram_args_t; -static inline intptr_t mca_btl_ugni_get_datagram_device (mca_btl_ugni_device_t *device, void *arg0) +static inline intptr_t mca_btl_ugni_get_datagram_device(mca_btl_ugni_device_t *device, void *arg0) { mca_btl_ugni_get_datagram_args_t *args = (mca_btl_ugni_get_datagram_args_t *) arg0; uint32_t remote_addr, remote_id; @@ -387,32 +409,36 @@ static inline intptr_t mca_btl_ugni_get_datagram_device (mca_btl_ugni_device_t * gni_return_t grc; uint64_t data; - grc = GNI_PostDataProbeById (device->dev_handle, &datagram_id); + grc = GNI_PostDataProbeById(device->dev_handle, &datagram_id); if (OPAL_LIKELY(GNI_RC_SUCCESS != grc)) { return 0; } data = datagram_id & ~(MCA_BTL_UGNI_DATAGRAM_MASK); - BTL_VERBOSE(("rc: %d, datgram_id: %" PRIx64 ", mask: %" PRIx64, grc, datagram_id, (uint64_t) (datagram_id & MCA_BTL_UGNI_DATAGRAM_MASK))); + BTL_VERBOSE(("rc: %d, datgram_id: %" PRIx64 ", mask: %" PRIx64, grc, datagram_id, + (uint64_t)(datagram_id & MCA_BTL_UGNI_DATAGRAM_MASK))); if ((datagram_id & MCA_BTL_UGNI_DATAGRAM_MASK) == MCA_BTL_UGNI_CONNECT_DIRECTED_ID) { - *(args->ep) = (mca_btl_base_endpoint_t *) opal_pointer_array_get_item (&args->ugni_module->endpoints, data); + *(args->ep) = (mca_btl_base_endpoint_t *) + opal_pointer_array_get_item(&args->ugni_module->endpoints, data); *(args->handle) = (*args->ep)->smsg_ep_handle.gni_handle; } else { *(args->handle) = args->ugni_module->wildcard_ep; } /* wait for the incoming datagram to complete (in case it isn't) */ - grc = GNI_EpPostDataWaitById (*args->handle, datagram_id, -1, &post_state, - &remote_addr, &remote_id); + grc = GNI_EpPostDataWaitById(*args->handle, datagram_id, -1, &post_state, &remote_addr, + &remote_id); if (GNI_RC_SUCCESS != grc) { BTL_ERROR(("GNI_EpPostDataWaitById failed with rc = %d", grc)); - return mca_btl_rc_ugni_to_opal (grc); + return mca_btl_rc_ugni_to_opal(grc); } - BTL_VERBOSE(("handled datagram completion. post_state: %d, remote_addr: %u, remote_id: %u, directed?: %d", - post_state, remote_addr, remote_id, (datagram_id & MCA_BTL_UGNI_DATAGRAM_MASK) == MCA_BTL_UGNI_CONNECT_DIRECTED_ID)); + BTL_VERBOSE(("handled datagram completion. post_state: %d, remote_addr: %u, remote_id: %u, " + "directed?: %d", + post_state, remote_addr, remote_id, + (datagram_id & MCA_BTL_UGNI_DATAGRAM_MASK) == MCA_BTL_UGNI_CONNECT_DIRECTED_ID)); return 1; } @@ -426,13 +452,13 @@ typedef struct mca_btl_ugni_reg_mem_args_t { int flags; } mca_btl_ugni_reg_mem_args_t; -static intptr_t mca_btl_ugni_reg_mem_device (mca_btl_ugni_device_t *device, void *arg) +static intptr_t mca_btl_ugni_reg_mem_device(mca_btl_ugni_device_t *device, void *arg) { mca_btl_ugni_reg_mem_args_t *args = (mca_btl_ugni_reg_mem_args_t *) arg; gni_return_t rc; - rc = GNI_MemRegister (device->dev_handle, (uint64_t) args->base, args->size, args->cq, - args->flags, -1, &args->ugni_reg->handle.gni_handle); + rc = GNI_MemRegister(device->dev_handle, (uint64_t) args->base, args->size, args->cq, + args->flags, -1, &args->ugni_reg->handle.gni_handle); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -445,135 +471,194 @@ typedef struct mca_btl_ugni_dereg_mem_arg_t { mca_btl_ugni_reg_t *ugni_reg; } mca_btl_ugni_dereg_mem_arg_t; -static intptr_t mca_btl_ugni_dereg_mem_device (mca_btl_ugni_device_t *device, void *arg) +static intptr_t mca_btl_ugni_dereg_mem_device(mca_btl_ugni_device_t *device, void *arg) { mca_btl_ugni_dereg_mem_arg_t *args = (mca_btl_ugni_dereg_mem_arg_t *) arg; gni_return_t rc; - rc = GNI_MemDeregister (device->dev_handle, &args->ugni_reg->handle.gni_handle); - return mca_btl_rc_ugni_to_opal (rc); + rc = GNI_MemDeregister(device->dev_handle, &args->ugni_reg->handle.gni_handle); + return mca_btl_rc_ugni_to_opal(rc); } /* multi-thread safe interface to uGNI */ -static inline int mca_btl_ugni_endpoint_smsg_send_wtag (mca_btl_base_endpoint_t *endpoint, void *hdr, size_t hdr_len, - void *payload, size_t payload_len, uint32_t msg_id, int tag) +static inline int mca_btl_ugni_endpoint_smsg_send_wtag(mca_btl_base_endpoint_t *endpoint, void *hdr, + size_t hdr_len, void *payload, + size_t payload_len, uint32_t msg_id, int tag) { mca_btl_ugni_smsg_send_wtag_arg_t args = {.ep_handle = endpoint->smsg_ep_handle.gni_handle, - .hdr = hdr, .hdr_len = hdr_len, .payload = payload, - .payload_len = payload_len, .msg_id = msg_id, + .hdr = hdr, + .hdr_len = hdr_len, + .payload = payload, + .payload_len = payload_len, + .msg_id = msg_id, .tag = tag}; mca_btl_ugni_device_t *device = endpoint->smsg_ep_handle.device; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_smsg_send_wtag_device, &args); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_smsg_send_wtag_device, + &args); } -static inline int mca_btl_ugni_smsg_get_next_wtag (mca_btl_ugni_endpoint_handle_t *ep_handle, uintptr_t *data_ptr, uint8_t *tag) +static inline int mca_btl_ugni_smsg_get_next_wtag(mca_btl_ugni_endpoint_handle_t *ep_handle, + uintptr_t *data_ptr, uint8_t *tag) { mca_btl_ugni_device_t *device = ep_handle->device; - mca_btl_ugni_smsg_get_next_wtag_arg_t args = {.ep_handle = ep_handle->gni_handle, .data_ptr = data_ptr, .tag = tag}; - - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_smsg_get_next_wtag_device, &args); + mca_btl_ugni_smsg_get_next_wtag_arg_t args = {.ep_handle = ep_handle->gni_handle, + .data_ptr = data_ptr, + .tag = tag}; + + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_smsg_get_next_wtag_device, + &args); } -static inline int mca_btl_ugni_smsg_release (mca_btl_ugni_endpoint_handle_t *ep_handle) +static inline int mca_btl_ugni_smsg_release(mca_btl_ugni_endpoint_handle_t *ep_handle) { mca_btl_ugni_device_t *device = ep_handle->device; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_smsg_release_device, ep_handle); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_smsg_release_device, + ep_handle); } -static inline void mca_btl_ugni_cq_clear (mca_btl_ugni_device_t *device, gni_cq_handle_t cq) +static inline void mca_btl_ugni_cq_clear(mca_btl_ugni_device_t *device, gni_cq_handle_t cq) { - (void) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_cq_clear_device, (void *) (intptr_t) cq); + (void) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_cq_clear_device, + (void *) (intptr_t) cq); } -static inline int mca_btl_ugni_cq_get_event (mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq, gni_cq_entry_t *event_data) +static inline int mca_btl_ugni_cq_get_event(mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq, + gni_cq_entry_t *event_data) { mca_btl_ugni_cq_get_event_args_t args = {.cq = cq, .event_data = event_data}; /* NTH: normally there would be a check for any outstanding CQ operations but there seems * to be a reason to check the local SMSG completion queue anyway. since this function * only handled the SMSG local completion queue not checking here should be fine and * should not impact performance. */ - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_cq_get_event_device, &args); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_cq_get_event_device, + &args); } -static inline int mca_btl_ugni_gni_cq_get_event (mca_btl_ugni_device_t *device, gni_cq_handle_t cq, gni_cq_entry_t *event_data) +static inline int mca_btl_ugni_gni_cq_get_event(mca_btl_ugni_device_t *device, gni_cq_handle_t cq, + gni_cq_entry_t *event_data) { mca_btl_ugni_gni_cq_get_event_args_t args = {.cq = cq, .event_data = event_data}; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_gni_cq_get_event_device, &args); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_gni_cq_get_event_device, + &args); } -__opal_attribute_always_inline__ -static inline int mca_btl_ugni_endpoint_post (mca_btl_ugni_endpoint_t *endpoint, mca_btl_ugni_post_descriptor_t *desc, - mca_btl_ugni_device_serialize_fn_t post_fn) +__opal_attribute_always_inline__ static inline int +mca_btl_ugni_endpoint_post(mca_btl_ugni_endpoint_t *endpoint, mca_btl_ugni_post_descriptor_t *desc, + mca_btl_ugni_device_serialize_fn_t post_fn) { struct mca_btl_ugni_post_device_args_t args = {.desc = desc}; - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (endpoint); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(endpoint); int rc; - /* use serialize_any as it is responsible for binding devices to threads (if enabled). this generally - * gives better performance as it reduces contention on any individual device. */ - rc = mca_btl_ugni_device_serialize_any (ugni_module, post_fn, &args); + /* use serialize_any as it is responsible for binding devices to threads (if enabled). this + * generally gives better performance as it reduces contention on any individual device. */ + rc = mca_btl_ugni_device_serialize_any(ugni_module, post_fn, &args); if (args.count) { - mca_btl_ugni_handle_rdma_completions (ugni_module, args.device, args.completed, args.count); + mca_btl_ugni_handle_rdma_completions(ugni_module, args.device, args.completed, args.count); } return rc; } -__opal_attribute_always_inline__ -static inline int mca_btl_ugni_endpoint_post_fma (mca_btl_ugni_endpoint_t *endpoint, mca_btl_ugni_post_descriptor_t *desc) +__opal_attribute_always_inline__ static inline int +mca_btl_ugni_endpoint_post_fma(mca_btl_ugni_endpoint_t *endpoint, + mca_btl_ugni_post_descriptor_t *desc) { - return mca_btl_ugni_endpoint_post (endpoint, desc, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_post_fma_device); + return mca_btl_ugni_endpoint_post(endpoint, desc, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_post_fma_device); } -__opal_attribute_always_inline__ -static inline int mca_btl_ugni_endpoint_post_rdma (mca_btl_ugni_endpoint_t *endpoint, mca_btl_ugni_post_descriptor_t *desc) +__opal_attribute_always_inline__ static inline int +mca_btl_ugni_endpoint_post_rdma(mca_btl_ugni_endpoint_t *endpoint, + mca_btl_ugni_post_descriptor_t *desc) { - return mca_btl_ugni_endpoint_post (endpoint, desc, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_post_rdma_device); + return mca_btl_ugni_endpoint_post(endpoint, desc, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_post_rdma_device); } -static inline int mca_btl_ugni_endpoint_post_cqwrite (mca_btl_ugni_endpoint_t *endpoint, mca_btl_ugni_post_descriptor_t *desc) +static inline int mca_btl_ugni_endpoint_post_cqwrite(mca_btl_ugni_endpoint_t *endpoint, + mca_btl_ugni_post_descriptor_t *desc) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (endpoint); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(endpoint); mca_btl_ugni_device_t *device = ugni_module->devices; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_post_cqwrite_device, desc); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_post_cqwrite_device, + desc); } -__opal_attribute_always_inline__ -static inline int mca_btl_ugni_cq_get_completed_desc (mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq, - mca_btl_ugni_post_descriptor_t *post_desc, - int count) +__opal_attribute_always_inline__ static inline int +mca_btl_ugni_cq_get_completed_desc(mca_btl_ugni_device_t *device, mca_btl_ugni_cq_t *cq, + mca_btl_ugni_post_descriptor_t *post_desc, int count) { - mca_btl_ugni_cq_get_completed_desc_arg_t args = {.cq = cq, .post_desc = post_desc, .count = count}; + mca_btl_ugni_cq_get_completed_desc_arg_t args = {.cq = cq, + .post_desc = post_desc, + .count = count}; if (0 == cq->active_operations) { return 0; } - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_cq_get_completed_desc_device, &args); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_cq_get_completed_desc_device, + &args); } -static inline int mca_btl_ugni_get_datagram (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_device_t *device, gni_ep_handle_t *gni_handle, - mca_btl_base_endpoint_t **ep) +static inline int mca_btl_ugni_get_datagram(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_device_t *device, + gni_ep_handle_t *gni_handle, + mca_btl_base_endpoint_t **ep) { - mca_btl_ugni_get_datagram_args_t args = {.ugni_module = ugni_module, .ep = ep, .handle = gni_handle}; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_get_datagram_device, &args); + mca_btl_ugni_get_datagram_args_t args = {.ugni_module = ugni_module, + .ep = ep, + .handle = gni_handle}; + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_get_datagram_device, + &args); } -static inline int mca_btl_ugni_reg_mem (mca_btl_ugni_module_t *ugni_module, void *base, size_t size, mca_btl_ugni_reg_t *ugni_reg, - gni_cq_handle_t cq, int flags) +static inline int mca_btl_ugni_reg_mem(mca_btl_ugni_module_t *ugni_module, void *base, size_t size, + mca_btl_ugni_reg_t *ugni_reg, gni_cq_handle_t cq, int flags) { - mca_btl_ugni_reg_mem_args_t args = {.ugni_module = ugni_module, .base = base, .size = size, - .ugni_reg = ugni_reg, .cq = cq, .flags = flags}; + mca_btl_ugni_reg_mem_args_t args = {.ugni_module = ugni_module, + .base = base, + .size = size, + .ugni_reg = ugni_reg, + .cq = cq, + .flags = flags}; mca_btl_ugni_device_t *device = ugni_module->devices; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_reg_mem_device, &args); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_reg_mem_device, + &args); } -static inline int mca_btl_ugni_dereg_mem (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_reg_t *ugni_reg) +static inline int mca_btl_ugni_dereg_mem(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_reg_t *ugni_reg) { mca_btl_ugni_dereg_mem_arg_t args = {.ugni_module = ugni_module, .ugni_reg = ugni_reg}; mca_btl_ugni_device_t *device = ugni_module->devices; - return (int) mca_btl_ugni_device_serialize (device, (mca_btl_ugni_device_serialize_fn_t) mca_btl_ugni_dereg_mem_device, &args); + return (int) mca_btl_ugni_device_serialize(device, + (mca_btl_ugni_device_serialize_fn_t) + mca_btl_ugni_dereg_mem_device, + &args); } #endif /* BTL_UGNI_DEVICE_H */ diff --git a/opal/mca/btl/ugni/btl_ugni_endpoint.c b/opal/mca/btl/ugni/btl_ugni_endpoint.c index 98e3ca90c8f..d93b5f33679 100644 --- a/opal/mca/btl/ugni/btl_ugni_endpoint.c +++ b/opal/mca/btl/ugni/btl_ugni_endpoint.c @@ -15,34 +15,34 @@ #include "btl_ugni_smsg.h" #include "opal/mca/pmix/pmix-internal.h" -static void mca_btl_ugni_ep_construct (mca_btl_base_endpoint_t *ep) +static void mca_btl_ugni_ep_construct(mca_btl_base_endpoint_t *ep) { - memset ((char *) ep + sizeof(ep->super), 0, sizeof (*ep) - sizeof (ep->super)); + memset((char *) ep + sizeof(ep->super), 0, sizeof(*ep) - sizeof(ep->super)); OBJ_CONSTRUCT(&ep->frag_wait_list, opal_list_t); OBJ_CONSTRUCT(&ep->lock, opal_recursive_mutex_t); } -static void mca_btl_ugni_ep_destruct (mca_btl_base_endpoint_t *ep) +static void mca_btl_ugni_ep_destruct(mca_btl_base_endpoint_t *ep) { OBJ_DESTRUCT(&ep->frag_wait_list); OBJ_DESTRUCT(&ep->lock); - free (ep->remote_attr); + free(ep->remote_attr); } -OBJ_CLASS_INSTANCE(mca_btl_ugni_endpoint_t, opal_list_item_t, - mca_btl_ugni_ep_construct, mca_btl_ugni_ep_destruct); +OBJ_CLASS_INSTANCE(mca_btl_ugni_endpoint_t, opal_list_item_t, mca_btl_ugni_ep_construct, + mca_btl_ugni_ep_destruct); -static int mca_btl_ugni_endpoint_get_modex (mca_btl_base_endpoint_t *ep) +static int mca_btl_ugni_endpoint_get_modex(mca_btl_base_endpoint_t *ep) { mca_btl_ugni_modex_t *modex; size_t msg_size; int rc; - assert (NULL != ep && NULL != ep->peer_proc); + assert(NULL != ep && NULL != ep->peer_proc); /* Receive the modex */ - OPAL_MODEX_RECV(rc, &mca_btl_ugni_component.super.btl_version, - &ep->peer_proc->proc_name, (void **)&modex, &msg_size); + OPAL_MODEX_RECV(rc, &mca_btl_ugni_component.super.btl_version, &ep->peer_proc->proc_name, + (void **) &modex, &msg_size); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error receiving modex")); return rc; @@ -51,22 +51,22 @@ static int mca_btl_ugni_endpoint_get_modex (mca_btl_base_endpoint_t *ep) ep->ep_rem_addr = modex->addr; ep->ep_rem_id = modex->id; + BTL_VERBOSE(("received modex for ep %p. addr: %d, id: %d", (void *) ep, ep->ep_rem_addr, + ep->ep_rem_id)); - BTL_VERBOSE(("received modex for ep %p. addr: %d, id: %d", (void*)ep, ep->ep_rem_addr, ep->ep_rem_id)); - - free (modex); + free(modex); return OPAL_SUCCESS; } -int mca_btl_ugni_init_ep (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_endpoint_t **ep, - mca_btl_ugni_module_t *btl, opal_proc_t *peer_proc) +int mca_btl_ugni_init_ep(mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_endpoint_t **ep, + mca_btl_ugni_module_t *btl, opal_proc_t *peer_proc) { mca_btl_ugni_endpoint_t *endpoint; int rc; endpoint = OBJ_NEW(mca_btl_ugni_endpoint_t); - assert (endpoint != NULL); + assert(endpoint != NULL); endpoint->smsg_progressing = 0; endpoint->state = MCA_BTL_UGNI_EP_STATE_INIT; @@ -74,47 +74,48 @@ int mca_btl_ugni_init_ep (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_endpo /* get the modex info for this endpoint and setup a ugni endpoint. this call may lead * to re-entry through opal_progress(). */ - rc = mca_btl_ugni_endpoint_get_modex (endpoint); + rc = mca_btl_ugni_endpoint_get_modex(endpoint); if (OPAL_SUCCESS != rc) { - assert (0); + assert(0); return rc; } /* add this endpoint to the pointer array */ - endpoint->index = opal_pointer_array_add (&ugni_module->endpoints, endpoint); + endpoint->index = opal_pointer_array_add(&ugni_module->endpoints, endpoint); *ep = endpoint; return OPAL_SUCCESS; } -void mca_btl_ugni_release_ep (mca_btl_ugni_endpoint_t *ep) +void mca_btl_ugni_release_ep(mca_btl_ugni_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); int rc; - opal_mutex_lock (&ep->lock); + opal_mutex_lock(&ep->lock); - rc = mca_btl_ugni_ep_disconnect (ep, false); + rc = mca_btl_ugni_ep_disconnect(ep, false); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_VERBOSE(("btl/ugni error disconnecting endpoint")); } /* TODO -- Clear space at the end of the endpoint array */ - opal_pointer_array_set_item (&ugni_module->endpoints, ep->index, NULL); + opal_pointer_array_set_item(&ugni_module->endpoints, ep->index, NULL); - opal_mutex_unlock (&ep->lock); + opal_mutex_unlock(&ep->lock); OBJ_RELEASE(ep); } -static inline int mca_btl_ugni_ep_smsg_get_mbox (mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); +static inline int mca_btl_ugni_ep_smsg_get_mbox(mca_btl_base_endpoint_t *ep) +{ + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); opal_free_list_item_t *mbox; - assert (NULL == ep->mailbox); + assert(NULL == ep->mailbox); - mbox = opal_free_list_get (&ugni_module->smsg_mboxes); + mbox = opal_free_list_get(&ugni_module->smsg_mboxes); if (OPAL_UNLIKELY(NULL == mbox)) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -123,31 +124,34 @@ static inline int mca_btl_ugni_ep_smsg_get_mbox (mca_btl_base_endpoint_t *ep) { ep->mailbox->attr.index = ep->index; /* per ugni spec we need to zero mailbox data before connecting */ - memset ((char *)ep->mailbox->attr.smsg_attr.msg_buffer + ep->mailbox->attr.smsg_attr.mbox_offset, 0, - ep->mailbox->attr.smsg_attr.buff_size); + memset((char *) ep->mailbox->attr.smsg_attr.msg_buffer + + ep->mailbox->attr.smsg_attr.mbox_offset, + 0, ep->mailbox->attr.smsg_attr.buff_size); return OPAL_SUCCESS; } -static int mca_btl_ugni_ep_send_disconnect (mca_btl_base_endpoint_t *ep) +static int mca_btl_ugni_ep_send_disconnect(mca_btl_base_endpoint_t *ep) { int rc; do { - rc = mca_btl_ugni_endpoint_smsg_send_wtag (ep, NULL, 0, NULL, 0, -1, MCA_BTL_UGNI_TAG_DISCONNECT); + rc = mca_btl_ugni_endpoint_smsg_send_wtag(ep, NULL, 0, NULL, 0, -1, + MCA_BTL_UGNI_TAG_DISCONNECT); if (OPAL_LIKELY(GNI_RC_NOT_DONE != rc)) { break; } - /* most likely got here because we are out of credits. check the remote CQ to get credit return */ - (void) mca_btl_ugni_progress_remote_smsg (mca_btl_ugni_ep_btl (ep)); + /* most likely got here because we are out of credits. check the remote CQ to get credit + * return */ + (void) mca_btl_ugni_progress_remote_smsg(mca_btl_ugni_ep_btl(ep)); } while (1); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } -int mca_btl_ugni_ep_disconnect (mca_btl_base_endpoint_t *ep, bool send_disconnect) +int mca_btl_ugni_ep_disconnect(mca_btl_base_endpoint_t *ep, bool send_disconnect) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); mca_btl_ugni_device_t *device; int rc; @@ -160,14 +164,14 @@ int mca_btl_ugni_ep_disconnect (mca_btl_base_endpoint_t *ep, bool send_disconnec while (device->dev_smsg_local_cq.active_operations) { /* ensure all sends are complete before removing and procs */ - rc = mca_btl_ugni_progress_local_smsg (ugni_module, device); + rc = mca_btl_ugni_progress_local_smsg(ugni_module, device); if (OPAL_SUCCESS != rc) { break; } } if (MCA_BTL_UGNI_EP_STATE_CONNECTED == ep->state && send_disconnect) { - rc = mca_btl_ugni_ep_send_disconnect (ep); + rc = mca_btl_ugni_ep_send_disconnect(ep); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_VERBOSE(("could not send disconnect message to peer")); } @@ -175,25 +179,25 @@ int mca_btl_ugni_ep_disconnect (mca_btl_base_endpoint_t *ep, bool send_disconnec /* wait for the disconnect messagse to go */ do { /* ensure all sends are complete before removing and procs */ - rc = mca_btl_ugni_progress_local_smsg (ugni_module, device); + rc = mca_btl_ugni_progress_local_smsg(ugni_module, device); if (OPAL_SUCCESS != rc) { break; } } while (device->dev_smsg_local_cq.active_operations); - (void) opal_atomic_add_fetch_32 (&ep->smsg_ep_handle.device->smsg_connections, -1); + (void) opal_atomic_add_fetch_32(&ep->smsg_ep_handle.device->smsg_connections, -1); } - mca_btl_ugni_device_lock (device); + mca_btl_ugni_device_lock(device); /* NTH: this call may not need the device lock. seems to work without it but * the lock is here to be safe. */ - (void) mca_btl_ugni_ep_handle_cleanup (&ep->smsg_ep_handle); + (void) mca_btl_ugni_ep_handle_cleanup(&ep->smsg_ep_handle); - mca_btl_ugni_device_unlock (device); + mca_btl_ugni_device_unlock(device); if (ep->mailbox) { - opal_free_list_return (&ugni_module->smsg_mboxes, ((opal_free_list_item_t *) ep->mailbox)); + opal_free_list_return(&ugni_module->smsg_mboxes, ((opal_free_list_item_t *) ep->mailbox)); ep->mailbox = NULL; } @@ -202,8 +206,9 @@ int mca_btl_ugni_ep_disconnect (mca_btl_base_endpoint_t *ep, bool send_disconnec return OPAL_SUCCESS; } -static inline int mca_btl_ugni_ep_connect_start (mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); +static inline int mca_btl_ugni_ep_connect_start(mca_btl_base_endpoint_t *ep) +{ + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); mca_btl_ugni_device_t *device = ugni_module->devices; int rc; @@ -215,24 +220,25 @@ static inline int mca_btl_ugni_ep_connect_start (mca_btl_base_endpoint_t *ep) { ep->state = MCA_BTL_UGNI_EP_STATE_CONNECTING; BTL_VERBOSE(("initiating connection to remote peer with address: %u id: %u proc: %p", - ep->ep_rem_addr, ep->ep_rem_id, (void *)ep->peer_proc)); + ep->ep_rem_addr, ep->ep_rem_id, (void *) ep->peer_proc)); /* bind endpoint to remote address */ /* we bind two endpoints to seperate out local smsg completion and local fma completion */ - mca_btl_ugni_device_lock (device); - rc = mca_btl_ugni_ep_handle_init (ep, device->dev_smsg_local_cq.gni_handle, device, &ep->smsg_ep_handle); - mca_btl_ugni_device_unlock (device); + mca_btl_ugni_device_lock(device); + rc = mca_btl_ugni_ep_handle_init(ep, device->dev_smsg_local_cq.gni_handle, device, + &ep->smsg_ep_handle); + mca_btl_ugni_device_unlock(device); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return rc; } /* build connection data */ - rc = mca_btl_ugni_ep_smsg_get_mbox (ep); + rc = mca_btl_ugni_ep_smsg_get_mbox(ep); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return rc; } - ep->remote_attr = calloc (1, sizeof (*ep->remote_attr)); + ep->remote_attr = calloc(1, sizeof(*ep->remote_attr)); if (OPAL_UNLIKELY(NULL == ep->remote_attr)) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -242,121 +248,128 @@ static inline int mca_btl_ugni_ep_connect_start (mca_btl_base_endpoint_t *ep) { return OPAL_SUCCESS; } -static inline int mca_btl_ugni_ep_connect_finish (mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); +static inline int mca_btl_ugni_ep_connect_finish(mca_btl_base_endpoint_t *ep) +{ + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); gni_return_t grc; int rc; - BTL_VERBOSE(("finishing connection. remote attributes: msg_type = %d, msg_buffer = %p, buff_size = %d, " - "mem_hndl = {qword1 = %" PRIu64 ", qword2 = %" PRIu64 "}, mbox = %d, mbox_maxcredit = %d, " - "msg_maxsize = %d", ep->remote_attr->smsg_attr.msg_type, ep->remote_attr->smsg_attr.msg_buffer, - ep->remote_attr->smsg_attr.buff_size, ep->remote_attr->smsg_attr.mem_hndl.qword1, - ep->remote_attr->smsg_attr.mem_hndl.qword2, ep->remote_attr->smsg_attr.mbox_offset, - ep->remote_attr->smsg_attr.mbox_maxcredit, ep->remote_attr->smsg_attr.msg_maxsize)); - - BTL_VERBOSE(("finishing connection. local attributes: msg_type = %d, msg_buffer = %p, buff_size = %d, " - "mem_hndl = {qword1 = %" PRIu64 ", qword2 = %" PRIu64 "}, mbox = %d, mbox_maxcredit = %d, " - "msg_maxsize = %d", ep->mailbox->attr.smsg_attr.msg_type, ep->mailbox->attr.smsg_attr.msg_buffer, - ep->mailbox->attr.smsg_attr.buff_size, ep->mailbox->attr.smsg_attr.mem_hndl.qword1, - ep->mailbox->attr.smsg_attr.mem_hndl.qword2, ep->mailbox->attr.smsg_attr.mbox_offset, - ep->mailbox->attr.smsg_attr.mbox_maxcredit, ep->mailbox->attr.smsg_attr.msg_maxsize)); - - grc = GNI_SmsgInit (ep->smsg_ep_handle.gni_handle, &ep->mailbox->attr.smsg_attr, - &ep->remote_attr->smsg_attr); + BTL_VERBOSE( + ("finishing connection. remote attributes: msg_type = %d, msg_buffer = %p, buff_size = %d, " + "mem_hndl = {qword1 = %" PRIu64 ", qword2 = %" PRIu64 "}, mbox = %d, mbox_maxcredit = %d, " + "msg_maxsize = %d", + ep->remote_attr->smsg_attr.msg_type, ep->remote_attr->smsg_attr.msg_buffer, + ep->remote_attr->smsg_attr.buff_size, ep->remote_attr->smsg_attr.mem_hndl.qword1, + ep->remote_attr->smsg_attr.mem_hndl.qword2, ep->remote_attr->smsg_attr.mbox_offset, + ep->remote_attr->smsg_attr.mbox_maxcredit, ep->remote_attr->smsg_attr.msg_maxsize)); + + BTL_VERBOSE( + ("finishing connection. local attributes: msg_type = %d, msg_buffer = %p, buff_size = %d, " + "mem_hndl = {qword1 = %" PRIu64 ", qword2 = %" PRIu64 "}, mbox = %d, mbox_maxcredit = %d, " + "msg_maxsize = %d", + ep->mailbox->attr.smsg_attr.msg_type, ep->mailbox->attr.smsg_attr.msg_buffer, + ep->mailbox->attr.smsg_attr.buff_size, ep->mailbox->attr.smsg_attr.mem_hndl.qword1, + ep->mailbox->attr.smsg_attr.mem_hndl.qword2, ep->mailbox->attr.smsg_attr.mbox_offset, + ep->mailbox->attr.smsg_attr.mbox_maxcredit, ep->mailbox->attr.smsg_attr.msg_maxsize)); + + grc = GNI_SmsgInit(ep->smsg_ep_handle.gni_handle, &ep->mailbox->attr.smsg_attr, + &ep->remote_attr->smsg_attr); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != grc)) { BTL_ERROR(("error initializing SMSG protocol. rc = %d", grc)); - return mca_btl_rc_ugni_to_opal (grc); + return mca_btl_rc_ugni_to_opal(grc); } /* set the local event data to the local index and the remote event data to my * index on the remote peer. This makes lookup of endpoints on completion take * a single lookup in the endpoints array. we will not be able to change the * remote peer's index in the endpoint's array after this point. */ - GNI_EpSetEventData (ep->smsg_ep_handle.gni_handle, ep->index, ep->remote_attr->index); + GNI_EpSetEventData(ep->smsg_ep_handle.gni_handle, ep->index, ep->remote_attr->index); ep->rmt_irq_mem_hndl = ep->remote_attr->rmt_irq_mem_hndl; ep->state = MCA_BTL_UGNI_EP_STATE_CONNECTED; - (void) opal_atomic_add_fetch_32 (&ep->smsg_ep_handle.device->smsg_connections, 1); + (void) opal_atomic_add_fetch_32(&ep->smsg_ep_handle.device->smsg_connections, 1); /* send all pending messages */ - BTL_VERBOSE(("endpoint connected. posting %u sends", (unsigned int) opal_list_get_size (&ep->frag_wait_list))); + BTL_VERBOSE(("endpoint connected. posting %u sends", + (unsigned int) opal_list_get_size(&ep->frag_wait_list))); - rc = mca_btl_ugni_progress_send_wait_list (ep); + rc = mca_btl_ugni_progress_send_wait_list(ep); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { OPAL_THREAD_LOCK(&ugni_module->ep_wait_list_lock); if (false == ep->wait_listed) { - opal_list_append (&ugni_module->ep_wait_list, &ep->super); + opal_list_append(&ugni_module->ep_wait_list, &ep->super); ep->wait_listed = true; } OPAL_THREAD_UNLOCK(&ugni_module->ep_wait_list_lock); } - free (ep->remote_attr); + free(ep->remote_attr); ep->remote_attr = NULL; return OPAL_SUCCESS; } -static int mca_btl_ugni_directed_ep_post (mca_btl_base_endpoint_t *ep) +static int mca_btl_ugni_directed_ep_post(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); gni_return_t rc; - BTL_VERBOSE(("posting directed datagram to remote id: %d for endpoint %p", ep->ep_rem_id, (void *)ep)); + BTL_VERBOSE( + ("posting directed datagram to remote id: %d for endpoint %p", ep->ep_rem_id, (void *) ep)); /* the irq cq is associated with only the first device */ ep->mailbox->attr.rmt_irq_mem_hndl = ugni_module->devices->smsg_irq_mhndl; - rc = GNI_EpPostDataWId (ep->smsg_ep_handle.gni_handle, &ep->mailbox->attr, sizeof (ep->mailbox->attr), - ep->remote_attr, sizeof (*ep->remote_attr), - MCA_BTL_UGNI_CONNECT_DIRECTED_ID | ep->index); + rc = GNI_EpPostDataWId(ep->smsg_ep_handle.gni_handle, &ep->mailbox->attr, + sizeof(ep->mailbox->attr), ep->remote_attr, sizeof(*ep->remote_attr), + MCA_BTL_UGNI_CONNECT_DIRECTED_ID | ep->index); if (OPAL_LIKELY(GNI_RC_SUCCESS == rc)) { - (void) opal_atomic_add_fetch_32 (&ugni_module->active_datagrams, 1); + (void) opal_atomic_add_fetch_32(&ugni_module->active_datagrams, 1); } - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } -int mca_btl_ugni_wildcard_ep_post (mca_btl_ugni_module_t *ugni_module) +int mca_btl_ugni_wildcard_ep_post(mca_btl_ugni_module_t *ugni_module) { gni_return_t rc; BTL_VERBOSE(("posting wildcard datagram")); - memset (&ugni_module->wc_local_attr, 0, sizeof (ugni_module->wc_local_attr)); - memset (&ugni_module->wc_remote_attr, 0, sizeof (ugni_module->wc_remote_attr)); - rc = GNI_EpPostDataWId (ugni_module->wildcard_ep, &ugni_module->wc_local_attr, - sizeof (ugni_module->wc_local_attr), &ugni_module->wc_remote_attr, - sizeof (ugni_module->wc_remote_attr), MCA_BTL_UGNI_CONNECT_WILDCARD_ID); + memset(&ugni_module->wc_local_attr, 0, sizeof(ugni_module->wc_local_attr)); + memset(&ugni_module->wc_remote_attr, 0, sizeof(ugni_module->wc_remote_attr)); + rc = GNI_EpPostDataWId(ugni_module->wildcard_ep, &ugni_module->wc_local_attr, + sizeof(ugni_module->wc_local_attr), &ugni_module->wc_remote_attr, + sizeof(ugni_module->wc_remote_attr), MCA_BTL_UGNI_CONNECT_WILDCARD_ID); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } - -int mca_btl_ugni_ep_connect_progress (mca_btl_base_endpoint_t *ep) +int mca_btl_ugni_ep_connect_progress(mca_btl_base_endpoint_t *ep) { int rc; - BTL_VERBOSE(("progressing connection for endpoint %p with state %d", (void *)ep, ep->state)); + BTL_VERBOSE(("progressing connection for endpoint %p with state %d", (void *) ep, ep->state)); if (MCA_BTL_UGNI_EP_STATE_CONNECTED == ep->state) { return OPAL_SUCCESS; } if (MCA_BTL_UGNI_EP_STATE_INIT == ep->state) { - rc = mca_btl_ugni_ep_connect_start (ep); + rc = mca_btl_ugni_ep_connect_start(ep); if (OPAL_SUCCESS != rc) { return rc; } } - BTL_VERBOSE(("ep->remote_attr->smsg_attr = {.msg_type = %d, .msg_buffer = %p}", ep->remote_attr->smsg_attr.msg_type, - (void*)ep->remote_attr->smsg_attr.msg_buffer)); + BTL_VERBOSE(("ep->remote_attr->smsg_attr = {.msg_type = %d, .msg_buffer = %p}", + ep->remote_attr->smsg_attr.msg_type, + (void *) ep->remote_attr->smsg_attr.msg_buffer)); if (GNI_SMSG_TYPE_INVALID == ep->remote_attr->smsg_attr.msg_type) { /* use datagram to exchange connection information with the remote peer */ if (!ep->dg_posted) { - rc = mca_btl_ugni_directed_ep_post (ep); + rc = mca_btl_ugni_directed_ep_post(ep); if (OPAL_SUCCESS == rc) { ep->dg_posted = true; rc = OPAL_ERR_RESOURCE_BUSY; @@ -368,26 +381,27 @@ int mca_btl_ugni_ep_connect_progress (mca_btl_base_endpoint_t *ep) return OPAL_SUCCESS; } - return mca_btl_ugni_ep_connect_finish (ep); + return mca_btl_ugni_ep_connect_finish(ep); } -int mca_btl_ugni_ep_handle_init (mca_btl_ugni_endpoint_t *ep, gni_cq_handle_t cq, - mca_btl_ugni_device_t *device, mca_btl_ugni_endpoint_handle_t *ep_handle) +int mca_btl_ugni_ep_handle_init(mca_btl_ugni_endpoint_t *ep, gni_cq_handle_t cq, + mca_btl_ugni_device_t *device, + mca_btl_ugni_endpoint_handle_t *ep_handle) { gni_return_t grc; ep_handle->device = device; /* create a uGNI endpoint handle and bind it to the remote peer */ - grc = GNI_EpCreate (device->dev_handle, cq, &ep_handle->gni_handle); + grc = GNI_EpCreate(device->dev_handle, cq, &ep_handle->gni_handle); if (OPAL_LIKELY(GNI_RC_SUCCESS == grc)) { - grc = GNI_EpBind (ep_handle->gni_handle, ep->ep_rem_addr, ep->ep_rem_id); + grc = GNI_EpBind(ep_handle->gni_handle, ep->ep_rem_addr, ep->ep_rem_id); } - return mca_btl_rc_ugni_to_opal (grc); + return mca_btl_rc_ugni_to_opal(grc); } -int mca_btl_ugni_ep_handle_cleanup (mca_btl_ugni_endpoint_handle_t *ep_handle) +int mca_btl_ugni_ep_handle_cleanup(mca_btl_ugni_endpoint_handle_t *ep_handle) { int rc; @@ -396,11 +410,11 @@ int mca_btl_ugni_ep_handle_cleanup (mca_btl_ugni_endpoint_handle_t *ep_handle) } /* TODO: need to fix, may be outstanding tx's, etc. */ - rc = GNI_EpUnbind (ep_handle->gni_handle); + rc = GNI_EpUnbind(ep_handle->gni_handle); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { /* should warn */ } else { - (void) GNI_EpDestroy (ep_handle->gni_handle); + (void) GNI_EpDestroy(ep_handle->gni_handle); } ep_handle->gni_handle = 0; diff --git a/opal/mca/btl/ugni/btl_ugni_endpoint.h b/opal/mca/btl/ugni/btl_ugni_endpoint.h index 71bfcca9016..4b6d040f11f 100644 --- a/opal/mca/btl/ugni/btl_ugni_endpoint.h +++ b/opal/mca/btl/ugni/btl_ugni_endpoint.h @@ -75,28 +75,29 @@ typedef struct mca_btl_base_endpoint_t { int index; } mca_btl_base_endpoint_t; -typedef mca_btl_base_endpoint_t mca_btl_ugni_endpoint_t; +typedef mca_btl_base_endpoint_t mca_btl_ugni_endpoint_t; OBJ_CLASS_DECLARATION(mca_btl_ugni_endpoint_t); -int mca_btl_ugni_ep_connect_progress (mca_btl_ugni_endpoint_t *ep); -int mca_btl_ugni_ep_disconnect (mca_btl_ugni_endpoint_t *ep, bool send_disconnect); -int mca_btl_ugni_wildcard_ep_post (mca_btl_ugni_module_t *ugni_module); -void mca_btl_ugni_release_ep (mca_btl_ugni_endpoint_t *ep); -int mca_btl_ugni_init_ep (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_endpoint_t **ep, - mca_btl_ugni_module_t *btl, opal_proc_t *peer_proc); +int mca_btl_ugni_ep_connect_progress(mca_btl_ugni_endpoint_t *ep); +int mca_btl_ugni_ep_disconnect(mca_btl_ugni_endpoint_t *ep, bool send_disconnect); +int mca_btl_ugni_wildcard_ep_post(mca_btl_ugni_module_t *ugni_module); +void mca_btl_ugni_release_ep(mca_btl_ugni_endpoint_t *ep); +int mca_btl_ugni_init_ep(mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_endpoint_t **ep, + mca_btl_ugni_module_t *btl, opal_proc_t *peer_proc); -static inline int mca_btl_ugni_check_endpoint_state (mca_btl_ugni_endpoint_t *ep) { +static inline int mca_btl_ugni_check_endpoint_state(mca_btl_ugni_endpoint_t *ep) +{ int rc; if (OPAL_LIKELY(MCA_BTL_UGNI_EP_STATE_CONNECTED == ep->state)) { return OPAL_SUCCESS; } - opal_mutex_lock (&ep->lock); + opal_mutex_lock(&ep->lock); switch (ep->state) { case MCA_BTL_UGNI_EP_STATE_INIT: - rc = mca_btl_ugni_ep_connect_progress (ep); + rc = mca_btl_ugni_ep_connect_progress(ep); if (OPAL_SUCCESS != rc) { break; } @@ -107,7 +108,7 @@ static inline int mca_btl_ugni_check_endpoint_state (mca_btl_ugni_endpoint_t *ep rc = OPAL_SUCCESS; } - opal_mutex_unlock (&ep->lock); + opal_mutex_unlock(&ep->lock); return rc; } @@ -122,7 +123,7 @@ static inline int mca_btl_ugni_check_endpoint_state (mca_btl_ugni_endpoint_t *ep * pointer in the component structure. This saves 4-8 bytes in the endpoint * structure. */ -static inline mca_btl_ugni_module_t *mca_btl_ugni_ep_btl (mca_btl_ugni_endpoint_t *ep) +static inline mca_btl_ugni_module_t *mca_btl_ugni_ep_btl(mca_btl_ugni_endpoint_t *ep) { /* there is only one ugni module at this time. if that changes add a btl pointer back * to the endpoint structure. */ @@ -137,9 +138,10 @@ static inline mca_btl_ugni_module_t *mca_btl_ugni_ep_btl (mca_btl_ugni_endpoint_ * @param[in] device device to bind with * @param[in] ep_handle endpoint handle to initialize and bind */ -int mca_btl_ugni_ep_handle_init (mca_btl_ugni_endpoint_t *ep, gni_cq_handle_t cq, - mca_btl_ugni_device_t *device, mca_btl_ugni_endpoint_handle_t *ep_handle); +int mca_btl_ugni_ep_handle_init(mca_btl_ugni_endpoint_t *ep, gni_cq_handle_t cq, + mca_btl_ugni_device_t *device, + mca_btl_ugni_endpoint_handle_t *ep_handle); -int mca_btl_ugni_ep_handle_cleanup (mca_btl_ugni_endpoint_handle_t *ep_handle); +int mca_btl_ugni_ep_handle_cleanup(mca_btl_ugni_endpoint_handle_t *ep_handle); #endif /* MCA_BTL_UGNI_ENDPOINT_H */ diff --git a/opal/mca/btl/ugni/btl_ugni_frag.c b/opal/mca/btl/ugni/btl_ugni_frag.c index 5f49e3e3369..c7c0ba6bbfd 100644 --- a/opal/mca/btl/ugni/btl_ugni_frag.c +++ b/opal/mca/btl/ugni/btl_ugni_frag.c @@ -10,21 +10,20 @@ * $HEADER$ */ -#include "btl_ugni.h" #include "btl_ugni_frag.h" +#include "btl_ugni.h" -static inline void mca_btl_ugni_base_frag_constructor (mca_btl_ugni_base_frag_t *frag) +static inline void mca_btl_ugni_base_frag_constructor(mca_btl_ugni_base_frag_t *frag) { - memset ((char *) frag + sizeof (frag->base), 0, sizeof (*frag) - sizeof (frag->base)); + memset((char *) frag + sizeof(frag->base), 0, sizeof(*frag) - sizeof(frag->base)); frag->segments[0].seg_addr.pval = frag->base.super.ptr; } -static inline void mca_btl_ugni_eager_frag_constructor (mca_btl_ugni_base_frag_t *frag) +static inline void mca_btl_ugni_eager_frag_constructor(mca_btl_ugni_base_frag_t *frag) { - struct mca_btl_ugni_reg_t *reg = - (struct mca_btl_ugni_reg_t *) frag->base.super.registration; + struct mca_btl_ugni_reg_t *reg = (struct mca_btl_ugni_reg_t *) frag->base.super.registration; - mca_btl_ugni_base_frag_constructor (frag); + mca_btl_ugni_base_frag_constructor(frag); frag->memory_handle = reg->handle; } @@ -38,7 +37,7 @@ OBJ_CLASS_INSTANCE(mca_btl_ugni_rdma_frag_t, mca_btl_base_descriptor_t, OBJ_CLASS_INSTANCE(mca_btl_ugni_eager_frag_t, mca_btl_base_descriptor_t, mca_btl_ugni_eager_frag_constructor, NULL); -static void mca_btl_ugni_post_descriptor_constructor (mca_btl_ugni_post_descriptor_t *desc) +static void mca_btl_ugni_post_descriptor_constructor(mca_btl_ugni_post_descriptor_t *desc) { desc->cq = NULL; } @@ -46,37 +45,37 @@ static void mca_btl_ugni_post_descriptor_constructor (mca_btl_ugni_post_descript OBJ_CLASS_INSTANCE(mca_btl_ugni_post_descriptor_t, opal_free_list_item_t, mca_btl_ugni_post_descriptor_constructor, NULL); -static void mca_btl_ugni_rdma_desc_constructor (mca_btl_ugni_rdma_desc_t *desc) +static void mca_btl_ugni_rdma_desc_constructor(mca_btl_ugni_rdma_desc_t *desc) { desc->device = NULL; desc->gni_handle = 0; desc->tries = 0; } -static void mca_btl_ugni_rdma_desc_destructor (mca_btl_ugni_rdma_desc_t *desc) +static void mca_btl_ugni_rdma_desc_destructor(mca_btl_ugni_rdma_desc_t *desc) { if (0 != desc->gni_handle) { - (void) GNI_EpDestroy (desc->gni_handle); + (void) GNI_EpDestroy(desc->gni_handle); desc->gni_handle = 0; } } -int mca_btl_ugni_rdma_desc_init (opal_free_list_item_t *item, void *ctx) +int mca_btl_ugni_rdma_desc_init(opal_free_list_item_t *item, void *ctx) { mca_btl_ugni_rdma_desc_t *rdma_desc = (mca_btl_ugni_rdma_desc_t *) item; mca_btl_ugni_device_t *device = (mca_btl_ugni_device_t *) ctx; gni_return_t grc; - grc = GNI_EpCreate (device->dev_handle, device->dev_rdma_local_cq.gni_handle, &rdma_desc->gni_handle); + grc = GNI_EpCreate(device->dev_handle, device->dev_rdma_local_cq.gni_handle, + &rdma_desc->gni_handle); rdma_desc->device = device; - return mca_btl_rc_ugni_to_opal (grc); + return mca_btl_rc_ugni_to_opal(grc); } - OBJ_CLASS_INSTANCE(mca_btl_ugni_rdma_desc_t, opal_free_list_item_t, mca_btl_ugni_rdma_desc_constructor, mca_btl_ugni_rdma_desc_destructor); -int mca_btl_ugni_frag_init (mca_btl_ugni_base_frag_t *frag, void *id) +int mca_btl_ugni_frag_init(mca_btl_ugni_base_frag_t *frag, void *id) { /* NTH: the id is a combination of the module id and the free list id. for now there * is only ever one module so the module id is ignored. if this changes the code @@ -84,7 +83,7 @@ int mca_btl_ugni_frag_init (mca_btl_ugni_base_frag_t *frag, void *id) intptr_t free_list_id = (intptr_t) id & 0xff; mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_component.modules; - frag->msg_id = opal_pointer_array_add (&ugni_module->pending_smsg_frags_bb, (void *) frag); + frag->msg_id = opal_pointer_array_add(&ugni_module->pending_smsg_frags_bb, (void *) frag); frag->my_list = ugni_module->frags_lists + free_list_id; return OPAL_SUCCESS; diff --git a/opal/mca/btl/ugni/btl_ugni_frag.h b/opal/mca/btl/ugni/btl_ugni_frag.h index c8e91568c97..47a67697ce9 100644 --- a/opal/mca/btl/ugni/btl_ugni_frag.h +++ b/opal/mca/btl/ugni/btl_ugni_frag.h @@ -14,12 +14,12 @@ */ #if !defined(MCA_BTL_UGNI_FRAG_H) -#define MCA_BTL_UGNI_FRAG_H +# define MCA_BTL_UGNI_FRAG_H -#include "btl_ugni.h" -#include "btl_ugni_endpoint.h" +# include "btl_ugni.h" +# include "btl_ugni_endpoint.h" -#include +# include typedef struct mca_btl_ugni_send_frag_hdr_t { uint32_t lag; @@ -27,7 +27,7 @@ typedef struct mca_btl_ugni_send_frag_hdr_t { typedef struct mca_btl_ugni_send_ex_frag_hdr_t { mca_btl_ugni_send_frag_hdr_t send; - uint8_t pml_header[128]; + uint8_t pml_header[128]; } mca_btl_ugni_send_ex_frag_hdr_t; typedef struct mca_btl_ugni_rdma_frag_hdr_t { @@ -44,40 +44,40 @@ typedef struct mca_btl_ugni_eager_frag_hdr_t { typedef struct mca_btl_ugni_eager_ex_frag_hdr_t { mca_btl_ugni_eager_frag_hdr_t eager; - uint8_t pml_header[128]; + uint8_t pml_header[128]; } mca_btl_ugni_eager_ex_frag_hdr_t; typedef union mca_btl_ugni_frag_hdr_t { - mca_btl_ugni_send_frag_hdr_t send; - mca_btl_ugni_send_ex_frag_hdr_t send_ex; - mca_btl_ugni_rdma_frag_hdr_t rdma; - mca_btl_ugni_eager_frag_hdr_t eager; + mca_btl_ugni_send_frag_hdr_t send; + mca_btl_ugni_send_ex_frag_hdr_t send_ex; + mca_btl_ugni_rdma_frag_hdr_t rdma; + mca_btl_ugni_eager_frag_hdr_t eager; mca_btl_ugni_eager_ex_frag_hdr_t eager_ex; } mca_btl_ugni_frag_hdr_t; enum { - MCA_BTL_UGNI_FRAG_BUFFERED = 1, /* frag data is buffered */ - MCA_BTL_UGNI_FRAG_COMPLETE = 2, /* smsg complete for frag */ - MCA_BTL_UGNI_FRAG_EAGER = 4, /* eager get frag */ - MCA_BTL_UGNI_FRAG_IGNORE = 8, /* ignore local smsg completion */ + MCA_BTL_UGNI_FRAG_BUFFERED = 1, /* frag data is buffered */ + MCA_BTL_UGNI_FRAG_COMPLETE = 2, /* smsg complete for frag */ + MCA_BTL_UGNI_FRAG_EAGER = 4, /* eager get frag */ + MCA_BTL_UGNI_FRAG_IGNORE = 8, /* ignore local smsg completion */ MCA_BTL_UGNI_FRAG_SMSG_COMPLETE = 16, /* SMSG has completed for this message */ - MCA_BTL_UGNI_FRAG_RESPONSE = 32, + MCA_BTL_UGNI_FRAG_RESPONSE = 32, }; struct mca_btl_ugni_base_frag_t; typedef struct mca_btl_ugni_base_frag_t { - mca_btl_base_descriptor_t base; - opal_atomic_int32_t ref_cnt; - uint32_t msg_id; - uint16_t hdr_size; - uint16_t flags; - mca_btl_ugni_frag_hdr_t hdr; - mca_btl_base_segment_t segments[2]; - gni_post_descriptor_t post_desc; - mca_btl_base_endpoint_t *endpoint; - mca_btl_ugni_reg_t *registration; - opal_free_list_t *my_list; + mca_btl_base_descriptor_t base; + opal_atomic_int32_t ref_cnt; + uint32_t msg_id; + uint16_t hdr_size; + uint16_t flags; + mca_btl_ugni_frag_hdr_t hdr; + mca_btl_base_segment_t segments[2]; + gni_post_descriptor_t post_desc; + mca_btl_base_endpoint_t *endpoint; + mca_btl_ugni_reg_t *registration; + opal_free_list_t *my_list; mca_btl_base_registration_handle_t memory_handle; } mca_btl_ugni_base_frag_t; @@ -123,8 +123,10 @@ typedef struct mca_btl_ugni_rdma_desc_t { OBJ_CLASS_DECLARATION(mca_btl_ugni_rdma_desc_t); -#define MCA_BTL_UGNI_GNI_DESC_TO_RDMA_DESC(desc) \ - ((mca_btl_ugni_rdma_desc_t *) ((uintptr_t)(desc) - offsetof (mca_btl_ugni_rdma_desc_t, btl_ugni_desc) - offsetof (mca_btl_ugni_post_descriptor_t, gni_desc))) +# define MCA_BTL_UGNI_GNI_DESC_TO_RDMA_DESC(desc) \ + ((mca_btl_ugni_rdma_desc_t *) ((uintptr_t)(desc) -offsetof(mca_btl_ugni_rdma_desc_t, \ + btl_ugni_desc) \ + - offsetof(mca_btl_ugni_post_descriptor_t, gni_desc))) /** * Initialize a RDMA descriptor @@ -137,7 +139,7 @@ OBJ_CLASS_DECLARATION(mca_btl_ugni_rdma_desc_t); * descriptor can be used. Usually this is passed as an argument to * opal_free_list_init(). */ -int mca_btl_ugni_rdma_desc_init (opal_free_list_item_t *item, void *ctx); +int mca_btl_ugni_rdma_desc_init(opal_free_list_item_t *item, void *ctx); /** * @brief get an endpoint handle from a device's free list @@ -150,16 +152,18 @@ int mca_btl_ugni_rdma_desc_init (opal_free_list_item_t *item, void *ctx); * the atomic free list to avoid unnecessary atomics in the critical path. */ static inline mca_btl_ugni_rdma_desc_t * -mca_btl_ugni_alloc_rdma_desc (mca_btl_ugni_device_t *device, mca_btl_ugni_post_descriptor_t *ugni_desc, const bool use_bte) +mca_btl_ugni_alloc_rdma_desc(mca_btl_ugni_device_t *device, + mca_btl_ugni_post_descriptor_t *ugni_desc, const bool use_bte) { - mca_btl_ugni_rdma_desc_t *desc = (mca_btl_ugni_rdma_desc_t *) opal_free_list_get_st (&device->rdma_descs); + mca_btl_ugni_rdma_desc_t *desc = (mca_btl_ugni_rdma_desc_t *) opal_free_list_get_st( + &device->rdma_descs); mca_btl_ugni_endpoint_t *ep = ugni_desc->endpoint; gni_return_t grc; if (OPAL_LIKELY(NULL != desc)) { - grc = GNI_EpBind (desc->gni_handle, ep->ep_rem_addr, ep->ep_rem_id | device->dev_index); + grc = GNI_EpBind(desc->gni_handle, ep->ep_rem_addr, ep->ep_rem_id | device->dev_index); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != grc)) { - opal_free_list_return_st (&device->rdma_descs, &desc->super); + opal_free_list_return_st(&device->rdma_descs, &desc->super); return NULL; } @@ -172,20 +176,22 @@ mca_btl_ugni_alloc_rdma_desc (mca_btl_ugni_device_t *device, mca_btl_ugni_post_d return desc; } -static inline void mca_btl_ugni_return_rdma_desc (mca_btl_ugni_rdma_desc_t *desc) +static inline void mca_btl_ugni_return_rdma_desc(mca_btl_ugni_rdma_desc_t *desc) { - (void) GNI_EpUnbind (desc->gni_handle); - opal_free_list_return_st (&desc->device->rdma_descs, &desc->super); + (void) GNI_EpUnbind(desc->gni_handle); + opal_free_list_return_st(&desc->device->rdma_descs, &desc->super); } -static inline void mca_btl_ugni_post_desc_complete (mca_btl_ugni_module_t *module, mca_btl_ugni_post_descriptor_t *desc, int rc) +static inline void mca_btl_ugni_post_desc_complete(mca_btl_ugni_module_t *module, + mca_btl_ugni_post_descriptor_t *desc, int rc) { - BTL_VERBOSE(("RDMA/FMA/ATOMIC operation complete for post descriptor %p. rc = %d", (void *) desc, rc)); + BTL_VERBOSE( + ("RDMA/FMA/ATOMIC operation complete for post descriptor %p. rc = %d", (void *) desc, rc)); if (NULL != desc->cbfunc) { /* call the user's callback function */ - desc->cbfunc (&module->super, desc->endpoint, (void *)(intptr_t) desc->gni_desc.local_addr, - desc->local_handle, desc->ctx, desc->cbdata, rc); + desc->cbfunc(&module->super, desc->endpoint, (void *) (intptr_t) desc->gni_desc.local_addr, + desc->local_handle, desc->ctx, desc->cbdata, rc); } } @@ -193,12 +199,12 @@ OBJ_CLASS_DECLARATION(mca_btl_ugni_smsg_frag_t); OBJ_CLASS_DECLARATION(mca_btl_ugni_rdma_frag_t); OBJ_CLASS_DECLARATION(mca_btl_ugni_eager_frag_t); -int mca_btl_ugni_frag_init (mca_btl_ugni_base_frag_t *frag, void *id); +int mca_btl_ugni_frag_init(mca_btl_ugni_base_frag_t *frag, void *id); -static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc (mca_btl_base_endpoint_t *ep, - opal_free_list_t *list) +static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc(mca_btl_base_endpoint_t *ep, + opal_free_list_t *list) { - mca_btl_ugni_base_frag_t *frag = (mca_btl_ugni_base_frag_t *) opal_free_list_get (list); + mca_btl_ugni_base_frag_t *frag = (mca_btl_ugni_base_frag_t *) opal_free_list_get(list); if (OPAL_LIKELY(NULL != frag)) { frag->endpoint = ep; frag->ref_cnt = 1; @@ -207,33 +213,35 @@ static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc (mca_btl_base_en return frag; } -static inline int mca_btl_ugni_frag_return (mca_btl_ugni_base_frag_t *frag) +static inline int mca_btl_ugni_frag_return(mca_btl_ugni_base_frag_t *frag) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (frag->endpoint); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(frag->endpoint); if (frag->registration) { - ugni_module->rcache->rcache_deregister (ugni_module->rcache, - (mca_rcache_base_registration_t *) frag->registration); + ugni_module->rcache->rcache_deregister(ugni_module->rcache, + (mca_rcache_base_registration_t *) + frag->registration); frag->registration = NULL; } frag->flags = 0; - opal_free_list_return (frag->my_list, (opal_free_list_item_t *) frag); + opal_free_list_return(frag->my_list, (opal_free_list_item_t *) frag); return OPAL_SUCCESS; } -static inline bool mca_btl_ugni_frag_del_ref (mca_btl_ugni_base_frag_t *frag, int rc) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (frag->endpoint); +static inline bool mca_btl_ugni_frag_del_ref(mca_btl_ugni_base_frag_t *frag, int rc) +{ + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(frag->endpoint); /* save the descriptor flags since the callback is allowed to free the frag */ int des_flags = frag->base.des_flags; int32_t ref_cnt; - opal_atomic_mb (); + opal_atomic_mb(); ref_cnt = OPAL_THREAD_ADD_FETCH32(&frag->ref_cnt, -1); if (ref_cnt) { - assert (ref_cnt > 0); + assert(ref_cnt > 0); return false; } @@ -243,56 +251,61 @@ static inline bool mca_btl_ugni_frag_del_ref (mca_btl_ugni_base_frag_t *frag, in } if (des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP) { - mca_btl_ugni_frag_return (frag); + mca_btl_ugni_frag_return(frag); } return true; } -static inline void mca_btl_ugni_frag_complete (mca_btl_ugni_base_frag_t *frag, int rc) { +static inline void mca_btl_ugni_frag_complete(mca_btl_ugni_base_frag_t *frag, int rc) +{ BTL_VERBOSE(("frag complete. flags = %d", frag->base.des_flags)); frag->flags |= MCA_BTL_UGNI_FRAG_COMPLETE; - mca_btl_ugni_frag_del_ref (frag, rc); + mca_btl_ugni_frag_del_ref(frag, rc); } -static inline bool mca_btl_ugni_frag_check_complete (mca_btl_ugni_base_frag_t *frag) { +static inline bool mca_btl_ugni_frag_check_complete(mca_btl_ugni_base_frag_t *frag) +{ return !!(MCA_BTL_UGNI_FRAG_COMPLETE & frag->flags); } +void mca_btl_ugni_wait_list_append(mca_btl_ugni_module_t *ugni_module, + mca_btl_base_endpoint_t *endpoint, + mca_btl_ugni_base_frag_t *frag); -void mca_btl_ugni_wait_list_append (mca_btl_ugni_module_t *ugni_module, mca_btl_base_endpoint_t *endpoint, - mca_btl_ugni_base_frag_t *frag); - -static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_smsg (mca_btl_base_endpoint_t *ep) +static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_smsg(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); - return mca_btl_ugni_frag_alloc (ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_SMSG); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); + return mca_btl_ugni_frag_alloc(ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_SMSG); } -static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_rdma (mca_btl_base_endpoint_t *ep) +static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_rdma(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); - return mca_btl_ugni_frag_alloc (ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); + return mca_btl_ugni_frag_alloc(ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA); } -static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_rdma_int (mca_btl_base_endpoint_t *ep) +static inline mca_btl_ugni_base_frag_t * +mca_btl_ugni_frag_alloc_rdma_int(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); - return mca_btl_ugni_frag_alloc (ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA_INT); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); + return mca_btl_ugni_frag_alloc(ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_RDMA_INT); } -static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_eager_send (mca_btl_base_endpoint_t *ep) +static inline mca_btl_ugni_base_frag_t * +mca_btl_ugni_frag_alloc_eager_send(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); - return mca_btl_ugni_frag_alloc (ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_SEND); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); + return mca_btl_ugni_frag_alloc(ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_SEND); } -static inline mca_btl_ugni_base_frag_t *mca_btl_ugni_frag_alloc_eager_recv (mca_btl_base_endpoint_t *ep) +static inline mca_btl_ugni_base_frag_t * +mca_btl_ugni_frag_alloc_eager_recv(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); - return mca_btl_ugni_frag_alloc (ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_RECV); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); + return mca_btl_ugni_frag_alloc(ep, ugni_module->frags_lists + MCA_BTL_UGNI_LIST_EAGER_RECV); } #endif /* MCA_BTL_UGNI_FRAG_H */ diff --git a/opal/mca/btl/ugni/btl_ugni_get.c b/opal/mca/btl/ugni/btl_ugni_get.c index e5189c0d2e1..30279aa9af3 100644 --- a/opal/mca/btl/ugni/btl_ugni_get.c +++ b/opal/mca/btl/ugni/btl_ugni_get.c @@ -13,22 +13,24 @@ #include "btl_ugni_rdma.h" #include "btl_ugni_smsg.h" -/* +/* * taken from osc_rdma_comm.h, ugh. */ -#define ALIGNMENT_MASK(x) ((x) ? (x) - 1 : 0) +#define ALIGNMENT_MASK(x) ((x) ? (x) -1 : 0) -int mca_btl_ugni_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ugni_get(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { bool check; /* Check if the get is aligned/sized on a multiple of 4 */ - check = !!((remote_address | (uint64_t)(intptr_t) local_address | size) & - ALIGNMENT_MASK(mca_btl_ugni_module.super.btl_get_alignment)); + check = !!((remote_address | (uint64_t)(intptr_t) local_address | size) + & ALIGNMENT_MASK(mca_btl_ugni_module.super.btl_get_alignment)); if (OPAL_UNLIKELY(check || size > mca_btl_ugni_module.super.btl_get_limit)) { BTL_VERBOSE(("RDMA/FMA Get not available due to size or alignment restrictions")); @@ -40,43 +42,48 @@ int mca_btl_ugni_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t BTL_VERBOSE(("Using RDMA/FMA Get %lu bytes to local address %p to remote address %" PRIx64, (unsigned long) size, local_address, remote_address)); - return mca_btl_ugni_post (endpoint, true, size, local_address, remote_address, local_handle, - remote_handle, order, cbfunc, cbcontext, cbdata); + return mca_btl_ugni_post(endpoint, true, size, local_address, remote_address, local_handle, + remote_handle, order, cbfunc, cbcontext, cbdata); } /* eager get */ -static void mca_btl_ugni_callback_eager_get_progress_pending (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - struct mca_btl_base_descriptor_t *desc, int rc) +static void +mca_btl_ugni_callback_eager_get_progress_pending(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *desc, int rc) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; mca_btl_ugni_base_frag_t *pending_frag, *frag = (mca_btl_ugni_base_frag_t *) desc; - memset (&frag->hdr, 0, sizeof (frag->hdr)); + memset(&frag->hdr, 0, sizeof(frag->hdr)); OPAL_THREAD_LOCK(&ugni_module->eager_get_pending_lock); - pending_frag = (mca_btl_ugni_base_frag_t *) opal_list_remove_first (&ugni_module->eager_get_pending); + pending_frag = (mca_btl_ugni_base_frag_t *) opal_list_remove_first( + &ugni_module->eager_get_pending); OPAL_THREAD_UNLOCK(&ugni_module->eager_get_pending_lock); if (NULL != pending_frag) { /* copy the relevant data out of the pending fragment */ frag->endpoint = pending_frag->endpoint; - assert (frag != pending_frag); + assert(frag != pending_frag); /* start the next eager get using this fragment */ - (void) mca_btl_ugni_start_eager_get (frag->endpoint, pending_frag->hdr.eager_ex, frag); + (void) mca_btl_ugni_start_eager_get(frag->endpoint, pending_frag->hdr.eager_ex, frag); /* return the temporary fragment */ - mca_btl_ugni_frag_return (pending_frag); + mca_btl_ugni_frag_return(pending_frag); } else { /* not needed anymore */ - mca_btl_ugni_frag_return (frag); + mca_btl_ugni_frag_return(frag); } } -static void mca_btl_ugni_callback_eager_get (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, - void *local_address, mca_btl_base_registration_handle_t *local_handle, - void *context, void *cbdata, int status) +static void mca_btl_ugni_callback_eager_get(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + void *local_address, + mca_btl_base_registration_handle_t *local_handle, + void *context, void *cbdata, int status) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; mca_btl_ugni_base_frag_t *frag = (mca_btl_ugni_base_frag_t *) context; @@ -86,21 +93,23 @@ static void mca_btl_ugni_callback_eager_get (struct mca_btl_base_module_t *btl, size_t hdr_len = len - payload_len; mca_btl_active_message_callback_t *reg = mca_btl_base_active_message_trigger + tag; mca_btl_base_segment_t segs[2]; - const mca_btl_base_receive_descriptor_t tmp = {.endpoint = endpoint, .des_segments = segs, + const mca_btl_base_receive_descriptor_t tmp = {.endpoint = endpoint, + .des_segments = segs, .des_segment_count = hdr_len ? 2 : 1, - .tag = tag, .cbdata = reg->cbdata}; + .tag = tag, + .cbdata = reg->cbdata}; int rc; BTL_VERBOSE(("eager get for rem_ctx %p complete", frag->hdr.eager.ctx)) if (hdr_len) { segs[0].seg_addr.pval = frag->hdr.eager_ex.pml_header; - segs[0].seg_len = hdr_len; + segs[0].seg_len = hdr_len; segs[1].seg_addr.pval = local_address; - segs[1].seg_len = payload_len; + segs[1].seg_len = payload_len; } else { segs[0].seg_addr.pval = local_address; - segs[0].seg_len = payload_len; + segs[0].seg_len = payload_len; } reg->cbfunc(&ugni_module->super, &tmp); @@ -116,19 +125,19 @@ static void mca_btl_ugni_callback_eager_get (struct mca_btl_base_module_t *btl, frag->base.des_cbfunc = mca_btl_ugni_callback_eager_get_progress_pending; /* tell the remote peer the operation is complete */ - rc = opal_mca_btl_ugni_smsg_send (frag, &frag->hdr.rdma, sizeof (frag->hdr.rdma), - NULL, 0, MCA_BTL_UGNI_TAG_RDMA_COMPLETE); + rc = opal_mca_btl_ugni_smsg_send(frag, &frag->hdr.rdma, sizeof(frag->hdr.rdma), NULL, 0, + MCA_BTL_UGNI_TAG_RDMA_COMPLETE); if (OPAL_UNLIKELY(0 > rc)) { /* queue fragment */ - mca_btl_ugni_wait_list_append (ugni_module, endpoint, frag); + mca_btl_ugni_wait_list_append(ugni_module, endpoint, frag); } } -int mca_btl_ugni_start_eager_get (mca_btl_base_endpoint_t *endpoint, - mca_btl_ugni_eager_ex_frag_hdr_t hdr, - mca_btl_ugni_base_frag_t *frag) +int mca_btl_ugni_start_eager_get(mca_btl_base_endpoint_t *endpoint, + mca_btl_ugni_eager_ex_frag_hdr_t hdr, + mca_btl_ugni_base_frag_t *frag) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (endpoint); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(endpoint); size_t size; int rc = OPAL_SUCCESS; @@ -137,13 +146,13 @@ int mca_btl_ugni_start_eager_get (mca_btl_base_endpoint_t *endpoint, do { if (NULL == frag) { /* try to allocate a registered buffer */ - frag = mca_btl_ugni_frag_alloc_eager_recv (endpoint); + frag = mca_btl_ugni_frag_alloc_eager_recv(endpoint); if (OPAL_UNLIKELY(NULL == frag)) { /* no registered buffers available. try again later */ - frag = mca_btl_ugni_frag_alloc_rdma_int (endpoint); + frag = mca_btl_ugni_frag_alloc_rdma_int(endpoint); /* not much can be done if a small fragment can not be allocated. abort! */ - assert (NULL != frag); + assert(NULL != frag); frag->hdr.eager_ex = hdr; break; } @@ -157,19 +166,19 @@ int mca_btl_ugni_start_eager_get (mca_btl_base_endpoint_t *endpoint, size = (hdr.eager.size + 3) & ~3; /* set up callback for get completion */ - frag->base.des_flags = MCA_BTL_DES_SEND_ALWAYS_CALLBACK; + frag->base.des_flags = MCA_BTL_DES_SEND_ALWAYS_CALLBACK; /* start the get */ - rc = mca_btl_ugni_post (endpoint, true, size, frag->base.super.ptr, hdr.eager.address, - &frag->memory_handle, &hdr.eager.memory_handle, - MCA_BTL_NO_ORDER, mca_btl_ugni_callback_eager_get, frag, NULL); + rc = mca_btl_ugni_post(endpoint, true, size, frag->base.super.ptr, hdr.eager.address, + &frag->memory_handle, &hdr.eager.memory_handle, MCA_BTL_NO_ORDER, + mca_btl_ugni_callback_eager_get, frag, NULL); if (OPAL_UNLIKELY(OPAL_SUCCESS == rc)) { return OPAL_SUCCESS; } } while (0); OPAL_THREAD_LOCK(&ugni_module->eager_get_pending_lock); - opal_list_append (&ugni_module->eager_get_pending, (opal_list_item_t *) frag); + opal_list_append(&ugni_module->eager_get_pending, (opal_list_item_t *) frag); OPAL_THREAD_UNLOCK(&ugni_module->eager_get_pending_lock); return rc; diff --git a/opal/mca/btl/ugni/btl_ugni_init.c b/opal/mca/btl/ugni/btl_ugni_init.c index e29d3da2510..95f52ddf512 100644 --- a/opal/mca/btl/ugni/btl_ugni_init.c +++ b/opal/mca/btl/ugni/btl_ugni_init.c @@ -14,15 +14,14 @@ * $HEADER$ */ - #include "btl_ugni.h" #include "btl_ugni_endpoint.h" #include "btl_ugni_frag.h" #include "opal/class/opal_list.h" +#include "opal/mca/hwloc/base/base.h" #include "opal/mca/pmix/pmix-internal.h" #include "opal/util/bit_ops.h" -#include "opal/mca/hwloc/base/base.h" static inline int get_ptag(uint8_t *out_ptag) { @@ -35,7 +34,7 @@ static inline int get_ptag(uint8_t *out_ptag) return OPAL_ERR_NOT_FOUND; } errno = 0; - tmp_ptag = (uint8_t)strtoul (ptr, (char **)NULL, 10); + tmp_ptag = (uint8_t) strtoul(ptr, (char **) NULL, 10); if (0 != errno) { /* TODO add err msg - better rc? */ return OPAL_ERR_VALUE_OUT_OF_BOUNDS; @@ -44,7 +43,7 @@ static inline int get_ptag(uint8_t *out_ptag) return OPAL_SUCCESS; } -static inline int get_cookie (uint32_t *out_cookie) +static inline int get_cookie(uint32_t *out_cookie) { /* TODO no need for tmp */ char *ptr; @@ -55,7 +54,7 @@ static inline int get_cookie (uint32_t *out_cookie) return OPAL_ERR_NOT_FOUND; } errno = 0; - tmp_cookie = (uint32_t) strtoul (ptr, NULL, 10); + tmp_cookie = (uint32_t) strtoul(ptr, NULL, 10); if (0 != errno) { /* TODO add err msg - better rc? */ return OPAL_ERR_VALUE_OUT_OF_BOUNDS; @@ -70,14 +69,14 @@ static unsigned int mca_btl_ugni_get_nic_address(int device_id) unsigned int address, cpu_id; gni_return_t status; int i, alps_dev_id = -1; - char *token,*p_ptr; + char *token, *p_ptr; p_ptr = getenv("PMI_GNI_DEV_ID"); if (!p_ptr) { status = GNI_CdmGetNicAddress(device_id, &address, &cpu_id); - if(status != GNI_RC_SUCCESS) { - opal_output (0, "FAILED:GNI_CdmGetNicAddress returned error %d", status); - return (unsigned int)-1; + if (status != GNI_RC_SUCCESS) { + opal_output(0, "FAILED:GNI_CdmGetNicAddress returned error %d", status); + return (unsigned int) -1; } return address; } @@ -91,27 +90,27 @@ static unsigned int mca_btl_ugni_get_nic_address(int device_id) } if (OPAL_UNLIKELY(-1 == alps_dev_id)) { - return (unsigned int)-1; + return (unsigned int) -1; } p_ptr = getenv("PMI_GNI_LOC_ADDR"); if (OPAL_UNLIKELY(NULL == p_ptr)) { - return (unsigned int)-1; + return (unsigned int) -1; } i = 0; while (NULL != (token = strtok(p_ptr, ":"))) { if (i == alps_dev_id) { - return strtoul (token, NULL, 10); + return strtoul(token, NULL, 10); } p_ptr = NULL; ++i; } - return (unsigned int)-1; + return (unsigned int) -1; } -int mca_btl_ugni_device_init (mca_btl_ugni_device_t *device, int virtual_device_id) +int mca_btl_ugni_device_init(mca_btl_ugni_device_t *device, int virtual_device_id) { uint32_t dev_pe_addr; int rc; @@ -119,12 +118,14 @@ int mca_btl_ugni_device_init (mca_btl_ugni_device_t *device, int virtual_device_ OBJ_CONSTRUCT(&device->rdma_descs, opal_free_list_t); /* create a communication domain */ - rc = GNI_CdmCreate (mca_btl_ugni_component.cdm_id_base | virtual_device_id, mca_btl_ugni_component.ptag, - mca_btl_ugni_component.cookie, mca_btl_ugni_component.cdm_flags, &device->dev_cd_handle); + rc = GNI_CdmCreate(mca_btl_ugni_component.cdm_id_base | virtual_device_id, + mca_btl_ugni_component.ptag, mca_btl_ugni_component.cookie, + mca_btl_ugni_component.cdm_flags, &device->dev_cd_handle); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { /* this REALLY is an error but under alps + mapn we may not get any credentials */ - BTL_VERBOSE(("Error: Creating communication domain %d for virtual device %d", rc, virtual_device_id)); - return mca_btl_rc_ugni_to_opal (rc); + BTL_VERBOSE(("Error: Creating communication domain %d for virtual device %d", rc, + virtual_device_id)); + return mca_btl_rc_ugni_to_opal(rc); } device->dev_index = virtual_device_id; @@ -133,16 +134,17 @@ int mca_btl_ugni_device_init (mca_btl_ugni_device_t *device, int virtual_device_ OPAL_OUTPUT((-1, "Got NIC Addr: 0x%08x, CPU ID: %d", mca_btl_ugni_component.dev_addr, 0)); /* Attach device to the communication domain */ - rc = GNI_CdmAttach (device->dev_cd_handle, 0, &dev_pe_addr, &device->dev_handle); + rc = GNI_CdmAttach(device->dev_cd_handle, 0, &dev_pe_addr, &device->dev_handle); if (GNI_RC_SUCCESS != rc) { - BTL_VERBOSE(("Error: Attaching to communication domain. rc = %d, virtual device = %d", rc, virtual_device_id)); - return mca_btl_rc_ugni_to_opal (rc); + BTL_VERBOSE(("Error: Attaching to communication domain. rc = %d, virtual device = %d", rc, + virtual_device_id)); + return mca_btl_rc_ugni_to_opal(rc); } - rc = opal_free_list_init (&device->rdma_descs, sizeof (mca_btl_ugni_rdma_desc_t), - 64, OBJ_CLASS(mca_btl_ugni_rdma_desc_t), 0, 8, 0, - mca_btl_ugni_component.local_rdma_cq_size, 32, - NULL, 0, NULL, mca_btl_ugni_rdma_desc_init, (void *) device); + rc = opal_free_list_init(&device->rdma_descs, sizeof(mca_btl_ugni_rdma_desc_t), 64, + OBJ_CLASS(mca_btl_ugni_rdma_desc_t), 0, 8, 0, + mca_btl_ugni_component.local_rdma_cq_size, 32, NULL, 0, NULL, + mca_btl_ugni_rdma_desc_init, (void *) device); if (OPAL_SUCCESS != rc) { OBJ_DESTRUCT(&device->rdma_descs); return rc; @@ -160,28 +162,28 @@ int mca_btl_ugni_device_init (mca_btl_ugni_device_t *device, int virtual_device_ return OPAL_SUCCESS; } -int mca_btl_ugni_device_fini (mca_btl_ugni_device_t *dev) +int mca_btl_ugni_device_fini(mca_btl_ugni_device_t *dev) { int rc; OBJ_DESTRUCT(&dev->rdma_descs); if (0 != dev->dev_rdma_local_cq.gni_handle) { - GNI_CqDestroy (dev->dev_rdma_local_cq.gni_handle); + GNI_CqDestroy(dev->dev_rdma_local_cq.gni_handle); dev->dev_rdma_local_cq.gni_handle = 0; } if (0 != dev->dev_rdma_local_irq_cq.gni_handle) { - GNI_CqDestroy (dev->dev_rdma_local_irq_cq.gni_handle); + GNI_CqDestroy(dev->dev_rdma_local_irq_cq.gni_handle); dev->dev_rdma_local_irq_cq.gni_handle = 0; } if (0 != dev->dev_smsg_local_cq.gni_handle) { - GNI_CqDestroy (dev->dev_smsg_local_cq.gni_handle); + GNI_CqDestroy(dev->dev_smsg_local_cq.gni_handle); dev->dev_smsg_local_cq.gni_handle = 0; } - rc = GNI_CdmDestroy (dev->dev_cd_handle); + rc = GNI_CdmDestroy(dev->dev_cd_handle); if (GNI_RC_SUCCESS != rc) { BTL_VERBOSE(("error destroying cdm handle")); } @@ -193,49 +195,47 @@ int mca_btl_ugni_device_fini (mca_btl_ugni_device_t *dev) * Send local device information and other information * required for setup */ -static int mca_btl_ugni_send_modex (void) +static int mca_btl_ugni_send_modex(void) { struct mca_btl_ugni_modex_t modex; uint32_t modex_size; char *modex_msg; int rc; - modex_size = sizeof (struct mca_btl_ugni_modex_t); + modex_size = sizeof(struct mca_btl_ugni_modex_t); - modex_msg = (char *) malloc (modex_size); + modex_msg = (char *) malloc(modex_size); if (NULL == modex_msg) { - OPAL_OUTPUT((-1, "Error allocating memory for modex @ %s:%d", - __FILE__, __LINE__)); + OPAL_OUTPUT((-1, "Error allocating memory for modex @ %s:%d", __FILE__, __LINE__)); return OPAL_ERR_OUT_OF_RESOURCE; } modex.addr = mca_btl_ugni_component.dev_addr; - modex.id = mca_btl_ugni_component.cdm_id_base; + modex.id = mca_btl_ugni_component.cdm_id_base; BTL_VERBOSE(("sending modex. addr: %d, id: %d", modex.addr, modex.id)); - memcpy ((void *) modex_msg, (void *) &modex, modex_size); + memcpy((void *) modex_msg, (void *) &modex, modex_size); /* * need global for edge cases like MPI_Comm_spawn support with * new ranks started on the same nodes as the spawnee ranks, etc. */ - OPAL_MODEX_SEND(rc, PMIX_GLOBAL, - &mca_btl_ugni_component.super.btl_version, - modex_msg, modex_size); + OPAL_MODEX_SEND(rc, PMIX_GLOBAL, &mca_btl_ugni_component.super.btl_version, modex_msg, + modex_size); - free (modex_msg); + free(modex_msg); return rc; } -int mca_btl_ugni_fini (void) +int mca_btl_ugni_fini(void) { return OPAL_SUCCESS; } -int mca_btl_ugni_init (void) +int mca_btl_ugni_init(void) { int32_t pid_max = 32768; int rc, bit; @@ -244,15 +244,16 @@ int mca_btl_ugni_init (void) if (0 == mca_btl_ugni_component.virtual_device_count) { int core_count; - (void) opal_hwloc_base_get_topology (); - core_count = hwloc_get_nbobjs_by_type (opal_hwloc_topology, HWLOC_OBJ_CORE); + (void) opal_hwloc_base_get_topology(); + core_count = hwloc_get_nbobjs_by_type(opal_hwloc_topology, HWLOC_OBJ_CORE); if (core_count <= opal_process_info.num_local_peers || !opal_using_threads()) { /* there is probably no benefit to using multiple device contexts when not * using threads. */ mca_btl_ugni_component.virtual_device_count = 1; } else { - mca_btl_ugni_component.virtual_device_count = core_count / (opal_process_info.num_local_peers + 1); + mca_btl_ugni_component.virtual_device_count = core_count + / (opal_process_info.num_local_peers + 1); } } @@ -268,12 +269,13 @@ int mca_btl_ugni_init (void) } } - if ((mca_btl_ugni_component.virtual_device_count * (1 + opal_process_info.num_local_peers)) < 122) { - /* if there are fewer total devices than FMA descriptors it makes sense to turn off FMA sharing. - * *DO NOT* override a user requested flag. */ + if ((mca_btl_ugni_component.virtual_device_count * (1 + opal_process_info.num_local_peers)) + < 122) { + /* if there are fewer total devices than FMA descriptors it makes sense to turn off FMA + * sharing. *DO NOT* override a user requested flag. */ mca_base_var_source_t source = MCA_BASE_VAR_SOURCE_DEFAULT; - mca_base_var_get_value (mca_btl_ugni_component.cdm_flags_id, NULL, &source, NULL); + mca_base_var_get_value(mca_btl_ugni_component.cdm_flags_id, NULL, &source, NULL); if (MCA_BASE_VAR_SOURCE_DEFAULT == source) { BTL_VERBOSE(("disabling shared FMA sharing")); @@ -282,16 +284,16 @@ int mca_btl_ugni_init (void) } } - fh = fopen ("/proc/sys/kernel/pid_max", "r"); + fh = fopen("/proc/sys/kernel/pid_max", "r"); if (NULL != fh) { - fscanf (fh, "%d", &pid_max); - fclose (fh); + fscanf(fh, "%d", &pid_max); + fclose(fh); } /* Use pid to generate the cdm_id. Although its not stated in the uGNI * documentation, the cdm_id only needs to be unique within a node for a * given ptag/cookie tuple */ - bit = opal_hibit (pid_max, 31); + bit = opal_hibit(pid_max, 31); if (bit >= 31) { mca_btl_ugni_component.virtual_device_count = 1; mca_btl_ugni_component.cdm_id_base = getpid(); @@ -315,10 +317,10 @@ int mca_btl_ugni_init (void) } /* get the device address of the NIC */ - mca_btl_ugni_component.dev_addr = mca_btl_ugni_get_nic_address (0); + mca_btl_ugni_component.dev_addr = mca_btl_ugni_get_nic_address(0); /* send ugni modex */ - mca_btl_ugni_send_modex (); + mca_btl_ugni_send_modex(); return OPAL_SUCCESS; } diff --git a/opal/mca/btl/ugni/btl_ugni_module.c b/opal/mca/btl/ugni/btl_ugni_module.c index 3993e4c2524..3915be11c39 100644 --- a/opal/mca/btl/ugni/btl_ugni_module.c +++ b/opal/mca/btl/ugni/btl_ugni_module.c @@ -16,94 +16,88 @@ #include "opal_config.h" #include "btl_ugni.h" -#include "btl_ugni_frag.h" #include "btl_ugni_endpoint.h" +#include "btl_ugni_frag.h" #include "btl_ugni_prepare.h" #include "btl_ugni_smsg.h" -static int -mca_btl_ugni_free (struct mca_btl_base_module_t *btl, - mca_btl_base_descriptor_t *des); +static int mca_btl_ugni_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des); -static int -mca_btl_ugni_module_finalize (struct mca_btl_base_module_t* btl); +static int mca_btl_ugni_module_finalize(struct mca_btl_base_module_t *btl); static struct mca_btl_base_descriptor_t * -mca_btl_ugni_prepare_src (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, size_t reserve, size_t *size, - uint32_t flags); +mca_btl_ugni_prepare_src(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, + size_t *size, uint32_t flags); static mca_btl_base_registration_handle_t * -mca_btl_ugni_register_mem (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags); - -static int mca_btl_ugni_deregister_mem (mca_btl_base_module_t *btl, mca_btl_base_registration_handle_t *handle); - -mca_btl_ugni_module_t mca_btl_ugni_module = { - .super = { - .btl_component = &mca_btl_ugni_component.super, - .btl_add_procs = mca_btl_ugni_add_procs, - .btl_del_procs = mca_btl_ugni_del_procs, - .btl_finalize = mca_btl_ugni_module_finalize, - .btl_alloc = mca_btl_ugni_alloc, - .btl_free = mca_btl_ugni_free, - .btl_prepare_src = mca_btl_ugni_prepare_src, - .btl_send = mca_btl_ugni_send, - .btl_sendi = mca_btl_ugni_sendi, - .btl_put = mca_btl_ugni_put, - .btl_get = mca_btl_ugni_get, - .btl_register_mem = mca_btl_ugni_register_mem, - .btl_deregister_mem = mca_btl_ugni_deregister_mem, - .btl_atomic_op = mca_btl_ugni_aop, - .btl_atomic_fop = mca_btl_ugni_afop, - .btl_atomic_cswap = mca_btl_ugni_acswap, - .btl_flush = mca_btl_ugni_flush, - } -}; - -static void mca_btl_ugni_datagram_event (int foo, short bar, void *arg) +mca_btl_ugni_register_mem(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *base, + size_t size, uint32_t flags); + +static int mca_btl_ugni_deregister_mem(mca_btl_base_module_t *btl, + mca_btl_base_registration_handle_t *handle); + +mca_btl_ugni_module_t mca_btl_ugni_module = {.super = { + .btl_component = &mca_btl_ugni_component.super, + .btl_add_procs = mca_btl_ugni_add_procs, + .btl_del_procs = mca_btl_ugni_del_procs, + .btl_finalize = mca_btl_ugni_module_finalize, + .btl_alloc = mca_btl_ugni_alloc, + .btl_free = mca_btl_ugni_free, + .btl_prepare_src = mca_btl_ugni_prepare_src, + .btl_send = mca_btl_ugni_send, + .btl_sendi = mca_btl_ugni_sendi, + .btl_put = mca_btl_ugni_put, + .btl_get = mca_btl_ugni_get, + .btl_register_mem = mca_btl_ugni_register_mem, + .btl_deregister_mem = mca_btl_ugni_deregister_mem, + .btl_atomic_op = mca_btl_ugni_aop, + .btl_atomic_fop = mca_btl_ugni_afop, + .btl_atomic_cswap = mca_btl_ugni_acswap, + .btl_flush = mca_btl_ugni_flush, + }}; + +static void mca_btl_ugni_datagram_event(int foo, short bar, void *arg) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) arg; mca_btl_ugni_device_t *device = ugni_module->devices; struct timeval tv = {.tv_sec = 0, .tv_usec = MCA_BTL_UGNI_CONNECT_USEC}; - mca_btl_ugni_progress_datagram (device); + mca_btl_ugni_progress_datagram(device); - opal_event_evtimer_add (&ugni_module->connection_event, &tv); + opal_event_evtimer_add(&ugni_module->connection_event, &tv); } -int -mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module) +int mca_btl_ugni_module_init(mca_btl_ugni_module_t *ugni_module) { int rc; BTL_VERBOSE(("binding module %p to device 0", (void *) ugni_module)); /* copy module defaults (and function pointers) */ - memmove (ugni_module, &mca_btl_ugni_module, sizeof (mca_btl_ugni_module)); + memmove(ugni_module, &mca_btl_ugni_module, sizeof(mca_btl_ugni_module)); ugni_module->initialized = false; ugni_module->nlocal_procs = 0; ugni_module->active_datagrams = 0; ugni_module->active_rdma_count = 0; - opal_event_evtimer_set (opal_sync_event_base, &ugni_module->connection_event, - mca_btl_ugni_datagram_event, ugni_module); + opal_event_evtimer_set(opal_sync_event_base, &ugni_module->connection_event, + mca_btl_ugni_datagram_event, ugni_module); OBJ_CONSTRUCT(&ugni_module->failed_frags, opal_list_t); OBJ_CONSTRUCT(&ugni_module->failed_frags_lock, opal_mutex_t); OBJ_CONSTRUCT(&ugni_module->eager_get_pending, opal_list_t); - OBJ_CONSTRUCT(&ugni_module->eager_get_pending_lock,opal_mutex_t); + OBJ_CONSTRUCT(&ugni_module->eager_get_pending_lock, opal_mutex_t); - for (int i = 0 ; i < MCA_BTL_UGNI_LIST_MAX ; ++i) { + for (int i = 0; i < MCA_BTL_UGNI_LIST_MAX; ++i) { OBJ_CONSTRUCT(ugni_module->frags_lists + i, opal_free_list_t); } OBJ_CONSTRUCT(&ugni_module->pending_smsg_frags_bb, opal_pointer_array_t); - OBJ_CONSTRUCT(&ugni_module->ep_wait_list_lock,opal_mutex_t); + OBJ_CONSTRUCT(&ugni_module->ep_wait_list_lock, opal_mutex_t); OBJ_CONSTRUCT(&ugni_module->ep_wait_list, opal_list_t); OBJ_CONSTRUCT(&ugni_module->endpoint_lock, opal_mutex_t); OBJ_CONSTRUCT(&ugni_module->endpoints, opal_pointer_array_t); @@ -112,8 +106,8 @@ mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module) OBJ_CONSTRUCT(&ugni_module->eager_get_pending, opal_list_t); /* set up virtual device handles */ - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { - rc = mca_btl_ugni_device_init (ugni_module->devices + i, i); + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { + rc = mca_btl_ugni_device_init(ugni_module->devices + i, i); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_VERBOSE(("error initializing uGNI device handle")); return rc; @@ -123,15 +117,14 @@ mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module) /* create wildcard endpoint on first device to listen for connections. * there is no need to bind this endpoint. We are single threaded * here so there is no need for a device lock. */ - rc = GNI_EpCreate (ugni_module->devices[0].dev_handle, NULL, - &ugni_module->wildcard_ep); + rc = GNI_EpCreate(ugni_module->devices[0].dev_handle, NULL, &ugni_module->wildcard_ep); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error creating wildcard ugni endpoint")); - return mca_btl_rc_ugni_to_opal (rc); + return mca_btl_rc_ugni_to_opal(rc); } /* post wildcard datagram */ - rc = mca_btl_ugni_wildcard_ep_post (ugni_module); + rc = mca_btl_ugni_wildcard_ep_post(ugni_module); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { BTL_ERROR(("error posting wildcard datagram")); return rc; @@ -140,19 +133,18 @@ mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module) return OPAL_SUCCESS; } -static int -mca_btl_ugni_module_finalize (struct mca_btl_base_module_t *btl) +static int mca_btl_ugni_module_finalize(struct mca_btl_base_module_t *btl) { - mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *)btl; + mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; mca_btl_base_endpoint_t *ep; uint64_t key; int rc; if (ugni_module->initialized) { /* close all open connections and release endpoints */ - OPAL_HASH_TABLE_FOREACH(key, uint64, ep, &ugni_module->id_to_endpoint) { + OPAL_HASH_TABLE_FOREACH (key, uint64, ep, &ugni_module->id_to_endpoint) { if (NULL != ep) { - mca_btl_ugni_release_ep (ep); + mca_btl_ugni_release_ep(ep); } } @@ -161,36 +153,35 @@ mca_btl_ugni_module_finalize (struct mca_btl_base_module_t *btl) } /* destroy all cqs */ - rc = GNI_CqDestroy (ugni_module->smsg_remote_cq); + rc = GNI_CqDestroy(ugni_module->smsg_remote_cq); if (GNI_RC_SUCCESS != rc) { - BTL_ERROR(("error tearing down RX SMSG CQ - %s",gni_err_str[rc])); + BTL_ERROR(("error tearing down RX SMSG CQ - %s", gni_err_str[rc])); } if (mca_btl_ugni_component.progress_thread_enabled) { - rc = GNI_CqDestroy (ugni_module->smsg_remote_irq_cq); + rc = GNI_CqDestroy(ugni_module->smsg_remote_irq_cq); if (GNI_RC_SUCCESS != rc) { - BTL_ERROR(("error tearing down remote SMSG CQ - %s",gni_err_str[rc])); + BTL_ERROR(("error tearing down remote SMSG CQ - %s", gni_err_str[rc])); } } /* cancel wildcard post */ - rc = GNI_EpPostDataCancelById (ugni_module->wildcard_ep, - MCA_BTL_UGNI_CONNECT_WILDCARD_ID | - OPAL_PROC_MY_NAME.vpid); + rc = GNI_EpPostDataCancelById(ugni_module->wildcard_ep, + MCA_BTL_UGNI_CONNECT_WILDCARD_ID | OPAL_PROC_MY_NAME.vpid); if (GNI_RC_SUCCESS != rc) { BTL_VERBOSE(("btl/ugni error cancelling wildcard post")); } /* tear down wildcard endpoint */ - rc = GNI_EpDestroy (ugni_module->wildcard_ep); + rc = GNI_EpDestroy(ugni_module->wildcard_ep); if (GNI_RC_SUCCESS != rc) { - BTL_VERBOSE(("btl/ugni error destroying endpoint - %s",gni_err_str[rc])); + BTL_VERBOSE(("btl/ugni error destroying endpoint - %s", gni_err_str[rc])); } - opal_event_del (&ugni_module->connection_event); + opal_event_del(&ugni_module->connection_event); } - for (int i = 0 ; i < MCA_BTL_UGNI_LIST_MAX ; ++i) { + for (int i = 0; i < MCA_BTL_UGNI_LIST_MAX; ++i) { OBJ_DESTRUCT(ugni_module->frags_lists + i); } @@ -205,11 +196,11 @@ mca_btl_ugni_module_finalize (struct mca_btl_base_module_t *btl) OBJ_DESTRUCT(&ugni_module->eager_get_pending_lock); if (ugni_module->rcache) { - mca_rcache_base_module_destroy (ugni_module->rcache); + mca_rcache_base_module_destroy(ugni_module->rcache); } - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { - mca_btl_ugni_device_fini (ugni_module->devices + i); + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { + mca_btl_ugni_device_fini(ugni_module->devices + i); } ugni_module->initialized = false; @@ -217,25 +208,23 @@ mca_btl_ugni_module_finalize (struct mca_btl_base_module_t *btl) return OPAL_SUCCESS; } - -mca_btl_base_descriptor_t * -mca_btl_ugni_alloc(struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t size, uint32_t flags) +mca_btl_base_descriptor_t *mca_btl_ugni_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { mca_btl_ugni_base_frag_t *frag = NULL; /* do not allocate a fragment unless the wait list is relatively small. this * reduces the potential for resource exhaustion. note the wait list only exists * because we have no way to notify the sender that credits are available. */ - if (OPAL_UNLIKELY(opal_list_get_size (&endpoint->frag_wait_list) > 32)) { + if (OPAL_UNLIKELY(opal_list_get_size(&endpoint->frag_wait_list) > 32)) { return NULL; } if (size <= mca_btl_ugni_component.smsg_max_data) { - frag = mca_btl_ugni_frag_alloc_smsg (endpoint); + frag = mca_btl_ugni_frag_alloc_smsg(endpoint); } else if (size <= btl->btl_eager_limit) { - frag = mca_btl_ugni_frag_alloc_eager_send (endpoint); + frag = mca_btl_ugni_frag_alloc_eager_send(endpoint); } if (OPAL_UNLIKELY(NULL == frag)) { @@ -243,7 +232,7 @@ mca_btl_ugni_alloc(struct mca_btl_base_module_t *btl, } BTL_VERBOSE(("btl/ugni_module allocated frag of size: %u, flags: %x. frag = %p", - (unsigned int)size, flags, (void *) frag)); + (unsigned int) size, flags, (void *) frag)); frag->base.des_flags = flags; frag->base.order = order; @@ -251,63 +240,58 @@ mca_btl_ugni_alloc(struct mca_btl_base_module_t *btl, frag->base.des_segment_count = 1; frag->segments[0].seg_addr.pval = NULL; - frag->segments[0].seg_len = 0; + frag->segments[0].seg_len = 0; frag->segments[1].seg_addr.pval = frag->base.super.ptr; - frag->segments[1].seg_len = size; + frag->segments[1].seg_len = size; frag->flags = MCA_BTL_UGNI_FRAG_BUFFERED; if (size > mca_btl_ugni_component.smsg_max_data) { mca_btl_ugni_reg_t *registration; - frag->hdr_size = sizeof (frag->hdr.eager); - frag->flags |= MCA_BTL_UGNI_FRAG_EAGER | MCA_BTL_UGNI_FRAG_IGNORE; + frag->hdr_size = sizeof(frag->hdr.eager); + frag->flags |= MCA_BTL_UGNI_FRAG_EAGER | MCA_BTL_UGNI_FRAG_IGNORE; registration = (mca_btl_ugni_reg_t *) frag->base.super.registration; frag->hdr.eager.memory_handle = registration->handle; } else { - frag->hdr_size = sizeof (frag->hdr.send); + frag->hdr_size = sizeof(frag->hdr.send); } return &frag->base; } -static int -mca_btl_ugni_free (struct mca_btl_base_module_t *btl, - mca_btl_base_descriptor_t *des) +static int mca_btl_ugni_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { - return mca_btl_ugni_frag_return ((mca_btl_ugni_base_frag_t *) des); + return mca_btl_ugni_frag_return((mca_btl_ugni_base_frag_t *) des); } static struct mca_btl_base_descriptor_t * -mca_btl_ugni_prepare_src (struct mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, size_t reserve, size_t *size, - uint32_t flags) +mca_btl_ugni_prepare_src(struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, + size_t *size, uint32_t flags) { /* do not allocate a fragment unless the wait list is relatively small. this * reduces the potential for resource exhaustion. note the wait list only exists * because we have no way to notify the sender that credits are available. */ - if (OPAL_UNLIKELY(opal_list_get_size (&endpoint->frag_wait_list) > 32)) { + if (OPAL_UNLIKELY(opal_list_get_size(&endpoint->frag_wait_list) > 32)) { return NULL; } - return mca_btl_ugni_prepare_src_send (btl, endpoint, convertor, - order, reserve, size, flags); + return mca_btl_ugni_prepare_src_send(btl, endpoint, convertor, order, reserve, size, flags); } static mca_btl_base_registration_handle_t * -mca_btl_ugni_register_mem (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *base, - size_t size, uint32_t flags) +mca_btl_ugni_register_mem(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *base, + size_t size, uint32_t flags) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; mca_btl_ugni_reg_t *reg; int access_flags = flags & MCA_BTL_REG_FLAG_ACCESS_ANY; int rc; - rc = ugni_module->rcache->rcache_register (ugni_module->rcache, base, size, 0, access_flags, - (mca_rcache_base_registration_t **) ®); + rc = ugni_module->rcache->rcache_register(ugni_module->rcache, base, size, 0, access_flags, + (mca_rcache_base_registration_t **) ®); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { return NULL; } @@ -315,18 +299,19 @@ mca_btl_ugni_register_mem (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t * return ®->handle; } -static int mca_btl_ugni_deregister_mem (mca_btl_base_module_t *btl, mca_btl_base_registration_handle_t *handle) +static int mca_btl_ugni_deregister_mem(mca_btl_base_module_t *btl, + mca_btl_base_registration_handle_t *handle) { mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; - mca_btl_ugni_reg_t *reg = - (mca_btl_ugni_reg_t *)((intptr_t) handle - offsetof (mca_btl_ugni_reg_t, handle)); + mca_btl_ugni_reg_t *reg = (mca_btl_ugni_reg_t *) ((intptr_t) handle + - offsetof(mca_btl_ugni_reg_t, handle)); - (void) ugni_module->rcache->rcache_deregister (ugni_module->rcache, ®->base); + (void) ugni_module->rcache->rcache_deregister(ugni_module->rcache, ®->base); return OPAL_SUCCESS; } -int mca_btl_ugni_event_fatal_error (gni_return_t grc, gni_cq_entry_t event_data) +int mca_btl_ugni_event_fatal_error(gni_return_t grc, gni_cq_entry_t event_data) { /* combined error check for get event and get completed. we might miss exactly * what happened but it is unrecoverable anyway. fwiw, this error path has @@ -339,24 +324,27 @@ int mca_btl_ugni_event_fatal_error (gni_return_t grc, gni_cq_entry_t event_data) BTL_ERROR(("Error in GNI_GetComplete %s", gni_err_str[grc])); } - return mca_btl_rc_ugni_to_opal (grc); + return mca_btl_rc_ugni_to_opal(grc); } -int mca_btl_ugni_device_handle_event_error (mca_btl_ugni_rdma_desc_t *rdma_desc, gni_cq_entry_t event_data) +int mca_btl_ugni_device_handle_event_error(mca_btl_ugni_rdma_desc_t *rdma_desc, + gni_cq_entry_t event_data) { mca_btl_ugni_device_t *device = rdma_desc->device; uint32_t recoverable = 1; - (void) GNI_CqErrorRecoverable (event_data, &recoverable); + (void) GNI_CqErrorRecoverable(event_data, &recoverable); - if (OPAL_UNLIKELY(++rdma_desc->tries >= mca_btl_ugni_component.rdma_max_retries || !recoverable)) { + if (OPAL_UNLIKELY(++rdma_desc->tries >= mca_btl_ugni_component.rdma_max_retries + || !recoverable)) { char char_buffer[1024]; - GNI_CqErrorStr (event_data, char_buffer, sizeof (char_buffer)); + GNI_CqErrorStr(event_data, char_buffer, sizeof(char_buffer)); - BTL_ERROR(("giving up on desciptor %p, recoverable %d: %s", (void *) rdma_desc, recoverable, char_buffer)); + BTL_ERROR(("giving up on desciptor %p, recoverable %d: %s", (void *) rdma_desc, recoverable, + char_buffer)); return OPAL_ERROR; } - return _mca_btl_ugni_repost_rdma_desc_device (device, rdma_desc); + return _mca_btl_ugni_repost_rdma_desc_device(device, rdma_desc); } diff --git a/opal/mca/btl/ugni/btl_ugni_prepare.h b/opal/mca/btl/ugni/btl_ugni_prepare.h index 9d2da1954cf..d3692bb56dd 100644 --- a/opal/mca/btl/ugni/btl_ugni_prepare.h +++ b/opal/mca/btl/ugni/btl_ugni_prepare.h @@ -11,50 +11,46 @@ */ #if !defined(MCA_BTL_UGNI_PREPARE_H) -#define MCA_BTL_UGNI_PREPARE_H +# define MCA_BTL_UGNI_PREPARE_H -#include "opal_config.h" +# include "opal_config.h" -#include "btl_ugni.h" -#include "btl_ugni_frag.h" +# include "btl_ugni.h" +# include "btl_ugni_frag.h" static inline struct mca_btl_base_descriptor_t * -mca_btl_ugni_prepare_src_send_nodata (struct mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - uint8_t order, size_t reserve, - uint32_t flags) +mca_btl_ugni_prepare_src_send_nodata(struct mca_btl_base_module_t *btl, + mca_btl_base_endpoint_t *endpoint, uint8_t order, + size_t reserve, uint32_t flags) { mca_btl_ugni_base_frag_t *frag = NULL; - frag = mca_btl_ugni_frag_alloc_rdma (endpoint); + frag = mca_btl_ugni_frag_alloc_rdma(endpoint); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } BTL_VERBOSE(("preparing src for send fragment. size = %u", (unsigned int) reserve)); - frag->hdr_size = reserve + sizeof (frag->hdr.send); + frag->hdr_size = reserve + sizeof(frag->hdr.send); frag->segments[0].seg_addr.pval = frag->hdr.send_ex.pml_header; - frag->segments[0].seg_len = reserve; + frag->segments[0].seg_len = reserve; frag->segments[1].seg_addr.pval = NULL; - frag->segments[1].seg_len = 0; + frag->segments[1].seg_len = 0; - frag->base.des_segments = frag->segments; + frag->base.des_segments = frag->segments; frag->base.des_segment_count = 1; - frag->base.order = order; - frag->base.des_flags = flags; + frag->base.order = order; + frag->base.des_flags = flags; return &frag->base; } -static inline struct mca_btl_base_descriptor_t * -mca_btl_ugni_prepare_src_send_inplace (struct mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, size_t reserve, size_t *size, - uint32_t flags) +static inline struct mca_btl_base_descriptor_t *mca_btl_ugni_prepare_src_send_inplace( + struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, uint32_t flags) { bool use_eager_get = (*size + reserve) > mca_btl_ugni_component.smsg_max_data; mca_btl_ugni_module_t *ugni_module = (mca_btl_ugni_module_t *) btl; @@ -63,56 +59,54 @@ mca_btl_ugni_prepare_src_send_inplace (struct mca_btl_base_module_t *btl, void *data_ptr; int rc; - opal_convertor_get_current_pointer (convertor, &data_ptr); + opal_convertor_get_current_pointer(convertor, &data_ptr); - frag = mca_btl_ugni_frag_alloc_rdma (endpoint); + frag = mca_btl_ugni_frag_alloc_rdma(endpoint); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } - BTL_VERBOSE(("preparing src for send fragment. size = %u", - (unsigned int)(*size + reserve))); + BTL_VERBOSE(("preparing src for send fragment. size = %u", (unsigned int) (*size + reserve))); if (OPAL_UNLIKELY(true == use_eager_get)) { - rc = ugni_module->rcache->rcache_register (ugni_module->rcache, data_ptr, *size, 0, - MCA_RCACHE_ACCESS_REMOTE_READ, - (mca_rcache_base_registration_t **)®istration); + rc = ugni_module->rcache + ->rcache_register(ugni_module->rcache, data_ptr, *size, 0, + MCA_RCACHE_ACCESS_REMOTE_READ, + (mca_rcache_base_registration_t **) ®istration); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - mca_btl_ugni_frag_return (frag); + mca_btl_ugni_frag_return(frag); return NULL; } frag->flags = MCA_BTL_UGNI_FRAG_EAGER | MCA_BTL_UGNI_FRAG_IGNORE; frag->registration = registration; - frag->hdr.eager.memory_handle = registration->handle;; + frag->hdr.eager.memory_handle = registration->handle; + ; - frag->hdr_size = reserve + sizeof (frag->hdr.eager); + frag->hdr_size = reserve + sizeof(frag->hdr.eager); frag->segments[0].seg_addr.pval = frag->hdr.eager_ex.pml_header; } else { - frag->hdr_size = reserve + sizeof (frag->hdr.send); + frag->hdr_size = reserve + sizeof(frag->hdr.send); frag->segments[0].seg_addr.pval = frag->hdr.send_ex.pml_header; } - frag->segments[0].seg_len = reserve; + frag->segments[0].seg_len = reserve; frag->segments[1].seg_addr.pval = data_ptr; - frag->segments[1].seg_len = *size; + frag->segments[1].seg_len = *size; - frag->base.des_segments = frag->segments; + frag->base.des_segments = frag->segments; frag->base.des_segment_count = 2; - frag->base.order = order; - frag->base.des_flags = flags; + frag->base.order = order; + frag->base.des_flags = flags; return &frag->base; } -static inline struct mca_btl_base_descriptor_t * -mca_btl_ugni_prepare_src_send_buffered (struct mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, size_t reserve, size_t *size, - uint32_t flags) +static inline struct mca_btl_base_descriptor_t *mca_btl_ugni_prepare_src_send_buffered( + struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, uint32_t flags) { bool use_eager_get = (*size + reserve) > mca_btl_ugni_component.smsg_max_data; mca_btl_ugni_reg_t *registration = NULL; @@ -122,7 +116,7 @@ mca_btl_ugni_prepare_src_send_buffered (struct mca_btl_base_module_t *btl, int rc; if (OPAL_UNLIKELY(true == use_eager_get)) { - frag = mca_btl_ugni_frag_alloc_eager_send (endpoint); + frag = mca_btl_ugni_frag_alloc_eager_send(endpoint); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } @@ -132,68 +126,67 @@ mca_btl_ugni_prepare_src_send_buffered (struct mca_btl_base_module_t *btl, registration = (mca_btl_ugni_reg_t *) frag->base.super.registration; frag->hdr.eager.memory_handle = registration->handle; - frag->hdr_size = reserve + sizeof (frag->hdr.eager); + frag->hdr_size = reserve + sizeof(frag->hdr.eager); frag->segments[0].seg_addr.pval = frag->hdr.eager_ex.pml_header; } else { - frag = mca_btl_ugni_frag_alloc_smsg (endpoint); + frag = mca_btl_ugni_frag_alloc_smsg(endpoint); if (OPAL_UNLIKELY(NULL == frag)) { return NULL; } - frag->hdr_size = reserve + sizeof (frag->hdr.send); + frag->hdr_size = reserve + sizeof(frag->hdr.send); frag->segments[0].seg_addr.pval = frag->hdr.send_ex.pml_header; } frag->flags |= MCA_BTL_UGNI_FRAG_BUFFERED; - iov.iov_len = *size; + iov.iov_len = *size; iov.iov_base = (IOVBASE_TYPE *) frag->base.super.ptr; - rc = opal_convertor_pack (convertor, &iov, &iov_count, size); + rc = opal_convertor_pack(convertor, &iov, &iov_count, size); if (OPAL_UNLIKELY(rc < 0)) { - mca_btl_ugni_frag_return (frag); + mca_btl_ugni_frag_return(frag); return NULL; } - frag->segments[0].seg_len = reserve; + frag->segments[0].seg_len = reserve; frag->segments[1].seg_addr.pval = frag->base.super.ptr; - frag->segments[1].seg_len = *size; + frag->segments[1].seg_len = *size; - frag->base.des_segments = frag->segments; + frag->base.des_segments = frag->segments; frag->base.des_segment_count = 2; - frag->base.order = order; - frag->base.des_flags = flags; + frag->base.order = order; + frag->base.des_flags = flags; return &frag->base; } static inline struct mca_btl_base_descriptor_t * -mca_btl_ugni_prepare_src_send (struct mca_btl_base_module_t *btl, - mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, size_t reserve, size_t *size, - uint32_t flags) +mca_btl_ugni_prepare_src_send(struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, + size_t *size, uint32_t flags) { bool use_eager_get = (*size + reserve) > mca_btl_ugni_component.smsg_max_data; bool send_in_place; void *data_ptr; if (!(*size)) { - return mca_btl_ugni_prepare_src_send_nodata (btl, endpoint, order, reserve, flags); + return mca_btl_ugni_prepare_src_send_nodata(btl, endpoint, order, reserve, flags); } - opal_convertor_get_current_pointer (convertor, &data_ptr); + opal_convertor_get_current_pointer(convertor, &data_ptr); - send_in_place = (btl->btl_flags & MCA_BTL_FLAGS_SEND_INPLACE) && !(opal_convertor_need_buffers(convertor) || - (use_eager_get && ((uintptr_t)data_ptr & 3))); + send_in_place = (btl->btl_flags & MCA_BTL_FLAGS_SEND_INPLACE) + && !(opal_convertor_need_buffers(convertor) + || (use_eager_get && ((uintptr_t) data_ptr & 3))); if (send_in_place) { - return mca_btl_ugni_prepare_src_send_inplace (btl, endpoint, convertor, order, - reserve, size, flags); + return mca_btl_ugni_prepare_src_send_inplace(btl, endpoint, convertor, order, reserve, size, + flags); } else { - return mca_btl_ugni_prepare_src_send_buffered (btl, endpoint, convertor, order, - reserve, size, flags); + return mca_btl_ugni_prepare_src_send_buffered(btl, endpoint, convertor, order, reserve, + size, flags); } } diff --git a/opal/mca/btl/ugni/btl_ugni_progress_thread.c b/opal/mca/btl/ugni/btl_ugni_progress_thread.c index 3fa03911409..71cc1c9a411 100644 --- a/opal/mca/btl/ugni/btl_ugni_progress_thread.c +++ b/opal/mca/btl/ugni/btl_ugni_progress_thread.c @@ -18,20 +18,19 @@ #include "opal/include/opal/align.h" - static pthread_t mca_btl_ugni_progress_thread_id; static volatile int stop_progress_thread = 0; unsigned int mca_btl_ugni_progress_thread_wakeups = 0; -static void *mca_btl_ugni_prog_thread_fn(void * data) +static void *mca_btl_ugni_prog_thread_fn(void *data) { uint32_t which; gni_return_t status; gni_cq_handle_t cq_vec[1 + MCA_BTL_UGNI_MAX_DEV_HANDLES]; - struct mca_btl_ugni_module_t *btl = (mca_btl_ugni_module_t *)data; + struct mca_btl_ugni_module_t *btl = (mca_btl_ugni_module_t *) data; int cq_count = 1 + mca_btl_ugni_component.virtual_device_count; /* @@ -39,7 +38,7 @@ static void *mca_btl_ugni_prog_thread_fn(void * data) */ cq_vec[0] = btl->smsg_remote_irq_cq; - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { cq_vec[i + 1] = btl->devices[i].dev_rdma_local_irq_cq.gni_handle; } @@ -49,12 +48,10 @@ static void *mca_btl_ugni_prog_thread_fn(void * data) * this ugni call doesn't need a lock */ - status = GNI_CqVectorMonitor(cq_vec, - cq_count, - -1, - &which); + status = GNI_CqVectorMonitor(cq_vec, cq_count, -1, &which); - if (status == GNI_RC_NOT_DONE) continue; + if (status == GNI_RC_NOT_DONE) + continue; if ((status == GNI_RC_SUCCESS) && (stop_progress_thread == 0)) { mca_btl_ugni_progress_thread_wakeups++; @@ -67,38 +64,38 @@ static void *mca_btl_ugni_prog_thread_fn(void * data) int mca_btl_ugni_spawn_progress_thread(struct mca_btl_base_module_t *btl) { - int rc, ret=OPAL_SUCCESS; + int rc, ret = OPAL_SUCCESS; pthread_attr_t attr; pthread_attr_init(&attr); rc = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (0 != rc) { - BTL_ERROR(("btl/ugni pthread_attr_setdetachstate returned %s ",strerror(rc))); + BTL_ERROR(("btl/ugni pthread_attr_setdetachstate returned %s ", strerror(rc))); ret = OPAL_ERROR; goto fn_exit; } - rc = pthread_create(&mca_btl_ugni_progress_thread_id, - &attr, mca_btl_ugni_prog_thread_fn, (void *)btl); + rc = pthread_create(&mca_btl_ugni_progress_thread_id, &attr, mca_btl_ugni_prog_thread_fn, + (void *) btl); if (0 != rc) { - BTL_ERROR(("btl/ugni pthread_create returned %s ",strerror(rc))); + BTL_ERROR(("btl/ugni pthread_create returned %s ", strerror(rc))); ret = OPAL_ERROR; goto fn_exit; } rc = pthread_attr_destroy(&attr); if (0 != rc) { - BTL_ERROR(("btl/ugni pthread_attr_destory returned %s ",strerror(rc))); + BTL_ERROR(("btl/ugni pthread_attr_destory returned %s ", strerror(rc))); ret = OPAL_ERROR; } - fn_exit: +fn_exit: return ret; } int mca_btl_ugni_kill_progress_thread(void) { - int ret=OPAL_SUCCESS; + int ret = OPAL_SUCCESS; void *thread_rc; stop_progress_thread = 1; @@ -107,26 +104,25 @@ int mca_btl_ugni_kill_progress_thread(void) * post a CQ to myself to wake my thread up */ - ret = mca_btl_ugni_post_cqwrite (mca_btl_ugni_component.modules[0].local_ep, - &mca_btl_ugni_component.modules[0].devices[0].dev_rdma_local_cq, - mca_btl_ugni_component.modules[0].devices[0].smsg_irq_mhndl, - 0xdead, NULL, NULL, NULL); + ret = mca_btl_ugni_post_cqwrite(mca_btl_ugni_component.modules[0].local_ep, + &mca_btl_ugni_component.modules[0].devices[0].dev_rdma_local_cq, + mca_btl_ugni_component.modules[0].devices[0].smsg_irq_mhndl, + 0xdead, NULL, NULL, NULL); /* * TODO: if error returned, need to kill off thread manually */ if (OPAL_SUCCESS != ret) { /* force the thread to exit */ - pthread_cancel (mca_btl_ugni_progress_thread_id); + pthread_cancel(mca_btl_ugni_progress_thread_id); goto fn_exit; } - pthread_join (mca_btl_ugni_progress_thread_id, &thread_rc); + pthread_join(mca_btl_ugni_progress_thread_id, &thread_rc); if (0 != (intptr_t) thread_rc) { BTL_ERROR(("btl/ugni error returned from progress thread: %d", (int) (intptr_t) thread_rc)); - ret = (int)(intptr_t) thread_rc; + ret = (int) (intptr_t) thread_rc; } - fn_exit: +fn_exit: return ret; } - diff --git a/opal/mca/btl/ugni/btl_ugni_put.c b/opal/mca/btl/ugni/btl_ugni_put.c index 71ab146f040..f688b59621e 100644 --- a/opal/mca/btl/ugni/btl_ugni_put.c +++ b/opal/mca/btl/ugni/btl_ugni_put.c @@ -14,14 +14,16 @@ #include "btl_ugni_rdma.h" -int mca_btl_ugni_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address, - uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) +int mca_btl_ugni_put(mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata) { BTL_VERBOSE(("Using RDMA/FMA Put %lu bytes from local address %p to remote address %" PRIx64, (unsigned long) size, local_address, remote_address)); - return mca_btl_ugni_post (endpoint, false, size, local_address, remote_address, local_handle, - remote_handle, order, cbfunc, cbcontext, cbdata); + return mca_btl_ugni_post(endpoint, false, size, local_address, remote_address, local_handle, + remote_handle, order, cbfunc, cbcontext, cbdata); } diff --git a/opal/mca/btl/ugni/btl_ugni_rdma.h b/opal/mca/btl/ugni/btl_ugni_rdma.h index 31096d2fcb4..61a7b24aa7b 100644 --- a/opal/mca/btl/ugni/btl_ugni_rdma.h +++ b/opal/mca/btl/ugni/btl_ugni_rdma.h @@ -11,52 +11,49 @@ */ #if !defined(MCA_BTL_UGNI_RDMA_H) -#define MCA_BTL_UGNI_RDMA_H - -#include "btl_ugni.h" -#include "btl_ugni_frag.h" -#include "btl_ugni_device.h" - -int mca_btl_ugni_start_eager_get (mca_btl_base_endpoint_t *ep, - mca_btl_ugni_eager_ex_frag_hdr_t hdr, - mca_btl_ugni_base_frag_t *frag); - -static inline void init_post_desc (mca_btl_ugni_post_descriptor_t *post_desc, - mca_btl_base_endpoint_t *endpoint, int order, - gni_post_type_t op_type, uint64_t lcl_addr, - gni_mem_handle_t lcl_mdh, uint64_t rem_addr, - gni_mem_handle_t rem_mdh, uint64_t bufsize, - gni_cq_handle_t cq_hndl, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata, - mca_btl_base_registration_handle_t *local_handle) { +# define MCA_BTL_UGNI_RDMA_H + +# include "btl_ugni.h" +# include "btl_ugni_device.h" +# include "btl_ugni_frag.h" + +int mca_btl_ugni_start_eager_get(mca_btl_base_endpoint_t *ep, mca_btl_ugni_eager_ex_frag_hdr_t hdr, + mca_btl_ugni_base_frag_t *frag); + +static inline void +init_post_desc(mca_btl_ugni_post_descriptor_t *post_desc, mca_btl_base_endpoint_t *endpoint, + int order, gni_post_type_t op_type, uint64_t lcl_addr, gni_mem_handle_t lcl_mdh, + uint64_t rem_addr, gni_mem_handle_t rem_mdh, uint64_t bufsize, + gni_cq_handle_t cq_hndl, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, + void *cbdata, mca_btl_base_registration_handle_t *local_handle) +{ post_desc->endpoint = endpoint; post_desc->cbfunc = cbfunc; post_desc->ctx = cbcontext; post_desc->cbdata = cbdata; post_desc->local_handle = local_handle; - post_desc->gni_desc.type = op_type; - post_desc->gni_desc.cq_mode = GNI_CQMODE_GLOBAL_EVENT; + post_desc->gni_desc.type = op_type; + post_desc->gni_desc.cq_mode = GNI_CQMODE_GLOBAL_EVENT; if (MCA_BTL_NO_ORDER == order) { - post_desc->gni_desc.dlvr_mode = GNI_DLVMODE_PERFORMANCE; + post_desc->gni_desc.dlvr_mode = GNI_DLVMODE_PERFORMANCE; } else { - post_desc->gni_desc.dlvr_mode = GNI_DLVMODE_NO_ADAPT; + post_desc->gni_desc.dlvr_mode = GNI_DLVMODE_NO_ADAPT; } - post_desc->gni_desc.local_addr = (uint64_t) lcl_addr; - post_desc->gni_desc.local_mem_hndl = lcl_mdh; - post_desc->gni_desc.remote_addr = (uint64_t) rem_addr; + post_desc->gni_desc.local_addr = (uint64_t) lcl_addr; + post_desc->gni_desc.local_mem_hndl = lcl_mdh; + post_desc->gni_desc.remote_addr = (uint64_t) rem_addr; post_desc->gni_desc.remote_mem_hndl = rem_mdh; - post_desc->gni_desc.length = bufsize; - post_desc->gni_desc.rdma_mode = 0; - post_desc->gni_desc.src_cq_hndl = cq_hndl; + post_desc->gni_desc.length = bufsize; + post_desc->gni_desc.rdma_mode = 0; + post_desc->gni_desc.src_cq_hndl = cq_hndl; } -__opal_attribute_always_inline__ -static inline int mca_btl_ugni_post_fma (struct mca_btl_base_endpoint_t *endpoint, gni_post_type_t op_type, - size_t size, void *local_address, uint64_t remote_address, - mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +__opal_attribute_always_inline__ static inline int +mca_btl_ugni_post_fma(struct mca_btl_base_endpoint_t *endpoint, gni_post_type_t op_type, + size_t size, void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { mca_btl_ugni_post_descriptor_t post_desc; gni_mem_handle_t local_gni_handle = {0, 0}; @@ -67,83 +64,82 @@ static inline int mca_btl_ugni_post_fma (struct mca_btl_base_endpoint_t *endpoin /* Post descriptor (CQ is ignored for FMA transactions) -- The CQ associated with the endpoint * is used. */ - init_post_desc (&post_desc, endpoint, order, op_type, (intptr_t) local_address, local_gni_handle, - remote_address, remote_handle->gni_handle, size, 0, cbfunc, cbcontext, cbdata, - local_handle); + init_post_desc(&post_desc, endpoint, order, op_type, (intptr_t) local_address, local_gni_handle, + remote_address, remote_handle->gni_handle, size, 0, cbfunc, cbcontext, cbdata, + local_handle); - return mca_btl_ugni_endpoint_post_fma (endpoint, &post_desc); + return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc); } -static inline int mca_btl_ugni_post_bte (mca_btl_base_endpoint_t *endpoint, gni_post_type_t op_type, - size_t size, void *local_address, uint64_t remote_address, - mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +static inline int mca_btl_ugni_post_bte(mca_btl_base_endpoint_t *endpoint, gni_post_type_t op_type, + size_t size, void *local_address, uint64_t remote_address, + mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, + int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { - mca_btl_ugni_module_t *module = mca_btl_ugni_ep_btl (endpoint); + mca_btl_ugni_module_t *module = mca_btl_ugni_ep_btl(endpoint); mca_btl_ugni_post_descriptor_t post_desc; int rc; - /* There is a performance benefit to throttling the total number of active BTE tranactions. Not sure - * what the optimium is but the limit is inforced as a soft limit. */ + /* There is a performance benefit to throttling the total number of active BTE tranactions. Not + * sure what the optimium is but the limit is inforced as a soft limit. */ if (module->active_rdma_count >= mca_btl_ugni_component.active_rdma_threshold) { return OPAL_ERR_OUT_OF_RESOURCE; } - (void) OPAL_THREAD_FETCH_ADD32 (&module->active_rdma_count, 1); + (void) OPAL_THREAD_FETCH_ADD32(&module->active_rdma_count, 1); /* Post descriptor */ - init_post_desc (&post_desc, endpoint, order, op_type, (intptr_t) local_address, local_handle->gni_handle, - remote_address, remote_handle->gni_handle, size, 0, cbfunc, cbcontext, cbdata, - local_handle); + init_post_desc(&post_desc, endpoint, order, op_type, (intptr_t) local_address, + local_handle->gni_handle, remote_address, remote_handle->gni_handle, size, 0, + cbfunc, cbcontext, cbdata, local_handle); - rc = mca_btl_ugni_endpoint_post_rdma (endpoint, &post_desc); + rc = mca_btl_ugni_endpoint_post_rdma(endpoint, &post_desc); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - (void) OPAL_THREAD_FETCH_ADD32 (&module->active_rdma_count, -1); + (void) OPAL_THREAD_FETCH_ADD32(&module->active_rdma_count, -1); } return rc; } -static inline int mca_btl_ugni_post_cqwrite (mca_btl_base_endpoint_t *endpoint, mca_btl_ugni_cq_t *cq, - gni_mem_handle_t irq_mhndl, uint64_t value, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +static inline int mca_btl_ugni_post_cqwrite(mca_btl_base_endpoint_t *endpoint, + mca_btl_ugni_cq_t *cq, gni_mem_handle_t irq_mhndl, + uint64_t value, + mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { mca_btl_ugni_post_descriptor_t post_desc; post_desc.gni_desc.type = GNI_POST_CQWRITE; - post_desc.gni_desc.cqwrite_value = value; /* up to 48 bytes here, not used for now */ + post_desc.gni_desc.cqwrite_value = value; /* up to 48 bytes here, not used for now */ post_desc.gni_desc.cq_mode = GNI_CQMODE_GLOBAL_EVENT; post_desc.gni_desc.dlvr_mode = GNI_DLVMODE_IN_ORDER; post_desc.gni_desc.src_cq_hndl = cq->gni_handle; post_desc.gni_desc.remote_mem_hndl = irq_mhndl; post_desc.cq = cq; - return mca_btl_ugni_endpoint_post_cqwrite (endpoint, &post_desc); + return mca_btl_ugni_endpoint_post_cqwrite(endpoint, &post_desc); } -__opal_attribute_always_inline__ -static inline int mca_btl_ugni_post (mca_btl_base_endpoint_t *endpoint, int get, size_t size, - void *local_address, uint64_t remote_address, - mca_btl_base_registration_handle_t *local_handle, - mca_btl_base_registration_handle_t *remote_handle, - int order, mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +__opal_attribute_always_inline__ static inline int +mca_btl_ugni_post(mca_btl_base_endpoint_t *endpoint, int get, size_t size, void *local_address, + uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle, + mca_btl_base_registration_handle_t *remote_handle, int order, + mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata) { const gni_post_type_t fma_ops[2] = {GNI_POST_FMA_PUT, GNI_POST_FMA_GET}; const gni_post_type_t rdma_ops[2] = {GNI_POST_RDMA_PUT, GNI_POST_RDMA_GET}; - const size_t fma_limit = (size_t) (get ? mca_btl_ugni_component.ugni_fma_get_limit : - mca_btl_ugni_component.ugni_fma_put_limit); + const size_t fma_limit = (size_t)(get ? mca_btl_ugni_component.ugni_fma_get_limit + : mca_btl_ugni_component.ugni_fma_put_limit); if (size <= fma_limit) { - return mca_btl_ugni_post_fma (endpoint, fma_ops[get], size, local_address, remote_address, - local_handle, remote_handle, order, cbfunc, cbcontext, cbdata); + return mca_btl_ugni_post_fma(endpoint, fma_ops[get], size, local_address, remote_address, + local_handle, remote_handle, order, cbfunc, cbcontext, cbdata); } - return mca_btl_ugni_post_bte (endpoint, rdma_ops[get], size, local_address, remote_address, - local_handle, remote_handle, order, cbfunc, cbcontext, cbdata); + return mca_btl_ugni_post_bte(endpoint, rdma_ops[get], size, local_address, remote_address, + local_handle, remote_handle, order, cbfunc, cbcontext, cbdata); } #endif /* MCA_BTL_UGNI_RDMA_H */ diff --git a/opal/mca/btl/ugni/btl_ugni_send.c b/opal/mca/btl/ugni/btl_ugni_send.c index 5b120b75965..5ad6de50e18 100644 --- a/opal/mca/btl/ugni/btl_ugni_send.c +++ b/opal/mca/btl/ugni/btl_ugni_send.c @@ -15,37 +15,37 @@ #include "btl_ugni.h" #include "btl_ugni_frag.h" -#include "btl_ugni_smsg.h" #include "btl_ugni_prepare.h" +#include "btl_ugni_smsg.h" -void mca_btl_ugni_wait_list_append (mca_btl_ugni_module_t *ugni_module, mca_btl_base_endpoint_t *endpoint, - mca_btl_ugni_base_frag_t *frag) +void mca_btl_ugni_wait_list_append(mca_btl_ugni_module_t *ugni_module, + mca_btl_base_endpoint_t *endpoint, + mca_btl_ugni_base_frag_t *frag) { - BTL_VERBOSE(("wait-listing fragment %p to %s. endpoint state %d\n", (void*)frag, OPAL_NAME_PRINT(endpoint->peer_proc->proc_name), endpoint->state)); + BTL_VERBOSE(("wait-listing fragment %p to %s. endpoint state %d\n", (void *) frag, + OPAL_NAME_PRINT(endpoint->peer_proc->proc_name), endpoint->state)); frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; /* queue up request */ OPAL_THREAD_LOCK(&endpoint->lock); - opal_list_append (&endpoint->frag_wait_list, (opal_list_item_t *) frag); + opal_list_append(&endpoint->frag_wait_list, (opal_list_item_t *) frag); OPAL_THREAD_UNLOCK(&endpoint->lock); if (false == endpoint->wait_listed && MCA_BTL_UGNI_EP_STATE_CONNECTED == endpoint->state) { OPAL_THREAD_LOCK(&ugni_module->ep_wait_list_lock); if (false == endpoint->wait_listed) { - opal_list_append (&ugni_module->ep_wait_list, &endpoint->super); + opal_list_append(&ugni_module->ep_wait_list, &endpoint->super); endpoint->wait_listed = true; } OPAL_THREAD_UNLOCK(&ugni_module->ep_wait_list_lock); } } -int mca_btl_ugni_send (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - struct mca_btl_base_descriptor_t *descriptor, - mca_btl_base_tag_t tag) +int mca_btl_ugni_send(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { mca_btl_ugni_base_frag_t *frag = (mca_btl_ugni_base_frag_t *) descriptor; size_t size = frag->segments[0].seg_len + frag->segments[1].seg_len; @@ -55,12 +55,13 @@ int mca_btl_ugni_send (struct mca_btl_base_module_t *btl, /* tag and len are at the same location in eager and smsg frag hdrs */ frag->hdr.send.lag = (tag << 24) | size; - BTL_VERBOSE(("btl/ugni sending descriptor %p from %d -> %d. length = %" PRIu64, (void *)descriptor, - OPAL_PROC_MY_NAME.vpid, endpoint->peer_proc->proc_name.vpid, size)); + BTL_VERBOSE(("btl/ugni sending descriptor %p from %d -> %d. length = %" PRIu64, + (void *) descriptor, OPAL_PROC_MY_NAME.vpid, endpoint->peer_proc->proc_name.vpid, + size)); - rc = mca_btl_ugni_check_endpoint_state (endpoint); - if (OPAL_UNLIKELY(OPAL_SUCCESS != rc || opal_list_get_size (&endpoint->frag_wait_list))) { - mca_btl_ugni_wait_list_append (ugni_module, endpoint, frag); + rc = mca_btl_ugni_check_endpoint_state(endpoint); + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc || opal_list_get_size(&endpoint->frag_wait_list))) { + mca_btl_ugni_wait_list_append(ugni_module, endpoint, frag); return OPAL_SUCCESS; } @@ -69,15 +70,16 @@ int mca_btl_ugni_send (struct mca_btl_base_module_t *btl, ++frag->ref_cnt; frag->flags &= ~MCA_BTL_UGNI_FRAG_COMPLETE; - rc = mca_btl_ugni_send_frag (endpoint, frag); - if (OPAL_LIKELY(mca_btl_ugni_frag_check_complete (frag))) { + rc = mca_btl_ugni_send_frag(endpoint, frag); + if (OPAL_LIKELY(mca_btl_ugni_frag_check_complete(frag))) { /* fast path: remote side has received the frag */ - (void) mca_btl_ugni_frag_del_ref (frag, OPAL_SUCCESS); + (void) mca_btl_ugni_frag_del_ref(frag, OPAL_SUCCESS); return 1; } - if ((OPAL_SUCCESS == rc) && (frag->flags & MCA_BTL_UGNI_FRAG_BUFFERED) && (frag->flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { + if ((OPAL_SUCCESS == rc) && (frag->flags & MCA_BTL_UGNI_FRAG_BUFFERED) + && (frag->flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { /* fast(ish) path: btl owned buffered frag. report send as complete */ bool call_callback = !!(frag->flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK); frag->flags &= ~MCA_BTL_DES_SEND_ALWAYS_CALLBACK; @@ -86,7 +88,7 @@ int mca_btl_ugni_send (struct mca_btl_base_module_t *btl, frag->base.des_cbfunc(&ugni_module->super, frag->endpoint, &frag->base, rc); } - (void) mca_btl_ugni_frag_del_ref (frag, OPAL_SUCCESS); + (void) mca_btl_ugni_frag_del_ref(frag, OPAL_SUCCESS); return 1; } @@ -95,31 +97,28 @@ int mca_btl_ugni_send (struct mca_btl_base_module_t *btl, we get the local smsg/msgq or remote rdma completion */ frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; - mca_btl_ugni_frag_del_ref (frag, OPAL_SUCCESS); + mca_btl_ugni_frag_del_ref(frag, OPAL_SUCCESS); if (OPAL_UNLIKELY(OPAL_ERR_OUT_OF_RESOURCE == rc)) { /* queue up request */ - mca_btl_ugni_wait_list_append (ugni_module, endpoint, frag); + mca_btl_ugni_wait_list_append(ugni_module, endpoint, frag); rc = OPAL_SUCCESS; } return rc; } -int mca_btl_ugni_sendi (struct mca_btl_base_module_t *btl, - struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - void *header, size_t header_size, - size_t payload_size, uint8_t order, - uint32_t flags, mca_btl_base_tag_t tag, - mca_btl_base_descriptor_t **descriptor) +int mca_btl_ugni_sendi(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, void *header, size_t header_size, + size_t payload_size, uint8_t order, uint32_t flags, mca_btl_base_tag_t tag, + mca_btl_base_descriptor_t **descriptor) { size_t total_size = header_size + payload_size; mca_btl_ugni_base_frag_t *frag = NULL; size_t packed_size = payload_size; int rc; - if (OPAL_UNLIKELY(opal_list_get_size (&endpoint->frag_wait_list))) { + if (OPAL_UNLIKELY(opal_list_get_size(&endpoint->frag_wait_list))) { if (NULL != descriptor) { *descriptor = NULL; } @@ -128,28 +127,31 @@ int mca_btl_ugni_sendi (struct mca_btl_base_module_t *btl, do { BTL_VERBOSE(("btl/ugni isend sending fragment from %d -> %d. length = %" PRIu64 - " endoint state %d", OPAL_PROC_MY_NAME.vpid, endpoint->peer_proc->proc_name.vpid, + " endoint state %d", + OPAL_PROC_MY_NAME.vpid, endpoint->peer_proc->proc_name.vpid, payload_size + header_size, endpoint->state)); flags |= MCA_BTL_DES_FLAGS_BTL_OWNERSHIP; if (0 == payload_size) { - frag = (mca_btl_ugni_base_frag_t *) mca_btl_ugni_prepare_src_send_nodata (btl, endpoint, order, header_size, - flags); + frag = (mca_btl_ugni_base_frag_t *) + mca_btl_ugni_prepare_src_send_nodata(btl, endpoint, order, header_size, flags); } else { - frag = (mca_btl_ugni_base_frag_t *) mca_btl_ugni_prepare_src_send_buffered (btl, endpoint, convertor, order, - header_size, &packed_size, flags); + frag = (mca_btl_ugni_base_frag_t *) + mca_btl_ugni_prepare_src_send_buffered(btl, endpoint, convertor, order, header_size, + &packed_size, flags); } - assert (packed_size == payload_size); - if (OPAL_UNLIKELY(NULL == frag || OPAL_SUCCESS != mca_btl_ugni_check_endpoint_state (endpoint))) { + assert(packed_size == payload_size); + if (OPAL_UNLIKELY(NULL == frag + || OPAL_SUCCESS != mca_btl_ugni_check_endpoint_state(endpoint))) { break; } frag->hdr.send.lag = (tag << 24) | total_size; - memcpy (frag->segments[0].seg_addr.pval, header, header_size); + memcpy(frag->segments[0].seg_addr.pval, header, header_size); - rc = mca_btl_ugni_send_frag (endpoint, frag); + rc = mca_btl_ugni_send_frag(endpoint, frag); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { break; } @@ -164,36 +166,36 @@ int mca_btl_ugni_sendi (struct mca_btl_base_module_t *btl, return OPAL_ERR_OUT_OF_RESOURCE; } -int mca_btl_ugni_progress_send_wait_list (mca_btl_base_endpoint_t *endpoint) +int mca_btl_ugni_progress_send_wait_list(mca_btl_base_endpoint_t *endpoint) { - mca_btl_ugni_base_frag_t *frag=NULL; + mca_btl_ugni_base_frag_t *frag = NULL; int rc; do { OPAL_THREAD_LOCK(&endpoint->lock); - frag = (mca_btl_ugni_base_frag_t *) opal_list_remove_first (&endpoint->frag_wait_list); + frag = (mca_btl_ugni_base_frag_t *) opal_list_remove_first(&endpoint->frag_wait_list); OPAL_THREAD_UNLOCK(&endpoint->lock); if (NULL == frag) { break; } if (OPAL_LIKELY(!(frag->flags & MCA_BTL_UGNI_FRAG_RESPONSE))) { - rc = mca_btl_ugni_send_frag (endpoint, frag); + rc = mca_btl_ugni_send_frag(endpoint, frag); } else { - rc = opal_mca_btl_ugni_smsg_send (frag, &frag->hdr.rdma, sizeof (frag->hdr.rdma), - NULL, 0, MCA_BTL_UGNI_TAG_RDMA_COMPLETE); + rc = opal_mca_btl_ugni_smsg_send(frag, &frag->hdr.rdma, sizeof(frag->hdr.rdma), NULL, 0, + MCA_BTL_UGNI_TAG_RDMA_COMPLETE); } if (OPAL_UNLIKELY(OPAL_SUCCESS > rc)) { if (OPAL_LIKELY(OPAL_ERR_OUT_OF_RESOURCE == rc)) { OPAL_THREAD_LOCK(&endpoint->lock); - opal_list_prepend (&endpoint->frag_wait_list, (opal_list_item_t *) frag); + opal_list_prepend(&endpoint->frag_wait_list, (opal_list_item_t *) frag); OPAL_THREAD_UNLOCK(&endpoint->lock); } else { - mca_btl_ugni_frag_complete (frag, rc); + mca_btl_ugni_frag_complete(frag, rc); } return rc; } - } while(1); + } while (1); return OPAL_SUCCESS; } diff --git a/opal/mca/btl/ugni/btl_ugni_smsg.c b/opal/mca/btl/ugni/btl_ugni_smsg.c index c04586b0924..17ce9861ff9 100644 --- a/opal/mca/btl/ugni/btl_ugni_smsg.c +++ b/opal/mca/btl/ugni/btl_ugni_smsg.c @@ -13,20 +13,19 @@ #include "btl_ugni_smsg.h" #include "btl_ugni_rdma.h" -static void mca_btl_ugni_smsg_mbox_construct (mca_btl_ugni_smsg_mbox_t *mbox) { - struct mca_btl_ugni_reg_t *ugni_reg = - (struct mca_btl_ugni_reg_t *) mbox->super.registration; - mca_rcache_base_registration_t *base_reg = - (mca_rcache_base_registration_t *) ugni_reg; +static void mca_btl_ugni_smsg_mbox_construct(mca_btl_ugni_smsg_mbox_t *mbox) +{ + struct mca_btl_ugni_reg_t *ugni_reg = (struct mca_btl_ugni_reg_t *) mbox->super.registration; + mca_rcache_base_registration_t *base_reg = (mca_rcache_base_registration_t *) ugni_reg; /* initialize mailbox attributes */ - mbox->attr.smsg_attr.msg_type = GNI_SMSG_TYPE_MBOX_AUTO_RETRANSMIT; - mbox->attr.smsg_attr.msg_maxsize = mca_btl_ugni_component.ugni_smsg_limit; + mbox->attr.smsg_attr.msg_type = GNI_SMSG_TYPE_MBOX_AUTO_RETRANSMIT; + mbox->attr.smsg_attr.msg_maxsize = mca_btl_ugni_component.ugni_smsg_limit; mbox->attr.smsg_attr.mbox_maxcredit = mca_btl_ugni_component.smsg_max_credits; - mbox->attr.smsg_attr.mbox_offset = (uintptr_t) mbox->super.ptr - (uintptr_t) base_reg->base; - mbox->attr.smsg_attr.msg_buffer = base_reg->base; - mbox->attr.smsg_attr.buff_size = mca_btl_ugni_component.smsg_mbox_size; - mbox->attr.smsg_attr.mem_hndl = ugni_reg->handle.gni_handle; + mbox->attr.smsg_attr.mbox_offset = (uintptr_t) mbox->super.ptr - (uintptr_t) base_reg->base; + mbox->attr.smsg_attr.msg_buffer = base_reg->base; + mbox->attr.smsg_attr.buff_size = mca_btl_ugni_component.smsg_mbox_size; + mbox->attr.smsg_attr.mem_hndl = ugni_reg->handle.gni_handle; mbox->attr.proc_name = OPAL_PROC_MY_NAME; mbox->attr.rmt_irq_mem_hndl = mca_btl_ugni_component.modules[0].devices[0].smsg_irq_mhndl; } @@ -34,17 +33,16 @@ static void mca_btl_ugni_smsg_mbox_construct (mca_btl_ugni_smsg_mbox_t *mbox) { OBJ_CLASS_INSTANCE(mca_btl_ugni_smsg_mbox_t, opal_free_list_item_t, mca_btl_ugni_smsg_mbox_construct, NULL); - -int mca_btl_ugni_smsg_init (mca_btl_ugni_module_t *ugni_module) +int mca_btl_ugni_smsg_init(mca_btl_ugni_module_t *ugni_module) { gni_return_t rc; - for (int i = 0 ; i < mca_btl_ugni_component.virtual_device_count ; ++i) { - rc = GNI_SmsgSetMaxRetrans (ugni_module->devices[i].dev_handle, - mca_btl_ugni_component.smsg_max_retries); + for (int i = 0; i < mca_btl_ugni_component.virtual_device_count; ++i) { + rc = GNI_SmsgSetMaxRetrans(ugni_module->devices[i].dev_handle, + mca_btl_ugni_component.smsg_max_retries); if (GNI_RC_SUCCESS != rc) { - BTL_ERROR(("error setting maximum SMSG retries %s",gni_err_str[rc])); - return mca_btl_rc_ugni_to_opal (rc); + BTL_ERROR(("error setting maximum SMSG retries %s", gni_err_str[rc])); + return mca_btl_rc_ugni_to_opal(rc); } } @@ -52,9 +50,9 @@ int mca_btl_ugni_smsg_init (mca_btl_ugni_module_t *ugni_module) } /* progress */ -int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) +int mca_btl_ugni_smsg_process(mca_btl_base_endpoint_t *ep) { - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (ep); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(ep); mca_btl_active_message_callback_t *reg; mca_btl_ugni_base_frag_t frag; bool disconnect = false; @@ -64,7 +62,7 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) uint32_t len; int count = 0; - if (!opal_atomic_compare_exchange_strong_32 (&ep->smsg_progressing, &_tmp_value, 1)) { + if (!opal_atomic_compare_exchange_strong_32(&ep->smsg_progressing, &_tmp_value, 1)) { /* already progressing (we can't support reentry here) */ return 0; } @@ -73,7 +71,7 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) do { uint8_t tag = GNI_SMSG_ANY_TAG; - rc = mca_btl_ugni_smsg_get_next_wtag (&ep->smsg_ep_handle, &data_ptr, &tag); + rc = mca_btl_ugni_smsg_get_next_wtag(&ep->smsg_ep_handle, &data_ptr, &tag); if (GNI_RC_SUCCESS != rc) { if (OPAL_LIKELY(GNI_RC_NOT_DONE == rc)) { BTL_VERBOSE(("no smsg message waiting. rc = %s", gni_err_str[rc])); @@ -86,7 +84,7 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) return OPAL_ERROR; } - assert (0 != data_ptr); + assert(0 != data_ptr); count++; @@ -94,7 +92,7 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) switch (tag) { case MCA_BTL_UGNI_TAG_SEND: - + frag.hdr.send = ((mca_btl_ugni_send_frag_hdr_t *) data_ptr)[0]; tag = frag.hdr.send.lag >> 24; @@ -104,11 +102,14 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) reg = mca_btl_base_active_message_trigger + tag; - mca_btl_base_segment_t seg = - {.seg_addr.pval = (void *)((uintptr_t)data_ptr + sizeof (mca_btl_ugni_send_frag_hdr_t)), - seg.seg_len = len}; - const mca_btl_base_receive_descriptor_t desc = {.endpoint = ep, .des_segments = &seg, - .des_segment_count = 1, .tag = tag, + mca_btl_base_segment_t seg + = {.seg_addr.pval = (void *) ((uintptr_t) data_ptr + + sizeof(mca_btl_ugni_send_frag_hdr_t)), + seg.seg_len = len}; + const mca_btl_base_receive_descriptor_t desc = {.endpoint = ep, + .des_segments = &seg, + .des_segment_count = 1, + .tag = tag, .cbdata = reg->cbdata}; reg->cbfunc(&ugni_module->super, &desc); @@ -116,16 +117,18 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) case MCA_BTL_UGNI_TAG_GET_INIT: frag.hdr.eager_ex = ((mca_btl_ugni_eager_ex_frag_hdr_t *) data_ptr)[0]; - mca_btl_ugni_start_eager_get (ep, frag.hdr.eager_ex, NULL); + mca_btl_ugni_start_eager_get(ep, frag.hdr.eager_ex, NULL); break; case MCA_BTL_UGNI_TAG_RDMA_COMPLETE: frag.hdr.rdma = ((mca_btl_ugni_rdma_frag_hdr_t *) data_ptr)[0]; - if (((mca_btl_ugni_base_frag_t *)frag.hdr.rdma.ctx)->flags & MCA_BTL_UGNI_FRAG_SMSG_COMPLETE) { - mca_btl_ugni_frag_complete (frag.hdr.rdma.ctx, OPAL_SUCCESS); + if (((mca_btl_ugni_base_frag_t *) frag.hdr.rdma.ctx)->flags + & MCA_BTL_UGNI_FRAG_SMSG_COMPLETE) { + mca_btl_ugni_frag_complete(frag.hdr.rdma.ctx, OPAL_SUCCESS); } else { /* let the local smsg completion finish this frag */ - ((mca_btl_ugni_base_frag_t *)frag.hdr.rdma.ctx)->flags &= ~MCA_BTL_UGNI_FRAG_IGNORE; + ((mca_btl_ugni_base_frag_t *) frag.hdr.rdma.ctx)->flags + &= ~MCA_BTL_UGNI_FRAG_IGNORE; } break; case MCA_BTL_UGNI_TAG_DISCONNECT: @@ -137,7 +140,7 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) break; } - rc = mca_btl_ugni_smsg_release (&ep->smsg_ep_handle); + rc = mca_btl_ugni_smsg_release(&ep->smsg_ep_handle); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != rc)) { BTL_ERROR(("Smsg release failed! rc = %d", rc)); return OPAL_ERROR; @@ -147,17 +150,16 @@ int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep) ep->smsg_progressing = 0; /* disconnect if we get here */ - opal_mutex_lock (&ep->lock); + opal_mutex_lock(&ep->lock); - mca_btl_ugni_ep_disconnect (ep, false); + mca_btl_ugni_ep_disconnect(ep, false); - opal_mutex_unlock (&ep->lock); + opal_mutex_unlock(&ep->lock); return count; } -static inline int -mca_btl_ugni_handle_remote_smsg_overrun (mca_btl_ugni_module_t *btl) +static inline int mca_btl_ugni_handle_remote_smsg_overrun(mca_btl_ugni_module_t *btl) { size_t endpoint_count; unsigned int ep_index; @@ -170,22 +172,21 @@ mca_btl_ugni_handle_remote_smsg_overrun (mca_btl_ugni_module_t *btl) smsg remote cq and check all mailboxes */ /* clear out remote cq */ - mca_btl_ugni_cq_clear (btl->devices, btl->smsg_remote_cq); + mca_btl_ugni_cq_clear(btl->devices, btl->smsg_remote_cq); - endpoint_count = opal_pointer_array_get_size (&btl->endpoints); + endpoint_count = opal_pointer_array_get_size(&btl->endpoints); - for (ep_index = 0, count = 0 ; ep_index < endpoint_count ; ++ep_index) { + for (ep_index = 0, count = 0; ep_index < endpoint_count; ++ep_index) { mca_btl_base_endpoint_t *ep; - ep = (mca_btl_base_endpoint_t *) opal_pointer_array_get_item (&btl->endpoints, - ep_index); + ep = (mca_btl_base_endpoint_t *) opal_pointer_array_get_item(&btl->endpoints, ep_index); if (NULL == ep || MCA_BTL_UGNI_EP_STATE_CONNECTED != ep->state) { continue; } /* clear out smsg mailbox */ - rc = mca_btl_ugni_smsg_process (ep); + rc = mca_btl_ugni_smsg_process(ep); if (OPAL_LIKELY(rc >= 0)) { count += rc; } @@ -194,41 +195,40 @@ mca_btl_ugni_handle_remote_smsg_overrun (mca_btl_ugni_module_t *btl) return count; } -int mca_btl_ugni_progress_remote_smsg (mca_btl_ugni_module_t *btl) +int mca_btl_ugni_progress_remote_smsg(mca_btl_ugni_module_t *btl) { mca_btl_base_endpoint_t *ep; gni_cq_entry_t event_data; gni_return_t grc; uint64_t inst_id; - grc = mca_btl_ugni_gni_cq_get_event (btl->devices, btl->smsg_remote_cq, &event_data); + grc = mca_btl_ugni_gni_cq_get_event(btl->devices, btl->smsg_remote_cq, &event_data); if (GNI_RC_NOT_DONE == grc) { return 0; } - if (OPAL_UNLIKELY(GNI_RC_SUCCESS != grc || !GNI_CQ_STATUS_OK(event_data) || - GNI_CQ_OVERRUN(event_data))) { - if (GNI_RC_ERROR_RESOURCE == grc || - (GNI_RC_SUCCESS == grc && GNI_CQ_OVERRUN(event_data))) { + if (OPAL_UNLIKELY(GNI_RC_SUCCESS != grc || !GNI_CQ_STATUS_OK(event_data) + || GNI_CQ_OVERRUN(event_data))) { + if (GNI_RC_ERROR_RESOURCE == grc || (GNI_RC_SUCCESS == grc && GNI_CQ_OVERRUN(event_data))) { /* recover from smsg cq overrun */ - return mca_btl_ugni_handle_remote_smsg_overrun (btl); + return mca_btl_ugni_handle_remote_smsg_overrun(btl); } BTL_ERROR(("unhandled error in GNI_CqGetEvent")); /* unhandled error: crash */ - assert (0); - return mca_btl_rc_ugni_to_opal (grc); + assert(0); + return mca_btl_rc_ugni_to_opal(grc); } BTL_VERBOSE(("REMOTE CQ: Got event 0x%" PRIx64 ". msg id = %" PRIu64 - ". ok = %d, type = %" PRIu64, (uint64_t) event_data, - GNI_CQ_GET_INST_ID(event_data), GNI_CQ_STATUS_OK(event_data), - GNI_CQ_GET_TYPE(event_data))); + ". ok = %d, type = %" PRIu64, + (uint64_t) event_data, GNI_CQ_GET_INST_ID(event_data), + GNI_CQ_STATUS_OK(event_data), GNI_CQ_GET_TYPE(event_data))); inst_id = GNI_CQ_GET_INST_ID(event_data); - ep = (mca_btl_base_endpoint_t *) opal_pointer_array_get_item (&btl->endpoints, inst_id); + ep = (mca_btl_base_endpoint_t *) opal_pointer_array_get_item(&btl->endpoints, inst_id); if (OPAL_UNLIKELY(MCA_BTL_UGNI_EP_STATE_CONNECTED != ep->state)) { /* due to the nature of datagrams we may get a smsg completion before @@ -237,6 +237,5 @@ int mca_btl_ugni_progress_remote_smsg (mca_btl_ugni_module_t *btl) return 0; } - return mca_btl_ugni_smsg_process (ep); + return mca_btl_ugni_smsg_process(ep); } - diff --git a/opal/mca/btl/ugni/btl_ugni_smsg.h b/opal/mca/btl/ugni/btl_ugni_smsg.h index 82e54d55cb8..60db0f32abf 100644 --- a/opal/mca/btl/ugni/btl_ugni_smsg.h +++ b/opal/mca/btl/ugni/btl_ugni_smsg.h @@ -11,12 +11,12 @@ */ #if !defined(MCA_BTL_UGNI_SMSG_H) -#define MCA_BTL_UGNI_SMSG_H +# define MCA_BTL_UGNI_SMSG_H -#include "btl_ugni.h" -#include "btl_ugni_endpoint.h" -#include "btl_ugni_frag.h" -#include "btl_ugni_rdma.h" +# include "btl_ugni.h" +# include "btl_ugni_endpoint.h" +# include "btl_ugni_frag.h" +# include "btl_ugni_rdma.h" typedef enum { MCA_BTL_UGNI_TAG_SEND, @@ -32,17 +32,18 @@ typedef struct mca_btl_ugni_smsg_mbox_t { OBJ_CLASS_DECLARATION(mca_btl_ugni_smsg_mbox_t); -int mca_btl_ugni_smsg_init (mca_btl_ugni_module_t *ugni_module); -int mca_btl_ugni_smsg_process (mca_btl_base_endpoint_t *ep); -int mca_btl_ugni_progress_remote_smsg (mca_btl_ugni_module_t *btl); +int mca_btl_ugni_smsg_init(mca_btl_ugni_module_t *ugni_module); +int mca_btl_ugni_smsg_process(mca_btl_base_endpoint_t *ep); +int mca_btl_ugni_progress_remote_smsg(mca_btl_ugni_module_t *btl); -static inline int mca_btl_ugni_progress_local_smsg (mca_btl_ugni_module_t *ugni_module, mca_btl_ugni_device_t *device) +static inline int mca_btl_ugni_progress_local_smsg(mca_btl_ugni_module_t *ugni_module, + mca_btl_ugni_device_t *device) { mca_btl_ugni_base_frag_t *frag; gni_cq_entry_t event_data; gni_return_t grc; - grc = mca_btl_ugni_cq_get_event (device, &device->dev_smsg_local_cq, &event_data); + grc = mca_btl_ugni_cq_get_event(device, &device->dev_smsg_local_cq, &event_data); if (GNI_RC_NOT_DONE == grc) { return OPAL_SUCCESS; } @@ -50,48 +51,50 @@ static inline int mca_btl_ugni_progress_local_smsg (mca_btl_ugni_module_t *ugni_ if (OPAL_UNLIKELY((GNI_RC_SUCCESS != grc && !event_data) || GNI_CQ_OVERRUN(event_data))) { /* TODO -- need to handle overrun -- how do we do this without an event? * will the event eventually come back? Ask Cray */ - return mca_btl_ugni_event_fatal_error (grc, event_data); + return mca_btl_ugni_event_fatal_error(grc, event_data); } - assert (GNI_CQ_GET_TYPE(event_data) == GNI_CQ_EVENT_TYPE_SMSG); + assert(GNI_CQ_GET_TYPE(event_data) == GNI_CQ_EVENT_TYPE_SMSG); - frag = (mca_btl_ugni_base_frag_t *) opal_pointer_array_get_item (&ugni_module->pending_smsg_frags_bb, - GNI_CQ_GET_MSG_ID(event_data)); + frag = (mca_btl_ugni_base_frag_t *) + opal_pointer_array_get_item(&ugni_module->pending_smsg_frags_bb, + GNI_CQ_GET_MSG_ID(event_data)); if (OPAL_UNLIKELY(NULL == frag)) { - assert (0); + assert(0); return OPAL_ERROR; } frag->flags |= MCA_BTL_UGNI_FRAG_SMSG_COMPLETE; if (!(frag->flags & MCA_BTL_UGNI_FRAG_IGNORE)) { - mca_btl_ugni_frag_complete (frag, OPAL_SUCCESS); + mca_btl_ugni_frag_complete(frag, OPAL_SUCCESS); } return 1; } -static inline int opal_mca_btl_ugni_smsg_send (mca_btl_ugni_base_frag_t *frag, - void *hdr, size_t hdr_len, - void *payload, size_t payload_len, - mca_btl_ugni_smsg_tag_t tag) +static inline int opal_mca_btl_ugni_smsg_send(mca_btl_ugni_base_frag_t *frag, void *hdr, + size_t hdr_len, void *payload, size_t payload_len, + mca_btl_ugni_smsg_tag_t tag) { mca_btl_base_endpoint_t *endpoint = frag->endpoint; - mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (endpoint); + mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl(endpoint); gni_return_t grc; - grc = mca_btl_ugni_endpoint_smsg_send_wtag (endpoint, hdr, hdr_len, payload, payload_len, - frag->msg_id, tag); + grc = mca_btl_ugni_endpoint_smsg_send_wtag(endpoint, hdr, hdr_len, payload, payload_len, + frag->msg_id, tag); if (OPAL_LIKELY(GNI_RC_SUCCESS == grc)) { if (mca_btl_ugni_component.progress_thread_enabled) { if (frag->base.des_flags & MCA_BTL_DES_FLAGS_SIGNAL) { /* errors for PostCqWrite treated as non-fatal */ - (void) mca_btl_ugni_post_cqwrite (endpoint, &ugni_module->devices[0].dev_rdma_local_cq, - endpoint->rmt_irq_mem_hndl, 0xdead, NULL, NULL, NULL); + (void) mca_btl_ugni_post_cqwrite(endpoint, + &ugni_module->devices[0].dev_rdma_local_cq, + endpoint->rmt_irq_mem_hndl, 0xdead, NULL, NULL, + NULL); } } - (void) mca_btl_ugni_progress_local_smsg (ugni_module, endpoint->smsg_ep_handle.device); + (void) mca_btl_ugni_progress_local_smsg(ugni_module, endpoint->smsg_ep_handle.device); return OPAL_SUCCESS; } @@ -108,21 +111,21 @@ static inline int opal_mca_btl_ugni_smsg_send (mca_btl_ugni_base_frag_t *frag, return OPAL_ERROR; } -static inline int mca_btl_ugni_send_frag (struct mca_btl_base_endpoint_t *btl_peer, - mca_btl_ugni_base_frag_t *frag) { +static inline int mca_btl_ugni_send_frag(struct mca_btl_base_endpoint_t *btl_peer, + mca_btl_ugni_base_frag_t *frag) +{ if (OPAL_LIKELY(!(frag->flags & MCA_BTL_UGNI_FRAG_EAGER))) { - return opal_mca_btl_ugni_smsg_send (frag, &frag->hdr.send, frag->hdr_size, - frag->segments[1].seg_addr.pval, - frag->segments[1].seg_len, - MCA_BTL_UGNI_TAG_SEND); + return opal_mca_btl_ugni_smsg_send(frag, &frag->hdr.send, frag->hdr_size, + frag->segments[1].seg_addr.pval, + frag->segments[1].seg_len, MCA_BTL_UGNI_TAG_SEND); } - frag->hdr.eager.size = frag->segments[1].seg_len; + frag->hdr.eager.size = frag->segments[1].seg_len; frag->hdr.eager.address = frag->segments[1].seg_addr.lval; - frag->hdr.eager.ctx = (void *) frag; + frag->hdr.eager.ctx = (void *) frag; - return opal_mca_btl_ugni_smsg_send (frag, &frag->hdr.eager, frag->hdr_size, - NULL, 0, MCA_BTL_UGNI_TAG_GET_INIT); + return opal_mca_btl_ugni_smsg_send(frag, &frag->hdr.eager, frag->hdr_size, NULL, 0, + MCA_BTL_UGNI_TAG_GET_INIT); } #endif /* MCA_BTL_UGNI_SMSG_H */ diff --git a/opal/mca/btl/usnic/btl_usnic.h b/opal/mca/btl/usnic/btl_usnic.h index 5a3a94103cd..27d781c86c3 100644 --- a/opal/mca/btl/usnic/btl_usnic.h +++ b/opal/mca/btl/usnic/btl_usnic.h @@ -32,15 +32,14 @@ #include "opal_config.h" #include -#include "opal_stdint.h" -#include "opal/util/alfg.h" -#include "opal/class/opal_hash_table.h" #include "opal/class/opal_hash_table.h" +#include "opal/util/alfg.h" #include "opal/util/event.h" +#include "opal_stdint.h" -#include "opal/mca/btl/btl.h" -#include "opal/mca/btl/base/btl_base_error.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/rcache/rcache.h" #include "btl_usnic_compat.h" @@ -58,8 +57,7 @@ extern uint64_t opal_btl_usnic_ticks; /* Lock for MPU_THREAD_MULTIPLE support */ extern opal_recursive_mutex_t btl_usnic_lock; -static inline uint64_t -get_ticks(void) +static inline uint64_t get_ticks(void) { return opal_btl_usnic_ticks; } @@ -68,29 +66,32 @@ get_ticks(void) extern opal_rng_buff_t opal_btl_usnic_rand_buff; #ifndef container_of -#define container_of(ptr, type, member) ( \ - (type *)( ((char *)(ptr)) - offsetof(type,member) )) +# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member))) #endif #ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) +# define max(a, b) (((a) > (b)) ? (a) : (b)) #endif /* MSGDEBUG2 prints 1 line at each BTL entry point */ -#define MSGDEBUG2 (MSGDEBUG1||0) +#define MSGDEBUG2 (MSGDEBUG1 || 0) /* MSGDEBUG1 prints more info about arguments and internal functions */ #define MSGDEBUG1 0 /* output macros to declutter source */ #if MSGDEBUG1 -#define MSGDEBUG1_OUT(...) opal_output(0, __VA_ARGS__) +# define MSGDEBUG1_OUT(...) opal_output(0, __VA_ARGS__) #else -#define MSGDEBUG1_OUT(...) do {} while (0) +# define MSGDEBUG1_OUT(...) \ + do { \ + } while (0) #endif #if MSGDEBUG2 -#define MSGDEBUG2_OUT(...) opal_output(0, __VA_ARGS__) +# define MSGDEBUG2_OUT(...) opal_output(0, __VA_ARGS__) #else -#define MSGDEBUG2_OUT(...) do {} while (0) +# define MSGDEBUG2_OUT(...) \ + do { \ + } while (0) #endif /* Set to >0 to randomly drop received frags. The higher the number, @@ -105,24 +106,24 @@ extern opal_rng_buff_t opal_btl_usnic_rand_buff; #define WANT_FAIL_TO_RESEND_FRAG 0 #if WANT_RECV_DROPS > 0 -#define FAKE_RECV_DROP (opal_rand(&opal_btl_usnic_rand_buff) < WANT_RECV_DROPS) +# define FAKE_RECV_DROP (opal_rand(&opal_btl_usnic_rand_buff) < WANT_RECV_DROPS) #else -#define FAKE_RECV_DROP 0 +# define FAKE_RECV_DROP 0 #endif #if WANT_FAIL_TO_SEND_ACK > 0 -#define FAKE_FAIL_TO_SEND_ACK (opal_rand(&opal_btl_usnic_rand_buff) < WANT_FAIL_TO_SEND_ACK) +# define FAKE_FAIL_TO_SEND_ACK (opal_rand(&opal_btl_usnic_rand_buff) < WANT_FAIL_TO_SEND_ACK) #else -#define FAKE_FAIL_TO_SEND_ACK 0 +# define FAKE_FAIL_TO_SEND_ACK 0 #endif #if WANT_FAIL_TO_RESEND_FRAG > 0 -#define FAKE_FAIL_TO_RESEND_FRAG (opal_rand(&opal_btl_usnic_rand_buff) < WANT_FAIL_TO_RESEND_FRAG) +# define FAKE_FAIL_TO_RESEND_FRAG \ + (opal_rand(&opal_btl_usnic_rand_buff) < WANT_FAIL_TO_RESEND_FRAG) #else -#define FAKE_FAIL_TO_RESEND_FRAG 0 +# define FAKE_FAIL_TO_RESEND_FRAG 0 #endif - /** * usnic BTL component */ @@ -143,9 +144,9 @@ typedef struct opal_btl_usnic_component_t { uint64_t my_hashed_rte_name; /** array of possible BTLs (>= num_modules elements) */ - struct opal_btl_usnic_module_t* usnic_all_modules; + struct opal_btl_usnic_module_t *usnic_all_modules; /** array of pointers to active BTLs (num_modules elements) */ - struct opal_btl_usnic_module_t** usnic_active_modules; + struct opal_btl_usnic_module_t **usnic_active_modules; /** convertor packing threshold */ int pack_lazy_threshold; @@ -156,7 +157,7 @@ typedef struct opal_btl_usnic_component_t { opal_list_t usnic_procs; /** memory pool hints */ - char* usnic_mpool_hints; + char *usnic_mpool_hints; /** registration cache name */ char *usnic_rcache_name; @@ -255,11 +256,11 @@ typedef uint16_t opal_btl_usnic_seq_t; * Relies on the fact that sequence numbers should be relatively close * together as compared to (1<<31) */ -#define SEQ_DIFF(A,B) ((int16_t)((A)-(B))) -#define SEQ_LT(A,B) (SEQ_DIFF(A,B) < 0) -#define SEQ_LE(A,B) (SEQ_DIFF(A,B) <= 0) -#define SEQ_GT(A,B) (SEQ_DIFF(A,B) > 0) -#define SEQ_GE(A,B) (SEQ_DIFF(A,B) >= 0) +#define SEQ_DIFF(A, B) ((int16_t)((A) - (B))) +#define SEQ_LT(A, B) (SEQ_DIFF(A, B) < 0) +#define SEQ_LE(A, B) (SEQ_DIFF(A, B) <= 0) +#define SEQ_GT(A, B) (SEQ_DIFF(A, B) > 0) +#define SEQ_GE(A, B) (SEQ_DIFF(A, B) >= 0) /** * Register the usnic BTL MCA params diff --git a/opal/mca/btl/usnic/btl_usnic_ack.c b/opal/mca/btl/usnic/btl_usnic_ack.c index b7415e427d7..6bf02764c5a 100644 --- a/opal/mca/btl/usnic/btl_usnic_ack.c +++ b/opal/mca/btl/usnic/btl_usnic_ack.c @@ -13,26 +13,24 @@ #include #include -#include "opal/util/output.h" #include "opal/class/opal_hotel.h" +#include "opal/util/output.h" #include "btl_usnic.h" -#include "btl_usnic_frag.h" +#include "btl_usnic_ack.h" +#include "btl_usnic_connectivity.h" #include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" #include "btl_usnic_module.h" -#include "btl_usnic_ack.h" -#include "btl_usnic_util.h" #include "btl_usnic_send.h" -#include "btl_usnic_connectivity.h" +#include "btl_usnic_util.h" /* * Special case: we know exactly which segment is missing at the * receive; explicitly force retrans of that segment. */ -static void -opal_btl_usnic_fast_retrans( - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_seq_t ack_seq) +static void opal_btl_usnic_fast_retrans(opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_seq_t ack_seq) { opal_btl_usnic_send_segment_t *sseg; int is; @@ -59,15 +57,11 @@ opal_btl_usnic_fast_retrans( ++endpoint->endpoint_module->stats.num_fast_retrans; } - /* * We have received an ACK for a given sequence number (either standalone * or via piggy-back on a regular send) */ -void -opal_btl_usnic_handle_ack( - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_seq_t ack_seq) +void opal_btl_usnic_handle_ack(opal_btl_usnic_endpoint_t *endpoint, opal_btl_usnic_seq_t ack_seq) { opal_btl_usnic_seq_t is; opal_btl_usnic_send_segment_t *sseg; @@ -80,8 +74,8 @@ opal_btl_usnic_handle_ack( /* ignore if this is an old ACK */ if (SEQ_LT(ack_seq, endpoint->endpoint_ack_seq_rcvd)) { #if MSGDEBUG1 - opal_output(0, "Got OLD DUP ACK seq %"UDSEQ" < %"UDSEQ"\n", - ack_seq, endpoint->endpoint_ack_seq_rcvd); + opal_output(0, "Got OLD DUP ACK seq %" UDSEQ " < %" UDSEQ "\n", ack_seq, + endpoint->endpoint_ack_seq_rcvd); #endif ++module->stats.num_old_dup_acks; return; @@ -102,18 +96,20 @@ opal_btl_usnic_handle_ack( sseg = endpoint->endpoint_sent_segs[WINDOW_SIZE_MOD(is)]; #if MSGDEBUG1 - opal_output(0, " Checking ACK/sent_segs window %p, index %lu, seq %lu, occupied=%p, seg_room=%d", - (void*) endpoint->endpoint_sent_segs, - WINDOW_SIZE_MOD(is), is, (void*)sseg, (sseg?sseg->ss_hotel_room:-2)); + opal_output( + 0, " Checking ACK/sent_segs window %p, index %lu, seq %lu, occupied=%p, seg_room=%d", + (void *) endpoint->endpoint_sent_segs, WINDOW_SIZE_MOD(is), is, (void *) sseg, + (sseg ? sseg->ss_hotel_room : -2)); #endif assert(sseg != NULL); assert(sseg->ss_base.us_btl_header->pkt_seq == is); #if MSGDEBUG1 if (sseg->ss_hotel_room == -1) { - opal_output(0, "=== ACKed frag in sent_frags array is not in hotel/enqueued, module %p, endpoint %p, seg %p, seq %" UDSEQ ", slot %lu", - (void*) module, (void*) endpoint, - (void*) sseg, is, WINDOW_SIZE_MOD(is)); + opal_output(0, + "=== ACKed frag in sent_frags array is not in hotel/enqueued, module %p, " + "endpoint %p, seg %p, seq %" UDSEQ ", slot %lu", + (void *) module, (void *) endpoint, (void *) sseg, is, WINDOW_SIZE_MOD(is)); } #endif @@ -127,8 +123,7 @@ opal_btl_usnic_handle_ack( } /* hotel_room == -1 means queued for resend, remove it */ else { - opal_list_remove_item((&module->pending_resend_segs), - &sseg->ss_base.us_list.super); + opal_list_remove_item((&module->pending_resend_segs), &sseg->ss_base.us_list.super); } /* update the owning fragment */ @@ -136,11 +131,12 @@ opal_btl_usnic_handle_ack( frag = sseg->ss_parent_frag; #if MSGDEBUG1 - opal_output(0, " ACKED seg %p frag %p ack_bytes=%"PRIu32" left=%zd dst_seg[0].seg_addr=%p des_flags=0x%x\n", - (void*)sseg, (void*)frag, bytes_acked, - frag->sf_ack_bytes_left - bytes_acked, - frag->sf_base.uf_local_seg[0].seg_addr.pval, - frag->sf_base.uf_base.des_flags); + opal_output(0, + " ACKED seg %p frag %p ack_bytes=%" PRIu32 + " left=%zd dst_seg[0].seg_addr=%p des_flags=0x%x\n", + (void *) sseg, (void *) frag, bytes_acked, + frag->sf_ack_bytes_left - bytes_acked, + frag->sf_base.uf_local_seg[0].seg_addr.pval, frag->sf_base.uf_base.des_flags); #endif /* If all ACKs received, and this is a put or a regular send @@ -158,14 +154,12 @@ opal_btl_usnic_handle_ack( #if BTL_VERSION == 30 if (frag->sf_base.uf_remote_seg[0].seg_addr.pval != NULL) { OPAL_BTL_USNIC_DO_PUT_FRAG_CB(module, frag, "put completion"); - } else if (frag->sf_base.uf_base.des_flags & - MCA_BTL_DES_SEND_ALWAYS_CALLBACK) { + } else if (frag->sf_base.uf_base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) { OPAL_BTL_USNIC_DO_SEND_FRAG_CB(module, frag, "send completion"); } #else - if ((frag->sf_base.uf_remote_seg[0].seg_addr.pval != NULL) || - (frag->sf_base.uf_base.des_flags & - MCA_BTL_DES_SEND_ALWAYS_CALLBACK)) { + if ((frag->sf_base.uf_remote_seg[0].seg_addr.pval != NULL) + || (frag->sf_base.uf_base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK)) { OPAL_BTL_USNIC_DO_SEND_FRAG_CB(module, frag, "send completion"); } #endif @@ -198,10 +192,7 @@ opal_btl_usnic_handle_ack( /* * Send an ACK */ -int -opal_btl_usnic_ack_send( - opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint) +int opal_btl_usnic_ack_send(opal_btl_usnic_module_t *module, opal_btl_usnic_endpoint_t *endpoint) { opal_btl_usnic_ack_segment_t *ack; @@ -221,25 +212,18 @@ opal_btl_usnic_ack_send( /* send the seq of the lowest item in the window that we've received */ - ack->ss_base.us_btl_header->ack_seq = - SEQ_DIFF(endpoint->endpoint_next_contig_seq_to_recv, 1); + ack->ss_base.us_btl_header->ack_seq = SEQ_DIFF(endpoint->endpoint_next_contig_seq_to_recv, 1); ack->ss_len = sizeof(opal_btl_usnic_btl_header_t); #if MSGDEBUG1 { char remote_ip[IPV4STRADDRLEN]; - struct opal_btl_usnic_modex_t *modex = - &endpoint->endpoint_remote_modex; - opal_btl_usnic_snprintf_ipv4_addr(remote_ip, sizeof(remote_ip), - modex->ipv4_addr, + struct opal_btl_usnic_modex_t *modex = &endpoint->endpoint_remote_modex; + opal_btl_usnic_snprintf_ipv4_addr(remote_ip, sizeof(remote_ip), modex->ipv4_addr, modex->netmask); - - opal_output(0, "--> Sending ACK, length %d, seq %" UDSEQ " to %s, port %u", - ack->ss_len, - ack->ss_base.us_btl_header->ack_seq, - remote_ip, - modex->ports[ack->ss_channel]); + opal_output(0, "--> Sending ACK, length %d, seq %" UDSEQ " to %s, port %u", ack->ss_len, + ack->ss_base.us_btl_header->ack_seq, remote_ip, modex->ports[ack->ss_channel]); } #endif @@ -260,9 +244,7 @@ opal_btl_usnic_ack_send( /* * Sending an ACK has completed, return the segment to the free list */ -void -opal_btl_usnic_ack_complete(opal_btl_usnic_module_t *module, - opal_btl_usnic_ack_segment_t *ack) +void opal_btl_usnic_ack_complete(opal_btl_usnic_module_t *module, opal_btl_usnic_ack_segment_t *ack) { ++module->mod_channels[USNIC_PRIORITY_CHANNEL].credits; opal_btl_usnic_ack_segment_return(module, ack); @@ -275,25 +257,20 @@ opal_btl_usnic_ack_complete(opal_btl_usnic_module_t *module, * Callback for when a send times out without receiving a * corresponding ACK. */ -void -opal_btl_usnic_ack_timeout( - opal_hotel_t *hotel, - int room_num, - void *occupant) +void opal_btl_usnic_ack_timeout(opal_hotel_t *hotel, int room_num, void *occupant) { opal_btl_usnic_send_segment_t *seg; opal_btl_usnic_endpoint_t *endpoint; opal_btl_usnic_module_t *module; - seg = (opal_btl_usnic_send_segment_t*) occupant; + seg = (opal_btl_usnic_send_segment_t *) occupant; endpoint = seg->ss_parent_frag->sf_endpoint; module = endpoint->endpoint_module; #if MSGDEBUG1 { - opal_output(0, "Send timeout! seg %p, room %d, seq %" UDSEQ "\n", - (void*)seg, seg->ss_hotel_room, - seg->ss_base.us_btl_header->pkt_seq); + opal_output(0, "Send timeout! seg %p, room %d, seq %" UDSEQ "\n", (void *) seg, + seg->ss_hotel_room, seg->ss_base.us_btl_header->pkt_seq); } #endif @@ -301,8 +278,7 @@ opal_btl_usnic_ack_timeout( seg->ss_hotel_room = -1; /* Queue up this frag to be resent */ - opal_list_append(&(module->pending_resend_segs), - &(seg->ss_base.us_list.super)); + opal_list_append(&(module->pending_resend_segs), &(seg->ss_base.us_list.super)); /* Stats */ ++module->stats.num_timeout_retrans; diff --git a/opal/mca/btl/usnic/btl_usnic_ack.h b/opal/mca/btl/usnic/btl_usnic_ack.h index e1d4fe6fc87..7dbfb3ce0eb 100644 --- a/opal/mca/btl/usnic/btl_usnic_ack.h +++ b/opal/mca/btl/usnic/btl_usnic_ack.h @@ -15,93 +15,78 @@ #include "opal/class/opal_hotel.h" #include "btl_usnic.h" -#include "btl_usnic_frag.h" -#include "btl_usnic_endpoint.h" #include "btl_usnic_compat.h" +#include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" /* Invoke the descriptor callback for a (non-PUT) send frag, updating * stats and clearing the _CALLBACK flag in the process. */ -#define OPAL_BTL_USNIC_DO_SEND_FRAG_CB(module, send_frag, comment) \ - do { \ - MSGDEBUG1_OUT("%s:%d: %s SEND callback for module=%p frag=%p\n", \ - __func__, __LINE__, \ - (comment), (void *)(module), (void *)(send_frag)); \ - (send_frag)->sf_base.uf_base.des_cbfunc( \ - &(module)->super, \ - (send_frag)->sf_endpoint, \ - &(send_frag)->sf_base.uf_base, \ - OPAL_SUCCESS); \ - frag->sf_base.uf_base.des_flags &= ~MCA_BTL_DES_SEND_ALWAYS_CALLBACK; \ - ++((module)->stats.pml_send_callbacks); \ +#define OPAL_BTL_USNIC_DO_SEND_FRAG_CB(module, send_frag, comment) \ + do { \ + MSGDEBUG1_OUT("%s:%d: %s SEND callback for module=%p frag=%p\n", __func__, __LINE__, \ + (comment), (void *) (module), (void *) (send_frag)); \ + (send_frag)->sf_base.uf_base.des_cbfunc(&(module)->super, (send_frag)->sf_endpoint, \ + &(send_frag)->sf_base.uf_base, OPAL_SUCCESS); \ + frag->sf_base.uf_base.des_flags &= ~MCA_BTL_DES_SEND_ALWAYS_CALLBACK; \ + ++((module)->stats.pml_send_callbacks); \ } while (0) #if BTL_VERSION == 30 /* Invoke the descriptor callback for a send frag that was a PUT, * updating stats and clearing the _CALLBACK flag in the process. */ -#define OPAL_BTL_USNIC_DO_PUT_FRAG_CB(module, send_frag, comment) \ - do { \ - MSGDEBUG1_OUT("%s:%d: %s PUT callback for module=%p frag=%p\n", \ - __func__, __LINE__, \ - (comment), (void *)(module), (void *)(send_frag)); \ - mca_btl_base_rdma_completion_fn_t func = \ - (mca_btl_base_rdma_completion_fn_t) \ - (send_frag)->sf_base.uf_base.des_cbfunc; \ - func(&(module)->super, \ - (send_frag)->sf_endpoint, \ - (send_frag)->sf_base.uf_local_seg[0].seg_addr.pval, \ - NULL, \ - (send_frag)->sf_base.uf_base.des_context, \ - (send_frag)->sf_base.uf_base.des_cbdata, \ - OPAL_SUCCESS); \ - ++((module)->stats.pml_send_callbacks); \ - } while (0) +# define OPAL_BTL_USNIC_DO_PUT_FRAG_CB(module, send_frag, comment) \ + do { \ + MSGDEBUG1_OUT("%s:%d: %s PUT callback for module=%p frag=%p\n", __func__, __LINE__, \ + (comment), (void *) (module), (void *) (send_frag)); \ + mca_btl_base_rdma_completion_fn_t func = (mca_btl_base_rdma_completion_fn_t)( \ + send_frag) \ + ->sf_base.uf_base.des_cbfunc; \ + func(&(module)->super, (send_frag)->sf_endpoint, \ + (send_frag)->sf_base.uf_local_seg[0].seg_addr.pval, NULL, \ + (send_frag)->sf_base.uf_base.des_context, \ + (send_frag)->sf_base.uf_base.des_cbdata, OPAL_SUCCESS); \ + ++((module)->stats.pml_send_callbacks); \ + } while (0) #endif /* * Reap an ACK send that is complete */ void opal_btl_usnic_ack_complete(opal_btl_usnic_module_t *module, - opal_btl_usnic_ack_segment_t *ack); - + opal_btl_usnic_ack_segment_t *ack); /* * Send an ACK */ -int opal_btl_usnic_ack_send(opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint); +int opal_btl_usnic_ack_send(opal_btl_usnic_module_t *module, opal_btl_usnic_endpoint_t *endpoint); /* * Callback for when a send times out without receiving a * corresponding ACK */ -void opal_btl_usnic_ack_timeout(opal_hotel_t *hotel, int room_num, - void *occupant); +void opal_btl_usnic_ack_timeout(opal_hotel_t *hotel, int room_num, void *occupant); /* * Handle an incoming ACK */ -void opal_btl_usnic_handle_ack(opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_seq_t ack_seq); +void opal_btl_usnic_handle_ack(opal_btl_usnic_endpoint_t *endpoint, opal_btl_usnic_seq_t ack_seq); -static inline void -opal_btl_usnic_piggyback_ack( - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_segment_t *sseg) +static inline void opal_btl_usnic_piggyback_ack(opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_segment_t *sseg) { /* If ACK is needed, piggy-back it here and send it on */ if (endpoint->endpoint_ack_needed) { opal_btl_usnic_remove_from_endpoints_needing_ack(endpoint); - sseg->ss_base.us_btl_header->ack_seq = - SEQ_DIFF(endpoint->endpoint_next_contig_seq_to_recv, 1); + sseg->ss_base.us_btl_header->ack_seq = SEQ_DIFF(endpoint->endpoint_next_contig_seq_to_recv, + 1); sseg->ss_base.us_btl_header->ack_present = 1; #if MSGDEBUG1 - opal_output(0, "Piggy-backing ACK for sequence %"UDSEQ"\n", - sseg->ss_base.us_btl_header->ack_seq); + opal_output(0, "Piggy-backing ACK for sequence %" UDSEQ "\n", + sseg->ss_base.us_btl_header->ack_seq); #endif } else { sseg->ss_base.us_btl_header->ack_present = 0; } } - #endif /* BTL_USNIC_ACK_H */ diff --git a/opal/mca/btl/usnic/btl_usnic_cagent.c b/opal/mca/btl/usnic/btl_usnic_cagent.c index 105d5dfcfe5..7d821f2e591 100644 --- a/opal/mca/btl/usnic/btl_usnic_cagent.c +++ b/opal/mca/btl/usnic/btl_usnic_cagent.c @@ -13,23 +13,23 @@ #include "opal_config.h" #include -#include #include +#include #include #include #ifdef HAVE_ALLOCA_H -#include +# include #endif -#include "opal_stdint.h" #include "opal/mca/threads/mutex.h" -#include "opal/util/event.h" -#include "opal/util/show_help.h" #include "opal/types.h" -#include "opal/util/output.h" +#include "opal/util/event.h" #include "opal/util/fd.h" -#include "opal/util/string_copy.h" +#include "opal/util/output.h" #include "opal/util/printf.h" +#include "opal/util/show_help.h" +#include "opal/util/string_copy.h" +#include "opal_stdint.h" #include "btl_usnic.h" #include "btl_usnic_connectivity.h" @@ -54,7 +54,6 @@ static opal_list_t pings_pending; static opal_list_t ping_results; static volatile bool agent_initialized = false; - /* * Holds all the information about a UDP port that the agent thread is * listening on (for incoming PINGs and ACKs). @@ -95,14 +94,11 @@ typedef struct { OBJ_CLASS_DECLARATION(agent_ipc_listener_t); -typedef enum { - AGENT_MSG_TYPE_PING = 17, - AGENT_MSG_TYPE_ACK -} agent_udp_message_type_t; +typedef enum { AGENT_MSG_TYPE_PING = 17, AGENT_MSG_TYPE_ACK } agent_udp_message_type_t; // Arbitrary 64 bit numbers #define MAGIC_ORIGINATOR 0x9a9e2fbce63a11e5 -#define MAGIC_TARGET 0x60735c68f368aace +#define MAGIC_TARGET 0x60735c68f368aace /* * Ping and ACK messages @@ -159,18 +155,14 @@ typedef struct { OBJ_CLASS_DECLARATION(agent_ping_t); - /************************************************************************** * Utility functions, constructors, destructors **************************************************************************/ static void udp_port_listener_zero(agent_udp_port_listener_t *obj) { - obj->ipv4_addr = - obj->netmask = - obj->max_msg_size = 0; - obj->nodename = - obj->usnic_name = NULL; + obj->ipv4_addr = obj->netmask = obj->max_msg_size = 0; + obj->nodename = obj->usnic_name = NULL; memset(obj->ipv4_addr_str, 0, sizeof(obj->ipv4_addr_str)); obj->fd = -1; @@ -190,7 +182,7 @@ static void udp_port_listener_destructor(agent_udp_port_listener_t *obj) /* Find any pings that are pending on this listener and delete them */ agent_ping_t *ap, *apnext; - OPAL_LIST_FOREACH_SAFE(ap, apnext, &pings_pending, agent_ping_t) { + OPAL_LIST_FOREACH_SAFE (ap, apnext, &pings_pending, agent_ping_t) { if (ap->src_ipv4_addr == obj->ipv4_addr) { opal_list_remove_item(&pings_pending, &ap->super); OBJ_RELEASE(ap); @@ -220,9 +212,7 @@ static void udp_port_listener_destructor(agent_udp_port_listener_t *obj) udp_port_listener_zero(obj); } -OBJ_CLASS_INSTANCE(agent_udp_port_listener_t, - opal_list_item_t, - udp_port_listener_constructor, +OBJ_CLASS_INSTANCE(agent_udp_port_listener_t, opal_list_item_t, udp_port_listener_constructor, udp_port_listener_destructor); static void ipc_listener_zero(agent_ipc_listener_t *obj) @@ -252,9 +242,7 @@ static void ipc_listener_destructor(agent_ipc_listener_t *obj) ipc_listener_zero(obj); } -OBJ_CLASS_INSTANCE(agent_ipc_listener_t, - opal_list_item_t, - ipc_listener_constructor, +OBJ_CLASS_INSTANCE(agent_ipc_listener_t, opal_list_item_t, ipc_listener_constructor, ipc_listener_destructor); static void agent_ping_result_zero(agent_ping_t *obj) @@ -293,16 +281,13 @@ static void agent_ping_result_destructor(agent_ping_t *obj) agent_ping_result_zero(obj); } -OBJ_CLASS_INSTANCE(agent_ping_t, - opal_list_item_t, - agent_ping_result_constructor, +OBJ_CLASS_INSTANCE(agent_ping_t, opal_list_item_t, agent_ping_result_constructor, agent_ping_result_destructor); /* * Wrapper around sendto() loop */ -static void agent_sendto(int fd, char *buffer, ssize_t numbytes, - struct sockaddr *addr) +static void agent_sendto(int fd, char *buffer, ssize_t numbytes, struct sockaddr *addr) { ssize_t rc; while (1) { @@ -321,8 +306,7 @@ static void agent_sendto(int fd, char *buffer, ssize_t numbytes, } char *msg; - opal_asprintf(&msg, "Unexpected sendto() error: errno=%d (%s)", - errno, strerror(errno)); + opal_asprintf(&msg, "Unexpected sendto() error: errno=%d (%s)", errno, strerror(errno)); ABORT(msg); /* Will not return */ } @@ -342,20 +326,21 @@ static void agent_sendto(int fd, char *buffer, ssize_t numbytes, /* * Handle an incoming PING message (send an ACK) */ -static void agent_thread_handle_ping(agent_udp_port_listener_t *listener, - ssize_t numbytes, struct sockaddr *from) +static void agent_thread_handle_ping(agent_udp_port_listener_t *listener, ssize_t numbytes, + struct sockaddr *from) { /* If the size we received isn't equal to what the sender says it sent, do the simple thing: just don't send an ACK */ - agent_udp_message_t *msg = (agent_udp_message_t*) listener->buffer; - struct sockaddr_in *src_addr_in = (struct sockaddr_in*) from; + agent_udp_message_t *msg = (agent_udp_message_t *) listener->buffer; + struct sockaddr_in *src_addr_in = (struct sockaddr_in *) from; if (msg->size != numbytes) { char str[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &src_addr_in->sin_addr, str, sizeof(str)); - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got bad ping: %d bytes from %s, expected %d (discarded)", - (int) numbytes, str, (int) msg->size); + opal_output_verbose( + 20, USNIC_OUT, + "usNIC connectivity got bad ping: %d bytes from %s, expected %d (discarded)", + (int) numbytes, str, (int) msg->size); return; } @@ -367,32 +352,32 @@ static void agent_thread_handle_ping(agent_udp_port_listener_t *listener, char msg_ipv4_addr_str[IPV4STRADDRLEN]; char real_ipv4_addr_str[IPV4STRADDRLEN]; - opal_btl_usnic_snprintf_ipv4_addr(msg_ipv4_addr_str, - sizeof(msg_ipv4_addr_str), + opal_btl_usnic_snprintf_ipv4_addr(msg_ipv4_addr_str, sizeof(msg_ipv4_addr_str), msg->src_ipv4_addr, 0); - opal_btl_usnic_snprintf_ipv4_addr(real_ipv4_addr_str, - sizeof(real_ipv4_addr_str), + opal_btl_usnic_snprintf_ipv4_addr(real_ipv4_addr_str, sizeof(real_ipv4_addr_str), src_addr_in->sin_addr.s_addr, 0); if (msg->src_ipv4_addr != src_addr_in->sin_addr.s_addr) { - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got bad ping (from unexpected address: %s != %s, discarded)", - msg_ipv4_addr_str, real_ipv4_addr_str); + opal_output_verbose( + 20, USNIC_OUT, + "usNIC connectivity got bad ping (from unexpected address: %s != %s, discarded)", + msg_ipv4_addr_str, real_ipv4_addr_str); return; } if (msg->magic_number != MAGIC_ORIGINATOR) { opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got bad ping (magic number: %" PRIu64 ", discarded)", + "usNIC connectivity got bad ping (magic number: %" PRIu64 + ", discarded)", msg->magic_number); return; } - if (msg->major_version != OPAL_MAJOR_VERSION || - msg->minor_version != OPAL_MINOR_VERSION) { + if (msg->major_version != OPAL_MAJOR_VERSION || msg->minor_version != OPAL_MINOR_VERSION) { opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got bad ping (originator version: %d.%d, expected %d.%d, discarded)", - msg->major_version, msg->minor_version, - OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION); + "usNIC connectivity got bad ping (originator version: %d.%d, expected " + "%d.%d, discarded)", + msg->major_version, msg->minor_version, OPAL_MAJOR_VERSION, + OPAL_MINOR_VERSION); return; } @@ -401,8 +386,8 @@ static void agent_thread_handle_ping(agent_udp_port_listener_t *listener, expected. */ opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got PING (size=%ld) from %s; sending ACK", - numbytes, msg_ipv4_addr_str); + "usNIC connectivity got PING (size=%ld) from %s; sending ACK", numbytes, + msg_ipv4_addr_str); /* Send back an ACK. No need to allocate a new buffer; just re-use the same buffer we just got. Note that msg->size is @@ -412,26 +397,27 @@ static void agent_thread_handle_ping(agent_udp_port_listener_t *listener, msg->message_type = AGENT_MSG_TYPE_ACK; msg->magic_number = MAGIC_TARGET; - agent_sendto(listener->fd, (char*) listener->buffer, sizeof(*msg), from); + agent_sendto(listener->fd, (char *) listener->buffer, sizeof(*msg), from); } /* * Handle an incoming ACK message */ -static void agent_thread_handle_ack(agent_udp_port_listener_t *listener, - ssize_t numbytes, struct sockaddr *from) +static void agent_thread_handle_ack(agent_udp_port_listener_t *listener, ssize_t numbytes, + struct sockaddr *from) { char str[INET_ADDRSTRLEN]; - struct sockaddr_in *src_addr_in = (struct sockaddr_in*) from; + struct sockaddr_in *src_addr_in = (struct sockaddr_in *) from; inet_ntop(AF_INET, &src_addr_in->sin_addr, str, sizeof(str)); /* If we got a wonky ACK message that is the wrong length, just return */ - agent_udp_message_t *msg = (agent_udp_message_t*) listener->buffer; + agent_udp_message_t *msg = (agent_udp_message_t *) listener->buffer; if (numbytes != sizeof(*msg)) { - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got bad ACK: %d bytes from %s, expected %d (discarded)", - (int) numbytes, str, (int) sizeof(*msg)); + opal_output_verbose( + 20, USNIC_OUT, + "usNIC connectivity got bad ACK: %d bytes from %s, expected %d (discarded)", + (int) numbytes, str, (int) sizeof(*msg)); return; } if (msg->magic_number != MAGIC_TARGET) { @@ -445,11 +431,9 @@ static void agent_thread_handle_ack(agent_udp_port_listener_t *listener, If we don't find a match, we'll drop it. */ agent_ping_t *ap; uint32_t src_in_port = ntohs(src_addr_in->sin_port); - OPAL_LIST_FOREACH(ap, &pings_pending, agent_ping_t) { - if (ap->dest_ipv4_addr == src_addr_in->sin_addr.s_addr && - ap->dest_udp_port == src_in_port && - ap->src_ipv4_addr == msg->src_ipv4_addr && - ap->src_udp_port == msg->src_udp_port) { + OPAL_LIST_FOREACH (ap, &pings_pending, agent_ping_t) { + if (ap->dest_ipv4_addr == src_addr_in->sin_addr.s_addr && ap->dest_udp_port == src_in_port + && ap->src_ipv4_addr == msg->src_ipv4_addr && ap->src_udp_port == msg->src_udp_port) { /* Found it -- indicate that it has been acked */ for (int i = 0; i < NUM_PING_SIZES; ++i) { if (ap->sizes[i] == msg->size) { @@ -472,19 +456,18 @@ static void agent_thread_handle_ack(agent_udp_port_listener_t *listener, */ static void agent_thread_receive_ping(int fd, short flags, void *context) { - agent_udp_port_listener_t *listener = - (agent_udp_port_listener_t *) context; + agent_udp_port_listener_t *listener = (agent_udp_port_listener_t *) context; assert(NULL != listener); /* Receive the message */ ssize_t numbytes; struct sockaddr src_addr; - struct sockaddr_in *src_addr_in = (struct sockaddr_in*) &src_addr; + struct sockaddr_in *src_addr_in = (struct sockaddr_in *) &src_addr; socklen_t addrlen = sizeof(src_addr); while (1) { - numbytes = recvfrom(listener->fd, listener->buffer, listener->max_msg_size, 0, - &src_addr, &addrlen); + numbytes = recvfrom(listener->fd, listener->buffer, listener->max_msg_size, 0, &src_addr, + &addrlen); if (numbytes > 0) { break; } else if (numbytes < 0) { @@ -517,11 +500,10 @@ static void agent_thread_receive_ping(int fd, short flags, void *context) } } -static agent_udp_port_listener_t * -agent_thread_find_listener(uint32_t ipv4_addr, uint32_t *udp_port) +static agent_udp_port_listener_t *agent_thread_find_listener(uint32_t ipv4_addr, uint32_t *udp_port) { agent_udp_port_listener_t *listener; - OPAL_LIST_FOREACH(listener, &udp_port_listeners, agent_udp_port_listener_t) { + OPAL_LIST_FOREACH (listener, &udp_port_listeners, agent_udp_port_listener_t) { if (listener->ipv4_addr == ipv4_addr) { *udp_port = listener->udp_port; return listener; @@ -535,16 +517,13 @@ agent_thread_find_listener(uint32_t ipv4_addr, uint32_t *udp_port) * Send reply back from the LISTEN command: send back the IP address * and UDP port that we're listening on. */ -static int agent_thread_cmd_listen_reply(int fd, - uint32_t addr, int32_t udp_port) +static int agent_thread_cmd_listen_reply(int fd, uint32_t addr, int32_t udp_port) { int ret; - opal_btl_usnic_connectivity_cmd_listen_reply_t cmd = { - .cmd = CONNECTIVITY_AGENT_CMD_LISTEN, - .ipv4_addr = addr, - .udp_port = udp_port - }; + opal_btl_usnic_connectivity_cmd_listen_reply_t cmd = {.cmd = CONNECTIVITY_AGENT_CMD_LISTEN, + .ipv4_addr = addr, + .udp_port = udp_port}; ret = opal_fd_write(fd, sizeof(cmd), &cmd); if (OPAL_SUCCESS != ret) { @@ -587,8 +566,7 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) if (NULL == udp_listener->module) { udp_listener->module = cmd.module; } - agent_thread_cmd_listen_reply(ipc_listener->client_fd, - cmd.ipv4_addr, udp_port); + agent_thread_cmd_listen_reply(ipc_listener->client_fd, cmd.ipv4_addr, udp_port); return; } @@ -611,8 +589,8 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) address in sockaddr_in form, it's not worth using inet_ntop() */ opal_btl_usnic_snprintf_ipv4_addr(udp_listener->ipv4_addr_str, - sizeof(udp_listener->ipv4_addr_str), - cmd.ipv4_addr, cmd.netmask); + sizeof(udp_listener->ipv4_addr_str), cmd.ipv4_addr, + cmd.netmask); udp_listener->buffer = malloc(udp_listener->max_msg_size); if (NULL == udp_listener->buffer) { @@ -636,7 +614,7 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) inaddr.sin_addr.s_addr = cmd.ipv4_addr; inaddr.sin_port = htons(0); - ret = bind(udp_listener->fd, (struct sockaddr*) &inaddr, sizeof(inaddr)); + ret = bind(udp_listener->fd, (struct sockaddr *) &inaddr, sizeof(inaddr)); if (ret < 0) { OPAL_ERROR_LOG(ret); ABORT("Could not bind listening socket"); @@ -645,7 +623,7 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) /* Find out the port we got */ opal_socklen_t addrlen = sizeof(struct sockaddr_in); - ret = getsockname(udp_listener->fd, (struct sockaddr*) &inaddr, &addrlen); + ret = getsockname(udp_listener->fd, (struct sockaddr *) &inaddr, &addrlen); if (ret < 0) { OPAL_ERROR_LOG(ret); ABORT("Could not get UDP port number from listening socket"); @@ -653,10 +631,8 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) } udp_listener->udp_port = ntohs(inaddr.sin_port); - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity agent listening on %s:%d, (%s)", - udp_listener->ipv4_addr_str, - udp_listener->udp_port, + opal_output_verbose(20, USNIC_OUT, "usNIC connectivity agent listening on %s:%d, (%s)", + udp_listener->ipv4_addr_str, udp_listener->udp_port, udp_listener->usnic_name); /* Set the "don't fragment" bit on outgoing frames because we @@ -664,8 +640,7 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) peer, or fail if they have to fragment because of an MTU mismatch somewhere enroute */ int val = IP_PMTUDISC_DO; - ret = setsockopt(udp_listener->fd, IPPROTO_IP, IP_MTU_DISCOVER, - &val, sizeof(val)); + ret = setsockopt(udp_listener->fd, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)); if (0 != ret) { OPAL_ERROR_LOG(ret); ABORT("Unable to set \"do not fragment\" on UDP socket"); @@ -675,20 +650,16 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) /* Set the send and receive buffer sizes to our MTU size */ int temp; temp = (int) udp_listener->max_msg_size; - if ((ret = setsockopt(udp_listener->fd, SOL_SOCKET, SO_RCVBUF, - &temp, sizeof(temp))) < 0 || - (ret = setsockopt(udp_listener->fd, SOL_SOCKET, SO_SNDBUF, - &temp, sizeof(temp))) < 0) { + if ((ret = setsockopt(udp_listener->fd, SOL_SOCKET, SO_RCVBUF, &temp, sizeof(temp))) < 0 + || (ret = setsockopt(udp_listener->fd, SOL_SOCKET, SO_SNDBUF, &temp, sizeof(temp))) < 0) { OPAL_ERROR_LOG(ret); ABORT("Could not set socket buffer sizes"); /* Will not return */ } /* Create a listening event */ - opal_event_set(mca_btl_usnic_component.opal_evbase, - &udp_listener->event, udp_listener->fd, - OPAL_EV_READ | OPAL_EV_PERSIST, - agent_thread_receive_ping, udp_listener); + opal_event_set(mca_btl_usnic_component.opal_evbase, &udp_listener->event, udp_listener->fd, + OPAL_EV_READ | OPAL_EV_PERSIST, agent_thread_receive_ping, udp_listener); opal_event_add(&udp_listener->event, 0); /* Save this listener on the list of udp_port_listeners */ @@ -697,8 +668,8 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) udp_listener->active = true; /* Return the port number to the sender */ - ret = agent_thread_cmd_listen_reply(ipc_listener->client_fd, - cmd.ipv4_addr, udp_listener->udp_port); + ret = agent_thread_cmd_listen_reply(ipc_listener->client_fd, cmd.ipv4_addr, + udp_listener->udp_port); /* All done! */ return; @@ -709,12 +680,11 @@ static void agent_thread_cmd_listen(agent_ipc_listener_t *ipc_listener) */ static void agent_thread_send_ping(int fd, short flags, void *context) { - agent_ping_t *ap = (agent_ping_t*) context; + agent_ping_t *ap = (agent_ping_t *) context; ap->timer_active = false; char dest_ipv4_addr_str[IPV4STRADDRLEN]; - opal_btl_usnic_snprintf_ipv4_addr(dest_ipv4_addr_str, - sizeof(dest_ipv4_addr_str), + opal_btl_usnic_snprintf_ipv4_addr(dest_ipv4_addr_str, sizeof(dest_ipv4_addr_str), ap->dest_ipv4_addr, ap->dest_netmask); /* If we got all the ACKs for this ping, then move this ping from @@ -725,10 +695,8 @@ static void agent_thread_send_ping(int fd, short flags, void *context) opal_list_remove_item(&pings_pending, &ap->super); opal_list_append(&ping_results, &ap->super); - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity GOOD between %s <--> %s", - ap->listener->ipv4_addr_str, - dest_ipv4_addr_str); + opal_output_verbose(20, USNIC_OUT, "usNIC connectivity GOOD between %s <--> %s", + ap->listener->ipv4_addr_str, dest_ipv4_addr_str); for (int i = 0; i < 2; ++i) { if (NULL != ap->buffers[i]) { @@ -758,40 +726,29 @@ static void agent_thread_send_ping(int fd, short flags, void *context) } char ipv4_addr_str[IPV4STRADDRLEN]; - opal_btl_usnic_snprintf_ipv4_addr(ipv4_addr_str, sizeof(ipv4_addr_str), - ap->dest_ipv4_addr, + opal_btl_usnic_snprintf_ipv4_addr(ipv4_addr_str, sizeof(ipv4_addr_str), ap->dest_ipv4_addr, ap->dest_netmask); - opal_show_help("help-mpi-btl-usnic.txt", topic, true, - opal_process_info.nodename, - ap->listener->ipv4_addr_str, - ap->listener->usnic_name, - ap->dest_nodename, - ipv4_addr_str, - ap->sizes[0], - ap->sizes[1]); + opal_show_help("help-mpi-btl-usnic.txt", topic, true, opal_process_info.nodename, + ap->listener->ipv4_addr_str, ap->listener->usnic_name, ap->dest_nodename, + ipv4_addr_str, ap->sizes[0], ap->sizes[1]); opal_btl_usnic_exit(NULL); /* Will not return */ } time_t t = time(NULL); - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity pinging %s:%d (%s) from %s (%s) at %s", - dest_ipv4_addr_str, - ntohs(ap->dest_sockaddr.sin_port), - ap->dest_nodename, - ap->listener->ipv4_addr_str, - ap->listener->usnic_name, - ctime(&t)); + opal_output_verbose(20, USNIC_OUT, "usNIC connectivity pinging %s:%d (%s) from %s (%s) at %s", + dest_ipv4_addr_str, ntohs(ap->dest_sockaddr.sin_port), ap->dest_nodename, + ap->listener->ipv4_addr_str, ap->listener->usnic_name, ctime(&t)); /* Send the ping messages to the peer */ for (int i = 0; i < NUM_PING_SIZES; ++i) { - agent_sendto(ap->listener->fd, (char*) ap->buffers[i], ap->sizes[i], - (struct sockaddr*) &ap->dest_sockaddr); + agent_sendto(ap->listener->fd, (char *) ap->buffers[i], ap->sizes[i], + (struct sockaddr *) &ap->dest_sockaddr); } /* Set a timer to check if these pings are ACKed */ - opal_event_set(mca_btl_usnic_component.opal_evbase, &ap->timer, - -1, 0, agent_thread_send_ping, ap); + opal_event_set(mca_btl_usnic_component.opal_evbase, &ap->timer, -1, 0, agent_thread_send_ping, + ap); opal_event_add(&ap->timer, &ack_timeout); ap->timer_active = true; @@ -817,9 +774,8 @@ static void agent_thread_cmd_ping(agent_ipc_listener_t *ipc_listener) /* Have we already pinged this IP address / port? */ agent_ping_t *ap; - OPAL_LIST_FOREACH(ap, &ping_results, agent_ping_t) { - if (ap->dest_ipv4_addr == cmd.dest_ipv4_addr && - ap->dest_udp_port == cmd.dest_udp_port) { + OPAL_LIST_FOREACH (ap, &ping_results, agent_ping_t) { + if (ap->dest_ipv4_addr == cmd.dest_ipv4_addr && ap->dest_udp_port == cmd.dest_udp_port) { /* We already have results from pinging this IP address / port, so there's no need for further action */ return; @@ -827,9 +783,8 @@ static void agent_thread_cmd_ping(agent_ipc_listener_t *ipc_listener) } /* Are we in the middle of pinging this IP address / port? */ - OPAL_LIST_FOREACH(ap, &pings_pending, agent_ping_t) { - if (ap->dest_ipv4_addr == cmd.dest_ipv4_addr && - ap->dest_udp_port == cmd.dest_udp_port) { + OPAL_LIST_FOREACH (ap, &pings_pending, agent_ping_t) { + if (ap->dest_ipv4_addr == cmd.dest_ipv4_addr && ap->dest_udp_port == cmd.dest_udp_port) { /* We're already in the middle of pinging this IP address / port, so there's no need for further action */ return; @@ -840,8 +795,7 @@ static void agent_thread_cmd_ping(agent_ipc_listener_t *ipc_listener) ipv4 address */ bool found = false; agent_udp_port_listener_t *udp_listener; - OPAL_LIST_FOREACH(udp_listener, &udp_port_listeners, - agent_udp_port_listener_t) { + OPAL_LIST_FOREACH (udp_listener, &udp_port_listeners, agent_udp_port_listener_t) { if (udp_listener->ipv4_addr == cmd.src_ipv4_addr) { found = true; break; @@ -895,7 +849,7 @@ static void agent_thread_cmd_ping(agent_ipc_listener_t *ipc_listener) } /* Fill in the message with return addressing information */ - msg = (agent_udp_message_t*) ap->buffers[i]; + msg = (agent_udp_message_t *) ap->buffers[i]; msg->message_type = AGENT_MSG_TYPE_PING; msg->src_ipv4_addr = ap->src_ipv4_addr; msg->src_udp_port = ap->src_udp_port; @@ -947,7 +901,7 @@ static void agent_thread_cmd_unlisten(agent_ipc_listener_t *ipc_listener) static void agent_thread_ipc_receive(int fd, short flags, void *context) { int32_t command; - agent_ipc_listener_t *ipc_listener = (agent_ipc_listener_t*) context; + agent_ipc_listener_t *ipc_listener = (agent_ipc_listener_t *) context; /* Read the command */ command = -1; @@ -962,9 +916,8 @@ static void agent_thread_ipc_receive(int fd, short flags, void *context) /* Will not return */ } - assert(CONNECTIVITY_AGENT_CMD_LISTEN == command || - CONNECTIVITY_AGENT_CMD_PING == command || - CONNECTIVITY_AGENT_CMD_UNLISTEN == command); + assert(CONNECTIVITY_AGENT_CMD_LISTEN == command || CONNECTIVITY_AGENT_CMD_PING == command + || CONNECTIVITY_AGENT_CMD_UNLISTEN == command); switch (command) { case CONNECTIVITY_AGENT_CMD_LISTEN: @@ -1014,8 +967,9 @@ static void agent_thread_accept(int fd, short flags, void *context) /* Will not return */ } if (0 != memcmp(msg, CONNECTIVITY_MAGIC_TOKEN, tlen)) { - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity got bad IPC client (wrong magic token); disconnected"); + opal_output_verbose( + 20, USNIC_OUT, + "usNIC connectivity got bad IPC client (wrong magic token); disconnected"); close(client_fd); return; } @@ -1029,18 +983,15 @@ static void agent_thread_accept(int fd, short flags, void *context) /* Write back the magic token to ACK that we got the peer's magic token and all is kosher */ - if (OPAL_SUCCESS != opal_fd_write(client_fd, tlen, - CONNECTIVITY_MAGIC_TOKEN)) { + if (OPAL_SUCCESS != opal_fd_write(client_fd, tlen, CONNECTIVITY_MAGIC_TOKEN)) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); ABORT("usnic connectivity agent IPC read failed"); /* Will not return */ } /* Add this IPC listener to the event base */ - opal_event_set(mca_btl_usnic_component.opal_evbase, - &listener->event, client_fd, - OPAL_EV_READ | OPAL_EV_PERSIST, - agent_thread_ipc_receive, listener); + opal_event_set(mca_btl_usnic_component.opal_evbase, &listener->event, client_fd, + OPAL_EV_READ | OPAL_EV_PERSIST, agent_thread_ipc_receive, listener); opal_event_add(&listener->event, 0); /* Save this listener on the list of ipc_listeners */ @@ -1078,25 +1029,23 @@ static void agent_thread_finalize(int fd, short flags, void *context) first = false; } - if (ipc_accepts < opal_process_info.num_local_peers && - time(NULL) < timestamp + 10) { - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity agent delaying shutdown until all clients connect..."); + if (ipc_accepts < opal_process_info.num_local_peers && time(NULL) < timestamp + 10) { + opal_output_verbose( + 20, USNIC_OUT, + "usNIC connectivity agent delaying shutdown until all clients connect..."); opal_event_t *ev = calloc(sizeof(*ev), 1); - struct timeval finalize_retry = { - .tv_sec = 0, - .tv_usec = 10000 - }; + struct timeval finalize_retry = {.tv_sec = 0, .tv_usec = 10000}; - opal_event_set(mca_btl_usnic_component.opal_evbase, - ev, -1, 0, agent_thread_finalize, ev); + opal_event_set(mca_btl_usnic_component.opal_evbase, ev, -1, 0, agent_thread_finalize, ev); opal_event_add(ev, &finalize_retry); return; } if (ipc_accepts < opal_process_info.num_local_peers) { opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity agent: only %d of %d clients connected, but timeout has expired -- exiting anyway", ipc_accepts, opal_process_info.num_local_peers); + "usNIC connectivity agent: only %d of %d clients connected, but " + "timeout has expired -- exiting anyway", + ipc_accepts, opal_process_info.num_local_peers); } /* Remove the agent listening event from the opal async event @@ -1105,27 +1054,25 @@ static void agent_thread_finalize(int fd, short flags, void *context) /* Shut down all active udp_port_listeners */ agent_udp_port_listener_t *udp_listener, *ulnext; - OPAL_LIST_FOREACH_SAFE(udp_listener, ulnext, &udp_port_listeners, - agent_udp_port_listener_t) { + OPAL_LIST_FOREACH_SAFE (udp_listener, ulnext, &udp_port_listeners, agent_udp_port_listener_t) { OBJ_RELEASE(udp_listener); } /* Destroy the pending pings and ping results */ agent_ping_t *request, *pnext; - OPAL_LIST_FOREACH_SAFE(request, pnext, &pings_pending, agent_ping_t) { + OPAL_LIST_FOREACH_SAFE (request, pnext, &pings_pending, agent_ping_t) { opal_list_remove_item(&pings_pending, &request->super); OBJ_RELEASE(request); } - OPAL_LIST_FOREACH_SAFE(request, pnext, &ping_results, agent_ping_t) { + OPAL_LIST_FOREACH_SAFE (request, pnext, &ping_results, agent_ping_t) { opal_list_remove_item(&ping_results, &request->super); OBJ_RELEASE(request); } /* Shut down all active ipc_listeners */ agent_ipc_listener_t *ipc_listener, *inext; - OPAL_LIST_FOREACH_SAFE(ipc_listener, inext, &ipc_listeners, - agent_ipc_listener_t) { + OPAL_LIST_FOREACH_SAFE (ipc_listener, inext, &ipc_listeners, agent_ipc_listener_t) { OBJ_RELEASE(ipc_listener); } @@ -1154,10 +1101,8 @@ int opal_btl_usnic_connectivity_agent_init(void) /* Make a struct timeval for use with timer events. Note that the MCA param is expressed in terms of *milli*seconds, but the timeval timeout is expressed in terms of *micro*seconds. */ - ack_timeout.tv_sec = - mca_btl_usnic_component.connectivity_ack_timeout / 1000; - ack_timeout.tv_usec = - 1000 * (mca_btl_usnic_component.connectivity_ack_timeout % 1000); + ack_timeout.tv_sec = mca_btl_usnic_component.connectivity_ack_timeout / 1000; + ack_timeout.tv_usec = 1000 * (mca_btl_usnic_component.connectivity_ack_timeout % 1000); /* Create lists */ OBJ_CONSTRUCT(&udp_port_listeners, opal_list_t); @@ -1178,8 +1123,8 @@ int opal_btl_usnic_connectivity_agent_init(void) /* Will not return */ } - opal_asprintf(&ipc_filename, "%s/%s", - opal_process_info.job_session_dir, CONNECTIVITY_SOCK_NAME); + opal_asprintf(&ipc_filename, "%s/%s", opal_process_info.job_session_dir, + CONNECTIVITY_SOCK_NAME); if (NULL == ipc_filename) { OPAL_ERROR_LOG(OPAL_ERR_IN_ERRNO); ABORT("Out of memory"); @@ -1194,8 +1139,7 @@ int opal_btl_usnic_connectivity_agent_init(void) address.sun_family = AF_UNIX; opal_string_copy(address.sun_path, ipc_filename, sizeof(address.sun_path)); - if (bind(ipc_accept_fd, (struct sockaddr *) &address, - sizeof(struct sockaddr_un)) != 0) { + if (bind(ipc_accept_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0) { OPAL_ERROR_LOG(OPAL_ERR_IN_ERRNO); ABORT("bind() failed"); /* Will not return */ @@ -1212,14 +1156,11 @@ int opal_btl_usnic_connectivity_agent_init(void) } /* Add the socket to the event base */ - opal_event_set(mca_btl_usnic_component.opal_evbase, - &ipc_event, ipc_accept_fd, - OPAL_EV_READ | OPAL_EV_PERSIST, - agent_thread_accept, NULL); + opal_event_set(mca_btl_usnic_component.opal_evbase, &ipc_event, ipc_accept_fd, + OPAL_EV_READ | OPAL_EV_PERSIST, agent_thread_accept, NULL); opal_event_add(&ipc_event, 0); - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity agent initialized"); + opal_output_verbose(20, USNIC_OUT, "usNIC connectivity agent initialized"); agent_initialized = true; return OPAL_SUCCESS; } @@ -1238,16 +1179,13 @@ int opal_btl_usnic_connectivity_agent_finalize(void) the usNIC events. See the rationale for doing this in the comment in the agent_thread_finalize() function. */ opal_event_t *ev = calloc(sizeof(*ev), 1); - opal_event_set(mca_btl_usnic_component.opal_evbase, - ev, -1, OPAL_EV_WRITE, agent_thread_finalize, ev); + opal_event_set(mca_btl_usnic_component.opal_evbase, ev, -1, OPAL_EV_WRITE, + agent_thread_finalize, ev); opal_event_active(ev, OPAL_EV_WRITE, 1); /* Wait for the event to fire and complete */ while (agent_initialized) { - struct timespec tp = { - .tv_sec = 0, - .tv_nsec = 1000 - }; + struct timespec tp = {.tv_sec = 0, .tv_nsec = 1000}; nanosleep(&tp, NULL); } @@ -1262,7 +1200,6 @@ int opal_btl_usnic_connectivity_agent_finalize(void) ipc_filename = NULL; } - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity client finalized"); + opal_output_verbose(20, USNIC_OUT, "usNIC connectivity client finalized"); return OPAL_SUCCESS; } diff --git a/opal/mca/btl/usnic/btl_usnic_cclient.c b/opal/mca/btl/usnic/btl_usnic_cclient.c index 3de1b46763c..5f7b5534512 100644 --- a/opal/mca/btl/usnic/btl_usnic_cclient.c +++ b/opal/mca/btl/usnic/btl_usnic_cclient.c @@ -13,28 +13,28 @@ #include "opal_config.h" #include -#include +#include #include -#include +#include #include -#include +#include #include #ifdef HAVE_ALLOCA_H -#include +# include #endif #include -#include "opal_stdint.h" #include "opal/mca/threads/mutex.h" #include "opal/util/event.h" -#include "opal/util/output.h" #include "opal/util/fd.h" -#include "opal/util/string_copy.h" +#include "opal/util/output.h" #include "opal/util/printf.h" +#include "opal/util/string_copy.h" +#include "opal_stdint.h" #include "btl_usnic.h" -#include "btl_usnic_module.h" #include "btl_usnic_connectivity.h" +#include "btl_usnic_module.h" /************************************************************************** * Client-side data and methods @@ -43,7 +43,6 @@ static bool initialized = false; static int agent_fd = -1; - /* * Startup the agent and share our MCA param values with the it. */ @@ -64,8 +63,8 @@ int opal_btl_usnic_connectivity_client_init(void) } char *ipc_filename = NULL; - opal_asprintf(&ipc_filename, "%s/%s", - opal_process_info.job_session_dir, CONNECTIVITY_SOCK_NAME); + opal_asprintf(&ipc_filename, "%s/%s", opal_process_info.job_session_dir, + CONNECTIVITY_SOCK_NAME); if (NULL == ipc_filename) { OPAL_ERROR_LOG(OPAL_ERR_IN_ERRNO); ABORT("Out of memory"); @@ -110,8 +109,7 @@ int opal_btl_usnic_connectivity_client_init(void) int count = 0; while (1) { - int ret = connect(agent_fd, (struct sockaddr*) &address, - sizeof(address)); + int ret = connect(agent_fd, (struct sockaddr *) &address, sizeof(address)); if (0 == ret) { break; } @@ -132,8 +130,7 @@ int opal_btl_usnic_connectivity_client_init(void) /* Send the magic token */ int tlen = strlen(CONNECTIVITY_MAGIC_TOKEN); - if (OPAL_SUCCESS != opal_fd_write(agent_fd, tlen, - CONNECTIVITY_MAGIC_TOKEN)) { + if (OPAL_SUCCESS != opal_fd_write(agent_fd, tlen, CONNECTIVITY_MAGIC_TOKEN)) { OPAL_ERROR_LOG(OPAL_ERR_IN_ERRNO); ABORT("usnic connectivity client IPC connect write failed"); /* Will not return */ @@ -159,12 +156,10 @@ int opal_btl_usnic_connectivity_client_init(void) /* All done */ initialized = true; - opal_output_verbose(20, USNIC_OUT, - "usNIC connectivity client initialized"); + opal_output_verbose(20, USNIC_OUT, "usNIC connectivity client initialized"); return OPAL_SUCCESS; } - /* * Send a listen command to the agent */ @@ -185,12 +180,11 @@ int opal_btl_usnic_connectivity_listen(opal_btl_usnic_module_t *module) } /* Send the LISTEN command parameters */ - opal_btl_usnic_connectivity_cmd_listen_t cmd = { - .module = NULL, - .ipv4_addr = module->local_modex.ipv4_addr, - .netmask = module->local_modex.netmask, - .max_msg_size = module->local_modex.max_msg_size - }; + opal_btl_usnic_connectivity_cmd_listen_t cmd = {.module = NULL, + .ipv4_addr = module->local_modex.ipv4_addr, + .netmask = module->local_modex.netmask, + .max_msg_size = module->local_modex + .max_msg_size}; /* Only the MPI process who is also the agent will send the pointer value (it doesn't make sense otherwise) */ if (0 == opal_process_info.my_local_rank) { @@ -198,10 +192,8 @@ int opal_btl_usnic_connectivity_listen(opal_btl_usnic_module_t *module) } /* Ensure to NULL-terminate the passed strings */ - opal_string_copy(cmd.nodename, opal_process_info.nodename, - CONNECTIVITY_NODENAME_LEN); - opal_string_copy(cmd.usnic_name, module->linux_device_name, - CONNECTIVITY_IFNAME_LEN); + opal_string_copy(cmd.nodename, opal_process_info.nodename, CONNECTIVITY_NODENAME_LEN); + opal_string_copy(cmd.usnic_name, module->linux_device_name, CONNECTIVITY_IFNAME_LEN); if (OPAL_SUCCESS != opal_fd_write(agent_fd, sizeof(cmd), &cmd)) { OPAL_ERROR_LOG(OPAL_ERR_IN_ERRNO); @@ -225,11 +217,8 @@ int opal_btl_usnic_connectivity_listen(opal_btl_usnic_module_t *module) return OPAL_SUCCESS; } - -int opal_btl_usnic_connectivity_ping(uint32_t src_ipv4_addr, int src_port, - uint32_t dest_ipv4_addr, - uint32_t dest_netmask, int dest_port, - char *dest_nodename, +int opal_btl_usnic_connectivity_ping(uint32_t src_ipv4_addr, int src_port, uint32_t dest_ipv4_addr, + uint32_t dest_netmask, int dest_port, char *dest_nodename, size_t max_msg_size) { /* If connectivity checking is not enabled, do nothing */ @@ -249,14 +238,12 @@ int opal_btl_usnic_connectivity_ping(uint32_t src_ipv4_addr, int src_port, } /* Send the PING command parameters */ - opal_btl_usnic_connectivity_cmd_ping_t cmd = { - .src_ipv4_addr = src_ipv4_addr, - .src_udp_port = src_port, - .dest_ipv4_addr = dest_ipv4_addr, - .dest_netmask = dest_netmask, - .dest_udp_port = dest_port, - .max_msg_size = max_msg_size - }; + opal_btl_usnic_connectivity_cmd_ping_t cmd = {.src_ipv4_addr = src_ipv4_addr, + .src_udp_port = src_port, + .dest_ipv4_addr = dest_ipv4_addr, + .dest_netmask = dest_netmask, + .dest_udp_port = dest_port, + .max_msg_size = max_msg_size}; /* Ensure to NULL-terminate the passed string */ opal_string_copy(cmd.dest_nodename, dest_nodename, CONNECTIVITY_NODENAME_LEN); @@ -272,7 +259,6 @@ int opal_btl_usnic_connectivity_ping(uint32_t src_ipv4_addr, int src_port, return OPAL_SUCCESS; } - /* * Send an unlisten command to the agent */ @@ -310,7 +296,6 @@ int opal_btl_usnic_connectivity_unlisten(opal_btl_usnic_module_t *module) return OPAL_SUCCESS; } - /* * Shut down the connectivity client */ diff --git a/opal/mca/btl/usnic/btl_usnic_compat.c b/opal/mca/btl/usnic/btl_usnic_compat.c index b1dc6900c81..0dee1ab71c6 100644 --- a/opal/mca/btl/usnic/btl_usnic_compat.c +++ b/opal/mca/btl/usnic/btl_usnic_compat.c @@ -15,30 +15,23 @@ #include "opal_stdint.h" #include "btl_usnic_compat.h" -#include "btl_usnic_frag.h" -#include "btl_usnic_endpoint.h" #include "btl_usnic_connectivity.h" +#include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" #include "btl_usnic_send.h" #include "opal/util/proc.h" -void usnic_compat_modex_send(int *rc, - mca_base_component_t *component, - opal_btl_usnic_modex_t *modexes, - size_t size) +void usnic_compat_modex_send(int *rc, mca_base_component_t *component, + opal_btl_usnic_modex_t *modexes, size_t size) { - OPAL_MODEX_SEND(*rc, PMIX_REMOTE, component, - modexes, size); + OPAL_MODEX_SEND(*rc, PMIX_REMOTE, component, modexes, size); } -void usnic_compat_modex_recv(int *rc, - mca_base_component_t *component, - opal_proc_t *proc, - opal_btl_usnic_modex_t **modexes, - size_t *size) +void usnic_compat_modex_recv(int *rc, mca_base_component_t *component, opal_proc_t *proc, + opal_btl_usnic_modex_t **modexes, size_t *size) { - OPAL_MODEX_RECV(*rc, component, &proc->proc_name, - (uint8_t**) modexes, size); + OPAL_MODEX_RECV(*rc, component, &proc->proc_name, (uint8_t **) modexes, size); } uint64_t usnic_compat_rte_hash_name(opal_process_name_t *pname) @@ -61,14 +54,9 @@ const char *usnic_compat_proc_name_print(opal_process_name_t *pname) * requested if the given convertor cannot process the entire (*size). */ static inline opal_btl_usnic_send_frag_t * -prepare_src_small( - struct opal_btl_usnic_module_t* module, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags) +prepare_src_small(struct opal_btl_usnic_module_t *module, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, + uint32_t flags) { opal_btl_usnic_send_frag_t *frag; opal_btl_usnic_small_send_frag_t *sfrag; @@ -106,11 +94,10 @@ prepare_src_small( if (OPAL_UNLIKELY(opal_convertor_need_buffers(convertor))) { /* put user data just after end of 1st seg (upper layer header) */ assert(payload_len <= module->max_frag_payload); - usnic_convertor_pack_simple( - convertor, - (IOVBASE_TYPE*)(intptr_t)(frag->sf_base.uf_local_seg[0].seg_addr.lval + reserve), - *size, - size); + usnic_convertor_pack_simple(convertor, + (IOVBASE_TYPE *) (intptr_t)( + frag->sf_base.uf_local_seg[0].seg_addr.lval + reserve), + *size, size); payload_len = reserve + *size; frag->sf_base.uf_base.USNIC_SEND_LOCAL_COUNT = 1; /* PML will copy header into beginning of segment */ @@ -129,14 +116,11 @@ prepare_src_small( return frag; } -static void * -pack_chunk_seg_chain_with_reserve( - struct opal_btl_usnic_module_t* module, - opal_btl_usnic_large_send_frag_t *lfrag, - size_t reserve_len, - opal_convertor_t *convertor, - size_t max_convertor_bytes, - size_t *convertor_bytes_packed) +static void *pack_chunk_seg_chain_with_reserve(struct opal_btl_usnic_module_t *module, + opal_btl_usnic_large_send_frag_t *lfrag, + size_t reserve_len, opal_convertor_t *convertor, + size_t max_convertor_bytes, + size_t *convertor_bytes_packed) { opal_btl_usnic_chunk_segment_t *seg; void *ret_ptr = NULL; @@ -154,12 +138,10 @@ pack_chunk_seg_chain_with_reserve( *convertor_bytes_packed = 0; first_pass = true; - while (*convertor_bytes_packed < max_convertor_bytes || - first_pass) { + while (*convertor_bytes_packed < max_convertor_bytes || first_pass) { seg = opal_btl_usnic_chunk_segment_alloc(module); if (OPAL_UNLIKELY(NULL == seg)) { - opal_btl_usnic_util_abort("chunk segment allocation error", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("chunk segment allocation error", __FILE__, __LINE__); } ++n_segs; @@ -185,8 +167,8 @@ pack_chunk_seg_chain_with_reserve( *convertor_bytes_packed += max_data; /* If unable to pack any of the remaining bytes, release the - * most recently allocated segment and finish processing. - */ + * most recently allocated segment and finish processing. + */ if (seg_space == module->max_chunk_payload) { assert(max_data == 0); /* only way this can happen */ opal_btl_usnic_chunk_segment_return(module, seg); @@ -204,9 +186,8 @@ pack_chunk_seg_chain_with_reserve( opal_list_append(&lfrag->lsf_seg_chain, &seg->ss_base.us_list.super); #if MSGDEBUG1 - opal_output(0, "%s: appending seg=%p, frag=%p, payload=%zd\n", - __func__, (void *)seg, (void *)lfrag, - (module->max_chunk_payload - seg_space)); + opal_output(0, "%s: appending seg=%p, frag=%p, payload=%zd\n", __func__, (void *) seg, + (void *) lfrag, (module->max_chunk_payload - seg_space)); #endif first_pass = false; @@ -219,15 +200,11 @@ pack_chunk_seg_chain_with_reserve( * in the same manner as btl_prepare_src. Must return a smaller amount than * requested if the given convertor cannot process the entire (*size). */ -static opal_btl_usnic_send_frag_t * -prepare_src_large( - struct opal_btl_usnic_module_t* module, - struct mca_btl_base_endpoint_t* endpoint, - struct opal_convertor_t* convertor, - uint8_t order, - size_t reserve, - size_t* size, - uint32_t flags) +static opal_btl_usnic_send_frag_t *prepare_src_large(struct opal_btl_usnic_module_t *module, + struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, + uint8_t order, size_t reserve, size_t *size, + uint32_t flags) { opal_btl_usnic_send_frag_t *frag; opal_btl_usnic_large_send_frag_t *lfrag; @@ -252,9 +229,9 @@ prepare_src_large( if (OPAL_UNLIKELY(opal_convertor_need_buffers(convertor))) { /* threshold == -1 means always pack eagerly */ - if (mca_btl_usnic_component.pack_lazy_threshold >= 0 && - *size >= (size_t)mca_btl_usnic_component.pack_lazy_threshold) { - MSGDEBUG1_OUT("packing frag %p on the fly", (void *)frag); + if (mca_btl_usnic_component.pack_lazy_threshold >= 0 + && *size >= (size_t) mca_btl_usnic_component.pack_lazy_threshold) { + MSGDEBUG1_OUT("packing frag %p on the fly", (void *) frag); lfrag->lsf_pack_on_the_fly = true; /* tell the PML we will absorb as much as possible while still @@ -266,16 +243,13 @@ prepare_src_large( rc = opal_convertor_clone(convertor, &frag->sf_convertor, /*copy_stack=*/true); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { - opal_btl_usnic_util_abort("unexpected convertor clone error", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("unexpected convertor clone error", __FILE__, __LINE__); } - } - else { + } else { /* pack everything in the convertor into a chain of segments now, * leaving space for the PML header in the first segment */ - lfrag->lsf_base.sf_base.uf_local_seg[0].seg_addr.pval = - pack_chunk_seg_chain_with_reserve(module, lfrag, reserve, - convertor, *size, size); + lfrag->lsf_base.sf_base.uf_local_seg[0].seg_addr.pval + = pack_chunk_seg_chain_with_reserve(module, lfrag, reserve, convertor, *size, size); } /* We set SG[1] to {NULL,bytes_packed} so that various calculations @@ -287,8 +261,7 @@ prepare_src_large( } else { /* convertor not needed, just save the payload pointer in SG[1] */ lfrag->lsf_pack_on_the_fly = true; - opal_convertor_get_current_pointer(convertor, - &frag->sf_base.uf_local_seg[1].seg_addr.pval); + opal_convertor_get_current_pointer(convertor, &frag->sf_base.uf_local_seg[1].seg_addr.pval); frag->sf_base.uf_local_seg[1].seg_len = *size; } @@ -327,16 +300,11 @@ prepare_src_large( * NOTE that the *only* reason this routine is allowed to return a size smaller * than was requested is if the convertor cannot process the entire amount. */ -struct mca_btl_base_descriptor_t * -opal_btl_usnic_prepare_src(struct mca_btl_base_module_t *base_module, - struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, - size_t reserve, - size_t *size, - uint32_t flags) +struct mca_btl_base_descriptor_t *opal_btl_usnic_prepare_src( + struct mca_btl_base_module_t *base_module, struct mca_btl_base_endpoint_t *endpoint, + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, size_t *size, uint32_t flags) { - opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t*) base_module; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) base_module; opal_btl_usnic_send_frag_t *frag; uint32_t payload_len; #if MSGDEBUG2 @@ -353,30 +321,27 @@ opal_btl_usnic_prepare_src(struct mca_btl_base_module_t *base_module, */ payload_len = *size + reserve; if (payload_len <= module->max_frag_payload) { - frag = prepare_src_small(module, endpoint, convertor, - order, reserve, size, flags); + frag = prepare_src_small(module, endpoint, convertor, order, reserve, size, flags); } else { - frag = prepare_src_large(module, endpoint, convertor, - order, reserve, size, flags); + frag = prepare_src_large(module, endpoint, convertor, order, reserve, size, flags); } #if MSGDEBUG2 opal_output(0, "prep_src: %s %s frag %p, size=%d+%u (was %u), conv=%p\n", module->linux_device_name, - (reserve + *size) <= module->max_frag_payload?"small":"large", - (void *)frag, (int)reserve, (unsigned)*size, (unsigned)osize, - (void *)convertor); -#if MSGDEBUG1 + (reserve + *size) <= module->max_frag_payload ? "small" : "large", (void *) frag, + (int) reserve, (unsigned) *size, (unsigned) osize, (void *) convertor); +# if MSGDEBUG1 { unsigned i; mca_btl_base_descriptor_t *desc = &frag->sf_base.uf_base; - for (i=0; iUSNIC_SEND_LOCAL_COUNT; ++i) { + for (i = 0; i < desc->USNIC_SEND_LOCAL_COUNT; ++i) { opal_output(0, " %d: ptr:%p len:%d\n", i, - (void *)desc->USNIC_SEND_LOCAL[i].seg_addr.pval, + (void *) desc->USNIC_SEND_LOCAL[i].seg_addr.pval, desc->USNIC_SEND_LOCAL[i].seg_len); } } -#endif +# endif #endif return &frag->sf_base.uf_base; @@ -391,18 +356,16 @@ opal_btl_usnic_prepare_src(struct mca_btl_base_module_t *base_module, * Note that this function is only ever called with contiguous * buffers, so a convertor is not necessary. */ -int -opal_btl_usnic_put(struct mca_btl_base_module_t *base_module, - struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, - struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, - size_t size, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata) +int opal_btl_usnic_put(struct mca_btl_base_module_t *base_module, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata) { opal_btl_usnic_send_frag_t *sfrag; - opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t*) base_module; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) base_module; /* At least for the moment, continue to make a descriptor, like we used to in BTL 2.0 */ @@ -439,8 +402,7 @@ opal_btl_usnic_put(struct mca_btl_base_module_t *base_module, frag->uf_local_seg[0].seg_len = size; frag->uf_local_seg[0].seg_addr.pval = local_address; frag->uf_remote_seg[0].seg_len = size; - frag->uf_remote_seg[0].seg_addr.pval = - (void *)(uintptr_t) remote_address; + frag->uf_remote_seg[0].seg_addr.pval = (void *) (uintptr_t) remote_address; mca_btl_base_descriptor_t *desc; desc = &frag->uf_base; @@ -455,9 +417,7 @@ opal_btl_usnic_put(struct mca_btl_base_module_t *base_module, desc->order = order; int rc; - rc = opal_btl_usnic_finish_put_or_send(module, - (opal_btl_usnic_endpoint_t *)endpoint, - sfrag, + rc = opal_btl_usnic_finish_put_or_send(module, (opal_btl_usnic_endpoint_t *) endpoint, sfrag, /*tag=*/MCA_BTL_NO_ORDER); return rc; } diff --git a/opal/mca/btl/usnic/btl_usnic_compat.h b/opal/mca/btl/usnic/btl_usnic_compat.h index f2a6a486a96..4c42eae68d1 100644 --- a/opal/mca/btl/usnic/btl_usnic_compat.h +++ b/opal/mca/btl/usnic/btl_usnic_compat.h @@ -17,8 +17,8 @@ #ifndef BTL_USNIC_COMPAT_H #define BTL_USNIC_COMPAT_H -#include "opal/mca/rcache/rcache.h" #include "opal/mca/btl/btl.h" +#include "opal/mca/rcache/rcache.h" /************************************************************************/ @@ -40,8 +40,8 @@ #define USNIC_OUT opal_btl_base_framework.framework_output /* JMS Really want to be able to get the job size somehow... But for now, so that we can compile, just set it to a constant :-( */ -#define USNIC_MCW_SIZE 2 -#define proc_bound() (NULL != opal_process_info.cpuset ? 1 : 0) +#define USNIC_MCW_SIZE 2 +#define proc_bound() (NULL != opal_process_info.cpuset ? 1 : 0) #define USNIC_BTL_DEFAULT_VERSION(name) MCA_BTL_DEFAULT_VERSION(name) #define USNIC_SEND_LOCAL des_segments @@ -54,24 +54,20 @@ #define USNIC_RECV_REMOTE des_segments #define USNIC_RECV_REMOTE_COUNT des_segment_count -#define USNIC_PUT_LOCAL des_segments -#define USNIC_PUT_LOCAL_COUNT des_segment_count -#define USNIC_PUT_REMOTE des_segments -#define USNIC_PUT_REMOTE_COUNT des_segments_count +#define USNIC_PUT_LOCAL des_segments +#define USNIC_PUT_LOCAL_COUNT des_segment_count +#define USNIC_PUT_REMOTE des_segments +#define USNIC_PUT_REMOTE_COUNT des_segments_count -#define USNIC_COMPAT_FREE_LIST_GET(list, item) \ - (item) = opal_free_list_get((list)) -#define USNIC_COMPAT_FREE_LIST_RETURN(list, item) \ - opal_free_list_return((list), (item)) +#define USNIC_COMPAT_FREE_LIST_GET(list, item) (item) = opal_free_list_get((list)) +#define USNIC_COMPAT_FREE_LIST_RETURN(list, item) opal_free_list_return((list), (item)) #define usnic_compat_free_list_init opal_free_list_init /* * Performance critical; needs to be inline */ -static inline int -usnic_compat_proc_name_compare(opal_process_name_t a, - opal_process_name_t b) +static inline int usnic_compat_proc_name_compare(opal_process_name_t a, opal_process_name_t b) { return (bool) (a.jobid == b.jobid && a.vpid == b.vpid); } @@ -81,16 +77,11 @@ usnic_compat_proc_name_compare(opal_process_name_t a, /* Forward declare to avoid #include ordering complications */ struct opal_btl_usnic_modex_t; -void usnic_compat_modex_send(int *rc, - mca_base_component_t *component, - struct opal_btl_usnic_modex_t *modexes, - size_t size); +void usnic_compat_modex_send(int *rc, mca_base_component_t *component, + struct opal_btl_usnic_modex_t *modexes, size_t size); -void usnic_compat_modex_recv(int *rc, - mca_base_component_t *component, - opal_proc_t *proc, - struct opal_btl_usnic_modex_t **modexes, - size_t *size); +void usnic_compat_modex_recv(int *rc, mca_base_component_t *component, opal_proc_t *proc, + struct opal_btl_usnic_modex_t **modexes, size_t *size); uint64_t usnic_compat_rte_hash_name(opal_process_name_t *pname); const char *usnic_compat_proc_name_print(opal_process_name_t *pname); @@ -103,20 +94,15 @@ struct mca_btl_base_endpoint_t; struct mca_btl_base_descriptor_t * opal_btl_usnic_prepare_src(struct mca_btl_base_module_t *base_module, struct mca_btl_base_endpoint_t *endpoint, - struct opal_convertor_t *convertor, - uint8_t order, - size_t reserve, - size_t *size, - uint32_t flags); - -int -opal_btl_usnic_put(struct mca_btl_base_module_t *base_module, - struct mca_btl_base_endpoint_t *endpoint, - void *local_address, uint64_t remote_address, - struct mca_btl_base_registration_handle_t *local_handle, - struct mca_btl_base_registration_handle_t *remote_handle, - size_t size, int flags, int order, - mca_btl_base_rdma_completion_fn_t cbfunc, - void *cbcontext, void *cbdata); + struct opal_convertor_t *convertor, uint8_t order, size_t reserve, + size_t *size, uint32_t flags); + +int opal_btl_usnic_put(struct mca_btl_base_module_t *base_module, + struct mca_btl_base_endpoint_t *endpoint, void *local_address, + uint64_t remote_address, + struct mca_btl_base_registration_handle_t *local_handle, + struct mca_btl_base_registration_handle_t *remote_handle, size_t size, + int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc, + void *cbcontext, void *cbdata); #endif /* BTL_USNIC_COMPAT_H */ diff --git a/opal/mca/btl/usnic/btl_usnic_component.c b/opal/mca/btl/usnic/btl_usnic_component.c index ea796e8e3bb..44e3b2c5982 100644 --- a/opal/mca/btl/usnic/btl_usnic_component.c +++ b/opal/mca/btl/usnic/btl_usnic_component.c @@ -38,52 +38,52 @@ #include "opal_config.h" -#include #include #include -#include +#include #include -#include +#include #include -#include #include -#include +#include +#include +#include #include -#include "opal_stdint.h" -#include "opal/prefetch.h" +#include "opal/constants.h" +#include "opal/mca/base/mca_base_var.h" +#include "opal/mca/memchecker/base/base.h" #include "opal/mca/timer/base/base.h" +#include "opal/prefetch.h" #include "opal/util/argv.h" -#include "opal/util/net.h" #include "opal/util/if.h" +#include "opal/util/net.h" #include "opal/util/printf.h" -#include "opal/mca/base/mca_base_var.h" -#include "opal/mca/memchecker/base/base.h" #include "opal/util/show_help.h" -#include "opal/constants.h" +#include "opal_stdint.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "opal/util/proc.h" #include "btl_usnic.h" +#include "btl_usnic_ack.h" #include "btl_usnic_connectivity.h" -#include "btl_usnic_frag.h" #include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" #include "btl_usnic_module.h" -#include "btl_usnic_stats.h" -#include "btl_usnic_util.h" -#include "btl_usnic_ack.h" -#include "btl_usnic_send.h" -#include "btl_usnic_recv.h" #include "btl_usnic_proc.h" +#include "btl_usnic_recv.h" +#include "btl_usnic_send.h" +#include "btl_usnic_stats.h" #include "btl_usnic_test.h" +#include "btl_usnic_util.h" #define OPAL_BTL_USNIC_NUM_COMPLETIONS 500 /* MPI_THREAD_MULTIPLE_SUPPORT */ -opal_recursive_mutex_t btl_usnic_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT; +opal_recursive_mutex_t btl_usnic_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT; /* RNG buffer definition */ opal_rng_buff_t opal_btl_usnic_rand_buff = {{0}}; @@ -102,8 +102,7 @@ static volatile bool dump_bitvectors = false; static int usnic_component_open(void); static int usnic_component_close(void); static mca_btl_base_module_t ** -usnic_component_init(int* num_btl_modules, bool want_progress_threads, - bool want_mpi_threads); +usnic_component_init(int *num_btl_modules, bool want_progress_threads, bool want_mpi_threads); static int usnic_component_progress(void); /* Types for filtering interfaces */ @@ -123,34 +122,29 @@ typedef struct usnic_if_filter_t { filter_elt_t *elts; } usnic_if_filter_t; -static bool filter_module(opal_btl_usnic_module_t *module, - usnic_if_filter_t *filter, +static bool filter_module(opal_btl_usnic_module_t *module, usnic_if_filter_t *filter, bool filter_incl); -static usnic_if_filter_t *parse_ifex_str(const char *orig_str, - const char *name); +static usnic_if_filter_t *parse_ifex_str(const char *orig_str, const char *name); static void free_filter(usnic_if_filter_t *filter); - opal_btl_usnic_component_t mca_btl_usnic_component = { .super = { /* First, the mca_base_component_t struct containing meta information about the component itself */ - .btl_version = { - USNIC_BTL_DEFAULT_VERSION("usnic"), - .mca_open_component = usnic_component_open, - .mca_close_component = usnic_component_close, - .mca_register_component_params = opal_btl_usnic_component_register, - }, - .btl_data = { - /* The component is not checkpoint ready */ - .param_field = MCA_BASE_METADATA_PARAM_NONE - }, + .btl_version = + { + USNIC_BTL_DEFAULT_VERSION("usnic"), + .mca_open_component = usnic_component_open, + .mca_close_component = usnic_component_close, + .mca_register_component_params = opal_btl_usnic_component_register, + }, + .btl_data = + {/* The component is not checkpoint ready */ + .param_field = MCA_BASE_METADATA_PARAM_NONE}, .btl_init = usnic_component_init, .btl_progress = usnic_component_progress, - } -}; - + }}; /* * Called by MCA framework to open the component @@ -169,14 +163,12 @@ static int usnic_component_open(void) /* Sanity check: if_include and if_exclude need to be mutually exclusive */ - if (OPAL_SUCCESS != - mca_base_var_check_exclusive("opal", - mca_btl_usnic_component.super.btl_version.mca_type_name, - mca_btl_usnic_component.super.btl_version.mca_component_name, - "if_include", + if (OPAL_SUCCESS + != mca_base_var_check_exclusive( + "opal", mca_btl_usnic_component.super.btl_version.mca_type_name, + mca_btl_usnic_component.super.btl_version.mca_component_name, "if_include", mca_btl_usnic_component.super.btl_version.mca_type_name, - mca_btl_usnic_component.super.btl_version.mca_component_name, - "if_exclude")) { + mca_btl_usnic_component.super.btl_version.mca_component_name, "if_exclude")) { /* Return ERR_NOT_AVAILABLE so that a warning message about "open" failing is not printed */ return OPAL_ERR_NOT_AVAILABLE; @@ -185,7 +177,6 @@ static int usnic_component_open(void) return OPAL_SUCCESS; } - /* * Component cleanup */ @@ -226,7 +217,6 @@ static int usnic_component_close(void) return OPAL_SUCCESS; } - /* * Register address information. The modex will make this available * to all peers. @@ -236,22 +226,20 @@ static int usnic_modex_send(void) int rc; int i; size_t size; - opal_btl_usnic_modex_t* modexes = NULL; + opal_btl_usnic_modex_t *modexes = NULL; if (0 == mca_btl_usnic_component.num_modules) { return OPAL_SUCCESS; } - size = mca_btl_usnic_component.num_modules * - sizeof(opal_btl_usnic_modex_t); - modexes = (opal_btl_usnic_modex_t*) malloc(size); + size = mca_btl_usnic_component.num_modules * sizeof(opal_btl_usnic_modex_t); + modexes = (opal_btl_usnic_modex_t *) malloc(size); if (NULL == modexes) { return OPAL_ERR_OUT_OF_RESOURCE; } for (i = 0; i < mca_btl_usnic_component.num_modules; i++) { - opal_btl_usnic_module_t* module = - mca_btl_usnic_component.usnic_active_modules[i]; + opal_btl_usnic_module_t *module = mca_btl_usnic_component.usnic_active_modules[i]; modexes[i] = module->local_modex; opal_output_verbose(5, USNIC_OUT, "btl:usnic: " @@ -259,18 +247,15 @@ static int usnic_modex_send(void) "modex_send data port:%d, " "%s", modexes[i].ports[USNIC_PRIORITY_CHANNEL], - modexes[i].ports[USNIC_DATA_CHANNEL], - module->if_ipv4_addr_str); + modexes[i].ports[USNIC_DATA_CHANNEL], module->if_ipv4_addr_str); } - usnic_compat_modex_send(&rc, &mca_btl_usnic_component.super.btl_version, - modexes, size); + usnic_compat_modex_send(&rc, &mca_btl_usnic_component.super.btl_version, modexes, size); free(modexes); return rc; } - /* * See if our memlock limit is >64K. 64K is the RHEL default memlock * limit; this check is a first-line-of-defense hueristic to see if @@ -290,20 +275,17 @@ static int check_reg_mem_basics(void) ret = getrlimit(RLIMIT_MEMLOCK, &limit); if (0 == ret) { - if ((long) limit.rlim_cur > (64 * 1024) || - limit.rlim_cur == RLIM_INFINITY) { + if ((long) limit.rlim_cur > (64 * 1024) || limit.rlim_cur == RLIM_INFINITY) { return OPAL_SUCCESS; } else { - opal_asprintf(&str_limit, "%ld", (long)limit.rlim_cur); + opal_asprintf(&str_limit, "%ld", (long) limit.rlim_cur); } } else { opal_asprintf(&str_limit, "Unknown"); } - opal_show_help("help-mpi-btl-usnic.txt", "check_reg_mem_basics fail", - true, - opal_process_info.nodename, - str_limit); + opal_show_help("help-mpi-btl-usnic.txt", "check_reg_mem_basics fail", true, + opal_process_info.nodename, str_limit); return OPAL_ERR_OUT_OF_RESOURCE; #else @@ -313,12 +295,10 @@ static int check_reg_mem_basics(void) #endif } - /* * Basic sanity checking for usNIC VFs / resources. */ -static int check_usnic_config(opal_btl_usnic_module_t *module, - int num_local_procs) +static int check_usnic_config(opal_btl_usnic_module_t *module, int num_local_procs) { char str[128]; unsigned unlp; @@ -344,40 +324,33 @@ static int check_usnic_config(opal_btl_usnic_module_t *module, (to ensure that each MPI process will be able to get the number of CQs that it needs) */ if (uip->ui.v1.ui_num_vf < unlp) { - snprintf(str, sizeof(str), "Not enough usNICs (found %d, need %d)", - uip->ui.v1.ui_num_vf, unlp); + snprintf(str, sizeof(str), "Not enough usNICs (found %d, need %d)", uip->ui.v1.ui_num_vf, + unlp); goto error; } if (uip->ui.v1.ui_qp_per_vf < USNIC_NUM_CHANNELS) { - snprintf(str, sizeof(str), "Not enough transmit/receive queues per usNIC (found %d, need %d)", - uip->ui.v1.ui_qp_per_vf, - USNIC_NUM_CHANNELS); + snprintf(str, sizeof(str), + "Not enough transmit/receive queues per usNIC (found %d, need %d)", + uip->ui.v1.ui_qp_per_vf, USNIC_NUM_CHANNELS); goto error; } if (uip->ui.v1.ui_cq_per_vf < USNIC_NUM_CHANNELS) { - snprintf(str, sizeof(str), - "Not enough completion queues per usNIC (found %d, need %d)", - uip->ui.v1.ui_cq_per_vf, - USNIC_NUM_CHANNELS); + snprintf(str, sizeof(str), "Not enough completion queues per usNIC (found %d, need %d)", + uip->ui.v1.ui_cq_per_vf, USNIC_NUM_CHANNELS); goto error; } /* All is good! */ return OPAL_SUCCESS; - error: +error: /* Sad panda */ - opal_show_help("help-mpi-btl-usnic.txt", - "not enough usnic resources", - true, - opal_process_info.nodename, - module->linux_device_name, - str); + opal_show_help("help-mpi-btl-usnic.txt", "not enough usnic resources", true, + opal_process_info.nodename, module->linux_device_name, str); return OPAL_ERROR; } - static void usnic_clock_callback(int fd, short flags, void *timeout) { /* Increase by so many ticks that we will definitely force sending @@ -390,7 +363,6 @@ static void usnic_clock_callback(int fd, short flags, void *timeout) opal_event_add(&usnic_clock_timer_event, timeout); } - /* Parse a string which is a comma-separated list containing a mix of * interface names and IPv4 CIDR-format netmasks. * @@ -402,8 +374,7 @@ static void usnic_clock_callback(int fd, short flags, void *timeout) * of filter elements, and any strings in it (can do this via * free_filter()). */ -static usnic_if_filter_t *parse_ifex_str(const char *orig_str, - const char *name) +static usnic_if_filter_t *parse_ifex_str(const char *orig_str, const char *name) { int i, ret; char **argv, *str, *tmp; @@ -450,8 +421,8 @@ static usnic_if_filter_t *parse_ifex_str(const char *orig_str, filter->elts[filter->n_elt].is_netmask = false; filter->elts[filter->n_elt].if_name = strdup(argv[i]); opal_output_verbose(20, USNIC_OUT, - "btl:usnic:parse_ifex_str: parsed %s device name: %s", - name, filter->elts[filter->n_elt].if_name); + "btl:usnic:parse_ifex_str: parsed %s device name: %s", name, + filter->elts[filter->n_elt].if_name); ++filter->n_elt; continue; @@ -463,51 +434,44 @@ static usnic_if_filter_t *parse_ifex_str(const char *orig_str, tmp = strdup(argv[i]); str = strchr(argv[i], '/'); if (NULL == str) { - opal_show_help("help-mpi-btl-usnic.txt", "invalid if_inexclude", - true, name, opal_process_info.nodename, - tmp, "Invalid specification (missing \"/\")"); + opal_show_help("help-mpi-btl-usnic.txt", "invalid if_inexclude", true, name, + opal_process_info.nodename, tmp, + "Invalid specification (missing \"/\")"); free(tmp); continue; } *str = '\0'; argv_prefix = atoi(str + 1); if (argv_prefix < 1 || argv_prefix > 32) { - opal_show_help("help-mpi-btl-usnic.txt", "invalid if_inexclude", - true, name, opal_process_info.nodename, - tmp, "Invalid specification (prefix < 1 or prefix >32)"); + opal_show_help("help-mpi-btl-usnic.txt", "invalid if_inexclude", true, name, + opal_process_info.nodename, tmp, + "Invalid specification (prefix < 1 or prefix >32)"); free(tmp); continue; } /* Now convert the IPv4 address */ - ((struct sockaddr*) &argv_inaddr)->sa_family = AF_INET; - ret = inet_pton(AF_INET, argv[i], - &((struct sockaddr_in*) &argv_inaddr)->sin_addr); + ((struct sockaddr *) &argv_inaddr)->sa_family = AF_INET; + ret = inet_pton(AF_INET, argv[i], &((struct sockaddr_in *) &argv_inaddr)->sin_addr); if (1 != ret) { - opal_show_help("help-mpi-btl-usnic.txt", "invalid if_inexclude", - true, name, opal_process_info.nodename, tmp, + opal_show_help("help-mpi-btl-usnic.txt", "invalid if_inexclude", true, name, + opal_process_info.nodename, tmp, "Invalid specification (inet_pton() failed)"); free(tmp); continue; } opal_output_verbose(20, USNIC_OUT, - "btl:usnic:parse_ifex_str: parsed %s address+prefix: %s / %u", - name, - opal_net_get_hostname((struct sockaddr*) &argv_inaddr), - argv_prefix); + "btl:usnic:parse_ifex_str: parsed %s address+prefix: %s / %u", name, + opal_net_get_hostname((struct sockaddr *) &argv_inaddr), argv_prefix); - memcpy(&addr, - &((struct sockaddr_in*) &argv_inaddr)->sin_addr, - sizeof(addr)); + memcpy(&addr, &((struct sockaddr_in *) &argv_inaddr)->sin_addr, sizeof(addr)); /* be helpful: if the user passed A.B.C.D/24 instead of A.B.C.0/24, * also normalize the netmask */ filter->elts[filter->n_elt].is_netmask = true; filter->elts[filter->n_elt].if_name = NULL; - filter->elts[filter->n_elt].netmask_be = - usnic_cidrlen_to_netmask(argv_prefix); - filter->elts[filter->n_elt].addr_be = addr & - filter->elts[filter->n_elt].netmask_be; + filter->elts[filter->n_elt].netmask_be = usnic_cidrlen_to_netmask(argv_prefix); + filter->elts[filter->n_elt].addr_be = addr & filter->elts[filter->n_elt].netmask_be; ++filter->n_elt; free(tmp); @@ -528,8 +492,7 @@ static usnic_if_filter_t *parse_ifex_str(const char *orig_str, /* * Check this module to see if should be kept or not. */ -static bool filter_module(opal_btl_usnic_module_t *module, - usnic_if_filter_t *filter, +static bool filter_module(opal_btl_usnic_module_t *module, usnic_if_filter_t *filter, bool filter_incl) { int i; @@ -549,13 +512,12 @@ static bool filter_module(opal_btl_usnic_module_t *module, for (i = 0; i < filter->n_elt; ++i) { if (filter->elts[i].is_netmask) { /* conservative: we also require the netmask to match */ - if (filter->elts[i].netmask_be == uip->ui.v1.ui_netmask_be && - filter->elts[i].addr_be == module_mask) { + if (filter->elts[i].netmask_be == uip->ui.v1.ui_netmask_be + && filter->elts[i].addr_be == module_mask) { match = true; break; } - } - else { + } else { if (strcmp(filter->elts[i].if_name, linux_device_name) == 0) { match = true; break; @@ -594,9 +556,8 @@ static void free_filter(usnic_if_filter_t *filter) * (2) post OOB receive for incoming connection attempts * (3) register BTL parameters with the MCA */ -static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, - bool want_progress_threads, - bool want_mpi_threads) +static mca_btl_base_module_t ** +usnic_component_init(int *num_btl_modules, bool want_progress_threads, bool want_mpi_threads) { mca_btl_base_module_t **btls = NULL; int i, j, num_final_modules; @@ -616,15 +577,14 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, /* MPI_THREAD_MULTIPLE is only supported in 2.0+ */ if (want_mpi_threads && !mca_btl_base_thread_multiple_override) { - if (OPAL_MAJOR_VERSION >= 2) { + if (OPAL_MAJOR_VERSION >= 2) { opal_output_verbose(5, USNIC_OUT, "btl:usnic: MPI_THREAD_MULTIPLE support is in testing phase."); - } - else { + } else { opal_output_verbose(5, USNIC_OUT, "btl:usnic: MPI_THREAD_MULTIPLE is not supported in version < 2."); - return NULL; - } + return NULL; + } } OBJ_CONSTRUCT(&btl_usnic_lock, opal_recursive_mutex_t); @@ -687,8 +647,10 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, uint32_t libfabric_api; libfabric_api = fi_version(); if (libfabric_api < FI_VERSION(1, 3)) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: disqualifiying myself because Libfabric does not support v1.3 of the API (v1.3 is *required* for correct usNIC functionality)."); + opal_output_verbose( + 5, USNIC_OUT, + "btl:usnic: disqualifiying myself because Libfabric does not support v1.3 of the API " + "(v1.3 is *required* for correct usNIC functionality)."); return NULL; } @@ -721,8 +683,9 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, ret = fi_getinfo(libfabric_api, NULL, 0, 0, &hints, &info_list); if (0 != ret) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: disqualifiying myself due to fi_getinfo(3) failure: %s (%d)", strerror(-ret), ret); + opal_output_verbose( + 5, USNIC_OUT, "btl:usnic: disqualifiying myself due to fi_getinfo(3) failure: %s (%d)", + strerror(-ret), ret); return NULL; } @@ -732,7 +695,7 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, } if (0 == num_devs) { opal_output_verbose(5, USNIC_OUT, - "btl:usnic: disqualifiying myself due to lack of libfabric providers"); + "btl:usnic: disqualifiying myself due to lack of libfabric providers"); return NULL; } @@ -750,38 +713,35 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, * we fail. ************************************************************************/ - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: usNIC fabrics found"); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: usNIC fabrics found"); opal_proc_t *me = opal_proc_local_get(); opal_process_name_t *name = &(me->proc_name); - mca_btl_usnic_component.my_hashed_rte_name = - usnic_compat_rte_hash_name(name); - MSGDEBUG1_OUT("%s: my_hashed_rte_name=0x%" PRIx64, - __func__, mca_btl_usnic_component.my_hashed_rte_name); + mca_btl_usnic_component.my_hashed_rte_name = usnic_compat_rte_hash_name(name); + MSGDEBUG1_OUT("%s: my_hashed_rte_name=0x%" PRIx64, __func__, + mca_btl_usnic_component.my_hashed_rte_name); opal_srand(&opal_btl_usnic_rand_buff, ((uint32_t) getpid())); /* Setup an array of pointers to point to each module (which we'll return upstream) */ mca_btl_usnic_component.num_modules = num_devs; - btls = (struct mca_btl_base_module_t**) - malloc(mca_btl_usnic_component.num_modules * - sizeof(opal_btl_usnic_module_t*)); + btls = (struct mca_btl_base_module_t **) malloc(mca_btl_usnic_component.num_modules + * sizeof(opal_btl_usnic_module_t *)); if (NULL == btls) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); goto send_modex; } /* Allocate space for btl module instances */ - mca_btl_usnic_component.usnic_all_modules = - calloc(mca_btl_usnic_component.num_modules, - sizeof(*mca_btl_usnic_component.usnic_all_modules)); - mca_btl_usnic_component.usnic_active_modules = - calloc(mca_btl_usnic_component.num_modules, - sizeof(*mca_btl_usnic_component.usnic_active_modules)); - if (NULL == mca_btl_usnic_component.usnic_all_modules || - NULL == mca_btl_usnic_component.usnic_active_modules) { + mca_btl_usnic_component.usnic_all_modules = calloc(mca_btl_usnic_component.num_modules, + sizeof(*mca_btl_usnic_component + .usnic_all_modules)); + mca_btl_usnic_component.usnic_active_modules = calloc(mca_btl_usnic_component.num_modules, + sizeof(*mca_btl_usnic_component + .usnic_active_modules)); + if (NULL == mca_btl_usnic_component.usnic_all_modules + || NULL == mca_btl_usnic_component.usnic_active_modules) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); goto error; } @@ -791,15 +751,13 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, * so don't bother checking that here) */ if (NULL != mca_btl_usnic_component.if_include) { - opal_output_verbose(20, USNIC_OUT, - "btl:usnic:filter_module: if_include=%s", + opal_output_verbose(20, USNIC_OUT, "btl:usnic:filter_module: if_include=%s", mca_btl_usnic_component.if_include); filter_incl = true; filter = parse_ifex_str(mca_btl_usnic_component.if_include, "include"); } else if (NULL != mca_btl_usnic_component.if_exclude) { - opal_output_verbose(20, USNIC_OUT, - "btl:usnic:filter_module: if_exclude=%s", + opal_output_verbose(20, USNIC_OUT, "btl:usnic:filter_module: if_exclude=%s", mca_btl_usnic_component.if_exclude); filter_incl = false; @@ -811,10 +769,10 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, /* Go through the list of devices and determine if we want it or not. Create a module for each one that we want. */ info = info_list; - for (j = i = 0; i < num_devs && - (0 == mca_btl_usnic_component.max_modules || - i < mca_btl_usnic_component.max_modules); - ++i, info = info->next) { + for (j = i = 0; + i < num_devs + && (0 == mca_btl_usnic_component.max_modules || i < mca_btl_usnic_component.max_modules); + ++i, info = info->next) { // The fabric/domain names changed at libfabric API v1.4 (see above). char *linux_device_name; @@ -826,42 +784,29 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, ret = fi_fabric(info->fabric_attr, &fabric, NULL); if (0 != ret) { - opal_show_help("help-mpi-btl-usnic.txt", - "libfabric API failed", - true, - opal_process_info.nodename, - linux_device_name, - "fi_fabric()", __FILE__, __LINE__, - ret, - strerror(-ret)); + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, linux_device_name, "fi_fabric()", __FILE__, + __LINE__, ret, strerror(-ret)); continue; } opal_memchecker_base_mem_defined(&fabric, sizeof(fabric)); ret = fi_domain(fabric, info, &domain, NULL); if (0 != ret) { - opal_show_help("help-mpi-btl-usnic.txt", - "libfabric API failed", - true, - opal_process_info.nodename, - linux_device_name, - "fi_domain()", __FILE__, __LINE__, - ret, - strerror(-ret)); + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, linux_device_name, "fi_domain()", __FILE__, + __LINE__, ret, strerror(-ret)); continue; } opal_memchecker_base_mem_defined(&domain, sizeof(domain)); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: found: usNIC device %s", - linux_device_name); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: found: usNIC device %s", linux_device_name); /* Save a little info on the module that we have already gathered. The rest of the module will be filled in later. */ module = &(mca_btl_usnic_component.usnic_all_modules[j]); - memcpy(module, &opal_btl_usnic_module_template, - sizeof(opal_btl_usnic_module_t)); + memcpy(module, &opal_btl_usnic_module_template, sizeof(opal_btl_usnic_module_t)); module->fabric = fabric; module->domain = domain; module->fabric_info = info; @@ -876,45 +821,38 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, doesn't come in the normal fi_getinfo(). This allows us to do filtering, later. */ ret = fi_open_ops(&fabric->fid, FI_USNIC_FABRIC_OPS_1, 0, - (void **)&module->usnic_fabric_ops, NULL); + (void **) &module->usnic_fabric_ops, NULL); if (ret != 0) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: device %s fabric_open_ops failed %d (%s)", - module->linux_device_name, ret, fi_strerror(-ret)); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: device %s fabric_open_ops failed %d (%s)", + module->linux_device_name, ret, fi_strerror(-ret)); fi_close(&domain->fid); fi_close(&fabric->fid); continue; } - ret = - module->usnic_fabric_ops->getinfo(1, - fabric, - &module->usnic_info); + ret = module->usnic_fabric_ops->getinfo(1, fabric, &module->usnic_info); if (ret != 0) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: device %s usnic_getinfo failed %d (%s)", - module->linux_device_name, ret, fi_strerror(-ret)); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: device %s usnic_getinfo failed %d (%s)", + module->linux_device_name, ret, fi_strerror(-ret)); fi_close(&domain->fid); fi_close(&fabric->fid); continue; } opal_output_verbose(5, USNIC_OUT, - "btl:usnic: device %s usnic_info: link speed=%d, netmask=0x%x, ifname=%s, num_vf=%d, qp/vf=%d, cq/vf=%d", + "btl:usnic: device %s usnic_info: link speed=%d, netmask=0x%x, " + "ifname=%s, num_vf=%d, qp/vf=%d, cq/vf=%d", module->linux_device_name, (unsigned int) module->usnic_info.ui.v1.ui_link_speed, (unsigned int) module->usnic_info.ui.v1.ui_netmask_be, - module->usnic_info.ui.v1.ui_ifname, - module->usnic_info.ui.v1.ui_num_vf, + module->usnic_info.ui.v1.ui_ifname, module->usnic_info.ui.v1.ui_num_vf, module->usnic_info.ui.v1.ui_qp_per_vf, module->usnic_info.ui.v1.ui_cq_per_vf); /* respect if_include/if_exclude subnets/ifaces from the user */ if (filter != NULL) { keep_module = filter_module(module, filter, filter_incl); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s %s due to %s", - (keep_module ? "keeping" : "skipping"), - module->linux_device_name, + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s %s due to %s", + (keep_module ? "keeping" : "skipping"), module->linux_device_name, (filter_incl ? "if_include" : "if_exclude")); if (!keep_module) { fi_close(&domain->fid); @@ -928,11 +866,11 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, probes (these are VIC-wide settings -- they don't change for each module we create, so we only need to check once). */ - if (0 == j && - check_usnic_config(module, num_local_procs) != OPAL_SUCCESS) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: device %s is not provisioned with enough resources -- skipping", - module->linux_device_name); + if (0 == j && check_usnic_config(module, num_local_procs) != OPAL_SUCCESS) { + opal_output_verbose( + 5, USNIC_OUT, + "btl:usnic: device %s is not provisioned with enough resources -- skipping", + module->linux_device_name); fi_close(&domain->fid); fi_close(&fabric->fid); @@ -944,8 +882,7 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, /* Below this point, we know we want this device */ /*************************************************/ - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: device %s looks good!", + opal_output_verbose(5, USNIC_OUT, "btl:usnic: device %s looks good!", module->linux_device_name); /* Let this module advance to the next round! */ @@ -961,11 +898,10 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, /* If we actually have some modules, setup the connectivity checking agent and client. */ - if (mca_btl_usnic_component.num_modules > 0 && - mca_btl_usnic_component.connectivity_enabled) { + if (mca_btl_usnic_component.num_modules > 0 && mca_btl_usnic_component.connectivity_enabled) { mca_btl_usnic_component.opal_evbase = opal_progress_thread_init(NULL); - if (OPAL_SUCCESS != opal_btl_usnic_connectivity_agent_init() || - OPAL_SUCCESS != opal_btl_usnic_connectivity_client_init()) { + if (OPAL_SUCCESS != opal_btl_usnic_connectivity_agent_init() + || OPAL_SUCCESS != opal_btl_usnic_connectivity_client_init()) { opal_progress_thread_finalize(NULL); return NULL; } @@ -974,14 +910,12 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, /* Now that we know how many modules there are, let the modules initialize themselves (it's useful to know how many modules there are before doing this). */ - for (num_final_modules = i = 0; - i < mca_btl_usnic_component.num_modules; ++i) { - module = (opal_btl_usnic_module_t*) btls[i]; + for (num_final_modules = i = 0; i < mca_btl_usnic_component.num_modules; ++i) { + module = (opal_btl_usnic_module_t *) btls[i]; /* Let the module initialize itself */ if (OPAL_SUCCESS != opal_btl_usnic_module_init(module)) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: failed to init module for %s", + opal_output_verbose(5, USNIC_OUT, "btl:usnic: failed to init module for %s", module->if_ipv4_addr_str); continue; } @@ -999,35 +933,20 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, const char *devname = module->linux_device_name; opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s num sqe=%d, num rqe=%d, num cqe=%d, num aveqe=%d", - devname, - module->sd_num, - module->rd_num, - module->cq_num, + devname, module->sd_num, module->rd_num, module->cq_num, module->av_eq_num); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s priority MTU = %" PRIsize_t, - devname, + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s priority MTU = %" PRIsize_t, devname, module->max_tiny_msg_size); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s priority limit = %" PRIsize_t, - devname, + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s priority limit = %" PRIsize_t, devname, module->max_tiny_payload); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s eager limit = %" PRIsize_t, - devname, + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s eager limit = %" PRIsize_t, devname, module->super.btl_eager_limit); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s eager rndv limit = %" PRIsize_t, - devname, + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s eager rndv limit = %" PRIsize_t, devname, module->super.btl_rndv_eager_limit); opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s max send size= %" PRIsize_t - " (not overrideable)", - devname, - module->super.btl_max_send_size); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s exclusivity = %d", - devname, + "btl:usnic: %s max send size= %" PRIsize_t " (not overrideable)", + devname, module->super.btl_max_send_size); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s exclusivity = %d", devname, module->super.btl_exclusivity); } @@ -1044,15 +963,13 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, That being said, if we ended up with zero acceptable devices, then free everything. */ if (0 == num_final_modules) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: returning 0 modules"); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: returning 0 modules"); goto error; } /* we have a nonzero number of modules, so save a copy of the btls array * for later use */ - memcpy(mca_btl_usnic_component.usnic_active_modules, btls, - num_final_modules * sizeof(*btls)); + memcpy(mca_btl_usnic_component.usnic_active_modules, btls, num_final_modules * sizeof(*btls)); /* Loop over the modules and find the minimum value for module->numa_distance. For every module that has a @@ -1061,13 +978,13 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, messages over "near" modules. */ min_distance = 9999999; for (i = 0; i < mca_btl_usnic_component.num_modules; ++i) { - module = (opal_btl_usnic_module_t*) btls[i]; + module = (opal_btl_usnic_module_t *) btls[i]; if (module->numa_distance < min_distance) { min_distance = module->numa_distance; } } for (i = 0; i < mca_btl_usnic_component.num_modules; ++i) { - module = (opal_btl_usnic_module_t*) btls[i]; + module = (opal_btl_usnic_module_t *) btls[i]; if (module->numa_distance > min_distance) { ++module->super.btl_latency; opal_output_verbose(5, USNIC_OUT, @@ -1077,8 +994,7 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, } /* start timer to guarantee synthetic clock advances */ - opal_event_set(opal_sync_event_base, &usnic_clock_timer_event, - -1, 0, usnic_clock_callback, + opal_event_set(opal_sync_event_base, &usnic_clock_timer_event, -1, 0, usnic_clock_callback, &usnic_clock_timeout); usnic_clock_timer_event_set = true; @@ -1092,14 +1008,13 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, /* All done */ *num_btl_modules = mca_btl_usnic_component.num_modules; - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: returning %d modules", *num_btl_modules); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: returning %d modules", *num_btl_modules); - send_modex: +send_modex: usnic_modex_send(); return btls; - error: +error: /* clean up as much allocated memory as possible */ free(btls); btls = NULL; @@ -1127,18 +1042,19 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules, * immediately after one packet to avoid starvation, "fastpath_ok" is * used for this. */ -static int usnic_handle_completion(opal_btl_usnic_module_t* module, - opal_btl_usnic_channel_t *channel, struct fi_cq_entry *completion); +static int usnic_handle_completion(opal_btl_usnic_module_t *module, + opal_btl_usnic_channel_t *channel, + struct fi_cq_entry *completion); static int usnic_component_progress_2(bool check_priority); -static void usnic_handle_cq_error(opal_btl_usnic_module_t* module, - opal_btl_usnic_channel_t *channel, int cq_ret); +static void usnic_handle_cq_error(opal_btl_usnic_module_t *module, + opal_btl_usnic_channel_t *channel, int cq_ret); static int usnic_component_progress(void) { int i; int count; - opal_btl_usnic_recv_segment_t* rseg; - opal_btl_usnic_module_t* module; + opal_btl_usnic_recv_segment_t *rseg; + opal_btl_usnic_module_t *module; struct fi_cq_entry completion; opal_btl_usnic_channel_t *channel; static bool fastpath_ok = true; @@ -1155,19 +1071,16 @@ static int usnic_component_progress(void) int ret = fi_cq_read(channel->cq, &completion, 1); assert(0 != ret); if (OPAL_LIKELY(1 == ret)) { - opal_memchecker_base_mem_defined(&completion, - sizeof(completion)); - rseg = (opal_btl_usnic_recv_segment_t*) completion.op_context; - if (OPAL_LIKELY(OPAL_BTL_USNIC_SEG_RECV == - rseg->rs_base.us_type)) { + opal_memchecker_base_mem_defined(&completion, sizeof(completion)); + rseg = (opal_btl_usnic_recv_segment_t *) completion.op_context; + if (OPAL_LIKELY(OPAL_BTL_USNIC_SEG_RECV == rseg->rs_base.us_type)) { opal_btl_usnic_recv_fast(module, rseg, channel); ++module->stats.num_seg_total_completions; ++module->stats.num_seg_recv_completions; - fastpath_ok = false; /* prevent starvation */ + fastpath_ok = false; /* prevent starvation */ return 1; } else { - count += usnic_handle_completion(module, channel, - &completion); + count += usnic_handle_completion(module, channel, &completion); } } else if (OPAL_LIKELY(-FI_EAGAIN == ret)) { continue; @@ -1182,16 +1095,15 @@ static int usnic_component_progress(void) return count + usnic_component_progress_2(check_priority); } -static int usnic_handle_completion( - opal_btl_usnic_module_t* module, - opal_btl_usnic_channel_t *channel, - struct fi_cq_entry *completion) +static int usnic_handle_completion(opal_btl_usnic_module_t *module, + opal_btl_usnic_channel_t *channel, + struct fi_cq_entry *completion) { - opal_btl_usnic_segment_t* seg; - opal_btl_usnic_recv_segment_t* rseg; + opal_btl_usnic_segment_t *seg; + opal_btl_usnic_recv_segment_t *rseg; - seg = (opal_btl_usnic_segment_t*)completion->op_context; - rseg = (opal_btl_usnic_recv_segment_t*)seg; + seg = (opal_btl_usnic_segment_t *) completion->op_context; + rseg = (opal_btl_usnic_recv_segment_t *) seg; ++module->stats.num_seg_total_completions; @@ -1201,29 +1113,26 @@ static int usnic_handle_completion( OPAL_THREAD_LOCK(&btl_usnic_lock); /* Handle work completions */ - switch(seg->us_type) { + switch (seg->us_type) { /**** Send ACK completions ****/ case OPAL_BTL_USNIC_SEG_ACK: ++module->stats.num_seg_ack_completions; - opal_btl_usnic_ack_complete(module, - (opal_btl_usnic_ack_segment_t *)seg); + opal_btl_usnic_ack_complete(module, (opal_btl_usnic_ack_segment_t *) seg); break; /**** Send of frag segment completion (i.e., the MPI message's one-and-only segment has completed sending) ****/ case OPAL_BTL_USNIC_SEG_FRAG: ++module->stats.num_seg_frag_completions; - opal_btl_usnic_frag_send_complete(module, - (opal_btl_usnic_frag_segment_t*)seg); + opal_btl_usnic_frag_send_complete(module, (opal_btl_usnic_frag_segment_t *) seg); break; /**** Send of chunk segment completion (i.e., part of a large MPI message is done sending) ****/ case OPAL_BTL_USNIC_SEG_CHUNK: ++module->stats.num_seg_chunk_completions; - opal_btl_usnic_chunk_send_complete(module, - (opal_btl_usnic_chunk_segment_t*)seg); + opal_btl_usnic_chunk_send_complete(module, (opal_btl_usnic_chunk_segment_t *) seg); break; /**** Receive completions ****/ @@ -1241,18 +1150,16 @@ static int usnic_handle_completion( return 1; } -static void -usnic_handle_cq_error(opal_btl_usnic_module_t* module, - opal_btl_usnic_channel_t *channel, int cq_ret) +static void usnic_handle_cq_error(opal_btl_usnic_module_t *module, + opal_btl_usnic_channel_t *channel, int cq_ret) { int rc; struct fi_cq_err_entry err_entry; - opal_btl_usnic_recv_segment_t* rseg; + opal_btl_usnic_recv_segment_t *rseg; if (cq_ret != -FI_EAVAIL) { - BTL_ERROR(("%s: cq_read ret = %d (%s)", - module->linux_device_name, cq_ret, - fi_strerror(-cq_ret))); + BTL_ERROR( + ("%s: cq_read ret = %d (%s)", module->linux_device_name, cq_ret, fi_strerror(-cq_ret))); channel->chan_error = true; } @@ -1260,23 +1167,18 @@ usnic_handle_cq_error(opal_btl_usnic_module_t* module, if (rc == -FI_EAGAIN) { return; } else if (rc != 1) { - BTL_ERROR(("%s: cq_readerr ret = %d (expected 1)", - module->linux_device_name, rc)); + BTL_ERROR(("%s: cq_readerr ret = %d (expected 1)", module->linux_device_name, rc)); channel->chan_error = true; } /* Silently count CRC errors. Truncation errors are usually a different symptom of a CRC error. */ - else if (FI_ECRC == err_entry.prov_errno || - FI_ETRUNC == err_entry.prov_errno) { + else if (FI_ECRC == err_entry.prov_errno || FI_ETRUNC == err_entry.prov_errno) { #if MSGDEBUG1 static int once = 0; if (once++ == 0) { - BTL_ERROR(("%s: Channel %d, %s", - module->linux_device_name, - channel->chan_index, - FI_ECRC == err_entry.prov_errno ? - "CRC error" : "message truncation")); + BTL_ERROR(("%s: Channel %d, %s", module->linux_device_name, channel->chan_index, + FI_ECRC == err_entry.prov_errno ? "CRC error" : "message truncation")); } #endif @@ -1293,8 +1195,7 @@ usnic_handle_cq_error(opal_btl_usnic_module_t* module, channel->repost_recv_head = rseg; } } else { - BTL_ERROR(("%s: CQ[%d] prov_err = %d", - module->linux_device_name, channel->chan_index, + BTL_ERROR(("%s: CQ[%d] prov_err = %d", module->linux_device_name, channel->chan_index, err_entry.prov_errno)); channel->chan_error = true; } @@ -1303,7 +1204,7 @@ usnic_handle_cq_error(opal_btl_usnic_module_t* module, static int usnic_component_progress_2(bool check_priority) { int i, j, count = 0, num_events, ret; - opal_btl_usnic_module_t* module; + opal_btl_usnic_module_t *module; static struct fi_cq_entry completions[OPAL_BTL_USNIC_NUM_COMPLETIONS]; opal_btl_usnic_channel_t *channel; int rc; @@ -1320,18 +1221,16 @@ static int usnic_component_progress_2(bool check_priority) module = mca_btl_usnic_component.usnic_active_modules[i]; /* poll each channel */ - for (c=c_start; cmod_channels[c]; if (channel->chan_deferred_recv != NULL) { - (void) opal_btl_usnic_recv_frag_bookkeeping(module, - channel->chan_deferred_recv, channel); + (void) opal_btl_usnic_recv_frag_bookkeeping(module, channel->chan_deferred_recv, + channel); channel->chan_deferred_recv = NULL; } - num_events = ret = - fi_cq_read(channel->cq, completions, - OPAL_BTL_USNIC_NUM_COMPLETIONS); + num_events = ret = fi_cq_read(channel->cq, completions, OPAL_BTL_USNIC_NUM_COMPLETIONS); assert(0 != ret); opal_memchecker_base_mem_defined(&ret, sizeof(ret)); if (OPAL_UNLIKELY(ret < 0 && -FI_EAGAIN != ret)) { @@ -1341,13 +1240,10 @@ static int usnic_component_progress_2(bool check_priority) num_events = 0; } - opal_memchecker_base_mem_defined(completions, - sizeof(completions[0]) * - num_events); + opal_memchecker_base_mem_defined(completions, sizeof(completions[0]) * num_events); /* Handle each event */ for (j = 0; j < num_events; j++) { - count += usnic_handle_completion(module, channel, - &completions[j]); + count += usnic_handle_completion(module, channel, &completions[j]); } /* return error if detected - this may be slightly deferred @@ -1389,71 +1285,69 @@ static void dump_endpoint(opal_btl_usnic_endpoint_t *endpoint) ia.s_addr = endpoint->endpoint_remote_modex.ipv4_addr; inet_ntop(AF_INET, &ia, ep_addr_str, sizeof(ep_addr_str)); - opal_output(0, " endpoint %p, %s job=%u, rank=%u rts=%s s_credits=%"PRIi32"\n", - (void *)endpoint, ep_addr_str, - endpoint->endpoint_proc->proc_opal->proc_name.jobid, + opal_output(0, " endpoint %p, %s job=%u, rank=%u rts=%s s_credits=%" PRIi32 "\n", + (void *) endpoint, ep_addr_str, endpoint->endpoint_proc->proc_opal->proc_name.jobid, endpoint->endpoint_proc->proc_opal->proc_name.vpid, (endpoint->endpoint_ready_to_send ? "true" : "false"), endpoint->endpoint_send_credits); opal_output(0, " endpoint->frag_send_queue:\n"); - OPAL_LIST_FOREACH(frag, &endpoint->endpoint_frag_send_queue, - opal_btl_usnic_frag_t) { + OPAL_LIST_FOREACH (frag, &endpoint->endpoint_frag_send_queue, opal_btl_usnic_frag_t) { opal_btl_usnic_small_send_frag_t *ssfrag; opal_btl_usnic_large_send_frag_t *lsfrag; - snprintf(str, sizeof(str), " --> frag %p, %s", (void *)frag, + snprintf(str, sizeof(str), " --> frag %p, %s", (void *) frag, usnic_frag_type(frag->uf_type)); switch (frag->uf_type) { - case OPAL_BTL_USNIC_FRAG_LARGE_SEND: - lsfrag = (opal_btl_usnic_large_send_frag_t *)frag; - snprintf(tmp, sizeof(tmp), " tag=%"PRIu8" id=%"PRIu32" offset=%llu/%llu post_cnt=%"PRIu32" ack_bytes_left=%llu\n", - lsfrag->lsf_tag, - lsfrag->lsf_frag_id, - (unsigned long long)lsfrag->lsf_cur_offset, - (unsigned long long)lsfrag->lsf_base.sf_size, - lsfrag->lsf_base.sf_seg_post_cnt, - (unsigned long long)lsfrag->lsf_base.sf_ack_bytes_left); - strncat(str, tmp, sizeof(str) - strlen(str) - 1); - opal_output(0, "%s", str); - - OPAL_LIST_FOREACH(sseg, &lsfrag->lsf_seg_chain, - opal_btl_usnic_send_segment_t) { - /* chunk segs are just typedefs to send segs */ - opal_output(0, " chunk seg %p, chan=%s hotel=%d times_posted=%"PRIu32" pending=%s\n", - (void *)sseg, - (USNIC_PRIORITY_CHANNEL == sseg->ss_channel ? - "prio" : "data"), - sseg->ss_hotel_room, - sseg->ss_send_posted, - (sseg->ss_ack_pending ? "true" : "false")); - } + case OPAL_BTL_USNIC_FRAG_LARGE_SEND: + lsfrag = (opal_btl_usnic_large_send_frag_t *) frag; + snprintf(tmp, sizeof(tmp), + " tag=%" PRIu8 " id=%" PRIu32 " offset=%llu/%llu post_cnt=%" PRIu32 + " ack_bytes_left=%llu\n", + lsfrag->lsf_tag, lsfrag->lsf_frag_id, + (unsigned long long) lsfrag->lsf_cur_offset, + (unsigned long long) lsfrag->lsf_base.sf_size, + lsfrag->lsf_base.sf_seg_post_cnt, + (unsigned long long) lsfrag->lsf_base.sf_ack_bytes_left); + strncat(str, tmp, sizeof(str) - strlen(str) - 1); + opal_output(0, "%s", str); + + OPAL_LIST_FOREACH (sseg, &lsfrag->lsf_seg_chain, opal_btl_usnic_send_segment_t) { + /* chunk segs are just typedefs to send segs */ + opal_output(0, + " chunk seg %p, chan=%s hotel=%d times_posted=%" PRIu32 + " pending=%s\n", + (void *) sseg, + (USNIC_PRIORITY_CHANNEL == sseg->ss_channel ? "prio" : "data"), + sseg->ss_hotel_room, sseg->ss_send_posted, + (sseg->ss_ack_pending ? "true" : "false")); + } break; - case OPAL_BTL_USNIC_FRAG_SMALL_SEND: - ssfrag = (opal_btl_usnic_small_send_frag_t *)frag; - snprintf(tmp, sizeof(tmp), " sf_size=%llu post_cnt=%"PRIu32" ack_bytes_left=%llu\n", - (unsigned long long)ssfrag->ssf_base.sf_size, - ssfrag->ssf_base.sf_seg_post_cnt, - (unsigned long long)ssfrag->ssf_base.sf_ack_bytes_left); - strncat(str, tmp, sizeof(str) - strlen(str) - 1); - opal_output(0, "%s", str); - - sseg = &ssfrag->ssf_segment; - opal_output(0, " small seg %p, chan=%s hotel=%d times_posted=%"PRIu32" pending=%s\n", - (void *)sseg, - (USNIC_PRIORITY_CHANNEL == sseg->ss_channel ? - "prio" : "data"), - sseg->ss_hotel_room, - sseg->ss_send_posted, - (sseg->ss_ack_pending ? "true" : "false")); + case OPAL_BTL_USNIC_FRAG_SMALL_SEND: + ssfrag = (opal_btl_usnic_small_send_frag_t *) frag; + snprintf(tmp, sizeof(tmp), " sf_size=%llu post_cnt=%" PRIu32 " ack_bytes_left=%llu\n", + (unsigned long long) ssfrag->ssf_base.sf_size, + ssfrag->ssf_base.sf_seg_post_cnt, + (unsigned long long) ssfrag->ssf_base.sf_ack_bytes_left); + strncat(str, tmp, sizeof(str) - strlen(str) - 1); + opal_output(0, "%s", str); + + sseg = &ssfrag->ssf_segment; + opal_output(0, + " small seg %p, chan=%s hotel=%d times_posted=%" PRIu32 + " pending=%s\n", + (void *) sseg, + (USNIC_PRIORITY_CHANNEL == sseg->ss_channel ? "prio" : "data"), + sseg->ss_hotel_room, sseg->ss_send_posted, + (sseg->ss_ack_pending ? "true" : "false")); break; - case OPAL_BTL_USNIC_FRAG_PUT_DEST: - /* put_dest frags are just a typedef to generic frags */ - snprintf(tmp, sizeof(tmp), " put_addr=%p\n", frag->uf_remote_seg[0].seg_addr.pval); - strncat(str, tmp, sizeof(str) - strlen(str) - 1); - opal_output(0, "%s", str); + case OPAL_BTL_USNIC_FRAG_PUT_DEST: + /* put_dest frags are just a typedef to generic frags */ + snprintf(tmp, sizeof(tmp), " put_addr=%p\n", frag->uf_remote_seg[0].seg_addr.pval); + strncat(str, tmp, sizeof(str) - strlen(str) - 1); + opal_output(0, "%s", str); break; } } @@ -1463,33 +1357,30 @@ static void dump_endpoint(opal_btl_usnic_endpoint_t *endpoint) * eventually this should be done through some sort of debug or iteration * interface in the hotel code. */ opal_output(0, " endpoint->endpoint_sent_segs (%p):\n", - (void *)endpoint->endpoint_sent_segs); + (void *) endpoint->endpoint_sent_segs); for (i = 0; i < WINDOW_SIZE; ++i) { sseg = endpoint->endpoint_sent_segs[i]; if (NULL != sseg) { - opal_output(0, " [%d] sseg=%p %s chan=%s hotel=%d times_posted=%"PRIu32" pending=%s\n", - i, - (void *)sseg, - usnic_seg_type_str(sseg->ss_base.us_type), - (USNIC_PRIORITY_CHANNEL == sseg->ss_channel ? - "prio" : "data"), - sseg->ss_hotel_room, - sseg->ss_send_posted, - (sseg->ss_ack_pending ? "true" : "false")); + opal_output(0, + " [%d] sseg=%p %s chan=%s hotel=%d times_posted=%" PRIu32 + " pending=%s\n", + i, (void *) sseg, usnic_seg_type_str(sseg->ss_base.us_type), + (USNIC_PRIORITY_CHANNEL == sseg->ss_channel ? "prio" : "data"), + sseg->ss_hotel_room, sseg->ss_send_posted, + (sseg->ss_ack_pending ? "true" : "false")); } } - opal_output(0, " ack_needed=%s n_t=%"UDSEQ" n_a=%"UDSEQ" n_r=%"UDSEQ" n_s=%"UDSEQ" rfstart=%"PRIu32"\n", - (endpoint->endpoint_ack_needed?"true":"false"), - endpoint->endpoint_next_seq_to_send, - endpoint->endpoint_ack_seq_rcvd, - endpoint->endpoint_next_contig_seq_to_recv, - endpoint->endpoint_highest_seq_rcvd, + opal_output(0, + " ack_needed=%s n_t=%" UDSEQ " n_a=%" UDSEQ " n_r=%" UDSEQ " n_s=%" UDSEQ + " rfstart=%" PRIu32 "\n", + (endpoint->endpoint_ack_needed ? "true" : "false"), + endpoint->endpoint_next_seq_to_send, endpoint->endpoint_ack_seq_rcvd, + endpoint->endpoint_next_contig_seq_to_recv, endpoint->endpoint_highest_seq_rcvd, endpoint->endpoint_rfstart); if (dump_bitvectors) { - opal_btl_usnic_snprintf_bool_array(str, sizeof(str), - endpoint->endpoint_rcvd_segs, + opal_btl_usnic_snprintf_bool_array(str, sizeof(str), endpoint->endpoint_rcvd_segs, WINDOW_SIZE); opal_output(0, " rcvd_segs 0x%s", str); } @@ -1506,24 +1397,22 @@ void opal_btl_usnic_component_debug(void) opal_output(0, "*** dumping usnic state for MPI_COMM_WORLD rank %u ***\n", proc->proc_name.vpid); - for (i = 0; i < (int)mca_btl_usnic_component.num_modules; ++i) { + for (i = 0; i < (int) mca_btl_usnic_component.num_modules; ++i) { module = mca_btl_usnic_component.usnic_active_modules[i]; - opal_output(0, "active_modules[%d]=%p %s max{frag,chunk,tiny}=%llu,%llu,%llu\n", - i, (void *)module, module->linux_device_name, - (unsigned long long)module->max_frag_payload, - (unsigned long long)module->max_chunk_payload, - (unsigned long long)module->max_tiny_payload); + opal_output(0, "active_modules[%d]=%p %s max{frag,chunk,tiny}=%llu,%llu,%llu\n", i, + (void *) module, module->linux_device_name, + (unsigned long long) module->max_frag_payload, + (unsigned long long) module->max_chunk_payload, + (unsigned long long) module->max_tiny_payload); opal_output(0, " endpoints_with_sends:\n"); - OPAL_LIST_FOREACH(endpoint, &module->endpoints_with_sends, - opal_btl_usnic_endpoint_t) { + OPAL_LIST_FOREACH (endpoint, &module->endpoints_with_sends, opal_btl_usnic_endpoint_t) { dump_endpoint(endpoint); } opal_output(0, " endpoints_that_need_acks:\n"); - OPAL_LIST_FOREACH(endpoint, &module->endpoints_that_need_acks, - opal_btl_usnic_endpoint_t) { + OPAL_LIST_FOREACH (endpoint, &module->endpoints_that_need_acks, opal_btl_usnic_endpoint_t) { dump_endpoint(endpoint); } @@ -1532,17 +1421,15 @@ void opal_btl_usnic_component_debug(void) opal_mutex_lock(&module->all_endpoints_lock); item = opal_list_get_first(&module->all_endpoints); while (item != opal_list_get_end(&module->all_endpoints)) { - endpoint = container_of(item, mca_btl_base_endpoint_t, - endpoint_endpoint_li); + endpoint = container_of(item, mca_btl_base_endpoint_t, endpoint_endpoint_li); item = opal_list_get_next(item); dump_endpoint(endpoint); } opal_mutex_unlock(&module->all_endpoints_lock); opal_output(0, " pending_resend_segs:\n"); - OPAL_LIST_FOREACH(sseg, &module->pending_resend_segs, - opal_btl_usnic_send_segment_t) { - opal_output(0, " sseg %p\n", (void *)sseg); + OPAL_LIST_FOREACH (sseg, &module->pending_resend_segs, opal_btl_usnic_send_segment_t) { + opal_output(0, " sseg %p\n", (void *) sseg); } opal_btl_usnic_print_stats(module, " manual", /*reset=*/false); diff --git a/opal/mca/btl/usnic/btl_usnic_connectivity.h b/opal/mca/btl/usnic/btl_usnic_connectivity.h index 7bde19f81fd..a2678030e94 100644 --- a/opal/mca/btl/usnic/btl_usnic_connectivity.h +++ b/opal/mca/btl/usnic/btl_usnic_connectivity.h @@ -22,7 +22,6 @@ #include "btl_usnic_proc.h" #include "btl_usnic_util.h" - /** * Agent-based service to verify UDP connectivity between two peers. * @@ -104,7 +103,7 @@ enum { }; #define CONNECTIVITY_NODENAME_LEN 128 -#define CONNECTIVITY_IFNAME_LEN 32 +#define CONNECTIVITY_IFNAME_LEN 32 /* * Unix domain socket name @@ -217,10 +216,8 @@ int opal_btl_usnic_connectivity_listen(struct opal_btl_usnic_module_t *module); * It is safe to call this function even if the connectivity check is * disabled; it will be a no-op in this case. */ -int opal_btl_usnic_connectivity_ping(uint32_t src_ipv4_addr, int src_port, - uint32_t dest_ipv4_addr, - uint32_t dest_netmask, int dest_port, - char *dest_nodename, +int opal_btl_usnic_connectivity_ping(uint32_t src_ipv4_addr, int src_port, uint32_t dest_ipv4_addr, + uint32_t dest_netmask, int dest_port, char *dest_nodename, size_t max_msg_size); /** @@ -268,25 +265,22 @@ int opal_btl_usnic_connectivity_agent_init(void); */ int opal_btl_usnic_connectivity_agent_finalize(void); - /** * Helper function invoked in the BTL that will invoke a ping, if the * ping hasn't already been invoked. */ -static inline void -opal_btl_usnic_check_connectivity(opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint) +static inline void opal_btl_usnic_check_connectivity(opal_btl_usnic_module_t *module, + opal_btl_usnic_endpoint_t *endpoint) { - if (OPAL_LIKELY(mca_btl_usnic_component.connectivity_enabled) && - OPAL_UNLIKELY(!endpoint->endpoint_connectivity_checked)) { + if (OPAL_LIKELY(mca_btl_usnic_component.connectivity_enabled) + && OPAL_UNLIKELY(!endpoint->endpoint_connectivity_checked)) { char *host = opal_get_proc_hostname(endpoint->endpoint_proc->proc_opal); opal_btl_usnic_connectivity_ping(module->local_modex.ipv4_addr, module->local_modex.connectivity_udp_port, endpoint->endpoint_remote_modex.ipv4_addr, endpoint->endpoint_remote_modex.netmask, endpoint->endpoint_remote_modex.connectivity_udp_port, - host, - endpoint->endpoint_remote_modex.max_msg_size); + host, endpoint->endpoint_remote_modex.max_msg_size); free(host); endpoint->endpoint_connectivity_checked = true; } diff --git a/opal/mca/btl/usnic/btl_usnic_endpoint.c b/opal/mca/btl/usnic/btl_usnic_endpoint.c index 40a1faee1bb..65317f8006b 100644 --- a/opal/mca/btl/usnic/btl_usnic_endpoint.c +++ b/opal/mca/btl/usnic/btl_usnic_endpoint.c @@ -24,8 +24,8 @@ #include "opal_config.h" -#include #include +#include #include #include #include @@ -34,18 +34,18 @@ #include "opal/types.h" #include "btl_usnic.h" +#include "btl_usnic_ack.h" #include "btl_usnic_endpoint.h" -#include "btl_usnic_module.h" #include "btl_usnic_frag.h" +#include "btl_usnic_module.h" #include "btl_usnic_proc.h" -#include "btl_usnic_util.h" -#include "btl_usnic_ack.h" #include "btl_usnic_send.h" +#include "btl_usnic_util.h" /* * Construct/destruct an endpoint structure. */ -static void endpoint_construct(mca_btl_base_endpoint_t* endpoint) +static void endpoint_construct(mca_btl_base_endpoint_t *endpoint) { int i; @@ -74,10 +74,8 @@ static void endpoint_construct(mca_btl_base_endpoint_t* endpoint) endpoint->endpoint_ack_needed = false; /* clear sent/received sequence number array */ - memset(endpoint->endpoint_sent_segs, 0, - sizeof(endpoint->endpoint_sent_segs)); - memset(endpoint->endpoint_rcvd_segs, 0, - sizeof(endpoint->endpoint_rcvd_segs)); + memset(endpoint->endpoint_sent_segs, 0, sizeof(endpoint->endpoint_sent_segs)); + memset(endpoint->endpoint_rcvd_segs, 0, sizeof(endpoint->endpoint_rcvd_segs)); /* * Make a new OPAL hotel for this module @@ -85,12 +83,8 @@ static void endpoint_construct(mca_btl_base_endpoint_t* endpoint) * due to timeout */ OBJ_CONSTRUCT(&endpoint->endpoint_hotel, opal_hotel_t); - opal_hotel_init(&endpoint->endpoint_hotel, - WINDOW_SIZE, - opal_sync_event_base, - mca_btl_usnic_component.retrans_timeout, - 0, - opal_btl_usnic_ack_timeout); + opal_hotel_init(&endpoint->endpoint_hotel, WINDOW_SIZE, opal_sync_event_base, + mca_btl_usnic_component.retrans_timeout, 0, opal_btl_usnic_ack_timeout); /* Setup this endpoint's list links */ OBJ_CONSTRUCT(&(endpoint->endpoint_ack_li), opal_list_item_t); @@ -98,8 +92,8 @@ static void endpoint_construct(mca_btl_base_endpoint_t* endpoint) endpoint->endpoint_ack_needed = false; /* fragment reassembly info */ - endpoint->endpoint_rx_frag_info = - calloc(sizeof(struct opal_btl_usnic_rx_frag_info_t), MAX_ACTIVE_FRAGS); + endpoint->endpoint_rx_frag_info = calloc(sizeof(struct opal_btl_usnic_rx_frag_info_t), + MAX_ACTIVE_FRAGS); assert(NULL != endpoint->endpoint_rx_frag_info); if (OPAL_UNLIKELY(endpoint->endpoint_rx_frag_info == NULL)) { BTL_ERROR(("calloc returned NULL -- this should not happen!")); @@ -108,7 +102,7 @@ static void endpoint_construct(mca_btl_base_endpoint_t* endpoint) } } -static void endpoint_destruct(mca_btl_base_endpoint_t* endpoint) +static void endpoint_destruct(mca_btl_base_endpoint_t *endpoint) { opal_btl_usnic_proc_t *proc; @@ -121,8 +115,7 @@ static void endpoint_destruct(mca_btl_base_endpoint_t* endpoint) opal_btl_usnic_module_t *module = endpoint->endpoint_module; opal_mutex_lock(&module->all_endpoints_lock); if (endpoint->endpoint_on_all_endpoints) { - opal_list_remove_item(&module->all_endpoints, - &endpoint->endpoint_endpoint_li); + opal_list_remove_item(&module->all_endpoints, &endpoint->endpoint_endpoint_li); endpoint->endpoint_on_all_endpoints = false; } opal_mutex_unlock(&module->all_endpoints_lock); @@ -144,25 +137,21 @@ static void endpoint_destruct(mca_btl_base_endpoint_t* endpoint) free(endpoint->endpoint_rx_frag_info); } -OBJ_CLASS_INSTANCE(opal_btl_usnic_endpoint_t, - opal_list_item_t, - endpoint_construct, +OBJ_CLASS_INSTANCE(opal_btl_usnic_endpoint_t, opal_list_item_t, endpoint_construct, endpoint_destruct); /* * Forcibly drain all pending output on an endpoint, without waiting for * actual completion. */ -void -opal_btl_usnic_flush_endpoint( - opal_btl_usnic_endpoint_t *endpoint) +void opal_btl_usnic_flush_endpoint(opal_btl_usnic_endpoint_t *endpoint) { opal_btl_usnic_send_frag_t *frag; /* First, free all pending fragments */ while (!opal_list_is_empty(&endpoint->endpoint_frag_send_queue)) { - frag = (opal_btl_usnic_send_frag_t *)opal_list_remove_first( - &endpoint->endpoint_frag_send_queue); + frag = (opal_btl_usnic_send_frag_t *) opal_list_remove_first( + &endpoint->endpoint_frag_send_queue); /* _cond still needs to check ownership, but make sure the * fragment is marked as done. @@ -173,5 +162,5 @@ opal_btl_usnic_flush_endpoint( } /* Now, ACK everything that is pending */ - opal_btl_usnic_handle_ack(endpoint, endpoint->endpoint_next_seq_to_send-1); + opal_btl_usnic_handle_ack(endpoint, endpoint->endpoint_next_seq_to_send - 1); } diff --git a/opal/mca/btl/usnic/btl_usnic_endpoint.h b/opal/mca/btl/usnic/btl_usnic_endpoint.h index ff66550a66f..e3575007a1e 100644 --- a/opal/mca/btl/usnic/btl_usnic_endpoint.h +++ b/opal/mca/btl/usnic/btl_usnic_endpoint.h @@ -26,8 +26,8 @@ #include -#include "opal/class/opal_list.h" #include "opal/class/opal_hotel.h" +#include "opal/class/opal_list.h" #include "opal/util/event.h" #include "btl_usnic.h" @@ -44,18 +44,16 @@ struct opal_btl_usnic_send_segment_t; * Have the window size as a compile-time constant that is a power of * two so that we can take advantage of fast bit operations. */ -#define WINDOW_SIZE 4096 +#define WINDOW_SIZE 4096 #define WINDOW_SIZE_MOD(a) (((a) & (WINDOW_SIZE - 1))) -#define WINDOW_OPEN(E) (SEQ_LT((E)->endpoint_next_seq_to_send, \ - ((E)->endpoint_ack_seq_rcvd + WINDOW_SIZE))) -#define WINDOW_EMPTY(E) ((E)->endpoint_ack_seq_rcvd == \ - ((E)->endpoint_next_seq_to_send-1)) +#define WINDOW_OPEN(E) \ + (SEQ_LT((E)->endpoint_next_seq_to_send, ((E)->endpoint_ack_seq_rcvd + WINDOW_SIZE))) +#define WINDOW_EMPTY(E) ((E)->endpoint_ack_seq_rcvd == ((E)->endpoint_next_seq_to_send - 1)) /* * Returns true when an endpoint has nothing left to send */ -#define ENDPOINT_DRAINED(E) (WINDOW_EMPTY(E) && \ - opal_list_is_empty(&(E)->endpoint_frag_send_queue)) +#define ENDPOINT_DRAINED(E) (WINDOW_EMPTY(E) && opal_list_is_empty(&(E)->endpoint_frag_send_queue)) /* * Channel IDs @@ -99,14 +97,14 @@ struct opal_btl_usnic_proc_t; * and waiting for retrans is just fine in this hypothetical hyper-pathological * case, which is what we'll do. */ -#define MAX_ACTIVE_FRAGS (WINDOW_SIZE/2) +#define MAX_ACTIVE_FRAGS (WINDOW_SIZE / 2) typedef struct opal_btl_usnic_rx_frag_info_t { - uint32_t rfi_frag_id; /* ID for this fragment */ - uint32_t rfi_frag_size; /* bytes in this fragment */ - uint32_t rfi_bytes_left; /* bytes remaining to RX in fragment */ - bool rfi_data_in_pool; /* data in data_pool if true, else malloced */ - int rfi_data_pool; /* if <0, data malloced, else rx buf pool */ - char *rfi_data; /* pointer to assembly area */ + uint32_t rfi_frag_id; /* ID for this fragment */ + uint32_t rfi_frag_size; /* bytes in this fragment */ + uint32_t rfi_bytes_left; /* bytes remaining to RX in fragment */ + bool rfi_data_in_pool; /* data in data_pool if true, else malloced */ + int rfi_data_pool; /* if <0, data malloced, else rx buf pool */ + char *rfi_data; /* pointer to assembly area */ opal_free_list_item_t *rfi_fl_elt; /* free list elemement from buf pool when rfi_data_pool is nonzero */ } opal_btl_usnic_rx_frag_info_t; @@ -126,7 +124,7 @@ typedef struct mca_btl_base_endpoint_t { /** proc that owns this endpoint */ struct opal_btl_usnic_proc_t *endpoint_proc; - int endpoint_proc_index; /* index in owning proc's endpoint array */ + int endpoint_proc_index; /* index in owning proc's endpoint array */ /** True when proc has been deleted, but still have sends that need ACKs */ bool endpoint_exiting; @@ -160,7 +158,7 @@ typedef struct mca_btl_base_endpoint_t { /* Values for the current proc to send to this endpoint on the peer proc */ opal_btl_usnic_seq_t endpoint_next_seq_to_send; /* n_t */ - opal_btl_usnic_seq_t endpoint_ack_seq_rcvd; /* n_a */ + opal_btl_usnic_seq_t endpoint_ack_seq_rcvd; /* n_a */ /* Table where sent segments sit while waiting for their ACKs. When a segment is ACKed, it is removed from this table. */ @@ -176,7 +174,7 @@ typedef struct mca_btl_base_endpoint_t { uint64_t endpoint_acktime; opal_btl_usnic_seq_t endpoint_next_contig_seq_to_recv; /* n_r */ - opal_btl_usnic_seq_t endpoint_highest_seq_rcvd; /* n_s */ + opal_btl_usnic_seq_t endpoint_highest_seq_rcvd; /* n_s */ bool endpoint_rcvd_segs[WINDOW_SIZE]; uint32_t endpoint_rfstart; @@ -199,9 +197,7 @@ typedef struct { /* * Flush all pending sends and resends from and endpoint */ -void -opal_btl_usnic_flush_endpoint( - opal_btl_usnic_endpoint_t *endpoint); +void opal_btl_usnic_flush_endpoint(opal_btl_usnic_endpoint_t *endpoint); END_C_DECLS #endif diff --git a/opal/mca/btl/usnic/btl_usnic_frag.c b/opal/mca/btl/usnic/btl_usnic_frag.c index 6a8129a3f7e..30a8e6aff3e 100644 --- a/opal/mca/btl/usnic/btl_usnic_frag.c +++ b/opal/mca/btl/usnic/btl_usnic_frag.c @@ -24,13 +24,12 @@ #include #include "btl_usnic.h" +#include "btl_usnic_ack.h" #include "btl_usnic_endpoint.h" -#include "btl_usnic_module.h" #include "btl_usnic_frag.h" -#include "btl_usnic_ack.h" +#include "btl_usnic_module.h" -static void -common_send_seg_helper(opal_btl_usnic_send_segment_t *seg) +static void common_send_seg_helper(opal_btl_usnic_send_segment_t *seg) { opal_btl_usnic_segment_t *bseg; @@ -43,14 +42,12 @@ common_send_seg_helper(opal_btl_usnic_send_segment_t *seg) /* Offset the BTL header by (prefix_send_offset) bytes into the raw buffer */ bseg = &seg->ss_base; - bseg->us_btl_header = (opal_btl_usnic_btl_header_t *) - (seg->ss_ptr + mca_btl_usnic_component.prefix_send_offset); + bseg->us_btl_header = (opal_btl_usnic_btl_header_t + *) (seg->ss_ptr + mca_btl_usnic_component.prefix_send_offset); bseg->us_btl_header->sender = mca_btl_usnic_component.my_hashed_rte_name; } -static void -chunk_seg_constructor( - opal_btl_usnic_chunk_segment_t *cseg) +static void chunk_seg_constructor(opal_btl_usnic_chunk_segment_t *cseg) { opal_btl_usnic_segment_t *bseg; @@ -61,14 +58,12 @@ chunk_seg_constructor( common_send_seg_helper(cseg); /* payload starts next byte beyond BTL chunk header */ - bseg->us_payload.raw = (uint8_t *)(bseg->us_btl_chunk_header + 1); + bseg->us_payload.raw = (uint8_t *) (bseg->us_btl_chunk_header + 1); bseg->us_btl_header->payload_type = OPAL_BTL_USNIC_PAYLOAD_TYPE_CHUNK; } -static void -frag_seg_constructor( - opal_btl_usnic_frag_segment_t *fseg) +static void frag_seg_constructor(opal_btl_usnic_frag_segment_t *fseg) { opal_btl_usnic_segment_t *bseg; @@ -79,14 +74,12 @@ frag_seg_constructor( common_send_seg_helper(fseg); /* payload starts next byte beyond BTL header */ - bseg->us_payload.raw = (uint8_t *)(bseg->us_btl_header + 1); + bseg->us_payload.raw = (uint8_t *) (bseg->us_btl_header + 1); bseg->us_btl_header->payload_type = OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG; } -static void -ack_seg_constructor( - opal_btl_usnic_ack_segment_t *ack) +static void ack_seg_constructor(opal_btl_usnic_ack_segment_t *ack) { opal_btl_usnic_segment_t *bseg; @@ -104,10 +97,7 @@ ack_seg_constructor( ack->ss_len = sizeof(bseg->us_btl_header); } - -static void -recv_seg_constructor( - opal_btl_usnic_recv_segment_t *seg) +static void recv_seg_constructor(opal_btl_usnic_recv_segment_t *seg) { opal_btl_usnic_segment_t *bseg; @@ -116,9 +106,9 @@ recv_seg_constructor( /* on receive, BTL header starts after protocol header */ seg->rs_protocol_header = bseg->us_list.ptr; - bseg->us_btl_header = (opal_btl_usnic_btl_header_t *)( - ((char *) seg->rs_protocol_header) + - mca_btl_usnic_component.transport_header_len); + bseg->us_btl_header = (opal_btl_usnic_btl_header_t *) (((char *) seg->rs_protocol_header) + + mca_btl_usnic_component + .transport_header_len); /* initialize descriptor */ /* JMS Initializing RECV_REMOTE for receive frags is unnecessary @@ -138,13 +128,11 @@ recv_seg_constructor( * OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG, but that's the only time * we ever give segment directly to upper layer, so its OK */ - bseg->us_payload.ompi_header = (mca_btl_base_header_t *) - (bseg->us_btl_header+1); + bseg->us_payload.ompi_header = (mca_btl_base_header_t *) (bseg->us_btl_header + 1); seg->rs_segment.seg_addr.pval = bseg->us_payload.ompi_header; } -static void -send_frag_constructor(opal_btl_usnic_send_frag_t *frag) +static void send_frag_constructor(opal_btl_usnic_send_frag_t *frag) { mca_btl_base_descriptor_t *desc; @@ -172,8 +160,7 @@ send_frag_constructor(opal_btl_usnic_send_frag_t *frag) frag->sf_seg_post_cnt = 0; } -static void -send_frag_destructor(opal_btl_usnic_send_frag_t *frag) +static void send_frag_destructor(opal_btl_usnic_send_frag_t *frag) { #if OPAL_ENABLE_DEBUG /* make sure nobody twiddled these values after the constructor */ @@ -189,8 +176,7 @@ send_frag_destructor(opal_btl_usnic_send_frag_t *frag) OBJ_DESTRUCT(&frag->sf_convertor); } -static void -small_send_frag_constructor(opal_btl_usnic_small_send_frag_t *frag) +static void small_send_frag_constructor(opal_btl_usnic_small_send_frag_t *frag) { opal_btl_usnic_frag_segment_t *fseg; @@ -201,44 +187,38 @@ small_send_frag_constructor(opal_btl_usnic_small_send_frag_t *frag) OBJ_CONSTRUCT(fseg, opal_btl_usnic_frag_segment_t); /* set us as parent in dedicated frag */ - fseg->ss_parent_frag = (struct opal_btl_usnic_send_frag_t *)frag; + fseg->ss_parent_frag = (struct opal_btl_usnic_send_frag_t *) frag; frag->ssf_base.sf_base.uf_type = OPAL_BTL_USNIC_FRAG_SMALL_SEND; /* save data pointer for PML */ - frag->ssf_base.sf_base.uf_local_seg[0].seg_addr.pval = - fseg->ss_base.us_payload.raw; + frag->ssf_base.sf_base.uf_local_seg[0].seg_addr.pval = fseg->ss_base.us_payload.raw; } -static void -small_send_frag_destructor(opal_btl_usnic_small_send_frag_t *frag) +static void small_send_frag_destructor(opal_btl_usnic_small_send_frag_t *frag) { opal_btl_usnic_frag_segment_t *fseg; fseg = &frag->ssf_segment; - assert(fseg->ss_parent_frag == (struct opal_btl_usnic_send_frag_t *)frag); + assert(fseg->ss_parent_frag == (struct opal_btl_usnic_send_frag_t *) frag); assert(frag->ssf_base.sf_base.uf_type == OPAL_BTL_USNIC_FRAG_SMALL_SEND); - assert(frag->ssf_base.sf_base.uf_local_seg[0].seg_addr.pval == - fseg->ss_base.us_payload.raw); + assert(frag->ssf_base.sf_base.uf_local_seg[0].seg_addr.pval == fseg->ss_base.us_payload.raw); OBJ_DESTRUCT(fseg); } -static void -large_send_frag_constructor(opal_btl_usnic_large_send_frag_t *lfrag) +static void large_send_frag_constructor(opal_btl_usnic_large_send_frag_t *lfrag) { lfrag->lsf_base.sf_base.uf_type = OPAL_BTL_USNIC_FRAG_LARGE_SEND; /* save data pointer for upper layer */ - lfrag->lsf_base.sf_base.uf_local_seg[0].seg_addr.pval = - &lfrag->lsf_ompi_header; + lfrag->lsf_base.sf_base.uf_local_seg[0].seg_addr.pval = &lfrag->lsf_ompi_header; lfrag->lsf_buffer = NULL; OBJ_CONSTRUCT(&lfrag->lsf_seg_chain, opal_list_t); lfrag->lsf_pack_on_the_fly = false; } -static void -put_dest_frag_constructor(opal_btl_usnic_put_dest_frag_t *pfrag) +static void put_dest_frag_constructor(opal_btl_usnic_put_dest_frag_t *pfrag) { pfrag->uf_type = OPAL_BTL_USNIC_FRAG_PUT_DEST; @@ -247,67 +227,41 @@ put_dest_frag_constructor(opal_btl_usnic_put_dest_frag_t *pfrag) pfrag->uf_base.USNIC_PUT_LOCAL_COUNT = 1; } -static void -put_dest_frag_destructor(opal_btl_usnic_put_dest_frag_t *pfrag) +static void put_dest_frag_destructor(opal_btl_usnic_put_dest_frag_t *pfrag) { assert(pfrag->uf_base.USNIC_PUT_LOCAL == pfrag->uf_remote_seg); assert(1 == pfrag->uf_base.USNIC_PUT_LOCAL_COUNT); } -OBJ_CLASS_INSTANCE(opal_btl_usnic_segment_t, - opal_free_list_item_t, - NULL, - NULL); +OBJ_CLASS_INSTANCE(opal_btl_usnic_segment_t, opal_free_list_item_t, NULL, NULL); -OBJ_CLASS_INSTANCE(opal_btl_usnic_frag_segment_t, - opal_btl_usnic_segment_t, - frag_seg_constructor, +OBJ_CLASS_INSTANCE(opal_btl_usnic_frag_segment_t, opal_btl_usnic_segment_t, frag_seg_constructor, NULL); -OBJ_CLASS_INSTANCE(opal_btl_usnic_chunk_segment_t, - opal_btl_usnic_segment_t, - chunk_seg_constructor, +OBJ_CLASS_INSTANCE(opal_btl_usnic_chunk_segment_t, opal_btl_usnic_segment_t, chunk_seg_constructor, NULL); -OBJ_CLASS_INSTANCE(opal_btl_usnic_recv_segment_t, - opal_btl_usnic_segment_t, - recv_seg_constructor, +OBJ_CLASS_INSTANCE(opal_btl_usnic_recv_segment_t, opal_btl_usnic_segment_t, recv_seg_constructor, NULL); -OBJ_CLASS_INSTANCE(opal_btl_usnic_ack_segment_t, - opal_btl_usnic_segment_t, - ack_seg_constructor, +OBJ_CLASS_INSTANCE(opal_btl_usnic_ack_segment_t, opal_btl_usnic_segment_t, ack_seg_constructor, NULL); /* * Fragments */ -OBJ_CLASS_INSTANCE(opal_btl_usnic_frag_t, - mca_btl_base_descriptor_t, - NULL, - NULL); +OBJ_CLASS_INSTANCE(opal_btl_usnic_frag_t, mca_btl_base_descriptor_t, NULL, NULL); -OBJ_CLASS_INSTANCE(opal_btl_usnic_send_frag_t, - opal_btl_usnic_frag_t, - send_frag_constructor, +OBJ_CLASS_INSTANCE(opal_btl_usnic_send_frag_t, opal_btl_usnic_frag_t, send_frag_constructor, send_frag_destructor); -OBJ_CLASS_INSTANCE(opal_btl_usnic_large_send_frag_t, - opal_btl_usnic_send_frag_t, - large_send_frag_constructor, - NULL); +OBJ_CLASS_INSTANCE(opal_btl_usnic_large_send_frag_t, opal_btl_usnic_send_frag_t, + large_send_frag_constructor, NULL); -OBJ_CLASS_INSTANCE(opal_btl_usnic_small_send_frag_t, - opal_btl_usnic_send_frag_t, - small_send_frag_constructor, - small_send_frag_destructor); +OBJ_CLASS_INSTANCE(opal_btl_usnic_small_send_frag_t, opal_btl_usnic_send_frag_t, + small_send_frag_constructor, small_send_frag_destructor); -OBJ_CLASS_INSTANCE(opal_btl_usnic_put_dest_frag_t, - opal_btl_usnic_frag_t, - put_dest_frag_constructor, +OBJ_CLASS_INSTANCE(opal_btl_usnic_put_dest_frag_t, opal_btl_usnic_frag_t, put_dest_frag_constructor, put_dest_frag_destructor); -OBJ_CLASS_INSTANCE(opal_btl_usnic_rx_buf_t, - opal_free_list_item_t, - NULL, - NULL); +OBJ_CLASS_INSTANCE(opal_btl_usnic_rx_buf_t, opal_free_list_item_t, NULL, NULL); diff --git a/opal/mca/btl/usnic/btl_usnic_frag.h b/opal/mca/btl/usnic/btl_usnic_frag.h index e9bdd8223c8..8fdad11f4a9 100644 --- a/opal/mca/btl/usnic/btl_usnic_frag.h +++ b/opal/mca/btl/usnic/btl_usnic_frag.h @@ -54,14 +54,17 @@ typedef enum { OPAL_BTL_USNIC_FRAG_PUT_DEST } opal_btl_usnic_frag_type_t; -static inline const char * -usnic_frag_type(opal_btl_usnic_frag_type_t t) +static inline const char *usnic_frag_type(opal_btl_usnic_frag_type_t t) { switch (t) { - case OPAL_BTL_USNIC_FRAG_LARGE_SEND: return "large"; - case OPAL_BTL_USNIC_FRAG_SMALL_SEND: return "small"; - case OPAL_BTL_USNIC_FRAG_PUT_DEST: return "put dest"; - default: return "unknown"; + case OPAL_BTL_USNIC_FRAG_LARGE_SEND: + return "large"; + case OPAL_BTL_USNIC_FRAG_SMALL_SEND: + return "small"; + case OPAL_BTL_USNIC_FRAG_PUT_DEST: + return "put dest"; + default: + return "unknown"; } } @@ -72,19 +75,22 @@ typedef enum { OPAL_BTL_USNIC_SEG_RECV } opal_btl_usnic_seg_type_t; -static inline const char * -usnic_seg_type_str(opal_btl_usnic_seg_type_t t) +static inline const char *usnic_seg_type_str(opal_btl_usnic_seg_type_t t) { switch (t) { - case OPAL_BTL_USNIC_SEG_ACK: return "ACK"; - case OPAL_BTL_USNIC_SEG_FRAG: return "FRAG"; - case OPAL_BTL_USNIC_SEG_CHUNK: return "CHUNK"; - case OPAL_BTL_USNIC_SEG_RECV: return "RECV"; - default: return "unknown"; + case OPAL_BTL_USNIC_SEG_ACK: + return "ACK"; + case OPAL_BTL_USNIC_SEG_FRAG: + return "FRAG"; + case OPAL_BTL_USNIC_SEG_CHUNK: + return "CHUNK"; + case OPAL_BTL_USNIC_SEG_RECV: + return "RECV"; + default: + return "unknown"; } } - /* * usnic registration handle (passed over the network to peers as a * cookie). @@ -109,14 +115,13 @@ typedef struct opal_btl_usnic_reg_t { struct fid_mr *ur_mr; } opal_btl_usnic_reg_t; - /** * usnic header type */ typedef enum { OPAL_BTL_USNIC_PAYLOAD_TYPE_ACK = 1, - OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG = 2, /* an entire fragment */ - OPAL_BTL_USNIC_PAYLOAD_TYPE_CHUNK = 3 /* one chunk of fragment */ + OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG = 2, /* an entire fragment */ + OPAL_BTL_USNIC_PAYLOAD_TYPE_CHUNK = 3 /* one chunk of fragment */ } opal_btl_usnic_payload_type_t; /** @@ -131,7 +136,7 @@ typedef struct { /* Sliding window sequence number (echoed back in an ACK). */ opal_btl_usnic_seq_t pkt_seq; - opal_btl_usnic_seq_t ack_seq; /* for piggy-backing ACKs */ + opal_btl_usnic_seq_t ack_seq; /* for piggy-backing ACKs */ /* payload legnth (in bytes). We unfortunately have to include this in our header because the L2 layer may artifically inflate @@ -163,9 +168,9 @@ typedef struct { typedef struct { opal_btl_usnic_btl_header_t ch_hdr; - uint32_t ch_frag_id; /* ID for collecting segments of same frag */ - uint32_t ch_frag_size; /* total frag len */ - uint32_t ch_frag_offset; /* where in fragment this goes */ + uint32_t ch_frag_id; /* ID for collecting segments of same frag */ + uint32_t ch_frag_size; /* total frag len */ + uint32_t ch_frag_offset; /* where in fragment this goes */ } opal_btl_usnic_btl_chunk_header_t; /** @@ -182,7 +187,7 @@ typedef struct opal_btl_usnic_segment_t { opal_btl_usnic_btl_header_t *uus_btl_header; opal_btl_usnic_btl_chunk_header_t *uus_btl_chunk_header; } us_hdr; -#define us_btl_header us_hdr.uus_btl_header +#define us_btl_header us_hdr.uus_btl_header #define us_btl_chunk_header us_hdr.uus_btl_chunk_header union { @@ -226,11 +231,11 @@ typedef struct opal_btl_usnic_send_segment_t { opal_btl_usnic_channel_id_t ss_channel; struct opal_btl_usnic_send_frag_t *ss_parent_frag; - int ss_hotel_room; /* current retrans room, or -1 if none */ + int ss_hotel_room; /* current retrans room, or -1 if none */ /* How many times is this frag on a hardware queue? */ uint32_t ss_send_posted; - bool ss_ack_pending; /* true until this segment is ACKed */ + bool ss_ack_pending; /* true until this segment is ACKed */ } opal_btl_usnic_send_segment_t; @@ -262,13 +267,13 @@ typedef struct opal_btl_usnic_send_frag_t { struct mca_btl_base_endpoint_t *sf_endpoint; - size_t sf_size; /* total_fragment size (upper + user payload) */ + size_t sf_size; /* total_fragment size (upper + user payload) */ struct opal_convertor_t sf_convertor; /* copy of original message data if convertor required */ - uint32_t sf_seg_post_cnt; /* total segs currently posted for this frag */ - size_t sf_ack_bytes_left; /* bytes remaining to be ACKed */ + uint32_t sf_seg_post_cnt; /* total segs currently posted for this frag */ + size_t sf_ack_bytes_left; /* bytes remaining to be ACKed */ struct opal_btl_usnic_send_frag_t *sf_next; } opal_btl_usnic_send_frag_t; @@ -284,7 +289,7 @@ typedef struct opal_btl_usnic_large_send_frag_t { char lsf_ompi_header[64]; /* space for upper layer header */ mca_btl_base_tag_t lsf_tag; /* save tag */ - uint32_t lsf_frag_id; /* fragment ID for reassembly */ + uint32_t lsf_frag_id; /* fragment ID for reassembly */ size_t lsf_cur_offset; /* next byte offset to be enqueued on the endpoint (incl. any convertor payload) */ @@ -296,16 +301,16 @@ typedef struct opal_btl_usnic_large_send_frag_t { int lsf_cur_sge; size_t lsf_bytes_left_in_sge; - uint8_t *lsf_buffer; /* attached storage for usnic_alloc() */ + uint8_t *lsf_buffer; /* attached storage for usnic_alloc() */ - opal_list_t lsf_seg_chain; /* chain of segments for converted data */ + opal_list_t lsf_seg_chain; /* chain of segments for converted data */ - bool lsf_pack_on_the_fly; /* true if we are packing on the fly */ + bool lsf_pack_on_the_fly; /* true if we are packing on the fly */ } opal_btl_usnic_large_send_frag_t; /* Shortcut member macros. Access uf_src_seg array instead of the descriptor's * des_src ptr to save a deref. */ -#define lsf_des_src lsf_base.sf_base.uf_local_seg +#define lsf_des_src lsf_base.sf_base.uf_local_seg /** * small send fragment @@ -372,7 +377,7 @@ opal_btl_usnic_small_send_frag_alloc(opal_btl_usnic_module_t *module) return NULL; } - frag = (opal_btl_usnic_small_send_frag_t*) item; + frag = (opal_btl_usnic_small_send_frag_t *) item; /* this belongs in constructor... */ frag->ssf_base.sf_base.uf_freelist = &(module->small_send_frags); @@ -395,7 +400,7 @@ opal_btl_usnic_large_send_frag_alloc(opal_btl_usnic_module_t *module) return NULL; } - frag = (opal_btl_usnic_large_send_frag_t*) item; + frag = (opal_btl_usnic_large_send_frag_t *) item; /* this belongs in constructor... */ frag->lsf_base.sf_base.uf_freelist = &(module->large_send_frags); @@ -407,8 +412,7 @@ opal_btl_usnic_large_send_frag_alloc(opal_btl_usnic_module_t *module) } static inline opal_btl_usnic_put_dest_frag_t * -opal_btl_usnic_put_dest_frag_alloc( - struct opal_btl_usnic_module_t *module) +opal_btl_usnic_put_dest_frag_alloc(struct opal_btl_usnic_module_t *module) { opal_free_list_item_t *item; opal_btl_usnic_put_dest_frag_t *frag; @@ -418,7 +422,7 @@ opal_btl_usnic_put_dest_frag_alloc( return NULL; } - frag = (opal_btl_usnic_put_dest_frag_t*) item; + frag = (opal_btl_usnic_put_dest_frag_t *) item; /* this belongs in constructor... */ frag->uf_freelist = &(module->put_dest_frags); @@ -439,31 +443,24 @@ opal_btl_usnic_put_dest_frag_alloc( * b) all of its segments have been ACKed * c) it is owned by the BTL */ -static inline bool -opal_btl_usnic_send_frag_ok_to_return( - opal_btl_usnic_module_t *module, - opal_btl_usnic_send_frag_t *frag) +static inline bool opal_btl_usnic_send_frag_ok_to_return(opal_btl_usnic_module_t *module, + opal_btl_usnic_send_frag_t *frag) { assert(frag); - if (OPAL_LIKELY(frag->sf_base.uf_base.des_flags & - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP) && - 0 == frag->sf_ack_bytes_left && - 0 == frag->sf_seg_post_cnt) { + if (OPAL_LIKELY(frag->sf_base.uf_base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP) + && 0 == frag->sf_ack_bytes_left && 0 == frag->sf_seg_post_cnt) { return true; } return false; } -static inline void -opal_btl_usnic_frag_return( - struct opal_btl_usnic_module_t *module, - opal_btl_usnic_frag_t *frag) +static inline void opal_btl_usnic_frag_return(struct opal_btl_usnic_module_t *module, + opal_btl_usnic_frag_t *frag) { #if MSGDEBUG1 - opal_output(0, "freeing frag %p, type %s\n", (void *)frag, - usnic_frag_type(frag->uf_type)); + opal_output(0, "freeing frag %p, type %s\n", (void *) frag, usnic_frag_type(frag->uf_type)); #endif frag->uf_local_seg[0].seg_len = 0; frag->uf_local_seg[1].seg_len = 0; @@ -473,7 +470,7 @@ opal_btl_usnic_frag_return( */ if (frag->uf_type == OPAL_BTL_USNIC_FRAG_LARGE_SEND) { opal_btl_usnic_large_send_frag_t *lfrag; - lfrag = (opal_btl_usnic_large_send_frag_t *)frag; + lfrag = (opal_btl_usnic_large_send_frag_t *) frag; if (lfrag->lsf_buffer != NULL) { free(lfrag->lsf_buffer); lfrag->lsf_buffer = NULL; @@ -481,8 +478,8 @@ opal_btl_usnic_frag_return( lfrag->lsf_pack_on_the_fly = false; /* JMS This should never happen any more, right? */ - if (2 == lfrag->lsf_base.sf_base.uf_base.USNIC_SEND_LOCAL_COUNT && - NULL == lfrag->lsf_des_src[1].seg_addr.pval) { + if (2 == lfrag->lsf_base.sf_base.uf_base.USNIC_SEND_LOCAL_COUNT + && NULL == lfrag->lsf_des_src[1].seg_addr.pval) { opal_convertor_cleanup(&lfrag->lsf_base.sf_convertor); } } @@ -501,10 +498,8 @@ opal_btl_usnic_frag_return( /* * Return a send frag if it's all done and owned by BTL */ -static inline void -opal_btl_usnic_send_frag_return_cond( - struct opal_btl_usnic_module_t *module, - opal_btl_usnic_send_frag_t *frag) +static inline void opal_btl_usnic_send_frag_return_cond(struct opal_btl_usnic_module_t *module, + opal_btl_usnic_send_frag_t *frag) { if (opal_btl_usnic_send_frag_ok_to_return(module, frag)) { opal_btl_usnic_frag_return(module, &frag->sf_base); @@ -517,25 +512,20 @@ opal_btl_usnic_send_frag_return_cond( * a send frag, there are other conditions, so use the specific send frag * return checker. */ -static inline void -opal_btl_usnic_frag_return_cond( - struct opal_btl_usnic_module_t *module, - opal_btl_usnic_frag_t *frag) +static inline void opal_btl_usnic_frag_return_cond(struct opal_btl_usnic_module_t *module, + opal_btl_usnic_frag_t *frag) { if (OPAL_BTL_USNIC_FRAG_PUT_DEST == frag->uf_type) { - if (OPAL_LIKELY(frag->uf_base.des_flags & - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { + if (OPAL_LIKELY(frag->uf_base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { opal_btl_usnic_frag_return(module, frag); } } else { - opal_btl_usnic_send_frag_return_cond(module, - (opal_btl_usnic_send_frag_t *)frag); + opal_btl_usnic_send_frag_return_cond(module, (opal_btl_usnic_send_frag_t *) frag); } } static inline opal_btl_usnic_chunk_segment_t * -opal_btl_usnic_chunk_segment_alloc( - opal_btl_usnic_module_t *module) +opal_btl_usnic_chunk_segment_alloc(opal_btl_usnic_module_t *module) { opal_free_list_item_t *item; opal_btl_usnic_send_segment_t *seg; @@ -545,7 +535,7 @@ opal_btl_usnic_chunk_segment_alloc( return NULL; } - seg = (opal_btl_usnic_send_segment_t*) item; + seg = (opal_btl_usnic_send_segment_t *) item; seg->ss_channel = USNIC_DATA_CHANNEL; assert(seg); @@ -554,10 +544,8 @@ opal_btl_usnic_chunk_segment_alloc( return seg; } -static inline void -opal_btl_usnic_chunk_segment_return( - opal_btl_usnic_module_t *module, - opal_btl_usnic_chunk_segment_t *seg) +static inline void opal_btl_usnic_chunk_segment_return(opal_btl_usnic_module_t *module, + opal_btl_usnic_chunk_segment_t *seg) { assert(seg); assert(OPAL_BTL_USNIC_SEG_CHUNK == seg->ss_base.us_type); @@ -579,7 +567,7 @@ opal_btl_usnic_ack_segment_alloc(opal_btl_usnic_module_t *module) return NULL; } - ack = (opal_btl_usnic_ack_segment_t*) item; + ack = (opal_btl_usnic_ack_segment_t *) item; ack->ss_channel = USNIC_PRIORITY_CHANNEL; assert(ack); @@ -591,10 +579,8 @@ opal_btl_usnic_ack_segment_alloc(opal_btl_usnic_module_t *module) /* * Return an ACK segment */ -static inline void -opal_btl_usnic_ack_segment_return( - opal_btl_usnic_module_t *module, - opal_btl_usnic_ack_segment_t *ack) +static inline void opal_btl_usnic_ack_segment_return(opal_btl_usnic_module_t *module, + opal_btl_usnic_ack_segment_t *ack) { assert(ack); assert(OPAL_BTL_USNIC_SEG_ACK == ack->ss_base.us_type); @@ -605,8 +591,7 @@ opal_btl_usnic_ack_segment_return( /* Compute and set the proper value for sfrag->sf_size. This must not be used * during usnic_alloc, since the PML might change the segment size after * usnic_alloc returns. */ -static inline void -opal_btl_usnic_compute_sf_size(opal_btl_usnic_send_frag_t *sfrag) +static inline void opal_btl_usnic_compute_sf_size(opal_btl_usnic_send_frag_t *sfrag) { opal_btl_usnic_frag_t *frag; diff --git a/opal/mca/btl/usnic/btl_usnic_hwloc.c b/opal/mca/btl/usnic/btl_usnic_hwloc.c index 88768f4116b..4d67e423255 100644 --- a/opal/mca/btl/usnic/btl_usnic_hwloc.c +++ b/opal/mca/btl/usnic/btl_usnic_hwloc.c @@ -10,8 +10,8 @@ #include "opal_config.h" -#include "opal/mca/hwloc/base/base.h" #include "opal/constants.h" +#include "opal/mca/hwloc/base/base.h" #include "opal/mca/btl/base/base.h" @@ -37,15 +37,15 @@ static int get_distance_matrix(void) * responsible for freeing it. */ if (NULL == matrix) { - matrix = hwloc_get_whole_distance_matrix_by_type(opal_hwloc_topology, - HWLOC_OBJ_NODE); + matrix = hwloc_get_whole_distance_matrix_by_type(opal_hwloc_topology, HWLOC_OBJ_NODE); } return (NULL == matrix) ? OPAL_ERROR : OPAL_SUCCESS; #else - if (0 != hwloc_distances_get_by_type(opal_hwloc_topology, HWLOC_OBJ_NODE, - &matrix_nr, &matrix, - HWLOC_DISTANCES_KIND_MEANS_LATENCY, 0) || 0 == matrix_nr) { + if (0 + != hwloc_distances_get_by_type(opal_hwloc_topology, HWLOC_OBJ_NODE, &matrix_nr, &matrix, + HWLOC_DISTANCES_KIND_MEANS_LATENCY, 0) + || 0 == matrix_nr) { return OPAL_ERROR; } return OPAL_SUCCESS; @@ -59,28 +59,27 @@ static hwloc_obj_t find_numa_node(hwloc_bitmap_t cpuset) { hwloc_obj_t obj; - obj = - hwloc_get_first_largest_obj_inside_cpuset(opal_hwloc_topology, cpuset); + obj = hwloc_get_first_largest_obj_inside_cpuset(opal_hwloc_topology, cpuset); /* Go upwards until we hit the NUMA node or run out of parents */ - while (obj->type > HWLOC_OBJ_NODE && - NULL != obj->parent) { + while (obj->type > HWLOC_OBJ_NODE && NULL != obj->parent) { obj = obj->parent; } /* Make sure we ended up on the NUMA node */ if (obj->type != HWLOC_OBJ_NODE) { opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: could not find NUMA node where this process is bound; filtering by NUMA distance not possible"); + "btl:usnic:filter_numa: could not find NUMA node where this process is " + "bound; filtering by NUMA distance not possible"); return NULL; } /* Finally, make sure that our cpuset doesn't span more than 1 NUMA node */ - if (hwloc_get_nbobjs_inside_cpuset_by_type(opal_hwloc_topology, - cpuset, HWLOC_OBJ_NODE) > 1) { + if (hwloc_get_nbobjs_inside_cpuset_by_type(opal_hwloc_topology, cpuset, HWLOC_OBJ_NODE) > 1) { opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: this process is bound to more than 1 NUMA node; filtering by NUMA distance not possible"); + "btl:usnic:filter_numa: this process is bound to more than 1 NUMA " + "node; filtering by NUMA distance not possible"); return NULL; } @@ -124,10 +123,8 @@ static int find_my_numa_node(void) /* Happiness */ my_numa_node = obj; - num_numa_nodes = hwloc_get_nbobjs_by_type(opal_hwloc_topology, - HWLOC_OBJ_NODE); + num_numa_nodes = hwloc_get_nbobjs_by_type(opal_hwloc_topology, HWLOC_OBJ_NODE); return OPAL_SUCCESS; - } /* @@ -162,15 +159,15 @@ static hwloc_obj_t find_device_numa(opal_btl_usnic_module_t *module) /* Search upwards to find the device's NUMA node */ /* Go upwards until we hit the NUMA node or run out of parents */ - while (obj->type > HWLOC_OBJ_NODE && - NULL != obj->parent) { + while (obj->type > HWLOC_OBJ_NODE && NULL != obj->parent) { obj = obj->parent; } /* Make sure we ended up on the NUMA node */ if (obj->type != HWLOC_OBJ_NODE) { opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: could not find NUMA node for %s; filtering by NUMA distance not possible", + "btl:usnic:filter_numa: could not find NUMA node for %s; filtering by " + "NUMA distance not possible", module->linux_device_name); return NULL; } @@ -192,18 +189,19 @@ int opal_btl_usnic_hwloc_distance(opal_btl_usnic_module_t *module) /* Is this process bound? */ if (!proc_bound()) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: not sorting devices by NUMA distance (process not bound)"); + opal_output_verbose( + 5, USNIC_OUT, + "btl:usnic:filter_numa: not sorting devices by NUMA distance (process not bound)"); return OPAL_SUCCESS; } - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: filtering devices by NUMA distance"); + opal_output_verbose(5, USNIC_OUT, "btl:usnic:filter_numa: filtering devices by NUMA distance"); /* ensure we have the topology */ if (OPAL_SUCCESS != opal_hwloc_base_get_topology()) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: not sorting devices by NUMA distance (topology not available)"); + opal_output_verbose( + 5, USNIC_OUT, + "btl:usnic:filter_numa: not sorting devices by NUMA distance (topology not available)"); return OPAL_SUCCESS; } @@ -229,21 +227,18 @@ int opal_btl_usnic_hwloc_distance(opal_btl_usnic_module_t *module) the device */ #if HWLOC_API_VERSION < 0x20000 if (NULL != dev_numa) { - module->numa_distance = - matrix->latency[dev_numa->logical_index * num_numa_nodes + - my_numa_node->logical_index]; + module->numa_distance = matrix->latency[dev_numa->logical_index * num_numa_nodes + + my_numa_node->logical_index]; - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: %s is distance %d from me", - module->linux_device_name, - module->numa_distance); + opal_output_verbose(5, USNIC_OUT, "btl:usnic:filter_numa: %s is distance %d from me", + module->linux_device_name, module->numa_distance); } #else if (NULL != dev_numa) { int myindex, devindex; unsigned int j; myindex = -1; - for (j=0; j < matrix_nr; j++) { + for (j = 0; j < matrix_nr; j++) { if (my_numa_node == matrix->objs[j]) { myindex = j; break; @@ -253,7 +248,7 @@ int opal_btl_usnic_hwloc_distance(opal_btl_usnic_module_t *module) return OPAL_SUCCESS; } devindex = -1; - for (j=0; j < matrix_nr; j++) { + for (j = 0; j < matrix_nr; j++) { if (dev_numa == matrix->objs[j]) { devindex = j; break; @@ -263,13 +258,10 @@ int opal_btl_usnic_hwloc_distance(opal_btl_usnic_module_t *module) return OPAL_SUCCESS; } - module->numa_distance = - matrix->values[(devindex * num_numa_nodes) + myindex]; + module->numa_distance = matrix->values[(devindex * num_numa_nodes) + myindex]; - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:filter_numa: %s is distance %d from me", - module->linux_device_name, - module->numa_distance); + opal_output_verbose(5, USNIC_OUT, "btl:usnic:filter_numa: %s is distance %d from me", + module->linux_device_name, module->numa_distance); } #endif diff --git a/opal/mca/btl/usnic/btl_usnic_hwloc.h b/opal/mca/btl/usnic/btl_usnic_hwloc.h index 80bc2c7ac77..87ac494ddca 100644 --- a/opal/mca/btl/usnic/btl_usnic_hwloc.h +++ b/opal/mca/btl/usnic/btl_usnic_hwloc.h @@ -14,7 +14,6 @@ #include "btl_usnic_module.h" - int opal_btl_usnic_hwloc_distance(opal_btl_usnic_module_t *module); #endif /* BTL_USNIC_HWLOC_H */ diff --git a/opal/mca/btl/usnic/btl_usnic_map.c b/opal/mca/btl/usnic/btl_usnic_map.c index b9d074efdf3..29443109490 100644 --- a/opal/mca/btl/usnic/btl_usnic_map.c +++ b/opal/mca/btl/usnic/btl_usnic_map.c @@ -15,25 +15,24 @@ #include #include -#include "opal/util/show_help.h" #include "opal/util/printf.h" +#include "opal/util/show_help.h" -#include "btl_usnic_compat.h" #include "btl_usnic.h" +#include "btl_usnic_compat.h" #include "btl_usnic_module.h" -#include "btl_usnic_util.h" #include "btl_usnic_proc.h" +#include "btl_usnic_util.h" /* * qsort helper: compare modules by fabric name */ static int map_compare_modules(const void *aa, const void *bb) { - opal_btl_usnic_module_t *a = *((opal_btl_usnic_module_t**) aa); - opal_btl_usnic_module_t *b = *((opal_btl_usnic_module_t**) bb); + opal_btl_usnic_module_t *a = *((opal_btl_usnic_module_t **) aa); + opal_btl_usnic_module_t *b = *((opal_btl_usnic_module_t **) bb); - return strcmp(a->linux_device_name, - b->linux_device_name); + return strcmp(a->linux_device_name, b->linux_device_name); } /* @@ -53,17 +52,15 @@ static int map_output_modules(FILE *fp) /* First, we must sort the modules (by device name) so that they're always output in a repeatable order. */ - size = mca_btl_usnic_component.num_modules * - sizeof(opal_btl_usnic_module_t*); + size = mca_btl_usnic_component.num_modules * sizeof(opal_btl_usnic_module_t *); modules = calloc(1, size); if (NULL == modules) { return OPAL_ERR_IN_ERRNO; } memcpy(modules, mca_btl_usnic_component.usnic_active_modules, size); - qsort(modules, mca_btl_usnic_component.num_modules, - sizeof(opal_btl_usnic_module_t*), map_compare_modules); - + qsort(modules, mca_btl_usnic_component.num_modules, sizeof(opal_btl_usnic_module_t *), + map_compare_modules); /* Loop over and print the sorted module device information */ for (i = 0; i < mca_btl_usnic_component.num_modules; ++i) { @@ -71,13 +68,10 @@ static int map_output_modules(FILE *fp) sin = modules[i]->fabric_info->src_addr; prefix_len = usnic_netmask_to_cidrlen(uip->ui.v1.ui_netmask_be); - opal_btl_usnic_snprintf_ipv4_addr(ipv4, IPV4STRADDRLEN, - sin->sin_addr.s_addr, - prefix_len); + opal_btl_usnic_snprintf_ipv4_addr(ipv4, IPV4STRADDRLEN, sin->sin_addr.s_addr, prefix_len); - fprintf(fp, "device=%s,ip=%s,mss=%" PRIsize_t "\n", - modules[i]->linux_device_name, - ipv4, modules[i]->fabric_info->ep_attr->max_msg_size); + fprintf(fp, "device=%s,ip=%s,mss=%" PRIsize_t "\n", modules[i]->linux_device_name, ipv4, + modules[i]->fabric_info->ep_attr->max_msg_size); } /* Free the temp array */ @@ -93,8 +87,8 @@ static int map_output_modules(FILE *fp) */ static int map_compare_endpoints(const void *aa, const void *bb) { - opal_btl_usnic_endpoint_t *a = *((opal_btl_usnic_endpoint_t**) aa); - opal_btl_usnic_endpoint_t *b = *((opal_btl_usnic_endpoint_t**) bb); + opal_btl_usnic_endpoint_t *a = *((opal_btl_usnic_endpoint_t **) aa); + opal_btl_usnic_endpoint_t *b = *((opal_btl_usnic_endpoint_t **) bb); if (NULL == a && NULL == b) { return 0; @@ -104,8 +98,7 @@ static int map_compare_endpoints(const void *aa, const void *bb) return -1; } - return strcmp(a->endpoint_module->linux_device_name, - b->endpoint_module->linux_device_name); + return strcmp(a->endpoint_module->linux_device_name, b->endpoint_module->linux_device_name); } /* @@ -131,8 +124,7 @@ static int map_output_endpoints(FILE *fp, opal_btl_usnic_proc_t *proc) } memcpy(eps, proc->proc_endpoints, size); - qsort(eps, proc->proc_endpoint_count, - sizeof(opal_btl_usnic_endpoint_t*), + qsort(eps, proc->proc_endpoint_count, sizeof(opal_btl_usnic_endpoint_t *), map_compare_endpoints); /* Loop over and print the sorted endpoint information, ignoring @@ -149,9 +141,7 @@ static int map_output_endpoints(FILE *fp, opal_btl_usnic_proc_t *proc) eps[i]->endpoint_remote_modex.ipv4_addr, eps[i]->endpoint_remote_modex.netmask); - fprintf(fp, "device=%s@peer_ip=%s", - eps[i]->endpoint_module->linux_device_name, - ipv4); + fprintf(fp, "device=%s@peer_ip=%s", eps[i]->endpoint_module->linux_device_name, ipv4); ++num_output; } fprintf(fp, "\n"); @@ -169,8 +159,8 @@ static int map_output_endpoints(FILE *fp, opal_btl_usnic_proc_t *proc) */ static int map_compare_procs(const void *aa, const void *bb) { - opal_btl_usnic_proc_t *a = *((opal_btl_usnic_proc_t**) aa); - opal_btl_usnic_proc_t *b = *((opal_btl_usnic_proc_t**) bb); + opal_btl_usnic_proc_t *a = *((opal_btl_usnic_proc_t **) aa); + opal_btl_usnic_proc_t *b = *((opal_btl_usnic_proc_t **) bb); opal_process_name_t *an = &(a->proc_opal->proc_name); opal_process_name_t *bn = &(b->proc_opal->proc_name); @@ -198,19 +188,17 @@ static int map_output_procs(FILE *fp) /* First, we must sort the procs by MCW rank so that they're always output in a repeatable order. */ num_procs = opal_list_get_size(&mca_btl_usnic_component.usnic_procs); - procs = calloc(num_procs, sizeof(opal_btl_usnic_proc_t*)); + procs = calloc(num_procs, sizeof(opal_btl_usnic_proc_t *)); if (NULL == procs) { return OPAL_ERR_IN_ERRNO; } i = 0; - OPAL_LIST_FOREACH(pitem, &mca_btl_usnic_component.usnic_procs, - opal_btl_usnic_proc_t) { + OPAL_LIST_FOREACH (pitem, &mca_btl_usnic_component.usnic_procs, opal_btl_usnic_proc_t) { procs[i] = pitem; ++i; } - qsort(procs, num_procs, sizeof(opal_btl_usnic_proc_t*), - map_compare_procs); + qsort(procs, num_procs, sizeof(opal_btl_usnic_proc_t *), map_compare_procs); /* Loop over and print the sorted module device information */ int ret = OPAL_SUCCESS; @@ -247,11 +235,9 @@ void opal_btl_usnic_connectivity_map(void) /* Filename is of the form: -....txt */ opal_asprintf(&filename, "%s-%s.pid%d.job%d.mcwrank%d.txt", - mca_btl_usnic_component.connectivity_map_prefix, - opal_process_info.nodename, - getpid(), - opal_proc_local_get()->proc_name.jobid, - opal_proc_local_get()->proc_name.vpid); + mca_btl_usnic_component.connectivity_map_prefix, opal_process_info.nodename, + getpid(), opal_proc_local_get()->proc_name.jobid, + opal_proc_local_get()->proc_name.vpid); if (NULL == filename) { /* JMS abort? */ return; @@ -262,12 +248,8 @@ void opal_btl_usnic_connectivity_map(void) char dirname[PATH_MAX]; getcwd(dirname, sizeof(dirname)); dirname[sizeof(dirname) - 1] = '\0'; - opal_show_help("help-mpi-btl-usnic.txt", "cannot write to map file", - true, - opal_process_info.nodename, - filename, - dirname, - strerror(errno), errno); + opal_show_help("help-mpi-btl-usnic.txt", "cannot write to map file", true, + opal_process_info.nodename, filename, dirname, strerror(errno), errno); return; } diff --git a/opal/mca/btl/usnic/btl_usnic_mca.c b/opal/mca/btl/usnic/btl_usnic_mca.c index 76ff5595512..7f2d9dce654 100644 --- a/opal/mca/btl/usnic/btl_usnic_mca.c +++ b/opal/mca/btl/usnic/btl_usnic_mca.c @@ -25,23 +25,22 @@ #include "opal_config.h" -#include #include +#include #include "opal/mca/base/mca_base_var.h" #include "opal/util/argv.h" #include "opal/constants.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "btl_usnic.h" -#include "btl_usnic_frag.h" #include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" #include "btl_usnic_module.h" - /* * Local flags */ @@ -54,99 +53,69 @@ enum { REGINT_MAX = 0x88 }; - enum { REGSTR_EMPTY_OK = 0x01, REGSTR_MAX = 0x88 }; - /* * utility routine for string parameter registration */ -static int reg_string(const char* param_name, - const char* help_string, - const char* default_value, char **storage, - int flags, int level) +static int reg_string(const char *param_name, const char *help_string, const char *default_value, + char **storage, int flags, int level) { - *storage = (char*) default_value; - mca_base_component_var_register(&mca_btl_usnic_component.super.btl_version, - param_name, help_string, - MCA_BASE_VAR_TYPE_STRING, - NULL, - 0, - 0, - level, - MCA_BASE_VAR_SCOPE_READONLY, - storage); - - if (0 == (flags & REGSTR_EMPTY_OK) && - (NULL == *storage || 0 == strlen(*storage))) { - opal_output(0, "Bad parameter value for parameter \"%s\"", - param_name); + *storage = (char *) default_value; + mca_base_component_var_register(&mca_btl_usnic_component.super.btl_version, param_name, + help_string, MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, level, + MCA_BASE_VAR_SCOPE_READONLY, storage); + + if (0 == (flags & REGSTR_EMPTY_OK) && (NULL == *storage || 0 == strlen(*storage))) { + opal_output(0, "Bad parameter value for parameter \"%s\"", param_name); return OPAL_ERR_BAD_PARAM; } return OPAL_SUCCESS; } - /* * utility routine for integer parameter registration */ -static int reg_int(const char* param_name, - const char* help_string, - int default_value, int *storage, int flags, int level) +static int reg_int(const char *param_name, const char *help_string, int default_value, int *storage, + int flags, int level) { *storage = default_value; - mca_base_component_var_register(&mca_btl_usnic_component.super.btl_version, - param_name, help_string, - MCA_BASE_VAR_TYPE_INT, - NULL, - 0, - 0, - level, - MCA_BASE_VAR_SCOPE_READONLY, - storage); + mca_base_component_var_register(&mca_btl_usnic_component.super.btl_version, param_name, + help_string, MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, level, + MCA_BASE_VAR_SCOPE_READONLY, storage); if (0 != (flags & REGINT_NEG_ONE_OK) && -1 == *storage) { return OPAL_SUCCESS; } - if ((0 != (flags & REGINT_GE_ZERO) && *storage < 0) || - (0 != (flags & REGINT_GE_ONE) && *storage < 1) || - (0 != (flags & REGINT_NONZERO) && 0 == *storage)) { - opal_output(0, "Bad parameter value for parameter \"%s\"", - param_name); + if ((0 != (flags & REGINT_GE_ZERO) && *storage < 0) + || (0 != (flags & REGINT_GE_ONE) && *storage < 1) + || (0 != (flags & REGINT_NONZERO) && 0 == *storage)) { + opal_output(0, "Bad parameter value for parameter \"%s\"", param_name); return OPAL_ERR_BAD_PARAM; } return OPAL_SUCCESS; } - /* * utility routine for integer parameter registration */ -static int reg_bool(const char* param_name, - const char* help_string, - bool default_value, bool *storage, int level) +static int reg_bool(const char *param_name, const char *help_string, bool default_value, + bool *storage, int level) { *storage = default_value; - mca_base_component_var_register(&mca_btl_usnic_component.super.btl_version, - param_name, help_string, - MCA_BASE_VAR_TYPE_BOOL, - NULL, - 0, - 0, - level, - MCA_BASE_VAR_SCOPE_READONLY, - storage); + mca_base_component_var_register(&mca_btl_usnic_component.super.btl_version, param_name, + help_string, MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, level, + MCA_BASE_VAR_SCOPE_READONLY, storage); return OPAL_SUCCESS; } - int opal_btl_usnic_component_register(void) { int tmp, ret = 0; @@ -166,119 +135,144 @@ int opal_btl_usnic_component_register(void) static int pack_lazy_threshold; static int max_short_packets; -#define CHECK(expr) do {\ - tmp = (expr); \ - if (OPAL_SUCCESS != tmp) ret = tmp; \ - } while (0) +#define CHECK(expr) \ + do { \ + tmp = (expr); \ + if (OPAL_SUCCESS != tmp) \ + ret = tmp; \ + } while (0) CHECK(reg_int("max_btls", - "Maximum number of usNICs to use (default: 0 = as many as are available)", - 0, &max_modules, - REGINT_GE_ZERO, OPAL_INFO_LVL_2)); + "Maximum number of usNICs to use (default: 0 = as many as are available)", 0, + &max_modules, REGINT_GE_ZERO, OPAL_INFO_LVL_2)); mca_btl_usnic_component.max_modules = (size_t) max_modules; CHECK(reg_string("if_include", - "Comma-delimited list of usNIC devices/networks to be used (e.g. \"eth3,usnic_0,10.10.0.0/16\"; empty value means to use all available usNICs). Mutually exclusive with btl_usnic_if_exclude.", - NULL, &mca_btl_usnic_component.if_include, - REGSTR_EMPTY_OK, OPAL_INFO_LVL_1)); + "Comma-delimited list of usNIC devices/networks to be used (e.g. " + "\"eth3,usnic_0,10.10.0.0/16\"; empty value means to use all available " + "usNICs). Mutually exclusive with btl_usnic_if_exclude.", + NULL, &mca_btl_usnic_component.if_include, REGSTR_EMPTY_OK, OPAL_INFO_LVL_1)); - CHECK(reg_string("if_exclude", - "Comma-delimited list of usNIC devices/networks to be excluded (empty value means to not exclude any usNICs). Mutually exclusive with btl_usnic_if_include.", - NULL, &mca_btl_usnic_component.if_exclude, - REGSTR_EMPTY_OK, OPAL_INFO_LVL_1)); + CHECK(reg_string( + "if_exclude", + "Comma-delimited list of usNIC devices/networks to be excluded (empty value means to not " + "exclude any usNICs). Mutually exclusive with btl_usnic_if_include.", + NULL, &mca_btl_usnic_component.if_exclude, REGSTR_EMPTY_OK, OPAL_INFO_LVL_1)); CHECK(reg_int("stats", - "A non-negative integer specifying the frequency at which each usnic BTL will output statistics (default: 0 seconds, meaning that statistics are disabled)", - 0, &mca_btl_usnic_component.stats_frequency, 0, - OPAL_INFO_LVL_4)); - mca_btl_usnic_component.stats_enabled = - (bool) (mca_btl_usnic_component.stats_frequency > 0); + "A non-negative integer specifying the frequency at which each usnic BTL will " + "output statistics (default: 0 seconds, meaning that statistics are disabled)", + 0, &mca_btl_usnic_component.stats_frequency, 0, OPAL_INFO_LVL_4)); + mca_btl_usnic_component.stats_enabled = (bool) (mca_btl_usnic_component.stats_frequency > 0); CHECK(reg_int("stats_relative", - "If stats are enabled, output relative stats between the timestamps (vs. cumulative stats since the beginning of the job) (default: 0 -- i.e., absolute)", + "If stats are enabled, output relative stats between the timestamps (vs. " + "cumulative stats since the beginning of the job) (default: 0 -- i.e., absolute)", 0, &stats_relative, 0, OPAL_INFO_LVL_4)); mca_btl_usnic_component.stats_relative = (bool) stats_relative; - CHECK(reg_string("mpool_hints", "Hints to use when selecting mpool", - NULL, &mca_btl_usnic_component.usnic_mpool_hints, - REGSTR_EMPTY_OK, - OPAL_INFO_LVL_5)); + CHECK(reg_string("mpool_hints", "Hints to use when selecting mpool", NULL, + &mca_btl_usnic_component.usnic_mpool_hints, REGSTR_EMPTY_OK, OPAL_INFO_LVL_5)); - CHECK(reg_string("rcache", "Name of the registration cache to be used", - "grdma", &mca_btl_usnic_component.usnic_rcache_name, 0, - OPAL_INFO_LVL_5)); + CHECK(reg_string("rcache", "Name of the registration cache to be used", "grdma", + &mca_btl_usnic_component.usnic_rcache_name, 0, OPAL_INFO_LVL_5)); want_numa_device_assignment = 1; - CHECK(reg_int("want_numa_device_assignment", - "If 1, use only Cisco VIC ports thare are a minimum NUMA distance from the MPI process for short messages. If 0, use all available Cisco VIC ports for short messages. This parameter is meaningless (and ignored) unless MPI proceses are bound to processor cores. Defaults to 1 if NUMA support is included in Open MPI; -1 otherwise.", - want_numa_device_assignment, - &want_numa_device_assignment, - 0, OPAL_INFO_LVL_5)); - mca_btl_usnic_component.want_numa_device_assignment = - (1 == want_numa_device_assignment) ? true : false; - - CHECK(reg_int("sd_num", "Maximum send descriptors to post (-1 = pre-set defaults; depends on number and type of devices available)", + CHECK(reg_int( + "want_numa_device_assignment", + "If 1, use only Cisco VIC ports thare are a minimum NUMA distance from the MPI process for " + "short messages. If 0, use all available Cisco VIC ports for short messages. This " + "parameter is meaningless (and ignored) unless MPI proceses are bound to processor cores. " + "Defaults to 1 if NUMA support is included in Open MPI; -1 otherwise.", + want_numa_device_assignment, &want_numa_device_assignment, 0, OPAL_INFO_LVL_5)); + mca_btl_usnic_component.want_numa_device_assignment = (1 == want_numa_device_assignment) + ? true + : false; + + CHECK(reg_int("sd_num", + "Maximum send descriptors to post (-1 = pre-set defaults; depends on number and " + "type of devices available)", -1, &sd_num, REGINT_NEG_ONE_OK, OPAL_INFO_LVL_5)); mca_btl_usnic_component.sd_num = (int32_t) sd_num; - CHECK(reg_int("rd_num", "Number of pre-posted receive buffers (-1 = pre-set defaults; depends on number and type of devices available)", + CHECK(reg_int("rd_num", + "Number of pre-posted receive buffers (-1 = pre-set defaults; depends on number " + "and type of devices available)", -1, &rd_num, REGINT_NEG_ONE_OK, OPAL_INFO_LVL_5)); mca_btl_usnic_component.rd_num = (int32_t) rd_num; - CHECK(reg_int("prio_sd_num", "Maximum priority send descriptors to post (-1 = pre-set defaults; depends on number and type of devices available)", + CHECK(reg_int("prio_sd_num", + "Maximum priority send descriptors to post (-1 = pre-set defaults; depends on " + "number and type of devices available)", -1, &prio_sd_num, REGINT_NEG_ONE_OK, OPAL_INFO_LVL_5)); mca_btl_usnic_component.prio_sd_num = (int32_t) prio_sd_num; - CHECK(reg_int("prio_rd_num", "Number of pre-posted priority receive buffers (-1 = pre-set defaults; depends on number and type of devices available)", + CHECK(reg_int("prio_rd_num", + "Number of pre-posted priority receive buffers (-1 = pre-set defaults; depends " + "on number and type of devices available)", -1, &prio_rd_num, REGINT_NEG_ONE_OK, OPAL_INFO_LVL_5)); mca_btl_usnic_component.prio_rd_num = (int32_t) prio_rd_num; - CHECK(reg_int("cq_num", "Number of completion queue entries (-1 = pre-set defaults; depends on number and type of devices available; will error if (sd_num+rd_num)>cq_num)", + CHECK(reg_int("cq_num", + "Number of completion queue entries (-1 = pre-set defaults; depends on number " + "and type of devices available; will error if (sd_num+rd_num)>cq_num)", -1, &cq_num, REGINT_NEG_ONE_OK, OPAL_INFO_LVL_5)); mca_btl_usnic_component.cq_num = (int32_t) cq_num; - CHECK(reg_int("av_eq_num", "Number of event queue entries for peer address resolution", - 1024, &av_eq_num, REGINT_GE_ONE, OPAL_INFO_LVL_5)); + CHECK(reg_int("av_eq_num", "Number of event queue entries for peer address resolution", 1024, + &av_eq_num, REGINT_GE_ONE, OPAL_INFO_LVL_5)); mca_btl_usnic_component.av_eq_num = (int32_t) av_eq_num; - CHECK(reg_int("base_udp_port", "Base UDP port to use for usNIC communications. If 0, system will pick the port number. If non-zero, it will be added to each process' local rank to obtain the final port number (default: 0)", + CHECK(reg_int("base_udp_port", + "Base UDP port to use for usNIC communications. If 0, system will pick the port " + "number. If non-zero, it will be added to each process' local rank to obtain " + "the final port number (default: 0)", 0, &udp_port_base, REGINT_GE_ZERO, OPAL_INFO_LVL_5)); mca_btl_usnic_component.udp_port_base = (int) udp_port_base; - CHECK(reg_int("retrans_timeout", "Number of microseconds before retransmitting a frame", - 5000, &mca_btl_usnic_component.retrans_timeout, - REGINT_GE_ONE, OPAL_INFO_LVL_5)); - - CHECK(reg_int("max_resends_per_iteration", "Maximum number of frames to resend in a single iteration through usNIC component progress", - 16, &mca_btl_usnic_component.max_resends_per_iteration, - REGINT_GE_ONE, OPAL_INFO_LVL_5)); - - CHECK(reg_int("ack_iteration_delay", "Minimum number of times through usNIC \"progress\" function before checking to see if standalone ACKs need to be sent", - 4, &mca_btl_usnic_component.ack_iteration_delay, - REGINT_GE_ZERO, OPAL_INFO_LVL_5)); - - CHECK(reg_int("priority_limit", "Max size of \"priority\" messages (0 = use pre-set defaults; depends on number and type of devices available)", - 0, &max_tiny_msg_size, - REGINT_GE_ZERO, OPAL_INFO_LVL_5)); - opal_btl_usnic_module_template.max_tiny_msg_size = - (size_t) max_tiny_msg_size; - - CHECK(reg_int("eager_limit", "Eager send limit (0 = use pre-set defaults; depends on number and type of devices available)", + CHECK(reg_int("retrans_timeout", "Number of microseconds before retransmitting a frame", 5000, + &mca_btl_usnic_component.retrans_timeout, REGINT_GE_ONE, OPAL_INFO_LVL_5)); + + CHECK(reg_int( + "max_resends_per_iteration", + "Maximum number of frames to resend in a single iteration through usNIC component progress", + 16, &mca_btl_usnic_component.max_resends_per_iteration, REGINT_GE_ONE, OPAL_INFO_LVL_5)); + + CHECK(reg_int("ack_iteration_delay", + "Minimum number of times through usNIC \"progress\" function before checking to " + "see if standalone ACKs need to be sent", + 4, &mca_btl_usnic_component.ack_iteration_delay, REGINT_GE_ZERO, + OPAL_INFO_LVL_5)); + + CHECK(reg_int("priority_limit", + "Max size of \"priority\" messages (0 = use pre-set defaults; depends on number " + "and type of devices available)", + 0, &max_tiny_msg_size, REGINT_GE_ZERO, OPAL_INFO_LVL_5)); + opal_btl_usnic_module_template.max_tiny_msg_size = (size_t) max_tiny_msg_size; + + CHECK(reg_int("eager_limit", + "Eager send limit (0 = use pre-set defaults; depends on number and type of " + "devices available)", 0, &eager_limit, REGINT_GE_ZERO, OPAL_INFO_LVL_5)); opal_btl_usnic_module_template.super.btl_eager_limit = eager_limit; - CHECK(reg_int("rndv_eager_limit", "Eager rendezvous limit (0 = use pre-set defaults; depends on number and type of devices available)", + CHECK(reg_int("rndv_eager_limit", + "Eager rendezvous limit (0 = use pre-set defaults; depends on number and type of " + "devices available)", 0, &rndv_eager_limit, REGINT_GE_ZERO, OPAL_INFO_LVL_5)); - opal_btl_usnic_module_template.super.btl_rndv_eager_limit = - rndv_eager_limit; + opal_btl_usnic_module_template.super.btl_rndv_eager_limit = rndv_eager_limit; - CHECK(reg_int("pack_lazy_threshold", "Convertor packing on-the-fly threshold (-1 = always pack eagerly, 0 = always pack lazily, otherwise will pack on the fly if fragment size is > limit)", - USNIC_DFLT_PACK_LAZY_THRESHOLD, &pack_lazy_threshold, REGINT_NEG_ONE_OK, OPAL_INFO_LVL_5)); + CHECK(reg_int("pack_lazy_threshold", + "Convertor packing on-the-fly threshold (-1 = always pack eagerly, 0 = always " + "pack lazily, otherwise will pack on the fly if fragment size is > limit)", + USNIC_DFLT_PACK_LAZY_THRESHOLD, &pack_lazy_threshold, REGINT_NEG_ONE_OK, + OPAL_INFO_LVL_5)); mca_btl_usnic_component.pack_lazy_threshold = pack_lazy_threshold; - CHECK(reg_int("max_short_packets", "Number of abnormally-short packets received before outputting a warning (0 = never show the warning)", - 25, &max_short_packets, - REGINT_GE_ZERO, OPAL_INFO_LVL_5)); + CHECK(reg_int("max_short_packets", + "Number of abnormally-short packets received before outputting a warning (0 = " + "never show the warning)", + 25, &max_short_packets, REGINT_GE_ZERO, OPAL_INFO_LVL_5)); mca_btl_usnic_component.max_short_packets = max_short_packets; /* Default to bandwidth auto-detection */ @@ -288,39 +282,43 @@ int opal_btl_usnic_component_register(void) /* Show "cannot find route" warnings? */ mca_btl_usnic_component.show_route_failures = true; CHECK(reg_bool("show_route_failures", - "Whether to show a warning when route failures between MPI process peers are detected (default = 1, enabled; 0 = disabled)", + "Whether to show a warning when route failures between MPI process peers are " + "detected (default = 1, enabled; 0 = disabled)", mca_btl_usnic_component.show_route_failures, - &mca_btl_usnic_component.show_route_failures, - OPAL_INFO_LVL_3)); + &mca_btl_usnic_component.show_route_failures, OPAL_INFO_LVL_3)); /* Connectivity verification */ mca_btl_usnic_component.connectivity_enabled = true; CHECK(reg_bool("connectivity_check", - "Whether to enable the usNIC connectivity check upon first send (default = 1, enabled; 0 = disabled)", + "Whether to enable the usNIC connectivity check upon first send (default = 1, " + "enabled; 0 = disabled)", mca_btl_usnic_component.connectivity_enabled, - &mca_btl_usnic_component.connectivity_enabled, - OPAL_INFO_LVL_3)); + &mca_btl_usnic_component.connectivity_enabled, OPAL_INFO_LVL_3)); mca_btl_usnic_component.connectivity_ack_timeout = 250; - CHECK(reg_int("connectivity_ack_timeout", - "Timeout, in milliseconds, while waiting for an ACK while verification connectivity between usNIC interfaces. If 0, the connectivity check is disabled (must be >=0).", - mca_btl_usnic_component.connectivity_ack_timeout, - &mca_btl_usnic_component.connectivity_ack_timeout, - REGINT_GE_ZERO, OPAL_INFO_LVL_3)); + CHECK(reg_int( + "connectivity_ack_timeout", + "Timeout, in milliseconds, while waiting for an ACK while verification connectivity " + "between usNIC interfaces. If 0, the connectivity check is disabled (must be >=0).", + mca_btl_usnic_component.connectivity_ack_timeout, + &mca_btl_usnic_component.connectivity_ack_timeout, REGINT_GE_ZERO, OPAL_INFO_LVL_3)); mca_btl_usnic_component.connectivity_num_retries = 40; CHECK(reg_int("connectivity_error_num_retries", - "Number of times to retry usNIC connectivity verification before aborting the MPI job (must be >0).", + "Number of times to retry usNIC connectivity verification before aborting the " + "MPI job (must be >0).", mca_btl_usnic_component.connectivity_num_retries, - &mca_btl_usnic_component.connectivity_num_retries, - REGINT_GE_ONE, OPAL_INFO_LVL_3)); + &mca_btl_usnic_component.connectivity_num_retries, REGINT_GE_ONE, + OPAL_INFO_LVL_3)); mca_btl_usnic_component.connectivity_map_prefix = NULL; - CHECK(reg_string("connectivity_map", - "Write a per-process file containing the usNIC connectivity map. If this parameter is specified, it is the filename prefix emitted by each MPI process. The full filename emitted by each process is of the form: -....txt.", - mca_btl_usnic_component.connectivity_map_prefix, - &mca_btl_usnic_component.connectivity_map_prefix, - REGSTR_EMPTY_OK, OPAL_INFO_LVL_3)); + CHECK(reg_string( + "connectivity_map", + "Write a per-process file containing the usNIC connectivity map. If this parameter is " + "specified, it is the filename prefix emitted by each MPI process. The full filename " + "emitted by each process is of the form: -....txt.", + mca_btl_usnic_component.connectivity_map_prefix, + &mca_btl_usnic_component.connectivity_map_prefix, REGSTR_EMPTY_OK, OPAL_INFO_LVL_3)); return ret; } diff --git a/opal/mca/btl/usnic/btl_usnic_module.c b/opal/mca/btl/usnic/btl_usnic_module.c index e65d0093d12..7ae08e6fb67 100644 --- a/opal/mca/btl/usnic/btl_usnic_module.c +++ b/opal/mca/btl/usnic/btl_usnic_module.c @@ -27,59 +27,54 @@ #include "opal_config.h" #include -#include -#include #include +#include #include +#include -#include "opal_stdint.h" #include "opal/class/opal_bitmap.h" +#include "opal/datatype/opal_convertor.h" +#include "opal/mca/memchecker/base/base.h" #include "opal/prefetch.h" #include "opal/util/output.h" -#include "opal/datatype/opal_convertor.h" -#include "opal/util/show_help.h" #include "opal/util/printf.h" -#include "opal/mca/memchecker/base/base.h" +#include "opal/util/show_help.h" +#include "opal_stdint.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/btl_base_error.h" +#include "opal/mca/btl/btl.h" #include "opal/mca/mpool/base/base.h" #include "opal/mca/mpool/mpool.h" #include "opal/mca/rcache/base/base.h" #include "opal/mca/rcache/rcache.h" -#include "btl_usnic_compat.h" #include "btl_usnic.h" +#include "btl_usnic_ack.h" +#include "btl_usnic_compat.h" #include "btl_usnic_connectivity.h" -#include "btl_usnic_frag.h" -#include "btl_usnic_proc.h" #include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" +#include "btl_usnic_hwloc.h" #include "btl_usnic_module.h" -#include "btl_usnic_util.h" +#include "btl_usnic_proc.h" #include "btl_usnic_send.h" -#include "btl_usnic_ack.h" -#include "btl_usnic_hwloc.h" #include "btl_usnic_stats.h" +#include "btl_usnic_util.h" static void finalize_one_channel(opal_btl_usnic_module_t *module, struct opal_btl_usnic_channel_t *channel); -static int channel_addr2str(opal_btl_usnic_module_t *module, int channel, - char *str, size_t len_param) +static int channel_addr2str(opal_btl_usnic_module_t *module, int channel, char *str, + size_t len_param) { size_t len; len = len_param; - fi_av_straddr(module->av, module->mod_channels[channel].info->src_addr, - str, &len); + fi_av_straddr(module->av, module->mod_channels[channel].info->src_addr, str, &len); if (len > len_param) { - opal_show_help("help-mpi-btl-usnic.txt", - "libfabric API failed", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_av_straddr", __FILE__, __LINE__, - FI_ENODATA, + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, module->linux_device_name, "fi_av_straddr", + __FILE__, __LINE__, FI_ENODATA, "Failed to convert address to string: buffer too short"); return OPAL_ERR_OUT_OF_RESOURCE; @@ -88,19 +83,16 @@ static int channel_addr2str(opal_btl_usnic_module_t *module, int channel, return OPAL_SUCCESS; } - /* * Loop over a block of procs sent to us in add_procs and see if we * want to add a proc/endpoint for them. */ -static int add_procs_block_create_endpoints(opal_btl_usnic_module_t *module, - size_t block_offset, - size_t block_len, - opal_proc_t **procs, +static int add_procs_block_create_endpoints(opal_btl_usnic_module_t *module, size_t block_offset, + size_t block_len, opal_proc_t **procs, mca_btl_base_endpoint_t **endpoints) { int rc; - opal_proc_t* my_proc; + opal_proc_t *my_proc; size_t num_created = 0; char *errhost; @@ -112,16 +104,15 @@ static int add_procs_block_create_endpoints(opal_btl_usnic_module_t *module, /* Loop over a block in the procs we were given */ for (size_t i = block_offset; i < (block_offset + block_len); i++) { - struct opal_proc_t* opal_proc = procs[i]; - opal_btl_usnic_proc_t* usnic_proc; - mca_btl_base_endpoint_t* usnic_endpoint; + struct opal_proc_t *opal_proc = procs[i]; + opal_btl_usnic_proc_t *usnic_proc; + mca_btl_base_endpoint_t *usnic_endpoint; endpoints[i] = NULL; /* Do not create loopback usnic connections */ if (opal_proc == my_proc) { - opal_output_verbose(75, USNIC_OUT, - "btl:usnic:add_procs:%s: not connecting to self", + opal_output_verbose(75, USNIC_OUT, "btl:usnic:add_procs:%s: not connecting to self", module->linux_device_name); continue; } @@ -144,12 +135,13 @@ static int add_procs_block_create_endpoints(opal_btl_usnic_module_t *module, if (OPAL_ERR_UNREACH == rc) { /* If the peer doesn't have usnic modex info, then we just skip it */ - if (74 < opal_output_get_verbosity(USNIC_OUT)) { + if (74 < opal_output_get_verbosity(USNIC_OUT)) { errhost = opal_get_proc_hostname(opal_proc); - opal_output(0, "btl:usnic:add_procs:%s: peer %s on %s does not have usnic modex info; skipping", + opal_output(0, + "btl:usnic:add_procs:%s: peer %s on %s does not have usnic modex info; " + "skipping", module->linux_device_name, - usnic_compat_proc_name_print(&opal_proc->proc_name), - errhost); + usnic_compat_proc_name_print(&opal_proc->proc_name), errhost); free(errhost); } continue; @@ -160,15 +152,13 @@ static int add_procs_block_create_endpoints(opal_btl_usnic_module_t *module, /* Create the endpoint for this proc/module combination. If we cannot * reach this proc via this module, move on to the next proc. */ usnic_endpoint = NULL; - rc = opal_btl_usnic_create_endpoint(module, usnic_proc, - &usnic_endpoint); + rc = opal_btl_usnic_create_endpoint(module, usnic_proc, &usnic_endpoint); if (OPAL_SUCCESS != rc) { - if (4 < opal_output_get_verbosity(USNIC_OUT)) { + if (4 < opal_output_get_verbosity(USNIC_OUT)) { errhost = opal_get_proc_hostname(opal_proc); opal_output(0, "btl:usnic:add_procs:%s: unable to create endpoint to peer %s on %s", module->linux_device_name, - usnic_compat_proc_name_print(&opal_proc->proc_name), - errhost); + usnic_compat_proc_name_print(&opal_proc->proc_name), errhost); free(errhost); } OBJ_RELEASE(usnic_proc); @@ -179,43 +169,35 @@ static int add_procs_block_create_endpoints(opal_btl_usnic_module_t *module, opal_pointer_array_add(&module->all_procs, usnic_proc); char str[IPV4STRADDRLEN]; - struct opal_btl_usnic_modex_t *modex = - &usnic_endpoint->endpoint_remote_modex; - opal_btl_usnic_snprintf_ipv4_addr(str, sizeof(str), - modex->ipv4_addr, - modex->netmask); + struct opal_btl_usnic_modex_t *modex = &usnic_endpoint->endpoint_remote_modex; + opal_btl_usnic_snprintf_ipv4_addr(str, sizeof(str), modex->ipv4_addr, modex->netmask); char local_pri_addr[64] = {0}; - rc = channel_addr2str(module, USNIC_PRIORITY_CHANNEL, - local_pri_addr, sizeof(local_pri_addr)); + rc = channel_addr2str(module, USNIC_PRIORITY_CHANNEL, local_pri_addr, + sizeof(local_pri_addr)); if (OPAL_SUCCESS != rc) { OBJ_RELEASE(usnic_proc); continue; } char local_data_addr[64] = {0}; - rc = channel_addr2str(module, USNIC_DATA_CHANNEL, - local_data_addr, sizeof(local_data_addr)); + rc = channel_addr2str(module, USNIC_DATA_CHANNEL, local_data_addr, sizeof(local_data_addr)); if (OPAL_SUCCESS != rc) { OBJ_RELEASE(usnic_proc); continue; } opal_output_verbose(5, USNIC_OUT, - "btl:usnic:add_procs:%s: new usnic peer endpoint: pri=%s:%d, data=%s:%d (local: pri=%s, data=%s)", - module->linux_device_name, - str, modex->ports[USNIC_PRIORITY_CHANNEL], - str, modex->ports[USNIC_DATA_CHANNEL], - local_pri_addr, - local_data_addr); + "btl:usnic:add_procs:%s: new usnic peer endpoint: pri=%s:%d, " + "data=%s:%d (local: pri=%s, data=%s)", + module->linux_device_name, str, modex->ports[USNIC_PRIORITY_CHANNEL], + str, modex->ports[USNIC_DATA_CHANNEL], local_pri_addr, local_data_addr); endpoints[i] = usnic_endpoint; ++num_created; } - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: made %" PRIsize_t " endpoints", - num_created); + opal_output_verbose(5, USNIC_OUT, "btl:usnic: made %" PRIsize_t " endpoints", num_created); return OPAL_SUCCESS; } @@ -240,30 +222,21 @@ static void add_procs_warn_unreachable(opal_btl_usnic_module_t *module, endpoint->endpoint_remote_modex.ipv4_addr, endpoint->endpoint_remote_modex.netmask); - opal_output_verbose(15, USNIC_OUT, - "btl:usnic: %s (which is %s) couldn't reach peer %s", - module->linux_device_name, - module->if_ipv4_addr_str, - remote); + opal_output_verbose(15, USNIC_OUT, "btl:usnic: %s (which is %s) couldn't reach peer %s", + module->linux_device_name, module->if_ipv4_addr_str, remote); errhost = opal_get_proc_hostname(endpoint->endpoint_proc->proc_opal); - opal_show_help("help-mpi-btl-usnic.txt", "unreachable peer IP", - true, - opal_process_info.nodename, - module->if_ipv4_addr_str, - module->linux_device_name, - errhost, - remote); + opal_show_help("help-mpi-btl-usnic.txt", "unreachable peer IP", true, + opal_process_info.nodename, module->if_ipv4_addr_str, module->linux_device_name, + errhost, remote); free(errhost); } /* A bunch of calls to fi_av_insert() were previously * invoked. Go reap them all. */ -static int -add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, - size_t block_offset, - size_t block_len, - struct mca_btl_base_endpoint_t **endpoints) +static int add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, size_t block_offset, + size_t block_len, + struct mca_btl_base_endpoint_t **endpoints) { int ret = OPAL_SUCCESS; int num_left; @@ -319,8 +292,7 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, that we couldn't find a route to that peer (e.g., the networking is hosed between us). So just mark that we can't reach this peer, and print a pretty warning. */ - if (EADDRNOTAVAIL == err_entry.err || - EHOSTUNREACH == err_entry.err) { + if (EADDRNOTAVAIL == err_entry.err || EHOSTUNREACH == err_entry.err) { /* Note that endpoint was passed in a context in USNIC_NUM_CHANNELS fi_av_insert() calls. @@ -333,8 +305,7 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, the *first* time it is reported. */ for (i = block_offset; i < (block_offset + block_len); ++i) { if (endpoints[i] == context->endpoint) { - add_procs_warn_unreachable(module, - context->endpoint); + add_procs_warn_unreachable(module, context->endpoint); OBJ_RELEASE(context->endpoint); endpoints[i] = NULL; break; @@ -346,13 +317,9 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, /* Got some other kind of error -- give up on this interface. */ else { - opal_show_help("help-mpi-btl-usnic.txt", - "libfabric API failed", - true, - opal_process_info.nodename, - module->linux_device_name, - "async insertion result", __FILE__, __LINE__, - err_entry.err, + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, module->linux_device_name, + "async insertion result", __FILE__, __LINE__, err_entry.err, "Failed to insert address to AV"); ret = OPAL_ERR_OUT_OF_RESOURCE; error_occurred = true; @@ -370,13 +337,9 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, badly, which means something has gone tremendously wrong. Probably the only safe thing to do here is exit. */ - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_eq_readerr()", __FILE__, __LINE__, - ret, + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "fi_eq_readerr()", __FILE__, __LINE__, ret, "Returned != sizeof(err_entry)"); ret = OPAL_ERR_OUT_OF_RESOURCE; error_occurred = true; @@ -391,14 +354,9 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, Given that we're potentially not even all the way through MPI_INIT yet, the only sane thing to do here is exit. */ - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_eq_sread()", __FILE__, __LINE__, - ret, - "Returned != (sizeof(entry) or -FI_EAVAIL)"); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "fi_eq_sread()", + __FILE__, __LINE__, ret, "Returned != (sizeof(entry) or -FI_EAVAIL)"); ret = OPAL_ERR_OUT_OF_RESOURCE; error_occurred = true; @@ -422,8 +380,7 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, happy = false; } else { for (channel = 0; channel < USNIC_NUM_CHANNELS; ++channel) { - if (FI_ADDR_NOTAVAIL == - endpoints[i]->endpoint_remote_addrs[channel]) { + if (FI_ADDR_NOTAVAIL == endpoints[i]->endpoint_remote_addrs[channel]) { happy = false; break; } @@ -441,8 +398,7 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, /* All done */ opal_output_verbose(5, USNIC_OUT, - "btl:usnic: created destinations for %" PRIsize_t - " endpoints", + "btl:usnic: created destinations for %" PRIsize_t " endpoints", num_endpoints_created); return ret; } @@ -450,10 +406,9 @@ add_procs_block_reap_fi_av_inserts(opal_btl_usnic_module_t *module, /* * Create endpoints for the procs we were given in add_procs. */ -static int add_procs_create_endpoints(struct opal_btl_usnic_module_t* module, - size_t nprocs, +static int add_procs_create_endpoints(struct opal_btl_usnic_module_t *module, size_t nprocs, struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** endpoints) + struct mca_btl_base_endpoint_t **endpoints) { /* We need to ensure that we don't overrun the libfabric AV EQ. Divide up all the peer address resolutions we need to do into a @@ -464,11 +419,8 @@ static int add_procs_create_endpoints(struct opal_btl_usnic_module_t* module, /* Leave a few empty slots in the AV EQ, just for good measure */ if (module->av_eq_size < 8) { - opal_show_help("help-mpi-btl-usnic.txt", "fi_av_eq too small", - true, - opal_process_info.nodename, - module->av_eq_size, - 8); + opal_show_help("help-mpi-btl-usnic.txt", "fi_av_eq too small", true, + opal_process_info.nodename, module->av_eq_size, 8); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -497,9 +449,7 @@ static int add_procs_create_endpoints(struct opal_btl_usnic_module_t* module, /* First, create endpoints (and procs, if they're not already created) for the usnic-reachable procs we were given. */ - rc = add_procs_block_create_endpoints(module, - block_offset, block_len, - procs, endpoints); + rc = add_procs_block_create_endpoints(module, block_offset, block_len, procs, endpoints); if (OPAL_SUCCESS != rc) { return rc; } @@ -509,9 +459,7 @@ static int add_procs_create_endpoints(struct opal_btl_usnic_module_t* module, those. This will be the final determination of whether we can use the endpoint or not because we'll find out if each endpoint is reachable or not. */ - rc = add_procs_block_reap_fi_av_inserts(module, - block_offset, block_len, - endpoints); + rc = add_procs_block_reap_fi_av_inserts(module, block_offset, block_len, endpoints); if (OPAL_SUCCESS != rc) { return rc; } @@ -537,13 +485,11 @@ static int add_procs_create_endpoints(struct opal_btl_usnic_module_t* module, * peers (i.e., we should just mark those peers as unreachable and not * add a proc or endpoint for them). */ -static int usnic_add_procs(struct mca_btl_base_module_t* base_module, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t** endpoints, - opal_bitmap_t* reachable) +static int usnic_add_procs(struct mca_btl_base_module_t *base_module, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **endpoints, + opal_bitmap_t *reachable) { - opal_btl_usnic_module_t* module = (opal_btl_usnic_module_t*) base_module; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) base_module; int rc; /* Go create the endpoints (including all relevant address @@ -559,8 +505,7 @@ static int usnic_add_procs(struct mca_btl_base_module_t* base_module, if (NULL != endpoints[i]) { bool happy = true; for (int channel = 0; channel < USNIC_NUM_CHANNELS; ++channel) { - if (FI_ADDR_NOTAVAIL == - endpoints[i]->endpoint_remote_addrs[channel]) { + if (FI_ADDR_NOTAVAIL == endpoints[i]->endpoint_remote_addrs[channel]) { happy = false; break; } @@ -581,14 +526,13 @@ static int usnic_add_procs(struct mca_btl_base_module_t* base_module, call the function to output the map. */ static int num_times_add_procs_called = 0; ++num_times_add_procs_called; - if (0 == (num_times_add_procs_called % - mca_btl_usnic_component.num_modules)) { + if (0 == (num_times_add_procs_called % mca_btl_usnic_component.num_modules)) { opal_btl_usnic_connectivity_map(); } return OPAL_SUCCESS; - fail: +fail: /* If we get here, it means something went terribly wrong. Scorch the earth: destroy all endpoints and say that nothing was reachable. */ @@ -608,21 +552,18 @@ static int usnic_add_procs(struct mca_btl_base_module_t* base_module, * multiple times to remove each proc. The OBJ reference counts * will make all the details work out. */ -static int usnic_del_procs(struct mca_btl_base_module_t *base_module, - size_t nprocs, - struct opal_proc_t **procs, - struct mca_btl_base_endpoint_t **peers) +static int usnic_del_procs(struct mca_btl_base_module_t *base_module, size_t nprocs, + struct opal_proc_t **procs, struct mca_btl_base_endpoint_t **peers) { size_t i, j; opal_btl_usnic_module_t *module; opal_btl_usnic_endpoint_t *endpoint; int index; - module = (struct opal_btl_usnic_module_t *)base_module; + module = (struct opal_btl_usnic_module_t *) base_module; for (i = 0; i < nprocs; i++) { - opal_btl_usnic_proc_t* proc = - opal_btl_usnic_proc_lookup_ompi(procs[i]); + opal_btl_usnic_proc_t *proc = opal_btl_usnic_proc_lookup_ompi(procs[i]); if (NULL != proc) { /* find endpoint for this module */ @@ -645,17 +586,15 @@ static int usnic_del_procs(struct mca_btl_base_module_t *base_module, /* We're all done with this endpoint */ OBJ_RELEASE(endpoint); - break; /* done once we found match */ + break; /* done once we found match */ } } /* remove proc from this module, and decrement its refcount */ for (index = 0; index < module->all_procs.size; ++index) { - if (opal_pointer_array_get_item(&module->all_procs, index) == - proc) { + if (opal_pointer_array_get_item(&module->all_procs, index) == proc) { OBJ_RELEASE(proc); - opal_pointer_array_set_item(&module->all_procs, index, - NULL); + opal_pointer_array_set_item(&module->all_procs, index, NULL); break; } } @@ -665,14 +604,13 @@ static int usnic_del_procs(struct mca_btl_base_module_t *base_module, return OPAL_SUCCESS; } - /* * Let the PML register a callback function with me */ -static int usnic_register_pml_err_cb(struct mca_btl_base_module_t* btl, +static int usnic_register_pml_err_cb(struct mca_btl_base_module_t *btl, mca_btl_base_module_error_cb_fn_t cbfunc) { - opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t*) btl; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) btl; module->pml_error_callback = cbfunc; @@ -686,18 +624,14 @@ static int usnic_register_pml_err_cb(struct mca_btl_base_module_t* btl, * alloc. * --> Contraction in the btl.h documentation. */ -static mca_btl_base_descriptor_t* -usnic_alloc(struct mca_btl_base_module_t* btl, - struct mca_btl_base_endpoint_t* endpoint, - uint8_t order, - size_t size, - uint32_t flags) +static mca_btl_base_descriptor_t *usnic_alloc(struct mca_btl_base_module_t *btl, + struct mca_btl_base_endpoint_t *endpoint, + uint8_t order, size_t size, uint32_t flags) { opal_btl_usnic_send_frag_t *frag; - opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t*) btl; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) btl; mca_btl_base_descriptor_t *desc; - /* small is easy, just allocate a small segment */ if (OPAL_LIKELY(size <= module->max_frag_payload)) { opal_btl_usnic_small_send_frag_t *sfrag; @@ -708,10 +642,10 @@ usnic_alloc(struct mca_btl_base_module_t* btl, } frag = &sfrag->ssf_base; - /* between MTU and eager limit, we need to allocate a buffer - * which can hold the data. We will allocate a - * large fragment, and attach the buffer to it. - */ + /* between MTU and eager limit, we need to allocate a buffer + * which can hold the data. We will allocate a + * large fragment, and attach the buffer to it. + */ } else { opal_btl_usnic_large_send_frag_t *lfrag; @@ -734,17 +668,16 @@ usnic_alloc(struct mca_btl_base_module_t* btl, } /* pointer to buffer for caller */ - frag->sf_base.uf_base.USNIC_SEND_LOCAL[0].seg_addr.pval = - lfrag->lsf_buffer; + frag->sf_base.uf_base.USNIC_SEND_LOCAL[0].seg_addr.pval = lfrag->lsf_buffer; - MSGDEBUG1_OUT("usnic_alloc: packing frag %p on the fly", (void *)frag); + MSGDEBUG1_OUT("usnic_alloc: packing frag %p on the fly", (void *) frag); lfrag->lsf_pack_on_the_fly = true; } #if MSGDEBUG2 - opal_output(0, "usnic_alloc: %s frag=%p, size=%d, flags=0x%x\n", - (size <= module->max_frag_payload)?"small":"large", - (void *)frag, (int)size, flags); + opal_output(0, "usnic_alloc: %s frag=%p, size=%d, flags=0x%x\n", + (size <= module->max_frag_payload) ? "small" : "large", (void *) frag, (int) size, + flags); #endif /* set endpoint */ @@ -759,28 +692,24 @@ usnic_alloc(struct mca_btl_base_module_t* btl, return desc; } - /** * Return an allocated fragment * * Return the send fragment to the appropriate list */ -static int usnic_free(struct mca_btl_base_module_t* btl, - mca_btl_base_descriptor_t* des) +static int usnic_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des) { - opal_btl_usnic_frag_t* frag = (opal_btl_usnic_frag_t*)des; + opal_btl_usnic_frag_t *frag = (opal_btl_usnic_frag_t *) des; #if MSGDEBUG2 - opal_output(0, "usnic_free: %p (%s)\n", (void*)frag, - usnic_frag_type(frag->uf_type)); + opal_output(0, "usnic_free: %p (%s)\n", (void *) frag, usnic_frag_type(frag->uf_type)); #endif /* calling free routine gives us ownership - we need to make sure * the flag is set for lower layers. */ frag->uf_base.des_flags |= MCA_BTL_DES_FLAGS_BTL_OWNERSHIP; - opal_btl_usnic_frag_return_cond((struct opal_btl_usnic_module_t *)btl, - frag); + opal_btl_usnic_frag_return_cond((struct opal_btl_usnic_module_t *) btl, frag); return OPAL_SUCCESS; } @@ -791,11 +720,9 @@ static int usnic_free(struct mca_btl_base_module_t* btl, * the convertor contained in the frag. * * The frag's bookkeeping data will be updated appropriately. */ -static -opal_btl_usnic_chunk_segment_t * -pack_chunk_seg_from_frag( - struct opal_btl_usnic_module_t* module, - opal_btl_usnic_large_send_frag_t *lfrag) +static opal_btl_usnic_chunk_segment_t * +pack_chunk_seg_from_frag(struct opal_btl_usnic_module_t *module, + opal_btl_usnic_large_send_frag_t *lfrag) { opal_btl_usnic_chunk_segment_t *seg; uint8_t *copyptr; @@ -812,8 +739,7 @@ pack_chunk_seg_from_frag( /* TODO look at ways to deal with this case more gracefully, possibly as * part of capping the overall BTL memory consumption. Watch out for * possible MPI-layer deadlock. */ - opal_btl_usnic_util_abort("chunk segment allocation error", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("chunk segment allocation error", __FILE__, __LINE__); } seg_space = module->max_chunk_payload; @@ -822,9 +748,7 @@ pack_chunk_seg_from_frag( /* Keep copying in as long as we have space, there is data to be copied, and * we aren't using a convertor (SG[1] will be NULL if we have a convertor). */ - while (seg_space > 0 && - lfrag->lsf_pack_bytes_left > 0 && - NULL != lfrag->lsf_cur_ptr) { + while (seg_space > 0 && lfrag->lsf_pack_bytes_left > 0 && NULL != lfrag->lsf_cur_ptr) { if (seg_space > lfrag->lsf_bytes_left_in_sge) { copylen = lfrag->lsf_bytes_left_in_sge; } else { @@ -840,10 +764,8 @@ pack_chunk_seg_from_frag( lfrag->lsf_cur_ptr += copylen; } else { ++lfrag->lsf_cur_sge; - lfrag->lsf_cur_ptr = - lfrag->lsf_des_src[lfrag->lsf_cur_sge].seg_addr.pval; - lfrag->lsf_bytes_left_in_sge = - lfrag->lsf_des_src[lfrag->lsf_cur_sge].seg_len; + lfrag->lsf_cur_ptr = lfrag->lsf_des_src[lfrag->lsf_cur_sge].seg_addr.pval; + lfrag->lsf_bytes_left_in_sge = lfrag->lsf_des_src[lfrag->lsf_cur_sge].seg_len; } } @@ -856,16 +778,14 @@ pack_chunk_seg_from_frag( if (copylen > seg_space) { copylen = seg_space; } - usnic_convertor_pack_simple(&lfrag->lsf_base.sf_convertor, copyptr, - copylen, &max_data); + usnic_convertor_pack_simple(&lfrag->lsf_base.sf_convertor, copyptr, copylen, &max_data); seg_space -= max_data; lfrag->lsf_bytes_left_in_sge -= max_data; lfrag->lsf_pack_bytes_left -= max_data; } - MSGDEBUG1_OUT("%s: packed seg=%p, frag=%p, payload=%zd\n", - __func__, (void *)seg, (void *)lfrag, - (module->max_chunk_payload - seg_space)); + MSGDEBUG1_OUT("%s: packed seg=%p, frag=%p, payload=%zd\n", __func__, (void *) seg, + (void *) lfrag, (module->max_chunk_payload - seg_space)); assert(lfrag->lsf_cur_sge <= 2); assert(seg_space < module->max_chunk_payload); /* must make progress */ @@ -876,9 +796,9 @@ pack_chunk_seg_from_frag( return seg; } -static int usnic_finalize(struct mca_btl_base_module_t* btl) +static int usnic_finalize(struct mca_btl_base_module_t *btl) { - opal_btl_usnic_module_t* module = (opal_btl_usnic_module_t*)btl; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) btl; if (module->device_async_event_active) { opal_event_del(&(module->device_async_event)); @@ -887,10 +807,8 @@ static int usnic_finalize(struct mca_btl_base_module_t* btl) opal_btl_usnic_connectivity_unlisten(module); - finalize_one_channel(module, - &module->mod_channels[USNIC_DATA_CHANNEL]); - finalize_one_channel(module, - &module->mod_channels[USNIC_PRIORITY_CHANNEL]); + finalize_one_channel(module, &module->mod_channels[USNIC_DATA_CHANNEL]); + finalize_one_channel(module, &module->mod_channels[USNIC_PRIORITY_CHANNEL]); /* Shutdown the stats on this module */ opal_btl_usnic_stats_finalize(module); @@ -952,15 +870,12 @@ static int usnic_finalize(struct mca_btl_base_module_t* btl) return OPAL_SUCCESS; } -static inline unsigned -get_send_credits(struct opal_btl_usnic_channel_t *chan) +static inline unsigned get_send_credits(struct opal_btl_usnic_channel_t *chan) { return chan->credits; } -static void -usnic_do_resends( - opal_btl_usnic_module_t *module) +static void usnic_do_resends(opal_btl_usnic_module_t *module) { opal_btl_usnic_send_segment_t *sseg; opal_btl_usnic_endpoint_t *endpoint; @@ -970,15 +885,15 @@ usnic_do_resends( data_channel = &module->mod_channels[USNIC_DATA_CHANNEL]; count = mca_btl_usnic_component.max_resends_per_iteration; - while (count > 0 && (get_send_credits(data_channel) > 1) && - !opal_list_is_empty(&module->pending_resend_segs)) { + while (count > 0 && (get_send_credits(data_channel) > 1) + && !opal_list_is_empty(&module->pending_resend_segs)) { /* * If a segment is on the re-send list, it will not * be in the retransmit hotel. Post the segment, then check it in. */ - sseg = (opal_btl_usnic_send_segment_t *) - opal_list_remove_first(&module->pending_resend_segs); + sseg = (opal_btl_usnic_send_segment_t *) opal_list_remove_first( + &module->pending_resend_segs); endpoint = sseg->ss_parent_frag->sf_endpoint; /* clobber any stale piggy-backed ACK */ @@ -1006,8 +921,7 @@ usnic_do_resends( } /* restart the retrans timer */ - ret = opal_hotel_checkin(&endpoint->endpoint_hotel, - sseg, &sseg->ss_hotel_room); + ret = opal_hotel_checkin(&endpoint->endpoint_hotel, sseg, &sseg->ss_hotel_room); if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) { opal_btl_usnic_util_abort("hotel checkin failed\n", __FILE__, __LINE__); } @@ -1025,11 +939,9 @@ usnic_do_resends( * ASSUMES THAT THE CALLER HAS ALREADY CHECKED TO SEE IF WE HAVE * A SEND CREDIT! */ -static void -usnic_handle_large_send( - opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_frag_t *frag) +static void usnic_handle_large_send(opal_btl_usnic_module_t *module, + opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_frag_t *frag) { opal_btl_usnic_large_send_frag_t *lfrag; opal_btl_usnic_btl_chunk_header_t *chp; @@ -1037,7 +949,7 @@ usnic_handle_large_send( size_t payload_len; assert(frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_LARGE_SEND); - lfrag = (opal_btl_usnic_large_send_frag_t *)frag; + lfrag = (opal_btl_usnic_large_send_frag_t *) frag; if (lfrag->lsf_cur_offset == 0) { /* assign a fragment ID */ do { @@ -1052,8 +964,7 @@ usnic_handle_large_send( sseg = pack_chunk_seg_from_frag(module, lfrag); } else { /* data was pre-packed in prepare_src */ - sseg = (opal_btl_usnic_send_segment_t *) - opal_list_remove_first(&lfrag->lsf_seg_chain); + sseg = (opal_btl_usnic_send_segment_t *) opal_list_remove_first(&lfrag->lsf_seg_chain); } assert(NULL != sseg); @@ -1085,9 +996,8 @@ usnic_handle_large_send( lfrag->lsf_cur_offset += payload_len; #if MSGDEBUG1 - opal_output(0, "%s: payload_len=%zd, bytes_left=%zd on_the_fly=%s\n", - __func__, payload_len, lfrag->lsf_bytes_left, - lfrag->lsf_pack_on_the_fly?"true":"false"); + opal_output(0, "%s: payload_len=%zd, bytes_left=%zd on_the_fly=%s\n", __func__, payload_len, + lfrag->lsf_bytes_left, lfrag->lsf_pack_on_the_fly ? "true" : "false"); #endif /* done with fragment? */ if (lfrag->lsf_bytes_left == 0) { @@ -1096,14 +1006,13 @@ usnic_handle_large_send( * decide to put it on some other list in the callback */ opal_list_remove_item(&endpoint->endpoint_frag_send_queue, - &frag->sf_base.uf_base.super.super); + &frag->sf_base.uf_base.super.super); /* only callback now if this was not a PUT and we own the fragment, * otherwise we need to wait until last byte is ACKed */ - if (frag->sf_base.uf_remote_seg[0].seg_addr.pval == NULL && - (frag->sf_base.uf_base.des_flags & - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { + if (frag->sf_base.uf_remote_seg[0].seg_addr.pval == NULL + && (frag->sf_base.uf_base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { OPAL_BTL_USNIC_DO_SEND_FRAG_CB(module, frag, "large"); } @@ -1115,9 +1024,7 @@ usnic_handle_large_send( * Should only ever be called from usnic_component_progress() to * avoid re-entrancy issues. */ -void -opal_btl_usnic_module_progress_sends( - opal_btl_usnic_module_t *module) +void opal_btl_usnic_module_progress_sends(opal_btl_usnic_module_t *module) { opal_btl_usnic_send_frag_t *frag; opal_btl_usnic_send_segment_t *sseg; @@ -1145,8 +1052,8 @@ opal_btl_usnic_module_progress_sends( /* * Keep sending as long as there are WQEs and something to do */ - while ((get_send_credits(data_channel) > 1) && - !opal_list_is_empty(&module->endpoints_with_sends)) { + while ((get_send_credits(data_channel) > 1) + && !opal_list_is_empty(&module->endpoints_with_sends)) { opal_btl_usnic_small_send_frag_t *sfrag; size_t payload_len; @@ -1157,10 +1064,9 @@ opal_btl_usnic_module_progress_sends( * credits. */ - endpoint = (opal_btl_usnic_endpoint_t *) - opal_list_get_first(&module->endpoints_with_sends); - frag = (opal_btl_usnic_send_frag_t *) - opal_list_get_first(&endpoint->endpoint_frag_send_queue); + endpoint = (opal_btl_usnic_endpoint_t *) opal_list_get_first(&module->endpoints_with_sends); + frag = (opal_btl_usnic_send_frag_t *) opal_list_get_first( + &endpoint->endpoint_frag_send_queue); /* * small send? (fragment fits in one segment) @@ -1172,9 +1078,9 @@ opal_btl_usnic_module_progress_sends( * decide to put it on some other list in the callback */ opal_list_remove_item(&endpoint->endpoint_frag_send_queue, - &frag->sf_base.uf_base.super.super); + &frag->sf_base.uf_base.super.super); - sfrag = (opal_btl_usnic_small_send_frag_t *)frag; + sfrag = (opal_btl_usnic_small_send_frag_t *) frag; sseg = &sfrag->ssf_segment; /* get payload len from segment */ @@ -1182,12 +1088,11 @@ opal_btl_usnic_module_progress_sends( sseg->ss_base.us_btl_header->payload_len = payload_len; #if MSGDEBUG1 - opal_output(0, "progress send small, frag=%p, ptr=%p, payload=%zd, len=%"PRIu32", ep=%p, tag=%d\n", - (void *)frag, - (void *)sseg->ss_ptr, payload_len, - sseg->ss_len, - (void *)frag->sf_endpoint, - sseg->ss_base.us_btl_header->tag); + opal_output(0, + "progress send small, frag=%p, ptr=%p, payload=%zd, len=%" PRIu32 + ", ep=%p, tag=%d\n", + (void *) frag, (void *) sseg->ss_ptr, payload_len, sseg->ss_len, + (void *) frag->sf_endpoint, sseg->ss_base.us_btl_header->tag); #endif /* post the send (we have a send credit available) */ @@ -1201,16 +1106,14 @@ opal_btl_usnic_module_progress_sends( * because we are not done with the segment inside. * (ACK not received yet) */ - if ((frag->sf_base.uf_base.des_flags & - (MCA_BTL_DES_SEND_ALWAYS_CALLBACK | - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) == - (MCA_BTL_DES_SEND_ALWAYS_CALLBACK | - MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { + if ((frag->sf_base.uf_base.des_flags + & (MCA_BTL_DES_SEND_ALWAYS_CALLBACK | MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) + == (MCA_BTL_DES_SEND_ALWAYS_CALLBACK | MCA_BTL_DES_FLAGS_BTL_OWNERSHIP)) { OPAL_BTL_USNIC_DO_SEND_FRAG_CB(module, frag, "small"); } } - /* Large sends... */ + /* Large sends... */ } else { usnic_handle_large_send(module, endpoint, frag); } @@ -1218,12 +1121,10 @@ opal_btl_usnic_module_progress_sends( /* If no more sends or endpoint send window is closed, * or no more send credits, remove from send list */ - if (opal_list_is_empty(&endpoint->endpoint_frag_send_queue) || - endpoint->endpoint_send_credits <= 0 || - !WINDOW_OPEN(endpoint)) { + if (opal_list_is_empty(&endpoint->endpoint_frag_send_queue) + || endpoint->endpoint_send_credits <= 0 || !WINDOW_OPEN(endpoint)) { - opal_list_remove_item(&module->endpoints_with_sends, - &endpoint->super); + opal_list_remove_item(&module->endpoints_with_sends, &endpoint->super); endpoint->endpoint_ready_to_send = false; } } @@ -1239,8 +1140,7 @@ opal_btl_usnic_module_progress_sends( next_endpoint = opal_btl_usnic_get_next_endpoint_needing_ack(endpoint); /* Is it time to send ACK? */ - if (endpoint->endpoint_acktime == 0 || - endpoint->endpoint_acktime <= get_ticks()) { + if (endpoint->endpoint_acktime == 0 || endpoint->endpoint_acktime <= get_ticks()) { if (OPAL_LIKELY(opal_btl_usnic_ack_send(module, endpoint) == OPAL_SUCCESS)) { opal_btl_usnic_remove_from_endpoints_needing_ack(endpoint); } else { @@ -1273,12 +1173,9 @@ opal_btl_usnic_module_progress_sends( * until the last of the data has been copied out by routines called * from opal_btl_usnic_progress_sends() */ -static int -usnic_send( - struct mca_btl_base_module_t* base_module, - struct mca_btl_base_endpoint_t* base_endpoint, - struct mca_btl_base_descriptor_t* descriptor, - mca_btl_base_tag_t tag) +static int usnic_send(struct mca_btl_base_module_t *base_module, + struct mca_btl_base_endpoint_t *base_endpoint, + struct mca_btl_base_descriptor_t *descriptor, mca_btl_base_tag_t tag) { int rc; opal_btl_usnic_send_frag_t *frag; @@ -1288,30 +1185,30 @@ usnic_send( opal_btl_usnic_send_segment_t *sseg; OPAL_THREAD_LOCK(&btl_usnic_lock); - endpoint = (opal_btl_usnic_endpoint_t *)base_endpoint; - module = (opal_btl_usnic_module_t *)base_module; - frag = (opal_btl_usnic_send_frag_t*) descriptor; + endpoint = (opal_btl_usnic_endpoint_t *) base_endpoint; + module = (opal_btl_usnic_module_t *) base_module; + frag = (opal_btl_usnic_send_frag_t *) descriptor; assert(frag->sf_endpoint == endpoint); - frag->sf_base.uf_remote_seg[0].seg_addr.pval = NULL; /* not a PUT */ + frag->sf_base.uf_remote_seg[0].seg_addr.pval = NULL; /* not a PUT */ opal_btl_usnic_compute_sf_size(frag); frag->sf_ack_bytes_left = frag->sf_size; #if MSGDEBUG2 - opal_output(0, "usnic_send: frag=%p, endpoint=%p, tag=%d, sf_size=%d\n", - (void *)frag, (void *)endpoint, - tag, (int)frag->sf_size); -#if MSGDEBUG1 - { unsigned i; + opal_output(0, "usnic_send: frag=%p, endpoint=%p, tag=%d, sf_size=%d\n", (void *) frag, + (void *) endpoint, tag, (int) frag->sf_size); +# if MSGDEBUG1 + { + unsigned i; opal_output(0, " descriptor->des_flags=0x%x\n", descriptor->des_flags); - for (i=0; iUSNIC_SEND_LOCAL_COUNT; ++i) { + for (i = 0; i < descriptor->USNIC_SEND_LOCAL_COUNT; ++i) { opal_output(0, " %d: ptr:%p len:%d\n", i, - descriptor->USNIC_SEND_LOCAL[i].seg_addr.pval, - descriptor->USNIC_SEND_LOCAL[i].seg_len); + descriptor->USNIC_SEND_LOCAL[i].seg_addr.pval, + descriptor->USNIC_SEND_LOCAL[i].seg_len); } } -#endif +# endif #endif /* @@ -1319,31 +1216,28 @@ usnic_send( * and we have enough send WQEs, * then inline and fastpath it */ - if (frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_SMALL_SEND && - frag->sf_ack_bytes_left < module->max_tiny_payload && - WINDOW_OPEN(endpoint) && - (get_send_credits(&module->mod_channels[USNIC_DATA_CHANNEL]) >= - module->mod_channels[USNIC_DATA_CHANNEL].fastsend_wqe_thresh)) { + if (frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_SMALL_SEND + && frag->sf_ack_bytes_left < module->max_tiny_payload && WINDOW_OPEN(endpoint) + && (get_send_credits(&module->mod_channels[USNIC_DATA_CHANNEL]) + >= module->mod_channels[USNIC_DATA_CHANNEL].fastsend_wqe_thresh)) { size_t payload_len; - sfrag = (opal_btl_usnic_small_send_frag_t *)frag; + sfrag = (opal_btl_usnic_small_send_frag_t *) frag; sseg = &sfrag->ssf_segment; payload_len = frag->sf_ack_bytes_left; sseg->ss_base.us_btl_header->payload_len = payload_len; - /* copy the 2nd SGE into the segment */ if (frag->sf_base.uf_base.USNIC_SEND_LOCAL_COUNT > 1) { - memcpy(((char *)(intptr_t)frag->sf_base.uf_local_seg[0].seg_addr.lval + - frag->sf_base.uf_local_seg[0].seg_len), - frag->sf_base.uf_local_seg[1].seg_addr.pval, - frag->sf_base.uf_local_seg[1].seg_len); + memcpy(((char *) (intptr_t) frag->sf_base.uf_local_seg[0].seg_addr.lval + + frag->sf_base.uf_local_seg[0].seg_len), + frag->sf_base.uf_local_seg[1].seg_addr.pval, + frag->sf_base.uf_local_seg[1].seg_len); /* update 1st segment length */ frag->sf_base.uf_base.USNIC_SEND_LOCAL_COUNT = 1; - frag->sf_base.uf_local_seg[0].seg_len += - frag->sf_base.uf_local_seg[1].seg_len; + frag->sf_base.uf_local_seg[0].seg_len += frag->sf_base.uf_local_seg[1].seg_len; } /* assign length */ @@ -1352,7 +1246,7 @@ usnic_send( sseg->ss_channel = USNIC_DATA_CHANNEL; sseg->ss_base.us_btl_header->tag = tag; #if MSGDEBUG1 - opal_output(0, "INLINE send, sseg=%p", (void *)sseg); + opal_output(0, "INLINE send, sseg=%p", (void *) sseg); #endif /* post the segment now (we have a send credit available) */ @@ -1369,14 +1263,14 @@ usnic_send( rc = 0; } else { #if MSGDEBUG1 - opal_output(0, "skipping callback for frag %p, returning 1\n", (void *)frag); + opal_output(0, "skipping callback for frag %p, returning 1\n", (void *) frag); #endif rc = 1; - ++module->stats.pml_send_callbacks; /* returning "1" is an implicit CB */ + ++module->stats.pml_send_callbacks; /* returning "1" is an implicit CB */ } } else { #if MSGDEBUG1 - opal_output(0, "don't own descriptor, defer callback for frag %p\n", (void *)frag); + opal_output(0, "don't own descriptor, defer callback for frag %p\n", (void *) frag); #endif descriptor->des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK; rc = 0; @@ -1420,15 +1314,14 @@ static int usnic_sendi(struct mca_btl_base_module_t* btl, } #endif - /* * RDMA Memory Pool (de)register callbacks */ -static int usnic_reg_mr(void* reg_data, void* base, size_t size, - mca_rcache_base_registration_t* reg) +static int usnic_reg_mr(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg) { - opal_btl_usnic_module_t* mod = (opal_btl_usnic_module_t*)reg_data; - opal_btl_usnic_reg_t* ur = (opal_btl_usnic_reg_t*)reg; + opal_btl_usnic_module_t *mod = (opal_btl_usnic_module_t *) reg_data; + opal_btl_usnic_reg_t *ur = (opal_btl_usnic_reg_t *) reg; int rc; rc = fi_mr_reg(mod->domain, base, size, 0, 0, 0, 0, &ur->ur_mr, NULL); @@ -1439,15 +1332,14 @@ static int usnic_reg_mr(void* reg_data, void* base, size_t size, return OPAL_SUCCESS; } -static int usnic_dereg_mr(void* reg_data, - mca_rcache_base_registration_t* reg) +static int usnic_dereg_mr(void *reg_data, mca_rcache_base_registration_t *reg) { - opal_btl_usnic_reg_t* ur = (opal_btl_usnic_reg_t*)reg; + opal_btl_usnic_reg_t *ur = (opal_btl_usnic_reg_t *) reg; if (ur->ur_mr != NULL) { if (0 != fi_close(&ur->ur_mr->fid)) { - opal_output(0, "%s: error unpinning USD memory mr=%p: %s\n", - __func__, (void*) ur->ur_mr, strerror(errno)); + opal_output(0, "%s: error unpinning USD memory mr=%p: %s\n", __func__, + (void *) ur->ur_mr, strerror(errno)); return OPAL_ERROR; } } @@ -1456,7 +1348,6 @@ static int usnic_dereg_mr(void* reg_data, return OPAL_SUCCESS; } - /* * Called back by libevent if an async event occurs on the device */ @@ -1464,7 +1355,7 @@ static void module_async_event_callback(int fd, short flags, void *arg) { char *str = NULL; bool fatal = false; - opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t*) arg; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) arg; uint32_t event; struct fi_eq_entry entry; @@ -1476,13 +1367,9 @@ static void module_async_event_callback(int fd, short flags, void *arg) } else if (ret != 0) { - opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_eq_read()", __FILE__, __LINE__, - ret, - "Failed to get domain event"); + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, module->linux_device_name, "fi_eq_read()", + __FILE__, __LINE__, ret, "Failed to get domain event"); fatal = true; } @@ -1490,18 +1377,17 @@ static void module_async_event_callback(int fd, short flags, void *arg) opal_memchecker_base_mem_defined(&event, sizeof(event)); opal_memchecker_base_mem_defined(&entry, sizeof(entry)); switch (entry.data) { - case 0: // USD_EVENT_LINK_UP: + case 0: // USD_EVENT_LINK_UP: /* This event should never happen, because OMPI will ignore ports that are down, and we should only get this event if a port *was* down and is now *up*. But if we ever do get it, it should be a harmless event -- just ignore it. */ - opal_output_verbose(10, USNIC_OUT, - "btl:usnic: got LINK_UP on %s", + opal_output_verbose(10, USNIC_OUT, "btl:usnic: got LINK_UP on %s", module->linux_device_name); break; - case 1: // USD_EVENT_LINK_DOWN: + case 1: // USD_EVENT_LINK_DOWN: str = "link down"; /* Fall through */ @@ -1514,11 +1400,8 @@ static void module_async_event_callback(int fd, short flags, void *arg) will report to us. However, they're only listed here for completeness. We currently abort if any async event other than LINK_UP occurs. */ - opal_show_help("help-mpi-btl-usnic.txt", "async event", - true, - opal_process_info.nodename, - module->linux_device_name, - str, entry.data); + opal_show_help("help-mpi-btl-usnic.txt", "async event", true, + opal_process_info.nodename, module->linux_device_name, str, entry.data); fatal = true; } } @@ -1534,8 +1417,7 @@ static void module_async_event_callback(int fd, short flags, void *arg) /* * Create a single libfabric endpoint */ -static int create_ep(opal_btl_usnic_module_t* module, - struct opal_btl_usnic_channel_t *channel) +static int create_ep(opal_btl_usnic_module_t *module, struct opal_btl_usnic_channel_t *channel) { int rc; struct sockaddr_in *sin; @@ -1544,13 +1426,9 @@ static int create_ep(opal_btl_usnic_module_t* module, hint = fi_dupinfo(module->fabric_info); if (NULL == hint) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_dupinfo() failed", __FILE__, __LINE__, - -1, "Unknown"); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "fi_dupinfo() failed", + __FILE__, __LINE__, -1, "Unknown"); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1562,20 +1440,16 @@ static int create_ep(opal_btl_usnic_module_t* module, if (0 == mca_btl_usnic_component.udp_port_base) { sin->sin_port = 0; } else { - sin->sin_port = htons(mca_btl_usnic_component.udp_port_base + - opal_process_info.my_local_rank); + sin->sin_port = htons(mca_btl_usnic_component.udp_port_base + + opal_process_info.my_local_rank); } rc = fi_getinfo(module->libfabric_api, NULL, 0, 0, hint, &channel->info); fi_freeinfo(hint); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_getinfo() failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "fi_getinfo() failed", + __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } if (channel->chan_index != USNIC_PRIORITY_CHANNEL) { @@ -1588,16 +1462,16 @@ static int create_ep(opal_btl_usnic_module_t* module, /* all of the OMPI code assumes IPv4, but some versions of libfabric will * return FI_SOCKADDR instead of FI_SOCKADDR_IN, so we need to do a little * bit of sanity checking */ - assert(FI_SOCKADDR_IN == channel->info->addr_format || - FI_SOCKADDR == channel->info->addr_format); + assert(FI_SOCKADDR_IN == channel->info->addr_format + || FI_SOCKADDR == channel->info->addr_format); if (FI_SOCKADDR == channel->info->addr_format) { struct sockaddr *sa; - sa = (struct sockaddr *)channel->info->src_addr; + sa = (struct sockaddr *) channel->info->src_addr; assert(AF_INET == sa->sa_family); } #endif - sin = (struct sockaddr_in *)channel->info->src_addr; + sin = (struct sockaddr_in *) channel->info->src_addr; assert(sizeof(struct sockaddr_in) == channel->info->src_addrlen); /* no matter the version of libfabric, this should hold */ @@ -1605,13 +1479,9 @@ static int create_ep(opal_btl_usnic_module_t* module, rc = fi_endpoint(module->domain, channel->info, &channel->ep, NULL); if (0 != rc || NULL == channel->ep) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_endpoint() failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "fi_endpoint() failed", __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1619,72 +1489,50 @@ static int create_ep(opal_btl_usnic_module_t* module, long as we asked for */ if ((int) channel->info->rx_attr->size < channel->chan_rd_num) { rc = FI_ETOOSMALL; - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "endpoint RX queue length is too short", __FILE__, __LINE__, - rc, fi_strerror(rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "endpoint RX queue length is too short", __FILE__, __LINE__, rc, + fi_strerror(rc)); return OPAL_ERR_OUT_OF_RESOURCE; } if ((int) channel->info->tx_attr->size < channel->chan_sd_num) { rc = FI_ETOOSMALL; - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "endpoint TX queue length is too short", __FILE__, __LINE__, - rc, fi_strerror(rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "endpoint TX queue length is too short", __FILE__, __LINE__, rc, + fi_strerror(rc)); return OPAL_ERR_OUT_OF_RESOURCE; } /* attach CQ to EP */ rc = fi_ep_bind(channel->ep, &channel->cq->fid, FI_SEND); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_ep_bind() SCQ to EP failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "fi_ep_bind() SCQ to EP failed", __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } rc = fi_ep_bind(channel->ep, &channel->cq->fid, FI_RECV); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_ep_bind() RCQ to EP failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "fi_ep_bind() RCQ to EP failed", __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } rc = fi_ep_bind(channel->ep, &module->av->fid, 0); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_ep_bind() AV to EP failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "fi_ep_bind() AV to EP failed", __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } /* Enable the endpoint */ rc = fi_enable(channel->ep); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_enable() failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "fi_enable() failed", + __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1700,13 +1548,9 @@ static int create_ep(opal_btl_usnic_module_t* module, addrlen = sizeof(struct sockaddr_in); rc = fi_getname(&channel->ep->fid, channel->info->src_addr, &addrlen); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_getname() failed", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "fi_getname() failed", __FILE__, __LINE__, rc, fi_strerror(-rc)); return OPAL_ERR_OUT_OF_RESOURCE; } assert(0 != sin->sin_port); @@ -1722,15 +1566,12 @@ static int create_ep(opal_btl_usnic_module_t* module, } opal_output_verbose(15, USNIC_OUT, "btl:usnic:create_ep:%s: new usnic local endpoint channel %s: %s:%d", - module->linux_device_name, - str, - inet_ntoa(sin->sin_addr), + module->linux_device_name, str, inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); return OPAL_SUCCESS; } - /* * finalize channel - release all associated resources */ @@ -1765,18 +1606,14 @@ static void finalize_one_channel(opal_btl_usnic_module_t *module, /* * Initialize a channel */ -static int init_one_channel(opal_btl_usnic_module_t *module, - int index, - int max_msg_size, - int rd_num, - int sd_num, - int cq_num) +static int init_one_channel(opal_btl_usnic_module_t *module, int index, int max_msg_size, + int rd_num, int sd_num, int cq_num) { int i; int rc; uint32_t segsize; opal_btl_usnic_recv_segment_t *rseg; - opal_free_list_item_t* item; + opal_free_list_item_t *item; struct opal_btl_usnic_channel_t *channel; struct fi_cq_attr cq_attr; @@ -1803,13 +1640,9 @@ static int init_one_channel(opal_btl_usnic_module_t *module, cq_attr.size = cq_num; rc = fi_cq_open(module->domain, &cq_attr, &channel->cq, NULL); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "failed to create CQ", __FILE__, __LINE__, - rc, fi_strerror(-rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "failed to create CQ", + __FILE__, __LINE__, rc, fi_strerror(-rc)); goto error; } @@ -1817,13 +1650,9 @@ static int init_one_channel(opal_btl_usnic_module_t *module, for */ if ((int) cq_attr.size < cq_num) { rc = FI_ETOOSMALL; - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "created CQ is too small", __FILE__, __LINE__, - rc, fi_strerror(rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "created CQ is too small", __FILE__, __LINE__, rc, fi_strerror(rc)); goto error; } @@ -1833,16 +1662,15 @@ static int init_one_channel(opal_btl_usnic_module_t *module, goto error; } - assert(channel->info->ep_attr->msg_prefix_size == - (uint32_t) mca_btl_usnic_component.transport_header_len); + assert(channel->info->ep_attr->msg_prefix_size + == (uint32_t) mca_btl_usnic_component.transport_header_len); opal_output_verbose(15, USNIC_OUT, - "btl:usnic:init_one_channel:%s: channel %s, rx queue size=%" PRIsize_t ", tx queue size=%" PRIsize_t ", cq size=%" PRIsize_t ", send credits=%d", + "btl:usnic:init_one_channel:%s: channel %s, rx queue size=%" PRIsize_t + ", tx queue size=%" PRIsize_t ", cq size=%" PRIsize_t ", send credits=%d", module->linux_device_name, (index == USNIC_PRIORITY_CHANNEL) ? "priority" : "data", - channel->info->rx_attr->size, - channel->info->tx_attr->size, - cq_attr.size, + channel->info->rx_attr->size, channel->info->tx_attr->size, cq_attr.size, channel->credits); /* @@ -1850,24 +1678,18 @@ static int init_one_channel(opal_btl_usnic_module_t *module, * line size so that each segment is guaranteed to start on a * cache line boundary. */ - segsize = (max_msg_size + channel->info->ep_attr->msg_prefix_size + - opal_cache_line_size - 1) & ~(opal_cache_line_size - 1); + segsize = (max_msg_size + channel->info->ep_attr->msg_prefix_size + opal_cache_line_size - 1) + & ~(opal_cache_line_size - 1); OBJ_CONSTRUCT(&channel->recv_segs, opal_free_list_t); - rc = - usnic_compat_free_list_init(&channel->recv_segs, - sizeof(opal_btl_usnic_recv_segment_t) /* frag size */, - opal_cache_line_size /* frag alignment */, - OBJ_CLASS(opal_btl_usnic_recv_segment_t), - segsize /* payload buffer size */, - opal_cache_line_size /* payload alignmt */, - rd_num /* num erorments to alloc */, - rd_num /* max elements to alloc */, - rd_num /* num elements per alloc */, - module->super.btl_mpool /* mpool for (1.x, 2.0: reg, 2.1+: allocation) */, - 0 /* mpool reg flags */, - module->rcache /* registration cache for 2.1+ */, - NULL /* item_init */, - NULL /* item_init_context */); + rc = usnic_compat_free_list_init( + &channel->recv_segs, sizeof(opal_btl_usnic_recv_segment_t) /* frag size */, + opal_cache_line_size /* frag alignment */, OBJ_CLASS(opal_btl_usnic_recv_segment_t), + segsize /* payload buffer size */, opal_cache_line_size /* payload alignmt */, + rd_num /* num erorments to alloc */, rd_num /* max elements to alloc */, + rd_num /* num elements per alloc */, + module->super.btl_mpool /* mpool for (1.x, 2.0: reg, 2.1+: allocation) */, + 0 /* mpool reg flags */, module->rcache /* registration cache for 2.1+ */, + NULL /* item_init */, NULL /* item_init_context */); channel->recv_segs.ctx = module; /* must come after free_list_init, otherwise ctx gets @@ -1880,32 +1702,23 @@ static int init_one_channel(opal_btl_usnic_module_t *module, for (i = 0; i < rd_num; i++) { USNIC_COMPAT_FREE_LIST_GET(&channel->recv_segs, item); assert(NULL != item); - rseg = (opal_btl_usnic_recv_segment_t*)item; + rseg = (opal_btl_usnic_recv_segment_t *) item; if (NULL == rseg) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "Failed to get receive buffer from freelist", - __FILE__, __LINE__); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "Failed to get receive buffer from freelist", __FILE__, __LINE__); goto error; } /* cannot find length from constructor, set it now */ rseg->rs_len = segsize; - rc = fi_recv(channel->ep, rseg->rs_protocol_header, segsize, - NULL, FI_ADDR_UNSPEC, rseg); + rc = fi_recv(channel->ep, rseg->rs_protocol_header, segsize, NULL, FI_ADDR_UNSPEC, rseg); if (0 != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "Failed to post receive buffer", - __FILE__, __LINE__); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, + "Failed to post receive buffer", __FILE__, __LINE__); goto error; } } @@ -1920,12 +1733,11 @@ static int init_one_channel(opal_btl_usnic_module_t *module, /* * generate initial send sequence number */ -static opal_btl_usnic_seq_t -get_initial_seq_no(void) +static opal_btl_usnic_seq_t get_initial_seq_no(void) { opal_btl_usnic_seq_t isn; - isn = (opal_btl_usnic_seq_t)opal_rand(&opal_btl_usnic_rand_buff); + isn = (opal_btl_usnic_seq_t) opal_rand(&opal_btl_usnic_rand_buff); return isn; } @@ -1943,7 +1755,6 @@ static void init_module_globals(opal_btl_usnic_module_t *module) OBJ_CONSTRUCT(&module->all_endpoints_lock, opal_mutex_t); } - /* * Initialize our local modex entry from the device attributes */ @@ -1958,20 +1769,16 @@ static void init_local_modex_part1(opal_btl_usnic_module_t *module) struct sockaddr_in *sin; sin = info->src_addr; - modex->ipv4_addr = sin->sin_addr.s_addr; - modex->netmask = uip->ui.v1.ui_netmask_be; - modex->max_msg_size = info->ep_attr->max_msg_size; + modex->ipv4_addr = sin->sin_addr.s_addr; + modex->netmask = uip->ui.v1.ui_netmask_be; + modex->max_msg_size = info->ep_attr->max_msg_size; modex->link_speed_mbps = uip->ui.v1.ui_link_speed; - opal_btl_usnic_snprintf_ipv4_addr(module->if_ipv4_addr_str, - sizeof(module->if_ipv4_addr_str), - modex->ipv4_addr, - modex->netmask); + opal_btl_usnic_snprintf_ipv4_addr(module->if_ipv4_addr_str, sizeof(module->if_ipv4_addr_str), + modex->ipv4_addr, modex->netmask); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic: %s IP charactertics: %s, %u Mbps", - module->linux_device_name, - module->if_ipv4_addr_str, + opal_output_verbose(5, USNIC_OUT, "btl:usnic: %s IP charactertics: %s, %u Mbps", + module->linux_device_name, module->if_ipv4_addr_str, modex->link_speed_mbps); } @@ -1984,10 +1791,8 @@ static void init_local_modex_part1(opal_btl_usnic_module_t *module) */ static void init_find_transport_header_len(opal_btl_usnic_module_t *module) { - mca_btl_usnic_component.transport_header_len = - module->fabric_info->ep_attr->msg_prefix_size; - mca_btl_usnic_component.transport_protocol = - module->fabric_info->ep_attr->protocol; + mca_btl_usnic_component.transport_header_len = module->fabric_info->ep_attr->msg_prefix_size; + mca_btl_usnic_component.transport_protocol = module->fabric_info->ep_attr->protocol; /* The usnic provider in libfabric v1.0.0 (i.e., API v1.0) treated FI_MSG_PREFIX inconsistently between senders and receivers. It @@ -2008,12 +1813,10 @@ static void init_find_transport_header_len(opal_btl_usnic_module_t *module) attribute to the same value. So it's ok. */ uint32_t libfabric_api; libfabric_api = fi_version(); - if (1 == FI_MAJOR(libfabric_api) && - 0 == FI_MINOR(libfabric_api)) { + if (1 == FI_MAJOR(libfabric_api) && 0 == FI_MINOR(libfabric_api)) { mca_btl_usnic_component.prefix_send_offset = 0; } else { - mca_btl_usnic_component.prefix_send_offset = - module->fabric_info->ep_attr->msg_prefix_size; + mca_btl_usnic_component.prefix_send_offset = module->fabric_info->ep_attr->msg_prefix_size; } } @@ -2056,20 +1859,17 @@ static void init_queue_lengths(opal_btl_usnic_module_t *module) } else { module->prio_sd_num = mca_btl_usnic_component.prio_sd_num; } - if (module->prio_sd_num > 0 && - (unsigned) module->prio_sd_num > - module->fabric_info->tx_attr->size) { + if (module->prio_sd_num > 0 + && (unsigned) module->prio_sd_num > module->fabric_info->tx_attr->size) { module->prio_sd_num = module->fabric_info->tx_attr->size; } if (-1 == mca_btl_usnic_component.prio_rd_num) { - module->prio_rd_num = - max(128, 32 * USNIC_MCW_SIZE) - 1; + module->prio_rd_num = max(128, 32 * USNIC_MCW_SIZE) - 1; } else { module->prio_rd_num = mca_btl_usnic_component.prio_rd_num; } - if (module->prio_rd_num > 0 && - (unsigned) module->prio_rd_num > - module->fabric_info->rx_attr->size) { + if (module->prio_rd_num > 0 + && (unsigned) module->prio_rd_num > module->fabric_info->rx_attr->size) { module->prio_rd_num = module->fabric_info->rx_attr->size; } if (cq_is_sum) { @@ -2082,24 +1882,21 @@ static void init_queue_lengths(opal_btl_usnic_module_t *module) static void init_payload_lengths(opal_btl_usnic_module_t *module) { /* Find the max payload this port can handle */ - module->max_frag_payload = - module->local_modex.max_msg_size - /* start with the MTU */ - sizeof(opal_btl_usnic_btl_header_t) - /* subtract size of - the BTL header */ - mca_btl_usnic_component.prefix_send_offset; + module->max_frag_payload = module->local_modex.max_msg_size - /* start with the MTU */ + sizeof(opal_btl_usnic_btl_header_t) - /* subtract size of + the BTL header */ + mca_btl_usnic_component.prefix_send_offset; /* same, but use chunk header */ - module->max_chunk_payload = - module->local_modex.max_msg_size - - sizeof(opal_btl_usnic_btl_chunk_header_t) - - mca_btl_usnic_component.prefix_send_offset; + module->max_chunk_payload = module->local_modex.max_msg_size + - sizeof(opal_btl_usnic_btl_chunk_header_t) + - mca_btl_usnic_component.prefix_send_offset; /* Priorirty queue MTU and max size */ if (0 == module->max_tiny_msg_size) { module->max_tiny_msg_size = 768; } - module->max_tiny_payload = module->max_tiny_msg_size - - sizeof(opal_btl_usnic_btl_header_t); + module->max_tiny_payload = module->max_tiny_msg_size - sizeof(opal_btl_usnic_btl_header_t); } static void init_pml_values(opal_btl_usnic_module_t *module) @@ -2115,22 +1912,18 @@ static void init_pml_values(opal_btl_usnic_module_t *module) if (0 == module->super.btl_eager_limit) { /* 150k for 1 module, 25k for >1 module */ if (1 == mca_btl_usnic_component.num_modules) { - module->super.btl_eager_limit = - USNIC_DFLT_EAGER_LIMIT_1DEVICE; + module->super.btl_eager_limit = USNIC_DFLT_EAGER_LIMIT_1DEVICE; } else { - module->super.btl_eager_limit = - USNIC_DFLT_EAGER_LIMIT_NDEVICES; + module->super.btl_eager_limit = USNIC_DFLT_EAGER_LIMIT_NDEVICES; } } /* Since we emulate PUT, max_send_size can be same as eager_limit */ - module->super.btl_max_send_size = - module->super.btl_eager_limit; + module->super.btl_max_send_size = module->super.btl_eager_limit; #if BTL_VERSION == 30 - module->super.btl_put_limit = - module->super.btl_eager_limit; + module->super.btl_put_limit = module->super.btl_eager_limit; #endif } @@ -2151,8 +1944,8 @@ static void init_connectivity_checker(opal_btl_usnic_module_t *module) int rc = opal_btl_usnic_connectivity_listen(module); if (OPAL_SUCCESS != rc) { OPAL_ERROR_LOG(rc); - opal_btl_usnic_util_abort("Failed to notify connectivity agent to listen", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("Failed to notify connectivity agent to listen", __FILE__, + __LINE__); } } @@ -2164,7 +1957,8 @@ static void init_hwloc(opal_btl_usnic_module_t *module) opal_btl_usnic_hwloc_distance(module); } else { opal_output_verbose(5, USNIC_OUT, - "btl:usnic: not sorting devices by NUMA distance (MCA btl_usnic_want_numa_device_assignment)"); + "btl:usnic: not sorting devices by NUMA distance (MCA " + "btl_usnic_want_numa_device_assignment)"); } } @@ -2183,32 +1977,25 @@ static int init_mpool(opal_btl_usnic_module_t *module) { struct mca_rcache_base_resources_t rcache_resources; - rcache_resources.reg_data = (void*)module; + rcache_resources.reg_data = (void *) module; rcache_resources.sizeof_reg = sizeof(opal_btl_usnic_reg_t); rcache_resources.register_mem = usnic_reg_mr; rcache_resources.deregister_mem = usnic_dereg_mr; rcache_resources.cache_name = mca_btl_usnic_component.usnic_rcache_name; - module->rcache = - mca_rcache_base_module_create (mca_btl_usnic_component.usnic_rcache_name, - &module->super, &rcache_resources); + module->rcache = mca_rcache_base_module_create(mca_btl_usnic_component.usnic_rcache_name, + &module->super, &rcache_resources); if (NULL == module->rcache) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "create rcache", __FILE__, __LINE__); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "create rcache", + __FILE__, __LINE__); return OPAL_ERROR; } - module->super.btl_mpool = - mca_mpool_base_module_lookup (mca_btl_usnic_component.usnic_mpool_hints); + module->super.btl_mpool = mca_mpool_base_module_lookup( + mca_btl_usnic_component.usnic_mpool_hints); if (NULL == module->super.btl_mpool) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - module->linux_device_name, - "create mpool", __FILE__, __LINE__); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, module->linux_device_name, "create mpool", + __FILE__, __LINE__); return OPAL_ERROR; } @@ -2221,10 +2008,8 @@ static int init_channels(opal_btl_usnic_module_t *module) struct fi_av_attr av_attr; struct fi_eq_attr eq_attr; - memset(&module->mod_channels[0], 0, - sizeof(module->mod_channels[0])); - memset(&module->mod_channels[1], 0, - sizeof(module->mod_channels[1])); + memset(&module->mod_channels[0], 0, sizeof(module->mod_channels[0])); + memset(&module->mod_channels[1], 0, sizeof(module->mod_channels[1])); memset(&av_attr, 0, sizeof(av_attr)); av_attr.type = FI_AV_MAP; @@ -2234,8 +2019,7 @@ static int init_channels(opal_btl_usnic_module_t *module) goto destroy; } - rc = fi_open_ops(&module->av->fid, FI_USNIC_AV_OPS_1, 0, - (void **)&module->usnic_av_ops, NULL); + rc = fi_open_ops(&module->av->fid, FI_USNIC_AV_OPS_1, 0, (void **) &module->usnic_av_ops, NULL); if (rc != OPAL_SUCCESS) { goto destroy; } @@ -2267,28 +2051,22 @@ static int init_channels(opal_btl_usnic_module_t *module) } /* initialize data and priority channels */ - rc = init_one_channel(module, - USNIC_PRIORITY_CHANNEL, - module->max_tiny_msg_size, - module->prio_rd_num, module->prio_sd_num, module->prio_cq_num); + rc = init_one_channel(module, USNIC_PRIORITY_CHANNEL, module->max_tiny_msg_size, + module->prio_rd_num, module->prio_sd_num, module->prio_cq_num); if (rc != OPAL_SUCCESS) { goto destroy; } - rc = init_one_channel(module, - USNIC_DATA_CHANNEL, - module->fabric_info->ep_attr->max_msg_size, - module->rd_num, module->sd_num, module->cq_num); + rc = init_one_channel(module, USNIC_DATA_CHANNEL, module->fabric_info->ep_attr->max_msg_size, + module->rd_num, module->sd_num, module->cq_num); if (rc != OPAL_SUCCESS) { goto destroy; } return OPAL_SUCCESS; - destroy: - finalize_one_channel(module, - &module->mod_channels[USNIC_DATA_CHANNEL]); - finalize_one_channel(module, - &module->mod_channels[USNIC_PRIORITY_CHANNEL]); +destroy: + finalize_one_channel(module, &module->mod_channels[USNIC_DATA_CHANNEL]); + finalize_one_channel(module, &module->mod_channels[USNIC_PRIORITY_CHANNEL]); return rc; } @@ -2316,22 +2094,16 @@ static void init_async_event(opal_btl_usnic_module_t *module) ret = fi_control(&module->dom_eq->fid, FI_GETWAIT, &fd); if (ret != 0) { - opal_show_help("help-mpi-btl-usnic.txt", - "libfabric API failed", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_control(eq, FI_GETWAIT)", __FILE__, __LINE__, - ret, - fi_strerror(-ret)); + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, module->linux_device_name, + "fi_control(eq, FI_GETWAIT)", __FILE__, __LINE__, ret, fi_strerror(-ret)); return; } /* Get the fd to receive events on this device. Keep this in the sync event base (not the async event base) */ opal_event_set(opal_sync_event_base, &(module->device_async_event), fd, - OPAL_EV_READ | OPAL_EV_PERSIST, - module_async_event_callback, module); + OPAL_EV_READ | OPAL_EV_PERSIST, module_async_event_callback, module); opal_event_add(&(module->device_async_event), NULL); module->device_async_event_active = true; } @@ -2357,101 +2129,66 @@ static void init_freelists(opal_btl_usnic_module_t *module) int rc __opal_attribute_unused__; uint32_t segsize; - segsize = (module->local_modex.max_msg_size + - mca_btl_usnic_component.prefix_send_offset + - opal_cache_line_size - 1) & - ~(opal_cache_line_size - 1); + segsize = (module->local_modex.max_msg_size + mca_btl_usnic_component.prefix_send_offset + + opal_cache_line_size - 1) + & ~(opal_cache_line_size - 1); /* Send frags freelists */ OBJ_CONSTRUCT(&module->small_send_frags, opal_free_list_t); rc = usnic_compat_free_list_init(&module->small_send_frags, - sizeof(opal_btl_usnic_small_send_frag_t), - opal_cache_line_size, - OBJ_CLASS(opal_btl_usnic_small_send_frag_t), - segsize, - opal_cache_line_size, - module->sd_num * 4, - -1, - module->sd_num / 2, - module->super.btl_mpool, - 0 /* mpool reg flags */, - module->rcache, - NULL /* item_init */, - NULL /* item_init_context */); + sizeof(opal_btl_usnic_small_send_frag_t), opal_cache_line_size, + OBJ_CLASS(opal_btl_usnic_small_send_frag_t), segsize, + opal_cache_line_size, module->sd_num * 4, -1, + module->sd_num / 2, module->super.btl_mpool, + 0 /* mpool reg flags */, module->rcache, NULL /* item_init */, + NULL /* item_init_context */); assert(OPAL_SUCCESS == rc); OBJ_CONSTRUCT(&module->large_send_frags, opal_free_list_t); rc = usnic_compat_free_list_init(&module->large_send_frags, - sizeof(opal_btl_usnic_large_send_frag_t), - opal_cache_line_size, - OBJ_CLASS(opal_btl_usnic_large_send_frag_t), - 0, /* payload size */ - 0, /* payload align */ - module->sd_num / 8, - -1, - module->sd_num / 8, - NULL, - 0 /* mpool reg flags */, - NULL /* unused0 */, - NULL /* item_init */, - NULL /* item_init_context */); + sizeof(opal_btl_usnic_large_send_frag_t), opal_cache_line_size, + OBJ_CLASS(opal_btl_usnic_large_send_frag_t), + 0, /* payload size */ + 0, /* payload align */ + module->sd_num / 8, -1, module->sd_num / 8, NULL, + 0 /* mpool reg flags */, NULL /* unused0 */, + NULL /* item_init */, NULL /* item_init_context */); assert(OPAL_SUCCESS == rc); OBJ_CONSTRUCT(&module->put_dest_frags, opal_free_list_t); rc = usnic_compat_free_list_init(&module->put_dest_frags, - sizeof(opal_btl_usnic_put_dest_frag_t), - opal_cache_line_size, - OBJ_CLASS(opal_btl_usnic_put_dest_frag_t), - 0, /* payload size */ - 0, /* payload align */ - module->sd_num / 8, - -1, - module->sd_num / 8, - NULL, - 0 /* mpool reg flags */, - NULL /* unused0 */, - NULL /* item_init */, - NULL /* item_init_context */); + sizeof(opal_btl_usnic_put_dest_frag_t), opal_cache_line_size, + OBJ_CLASS(opal_btl_usnic_put_dest_frag_t), + 0, /* payload size */ + 0, /* payload align */ + module->sd_num / 8, -1, module->sd_num / 8, NULL, + 0 /* mpool reg flags */, NULL /* unused0 */, + NULL /* item_init */, NULL /* item_init_context */); assert(OPAL_SUCCESS == rc); /* list of segments to use for sending */ OBJ_CONSTRUCT(&module->chunk_segs, opal_free_list_t); - rc = usnic_compat_free_list_init(&module->chunk_segs, - sizeof(opal_btl_usnic_chunk_segment_t), - opal_cache_line_size, - OBJ_CLASS(opal_btl_usnic_chunk_segment_t), - segsize, - opal_cache_line_size, - module->sd_num * 4, - -1, - module->sd_num / 2, - module->super.btl_mpool, - 0 /* mpool reg flags */, - module->rcache, - NULL /* item_init */, - NULL /* item_init_context */); + rc = usnic_compat_free_list_init(&module->chunk_segs, sizeof(opal_btl_usnic_chunk_segment_t), + opal_cache_line_size, + OBJ_CLASS(opal_btl_usnic_chunk_segment_t), segsize, + opal_cache_line_size, module->sd_num * 4, -1, + module->sd_num / 2, module->super.btl_mpool, + 0 /* mpool reg flags */, module->rcache, NULL /* item_init */, + NULL /* item_init_context */); assert(OPAL_SUCCESS == rc); /* ACK segments freelist */ uint32_t ack_segment_len; - ack_segment_len = (sizeof(opal_btl_usnic_btl_header_t) + - mca_btl_usnic_component.prefix_send_offset + - opal_cache_line_size - 1) & ~(opal_cache_line_size - 1); + ack_segment_len = (sizeof(opal_btl_usnic_btl_header_t) + + mca_btl_usnic_component.prefix_send_offset + opal_cache_line_size - 1) + & ~(opal_cache_line_size - 1); OBJ_CONSTRUCT(&module->ack_segs, opal_free_list_t); - rc = usnic_compat_free_list_init(&module->ack_segs, - sizeof(opal_btl_usnic_ack_segment_t), - opal_cache_line_size, - OBJ_CLASS(opal_btl_usnic_ack_segment_t), - ack_segment_len, - opal_cache_line_size, - module->sd_num * 4, - -1, - module->sd_num / 2, - module->super.btl_mpool, - 0 /* mpool reg flags */, - module->rcache, - NULL /* item_init */, - NULL /* item_init_context */); + rc = usnic_compat_free_list_init(&module->ack_segs, sizeof(opal_btl_usnic_ack_segment_t), + opal_cache_line_size, OBJ_CLASS(opal_btl_usnic_ack_segment_t), + ack_segment_len, opal_cache_line_size, module->sd_num * 4, -1, + module->sd_num / 2, module->super.btl_mpool, + 0 /* mpool reg flags */, module->rcache, NULL /* item_init */, + NULL /* item_init_context */); assert(OPAL_SUCCESS == rc); /* @@ -2461,27 +2198,22 @@ static void init_freelists(opal_btl_usnic_module_t *module) * pools simply won't be used in that case. */ module->first_pool = 16; /* 64 kiB */ - module->last_pool = usnic_fls(module->super.btl_eager_limit-1); - module->module_recv_buffers = calloc(module->last_pool+1, - sizeof(opal_free_list_t)); + module->last_pool = usnic_fls(module->super.btl_eager_limit - 1); + module->module_recv_buffers = calloc(module->last_pool + 1, sizeof(opal_free_list_t)); assert(module->module_recv_buffers != NULL); for (int i = module->first_pool; i <= module->last_pool; ++i) { size_t elt_size = sizeof(opal_btl_usnic_rx_buf_t) - 1 + (1 << i); OBJ_CONSTRUCT(&module->module_recv_buffers[i], opal_free_list_t); - rc = usnic_compat_free_list_init(&module->module_recv_buffers[i], - elt_size, - opal_cache_line_size, - OBJ_CLASS(opal_btl_usnic_rx_buf_t), - 0, /* payload size */ - 0, /* payload align */ - 128, /* init elts to alloc */ - 128, /* max elts to alloc */ - 128, /* num elts per alloc */ - NULL /* mpool */, - 0 /* mpool reg flags */, - NULL /* unused0 */, - NULL /* item_init */, - NULL /* item_init_context */); + rc = usnic_compat_free_list_init(&module->module_recv_buffers[i], elt_size, + opal_cache_line_size, OBJ_CLASS(opal_btl_usnic_rx_buf_t), + 0, /* payload size */ + 0, /* payload align */ + 128, /* init elts to alloc */ + 128, /* max elts to alloc */ + 128, /* num elts per alloc */ + NULL /* mpool */, 0 /* mpool reg flags */, + NULL /* unused0 */, NULL /* item_init */, + NULL /* item_init_context */); assert(OPAL_SUCCESS == rc); } } @@ -2504,9 +2236,9 @@ int opal_btl_usnic_module_init(opal_btl_usnic_module_t *module) init_procs(module); int ret; - if (OPAL_SUCCESS != (ret = init_mpool(module)) || - OPAL_SUCCESS != (ret = init_channels(module))) { - mca_rcache_base_module_destroy (module->rcache); + if (OPAL_SUCCESS != (ret = init_mpool(module)) + || OPAL_SUCCESS != (ret = init_channels(module))) { + mca_rcache_base_module_destroy(module->rcache); return ret; } @@ -2522,8 +2254,8 @@ int opal_btl_usnic_module_init(opal_btl_usnic_module_t *module) int rc = opal_btl_usnic_connectivity_listen(module); if (OPAL_SUCCESS != rc) { OPAL_ERROR_LOG(rc); - opal_btl_usnic_util_abort("Failed to notify connectivity agent to listen", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("Failed to notify connectivity agent to listen", __FILE__, + __LINE__); } } else { /* If we're not doing a connectivity check, just set the port @@ -2534,7 +2266,6 @@ int opal_btl_usnic_module_init(opal_btl_usnic_module_t *module) return OPAL_SUCCESS; } - opal_btl_usnic_module_t opal_btl_usnic_module_template = { .super = { .btl_component = &mca_btl_usnic_component.super, @@ -2557,13 +2288,11 @@ opal_btl_usnic_module_t opal_btl_usnic_module_template = { #endif .btl_exclusivity = MCA_BTL_EXCLUSIVITY_DEFAULT, - .btl_flags = - MCA_BTL_FLAGS_SEND | - MCA_BTL_FLAGS_SEND_INPLACE | - /* Need to set FLAGS_SINGLE_ADD_PROCS until - btl_recv.h:lookup_sender() can handle an incoming - message with an unknown sender. */ - MCA_BTL_FLAGS_SINGLE_ADD_PROCS, + .btl_flags = MCA_BTL_FLAGS_SEND | MCA_BTL_FLAGS_SEND_INPLACE | + /* Need to set FLAGS_SINGLE_ADD_PROCS until + btl_recv.h:lookup_sender() can handle an incoming + message with an unknown sender. */ + MCA_BTL_FLAGS_SINGLE_ADD_PROCS, .btl_add_procs = usnic_add_procs, .btl_del_procs = usnic_del_procs, @@ -2581,5 +2310,4 @@ opal_btl_usnic_module_t opal_btl_usnic_module_template = { .btl_mpool = NULL, .btl_register_error = usnic_register_pml_err_cb, - } -}; + }}; diff --git a/opal/mca/btl/usnic/btl_usnic_module.h b/opal/mca/btl/usnic/btl_usnic_module.h index 17de3d090be..4b6ff2ed877 100644 --- a/opal/mca/btl/usnic/btl_usnic_module.h +++ b/opal/mca/btl/usnic/btl_usnic_module.h @@ -29,8 +29,8 @@ #include #include -#include #include +#include #include #include @@ -46,10 +46,10 @@ * These values obtained from empirical testing on Intel E5-2690 * machines with Sereno/Lexington cards through an N3546 switch. */ -#define USNIC_DFLT_EAGER_LIMIT_1DEVICE (150 * 1024) +#define USNIC_DFLT_EAGER_LIMIT_1DEVICE (150 * 1024) #define USNIC_DFLT_EAGER_LIMIT_NDEVICES (25 * 1024) -#define USNIC_DFLT_RNDV_EAGER_LIMIT 500 -#define USNIC_DFLT_PACK_LAZY_THRESHOLD (16 * 1024) +#define USNIC_DFLT_RNDV_EAGER_LIMIT 500 +#define USNIC_DFLT_PACK_LAZY_THRESHOLD (16 * 1024) BEGIN_C_DECLS @@ -89,7 +89,7 @@ typedef struct opal_btl_usnic_channel_t { /** receive segments & buffers */ opal_free_list_t recv_segs; - bool chan_error; /* set when error detected on channel */ + bool chan_error; /* set when error detected on channel */ /* statistics */ uint32_t num_channel_sends; @@ -146,9 +146,9 @@ typedef struct opal_btl_usnic_module_t { * to fragment reassembly info. */ size_t max_tiny_msg_size; - size_t max_frag_payload; /* most that fits in a frag segment */ - size_t max_chunk_payload; /* most that can fit in chunk segment */ - size_t max_tiny_payload; /* threshold for using inline send */ + size_t max_frag_payload; /* most that fits in a frag segment */ + size_t max_chunk_payload; /* most that can fit in chunk segment */ + size_t max_tiny_payload; /* threshold for using inline send */ /** Hash table to keep track of senders */ opal_hash_table_t senders; @@ -217,8 +217,7 @@ extern opal_btl_usnic_module_t opal_btl_usnic_module_template; /* get first endpoint needing ACK */ static inline opal_btl_usnic_endpoint_t * -opal_btl_usnic_get_first_endpoint_needing_ack( - opal_btl_usnic_module_t *module) +opal_btl_usnic_get_first_endpoint_needing_ack(opal_btl_usnic_module_t *module) { opal_list_item_t *item; opal_btl_usnic_endpoint_t *endpoint; @@ -234,8 +233,7 @@ opal_btl_usnic_get_first_endpoint_needing_ack( /* get next item in chain */ static inline opal_btl_usnic_endpoint_t * -opal_btl_usnic_get_next_endpoint_needing_ack( - opal_btl_usnic_endpoint_t *endpoint) +opal_btl_usnic_get_next_endpoint_needing_ack(opal_btl_usnic_endpoint_t *endpoint) { opal_list_item_t *item; opal_btl_usnic_module_t *module; @@ -252,36 +250,31 @@ opal_btl_usnic_get_next_endpoint_needing_ack( } static inline void -opal_btl_usnic_remove_from_endpoints_needing_ack( - opal_btl_usnic_endpoint_t *endpoint) +opal_btl_usnic_remove_from_endpoints_needing_ack(opal_btl_usnic_endpoint_t *endpoint) { - opal_list_remove_item( - &(endpoint->endpoint_module->endpoints_that_need_acks), - &endpoint->endpoint_ack_li); + opal_list_remove_item(&(endpoint->endpoint_module->endpoints_that_need_acks), + &endpoint->endpoint_ack_li); endpoint->endpoint_ack_needed = false; endpoint->endpoint_acktime = 0; #if MSGDEBUG1 - opal_output(0, "clear ack_needed on %p\n", (void*)endpoint); + opal_output(0, "clear ack_needed on %p\n", (void *) endpoint); #endif } -static inline void -opal_btl_usnic_add_to_endpoints_needing_ack( - opal_btl_usnic_endpoint_t *endpoint) +static inline void opal_btl_usnic_add_to_endpoints_needing_ack(opal_btl_usnic_endpoint_t *endpoint) { opal_list_append(&(endpoint->endpoint_module->endpoints_that_need_acks), - &endpoint->endpoint_ack_li); + &endpoint->endpoint_ack_li); endpoint->endpoint_ack_needed = true; #if MSGDEBUG1 - opal_output(0, "set ack_needed on %p\n", (void*)endpoint); + opal_output(0, "set ack_needed on %p\n", (void *) endpoint); #endif } /* * Initialize a module */ -int opal_btl_usnic_module_init(opal_btl_usnic_module_t* module); - +int opal_btl_usnic_module_init(opal_btl_usnic_module_t *module); /* * Progress pending sends on a module @@ -289,10 +282,8 @@ int opal_btl_usnic_module_init(opal_btl_usnic_module_t* module); void opal_btl_usnic_module_progress_sends(opal_btl_usnic_module_t *module); /* opal_output statistics that are useful for debugging */ -void opal_btl_usnic_print_stats( - opal_btl_usnic_module_t *module, - const char *prefix, - bool reset_stats); +void opal_btl_usnic_print_stats(opal_btl_usnic_module_t *module, const char *prefix, + bool reset_stats); END_C_DECLS #endif diff --git a/opal/mca/btl/usnic/btl_usnic_proc.c b/opal/mca/btl/usnic/btl_usnic_proc.c index a2878c5b509..4f7daeba856 100644 --- a/opal/mca/btl/usnic/btl_usnic_proc.c +++ b/opal/mca/btl/usnic/btl_usnic_proc.c @@ -23,34 +23,32 @@ #include "opal_config.h" -#include "opal_stdint.h" -#include "opal/util/arch.h" -#include "opal/util/show_help.h" #include "opal/constants.h" +#include "opal/util/arch.h" #include "opal/util/bipartite_graph.h" +#include "opal/util/show_help.h" #include "opal/util/string_copy.h" +#include "opal_stdint.h" -#include "btl_usnic_compat.h" #include "btl_usnic.h" -#include "btl_usnic_proc.h" +#include "btl_usnic_compat.h" #include "btl_usnic_endpoint.h" #include "btl_usnic_module.h" +#include "btl_usnic_proc.h" #include "btl_usnic_util.h" /* larger weight values are more desirable (i.e., worth, not cost) */ -enum { - WEIGHT_UNREACHABLE = -1 -}; +enum { WEIGHT_UNREACHABLE = -1 }; /* Helper macros for "match_modex" and friends for translating between array * indices and vertex IDs. Module vertices always come first in the graph, * followed by proc (endpoint) vertices. */ -#define PROC_VERTEX(modex_idx) (mca_btl_usnic_component.num_modules + modex_idx) -#define MODULE_VERTEX(module_idx) (module_idx) -#define PROC_INDEX(proc_vertex) ((proc_vertex) - mca_btl_usnic_component.num_modules) +#define PROC_VERTEX(modex_idx) (mca_btl_usnic_component.num_modules + modex_idx) +#define MODULE_VERTEX(module_idx) (module_idx) +#define PROC_INDEX(proc_vertex) ((proc_vertex) -mca_btl_usnic_component.num_modules) #define MODULE_INDEX(module_vertex) (module_vertex) -static void proc_construct(opal_btl_usnic_proc_t* proc) +static void proc_construct(opal_btl_usnic_proc_t *proc) { proc->proc_opal = 0; proc->proc_modex = NULL; @@ -65,8 +63,7 @@ static void proc_construct(opal_btl_usnic_proc_t* proc) opal_list_append(&mca_btl_usnic_component.usnic_procs, &proc->super); } - -static void proc_destruct(opal_btl_usnic_proc_t* proc) +static void proc_destruct(opal_btl_usnic_proc_t *proc) { /* remove from list of all proc instances */ opal_list_remove_item(&mca_btl_usnic_component.usnic_procs, &proc->super); @@ -94,27 +91,21 @@ static void proc_destruct(opal_btl_usnic_proc_t* proc) } } - -OBJ_CLASS_INSTANCE(opal_btl_usnic_proc_t, - opal_list_item_t, - proc_construct, - proc_destruct); +OBJ_CLASS_INSTANCE(opal_btl_usnic_proc_t, opal_list_item_t, proc_construct, proc_destruct); /* * Look for an existing usnic process instance based on the * associated opal_proc_t instance. */ -opal_btl_usnic_proc_t * -opal_btl_usnic_proc_lookup_ompi(opal_proc_t* opal_proc) +opal_btl_usnic_proc_t *opal_btl_usnic_proc_lookup_ompi(opal_proc_t *opal_proc) { - opal_btl_usnic_proc_t* usnic_proc; - - for (usnic_proc = (opal_btl_usnic_proc_t*) - opal_list_get_first(&mca_btl_usnic_component.usnic_procs); - usnic_proc != (opal_btl_usnic_proc_t*) - opal_list_get_end(&mca_btl_usnic_component.usnic_procs); - usnic_proc = (opal_btl_usnic_proc_t*) - opal_list_get_next(usnic_proc)) { + opal_btl_usnic_proc_t *usnic_proc; + + for (usnic_proc = (opal_btl_usnic_proc_t *) opal_list_get_first( + &mca_btl_usnic_component.usnic_procs); + usnic_proc + != (opal_btl_usnic_proc_t *) opal_list_get_end(&mca_btl_usnic_component.usnic_procs); + usnic_proc = (opal_btl_usnic_proc_t *) opal_list_get_next(usnic_proc)) { if (usnic_proc->proc_opal == opal_proc) { return usnic_proc; } @@ -123,38 +114,32 @@ opal_btl_usnic_proc_lookup_ompi(opal_proc_t* opal_proc) return NULL; } - /* * Look for an existing usnic proc based on a hashed RTE process * name. */ -opal_btl_usnic_endpoint_t * -opal_btl_usnic_proc_lookup_endpoint(opal_btl_usnic_module_t *receiver, - uint64_t sender_proc_name) +opal_btl_usnic_endpoint_t *opal_btl_usnic_proc_lookup_endpoint(opal_btl_usnic_module_t *receiver, + uint64_t sender_proc_name) { opal_btl_usnic_proc_t *proc; opal_btl_usnic_endpoint_t *endpoint; opal_list_item_t *item; - MSGDEBUG1_OUT("lookup_endpoint: recvmodule=%p sendhash=0x%" PRIx64, - (void *)receiver, sender_proc_name); + MSGDEBUG1_OUT("lookup_endpoint: recvmodule=%p sendhash=0x%" PRIx64, (void *) receiver, + sender_proc_name); opal_mutex_lock(&receiver->all_endpoints_lock); for (item = opal_list_get_first(&receiver->all_endpoints); - item != opal_list_get_end(&receiver->all_endpoints); - item = opal_list_get_next(item)) { - endpoint = container_of(item, opal_btl_usnic_endpoint_t, - endpoint_endpoint_li); + item != opal_list_get_end(&receiver->all_endpoints); item = opal_list_get_next(item)) { + endpoint = container_of(item, opal_btl_usnic_endpoint_t, endpoint_endpoint_li); proc = endpoint->endpoint_proc; /* Note that this works today because opal_proc_t->proc_name is unique across the universe. George is potentially working to give handles instead of proc names, and then have a function pointer to perform comparisons. This would be bad here in the critical path, though... */ - if (usnic_compat_rte_hash_name(&(proc->proc_opal->proc_name)) == - sender_proc_name) { - MSGDEBUG1_OUT("lookup_endpoint: matched endpoint=%p", - (void *)endpoint); + if (usnic_compat_rte_hash_name(&(proc->proc_opal->proc_name)) == sender_proc_name) { + MSGDEBUG1_OUT("lookup_endpoint: matched endpoint=%p", (void *) endpoint); opal_mutex_unlock(&receiver->all_endpoints_lock); return endpoint; } @@ -172,8 +157,7 @@ opal_btl_usnic_proc_lookup_endpoint(opal_btl_usnic_module_t *receiver, * Returns OPAL_ERR_UNREACH if we can't reach the peer (i.e., we can't * find their modex data). */ -static int create_proc(opal_proc_t *opal_proc, - opal_btl_usnic_proc_t **usnic_proc) +static int create_proc(opal_proc_t *opal_proc, opal_btl_usnic_proc_t **usnic_proc) { opal_btl_usnic_proc_t *proc = NULL; size_t size; @@ -192,8 +176,8 @@ static int create_proc(opal_proc_t *opal_proc, proc->proc_opal = opal_proc; /* query for the peer address info */ - usnic_compat_modex_recv(&rc, &mca_btl_usnic_component.super.btl_version, - opal_proc, &proc->proc_modex, &size); + usnic_compat_modex_recv(&rc, &mca_btl_usnic_component.super.btl_version, opal_proc, + &proc->proc_modex, &size); /* If this proc simply doesn't have this key, then they're not running the usnic BTL -- just ignore them. Otherwise, show an @@ -202,13 +186,9 @@ static int create_proc(opal_proc_t *opal_proc, OBJ_RELEASE(proc); return OPAL_ERR_UNREACH; } else if (OPAL_SUCCESS != rc) { - opal_show_help("help-mpi-btl-usnic.txt", - "internal error during init", - true, - opal_process_info.nodename, - "", "", - "opal_modex_recv() failed", __FILE__, __LINE__, - opal_strerror(rc)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, "", "", "opal_modex_recv() failed", + __FILE__, __LINE__, opal_strerror(rc)); OBJ_RELEASE(proc); return OPAL_ERROR; } @@ -216,16 +196,12 @@ static int create_proc(opal_proc_t *opal_proc, if ((size % sizeof(opal_btl_usnic_modex_t)) != 0) { char msg[1024]; - snprintf(msg, sizeof(msg), - "sizeof(modex for peer %s data) == %d, expected multiple of %d", - usnic_compat_proc_name_print(&opal_proc->proc_name), - (int) size, (int) sizeof(opal_btl_usnic_modex_t)); - opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", - true, - opal_process_info.nodename, - "", 0, - "invalid modex data", __FILE__, __LINE__, - msg); + snprintf(msg, sizeof(msg), "sizeof(modex for peer %s data) == %d, expected multiple of %d", + usnic_compat_proc_name_print(&opal_proc->proc_name), (int) size, + (int) sizeof(opal_btl_usnic_modex_t)); + opal_show_help("help-mpi-btl-usnic.txt", "internal error during init", true, + opal_process_info.nodename, "", 0, "invalid modex data", __FILE__, + __LINE__, msg); OBJ_RELEASE(proc); return OPAL_ERR_VALUE_OUT_OF_BOUNDS; @@ -233,22 +209,16 @@ static int create_proc(opal_proc_t *opal_proc, /* See if the peer has the same underlying wire protocol as me. If not, then print an error and ignore this peer. */ -// RFXXX - things are weird when i force this to fail - if (mca_btl_usnic_component.transport_protocol != - proc->proc_modex->protocol) { + // RFXXX - things are weird when i force this to fail + if (mca_btl_usnic_component.transport_protocol != proc->proc_modex->protocol) { uint64_t proto; char protostr[32]; proto = mca_btl_usnic_component.transport_protocol; memset(protostr, 0, sizeof(protostr)); - opal_string_copy(protostr, fi_tostr(&proto, FI_TYPE_PROTOCOL), - sizeof(protostr)); + opal_string_copy(protostr, fi_tostr(&proto, FI_TYPE_PROTOCOL), sizeof(protostr)); proto = proc->proc_modex->protocol; - opal_show_help("help-mpi-btl-usnic.txt", - "transport mismatch", - true, - opal_process_info.nodename, - protostr, - "peer", + opal_show_help("help-mpi-btl-usnic.txt", "transport mismatch", true, + opal_process_info.nodename, protostr, "peer", fi_tostr(&proto, FI_TYPE_PROTOCOL)); OBJ_RELEASE(proc); @@ -262,16 +232,15 @@ static int create_proc(opal_proc_t *opal_proc, return OPAL_ERR_UNREACH; } - proc->proc_modex_claimed = (bool*) - calloc(proc->proc_modex_count, sizeof(bool)); + proc->proc_modex_claimed = (bool *) calloc(proc->proc_modex_count, sizeof(bool)); if (NULL == proc->proc_modex_claimed) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); OBJ_RELEASE(proc); return OPAL_ERR_OUT_OF_RESOURCE; } - proc->proc_endpoints = (mca_btl_base_endpoint_t**) - calloc(proc->proc_modex_count, sizeof(mca_btl_base_endpoint_t*)); + proc->proc_endpoints = (mca_btl_base_endpoint_t **) calloc(proc->proc_modex_count, + sizeof(mca_btl_base_endpoint_t *)); if (NULL == proc->proc_endpoints) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); OBJ_RELEASE(proc); @@ -285,9 +254,8 @@ static int create_proc(opal_proc_t *opal_proc, /* Compare the addresses of the local interface corresponding to module and the * remote interface corresponding to proc_modex_addr. Returns a weight value * (higher values indicate more desirable connections). */ -static uint64_t compute_weight( - opal_btl_usnic_module_t *module, - opal_btl_usnic_modex_t *proc_modex_addr) +static uint64_t compute_weight(opal_btl_usnic_module_t *module, + opal_btl_usnic_modex_t *proc_modex_addr) { char my_ip_string[INET_ADDRSTRLEN], peer_ip_string[INET_ADDRSTRLEN]; struct sockaddr_in sin; @@ -300,10 +268,8 @@ static uint64_t compute_weight( uip = &module->usnic_info; sinp = module->fabric_info->src_addr; - inet_ntop(AF_INET, &sinp->sin_addr, - my_ip_string, sizeof(my_ip_string)); - inet_ntop(AF_INET, &proc_modex_addr->ipv4_addr, - peer_ip_string, sizeof(peer_ip_string)); + inet_ntop(AF_INET, &sinp->sin_addr, my_ip_string, sizeof(my_ip_string)); + inet_ntop(AF_INET, &proc_modex_addr->ipv4_addr, peer_ip_string, sizeof(peer_ip_string)); /* Just compare the CIDR-masked IP address to see if they're on the same network. If so, we're good. */ @@ -311,14 +277,11 @@ static uint64_t compute_weight( peernet = proc_modex_addr->ipv4_addr & proc_modex_addr->netmask; opal_output_verbose(5, USNIC_OUT, "btl:usnic:%s: checking my IP address/subnet (%s/%d) vs. peer (%s/%d): %s", - __func__, my_ip_string, - usnic_netmask_to_cidrlen(uip->ui.v1.ui_netmask_be), - peer_ip_string, - usnic_netmask_to_cidrlen(proc_modex_addr->netmask), + __func__, my_ip_string, usnic_netmask_to_cidrlen(uip->ui.v1.ui_netmask_be), + peer_ip_string, usnic_netmask_to_cidrlen(proc_modex_addr->netmask), (mynet == peernet ? "match" : "DO NOT match")); - min_link_speed_gbps = MIN(module->super.btl_bandwidth, - proc_modex_addr->link_speed_mbps) / 1000; + min_link_speed_gbps = MIN(module->super.btl_bandwidth, proc_modex_addr->link_speed_mbps) / 1000; /* Returned metric is: * 0 - same VLAN @@ -332,8 +295,7 @@ static uint64_t compute_weight( err = module->usnic_av_ops->get_distance(module->av, &sin, &metric); if (0 != err || (0 == err && -1 == metric)) { return 0; /* no connectivity */ - } - else { + } else { /* Format in binary MSB LSB * most sig. 32-bits: 00000000 0000000A BBBBBBBB 00000001 * least sig. 32-bits: CCCCCCCC CCCCCCCC CCCCCCCC CCCCCCCC @@ -359,10 +321,8 @@ static uint64_t compute_weight( min_link_speed_gbps); min_link_speed_gbps = 0xff; } - return ((uint64_t)(mynet == peernet) << 48) | - ((uint64_t)(min_link_speed_gbps & 0xff) << 40) | - ((uint64_t)0x1 << 32) | - (/*metric=*/0); + return ((uint64_t)(mynet == peernet) << 48) | ((uint64_t)(min_link_speed_gbps & 0xff) << 40) + | ((uint64_t) 0x1 << 32) | (/*metric=*/0); } } @@ -371,23 +331,20 @@ static uint64_t compute_weight( * (DJG: this unfortunately knows a bit too much about the internals of * "match_modex") */ -static void edge_pairs_to_match_table( - opal_btl_usnic_proc_t *proc, - bool proc_is_left, - int nme, - int *me) +static void edge_pairs_to_match_table(opal_btl_usnic_proc_t *proc, bool proc_is_left, int nme, + int *me) { int i; int left, right; int module_idx, proc_idx; int num_modules; - num_modules = (int)mca_btl_usnic_component.num_modules; + num_modules = (int) mca_btl_usnic_component.num_modules; assert(nme >= 0); for (i = 0; i < nme; ++i) { - left = me[2*i+0]; - right = me[2*i+1]; + left = me[2 * i + 0]; + right = me[2 * i + 1]; if (proc_is_left) { proc_idx = PROC_INDEX(left); @@ -397,7 +354,7 @@ static void edge_pairs_to_match_table( proc_idx = PROC_INDEX(right); } assert(module_idx >= 0 && module_idx < num_modules); - assert(proc_idx >= 0 && proc_idx < (int)proc->proc_modex_count); + assert(proc_idx >= 0 && proc_idx < (int) proc->proc_modex_count); proc->proc_ep_match_table[module_idx] = proc_idx; proc->proc_match_exists = true; } @@ -405,17 +362,15 @@ static void edge_pairs_to_match_table( /* emit match summary for debugging purposes */ for (i = 0; i < num_modules; ++i) { if (-1 != proc->proc_ep_match_table[i]) { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:%s: module[%d] (%p) should claim endpoint[%d] on proc %p", - __func__, i, - (void *)mca_btl_usnic_component.usnic_active_modules[i], - proc->proc_ep_match_table[i], (void *)proc); + opal_output_verbose( + 5, USNIC_OUT, "btl:usnic:%s: module[%d] (%p) should claim endpoint[%d] on proc %p", + __func__, i, (void *) mca_btl_usnic_component.usnic_active_modules[i], + proc->proc_ep_match_table[i], (void *) proc); } else { - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:%s: module[%d] (%p) will NOT claim an endpoint on proc %p", - __func__, i, - (void *)mca_btl_usnic_component.usnic_active_modules[i], - (void *)proc); + opal_output_verbose( + 5, USNIC_OUT, "btl:usnic:%s: module[%d] (%p) will NOT claim an endpoint on proc %p", + __func__, i, (void *) mca_btl_usnic_component.usnic_active_modules[i], + (void *) proc); } } } @@ -425,10 +380,8 @@ static void edge_pairs_to_match_table( * remote interfaces. The resulting vertices will always have the module * vertices appear before the proc vertices. */ -static int create_proc_module_graph( - opal_btl_usnic_proc_t *proc, - bool proc_is_left, - opal_bp_graph_t **g_out) +static int create_proc_module_graph(opal_btl_usnic_proc_t *proc, bool proc_is_left, + opal_bp_graph_t **g_out) { int err; int i, j; @@ -441,7 +394,7 @@ static int create_proc_module_graph( } *g_out = NULL; - num_modules = (int)mca_btl_usnic_component.num_modules; + num_modules = (int) mca_btl_usnic_component.num_modules; /* Construct a bipartite graph with remote interfaces on the one side and * local interfaces (modules) on the other. */ @@ -454,28 +407,26 @@ static int create_proc_module_graph( /* create vertices for each interface (local and remote) */ for (i = 0; i < num_modules; ++i) { int idx = -1; - err = opal_bp_graph_add_vertex(g, - mca_btl_usnic_component.usnic_active_modules[i], - &idx); + err = opal_bp_graph_add_vertex(g, mca_btl_usnic_component.usnic_active_modules[i], &idx); if (OPAL_SUCCESS != err) { OPAL_ERROR_LOG(err); goto out_free_graph; } assert(idx == MODULE_VERTEX(i)); } - for (i = 0; i < (int)proc->proc_modex_count; ++i) { + for (i = 0; i < (int) proc->proc_modex_count; ++i) { int idx = -1; err = opal_bp_graph_add_vertex(g, &proc->proc_modex[i], &idx); if (OPAL_SUCCESS != err) { OPAL_ERROR_LOG(err); goto out_free_graph; } - assert(idx == (int)PROC_VERTEX(i)); + assert(idx == (int) PROC_VERTEX(i)); } /* now add edges between interfaces that can communicate */ for (i = 0; i < num_modules; ++i) { - for (j = 0; j < (int)proc->proc_modex_count; ++j) { + for (j = 0; j < (int) proc->proc_modex_count; ++j) { int64_t weight, cost; /* assumption: compute_weight returns the same weight on the @@ -484,11 +435,11 @@ static int create_proc_module_graph( &proc->proc_modex[j]); opal_output_verbose(20, USNIC_OUT, - "btl:usnic:%s: weight=0x%016" PRIx64 " for edge module[%d] (%p) <--> endpoint[%d] on proc %p", - __func__, - weight, i, - (void *)mca_btl_usnic_component.usnic_active_modules[i], - j, (void *)proc); + "btl:usnic:%s: weight=0x%016" PRIx64 + " for edge module[%d] (%p) <--> endpoint[%d] on proc %p", + __func__, weight, i, + (void *) mca_btl_usnic_component.usnic_active_modules[i], j, + (void *) proc); if (WEIGHT_UNREACHABLE == weight) { continue; @@ -508,11 +459,12 @@ static int create_proc_module_graph( v = PROC_VERTEX(j); } opal_output_verbose(20, USNIC_OUT, - "btl:usnic:%s: adding edge (%d,%d) with cost=%" PRIi64 " for edge module[%d] <--> endpoint[%d]", + "btl:usnic:%s: adding edge (%d,%d) with cost=%" PRIi64 + " for edge module[%d] <--> endpoint[%d]", __func__, u, v, cost, i, j); err = opal_bp_graph_add_edge(g, u, v, cost, - /*capacity=*/1, - /*e_data=*/NULL); + /*capacity=*/1, + /*e_data=*/NULL); if (OPAL_SUCCESS != err) { OPAL_ERROR_LOG(err); goto out_free_graph; @@ -541,9 +493,7 @@ static int create_proc_module_graph( * canonicalize this match ordering somehow, probably by (jobid,vpid) pair or * by the interface MAC or IP address. */ -static int match_modex(opal_btl_usnic_module_t *module, - opal_btl_usnic_proc_t *proc, - int *index_out) +static int match_modex(opal_btl_usnic_module_t *module, opal_btl_usnic_proc_t *proc, int *index_out) { int err = OPAL_SUCCESS; size_t i; @@ -559,15 +509,14 @@ static int match_modex(opal_btl_usnic_module_t *module, num_modules = mca_btl_usnic_component.num_modules; opal_output_verbose(20, USNIC_OUT, "btl:usnic:%s: module=%p proc=%p with dimensions %d x %d", - __func__, (void *)module, (void *)proc, - num_modules, (int)proc->proc_modex_count); + __func__, (void *) module, (void *) proc, num_modules, + (int) proc->proc_modex_count); /* We compute an interface match-up table once for each (module,proc) pair * and cache it in the proc. Store per-proc instead of per-module, since * MPI dynamic process routines can add procs but not new modules. */ if (NULL == proc->proc_ep_match_table) { - proc->proc_ep_match_table = malloc(num_modules * - sizeof(*proc->proc_ep_match_table)); + proc->proc_ep_match_table = malloc(num_modules * sizeof(*proc->proc_ep_match_table)); if (NULL == proc->proc_ep_match_table) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); return OPAL_ERR_OUT_OF_RESOURCE; @@ -588,9 +537,8 @@ static int match_modex(opal_btl_usnic_module_t *module, proc_is_left = (proc->proc_opal->proc_name < opal_proc_local_get()->proc_name); #else - proc_is_left = - usnic_compat_proc_name_compare(proc->proc_opal->proc_name, - opal_proc_local_get()->proc_name); + proc_is_left = usnic_compat_proc_name_compare(proc->proc_opal->proc_name, + opal_proc_local_get()->proc_name); #endif err = create_proc_module_graph(proc, proc_is_left, &g); @@ -616,11 +564,10 @@ static int match_modex(opal_btl_usnic_module_t *module, } } - if (!proc->proc_match_exists) { - opal_output_verbose(5, USNIC_OUT, "btl:usnic:%s: unable to find any valid interface pairs for proc %s", - __func__, - usnic_compat_proc_name_print(&proc->proc_opal->proc_name)); + opal_output_verbose(5, USNIC_OUT, + "btl:usnic:%s: unable to find any valid interface pairs for proc %s", + __func__, usnic_compat_proc_name_print(&proc->proc_opal->proc_name)); return OPAL_ERR_NOT_FOUND; } @@ -638,17 +585,13 @@ static int match_modex(opal_btl_usnic_module_t *module, /* TODO with UDP, do we still want to enforce this restriction or just take * the min of the two MTUs? Another choice is to disqualify this pairing * before running the matching algorithm on it. */ - if (*index_out >= 0 && - proc->proc_modex[*index_out].max_msg_size != - (uint16_t) module->fabric_info->ep_attr->max_msg_size) { + if (*index_out >= 0 + && proc->proc_modex[*index_out].max_msg_size + != (uint16_t) module->fabric_info->ep_attr->max_msg_size) { char *errhost = opal_get_proc_hostname(proc->proc_opal); - opal_show_help("help-mpi-btl-usnic.txt", "MTU mismatch", - true, - opal_process_info.nodename, - module->linux_device_name, - module->fabric_info->ep_attr->max_msg_size, - errhost, - proc->proc_modex[*index_out].max_msg_size); + opal_show_help("help-mpi-btl-usnic.txt", "MTU mismatch", true, opal_process_info.nodename, + module->linux_device_name, module->fabric_info->ep_attr->max_msg_size, + errhost, proc->proc_modex[*index_out].max_msg_size); free(errhost); *index_out = -1; return OPAL_ERR_UNREACH; @@ -669,9 +612,8 @@ static int match_modex(opal_btl_usnic_module_t *module, * Initiate the process to create a USD dest. * It will be polled for completion later. */ -static int start_av_insert(opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint, - int channel) +static int start_av_insert(opal_btl_usnic_module_t *module, opal_btl_usnic_endpoint_t *endpoint, + int channel) { int ret; opal_btl_usnic_modex_t *modex = &endpoint->endpoint_remote_modex; @@ -683,11 +625,9 @@ static int start_av_insert(opal_btl_usnic_module_t *module, context->channel_id = channel; char str[IPV4STRADDRLEN]; - opal_btl_usnic_snprintf_ipv4_addr(str, sizeof(str), modex->ipv4_addr, - modex->netmask); - opal_output_verbose(5, USNIC_OUT, - "btl:usnic:start_av_insert: to channel %d at %s:%d", - channel, str, modex->ports[channel]); + opal_btl_usnic_snprintf_ipv4_addr(str, sizeof(str), modex->ipv4_addr, modex->netmask); + opal_output_verbose(5, USNIC_OUT, "btl:usnic:start_av_insert: to channel %d at %s:%d", channel, + str, modex->ports[channel]); /* build remote address */ memset(&sin, 0, sizeof(sin)); @@ -695,17 +635,12 @@ static int start_av_insert(opal_btl_usnic_module_t *module, sin.sin_port = htons(modex->ports[channel]); sin.sin_addr.s_addr = modex->ipv4_addr; - ret = fi_av_insert(module->av, &sin, 1, - &endpoint->endpoint_remote_addrs[channel], 0, context); + ret = fi_av_insert(module->av, &sin, 1, &endpoint->endpoint_remote_addrs[channel], 0, context); /* Did an error occur? */ if (0 != ret) { - opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", - true, - opal_process_info.nodename, - module->linux_device_name, - "fi_av_insert()", __FILE__, __LINE__, - ret, - "Failed to initiate AV insert"); + opal_show_help("help-mpi-btl-usnic.txt", "libfabric API failed", true, + opal_process_info.nodename, module->linux_device_name, "fi_av_insert()", + __FILE__, __LINE__, ret, "Failed to initiate AV insert"); free(context); return OPAL_ERROR; } @@ -716,10 +651,8 @@ static int start_av_insert(opal_btl_usnic_module_t *module, /* * Create an endpoint and claim the matched modex slot */ -int -opal_btl_usnic_create_endpoint(opal_btl_usnic_module_t *module, - opal_btl_usnic_proc_t *proc, - opal_btl_usnic_endpoint_t **endpoint_o) +int opal_btl_usnic_create_endpoint(opal_btl_usnic_module_t *module, opal_btl_usnic_proc_t *proc, + opal_btl_usnic_endpoint_t **endpoint_o) { int rc; int modex_index; @@ -741,13 +674,13 @@ opal_btl_usnic_create_endpoint(opal_btl_usnic_module_t *module, /* Initalize the endpoint */ endpoint->endpoint_module = module; - assert(modex_index >= 0 && modex_index < (int)proc->proc_modex_count); + assert(modex_index >= 0 && modex_index < (int) proc->proc_modex_count); endpoint->endpoint_remote_modex = proc->proc_modex[modex_index]; endpoint->endpoint_send_credits = module->sd_num; /* Start creating destinations; one for each channel. These progress in the background.a */ - for (int i = 0; i < USNIC_NUM_CHANNELS; ++i) { + for (int i = 0; i < USNIC_NUM_CHANNELS; ++i) { rc = start_av_insert(module, endpoint, i); if (OPAL_SUCCESS != rc) { OBJ_RELEASE(endpoint); @@ -758,17 +691,15 @@ opal_btl_usnic_create_endpoint(opal_btl_usnic_module_t *module, /* Initialize endpoint sequence number info */ endpoint->endpoint_next_seq_to_send = module->local_modex.isn; endpoint->endpoint_ack_seq_rcvd = endpoint->endpoint_next_seq_to_send - 1; - endpoint->endpoint_next_contig_seq_to_recv = - endpoint->endpoint_remote_modex.isn; - endpoint->endpoint_highest_seq_rcvd = - endpoint->endpoint_next_contig_seq_to_recv - 1; + endpoint->endpoint_next_contig_seq_to_recv = endpoint->endpoint_remote_modex.isn; + endpoint->endpoint_highest_seq_rcvd = endpoint->endpoint_next_contig_seq_to_recv - 1; endpoint->endpoint_rfstart = WINDOW_SIZE_MOD(endpoint->endpoint_next_contig_seq_to_recv); /* Now claim that modex slot */ proc->proc_modex_claimed[modex_index] = true; - MSGDEBUG1_OUT("create_endpoint: module=%p claimed endpoint=%p on proc=%p (hash=0x%" PRIx64 ")\n", - (void *)module, (void *)endpoint, (void *)proc, - proc->proc_opal->proc_name); + MSGDEBUG1_OUT("create_endpoint: module=%p claimed endpoint=%p on proc=%p (hash=0x%" PRIx64 + ")\n", + (void *) module, (void *) endpoint, (void *) proc, proc->proc_opal->proc_name); /* Save the endpoint on this proc's array of endpoints */ proc->proc_endpoints[proc->proc_endpoint_count] = endpoint; @@ -781,8 +712,7 @@ opal_btl_usnic_create_endpoint(opal_btl_usnic_module_t *module, not in the endpoint constructor because we aren't able to pass the module as a constructor argument -- doh!). */ opal_mutex_lock(&module->all_endpoints_lock); - opal_list_append(&(module->all_endpoints), - &(endpoint->endpoint_endpoint_li)); + opal_list_append(&(module->all_endpoints), &(endpoint->endpoint_endpoint_li)); endpoint->endpoint_on_all_endpoints = true; opal_mutex_unlock(&module->all_endpoints_lock); @@ -807,8 +737,7 @@ opal_btl_usnic_create_endpoint(opal_btl_usnic_module_t *module, * opal_btl_usnic_endpoint_t instances, and published addresses/modex * info. */ -int opal_btl_usnic_proc_match(opal_proc_t *opal_proc, - opal_btl_usnic_module_t *module, +int opal_btl_usnic_proc_match(opal_proc_t *opal_proc, opal_btl_usnic_module_t *module, opal_btl_usnic_proc_t **proc) { /* Check if we have already created a proc structure for this peer diff --git a/opal/mca/btl/usnic/btl_usnic_proc.h b/opal/mca/btl/usnic/btl_usnic_proc.h index 2365c8b5d6a..7c8f2c4da06 100644 --- a/opal/mca/btl/usnic/btl_usnic_proc.h +++ b/opal/mca/btl/usnic/btl_usnic_proc.h @@ -45,7 +45,7 @@ typedef struct opal_btl_usnic_proc_t { opal_proc_t *proc_opal; /** Addresses received via modex for this remote proc */ - opal_btl_usnic_modex_t* proc_modex; + opal_btl_usnic_modex_t *proc_modex; /** Number of entries in the proc_modex array */ size_t proc_modex_count; /** Whether the modex entry is "claimed" by a module or not */ @@ -78,8 +78,7 @@ typedef struct opal_btl_usnic_proc_t { OBJ_CLASS_DECLARATION(opal_btl_usnic_proc_t); - -opal_btl_usnic_proc_t *opal_btl_usnic_proc_lookup_ompi(opal_proc_t* opal_proc); +opal_btl_usnic_proc_t *opal_btl_usnic_proc_lookup_ompi(opal_proc_t *opal_proc); struct opal_btl_usnic_module_t; @@ -87,13 +86,11 @@ opal_btl_usnic_endpoint_t * opal_btl_usnic_proc_lookup_endpoint(struct opal_btl_usnic_module_t *receiver, uint64_t sender_hashed_rte_name); -int opal_btl_usnic_proc_match(opal_proc_t* opal_proc, - struct opal_btl_usnic_module_t *module, +int opal_btl_usnic_proc_match(opal_proc_t *opal_proc, struct opal_btl_usnic_module_t *module, opal_btl_usnic_proc_t **proc); -int -opal_btl_usnic_create_endpoint(struct opal_btl_usnic_module_t *module, - opal_btl_usnic_proc_t *proc, - opal_btl_usnic_endpoint_t **endpoint_o); +int opal_btl_usnic_create_endpoint(struct opal_btl_usnic_module_t *module, + opal_btl_usnic_proc_t *proc, + opal_btl_usnic_endpoint_t **endpoint_o); END_C_DECLS diff --git a/opal/mca/btl/usnic/btl_usnic_recv.c b/opal/mca/btl/usnic/btl_usnic_recv.c index 535ced87363..598dbd081db 100644 --- a/opal/mca/btl/usnic/btl_usnic_recv.c +++ b/opal/mca/btl/usnic/btl_usnic_recv.c @@ -26,33 +26,31 @@ #include -#include "opal_stdint.h" -#include "opal/mca/memchecker/base/base.h" #include "opal/constants.h" +#include "opal/mca/memchecker/base/base.h" +#include "opal_stdint.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "btl_usnic.h" -#include "btl_usnic_frag.h" +#include "btl_usnic_ack.h" #include "btl_usnic_endpoint.h" +#include "btl_usnic_frag.h" #include "btl_usnic_module.h" #include "btl_usnic_proc.h" -#include "btl_usnic_ack.h" #include "btl_usnic_recv.h" #include "btl_usnic_util.h" - /* * We have received a segment, take action based on the * packet type in the BTL header */ -void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, - opal_btl_usnic_recv_segment_t *seg, +void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, opal_btl_usnic_recv_segment_t *seg, opal_btl_usnic_channel_t *channel) { opal_btl_usnic_segment_t *bseg; - mca_btl_active_message_callback_t* reg; + mca_btl_active_message_callback_t *reg; opal_btl_usnic_endpoint_t *endpoint; opal_btl_usnic_btl_chunk_header_t *chunk_hdr; opal_btl_usnic_btl_header_t *hdr; @@ -68,16 +66,14 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, ++module->stats.num_total_recvs; /* Valgrind help */ - opal_memchecker_base_mem_defined((void*)(seg->rs_protocol_header), - seg->rs_len); + opal_memchecker_base_mem_defined((void *) (seg->rs_protocol_header), seg->rs_len); /* Find out who sent this segment */ endpoint = seg->rs_endpoint; if (FAKE_RECV_DROP || OPAL_UNLIKELY(NULL == endpoint)) { /* No idea who this was from, so drop it */ #if MSGDEBUG1 - opal_output(0, "=== Unknown sender; dropped: seq %" UDSEQ, - bseg->us_btl_header->pkt_seq); + opal_output(0, "=== Unknown sender; dropped: seq %" UDSEQ, bseg->us_btl_header->pkt_seq); #endif ++module->stats.num_unk_recvs; goto repost_no_endpoint; @@ -87,12 +83,9 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, struct opal_btl_usnic_modex_t *modex; modex = &module->local_modex; - opal_btl_usnic_snprintf_ipv4_addr(local_ip, sizeof(local_ip), - modex->ipv4_addr, - modex->netmask); + opal_btl_usnic_snprintf_ipv4_addr(local_ip, sizeof(local_ip), modex->ipv4_addr, modex->netmask); modex = &endpoint->endpoint_remote_modex; - opal_btl_usnic_snprintf_ipv4_addr(remote_ip, sizeof(remote_ip), - modex->ipv4_addr, + opal_btl_usnic_snprintf_ipv4_addr(remote_ip, sizeof(remote_ip), modex->ipv4_addr, modex->netmask); #endif @@ -109,9 +102,9 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, hdr = seg->rs_base.us_btl_header; #if MSGDEBUG1 - opal_output(0, "<-- Received FRAG ep %p, seq %" UDSEQ ", len=%d\n", - (void*) endpoint, hdr->pkt_seq, hdr->payload_len); -#if 0 + opal_output(0, "<-- Received FRAG ep %p, seq %" UDSEQ ", len=%d\n", (void *) endpoint, + hdr->pkt_seq, hdr->payload_len); +# if 0 opal_output(0, "<-- Received FRAG ep %p, seq %" UDSEQ " from %s to %s: GOOD! (rel seq %d, lowest seq %" UDSEQ ", highest seq: %" UDSEQ ", rwstart %d) seg %p, module %p\n", (void*) endpoint, @@ -126,7 +119,7 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, opal_output(0, " put_addr = %p\n", seg->rs_base.us_btl_header->put_addr); } -#endif +# endif #endif /* If this it not a PUT, Pass this segment up to the PML. @@ -139,27 +132,25 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, reg = mca_btl_base_active_message_trigger + hdr->tag; seg->rs_segment.seg_len = hdr->payload_len; #if MSGDEBUG2 - opal_output(0, "small recv complete, pass up %u bytes, tag=%d\n", - (unsigned)bseg->us_btl_header->payload_len, - (int)bseg->us_btl_header->tag); + opal_output(0, "small recv complete, pass up %u bytes, tag=%d\n", + (unsigned) bseg->us_btl_header->payload_len, + (int) bseg->us_btl_header->tag); #endif seg->rs_desc.endpoint = endpoint; seg->rs_desc.tag = hdr->tag; seg->rs_desc.cbdata = reg->cbdata; reg->cbfunc(&module->super, &seg->rs_desc); - /* - * If this is a PUT, need to copy it to user buffer - */ + /* + * If this is a PUT, need to copy it to user buffer + */ } else { #if MSGDEBUG1 - opal_output(0, "Copy %d PUT bytes to %p\n", - seg->rs_base.us_btl_header->payload_len, - (void*)seg->rs_base.us_btl_header->put_addr); + opal_output(0, "Copy %d PUT bytes to %p\n", seg->rs_base.us_btl_header->payload_len, + (void *) seg->rs_base.us_btl_header->put_addr); #endif - memcpy(seg->rs_base.us_btl_header->put_addr, - seg->rs_base.us_payload.raw, - seg->rs_base.us_btl_header->payload_len); + memcpy(seg->rs_base.us_btl_header->put_addr, seg->rs_base.us_payload.raw, + seg->rs_base.us_btl_header->payload_len); } /* do not jump to repost, already done by bookkeeping */ @@ -173,22 +164,20 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, opal_btl_usnic_rx_frag_info_t *fip; /* Is incoming sequence # ok? */ - if (OPAL_UNLIKELY(opal_btl_usnic_check_rx_seq(endpoint, seg, - &window_index) != 0)) { + if (OPAL_UNLIKELY(opal_btl_usnic_check_rx_seq(endpoint, seg, &window_index) != 0)) { goto repost; } #if MSGDEBUG1 - opal_output(0, "<-- Received CHUNK fid %d ep %p, seq %" UDSEQ " from %s to %s: GOOD! (rel seq %d, lowest seq %" UDSEQ ", highest seq: %" UDSEQ ", rwstart %d) seg %p, module %p\n", - seg->rs_base.us_btl_chunk_header->ch_frag_id, - (void*) endpoint, - seg->rs_base.us_btl_chunk_header->ch_hdr.pkt_seq, - remote_ip, local_ip, - window_index, - endpoint->endpoint_next_contig_seq_to_recv, - endpoint->endpoint_highest_seq_rcvd, - endpoint->endpoint_rfstart, - (void*) seg, (void*) module); + opal_output(0, + "<-- Received CHUNK fid %d ep %p, seq %" UDSEQ + " from %s to %s: GOOD! (rel seq %d, lowest seq %" UDSEQ ", highest seq: %" UDSEQ + ", rwstart %d) seg %p, module %p\n", + seg->rs_base.us_btl_chunk_header->ch_frag_id, (void *) endpoint, + seg->rs_base.us_btl_chunk_header->ch_hdr.pkt_seq, remote_ip, local_ip, + window_index, endpoint->endpoint_next_contig_seq_to_recv, + endpoint->endpoint_highest_seq_rcvd, endpoint->endpoint_rfstart, (void *) seg, + (void *) module); #endif /* start a new fragment if not one in progress @@ -211,13 +200,12 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, /* See which data pool this should come from, * or if it should be malloc()ed */ - pool = usnic_fls(chunk_hdr->ch_frag_size-1); - if (pool >= module->first_pool && - pool <= module->last_pool) { - opal_free_list_item_t* item; + pool = usnic_fls(chunk_hdr->ch_frag_size - 1); + if (pool >= module->first_pool && pool <= module->last_pool) { + opal_free_list_item_t *item; opal_btl_usnic_rx_buf_t *rx_buf; USNIC_COMPAT_FREE_LIST_GET(&module->module_recv_buffers[pool], item); - rx_buf = (opal_btl_usnic_rx_buf_t *)item; + rx_buf = (opal_btl_usnic_rx_buf_t *) item; if (OPAL_LIKELY(NULL != rx_buf)) { fip->rfi_fl_elt = item; fip->rfi_data = rx_buf->buf; @@ -233,42 +221,38 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, opal_btl_usnic_util_abort("malloc failed", __FILE__, __LINE__); } #if MSGDEBUG1 - opal_output(0, "Start large recv to %p, size=%"PRIu32"\n", - (void *)fip->rfi_data, chunk_hdr->ch_frag_size); + opal_output(0, "Start large recv to %p, size=%" PRIu32 "\n", (void *) fip->rfi_data, + chunk_hdr->ch_frag_size); #endif } else { #if MSGDEBUG1 - opal_output(0, "Start PUT to %p\n", - (void *)chunk_hdr->ch_hdr.put_addr); + opal_output(0, "Start PUT to %p\n", (void *) chunk_hdr->ch_hdr.put_addr); #endif fip->rfi_data = chunk_hdr->ch_hdr.put_addr; } fip->rfi_bytes_left = chunk_hdr->ch_frag_size; fip->rfi_frag_id = chunk_hdr->ch_frag_id; - /* frag_id is not 0 - it must match, drop if not */ + /* frag_id is not 0 - it must match, drop if not */ } else if (fip->rfi_frag_id != chunk_hdr->ch_frag_id) { ++module->stats.num_badfrag_recvs; goto repost; } #if MSGDEBUG1 - opal_output(0, "put_addr=%p, copy_addr=%p, off=%d\n", - chunk_hdr->ch_hdr.put_addr, - fip->rfi_data+chunk_hdr->ch_frag_offset, - chunk_hdr->ch_frag_offset); + opal_output(0, "put_addr=%p, copy_addr=%p, off=%d\n", chunk_hdr->ch_hdr.put_addr, + fip->rfi_data + chunk_hdr->ch_frag_offset, chunk_hdr->ch_frag_offset); #endif /* Stats */ ++module->stats.num_chunk_recvs; /* validate offset and len to be within fragment */ - assert(chunk_hdr->ch_frag_offset + chunk_hdr->ch_hdr.payload_len <= - fip->rfi_frag_size); + assert(chunk_hdr->ch_frag_offset + chunk_hdr->ch_hdr.payload_len <= fip->rfi_frag_size); assert(fip->rfi_frag_size == chunk_hdr->ch_frag_size); /* copy the data into place */ - memcpy(fip->rfi_data + chunk_hdr->ch_frag_offset, (char *)(chunk_hdr+1), - chunk_hdr->ch_hdr.payload_len); + memcpy(fip->rfi_data + chunk_hdr->ch_frag_offset, (char *) (chunk_hdr + 1), + chunk_hdr->ch_hdr.payload_len); /* update sliding window */ opal_btl_usnic_update_window(endpoint, window_index); @@ -289,12 +273,10 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, /* Pass this segment up to the PML */ #if MSGDEBUG2 opal_output(0, "large recv complete, pass up %p, %u bytes, tag=%d\n", - desc.USNIC_RECV_LOCAL->seg_addr.pval, - (unsigned)desc.USNIC_RECV_LOCAL->seg_len, - (int)chunk_hdr->ch_hdr.tag); + desc.USNIC_RECV_LOCAL->seg_addr.pval, + (unsigned) desc.USNIC_RECV_LOCAL->seg_len, (int) chunk_hdr->ch_hdr.tag); #endif - reg = mca_btl_base_active_message_trigger + - chunk_hdr->ch_hdr.tag; + reg = mca_btl_base_active_message_trigger + chunk_hdr->ch_hdr.tag; /* mca_pml_ob1_recv_frag_callback_frag() */ desc.endpoint = endpoint; @@ -327,8 +309,7 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, /***********************************************************************/ /* Frag is an incoming ACK */ - else if (OPAL_LIKELY(OPAL_BTL_USNIC_PAYLOAD_TYPE_ACK == - bseg->us_btl_header->payload_type)) { + else if (OPAL_LIKELY(OPAL_BTL_USNIC_PAYLOAD_TYPE_ACK == bseg->us_btl_header->payload_type)) { opal_btl_usnic_seq_t ack_seq; /* sequence being ACKed */ @@ -352,21 +333,24 @@ void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, else { ++module->stats.num_unk_recvs; if (module->stats.num_unk_recvs < 10) { - opal_output_verbose(15, USNIC_OUT, "unrecognized payload type %d", bseg->us_btl_header->payload_type); - opal_output_verbose(15, USNIC_OUT, "base = %p, proto = %p, hdr = %p", bseg->us_list.ptr, seg->rs_protocol_header, (void*) bseg->us_btl_header); - opal_btl_usnic_dump_hex(15, USNIC_OUT, bseg->us_list.ptr, 96+sizeof(*bseg->us_btl_header)); + opal_output_verbose(15, USNIC_OUT, "unrecognized payload type %d", + bseg->us_btl_header->payload_type); + opal_output_verbose(15, USNIC_OUT, "base = %p, proto = %p, hdr = %p", bseg->us_list.ptr, + seg->rs_protocol_header, (void *) bseg->us_btl_header); + opal_btl_usnic_dump_hex(15, USNIC_OUT, bseg->us_list.ptr, + 96 + sizeof(*bseg->us_btl_header)); } goto repost; } /***********************************************************************/ - repost: +repost: /* if endpoint exiting, and all ACKs received, release the endpoint */ if (endpoint->endpoint_exiting && ENDPOINT_DRAINED(endpoint)) { OBJ_RELEASE(endpoint); } - repost_no_endpoint: +repost_no_endpoint: ++module->stats.num_recv_reposts; /* Add recv to linked list for reposting */ diff --git a/opal/mca/btl/usnic/btl_usnic_recv.h b/opal/mca/btl/usnic/btl_usnic_recv.h index 0a663fe60cf..8c58c528d52 100644 --- a/opal/mca/btl/usnic/btl_usnic_recv.h +++ b/opal/mca/btl/usnic/btl_usnic_recv.h @@ -12,17 +12,14 @@ #define BTL_USNIC_RECV_H #include "btl_usnic.h" -#include "btl_usnic_util.h" #include "btl_usnic_frag.h" #include "btl_usnic_proc.h" +#include "btl_usnic_util.h" - -void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, - opal_btl_usnic_recv_segment_t *rseg, +void opal_btl_usnic_recv_call(opal_btl_usnic_module_t *module, opal_btl_usnic_recv_segment_t *rseg, opal_btl_usnic_channel_t *channel); -static inline int -opal_btl_usnic_post_recv_list(opal_btl_usnic_channel_t *channel) +static inline int opal_btl_usnic_post_recv_list(opal_btl_usnic_channel_t *channel) { struct iovec iov; struct fi_msg msg; @@ -57,8 +54,8 @@ opal_btl_usnic_post_recv_list(opal_btl_usnic_channel_t *channel) /* * Given an incoming segment, lookup the endpoint that sent it */ -static inline opal_btl_usnic_endpoint_t * -lookup_sender(opal_btl_usnic_module_t *module, opal_btl_usnic_segment_t *seg) +static inline opal_btl_usnic_endpoint_t *lookup_sender(opal_btl_usnic_module_t *module, + opal_btl_usnic_segment_t *seg) { int ret; opal_btl_usnic_endpoint_t *sender; @@ -72,20 +69,17 @@ lookup_sender(opal_btl_usnic_module_t *module, opal_btl_usnic_segment_t *seg) btl_header->sender, echo back the ptr to the sender's ompi_proc. There was limited speedup with this scheme; more investigation is required. */ - ret = opal_hash_table_get_value_uint64(&module->senders, - seg->us_btl_header->sender, - (void**) &sender); + ret = opal_hash_table_get_value_uint64(&module->senders, seg->us_btl_header->sender, + (void **) &sender); if (OPAL_LIKELY(OPAL_SUCCESS == ret)) { return sender; } /* The sender wasn't in the hash table, so do a slow lookup and put the result in the hash table */ - sender = opal_btl_usnic_proc_lookup_endpoint(module, - seg->us_btl_header->sender); + sender = opal_btl_usnic_proc_lookup_endpoint(module, seg->us_btl_header->sender); if (NULL != sender) { - opal_hash_table_set_value_uint64(&module->senders, - seg->us_btl_header->sender, sender); + opal_hash_table_set_value_uint64(&module->senders, seg->us_btl_header->sender, sender); return sender; } @@ -98,16 +92,15 @@ lookup_sender(opal_btl_usnic_module_t *module, opal_btl_usnic_segment_t *seg) * to indicate that it and possible following contiguous sequence * numbers have been received. */ -static inline void -opal_btl_usnic_update_window( - opal_btl_usnic_endpoint_t *endpoint, - uint32_t window_index) +static inline void opal_btl_usnic_update_window(opal_btl_usnic_endpoint_t *endpoint, + uint32_t window_index) { uint32_t i; /* Enable ACK reply if not enabled */ #if MSGDEBUG1 - opal_output(0, "ep: %p, ack_needed = %s\n", (void*)endpoint, endpoint->endpoint_ack_needed?"true":"false"); + opal_output(0, "ep: %p, ack_needed = %s\n", (void *) endpoint, + endpoint->endpoint_ack_needed ? "true" : "false"); #endif if (!endpoint->endpoint_ack_needed) { opal_btl_usnic_add_to_endpoints_needing_ack(endpoint); @@ -117,8 +110,7 @@ opal_btl_usnic_update_window( incoming DATA_CHANNEL component.act_iteration_delay times (i.e., so we can piggyback an ACK on an outgoing send) */ if (0 == endpoint->endpoint_acktime) { - endpoint->endpoint_acktime = - get_ticks() + mca_btl_usnic_component.ack_iteration_delay; + endpoint->endpoint_acktime = get_ticks() + mca_btl_usnic_component.ack_iteration_delay; } /* Save this incoming segment in the received segmentss array on the @@ -144,11 +136,9 @@ opal_btl_usnic_update_window( endpoint->endpoint_rfstart = i; } -static inline int -opal_btl_usnic_check_rx_seq( - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_recv_segment_t *seg, - uint32_t *window_index) +static inline int opal_btl_usnic_check_rx_seq(opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_recv_segment_t *seg, + uint32_t *window_index) { uint32_t i; opal_btl_usnic_seq_t seq; @@ -159,11 +149,11 @@ opal_btl_usnic_check_rx_seq( */ if (seg->rs_base.us_btl_header->ack_present) { #if MSGDEBUG1 - opal_output(0, "Handle piggy-packed ACK seq %"UDSEQ"\n", seg->rs_base.us_btl_header->ack_seq); + opal_output(0, "Handle piggy-packed ACK seq %" UDSEQ "\n", + seg->rs_base.us_btl_header->ack_seq); #endif OPAL_THREAD_LOCK(&btl_usnic_lock); - opal_btl_usnic_handle_ack(endpoint, - seg->rs_base.us_btl_header->ack_seq); + opal_btl_usnic_handle_ack(endpoint, seg->rs_base.us_btl_header->ack_seq); OPAL_THREAD_UNLOCK(&btl_usnic_lock); } @@ -194,13 +184,13 @@ opal_btl_usnic_check_rx_seq( delta = SEQ_DIFF(seq, endpoint->endpoint_next_contig_seq_to_recv); if (delta < 0 || delta >= WINDOW_SIZE) { #if MSGDEBUG1 - opal_output(0, "<-- Received FRAG/CHUNK ep %p, seq %" UDSEQ " outside of window (%" UDSEQ " - %" UDSEQ "), %p, module %p -- DROPPED\n", - (void*)endpoint, seg->rs_base.us_btl_header->pkt_seq, - endpoint->endpoint_next_contig_seq_to_recv, - (endpoint->endpoint_next_contig_seq_to_recv + - WINDOW_SIZE - 1), - (void*) seg, - (void*) endpoint->endpoint_module); + opal_output(0, + "<-- Received FRAG/CHUNK ep %p, seq %" UDSEQ " outside of window (%" UDSEQ + " - %" UDSEQ "), %p, module %p -- DROPPED\n", + (void *) endpoint, seg->rs_base.us_btl_header->pkt_seq, + endpoint->endpoint_next_contig_seq_to_recv, + (endpoint->endpoint_next_contig_seq_to_recv + WINDOW_SIZE - 1), (void *) seg, + (void *) endpoint->endpoint_module); #endif /* Stats */ @@ -239,15 +229,16 @@ opal_btl_usnic_check_rx_seq( i = WINDOW_SIZE_MOD(i + endpoint->endpoint_rfstart); if (endpoint->endpoint_rcvd_segs[i]) { #if MSGDEBUG1 - opal_output(0, "<-- Received FRAG/CHUNK ep %p, seq %" UDSEQ ", seg %p: duplicate -- DROPPED\n", - (void*) endpoint, seg->rs_base.us_btl_header->pkt_seq, (void*) seg); + opal_output(0, + "<-- Received FRAG/CHUNK ep %p, seq %" UDSEQ ", seg %p: duplicate -- DROPPED\n", + (void *) endpoint, seg->rs_base.us_btl_header->pkt_seq, (void *) seg); #endif /* highest_seq_rcvd is for debug stats only; it's not used in any window calculations */ assert(SEQ_LE(seq, endpoint->endpoint_highest_seq_rcvd)); /* next_contig_seq_to_recv-1 is the ack number we'll send */ - assert (SEQ_GT(seq, endpoint->endpoint_next_contig_seq_to_recv - 1)); + assert(SEQ_GT(seq, endpoint->endpoint_next_contig_seq_to_recv - 1)); /* Stats */ ++endpoint->endpoint_module->stats.num_dup_recvs; @@ -276,13 +267,12 @@ opal_btl_usnic_check_rx_seq( * possible. * See README.txt for a discussion of receive fastpath */ -static inline void -opal_btl_usnic_recv_fast(opal_btl_usnic_module_t *module, - opal_btl_usnic_recv_segment_t *seg, - opal_btl_usnic_channel_t *channel) +static inline void opal_btl_usnic_recv_fast(opal_btl_usnic_module_t *module, + opal_btl_usnic_recv_segment_t *seg, + opal_btl_usnic_channel_t *channel) { opal_btl_usnic_segment_t *bseg; - mca_btl_active_message_callback_t* reg; + mca_btl_active_message_callback_t *reg; opal_btl_usnic_seq_t seq; opal_btl_usnic_endpoint_t *endpoint; int delta; @@ -305,10 +295,9 @@ opal_btl_usnic_dump_hex(15, USNIC_OUT, bseg->us_btl_header, bseg->us_btl_header- wholly contained in this one message -- it is not chunked across multiple messages), and it's not a PUT from the sender, then just handle it here. */ - if (endpoint != NULL && !endpoint->endpoint_exiting && - (OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG == - bseg->us_btl_header->payload_type) && - seg->rs_base.us_btl_header->put_addr == NULL) { + if (endpoint != NULL && !endpoint->endpoint_exiting + && (OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG == bseg->us_btl_header->payload_type) + && seg->rs_base.us_btl_header->put_addr == NULL) { seq = seg->rs_base.us_btl_header->pkt_seq; delta = SEQ_DIFF(seq, endpoint->endpoint_next_contig_seq_to_recv); @@ -335,7 +324,7 @@ opal_btl_usnic_dump_hex(15, USNIC_OUT, bseg->us_btl_header, bseg->us_btl_header- seg->rs_desc.cbdata = reg->cbdata; reg->cbfunc(&module->super, &seg->rs_desc); -drop: + drop: channel->chan_deferred_recv = seg; } @@ -347,21 +336,18 @@ opal_btl_usnic_dump_hex(15, USNIC_OUT, bseg->us_btl_header, bseg->us_btl_header- /* */ -static inline int -opal_btl_usnic_recv_frag_bookkeeping( - opal_btl_usnic_module_t* module, - opal_btl_usnic_recv_segment_t *seg, - opal_btl_usnic_channel_t *channel) +static inline int opal_btl_usnic_recv_frag_bookkeeping(opal_btl_usnic_module_t *module, + opal_btl_usnic_recv_segment_t *seg, + opal_btl_usnic_channel_t *channel) { - opal_btl_usnic_endpoint_t* endpoint; + opal_btl_usnic_endpoint_t *endpoint; uint32_t window_index; int rc; endpoint = seg->rs_endpoint; /* Valgrind help */ - opal_memchecker_base_mem_defined( - (void*)(seg->rs_protocol_header), seg->rs_len); + opal_memchecker_base_mem_defined((void *) (seg->rs_protocol_header), seg->rs_len); ++module->stats.num_total_recvs; @@ -394,13 +380,12 @@ opal_btl_usnic_recv_frag_bookkeeping( * We have received a segment, take action based on the * packet type in the BTL header */ -static inline void -opal_btl_usnic_recv(opal_btl_usnic_module_t *module, - opal_btl_usnic_recv_segment_t *seg, - opal_btl_usnic_channel_t *channel) +static inline void opal_btl_usnic_recv(opal_btl_usnic_module_t *module, + opal_btl_usnic_recv_segment_t *seg, + opal_btl_usnic_channel_t *channel) { opal_btl_usnic_segment_t *bseg; - mca_btl_active_message_callback_t* reg; + mca_btl_active_message_callback_t *reg; opal_btl_usnic_endpoint_t *endpoint; int rc; @@ -417,13 +402,12 @@ opal_btl_usnic_recv(opal_btl_usnic_module_t *module, wholly contained in this one message -- it is not chunked across multiple messages), and it's not a PUT from the sender, then just handle it here. */ - if (endpoint != NULL && !endpoint->endpoint_exiting && - (OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG == - bseg->us_btl_header->payload_type) && - seg->rs_base.us_btl_header->put_addr == NULL) { + if (endpoint != NULL && !endpoint->endpoint_exiting + && (OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG == bseg->us_btl_header->payload_type) + && seg->rs_base.us_btl_header->put_addr == NULL) { MSGDEBUG1_OUT("<-- Received FRAG (fastpath) ep %p, seq %" UDSEQ ", len=%" PRIu16 "\n", - (void*) endpoint, bseg->us_btl_header->pkt_seq, + (void *) endpoint, bseg->us_btl_header->pkt_seq, bseg->us_btl_header->payload_len); /* do the receive bookkeeping */ diff --git a/opal/mca/btl/usnic/btl_usnic_send.c b/opal/mca/btl/usnic/btl_usnic_send.c index 3c7b715fc70..c2e3ba74428 100644 --- a/opal/mca/btl/usnic/btl_usnic_send.c +++ b/opal/mca/btl/usnic/btl_usnic_send.c @@ -27,24 +27,22 @@ #include "opal/constants.h" -#include "opal/mca/btl/btl.h" #include "opal/mca/btl/base/base.h" +#include "opal/mca/btl/btl.h" #include "btl_usnic.h" +#include "btl_usnic_ack.h" #include "btl_usnic_frag.h" -#include "btl_usnic_util.h" #include "btl_usnic_send.h" -#include "btl_usnic_ack.h" - +#include "btl_usnic_util.h" /* * This function is called when a send of a segment completes that is * the one-and-only segment of an MPI message. Return the WQE and * also return the segment if no ACK pending. */ -void -opal_btl_usnic_frag_send_complete(opal_btl_usnic_module_t *module, - opal_btl_usnic_send_segment_t *sseg) +void opal_btl_usnic_frag_send_complete(opal_btl_usnic_module_t *module, + opal_btl_usnic_send_segment_t *sseg) { opal_btl_usnic_send_frag_t *frag; @@ -77,9 +75,8 @@ opal_btl_usnic_frag_send_complete(opal_btl_usnic_module_t *module, * segments that have not yet completed sending). Return the WQE and * also return the segment if no ACK pending. */ -void -opal_btl_usnic_chunk_send_complete(opal_btl_usnic_module_t *module, - opal_btl_usnic_send_segment_t *sseg) +void opal_btl_usnic_chunk_send_complete(opal_btl_usnic_module_t *module, + opal_btl_usnic_send_segment_t *sseg) { opal_btl_usnic_send_frag_t *frag; @@ -115,12 +112,9 @@ opal_btl_usnic_chunk_send_complete(opal_btl_usnic_module_t *module, * * The "tag" only applies to sends. */ -int -opal_btl_usnic_finish_put_or_send( - opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_frag_t *frag, - mca_btl_base_tag_t tag) +int opal_btl_usnic_finish_put_or_send(opal_btl_usnic_module_t *module, + opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_frag_t *frag, mca_btl_base_tag_t tag) { int rc; opal_btl_usnic_small_send_frag_t *sfrag; @@ -133,7 +127,7 @@ opal_btl_usnic_finish_put_or_send( */ if (frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_SMALL_SEND) { - sfrag = (opal_btl_usnic_small_send_frag_t *)frag; + sfrag = (opal_btl_usnic_small_send_frag_t *) frag; sseg = &sfrag->ssf_segment; /* Copy in user data if there is any, collapsing 2 segments into 1. @@ -144,15 +138,14 @@ opal_btl_usnic_finish_put_or_send( /* no convertor */ assert(NULL != frag->sf_base.uf_local_seg[1].seg_addr.pval); - memcpy(((char *)(intptr_t)frag->sf_base.uf_local_seg[0].seg_addr.lval + - frag->sf_base.uf_local_seg[0].seg_len), - frag->sf_base.uf_local_seg[1].seg_addr.pval, - frag->sf_base.uf_local_seg[1].seg_len); + memcpy(((char *) (intptr_t) frag->sf_base.uf_local_seg[0].seg_addr.lval + + frag->sf_base.uf_local_seg[0].seg_len), + frag->sf_base.uf_local_seg[1].seg_addr.pval, + frag->sf_base.uf_local_seg[1].seg_len); /* update 1st segment length */ frag->sf_base.uf_base.USNIC_SEND_LOCAL_COUNT = 1; - frag->sf_base.uf_local_seg[0].seg_len += - frag->sf_base.uf_local_seg[1].seg_len; + frag->sf_base.uf_local_seg[0].seg_len += frag->sf_base.uf_local_seg[1].seg_len; } sseg->ss_len = sizeof(opal_btl_usnic_btl_header_t) + frag->sf_size; @@ -165,7 +158,7 @@ opal_btl_usnic_finish_put_or_send( /* Save info about the frag so that future invocations of * usnic_handle_large_send can generate segments to put on the wire. */ - lfrag = (opal_btl_usnic_large_send_frag_t *)frag; + lfrag = (opal_btl_usnic_large_send_frag_t *) frag; lfrag->lsf_tag = tag; lfrag->lsf_cur_offset = 0; lfrag->lsf_cur_ptr = lfrag->lsf_des_src[0].seg_addr.pval; diff --git a/opal/mca/btl/usnic/btl_usnic_send.h b/opal/mca/btl/usnic/btl_usnic_send.h index 4d093b80156..a4d6fbf25f3 100644 --- a/opal/mca/btl/usnic/btl_usnic_send.h +++ b/opal/mca/btl/usnic/btl_usnic_send.h @@ -11,19 +11,17 @@ #define BTL_USNIC_SEND_H #include "btl_usnic.h" -#include "btl_usnic_frag.h" #include "btl_usnic_ack.h" +#include "btl_usnic_frag.h" #if MSGDEBUG1 -#include "btl_usnic_util.h" +# include "btl_usnic_util.h" #endif /* * Check if conditions are right, and if so, put endpoint on * list of endpoints that have sends to be done */ -static inline void -opal_btl_usnic_check_rts( - opal_btl_usnic_endpoint_t *endpoint) +static inline void opal_btl_usnic_check_rts(opal_btl_usnic_endpoint_t *endpoint) { /* * If endpoint not already ready, @@ -32,21 +30,17 @@ opal_btl_usnic_check_rts( * and its retransmission window is open, * make it ready */ - if (!endpoint->endpoint_ready_to_send && - !opal_list_is_empty(&endpoint->endpoint_frag_send_queue) && - endpoint->endpoint_send_credits > 0 && - WINDOW_OPEN(endpoint)) { - opal_list_append(&endpoint->endpoint_module->endpoints_with_sends, - &endpoint->super); + if (!endpoint->endpoint_ready_to_send + && !opal_list_is_empty(&endpoint->endpoint_frag_send_queue) + && endpoint->endpoint_send_credits > 0 && WINDOW_OPEN(endpoint)) { + opal_list_append(&endpoint->endpoint_module->endpoints_with_sends, &endpoint->super); endpoint->endpoint_ready_to_send = true; #if MSGDEBUG1 - opal_output(0, "make endpoint %p RTS\n", (void*)endpoint); + opal_output(0, "make endpoint %p RTS\n", (void *) endpoint); } else { - opal_output(0, "rts:%d empty:%d cred:%d open%d\n", - endpoint->endpoint_ready_to_send, - opal_list_is_empty(&endpoint->endpoint_frag_send_queue), - endpoint->endpoint_send_credits, - WINDOW_OPEN(endpoint)); + opal_output(0, "rts:%d empty:%d cred:%d open%d\n", endpoint->endpoint_ready_to_send, + opal_list_is_empty(&endpoint->endpoint_frag_send_queue), + endpoint->endpoint_send_credits, WINDOW_OPEN(endpoint)); #endif } } @@ -57,11 +51,9 @@ opal_btl_usnic_check_rts( * ASSUMES THAT THE CALLER HAS ALREADY CHECKED TO SEE IF WE HAVE * A SEND CREDIT! */ -static inline void -opal_btl_usnic_post_segment( - opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_segment_t *sseg) +static inline void opal_btl_usnic_post_segment(opal_btl_usnic_module_t *module, + opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_segment_t *sseg) { int ret; @@ -70,12 +62,9 @@ opal_btl_usnic_post_segment( opal_btl_usnic_channel_t *channel = &module->mod_channels[channel_id]; #if MSGDEBUG1 - opal_output(0, "post_send: type=%s, ep=%p, remote_addr=%p, addr=%p, len=%" - PRIsize_t, - usnic_seg_type_str(sseg->ss_base.us_type), - (void*) channel->ep, - (void*) endpoint->endpoint_remote_addrs[channel_id], - (void*) sseg->ss_ptr, + opal_output(0, "post_send: type=%s, ep=%p, remote_addr=%p, addr=%p, len=%" PRIsize_t, + usnic_seg_type_str(sseg->ss_base.us_type), (void *) channel->ep, + (void *) endpoint->endpoint_remote_addrs[channel_id], (void *) sseg->ss_ptr, sseg->ss_len); #endif @@ -83,15 +72,11 @@ opal_btl_usnic_post_segment( assert(channel->credits > 1); /* Send the segment */ - ret = fi_send(channel->ep, - sseg->ss_ptr, - sseg->ss_len + mca_btl_usnic_component.prefix_send_offset, - NULL, - endpoint->endpoint_remote_addrs[channel_id], - sseg); + ret = fi_send(channel->ep, sseg->ss_ptr, + sseg->ss_len + mca_btl_usnic_component.prefix_send_offset, NULL, + endpoint->endpoint_remote_addrs[channel_id], sseg); if (OPAL_UNLIKELY(0 != ret)) { - opal_btl_usnic_util_abort("fi_send() failed", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("fi_send() failed", __FILE__, __LINE__); /* Never returns */ } @@ -113,11 +98,9 @@ opal_btl_usnic_post_segment( * ASSUMES THAT THE CALLER HAS ALREADY CHECKED TO SEE IF WE HAVE * A SEND CREDIT! */ -static inline void -opal_btl_usnic_post_ack( - opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_segment_t *sseg) +static inline void opal_btl_usnic_post_ack(opal_btl_usnic_module_t *module, + opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_segment_t *sseg) { int ret; @@ -126,27 +109,20 @@ opal_btl_usnic_post_ack( opal_btl_usnic_channel_t *channel = &module->mod_channels[channel_id]; #if MSGDEBUG1 - opal_output(0, "post_send ACK: type=%s, ep=%p, remote_addr=%p, addr=%p, len=%" - PRIsize_t, - usnic_seg_type_str(sseg->ss_base.us_type), - (void*) channel->ep, - (void*) endpoint->endpoint_remote_addrs[channel_id], - (void*) sseg->ss_ptr, + opal_output(0, "post_send ACK: type=%s, ep=%p, remote_addr=%p, addr=%p, len=%" PRIsize_t, + usnic_seg_type_str(sseg->ss_base.us_type), (void *) channel->ep, + (void *) endpoint->endpoint_remote_addrs[channel_id], (void *) sseg->ss_ptr, sseg->ss_len); #endif assert(channel_id == USNIC_PRIORITY_CHANNEL); assert(channel->credits > 1); - ret = fi_send(channel->ep, - sseg->ss_ptr, - sseg->ss_len + mca_btl_usnic_component.prefix_send_offset, - NULL, - endpoint->endpoint_remote_addrs[channel_id], - sseg); + ret = fi_send(channel->ep, sseg->ss_ptr, + sseg->ss_len + mca_btl_usnic_component.prefix_send_offset, NULL, + endpoint->endpoint_remote_addrs[channel_id], sseg); if (OPAL_UNLIKELY(0 != ret)) { - opal_btl_usnic_util_abort("fi_send() failed", - __FILE__, __LINE__); + opal_btl_usnic_util_abort("fi_send() failed", __FILE__, __LINE__); /* Never returns */ } @@ -159,10 +135,8 @@ opal_btl_usnic_post_ack( /* * Post a send to the work queue */ -static inline void -opal_btl_usnic_endpoint_send_segment( - opal_btl_usnic_module_t *module, - opal_btl_usnic_send_segment_t *sseg) +static inline void opal_btl_usnic_endpoint_send_segment(opal_btl_usnic_module_t *module, + opal_btl_usnic_send_segment_t *sseg) { opal_btl_usnic_send_frag_t *frag; opal_btl_usnic_endpoint_t *endpoint; @@ -192,17 +166,14 @@ opal_btl_usnic_endpoint_send_segment( next_seq_to_send > ack_seq_rcvd + WINDOW_SIZE */ - assert(SEQ_GT(endpoint->endpoint_next_seq_to_send, - endpoint->endpoint_ack_seq_rcvd)); + assert(SEQ_GT(endpoint->endpoint_next_seq_to_send, endpoint->endpoint_ack_seq_rcvd)); assert(WINDOW_OPEN(endpoint)); /* Assign sequence number and increment */ - sseg->ss_base.us_btl_header->pkt_seq = - endpoint->endpoint_next_seq_to_send++; + sseg->ss_base.us_btl_header->pkt_seq = endpoint->endpoint_next_seq_to_send++; /* Fill in remote address to indicate PUT or not */ - sseg->ss_base.us_btl_header->put_addr = - frag->sf_base.uf_remote_seg[0].seg_addr.pval; + sseg->ss_base.us_btl_header->put_addr = frag->sf_base.uf_remote_seg[0].seg_addr.pval; /* piggy-back an ACK if needed */ opal_btl_usnic_piggyback_ack(endpoint, sseg); @@ -212,25 +183,23 @@ opal_btl_usnic_endpoint_send_segment( char local_ip[32]; char remote_ip[32]; - opal_btl_usnic_snprintf_ipv4_addr(local_ip, sizeof(local_ip), - module->local_modex.ipv4_addr, + opal_btl_usnic_snprintf_ipv4_addr(local_ip, sizeof(local_ip), module->local_modex.ipv4_addr, module->local_modex.netmask); opal_btl_usnic_snprintf_ipv4_addr(remote_ip, sizeof(remote_ip), endpoint->endpoint_remote_modex.ipv4_addr, endpoint->endpoint_remote_modex.netmask); - opal_output(0, "--> Sending %s: seq: %" UDSEQ ", sender: 0x%016lx from device %s, IP %s, port %u, seg %p, room %d, wc len %u, remote IP %s, port %u", - (sseg->ss_parent_frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_LARGE_SEND)? - "CHUNK" : "FRAG", - sseg->ss_base.us_btl_header->pkt_seq, - sseg->ss_base.us_btl_header->sender, - endpoint->endpoint_module->linux_device_name, - local_ip, - module->local_modex.ports[sseg->ss_channel], - (void*)sseg, - sseg->ss_hotel_room, - sseg->ss_ptr, - remote_ip, + opal_output(0, + "--> Sending %s: seq: %" UDSEQ + ", sender: 0x%016lx from device %s, IP %s, port %u, seg %p, room %d, wc len " + "%u, remote IP %s, port %u", + (sseg->ss_parent_frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_LARGE_SEND) + ? "CHUNK" + : "FRAG", + sseg->ss_base.us_btl_header->pkt_seq, sseg->ss_base.us_btl_header->sender, + endpoint->endpoint_module->linux_device_name, local_ip, + module->local_modex.ports[sseg->ss_channel], (void *) sseg, sseg->ss_hotel_room, + sseg->ss_ptr, remote_ip, endpoint->endpoint_remote_modex.ports[sseg->ss_channel]); } #endif @@ -251,8 +220,7 @@ opal_btl_usnic_endpoint_send_segment( --endpoint->endpoint_send_credits; /* Stats */ - if (sseg->ss_parent_frag->sf_base.uf_type - == OPAL_BTL_USNIC_FRAG_LARGE_SEND) { + if (sseg->ss_parent_frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_LARGE_SEND) { ++module->stats.num_chunk_sends; } else { ++module->stats.num_frag_sends; @@ -260,34 +228,29 @@ opal_btl_usnic_endpoint_send_segment( /* If we have room in the sender's window, we also have room in endpoint hotel */ - opal_hotel_checkin_with_res(&endpoint->endpoint_hotel, sseg, - &sseg->ss_hotel_room); + opal_hotel_checkin_with_res(&endpoint->endpoint_hotel, sseg, &sseg->ss_hotel_room); } /* * This enqueues a fragment send into the system. A send of a fragment * may result in the sending of multiple segments */ -static inline int -opal_btl_usnic_endpoint_enqueue_frag( - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_frag_t *frag) +static inline int opal_btl_usnic_endpoint_enqueue_frag(opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_frag_t *frag) { #if MSGDEBUG1 - opal_output(0, "enq_frag: frag=%p, endpoint=%p, %s, len=%lu\n", - (void*)frag, (void*)endpoint, - usnic_frag_type(frag->sf_base.uf_type), - (long unsigned)frag->sf_base.uf_base.des_src->seg_len); + opal_output(0, "enq_frag: frag=%p, endpoint=%p, %s, len=%lu\n", (void *) frag, + (void *) endpoint, usnic_frag_type(frag->sf_base.uf_type), + (long unsigned) frag->sf_base.uf_base.des_src->seg_len); if (frag->sf_base.uf_type == OPAL_BTL_USNIC_FRAG_LARGE_SEND) { opal_btl_usnic_large_send_frag_t *lfrag; - lfrag = (opal_btl_usnic_large_send_frag_t *)frag; + lfrag = (opal_btl_usnic_large_send_frag_t *) frag; opal_output(0, " large size=%zd\n", lfrag->lsf_base.sf_size); } #endif /* add to tail of in-progress list */ - opal_list_append(&endpoint->endpoint_frag_send_queue, - &frag->sf_base.uf_base.super.super); + opal_list_append(&endpoint->endpoint_frag_send_queue, &frag->sf_base.uf_base.super.super); /* possibly make this endpoint ready to send again */ opal_btl_usnic_check_rts(endpoint); @@ -295,11 +258,9 @@ opal_btl_usnic_endpoint_enqueue_frag( return OPAL_SUCCESS; } -static inline void -opal_btl_usnic_release_send_segment( - opal_btl_usnic_module_t *module, - opal_btl_usnic_send_frag_t *frag, - opal_btl_usnic_send_segment_t *sseg) +static inline void opal_btl_usnic_release_send_segment(opal_btl_usnic_module_t *module, + opal_btl_usnic_send_frag_t *frag, + opal_btl_usnic_send_segment_t *sseg) { /* We only return CHUNK segments because they are the only send-style * segments that are dynamically allocated. @@ -312,17 +273,14 @@ opal_btl_usnic_release_send_segment( void opal_btl_usnic_frag_complete(opal_btl_usnic_send_frag_t *frag); void opal_btl_usnic_frag_send_complete(opal_btl_usnic_module_t *module, - opal_btl_usnic_send_segment_t *sseg); + opal_btl_usnic_send_segment_t *sseg); void opal_btl_usnic_chunk_send_complete(opal_btl_usnic_module_t *module, - opal_btl_usnic_send_segment_t *sseg); - -int -opal_btl_usnic_finish_put_or_send( - opal_btl_usnic_module_t *module, - opal_btl_usnic_endpoint_t *endpoint, - opal_btl_usnic_send_frag_t *frag, - mca_btl_base_tag_t tag) -__opal_attribute_noinline__; + opal_btl_usnic_send_segment_t *sseg); + +int opal_btl_usnic_finish_put_or_send(opal_btl_usnic_module_t *module, + opal_btl_usnic_endpoint_t *endpoint, + opal_btl_usnic_send_frag_t *frag, + mca_btl_base_tag_t tag) __opal_attribute_noinline__; #endif /* BTL_USNIC_SEND_H */ diff --git a/opal/mca/btl/usnic/btl_usnic_stats.c b/opal/mca/btl/usnic/btl_usnic_stats.c index ae2a816b5c4..5d1e1e8a19e 100644 --- a/opal/mca/btl/usnic/btl_usnic_stats.c +++ b/opal/mca/btl/usnic/btl_usnic_stats.c @@ -10,16 +10,16 @@ #include "opal_config.h" -#include #include +#include +#include "opal/mca/base/mca_base_pvar.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/util/output.h" #include "opal/util/printf.h" -#include "opal/mca/base/mca_base_var.h" -#include "opal/mca/base/mca_base_pvar.h" -#include "btl_usnic_compat.h" #include "btl_usnic.h" +#include "btl_usnic_compat.h" #include "btl_usnic_module.h" #include "btl_usnic_stats.h" #include "btl_usnic_util.h" @@ -33,44 +33,30 @@ static inline void usnic_stats_reset(opal_btl_usnic_module_t *module) { int i; - module->stats.num_total_sends = - module->stats.num_resends = - module->stats.num_chunk_sends = - module->stats.num_frag_sends = - module->stats.num_ack_recvs = - - module->stats.num_total_recvs = - module->stats.num_unk_recvs = - module->stats.num_dup_recvs = - module->stats.num_oow_low_recvs = - module->stats.num_oow_high_recvs = - module->stats.num_frag_recvs = - module->stats.num_chunk_recvs = - module->stats.num_badfrag_recvs = - module->stats.num_ack_sends = - module->stats.num_recv_reposts = - module->stats.num_crc_errors = - - module->stats.num_old_dup_acks = - module->stats.num_dup_acks = - module->stats.num_fast_retrans = - module->stats.num_timeout_retrans = - - module->stats.max_sent_window_size = - module->stats.max_rcvd_window_size = - - module->stats.pml_module_sends = - module->stats.pml_send_callbacks = - - module->stats.num_seg_total_completions = - module->stats.num_seg_ack_completions = - module->stats.num_seg_frag_completions = - module->stats.num_seg_chunk_completions = - module->stats.num_seg_recv_completions = - - 0; - - for (i=0; istats.num_total_sends = module->stats.num_resends = module->stats.num_chunk_sends + = module->stats.num_frag_sends = module->stats.num_ack_recvs = + + module->stats.num_total_recvs = module->stats.num_unk_recvs + = module->stats.num_dup_recvs = module->stats.num_oow_low_recvs + = module->stats.num_oow_high_recvs = module->stats.num_frag_recvs + = module->stats.num_chunk_recvs = module->stats.num_badfrag_recvs = module->stats + .num_ack_sends + = module->stats.num_recv_reposts = module->stats.num_crc_errors = + + module->stats.num_old_dup_acks = module->stats.num_dup_acks + = module->stats.num_fast_retrans = module->stats.num_timeout_retrans = + + module->stats.max_sent_window_size = module->stats.max_rcvd_window_size = + + module->stats.pml_module_sends = module->stats.pml_send_callbacks = + + module->stats.num_seg_total_completions = module->stats.num_seg_ack_completions + = module->stats.num_seg_frag_completions = module->stats.num_seg_chunk_completions + = module->stats.num_seg_recv_completions = + + 0; + + for (i = 0; i < USNIC_NUM_CHANNELS; ++i) { module->mod_channels[i].num_channel_sends = 0; } } @@ -82,58 +68,47 @@ static inline void usnic_stats_reset(opal_btl_usnic_module_t *module) * NOTE: this routine ignores the setting of stats_enable, so it can be used * for debugging routines even when normal stats reporting is not enabled. */ -void opal_btl_usnic_print_stats( - opal_btl_usnic_module_t *module, - const char *prefix, - bool reset_stats) +void opal_btl_usnic_print_stats(opal_btl_usnic_module_t *module, const char *prefix, + bool reset_stats) { char tmp[128], str[2048]; /* The usuals */ - snprintf(str, sizeof(str), "%s:MCW:%3u, %s, ST(P+D)/F/C/R(T+F)/A:%8lu(%8u+%8u)/%8lu/%8lu/%4lu(%4lu+%4lu)/%8lu, RcvTot/Chk/F/C/L/H/D/BF/A:%8lu/%c%c/%8lu/%8lu/%4lu+%2lu/%4lu/%4lu/%6lu Comp:T(A/F/C/R) %8lu(%8lu/%8lu/%8lu/%8lu), OA/DA %4lu/%4lu CRC:%4lu ", - prefix, - opal_proc_local_get()->proc_name.vpid, + snprintf(str, sizeof(str), + "%s:MCW:%3u, %s, ST(P+D)/F/C/R(T+F)/A:%8lu(%8u+%8u)/%8lu/%8lu/%4lu(%4lu+%4lu)/%8lu, " + "RcvTot/Chk/F/C/L/H/D/BF/A:%8lu/%c%c/%8lu/%8lu/%4lu+%2lu/%4lu/%4lu/%6lu " + "Comp:T(A/F/C/R) %8lu(%8lu/%8lu/%8lu/%8lu), OA/DA %4lu/%4lu CRC:%4lu ", + prefix, opal_proc_local_get()->proc_name.vpid, module->linux_device_name, module->stats.num_total_sends, module->mod_channels[USNIC_PRIORITY_CHANNEL].num_channel_sends, module->mod_channels[USNIC_DATA_CHANNEL].num_channel_sends, - module->stats.num_frag_sends, - module->stats.num_chunk_sends, - module->stats.num_resends, - module->stats.num_timeout_retrans, - module->stats.num_fast_retrans, + module->stats.num_frag_sends, module->stats.num_chunk_sends, module->stats.num_resends, + module->stats.num_timeout_retrans, module->stats.num_fast_retrans, module->stats.num_ack_sends, module->stats.num_total_recvs, - (module->stats.num_total_recvs - - module->stats.num_recv_reposts) == 0 ? 'g' : 'B', - (module->stats.num_total_recvs - - module->stats.num_frag_recvs - - module->stats.num_chunk_recvs - - module->stats.num_badfrag_recvs - - module->stats.num_oow_low_recvs - - module->stats.num_oow_high_recvs - - module->stats.num_dup_recvs - - module->stats.num_ack_recvs - - module->stats.num_unk_recvs) == 0 ? 'g' : 'B', - module->stats.num_frag_recvs, - module->stats.num_chunk_recvs, - module->stats.num_oow_low_recvs, - module->stats.num_oow_high_recvs, - module->stats.num_dup_recvs, - module->stats.num_badfrag_recvs, + (module->stats.num_total_recvs - module->stats.num_recv_reposts) == 0 ? 'g' : 'B', + (module->stats.num_total_recvs - module->stats.num_frag_recvs + - module->stats.num_chunk_recvs - module->stats.num_badfrag_recvs + - module->stats.num_oow_low_recvs - module->stats.num_oow_high_recvs + - module->stats.num_dup_recvs - module->stats.num_ack_recvs + - module->stats.num_unk_recvs) + == 0 + ? 'g' + : 'B', + module->stats.num_frag_recvs, module->stats.num_chunk_recvs, + module->stats.num_oow_low_recvs, module->stats.num_oow_high_recvs, + module->stats.num_dup_recvs, module->stats.num_badfrag_recvs, module->stats.num_ack_recvs, - module->stats.num_seg_total_completions, - module->stats.num_seg_ack_completions, - module->stats.num_seg_frag_completions, - module->stats.num_seg_chunk_completions, - module->stats.num_seg_recv_completions, + module->stats.num_seg_total_completions, module->stats.num_seg_ack_completions, + module->stats.num_seg_frag_completions, module->stats.num_seg_chunk_completions, + module->stats.num_seg_recv_completions, - module->stats.num_old_dup_acks, - module->stats.num_dup_acks, + module->stats.num_old_dup_acks, module->stats.num_dup_acks, module->stats.num_crc_errors); @@ -144,8 +119,7 @@ void opal_btl_usnic_print_stats( /* If our PML calls were 0, then show send and receive window extents instead */ - if (module->stats.pml_module_sends + - module->stats.pml_send_callbacks == 0) { + if (module->stats.pml_module_sends + module->stats.pml_send_callbacks == 0) { int64_t send_unacked, su_min = WINDOW_SIZE * 2, su_max = 0; int64_t recv_depth, rd_min = WINDOW_SIZE * 2, rd_max = 0; opal_btl_usnic_endpoint_t *endpoint; @@ -157,39 +131,36 @@ void opal_btl_usnic_print_stats( opal_mutex_lock(&module->all_endpoints_lock); item = opal_list_get_first(&module->all_endpoints); while (item != opal_list_get_end(&(module->all_endpoints))) { - endpoint = container_of(item, mca_btl_base_endpoint_t, - endpoint_endpoint_li); + endpoint = container_of(item, mca_btl_base_endpoint_t, endpoint_endpoint_li); item = opal_list_get_next(item); /* Number of un-acked sends (i.e., sends for which we're still waiting for ACK) */ - send_unacked = - SEQ_DIFF(endpoint->endpoint_next_seq_to_send, - SEQ_DIFF(endpoint->endpoint_ack_seq_rcvd, 1)); + send_unacked = SEQ_DIFF(endpoint->endpoint_next_seq_to_send, + SEQ_DIFF(endpoint->endpoint_ack_seq_rcvd, 1)); - if (send_unacked > su_max) su_max = send_unacked; - if (send_unacked < su_min) su_min = send_unacked; + if (send_unacked > su_max) + su_max = send_unacked; + if (send_unacked < su_min) + su_min = send_unacked; /* Receive window depth (i.e., difference between highest seq received and the next message we haven't ACKed yet) */ - recv_depth = - endpoint->endpoint_highest_seq_rcvd - - endpoint->endpoint_next_contig_seq_to_recv; - if (recv_depth > rd_max) rd_max = recv_depth; - if (recv_depth < rd_min) rd_min = recv_depth; + recv_depth = endpoint->endpoint_highest_seq_rcvd + - endpoint->endpoint_next_contig_seq_to_recv; + if (recv_depth > rd_max) + rd_max = recv_depth; + if (recv_depth < rd_min) + rd_min = recv_depth; } opal_mutex_unlock(&module->all_endpoints_lock); snprintf(tmp, sizeof(tmp), "PML S:%1ld, Win!A/R:%4ld/%4ld %4ld/%4ld", - module->stats.pml_module_sends, - su_min, su_max, - rd_min, rd_max); + module->stats.pml_module_sends, su_min, su_max, rd_min, rd_max); } else { - snprintf(tmp, sizeof(tmp), "PML S/CB/Diff:%4lu/%4lu=%4ld", - module->stats.pml_module_sends, - module->stats.pml_send_callbacks, - module->stats.pml_module_sends - - module->stats.pml_send_callbacks); + snprintf(tmp, sizeof(tmp), "PML S/CB/Diff:%4lu/%4lu=%4ld", module->stats.pml_module_sends, + module->stats.pml_send_callbacks, + module->stats.pml_module_sends - module->stats.pml_send_callbacks); } strncat(str, tmp, sizeof(str) - strlen(str) - 1); @@ -205,7 +176,7 @@ void opal_btl_usnic_print_stats( */ static void usnic_stats_callback(int fd, short flags, void *arg) { - opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t*) arg; + opal_btl_usnic_module_t *module = (opal_btl_usnic_module_t *) arg; char tmp[128]; if (!mca_btl_usnic_component.stats_enabled) { @@ -229,12 +200,9 @@ int opal_btl_usnic_stats_init(opal_btl_usnic_module_t *module) module->stats.timeout.tv_sec = mca_btl_usnic_component.stats_frequency; module->stats.timeout.tv_usec = 0; - opal_event_set(mca_btl_usnic_component.opal_evbase, - &(module->stats.timer_event), - -1, EV_TIMEOUT | EV_PERSIST, - &usnic_stats_callback, module); - opal_event_add(&(module->stats.timer_event), - &(module->stats.timeout)); + opal_event_set(mca_btl_usnic_component.opal_evbase, &(module->stats.timer_event), -1, + EV_TIMEOUT | EV_PERSIST, &usnic_stats_callback, module); + opal_event_add(&(module->stats.timer_event), &(module->stats.timeout)); } return OPAL_SUCCESS; @@ -261,9 +229,8 @@ int opal_btl_usnic_stats_finalize(opal_btl_usnic_module_t *module) * Function called by the pvar base upon MPI_T_pvar_handle_alloc, * handle_start, and handle_stop. */ -static int usnic_pvar_notify(struct mca_base_pvar_t *pvar, - mca_base_pvar_event_t event, - void *obj, int *count) +static int usnic_pvar_notify(struct mca_base_pvar_t *pvar, mca_base_pvar_event_t event, void *obj, + int *count) { if (MCA_BASE_PVAR_HANDLE_BIND == event) { *count = mca_btl_usnic_component.num_modules; @@ -274,26 +241,23 @@ static int usnic_pvar_notify(struct mca_base_pvar_t *pvar, return OPAL_SUCCESS; } - /* * Function called by the pvar base when a user wants to read the * value of an MPI_T performance variable. */ -static int usnic_pvar_read(const struct mca_base_pvar_t *pvar, - void *value, void *bound_obj) +static int usnic_pvar_read(const struct mca_base_pvar_t *pvar, void *value, void *bound_obj) { size_t offset = (size_t) pvar->ctx; - uint64_t *array = (uint64_t*) value; + uint64_t *array = (uint64_t *) value; for (int i = 0; i < mca_btl_usnic_component.num_modules; ++i) { - char *base = (char*) &(mca_btl_usnic_component.usnic_active_modules[i]->stats); - array[i] = *((uint64_t*) (base + offset)); + char *base = (char *) &(mca_btl_usnic_component.usnic_active_modules[i]->stats); + array[i] = *((uint64_t *) (base + offset)); } return OPAL_SUCCESS; } - /* * Register an MPI_T performance variable of type CLASS_HIGHWATERMARK. */ @@ -301,31 +265,24 @@ static void register_pvar_highwater(char *name, char *desc, size_t offset) { int rc __opal_attribute_unused__; - rc = mca_base_component_pvar_register(&mca_btl_usnic_component.super.btl_version, - name, desc, - OPAL_INFO_LVL_5, - MCA_BASE_PVAR_CLASS_HIGHWATERMARK, - pvar_type, - NULL, /* enumeration */ + rc = mca_base_component_pvar_register(&mca_btl_usnic_component.super.btl_version, name, desc, + OPAL_INFO_LVL_5, MCA_BASE_PVAR_CLASS_HIGHWATERMARK, + pvar_type, NULL, /* enumeration */ MCA_BASE_VAR_BIND_NO_OBJECT, - (MCA_BASE_PVAR_FLAG_READONLY | - MCA_BASE_PVAR_FLAG_CONTINUOUS), - usnic_pvar_read, - NULL, /* write function */ - usnic_pvar_notify, - (void *) offset); + (MCA_BASE_PVAR_FLAG_READONLY + | MCA_BASE_PVAR_FLAG_CONTINUOUS), + usnic_pvar_read, NULL, /* write function */ + usnic_pvar_notify, (void *) offset); assert(rc >= 0); } - /* * Function called by the pvar base when a user wants to read the * devices enum value. The array is a simple list of 0..num_modules, * which will map to the strings in the devices_enum * setup_mpit_pvar_type(). */ -static int usnic_pvar_enum_read(const struct mca_base_pvar_t *pvar, - void *value, void *bound_obj) +static int usnic_pvar_enum_read(const struct mca_base_pvar_t *pvar, void *value, void *bound_obj) { int *array = (int *) value; @@ -336,7 +293,6 @@ static int usnic_pvar_enum_read(const struct mca_base_pvar_t *pvar, return OPAL_SUCCESS; } - /* * Register an MPI_T performance variable of type CLASS_COUNTER. */ @@ -344,23 +300,17 @@ static void register_pvar_counter(char *name, char *desc, size_t offset) { int rc __opal_attribute_unused__; - rc = mca_base_component_pvar_register(&mca_btl_usnic_component.super.btl_version, - name, desc, - OPAL_INFO_LVL_5, - MCA_BASE_PVAR_CLASS_COUNTER, - pvar_type, + rc = mca_base_component_pvar_register(&mca_btl_usnic_component.super.btl_version, name, desc, + OPAL_INFO_LVL_5, MCA_BASE_PVAR_CLASS_COUNTER, pvar_type, NULL, /* enumeration */ MCA_BASE_VAR_BIND_NO_OBJECT, - (MCA_BASE_PVAR_FLAG_READONLY | - MCA_BASE_PVAR_FLAG_CONTINUOUS), - usnic_pvar_read, - NULL, /* write function */ - usnic_pvar_notify, - (void *) offset); + (MCA_BASE_PVAR_FLAG_READONLY + | MCA_BASE_PVAR_FLAG_CONTINUOUS), + usnic_pvar_read, NULL, /* write function */ + usnic_pvar_notify, (void *) offset); assert(rc >= 0); } - /* * Find the MPI_T type corresponding to our uint64_t counters and * highwatermarks. @@ -384,7 +334,6 @@ static bool setup_mpit_pvar_type(void) return true; } - /* * Setup the usnic_X device enumeration pvar */ @@ -398,8 +347,7 @@ static void setup_mpit_pvars_enum(void) unsigned char *c; struct sockaddr_in *sin; - devices = calloc(mca_btl_usnic_component.num_modules + 1, - sizeof(*devices)); + devices = calloc(mca_btl_usnic_component.num_modules + 1, sizeof(*devices)); assert(devices != NULL); for (i = 0; i < mca_btl_usnic_component.num_modules; ++i) { @@ -407,13 +355,11 @@ static void setup_mpit_pvars_enum(void) m = mca_btl_usnic_component.usnic_active_modules[i]; sin = m->fabric_info->src_addr; - c = (unsigned char*) &sin->sin_addr.s_addr; + c = (unsigned char *) &sin->sin_addr.s_addr; devices[i].value = i; - rc = opal_asprintf(&str, "%s,%hhu.%hhu.%hhu.%hhu/%" PRIu32, - m->linux_device_name, - c[0], c[1], c[2], c[3], - usnic_netmask_to_cidrlen(sin->sin_addr.s_addr)); + rc = opal_asprintf(&str, "%s,%hhu.%hhu.%hhu.%hhu/%" PRIu32, m->linux_device_name, c[0], + c[1], c[2], c[3], usnic_netmask_to_cidrlen(sin->sin_addr.s_addr)); assert(rc > 0); devices[i].string = str; } @@ -422,26 +368,20 @@ static void setup_mpit_pvars_enum(void) rc = mca_base_var_enum_create("btl_usnic", devices, &devices_enum); assert(OPAL_SUCCESS == rc); - rc = mca_base_component_pvar_register(&mca_btl_usnic_component.super.btl_version, - "devices", - "Enumeration representing which slot in btl_usnic_* MPI_T pvar value arrays correspond to which usnic_X Linux device", - OPAL_INFO_LVL_5, - MCA_BASE_PVAR_CLASS_STATE, - MCA_BASE_VAR_TYPE_INT, - devices_enum, - MCA_BASE_VAR_BIND_NO_OBJECT, - (MCA_BASE_PVAR_FLAG_READONLY | - MCA_BASE_PVAR_FLAG_CONTINUOUS), - usnic_pvar_enum_read, - NULL, /* write function */ - usnic_pvar_notify, - NULL /* context */); + rc = mca_base_component_pvar_register( + &mca_btl_usnic_component.super.btl_version, "devices", + "Enumeration representing which slot in btl_usnic_* MPI_T pvar value arrays correspond to " + "which usnic_X Linux device", + OPAL_INFO_LVL_5, MCA_BASE_PVAR_CLASS_STATE, MCA_BASE_VAR_TYPE_INT, devices_enum, + MCA_BASE_VAR_BIND_NO_OBJECT, (MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS), + usnic_pvar_enum_read, NULL, /* write function */ + usnic_pvar_notify, NULL /* context */); assert(rc >= 0); /* Free the strings (mca_base_var_enum_create() strdup()'ed them into private storage, so we don't need them any more) */ for (int i = 0; i < mca_btl_usnic_component.num_modules; ++i) { - free((char*) devices[i].string); + free((char *) devices[i].string); } free(devices); @@ -451,7 +391,6 @@ static void setup_mpit_pvars_enum(void) OBJ_RELEASE(devices_enum); } - /* * Setup high watermark MPI_T performance variables */ @@ -466,7 +405,6 @@ static void setup_mpit_pvars_highwatermark(void) "Maximum number of entries in all receive windows to this peer"); } - /* * Setup counter MPI_T performance variables */ @@ -475,57 +413,49 @@ static void setup_mpit_pvars_counters(void) #define REGISTERC(field, desc) \ register_pvar_counter(#field, (desc), offsetof(opal_btl_usnic_module_stats_t, field)) - REGISTERC(num_total_sends, - "Total number of sends (MPI data, ACKs, retransmissions, etc.)"); - REGISTERC(num_resends, - "Total number of all retransmissions"); - REGISTERC(num_timeout_retrans, - "Number of times chunk retransmissions have occured because an ACK was not received within the timeout"); + REGISTERC(num_total_sends, "Total number of sends (MPI data, ACKs, retransmissions, etc.)"); + REGISTERC(num_resends, "Total number of all retransmissions"); + REGISTERC(num_timeout_retrans, "Number of times chunk retransmissions have occured because an " + "ACK was not received within the timeout"); REGISTERC(num_fast_retrans, "Number of times chunk retransmissions have occured because due to a repeated ACK"); REGISTERC(num_chunk_sends, - "Number of sends that were part of a larger MPI message fragment (i.e., the MPI message was so long that it had to be split into multiple MTU/network sends)"); - REGISTERC(num_frag_sends, - "Number of sends where the entire MPI message fragment fit into a single MTU/network send"); - REGISTERC(num_ack_sends, - "Number of ACKs sent (i.e., usNIC-BTL-to-usNIC-BTL control messages)"); - - REGISTERC(num_total_recvs, - "Total number of receives completed"); - REGISTERC(num_unk_recvs, - "Number of receives with an unknown source or type, and therefore ignored by the usNIC BTL (this should never be >0)"); - REGISTERC(num_dup_recvs, - "Number of duplicate receives"); + "Number of sends that were part of a larger MPI message fragment (i.e., the MPI " + "message was so long that it had to be split into multiple MTU/network sends)"); + REGISTERC( + num_frag_sends, + "Number of sends where the entire MPI message fragment fit into a single MTU/network send"); + REGISTERC(num_ack_sends, "Number of ACKs sent (i.e., usNIC-BTL-to-usNIC-BTL control messages)"); + + REGISTERC(num_total_recvs, "Total number of receives completed"); + REGISTERC(num_unk_recvs, "Number of receives with an unknown source or type, and therefore " + "ignored by the usNIC BTL (this should never be >0)"); + REGISTERC(num_dup_recvs, "Number of duplicate receives"); REGISTERC(num_oow_low_recvs, "Number of times a receive was out of the sliding window (on the low side)"); REGISTERC(num_oow_high_recvs, "Number of times a receive was out of the sliding window (on the high side)"); - REGISTERC(num_frag_recvs, - "Number of receives where the entire MPI message fragment fit into a single MTU/network send"); + REGISTERC(num_frag_recvs, "Number of receives where the entire MPI message fragment fit into a " + "single MTU/network send"); REGISTERC(num_chunk_recvs, - "Number of receives that were part of a larger MPI message fragment (i.e., this receive was reassembled into a larger MPI message fragment)"); + "Number of receives that were part of a larger MPI message fragment (i.e., this " + "receive was reassembled into a larger MPI message fragment)"); REGISTERC(num_badfrag_recvs, "Number of chunks received that had a bad fragment ID (this should never be >0)"); - REGISTERC(num_ack_recvs, - "Total number of ACKs received"); + REGISTERC(num_ack_recvs, "Total number of ACKs received"); REGISTERC(num_old_dup_acks, "Number of old duplicate ACKs received (i.e., before the current expected ACK)"); - REGISTERC(num_dup_acks, - "Number of duplicate ACKs received (i.e., the current expected ACK)"); + REGISTERC(num_dup_acks, "Number of duplicate ACKs received (i.e., the current expected ACK)"); - REGISTERC(num_recv_reposts, - "Number of times buffers have been reposted for receives"); - REGISTERC(num_crc_errors, - "Number of times receives were aborted because of a CRC error"); + REGISTERC(num_recv_reposts, "Number of times buffers have been reposted for receives"); + REGISTERC(num_crc_errors, "Number of times receives were aborted because of a CRC error"); - REGISTERC(pml_module_sends, - "Number of times the PML has called down to send a message"); + REGISTERC(pml_module_sends, "Number of times the PML has called down to send a message"); REGISTERC(pml_send_callbacks, "Number of times the usNIC BTL has called up to the PML to complete a send"); } - /* * Initialize MPI_T performance variables */ diff --git a/opal/mca/btl/usnic/btl_usnic_stats.h b/opal/mca/btl/usnic/btl_usnic_stats.h index ae18cb0fed6..efbdead634b 100644 --- a/opal/mca/btl/usnic/btl_usnic_stats.h +++ b/opal/mca/btl/usnic/btl_usnic_stats.h @@ -22,7 +22,6 @@ #include "opal/util/event.h" - /** * Struct containing all the statistics that are trackedx */ @@ -68,7 +67,6 @@ typedef struct opal_btl_usnic_module_stats_t { struct timeval timeout; } opal_btl_usnic_module_stats_t; - /** * Initialize the stats on a module. Must use "struct * opal_btl_usnic_module_t*" here to avoid an #include cycle. diff --git a/opal/mca/btl/usnic/btl_usnic_test.c b/opal/mca/btl/usnic/btl_usnic_test.c index 49fb7079b5f..8cb5baa5123 100644 --- a/opal/mca/btl/usnic/btl_usnic_test.c +++ b/opal/mca/btl/usnic/btl_usnic_test.c @@ -53,9 +53,7 @@ static void init_test_infra(void) } } -void opal_btl_usnic_register_test(const char *name, - opal_btl_usnic_test_fn_t test_fn, - void *ctx) +void opal_btl_usnic_register_test(const char *name, opal_btl_usnic_test_fn_t test_fn, void *ctx) { struct test_info *info = malloc(sizeof(*info)); assert(info != NULL); @@ -82,38 +80,34 @@ void opal_btl_usnic_run_tests(void) } test_out("STARTING TESTS\n"); - OPAL_LIST_FOREACH(info, &all_tests, struct test_info) { + OPAL_LIST_FOREACH (info, &all_tests, struct test_info) { test_out("running test '%s'... ", info->name); result = info->test_fn(info->ctx); ++opal_btl_usnic_num_tests_run; switch (result) { - case TEST_PASSED: - ++opal_btl_usnic_num_tests_passed; - test_out("PASSED\n"); - break; - case TEST_FAILED: - ++opal_btl_usnic_num_tests_failed; - test_out("FAILED\n"); - break; - case TEST_SKIPPED: - ++opal_btl_usnic_num_tests_skipped; - test_out("SKIPPED\n"); - break; + case TEST_PASSED: + ++opal_btl_usnic_num_tests_passed; + test_out("PASSED\n"); + break; + case TEST_FAILED: + ++opal_btl_usnic_num_tests_failed; + test_out("FAILED\n"); + break; + case TEST_SKIPPED: + ++opal_btl_usnic_num_tests_skipped; + test_out("SKIPPED\n"); + break; } } - test_out("FINISHED TESTS (%d passed, %d failed, %d skipped)\n", - opal_btl_usnic_num_tests_passed, - opal_btl_usnic_num_tests_failed, - opal_btl_usnic_num_tests_skipped); + test_out("FINISHED TESTS (%d passed, %d failed, %d skipped)\n", opal_btl_usnic_num_tests_passed, + opal_btl_usnic_num_tests_failed, opal_btl_usnic_num_tests_skipped); } #else /* !OPAL_BTL_USNIC_UNIT_TESTS */ -void opal_btl_usnic_register_test(const char *name, - opal_btl_usnic_test_fn_t test_fn, - void *ctx) +void opal_btl_usnic_register_test(const char *name, opal_btl_usnic_test_fn_t test_fn, void *ctx) { abort(); /* never should be called */ } diff --git a/opal/mca/btl/usnic/btl_usnic_test.h b/opal/mca/btl/usnic/btl_usnic_test.h index e6f6b2d7d6c..7544d6d34dc 100644 --- a/opal/mca/btl/usnic/btl_usnic_test.h +++ b/opal/mca/btl/usnic/btl_usnic_test.h @@ -15,79 +15,71 @@ typedef int (*opal_btl_usnic_test_fn_t)(void *ctx); #if OPAL_BTL_USNIC_UNIT_TESTS -# define test_out(...) fprintf(stderr, __VA_ARGS__) -# define check(a) \ - do { \ - if (!(a)) { \ - test_out("%s:%d: check failed, '%s'\n", __func__, __LINE__, #a); \ - return TEST_FAILED; \ - } \ - } while (0) -# define check_str_eq(a,b) \ - do { \ - const char *a_ = (a); \ - const char *b_ = (b); \ - if (0 != strcmp(a_,b_)) { \ - test_out("%s:%d: check failed, \"%s\" != \"%s\"\n", \ - __func__, __LINE__, a_, b_); \ - return TEST_FAILED; \ - } \ - } while (0) -# define check_int_eq(got, expected) \ - do { \ - if ((got) != (expected)) { \ - test_out("%s:%d: check failed, \"%s\" != \"%s\", got %d\n", \ - __func__, __LINE__, #got, #expected, (got)); \ - return TEST_FAILED; \ - } \ - } while (0) +# define test_out(...) fprintf(stderr, __VA_ARGS__) +# define check(a) \ + do { \ + if (!(a)) { \ + test_out("%s:%d: check failed, '%s'\n", __func__, __LINE__, #a); \ + return TEST_FAILED; \ + } \ + } while (0) +# define check_str_eq(a, b) \ + do { \ + const char *a_ = (a); \ + const char *b_ = (b); \ + if (0 != strcmp(a_, b_)) { \ + test_out("%s:%d: check failed, \"%s\" != \"%s\"\n", __func__, __LINE__, a_, b_); \ + return TEST_FAILED; \ + } \ + } while (0) +# define check_int_eq(got, expected) \ + do { \ + if ((got) != (expected)) { \ + test_out("%s:%d: check failed, \"%s\" != \"%s\", got %d\n", __func__, __LINE__, \ + #got, #expected, (got)); \ + return TEST_FAILED; \ + } \ + } while (0) /* just use check_int_eq for now, no public error code to string routine * exists (opal_err2str is static) */ -# define check_err_code(got, expected) \ - check_int_eq(got, expected) -# define check_msg(a, msg) \ - do { \ - if (!(a)) { \ - test_out("%s:%d: check failed, \"%s\" (%s)\n", \ - __func__, __LINE__, #a, (msg)); \ - return TEST_FAILED; \ - } \ - } while (0) +# define check_err_code(got, expected) check_int_eq(got, expected) +# define check_msg(a, msg) \ + do { \ + if (!(a)) { \ + test_out("%s:%d: check failed, \"%s\" (%s)\n", __func__, __LINE__, #a, (msg)); \ + return TEST_FAILED; \ + } \ + } while (0) extern int opal_btl_usnic_num_tests_run; extern int opal_btl_usnic_num_tests_passed; extern int opal_btl_usnic_num_tests_failed; extern int opal_btl_usnic_num_tests_skipped; -enum test_result { - TEST_PASSED = 0, - TEST_FAILED, - TEST_SKIPPED -}; +enum test_result { TEST_PASSED = 0, TEST_FAILED, TEST_SKIPPED }; /* let us actually paste __LINE__ with other tokens */ -# define USNIC_PASTE(a,b) USNIC_PASTE2(a,b) -# define USNIC_PASTE2(a,b) a ## b +# define USNIC_PASTE(a, b) USNIC_PASTE2(a, b) +# define USNIC_PASTE2(a, b) a##b /* A helper macro to de-clutter test registration. */ -# define USNIC_REGISTER_TEST(name, test_fn, ctx) \ -__attribute__((__constructor__)) \ -static void USNIC_PASTE(usnic_reg_ctor_,__LINE__)(void) \ -{ \ - opal_btl_usnic_register_test(name, test_fn, ctx); \ -} \ +# define USNIC_REGISTER_TEST(name, test_fn, ctx) \ + __attribute__((__constructor__)) static void USNIC_PASTE(usnic_reg_ctor_, __LINE__)(void) \ + { \ + opal_btl_usnic_register_test(name, test_fn, ctx); \ + } #else /* !OPAL_BTL_USNIC_UNIT_TESTS */ -# define test_out(...) do {} while(0) -# define USNIC_REGISTER_TEST(name, test_fn, ctx) +# define test_out(...) \ + do { \ + } while (0) +# define USNIC_REGISTER_TEST(name, test_fn, ctx) #endif /* Run all registered tests. Typically called by an external utility that * dlopens the usnic BTL shared object. See run_usnic_tests.c. */ void opal_btl_usnic_run_tests(void); -void opal_btl_usnic_register_test(const char *name, - opal_btl_usnic_test_fn_t test_fn, - void *ctx); +void opal_btl_usnic_register_test(const char *name, opal_btl_usnic_test_fn_t test_fn, void *ctx); /* should be called once, at component close time */ void opal_btl_usnic_cleanup_tests(void); diff --git a/opal/mca/btl/usnic/btl_usnic_util.c b/opal/mca/btl/usnic/btl_usnic_util.c index 8b19f161f0a..3596ec311d3 100644 --- a/opal/mca/btl/usnic/btl_usnic_util.c +++ b/opal/mca/btl/usnic/btl_usnic_util.c @@ -12,14 +12,13 @@ #include #include -#include "opal/util/show_help.h" #include "opal/constants.h" #include "opal/util/if.h" +#include "opal/util/show_help.h" #include "btl_usnic_module.h" #include "btl_usnic_util.h" - // The following comment tells Coverity that this function does not return. // See https://scan.coverity.com/tune. @@ -29,9 +28,9 @@ void opal_btl_usnic_exit(opal_btl_usnic_module_t *module) if (NULL == module) { /* Find the first module with an error callback */ for (int i = 0; i < mca_btl_usnic_component.num_modules; ++i) { - if (NULL != mca_btl_usnic_component.usnic_active_modules && - NULL != mca_btl_usnic_component.usnic_active_modules[i] && - NULL != mca_btl_usnic_component.usnic_active_modules[i]->pml_error_callback) { + if (NULL != mca_btl_usnic_component.usnic_active_modules + && NULL != mca_btl_usnic_component.usnic_active_modules[i] + && NULL != mca_btl_usnic_component.usnic_active_modules[i]->pml_error_callback) { module = mca_btl_usnic_component.usnic_active_modules[i]; break; } @@ -50,10 +49,10 @@ void opal_btl_usnic_exit(opal_btl_usnic_module_t *module) if the passed proc is yourself (e.g., don't call del_procs() on yourself). */ if (NULL != module->pml_error_callback) { - module->pml_error_callback(&module->super, - MCA_BTL_ERROR_FLAGS_FATAL, - (opal_proc_t*) opal_proc_local_get(), - "The usnic BTL is aborting the MPI job (via PML error callback)."); + module + ->pml_error_callback(&module->super, MCA_BTL_ERROR_FLAGS_FATAL, + (opal_proc_t *) opal_proc_local_get(), + "The usnic BTL is aborting the MPI job (via PML error callback)."); } /* If the PML error callback returns (or if there wasn't one), @@ -61,7 +60,6 @@ void opal_btl_usnic_exit(opal_btl_usnic_module_t *module) exit(1); } - /* * Simple utility in a .c file, mainly so that inline functions in .h * files don't need to include the show_help header file. @@ -75,25 +73,20 @@ void opal_btl_usnic_exit(opal_btl_usnic_module_t *module) /* coverity[+kill] */ void opal_btl_usnic_util_abort(const char *msg, const char *file, int line) { - opal_show_help("help-mpi-btl-usnic.txt", "internal error after init", - true, - opal_process_info.nodename, - file, line, msg); + opal_show_help("help-mpi-btl-usnic.txt", "internal error after init", true, + opal_process_info.nodename, file, line, msg); opal_btl_usnic_exit(NULL); /* Never returns */ } - -void -opal_btl_usnic_dump_hex(int verbose_level, int output_id, - void *vaddr, int len) +void opal_btl_usnic_dump_hex(int verbose_level, int output_id, void *vaddr, int len) { char buf[128]; size_t bufspace; int i, ret; char *p; - uint32_t sum=0; + uint32_t sum = 0; uint8_t *addr; addr = vaddr; @@ -101,65 +94,51 @@ opal_btl_usnic_dump_hex(int verbose_level, int output_id, memset(buf, 0, sizeof(buf)); bufspace = sizeof(buf) - 1; - for (i=0; i +#include /* for dirname() */ #include #include #include -#include /* for dirname() */ #include @@ -39,22 +39,22 @@ int main(int argc, char **argv) char *to; int path_len; - mpi_handle = dlopen("lib" OMPI_LIBMPI_NAME ".so", RTLD_NOW|RTLD_GLOBAL); + mpi_handle = dlopen("lib" OMPI_LIBMPI_NAME ".so", RTLD_NOW | RTLD_GLOBAL); if (mpi_handle == NULL) { fprintf(stderr, "mpi_handle=NULL dlerror()=%s\n", dlerror()); abort(); } /* casting awfulness needed for GCC's "-pedantic" option :( */ - *(void **)(&init) = dlsym(mpi_handle, "MPI_Init"); + *(void **) (&init) = dlsym(mpi_handle, "MPI_Init"); if (init == NULL) { fprintf(stderr, "init=NULL dlerror()=%s\n", dlerror()); abort(); } /* casting awfulness needed for GCC's "-pedantic" option :( */ - *(void **)(&finalize) = dlsym(mpi_handle, "MPI_Finalize"); + *(void **) (&finalize) = dlsym(mpi_handle, "MPI_Finalize"); if (finalize == NULL) { - fprintf(stderr, "finalize=%p dlerror()=%s\n", *(void **)(&finalize), dlerror()); + fprintf(stderr, "finalize=%p dlerror()=%s\n", *(void **) (&finalize), dlerror()); abort(); } @@ -62,22 +62,22 @@ int main(int argc, char **argv) init(&argc, &argv); /* figure out where the usnic BTL shared object is relative to libmpi.so */ - if (!dladdr(*(void **)(&init), &info)) { + if (!dladdr(*(void **) (&init), &info)) { fprintf(stderr, "ERROR: unable to dladdr(init,...)\n"); abort(); } libmpi_path = strdup(info.dli_fname); assert(libmpi_path != NULL); path_len = strlen(libmpi_path) + strlen("/openmpi/") + strlen(MCA_BTL_USNIC_SO); - path = calloc(path_len+1, 1); + path = calloc(path_len + 1, 1); to = path; to = stpcpy(to, dirname(libmpi_path)); to = stpcpy(to, "/openmpi/"); to = stpcpy(to, MCA_BTL_USNIC_SO); - usnic_handle = dlopen(path, RTLD_NOW|RTLD_LOCAL); + usnic_handle = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (usnic_handle == NULL) { - fprintf(stderr, "usnic_handle=%p dlerror()=%s\n", (void *)usnic_handle, dlerror()); + fprintf(stderr, "usnic_handle=%p dlerror()=%s\n", (void *) usnic_handle, dlerror()); abort(); } @@ -85,10 +85,9 @@ int main(int argc, char **argv) free(path); /* casting awfulness needed for GCC's "-pedantic" option :( */ - *(void **)(&run_tests) = dlsym(usnic_handle, BTL_USNIC_RUN_TESTS_SYMBOL); + *(void **) (&run_tests) = dlsym(usnic_handle, BTL_USNIC_RUN_TESTS_SYMBOL); if (run_tests == NULL) { - fprintf(stderr, "run_tests=%p dlerror()=%s\n", - *(void **)(&run_tests), dlerror()); + fprintf(stderr, "run_tests=%p dlerror()=%s\n", *(void **) (&run_tests), dlerror()); abort(); } run_tests(); diff --git a/opal/mca/common/cuda/common_cuda.c b/opal/mca/common/cuda/common_cuda.c index 81e6a134486..b6826408df0 100644 --- a/opal/mca/common/cuda/common_cuda.c +++ b/opal/mca/common/cuda/common_cuda.c @@ -27,22 +27,22 @@ */ #include "opal_config.h" +#include #include #include -#include #include "opal/align.h" #include "opal/datatype/opal_convertor.h" -#include "opal/util/output.h" -#include "opal/util/show_help.h" -#include "opal/util/proc.h" #include "opal/util/argv.h" +#include "opal/util/output.h" #include "opal/util/printf.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" +#include "opal/mca/dl/base/base.h" #include "opal/mca/rcache/base/base.h" -#include "opal/runtime/opal_params.h" #include "opal/mca/timer/base/base.h" -#include "opal/mca/dl/base/base.h" +#include "opal/runtime/opal_params.h" #include "common_cuda.h" @@ -54,24 +54,22 @@ * We want to make sure we find cuMemFree_v2, not cuMemFree. */ #define STRINGIFY2(x) #x -#define STRINGIFY(x) STRINGIFY2(x) - -#define OPAL_CUDA_DLSYM(libhandle, funcName) \ -do { \ - char *err_msg; \ - void *ptr; \ - if (OPAL_SUCCESS != \ - opal_dl_lookup(libhandle, STRINGIFY(funcName), &ptr, &err_msg)) { \ - opal_show_help("help-mpi-common-cuda.txt", "dlsym failed", true, \ - STRINGIFY(funcName), err_msg); \ - return 1; \ - } else { \ - *(void **)(&cuFunc.funcName) = ptr; \ - opal_output_verbose(15, mca_common_cuda_output, \ - "CUDA: successful dlsym of %s", \ - STRINGIFY(funcName)); \ - } \ -} while (0) +#define STRINGIFY(x) STRINGIFY2(x) + +#define OPAL_CUDA_DLSYM(libhandle, funcName) \ + do { \ + char *err_msg; \ + void *ptr; \ + if (OPAL_SUCCESS != opal_dl_lookup(libhandle, STRINGIFY(funcName), &ptr, &err_msg)) { \ + opal_show_help("help-mpi-common-cuda.txt", "dlsym failed", true, STRINGIFY(funcName), \ + err_msg); \ + return 1; \ + } else { \ + *(void **) (&cuFunc.funcName) = ptr; \ + opal_output_verbose(15, mca_common_cuda_output, "CUDA: successful dlsym of %s", \ + STRINGIFY(funcName)); \ + } \ + } while (0) /* Structure to hold CUDA function pointers that get dynamically loaded. */ struct cudaFunctionTable { @@ -89,12 +87,12 @@ struct cudaFunctionTable { int (*cuEventQuery)(CUevent); int (*cuEventDestroy)(CUevent); int (*cuStreamWaitEvent)(CUstream, CUevent, unsigned int); - int (*cuMemGetAddressRange)(CUdeviceptr*, size_t*, CUdeviceptr); - int (*cuIpcGetEventHandle)(CUipcEventHandle*, CUevent); - int (*cuIpcOpenEventHandle)(CUevent*, CUipcEventHandle); - int (*cuIpcOpenMemHandle)(CUdeviceptr*, CUipcMemHandle, unsigned int); + int (*cuMemGetAddressRange)(CUdeviceptr *, size_t *, CUdeviceptr); + int (*cuIpcGetEventHandle)(CUipcEventHandle *, CUevent); + int (*cuIpcOpenEventHandle)(CUevent *, CUipcEventHandle); + int (*cuIpcOpenMemHandle)(CUdeviceptr *, CUipcMemHandle, unsigned int); int (*cuIpcCloseMemHandle)(CUdeviceptr); - int (*cuIpcGetMemHandle)(CUipcMemHandle*, CUdeviceptr); + int (*cuIpcGetMemHandle)(CUipcMemHandle *, CUdeviceptr); int (*cuCtxGetDevice)(CUdevice *); int (*cuDeviceCanAccessPeer)(int *, CUdevice, CUdevice); int (*cuDeviceGet)(CUdevice *, int); @@ -133,10 +131,10 @@ static opal_mutex_t common_cuda_dtoh_lock; static opal_mutex_t common_cuda_ipc_lock; /* Functions called by opal layer - plugged into opal function table */ -static int mca_common_cuda_is_gpu_buffer(const void*, opal_convertor_t*); -static int mca_common_cuda_memmove(void*, void*, size_t); -static int mca_common_cuda_cu_memcpy_async(void*, const void*, size_t, opal_convertor_t*); -static int mca_common_cuda_cu_memcpy(void*, const void*, size_t); +static int mca_common_cuda_is_gpu_buffer(const void *, opal_convertor_t *); +static int mca_common_cuda_memmove(void *, void *, size_t); +static int mca_common_cuda_cu_memcpy_async(void *, const void *, size_t, opal_convertor_t *); +static int mca_common_cuda_cu_memcpy(void *, const void *, size_t); /* Function that gets plugged into opal layer */ static int mca_common_cuda_stage_two_init(opal_common_cuda_function_table_t *); @@ -151,10 +149,7 @@ struct common_cuda_mem_regs_t { }; typedef struct common_cuda_mem_regs_t common_cuda_mem_regs_t; OBJ_CLASS_DECLARATION(common_cuda_mem_regs_t); -OBJ_CLASS_INSTANCE(common_cuda_mem_regs_t, - opal_list_item_t, - NULL, - NULL); +OBJ_CLASS_INSTANCE(common_cuda_mem_regs_t, opal_list_item_t, NULL, NULL); static int mca_common_cuda_async = 1; static int mca_common_cuda_cumemcpy_async; @@ -206,20 +201,20 @@ static int ctx_ok = 1; static opal_timer_t ts_start; static opal_timer_t ts_end; static double accum; -#define THOUSAND 1000L -#define MILLION 1000000L +# define THOUSAND 1000L +# define MILLION 1000000L static float mydifftime(opal_timer_t ts_start, opal_timer_t ts_end); #endif /* OPAL_ENABLE_DEBUG */ /* These functions are typically unused in the optimized builds. */ -static void cuda_dump_evthandle(int, void *, char *) __opal_attribute_unused__ ; -static void cuda_dump_memhandle(int, void *, char *) __opal_attribute_unused__ ; +static void cuda_dump_evthandle(int, void *, char *) __opal_attribute_unused__; +static void cuda_dump_memhandle(int, void *, char *) __opal_attribute_unused__; #if OPAL_ENABLE_DEBUG -#define CUDA_DUMP_MEMHANDLE(a) cuda_dump_memhandle a -#define CUDA_DUMP_EVTHANDLE(a) cuda_dump_evthandle a +# define CUDA_DUMP_MEMHANDLE(a) cuda_dump_memhandle a +# define CUDA_DUMP_EVTHANDLE(a) cuda_dump_evthandle a #else -#define CUDA_DUMP_MEMHANDLE(a) -#define CUDA_DUMP_EVTHANDLE(a) +# define CUDA_DUMP_MEMHANDLE(a) +# define CUDA_DUMP_EVTHANDLE(a) #endif /* OPAL_ENABLE_DEBUG */ /* This is a seperate function so we can see these variables with ompi_info and @@ -233,10 +228,8 @@ void mca_common_cuda_register_mca_variables(void) /* Set different levels of verbosity in the cuda related code. */ mca_common_cuda_verbose = 0; (void) mca_base_var_register("ompi", "mpi", "common_cuda", "verbose", - "Set level of common cuda verbosity", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + "Set level of common cuda verbosity", MCA_BASE_VAR_TYPE_INT, NULL, + 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_common_cuda_verbose); /* Control whether system buffers get CUDA pinned or not. Allows for @@ -244,10 +237,8 @@ void mca_common_cuda_register_mca_variables(void) mca_common_cuda_register_memory = true; (void) mca_base_var_register("ompi", "mpi", "common_cuda", "register_memory", "Whether to cuMemHostRegister preallocated BTL buffers", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_common_cuda_register_memory); + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_common_cuda_register_memory); /* Control whether we see warnings when CUDA memory registration fails. This is * useful when CUDA support is configured in, but we are running a regular MPI @@ -255,54 +246,44 @@ void mca_common_cuda_register_mca_variables(void) mca_common_cuda_warning = true; (void) mca_base_var_register("ompi", "mpi", "common_cuda", "warning", "Whether to print warnings when CUDA registration fails", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_common_cuda_warning); + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_common_cuda_warning); /* Use this flag to test async vs sync copies */ mca_common_cuda_async = 1; (void) mca_base_var_register("ompi", "mpi", "common_cuda", "memcpy_async", "Set to 0 to force CUDA sync copy instead of async", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_common_cuda_async); + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &mca_common_cuda_async); /* Use this parameter to increase the number of outstanding events allows */ (void) mca_base_var_register("ompi", "mpi", "common_cuda", "event_max", - "Set number of oustanding CUDA events", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + "Set number of oustanding CUDA events", MCA_BASE_VAR_TYPE_INT, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &cuda_event_max); /* Use this flag to test cuMemcpyAsync vs cuMemcpy */ mca_common_cuda_cumemcpy_async = 1; - (void) mca_base_var_register("ompi", "mpi", "common_cuda", "cumemcpy_async", - "Set to 0 to force CUDA cuMemcpy instead of cuMemcpyAsync/cuStreamSynchronize", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_common_cuda_cumemcpy_async); + (void) mca_base_var_register( + "ompi", "mpi", "common_cuda", "cumemcpy_async", + "Set to 0 to force CUDA cuMemcpy instead of cuMemcpyAsync/cuStreamSynchronize", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &mca_common_cuda_cumemcpy_async); #if OPAL_ENABLE_DEBUG /* Use this flag to dump out timing of cumempcy sync and async */ mca_common_cuda_cumemcpy_timing = 0; (void) mca_base_var_register("ompi", "mpi", "common_cuda", "cumemcpy_timing", - "Set to 1 to dump timing of eager copies", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, + "Set to 1 to dump timing of eager copies", MCA_BASE_VAR_TYPE_INT, + NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, &mca_common_cuda_cumemcpy_timing); #endif /* OPAL_ENABLE_DEBUG */ - (void) mca_base_var_register("ompi", "mpi", "common_cuda", "gpu_mem_check_workaround", - "Set to 0 to disable GPU memory check workaround. A user would rarely have to do this.", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_common_cuda_gpu_mem_check_workaround); + (void) mca_base_var_register( + "ompi", "mpi", "common_cuda", "gpu_mem_check_workaround", + "Set to 0 to disable GPU memory check workaround. A user would rarely have to do this.", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &mca_common_cuda_gpu_mem_check_workaround); } /** @@ -394,27 +375,23 @@ int mca_common_cuda_stage_one_init(void) filename = strdup(cudalibs[i]); } if (NULL == filename) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, + OPAL_PROC_MY_HOSTNAME); return 1; } - retval = opal_dl_open(filename, false, false, - &libcuda_handle, &str); + retval = opal_dl_open(filename, false, false, &libcuda_handle, &str); if (OPAL_SUCCESS != retval || NULL == libcuda_handle) { if (NULL != str) { opal_argv_append(&errsize, &errmsgs, str); } else { - opal_argv_append(&errsize, &errmsgs, - "opal_dl_open() returned NULL."); + opal_argv_append(&errsize, &errmsgs, "opal_dl_open() returned NULL."); } - opal_output_verbose(10, mca_common_cuda_output, - "CUDA: Library open error: %s", - errmsgs[errsize-1]); + opal_output_verbose(10, mca_common_cuda_output, "CUDA: Library open error: %s", + errmsgs[errsize - 1]); } else { opal_output_verbose(10, mca_common_cuda_output, - "CUDA: Library successfully opened %s", - cudalibs[i]); + "CUDA: Library successfully opened %s", cudalibs[i]); stage_one_init_passed = true; break; } @@ -431,8 +408,7 @@ int mca_common_cuda_stage_one_init(void) if (true != stage_one_init_passed) { errmsg = opal_argv_join(errmsgs, '\n'); if (opal_warn_on_missing_libcuda) { - opal_show_help("help-mpi-common-cuda.txt", "dlopen failed", true, - errmsg); + opal_show_help("help-mpi-common-cuda.txt", "dlopen failed", true, errmsg); } opal_cuda_support = 0; } @@ -503,8 +479,7 @@ static int mca_common_cuda_stage_two_init(opal_common_cuda_function_table_t *fta ftable->gpu_malloc = &mca_common_cuda_malloc; ftable->gpu_free = &mca_common_cuda_free; - opal_output_verbose(30, mca_common_cuda_output, - "CUDA: support functions initialized"); + opal_output_verbose(30, mca_common_cuda_output, "CUDA: support functions initialized"); return OPAL_SUCCESS; } @@ -523,10 +498,9 @@ static int mca_common_cuda_stage_three_init(void) common_cuda_mem_regs_t *mem_reg; OPAL_THREAD_LOCK(&common_cuda_init_lock); - opal_output_verbose(20, mca_common_cuda_output, - "CUDA: entering stage three init"); + opal_output_verbose(20, mca_common_cuda_output, "CUDA: entering stage three init"); -/* Compiled without support or user disabled support */ + /* Compiled without support or user disabled support */ if (OPAL_UNLIKELY(!opal_cuda_support)) { opal_output_verbose(20, mca_common_cuda_output, "CUDA: No mpi cuda support, exiting stage three init"); @@ -561,16 +535,14 @@ static int mca_common_cuda_stage_three_init(void) opal_show_help("help-mpi-common-cuda.txt", "cuCtxGetCurrent failed not initialized", true); } else { - opal_show_help("help-mpi-common-cuda.txt", "cuCtxGetCurrent failed", - true, res); + opal_show_help("help-mpi-common-cuda.txt", "cuCtxGetCurrent failed", true, res); } } mca_common_cuda_enabled = false; mca_common_cuda_register_memory = false; } else if ((CUDA_SUCCESS == res) && (NULL == cuContext)) { if (mca_common_cuda_warning) { - opal_show_help("help-mpi-common-cuda.txt", "cuCtxGetCurrent returned NULL", - true); + opal_show_help("help-mpi-common-cuda.txt", "cuCtxGetCurrent returned NULL", true); } mca_common_cuda_enabled = false; mca_common_cuda_register_memory = false; @@ -579,8 +551,7 @@ static int mca_common_cuda_stage_three_init(void) * value. Normally, that is 1, but the user can override it to disable * registration of the internal buffers. */ mca_common_cuda_enabled = true; - opal_output_verbose(20, mca_common_cuda_output, - "CUDA: cuCtxGetCurrent succeeded"); + opal_output_verbose(20, mca_common_cuda_output, "CUDA: cuCtxGetCurrent succeeded"); } /* No need to go on at this point. If we cannot create a context and we are at @@ -600,8 +571,7 @@ static int mca_common_cuda_stage_three_init(void) cuda_event_ipc_array = (CUevent *) calloc(cuda_event_max, sizeof(CUevent *)); if (NULL == cuda_event_ipc_array) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, OPAL_PROC_MY_HOSTNAME); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -610,8 +580,8 @@ static int mca_common_cuda_stage_three_init(void) for (i = 0; i < cuda_event_max; i++) { res = cuFunc.cuEventCreate(&cuda_event_ipc_array[i], CU_EVENT_DISABLE_TIMING); if (CUDA_SUCCESS != res) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -619,11 +589,10 @@ static int mca_common_cuda_stage_three_init(void) /* The first available status index is 0. Make an empty frag array. */ - cuda_event_ipc_frag_array = (struct mca_btl_base_descriptor_t **) - malloc(sizeof(struct mca_btl_base_descriptor_t *) * cuda_event_max); + cuda_event_ipc_frag_array = (struct mca_btl_base_descriptor_t **) malloc( + sizeof(struct mca_btl_base_descriptor_t *) * cuda_event_max); if (NULL == cuda_event_ipc_frag_array) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, OPAL_PROC_MY_HOSTNAME); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -638,8 +607,7 @@ static int mca_common_cuda_stage_three_init(void) cuda_event_dtoh_array = (CUevent *) calloc(cuda_event_max, sizeof(CUevent *)); if (NULL == cuda_event_dtoh_array) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, OPAL_PROC_MY_HOSTNAME); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -648,8 +616,8 @@ static int mca_common_cuda_stage_three_init(void) for (i = 0; i < cuda_event_max; i++) { res = cuFunc.cuEventCreate(&cuda_event_dtoh_array[i], CU_EVENT_DISABLE_TIMING); if (CUDA_SUCCESS != res) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -657,11 +625,10 @@ static int mca_common_cuda_stage_three_init(void) /* The first available status index is 0. Make an empty frag array. */ - cuda_event_dtoh_frag_array = (struct mca_btl_base_descriptor_t **) - malloc(sizeof(struct mca_btl_base_descriptor_t *) * cuda_event_max); + cuda_event_dtoh_frag_array = (struct mca_btl_base_descriptor_t **) malloc( + sizeof(struct mca_btl_base_descriptor_t *) * cuda_event_max); if (NULL == cuda_event_dtoh_frag_array) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, OPAL_PROC_MY_HOSTNAME); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -674,52 +641,50 @@ static int mca_common_cuda_stage_three_init(void) cuda_event_htod_array = (CUevent *) calloc(cuda_event_max, sizeof(CUevent *)); if (NULL == cuda_event_htod_array) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); - rc = OPAL_ERROR; - goto cleanup_and_error; + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, OPAL_PROC_MY_HOSTNAME); + rc = OPAL_ERROR; + goto cleanup_and_error; } /* Create the events since they can be reused. */ for (i = 0; i < cuda_event_max; i++) { res = cuFunc.cuEventCreate(&cuda_event_htod_array[i], CU_EVENT_DISABLE_TIMING); if (CUDA_SUCCESS != res) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); - rc = OPAL_ERROR; - goto cleanup_and_error; + opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); + rc = OPAL_ERROR; + goto cleanup_and_error; } } /* The first available status index is 0. Make an empty frag array. */ - cuda_event_htod_frag_array = (struct mca_btl_base_descriptor_t **) - malloc(sizeof(struct mca_btl_base_descriptor_t *) * cuda_event_max); + cuda_event_htod_frag_array = (struct mca_btl_base_descriptor_t **) malloc( + sizeof(struct mca_btl_base_descriptor_t *) * cuda_event_max); if (NULL == cuda_event_htod_frag_array) { - opal_show_help("help-mpi-common-cuda.txt", "No memory", - true, OPAL_PROC_MY_HOSTNAME); - rc = OPAL_ERROR; - goto cleanup_and_error; + opal_show_help("help-mpi-common-cuda.txt", "No memory", true, OPAL_PROC_MY_HOSTNAME); + rc = OPAL_ERROR; + goto cleanup_and_error; } } s = opal_list_get_size(&common_cuda_memory_registrations); - for(i = 0; i < s; i++) { - mem_reg = (common_cuda_mem_regs_t *) - opal_list_remove_first(&common_cuda_memory_registrations); + for (i = 0; i < s; i++) { + mem_reg = (common_cuda_mem_regs_t *) opal_list_remove_first( + &common_cuda_memory_registrations); if (mca_common_cuda_enabled && mca_common_cuda_register_memory) { res = cuFunc.cuMemHostRegister(mem_reg->ptr, mem_reg->amount, 0); if (res != CUDA_SUCCESS) { /* If registering the memory fails, print a message and continue. * This is not a fatal error. */ opal_show_help("help-mpi-common-cuda.txt", "cuMemHostRegister during init failed", - true, mem_reg->ptr, mem_reg->amount, - OPAL_PROC_MY_HOSTNAME, res, mem_reg->msg); + true, mem_reg->ptr, mem_reg->amount, OPAL_PROC_MY_HOSTNAME, res, + mem_reg->msg); } else { opal_output_verbose(20, mca_common_cuda_output, "CUDA: cuMemHostRegister OK on rcache %s: " "address=%p, bufsize=%d", - mem_reg->msg, mem_reg->ptr, (int)mem_reg->amount); + mem_reg->msg, mem_reg->ptr, (int) mem_reg->amount); } } free(mem_reg->msg); @@ -729,8 +694,8 @@ static int mca_common_cuda_stage_three_init(void) /* Create stream for use in ipc asynchronous copies */ res = cuFunc.cuStreamCreate(&ipcStream, 0); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -738,8 +703,8 @@ static int mca_common_cuda_stage_three_init(void) /* Create stream for use in dtoh asynchronous copies */ res = cuFunc.cuStreamCreate(&dtohStream, 0); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -747,8 +712,8 @@ static int mca_common_cuda_stage_three_init(void) /* Create stream for use in htod asynchronous copies */ res = cuFunc.cuStreamCreate(&htodStream, 0); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -757,8 +722,8 @@ static int mca_common_cuda_stage_three_init(void) /* Create stream for use in cuMemcpyAsync synchronous copies */ res = cuFunc.cuStreamCreate(&memcpyStream, 0); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamCreate failed", true, + OPAL_PROC_MY_HOSTNAME, res); rc = OPAL_ERROR; goto cleanup_and_error; } @@ -768,28 +733,26 @@ static int mca_common_cuda_stage_three_init(void) if (res != CUDA_SUCCESS) { /* If registering the memory fails, print a message and continue. * This is not a fatal error. */ - opal_show_help("help-mpi-common-cuda.txt", "cuMemHostRegister during init failed", - true, &checkmem, sizeof(int), - OPAL_PROC_MY_HOSTNAME, res, "checkmem"); + opal_show_help("help-mpi-common-cuda.txt", "cuMemHostRegister during init failed", true, + &checkmem, sizeof(int), OPAL_PROC_MY_HOSTNAME, res, "checkmem"); } else { opal_output_verbose(20, mca_common_cuda_output, "CUDA: cuMemHostRegister OK on test region"); } - opal_output_verbose(20, mca_common_cuda_output, - "CUDA: the extra gpu memory check is %s", (mca_common_cuda_gpu_mem_check_workaround == 1) ? "on":"off"); + opal_output_verbose(20, mca_common_cuda_output, "CUDA: the extra gpu memory check is %s", + (mca_common_cuda_gpu_mem_check_workaround == 1) ? "on" : "off"); - opal_output_verbose(30, mca_common_cuda_output, - "CUDA: initialized"); - opal_atomic_mb(); /* Make sure next statement does not get reordered */ + opal_output_verbose(30, mca_common_cuda_output, "CUDA: initialized"); + opal_atomic_mb(); /* Make sure next statement does not get reordered */ common_cuda_initialized = true; stage_three_init_complete = true; OPAL_THREAD_UNLOCK(&common_cuda_init_lock); return OPAL_SUCCESS; /* If we are here, something went wrong. Cleanup and return an error. */ - cleanup_and_error: +cleanup_and_error: opal_atomic_mb(); /* Make sure next statement does not get reordered */ stage_three_init_complete = true; OPAL_THREAD_UNLOCK(&common_cuda_init_lock); @@ -813,7 +776,8 @@ void mca_common_cuda_fini(void) stage_one_init_ref_count--; opal_output_verbose(20, mca_common_cuda_output, "CUDA: mca_common_cuda_fini, never completed initialization so " - "skipping fini, ref_count is now %d", stage_one_init_ref_count); + "skipping fini, ref_count is now %d", + stage_one_init_ref_count); return; } @@ -838,9 +802,9 @@ void mca_common_cuda_fini(void) if (CUDA_SUCCESS != res) { ctx_ok = 0; } - opal_output_verbose(20, mca_common_cuda_output, - "CUDA: mca_common_cuda_fini, cuMemHostUnregister returned %d, ctx_ok=%d", - res, ctx_ok); + opal_output_verbose( + 20, mca_common_cuda_output, + "CUDA: mca_common_cuda_fini, cuMemHostUnregister returned %d, ctx_ok=%d", res, ctx_ok); if (NULL != cuda_event_ipc_array) { if (ctx_ok) { @@ -921,7 +885,8 @@ void mca_common_cuda_fini(void) * Call the CUDA register function so we pin the memory in the CUDA * space. */ -void mca_common_cuda_register(void *ptr, size_t amount, char *msg) { +void mca_common_cuda_register(void *ptr, size_t amount, char *msg) +{ int res; /* Always first check if the support is enabled. If not, just return */ @@ -936,8 +901,7 @@ void mca_common_cuda_register(void *ptr, size_t amount, char *msg) { regptr->ptr = ptr; regptr->amount = amount; regptr->msg = strdup(msg); - opal_list_append(&common_cuda_memory_registrations, - (opal_list_item_t*)regptr); + opal_list_append(&common_cuda_memory_registrations, (opal_list_item_t *) regptr); OPAL_THREAD_UNLOCK(&common_cuda_init_lock); return; } @@ -949,14 +913,13 @@ void mca_common_cuda_register(void *ptr, size_t amount, char *msg) { if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { /* If registering the memory fails, print a message and continue. * This is not a fatal error. */ - opal_show_help("help-mpi-common-cuda.txt", "cuMemHostRegister failed", - true, ptr, amount, - OPAL_PROC_MY_HOSTNAME, res, msg); + opal_show_help("help-mpi-common-cuda.txt", "cuMemHostRegister failed", true, ptr, + amount, OPAL_PROC_MY_HOSTNAME, res, msg); } else { opal_output_verbose(20, mca_common_cuda_output, "CUDA: cuMemHostRegister OK on rcache %s: " "address=%p, bufsize=%d", - msg, ptr, (int)amount); + msg, ptr, (int) amount); } } } @@ -965,7 +928,8 @@ void mca_common_cuda_register(void *ptr, size_t amount, char *msg) { * Call the CUDA unregister function so we unpin the memory in the CUDA * space. */ -void mca_common_cuda_unregister(void *ptr, char *msg) { +void mca_common_cuda_unregister(void *ptr, char *msg) +{ int res, i, s; common_cuda_mem_regs_t *mem_reg; @@ -974,9 +938,9 @@ void mca_common_cuda_unregister(void *ptr, char *msg) { * Therefore, just release any of the resources. */ if (!common_cuda_initialized) { s = opal_list_get_size(&common_cuda_memory_registrations); - for(i = 0; i < s; i++) { - mem_reg = (common_cuda_mem_regs_t *) - opal_list_remove_first(&common_cuda_memory_registrations); + for (i = 0; i < s; i++) { + mem_reg = (common_cuda_mem_regs_t *) opal_list_remove_first( + &common_cuda_memory_registrations); free(mem_reg->msg); OBJ_RELEASE(mem_reg); } @@ -989,8 +953,8 @@ void mca_common_cuda_unregister(void *ptr, char *msg) { /* If unregistering the memory fails, just continue. This is during * shutdown. Only print when running in verbose mode. */ opal_output_verbose(20, mca_common_cuda_output, - "CUDA: cuMemHostUnregister failed: ptr=%p, res=%d, rcache=%s", - ptr, res, msg); + "CUDA: cuMemHostUnregister failed: ptr=%p, res=%d, rcache=%s", ptr, + res, msg); } else { opal_output_verbose(20, mca_common_cuda_output, @@ -1016,45 +980,44 @@ int cuda_getmemhandle(void *base, size_t size, mca_rcache_base_registration_t *n CUdeviceptr pbase; size_t psize; - mca_rcache_common_cuda_reg_t *cuda_reg = (mca_rcache_common_cuda_reg_t*)newreg; - memHandle = (CUipcMemHandle *)cuda_reg->data.memHandle; + mca_rcache_common_cuda_reg_t *cuda_reg = (mca_rcache_common_cuda_reg_t *) newreg; + memHandle = (CUipcMemHandle *) cuda_reg->data.memHandle; /* We should only be there if this is a CUDA device pointer */ - result = cuFunc.cuPointerGetAttribute(&memType, - CU_POINTER_ATTRIBUTE_MEMORY_TYPE, (CUdeviceptr)base); + result = cuFunc.cuPointerGetAttribute(&memType, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, + (CUdeviceptr) base); assert(CUDA_SUCCESS == result); assert(CU_MEMORYTYPE_DEVICE == memType); /* Get the memory handle so we can send it to the remote process. */ - result = cuFunc.cuIpcGetMemHandle(memHandle, (CUdeviceptr)base); + result = cuFunc.cuIpcGetMemHandle(memHandle, (CUdeviceptr) base); CUDA_DUMP_MEMHANDLE((100, memHandle, "GetMemHandle-After")); if (CUDA_SUCCESS != result) { - opal_show_help("help-mpi-common-cuda.txt", "cuIpcGetMemHandle failed", - true, result, base); + opal_show_help("help-mpi-common-cuda.txt", "cuIpcGetMemHandle failed", true, result, base); return OPAL_ERROR; } else { opal_output_verbose(20, mca_common_cuda_output, - "CUDA: cuIpcGetMemHandle passed: base=%p size=%d", - base, (int)size); + "CUDA: cuIpcGetMemHandle passed: base=%p size=%d", base, (int) size); } /* Need to get the real base and size of the memory handle. This is * how the remote side saves the handles in a cache. */ - result = cuFunc.cuMemGetAddressRange(&pbase, &psize, (CUdeviceptr)base); + result = cuFunc.cuMemGetAddressRange(&pbase, &psize, (CUdeviceptr) base); if (CUDA_SUCCESS != result) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemGetAddressRange failed", - true, result, base); + opal_show_help("help-mpi-common-cuda.txt", "cuMemGetAddressRange failed", true, result, + base); return OPAL_ERROR; } else { - opal_output_verbose(10, mca_common_cuda_output, - "CUDA: cuMemGetAddressRange passed: addr=%p, size=%d, pbase=%p, psize=%d ", - base, (int)size, (void *)pbase, (int)psize); + opal_output_verbose( + 10, mca_common_cuda_output, + "CUDA: cuMemGetAddressRange passed: addr=%p, size=%d, pbase=%p, psize=%d ", base, + (int) size, (void *) pbase, (int) psize); } /* Store all the information in the registration */ - cuda_reg->base.base = (void *)pbase; - cuda_reg->base.bound = (unsigned char *)pbase + psize - 1; + cuda_reg->base.base = (void *) pbase; + cuda_reg->base.bound = (unsigned char *) pbase + psize - 1; cuda_reg->data.memh_seg_addr.pval = (void *) pbase; cuda_reg->data.memh_seg_len = psize; @@ -1066,10 +1029,10 @@ int cuda_getmemhandle(void *base, size_t size, mca_rcache_base_registration_t *n */ memType = 1; /* Just use this variable since we already have it */ result = cuFunc.cuPointerSetAttribute(&memType, CU_POINTER_ATTRIBUTE_SYNC_MEMOPS, - (CUdeviceptr)base); + (CUdeviceptr) base); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuPointerSetAttribute failed", - true, OPAL_PROC_MY_HOSTNAME, result, base); + opal_show_help("help-mpi-common-cuda.txt", "cuPointerSetAttribute failed", true, + OPAL_PROC_MY_HOSTNAME, result, base); return OPAL_ERROR; } #else @@ -1080,10 +1043,9 @@ int cuda_getmemhandle(void *base, size_t size, mca_rcache_base_registration_t *n * Note that this needs to be the NULL stream to make since it is * unknown what stream any copies into the device memory were done * with. */ - result = cuFunc.cuEventRecord((CUevent)cuda_reg->data.event, 0); + result = cuFunc.cuEventRecord((CUevent) cuda_reg->data.event, 0); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", - true, result, base); + opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", true, result, base); return OPAL_ERROR; } #endif /* OPAL_CUDA_SYNC_MEMOPS */ @@ -1097,9 +1059,10 @@ int cuda_getmemhandle(void *base, size_t size, mca_rcache_base_registration_t *n */ int cuda_ungetmemhandle(void *reg_data, mca_rcache_base_registration_t *reg) { - opal_output_verbose(10, mca_common_cuda_output, - "CUDA: cuda_ungetmemhandle (no-op): base=%p", reg->base); - CUDA_DUMP_MEMHANDLE((100, ((mca_rcache_common_cuda_reg_t *)reg)->data.memHandle, "cuda_ungetmemhandle")); + opal_output_verbose(10, mca_common_cuda_output, "CUDA: cuda_ungetmemhandle (no-op): base=%p", + reg->base); + CUDA_DUMP_MEMHANDLE( + (100, ((mca_rcache_common_cuda_reg_t *) reg)->data.memHandle, "cuda_ungetmemhandle")); return OPAL_SUCCESS; } @@ -1115,14 +1078,14 @@ int cuda_openmemhandle(void *base, size_t size, mca_rcache_base_registration_t * { CUresult result; CUipcMemHandle *memHandle; - mca_rcache_common_cuda_reg_t *cuda_newreg = (mca_rcache_common_cuda_reg_t*)newreg; + mca_rcache_common_cuda_reg_t *cuda_newreg = (mca_rcache_common_cuda_reg_t *) newreg; /* Save in local variable to avoid ugly casting */ - memHandle = (CUipcMemHandle *)cuda_newreg->data.memHandle; + memHandle = (CUipcMemHandle *) cuda_newreg->data.memHandle; CUDA_DUMP_MEMHANDLE((100, memHandle, "Before call to cuIpcOpenMemHandle")); /* Open the memory handle and store it into the registration structure. */ - result = cuFunc.cuIpcOpenMemHandle((CUdeviceptr *)&newreg->alloc_base, *memHandle, + result = cuFunc.cuIpcOpenMemHandle((CUdeviceptr *) &newreg->alloc_base, *memHandle, CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS); /* If there are some stale entries in the cache, they can cause other @@ -1131,18 +1094,19 @@ int cuda_openmemhandle(void *base, size_t size, mca_rcache_base_registration_t * if (CUDA_ERROR_ALREADY_MAPPED == result) { opal_output_verbose(10, mca_common_cuda_output, "CUDA: cuIpcOpenMemHandle returned CUDA_ERROR_ALREADY_MAPPED for " - "p=%p,size=%d: notify memory pool\n", base, (int)size); + "p=%p,size=%d: notify memory pool\n", + base, (int) size); return OPAL_ERR_WOULD_BLOCK; } if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuIpcOpenMemHandle failed", - true, OPAL_PROC_MY_HOSTNAME, result, base); + opal_show_help("help-mpi-common-cuda.txt", "cuIpcOpenMemHandle failed", true, + OPAL_PROC_MY_HOSTNAME, result, base); /* Currently, this is a non-recoverable error */ return OPAL_ERROR; } else { opal_output_verbose(10, mca_common_cuda_output, "CUDA: cuIpcOpenMemHandle passed: base=%p (remote base=%p,size=%d)", - newreg->alloc_base, base, (int)size); + newreg->alloc_base, base, (int) size); CUDA_DUMP_MEMHANDLE((200, memHandle, "cuIpcOpenMemHandle")); } @@ -1155,16 +1119,16 @@ int cuda_openmemhandle(void *base, size_t size, mca_rcache_base_registration_t * int cuda_closememhandle(void *reg_data, mca_rcache_base_registration_t *reg) { CUresult result; - mca_rcache_common_cuda_reg_t *cuda_reg = (mca_rcache_common_cuda_reg_t*)reg; + mca_rcache_common_cuda_reg_t *cuda_reg = (mca_rcache_common_cuda_reg_t *) reg; /* Only attempt to close if we have valid context. This can change if a call * to the fini function is made and we discover context is gone. */ if (ctx_ok) { - result = cuFunc.cuIpcCloseMemHandle((CUdeviceptr)cuda_reg->base.alloc_base); + result = cuFunc.cuIpcCloseMemHandle((CUdeviceptr) cuda_reg->base.alloc_base); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { if (CUDA_ERROR_DEINITIALIZED != result) { - opal_show_help("help-mpi-common-cuda.txt", "cuIpcCloseMemHandle failed", - true, result, cuda_reg->base.alloc_base); + opal_show_help("help-mpi-common-cuda.txt", "cuIpcCloseMemHandle failed", true, + result, cuda_reg->base.alloc_base); } /* We will just continue on and hope things continue to work. */ } else { @@ -1182,20 +1146,19 @@ void mca_common_cuda_construct_event_and_handle(uintptr_t *event, void *handle) { CUresult result; - result = cuFunc.cuEventCreate((CUevent *)event, CU_EVENT_INTERPROCESS | CU_EVENT_DISABLE_TIMING); + result = cuFunc.cuEventCreate((CUevent *) event, + CU_EVENT_INTERPROCESS | CU_EVENT_DISABLE_TIMING); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventCreate failed", true, + OPAL_PROC_MY_HOSTNAME, result); } - result = cuFunc.cuIpcGetEventHandle((CUipcEventHandle *)handle, (CUevent)*event); + result = cuFunc.cuIpcGetEventHandle((CUipcEventHandle *) handle, (CUevent) *event); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuIpcGetEventHandle failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuIpcGetEventHandle failed", true, result); } CUDA_DUMP_EVTHANDLE((10, handle, "construct_event_and_handle")); - } void mca_common_cuda_destruct_event(uintptr_t event) @@ -1205,15 +1168,13 @@ void mca_common_cuda_destruct_event(uintptr_t event) /* Only attempt to destroy if we have valid context. This can change if a call * to the fini function is made and we discover context is gone. */ if (ctx_ok) { - result = cuFunc.cuEventDestroy((CUevent)event); + result = cuFunc.cuEventDestroy((CUevent) event); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventDestroy failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventDestroy failed", true, result); } } } - /* * Put remote event on stream to ensure that the the start of the * copy does not start until the completion of the event. @@ -1233,8 +1194,7 @@ void mca_common_wait_stream_synchronize(mca_rcache_common_cuda_reg_t *rget_reg) result = cuFunc.cuIpcOpenEventHandle(&event, evtHandle); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuIpcOpenEventHandle failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuIpcOpenEventHandle failed", true, result); } /* BEGIN of Workaround - There is a bug in CUDA 4.1 RC2 and earlier @@ -1244,22 +1204,20 @@ void mca_common_wait_stream_synchronize(mca_rcache_common_cuda_reg_t *rget_reg) */ result = cuFunc.cuEventRecord(event, 0); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", true, + OPAL_PROC_MY_HOSTNAME, result); } /* END of Workaround */ result = cuFunc.cuStreamWaitEvent(0, event, 0); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamWaitEvent failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamWaitEvent failed", true, result); } /* All done with this event. */ result = cuFunc.cuEventDestroy(event); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventDestroy failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventDestroy failed", true, result); } #endif /* OPAL_CUDA_SYNC_MEMOPS */ } @@ -1279,8 +1237,8 @@ int mca_common_cuda_memcpy(void *dst, void *src, size_t amount, char *msg, * return an error. The error message will tell the user to try and * run again, but with a larger array for storing events. */ if (cuda_event_ipc_num_used == cuda_event_max) { - opal_show_help("help-mpi-common-cuda.txt", "Out of cuEvent handles", - true, cuda_event_max, cuda_event_max+100, cuda_event_max+100); + opal_show_help("help-mpi-common-cuda.txt", "Out of cuEvent handles", true, cuda_event_max, + cuda_event_max + 100, cuda_event_max + 100); OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1289,29 +1247,29 @@ int mca_common_cuda_memcpy(void *dst, void *src, size_t amount, char *msg, cuda_event_ipc_most = cuda_event_ipc_num_used; /* Just print multiples of 10 */ if (0 == (cuda_event_ipc_most % 10)) { - opal_output_verbose(20, mca_common_cuda_output, - "Maximum ipc events used is now %d", cuda_event_ipc_most); + opal_output_verbose(20, mca_common_cuda_output, "Maximum ipc events used is now %d", + cuda_event_ipc_most); } } /* This is the standard way to run. Running with synchronous copies is available * to measure the advantages of asynchronous copies. */ if (OPAL_LIKELY(mca_common_cuda_async)) { - result = cuFunc.cuMemcpyAsync((CUdeviceptr)dst, (CUdeviceptr)src, amount, ipcStream); + result = cuFunc.cuMemcpyAsync((CUdeviceptr) dst, (CUdeviceptr) src, amount, ipcStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", - true, dst, src, amount, result); + opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", true, dst, src, + amount, result); OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } else { opal_output_verbose(20, mca_common_cuda_output, - "CUDA: cuMemcpyAsync passed: dst=%p, src=%p, size=%d", - dst, src, (int)amount); + "CUDA: cuMemcpyAsync passed: dst=%p, src=%p, size=%d", dst, src, + (int) amount); } result = cuFunc.cuEventRecord(cuda_event_ipc_array[cuda_event_ipc_first_avail], ipcStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", true, + OPAL_PROC_MY_HOSTNAME, result); OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } @@ -1327,23 +1285,23 @@ int mca_common_cuda_memcpy(void *dst, void *src, size_t amount, char *msg, *done = 0; } else { /* Mimic the async function so they use the same memcpy call. */ - result = cuFunc.cuMemcpyAsync((CUdeviceptr)dst, (CUdeviceptr)src, amount, ipcStream); + result = cuFunc.cuMemcpyAsync((CUdeviceptr) dst, (CUdeviceptr) src, amount, ipcStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", - true, dst, src, amount, result); + opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", true, dst, src, + amount, result); OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } else { opal_output_verbose(20, mca_common_cuda_output, - "CUDA: cuMemcpyAsync passed: dst=%p, src=%p, size=%d", - dst, src, (int)amount); + "CUDA: cuMemcpyAsync passed: dst=%p, src=%p, size=%d", dst, src, + (int) amount); } /* Record an event, then wait for it to complete with calls to cuEventQuery */ result = cuFunc.cuEventRecord(cuda_event_ipc_array[cuda_event_ipc_first_avail], ipcStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", true, + OPAL_PROC_MY_HOSTNAME, result); OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } @@ -1359,8 +1317,7 @@ int mca_common_cuda_memcpy(void *dst, void *src, size_t amount, char *msg, result = cuFunc.cuEventQuery(cuda_event_ipc_array[cuda_event_ipc_first_used]); if ((CUDA_SUCCESS != result) && (CUDA_ERROR_NOT_READY != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", true, result); OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } @@ -1372,9 +1329,8 @@ int mca_common_cuda_memcpy(void *dst, void *src, size_t amount, char *msg, } result = cuFunc.cuEventQuery(cuda_event_ipc_array[cuda_event_ipc_first_used]); if ((CUDA_SUCCESS != result) && (CUDA_ERROR_NOT_READY != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", - true, result); - OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); + opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", true, result); + OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } iter++; @@ -1404,8 +1360,8 @@ int mca_common_cuda_record_dtoh_event(char *msg, struct mca_btl_base_descriptor_ * run again, but with a larger array for storing events. */ OPAL_THREAD_LOCK(&common_cuda_dtoh_lock); if (cuda_event_dtoh_num_used == cuda_event_max) { - opal_show_help("help-mpi-common-cuda.txt", "Out of cuEvent handles", - true, cuda_event_max, cuda_event_max+100, cuda_event_max+100); + opal_show_help("help-mpi-common-cuda.txt", "Out of cuEvent handles", true, cuda_event_max, + cuda_event_max + 100, cuda_event_max + 100); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1413,15 +1369,15 @@ int mca_common_cuda_record_dtoh_event(char *msg, struct mca_btl_base_descriptor_ cuda_event_dtoh_most = cuda_event_dtoh_num_used; /* Just print multiples of 10 */ if (0 == (cuda_event_dtoh_most % 10)) { - opal_output_verbose(20, mca_common_cuda_output, - "Maximum DtoH events used is now %d", cuda_event_dtoh_most); + opal_output_verbose(20, mca_common_cuda_output, "Maximum DtoH events used is now %d", + cuda_event_dtoh_most); } } result = cuFunc.cuEventRecord(cuda_event_dtoh_array[cuda_event_dtoh_first_avail], dtohStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", true, + OPAL_PROC_MY_HOSTNAME, result); OPAL_THREAD_UNLOCK(&common_cuda_dtoh_lock); return OPAL_ERROR; } @@ -1451,8 +1407,8 @@ int mca_common_cuda_record_htod_event(char *msg, struct mca_btl_base_descriptor_ * return an error. The error message will tell the user to try and * run again, but with a larger array for storing events. */ if (cuda_event_htod_num_used == cuda_event_max) { - opal_show_help("help-mpi-common-cuda.txt", "Out of cuEvent handles", - true, cuda_event_max, cuda_event_max+100, cuda_event_max+100); + opal_show_help("help-mpi-common-cuda.txt", "Out of cuEvent handles", true, cuda_event_max, + cuda_event_max + 100, cuda_event_max + 100); OPAL_THREAD_UNLOCK(&common_cuda_htod_lock); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -1461,21 +1417,21 @@ int mca_common_cuda_record_htod_event(char *msg, struct mca_btl_base_descriptor_ cuda_event_htod_most = cuda_event_htod_num_used; /* Just print multiples of 10 */ if (0 == (cuda_event_htod_most % 10)) { - opal_output_verbose(20, mca_common_cuda_output, - "Maximum HtoD events used is now %d", cuda_event_htod_most); + opal_output_verbose(20, mca_common_cuda_output, "Maximum HtoD events used is now %d", + cuda_event_htod_most); } } result = cuFunc.cuEventRecord(cuda_event_htod_array[cuda_event_htod_first_avail], htodStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventRecord failed", true, + OPAL_PROC_MY_HOSTNAME, result); OPAL_THREAD_UNLOCK(&common_cuda_htod_lock); return OPAL_ERROR; } cuda_event_htod_frag_array[cuda_event_htod_first_avail] = frag; - /* Bump up the first available slot and number used by 1 */ + /* Bump up the first available slot and number used by 1 */ cuda_event_htod_first_avail++; if (cuda_event_htod_first_avail >= cuda_event_max) { cuda_event_htod_first_avail = 0; @@ -1489,15 +1445,17 @@ int mca_common_cuda_record_htod_event(char *msg, struct mca_btl_base_descriptor_ /** * Used to get the dtoh stream for initiating asynchronous copies. */ -void *mca_common_cuda_get_dtoh_stream(void) { - return (void *)dtohStream; +void *mca_common_cuda_get_dtoh_stream(void) +{ + return (void *) dtohStream; } /** * Used to get the htod stream for initiating asynchronous copies. */ -void *mca_common_cuda_get_htod_stream(void) { - return (void *)htodStream; +void *mca_common_cuda_get_htod_stream(void) +{ + return (void *) htodStream; } /* @@ -1505,16 +1463,17 @@ void *mca_common_cuda_get_htod_stream(void) { * are outstanding events, check to see if one has completed. If so, hand * back the fragment for further processing. */ -int progress_one_cuda_ipc_event(struct mca_btl_base_descriptor_t **frag) { +int progress_one_cuda_ipc_event(struct mca_btl_base_descriptor_t **frag) +{ CUresult result; - if( OPAL_LIKELY(0 == cuda_event_ipc_num_used) ) + if (OPAL_LIKELY(0 == cuda_event_ipc_num_used)) return 0; OPAL_THREAD_LOCK(&common_cuda_ipc_lock); if (cuda_event_ipc_num_used > 0) { opal_output_verbose(20, mca_common_cuda_output, - "CUDA: progress_one_cuda_ipc_event, outstanding_events=%d", + "CUDA: progress_one_cuda_ipc_event, outstanding_events=%d", cuda_event_ipc_num_used); result = cuFunc.cuEventQuery(cuda_event_ipc_array[cuda_event_ipc_first_used]); @@ -1527,16 +1486,14 @@ int progress_one_cuda_ipc_event(struct mca_btl_base_descriptor_t **frag) { OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return 0; } else if (CUDA_SUCCESS != result) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", true, result); *frag = NULL; OPAL_THREAD_UNLOCK(&common_cuda_ipc_lock); return OPAL_ERROR; } *frag = cuda_event_ipc_frag_array[cuda_event_ipc_first_used]; - opal_output_verbose(10, mca_common_cuda_output, - "CUDA: cuEventQuery returned %d", result); + opal_output_verbose(10, mca_common_cuda_output, "CUDA: cuEventQuery returned %d", result); /* Bump counters, loop around the circular buffer if necessary */ --cuda_event_ipc_num_used; @@ -1555,13 +1512,14 @@ int progress_one_cuda_ipc_event(struct mca_btl_base_descriptor_t **frag) { /** * Progress any dtoh event completions. */ -int progress_one_cuda_dtoh_event(struct mca_btl_base_descriptor_t **frag) { +int progress_one_cuda_dtoh_event(struct mca_btl_base_descriptor_t **frag) +{ CUresult result; OPAL_THREAD_LOCK(&common_cuda_dtoh_lock); if (cuda_event_dtoh_num_used > 0) { opal_output_verbose(30, mca_common_cuda_output, - "CUDA: progress_one_cuda_dtoh_event, outstanding_events=%d", + "CUDA: progress_one_cuda_dtoh_event, outstanding_events=%d", cuda_event_dtoh_num_used); result = cuFunc.cuEventQuery(cuda_event_dtoh_array[cuda_event_dtoh_first_used]); @@ -1574,16 +1532,14 @@ int progress_one_cuda_dtoh_event(struct mca_btl_base_descriptor_t **frag) { OPAL_THREAD_UNLOCK(&common_cuda_dtoh_lock); return 0; } else if (CUDA_SUCCESS != result) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", true, result); *frag = NULL; OPAL_THREAD_UNLOCK(&common_cuda_dtoh_lock); return OPAL_ERROR; } *frag = cuda_event_dtoh_frag_array[cuda_event_dtoh_first_used]; - opal_output_verbose(30, mca_common_cuda_output, - "CUDA: cuEventQuery returned %d", result); + opal_output_verbose(30, mca_common_cuda_output, "CUDA: cuEventQuery returned %d", result); /* Bump counters, loop around the circular buffer if necessary */ --cuda_event_dtoh_num_used; @@ -1602,13 +1558,14 @@ int progress_one_cuda_dtoh_event(struct mca_btl_base_descriptor_t **frag) { /** * Progress any dtoh event completions. */ -int progress_one_cuda_htod_event(struct mca_btl_base_descriptor_t **frag) { +int progress_one_cuda_htod_event(struct mca_btl_base_descriptor_t **frag) +{ CUresult result; OPAL_THREAD_LOCK(&common_cuda_htod_lock); if (cuda_event_htod_num_used > 0) { opal_output_verbose(30, mca_common_cuda_output, - "CUDA: progress_one_cuda_htod_event, outstanding_events=%d", + "CUDA: progress_one_cuda_htod_event, outstanding_events=%d", cuda_event_htod_num_used); result = cuFunc.cuEventQuery(cuda_event_htod_array[cuda_event_htod_first_used]); @@ -1621,16 +1578,14 @@ int progress_one_cuda_htod_event(struct mca_btl_base_descriptor_t **frag) { OPAL_THREAD_UNLOCK(&common_cuda_htod_lock); return 0; } else if (CUDA_SUCCESS != result) { - opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", - true, result); + opal_show_help("help-mpi-common-cuda.txt", "cuEventQuery failed", true, result); *frag = NULL; OPAL_THREAD_UNLOCK(&common_cuda_htod_lock); return OPAL_ERROR; } *frag = cuda_event_htod_frag_array[cuda_event_htod_first_used]; - opal_output_verbose(30, mca_common_cuda_output, - "CUDA: cuEventQuery returned %d", result); + opal_output_verbose(30, mca_common_cuda_output, "CUDA: cuEventQuery returned %d", result); /* Bump counters, loop around the circular buffer if necessary */ --cuda_event_htod_num_used; @@ -1646,7 +1601,6 @@ int progress_one_cuda_htod_event(struct mca_btl_base_descriptor_t **frag) { return OPAL_ERR_RESOURCE_BUSY; } - /** * Need to make sure the handle we are retrieving from the cache is still * valid. Compare the cached handle to the one received. @@ -1655,31 +1609,32 @@ int mca_common_cuda_memhandle_matches(mca_rcache_common_cuda_reg_t *new_reg, mca_rcache_common_cuda_reg_t *old_reg) { - if (0 == memcmp(new_reg->data.memHandle, old_reg->data.memHandle, sizeof(new_reg->data.memHandle))) { + if (0 + == memcmp(new_reg->data.memHandle, old_reg->data.memHandle, + sizeof(new_reg->data.memHandle))) { return 1; } else { return 0; } - } /* * Function to dump memory handle information. This is based on * definitions from cuiinterprocess_private.h. */ -static void cuda_dump_memhandle(int verbose, void *memHandle, char *str) { +static void cuda_dump_memhandle(int verbose, void *memHandle, char *str) +{ - struct InterprocessMemHandleInternal - { + struct InterprocessMemHandleInternal { /* The first two entries are the CUinterprocessCtxHandle */ int64_t ctxId; /* unique (within a process) id of the sharing context */ - int pid; /* pid of sharing context */ + int pid; /* pid of sharing context */ int64_t size; int64_t blocksize; int64_t offset; - int gpuId; - int subDeviceIndex; + int gpuId; + int subDeviceIndex; int64_t serial; } memH; @@ -1688,8 +1643,8 @@ static void cuda_dump_memhandle(int verbose, void *memHandle, char *str) { } memcpy(&memH, memHandle, sizeof(memH)); opal_output_verbose(verbose, mca_common_cuda_output, - "%s:ctxId=0x%" PRIx64 ", pid=%d, size=%" PRIu64 ", blocksize=%" PRIu64 ", offset=%" - PRIu64 ", gpuId=%d, subDeviceIndex=%d, serial=%" PRIu64, + "%s:ctxId=0x%" PRIx64 ", pid=%d, size=%" PRIu64 ", blocksize=%" PRIu64 + ", offset=%" PRIu64 ", gpuId=%d, subDeviceIndex=%d, serial=%" PRIu64, str, memH.ctxId, memH.pid, memH.size, memH.blocksize, memH.offset, memH.gpuId, memH.subDeviceIndex, memH.serial); } @@ -1698,10 +1653,10 @@ static void cuda_dump_memhandle(int verbose, void *memHandle, char *str) { * Function to dump memory handle information. This is based on * definitions from cuiinterprocess_private.h. */ -static void cuda_dump_evthandle(int verbose, void *evtHandle, char *str) { +static void cuda_dump_evthandle(int verbose, void *evtHandle, char *str) +{ - struct InterprocessEventHandleInternal - { + struct InterprocessEventHandleInternal { unsigned long pid; unsigned long serial; int index; @@ -1711,12 +1666,10 @@ static void cuda_dump_evthandle(int verbose, void *evtHandle, char *str) { str = "CUDA"; } memcpy(&evtH, evtHandle, sizeof(evtH)); - opal_output_verbose(verbose, mca_common_cuda_output, - "CUDA: %s:pid=%lu, serial=%lu, index=%d", + opal_output_verbose(verbose, mca_common_cuda_output, "CUDA: %s:pid=%lu, serial=%lu, index=%d", str, evtH.pid, evtH.serial, evtH.index); } - /* Return microseconds of elapsed time. Microseconds are relevant when * trying to understand the fixed overhead of the communication. Used * when trying to time various functions. @@ -1731,7 +1684,8 @@ static void cuda_dump_evthandle(int verbose, void *evtHandle, char *str) { * */ #if OPAL_ENABLE_DEBUG -static float mydifftime(opal_timer_t ts_start, opal_timer_t ts_end) { +static float mydifftime(opal_timer_t ts_start, opal_timer_t ts_end) +{ return (ts_end - ts_start); } #endif /* OPAL_ENABLE_DEBUG */ @@ -1741,7 +1695,7 @@ static int mca_common_cuda_is_gpu_buffer(const void *pUserBuf, opal_convertor_t { int res; CUmemorytype memType = 0; - CUdeviceptr dbuf = (CUdeviceptr)pUserBuf; + CUdeviceptr dbuf = (CUdeviceptr) pUserBuf; CUcontext ctx = NULL, memCtx = NULL; #if OPAL_CUDA_GET_ATTRIBUTES uint32_t isManaged = 0; @@ -1749,12 +1703,12 @@ static int mca_common_cuda_is_gpu_buffer(const void *pUserBuf, opal_convertor_t CUpointer_attribute attributes[3] = {CU_POINTER_ATTRIBUTE_MEMORY_TYPE, CU_POINTER_ATTRIBUTE_CONTEXT, CU_POINTER_ATTRIBUTE_IS_MANAGED}; - void *attrdata[] = {(void *)&memType, (void *)&memCtx, (void *)&isManaged}; + void *attrdata[] = {(void *) &memType, (void *) &memCtx, (void *) &isManaged}; res = cuFunc.cuPointerGetAttributes(3, attributes, attrdata, dbuf); OPAL_OUTPUT_VERBOSE((101, mca_common_cuda_output, - "dbuf=%p, memType=%d, memCtx=%p, isManaged=%d, res=%d", - (void *)dbuf, (int)memType, (void *)memCtx, isManaged, res)); + "dbuf=%p, memType=%d, memCtx=%p, isManaged=%d, res=%d", (void *) dbuf, + (int) memType, (void *) memCtx, isManaged, res)); /* Mark unified memory buffers with a flag. This will allow all unified * memory to be forced through host buffers. Note that this memory can @@ -1778,8 +1732,7 @@ static int mca_common_cuda_is_gpu_buffer(const void *pUserBuf, opal_convertor_t /* Must be a device pointer */ assert(memType == CU_MEMORYTYPE_DEVICE); #else /* OPAL_CUDA_GET_ATTRIBUTES */ - res = cuFunc.cuPointerGetAttribute(&memType, - CU_POINTER_ATTRIBUTE_MEMORY_TYPE, dbuf); + res = cuFunc.cuPointerGetAttribute(&memType, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, dbuf); if (res != CUDA_SUCCESS) { /* If we cannot determine it is device pointer, * just assume it is not. */ @@ -1804,27 +1757,32 @@ static int mca_common_cuda_is_gpu_buffer(const void *pUserBuf, opal_convertor_t if (OPAL_UNLIKELY(NULL == ctx)) { if (CUDA_SUCCESS == res) { #if !OPAL_CUDA_GET_ATTRIBUTES - res = cuFunc.cuPointerGetAttribute(&memCtx, - CU_POINTER_ATTRIBUTE_CONTEXT, dbuf); + res = cuFunc.cuPointerGetAttribute(&memCtx, CU_POINTER_ATTRIBUTE_CONTEXT, dbuf); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_output(0, "CUDA: error calling cuPointerGetAttribute: " - "res=%d, ptr=%p aborting...", res, pUserBuf); + opal_output(0, + "CUDA: error calling cuPointerGetAttribute: " + "res=%d, ptr=%p aborting...", + res, pUserBuf); return OPAL_ERROR; } #endif /* OPAL_CUDA_GET_ATTRIBUTES */ res = cuFunc.cuCtxSetCurrent(memCtx); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_output(0, "CUDA: error calling cuCtxSetCurrent: " - "res=%d, ptr=%p aborting...", res, pUserBuf); + opal_output(0, + "CUDA: error calling cuCtxSetCurrent: " + "res=%d, ptr=%p aborting...", + res, pUserBuf); return OPAL_ERROR; } else { - OPAL_OUTPUT_VERBOSE((10, mca_common_cuda_output, - "CUDA: cuCtxSetCurrent passed: ptr=%p", pUserBuf)); + OPAL_OUTPUT_VERBOSE( + (10, mca_common_cuda_output, "CUDA: cuCtxSetCurrent passed: ptr=%p", pUserBuf)); } } else { /* Print error and proceed */ - opal_output(0, "CUDA: error calling cuCtxGetCurrent: " - "res=%d, ptr=%p aborting...", res, pUserBuf); + opal_output(0, + "CUDA: error calling cuCtxGetCurrent: " + "res=%d, ptr=%p aborting...", + res, pUserBuf); return OPAL_ERROR; } } @@ -1843,7 +1801,7 @@ static int mca_common_cuda_is_gpu_buffer(const void *pUserBuf, opal_convertor_t opal_output_verbose(5, mca_common_cuda_output, "CUDA: cuMemGetAddressRange failed on this pointer: res=%d, buf=%p " "Overriding check and setting to host pointer. ", - res, (void *)dbuf); + res, (void *) dbuf); /* This cannot be GPU memory if the previous call failed */ return 0; } @@ -1861,10 +1819,10 @@ static int mca_common_cuda_is_gpu_buffer(const void *pUserBuf, opal_convertor_t } static int mca_common_cuda_cu_memcpy_async(void *dest, const void *src, size_t size, - opal_convertor_t* convertor) + opal_convertor_t *convertor) { - return cuFunc.cuMemcpyAsync((CUdeviceptr)dest, (CUdeviceptr)src, size, - (CUstream)convertor->stream); + return cuFunc.cuMemcpyAsync((CUdeviceptr) dest, (CUdeviceptr) src, size, + (CUstream) convertor->stream); } /** @@ -1879,44 +1837,45 @@ static int mca_common_cuda_cu_memcpy(void *dest, const void *src, size_t size) if (OPAL_UNLIKELY(mca_common_cuda_cumemcpy_timing)) { /* Nice to know type of source and destination for timing output. Do * not care about return code as memory type will just be set to 0 */ - result = cuFunc.cuPointerGetAttribute(&memTypeDst, - CU_POINTER_ATTRIBUTE_MEMORY_TYPE, (CUdeviceptr)dest); - result = cuFunc.cuPointerGetAttribute(&memTypeSrc, - CU_POINTER_ATTRIBUTE_MEMORY_TYPE, (CUdeviceptr)src); + result = cuFunc.cuPointerGetAttribute(&memTypeDst, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, + (CUdeviceptr) dest); + result = cuFunc.cuPointerGetAttribute(&memTypeSrc, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, + (CUdeviceptr) src); ts_start = opal_timer_base_get_usec(); } #endif if (mca_common_cuda_cumemcpy_async) { - result = cuFunc.cuMemcpyAsync((CUdeviceptr)dest, (CUdeviceptr)src, size, memcpyStream); + result = cuFunc.cuMemcpyAsync((CUdeviceptr) dest, (CUdeviceptr) src, size, memcpyStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", - true, dest, src, size, result); + opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", true, dest, src, + size, result); return OPAL_ERROR; } result = cuFunc.cuStreamSynchronize(memcpyStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamSynchronize failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamSynchronize failed", true, + OPAL_PROC_MY_HOSTNAME, result); return OPAL_ERROR; } } else { - result = cuFunc.cuMemcpy((CUdeviceptr)dest, (CUdeviceptr)src, size); - if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemcpy failed", - true, OPAL_PROC_MY_HOSTNAME, result); - return OPAL_ERROR; - } + result = cuFunc.cuMemcpy((CUdeviceptr) dest, (CUdeviceptr) src, size); + if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { + opal_show_help("help-mpi-common-cuda.txt", "cuMemcpy failed", true, + OPAL_PROC_MY_HOSTNAME, result); + return OPAL_ERROR; + } } #if OPAL_ENABLE_DEBUG if (OPAL_UNLIKELY(mca_common_cuda_cumemcpy_timing)) { ts_end = opal_timer_base_get_usec(); accum = mydifftime(ts_start, ts_end); if (mca_common_cuda_cumemcpy_async) { - opal_output(0, "cuMemcpyAsync took %7.2f usecs, size=%d, (src=%p (%d), dst=%p (%d))\n", - accum, (int)size, src, memTypeSrc, dest, memTypeDst); + opal_output(0, + "cuMemcpyAsync took %7.2f usecs, size=%d, (src=%p (%d), dst=%p (%d))\n", + accum, (int) size, src, memTypeSrc, dest, memTypeDst); } else { opal_output(0, "cuMemcpy took %7.2f usecs, size=%d, (src=%p (%d), dst=%p (%d))\n", - accum, (int)size, src, memTypeSrc, dest, memTypeDst); + accum, (int) size, src, memTypeSrc, dest, memTypeDst); } } #endif @@ -1927,10 +1886,9 @@ int mca_common_cuda_malloc(void **dptr, size_t size) { int res, count = 0; if (size > 0) { - res = cuFunc.cuMemAlloc((CUdeviceptr *)dptr, size); + res = cuFunc.cuMemAlloc((CUdeviceptr *) dptr, size); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_output(0, "CUDA: cuMemAlloc failed: res=%d", - res); + opal_output(0, "CUDA: cuMemAlloc failed: res=%d", res); return res; } } @@ -1941,53 +1899,51 @@ int mca_common_cuda_free(void *dptr) { int res; if (NULL != dptr) { - res = cuFunc.cuMemFree((CUdeviceptr)dptr); + res = cuFunc.cuMemFree((CUdeviceptr) dptr); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_output(0, "CUDA: cuMemFree failed: res=%d", - res); + opal_output(0, "CUDA: cuMemFree failed: res=%d", res); return res; } } return 0; } - static int mca_common_cuda_memmove(void *dest, void *src, size_t size) { CUdeviceptr tmp; int result; - result = cuFunc.cuMemAlloc(&tmp,size); + result = cuFunc.cuMemAlloc(&tmp, size); if (mca_common_cuda_cumemcpy_async) { - result = cuFunc.cuMemcpyAsync(tmp, (CUdeviceptr)src, size, memcpyStream); + result = cuFunc.cuMemcpyAsync(tmp, (CUdeviceptr) src, size, memcpyStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", - true, tmp, src, size, result); + opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", true, tmp, src, size, + result); return OPAL_ERROR; } - result = cuFunc.cuMemcpyAsync((CUdeviceptr)dest, tmp, size, memcpyStream); + result = cuFunc.cuMemcpyAsync((CUdeviceptr) dest, tmp, size, memcpyStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", - true, dest, tmp, size, result); + opal_show_help("help-mpi-common-cuda.txt", "cuMemcpyAsync failed", true, dest, tmp, + size, result); return OPAL_ERROR; } result = cuFunc.cuStreamSynchronize(memcpyStream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuStreamSynchronize failed", - true, OPAL_PROC_MY_HOSTNAME, result); + opal_show_help("help-mpi-common-cuda.txt", "cuStreamSynchronize failed", true, + OPAL_PROC_MY_HOSTNAME, result); return OPAL_ERROR; } } else { - result = cuFunc.cuMemcpy(tmp, (CUdeviceptr)src, size); + result = cuFunc.cuMemcpy(tmp, (CUdeviceptr) src, size); if (OPAL_UNLIKELY(result != CUDA_SUCCESS)) { opal_output(0, "CUDA: memmove-Error in cuMemcpy: res=%d, dest=%p, src=%p, size=%d", - result, (void *)tmp, src, (int)size); + result, (void *) tmp, src, (int) size); return OPAL_ERROR; } - result = cuFunc.cuMemcpy((CUdeviceptr)dest, tmp, size); + result = cuFunc.cuMemcpy((CUdeviceptr) dest, tmp, size); if (OPAL_UNLIKELY(result != CUDA_SUCCESS)) { opal_output(0, "CUDA: memmove-Error in cuMemcpy: res=%d, dest=%p, src=%p, size=%d", - result, dest, (void *)tmp, (int)size); + result, dest, (void *) tmp, (int) size); return OPAL_ERROR; } } @@ -2002,8 +1958,7 @@ int mca_common_cuda_get_device(int *devicenum) res = cuFunc.cuCtxGetDevice(&cuDev); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_output(0, "CUDA: cuCtxGetDevice failed: res=%d", - res); + opal_output(0, "CUDA: cuCtxGetDevice failed: res=%d", res); return res; } *devicenum = cuDev; @@ -2013,10 +1968,9 @@ int mca_common_cuda_get_device(int *devicenum) int mca_common_cuda_device_can_access_peer(int *access, int dev1, int dev2) { int res; - res = cuFunc.cuDeviceCanAccessPeer(access, (CUdevice)dev1, (CUdevice)dev2); + res = cuFunc.cuDeviceCanAccessPeer(access, (CUdevice) dev1, (CUdevice) dev2); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_output(0, "CUDA: cuDeviceCanAccessPeer failed: res=%d", - res); + opal_output(0, "CUDA: cuDeviceCanAccessPeer failed: res=%d", res); return res; } return 0; @@ -2025,15 +1979,15 @@ int mca_common_cuda_device_can_access_peer(int *access, int dev1, int dev2) int mca_common_cuda_get_address_range(void *pbase, size_t *psize, void *base) { CUresult result; - result = cuFunc.cuMemGetAddressRange((CUdeviceptr *)pbase, psize, (CUdeviceptr)base); + result = cuFunc.cuMemGetAddressRange((CUdeviceptr *) pbase, psize, (CUdeviceptr) base); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { - opal_show_help("help-mpi-common-cuda.txt", "cuMemGetAddressRange failed 2", - true, OPAL_PROC_MY_HOSTNAME, result, base); + opal_show_help("help-mpi-common-cuda.txt", "cuMemGetAddressRange failed 2", true, + OPAL_PROC_MY_HOSTNAME, result, base); return OPAL_ERROR; } else { opal_output_verbose(50, mca_common_cuda_output, "CUDA: cuMemGetAddressRange passed: addr=%p, pbase=%p, psize=%lu ", - base, *(char **)pbase, *psize); + base, *(char **) pbase, *psize); } return 0; } @@ -2051,18 +2005,18 @@ bool mca_common_cuda_previously_freed_memory(mca_rcache_base_registration_t *reg unsigned long long bufID; unsigned char *dbuf = reg->base; - res = cuFunc.cuPointerGetAttribute(&bufID, CU_POINTER_ATTRIBUTE_BUFFER_ID, - (CUdeviceptr)dbuf); + res = cuFunc.cuPointerGetAttribute(&bufID, CU_POINTER_ATTRIBUTE_BUFFER_ID, (CUdeviceptr) dbuf); /* If we cannot determine the BUFFER_ID, then print a message and default * to forcing the registration to be kicked out. */ if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_show_help("help-mpi-common-cuda.txt", "bufferID failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "bufferID failed", true, OPAL_PROC_MY_HOSTNAME, + res); return true; } opal_output_verbose(50, mca_common_cuda_output, - "CUDA: base=%p, bufID=%llu, reg->gpu_bufID=%llu, %s", dbuf, bufID, reg->gpu_bufID, - (reg->gpu_bufID == bufID ? "BUFFER_ID match":"BUFFER_ID do not match")); + "CUDA: base=%p, bufID=%llu, reg->gpu_bufID=%llu, %s", dbuf, bufID, + reg->gpu_bufID, + (reg->gpu_bufID == bufID ? "BUFFER_ID match" : "BUFFER_ID do not match")); if (bufID != reg->gpu_bufID) { return true; } else { @@ -2084,19 +2038,18 @@ void mca_common_cuda_get_buffer_id(mca_rcache_base_registration_t *reg) unsigned char *dbuf = reg->base; int enable = 1; - res = cuFunc.cuPointerGetAttribute(&bufID, CU_POINTER_ATTRIBUTE_BUFFER_ID, - (CUdeviceptr)dbuf); + res = cuFunc.cuPointerGetAttribute(&bufID, CU_POINTER_ATTRIBUTE_BUFFER_ID, (CUdeviceptr) dbuf); if (OPAL_UNLIKELY(res != CUDA_SUCCESS)) { - opal_show_help("help-mpi-common-cuda.txt", "bufferID failed", - true, OPAL_PROC_MY_HOSTNAME, res); + opal_show_help("help-mpi-common-cuda.txt", "bufferID failed", true, OPAL_PROC_MY_HOSTNAME, + res); } reg->gpu_bufID = bufID; res = cuFunc.cuPointerSetAttribute(&enable, CU_POINTER_ATTRIBUTE_SYNC_MEMOPS, - (CUdeviceptr)dbuf); + (CUdeviceptr) dbuf); if (OPAL_UNLIKELY(CUDA_SUCCESS != res)) { - opal_show_help("help-mpi-common-cuda.txt", "cuPointerSetAttribute failed", - true, OPAL_PROC_MY_HOSTNAME, res, dbuf); + opal_show_help("help-mpi-common-cuda.txt", "cuPointerSetAttribute failed", true, + OPAL_PROC_MY_HOSTNAME, res, dbuf); } } @@ -2113,7 +2066,8 @@ static opal_common_cuda_function_table_t ftable; * is made to send or receive a GPU pointer. This allows us to delay * some CUDA initialization until after MPI_Init(). */ -void opal_cuda_add_initialization_function(int (*fptr)(opal_common_cuda_function_table_t *)) { +void opal_cuda_add_initialization_function(int (*fptr)(opal_common_cuda_function_table_t *)) +{ common_cuda_initialization_function = fptr; } @@ -2123,7 +2077,7 @@ void opal_cuda_add_initialization_function(int (*fptr)(opal_common_cuda_function * is enabled or not. If CUDA is not enabled, then short circuit out * for all future calls. */ -void mca_cuda_convertor_init(opal_convertor_t* convertor, const void *pUserBuf) +void mca_cuda_convertor_init(opal_convertor_t *convertor, const void *pUserBuf) { /* Only do the initialization on the first GPU access */ if (!initialized) { @@ -2132,7 +2086,7 @@ void mca_cuda_convertor_init(opal_convertor_t* convertor, const void *pUserBuf) /* This is needed to handle case where convertor is not fully initialized * like when trying to do a sendi with convertor on the statck */ - convertor->cbmemcpy = (memcpy_fct_t)&opal_cuda_memcpy; + convertor->cbmemcpy = (memcpy_fct_t) &opal_cuda_memcpy; /* If not enabled, then nothing else to do */ if (!opal_cuda_enabled) { @@ -2179,7 +2133,7 @@ bool opal_cuda_check_bufs(char *dest, char *src) * @param buf check one pointer providing a convertor. * Provides aditional information, e.g. managed vs. unmanaged GPU buffer */ -bool opal_cuda_check_one_buf(char *buf, opal_convertor_t *convertor ) +bool opal_cuda_check_one_buf(char *buf, opal_convertor_t *convertor) { /* Only do the initialization on the first GPU access */ if (!initialized) { @@ -2190,7 +2144,7 @@ bool opal_cuda_check_one_buf(char *buf, opal_convertor_t *convertor ) return false; } - return ( ftable.gpu_is_gpu_buffer(buf, convertor)); + return (ftable.gpu_is_gpu_buffer(buf, convertor)); } /* @@ -2204,17 +2158,16 @@ bool opal_cuda_check_one_buf(char *buf, opal_convertor_t *convertor ) * * @returns void * A pointer to the newly allocated buffer. */ -void *opal_cuda_malloc(size_t size, opal_convertor_t* convertor) +void *opal_cuda_malloc(size_t size, opal_convertor_t *convertor) { int res; - void* buffer; + void *buffer; if (!(convertor->flags & CONVERTOR_CUDA)) { return malloc(size); } res = ftable.gpu_malloc(buffer, size); - if (res != 0 ) { - opal_output(0, "CUDA: Error in cuMemAlloc: size=%d", - (int)size); + if (res != 0) { + opal_output(0, "CUDA: Error in cuMemAlloc: size=%d", (int) size); abort(); } else { return buffer; @@ -2230,7 +2183,7 @@ void *opal_cuda_malloc(size_t size, opal_convertor_t* convertor) * should be a Host or Cuda buffer. * */ -void opal_cuda_free(void *buffer, opal_convertor_t* convertor) +void opal_cuda_free(void *buffer, opal_convertor_t *convertor) { int res; if (!(convertor->flags & CONVERTOR_CUDA)) { @@ -2238,9 +2191,8 @@ void opal_cuda_free(void *buffer, opal_convertor_t* convertor) return; } res = ftable.gpu_free(buffer); - if (res != 0 ) { - opal_output(0, "CUDA: Error in cuMemFree: ptr=%p", - buffer); + if (res != 0) { + opal_output(0, "CUDA: Error in cuMemFree: ptr=%p", buffer); abort(); } return; @@ -2253,7 +2205,7 @@ void opal_cuda_free(void *buffer, opal_convertor_t* convertor) * aborts as there is no recovering. */ -void *opal_cuda_memcpy(void *dest, const void *src, size_t size, opal_convertor_t* convertor) +void *opal_cuda_memcpy(void *dest, const void *src, size_t size, opal_convertor_t *convertor) { int res; @@ -2262,14 +2214,14 @@ void *opal_cuda_memcpy(void *dest, const void *src, size_t size, opal_convertor_ } if (convertor->flags & CONVERTOR_CUDA_ASYNC) { - res = ftable.gpu_cu_memcpy_async(dest, (void *)src, size, convertor); + res = ftable.gpu_cu_memcpy_async(dest, (void *) src, size, convertor); } else { - res = ftable.gpu_cu_memcpy(dest, (void *)src, size); + res = ftable.gpu_cu_memcpy(dest, (void *) src, size); } if (res != 0) { - opal_output(0, "CUDA: Error in cuMemcpy: res=%d, dest=%p, src=%p, size=%d", - res, dest, src, (int)size); + opal_output(0, "CUDA: Error in cuMemcpy: res=%d, dest=%p, src=%p, size=%d", res, dest, src, + (int) size); abort(); } else { return dest; @@ -2286,8 +2238,8 @@ void *opal_cuda_memcpy_sync(void *dest, const void *src, size_t size) int res; res = ftable.gpu_cu_memcpy(dest, src, size); if (res != 0) { - opal_output(0, "CUDA: Error in cuMemcpy: res=%d, dest=%p, src=%p, size=%d", - res, dest, src, (int)size); + opal_output(0, "CUDA: Error in cuMemcpy: res=%d, dest=%p, src=%p, size=%d", res, dest, src, + (int) size); abort(); } else { return dest; @@ -2303,9 +2255,9 @@ void *opal_cuda_memmove(void *dest, void *src, size_t size) int res; res = ftable.gpu_memmove(dest, src, size); - if(res != 0){ - opal_output(0, "CUDA: Error in gpu memmove: res=%d, dest=%p, src=%p, size=%d", - res, dest, src, (int)size); + if (res != 0) { + opal_output(0, "CUDA: Error in gpu memmove: res=%d, dest=%p, src=%p, size=%d", res, dest, + src, (int) size); abort(); } return dest; @@ -2348,7 +2300,7 @@ static void opal_cuda_support_init(void) * Tell the convertor that copies will be asynchronous CUDA copies. The * flags are cleared when the convertor is reinitialized. */ -void opal_cuda_set_copy_function_async(opal_convertor_t* convertor, void *stream) +void opal_cuda_set_copy_function_async(opal_convertor_t *convertor, void *stream) { convertor->flags |= CONVERTOR_CUDA_ASYNC; convertor->stream = stream; diff --git a/opal/mca/common/cuda/common_cuda.h b/opal/mca/common/cuda/common_cuda.h index 695201bc134..0889551640d 100644 --- a/opal/mca/common/cuda/common_cuda.h +++ b/opal/mca/common/cuda/common_cuda.h @@ -22,8 +22,8 @@ #ifndef OPAL_MCA_COMMON_CUDA_H #define OPAL_MCA_COMMON_CUDA_H -#include "opal/mca/btl/btl.h" #include "opal/datatype/opal_convertor.h" +#include "opal/mca/btl/btl.h" #define MEMHANDLE_SIZE 8 #define EVTHANDLE_SIZE 8 @@ -59,7 +59,7 @@ OPAL_DECLSPEC int mca_common_cuda_memcpy(void *dst, void *src, size_t amount, ch struct mca_btl_base_descriptor_t *, int *done); OPAL_DECLSPEC int mca_common_cuda_record_ipc_event(char *msg, - struct mca_btl_base_descriptor_t *frag); + struct mca_btl_base_descriptor_t *frag); OPAL_DECLSPEC int mca_common_cuda_record_dtoh_event(char *msg, struct mca_btl_base_descriptor_t *frag); OPAL_DECLSPEC int mca_common_cuda_record_htod_event(char *msg, @@ -81,7 +81,8 @@ OPAL_DECLSPEC void mca_common_cuda_destruct_event(uintptr_t event); OPAL_DECLSPEC int cuda_getmemhandle(void *base, size_t, mca_rcache_base_registration_t *newreg, mca_rcache_base_registration_t *hdrreg); OPAL_DECLSPEC int cuda_ungetmemhandle(void *reg_data, mca_rcache_base_registration_t *reg); -OPAL_DECLSPEC int cuda_openmemhandle(void *base, size_t size, mca_rcache_base_registration_t *newreg, +OPAL_DECLSPEC int cuda_openmemhandle(void *base, size_t size, + mca_rcache_base_registration_t *newreg, mca_rcache_base_registration_t *hdrreg); OPAL_DECLSPEC int cuda_closememhandle(void *reg_data, mca_rcache_base_registration_t *reg); OPAL_DECLSPEC int mca_common_cuda_get_device(int *devicenum); @@ -101,11 +102,11 @@ OPAL_DECLSPEC void mca_common_cuda_get_buffer_id(mca_rcache_base_registration_t * (source arch != dest arch) or non contiguous memory * layout. */ -static inline int32_t opal_convertor_cuda_need_buffers( opal_convertor_t* pConvertor ) +static inline int32_t opal_convertor_cuda_need_buffers(opal_convertor_t *pConvertor) { int32_t retval; uint32_t cudaflag = pConvertor->flags & CONVERTOR_CUDA; /* Save CUDA flag */ - pConvertor->flags &= ~CONVERTOR_CUDA; /* Clear CUDA flag if it exists */ + pConvertor->flags &= ~CONVERTOR_CUDA; /* Clear CUDA flag if it exists */ retval = opal_convertor_need_buffers(pConvertor); pConvertor->flags |= cudaflag; /* Restore CUDA flag */ return retval; @@ -115,24 +116,24 @@ static inline int32_t opal_convertor_cuda_need_buffers( opal_convertor_t* pConve * common cuda code is initialized. This removes any dependency on * in the opal cuda datatype code. */ struct opal_common_cuda_function_table { - int (*gpu_is_gpu_buffer)(const void*, opal_convertor_t*); - int (*gpu_cu_memcpy_async)(void*, const void*, size_t, opal_convertor_t*); - int (*gpu_cu_memcpy)(void*, const void*, size_t); - int (*gpu_memmove)(void*, void*, size_t); - int (*gpu_malloc)(void*, size_t); - int (*gpu_free)(void*); + int (*gpu_is_gpu_buffer)(const void *, opal_convertor_t *); + int (*gpu_cu_memcpy_async)(void *, const void *, size_t, opal_convertor_t *); + int (*gpu_cu_memcpy)(void *, const void *, size_t); + int (*gpu_memmove)(void *, void *, size_t); + int (*gpu_malloc)(void *, size_t); + int (*gpu_free)(void *); }; typedef struct opal_common_cuda_function_table opal_common_cuda_function_table_t; -void mca_cuda_convertor_init(opal_convertor_t* convertor, const void *pUserBuf); +void mca_cuda_convertor_init(opal_convertor_t *convertor, const void *pUserBuf); bool opal_cuda_check_bufs(char *dest, char *src); -bool opal_cuda_check_one_buf(char *buf, opal_convertor_t *convertor ); -void* opal_cuda_malloc(size_t size, opal_convertor_t* convertor); -void opal_cuda_free(void * buffer, opal_convertor_t* convertor); -void* opal_cuda_memcpy(void * dest, const void * src, size_t size, opal_convertor_t* convertor); -void* opal_cuda_memcpy_sync(void * dest, const void * src, size_t size); -void* opal_cuda_memmove(void * dest, void * src, size_t size); +bool opal_cuda_check_one_buf(char *buf, opal_convertor_t *convertor); +void *opal_cuda_malloc(size_t size, opal_convertor_t *convertor); +void opal_cuda_free(void *buffer, opal_convertor_t *convertor); +void *opal_cuda_memcpy(void *dest, const void *src, size_t size, opal_convertor_t *convertor); +void *opal_cuda_memcpy_sync(void *dest, const void *src, size_t size); +void *opal_cuda_memmove(void *dest, void *src, size_t size); void opal_cuda_add_initialization_function(int (*fptr)(opal_common_cuda_function_table_t *)); -void opal_cuda_set_copy_function_async(opal_convertor_t* convertor, void *stream); +void opal_cuda_set_copy_function_async(opal_convertor_t *convertor, void *stream); #endif /* OPAL_MCA_COMMON_CUDA_H */ diff --git a/opal/mca/common/ofi/common_ofi.c b/opal/mca/common/ofi/common_ofi.c index 3630aaec5ce..0c50a88a010 100644 --- a/opal/mca/common/ofi/common_ofi.c +++ b/opal/mca/common/ofi/common_ofi.c @@ -13,27 +13,23 @@ * $HEADER$ */ - #include #include #include "opal_config.h" #include "common_ofi.h" -#include "opal_config.h" #include "opal/constants.h" -#include "opal/util/argv.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/mca/hwloc/base/base.h" #include "opal/mca/pmix/base/base.h" +#include "opal/util/argv.h" #include "opal/util/show_help.h" -OPAL_DECLSPEC opal_common_ofi_module_t opal_common_ofi = { - .prov_include = NULL, - .prov_exclude = NULL, - .registered = 0, - .verbose = 0 -}; +OPAL_DECLSPEC opal_common_ofi_module_t opal_common_ofi = {.prov_include = NULL, + .prov_exclude = NULL, + .registered = 0, + .verbose = 0}; static const char default_prov_exclude_list[] = "shm,sockets,tcp,udp,rstream"; @@ -63,55 +59,52 @@ OPAL_DECLSPEC int opal_common_ofi_register_mca_variables(const mca_base_componen static int exclude_index; static int verbose_index; - if (fi_version() < FI_VERSION(1,0)) { + if (fi_version() < FI_VERSION(1, 0)) { return OPAL_ERROR; } if (!registered) { /* - * this monkey business is needed because of the way the MCA VARs stuff tries to handle pointers to strings when - * when destructing the MCA var database. If you don't do something like this,the MCA var framework will try - * to dereference a pointer which itself is no longer a valid address owing to having been previously dlclosed. + * this monkey business is needed because of the way the MCA VARs stuff tries to handle + * pointers to strings when when destructing the MCA var database. If you don't do + * something like this,the MCA var framework will try to dereference a pointer which itself + * is no longer a valid address owing to having been previously dlclosed. */ - opal_common_ofi.prov_include = (char **)malloc(sizeof(char *)); - *opal_common_ofi.prov_include = NULL; - include_index = mca_base_var_register("opal", "opal_common", "ofi", - "provider_include", - "Comma-delimited list of OFI providers that are considered for use (e.g., \"psm,psm2\"; an empty value means that all providers will be considered). Mutually exclusive with mtl_ofi_provider_exclude.", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_1, - MCA_BASE_VAR_SCOPE_READONLY, - opal_common_ofi.prov_include); - opal_common_ofi.prov_exclude = (char **)malloc(sizeof(char *)); + opal_common_ofi.prov_include = (char **) malloc(sizeof(char *)); + *opal_common_ofi.prov_include = NULL; + include_index = mca_base_var_register( + "opal", "opal_common", "ofi", "provider_include", + "Comma-delimited list of OFI providers that are considered for use (e.g., " + "\"psm,psm2\"; an empty value means that all providers will be considered). Mutually " + "exclusive with mtl_ofi_provider_exclude.", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_1, MCA_BASE_VAR_SCOPE_READONLY, + opal_common_ofi.prov_include); + opal_common_ofi.prov_exclude = (char **) malloc(sizeof(char *)); *opal_common_ofi.prov_exclude = strdup(default_prov_exclude_list); - exclude_index = mca_base_var_register("opal", "opal_common", "ofi", - "provider_exclude", - "Comma-delimited list of OFI providers that are not considered for use (default: \"sockets,mxm\"; empty value means that all providers will be considered). Mutually exclusive with mtl_ofi_provider_include.", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_1, - MCA_BASE_VAR_SCOPE_READONLY, - opal_common_ofi.prov_exclude); + exclude_index = mca_base_var_register( + "opal", "opal_common", "ofi", "provider_exclude", + "Comma-delimited list of OFI providers that are not considered for use (default: " + "\"sockets,mxm\"; empty value means that all providers will be considered). Mutually " + "exclusive with mtl_ofi_provider_include.", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_1, MCA_BASE_VAR_SCOPE_READONLY, + opal_common_ofi.prov_exclude); verbose_index = mca_base_var_register("opal", "opal_common", "ofi", "verbose", "Verbose level of the OFI components", MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - &opal_common_ofi.verbose); + MCA_BASE_VAR_SCOPE_LOCAL, &opal_common_ofi.verbose); registered = 1; } if (component) { mca_base_var_register_synonym(include_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "provider_include", 0); mca_base_var_register_synonym(exclude_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "provider_exclude", 0); mca_base_var_register_synonym(verbose_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "verbose", 0); } @@ -122,7 +115,7 @@ OPAL_DECLSPEC void opal_common_ofi_mca_register(void) { opal_common_ofi.registered++; if (opal_common_ofi.registered > 1) { - opal_output_set_verbosity(opal_common_ofi.output, opal_common_ofi.verbose); + opal_output_set_verbosity(opal_common_ofi.output, opal_common_ofi.verbose); return; } @@ -142,13 +135,11 @@ OPAL_DECLSPEC void opal_common_ofi_mca_deregister(void) } /* check that the tx attributes match */ -static int -check_tx_attr(struct fi_tx_attr *provider_info, - struct fi_tx_attr *provider) +static int check_tx_attr(struct fi_tx_attr *provider_info, struct fi_tx_attr *provider) { - if (!(provider->msg_order & ~(provider_info->msg_order)) && - !(provider->op_flags & ~(provider_info->op_flags)) && - (provider->inject_size == provider_info->inject_size)) { + if (!(provider->msg_order & ~(provider_info->msg_order)) + && !(provider->op_flags & ~(provider_info->op_flags)) + && (provider->inject_size == provider_info->inject_size)) { return 0; } else { return OPAL_ERROR; @@ -156,12 +147,10 @@ check_tx_attr(struct fi_tx_attr *provider_info, } /* check that the rx attributes match */ -static int -check_rx_attr(struct fi_rx_attr *provider_info, - struct fi_rx_attr *provider) +static int check_rx_attr(struct fi_rx_attr *provider_info, struct fi_rx_attr *provider) { - if (!(provider->msg_order & ~(provider_info->msg_order)) && - !(provider->op_flags & ~(provider_info->op_flags))) { + if (!(provider->msg_order & ~(provider_info->msg_order)) + && !(provider->op_flags & ~(provider_info->op_flags))) { return 0; } else { return OPAL_ERROR; @@ -169,15 +158,13 @@ check_rx_attr(struct fi_rx_attr *provider_info, } /* check that the ep attributes match */ -static int -check_ep_attr(struct fi_ep_attr *provider_info, - struct fi_ep_attr *provider) +static int check_ep_attr(struct fi_ep_attr *provider_info, struct fi_ep_attr *provider) { - if (!(provider->type & ~(provider_info->type)) && - !(provider->mem_tag_format & ~(provider_info->mem_tag_format)) && - (provider->max_msg_size == provider_info->max_msg_size) && - (provider->tx_ctx_cnt == provider_info->tx_ctx_cnt) && - (provider->rx_ctx_cnt == provider_info->rx_ctx_cnt)) { + if (!(provider->type & ~(provider_info->type)) + && !(provider->mem_tag_format & ~(provider_info->mem_tag_format)) + && (provider->max_msg_size == provider_info->max_msg_size) + && (provider->tx_ctx_cnt == provider_info->tx_ctx_cnt) + && (provider->rx_ctx_cnt == provider_info->rx_ctx_cnt)) { return 0; } else { return OPAL_ERROR; @@ -185,18 +172,15 @@ check_ep_attr(struct fi_ep_attr *provider_info, } /* check that the provider attributes match */ -static int -check_provider_attr(struct fi_info *provider_info, - struct fi_info *provider) +static int check_provider_attr(struct fi_info *provider_info, struct fi_info *provider) { /* make sure both info are the same provider and provide the same attributes */ - if (0 == strcmp(provider_info->fabric_attr->prov_name, provider->fabric_attr->prov_name) && - !check_tx_attr(provider_info->tx_attr, provider->tx_attr) && - !check_rx_attr(provider_info->rx_attr, provider->rx_attr) && - !check_ep_attr(provider_info->ep_attr, provider->ep_attr) && - !(provider_info->caps & ~(provider->caps)) && - !(provider_info->mode & ~(provider->mode)) && - provider_info->addr_format == provider->addr_format) { + if (0 == strcmp(provider_info->fabric_attr->prov_name, provider->fabric_attr->prov_name) + && !check_tx_attr(provider_info->tx_attr, provider->tx_attr) + && !check_rx_attr(provider_info->rx_attr, provider->rx_attr) + && !check_ep_attr(provider_info->ep_attr, provider->ep_attr) + && !(provider_info->caps & ~(provider->caps)) && !(provider_info->mode & ~(provider->mode)) + && provider_info->addr_format == provider->addr_format) { return 0; } else { return OPAL_ERROR; @@ -220,8 +204,7 @@ check_provider_attr(struct fi_info *provider_info, * reason, returns false. Otherwise, returns the result of * hwloc_cpuset_intersects() */ -static bool -compare_cpusets(hwloc_topology_t topology, struct fi_pci_attr pci) +static bool compare_cpusets(hwloc_topology_t topology, struct fi_pci_attr pci) { bool result = false; int ret; @@ -246,8 +229,8 @@ compare_cpusets(hwloc_topology_t topology, struct fi_pci_attr pci) } /* Get the pci device from bdf */ - obj = hwloc_get_pcidev_by_busid(topology, pci.domain_id, pci.bus_id, - pci.device_id, pci.function_id); + obj = hwloc_get_pcidev_by_busid(topology, pci.domain_id, pci.bus_id, pci.device_id, + pci.function_id); if (NULL == obj) { goto error; } @@ -271,10 +254,9 @@ compare_cpusets(hwloc_topology_t topology, struct fi_pci_attr pci) * * returns 0 if the list is NULL */ -static int -count_providers(struct fi_info* provider_list) +static int count_providers(struct fi_info *provider_list) { - struct fi_info* dev = provider_list; + struct fi_info *dev = provider_list; int num_provider = 0; while (NULL != dev) { @@ -315,20 +297,18 @@ static uint32_t get_package_rank(opal_process_info_t *process_info) #if HAVE_DECL_PMIX_PACKAGE_RANK // Try to get the PACKAGE_RANK from PMIx - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_PACKAGE_RANK, - &pname, &package_rank_ptr, PMIX_UINT16); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_PACKAGE_RANK, &pname, &package_rank_ptr, PMIX_UINT16); if (PMIX_SUCCESS == rc) { - return (uint32_t)*package_rank_ptr; + return (uint32_t) *package_rank_ptr; } #endif // Get the local peers - OPAL_MODEX_RECV_VALUE(rc, PMIX_LOCAL_PEERS, - &pname, &local_peers, PMIX_STRING); + OPAL_MODEX_RECV_VALUE(rc, PMIX_LOCAL_PEERS, &pname, &local_peers, PMIX_STRING); if (PMIX_SUCCESS != rc || NULL == local_peers) { // We can't find package_rank, fall back to procid opal_show_help("help-common-ofi.txt", "package_rank failed", true); - return (uint32_t)process_info->myprocid.rank; + return (uint32_t) process_info->myprocid.rank; } peers = opal_argv_split(local_peers, ','); free(local_peers); @@ -337,19 +317,20 @@ static uint32_t get_package_rank(opal_process_info_t *process_info) pname.vpid = strtoul(peers[i], NULL, 10); locality_string = NULL; // Get the LOCALITY_STRING for process[i] - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCALITY_STRING, - &pname, &locality_string, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCALITY_STRING, &pname, &locality_string, + PMIX_STRING); if (PMIX_SUCCESS != rc || NULL == locality_string) { // If we don't have information about locality, fall back to procid int level = 10; if (opal_output_get_verbosity(opal_common_ofi.output) >= level) { opal_show_help("help-common-ofi.txt", "package_rank failed", true, level); } - return (uint32_t)process_info->myprocid.rank; + return (uint32_t) process_info->myprocid.rank; } // compute relative locality - relative_locality = opal_hwloc_compute_relative_locality(process_info->locality, locality_string); + relative_locality = opal_hwloc_compute_relative_locality(process_info->locality, + locality_string); free(locality_string); if (relative_locality & OPAL_PROC_ON_SOCKET) { @@ -358,7 +339,7 @@ static uint32_t get_package_rank(opal_process_info_t *process_info) } } - return (uint32_t)package_ranks[process_info->my_local_rank]; + return (uint32_t) package_ranks[process_info->my_local_rank]; } /* Selects a NIC based on hardware locality between process cpuset and device BDF. @@ -416,8 +397,8 @@ static uint32_t get_package_rank(opal_process_info_t *process_info) * that the provider returned is local to the process or that the processes will * balance across available NICs. */ -struct fi_info* -opal_mca_common_ofi_select_provider(struct fi_info *provider_list, opal_process_info_t *process_info) +struct fi_info *opal_mca_common_ofi_select_provider(struct fi_info *provider_list, + opal_process_info_t *process_info) { struct fi_info *provider = provider_list, *current_provider = provider_list; struct fi_info **provider_table; @@ -433,19 +414,18 @@ opal_mca_common_ofi_select_provider(struct fi_info *provider_list, opal_process_ ret = opal_hwloc_base_get_topology(); if (0 > ret) { /* Provider selection can continue but there is no guarantee of locality */ - opal_output_verbose(1, opal_common_ofi.output, - "%s:%d:Failed to initialize topology\n", + opal_output_verbose(1, opal_common_ofi.output, "%s:%d:Failed to initialize topology\n", __FILE__, __LINE__); } provider_limit = count_providers(provider_list); /* Allocate memory for provider table */ - provider_table = calloc(provider_limit, sizeof(struct fi_info*)); + provider_table = calloc(provider_limit, sizeof(struct fi_info *)); if (NULL == provider_table) { opal_output_verbose(1, opal_common_ofi.output, - "%s:%d:Failed to allocate memory for provider table\n", - __FILE__, __LINE__); + "%s:%d:Failed to allocate memory for provider table\n", __FILE__, + __LINE__); return provider_list; } @@ -499,9 +479,8 @@ opal_mca_common_ofi_select_provider(struct fi_info *provider_list, opal_process_ #if OPAL_ENABLE_DEBUG opal_output_verbose(1, opal_common_ofi.output, - "package rank: %d device: %s cpusets match: %s\n", - package_rank, provider->domain_attr->name, - cpusets_match ? "true" : "false"); + "package rank: %d device: %s cpusets match: %s\n", package_rank, + provider->domain_attr->name, cpusets_match ? "true" : "false"); #endif free(provider_table); diff --git a/opal/mca/common/ofi/common_ofi.h b/opal/mca/common/ofi/common_ofi.h index 5b7ebc13206..2ec8ae5db10 100644 --- a/opal/mca/common/ofi/common_ofi.h +++ b/opal/mca/common/ofi/common_ofi.h @@ -17,8 +17,8 @@ #define OPAL_MCA_COMMON_OFI_H #include "opal_config.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/util/proc.h" #include @@ -56,6 +56,7 @@ OPAL_DECLSPEC int opal_common_ofi_is_in_list(char **list, char *item); END_C_DECLS -struct fi_info* opal_mca_common_ofi_select_provider(struct fi_info *provider_list, opal_process_info_t *process_info); +struct fi_info *opal_mca_common_ofi_select_provider(struct fi_info *provider_list, + opal_process_info_t *process_info); #endif /* OPAL_MCA_COMMON_OFI_H */ diff --git a/opal/mca/common/sm/common_sm.c b/opal/mca/common/sm/common_sm.c index 573254cb44e..ce329f60ace 100644 --- a/opal/mca/common/sm/common_sm.c +++ b/opal/mca/common/sm/common_sm.c @@ -32,30 +32,24 @@ #include "opal_config.h" +#include "common_sm.h" #include "opal/align.h" +#include "opal/constants.h" +#include "opal/mca/shmem/base/base.h" #include "opal/util/argv.h" -#include "opal/util/show_help.h" #include "opal/util/error.h" -#include "opal/mca/shmem/base/base.h" -#include "common_sm.h" -#include "opal/constants.h" - - -OBJ_CLASS_INSTANCE(mca_common_sm_module_t,opal_list_item_t, - NULL, NULL); +#include "opal/util/show_help.h" +OBJ_CLASS_INSTANCE(mca_common_sm_module_t, opal_list_item_t, NULL, NULL); /* ////////////////////////////////////////////////////////////////////////// */ /* static utility functions */ /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ -static mca_common_sm_module_t * -attach_and_init(opal_shmem_ds_t *shmem_bufp, - size_t size, - size_t size_ctl_structure, - size_t data_seg_alignment, - bool first_call) +static mca_common_sm_module_t *attach_and_init(opal_shmem_ds_t *shmem_bufp, size_t size, + size_t size_ctl_structure, size_t data_seg_alignment, + bool first_call) { mca_common_sm_module_t *map = NULL; mca_common_sm_seg_header_t *seg = NULL; @@ -64,22 +58,21 @@ attach_and_init(opal_shmem_ds_t *shmem_bufp, /* attach to the specified segment. note that at this point, the contents of * *shmem_bufp have already been initialized via opal_shmem_segment_create. */ - if (NULL == (seg = (mca_common_sm_seg_header_t *) - opal_shmem_segment_attach(shmem_bufp))) { + if (NULL == (seg = (mca_common_sm_seg_header_t *) opal_shmem_segment_attach(shmem_bufp))) { return NULL; } opal_atomic_rmb(); if (NULL == (map = OBJ_NEW(mca_common_sm_module_t))) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); - (void)opal_shmem_segment_detach(shmem_bufp); + (void) opal_shmem_segment_detach(shmem_bufp); return NULL; } /* copy meta information into common sm module * from ====> to */ if (OPAL_SUCCESS != opal_shmem_ds_copy(shmem_bufp, &map->shmem_ds)) { - (void)opal_shmem_segment_detach(shmem_bufp); + (void) opal_shmem_segment_detach(shmem_bufp); free(map); return NULL; } @@ -90,7 +83,7 @@ attach_and_init(opal_shmem_ds_t *shmem_bufp, */ map->module_seg = seg; - addr = ((unsigned char *)seg) + size_ctl_structure; + addr = ((unsigned char *) seg) + size_ctl_structure; /* if we have a data segment (i.e., if 0 != data_seg_alignment), * then make it the first aligned address after the control * structure. IF THIS HAPPENS, THIS IS A PROGRAMMING ERROR IN @@ -99,26 +92,23 @@ attach_and_init(opal_shmem_ds_t *shmem_bufp, if (0 != data_seg_alignment) { addr = OPAL_ALIGN_PTR(addr, data_seg_alignment, unsigned char *); /* is addr past end of the shared memory segment? */ - if ((unsigned char *)seg + shmem_bufp->seg_size < addr) { + if ((unsigned char *) seg + shmem_bufp->seg_size < addr) { opal_show_help("help-mpi-common-sm.txt", "mmap too small", 1, - opal_process_info.nodename, - (unsigned long)shmem_bufp->seg_size, - (unsigned long)size_ctl_structure, - (unsigned long)data_seg_alignment); - (void)opal_shmem_segment_detach(shmem_bufp); + opal_process_info.nodename, (unsigned long) shmem_bufp->seg_size, + (unsigned long) size_ctl_structure, (unsigned long) data_seg_alignment); + (void) opal_shmem_segment_detach(shmem_bufp); free(map); return NULL; } } map->module_data_addr = addr; - map->module_seg_addr = (unsigned char *)seg; + map->module_seg_addr = (unsigned char *) seg; /* note that size is only used during the first call */ if (first_call) { /* initialize some segment information */ - size_t mem_offset = map->module_data_addr - - (unsigned char *)map->module_seg; + size_t mem_offset = map->module_data_addr - (unsigned char *) map->module_seg; opal_atomic_lock_init(&map->module_seg->seg_lock, OPAL_ATOMIC_LOCK_UNLOCKED); map->module_seg->seg_inited = 0; map->module_seg->seg_num_procs_inited = 0; @@ -128,7 +118,7 @@ attach_and_init(opal_shmem_ds_t *shmem_bufp, } /* increment the number of processes that are attached to the segment. */ - (void)opal_atomic_add_fetch_size_t(&map->module_seg->seg_num_procs_inited, 1); + (void) opal_atomic_add_fetch_size_t(&map->module_seg->seg_num_procs_inited, 1); /* commit the changes before we return */ opal_atomic_wmb(); @@ -141,11 +131,9 @@ attach_and_init(opal_shmem_ds_t *shmem_bufp, /* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */ -mca_common_sm_module_t * -mca_common_sm_module_create_and_attach(size_t size, - char *file_name, - size_t size_ctl_structure, - size_t data_seg_alignment) +mca_common_sm_module_t *mca_common_sm_module_create_and_attach(size_t size, char *file_name, + size_t size_ctl_structure, + size_t data_seg_alignment) { mca_common_sm_module_t *map = NULL; opal_shmem_ds_t *seg_meta = NULL; @@ -155,8 +143,7 @@ mca_common_sm_module_create_and_attach(size_t size, return NULL; } if (OPAL_SUCCESS == opal_shmem_segment_create(seg_meta, file_name, size)) { - map = attach_and_init(seg_meta, size, size_ctl_structure, - data_seg_alignment, true); + map = attach_and_init(seg_meta, size, size_ctl_structure, data_seg_alignment, true); } /* at this point, seg_meta has been copied to the newly created * shared memory segment, so we can free it */ @@ -172,20 +159,17 @@ mca_common_sm_module_create_and_attach(size_t size, * @return a pointer to the mca_common_sm_module_t associated with seg_meta if * everything was okay, otherwise returns NULL. */ -mca_common_sm_module_t * -mca_common_sm_module_attach(opal_shmem_ds_t *seg_meta, - size_t size_ctl_structure, - size_t data_seg_alignment) +mca_common_sm_module_t *mca_common_sm_module_attach(opal_shmem_ds_t *seg_meta, + size_t size_ctl_structure, + size_t data_seg_alignment) { /* notice that size is 0 here. it really doesn't matter because size WILL * NOT be used because this is an attach (first_call is false). */ - return attach_and_init(seg_meta, 0, size_ctl_structure, - data_seg_alignment, false); + return attach_and_init(seg_meta, 0, size_ctl_structure, data_seg_alignment, false); } /* ////////////////////////////////////////////////////////////////////////// */ -int -mca_common_sm_module_unlink(mca_common_sm_module_t *modp) +int mca_common_sm_module_unlink(mca_common_sm_module_t *modp) { if (NULL == modp) { return OPAL_ERROR; @@ -197,10 +181,8 @@ mca_common_sm_module_unlink(mca_common_sm_module_t *modp) } /* ////////////////////////////////////////////////////////////////////////// */ -int -mca_common_sm_local_proc_reorder(opal_proc_t **procs, - size_t num_procs, - size_t *out_num_local_procs) +int mca_common_sm_local_proc_reorder(opal_proc_t **procs, size_t num_procs, + size_t *out_num_local_procs) { size_t num_local_procs = 0; bool found_lowest = false; @@ -221,13 +203,12 @@ mca_common_sm_local_proc_reorder(opal_proc_t **procs, if (!found_lowest) { procs[0] = procs[p]; found_lowest = true; - } - else { + } else { /* save this proc */ procs[num_local_procs] = procs[p]; /* if we have a new lowest, swap it with position 0 * so that procs[0] is always the lowest named proc */ - if( 0 > opal_compare_proc(procs[p]->proc_name, procs[0]->proc_name) ) { + if (0 > opal_compare_proc(procs[p]->proc_name, procs[0]->proc_name)) { temp_proc = procs[0]; procs[0] = procs[p]; procs[num_local_procs] = temp_proc; @@ -253,7 +234,7 @@ mca_common_sm_local_proc_reorder(opal_proc_t **procs, * * @retval addr virtual address */ -void *mca_common_sm_seg_alloc (void *ctx, size_t *size) +void *mca_common_sm_seg_alloc(void *ctx, size_t *size) { mca_common_sm_module_t *sm_module = (mca_common_sm_module_t *) ctx; mca_common_sm_seg_header_t *seg = sm_module->module_seg; @@ -262,8 +243,7 @@ void *mca_common_sm_seg_alloc (void *ctx, size_t *size) opal_atomic_lock(&seg->seg_lock); if (seg->seg_offset + *size > seg->seg_size) { addr = NULL; - } - else { + } else { size_t fixup; /* add base address to segment offset */ @@ -284,14 +264,12 @@ void *mca_common_sm_seg_alloc (void *ctx, size_t *size) } /* ////////////////////////////////////////////////////////////////////////// */ -int -mca_common_sm_fini(mca_common_sm_module_t *mca_common_sm_module) +int mca_common_sm_fini(mca_common_sm_module_t *mca_common_sm_module) { int rc = OPAL_SUCCESS; if (NULL != mca_common_sm_module->module_seg) { - if (OPAL_SUCCESS != - opal_shmem_segment_detach(&mca_common_sm_module->shmem_ds)) { + if (OPAL_SUCCESS != opal_shmem_segment_detach(&mca_common_sm_module->shmem_ds)) { rc = OPAL_ERROR; } } diff --git a/opal/mca/common/sm/common_sm.h b/opal/mca/common/sm/common_sm.h index 7c4456f0457..b5a3704b312 100644 --- a/opal/mca/common/sm/common_sm.h +++ b/opal/mca/common/sm/common_sm.h @@ -25,15 +25,15 @@ #include "opal_config.h" -#include "opal/mca/mca.h" -#include "opal/class/opal_object.h" +#include "common_sm_mpool.h" #include "opal/class/opal_list.h" -#include "opal/sys/atomic.h" -#include "opal/mca/shmem/shmem.h" +#include "opal/class/opal_object.h" #include "opal/mca/btl/base/base.h" -#include "opal/util/proc.h" #include "opal/mca/btl/base/btl_base_error.h" -#include "common_sm_mpool.h" +#include "opal/mca/mca.h" +#include "opal/mca/shmem/shmem.h" +#include "opal/sys/atomic.h" +#include "opal/util/proc.h" BEGIN_C_DECLS @@ -81,10 +81,8 @@ OBJ_CLASS_DECLARATION(mca_common_sm_module_t); * * @returnvalue OPAL_SUCCESS on success, something else, otherwise. */ -OPAL_DECLSPEC extern int -mca_common_sm_local_proc_reorder(opal_proc_t **procs, - size_t num_procs, - size_t *out_num_local_procs); +OPAL_DECLSPEC extern int mca_common_sm_local_proc_reorder(opal_proc_t **procs, size_t num_procs, + size_t *out_num_local_procs); /** * This routine is used to create and attach to a shared memory segment @@ -95,9 +93,7 @@ mca_common_sm_local_proc_reorder(opal_proc_t **procs, * Returns NULL if an error occurred. */ OPAL_DECLSPEC extern mca_common_sm_module_t * -mca_common_sm_module_create_and_attach(size_t size, - char *file_name, - size_t size_ctl_structure, +mca_common_sm_module_create_and_attach(size_t size, char *file_name, size_t size_ctl_structure, size_t data_seg_alignment); /** @@ -110,10 +106,9 @@ mca_common_sm_module_create_and_attach(size_t size, * @returnvalue pointer to control structure at head of shared memory segment. * Returns NULL if an error occurred. */ -OPAL_DECLSPEC extern mca_common_sm_module_t * -mca_common_sm_module_attach(opal_shmem_ds_t *seg_meta, - size_t size_ctl_structure, - size_t data_seg_alignment); +OPAL_DECLSPEC extern mca_common_sm_module_t *mca_common_sm_module_attach(opal_shmem_ds_t *seg_meta, + size_t size_ctl_structure, + size_t data_seg_alignment); /** * A thin wrapper around opal_shmem_unlink. @@ -123,13 +118,12 @@ mca_common_sm_module_attach(opal_shmem_ds_t *seg_meta, * @returnvalue OPAL_SUCCESS if the operation completed successfully, * OPAL_ERROR otherwise. */ -OPAL_DECLSPEC extern int -mca_common_sm_module_unlink(mca_common_sm_module_t *modp); +OPAL_DECLSPEC extern int mca_common_sm_module_unlink(mca_common_sm_module_t *modp); /** * callback from the sm mpool */ -OPAL_DECLSPEC extern void *mca_common_sm_seg_alloc (void *ctx, size_t *size); +OPAL_DECLSPEC extern void *mca_common_sm_seg_alloc(void *ctx, size_t *size); /** * This function will release all local resources attached to the @@ -142,15 +136,13 @@ OPAL_DECLSPEC extern void *mca_common_sm_seg_alloc (void *ctx, size_t *size); * @return OPAL_SUCCESS if everything was okay, otherwise return OPAL_ERROR. */ -OPAL_DECLSPEC extern int -mca_common_sm_fini(mca_common_sm_module_t *mca_common_sm_module); +OPAL_DECLSPEC extern int mca_common_sm_fini(mca_common_sm_module_t *mca_common_sm_module); /** * instance that is shared between components that use shared memory. */ OPAL_DECLSPEC extern mca_common_sm_module_t *mca_common_sm_module; - END_C_DECLS #endif /* _COMMON_SM_H_ */ diff --git a/opal/mca/common/sm/common_sm_mpool.c b/opal/mca/common/sm/common_sm_mpool.c index c50d048eff9..eaf4b8c114d 100644 --- a/opal/mca/common/sm/common_sm_mpool.c +++ b/opal/mca/common/sm/common_sm_mpool.c @@ -23,41 +23,39 @@ */ #include "opal_config.h" -#include -#include "opal/util/printf.h" #include "common_sm_mpool.h" -#include "opal/mca/common/sm/common_sm.h" -#include "opal/mca/common/cuda/common_cuda.h" #include "opal/mca/allocator/base/base.h" +#include "opal/mca/common/cuda/common_cuda.h" +#include "opal/mca/common/sm/common_sm.h" +#include "opal/util/printf.h" +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #include "opal/mca/hwloc/base/base.h" -static void sm_module_finalize(mca_mpool_base_module_t* module); +static void sm_module_finalize(mca_mpool_base_module_t *module); /* * Returns base address of shared memory mapping. */ -static void *mca_common_sm_mpool_base (mca_mpool_base_module_t *mpool); +static void *mca_common_sm_mpool_base(mca_mpool_base_module_t *mpool); /** - * Allocate block of shared memory. - */ -static void *mca_common_sm_mpool_alloc (mca_mpool_base_module_t *mpool, - size_t size, size_t align, - uint32_t flags); + * Allocate block of shared memory. + */ +static void *mca_common_sm_mpool_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags); /** - * free function typedef - */ -static void mca_common_sm_mpool_free(mca_mpool_base_module_t *mpool, - void *addr); + * free function typedef + */ +static void mca_common_sm_mpool_free(mca_mpool_base_module_t *mpool, void *addr); /* * Initializes the mpool module. */ -static void mca_common_sm_mpool_module_init(mca_common_sm_mpool_module_t* mpool) +static void mca_common_sm_mpool_module_init(mca_common_sm_mpool_module_t *mpool) { mpool->super.mpool_base = mca_common_sm_mpool_base; mpool->super.mpool_alloc = mca_common_sm_mpool_alloc; @@ -72,13 +70,13 @@ static void mca_common_sm_mpool_module_init(mca_common_sm_mpool_module_t* mpool) mpool->mem_node = -1; } -mca_mpool_base_module_t *common_sm_mpool_create (mca_common_sm_mpool_resources_t *resources) +mca_mpool_base_module_t *common_sm_mpool_create(mca_common_sm_mpool_resources_t *resources) { mca_common_sm_mpool_module_t *mpool_module; - mca_allocator_base_component_t* allocator_component; + mca_allocator_base_component_t *allocator_component; /* Make a new mpool module */ - mpool_module = (mca_common_sm_mpool_module_t *) malloc (sizeof (*mpool_module)); + mpool_module = (mca_common_sm_mpool_module_t *) malloc(sizeof(*mpool_module)); mca_common_sm_mpool_module_init(mpool_module); /* set sm_size */ @@ -89,18 +87,17 @@ mca_mpool_base_module_t *common_sm_mpool_create (mca_common_sm_mpool_resources_t /* if specified allocator cannot be loaded - look for an alternative */ if (NULL == allocator_component) { if (opal_list_get_size(&opal_allocator_base_framework.framework_components) == 0) { - mca_base_component_list_item_t *item = - (mca_base_component_list_item_t *) + mca_base_component_list_item_t *item = (mca_base_component_list_item_t *) opal_list_get_first(&opal_allocator_base_framework.framework_components); - allocator_component = - (mca_allocator_base_component_t *)item->cli_component; - opal_output( - 0, "mca_common_sm_mpool_init: " - "unable to locate allocator: %s - using %s\n", - resources->allocator, - allocator_component->allocator_version.mca_component_name); + allocator_component = (mca_allocator_base_component_t *) item->cli_component; + opal_output(0, + "mca_common_sm_mpool_init: " + "unable to locate allocator: %s - using %s\n", + resources->allocator, + allocator_component->allocator_version.mca_component_name); } else { - opal_output(0, "mca_common_sm_mpool_init: " + opal_output(0, + "mca_common_sm_mpool_init: " "unable to locate allocator: %s\n", resources->allocator); free(mpool_module); @@ -110,10 +107,11 @@ mca_mpool_base_module_t *common_sm_mpool_create (mca_common_sm_mpool_resources_t mpool_module->mem_node = resources->mem_node; - if (NULL == (mpool_module->sm_common_module = - mca_common_sm_module_attach(&resources->bs_meta_buf, - sizeof(mca_common_sm_module_t), 8))) { - opal_output(0, "mca_common_sm_mpool_init: " + if (NULL + == (mpool_module->sm_common_module = mca_common_sm_module_attach( + &resources->bs_meta_buf, sizeof(mca_common_sm_module_t), 8))) { + opal_output(0, + "mca_common_sm_mpool_init: " "unable to create shared memory mapping (%s)", resources->bs_meta_buf.seg_name); free(mpool_module); @@ -121,9 +119,9 @@ mca_mpool_base_module_t *common_sm_mpool_create (mca_common_sm_mpool_resources_t } /* setup allocator */ - mpool_module->sm_allocator = - allocator_component->allocator_init (true, mca_common_sm_seg_alloc, - NULL, mpool_module->sm_common_module); + mpool_module->sm_allocator = allocator_component + ->allocator_init(true, mca_common_sm_seg_alloc, NULL, + mpool_module->sm_common_module); if (NULL == mpool_module->sm_allocator) { opal_output(0, "mca_common_sm_mpool_init: unable to initialize allocator"); free(mpool_module); @@ -133,28 +131,26 @@ mca_mpool_base_module_t *common_sm_mpool_create (mca_common_sm_mpool_resources_t return &mpool_module->super; } - /* * base address of shared memory mapping */ static void *mca_common_sm_mpool_base(mca_mpool_base_module_t *mpool) { mca_common_sm_mpool_module_t *sm_mpool = (mca_common_sm_mpool_module_t *) mpool; - return (NULL != sm_mpool->sm_common_module) ? - sm_mpool->sm_common_module->module_seg_addr : NULL; + return (NULL != sm_mpool->sm_common_module) ? sm_mpool->sm_common_module->module_seg_addr + : NULL; } /** - * allocate function - */ -static void *mca_common_sm_mpool_alloc (mca_mpool_base_module_t* mpool, - size_t size, size_t align, uint32_t flags) + * allocate function + */ +static void *mca_common_sm_mpool_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags) { - mca_common_sm_mpool_module_t* mpool_sm = (mca_common_sm_mpool_module_t*)mpool; + mca_common_sm_mpool_module_t *mpool_sm = (mca_common_sm_mpool_module_t *) mpool; opal_hwloc_base_memory_segment_t mseg; - mseg.mbs_start_addr = - mpool_sm->sm_allocator->alc_alloc(mpool_sm->sm_allocator, size, align); + mseg.mbs_start_addr = mpool_sm->sm_allocator->alc_alloc(mpool_sm->sm_allocator, size, align); if (mpool_sm->mem_node >= 0) { mseg.mbs_len = size; @@ -165,21 +161,20 @@ static void *mca_common_sm_mpool_alloc (mca_mpool_base_module_t* mpool, } /** - * free function - */ + * free function + */ void mca_common_sm_mpool_free(mca_mpool_base_module_t *mpool, void *addr) { - mca_common_sm_mpool_module_t* mpool_sm = (mca_common_sm_mpool_module_t*)mpool; + mca_common_sm_mpool_module_t *mpool_sm = (mca_common_sm_mpool_module_t *) mpool; mpool_sm->sm_allocator->alc_free(mpool_sm->sm_allocator, addr); } -static void sm_module_finalize(mca_mpool_base_module_t* module) +static void sm_module_finalize(mca_mpool_base_module_t *module) { - mca_common_sm_mpool_module_t *sm_module = (mca_common_sm_mpool_module_t*) module; + mca_common_sm_mpool_module_t *sm_module = (mca_common_sm_mpool_module_t *) module; if (NULL != sm_module->sm_common_module) { - if (OPAL_SUCCESS == - mca_common_sm_fini(sm_module->sm_common_module)) { + if (OPAL_SUCCESS == mca_common_sm_fini(sm_module->sm_common_module)) { unlink(sm_module->sm_common_module->shmem_ds.seg_name); } OBJ_RELEASE(sm_module->sm_common_module); diff --git a/opal/mca/common/sm/common_sm_mpool.h b/opal/mca/common/sm/common_sm_mpool.h index fdaa72e1830..693ce8b216a 100644 --- a/opal/mca/common/sm/common_sm_mpool.h +++ b/opal/mca/common/sm/common_sm_mpool.h @@ -30,18 +30,18 @@ #include "opal_config.h" -#include "opal/util/event.h" #include "opal/mca/shmem/shmem.h" +#include "opal/util/event.h" -#include "opal/mca/mpool/mpool.h" #include "opal/mca/allocator/allocator.h" +#include "opal/mca/mpool/mpool.h" BEGIN_C_DECLS struct mca_common_sm_module_t; typedef struct mca_common_sm_mpool_resources_t { - size_t size; + size_t size; int32_t mem_node; const char *allocator; /* backing store metadata */ @@ -57,7 +57,7 @@ typedef struct mca_common_sm_mpool_module_t { int32_t mem_node; } mca_common_sm_mpool_module_t; -OPAL_DECLSPEC mca_mpool_base_module_t *common_sm_mpool_create (mca_common_sm_mpool_resources_t *); +OPAL_DECLSPEC mca_mpool_base_module_t *common_sm_mpool_create(mca_common_sm_mpool_resources_t *); END_C_DECLS diff --git a/opal/mca/common/ucx/common_ucx.c b/opal/mca/common/ucx/common_ucx.c index 592044a7ccd..52a704c2f24 100644 --- a/opal/mca/common/ucx/common_ucx.c +++ b/opal/mca/common/ucx/common_ucx.c @@ -13,37 +13,34 @@ #include "opal_config.h" #include "common_ucx.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/mca/pmix/pmix-internal.h" #include "opal/memoryhooks/memory.h" #include "opal/util/argv.h" -#include #include #include +#include /***********************************************************************/ extern mca_base_framework_t opal_memory_base_framework; -opal_common_ucx_module_t opal_common_ucx = { - .verbose = 0, - .progress_iterations = 100, - .registered = 0, - .opal_mem_hooks = 0, - .tls = NULL -}; +opal_common_ucx_module_t opal_common_ucx = {.verbose = 0, + .progress_iterations = 100, + .registered = 0, + .opal_mem_hooks = 0, + .tls = NULL}; -static void opal_common_ucx_mem_release_cb(void *buf, size_t length, - void *cbdata, bool from_alloc) +static void opal_common_ucx_mem_release_cb(void *buf, size_t length, void *cbdata, bool from_alloc) { ucm_vm_munmap(buf, length); } OPAL_DECLSPEC void opal_common_ucx_mca_var_register(const mca_base_component_t *component) { - static const char *default_tls = "rc_verbs,ud_verbs,rc_mlx5,dc_mlx5,cuda_ipc,rocm_ipc"; + static const char *default_tls = "rc_verbs,ud_verbs,rc_mlx5,dc_mlx5,cuda_ipc,rocm_ipc"; static const char *default_devices = "mlx*"; static int registered = 0; static int hook_index; @@ -57,8 +54,7 @@ OPAL_DECLSPEC void opal_common_ucx_mca_var_register(const mca_base_component_t * "Verbose level of the UCX components", MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - &opal_common_ucx.verbose); + MCA_BASE_VAR_SCOPE_LOCAL, &opal_common_ucx.verbose); progress_index = mca_base_var_register("opal", "opal_common", "ucx", "progress_iterations", "Set number of calls of internal UCX progress " "calls per opal_progress call", @@ -68,55 +64,48 @@ OPAL_DECLSPEC void opal_common_ucx_mca_var_register(const mca_base_component_t * &opal_common_ucx.progress_iterations); hook_index = mca_base_var_register("opal", "opal_common", "ucx", "opal_mem_hooks", "Use OPAL memory hooks, instead of UCX internal " - "memory hooks", MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_3, + "memory hooks", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, &opal_common_ucx.opal_mem_hooks); - opal_common_ucx.tls = malloc(sizeof(*opal_common_ucx.tls)); + opal_common_ucx.tls = malloc(sizeof(*opal_common_ucx.tls)); *opal_common_ucx.tls = strdup(default_tls); - tls_index = mca_base_var_register("opal", "opal_common", "ucx", "tls", - "List of UCX transports which should be supported on the system, to enable " - "selecting the UCX component. Special values: any (any available). " - "A '^' prefix negates the list. " - "For example, in order to exclude on shared memory and TCP transports, " - "please set to '^posix,sysv,self,tcp,cma,knem,xpmem'.", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - opal_common_ucx.tls); - - opal_common_ucx.devices = malloc(sizeof(*opal_common_ucx.devices)); + tls_index = mca_base_var_register( + "opal", "opal_common", "ucx", "tls", + "List of UCX transports which should be supported on the system, to enable " + "selecting the UCX component. Special values: any (any available). " + "A '^' prefix negates the list. " + "For example, in order to exclude on shared memory and TCP transports, " + "please set to '^posix,sysv,self,tcp,cma,knem,xpmem'.", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, + opal_common_ucx.tls); + + opal_common_ucx.devices = malloc(sizeof(*opal_common_ucx.devices)); *opal_common_ucx.devices = strdup(default_devices); - devices_index = mca_base_var_register("opal", "opal_common", "ucx", "devices", - "List of device driver pattern names, which, if supported by UCX, will " - "bump its priority above ob1. Special values: any (any available)", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - opal_common_ucx.devices); + devices_index = mca_base_var_register( + "opal", "opal_common", "ucx", "devices", + "List of device driver pattern names, which, if supported by UCX, will " + "bump its priority above ob1. Special values: any (any available)", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, + opal_common_ucx.devices); registered = 1; } if (component) { mca_base_var_register_synonym(verbose_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "verbose", 0); mca_base_var_register_synonym(progress_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "progress_iterations", 0); mca_base_var_register_synonym(hook_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "opal_mem_hooks", 0); mca_base_var_register_synonym(tls_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "tls", 0); mca_base_var_register_synonym(devices_index, component->mca_project_name, - component->mca_type_name, - component->mca_component_name, + component->mca_type_name, component->mca_component_name, "devices", 0); } } @@ -139,14 +128,16 @@ OPAL_DECLSPEC void opal_common_ucx_mca_register(void) ret = mca_base_framework_open(&opal_memory_base_framework, 0); if (OPAL_SUCCESS != ret) { /* failed to initialize memory framework - just exit */ - MCA_COMMON_UCX_VERBOSE(1, "failed to initialize memory base framework: %d, " - "memory hooks will not be used", ret); + MCA_COMMON_UCX_VERBOSE(1, + "failed to initialize memory base framework: %d, " + "memory hooks will not be used", + ret); return; } - if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) == - ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & - opal_mem_hooks_support_level())) { + if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) + == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) + & opal_mem_hooks_support_level())) { MCA_COMMON_UCX_VERBOSE(1, "%s", "using OPAL memory hooks as external events"); ucm_set_external_event(UCM_EVENT_VM_UNMAPPED); opal_mem_hooks_register_release(opal_common_ucx_mem_release_cb, NULL); @@ -190,16 +181,14 @@ static bool opal_common_ucx_check_device(const char *device_name, char **device_ driver_path[sizeof(driver_path) - 1] = '\0'; ret = readlink(sysfs_driver_link, driver_path, sizeof(driver_path) - 1); if (ret < 0) { - MCA_COMMON_UCX_VERBOSE(2, "readlink(%s) failed: %s", sysfs_driver_link, - strerror(errno)); + MCA_COMMON_UCX_VERBOSE(2, "readlink(%s) failed: %s", sysfs_driver_link, strerror(errno)); return false; } driver_name = basename(driver_path); for (list_item = device_list; *list_item != NULL; ++list_item) { if (!fnmatch(*list_item, driver_name, 0)) { - MCA_COMMON_UCX_VERBOSE(2, "driver '%s' matched by '%s'", - driver_path, *list_item); + MCA_COMMON_UCX_VERBOSE(2, "driver '%s' matched by '%s'", driver_path, *list_item); return true; } } @@ -208,15 +197,13 @@ static bool opal_common_ucx_check_device(const char *device_name, char **device_ } #endif -OPAL_DECLSPEC opal_common_ucx_support_level_t -opal_common_ucx_support_level(ucp_context_h context) +OPAL_DECLSPEC opal_common_ucx_support_level_t opal_common_ucx_support_level(ucp_context_h context) { opal_common_ucx_support_level_t support_level = OPAL_COMMON_UCX_SUPPORT_NONE; - static const char *support_level_names[] = { - [OPAL_COMMON_UCX_SUPPORT_NONE] = "none", - [OPAL_COMMON_UCX_SUPPORT_TRANSPORT] = "transports only", - [OPAL_COMMON_UCX_SUPPORT_DEVICE] = "transports and devices" - }; + static const char *support_level_names[] + = {[OPAL_COMMON_UCX_SUPPORT_NONE] = "none", + [OPAL_COMMON_UCX_SUPPORT_TRANSPORT] = "transports only", + [OPAL_COMMON_UCX_SUPPORT_DEVICE] = "transports and devices"}; #if HAVE_DECL_OPEN_MEMSTREAM char *rsc_tl_name, *rsc_device_name; char **tl_list, **device_list, **list_item; @@ -229,7 +216,7 @@ opal_common_ucx_support_level(ucp_context_h context) int ret; #endif - is_any_tl = !strcmp(*opal_common_ucx.tls, "any"); + is_any_tl = !strcmp(*opal_common_ucx.tls, "any"); is_any_device = !strcmp(*opal_common_ucx.devices, "any"); /* Check for special value "any" */ @@ -242,7 +229,7 @@ opal_common_ucx_support_level(ucp_context_h context) #if HAVE_DECL_OPEN_MEMSTREAM /* Split transports list */ - negate = ('^' == (*opal_common_ucx.tls)[0]); + negate = ('^' == (*opal_common_ucx.tls)[0]); tl_list = opal_argv_split(*opal_common_ucx.tls + (negate ? 1 : 0), ','); if (tl_list == NULL) { MCA_COMMON_UCX_VERBOSE(1, "failed to split tl list '%s', ucx is disabled", @@ -261,8 +248,10 @@ opal_common_ucx_support_level(ucp_context_h context) /* Open memory stream to dump UCX information to */ stream = open_memstream(&buffer, &size); if (stream == NULL) { - MCA_COMMON_UCX_VERBOSE(1, "failed to open memory stream for ucx info (%s), " - "ucx is disabled", strerror(errno)); + MCA_COMMON_UCX_VERBOSE(1, + "failed to open memory stream for ucx info (%s), " + "ucx is disabled", + strerror(errno)); goto out_free_device_list; } @@ -271,8 +260,8 @@ opal_common_ucx_support_level(ucp_context_h context) /* Rewind and read transports/devices list from the stream */ fseek(stream, 0, SEEK_SET); - while ((support_level != OPAL_COMMON_UCX_SUPPORT_DEVICE) && - (fgets(line, sizeof(line), stream) != NULL)) { + while ((support_level != OPAL_COMMON_UCX_SUPPORT_DEVICE) + && (fgets(line, sizeof(line), stream) != NULL)) { rsc_tl_name = NULL; ret = sscanf(line, /* "# resource 6 : md 5 dev 4 flags -- rc_verbs/mlx5_0:1" */ @@ -292,19 +281,18 @@ opal_common_ucx_support_level(ucp_context_h context) /* Check if the transport has a match (either positive or negative) */ assert(!(is_any_tl && negate)); if (found_tl != negate) { - if (is_any_device || - opal_common_ucx_check_device(rsc_device_name, device_list)) { + if (is_any_device || opal_common_ucx_check_device(rsc_device_name, device_list)) { MCA_COMMON_UCX_VERBOSE(2, "%s/%s: matched both transport and device list", - rsc_tl_name, rsc_device_name); + rsc_tl_name, rsc_device_name); support_level = OPAL_COMMON_UCX_SUPPORT_DEVICE; } else { MCA_COMMON_UCX_VERBOSE(2, "%s/%s: matched transport list but not device list", - rsc_tl_name, rsc_device_name); + rsc_tl_name, rsc_device_name); support_level = OPAL_COMMON_UCX_SUPPORT_TRANSPORT; } } else { - MCA_COMMON_UCX_VERBOSE(2, "%s/%s: did not match transport list", - rsc_tl_name, rsc_device_name); + MCA_COMMON_UCX_VERBOSE(2, "%s/%s: did not match transport list", rsc_tl_name, + rsc_device_name); } free(rsc_device_name); @@ -332,17 +320,17 @@ void opal_common_ucx_empty_complete_cb(void *request, ucs_status_t status) static void opal_common_ucx_mca_fence_complete_cb(int status, void *fenced) { - *(int*)fenced = 1; + *(int *) fenced = 1; } #if HAVE_DECL_UCM_TEST_EVENTS static ucs_status_t opal_common_ucx_mca_test_external_events(int events) { -#if HAVE_DECL_UCM_TEST_EXTERNAL_EVENTS +# if HAVE_DECL_UCM_TEST_EXTERNAL_EVENTS return ucm_test_external_events(UCM_EVENT_VM_UNMAPPED); -#else +# else return ucm_test_events(UCM_EVENT_VM_UNMAPPED); -#endif +# endif } static void opal_common_ucx_mca_test_events(void) @@ -354,17 +342,18 @@ static void opal_common_ucx_mca_test_events(void) if (!warned) { if (opal_common_ucx.opal_mem_hooks) { suggestion = "Please check OPAL memory events infrastructure."; - status = opal_common_ucx_mca_test_external_events(UCM_EVENT_VM_UNMAPPED); + status = opal_common_ucx_mca_test_external_events(UCM_EVENT_VM_UNMAPPED); } else { suggestion = "Pls try adding --mca opal_common_ucx_opal_mem_hooks 1 " "to mpirun/oshrun command line to resolve this issue."; - status = ucm_test_events(UCM_EVENT_VM_UNMAPPED); + status = ucm_test_events(UCM_EVENT_VM_UNMAPPED); } if (status != UCS_OK) { MCA_COMMON_UCX_WARN("UCX is unable to handle VM_UNMAP event. " "This may cause performance degradation or data " - "corruption. %s", suggestion); + "corruption. %s", + suggestion); warned = 1; } } @@ -380,7 +369,7 @@ void opal_common_ucx_mca_proc_added(void) OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence_nb(int *fenced) { - return PMIx_Fence_nb(NULL, 0, NULL, 0, opal_common_ucx_mca_fence_complete_cb, (void *)fenced); + return PMIx_Fence_nb(NULL, 0, NULL, 0, opal_common_ucx_mca_fence_complete_cb, (void *) fenced); } OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence(ucp_worker_h worker) @@ -388,8 +377,9 @@ OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence(ucp_worker_h worker) volatile int fenced = 0; int ret = OPAL_SUCCESS; - if (OPAL_SUCCESS != (ret = PMIx_Fence_nb(NULL, 0, NULL, 0, - opal_common_ucx_mca_fence_complete_cb, (void*)&fenced))){ + if (OPAL_SUCCESS + != (ret = PMIx_Fence_nb(NULL, 0, NULL, 0, opal_common_ucx_mca_fence_complete_cb, + (void *) &fenced))) { return ret; } @@ -400,7 +390,6 @@ OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence(ucp_worker_h worker) return ret; } - static void opal_common_ucx_wait_all_requests(void **reqs, int count, ucp_worker_h worker) { int i; @@ -412,9 +401,8 @@ static void opal_common_ucx_wait_all_requests(void **reqs, int count, ucp_worker } } -OPAL_DECLSPEC int opal_common_ucx_del_procs_nofence(opal_common_ucx_del_proc_t *procs, - size_t count, size_t my_rank, - size_t max_disconnect, +OPAL_DECLSPEC int opal_common_ucx_del_procs_nofence(opal_common_ucx_del_proc_t *procs, size_t count, + size_t my_rank, size_t max_disconnect, ucp_worker_h worker) { size_t num_reqs; @@ -467,10 +455,10 @@ OPAL_DECLSPEC int opal_common_ucx_del_procs_nofence(opal_common_ucx_del_proc_t * } OPAL_DECLSPEC int opal_common_ucx_del_procs(opal_common_ucx_del_proc_t *procs, size_t count, - size_t my_rank, size_t max_disconnect, ucp_worker_h worker) + size_t my_rank, size_t max_disconnect, + ucp_worker_h worker) { opal_common_ucx_del_procs_nofence(procs, count, my_rank, max_disconnect, worker); return opal_common_ucx_mca_pmix_fence(worker); } - diff --git a/opal/mca/common/ucx/common_ucx.h b/opal/mca/common/ucx/common_ucx.h index a96ba24f2f5..a7312b27f9e 100644 --- a/opal/mca/common/ucx/common_ucx.h +++ b/opal/mca/common/ucx/common_ucx.h @@ -21,80 +21,74 @@ #include +#include "opal/class/opal_list.h" +#include "opal/include/opal/constants.h" #include "opal/mca/mca.h" -#include "opal/util/output.h" #include "opal/runtime/opal_progress.h" -#include "opal/include/opal/constants.h" -#include "opal/class/opal_list.h" +#include "opal/util/output.h" BEGIN_C_DECLS -#define MCA_COMMON_UCX_ENABLE_DEBUG OPAL_ENABLE_DEBUG +#define MCA_COMMON_UCX_ENABLE_DEBUG OPAL_ENABLE_DEBUG #if MCA_COMMON_UCX_ENABLE_DEBUG -# define MCA_COMMON_UCX_MAX_VERBOSE 100 -# define MCA_COMMON_UCX_ASSERT(_x) assert(_x) +# define MCA_COMMON_UCX_MAX_VERBOSE 100 +# define MCA_COMMON_UCX_ASSERT(_x) assert(_x) #else -# define MCA_COMMON_UCX_MAX_VERBOSE 2 -# define MCA_COMMON_UCX_ASSERT(_x) +# define MCA_COMMON_UCX_MAX_VERBOSE 2 +# define MCA_COMMON_UCX_ASSERT(_x) #endif #define MCA_COMMON_UCX_PER_TARGET_OPS_THRESHOLD 1000 -#define MCA_COMMON_UCX_GLOBAL_OPS_THRESHOLD 1000 +#define MCA_COMMON_UCX_GLOBAL_OPS_THRESHOLD 1000 -#define UCX_VERSION(_major, _minor, _build) (((_major) * 100) + (_minor)) +#define UCX_VERSION(_major, _minor, _build) (((_major) *100) + (_minor)) +#define _MCA_COMMON_UCX_QUOTE(_x) #_x +#define MCA_COMMON_UCX_QUOTE(_x) _MCA_COMMON_UCX_QUOTE(_x) -#define _MCA_COMMON_UCX_QUOTE(_x) \ - # _x -#define MCA_COMMON_UCX_QUOTE(_x) \ - _MCA_COMMON_UCX_QUOTE(_x) +#define MCA_COMMON_UCX_ERROR(...) MCA_COMMON_UCX_VERBOSE(0, " Error: " __VA_ARGS__) -#define MCA_COMMON_UCX_ERROR(...) \ - MCA_COMMON_UCX_VERBOSE(0, " Error: " __VA_ARGS__) +#define MCA_COMMON_UCX_WARN(...) MCA_COMMON_UCX_VERBOSE(0, " Warning: " __VA_ARGS__) -#define MCA_COMMON_UCX_WARN(...) \ - MCA_COMMON_UCX_VERBOSE(0, " Warning: " __VA_ARGS__) - -#define MCA_COMMON_UCX_VERBOSE(_level, ... ) \ - if (((_level) <= MCA_COMMON_UCX_MAX_VERBOSE) && \ - ((_level) <= opal_common_ucx.verbose)) { \ - opal_output_verbose(_level, opal_common_ucx.output, \ - __FILE__ ":" MCA_COMMON_UCX_QUOTE(__LINE__) " " \ - __VA_ARGS__); \ +#define MCA_COMMON_UCX_VERBOSE(_level, ...) \ + if (((_level) <= MCA_COMMON_UCX_MAX_VERBOSE) && ((_level) <= opal_common_ucx.verbose)) { \ + opal_output_verbose(_level, opal_common_ucx.output, \ + __FILE__ ":" MCA_COMMON_UCX_QUOTE(__LINE__) " " __VA_ARGS__); \ } /* progress loop to allow call UCX/opal progress */ /* used C99 for-statement variable initialization */ -#define MCA_COMMON_UCX_PROGRESS_LOOP(_worker) \ - for (unsigned iter = 0;; (++iter % opal_common_ucx.progress_iterations) ? \ - (void)ucp_worker_progress(_worker) : opal_progress()) - -#define MCA_COMMON_UCX_WAIT_LOOP(_request, _worker, _msg, _completed) \ - do { \ - ucs_status_t status; \ - /* call UCX progress */ \ - MCA_COMMON_UCX_PROGRESS_LOOP(_worker) { \ - status = opal_common_ucx_request_status(_request); \ - if (UCS_INPROGRESS != status) { \ - _completed; \ - if (OPAL_LIKELY(UCS_OK == status)) { \ - return OPAL_SUCCESS; \ - } else { \ - MCA_COMMON_UCX_VERBOSE(1, "%s failed: %d, %s", \ - (_msg) ? (_msg) : __func__, \ - UCS_PTR_STATUS(_request), \ - ucs_status_string(UCS_PTR_STATUS(_request))); \ - return OPAL_ERROR; \ - } \ - } \ - } \ +#define MCA_COMMON_UCX_PROGRESS_LOOP(_worker) \ + for (unsigned iter = 0;; (++iter % opal_common_ucx.progress_iterations) \ + ? (void) ucp_worker_progress(_worker) \ + : opal_progress()) + +#define MCA_COMMON_UCX_WAIT_LOOP(_request, _worker, _msg, _completed) \ + do { \ + ucs_status_t status; \ + /* call UCX progress */ \ + MCA_COMMON_UCX_PROGRESS_LOOP(_worker) \ + { \ + status = opal_common_ucx_request_status(_request); \ + if (UCS_INPROGRESS != status) { \ + _completed; \ + if (OPAL_LIKELY(UCS_OK == status)) { \ + return OPAL_SUCCESS; \ + } else { \ + MCA_COMMON_UCX_VERBOSE(1, "%s failed: %d, %s", (_msg) ? (_msg) : __func__, \ + UCS_PTR_STATUS(_request), \ + ucs_status_string(UCS_PTR_STATUS(_request))); \ + return OPAL_ERROR; \ + } \ + } \ + } \ } while (0) typedef struct opal_common_ucx_module { - int output; - int verbose; - int progress_iterations; - int registered; + int output; + int verbose; + int progress_iterations; + int registered; bool opal_mem_hooks; char **tls; char **devices; @@ -102,7 +96,7 @@ typedef struct opal_common_ucx_module { typedef struct opal_common_ucx_del_proc { ucp_ep_h ep; - size_t vpid; + size_t vpid; } opal_common_ucx_del_proc_t; typedef enum { @@ -127,48 +121,46 @@ OPAL_DECLSPEC void opal_common_ucx_empty_complete_cb(void *request, ucs_status_t OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence(ucp_worker_h worker); OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence_nb(int *fenced); OPAL_DECLSPEC int opal_common_ucx_del_procs(opal_common_ucx_del_proc_t *procs, size_t count, - size_t my_rank, size_t max_disconnect, ucp_worker_h worker); + size_t my_rank, size_t max_disconnect, + ucp_worker_h worker); OPAL_DECLSPEC int opal_common_ucx_del_procs_nofence(opal_common_ucx_del_proc_t *procs, size_t count, - size_t my_rank, size_t max_disconnect, ucp_worker_h worker); + size_t my_rank, size_t max_disconnect, + ucp_worker_h worker); OPAL_DECLSPEC void opal_common_ucx_mca_var_register(const mca_base_component_t *component); /** * Load an integer value of \c size bytes from \c ptr and cast it to uint64_t. */ -static inline -uint64_t opal_common_ucx_load_uint64(const void *ptr, size_t size) +static inline uint64_t opal_common_ucx_load_uint64(const void *ptr, size_t size) { if (sizeof(uint8_t) == size) { - return *(uint8_t*)ptr; + return *(uint8_t *) ptr; } else if (sizeof(uint16_t) == size) { - return *(uint16_t*)ptr; + return *(uint16_t *) ptr; } else if (sizeof(uint32_t) == size) { - return *(uint32_t*)ptr; + return *(uint32_t *) ptr; } else { - return *(uint64_t*)ptr; + return *(uint64_t *) ptr; } } /** * Cast and store a uint64_t value to a value of \c size bytes pointed to by \c ptr. */ -static inline -void opal_common_ucx_store_uint64(uint64_t value, void *ptr, size_t size) +static inline void opal_common_ucx_store_uint64(uint64_t value, void *ptr, size_t size) { if (sizeof(uint8_t) == size) { - *(uint8_t*)ptr = value; + *(uint8_t *) ptr = value; } else if (sizeof(uint16_t) == size) { - *(uint16_t*)ptr = value; + *(uint16_t *) ptr = value; } else if (sizeof(uint32_t) == size) { - *(uint32_t*)ptr = value; + *(uint32_t *) ptr = value; } else { - *(uint64_t*)ptr = value; + *(uint64_t *) ptr = value; } } - -static inline -ucs_status_t opal_common_ucx_request_status(ucs_status_ptr_t request) +static inline ucs_status_t opal_common_ucx_request_status(ucs_status_ptr_t request) { #if !HAVE_DECL_UCP_REQUEST_CHECK_STATUS ucp_tag_recv_info_t info; @@ -179,25 +171,22 @@ ucs_status_t opal_common_ucx_request_status(ucs_status_ptr_t request) #endif } -static inline -int opal_common_ucx_wait_request(ucs_status_ptr_t request, ucp_worker_h worker, - const char *msg) +static inline int opal_common_ucx_wait_request(ucs_status_ptr_t request, ucp_worker_h worker, + const char *msg) { /* check for request completed or failed */ if (OPAL_LIKELY(UCS_OK == request)) { return OPAL_SUCCESS; } else if (OPAL_UNLIKELY(UCS_PTR_IS_ERR(request))) { MCA_COMMON_UCX_VERBOSE(1, "%s failed: %d, %s", msg ? msg : __func__, - UCS_PTR_STATUS(request), - ucs_status_string(UCS_PTR_STATUS(request))); + UCS_PTR_STATUS(request), ucs_status_string(UCS_PTR_STATUS(request))); return OPAL_ERROR; } MCA_COMMON_UCX_WAIT_LOOP(request, worker, msg, ucp_request_free(request)); } -static inline -int opal_common_ucx_ep_flush(ucp_ep_h ep, ucp_worker_h worker) +static inline int opal_common_ucx_ep_flush(ucp_ep_h ep, ucp_worker_h worker) { #if HAVE_DECL_UCP_EP_FLUSH_NB ucs_status_ptr_t request; @@ -212,8 +201,7 @@ int opal_common_ucx_ep_flush(ucp_ep_h ep, ucp_worker_h worker) #endif } -static inline -int opal_common_ucx_worker_flush(ucp_worker_h worker) +static inline int opal_common_ucx_worker_flush(ucp_worker_h worker) { #if HAVE_DECL_UCP_WORKER_FLUSH_NB ucs_status_ptr_t request; @@ -228,51 +216,43 @@ int opal_common_ucx_worker_flush(ucp_worker_h worker) #endif } -static inline -int opal_common_ucx_atomic_fetch(ucp_ep_h ep, ucp_atomic_fetch_op_t opcode, - uint64_t value, void *result, size_t op_size, - uint64_t remote_addr, ucp_rkey_h rkey, - ucp_worker_h worker) +static inline int opal_common_ucx_atomic_fetch(ucp_ep_h ep, ucp_atomic_fetch_op_t opcode, + uint64_t value, void *result, size_t op_size, + uint64_t remote_addr, ucp_rkey_h rkey, + ucp_worker_h worker) { ucs_status_ptr_t request; - request = ucp_atomic_fetch_nb(ep, opcode, value, result, op_size, - remote_addr, rkey, opal_common_ucx_empty_complete_cb); + request = ucp_atomic_fetch_nb(ep, opcode, value, result, op_size, remote_addr, rkey, + opal_common_ucx_empty_complete_cb); return opal_common_ucx_wait_request(request, worker, "ucp_atomic_fetch_nb"); } -static inline -ucs_status_ptr_t opal_common_ucx_atomic_fetch_nb(ucp_ep_h ep, ucp_atomic_fetch_op_t opcode, - uint64_t value, void *result, size_t op_size, - uint64_t remote_addr, ucp_rkey_h rkey, - ucp_send_callback_t req_handler, - ucp_worker_h worker) +static inline ucs_status_ptr_t +opal_common_ucx_atomic_fetch_nb(ucp_ep_h ep, ucp_atomic_fetch_op_t opcode, uint64_t value, + void *result, size_t op_size, uint64_t remote_addr, ucp_rkey_h rkey, + ucp_send_callback_t req_handler, ucp_worker_h worker) { - return ucp_atomic_fetch_nb(ep, opcode, value, result, op_size, - remote_addr, rkey, req_handler); + return ucp_atomic_fetch_nb(ep, opcode, value, result, op_size, remote_addr, rkey, req_handler); } -static inline -int opal_common_ucx_atomic_cswap(ucp_ep_h ep, uint64_t compare, - uint64_t value, void *result, size_t op_size, - uint64_t remote_addr, ucp_rkey_h rkey, - ucp_worker_h worker) +static inline int opal_common_ucx_atomic_cswap(ucp_ep_h ep, uint64_t compare, uint64_t value, + void *result, size_t op_size, uint64_t remote_addr, + ucp_rkey_h rkey, ucp_worker_h worker) { opal_common_ucx_store_uint64(value, result, op_size); - return opal_common_ucx_atomic_fetch(ep, UCP_ATOMIC_FETCH_OP_CSWAP, compare, result, - op_size, remote_addr, rkey, worker); + return opal_common_ucx_atomic_fetch(ep, UCP_ATOMIC_FETCH_OP_CSWAP, compare, result, op_size, + remote_addr, rkey, worker); } -static inline -ucs_status_ptr_t opal_common_ucx_atomic_cswap_nb(ucp_ep_h ep, uint64_t compare, - uint64_t value, void *result, size_t op_size, - uint64_t remote_addr, ucp_rkey_h rkey, - ucp_send_callback_t req_handler, - ucp_worker_h worker) +static inline ucs_status_ptr_t +opal_common_ucx_atomic_cswap_nb(ucp_ep_h ep, uint64_t compare, uint64_t value, void *result, + size_t op_size, uint64_t remote_addr, ucp_rkey_h rkey, + ucp_send_callback_t req_handler, ucp_worker_h worker) { opal_common_ucx_store_uint64(value, result, op_size); - return opal_common_ucx_atomic_fetch_nb(ep, UCP_ATOMIC_FETCH_OP_CSWAP, compare, result, - op_size, remote_addr, rkey, req_handler, worker); + return opal_common_ucx_atomic_fetch_nb(ep, UCP_ATOMIC_FETCH_OP_CSWAP, compare, result, op_size, + remote_addr, rkey, req_handler, worker); } END_C_DECLS diff --git a/opal/mca/common/ucx/common_ucx_wpool.c b/opal/mca/common/ucx/common_ucx_wpool.c index b93891cdd05..1ea7f40932e 100644 --- a/opal/mca/common/ucx/common_ucx_wpool.c +++ b/opal/mca/common/ucx/common_ucx_wpool.c @@ -3,8 +3,8 @@ #include "common_ucx.h" #include "common_ucx_wpool.h" #include "common_ucx_wpool_int.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/mca/pmix/pmix-internal.h" #include "opal/memoryhooks/memory.h" #include "opal/util/proc.h" @@ -29,11 +29,9 @@ OBJ_CLASS_INSTANCE(_mem_record_t, opal_list_item_t, NULL, NULL); __thread FILE *tls_pf = NULL; __thread int initialized = 0; #endif - -static _ctx_record_t * -_tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx); -static inline _ctx_record_t * -_tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key); + +static _ctx_record_t *_tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx); +static inline _ctx_record_t *_tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key); static void _tlocal_ctx_rec_cleanup(_ctx_record_t *ctx_rec); static void _tlocal_mem_rec_cleanup(_mem_record_t *mem_rec); static void _ctx_rec_destructor(void *arg); @@ -42,8 +40,7 @@ static void _mem_rec_destructor(void *arg); /* ----------------------------------------------------------------------------- * Worker information (winfo) management functionality *----------------------------------------------------------------------------*/ -static opal_common_ucx_winfo_t * -_winfo_create(opal_common_ucx_wpool_t *wpool) +static opal_common_ucx_winfo_t *_winfo_create(opal_common_ucx_wpool_t *wpool) { ucp_worker_params_t worker_params; ucp_worker_h worker; @@ -81,21 +78,19 @@ _winfo_create(opal_common_ucx_wpool_t *wpool) return winfo; } -static void -_winfo_destructor(opal_common_ucx_winfo_t *winfo) +static void _winfo_destructor(opal_common_ucx_winfo_t *winfo) { if (winfo->inflight_req != UCS_OK) { - opal_common_ucx_wait_request_mt(winfo->inflight_req, - "opal_common_ucx_flush"); + opal_common_ucx_wait_request_mt(winfo->inflight_req, "opal_common_ucx_flush"); winfo->inflight_req = UCS_OK; } assert(winfo->global_inflight_ops == 0); - if(winfo->comm_size != 0) { + if (winfo->comm_size != 0) { size_t i; for (i = 0; i < winfo->comm_size; i++) { - if (NULL != winfo->endpoints[i]){ + if (NULL != winfo->endpoints[i]) { ucp_ep_destroy(winfo->endpoints[i]); } assert(winfo->inflight_ops[i] == 0); @@ -114,8 +109,7 @@ _winfo_destructor(opal_common_ucx_winfo_t *winfo) * Worker Pool management functionality *----------------------------------------------------------------------------*/ -OPAL_DECLSPEC opal_common_ucx_wpool_t * -opal_common_ucx_wpool_allocate(void) +OPAL_DECLSPEC opal_common_ucx_wpool_t *opal_common_ucx_wpool_allocate(void) { opal_common_ucx_wpool_t *ptr = calloc(1, sizeof(opal_common_ucx_wpool_t)); ptr->refcnt = 0; @@ -123,19 +117,17 @@ opal_common_ucx_wpool_allocate(void) return ptr; } -OPAL_DECLSPEC void -opal_common_ucx_wpool_free(opal_common_ucx_wpool_t *wpool) +OPAL_DECLSPEC void opal_common_ucx_wpool_free(opal_common_ucx_wpool_t *wpool) { assert(wpool->refcnt == 0); free(wpool); } static int _wpool_list_put(opal_common_ucx_wpool_t *wpool, opal_list_t *list, - opal_common_ucx_winfo_t *winfo); + opal_common_ucx_winfo_t *winfo); -OPAL_DECLSPEC int -opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, - int proc_world_size, bool enable_mt) +OPAL_DECLSPEC int opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, int proc_world_size, + bool enable_mt) { ucp_config_t *config = NULL; ucp_params_t context_params; @@ -159,13 +151,10 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, /* initialize UCP context */ memset(&context_params, 0, sizeof(context_params)); - context_params.field_mask = UCP_PARAM_FIELD_FEATURES | - UCP_PARAM_FIELD_MT_WORKERS_SHARED | - UCP_PARAM_FIELD_ESTIMATED_NUM_EPS | - UCP_PARAM_FIELD_REQUEST_INIT | - UCP_PARAM_FIELD_REQUEST_SIZE; - context_params.features = UCP_FEATURE_RMA | UCP_FEATURE_AMO32 | - UCP_FEATURE_AMO64; + context_params.field_mask = UCP_PARAM_FIELD_FEATURES | UCP_PARAM_FIELD_MT_WORKERS_SHARED + | UCP_PARAM_FIELD_ESTIMATED_NUM_EPS | UCP_PARAM_FIELD_REQUEST_INIT + | UCP_PARAM_FIELD_REQUEST_SIZE; + context_params.features = UCP_FEATURE_RMA | UCP_FEATURE_AMO32 | UCP_FEATURE_AMO64; context_params.mt_workers_shared = (enable_mt ? 1 : 0); context_params.estimated_num_eps = proc_world_size; context_params.request_init = opal_common_ucx_req_init; @@ -173,7 +162,7 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, #if HAVE_DECL_UCP_PARAM_FIELD_ESTIMATED_NUM_PPN context_params.estimated_num_ppn = opal_process_info.num_local_peers + 1; - context_params.field_mask |= UCP_PARAM_FIELD_ESTIMATED_NUM_PPN; + context_params.field_mask |= UCP_PARAM_FIELD_ESTIMATED_NUM_PPN; #endif status = ucp_init(&context_params, config, &wpool->ucp_ctx); @@ -197,8 +186,8 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, wpool->dflt_winfo = winfo; OBJ_RETAIN(wpool->dflt_winfo); - status = ucp_worker_get_address(wpool->dflt_winfo->worker, - &wpool->recv_waddr, &wpool->recv_waddr_len); + status = ucp_worker_get_address(wpool->dflt_winfo->worker, &wpool->recv_waddr, + &wpool->recv_waddr_len); if (status != UCS_OK) { MCA_COMMON_UCX_VERBOSE(1, "ucp_worker_get_address failed: %d", status); rc = OPAL_ERROR; @@ -218,11 +207,11 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, OBJ_RELEASE(winfo); OBJ_RELEASE(wpool->dflt_winfo); wpool->dflt_winfo = NULL; - err_worker_create: +err_worker_create: OBJ_DESTRUCT(&wpool->idle_workers); OBJ_DESTRUCT(&wpool->active_workers); ucp_cleanup(wpool->ucp_ctx); - err_ucp_init: +err_ucp_init: return rc; } @@ -241,8 +230,7 @@ void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool) /* Go over the list, free idle list items */ if (!opal_list_is_empty(&wpool->idle_workers)) { opal_common_ucx_winfo_t *winfo, *next; - OPAL_LIST_FOREACH_SAFE(winfo, next, &wpool->idle_workers, - opal_common_ucx_winfo_t) { + OPAL_LIST_FOREACH_SAFE (winfo, next, &wpool->idle_workers, opal_common_ucx_winfo_t) { opal_list_remove_item(&wpool->idle_workers, &winfo->super); OBJ_RELEASE(winfo); } @@ -253,8 +241,7 @@ void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool) * because opal_common_ucx_wpool_finalize is being called. */ if (!opal_list_is_empty(&wpool->active_workers)) { opal_common_ucx_winfo_t *winfo, *next; - OPAL_LIST_FOREACH_SAFE(winfo, next, &wpool->active_workers, - opal_common_ucx_winfo_t) { + OPAL_LIST_FOREACH_SAFE (winfo, next, &wpool->active_workers, opal_common_ucx_winfo_t) { opal_list_remove_item(&wpool->active_workers, &winfo->super); OBJ_RELEASE(winfo); } @@ -269,8 +256,7 @@ void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool) return; } -OPAL_DECLSPEC int -opal_common_ucx_wpool_progress(opal_common_ucx_wpool_t *wpool) +OPAL_DECLSPEC int opal_common_ucx_wpool_progress(opal_common_ucx_wpool_t *wpool) { opal_common_ucx_winfo_t *winfo = NULL, *next = NULL; int completed = 0, progressed = 0; @@ -283,8 +269,7 @@ opal_common_ucx_wpool_progress(opal_common_ucx_wpool_t *wpool) } bool progress_dflt_worker = true; - OPAL_LIST_FOREACH_SAFE(winfo, next, &wpool->active_workers, - opal_common_ucx_winfo_t) { + OPAL_LIST_FOREACH_SAFE (winfo, next, &wpool->active_workers, opal_common_ucx_winfo_t) { if (0 != opal_mutex_trylock(&winfo->mutex)) { continue; } @@ -308,29 +293,26 @@ opal_common_ucx_wpool_progress(opal_common_ucx_wpool_t *wpool) return completed; } -static int -_wpool_list_put(opal_common_ucx_wpool_t *wpool, opal_list_t *list, - opal_common_ucx_winfo_t *winfo) +static int _wpool_list_put(opal_common_ucx_wpool_t *wpool, opal_list_t *list, + opal_common_ucx_winfo_t *winfo) { opal_list_append(list, &winfo->super); return OPAL_SUCCESS; } -static opal_common_ucx_winfo_t* -_wpool_list_get(opal_common_ucx_wpool_t *wpool, opal_list_t *list) +static opal_common_ucx_winfo_t *_wpool_list_get(opal_common_ucx_wpool_t *wpool, opal_list_t *list) { opal_common_ucx_winfo_t *winfo = NULL; if (!opal_list_is_empty(list)) { - winfo = (opal_common_ucx_winfo_t *)opal_list_get_first(list); + winfo = (opal_common_ucx_winfo_t *) opal_list_get_first(list); opal_list_remove_item(list, &winfo->super); } return winfo; } -static opal_common_ucx_winfo_t * -_wpool_get_winfo(opal_common_ucx_wpool_t *wpool, size_t comm_size) +static opal_common_ucx_winfo_t *_wpool_get_winfo(opal_common_ucx_wpool_t *wpool, size_t comm_size) { opal_common_ucx_winfo_t *winfo; opal_mutex_lock(&wpool->mutex); @@ -356,14 +338,13 @@ _wpool_get_winfo(opal_common_ucx_wpool_t *wpool, size_t comm_size) return winfo; } -static void -_wpool_put_winfo(opal_common_ucx_wpool_t *wpool, opal_common_ucx_winfo_t *winfo) +static void _wpool_put_winfo(opal_common_ucx_wpool_t *wpool, opal_common_ucx_winfo_t *winfo) { opal_mutex_lock(&wpool->mutex); opal_list_remove_item(&wpool->active_workers, &winfo->super); opal_list_prepend(&wpool->idle_workers, &winfo->super); opal_mutex_unlock(&wpool->mutex); - + return; } @@ -371,11 +352,10 @@ _wpool_put_winfo(opal_common_ucx_wpool_t *wpool, opal_common_ucx_winfo_t *winfo) * Worker Pool Communication context management functionality *----------------------------------------------------------------------------*/ -OPAL_DECLSPEC int -opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size, - opal_common_ucx_exchange_func_t exchange_func, - void *exchange_metadata, - opal_common_ucx_ctx_t **ctx_ptr) +OPAL_DECLSPEC int opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size, + opal_common_ucx_exchange_func_t exchange_func, + void *exchange_metadata, + opal_common_ucx_ctx_t **ctx_ptr) { opal_common_ucx_ctx_t *ctx = calloc(1, sizeof(*ctx)); int ret = OPAL_SUCCESS; @@ -388,8 +368,7 @@ opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size, ctx->recv_worker_addrs = NULL; ctx->recv_worker_displs = NULL; - ret = exchange_func(wpool->recv_waddr, wpool->recv_waddr_len, - &ctx->recv_worker_addrs, + ret = exchange_func(wpool->recv_waddr, wpool->recv_waddr_len, &ctx->recv_worker_addrs, &ctx->recv_worker_displs, exchange_metadata); if (ret != OPAL_SUCCESS) { goto error; @@ -408,8 +387,7 @@ opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size, return ret; } -OPAL_DECLSPEC void -opal_common_ucx_wpctx_release(opal_common_ucx_ctx_t *ctx) +OPAL_DECLSPEC void opal_common_ucx_wpctx_release(opal_common_ucx_ctx_t *ctx) { _ctx_record_t *ctx_rec = NULL, *next; @@ -420,8 +398,8 @@ opal_common_ucx_wpctx_release(opal_common_ucx_ctx_t *ctx) OBJ_DESTRUCT(&ctx->tls_key); /* loop through list of records */ - OPAL_LIST_FOREACH_SAFE(ctx_rec, next, &ctx->ctx_records, _ctx_record_t) { - _tlocal_ctx_rec_cleanup(ctx_rec); + OPAL_LIST_FOREACH_SAFE (ctx_rec, next, &ctx->ctx_records, _ctx_record_t) { + _tlocal_ctx_rec_cleanup(ctx_rec); } free(ctx->recv_worker_addrs); @@ -438,14 +416,11 @@ opal_common_ucx_wpctx_release(opal_common_ucx_ctx_t *ctx) *----------------------------------------------------------------------------*/ OPAL_DECLSPEC -int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, - void **mem_base, size_t mem_size, - opal_common_ucx_mem_type_t mem_type, - opal_common_ucx_exchange_func_t exchange_func, - void *exchange_metadata, - char **my_mem_addr, - int *my_mem_addr_size, - opal_common_ucx_wpmem_t **mem_ptr) +int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, void **mem_base, size_t mem_size, + opal_common_ucx_mem_type_t mem_type, + opal_common_ucx_exchange_func_t exchange_func, + void *exchange_metadata, char **my_mem_addr, int *my_mem_addr_size, + opal_common_ucx_wpmem_t **mem_ptr) { opal_common_ucx_wpmem_t *mem = calloc(1, sizeof(*mem)); void *rkey_addr = NULL; @@ -456,27 +431,25 @@ int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, mem->ctx = ctx; mem->mem_addrs = NULL; mem->mem_displs = NULL; - + OBJ_CONSTRUCT(&mem->mutex, opal_mutex_t); OBJ_CONSTRUCT(&mem->mem_records, opal_list_t); - ret = _comm_ucx_wpmem_map(ctx->wpool, mem_base, mem_size, &mem->memh, - mem_type); + ret = _comm_ucx_wpmem_map(ctx->wpool, mem_base, mem_size, &mem->memh, mem_type); if (ret != OPAL_SUCCESS) { MCA_COMMON_UCX_VERBOSE(1, "_comm_ucx_mem_map failed: %d", ret); goto error_mem_map; } - status = ucp_rkey_pack(ctx->wpool->ucp_ctx, mem->memh, - &rkey_addr, &rkey_addr_len); + status = ucp_rkey_pack(ctx->wpool->ucp_ctx, mem->memh, &rkey_addr, &rkey_addr_len); if (status != UCS_OK) { MCA_COMMON_UCX_VERBOSE(1, "ucp_rkey_pack failed: %d", status); ret = OPAL_ERROR; goto error_rkey_pack; } - ret = exchange_func(rkey_addr, rkey_addr_len, - &mem->mem_addrs, &mem->mem_displs, exchange_metadata); + ret = exchange_func(rkey_addr, rkey_addr_len, &mem->mem_addrs, &mem->mem_displs, + exchange_metadata); if (ret != OPAL_SUCCESS) { goto error_rkey_pack; } @@ -490,17 +463,16 @@ int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, return ret; - error_rkey_pack: +error_rkey_pack: ucp_mem_unmap(ctx->wpool->ucp_ctx, mem->memh); - error_mem_map: +error_mem_map: free(mem); (*mem_ptr) = NULL; return ret; } -static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, - void **base, size_t size, ucp_mem_h *memh_ptr, - opal_common_ucx_mem_type_t mem_type) +static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, void **base, size_t size, + ucp_mem_h *memh_ptr, opal_common_ucx_mem_type_t mem_type) { ucp_mem_map_params_t mem_params; ucp_mem_attr_t mem_attrs; @@ -508,9 +480,8 @@ static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, int ret = OPAL_SUCCESS; memset(&mem_params, 0, sizeof(ucp_mem_map_params_t)); - mem_params.field_mask = UCP_MEM_MAP_PARAM_FIELD_ADDRESS | - UCP_MEM_MAP_PARAM_FIELD_LENGTH | - UCP_MEM_MAP_PARAM_FIELD_FLAGS; + mem_params.field_mask = UCP_MEM_MAP_PARAM_FIELD_ADDRESS | UCP_MEM_MAP_PARAM_FIELD_LENGTH + | UCP_MEM_MAP_PARAM_FIELD_FLAGS; mem_params.length = size; if (mem_type == OPAL_COMMON_UCX_MEM_ALLOCATE_MAP) { mem_params.address = NULL; @@ -542,7 +513,7 @@ static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, } return ret; - error: +error: ucp_mem_unmap(wpool->ucp_ctx, (*memh_ptr)); return ret; } @@ -554,14 +525,14 @@ void opal_common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem) if (NULL == mem) { return; } - + OBJ_DESTRUCT(&mem->tls_key); /* Loop through list of records */ - OPAL_LIST_FOREACH_SAFE(mem_rec, next, &mem->mem_records, _mem_record_t) { + OPAL_LIST_FOREACH_SAFE (mem_rec, next, &mem->mem_records, _mem_record_t) { _tlocal_mem_rec_cleanup(mem_rec); } - + OBJ_DESTRUCT(&mem->mem_records); free(mem->mem_addrs); @@ -571,10 +542,10 @@ void opal_common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem) free(mem); } -static inline _ctx_record_t * -_tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key){ +static inline _ctx_record_t *_tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key) +{ _ctx_record_t *ctx_rec = NULL; - int rc = opal_tsd_tracked_key_get(&tls_key, (void**)&ctx_rec); + int rc = opal_tsd_tracked_key_get(&tls_key, (void **) &ctx_rec); if (OPAL_SUCCESS != rc) { return NULL; @@ -583,14 +554,14 @@ _tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key){ return ctx_rec; } -static void _ctx_rec_destructor(void *arg) { - _tlocal_ctx_rec_cleanup ((_ctx_record_t *) arg); +static void _ctx_rec_destructor(void *arg) +{ + _tlocal_ctx_rec_cleanup((_ctx_record_t *) arg); return; } /* Thread local storage destructor, also called from wpool_ctx release */ -static void -_tlocal_ctx_rec_cleanup(_ctx_record_t *ctx_rec) +static void _tlocal_ctx_rec_cleanup(_ctx_record_t *ctx_rec) { if (NULL == ctx_rec) { return; @@ -612,11 +583,10 @@ _tlocal_ctx_rec_cleanup(_ctx_record_t *ctx_rec) return; } -static _ctx_record_t * -_tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx) +static _ctx_record_t *_tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx) { int rc; - + _ctx_record_t *ctx_rec = OBJ_NEW(_ctx_record_t); if (!ctx_rec) { MCA_COMMON_UCX_ERROR("Failed to allocate new ctx_rec"); @@ -639,7 +609,7 @@ _tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx) rc = opal_tsd_tracked_key_set(&ctx->tls_key, ctx_rec); if (OPAL_SUCCESS != rc) { MCA_COMMON_UCX_ERROR("Failed to set ctx_rec tls key"); - goto error3; + goto error3; } /* All good - return the record */ @@ -669,7 +639,7 @@ static int _tlocal_ctx_connect(_ctx_record_t *ctx_rec, int target) opal_mutex_lock(&winfo->mutex); displ = gctx->recv_worker_displs[target]; - ep_params.address = (ucp_address_t *)&(gctx->recv_worker_addrs[displ]); + ep_params.address = (ucp_address_t *) &(gctx->recv_worker_addrs[displ]); status = ucp_ep_create(winfo->worker, &ep_params, &winfo->endpoints[target]); if (status != UCS_OK) { opal_mutex_unlock(&winfo->mutex); @@ -681,14 +651,13 @@ static int _tlocal_ctx_connect(_ctx_record_t *ctx_rec, int target) return OPAL_SUCCESS; } -static void -_mem_rec_destructor(void * arg) { - _tlocal_mem_rec_cleanup ((_mem_record_t *) arg); +static void _mem_rec_destructor(void *arg) +{ + _tlocal_mem_rec_cleanup((_mem_record_t *) arg); return; } -static void -_tlocal_mem_rec_cleanup(_mem_record_t *mem_rec) +static void _tlocal_mem_rec_cleanup(_mem_record_t *mem_rec) { size_t i; if (NULL == mem_rec) { @@ -696,7 +665,7 @@ _tlocal_mem_rec_cleanup(_mem_record_t *mem_rec) } opal_mutex_lock(&mem_rec->winfo->mutex); - for(i = 0; i < mem_rec->gmem->ctx->comm_size; i++) { + for (i = 0; i < mem_rec->gmem->ctx->comm_size; i++) { if (mem_rec->rkeys[i]) { ucp_rkey_destroy(mem_rec->rkeys[i]); } @@ -726,7 +695,7 @@ static _mem_record_t *_tlocal_add_mem_rec(opal_common_ucx_wpmem_t *mem, _ctx_rec mem_rec->ctx_rec = ctx_rec; mem_rec->winfo = ctx_rec->winfo; mem_rec->rkeys = calloc(mem->ctx->comm_size, sizeof(*mem_rec->rkeys)); - + rc = opal_tsd_tracked_key_set(&mem->tls_key, mem_rec); if (OPAL_SUCCESS != rc) { return NULL; @@ -739,16 +708,14 @@ static _mem_record_t *_tlocal_add_mem_rec(opal_common_ucx_wpmem_t *mem, _ctx_rec return mem_rec; } -static int -_tlocal_mem_create_rkey(_mem_record_t *mem_rec, ucp_ep_h ep, int target) +static int _tlocal_mem_create_rkey(_mem_record_t *mem_rec, ucp_ep_h ep, int target) { opal_common_ucx_wpmem_t *gmem = mem_rec->gmem; int displ = gmem->mem_displs[target]; ucs_status_t status; opal_mutex_lock(&mem_rec->winfo->mutex); - status = ucp_ep_rkey_unpack(ep, &gmem->mem_addrs[displ], - &mem_rec->rkeys[target]); + status = ucp_ep_rkey_unpack(ep, &gmem->mem_addrs[displ], &mem_rec->rkeys[target]); opal_mutex_unlock(&mem_rec->winfo->mutex); if (status != UCS_OK) { MCA_COMMON_UCX_VERBOSE(1, "ucp_ep_rkey_unpack failed: %d", status); @@ -759,8 +726,7 @@ _tlocal_mem_create_rkey(_mem_record_t *mem_rec, ucp_ep_h ep, int target) } /* Get the TLS in case of slow path (not everything has been yet initialized */ -OPAL_DECLSPEC int -opal_common_ucx_tlocal_fetch_spath(opal_common_ucx_wpmem_t *mem, int target) +OPAL_DECLSPEC int opal_common_ucx_tlocal_fetch_spath(opal_common_ucx_wpmem_t *mem, int target) { _ctx_record_t *ctx_rec = NULL; _mem_record_t *mem_rec = NULL; @@ -801,11 +767,10 @@ opal_common_ucx_tlocal_fetch_spath(opal_common_ucx_wpmem_t *mem, int target) return OPAL_SUCCESS; } -OPAL_DECLSPEC int -opal_common_ucx_winfo_flush(opal_common_ucx_winfo_t *winfo, int target, - opal_common_ucx_flush_type_t type, - opal_common_ucx_flush_scope_t scope, - ucs_status_ptr_t *req_ptr) +OPAL_DECLSPEC int opal_common_ucx_winfo_flush(opal_common_ucx_winfo_t *winfo, int target, + opal_common_ucx_flush_type_t type, + opal_common_ucx_flush_scope_t scope, + ucs_status_ptr_t *req_ptr) { ucs_status_ptr_t req; ucs_status_t status = UCS_OK; @@ -818,10 +783,10 @@ opal_common_ucx_winfo_flush(opal_common_ucx_winfo_t *winfo, int target, req = ucp_worker_flush_nb(winfo->worker, 0, opal_common_ucx_empty_complete_cb); } if (UCS_PTR_IS_PTR(req)) { - ((opal_common_ucx_request_t *)req)->winfo = winfo; + ((opal_common_ucx_request_t *) req)->winfo = winfo; } - if(OPAL_COMMON_UCX_FLUSH_B) { + if (OPAL_COMMON_UCX_FLUSH_B) { rc = opal_common_ucx_wait_request_mt(req, "ucp_ep_flush_nb"); } else { *req_ptr = req; @@ -844,10 +809,8 @@ opal_common_ucx_winfo_flush(opal_common_ucx_winfo_t *winfo, int target, return rc; } -OPAL_DECLSPEC int -opal_common_ucx_wpmem_flush(opal_common_ucx_wpmem_t *mem, - opal_common_ucx_flush_scope_t scope, - int target) +OPAL_DECLSPEC int opal_common_ucx_wpmem_flush(opal_common_ucx_wpmem_t *mem, + opal_common_ucx_flush_scope_t scope, int target) { _ctx_record_t *ctx_rec; opal_common_ucx_ctx_t *ctx; @@ -860,15 +823,13 @@ opal_common_ucx_wpmem_flush(opal_common_ucx_wpmem_t *mem, ctx = mem->ctx; opal_mutex_lock(&ctx->mutex); - OPAL_LIST_FOREACH(ctx_rec, &ctx->ctx_records, _ctx_record_t) { + OPAL_LIST_FOREACH (ctx_rec, &ctx->ctx_records, _ctx_record_t) { opal_common_ucx_winfo_t *winfo = ctx_rec->winfo; - if ((scope == OPAL_COMMON_UCX_SCOPE_EP) && - (NULL == winfo->endpoints[target])) { + if ((scope == OPAL_COMMON_UCX_SCOPE_EP) && (NULL == winfo->endpoints[target])) { continue; } opal_mutex_lock(&winfo->mutex); - rc = opal_common_ucx_winfo_flush(winfo, target, OPAL_COMMON_UCX_FLUSH_B, - scope, NULL); + rc = opal_common_ucx_winfo_flush(winfo, target, OPAL_COMMON_UCX_FLUSH_B, scope, NULL); switch (scope) { case OPAL_COMMON_UCX_SCOPE_WORKER: winfo->global_inflight_ops = 0; @@ -882,8 +843,7 @@ opal_common_ucx_wpmem_flush(opal_common_ucx_wpmem_t *mem, opal_mutex_unlock(&winfo->mutex); if (rc != OPAL_SUCCESS) { - MCA_COMMON_UCX_ERROR("opal_common_ucx_flush failed: %d", - rc); + MCA_COMMON_UCX_ERROR("opal_common_ucx_flush failed: %d", rc); rc = OPAL_ERROR; } } @@ -892,23 +852,23 @@ opal_common_ucx_wpmem_flush(opal_common_ucx_wpmem_t *mem, return rc; } -OPAL_DECLSPEC int -opal_common_ucx_wpmem_fence(opal_common_ucx_wpmem_t *mem) { +OPAL_DECLSPEC int opal_common_ucx_wpmem_fence(opal_common_ucx_wpmem_t *mem) +{ /* TODO */ return OPAL_SUCCESS; } -OPAL_DECLSPEC void -opal_common_ucx_req_init(void *request) { - opal_common_ucx_request_t *req = (opal_common_ucx_request_t *)request; +OPAL_DECLSPEC void opal_common_ucx_req_init(void *request) +{ + opal_common_ucx_request_t *req = (opal_common_ucx_request_t *) request; req->ext_req = NULL; req->ext_cb = NULL; req->winfo = NULL; } -OPAL_DECLSPEC void -opal_common_ucx_req_completion(void *request, ucs_status_t status) { - opal_common_ucx_request_t *req = (opal_common_ucx_request_t *)request; +OPAL_DECLSPEC void opal_common_ucx_req_completion(void *request, ucs_status_t status) +{ + opal_common_ucx_request_t *req = (opal_common_ucx_request_t *) request; if (req->ext_cb != NULL) { (*req->ext_cb)(req->ext_req); } diff --git a/opal/mca/common/ucx/common_ucx_wpool.h b/opal/mca/common/ucx/common_ucx_wpool.h index ce5ef4d3b4a..5d9f271bbb3 100644 --- a/opal/mca/common/ucx/common_ucx_wpool.h +++ b/opal/mca/common/ucx/common_ucx_wpool.h @@ -12,7 +12,6 @@ #ifndef COMMON_UCX_WPOOL_H #define COMMON_UCX_WPOOL_H - #include "opal_config.h" #include "common_ucx.h" @@ -21,12 +20,12 @@ #include -#include "opal/mca/mca.h" -#include "opal/util/output.h" -#include "opal/runtime/opal_progress.h" -#include "opal/include/opal/constants.h" #include "opal/class/opal_list.h" +#include "opal/include/opal/constants.h" +#include "opal/mca/mca.h" #include "opal/mca/threads/tsd.h" +#include "opal/runtime/opal_progress.h" +#include "opal/util/output.h" BEGIN_C_DECLS @@ -143,10 +142,7 @@ typedef struct { opal_common_ucx_winfo_t *winfo; } opal_common_ucx_request_t; -typedef enum { - OPAL_COMMON_UCX_PUT, - OPAL_COMMON_UCX_GET -} opal_common_ucx_op_t; +typedef enum { OPAL_COMMON_UCX_PUT, OPAL_COMMON_UCX_GET } opal_common_ucx_op_t; typedef enum { OPAL_COMMON_UCX_SCOPE_EP, @@ -168,7 +164,7 @@ typedef struct { opal_list_item_t super; opal_common_ucx_ctx_t *gctx; opal_common_ucx_winfo_t *winfo; -} _ctx_record_t; +} _ctx_record_t; OBJ_CLASS_DECLARATION(_ctx_record_t); typedef struct { @@ -180,23 +176,22 @@ typedef struct { } _mem_record_t; OBJ_CLASS_DECLARATION(_mem_record_t); -typedef int (*opal_common_ucx_exchange_func_t)(void *my_info, size_t my_info_len, - char **recv_info, int **disps, - void *metadata); +typedef int (*opal_common_ucx_exchange_func_t)(void *my_info, size_t my_info_len, char **recv_info, + int **disps, void *metadata); /* Manage Worker Pool (wpool) */ -OPAL_DECLSPEC opal_common_ucx_wpool_t * opal_common_ucx_wpool_allocate(void); +OPAL_DECLSPEC opal_common_ucx_wpool_t *opal_common_ucx_wpool_allocate(void); OPAL_DECLSPEC void opal_common_ucx_wpool_free(opal_common_ucx_wpool_t *wpool); -OPAL_DECLSPEC int opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, - int proc_world_size, bool enable_mt); +OPAL_DECLSPEC int opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool, int proc_world_size, + bool enable_mt); OPAL_DECLSPEC void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool); OPAL_DECLSPEC int opal_common_ucx_wpool_progress(opal_common_ucx_wpool_t *wpool); /* Manage Communication context */ OPAL_DECLSPEC int opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size, - opal_common_ucx_exchange_func_t exchange_func, - void *exchange_metadata, - opal_common_ucx_ctx_t **ctx_ptr); + opal_common_ucx_exchange_func_t exchange_func, + void *exchange_metadata, + opal_common_ucx_ctx_t **ctx_ptr); OPAL_DECLSPEC void opal_common_ucx_wpctx_release(opal_common_ucx_ctx_t *ctx); /* request init / completion */ @@ -205,29 +200,27 @@ OPAL_DECLSPEC void opal_common_ucx_req_completion(void *request, ucs_status_t st /* Managing thread local storage */ OPAL_DECLSPEC int opal_common_ucx_tlocal_fetch_spath(opal_common_ucx_wpmem_t *mem, int target); -static inline int -opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target, - ucp_ep_h *_ep, ucp_rkey_h *_rkey, - opal_common_ucx_winfo_t **_winfo) +static inline int opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target, + ucp_ep_h *_ep, ucp_rkey_h *_rkey, + opal_common_ucx_winfo_t **_winfo) { _mem_record_t *mem_rec = NULL; int is_ready; int rc = OPAL_SUCCESS; /* First check the fast-path */ - rc = opal_tsd_tracked_key_get(&mem->tls_key, (void**)&mem_rec); + rc = opal_tsd_tracked_key_get(&mem->tls_key, (void **) &mem_rec); if (OPAL_SUCCESS != rc) { return rc; } - is_ready = mem_rec && (mem_rec->winfo->endpoints[target]) && - (NULL != mem_rec->rkeys[target]); + is_ready = mem_rec && (mem_rec->winfo->endpoints[target]) && (NULL != mem_rec->rkeys[target]); MCA_COMMON_UCX_ASSERT((NULL == mem_rec) || (NULL != mem_rec->winfo)); if (OPAL_UNLIKELY(!is_ready)) { rc = opal_common_ucx_tlocal_fetch_spath(mem, target); if (OPAL_SUCCESS != rc) { return rc; } - rc = opal_tsd_tracked_key_get(&mem->tls_key, (void**)&mem_rec); + rc = opal_tsd_tracked_key_get(&mem->tls_key, (void **) &mem_rec); if (OPAL_SUCCESS != rc) { return rc; } @@ -244,19 +237,16 @@ opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target, } /* Manage & operations on the Memory registrations */ -OPAL_DECLSPEC int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, - void **mem_base, size_t mem_size, - opal_common_ucx_mem_type_t mem_type, - opal_common_ucx_exchange_func_t exchange_func, - void *exchange_metadata, - char **my_mem_addr, +OPAL_DECLSPEC int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx, void **mem_base, + size_t mem_size, opal_common_ucx_mem_type_t mem_type, + opal_common_ucx_exchange_func_t exchange_func, + void *exchange_metadata, char **my_mem_addr, int *my_mem_addr_size, - opal_common_ucx_wpmem_t **mem_ptr); + opal_common_ucx_wpmem_t **mem_ptr); OPAL_DECLSPEC void opal_common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem); OPAL_DECLSPEC int opal_common_ucx_wpmem_flush(opal_common_ucx_wpmem_t *mem, - opal_common_ucx_flush_scope_t scope, - int target); + opal_common_ucx_flush_scope_t scope, int target); OPAL_DECLSPEC int opal_common_ucx_wpmem_fence(opal_common_ucx_wpmem_t *mem); OPAL_DECLSPEC int opal_common_ucx_winfo_flush(opal_common_ucx_winfo_t *winfo, int target, @@ -264,8 +254,7 @@ OPAL_DECLSPEC int opal_common_ucx_winfo_flush(opal_common_ucx_winfo_t *winfo, in opal_common_ucx_flush_scope_t scope, ucs_status_ptr_t *req_ptr); -static inline -int opal_common_ucx_wait_request_mt(ucs_status_ptr_t request, const char *msg) +static inline int opal_common_ucx_wait_request_mt(ucs_status_ptr_t request, const char *msg) { ucs_status_t status; int ctr = 0, ret = 0; @@ -276,12 +265,11 @@ int opal_common_ucx_wait_request_mt(ucs_status_ptr_t request, const char *msg) return OPAL_SUCCESS; } else if (OPAL_UNLIKELY(UCS_PTR_IS_ERR(request))) { MCA_COMMON_UCX_VERBOSE(1, "%s failed: %d, %s", msg ? msg : __func__, - UCS_PTR_STATUS(request), - ucs_status_string(UCS_PTR_STATUS(request))); + UCS_PTR_STATUS(request), ucs_status_string(UCS_PTR_STATUS(request))); return OPAL_ERROR; } - winfo = ((opal_common_ucx_request_t *)request)->winfo; + winfo = ((opal_common_ucx_request_t *) request)->winfo; assert(winfo != NULL); do { @@ -293,12 +281,11 @@ int opal_common_ucx_wait_request_mt(ucs_status_ptr_t request, const char *msg) if (status != UCS_INPROGRESS) { ucp_request_free(request); if (OPAL_UNLIKELY(UCS_OK != status)) { - MCA_COMMON_UCX_VERBOSE(1, "%s failed: %d, %s", - msg ? msg : __func__, + MCA_COMMON_UCX_VERBOSE(1, "%s failed: %d, %s", msg ? msg : __func__, UCS_PTR_STATUS(request), ucs_status_string(UCS_PTR_STATUS(request))); - opal_mutex_unlock(&winfo->mutex); - return OPAL_ERROR; + opal_mutex_unlock(&winfo->mutex); + return OPAL_ERROR; } break; } @@ -311,22 +298,21 @@ int opal_common_ucx_wait_request_mt(ucs_status_ptr_t request, const char *msg) return OPAL_SUCCESS; } -static inline int _periodical_flush_nb(opal_common_ucx_wpmem_t *mem, - opal_common_ucx_winfo_t *winfo, - int target) { +static inline int _periodical_flush_nb(opal_common_ucx_wpmem_t *mem, opal_common_ucx_winfo_t *winfo, + int target) +{ int rc = OPAL_SUCCESS; winfo->inflight_ops[target]++; winfo->global_inflight_ops++; - if (OPAL_UNLIKELY(winfo->inflight_ops[target] >= MCA_COMMON_UCX_PER_TARGET_OPS_THRESHOLD) || - OPAL_UNLIKELY(winfo->global_inflight_ops >= MCA_COMMON_UCX_GLOBAL_OPS_THRESHOLD)) { + if (OPAL_UNLIKELY(winfo->inflight_ops[target] >= MCA_COMMON_UCX_PER_TARGET_OPS_THRESHOLD) + || OPAL_UNLIKELY(winfo->global_inflight_ops >= MCA_COMMON_UCX_GLOBAL_OPS_THRESHOLD)) { opal_common_ucx_flush_scope_t scope; if (winfo->inflight_req != UCS_OK) { - rc = opal_common_ucx_wait_request_mt(winfo->inflight_req, - "opal_common_ucx_flush_nb"); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + rc = opal_common_ucx_wait_request_mt(winfo->inflight_req, "opal_common_ucx_flush_nb"); + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "opal_common_ucx_wait_request failed: %d", rc); return rc; } @@ -343,9 +329,9 @@ static inline int _periodical_flush_nb(opal_common_ucx_wpmem_t *mem, winfo->inflight_ops[target] = 0; } - rc = opal_common_ucx_winfo_flush(winfo, target, OPAL_COMMON_UCX_FLUSH_NB_PREFERRED, - scope, &winfo->inflight_req); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + rc = opal_common_ucx_winfo_flush(winfo, target, OPAL_COMMON_UCX_FLUSH_NB_PREFERRED, scope, + &winfo->inflight_req); + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "opal_common_ucx_flush failed: %d", rc); return rc; } @@ -358,10 +344,9 @@ static inline int _periodical_flush_nb(opal_common_ucx_wpmem_t *mem, return rc; } -static inline int -opal_common_ucx_wpmem_putget(opal_common_ucx_wpmem_t *mem, opal_common_ucx_op_t op, - int target, void *buffer, size_t len, - uint64_t rem_addr) +static inline int opal_common_ucx_wpmem_putget(opal_common_ucx_wpmem_t *mem, + opal_common_ucx_op_t op, int target, void *buffer, + size_t len, uint64_t rem_addr) { ucp_ep_h ep; ucp_rkey_h rkey; @@ -371,20 +356,20 @@ opal_common_ucx_wpmem_putget(opal_common_ucx_wpmem_t *mem, opal_common_ucx_op_t char *called_func = ""; rc = opal_common_ucx_tlocal_fetch(mem, target, &ep, &rkey, &winfo); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "tlocal_fetch failed: %d", rc); return rc; } /* Perform the operation */ opal_mutex_lock(&winfo->mutex); - switch(op){ + switch (op) { case OPAL_COMMON_UCX_PUT: - status = ucp_put_nbi(ep, buffer,len, rem_addr, rkey); + status = ucp_put_nbi(ep, buffer, len, rem_addr, rkey); called_func = "ucp_put_nbi"; break; case OPAL_COMMON_UCX_GET: - status = ucp_get_nbi(ep, buffer,len, rem_addr, rkey); + status = ucp_get_nbi(ep, buffer, len, rem_addr, rkey); called_func = "ucp_get_nbi"; break; } @@ -396,7 +381,7 @@ opal_common_ucx_wpmem_putget(opal_common_ucx_wpmem_t *mem, opal_common_ucx_op_t } rc = _periodical_flush_nb(mem, winfo, target); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "_incr_and_check_inflight_ops failed: %d", rc); } @@ -406,11 +391,9 @@ opal_common_ucx_wpmem_putget(opal_common_ucx_wpmem_t *mem, opal_common_ucx_op_t return rc; } - -static inline int -opal_common_ucx_wpmem_cmpswp(opal_common_ucx_wpmem_t *mem, uint64_t compare, - uint64_t value, int target, void *buffer, size_t len, - uint64_t rem_addr) +static inline int opal_common_ucx_wpmem_cmpswp(opal_common_ucx_wpmem_t *mem, uint64_t compare, + uint64_t value, int target, void *buffer, size_t len, + uint64_t rem_addr) { ucp_ep_h ep; ucp_rkey_h rkey; @@ -426,9 +409,7 @@ opal_common_ucx_wpmem_cmpswp(opal_common_ucx_wpmem_t *mem, uint64_t compare, /* Perform the operation */ opal_mutex_lock(&winfo->mutex); - status = opal_common_ucx_atomic_cswap(ep, compare, value, - buffer, len, - rem_addr, rkey, + status = opal_common_ucx_atomic_cswap(ep, compare, value, buffer, len, rem_addr, rkey, winfo->worker); if (OPAL_UNLIKELY(status != UCS_OK)) { MCA_COMMON_UCX_ERROR("opal_common_ucx_atomic_cswap failed: %d", status); @@ -437,7 +418,7 @@ opal_common_ucx_wpmem_cmpswp(opal_common_ucx_wpmem_t *mem, uint64_t compare, } rc = _periodical_flush_nb(mem, winfo, target); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "_incr_and_check_inflight_ops failed: %d", rc); } @@ -447,13 +428,11 @@ opal_common_ucx_wpmem_cmpswp(opal_common_ucx_wpmem_t *mem, uint64_t compare, return rc; } - -static inline int -opal_common_ucx_wpmem_cmpswp_nb(opal_common_ucx_wpmem_t *mem, uint64_t compare, - uint64_t value, int target, void *buffer, size_t len, - uint64_t rem_addr, - opal_common_ucx_user_req_handler_t user_req_cb, - void *user_req_ptr) +static inline int opal_common_ucx_wpmem_cmpswp_nb(opal_common_ucx_wpmem_t *mem, uint64_t compare, + uint64_t value, int target, void *buffer, + size_t len, uint64_t rem_addr, + opal_common_ucx_user_req_handler_t user_req_cb, + void *user_req_ptr) { ucp_ep_h ep; ucp_rkey_h rkey; @@ -469,10 +448,8 @@ opal_common_ucx_wpmem_cmpswp_nb(opal_common_ucx_wpmem_t *mem, uint64_t compare, /* Perform the operation */ opal_mutex_lock(&winfo->mutex); - req = opal_common_ucx_atomic_cswap_nb(ep, compare, value, - buffer, len, - rem_addr, rkey, opal_common_ucx_req_completion, - winfo->worker); + req = opal_common_ucx_atomic_cswap_nb(ep, compare, value, buffer, len, rem_addr, rkey, + opal_common_ucx_req_completion, winfo->worker); if (UCS_PTR_IS_PTR(req)) { req->ext_req = user_req_ptr; @@ -484,9 +461,8 @@ opal_common_ucx_wpmem_cmpswp_nb(opal_common_ucx_wpmem_t *mem, uint64_t compare, } } - rc = _periodical_flush_nb(mem, winfo, target); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "_incr_and_check_inflight_ops failed: %d", rc); } @@ -495,10 +471,9 @@ opal_common_ucx_wpmem_cmpswp_nb(opal_common_ucx_wpmem_t *mem, uint64_t compare, return rc; } - -static inline int -opal_common_ucx_wpmem_post(opal_common_ucx_wpmem_t *mem, ucp_atomic_post_op_t opcode, - uint64_t value, int target, size_t len, uint64_t rem_addr) +static inline int opal_common_ucx_wpmem_post(opal_common_ucx_wpmem_t *mem, + ucp_atomic_post_op_t opcode, uint64_t value, + int target, size_t len, uint64_t rem_addr) { ucp_ep_h ep; ucp_rkey_h rkey; @@ -506,17 +481,15 @@ opal_common_ucx_wpmem_post(opal_common_ucx_wpmem_t *mem, ucp_atomic_post_op_t op ucs_status_t status; int rc = OPAL_SUCCESS; - - rc =opal_common_ucx_tlocal_fetch(mem, target, &ep, &rkey, &winfo); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + rc = opal_common_ucx_tlocal_fetch(mem, target, &ep, &rkey, &winfo); + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_ERROR("tlocal_fetch failed: %d", rc); return rc; } /* Perform the operation */ opal_mutex_lock(&winfo->mutex); - status = ucp_atomic_post(ep, opcode, value, - len, rem_addr, rkey); + status = ucp_atomic_post(ep, opcode, value, len, rem_addr, rkey); if (OPAL_UNLIKELY(status != UCS_OK)) { MCA_COMMON_UCX_ERROR("ucp_atomic_post failed: %d", status); rc = OPAL_ERROR; @@ -524,7 +497,7 @@ opal_common_ucx_wpmem_post(opal_common_ucx_wpmem_t *mem, ucp_atomic_post_op_t op } rc = _periodical_flush_nb(mem, winfo, target); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "_incr_and_check_inflight_ops failed: %d", rc); } @@ -533,11 +506,10 @@ opal_common_ucx_wpmem_post(opal_common_ucx_wpmem_t *mem, ucp_atomic_post_op_t op return rc; } -static inline int -opal_common_ucx_wpmem_fetch(opal_common_ucx_wpmem_t *mem, - ucp_atomic_fetch_op_t opcode, uint64_t value, - int target, void *buffer, size_t len, - uint64_t rem_addr) +static inline int opal_common_ucx_wpmem_fetch(opal_common_ucx_wpmem_t *mem, + ucp_atomic_fetch_op_t opcode, uint64_t value, + int target, void *buffer, size_t len, + uint64_t rem_addr) { ucp_ep_h ep = NULL; ucp_rkey_h rkey = NULL; @@ -546,16 +518,14 @@ opal_common_ucx_wpmem_fetch(opal_common_ucx_wpmem_t *mem, int rc = OPAL_SUCCESS; rc = opal_common_ucx_tlocal_fetch(mem, target, &ep, &rkey, &winfo); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_ERROR("tlocal_fetch failed: %d", rc); return rc; } /* Perform the operation */ opal_mutex_lock(&winfo->mutex); - status = opal_common_ucx_atomic_fetch(ep, opcode, value, - buffer, len, - rem_addr, rkey, + status = opal_common_ucx_atomic_fetch(ep, opcode, value, buffer, len, rem_addr, rkey, winfo->worker); if (OPAL_UNLIKELY(status != UCS_OK)) { MCA_COMMON_UCX_ERROR("ucp_atomic_cswap64 failed: %d", status); @@ -564,7 +534,7 @@ opal_common_ucx_wpmem_fetch(opal_common_ucx_wpmem_t *mem, } rc = _periodical_flush_nb(mem, winfo, target); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "_incr_and_check_inflight_ops failed: %d", rc); } @@ -574,14 +544,12 @@ opal_common_ucx_wpmem_fetch(opal_common_ucx_wpmem_t *mem, return rc; } -static inline int -opal_common_ucx_wpmem_fetch_nb(opal_common_ucx_wpmem_t *mem, - ucp_atomic_fetch_op_t opcode, - uint64_t value, - int target, void *buffer, size_t len, - uint64_t rem_addr, - opal_common_ucx_user_req_handler_t user_req_cb, - void *user_req_ptr) +static inline int opal_common_ucx_wpmem_fetch_nb(opal_common_ucx_wpmem_t *mem, + ucp_atomic_fetch_op_t opcode, uint64_t value, + int target, void *buffer, size_t len, + uint64_t rem_addr, + opal_common_ucx_user_req_handler_t user_req_cb, + void *user_req_ptr) { ucp_ep_h ep = NULL; ucp_rkey_h rkey = NULL; @@ -590,15 +558,14 @@ opal_common_ucx_wpmem_fetch_nb(opal_common_ucx_wpmem_t *mem, opal_common_ucx_request_t *req; rc = opal_common_ucx_tlocal_fetch(mem, target, &ep, &rkey, &winfo); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_ERROR("tlocal_fetch failed: %d", rc); return rc; } /* Perform the operation */ opal_mutex_lock(&winfo->mutex); - req = opal_common_ucx_atomic_fetch_nb(ep, opcode, value, buffer, len, - rem_addr, rkey, opal_common_ucx_req_completion, - winfo->worker); + req = opal_common_ucx_atomic_fetch_nb(ep, opcode, value, buffer, len, rem_addr, rkey, + opal_common_ucx_req_completion, winfo->worker); if (UCS_PTR_IS_PTR(req)) { req->ext_req = user_req_ptr; req->ext_cb = user_req_cb; @@ -610,7 +577,7 @@ opal_common_ucx_wpmem_fetch_nb(opal_common_ucx_wpmem_t *mem, } rc = _periodical_flush_nb(mem, winfo, target); - if(OPAL_UNLIKELY(OPAL_SUCCESS != rc)){ + if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { MCA_COMMON_UCX_VERBOSE(1, "_incr_and_check_inflight_ops failed: %d", rc); } diff --git a/opal/mca/common/ucx/common_ucx_wpool_int.h b/opal/mca/common/ucx/common_ucx_wpool_int.h index 2dcbf2c970c..2c4d0fe6134 100644 --- a/opal/mca/common/ucx/common_ucx_wpool_int.h +++ b/opal/mca/common/ucx/common_ucx_wpool_int.h @@ -15,8 +15,7 @@ static opal_common_ucx_winfo_t *_winfo_create(opal_common_ucx_wpool_t *wpool); static void _winfo_destructor(opal_common_ucx_winfo_t *winfo); /* Internal Worker Pool Memory management */ -static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, - void **base, size_t size, ucp_mem_h *memh_ptr, - opal_common_ucx_mem_type_t mem_type); +static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool, void **base, size_t size, + ucp_mem_h *memh_ptr, opal_common_ucx_mem_type_t mem_type); #endif // COMMON_UCX_WPOOL_INT_H diff --git a/opal/mca/dl/base/base.h b/opal/mca/dl/base/base.h index 50b07ec02b2..5bfaca4a3a5 100644 --- a/opal/mca/dl/base/base.h +++ b/opal/mca/dl/base/base.h @@ -19,18 +19,15 @@ #include "opal/mca/base/base.h" - BEGIN_C_DECLS /** * Globals */ OPAL_DECLSPEC extern mca_base_framework_t opal_dl_base_framework; -OPAL_DECLSPEC extern opal_dl_base_component_t -*opal_dl_base_selected_component; +OPAL_DECLSPEC extern opal_dl_base_component_t *opal_dl_base_selected_component; OPAL_DECLSPEC extern opal_dl_base_module_t *opal_dl; - /** * Initialize the DL MCA framework * @@ -67,8 +64,7 @@ OPAL_DECLSPEC int opal_dl_base_close(void); * (see opal_dl_base_module_open_ft_t in opal/mca/dl/dl.h for * documentation of this function) */ -OPAL_DECLSPEC int opal_dl_open(const char *fname, - bool use_ext, bool private_namespace, +OPAL_DECLSPEC int opal_dl_open(const char *fname, bool use_ext, bool private_namespace, opal_dl_handle_t **handle, char **err_msg); /** @@ -77,9 +73,8 @@ OPAL_DECLSPEC int opal_dl_open(const char *fname, * (see opal_dl_base_module_lookup_ft_t in opal/mca/dl/dl.h for * documentation of this function) */ -OPAL_DECLSPEC int opal_dl_lookup(opal_dl_handle_t *handle, - const char *symbol, - void **ptr, char **err_msg); +OPAL_DECLSPEC int opal_dl_lookup(opal_dl_handle_t *handle, const char *symbol, void **ptr, + char **err_msg); /** * Close a DSO @@ -96,8 +91,7 @@ OPAL_DECLSPEC int opal_dl_close(opal_dl_handle_t *handle); * documentation of this function) */ OPAL_DECLSPEC int opal_dl_foreachfile(const char *search_path, - int (*cb_func)(const char *filename, - void *context), + int (*cb_func)(const char *filename, void *context), void *context); END_C_DECLS diff --git a/opal/mca/dl/base/dl_base_close.c b/opal/mca/dl/base/dl_base_close.c index 3bf286ab443..1c2bdf1d0c9 100644 --- a/opal/mca/dl/base/dl_base_close.c +++ b/opal/mca/dl/base/dl_base_close.c @@ -11,12 +11,11 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" -#include "opal/mca/dl/dl.h" #include "opal/mca/dl/base/base.h" - +#include "opal/mca/dl/dl.h" int opal_dl_base_close(void) { diff --git a/opal/mca/dl/base/dl_base_fns.c b/opal/mca/dl/base/dl_base_fns.c index 32b70111236..4a9696cf134 100644 --- a/opal/mca/dl/base/dl_base_fns.c +++ b/opal/mca/dl/base/dl_base_fns.c @@ -21,24 +21,19 @@ #include "opal/mca/dl/base/base.h" - -int opal_dl_open(const char *fname, - bool use_ext, bool private_namespace, - opal_dl_handle_t **handle, char **err_msg) +int opal_dl_open(const char *fname, bool use_ext, bool private_namespace, opal_dl_handle_t **handle, + char **err_msg) { *handle = NULL; if (NULL != opal_dl && NULL != opal_dl->open) { - return opal_dl->open(fname, use_ext, private_namespace, - handle, err_msg); + return opal_dl->open(fname, use_ext, private_namespace, handle, err_msg); } return OPAL_ERR_NOT_SUPPORTED; } -int opal_dl_lookup(opal_dl_handle_t *handle, - const char *symbol, - void **ptr, char **err_msg) +int opal_dl_lookup(opal_dl_handle_t *handle, const char *symbol, void **ptr, char **err_msg) { if (NULL != opal_dl && NULL != opal_dl->lookup) { return opal_dl->lookup(handle, symbol, ptr, err_msg); @@ -57,8 +52,7 @@ int opal_dl_close(opal_dl_handle_t *handle) } int opal_dl_foreachfile(const char *search_path, - int (*cb_func)(const char *filename, void *context), - void *context) + int (*cb_func)(const char *filename, void *context), void *context) { if (NULL != opal_dl && NULL != opal_dl->foreachfile) { return opal_dl->foreachfile(search_path, cb_func, context); diff --git a/opal/mca/dl/base/dl_base_open.c b/opal/mca/dl/base/dl_base_open.c index 5e65cff9c0b..540be388732 100644 --- a/opal/mca/dl/base/dl_base_open.c +++ b/opal/mca/dl/base/dl_base_open.c @@ -17,14 +17,12 @@ #include "opal/mca/dl/base/static-components.h" - /* * Globals */ opal_dl_base_module_t *opal_dl = NULL; opal_dl_base_component_t *opal_dl_base_selected_component = NULL; - /* * Function for finding and opening either all MCA components, * or the one that was specifically requested via a MCA parameter. @@ -46,9 +44,6 @@ int opal_dl_base_open(mca_base_open_flag_t flags) But we must mark this framework is NO_DSO so that the MCA framework base doesn't try to open any dynamic components in this framework. */ -MCA_BASE_FRAMEWORK_DECLARE(opal, dl, "Dynamic loader framework", - NULL /* register */, - opal_dl_base_open /* open */, - NULL /* close */, - mca_dl_base_static_components, - MCA_BASE_FRAMEWORK_FLAG_NO_DSO); +MCA_BASE_FRAMEWORK_DECLARE(opal, dl, "Dynamic loader framework", NULL /* register */, + opal_dl_base_open /* open */, NULL /* close */, + mca_dl_base_static_components, MCA_BASE_FRAMEWORK_FLAG_NO_DSO); diff --git a/opal/mca/dl/base/dl_base_select.c b/opal/mca/dl/base/dl_base_select.c index 8db0b5e99b7..beb55c8f2fc 100644 --- a/opal/mca/dl/base/dl_base_select.c +++ b/opal/mca/dl/base/dl_base_select.c @@ -16,16 +16,15 @@ #include "opal_config.h" #ifdef HAVE_UNISTD_H -#include "unistd.h" +# include "unistd.h" #endif #include "opal/include/opal/constants.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/dl/dl.h" #include "opal/mca/dl/base/base.h" - +#include "opal/mca/dl/dl.h" +#include "opal/mca/mca.h" +#include "opal/util/output.h" int opal_dl_base_select(void) { @@ -36,11 +35,11 @@ int opal_dl_base_select(void) /* * Select the best component */ - if (OPAL_SUCCESS != mca_base_select("dl", - opal_dl_base_framework.framework_output, - &opal_dl_base_framework.framework_components, - (mca_base_module_t **) &best_module, - (mca_base_component_t **) &best_component, NULL) ) { + if (OPAL_SUCCESS + != mca_base_select("dl", opal_dl_base_framework.framework_output, + &opal_dl_base_framework.framework_components, + (mca_base_module_t **) &best_module, + (mca_base_component_t **) &best_component, NULL)) { /* This will only happen if no component was selected */ exit_status = OPAL_ERROR; goto cleanup; @@ -50,6 +49,6 @@ int opal_dl_base_select(void) opal_dl_base_selected_component = best_component; opal_dl = best_module; - cleanup: +cleanup: return exit_status; } diff --git a/opal/mca/dl/dl.h b/opal/mca/dl/dl.h index b2541672264..fa14328f8e0 100644 --- a/opal/mca/dl/dl.h +++ b/opal/mca/dl/dl.h @@ -49,8 +49,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" BEGIN_C_DECLS @@ -85,9 +85,9 @@ typedef struct opal_dl_handle_t opal_dl_handle_t; * or freed by the caller. The contents of the err_msg string may * change after successive calls to opal_dl API calls. */ -typedef int (*opal_dl_base_module_open_fn_t) - (const char *fname, bool use_ext, bool private_namespace, - opal_dl_handle_t **handle, char **err_msg); +typedef int (*opal_dl_base_module_open_fn_t)(const char *fname, bool use_ext, + bool private_namespace, opal_dl_handle_t **handle, + char **err_msg); /** * Lookup a symbol in an opened file. @@ -106,8 +106,8 @@ typedef int (*opal_dl_base_module_open_fn_t) * or freed by the caller. The contents of the err_msg string may * change after successive calls to opal_dl API calls. */ -typedef int (*opal_dl_base_module_lookup_fn_t) - (opal_dl_handle_t *handle, const char *symbol, void **ptr, char **err_msg); +typedef int (*opal_dl_base_module_lookup_fn_t)(opal_dl_handle_t *handle, const char *symbol, + void **ptr, char **err_msg); /** * Dynamically close a previously dynamically-opened file. @@ -120,8 +120,7 @@ typedef int (*opal_dl_base_module_lookup_fn_t) * This function should close the file and free and resources * associated with it (e.g., whatever is cached on the handle). */ -typedef int (*opal_dl_base_module_close_fn_t) - (opal_dl_handle_t *handle); +typedef int (*opal_dl_base_module_close_fn_t)(opal_dl_handle_t *handle); /** * Search through a path of directories, invoking a callback on each @@ -136,10 +135,8 @@ typedef int (*opal_dl_base_module_close_fn_t) * Returns: * OPAL_SUCESS on success, OPAL_ERR* otherwise */ -typedef int (*opal_dl_base_module_foreachfile_fn_t) - (const char *search_path, - int (*cb_func)(const char *filename, void *context), - void *context); +typedef int (*opal_dl_base_module_foreachfile_fn_t)( + const char *search_path, int (*cb_func)(const char *filename, void *context), void *context); /** * Structure for DL components. @@ -160,17 +157,17 @@ typedef struct opal_dl_base_component_1_0_0_t opal_dl_base_component_t; * Structure for DL modules */ struct opal_dl_base_module_1_0_0_t { - mca_base_module_2_0_0_t super; + mca_base_module_2_0_0_t super; /** Open / close */ - opal_dl_base_module_open_fn_t open; - opal_dl_base_module_close_fn_t close; + opal_dl_base_module_open_fn_t open; + opal_dl_base_module_close_fn_t close; /** Lookup a symbol */ - opal_dl_base_module_lookup_fn_t lookup; + opal_dl_base_module_lookup_fn_t lookup; /** Iterate looking for files */ - opal_dl_base_module_foreachfile_fn_t foreachfile; + opal_dl_base_module_foreachfile_fn_t foreachfile; }; typedef struct opal_dl_base_module_1_0_0_t opal_dl_base_module_1_0_0_t; typedef struct opal_dl_base_module_1_0_0_t opal_dl_base_module_t; @@ -178,8 +175,7 @@ typedef struct opal_dl_base_module_1_0_0_t opal_dl_base_module_t; /** * Macro for use in components that are of type DL */ -#define OPAL_DL_BASE_VERSION_1_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("dl", 1, 0, 0) +#define OPAL_DL_BASE_VERSION_1_0_0 OPAL_MCA_BASE_VERSION_2_1_0("dl", 1, 0, 0) END_C_DECLS diff --git a/opal/mca/dl/dlopen/dl_dlopen_component.c b/opal/mca/dl/dlopen/dl_dlopen_component.c index 97f8872f14e..046878bb9e9 100644 --- a/opal/mca/dl/dlopen/dl_dlopen_component.c +++ b/opal/mca/dl/dlopen/dl_dlopen_component.c @@ -18,13 +18,11 @@ #include "dl_dlopen.h" - /* * Public string showing the sysinfo ompi_linux component version number */ -const char *opal_dl_dlopen_component_version_string = - "OPAL dl dlopen MCA component version " OPAL_VERSION; - +const char *opal_dl_dlopen_component_version_string + = "OPAL dl dlopen MCA component version " OPAL_VERSION; /* * Local functions @@ -42,58 +40,51 @@ static int dlopen_component_query(mca_base_module_t **module, int *priority); opal_dl_dlopen_component_t mca_dl_dlopen_component = { /* Fill in the mca_dl_base_component_t */ - .base = { - - /* First, the mca_component_t struct containing meta information - about the component itself */ - .base_version = { - OPAL_DL_BASE_VERSION_1_0_0, - - /* Component name and version */ - .mca_component_name = "dlopen", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - /* Component functions */ - .mca_register_component_params = dlopen_component_register, - .mca_open_component = dlopen_component_open, - .mca_close_component = dlopen_component_close, - .mca_query_component = dlopen_component_query, - }, - - .base_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - - /* The dl framework members */ - .priority = 80 - }, + .base = + { + + /* First, the mca_component_t struct containing meta information + about the component itself */ + .base_version = + { + OPAL_DL_BASE_VERSION_1_0_0, + + /* Component name and version */ + .mca_component_name = "dlopen", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + /* Component functions */ + .mca_register_component_params = dlopen_component_register, + .mca_open_component = dlopen_component_open, + .mca_close_component = dlopen_component_close, + .mca_query_component = dlopen_component_query, + }, + + .base_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + /* The dl framework members */ + .priority = 80}, }; - static int dlopen_component_register(void) { int ret; mca_dl_dlopen_component.filename_suffixes_mca_storage = ".so,.dylib,.dll,.sl"; - ret = - mca_base_component_var_register(&mca_dl_dlopen_component.base.base_version, - "filename_suffixes", - "Comma-delimited list of filename suffixes that the dlopen component will try", - MCA_BASE_VAR_TYPE_STRING, - NULL, - 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_LOCAL, - &mca_dl_dlopen_component.filename_suffixes_mca_storage); + ret = mca_base_component_var_register( + &mca_dl_dlopen_component.base.base_version, "filename_suffixes", + "Comma-delimited list of filename suffixes that the dlopen component will try", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_dl_dlopen_component.filename_suffixes_mca_storage); if (ret < 0) { return ret; } - mca_dl_dlopen_component.filename_suffixes = - opal_argv_split(mca_dl_dlopen_component.filename_suffixes_mca_storage, - ','); + mca_dl_dlopen_component.filename_suffixes = opal_argv_split(mca_dl_dlopen_component + .filename_suffixes_mca_storage, + ','); return OPAL_SUCCESS; } @@ -103,7 +94,6 @@ static int dlopen_component_open(void) return OPAL_SUCCESS; } - static int dlopen_component_close(void) { if (NULL != mca_dl_dlopen_component.filename_suffixes) { @@ -114,7 +104,6 @@ static int dlopen_component_close(void) return OPAL_SUCCESS; } - static int dlopen_component_query(mca_base_module_t **module, int *priority) { /* The priority value is somewhat meaningless here; by diff --git a/opal/mca/dl/dlopen/dl_dlopen_module.c b/opal/mca/dl/dlopen/dl_dlopen_module.c index 57f392fe046..930e9554b81 100644 --- a/opal/mca/dl/dlopen/dl_dlopen_module.c +++ b/opal/mca/dl/dlopen/dl_dlopen_module.c @@ -14,11 +14,11 @@ #include "opal_config.h" -#include -#include -#include #include +#include +#include #include +#include #include #include "opal/constants.h" @@ -28,12 +28,10 @@ #include "dl_dlopen.h" - /* * Trivial helper function to avoid replicating code */ -static void do_dlopen(const char *fname, int flags, - void **handle, char **err_msg) +static void do_dlopen(const char *fname, int flags, void **handle, char **err_msg) { assert(handle); @@ -48,7 +46,6 @@ static void do_dlopen(const char *fname, int flags, } } - static int dlopen_open(const char *fname, bool use_ext, bool private_namespace, opal_dl_handle_t **handle, char **err_msg) { @@ -71,8 +68,7 @@ static int dlopen_open(const char *fname, bool use_ext, bool private_namespace, int i; char *ext; - for (i = 0, ext = mca_dl_dlopen_component.filename_suffixes[i]; - NULL != ext; + for (i = 0, ext = mca_dl_dlopen_component.filename_suffixes[i]; NULL != ext; ext = mca_dl_dlopen_component.filename_suffixes[++i]) { char *name; @@ -110,10 +106,9 @@ static int dlopen_open(const char *fname, bool use_ext, bool private_namespace, (*handle)->dlopen_handle = local_handle; #if OPAL_ENABLE_DEBUG - if( NULL != fname ) { + if (NULL != fname) { (*handle)->filename = strdup(fname); - } - else { + } else { (*handle)->filename = strdup("(null)"); } #endif @@ -121,9 +116,7 @@ static int dlopen_open(const char *fname, bool use_ext, bool private_namespace, return (NULL != local_handle) ? OPAL_SUCCESS : OPAL_ERROR; } - -static int dlopen_lookup(opal_dl_handle_t *handle, const char *symbol, - void **ptr, char **err_msg) +static int dlopen_lookup(opal_dl_handle_t *handle, const char *symbol, void **ptr, char **err_msg) { assert(handle); assert(handle->dlopen_handle); @@ -141,7 +134,6 @@ static int dlopen_lookup(opal_dl_handle_t *handle, const char *symbol, return OPAL_ERROR; } - static int dlopen_close(opal_dl_handle_t *handle) { assert(handle); @@ -162,8 +154,7 @@ static int dlopen_close(opal_dl_handle_t *handle) * on each one. */ static int dlopen_foreachfile(const char *search_path, - int (*func)(const char *filename, void *data), - void *data) + int (*func)(const char *filename, void *data), void *data) { int ret; DIR *dp = NULL; @@ -209,9 +200,8 @@ static int dlopen_foreachfile(const char *search_path, if (NULL != ptr) { /* Skip libtool files */ - if (strcmp(ptr, ".la") == 0 || - strcmp(ptr, ".lo") == 0) { - free (abs_name); + if (strcmp(ptr, ".la") == 0 || strcmp(ptr, ".lo") == 0) { + free(abs_name); continue; } @@ -221,8 +211,7 @@ static int dlopen_foreachfile(const char *search_path, /* Have we already found this file? Or already found a file with the same basename (but different suffix)? */ bool found = false; - for (int j = 0; NULL != good_files && - NULL != good_files[j]; ++j) { + for (int j = 0; NULL != good_files && NULL != good_files[j]; ++j) { if (strcmp(good_files[j], abs_name) == 0) { found = true; break; @@ -250,7 +239,7 @@ static int dlopen_foreachfile(const char *search_path, ret = OPAL_SUCCESS; - error: +error: if (NULL != dp) { closedir(dp); } @@ -264,13 +253,10 @@ static int dlopen_foreachfile(const char *search_path, return ret; } - /* * Module definition */ -opal_dl_base_module_t opal_dl_dlopen_module = { - .open = dlopen_open, - .lookup = dlopen_lookup, - .close = dlopen_close, - .foreachfile = dlopen_foreachfile -}; +opal_dl_base_module_t opal_dl_dlopen_module = {.open = dlopen_open, + .lookup = dlopen_lookup, + .close = dlopen_close, + .foreachfile = dlopen_foreachfile}; diff --git a/opal/mca/dl/libltdl/dl_libltdl.h b/opal/mca/dl/libltdl/dl_libltdl.h index c5b5b16788f..93a9c4a87cd 100644 --- a/opal/mca/dl/libltdl/dl_libltdl.h +++ b/opal/mca/dl/libltdl/dl_libltdl.h @@ -16,7 +16,6 @@ #include - OPAL_DECLSPEC extern opal_dl_base_module_t opal_dl_libltdl_module; /* diff --git a/opal/mca/dl/libltdl/dl_libltdl_component.c b/opal/mca/dl/libltdl/dl_libltdl_component.c index 5855bf0a312..a75ba852252 100644 --- a/opal/mca/dl/libltdl/dl_libltdl_component.c +++ b/opal/mca/dl/libltdl/dl_libltdl_component.c @@ -13,19 +13,17 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/dl/dl.h" #include "opal/mca/base/mca_base_var.h" +#include "opal/mca/dl/dl.h" #include "opal/util/argv.h" #include "dl_libltdl.h" - /* * Public string showing the sysinfo ompi_linux component version number */ -const char *opal_dl_libltdl_component_version_string = - "OPAL dl libltdl MCA component version " OPAL_VERSION; - +const char *opal_dl_libltdl_component_version_string + = "OPAL dl libltdl MCA component version " OPAL_VERSION; /* * Local functions @@ -43,53 +41,47 @@ static int libltdl_component_query(mca_base_module_t **module, int *priority); opal_dl_libltdl_component_t mca_dl_libltdl_component = { /* Fill in the mca_dl_base_component_t */ - .base = { - - /* First, the mca_component_t struct containing meta information - about the component itself */ - .base_version = { - OPAL_DL_BASE_VERSION_1_0_0, - - /* Component name and version */ - .mca_component_name = "libltdl", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - /* Component functions */ - .mca_register_component_params = libltdl_component_register, - .mca_open_component = libltdl_component_open, - .mca_close_component = libltdl_component_close, - .mca_query_component = libltdl_component_query, - }, - - .base_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - - /* The dl framework members */ - .priority = 50 - } + .base = + { + + /* First, the mca_component_t struct containing meta information + about the component itself */ + .base_version = + { + OPAL_DL_BASE_VERSION_1_0_0, + + /* Component name and version */ + .mca_component_name = "libltdl", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + /* Component functions */ + .mca_register_component_params = libltdl_component_register, + .mca_open_component = libltdl_component_open, + .mca_close_component = libltdl_component_close, + .mca_query_component = libltdl_component_query, + }, + + .base_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + /* The dl framework members */ + .priority = 50} /* Now fill in the libltdl component-specific members */ }; - static int libltdl_component_register(void) { /* Register an info param indicating whether we have lt_dladvise support or not */ bool supported = OPAL_INT_TO_BOOL(OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE); - mca_base_component_var_register(&mca_dl_libltdl_component.base.base_version, - "have_lt_dladvise", - "Whether the version of libltdl that this component is built against supports lt_dladvise functionality or not", - MCA_BASE_VAR_TYPE_BOOL, - NULL, - 0, - MCA_BASE_VAR_FLAG_DEFAULT_ONLY, - OPAL_INFO_LVL_7, - MCA_BASE_VAR_SCOPE_CONSTANT, - &supported); + mca_base_component_var_register(&mca_dl_libltdl_component.base.base_version, "have_lt_dladvise", + "Whether the version of libltdl that this component is built " + "against supports lt_dladvise functionality or not", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_DEFAULT_ONLY, + OPAL_INFO_LVL_7, MCA_BASE_VAR_SCOPE_CONSTANT, &supported); return OPAL_SUCCESS; } @@ -107,19 +99,16 @@ static int libltdl_component_open(void) return OPAL_ERR_OUT_OF_RESOURCE; } - if (lt_dladvise_init(&c->advise_private_ext) || - lt_dladvise_ext(&c->advise_private_ext)) { + if (lt_dladvise_init(&c->advise_private_ext) || lt_dladvise_ext(&c->advise_private_ext)) { return OPAL_ERR_OUT_OF_RESOURCE; } - if (lt_dladvise_init(&c->advise_public_noext) || - lt_dladvise_global(&c->advise_public_noext)) { + if (lt_dladvise_init(&c->advise_public_noext) || lt_dladvise_global(&c->advise_public_noext)) { return OPAL_ERR_OUT_OF_RESOURCE; } - if (lt_dladvise_init(&c->advise_public_ext) || - lt_dladvise_global(&c->advise_public_ext) || - lt_dladvise_ext(&c->advise_public_ext)) { + if (lt_dladvise_init(&c->advise_public_ext) || lt_dladvise_global(&c->advise_public_ext) + || lt_dladvise_ext(&c->advise_public_ext)) { return OPAL_ERR_OUT_OF_RESOURCE; } #endif @@ -127,7 +116,6 @@ static int libltdl_component_open(void) return OPAL_SUCCESS; } - static int libltdl_component_close(void) { #if OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE @@ -144,7 +132,6 @@ static int libltdl_component_close(void) return OPAL_SUCCESS; } - static int libltdl_component_query(mca_base_module_t **module, int *priority) { /* The priority value is somewhat meaningless here; by diff --git a/opal/mca/dl/libltdl/dl_libltdl_module.c b/opal/mca/dl/libltdl/dl_libltdl_module.c index 4704d000984..a76f6370884 100644 --- a/opal/mca/dl/libltdl/dl_libltdl_module.c +++ b/opal/mca/dl/libltdl/dl_libltdl_module.c @@ -15,9 +15,8 @@ #include "dl_libltdl.h" - static int libltdl_open(const char *fname, bool use_ext, bool private_namespace, - opal_dl_handle_t **handle, char **err_msg) + opal_dl_handle_t **handle, char **err_msg) { assert(handle); @@ -53,10 +52,9 @@ static int libltdl_open(const char *fname, bool use_ext, bool private_namespace, (*handle)->ltdl_handle = local_handle; #if OPAL_ENABLE_DEBUG - if( NULL != fname ) { + if (NULL != fname) { (*handle)->filename = strdup(fname); - } - else { + } else { (*handle)->filename = strdup("(null)"); } #endif @@ -65,14 +63,12 @@ static int libltdl_open(const char *fname, bool use_ext, bool private_namespace, } if (NULL != err_msg) { - *err_msg = (char*) lt_dlerror(); + *err_msg = (char *) lt_dlerror(); } return OPAL_ERROR; } - -static int libltdl_lookup(opal_dl_handle_t *handle, const char *symbol, - void **ptr, char **err_msg) +static int libltdl_lookup(opal_dl_handle_t *handle, const char *symbol, void **ptr, char **err_msg) { assert(handle); assert(handle->ltdl_handle); @@ -89,12 +85,11 @@ static int libltdl_lookup(opal_dl_handle_t *handle, const char *symbol, } if (NULL != err_msg) { - *err_msg = (char*) lt_dlerror(); + *err_msg = (char *) lt_dlerror(); } return OPAL_ERROR; } - static int libltdl_close(opal_dl_handle_t *handle) { assert(handle); @@ -111,8 +106,7 @@ static int libltdl_close(opal_dl_handle_t *handle) } static int libltdl_foreachfile(const char *search_path, - int (*func)(const char *filename, void *data), - void *data) + int (*func)(const char *filename, void *data), void *data) { assert(search_path); assert(func); @@ -121,13 +115,10 @@ static int libltdl_foreachfile(const char *search_path, return (0 == ret) ? OPAL_SUCCESS : OPAL_ERROR; } - /* * Module definition */ -opal_dl_base_module_t opal_dl_libltdl_module = { - .open = libltdl_open, - .lookup = libltdl_lookup, - .close = libltdl_close, - .foreachfile = libltdl_foreachfile -}; +opal_dl_base_module_t opal_dl_libltdl_module = {.open = libltdl_open, + .lookup = libltdl_lookup, + .close = libltdl_close, + .foreachfile = libltdl_foreachfile}; diff --git a/opal/mca/hwloc/base/base.h b/opal/mca/hwloc/base/base.h index 80fa9ab356a..646476c3aa6 100644 --- a/opal/mca/hwloc/base/base.h +++ b/opal/mca/hwloc/base/base.h @@ -19,9 +19,9 @@ #include "opal/mca/hwloc/hwloc-internal.h" #if HWLOC_API_VERSION < 0x20000 -#define HWLOC_OBJ_L3CACHE HWLOC_OBJ_CACHE -#define HWLOC_OBJ_L2CACHE HWLOC_OBJ_CACHE -#define HWLOC_OBJ_L1CACHE HWLOC_OBJ_CACHE +# define HWLOC_OBJ_L3CACHE HWLOC_OBJ_CACHE +# define HWLOC_OBJ_L2CACHE HWLOC_OBJ_CACHE +# define HWLOC_OBJ_L1CACHE HWLOC_OBJ_CACHE #endif /* @@ -54,56 +54,52 @@ OPAL_DECLSPEC extern bool opal_hwloc_topology_inited; OPAL_DECLSPEC extern mca_base_framework_t opal_hwloc_base_framework; /* we always must have some minimal locality support */ -#define OPAL_HWLOC_PRINT_MAX_SIZE 50 -#define OPAL_HWLOC_PRINT_NUM_BUFS 16 +#define OPAL_HWLOC_PRINT_MAX_SIZE 50 +#define OPAL_HWLOC_PRINT_NUM_BUFS 16 typedef struct { char *buffers[OPAL_HWLOC_PRINT_NUM_BUFS]; int cntr; } opal_hwloc_print_buffers_t; opal_hwloc_print_buffers_t *opal_hwloc_get_print_buffer(void); -extern char* opal_hwloc_print_null; -OPAL_DECLSPEC char* opal_hwloc_base_print_locality(opal_hwloc_locality_t locality); +extern char *opal_hwloc_print_null; +OPAL_DECLSPEC char *opal_hwloc_base_print_locality(opal_hwloc_locality_t locality); OPAL_DECLSPEC extern char *opal_hwloc_base_cpu_list; OPAL_DECLSPEC extern hwloc_cpuset_t opal_hwloc_base_given_cpus; OPAL_DECLSPEC extern char *opal_hwloc_base_topo_file; /* convenience macro for debugging */ -#define OPAL_HWLOC_SHOW_BINDING(n, v, t) \ - do { \ - char tmp1[1024]; \ - hwloc_cpuset_t bind; \ - bind = opal_hwloc_alloc(); \ - if (hwloc_get_cpubind(t, bind, \ - HWLOC_CPUBIND_PROCESS) < 0) { \ - opal_output_verbose(n, v, \ - "CANNOT DETERMINE BINDING AT %s:%d", \ - __FILE__, __LINE__); \ - } else { \ - opal_hwloc_base_cset2mapstr(tmp1, sizeof(tmp1), t, bind); \ - opal_output_verbose(n, v, \ - "BINDINGS AT %s:%d: %s", \ - __FILE__, __LINE__, tmp1); \ - } \ - hwloc_bitmap_free(bind); \ - } while(0); +#define OPAL_HWLOC_SHOW_BINDING(n, v, t) \ + do { \ + char tmp1[1024]; \ + hwloc_cpuset_t bind; \ + bind = opal_hwloc_alloc(); \ + if (hwloc_get_cpubind(t, bind, HWLOC_CPUBIND_PROCESS) < 0) { \ + opal_output_verbose(n, v, "CANNOT DETERMINE BINDING AT %s:%d", __FILE__, __LINE__); \ + } else { \ + opal_hwloc_base_cset2mapstr(tmp1, sizeof(tmp1), t, bind); \ + opal_output_verbose(n, v, "BINDINGS AT %s:%d: %s", __FILE__, __LINE__, tmp1); \ + } \ + hwloc_bitmap_free(bind); \ + } while (0); #if HWLOC_API_VERSION < 0x20000 -#define OPAL_HWLOC_MAKE_OBJ_CACHE(level, obj, cache_level) \ - do { \ - obj = HWLOC_OBJ_CACHE; \ - cache_level = level; \ - } while(0) +# define OPAL_HWLOC_MAKE_OBJ_CACHE(level, obj, cache_level) \ + do { \ + obj = HWLOC_OBJ_CACHE; \ + cache_level = level; \ + } while (0) #else -#define OPAL_HWLOC_MAKE_OBJ_CACHE(level, obj, cache_level) \ - do { \ - obj = HWLOC_OBJ_L##level##CACHE; \ - cache_level = 0; \ - } while(0) +# define OPAL_HWLOC_MAKE_OBJ_CACHE(level, obj, cache_level) \ + do { \ + obj = HWLOC_OBJ_L##level##CACHE; \ + cache_level = 0; \ + } while (0) #endif OPAL_DECLSPEC opal_hwloc_locality_t opal_hwloc_base_get_relative_locality(hwloc_topology_t topo, - char *cpuset1, char *cpuset2); + char *cpuset1, + char *cpuset2); OPAL_DECLSPEC int opal_hwloc_base_set_binding_policy(opal_binding_policy_t *policy, char *spec); @@ -128,10 +124,7 @@ OBJ_CLASS_DECLARATION(opal_rmaps_numa_node_t); * Enum for what memory allocation policy we want for user allocations. * MAP = memory allocation policy. */ -typedef enum { - OPAL_HWLOC_BASE_MAP_NONE, - OPAL_HWLOC_BASE_MAP_LOCAL_ONLY -} opal_hwloc_base_map_t; +typedef enum { OPAL_HWLOC_BASE_MAP_NONE, OPAL_HWLOC_BASE_MAP_LOCAL_ONLY } opal_hwloc_base_map_t; /** * Global reflecting the MAP (set by MCA param). @@ -181,7 +174,7 @@ OPAL_DECLSPEC hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo, unsigned int instance, opal_hwloc_resource_type_t rtype); -OPAL_DECLSPEC char* opal_hwloc_base_print_binding(opal_binding_policy_t binding); +OPAL_DECLSPEC char *opal_hwloc_base_print_binding(opal_binding_policy_t binding); /** * Determine if there is a single cpu in a bitmap. @@ -193,9 +186,7 @@ OPAL_DECLSPEC bool opal_hwloc_base_single_cpu(hwloc_cpuset_t cpuset); * fails to bind memory -- according to the value of the * hwloc_base_bind_failure_action MCA parameter. */ -OPAL_DECLSPEC int opal_hwloc_base_report_bind_failure(const char *file, - int line, - const char *msg, +OPAL_DECLSPEC int opal_hwloc_base_report_bind_failure(const char *file, int line, const char *msg, int rc); /** @@ -208,8 +199,8 @@ OPAL_DECLSPEC int opal_hwloc_base_report_bind_failure(const char *file, */ OPAL_DECLSPEC int opal_hwloc_base_set_process_membind_policy(void); -OPAL_DECLSPEC int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, - size_t count, int node_id); +OPAL_DECLSPEC int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, size_t count, + int node_id); OPAL_DECLSPEC int opal_hwloc_base_node_name_to_id(char *node_name, int *id); @@ -220,8 +211,7 @@ OPAL_DECLSPEC int opal_hwloc_base_memory_set(opal_hwloc_base_memory_segment_t *s * Make a prettyprint string for a hwloc_cpuset_t (e.g., "socket * 2[core 3]"). */ -OPAL_DECLSPEC int opal_hwloc_base_cset2str(char *str, int len, - hwloc_topology_t topo, +OPAL_DECLSPEC int opal_hwloc_base_cset2str(char *str, int len, hwloc_topology_t topo, hwloc_cpuset_t cpuset); /** @@ -232,26 +222,24 @@ OPAL_DECLSPEC int opal_hwloc_base_cset2str(char *str, int len, * . - signifies PU a process not bound to * B - signifies PU a process is bound to */ -OPAL_DECLSPEC int opal_hwloc_base_cset2mapstr(char *str, int len, - hwloc_topology_t topo, +OPAL_DECLSPEC int opal_hwloc_base_cset2mapstr(char *str, int len, hwloc_topology_t topo, hwloc_cpuset_t cpuset); /* get the hwloc object that corresponds to the given processor id and type */ -OPAL_DECLSPEC hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, - int lid, +OPAL_DECLSPEC hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, int lid, opal_hwloc_resource_type_t rtype); /* get a string describing the locality of a given process */ -OPAL_DECLSPEC char* opal_hwloc_base_get_locality_string(hwloc_topology_t topo, char *bitmap); +OPAL_DECLSPEC char *opal_hwloc_base_get_locality_string(hwloc_topology_t topo, char *bitmap); /* extract a location from the locality string */ -OPAL_DECLSPEC char* opal_hwloc_base_get_location(char *locality, - hwloc_obj_type_t type, +OPAL_DECLSPEC char *opal_hwloc_base_get_location(char *locality, hwloc_obj_type_t type, unsigned index); OPAL_DECLSPEC opal_hwloc_locality_t opal_hwloc_compute_relative_locality(char *loc1, char *loc2); -OPAL_DECLSPEC int opal_hwloc_base_topology_set_flags (hwloc_topology_t topology, unsigned long flags, bool io); +OPAL_DECLSPEC int opal_hwloc_base_topology_set_flags(hwloc_topology_t topology, unsigned long flags, + bool io); END_C_DECLS #endif /* OPAL_HWLOC_BASE_H */ diff --git a/opal/mca/hwloc/base/hwloc_base_frame.c b/opal/mca/hwloc/base/hwloc_base_frame.c index ee69bc6306e..75a6220851a 100644 --- a/opal/mca/hwloc/base/hwloc_base_frame.c +++ b/opal/mca/hwloc/base/hwloc_base_frame.c @@ -12,20 +12,18 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" +#include "opal/mca/base/base.h" +#include "opal/mca/mca.h" +#include "opal/mca/threads/tsd.h" #include "opal/util/argv.h" #include "opal/util/output.h" #include "opal/util/show_help.h" -#include "opal/mca/mca.h" -#include "opal/mca/base/base.h" -#include "opal/mca/threads/tsd.h" -#include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/hwloc/base/base.h" - +#include "opal/mca/hwloc/hwloc-internal.h" /* * The following file was created by configure. It contains extern @@ -34,51 +32,39 @@ */ #include "opal/mca/hwloc/base/static-components.h" - /* * Globals */ bool opal_hwloc_base_inited = false; -hwloc_topology_t opal_hwloc_topology=NULL; -hwloc_cpuset_t opal_hwloc_my_cpuset=NULL; -hwloc_cpuset_t opal_hwloc_base_given_cpus=NULL; +hwloc_topology_t opal_hwloc_topology = NULL; +hwloc_cpuset_t opal_hwloc_my_cpuset = NULL; +hwloc_cpuset_t opal_hwloc_base_given_cpus = NULL; opal_hwloc_base_map_t opal_hwloc_base_map = OPAL_HWLOC_BASE_MAP_NONE; opal_hwloc_base_mbfa_t opal_hwloc_base_mbfa = OPAL_HWLOC_BASE_MBFA_WARN; -opal_binding_policy_t opal_hwloc_binding_policy=0; -char *opal_hwloc_base_cpu_list=NULL; -bool opal_hwloc_report_bindings=false; -hwloc_obj_type_t opal_hwloc_levels[] = { - HWLOC_OBJ_MACHINE, - HWLOC_OBJ_NODE, - HWLOC_OBJ_SOCKET, - HWLOC_OBJ_L3CACHE, - HWLOC_OBJ_L2CACHE, - HWLOC_OBJ_L1CACHE, - HWLOC_OBJ_CORE, - HWLOC_OBJ_PU -}; +opal_binding_policy_t opal_hwloc_binding_policy = 0; +char *opal_hwloc_base_cpu_list = NULL; +bool opal_hwloc_report_bindings = false; +hwloc_obj_type_t opal_hwloc_levels[] = {HWLOC_OBJ_MACHINE, HWLOC_OBJ_NODE, HWLOC_OBJ_SOCKET, + HWLOC_OBJ_L3CACHE, HWLOC_OBJ_L2CACHE, HWLOC_OBJ_L1CACHE, + HWLOC_OBJ_CORE, HWLOC_OBJ_PU}; bool opal_hwloc_use_hwthreads_as_cpus = false; char *opal_hwloc_base_topo_file = NULL; -static mca_base_var_enum_value_t hwloc_base_map[] = { - {OPAL_HWLOC_BASE_MAP_NONE, "none"}, - {OPAL_HWLOC_BASE_MAP_LOCAL_ONLY, "local_only"}, - {0, NULL} -}; +static mca_base_var_enum_value_t hwloc_base_map[] = {{OPAL_HWLOC_BASE_MAP_NONE, "none"}, + {OPAL_HWLOC_BASE_MAP_LOCAL_ONLY, "local_only"}, + {0, NULL}}; -static mca_base_var_enum_value_t hwloc_failure_action[] = { - {OPAL_HWLOC_BASE_MBFA_SILENT, "silent"}, - {OPAL_HWLOC_BASE_MBFA_WARN, "warn"}, - {OPAL_HWLOC_BASE_MBFA_ERROR, "error"}, - {0, NULL} -}; +static mca_base_var_enum_value_t hwloc_failure_action[] = {{OPAL_HWLOC_BASE_MBFA_SILENT, "silent"}, + {OPAL_HWLOC_BASE_MBFA_WARN, "warn"}, + {OPAL_HWLOC_BASE_MBFA_ERROR, "error"}, + {0, NULL}}; static int opal_hwloc_base_register(mca_base_register_flag_t flags); static int opal_hwloc_base_open(mca_base_open_flag_t flags); static int opal_hwloc_base_close(void); -MCA_BASE_FRAMEWORK_DECLARE(opal, hwloc, NULL, opal_hwloc_base_register, opal_hwloc_base_open, opal_hwloc_base_close, - mca_hwloc_base_static_components, 0); +MCA_BASE_FRAMEWORK_DECLARE(opal, hwloc, NULL, opal_hwloc_base_register, opal_hwloc_base_open, + opal_hwloc_base_close, mca_hwloc_base_static_components, 0); static char *opal_hwloc_base_binding_policy = NULL; static bool opal_hwloc_base_bind_to_core = false; @@ -93,13 +79,17 @@ static int opal_hwloc_base_register(mca_base_register_flag_t flags) opal_hwloc_base_map = OPAL_HWLOC_BASE_MAP_NONE; mca_base_var_enum_create("hwloc memory allocation policy", hwloc_base_map, &new_enum); - ret = mca_base_var_register("opal", "hwloc", "base", "mem_alloc_policy", - "General memory allocations placement policy (this is not memory binding). " - "\"none\" means that no memory policy is applied. \"local_only\" means that a process' memory allocations will be restricted to its local NUMA node. " - "If using direct launch, this policy will not be in effect until after MPI_INIT. " - "Note that operating system paging policies are unaffected by this setting. For example, if \"local_only\" is used and local NUMA node memory is exhausted, a new memory allocation may cause paging.", - MCA_BASE_VAR_TYPE_INT, new_enum, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_base_map); + ret = mca_base_var_register( + "opal", "hwloc", "base", "mem_alloc_policy", + "General memory allocations placement policy (this is not memory binding). " + "\"none\" means that no memory policy is applied. \"local_only\" means that a process' " + "memory allocations will be restricted to its local NUMA node. " + "If using direct launch, this policy will not be in effect until after MPI_INIT. " + "Note that operating system paging policies are unaffected by this setting. For example, " + "if \"local_only\" is used and local NUMA node memory is exhausted, a new memory " + "allocation may cause paging.", + MCA_BASE_VAR_TYPE_INT, new_enum, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_hwloc_base_map); OBJ_RELEASE(new_enum); if (0 > ret) { return ret; @@ -108,23 +98,31 @@ static int opal_hwloc_base_register(mca_base_register_flag_t flags) /* hwloc_base_bind_failure_action */ opal_hwloc_base_mbfa = OPAL_HWLOC_BASE_MBFA_WARN; mca_base_var_enum_create("hwloc memory bind failure action", hwloc_failure_action, &new_enum); - ret = mca_base_var_register("opal", "hwloc", "base", "mem_bind_failure_action", - "What Open MPI will do if it explicitly tries to bind memory to a specific NUMA location, and fails. Note that this is a different case than the general allocation policy described by hwloc_base_alloc_policy. A value of \"silent\" means that Open MPI will proceed without comment. A value of \"warn\" means that Open MPI will warn the first time this happens, but allow the job to continue (possibly with degraded performance). A value of \"error\" means that Open MPI will abort the job if this happens.", - MCA_BASE_VAR_TYPE_INT, new_enum, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_base_mbfa); + ret = mca_base_var_register( + "opal", "hwloc", "base", "mem_bind_failure_action", + "What Open MPI will do if it explicitly tries to bind memory to a specific NUMA location, " + "and fails. Note that this is a different case than the general allocation policy " + "described by hwloc_base_alloc_policy. A value of \"silent\" means that Open MPI will " + "proceed without comment. A value of \"warn\" means that Open MPI will warn the first time " + "this happens, but allow the job to continue (possibly with degraded performance). A " + "value of \"error\" means that Open MPI will abort the job if this happens.", + MCA_BASE_VAR_TYPE_INT, new_enum, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_hwloc_base_mbfa); OBJ_RELEASE(new_enum); if (0 > ret) { return ret; } opal_hwloc_base_binding_policy = NULL; - (void) mca_base_var_register("opal", "hwloc", "base", "binding_policy", - "Policy for binding processes. Allowed values: none, hwthread, core, l1cache, l2cache, " - "l3cache, socket, numa, board, cpu-list (\"none\" is the default when oversubscribed, \"core\" is " - "the default when np<=2, and \"numa\" is the default when np>2). Allowed qualifiers: " - "overload-allowed, if-supported, ordered", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_base_binding_policy); + (void) mca_base_var_register( + "opal", "hwloc", "base", "binding_policy", + "Policy for binding processes. Allowed values: none, hwthread, core, l1cache, l2cache, " + "l3cache, socket, numa, board, cpu-list (\"none\" is the default when oversubscribed, " + "\"core\" is " + "the default when np<=2, and \"numa\" is the default when np>2). Allowed qualifiers: " + "overload-allowed, if-supported, ordered", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_hwloc_base_binding_policy); /* backward compatibility */ opal_hwloc_base_bind_to_core = false; @@ -133,29 +131,34 @@ static int opal_hwloc_base_register(mca_base_register_flag_t flags) MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_base_bind_to_core); opal_hwloc_base_bind_to_socket = false; - (void) mca_base_var_register("opal", "hwloc", "base", "bind_to_socket", "Bind processes to sockets", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_base_bind_to_socket); + (void) mca_base_var_register("opal", "hwloc", "base", "bind_to_socket", + "Bind processes to sockets", MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_hwloc_base_bind_to_socket); opal_hwloc_report_bindings = false; - (void) mca_base_var_register("opal", "hwloc", "base", "report_bindings", "Report bindings to stderr", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_report_bindings); + (void) mca_base_var_register("opal", "hwloc", "base", "report_bindings", + "Report bindings to stderr", MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_hwloc_report_bindings); opal_hwloc_base_cpu_list = NULL; varid = mca_base_var_register("opal", "hwloc", "base", "cpu_list", - "Comma-separated list of ranges specifying logical cpus to be used by these processes [default: none]", + "Comma-separated list of ranges specifying logical cpus to be " + "used by these processes [default: none]", MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_base_cpu_list); - mca_base_var_register_synonym (varid, "opal", "hwloc", "base", "slot_list", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); - mca_base_var_register_synonym (varid, "opal", "hwloc", "base", "cpu_set", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); + mca_base_var_register_synonym(varid, "opal", "hwloc", "base", "slot_list", + MCA_BASE_VAR_SYN_FLAG_DEPRECATED); + mca_base_var_register_synonym(varid, "opal", "hwloc", "base", "cpu_set", + MCA_BASE_VAR_SYN_FLAG_DEPRECATED); /* declare hwthreads as independent cpus */ opal_hwloc_use_hwthreads_as_cpus = false; (void) mca_base_var_register("opal", "hwloc", "base", "use_hwthreads_as_cpus", - "Use hardware threads as independent cpus", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_hwloc_use_hwthreads_as_cpus); + "Use hardware threads as independent cpus", MCA_BASE_VAR_TYPE_BOOL, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_hwloc_use_hwthreads_as_cpus); opal_hwloc_base_topo_file = NULL; (void) mca_base_var_register("opal", "hwloc", "base", "topo_file", @@ -176,36 +179,37 @@ static int opal_hwloc_base_open(mca_base_open_flag_t flags) } opal_hwloc_base_inited = true; - if (OPAL_SUCCESS != (rc = opal_hwloc_base_set_binding_policy(&opal_hwloc_binding_policy, - opal_hwloc_base_binding_policy))) { + if (OPAL_SUCCESS + != (rc = opal_hwloc_base_set_binding_policy(&opal_hwloc_binding_policy, + opal_hwloc_base_binding_policy))) { return rc; } if (opal_hwloc_base_bind_to_core) { - opal_show_help("help-opal-hwloc-base.txt", "deprecated", true, - "--bind-to-core", "--bind-to core", - "hwloc_base_bind_to_core", "hwloc_base_binding_policy=core"); + opal_show_help("help-opal-hwloc-base.txt", "deprecated", true, "--bind-to-core", + "--bind-to core", "hwloc_base_bind_to_core", + "hwloc_base_binding_policy=core"); /* set binding policy to core - error if something else already set */ - if (OPAL_BINDING_POLICY_IS_SET(opal_hwloc_binding_policy) && - OPAL_GET_BINDING_POLICY(opal_hwloc_binding_policy) != OPAL_BIND_TO_CORE) { + if (OPAL_BINDING_POLICY_IS_SET(opal_hwloc_binding_policy) + && OPAL_GET_BINDING_POLICY(opal_hwloc_binding_policy) != OPAL_BIND_TO_CORE) { /* error - cannot redefine the default ranking policy */ - opal_show_help("help-opal-hwloc-base.txt", "redefining-policy", true, - "core", opal_hwloc_base_print_binding(opal_hwloc_binding_policy)); + opal_show_help("help-opal-hwloc-base.txt", "redefining-policy", true, "core", + opal_hwloc_base_print_binding(opal_hwloc_binding_policy)); return OPAL_ERR_BAD_PARAM; } OPAL_SET_BINDING_POLICY(opal_hwloc_binding_policy, OPAL_BIND_TO_CORE); } if (opal_hwloc_base_bind_to_socket) { - opal_show_help("help-opal-hwloc-base.txt", "deprecated", true, - "--bind-to-socket", "--bind-to socket", - "hwloc_base_bind_to_socket", "hwloc_base_binding_policy=socket"); + opal_show_help("help-opal-hwloc-base.txt", "deprecated", true, "--bind-to-socket", + "--bind-to socket", "hwloc_base_bind_to_socket", + "hwloc_base_binding_policy=socket"); /* set binding policy to socket - error if something else already set */ - if (OPAL_BINDING_POLICY_IS_SET(opal_hwloc_binding_policy) && - OPAL_GET_BINDING_POLICY(opal_hwloc_binding_policy) != OPAL_BIND_TO_SOCKET) { + if (OPAL_BINDING_POLICY_IS_SET(opal_hwloc_binding_policy) + && OPAL_GET_BINDING_POLICY(opal_hwloc_binding_policy) != OPAL_BIND_TO_SOCKET) { /* error - cannot redefine the default ranking policy */ - opal_show_help("help-opal-hwloc-base.txt", "redefining-policy", true, - "socket", opal_hwloc_base_print_binding(opal_hwloc_binding_policy)); + opal_show_help("help-opal-hwloc-base.txt", "redefining-policy", true, "socket", + opal_hwloc_base_print_binding(opal_hwloc_binding_policy)); return OPAL_ERR_SILENT; } OPAL_SET_BINDING_POLICY(opal_hwloc_binding_policy, OPAL_BIND_TO_SOCKET); @@ -217,11 +221,11 @@ static int opal_hwloc_base_open(mca_base_open_flag_t flags) * we do bind to the given cpus if provided, otherwise this would be * ignored if someone didn't also specify a binding policy */ -// Restoring pre ef86707fbe3392c8ed15f79cc4892f0313b409af behavior. -// Formerly -cpu-set #,#,# along with -use_hwthread-cpus resulted -// in the binding policy staying OPAL_BIND_TO_HWTHREAD -// I think that should be right because I thought -cpu-set was a contraint you put -// on another binding policy, not a binding policy in itself. + // Restoring pre ef86707fbe3392c8ed15f79cc4892f0313b409af behavior. + // Formerly -cpu-set #,#,# along with -use_hwthread-cpus resulted + // in the binding policy staying OPAL_BIND_TO_HWTHREAD + // I think that should be right because I thought -cpu-set was a contraint you put + // on another binding policy, not a binding policy in itself. if (!OPAL_BINDING_POLICY_IS_SET(opal_hwloc_binding_policy)) { OPAL_SET_BINDING_POLICY(opal_hwloc_binding_policy, OPAL_BIND_TO_CPUSET); } @@ -235,8 +239,7 @@ static int opal_hwloc_base_open(mca_base_open_flag_t flags) /* to support tools such as ompi_info, add the components * to a list */ - if (OPAL_SUCCESS != - mca_base_framework_components_open(&opal_hwloc_base_framework, flags)) { + if (OPAL_SUCCESS != mca_base_framework_components_open(&opal_hwloc_base_framework, flags)) { return OPAL_ERROR; } @@ -260,7 +263,7 @@ static int opal_hwloc_base_close(void) /* no need to close the component as it was statically opened */ /* for support of tools such as ompi_info */ - ret = mca_base_framework_components_close (&opal_hwloc_base_framework, NULL); + ret = mca_base_framework_components_close(&opal_hwloc_base_framework, NULL); if (OPAL_SUCCESS != ret) { return ret; } @@ -277,14 +280,13 @@ static int opal_hwloc_base_close(void) opal_hwloc_topology = NULL; } - /* All done */ opal_hwloc_base_inited = false; return OPAL_SUCCESS; } -static bool fns_init=false; -char* opal_hwloc_print_null = "NULL"; +static bool fns_init = false; +char *opal_hwloc_print_null = "NULL"; static void buffer_cleanup(void *value) { @@ -292,8 +294,8 @@ static void buffer_cleanup(void *value) opal_hwloc_print_buffers_t *ptr; if (NULL != value) { - ptr = (opal_hwloc_print_buffers_t*)value; - for (i=0; i < OPAL_HWLOC_PRINT_NUM_BUFS; i++) { + ptr = (opal_hwloc_print_buffers_t *) value; + for (i = 0; i < OPAL_HWLOC_PRINT_NUM_BUFS; i++) { free(ptr->buffers[i]); } free(ptr); @@ -312,22 +314,24 @@ opal_hwloc_print_buffers_t *opal_hwloc_get_print_buffer(void) fns_init = true; } - ret = opal_tsd_tracked_key_get(print_tsd_key, (void**)&ptr); - if (OPAL_SUCCESS != ret) return NULL; + ret = opal_tsd_tracked_key_get(print_tsd_key, (void **) &ptr); + if (OPAL_SUCCESS != ret) { + return NULL; + } if (NULL == ptr) { - ptr = (opal_hwloc_print_buffers_t*)malloc(sizeof(opal_hwloc_print_buffers_t)); - for (i=0; i < OPAL_HWLOC_PRINT_NUM_BUFS; i++) { - ptr->buffers[i] = (char *) malloc((OPAL_HWLOC_PRINT_MAX_SIZE+1) * sizeof(char)); + ptr = (opal_hwloc_print_buffers_t *) malloc(sizeof(opal_hwloc_print_buffers_t)); + for (i = 0; i < OPAL_HWLOC_PRINT_NUM_BUFS; i++) { + ptr->buffers[i] = (char *) malloc((OPAL_HWLOC_PRINT_MAX_SIZE + 1) * sizeof(char)); } ptr->cntr = 0; - ret = opal_tsd_tracked_key_set(print_tsd_key, (void*)ptr); + ret = opal_tsd_tracked_key_set(print_tsd_key, (void *) ptr); } - return (opal_hwloc_print_buffers_t*) ptr; + return (opal_hwloc_print_buffers_t *) ptr; } -char* opal_hwloc_base_print_locality(opal_hwloc_locality_t locality) +char *opal_hwloc_base_print_locality(opal_hwloc_locality_t locality) { opal_hwloc_print_buffers_t *ptr; int idx; @@ -396,7 +400,7 @@ char* opal_hwloc_base_print_locality(opal_hwloc_locality_t locality) ptr->buffers[ptr->cntr][idx++] = ':'; } if (0 < idx) { - ptr->buffers[ptr->cntr][idx-1] = '\0'; + ptr->buffers[ptr->cntr][idx - 1] = '\0'; } else if (OPAL_PROC_NON_LOCAL & locality) { ptr->buffers[ptr->cntr][idx++] = 'N'; ptr->buffers[ptr->cntr][idx++] = 'O'; @@ -420,9 +424,7 @@ static void obj_data_const(opal_hwloc_obj_data_t *ptr) ptr->idx = UINT_MAX; ptr->num_bound = 0; } -OBJ_CLASS_INSTANCE(opal_hwloc_obj_data_t, - opal_object_t, - obj_data_const, NULL); +OBJ_CLASS_INSTANCE(opal_hwloc_obj_data_t, opal_object_t, obj_data_const, NULL); static void sum_const(opal_hwloc_summary_t *ptr) { @@ -438,9 +440,7 @@ static void sum_dest(opal_hwloc_summary_t *ptr) } OBJ_DESTRUCT(&ptr->sorted_by_dist_list); } -OBJ_CLASS_INSTANCE(opal_hwloc_summary_t, - opal_list_item_t, - sum_const, sum_dest); +OBJ_CLASS_INSTANCE(opal_hwloc_summary_t, opal_list_item_t, sum_const, sum_dest); static void topo_data_const(opal_hwloc_topo_data_t *ptr) { ptr->available = NULL; @@ -460,15 +460,9 @@ static void topo_data_dest(opal_hwloc_topo_data_t *ptr) OBJ_DESTRUCT(&ptr->summaries); ptr->userdata = NULL; } -OBJ_CLASS_INSTANCE(opal_hwloc_topo_data_t, - opal_object_t, - topo_data_const, - topo_data_dest); +OBJ_CLASS_INSTANCE(opal_hwloc_topo_data_t, opal_object_t, topo_data_const, topo_data_dest); -OBJ_CLASS_INSTANCE(opal_rmaps_numa_node_t, - opal_list_item_t, - NULL, - NULL); +OBJ_CLASS_INSTANCE(opal_rmaps_numa_node_t, opal_list_item_t, NULL, NULL); int opal_hwloc_base_set_binding_policy(opal_binding_policy_t *policy, char *spec) { @@ -498,11 +492,13 @@ int opal_hwloc_base_set_binding_policy(opal_binding_policy_t *policy, char *spec } else { quals = opal_argv_split(tmpvals[1], ','); } - for (i=0; NULL != quals[i]; i++) { + for (i = 0; NULL != quals[i]; i++) { if (0 == strncasecmp(quals[i], "if-supported", strlen(quals[i]))) { tmp |= OPAL_BIND_IF_SUPPORTED; - } else if (0 == strncasecmp(quals[i], "overload-allowed", strlen(quals[i])) || - 0 == strncasecmp(quals[i], "oversubscribe-allowed", strlen(quals[i]))) { + } else if (0 == strncasecmp(quals[i], "overload-allowed", strlen(quals[i])) + || 0 + == strncasecmp(quals[i], "oversubscribe-allowed", + strlen(quals[i]))) { tmp |= OPAL_BIND_ALLOW_OVERLOAD; } else if (0 == strncasecmp(quals[i], "ordered", strlen(quals[i]))) { tmp |= OPAL_BIND_ORDERED; @@ -536,14 +532,15 @@ int opal_hwloc_base_set_binding_policy(opal_binding_policy_t *policy, char *spec OPAL_SET_BINDING_POLICY(tmp, OPAL_BIND_TO_NUMA); } else if (0 == strcasecmp(tmpvals[0], "board")) { OPAL_SET_BINDING_POLICY(tmp, OPAL_BIND_TO_BOARD); - } else if (0 == strcasecmp(tmpvals[0], "cpu-list") || - 0 == strcasecmp(tmpvals[0], "cpulist")) { + } else if (0 == strcasecmp(tmpvals[0], "cpu-list") + || 0 == strcasecmp(tmpvals[0], "cpulist")) { // Accept both "cpu-list" (which matches the // "--cpu-list" CLI option) and "cpulist" (because // people will be lazy) OPAL_SET_BINDING_POLICY(tmp, OPAL_BIND_TO_CPUSET); } else { - opal_show_help("help-opal-hwloc-base.txt", "invalid binding_policy", true, "binding", spec); + opal_show_help("help-opal-hwloc-base.txt", "invalid binding_policy", true, + "binding", spec); opal_argv_free(tmpvals); return OPAL_ERR_BAD_PARAM; } diff --git a/opal/mca/hwloc/base/hwloc_base_maffinity.c b/opal/mca/hwloc/base/hwloc_base_maffinity.c index 4b442037e3d..a29af1aed4b 100644 --- a/opal/mca/hwloc/base/hwloc_base_maffinity.c +++ b/opal/mca/hwloc/base/hwloc_base_maffinity.c @@ -8,14 +8,12 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/hwloc/base/base.h" - +#include "opal/mca/hwloc/hwloc-internal.h" /* * Don't use show_help() here (or print any error message at all). @@ -57,16 +55,14 @@ int opal_hwloc_base_set_process_membind_policy(void) } else { int e; hwloc_get_cpubind(opal_hwloc_topology, cpuset, 0); - rc = hwloc_set_membind(opal_hwloc_topology, - cpuset, policy, flags); + rc = hwloc_set_membind(opal_hwloc_topology, cpuset, policy, flags); e = errno; hwloc_bitmap_free(cpuset); /* See if hwloc was able to do it. If hwloc failed due to ENOSYS, but the base_map == NONE, then it's not really an error. */ - if (0 != rc && ENOSYS == e && - OPAL_HWLOC_BASE_MAP_NONE == opal_hwloc_base_map) { + if (0 != rc && ENOSYS == e && OPAL_HWLOC_BASE_MAP_NONE == opal_hwloc_base_map) { rc = 0; } } @@ -74,8 +70,7 @@ int opal_hwloc_base_set_process_membind_policy(void) return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } -int opal_hwloc_base_memory_set(opal_hwloc_base_memory_segment_t *segments, - size_t num_segments) +int opal_hwloc_base_memory_set(opal_hwloc_base_memory_segment_t *segments, size_t num_segments) { int rc = OPAL_SUCCESS; char *msg = NULL; @@ -85,8 +80,7 @@ int opal_hwloc_base_memory_set(opal_hwloc_base_memory_segment_t *segments, /* bozo check */ if (OPAL_SUCCESS != opal_hwloc_base_get_topology()) { msg = "hwloc_set_area_membind() failure - topology not available"; - return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__, - msg, rc); + return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__, msg, rc); } /* This module won't be used unless the process is already @@ -100,18 +94,17 @@ int opal_hwloc_base_memory_set(opal_hwloc_base_memory_segment_t *segments, } hwloc_get_cpubind(opal_hwloc_topology, cpuset, 0); for (i = 0; i < num_segments; ++i) { - if (0 != hwloc_set_area_membind(opal_hwloc_topology, - segments[i].mbs_start_addr, - segments[i].mbs_len, cpuset, - HWLOC_MEMBIND_BIND, - HWLOC_MEMBIND_STRICT)) { + if (0 + != hwloc_set_area_membind(opal_hwloc_topology, segments[i].mbs_start_addr, + segments[i].mbs_len, cpuset, HWLOC_MEMBIND_BIND, + HWLOC_MEMBIND_STRICT)) { rc = OPAL_ERROR; msg = "hwloc_set_area_membind() failure"; goto out; } } - out: +out: if (NULL != cpuset) { hwloc_bitmap_free(cpuset); } @@ -129,8 +122,7 @@ int opal_hwloc_base_node_name_to_id(char *node_name, int *id) return OPAL_SUCCESS; } -int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, - size_t count, int node_id) +int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, size_t count, int node_id) { size_t i; int rc = OPAL_SUCCESS; @@ -140,8 +132,7 @@ int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, /* bozo check */ if (OPAL_SUCCESS != opal_hwloc_base_get_topology()) { msg = "hwloc_set_area_membind() failure - topology not available"; - return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__, - msg, rc); + return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__, msg, rc); } cpuset = hwloc_bitmap_alloc(); @@ -151,19 +142,17 @@ int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, goto out; } hwloc_bitmap_set(cpuset, node_id); - for(i = 0; i < count; i++) { - if (0 != hwloc_set_area_membind(opal_hwloc_topology, - segs[i].mbs_start_addr, - segs[i].mbs_len, cpuset, - HWLOC_MEMBIND_BIND, - HWLOC_MEMBIND_STRICT)) { + for (i = 0; i < count; i++) { + if (0 + != hwloc_set_area_membind(opal_hwloc_topology, segs[i].mbs_start_addr, segs[i].mbs_len, + cpuset, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_STRICT)) { rc = OPAL_ERROR; msg = "hwloc_set_area_membind() failure"; goto out; } } - out: +out: if (NULL != cpuset) { hwloc_bitmap_free(cpuset); } diff --git a/opal/mca/hwloc/base/hwloc_base_proc_mempolicy.c b/opal/mca/hwloc/base/hwloc_base_proc_mempolicy.c index 54c55648a78..b535659a40c 100644 --- a/opal/mca/hwloc/base/hwloc_base_proc_mempolicy.c +++ b/opal/mca/hwloc/base/hwloc_base_proc_mempolicy.c @@ -7,14 +7,12 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/hwloc/base/base.h" - +#include "opal/mca/hwloc/hwloc-internal.h" /* * Don't use show_help() here (or print any error message at all). @@ -56,16 +54,14 @@ int opal_hwloc_base_set_process_membind_policy(void) } else { int e; hwloc_get_cpubind(opal_hwloc_topology, cpuset, 0); - rc = hwloc_set_membind(opal_hwloc_topology, - cpuset, policy, flags); + rc = hwloc_set_membind(opal_hwloc_topology, cpuset, policy, flags); e = errno; hwloc_bitmap_free(cpuset); /* See if hwloc was able to do it. If hwloc failed due to ENOSYS, but the base_map == NONE, then it's not really an error. */ - if (0 != rc && ENOSYS == e && - OPAL_HWLOC_BASE_MAP_NONE == opal_hwloc_base_map) { + if (0 != rc && ENOSYS == e && OPAL_HWLOC_BASE_MAP_NONE == opal_hwloc_base_map) { rc = 0; } } diff --git a/opal/mca/hwloc/base/hwloc_base_util.c b/opal/mca/hwloc/base/hwloc_base_util.c index d8ac76b0199..5afa0b9d80d 100644 --- a/opal/mca/hwloc/base/hwloc_base_util.c +++ b/opal/mca/hwloc/base/hwloc_base_util.c @@ -33,33 +33,33 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_ENDIAN_H -#include +# include #endif #ifdef HAVE_SYS_STAT_H -#include +# include #endif #if HAVE_FCNTL_H -#include +# include #endif -#include "opal/runtime/opal.h" #include "opal/constants.h" +#include "opal/mca/pmix/pmix-internal.h" +#include "opal/mca/threads/tsd.h" +#include "opal/runtime/opal.h" #include "opal/util/argv.h" -#include "opal/util/output.h" #include "opal/util/os_dirpath.h" -#include "opal/util/show_help.h" +#include "opal/util/output.h" #include "opal/util/printf.h" -#include "opal/mca/pmix/pmix-internal.h" -#include "opal/mca/threads/tsd.h" +#include "opal/util/show_help.h" -#include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/hwloc/base/base.h" +#include "opal/mca/hwloc/hwloc-internal.h" static bool topo_in_shmem = false; @@ -70,9 +70,7 @@ static bool topo_in_shmem = false; * only find PUs (!). On such platforms, then do the same calculation * but with PUs instead of COREs. */ -hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, - int lid, - opal_hwloc_resource_type_t rtype) +hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, int lid, opal_hwloc_resource_type_t rtype) { hwloc_obj_type_t obj_type = HWLOC_OBJ_CORE; hwloc_obj_t obj; @@ -90,7 +88,8 @@ hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, So first we have to see if we can find *any* cores by looking for the 0th core. If we find it, then try to find the Nth core. Otherwise, try to find the Nth PU. */ - if (opal_hwloc_use_hwthreads_as_cpus || (NULL == hwloc_get_obj_by_type(topo, HWLOC_OBJ_CORE, 0))) { + if (opal_hwloc_use_hwthreads_as_cpus + || (NULL == hwloc_get_obj_by_type(topo, HWLOC_OBJ_CORE, 0))) { obj_type = HWLOC_OBJ_PU; } @@ -100,10 +99,10 @@ hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, * numbered within their sockets instead). So we find the * specified PU, and then return the core object that contains it */ obj = hwloc_get_pu_obj_by_os_index(topo, lid); - OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, - "physical cpu %d %s found in cpuset %s", - lid, (NULL == obj) ? "not" : "is", - (NULL == opal_hwloc_base_cpu_list) ? "None" : opal_hwloc_base_cpu_list)); + OPAL_OUTPUT_VERBOSE( + (5, opal_hwloc_base_framework.framework_output, "physical cpu %d %s found in cpuset %s", + lid, (NULL == obj) ? "not" : "is", + (NULL == opal_hwloc_base_cpu_list) ? "None" : opal_hwloc_base_cpu_list)); /* we now need to shift upward to the core including this PU */ if (NULL != obj && HWLOC_OBJ_CORE == obj_type) { obj = obj->parent; @@ -117,8 +116,7 @@ hwloc_obj_t opal_hwloc_base_get_pu(hwloc_topology_t topo, /* Now do the actual lookup. */ obj = hwloc_get_obj_by_type(topo, obj_type, lid); OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, - "logical cpu %d %s found in cpuset %s", - lid, (NULL == obj) ? "not" : "is", + "logical cpu %d %s found in cpuset %s", lid, (NULL == obj) ? "not" : "is", (NULL == opal_hwloc_base_cpu_list) ? "None" : opal_hwloc_base_cpu_list)); /* Found the right core (or PU). Return the object */ @@ -134,15 +132,15 @@ int opal_hwloc_base_filter_cpus(hwloc_topology_t topo) hwloc_cpuset_t avail = NULL, pucpus, res; opal_hwloc_topo_data_t *sum; opal_hwloc_obj_data_t *data; - char **ranges=NULL, **range=NULL; + char **ranges = NULL, **range = NULL; int idx, cpu, start, end; root = hwloc_get_root_obj(topo); if (NULL == root->userdata) { - root->userdata = (void*)OBJ_NEW(opal_hwloc_topo_data_t); + root->userdata = (void *) OBJ_NEW(opal_hwloc_topo_data_t); } - sum = (opal_hwloc_topo_data_t*)root->userdata; + sum = (opal_hwloc_topo_data_t *) root->userdata; /* should only ever enter here once, but check anyway */ if (NULL != sum->available) { @@ -151,43 +149,43 @@ int opal_hwloc_base_filter_cpus(hwloc_topology_t topo) /* process any specified default cpu set against this topology */ if (NULL == opal_hwloc_base_cpu_list) { - /* get the root available cpuset */ - #if HWLOC_API_VERSION < 0x20000 - avail = hwloc_bitmap_alloc(); - hwloc_bitmap_and(avail, root->online_cpuset, root->allowed_cpuset); - #else - avail = hwloc_bitmap_dup(root->cpuset); - #endif +/* get the root available cpuset */ +#if HWLOC_API_VERSION < 0x20000 + avail = hwloc_bitmap_alloc(); + hwloc_bitmap_and(avail, root->online_cpuset, root->allowed_cpuset); +#else + avail = hwloc_bitmap_dup(root->cpuset); +#endif OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, "hwloc:base: no cpus specified - using root available cpuset")); } else { - OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, - "hwloc:base: filtering cpuset")); + OPAL_OUTPUT_VERBOSE( + (5, opal_hwloc_base_framework.framework_output, "hwloc:base: filtering cpuset")); /* find the specified logical cpus */ ranges = opal_argv_split(opal_hwloc_base_cpu_list, ','); avail = hwloc_bitmap_alloc(); hwloc_bitmap_zero(avail); res = hwloc_bitmap_alloc(); pucpus = hwloc_bitmap_alloc(); - for (idx=0; idx < opal_argv_count(ranges); idx++) { + for (idx = 0; idx < opal_argv_count(ranges); idx++) { range = opal_argv_split(ranges[idx], '-'); switch (opal_argv_count(range)) { case 1: /* only one cpu given - get that object */ cpu = strtoul(range[0], NULL, 10); if (NULL != (pu = opal_hwloc_base_get_pu(topo, cpu, OPAL_HWLOC_LOGICAL))) { - #if HWLOC_API_VERSION < 0x20000 - hwloc_bitmap_and(pucpus, pu->online_cpuset, pu->allowed_cpuset); - #else - hwloc_bitmap_free(pucpus); - pucpus = hwloc_bitmap_dup(pu->cpuset); - #endif +#if HWLOC_API_VERSION < 0x20000 + hwloc_bitmap_and(pucpus, pu->online_cpuset, pu->allowed_cpuset); +#else + hwloc_bitmap_free(pucpus); + pucpus = hwloc_bitmap_dup(pu->cpuset); +#endif hwloc_bitmap_or(res, avail, pucpus); hwloc_bitmap_copy(avail, res); - data = (opal_hwloc_obj_data_t*)pu->userdata; + data = (opal_hwloc_obj_data_t *) pu->userdata; if (NULL == data) { - pu->userdata = (void*)OBJ_NEW(opal_hwloc_obj_data_t); - data = (opal_hwloc_obj_data_t*)pu->userdata; + pu->userdata = (void *) OBJ_NEW(opal_hwloc_obj_data_t); + data = (opal_hwloc_obj_data_t *) pu->userdata; } data->npus++; } @@ -196,20 +194,20 @@ int opal_hwloc_base_filter_cpus(hwloc_topology_t topo) /* range given */ start = strtoul(range[0], NULL, 10); end = strtoul(range[1], NULL, 10); - for (cpu=start; cpu <= end; cpu++) { + for (cpu = start; cpu <= end; cpu++) { if (NULL != (pu = opal_hwloc_base_get_pu(topo, cpu, OPAL_HWLOC_LOGICAL))) { - #if HWLOC_API_VERSION < 0x20000 - hwloc_bitmap_and(pucpus, pu->online_cpuset, pu->allowed_cpuset); - #else - hwloc_bitmap_free(pucpus); - pucpus = hwloc_bitmap_dup(pu->cpuset); - #endif +#if HWLOC_API_VERSION < 0x20000 + hwloc_bitmap_and(pucpus, pu->online_cpuset, pu->allowed_cpuset); +#else + hwloc_bitmap_free(pucpus); + pucpus = hwloc_bitmap_dup(pu->cpuset); +#endif hwloc_bitmap_or(res, avail, pucpus); hwloc_bitmap_copy(avail, res); - data = (opal_hwloc_obj_data_t*)pu->userdata; + data = (opal_hwloc_obj_data_t *) pu->userdata; if (NULL == data) { - pu->userdata = (void*)OBJ_NEW(opal_hwloc_obj_data_t); - data = (opal_hwloc_obj_data_t*)pu->userdata; + pu->userdata = (void *) OBJ_NEW(opal_hwloc_obj_data_t); + data = (opal_hwloc_obj_data_t *) pu->userdata; } data->npus++; } @@ -244,19 +242,17 @@ static void fill_cache_line_size(void) /* Look for the smallest L2 cache size */ size = 4096; while (cache_level > 0 && !found) { - i=0; + i = 0; while (1) { - obj = opal_hwloc_base_get_obj_by_type(opal_hwloc_topology, - cache_object, cache_level, - i, OPAL_HWLOC_LOGICAL); + obj = opal_hwloc_base_get_obj_by_type(opal_hwloc_topology, cache_object, cache_level, i, + OPAL_HWLOC_LOGICAL); if (NULL == obj) { --cache_level; cache_object = HWLOC_OBJ_L1CACHE; break; } else { - if (NULL != obj->attr && - obj->attr->cache.linesize > 0 && - size > obj->attr->cache.linesize) { + if (NULL != obj->attr && obj->attr->cache.linesize > 0 + && size > obj->attr->cache.linesize) { size = obj->attr->cache.linesize; found = true; } @@ -284,8 +280,7 @@ int opal_hwloc_base_get_topology(void) char *shmemfile; #endif - opal_output_verbose(2, opal_hwloc_base_framework.framework_output, - "hwloc:base:get_topology"); + opal_output_verbose(2, opal_hwloc_base_framework.framework_output, "hwloc:base:get_topology"); /* see if we already have it */ if (NULL != opal_hwloc_topology) { @@ -296,11 +291,10 @@ int opal_hwloc_base_get_topology(void) // Did the user ask for a topo file at the mca line? // Check this first, before main methods. - if(NULL != opal_hwloc_base_topo_file) { + if (NULL != opal_hwloc_base_topo_file) { opal_output_verbose(1, opal_hwloc_base_framework.framework_output, - "hwloc:base loading topology from file %s", - opal_hwloc_base_topo_file); - if(OPAL_SUCCESS != (rc = opal_hwloc_base_set_topology(opal_hwloc_base_topo_file))) { + "hwloc:base loading topology from file %s", opal_hwloc_base_topo_file); + if (OPAL_SUCCESS != (rc = opal_hwloc_base_set_topology(opal_hwloc_base_topo_file))) { return rc; } goto done; @@ -308,17 +302,17 @@ int opal_hwloc_base_get_topology(void) #if HWLOC_API_VERSION >= 0x20000 opal_output_verbose(2, opal_hwloc_base_framework.framework_output, - "hwloc:base: looking for topology in shared memory"); + "hwloc:base: looking for topology in shared memory"); /* first try to get the shmem link, if available */ aptr = &addr; sptr = &size; - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_HWLOC_SHMEM_FILE, - &wildcard_rank, (void**)&shmemfile, PMIX_STRING); - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc2, PMIX_HWLOC_SHMEM_ADDR, - &wildcard_rank, (void**)&aptr, PMIX_SIZE); - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc3, PMIX_HWLOC_SHMEM_SIZE, - &wildcard_rank, (void**)&sptr, PMIX_SIZE); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_HWLOC_SHMEM_FILE, &wildcard_rank, (void **) &shmemfile, + PMIX_STRING); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc2, PMIX_HWLOC_SHMEM_ADDR, &wildcard_rank, (void **) &aptr, + PMIX_SIZE); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc3, PMIX_HWLOC_SHMEM_SIZE, &wildcard_rank, (void **) &sptr, + PMIX_SIZE); if (OPAL_SUCCESS == rc && OPAL_SUCCESS == rc2 && OPAL_SUCCESS == rc3) { if (0 > (fd = open(shmemfile, O_RDONLY))) { free(shmemfile); @@ -326,8 +320,7 @@ int opal_hwloc_base_get_topology(void) return OPAL_ERR_FILE_OPEN_FAILURE; } free(shmemfile); - if (0 != hwloc_shmem_topology_adopt(&opal_hwloc_topology, fd, - 0, (void*)addr, size, 0)) { + if (0 != hwloc_shmem_topology_adopt(&opal_hwloc_topology, fd, 0, (void *) addr, size, 0)) { if (4 < opal_output_get_verbosity(opal_hwloc_base_framework.framework_output)) { FILE *file = fopen("/proc/self/maps", "r"); if (file) { @@ -356,19 +349,15 @@ int opal_hwloc_base_get_topology(void) /* if that isn't available, then try to retrieve * the xml representation from the PMIx data store */ opal_output_verbose(1, opal_hwloc_base_framework.framework_output, - "hwloc:base[%s:%d] getting topology XML string", - __FILE__, __LINE__); + "hwloc:base[%s:%d] getting topology XML string", __FILE__, __LINE__); #if HWLOC_API_VERSION >= 0x20000 - OPAL_MODEX_RECV_VALUE_IMMEDIATE(rc, PMIX_HWLOC_XML_V2, - &wildcard_rank, &val, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_IMMEDIATE(rc, PMIX_HWLOC_XML_V2, &wildcard_rank, &val, PMIX_STRING); #else - OPAL_MODEX_RECV_VALUE_IMMEDIATE(rc, PMIX_HWLOC_XML_V1, - &wildcard_rank, &val, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_IMMEDIATE(rc, PMIX_HWLOC_XML_V1, &wildcard_rank, &val, PMIX_STRING); #endif if (rc != OPAL_SUCCESS) { /* check the old topo key to keep compatibility with older RMs */ - OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCAL_TOPO, - &wildcard_rank, &val, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCAL_TOPO, &wildcard_rank, &val, PMIX_STRING); } if (OPAL_SUCCESS == rc && NULL != val) { @@ -379,7 +368,7 @@ int opal_hwloc_base_get_topology(void) free(val); return OPAL_ERROR; } - if (0 != hwloc_topology_set_xmlbuffer(opal_hwloc_topology, val, strlen(val)+1)) { + if (0 != hwloc_topology_set_xmlbuffer(opal_hwloc_topology, val, strlen(val) + 1)) { free(val); hwloc_topology_destroy(opal_hwloc_topology); return OPAL_ERROR; @@ -387,9 +376,9 @@ int opal_hwloc_base_get_topology(void) /* since we are loading this from an external source, we have to * explicitly set a flag so hwloc sets things up correctly */ - if (0 != opal_hwloc_base_topology_set_flags(opal_hwloc_topology, - HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM, - true)) { + if (0 + != opal_hwloc_base_topology_set_flags(opal_hwloc_topology, + HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM, true)) { hwloc_topology_destroy(opal_hwloc_topology); free(val); return OPAL_ERROR; @@ -409,9 +398,9 @@ int opal_hwloc_base_get_topology(void) } else { opal_output_verbose(1, opal_hwloc_base_framework.framework_output, "hwloc:base discovering topology"); - if (0 != hwloc_topology_init(&opal_hwloc_topology) || - 0 != opal_hwloc_base_topology_set_flags(opal_hwloc_topology, 0, true) || - 0 != hwloc_topology_load(opal_hwloc_topology)) { + if (0 != hwloc_topology_init(&opal_hwloc_topology) + || 0 != opal_hwloc_base_topology_set_flags(opal_hwloc_topology, 0, true) + || 0 != hwloc_topology_load(opal_hwloc_topology)) { OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED); return OPAL_ERR_NOT_SUPPORTED; } @@ -422,7 +411,7 @@ int opal_hwloc_base_get_topology(void) } } - done: +done: /* fill opal_cache_line_size global with the smallest L1 cache line size */ @@ -440,10 +429,10 @@ int opal_hwloc_base_set_topology(char *topofile) { struct hwloc_topology_support *support; - OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, - "hwloc:base:set_topology %s", topofile)); + OPAL_OUTPUT_VERBOSE( + (5, opal_hwloc_base_framework.framework_output, "hwloc:base:set_topology %s", topofile)); - if (NULL != opal_hwloc_topology) { + if (NULL != opal_hwloc_topology) { hwloc_topology_destroy(opal_hwloc_topology); } if (0 != hwloc_topology_init(&opal_hwloc_topology)) { @@ -458,9 +447,9 @@ int opal_hwloc_base_set_topology(char *topofile) /* since we are loading this from an external source, we have to * explicitly set a flag so hwloc sets things up correctly */ - if (0 != opal_hwloc_base_topology_set_flags(opal_hwloc_topology, - HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM, - true)) { + if (0 + != opal_hwloc_base_topology_set_flags(opal_hwloc_topology, + HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM, true)) { hwloc_topology_destroy(opal_hwloc_topology); return OPAL_ERR_NOT_SUPPORTED; } @@ -476,7 +465,7 @@ int opal_hwloc_base_set_topology(char *topofile) * systems that use this option are likely to provide * binding support */ - support = (struct hwloc_topology_support*)hwloc_topology_get_support(opal_hwloc_topology); + support = (struct hwloc_topology_support *) hwloc_topology_get_support(opal_hwloc_topology); support->cpubind->set_thisproc_cpubind = true; support->membind->set_thisproc_membind = true; @@ -495,13 +484,13 @@ static void free_object(hwloc_obj_t obj) /* free any data hanging on this object */ if (NULL != obj->userdata) { - data = (opal_hwloc_obj_data_t*)obj->userdata; + data = (opal_hwloc_obj_data_t *) obj->userdata; OBJ_RELEASE(data); obj->userdata = NULL; } /* loop thru our children */ - for (k=0; k < obj->arity; k++) { + for (k = 0; k < obj->arity; k++) { free_object(obj->children[k]); } } @@ -516,14 +505,14 @@ void opal_hwloc_base_free_topology(hwloc_topology_t topo) obj = hwloc_get_root_obj(topo); /* release the root-level userdata */ if (NULL != obj->userdata) { - rdata = (opal_hwloc_topo_data_t*)obj->userdata; + rdata = (opal_hwloc_topo_data_t *) obj->userdata; OBJ_RELEASE(rdata); obj->userdata = NULL; } /* now recursively descend and release userdata * in the rest of the objects */ - for (k=0; k < obj->arity; k++) { + for (k = 0; k < obj->arity; k++) { free_object(obj->children[k]); } } @@ -540,9 +529,8 @@ void opal_hwloc_base_get_local_cpuset(void) } /* get the cpus we are bound to */ - if (hwloc_get_cpubind(opal_hwloc_topology, - opal_hwloc_my_cpuset, - HWLOC_CPUBIND_PROCESS) < 0) { + if (hwloc_get_cpubind(opal_hwloc_topology, opal_hwloc_my_cpuset, HWLOC_CPUBIND_PROCESS) + < 0) { /* we are not bound - use the root's available cpuset */ root = hwloc_get_root_obj(opal_hwloc_topology); hwloc_bitmap_copy(opal_hwloc_my_cpuset, root->cpuset); @@ -550,22 +538,19 @@ void opal_hwloc_base_get_local_cpuset(void) } } -int opal_hwloc_base_report_bind_failure(const char *file, - int line, - const char *msg, int rc) +int opal_hwloc_base_report_bind_failure(const char *file, int line, const char *msg, int rc) { static int already_reported = 0; - if (!already_reported && - OPAL_HWLOC_BASE_MBFA_SILENT != opal_hwloc_base_mbfa) { + if (!already_reported && OPAL_HWLOC_BASE_MBFA_SILENT != opal_hwloc_base_mbfa) { char hostname[OPAL_MAXHOSTNAMELEN]; gethostname(hostname, sizeof(hostname)); - opal_show_help("help-opal-hwloc-base.txt", "mbind failure", true, - hostname, getpid(), file, line, msg, - (OPAL_HWLOC_BASE_MBFA_WARN == opal_hwloc_base_mbfa) ? - "Warning -- your job will continue, but possibly with degraded performance" : - "ERROR -- your job may abort or behave erraticly"); + opal_show_help( + "help-opal-hwloc-base.txt", "mbind failure", true, hostname, getpid(), file, line, msg, + (OPAL_HWLOC_BASE_MBFA_WARN == opal_hwloc_base_mbfa) + ? "Warning -- your job will continue, but possibly with degraded performance" + : "ERROR -- your job may abort or behave erraticly"); already_reported = 1; return rc; } @@ -577,7 +562,7 @@ int opal_hwloc_base_report_bind_failure(const char *file, bool opal_hwloc_base_single_cpu(hwloc_cpuset_t cpuset) { int i; - bool one=false; + bool one = false; /* count the number of bits that are set - there is * one bit for each available pu. We could just @@ -587,9 +572,7 @@ bool opal_hwloc_base_single_cpu(hwloc_cpuset_t cpuset) * search for them. Return false if we anything * other than one */ - for (i=hwloc_bitmap_first(cpuset); - i <= hwloc_bitmap_last(cpuset); - i++) { + for (i = hwloc_bitmap_first(cpuset); i <= hwloc_bitmap_last(cpuset); i++) { if (hwloc_bitmap_isset(cpuset, i)) { if (one) { return false; @@ -607,13 +590,9 @@ bool opal_hwloc_base_single_cpu(hwloc_cpuset_t cpuset) * in an attribute union. So looking for cache objects involves * a multi-step test :-( */ -static hwloc_obj_t df_search(hwloc_topology_t topo, - hwloc_obj_t start, - hwloc_obj_type_t target, - unsigned cache_level, - unsigned int nobj, - opal_hwloc_resource_type_t rtype, - unsigned int *num_objs) +static hwloc_obj_t df_search(hwloc_topology_t topo, hwloc_obj_t start, hwloc_obj_type_t target, + unsigned cache_level, unsigned int nobj, + opal_hwloc_resource_type_t rtype, unsigned int *num_objs) { hwloc_obj_t obj; int search_depth; @@ -629,12 +608,14 @@ static hwloc_obj_t df_search(hwloc_topology_t topo, search_depth = hwloc_get_cache_type_depth(topo, cache_level, (hwloc_obj_cache_type_t) -1); #endif } - if (HWLOC_TYPE_DEPTH_UNKNOWN == search_depth) + if (HWLOC_TYPE_DEPTH_UNKNOWN == search_depth) { return NULL; + } if (OPAL_HWLOC_LOGICAL == rtype) { - if (num_objs) + if (num_objs) { *num_objs = hwloc_get_nbobjs_by_depth(topo, search_depth); + } return hwloc_get_obj_by_depth(topo, search_depth, nobj); } if (OPAL_HWLOC_PHYSICAL == rtype) { @@ -651,25 +632,28 @@ static hwloc_obj_t df_search(hwloc_topology_t topo, */ hwloc_obj_t found = NULL; obj = NULL; - if (num_objs) + if (num_objs) { *num_objs = 0; + } while ((obj = hwloc_get_next_obj_by_depth(topo, search_depth, obj)) != NULL) { - if (num_objs && obj->os_index > *num_objs) + if (num_objs && obj->os_index > *num_objs) { *num_objs = obj->os_index; - if (obj->os_index == nobj) + } + if (obj->os_index == nobj) { found = obj; + } } return found; } if (OPAL_HWLOC_AVAILABLE == rtype) { -// The previous (3.x) code included a check for -// available = opal_hwloc_base_get_available_cpus(topo, start) -// and skipped objs that had hwloc_bitmap_iszero(available) + // The previous (3.x) code included a check for + // available = opal_hwloc_base_get_available_cpus(topo, start) + // and skipped objs that had hwloc_bitmap_iszero(available) hwloc_obj_t root; opal_hwloc_topo_data_t *rdata = NULL; root = hwloc_get_root_obj(topo); - if(false == topo_in_shmem) { - rdata = (opal_hwloc_topo_data_t*)root->userdata; + if (false == topo_in_shmem) { + rdata = (opal_hwloc_topo_data_t *) root->userdata; } hwloc_cpuset_t constrained_cpuset; @@ -681,10 +665,14 @@ static hwloc_obj_t df_search(hwloc_topology_t topo, } unsigned idx = 0; - if (num_objs) - *num_objs = hwloc_get_nbobjs_inside_cpuset_by_depth(topo, constrained_cpuset, search_depth); + if (num_objs) { + *num_objs = hwloc_get_nbobjs_inside_cpuset_by_depth(topo, constrained_cpuset, + search_depth); + } obj = NULL; - while ((obj = hwloc_get_next_obj_inside_cpuset_by_depth(topo, constrained_cpuset, search_depth, obj)) != NULL) { + while ((obj = hwloc_get_next_obj_inside_cpuset_by_depth(topo, constrained_cpuset, + search_depth, obj)) + != NULL) { if (idx == nobj) { hwloc_bitmap_free(constrained_cpuset); return obj; @@ -697,8 +685,7 @@ static hwloc_obj_t df_search(hwloc_topology_t topo, return NULL; } -unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, - hwloc_obj_type_t target, +unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, hwloc_obj_type_t target, unsigned cache_level, opal_hwloc_resource_type_t rtype) { @@ -710,8 +697,8 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, /* bozo check */ if (NULL == topo) { - OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, - "hwloc:base:get_nbobjs NULL topology")); + OPAL_OUTPUT_VERBOSE( + (5, opal_hwloc_base_framework.framework_output, "hwloc:base:get_nbobjs NULL topology")); return 0; } @@ -723,7 +710,7 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, #if HWLOC_API_VERSION < 0x20000 && HWLOC_OBJ_CACHE != target #endif - ) { + ) { /* we should not get an error back, but just in case... */ if (0 > (rc = hwloc_get_nbobjs_by_type(topo, target))) { opal_output(0, "UNKNOWN HWLOC ERROR"); @@ -737,22 +724,20 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, obj = hwloc_get_root_obj(topo); /* first see if the topology already has this summary */ - if(false == topo_in_shmem) { - data = (opal_hwloc_topo_data_t*)obj->userdata; + if (false == topo_in_shmem) { + data = (opal_hwloc_topo_data_t *) obj->userdata; } if (NULL == data) { data = OBJ_NEW(opal_hwloc_topo_data_t); - if(false == topo_in_shmem) { + if (false == topo_in_shmem) { // Can't touch userdata if in read-only shmem! // We have to protect here for the case where obj->userdata // is in shmem and it is NULL. - obj->userdata = (void*) data; + obj->userdata = (void *) data; } } else { - OPAL_LIST_FOREACH(sum, &data->summaries, opal_hwloc_summary_t) { - if (target == sum->type && - cache_level == sum->cache_level && - rtype == sum->rtype) { + OPAL_LIST_FOREACH (sum, &data->summaries, opal_hwloc_summary_t) { + if (target == sum->type && cache_level == sum->cache_level && rtype == sum->rtype) { /* yep - return the value */ OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, "hwloc:base:get_nbojbs pre-existing data %u of %s:%u", @@ -774,8 +759,8 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, opal_list_append(&data->summaries, &sum->super); OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output, - "hwloc:base:get_nbojbs computed data %u of %s:%u", - num_objs, hwloc_obj_type_string(target), cache_level)); + "hwloc:base:get_nbojbs computed data %u of %s:%u", num_objs, + hwloc_obj_type_string(target), cache_level)); return num_objs; } @@ -783,10 +768,8 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, /* as above, only return the Nth instance of the specified object * type from inside the topology */ -hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo, - hwloc_obj_type_t target, - unsigned cache_level, - unsigned int instance, +hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo, hwloc_obj_type_t target, + unsigned cache_level, unsigned int instance, opal_hwloc_resource_type_t rtype) { hwloc_obj_t obj; @@ -804,7 +787,7 @@ hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo, #if HWLOC_API_VERSION < 0x20000 && HWLOC_OBJ_CACHE != target #endif - ) { + ) { return hwloc_get_obj_by_type(topo, target, instance); } @@ -815,7 +798,8 @@ hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo, static void opal_hwloc_base_get_relative_locality_by_depth(hwloc_topology_t topo, unsigned d, hwloc_cpuset_t loc1, hwloc_cpuset_t loc2, - opal_hwloc_locality_t *locality, bool *shared) + opal_hwloc_locality_t *locality, + bool *shared) { unsigned width, w; hwloc_obj_t obj; @@ -827,7 +811,7 @@ static void opal_hwloc_base_get_relative_locality_by_depth(hwloc_topology_t topo /* scan all objects at this depth to see if * our locations overlap with them */ - for (w=0; w < width; w++) { + for (w = 0; w < width; w++) { /* get the object at this depth/index */ obj = hwloc_get_obj_by_depth(topo, d, w); /* see if our locations intersect with the cpuset for this obj */ @@ -836,7 +820,7 @@ static void opal_hwloc_base_get_relative_locality_by_depth(hwloc_topology_t topo /* if both intersect, then we share this level */ if (sect1 && sect2) { *shared = true; - switch(obj->type) { + switch (obj->type) { case HWLOC_OBJ_NODE: *locality |= OPAL_PROC_ON_NUMA; break; @@ -883,8 +867,8 @@ static void opal_hwloc_base_get_relative_locality_by_depth(hwloc_topology_t topo } } -opal_hwloc_locality_t opal_hwloc_base_get_relative_locality(hwloc_topology_t topo, - char *cpuset1, char *cpuset2) +opal_hwloc_locality_t opal_hwloc_base_get_relative_locality(hwloc_topology_t topo, char *cpuset1, + char *cpuset2) { opal_hwloc_locality_t locality; hwloc_cpuset_t loc1, loc2; @@ -913,22 +897,18 @@ opal_hwloc_locality_t opal_hwloc_base_get_relative_locality(hwloc_topology_t top hwloc_bitmap_list_sscanf(loc2, cpuset2); /* start at the first depth below the top machine level */ - for (d=1; d < depth; d++) { + for (d = 1; d < depth; d++) { shared = false; /* get the object type at this depth */ type = hwloc_get_depth_type(topo, d); /* if it isn't one of interest, then ignore it */ - if (HWLOC_OBJ_NODE != type && - HWLOC_OBJ_SOCKET != type && + if (HWLOC_OBJ_NODE != type && HWLOC_OBJ_SOCKET != type && #if HWLOC_API_VERSION < 0x20000 HWLOC_OBJ_CACHE != type && #else - HWLOC_OBJ_L3CACHE != type && - HWLOC_OBJ_L2CACHE != type && - HWLOC_OBJ_L1CACHE != type && + HWLOC_OBJ_L3CACHE != type && HWLOC_OBJ_L2CACHE != type && HWLOC_OBJ_L1CACHE != type && #endif - HWLOC_OBJ_CORE != type && - HWLOC_OBJ_PU != type) { + HWLOC_OBJ_CORE != type && HWLOC_OBJ_PU != type) { continue; } opal_hwloc_base_get_relative_locality_by_depth(topo, d, loc1, loc2, &locality, &shared); @@ -942,11 +922,11 @@ opal_hwloc_locality_t opal_hwloc_base_get_relative_locality(hwloc_topology_t top } } #if HWLOC_API_VERSION >= 0x20000 - opal_hwloc_base_get_relative_locality_by_depth(topo, HWLOC_TYPE_DEPTH_NUMANODE, loc1, loc2, &locality, &shared); + opal_hwloc_base_get_relative_locality_by_depth(topo, HWLOC_TYPE_DEPTH_NUMANODE, loc1, loc2, + &locality, &shared); #endif - opal_output_verbose(5, opal_hwloc_base_framework.framework_output, - "locality: %s", + opal_output_verbose(5, opal_hwloc_base_framework.framework_output, "locality: %s", opal_hwloc_base_print_locality(locality)); hwloc_bitmap_free(loc1); hwloc_bitmap_free(loc2); @@ -954,13 +934,12 @@ opal_hwloc_locality_t opal_hwloc_base_get_relative_locality(hwloc_topology_t top return locality; } - -char* opal_hwloc_base_print_binding(opal_binding_policy_t binding) +char *opal_hwloc_base_print_binding(opal_binding_policy_t binding) { char *ret, *bind; opal_hwloc_print_buffers_t *ptr; - switch(OPAL_GET_BINDING_POLICY(binding)) { + switch (OPAL_GET_BINDING_POLICY(binding)) { case OPAL_BIND_TO_NONE: bind = "NONE"; break; @@ -1002,16 +981,13 @@ char* opal_hwloc_base_print_binding(opal_binding_policy_t binding) if (OPAL_HWLOC_PRINT_NUM_BUFS == ptr->cntr) { ptr->cntr = 0; } - if (!OPAL_BINDING_REQUIRED(binding) && - OPAL_BIND_OVERLOAD_ALLOWED(binding)) { + if (!OPAL_BINDING_REQUIRED(binding) && OPAL_BIND_OVERLOAD_ALLOWED(binding)) { snprintf(ptr->buffers[ptr->cntr], OPAL_HWLOC_PRINT_MAX_SIZE, "%s:IF-SUPPORTED:OVERLOAD-ALLOWED", bind); } else if (OPAL_BIND_OVERLOAD_ALLOWED(binding)) { - snprintf(ptr->buffers[ptr->cntr], OPAL_HWLOC_PRINT_MAX_SIZE, - "%s:OVERLOAD-ALLOWED", bind); + snprintf(ptr->buffers[ptr->cntr], OPAL_HWLOC_PRINT_MAX_SIZE, "%s:OVERLOAD-ALLOWED", bind); } else if (!OPAL_BINDING_REQUIRED(binding)) { - snprintf(ptr->buffers[ptr->cntr], OPAL_HWLOC_PRINT_MAX_SIZE, - "%s:IF-SUPPORTED", bind); + snprintf(ptr->buffers[ptr->cntr], OPAL_HWLOC_PRINT_MAX_SIZE, "%s:IF-SUPPORTED", bind); } else { snprintf(ptr->buffers[ptr->cntr], OPAL_HWLOC_PRINT_MAX_SIZE, "%s", bind); } @@ -1094,8 +1070,8 @@ static char *bitmap2rangestr(int bitmap) /* * Make a map of socket/core/hwthread tuples */ -static int build_map(int *num_sockets_arg, int *num_cores_arg, - hwloc_cpuset_t cpuset, int ***map, hwloc_topology_t topo) +static int build_map(int *num_sockets_arg, int *num_cores_arg, hwloc_cpuset_t cpuset, int ***map, + hwloc_topology_t topo) { int num_sockets, num_cores; int socket_index, core_index, pu_index; @@ -1134,13 +1110,9 @@ static int build_map(int *num_sockets_arg, int *num_cores_arg, /* Iterate the PUs in this cpuset; fill in the data[][] array with the socket/core/pu triples */ for (pu_index = 0, - pu = hwloc_get_obj_inside_cpuset_by_type(topo, - cpuset, HWLOC_OBJ_PU, - pu_index); + pu = hwloc_get_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, pu_index); NULL != pu; - pu = hwloc_get_obj_inside_cpuset_by_type(topo, - cpuset, HWLOC_OBJ_PU, - ++pu_index)) { + pu = hwloc_get_obj_inside_cpuset_by_type(topo, cpuset, HWLOC_OBJ_PU, ++pu_index)) { /* Go upward and find the core this PU belongs to */ core = pu; while (NULL != core && core->type != HWLOC_OBJ_CORE) { @@ -1173,16 +1145,14 @@ static int build_map(int *num_sockets_arg, int *num_cores_arg, /* * Make a prettyprint string for a hwloc_cpuset_t */ -int opal_hwloc_base_cset2str(char *str, int len, - hwloc_topology_t topo, - hwloc_cpuset_t cpuset) +int opal_hwloc_base_cset2str(char *str, int len, hwloc_topology_t topo, hwloc_cpuset_t cpuset) { bool first; int num_sockets, num_cores; int ret, socket_index, core_index; char tmp[BUFSIZ]; const int stmp = sizeof(tmp) - 1; - int **map=NULL; + int **map = NULL; str[0] = tmp[stmp] = '\0'; @@ -1204,8 +1174,7 @@ int opal_hwloc_base_cset2str(char *str, int len, } first = false; - snprintf(tmp, stmp, "socket %d[core %d[hwt %s]]", - socket_index, core_index, + snprintf(tmp, stmp, "socket %d[core %d[hwt %s]]", socket_index, core_index, bitmap2rangestr(map[socket_index][core_index])); strncat(str, tmp, len - strlen(str) - 1); } @@ -1229,9 +1198,7 @@ int opal_hwloc_base_cset2str(char *str, int len, * . - signifies PU a process not bound to * B - signifies PU a process is bound to */ -int opal_hwloc_base_cset2mapstr(char *str, int len, - hwloc_topology_t topo, - hwloc_cpuset_t cpuset) +int opal_hwloc_base_cset2mapstr(char *str, int len, hwloc_topology_t topo, hwloc_cpuset_t cpuset) { char tmp[BUFSIZ]; int core_index, pu_index; @@ -1246,33 +1213,27 @@ int opal_hwloc_base_cset2mapstr(char *str, int len, } /* Iterate over all existing sockets */ - for (socket = hwloc_get_obj_by_type(topo, HWLOC_OBJ_SOCKET, 0); - NULL != socket; + for (socket = hwloc_get_obj_by_type(topo, HWLOC_OBJ_SOCKET, 0); NULL != socket; socket = socket->next_cousin) { strncat(str, "[", len - strlen(str) - 1); /* Iterate over all existing cores in this socket */ core_index = 0; - for (core = hwloc_get_obj_inside_cpuset_by_type(topo, - socket->cpuset, - HWLOC_OBJ_CORE, core_index); + for (core = hwloc_get_obj_inside_cpuset_by_type(topo, socket->cpuset, HWLOC_OBJ_CORE, + core_index); NULL != core; - core = hwloc_get_obj_inside_cpuset_by_type(topo, - socket->cpuset, - HWLOC_OBJ_CORE, ++core_index)) { + core = hwloc_get_obj_inside_cpuset_by_type(topo, socket->cpuset, HWLOC_OBJ_CORE, + ++core_index)) { if (core_index > 0) { strncat(str, "/", len - strlen(str) - 1); } /* Iterate over all existing PUs in this core */ pu_index = 0; - for (pu = hwloc_get_obj_inside_cpuset_by_type(topo, - core->cpuset, - HWLOC_OBJ_PU, pu_index); - NULL != pu; - pu = hwloc_get_obj_inside_cpuset_by_type(topo, - core->cpuset, - HWLOC_OBJ_PU, ++pu_index)) { + for (pu = hwloc_get_obj_inside_cpuset_by_type(topo, core->cpuset, HWLOC_OBJ_PU, + pu_index); + NULL != pu; pu = hwloc_get_obj_inside_cpuset_by_type(topo, core->cpuset, + HWLOC_OBJ_PU, ++pu_index)) { /* Is this PU in the cpuset? */ if (hwloc_bitmap_isset(cpuset, pu->os_index)) { @@ -1288,9 +1249,7 @@ int opal_hwloc_base_cset2mapstr(char *str, int len, return OPAL_SUCCESS; } -char* opal_hwloc_base_get_location(char *locality, - hwloc_obj_type_t type, - unsigned index) +char *opal_hwloc_base_get_location(char *locality, hwloc_obj_type_t type, unsigned index) { char **loc; char *srch, *ans = NULL; @@ -1299,45 +1258,45 @@ char* opal_hwloc_base_get_location(char *locality, if (NULL == locality) { return NULL; } - switch(type) { - case HWLOC_OBJ_NODE: - srch = "NM"; - break; - case HWLOC_OBJ_SOCKET: - srch = "SK"; - break; + switch (type) { + case HWLOC_OBJ_NODE: + srch = "NM"; + break; + case HWLOC_OBJ_SOCKET: + srch = "SK"; + break; #if HWLOC_API_VERSION < 0x20000 - case HWLOC_OBJ_CACHE: - if (3 == index) { - srch = "L3"; - } else if (2 == index) { - srch = "L2"; - } else { - srch = "L1"; - } - break; -#else - case HWLOC_OBJ_L3CACHE: + case HWLOC_OBJ_CACHE: + if (3 == index) { srch = "L3"; - break; - case HWLOC_OBJ_L2CACHE: + } else if (2 == index) { srch = "L2"; - break; - case HWLOC_OBJ_L1CACHE: + } else { srch = "L1"; - break; + } + break; +#else + case HWLOC_OBJ_L3CACHE: + srch = "L3"; + break; + case HWLOC_OBJ_L2CACHE: + srch = "L2"; + break; + case HWLOC_OBJ_L1CACHE: + srch = "L1"; + break; #endif - case HWLOC_OBJ_CORE: - srch = "CR"; - break; - case HWLOC_OBJ_PU: - srch = "HT"; - break; - default: - return NULL; + case HWLOC_OBJ_CORE: + srch = "CR"; + break; + case HWLOC_OBJ_PU: + srch = "HT"; + break; + default: + return NULL; } loc = opal_argv_split(locality, ':'); - for (n=0; NULL != loc[n]; n++) { + for (n = 0; NULL != loc[n]; n++) { if (0 == strncmp(loc[n], srch, 2)) { ans = strdup(&loc[n][2]); break; @@ -1372,11 +1331,11 @@ opal_hwloc_locality_t opal_hwloc_compute_relative_locality(char *loc1, char *loc bit2 = hwloc_bitmap_alloc(); /* check each matching type */ - for (n1=0; NULL != set1[n1]; n1++) { + for (n1 = 0; NULL != set1[n1]; n1++) { /* convert the location into bitmap */ hwloc_bitmap_list_sscanf(bit1, &set1[n1][2]); /* find the matching type in set2 */ - for (n2=0; NULL != set2[n2]; n2++) { + for (n2 = 0; NULL != set2[n2]; n2++) { if (0 == strncmp(set1[n1], set2[n2], 2)) { /* convert the location into bitmap */ hwloc_bitmap_list_sscanf(bit2, &set2[n2][2]); @@ -1413,13 +1372,16 @@ opal_hwloc_locality_t opal_hwloc_compute_relative_locality(char *loc1, char *loc return locality; } -int opal_hwloc_base_topology_set_flags (hwloc_topology_t topology, unsigned long flags, bool io) { +int opal_hwloc_base_topology_set_flags(hwloc_topology_t topology, unsigned long flags, bool io) +{ if (io) { #if HWLOC_API_VERSION < 0x20000 flags |= HWLOC_TOPOLOGY_FLAG_IO_DEVICES; #else int ret = hwloc_topology_set_io_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_IMPORTANT); - if (0 != ret) return ret; + if (0 != ret) { + return ret; + } #endif } return hwloc_topology_set_flags(topology, flags); diff --git a/opal/mca/hwloc/base/static-components.h b/opal/mca/hwloc/base/static-components.h index dd18f72da26..3e5b0f9b19d 100644 --- a/opal/mca/hwloc/base/static-components.h +++ b/opal/mca/hwloc/base/static-components.h @@ -5,14 +5,10 @@ extern "C" { #endif - - const mca_base_component_t *mca_hwloc_base_static_components[] = { - NULL -}; + NULL}; #if defined(c_plusplus) || defined(__cplusplus) } #endif - diff --git a/opal/mca/hwloc/hwloc-internal.h b/opal/mca/hwloc/hwloc-internal.h index 57eae358afc..3fefadb2011 100644 --- a/opal/mca/hwloc/hwloc-internal.h +++ b/opal/mca/hwloc/hwloc-internal.h @@ -26,26 +26,26 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_TIME_H -#include +# include #endif -#include #include +#include #include "opal/class/opal_list.h" #include "opal/class/opal_value_array.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" BEGIN_C_DECLS #ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#undef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# include +# undef WIN32_LEAN_AND_MEAN typedef unsigned char u_char; typedef unsigned short u_short; #endif @@ -69,9 +69,7 @@ typedef struct opal_hwloc_base_component_2_0_0_t opal_hwloc_component_t; /** * Macro for use in components that are of type hwloc */ -#define OPAL_HWLOC_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("hwloc", 2, 0, 0) - +#define OPAL_HWLOC_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("hwloc", 2, 0, 0) /* ******************************************************************** */ /* Although we cannot bind if --without-hwloc is set, @@ -85,36 +83,36 @@ typedef uint16_t opal_hwloc_locality_t; /** Process locality definitions */ enum { - OPAL_PROC_LOCALITY_UNKNOWN = 0x0000, - OPAL_PROC_NON_LOCAL = 0x8000, - OPAL_PROC_ON_CLUSTER = 0x0001, - OPAL_PROC_ON_CU = 0x0002, - OPAL_PROC_ON_HOST = 0x0004, - OPAL_PROC_ON_BOARD = 0x0008, - OPAL_PROC_ON_NODE = 0x000c, // same host and board - OPAL_PROC_ON_NUMA = 0x0010, - OPAL_PROC_ON_SOCKET = 0x0020, - OPAL_PROC_ON_L3CACHE = 0x0040, - OPAL_PROC_ON_L2CACHE = 0x0080, - OPAL_PROC_ON_L1CACHE = 0x0100, - OPAL_PROC_ON_CORE = 0x0200, - OPAL_PROC_ON_HWTHREAD = 0x0400, - OPAL_PROC_ALL_LOCAL = 0x0fff, + OPAL_PROC_LOCALITY_UNKNOWN = 0x0000, + OPAL_PROC_NON_LOCAL = 0x8000, + OPAL_PROC_ON_CLUSTER = 0x0001, + OPAL_PROC_ON_CU = 0x0002, + OPAL_PROC_ON_HOST = 0x0004, + OPAL_PROC_ON_BOARD = 0x0008, + OPAL_PROC_ON_NODE = 0x000c, // same host and board + OPAL_PROC_ON_NUMA = 0x0010, + OPAL_PROC_ON_SOCKET = 0x0020, + OPAL_PROC_ON_L3CACHE = 0x0040, + OPAL_PROC_ON_L2CACHE = 0x0080, + OPAL_PROC_ON_L1CACHE = 0x0100, + OPAL_PROC_ON_CORE = 0x0200, + OPAL_PROC_ON_HWTHREAD = 0x0400, + OPAL_PROC_ALL_LOCAL = 0x0fff, }; /** Process locality macros */ -#define OPAL_PROC_ON_LOCAL_CLUSTER(n) (!!((n) & OPAL_PROC_ON_CLUSTER)) -#define OPAL_PROC_ON_LOCAL_CU(n) (!!((n) & OPAL_PROC_ON_CU)) -#define OPAL_PROC_ON_LOCAL_HOST(n) (!!((n) & OPAL_PROC_ON_HOST)) -#define OPAL_PROC_ON_LOCAL_BOARD(n) (!!((n) & OPAL_PROC_ON_BOARD)) -#define OPAL_PROC_ON_LOCAL_NODE(n) (OPAL_PROC_ON_LOCAL_HOST(n) && OPAL_PROC_ON_LOCAL_BOARD(n)) -#define OPAL_PROC_ON_LOCAL_NUMA(n) (!!((n) & OPAL_PROC_ON_NUMA)) -#define OPAL_PROC_ON_LOCAL_SOCKET(n) (!!((n) & OPAL_PROC_ON_SOCKET)) -#define OPAL_PROC_ON_LOCAL_L3CACHE(n) (!!((n) & OPAL_PROC_ON_L3CACHE)) -#define OPAL_PROC_ON_LOCAL_L2CACHE(n) (!!((n) & OPAL_PROC_ON_L2CACHE)) -#define OPAL_PROC_ON_LOCAL_L1CACHE(n) (!!((n) & OPAL_PROC_ON_L1CACHE)) -#define OPAL_PROC_ON_LOCAL_CORE(n) (!!((n) & OPAL_PROC_ON_CORE)) -#define OPAL_PROC_ON_LOCAL_HWTHREAD(n) (!!((n) & OPAL_PROC_ON_HWTHREAD)) +#define OPAL_PROC_ON_LOCAL_CLUSTER(n) (!!((n) &OPAL_PROC_ON_CLUSTER)) +#define OPAL_PROC_ON_LOCAL_CU(n) (!!((n) &OPAL_PROC_ON_CU)) +#define OPAL_PROC_ON_LOCAL_HOST(n) (!!((n) &OPAL_PROC_ON_HOST)) +#define OPAL_PROC_ON_LOCAL_BOARD(n) (!!((n) &OPAL_PROC_ON_BOARD)) +#define OPAL_PROC_ON_LOCAL_NODE(n) (OPAL_PROC_ON_LOCAL_HOST(n) && OPAL_PROC_ON_LOCAL_BOARD(n)) +#define OPAL_PROC_ON_LOCAL_NUMA(n) (!!((n) &OPAL_PROC_ON_NUMA)) +#define OPAL_PROC_ON_LOCAL_SOCKET(n) (!!((n) &OPAL_PROC_ON_SOCKET)) +#define OPAL_PROC_ON_LOCAL_L3CACHE(n) (!!((n) &OPAL_PROC_ON_L3CACHE)) +#define OPAL_PROC_ON_LOCAL_L2CACHE(n) (!!((n) &OPAL_PROC_ON_L2CACHE)) +#define OPAL_PROC_ON_LOCAL_L1CACHE(n) (!!((n) &OPAL_PROC_ON_L1CACHE)) +#define OPAL_PROC_ON_LOCAL_CORE(n) (!!((n) &OPAL_PROC_ON_CORE)) +#define OPAL_PROC_ON_LOCAL_HWTHREAD(n) (!!((n) &OPAL_PROC_ON_HWTHREAD)) /* ******************************************************************** */ @@ -143,21 +141,22 @@ typedef struct { # if HWLOC_API_VERSION >= 0x20000 # include # endif -/* Do nothing in the 1.x case because the caller doesn't know HWLOC_API_VERSION when it sets OPAL_HWLOC_WANT_SHMEM. - * Calls to hwloc/shmem.h are protected by HWLOC_API_VERSION >= 0x20000 in the actual code. +/* Do nothing in the 1.x case because the caller doesn't know HWLOC_API_VERSION when it sets + * OPAL_HWLOC_WANT_SHMEM. Calls to hwloc/shmem.h are protected by HWLOC_API_VERSION >= 0x20000 in + * the actual code. */ #endif #if HWLOC_API_VERSION < 0x00010b00 -#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE -#define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET +# define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE +# define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET #endif /* define type of processor info requested */ typedef uint8_t opal_hwloc_resource_type_t; -#define OPAL_HWLOC_PHYSICAL 1 -#define OPAL_HWLOC_LOGICAL 2 -#define OPAL_HWLOC_AVAILABLE 3 +#define OPAL_HWLOC_PHYSICAL 1 +#define OPAL_HWLOC_LOGICAL 2 +#define OPAL_HWLOC_AVAILABLE 3 /* structs for storing info on objects */ typedef struct { @@ -194,52 +193,46 @@ typedef uint16_t opal_binding_policy_t; #define OPAL_BINDING_POLICY OPAL_UINT16 /* binding directives */ -#define OPAL_BIND_IF_SUPPORTED 0x1000 +#define OPAL_BIND_IF_SUPPORTED 0x1000 /* allow assignment of multiple procs to * same cpu */ -#define OPAL_BIND_ALLOW_OVERLOAD 0x2000 +#define OPAL_BIND_ALLOW_OVERLOAD 0x2000 /* the binding policy was specified by the user */ -#define OPAL_BIND_GIVEN 0x4000 +#define OPAL_BIND_GIVEN 0x4000 /* bind each rank to the cpu in the given * cpu list based on its node-local-rank */ -#define OPAL_BIND_ORDERED 0x8000 +#define OPAL_BIND_ORDERED 0x8000 /* binding policies - any changes in these * values must be reflected in orte/mca/rmaps/rmaps.h */ -#define OPAL_BIND_TO_NONE 1 -#define OPAL_BIND_TO_BOARD 2 -#define OPAL_BIND_TO_NUMA 3 -#define OPAL_BIND_TO_SOCKET 4 -#define OPAL_BIND_TO_L3CACHE 5 -#define OPAL_BIND_TO_L2CACHE 6 -#define OPAL_BIND_TO_L1CACHE 7 -#define OPAL_BIND_TO_CORE 8 -#define OPAL_BIND_TO_HWTHREAD 9 -#define OPAL_BIND_TO_CPUSET 10 -#define OPAL_GET_BINDING_POLICY(pol) \ - ((pol) & 0x0fff) +#define OPAL_BIND_TO_NONE 1 +#define OPAL_BIND_TO_BOARD 2 +#define OPAL_BIND_TO_NUMA 3 +#define OPAL_BIND_TO_SOCKET 4 +#define OPAL_BIND_TO_L3CACHE 5 +#define OPAL_BIND_TO_L2CACHE 6 +#define OPAL_BIND_TO_L1CACHE 7 +#define OPAL_BIND_TO_CORE 8 +#define OPAL_BIND_TO_HWTHREAD 9 +#define OPAL_BIND_TO_CPUSET 10 +#define OPAL_GET_BINDING_POLICY(pol) ((pol) &0x0fff) #define OPAL_SET_BINDING_POLICY(target, pol) \ - (target) = (pol) | (((target) & 0xf000) | OPAL_BIND_GIVEN) -#define OPAL_SET_DEFAULT_BINDING_POLICY(target, pol) \ - do { \ - if (!OPAL_BINDING_POLICY_IS_SET((target))) { \ - (target) = (pol) | (((target) & 0xf000) | \ - OPAL_BIND_IF_SUPPORTED); \ - } \ - } while(0); + (target) = (pol) | (((target) &0xf000) | OPAL_BIND_GIVEN) +#define OPAL_SET_DEFAULT_BINDING_POLICY(target, pol) \ + do { \ + if (!OPAL_BINDING_POLICY_IS_SET((target))) { \ + (target) = (pol) | (((target) &0xf000) | OPAL_BIND_IF_SUPPORTED); \ + } \ + } while (0); /* check if policy is set */ -#define OPAL_BINDING_POLICY_IS_SET(pol) \ - ((pol) & 0x4000) +#define OPAL_BINDING_POLICY_IS_SET(pol) ((pol) &0x4000) /* macro to detect if binding was qualified */ -#define OPAL_BINDING_REQUIRED(n) \ - (!(OPAL_BIND_IF_SUPPORTED & (n))) +#define OPAL_BINDING_REQUIRED(n) (!(OPAL_BIND_IF_SUPPORTED & (n))) /* macro to detect if binding is forced */ -#define OPAL_BIND_OVERLOAD_ALLOWED(n) \ - (OPAL_BIND_ALLOW_OVERLOAD & (n)) -#define OPAL_BIND_ORDERED_REQUESTED(n) \ - (OPAL_BIND_ORDERED & (n)) +#define OPAL_BIND_OVERLOAD_ALLOWED(n) (OPAL_BIND_ALLOW_OVERLOAD & (n)) +#define OPAL_BIND_ORDERED_REQUESTED(n) (OPAL_BIND_ORDERED & (n)) /* some global values */ OPAL_DECLSPEC extern hwloc_topology_t opal_hwloc_topology; diff --git a/opal/mca/if/base/if_base_components.c b/opal/mca/if/base/if_base_components.c index 7c1322a5a99..86d2aea4ee6 100644 --- a/opal/mca/if/base/if_base_components.c +++ b/opal/mca/if/base/if_base_components.c @@ -14,19 +14,19 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" -#include "opal/mca/if/if.h" #include "opal/mca/if/base/base.h" #include "opal/mca/if/base/static-components.h" +#include "opal/mca/if/if.h" +#include "opal/mca/mca.h" +#include "opal/util/output.h" /* instantiate the global list of interfaces */ opal_list_t opal_if_list = {{0}}; bool opal_if_do_not_resolve = false; bool opal_if_retain_loopback = false; -static int opal_if_base_register (mca_base_register_flag_t flags); -static int opal_if_base_open (mca_base_open_flag_t flags); +static int opal_if_base_register(mca_base_register_flag_t flags); +static int opal_if_base_open(mca_base_open_flag_t flags); static int opal_if_base_close(void); static void opal_if_construct(opal_if_t *obj); @@ -35,30 +35,29 @@ static bool frameopen = false; /* instance the opal_if_t object */ OBJ_CLASS_INSTANCE(opal_if_t, opal_list_item_t, opal_if_construct, NULL); -MCA_BASE_FRAMEWORK_DECLARE(opal, if, NULL, opal_if_base_register, opal_if_base_open, opal_if_base_close, - mca_if_base_static_components, 0); +MCA_BASE_FRAMEWORK_DECLARE(opal, if, NULL, opal_if_base_register, opal_if_base_open, + opal_if_base_close, mca_if_base_static_components, 0); -static int opal_if_base_register (mca_base_register_flag_t flags) +static int opal_if_base_register(mca_base_register_flag_t flags) { opal_if_do_not_resolve = false; - (void) mca_base_framework_var_register (&opal_if_base_framework, "do_not_resolve", - "If nonzero, do not attempt to resolve interfaces", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_if_do_not_resolve); + (void) mca_base_framework_var_register(&opal_if_base_framework, "do_not_resolve", + "If nonzero, do not attempt to resolve interfaces", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_if_do_not_resolve); opal_if_retain_loopback = false; - (void) mca_base_framework_var_register (&opal_if_base_framework, "retain_loopback", - "If nonzero, retain loopback interfaces", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_if_retain_loopback); + (void) mca_base_framework_var_register(&opal_if_base_framework, "retain_loopback", + "If nonzero, retain loopback interfaces", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_if_retain_loopback); return OPAL_SUCCESS; } - -static int opal_if_base_open (mca_base_open_flag_t flags) +static int opal_if_base_open(mca_base_open_flag_t flags) { if (frameopen) { return OPAL_SUCCESS; @@ -71,7 +70,6 @@ static int opal_if_base_open (mca_base_open_flag_t flags) return mca_base_framework_components_open(&opal_if_base_framework, flags); } - static int opal_if_base_close(void) { opal_list_item_t *item; diff --git a/opal/mca/if/bsdx_ipv4/if_bsdx.c b/opal/mca/if/bsdx_ipv4/if_bsdx.c index 1043ddca84b..86fa2b5e784 100644 --- a/opal/mca/if/bsdx_ipv4/if_bsdx.c +++ b/opal/mca/if/bsdx_ipv4/if_bsdx.c @@ -14,9 +14,9 @@ #include #include "opal/constants.h" +#include "opal/mca/if/if.h" #include "opal/util/output.h" #include "opal/util/string_copy.h" -#include "opal/mca/if/if.h" static int if_bsdx_open(void); @@ -29,27 +29,19 @@ static int if_bsdx_open(void); opal_if_base_component_t mca_if_bsdx_ipv4_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_IF_BASE_VERSION_2_0_0, - - /* Component name and version */ - "bsdx_ipv4", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - - /* Component open and close functions */ - if_bsdx_open, - NULL - }, - { - /* This component is checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + {OPAL_IF_BASE_VERSION_2_0_0, + + /* Component name and version */ + "bsdx_ipv4", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + + /* Component open and close functions */ + if_bsdx_open, NULL}, + {/* This component is checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; /* convert a netmask (in network byte order) to CIDR notation */ -static int prefix (uint32_t netmask) +static int prefix(uint32_t netmask) { uint32_t mask = ntohl(netmask); int plen = 0; @@ -71,24 +63,22 @@ static int if_bsdx_open(void) { struct ifaddrs **ifadd_list; struct ifaddrs *cur_ifaddrs; - struct sockaddr_in* sin_addr; + struct sockaddr_in *sin_addr; /* * the manpage claims that getifaddrs() allocates the memory, * and freeifaddrs() is later used to release the allocated memory. * however, without this malloc the call to getifaddrs() segfaults */ - ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*)); + ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs *)); /* create the linked list of ifaddrs structs */ if (getifaddrs(ifadd_list) < 0) { - opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n", - errno); + opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n", errno); return OPAL_ERROR; } - for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs; - cur_ifaddrs = cur_ifaddrs->ifa_next) { + for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs; cur_ifaddrs = cur_ifaddrs->ifa_next) { opal_if_t *intf; struct in_addr a4; @@ -117,8 +107,7 @@ static int if_bsdx_open(void) intf = OBJ_NEW(opal_if_t); if (NULL == intf) { - opal_output(0, "opal_ifinit: unable to allocate %d bytes\n", - (int) sizeof(opal_if_t)); + opal_output(0, "opal_ifinit: unable to allocate %d bytes\n", (int) sizeof(opal_if_t)); return OPAL_ERR_OUT_OF_RESOURCE; } intf->af_family = AF_INET; @@ -128,20 +117,17 @@ static int if_bsdx_open(void) opal_string_copy(intf->if_name, cur_ifaddrs->ifa_name, OPAL_IF_NAMESIZE); intf->if_index = opal_list_get_size(&opal_if_list) + 1; - ((struct sockaddr_in*) &intf->if_addr)->sin_addr = a4; - ((struct sockaddr_in*) &intf->if_addr)->sin_family = AF_INET; - ((struct sockaddr_in*) &intf->if_addr)->sin_len = cur_ifaddrs->ifa_addr->sa_len; + ((struct sockaddr_in *) &intf->if_addr)->sin_addr = a4; + ((struct sockaddr_in *) &intf->if_addr)->sin_family = AF_INET; + ((struct sockaddr_in *) &intf->if_addr)->sin_len = cur_ifaddrs->ifa_addr->sa_len; - intf->if_mask = prefix( sin_addr->sin_addr.s_addr); + intf->if_mask = prefix(sin_addr->sin_addr.s_addr); intf->if_flags = cur_ifaddrs->ifa_flags; - intf->if_kernel_index = - (uint16_t) if_nametoindex(cur_ifaddrs->ifa_name); + intf->if_kernel_index = (uint16_t) if_nametoindex(cur_ifaddrs->ifa_name); opal_list_append(&opal_if_list, &(intf->super)); - } /* of for loop over ifaddrs list */ + } /* of for loop over ifaddrs list */ return OPAL_SUCCESS; } - - diff --git a/opal/mca/if/bsdx_ipv6/if_bsdx_ipv6.c b/opal/mca/if/bsdx_ipv6/if_bsdx_ipv6.c index 7716f7933b2..7b219ac9e97 100644 --- a/opal/mca/if/bsdx_ipv6/if_bsdx_ipv6.c +++ b/opal/mca/if/bsdx_ipv6/if_bsdx_ipv6.c @@ -17,39 +17,39 @@ #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_SOCKIO_H -#include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_NET_IF_H -#include +# include #endif #ifdef HAVE_NETDB_H -#include +# include #endif #ifdef HAVE_IFADDRS_H -#include +# include #endif -#include "opal/mca/if/if.h" #include "opal/mca/if/base/base.h" +#include "opal/mca/if/if.h" static int if_bsdx_ipv6_open(void); @@ -65,23 +65,15 @@ static int if_bsdx_ipv6_open(void); opal_if_base_component_t mca_if_bsdx_ipv6_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_IF_BASE_VERSION_2_0_0, - - /* Component name and version */ - "bsdx_ipv6", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - - /* Component open and close functions */ - if_bsdx_ipv6_open, - NULL - }, - { - /* This component is checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + {OPAL_IF_BASE_VERSION_2_0_0, + + /* Component name and version */ + "bsdx_ipv6", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + + /* Component open and close functions */ + if_bsdx_ipv6_open, NULL}, + {/* This component is checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; /* configure using getifaddrs(3) */ @@ -90,7 +82,7 @@ static int if_bsdx_ipv6_open(void) #if OPAL_ENABLE_IPV6 struct ifaddrs **ifadd_list; struct ifaddrs *cur_ifaddrs; - struct sockaddr_in6* sin_addr; + struct sockaddr_in6 *sin_addr; opal_output_verbose(1, opal_if_base_framework.framework_output, "searching for IPv6 interfaces"); @@ -100,26 +92,24 @@ static int if_bsdx_ipv6_open(void) * and freeifaddrs() is later used to release the allocated memory. * however, without this malloc the call to getifaddrs() segfaults */ - ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*)); + ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs *)); /* create the linked list of ifaddrs structs */ if (getifaddrs(ifadd_list) < 0) { - opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n", - errno); + opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n", errno); free(ifadd_list); return OPAL_ERROR; } - for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs; - cur_ifaddrs = cur_ifaddrs->ifa_next) { + for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs; cur_ifaddrs = cur_ifaddrs->ifa_next) { opal_if_t *intf; struct in6_addr a6; /* skip non-ipv6 interface addresses */ if (AF_INET6 != cur_ifaddrs->ifa_addr->sa_family) { opal_output_verbose(1, opal_if_base_framework.framework_output, - "skipping non-ipv6 interface %s[%d].\n", - cur_ifaddrs->ifa_name, (int)cur_ifaddrs->ifa_addr->sa_family); + "skipping non-ipv6 interface %s[%d].\n", cur_ifaddrs->ifa_name, + (int) cur_ifaddrs->ifa_addr->sa_family); continue; } @@ -139,7 +129,7 @@ static int if_bsdx_ipv6_open(void) /* or if it is a point-to-point interface */ /* TODO: do we really skip p2p? */ - if (0!= (cur_ifaddrs->ifa_flags & IFF_POINTOPOINT)) { + if (0 != (cur_ifaddrs->ifa_flags & IFF_POINTOPOINT)) { opal_output_verbose(1, opal_if_base_framework.framework_output, "skipping p2p interface %s.\n", cur_ifaddrs->ifa_name); continue; @@ -158,7 +148,7 @@ static int if_bsdx_ipv6_open(void) * so the scope returned by getifaddrs() isn't working properly */ - if ((IN6_IS_ADDR_LINKLOCAL (&sin_addr->sin6_addr))) { + if ((IN6_IS_ADDR_LINKLOCAL(&sin_addr->sin6_addr))) { opal_output_verbose(1, opal_if_base_framework.framework_output, "skipping link-local ipv6 address on interface " "%s with scope %d.\n", @@ -167,8 +157,8 @@ static int if_bsdx_ipv6_open(void) } if (0 < opal_output_get_verbosity(opal_if_base_framework.framework_output)) { - char *addr_name = (char *) malloc(48*sizeof(char)); - inet_ntop(AF_INET6, &sin_addr->sin6_addr, addr_name, 48*sizeof(char)); + char *addr_name = (char *) malloc(48 * sizeof(char)); + inet_ntop(AF_INET6, &sin_addr->sin6_addr, addr_name, 48 * sizeof(char)); opal_output(0, "ipv6 capable interface %s discovered, address %s.\n", cur_ifaddrs->ifa_name, addr_name); free(addr_name); @@ -179,19 +169,18 @@ static int if_bsdx_ipv6_open(void) intf = OBJ_NEW(opal_if_t); if (NULL == intf) { - opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n", - sizeof(opal_if_t)); + opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n", sizeof(opal_if_t)); free(ifadd_list); return OPAL_ERR_OUT_OF_RESOURCE; } intf->af_family = AF_INET6; opal_string_copy(intf->if_name, cur_ifaddrs->ifa_name, OPAL_IF_NAMESIZE); intf->if_index = opal_list_get_size(&opal_if_list) + 1; - ((struct sockaddr_in6*) &intf->if_addr)->sin6_addr = a6; - ((struct sockaddr_in6*) &intf->if_addr)->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) &intf->if_addr)->sin6_addr = a6; + ((struct sockaddr_in6 *) &intf->if_addr)->sin6_family = AF_INET6; /* since every scope != 0 is ignored, we just set the scope to 0 */ - ((struct sockaddr_in6*) &intf->if_addr)->sin6_scope_id = 0; + ((struct sockaddr_in6 *) &intf->if_addr)->sin6_scope_id = 0; /* * hardcoded netmask, adrian says that's ok @@ -204,15 +193,12 @@ static int if_bsdx_ipv6_open(void) * (or create our own), getifaddrs() does not contain such * data */ - intf->if_kernel_index = - (uint16_t) if_nametoindex(cur_ifaddrs->ifa_name); + intf->if_kernel_index = (uint16_t) if_nametoindex(cur_ifaddrs->ifa_name); opal_list_append(&opal_if_list, &(intf->super)); - } /* of for loop over ifaddrs list */ + } /* of for loop over ifaddrs list */ free(ifadd_list); -#endif /* OPAL_ENABLE_IPV6 */ +#endif /* OPAL_ENABLE_IPV6 */ return OPAL_SUCCESS; } - - diff --git a/opal/mca/if/if.h b/opal/mca/if/if.h index c2993aebb72..d2f8f68d9b6 100644 --- a/opal/mca/if/if.h +++ b/opal/mca/if/if.h @@ -19,40 +19,40 @@ #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_SOCKIO_H -#include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_NET_IF_H -#include +# include #endif #ifdef HAVE_NETDB_H -#include +# include #endif #ifdef HAVE_IFADDRS_H -#include +# include #endif -#include "opal/util/if.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" +#include "opal/util/if.h" BEGIN_C_DECLS @@ -65,31 +65,29 @@ BEGIN_C_DECLS */ #if !defined(INADDR_NONE) -#define INADDR_NONE -1 +# define INADDR_NONE -1 #endif #define DEFAULT_NUMBER_INTERFACES 10 -#define MAX_IFCONF_SIZE 10 * 1024 * 1024 - +#define MAX_IFCONF_SIZE 10 * 1024 * 1024 typedef struct opal_if_t { - opal_list_item_t super; - char if_name[OPAL_IF_NAMESIZE]; - int if_index; - uint16_t if_kernel_index; - uint16_t af_family; - int if_flags; - int if_speed; - struct sockaddr_storage if_addr; - uint32_t if_mask; - uint32_t if_bandwidth; - uint8_t if_mac[6]; - int ifmtu; /* Can't use if_mtu because of a - #define collision on some BSDs */ + opal_list_item_t super; + char if_name[OPAL_IF_NAMESIZE]; + int if_index; + uint16_t if_kernel_index; + uint16_t af_family; + int if_flags; + int if_speed; + struct sockaddr_storage if_addr; + uint32_t if_mask; + uint32_t if_bandwidth; + uint8_t if_mac[6]; + int ifmtu; /* Can't use if_mtu because of a + #define collision on some BSDs */ } opal_if_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_if_t); - /* "global" list of available interfaces */ OPAL_DECLSPEC extern opal_list_t opal_if_list; @@ -114,8 +112,7 @@ typedef struct opal_if_base_component_2_0_0_t opal_if_base_component_t; /* * Macro for use in components that are of type if */ -#define OPAL_IF_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("if", 2, 0, 0) +#define OPAL_IF_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("if", 2, 0, 0) END_C_DECLS diff --git a/opal/mca/if/linux_ipv6/if_linux_ipv6.c b/opal/mca/if/linux_ipv6/if_linux_ipv6.c index e44b09de724..583c1ab115f 100644 --- a/opal/mca/if/linux_ipv6/if_linux_ipv6.c +++ b/opal/mca/if/linux_ipv6/if_linux_ipv6.c @@ -16,45 +16,45 @@ #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_SOCKIO_H -#include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_NET_IF_H -#include +# include #endif #ifdef HAVE_NETDB_H -#include +# include #endif #ifdef HAVE_IFADDRS_H -#include +# include #endif -#include "opal/runtime/opal.h" #include "opal/constants.h" +#include "opal/mca/if/base/base.h" +#include "opal/mca/if/if.h" +#include "opal/runtime/opal.h" #include "opal/util/if.h" #include "opal/util/output.h" #include "opal/util/show_help.h" #include "opal/util/string_copy.h" -#include "opal/mca/if/if.h" -#include "opal/mca/if/base/base.h" #define LOG_PREFIX "mca: if: linux_ipv6: " @@ -64,23 +64,15 @@ static int if_linux_ipv6_open(void); opal_if_base_component_t mca_if_linux_ipv6_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_IF_BASE_VERSION_2_0_0, - - /* Component name and version */ - "linux_ipv6", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - - /* Component open and close functions */ - if_linux_ipv6_open, - NULL - }, - { - /* This component is checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + {OPAL_IF_BASE_VERSION_2_0_0, + + /* Component name and version */ + "linux_ipv6", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + + /* Component open and close functions */ + if_linux_ipv6_open, NULL}, + {/* This component is checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; #if OPAL_ENABLE_IPV6 @@ -96,7 +88,6 @@ static bool hex2int(char hex, int *dst) return false; } return true; - } static bool hexdecode(const char *src, uint8_t *dst, size_t dstsize) @@ -125,36 +116,35 @@ static int if_linux_ipv6_open(void) char addrhex[sizeof a6.s6_addr * 2 + 1]; char addrstr[INET6_ADDRSTRLEN]; - while (fscanf(f, "%s %x %x %x %x %s\n", addrhex, - &idx, &pfxlen, &scope, &dadstat, ifname) != EOF) { + while (fscanf(f, "%s %x %x %x %x %s\n", addrhex, &idx, &pfxlen, &scope, &dadstat, ifname) + != EOF) { opal_if_t *intf; if (!hexdecode(addrhex, a6.s6_addr, sizeof a6.s6_addr)) { const char *hostname; hostname = opal_gethostname(); - opal_show_help("help-opal-if-linux-ipv6.txt", - "fail to parse if_inet6", true, + opal_show_help("help-opal-if-linux-ipv6.txt", "fail to parse if_inet6", true, hostname, ifname, addrhex); continue; }; inet_ntop(AF_INET6, a6.s6_addr, addrstr, sizeof addrstr); opal_output_verbose(1, opal_if_base_framework.framework_output, - LOG_PREFIX "found interface %s inet6 %s scope %x\n", - ifname, addrstr, scope); + LOG_PREFIX "found interface %s inet6 %s scope %x\n", ifname, + addrstr, scope); /* Only interested in global (0x00) scope */ - if (scope != 0x00) { + if (scope != 0x00) { opal_output_verbose(1, opal_if_base_framework.framework_output, - LOG_PREFIX "skipped interface %s inet6 %s scope %x\n", - ifname, addrstr, scope); + LOG_PREFIX "skipped interface %s inet6 %s scope %x\n", ifname, + addrstr, scope); continue; } intf = OBJ_NEW(opal_if_t); if (NULL == intf) { opal_output(0, LOG_PREFIX "unable to allocate %lu bytes\n", - (unsigned long)sizeof(opal_if_t)); + (unsigned long) sizeof(opal_if_t)); fclose(f); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -162,13 +152,13 @@ static int if_linux_ipv6_open(void) /* now construct the opal_if_t */ opal_string_copy(intf->if_name, ifname, OPAL_IF_NAMESIZE); - intf->if_index = opal_list_get_size(&opal_if_list)+1; + intf->if_index = opal_list_get_size(&opal_if_list) + 1; intf->if_kernel_index = (uint16_t) idx; - ((struct sockaddr_in6*) &intf->if_addr)->sin6_addr = a6; - ((struct sockaddr_in6*) &intf->if_addr)->sin6_family = AF_INET6; - ((struct sockaddr_in6*) &intf->if_addr)->sin6_scope_id = scope; + ((struct sockaddr_in6 *) &intf->if_addr)->sin6_addr = a6; + ((struct sockaddr_in6 *) &intf->if_addr)->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) &intf->if_addr)->sin6_scope_id = scope; intf->if_mask = pfxlen; - if (OPAL_SUCCESS == opal_ifindextoflags(opal_ifnametoindex (ifname), &flag)) { + if (OPAL_SUCCESS == opal_ifindextoflags(opal_ifnametoindex(ifname), &flag)) { intf->if_flags = flag; } else { intf->if_flags = IFF_UP; @@ -178,12 +168,12 @@ static int if_linux_ipv6_open(void) to list */ opal_list_append(&opal_if_list, &(intf->super)); opal_output_verbose(1, opal_if_base_framework.framework_output, - LOG_PREFIX "added interface %s inet6 %s scope %x\n", - ifname, addrstr, scope); + LOG_PREFIX "added interface %s inet6 %s scope %x\n", ifname, + addrstr, scope); } /* of while */ fclose(f); } -#endif /* OPAL_ENABLE_IPV6 */ +#endif /* OPAL_ENABLE_IPV6 */ return OPAL_SUCCESS; } diff --git a/opal/mca/if/posix_ipv4/if_posix.c b/opal/mca/if/posix_ipv4/if_posix.c index 0145ac8488b..48574b1fa7a 100644 --- a/opal/mca/if/posix_ipv4/if_posix.c +++ b/opal/mca/if/posix_ipv4/if_posix.c @@ -18,10 +18,10 @@ #include #include "opal/constants.h" +#include "opal/mca/if/base/base.h" +#include "opal/mca/if/if.h" #include "opal/util/output.h" #include "opal/util/string_copy.h" -#include "opal/mca/if/if.h" -#include "opal/mca/if/base/base.h" static int if_posix_open(void); @@ -31,27 +31,19 @@ static int if_posix_open(void); opal_if_base_component_t mca_if_posix_ipv4_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_IF_BASE_VERSION_2_0_0, - - /* Component name and version */ - "posix_ipv4", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - - /* Component open and close functions */ - if_posix_open, - NULL - }, - { - /* This component is checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + {OPAL_IF_BASE_VERSION_2_0_0, + + /* Component name and version */ + "posix_ipv4", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + + /* Component open and close functions */ + if_posix_open, NULL}, + {/* This component is checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; /* convert a netmask (in network byte order) to CIDR notation */ -static int prefix (uint32_t netmask) +static int prefix(uint32_t netmask) { uint32_t mask = ntohl(netmask); int plen = 0; @@ -82,8 +74,7 @@ static int if_posix_open(void) using AF_UNSPEC or AF_INET6 will cause everything to fail. */ if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - opal_output(0, "opal_ifinit: socket() failed with errno=%d\n", - errno); + opal_output(0, "opal_ifinit: socket() failed with errno=%d\n", errno); return OPAL_ERROR; } @@ -158,12 +149,12 @@ static int if_posix_open(void) /* * Setup indexes */ - ptr = (char*) ifconf.ifc_req; + ptr = (char *) ifconf.ifc_req; rem = ifconf.ifc_len; /* loop through all interfaces */ while (rem > 0) { - struct ifreq* ifr = (struct ifreq*) ptr; + struct ifreq *ifr = (struct ifreq *) ptr; opal_if_t *intf; int length; @@ -210,7 +201,8 @@ static int if_posix_open(void) intf = OBJ_NEW(opal_if_t); if (NULL == intf) { - opal_output(0, "opal_ifinit: unable to allocated %lu bytes\n", (unsigned long)sizeof(opal_if_t)); + opal_output(0, "opal_ifinit: unable to allocated %lu bytes\n", + (unsigned long) sizeof(opal_if_t)); free(ifconf.ifc_req); close(sd); return OPAL_ERR_OUT_OF_RESOURCE; @@ -223,27 +215,27 @@ static int if_posix_open(void) intf->if_flags = ifr->ifr_flags; /* every new address gets its own internal if_index */ - intf->if_index = opal_list_get_size(&opal_if_list)+1; + intf->if_index = opal_list_get_size(&opal_if_list) + 1; - opal_output_verbose(1, opal_if_base_framework.framework_output, - "found interface %s", intf->if_name); + opal_output_verbose(1, opal_if_base_framework.framework_output, "found interface %s", + intf->if_name); /* assign the kernel index to distinguish different NICs */ #ifndef SIOCGIFINDEX intf->if_kernel_index = intf->if_index; #else if (ioctl(sd, SIOCGIFINDEX, ifr) < 0) { - opal_output(0,"opal_ifinit: ioctl(SIOCGIFINDEX) failed with errno=%d", errno); + opal_output(0, "opal_ifinit: ioctl(SIOCGIFINDEX) failed with errno=%d", errno); OBJ_RELEASE(intf); continue; } -#if defined(ifr_ifindex) +# if defined(ifr_ifindex) intf->if_kernel_index = ifr->ifr_ifindex; -#elif defined(ifr_index) +# elif defined(ifr_index) intf->if_kernel_index = ifr->ifr_index; -#else +# else intf->if_kernel_index = -1; -#endif +# endif #endif /* SIOCGIFINDEX */ /* This call returns IPv4 addresses only. Use SIOCGLIFADDR @@ -268,7 +260,7 @@ static int if_posix_open(void) } /* generate CIDR and assign to netmask */ - intf->if_mask = prefix(((struct sockaddr_in*) &ifr->ifr_addr)->sin_addr.s_addr); + intf->if_mask = prefix(((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr); #if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR) /* get the MAC address */ @@ -295,5 +287,3 @@ static int if_posix_open(void) return OPAL_SUCCESS; } - - diff --git a/opal/mca/if/solaris_ipv6/if_solaris_ipv6.c b/opal/mca/if/solaris_ipv6/if_solaris_ipv6.c index 81c8ae1cda0..7103bc393cd 100644 --- a/opal/mca/if/solaris_ipv6/if_solaris_ipv6.c +++ b/opal/mca/if/solaris_ipv6/if_solaris_ipv6.c @@ -14,9 +14,9 @@ #include #include "opal/constants.h" +#include "opal/mca/if/if.h" #include "opal/util/output.h" #include "opal/util/string_copy.h" -#include "opal/mca/if/if.h" static int if_solaris_ipv6_open(void); @@ -24,23 +24,15 @@ static int if_solaris_ipv6_open(void); opal_if_base_component_t mca_if_solaris_ipv6_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_IF_BASE_VERSION_2_0_0, - - /* Component name and version */ - "solaris_ipv6", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - - /* Component open and close functions */ - if_solaris_ipv6_open, - NULL - }, - { - /* This component is checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + {OPAL_IF_BASE_VERSION_2_0_0, + + /* Component name and version */ + "solaris_ipv6", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, + + /* Component open and close functions */ + if_solaris_ipv6_open, NULL}, + {/* This component is checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; /* configure using getifaddrs(3) */ @@ -55,9 +47,9 @@ static int if_solaris_ipv6_open(void) struct lifconf lifconf; struct lifreq *lifreq, lifquery; - sd = socket (AF_INET6, SOCK_DGRAM, 0); + sd = socket(AF_INET6, SOCK_DGRAM, 0); if (sd < 0) { - opal_output (0, "opal_ifinit: unable to open IPv6 socket\n"); + opal_output(0, "opal_ifinit: unable to open IPv6 socket\n"); return OPAL_ERROR; } @@ -67,58 +59,52 @@ static int if_solaris_ipv6_open(void) lifnum.lifn_count = 0; /* get the number of interfaces in the system */ - error = ioctl (sd, SIOCGLIFNUM, &lifnum); + error = ioctl(sd, SIOCGLIFNUM, &lifnum); if (error < 0) { - opal_output (0, - "opal_ifinit: ioctl SIOCGLIFNUM failed with errno=%d\n", errno); + opal_output(0, "opal_ifinit: ioctl SIOCGLIFNUM failed with errno=%d\n", errno); return OPAL_ERROR; } - memset (&lifconf, 0, sizeof (struct lifconf)); - memset (&lifquery, 0, sizeof (struct lifreq)); + memset(&lifconf, 0, sizeof(struct lifconf)); + memset(&lifquery, 0, sizeof(struct lifreq)); lifconf.lifc_family = AF_INET6; lifconf.lifc_flags = 0; - lifconf.lifc_len = lifnum.lifn_count * sizeof (struct lifreq) * 2; - lifconf.lifc_buf = malloc (lifconf.lifc_len); + lifconf.lifc_len = lifnum.lifn_count * sizeof(struct lifreq) * 2; + lifconf.lifc_buf = malloc(lifconf.lifc_len); if (NULL == lifconf.lifc_buf) { - opal_output (0, "opal_ifinit: IPv6 discovery: malloc() failed\n"); + opal_output(0, "opal_ifinit: IPv6 discovery: malloc() failed\n"); return OPAL_ERR_OUT_OF_RESOURCE; } - memset (lifconf.lifc_buf, 0, lifconf.lifc_len); + memset(lifconf.lifc_buf, 0, lifconf.lifc_len); - error = ioctl (sd, SIOCGLIFCONF, &lifconf); + error = ioctl(sd, SIOCGLIFCONF, &lifconf); if (error < 0) { - opal_output (0, - "opal_ifinit: IPv6 SIOCGLIFCONF failed with errno=%d\n", errno); + opal_output(0, "opal_ifinit: IPv6 SIOCGLIFCONF failed with errno=%d\n", errno); } - for (i = 0; i + sizeof (struct lifreq) <= lifconf.lifc_len; - i += sizeof (*lifreq)) { + for (i = 0; i + sizeof(struct lifreq) <= lifconf.lifc_len; i += sizeof(*lifreq)) { - lifreq = (struct lifreq *)((caddr_t)lifconf.lifc_buf + i); - opal_string_copy (lifquery.lifr_name, lifreq->lifr_name, - sizeof (lifquery.lifr_name)); + lifreq = (struct lifreq *) ((caddr_t) lifconf.lifc_buf + i); + opal_string_copy(lifquery.lifr_name, lifreq->lifr_name, sizeof(lifquery.lifr_name)); /* lookup kernel index */ - error = ioctl (sd, SIOCGLIFINDEX, &lifquery); + error = ioctl(sd, SIOCGLIFINDEX, &lifquery); if (error < 0) { - opal_output (0, - "opal_ifinit: SIOCGLIFINDEX failed with errno=%d\n", errno); + opal_output(0, "opal_ifinit: SIOCGLIFINDEX failed with errno=%d\n", errno); return OPAL_ERROR; } kindex = lifquery.lifr_index; /* lookup interface flags */ - error = ioctl (sd, SIOCGLIFFLAGS, &lifquery); + error = ioctl(sd, SIOCGLIFFLAGS, &lifquery); if (error < 0) { - opal_output (0, - "opal_ifinit: SIOCGLIFFLAGS failed with errno=%d\n", errno); + opal_output(0, "opal_ifinit: SIOCGLIFFLAGS failed with errno=%d\n", errno); return OPAL_ERROR; } if (AF_INET6 == lifreq->lifr_addr.ss_family) { - struct sockaddr_in6* my_addr = (struct sockaddr_in6*) &lifreq->lifr_addr; + struct sockaddr_in6 *my_addr = (struct sockaddr_in6 *) &lifreq->lifr_addr; /* we surely want to check for sin6_scope_id, but Solaris does not set it correctly, so we have to look for global scope. For now, global is anything which is @@ -127,40 +113,35 @@ static int if_solaris_ipv6_open(void) Bug, FIXME: site-local, multicast, ... missing Check for 2000::/3? */ - if ( (!opal_if_retain_loopback && !IN6_IS_ADDR_LOOPBACK (&my_addr->sin6_addr)) && - (! IN6_IS_ADDR_LINKLOCAL (&my_addr->sin6_addr))) { + if ((!opal_if_retain_loopback && !IN6_IS_ADDR_LOOPBACK(&my_addr->sin6_addr)) + && (!IN6_IS_ADDR_LINKLOCAL(&my_addr->sin6_addr))) { /* create interface for newly found address */ opal_if_t *intf; intf = OBJ_NEW(opal_if_t); if (NULL == intf) { - opal_output (0, - "opal_ifinit: unable to allocate %d bytes\n", - sizeof (opal_if_t)); + opal_output(0, "opal_ifinit: unable to allocate %d bytes\n", sizeof(opal_if_t)); return OPAL_ERR_OUT_OF_RESOURCE; } intf->af_family = AF_INET6; - opal_string_copy (intf->if_name, lifreq->lifr_name, OPAL_IF_NAMESIZE); - intf->if_index = opal_list_get_size(&opal_if_list)+1; - memcpy(&intf->if_addr, my_addr, sizeof (*my_addr)); + opal_string_copy(intf->if_name, lifreq->lifr_name, OPAL_IF_NAMESIZE); + intf->if_index = opal_list_get_size(&opal_if_list) + 1; + memcpy(&intf->if_addr, my_addr, sizeof(*my_addr)); intf->if_mask = 64; /* lifrq flags are uint64_t */ - intf->if_flags = - (uint32_t)(0x00000000ffffffff) & lifquery.lifr_flags; + intf->if_flags = (uint32_t)(0x00000000ffffffff) & lifquery.lifr_flags; /* append to list */ - opal_list_append (&opal_if_list, &(intf->super)); + opal_list_append(&opal_if_list, &(intf->super)); } } } /* for */ if (NULL != lifconf.lifc_buf) { - free (lifconf.lifc_buf); + free(lifconf.lifc_buf); } -#endif /* OPAL_ENABLE_IPV6 */ +#endif /* OPAL_ENABLE_IPV6 */ return OPAL_SUCCESS; } - - diff --git a/opal/mca/installdirs/base/base.h b/opal/mca/installdirs/base/base.h index 94ad6fbfed9..32b3ae099c5 100644 --- a/opal/mca/installdirs/base/base.h +++ b/opal/mca/installdirs/base/base.h @@ -32,7 +32,7 @@ OPAL_DECLSPEC extern mca_base_framework_t opal_installdirs_base_framework; also insert the value of the environment variable $OPAL_DESTDIR, if it exists/is set. This function should *only* be used during the setup routines of installdirs. */ -char * opal_install_dirs_expand_setup(const char* input); +char *opal_install_dirs_expand_setup(const char *input); END_C_DECLS diff --git a/opal/mca/installdirs/base/installdirs_base_components.c b/opal/mca/installdirs/base/installdirs_base_components.c index 0c10e12fb6f..1daae990df0 100644 --- a/opal/mca/installdirs/base/installdirs_base_components.c +++ b/opal/mca/installdirs/base/installdirs_base_components.c @@ -16,108 +16,76 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/mca.h" -#include "opal/mca/installdirs/installdirs.h" #include "opal/mca/installdirs/base/base.h" #include "opal/mca/installdirs/base/static-components.h" +#include "opal/mca/installdirs/installdirs.h" +#include "opal/mca/mca.h" opal_install_dirs_t opal_install_dirs = {0}; -#define CONDITIONAL_COPY(target, origin, field) \ - do { \ - if (origin.field != NULL && target.field == NULL) { \ - target.field = origin.field; \ - } \ +#define CONDITIONAL_COPY(target, origin, field) \ + do { \ + if (origin.field != NULL && target.field == NULL) { \ + target.field = origin.field; \ + } \ } while (0) -static int -opal_installdirs_base_open(mca_base_open_flag_t flags) +static int opal_installdirs_base_open(mca_base_open_flag_t flags) { mca_base_component_list_item_t *component_item; int ret; - ret = mca_base_framework_components_open (&opal_installdirs_base_framework, - flags); + ret = mca_base_framework_components_open(&opal_installdirs_base_framework, flags); if (OPAL_SUCCESS != ret) { return ret; } - OPAL_LIST_FOREACH(component_item, &opal_installdirs_base_framework.framework_components, mca_base_component_list_item_t) { - const opal_installdirs_base_component_t *component = - (const opal_installdirs_base_component_t *) component_item->cli_component; + OPAL_LIST_FOREACH (component_item, &opal_installdirs_base_framework.framework_components, + mca_base_component_list_item_t) { + const opal_installdirs_base_component_t *component + = (const opal_installdirs_base_component_t *) component_item->cli_component; /* copy over the data, if something isn't already there */ - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - prefix); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - exec_prefix); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - bindir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - sbindir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - libexecdir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - datarootdir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - datadir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - sysconfdir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - sharedstatedir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - localstatedir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - libdir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - includedir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - infodir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - mandir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - opaldatadir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - opallibdir); - CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, - opalincludedir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, prefix); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, exec_prefix); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, bindir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, sbindir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, libexecdir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, datarootdir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, datadir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, sysconfdir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, sharedstatedir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, localstatedir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, libdir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, includedir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, infodir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, mandir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, opaldatadir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, opallibdir); + CONDITIONAL_COPY(opal_install_dirs, component->install_dirs_data, opalincludedir); } /* expand out all the fields */ - opal_install_dirs.prefix = - opal_install_dirs_expand_setup(opal_install_dirs.prefix); - opal_install_dirs.exec_prefix = - opal_install_dirs_expand_setup(opal_install_dirs.exec_prefix); - opal_install_dirs.bindir = - opal_install_dirs_expand_setup(opal_install_dirs.bindir); - opal_install_dirs.sbindir = - opal_install_dirs_expand_setup(opal_install_dirs.sbindir); - opal_install_dirs.libexecdir = - opal_install_dirs_expand_setup(opal_install_dirs.libexecdir); - opal_install_dirs.datarootdir = - opal_install_dirs_expand_setup(opal_install_dirs.datarootdir); - opal_install_dirs.datadir = - opal_install_dirs_expand_setup(opal_install_dirs.datadir); - opal_install_dirs.sysconfdir = - opal_install_dirs_expand_setup(opal_install_dirs.sysconfdir); - opal_install_dirs.sharedstatedir = - opal_install_dirs_expand_setup(opal_install_dirs.sharedstatedir); - opal_install_dirs.localstatedir = - opal_install_dirs_expand_setup(opal_install_dirs.localstatedir); - opal_install_dirs.libdir = - opal_install_dirs_expand_setup(opal_install_dirs.libdir); - opal_install_dirs.includedir = - opal_install_dirs_expand_setup(opal_install_dirs.includedir); - opal_install_dirs.infodir = - opal_install_dirs_expand_setup(opal_install_dirs.infodir); - opal_install_dirs.mandir = - opal_install_dirs_expand_setup(opal_install_dirs.mandir); - opal_install_dirs.opaldatadir = - opal_install_dirs_expand_setup(opal_install_dirs.opaldatadir); - opal_install_dirs.opallibdir = - opal_install_dirs_expand_setup(opal_install_dirs.opallibdir); - opal_install_dirs.opalincludedir = - opal_install_dirs_expand_setup(opal_install_dirs.opalincludedir); + opal_install_dirs.prefix = opal_install_dirs_expand_setup(opal_install_dirs.prefix); + opal_install_dirs.exec_prefix = opal_install_dirs_expand_setup(opal_install_dirs.exec_prefix); + opal_install_dirs.bindir = opal_install_dirs_expand_setup(opal_install_dirs.bindir); + opal_install_dirs.sbindir = opal_install_dirs_expand_setup(opal_install_dirs.sbindir); + opal_install_dirs.libexecdir = opal_install_dirs_expand_setup(opal_install_dirs.libexecdir); + opal_install_dirs.datarootdir = opal_install_dirs_expand_setup(opal_install_dirs.datarootdir); + opal_install_dirs.datadir = opal_install_dirs_expand_setup(opal_install_dirs.datadir); + opal_install_dirs.sysconfdir = opal_install_dirs_expand_setup(opal_install_dirs.sysconfdir); + opal_install_dirs.sharedstatedir = opal_install_dirs_expand_setup( + opal_install_dirs.sharedstatedir); + opal_install_dirs.localstatedir = opal_install_dirs_expand_setup( + opal_install_dirs.localstatedir); + opal_install_dirs.libdir = opal_install_dirs_expand_setup(opal_install_dirs.libdir); + opal_install_dirs.includedir = opal_install_dirs_expand_setup(opal_install_dirs.includedir); + opal_install_dirs.infodir = opal_install_dirs_expand_setup(opal_install_dirs.infodir); + opal_install_dirs.mandir = opal_install_dirs_expand_setup(opal_install_dirs.mandir); + opal_install_dirs.opaldatadir = opal_install_dirs_expand_setup(opal_install_dirs.opaldatadir); + opal_install_dirs.opallibdir = opal_install_dirs_expand_setup(opal_install_dirs.opallibdir); + opal_install_dirs.opalincludedir = opal_install_dirs_expand_setup( + opal_install_dirs.opalincludedir); #if 0 fprintf(stderr, "prefix: %s\n", opal_install_dirs.prefix); @@ -145,9 +113,7 @@ opal_installdirs_base_open(mca_base_open_flag_t flags) return OPAL_SUCCESS; } - -static int -opal_installdirs_base_close(void) +static int opal_installdirs_base_close(void) { free(opal_install_dirs.prefix); free(opal_install_dirs.exec_prefix); @@ -166,9 +132,9 @@ opal_installdirs_base_close(void) free(opal_install_dirs.opaldatadir); free(opal_install_dirs.opallibdir); free(opal_install_dirs.opalincludedir); - memset (&opal_install_dirs, 0, sizeof (opal_install_dirs)); + memset(&opal_install_dirs, 0, sizeof(opal_install_dirs)); - return mca_base_framework_components_close (&opal_installdirs_base_framework, NULL); + return mca_base_framework_components_close(&opal_installdirs_base_framework, NULL); } /* Declare the installdirs framework */ diff --git a/opal/mca/installdirs/base/installdirs_base_expand.c b/opal/mca/installdirs/base/installdirs_base_expand.c index 8c3d1324798..c483c545da4 100644 --- a/opal/mca/installdirs/base/installdirs_base_expand.c +++ b/opal/mca/installdirs/base/installdirs_base_expand.c @@ -17,10 +17,10 @@ #include -#include "opal/util/os_path.h" -#include "opal/util/printf.h" #include "opal/mca/installdirs/base/base.h" #include "opal/mca/installdirs/installdirs.h" +#include "opal/util/os_path.h" +#include "opal/util/printf.h" /* Support both ${name} and @{name} forms. The latter allows us to pass values through AC_SUBST without being munged by m4 (e.g., if @@ -28,36 +28,32 @@ whatever the actual value of the shell variable is. */ #define EXPAND_STRING(name) EXPAND_STRING2(name, name) -#define EXPAND_STRING2(ompiname, fieldname) \ - do { \ - if (NULL != (start_pos = strstr(retval, "${" #fieldname "}"))) { \ - tmp = retval; \ - *start_pos = '\0'; \ - end_pos = start_pos + strlen("${" #fieldname "}"); \ - opal_asprintf(&retval, "%s%s%s", tmp, \ - opal_install_dirs.ompiname + destdir_offset, \ - end_pos); \ - free(tmp); \ - changed = true; \ - } else if (NULL != (start_pos = strstr(retval, "@{" #fieldname "}"))) { \ - tmp = retval; \ - *start_pos = '\0'; \ - end_pos = start_pos + strlen("@{" #fieldname "}"); \ - opal_asprintf(&retval, "%s%s%s", tmp, \ - opal_install_dirs.ompiname + destdir_offset, \ - end_pos); \ - free(tmp); \ - changed = true; \ - } \ +#define EXPAND_STRING2(ompiname, fieldname) \ + do { \ + if (NULL != (start_pos = strstr(retval, "${" #fieldname "}"))) { \ + tmp = retval; \ + *start_pos = '\0'; \ + end_pos = start_pos + strlen("${" #fieldname "}"); \ + opal_asprintf(&retval, "%s%s%s", tmp, opal_install_dirs.ompiname + destdir_offset, \ + end_pos); \ + free(tmp); \ + changed = true; \ + } else if (NULL != (start_pos = strstr(retval, "@{" #fieldname "}"))) { \ + tmp = retval; \ + *start_pos = '\0'; \ + end_pos = start_pos + strlen("@{" #fieldname "}"); \ + opal_asprintf(&retval, "%s%s%s", tmp, opal_install_dirs.ompiname + destdir_offset, \ + end_pos); \ + free(tmp); \ + changed = true; \ + } \ } while (0) - /* * Read the lengthy comment below to understand the value of the * is_setup parameter. */ -static char * -opal_install_dirs_expand_internal(const char* input, bool is_setup) +static char *opal_install_dirs_expand_internal(const char *input, bool is_setup) { size_t len, i; bool needs_expand = false; @@ -113,7 +109,7 @@ opal_install_dirs_expand_internal(const char* input, bool is_setup) } len = strlen(input); - for (i = 0 ; i < len ; ++i) { + for (i = 0; i < len; ++i) { if ('$' == input[i] || '@' == input[i]) { needs_expand = true; break; @@ -121,7 +117,9 @@ opal_install_dirs_expand_internal(const char* input, bool is_setup) } retval = strdup(input); - if (NULL == retval) return NULL; + if (NULL == retval) { + return NULL; + } if (needs_expand) { bool changed = false; @@ -158,17 +156,13 @@ opal_install_dirs_expand_internal(const char* input, bool is_setup) return retval; } - -char * -opal_install_dirs_expand(const char* input) +char *opal_install_dirs_expand(const char *input) { /* We do NOT want OPAL_DESTDIR expansion in this case. */ return opal_install_dirs_expand_internal(input, false); } - -char * -opal_install_dirs_expand_setup(const char* input) +char *opal_install_dirs_expand_setup(const char *input) { /* We DO want OPAL_DESTDIR expansion in this case. */ return opal_install_dirs_expand_internal(input, true); diff --git a/opal/mca/installdirs/config/opal_installdirs_config.c b/opal/mca/installdirs/config/opal_installdirs_config.c index d2f8fa8d1de..201cc497f16 100644 --- a/opal/mca/installdirs/config/opal_installdirs_config.c +++ b/opal/mca/installdirs/config/opal_installdirs_config.c @@ -10,47 +10,23 @@ #include "opal_config.h" -#include "opal/mca/installdirs/installdirs.h" #include "opal/mca/installdirs/config/install_dirs.h" +#include "opal/mca/installdirs/installdirs.h" const opal_installdirs_base_component_t mca_installdirs_config_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_INSTALLDIRS_BASE_VERSION_2_0_0, + {OPAL_INSTALLDIRS_BASE_VERSION_2_0_0, - /* Component name and version */ - "config", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, + /* Component name and version */ + "config", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, - /* Component open and close functions */ - NULL, - NULL - }, - { - /* This component is Checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component open and close functions */ + NULL, NULL}, + {/* This component is Checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, - { - OPAL_PREFIX, - OPAL_EXEC_PREFIX, - OPAL_BINDIR, - OPAL_SBINDIR, - OPAL_LIBEXECDIR, - OPAL_DATAROOTDIR, - OPAL_DATADIR, - OPAL_SYSCONFDIR, - OPAL_SHAREDSTATEDIR, - OPAL_LOCALSTATEDIR, - OPAL_LIBDIR, - OPAL_INCLUDEDIR, - OPAL_INFODIR, - OPAL_MANDIR, - OPAL_PKGDATADIR, - OPAL_PKGLIBDIR, - OPAL_PKGINCLUDEDIR - } -}; + {OPAL_PREFIX, OPAL_EXEC_PREFIX, OPAL_BINDIR, OPAL_SBINDIR, OPAL_LIBEXECDIR, OPAL_DATAROOTDIR, + OPAL_DATADIR, OPAL_SYSCONFDIR, OPAL_SHAREDSTATEDIR, OPAL_LOCALSTATEDIR, OPAL_LIBDIR, + OPAL_INCLUDEDIR, OPAL_INFODIR, OPAL_MANDIR, OPAL_PKGDATADIR, OPAL_PKGLIBDIR, + OPAL_PKGINCLUDEDIR}}; diff --git a/opal/mca/installdirs/env/opal_installdirs_env.c b/opal/mca/installdirs/env/opal_installdirs_env.c index 340008e91d4..63cada8ee93 100644 --- a/opal/mca/installdirs/env/opal_installdirs_env.c +++ b/opal/mca/installdirs/env/opal_installdirs_env.c @@ -19,27 +19,18 @@ static int installdirs_env_open(void); - opal_installdirs_base_component_t mca_installdirs_env_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - { - OPAL_INSTALLDIRS_BASE_VERSION_2_0_0, + {OPAL_INSTALLDIRS_BASE_VERSION_2_0_0, - /* Component name and version */ - "env", - OPAL_MAJOR_VERSION, - OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, + /* Component name and version */ + "env", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, - /* Component open and close functions */ - installdirs_env_open, - NULL - }, - { - /* This component is checkpointable */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component open and close functions */ + installdirs_env_open, NULL}, + {/* This component is checkpointable */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, /* Next the opal_install_dirs_t install_dirs_data information */ { @@ -47,19 +38,16 @@ opal_installdirs_base_component_t mca_installdirs_env_component = { }, }; - -#define SET_FIELD(field, envname) \ - do { \ - char *tmp = getenv(envname); \ - if (NULL != tmp && 0 == strlen(tmp)) { \ - tmp = NULL; \ - } \ - mca_installdirs_env_component.install_dirs_data.field = tmp; \ +#define SET_FIELD(field, envname) \ + do { \ + char *tmp = getenv(envname); \ + if (NULL != tmp && 0 == strlen(tmp)) { \ + tmp = NULL; \ + } \ + mca_installdirs_env_component.install_dirs_data.field = tmp; \ } while (0) - -static int -installdirs_env_open(void) +static int installdirs_env_open(void) { SET_FIELD(prefix, "OPAL_PREFIX"); SET_FIELD(exec_prefix, "OPAL_EXEC_PREFIX"); diff --git a/opal/mca/installdirs/installdirs.h b/opal/mca/installdirs/installdirs.h index 7015adf31ea..bae70867ea6 100644 --- a/opal/mca/installdirs/installdirs.h +++ b/opal/mca/installdirs/installdirs.h @@ -14,8 +14,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" BEGIN_C_DECLS @@ -24,20 +24,20 @@ BEGIN_C_DECLS * once opal_init has been called is the opal_install_dirs structure * and the opal_install_dirs_expand() call */ struct opal_install_dirs_t { - char* prefix; - char* exec_prefix; - char* bindir; - char* sbindir; - char* libexecdir; - char* datarootdir; - char* datadir; - char* sysconfdir; - char* sharedstatedir; - char* localstatedir; - char* libdir; - char* includedir; - char* infodir; - char* mandir; + char *prefix; + char *exec_prefix; + char *bindir; + char *sbindir; + char *libexecdir; + char *datarootdir; + char *datadir; + char *sysconfdir; + char *sharedstatedir; + char *localstatedir; + char *libdir; + char *includedir; + char *infodir; + char *mandir; /* Note that the following fields intentionally have an "ompi" prefix, even though they're down in the OPAL layer. This is @@ -55,9 +55,9 @@ struct opal_install_dirs_t { Note that these field names match macros set by configure that are used in Makefile.am files. E.g., project help files are installed into $(opaldatadir). */ - char* opaldatadir; - char* opallibdir; - char* opalincludedir; + char *opaldatadir; + char *opallibdir; + char *opalincludedir; }; typedef struct opal_install_dirs_t opal_install_dirs_t; @@ -67,8 +67,7 @@ OPAL_DECLSPEC extern opal_install_dirs_t opal_install_dirs; /** * Expand out path variables (such as ${prefix}) in the input string * using the current opal_install_dirs structure */ -OPAL_DECLSPEC char * opal_install_dirs_expand(const char* input); - +OPAL_DECLSPEC char *opal_install_dirs_expand(const char *input); /** * Structure for installdirs components. @@ -89,8 +88,7 @@ typedef struct opal_installdirs_base_component_2_0_0_t opal_installdirs_base_com /* * Macro for use in components that are of type installdirs */ -#define OPAL_INSTALLDIRS_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("installdirs", 2, 0, 0) +#define OPAL_INSTALLDIRS_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("installdirs", 2, 0, 0) END_C_DECLS diff --git a/opal/mca/mca.h b/opal/mca/mca.h index 61bb5c7b963..859ee141687 100644 --- a/opal/mca/mca.h +++ b/opal/mca/mca.h @@ -92,7 +92,6 @@ #include "opal_config.h" - /** * Common type for all MCA modules. * @@ -110,7 +109,6 @@ typedef struct mca_base_module_2_0_0_t mca_base_module_t; /** Versioned convenience typedef */ typedef struct mca_base_module_2_0_0_t mca_base_module_2_0_0_t; - /** * MCA component open function. * @@ -243,7 +241,6 @@ typedef int (*mca_base_query_component_2_0_0_fn_t)(mca_base_module_2_0_0_t **mod */ typedef int (*mca_base_register_component_params_2_0_0_fn_t)(void); - /** * Maximum length of MCA project string names. */ @@ -284,61 +281,61 @@ enum { */ struct mca_base_component_2_1_0_t { - int mca_major_version; - /**< Major number of the MCA. */ - int mca_minor_version; - /**< Minor number of the MCA. */ - int mca_release_version; - /**< Release number of the MCA. */ + int mca_major_version; + /**< Major number of the MCA. */ + int mca_minor_version; + /**< Minor number of the MCA. */ + int mca_release_version; + /**< Release number of the MCA. */ - char mca_project_name[MCA_BASE_MAX_PROJECT_NAME_LEN + 1]; - /**< String name of the project that this component belongs to. */ - int mca_project_major_version; - /**< Major version number of the project that this component - belongs to. */ - int mca_project_minor_version; - /**< Minor version number of the project that this component - belongs to. */ - int mca_project_release_version; - /**< Release version number of the project that this component - belongs to. */ + char mca_project_name[MCA_BASE_MAX_PROJECT_NAME_LEN + 1]; + /**< String name of the project that this component belongs to. */ + int mca_project_major_version; + /**< Major version number of the project that this component + belongs to. */ + int mca_project_minor_version; + /**< Minor version number of the project that this component + belongs to. */ + int mca_project_release_version; + /**< Release version number of the project that this component + belongs to. */ - char mca_type_name[MCA_BASE_MAX_TYPE_NAME_LEN + 1]; - /**< String name of the framework that this component belongs to. */ - int mca_type_major_version; - /**< Major version number of the framework that this component - belongs to. */ - int mca_type_minor_version; - /**< Minor version number of the framework that this component - belongs to. */ - int mca_type_release_version; - /**< Release version number of the framework that this component - belongs to. */ + char mca_type_name[MCA_BASE_MAX_TYPE_NAME_LEN + 1]; + /**< String name of the framework that this component belongs to. */ + int mca_type_major_version; + /**< Major version number of the framework that this component + belongs to. */ + int mca_type_minor_version; + /**< Minor version number of the framework that this component + belongs to. */ + int mca_type_release_version; + /**< Release version number of the framework that this component + belongs to. */ - char mca_component_name[MCA_BASE_MAX_COMPONENT_NAME_LEN + 1]; - /**< This comopnent's string name. */ - int mca_component_major_version; - /**< This component's major version number. */ - int mca_component_minor_version; - /**< This component's minor version number. */ - int mca_component_release_version; - /**< This component's release version number. */ + char mca_component_name[MCA_BASE_MAX_COMPONENT_NAME_LEN + 1]; + /**< This comopnent's string name. */ + int mca_component_major_version; + /**< This component's major version number. */ + int mca_component_minor_version; + /**< This component's minor version number. */ + int mca_component_release_version; + /**< This component's release version number. */ - mca_base_open_component_1_0_0_fn_t mca_open_component; - /**< Method for opening this component. */ - mca_base_close_component_1_0_0_fn_t mca_close_component; - /**< Method for closing this component. */ - mca_base_query_component_2_0_0_fn_t mca_query_component; - /**< Method for querying this component. */ - mca_base_register_component_params_2_0_0_fn_t mca_register_component_params; - /**< Method for registering the component's MCA parameters */ + mca_base_open_component_1_0_0_fn_t mca_open_component; + /**< Method for opening this component. */ + mca_base_close_component_1_0_0_fn_t mca_close_component; + /**< Method for closing this component. */ + mca_base_query_component_2_0_0_fn_t mca_query_component; + /**< Method for querying this component. */ + mca_base_register_component_params_2_0_0_fn_t mca_register_component_params; + /**< Method for registering the component's MCA parameters */ - int32_t mca_component_flags; - /**< flags for this component */ + int32_t mca_component_flags; + /**< flags for this component */ - /** Extra space to allow for expansion in the future without - breaking older components. */ - char reserved[28]; + /** Extra space to allow for expansion in the future without + breaking older components. */ + char reserved[28]; }; /** Unversioned convenience typedef; use this name in frameworks/components to stay forward source-compatible */ @@ -349,9 +346,9 @@ typedef struct mca_base_component_2_1_0_t mca_base_component_2_1_0_t; /* * Metadata Bit field parameters */ -#define MCA_BASE_METADATA_PARAM_NONE (uint32_t)0x00 /**< No Metadata flags */ -#define MCA_BASE_METADATA_PARAM_CHECKPOINT (uint32_t)0x02 /**< Checkpoint enabled Component */ -#define MCA_BASE_METADATA_PARAM_DEBUG (uint32_t)0x04 /**< Debug enabled/only Component */ +#define MCA_BASE_METADATA_PARAM_NONE (uint32_t) 0x00 /**< No Metadata flags */ +#define MCA_BASE_METADATA_PARAM_CHECKPOINT (uint32_t) 0x02 /**< Checkpoint enabled Component */ +#define MCA_BASE_METADATA_PARAM_DEBUG (uint32_t) 0x04 /**< Debug enabled/only Component */ /** * Meta data for MCA v2.0.0 components. @@ -378,26 +375,23 @@ typedef struct mca_base_component_data_2_0_0_t mca_base_component_data_2_0_0_t; * indicating that they subscribe to the MCA version 2.0.0. See * component header files (e.g., coll.h) for examples of its usage. */ -#define MCA_BASE_VERSION_MAJOR 2 -#define MCA_BASE_VERSION_MINOR 1 +#define MCA_BASE_VERSION_MAJOR 2 +#define MCA_BASE_VERSION_MINOR 1 #define MCA_BASE_VERSION_RELEASE 0 -#define MCA_BASE_MAKE_VERSION(level, MAJOR, MINOR, RELEASE) \ - .mca_## level ##_major_version = MAJOR, \ - .mca_## level ##_minor_version = MINOR, \ - .mca_## level ##_release_version = RELEASE - +#define MCA_BASE_MAKE_VERSION(level, MAJOR, MINOR, RELEASE) \ + .mca_##level##_major_version = MAJOR, .mca_##level##_minor_version = MINOR, \ + .mca_##level##_release_version = RELEASE -#define MCA_BASE_VERSION_2_1_0(PROJECT, project_major, project_minor, project_release, TYPE, type_major, type_minor, type_release) \ - .mca_major_version = MCA_BASE_VERSION_MAJOR, \ - .mca_minor_version = MCA_BASE_VERSION_MINOR, \ - .mca_release_version = MCA_BASE_VERSION_RELEASE, \ - .mca_project_name = PROJECT, \ - MCA_BASE_MAKE_VERSION(project, project_major, project_minor, project_release), \ - .mca_type_name = TYPE, \ - MCA_BASE_MAKE_VERSION(type, type_major, type_minor, type_release) +#define MCA_BASE_VERSION_2_1_0(PROJECT, project_major, project_minor, project_release, TYPE, \ + type_major, type_minor, type_release) \ + .mca_major_version = MCA_BASE_VERSION_MAJOR, .mca_minor_version = MCA_BASE_VERSION_MINOR, \ + .mca_release_version = MCA_BASE_VERSION_RELEASE, .mca_project_name = PROJECT, \ + MCA_BASE_MAKE_VERSION(project, project_major, project_minor, project_release), \ + .mca_type_name = TYPE, MCA_BASE_MAKE_VERSION(type, type_major, type_minor, type_release) -#define OPAL_MCA_BASE_VERSION_2_1_0(type, type_major, type_minor, type_release) \ - MCA_BASE_VERSION_2_1_0("opal", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, type, type_major, type_minor, type_release) +#define OPAL_MCA_BASE_VERSION_2_1_0(type, type_major, type_minor, type_release) \ + MCA_BASE_VERSION_2_1_0("opal", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, \ + type, type_major, type_minor, type_release) #endif /* OPAL_MCA_H */ diff --git a/opal/mca/memchecker/base/base.h b/opal/mca/memchecker/base/base.h index a9796193413..6226124c3e4 100644 --- a/opal/mca/memchecker/base/base.h +++ b/opal/mca/memchecker/base/base.h @@ -45,14 +45,12 @@ OPAL_DECLSPEC extern bool opal_memchecker_base_selected; /** * Global component struct for the selected component */ -OPAL_DECLSPEC extern const opal_memchecker_base_component_2_0_0_t - *opal_memchecker_base_component; +OPAL_DECLSPEC extern const opal_memchecker_base_component_2_0_0_t *opal_memchecker_base_component; /** * Global module struct for the selected module */ -OPAL_DECLSPEC extern const opal_memchecker_base_module_1_0_0_t - *opal_memchecker_base_module; +OPAL_DECLSPEC extern const opal_memchecker_base_module_1_0_0_t *opal_memchecker_base_module; /** * Check if we are running under the memory debugger. @@ -63,10 +61,9 @@ OPAL_DECLSPEC extern const opal_memchecker_base_module_1_0_0_t */ OPAL_DECLSPEC int opal_memchecker_base_runindebugger(void); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_runindebugger() 0 +# define opal_memchecker_base_runindebugger() 0 #endif - /** * Check if a memory region is valid to address * @@ -78,12 +75,11 @@ OPAL_DECLSPEC int opal_memchecker_base_runindebugger(void); * This function calls the selected memchecker, whether * every Byte of this memory region is addressable */ -OPAL_DECLSPEC int opal_memchecker_base_isaddressable(void * p, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_isaddressable(void *p, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_isaddressable(p, len) 0 +# define opal_memchecker_base_isaddressable(p, len) 0 #endif - /** * Check if a memory region is defined * @@ -95,9 +91,9 @@ OPAL_DECLSPEC int opal_memchecker_base_isaddressable(void * p, size_t len); * This function calls the selected memchecker, whether * every Byte of this memory region is correctly initialized. */ -OPAL_DECLSPEC int opal_memchecker_base_isdefined(void * p, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_isdefined(void *p, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_isdefined(p, len) 0 +# define opal_memchecker_base_isdefined(p, len) 0 #endif /** @@ -111,9 +107,9 @@ OPAL_DECLSPEC int opal_memchecker_base_isdefined(void * p, size_t len); * This function calls the selected memchecker, to set * every Byte of this memory region to not accessible. */ -OPAL_DECLSPEC int opal_memchecker_base_mem_noaccess(void * p, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_mem_noaccess(void *p, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_mem_noaccess(p, len) +# define opal_memchecker_base_mem_noaccess(p, len) #endif /** @@ -127,9 +123,9 @@ OPAL_DECLSPEC int opal_memchecker_base_mem_noaccess(void * p, size_t len); * This function calls the selected memchecker, to set * every Byte of this memory region to not contain initialized data. */ -OPAL_DECLSPEC int opal_memchecker_base_mem_undefined(void * p, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_mem_undefined(void *p, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_mem_undefined(p, len) +# define opal_memchecker_base_mem_undefined(p, len) #endif /** @@ -143,9 +139,9 @@ OPAL_DECLSPEC int opal_memchecker_base_mem_undefined(void * p, size_t len); * This function calls the selected memchecker, to set * every Byte of this memory region to contain valid, initialized data. */ -OPAL_DECLSPEC int opal_memchecker_base_mem_defined(void * p, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_mem_defined(void *p, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_mem_defined(p, len) +# define opal_memchecker_base_mem_defined(p, len) #endif /** @@ -160,9 +156,9 @@ OPAL_DECLSPEC int opal_memchecker_base_mem_defined(void * p, size_t len); * every Byte of this memory region to contain valid, initialized data, * but only, if the memory region is addressable. */ -OPAL_DECLSPEC int opal_memchecker_base_mem_defined_if_addressable(void * p, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_mem_defined_if_addressable(void *p, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_mem_defined_if_addressable(p, len) +# define opal_memchecker_base_mem_defined_if_addressable(p, len) #endif /** @@ -177,9 +173,9 @@ OPAL_DECLSPEC int opal_memchecker_base_mem_defined_if_addressable(void * p, size * This function calls the selected memchecker, to name * this memory region. */ -OPAL_DECLSPEC int opal_memchecker_base_create_block(void * p, size_t len, char * description); +OPAL_DECLSPEC int opal_memchecker_base_create_block(void *p, size_t len, char *description); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_create_block(p, len, description) +# define opal_memchecker_base_create_block(p, len, description) #endif /** @@ -192,9 +188,9 @@ OPAL_DECLSPEC int opal_memchecker_base_create_block(void * p, size_t len, char * * This function calls the selected memchecker, to discard * the name information of the memory region. */ -OPAL_DECLSPEC int opal_memchecker_base_discard_block(void * p); +OPAL_DECLSPEC int opal_memchecker_base_discard_block(void *p); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_discard_block(p) +# define opal_memchecker_base_discard_block(p) #endif /** @@ -209,7 +205,7 @@ OPAL_DECLSPEC int opal_memchecker_base_discard_block(void * p); */ OPAL_DECLSPEC int opal_memchecker_base_leakcheck(void); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_leakcheck +# define opal_memchecker_base_leakcheck #endif /** @@ -224,9 +220,9 @@ OPAL_DECLSPEC int opal_memchecker_base_leakcheck(void); * This function calls the selected memchecker, to get * every vbit of this memory region. */ -OPAL_DECLSPEC int opal_memchecker_base_get_vbits(void * p, char * vbits, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_get_vbits(void *p, char *vbits, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_get_vbits(p, vbits, len) +# define opal_memchecker_base_get_vbits(p, vbits, len) #endif /** @@ -241,9 +237,9 @@ OPAL_DECLSPEC int opal_memchecker_base_get_vbits(void * p, char * vbits, size_t * This function calls the selected memchecker, to get * every vbit of this memory region. */ -OPAL_DECLSPEC int opal_memchecker_base_set_vbits(void * p, char * vbits, size_t len); +OPAL_DECLSPEC int opal_memchecker_base_set_vbits(void *p, char *vbits, size_t len); #if OPAL_WANT_MEMCHECKER == 0 -#define opal_memchecker_base_set_vbits(p, vbits, len) +# define opal_memchecker_base_set_vbits(p, vbits, len) #endif END_C_DECLS diff --git a/opal/mca/memchecker/base/memchecker_base_open.c b/opal/mca/memchecker/base/memchecker_base_open.c index 69eabb3370b..8f7bd11cf8b 100644 --- a/opal/mca/memchecker/base/memchecker_base_open.c +++ b/opal/mca/memchecker/base/memchecker_base_open.c @@ -8,15 +8,14 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/memchecker/memchecker.h" +#include "opal/mca/mca.h" #include "opal/mca/memchecker/base/base.h" +#include "opal/mca/memchecker/memchecker.h" +#include "opal/util/output.h" /* * The following file was created by configure. It contains extern diff --git a/opal/mca/memchecker/base/memchecker_base_select.c b/opal/mca/memchecker/base/memchecker_base_select.c index 3e701ed2edf..2200776857f 100644 --- a/opal/mca/memchecker/base/memchecker_base_select.c +++ b/opal/mca/memchecker/base/memchecker_base_select.c @@ -13,14 +13,13 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/memchecker/memchecker.h" +#include "opal/mca/mca.h" #include "opal/mca/memchecker/base/base.h" +#include "opal/mca/memchecker/memchecker.h" /* * Globals @@ -29,7 +28,6 @@ bool opal_memchecker_base_selected = false; const opal_memchecker_base_component_2_0_0_t *opal_memchecker_base_component = NULL; const opal_memchecker_base_module_1_0_0_t *opal_memchecker_base_module = NULL; - int opal_memchecker_base_select(void) { #if OPAL_WANT_MEMCHECKER @@ -40,10 +38,11 @@ int opal_memchecker_base_select(void) /* * Select the best component */ - if( OPAL_SUCCESS != mca_base_select("memchecker", opal_memchecker_base_framework.framework_output, - &opal_memchecker_base_framework.framework_components, - (mca_base_module_t **) &best_module, - (mca_base_component_t **) &best_component, NULL) ) { + if (OPAL_SUCCESS + != mca_base_select("memchecker", opal_memchecker_base_framework.framework_output, + &opal_memchecker_base_framework.framework_components, + (mca_base_module_t **) &best_module, + (mca_base_component_t **) &best_component, NULL)) { /* This will only happen if no component was selected */ exit_status = OPAL_ERR_NOT_FOUND; goto cleanup; @@ -51,21 +50,20 @@ int opal_memchecker_base_select(void) /* Save the winner */ opal_memchecker_base_component = best_component; - opal_memchecker_base_module = best_module; - opal_memchecker_base_selected = true; + opal_memchecker_base_module = best_module; + opal_memchecker_base_selected = true; /* Initialize the winner */ if (NULL != opal_memchecker_base_module) { - if (OPAL_SUCCESS != (ret = opal_memchecker_base_module->init()) ) { + if (OPAL_SUCCESS != (ret = opal_memchecker_base_module->init())) { exit_status = ret; goto cleanup; } } - cleanup: +cleanup: return exit_status; #else return OPAL_SUCCESS; #endif /* OPAL_WANT_MEMCHECKER */ } - diff --git a/opal/mca/memchecker/base/memchecker_base_wrappers.c b/opal/mca/memchecker/base/memchecker_base_wrappers.c index babadb918fb..d08f1d54654 100644 --- a/opal/mca/memchecker/base/memchecker_base_wrappers.c +++ b/opal/mca/memchecker/base/memchecker_base_wrappers.c @@ -8,79 +8,69 @@ * $HEADER$ */ - #include "opal_config.h" - #if OPAL_WANT_MEMCHECKER -#include "opal/mca/memchecker/memchecker.h" -#include "opal/mca/memchecker/base/base.h" +# include "opal/mca/memchecker/base/base.h" +# include "opal/mca/memchecker/memchecker.h" int opal_memchecker_base_runindebugger(void) { return opal_memchecker_base_module->runindebugger(); } -int opal_memchecker_base_isaddressable(void * p, size_t len) +int opal_memchecker_base_isaddressable(void *p, size_t len) { return opal_memchecker_base_module->isaddressable(p, len); } - -int opal_memchecker_base_isdefined(void * p, size_t len) +int opal_memchecker_base_isdefined(void *p, size_t len) { return opal_memchecker_base_module->isdefined(p, len); } - -int opal_memchecker_base_mem_noaccess(void * p, size_t len) +int opal_memchecker_base_mem_noaccess(void *p, size_t len) { return opal_memchecker_base_module->mem_noaccess(p, len); } - -int opal_memchecker_base_mem_undefined(void * p, size_t len) +int opal_memchecker_base_mem_undefined(void *p, size_t len) { return opal_memchecker_base_module->mem_undefined(p, len); } - -int opal_memchecker_base_mem_defined(void * p, size_t len) +int opal_memchecker_base_mem_defined(void *p, size_t len) { return opal_memchecker_base_module->mem_defined(p, len); } - -int opal_memchecker_base_mem_defined_if_addressable(void * p, size_t len) +int opal_memchecker_base_mem_defined_if_addressable(void *p, size_t len) { return opal_memchecker_base_module->mem_defined_if_addressable(p, len); } - -int opal_memchecker_base_create_block(void * p, size_t len, char * description) +int opal_memchecker_base_create_block(void *p, size_t len, char *description) { return opal_memchecker_base_module->create_block(p, len, description); } - -int opal_memchecker_base_discard_block(void * p) +int opal_memchecker_base_discard_block(void *p) { return opal_memchecker_base_module->discard_block(p); } - int opal_memchecker_base_leakcheck(void) { return opal_memchecker_base_module->leakcheck(); } -int opal_memchecker_base_get_vbits(void * p, char * vbits, size_t len) +int opal_memchecker_base_get_vbits(void *p, char *vbits, size_t len) { return opal_memchecker_base_module->get_vbits(p, vbits, len); } -int opal_memchecker_base_set_vbits(void * p, char * vbits, size_t len) +int opal_memchecker_base_set_vbits(void *p, char *vbits, size_t len) { return opal_memchecker_base_module->set_vbits(p, vbits, len); } diff --git a/opal/mca/memchecker/memchecker.h b/opal/mca/memchecker/memchecker.h index 120b0a417c7..eb9ce80f082 100644 --- a/opal/mca/memchecker/memchecker.h +++ b/opal/mca/memchecker/memchecker.h @@ -39,8 +39,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" /** * Module initialization function. Should return OPAL_SUCCESS. @@ -56,42 +56,44 @@ typedef int (*opal_memchecker_base_module_runindebugger_fn_t)(void); /** * Module function to check, whether memory region is addressable */ -typedef int (*opal_memchecker_base_module_isaddressable_fn_t)(void * p, size_t len); +typedef int (*opal_memchecker_base_module_isaddressable_fn_t)(void *p, size_t len); /** * Module function to check, whether memory region is defined */ -typedef int (*opal_memchecker_base_module_isdefined_fn_t)(void * p, size_t len); +typedef int (*opal_memchecker_base_module_isdefined_fn_t)(void *p, size_t len); /** * Module function to set memory region to not accessible */ -typedef int (*opal_memchecker_base_module_mem_noaccess_fn_t)(void * p, size_t len); +typedef int (*opal_memchecker_base_module_mem_noaccess_fn_t)(void *p, size_t len); /** * Module function to set memory region to undefined */ -typedef int (*opal_memchecker_base_module_mem_undefined_fn_t)(void * p, size_t len); +typedef int (*opal_memchecker_base_module_mem_undefined_fn_t)(void *p, size_t len); /** * Module function to set memory region to defined */ -typedef int (*opal_memchecker_base_module_mem_defined_fn_t)(void * p, size_t len); +typedef int (*opal_memchecker_base_module_mem_defined_fn_t)(void *p, size_t len); /** * Module function to set memory region to defined, but only if addressable */ -typedef int (*opal_memchecker_base_module_mem_defined_if_addressable_fn_t)(void * p, size_t len); +typedef int (*opal_memchecker_base_module_mem_defined_if_addressable_fn_t)(void *p, size_t len); /** * Module function name a specific memory region */ -typedef int (*opal_memchecker_base_module_create_block_fn_t)(void * p, size_t len, char * description); +typedef int (*opal_memchecker_base_module_create_block_fn_t)(void *p, size_t len, + char *description); /** * Module function to discard a named memory region */ -typedef int (*opal_memchecker_base_module_discard_block_fn_t)(void * p); /* Here, we need to do some mapping for valgrind */ +typedef int (*opal_memchecker_base_module_discard_block_fn_t)( + void *p); /* Here, we need to do some mapping for valgrind */ /** * Module function to check for any leaks @@ -101,14 +103,12 @@ typedef int (*opal_memchecker_base_module_leakcheck_fn_t)(void); /** * Module function to get vbits */ -typedef int (*opal_memchecker_base_module_get_vbits_fn_t)(void * p, char * vbits, size_t len); +typedef int (*opal_memchecker_base_module_get_vbits_fn_t)(void *p, char *vbits, size_t len); /** * Module function to set vbits */ -typedef int (*opal_memchecker_base_module_set_vbits_fn_t)(void * p, char * vbits, size_t len); - - +typedef int (*opal_memchecker_base_module_set_vbits_fn_t)(void *p, char *vbits, size_t len); /** * Structure for memchecker components. @@ -176,11 +176,9 @@ struct opal_memchecker_base_module_1_0_0_t { typedef struct opal_memchecker_base_module_1_0_0_t opal_memchecker_base_module_1_0_0_t; typedef struct opal_memchecker_base_module_1_0_0_t opal_memchecker_base_module_t; - /** * Macro for use in components that are of type memchecker */ -#define OPAL_MEMCHECKER_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("memchecker", 2, 0, 0) +#define OPAL_MEMCHECKER_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("memchecker", 2, 0, 0) #endif /* OPAL_MCA_MEMCHECKER_MEMCHECKER_H */ diff --git a/opal/mca/memchecker/valgrind/memchecker_valgrind.h b/opal/mca/memchecker/valgrind/memchecker_valgrind.h index ed504f05d39..34c5406bc9c 100644 --- a/opal/mca/memchecker/valgrind/memchecker_valgrind.h +++ b/opal/mca/memchecker/valgrind/memchecker_valgrind.h @@ -29,8 +29,7 @@ BEGIN_C_DECLS /** * Globally exported variable */ -OPAL_DECLSPEC extern const opal_memchecker_base_component_2_0_0_t - mca_memchecker_valgrind_component; +OPAL_DECLSPEC extern const opal_memchecker_base_component_2_0_0_t mca_memchecker_valgrind_component; /** * memchecker query API function diff --git a/opal/mca/memchecker/valgrind/memchecker_valgrind_component.c b/opal/mca/memchecker/valgrind/memchecker_valgrind_component.c index b06d882ec4a..ad7a1f322a9 100644 --- a/opal/mca/memchecker/valgrind/memchecker_valgrind_component.c +++ b/opal/mca/memchecker/valgrind/memchecker_valgrind_component.c @@ -24,17 +24,17 @@ #include "opal_config.h" +#include "memchecker_valgrind.h" #include "opal/constants.h" #include "opal/mca/memchecker/memchecker.h" -#include "memchecker_valgrind.h" int opal_memchecker_component_priority = 0; /* * Public string showing the memchecker ompi_linux component version number */ -const char *opal_memchecker_valgrind_component_version_string = - "OPAL valgrind memchecker MCA component version " OPAL_VERSION; +const char *opal_memchecker_valgrind_component_version_string + = "OPAL valgrind memchecker MCA component version " OPAL_VERSION; /* * Local function @@ -52,35 +52,30 @@ const opal_memchecker_base_component_2_0_0_t mca_memchecker_valgrind_component = /* First, the mca_component_t struct containing meta information about the component itself */ - .base_version = { - OPAL_MEMCHECKER_BASE_VERSION_2_0_0, - - /* Component name and version */ - .mca_component_name = "valgrind", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), + .base_version = {OPAL_MEMCHECKER_BASE_VERSION_2_0_0, - /* Component open and close functions */ - .mca_open_component = valgrind_open, - .mca_close_component = valgrind_close, - .mca_query_component = opal_memchecker_valgrind_component_query, - .mca_register_component_params = valgrind_register - }, - .base_data = { - /* Valgrind does not offer functionality to save the state */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - } -}; + /* Component name and version */ + .mca_component_name = "valgrind", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + /* Component open and close functions */ + .mca_open_component = valgrind_open, .mca_close_component = valgrind_close, + .mca_query_component = opal_memchecker_valgrind_component_query, + .mca_register_component_params = valgrind_register}, + .base_data = {/* Valgrind does not offer functionality to save the state */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}}; static int valgrind_register(void) { opal_memchecker_component_priority = 0; (void) mca_base_component_var_register(&mca_memchecker_valgrind_component.base_version, - "priority", "Priority for the memchecker valgrind " - "component (default: 0)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, + "priority", + "Priority for the memchecker valgrind " + "component (default: 0)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_memchecker_component_priority); return OPAL_SUCCESS; @@ -98,7 +93,6 @@ static int valgrind_open(void) return OPAL_SUCCESS; } - static int valgrind_close(void) { /* @@ -110,4 +104,3 @@ static int valgrind_close(void) */ return OPAL_SUCCESS; } - diff --git a/opal/mca/memchecker/valgrind/memchecker_valgrind_module.c b/opal/mca/memchecker/valgrind/memchecker_valgrind_module.c index a989736b477..2ece5a61780 100644 --- a/opal/mca/memchecker/valgrind/memchecker_valgrind_module.c +++ b/opal/mca/memchecker/valgrind/memchecker_valgrind_module.c @@ -20,28 +20,28 @@ #include "opal_config.h" +#include "memchecker_valgrind.h" #include "opal/constants.h" #include "opal/mca/base/mca_base_var.h" -#include "opal/mca/memchecker/memchecker.h" #include "opal/mca/memchecker/base/base.h" -#include "memchecker_valgrind.h" -#include "valgrind/valgrind.h" +#include "opal/mca/memchecker/memchecker.h" #include "valgrind/memcheck.h" - +#include "valgrind/valgrind.h" /* * Local functions */ static int valgrind_module_init(void); static int valgrind_module_runindebugger(void); -static int valgrind_module_isaddressable(void * p, size_t len); -static int valgrind_module_isdefined(void * p, size_t len); -static int valgrind_module_mem_noaccess(void * p, size_t len); -static int valgrind_module_mem_undefined(void * p, size_t len); -static int valgrind_module_mem_defined(void * p, size_t len); -static int valgrind_module_mem_defined_if_addressable(void * p, size_t len); -static int valgrind_module_create_block(void * p, size_t len, char * description); -static int valgrind_module_discard_block(void * p); /* Here, we need to do some mapping for valgrind */ +static int valgrind_module_isaddressable(void *p, size_t len); +static int valgrind_module_isdefined(void *p, size_t len); +static int valgrind_module_mem_noaccess(void *p, size_t len); +static int valgrind_module_mem_undefined(void *p, size_t len); +static int valgrind_module_mem_defined(void *p, size_t len); +static int valgrind_module_mem_defined_if_addressable(void *p, size_t len); +static int valgrind_module_create_block(void *p, size_t len, char *description); +static int +valgrind_module_discard_block(void *p); /* Here, we need to do some mapping for valgrind */ static int valgrind_module_leakcheck(void); #if 0 static int valgrind_module_get_vbits(void * p, char * vbits, size_t len); @@ -58,29 +58,20 @@ static const opal_memchecker_base_module_1_0_0_t loc_module = { valgrind_module_init, /* Module function pointers */ - valgrind_module_runindebugger, - valgrind_module_isaddressable, - valgrind_module_isdefined, - valgrind_module_mem_noaccess, - valgrind_module_mem_undefined, - valgrind_module_mem_defined, - valgrind_module_mem_defined_if_addressable, - valgrind_module_create_block, - valgrind_module_discard_block, - valgrind_module_leakcheck -}; - + valgrind_module_runindebugger, valgrind_module_isaddressable, valgrind_module_isdefined, + valgrind_module_mem_noaccess, valgrind_module_mem_undefined, valgrind_module_mem_defined, + valgrind_module_mem_defined_if_addressable, valgrind_module_create_block, + valgrind_module_discard_block, valgrind_module_leakcheck}; int opal_memchecker_valgrind_component_query(mca_base_module_t **module, int *priority) { *priority = opal_memchecker_component_priority; - *module = (mca_base_module_t *)&loc_module; + *module = (mca_base_module_t *) &loc_module; return OPAL_SUCCESS; } - static int valgrind_module_init(void) { /* Nothing to do yet, possibly update the amount of memory blocks. */ @@ -88,14 +79,12 @@ static int valgrind_module_init(void) return OPAL_SUCCESS; } - static int valgrind_module_runindebugger(void) { return RUNNING_ON_VALGRIND; } - -static int valgrind_module_isaddressable(void * p, size_t len) +static int valgrind_module_isaddressable(void *p, size_t len) { if (len > 0) { VALGRIND_CHECK_MEM_IS_ADDRESSABLE(p, len); @@ -104,8 +93,7 @@ static int valgrind_module_isaddressable(void * p, size_t len) return OPAL_SUCCESS; } - -static int valgrind_module_isdefined(void * p, size_t len) +static int valgrind_module_isdefined(void *p, size_t len) { if (len > 0) { VALGRIND_CHECK_MEM_IS_DEFINED(p, len); @@ -114,8 +102,7 @@ static int valgrind_module_isdefined(void * p, size_t len) return OPAL_SUCCESS; } - -static int valgrind_module_mem_noaccess(void * p, size_t len) +static int valgrind_module_mem_noaccess(void *p, size_t len) { if (len > 0) { VALGRIND_MAKE_MEM_NOACCESS(p, len); @@ -124,8 +111,7 @@ static int valgrind_module_mem_noaccess(void * p, size_t len) return OPAL_SUCCESS; } - -static int valgrind_module_mem_undefined(void * p, size_t len) +static int valgrind_module_mem_undefined(void *p, size_t len) { if (len > 0) { VALGRIND_MAKE_MEM_UNDEFINED(p, len); @@ -134,8 +120,7 @@ static int valgrind_module_mem_undefined(void * p, size_t len) return OPAL_SUCCESS; } - -static int valgrind_module_mem_defined(void * p, size_t len) +static int valgrind_module_mem_defined(void *p, size_t len) { if (len > 0) { VALGRIND_MAKE_MEM_DEFINED(p, len); @@ -144,8 +129,7 @@ static int valgrind_module_mem_defined(void * p, size_t len) return OPAL_SUCCESS; } - -static int valgrind_module_mem_defined_if_addressable(void * p, size_t len) +static int valgrind_module_mem_defined_if_addressable(void *p, size_t len) { if (len > 0) { VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(p, len); @@ -154,11 +138,10 @@ static int valgrind_module_mem_defined_if_addressable(void * p, size_t len) return OPAL_SUCCESS; } - -static int valgrind_module_create_block(void * p, size_t len, char * description) +static int valgrind_module_create_block(void *p, size_t len, char *description) { if (len > 0) { - VALGRIND_CREATE_BLOCK (p, len, description); + VALGRIND_CREATE_BLOCK(p, len, description); /* * Add p to some list atomically */ @@ -166,8 +149,7 @@ static int valgrind_module_create_block(void * p, size_t len, char * description return OPAL_SUCCESS; } - -static int valgrind_module_discard_block(void * p) +static int valgrind_module_discard_block(void *p) { /* Here, we need to do some mapping for valgrind */ /* @@ -176,14 +158,12 @@ static int valgrind_module_discard_block(void * p) return OPAL_SUCCESS; } - static int valgrind_module_leakcheck(void) { VALGRIND_DO_LEAK_CHECK; return OPAL_SUCCESS; } - #if 0 static int valgrind_module_get_vbits(void * p, char * vbits, size_t len) { @@ -204,4 +184,3 @@ static int valgrind_module_set_vbits(void * p, char * vbits, size_t len) return OPAL_SUCCESS; } #endif - diff --git a/opal/mca/memcpy/base/base.h b/opal/mca/memcpy/base/base.h index 7bd44254d14..7a7bc0a75bd 100644 --- a/opal/mca/memcpy/base/base.h +++ b/opal/mca/memcpy/base/base.h @@ -17,7 +17,6 @@ #include "opal/mca/base/mca_base_framework.h" #include "opal/mca/memcpy/memcpy.h" - /* * Global functions for MCA overall memcpy open and close */ diff --git a/opal/mca/memcpy/base/memcpy_base_default.h b/opal/mca/memcpy/base/memcpy_base_default.h index c567602ca43..f3d058bff0e 100644 --- a/opal/mca/memcpy/base/memcpy_base_default.h +++ b/opal/mca/memcpy/base/memcpy_base_default.h @@ -12,31 +12,28 @@ #ifndef OPAL_MCA_MEMCPY_BASE_MEMCPY_BASE_NULL_H #define OPAL_MCA_MEMCPY_BASE_MEMCPY_BASE_NULL_H -#define opal_memcpy( dst, src, length ) \ - memcpy( (dst), (src), (length) ); +#define opal_memcpy(dst, src, length) memcpy((dst), (src), (length)); -#define opal_memcpy_tov( dst_iov, src, count ) \ - do { \ - int _i; \ - char* _src = (char*)src; \ - \ - for( _i = 0; _i < count; _i++ ) { \ - opal_memcpy( dst_iov[_i].iov_base, _src, \ - dst_iov[_i].iov_len ); \ - _src += dst_iov[_i].iov_len; \ - } \ +#define opal_memcpy_tov(dst_iov, src, count) \ + do { \ + int _i; \ + char *_src = (char *) src; \ + \ + for (_i = 0; _i < count; _i++) { \ + opal_memcpy(dst_iov[_i].iov_base, _src, dst_iov[_i].iov_len); \ + _src += dst_iov[_i].iov_len; \ + } \ } while (0) -#define opal_memcpy_fromv( dst, src_iov, count ) \ - do { \ - int _i; \ - char* _dst = (char*)dst; \ - \ - for( _i = 0; _i < count; _i++ ) { \ - opal_memcpy( _dst, src_iov[_i].iov_base, \ - src_iov[_i].iov_len ); \ - _dst += src_iov[_i].iov_len; \ - } \ +#define opal_memcpy_fromv(dst, src_iov, count) \ + do { \ + int _i; \ + char *_dst = (char *) dst; \ + \ + for (_i = 0; _i < count; _i++) { \ + opal_memcpy(_dst, src_iov[_i].iov_base, src_iov[_i].iov_len); \ + _dst += src_iov[_i].iov_len; \ + } \ } while (0) #endif diff --git a/opal/mca/memcpy/base/memcpy_base_open.c b/opal/mca/memcpy/base/memcpy_base_open.c index 9b737f71984..84e9bbc00ea 100644 --- a/opal/mca/memcpy/base/memcpy_base_open.c +++ b/opal/mca/memcpy/base/memcpy_base_open.c @@ -9,15 +9,13 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/memcpy/memcpy.h" +#include "opal/mca/mca.h" #include "opal/mca/memcpy/base/base.h" - +#include "opal/mca/memcpy/memcpy.h" /* * The following file was created by configure. It contains extern @@ -30,5 +28,5 @@ * Globals */ /* Use default register/open/close functions */ -MCA_BASE_FRAMEWORK_DECLARE(opal, memcpy, NULL, NULL, NULL, NULL, - mca_memcpy_base_static_components, 0); +MCA_BASE_FRAMEWORK_DECLARE(opal, memcpy, NULL, NULL, NULL, NULL, mca_memcpy_base_static_components, + 0); diff --git a/opal/mca/memcpy/memcpy.h b/opal/mca/memcpy/memcpy.h index d8744844c4d..885a3094dee 100644 --- a/opal/mca/memcpy/memcpy.h +++ b/opal/mca/memcpy/memcpy.h @@ -22,8 +22,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" /** * Structure for memcpy components. @@ -43,7 +43,6 @@ typedef struct opal_memcpy_base_component_2_0_0_t opal_memcpy_base_component_2_0 /* * Macro for use in components that are of type memcpy */ -#define OPAL_MEMCPY_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("memcpy", 2, 0, 0) +#define OPAL_MEMCPY_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("memcpy", 2, 0, 0) #endif /* OPAL_MCA_MEMCPY_MEMCPY_H */ diff --git a/opal/mca/memory/base/base.h b/opal/mca/memory/base/base.h index 63e5b568031..2f1e227f89b 100644 --- a/opal/mca/memory/base/base.h +++ b/opal/mca/memory/base/base.h @@ -24,7 +24,6 @@ #include "opal/mca/base/mca_base_framework.h" #include "opal/mca/memory/memory.h" - BEGIN_C_DECLS /** @@ -32,7 +31,7 @@ BEGIN_C_DECLS */ OPAL_DECLSPEC extern mca_base_framework_t opal_memory_base_framework; -OPAL_DECLSPEC void opal_memory_base_malloc_init_hook (void); +OPAL_DECLSPEC void opal_memory_base_malloc_init_hook(void); END_C_DECLS #endif /* OPAL_BASE_MEMORY_H */ diff --git a/opal/mca/memory/base/empty.h b/opal/mca/memory/base/empty.h index 46cacc56e34..66fc8abc769 100644 --- a/opal/mca/memory/base/empty.h +++ b/opal/mca/memory/base/empty.h @@ -40,8 +40,7 @@ BEGIN_C_DECLS * * See opal/mca/memory/memory.h for a description of the parameters. */ -OPAL_DECLSPEC int opal_memory_base_component_register_empty(void *start, - size_t len, +OPAL_DECLSPEC int opal_memory_base_component_register_empty(void *start, size_t len, uint64_t cookie); /** @@ -49,8 +48,7 @@ OPAL_DECLSPEC int opal_memory_base_component_register_empty(void *start, * * See opal/mca/memory/memory.h for a description of the parameters. */ -OPAL_DECLSPEC int opal_memory_base_component_deregister_empty(void *start, - size_t len, +OPAL_DECLSPEC int opal_memory_base_component_deregister_empty(void *start, size_t len, uint64_t cookie); /** @@ -61,7 +59,6 @@ OPAL_DECLSPEC int opal_memory_base_component_deregister_empty(void *start, OPAL_DECLSPEC void opal_memory_base_component_set_alignment_empty(int use_memalign, size_t memalign_threshold); - END_C_DECLS #endif diff --git a/opal/mca/memory/base/memory_base_empty.c b/opal/mca/memory/base/memory_base_empty.c index c31db234873..5633c12aaa2 100644 --- a/opal/mca/memory/base/memory_base_empty.c +++ b/opal/mca/memory/base/memory_base_empty.c @@ -23,22 +23,16 @@ #include "opal/constants.h" #include "opal/mca/memory/base/empty.h" - -int opal_memory_base_component_register_empty(void *base, size_t len, - uint64_t cookie) +int opal_memory_base_component_register_empty(void *base, size_t len, uint64_t cookie) { return OPAL_SUCCESS; } - -int opal_memory_base_component_deregister_empty(void *base, size_t len, - uint64_t cookie) +int opal_memory_base_component_deregister_empty(void *base, size_t len, uint64_t cookie) { return OPAL_SUCCESS; } -void opal_memory_base_component_set_alignment_empty(int use_memalign, - size_t memalign_threshold) +void opal_memory_base_component_set_alignment_empty(int use_memalign, size_t memalign_threshold) { } - diff --git a/opal/mca/memory/base/memory_base_open.c b/opal/mca/memory/base/memory_base_open.c index 0560b93ae08..f632d735a99 100644 --- a/opal/mca/memory/base/memory_base_open.c +++ b/opal/mca/memory/base/memory_base_open.c @@ -22,16 +22,14 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/memory/memory.h" +#include "opal/mca/mca.h" #include "opal/mca/memory/base/base.h" #include "opal/mca/memory/base/empty.h" - +#include "opal/mca/memory/memory.h" /* * The following file was created by configure. It contains extern @@ -45,7 +43,7 @@ static int empty_process(void) return OPAL_SUCCESS; } -static int empty_query (int *priority) +static int empty_query(int *priority) { *priority = 0; return OPAL_SUCCESS; @@ -63,17 +61,15 @@ static opal_memory_base_component_2_0_0_t empty_component = { .memoryc_set_alignment = opal_memory_base_component_set_alignment_empty, }; - /* * Globals */ opal_memory_base_component_2_0_0_t *opal_memory = &empty_component; - -void opal_memory_base_malloc_init_hook (void) +void opal_memory_base_malloc_init_hook(void) { if (opal_memory->memoryc_init_hook) { - opal_memory->memoryc_init_hook (); + opal_memory->memoryc_init_hook(); } } @@ -89,9 +85,10 @@ static int opal_memory_base_open(mca_base_open_flag_t flags) int ret; /* can only be zero or one */ - OPAL_LIST_FOREACH(item, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH (item, &opal_memory_base_framework.framework_components, + mca_base_component_list_item_t) { tmp = (opal_memory_base_component_2_0_0_t *) item->cli_component; - ret = tmp->memoryc_query (&priority); + ret = tmp->memoryc_query(&priority); if (OPAL_SUCCESS != ret || priority < highest_priority) { continue; } @@ -100,15 +97,17 @@ static int opal_memory_base_open(mca_base_open_flag_t flags) opal_memory = tmp; } - OPAL_LIST_FOREACH_SAFE(item, next, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH_SAFE (item, next, &opal_memory_base_framework.framework_components, + mca_base_component_list_item_t) { if ((void *) opal_memory != (void *) item->cli_component) { - mca_base_component_unload (item->cli_component, opal_memory_base_framework.framework_output); - opal_list_remove_item (&opal_memory_base_framework.framework_components, &item->super); + mca_base_component_unload(item->cli_component, + opal_memory_base_framework.framework_output); + opal_list_remove_item(&opal_memory_base_framework.framework_components, &item->super); } } /* open remaining component */ - ret = mca_base_framework_components_open (&opal_memory_base_framework, flags); + ret = mca_base_framework_components_open(&opal_memory_base_framework, flags); if (ret != OPAL_SUCCESS) { return ret; } diff --git a/opal/mca/memory/malloc_solaris/memory_malloc_solaris_component.c b/opal/mca/memory/malloc_solaris/memory_malloc_solaris_component.c index 035d14ade41..e527ff93e4c 100644 --- a/opal/mca/memory/malloc_solaris/memory_malloc_solaris_component.c +++ b/opal/mca/memory/malloc_solaris/memory_malloc_solaris_component.c @@ -24,25 +24,24 @@ */ #include "opal_config.h" -#include "opal/mca/memory/memory.h" +#include "opal/constants.h" #include "opal/mca/memory/base/empty.h" +#include "opal/mca/memory/memory.h" #include "opal/memoryhooks/memory_internal.h" -#include "opal/constants.h" -#include +#include #include #include -#include +#include #if defined(HAVE___MUNMAP) /* here so we only include others if we absolutely have to */ #elif defined(HAVE_SYSCALL) -#include -#include +# include +# include #endif - #if defined(HAVE___MUNMAP) -int __munmap(caddr_t addr, size_t len); +int __munmap(caddr_t addr, size_t len); #endif static int opal_memory_malloc_open(void); @@ -51,21 +50,21 @@ static int opal_memory_malloc_query(int *); const opal_memory_base_component_2_0_0_t mca_memory_malloc_solaris_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .memoryc_version = { - OPAL_MEMORY_BASE_VERSION_2_0_0, + .memoryc_version = + { + OPAL_MEMORY_BASE_VERSION_2_0_0, - /* Component name and version */ - .mca_component_name = "malloc_solaris", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), + /* Component name and version */ + .mca_component_name = "malloc_solaris", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), - /* Component open and close functions */ - .mca_open_component = opal_memory_malloc_open, - }, - .memoryc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component open and close functions */ + .mca_open_component = opal_memory_malloc_open, + }, + .memoryc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, /* This component doesn't need these functions, but need to provide safe/empty register/deregister functions to call */ @@ -87,15 +86,13 @@ const opal_memory_base_component_2_0_0_t mca_memory_malloc_solaris_component = { * free() may be unique to Solaris which is why this component * was created. */ -static int -opal_memory_malloc_open(void) +static int opal_memory_malloc_open(void) { - opal_mem_hooks_set_support( - (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT)); + opal_mem_hooks_set_support((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT)); return OPAL_SUCCESS; } -static int opal_memory_malloc_query (int *priority) +static int opal_memory_malloc_query(int *priority) { *priority = 79; return OPAL_SUCCESS; @@ -109,17 +106,14 @@ static int opal_memory_malloc_query (int *priority) */ #if USE_SOLARIS_LEGACY_MUNMAP_PROTOTYPE /* We are compiling using S10 so use its munmap prototype */ -int -munmap(caddr_t addr, size_t len) +int munmap(caddr_t addr, size_t len) #else /* From S11 on forward munmap's addr is void * */ -int -munmap(void *addr, size_t len) +int munmap(void *addr, size_t len) #endif { -#if !defined(HAVE___MUNMAP) && \ - !defined(HAVE_SYSCALL) && defined(HAVE_DLSYM) - static int (*realmunmap)(void*, size_t); +#if !defined(HAVE___MUNMAP) && !defined(HAVE_SYSCALL) && defined(HAVE_DLSYM) + static int (*realmunmap)(void *, size_t); #endif opal_mem_hooks_release_hook(addr, len, 0); @@ -131,7 +125,7 @@ munmap(void *addr, size_t len) #elif defined(HAVE_DLSYM) if (NULL == realmunmap) { union { - int (*munmap_fp)(void*, size_t); + int (*munmap_fp)(void *, size_t); void *munmap_p; } tmp; @@ -140,6 +134,6 @@ munmap(void *addr, size_t len) } return realmunmap(addr, len); #else - #error "Can not determine how to call munmap" +# error "Can not determine how to call munmap" #endif } diff --git a/opal/mca/memory/memory.h b/opal/mca/memory/memory.h index b5968fd2640..846c745ea8f 100644 --- a/opal/mca/memory/memory.h +++ b/opal/mca/memory/memory.h @@ -63,8 +63,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" BEGIN_C_DECLS @@ -94,10 +94,7 @@ typedef int (*opal_memory_base_component_query_fn_t)(int *priority); * can use the value opal_memory_base_register_empty (an empty * implementation of this function). */ -typedef int (*opal_memory_base_component_register_fn_t)(void *base, - size_t len, - uint64_t cookie); - +typedef int (*opal_memory_base_component_register_fn_t)(void *base, size_t len, uint64_t cookie); /** * Prototype for a function that is the opposite of @@ -114,10 +111,7 @@ typedef int (*opal_memory_base_component_register_fn_t)(void *base, * can use the value opal_memory_base_deregister_empty (an empty * implementation of this function). */ -typedef int (*opal_memory_base_component_deregister_fn_t)(void *base, - size_t len, - uint64_t cookie); - +typedef int (*opal_memory_base_component_deregister_fn_t)(void *base, size_t len, uint64_t cookie); /** * Prototype for a function that set the memory alignment @@ -168,7 +162,6 @@ END_C_DECLS /* * Macro for use in components that are of type memory */ -#define OPAL_MEMORY_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("memory", 2, 0, 0) +#define OPAL_MEMORY_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("memory", 2, 0, 0) #endif /* OPAL_MCA_MEMORY_MEMORY_H */ diff --git a/opal/mca/memory/patcher/memory_patcher.h b/opal/mca/memory/patcher/memory_patcher.h index 1909443c549..ef9b7501f4c 100644 --- a/opal/mca/memory/patcher/memory_patcher.h +++ b/opal/mca/memory/patcher/memory_patcher.h @@ -11,15 +11,15 @@ */ #if !defined(OPAL_MEMORY_PATCHER_H) -#define OPAL_MEMORY_PATCHER_H +# define OPAL_MEMORY_PATCHER_H -#include "opal_config.h" +# include "opal_config.h" -#include "opal/mca/memory/memory.h" -#include "opal/mca/patcher/patcher.h" +# include "opal/mca/memory/memory.h" +# include "opal/mca/patcher/patcher.h" typedef struct opal_memory_patcher_component_t { - opal_memory_base_component_2_0_0_t super; + opal_memory_base_component_2_0_0_t super; } opal_memory_patcher_component_t; extern opal_memory_patcher_component_t mca_memory_patcher_component; diff --git a/opal/mca/memory/patcher/memory_patcher_component.c b/opal/mca/memory/patcher/memory_patcher_component.c index 8a83458fa1f..d48bf65f716 100644 --- a/opal/mca/memory/patcher/memory_patcher_component.c +++ b/opal/mca/memory/patcher/memory_patcher_component.c @@ -26,81 +26,82 @@ #include "memory_patcher.h" -#include "opal/util/output.h" -#include "opal/util/show_help.h" -#include "opal/mca/memory/base/empty.h" #include "opal/mca/memory/base/base.h" -#include "opal/memoryhooks/memory.h" +#include "opal/mca/memory/base/empty.h" #include "opal/mca/patcher/base/base.h" +#include "opal/memoryhooks/memory.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" -#include -#include -#include +#include +#include #include #include +#include +#include #include -#include -#include #include +#include #if defined(HAVE_SYS_SYSCALL_H) -#include +# include #endif #if defined(HAVE_LINUX_MMAN_H) -#include +# include #endif #if defined(HAVE_SYS_IPC_H) -#include +# include #endif #include "memory_patcher.h" #undef opal_memory_changed #if defined(SYS_shmdt) || (defined(IPCOP_shmdt) && defined(SYS_ipc)) -#define HAS_SHMDT 1 +# define HAS_SHMDT 1 #else -#define HAS_SHMDT 0 +# define HAS_SHMDT 0 #endif -#if defined(SYS_shmat) ||(defined(IPCOP_shmat) && defined(SYS_ipc)) -#define HAS_SHMAT 1 +#if defined(SYS_shmat) || (defined(IPCOP_shmat) && defined(SYS_ipc)) +# define HAS_SHMAT 1 #else -#define HAS_SHMAT 0 +# define HAS_SHMAT 0 #endif static int patcher_open(void); static int patcher_close(void); static int patcher_register(void); -static int patcher_query (int *); +static int patcher_query(int *); static int mca_memory_patcher_priority; opal_memory_patcher_component_t mca_memory_patcher_component = { - .super = { - .memoryc_version = { - OPAL_MEMORY_BASE_VERSION_2_0_0, - - /* Component name and version */ - .mca_component_name = "patcher", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - /* Component open and close functions */ - .mca_open_component = patcher_open, - .mca_close_component = patcher_close, - .mca_register_component_params = patcher_register, - }, - .memoryc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT + .super = + { + .memoryc_version = + { + OPAL_MEMORY_BASE_VERSION_2_0_0, + + /* Component name and version */ + .mca_component_name = "patcher", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + /* Component open and close functions */ + .mca_open_component = patcher_open, + .mca_close_component = patcher_close, + .mca_register_component_params = patcher_register, + }, + .memoryc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + /* Memory framework functions. */ + .memoryc_query = patcher_query, + .memoryc_register = opal_memory_base_component_register_empty, + .memoryc_deregister = opal_memory_base_component_deregister_empty, + .memoryc_set_alignment = opal_memory_base_component_set_alignment_empty, }, - /* Memory framework functions. */ - .memoryc_query = patcher_query, - .memoryc_register = opal_memory_base_component_register_empty, - .memoryc_deregister = opal_memory_base_component_deregister_empty, - .memoryc_set_alignment = opal_memory_base_component_set_alignment_empty, - }, - /* Component-specific data, filled in later (compiler will 0/NULL it out) */ }; @@ -108,9 +109,9 @@ opal_memory_patcher_component_t mca_memory_patcher_component = { #if HAVE_DECL___SYSCALL && defined(HAVE___SYSCALL) /* calling __syscall is preferred on some systems when some arguments may be 64-bit. it also * has the benefit of having an off_t return type */ -#define memory_patcher_syscall __syscall +# define memory_patcher_syscall __syscall #else -#define memory_patcher_syscall syscall +# define memory_patcher_syscall syscall #endif /* All the hooks in this file have two levels. The first level has the OPAL_PATCHER_* macros @@ -123,34 +124,38 @@ opal_memory_patcher_component_t mca_memory_patcher_component = { * Nathan's original fix described above can have the same problem reappear if the * interception functions inline themselves. */ -static void *_intercept_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) __opal_attribute_noinline__; +static void *_intercept_mmap(void *start, size_t length, int prot, int flags, int fd, + off_t offset) __opal_attribute_noinline__; static int _intercept_munmap(void *start, size_t length) __opal_attribute_noinline__; -#if defined (SYS_mremap) -#if defined(__linux__) -static void *_intercept_mremap (void *start, size_t oldlen, size_t newlen, int flags, void *new_address) __opal_attribute_noinline__; -#else -static void *_intercept_mremap (void *start, size_t oldlen, void *new_address, size_t newlen, int flags) __opal_attribute_noinline__; -#endif // defined(__linux__) +#if defined(SYS_mremap) +# if defined(__linux__) +static void *_intercept_mremap(void *start, size_t oldlen, size_t newlen, int flags, + void *new_address) __opal_attribute_noinline__; +# else +static void *_intercept_mremap(void *start, size_t oldlen, void *new_address, size_t newlen, + int flags) __opal_attribute_noinline__; +# endif // defined(__linux__) #endif // defined(SYS_mremap) -static int _intercept_madvise (void *start, size_t length, int advice) __opal_attribute_noinline__; +static int _intercept_madvise(void *start, size_t length, int advice) __opal_attribute_noinline__; #if defined SYS_brk -static int _intercept_brk (void *addr) __opal_attribute_noinline__; +static int _intercept_brk(void *addr) __opal_attribute_noinline__; #endif #if defined(__linux__) -#if HAS_SHMAT -static void *_intercept_shmat(int shmid, const void *shmaddr, int shmflg) __opal_attribute_noinline__; -#endif // HAS_SHMAT -#if HAS_SHMDT -static int _intercept_shmdt (const void *shmaddr) __opal_attribute_noinline__; -#endif // HAS_SHMDT +# if HAS_SHMAT +static void *_intercept_shmat(int shmid, const void *shmaddr, + int shmflg) __opal_attribute_noinline__; +# endif // HAS_SHMAT +# if HAS_SHMDT +static int _intercept_shmdt(const void *shmaddr) __opal_attribute_noinline__; +# endif // HAS_SHMDT #endif // defined(__linux__) -#if defined (SYS_mmap) +#if defined(SYS_mmap) -#if defined(HAVE___MMAP) && !HAVE_DECL___MMAP +# if defined(HAVE___MMAP) && !HAVE_DECL___MMAP /* prototype for Apple's internal mmap function */ -void *__mmap (void *start, size_t length, int prot, int flags, int fd, off_t offset); -#endif +void *__mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); +# endif static void *(*original_mmap)(void *, size_t, int, int, int, off_t); @@ -159,13 +164,14 @@ static void *_intercept_mmap(void *start, size_t length, int prot, int flags, in void *result = 0; if ((flags & MAP_FIXED) && (start != NULL)) { - opal_mem_hooks_release_hook (start, length, true); + opal_mem_hooks_release_hook(start, length, true); } if (!original_mmap) { - result = (void*)(intptr_t) memory_patcher_syscall(SYS_mmap, start, length, prot, flags, fd, offset); + result = (void *) (intptr_t) memory_patcher_syscall(SYS_mmap, start, length, prot, flags, + fd, offset); } else { - result = original_mmap (start, length, prot, flags, fd, offset); + result = original_mmap(start, length, prot, flags, fd, offset); } return result; @@ -174,26 +180,26 @@ static void *_intercept_mmap(void *start, size_t length, int prot, int flags, in static void *intercept_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { OPAL_PATCHER_BEGIN; - void *result = _intercept_mmap (start, length, prot, flags, fd, offset); + void *result = _intercept_mmap(start, length, prot, flags, fd, offset); OPAL_PATCHER_END; return result; } #endif -#if defined (SYS_munmap) -static int (*original_munmap) (void *, size_t); +#if defined(SYS_munmap) +static int (*original_munmap)(void *, size_t); static int _intercept_munmap(void *start, size_t length) { int result = 0; /* could be in a malloc implementation */ - opal_mem_hooks_release_hook (start, length, true); + opal_mem_hooks_release_hook(start, length, true); if (!original_munmap) { result = memory_patcher_syscall(SYS_munmap, start, length); } else { - result = original_munmap (start, length); + result = original_munmap(start, length); } return result; @@ -202,111 +208,116 @@ static int _intercept_munmap(void *start, size_t length) static int intercept_munmap(void *start, size_t length) { OPAL_PATCHER_BEGIN; - int result = _intercept_munmap (start, length); + int result = _intercept_munmap(start, length); OPAL_PATCHER_END; return result; } #endif -#if defined (SYS_mremap) +#if defined(SYS_mremap) -#if defined(__linux__) +# if defined(__linux__) /* on linux this function has an optional extra argument but ... can not be used here because it * causes issues when intercepting a 4-argument mremap call */ -static void *(*original_mremap) (void *, size_t, size_t, int, void *); -#else +static void *(*original_mremap)(void *, size_t, size_t, int, void *); +# else /* mremap has a different signature on BSD systems */ -static void *(*original_mremap) (void *, size_t, void *, size_t, int); -#endif - -#if defined(__linux__) -static void *_intercept_mremap (void *start, size_t oldlen, size_t newlen, int flags, void *new_address) -#else -static void *_intercept_mremap (void *start, size_t oldlen, void *new_address, size_t newlen, int flags) -#endif +static void *(*original_mremap)(void *, size_t, void *, size_t, int); +# endif + +# if defined(__linux__) +static void *_intercept_mremap(void *start, size_t oldlen, size_t newlen, int flags, + void *new_address) +# else +static void *_intercept_mremap(void *start, size_t oldlen, void *new_address, size_t newlen, + int flags) +# endif { void *result = MAP_FAILED; if (MAP_FAILED != start && oldlen > 0) { - opal_mem_hooks_release_hook (start, oldlen, true); + opal_mem_hooks_release_hook(start, oldlen, true); } -#if defined(MREMAP_FIXED) +# if defined(MREMAP_FIXED) if (!(flags & MREMAP_FIXED)) { new_address = NULL; } -#endif +# endif -#if defined(__linux__) +# if defined(__linux__) if (!original_mremap) { - result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, newlen, flags, new_address); + result = (void *) (intptr_t) memory_patcher_syscall(SYS_mremap, start, oldlen, newlen, + flags, new_address); } else { - result = original_mremap (start, oldlen, newlen, flags, new_address); + result = original_mremap(start, oldlen, newlen, flags, new_address); } -#else +# else if (!original_mremap) { - result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, new_address, newlen, flags); + result = (void *) (intptr_t) memory_patcher_syscall(SYS_mremap, start, oldlen, new_address, + newlen, flags); } else { - result = original_mremap (start, oldlen, new_address, newlen, flags); + result = original_mremap(start, oldlen, new_address, newlen, flags); } -#endif +# endif return result; } -#if defined(__linux__) -static void *intercept_mremap (void *start, size_t oldlen, size_t newlen, int flags, void *new_address) +# if defined(__linux__) +static void *intercept_mremap(void *start, size_t oldlen, size_t newlen, int flags, + void *new_address) { OPAL_PATCHER_BEGIN; - void *result = _intercept_mremap (start, oldlen, newlen, flags, new_address); + void *result = _intercept_mremap(start, oldlen, newlen, flags, new_address); OPAL_PATCHER_END; return result; } -#else -static void *intercept_mremap (void *start, size_t oldlen, void *new_address, size_t newlen, int flags) +# else +static void *intercept_mremap(void *start, size_t oldlen, void *new_address, size_t newlen, + int flags) { OPAL_PATCHER_BEGIN; - void *result = _intercept_mremap (start, oldlen, new_address, newlen, flags); + void *result = _intercept_mremap(start, oldlen, new_address, newlen, flags); OPAL_PATCHER_END; return result; } -#endif +# endif #endif -#if defined (SYS_madvise) +#if defined(SYS_madvise) -static int (*original_madvise) (void *, size_t, int); +static int (*original_madvise)(void *, size_t, int); -static int _intercept_madvise (void *start, size_t length, int advice) +static int _intercept_madvise(void *start, size_t length, int advice) { int result = 0; if (advice == MADV_DONTNEED || -#ifdef MADV_FREE +# ifdef MADV_FREE advice == MADV_FREE || -#endif -#ifdef MADV_REMOVE +# endif +# ifdef MADV_REMOVE advice == MADV_REMOVE || -#endif - advice == POSIX_MADV_DONTNEED) - { - opal_mem_hooks_release_hook (start, length, false); +# endif + advice == POSIX_MADV_DONTNEED) { + opal_mem_hooks_release_hook(start, length, false); } if (!original_madvise) { result = memory_patcher_syscall(SYS_madvise, start, length, advice); } else { - result = original_madvise (start, length, advice); + result = original_madvise(start, length, advice); } return result; } -static int intercept_madvise (void *start, size_t length, int advice) +static int intercept_madvise(void *start, size_t length, int advice) { OPAL_PATCHER_BEGIN; - int result = _intercept_madvise (start, length, advice); + int result = _intercept_madvise(start, length, advice); OPAL_PATCHER_END; return result; } @@ -315,57 +326,57 @@ static int intercept_madvise (void *start, size_t length, int advice) #if defined SYS_brk -#ifdef HAVE___CURBRK +# ifdef HAVE___CURBRK extern void *__curbrk; /* in libc */ -#endif +# endif -static int (*original_brk) (void *); +static int (*original_brk)(void *); -static int _intercept_brk (void *addr) +static int _intercept_brk(void *addr) { int result = 0; void *old_addr, *new_addr; -#ifdef HAVE___CURBRK +# ifdef HAVE___CURBRK old_addr = __curbrk; -#else - old_addr = sbrk (0); -#endif +# else + old_addr = sbrk(0); +# endif if (!original_brk) { /* get the current_addr */ new_addr = (void *) (intptr_t) memory_patcher_syscall(SYS_brk, addr); -#ifdef HAVE___CURBRK +# ifdef HAVE___CURBRK /* * Note: if we were using glibc brk/sbrk, their __curbrk would get * updated, but since we're going straight to the syscall, we have * to update __curbrk or else glibc won't see it. */ __curbrk = new_addr; -#endif +# endif } else { - result = original_brk (addr); -#ifdef HAVE___CURBRK + result = original_brk(addr); +# ifdef HAVE___CURBRK new_addr = __curbrk; -#else - new_addr = sbrk (0); -#endif +# else + new_addr = sbrk(0); +# endif } if (new_addr < addr) { errno = ENOMEM; result = -1; } else if (new_addr < old_addr) { - opal_mem_hooks_release_hook (new_addr, (intptr_t) old_addr - (intptr_t) new_addr, true); + opal_mem_hooks_release_hook(new_addr, (intptr_t) old_addr - (intptr_t) new_addr, true); } return result; } -static int intercept_brk (void *addr) +static int intercept_brk(void *addr) { OPAL_PATCHER_BEGIN; - int result = _intercept_brk (addr); + int result = _intercept_brk(addr); OPAL_PATCHER_END; return result; } @@ -378,20 +389,20 @@ static int intercept_brk (void *addr) // and when glibc uses that syscall it seems to do so from its own definitions: // https://github.com/bminor/glibc/search?q=IPCOP_shmat&unscoped_q=IPCOP_shmat #ifndef IPCOP_shmat -#define IPCOP_shmat 21 +# define IPCOP_shmat 21 #endif #ifndef IPCOP_shmdt -#define IPCOP_shmdt 22 +# define IPCOP_shmdt 22 #endif #if HAS_SHMDT || HAS_SHMAT -#if defined(__linux__) +# if defined(__linux__) -#include -#include -#include +# include +# include +# include -static size_t memory_patcher_get_shm_seg_size (const void *shmaddr) +static size_t memory_patcher_get_shm_seg_size(const void *shmaddr) { unsigned long start_addr, end_addr; char *ptr, *newline; @@ -401,12 +412,12 @@ static size_t memory_patcher_get_shm_seg_size (const void *shmaddr) seg_size = 0; - fd = open ("/proc/self/maps", O_RDONLY); + fd = open("/proc/self/maps", O_RDONLY); if (fd < 0) { return 0; } - for (size_t read_offset = 0 ; ; ) { + for (size_t read_offset = 0;;) { ssize_t nread = read(fd, buffer + read_offset, sizeof(buffer) - 1 - read_offset); if (nread <= 0) { if (errno == EINTR) { @@ -419,14 +430,14 @@ static size_t memory_patcher_get_shm_seg_size (const void *shmaddr) } ptr = buffer; - while ( (newline = strchr(ptr, '\n')) != NULL ) { + while ((newline = strchr(ptr, '\n')) != NULL) { /* 00400000-0040b000 r-xp ... \n */ int ret = sscanf(ptr, "%lx-%lx ", &start_addr, &end_addr); if (ret != 2) { continue; } - if (start_addr == (uintptr_t)shmaddr) { + if (start_addr == (uintptr_t) shmaddr) { seg_size = end_addr - start_addr; goto out_close; } @@ -443,7 +454,7 @@ static size_t memory_patcher_get_shm_seg_size (const void *shmaddr) memmove(buffer, ptr, read_offset); } - out_close: +out_close: close(fd); return seg_size; } @@ -460,11 +471,11 @@ static size_t get_shm_size(int shmid) return ds.shm_segsz; } -#endif +# endif #endif #if HAS_SHMAT -#if defined(__linux__) +# if defined(__linux__) static void *(*original_shmat)(int shmid, const void *shmaddr, int shmflg); static void *_intercept_shmat(int shmid, const void *shmaddr, int shmflg) @@ -474,95 +485,94 @@ static void *_intercept_shmat(int shmid, const void *shmaddr, int shmflg) size_t size = get_shm_size(shmid); if ((shmflg & SHM_REMAP) && (shmaddr != NULL)) { -// I don't really know what REMAP combined with SHM_RND does, so I'll just -// guess it remaps all the way down to the lower attach_addr, and all the -// way up to the original shmaddr+size - uintptr_t attach_addr = (uintptr_t)shmaddr; + // I don't really know what REMAP combined with SHM_RND does, so I'll just + // guess it remaps all the way down to the lower attach_addr, and all the + // way up to the original shmaddr+size + uintptr_t attach_addr = (uintptr_t) shmaddr; if (shmflg & SHM_RND) { - attach_addr -= ((uintptr_t)shmaddr) % SHMLBA; - size += ((uintptr_t)shmaddr) % SHMLBA; + attach_addr -= ((uintptr_t) shmaddr) % SHMLBA; + size += ((uintptr_t) shmaddr) % SHMLBA; } - opal_mem_hooks_release_hook ((void*)attach_addr, size, false); + opal_mem_hooks_release_hook((void *) attach_addr, size, false); } if (!original_shmat) { -#if defined(SYS_shmat) - result = (void*) memory_patcher_syscall(SYS_shmat, shmid, shmaddr, shmflg); -#else // IPCOP_shmat +# if defined(SYS_shmat) + result = (void *) memory_patcher_syscall(SYS_shmat, shmid, shmaddr, shmflg); +# else // IPCOP_shmat unsigned long ret; - ret = memory_patcher_syscall(SYS_ipc, IPCOP_shmat, - shmid, shmflg, &shmaddr, shmaddr); - result = (ret > -(unsigned long)SHMLBA) ? (void *)ret : (void *)shmaddr; -#endif + ret = memory_patcher_syscall(SYS_ipc, IPCOP_shmat, shmid, shmflg, &shmaddr, shmaddr); + result = (ret > -(unsigned long) SHMLBA) ? (void *) ret : (void *) shmaddr; +# endif } else { - result = original_shmat (shmid, shmaddr, shmflg); + result = original_shmat(shmid, shmaddr, shmflg); } return result; } -static void* intercept_shmat (int shmid, const void * shmaddr, int shmflg) +static void *intercept_shmat(int shmid, const void *shmaddr, int shmflg) { OPAL_PATCHER_BEGIN; - void *result = _intercept_shmat (shmid, shmaddr, shmflg); + void *result = _intercept_shmat(shmid, shmaddr, shmflg); OPAL_PATCHER_END; return result; } -#endif +# endif #endif #if HAS_SHMDT -#if defined(__linux__) -static int (*original_shmdt) (const void *); +# if defined(__linux__) +static int (*original_shmdt)(const void *); -static int _intercept_shmdt (const void *shmaddr) +static int _intercept_shmdt(const void *shmaddr) { int result; /* opal_mem_hooks_release_hook should probably be updated to take a const void *. * for now just cast away the const */ - opal_mem_hooks_release_hook ((void *) shmaddr, memory_patcher_get_shm_seg_size (shmaddr), false); + opal_mem_hooks_release_hook((void *) shmaddr, memory_patcher_get_shm_seg_size(shmaddr), false); if (original_shmdt) { - result = original_shmdt (shmaddr); + result = original_shmdt(shmaddr); } else { -#if defined(SYS_shmdt) - result = memory_patcher_syscall (SYS_shmdt, shmaddr); -#else // IPCOP_shmdt +# if defined(SYS_shmdt) + result = memory_patcher_syscall(SYS_shmdt, shmaddr); +# else // IPCOP_shmdt result = memory_patcher_syscall(SYS_ipc, IPCOP_shmdt, 0, 0, 0, shmaddr); -#endif +# endif } return result; } -static int intercept_shmdt (const void *shmaddr) +static int intercept_shmdt(const void *shmaddr) { OPAL_PATCHER_BEGIN; - int result = _intercept_shmdt (shmaddr); + int result = _intercept_shmdt(shmaddr); OPAL_PATCHER_END; return result; } -#endif +# endif #endif -static int patcher_register (void) +static int patcher_register(void) { mca_memory_patcher_priority = 80; - mca_base_component_var_register (&mca_memory_patcher_component.super.memoryc_version, - "priority", "Priority of the patcher memory hook component", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_CONSTANT, &mca_memory_patcher_priority); + mca_base_component_var_register(&mca_memory_patcher_component.super.memoryc_version, "priority", + "Priority of the patcher memory hook component", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_CONSTANT, &mca_memory_patcher_priority); return OPAL_SUCCESS; } -static int patcher_query (int *priority) +static int patcher_query(int *priority) { int rc; - rc = mca_base_framework_open (&opal_patcher_base_framework, 0); + rc = mca_base_framework_open(&opal_patcher_base_framework, 0); if (OPAL_SUCCESS != rc) { *priority = -1; return OPAL_SUCCESS; @@ -573,7 +583,7 @@ static int patcher_query (int *priority) return OPAL_SUCCESS; } -static int patcher_open (void) +static int patcher_open(void) { static int was_executed_already = 0; int rc; @@ -584,63 +594,69 @@ static int patcher_open (void) was_executed_already = 1; - rc = opal_patcher_base_select (); + rc = opal_patcher_base_select(); if (OPAL_SUCCESS != rc) { - mca_base_framework_close (&opal_patcher_base_framework); + mca_base_framework_close(&opal_patcher_base_framework); return OPAL_ERR_NOT_AVAILABLE; } /* set memory hooks support level */ - opal_mem_hooks_set_support (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT); + opal_mem_hooks_set_support(OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT); -#if defined (SYS_mmap) - rc = opal_patcher->patch_symbol ("mmap", (uintptr_t) intercept_mmap, (uintptr_t *) &original_mmap); +#if defined(SYS_mmap) + rc = opal_patcher->patch_symbol("mmap", (uintptr_t) intercept_mmap, + (uintptr_t *) &original_mmap); if (OPAL_SUCCESS != rc) { return rc; } #endif -#if defined (SYS_munmap) - rc = opal_patcher->patch_symbol ("munmap", (uintptr_t)intercept_munmap, (uintptr_t *) &original_munmap); +#if defined(SYS_munmap) + rc = opal_patcher->patch_symbol("munmap", (uintptr_t) intercept_munmap, + (uintptr_t *) &original_munmap); if (OPAL_SUCCESS != rc) { return rc; } #endif -#if defined (SYS_mremap) - rc = opal_patcher->patch_symbol ("mremap",(uintptr_t)intercept_mremap, (uintptr_t *) &original_mremap); +#if defined(SYS_mremap) + rc = opal_patcher->patch_symbol("mremap", (uintptr_t) intercept_mremap, + (uintptr_t *) &original_mremap); if (OPAL_SUCCESS != rc) { return rc; } #endif -#if defined (SYS_madvise) - rc = opal_patcher->patch_symbol ("madvise", (uintptr_t)intercept_madvise, (uintptr_t *) &original_madvise); +#if defined(SYS_madvise) + rc = opal_patcher->patch_symbol("madvise", (uintptr_t) intercept_madvise, + (uintptr_t *) &original_madvise); if (OPAL_SUCCESS != rc) { return rc; } #endif #if HAS_SHMAT -#if defined(__linux__) - rc = opal_patcher->patch_symbol ("shmat", (uintptr_t) intercept_shmat, (uintptr_t *) &original_shmat); +# if defined(__linux__) + rc = opal_patcher->patch_symbol("shmat", (uintptr_t) intercept_shmat, + (uintptr_t *) &original_shmat); if (OPAL_SUCCESS != rc) { return rc; } -#endif +# endif #endif #if defined(__linux__) -#if HAS_SHMDT - rc = opal_patcher->patch_symbol ("shmdt", (uintptr_t) intercept_shmdt, (uintptr_t *) &original_shmdt); +# if HAS_SHMDT + rc = opal_patcher->patch_symbol("shmdt", (uintptr_t) intercept_shmdt, + (uintptr_t *) &original_shmdt); if (OPAL_SUCCESS != rc) { return rc; } -#endif +# endif #endif -#if defined (SYS_brk) - rc = opal_patcher->patch_symbol ("brk", (uintptr_t)intercept_brk, (uintptr_t *) &original_brk); +#if defined(SYS_brk) + rc = opal_patcher->patch_symbol("brk", (uintptr_t) intercept_brk, (uintptr_t *) &original_brk); #endif return rc; @@ -648,7 +664,7 @@ static int patcher_open (void) static int patcher_close(void) { - mca_base_framework_close (&opal_patcher_base_framework); + mca_base_framework_close(&opal_patcher_base_framework); /* Note that we don't need to unpatch any symbols here; the patcher framework will take care of all of that for us. */ diff --git a/opal/mca/mpool/base/base.h b/opal/mca/mpool/base/base.h index 6d95665bff7..b56bad24fa0 100644 --- a/opal/mca/mpool/base/base.h +++ b/opal/mca/mpool/base/base.h @@ -50,10 +50,11 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_mpool_base_selected_module_t); * Global functions for MCA: overall mpool open and close */ -OPAL_DECLSPEC mca_mpool_base_component_t* mca_mpool_base_component_lookup(const char* name); -OPAL_DECLSPEC mca_mpool_base_module_t* mca_mpool_base_module_lookup(const char* name); +OPAL_DECLSPEC mca_mpool_base_component_t *mca_mpool_base_component_lookup(const char *name); +OPAL_DECLSPEC mca_mpool_base_module_t *mca_mpool_base_module_lookup(const char *name); -OPAL_DECLSPEC mca_mpool_base_module_t *mca_mpool_basic_create (void *base, size_t size, unsigned min_align); +OPAL_DECLSPEC mca_mpool_base_module_t *mca_mpool_basic_create(void *base, size_t size, + unsigned min_align); /* * Globals @@ -62,7 +63,6 @@ extern opal_list_t mca_mpool_base_modules; extern mca_mpool_base_module_t *mca_mpool_base_default_module; extern int mca_mpool_base_default_priority; - OPAL_DECLSPEC extern mca_base_framework_t opal_mpool_base_framework; END_C_DECLS diff --git a/opal/mca/mpool/base/mpool_base_alloc.c b/opal/mca/mpool/base/mpool_base_alloc.c index b75d8b07ad6..1bd7dfc4445 100644 --- a/opal/mca/mpool/base/mpool_base_alloc.c +++ b/opal/mca/mpool/base/mpool_base_alloc.c @@ -24,15 +24,14 @@ */ #include "opal_config.h" -#include -#include -#include "opal/mca/mpool/mpool.h" #include "base.h" #include "mpool_base_tree.h" +#include "opal/align.h" +#include "opal/mca/mpool/mpool.h" #include "opal/mca/threads/mutex.h" #include "opal/util/info.h" -#include "opal/align.h" - +#include +#include static void unregister_tree_item(mca_mpool_base_tree_item_t *mpool_tree_item) { @@ -65,9 +64,9 @@ void *mca_mpool_base_alloc(size_t size, opal_info_t *info, const char *hints) void *mem = NULL; #if defined(TODO_BTL_GB) int flag = 0; -#endif /* defined(TODO_BTL_GB) */ +#endif /* defined(TODO_BTL_GB) */ - mpool_tree_item = mca_mpool_base_tree_item_get (); + mpool_tree_item = mca_mpool_base_tree_item_get(); if (!mpool_tree_item) { return NULL; } @@ -75,20 +74,20 @@ void *mca_mpool_base_alloc(size_t size, opal_info_t *info, const char *hints) mpool_tree_item->num_bytes = size; mpool_tree_item->count = 0; - mpool = mca_mpool_base_module_lookup (hints); + mpool = mca_mpool_base_module_lookup(hints); if (NULL != mpool) { - mem = mpool->mpool_alloc (mpool, size, OPAL_ALIGN_MIN, 0); + mem = mpool->mpool_alloc(mpool, size, OPAL_ALIGN_MIN, 0); } if (NULL == mem) { /* fall back on malloc */ mem = malloc(size); - mca_mpool_base_tree_item_put (mpool_tree_item); + mca_mpool_base_tree_item_put(mpool_tree_item); } else { mpool_tree_item->mpool = mpool; mpool_tree_item->key = mem; - mca_mpool_base_tree_insert (mpool_tree_item); + mca_mpool_base_tree_insert(mpool_tree_item); } return mem; @@ -107,20 +106,20 @@ int mca_mpool_base_free(void *base) mca_mpool_base_tree_item_t *mpool_tree_item = NULL; int rc; - if(!base) { + if (!base) { return OPAL_ERROR; } mpool_tree_item = mca_mpool_base_tree_find(base); - if(!mpool_tree_item) { + if (!mpool_tree_item) { /* nothing in the tree this was just plain old malloc'd memory */ free(base); return OPAL_SUCCESS; } rc = mca_mpool_base_tree_delete(mpool_tree_item); - if(OPAL_SUCCESS == rc) { + if (OPAL_SUCCESS == rc) { unregister_tree_item(mpool_tree_item); mca_mpool_base_tree_item_put(mpool_tree_item); } diff --git a/opal/mca/mpool/base/mpool_base_basic.c b/opal/mca/mpool/base/mpool_base_basic.c index e11f5273eae..0cb84d2bf90 100644 --- a/opal/mca/mpool/base/mpool_base_basic.c +++ b/opal/mca/mpool/base/mpool_base_basic.c @@ -18,13 +18,13 @@ #include #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/mca/mpool/base/base.h" -#include "opal/constants.h" #include "opal/util/sys_limits.h" struct mca_mpool_base_basic_module_t { @@ -37,14 +37,14 @@ struct mca_mpool_base_basic_module_t { }; typedef struct mca_mpool_base_basic_module_t mca_mpool_base_basic_module_t; -static void *mca_mpool_base_basic_alloc (mca_mpool_base_module_t *mpool, size_t size, - size_t align, uint32_t flags) +static void *mca_mpool_base_basic_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags) { mca_mpool_base_basic_module_t *basic_module = (mca_mpool_base_basic_module_t *) mpool; uintptr_t next_ptr; void *ptr; - opal_mutex_lock (&basic_module->lock); + opal_mutex_lock(&basic_module->lock); align = align > basic_module->min_align ? align : basic_module->min_align; @@ -53,7 +53,7 @@ static void *mca_mpool_base_basic_alloc (mca_mpool_base_module_t *mpool, size_t size = OPAL_ALIGN(size, 8, size_t) + next_ptr - basic_module->ptr; if (size > basic_module->avail) { - opal_mutex_unlock (&basic_module->lock); + opal_mutex_unlock(&basic_module->lock); return NULL; } @@ -61,31 +61,31 @@ static void *mca_mpool_base_basic_alloc (mca_mpool_base_module_t *mpool, size_t basic_module->avail -= size; basic_module->ptr += size; - opal_mutex_unlock (&basic_module->lock); + opal_mutex_unlock(&basic_module->lock); return ptr; } /** - * free function - */ -static void mca_mpool_base_basic_free (mca_mpool_base_module_t *mpool, void *addr) + * free function + */ +static void mca_mpool_base_basic_free(mca_mpool_base_module_t *mpool, void *addr) { /* nothing to do for now */ } -static void mca_mpool_base_basic_finalize (struct mca_mpool_base_module_t *mpool) +static void mca_mpool_base_basic_finalize(struct mca_mpool_base_module_t *mpool) { mca_mpool_base_basic_module_t *basic_module = (mca_mpool_base_basic_module_t *) mpool; OBJ_DESTRUCT(&basic_module->lock); - free (mpool); + free(mpool); } static void *mca_mpool_base_basic_base(mca_mpool_base_module_t *mpool) { mca_mpool_base_basic_module_t *basic_module = (mca_mpool_base_basic_module_t *) mpool; - return (void*) basic_module->ptr; + return (void *) basic_module->ptr; } static mca_mpool_base_module_t mca_mpool_basic_template = { @@ -96,15 +96,15 @@ static mca_mpool_base_module_t mca_mpool_basic_template = { .flags = MCA_MPOOL_FLAGS_MPI_ALLOC_MEM, }; -mca_mpool_base_module_t *mca_mpool_basic_create (void *base, size_t size, unsigned min_align) +mca_mpool_base_module_t *mca_mpool_basic_create(void *base, size_t size, unsigned min_align) { - mca_mpool_base_basic_module_t *basic_module = calloc (1, sizeof (*basic_module)); + mca_mpool_base_basic_module_t *basic_module = calloc(1, sizeof(*basic_module)); if (OPAL_UNLIKELY(NULL == basic_module)) { return NULL; } - memcpy (&basic_module->super, &mca_mpool_basic_template, sizeof (mca_mpool_basic_template)); + memcpy(&basic_module->super, &mca_mpool_basic_template, sizeof(mca_mpool_basic_template)); OBJ_CONSTRUCT(&basic_module->lock, opal_mutex_t); diff --git a/opal/mca/mpool/base/mpool_base_default.c b/opal/mca/mpool/base/mpool_base_default.c index b176d3aaa75..e2251330846 100644 --- a/opal/mca/mpool/base/mpool_base_default.c +++ b/opal/mca/mpool/base/mpool_base_default.c @@ -16,67 +16,67 @@ #include #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/mca/mpool/base/base.h" -#include "opal/constants.h" #include "opal/util/sys_limits.h" -static void *mca_mpool_default_alloc (mca_mpool_base_module_t *mpool, size_t size, - size_t align, uint32_t flags) +static void *mca_mpool_default_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags) { #if HAVE_POSIX_MEMALIGN void *addr = NULL; if (align <= sizeof(void *)) { - addr = malloc (size); + addr = malloc(size); } else { - (void) posix_memalign (&addr, align, size); + (void) posix_memalign(&addr, align, size); } return addr; #else void *addr, *ret; - addr = malloc (size + align + sizeof (void *)); + addr = malloc(size + align + sizeof(void *)); ret = OPAL_ALIGN_PTR((intptr_t) addr + 8, align, void *); *((void **) ret - 1) = addr; return ret; #endif } -static void *mca_mpool_default_realloc (mca_mpool_base_module_t *mpool, void *addr, size_t size) +static void *mca_mpool_default_realloc(mca_mpool_base_module_t *mpool, void *addr, size_t size) { #if HAVE_POSIX_MEMALIGN - return realloc (addr, size); + return realloc(addr, size); #else if (NULL != addr) { void *base = *((void **) addr - 1); - void *ptr = realloc (base, size + (intptr_t) addr - (intptr_t) - size); - void *ret = (void *)((intptr_t) ptr + (intptr_t) addr - (intptr_t) - size); + void *ptr = realloc(base, size + (intptr_t) addr - (intptr_t) -size); + void *ret = (void *) ((intptr_t) ptr + (intptr_t) addr - (intptr_t) -size); *((void **) ret - 1) = ptr; return ret; } else { - return mca_mpool_default_alloc (mpool, size, 8, 0); + return mca_mpool_default_alloc(mpool, size, 8, 0); } #endif } -static void mca_mpool_default_free (mca_mpool_base_module_t *mpool, void *addr) +static void mca_mpool_default_free(mca_mpool_base_module_t *mpool, void *addr) { #if HAVE_POSIX_MEMALIGN - free (addr); + free(addr); #else if (NULL != addr) { void *base = *((void **) addr - 1); - free (base); + free(base); } #endif } -static void mca_mpool_default_finalize (struct mca_mpool_base_module_t *mpool) +static void mca_mpool_default_finalize(struct mca_mpool_base_module_t *mpool) { } diff --git a/opal/mca/mpool/base/mpool_base_frame.c b/opal/mca/mpool/base/mpool_base_frame.c index da0b146dac4..ad772011698 100644 --- a/opal/mca/mpool/base/mpool_base_frame.c +++ b/opal/mca/mpool/base/mpool_base_frame.c @@ -28,13 +28,13 @@ #include #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/mca/mpool/base/base.h" -#include "opal/constants.h" #include "opal/util/sys_limits.h" /* @@ -56,23 +56,20 @@ int mca_mpool_base_default_priority = 50; OBJ_CLASS_INSTANCE(mca_mpool_base_selected_module_t, opal_list_item_t, NULL, NULL); -static int mca_mpool_base_register (mca_base_register_flag_t flags) +static int mca_mpool_base_register(mca_base_register_flag_t flags) { mca_mpool_base_default_hints = NULL; - (void) mca_base_var_register ("opal", "mpool", "base", "default_hints", - "Hints to use when selecting the default memory pool", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, - MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, - &mca_mpool_base_default_hints); + (void) mca_base_var_register("opal", "mpool", "base", "default_hints", + "Hints to use when selecting the default memory pool", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, + &mca_mpool_base_default_hints); mca_mpool_base_default_priority = 50; - (void) mca_base_var_register ("opal", "mpool", "base", "default_priority", - "Priority of the default mpool module", - MCA_BASE_VAR_TYPE_INT, NULL, 0, - MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, - &mca_mpool_base_default_priority); + (void) mca_base_var_register("opal", "mpool", "base", "default_priority", + "Priority of the default mpool module", MCA_BASE_VAR_TYPE_INT, + NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_mpool_base_default_priority); return OPAL_SUCCESS; } @@ -85,17 +82,16 @@ static int mca_mpool_base_open(mca_base_open_flag_t flags) { /* Open up all available components - and populate the opal_mpool_base_framework.framework_components list */ - if (OPAL_SUCCESS != - mca_base_framework_components_open(&opal_mpool_base_framework, flags)) { + if (OPAL_SUCCESS != mca_base_framework_components_open(&opal_mpool_base_framework, flags)) { return OPAL_ERROR; } if (mca_mpool_base_default_hints) { - mca_mpool_base_default_module = mca_mpool_base_module_lookup (mca_mpool_base_default_hints); + mca_mpool_base_default_module = mca_mpool_base_module_lookup(mca_mpool_base_default_hints); } - /* Initialize the list so that in mca_mpool_base_close(), we can - iterate over it (even if it's empty, as in the case of opal_info) */ + /* Initialize the list so that in mca_mpool_base_close(), we can + iterate over it (even if it's empty, as in the case of opal_info) */ OBJ_CONSTRUCT(&mca_mpool_base_modules, opal_list_t); /* setup tree for tracking MPI_Alloc_mem */ @@ -106,33 +102,34 @@ static int mca_mpool_base_open(mca_base_open_flag_t flags) static int mca_mpool_base_close(void) { - opal_list_item_t *item; - mca_mpool_base_selected_module_t *sm; + opal_list_item_t *item; + mca_mpool_base_selected_module_t *sm; - /* Finalize all the mpool components and free their list items */ + /* Finalize all the mpool components and free their list items */ - while(NULL != (item = opal_list_remove_first(&mca_mpool_base_modules))) { - sm = (mca_mpool_base_selected_module_t *) item; + while (NULL != (item = opal_list_remove_first(&mca_mpool_base_modules))) { + sm = (mca_mpool_base_selected_module_t *) item; - /* Blatently ignore the return code (what would we do to recover, - anyway? This component is going away, so errors don't matter - anymore). Note that it's legal for the module to have NULL for - the finalize function. */ + /* Blatently ignore the return code (what would we do to recover, + anyway? This component is going away, so errors don't matter + anymore). Note that it's legal for the module to have NULL for + the finalize function. */ - if (NULL != sm->mpool_module->mpool_finalize) { - sm->mpool_module->mpool_finalize(sm->mpool_module); + if (NULL != sm->mpool_module->mpool_finalize) { + sm->mpool_module->mpool_finalize(sm->mpool_module); + } + OBJ_RELEASE(sm); } - OBJ_RELEASE(sm); - } - /* Close all remaining available components (may be one if this is a - OMPI RTE program, or [possibly] multiple if this is opal_info) */ - (void) mca_base_framework_components_close(&opal_mpool_base_framework, NULL); + /* Close all remaining available components (may be one if this is a + OMPI RTE program, or [possibly] multiple if this is opal_info) */ + (void) mca_base_framework_components_close(&opal_mpool_base_framework, NULL); - mca_mpool_base_tree_fini(); + mca_mpool_base_tree_fini(); - return OPAL_SUCCESS; + return OPAL_SUCCESS; } -MCA_BASE_FRAMEWORK_DECLARE(opal, mpool, "Memory pools", mca_mpool_base_register, mca_mpool_base_open, - mca_mpool_base_close, mca_mpool_base_static_components, 0); +MCA_BASE_FRAMEWORK_DECLARE(opal, mpool, "Memory pools", mca_mpool_base_register, + mca_mpool_base_open, mca_mpool_base_close, + mca_mpool_base_static_components, 0); diff --git a/opal/mca/mpool/base/mpool_base_lookup.c b/opal/mca/mpool/base/mpool_base_lookup.c index fa0e0ce34af..d64fabcec3f 100644 --- a/opal/mca/mpool/base/mpool_base_lookup.c +++ b/opal/mca/mpool/base/mpool_base_lookup.c @@ -26,21 +26,22 @@ #include #include -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/util/show_help.h" +#include "opal/mca/mca.h" #include "opal/util/proc.h" +#include "opal/util/show_help.h" -#include "opal/mca/mpool/mpool.h" #include "opal/mca/mpool/base/base.h" +#include "opal/mca/mpool/mpool.h" -mca_mpool_base_component_t* mca_mpool_base_component_lookup(const char *name) +mca_mpool_base_component_t *mca_mpool_base_component_lookup(const char *name) { mca_base_component_list_item_t *cli; /* Traverse the list of available modules; call their init functions. */ - OPAL_LIST_FOREACH(cli, &opal_mpool_base_framework.framework_components, mca_base_component_list_item_t) { - mca_mpool_base_component_t* component = (mca_mpool_base_component_t *) cli->cli_component; + OPAL_LIST_FOREACH (cli, &opal_mpool_base_framework.framework_components, + mca_base_component_list_item_t) { + mca_mpool_base_component_t *component = (mca_mpool_base_component_t *) cli->cli_component; if (strcmp(component->mpool_version.mca_component_name, name) == 0) { return component; } @@ -49,27 +50,26 @@ mca_mpool_base_component_t* mca_mpool_base_component_lookup(const char *name) return NULL; } - - -mca_mpool_base_module_t *mca_mpool_base_module_lookup (const char *hints) +mca_mpool_base_module_t *mca_mpool_base_module_lookup(const char *hints) { mca_mpool_base_module_t *best_module = mca_mpool_base_default_module; mca_base_component_list_item_t *cli; int best_priority = mca_mpool_base_default_priority; int rc; - OPAL_LIST_FOREACH(cli, &opal_mpool_base_framework.framework_components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH (cli, &opal_mpool_base_framework.framework_components, + mca_base_component_list_item_t) { mca_mpool_base_component_t *component = (mca_mpool_base_component_t *) cli->cli_component; - mca_mpool_base_module_t *module; - int priority; + mca_mpool_base_module_t *module; + int priority; - rc = component->mpool_query (hints, &priority, &module); - if (OPAL_SUCCESS == rc) { - if (priority > best_priority) { - best_priority = priority; - best_module = module; - } - } + rc = component->mpool_query(hints, &priority, &module); + if (OPAL_SUCCESS == rc) { + if (priority > best_priority) { + best_priority = priority; + best_module = module; + } + } } return best_module; diff --git a/opal/mca/mpool/base/mpool_base_tree.c b/opal/mca/mpool/base/mpool_base_tree.c index a5937f03820..29a5ba3e690 100644 --- a/opal/mca/mpool/base/mpool_base_tree.c +++ b/opal/mca/mpool/base/mpool_base_tree.c @@ -29,13 +29,12 @@ #include "opal_config.h" #include "opal/mca/mca.h" -#include "opal/util/show_help.h" -#include "opal/util/proc.h" #include "opal/util/printf.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" -#include "opal/class/opal_rb_tree.h" #include "mpool_base_tree.h" - +#include "opal/class/opal_rb_tree.h" static int num_leaks = 0; static int max_mem_leaks = -1; @@ -44,11 +43,13 @@ static char *leak_msg = NULL; static int condition(void *value); static void action(void *key, void *value); -static void opal_mca_mpool_base_tree_constructor(mca_mpool_base_tree_item_t *item) { +static void opal_mca_mpool_base_tree_constructor(mca_mpool_base_tree_item_t *item) +{ item->key = NULL; } -OBJ_CLASS_INSTANCE(mca_mpool_base_tree_item_t, opal_free_list_item_t, opal_mca_mpool_base_tree_constructor, NULL); +OBJ_CLASS_INSTANCE(mca_mpool_base_tree_item_t, opal_free_list_item_t, + opal_mca_mpool_base_tree_constructor, NULL); /* * use globals for the tree and the tree_item free list.. @@ -60,18 +61,13 @@ static opal_mutex_t tree_lock; /* * simple minded compare function... */ -int mca_mpool_base_tree_node_compare(void * key1, void * key2) +int mca_mpool_base_tree_node_compare(void *key1, void *key2) { - if(key1 < key2) - { + if (key1 < key2) { return -1; - } - else if(key1 > key2) - { + } else if (key1 > key2) { return 1; - } - else - { + } else { return 0; } } @@ -79,18 +75,17 @@ int mca_mpool_base_tree_node_compare(void * key1, void * key2) /* * initialize the rb tree */ -int mca_mpool_base_tree_init(void) { +int mca_mpool_base_tree_init(void) +{ int rc; OBJ_CONSTRUCT(&mca_mpool_base_tree, opal_rb_tree_t); OBJ_CONSTRUCT(&mca_mpool_base_tree_item_free_list, opal_free_list_t); OBJ_CONSTRUCT(&tree_lock, opal_mutex_t); - rc = opal_free_list_init (&mca_mpool_base_tree_item_free_list, - sizeof(mca_mpool_base_tree_item_t), - opal_cache_line_size, - OBJ_CLASS(mca_mpool_base_tree_item_t), - 0,opal_cache_line_size, - 0, -1 , 4, NULL, 0, NULL, NULL, NULL); - if(OPAL_SUCCESS == rc) { + rc = opal_free_list_init(&mca_mpool_base_tree_item_free_list, + sizeof(mca_mpool_base_tree_item_t), opal_cache_line_size, + OBJ_CLASS(mca_mpool_base_tree_item_t), 0, opal_cache_line_size, 0, -1, + 4, NULL, 0, NULL, NULL, NULL); + if (OPAL_SUCCESS == rc) { rc = opal_rb_tree_init(&mca_mpool_base_tree, mca_mpool_base_tree_node_compare); } return rc; @@ -110,7 +105,8 @@ int mca_mpool_base_tree_fini(void) /* * insert an item in the rb tree */ -int mca_mpool_base_tree_insert(mca_mpool_base_tree_item_t* item) { +int mca_mpool_base_tree_insert(mca_mpool_base_tree_item_t *item) +{ int rc; OPAL_THREAD_LOCK(&tree_lock); @@ -130,7 +126,8 @@ int mca_mpool_base_tree_insert(mca_mpool_base_tree_item_t* item) { * race conditions can occur * */ -int mca_mpool_base_tree_delete(mca_mpool_base_tree_item_t* item) { +int mca_mpool_base_tree_delete(mca_mpool_base_tree_item_t *item) +{ int rc; OPAL_THREAD_LOCK(&tree_lock); @@ -143,12 +140,12 @@ int mca_mpool_base_tree_delete(mca_mpool_base_tree_item_t* item) { /** * find the item in the rb tree */ -mca_mpool_base_tree_item_t* mca_mpool_base_tree_find(void* base) { - mca_mpool_base_tree_item_t* item; +mca_mpool_base_tree_item_t *mca_mpool_base_tree_find(void *base) +{ + mca_mpool_base_tree_item_t *item; OPAL_THREAD_LOCK(&tree_lock); - item = (mca_mpool_base_tree_item_t*)opal_rb_tree_find(&mca_mpool_base_tree, - base); + item = (mca_mpool_base_tree_item_t *) opal_rb_tree_find(&mca_mpool_base_tree, base); OPAL_THREAD_UNLOCK(&tree_lock); return item; @@ -157,20 +154,19 @@ mca_mpool_base_tree_item_t* mca_mpool_base_tree_find(void* base) { /* * get a tree item from the free list */ -mca_mpool_base_tree_item_t* mca_mpool_base_tree_item_get(void) { - return (mca_mpool_base_tree_item_t *) - opal_free_list_get (&mca_mpool_base_tree_item_free_list); +mca_mpool_base_tree_item_t *mca_mpool_base_tree_item_get(void) +{ + return (mca_mpool_base_tree_item_t *) opal_free_list_get(&mca_mpool_base_tree_item_free_list); } /* * put an item back into the free list */ -void mca_mpool_base_tree_item_put(mca_mpool_base_tree_item_t* item) { - opal_free_list_return (&mca_mpool_base_tree_item_free_list, - &item->super); +void mca_mpool_base_tree_item_put(mca_mpool_base_tree_item_t *item) +{ + opal_free_list_return(&mca_mpool_base_tree_item_free_list, &item->super); } - /* * Print a show_help kind of message for an items still left in the * tree @@ -189,52 +185,43 @@ void mca_mpool_base_tree_print(int show_up_to_mem_leaks) return; } - if (num_leaks <= show_up_to_mem_leaks || - show_up_to_mem_leaks < 0) { - opal_show_help("help-mpool-base.txt", "all mem leaks", - true, OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), - opal_process_info.nodename, - getpid(), leak_msg); + if (num_leaks <= show_up_to_mem_leaks || show_up_to_mem_leaks < 0) { + opal_show_help("help-mpool-base.txt", "all mem leaks", true, + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), opal_process_info.nodename, getpid(), + leak_msg); } else { int i = num_leaks - show_up_to_mem_leaks; - opal_show_help("help-mpool-base.txt", "some mem leaks", - true, OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), - opal_process_info.nodename, - getpid(), leak_msg, i, - (i > 1) ? "s were" : " was", - (i > 1) ? "are" : "is"); + opal_show_help("help-mpool-base.txt", "some mem leaks", true, + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), opal_process_info.nodename, getpid(), + leak_msg, i, (i > 1) ? "s were" : " was", (i > 1) ? "are" : "is"); } free(leak_msg); leak_msg = NULL; } - /* Condition function for rb traversal */ static int condition(void *value) { return 1; } - /* Action function for rb traversal */ static void action(void *key, void *value) { char *tmp; mca_mpool_base_tree_item_t *item = (mca_mpool_base_tree_item_t *) value; - if( (++num_leaks <= max_mem_leaks) || (max_mem_leaks < 0) ) { + if ((++num_leaks <= max_mem_leaks) || (max_mem_leaks < 0)) { /* We know that we're supposed to make the first one; check on successive items if we're supposed to catenate more notices. */ if (NULL == leak_msg) { opal_asprintf(&leak_msg, " %lu bytes at address 0x%lx", - (unsigned long) item->num_bytes, - (unsigned long) key); + (unsigned long) item->num_bytes, (unsigned long) key); } else { - opal_asprintf(&tmp, "%s\n %lu bytes at address 0x%lx", - leak_msg, (unsigned long) item->num_bytes, - (unsigned long) key); + opal_asprintf(&tmp, "%s\n %lu bytes at address 0x%lx", leak_msg, + (unsigned long) item->num_bytes, (unsigned long) key); free(leak_msg); leak_msg = tmp; } diff --git a/opal/mca/mpool/base/mpool_base_tree.h b/opal/mca/mpool/base/mpool_base_tree.h index 2a31175a77f..6842eb98f9f 100644 --- a/opal/mca/mpool/base/mpool_base_tree.h +++ b/opal/mca/mpool/base/mpool_base_tree.h @@ -40,15 +40,14 @@ BEGIN_C_DECLS /** * The item in the tree itself */ -struct mca_mpool_base_tree_item_t -{ - opal_free_list_item_t super; /**< the parent class */ - void* key; /**< the address this was alloc'd on */ - size_t num_bytes; /**< the number of bytes in this alloc, only for - debugging reporting with - mpi_show_mpi_alloc_mem_leaks */ +struct mca_mpool_base_tree_item_t { + opal_free_list_item_t super; /**< the parent class */ + void *key; /**< the address this was alloc'd on */ + size_t num_bytes; /**< the number of bytes in this alloc, only for + debugging reporting with + mpi_show_mpi_alloc_mem_leaks */ mca_mpool_base_module_t *mpool; - mca_rcache_base_module_t *rcaches[MCA_MPOOL_BASE_TREE_MAX]; /**< the registration caches */ + mca_rcache_base_module_t *rcaches[MCA_MPOOL_BASE_TREE_MAX]; /**< the registration caches */ mca_rcache_base_registration_t *regs[MCA_MPOOL_BASE_TREE_MAX]; /**< the registrations */ uint8_t count; /**< length of the mpools/regs array */ }; @@ -65,28 +64,27 @@ int mca_mpool_base_tree_fini(void); /* * insert an item in the rb tree */ -int mca_mpool_base_tree_insert(mca_mpool_base_tree_item_t* item); +int mca_mpool_base_tree_insert(mca_mpool_base_tree_item_t *item); /* * remove an item from the rb tree */ -int mca_mpool_base_tree_delete(mca_mpool_base_tree_item_t* item); - +int mca_mpool_base_tree_delete(mca_mpool_base_tree_item_t *item); /** * find the item in the rb tree */ -mca_mpool_base_tree_item_t* mca_mpool_base_tree_find(void* base); +mca_mpool_base_tree_item_t *mca_mpool_base_tree_find(void *base); /* * get a tree item from the free list */ -mca_mpool_base_tree_item_t* mca_mpool_base_tree_item_get(void); +mca_mpool_base_tree_item_t *mca_mpool_base_tree_item_get(void); /* * put tree item back into the free list */ -void mca_mpool_base_tree_item_put(mca_mpool_base_tree_item_t* item); +void mca_mpool_base_tree_item_put(mca_mpool_base_tree_item_t *item); /* * For debugging, print a show_help kind of message if there are items diff --git a/opal/mca/mpool/hugepage/mpool_hugepage.h b/opal/mca/mpool/hugepage/mpool_hugepage.h index 75da4a28c73..e78bac03591 100644 --- a/opal/mca/mpool/hugepage/mpool_hugepage.h +++ b/opal/mca/mpool/hugepage/mpool_hugepage.h @@ -29,13 +29,13 @@ #define MCA_MPOOL_HUGEPAGE_H #include "opal_config.h" -#include "opal/class/opal_list.h" #include "opal/class/opal_free_list.h" +#include "opal/class/opal_list.h" #include "opal/class/opal_rb_tree.h" -#include "opal/util/event.h" +#include "opal/mca/allocator/allocator.h" #include "opal/mca/mpool/mpool.h" +#include "opal/util/event.h" #include "opal/util/proc.h" -#include "opal/mca/allocator/allocator.h" #include "opal/util/sys_limits.h" BEGIN_C_DECLS @@ -60,13 +60,13 @@ struct mca_mpool_hugepage_hugepage_t { /** opal list item superclass */ opal_list_item_t super; /** page size in bytes */ - unsigned long page_size; + unsigned long page_size; /** path for mmapped files */ - char *path; + char *path; /** counter to help ensure unique file names for mmaped files */ opal_atomic_int32_t count; /** some platforms allow allocation of hugepages through mmap flags */ - int mmap_flags; + int mmap_flags; }; typedef struct mca_mpool_hugepage_hugepage_t mca_mpool_hugepage_hugepage_t; @@ -83,11 +83,11 @@ struct mca_mpool_hugepage_module_t { /* * Initializes the mpool module. */ -int mca_mpool_hugepage_module_init (mca_mpool_hugepage_module_t *mpool, - mca_mpool_hugepage_hugepage_t *huge_page); +int mca_mpool_hugepage_module_init(mca_mpool_hugepage_module_t *mpool, + mca_mpool_hugepage_hugepage_t *huge_page); -void *mca_mpool_hugepage_seg_alloc (void *ctx, size_t *sizep); -void mca_mpool_hugepage_seg_free (void *ctx, void *addr); +void *mca_mpool_hugepage_seg_alloc(void *ctx, size_t *sizep); +void mca_mpool_hugepage_seg_free(void *ctx, void *addr); END_C_DECLS #endif diff --git a/opal/mca/mpool/hugepage/mpool_hugepage_component.c b/opal/mca/mpool/hugepage/mpool_hugepage_component.c index f2af73345c4..d2c7dcb4a59 100644 --- a/opal/mca/mpool/hugepage/mpool_hugepage_component.c +++ b/opal/mca/mpool/hugepage/mpool_hugepage_component.c @@ -27,36 +27,36 @@ #define OPAL_DISABLE_ENABLE_MEM_DEBUG 1 #include "opal_config.h" +#include "opal/mca/allocator/base/base.h" #include "opal/mca/base/base.h" -#include "opal/runtime/opal_params.h" #include "opal/mca/base/mca_base_pvar.h" #include "opal/mca/mpool/base/base.h" -#include "opal/mca/allocator/base/base.h" +#include "opal/runtime/opal_params.h" #include "opal/util/argv.h" #include "mpool_hugepage.h" #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_MALLOC_H -#include +# include #endif #ifdef HAVE_SYS_VFS_H -#include +# include #endif #ifdef HAVE_SYS_MOUNT_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #ifdef HAVE_SYS_MMAN_H -#include +# include #endif #ifdef HAVE_MNTENT_H -#include +# include #endif #include @@ -66,21 +66,20 @@ * no struct statfs (!). So check to make sure we have struct statfs * before allowing the use of statfs(). */ -#if defined(HAVE_STATFS) && (defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || \ - defined(HAVE_STRUCT_STATFS_F_TYPE)) -#define USE_STATFS 1 +#if defined(HAVE_STATFS) \ + && (defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATFS_F_TYPE)) +# define USE_STATFS 1 #endif - /* * Local functions */ -static int mca_mpool_hugepage_open (void); -static int mca_mpool_hugepage_close (void); -static int mca_mpool_hugepage_register (void); -static int mca_mpool_hugepage_query (const char *hints, int *priority, - mca_mpool_base_module_t **module); -static void mca_mpool_hugepage_find_hugepages (void); +static int mca_mpool_hugepage_open(void); +static int mca_mpool_hugepage_close(void); +static int mca_mpool_hugepage_register(void); +static int mca_mpool_hugepage_query(const char *hints, int *priority, + mca_mpool_base_module_t **module); +static void mca_mpool_hugepage_find_hugepages(void); static int mca_mpool_hugepage_priority; static unsigned long mca_mpool_hugepage_page_size; @@ -90,80 +89,88 @@ mca_mpool_hugepage_component_t mca_mpool_hugepage_component = { /* First, the mca_base_component_t struct containing meta information about the component itself */ - .mpool_version ={ - MCA_MPOOL_BASE_VERSION_3_1_0, - - .mca_component_name = "hugepage", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - .mca_open_component = mca_mpool_hugepage_open, - .mca_close_component = mca_mpool_hugepage_close, - .mca_register_component_params = mca_mpool_hugepage_register, - }, - .mpool_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .mpool_version = + { + MCA_MPOOL_BASE_VERSION_3_1_0, + + .mca_component_name = "hugepage", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + .mca_open_component = mca_mpool_hugepage_open, + .mca_close_component = mca_mpool_hugepage_close, + .mca_register_component_params = mca_mpool_hugepage_register, + }, + .mpool_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, .mpool_query = mca_mpool_hugepage_query, }, }; /** - * component open/close/init function - */ + * component open/close/init function + */ static int mca_mpool_hugepage_register(void) { mca_mpool_hugepage_priority = 50; - (void) mca_base_component_var_register (&mca_mpool_hugepage_component.super.mpool_version, - "priority", "Default priority of the hugepage mpool component " - "(default: 50)", MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, - &mca_mpool_hugepage_priority); + (void) mca_base_component_var_register(&mca_mpool_hugepage_component.super.mpool_version, + "priority", + "Default priority of the hugepage mpool component " + "(default: 50)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_mpool_hugepage_priority); mca_mpool_hugepage_page_size = 1 << 21; - (void) mca_base_component_var_register (&mca_mpool_hugepage_component.super.mpool_version, - "page_size", "Default huge page size of the hugepage mpool component " - "(default: 2M)", MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, - &mca_mpool_hugepage_page_size); + (void) mca_base_component_var_register(&mca_mpool_hugepage_component.super.mpool_version, + "page_size", + "Default huge page size of the hugepage mpool component " + "(default: 2M)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_mpool_hugepage_page_size); mca_mpool_hugepage_component.bytes_allocated = 0; - (void) mca_base_component_pvar_register (&mca_mpool_hugepage_component.super.mpool_version, - "bytes_allocated", "Number of bytes currently allocated in the mpool " - "hugepage component", OPAL_INFO_LVL_3, MCA_BASE_PVAR_CLASS_SIZE, - MCA_BASE_VAR_TYPE_UNSIGNED_LONG, NULL, MCA_BASE_VAR_BIND_NO_OBJECT, - MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS, - NULL, NULL, NULL, (void *) &mca_mpool_hugepage_component.bytes_allocated); + (void) mca_base_component_pvar_register(&mca_mpool_hugepage_component.super.mpool_version, + "bytes_allocated", + "Number of bytes currently allocated in the mpool " + "hugepage component", + OPAL_INFO_LVL_3, MCA_BASE_PVAR_CLASS_SIZE, + MCA_BASE_VAR_TYPE_UNSIGNED_LONG, NULL, + MCA_BASE_VAR_BIND_NO_OBJECT, + MCA_BASE_PVAR_FLAG_READONLY + | MCA_BASE_PVAR_FLAG_CONTINUOUS, + NULL, NULL, NULL, + (void *) &mca_mpool_hugepage_component.bytes_allocated); return OPAL_SUCCESS; } -static int mca_mpool_hugepage_open (void) +static int mca_mpool_hugepage_open(void) { mca_mpool_hugepage_module_t *hugepage_module; mca_mpool_hugepage_hugepage_t *hp; int module_index, rc; OBJ_CONSTRUCT(&mca_mpool_hugepage_component.huge_pages, opal_list_t); - mca_mpool_hugepage_find_hugepages (); + mca_mpool_hugepage_find_hugepages(); - if (0 == opal_list_get_size (&mca_mpool_hugepage_component.huge_pages)) { + if (0 == opal_list_get_size(&mca_mpool_hugepage_component.huge_pages)) { return OPAL_SUCCESS; } mca_mpool_hugepage_component.modules = (mca_mpool_hugepage_module_t *) - calloc (opal_list_get_size (&mca_mpool_hugepage_component.huge_pages), - sizeof (mca_mpool_hugepage_module_t)); + calloc(opal_list_get_size(&mca_mpool_hugepage_component.huge_pages), + sizeof(mca_mpool_hugepage_module_t)); if (NULL == mca_mpool_hugepage_component.modules) { return OPAL_ERR_OUT_OF_RESOURCE; } module_index = 0; - OPAL_LIST_FOREACH(hp, &mca_mpool_hugepage_component.huge_pages, mca_mpool_hugepage_hugepage_t) { + OPAL_LIST_FOREACH (hp, &mca_mpool_hugepage_component.huge_pages, + mca_mpool_hugepage_hugepage_t) { hugepage_module = mca_mpool_hugepage_component.modules + module_index; - rc = mca_mpool_hugepage_module_init (hugepage_module, hp); + rc = mca_mpool_hugepage_module_init(hugepage_module, hp); if (OPAL_SUCCESS != rc) { continue; } @@ -175,23 +182,24 @@ static int mca_mpool_hugepage_open (void) return OPAL_SUCCESS; } -static int mca_mpool_hugepage_close (void) +static int mca_mpool_hugepage_close(void) { OPAL_LIST_DESTRUCT(&mca_mpool_hugepage_component.huge_pages); - for (int i = 0 ; i < mca_mpool_hugepage_component.module_count ; ++i) { - mca_mpool_hugepage_module_t *module = mca_mpool_hugepage_component.modules + i; - module->super.mpool_finalize (&module->super); + for (int i = 0; i < mca_mpool_hugepage_component.module_count; ++i) { + mca_mpool_hugepage_module_t *module = mca_mpool_hugepage_component.modules + i; + module->super.mpool_finalize(&module->super); } - free (mca_mpool_hugepage_component.modules); + free(mca_mpool_hugepage_component.modules); mca_mpool_hugepage_component.modules = NULL; return OPAL_SUCCESS; } #ifdef HAVE_MNTENT_H -static int page_compare (opal_list_item_t **a, opal_list_item_t **b) { +static int page_compare(opal_list_item_t **a, opal_list_item_t **b) +{ mca_mpool_hugepage_hugepage_t *pagea = (mca_mpool_hugepage_hugepage_t *) *a; mca_mpool_hugepage_hugepage_t *pageb = (mca_mpool_hugepage_hugepage_t *) *b; if (pagea->page_size > pageb->page_size) { @@ -204,14 +212,15 @@ static int page_compare (opal_list_item_t **a, opal_list_item_t **b) { } #endif -static void mca_mpool_hugepage_find_hugepages (void) { +static void mca_mpool_hugepage_find_hugepages(void) +{ #ifdef HAVE_MNTENT_H mca_mpool_hugepage_hugepage_t *hp; FILE *fh; struct mntent *mntent; char *opts, *tok, *ctx; - fh = setmntent ("/proc/mounts", "r"); + fh = setmntent("/proc/mounts", "r"); if (NULL == fh) { return; } @@ -228,27 +237,27 @@ static void mca_mpool_hugepage_find_hugepages (void) { break; } - tok = strtok_r (opts, ",", &ctx); + tok = strtok_r(opts, ",", &ctx); do { - if (0 == strncmp (tok, "pagesize", 8)) { + if (0 == strncmp(tok, "pagesize", 8)) { break; } - tok = strtok_r (NULL, ",", &ctx); + tok = strtok_r(NULL, ",", &ctx); } while (tok); if (!tok) { -#if defined(USE_STATFS) +# if defined(USE_STATFS) struct statfs info; - statfs (mntent->mnt_dir, &info); -#elif defined(HAVE_STATVFS) + statfs(mntent->mnt_dir, &info); +# elif defined(HAVE_STATVFS) struct statvfs info; - statvfs (mntent->mnt_dir, &info); -#endif + statvfs(mntent->mnt_dir, &info); +# endif page_size = info.f_bsize; } else { - (void) sscanf (tok, "pagesize=%lu", &page_size); + (void) sscanf(tok, "pagesize=%lu", &page_size); } free(opts); @@ -262,30 +271,33 @@ static void mca_mpool_hugepage_find_hugepages (void) { break; } - hp->path = strdup (mntent->mnt_dir); + hp->path = strdup(mntent->mnt_dir); hp->page_size = page_size; - - if(0 == access (hp->path, R_OK | W_OK)){ - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, - "found huge page with size = %lu, path = %s, mmap flags = 0x%x, adding to list", - hp->page_size, hp->path, hp->mmap_flags); - opal_list_append (&mca_mpool_hugepage_component.huge_pages, &hp->super); + + if (0 == access(hp->path, R_OK | W_OK)) { + opal_output_verbose( + MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, + "found huge page with size = %lu, path = %s, mmap flags = 0x%x, adding to list", + hp->page_size, hp->path, hp->mmap_flags); + opal_list_append(&mca_mpool_hugepage_component.huge_pages, &hp->super); } else { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, - "found huge page with size = %lu, path = %s, mmap flags = 0x%x, with invalid " - "permissions, skipping", hp->page_size, hp->path, hp->mmap_flags); + opal_output_verbose( + MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, + "found huge page with size = %lu, path = %s, mmap flags = 0x%x, with invalid " + "permissions, skipping", + hp->page_size, hp->path, hp->mmap_flags); OBJ_RELEASE(hp); - } + } } - opal_list_sort (&mca_mpool_hugepage_component.huge_pages, page_compare); + opal_list_sort(&mca_mpool_hugepage_component.huge_pages, page_compare); - endmntent (fh); + endmntent(fh); #endif } -static int mca_mpool_hugepage_query (const char *hints, int *priority_out, - mca_mpool_base_module_t **module) +static int mca_mpool_hugepage_query(const char *hints, int *priority_out, + mca_mpool_base_module_t **module) { unsigned long page_size = 0; char **hints_array; @@ -298,38 +310,40 @@ static int mca_mpool_hugepage_query (const char *hints, int *priority_out, } if (hints) { - hints_array = opal_argv_split (hints, ','); + hints_array = opal_argv_split(hints, ','); if (NULL == hints_array) { return OPAL_ERR_OUT_OF_RESOURCE; } - for (int i = 0 ; hints_array[i] ; ++i) { + for (int i = 0; hints_array[i]; ++i) { char *key = hints_array[i]; char *value = NULL; - if (NULL != (tmp = strchr (key, '='))) { + if (NULL != (tmp = strchr(key, '='))) { value = tmp + 1; *tmp = '\0'; } - if (0 == strcasecmp ("mpool", key)) { - if (value && 0 == strcasecmp ("hugepage", value)) { + if (0 == strcasecmp("mpool", key)) { + if (value && 0 == strcasecmp("hugepage", value)) { /* this mpool was requested by name */ my_priority = 100; - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, - "hugepage mpool matches hint: %s=%s", key, value); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_mpool_base_framework.framework_output, + "hugepage mpool matches hint: %s=%s", key, value); } else { /* different mpool requested */ my_priority = 0; - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, - "hugepage mpool does not match hint: %s=%s", key, value); - opal_argv_free (hints_array); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_mpool_base_framework.framework_output, + "hugepage mpool does not match hint: %s=%s", key, value); + opal_argv_free(hints_array); return OPAL_ERR_NOT_FOUND; } } - if (0 == strcasecmp ("page_size", key) && value) { - page_size = strtoul (value, &tmp, 0); + if (0 == strcasecmp("page_size", key) && value) { + page_size = strtoul(value, &tmp, 0); if (*tmp) { switch (*tmp) { case 'g': @@ -348,12 +362,13 @@ static int mca_mpool_hugepage_query (const char *hints, int *priority_out, page_size = -1; } } - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, - "hugepage mpool requested page size: %lu", page_size); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_mpool_base_framework.framework_output, + "hugepage mpool requested page size: %lu", page_size); } } - opal_argv_free (hints_array); + opal_argv_free(hints_array); } if (0 == page_size) { @@ -363,11 +378,11 @@ static int mca_mpool_hugepage_query (const char *hints, int *priority_out, /* take a priority hit if this mpool was not asked for by name */ my_priority = 0; } - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "hugepage mpool did not match any hints: %s", hints); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, + "hugepage mpool did not match any hints: %s", hints); } - for (int i = 0 ; i < mca_mpool_hugepage_component.module_count ; ++i) { + for (int i = 0; i < mca_mpool_hugepage_component.module_count; ++i) { mca_mpool_hugepage_module_t *hugepage_module = mca_mpool_hugepage_component.modules + i; if (hugepage_module->huge_page->page_size != page_size) { @@ -380,17 +395,18 @@ static int mca_mpool_hugepage_query (const char *hints, int *priority_out, *module = &hugepage_module->super; } - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, - "matches page size hint. page size: %lu, path: %s, mmap flags: " - "0x%x", page_size, hugepage_module->huge_page->path, - hugepage_module->huge_page->mmap_flags); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output, + "matches page size hint. page size: %lu, path: %s, mmap flags: " + "0x%x", + page_size, hugepage_module->huge_page->path, + hugepage_module->huge_page->mmap_flags); found = true; break; } if (!found) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "could not find page matching page request: %lu", page_size); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, + "could not find page matching page request: %lu", page_size); return OPAL_ERR_NOT_FOUND; } diff --git a/opal/mca/mpool/hugepage/mpool_hugepage_module.c b/opal/mca/mpool/hugepage/mpool_hugepage_module.c index d2010e8a6e8..874e8996fd1 100644 --- a/opal/mca/mpool/hugepage/mpool_hugepage_module.c +++ b/opal/mca/mpool/hugepage/mpool_hugepage_module.c @@ -29,44 +29,43 @@ #define OPAL_DISABLE_ENABLE_MEM_DEBUG 1 #include "opal_config.h" -#include "opal/align.h" #include "mpool_hugepage.h" +#include "opal/align.h" #include #include #ifdef HAVE_MALLOC_H -#include +# include #endif -#include "opal/mca/mpool/base/base.h" -#include "opal/runtime/opal_params.h" #include "opal/include/opal_stdint.h" #include "opal/mca/allocator/base/base.h" +#include "opal/mca/mpool/base/base.h" +#include "opal/runtime/opal_params.h" #include "opal/util/printf.h" #include #include +static void *mca_mpool_hugepage_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags); +static void *mca_mpool_hugepage_realloc(mca_mpool_base_module_t *mpool, void *addr, size_t size); +static void mca_mpool_hugepage_free(mca_mpool_base_module_t *mpool, void *addr); +static void mca_mpool_hugepage_finalize(mca_mpool_base_module_t *mpool); -static void *mca_mpool_hugepage_alloc (mca_mpool_base_module_t *mpool, size_t size, size_t align, - uint32_t flags); -static void *mca_mpool_hugepage_realloc (mca_mpool_base_module_t *mpool, void *addr, size_t size); -static void mca_mpool_hugepage_free (mca_mpool_base_module_t *mpool, void *addr); -static void mca_mpool_hugepage_finalize (mca_mpool_base_module_t *mpool); - -static void mca_mpool_hugepage_hugepage_constructor (mca_mpool_hugepage_hugepage_t *huge_page) +static void mca_mpool_hugepage_hugepage_constructor(mca_mpool_hugepage_hugepage_t *huge_page) { - memset ((char *)huge_page + sizeof(huge_page->super), 0, sizeof (*huge_page) - sizeof (huge_page->super)); + memset((char *) huge_page + sizeof(huge_page->super), 0, + sizeof(*huge_page) - sizeof(huge_page->super)); } -static void mca_mpool_hugepage_hugepage_destructor (mca_mpool_hugepage_hugepage_t *huge_page) +static void mca_mpool_hugepage_hugepage_destructor(mca_mpool_hugepage_hugepage_t *huge_page) { - free (huge_page->path); + free(huge_page->path); } OBJ_CLASS_INSTANCE(mca_mpool_hugepage_hugepage_t, opal_list_item_t, - mca_mpool_hugepage_hugepage_constructor, - mca_mpool_hugepage_hugepage_destructor); + mca_mpool_hugepage_hugepage_constructor, mca_mpool_hugepage_hugepage_destructor); -static int mca_mpool_rb_hugepage_compare (void *key1, void *key2) +static int mca_mpool_rb_hugepage_compare(void *key1, void *key2) { if (key1 == key2) { return 0; @@ -79,7 +78,7 @@ static int mca_mpool_rb_hugepage_compare (void *key1, void *key2) * Initializes the mpool module. */ int mca_mpool_hugepage_module_init(mca_mpool_hugepage_module_t *mpool, - mca_mpool_hugepage_hugepage_t *huge_page) + mca_mpool_hugepage_hugepage_t *huge_page) { mca_allocator_base_component_t *allocator_component; int rc; @@ -97,16 +96,16 @@ int mca_mpool_hugepage_module_init(mca_mpool_hugepage_module_t *mpool, mpool->huge_page = huge_page; /* use an allocator component to reduce waste when making small allocations */ - allocator_component = mca_allocator_component_lookup ("bucket"); + allocator_component = mca_allocator_component_lookup("bucket"); if (NULL == allocator_component) { return OPAL_ERR_NOT_AVAILABLE; } - mpool->allocator = allocator_component->allocator_init (true, mca_mpool_hugepage_seg_alloc, - mca_mpool_hugepage_seg_free, mpool); + mpool->allocator = allocator_component->allocator_init(true, mca_mpool_hugepage_seg_alloc, + mca_mpool_hugepage_seg_free, mpool); OBJ_CONSTRUCT(&mpool->allocation_tree, opal_rb_tree_t); - rc = opal_rb_tree_init (&mpool->allocation_tree, mca_mpool_rb_hugepage_compare); + rc = opal_rb_tree_init(&mpool->allocation_tree, mca_mpool_rb_hugepage_compare); if (OPAL_SUCCESS != rc) { OBJ_DESTRUCT(&mpool->allocation_tree); return OPAL_ERR_NOT_AVAILABLE; @@ -115,7 +114,7 @@ int mca_mpool_hugepage_module_init(mca_mpool_hugepage_module_t *mpool, return OPAL_SUCCESS; } -void *mca_mpool_hugepage_seg_alloc (void *ctx, size_t *sizep) +void *mca_mpool_hugepage_seg_alloc(void *ctx, size_t *sizep) { mca_mpool_hugepage_module_t *hugepage_module = (mca_mpool_hugepage_module_t *) ctx; mca_mpool_hugepage_hugepage_t *huge_page = hugepage_module->huge_page; @@ -131,24 +130,23 @@ void *mca_mpool_hugepage_seg_alloc (void *ctx, size_t *sizep) if (huge_page->path) { int32_t count; - count = opal_atomic_add_fetch_32 (&huge_page->count, 1); + count = opal_atomic_add_fetch_32(&huge_page->count, 1); - rc = opal_asprintf (&path, "%s/hugepage.openmpi.%d.%d", huge_page->path, - getpid (), count); + rc = opal_asprintf(&path, "%s/hugepage.openmpi.%d.%d", huge_page->path, getpid(), count); if (0 > rc) { return NULL; } - fd = open (path, O_RDWR | O_CREAT, 0600); + fd = open(path, O_RDWR | O_CREAT, 0600); if (-1 == fd) { - free (path); + free(path); return NULL; } - if (0 != ftruncate (fd, size)) { - close (fd); - unlink (path); - free (path); + if (0 != ftruncate(fd, size)) { + close(fd); + unlink(path); + free(path); return NULL; } } else { @@ -160,31 +158,31 @@ void *mca_mpool_hugepage_seg_alloc (void *ctx, size_t *sizep) #endif } - base = mmap (NULL, size, PROT_READ | PROT_WRITE, flags | huge_page->mmap_flags, fd, 0); + base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags | huge_page->mmap_flags, fd, 0); if (path) { - unlink (path); - free (path); + unlink(path); + free(path); } if (fd >= 0) { - close (fd); + close(fd); } if (MAP_FAILED == base) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_verbose, - "could not allocate huge page(s). falling back on standard pages"); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_verbose, + "could not allocate huge page(s). falling back on standard pages"); /* fall back on regular pages */ - base = mmap (NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); + base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); } if (MAP_FAILED == base) { return NULL; } - opal_mutex_lock (&hugepage_module->lock); - opal_rb_tree_insert (&hugepage_module->allocation_tree, base, (void *) (intptr_t) size); - (void) opal_atomic_fetch_add_size_t (&mca_mpool_hugepage_component.bytes_allocated, size); - opal_mutex_unlock (&hugepage_module->lock); + opal_mutex_lock(&hugepage_module->lock); + opal_rb_tree_insert(&hugepage_module->allocation_tree, base, (void *) (intptr_t) size); + (void) opal_atomic_fetch_add_size_t(&mca_mpool_hugepage_component.bytes_allocated, size); + opal_mutex_unlock(&hugepage_module->lock); OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_mpool_base_framework.framework_verbose, "allocated segment %p of size %lu bytes", base, size)); @@ -194,56 +192,56 @@ void *mca_mpool_hugepage_seg_alloc (void *ctx, size_t *sizep) return base; } -void mca_mpool_hugepage_seg_free (void *ctx, void *addr) +void mca_mpool_hugepage_seg_free(void *ctx, void *addr) { mca_mpool_hugepage_module_t *hugepage_module = (mca_mpool_hugepage_module_t *) ctx; size_t size; - opal_mutex_lock (&hugepage_module->lock); + opal_mutex_lock(&hugepage_module->lock); - size = (size_t) (intptr_t) opal_rb_tree_find (&hugepage_module->allocation_tree, addr); + size = (size_t)(intptr_t) opal_rb_tree_find(&hugepage_module->allocation_tree, addr); if (size > 0) { - opal_rb_tree_delete (&hugepage_module->allocation_tree, addr); + opal_rb_tree_delete(&hugepage_module->allocation_tree, addr); OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_mpool_base_framework.framework_verbose, "freeing segment %p of size %lu bytes", addr, size)); - munmap (addr, size); - (void) opal_atomic_fetch_add_size_t (&mca_mpool_hugepage_component.bytes_allocated, -size); + munmap(addr, size); + (void) opal_atomic_fetch_add_size_t(&mca_mpool_hugepage_component.bytes_allocated, -size); } - opal_mutex_unlock (&hugepage_module->lock); + opal_mutex_unlock(&hugepage_module->lock); } /** - * allocate function - */ -static void *mca_mpool_hugepage_alloc (mca_mpool_base_module_t *mpool, size_t size, - size_t align, uint32_t flags) + * allocate function + */ +static void *mca_mpool_hugepage_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags) { mca_mpool_hugepage_module_t *hugepage_module = (mca_mpool_hugepage_module_t *) mpool; - return hugepage_module->allocator->alc_alloc (hugepage_module->allocator, size, align); + return hugepage_module->allocator->alc_alloc(hugepage_module->allocator, size, align); } /** - * allocate function - */ -static void *mca_mpool_hugepage_realloc (mca_mpool_base_module_t *mpool, void *addr, size_t size) + * allocate function + */ +static void *mca_mpool_hugepage_realloc(mca_mpool_base_module_t *mpool, void *addr, size_t size) { mca_mpool_hugepage_module_t *hugepage_module = (mca_mpool_hugepage_module_t *) mpool; - return hugepage_module->allocator->alc_realloc (hugepage_module->allocator, addr, size); + return hugepage_module->allocator->alc_realloc(hugepage_module->allocator, addr, size); } /** - * free function - */ -static void mca_mpool_hugepage_free (mca_mpool_base_module_t *mpool, void *addr) + * free function + */ +static void mca_mpool_hugepage_free(mca_mpool_base_module_t *mpool, void *addr) { mca_mpool_hugepage_module_t *hugepage_module = (mca_mpool_hugepage_module_t *) mpool; - hugepage_module->allocator->alc_free (hugepage_module->allocator, addr); + hugepage_module->allocator->alc_free(hugepage_module->allocator, addr); } -static void mca_mpool_hugepage_finalize (struct mca_mpool_base_module_t *mpool) +static void mca_mpool_hugepage_finalize(struct mca_mpool_base_module_t *mpool) { mca_mpool_hugepage_module_t *hugepage_module = (mca_mpool_hugepage_module_t *) mpool; @@ -251,7 +249,7 @@ static void mca_mpool_hugepage_finalize (struct mca_mpool_base_module_t *mpool) OBJ_DESTRUCT(&hugepage_module->allocation_tree); if (hugepage_module->allocator) { - (void) hugepage_module->allocator->alc_finalize (hugepage_module->allocator); + (void) hugepage_module->allocator->alc_finalize(hugepage_module->allocator); hugepage_module->allocator = NULL; } } diff --git a/opal/mca/mpool/memkind/mpool_memkind.h b/opal/mca/mpool/memkind/mpool_memkind.h index 75ca0384511..0a5d4372630 100644 --- a/opal/mca/mpool/memkind/mpool_memkind.h +++ b/opal/mca/mpool/memkind/mpool_memkind.h @@ -30,8 +30,8 @@ #include "opal_config.h" -#include "opal/util/event.h" #include "opal/mca/mpool/mpool.h" +#include "opal/util/event.h" #include "opal/mca/allocator/allocator.h" #include @@ -40,13 +40,12 @@ BEGIN_C_DECLS static const int mca_mpool_memkind_default_pagesize = 4096; - struct mca_mpool_memkind_module_t { mca_mpool_base_module_t super; memkind_t kind; memkind_memtype_t type; - memkind_policy_t policy; - memkind_bits_t memkind_bits; + memkind_policy_t policy; + memkind_bits_t memkind_bits; int page_size; }; @@ -62,15 +61,15 @@ OBJ_CLASS_DECLARATION(mca_mpool_memkind_module_le_t); struct mca_mpool_memkind_component_t { mca_mpool_base_component_t super; - int hbw; - int pagesize; - int bind; + int hbw; + int pagesize; + int bind; memkind_memtype_t default_type; - memkind_policy_t default_policy; - memkind_bits_t default_memkind_bits; - memkind_t default_kind; - int priority; - int output; + memkind_policy_t default_policy; + memkind_bits_t default_memkind_bits; + memkind_t default_kind; + int priority; + int output; opal_list_t module_list; }; @@ -83,30 +82,21 @@ OPAL_MODULE_DECLSPEC extern mca_mpool_memkind_component_t mca_mpool_memkind_comp void mca_mpool_memkind_module_init(mca_mpool_memkind_module_t *mpool); - /** - * Allocate block of high bandwidth memory. - */ -void* mca_mpool_memkind_alloc( - mca_mpool_base_module_t* mpool, - size_t size, - size_t align, - uint32_t flags); + * Allocate block of high bandwidth memory. + */ +void *mca_mpool_memkind_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags); /** - * realloc function typedef - */ -void* mca_mpool_memkind_realloc( - mca_mpool_base_module_t* mpool, - void* addr, - size_t size); + * realloc function typedef + */ +void *mca_mpool_memkind_realloc(mca_mpool_base_module_t *mpool, void *addr, size_t size); /** - * free function typedef - */ -void mca_mpool_memkind_free( - mca_mpool_base_module_t* mpool, - void * addr); + * free function typedef + */ +void mca_mpool_memkind_free(mca_mpool_base_module_t *mpool, void *addr); END_C_DECLS diff --git a/opal/mca/mpool/memkind/mpool_memkind_component.c b/opal/mca/mpool/memkind/mpool_memkind_component.c index 02d53eb39d9..55be1a657e5 100644 --- a/opal/mca/mpool/memkind/mpool_memkind_component.c +++ b/opal/mca/mpool/memkind/mpool_memkind_component.c @@ -26,57 +26,47 @@ #include "opal_config.h" #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H*/ +# include +#endif /* HAVE_UNISTD_H*/ #ifdef HAVE_STDLIB_H -#include -#endif /* HAVE_STDLIB_H */ -#include -#include -#include "opal/mca/base/base.h" +# include +#endif /* HAVE_STDLIB_H */ +#include "mpool_memkind.h" #include "opal/mca/allocator/base/base.h" +#include "opal/mca/base/base.h" #include "opal/mca/mpool/base/base.h" #include "opal/util/argv.h" -#include "mpool_memkind.h" - +#include +#include /* * Local functions */ -static int -mca_mpool_memkind_register(void); - -static int -mca_mpool_memkind_open(void); - -static int -mca_mpool_memkind_close(void); - -static int mca_mpool_memkind_query (const char *hints, int *priority, - mca_mpool_base_module_t **module); - -mca_mpool_memkind_component_t mca_mpool_memkind_component = { - { - /* First, the mca_base_component_t struct containing meta - information about the component itself */ - .mpool_version = { - MCA_MPOOL_BASE_VERSION_3_1_0, - "memkind", /* MCA component name */ - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - .mca_open_component = mca_mpool_memkind_open, - .mca_close_component = mca_mpool_memkind_close, - .mca_register_component_params = mca_mpool_memkind_register - }, - .mpool_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - - .mpool_query = mca_mpool_memkind_query, - } -}; +static int mca_mpool_memkind_register(void); + +static int mca_mpool_memkind_open(void); + +static int mca_mpool_memkind_close(void); + +static int mca_mpool_memkind_query(const char *hints, int *priority, + mca_mpool_base_module_t **module); + +mca_mpool_memkind_component_t mca_mpool_memkind_component = {{ + /* First, the mca_base_component_t struct containing meta + information about the component itself */ + .mpool_version = {MCA_MPOOL_BASE_VERSION_3_1_0, "memkind", /* MCA component name */ + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + .mca_open_component = mca_mpool_memkind_open, + .mca_close_component = mca_mpool_memkind_close, + .mca_register_component_params = mca_mpool_memkind_register}, + .mpool_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + .mpool_query = mca_mpool_memkind_query, +}}; static void mca_mpool_memkind_module_le_destroy(mca_mpool_memkind_module_le_t *elem) { @@ -85,30 +75,28 @@ static void mca_mpool_memkind_module_le_destroy(mca_mpool_memkind_module_le_t *e } } -OBJ_CLASS_INSTANCE(mca_mpool_memkind_module_le_t, - opal_list_item_t, - NULL, +OBJ_CLASS_INSTANCE(mca_mpool_memkind_module_le_t, opal_list_item_t, NULL, mca_mpool_memkind_module_le_destroy); static mca_base_var_enum_value_t memory_types[] = { - {.value = MEMKIND_MEMTYPE_DEFAULT, .string = "memkind_default"}, - {.value = MEMKIND_MEMTYPE_HIGH_BANDWIDTH, .string = "memkind_hbw"}, - {.string = NULL}, + {.value = MEMKIND_MEMTYPE_DEFAULT, .string = "memkind_default"}, + {.value = MEMKIND_MEMTYPE_HIGH_BANDWIDTH, .string = "memkind_hbw"}, + {.string = NULL}, }; static mca_base_var_enum_value_t memory_policy[] = { - {.value = MEMKIND_POLICY_BIND_LOCAL, .string = "mempolicy_bind_local"}, - {.value = MEMKIND_POLICY_BIND_ALL, .string = "mempolicy_bind_all"}, - {.value = MEMKIND_POLICY_PREFERRED_LOCAL, .string = "mempolicy_perferred_local"}, - {.value = MEMKIND_POLICY_INTERLEAVE_LOCAL, .string = "mempolicy_interleave_local"}, - {.value = MEMKIND_POLICY_INTERLEAVE_ALL, .string = "mempolicy_interleave_all"}, - {.string = NULL}, + {.value = MEMKIND_POLICY_BIND_LOCAL, .string = "mempolicy_bind_local"}, + {.value = MEMKIND_POLICY_BIND_ALL, .string = "mempolicy_bind_all"}, + {.value = MEMKIND_POLICY_PREFERRED_LOCAL, .string = "mempolicy_perferred_local"}, + {.value = MEMKIND_POLICY_INTERLEAVE_LOCAL, .string = "mempolicy_interleave_local"}, + {.value = MEMKIND_POLICY_INTERLEAVE_ALL, .string = "mempolicy_interleave_all"}, + {.string = NULL}, }; static mca_base_var_enum_value_t memory_kind_bits[] = { - {.value = 0, .string = "memkind_mask_page_size_4KB"}, - {.value = MEMKIND_MASK_PAGE_SIZE_2MB, .string = "memkind_mask_page_size_2MB"}, - {.string = NULL}, + {.value = 0, .string = "memkind_mask_page_size_4KB"}, + {.value = MEMKIND_MASK_PAGE_SIZE_2MB, .string = "memkind_mask_page_size_2MB"}, + {.string = NULL}, }; static mca_base_var_enum_t *mca_mpool_memkind_policy_enum = NULL; @@ -124,8 +112,8 @@ static int mca_mpool_memkind_register(void) mca_mpool_memkind_component.default_type = memory_types[0].value; - rc = mca_base_var_enum_create ("memkind memory types", memory_types, - &mca_mpool_memkind_type_enum); + rc = mca_base_var_enum_create("memkind memory types", memory_types, + &mca_mpool_memkind_type_enum); if (OPAL_SUCCESS != rc) { return rc; } @@ -137,41 +125,41 @@ static int mca_mpool_memkind_register(void) &mca_mpool_memkind_component.default_type); /* - * see memkind source to understand the 2 + * see memkind source to understand the 2 */ mca_mpool_memkind_component.default_policy = memory_policy[2].value; - rc = mca_base_var_enum_create ("memkind memory policy", memory_policy, - &mca_mpool_memkind_policy_enum); + rc = mca_base_var_enum_create("memkind memory policy", memory_policy, + &mca_mpool_memkind_policy_enum); if (OPAL_SUCCESS != rc) { return rc; } (void) mca_base_component_var_register(&mca_mpool_memkind_component.super.mpool_version, "default_policy", "Default memkind policy to use", - MCA_BASE_VAR_TYPE_INT, mca_mpool_memkind_policy_enum, 0, 0, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_TYPE_INT, mca_mpool_memkind_policy_enum, 0, + 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, &mca_mpool_memkind_component.default_policy); mca_mpool_memkind_component.default_memkind_bits = memory_kind_bits[0].value; - rc = mca_base_var_enum_create ("memkind memory bits", memory_kind_bits, - &mca_mpool_memkind_kind_bits_enum); + rc = mca_base_var_enum_create("memkind memory bits", memory_kind_bits, + &mca_mpool_memkind_kind_bits_enum); if (OPAL_SUCCESS != rc) { return rc; } (void) mca_base_component_var_register(&mca_mpool_memkind_component.super.mpool_version, "default_bits", "Default memkind bits to use", - MCA_BASE_VAR_TYPE_INT, mca_mpool_memkind_kind_bits_enum, 0, 0, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_TYPE_INT, mca_mpool_memkind_kind_bits_enum, + 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, &mca_mpool_memkind_component.default_memkind_bits); mca_mpool_memkind_component.priority = 10; (void) mca_base_component_var_register(&mca_mpool_memkind_component.super.mpool_version, "priority", "Default priority of the memkind component", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_LOCAL, + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_mpool_memkind_component.priority); opal_mpool_memkind_verbose = 0; @@ -185,9 +173,9 @@ static int mca_mpool_memkind_register(void) } /** - * component open/close/init function - */ -static int mca_mpool_memkind_open (void) + * component open/close/init function + */ +static int mca_mpool_memkind_open(void) { int rc; mca_mpool_memkind_module_le_t *item = NULL; @@ -205,15 +193,15 @@ static int mca_mpool_memkind_open (void) mca_mpool_memkind_component.default_memkind_bits, &mca_mpool_memkind_component.default_kind); if (MEMKIND_SUCCESS != rc) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "memkind_create_kind default returned %d", rc); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, + "memkind_create_kind default returned %d", rc); return OPAL_ERR_NOT_AVAILABLE; } item = OBJ_NEW(mca_mpool_memkind_module_le_t); - item->module.type = mca_mpool_memkind_component.default_type; - item->module.policy = mca_mpool_memkind_component.default_policy; + item->module.type = mca_mpool_memkind_component.default_type; + item->module.policy = mca_mpool_memkind_component.default_policy; item->module.memkind_bits = mca_mpool_memkind_component.default_memkind_bits; item->module.kind = mca_mpool_memkind_component.default_kind; /* @@ -225,16 +213,14 @@ static int mca_mpool_memkind_open (void) item->module.page_size = 4096; } - opal_list_append(&mca_mpool_memkind_component.module_list, - (opal_list_item_t *)item); - + opal_list_append(&mca_mpool_memkind_component.module_list, (opal_list_item_t *) item); return OPAL_SUCCESS; } static int mca_mpool_memkind_close(void) { - opal_output_close (mca_mpool_memkind_component.output); + opal_output_close(mca_mpool_memkind_component.output); mca_mpool_memkind_component.output = -1; OPAL_LIST_DESTRUCT(&mca_mpool_memkind_component.module_list); @@ -257,16 +243,16 @@ static int mca_mpool_memkind_close(void) return OPAL_SUCCESS; } -static int mca_mpool_memkind_query (const char *hints, int *priority_out, - mca_mpool_base_module_t **module) +static int mca_mpool_memkind_query(const char *hints, int *priority_out, + mca_mpool_base_module_t **module) { int my_priority = mca_mpool_memkind_component.priority; char **hint_array; char *tmp, *key, *value = NULL; int rc; memkind_memtype_t type = mca_mpool_memkind_component.default_type; - memkind_policy_t policy = mca_mpool_memkind_component.default_policy; - memkind_bits_t memkind_bits = mca_mpool_memkind_component.default_memkind_bits; + memkind_policy_t policy = mca_mpool_memkind_component.default_policy; + memkind_bits_t memkind_bits = mca_mpool_memkind_component.default_memkind_bits; mca_mpool_memkind_module_le_t *item = NULL; mca_mpool_base_module_t *found_module = NULL; memkind_t kind; @@ -278,7 +264,7 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, return OPAL_SUCCESS; } - hint_array = opal_argv_split (hints, ','); + hint_array = opal_argv_split(hints, ','); if (NULL == hint_array) { if (priority_out) { *priority_out = my_priority; @@ -286,10 +272,10 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, return OPAL_SUCCESS; } - for (int i = 0 ; hint_array[i] ; ++i) { + for (int i = 0; hint_array[i]; ++i) { key = hint_array[i]; - tmp = strchr (key, '='); + tmp = strchr(key, '='); if (tmp) { *tmp = '\0'; value = tmp + 1; @@ -298,10 +284,11 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, /* * TODO: may want to emit a warning */ - if (value == NULL) break; + if (value == NULL) + break; - if (0 == strcasecmp (key, "mpool")) { - if (0 == strcasecmp (value, "memkind")) { + if (0 == strcasecmp(key, "mpool")) { + if (0 == strcasecmp(value, "memkind")) { /* specifically selected */ my_priority = 100; @@ -311,31 +298,35 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, } return OPAL_SUCCESS; } - } else if (0 == strcasecmp (key, "policy")) { + } else if (0 == strcasecmp(key, "policy")) { - rc = mca_mpool_memkind_policy_enum->value_from_string (mca_mpool_memkind_policy_enum, - value, (int *)&policy); + rc = mca_mpool_memkind_policy_enum->value_from_string(mca_mpool_memkind_policy_enum, + value, (int *) &policy); if (OPAL_SUCCESS != rc) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "invalid memkind policy %s specified", value); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, + opal_mpool_base_framework.framework_output, + "invalid memkind policy %s specified", value); } - } else if (0 == strcasecmp (key, "type")) { + } else if (0 == strcasecmp(key, "type")) { - rc = mca_mpool_memkind_type_enum->value_from_string (mca_mpool_memkind_type_enum, - value, (int *)&type); + rc = mca_mpool_memkind_type_enum->value_from_string(mca_mpool_memkind_type_enum, value, + (int *) &type); if (OPAL_SUCCESS != rc) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "invalid memkind type %s specified", value); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, + opal_mpool_base_framework.framework_output, + "invalid memkind type %s specified", value); } - } else if (0 == strcasecmp (key, "kind_bits")) { + } else if (0 == strcasecmp(key, "kind_bits")) { - rc = mca_mpool_memkind_kind_bits_enum->value_from_string (mca_mpool_memkind_kind_bits_enum, - value, (int *)&memkind_bits); + rc = mca_mpool_memkind_kind_bits_enum + ->value_from_string(mca_mpool_memkind_kind_bits_enum, value, + (int *) &memkind_bits); if (OPAL_SUCCESS != rc) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "invalid memkind kind_bits %s specified", value); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, + opal_mpool_base_framework.framework_output, + "invalid memkind kind_bits %s specified", value); } } } @@ -344,18 +335,17 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, * now look for an existing module with matching policy, type, memkind bits */ - OPAL_LIST_FOREACH(item, &mca_mpool_memkind_component.module_list, - mca_mpool_memkind_module_le_t) { - if ((item->module.type == type) && - (item->module.policy == policy) && - (item->module.memkind_bits = memkind_bits)) { - found_module = &item->module.super; - break; + OPAL_LIST_FOREACH (item, &mca_mpool_memkind_component.module_list, + mca_mpool_memkind_module_le_t) { + if ((item->module.type == type) && (item->module.policy == policy) + && (item->module.memkind_bits = memkind_bits)) { + found_module = &item->module.super; + break; } - } + } /* - * didn't find a matching module, try to create one + * didn't find a matching module, try to create one */ if (NULL == found_module) { @@ -364,8 +354,8 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, item = OBJ_NEW(mca_mpool_memkind_module_le_t); - item->module.type = type; - item->module.policy = policy; + item->module.type = type; + item->module.policy = policy; item->module.memkind_bits = memkind_bits; item->module.kind = kind; @@ -377,13 +367,12 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, mca_mpool_memkind_module_init(&item->module); - opal_list_append(&mca_mpool_memkind_component.module_list, - (opal_list_item_t *)item); + opal_list_append(&mca_mpool_memkind_component.module_list, (opal_list_item_t *) item); found_module = &item->module.super; } else { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, - "memkind_create_kind returned %d", rc); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_output, + "memkind_create_kind returned %d", rc); if (priority_out) { *priority_out = 0; } @@ -395,7 +384,7 @@ static int mca_mpool_memkind_query (const char *hints, int *priority_out, *module = found_module; } - opal_argv_free (hint_array); + opal_argv_free(hint_array); if (priority_out) { *priority_out = my_priority; diff --git a/opal/mca/mpool/memkind/mpool_memkind_module.c b/opal/mca/mpool/memkind/mpool_memkind_module.c index d53f80a27d1..ecedaa77a4b 100644 --- a/opal/mca/mpool/memkind/mpool_memkind_module.c +++ b/opal/mca/mpool/memkind/mpool_memkind_module.c @@ -22,10 +22,10 @@ */ #include "opal_config.h" -#include #include "mpool_memkind.h" +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #include "opal/mca/mpool/base/base.h" @@ -42,11 +42,8 @@ void mca_mpool_memkind_module_init(mca_mpool_memkind_module_t *mpool) mpool->super.flags = MCA_MPOOL_FLAGS_MPI_ALLOC_MEM; } -void* mca_mpool_memkind_alloc( - mca_mpool_base_module_t* mpool, - size_t size, - size_t align, - uint32_t flags) +void *mca_mpool_memkind_alloc(mca_mpool_base_module_t *mpool, size_t size, size_t align, + uint32_t flags) { mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool; void *addr; @@ -55,18 +52,17 @@ void* mca_mpool_memkind_alloc( align = memkind_module->page_size; } - if ((errno = memkind_posix_memalign(memkind_module->kind, &addr, align, size))!= 0){ + if ((errno = memkind_posix_memalign(memkind_module->kind, &addr, align, size)) != 0) { return NULL; } return addr; } -void* mca_mpool_memkind_realloc(mca_mpool_base_module_t *mpool, void *addr, - size_t size) +void *mca_mpool_memkind_realloc(mca_mpool_base_module_t *mpool, void *addr, size_t size) { mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool; - return memkind_realloc (memkind_module->kind, addr, size); + return memkind_realloc(memkind_module->kind, addr, size); } void mca_mpool_memkind_free(mca_mpool_base_module_t *mpool, void *addr) diff --git a/opal/mca/mpool/mpool.h b/opal/mca/mpool/mpool.h index 3c9e6355398..d93bf649202 100644 --- a/opal/mca/mpool/mpool.h +++ b/opal/mca/mpool/mpool.h @@ -21,20 +21,20 @@ * $HEADER$ */ /** - * @file - * Description of the Memory Pool framework - */ + * @file + * Description of the Memory Pool framework + */ #ifndef MCA_MPOOL_H #define MCA_MPOOL_H #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/class/opal_free_list.h" +#include "opal/mca/mca.h" #include "opal/mca/rcache/base/rcache_base_vma.h" -#define MCA_MPOOL_ALLOC_FLAG_DEFAULT 0x00 -#define MCA_MPOOL_ALLOC_FLAG_USER 0x01 +#define MCA_MPOOL_ALLOC_FLAG_DEFAULT 0x00 +#define MCA_MPOOL_ALLOC_FLAG_USER 0x01 -#define MCA_MPOOL_FLAGS_MPI_ALLOC_MEM 0x80 +#define MCA_MPOOL_FLAGS_MPI_ALLOC_MEM 0x80 struct opal_info_t; struct mca_mpool_base_module_t; @@ -59,36 +59,34 @@ typedef struct mca_mpool_base_module_t mca_mpool_base_module_t; * Memory pools should try to support at a minimum name=value but can define * any additional keys. */ -typedef int (*mca_mpool_base_component_query_fn_t) (const char *hints, int *priority, - mca_mpool_base_module_t **module); +typedef int (*mca_mpool_base_component_query_fn_t)(const char *hints, int *priority, + mca_mpool_base_module_t **module); /** - * allocate function typedef - */ -typedef void *(*mca_mpool_base_module_alloc_fn_t) (mca_mpool_base_module_t *mpool, - size_t size, size_t align, - uint32_t flags); + * allocate function typedef + */ +typedef void *(*mca_mpool_base_module_alloc_fn_t)(mca_mpool_base_module_t *mpool, size_t size, + size_t align, uint32_t flags); /** - * allocate function typedef - */ -typedef void *(*mca_mpool_base_module_realloc_fn_t) (mca_mpool_base_module_t *mpool, - void *addr, size_t size); + * allocate function typedef + */ +typedef void *(*mca_mpool_base_module_realloc_fn_t)(mca_mpool_base_module_t *mpool, void *addr, + size_t size); /** - * free function typedef - */ -typedef void (*mca_mpool_base_module_free_fn_t) (mca_mpool_base_module_t *mpool, - void *addr); + * free function typedef + */ +typedef void (*mca_mpool_base_module_free_fn_t)(mca_mpool_base_module_t *mpool, void *addr); /** - * if appropriate - returns base address of memory pool - */ -typedef void* (*mca_mpool_base_module_address_fn_t) (mca_mpool_base_module_t *mpool); + * if appropriate - returns base address of memory pool + */ +typedef void *(*mca_mpool_base_module_address_fn_t)(mca_mpool_base_module_t *mpool); /** - * finalize - */ + * finalize + */ typedef void (*mca_mpool_base_module_finalize_fn_t)(mca_mpool_base_module_t *mpool); /** @@ -96,18 +94,18 @@ typedef void (*mca_mpool_base_module_finalize_fn_t)(mca_mpool_base_module_t *mpo * and open/close/init functions. */ struct mca_mpool_base_component_3_1_0_t { - mca_base_component_t mpool_version; /**< version */ - mca_base_component_data_t mpool_data;/**< metadata */ + mca_base_component_t mpool_version; /**< version */ + mca_base_component_data_t mpool_data; /**< metadata */ - mca_mpool_base_component_query_fn_t mpool_query; /**< query for matching pools */ + mca_mpool_base_component_query_fn_t mpool_query; /**< query for matching pools */ }; /** * Convenience typedef. */ typedef struct mca_mpool_base_component_3_1_0_t mca_mpool_base_component_3_1_0_t; /** - * Convenience typedef - */ + * Convenience typedef + */ typedef struct mca_mpool_base_component_3_1_0_t mca_mpool_base_component_t; /** @@ -116,20 +114,19 @@ typedef struct mca_mpool_base_component_3_1_0_t mca_mpool_base_component_t; * details. */ struct mca_mpool_base_module_t { - mca_mpool_base_component_t *mpool_component; /**< component stuct */ - mca_mpool_base_module_address_fn_t mpool_base; /**< returns the base address */ - mca_mpool_base_module_alloc_fn_t mpool_alloc; /**< allocate function */ - mca_mpool_base_module_realloc_fn_t mpool_realloc; /**< reallocate function */ - mca_mpool_base_module_free_fn_t mpool_free; /**< free function */ + mca_mpool_base_component_t *mpool_component; /**< component stuct */ + mca_mpool_base_module_address_fn_t mpool_base; /**< returns the base address */ + mca_mpool_base_module_alloc_fn_t mpool_alloc; /**< allocate function */ + mca_mpool_base_module_realloc_fn_t mpool_realloc; /**< reallocate function */ + mca_mpool_base_module_free_fn_t mpool_free; /**< free function */ - mca_mpool_base_module_finalize_fn_t mpool_finalize; /**< finalize */ - uint32_t flags; /**< mpool flags */ + mca_mpool_base_module_finalize_fn_t mpool_finalize; /**< finalize */ + uint32_t flags; /**< mpool flags */ - size_t mpool_allocation_unit; /**< allocation unit used by this mpool */ - char *mpool_name; /**< name of this pool module */ + size_t mpool_allocation_unit; /**< allocation unit used by this mpool */ + char *mpool_name; /**< name of this pool module */ }; - /** * Function to allocate special memory according to what the user requests in * the info object. @@ -150,7 +147,7 @@ struct mca_mpool_base_module_t { * @retval pointer to the allocated memory * @retval NULL on failure */ -OPAL_DECLSPEC void * mca_mpool_base_alloc(size_t size, struct opal_info_t * info, const char *hints); +OPAL_DECLSPEC void *mca_mpool_base_alloc(size_t size, struct opal_info_t *info, const char *hints); /** * Function to free memory previously allocated by mca_mpool_base_alloc @@ -160,7 +157,7 @@ OPAL_DECLSPEC void * mca_mpool_base_alloc(size_t size, struct opal_info_t * info * @retval OPAL_SUCCESS * @retval OPAL_ERR_BAD_PARAM if the passed base pointer was invalid */ -OPAL_DECLSPEC int mca_mpool_base_free(void * base); +OPAL_DECLSPEC int mca_mpool_base_free(void *base); /** * Function for the red black tree to compare 2 keys @@ -172,13 +169,11 @@ OPAL_DECLSPEC int mca_mpool_base_free(void * base); * @retval 1 if key 1 is above key2 * @retval 0 if the keys are the same */ -OPAL_DECLSPEC int mca_mpool_base_tree_node_compare(void * key1, void * key2); +OPAL_DECLSPEC int mca_mpool_base_tree_node_compare(void *key1, void *key2); /** * Macro for use in components that are of type mpool */ -#define MCA_MPOOL_BASE_VERSION_3_1_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("mpool", 3, 1, 0) +#define MCA_MPOOL_BASE_VERSION_3_1_0 OPAL_MCA_BASE_VERSION_2_1_0("mpool", 3, 1, 0) #endif /* MCA_MPOOL_H */ - diff --git a/opal/mca/patcher/base/base.h b/opal/mca/patcher/base/base.h index 0be3cf1dd7c..cbc32120e37 100644 --- a/opal/mca/patcher/base/base.h +++ b/opal/mca/patcher/base/base.h @@ -27,30 +27,29 @@ #include "opal/mca/base/mca_base_framework.h" #include "opal/mca/patcher/patcher.h" - BEGIN_C_DECLS #define MCA_BASE_PATCHER_MAX_PATCH 32 struct mca_patcher_base_patch_t; -typedef void (*mca_patcher_base_restore_fn_t) (struct mca_patcher_base_patch_t *); +typedef void (*mca_patcher_base_restore_fn_t)(struct mca_patcher_base_patch_t *); struct mca_patcher_base_patch_t { /** patches are list items */ opal_list_item_t super; /** name symbol to patch */ - char *patch_symbol; + char *patch_symbol; /** address of function to call instead */ - uintptr_t patch_value; + uintptr_t patch_value; /** original address of function */ - uintptr_t patch_orig; + uintptr_t patch_orig; /** patch data */ - unsigned char patch_data[MCA_BASE_PATCHER_MAX_PATCH]; + unsigned char patch_data[MCA_BASE_PATCHER_MAX_PATCH]; /** original data */ - unsigned char patch_orig_data[MCA_BASE_PATCHER_MAX_PATCH]; + unsigned char patch_orig_data[MCA_BASE_PATCHER_MAX_PATCH]; /** size of patch data */ - unsigned patch_data_size; + unsigned patch_data_size; /** function to undo the patch */ mca_patcher_base_restore_fn_t patch_restore; }; @@ -63,17 +62,18 @@ OBJ_CLASS_DECLARATION(mca_patcher_base_patch_t); * Framework struct declaration for this framework */ OPAL_DECLSPEC extern mca_base_framework_t opal_patcher_base_framework; -OPAL_DECLSPEC int opal_patcher_base_select (void); -OPAL_DECLSPEC int mca_patcher_base_patch_hook (mca_patcher_base_module_t *module, uintptr_t hook); -OPAL_DECLSPEC void mca_base_patcher_patch_apply_binary (mca_patcher_base_patch_t *patch); +OPAL_DECLSPEC int opal_patcher_base_select(void); +OPAL_DECLSPEC int mca_patcher_base_patch_hook(mca_patcher_base_module_t *module, uintptr_t hook); +OPAL_DECLSPEC void mca_base_patcher_patch_apply_binary(mca_patcher_base_patch_t *patch); -static inline uintptr_t mca_patcher_base_addr_text (uintptr_t addr) { -#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) && (!defined (_CALL_ELF) || (_CALL_ELF != 2)) +static inline uintptr_t mca_patcher_base_addr_text(uintptr_t addr) +{ +#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) && (!defined(_CALL_ELF) || (_CALL_ELF != 2)) struct odp_t { uintptr_t text; uintptr_t toc; } *odp = (struct odp_t *) addr; - return (odp)?odp->text:0; + return (odp) ? odp->text : 0; #else return addr; #endif diff --git a/opal/mca/patcher/base/patcher_base_frame.c b/opal/mca/patcher/base/patcher_base_frame.c index 8d685d3fa43..d44ffc78e42 100644 --- a/opal/mca/patcher/base/patcher_base_frame.c +++ b/opal/mca/patcher/base/patcher_base_frame.c @@ -11,9 +11,9 @@ #include "opal_config.h" -#include "opal/mca/patcher/patcher.h" #include "opal/mca/patcher/base/base.h" #include "opal/mca/patcher/base/static-components.h" +#include "opal/mca/patcher/patcher.h" /* * Local variables @@ -25,16 +25,16 @@ static mca_patcher_base_module_t empty_module; */ mca_patcher_base_module_t *opal_patcher = &empty_module; -int opal_patcher_base_select (void) +int opal_patcher_base_select(void) { mca_patcher_base_module_t *best_module; mca_patcher_base_component_t *best_component; int rc, priority; - rc = mca_base_select ("patcher", opal_patcher_base_framework.framework_output, - &opal_patcher_base_framework.framework_components, - (mca_base_module_t **) &best_module, (mca_base_component_t **) &best_component, - &priority); + rc = mca_base_select("patcher", opal_patcher_base_framework.framework_output, + &opal_patcher_base_framework.framework_components, + (mca_base_module_t **) &best_module, + (mca_base_component_t **) &best_component, &priority); if (OPAL_SUCCESS != rc) { return rc; } @@ -43,7 +43,7 @@ int opal_patcher_base_select (void) OBJ_CONSTRUCT(&best_module->patch_list_mutex, opal_mutex_t); if (best_module->patch_init) { - rc = best_module->patch_init (); + rc = best_module->patch_init(); if (OPAL_SUCCESS != rc) { return rc; } @@ -54,22 +54,22 @@ int opal_patcher_base_select (void) return OPAL_SUCCESS; } -static int opal_patcher_base_close (void) +static int opal_patcher_base_close(void) { if (opal_patcher == &empty_module) { return OPAL_SUCCESS; } mca_patcher_base_patch_t *patch; - OPAL_LIST_FOREACH_REV(patch, &opal_patcher->patch_list, mca_patcher_base_patch_t) { - patch->patch_restore (patch); + OPAL_LIST_FOREACH_REV (patch, &opal_patcher->patch_list, mca_patcher_base_patch_t) { + patch->patch_restore(patch); } OPAL_LIST_DESTRUCT(&opal_patcher->patch_list); OBJ_DESTRUCT(&opal_patcher->patch_list_mutex); if (opal_patcher->patch_fini) { - return opal_patcher->patch_fini (); + return opal_patcher->patch_fini(); } return OPAL_SUCCESS; @@ -77,5 +77,4 @@ static int opal_patcher_base_close (void) /* Use default register/open functions */ MCA_BASE_FRAMEWORK_DECLARE(opal, patcher, "runtime code patching", NULL, NULL, - opal_patcher_base_close, mca_patcher_base_static_components, - 0); + opal_patcher_base_close, mca_patcher_base_static_components, 0); diff --git a/opal/mca/patcher/base/patcher_base_patch.c b/opal/mca/patcher/base/patcher_base_patch.c index c424e63997f..8e84847733e 100644 --- a/opal/mca/patcher/base/patcher_base_patch.c +++ b/opal/mca/patcher/base/patcher_base_patch.c @@ -13,74 +13,78 @@ #include "opal_config.h" -#include "opal/mca/patcher/patcher.h" #include "opal/mca/patcher/base/base.h" -#include "opal/util/sys_limits.h" +#include "opal/mca/patcher/patcher.h" #include "opal/prefetch.h" +#include "opal/util/sys_limits.h" #include -static void mca_patcher_base_patch_construct (mca_patcher_base_patch_t *patch) +static void mca_patcher_base_patch_construct(mca_patcher_base_patch_t *patch) { patch->patch_symbol = NULL; patch->patch_data_size = 0; } -static void mca_patcher_base_patch_destruct (mca_patcher_base_patch_t *patch) +static void mca_patcher_base_patch_destruct(mca_patcher_base_patch_t *patch) { - free (patch->patch_symbol); + free(patch->patch_symbol); } -OBJ_CLASS_INSTANCE(mca_patcher_base_patch_t, opal_list_item_t, - mca_patcher_base_patch_construct, +OBJ_CLASS_INSTANCE(mca_patcher_base_patch_t, opal_list_item_t, mca_patcher_base_patch_construct, mca_patcher_base_patch_destruct); #if defined(__PPC__) // PowerPC instructions used in patching // Reference: "PowerPC User Instruction Set Architecture" -static unsigned int addis(unsigned int RT, unsigned int RS, unsigned int UI) { - return (15<<26) + (RT<<21) + (RS<<16) + (UI&0xffff); +static unsigned int addis(unsigned int RT, unsigned int RS, unsigned int UI) +{ + return (15 << 26) + (RT << 21) + (RS << 16) + (UI & 0xffff); } -static unsigned int ori(unsigned int RT, unsigned int RS, unsigned int UI) { - return (24<<26) + (RS<<21) + (RT<<16) + (UI&0xffff); +static unsigned int ori(unsigned int RT, unsigned int RS, unsigned int UI) +{ + return (24 << 26) + (RS << 21) + (RT << 16) + (UI & 0xffff); } -static unsigned int oris(unsigned int RT, unsigned int RS, unsigned int UI) { - return (25<<26) + (RS<<21) + (RT<<16) + (UI&0xffff); +static unsigned int oris(unsigned int RT, unsigned int RS, unsigned int UI) +{ + return (25 << 26) + (RS << 21) + (RT << 16) + (UI & 0xffff); } -static unsigned int mtspr(unsigned int SPR, unsigned int RS) { - return (31<<26) + (RS<<21) + ((SPR&0x1f)<<16) + ((SPR>>5)<<11) + (467<<1); +static unsigned int mtspr(unsigned int SPR, unsigned int RS) +{ + return (31 << 26) + (RS << 21) + ((SPR & 0x1f) << 16) + ((SPR >> 5) << 11) + (467 << 1); } -static unsigned int bcctr(unsigned int BO, unsigned int BI, unsigned int BH) { - return (19<<26) + (BO<<21) + (BI<<16) + (BH<<11) + (528<<1); +static unsigned int bcctr(unsigned int BO, unsigned int BI, unsigned int BH) +{ + return (19 << 26) + (BO << 21) + (BI << 16) + (BH << 11) + (528 << 1); } static unsigned int rldicr(unsigned int RT, unsigned int RS, unsigned int SH, unsigned int MB) { - return (30<<26) + (RS<<21) + (RT<<16) + ((SH&0x1f)<<11) + ((SH>>5)<<1) - + ((MB&0x1f)<<6) + ((MB>>5)<<5) + (1<<2); + return (30 << 26) + (RS << 21) + (RT << 16) + ((SH & 0x1f) << 11) + ((SH >> 5) << 1) + + ((MB & 0x1f) << 6) + ((MB >> 5) << 5) + (1 << 2); } -static int PatchLoadImm (uintptr_t addr, unsigned int reg, size_t value) +static int PatchLoadImm(uintptr_t addr, unsigned int reg, size_t value) { -#if defined(__PPC64__) - *(unsigned int *) (addr + 0) = addis ( reg, 0, (value >> 48)); - *(unsigned int *) (addr + 4) = ori ( reg, reg, (value >> 32)); - *(unsigned int *) (addr + 8) = rldicr( reg, reg, 32, 31); - *(unsigned int *) (addr +12) = oris ( reg, reg, (value >> 16)); - *(unsigned int *) (addr +16) = ori ( reg, reg, (value >> 0)); +# if defined(__PPC64__) + *(unsigned int *) (addr + 0) = addis(reg, 0, (value >> 48)); + *(unsigned int *) (addr + 4) = ori(reg, reg, (value >> 32)); + *(unsigned int *) (addr + 8) = rldicr(reg, reg, 32, 31); + *(unsigned int *) (addr + 12) = oris(reg, reg, (value >> 16)); + *(unsigned int *) (addr + 16) = ori(reg, reg, (value >> 0)); return 20; -#else - *(unsigned int *) (addr + 0) = addis ( reg, 0, (value >> 16)); - *(unsigned int *) (addr + 4) = ori ( reg, reg, (value >> 0)); +# else + *(unsigned int *) (addr + 0) = addis(reg, 0, (value >> 16)); + *(unsigned int *) (addr + 4) = ori(reg, reg, (value >> 0)); return 8; -#endif +# endif } #endif #if !HAVE___CLEAR_CACHE -static void flush_and_invalidate_cache (unsigned long a) +static void flush_and_invalidate_cache(unsigned long a) { -#if OPAL_ASSEMBLY_ARCH == OPAL_IA32 +# if OPAL_ASSEMBLY_ARCH == OPAL_IA32 static int have_clflush = -1; if (OPAL_UNLIKELY(-1 == have_clflush)) { @@ -89,97 +93,96 @@ static void flush_and_invalidate_cache (unsigned long a) /* cpuid clobbers ebx but it must be restored for -fPIC so save * then restore ebx */ - __asm__ volatile ("xchgl %%ebx, %2\n" - "cpuid\n" - "xchgl %%ebx, %2\n": - "=a" (cpuid1), "=d" (cpuid2), "=r" (tmp) : - "a" (level) : - "ecx"); + __asm__ volatile("xchgl %%ebx, %2\n" + "cpuid\n" + "xchgl %%ebx, %2\n" + : "=a"(cpuid1), "=d"(cpuid2), "=r"(tmp) + : "a"(level) + : "ecx"); /* clflush is in edx bit 19 */ have_clflush = !!(cpuid2 & (1 << 19)); } if (have_clflush) { /* does not work with AMD processors */ - __asm__ volatile("mfence;clflush %0;mfence" : :"m" (*(char*)a)); + __asm__ volatile("mfence;clflush %0;mfence" : : "m"(*(char *) a)); } -#elif OPAL_ASSEMBLY_ARCH == OPAL_X86_64 - __asm__ volatile("mfence;clflush %0;mfence" : :"m" (*(char*)a)); -#elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 - __asm__ volatile ("dc cvau, %0\n\t" - "dsb ish\n\t" - "ic ivau, %0\n\t" - "dsb ish\n\t" - "isb":: "r" (a)); -#endif +# elif OPAL_ASSEMBLY_ARCH == OPAL_X86_64 + __asm__ volatile("mfence;clflush %0;mfence" : : "m"(*(char *) a)); +# elif OPAL_ASSEMBLY_ARCH == OPAL_ARM64 + __asm__ volatile("dc cvau, %0\n\t" + "dsb ish\n\t" + "ic ivau, %0\n\t" + "dsb ish\n\t" + "isb" ::"r"(a)); +# endif } -#endif // !HAVE___CLEAR_CACHE +#endif // !HAVE___CLEAR_CACHE // modify protection of memory range -static void ModifyMemoryProtection (uintptr_t addr, size_t length, int prot) +static void ModifyMemoryProtection(uintptr_t addr, size_t length, int prot) { - long page_size = opal_getpagesize (); - uintptr_t base = (addr & ~(page_size-1)); - uintptr_t bound = ((addr + length + page_size-1) & ~(page_size-1)); + long page_size = opal_getpagesize(); + uintptr_t base = (addr & ~(page_size - 1)); + uintptr_t bound = ((addr + length + page_size - 1) & ~(page_size - 1)); length = bound - base; #if defined(__PPC__) /* NTH: is a loop necessary here? */ do { - if (mprotect((void *)base, page_size, prot)) + if (mprotect((void *) base, page_size, prot)) perror("MemHook: mprotect failed"); base += page_size; } while (base < bound); #else if (mprotect((void *) base, length, prot)) { - perror("MemHook: mprotect failed"); + perror("MemHook: mprotect failed"); } #endif } -static inline void apply_patch (unsigned char *patch_data, uintptr_t address, size_t data_size) +static inline void apply_patch(unsigned char *patch_data, uintptr_t address, size_t data_size) { - ModifyMemoryProtection (address, data_size, PROT_EXEC|PROT_READ|PROT_WRITE); - memcpy ((void *) address, patch_data, data_size); + ModifyMemoryProtection(address, data_size, PROT_EXEC | PROT_READ | PROT_WRITE); + memcpy((void *) address, patch_data, data_size); #if HAVE___CLEAR_CACHE /* do not allow global declaration of compiler intrinsic */ - void __clear_cache(void* beg, void* end); + void __clear_cache(void *beg, void *end); - __clear_cache ((void *) address, (void *) (address + data_size)); + __clear_cache((void *) address, (void *) (address + data_size)); #else size_t offset_jump = 16; -#if OPAL_ASSEMBLY_ARCH == OPAL_ARM64 +# if OPAL_ASSEMBLY_ARCH == OPAL_ARM64 offset_jump = 32; -#endif +# endif /* align the address */ address &= ~(offset_jump - 1); - for (size_t i = 0 ; i < data_size ; i += offset_jump) { - flush_and_invalidate_cache (address + i); + for (size_t i = 0; i < data_size; i += offset_jump) { + flush_and_invalidate_cache(address + i); } #endif - ModifyMemoryProtection (address, data_size, PROT_EXEC|PROT_READ); + ModifyMemoryProtection(address, data_size, PROT_EXEC | PROT_READ); } -static void mca_base_patcher_patch_unapply_binary (mca_patcher_base_patch_t *patch) +static void mca_base_patcher_patch_unapply_binary(mca_patcher_base_patch_t *patch) { - apply_patch (patch->patch_orig_data, patch->patch_orig, patch->patch_data_size); + apply_patch(patch->patch_orig_data, patch->patch_orig, patch->patch_data_size); } -void mca_base_patcher_patch_apply_binary (mca_patcher_base_patch_t *patch) +void mca_base_patcher_patch_apply_binary(mca_patcher_base_patch_t *patch) { - memcpy (patch->patch_orig_data, (void *) patch->patch_orig, patch->patch_data_size); - apply_patch (patch->patch_data, patch->patch_orig, patch->patch_data_size); + memcpy(patch->patch_orig_data, (void *) patch->patch_orig, patch->patch_data_size); + apply_patch(patch->patch_data, patch->patch_orig, patch->patch_data_size); patch->patch_restore = mca_base_patcher_patch_unapply_binary; } - -int mca_patcher_base_patch_hook (mca_patcher_base_module_t *module, uintptr_t hook_addr) +int mca_patcher_base_patch_hook(mca_patcher_base_module_t *module, uintptr_t hook_addr) { #if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) mca_patcher_base_patch_t *hook_patch; @@ -191,9 +194,9 @@ int mca_patcher_base_patch_hook (mca_patcher_base_module_t *module, uintptr_t ho } // locate reserved code space in hook function - for (unsigned int *nop_addr = (unsigned int *)hook_addr ; ; nop_addr++) { - if (nop_addr[0] == nop && nop_addr[1] == nop && nop_addr[2] == nop - && nop_addr[3] == nop && nop_addr[4] == nop) { + for (unsigned int *nop_addr = (unsigned int *) hook_addr;; nop_addr++) { + if (nop_addr[0] == nop && nop_addr[1] == nop && nop_addr[2] == nop && nop_addr[3] == nop + && nop_addr[4] == nop) { hook_patch->patch_orig = (uintptr_t) nop_addr; break; } @@ -202,14 +205,14 @@ int mca_patcher_base_patch_hook (mca_patcher_base_module_t *module, uintptr_t ho // generate code to restore TOC unsigned long toc; - asm volatile ("std 2, %0" : "=m" (toc)); + asm volatile("std 2, %0" : "=m"(toc)); - hook_patch->patch_data_size = PatchLoadImm((uintptr_t)hook_patch->patch_data, 2, toc); + hook_patch->patch_data_size = PatchLoadImm((uintptr_t) hook_patch->patch_data, 2, toc); /* put the hook patch on the patch list so it will be undone on finalize */ - opal_list_append (&module->patch_list, &hook_patch->super); + opal_list_append(&module->patch_list, &hook_patch->super); - mca_base_patcher_patch_apply_binary (hook_patch); + mca_base_patcher_patch_apply_binary(hook_patch); #endif return OPAL_SUCCESS; diff --git a/opal/mca/patcher/overwrite/patcher_overwrite.h b/opal/mca/patcher/overwrite/patcher_overwrite.h index 9c2ad58dfd5..7d3e75eb08c 100644 --- a/opal/mca/patcher/overwrite/patcher_overwrite.h +++ b/opal/mca/patcher/overwrite/patcher_overwrite.h @@ -20,11 +20,11 @@ */ #if !defined(OPAL_PATCHER_OVERWRITE_H) -#define OPAL_PATCHER_OVERWRITE_H +# define OPAL_PATCHER_OVERWRITE_H -#include "opal_config.h" -#include "opal/mca/patcher/patcher.h" -#include "opal/class/opal_list.h" +# include "opal_config.h" +# include "opal/class/opal_list.h" +# include "opal/mca/patcher/patcher.h" extern mca_patcher_base_module_t mca_patcher_overwrite_module; extern mca_patcher_base_component_t mca_patcher_overwrite_component; diff --git a/opal/mca/patcher/overwrite/patcher_overwrite_component.c b/opal/mca/patcher/overwrite/patcher_overwrite_component.c index 5211d4deaef..90abcf6f418 100644 --- a/opal/mca/patcher/overwrite/patcher_overwrite_component.c +++ b/opal/mca/patcher/overwrite/patcher_overwrite_component.c @@ -9,24 +9,24 @@ * $HEADER$ */ -#include "patcher_overwrite.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" +#include "patcher_overwrite.h" static int mca_patcher_overwrite_priority; -static int mca_patcher_overwrite_register (void) +static int mca_patcher_overwrite_register(void) { mca_patcher_overwrite_priority = 37; - mca_base_component_var_register (&mca_patcher_overwrite_component.patcherc_version, - "priority", "Priority of the overwrite binary patcher component", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_CONSTANT, &mca_patcher_overwrite_priority); + mca_base_component_var_register(&mca_patcher_overwrite_component.patcherc_version, "priority", + "Priority of the overwrite binary patcher component", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_CONSTANT, &mca_patcher_overwrite_priority); return OPAL_SUCCESS; } -static int mca_patcher_overwrite_query (mca_base_module_t **module, int *priority) +static int mca_patcher_overwrite_query(mca_base_module_t **module, int *priority) { *module = &mca_patcher_overwrite_module.super; *priority = mca_patcher_overwrite_priority; @@ -34,12 +34,13 @@ static int mca_patcher_overwrite_query (mca_base_module_t **module, int *priorit } mca_patcher_base_component_t mca_patcher_overwrite_component = { - .patcherc_version = { - OPAL_PATCHER_BASE_VERSION_1_0_0, - .mca_component_name = "overwrite", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - .mca_query_component = mca_patcher_overwrite_query, - .mca_register_component_params = mca_patcher_overwrite_register, - }, + .patcherc_version = + { + OPAL_PATCHER_BASE_VERSION_1_0_0, + .mca_component_name = "overwrite", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + .mca_query_component = mca_patcher_overwrite_query, + .mca_register_component_params = mca_patcher_overwrite_register, + }, }; diff --git a/opal/mca/patcher/overwrite/patcher_overwrite_module.c b/opal/mca/patcher/overwrite/patcher_overwrite_module.c index dae4cd1ae1d..bb6d2344a55 100644 --- a/opal/mca/patcher/overwrite/patcher_overwrite_module.c +++ b/opal/mca/patcher/overwrite/patcher_overwrite_module.c @@ -17,41 +17,42 @@ #include "opal/mca/patcher/base/base.h" #include "opal/constants.h" -#include "opal/util/sys_limits.h" -#include "opal/util/output.h" #include "opal/prefetch.h" +#include "opal/util/output.h" +#include "opal/util/sys_limits.h" +#include +#include +#include #include #include -#include -#include #include #include -#include -#include +#include #if (OPAL_ASSEMBLY_ARCH == OPAL_IA32) || (OPAL_ASSEMBLY_ARCH == OPAL_X86_64) -static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) +static int mca_patcher_overwrite_apply_patch(mca_patcher_base_patch_t *patch) { uintptr_t func_new_addr = patch->patch_value; { -#if (OPAL_ASSEMBLY_ARCH == OPAL_IA32) +# if (OPAL_ASSEMBLY_ARCH == OPAL_IA32) patch->patch_data_size = 5; - *(unsigned char *)(patch->patch_data+0) = 0xe9; - *(unsigned int *) (patch->patch_data+1) = (unsigned int)(func_new_addr - patch->patch_orig - 5); -#elif (OPAL_ASSEMBLY_ARCH == OPAL_X86_64) + *(unsigned char *) (patch->patch_data + 0) = 0xe9; + *(unsigned int *) (patch->patch_data + 1) = (unsigned int) (func_new_addr + - patch->patch_orig - 5); +# elif (OPAL_ASSEMBLY_ARCH == OPAL_X86_64) patch->patch_data_size = 13; - *(unsigned short*)(patch->patch_data + 0) = 0xbb49; - *(unsigned long* )(patch->patch_data + 2) = (unsigned long) func_new_addr; - *(unsigned char*) (patch->patch_data +10) = 0x41; - *(unsigned char*) (patch->patch_data +11) = 0xff; - *(unsigned char*) (patch->patch_data +12) = 0xe3; -#endif + *(unsigned short *) (patch->patch_data + 0) = 0xbb49; + *(unsigned long *) (patch->patch_data + 2) = (unsigned long) func_new_addr; + *(unsigned char *) (patch->patch_data + 10) = 0x41; + *(unsigned char *) (patch->patch_data + 11) = 0xff; + *(unsigned char *) (patch->patch_data + 12) = 0xe3; +# endif } - mca_base_patcher_patch_apply_binary (patch); + mca_base_patcher_patch_apply_binary(patch); return OPAL_SUCCESS; } @@ -62,46 +63,49 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) // PowerPC instructions used in patching // Reference: "PowerPC User Instruction Set Architecture" -static unsigned int addis(unsigned int RT, unsigned int RS, unsigned int UI) { - return (15<<26) + (RT<<21) + (RS<<16) + (UI&0xffff); +static unsigned int addis(unsigned int RT, unsigned int RS, unsigned int UI) +{ + return (15 << 26) + (RT << 21) + (RS << 16) + (UI & 0xffff); } -static unsigned int ori(unsigned int RT, unsigned int RS, unsigned int UI) { - return (24<<26) + (RS<<21) + (RT<<16) + (UI&0xffff); +static unsigned int ori(unsigned int RT, unsigned int RS, unsigned int UI) +{ + return (24 << 26) + (RS << 21) + (RT << 16) + (UI & 0xffff); } -static unsigned int oris(unsigned int RT, unsigned int RS, unsigned int UI) { - return (25<<26) + (RS<<21) + (RT<<16) + (UI&0xffff); +static unsigned int oris(unsigned int RT, unsigned int RS, unsigned int UI) +{ + return (25 << 26) + (RS << 21) + (RT << 16) + (UI & 0xffff); } -static unsigned int mtspr(unsigned int SPR, unsigned int RS) { - return (31<<26) + (RS<<21) + ((SPR&0x1f)<<16) + ((SPR>>5)<<11) + (467<<1); +static unsigned int mtspr(unsigned int SPR, unsigned int RS) +{ + return (31 << 26) + (RS << 21) + ((SPR & 0x1f) << 16) + ((SPR >> 5) << 11) + (467 << 1); } -static unsigned int bcctr(unsigned int BO, unsigned int BI, unsigned int BH) { - return (19<<26) + (BO<<21) + (BI<<16) + (BH<<11) + (528<<1); +static unsigned int bcctr(unsigned int BO, unsigned int BI, unsigned int BH) +{ + return (19 << 26) + (BO << 21) + (BI << 16) + (BH << 11) + (528 << 1); } static unsigned int rldicr(unsigned int RT, unsigned int RS, unsigned int SH, unsigned int MB) { - return (30<<26) + (RS<<21) + (RT<<16) + ((SH&0x1f)<<11) + ((SH>>5)<<1) - + ((MB&0x1f)<<6) + ((MB>>5)<<5) + (1<<2); + return (30 << 26) + (RS << 21) + (RT << 16) + ((SH & 0x1f) << 11) + ((SH >> 5) << 1) + + ((MB & 0x1f) << 6) + ((MB >> 5) << 5) + (1 << 2); } -static int -PatchLoadImm(uintptr_t addr, unsigned int reg, size_t value) +static int PatchLoadImm(uintptr_t addr, unsigned int reg, size_t value) { -#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) - *(unsigned int *) (addr + 0) = addis ( reg, 0, (value >> 48)); - *(unsigned int *) (addr + 4) = ori ( reg, reg, (value >> 32)); - *(unsigned int *) (addr + 8) = rldicr( reg, reg, 32, 31); - *(unsigned int *) (addr +12) = oris ( reg, reg, (value >> 16)); - *(unsigned int *) (addr +16) = ori ( reg, reg, (value >> 0)); +# if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) + *(unsigned int *) (addr + 0) = addis(reg, 0, (value >> 48)); + *(unsigned int *) (addr + 4) = ori(reg, reg, (value >> 32)); + *(unsigned int *) (addr + 8) = rldicr(reg, reg, 32, 31); + *(unsigned int *) (addr + 12) = oris(reg, reg, (value >> 16)); + *(unsigned int *) (addr + 16) = ori(reg, reg, (value >> 0)); return 20; -#else - *(unsigned int *) (addr + 0) = addis ( reg, 0, (value >> 16)); - *(unsigned int *) (addr + 4) = ori ( reg, reg, (value >> 0)); +# else + *(unsigned int *) (addr + 0) = addis(reg, 0, (value >> 16)); + *(unsigned int *) (addr + 4) = ori(reg, reg, (value >> 0)); return 8; -#endif +# endif } - -static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) +static int mca_patcher_overwrite_apply_patch(mca_patcher_base_patch_t *patch) { uintptr_t sys_addr, hook_addr; int offset, rc; @@ -111,29 +115,29 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) hook_addr = mca_patcher_base_addr_text(patch->patch_value); // Patch for hook function: -#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) - rc = mca_patcher_base_patch_hook (&mca_patcher_overwrite_module, hook_addr); +# if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) + rc = mca_patcher_base_patch_hook(&mca_patcher_overwrite_module, hook_addr); if (OPAL_SUCCESS != rc) { return rc; } -#if defined(_CALL_ELF) && (_CALL_ELF == 2) +# if defined(_CALL_ELF) && (_CALL_ELF == 2) sys_addr += 8; hook_addr += 8; -#endif /* _CALL_ELF == 2*/ -#endif +# endif /* _CALL_ELF == 2*/ +# endif // Patch for system function: // generate patch code // r11 is a volatile register according to PowerPC EABI const unsigned int gr = 11; - offset = PatchLoadImm ((uintptr_t) patch->patch_data, gr, hook_addr); - *(unsigned int *) (patch->patch_data + offset + 0) = mtspr (9, gr); // 9 = CTR - *(unsigned int *) (patch->patch_data + offset + 4) = bcctr (20, 0, 0);// 20 = always + offset = PatchLoadImm((uintptr_t) patch->patch_data, gr, hook_addr); + *(unsigned int *) (patch->patch_data + offset + 0) = mtspr(9, gr); // 9 = CTR + *(unsigned int *) (patch->patch_data + offset + 4) = bcctr(20, 0, 0); // 20 = always patch->patch_data_size = offset + 8; patch->patch_orig = sys_addr; - mca_base_patcher_patch_apply_binary (patch); + mca_base_patcher_patch_apply_binary(patch); return OPAL_SUCCESS; } @@ -147,7 +151,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) * @param[in] shift shift amount (0-3) * 16-bits * @param[in] value immediate value */ -static uint32_t mov (unsigned int reg, uint16_t shift, uint16_t value) +static uint32_t mov(unsigned int reg, uint16_t shift, uint16_t value) { return (0x1a5 << 23) + ((uint32_t) shift << 21) + ((uint32_t) value << 5) + reg; } @@ -159,27 +163,26 @@ static uint32_t mov (unsigned int reg, uint16_t shift, uint16_t value) * @param[in] shift shift amount (0-3) * 16-bits * @param[in] value immediate value */ -static uint32_t movk (unsigned int reg, uint16_t shift, uint16_t value) +static uint32_t movk(unsigned int reg, uint16_t shift, uint16_t value) { return (0x1e5 << 23) + ((uint32_t) shift << 21) + ((uint32_t) value << 5) + reg; } -static uint32_t br (unsigned int reg) +static uint32_t br(unsigned int reg) { return (0xd61f << 16) + (reg << 5); } -static int -PatchLoadImm(uintptr_t addr, unsigned int reg, uint64_t value) +static int PatchLoadImm(uintptr_t addr, unsigned int reg, uint64_t value) { - *(uint32_t *) (addr + 0) = mov(reg, 3, value >> 48); - *(uint32_t *) (addr + 4) = movk(reg, 2, value >> 32); - *(uint32_t *) (addr + 8) = movk(reg, 1, value >> 16); + *(uint32_t *) (addr + 0) = mov(reg, 3, value >> 48); + *(uint32_t *) (addr + 4) = movk(reg, 2, value >> 32); + *(uint32_t *) (addr + 8) = movk(reg, 1, value >> 16); *(uint32_t *) (addr + 12) = movk(reg, 0, value); return 16; } -static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) +static int mca_patcher_overwrite_apply_patch(mca_patcher_base_patch_t *patch) { uintptr_t sys_addr, hook_addr; int offset, rc; @@ -189,7 +192,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) hook_addr = mca_patcher_base_addr_text(patch->patch_value); /* Patch for hook function: */ - rc = mca_patcher_base_patch_hook (&mca_patcher_overwrite_module, hook_addr); + rc = mca_patcher_base_patch_hook(&mca_patcher_overwrite_module, hook_addr); if (OPAL_SUCCESS != rc) { return rc; } @@ -199,19 +202,19 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch) * r15 is the highest numbered temporary register. I am assuming this one is safe * to use. */ const unsigned int gr = 15; - offset = PatchLoadImm ((uintptr_t) patch->patch_data, gr, hook_addr); + offset = PatchLoadImm((uintptr_t) patch->patch_data, gr, hook_addr); *(uint32_t *) (patch->patch_data + offset) = br(gr); patch->patch_data_size = offset + 4; patch->patch_orig = sys_addr; - mca_base_patcher_patch_apply_binary (patch); + mca_base_patcher_patch_apply_binary(patch); return OPAL_SUCCESS; } #endif -static int mca_patcher_overwrite_patch_address (uintptr_t sys_addr, uintptr_t hook_addr) +static int mca_patcher_overwrite_patch_address(uintptr_t sys_addr, uintptr_t hook_addr) { mca_patcher_base_patch_t *patch; int rc; @@ -224,23 +227,23 @@ static int mca_patcher_overwrite_patch_address (uintptr_t sys_addr, uintptr_t ho patch->patch_orig = sys_addr; patch->patch_value = hook_addr; - opal_mutex_lock (&mca_patcher_overwrite_module.patch_list_mutex); + opal_mutex_lock(&mca_patcher_overwrite_module.patch_list_mutex); do { - rc = mca_patcher_overwrite_apply_patch (patch); + rc = mca_patcher_overwrite_apply_patch(patch); if (OPAL_SUCCESS != rc) { break; } - opal_list_append (&mca_patcher_overwrite_module.patch_list, &patch->super); + opal_list_append(&mca_patcher_overwrite_module.patch_list, &patch->super); } while (0); - opal_mutex_unlock (&mca_patcher_overwrite_module.patch_list_mutex); + opal_mutex_unlock(&mca_patcher_overwrite_module.patch_list_mutex); return OPAL_SUCCESS; } -static int mca_patcher_overwrite_patch_symbol (const char *func_symbol_name, uintptr_t func_new_addr, - uintptr_t *func_old_addr) +static int mca_patcher_overwrite_patch_symbol(const char *func_symbol_name, uintptr_t func_new_addr, + uintptr_t *func_old_addr) { void *sym_addr; char *error; @@ -248,17 +251,16 @@ static int mca_patcher_overwrite_patch_symbol (const char *func_symbol_name, uin /* NTH: might want to update opal/mca/dl to handle lookups in the default * handle. */ - sym_addr = dlsym (RTLD_NEXT, func_symbol_name); + sym_addr = dlsym(RTLD_NEXT, func_symbol_name); if (NULL == sym_addr) { sym_addr = dlsym(RTLD_DEFAULT, func_symbol_name); - if ( (sym_addr == NULL) && ((error = dlerror()) != NULL) ) { - opal_output(0, "error locating symbol %s to patch. %s", func_symbol_name, - error); + if ((sym_addr == NULL) && ((error = dlerror()) != NULL)) { + opal_output(0, "error locating symbol %s to patch. %s", func_symbol_name, error); return OPAL_ERR_NOT_FOUND; } } - old_addr = (unsigned long)sym_addr; + old_addr = (unsigned long) sym_addr; if (func_old_addr) { /* we will be overwritting part of the original function. do not return @@ -266,7 +268,7 @@ static int mca_patcher_overwrite_patch_symbol (const char *func_symbol_name, uin *func_old_addr = 0; } - return mca_patcher_overwrite_patch_address (old_addr, func_new_addr); + return mca_patcher_overwrite_patch_address(old_addr, func_new_addr); } mca_patcher_base_module_t mca_patcher_overwrite_module = { diff --git a/opal/mca/patcher/patcher.h b/opal/mca/patcher/patcher.h index 8e8d13a1c93..2ebf752e6d1 100644 --- a/opal/mca/patcher/patcher.h +++ b/opal/mca/patcher/patcher.h @@ -14,9 +14,9 @@ #include "opal_config.h" -#include "opal/mca/mca.h" -#include "opal/mca/base/base.h" #include "opal/class/opal_list.h" +#include "opal/mca/base/base.h" +#include "opal/mca/mca.h" /* Any function being patched in as a hook must use SYMBOLPATCH_BEGIN at the top, * and SYMBOLPATCH_END before it returns (this is just for PPC). */ @@ -25,17 +25,16 @@ /* special processing for ppc64 to save and restore TOC (r2) * Reference: "64-bit PowerPC ELF Application Binary Interface Supplement 1.9" */ -#define OPAL_PATCHER_BEGIN \ - unsigned long toc_save; \ - asm volatile ("std 2, %0" : "=m" (toc_save)); \ - asm volatile ("nop; nop; nop; nop; nop"); -#define OPAL_PATCHER_END \ - asm volatile ("ld 2, %0" : : "m" (toc_save)); +# define OPAL_PATCHER_BEGIN \ + unsigned long toc_save; \ + asm volatile("std 2, %0" : "=m"(toc_save)); \ + asm volatile("nop; nop; nop; nop; nop"); +# define OPAL_PATCHER_END asm volatile("ld 2, %0" : : "m"(toc_save)); #else /* !__PPC64__ */ -#define OPAL_PATCHER_BEGIN -#define OPAL_PATCHER_END +# define OPAL_PATCHER_BEGIN +# define OPAL_PATCHER_END #endif @@ -51,8 +50,9 @@ * function to call the original function the patcher module will return * the old function's address in func_old_addr. */ -typedef int (*mca_patcher_base_patch_symbol_fn_t)(const char *func_symbol_name, uintptr_t func_new_addr, - uintptr_t *func_old_addr); +typedef int (*mca_patcher_base_patch_symbol_fn_t)(const char *func_symbol_name, + uintptr_t func_new_addr, + uintptr_t *func_old_addr); /** * Make any calls to a function redirect to a new function @@ -69,12 +69,12 @@ typedef int (*mca_patcher_base_patch_address_fn_t)(uintptr_t func_addr, uintptr_ /** * Set up the patcher module */ -typedef int (*mca_patcher_base_init_fn_t) (void); +typedef int (*mca_patcher_base_init_fn_t)(void); /** * Finalize the patcher module */ -typedef int (*mca_patcher_base_fini_fn_t) (void); +typedef int (*mca_patcher_base_fini_fn_t)(void); /** * Structure for patcher modules. @@ -82,22 +82,21 @@ typedef int (*mca_patcher_base_fini_fn_t) (void); typedef struct mca_patcher_base_module_t { mca_base_module_t super; /** list of patches */ - opal_list_t patch_list; + opal_list_t patch_list; /** lock for patch list */ - opal_mutex_t patch_list_mutex; + opal_mutex_t patch_list_mutex; /** function to call if the patcher module is used. can * be NULL. */ - mca_patcher_base_init_fn_t patch_init; + mca_patcher_base_init_fn_t patch_init; /** function to call when patcher is unloaded. this function * MUST clean up all active patches. can be NULL. */ - mca_patcher_base_fini_fn_t patch_fini; + mca_patcher_base_fini_fn_t patch_fini; /** hook a symbol. may be NULL */ - mca_patcher_base_patch_symbol_fn_t patch_symbol; + mca_patcher_base_patch_symbol_fn_t patch_symbol; /** hook a function pointer. may be NULL */ mca_patcher_base_patch_address_fn_t patch_address; } mca_patcher_base_module_t; - OPAL_DECLSPEC extern mca_patcher_base_module_t *opal_patcher; /** @@ -115,7 +114,6 @@ typedef mca_patcher_base_component_1_0_0_t mca_patcher_base_component_t; /* * Macro for use in components that are of type patcher */ -#define OPAL_PATCHER_BASE_VERSION_1_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("patcher", 1, 0, 0) +#define OPAL_PATCHER_BASE_VERSION_1_0_0 OPAL_MCA_BASE_VERSION_2_1_0("patcher", 1, 0, 0) #endif /* OPAL_MCA_PATCHER_PATCHER_H */ diff --git a/opal/mca/pmix/base/base.h b/opal/mca/pmix/base/base.h index 323a92f9800..380a98dbcec 100644 --- a/opal/mca/pmix/base/base.h +++ b/opal/mca/pmix/base/base.h @@ -15,10 +15,10 @@ #define MCA_PMI_BASE_H #include "opal_config.h" -#include "opal/types.h" -#include "opal/mca/threads/threads.h" -#include "opal/mca/mca.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/mca.h" +#include "opal/mca/threads/threads.h" +#include "opal/types.h" #include "opal/mca/pmix/pmix-internal.h" @@ -33,9 +33,7 @@ OPAL_DECLSPEC int opal_pmix_base_select(void); OPAL_DECLSPEC extern bool opal_pmix_base_allow_delayed_server; -OPAL_DECLSPEC int opal_pmix_base_exchange(pmix_info_t *info, - pmix_pdata_t *pdat, - int timeout); +OPAL_DECLSPEC int opal_pmix_base_exchange(pmix_info_t *info, pmix_pdata_t *pdat, int timeout); typedef struct { opal_event_base_t *evbase; diff --git a/opal/mca/pmix/base/pmix_base_fns.c b/opal/mca/pmix/base/pmix_base_fns.c index 13bfc092b60..eaeee0900f9 100644 --- a/opal/mca/pmix/base/pmix_base_fns.c +++ b/opal/mca/pmix/base/pmix_base_fns.c @@ -20,28 +20,24 @@ #include "opal_config.h" #include "opal/constants.h" - #include -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif -#include "opal_stdint.h" #include "opal/class/opal_pointer_array.h" #include "opal/util/argv.h" #include "opal/util/output.h" #include "opal/util/proc.h" #include "opal/util/show_help.h" +#include "opal_stdint.h" #include "opal/mca/pmix/base/base.h" - -int opal_pmix_base_exchange(pmix_info_t *indat, - pmix_pdata_t *outdat, - int timeout) +int opal_pmix_base_exchange(pmix_info_t *indat, pmix_pdata_t *outdat, int timeout) { pmix_status_t rc; pmix_info_t info[2]; @@ -83,9 +79,7 @@ typedef struct { pmix_nspace_t nspace; opal_jobid_t jobid; } opal_nptr_t; -static OBJ_CLASS_INSTANCE(opal_nptr_t, - opal_list_item_t, - NULL, NULL); +static OBJ_CLASS_INSTANCE(opal_nptr_t, opal_list_item_t, NULL, NULL); static opal_list_t localnspaces; @@ -112,7 +106,7 @@ int opal_pmix_convert_jobid(pmix_nspace_t nspace, opal_jobid_t jobid) PMIX_LOAD_NSPACE(nspace, NULL); /* cycle across our list of known jobids */ - OPAL_LIST_FOREACH(nptr, &localnspaces, opal_nptr_t) { + OPAL_LIST_FOREACH (nptr, &localnspaces, opal_nptr_t) { if (jobid == nptr->jobid) { PMIX_LOAD_NSPACE(nspace, nptr->nspace); return OPAL_SUCCESS; @@ -141,7 +135,7 @@ int opal_pmix_convert_nspace(opal_jobid_t *jobid, pmix_nspace_t nspace) } /* cycle across our list of known nspace's */ - OPAL_LIST_FOREACH(nptr, &localnspaces, opal_nptr_t) { + OPAL_LIST_FOREACH (nptr, &localnspaces, opal_nptr_t) { if (PMIX_CHECK_NSPACE(nspace, nptr->nspace)) { if (NULL != jobid) { *jobid = nptr->jobid; @@ -164,7 +158,7 @@ int opal_pmix_convert_nspace(opal_jobid_t *jobid, pmix_nspace_t nspace) /* now compress to 16-bits */ jobfam = (uint16_t)(((0x0000ffff & (0xffff0000 & hash32) >> 16)) ^ (0x0000ffff & hash32)); - jid = (0xffff0000 & ((uint32_t)jobfam << 16)) | (0x0000ffff & localjob); + jid = (0xffff0000 & ((uint32_t) jobfam << 16)) | (0x0000ffff & localjob); if (NULL != jobid) { *jobid = jid; } @@ -356,102 +350,99 @@ int opal_pmix_convert_status(pmix_status_t status) pmix_proc_state_t opal_pmix_convert_state(int state) { - switch(state) { - case 0: - return PMIX_PROC_STATE_UNDEF; - case 1: - return PMIX_PROC_STATE_LAUNCH_UNDERWAY; - case 2: - return PMIX_PROC_STATE_RESTART; - case 3: - return PMIX_PROC_STATE_TERMINATE; - case 4: - return PMIX_PROC_STATE_RUNNING; - case 5: - return PMIX_PROC_STATE_CONNECTED; - case 51: - return PMIX_PROC_STATE_KILLED_BY_CMD; - case 52: - return PMIX_PROC_STATE_ABORTED; - case 53: - return PMIX_PROC_STATE_FAILED_TO_START; - case 54: - return PMIX_PROC_STATE_ABORTED_BY_SIG; - case 55: - return PMIX_PROC_STATE_TERM_WO_SYNC; - case 56: - return PMIX_PROC_STATE_COMM_FAILED; - case 58: - return PMIX_PROC_STATE_CALLED_ABORT; - case 59: - return PMIX_PROC_STATE_MIGRATING; - case 61: - return PMIX_PROC_STATE_CANNOT_RESTART; - case 62: - return PMIX_PROC_STATE_TERM_NON_ZERO; - case 63: - return PMIX_PROC_STATE_FAILED_TO_LAUNCH; - default: - return PMIX_PROC_STATE_UNDEF; + switch (state) { + case 0: + return PMIX_PROC_STATE_UNDEF; + case 1: + return PMIX_PROC_STATE_LAUNCH_UNDERWAY; + case 2: + return PMIX_PROC_STATE_RESTART; + case 3: + return PMIX_PROC_STATE_TERMINATE; + case 4: + return PMIX_PROC_STATE_RUNNING; + case 5: + return PMIX_PROC_STATE_CONNECTED; + case 51: + return PMIX_PROC_STATE_KILLED_BY_CMD; + case 52: + return PMIX_PROC_STATE_ABORTED; + case 53: + return PMIX_PROC_STATE_FAILED_TO_START; + case 54: + return PMIX_PROC_STATE_ABORTED_BY_SIG; + case 55: + return PMIX_PROC_STATE_TERM_WO_SYNC; + case 56: + return PMIX_PROC_STATE_COMM_FAILED; + case 58: + return PMIX_PROC_STATE_CALLED_ABORT; + case 59: + return PMIX_PROC_STATE_MIGRATING; + case 61: + return PMIX_PROC_STATE_CANNOT_RESTART; + case 62: + return PMIX_PROC_STATE_TERM_NON_ZERO; + case 63: + return PMIX_PROC_STATE_FAILED_TO_LAUNCH; + default: + return PMIX_PROC_STATE_UNDEF; } } int opal_pmix_convert_pstate(pmix_proc_state_t state) { - switch(state) { - case PMIX_PROC_STATE_UNDEF: - return 0; - case PMIX_PROC_STATE_PREPPED: - case PMIX_PROC_STATE_LAUNCH_UNDERWAY: - return 1; - case PMIX_PROC_STATE_RESTART: - return 2; - case PMIX_PROC_STATE_TERMINATE: - return 3; - case PMIX_PROC_STATE_RUNNING: - return 4; - case PMIX_PROC_STATE_CONNECTED: - return 5; - case PMIX_PROC_STATE_UNTERMINATED: - return 15; - case PMIX_PROC_STATE_TERMINATED: - return 20; - case PMIX_PROC_STATE_KILLED_BY_CMD: - return 51; - case PMIX_PROC_STATE_ABORTED: - return 52; - case PMIX_PROC_STATE_FAILED_TO_START: - return 53; - case PMIX_PROC_STATE_ABORTED_BY_SIG: - return 54; - case PMIX_PROC_STATE_TERM_WO_SYNC: - return 55; - case PMIX_PROC_STATE_COMM_FAILED: - return 56; - case PMIX_PROC_STATE_CALLED_ABORT: - return 58; - case PMIX_PROC_STATE_MIGRATING: - return 60; - case PMIX_PROC_STATE_CANNOT_RESTART: - return 61; - case PMIX_PROC_STATE_TERM_NON_ZERO: - return 62; - case PMIX_PROC_STATE_FAILED_TO_LAUNCH: - return 63; - default: - return 0; // undef + switch (state) { + case PMIX_PROC_STATE_UNDEF: + return 0; + case PMIX_PROC_STATE_PREPPED: + case PMIX_PROC_STATE_LAUNCH_UNDERWAY: + return 1; + case PMIX_PROC_STATE_RESTART: + return 2; + case PMIX_PROC_STATE_TERMINATE: + return 3; + case PMIX_PROC_STATE_RUNNING: + return 4; + case PMIX_PROC_STATE_CONNECTED: + return 5; + case PMIX_PROC_STATE_UNTERMINATED: + return 15; + case PMIX_PROC_STATE_TERMINATED: + return 20; + case PMIX_PROC_STATE_KILLED_BY_CMD: + return 51; + case PMIX_PROC_STATE_ABORTED: + return 52; + case PMIX_PROC_STATE_FAILED_TO_START: + return 53; + case PMIX_PROC_STATE_ABORTED_BY_SIG: + return 54; + case PMIX_PROC_STATE_TERM_WO_SYNC: + return 55; + case PMIX_PROC_STATE_COMM_FAILED: + return 56; + case PMIX_PROC_STATE_CALLED_ABORT: + return 58; + case PMIX_PROC_STATE_MIGRATING: + return 60; + case PMIX_PROC_STATE_CANNOT_RESTART: + return 61; + case PMIX_PROC_STATE_TERM_NON_ZERO: + return 62; + case PMIX_PROC_STATE_FAILED_TO_LAUNCH: + return 63; + default: + return 0; // undef } } #if PMIX_NUMERIC_VERSION >= 0x00030000 -static void cleanup_cbfunc(pmix_status_t status, - pmix_info_t *info, size_t ninfo, - void *cbdata, - pmix_release_cbfunc_t release_fn, - void *release_cbdata) +static void cleanup_cbfunc(pmix_status_t status, pmix_info_t *info, size_t ninfo, void *cbdata, + pmix_release_cbfunc_t release_fn, void *release_cbdata) { - opal_pmix_lock_t *lk = (opal_pmix_lock_t*)cbdata; + opal_pmix_lock_t *lk = (opal_pmix_lock_t *) cbdata; OPAL_POST_OBJECT(lk); @@ -472,7 +463,7 @@ int opal_pmix_register_cleanup(char *path, bool directory, bool ignore, bool job #if PMIX_NUMERIC_VERSION >= 0x00030000 opal_pmix_lock_t lk; pmix_info_t pinfo[3]; - size_t n, ninfo=0; + size_t n, ninfo = 0; pmix_status_t rc, ret; pmix_proc_t proc; @@ -498,27 +489,27 @@ int opal_pmix_register_cleanup(char *path, bool directory, bool ignore, bool job /* if they want this applied to the job, then indicate so */ if (jobscope) { - rc = PMIx_Job_control_nb(NULL, 0, pinfo, ninfo, cleanup_cbfunc, (void*)&lk); + rc = PMIx_Job_control_nb(NULL, 0, pinfo, ninfo, cleanup_cbfunc, (void *) &lk); } else { /* only applies to us */ - (void)snprintf(proc.nspace, PMIX_MAX_NSLEN, "%s", - OPAL_JOBID_PRINT(OPAL_PROC_MY_NAME.jobid)); + (void) snprintf(proc.nspace, PMIX_MAX_NSLEN, "%s", + OPAL_JOBID_PRINT(OPAL_PROC_MY_NAME.jobid)); proc.rank = OPAL_PROC_MY_NAME.vpid; - rc = PMIx_Job_control_nb(&proc, 1, pinfo, ninfo, cleanup_cbfunc, (void*)&lk); + rc = PMIx_Job_control_nb(&proc, 1, pinfo, ninfo, cleanup_cbfunc, (void *) &lk); } if (PMIX_SUCCESS != rc) { ret = rc; } else { -#if PMIX_VERSION_MAJOR == 3 && PMIX_VERSION_MINOR == 0 && PMIX_VERSION_RELEASE < 3 +# if PMIX_VERSION_MAJOR == 3 && PMIX_VERSION_MINOR == 0 && PMIX_VERSION_RELEASE < 3 /* There is a bug in PMIx 3.0.0 up to 3.0.2 that causes the callback never * being called, so assumes the everything went well and avoid a deadlock. */ - cleanup_cbfunc(PMIX_SUCCESS, NULL, 0, (void *)&lk, NULL, NULL); -#endif + cleanup_cbfunc(PMIX_SUCCESS, NULL, 0, (void *) &lk, NULL, NULL); +# endif OPAL_PMIX_WAIT_THREAD(&lk); ret = lk.status; } OPAL_PMIX_DESTRUCT_LOCK(&lk); - for (n=0; n < ninfo; n++) { + for (n = 0; n < ninfo; n++) { PMIX_INFO_DESTRUCT(&pinfo[n]); } return ret; @@ -527,7 +518,6 @@ int opal_pmix_register_cleanup(char *path, bool directory, bool ignore, bool job #endif } - /* CLASS INSTANTIATIONS */ static void dsicon(opal_ds_info_t *p) { @@ -539,9 +529,7 @@ static void dsicon(opal_ds_info_t *p) p->persistence = PMIX_PERSIST_INDEF; #endif } -OBJ_CLASS_INSTANCE(opal_ds_info_t, - opal_list_item_t, - dsicon, NULL); +OBJ_CLASS_INSTANCE(opal_ds_info_t, opal_list_item_t, dsicon, NULL); static void infoitmcon(opal_info_item_t *p) { @@ -551,10 +539,6 @@ static void infoitdecon(opal_info_item_t *p) { PMIX_INFO_DESTRUCT(&p->info); } -OBJ_CLASS_INSTANCE(opal_info_item_t, - opal_list_item_t, - infoitmcon, infoitdecon); +OBJ_CLASS_INSTANCE(opal_info_item_t, opal_list_item_t, infoitmcon, infoitdecon); -OBJ_CLASS_INSTANCE(opal_proclist_t, - opal_list_item_t, - NULL, NULL); +OBJ_CLASS_INSTANCE(opal_proclist_t, opal_list_item_t, NULL, NULL); diff --git a/opal/mca/pmix/base/pmix_base_frame.c b/opal/mca/pmix/base/pmix_base_frame.c index 0d509b5bfd6..319b21ccddc 100644 --- a/opal/mca/pmix/base/pmix_base_frame.c +++ b/opal/mca/pmix/base/pmix_base_frame.c @@ -8,19 +8,17 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" +#include "opal/mca/base/base.h" #include "opal/mca/mca.h" #include "opal/mca/threads/thread_usage.h" #include "opal/util/argv.h" #include "opal/util/output.h" -#include "opal/mca/base/base.h" -#include "opal/mca/pmix/pmix-internal.h" #include "opal/mca/pmix/base/base.h" - +#include "opal/mca/pmix/pmix-internal.h" /* * The following file was created by configure. It contains extern @@ -33,27 +31,25 @@ bool opal_pmix_collect_all_data = true; int opal_pmix_verbose_output = -1; bool opal_pmix_base_async_modex = false; -opal_pmix_base_t opal_pmix_base = { - .evbase = NULL, - .timeout = 0, - .initialized = 0, - .lock = { - .mutex = OPAL_MUTEX_STATIC_INIT, - .cond = OPAL_PMIX_CONDITION_STATIC_INIT, - .active = false - } -}; +opal_pmix_base_t opal_pmix_base = {.evbase = NULL, + .timeout = 0, + .initialized = 0, + .lock = {.mutex = OPAL_MUTEX_STATIC_INIT, + .cond = OPAL_PMIX_CONDITION_STATIC_INIT, + .active = false}}; static int opal_pmix_base_frame_register(mca_base_register_flag_t flags) { opal_pmix_base_async_modex = false; - (void) mca_base_var_register("opal", "pmix", "base", "async_modex", "Use asynchronous modex mode", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_pmix_base_async_modex); + (void) mca_base_var_register("opal", "pmix", "base", "async_modex", + "Use asynchronous modex mode", MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_pmix_base_async_modex); opal_pmix_collect_all_data = true; - (void) mca_base_var_register("opal", "pmix", "base", "collect_data", "Collect all data during modex", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, &opal_pmix_collect_all_data); + (void) mca_base_var_register("opal", "pmix", "base", "collect_data", + "Collect all data during modex", MCA_BASE_VAR_TYPE_BOOL, NULL, 0, + 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &opal_pmix_collect_all_data); opal_pmix_base.timeout = -1; (void) mca_base_var_register("opal", "pmix", "base", "exchange_timeout", @@ -84,8 +80,6 @@ static int opal_pmix_base_frame_open(mca_base_open_flag_t flags) return rc; } -MCA_BASE_FRAMEWORK_DECLARE(opal, pmix, "OPAL PMI Client Framework", - opal_pmix_base_frame_register, - opal_pmix_base_frame_open, - opal_pmix_base_frame_close, +MCA_BASE_FRAMEWORK_DECLARE(opal, pmix, "OPAL PMI Client Framework", opal_pmix_base_frame_register, + opal_pmix_base_frame_open, opal_pmix_base_frame_close, mca_pmix_base_static_components, 0); diff --git a/opal/mca/pmix/base/static-components.h b/opal/mca/pmix/base/static-components.h index a4e4303659b..f2be97a0c2b 100644 --- a/opal/mca/pmix/base/static-components.h +++ b/opal/mca/pmix/base/static-components.h @@ -9,10 +9,8 @@ extern const mca_base_component_t mca_pmix_pmix4x_component; const mca_base_component_t *mca_pmix_base_static_components[] = { - NULL -}; + NULL}; #if defined(c_plusplus) || defined(__cplusplus) } #endif - diff --git a/opal/mca/pmix/pmix-internal.h b/opal/mca/pmix/pmix-internal.h index 23aa731ec78..9def6485266 100644 --- a/opal/mca/pmix/pmix-internal.h +++ b/opal/mca/pmix/pmix-internal.h @@ -32,18 +32,17 @@ #include "opal/types.h" #ifdef HAVE_SYS_UN_H -#include +# include #endif +#include "opal/hash_string.h" #include "opal/mca/mca.h" -#include "opal/util/event.h" #include "opal/mca/threads/threads.h" #include "opal/util/error.h" -#include "opal/hash_string.h" +#include "opal/util/event.h" #include - BEGIN_C_DECLS typedef uint32_t opal_jobid_t; @@ -54,9 +53,9 @@ typedef struct { } opal_process_name_t; #define OPAL_SIZEOF_PROCESS_NAME_T 8 -#define OPAL_EQUAL 0 -#define OPAL_VALUE1_GREATER 1 -#define OPAL_VALUE2_GREATER -1 +#define OPAL_EQUAL 0 +#define OPAL_VALUE1_GREATER 1 +#define OPAL_VALUE2_GREATER -1 /* provide access to the framework verbose output without * exposing the entire base */ @@ -89,7 +88,6 @@ typedef struct { } opal_proclist_t; OBJ_CLASS_DECLARATION(opal_proclist_t); - typedef opal_cond_t opal_pmix_condition_t; typedef struct { @@ -100,127 +98,120 @@ typedef struct { char *msg; } opal_pmix_lock_t; -#define opal_pmix_condition_wait(a,b) opal_cond_wait(a, b) +#define opal_pmix_condition_wait(a, b) opal_cond_wait(a, b) #define opal_pmix_condition_broadcast(a) opal_cond_broadcast(a) -#define OPAL_PMIX_CONSTRUCT_LOCK(l) \ - do { \ - OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \ - opal_cond_init(&(l)->cond); \ - (l)->active = true; \ - (l)->status = 0; \ - (l)->msg = NULL; \ - OPAL_POST_OBJECT((l)); \ - } while(0) - -#define OPAL_PMIX_DESTRUCT_LOCK(l) \ - do { \ - OPAL_ACQUIRE_OBJECT((l)); \ - OBJ_DESTRUCT(&(l)->mutex); \ - opal_cond_destroy(&(l)->cond); \ - if (NULL != (l)->msg) { \ - free((l)->msg); \ - } \ - } while(0) - +#define OPAL_PMIX_CONSTRUCT_LOCK(l) \ + do { \ + OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \ + opal_cond_init(&(l)->cond); \ + (l)->active = true; \ + (l)->status = 0; \ + (l)->msg = NULL; \ + OPAL_POST_OBJECT((l)); \ + } while (0) + +#define OPAL_PMIX_DESTRUCT_LOCK(l) \ + do { \ + OPAL_ACQUIRE_OBJECT((l)); \ + OBJ_DESTRUCT(&(l)->mutex); \ + opal_cond_destroy(&(l)->cond); \ + if (NULL != (l)->msg) { \ + free((l)->msg); \ + } \ + } while (0) #if OPAL_ENABLE_DEBUG -#define OPAL_PMIX_ACQUIRE_THREAD(lck) \ - do { \ - opal_mutex_lock(&(lck)->mutex); \ - if (opal_debug_threads) { \ - opal_output(0, "Waiting for thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - while ((lck)->active) { \ - opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ - } \ - if (opal_debug_threads) { \ - opal_output(0, "Thread obtained %s:%d", \ - __FILE__, __LINE__); \ - } \ - (lck)->active = true; \ - } while(0) +# define OPAL_PMIX_ACQUIRE_THREAD(lck) \ + do { \ + opal_mutex_lock(&(lck)->mutex); \ + if (opal_debug_threads) { \ + opal_output(0, "Waiting for thread %s:%d", __FILE__, __LINE__); \ + } \ + while ((lck)->active) { \ + opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ + } \ + if (opal_debug_threads) { \ + opal_output(0, "Thread obtained %s:%d", __FILE__, __LINE__); \ + } \ + (lck)->active = true; \ + } while (0) #else -#define OPAL_PMIX_ACQUIRE_THREAD(lck) \ - do { \ - opal_mutex_lock(&(lck)->mutex); \ - while ((lck)->active) { \ - opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ - } \ - (lck)->active = true; \ - } while(0) +# define OPAL_PMIX_ACQUIRE_THREAD(lck) \ + do { \ + opal_mutex_lock(&(lck)->mutex); \ + while ((lck)->active) { \ + opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ + } \ + (lck)->active = true; \ + } while (0) #endif - #if OPAL_ENABLE_DEBUG -#define OPAL_PMIX_WAIT_THREAD(lck) \ - do { \ - opal_mutex_lock(&(lck)->mutex); \ - if (opal_debug_threads) { \ - opal_output(0, "Waiting for thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - while ((lck)->active) { \ - opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ - } \ - if (opal_debug_threads) { \ - opal_output(0, "Thread obtained %s:%d", \ - __FILE__, __LINE__); \ - } \ - OPAL_ACQUIRE_OBJECT(&lck); \ - opal_mutex_unlock(&(lck)->mutex); \ - } while(0) +# define OPAL_PMIX_WAIT_THREAD(lck) \ + do { \ + opal_mutex_lock(&(lck)->mutex); \ + if (opal_debug_threads) { \ + opal_output(0, "Waiting for thread %s:%d", __FILE__, __LINE__); \ + } \ + while ((lck)->active) { \ + opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ + } \ + if (opal_debug_threads) { \ + opal_output(0, "Thread obtained %s:%d", __FILE__, __LINE__); \ + } \ + OPAL_ACQUIRE_OBJECT(&lck); \ + opal_mutex_unlock(&(lck)->mutex); \ + } while (0) #else -#define OPAL_PMIX_WAIT_THREAD(lck) \ - do { \ - opal_mutex_lock(&(lck)->mutex); \ - while ((lck)->active) { \ - opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ - } \ - OPAL_ACQUIRE_OBJECT(lck); \ - opal_mutex_unlock(&(lck)->mutex); \ - } while(0) +# define OPAL_PMIX_WAIT_THREAD(lck) \ + do { \ + opal_mutex_lock(&(lck)->mutex); \ + while ((lck)->active) { \ + opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex); \ + } \ + OPAL_ACQUIRE_OBJECT(lck); \ + opal_mutex_unlock(&(lck)->mutex); \ + } while (0) #endif - #if OPAL_ENABLE_DEBUG -#define OPAL_PMIX_RELEASE_THREAD(lck) \ - do { \ - if (opal_debug_threads) { \ - opal_output(0, "Releasing thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - (lck)->active = false; \ - opal_pmix_condition_broadcast(&(lck)->cond); \ - opal_mutex_unlock(&(lck)->mutex); \ - } while(0) +# define OPAL_PMIX_RELEASE_THREAD(lck) \ + do { \ + if (opal_debug_threads) { \ + opal_output(0, "Releasing thread %s:%d", __FILE__, __LINE__); \ + } \ + (lck)->active = false; \ + opal_pmix_condition_broadcast(&(lck)->cond); \ + opal_mutex_unlock(&(lck)->mutex); \ + } while (0) #else -#define OPAL_PMIX_RELEASE_THREAD(lck) \ - do { \ - assert(0 != opal_mutex_trylock(&(lck)->mutex)); \ - (lck)->active = false; \ - opal_pmix_condition_broadcast(&(lck)->cond); \ - opal_mutex_unlock(&(lck)->mutex); \ - } while(0) +# define OPAL_PMIX_RELEASE_THREAD(lck) \ + do { \ + assert(0 != opal_mutex_trylock(&(lck)->mutex)); \ + (lck)->active = false; \ + opal_pmix_condition_broadcast(&(lck)->cond); \ + opal_mutex_unlock(&(lck)->mutex); \ + } while (0) #endif -#define OPAL_PMIX_WAKEUP_THREAD(lck) \ - do { \ - opal_mutex_lock(&(lck)->mutex); \ - (lck)->active = false; \ - OPAL_POST_OBJECT(lck); \ - opal_pmix_condition_broadcast(&(lck)->cond); \ - opal_mutex_unlock(&(lck)->mutex); \ - } while(0) +#define OPAL_PMIX_WAKEUP_THREAD(lck) \ + do { \ + opal_mutex_lock(&(lck)->mutex); \ + (lck)->active = false; \ + OPAL_POST_OBJECT(lck); \ + opal_pmix_condition_broadcast(&(lck)->cond); \ + opal_mutex_unlock(&(lck)->mutex); \ + } while (0) /* * Count the fash for the the external RM */ -#define OPAL_HASH_JOBID( str, hash ){ \ - OPAL_HASH_STR( str, hash ); \ - hash &= ~(0x8000); \ -} +#define OPAL_HASH_JOBID(str, hash) \ + { \ + OPAL_HASH_STR(str, hash); \ + hash &= ~(0x8000); \ + } /** * Provide a simplified macro for sending data via modex @@ -232,12 +223,12 @@ typedef struct { * d - pointer to the data object being posted * t - the type of the data */ -#define OPAL_MODEX_SEND_VALUE(r, sc, s, d, t) \ - do { \ - pmix_value_t _kv; \ - PMIX_VALUE_LOAD(&_kv, (d), (t)); \ - (r) = PMIx_Put((sc), (s), &(_kv)); \ - } while(0); +#define OPAL_MODEX_SEND_VALUE(r, sc, s, d, t) \ + do { \ + pmix_value_t _kv; \ + PMIX_VALUE_LOAD(&_kv, (d), (t)); \ + (r) = PMIx_Put((sc), (s), &(_kv)); \ + } while (0); /** * Provide a simplified macro for sending data via modex @@ -249,14 +240,14 @@ typedef struct { * d - the data object being posted * sz - the number of bytes in the data object */ -#define OPAL_MODEX_SEND_STRING(r, sc, s, d, sz) \ - do { \ - pmix_value_t _kv; \ - _kv.type = PMIX_BYTE_OBJECT; \ - _kv.data.bo.bytes = (char*)(d); \ - _kv.data.bo.size = (sz); \ - (r) = PMIx_Put(sc, (s), &(_kv)); \ - } while(0); +#define OPAL_MODEX_SEND_STRING(r, sc, s, d, sz) \ + do { \ + pmix_value_t _kv; \ + _kv.type = PMIX_BYTE_OBJECT; \ + _kv.data.bo.bytes = (char *) (d); \ + _kv.data.bo.size = (sz); \ + (r) = PMIx_Put(sc, (s), &(_kv)); \ + } while (0); /** * Provide a simplified macro for sending data via modex @@ -268,13 +259,13 @@ typedef struct { * d - the data object being posted * sz - the number of bytes in the data object */ -#define OPAL_MODEX_SEND(r, sc, s, d, sz) \ - do { \ - char *_key; \ - _key = mca_base_component_to_string((s)); \ - OPAL_MODEX_SEND_STRING((r), (sc), _key, (d), (sz)); \ - free(_key); \ - } while(0); +#define OPAL_MODEX_SEND(r, sc, s, d, sz) \ + do { \ + char *_key; \ + _key = mca_base_component_to_string((s)); \ + OPAL_MODEX_SEND_STRING((r), (sc), _key, (d), (sz)); \ + free(_key); \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -289,32 +280,31 @@ typedef struct { * is to be returned * t - the expected data type */ -#define OPAL_MODEX_RECV_VALUE_OPTIONAL(r, s, p, d, t) \ - do { \ - pmix_proc_t _proc; \ - pmix_value_t *_kv = NULL; \ - pmix_info_t _info; \ - size_t _sz; \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV VALUE OPTIONAL FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), (s))); \ - OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ - PMIX_INFO_LOAD(&_info, PMIX_OPTIONAL, NULL, PMIX_BOOL); \ - (r) = PMIx_Get(&(_proc), (s), &(_info), 1, &(_kv)); \ - PMIX_INFO_DESTRUCT(&_info); \ - if (NULL == _kv) { \ - (r) = PMIX_ERR_NOT_FOUND; \ - } else if (_kv->type != (t)) { \ - (r) = PMIX_ERR_TYPE_MISMATCH; \ - } else if (PMIX_SUCCESS == (r)) { \ - PMIX_VALUE_UNLOAD((r), _kv, (void**)(d), &_sz); \ - } \ - if (NULL != _kv) { \ - PMIX_VALUE_RELEASE(_kv); \ - } \ - } while(0); +#define OPAL_MODEX_RECV_VALUE_OPTIONAL(r, s, p, d, t) \ + do { \ + pmix_proc_t _proc; \ + pmix_value_t *_kv = NULL; \ + pmix_info_t _info; \ + size_t _sz; \ + OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ + "%s[%s:%d] MODEX RECV VALUE OPTIONAL FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + OPAL_NAME_PRINT(*(p)), (s))); \ + OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ + PMIX_INFO_LOAD(&_info, PMIX_OPTIONAL, NULL, PMIX_BOOL); \ + (r) = PMIx_Get(&(_proc), (s), &(_info), 1, &(_kv)); \ + PMIX_INFO_DESTRUCT(&_info); \ + if (NULL == _kv) { \ + (r) = PMIX_ERR_NOT_FOUND; \ + } else if (_kv->type != (t)) { \ + (r) = PMIX_ERR_TYPE_MISMATCH; \ + } else if (PMIX_SUCCESS == (r)) { \ + PMIX_VALUE_UNLOAD((r), _kv, (void **) (d), &_sz); \ + } \ + if (NULL != _kv) { \ + PMIX_VALUE_RELEASE(_kv); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -338,10 +328,9 @@ typedef struct { pmix_info_t _info; \ size_t _sz; \ OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV VALUE IMMEDIATE FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), (s))); \ + "%s[%s:%d] MODEX RECV VALUE IMMEDIATE FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + OPAL_NAME_PRINT(*(p)), (s))); \ OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ PMIX_INFO_LOAD(&_info, PMIX_IMMEDIATE, NULL, PMIX_BOOL); \ (r) = PMIx_Get(&(_proc), (s), &(_info), 1, &(_kv)); \ @@ -351,12 +340,12 @@ typedef struct { } else if (_kv->type != (t)) { \ (r) = PMIX_ERR_TYPE_MISMATCH; \ } else if (PMIX_SUCCESS == (r)) { \ - PMIX_VALUE_UNLOAD((r), _kv, (void**)(d), &_sz); \ + PMIX_VALUE_UNLOAD((r), _kv, (void **) (d), &_sz); \ } \ if (NULL != _kv) { \ PMIX_VALUE_RELEASE(_kv); \ } \ - } while(0); + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -370,29 +359,27 @@ typedef struct { * is to be returned * t - the expected data type */ -#define OPAL_MODEX_RECV_VALUE(r, s, p, d, t) \ - do { \ - pmix_proc_t _proc; \ - pmix_value_t *_kv = NULL; \ - size_t _sz; \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV VALUE FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), (s))); \ - OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ - (r) = PMIx_Get(&(_proc), (s), NULL, 0, &(_kv)); \ - if (NULL == _kv) { \ - (r) = PMIX_ERR_NOT_FOUND; \ - } else if (_kv->type != (t)) { \ - (r) = PMIX_ERR_TYPE_MISMATCH; \ - } else if (PMIX_SUCCESS == (r)) { \ - PMIX_VALUE_UNLOAD((r), _kv, (void**)(d), &_sz); \ - } \ - if (NULL != _kv) { \ - PMIX_VALUE_RELEASE(_kv); \ - } \ - } while(0); +#define OPAL_MODEX_RECV_VALUE(r, s, p, d, t) \ + do { \ + pmix_proc_t _proc; \ + pmix_value_t *_kv = NULL; \ + size_t _sz; \ + OPAL_OUTPUT_VERBOSE( \ + (1, opal_pmix_verbose_output, "%s[%s:%d] MODEX RECV VALUE FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, OPAL_NAME_PRINT(*(p)), (s))); \ + OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ + (r) = PMIx_Get(&(_proc), (s), NULL, 0, &(_kv)); \ + if (NULL == _kv) { \ + (r) = PMIX_ERR_NOT_FOUND; \ + } else if (_kv->type != (t)) { \ + (r) = PMIX_ERR_TYPE_MISMATCH; \ + } else if (PMIX_SUCCESS == (r)) { \ + PMIX_VALUE_UNLOAD((r), _kv, (void **) (d), &_sz); \ + } \ + if (NULL != _kv) { \ + PMIX_VALUE_RELEASE(_kv); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -407,32 +394,31 @@ typedef struct { * sz - pointer to a location wherein the number of bytes * in the data object can be returned (size_t) */ -#define OPAL_MODEX_RECV_STRING_OPTIONAL(r, s, p, d, sz) \ - do { \ - pmix_proc_t _proc; \ - pmix_value_t *_kv = NULL; \ - pmix_info_t _info; \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV STRING OPTIONAL FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), (s))); \ - *(d) = NULL; \ - *(sz) = 0; \ - OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ - PMIX_INFO_LOAD(&_info, PMIX_OPTIONAL, NULL, PMIX_BOOL); \ - (r) = PMIx_Get(&(_proc), (s), &(_info), 1, &(_kv)); \ - if (NULL == _kv) { \ - (r) = PMIX_ERR_NOT_FOUND; \ - } else if (PMIX_SUCCESS == (r)) { \ - *(d) = (uint8_t*)_kv->data.bo.bytes; \ - *(sz) = _kv->data.bo.size; \ - _kv->data.bo.bytes = NULL; /* protect the data */ \ - } \ - if (NULL != _kv) { \ - PMIX_VALUE_RELEASE(_kv); \ - } \ - } while(0); +#define OPAL_MODEX_RECV_STRING_OPTIONAL(r, s, p, d, sz) \ + do { \ + pmix_proc_t _proc; \ + pmix_value_t *_kv = NULL; \ + pmix_info_t _info; \ + OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ + "%s[%s:%d] MODEX RECV STRING OPTIONAL FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + OPAL_NAME_PRINT(*(p)), (s))); \ + *(d) = NULL; \ + *(sz) = 0; \ + OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ + PMIX_INFO_LOAD(&_info, PMIX_OPTIONAL, NULL, PMIX_BOOL); \ + (r) = PMIx_Get(&(_proc), (s), &(_info), 1, &(_kv)); \ + if (NULL == _kv) { \ + (r) = PMIX_ERR_NOT_FOUND; \ + } else if (PMIX_SUCCESS == (r)) { \ + *(d) = (uint8_t *) _kv->data.bo.bytes; \ + *(sz) = _kv->data.bo.size; \ + _kv->data.bo.bytes = NULL; /* protect the data */ \ + } \ + if (NULL != _kv) { \ + PMIX_VALUE_RELEASE(_kv); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -447,33 +433,31 @@ typedef struct { * sz - pointer to a location wherein the number of bytes * in the data object can be returned (size_t) */ -#define OPAL_MODEX_RECV_STRING_IMMEDIATE(r, s, p, d, sz) \ - do { \ - pmix_proc_t _proc; \ - pmix_value_t *_kv = NULL; \ - pmix_info_t _info; \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV STRING FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), (s))); \ - *(d) = NULL; \ - *(sz) = 0; \ - OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ - PMIX_INFO_LOAD(&_info, PMIX_IMMEDIATE, NULL, PMIX_BOOL); \ - (r) = PMIx_Get(&(_proc), (s), &_info, 1, &(_kv)); \ - PMIX_INFO_DESTRUCT(&_info); \ - if (NULL == _kv) { \ - (r) = PMIX_ERR_NOT_FOUND; \ - } else if (PMIX_SUCCESS == (r)) { \ - *(d) = (uint8_t*)_kv->data.bo.bytes; \ - *(sz) = _kv->data.bo.size; \ - _kv->data.bo.bytes = NULL; /* protect the data */ \ - } \ - if (NULL != _kv) { \ - PMIX_VALUE_RELEASE(_kv); \ - } \ - } while(0); +#define OPAL_MODEX_RECV_STRING_IMMEDIATE(r, s, p, d, sz) \ + do { \ + pmix_proc_t _proc; \ + pmix_value_t *_kv = NULL; \ + pmix_info_t _info; \ + OPAL_OUTPUT_VERBOSE( \ + (1, opal_pmix_verbose_output, "%s[%s:%d] MODEX RECV STRING FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, OPAL_NAME_PRINT(*(p)), (s))); \ + *(d) = NULL; \ + *(sz) = 0; \ + OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ + PMIX_INFO_LOAD(&_info, PMIX_IMMEDIATE, NULL, PMIX_BOOL); \ + (r) = PMIx_Get(&(_proc), (s), &_info, 1, &(_kv)); \ + PMIX_INFO_DESTRUCT(&_info); \ + if (NULL == _kv) { \ + (r) = PMIX_ERR_NOT_FOUND; \ + } else if (PMIX_SUCCESS == (r)) { \ + *(d) = (uint8_t *) _kv->data.bo.bytes; \ + *(sz) = _kv->data.bo.size; \ + _kv->data.bo.bytes = NULL; /* protect the data */ \ + } \ + if (NULL != _kv) { \ + PMIX_VALUE_RELEASE(_kv); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -488,30 +472,28 @@ typedef struct { * sz - pointer to a location wherein the number of bytes * in the data object can be returned (size_t) */ -#define OPAL_MODEX_RECV_STRING(r, s, p, d, sz) \ - do { \ - pmix_proc_t _proc; \ - pmix_value_t *_kv = NULL; \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV STRING FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), (s))); \ - *(d) = NULL; \ - *(sz) = 0; \ - OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ - (r) = PMIx_Get(&(_proc), (s), NULL, 0, &(_kv)); \ - if (NULL == _kv) { \ - (r) = PMIX_ERR_NOT_FOUND; \ - } else if (PMIX_SUCCESS == (r)) { \ - *(d) = (uint8_t*)_kv->data.bo.bytes; \ - *(sz) = _kv->data.bo.size; \ - _kv->data.bo.bytes = NULL; /* protect the data */ \ - } \ - if (NULL != _kv) { \ - PMIX_VALUE_RELEASE(_kv); \ - } \ - } while(0); +#define OPAL_MODEX_RECV_STRING(r, s, p, d, sz) \ + do { \ + pmix_proc_t _proc; \ + pmix_value_t *_kv = NULL; \ + OPAL_OUTPUT_VERBOSE( \ + (1, opal_pmix_verbose_output, "%s[%s:%d] MODEX RECV STRING FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, OPAL_NAME_PRINT(*(p)), (s))); \ + *(d) = NULL; \ + *(sz) = 0; \ + OPAL_PMIX_CONVERT_NAME(&_proc, (p)); \ + (r) = PMIx_Get(&(_proc), (s), NULL, 0, &(_kv)); \ + if (NULL == _kv) { \ + (r) = PMIX_ERR_NOT_FOUND; \ + } else if (PMIX_SUCCESS == (r)) { \ + *(d) = (uint8_t *) _kv->data.bo.bytes; \ + *(sz) = _kv->data.bo.size; \ + _kv->data.bo.bytes = NULL; /* protect the data */ \ + } \ + if (NULL != _kv) { \ + PMIX_VALUE_RELEASE(_kv); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -526,24 +508,22 @@ typedef struct { * sz - pointer to a location wherein the number of bytes * in the data object can be returned (size_t) */ -#define OPAL_MODEX_RECV_OPTIONAL(r, s, p, d, sz) \ - do { \ - char *_key; \ - _key = mca_base_component_to_string((s)); \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), _key)); \ - if (NULL == _key) { \ - OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); \ - (r) = OPAL_ERR_OUT_OF_RESOURCE; \ - } else { \ - OPAL_MODEX_RECV_STRING_OPTIONAL((r), _key, (p), (d), (sz)); \ - free(_key); \ - } \ - } while(0); - +#define OPAL_MODEX_RECV_OPTIONAL(r, s, p, d, sz) \ + do { \ + char *_key; \ + _key = mca_base_component_to_string((s)); \ + OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ + "%s[%s:%d] MODEX RECV FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + OPAL_NAME_PRINT(*(p)), _key)); \ + if (NULL == _key) { \ + OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); \ + (r) = OPAL_ERR_OUT_OF_RESOURCE; \ + } else { \ + OPAL_MODEX_RECV_STRING_OPTIONAL((r), _key, (p), (d), (sz)); \ + free(_key); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -558,24 +538,22 @@ typedef struct { * sz - pointer to a location wherein the number of bytes * in the data object can be returned (size_t) */ -#define OPAL_MODEX_RECV_IMMEDIATE(r, s, p, d, sz) \ - do { \ - char *_key; \ - _key = mca_base_component_to_string((s)); \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), _key)); \ - if (NULL == _key) { \ - OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); \ - (r) = OPAL_ERR_OUT_OF_RESOURCE; \ - } else { \ - OPAL_MODEX_RECV_STRING_IMMEDIATE((r), _key, (p), (d), (sz)); \ - free(_key); \ - } \ - } while(0); - +#define OPAL_MODEX_RECV_IMMEDIATE(r, s, p, d, sz) \ + do { \ + char *_key; \ + _key = mca_base_component_to_string((s)); \ + OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ + "%s[%s:%d] MODEX RECV FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + OPAL_NAME_PRINT(*(p)), _key)); \ + if (NULL == _key) { \ + OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); \ + (r) = OPAL_ERR_OUT_OF_RESOURCE; \ + } else { \ + OPAL_MODEX_RECV_STRING_IMMEDIATE((r), _key, (p), (d), (sz)); \ + free(_key); \ + } \ + } while (0); /** * Provide a simplified macro for retrieving modex data @@ -590,29 +568,27 @@ typedef struct { * sz - pointer to a location wherein the number of bytes * in the data object can be returned (size_t) */ -#define OPAL_MODEX_RECV(r, s, p, d, sz) \ - do { \ - char *_key; \ - _key = mca_base_component_to_string((s)); \ - OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ - "%s[%s:%d] MODEX RECV FOR PROC %s KEY %s", \ - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), \ - __FILE__, __LINE__, \ - OPAL_NAME_PRINT(*(p)), _key)); \ - if (NULL == _key) { \ - OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); \ - (r) = OPAL_ERR_OUT_OF_RESOURCE; \ - } else { \ - OPAL_MODEX_RECV_STRING((r), _key, (p), (d), (sz)); \ - free(_key); \ - } \ - } while(0); - - -#define PMIX_ERROR_LOG(r) \ +#define OPAL_MODEX_RECV(r, s, p, d, sz) \ + do { \ + char *_key; \ + _key = mca_base_component_to_string((s)); \ + OPAL_OUTPUT_VERBOSE((1, opal_pmix_verbose_output, \ + "%s[%s:%d] MODEX RECV FOR PROC %s KEY %s", \ + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), __FILE__, __LINE__, \ + OPAL_NAME_PRINT(*(p)), _key)); \ + if (NULL == _key) { \ + OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); \ + (r) = OPAL_ERR_OUT_OF_RESOURCE; \ + } else { \ + OPAL_MODEX_RECV_STRING((r), _key, (p), (d), (sz)); \ + free(_key); \ + } \ + } while (0); + +#define PMIX_ERROR_LOG(r) \ opal_output(0, "[%s:%d] PMIx Error: %s", __FILE__, __LINE__, PMIx_Error_string((r))) -#define OPAL_PMIX_SHOW_HELP "opal.show.help" +#define OPAL_PMIX_SHOW_HELP "opal.show.help" /* some helper functions */ OPAL_DECLSPEC pmix_proc_state_t opal_pmix_convert_state(int state); @@ -624,121 +600,115 @@ OPAL_DECLSPEC int opal_pmix_convert_nspace(opal_jobid_t *jobid, pmix_nspace_t ns OPAL_DECLSPEC void opal_pmix_setup_nspace_tracker(void); OPAL_DECLSPEC void opal_pmix_finalize_nspace_tracker(void); -#define OPAL_SCHEMA_DELIMITER_CHAR '.' -#define OPAL_SCHEMA_WILDCARD_CHAR '*' -#define OPAL_SCHEMA_WILDCARD_STRING "*" -#define OPAL_SCHEMA_INVALID_CHAR '$' -#define OPAL_SCHEMA_INVALID_STRING "$" +#define OPAL_SCHEMA_DELIMITER_CHAR '.' +#define OPAL_SCHEMA_WILDCARD_CHAR '*' +#define OPAL_SCHEMA_WILDCARD_STRING "*" +#define OPAL_SCHEMA_INVALID_CHAR '$' +#define OPAL_SCHEMA_INVALID_STRING "$" /* convert jobid to nspace */ -#define OPAL_PMIX_CONVERT_JOBID(n, j) \ - opal_pmix_convert_jobid((n), (j)) +#define OPAL_PMIX_CONVERT_JOBID(n, j) opal_pmix_convert_jobid((n), (j)) /* convert vpid to rank */ -#define OPAL_PMIX_CONVERT_VPID(r, v) \ - do { \ - if (OPAL_VPID_WILDCARD == (v)) { \ - (r) = PMIX_RANK_WILDCARD; \ - } else if (OPAL_VPID_INVALID == (v)) { \ - (r) = PMIX_RANK_INVALID; \ - } else { \ - (r) = (v); \ - } \ - } while(0) +#define OPAL_PMIX_CONVERT_VPID(r, v) \ + do { \ + if (OPAL_VPID_WILDCARD == (v)) { \ + (r) = PMIX_RANK_WILDCARD; \ + } else if (OPAL_VPID_INVALID == (v)) { \ + (r) = PMIX_RANK_INVALID; \ + } else { \ + (r) = (v); \ + } \ + } while (0) /* convert opal_process_name_t to pmix_proc_t */ -#define OPAL_PMIX_CONVERT_NAME(p, n) \ - do { \ - OPAL_PMIX_CONVERT_JOBID((p)->nspace, (n)->jobid); \ - OPAL_PMIX_CONVERT_VPID((p)->rank, (n)->vpid); \ - } while(0) - +#define OPAL_PMIX_CONVERT_NAME(p, n) \ + do { \ + OPAL_PMIX_CONVERT_JOBID((p)->nspace, (n)->jobid); \ + OPAL_PMIX_CONVERT_VPID((p)->rank, (n)->vpid); \ + } while (0) /* convert nspace to jobid */ -#define OPAL_PMIX_CONVERT_NSPACE(r, j, n) \ - (r) = opal_pmix_convert_nspace((j), (n)) +#define OPAL_PMIX_CONVERT_NSPACE(r, j, n) (r) = opal_pmix_convert_nspace((j), (n)) /* convert pmix rank to opal vpid */ -#define OPAL_PMIX_CONVERT_RANK(v, r) \ - do { \ - if (PMIX_RANK_WILDCARD == (r)) { \ - (v) = OPAL_VPID_WILDCARD; \ - } else if (PMIX_RANK_INVALID == (r)) { \ - (v) = OPAL_VPID_INVALID; \ - } else { \ - (v) = (r); \ - } \ - } while(0) +#define OPAL_PMIX_CONVERT_RANK(v, r) \ + do { \ + if (PMIX_RANK_WILDCARD == (r)) { \ + (v) = OPAL_VPID_WILDCARD; \ + } else if (PMIX_RANK_INVALID == (r)) { \ + (v) = OPAL_VPID_INVALID; \ + } else { \ + (v) = (r); \ + } \ + } while (0) /* convert pmix_proc_t to opal_process_name_t */ -#define OPAL_PMIX_CONVERT_PROCT(r, n, p) \ - do { \ - OPAL_PMIX_CONVERT_NSPACE((r), &(n)->jobid, (p)->nspace); \ - if (OPAL_SUCCESS == (r)) { \ - OPAL_PMIX_CONVERT_RANK((n)->vpid, (p)->rank); \ - } \ - } while(0) +#define OPAL_PMIX_CONVERT_PROCT(r, n, p) \ + do { \ + OPAL_PMIX_CONVERT_NSPACE((r), &(n)->jobid, (p)->nspace); \ + if (OPAL_SUCCESS == (r)) { \ + OPAL_PMIX_CONVERT_RANK((n)->vpid, (p)->rank); \ + } \ + } while (0) #define OPAL_PMIX_CONVERT_PROCT_TO_STRING(s, p) \ do { \ if (PMIX_RANK_WILDCARD == (p)->rank) { \ - (void)opal_asprintf((s), "%s.*", (p)->nspace); \ + (void) opal_asprintf((s), "%s.*", (p)->nspace); \ } else if (PMIX_RANK_INVALID == (p)->rank) { \ - (void)opal_asprintf((s), "%s.$", (p)->nspace); \ + (void) opal_asprintf((s), "%s.$", (p)->nspace); \ } else { \ - (void)opal_asprintf((s), "%s.%u", (p)->nspace, (p)->rank); \ + (void) opal_asprintf((s), "%s.%u", (p)->nspace, (p)->rank); \ } \ - } while(0) - -#define OPAL_PMIX_CONVERT_STRING_TO_PROCT(p, s) \ - do { \ - char *_ptr; \ - _ptr = strrchr((s), '.'); \ - *_ptr = '\0'; \ - _ptr++; \ - PMIX_LOAD_NSPACE((p)->nspace, (s)); \ - if ('*' == *_ptr) { \ - (p)->rank = PMIX_RANK_WILDCARD; \ - } else if ('$' == *_ptr) { \ - (p)->rank = PMIX_RANK_INVALID; \ - } else { \ - (p)->rank = strtoul(_ptr, NULL, 10); \ - } \ - } while(0) - -OPAL_DECLSPEC int opal_pmix_register_cleanup(char *path, - bool directory, - bool ignore, + } while (0) + +#define OPAL_PMIX_CONVERT_STRING_TO_PROCT(p, s) \ + do { \ + char *_ptr; \ + _ptr = strrchr((s), '.'); \ + *_ptr = '\0'; \ + _ptr++; \ + PMIX_LOAD_NSPACE((p)->nspace, (s)); \ + if ('*' == *_ptr) { \ + (p)->rank = PMIX_RANK_WILDCARD; \ + } else if ('$' == *_ptr) { \ + (p)->rank = PMIX_RANK_INVALID; \ + } else { \ + (p)->rank = strtoul(_ptr, NULL, 10); \ + } \ + } while (0) + +OPAL_DECLSPEC int opal_pmix_register_cleanup(char *path, bool directory, bool ignore, bool jobscope); /* protect against early versions of PMIx */ #if PMIX_VERSION_MAJOR == 3 -#if PMIX_VERSION_MINOR == 0 -#if PMIX_VERSION_RELEASE == 0 -#define PMIX_NUMERIC_VERSION 0x00030000 -#define PMIX_OPERATION_SUCCEEDED (PMIX_ERR_OP_BASE - 27) -#elif PMIX_VERSION_RELEASE == 2 -#undef PMIX_NUMERIC_VERSION -#define PMIX_NUMERIC_VERSION 0x00030002 -#endif -#define PMIX_LOAD_KEY(a, b) \ - do { \ - memset((a), 0, PMIX_MAX_KEYLEN+1); \ - pmix_strncpy((a), (b), PMIX_MAX_KEYLEN); \ - }while(0) -#if PMIX_VERSION_RELEASE < 2 -#define PMIX_CHECK_KEY(a, b) \ - (0 == strncmp((a)->key, (b), PMIX_MAX_KEYLEN)) -#endif -#elif PMIX_VERSION_MINOR == 1 -#if PMIX_VERSION_RELEASE == 1 -#undef PMIX_NUMERIC_VERSION -#define PMIX_NUMERIC_VERSION 0x00030101 -#elif PMIX_VERSION_RELEASE == 2 -#undef PMIX_NUMERIC_VERSION -#define PMIX_NUMERIC_VERSION 0x00030102 -#endif -#endif +# if PMIX_VERSION_MINOR == 0 +# if PMIX_VERSION_RELEASE == 0 +# define PMIX_NUMERIC_VERSION 0x00030000 +# define PMIX_OPERATION_SUCCEEDED (PMIX_ERR_OP_BASE - 27) +# elif PMIX_VERSION_RELEASE == 2 +# undef PMIX_NUMERIC_VERSION +# define PMIX_NUMERIC_VERSION 0x00030002 +# endif +# define PMIX_LOAD_KEY(a, b) \ + do { \ + memset((a), 0, PMIX_MAX_KEYLEN + 1); \ + pmix_strncpy((a), (b), PMIX_MAX_KEYLEN); \ + } while (0) +# if PMIX_VERSION_RELEASE < 2 +# define PMIX_CHECK_KEY(a, b) (0 == strncmp((a)->key, (b), PMIX_MAX_KEYLEN)) +# endif +# elif PMIX_VERSION_MINOR == 1 +# if PMIX_VERSION_RELEASE == 1 +# undef PMIX_NUMERIC_VERSION +# define PMIX_NUMERIC_VERSION 0x00030101 +# elif PMIX_VERSION_RELEASE == 2 +# undef PMIX_NUMERIC_VERSION +# define PMIX_NUMERIC_VERSION 0x00030102 +# endif +# endif #endif /** @@ -760,9 +730,7 @@ typedef struct opal_pmix_base_component_2_0_0_t opal_pmix_component_t; /** * Macro for use in components that are of type hwloc */ -#define OPAL_PMIX_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("pmix", 2, 0, 0) - +#define OPAL_PMIX_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("pmix", 2, 0, 0) END_C_DECLS diff --git a/opal/mca/rcache/base/base.h b/opal/mca/rcache/base/base.h index 37526814a46..1475afd10e3 100644 --- a/opal/mca/rcache/base/base.h +++ b/opal/mca/rcache/base/base.h @@ -28,16 +28,17 @@ #include "opal/class/opal_list.h" #include "opal/mca/mca.h" -#include "opal/mca/rcache/rcache.h" #include "opal/mca/memory/base/base.h" +#include "opal/mca/rcache/rcache.h" BEGIN_C_DECLS /* * create a module by name */ -OPAL_DECLSPEC mca_rcache_base_module_t *mca_rcache_base_module_create (const char *name, void *user_data, - mca_rcache_base_resources_t *rcache_resources); +OPAL_DECLSPEC mca_rcache_base_module_t * +mca_rcache_base_module_create(const char *name, void *user_data, + mca_rcache_base_resources_t *rcache_resources); /* * MCA framework @@ -55,7 +56,7 @@ typedef struct mca_rcache_base_selected_module_t mca_rcache_base_selected_module OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_rcache_base_selected_module_t); OPAL_DECLSPEC mca_rcache_base_component_t *mca_rcache_base_component_lookup(const char *name); -OPAL_DECLSPEC mca_rcache_base_module_t *mca_rcache_base_module_lookup (const char *name); +OPAL_DECLSPEC mca_rcache_base_module_t *mca_rcache_base_module_lookup(const char *name); OPAL_DECLSPEC int mca_rcache_base_module_destroy(mca_rcache_base_module_t *module); extern opal_free_list_t mca_rcache_base_vma_tree_items; diff --git a/opal/mca/rcache/base/rcache_base_create.c b/opal/mca/rcache/base/rcache_base_create.c index df74b7784c9..7f2ce5e5b01 100644 --- a/opal/mca/rcache/base/rcache_base_create.c +++ b/opal/mca/rcache/base/rcache_base_create.c @@ -25,23 +25,24 @@ #include #include -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/rcache/rcache.h" +#include "opal/mca/mca.h" #include "opal/mca/rcache/base/base.h" #include "opal/mca/rcache/base/rcache_base_mem_cb.h" -#include "rcache_base_vma_tree.h" -#include "opal/util/show_help.h" +#include "opal/mca/rcache/rcache.h" #include "opal/util/proc.h" +#include "opal/util/show_help.h" +#include "rcache_base_vma_tree.h" -#include "opal/runtime/opal_params.h" #include "opal/memoryhooks/memory.h" +#include "opal/runtime/opal_params.h" -mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void *user_data, - struct mca_rcache_base_resources_t* resources) +mca_rcache_base_module_t * +mca_rcache_base_module_create(const char *name, void *user_data, + struct mca_rcache_base_resources_t *resources) { - mca_rcache_base_component_t* component = NULL; - mca_rcache_base_module_t* module = NULL; + mca_rcache_base_component_t *component = NULL; + mca_rcache_base_module_t *module = NULL; mca_base_component_list_item_t *cli; mca_rcache_base_selected_module_t *sm; @@ -60,19 +61,18 @@ mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void triggered before this (any time after mem_free_init(), actually). This is a hook available for memory manager hooks without good initialization routine support */ - (void) mca_base_framework_open (&opal_memory_base_framework, 0); + (void) mca_base_framework_open(&opal_memory_base_framework, 0); - if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) == - ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & - opal_mem_hooks_support_level())) { + if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) + == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) + & opal_mem_hooks_support_level())) { if (-1 == opal_leave_pinned) { opal_leave_pinned = !opal_leave_pinned_pipeline; } opal_mem_hooks_register_release(mca_rcache_base_mem_cb, NULL); } else if (1 == opal_leave_pinned || opal_leave_pinned_pipeline) { - opal_show_help("help-rcache-base.txt", "leave pinned failed", - true, name, OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), - opal_process_info.nodename); + opal_show_help("help-rcache-base.txt", "leave pinned failed", true, name, + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), opal_process_info.nodename); return NULL; } @@ -82,15 +82,16 @@ mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void } } - OPAL_LIST_FOREACH(cli, &opal_rcache_base_framework.framework_components, mca_base_component_list_item_t) { - component = (mca_rcache_base_component_t *) cli->cli_component; - if(0 == strcmp(component->rcache_version.mca_component_name, name)) { - module = component->rcache_init (resources); - break; - } + OPAL_LIST_FOREACH (cli, &opal_rcache_base_framework.framework_components, + mca_base_component_list_item_t) { + component = (mca_rcache_base_component_t *) cli->cli_component; + if (0 == strcmp(component->rcache_version.mca_component_name, name)) { + module = component->rcache_init(resources); + break; + } } - if ( NULL == module ) { + if (NULL == module) { return NULL; } @@ -98,7 +99,7 @@ mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void sm->rcache_component = component; sm->rcache_module = module; sm->user_data = user_data; - opal_list_append(&mca_rcache_base_modules, (opal_list_item_t*) sm); + opal_list_append(&mca_rcache_base_modules, (opal_list_item_t *) sm); return module; } @@ -107,9 +108,9 @@ int mca_rcache_base_module_destroy(mca_rcache_base_module_t *module) { mca_rcache_base_selected_module_t *sm, *next; - OPAL_LIST_FOREACH_SAFE(sm, next, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) { + OPAL_LIST_FOREACH_SAFE (sm, next, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) { if (module == sm->rcache_module) { - opal_list_remove_item(&mca_rcache_base_modules, (opal_list_item_t*)sm); + opal_list_remove_item(&mca_rcache_base_modules, (opal_list_item_t *) sm); if (NULL != sm->rcache_module->rcache_finalize) { sm->rcache_module->rcache_finalize(sm->rcache_module); } diff --git a/opal/mca/rcache/base/rcache_base_frame.c b/opal/mca/rcache/base/rcache_base_frame.c index fd0c2832172..e8d51667246 100644 --- a/opal/mca/rcache/base/rcache_base_frame.c +++ b/opal/mca/rcache/base/rcache_base_frame.c @@ -22,22 +22,21 @@ * $HEADER$ */ - #include "opal_config.h" #include -#include "opal/mca/mca.h" +#include "opal/constants.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_pvar.h" -#include "opal/mca/rcache/rcache.h" +#include "opal/mca/mca.h" #include "opal/mca/rcache/base/base.h" +#include "opal/mca/rcache/rcache.h" #include "opal/memoryhooks/memory.h" -#include "opal/constants.h" #include "rcache_base_mem_cb.h" /* two-level macro for stringifying a number */ #define STRINGIFYX(x) #x -#define STRINGIFY(x) STRINGIFYX(x) +#define STRINGIFY(x) STRINGIFYX(x) /* * The following file was created by configure. It contains extern @@ -53,7 +52,7 @@ int mca_rcache_base_used_mem_hooks = 0; * Memory Pool Registration */ -static void mca_rcache_base_registration_constructor( mca_rcache_base_registration_t * reg ) +static void mca_rcache_base_registration_constructor(mca_rcache_base_registration_t *reg) { reg->rcache = NULL; reg->base = NULL; @@ -106,7 +105,7 @@ static int mca_rcache_base_close(void) opal_mem_free_finalize(), and callbacks from the memory manager hooks to the bowels of the mem_free code can still occur any time between now and end of application (even post main()!) */ - (void) mca_base_framework_close (&opal_memory_base_framework); + (void) mca_base_framework_close(&opal_memory_base_framework); } /* All done */ @@ -125,17 +124,15 @@ static int mca_rcache_base_open(mca_base_open_flag_t flags) OBJ_CONSTRUCT(&mca_rcache_base_modules, opal_list_t); - /* Open up all available components */ + /* Open up all available components */ return mca_base_framework_components_open(&opal_rcache_base_framework, flags); } -static int mca_rcache_base_register_mca_variables (mca_base_register_flag_t flags) +static int mca_rcache_base_register_mca_variables(mca_base_register_flag_t flags) { return OPAL_SUCCESS; } MCA_BASE_FRAMEWORK_DECLARE(opal, rcache, "OPAL Registration Cache", - mca_rcache_base_register_mca_variables, - mca_rcache_base_open, mca_rcache_base_close, - mca_rcache_base_static_components, 0); - + mca_rcache_base_register_mca_variables, mca_rcache_base_open, + mca_rcache_base_close, mca_rcache_base_static_components, 0); diff --git a/opal/mca/rcache/base/rcache_base_mem_cb.c b/opal/mca/rcache/base/rcache_base_mem_cb.c index 8c164d00e6f..ed7393c3ed3 100644 --- a/opal/mca/rcache/base/rcache_base_mem_cb.c +++ b/opal/mca/rcache/base/rcache_base_mem_cb.c @@ -26,31 +26,30 @@ #include "opal_config.h" #ifdef HAVE_UNISTD_H -#include +# include #endif -#include "opal/util/show_help.h" -#include "opal/util/proc.h" #include "opal/runtime/opal_params.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" -#include "opal/mca/rcache/base/rcache_base_mem_cb.h" #include "opal/mca/rcache/base/base.h" +#include "opal/mca/rcache/base/rcache_base_mem_cb.h" #include "opal/mca/mca.h" #include "opal/memoryhooks/memory.h" static char msg[512]; - /* * memory hook callback, called when memory is free'd out from under * us. Be wary of the from_alloc flag -- if you're called with * from_alloc==true, then you cannot call malloc (or any of its * friends)! */ -void mca_rcache_base_mem_cb (void* base, size_t size, void* cbdata, bool from_alloc) +void mca_rcache_base_mem_cb(void *base, size_t size, void *cbdata, bool from_alloc) { - mca_rcache_base_selected_module_t* current; + mca_rcache_base_selected_module_t *current; int rc; /* Only do anything meaningful if the OPAL layer is up and running @@ -59,25 +58,25 @@ void mca_rcache_base_mem_cb (void* base, size_t size, void* cbdata, bool from_al return; } - OPAL_LIST_FOREACH(current, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) { + OPAL_LIST_FOREACH (current, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) { if (current->rcache_module->rcache_invalidate_range != NULL) { - rc = current->rcache_module->rcache_invalidate_range (current->rcache_module, - base, size); + rc = current->rcache_module->rcache_invalidate_range(current->rcache_module, base, + size); if (rc != OPAL_SUCCESS) { if (from_alloc) { int len; - len = snprintf(msg, sizeof(msg), "[%s:%05d] Attempt to free memory that is still in " - "use by an ongoing MPI communication (buffer %p, size %lu). MPI job " - "will now abort.\n", opal_process_info.nodename, - getpid(), base, (unsigned long) size); + len = snprintf( + msg, sizeof(msg), + "[%s:%05d] Attempt to free memory that is still in " + "use by an ongoing MPI communication (buffer %p, size %lu). MPI job " + "will now abort.\n", + opal_process_info.nodename, getpid(), base, (unsigned long) size); msg[sizeof(msg) - 1] = '\0'; write(2, msg, len); } else { - opal_show_help("help-rcache-base.txt", - "cannot deregister in-use memory", true, + opal_show_help("help-rcache-base.txt", "cannot deregister in-use memory", true, current->rcache_component->rcache_version.mca_component_name, - opal_process_info.nodename, - base, (unsigned long) size); + opal_process_info.nodename, base, (unsigned long) size); } /* We're in a callback from somewhere; we can't do diff --git a/opal/mca/rcache/base/rcache_base_mem_cb.h b/opal/mca/rcache/base/rcache_base_mem_cb.h index 3192aeecb4b..db8dfeaf13f 100644 --- a/opal/mca/rcache/base/rcache_base_mem_cb.h +++ b/opal/mca/rcache/base/rcache_base_mem_cb.h @@ -31,7 +31,7 @@ BEGIN_C_DECLS /* * memory hook callback, called when memory is free'd out from under us */ -void mca_rcache_base_mem_cb (void* base, size_t size, void* cbdata, bool from_alloc); +void mca_rcache_base_mem_cb(void *base, size_t size, void *cbdata, bool from_alloc); END_C_DECLS diff --git a/opal/mca/rcache/base/rcache_base_vma.c b/opal/mca/rcache/base/rcache_base_vma.c index c31e5fd3274..d45e6241ec2 100644 --- a/opal/mca/rcache/base/rcache_base_vma.c +++ b/opal/mca/rcache/base/rcache_base_vma.c @@ -28,36 +28,37 @@ #include MCA_memory_IMPLEMENTATION_HEADER #include "opal/mca/memory/memory.h" +#include "opal/mca/rcache/base/base.h" #include "opal/mca/rcache/rcache.h" #include "rcache_base_vma.h" #include "rcache_base_vma_tree.h" -#include "opal/mca/rcache/base/base.h" /** * Initialize the rcache */ -static void mca_rcache_base_vma_module_construct (mca_rcache_base_vma_module_t *vma_module) { +static void mca_rcache_base_vma_module_construct(mca_rcache_base_vma_module_t *vma_module) +{ OBJ_CONSTRUCT(&vma_module->vma_lock, opal_recursive_mutex_t); - (void) mca_rcache_base_vma_tree_init (vma_module); + (void) mca_rcache_base_vma_tree_init(vma_module); } -static void mca_rcache_base_vma_module_destruct (mca_rcache_base_vma_module_t *vma_module) { +static void mca_rcache_base_vma_module_destruct(mca_rcache_base_vma_module_t *vma_module) +{ OBJ_DESTRUCT(&vma_module->vma_lock); - mca_rcache_base_vma_tree_finalize (vma_module); + mca_rcache_base_vma_tree_finalize(vma_module); } OBJ_CLASS_INSTANCE(mca_rcache_base_vma_module_t, opal_object_t, - mca_rcache_base_vma_module_construct, - mca_rcache_base_vma_module_destruct); + mca_rcache_base_vma_module_construct, mca_rcache_base_vma_module_destruct); -mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc (void) +mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc(void) { return OBJ_NEW(mca_rcache_base_vma_module_t); } -int mca_rcache_base_vma_find (mca_rcache_base_vma_module_t *vma_module, void *addr, - size_t size, mca_rcache_base_registration_t **reg) +int mca_rcache_base_vma_find(mca_rcache_base_vma_module_t *vma_module, void *addr, size_t size, + mca_rcache_base_registration_t **reg) { int rc; unsigned char *bound_addr; @@ -69,43 +70,40 @@ int mca_rcache_base_vma_find (mca_rcache_base_vma_module_t *vma_module, void *ad bound_addr = (unsigned char *) ((intptr_t) addr + size - 1); /* Check to ensure that the cache is valid */ - if (OPAL_UNLIKELY(opal_memory_changed() && - NULL != opal_memory->memoryc_process && - OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) { + if (OPAL_UNLIKELY(opal_memory_changed() && NULL != opal_memory->memoryc_process + && OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) { return rc; } - *reg = mca_rcache_base_vma_tree_find (vma_module, (unsigned char *) addr, bound_addr); + *reg = mca_rcache_base_vma_tree_find(vma_module, (unsigned char *) addr, bound_addr); return OPAL_SUCCESS; } -int mca_rcache_base_vma_find_all (mca_rcache_base_vma_module_t *vma_module, void *addr, - size_t size, mca_rcache_base_registration_t **regs, - int reg_cnt) +int mca_rcache_base_vma_find_all(mca_rcache_base_vma_module_t *vma_module, void *addr, size_t size, + mca_rcache_base_registration_t **regs, int reg_cnt) { int rc; unsigned char *bound_addr; - if(size == 0) { + if (size == 0) { return OPAL_ERROR; } bound_addr = (unsigned char *) ((intptr_t) addr + size - 1); /* Check to ensure that the cache is valid */ - if (OPAL_UNLIKELY(opal_memory_changed() && - NULL != opal_memory->memoryc_process && - OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) { + if (OPAL_UNLIKELY(opal_memory_changed() && NULL != opal_memory->memoryc_process + && OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) { return rc; } - return mca_rcache_base_vma_tree_find_all (vma_module, (unsigned char *) addr, - bound_addr, regs, reg_cnt); + return mca_rcache_base_vma_tree_find_all(vma_module, (unsigned char *) addr, bound_addr, regs, + reg_cnt); } -int mca_rcache_base_vma_insert (mca_rcache_base_vma_module_t *vma_module, - mca_rcache_base_registration_t *reg, size_t limit) +int mca_rcache_base_vma_insert(mca_rcache_base_vma_module_t *vma_module, + mca_rcache_base_registration_t *reg, size_t limit) { size_t reg_size = reg->bound - reg->base + 1; int rc; @@ -117,49 +115,46 @@ int mca_rcache_base_vma_insert (mca_rcache_base_vma_module_t *vma_module, } /* Check to ensure that the cache is valid */ - if (OPAL_UNLIKELY(opal_memory_changed() && - NULL != opal_memory->memoryc_process && - OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) { + if (OPAL_UNLIKELY(opal_memory_changed() && NULL != opal_memory->memoryc_process + && OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) { return rc; } - rc = mca_rcache_base_vma_tree_insert (vma_module, reg, limit); + rc = mca_rcache_base_vma_tree_insert(vma_module, reg, limit); if (OPAL_LIKELY(OPAL_SUCCESS == rc)) { /* If we successfully registered, then tell the memory manager to start monitoring this region */ - opal_memory->memoryc_register (reg->base, (uint64_t) reg_size, - (uint64_t) (uintptr_t) reg); + opal_memory->memoryc_register(reg->base, (uint64_t) reg_size, (uint64_t)(uintptr_t) reg); } return rc; } -int mca_rcache_base_vma_delete (mca_rcache_base_vma_module_t *vma_module, - mca_rcache_base_registration_t *reg) +int mca_rcache_base_vma_delete(mca_rcache_base_vma_module_t *vma_module, + mca_rcache_base_registration_t *reg) { /* Tell the memory manager that we no longer care about this region */ - opal_memory->memoryc_deregister (reg->base, - (uint64_t) (reg->bound - reg->base), - (uint64_t) (uintptr_t) reg); - return mca_rcache_base_vma_tree_delete (vma_module, reg); + opal_memory->memoryc_deregister(reg->base, (uint64_t)(reg->bound - reg->base), + (uint64_t)(uintptr_t) reg); + return mca_rcache_base_vma_tree_delete(vma_module, reg); } -int mca_rcache_base_vma_iterate (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, bool partial_ok, - int (*callback_fn) (struct mca_rcache_base_registration_t *, void *), - void *ctx) +int mca_rcache_base_vma_iterate(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + size_t size, bool partial_ok, + int (*callback_fn)(struct mca_rcache_base_registration_t *, void *), + void *ctx) { - return mca_rcache_base_vma_tree_iterate (vma_module, base, size, partial_ok, callback_fn, ctx); + return mca_rcache_base_vma_tree_iterate(vma_module, base, size, partial_ok, callback_fn, ctx); } -void mca_rcache_base_vma_dump_range (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, char *msg) +void mca_rcache_base_vma_dump_range(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + size_t size, char *msg) { - mca_rcache_base_vma_tree_dump_range (vma_module, base, size, msg); + mca_rcache_base_vma_tree_dump_range(vma_module, base, size, msg); } -size_t mca_rcache_base_vma_size (mca_rcache_base_vma_module_t *vma_module) +size_t mca_rcache_base_vma_size(mca_rcache_base_vma_module_t *vma_module) { - return mca_rcache_base_vma_tree_size (vma_module); + return mca_rcache_base_vma_tree_size(vma_module); } diff --git a/opal/mca/rcache/base/rcache_base_vma.h b/opal/mca/rcache/base/rcache_base_vma.h index 261cad67196..c87352f2d78 100644 --- a/opal/mca/rcache/base/rcache_base_vma.h +++ b/opal/mca/rcache/base/rcache_base_vma.h @@ -32,9 +32,9 @@ #define MCA_RCACHE_BASE_VMA_H #include "opal_config.h" -#include "opal/class/opal_list.h" #include "opal/class/opal_interval_tree.h" #include "opal/class/opal_lifo.h" +#include "opal/class/opal_list.h" BEGIN_C_DECLS @@ -52,24 +52,22 @@ typedef struct mca_rcache_base_vma_module_t mca_rcache_base_vma_module_t; OBJ_CLASS_DECLARATION(mca_rcache_base_vma_module_t); -mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc (void); +mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc(void); -int mca_rcache_base_vma_find (mca_rcache_base_vma_module_t *vma_module, void *addr, - size_t size, struct mca_rcache_base_registration_t **reg); +int mca_rcache_base_vma_find(mca_rcache_base_vma_module_t *vma_module, void *addr, size_t size, + struct mca_rcache_base_registration_t **reg); -int mca_rcache_base_vma_find_all (mca_rcache_base_vma_module_t *vma_module, void *addr, - size_t size, struct mca_rcache_base_registration_t **regs, - int reg_cnt); +int mca_rcache_base_vma_find_all(mca_rcache_base_vma_module_t *vma_module, void *addr, size_t size, + struct mca_rcache_base_registration_t **regs, int reg_cnt); -int mca_rcache_base_vma_insert (mca_rcache_base_vma_module_t *vma_module, - struct mca_rcache_base_registration_t *registration, - size_t limit); +int mca_rcache_base_vma_insert(mca_rcache_base_vma_module_t *vma_module, + struct mca_rcache_base_registration_t *registration, size_t limit); -int mca_rcache_base_vma_delete (mca_rcache_base_vma_module_t *vma_module, - struct mca_rcache_base_registration_t *registration); +int mca_rcache_base_vma_delete(mca_rcache_base_vma_module_t *vma_module, + struct mca_rcache_base_registration_t *registration); -void mca_rcache_base_vma_dump_range (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, char *msg); +void mca_rcache_base_vma_dump_range(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + size_t size, char *msg); /** * Iterate over registrations in the specified range. @@ -87,12 +85,12 @@ void mca_rcache_base_vma_dump_range (mca_rcache_base_vma_module_t *vma_module, * from the callback. The iteration will terminate if the callback returns anything * other than OPAL_SUCCESS. */ -int mca_rcache_base_vma_iterate (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, bool partial_ok, - int (*callback_fn) (struct mca_rcache_base_registration_t *, void *), - void *ctx); +int mca_rcache_base_vma_iterate(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + size_t size, bool partial_ok, + int (*callback_fn)(struct mca_rcache_base_registration_t *, void *), + void *ctx); -size_t mca_rcache_base_vma_size (mca_rcache_base_vma_module_t *vma_module); +size_t mca_rcache_base_vma_size(mca_rcache_base_vma_module_t *vma_module); END_C_DECLS diff --git a/opal/mca/rcache/base/rcache_base_vma_tree.c b/opal/mca/rcache/base/rcache_base_vma_tree.c index 09362f4f2b5..0883e1f3825 100644 --- a/opal/mca/rcache/base/rcache_base_vma_tree.c +++ b/opal/mca/rcache/base/rcache_base_vma_tree.c @@ -27,27 +27,29 @@ * $HEADER$ */ -#include "opal/util/output.h" #include "rcache_base_vma_tree.h" #include "opal/mca/rcache/base/base.h" +#include "opal/util/output.h" -int mca_rcache_base_vma_tree_init (mca_rcache_base_vma_module_t *vma_module) +int mca_rcache_base_vma_tree_init(mca_rcache_base_vma_module_t *vma_module) { OBJ_CONSTRUCT(&vma_module->tree, opal_interval_tree_t); vma_module->reg_cur_cache_size = 0; - return opal_interval_tree_init (&vma_module->tree); + return opal_interval_tree_init(&vma_module->tree); } -void mca_rcache_base_vma_tree_finalize (mca_rcache_base_vma_module_t *vma_module) +void mca_rcache_base_vma_tree_finalize(mca_rcache_base_vma_module_t *vma_module) { OBJ_DESTRUCT(&vma_module->tree); } -mca_rcache_base_registration_t *mca_rcache_base_vma_tree_find (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, unsigned char *bound) +mca_rcache_base_registration_t * +mca_rcache_base_vma_tree_find(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + unsigned char *bound) { - return (mca_rcache_base_registration_t *) opal_interval_tree_find_overlapping (&vma_module->tree, (uintptr_t) base, - ((uintptr_t) bound) + 1); + return (mca_rcache_base_registration_t *) + opal_interval_tree_find_overlapping(&vma_module->tree, (uintptr_t) base, + ((uintptr_t) bound) + 1); } struct mca_rcache_base_vma_tree_find_all_helper_args_t { @@ -56,11 +58,14 @@ struct mca_rcache_base_vma_tree_find_all_helper_args_t { int reg_max; }; -typedef struct mca_rcache_base_vma_tree_find_all_helper_args_t mca_rcache_base_vma_tree_find_all_helper_args_t; +typedef struct mca_rcache_base_vma_tree_find_all_helper_args_t + mca_rcache_base_vma_tree_find_all_helper_args_t; -static int mca_rcache_base_vma_tree_find_all_helper (uint64_t low, uint64_t high, void *data, void *ctx) +static int mca_rcache_base_vma_tree_find_all_helper(uint64_t low, uint64_t high, void *data, + void *ctx) { - mca_rcache_base_vma_tree_find_all_helper_args_t *args = (mca_rcache_base_vma_tree_find_all_helper_args_t *) ctx; + mca_rcache_base_vma_tree_find_all_helper_args_t *args + = (mca_rcache_base_vma_tree_find_all_helper_args_t *) ctx; mca_rcache_base_registration_t *reg = (mca_rcache_base_registration_t *) data; if (args->reg_cnt == args->reg_max) { @@ -72,44 +77,51 @@ static int mca_rcache_base_vma_tree_find_all_helper (uint64_t low, uint64_t high return OPAL_SUCCESS; } -int mca_rcache_base_vma_tree_find_all (mca_rcache_base_vma_module_t *vma_module, unsigned char *base, - unsigned char *bound, mca_rcache_base_registration_t **regs, - int reg_cnt) +int mca_rcache_base_vma_tree_find_all(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + unsigned char *bound, mca_rcache_base_registration_t **regs, + int reg_cnt) { - mca_rcache_base_vma_tree_find_all_helper_args_t args = {.regs = regs, .reg_max = reg_cnt, .reg_cnt = 0}; + mca_rcache_base_vma_tree_find_all_helper_args_t args = {.regs = regs, + .reg_max = reg_cnt, + .reg_cnt = 0}; - (void) opal_interval_tree_traverse (&vma_module->tree, (uint64_t) (uintptr_t) base, ((uint64_t) (uintptr_t) bound) + 1, - true, mca_rcache_base_vma_tree_find_all_helper, &args); + (void) opal_interval_tree_traverse(&vma_module->tree, (uint64_t)(uintptr_t) base, + ((uint64_t)(uintptr_t) bound) + 1, true, + mca_rcache_base_vma_tree_find_all_helper, &args); return args.reg_cnt; } struct mca_rcache_base_vma_tree_iterate_helper_args_t { - int (*callback_fn) (struct mca_rcache_base_registration_t *, void *); + int (*callback_fn)(struct mca_rcache_base_registration_t *, void *); void *ctx; }; -typedef struct mca_rcache_base_vma_tree_iterate_helper_args_t mca_rcache_base_vma_tree_iterate_helper_args_t; +typedef struct mca_rcache_base_vma_tree_iterate_helper_args_t + mca_rcache_base_vma_tree_iterate_helper_args_t; -static int mca_rcache_base_vma_tree_iterate_helper (uint64_t low, uint64_t high, void *data, void *ctx) +static int mca_rcache_base_vma_tree_iterate_helper(uint64_t low, uint64_t high, void *data, + void *ctx) { - mca_rcache_base_vma_tree_iterate_helper_args_t *args = (mca_rcache_base_vma_tree_iterate_helper_args_t *) ctx; - return args->callback_fn ((mca_rcache_base_registration_t *) data, args->ctx); + mca_rcache_base_vma_tree_iterate_helper_args_t *args + = (mca_rcache_base_vma_tree_iterate_helper_args_t *) ctx; + return args->callback_fn((mca_rcache_base_registration_t *) data, args->ctx); } -int mca_rcache_base_vma_tree_iterate (mca_rcache_base_vma_module_t *vma_module, unsigned char *base, size_t size, - bool partial_ok, int (*callback_fn) (struct mca_rcache_base_registration_t *, void *), - void *ctx) +int mca_rcache_base_vma_tree_iterate( + mca_rcache_base_vma_module_t *vma_module, unsigned char *base, size_t size, bool partial_ok, + int (*callback_fn)(struct mca_rcache_base_registration_t *, void *), void *ctx) { mca_rcache_base_vma_tree_iterate_helper_args_t args = {.callback_fn = callback_fn, .ctx = ctx}; uintptr_t bound = (uintptr_t) base + size; - return opal_interval_tree_traverse (&vma_module->tree, (uint64_t) (intptr_t) base, bound, partial_ok, - mca_rcache_base_vma_tree_iterate_helper, &args); + return opal_interval_tree_traverse(&vma_module->tree, (uint64_t)(intptr_t) base, bound, + partial_ok, mca_rcache_base_vma_tree_iterate_helper, &args); } -int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t *vma_module, - mca_rcache_base_registration_t *reg, size_t limit) +int mca_rcache_base_vma_tree_insert(mca_rcache_base_vma_module_t *vma_module, + mca_rcache_base_registration_t *reg, size_t limit) { - return opal_interval_tree_insert (&vma_module->tree, reg, (uintptr_t) reg->base, (uintptr_t) reg->bound + 1); + return opal_interval_tree_insert(&vma_module->tree, reg, (uintptr_t) reg->base, + (uintptr_t) reg->bound + 1); } /** @@ -120,39 +132,41 @@ int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t *vma_module, * @retval OPAL_SUCCESS * @retval OPAL_ERR_BAD_PARAM if the passed base pointer was invalid */ -int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module, - mca_rcache_base_registration_t *reg) +int mca_rcache_base_vma_tree_delete(mca_rcache_base_vma_module_t *vma_module, + mca_rcache_base_registration_t *reg) { - return opal_interval_tree_delete (&vma_module->tree, (uintptr_t) reg->base, (uintptr_t) reg->bound + 1, reg); + return opal_interval_tree_delete(&vma_module->tree, (uintptr_t) reg->base, + (uintptr_t) reg->bound + 1, reg); } -static int mca_rcache_base_tree_dump_range_helper (uint64_t low, uint64_t high, void *data, void *ctx) +static int mca_rcache_base_tree_dump_range_helper(uint64_t low, uint64_t high, void *data, + void *ctx) { - mca_rcache_base_registration_t *reg = ( mca_rcache_base_registration_t *) data; + mca_rcache_base_registration_t *reg = (mca_rcache_base_registration_t *) data; - opal_output(0, " reg: base=%p, bound=%p, ref_count=%d, flags=0x%x", - (void *) reg->base, (void *) reg->bound, reg->ref_count, reg->flags); + opal_output(0, " reg: base=%p, bound=%p, ref_count=%d, flags=0x%x", (void *) reg->base, + (void *) reg->bound, reg->ref_count, reg->flags); return OPAL_SUCCESS; } /* Dump out rcache entries within a range of memory. Useful for debugging. */ -void mca_rcache_base_vma_tree_dump_range (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, char *msg) +void mca_rcache_base_vma_tree_dump_range(mca_rcache_base_vma_module_t *vma_module, + unsigned char *base, size_t size, char *msg) { uintptr_t bound = (uintptr_t) base + size; opal_output(0, "Dumping rcache entries: %s", msg ? msg : ""); - if (opal_interval_tree_size (&vma_module->tree)) { - (void) opal_interval_tree_traverse (&vma_module->tree, (uintptr_t) base, bound, false, - mca_rcache_base_tree_dump_range_helper, NULL); + if (opal_interval_tree_size(&vma_module->tree)) { + (void) opal_interval_tree_traverse(&vma_module->tree, (uintptr_t) base, bound, false, + mca_rcache_base_tree_dump_range_helper, NULL); } else { opal_output(0, " rcache is empty"); } } -size_t mca_rcache_base_vma_tree_size (mca_rcache_base_vma_module_t *vma_module) +size_t mca_rcache_base_vma_tree_size(mca_rcache_base_vma_module_t *vma_module) { - return opal_interval_tree_size (&vma_module->tree); + return opal_interval_tree_size(&vma_module->tree); } diff --git a/opal/mca/rcache/base/rcache_base_vma_tree.h b/opal/mca/rcache/base/rcache_base_vma_tree.h index 87f8de2a02e..4127e03dc93 100644 --- a/opal/mca/rcache/base/rcache_base_vma_tree.h +++ b/opal/mca/rcache/base/rcache_base_vma_tree.h @@ -24,9 +24,9 @@ * $HEADER$ */ /** - * @file - * Registation cache VMA tree implementation - */ + * @file + * Registation cache VMA tree implementation + */ #ifndef MCA_RCACHE_BASE_VMA_TREE_H #define MCA_RCACHE_BASE_VMA_TREE_H @@ -38,7 +38,7 @@ /* * initialize the vma tree */ -int mca_rcache_base_vma_tree_init (mca_rcache_base_vma_module_t *vma_module); +int mca_rcache_base_vma_tree_init(mca_rcache_base_vma_module_t *vma_module); /* * clean up the vma tree @@ -48,43 +48,40 @@ void mca_rcache_base_vma_tree_finalize(mca_rcache_base_vma_module_t *vma_module) /** * Returns the item in the vma tree */ -mca_rcache_base_registration_t *mca_rcache_base_vma_tree_find (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, - unsigned char *bound); +mca_rcache_base_registration_t * +mca_rcache_base_vma_tree_find(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + unsigned char *bound); /** * Returns all registration that overlaps given memory region */ -int mca_rcache_base_vma_tree_find_all ( - mca_rcache_base_vma_module_t *vma_module, unsigned char *base, - unsigned char *bound, mca_rcache_base_registration_t **regs, - int reg_cnt); +int mca_rcache_base_vma_tree_find_all(mca_rcache_base_vma_module_t *vma_module, unsigned char *base, + unsigned char *bound, mca_rcache_base_registration_t **regs, + int reg_cnt); /* * insert an item in the vma tree */ -int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t *vma_module, - mca_rcache_base_registration_t* reg, size_t limit); +int mca_rcache_base_vma_tree_insert(mca_rcache_base_vma_module_t *vma_module, + mca_rcache_base_registration_t *reg, size_t limit); /* * remove an item from the vma tree */ -int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module, - mca_rcache_base_registration_t *reg); +int mca_rcache_base_vma_tree_delete(mca_rcache_base_vma_module_t *vma_module, + mca_rcache_base_registration_t *reg); /* * Dump out the contents of the rcache for debugging. */ -void mca_rcache_base_vma_tree_dump_range (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, char *msg); - +void mca_rcache_base_vma_tree_dump_range(mca_rcache_base_vma_module_t *vma_module, + unsigned char *base, size_t size, char *msg); /* * Iterate over matching registration handles in the tree. */ -int mca_rcache_base_vma_tree_iterate (mca_rcache_base_vma_module_t *vma_module, - unsigned char *base, size_t size, bool partial_ok, - int (*callback_fn) (struct mca_rcache_base_registration_t *, void *), - void *ctx); +int mca_rcache_base_vma_tree_iterate( + mca_rcache_base_vma_module_t *vma_module, unsigned char *base, size_t size, bool partial_ok, + int (*callback_fn)(struct mca_rcache_base_registration_t *, void *), void *ctx); /** * @brief Get the current size of the vma tree @@ -93,6 +90,6 @@ int mca_rcache_base_vma_tree_iterate (mca_rcache_base_vma_module_t *vma_module, * * @returns the current number of vma regions in the tree */ -size_t mca_rcache_base_vma_tree_size (mca_rcache_base_vma_module_t *vma_module); +size_t mca_rcache_base_vma_tree_size(mca_rcache_base_vma_module_t *vma_module); #endif /* MCA_RCACHE_BASE_VMA_TREE_H */ diff --git a/opal/mca/rcache/gpusm/rcache_gpusm.h b/opal/mca/rcache/gpusm/rcache_gpusm.h index 00733f3c00f..43a11949c02 100644 --- a/opal/mca/rcache/gpusm/rcache_gpusm.h +++ b/opal/mca/rcache/gpusm/rcache_gpusm.h @@ -54,7 +54,8 @@ OPAL_DECLSPEC extern mca_rcache_gpusm_component_t mca_rcache_gpusm_component; struct mca_rcache_gpusm_module_t { mca_rcache_base_module_t super; opal_free_list_t reg_list; -}; typedef struct mca_rcache_gpusm_module_t mca_rcache_gpusm_module_t; +}; +typedef struct mca_rcache_gpusm_module_t mca_rcache_gpusm_module_t; /* * Initializes the rcache module. @@ -62,22 +63,23 @@ struct mca_rcache_gpusm_module_t { void mca_rcache_gpusm_module_init(mca_rcache_gpusm_module_t *rcache); /** - * register block of memory - */ -int mca_rcache_gpusm_register(mca_rcache_base_module_t* rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, mca_rcache_base_registration_t **reg); + * register block of memory + */ +int mca_rcache_gpusm_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, + mca_rcache_base_registration_t **reg); /** * deregister memory */ int mca_rcache_gpusm_deregister(mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg); + mca_rcache_base_registration_t *reg); /** * find registration for a given block of memory */ -int mca_rcache_gpusm_find(struct mca_rcache_base_module_t* rcache, void* addr, - size_t size, mca_rcache_base_registration_t **reg); +int mca_rcache_gpusm_find(struct mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg); /** * finalize rcache diff --git a/opal/mca/rcache/gpusm/rcache_gpusm_component.c b/opal/mca/rcache/gpusm/rcache_gpusm_component.c index fed00b62cf5..7c398a484d0 100644 --- a/opal/mca/rcache/gpusm/rcache_gpusm_component.c +++ b/opal/mca/rcache/gpusm/rcache_gpusm_component.c @@ -28,10 +28,10 @@ #include "opal/mca/base/base.h" #include "rcache_gpusm.h" #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_MALLOC_H -#include +# include #endif /* @@ -40,14 +40,14 @@ static int gpusm_open(void); static int gpusm_close(void); static int gpusm_register(void); -static mca_rcache_base_module_t* gpusm_init(struct mca_rcache_base_resources_t* resources); +static mca_rcache_base_module_t *gpusm_init(struct mca_rcache_base_resources_t *resources); -mca_rcache_gpusm_component_t mca_rcache_gpusm_component = { - { - /* First, the mca_base_component_t struct containing meta - information about the component itself */ +mca_rcache_gpusm_component_t mca_rcache_gpusm_component = {{ + /* First, the mca_base_component_t struct containing meta + information about the component itself */ - .rcache_version = { + .rcache_version = + { MCA_RCACHE_BASE_VERSION_3_0_0, .mca_component_name = "gpusm", @@ -57,44 +57,39 @@ mca_rcache_gpusm_component_t mca_rcache_gpusm_component = { .mca_close_component = gpusm_close, .mca_register_component_params = gpusm_register, }, - .rcache_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .rcache_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, - .rcache_init = gpusm_init, - } -}; + .rcache_init = gpusm_init, +}}; /** - * Component open/close/init/register functions. Most do not do anything, - * but keep around for placeholders. - */ + * Component open/close/init/register functions. Most do not do anything, + * but keep around for placeholders. + */ static int gpusm_open(void) { return OPAL_SUCCESS; } - static int gpusm_register(void) { - return OPAL_SUCCESS; + return OPAL_SUCCESS; } - static int gpusm_close(void) { return OPAL_SUCCESS; } - -static mca_rcache_base_module_t* gpusm_init(struct mca_rcache_base_resources_t *resources) +static mca_rcache_base_module_t *gpusm_init(struct mca_rcache_base_resources_t *resources) { - mca_rcache_gpusm_module_t* rcache_module; + mca_rcache_gpusm_module_t *rcache_module; (void) resources; - rcache_module = (mca_rcache_gpusm_module_t *) calloc (1, sizeof (*rcache_module)); + rcache_module = (mca_rcache_gpusm_module_t *) calloc(1, sizeof(*rcache_module)); if (NULL == rcache_module) { return NULL; } diff --git a/opal/mca/rcache/gpusm/rcache_gpusm_module.c b/opal/mca/rcache/gpusm/rcache_gpusm_module.c index caf8913a938..5f490696a1d 100644 --- a/opal/mca/rcache/gpusm/rcache_gpusm_module.c +++ b/opal/mca/rcache/gpusm/rcache_gpusm_module.c @@ -38,24 +38,23 @@ */ #include "opal_config.h" +#include "opal/mca/common/cuda/common_cuda.h" #include "opal/mca/rcache/base/base.h" #include "opal/mca/rcache/gpusm/rcache_gpusm.h" -#include "opal/mca/common/cuda/common_cuda.h" /** * Called when the registration free list is created. An event is created * for each entry. */ -static void mca_rcache_gpusm_registration_constructor( mca_rcache_gpusm_registration_t *item ) +static void mca_rcache_gpusm_registration_constructor(mca_rcache_gpusm_registration_t *item) { - mca_common_cuda_construct_event_and_handle(&item->event, - (void *)&item->evtHandle); + mca_common_cuda_construct_event_and_handle(&item->event, (void *) &item->evtHandle); } /** * Called when the program is exiting. This destroys the events. */ -static void mca_rcache_gpusm_registration_destructor( mca_rcache_gpusm_registration_t *item ) +static void mca_rcache_gpusm_registration_destructor(mca_rcache_gpusm_registration_t *item) { mca_common_cuda_destruct_event(item->event); } @@ -67,7 +66,7 @@ OBJ_CLASS_INSTANCE(mca_rcache_gpusm_registration_t, mca_rcache_base_registration /* * Initializes the rcache module. */ -void mca_rcache_gpusm_module_init(mca_rcache_gpusm_module_t* rcache) +void mca_rcache_gpusm_module_init(mca_rcache_gpusm_module_t *rcache) { rcache->super.rcache_component = &mca_rcache_gpusm_component.super; rcache->super.rcache_register = mca_rcache_gpusm_register; @@ -80,21 +79,17 @@ void mca_rcache_gpusm_module_init(mca_rcache_gpusm_module_t* rcache) /* Start with 0 entries in the free list since CUDA may not have * been initialized when this free list is created and there is * some CUDA specific activities that need to be done. */ - opal_free_list_init (&rcache->reg_list, sizeof(struct mca_rcache_common_cuda_reg_t), - opal_cache_line_size, - OBJ_CLASS(mca_rcache_gpusm_registration_t), - 0,opal_cache_line_size, - 0, -1, 64, NULL, 0, NULL, NULL, NULL); - + opal_free_list_init(&rcache->reg_list, sizeof(struct mca_rcache_common_cuda_reg_t), + opal_cache_line_size, OBJ_CLASS(mca_rcache_gpusm_registration_t), 0, + opal_cache_line_size, 0, -1, 64, NULL, 0, NULL, NULL, NULL); } /** * Just go ahead and get a new registration. The find and register * functions are the same thing for this memory pool. */ -int mca_rcache_gpusm_find(mca_rcache_base_module_t *rcache, void *addr, - size_t size, - mca_rcache_base_registration_t **reg) +int mca_rcache_gpusm_find(mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg) { return mca_rcache_gpusm_register(rcache, addr, size, 0, 0, reg); } @@ -105,11 +100,11 @@ int mca_rcache_gpusm_find(mca_rcache_base_module_t *rcache, void *addr, * buffer. There is no need to deregister the memory handle so the * deregister function is a no-op. */ -int mca_rcache_gpusm_register(mca_rcache_base_module_t *rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, - mca_rcache_base_registration_t **reg) +int mca_rcache_gpusm_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, + mca_rcache_base_registration_t **reg) { - mca_rcache_gpusm_module_t *rcache_gpusm = (mca_rcache_gpusm_module_t*)rcache; + mca_rcache_gpusm_module_t *rcache_gpusm = (mca_rcache_gpusm_module_t *) rcache; mca_rcache_base_registration_t *gpusm_reg; opal_free_list_item_t *item; unsigned char *base, *bound; @@ -122,13 +117,13 @@ int mca_rcache_gpusm_register(mca_rcache_base_module_t *rcache, void *addr, *reg = NULL; base = addr; - bound = (unsigned char *)addr + size - 1; + bound = (unsigned char *) addr + size - 1; - item = opal_free_list_get (&rcache_gpusm->reg_list); - if(NULL == item) { + item = opal_free_list_get(&rcache_gpusm->reg_list); + if (NULL == item) { return OPAL_ERR_OUT_OF_RESOURCE; } - gpusm_reg = (mca_rcache_base_registration_t*)item; + gpusm_reg = (mca_rcache_base_registration_t *) item; gpusm_reg->rcache = rcache; gpusm_reg->base = base; @@ -136,30 +131,29 @@ int mca_rcache_gpusm_register(mca_rcache_base_module_t *rcache, void *addr, gpusm_reg->flags = flags; gpusm_reg->access_flags = access_flags; - rc = cuda_getmemhandle (base, size, gpusm_reg, NULL); + rc = cuda_getmemhandle(base, size, gpusm_reg, NULL); - if(rc != OPAL_SUCCESS) { - opal_free_list_return (&rcache_gpusm->reg_list, item); + if (rc != OPAL_SUCCESS) { + opal_free_list_return(&rcache_gpusm->reg_list, item); return rc; } *reg = gpusm_reg; (*reg)->ref_count++; return OPAL_SUCCESS; - } /* * Return the registration to the free list. */ int mca_rcache_gpusm_deregister(struct mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg) + mca_rcache_base_registration_t *reg) { int rc; - mca_rcache_gpusm_module_t *rcache_gpusm = (mca_rcache_gpusm_module_t *)rcache; + mca_rcache_gpusm_module_t *rcache_gpusm = (mca_rcache_gpusm_module_t *) rcache; - rc = cuda_ungetmemhandle (NULL, reg); - opal_free_list_return (&rcache_gpusm->reg_list, (opal_free_list_item_t *) reg); + rc = cuda_ungetmemhandle(NULL, reg); + opal_free_list_return(&rcache_gpusm->reg_list, (opal_free_list_item_t *) reg); return OPAL_SUCCESS; } @@ -169,12 +163,13 @@ int mca_rcache_gpusm_deregister(struct mca_rcache_base_module_t *rcache, void mca_rcache_gpusm_finalize(struct mca_rcache_base_module_t *rcache) { opal_free_list_item_t *item; - mca_rcache_gpusm_module_t *rcache_gpusm = (mca_rcache_gpusm_module_t *)rcache; + mca_rcache_gpusm_module_t *rcache_gpusm = (mca_rcache_gpusm_module_t *) rcache; /* Need to run the destructor on each item in the free list explicitly. * The destruction of the free list only runs the destructor on the * main free list, not each item. */ - while (NULL != (item = (opal_free_list_item_t *)opal_lifo_pop(&(rcache_gpusm->reg_list.super)))) { + while (NULL + != (item = (opal_free_list_item_t *) opal_lifo_pop(&(rcache_gpusm->reg_list.super)))) { OBJ_DESTRUCT(item); } diff --git a/opal/mca/rcache/grdma/rcache_grdma.h b/opal/mca/rcache/grdma/rcache_grdma.h index 7d912dd6aeb..00e8d30f08a 100644 --- a/opal/mca/rcache/grdma/rcache_grdma.h +++ b/opal/mca/rcache/grdma/rcache_grdma.h @@ -30,10 +30,10 @@ #include "opal_config.h" #include "opal/class/opal_list.h" -#include "opal/util/event.h" #include "opal/mca/rcache/rcache.h" +#include "opal/util/event.h" #if HAVE_SYS_MMAN_H -#include +# include #endif #define MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU MCA_RCACHE_FLAGS_MOD_RESV0 @@ -80,7 +80,8 @@ typedef struct mca_rcache_grdma_module_t mca_rcache_grdma_module_t; /* * Initializes the rcache module. */ -void mca_rcache_grdma_module_init(mca_rcache_grdma_module_t *rcache, mca_rcache_grdma_cache_t *cache); +void mca_rcache_grdma_module_init(mca_rcache_grdma_module_t *rcache, + mca_rcache_grdma_cache_t *cache); END_C_DECLS #endif diff --git a/opal/mca/rcache/grdma/rcache_grdma_component.c b/opal/mca/rcache/grdma/rcache_grdma_component.c index 3660eb8c055..f55d752378b 100644 --- a/opal/mca/rcache/grdma/rcache_grdma_component.c +++ b/opal/mca/rcache/grdma/rcache_grdma_component.c @@ -28,10 +28,10 @@ #include "opal/runtime/opal_params.h" #include "rcache_grdma.h" #ifdef HAVE_UNISTD_H -#include +# include #endif -#include #include +#include /* * Local functions @@ -39,15 +39,14 @@ static int grdma_open(void); static int grdma_close(void); static int grdma_register(void); -static mca_rcache_base_module_t* grdma_init( - struct mca_rcache_base_resources_t* resources); +static mca_rcache_base_module_t *grdma_init(struct mca_rcache_base_resources_t *resources); -mca_rcache_grdma_component_t mca_rcache_grdma_component = { - { - /* First, the mca_base_component_t struct containing meta - information about the component itself */ +mca_rcache_grdma_component_t mca_rcache_grdma_component = {{ + /* First, the mca_base_component_t struct containing meta + information about the component itself */ - .rcache_version = { + .rcache_version = + { MCA_RCACHE_BASE_VERSION_3_0_0, .mca_component_name = "grdma", @@ -57,18 +56,16 @@ mca_rcache_grdma_component_t mca_rcache_grdma_component = { .mca_close_component = grdma_close, .mca_register_component_params = grdma_register, }, - .rcache_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .rcache_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, - .rcache_init = grdma_init, - } -}; + .rcache_init = grdma_init, +}}; /** - * component open/close/init function - */ + * component open/close/init function + */ static int grdma_open(void) { OBJ_CONSTRUCT(&mca_rcache_grdma_component.caches, opal_list_t); @@ -76,30 +73,25 @@ static int grdma_open(void) return OPAL_SUCCESS; } - static int grdma_register(void) { mca_rcache_grdma_component.print_stats = false; - (void) mca_base_component_var_register(&mca_rcache_grdma_component.super.rcache_version, - "print_stats", "print registration cache usage statistics at the end of the run", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_rcache_grdma_component.print_stats); + (void) mca_base_component_var_register( + &mca_rcache_grdma_component.super.rcache_version, "print_stats", + "print registration cache usage statistics at the end of the run", MCA_BASE_VAR_TYPE_BOOL, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &mca_rcache_grdma_component.print_stats); return OPAL_SUCCESS; } - static int grdma_close(void) { OPAL_LIST_DESTRUCT(&mca_rcache_grdma_component.caches); return OPAL_SUCCESS; } - -static mca_rcache_base_module_t * -grdma_init(struct mca_rcache_base_resources_t *resources) +static mca_rcache_base_module_t *grdma_init(struct mca_rcache_base_resources_t *resources) { mca_rcache_grdma_module_t *rcache_module; mca_rcache_grdma_cache_t *cache = NULL, *item; @@ -107,12 +99,12 @@ grdma_init(struct mca_rcache_base_resources_t *resources) /* Set this here (vs in component.c) because opal_leave_pinned* may have been set after MCA params were read (e.g., by the openib btl) */ - mca_rcache_grdma_component.leave_pinned = (int) - (1 == opal_leave_pinned || opal_leave_pinned_pipeline); + mca_rcache_grdma_component.leave_pinned = (int) (1 == opal_leave_pinned + || opal_leave_pinned_pipeline); /* find the specified pool */ - OPAL_LIST_FOREACH(item, &mca_rcache_grdma_component.caches, mca_rcache_grdma_cache_t) { - if (0 == strcmp (item->cache_name, resources->cache_name)) { + OPAL_LIST_FOREACH (item, &mca_rcache_grdma_component.caches, mca_rcache_grdma_cache_t) { + if (0 == strcmp(item->cache_name, resources->cache_name)) { cache = item; break; } @@ -125,16 +117,16 @@ grdma_init(struct mca_rcache_base_resources_t *resources) return NULL; } - cache->cache_name = strdup (resources->cache_name); + cache->cache_name = strdup(resources->cache_name); - opal_list_append (&mca_rcache_grdma_component.caches, &cache->super); + opal_list_append(&mca_rcache_grdma_component.caches, &cache->super); } - rcache_module = (mca_rcache_grdma_module_t *) malloc (sizeof (*rcache_module)); + rcache_module = (mca_rcache_grdma_module_t *) malloc(sizeof(*rcache_module)); rcache_module->resources = *resources; - mca_rcache_grdma_module_init (rcache_module, cache); + mca_rcache_grdma_module_init(rcache_module, cache); return &rcache_module->super; } diff --git a/opal/mca/rcache/grdma/rcache_grdma_module.c b/opal/mca/rcache/grdma/rcache_grdma_module.c index 3f163c2d7f1..05833070854 100644 --- a/opal/mca/rcache/grdma/rcache_grdma_module.c +++ b/opal/mca/rcache/grdma/rcache_grdma_module.c @@ -32,67 +32,67 @@ #include "opal_config.h" #include -#include #include +#include #include "opal/align.h" #include "opal/util/proc.h" #if OPAL_CUDA_GDR_SUPPORT -#include "opal/mca/common/cuda/common_cuda.h" +# include "opal/mca/common/cuda/common_cuda.h" #endif /* OPAL_CUDA_GDR_SUPPORT */ -#include "opal/mca/rcache/rcache.h" #include "opal/mca/rcache/base/base.h" +#include "opal/mca/rcache/rcache.h" -#include "opal/util/sys_limits.h" #include "opal/align.h" +#include "opal/util/sys_limits.h" #include "rcache_grdma.h" - -static int mca_rcache_grdma_register (mca_rcache_base_module_t *rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, - mca_rcache_base_registration_t **reg); -static int mca_rcache_grdma_deregister (mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg); -static int mca_rcache_grdma_find (mca_rcache_base_module_t *rcache, void *addr, - size_t size, mca_rcache_base_registration_t **reg); -static int mca_rcache_grdma_invalidate_range (mca_rcache_base_module_t *rcache, void *base, - size_t size); -static void mca_rcache_grdma_finalize (mca_rcache_base_module_t *rcache); -static bool mca_rcache_grdma_evict (mca_rcache_base_module_t *rcache); -static int mca_rcache_grdma_add_to_gc (mca_rcache_base_registration_t *grdma_reg); - -static inline bool registration_flags_cacheable (uint32_t flags) +static int mca_rcache_grdma_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, + mca_rcache_base_registration_t **reg); +static int mca_rcache_grdma_deregister(mca_rcache_base_module_t *rcache, + mca_rcache_base_registration_t *reg); +static int mca_rcache_grdma_find(mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg); +static int mca_rcache_grdma_invalidate_range(mca_rcache_base_module_t *rcache, void *base, + size_t size); +static void mca_rcache_grdma_finalize(mca_rcache_base_module_t *rcache); +static bool mca_rcache_grdma_evict(mca_rcache_base_module_t *rcache); +static int mca_rcache_grdma_add_to_gc(mca_rcache_base_registration_t *grdma_reg); + +static inline bool registration_flags_cacheable(uint32_t flags) { - return (mca_rcache_grdma_component.leave_pinned && - !(flags & - (MCA_RCACHE_FLAGS_CACHE_BYPASS | - MCA_RCACHE_FLAGS_PERSIST | - MCA_RCACHE_FLAGS_INVALID))); + return (mca_rcache_grdma_component.leave_pinned + && !(flags + & (MCA_RCACHE_FLAGS_CACHE_BYPASS | MCA_RCACHE_FLAGS_PERSIST + | MCA_RCACHE_FLAGS_INVALID))); } static inline bool registration_is_cacheable(mca_rcache_base_registration_t *reg) { - return registration_flags_cacheable (reg->flags); + return registration_flags_cacheable(reg->flags); } #if OPAL_CUDA_GDR_SUPPORT static int check_for_cuda_freed_memory(mca_rcache_base_module_t *rcache, void *addr, size_t size); #endif /* OPAL_CUDA_GDR_SUPPORT */ -static void mca_rcache_grdma_cache_contructor (mca_rcache_grdma_cache_t *cache) +static void mca_rcache_grdma_cache_contructor(mca_rcache_grdma_cache_t *cache) { - memset ((void *)((uintptr_t)cache + sizeof (cache->super)), 0, sizeof (*cache) - sizeof (cache->super)); + memset((void *) ((uintptr_t) cache + sizeof(cache->super)), 0, + sizeof(*cache) - sizeof(cache->super)); OBJ_CONSTRUCT(&cache->lru_list, opal_list_t); OBJ_CONSTRUCT(&cache->gc_lifo, opal_lifo_t); - cache->vma_module = mca_rcache_base_vma_module_alloc (); + cache->vma_module = mca_rcache_base_vma_module_alloc(); } -static void mca_rcache_grdma_cache_destructor (mca_rcache_grdma_cache_t *cache) +static void mca_rcache_grdma_cache_destructor(mca_rcache_grdma_cache_t *cache) { /* clear the lru before releasing the list */ - while (NULL != opal_list_remove_first (&cache->lru_list)); + while (NULL != opal_list_remove_first(&cache->lru_list)) { + } OBJ_DESTRUCT(&cache->lru_list); OBJ_DESTRUCT(&cache->gc_lifo); @@ -100,17 +100,17 @@ static void mca_rcache_grdma_cache_destructor (mca_rcache_grdma_cache_t *cache) OBJ_RELEASE(cache->vma_module); } - free (cache->cache_name); + free(cache->cache_name); } -OBJ_CLASS_INSTANCE(mca_rcache_grdma_cache_t, opal_list_item_t, - mca_rcache_grdma_cache_contructor, +OBJ_CLASS_INSTANCE(mca_rcache_grdma_cache_t, opal_list_item_t, mca_rcache_grdma_cache_contructor, mca_rcache_grdma_cache_destructor); /* * Initializes the rcache module. */ -void mca_rcache_grdma_module_init(mca_rcache_grdma_module_t* rcache, mca_rcache_grdma_cache_t *cache) +void mca_rcache_grdma_module_init(mca_rcache_grdma_module_t *rcache, + mca_rcache_grdma_cache_t *cache) { OBJ_RETAIN(cache); rcache->cache = cache; @@ -127,11 +127,9 @@ void mca_rcache_grdma_module_init(mca_rcache_grdma_module_t* rcache, mca_rcache_ rcache->stat_cache_found = rcache->stat_cache_notfound = 0; OBJ_CONSTRUCT(&rcache->reg_list, opal_free_list_t); - opal_free_list_init (&rcache->reg_list, rcache->resources.sizeof_reg, - opal_cache_line_size, - OBJ_CLASS(mca_rcache_base_registration_t), - 0, opal_cache_line_size, 0, -1, 32, NULL, 0, - NULL, NULL, NULL); + opal_free_list_init(&rcache->reg_list, rcache->resources.sizeof_reg, opal_cache_line_size, + OBJ_CLASS(mca_rcache_base_registration_t), 0, opal_cache_line_size, 0, -1, + 32, NULL, 0, NULL, NULL, NULL); } static inline int dereg_mem(mca_rcache_base_registration_t *reg) @@ -142,13 +140,12 @@ static inline int dereg_mem(mca_rcache_base_registration_t *reg) reg->ref_count = 0; if (!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) { - mca_rcache_base_vma_delete (rcache_grdma->cache->vma_module, reg); + mca_rcache_base_vma_delete(rcache_grdma->cache->vma_module, reg); } - rc = rcache_grdma->resources.deregister_mem (rcache_grdma->resources.reg_data, reg); + rc = rcache_grdma->resources.deregister_mem(rcache_grdma->resources.reg_data, reg); if (OPAL_LIKELY(OPAL_SUCCESS == rc)) { - opal_free_list_return_mt (&rcache_grdma->reg_list, - (opal_free_list_item_t *) reg); + opal_free_list_return_mt(&rcache_grdma->reg_list, (opal_free_list_item_t *) reg); } OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_rcache_base_framework.framework_output, @@ -156,28 +153,30 @@ static inline int dereg_mem(mca_rcache_base_registration_t *reg) return rc; } -static inline void do_unregistration_gc (mca_rcache_base_module_t *rcache) +static inline void do_unregistration_gc(mca_rcache_base_module_t *rcache) { mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; opal_list_item_t *item; /* Remove registration from garbage collection list before deregistering it */ - while (NULL != (item = opal_lifo_pop_atomic (&rcache_grdma->cache->gc_lifo))) { + while (NULL != (item = opal_lifo_pop_atomic(&rcache_grdma->cache->gc_lifo))) { OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_rcache_base_framework.framework_output, "deleting stale registration %p", (void *) item)); - dereg_mem ((mca_rcache_base_registration_t *) item); + dereg_mem((mca_rcache_base_registration_t *) item); } } -static inline mca_rcache_base_registration_t *mca_rcache_grdma_remove_lru_head(mca_rcache_grdma_cache_t *cache) { +static inline mca_rcache_base_registration_t * +mca_rcache_grdma_remove_lru_head(mca_rcache_grdma_cache_t *cache) +{ mca_rcache_base_registration_t *old_reg; int32_t old_flags; do { - opal_mutex_lock (&cache->vma_module->vma_lock); - old_reg = (mca_rcache_base_registration_t *) opal_list_remove_first (&cache->lru_list); + opal_mutex_lock(&cache->vma_module->vma_lock); + old_reg = (mca_rcache_base_registration_t *) opal_list_remove_first(&cache->lru_list); if (NULL == old_reg) { - opal_mutex_unlock (&cache->vma_module->vma_lock); + opal_mutex_unlock(&cache->vma_module->vma_lock); break; } @@ -187,11 +186,12 @@ static inline mca_rcache_base_registration_t *mca_rcache_grdma_remove_lru_head(m /* registration has been selected for removal and is no longer in the LRU. mark it * as such. */ new_flags = (old_flags & ~MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU) | MCA_RCACHE_FLAGS_INVALID; - if (opal_atomic_compare_exchange_strong_32((opal_atomic_int32_t*)&old_reg->flags, &old_flags, new_flags)) { + if (opal_atomic_compare_exchange_strong_32((opal_atomic_int32_t *) &old_reg->flags, + &old_flags, new_flags)) { break; } } while (1); - opal_mutex_unlock (&cache->vma_module->vma_lock); + opal_mutex_unlock(&cache->vma_module->vma_lock); if (old_flags & MCA_RCACHE_FLAGS_INVALID) { /* registration was already invalidated. in this case its fate is being determined @@ -205,7 +205,7 @@ static inline mca_rcache_base_registration_t *mca_rcache_grdma_remove_lru_head(m return NULL; } -static inline bool mca_rcache_grdma_evict_lru_local (mca_rcache_grdma_cache_t *cache) +static inline bool mca_rcache_grdma_evict_lru_local(mca_rcache_grdma_cache_t *cache) { mca_rcache_grdma_module_t *rcache_grdma; mca_rcache_base_registration_t *old_reg; @@ -217,15 +217,15 @@ static inline bool mca_rcache_grdma_evict_lru_local (mca_rcache_grdma_cache_t *c rcache_grdma = (mca_rcache_grdma_module_t *) old_reg->rcache; - (void) dereg_mem (old_reg); + (void) dereg_mem(old_reg); rcache_grdma->stat_evicted++; return true; } -static bool mca_rcache_grdma_evict (mca_rcache_base_module_t *rcache) +static bool mca_rcache_grdma_evict(mca_rcache_base_module_t *rcache) { - return mca_rcache_grdma_evict_lru_local (((mca_rcache_grdma_module_t *) rcache)->cache); + return mca_rcache_grdma_evict_lru_local(((mca_rcache_grdma_module_t *) rcache)->cache); } struct mca_rcache_base_find_args_t { @@ -238,44 +238,48 @@ struct mca_rcache_base_find_args_t { typedef struct mca_rcache_base_find_args_t mca_rcache_base_find_args_t; -static inline void mca_rcache_grdma_add_to_lru (mca_rcache_grdma_module_t *rcache_grdma, mca_rcache_base_registration_t *grdma_reg) +static inline void mca_rcache_grdma_add_to_lru(mca_rcache_grdma_module_t *rcache_grdma, + mca_rcache_base_registration_t *grdma_reg) { - opal_mutex_lock (&rcache_grdma->cache->vma_module->vma_lock); + opal_mutex_lock(&rcache_grdma->cache->vma_module->vma_lock); opal_list_append(&rcache_grdma->cache->lru_list, (opal_list_item_t *) grdma_reg); /* ensure the append is complete before setting the flag */ - opal_atomic_wmb (); + opal_atomic_wmb(); /* mark this registration as being in the LRU */ - opal_atomic_fetch_or_32 ((opal_atomic_int32_t *) &grdma_reg->flags, MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU); + opal_atomic_fetch_or_32((opal_atomic_int32_t *) &grdma_reg->flags, + MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU); - opal_mutex_unlock (&rcache_grdma->cache->vma_module->vma_lock); + opal_mutex_unlock(&rcache_grdma->cache->vma_module->vma_lock); } -static inline void mca_rcache_grdma_remove_from_lru (mca_rcache_grdma_module_t *rcache_grdma, mca_rcache_base_registration_t *grdma_reg) +static inline void mca_rcache_grdma_remove_from_lru(mca_rcache_grdma_module_t *rcache_grdma, + mca_rcache_base_registration_t *grdma_reg) { /* if the reference count was observed to be 0 (which must be the case for this * function to be called then some thread deregistered the region. it may be the * case that the deregistration is still ongoing so wait until the deregistration * thread has marked this registration as being in the lru before continuing */ - while (!(grdma_reg->flags & MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU)); + while (!(grdma_reg->flags & MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU)) { + } /* opal lists are not thread safe at this time so we must lock :'( */ - opal_mutex_lock (&rcache_grdma->cache->vma_module->vma_lock); - opal_list_remove_item (&rcache_grdma->cache->lru_list, (opal_list_item_t *) grdma_reg); + opal_mutex_lock(&rcache_grdma->cache->vma_module->vma_lock); + opal_list_remove_item(&rcache_grdma->cache->lru_list, (opal_list_item_t *) grdma_reg); /* clear the LRU flag */ grdma_reg->flags &= ~MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU; - opal_mutex_unlock (&rcache_grdma->cache->vma_module->vma_lock); + opal_mutex_unlock(&rcache_grdma->cache->vma_module->vma_lock); } -static int mca_rcache_grdma_check_cached (mca_rcache_base_registration_t *grdma_reg, void *ctx) +static int mca_rcache_grdma_check_cached(mca_rcache_base_registration_t *grdma_reg, void *ctx) { mca_rcache_base_find_args_t *args = (mca_rcache_base_find_args_t *) ctx; mca_rcache_grdma_module_t *rcache_grdma = args->rcache_grdma; - if ((grdma_reg->flags & MCA_RCACHE_FLAGS_INVALID) || &rcache_grdma->super != grdma_reg->rcache || - grdma_reg->base > args->base || grdma_reg->bound < args->bound) { + if ((grdma_reg->flags & MCA_RCACHE_FLAGS_INVALID) || &rcache_grdma->super != grdma_reg->rcache + || grdma_reg->base > args->base || grdma_reg->bound < args->bound) { return 0; } @@ -283,37 +287,38 @@ static int mca_rcache_grdma_check_cached (mca_rcache_base_registration_t *grdma_ args->access_flags |= grdma_reg->access_flags; /* can't use this registration */ - return mca_rcache_grdma_add_to_gc (grdma_reg); + return mca_rcache_grdma_add_to_gc(grdma_reg); } - int32_t ref_cnt = opal_atomic_fetch_add_32 (&grdma_reg->ref_count, 1); + int32_t ref_cnt = opal_atomic_fetch_add_32(&grdma_reg->ref_count, 1); args->reg = grdma_reg; if (0 == ref_cnt) { - mca_rcache_grdma_remove_from_lru (rcache_grdma, grdma_reg); + mca_rcache_grdma_remove_from_lru(rcache_grdma, grdma_reg); } /* This segment fits fully within an existing segment. */ - (void) opal_atomic_fetch_add_32 ((opal_atomic_int32_t *) &rcache_grdma->stat_cache_hit, 1); + (void) opal_atomic_fetch_add_32((opal_atomic_int32_t *) &rcache_grdma->stat_cache_hit, 1); OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_rcache_base_framework.framework_output, - "returning existing registration %p. references %d", (void *) grdma_reg, ref_cnt)); + "returning existing registration %p. references %d", (void *) grdma_reg, + ref_cnt)); return 1; } /* * register memory */ -static int mca_rcache_grdma_register (mca_rcache_base_module_t *rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, - mca_rcache_base_registration_t **reg) +static int mca_rcache_grdma_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, + mca_rcache_base_registration_t **reg) { - mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t*)rcache; + mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; const bool bypass_cache = !!(flags & MCA_RCACHE_FLAGS_CACHE_BYPASS); const bool persist = !!(flags & MCA_RCACHE_FLAGS_PERSIST); mca_rcache_base_registration_t *grdma_reg; opal_free_list_item_t *item; unsigned char *base, *bound; - unsigned int page_size = opal_getpagesize (); + unsigned int page_size = opal_getpagesize(); int rc; *reg = NULL; @@ -333,17 +338,19 @@ static int mca_rcache_grdma_register (mca_rcache_base_module_t *rcache, void *ad } #endif /* OPAL_CUDA_GDR_SUPPORT */ - do_unregistration_gc (rcache); + do_unregistration_gc(rcache); /* look through existing regs if not persistent registration requested. * Persistent registration are always registered and placed in the cache */ if (!(bypass_cache || persist)) { - mca_rcache_base_find_args_t find_args = {.reg = NULL, .rcache_grdma = rcache_grdma, - .base = base, .bound = bound, + mca_rcache_base_find_args_t find_args = {.reg = NULL, + .rcache_grdma = rcache_grdma, + .base = base, + .bound = bound, .access_flags = access_flags}; /* check to see if memory is registered */ - rc = mca_rcache_base_vma_iterate (rcache_grdma->cache->vma_module, base, size, false, - mca_rcache_grdma_check_cached, (void *) &find_args); + rc = mca_rcache_base_vma_iterate(rcache_grdma->cache->vma_module, base, size, false, + mca_rcache_grdma_check_cached, (void *) &find_args); if (1 == rc) { *reg = find_args.reg; return OPAL_SUCCESS; @@ -355,11 +362,11 @@ static int mca_rcache_grdma_register (mca_rcache_base_module_t *rcache, void *ad OPAL_THREAD_ADD_FETCH32((opal_atomic_int32_t *) &rcache_grdma->stat_cache_miss, 1); } - item = opal_free_list_get_mt (&rcache_grdma->reg_list); - if(NULL == item) { + item = opal_free_list_get_mt(&rcache_grdma->reg_list); + if (NULL == item) { return OPAL_ERR_OUT_OF_RESOURCE; } - grdma_reg = (mca_rcache_base_registration_t*)item; + grdma_reg = (mca_rcache_base_registration_t *) item; grdma_reg->rcache = rcache; grdma_reg->base = base; @@ -373,17 +380,17 @@ static int mca_rcache_grdma_register (mca_rcache_base_module_t *rcache, void *ad } #endif /* OPAL_CUDA_GDR_SUPPORT */ - while (OPAL_ERR_OUT_OF_RESOURCE == - (rc = rcache_grdma->resources.register_mem(rcache_grdma->resources.reg_data, - base, bound - base + 1, grdma_reg))) { + while (OPAL_ERR_OUT_OF_RESOURCE + == (rc = rcache_grdma->resources.register_mem(rcache_grdma->resources.reg_data, base, + bound - base + 1, grdma_reg))) { /* try to remove one unused reg and retry */ - if (!mca_rcache_grdma_evict (rcache)) { + if (!mca_rcache_grdma_evict(rcache)) { break; } } if (OPAL_UNLIKELY(rc != OPAL_SUCCESS)) { - opal_free_list_return_mt (&rcache_grdma->reg_list, item); + opal_free_list_return_mt(&rcache_grdma->reg_list, item); return rc; } @@ -393,80 +400,78 @@ static int mca_rcache_grdma_register (mca_rcache_base_module_t *rcache, void *ad * no leave pinned protocol is in use but the same segment is in * use in multiple simultaneous transactions. We used to set bypass_cache * here is !mca_rcache_grdma_component.leave_pinned. */ - rc = mca_rcache_base_vma_insert (rcache_grdma->cache->vma_module, grdma_reg, 0); + rc = mca_rcache_base_vma_insert(rcache_grdma->cache->vma_module, grdma_reg, 0); if (OPAL_UNLIKELY(rc != OPAL_SUCCESS)) { - rcache_grdma->resources.deregister_mem (rcache_grdma->resources.reg_data, grdma_reg); - opal_free_list_return_mt (&rcache_grdma->reg_list, item); + rcache_grdma->resources.deregister_mem(rcache_grdma->resources.reg_data, grdma_reg); + opal_free_list_return_mt(&rcache_grdma->reg_list, item); return rc; } } OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_rcache_base_framework.framework_output, "created new registration %p for region {%p, %p} with flags 0x%x", - (void *)grdma_reg, (void*)base, (void*)bound, grdma_reg->flags)); + (void *) grdma_reg, (void *) base, (void *) bound, grdma_reg->flags)); *reg = grdma_reg; return OPAL_SUCCESS; } -static int mca_rcache_grdma_find (mca_rcache_base_module_t *rcache, void *addr, - size_t size, mca_rcache_base_registration_t **reg) +static int mca_rcache_grdma_find(mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg) { - mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t*)rcache; - unsigned long page_size = opal_getpagesize (); + mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; + unsigned long page_size = opal_getpagesize(); unsigned char *base, *bound; int rc; base = OPAL_DOWN_ALIGN_PTR(addr, page_size, unsigned char *); bound = OPAL_ALIGN_PTR((intptr_t) addr + size - 1, page_size, unsigned char *); - opal_mutex_lock (&rcache_grdma->cache->vma_module->vma_lock); - - rc = mca_rcache_base_vma_find (rcache_grdma->cache->vma_module, base, bound - base + 1, reg); - if(NULL != *reg && - (mca_rcache_grdma_component.leave_pinned || - ((*reg)->flags & MCA_RCACHE_FLAGS_PERSIST) || - ((*reg)->base == base && (*reg)->bound == bound))) { - assert(((void*)(*reg)->bound) >= addr); - if(0 == (*reg)->ref_count && - mca_rcache_grdma_component.leave_pinned) { - opal_list_remove_item(&rcache_grdma->cache->lru_list, - (opal_list_item_t*)(*reg)); + opal_mutex_lock(&rcache_grdma->cache->vma_module->vma_lock); + + rc = mca_rcache_base_vma_find(rcache_grdma->cache->vma_module, base, bound - base + 1, reg); + if (NULL != *reg + && (mca_rcache_grdma_component.leave_pinned || ((*reg)->flags & MCA_RCACHE_FLAGS_PERSIST) + || ((*reg)->base == base && (*reg)->bound == bound))) { + assert(((void *) (*reg)->bound) >= addr); + if (0 == (*reg)->ref_count && mca_rcache_grdma_component.leave_pinned) { + opal_list_remove_item(&rcache_grdma->cache->lru_list, (opal_list_item_t *) (*reg)); } rcache_grdma->stat_cache_found++; - opal_atomic_add_fetch_32 (&(*reg)->ref_count, 1); + opal_atomic_add_fetch_32(&(*reg)->ref_count, 1); } else { rcache_grdma->stat_cache_notfound++; } - opal_mutex_unlock (&rcache_grdma->cache->vma_module->vma_lock); + opal_mutex_unlock(&rcache_grdma->cache->vma_module->vma_lock); return rc; } -static int mca_rcache_grdma_deregister (mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg) +static int mca_rcache_grdma_deregister(mca_rcache_base_module_t *rcache, + mca_rcache_base_registration_t *reg) { mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; int32_t ref_count; - ref_count = opal_atomic_add_fetch_32 (®->ref_count, -1); + ref_count = opal_atomic_add_fetch_32(®->ref_count, -1); OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_rcache_base_framework.framework_output, - "returning registration %p, remaining references %d", (void *) reg, ref_count)); + "returning registration %p, remaining references %d", (void *) reg, + ref_count)); - assert (ref_count >= 0); + assert(ref_count >= 0); if (ref_count > 0) { return OPAL_SUCCESS; } if (registration_is_cacheable(reg)) { - mca_rcache_grdma_add_to_lru (rcache_grdma, reg); + mca_rcache_grdma_add_to_lru(rcache_grdma, reg); return OPAL_SUCCESS; } - return dereg_mem (reg); + return dereg_mem(reg); } struct gc_add_args_t { @@ -475,10 +480,11 @@ struct gc_add_args_t { }; typedef struct gc_add_args_t gc_add_args_t; -static int mca_rcache_grdma_add_to_gc (mca_rcache_base_registration_t *grdma_reg) +static int mca_rcache_grdma_add_to_gc(mca_rcache_base_registration_t *grdma_reg) { mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) grdma_reg->rcache; - uint32_t flags = opal_atomic_fetch_or_32 ((opal_atomic_int32_t *) &grdma_reg->flags, MCA_RCACHE_FLAGS_INVALID); + uint32_t flags = opal_atomic_fetch_or_32((opal_atomic_int32_t *) &grdma_reg->flags, + MCA_RCACHE_FLAGS_INVALID); if ((flags & MCA_RCACHE_FLAGS_INVALID) || 0 != grdma_reg->ref_count) { /* nothing to do */ @@ -488,16 +494,16 @@ static int mca_rcache_grdma_add_to_gc (mca_rcache_base_registration_t *grdma_reg /* This may be called from free() so avoid recursively calling into free by just * shifting this registration into the garbage collection list. The cleanup will * be done on the next registration attempt. */ - if (registration_flags_cacheable (flags)) { - mca_rcache_grdma_remove_from_lru (rcache_grdma, grdma_reg); + if (registration_flags_cacheable(flags)) { + mca_rcache_grdma_remove_from_lru(rcache_grdma, grdma_reg); } - opal_lifo_push_atomic (&rcache_grdma->cache->gc_lifo, (opal_list_item_t *) grdma_reg); + opal_lifo_push_atomic(&rcache_grdma->cache->gc_lifo, (opal_list_item_t *) grdma_reg); return OPAL_SUCCESS; } -static int gc_add (mca_rcache_base_registration_t *grdma_reg, void *ctx) +static int gc_add(mca_rcache_base_registration_t *grdma_reg, void *ctx) { gc_add_args_t *args = (gc_add_args_t *) ctx; @@ -516,15 +522,16 @@ static int gc_add (mca_rcache_base_registration_t *grdma_reg, void *ctx) return OPAL_ERROR; } - return mca_rcache_grdma_add_to_gc (grdma_reg); + return mca_rcache_grdma_add_to_gc(grdma_reg); } -static int mca_rcache_grdma_invalidate_range (mca_rcache_base_module_t *rcache, - void *base, size_t size) +static int mca_rcache_grdma_invalidate_range(mca_rcache_base_module_t *rcache, void *base, + size_t size) { mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; gc_add_args_t args = {.base = base, .size = size}; - return mca_rcache_base_vma_iterate (rcache_grdma->cache->vma_module, base, size, true, gc_add, &args); + return mca_rcache_base_vma_iterate(rcache_grdma->cache->vma_module, base, size, true, gc_add, + &args); } /* Make sure this registration request is not stale. In other words, ensure @@ -533,12 +540,12 @@ static int mca_rcache_grdma_invalidate_range (mca_rcache_base_module_t *rcache, * with the rcache->vma_module->vma_lock held. */ #if OPAL_CUDA_GDR_SUPPORT -static int check_for_cuda_freed_memory (mca_rcache_base_module_t *rcache, void *addr, size_t size) +static int check_for_cuda_freed_memory(mca_rcache_base_module_t *rcache, void *addr, size_t size) { mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; mca_rcache_base_registration_t *reg; - mca_rcache_base_vma_find (rcache_grdma->cache->vma_module, addr, size, ®); + mca_rcache_base_vma_find(rcache_grdma->cache->vma_module, addr, size, ®); if (NULL == reg) { return OPAL_SUCCESS; } @@ -551,29 +558,31 @@ static int check_for_cuda_freed_memory (mca_rcache_base_module_t *rcache, void * /* This memory has been freed. Find all registrations and delete. Ensure they are deregistered * now by passing dereg_mem as the delete function. This is safe because the vma lock is * recursive and this is only called from register. */ - return mca_rcache_base_vma_iterate (rcache_grdma->cache->vma_module, addr, size, true, gc_add, NULL); + return mca_rcache_base_vma_iterate(rcache_grdma->cache->vma_module, addr, size, true, gc_add, + NULL); } #endif /* OPAL_CUDA_GDR_SUPPORT */ -static void mca_rcache_grdma_finalize (mca_rcache_base_module_t *rcache) +static void mca_rcache_grdma_finalize(mca_rcache_base_module_t *rcache) { - mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t*)rcache; + mca_rcache_grdma_module_t *rcache_grdma = (mca_rcache_grdma_module_t *) rcache; /* Statistic */ if (true == mca_rcache_grdma_component.print_stats) { - opal_output(0, "%s grdma: stats " - "(hit/miss/found/not found/evicted/tree size): %d/%d/%d/%d/%d/%ld\n", - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), - rcache_grdma->stat_cache_hit, rcache_grdma->stat_cache_miss, - rcache_grdma->stat_cache_found, rcache_grdma->stat_cache_notfound, - rcache_grdma->stat_evicted, (long) mca_rcache_base_vma_size (rcache_grdma->cache->vma_module)); + opal_output(0, + "%s grdma: stats " + "(hit/miss/found/not found/evicted/tree size): %d/%d/%d/%d/%d/%ld\n", + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), rcache_grdma->stat_cache_hit, + rcache_grdma->stat_cache_miss, rcache_grdma->stat_cache_found, + rcache_grdma->stat_cache_notfound, rcache_grdma->stat_evicted, + (long) mca_rcache_base_vma_size(rcache_grdma->cache->vma_module)); } - do_unregistration_gc (&rcache_grdma->super); + do_unregistration_gc(&rcache_grdma->super); - (void) mca_rcache_base_vma_iterate (rcache_grdma->cache->vma_module, NULL, (size_t) -1, true, - gc_add, (void *) rcache); - do_unregistration_gc (rcache); + (void) mca_rcache_base_vma_iterate(rcache_grdma->cache->vma_module, NULL, (size_t) -1, true, + gc_add, (void *) rcache); + do_unregistration_gc(rcache); OBJ_RELEASE(rcache_grdma->cache); diff --git a/opal/mca/rcache/rcache.h b/opal/mca/rcache/rcache.h index ed68deca7ac..b2abb1d259f 100644 --- a/opal/mca/rcache/rcache.h +++ b/opal/mca/rcache/rcache.h @@ -20,63 +20,62 @@ * $HEADER$ */ /** - * @file - * Description of the Registration Cache framework - */ + * @file + * Description of the Registration Cache framework + */ #ifndef MCA_RCACHE_H #define MCA_RCACHE_H #include "opal/mca/mca.h" #include "opal/mca/mpool/mpool.h" #include "opal/mca/threads/mutex.h" - /* forward-declaration of rcache module structure */ struct mca_rcache_base_module_t; typedef struct mca_rcache_base_module_t mca_rcache_base_module_t; enum { /** bypass the cache when registering */ - MCA_RCACHE_FLAGS_CACHE_BYPASS = 0x0001, + MCA_RCACHE_FLAGS_CACHE_BYPASS = 0x0001, /** persistent registration */ - MCA_RCACHE_FLAGS_PERSIST = 0x0002, + MCA_RCACHE_FLAGS_PERSIST = 0x0002, /** registation requires strong ordering (disables relaxed ordering) */ - MCA_RCACHE_FLAGS_SO_MEM = 0x0004, + MCA_RCACHE_FLAGS_SO_MEM = 0x0004, /** address range is cuda buffer */ - MCA_RCACHE_FLAGS_CUDA_GPU_MEM = 0x0008, + MCA_RCACHE_FLAGS_CUDA_GPU_MEM = 0x0008, /** register with common cuda */ MCA_RCACHE_FLAGS_CUDA_REGISTER_MEM = 0x0010, /** invalid registration (no valid for passing to rcache register) */ - MCA_RCACHE_FLAGS_INVALID = 0x0080, + MCA_RCACHE_FLAGS_INVALID = 0x0080, /** reserved for rcache module */ - MCA_RCACHE_FLAGS_MOD_RESV0 = 0x0100, + MCA_RCACHE_FLAGS_MOD_RESV0 = 0x0100, /** reserved for rcache module */ - MCA_RCACHE_FLAGS_MOD_RESV1 = 0x0200, + MCA_RCACHE_FLAGS_MOD_RESV1 = 0x0200, /** reserved for rcache module */ - MCA_RCACHE_FLAGS_MOD_RESV2 = 0x0400, + MCA_RCACHE_FLAGS_MOD_RESV2 = 0x0400, /** reserved for rcache module */ - MCA_RCACHE_FLAGS_MOD_RESV3 = 0x0800, + MCA_RCACHE_FLAGS_MOD_RESV3 = 0x0800, /** reserved for register function */ - MCA_RCACHE_FLAGS_RESV0 = 0x1000, + MCA_RCACHE_FLAGS_RESV0 = 0x1000, /** reserved for register function */ - MCA_RCACHE_FLAGS_RESV1 = 0x2000, + MCA_RCACHE_FLAGS_RESV1 = 0x2000, /** reserved for register function */ - MCA_RCACHE_FLAGS_RESV2 = 0x4000, + MCA_RCACHE_FLAGS_RESV2 = 0x4000, /** reserved for register function */ - MCA_RCACHE_FLAGS_RESV3 = 0x8000, + MCA_RCACHE_FLAGS_RESV3 = 0x8000, }; /** access flags */ enum { /** register for local write */ - MCA_RCACHE_ACCESS_LOCAL_WRITE = 0x01, + MCA_RCACHE_ACCESS_LOCAL_WRITE = 0x01, /** register for remote read */ - MCA_RCACHE_ACCESS_REMOTE_READ = 0x02, + MCA_RCACHE_ACCESS_REMOTE_READ = 0x02, /** register for remote write */ - MCA_RCACHE_ACCESS_REMOTE_WRITE = 0x04, + MCA_RCACHE_ACCESS_REMOTE_WRITE = 0x04, /** register for local/remote atomic operations */ MCA_RCACHE_ACCESS_REMOTE_ATOMIC = 0x08, /** register for any access */ - MCA_RCACHE_ACCESS_ANY = 0x0f, + MCA_RCACHE_ACCESS_ANY = 0x0f, }; /** base class for all rcache registrations */ @@ -111,47 +110,47 @@ typedef struct mca_rcache_base_registration_t mca_rcache_base_registration_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(mca_rcache_base_registration_t); struct mca_rcache_base_resources_t { - char *cache_name; - void *reg_data; + char *cache_name; + void *reg_data; size_t sizeof_reg; - int (*register_mem) (void *reg_data, void *base, size_t size, - mca_rcache_base_registration_t *reg); - int (*deregister_mem) (void *reg_data, mca_rcache_base_registration_t *reg); + int (*register_mem)(void *reg_data, void *base, size_t size, + mca_rcache_base_registration_t *reg); + int (*deregister_mem)(void *reg_data, mca_rcache_base_registration_t *reg); }; typedef struct mca_rcache_base_resources_t mca_rcache_base_resources_t; - /** * component initialize */ -typedef struct mca_rcache_base_module_t *(*mca_rcache_base_component_init_fn_t)(mca_rcache_base_resources_t *); +typedef struct mca_rcache_base_module_t *(*mca_rcache_base_component_init_fn_t)( + mca_rcache_base_resources_t *); /** - * register memory - */ -typedef int (*mca_rcache_base_module_register_fn_t) (mca_rcache_base_module_t *rcache, - void *addr, size_t size, uint32_t flags, - int32_t access_flags, - mca_rcache_base_registration_t **reg); + * register memory + */ +typedef int (*mca_rcache_base_module_register_fn_t)(mca_rcache_base_module_t *rcache, void *addr, + size_t size, uint32_t flags, + int32_t access_flags, + mca_rcache_base_registration_t **reg); /** - * deregister memory - */ -typedef int (*mca_rcache_base_module_deregister_fn_t) (mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg); + * deregister memory + */ +typedef int (*mca_rcache_base_module_deregister_fn_t)(mca_rcache_base_module_t *rcache, + mca_rcache_base_registration_t *reg); /** * find registration in this memory pool */ -typedef int (*mca_rcache_base_module_find_fn_t) (mca_rcache_base_module_t *rcache, void *addr, - size_t size, mca_rcache_base_registration_t **reg); +typedef int (*mca_rcache_base_module_find_fn_t)(mca_rcache_base_module_t *rcache, void *addr, + size_t size, mca_rcache_base_registration_t **reg); /** * release memory region */ -typedef int (*mca_rcache_base_module_invalidate_range_fn_t) (mca_rcache_base_module_t *rcache, - void *addr, size_t size); +typedef int (*mca_rcache_base_module_invalidate_range_fn_t)(mca_rcache_base_module_t *rcache, + void *addr, size_t size); /** * evict one stale registration @@ -159,11 +158,11 @@ typedef int (*mca_rcache_base_module_invalidate_range_fn_t) (mca_rcache_base_mod * @returns true if successful * @returns false if no registration could be evicted */ -typedef bool (*mca_rcache_base_module_evict_fn_t) (mca_rcache_base_module_t *rcache); +typedef bool (*mca_rcache_base_module_evict_fn_t)(mca_rcache_base_module_t *rcache); /** - * finalize - */ + * finalize + */ typedef void (*mca_rcache_base_module_finalize_fn_t)(mca_rcache_base_module_t *rcache); /** @@ -171,9 +170,9 @@ typedef void (*mca_rcache_base_module_finalize_fn_t)(mca_rcache_base_module_t *r * open/close/init functions */ -struct mca_rcache_base_component_2_0_0_t{ - mca_base_component_t rcache_version; /**< version */ - mca_base_component_data_t rcache_data; /** +# include #endif #ifdef HAVE_MALLOC_H -#include +# include #endif /* @@ -40,37 +40,34 @@ static int rgpusm_open(void); static int rgpusm_close(void); static int rgpusm_register(void); -static mca_rcache_base_module_t* rgpusm_init(struct mca_rcache_base_resources_t* resources); +static mca_rcache_base_module_t *rgpusm_init(struct mca_rcache_base_resources_t *resources); static int opal_rcache_rgpusm_verbose = 0; mca_rcache_rgpusm_component_t mca_rcache_rgpusm_component = { - { - /* First, the mca_base_component_t struct containing meta - information about the component itself */ - - .rcache_version = { - MCA_RCACHE_BASE_VERSION_3_0_0, - - .mca_component_name = "rgpusm", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - .mca_open_component = rgpusm_open, - .mca_close_component = rgpusm_close, - .mca_register_component_params = rgpusm_register, - }, - .rcache_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - - .rcache_init = rgpusm_init - } -}; + {/* First, the mca_base_component_t struct containing meta + information about the component itself */ + + .rcache_version = + { + MCA_RCACHE_BASE_VERSION_3_0_0, + + .mca_component_name = "rgpusm", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + .mca_open_component = rgpusm_open, + .mca_close_component = rgpusm_close, + .mca_register_component_params = rgpusm_register, + }, + .rcache_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + .rcache_init = rgpusm_init}}; /** - * component open/close/init function - */ + * component open/close/init function + */ static int rgpusm_open(void) { mca_rcache_rgpusm_component.output = opal_output_open(NULL); @@ -79,42 +76,37 @@ static int rgpusm_open(void) return OPAL_SUCCESS; } - static int rgpusm_register(void) { mca_rcache_rgpusm_component.rcache_name = "vma"; - (void) mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, - "rcache_name", - "The name of the registration cache the rcache should use", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_rcache_rgpusm_component.rcache_name); + (void) + mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, + "rcache_name", + "The name of the registration cache the rcache should use", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, + &mca_rcache_rgpusm_component.rcache_name); mca_rcache_rgpusm_component.rcache_size_limit = 0; (void) mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, "rcache_size_limit", "the maximum size of registration cache in bytes. " "0 is unlimited (default 0)", MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, + OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_rgpusm_component.rcache_size_limit); mca_rcache_rgpusm_component.leave_pinned = 1; - (void) mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, - "leave_pinned", - "Whether to keep memory handles around or release them when done. ", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_rcache_rgpusm_component.leave_pinned); + (void) mca_base_component_var_register( + &mca_rcache_rgpusm_component.super.rcache_version, "leave_pinned", + "Whether to keep memory handles around or release them when done. ", MCA_BASE_VAR_TYPE_INT, + NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, + &mca_rcache_rgpusm_component.leave_pinned); mca_rcache_rgpusm_component.print_stats = false; (void) mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, "print_stats", "print pool usage statistics at the end of the run", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_rgpusm_component.print_stats); @@ -122,39 +114,36 @@ static int rgpusm_register(void) opal_rcache_rgpusm_verbose = 0; (void) mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, "verbose", "Set level of rcache rgpusm verbosity", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_9, + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &opal_rcache_rgpusm_verbose); /* Force emptying of entire registration cache when it gets full */ mca_rcache_rgpusm_component.empty_cache = false; - (void) mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, - "empty_cache", "When set, empty entire registration cache when it is full", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &mca_rcache_rgpusm_component.empty_cache); + (void) + mca_base_component_var_register(&mca_rcache_rgpusm_component.super.rcache_version, + "empty_cache", + "When set, empty entire registration cache when it is full", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_READONLY, + &mca_rcache_rgpusm_component.empty_cache); return OPAL_SUCCESS; } - static int rgpusm_close(void) { return OPAL_SUCCESS; } - -static mca_rcache_base_module_t* rgpusm_init( - struct mca_rcache_base_resources_t *resources) +static mca_rcache_base_module_t *rgpusm_init(struct mca_rcache_base_resources_t *resources) { - mca_rcache_rgpusm_module_t* rcache_module; + mca_rcache_rgpusm_module_t *rcache_module; /* ignore passed in resource structure */ (void) resources; - rcache_module = (mca_rcache_rgpusm_module_t *) calloc (1, sizeof (*rcache_module)); + rcache_module = (mca_rcache_rgpusm_module_t *) calloc(1, sizeof(*rcache_module)); if (NULL == rcache_module) { return NULL; } diff --git a/opal/mca/rcache/rgpusm/rcache_rgpusm_module.c b/opal/mca/rcache/rgpusm/rcache_rgpusm_module.c index 38645cb2768..cd15a14088b 100644 --- a/opal/mca/rcache/rgpusm/rcache_rgpusm_module.c +++ b/opal/mca/rcache/rgpusm/rcache_rgpusm_module.c @@ -84,38 +84,36 @@ #include #include #ifdef HAVE_MALLOC_H -#include +# include #endif -#include "opal/util/proc.h" -#include "opal/mca/rcache/rcache.h" -#include "opal/mca/rcache/base/base.h" -#include "opal/mca/rcache/base/base.h" #include "opal/mca/common/cuda/common_cuda.h" - +#include "opal/mca/rcache/base/base.h" +#include "opal/mca/rcache/rcache.h" +#include "opal/util/proc.h" static int mca_rcache_rgpusm_deregister_no_lock(struct mca_rcache_base_module_t *, - mca_rcache_base_registration_t *); -static inline bool mca_rcache_rgpusm_deregister_lru (mca_rcache_base_module_t *rcache) { + mca_rcache_base_registration_t *); +static inline bool mca_rcache_rgpusm_deregister_lru(mca_rcache_base_module_t *rcache) +{ mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t *) rcache; mca_rcache_base_registration_t *old_reg; int rc; /* Remove the registration from the cache and list before deregistering the memory */ - old_reg = (mca_rcache_base_registration_t*) - opal_list_remove_first (&rcache_rgpusm->lru_list); + old_reg = (mca_rcache_base_registration_t *) opal_list_remove_first(&rcache_rgpusm->lru_list); if (NULL == old_reg) { opal_output_verbose(10, mca_rcache_rgpusm_component.output, "RGPUSM: The LRU list is empty. There is nothing to deregister"); return false; } - mca_rcache_base_vma_delete (rcache_rgpusm->vma_module, old_reg); + mca_rcache_base_vma_delete(rcache_rgpusm->vma_module, old_reg); /* Drop the rcache lock while we deregister the memory */ OPAL_THREAD_UNLOCK(&rcache->lock); assert(old_reg->ref_count == 0); - rc = cuda_closememhandle (NULL, old_reg); + rc = cuda_closememhandle(NULL, old_reg); OPAL_THREAD_LOCK(&rcache->lock); /* This introduces a potential leak of registrations if @@ -124,41 +122,36 @@ static inline bool mca_rcache_rgpusm_deregister_lru (mca_rcache_base_module_t *r if (OPAL_SUCCESS != rc) { opal_output_verbose(10, mca_rcache_rgpusm_component.output, "RGPUSM: Failed to deregister the memory addr=%p, size=%d", - old_reg->base, (int)(old_reg->bound - old_reg->base + 1)); + old_reg->base, (int) (old_reg->bound - old_reg->base + 1)); return false; } - opal_free_list_return (&rcache_rgpusm->reg_list, - (opal_free_list_item_t*)old_reg); + opal_free_list_return(&rcache_rgpusm->reg_list, (opal_free_list_item_t *) old_reg); rcache_rgpusm->stat_evicted++; return true; } - /* * Initializes the rcache module. */ -void mca_rcache_rgpusm_module_init(mca_rcache_rgpusm_module_t* rcache) +void mca_rcache_rgpusm_module_init(mca_rcache_rgpusm_module_t *rcache) { rcache->super.rcache_component = &mca_rcache_rgpusm_component.super; rcache->super.rcache_register = mca_rcache_rgpusm_register; rcache->super.rcache_find = mca_rcache_rgpusm_find; rcache->super.rcache_deregister = mca_rcache_rgpusm_deregister; rcache->super.rcache_finalize = mca_rcache_rgpusm_finalize; - rcache->vma_module = mca_rcache_base_vma_module_alloc (); + rcache->vma_module = mca_rcache_base_vma_module_alloc(); OBJ_CONSTRUCT(&rcache->reg_list, opal_free_list_t); - opal_free_list_init (&rcache->reg_list, sizeof(struct mca_rcache_common_cuda_reg_t), - opal_cache_line_size, - OBJ_CLASS(mca_rcache_base_registration_t), - 0,opal_cache_line_size, - 0, -1, 32, NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&rcache->reg_list, sizeof(struct mca_rcache_common_cuda_reg_t), + opal_cache_line_size, OBJ_CLASS(mca_rcache_base_registration_t), 0, + opal_cache_line_size, 0, -1, 32, NULL, 0, NULL, NULL, NULL); OBJ_CONSTRUCT(&rcache->lru_list, opal_list_t); rcache->stat_cache_hit = rcache->stat_cache_miss = rcache->stat_evicted = 0; rcache->stat_cache_found = rcache->stat_cache_notfound = 0; rcache->stat_cache_valid = rcache->stat_cache_invalid = 0; - } /* @@ -166,22 +159,22 @@ void mca_rcache_rgpusm_module_init(mca_rcache_rgpusm_module_t* rcache) * from the remote memory. It uses the addr and size of the remote * memory for caching the registration. */ -int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, +int mca_rcache_rgpusm_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, mca_rcache_base_registration_t **reg) { - mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t*)rcache; + mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t *) rcache; mca_rcache_common_cuda_reg_t *rgpusm_reg; mca_rcache_common_cuda_reg_t *rget_reg; opal_free_list_item_t *item; int rc; - int mypeer; /* just for debugging */ + int mypeer; /* just for debugging */ /* In order to preserve the signature of the mca_rcache_rgpusm_register * function, we are using the **reg variable to not only get back the * registration information, but to hand in the memory handle received * from the remote side. */ - rget_reg = (mca_rcache_common_cuda_reg_t *)*reg; + rget_reg = (mca_rcache_common_cuda_reg_t *) *reg; mypeer = flags; flags = 0; @@ -194,41 +187,44 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, * number of registrations occuring at the same time. Since we * are not leaving the registrations pinned, the number of * registrations is unlimited and there is no need for a cache. */ - if(!mca_rcache_rgpusm_component.leave_pinned && 0 == mca_rcache_rgpusm_component.rcache_size_limit) { - item = opal_free_list_get (&rcache_rgpusm->reg_list); - if(NULL == item) { + if (!mca_rcache_rgpusm_component.leave_pinned + && 0 == mca_rcache_rgpusm_component.rcache_size_limit) { + item = opal_free_list_get(&rcache_rgpusm->reg_list); + if (NULL == item) { return OPAL_ERR_OUT_OF_RESOURCE; } - rgpusm_reg = (mca_rcache_common_cuda_reg_t*)item; + rgpusm_reg = (mca_rcache_common_cuda_reg_t *) item; rgpusm_reg->base.rcache = rcache; rgpusm_reg->base.base = addr; - rgpusm_reg->base.bound = (unsigned char *)addr + size - 1;; + rgpusm_reg->base.bound = (unsigned char *) addr + size - 1; + ; rgpusm_reg->base.flags = flags; /* Copy the memory handle received into the registration */ - memcpy(rgpusm_reg->data.memHandle, rget_reg->data.memHandle, sizeof(rget_reg->data.memHandle)); + memcpy(rgpusm_reg->data.memHandle, rget_reg->data.memHandle, + sizeof(rget_reg->data.memHandle)); /* The rget_reg registration is holding the memory handle needed * to register the remote memory. This was received from the remote * process. A pointer to the memory is returned in the alloc_base field. */ - rc = cuda_openmemhandle (addr, size, (mca_rcache_base_registration_t *)rgpusm_reg, - (mca_rcache_base_registration_t *)rget_reg); + rc = cuda_openmemhandle(addr, size, (mca_rcache_base_registration_t *) rgpusm_reg, + (mca_rcache_base_registration_t *) rget_reg); /* This error should not happen with no cache in use. */ assert(OPAL_ERR_WOULD_BLOCK != rc); - if(rc != OPAL_SUCCESS) { - opal_free_list_return (&rcache_rgpusm->reg_list, item); + if (rc != OPAL_SUCCESS) { + opal_free_list_return(&rcache_rgpusm->reg_list, item); return rc; } rgpusm_reg->base.ref_count++; - *reg = (mca_rcache_base_registration_t *)rgpusm_reg; + *reg = (mca_rcache_base_registration_t *) rgpusm_reg; return OPAL_SUCCESS; } /* Check to see if memory is registered and stored in the cache. */ OPAL_THREAD_LOCK(&rcache->lock); - mca_rcache_base_vma_find (rcache_rgpusm->vma_module, addr, size, reg); + mca_rcache_base_vma_find(rcache_rgpusm->vma_module, addr, size, reg); /* If *reg is not NULL, we have a registration. Let us see if the * memory handle matches the one we were looking for. If not, the @@ -240,11 +236,10 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, if (*reg != NULL) { rcache_rgpusm->stat_cache_hit++; opal_output_verbose(10, mca_rcache_rgpusm_component.output, - "RGPUSM: Found addr=%p,size=%d (base=%p,size=%d) in cache", - addr, (int)size, (*reg)->base, - (int)((*reg)->bound - (*reg)->base)); + "RGPUSM: Found addr=%p,size=%d (base=%p,size=%d) in cache", addr, + (int) size, (*reg)->base, (int) ((*reg)->bound - (*reg)->base)); - if (mca_common_cuda_memhandle_matches((mca_rcache_common_cuda_reg_t *)*reg, rget_reg)) { + if (mca_common_cuda_memhandle_matches((mca_rcache_common_cuda_reg_t *) *reg, rget_reg)) { /* Registration matches what was requested. All is good. */ rcache_rgpusm->stat_cache_valid++; } else { @@ -252,15 +247,14 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, opal_output_verbose(10, mca_rcache_rgpusm_component.output, "RGPUSM: Mismatched Handle: Evicting/unregistering " "addr=%p,size=%d (base=%p,size=%d) from cache", - addr, (int)size, (*reg)->base, - (int)((*reg)->bound - (*reg)->base)); + addr, (int) size, (*reg)->base, + (int) ((*reg)->bound - (*reg)->base)); /* The ref_count has to be zero as this memory cannot possibly * be in use. Assert on that just to make sure. */ assert(0 == (*reg)->ref_count); if (mca_rcache_rgpusm_component.leave_pinned) { - opal_list_remove_item(&rcache_rgpusm->lru_list, - (opal_list_item_t*)(*reg)); + opal_list_remove_item(&rcache_rgpusm->lru_list, (opal_list_item_t *) (*reg)); } /* Bump the reference count to keep things copacetic in deregister */ @@ -279,42 +273,42 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, /* If we have a registration here, then we know it is valid. */ if (*reg != NULL) { opal_output_verbose(10, mca_rcache_rgpusm_component.output, - "RGPUSM: CACHE HIT is good: ep=%d, addr=%p, size=%d in cache", - mypeer, addr, (int)size); + "RGPUSM: CACHE HIT is good: ep=%d, addr=%p, size=%d in cache", mypeer, + addr, (int) size); /* When using leave pinned, we keep an LRU list. */ if ((0 == (*reg)->ref_count) && mca_rcache_rgpusm_component.leave_pinned) { opal_output_verbose(20, mca_rcache_rgpusm_component.output, - "RGPUSM: POP OFF LRU: ep=%d, addr=%p, size=%d in cache", - mypeer, addr, (int)size); - opal_list_remove_item(&rcache_rgpusm->lru_list, - (opal_list_item_t*)(*reg)); + "RGPUSM: POP OFF LRU: ep=%d, addr=%p, size=%d in cache", mypeer, + addr, (int) size); + opal_list_remove_item(&rcache_rgpusm->lru_list, (opal_list_item_t *) (*reg)); } (*reg)->ref_count++; OPAL_THREAD_UNLOCK(&rcache->lock); - opal_output(-1, "reg->ref_count=%d", (int)(*reg)->ref_count); + opal_output(-1, "reg->ref_count=%d", (int) (*reg)->ref_count); opal_output_verbose(80, mca_rcache_rgpusm_component.output, - "RGPUSM: Found entry in cache addr=%p, size=%d", addr, (int)size); + "RGPUSM: Found entry in cache addr=%p, size=%d", addr, (int) size); return OPAL_SUCCESS; } /* If we are here, then we did not find a registration, or it was invalid, * so this is a new one, and we are going to use the cache. */ assert(NULL == *reg); - opal_output_verbose(10, mca_rcache_rgpusm_component.output, - "RGPUSM: New registration ep=%d, addr=%p, size=%d. Need to register and insert in cache", - mypeer, addr, (int)size); + opal_output_verbose( + 10, mca_rcache_rgpusm_component.output, + "RGPUSM: New registration ep=%d, addr=%p, size=%d. Need to register and insert in cache", + mypeer, addr, (int) size); - item = opal_free_list_get (&rcache_rgpusm->reg_list); - if(NULL == item) { + item = opal_free_list_get(&rcache_rgpusm->reg_list); + if (NULL == item) { OPAL_THREAD_UNLOCK(&rcache->lock); return OPAL_ERR_OUT_OF_RESOURCE; } - rgpusm_reg = (mca_rcache_common_cuda_reg_t*)item; + rgpusm_reg = (mca_rcache_common_cuda_reg_t *) item; rgpusm_reg->base.rcache = rcache; rgpusm_reg->base.base = addr; - rgpusm_reg->base.bound = (unsigned char *)addr + size - 1; + rgpusm_reg->base.bound = (unsigned char *) addr + size - 1; rgpusm_reg->base.flags = flags; /* Need the memory handle saved in the registration */ @@ -325,8 +319,8 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, * bound values may be changed by the registration. The memory * associated with the handle comes back in the alloc_base * value. */ - rc = cuda_openmemhandle (addr, size, (mca_rcache_base_registration_t *)rgpusm_reg, - (mca_rcache_base_registration_t *)rget_reg); + rc = cuda_openmemhandle(addr, size, (mca_rcache_base_registration_t *) rgpusm_reg, + (mca_rcache_base_registration_t *) rget_reg); /* There is a chance we can get the OPAL_ERR_WOULD_BLOCK from the * CUDA codes attempt to register the memory. The case that this * can happen is as follows. A block of memory is registered. @@ -343,7 +337,7 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, /* Need to make sure it is at least 4 bytes in size This will * ensure we get the hit in the cache. */ - mca_rcache_base_vma_find (rcache_rgpusm->vma_module, addr, 4, &oldreg); + mca_rcache_base_vma_find(rcache_rgpusm->vma_module, addr, 4, &oldreg); /* For most cases, we will find a registration that overlaps. * Removal of it should allow the registration we are @@ -353,8 +347,7 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, * possibly be in use. Assert on that just to make sure. */ assert(0 == oldreg->ref_count); if (mca_rcache_rgpusm_component.leave_pinned) { - opal_list_remove_item(&rcache_rgpusm->lru_list, - (opal_list_item_t*)oldreg); + opal_list_remove_item(&rcache_rgpusm->lru_list, (opal_list_item_t *) oldreg); } /* Bump the reference count to keep things copacetic in deregister */ @@ -365,8 +358,8 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, rcache_rgpusm->stat_evicted++; /* And try again. This one usually works. */ - rc = cuda_openmemhandle (addr, size, (mca_rcache_base_registration_t *)rgpusm_reg, - (mca_rcache_base_registration_t *)rget_reg); + rc = cuda_openmemhandle(addr, size, (mca_rcache_base_registration_t *) rgpusm_reg, + (mca_rcache_base_registration_t *) rget_reg); } /* There is a chance that another registration is blocking our @@ -378,25 +371,27 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, break; } /* Clear out one registration. */ - rc = cuda_openmemhandle (addr, size, (mca_rcache_base_registration_t *)rgpusm_reg, - (mca_rcache_base_registration_t *)rget_reg); + rc = cuda_openmemhandle(addr, size, (mca_rcache_base_registration_t *) rgpusm_reg, + (mca_rcache_base_registration_t *) rget_reg); } } - if(rc != OPAL_SUCCESS) { + if (rc != OPAL_SUCCESS) { OPAL_THREAD_UNLOCK(&rcache->lock); - opal_free_list_return (&rcache_rgpusm->reg_list, item); + opal_free_list_return(&rcache_rgpusm->reg_list, item); return rc; } opal_output_verbose(80, mca_rcache_rgpusm_component.output, - "RGPUSM: About to insert in rgpusm cache addr=%p, size=%d", addr, (int)size); - rc = mca_rcache_base_vma_insert (rcache_rgpusm->vma_module, (mca_rcache_base_registration_t *)rgpusm_reg, - mca_rcache_rgpusm_component.rcache_size_limit); + "RGPUSM: About to insert in rgpusm cache addr=%p, size=%d", addr, + (int) size); + rc = mca_rcache_base_vma_insert(rcache_rgpusm->vma_module, + (mca_rcache_base_registration_t *) rgpusm_reg, + mca_rcache_rgpusm_component.rcache_size_limit); if (OPAL_ERR_TEMP_OUT_OF_RESOURCE == rc) { opal_output_verbose(40, mca_rcache_rgpusm_component.output, "RGPUSM: No room in the cache - boot the first one out"); - (void)mca_rcache_rgpusm_deregister_lru(rcache); + (void) mca_rcache_rgpusm_deregister_lru(rcache); if (mca_rcache_rgpusm_component.empty_cache) { int remNum = 1; /* Empty out every registration from LRU until it is empty */ @@ -407,13 +402,15 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, } opal_output_verbose(40, mca_rcache_rgpusm_component.output, "RGPUSM: Deleted and deregistered %d entries", remNum); - rc = mca_rcache_base_vma_insert (rcache_rgpusm->vma_module, (mca_rcache_base_registration_t *)rgpusm_reg, - mca_rcache_rgpusm_component.rcache_size_limit); + rc = mca_rcache_base_vma_insert(rcache_rgpusm->vma_module, + (mca_rcache_base_registration_t *) rgpusm_reg, + mca_rcache_rgpusm_component.rcache_size_limit); } else { /* Check for room after one removal. If not, remove another one until there is space */ - while((rc = mca_rcache_base_vma_insert (rcache_rgpusm->vma_module, (mca_rcache_base_registration_t *)rgpusm_reg, - mca_rcache_rgpusm_component.rcache_size_limit)) == - OPAL_ERR_TEMP_OUT_OF_RESOURCE) { + while ((rc = mca_rcache_base_vma_insert(rcache_rgpusm->vma_module, + (mca_rcache_base_registration_t *) rgpusm_reg, + mca_rcache_rgpusm_component.rcache_size_limit)) + == OPAL_ERR_TEMP_OUT_OF_RESOURCE) { opal_output_verbose(40, mca_rcache_rgpusm_component.output, "RGPUSM: No room in the cache - boot one out"); if (!mca_rcache_rgpusm_deregister_lru(rcache)) { @@ -423,9 +420,9 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, } } - if(rc != OPAL_SUCCESS) { + if (rc != OPAL_SUCCESS) { OPAL_THREAD_UNLOCK(&rcache->lock); - opal_free_list_return (&rcache_rgpusm->reg_list, item); + opal_free_list_return(&rcache_rgpusm->reg_list, item); /* We cannot recover from this. We can be here if the size of * the cache is smaller than the amount of memory we are * trying to register in a single transfer. In that case, rc @@ -433,21 +430,21 @@ int mca_rcache_rgpusm_register (mca_rcache_base_module_t *rcache, void *addr, * that point. Therefore, just error out completely. */ opal_output_verbose(10, mca_rcache_rgpusm_component.output, - "RGPUSM: Failed to register addr=%p, size=%d", addr, (int)size); + "RGPUSM: Failed to register addr=%p, size=%d", addr, (int) size); return OPAL_ERROR; } rgpusm_reg->base.ref_count++; - *reg = (mca_rcache_base_registration_t *)rgpusm_reg; + *reg = (mca_rcache_base_registration_t *) rgpusm_reg; OPAL_THREAD_UNLOCK(&rcache->lock); return OPAL_SUCCESS; } -int mca_rcache_rgpusm_find(struct mca_rcache_base_module_t *rcache, void *addr, - size_t size, mca_rcache_base_registration_t **reg) +int mca_rcache_rgpusm_find(struct mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg) { - mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t*)rcache; + mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t *) rcache; int rc; unsigned char *base, *bound; @@ -455,11 +452,11 @@ int mca_rcache_rgpusm_find(struct mca_rcache_base_module_t *rcache, void *addr, bound = base + size - 1; /* To keep cache hits working correctly */ OPAL_THREAD_LOCK(&rcache->lock); - opal_output(-1, "Looking for addr=%p, size=%d", addr, (int)size); - rc = mca_rcache_base_vma_find (rcache_rgpusm->vma_module, addr, size, reg); - if(*reg != NULL && mca_rcache_rgpusm_component.leave_pinned) { - if(0 == (*reg)->ref_count && mca_rcache_rgpusm_component.leave_pinned) { - opal_list_remove_item(&rcache_rgpusm->lru_list, (opal_list_item_t*)(*reg)); + opal_output(-1, "Looking for addr=%p, size=%d", addr, (int) size); + rc = mca_rcache_base_vma_find(rcache_rgpusm->vma_module, addr, size, reg); + if (*reg != NULL && mca_rcache_rgpusm_component.leave_pinned) { + if (0 == (*reg)->ref_count && mca_rcache_rgpusm_component.leave_pinned) { + opal_list_remove_item(&rcache_rgpusm->lru_list, (opal_list_item_t *) (*reg)); } rcache_rgpusm->stat_cache_found++; (*reg)->ref_count++; @@ -473,51 +470,48 @@ int mca_rcache_rgpusm_find(struct mca_rcache_base_module_t *rcache, void *addr, static inline bool registration_is_cachebale(mca_rcache_base_registration_t *reg) { - return !(reg->flags & - (MCA_RCACHE_FLAGS_CACHE_BYPASS | - MCA_RCACHE_FLAGS_INVALID)); + return !(reg->flags & (MCA_RCACHE_FLAGS_CACHE_BYPASS | MCA_RCACHE_FLAGS_INVALID)); } int mca_rcache_rgpusm_deregister(struct mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg) + mca_rcache_base_registration_t *reg) { - mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t*)rcache; + mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t *) rcache; int rc = OPAL_SUCCESS; assert(reg->ref_count > 0); OPAL_THREAD_LOCK(&rcache->lock); reg->ref_count--; - opal_output(-1, "Deregister: reg->ref_count=%d", (int)reg->ref_count); - if(reg->ref_count > 0) { + opal_output(-1, "Deregister: reg->ref_count=%d", (int) reg->ref_count); + if (reg->ref_count > 0) { OPAL_THREAD_UNLOCK(&rcache->lock); return OPAL_SUCCESS; } - if(mca_rcache_rgpusm_component.leave_pinned && registration_is_cachebale(reg)) - { + if (mca_rcache_rgpusm_component.leave_pinned && registration_is_cachebale(reg)) { /* if leave_pinned is set don't deregister memory, but put it * on LRU list for future use */ opal_output_verbose(20, mca_rcache_rgpusm_component.output, - "RGPUSM: Deregister: addr=%p, size=%d: cacheable and pinned, leave in cache, PUSH IN LRU", - reg->base, (int)(reg->bound - reg->base + 1)); - opal_list_prepend(&rcache_rgpusm->lru_list, (opal_list_item_t*)reg); + "RGPUSM: Deregister: addr=%p, size=%d: cacheable and pinned, leave in " + "cache, PUSH IN LRU", + reg->base, (int) (reg->bound - reg->base + 1)); + opal_list_prepend(&rcache_rgpusm->lru_list, (opal_list_item_t *) reg); } else { /* Remove from rcache first */ - if(!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) - mca_rcache_base_vma_delete (rcache_rgpusm->vma_module, reg); + if (!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) + mca_rcache_base_vma_delete(rcache_rgpusm->vma_module, reg); /* Drop the rcache lock before deregistring the memory */ OPAL_THREAD_UNLOCK(&rcache->lock); { - assert(reg->ref_count == 0); - rc = cuda_closememhandle (NULL, reg); - } + assert(reg->ref_count == 0); + rc = cuda_closememhandle(NULL, reg); + } OPAL_THREAD_LOCK(&rcache->lock); - if(OPAL_SUCCESS == rc) { - opal_free_list_return (&rcache_rgpusm->reg_list, - (opal_free_list_item_t*)reg); + if (OPAL_SUCCESS == rc) { + opal_free_list_return(&rcache_rgpusm->reg_list, (opal_free_list_item_t *) reg); } } OPAL_THREAD_UNLOCK(&rcache->lock); @@ -526,33 +520,31 @@ int mca_rcache_rgpusm_deregister(struct mca_rcache_base_module_t *rcache, } int mca_rcache_rgpusm_deregister_no_lock(struct mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg) + mca_rcache_base_registration_t *reg) { - mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t*)rcache; + mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t *) rcache; int rc = OPAL_SUCCESS; assert(reg->ref_count > 0); reg->ref_count--; - opal_output(-1, "Deregister: reg->ref_count=%d", (int)reg->ref_count); - if(reg->ref_count > 0) { + opal_output(-1, "Deregister: reg->ref_count=%d", (int) reg->ref_count); + if (reg->ref_count > 0) { return OPAL_SUCCESS; } - if(mca_rcache_rgpusm_component.leave_pinned && registration_is_cachebale(reg)) - { + if (mca_rcache_rgpusm_component.leave_pinned && registration_is_cachebale(reg)) { /* if leave_pinned is set don't deregister memory, but put it * on LRU list for future use */ - opal_list_prepend(&rcache_rgpusm->lru_list, (opal_list_item_t*)reg); + opal_list_prepend(&rcache_rgpusm->lru_list, (opal_list_item_t *) reg); } else { /* Remove from rcache first */ - if(!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) - mca_rcache_base_vma_delete (rcache_rgpusm->vma_module, reg); + if (!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) + mca_rcache_base_vma_delete(rcache_rgpusm->vma_module, reg); assert(reg->ref_count == 0); - rc = cuda_closememhandle (NULL, reg); + rc = cuda_closememhandle(NULL, reg); - if(OPAL_SUCCESS == rc) { - opal_free_list_return (&rcache_rgpusm->reg_list, - (opal_free_list_item_t*)reg); + if (OPAL_SUCCESS == rc) { + opal_free_list_return(&rcache_rgpusm->reg_list, (opal_free_list_item_t *) reg); } } @@ -563,57 +555,55 @@ int mca_rcache_rgpusm_deregister_no_lock(struct mca_rcache_base_module_t *rcache void mca_rcache_rgpusm_finalize(struct mca_rcache_base_module_t *rcache) { - mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t*)rcache; + mca_rcache_rgpusm_module_t *rcache_rgpusm = (mca_rcache_rgpusm_module_t *) rcache; mca_rcache_base_registration_t *reg; mca_rcache_base_registration_t *regs[RGPUSM_RCACHE_NREGS]; int reg_cnt, i; int rc; /* Statistic */ - if(true == mca_rcache_rgpusm_component.print_stats) { - opal_output(0, "%s rgpusm: stats " - "(hit/valid/invalid/miss/evicted): %d/%d/%d/%d/%d\n", - OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), - rcache_rgpusm->stat_cache_hit, rcache_rgpusm->stat_cache_valid, - rcache_rgpusm->stat_cache_invalid, rcache_rgpusm->stat_cache_miss, - rcache_rgpusm->stat_evicted); + if (true == mca_rcache_rgpusm_component.print_stats) { + opal_output(0, + "%s rgpusm: stats " + "(hit/valid/invalid/miss/evicted): %d/%d/%d/%d/%d\n", + OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), rcache_rgpusm->stat_cache_hit, + rcache_rgpusm->stat_cache_valid, rcache_rgpusm->stat_cache_invalid, + rcache_rgpusm->stat_cache_miss, rcache_rgpusm->stat_evicted); } OPAL_THREAD_LOCK(&rcache->lock); do { - reg_cnt = mca_rcache_base_vma_find_all (rcache_rgpusm->vma_module, 0, (size_t)-1, - regs, RGPUSM_RCACHE_NREGS); + reg_cnt = mca_rcache_base_vma_find_all(rcache_rgpusm->vma_module, 0, (size_t) -1, regs, + RGPUSM_RCACHE_NREGS); opal_output(-1, "Registration size at finalize = %d", reg_cnt); - for(i = 0; i < reg_cnt; i++) { + for (i = 0; i < reg_cnt; i++) { reg = regs[i]; - if(reg->ref_count) { + if (reg->ref_count) { reg->ref_count = 0; /* otherway dereg will fail on assert */ } else if (mca_rcache_rgpusm_component.leave_pinned) { - opal_list_remove_item(&rcache_rgpusm->lru_list, - (opal_list_item_t*)reg); + opal_list_remove_item(&rcache_rgpusm->lru_list, (opal_list_item_t *) reg); } /* Remove from rcache first */ - mca_rcache_base_vma_delete (rcache_rgpusm->vma_module, reg); + mca_rcache_base_vma_delete(rcache_rgpusm->vma_module, reg); /* Drop lock before deregistering memory */ OPAL_THREAD_UNLOCK(&rcache->lock); assert(reg->ref_count == 0); - rc = cuda_closememhandle (NULL, reg); + rc = cuda_closememhandle(NULL, reg); OPAL_THREAD_LOCK(&rcache->lock); - if(rc != OPAL_SUCCESS) { + if (rc != OPAL_SUCCESS) { /* Potentially lose track of registrations do we have to put it back? */ continue; } - opal_free_list_return (&rcache_rgpusm->reg_list, - (opal_free_list_item_t *) reg); + opal_free_list_return(&rcache_rgpusm->reg_list, (opal_free_list_item_t *) reg); } - } while(reg_cnt == RGPUSM_RCACHE_NREGS); + } while (reg_cnt == RGPUSM_RCACHE_NREGS); OBJ_DESTRUCT(&rcache_rgpusm->lru_list); OBJ_DESTRUCT(&rcache_rgpusm->reg_list); diff --git a/opal/mca/rcache/udreg/rcache_udreg.h b/opal/mca/rcache/udreg/rcache_udreg.h index d78ef9883ae..a328ec4b3c9 100644 --- a/opal/mca/rcache/udreg/rcache_udreg.h +++ b/opal/mca/rcache/udreg/rcache_udreg.h @@ -29,13 +29,13 @@ #define MCA_RCACHE_UDREG_H #include "opal_config.h" -#include "opal/class/opal_list.h" #include "opal/class/opal_free_list.h" -#include "opal/util/event.h" +#include "opal/class/opal_list.h" #include "opal/mca/rcache/rcache.h" +#include "opal/util/event.h" #include "opal/util/proc.h" #if HAVE_SYS_MMAN_H -#include +# include #endif BEGIN_C_DECLS @@ -53,9 +53,9 @@ struct mca_rcache_udreg_resources_t { mca_rcache_base_resources_t base; /* udreg specific resources */ - bool use_kernel_cache; - bool use_evict_w_unreg; - int max_entries; + bool use_kernel_cache; + bool use_evict_w_unreg; + int max_entries; size_t page_size; }; typedef struct mca_rcache_udreg_resources_t mca_rcache_udreg_resources_t; @@ -75,7 +75,6 @@ struct mca_rcache_udreg_module_t { }; typedef struct mca_rcache_udreg_module_t mca_rcache_udreg_module_t; - /* * Initializes the rcache module. */ diff --git a/opal/mca/rcache/udreg/rcache_udreg_component.c b/opal/mca/rcache/udreg/rcache_udreg_component.c index 8a4b44b9381..c0849169bc0 100644 --- a/opal/mca/rcache/udreg/rcache_udreg_component.c +++ b/opal/mca/rcache/udreg/rcache_udreg_component.c @@ -28,10 +28,10 @@ #include "opal/runtime/opal_params.h" #include "rcache_udreg.h" #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_MALLOC_H -#include +# include #endif #include @@ -42,87 +42,79 @@ static int udreg_open(void); static int udreg_close(void); static int udreg_register(void); -static mca_rcache_base_module_t* udreg_init( - struct mca_rcache_base_resources_t* resources); +static mca_rcache_base_module_t *udreg_init(struct mca_rcache_base_resources_t *resources); mca_rcache_udreg_component_t mca_rcache_udreg_component = { - { - /* First, the mca_base_component_t struct containing meta - information about the component itself */ - - .rcache_version ={ - MCA_RCACHE_BASE_VERSION_3_0_0, - - .mca_component_name = "udreg", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - .mca_open_component = udreg_open, - .mca_close_component = udreg_close, - .mca_register_component_params = udreg_register, - }, - .rcache_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - - .rcache_init = udreg_init - } -}; + {/* First, the mca_base_component_t struct containing meta + information about the component itself */ + + .rcache_version = + { + MCA_RCACHE_BASE_VERSION_3_0_0, + + .mca_component_name = "udreg", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + .mca_open_component = udreg_open, + .mca_close_component = udreg_close, + .mca_register_component_params = udreg_register, + }, + .rcache_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + + .rcache_init = udreg_init}}; /** - * component open/close/init function - */ + * component open/close/init function + */ static int udreg_open(void) { return OPAL_SUCCESS; } - static int udreg_register(void) { mca_rcache_udreg_component.print_stats = false; (void) mca_base_component_var_register(&mca_rcache_udreg_component.super.rcache_version, - "print_stats", "print pool usage statistics at the end of the run", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, + "print_stats", + "print pool usage statistics at the end of the run", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_udreg_component.print_stats); return OPAL_SUCCESS; } - static int udreg_close(void) { return OPAL_SUCCESS; } -static mca_rcache_base_module_t * -udreg_init(struct mca_rcache_base_resources_t *resources) +static mca_rcache_base_module_t *udreg_init(struct mca_rcache_base_resources_t *resources) { mca_rcache_udreg_resources_t *udreg_resources = (mca_rcache_udreg_resources_t *) resources; - mca_rcache_udreg_module_t* rcache_module; + mca_rcache_udreg_module_t *rcache_module; static int inited = false; int rc; /* Set this here (vs in component.c) because opal_leave_pinned* may have been set after MCA params were read (e.g., by the openib btl) */ - mca_rcache_udreg_component.leave_pinned = (int) - (1 == opal_leave_pinned || opal_leave_pinned_pipeline); + mca_rcache_udreg_component.leave_pinned = (int) (1 == opal_leave_pinned + || opal_leave_pinned_pipeline); if (!inited) { inited = true; } - rcache_module = - (mca_rcache_udreg_module_t *) malloc (sizeof (mca_rcache_udreg_module_t)); + rcache_module = (mca_rcache_udreg_module_t *) malloc(sizeof(mca_rcache_udreg_module_t)); - memmove (&rcache_module->resources, udreg_resources, sizeof (*udreg_resources)); + memmove(&rcache_module->resources, udreg_resources, sizeof(*udreg_resources)); rc = mca_rcache_udreg_module_init(rcache_module); if (OPAL_SUCCESS != rc) { - free (rcache_module); + free(rcache_module); return NULL; } diff --git a/opal/mca/rcache/udreg/rcache_udreg_module.c b/opal/mca/rcache/udreg/rcache_udreg_module.c index f6fc44e8c30..e4ff861cf31 100644 --- a/opal/mca/rcache/udreg/rcache_udreg_module.c +++ b/opal/mca/rcache/udreg/rcache_udreg_module.c @@ -31,13 +31,13 @@ #include #include #ifdef HAVE_MALLOC_H -#include +# include #endif +#include "opal/include/opal_stdint.h" #include "opal/mca/rcache/base/base.h" #include "opal/runtime/opal_params.h" -#include "opal/include/opal_stdint.h" -#include "opal/util/sys_limits.h" #include "opal/util/string_copy.h" +#include "opal/util/sys_limits.h" #include @@ -45,25 +45,23 @@ #include +static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, + mca_rcache_base_registration_t **reg); +static int mca_rcache_udreg_deregister(mca_rcache_base_module_t *rcache, + mca_rcache_base_registration_t *reg); +static int mca_rcache_udreg_find(mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg); +static void mca_rcache_udreg_finalize(mca_rcache_base_module_t *rcache); +static bool mca_rcache_udreg_evict(mca_rcache_base_module_t *rcache); -static int mca_rcache_udreg_register (mca_rcache_base_module_t* rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, - mca_rcache_base_registration_t **reg); -static int mca_rcache_udreg_deregister (mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg); -static int mca_rcache_udreg_find (mca_rcache_base_module_t* rcache, void* addr, - size_t size, mca_rcache_base_registration_t **reg); -static void mca_rcache_udreg_finalize (mca_rcache_base_module_t *rcache); -static bool mca_rcache_udreg_evict (mca_rcache_base_module_t *rcache); - -static void *mca_rcache_udreg_reg_func (void *addr, uint64_t len, void *reg_context); -static uint32_t mca_rcache_udreg_dereg_func (void *device_data, void *dreg_context); - +static void *mca_rcache_udreg_reg_func(void *addr, uint64_t len, void *reg_context); +static uint32_t mca_rcache_udreg_dereg_func(void *device_data, void *dreg_context); /* * Initializes the rcache module. */ -int mca_rcache_udreg_module_init (mca_rcache_udreg_module_t *rcache) +int mca_rcache_udreg_module_init(mca_rcache_udreg_module_t *rcache) { struct udreg_cache_attr cache_attr; int urc; @@ -93,49 +91,50 @@ int mca_rcache_udreg_module_init (mca_rcache_udreg_module_t *rcache) OBJ_CONSTRUCT(&rcache->lock, opal_mutex_t); - opal_string_copy (cache_attr.cache_name, rcache->resources.base.cache_name, UDREG_MAX_CACHENAME_LEN); - cache_attr.max_entries = rcache->resources.max_entries; - cache_attr.debug_mode = 0; - cache_attr.debug_rank = 0; - cache_attr.reg_context = rcache; - cache_attr.dreg_context = rcache; - cache_attr.destructor_context = rcache; - cache_attr.device_reg_func = mca_rcache_udreg_reg_func; - cache_attr.device_dereg_func = mca_rcache_udreg_dereg_func; + opal_string_copy(cache_attr.cache_name, rcache->resources.base.cache_name, + UDREG_MAX_CACHENAME_LEN); + cache_attr.max_entries = rcache->resources.max_entries; + cache_attr.debug_mode = 0; + cache_attr.debug_rank = 0; + cache_attr.reg_context = rcache; + cache_attr.dreg_context = rcache; + cache_attr.destructor_context = rcache; + cache_attr.device_reg_func = mca_rcache_udreg_reg_func; + cache_attr.device_dereg_func = mca_rcache_udreg_dereg_func; cache_attr.destructor_callback = NULL; - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "rcache/udreg: creating udreg cache with name %s", cache_attr.cache_name); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, + "rcache/udreg: creating udreg cache with name %s", cache_attr.cache_name); /* attempt to create the udreg cache. this will fail if one already exists */ - (void) UDREG_CacheCreate (&cache_attr); + (void) UDREG_CacheCreate(&cache_attr); - urc = UDREG_CacheAccess (rcache->resources.base.cache_name, (udreg_cache_handle_t *) &rcache->udreg_handle); + urc = UDREG_CacheAccess(rcache->resources.base.cache_name, + (udreg_cache_handle_t *) &rcache->udreg_handle); if (UDREG_RC_SUCCESS != urc) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_rcache_base_framework.framework_output, - "rcache/udreg: call to UDREG_CacheAccess failed with rc: %d", urc); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_rcache_base_framework.framework_output, + "rcache/udreg: call to UDREG_CacheAccess failed with rc: %d", urc); return OPAL_ERROR; } OBJ_CONSTRUCT(&rcache->reg_list, opal_free_list_t); - opal_free_list_init (&rcache->reg_list, rcache->resources.base.sizeof_reg, - opal_cache_line_size, OBJ_CLASS(mca_rcache_base_registration_t), - 0, opal_cache_line_size, 0, -1, 32, NULL, 0, - NULL, NULL, NULL); + opal_free_list_init(&rcache->reg_list, rcache->resources.base.sizeof_reg, opal_cache_line_size, + OBJ_CLASS(mca_rcache_base_registration_t), 0, opal_cache_line_size, 0, -1, + 32, NULL, 0, NULL, NULL, NULL); return OPAL_SUCCESS; } /* udreg callback functions */ -static void *mca_rcache_udreg_reg_func (void *addr, uint64_t size, void *reg_context) +static void *mca_rcache_udreg_reg_func(void *addr, uint64_t size, void *reg_context) { mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) reg_context; - unsigned int page_size = opal_getpagesize (); + unsigned int page_size = opal_getpagesize(); mca_rcache_base_registration_t *udreg_reg; opal_free_list_item_t *item; int rc; - item = opal_free_list_get (&rcache_udreg->reg_list); + item = opal_free_list_get(&rcache_udreg->reg_list); if (NULL == item) { return NULL; } @@ -143,26 +142,27 @@ static void *mca_rcache_udreg_reg_func (void *addr, uint64_t size, void *reg_con udreg_reg = (mca_rcache_base_registration_t *) item; udreg_reg->rcache = reg_context; - udreg_reg->base = OPAL_DOWN_ALIGN_PTR(addr, page_size, unsigned char *); + udreg_reg->base = OPAL_DOWN_ALIGN_PTR(addr, page_size, unsigned char *); udreg_reg->bound = OPAL_ALIGN_PTR((intptr_t) addr + size, page_size, unsigned char *) - 1; udreg_reg->ref_count = 0; addr = (void *) udreg_reg->base; - size = (uint64_t) (udreg_reg->bound - udreg_reg->base + 1); + size = (uint64_t)(udreg_reg->bound - udreg_reg->base + 1); /* pull the flags and access flags out of the rcache module */ udreg_reg->access_flags = rcache_udreg->requested_access_flags; udreg_reg->flags = rcache_udreg->requested_flags; - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "rcache/udreg: calling underlying register function for address range {%p, %p}", - addr, (void *)((intptr_t) addr + size)); - rc = rcache_udreg->resources.base.register_mem (rcache_udreg->resources.base.reg_data, udreg_reg->base, size, - udreg_reg); + opal_output_verbose( + MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, + "rcache/udreg: calling underlying register function for address range {%p, %p}", addr, + (void *) ((intptr_t) addr + size)); + rc = rcache_udreg->resources.base.register_mem(rcache_udreg->resources.base.reg_data, + udreg_reg->base, size, udreg_reg); if (OPAL_SUCCESS != rc) { - opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_rcache_base_framework.framework_output, - "rcache/udreg: could not register memory. rc: %d", rc); - opal_free_list_return (&rcache_udreg->reg_list, item); + opal_output_verbose(MCA_BASE_VERBOSE_WARN, opal_rcache_base_framework.framework_output, + "rcache/udreg: could not register memory. rc: %d", rc); + opal_free_list_return(&rcache_udreg->reg_list, item); /* NTH: this is the only way to get UDReg_Register to recognize a failure */ udreg_reg = UDREG_DEVICE_REG_FAILED; } @@ -170,44 +170,44 @@ static void *mca_rcache_udreg_reg_func (void *addr, uint64_t size, void *reg_con return udreg_reg; } -static uint32_t mca_rcache_udreg_dereg_func (void *device_data, void *dreg_context) +static uint32_t mca_rcache_udreg_dereg_func(void *device_data, void *dreg_context) { mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) dreg_context; mca_rcache_base_registration_t *udreg_reg = (mca_rcache_base_registration_t *) device_data; int rc; - assert (udreg_reg->ref_count == 0); + assert(udreg_reg->ref_count == 0); - rc = rcache_udreg->resources.base.deregister_mem (rcache_udreg->resources.base.reg_data, udreg_reg); + rc = rcache_udreg->resources.base.deregister_mem(rcache_udreg->resources.base.reg_data, + udreg_reg); if (OPAL_LIKELY(OPAL_SUCCESS == rc)) { - opal_free_list_return (&rcache_udreg->reg_list, - (opal_free_list_item_t *) udreg_reg); + opal_free_list_return(&rcache_udreg->reg_list, (opal_free_list_item_t *) udreg_reg); } /* might be worth printing out a warning if an error occurs here */ return 0; } -static bool mca_rcache_udreg_evict (mca_rcache_base_module_t *rcache) +static bool mca_rcache_udreg_evict(mca_rcache_base_module_t *rcache) { mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) rcache; udreg_return_t urc; - urc = UDREG_Evict (rcache_udreg->udreg_handle); + urc = UDREG_Evict(rcache_udreg->udreg_handle); return (UDREG_RC_SUCCESS == urc); } /* * register memory */ -static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *addr, - size_t size, uint32_t flags, int32_t access_flags, - mca_rcache_base_registration_t **reg) +static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *addr, size_t size, + uint32_t flags, int32_t access_flags, + mca_rcache_base_registration_t **reg) { mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) rcache; mca_rcache_base_registration_t *udreg_reg, *old_reg; bool bypass_cache = !!(flags & MCA_RCACHE_FLAGS_CACHE_BYPASS); - const unsigned int page_size = opal_getpagesize (); + const unsigned int page_size = opal_getpagesize(); unsigned char *base, *bound; udreg_entry_t *udreg_entry = NULL; @@ -215,7 +215,8 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add OPAL_THREAD_LOCK(&rcache_udreg->lock); - /* we hold the lock so no other thread can modify these flags until the registration is complete */ + /* we hold the lock so no other thread can modify these flags until the registration is complete + */ rcache_udreg->requested_access_flags = access_flags; rcache_udreg->requested_flags = flags; @@ -223,20 +224,23 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add bound = OPAL_ALIGN_PTR((intptr_t) addr + size, page_size, unsigned char *) - 1; addr = base; - size = (size_t) (uintptr_t) (bound - base) + 1; + size = (size_t)(uintptr_t)(bound - base) + 1; if (false == bypass_cache) { /* Get a udreg entry for this region */ do { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "rcache/udreg: XXX registering region {%p, %p} with udreg", addr, (void *)((intptr_t) addr + size)); - while (UDREG_RC_SUCCESS != UDREG_Register (rcache_udreg->udreg_handle, addr, size, &udreg_entry)) { + opal_output_verbose(MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, + "rcache/udreg: XXX registering region {%p, %p} with udreg", addr, + (void *) ((intptr_t) addr + size)); + while (UDREG_RC_SUCCESS + != UDREG_Register(rcache_udreg->udreg_handle, addr, size, &udreg_entry)) { /* try to remove one unused reg and retry */ - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "calling evict!"); - if (!mca_rcache_udreg_evict (rcache)) { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "rcache/udreg: could not register memory with udreg"); + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_rcache_base_framework.framework_output, "calling evict!"); + if (!mca_rcache_udreg_evict(rcache)) { + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_rcache_base_framework.framework_output, + "rcache/udreg: could not register memory with udreg"); OPAL_THREAD_UNLOCK(&rcache_udreg->lock); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -261,7 +265,7 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add if (!old_reg->ref_count) { /* deregister the region before attempting to re-register */ - mca_rcache_udreg_dereg_func (old_reg, rcache); + mca_rcache_udreg_dereg_func(old_reg, rcache); udreg_entry->device_data = NULL; old_reg = NULL; } else { @@ -274,10 +278,12 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add rcache_udreg->requested_access_flags = access_flags; /* get a new registration */ - while (UDREG_DEVICE_REG_FAILED == (udreg_reg = mca_rcache_udreg_reg_func (addr, size, rcache))) { - if (!mca_rcache_udreg_evict (rcache)) { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "rcache/udreg: could not register memory with udreg"); + while (UDREG_DEVICE_REG_FAILED + == (udreg_reg = mca_rcache_udreg_reg_func(addr, size, rcache))) { + if (!mca_rcache_udreg_evict(rcache)) { + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_rcache_base_framework.framework_output, + "rcache/udreg: could not register memory with udreg"); OPAL_THREAD_UNLOCK(&rcache_udreg->lock); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -288,11 +294,13 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add } while (0); } else { /* if cache bypass is requested don't use the udreg cache */ - while (UDREG_DEVICE_REG_FAILED == (udreg_reg = mca_rcache_udreg_reg_func (addr, size, rcache))) { + while (UDREG_DEVICE_REG_FAILED + == (udreg_reg = mca_rcache_udreg_reg_func(addr, size, rcache))) { /* try to remove one unused reg and retry */ - if (!mca_rcache_udreg_evict (rcache)) { - opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_rcache_base_framework.framework_output, - "rcache/udreg: could not register memory"); + if (!mca_rcache_udreg_evict(rcache)) { + opal_output_verbose(MCA_BASE_VERBOSE_INFO, + opal_rcache_base_framework.framework_output, + "rcache/udreg: could not register memory"); OPAL_THREAD_UNLOCK(&rcache_udreg->lock); return OPAL_ERR_OUT_OF_RESOURCE; } @@ -308,54 +316,51 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add return OPAL_SUCCESS; } -static int mca_rcache_udreg_find (mca_rcache_base_module_t *rcache, void *addr, - size_t size, mca_rcache_base_registration_t **reg) +static int mca_rcache_udreg_find(mca_rcache_base_module_t *rcache, void *addr, size_t size, + mca_rcache_base_registration_t **reg) { *reg = NULL; return OPAL_ERR_NOT_FOUND; } static int mca_rcache_udreg_deregister(mca_rcache_base_module_t *rcache, - mca_rcache_base_registration_t *reg) + mca_rcache_base_registration_t *reg) { mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) rcache; - int32_t ref_count = OPAL_THREAD_ADD_FETCH32 (®->ref_count, -1); + int32_t ref_count = OPAL_THREAD_ADD_FETCH32(®->ref_count, -1); assert(ref_count >= 0); if (!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) { OPAL_THREAD_LOCK(&rcache_udreg->lock); - UDREG_DecrRefcount (rcache_udreg->udreg_handle, reg->rcache_context); + UDREG_DecrRefcount(rcache_udreg->udreg_handle, reg->rcache_context); OPAL_THREAD_UNLOCK(&rcache_udreg->lock); } else if (!ref_count) { - mca_rcache_udreg_dereg_func (reg, rcache); + mca_rcache_udreg_dereg_func(reg, rcache); } return OPAL_SUCCESS; } -static void mca_rcache_udreg_finalize (mca_rcache_base_module_t *rcache) +static void mca_rcache_udreg_finalize(mca_rcache_base_module_t *rcache) { - mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t*)rcache; + mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) rcache; /* Statistic */ if (true == mca_rcache_udreg_component.print_stats) { uint64_t hit = 0, miss = 0, evicted = 0; - (void) UDREG_GetStat (rcache_udreg->udreg_handle, - UDREG_STAT_CACHE_HIT, &hit); + (void) UDREG_GetStat(rcache_udreg->udreg_handle, UDREG_STAT_CACHE_HIT, &hit); - (void) UDREG_GetStat (rcache_udreg->udreg_handle, - UDREG_STAT_CACHE_MISS, &miss); + (void) UDREG_GetStat(rcache_udreg->udreg_handle, UDREG_STAT_CACHE_MISS, &miss); - (void) UDREG_GetStat (rcache_udreg->udreg_handle, - UDREG_STAT_CACHE_EVICTED, &evicted); + (void) UDREG_GetStat(rcache_udreg->udreg_handle, UDREG_STAT_CACHE_EVICTED, &evicted); opal_output(0, "%s udreg: stats (hit/miss/evicted): %" PRIu64 "/%" PRIu64 "/%" PRIu64 "\n", OPAL_NAME_PRINT(OPAL_PROC_MY_NAME), hit, miss, evicted); } - UDREG_CacheRelease (rcache_udreg->udreg_handle); + UDREG_CacheRelease(rcache_udreg->udreg_handle); OBJ_DESTRUCT(&rcache_udreg->reg_list); OBJ_DESTRUCT(&rcache_udreg->lock); } diff --git a/opal/mca/reachable/base/base.h b/opal/mca/reachable/base/base.h index 6ab36d5b62f..4e92cb048e4 100644 --- a/opal/mca/reachable/base/base.h +++ b/opal/mca/reachable/base/base.h @@ -15,8 +15,8 @@ #include "opal_config.h" #include "opal/types.h" -#include "opal/mca/mca.h" #include "opal/mca/base/mca_base_framework.h" +#include "opal/mca/mca.h" #include "opal/mca/reachable/reachable.h" @@ -29,9 +29,8 @@ OPAL_DECLSPEC extern mca_base_framework_t opal_reachable_base_framework; */ OPAL_DECLSPEC int opal_reachable_base_select(void); -OPAL_DECLSPEC opal_reachable_t * opal_reachable_allocate(unsigned int num_local, - unsigned int num_remote); - +OPAL_DECLSPEC opal_reachable_t *opal_reachable_allocate(unsigned int num_local, + unsigned int num_remote); END_C_DECLS diff --git a/opal/mca/reachable/base/reachable_base_alloc.c b/opal/mca/reachable/base/reachable_base_alloc.c index 5f3a6834883..78f3d88d701 100644 --- a/opal/mca/reachable/base/reachable_base_alloc.c +++ b/opal/mca/reachable/base/reachable_base_alloc.c @@ -12,26 +12,22 @@ #include "opal/class/opal_object.h" -#include "opal/mca/reachable/reachable.h" #include "opal/mca/reachable/base/base.h" - +#include "opal/mca/reachable/reachable.h" static void opal_reachable_construct(opal_reachable_t *reachable) { reachable->weights = NULL; } - -static void opal_reachable_destruct(opal_reachable_t * reachable) +static void opal_reachable_destruct(opal_reachable_t *reachable) { if (NULL != reachable->memory) { free(reachable->memory); } } - -opal_reachable_t * opal_reachable_allocate(unsigned int num_local, - unsigned int num_remote) +opal_reachable_t *opal_reachable_allocate(unsigned int num_local, unsigned int num_remote) { char *memory; unsigned int i; @@ -42,28 +38,23 @@ opal_reachable_t * opal_reachable_allocate(unsigned int num_local, /* allocate all the pieces of the two dimensional array in one malloc, rather than a bunch of little allocations */ - memory = malloc(sizeof(int*) * num_local + - num_local * (sizeof(int) * num_remote)); + memory = malloc(sizeof(int *) * num_local + num_local * (sizeof(int) * num_remote)); if (memory == NULL) { OBJ_RELEASE(reachable); return NULL; } - reachable->memory = (void*)memory; - reachable->weights = (int**)reachable->memory; - memory += (sizeof(int*) * num_local); + reachable->memory = (void *) memory; + reachable->weights = (int **) reachable->memory; + memory += (sizeof(int *) * num_local); for (i = 0; i < num_local; i++) { - reachable->weights[i] = (int*)memory; + reachable->weights[i] = (int *) memory; memory += (sizeof(int) * num_remote); } return reachable; } -OBJ_CLASS_INSTANCE( - opal_reachable_t, - opal_object_t, - opal_reachable_construct, - opal_reachable_destruct -); +OBJ_CLASS_INSTANCE(opal_reachable_t, opal_object_t, opal_reachable_construct, + opal_reachable_destruct); diff --git a/opal/mca/reachable/base/reachable_base_frame.c b/opal/mca/reachable/base/reachable_base_frame.c index d9781086ab9..3caa3cc9214 100644 --- a/opal/mca/reachable/base/reachable_base_frame.c +++ b/opal/mca/reachable/base/reachable_base_frame.c @@ -9,17 +9,15 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" +#include "opal/mca/base/base.h" #include "opal/mca/mca.h" #include "opal/util/output.h" -#include "opal/mca/base/base.h" #include "opal/mca/reachable/base/base.h" - /* * The following file was created by configure. It contains extern * components and the definition of an array of pointers to each @@ -47,7 +45,6 @@ static int opal_reachable_base_frame_open(mca_base_open_flag_t flags) } MCA_BASE_FRAMEWORK_DECLARE(opal, reachable, "OPAL Reachability Framework", - opal_reachable_base_frame_register, - opal_reachable_base_frame_open, - opal_reachable_base_frame_close, - mca_reachable_base_static_components, 0); + opal_reachable_base_frame_register, opal_reachable_base_frame_open, + opal_reachable_base_frame_close, mca_reachable_base_static_components, + 0); diff --git a/opal/mca/reachable/base/reachable_base_select.c b/opal/mca/reachable/base/reachable_base_select.c index 24cdfc592ed..613d5a06688 100644 --- a/opal/mca/reachable/base/reachable_base_select.c +++ b/opal/mca/reachable/base/reachable_base_select.c @@ -10,14 +10,13 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/reachable/reachable.h" +#include "opal/mca/mca.h" #include "opal/mca/reachable/base/base.h" +#include "opal/mca/reachable/reachable.h" /* * Globals @@ -32,10 +31,11 @@ int opal_reachable_base_select(void) /* * Select the best component */ - if( OPAL_SUCCESS != mca_base_select("reachable", opal_reachable_base_framework.framework_output, - &opal_reachable_base_framework.framework_components, - (mca_base_module_t **) &best_module, - (mca_base_component_t **) &best_component, NULL) ) { + if (OPAL_SUCCESS + != mca_base_select("reachable", opal_reachable_base_framework.framework_output, + &opal_reachable_base_framework.framework_components, + (mca_base_module_t **) &best_module, + (mca_base_component_t **) &best_component, NULL)) { /* notify caller that no available component found */ return OPAL_ERR_NOT_FOUND; } diff --git a/opal/mca/reachable/netlink/libnl3_utils.h b/opal/mca/reachable/netlink/libnl3_utils.h index 3668685824f..583ccc15892 100644 --- a/opal/mca/reachable/netlink/libnl3_utils.h +++ b/opal/mca/reachable/netlink/libnl3_utils.h @@ -45,38 +45,38 @@ #include #include #include -#include #include +#include typedef struct nl_sock NL_HANDLE; -#define NLMSG_SIZE(size) nlmsg_size(size) -#define NL_GETERROR(err) nl_geterror(err) -#define NL_HANDLE_ALLOC nl_socket_alloc -#define NL_HANDLE_FREE nl_socket_free +#define NLMSG_SIZE(size) nlmsg_size(size) +#define NL_GETERROR(err) nl_geterror(err) +#define NL_HANDLE_ALLOC nl_socket_alloc +#define NL_HANDLE_FREE nl_socket_free #define NL_DISABLE_SEQ_CHECK nl_socket_disable_seq_check #define INC_CB_MSGCNT(arg) /* err will be returned as -NLE_AGAIN */ /* if the socket times out */ -#define NL_RECVMSGS(nlh, cb_arg, rc, err, out) \ - do { \ - err = nl_recvmsgs_default(nlh); \ - if (err < 0) { \ - opal_output(0, "Failed to receive netlink reply message, error %s\n", \ - NL_GETERROR(err)); \ - if (err == -NLE_AGAIN) \ - err = rc; \ - goto out; \ - } \ - } while (0) +#define NL_RECVMSGS(nlh, cb_arg, rc, err, out) \ + do { \ + err = nl_recvmsgs_default(nlh); \ + if (err < 0) { \ + opal_output(0, "Failed to receive netlink reply message, error %s\n", \ + NL_GETERROR(err)); \ + if (err == -NLE_AGAIN) \ + err = rc; \ + goto out; \ + } \ + } while (0) struct opal_reachable_netlink_rt_cb_arg { - int oif; - int found; - int has_gateway; - int replied; - struct opal_reachable_netlink_sk *unlsk; + int oif; + int found; + int has_gateway; + int replied; + struct opal_reachable_netlink_sk *unlsk; }; #endif /* LIBNL3_UTILS_H */ diff --git a/opal/mca/reachable/netlink/libnl_utils.h b/opal/mca/reachable/netlink/libnl_utils.h index 6a7c7cc5538..6b55aa78d66 100644 --- a/opal/mca/reachable/netlink/libnl_utils.h +++ b/opal/mca/reachable/netlink/libnl_utils.h @@ -49,8 +49,8 @@ #include "libnl3_utils.h" struct opal_reachable_netlink_sk { - NL_HANDLE *nlh; - uint32_t seq; + NL_HANDLE *nlh; + uint32_t seq; }; /* returns 0 if host is reachable, EHOSTUNREACH if the host @@ -59,9 +59,8 @@ struct opal_reachable_netlink_sk { * If the route to the destination is through a gateway, *has_gateway * is set to 1. Otherwise, it is set to 0. */ -int opal_reachable_netlink_rt_lookup(uint32_t src_addr, - uint32_t dst_addr, int oif, - int *has_gateway); +int opal_reachable_netlink_rt_lookup(uint32_t src_addr, uint32_t dst_addr, int oif, + int *has_gateway); #if OPAL_ENABLE_IPV6 /* returns 0 if host is reachable, EHOSTUNREACH if the host @@ -70,9 +69,8 @@ int opal_reachable_netlink_rt_lookup(uint32_t src_addr, * If the route to the destination is through a gateway, *has_gateway * is set to 1. Otherwise, it is set to 0. */ -int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, - struct in6_addr *dst_addr, int oif, - int *has_gateway); +int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, struct in6_addr *dst_addr, int oif, + int *has_gateway); #endif #endif /* LIBNL_UTILS_H */ diff --git a/opal/mca/reachable/netlink/reachable_netlink.h b/opal/mca/reachable/netlink/reachable_netlink.h index 3581d89a315..537cd38987b 100644 --- a/opal/mca/reachable/netlink/reachable_netlink.h +++ b/opal/mca/reachable/netlink/reachable_netlink.h @@ -16,11 +16,9 @@ BEGIN_C_DECLS -OPAL_DECLSPEC extern opal_reachable_base_component_t - mca_reachable_netlink_component; +OPAL_DECLSPEC extern opal_reachable_base_component_t mca_reachable_netlink_component; -OPAL_DECLSPEC extern const opal_reachable_base_module_t - opal_reachable_netlink_module; +OPAL_DECLSPEC extern const opal_reachable_base_module_t opal_reachable_netlink_module; END_C_DECLS diff --git a/opal/mca/reachable/netlink/reachable_netlink_component.c b/opal/mca/reachable/netlink/reachable_netlink_component.c index f958eb75c49..f015e068faa 100644 --- a/opal/mca/reachable/netlink/reachable_netlink_component.c +++ b/opal/mca/reachable/netlink/reachable_netlink_component.c @@ -14,15 +14,15 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/util/proc.h" #include "opal/mca/reachable/reachable.h" +#include "opal/util/proc.h" #include "reachable_netlink.h" /* * Public string showing the reachable netlink component version number */ -const char *opal_reachable_netlink_component_version_string = - "OPAL netlink reachable MCA component version " OPAL_VERSION; +const char *opal_reachable_netlink_component_version_string + = "OPAL netlink reachable MCA component version " OPAL_VERSION; /* * Local function @@ -32,7 +32,6 @@ static int reachable_netlink_close(void); static int reachable_netlink_component_query(mca_base_module_t **module, int *priority); static int component_register(void); - /* * Instantiate the public struct with all of our public information * and pointers to our public functions in it @@ -43,31 +42,29 @@ opal_reachable_base_component_t mca_reachable_netlink_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .base_version = { - /* Indicate that we are a reachable v1.1.0 component (which also - implies a specific MCA version) */ + .base_version = + { + /* Indicate that we are a reachable v1.1.0 component (which also + implies a specific MCA version) */ - OPAL_REACHABLE_BASE_VERSION_2_0_0, + OPAL_REACHABLE_BASE_VERSION_2_0_0, - /* Component name and version */ + /* Component name and version */ - .mca_component_name = "netlink", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), + .mca_component_name = "netlink", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), - /* Component open and close functions */ + /* Component open and close functions */ - .mca_open_component = reachable_netlink_open, - .mca_close_component = reachable_netlink_close, - .mca_query_component = reachable_netlink_component_query, - .mca_register_component_params = component_register, - }, + .mca_open_component = reachable_netlink_open, + .mca_close_component = reachable_netlink_close, + .mca_query_component = reachable_netlink_component_query, + .mca_register_component_params = component_register, + }, /* Next the MCA v1.0.0 component meta data */ - .base_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - } -}; + .base_data = {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}}; static int reachable_netlink_open(void) { @@ -86,8 +83,7 @@ static int component_register(void) return OPAL_SUCCESS; } -static int -reachable_netlink_component_query(mca_base_module_t **module, int *priority) +static int reachable_netlink_component_query(mca_base_module_t **module, int *priority) { *priority = 50; *module = (mca_base_module_t *) &opal_reachable_netlink_module; diff --git a/opal/mca/reachable/netlink/reachable_netlink_module.c b/opal/mca/reachable/netlink/reachable_netlink_module.c index cf6609242d5..9f772b53811 100644 --- a/opal/mca/reachable/netlink/reachable_netlink_module.c +++ b/opal/mca/reachable/netlink/reachable_netlink_module.c @@ -16,27 +16,22 @@ #include "opal/types.h" #ifdef HAVE_MATH_H -#include +# include #endif +#include "libnl_utils.h" +#include "opal/mca/reachable/base/base.h" #include "opal/util/net.h" #include "opal/util/string_copy.h" -#include "opal/mca/reachable/base/base.h" #include "reachable_netlink.h" -#include "libnl_utils.h" -enum connection_quality { - CQ_NO_CONNECTION = 0, - CQ_DIFFERENT_NETWORK = 50, - CQ_SAME_NETWORK = 100 -}; +enum connection_quality { CQ_NO_CONNECTION = 0, CQ_DIFFERENT_NETWORK = 50, CQ_SAME_NETWORK = 100 }; /* Local variables */ static int init_counter = 0; static int get_weights(opal_if_t *local_if, opal_if_t *remote_if); -static int calculate_weight(int bandwidth_local, int bandwidth_remote, - int connection_quality); +static int calculate_weight(int bandwidth_local, int bandwidth_remote, int connection_quality); static int netlink_init(void) { @@ -59,8 +54,7 @@ static int netlink_fini(void) * Higher weightings are given to connections on the same * network. */ -static opal_reachable_t* netlink_reachable(opal_list_t *local_ifs, - opal_list_t *remote_ifs) +static opal_reachable_t *netlink_reachable(opal_list_t *local_ifs, opal_list_t *remote_ifs) { opal_reachable_t *reachable_results = NULL; int i, j; @@ -73,9 +67,9 @@ static opal_reachable_t* netlink_reachable(opal_list_t *local_ifs, } i = 0; - OPAL_LIST_FOREACH(local_iter, local_ifs, opal_if_t) { + OPAL_LIST_FOREACH (local_iter, local_ifs, opal_if_t) { j = 0; - OPAL_LIST_FOREACH(remote_iter, remote_ifs, opal_if_t) { + OPAL_LIST_FOREACH (remote_iter, remote_ifs, opal_if_t) { reachable_results->weights[i][j] = get_weights(local_iter, remote_iter); j++; } @@ -85,7 +79,6 @@ static opal_reachable_t* netlink_reachable(opal_list_t *local_ifs, return reachable_results; } - static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) { char str_local[128], str_remote[128], *conn_type; @@ -93,13 +86,11 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) /* opal_net_get_hostname returns a static buffer. Great for single address printfs, need to copy in this case */ - opal_string_copy(str_local, - opal_net_get_hostname((struct sockaddr *)&local_if->if_addr), - sizeof(str_local)); + opal_string_copy(str_local, opal_net_get_hostname((struct sockaddr *) &local_if->if_addr), + sizeof(str_local)); str_local[sizeof(str_local) - 1] = '\0'; - opal_string_copy(str_remote, - opal_net_get_hostname((struct sockaddr *)&remote_if->if_addr), - sizeof(str_remote)); + opal_string_copy(str_remote, opal_net_get_hostname((struct sockaddr *) &remote_if->if_addr), + sizeof(str_remote)); str_remote[sizeof(str_remote) - 1] = '\0'; /* initially, assume no connection is possible */ @@ -108,8 +99,8 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) if (AF_INET == local_if->af_family && AF_INET == remote_if->af_family) { uint32_t local_ip, remote_ip; - local_ip = (uint32_t)((struct sockaddr_in *)&(local_if->if_addr))->sin_addr.s_addr; - remote_ip = (uint32_t)((struct sockaddr_in *)&(remote_if->if_addr))->sin_addr.s_addr; + local_ip = (uint32_t)((struct sockaddr_in *) &(local_if->if_addr))->sin_addr.s_addr; + remote_ip = (uint32_t)((struct sockaddr_in *) &(remote_if->if_addr))->sin_addr.s_addr; outgoing_interface = local_if->if_kernel_index; /* If the ips are identical, assume reachable through loopback. This @@ -117,26 +108,21 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) maintain similar behavior to previous implementations. */ if (local_ip == remote_ip) { conn_type = "IPv4 SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_SAME_NETWORK); goto out; } - ret = opal_reachable_netlink_rt_lookup(local_ip, - remote_ip, - outgoing_interface, + ret = opal_reachable_netlink_rt_lookup(local_ip, remote_ip, outgoing_interface, &has_gateway); if (0 == ret) { if (0 == has_gateway) { conn_type = "IPv4 SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_SAME_NETWORK); } else { conn_type = "IPv4 DIFFERENT NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_DIFFERENT_NETWORK); } } else { @@ -148,8 +134,8 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) } else if (AF_INET6 == local_if->af_family && AF_INET6 == remote_if->af_family) { struct in6_addr *local_ip, *remote_ip; - local_ip = &((struct sockaddr_in6 *)&(local_if->if_addr))->sin6_addr; - remote_ip = &((struct sockaddr_in6 *)&(remote_if->if_addr))->sin6_addr; + local_ip = &((struct sockaddr_in6 *) &(local_if->if_addr))->sin6_addr; + remote_ip = &((struct sockaddr_in6 *) &(remote_if->if_addr))->sin6_addr; outgoing_interface = local_if->if_kernel_index; /* If the ips are identical, assume reachable through loopback. This @@ -157,28 +143,23 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) maintain similar behavior to previous implementations. */ if (local_ip == remote_ip) { conn_type = "IPv6 SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_SAME_NETWORK); goto out; } - ret = opal_reachable_netlink_rt_lookup6(local_ip, - remote_ip, - outgoing_interface, + ret = opal_reachable_netlink_rt_lookup6(local_ip, remote_ip, outgoing_interface, &has_gateway); if (0 == ret) { if (0 == has_gateway) { conn_type = "IPv6 SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_SAME_NETWORK); } else { conn_type = "IPv6 DIFFERENT NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_DIFFERENT_NETWORK); } } else { @@ -196,19 +177,14 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) out: opal_output_verbose(20, opal_reachable_base_framework.framework_output, - "reachable:netlink: path from %s to %s: %s", - str_local, str_remote, conn_type); + "reachable:netlink: path from %s to %s: %s", str_local, str_remote, + conn_type); return weight; } - -const opal_reachable_base_module_t opal_reachable_netlink_module = { - netlink_init, - netlink_fini, - netlink_reachable -}; - +const opal_reachable_base_module_t opal_reachable_netlink_module = {netlink_init, netlink_fini, + netlink_reachable}; /* * Weights determined by bandwidth between @@ -236,10 +212,10 @@ const opal_reachable_base_module_t opal_reachable_netlink_module = { * connection_quality to be large enough * to capture decimals */ -static int calculate_weight(int bandwidth_local, int bandwidth_remote, - int connection_quality) +static int calculate_weight(int bandwidth_local, int bandwidth_remote, int connection_quality) { - int weight = connection_quality * (MIN(bandwidth_local, bandwidth_remote) + - 1.0/(1.0 + (double)abs(bandwidth_local - bandwidth_remote))); + int weight = connection_quality + * (MIN(bandwidth_local, bandwidth_remote) + + 1.0 / (1.0 + (double) abs(bandwidth_local - bandwidth_remote))); return weight; } diff --git a/opal/mca/reachable/netlink/reachable_netlink_utils_common.c b/opal/mca/reachable/netlink/reachable_netlink_utils_common.c index 9422c22d180..50bb10d623f 100644 --- a/opal/mca/reachable/netlink/reachable_netlink_utils_common.c +++ b/opal/mca/reachable/netlink/reachable_netlink_utils_common.c @@ -42,11 +42,11 @@ #include "opal_config.h" -#include #include +#include #include #ifdef HAVE_NETINET_IN_H -#include +# include #endif #include "libnl_utils.h" @@ -54,29 +54,31 @@ /* Adapt this copied code for Open MPI */ #include "opal/util/output.h" - -static struct nla_policy route_policy[RTA_MAX+1] = { - [RTA_IIF] = { .type = NLA_STRING, - .maxlen = IFNAMSIZ, }, - [RTA_OIF] = { .type = NLA_U32 }, - [RTA_PRIORITY] = { .type = NLA_U32 }, - [RTA_FLOW] = { .type = NLA_U32 }, - [RTA_MP_ALGO] = { .type = NLA_U32 }, - [RTA_CACHEINFO] = { .minlen = sizeof(struct rta_cacheinfo) }, - [RTA_METRICS] = { .type = NLA_NESTED }, - [RTA_MULTIPATH] = { .type = NLA_NESTED }, +static struct nla_policy route_policy[RTA_MAX + 1] = { + [RTA_IIF] = + { + .type = NLA_STRING, + .maxlen = IFNAMSIZ, + }, + [RTA_OIF] = {.type = NLA_U32}, + [RTA_PRIORITY] = {.type = NLA_U32}, + [RTA_FLOW] = {.type = NLA_U32}, + [RTA_MP_ALGO] = {.type = NLA_U32}, + [RTA_CACHEINFO] = {.minlen = sizeof(struct rta_cacheinfo)}, + [RTA_METRICS] = {.type = NLA_NESTED}, + [RTA_MULTIPATH] = {.type = NLA_NESTED}, }; static int opal_reachable_netlink_is_nlreply_expected(struct opal_reachable_netlink_sk *unlsk, - struct nlmsghdr *nlm_hdr) + struct nlmsghdr *nlm_hdr) { #if OPAL_ENABLE_DEBUG if (nlm_hdr->nlmsg_pid != nl_socket_get_local_port(unlsk->nlh) || nlm_hdr->nlmsg_seq != unlsk->seq) { - opal_output(0, "Not an expected reply msg pid: %u local pid: %u msg seq: %u expected seq: %u\n", - nlm_hdr->nlmsg_pid, - nl_socket_get_local_port(unlsk->nlh), - nlm_hdr->nlmsg_seq, unlsk->seq); + opal_output( + 0, "Not an expected reply msg pid: %u local pid: %u msg seq: %u expected seq: %u\n", + nlm_hdr->nlmsg_pid, nl_socket_get_local_port(unlsk->nlh), nlm_hdr->nlmsg_seq, + unlsk->seq); return 0; } #endif @@ -87,13 +89,11 @@ static int opal_reachable_netlink_is_nlreply_expected(struct opal_reachable_netl static int opal_reachable_netlink_is_nlreply_err(struct nlmsghdr *nlm_hdr) { if (nlm_hdr->nlmsg_type == NLMSG_ERROR) { - struct nlmsgerr *e = (struct nlmsgerr *)nlmsg_data(nlm_hdr); - if (nlm_hdr->nlmsg_len >= (__u32)NLMSG_SIZE(sizeof(*e))) - opal_output_verbose(20, 0, - "Received a netlink error message"); + struct nlmsgerr *e = (struct nlmsgerr *) nlmsg_data(nlm_hdr); + if (nlm_hdr->nlmsg_len >= (__u32) NLMSG_SIZE(sizeof(*e))) + opal_output_verbose(20, 0, "Received a netlink error message"); else - opal_output_verbose(20, 0, - "Received a truncated netlink error message\n"); + opal_output_verbose(20, 0, "Received a truncated netlink error message\n"); return 1; } @@ -101,8 +101,7 @@ static int opal_reachable_netlink_is_nlreply_err(struct nlmsghdr *nlm_hdr) } static int opal_reachable_netlink_send_query(struct opal_reachable_netlink_sk *unlsk, - struct nl_msg *msg, - int protocol, int flag) + struct nl_msg *msg, int protocol, int flag) { struct nlmsghdr *nlhdr; @@ -123,8 +122,8 @@ static int opal_reachable_netlink_set_rcvsk_timer(NL_HANDLE *nlh) timeout.tv_sec = 1; timeout.tv_usec = 0; - err = setsockopt(nl_socket_get_fd(nlh), SOL_SOCKET, SO_RCVTIMEO, - (char *)&timeout, sizeof(timeout)); + err = setsockopt(nl_socket_get_fd(nlh), SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, + sizeof(timeout)); #if OPAL_ENABLE_DEBUG if (err < 0) opal_output(0, "Failed to set SO_RCVTIMEO for nl socket"); @@ -154,8 +153,7 @@ static int opal_reachable_netlink_sk_alloc(struct opal_reachable_netlink_sk **p_ err = nl_connect(nlh, protocol); if (err < 0) { - opal_output(0, "Failed to connnect netlink route socket error: %s\n", - NL_GETERROR(err)); + opal_output(0, "Failed to connnect netlink route socket error: %s\n", NL_GETERROR(err)); err = EINVAL; goto err_free_nlh; } @@ -170,11 +168,11 @@ static int opal_reachable_netlink_sk_alloc(struct opal_reachable_netlink_sk **p_ *p_sk = unlsk; return 0; - err_close_nlh: +err_close_nlh: nl_close(nlh); - err_free_nlh: +err_free_nlh: NL_HANDLE_FREE(nlh); - err_free_unlsk: +err_free_unlsk: free(unlsk); return err; } @@ -188,7 +186,8 @@ static void opal_reachable_netlink_sk_free(struct opal_reachable_netlink_sk *unl static int opal_reachable_netlink_rt_raw_parse_cb(struct nl_msg *msg, void *arg) { - struct opal_reachable_netlink_rt_cb_arg *lookup_arg = (struct opal_reachable_netlink_rt_cb_arg *)arg; + struct opal_reachable_netlink_rt_cb_arg *lookup_arg = (struct opal_reachable_netlink_rt_cb_arg + *) arg; struct opal_reachable_netlink_sk *unlsk = lookup_arg->unlsk; struct nlmsghdr *nlm_hdr = nlmsg_hdr(msg); struct rtmsg *rtm; @@ -216,8 +215,7 @@ static int opal_reachable_netlink_rt_raw_parse_cb(struct nl_msg *msg, void *arg) #if OPAL_ENABLE_DEBUG char buf[128]; nl_nlmsgtype2str(nlm_hdr->nlmsg_type, buf, sizeof(buf)); - opal_output(0, "Received an invalid route request reply message type: %s\n", - buf); + opal_output(0, "Received an invalid route request reply message type: %s\n", buf); nl_msg_dump(msg, stderr); #endif return NL_SKIP; @@ -226,19 +224,17 @@ static int opal_reachable_netlink_rt_raw_parse_cb(struct nl_msg *msg, void *arg) rtm = nlmsg_data(nlm_hdr); if (rtm->rtm_family != AF_INET #if OPAL_ENABLE_IPV6 - && rtm->rtm_family != AF_INET6 + && rtm->rtm_family != AF_INET6 #endif - ) { + ) { #if OPAL_ENABLE_DEBUG - opal_output(0, "RTM message contains invalid AF family: %u\n", - rtm->rtm_family); + opal_output(0, "RTM message contains invalid AF family: %u\n", rtm->rtm_family); nl_msg_dump(msg, stderr); #endif return NL_SKIP; } - err = nlmsg_parse(nlm_hdr, sizeof(struct rtmsg), tb, RTA_MAX, - route_policy); + err = nlmsg_parse(nlm_hdr, sizeof(struct rtmsg), tb, RTA_MAX, route_policy); if (err < 0) { #if OPAL_ENABLE_DEBUG opal_output(0, "nlmsg parse error %s\n", NL_GETERROR(err)); @@ -248,15 +244,15 @@ static int opal_reachable_netlink_rt_raw_parse_cb(struct nl_msg *msg, void *arg) } if (tb[RTA_OIF]) { - if (nla_get_u32(tb[RTA_OIF]) == (uint32_t)lookup_arg->oif) + if (nla_get_u32(tb[RTA_OIF]) == (uint32_t) lookup_arg->oif) found = 1; else /* usually, this means that there is a route to the remote host, but that it's not through the given interface. For our purposes, that means it's not reachable. */ - opal_output_verbose(20, 0, "Retrieved route has a different outgoing interface %d (expected %d)\n", - nla_get_u32(tb[RTA_OIF]), - lookup_arg->oif); + opal_output_verbose( + 20, 0, "Retrieved route has a different outgoing interface %d (expected %d)\n", + nla_get_u32(tb[RTA_OIF]), lookup_arg->oif); } if (found && tb[RTA_GATEWAY]) { @@ -266,14 +262,12 @@ static int opal_reachable_netlink_rt_raw_parse_cb(struct nl_msg *msg, void *arg) return NL_STOP; } -int opal_reachable_netlink_rt_lookup(uint32_t src_addr, - uint32_t dst_addr, - int outgoing_interface, +int opal_reachable_netlink_rt_lookup(uint32_t src_addr, uint32_t dst_addr, int outgoing_interface, int *has_gateway) { - struct opal_reachable_netlink_sk *unlsk; /* netlink socket */ - struct nl_msg *nlm; /* netlink message */ - struct rtmsg rmsg; /* route message */ + struct opal_reachable_netlink_sk *unlsk; /* netlink socket */ + struct nl_msg *nlm; /* netlink message */ + struct rtmsg rmsg; /* route message */ struct opal_reachable_netlink_rt_cb_arg arg; /* callback argument */ int err; @@ -292,8 +286,7 @@ int opal_reachable_netlink_rt_lookup(uint32_t src_addr, /* allocate netlink message of type RTM_GETROUTE */ nlm = nlmsg_alloc_simple(RTM_GETROUTE, 0); if (!nlm) { - opal_output(0, "Failed to alloc nl message, %s\n", - NL_GETERROR(err)); + opal_output(0, "Failed to alloc nl message, %s\n", NL_GETERROR(err)); err = ENOMEM; goto out; } @@ -307,8 +300,7 @@ int opal_reachable_netlink_rt_lookup(uint32_t src_addr, err = opal_reachable_netlink_send_query(unlsk, nlm, NETLINK_ROUTE, NLM_F_REQUEST); nlmsg_free(nlm); if (err < 0) { - opal_output(0, "Failed to send RTM_GETROUTE query message, error %s\n", - NL_GETERROR(err)); + opal_output(0, "Failed to send RTM_GETROUTE query message, error %s\n", NL_GETERROR(err)); err = EINVAL; goto out; } @@ -320,8 +312,7 @@ int opal_reachable_netlink_rt_lookup(uint32_t src_addr, err = nl_socket_modify_cb(unlsk->nlh, NL_CB_MSG_IN, NL_CB_CUSTOM, opal_reachable_netlink_rt_raw_parse_cb, &arg); if (err != 0) { - opal_output(0, "Failed to setup callback function, error %s\n", - NL_GETERROR(err)); + opal_output(0, "Failed to setup callback function, error %s\n", NL_GETERROR(err)); err = EINVAL; goto out; } @@ -338,22 +329,19 @@ int opal_reachable_netlink_rt_lookup(uint32_t src_addr, err = EHOSTUNREACH; } - out: +out: opal_reachable_netlink_sk_free(unlsk); return err; } - #if OPAL_ENABLE_IPV6 -int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, - struct in6_addr *dst_addr, - int outgoing_interface, - int *has_gateway) +int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, struct in6_addr *dst_addr, + int outgoing_interface, int *has_gateway) { - struct opal_reachable_netlink_sk *unlsk; /* netlink socket */ - struct nl_msg *nlm; /* netlink message */ - struct rtmsg rmsg; /* route message */ + struct opal_reachable_netlink_sk *unlsk; /* netlink socket */ + struct nl_msg *nlm; /* netlink message */ + struct rtmsg rmsg; /* route message */ struct opal_reachable_netlink_rt_cb_arg arg; /* callback argument */ int err; @@ -361,7 +349,7 @@ int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, unlsk = NULL; err = opal_reachable_netlink_sk_alloc(&unlsk, NETLINK_ROUTE); if (err) - return err; + return err; /* allocate route message */ memset(&rmsg, 0, sizeof(rmsg)); @@ -372,10 +360,9 @@ int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, /* allocate netlink message of type RTM_GETROUTE */ nlm = nlmsg_alloc_simple(RTM_GETROUTE, 0); if (!nlm) { - opal_output(0, "Failed to alloc nl message, %s\n", - NL_GETERROR(err)); - err = ENOMEM; - goto out; + opal_output(0, "Failed to alloc nl message, %s\n", NL_GETERROR(err)); + err = ENOMEM; + goto out; } /* append route message and addresses to netlink message. */ @@ -387,10 +374,9 @@ int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, err = opal_reachable_netlink_send_query(unlsk, nlm, NETLINK_ROUTE, NLM_F_REQUEST); nlmsg_free(nlm); if (err < 0) { - opal_output(0, "Failed to send RTM_GETROUTE query message, error %s\n", - NL_GETERROR(err)); - err = EINVAL; - goto out; + opal_output(0, "Failed to send RTM_GETROUTE query message, error %s\n", NL_GETERROR(err)); + err = EINVAL; + goto out; } /* Setup callback function */ @@ -398,12 +384,11 @@ int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, arg.oif = outgoing_interface; arg.unlsk = unlsk; err = nl_socket_modify_cb(unlsk->nlh, NL_CB_MSG_IN, NL_CB_CUSTOM, - opal_reachable_netlink_rt_raw_parse_cb, &arg); + opal_reachable_netlink_rt_raw_parse_cb, &arg); if (err != 0) { - opal_output(0, "Failed to setup callback function, error %s\n", - NL_GETERROR(err)); - err = EINVAL; - goto out; + opal_output(0, "Failed to setup callback function, error %s\n", NL_GETERROR(err)); + err = EINVAL; + goto out; } /* receive results */ @@ -412,13 +397,13 @@ int opal_reachable_netlink_rt_lookup6(struct in6_addr *src_addr, /* check whether a route was found */ if (arg.found) { *has_gateway = arg.has_gateway; - err = 0; + err = 0; } else { *has_gateway = 0; - err = EHOSTUNREACH; + err = EHOSTUNREACH; } - out: +out: opal_reachable_netlink_sk_free(unlsk); return err; } diff --git a/opal/mca/reachable/reachable.h b/opal/mca/reachable/reachable.h index 9d2f31f706d..0eb9159609d 100644 --- a/opal/mca/reachable/reachable.h +++ b/opal/mca/reachable/reachable.h @@ -16,12 +16,11 @@ #define OPAL_REACHABLE_H #include "opal_config.h" -#include "opal/types.h" #include "opal/class/opal_object.h" +#include "opal/types.h" -#include "opal/mca/mca.h" #include "opal/mca/if/if.h" - +#include "opal/mca/mca.h" BEGIN_C_DECLS @@ -79,37 +78,33 @@ typedef int (*opal_reachable_base_module_fini_fn_t)(void); * reachable. * */ -typedef opal_reachable_t* -(*opal_reachable_base_module_reachable_fn_t)(opal_list_t *local_ifs, - opal_list_t *remote_ifs); - +typedef opal_reachable_t *(*opal_reachable_base_module_reachable_fn_t)(opal_list_t *local_ifs, + opal_list_t *remote_ifs); /* * the standard public API data structure */ typedef struct { /* currently used APIs */ - opal_reachable_base_module_init_fn_t init; - opal_reachable_base_module_fini_fn_t finalize; - opal_reachable_base_module_reachable_fn_t reachable; + opal_reachable_base_module_init_fn_t init; + opal_reachable_base_module_fini_fn_t finalize; + opal_reachable_base_module_reachable_fn_t reachable; } opal_reachable_base_module_t; typedef struct { - mca_base_component_t base_version; - mca_base_component_data_t base_data; + mca_base_component_t base_version; + mca_base_component_data_t base_data; int priority; } opal_reachable_base_component_t; /* * Macro for use in components that are of type reachable */ -#define OPAL_REACHABLE_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("reachable", 2, 0, 0) +#define OPAL_REACHABLE_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("reachable", 2, 0, 0) /* Global structure for accessing reachability functions */ OPAL_DECLSPEC extern opal_reachable_base_module_t opal_reachable; - END_C_DECLS #endif diff --git a/opal/mca/reachable/weighted/reachable_weighted.c b/opal/mca/reachable/weighted/reachable_weighted.c index ff5c60548ac..69c0c1300a3 100644 --- a/opal/mca/reachable/weighted/reachable_weighted.c +++ b/opal/mca/reachable/weighted/reachable_weighted.c @@ -20,27 +20,25 @@ #include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_MATH_H -#include +# include #endif #include "opal/mca/if/if.h" #include "opal/mca/reachable/base/base.h" -#include "reachable_weighted.h" #include "opal/util/net.h" #include "opal/util/string_copy.h" +#include "reachable_weighted.h" static int weighted_init(void); static int weighted_fini(void); -static opal_reachable_t* weighted_reachable(opal_list_t *local_ifs, - opal_list_t *remote_ifs); +static opal_reachable_t *weighted_reachable(opal_list_t *local_ifs, opal_list_t *remote_ifs); static int get_weights(opal_if_t *local_if, opal_if_t *remote_if); -static int calculate_weight(int bandwidth_local, int bandwidth_remote, - int connection_quality); +static int calculate_weight(int bandwidth_local, int bandwidth_remote, int connection_quality); /* * Describes the quality of a possible connection between a local and @@ -58,16 +56,12 @@ enum connection_quality { CQ_PUBLIC_SAME_NETWORK = 100 }; -const opal_reachable_base_module_t opal_reachable_weighted_module = { - weighted_init, - weighted_fini, - weighted_reachable -}; +const opal_reachable_base_module_t opal_reachable_weighted_module = {weighted_init, weighted_fini, + weighted_reachable}; // local variables static int init_cntr = 0; - static int weighted_init(void) { ++init_cntr; @@ -82,9 +76,7 @@ static int weighted_fini(void) return OPAL_SUCCESS; } - -static opal_reachable_t* weighted_reachable(opal_list_t *local_ifs, - opal_list_t *remote_ifs) +static opal_reachable_t *weighted_reachable(opal_list_t *local_ifs, opal_list_t *remote_ifs) { opal_reachable_t *reachable_results = NULL; int i, j; @@ -97,9 +89,9 @@ static opal_reachable_t* weighted_reachable(opal_list_t *local_ifs, } i = 0; - OPAL_LIST_FOREACH(local_iter, local_ifs, opal_if_t) { + OPAL_LIST_FOREACH (local_iter, local_ifs, opal_if_t) { j = 0; - OPAL_LIST_FOREACH(remote_iter, remote_ifs, opal_if_t) { + OPAL_LIST_FOREACH (remote_iter, remote_ifs, opal_if_t) { reachable_results->weights[i][j] = get_weights(local_iter, remote_iter); j++; } @@ -109,15 +101,14 @@ static opal_reachable_t* weighted_reachable(opal_list_t *local_ifs, return reachable_results; } - static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) { char str_local[128], str_remote[128], *conn_type; struct sockaddr *local_sockaddr, *remote_sockaddr; int weight; - local_sockaddr = (struct sockaddr *)&local_if->if_addr; - remote_sockaddr = (struct sockaddr *)&remote_if->if_addr; + local_sockaddr = (struct sockaddr *) &local_if->if_addr; + remote_sockaddr = (struct sockaddr *) &remote_if->if_addr; /* opal_net_get_hostname returns a static buffer. Great for single address printfs, need to copy in this case */ @@ -129,52 +120,41 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) /* initially, assume no connection is possible */ weight = calculate_weight(0, 0, CQ_NO_CONNECTION); - if (AF_INET == local_sockaddr->sa_family && - AF_INET == remote_sockaddr->sa_family) { + if (AF_INET == local_sockaddr->sa_family && AF_INET == remote_sockaddr->sa_family) { - if (opal_net_addr_isipv4public(local_sockaddr) && - opal_net_addr_isipv4public(remote_sockaddr)) { - if (opal_net_samenetwork(local_sockaddr, - remote_sockaddr, - local_if->if_mask)) { + if (opal_net_addr_isipv4public(local_sockaddr) + && opal_net_addr_isipv4public(remote_sockaddr)) { + if (opal_net_samenetwork(local_sockaddr, remote_sockaddr, local_if->if_mask)) { conn_type = "IPv4 PUBLIC SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PUBLIC_SAME_NETWORK); } else { conn_type = "IPv4 PUBLIC DIFFERENT NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PUBLIC_DIFFERENT_NETWORK); } - } else if (!opal_net_addr_isipv4public(local_sockaddr) && - !opal_net_addr_isipv4public(remote_sockaddr)) { - if (opal_net_samenetwork(local_sockaddr, - remote_sockaddr, - local_if->if_mask)) { + } else if (!opal_net_addr_isipv4public(local_sockaddr) + && !opal_net_addr_isipv4public(remote_sockaddr)) { + if (opal_net_samenetwork(local_sockaddr, remote_sockaddr, local_if->if_mask)) { conn_type = "IPv4 PRIVATE SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PRIVATE_SAME_NETWORK); } else { conn_type = "IPv4 PRIVATE DIFFERENT NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PRIVATE_DIFFERENT_NETWORK); } } else { /* one private, one public address. likely not a match. */ conn_type = "IPv4 NO CONNECTION"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_NO_CONNECTION); } #if OPAL_ENABLE_IPV6 - } else if (AF_INET6 == local_sockaddr->sa_family && - AF_INET6 == remote_sockaddr->sa_family) { - if (opal_net_addr_isipv6linklocal(local_sockaddr) && - opal_net_addr_isipv6linklocal(remote_sockaddr)) { + } else if (AF_INET6 == local_sockaddr->sa_family && AF_INET6 == remote_sockaddr->sa_family) { + if (opal_net_addr_isipv6linklocal(local_sockaddr) + && opal_net_addr_isipv6linklocal(remote_sockaddr)) { /* we can't actually tell if link local addresses are on * the same network or not with the weighted component. * Assume they are on the same network, so that they'll be @@ -189,29 +169,23 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) * either case, do so. */ conn_type = "IPv6 LINK-LOCAL SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PRIVATE_SAME_NETWORK); - } else if (!opal_net_addr_isipv6linklocal(local_sockaddr) && - !opal_net_addr_isipv6linklocal(remote_sockaddr)) { - if (opal_net_samenetwork(local_sockaddr, - remote_sockaddr, - local_if->if_mask)) { + } else if (!opal_net_addr_isipv6linklocal(local_sockaddr) + && !opal_net_addr_isipv6linklocal(remote_sockaddr)) { + if (opal_net_samenetwork(local_sockaddr, remote_sockaddr, local_if->if_mask)) { conn_type = "IPv6 PUBLIC SAME NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PUBLIC_SAME_NETWORK); } else { conn_type = "IPv6 PUBLIC DIFFERENT NETWORK"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_PUBLIC_DIFFERENT_NETWORK); } } else { /* one link-local, one public address. likely not a match. */ conn_type = "IPv6 NO CONNECTION"; - weight = calculate_weight(local_if->if_bandwidth, - remote_if->if_bandwidth, + weight = calculate_weight(local_if->if_bandwidth, remote_if->if_bandwidth, CQ_NO_CONNECTION); } #endif /* #if OPAL_ENABLE_IPV6 */ @@ -224,13 +198,12 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) } opal_output_verbose(20, opal_reachable_base_framework.framework_output, - "reachable:weighted: path from %s to %s: %s", - str_local, str_remote, conn_type); + "reachable:weighted: path from %s to %s: %s", str_local, str_remote, + conn_type); return weight; } - /* * Weights determined by bandwidth between * interfaces (limited by lower bandwidth @@ -257,10 +230,10 @@ static int get_weights(opal_if_t *local_if, opal_if_t *remote_if) * connection_quality to be large enough * to capture decimals */ -static int calculate_weight(int bandwidth_local, int bandwidth_remote, - int connection_quality) +static int calculate_weight(int bandwidth_local, int bandwidth_remote, int connection_quality) { - int weight = connection_quality * (MIN(bandwidth_local, bandwidth_remote) + - 1.0 / (1.0 + (double)abs(bandwidth_local - bandwidth_remote))); + int weight = connection_quality + * (MIN(bandwidth_local, bandwidth_remote) + + 1.0 / (1.0 + (double) abs(bandwidth_local - bandwidth_remote))); return weight; } diff --git a/opal/mca/reachable/weighted/reachable_weighted.h b/opal/mca/reachable/weighted/reachable_weighted.h index effdcaf3087..85bc50232c3 100644 --- a/opal/mca/reachable/weighted/reachable_weighted.h +++ b/opal/mca/reachable/weighted/reachable_weighted.h @@ -15,14 +15,14 @@ #include "opal_config.h" #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_UN_H -#include +# include #endif -#include "opal/mca/reachable/reachable.h" #include "opal/mca/mca.h" +#include "opal/mca/reachable/reachable.h" #include "opal/util/event.h" #include "opal/util/proc.h" @@ -38,7 +38,6 @@ OPAL_DECLSPEC extern opal_reachable_weighted_component_t mca_reachable_weighted_ OPAL_DECLSPEC extern const opal_reachable_base_module_t opal_reachable_weighted_module; - END_C_DECLS #endif /* MCA_REACHABLE_WEIGHTED_H */ diff --git a/opal/mca/reachable/weighted/reachable_weighted_component.c b/opal/mca/reachable/weighted/reachable_weighted_component.c index 6e8098b7698..13222d0fb7b 100644 --- a/opal/mca/reachable/weighted/reachable_weighted_component.c +++ b/opal/mca/reachable/weighted/reachable_weighted_component.c @@ -23,15 +23,15 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/util/proc.h" #include "opal/mca/reachable/reachable.h" +#include "opal/util/proc.h" #include "reachable_weighted.h" /* * Public string showing the reachable weighted component version number */ -const char *opal_reachable_weighted_component_version_string = - "OPAL weighted reachable MCA component version " OPAL_VERSION; +const char *opal_reachable_weighted_component_version_string + = "OPAL weighted reachable MCA component version " OPAL_VERSION; /* * Local function @@ -41,19 +41,18 @@ static int reachable_weighted_close(void); static int reachable_weighted_component_query(mca_base_module_t **module, int *priority); static int component_register(void); - /* * Instantiate the public struct with all of our public information * and pointers to our public functions in it */ -opal_reachable_weighted_component_t mca_reachable_weighted_component = { - { +opal_reachable_weighted_component_t mca_reachable_weighted_component = {{ - /* First, the mca_component_t struct containing meta information - about the component itself */ + /* First, the mca_component_t struct containing meta information + about the component itself */ - .base_version = { + .base_version = + { /* Indicate that we are a reachable v1.1.0 component (which also implies a specific MCA version) */ @@ -72,13 +71,11 @@ opal_reachable_weighted_component_t mca_reachable_weighted_component = { .mca_query_component = reachable_weighted_component_query, .mca_register_component_params = component_register, }, - /* Next the MCA v1.0.0 component meta data */ - .base_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - } -}; + /* Next the MCA v1.0.0 component meta data */ + .base_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, +}}; static int reachable_weighted_open(void) { @@ -100,6 +97,6 @@ static int component_register(void) static int reachable_weighted_component_query(mca_base_module_t **module, int *priority) { *priority = 1; - *module = (mca_base_module_t *)&opal_reachable_weighted_module; + *module = (mca_base_module_t *) &opal_reachable_weighted_module; return OPAL_SUCCESS; } diff --git a/opal/mca/shmem/base/base.h b/opal/mca/shmem/base/base.h index 57ee7785603..633598f2b73 100644 --- a/opal/mca/shmem/base/base.h +++ b/opal/mca/shmem/base/base.h @@ -31,23 +31,16 @@ BEGIN_C_DECLS /* ////////////////////////////////////////////////////////////////////////// */ /* Public API for the shmem framework */ /* ////////////////////////////////////////////////////////////////////////// */ -OPAL_DECLSPEC int -opal_shmem_segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size); +OPAL_DECLSPEC int opal_shmem_segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, + size_t size); -OPAL_DECLSPEC int -opal_shmem_ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to); +OPAL_DECLSPEC int opal_shmem_ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to); -OPAL_DECLSPEC void * -opal_shmem_segment_attach(opal_shmem_ds_t *ds_buf); +OPAL_DECLSPEC void *opal_shmem_segment_attach(opal_shmem_ds_t *ds_buf); -OPAL_DECLSPEC int -opal_shmem_segment_detach(opal_shmem_ds_t *ds_buf); +OPAL_DECLSPEC int opal_shmem_segment_detach(opal_shmem_ds_t *ds_buf); -OPAL_DECLSPEC int -opal_shmem_unlink(opal_shmem_ds_t *ds_buf); +OPAL_DECLSPEC int opal_shmem_unlink(opal_shmem_ds_t *ds_buf); /* ////////////////////////////////////////////////////////////////////////// */ /* End Public API for the shmem framework */ /* ////////////////////////////////////////////////////////////////////////// */ @@ -64,8 +57,7 @@ opal_shmem_unlink(opal_shmem_ds_t *ds_buf); * * see: orte/mca/odls/base/odls_base_default_fns.c */ -OPAL_DECLSPEC char * -opal_shmem_base_best_runnable_component_name(void); +OPAL_DECLSPEC char *opal_shmem_base_best_runnable_component_name(void); /** * Select an available component. @@ -98,8 +90,7 @@ opal_shmem_base_best_runnable_component_name(void); * selected. If no component was selected, subsequent invocation * of the shmem wrapper functions will return an error. */ -OPAL_DECLSPEC int -opal_shmem_base_select(void); +OPAL_DECLSPEC int opal_shmem_base_select(void); /** * Shut down the shmem MCA framework. @@ -112,8 +103,7 @@ opal_shmem_base_select(void); * It must be the last function invoked on the shmem MCA * framework. */ -OPAL_DECLSPEC int -opal_shmem_base_close(void); +OPAL_DECLSPEC int opal_shmem_base_close(void); /** * Indication of whether a component was successfully selected or diff --git a/opal/mca/shmem/base/shmem_base_close.c b/opal/mca/shmem/base/shmem_base_close.c index 4df2ff2e25a..415ea6c22e1 100644 --- a/opal/mca/shmem/base/shmem_base_close.c +++ b/opal/mca/shmem/base/shmem_base_close.c @@ -22,19 +22,17 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/shmem/shmem.h" +#include "opal/mca/mca.h" #include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" #include "opal/util/output.h" /* ////////////////////////////////////////////////////////////////////////// */ -int -opal_shmem_base_close(void) +int opal_shmem_base_close(void) { /* if there is a selected shmem module, finalize it */ - if (NULL != opal_shmem_base_module && - NULL != opal_shmem_base_module->module_finalize) { + if (NULL != opal_shmem_base_module && NULL != opal_shmem_base_module->module_finalize) { opal_shmem_base_module->module_finalize(); } @@ -42,7 +40,5 @@ opal_shmem_base_close(void) opal_shmem_base_component = NULL; opal_shmem_base_module = NULL; - return mca_base_framework_components_close (&opal_shmem_base_framework, - NULL); + return mca_base_framework_components_close(&opal_shmem_base_framework, NULL); } - diff --git a/opal/mca/shmem/base/shmem_base_open.c b/opal/mca/shmem/base/shmem_base_open.c index 0332a5aac58..a9055432d84 100644 --- a/opal/mca/shmem/base/shmem_base_open.c +++ b/opal/mca/shmem/base/shmem_base_open.c @@ -22,12 +22,12 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_var.h" -#include "opal/mca/shmem/shmem.h" +#include "opal/mca/mca.h" #include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" +#include "opal/util/output.h" /* * The following file was created by configure. It contains extern @@ -45,8 +45,7 @@ char *opal_shmem_base_RUNTIME_QUERY_hint = NULL; /** * Register some shmem-wide MCA params */ -static int -opal_shmem_base_register (mca_base_register_flag_t flags) +static int opal_shmem_base_register(mca_base_register_flag_t flags) { int ret; @@ -54,17 +53,17 @@ opal_shmem_base_register (mca_base_register_flag_t flags) * hint to the shmem framework. */ opal_shmem_base_RUNTIME_QUERY_hint = NULL; - ret = mca_base_framework_var_register (&opal_shmem_base_framework, "RUNTIME_QUERY_hint", - "Internal OMPI parameter used to provide a " - "component selection hint to the shmem " - "framework. The value of this parameter " - "is the name of the component that is " - "available, selectable, and meets our " - "run-time behavior requirements.", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, - MCA_BASE_VAR_FLAG_INTERNAL, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_ALL, - &opal_shmem_base_RUNTIME_QUERY_hint); + ret = mca_base_framework_var_register(&opal_shmem_base_framework, "RUNTIME_QUERY_hint", + "Internal OMPI parameter used to provide a " + "component selection hint to the shmem " + "framework. The value of this parameter " + "is the name of the component that is " + "available, selectable, and meets our " + "run-time behavior requirements.", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, + MCA_BASE_VAR_FLAG_INTERNAL, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_ALL, + &opal_shmem_base_RUNTIME_QUERY_hint); return (0 > ret) ? ret : OPAL_SUCCESS; } diff --git a/opal/mca/shmem/base/shmem_base_select.c b/opal/mca/shmem/base/shmem_base_select.c index 766f0321968..91d32e75bad 100644 --- a/opal/mca/shmem/base/shmem_base_select.c +++ b/opal/mca/shmem/base/shmem_base_select.c @@ -24,11 +24,11 @@ #include #include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" -#include "opal/mca/shmem/shmem.h" +#include "opal/mca/mca.h" #include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" +#include "opal/util/output.h" /* * globals @@ -44,9 +44,8 @@ opal_shmem_base_module_t *opal_shmem_base_module = NULL; * Similar to mca_base_select, but take into consideration environment * hints provided by orte. */ -static int -opal_shmem_base_runtime_query(mca_base_module_t **best_module, - mca_base_component_t **best_component) +static int opal_shmem_base_runtime_query(mca_base_module_t **best_module, + mca_base_component_t **best_component) { mca_base_component_list_item_t *cli = NULL; mca_base_component_t *component = NULL; @@ -73,14 +72,14 @@ opal_shmem_base_runtime_query(mca_base_module_t **best_module, * for each call their 'run-time query' functions to determine relative * priority. */ - OPAL_LIST_FOREACH(cli, &opal_shmem_base_framework.framework_components, mca_base_component_list_item_t) { - component = (mca_base_component_t *)cli->cli_component; + OPAL_LIST_FOREACH (cli, &opal_shmem_base_framework.framework_components, + mca_base_component_list_item_t) { + component = (mca_base_component_t *) cli->cli_component; /* if there is a run-time query function then use it. otherwise, skip * the component. */ - if (NULL == ((opal_shmem_base_component_2_0_0_t *) - component)->runtime_query) { + if (NULL == ((opal_shmem_base_component_2_0_0_t *) component)->runtime_query) { opal_output_verbose(5, opal_shmem_base_framework.framework_output, "shmem: base: runtime_query: " "(shmem) Skipping component [%s]. It does not " @@ -95,8 +94,8 @@ opal_shmem_base_runtime_query(mca_base_module_t **best_module, "(shmem) Querying component (run-time) [%s]", component->mca_component_name); - ((opal_shmem_base_component_2_0_0_t *) - component)->runtime_query(&module, &priority, opal_shmem_base_RUNTIME_QUERY_hint); + ((opal_shmem_base_component_2_0_0_t *) component) + ->runtime_query(&module, &priority, opal_shmem_base_RUNTIME_QUERY_hint); /* if no module was returned, then skip component. * this probably means that the run-time test deemed the shared memory @@ -131,30 +130,30 @@ opal_shmem_base_runtime_query(mca_base_module_t **best_module, if (NULL == *best_component) { opal_output_verbose(5, opal_shmem_base_framework.framework_output, "shmem: base: runtime_query: " - "(%5s) No component selected!", "shmem"); + "(%5s) No component selected!", + "shmem"); return OPAL_ERR_NOT_FOUND; } opal_output_verbose(5, opal_shmem_base_framework.framework_output, "shmem: base: runtime_query: " - "(%5s) Selected component [%s]", "shmem", - (*best_component)->mca_component_name); + "(%5s) Selected component [%s]", + "shmem", (*best_component)->mca_component_name); /* close the non-selected components */ - (void) mca_base_framework_components_close (&opal_shmem_base_framework, - (mca_base_component_t *)(*best_component)); + (void) mca_base_framework_components_close(&opal_shmem_base_framework, + (mca_base_component_t *) (*best_component)); /* save the winner */ - opal_shmem_base_component = (opal_shmem_base_component_t*) *best_component; - opal_shmem_base_module = (opal_shmem_base_module_t*) *best_module; + opal_shmem_base_component = (opal_shmem_base_component_t *) *best_component; + opal_shmem_base_module = (opal_shmem_base_module_t *) *best_module; opal_shmem_base_selected = true; return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -char * -opal_shmem_base_best_runnable_component_name(void) +char *opal_shmem_base_best_runnable_component_name(void) { mca_base_component_t *best_component = NULL; mca_base_module_t *best_module = NULL; @@ -163,20 +162,17 @@ opal_shmem_base_best_runnable_component_name(void) "shmem: base: best_runnable_component_name: " "Searching for best runnable component."); /* select the best component so we can get its name. */ - if (OPAL_SUCCESS != opal_shmem_base_runtime_query(&best_module, - &best_component)) { + if (OPAL_SUCCESS != opal_shmem_base_runtime_query(&best_module, &best_component)) { /* fail! */ return NULL; - } - else { + } else { if (NULL != best_component) { opal_output_verbose(10, opal_shmem_base_framework.framework_output, "shmem: base: best_runnable_component_name: " "Found best runnable component: (%s).", best_component->mca_component_name); return strdup(best_component->mca_component_name); - } - else { + } else { opal_output_verbose(10, opal_shmem_base_framework.framework_output, "shmem: base: best_runnable_component_name: " "Could not find runnable component."); @@ -187,15 +183,14 @@ opal_shmem_base_best_runnable_component_name(void) } /* ////////////////////////////////////////////////////////////////////////// */ -int -opal_shmem_base_select(void) +int opal_shmem_base_select(void) { opal_shmem_base_component_2_0_0_t *best_component = NULL; opal_shmem_base_module_2_0_0_t *best_module = NULL; /* select the best component */ - if (OPAL_SUCCESS != opal_shmem_base_runtime_query( - (mca_base_module_t **)&best_module, - (mca_base_component_t **)&best_component)) { + if (OPAL_SUCCESS + != opal_shmem_base_runtime_query((mca_base_module_t **) &best_module, + (mca_base_component_t **) &best_component)) { /* it is NOT okay if we don't find a module because we need at * least one shared memory backing facility component instance. */ @@ -205,9 +200,7 @@ opal_shmem_base_select(void) /* initialize the winner */ if (NULL != opal_shmem_base_module) { return opal_shmem_base_module->module_init(); - } - else { + } else { return OPAL_ERROR; } } - diff --git a/opal/mca/shmem/base/shmem_base_wrappers.c b/opal/mca/shmem/base/shmem_base_wrappers.c index c323c3b9acd..b1b0c02f6ec 100644 --- a/opal/mca/shmem/base/shmem_base_wrappers.c +++ b/opal/mca/shmem/base/shmem_base_wrappers.c @@ -22,14 +22,11 @@ #include "opal_config.h" #include "opal/constants.h" -#include "opal/mca/shmem/shmem.h" #include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" /* ////////////////////////////////////////////////////////////////////////// */ -int -opal_shmem_segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size) +int opal_shmem_segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size) { if (!opal_shmem_base_selected) { return OPAL_ERROR; @@ -39,9 +36,7 @@ opal_shmem_segment_create(opal_shmem_ds_t *ds_buf, } /* ////////////////////////////////////////////////////////////////////////// */ -int -opal_shmem_ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to) +int opal_shmem_ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to) { if (!opal_shmem_base_selected) { return OPAL_ERROR; @@ -51,8 +46,7 @@ opal_shmem_ds_copy(const opal_shmem_ds_t *from, } /* ////////////////////////////////////////////////////////////////////////// */ -void * -opal_shmem_segment_attach(opal_shmem_ds_t *ds_buf) +void *opal_shmem_segment_attach(opal_shmem_ds_t *ds_buf) { if (!opal_shmem_base_selected) { return NULL; @@ -62,8 +56,7 @@ opal_shmem_segment_attach(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -int -opal_shmem_segment_detach(opal_shmem_ds_t *ds_buf) +int opal_shmem_segment_detach(opal_shmem_ds_t *ds_buf) { if (!opal_shmem_base_selected) { return OPAL_ERROR; @@ -73,8 +66,7 @@ opal_shmem_segment_detach(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -int -opal_shmem_unlink(opal_shmem_ds_t *ds_buf) +int opal_shmem_unlink(opal_shmem_ds_t *ds_buf) { if (!opal_shmem_base_selected) { return OPAL_ERROR; @@ -82,4 +74,3 @@ opal_shmem_unlink(opal_shmem_ds_t *ds_buf) return opal_shmem_base_module->unlink(ds_buf); } - diff --git a/opal/mca/shmem/mmap/shmem_mmap.h b/opal/mca/shmem/mmap/shmem_mmap.h index 5cea8a5bcf9..da583a83a5f 100644 --- a/opal/mca/shmem/mmap/shmem_mmap.h +++ b/opal/mca/shmem/mmap/shmem_mmap.h @@ -43,8 +43,7 @@ typedef struct opal_shmem_mmap_component_t { int priority; } opal_shmem_mmap_component_t; -OPAL_MODULE_DECLSPEC extern opal_shmem_mmap_component_t -mca_shmem_mmap_component; +OPAL_MODULE_DECLSPEC extern opal_shmem_mmap_component_t mca_shmem_mmap_component; typedef struct opal_shmem_mmap_module_t { opal_shmem_base_module_t super; diff --git a/opal/mca/shmem/mmap/shmem_mmap_component.c b/opal/mca/shmem/mmap/shmem_mmap_component.c index 324f1493a94..ae006b2773c 100644 --- a/opal/mca/shmem/mmap/shmem_mmap_component.c +++ b/opal/mca/shmem/mmap/shmem_mmap_component.c @@ -37,8 +37,8 @@ /** * public string showing the shmem ompi_mmap component version number */ -const char *opal_shmem_mmap_component_version_string = - "OPAL mmap shmem MCA component version " OPAL_VERSION; +const char *opal_shmem_mmap_component_version_string + = "OPAL mmap shmem MCA component version " OPAL_VERSION; int opal_shmem_mmap_relocate_backing_file = 0; char *opal_shmem_mmap_backing_file_base_dir = NULL; @@ -51,66 +51,60 @@ static int mmap_register(void); static int mmap_open(void); static int mmap_close(void); static int mmap_query(mca_base_module_t **module, int *priority); -static int mmap_runtime_query(mca_base_module_t **module, - int *priority, - const char *hint); +static int mmap_runtime_query(mca_base_module_t **module, int *priority, const char *hint); /** * instantiate the public struct with all of our public information * and pointers to our public functions in it */ opal_shmem_mmap_component_t mca_shmem_mmap_component = { - .super = { - .base_version = { - OPAL_SHMEM_BASE_VERSION_2_0_0, - - /* component name and version */ - .mca_component_name = "mmap", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - .mca_open_component = mmap_open, - .mca_close_component = mmap_close, - .mca_query_component = mmap_query, - .mca_register_component_params = mmap_register, + .super = + { + .base_version = + { + OPAL_SHMEM_BASE_VERSION_2_0_0, + + /* component name and version */ + .mca_component_name = "mmap", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + .mca_open_component = mmap_open, + .mca_close_component = mmap_close, + .mca_query_component = mmap_query, + .mca_register_component_params = mmap_register, + }, + /* MCA v2.0.0 component meta data */ + .base_data = + {/* the component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + .runtime_query = mmap_runtime_query, }, - /* MCA v2.0.0 component meta data */ - .base_data = { - /* the component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, - .runtime_query = mmap_runtime_query, - }, }; /* ////////////////////////////////////////////////////////////////////////// */ -static int -mmap_runtime_query(mca_base_module_t **module, - int *priority, - const char *hint) +static int mmap_runtime_query(mca_base_module_t **module, int *priority, const char *hint) { /* no run-time query needed for mmap, so this is easy */ *priority = mca_shmem_mmap_component.priority; - *module = (mca_base_module_t *)&opal_shmem_mmap_module.super; + *module = (mca_base_module_t *) &opal_shmem_mmap_module.super; return OPAL_SUCCESS; } -static int -mmap_register(void) +static int mmap_register(void) { int ret; - /* ////////////////////////////////////////////////////////////////////// */ /* (default) priority - set high to make mmap the default */ mca_shmem_mmap_component.priority = 50; - ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version, - "priority", "Priority for shmem mmap " - "component (default: 50)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_ALL_EQ, - &mca_shmem_mmap_component.priority); + ret = mca_base_component_var_register(&mca_shmem_mmap_component.super.base_version, "priority", + "Priority for shmem mmap " + "component (default: 50)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL_EQ, + &mca_shmem_mmap_component.priority); if (0 > ret) { return ret; } @@ -126,42 +120,43 @@ mmap_register(void) * effect doesn't matter. */ opal_shmem_mmap_nfs_warning = true; - ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version, - "enable_nfs_warning", - "Enable the warning emitted when Open MPI detects " - "that its shared memory backing file is located on " - "a network filesystem (1 = enabled, 0 = disabled).", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_shmem_mmap_nfs_warning); + ret = mca_base_component_var_register(&mca_shmem_mmap_component.super.base_version, + "enable_nfs_warning", + "Enable the warning emitted when Open MPI detects " + "that its shared memory backing file is located on " + "a network filesystem (1 = enabled, 0 = disabled).", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_shmem_mmap_nfs_warning); if (0 > ret) { return ret; } opal_shmem_mmap_relocate_backing_file = 0; - ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version, - "relocate_backing_file", - "Whether to change the default placement of backing files or not " - "(Negative = try to relocate backing files to an area rooted at " - "the path specified by " - "shmem_mmap_backing_file_base_dir, but continue " - "with the default path if the relocation fails, 0 = do not relocate, " - "Positive = same as the negative option, but will fail if the " - "relocation fails.", MCA_BASE_VAR_TYPE_INT, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_shmem_mmap_relocate_backing_file); + ret = mca_base_component_var_register( + &mca_shmem_mmap_component.super.base_version, "relocate_backing_file", + "Whether to change the default placement of backing files or not " + "(Negative = try to relocate backing files to an area rooted at " + "the path specified by " + "shmem_mmap_backing_file_base_dir, but continue " + "with the default path if the relocation fails, 0 = do not relocate, " + "Positive = same as the negative option, but will fail if the " + "relocation fails.", + MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_shmem_mmap_relocate_backing_file); if (0 > ret) { return ret; } opal_shmem_mmap_backing_file_base_dir = "/dev/shm"; - ret = mca_base_component_var_register (&mca_shmem_mmap_component.super.base_version, - "backing_file_base_dir", - "Specifies where backing files will be created when " - "shmem_mmap_relocate_backing_file is in use.", MCA_BASE_VAR_TYPE_STRING, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_shmem_mmap_backing_file_base_dir); + ret = mca_base_component_var_register(&mca_shmem_mmap_component.super.base_version, + "backing_file_base_dir", + "Specifies where backing files will be created when " + "shmem_mmap_relocate_backing_file is in use.", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_ALL_EQ, + &opal_shmem_mmap_backing_file_base_dir); if (0 > ret) { return ret; } @@ -170,25 +165,21 @@ mmap_register(void) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -mmap_open(void) +static int mmap_open(void) { return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -mmap_query(mca_base_module_t **module, int *priority) +static int mmap_query(mca_base_module_t **module, int *priority) { *priority = mca_shmem_mmap_component.priority; - *module = (mca_base_module_t *)&opal_shmem_mmap_module.super; + *module = (mca_base_module_t *) &opal_shmem_mmap_module.super; return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -mmap_close(void) +static int mmap_close(void) { return OPAL_SUCCESS; } - diff --git a/opal/mca/shmem/mmap/shmem_mmap_module.c b/opal/mca/shmem/mmap/shmem_mmap_module.c index 0cfea545d8e..caca9c278b6 100644 --- a/opal/mca/shmem/mmap/shmem_mmap_module.c +++ b/opal/mca/shmem/mmap/shmem_mmap_module.c @@ -29,36 +29,36 @@ #include #ifdef HAVE_FCNTL_H -#include -#endif /* HAVE_FCNTL_H */ +# include +#endif /* HAVE_FCNTL_H */ #ifdef HAVE_SYS_MMAN_H -#include +# include #endif /* HAVE_SYS_MMAN_H */ #ifdef HAVE_UNISTD_H -#include +# include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_TYPES_H -#include +# include #endif /* HAVE_SYS_TYPES_H */ #include #ifdef HAVE_NETDB_H -#include +# include #endif /* HAVE_NETDB_H */ #include #ifdef HAVE_SYS_STAT_H -#include +# include #endif /* HAVE_SYS_STAT_H */ -#include "opal/runtime/opal.h" -#include "opal_stdint.h" #include "opal/constants.h" +#include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" +#include "opal/runtime/opal.h" #include "opal/util/alfg.h" #include "opal/util/output.h" #include "opal/util/path.h" #include "opal/util/show_help.h" #include "opal/util/string_copy.h" -#include "opal/mca/shmem/shmem.h" -#include "opal/mca/shmem/base/base.h" +#include "opal_stdint.h" #include "shmem_mmap.h" @@ -67,50 +67,33 @@ /* ////////////////////////////////////////////////////////////////////////// */ /*local functions */ /* local functions */ -static int -module_init(void); +static int module_init(void); -static int -segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size); +static int segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size); -static int -ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to); +static int ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to); -static void * -segment_attach(opal_shmem_ds_t *ds_buf); +static void *segment_attach(opal_shmem_ds_t *ds_buf); -static int -segment_detach(opal_shmem_ds_t *ds_buf); +static int segment_detach(opal_shmem_ds_t *ds_buf); -static int -segment_unlink(opal_shmem_ds_t *ds_buf); +static int segment_unlink(opal_shmem_ds_t *ds_buf); -static int -module_finalize(void); +static int module_finalize(void); -static int -enough_space(const char *filename, - size_t space_req, - uint64_t *space_avail, - bool *result); +static int enough_space(const char *filename, size_t space_req, uint64_t *space_avail, + bool *result); /* * mmap shmem module */ -opal_shmem_mmap_module_t opal_shmem_mmap_module = { - .super = { - .module_init = module_init, - .segment_create = segment_create, - .ds_copy = ds_copy, - .segment_attach = segment_attach, - .segment_detach = segment_detach, - .unlink = segment_unlink, - .module_finalize = module_finalize - } -}; +opal_shmem_mmap_module_t opal_shmem_mmap_module = {.super = {.module_init = module_init, + .segment_create = segment_create, + .ds_copy = ds_copy, + .segment_attach = segment_attach, + .segment_detach = segment_detach, + .unlink = segment_unlink, + .module_finalize = module_finalize}}; /* ////////////////////////////////////////////////////////////////////////// */ /* private utility functions */ @@ -120,16 +103,13 @@ opal_shmem_mmap_module_t opal_shmem_mmap_module = { /** * completely resets the contents of *ds_buf */ -static inline void -shmem_ds_reset(opal_shmem_ds_t *ds_buf) +static inline void shmem_ds_reset(opal_shmem_ds_t *ds_buf) { /* don't print ds_buf info here, as we may be printing garbage. */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: shmem_ds_resetting\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: shmem_ds_resetting\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name)); ds_buf->seg_cpid = 0; OPAL_SHMEM_DS_RESET_FLAGS(ds_buf); @@ -140,11 +120,7 @@ shmem_ds_reset(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -enough_space(const char *filename, - size_t space_req, - uint64_t *space_avail, - bool *result) +static int enough_space(const char *filename, size_t space_req, uint64_t *space_avail, bool *result) { uint64_t avail = 0; size_t fluff = (size_t)(.05 * space_req); @@ -165,22 +141,17 @@ enough_space(const char *filename, /* now check space availability */ if (OPAL_SUCCESS != (rc = opal_path_df(target_dir, &avail))) { OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "WARNING: opal_path_df failure!") - ); + (70, opal_shmem_base_framework.framework_output, "WARNING: opal_path_df failure!")); goto out; } /* do we have enough space? */ if (avail >= space_req + fluff) { enough = true; - } - else { - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "WARNING: not enough space on %s to meet request!" - "available: %"PRIu64 "requested: %lu", target_dir, - avail, (unsigned long)space_req + fluff) - ); + } else { + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "WARNING: not enough space on %s to meet request!" + "available: %" PRIu64 "requested: %lu", + target_dir, avail, (unsigned long) space_req + fluff)); } out: @@ -193,48 +164,40 @@ enough_space(const char *filename, } /* ////////////////////////////////////////////////////////////////////////// */ -static int -module_init(void) +static int module_init(void) { /* nothing to do */ return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -module_finalize(void) +static int module_finalize(void) { /* nothing to do */ return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to) +static int ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to) { memcpy(to, from, sizeof(opal_shmem_ds_t)); - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: ds_copy complete " - "from: (id: %d, size: %lu, " - "name: %s flags: 0x%02x) " - "to: (id: %d, size: %lu, " - "name: %s flags: 0x%02x)\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name, - from->seg_id, (unsigned long)from->seg_size, from->seg_name, - from->flags, to->seg_id, (unsigned long)to->seg_size, to->seg_name, - to->flags) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: ds_copy complete " + "from: (id: %d, size: %lu, " + "name: %s flags: 0x%02x) " + "to: (id: %d, size: %lu, " + "name: %s flags: 0x%02x)\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name, + from->seg_id, (unsigned long) from->seg_size, from->seg_name, from->flags, + to->seg_id, (unsigned long) to->seg_size, to->seg_name, to->flags)); return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static unsigned long -sdbm_hash(const unsigned char *hash_key) +static unsigned long sdbm_hash(const unsigned char *hash_key) { unsigned long str_hash = 0; int c; @@ -247,8 +210,7 @@ sdbm_hash(const unsigned char *hash_key) } /* ////////////////////////////////////////////////////////////////////////// */ -static bool -path_usable(const char *path, int *stat_errno) +static bool path_usable(const char *path, int *stat_errno) { struct stat buf; int rc; @@ -266,8 +228,7 @@ path_usable(const char *path, int *stat_errno) * caller is responsible for freeing returned resources. the returned string * will be OPAL_PATH_MAX long. */ -static char * -get_uniq_file_name(const char *base_path, const char *hash_key) +static char *get_uniq_file_name(const char *base_path, const char *hash_key) { char *uniq_name_buf = NULL; unsigned long str_hash = 0; @@ -285,21 +246,18 @@ get_uniq_file_name(const char *base_path, const char *hash_key) } my_pid = getpid(); - opal_srand(&rand_buff,((uint32_t)(time(NULL) + my_pid))); + opal_srand(&rand_buff, ((uint32_t)(time(NULL) + my_pid))); rand_num = opal_rand(&rand_buff) % 1024; - str_hash = sdbm_hash((unsigned char *)hash_key); + str_hash = sdbm_hash((unsigned char *) hash_key); /* build the name */ - snprintf(uniq_name_buf, OPAL_PATH_MAX, "%s/open_mpi_shmem_mmap.%d_%lu_%d", - base_path, (int)my_pid, str_hash, rand_num); + snprintf(uniq_name_buf, OPAL_PATH_MAX, "%s/open_mpi_shmem_mmap.%d_%lu_%d", base_path, + (int) my_pid, str_hash, rand_num); return uniq_name_buf; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size) +static int segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size) { int rc = OPAL_SUCCESS; char *real_file_name = NULL; @@ -315,10 +273,9 @@ segment_create(opal_shmem_ds_t *ds_buf, if (0 != opal_shmem_mmap_relocate_backing_file) { int err; if (path_usable(opal_shmem_mmap_backing_file_base_dir, &err)) { - if (NULL == - (real_file_name = - get_uniq_file_name(opal_shmem_mmap_backing_file_base_dir, - file_name))) { + if (NULL + == (real_file_name = get_uniq_file_name(opal_shmem_mmap_backing_file_base_dir, + file_name))) { /* out of resources */ return OPAL_ERROR; } @@ -328,17 +285,19 @@ segment_create(opal_shmem_ds_t *ds_buf, * with the default path. otherwise, fail. */ else if (opal_shmem_mmap_relocate_backing_file < 0) { - opal_output(0, "shmem: mmap: WARNING: could not relocate " + opal_output(0, + "shmem: mmap: WARNING: could not relocate " "backing store to \"%s\" (%s). Continuing with " "default path.\n", opal_shmem_mmap_backing_file_base_dir, strerror(err)); } /* must be positive, so fail */ else { - opal_output(0, "shmem: mmap: WARNING: could not relocate " + opal_output(0, + "shmem: mmap: WARNING: could not relocate " "backing store to \"%s\" (%s). Cannot continue with " - "shmem mmap.\n", opal_shmem_mmap_backing_file_base_dir, - strerror(err)); + "shmem mmap.\n", + opal_shmem_mmap_backing_file_base_dir, strerror(err)); return OPAL_ERROR; } } @@ -351,13 +310,11 @@ segment_create(opal_shmem_ds_t *ds_buf, } } - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: backing store base directory: %s\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name, - real_file_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: backing store base directory: %s\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name, + real_file_name)); /* determine whether the specified filename is on a network file system. * this is an important check because if the backing store is located on @@ -366,15 +323,15 @@ segment_create(opal_shmem_ds_t *ds_buf, if (opal_shmem_mmap_nfs_warning && opal_path_nfs(real_file_name, NULL)) { const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "mmap on nfs", 1, hn, - real_file_name); + opal_show_help("help-opal-shmem-mmap.txt", "mmap on nfs", 1, hn, real_file_name); } /* let's make sure we have enough space for the backing file */ - if (OPAL_SUCCESS != (rc = enough_space(real_file_name, size, - &amount_space_avail, - &space_available))) { - opal_output(0, "shmem: mmap: an error occurred while determining " - "whether or not %s could be created.", real_file_name); + if (OPAL_SUCCESS + != (rc = enough_space(real_file_name, size, &amount_space_avail, &space_available))) { + opal_output(0, + "shmem: mmap: an error occurred while determining " + "whether or not %s could be created.", + real_file_name); /* rc is set */ goto out; } @@ -382,9 +339,8 @@ segment_create(opal_shmem_ds_t *ds_buf, const char *hn; hn = opal_gethostname(); rc = OPAL_ERR_OUT_OF_RESOURCE; - opal_show_help("help-opal-shmem-mmap.txt", "target full", 1, - real_file_name, hn, (unsigned long)size, - (unsigned long long)amount_space_avail); + opal_show_help("help-opal-shmem-mmap.txt", "target full", 1, real_file_name, hn, + (unsigned long) size, (unsigned long long) amount_space_avail); goto out; } /* enough space is available, so create the segment */ @@ -392,8 +348,8 @@ segment_create(opal_shmem_ds_t *ds_buf, int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "open(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "open(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; } @@ -402,19 +358,18 @@ segment_create(opal_shmem_ds_t *ds_buf, int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "ftruncate(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "ftruncate(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; } - if (MAP_FAILED == (segment = mmap(NULL, size, - PROT_READ | PROT_WRITE, MAP_SHARED, - ds_buf->seg_id, 0))) { + if (MAP_FAILED + == (segment = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ds_buf->seg_id, 0))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "mmap(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "mmap(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; } @@ -425,19 +380,17 @@ segment_create(opal_shmem_ds_t *ds_buf, ds_buf->seg_cpid = my_pid; ds_buf->seg_size = size; ds_buf->seg_base_addr = segment; - (void)opal_string_copy(ds_buf->seg_name, real_file_name, OPAL_PATH_MAX); + (void) opal_string_copy(ds_buf->seg_name, real_file_name, OPAL_PATH_MAX); /* set "valid" bit because setment creation was successful */ OPAL_SHMEM_DS_SET_VALID(ds_buf); - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: create successful " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: create successful " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); } out: @@ -451,11 +404,11 @@ segment_create(opal_shmem_ds_t *ds_buf, int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "close(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "close(2)", "", + strerror(err), err); rc = OPAL_ERROR; - } - } + } + } /* an error occured, so invalidate the shmem object and munmap if needed */ if (OPAL_SUCCESS != rc) { if (MAP_FAILED != segment) { @@ -474,8 +427,7 @@ segment_create(opal_shmem_ds_t *ds_buf, /** * segment_attach can only be called after a successful call to segment_create */ -static void * -segment_attach(opal_shmem_ds_t *ds_buf) +static void *segment_attach(opal_shmem_ds_t *ds_buf) { pid_t my_pid = getpid(); @@ -484,18 +436,18 @@ segment_attach(opal_shmem_ds_t *ds_buf) int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "open(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "open(2)", "", + strerror(err), err); return NULL; } - if (MAP_FAILED == (ds_buf->seg_base_addr = mmap(NULL, ds_buf->seg_size, - PROT_READ | PROT_WRITE, MAP_SHARED, - ds_buf->seg_id, 0))) { + if (MAP_FAILED + == (ds_buf->seg_base_addr = mmap(NULL, ds_buf->seg_size, PROT_READ | PROT_WRITE, + MAP_SHARED, ds_buf->seg_id, 0))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "mmap(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "mmap(2)", "", + strerror(err), err); /* mmap failed, so close the file and return NULL - no error check * here because we are already in an error path... */ @@ -510,48 +462,43 @@ segment_attach(opal_shmem_ds_t *ds_buf) int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, - hn, "close(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "close(2)", "", + strerror(err), err); } } /* else i was the segment creator. nothing to do here because all the hard * work was done in segment_create :-). */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: attach successful " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: attach successful " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); /* update returned base pointer with an offset that hides our stuff */ return ds_buf->seg_base_addr; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_detach(opal_shmem_ds_t *ds_buf) +static int segment_detach(opal_shmem_ds_t *ds_buf) { int rc = OPAL_SUCCESS; - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: detaching " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: detaching " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); if (0 != munmap(ds_buf->seg_base_addr, ds_buf->seg_size)) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "munmap(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "munmap(2)", "", + strerror(err), err); rc = OPAL_ERROR; } /* reset the contents of the opal_shmem_ds_t associated with this @@ -562,24 +509,21 @@ segment_detach(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_unlink(opal_shmem_ds_t *ds_buf) +static int segment_unlink(opal_shmem_ds_t *ds_buf) { - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: unlinking" - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_mmap_component.super.base_version.mca_type_name, - mca_shmem_mmap_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: unlinking" + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_mmap_component.super.base_version.mca_type_name, + mca_shmem_mmap_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); if (-1 == unlink(ds_buf->seg_name)) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "unlink(2)", ds_buf->seg_name, strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "unlink(2)", + ds_buf->seg_name, strerror(err), err); return OPAL_ERROR; } @@ -592,4 +536,3 @@ segment_unlink(opal_shmem_ds_t *ds_buf) OPAL_SHMEM_DS_INVALIDATE(ds_buf); return OPAL_SUCCESS; } - diff --git a/opal/mca/shmem/posix/shmem_posix.h b/opal/mca/shmem/posix/shmem_posix.h index 9794bb22d8f..13ff856ccc9 100644 --- a/opal/mca/shmem/posix/shmem_posix.h +++ b/opal/mca/shmem/posix/shmem_posix.h @@ -54,8 +54,7 @@ typedef struct opal_shmem_posix_component_t { int priority; } opal_shmem_posix_component_t; -OPAL_MODULE_DECLSPEC extern opal_shmem_posix_component_t -mca_shmem_posix_component; +OPAL_MODULE_DECLSPEC extern opal_shmem_posix_component_t mca_shmem_posix_component; typedef struct opal_shmem_posix_module_t { opal_shmem_base_module_t super; diff --git a/opal/mca/shmem/posix/shmem_posix_common_utils.c b/opal/mca/shmem/posix/shmem_posix_common_utils.c index d5fbddbbe26..9946969b4f1 100644 --- a/opal/mca/shmem/posix/shmem_posix_common_utils.c +++ b/opal/mca/shmem/posix/shmem_posix_common_utils.c @@ -29,40 +29,39 @@ #include #ifdef HAVE_FCNTL_H -#include -#endif /* HAVE_FCNTL_H */ +# include +#endif /* HAVE_FCNTL_H */ #include #if OPAL_HAVE_SOLARIS && !defined(_POSIX_C_SOURCE) - #define _POSIX_C_SOURCE 200112L /* Required for shm_{open,unlink} decls */ - #include - #undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L /* Required for shm_{open,unlink} decls */ +# include +# undef _POSIX_C_SOURCE #else -#ifdef HAVE_SYS_MMAN_H -#include -#endif /* HAVE_SYS_MMAN_H */ +# ifdef HAVE_SYS_MMAN_H +# include +# endif /* HAVE_SYS_MMAN_H */ #endif #ifdef HAVE_UNISTD_H -#include +# include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_TYPES_H -#include +# include #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_NETDB_H -#include +# include #endif /* HAVE_NETDB_H */ +#include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" #include "opal/runtime/opal.h" #include "opal/util/output.h" #include "opal/util/show_help.h" -#include "opal/mca/shmem/base/base.h" -#include "opal/mca/shmem/shmem.h" #include "shmem_posix.h" #include "shmem_posix_common_utils.h" /* ////////////////////////////////////////////////////////////////////////// */ -int -shmem_posix_shm_open(char *posix_file_name_buff, size_t size) +int shmem_posix_shm_open(char *posix_file_name_buff, size_t size) { int attempt = 0, fd = -1; @@ -75,13 +74,12 @@ shmem_posix_shm_open(char *posix_file_name_buff, size_t size) * see comment in shmem_posix.h that explains why we chose to do things * this way. */ - snprintf(posix_file_name_buff, size, "%s%04d", - OPAL_SHMEM_POSIX_FILE_NAME_PREFIX, attempt++); + snprintf(posix_file_name_buff, size, "%s%04d", OPAL_SHMEM_POSIX_FILE_NAME_PREFIX, + attempt++); /* the check for the existence of the object and its creation if it * does not exist are performed atomically. */ - if (-1 == (fd = shm_open(posix_file_name_buff, - O_CREAT | O_EXCL | O_RDWR, 0600))) { + if (-1 == (fd = shm_open(posix_file_name_buff, O_CREAT | O_EXCL | O_RDWR, 0600))) { int err = errno; /* the object already exists, so try again with a new name */ if (EEXIST == err) { @@ -92,9 +90,9 @@ shmem_posix_shm_open(char *posix_file_name_buff, size_t size) */ else { opal_output_verbose(10, opal_shmem_base_framework.framework_output, - "shmem_posix_shm_open: disqualifying posix because " - "shm_open(2) failed with error: %s (errno %d)\n", - strerror(err), err); + "shmem_posix_shm_open: disqualifying posix because " + "shm_open(2) failed with error: %s (errno %d)\n", + strerror(err), err); break; } } @@ -107,8 +105,7 @@ shmem_posix_shm_open(char *posix_file_name_buff, size_t size) /* if we didn't find a name, let the user know that we tried and failed */ if (attempt >= OPAL_SHMEM_POSIX_MAX_ATTEMPTS) { opal_output(0, "shmem: posix: file name search - max attempts exceeded." - "cannot continue with posix.\n"); + "cannot continue with posix.\n"); } return fd; } - diff --git a/opal/mca/shmem/posix/shmem_posix_common_utils.h b/opal/mca/shmem/posix/shmem_posix_common_utils.h index e83a2bc736a..ac965f1f71b 100644 --- a/opal/mca/shmem/posix/shmem_posix_common_utils.h +++ b/opal/mca/shmem/posix/shmem_posix_common_utils.h @@ -42,8 +42,7 @@ BEGIN_C_DECLS * successful shm_open. otherwise, -1 is returned and the contents of * posix_file_name_buff are undefined. */ -OPAL_DECLSPEC extern int shmem_posix_shm_open(char *posix_file_name_buff, - size_t size); +OPAL_DECLSPEC extern int shmem_posix_shm_open(char *posix_file_name_buff, size_t size); END_C_DECLS diff --git a/opal/mca/shmem/posix/shmem_posix_component.c b/opal/mca/shmem/posix/shmem_posix_component.c index fea44efe34c..2ac79c99f31 100644 --- a/opal/mca/shmem/posix/shmem_posix_component.c +++ b/opal/mca/shmem/posix/shmem_posix_component.c @@ -32,39 +32,36 @@ #include "opal_config.h" - #include #include #ifdef HAVE_SYS_MMAN_H -#include +# include #endif /* HAVE_SYS_MMAN_H */ #ifdef HAVE_UNISTD_H -#include +# include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_NETDB_H -#include +# include #endif /* HAVE_NETDB_H */ -#include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal/util/show_help.h" -#include "opal/util/output.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/shmem/shmem.h" +#include "opal/runtime/opal.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" #include "shmem_posix.h" #include "shmem_posix_common_utils.h" /* public string showing the shmem ompi_posix component version number */ -const char *opal_shmem_posix_component_version_string = - "OPAL posix shmem MCA component version " OPAL_VERSION; +const char *opal_shmem_posix_component_version_string + = "OPAL posix shmem MCA component version " OPAL_VERSION; /* local functions */ -static int posix_register (void); +static int posix_register(void); static int posix_open(void); static int posix_query(mca_base_module_t **module, int *priority); -static int posix_runtime_query(mca_base_module_t **module, - int *priority, - const char *hint); +static int posix_runtime_query(mca_base_module_t **module, int *priority, const char *hint); /* local variables */ static bool rt_successful = false; @@ -73,41 +70,37 @@ static bool rt_successful = false; * and pointers to our public functions in it */ opal_shmem_posix_component_t mca_shmem_posix_component = { - .super = { - .base_version = { - OPAL_SHMEM_BASE_VERSION_2_0_0, - - /* component name and version */ - .mca_component_name = "posix", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - .mca_open_component = posix_open, - .mca_query_component = posix_query, - .mca_register_component_params = posix_register - }, - /* MCA v2.0.0 component meta data */ - .base_data = { - /* the component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT + .super = + { + .base_version = {OPAL_SHMEM_BASE_VERSION_2_0_0, + + /* component name and version */ + .mca_component_name = "posix", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, + OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION), + + .mca_open_component = posix_open, .mca_query_component = posix_query, + .mca_register_component_params = posix_register}, + /* MCA v2.0.0 component meta data */ + .base_data = + {/* the component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + .runtime_query = posix_runtime_query, }, - .runtime_query = posix_runtime_query, - }, }; - /* ////////////////////////////////////////////////////////////////////////// */ -static int -posix_register(void) +static int posix_register(void) { /* ////////////////////////////////////////////////////////////////////// */ /* (default) priority - set lower than mmap's priority */ mca_shmem_posix_component.priority = 40; (void) mca_base_component_var_register(&mca_shmem_posix_component.super.base_version, - "priority", "Priority for the shmem posix " - "component (default: 40)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, + "priority", + "Priority for the shmem posix " + "component (default: 40)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, &mca_shmem_posix_component.priority); @@ -116,8 +109,7 @@ posix_register(void) /* ////////////////////////////////////////////////////////////////////////// */ -static int -posix_open(void) +static int posix_open(void) { return OPAL_SUCCESS; } @@ -130,10 +122,7 @@ posix_open(void) * * @return OPAL_SUCCESS when posix can safely be used. */ -static int -posix_runtime_query(mca_base_module_t **module, - int *priority, - const char *hint) +static int posix_runtime_query(mca_base_module_t **module, int *priority, const char *hint) { char tmp_buff[OPAL_SHMEM_POSIX_FILE_LEN_MAX]; int fd = -1; @@ -146,21 +135,19 @@ posix_runtime_query(mca_base_module_t **module, * don't have to perform a run-time query. */ if (NULL != hint) { - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "shmem: posix: runtime_query: " - "attempting to use runtime hint (%s)\n", hint) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "shmem: posix: runtime_query: " + "attempting to use runtime hint (%s)\n", + hint)); /* was i selected? if so, then we are done. * otherwise, disqualify myself. */ - if (0 == strcasecmp(hint, - mca_shmem_posix_component.super.base_version.mca_component_name)) { + if (0 + == strcasecmp(hint, mca_shmem_posix_component.super.base_version.mca_component_name)) { *priority = mca_shmem_posix_component.priority; - *module = (mca_base_module_t *)&opal_shmem_posix_module.super; + *module = (mca_base_module_t *) &opal_shmem_posix_module.super; return OPAL_SUCCESS; - } - else { + } else { *priority = 0; *module = NULL; return OPAL_SUCCESS; @@ -170,28 +157,25 @@ posix_runtime_query(mca_base_module_t **module, * hint. it's either up to us to figure it out, or the caller wants us to * re-run the runtime query. */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "shmem: posix: runtime_query: NO HINT PROVIDED:" - "starting run-time test...\n") - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "shmem: posix: runtime_query: NO HINT PROVIDED:" + "starting run-time test...\n")); /* shmem_posix_shm_open successfully shm_opened - we can use posix sm! */ - if (-1 != (fd = shmem_posix_shm_open(tmp_buff, - OPAL_SHMEM_POSIX_FILE_LEN_MAX -1))) { + if (-1 != (fd = shmem_posix_shm_open(tmp_buff, OPAL_SHMEM_POSIX_FILE_LEN_MAX - 1))) { /* free up allocated resources before we return */ if (0 != shm_unlink(tmp_buff)) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, - hn, "shm_unlink(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "shm_unlink(2)", "", + strerror(err), err); /* something strange happened, so consider this a run-time test * failure even though shmem_posix_shm_open was successful */ } /* all is well */ else { *priority = mca_shmem_posix_component.priority; - *module = (mca_base_module_t *)&opal_shmem_posix_module.super; + *module = (mca_base_module_t *) &opal_shmem_posix_module.super; rt_successful = true; } } @@ -200,11 +184,9 @@ posix_runtime_query(mca_base_module_t **module, } /* ////////////////////////////////////////////////////////////////////////// */ -static int -posix_query(mca_base_module_t **module, int *priority) +static int posix_query(mca_base_module_t **module, int *priority) { *priority = mca_shmem_posix_component.priority; - *module = (mca_base_module_t *)&opal_shmem_posix_module.super; + *module = (mca_base_module_t *) &opal_shmem_posix_module.super; return OPAL_SUCCESS; } - diff --git a/opal/mca/shmem/posix/shmem_posix_module.c b/opal/mca/shmem/posix/shmem_posix_module.c index 95bdfb8d3d5..b6fbcb77da4 100644 --- a/opal/mca/shmem/posix/shmem_posix_module.c +++ b/opal/mca/shmem/posix/shmem_posix_module.c @@ -27,36 +27,36 @@ #include #ifdef HAVE_FCNTL_H -#include -#endif /* HAVE_FCNTL_H */ +# include +#endif /* HAVE_FCNTL_H */ #if OPAL_HAVE_SOLARIS && !defined(_POSIX_C_SOURCE) - #define _POSIX_C_SOURCE 200112L /* Required for shm_{open,unlink} decls */ - #include - #undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L /* Required for shm_{open,unlink} decls */ +# include +# undef _POSIX_C_SOURCE #else -#ifdef HAVE_SYS_MMAN_H -#include -#endif /* HAVE_SYS_MMAN_H */ +# ifdef HAVE_SYS_MMAN_H +# include +# endif /* HAVE_SYS_MMAN_H */ #endif #ifdef HAVE_UNISTD_H -#include +# include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_TYPES_H -#include +# include #endif /* HAVE_SYS_TYPES_H */ #include #ifdef HAVE_NETDB_H -#include +# include #endif /* HAVE_NETDB_H */ -#include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal_stdint.h" +#include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" +#include "opal/runtime/opal.h" #include "opal/util/output.h" #include "opal/util/path.h" #include "opal/util/show_help.h" -#include "opal/mca/shmem/shmem.h" -#include "opal/mca/shmem/base/base.h" +#include "opal_stdint.h" #include "shmem_posix.h" #include "shmem_posix_common_utils.h" @@ -65,42 +65,28 @@ /* ////////////////////////////////////////////////////////////////////////// */ /* local functions */ -static int -module_init(void); +static int module_init(void); -static int -segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size); +static int segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size); -static int -ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to); +static int ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to); -static void * -segment_attach(opal_shmem_ds_t *ds_buf); +static void *segment_attach(opal_shmem_ds_t *ds_buf); -static int -segment_detach(opal_shmem_ds_t *ds_buf); +static int segment_detach(opal_shmem_ds_t *ds_buf); -static int -segment_unlink(opal_shmem_ds_t *ds_buf); +static int segment_unlink(opal_shmem_ds_t *ds_buf); -static int -module_finalize(void); +static int module_finalize(void); /* posix shmem module */ -opal_shmem_posix_module_t opal_shmem_posix_module = { - .super = { - .module_init = module_init, - .segment_create = segment_create, - .ds_copy = ds_copy, - .segment_attach = segment_attach, - .segment_detach = segment_detach, - .unlink = segment_unlink, - .module_finalize = module_finalize - } -}; +opal_shmem_posix_module_t opal_shmem_posix_module = {.super = {.module_init = module_init, + .segment_create = segment_create, + .ds_copy = ds_copy, + .segment_attach = segment_attach, + .segment_detach = segment_detach, + .unlink = segment_unlink, + .module_finalize = module_finalize}}; /* ////////////////////////////////////////////////////////////////////////// */ /* private utility functions */ @@ -110,16 +96,13 @@ opal_shmem_posix_module_t opal_shmem_posix_module = { /** * completely resets the contents of *ds_buf */ -static inline void -shmem_ds_reset(opal_shmem_ds_t *ds_buf) +static inline void shmem_ds_reset(opal_shmem_ds_t *ds_buf) { /* don't print ds_buf info here, as we may be printing garbage. */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: shmem_ds_resetting\n", - mca_shmem_posix_component.super.base_version.mca_type_name, - mca_shmem_posix_component.super.base_version.mca_component_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: shmem_ds_resetting\n", + mca_shmem_posix_component.super.base_version.mca_type_name, + mca_shmem_posix_component.super.base_version.mca_component_name)); ds_buf->seg_cpid = 0; OPAL_SHMEM_DS_RESET_FLAGS(ds_buf); @@ -130,50 +113,40 @@ shmem_ds_reset(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -module_init(void) +static int module_init(void) { /* nothing to do */ return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -module_finalize(void) +static int module_finalize(void) { /* nothing to do */ return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to) +static int ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to) { memcpy(to, from, sizeof(opal_shmem_ds_t)); - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: ds_copy complete " - "from: (id: %d, size: %lu, " - "name: %s flags: 0x%02x) " - "to: (id: %d, size: %lu, " - "name: %s flags: 0x%02x)\n", - mca_shmem_posix_component.super.base_version.mca_type_name, - mca_shmem_posix_component.super.base_version.mca_component_name, - from->seg_id, (unsigned long)from->seg_size, from->seg_name, - from->flags, to->seg_id, (unsigned long)to->seg_size, to->seg_name, - to->flags) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: ds_copy complete " + "from: (id: %d, size: %lu, " + "name: %s flags: 0x%02x) " + "to: (id: %d, size: %lu, " + "name: %s flags: 0x%02x)\n", + mca_shmem_posix_component.super.base_version.mca_type_name, + mca_shmem_posix_component.super.base_version.mca_component_name, + from->seg_id, (unsigned long) from->seg_size, from->seg_name, from->flags, + to->seg_id, (unsigned long) to->seg_size, to->seg_name, to->flags)); return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size) +static int segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size) { int rc = OPAL_SUCCESS; pid_t my_pid = getpid(); @@ -190,9 +163,9 @@ segment_create(opal_shmem_ds_t *ds_buf, * memory object name and upon successful completion populates the name * buffer */ - if (-1 == (ds_buf->seg_id = shmem_posix_shm_open( - ds_buf->seg_name, - OPAL_SHMEM_POSIX_FILE_LEN_MAX - 1))) { + if (-1 + == (ds_buf->seg_id = shmem_posix_shm_open(ds_buf->seg_name, + OPAL_SHMEM_POSIX_FILE_LEN_MAX - 1))) { /* snaps! something happened in posix_shm_open. don't report anything * here because posix_shm_open will display all the necessary info. */ @@ -204,19 +177,18 @@ segment_create(opal_shmem_ds_t *ds_buf, int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, - "ftruncate(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "ftruncate(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; - } - else if (MAP_FAILED == (segment = mmap(NULL, size, - PROT_READ | PROT_WRITE, MAP_SHARED, - ds_buf->seg_id, 0))) { + } else if (MAP_FAILED + == (segment = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ds_buf->seg_id, + 0))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, - "mmap(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "mmap(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; } @@ -236,14 +208,12 @@ segment_create(opal_shmem_ds_t *ds_buf, /* set "valid" bit because setment creation was successful */ OPAL_SHMEM_DS_SET_VALID(ds_buf); - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: create successful " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_posix_component.super.base_version.mca_type_name, - mca_shmem_posix_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: create successful " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_posix_component.super.base_version.mca_type_name, + mca_shmem_posix_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); } out: @@ -257,11 +227,11 @@ segment_create(opal_shmem_ds_t *ds_buf, int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, - "close(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "close(2)", "", + strerror(err), err); rc = OPAL_ERROR; - } - } + } + } /* an error occured, so invalidate the shmem object and release any * allocated resources. */ @@ -274,7 +244,7 @@ segment_create(opal_shmem_ds_t *ds_buf, shm_unlink(ds_buf->seg_name); } if (MAP_FAILED != segment) { - munmap((void*)segment, size); + munmap((void *) segment, size); } /* always invalidate in this error path */ shmem_ds_reset(ds_buf); @@ -286,8 +256,7 @@ segment_create(opal_shmem_ds_t *ds_buf, /** * segment_attach can only be called after a successful call to segment_create */ -static void * -segment_attach(opal_shmem_ds_t *ds_buf) +static void *segment_attach(opal_shmem_ds_t *ds_buf) { pid_t my_pid = getpid(); @@ -296,18 +265,17 @@ segment_attach(opal_shmem_ds_t *ds_buf) int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, - "open(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "open(2)", "", + strerror(err), err); return NULL; - } - else if (MAP_FAILED == (ds_buf->seg_base_addr = mmap(NULL, ds_buf->seg_size, - PROT_READ | PROT_WRITE, MAP_SHARED, - ds_buf->seg_id, 0))) { + } else if (MAP_FAILED + == (ds_buf->seg_base_addr = mmap(NULL, ds_buf->seg_size, PROT_READ | PROT_WRITE, + MAP_SHARED, ds_buf->seg_id, 0))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, - "mmap(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "mmap(2)", "", + strerror(err), err); /* mmap failed, so shm_unlink and return NULL - no error check here * because we are already in an error path... */ @@ -323,49 +291,44 @@ segment_attach(opal_shmem_ds_t *ds_buf) int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, - hn, "close(2)", "", strerror(err), err); - } + opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn, "close(2)", "", + strerror(err), err); + } } } /* else i was the segment creator. nothing to do here because all the hard * work was done in segment_create :-). */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: attach successful " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_posix_component.super.base_version.mca_type_name, - mca_shmem_posix_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: attach successful " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_posix_component.super.base_version.mca_type_name, + mca_shmem_posix_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); /* update returned base pointer with an offset that hides our stuff */ return ds_buf->seg_base_addr; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_detach(opal_shmem_ds_t *ds_buf) +static int segment_detach(opal_shmem_ds_t *ds_buf) { int rc = OPAL_SUCCESS; - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: detaching " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_posix_component.super.base_version.mca_type_name, - mca_shmem_posix_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: detaching " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_posix_component.super.base_version.mca_type_name, + mca_shmem_posix_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); if (0 != munmap(ds_buf->seg_base_addr, ds_buf->seg_size)) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, - "munmap(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "munmap(2)", "", + strerror(err), err); rc = OPAL_ERROR; } /* reset the contents of the opal_shmem_ds_t associated with this @@ -376,24 +339,21 @@ segment_detach(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_unlink(opal_shmem_ds_t *ds_buf) +static int segment_unlink(opal_shmem_ds_t *ds_buf) { - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: unlinking " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_posix_component.super.base_version.mca_type_name, - mca_shmem_posix_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: unlinking " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_posix_component.super.base_version.mca_type_name, + mca_shmem_posix_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); if (-1 == shm_unlink(ds_buf->seg_name)) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, - "shm_unlink(2)", ds_buf->seg_name, strerror(err), err); + opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "shm_unlink(2)", + ds_buf->seg_name, strerror(err), err); return OPAL_ERROR; } @@ -406,4 +366,3 @@ segment_unlink(opal_shmem_ds_t *ds_buf) OPAL_SHMEM_DS_INVALIDATE(ds_buf); return OPAL_SUCCESS; } - diff --git a/opal/mca/shmem/shmem.h b/opal/mca/shmem/shmem.h index c10f47ed4e7..1ee669e0577 100644 --- a/opal/mca/shmem/shmem.h +++ b/opal/mca/shmem/shmem.h @@ -46,18 +46,16 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/mca/mca.h" #include "opal/mca/shmem/shmem_types.h" BEGIN_C_DECLS /* ////////////////////////////////////////////////////////////////////////// */ -typedef int -(*mca_shmem_base_component_runtime_query_fn_t)(mca_base_module_t **module, - int *priority, - const char *hint); +typedef int (*mca_shmem_base_component_runtime_query_fn_t)(mca_base_module_t **module, + int *priority, const char *hint); /* structure for shmem components. */ struct opal_shmem_base_component_2_0_0_t { @@ -70,8 +68,7 @@ struct opal_shmem_base_component_2_0_0_t { }; /* convenience typedefs */ -typedef struct opal_shmem_base_component_2_0_0_t -opal_shmem_base_component_2_0_0_t; +typedef struct opal_shmem_base_component_2_0_0_t opal_shmem_base_component_2_0_0_t; typedef struct opal_shmem_base_component_2_0_0_t opal_shmem_base_component_t; @@ -82,8 +79,7 @@ typedef struct opal_shmem_base_component_2_0_0_t opal_shmem_base_component_t; * module initialization function. * @return OPAL_SUCCESS on success. */ -typedef int -(*opal_shmem_base_module_init_fn_t)(void); +typedef int (*opal_shmem_base_module_init_fn_t)(void); /** * copy shmem data structure information pointed to by from to the structure @@ -95,9 +91,7 @@ typedef int * * @return OPAL_SUCCESS on success. */ -typedef int -(*opal_shmem_base_ds_copy_fn_t)(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to); +typedef int (*opal_shmem_base_ds_copy_fn_t)(const opal_shmem_ds_t *from, opal_shmem_ds_t *to); /** * create a new shared memory segment and initialize members in structure @@ -113,10 +107,8 @@ typedef int * * @return OPAL_SUCCESS on success. */ -typedef int -(*opal_shmem_base_module_segment_create_fn_t)(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size); +typedef int (*opal_shmem_base_module_segment_create_fn_t)(opal_shmem_ds_t *ds_buf, + const char *file_name, size_t size); /** * attach to an existing shared memory segment initialized by segment_create. @@ -127,8 +119,7 @@ typedef int * @return base address of shared memory segment on success. returns * NULL otherwise. */ -typedef void * -(*opal_shmem_base_module_segment_attach_fn_t)(opal_shmem_ds_t *ds_buf); +typedef void *(*opal_shmem_base_module_segment_attach_fn_t)(opal_shmem_ds_t *ds_buf); /** * detach from an existing shared memory segment. @@ -138,8 +129,7 @@ typedef void * * * @return OPAL_SUCCESS on success. */ -typedef int -(*opal_shmem_base_module_segment_detach_fn_t)(opal_shmem_ds_t *ds_buf); +typedef int (*opal_shmem_base_module_segment_detach_fn_t)(opal_shmem_ds_t *ds_buf); /** * unlink an existing shared memory segment. @@ -149,8 +139,7 @@ typedef int * * @return OPAL_SUCCESS on success. */ -typedef int -(*opal_shmem_base_module_unlink_fn_t)(opal_shmem_ds_t *ds_buf); +typedef int (*opal_shmem_base_module_unlink_fn_t)(opal_shmem_ds_t *ds_buf); /** * module finalize function. invoked by the base on the selected @@ -162,14 +151,14 @@ typedef int (*opal_shmem_base_module_finalize_fn_t)(void); * structure for shmem modules */ struct opal_shmem_base_module_2_0_0_t { - mca_base_module_t base; - opal_shmem_base_module_init_fn_t module_init; - opal_shmem_base_module_segment_create_fn_t segment_create; - opal_shmem_base_ds_copy_fn_t ds_copy; - opal_shmem_base_module_segment_attach_fn_t segment_attach; - opal_shmem_base_module_segment_detach_fn_t segment_detach; - opal_shmem_base_module_unlink_fn_t unlink; - opal_shmem_base_module_finalize_fn_t module_finalize; + mca_base_module_t base; + opal_shmem_base_module_init_fn_t module_init; + opal_shmem_base_module_segment_create_fn_t segment_create; + opal_shmem_base_ds_copy_fn_t ds_copy; + opal_shmem_base_module_segment_attach_fn_t segment_attach; + opal_shmem_base_module_segment_detach_fn_t segment_detach; + opal_shmem_base_module_unlink_fn_t unlink; + opal_shmem_base_module_finalize_fn_t module_finalize; }; /** @@ -182,8 +171,7 @@ typedef struct opal_shmem_base_module_2_0_0_t opal_shmem_base_module_t; * macro for use in components that are of type shmem * see: opal/mca/mca.h for more information */ -#define OPAL_SHMEM_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("shmem", 2, 0, 0) +#define OPAL_SHMEM_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("shmem", 2, 0, 0) END_C_DECLS diff --git a/opal/mca/shmem/shmem_types.h b/opal/mca/shmem/shmem_types.h index 0fc7e10ee56..78583c84286 100644 --- a/opal/mca/shmem/shmem_types.h +++ b/opal/mca/shmem/shmem_types.h @@ -67,33 +67,32 @@ BEGIN_C_DECLS /** * macro that sets all bits in flags to 0 */ -#define OPAL_SHMEM_DS_RESET_FLAGS(ds_buf) \ -do { \ - (ds_buf)->flags = 0x00; \ -} while (0) +#define OPAL_SHMEM_DS_RESET_FLAGS(ds_buf) \ + do { \ + (ds_buf)->flags = 0x00; \ + } while (0) /** * sets valid bit in flags to 1 */ -#define OPAL_SHMEM_DS_SET_VALID(ds_buf) \ -do { \ - (ds_buf)->flags |= OPAL_SHMEM_DS_FLAGS_VALID; \ -} while (0) +#define OPAL_SHMEM_DS_SET_VALID(ds_buf) \ + do { \ + (ds_buf)->flags |= OPAL_SHMEM_DS_FLAGS_VALID; \ + } while (0) /** * sets valid bit in flags to 0 */ -#define OPAL_SHMEM_DS_INVALIDATE(ds_buf) \ -do { \ - (ds_buf)->flags &= ~OPAL_SHMEM_DS_FLAGS_VALID; \ -} while (0) +#define OPAL_SHMEM_DS_INVALIDATE(ds_buf) \ + do { \ + (ds_buf)->flags &= ~OPAL_SHMEM_DS_FLAGS_VALID; \ + } while (0) /** * evaluates to 1 if the valid bit in flags is set to 1. evaluates to 0 * otherwise. */ -#define OPAL_SHMEM_DS_IS_VALID(ds_buf) \ - ( (ds_buf)->flags & OPAL_SHMEM_DS_FLAGS_VALID ) +#define OPAL_SHMEM_DS_IS_VALID(ds_buf) ((ds_buf)->flags & OPAL_SHMEM_DS_FLAGS_VALID) typedef uint8_t opal_shmem_ds_flag_t; @@ -124,13 +123,12 @@ typedef struct opal_shmem_ds_t opal_shmem_ds_t; * opal_shmem_ds_t payload isn't viable -- due to the potential disparity * between the reserved buffer space and what is actually in use. */ -static inline size_t -opal_shmem_sizeof_shmem_ds(const opal_shmem_ds_t *ds_bufp) +static inline size_t opal_shmem_sizeof_shmem_ds(const opal_shmem_ds_t *ds_bufp) { char *name_base = NULL; size_t name_buf_offset = offsetof(opal_shmem_ds_t, seg_name); - name_base = (char *)ds_bufp + name_buf_offset; + name_base = (char *) ds_bufp + name_buf_offset; return name_buf_offset + strlen(name_base) + 1; } diff --git a/opal/mca/shmem/sysv/shmem_sysv.h b/opal/mca/shmem/sysv/shmem_sysv.h index b2bb3719d5f..0899e3b4064 100644 --- a/opal/mca/shmem/sysv/shmem_sysv.h +++ b/opal/mca/shmem/sysv/shmem_sysv.h @@ -39,8 +39,7 @@ typedef struct opal_shmem_sysv_component_t { int priority; } opal_shmem_sysv_component_t; -OPAL_MODULE_DECLSPEC extern opal_shmem_sysv_component_t -mca_shmem_sysv_component; +OPAL_MODULE_DECLSPEC extern opal_shmem_sysv_component_t mca_shmem_sysv_component; typedef struct opal_shmem_sysv_module_t { opal_shmem_base_module_t super; diff --git a/opal/mca/shmem/sysv/shmem_sysv_component.c b/opal/mca/shmem/sysv/shmem_sysv_component.c index b53fd3bed1f..33aa8f142bd 100644 --- a/opal/mca/shmem/sysv/shmem_sysv_component.c +++ b/opal/mca/shmem/sysv/shmem_sysv_component.c @@ -33,82 +33,76 @@ #include "opal_config.h" #ifdef HAVE_SYS_MMAN_H -#include +# include #endif /* HAVE_SYS_MMAN_H */ #include #ifdef HAVE_UNISTD_H -#include +# include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_IPC_H -#include +# include #endif /* HAVE_SYS_IPC_H */ #if HAVE_SYS_SHM_H -#include +# include #endif /* HAVE_SYS_SHM_H */ #if HAVE_SYS_STAT_H -#include +# include #endif /* HAVE_SYS_STAT_H */ #include "opal/constants.h" -#include "opal/util/show_help.h" -#include "opal/util/output.h" -#include "opal/util/sys_limits.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/shmem/shmem.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" +#include "opal/util/sys_limits.h" #include "shmem_sysv.h" /* public string showing the shmem ompi_sysv component version number */ -const char *opal_shmem_sysv_component_version_string = - "OPAL sysv shmem MCA component version " OPAL_VERSION; +const char *opal_shmem_sysv_component_version_string + = "OPAL sysv shmem MCA component version " OPAL_VERSION; /* local functions */ -static int sysv_register (void); +static int sysv_register(void); static int sysv_open(void); static int sysv_query(mca_base_module_t **module, int *priority); -static int sysv_runtime_query(mca_base_module_t **module, - int *priority, - const char *hint); +static int sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint); /* instantiate the public struct with all of our public information * and pointers to our public functions in it */ opal_shmem_sysv_component_t mca_shmem_sysv_component = { - .super = { - /* common MCA component data */ + .super = { - OPAL_SHMEM_BASE_VERSION_2_0_0, - - /* component name and version */ - .mca_component_name = "sysv", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - .mca_open_component = sysv_open, - .mca_query_component = sysv_query, - .mca_register_component_params = sysv_register - }, - /* MCA v2.0.0 component meta data */ - .base_data = { - /* the component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT + /* common MCA component data */ + {OPAL_SHMEM_BASE_VERSION_2_0_0, + + /* component name and version */ + .mca_component_name = "sysv", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + .mca_open_component = sysv_open, .mca_query_component = sysv_query, + .mca_register_component_params = sysv_register}, + /* MCA v2.0.0 component meta data */ + .base_data = + {/* the component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, + .runtime_query = sysv_runtime_query, }, - .runtime_query = sysv_runtime_query, - }, }; /* ////////////////////////////////////////////////////////////////////////// */ -static int -sysv_register(void) +static int sysv_register(void) { /* ////////////////////////////////////////////////////////////////////// */ /* (default) priority - set lower than mmap's priority */ mca_shmem_sysv_component.priority = 30; - (void) mca_base_component_var_register(&mca_shmem_sysv_component.super.base_version, - "priority", "Priority for the shmem sysv " - "component (default: 30)", MCA_BASE_VAR_TYPE_INT, - NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, + (void) mca_base_component_var_register(&mca_shmem_sysv_component.super.base_version, "priority", + "Priority for the shmem sysv " + "component (default: 30)", + MCA_BASE_VAR_TYPE_INT, NULL, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, &mca_shmem_sysv_component.priority); @@ -116,8 +110,7 @@ sysv_register(void) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -sysv_open(void) +static int sysv_open(void) { return OPAL_SUCCESS; } @@ -130,12 +123,11 @@ sysv_open(void) * * @return OPAL_SUCCESS when sysv can safely be used. */ -static int -sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint) +static int sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint) { - char c = 'j'; - int shmid = -1; - char *a = NULL; + char c = 'j'; + int shmid = -1; + char *a = NULL; char *addr = NULL; struct shmid_ds tmp_buff; @@ -147,21 +139,18 @@ sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint) * don't have to perform a run-time query. */ if (NULL != hint) { - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "shmem: sysv: runtime_query: " - "attempting to use runtime hint (%s)\n", hint) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "shmem: sysv: runtime_query: " + "attempting to use runtime hint (%s)\n", + hint)); /* was i selected? if so, then we are done. * otherwise, disqualify myself. */ - if (0 == strcasecmp(hint, - mca_shmem_sysv_component.super.base_version.mca_component_name)) { + if (0 == strcasecmp(hint, mca_shmem_sysv_component.super.base_version.mca_component_name)) { *priority = mca_shmem_sysv_component.priority; - *module = (mca_base_module_t *)&opal_shmem_sysv_module.super; + *module = (mca_base_module_t *) &opal_shmem_sysv_module.super; return OPAL_SUCCESS; - } - else { + } else { *priority = 0; *module = NULL; return OPAL_SUCCESS; @@ -169,17 +158,15 @@ sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint) } /* if we are here, then let the run-time test games begin */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "shmem: sysv: runtime_query: NO HINT PROVIDED:" - "starting run-time test...\n") - ); - - if (-1 == (shmid = shmget(IPC_PRIVATE, (size_t)(opal_getpagesize()), - IPC_CREAT | IPC_EXCL | S_IRWXU ))) { + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "shmem: sysv: runtime_query: NO HINT PROVIDED:" + "starting run-time test...\n")); + + if (-1 + == (shmid = shmget(IPC_PRIVATE, (size_t)(opal_getpagesize()), + IPC_CREAT | IPC_EXCL | S_IRWXU))) { goto out; - } - else if ((void *)-1 == (addr = shmat(shmid, NULL, 0))) { + } else if ((void *) -1 == (addr = shmat(shmid, NULL, 0))) { goto out; } @@ -189,29 +176,26 @@ sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint) if (-1 == shmctl(shmid, IPC_RMID, NULL)) { goto out; - } - else if (-1 == shmctl(shmid, IPC_STAT, &tmp_buff)) { + } else if (-1 == shmctl(shmid, IPC_STAT, &tmp_buff)) { goto out; } /* all is well - rainbows and butterflies */ else { *priority = mca_shmem_sysv_component.priority; - *module = (mca_base_module_t *)&opal_shmem_sysv_module.super; + *module = (mca_base_module_t *) &opal_shmem_sysv_module.super; } out: - if (NULL != addr && (char *)-1 != addr) { + if (NULL != addr && (char *) -1 != addr) { shmdt(addr); } return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -sysv_query(mca_base_module_t **module, int *priority) +static int sysv_query(mca_base_module_t **module, int *priority) { *priority = mca_shmem_sysv_component.priority; - *module = (mca_base_module_t *)&opal_shmem_sysv_module.super; + *module = (mca_base_module_t *) &opal_shmem_sysv_module.super; return OPAL_SUCCESS; } - diff --git a/opal/mca/shmem/sysv/shmem_sysv_module.c b/opal/mca/shmem/sysv/shmem_sysv_module.c index 64b56aa56f7..179ae0b47cf 100644 --- a/opal/mca/shmem/sysv/shmem_sysv_module.c +++ b/opal/mca/shmem/sysv/shmem_sysv_module.c @@ -27,39 +27,39 @@ #include #ifdef HAVE_FCNTL_H -#include -#endif /* HAVE_FCNTL_H */ +# include +#endif /* HAVE_FCNTL_H */ #ifdef HAVE_SYS_MMAN_H -#include +# include #endif /* HAVE_SYS_MMAN_H */ #ifdef HAVE_UNISTD_H -#include +# include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_TYPES_H -#include +# include #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_SYS_IPC_H -#include +# include #endif /* HAVE_SYS_IPC_H */ #if HAVE_SYS_SHM_H -#include +# include #endif /* HAVE_SYS_SHM_H */ #if HAVE_SYS_STAT_H -#include +# include #endif /* HAVE_SYS_STAT_H */ #include #ifdef HAVE_NETDB_H -#include +# include #endif /* HAVE_NETDB_H */ -#include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal_stdint.h" +#include "opal/mca/shmem/base/base.h" +#include "opal/mca/shmem/shmem.h" +#include "opal/runtime/opal.h" #include "opal/util/output.h" #include "opal/util/path.h" #include "opal/util/show_help.h" -#include "opal/mca/shmem/shmem.h" -#include "opal/mca/shmem/base/base.h" +#include "opal_stdint.h" #include "shmem_sysv.h" @@ -67,42 +67,28 @@ /* ////////////////////////////////////////////////////////////////////////// */ /* local functions */ -static int -module_init(void); +static int module_init(void); -static int -segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size); +static int segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size); -static int -ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to); +static int ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to); -static void * -segment_attach(opal_shmem_ds_t *ds_buf); +static void *segment_attach(opal_shmem_ds_t *ds_buf); -static int -segment_detach(opal_shmem_ds_t *ds_buf); +static int segment_detach(opal_shmem_ds_t *ds_buf); -static int -segment_unlink(opal_shmem_ds_t *ds_buf); +static int segment_unlink(opal_shmem_ds_t *ds_buf); -static int -module_finalize(void); +static int module_finalize(void); /* sysv shmem module */ -opal_shmem_sysv_module_t opal_shmem_sysv_module = { - .super = { - .module_init = module_init, - .segment_create = segment_create, - .ds_copy = ds_copy, - .segment_attach = segment_attach, - .segment_detach = segment_detach, - .unlink = segment_unlink, - .module_finalize = module_finalize - } -}; +opal_shmem_sysv_module_t opal_shmem_sysv_module = {.super = {.module_init = module_init, + .segment_create = segment_create, + .ds_copy = ds_copy, + .segment_attach = segment_attach, + .segment_detach = segment_detach, + .unlink = segment_unlink, + .module_finalize = module_finalize}}; /* ////////////////////////////////////////////////////////////////////////// */ /* private utility functions */ @@ -112,70 +98,57 @@ opal_shmem_sysv_module_t opal_shmem_sysv_module = { /** * completely resets the contents of *ds_buf */ -static inline void -shmem_ds_reset(opal_shmem_ds_t *ds_buf) +static inline void shmem_ds_reset(opal_shmem_ds_t *ds_buf) { /* don't print ds_buf info here, as we may be printing garbage. */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: shmem_ds_resetting\n", - mca_shmem_sysv_component.super.base_version.mca_type_name, - mca_shmem_sysv_component.super.base_version.mca_component_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: shmem_ds_resetting\n", + mca_shmem_sysv_component.super.base_version.mca_type_name, + mca_shmem_sysv_component.super.base_version.mca_component_name)); ds_buf->seg_cpid = 0; OPAL_SHMEM_DS_RESET_FLAGS(ds_buf); ds_buf->seg_id = OPAL_SHMEM_DS_ID_INVALID; ds_buf->seg_size = 0; memset(ds_buf->seg_name, '\0', OPAL_PATH_MAX); - ds_buf->seg_base_addr = (unsigned char *)-1; + ds_buf->seg_base_addr = (unsigned char *) -1; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -module_init(void) +static int module_init(void) { /* nothing to do */ return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -module_finalize(void) +static int module_finalize(void) { /* nothing to do */ return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -ds_copy(const opal_shmem_ds_t *from, - opal_shmem_ds_t *to) +static int ds_copy(const opal_shmem_ds_t *from, opal_shmem_ds_t *to) { memcpy(to, from, sizeof(opal_shmem_ds_t)); - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: ds_copy complete " - "from: (id: %d, size: %lu, " - "name: %s flags: 0x%02x) " - "to: (id: %d, size: %lu, " - "name: %s flags: 0x%02x)\n", - mca_shmem_sysv_component.super.base_version.mca_type_name, - mca_shmem_sysv_component.super.base_version.mca_component_name, - from->seg_id, (unsigned long)from->seg_size, from->seg_name, - from->flags, to->seg_id, (unsigned long)to->seg_size, to->seg_name, - to->flags) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: ds_copy complete " + "from: (id: %d, size: %lu, " + "name: %s flags: 0x%02x) " + "to: (id: %d, size: %lu, " + "name: %s flags: 0x%02x)\n", + mca_shmem_sysv_component.super.base_version.mca_type_name, + mca_shmem_sysv_component.super.base_version.mca_component_name, + from->seg_id, (unsigned long) from->seg_size, from->seg_name, from->flags, + to->seg_id, (unsigned long) to->seg_size, to->seg_name, to->flags)); return OPAL_SUCCESS; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_create(opal_shmem_ds_t *ds_buf, - const char *file_name, - size_t size) +static int segment_create(opal_shmem_ds_t *ds_buf, const char *file_name, size_t size) { int rc = OPAL_SUCCESS; pid_t my_pid = getpid(); @@ -189,23 +162,22 @@ segment_create(opal_shmem_ds_t *ds_buf, */ /* create a new shared memory segment and save the shmid. */ - if (-1 == (ds_buf->seg_id = shmget(IPC_PRIVATE, size, - IPC_CREAT | IPC_EXCL | S_IRWXU))) { + if (-1 == (ds_buf->seg_id = shmget(IPC_PRIVATE, size, IPC_CREAT | IPC_EXCL | S_IRWXU))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, - "shmget(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, "shmget(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; } /* attach to the sement */ - else if ((void *)-1 == (segment = shmat(ds_buf->seg_id, NULL, 0))) { + else if ((void *) -1 == (segment = shmat(ds_buf->seg_id, NULL, 0))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, - "shmat(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, "shmat(2)", "", + strerror(err), err); shmctl(ds_buf->seg_id, IPC_RMID, NULL); rc = OPAL_ERROR; goto out; @@ -218,8 +190,8 @@ segment_create(opal_shmem_ds_t *ds_buf, int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, - "shmctl(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, "shmctl(2)", "", + strerror(err), err); rc = OPAL_ERROR; goto out; } @@ -229,7 +201,7 @@ segment_create(opal_shmem_ds_t *ds_buf, /* -- initialize the contents of opal_shmem_ds_t -- */ ds_buf->seg_cpid = my_pid; ds_buf->seg_size = size; - ds_buf->seg_base_addr = (unsigned char *)segment; + ds_buf->seg_base_addr = (unsigned char *) segment; /* notice that we are not setting ds_buf->name here. sysv doesn't use * it, so don't worry about it - shmem_ds_reset took care of @@ -239,14 +211,12 @@ segment_create(opal_shmem_ds_t *ds_buf, /* set "valid" bit because setment creation was successful */ OPAL_SHMEM_DS_SET_VALID(ds_buf); - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: create successful " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_sysv_component.super.base_version.mca_type_name, - mca_shmem_sysv_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: create successful " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_sysv_component.super.base_version.mca_type_name, + mca_shmem_sysv_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); } out: @@ -255,8 +225,8 @@ segment_create(opal_shmem_ds_t *ds_buf, */ if (OPAL_SUCCESS != rc) { /* best effort to delete the segment. */ - if ((void *)-1 != segment) { - shmdt((char*)segment); + if ((void *) -1 != segment) { + shmdt((char *) segment); } shmctl(ds_buf->seg_id, IPC_RMID, NULL); @@ -270,19 +240,17 @@ segment_create(opal_shmem_ds_t *ds_buf, /** * segment_attach can only be called after a successful call to segment_create */ -static void * -segment_attach(opal_shmem_ds_t *ds_buf) +static void *segment_attach(opal_shmem_ds_t *ds_buf) { pid_t my_pid = getpid(); if (my_pid != ds_buf->seg_cpid) { - if ((void *)-1 == (ds_buf->seg_base_addr = shmat(ds_buf->seg_id, NULL, - 0))) { + if ((void *) -1 == (ds_buf->seg_base_addr = shmat(ds_buf->seg_id, NULL, 0))) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, - "shmat(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, "shmat(2)", "", + strerror(err), err); shmctl(ds_buf->seg_id, IPC_RMID, NULL); return NULL; } @@ -291,40 +259,35 @@ segment_attach(opal_shmem_ds_t *ds_buf) * work was done in segment_create :-). */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: attach successful " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_sysv_component.super.base_version.mca_type_name, - mca_shmem_sysv_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: attach successful " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_sysv_component.super.base_version.mca_type_name, + mca_shmem_sysv_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); /* update returned base pointer with an offset that hides our stuff */ return ds_buf->seg_base_addr; } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_detach(opal_shmem_ds_t *ds_buf) +static int segment_detach(opal_shmem_ds_t *ds_buf) { int rc = OPAL_SUCCESS; - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: detaching " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_sysv_component.super.base_version.mca_type_name, - mca_shmem_sysv_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: detaching " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_sysv_component.super.base_version.mca_type_name, + mca_shmem_sysv_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); - if (0 != shmdt((char*)ds_buf->seg_base_addr)) { + if (0 != shmdt((char *) ds_buf->seg_base_addr)) { int err = errno; const char *hn; hn = opal_gethostname(); - opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, - "shmdt(2)", "", strerror(err), err); + opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn, "shmdt(2)", "", + strerror(err), err); rc = OPAL_ERROR; } @@ -336,19 +299,16 @@ segment_detach(opal_shmem_ds_t *ds_buf) } /* ////////////////////////////////////////////////////////////////////////// */ -static int -segment_unlink(opal_shmem_ds_t *ds_buf) +static int segment_unlink(opal_shmem_ds_t *ds_buf) { /* not much unlink work needed for sysv */ - OPAL_OUTPUT_VERBOSE( - (70, opal_shmem_base_framework.framework_output, - "%s: %s: unlinking " - "(id: %d, size: %lu, name: %s)\n", - mca_shmem_sysv_component.super.base_version.mca_type_name, - mca_shmem_sysv_component.super.base_version.mca_component_name, - ds_buf->seg_id, (unsigned long)ds_buf->seg_size, ds_buf->seg_name) - ); + OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output, + "%s: %s: unlinking " + "(id: %d, size: %lu, name: %s)\n", + mca_shmem_sysv_component.super.base_version.mca_type_name, + mca_shmem_sysv_component.super.base_version.mca_component_name, + ds_buf->seg_id, (unsigned long) ds_buf->seg_size, ds_buf->seg_name)); /* don't completely reset the opal_shmem_ds_t. in particular, only reset * the id and flip the invalid bit. size and name values will remain valid @@ -359,4 +319,3 @@ segment_unlink(opal_shmem_ds_t *ds_buf) OPAL_SHMEM_DS_INVALIDATE(ds_buf); return OPAL_SUCCESS; } - diff --git a/opal/mca/threads/argobots/threads_argobots_component.c b/opal/mca/threads/argobots/threads_argobots_component.c index 6c4e6f815fa..bce182b1086 100644 --- a/opal/mca/threads/argobots/threads_argobots_component.c +++ b/opal/mca/threads/argobots/threads_argobots_component.c @@ -23,30 +23,30 @@ #include "opal_config.h" +#include "opal/constants.h" #include "opal/mca/threads/argobots/threads_argobots.h" #include "opal/mca/threads/thread.h" #include "opal/mca/threads/threads.h" -#include "opal/constants.h" static int opal_threads_argobots_open(void); const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = { /* First, the mca_component_t struct containing meta information * about the component itself */ - .threadsc_version = { - OPAL_THREADS_BASE_VERSION_1_0_0, + .threadsc_version = + { + OPAL_THREADS_BASE_VERSION_1_0_0, - /* Component name and version */ - .mca_component_name = "argobots", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), + /* Component name and version */ + .mca_component_name = "argobots", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), - .mca_open_component = opal_threads_argobots_open, - }, - .threadsc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .mca_open_component = opal_threads_argobots_open, + }, + .threadsc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; int opal_threads_argobots_open(void) diff --git a/opal/mca/threads/argobots/threads_argobots_condition.c b/opal/mca/threads/argobots/threads_argobots_condition.c index 56b11cf9526..ca48c9bdf1b 100644 --- a/opal/mca/threads/argobots/threads_argobots_condition.c +++ b/opal/mca/threads/argobots/threads_argobots_condition.c @@ -33,7 +33,5 @@ static void opal_condition_destruct(opal_condition_t *c) { } -OBJ_CLASS_INSTANCE(opal_condition_t, - opal_object_t, - opal_condition_construct, +OBJ_CLASS_INSTANCE(opal_condition_t, opal_object_t, opal_condition_construct, opal_condition_destruct); diff --git a/opal/mca/threads/argobots/threads_argobots_module.c b/opal/mca/threads/argobots/threads_argobots_module.c index e1a0ba840e2..3d58de041eb 100644 --- a/opal/mca/threads/argobots/threads_argobots_module.c +++ b/opal/mca/threads/argobots/threads_argobots_module.c @@ -24,13 +24,13 @@ #include -#include "opal/mca/threads/argobots/threads_argobots.h" #include "opal/constants.h" -#include "opal/util/sys_limits.h" -#include "opal/util/output.h" -#include "opal/prefetch.h" +#include "opal/mca/threads/argobots/threads_argobots.h" #include "opal/mca/threads/threads.h" #include "opal/mca/threads/tsd.h" +#include "opal/prefetch.h" +#include "opal/util/output.h" +#include "opal/util/sys_limits.h" struct opal_tsd_key_value { opal_tsd_key_t key; @@ -51,9 +51,7 @@ static void opal_thread_construct(opal_thread_t *t) t->t_handle = ABT_THREAD_NULL; } -OBJ_CLASS_INSTANCE(opal_thread_t, - opal_object_t, - opal_thread_construct, NULL); +OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); static inline ABT_thread opal_thread_get_argobots_self(void) { @@ -64,8 +62,8 @@ static inline ABT_thread opal_thread_get_argobots_self(void) static void opal_thread_argobots_wrapper(void *arg) { - opal_thread_t *t = (opal_thread_t *)arg; - t->t_ret = ((void *(*)(void *))t->t_run)(t); + opal_thread_t *t = (opal_thread_t *) arg; + t->t_ret = ((void *(*) (void *) ) t->t_run)(t); } opal_thread_t *opal_thread_get_self(void) @@ -108,8 +106,7 @@ int opal_thread_start(opal_thread_t *t) ABT_xstream self_xstream; ABT_xstream_self(&self_xstream); - rc = ABT_thread_create_on_xstream(self_xstream, - opal_thread_argobots_wrapper, t, + rc = ABT_thread_create_on_xstream(self_xstream, opal_thread_argobots_wrapper, t, ABT_THREAD_ATTR_NULL, &t->t_handle); return (ABT_SUCCESS == rc) ? OPAL_SUCCESS : OPAL_ERROR; diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.c b/opal/mca/threads/argobots/threads_argobots_mutex.c index ce0df909629..330d7120439 100644 --- a/opal/mca/threads/argobots/threads_argobots_mutex.c +++ b/opal/mca/threads/argobots/threads_argobots_mutex.c @@ -23,14 +23,14 @@ * $HEADER$ */ -#include "opal/mca/threads/argobots/threads_argobots.h" #include "opal_config.h" +#include "opal/mca/threads/argobots/threads_argobots.h" #include -#include "opal/mca/threads/mutex.h" -#include "opal/mca/threads/argobots/threads_argobots_mutex.h" #include "opal/constants.h" +#include "opal/mca/threads/argobots/threads_argobots_mutex.h" +#include "opal/mca/threads/mutex.h" /* * Wait and see if some upper layer wants to use threads, if support @@ -58,8 +58,7 @@ static void mca_threads_argobots_mutex_destructor(opal_mutex_t *p_mutex) } } -static void mca_threads_argobots_recursive_mutex_constructor - (opal_recursive_mutex_t *p_mutex) +static void mca_threads_argobots_recursive_mutex_constructor(opal_recursive_mutex_t *p_mutex) { opal_threads_argobots_ensure_init(); p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL; @@ -72,20 +71,16 @@ static void mca_threads_argobots_recursive_mutex_constructor opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); } -static void mca_threads_argobots_recursive_mutex_destructor - (opal_recursive_mutex_t *p_mutex) +static void mca_threads_argobots_recursive_mutex_destructor(opal_recursive_mutex_t *p_mutex) { if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) { ABT_mutex_free(&p_mutex->m_lock_argobots); } } -OBJ_CLASS_INSTANCE(opal_mutex_t, - opal_object_t, - mca_threads_argobots_mutex_constructor, +OBJ_CLASS_INSTANCE(opal_mutex_t, opal_object_t, mca_threads_argobots_mutex_constructor, mca_threads_argobots_mutex_destructor); -OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, - opal_object_t, +OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, opal_object_t, mca_threads_argobots_recursive_mutex_constructor, mca_threads_argobots_recursive_mutex_destructor); @@ -104,9 +99,8 @@ void opal_mutex_create(struct opal_mutex_t *m) ABT_mutex_create(&abt_mutex); } void *null_ptr = OPAL_ABT_MUTEX_NULL; - if (opal_atomic_compare_exchange_strong_ptr( - (opal_atomic_intptr_t *)&m->m_lock_argobots, (intptr_t *)&null_ptr, - (intptr_t)abt_mutex)) { + if (opal_atomic_compare_exchange_strong_ptr((opal_atomic_intptr_t *) &m->m_lock_argobots, + (intptr_t *) &null_ptr, (intptr_t) abt_mutex)) { /* mutex is successfully created and substituted. */ return; } @@ -121,9 +115,8 @@ static void opal_cond_create(opal_cond_t *cond) ABT_cond new_cond; ABT_cond_create(&new_cond); void *null_ptr = OPAL_ABT_COND_NULL; - if (opal_atomic_compare_exchange_strong_ptr((opal_atomic_intptr_t *)cond, - (intptr_t *)&null_ptr, - (intptr_t)new_cond)) { + if (opal_atomic_compare_exchange_strong_ptr((opal_atomic_intptr_t *) cond, + (intptr_t *) &null_ptr, (intptr_t) new_cond)) { /* cond is successfully created and substituted. */ return; } diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.h b/opal/mca/threads/argobots/threads_argobots_mutex.h index 7dff30f010d..a60c229002c 100644 --- a/opal/mca/threads/argobots/threads_argobots_mutex.h +++ b/opal/mca/threads/argobots/threads_argobots_mutex.h @@ -40,7 +40,6 @@ #include "opal/sys/atomic.h" #include "opal/util/output.h" - BEGIN_C_DECLS /* Don't use ABT_MUTEX_NULL, since it might be not NULL. */ @@ -65,45 +64,33 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); #if OPAL_ENABLE_DEBUG -#define OPAL_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ - .m_recursive = 0, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 0, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #else -#define OPAL_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ - .m_recursive = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 0, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #endif #if OPAL_ENABLE_DEBUG -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ - .m_recursive = 1, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 1, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #else -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ - .m_recursive = 1, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \ + .m_recursive = 1, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #endif /************************************************************************ diff --git a/opal/mca/threads/argobots/threads_argobots_threads.h b/opal/mca/threads/argobots/threads_argobots_threads.h index 3992b32f274..649553adcbd 100644 --- a/opal/mca/threads/argobots/threads_argobots_threads.h +++ b/opal/mca/threads/argobots/threads_argobots_threads.h @@ -26,8 +26,8 @@ #ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H #define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H -#include #include "opal/mca/threads/argobots/threads_argobots.h" +#include struct opal_thread_t { opal_object_t super; @@ -37,12 +37,10 @@ struct opal_thread_t { void *t_ret; }; - /* Argobots are cooperatively scheduled so yield when idle */ #define OPAL_THREAD_YIELD_WHEN_IDLE_DEFAULT true -static inline -void opal_thread_yield(void) +static inline void opal_thread_yield(void) { ABT_thread_yield(); } diff --git a/opal/mca/threads/argobots/threads_argobots_tsd.h b/opal/mca/threads/argobots/threads_argobots_tsd.h index e441d56992d..c1c2468438d 100644 --- a/opal/mca/threads/argobots/threads_argobots_tsd.h +++ b/opal/mca/threads/argobots/threads_argobots_tsd.h @@ -23,7 +23,6 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H #define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.c b/opal/mca/threads/argobots/threads_argobots_wait_sync.c index 34ec10d5a74..5735fd128be 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.c +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.c @@ -23,11 +23,11 @@ static ompi_wait_sync_t *wait_sync_list = NULL; static opal_atomic_int32_t num_thread_in_progress = 0; -#define WAIT_SYNC_PASS_OWNERSHIP(who) \ - do { \ - ABT_mutex_lock((who)->lock); \ - ABT_cond_signal((who)->condition ); \ - ABT_mutex_unlock((who)->lock); \ +#define WAIT_SYNC_PASS_OWNERSHIP(who) \ + do { \ + ABT_mutex_lock((who)->lock); \ + ABT_cond_signal((who)->condition); \ + ABT_mutex_unlock((who)->lock); \ } while (0) int ompi_sync_wait_mt(ompi_wait_sync_t *sync) @@ -70,9 +70,8 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if (sync != wait_sync_list && - num_thread_in_progress >= opal_max_thread_in_progress) { +check_status: + if (sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { ABT_cond_wait(sync->condition, sync->lock); /** @@ -98,7 +97,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: +i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.h b/opal/mca/threads/argobots/threads_argobots_wait_sync.h index 0c46c7b872d..4117e92e5c1 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.h +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.h @@ -38,8 +38,7 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) \ - (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -49,34 +48,33 @@ typedef struct ompi_wait_sync_t { * as possible. Note that the race window is small so spinning here * is more optimal than sleeping since this macro is called in * the critical path. */ -#define WAIT_SYNC_RELEASE(sync) \ - if (opal_using_threads()) { \ - while ((sync)->signaling) { \ - ABT_thread_yield(); \ - continue; \ - } \ - ABT_cond_free(&(sync)->condition); \ - ABT_mutex_free(&(sync)->lock); \ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + while ((sync)->signaling) { \ + ABT_thread_yield(); \ + continue; \ + } \ + ABT_cond_free(&(sync)->condition); \ + ABT_mutex_free(&(sync)->lock); \ } -#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ - if (opal_using_threads()) { \ - ABT_cond_free(&(sync)->condition); \ - ABT_mutex_free(&(sync)->lock); \ +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + ABT_cond_free(&(sync)->condition); \ + ABT_mutex_free(&(sync)->lock); \ } - -#define WAIT_SYNC_SIGNAL(sync) \ - if (opal_using_threads()) { \ - ABT_mutex_lock(sync->lock); \ - ABT_cond_signal(sync->condition); \ - ABT_mutex_unlock(sync->lock); \ - sync->signaling = false; \ +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + ABT_mutex_lock(sync->lock); \ + ABT_cond_signal(sync->condition); \ + ABT_mutex_unlock(sync->lock); \ + sync->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync) \ - { \ - (sync)->signaling = false; \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ + (sync)->signaling = false; \ } OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); @@ -89,18 +87,17 @@ static inline int sync_wait_st(ompi_wait_sync_t *sync) return sync->status; } - -#define WAIT_SYNC_INIT(sync,c) \ - do { \ - (sync)->count = (c); \ - (sync)->next = NULL; \ - (sync)->prev = NULL; \ - (sync)->status = 0; \ - (sync)->signaling = (0 != (c)); \ - if (opal_using_threads()) { \ - ABT_cond_create(&(sync)->condition); \ - ABT_mutex_create(&(sync)->lock); \ - } \ +#define WAIT_SYNC_INIT(sync, c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + ABT_cond_create(&(sync)->condition); \ + ABT_mutex_create(&(sync)->lock); \ + } \ } while (0) #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/base/base.h b/opal/mca/threads/base/base.h index dd774005068..f6a0a6ab70f 100644 --- a/opal/mca/threads/base/base.h +++ b/opal/mca/threads/base/base.h @@ -28,7 +28,6 @@ #include "opal/mca/base/mca_base_framework.h" #include "opal/mca/threads/threads.h" - /* * Global functions for MCA overall threads open and close */ diff --git a/opal/mca/threads/base/threads_base.c b/opal/mca/threads/base/threads_base.c index a0611da1900..227aaeb64d3 100644 --- a/opal/mca/threads/base/threads_base.c +++ b/opal/mca/threads/base/threads_base.c @@ -45,6 +45,5 @@ static int mca_threads_base_register(mca_base_register_flag_t flags) * Globals */ /* Use default register/open/close functions */ -MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL threads", - mca_threads_base_register, NULL, NULL, +MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL threads", mca_threads_base_register, NULL, NULL, mca_threads_base_static_components, 0); diff --git a/opal/mca/threads/base/tsd.c b/opal/mca/threads/base/tsd.c index bb5c92afb99..4eec185c4c0 100644 --- a/opal/mca/threads/base/tsd.c +++ b/opal/mca/threads/base/tsd.c @@ -1,15 +1,16 @@ #include "opal/mca/threads/tsd.h" -static void _tracked_destructor(void *arg) { +static void _tracked_destructor(void *arg) +{ opal_tsd_list_item_t *tsd = NULL; opal_tsd_tracked_key_t *key = NULL; if (NULL == arg) { return; } - tsd = (opal_tsd_list_item_t *)arg; + tsd = (opal_tsd_list_item_t *) arg; key = tsd->tracked_key; - + opal_mutex_lock(&key->mutex); opal_list_remove_item(&key->tsd_list, &tsd->super); opal_mutex_unlock(&key->mutex); @@ -20,7 +21,8 @@ static void _tracked_destructor(void *arg) { OBJ_RELEASE(tsd); } -void opal_tsd_tracked_key_constructor(opal_tsd_tracked_key_t *key) { +void opal_tsd_tracked_key_constructor(opal_tsd_tracked_key_t *key) +{ OBJ_CONSTRUCT(&key->mutex, opal_mutex_t); OBJ_CONSTRUCT(&key->tsd_list, opal_list_t); key->user_destructor = NULL; @@ -32,7 +34,7 @@ void opal_tsd_tracked_key_destructor(opal_tsd_tracked_key_t *key) opal_tsd_list_item_t *tsd, *next; opal_tsd_key_delete(key->key); - OPAL_LIST_FOREACH_SAFE(tsd, next, &key->tsd_list, opal_tsd_list_item_t) { + OPAL_LIST_FOREACH_SAFE (tsd, next, &key->tsd_list, opal_tsd_list_item_t) { opal_list_remove_item(&key->tsd_list, &tsd->super); if (NULL != key->user_destructor) { key->user_destructor(tsd->data); @@ -45,10 +47,10 @@ void opal_tsd_tracked_key_destructor(opal_tsd_tracked_key_t *key) int opal_tsd_tracked_key_set(opal_tsd_tracked_key_t *key, void *p) { - assert( NULL != key); - + assert(NULL != key); + opal_tsd_list_item_t *tsd = NULL; - opal_tsd_get(key->key, (void **)&tsd); + opal_tsd_get(key->key, (void **) &tsd); if (NULL == tsd) { tsd = OBJ_NEW(opal_tsd_list_item_t); @@ -64,15 +66,16 @@ int opal_tsd_tracked_key_set(opal_tsd_tracked_key_t *key, void *p) tsd->data = p; tsd->tracked_key = key; - return opal_tsd_set(key->key, (void *)tsd); + return opal_tsd_set(key->key, (void *) tsd); } -void opal_tsd_tracked_key_set_destructor(opal_tsd_tracked_key_t *key, opal_tsd_destructor_t destructor) +void opal_tsd_tracked_key_set_destructor(opal_tsd_tracked_key_t *key, + opal_tsd_destructor_t destructor) { - assert (NULL != key); + assert(NULL != key); key->user_destructor = destructor; } OBJ_CLASS_INSTANCE(opal_tsd_list_item_t, opal_list_item_t, NULL, NULL); -OBJ_CLASS_INSTANCE(opal_tsd_tracked_key_t, opal_object_t, - opal_tsd_tracked_key_constructor, opal_tsd_tracked_key_destructor); +OBJ_CLASS_INSTANCE(opal_tsd_tracked_key_t, opal_object_t, opal_tsd_tracked_key_constructor, + opal_tsd_tracked_key_destructor); diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h index 031c8e9b3ec..799b8bae0b3 100644 --- a/opal/mca/threads/condition.h +++ b/opal/mca/threads/condition.h @@ -30,10 +30,10 @@ #include "opal_config.h" #ifdef HAVE_SYS_TIME_H -#include +# include #endif -#include #include +#include #include "opal/constants.h" #include "opal/mca/threads/mutex.h" @@ -55,7 +55,6 @@ typedef struct opal_condition_t opal_condition_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_condition_t); - static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) { int rc = OPAL_SUCCESS; @@ -103,9 +102,9 @@ static inline int opal_condition_timedwait(opal_condition_t *c, opal_mutex_t *m, opal_progress(); gettimeofday(&tv, NULL); opal_mutex_lock(m); - } while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && - tv.tv_usec < absolute.tv_usec))); + } while (0 == c->c_signaled + && (tv.tv_sec <= absolute.tv_sec + || (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); } } else { absolute.tv_sec = abstime->tv_sec; @@ -115,9 +114,9 @@ static inline int opal_condition_timedwait(opal_condition_t *c, opal_mutex_t *m, do { opal_progress(); gettimeofday(&tv, NULL); - } while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && - tv.tv_usec < absolute.tv_usec))); + } while (0 == c->c_signaled + && (tv.tv_sec <= absolute.tv_sec + || (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); } } diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index a81e94cb6e8..552f9f115ad 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -51,7 +51,6 @@ typedef struct opal_mutex_t opal_recursive_mutex_t; OBJ_CLASS_DECLARATION(opal_mutex_t); OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); - /** * Try to acquire a mutex. * @@ -60,7 +59,6 @@ OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); */ static inline int opal_mutex_trylock(opal_mutex_t *mutex); - /** * Acquire a mutex. * @@ -68,7 +66,6 @@ static inline int opal_mutex_trylock(opal_mutex_t *mutex); */ static inline void opal_mutex_lock(opal_mutex_t *mutex); - /** * Release a mutex. * @@ -76,7 +73,6 @@ static inline void opal_mutex_lock(opal_mutex_t *mutex); */ static inline void opal_mutex_unlock(opal_mutex_t *mutex); - /** * Try to acquire a mutex using atomic operations. * @@ -85,7 +81,6 @@ static inline void opal_mutex_unlock(opal_mutex_t *mutex); */ static inline int opal_mutex_atomic_trylock(opal_mutex_t *mutex); - /** * Acquire a mutex using atomic operations. * @@ -93,7 +88,6 @@ static inline int opal_mutex_atomic_trylock(opal_mutex_t *mutex); */ static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex); - /** * Release a mutex using atomic operations. * @@ -101,7 +95,6 @@ static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex); */ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); - /** * Lock a mutex if opal_using_threads() says that multiple threads may * be active in the process. @@ -115,14 +108,13 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, return immediately. */ -#define OPAL_THREAD_LOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - } \ +#define OPAL_THREAD_LOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + } \ } while (0) - /** * Try to lock a mutex if opal_using_threads() says that multiple * threads may be active in the process. @@ -161,7 +153,6 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); } \ } while (0) - /** * Lock a mutex if opal_using_threads() says that multiple threads may * be active in the process for the duration of the specified action. diff --git a/opal/mca/threads/pthreads/threads_pthreads.h b/opal/mca/threads/pthreads/threads_pthreads.h index 0801e56a09a..3d786516fc7 100644 --- a/opal/mca/threads/pthreads/threads_pthreads.h +++ b/opal/mca/threads/pthreads/threads_pthreads.h @@ -10,7 +10,6 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_H @@ -18,7 +17,7 @@ #include #include -typedef void (opal_threads_pthreads_yield_fn_t)(void); +typedef void(opal_threads_pthreads_yield_fn_t)(void); OPAL_DECLSPEC int opal_threads_pthreads_yield_init(const mca_base_component_t *component); diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c index 30c6ca70336..d2d51adc23a 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_component.c +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -23,11 +23,10 @@ #include "opal_config.h" -#include "opal/mca/threads/thread.h" -#include "opal/mca/threads/threads.h" #include "opal/constants.h" #include "opal/mca/threads/pthreads/threads_pthreads.h" - +#include "opal/mca/threads/thread.h" +#include "opal/mca/threads/threads.h" static int opal_threads_pthreads_open(void); static int opal_threads_pthreads_register(void); @@ -35,21 +34,18 @@ static int opal_threads_pthreads_register(void); const opal_threads_base_component_1_0_0_t mca_threads_pthreads_component = { /* First, the mca_component_t struct containing meta information * about the component itself */ - .threadsc_version = { - OPAL_THREADS_BASE_VERSION_1_0_0, - - /* Component name and version */ - .mca_component_name = "pthreads", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - .mca_open_component = opal_threads_pthreads_open, - .mca_register_component_params = opal_threads_pthreads_register - }, - .threadsc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .threadsc_version = {OPAL_THREADS_BASE_VERSION_1_0_0, + + /* Component name and version */ + .mca_component_name = "pthreads", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + .mca_open_component = opal_threads_pthreads_open, + .mca_register_component_params = opal_threads_pthreads_register}, + .threadsc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; int opal_threads_pthreads_register(void) diff --git a/opal/mca/threads/pthreads/threads_pthreads_condition.c b/opal/mca/threads/pthreads/threads_pthreads_condition.c index f685a24cef5..ca48c9bdf1b 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_condition.c +++ b/opal/mca/threads/pthreads/threads_pthreads_condition.c @@ -23,7 +23,6 @@ #include "opal/mca/threads/condition.h" - static void opal_condition_construct(opal_condition_t *c) { c->c_waiting = 0; @@ -34,7 +33,5 @@ static void opal_condition_destruct(opal_condition_t *c) { } -OBJ_CLASS_INSTANCE(opal_condition_t, - opal_object_t, - opal_condition_construct, +OBJ_CLASS_INSTANCE(opal_condition_t, opal_object_t, opal_condition_construct, opal_condition_destruct); diff --git a/opal/mca/threads/pthreads/threads_pthreads_module.c b/opal/mca/threads/pthreads/threads_pthreads_module.c index 2f1e918a4c6..70dec2964b6 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_module.c +++ b/opal/mca/threads/pthreads/threads_pthreads_module.c @@ -26,11 +26,11 @@ #include #include "opal/constants.h" -#include "opal/util/sys_limits.h" -#include "opal/util/output.h" -#include "opal/prefetch.h" #include "opal/mca/threads/threads.h" #include "opal/mca/threads/tsd.h" +#include "opal/prefetch.h" +#include "opal/util/output.h" +#include "opal/util/sys_limits.h" /* * Constructor @@ -38,24 +38,22 @@ static void opal_thread_construct(opal_thread_t *t) { t->t_run = 0; - t->t_handle = (pthread_t)-1; + t->t_handle = (pthread_t) -1; } -OBJ_CLASS_INSTANCE(opal_thread_t, - opal_object_t, - opal_thread_construct, NULL); +OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); int opal_thread_start(opal_thread_t *t) { int rc; if (OPAL_ENABLE_DEBUG) { - if (NULL == t->t_run || (pthread_t)-1 != t->t_handle) { + if (NULL == t->t_run || (pthread_t) -1 != t->t_handle) { return OPAL_ERR_BAD_PARAM; } } - rc = pthread_create(&t->t_handle, NULL, (void *(*)(void *))t->t_run, t); + rc = pthread_create(&t->t_handle, NULL, (void *(*) (void *) ) t->t_run, t); return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO; } @@ -63,7 +61,7 @@ int opal_thread_start(opal_thread_t *t) int opal_thread_join(opal_thread_t *t, void **thr_return) { int rc = pthread_join(t->t_handle, thr_return); - t->t_handle = (pthread_t)-1; + t->t_handle = (pthread_t) -1; return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO; } diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.c b/opal/mca/threads/pthreads/threads_pthreads_mutex.c index 8aa4671f46f..8072cfccd49 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.c +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.c @@ -28,9 +28,9 @@ #include #include +#include "opal/constants.h" #include "opal/mca/threads/mutex.h" #include "opal/mca/threads/pthreads/threads_pthreads_mutex.h" -#include "opal/constants.h" /* * Wait and see if some upper layer wants to use threads, if support @@ -70,8 +70,7 @@ static void mca_threads_pthreads_mutex_destructor(opal_mutex_t *p_mutex) pthread_mutex_destroy(&p_mutex->m_lock_pthread); } -static void mca_threads_pthreads_recursive_mutex_constructor - (opal_recursive_mutex_t *p_mutex) +static void mca_threads_pthreads_recursive_mutex_constructor(opal_recursive_mutex_t *p_mutex) { pthread_mutexattr_t mutex_attr; pthread_mutexattr_init(&mutex_attr); @@ -86,19 +85,15 @@ static void mca_threads_pthreads_recursive_mutex_constructor opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); } -static void mca_threads_pthreads_recursive_mutex_destructor - (opal_recursive_mutex_t *p_mutex) +static void mca_threads_pthreads_recursive_mutex_destructor(opal_recursive_mutex_t *p_mutex) { pthread_mutex_destroy(&p_mutex->m_lock_pthread); } -OBJ_CLASS_INSTANCE(opal_mutex_t, - opal_object_t, - mca_threads_pthreads_mutex_constructor, +OBJ_CLASS_INSTANCE(opal_mutex_t, opal_object_t, mca_threads_pthreads_mutex_constructor, mca_threads_pthreads_mutex_destructor); -OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, - opal_object_t, +OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, opal_object_t, mca_threads_pthreads_recursive_mutex_constructor, mca_threads_pthreads_recursive_mutex_destructor); diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.h b/opal/mca/threads/pthreads/threads_pthreads_mutex.h index 1547426d209..d60ed8dff54 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.h +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.h @@ -41,8 +41,8 @@ #include "opal_config.h" -#include #include +#include #include #include "opal/class/opal_object.h" @@ -68,52 +68,43 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) -#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +# define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) -#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER #endif #if OPAL_ENABLE_DEBUG -#define OPAL_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, .m_lock_debug = 0, .m_lock_file = NULL, \ + .m_lock_line = 0, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #else -#define OPAL_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #endif #if defined(OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER) -#if OPAL_ENABLE_DEBUG -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_pthread = OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } -#else -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock_pthread = OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } -#endif +# if OPAL_ENABLE_DEBUG +# define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_pthread = OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER, .m_lock_debug = 0, \ + .m_lock_file = NULL, .m_lock_line = 0, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +# else +# define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ + .m_lock_pthread = OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } +# endif #endif @@ -128,7 +119,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) int ret = pthread_mutex_trylock(&m->m_lock_pthread); if (EDEADLK == ret) { #if OPAL_ENABLE_DEBUG - opal_output(0, "opal_mutex_trylock() %d",ret); + opal_output(0, "opal_mutex_trylock() %d", ret); #endif return 1; } diff --git a/opal/mca/threads/pthreads/threads_pthreads_threads.h b/opal/mca/threads/pthreads/threads_pthreads_threads.h index 2d5d062f1d0..3cd7a3dae14 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_threads.h +++ b/opal/mca/threads/pthreads/threads_pthreads_threads.h @@ -23,15 +23,14 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H #include #include -#include "opal/mca/threads/threads.h" #include "opal/mca/threads/pthreads/threads_pthreads.h" +#include "opal/mca/threads/threads.h" struct opal_thread_t { opal_object_t super; @@ -43,8 +42,7 @@ struct opal_thread_t { /* Pthreads do not need to yield when idle */ #define OPAL_THREAD_YIELD_WHEN_IDLE_DEFAULT false -static inline -void opal_thread_yield(void) +static inline void opal_thread_yield(void) { opal_threads_pthreads_yield_fn(); } diff --git a/opal/mca/threads/pthreads/threads_pthreads_tsd.h b/opal/mca/threads/pthreads/threads_pthreads_tsd.h index 4db2ed4c3bc..f8e8e4e290f 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_tsd.h +++ b/opal/mca/threads/pthreads/threads_pthreads_tsd.h @@ -23,7 +23,6 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c index 3cb63127539..eb777d95dd3 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c @@ -20,33 +20,32 @@ static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; ompi_wait_sync_t *wait_sync_list = NULL; /* not static for inline "wait_sync_st" */ - void wait_sync_global_wakeup_st(int status) { - ompi_wait_sync_t* sync; - for( sync = wait_sync_list; sync != NULL; sync = sync->next ) { + ompi_wait_sync_t *sync; + for (sync = wait_sync_list; sync != NULL; sync = sync->next) { wait_sync_update(sync, 0, status); } } void wait_sync_global_wakeup_mt(int status) { - ompi_wait_sync_t* sync; + ompi_wait_sync_t *sync; opal_mutex_lock(&wait_sync_lock); - for( sync = wait_sync_list; sync != NULL; sync = sync->next ) { - /* sync_update is going to take the sync->lock from within - * the wait_sync_lock. Thread lightly here: Idealy we should + for (sync = wait_sync_list; sync != NULL; sync = sync->next) { + /* sync_update is going to take the sync->lock from within + * the wait_sync_lock. Thread lightly here: Idealy we should * find a way to not take a lock in a lock as this is deadlock prone, - * but as of today we are the only place doing this so it is safe. + * but as of today we are the only place doing this so it is safe. */ wait_sync_update(sync, 0, status); - if( sync->next == wait_sync_list ) break; /* special case for rings */ + if (sync->next == wait_sync_list) { + break; /* special case for rings */ + } } opal_mutex_unlock(&wait_sync_lock); } - - static opal_atomic_int32_t num_thread_in_progress = 0; #define WAIT_SYNC_PASS_OWNERSHIP(who) \ @@ -96,9 +95,8 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if (sync != wait_sync_list && - num_thread_in_progress >= opal_max_thread_in_progress) { +check_status: + if (sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { pthread_cond_wait(&sync->condition, &sync->lock); /** @@ -123,7 +121,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: +i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h index e8f5bfe0b17..e84a24e12e2 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h @@ -23,7 +23,6 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H #define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H @@ -37,8 +36,7 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) \ - (opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync)) +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -48,44 +46,42 @@ typedef struct ompi_wait_sync_t { * as possible. Note that the race window is small so spinning here * is more optimal than sleeping since this macro is called in * the critical path. */ -#define WAIT_SYNC_RELEASE(sync) \ - if (opal_using_threads()) { \ - while ((sync)->signaling) { \ - continue; \ - } \ - pthread_cond_destroy(&(sync)->condition); \ - pthread_mutex_destroy(&(sync)->lock); \ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + while ((sync)->signaling) { \ + continue; \ + } \ + pthread_cond_destroy(&(sync)->condition); \ + pthread_mutex_destroy(&(sync)->lock); \ } -#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ - if (opal_using_threads()) { \ - pthread_cond_destroy(&(sync)->condition); \ - pthread_mutex_destroy(&(sync)->lock); \ +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + pthread_cond_destroy(&(sync)->condition); \ + pthread_mutex_destroy(&(sync)->lock); \ } - -#define WAIT_SYNC_SIGNAL(sync) \ - if (opal_using_threads()) { \ - pthread_mutex_lock(&(sync->lock)); \ - pthread_cond_signal(&sync->condition); \ - pthread_mutex_unlock(&(sync->lock)); \ - sync->signaling = false; \ +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + pthread_mutex_lock(&(sync->lock)); \ + pthread_cond_signal(&sync->condition); \ + pthread_mutex_unlock(&(sync->lock)); \ + sync->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync) \ - { \ - (sync)->signaling = false; \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ + (sync)->signaling = false; \ } - /* not static for inline "wait_sync_st" */ OPAL_DECLSPEC extern ompi_wait_sync_t *wait_sync_list; OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); static inline int sync_wait_st(ompi_wait_sync_t *sync) { - assert( NULL == wait_sync_list ); - assert( NULL == sync->next ); + assert(NULL == wait_sync_list); + assert(NULL == sync->next); wait_sync_list = sync; while (sync->count > 0) { @@ -96,17 +92,17 @@ static inline int sync_wait_st(ompi_wait_sync_t *sync) return sync->status; } -#define WAIT_SYNC_INIT(sync,c) \ - do { \ - (sync)->count = (c); \ - (sync)->next = NULL; \ - (sync)->prev = NULL; \ - (sync)->status = 0; \ - (sync)->signaling = (0 != (c)); \ - if (opal_using_threads()) { \ - pthread_cond_init(&(sync)->condition, NULL); \ - pthread_mutex_init(&(sync)->lock, NULL); \ - } \ +#define WAIT_SYNC_INIT(sync, c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + pthread_cond_init(&(sync)->condition, NULL); \ + pthread_mutex_init(&(sync)->lock, NULL); \ + } \ } while (0) /** @@ -116,6 +112,7 @@ static inline int sync_wait_st(ompi_wait_sync_t *sync) */ OPAL_DECLSPEC void wait_sync_global_wakeup_st(int status); OPAL_DECLSPEC void wait_sync_global_wakeup_mt(int status); -#define wait_sync_global_wakeup(st) (opal_using_threads()? wait_sync_global_wakeup_mt(st): wait_sync_global_wakeup_st(st)) +#define wait_sync_global_wakeup(st) \ + (opal_using_threads() ? wait_sync_global_wakeup_mt(st) : wait_sync_global_wakeup_st(st)) #endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_yield.c b/opal/mca/threads/pthreads/threads_pthreads_yield.c index d68126fea4a..3ae102e43e0 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_yield.c +++ b/opal/mca/threads/pthreads/threads_pthreads_yield.c @@ -13,12 +13,12 @@ #include "opal_config.h" #include #ifdef HAVE_SCHED_H -#include +# include #endif #include "opal/constants.h" -#include "opal/mca/threads/thread.h" #include "opal/mca/threads/pthreads/threads_pthreads.h" +#include "opal/mca/threads/thread.h" static void opal_thread_pthreads_yield_sched_yield(void); static void opal_thread_pthreads_yield_nanosleep(void); @@ -28,12 +28,11 @@ typedef enum { OPAL_PTHREADS_YIELD_NANOSLEEP } opal_threads_pthreads_yield_strategy_t; -static mca_base_var_enum_value_t yield_strategy_values[] = { - {OPAL_PTHREADS_YIELD_SCHED_YIELD, "sched_yield"}, - {OPAL_PTHREADS_YIELD_NANOSLEEP, "nanosleep"}, - {0, NULL}}; - - +static mca_base_var_enum_value_t yield_strategy_values[] = {{OPAL_PTHREADS_YIELD_SCHED_YIELD, + "sched_yield"}, + {OPAL_PTHREADS_YIELD_NANOSLEEP, + "nanosleep"}, + {0, NULL}}; /* Number of nanoseconds to nanosleep, if enabled */ static uint64_t yield_nsleep_nanosecs; @@ -41,38 +40,40 @@ static uint64_t yield_nsleep_nanosecs; static struct timespec yield_nsleep_time = {.tv_sec = 0, .tv_nsec = 1}; static opal_threads_pthreads_yield_strategy_t yield_strategy = OPAL_PTHREADS_YIELD_SCHED_YIELD; -opal_threads_pthreads_yield_fn_t *opal_threads_pthreads_yield_fn = &opal_thread_pthreads_yield_sched_yield; +opal_threads_pthreads_yield_fn_t *opal_threads_pthreads_yield_fn + = &opal_thread_pthreads_yield_sched_yield; int opal_threads_pthreads_yield_init(const mca_base_component_t *component) { mca_base_var_enum_t *yield_strategy_enumerator; - mca_base_var_enum_create("pthread_yield_strategies", yield_strategy_values, &yield_strategy_enumerator); + mca_base_var_enum_create("pthread_yield_strategies", yield_strategy_values, + &yield_strategy_enumerator); (void) mca_base_component_var_register(component, "yield_strategy", - "Pthread yield strategy to use", - MCA_BASE_VAR_TYPE_INT, yield_strategy_enumerator, 0, 0, OPAL_INFO_LVL_3, + "Pthread yield strategy to use", MCA_BASE_VAR_TYPE_INT, + yield_strategy_enumerator, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, &yield_strategy); - switch(yield_strategy) { - case OPAL_PTHREADS_YIELD_NANOSLEEP: - opal_threads_pthreads_yield_fn = &opal_thread_pthreads_yield_nanosleep; - break; - default: - /* use initial value */ - break; + switch (yield_strategy) { + case OPAL_PTHREADS_YIELD_NANOSLEEP: + opal_threads_pthreads_yield_fn = &opal_thread_pthreads_yield_nanosleep; + break; + default: + /* use initial value */ + break; } OBJ_RELEASE(yield_strategy_enumerator); yield_nsleep_nanosecs = (yield_nsleep_time.tv_sec * 1E9) + yield_nsleep_time.tv_nsec; - (void) mca_base_component_var_register(component, "nanosleep_time", - "Number of nanoseconds to sleep when using nanosleep as the pthread yield strategy", - MCA_BASE_VAR_TYPE_UINT64_T, NULL, 0, 0, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, &yield_nsleep_nanosecs); - yield_nsleep_time.tv_sec = yield_nsleep_nanosecs / 1E9; + (void) mca_base_component_var_register( + component, "nanosleep_time", + "Number of nanoseconds to sleep when using nanosleep as the pthread yield strategy", + MCA_BASE_VAR_TYPE_UINT64_T, NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, + &yield_nsleep_nanosecs); + yield_nsleep_time.tv_sec = yield_nsleep_nanosecs / 1E9; yield_nsleep_time.tv_nsec = yield_nsleep_nanosecs - (uint64_t)(yield_nsleep_time.tv_sec * 1E9); return OPAL_SUCCESS; - } void opal_thread_pthreads_yield_sched_yield(void) @@ -86,4 +87,3 @@ void opal_thread_pthreads_yield_nanosleep(void) { nanosleep(&yield_nsleep_time, NULL); } - diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c index cf8f5944620..9ce9ac6f630 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_component.c +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -23,30 +23,30 @@ #include "opal_config.h" +#include "opal/constants.h" #include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/mca/threads/thread.h" #include "opal/mca/threads/threads.h" -#include "opal/constants.h" static int opal_threads_qthreads_open(void); const opal_threads_base_component_1_0_0_t mca_threads_qthreads_component = { /* First, the mca_component_t struct containing meta information * about the component itself */ - .threadsc_version = { - OPAL_THREADS_BASE_VERSION_1_0_0, + .threadsc_version = + { + OPAL_THREADS_BASE_VERSION_1_0_0, - /* Component name and version */ - .mca_component_name = "qthreads", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), + /* Component name and version */ + .mca_component_name = "qthreads", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), - .mca_open_component = opal_threads_qthreads_open, - }, - .threadsc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .mca_open_component = opal_threads_qthreads_open, + }, + .threadsc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; int opal_threads_qthreads_open(void) diff --git a/opal/mca/threads/qthreads/threads_qthreads_condition.c b/opal/mca/threads/qthreads/threads_qthreads_condition.c index 7c569b3898a..f9d9b195336 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_condition.c +++ b/opal/mca/threads/qthreads/threads_qthreads_condition.c @@ -27,16 +27,10 @@ #include "opal/mca/threads/condition.h" - static void opal_condition_construct(opal_condition_t *c) { c->c_waiting = 0; c->c_signaled = 0; } - - -OBJ_CLASS_INSTANCE(opal_condition_t, - opal_object_t, - opal_condition_construct, - NULL); +OBJ_CLASS_INSTANCE(opal_condition_t, opal_object_t, opal_condition_construct, NULL); diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c index d53c0681772..a5dc24674a2 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_module.c +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -19,8 +19,8 @@ * $HEADER$ */ -#include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/constants.h" +#include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/mca/threads/threads.h" #include "opal/mca/threads/tsd.h" @@ -60,26 +60,24 @@ static void opal_thread_construct(opal_thread_t *t) t->t_thread_ret = 0; } -OBJ_CLASS_INSTANCE(opal_thread_t, - opal_object_t, - opal_thread_construct, NULL); +OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); static inline aligned_t *opal_thread_get_qthreads_self(void) { self_key_ensure_init(); void *ptr = qthread_getspecific(opal_thread_self_key); - return (aligned_t *)ptr; + return (aligned_t *) ptr; } static aligned_t opal_thread_qthreads_wrapper(void *arg) { - opal_thread_t *t = (opal_thread_t *)arg; + opal_thread_t *t = (opal_thread_t *) arg; /* Register itself. */ self_key_ensure_init(); qthread_setspecific(opal_thread_self_key, t->t_thread_ret_ptr); - t->t_ret = ((void *(*)(void *))t->t_run)(t); + t->t_ret = ((void *(*) (void *) ) t->t_run)(t); return 0; } diff --git a/opal/mca/threads/qthreads/threads_qthreads_mutex.c b/opal/mca/threads/qthreads/threads_qthreads_mutex.c index 5fce8ec3239..dfadc65a7b1 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_mutex.c +++ b/opal/mca/threads/qthreads/threads_qthreads_mutex.c @@ -25,8 +25,8 @@ #include "opal_config.h" -#include "opal/mca/threads/mutex.h" #include "opal/constants.h" +#include "opal/mca/threads/mutex.h" /* * Wait and see if some upper layer wants to use threads, if support @@ -44,18 +44,13 @@ static void opal_mutex_destruct(opal_mutex_t *m) { } -OBJ_CLASS_INSTANCE(opal_mutex_t, - opal_object_t, - opal_mutex_construct, - opal_mutex_destruct); +OBJ_CLASS_INSTANCE(opal_mutex_t, opal_object_t, opal_mutex_construct, opal_mutex_destruct); static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m) { } -OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, - opal_object_t, - opal_recursive_mutex_construct, +OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, opal_object_t, opal_recursive_mutex_construct, opal_mutex_destruct); int opal_cond_init(opal_cond_t *cond) @@ -77,13 +72,13 @@ int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) /* This thread is taking "lock", so only this thread can access this * condition variable. */ opal_atomic_lock(&cond->m_lock); - cond_waiter_t waiter = { 0, NULL }; + cond_waiter_t waiter = {0, NULL}; if (NULL == cond->m_waiter_head) { - cond->m_waiter_tail = (void *)&waiter; + cond->m_waiter_tail = (void *) &waiter; } else { - ((cond_waiter_t *)cond->m_waiter_head)->m_prev = (void *)&waiter; + ((cond_waiter_t *) cond->m_waiter_head)->m_prev = (void *) &waiter; } - cond->m_waiter_head = (void *)&waiter; + cond->m_waiter_head = (void *) &waiter; opal_atomic_unlock(&cond->m_lock); while (1) { @@ -106,7 +101,7 @@ int opal_cond_broadcast(opal_cond_t *cond) { opal_atomic_lock(&cond->m_lock); while (NULL != cond->m_waiter_tail) { - cond_waiter_t *p_cur_tail = (cond_waiter_t *)cond->m_waiter_tail; + cond_waiter_t *p_cur_tail = (cond_waiter_t *) cond->m_waiter_tail; cond->m_waiter_tail = p_cur_tail->m_prev; /* Awaken one of threads in a FIFO manner. */ p_cur_tail->m_signaled = 1; @@ -121,7 +116,7 @@ int opal_cond_signal(opal_cond_t *cond) { opal_atomic_lock(&cond->m_lock); if (NULL != cond->m_waiter_tail) { - cond_waiter_t *p_cur_tail = (cond_waiter_t *)cond->m_waiter_tail; + cond_waiter_t *p_cur_tail = (cond_waiter_t *) cond->m_waiter_tail; cond->m_waiter_tail = p_cur_tail->m_prev; /* Awaken one of threads. */ p_cur_tail->m_signaled = 1; diff --git a/opal/mca/threads/qthreads/threads_qthreads_mutex.h b/opal/mca/threads/qthreads/threads_qthreads_mutex.h index 7571d616362..074a1bec955 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_mutex.h +++ b/opal/mca/threads/qthreads/threads_qthreads_mutex.h @@ -34,9 +34,9 @@ #include #include -#include "opal/mca/threads/qthreads/threads_qthreads.h" -#include "opal/constants.h" #include "opal/class/opal_object.h" +#include "opal/constants.h" +#include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/sys/atomic.h" #include "opal/util/output.h" @@ -61,45 +61,33 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); #if OPAL_ENABLE_DEBUG -#define OPAL_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock = OPAL_ATOMIC_LOCK_INIT, \ - .m_recursive = 0, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock = OPAL_ATOMIC_LOCK_INIT, \ + .m_recursive = 0, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #else -#define OPAL_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock = OPAL_ATOMIC_LOCK_INIT, \ - .m_recursive = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock = OPAL_ATOMIC_LOCK_INIT, \ + .m_recursive = 0, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #endif #if OPAL_ENABLE_DEBUG -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock = OPAL_ATOMIC_LOCK_INIT, \ - .m_recursive = 1, \ - .m_lock_debug = 0, \ - .m_lock_file = NULL, \ - .m_lock_line = 0, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock = OPAL_ATOMIC_LOCK_INIT, \ + .m_recursive = 1, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \ + .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #else -#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ - { \ - .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \ - .m_lock = OPAL_ATOMIC_LOCK_INIT, \ - .m_recursive = 1, \ - .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ - } +# define OPAL_RECURSIVE_MUTEX_STATIC_INIT \ + { \ + .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock = OPAL_ATOMIC_LOCK_INIT, \ + .m_recursive = 1, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \ + } #endif /************************************************************************ @@ -206,11 +194,9 @@ typedef struct opal_cond_t { void *m_waiter_tail; } opal_cond_t; -#define OPAL_CONDITION_STATIC_INIT \ - { \ - .m_lock = OPAL_ATOMIC_LOCK_INIT, \ - .m_waiter_head = NULL, \ - .m_waiter_tail = NULL, \ +#define OPAL_CONDITION_STATIC_INIT \ + { \ + .m_lock = OPAL_ATOMIC_LOCK_INIT, .m_waiter_head = NULL, .m_waiter_tail = NULL, \ } int opal_cond_init(opal_cond_t *cond); diff --git a/opal/mca/threads/qthreads/threads_qthreads_threads.h b/opal/mca/threads/qthreads/threads_qthreads_threads.h index c5eebe10fc8..1969c558c3d 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_threads.h +++ b/opal/mca/threads/qthreads/threads_qthreads_threads.h @@ -26,8 +26,8 @@ #ifndef OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_THREADS_H #define OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_THREADS_H 1 -#include #include "opal/mca/threads/qthreads/threads_qthreads.h" +#include struct opal_thread_t { opal_object_t super; @@ -41,8 +41,7 @@ struct opal_thread_t { /* Qthreads are cooperatively scheduled so yield when idle */ #define OPAL_THREAD_YIELD_WHEN_IDLE_DEFAULT true -static inline -void opal_thread_yield(void) +static inline void opal_thread_yield(void) { qthread_yield(); } diff --git a/opal/mca/threads/qthreads/threads_qthreads_tsd.h b/opal/mca/threads/qthreads/threads_qthreads_tsd.h index 0482ed366b5..b1e0d06f3bc 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_tsd.h +++ b/opal/mca/threads/qthreads/threads_qthreads_tsd.h @@ -23,7 +23,6 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_TSD_H #define OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_TSD_H 1 diff --git a/opal/mca/threads/qthreads/threads_qthreads_wait_sync.c b/opal/mca/threads/qthreads/threads_qthreads_wait_sync.c index fc350263661..cbdc56c174f 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_wait_sync.c +++ b/opal/mca/threads/qthreads/threads_qthreads_wait_sync.c @@ -23,11 +23,11 @@ static ompi_wait_sync_t *wait_sync_list = NULL; static opal_atomic_int32_t num_thread_in_progress = 0; -#define WAIT_SYNC_PASS_OWNERSHIP(who) \ - do { \ - opal_mutex_lock(&(who)->lock); \ - opal_cond_signal(&(who)->condition); \ - opal_mutex_unlock(&(who)->lock); \ +#define WAIT_SYNC_PASS_OWNERSHIP(who) \ + do { \ + opal_mutex_lock(&(who)->lock); \ + opal_cond_signal(&(who)->condition); \ + opal_mutex_unlock(&(who)->lock); \ } while (0) int ompi_sync_wait_mt(ompi_wait_sync_t *sync) @@ -70,9 +70,8 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if (sync != wait_sync_list && - num_thread_in_progress >= opal_max_thread_in_progress) { +check_status: + if (sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { opal_cond_wait(&sync->condition, &sync->lock); /** @@ -98,7 +97,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: +i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; diff --git a/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h b/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h index 3e4b9d12874..7f6f6b5dd83 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h +++ b/opal/mca/threads/qthreads/threads_qthreads_wait_sync.h @@ -23,12 +23,11 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_WAIT_SYNC_H #define OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_WAIT_SYNC_H 1 -#include "opal/mca/threads/qthreads/threads_qthreads.h" #include "opal/mca/threads/mutex.h" +#include "opal/mca/threads/qthreads/threads_qthreads.h" typedef struct ompi_wait_sync_t { opal_atomic_int32_t count; @@ -40,8 +39,7 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) \ - (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) +#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -51,31 +49,31 @@ typedef struct ompi_wait_sync_t { * as possible. Note that the race window is small so spinning here * is more optimal than sleeping since this macro is called in * the critical path. */ -#define WAIT_SYNC_RELEASE(sync) \ - if (opal_using_threads()) { \ - while ((sync)->signaling) { \ - qthread_yield(); \ - continue; \ - } \ - opal_cond_destroy(&(sync)->condition); \ +#define WAIT_SYNC_RELEASE(sync) \ + if (opal_using_threads()) { \ + while ((sync)->signaling) { \ + qthread_yield(); \ + continue; \ + } \ + opal_cond_destroy(&(sync)->condition); \ } -#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ - if (opal_using_threads()) { \ - opal_cond_destroy(&(sync)->condition); \ +#define WAIT_SYNC_RELEASE_NOWAIT(sync) \ + if (opal_using_threads()) { \ + opal_cond_destroy(&(sync)->condition); \ } -#define WAIT_SYNC_SIGNAL(sync) \ - if (opal_using_threads()) { \ - opal_mutex_lock(&(sync)->lock); \ - opal_cond_signal(&(sync)->condition); \ - opal_mutex_unlock(&(sync)->lock); \ - (sync)->signaling = false; \ +#define WAIT_SYNC_SIGNAL(sync) \ + if (opal_using_threads()) { \ + opal_mutex_lock(&(sync)->lock); \ + opal_cond_signal(&(sync)->condition); \ + opal_mutex_unlock(&(sync)->lock); \ + (sync)->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync) \ - { \ - (sync)->signaling = false; \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ + (sync)->signaling = false; \ } OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); @@ -88,19 +86,17 @@ static inline int sync_wait_st(ompi_wait_sync_t *sync) return sync->status; } - -#define WAIT_SYNC_INIT(sync,c) \ - do { \ - (sync)->count = (c); \ - (sync)->next = NULL; \ - (sync)->prev = NULL; \ - (sync)->status = 0; \ - (sync)->signaling = (0 != (c)); \ - if (opal_using_threads()) { \ - opal_cond_init(&(sync)->condition); \ - opal_mutex_create(&(sync)->lock); \ - } \ +#define WAIT_SYNC_INIT(sync, c) \ + do { \ + (sync)->count = (c); \ + (sync)->next = NULL; \ + (sync)->prev = NULL; \ + (sync)->status = 0; \ + (sync)->signaling = (0 != (c)); \ + if (opal_using_threads()) { \ + opal_cond_init(&(sync)->condition); \ + opal_mutex_create(&(sync)->lock); \ + } \ } while (0) - #endif /* OPAL_MCA_THREADS_QTHREADS_THREADS_QTHREADS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/thread.h b/opal/mca/threads/thread.h index 9be62eddb96..1f2de84d128 100644 --- a/opal/mca/threads/thread.h +++ b/opal/mca/threads/thread.h @@ -21,15 +21,13 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_THREAD_H #define OPAL_MCA_THREADS_THREAD_H #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" - +#include "opal/mca/mca.h" /** * Structure for threads components. @@ -43,13 +41,11 @@ struct opal_threads_base_component_1_0_0_t { /** * Convenience typedef */ -typedef struct opal_threads_base_component_1_0_0_t - opal_threads_base_component_1_0_0_t; +typedef struct opal_threads_base_component_1_0_0_t opal_threads_base_component_1_0_0_t; /* * Macro for use in components that are of type threads */ -#define OPAL_THREADS_BASE_VERSION_1_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("threads", 1, 0, 0) +#define OPAL_THREADS_BASE_VERSION_1_0_0 OPAL_MCA_BASE_VERSION_2_1_0("threads", 1, 0, 0) #endif /* OPAL_MCA_THREADS_THREAD_H */ diff --git a/opal/mca/threads/thread_usage.h b/opal/mca/threads/thread_usage.h index 34a8c9f717f..e340e2a19a5 100644 --- a/opal/mca/threads/thread_usage.h +++ b/opal/mca/threads/thread_usage.h @@ -29,8 +29,8 @@ #include "opal_config.h" -#include "opal/sys/atomic.h" #include "opal/prefetch.h" +#include "opal/sys/atomic.h" OPAL_DECLSPEC extern bool opal_uses_threads; @@ -89,69 +89,64 @@ static inline bool opal_set_using_threads(bool have) return opal_using_threads(); } - /** * Use an atomic operation for increment/decrement if opal_using_threads() * indicates that threads are in use by the application or library. */ -#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ -static inline type opal_thread_ ## name ## _fetch_ ## suffix \ - (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ - } \ - \ - *addr = *addr operator delta; \ - return *addr; \ -} \ - \ -static inline type opal_thread_fetch_ ## name ## _ ## suffix \ - (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ - } \ - \ - type old = *addr; \ - *addr = old operator delta; \ - return old; \ -} - -#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ -static inline bool opal_thread_compare_exchange_strong_ ## suffix \ - (opal_atomic_ ## addr_type *addr, type *compare, type value) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_compare_exchange_strong_ ## suffix \ - (addr, (addr_type *)compare, (addr_type)value); \ - } \ - \ - if ((type) *addr == *compare) { \ - ((type *)addr)[0] = value; \ - return true; \ - } \ - \ - *compare = ((type *)addr)[0]; \ - \ - return false; \ -} - -#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ -static inline type opal_thread_swap_ ## suffix \ - (opal_atomic_ ## addr_type *ptr, type newvalue) \ -{ \ - if (opal_using_threads ()) { \ - return (type) opal_atomic_swap_ ## suffix \ - (ptr, (addr_type) newvalue); \ - } \ - \ - type old = ((type *)ptr)[0]; \ - ((type *)ptr)[0] = newvalue; \ - \ - return old; \ -} +#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ + static inline type opal_thread_##name##_fetch_##suffix(opal_atomic_##type *addr, type delta) \ + { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_##name##_fetch_##suffix(addr, delta); \ + } \ + \ + *addr = *addr operator delta; \ + return *addr; \ + } \ + \ + static inline type opal_thread_fetch_##name##_##suffix(opal_atomic_##type *addr, type delta) \ + { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_fetch_##name##_##suffix(addr, delta); \ + } \ + \ + type old = *addr; \ + *addr = old operator delta; \ + return old; \ + } + +#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ + static inline bool opal_thread_compare_exchange_strong_##suffix(opal_atomic_##addr_type *addr, \ + type *compare, type value) \ + { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_compare_exchange_strong_##suffix(addr, (addr_type *) compare, \ + (addr_type) value); \ + } \ + \ + if ((type) *addr == *compare) { \ + ((type *) addr)[0] = value; \ + return true; \ + } \ + \ + *compare = ((type *) addr)[0]; \ + \ + return false; \ + } + +#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ + static inline type opal_thread_swap_##suffix(opal_atomic_##addr_type *ptr, type newvalue) \ + { \ + if (opal_using_threads()) { \ + return (type) opal_atomic_swap_##suffix(ptr, (addr_type) newvalue); \ + } \ + \ + type old = ((type *) ptr)[0]; \ + ((type *) ptr)[0] = newvalue; \ + \ + return old; \ + } OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, add, +, 32) OPAL_THREAD_DEFINE_ATOMIC_OP(size_t, add, +, size_t) @@ -202,23 +197,19 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(intptr_t, intptr_t, ptr) #define OPAL_THREAD_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t #define OPAL_ATOMIC_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 \ - opal_thread_compare_exchange_strong_32 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 \ - opal_thread_compare_exchange_strong_32 +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) \ - opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, \ - (intptr_t *) y, (intptr_t) z) -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR \ - OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) \ + opal_thread_compare_exchange_strong_ptr((opal_atomic_intptr_t *) x, (intptr_t *) y, \ + (intptr_t) z) +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR #define OPAL_THREAD_SWAP_32 opal_thread_swap_32 #define OPAL_ATOMIC_SWAP_32 opal_thread_swap_32 -#define OPAL_THREAD_SWAP_PTR(x, y) \ - opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) -#define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR +#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr((opal_atomic_intptr_t *) x, (intptr_t) y) +#define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR /* define 64-bit macros is 64-bit atomic math is available */ #if OPAL_HAVE_ATOMIC_MATH_64 @@ -231,52 +222,50 @@ OPAL_THREAD_DEFINE_ATOMIC_OP(int64_t, sub, -, 64) OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(int64_t, int64_t, 64) OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) -#define OPAL_THREAD_ADD_FETCH64 opal_thread_add_fetch_64 -#define OPAL_ATOMIC_ADD_FETCH64 opal_thread_add_fetch_64 +# define OPAL_THREAD_ADD_FETCH64 opal_thread_add_fetch_64 +# define OPAL_ATOMIC_ADD_FETCH64 opal_thread_add_fetch_64 -#define OPAL_THREAD_AND_FETCH64 opal_thread_and_fetch_64 -#define OPAL_ATOMIC_AND_FETCH64 opal_thread_and_fetch_64 +# define OPAL_THREAD_AND_FETCH64 opal_thread_and_fetch_64 +# define OPAL_ATOMIC_AND_FETCH64 opal_thread_and_fetch_64 -#define OPAL_THREAD_OR_FETCH64 opal_thread_or_fetch_64 -#define OPAL_ATOMIC_OR_FETCH64 opal_thread_or_fetch_64 +# define OPAL_THREAD_OR_FETCH64 opal_thread_or_fetch_64 +# define OPAL_ATOMIC_OR_FETCH64 opal_thread_or_fetch_64 -#define OPAL_THREAD_XOR_FETCH64 opal_thread_xor_fetch_64 -#define OPAL_ATOMIC_XOR_FETCH64 opal_thread_xor_fetch_64 +# define OPAL_THREAD_XOR_FETCH64 opal_thread_xor_fetch_64 +# define OPAL_ATOMIC_XOR_FETCH64 opal_thread_xor_fetch_64 -#define OPAL_THREAD_FETCH_ADD64 opal_thread_fetch_add_64 -#define OPAL_ATOMIC_FETCH_ADD64 opal_thread_fetch_add_64 +# define OPAL_THREAD_FETCH_ADD64 opal_thread_fetch_add_64 +# define OPAL_ATOMIC_FETCH_ADD64 opal_thread_fetch_add_64 -#define OPAL_THREAD_FETCH_AND64 opal_thread_fetch_and_64 -#define OPAL_ATOMIC_FETCH_AND64 opal_thread_fetch_and_64 +# define OPAL_THREAD_FETCH_AND64 opal_thread_fetch_and_64 +# define OPAL_ATOMIC_FETCH_AND64 opal_thread_fetch_and_64 -#define OPAL_THREAD_FETCH_OR64 opal_thread_fetch_or_64 -#define OPAL_ATOMIC_FETCH_OR64 opal_thread_fetch_or_64 +# define OPAL_THREAD_FETCH_OR64 opal_thread_fetch_or_64 +# define OPAL_ATOMIC_FETCH_OR64 opal_thread_fetch_or_64 -#define OPAL_THREAD_FETCH_XOR64 opal_thread_fetch_xor_64 -#define OPAL_ATOMIC_FETCH_XOR64 opal_thread_fetch_xor_64 +# define OPAL_THREAD_FETCH_XOR64 opal_thread_fetch_xor_64 +# define OPAL_ATOMIC_FETCH_XOR64 opal_thread_fetch_xor_64 -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 \ - opal_thread_compare_exchange_strong_64 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 \ - opal_thread_compare_exchange_strong_64 +# define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 +# define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 -#define OPAL_THREAD_SWAP_64 opal_thread_swap_64 -#define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 +# define OPAL_THREAD_SWAP_64 opal_thread_swap_64 +# define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 #endif /* thread local storage */ #if OPAL_C_HAVE__THREAD_LOCAL -#define opal_thread_local _Thread_local -#define OPAL_HAVE_THREAD_LOCAL 1 +# define opal_thread_local _Thread_local +# define OPAL_HAVE_THREAD_LOCAL 1 #elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */ -#define opal_thread_local __thread -#define OPAL_HAVE_THREAD_LOCAL 1 +# define opal_thread_local __thread +# define OPAL_HAVE_THREAD_LOCAL 1 #endif /* OPAL_C_HAVE___THREAD */ #if !defined(OPAL_HAVE_THREAD_LOCAL) -#define OPAL_HAVE_THREAD_LOCAL 0 +# define OPAL_HAVE_THREAD_LOCAL 0 #endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */ #endif /* OPAL_MCA_THREADS_THREAD_USAGE_H */ diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h index 7d51a9c6a12..7e168380666 100644 --- a/opal/mca/threads/threads.h +++ b/opal/mca/threads/threads.h @@ -31,17 +31,17 @@ #include "opal/class/opal_object.h" #if OPAL_ENABLE_DEBUG -#include "opal/util/output.h" +# include "opal/util/output.h" #endif -#include "mutex.h" #include "condition.h" +#include "mutex.h" BEGIN_C_DECLS typedef void *(*opal_thread_fn_t)(opal_object_t *); -#define OPAL_THREAD_CANCELLED ((void *)1); +#define OPAL_THREAD_CANCELLED ((void *) 1); #include MCA_threads_base_include_HEADER @@ -53,63 +53,57 @@ OBJ_CLASS_DECLARATION(opal_thread_t); OPAL_DECLSPEC extern bool opal_debug_threads; #endif - OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); #if OPAL_ENABLE_DEBUG -#define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ - do { \ - OPAL_THREAD_LOCK((lck)); \ - if (opal_debug_threads) { \ - opal_output(0, "Waiting for thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - while (*(act)) { \ - opal_condition_wait((cnd), (lck)); \ - } \ - if (opal_debug_threads) { \ - opal_output(0, "Thread obtained %s:%d", \ - __FILE__, __LINE__); \ - } \ - *(act) = true; \ - } while (0); +# define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ + do { \ + OPAL_THREAD_LOCK((lck)); \ + if (opal_debug_threads) { \ + opal_output(0, "Waiting for thread %s:%d", __FILE__, __LINE__); \ + } \ + while (*(act)) { \ + opal_condition_wait((cnd), (lck)); \ + } \ + if (opal_debug_threads) { \ + opal_output(0, "Thread obtained %s:%d", __FILE__, __LINE__); \ + } \ + *(act) = true; \ + } while (0); #else -#define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ - do { \ - OPAL_THREAD_LOCK((lck)); \ - while (*(act)) { \ - opal_condition_wait((cnd), (lck)); \ - } \ - *(act) = true; \ - } while (0); +# define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ + do { \ + OPAL_THREAD_LOCK((lck)); \ + while (*(act)) { \ + opal_condition_wait((cnd), (lck)); \ + } \ + *(act) = true; \ + } while (0); #endif - #if OPAL_ENABLE_DEBUG -#define OPAL_RELEASE_THREAD(lck, cnd, act) \ - do { \ - if (opal_debug_threads) { \ - opal_output(0, "Releasing thread %s:%d", \ - __FILE__, __LINE__); \ - } \ - *(act) = false; \ - opal_condition_broadcast((cnd)); \ - OPAL_THREAD_UNLOCK((lck)); \ - } while (0); +# define OPAL_RELEASE_THREAD(lck, cnd, act) \ + do { \ + if (opal_debug_threads) { \ + opal_output(0, "Releasing thread %s:%d", __FILE__, __LINE__); \ + } \ + *(act) = false; \ + opal_condition_broadcast((cnd)); \ + OPAL_THREAD_UNLOCK((lck)); \ + } while (0); #else -#define OPAL_RELEASE_THREAD(lck, cnd, act) \ - do { \ - *(act) = false; \ - opal_condition_broadcast((cnd)); \ - OPAL_THREAD_UNLOCK((lck)); \ - } while (0); +# define OPAL_RELEASE_THREAD(lck, cnd, act) \ + do { \ + *(act) = false; \ + opal_condition_broadcast((cnd)); \ + OPAL_THREAD_UNLOCK((lck)); \ + } while (0); #endif - -#define OPAL_WAKEUP_THREAD(cnd, act) \ - do { \ - *(act) = false; \ - opal_condition_broadcast((cnd)); \ +#define OPAL_WAKEUP_THREAD(cnd, act) \ + do { \ + *(act) = false; \ + opal_condition_broadcast((cnd)); \ } while (0); /* provide a macro for forward-proofing the shifting @@ -118,16 +112,14 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); /* post an object to another thread - for now, we * only have a memory barrier */ -#define OPAL_POST_OBJECT(o) opal_atomic_wmb() +#define OPAL_POST_OBJECT(o) opal_atomic_wmb() /* acquire an object from another thread - for now, * we only have a memory barrier */ -#define OPAL_ACQUIRE_OBJECT(o) opal_atomic_rmb() - - +#define OPAL_ACQUIRE_OBJECT(o) opal_atomic_rmb() -OPAL_DECLSPEC int opal_thread_start(opal_thread_t *); -OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return); +OPAL_DECLSPEC int opal_thread_start(opal_thread_t *); +OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return); OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t *); OPAL_DECLSPEC opal_thread_t *opal_thread_get_self(void); OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig); diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index 658bfe9424c..837665a0ee2 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -14,7 +14,6 @@ * $HEADER$ */ - #ifndef OPAL_MCA_THREADS_TSD_H #define OPAL_MCA_THREADS_TSD_H @@ -22,9 +21,9 @@ #include -#include "opal/constants.h" -#include "opal/class/opal_list.h" #include "mutex.h" +#include "opal/class/opal_list.h" +#include "opal/constants.h" BEGIN_C_DECLS @@ -36,7 +35,6 @@ BEGIN_C_DECLS * Functions for providing thread-specific datastore capabilities. */ - /** * Prototype for callback when tsd data is being destroyed */ @@ -69,7 +67,6 @@ typedef void *opal_tsd_key_t; */ OPAL_DECLSPEC int opal_tsd_key_delete(opal_tsd_key_t key); - /** * Set a thread-specific data value * @@ -89,7 +86,6 @@ OPAL_DECLSPEC int opal_tsd_key_delete(opal_tsd_key_t key); */ OPAL_DECLSPEC int opal_tsd_setspecific(opal_tsd_key_t key, void *value); - /** * Get a thread-specific data value * @@ -109,7 +105,7 @@ OPAL_DECLSPEC int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep); #else -#include MCA_threads_tsd_base_include_HEADER +# include MCA_threads_tsd_base_include_HEADER #endif @@ -136,11 +132,11 @@ void opal_tsd_tracked_key_destructor(opal_tsd_tracked_key_t *key); static inline int opal_tsd_tracked_key_get(opal_tsd_tracked_key_t *key, void **p) { - assert( NULL != key); + assert(NULL != key); *p = NULL; opal_tsd_list_item_t *tsd = NULL; - opal_tsd_get(key->key, (void **)&tsd); + opal_tsd_get(key->key, (void **) &tsd); if (NULL != tsd) { *p = tsd->data; } @@ -149,8 +145,8 @@ static inline int opal_tsd_tracked_key_get(opal_tsd_tracked_key_t *key, void **p } OPAL_DECLSPEC int opal_tsd_tracked_key_set(opal_tsd_tracked_key_t *key, void *p); -OPAL_DECLSPEC void opal_tsd_tracked_key_set_destructor( - opal_tsd_tracked_key_t *key, opal_tsd_destructor_t destructor); +OPAL_DECLSPEC void opal_tsd_tracked_key_set_destructor(opal_tsd_tracked_key_t *key, + opal_tsd_destructor_t destructor); /** * Create thread-specific data key @@ -177,8 +173,7 @@ OPAL_DECLSPEC void opal_tsd_tracked_key_set_destructor( * @retval OPAL_ERR Error * @retval OPAL_ERR_IN_ERRNO Error */ -OPAL_DECLSPEC int opal_tsd_key_create(opal_tsd_key_t *key, - opal_tsd_destructor_t destructor); +OPAL_DECLSPEC int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor); END_C_DECLS diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 9291a4b2e77..611d37c7628 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -21,8 +21,8 @@ #ifndef OPAL_MCA_THREADS_WAIT_SYNC_H #define OPAL_MCA_THREADS_WAIT_SYNC_H -#include "opal/sys/atomic.h" #include "opal/mca/threads/condition.h" +#include "opal/sys/atomic.h" BEGIN_C_DECLS @@ -36,8 +36,7 @@ extern int opal_max_thread_in_progress; * triggered. The status of the synchronization will be reported to * the waiting threads. */ -static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, - int status) +static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status) { if (OPAL_LIKELY(OPAL_SUCCESS == status)) { if (0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates))) { diff --git a/opal/mca/timer/altix/timer_altix.h b/opal/mca/timer/altix/timer_altix.h index b0161bd5c98..56b65e554fa 100644 --- a/opal/mca/timer/altix/timer_altix.h +++ b/opal/mca/timer/altix/timer_altix.h @@ -25,30 +25,24 @@ extern opal_timer_t opal_timer_altix_freq; extern opal_timer_t opal_timer_altix_usec_conv; extern volatile unsigned long *opal_timer_altix_mmdev_timer_addr; -static inline opal_timer_t -opal_timer_base_get_cycles(void) +static inline opal_timer_t opal_timer_base_get_cycles(void) { return (*opal_timer_altix_mmdev_timer_addr); } - -static inline opal_timer_t -opal_timer_base_get_usec(void) +static inline opal_timer_t opal_timer_base_get_usec(void) { return opal_timer_base_get_cycles() / opal_timer_altix_usec_conv; } - -static inline opal_timer_t -opal_timer_base_get_freq(void) +static inline opal_timer_t opal_timer_base_get_freq(void) { return opal_timer_altix_freq; } - -#define OPAL_TIMER_CYCLE_NATIVE 1 +#define OPAL_TIMER_CYCLE_NATIVE 1 #define OPAL_TIMER_CYCLE_SUPPORTED 1 -#define OPAL_TIMER_USEC_NATIVE 0 -#define OPAL_TIMER_USEC_SUPPORTED 1 +#define OPAL_TIMER_USEC_NATIVE 0 +#define OPAL_TIMER_USEC_SUPPORTED 1 #endif diff --git a/opal/mca/timer/altix/timer_altix_component.c b/opal/mca/timer/altix/timer_altix_component.c index 3f9c66a38ff..9e6a7f25230 100644 --- a/opal/mca/timer/altix/timer_altix_component.c +++ b/opal/mca/timer/altix/timer_altix_component.c @@ -23,18 +23,18 @@ #include "opal_config.h" -#include -#include +#include #include +#include #include #include -#include +#include +#include #include -#include -#include "opal/mca/timer/timer.h" -#include "opal/mca/timer/altix/timer_altix.h" #include "opal/constants.h" +#include "opal/mca/timer/altix/timer_altix.h" +#include "opal/mca/timer/timer.h" #include "opal/util/sys_limits.h" opal_timer_t opal_timer_altix_freq; @@ -48,64 +48,65 @@ static int opal_timer_altix_close(void); const opal_timer_base_component_2_0_0_t mca_timer_altix_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .timerc_version = { - OPAL_TIMER_BASE_VERSION_2_0_0, - - /* Component name and version */ - .mca_component_name = "altix", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - /* Component open and close functions */ - .mca_open_component = opal_timer_altix_open, - .mca_close_component = opal_timer_altix_close, - }, - .timerc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .timerc_version = + { + OPAL_TIMER_BASE_VERSION_2_0_0, + + /* Component name and version */ + .mca_component_name = "altix", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + /* Component open and close functions */ + .mca_open_component = opal_timer_altix_open, + .mca_close_component = opal_timer_altix_close, + }, + .timerc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; - -static int -opal_timer_altix_open(void) +static int opal_timer_altix_open(void) { int fd, ret; unsigned long val; long offset; fd = open(MMTIMER_FULLNAME, O_RDONLY); - if (fd < 0) return OPAL_ERR_NOT_FOUND; + if (fd < 0) + return OPAL_ERR_NOT_FOUND; /* make sure we can map the timer */ ret = ioctl(fd, MMTIMER_MMAPAVAIL, 0); - if (1 != ret) return OPAL_ERR_NOT_SUPPORTED; + if (1 != ret) + return OPAL_ERR_NOT_SUPPORTED; /* find the frequency */ ret = ioctl(fd, MMTIMER_GETFREQ, &val); - if (ret == -ENOSYS) return OPAL_ERR_NOT_SUPPORTED; + if (ret == -ENOSYS) + return OPAL_ERR_NOT_SUPPORTED; opal_timer_altix_freq = val; opal_timer_altix_usec_conv = opal_timer_altix_freq / 1000000; /* find the address of the counter */ ret = ioctl(fd, MMTIMER_GETOFFSET, 0); - if (ret == -ENOSYS) return OPAL_ERR_NOT_SUPPORTED; + if (ret == -ENOSYS) + return OPAL_ERR_NOT_SUPPORTED; offset = ret; - mmdev_map = mmap(0, (size_t)opal_getpagesize(), PROT_READ, MAP_SHARED, fd, 0); - if (NULL == mmdev_map) return OPAL_ERR_NOT_SUPPORTED; + mmdev_map = mmap(0, (size_t) opal_getpagesize(), PROT_READ, MAP_SHARED, fd, 0); + if (NULL == mmdev_map) + return OPAL_ERR_NOT_SUPPORTED; opal_timer_altix_mmdev_timer_addr = mmdev_map + offset; close(fd); return OPAL_SUCCESS; } - -static int -opal_timer_altix_close(void) +static int opal_timer_altix_close(void) { if (NULL != mmdev_map) { - munmap(mmdev_map, (size_t)opal_getpagesize()); + munmap(mmdev_map, (size_t) opal_getpagesize()); } return OPAL_SUCCESS; diff --git a/opal/mca/timer/base/base.h b/opal/mca/timer/base/base.h index df1a0c3a131..189e9b0b2d2 100644 --- a/opal/mca/timer/base/base.h +++ b/opal/mca/timer/base/base.h @@ -25,7 +25,6 @@ #include "opal/mca/base/mca_base_framework.h" #include "opal/mca/timer/timer.h" - /* * Global functions for MCA overall timer open and close */ diff --git a/opal/mca/timer/base/timer_base_null.h b/opal/mca/timer/base/timer_base_null.h index 89be9ad0134..f90291c2863 100644 --- a/opal/mca/timer/base/timer_base_null.h +++ b/opal/mca/timer/base/timer_base_null.h @@ -21,30 +21,24 @@ typedef int opal_timer_t; -static inline opal_timer_t -opal_timer_base_get_cycles(void) +static inline opal_timer_t opal_timer_base_get_cycles(void) { return 0; } - -static inline opal_timer_t -opal_timer_base_get_usec(void) +static inline opal_timer_t opal_timer_base_get_usec(void) { return 0; } - -static inline opal_timer_t -opal_timer_base_get_freq(void) +static inline opal_timer_t opal_timer_base_get_freq(void) { return 0; } - -#define OPAL_TIMER_CYCLE_NATIVE 0 +#define OPAL_TIMER_CYCLE_NATIVE 0 #define OPAL_TIMER_CYCLE_SUPPORTED 0 -#define OPAL_TIMER_USEC_NATIVE 0 -#define OPAL_TIMER_USEC_SUPPORTED 0 +#define OPAL_TIMER_USEC_NATIVE 0 +#define OPAL_TIMER_USEC_SUPPORTED 0 #endif diff --git a/opal/mca/timer/base/timer_base_open.c b/opal/mca/timer/base/timer_base_open.c index 1777ff9d356..08663b1b873 100644 --- a/opal/mca/timer/base/timer_base_open.c +++ b/opal/mca/timer/base/timer_base_open.c @@ -17,7 +17,6 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" @@ -36,10 +35,8 @@ static int mca_timer_base_register(mca_base_register_flag_t flags) { (void) mca_base_var_register("opal", "timer", "require", "monotonic", "Node-level monotonic timer required (default yes)", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_LOCAL, - &mca_timer_base_monotonic); + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_LOCAL, &mca_timer_base_monotonic); return OPAL_SUCCESS; } diff --git a/opal/mca/timer/darwin/timer_darwin.h b/opal/mca/timer/darwin/timer_darwin.h index fe35f99d5e4..cd3f219d820 100644 --- a/opal/mca/timer/darwin/timer_darwin.h +++ b/opal/mca/timer/darwin/timer_darwin.h @@ -33,15 +33,14 @@ OPAL_DECLSPEC extern opal_timer_t opal_timer_darwin_bias; * Use the pragmatic solution proposed at * http://stackoverflow.com/questions/23378063/how-can-i-use-mach-absolute-time-without-overflowing/23378064#23378064 */ -static inline opal_timer_t -opal_timer_base_get_cycles(void) +static inline opal_timer_t opal_timer_base_get_cycles(void) { uint64_t now = mach_absolute_time(); - if( opal_timer_darwin_info.denom == 0 ) { - (void)mach_timebase_info(&opal_timer_darwin_info); - if( opal_timer_darwin_info.denom > 1024 ) { - double frac = (double)opal_timer_darwin_info.numer/opal_timer_darwin_info.denom; + if (opal_timer_darwin_info.denom == 0) { + (void) mach_timebase_info(&opal_timer_darwin_info); + if (opal_timer_darwin_info.denom > 1024) { + double frac = (double) opal_timer_darwin_info.numer / opal_timer_darwin_info.denom; opal_timer_darwin_info.denom = 1024; opal_timer_darwin_info.numer = opal_timer_darwin_info.denom * frac + 0.5; } @@ -49,28 +48,24 @@ opal_timer_base_get_cycles(void) } /* this is basically a wrapper around the "right" assembly to convert the tick counter off the PowerPC Time Base into nanos. */ - return (now - opal_timer_darwin_bias) * opal_timer_darwin_info.numer / opal_timer_darwin_info.denom; + return (now - opal_timer_darwin_bias) * opal_timer_darwin_info.numer + / opal_timer_darwin_info.denom; } - -static inline opal_timer_t -opal_timer_base_get_usec(void) +static inline opal_timer_t opal_timer_base_get_usec(void) { /* freq is in Hz, so this gives usec */ return opal_timer_base_get_cycles() / 1000; } - -static inline opal_timer_t -opal_timer_base_get_freq(void) +static inline opal_timer_t opal_timer_base_get_freq(void) { return opal_timer_darwin_freq; } - -#define OPAL_TIMER_CYCLE_NATIVE 0 +#define OPAL_TIMER_CYCLE_NATIVE 0 #define OPAL_TIMER_CYCLE_SUPPORTED 1 -#define OPAL_TIMER_USEC_NATIVE 1 -#define OPAL_TIMER_USEC_SUPPORTED 1 +#define OPAL_TIMER_USEC_NATIVE 1 +#define OPAL_TIMER_USEC_SUPPORTED 1 #endif diff --git a/opal/mca/timer/darwin/timer_darwin_component.c b/opal/mca/timer/darwin/timer_darwin_component.c index da134d2dcd6..c7784b27d6f 100644 --- a/opal/mca/timer/darwin/timer_darwin_component.c +++ b/opal/mca/timer/darwin/timer_darwin_component.c @@ -21,9 +21,9 @@ #include "opal_config.h" -#include "opal/mca/timer/timer.h" -#include "opal/mca/timer/darwin/timer_darwin.h" #include "opal/constants.h" +#include "opal/mca/timer/darwin/timer_darwin.h" +#include "opal/mca/timer/timer.h" opal_timer_t opal_timer_darwin_freq = {0}; mach_timebase_info_data_t opal_timer_darwin_info = {.denom = 0}; @@ -34,20 +34,20 @@ static int opal_timer_darwin_open(void); const opal_timer_base_component_2_0_0_t mca_timer_darwin_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .timerc_version = { - OPAL_TIMER_BASE_VERSION_2_0_0, + .timerc_version = + { + OPAL_TIMER_BASE_VERSION_2_0_0, - /* Component name and version */ - .mca_component_name = "darwin", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), + /* Component name and version */ + .mca_component_name = "darwin", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), - .mca_open_component = opal_timer_darwin_open, - }, - .timerc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .mca_open_component = opal_timer_darwin_open, + }, + .timerc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; /* mach_timebase_info() returns a fraction that can be multiplied @@ -89,9 +89,10 @@ const opal_timer_base_component_2_0_0_t mca_timer_darwin_component = { int opal_timer_darwin_open(void) { /* Call the opal_timer_base_get_cycles once to start the enging */ - (void)opal_timer_base_get_cycles(); + (void) opal_timer_base_get_cycles(); - opal_timer_darwin_freq = opal_timer_darwin_info.denom * (1000000000 / opal_timer_darwin_info.numer); + opal_timer_darwin_freq = opal_timer_darwin_info.denom + * (1000000000 / opal_timer_darwin_info.numer); return OPAL_SUCCESS; } diff --git a/opal/mca/timer/linux/timer_linux.h b/opal/mca/timer/linux/timer_linux.h index 96fea46ce16..4d0c12ec3cc 100644 --- a/opal/mca/timer/linux/timer_linux.h +++ b/opal/mca/timer/linux/timer_linux.h @@ -30,9 +30,9 @@ OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_usec)(void); OPAL_DECLSPEC extern opal_timer_t opal_timer_base_get_freq(void); -#define OPAL_TIMER_CYCLE_NATIVE OPAL_HAVE_SYS_TIMER_GET_CYCLES +#define OPAL_TIMER_CYCLE_NATIVE OPAL_HAVE_SYS_TIMER_GET_CYCLES #define OPAL_TIMER_CYCLE_SUPPORTED OPAL_HAVE_SYS_TIMER_GET_CYCLES -#define OPAL_TIMER_USEC_NATIVE OPAL_HAVE_SYS_TIMER_GET_CYCLES -#define OPAL_TIMER_USEC_SUPPORTED OPAL_HAVE_SYS_TIMER_GET_CYCLES +#define OPAL_TIMER_USEC_NATIVE OPAL_HAVE_SYS_TIMER_GET_CYCLES +#define OPAL_TIMER_USEC_SUPPORTED OPAL_HAVE_SYS_TIMER_GET_CYCLES #endif diff --git a/opal/mca/timer/linux/timer_linux_component.c b/opal/mca/timer/linux/timer_linux_component.c index a969dabc632..b710e54f0e8 100644 --- a/opal/mca/timer/linux/timer_linux_component.c +++ b/opal/mca/timer/linux/timer_linux_component.c @@ -28,10 +28,10 @@ #include #include -#include "opal/mca/timer/timer.h" +#include "opal/constants.h" #include "opal/mca/timer/base/base.h" #include "opal/mca/timer/linux/timer_linux.h" -#include "opal/constants.h" +#include "opal/mca/timer/timer.h" #include "opal/util/show_help.h" static opal_timer_t opal_timer_linux_get_cycles_sys_timer(void); @@ -44,16 +44,12 @@ static opal_timer_t opal_timer_linux_get_usec_sys_timer(void); static opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void); static opal_timer_t opal_timer_linux_get_usec_clock_gettime(void); -opal_timer_t (*opal_timer_base_get_cycles)(void) = - opal_timer_linux_get_cycles_clock_gettime; -opal_timer_t (*opal_timer_base_get_usec)(void) = - opal_timer_linux_get_usec_clock_gettime; +opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_linux_get_cycles_clock_gettime; +opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_linux_get_usec_clock_gettime; #else -opal_timer_t (*opal_timer_base_get_cycles)(void) = - opal_timer_linux_get_cycles_sys_timer; -opal_timer_t (*opal_timer_base_get_usec)(void) = - opal_timer_linux_get_usec_sys_timer; -#endif /* OPAL_HAVE_CLOCK_GETTIME */ +opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_linux_get_cycles_sys_timer; +opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_linux_get_usec_sys_timer; +#endif /* OPAL_HAVE_CLOCK_GETTIME */ static opal_timer_t opal_timer_linux_freq = {0}; @@ -62,25 +58,24 @@ static int opal_timer_linux_open(void); const opal_timer_base_component_2_0_0_t mca_timer_linux_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .timerc_version = { - OPAL_TIMER_BASE_VERSION_2_0_0, - - /* Component name and version */ - .mca_component_name = "linux", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - - /* Component open and close functions */ - .mca_open_component = opal_timer_linux_open, - }, - .timerc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + .timerc_version = + { + OPAL_TIMER_BASE_VERSION_2_0_0, + + /* Component name and version */ + .mca_component_name = "linux", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + + /* Component open and close functions */ + .mca_open_component = opal_timer_linux_open, + }, + .timerc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; -static char * -find_info(FILE* fp, char *str, char *buf, size_t buflen) +static char *find_info(FILE *fp, char *str, char *buf, size_t buflen) { char *tmp; @@ -89,11 +84,13 @@ find_info(FILE* fp, char *str, char *buf, size_t buflen) if (strncmp(buf, str, strlen(str)) == 0) { /* we found the line. Now eat everything up to, including, and one past the : */ - for (tmp = buf ; (*tmp != '\0') && (*tmp != ':') ; ++tmp) ; + for (tmp = buf; (*tmp != '\0') && (*tmp != ':'); ++tmp) + ; if (*tmp == '\0') { continue; } - for ( ++tmp ; *tmp == ' ' ; ++tmp); + for (++tmp; *tmp == ' '; ++tmp) + ; if ('\0' != *tmp) { return tmp; } @@ -144,7 +141,7 @@ static int opal_timer_linux_find_freq(void) if (1 == ret) { /* number is in MHz * 2 and has 2 decimal digits convert to Hz and make an integer */ - opal_timer_linux_freq = (opal_timer_t) (cpu_f * 100.0f) * 5000; + opal_timer_linux_freq = (opal_timer_t)(cpu_f * 100.0f) * 5000; } } } @@ -157,7 +154,7 @@ static int opal_timer_linux_find_freq(void) ret = sscanf(loc, "%f", &cpu_f); if (1 == ret) { /* numer is in MHz - convert to Hz and make an integer */ - opal_timer_linux_freq = (opal_timer_t) (cpu_f * 1000000); + opal_timer_linux_freq = (opal_timer_t)(cpu_f * 1000000); } } } @@ -187,10 +184,10 @@ int opal_timer_linux_open(void) { int ret = OPAL_SUCCESS; - if (mca_timer_base_monotonic && !opal_sys_timer_is_monotonic ()) { + if (mca_timer_base_monotonic && !opal_sys_timer_is_monotonic()) { #if OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) struct timespec res; - if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) { + if (0 == clock_getres(CLOCK_MONOTONIC, &res)) { opal_timer_linux_freq = 1.e3; opal_timer_base_get_cycles = opal_timer_linux_get_cycles_clock_gettime; opal_timer_base_get_usec = opal_timer_linux_get_usec_clock_gettime; @@ -199,7 +196,7 @@ int opal_timer_linux_open(void) #else /* Monotonic time requested but cannot be found. Complain! */ opal_show_help("help-opal-timer-linux.txt", "monotonic not supported", true); -#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */ +#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */ } ret = opal_timer_linux_find_freq(); opal_timer_base_get_cycles = opal_timer_linux_get_cycles_sys_timer; @@ -212,9 +209,9 @@ opal_timer_t opal_timer_linux_get_usec_clock_gettime(void) { struct timespec tp = {.tv_sec = 0, .tv_nsec = 0}; - (void) clock_gettime (CLOCK_MONOTONIC, &tp); + (void) clock_gettime(CLOCK_MONOTONIC, &tp); - return (tp.tv_sec * 1e6 + tp.tv_nsec/1000); + return (tp.tv_sec * 1e6 + tp.tv_nsec / 1000); } opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void) @@ -225,7 +222,7 @@ opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void) return (tp.tv_sec * 1e9 + tp.tv_nsec); } -#endif /* OPAL_HAVE_CLOCK_GETTIME */ +#endif /* OPAL_HAVE_CLOCK_GETTIME */ opal_timer_t opal_timer_linux_get_cycles_sys_timer(void) { @@ -236,12 +233,11 @@ opal_timer_t opal_timer_linux_get_cycles_sys_timer(void) #endif } - opal_timer_t opal_timer_linux_get_usec_sys_timer(void) { #if OPAL_HAVE_SYS_TIMER_GET_CYCLES /* freq is in MHz, so this gives usec */ - return opal_sys_timer_get_cycles() / opal_timer_linux_freq; + return opal_sys_timer_get_cycles() / opal_timer_linux_freq; #else return 0; #endif diff --git a/opal/mca/timer/solaris/timer_solaris.h b/opal/mca/timer/solaris/timer_solaris.h index e71cba92f73..a0c93d92bcf 100644 --- a/opal/mca/timer/solaris/timer_solaris.h +++ b/opal/mca/timer/solaris/timer_solaris.h @@ -23,30 +23,25 @@ typedef hrtime_t opal_timer_t; - -static inline opal_timer_t -opal_timer_base_get_cycles(void) +static inline opal_timer_t opal_timer_base_get_cycles(void) { return 0; } -static inline opal_timer_t -opal_timer_base_get_usec(void) +static inline opal_timer_t opal_timer_base_get_usec(void) { /* gethrtime returns nanoseconds */ return gethrtime() / 1000; } -static inline opal_timer_t -opal_timer_base_get_freq(void) +static inline opal_timer_t opal_timer_base_get_freq(void) { return 0; } - -#define OPAL_TIMER_CYCLE_NATIVE 0 +#define OPAL_TIMER_CYCLE_NATIVE 0 #define OPAL_TIMER_CYCLE_SUPPORTED 0 -#define OPAL_TIMER_USEC_NATIVE 1 -#define OPAL_TIMER_USEC_SUPPORTED 1 +#define OPAL_TIMER_USEC_NATIVE 1 +#define OPAL_TIMER_USEC_SUPPORTED 1 #endif diff --git a/opal/mca/timer/solaris/timer_solaris_component.c b/opal/mca/timer/solaris/timer_solaris_component.c index b29eec29f90..0e80a9ab709 100644 --- a/opal/mca/timer/solaris/timer_solaris_component.c +++ b/opal/mca/timer/solaris/timer_solaris_component.c @@ -21,23 +21,22 @@ #include "opal_config.h" -#include "opal/mca/timer/timer.h" #include "opal/mca/timer/solaris/timer_solaris.h" - +#include "opal/mca/timer/timer.h" const opal_timer_base_component_2_0_0_t mca_timer_solaris_component = { /* First, the mca_component_t struct containing meta information about the component itself */ - .timerc_version = { - OPAL_TIMER_BASE_VERSION_2_0_0, + .timerc_version = + { + OPAL_TIMER_BASE_VERSION_2_0_0, - /* Component name and version */ - .mca_component_name = "solaris", - MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION), - }, - .timerc_data = { - /* The component is checkpoint ready */ - MCA_BASE_METADATA_PARAM_CHECKPOINT - }, + /* Component name and version */ + .mca_component_name = "solaris", + MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION), + }, + .timerc_data = + {/* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT}, }; diff --git a/opal/mca/timer/timer.h b/opal/mca/timer/timer.h index cb645f61d8a..c284019f34d 100644 --- a/opal/mca/timer/timer.h +++ b/opal/mca/timer/timer.h @@ -69,9 +69,8 @@ #include "opal_config.h" -#include "opal/mca/mca.h" #include "opal/mca/base/base.h" - +#include "opal/mca/mca.h" /** * Structure for timer components. @@ -90,7 +89,6 @@ typedef struct opal_timer_base_component_2_0_0_t opal_timer_base_component_2_0_0 /* * Macro for use in components that are of type timer */ -#define OPAL_TIMER_BASE_VERSION_2_0_0 \ - OPAL_MCA_BASE_VERSION_2_1_0("timer", 2, 0, 0) +#define OPAL_TIMER_BASE_VERSION_2_0_0 OPAL_MCA_BASE_VERSION_2_1_0("timer", 2, 0, 0) #endif /* OPAL_MCA_TIMER_TIMER_H */ diff --git a/opal/memoryhooks/memory.c b/opal/memoryhooks/memory.c index 5504192d9b2..d7f322853db 100644 --- a/opal/memoryhooks/memory.c +++ b/opal/memoryhooks/memory.c @@ -22,19 +22,19 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ +# include +#endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_SYS_MMAN_H -#include -#endif /* HAVE_SYS_MMAN_H */ +# include +#endif /* HAVE_SYS_MMAN_H */ +#include "opal/class/opal_list.h" +#include "opal/class/opal_object.h" #include "opal/constants.h" #include "opal/memoryhooks/memory.h" #include "opal/memoryhooks/memory_internal.h" -#include "opal/class/opal_list.h" -#include "opal/class/opal_object.h" -#include "opal/sys/atomic.h" #include "opal/runtime/opal.h" +#include "opal/sys/atomic.h" /* * local types @@ -88,7 +88,7 @@ static void opal_mem_hooks_finalize(void) opal_atomic_unlock(&release_lock); } -int opal_mem_hooks_init (void) +int opal_mem_hooks_init(void) { OBJ_CONSTRUCT(&release_cb_list, opal_list_t); @@ -99,28 +99,25 @@ int opal_mem_hooks_init (void) release_run_callbacks = false; opal_atomic_mb(); - opal_finalize_register_cleanup (opal_mem_hooks_finalize); + opal_finalize_register_cleanup(opal_mem_hooks_finalize); return OPAL_SUCCESS; } - - /* called from memory manager / memory-manager specific hooks */ -void -opal_mem_hooks_set_support(int support) +void opal_mem_hooks_set_support(int support) { hooks_support = support; } - /* called from the memory manager / memory-manager specific hooks */ -void -opal_mem_hooks_release_hook(void *buf, size_t length, bool from_alloc) +void opal_mem_hooks_release_hook(void *buf, size_t length, bool from_alloc) { callback_list_item_t *cbitem, *next; - if (!release_run_callbacks) return; + if (!release_run_callbacks) { + return; + } /* * This is not really thread safe - but we can't hold the lock @@ -133,7 +130,7 @@ opal_mem_hooks_release_hook(void *buf, size_t length, bool from_alloc) */ opal_atomic_lock(&release_lock); - OPAL_LIST_FOREACH_SAFE(cbitem, next, &release_cb_list, callback_list_item_t) { + OPAL_LIST_FOREACH_SAFE (cbitem, next, &release_cb_list, callback_list_item_t) { opal_atomic_unlock(&release_lock); cbitem->cbfunc(buf, length, cbitem->cbdata, (bool) from_alloc); opal_atomic_lock(&release_lock); @@ -141,21 +138,17 @@ opal_mem_hooks_release_hook(void *buf, size_t length, bool from_alloc) opal_atomic_unlock(&release_lock); } - -int -opal_mem_hooks_support_level(void) +int opal_mem_hooks_support_level(void) { return hooks_support; } - -int -opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, void *cbdata) +int opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, void *cbdata) { callback_list_item_t *cbitem, *new_cbitem; int ret = OPAL_SUCCESS; - if (0 == ((OPAL_MEMORY_FREE_SUPPORT|OPAL_MEMORY_MUNMAP_SUPPORT) & hooks_support)) { + if (0 == ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) & hooks_support)) { return OPAL_ERR_NOT_SUPPORTED; } @@ -176,7 +169,7 @@ opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, void *cbdata opal_atomic_mb(); /* make sure the callback isn't already in the list */ - OPAL_LIST_FOREACH(cbitem, &release_cb_list, callback_list_item_t) { + OPAL_LIST_FOREACH (cbitem, &release_cb_list, callback_list_item_t) { if (cbitem->cbfunc == func) { ret = OPAL_EXISTS; goto done; @@ -186,9 +179,9 @@ opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, void *cbdata new_cbitem->cbfunc = func; new_cbitem->cbdata = cbdata; - opal_list_append(&release_cb_list, (opal_list_item_t*) new_cbitem); + opal_list_append(&release_cb_list, (opal_list_item_t *) new_cbitem); - done: +done: opal_atomic_unlock(&release_lock); if (OPAL_EXISTS == ret && NULL != new_cbitem) { @@ -198,9 +191,7 @@ opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, void *cbdata return ret; } - -int -opal_mem_hooks_unregister_release(opal_mem_hooks_callback_fn_t* func) +int opal_mem_hooks_unregister_release(opal_mem_hooks_callback_fn_t *func) { callback_list_item_t *cbitem, *found_item = NULL; int ret = OPAL_ERR_NOT_FOUND; @@ -208,7 +199,7 @@ opal_mem_hooks_unregister_release(opal_mem_hooks_callback_fn_t* func) opal_atomic_lock(&release_lock); /* make sure the callback isn't already in the list */ - OPAL_LIST_FOREACH(cbitem, &release_cb_list, callback_list_item_t) { + OPAL_LIST_FOREACH (cbitem, &release_cb_list, callback_list_item_t) { if (cbitem->cbfunc == func) { opal_list_remove_item(&release_cb_list, (opal_list_item_t *) cbitem); found_item = cbitem; diff --git a/opal/memoryhooks/memory.h b/opal/memoryhooks/memory.h index f5dda4f5322..be534580137 100644 --- a/opal/memoryhooks/memory.h +++ b/opal/memoryhooks/memory.h @@ -46,7 +46,6 @@ BEGIN_C_DECLS - /** * Initialize the memory hooks subsystem * @@ -62,7 +61,6 @@ BEGIN_C_DECLS */ OPAL_DECLSPEC int opal_mem_hooks_init(void); - /** * Query level of support provided by memory hooks * @@ -89,7 +87,6 @@ OPAL_DECLSPEC int opal_mem_hooks_init(void); */ OPAL_DECLSPEC int opal_mem_hooks_support_level(void); - /** * Memory status change callback * @@ -106,9 +103,7 @@ OPAL_DECLSPEC int opal_mem_hooks_support_level(void); * general allocation routines (malloc, calloc, free, * etc.) or directly from the user (mmap, munmap, etc.) */ -typedef void (opal_mem_hooks_callback_fn_t)(void *buf, size_t length, - void *cbdata, bool from_alloc); - +typedef void(opal_mem_hooks_callback_fn_t)(void *buf, size_t length, void *cbdata, bool from_alloc); /** * Register callback for when memory is to be released @@ -126,8 +121,7 @@ typedef void (opal_mem_hooks_callback_fn_t)(void *buf, size_t length, * @retval OPAL_ERR_NOT_SUPPORTED There are no hooks available for * receiving callbacks when memory is to be released */ -OPAL_DECLSPEC int opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, - void *cbdata); +OPAL_DECLSPEC int opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t *func, void *cbdata); /** * Unregister previously registered release callback @@ -141,7 +135,6 @@ OPAL_DECLSPEC int opal_mem_hooks_register_release(opal_mem_hooks_callback_fn_t * */ OPAL_DECLSPEC int opal_mem_hooks_unregister_release(opal_mem_hooks_callback_fn_t *func); - END_C_DECLS #endif /* OPAL_MEMORY_MEMORY_H */ diff --git a/opal/memoryhooks/memory_internal.h b/opal/memoryhooks/memory_internal.h index b812275cea7..56588303f1b 100644 --- a/opal/memoryhooks/memory_internal.h +++ b/opal/memoryhooks/memory_internal.h @@ -22,7 +22,7 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -# include +# include #endif /* see memory.h for meaning */ @@ -38,5 +38,4 @@ OPAL_DECLSPEC void opal_mem_hooks_release_hook(void *buf, size_t length, bool fr END_C_DECLS - #endif /* OPAL_MEMORY_MEMORY_INTERNAL_H */ diff --git a/opal/runtime/opal.h b/opal/runtime/opal.h index 437ea87e89a..5ccc2f6f1a0 100644 --- a/opal/runtime/opal.h +++ b/opal/runtime/opal.h @@ -28,8 +28,8 @@ #define OPAL_H #include "opal_config.h" -#include "opal/types.h" #include "opal/class/opal_list.h" +#include "opal/types.h" #include "opal/util/proc.h" #include @@ -65,7 +65,7 @@ extern opal_list_t opal_finalize_cleanup_fns; * \note If this function is called, opal_init_util() should *not* be * called. */ -OPAL_DECLSPEC int opal_init(int* pargc, char*** pargv); +OPAL_DECLSPEC int opal_init(int *pargc, char ***pargv); /** * Finalize the OPAL layer, including the MCA system. @@ -87,7 +87,7 @@ OPAL_DECLSPEC int opal_finalize(void); * \note If this function is called, opal_init() should *not* * be called. */ -OPAL_DECLSPEC int opal_init_util(int* pargc, char*** pargv); +OPAL_DECLSPEC int opal_init_util(int *pargc, char ***pargv); /** * Disable PSM/PSM2 signal hijacking. @@ -177,7 +177,7 @@ OBJ_CLASS_DECLARATION(opal_finalize_domain_t); * This function sets the name of a finalize domain. The domain must * have already been initialized by OBJ_CONSTRUCT() or OBJ_NEW(). */ -void opal_finalize_domain_init (opal_finalize_domain_t *domain, const char *domain_name); +void opal_finalize_domain_init(opal_finalize_domain_t *domain, const char *domain_name); /** * @brief Set the current finalize domain for opal_finalize_append_cleanup() @@ -187,7 +187,7 @@ void opal_finalize_domain_init (opal_finalize_domain_t *domain, const char *doma * This function sets the current finalize domain. This API is not thread safe * and is must be protected from multi-threaded invocation. */ -void opal_finalize_set_domain (opal_finalize_domain_t *domain); +void opal_finalize_set_domain(opal_finalize_domain_t *domain); /** * @brief Finalize a domain @@ -199,7 +199,7 @@ void opal_finalize_set_domain (opal_finalize_domain_t *domain); * any memory allocated by the relevant calls to opal_finalize_append_cleanup() * and effectively empties the cleanup domain. */ -void opal_finalize_cleanup_domain (opal_finalize_domain_t *domain); +void opal_finalize_cleanup_domain(opal_finalize_domain_t *domain); /** * @brief Cleanup domain function @@ -207,7 +207,7 @@ void opal_finalize_cleanup_domain (opal_finalize_domain_t *domain); * The argument is optional. It is valid to use the opal_finalize_register_cleanup() * macro to register a function that is of type void (*) (void). */ -typedef void (*opal_cleanup_fn_t) (void *); +typedef void (*opal_cleanup_fn_t)(void *); /** * @brief Append a cleanup function to the current domain @@ -216,17 +216,20 @@ typedef void (*opal_cleanup_fn_t) (void *); * @param[in] fn_name Name of the cleanup function (for debugging) * @param[in] user_data User data to pass to the cleanup function */ -void opal_finalize_append_cleanup (opal_cleanup_fn_t cleanup_fn, const char *fn_name, void *user_data); +void opal_finalize_append_cleanup(opal_cleanup_fn_t cleanup_fn, const char *fn_name, + void *user_data); -#define opal_finalize_register_cleanup_3(x, y, z) opal_finalize_append_cleanup((opal_cleanup_fn_t) x, y, z) -#define opal_finalize_register_cleanup_arg(x, y) opal_finalize_append_cleanup((opal_cleanup_fn_t) x, # x "(" #y ")", y) -#define opal_finalize_register_cleanup(x) opal_finalize_register_cleanup_3((opal_cleanup_fn_t) (x), # x, NULL) +#define opal_finalize_register_cleanup_3(x, y, z) \ + opal_finalize_append_cleanup((opal_cleanup_fn_t) x, y, z) +#define opal_finalize_register_cleanup_arg(x, y) \ + opal_finalize_append_cleanup((opal_cleanup_fn_t) x, #x "(" #y ")", y) +#define opal_finalize_register_cleanup(x) \ + opal_finalize_register_cleanup_3((opal_cleanup_fn_t)(x), #x, NULL) /* opal cleanup domains */ extern opal_finalize_domain_t opal_init_util_domain; extern opal_finalize_domain_t opal_init_domain; - END_C_DECLS #endif diff --git a/opal/runtime/opal_finalize.c b/opal/runtime/opal_finalize.c index 665c2b43aeb..94cd775af5b 100644 --- a/opal/runtime/opal_finalize.c +++ b/opal/runtime/opal_finalize.c @@ -32,15 +32,15 @@ #include "opal_config.h" #include "opal/class/opal_object.h" -#include "opal/util/output.h" -#include "opal/util/malloc.h" -#include "opal/util/proc.h" -#include "opal/util/show_help.h" -#include "opal/memoryhooks/memory.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" #include "opal/mca/threads/tsd.h" +#include "opal/memoryhooks/memory.h" +#include "opal/runtime/opal.h" #include "opal/runtime/opal_progress.h" +#include "opal/util/malloc.h" +#include "opal/util/output.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" extern int opal_initialized; extern int opal_util_initialized; @@ -50,9 +50,9 @@ static opal_mutex_t opal_finalize_cleanup_fns_lock = OPAL_MUTEX_STATIC_INIT; opal_list_t opal_finalize_cleanup_fns = {{0}}; struct opal_cleanup_fn_item_t { - opal_list_item_t super; + opal_list_item_t super; opal_cleanup_fn_t cleanup_fn; - void *user_data; + void *user_data; #if OPAL_ENABLE_DEBUG char *cleanup_fn_name; #endif @@ -61,33 +61,32 @@ struct opal_cleanup_fn_item_t { typedef struct opal_cleanup_fn_item_t opal_cleanup_fn_item_t; OBJ_CLASS_DECLARATION(opal_cleanup_fn_item_t); -static void opal_cleanup_fn_item_construct (opal_cleanup_fn_item_t *item) +static void opal_cleanup_fn_item_construct(opal_cleanup_fn_item_t *item) { #if OPAL_ENABLE_DEBUG item->cleanup_fn_name = NULL; #endif } -static void opal_cleanup_fn_item_destruct (opal_cleanup_fn_item_t *item) +static void opal_cleanup_fn_item_destruct(opal_cleanup_fn_item_t *item) { #if OPAL_ENABLE_DEBUG - free (item->cleanup_fn_name); + free(item->cleanup_fn_name); item->cleanup_fn_name = NULL; #endif } +OBJ_CLASS_INSTANCE(opal_cleanup_fn_item_t, opal_list_item_t, opal_cleanup_fn_item_construct, + opal_cleanup_fn_item_destruct); -OBJ_CLASS_INSTANCE(opal_cleanup_fn_item_t, opal_list_item_t, - opal_cleanup_fn_item_construct, opal_cleanup_fn_item_destruct); - -static void opal_finalize_domain_construct (opal_finalize_domain_t *domain) +static void opal_finalize_domain_construct(opal_finalize_domain_t *domain) { domain->domain_name = NULL; } -static void opal_finalize_domain_destruct (opal_finalize_domain_t *domain) +static void opal_finalize_domain_destruct(opal_finalize_domain_t *domain) { - free (domain->domain_name); + free(domain->domain_name); domain->domain_name = NULL; } @@ -98,47 +97,48 @@ static opal_finalize_domain_t *current_finalize_domain; opal_finalize_domain_t opal_init_util_domain = {{{0}}}; opal_finalize_domain_t opal_init_domain = {{{0}}}; -void opal_finalize_append_cleanup (opal_cleanup_fn_t cleanup_fn, const char *fn_name, void *user_data) +void opal_finalize_append_cleanup(opal_cleanup_fn_t cleanup_fn, const char *fn_name, + void *user_data) { opal_cleanup_fn_item_t *cleanup_item = OBJ_NEW(opal_cleanup_fn_item_t); - assert (NULL != cleanup_item); + assert(NULL != cleanup_item); cleanup_item->cleanup_fn = cleanup_fn; cleanup_item->user_data = user_data; #if OPAL_ENABLE_DEBUG - cleanup_item->cleanup_fn_name = strdup (fn_name); - assert (NULL != cleanup_item->cleanup_fn_name); + cleanup_item->cleanup_fn_name = strdup(fn_name); + assert(NULL != cleanup_item->cleanup_fn_name); #else (void) fn_name; #endif - opal_mutex_lock (&opal_finalize_cleanup_fns_lock); - opal_list_append (¤t_finalize_domain->super, &cleanup_item->super); - opal_mutex_unlock (&opal_finalize_cleanup_fns_lock); + opal_mutex_lock(&opal_finalize_cleanup_fns_lock); + opal_list_append(¤t_finalize_domain->super, &cleanup_item->super); + opal_mutex_unlock(&opal_finalize_cleanup_fns_lock); } -void opal_finalize_domain_init (opal_finalize_domain_t *domain, const char *domain_name) +void opal_finalize_domain_init(opal_finalize_domain_t *domain, const char *domain_name) { - free (domain->domain_name); - domain->domain_name = domain_name ? strdup (domain_name) : NULL; + free(domain->domain_name); + domain->domain_name = domain_name ? strdup(domain_name) : NULL; } -void opal_finalize_set_domain (opal_finalize_domain_t *domain) +void opal_finalize_set_domain(opal_finalize_domain_t *domain) { current_finalize_domain = domain; } -void opal_finalize_cleanup_domain (opal_finalize_domain_t *domain) +void opal_finalize_cleanup_domain(opal_finalize_domain_t *domain) { opal_cleanup_fn_item_t *cleanup_item, *next; /* call any registered cleanup functions before tearing down OPAL */ - OPAL_LIST_FOREACH_SAFE_REV(cleanup_item, next, &domain->super, opal_cleanup_fn_item_t) { - cleanup_item->cleanup_fn (cleanup_item->user_data); - opal_list_remove_item (&domain->super, &cleanup_item->super); + OPAL_LIST_FOREACH_SAFE_REV (cleanup_item, next, &domain->super, opal_cleanup_fn_item_t) { + cleanup_item->cleanup_fn(cleanup_item->user_data); + opal_list_remove_item(&domain->super, &cleanup_item->super); OBJ_RELEASE(cleanup_item); } } -int opal_finalize_util (void) +int opal_finalize_util(void) { if (--opal_util_initialized != 0) { if (opal_util_initialized < 0) { @@ -147,19 +147,18 @@ int opal_finalize_util (void) return OPAL_SUCCESS; } - opal_finalize_cleanup_domain (&opal_init_util_domain); + opal_finalize_cleanup_domain(&opal_init_util_domain); OBJ_DESTRUCT(&opal_init_util_domain); /* finalize the class/object system */ opal_class_finalize(); - free (opal_process_info.nodename); + free(opal_process_info.nodename); opal_process_info.nodename = NULL; return OPAL_SUCCESS; } - int opal_finalize(void) { if (--opal_initialized != 0) { @@ -169,7 +168,7 @@ int opal_finalize(void) return OPAL_SUCCESS; } - opal_finalize_cleanup_domain (&opal_init_domain); + opal_finalize_cleanup_domain(&opal_init_domain); OBJ_DESTRUCT(&opal_init_domain); /* finalize libevent code */ diff --git a/opal/runtime/opal_info_support.c b/opal/runtime/opal_info_support.c index c4bd5eee30e..6676dba657b 100644 --- a/opal/runtime/opal_info_support.c +++ b/opal/runtime/opal_info_support.c @@ -27,11 +27,11 @@ #include "opal_config.h" -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #include @@ -39,21 +39,21 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/util/output.h" +#include "opal/mca/base/mca_base_pvar.h" +#include "opal/runtime/opal.h" +#include "opal/util/argv.h" #include "opal/util/cmd_line.h" #include "opal/util/error.h" -#include "opal/util/argv.h" -#include "opal/util/show_help.h" +#include "opal/util/output.h" #include "opal/util/printf.h" -#include "opal/runtime/opal.h" -#include "opal/mca/base/mca_base_pvar.h" +#include "opal/util/show_help.h" #include "opal/include/opal/frameworks.h" #include "opal/mca/installdirs/installdirs.h" -#include "opal/runtime/opal_info_support.h" #include "opal/mca/base/mca_base_component_repository.h" +#include "opal/runtime/opal_info_support.h" const char *opal_info_path_prefix = "prefix"; const char *opal_info_path_bindir = "bindir"; @@ -108,16 +108,13 @@ static void component_map_destruct(opal_info_component_map_t *map) * list of components */ } -OBJ_CLASS_INSTANCE(opal_info_component_map_t, - opal_list_item_t, - component_map_construct, +OBJ_CLASS_INSTANCE(opal_info_component_map_t, opal_list_item_t, component_map_construct, component_map_destruct); -static void opal_info_show_failed_component(const mca_base_component_repository_item_t* ri, +static void opal_info_show_failed_component(const mca_base_component_repository_item_t *ri, const char *error_msg); -int opal_info_init(int argc, char **argv, - opal_cmd_line_t *opal_info_cmd_line) +int opal_info_init(int argc, char **argv, opal_cmd_line_t *opal_info_cmd_line) { int ret; bool want_help = false; @@ -126,34 +123,38 @@ int opal_info_init(int argc, char **argv, /* Initialize the argv parsing handle */ if (OPAL_SUCCESS != (ret = opal_init_util(&argc, &argv))) { - opal_show_help("help-opal_info.txt", "lib-call-fail", true, - "opal_init_util", __FILE__, __LINE__, NULL); + opal_show_help("help-opal_info.txt", "lib-call-fail", true, "opal_init_util", __FILE__, + __LINE__, NULL); exit(ret); } /* add the cmd line options */ opal_cmd_line_make_opt3(opal_info_cmd_line, 'V', NULL, "version", 0, "Show version of Open MPI"); - opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "param", 2, - "Show MCA parameters. The first parameter is the framework (or the keyword \"all\"); the second parameter is the specific component name (or the keyword \"all\")."); - opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "params", 2, - "Synonym for --param"); + opal_cmd_line_make_opt3( + opal_info_cmd_line, '\0', NULL, "param", 2, + "Show MCA parameters. The first parameter is the framework (or the keyword \"all\"); the " + "second parameter is the specific component name (or the keyword \"all\")."); + opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "params", 2, "Synonym for --param"); opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "internal", 0, "Show internal MCA parameters (not meant to be modified by users)"); - opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "path", 1, - "Show paths that Open MPI was configured with. Accepts the following parameters: prefix, bindir, libdir, incdir, mandir, pkglibdir, sysconfdir, all"); + opal_cmd_line_make_opt3( + opal_info_cmd_line, '\0', NULL, "path", 1, + "Show paths that Open MPI was configured with. Accepts the following parameters: prefix, " + "bindir, libdir, incdir, mandir, pkglibdir, sysconfdir, all"); opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "arch", 0, "Show architecture Open MPI was compiled on"); opal_cmd_line_make_opt3(opal_info_cmd_line, 'c', NULL, "config", 0, "Show configuration options"); opal_cmd_line_make_opt3(opal_info_cmd_line, 't', NULL, "type", 1, "Show internal MCA parameters with the type specified in parameter."); - opal_cmd_line_make_opt3(opal_info_cmd_line, 'h', NULL, "help", 0, - "Show this help message"); + opal_cmd_line_make_opt3(opal_info_cmd_line, 'h', NULL, "help", 0, "Show this help message"); opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "pretty-print", 0, - "When used in conjunction with other parameters, the output is displayed in 'pretty-print' format (default)"); + "When used in conjunction with other parameters, the output is " + "displayed in 'pretty-print' format (default)"); opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "parsable", 0, - "When used in conjunction with other parameters, the output is displayed in a machine-parsable format"); + "When used in conjunction with other parameters, the output is " + "displayed in a machine-parsable format"); opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "parseable", 0, "Synonym for --parsable"); opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "hostname", 0, @@ -164,15 +165,17 @@ int opal_info_init(int argc, char **argv, "Show only variables with at most this level (1-9)"); opal_cmd_line_make_opt3(opal_info_cmd_line, 's', NULL, "selected-only", 0, "Show only variables from selected components"); - opal_cmd_line_make_opt3(opal_info_cmd_line, '\0', NULL, "show-failed", 0, - "Show the components that failed to load along with the reason why they failed."); + opal_cmd_line_make_opt3( + opal_info_cmd_line, '\0', NULL, "show-failed", 0, + "Show the components that failed to load along with the reason why they failed."); /* set our threading level */ opal_set_using_threads(false); /* Get MCA parameters, if any */ - if( OPAL_SUCCESS != mca_base_open() ) { - opal_show_help("help-opal_info.txt", "lib-call-fail", true, "mca_base_open", __FILE__, __LINE__ ); + if (OPAL_SUCCESS != mca_base_open()) { + opal_show_help("help-opal_info.txt", "lib-call-fail", true, "mca_base_open", __FILE__, + __LINE__); opal_finalize_util(); return OPAL_ERROR; } @@ -188,19 +191,17 @@ int opal_info_init(int argc, char **argv, if (OPAL_SUCCESS != ret) { cmd_error = true; if (OPAL_ERR_SILENT != ret) { - fprintf(stderr, "%s: command line error (%s)\n", argv[0], - opal_strerror(ret)); + fprintf(stderr, "%s: command line error (%s)\n", argv[0], opal_strerror(ret)); } } - if (!cmd_error && - (opal_cmd_line_is_taken(opal_info_cmd_line, "help") || - opal_cmd_line_is_taken(opal_info_cmd_line, "h"))) { + if (!cmd_error + && (opal_cmd_line_is_taken(opal_info_cmd_line, "help") + || opal_cmd_line_is_taken(opal_info_cmd_line, "h"))) { char *str, *usage; want_help = true; usage = opal_cmd_line_get_usage_msg(opal_info_cmd_line); - str = opal_show_help_string("help-opal_info.txt", "usage", - true, usage); + str = opal_show_help_string("help-opal_info.txt", "usage", true, usage); if (NULL != str) { printf("%s", str); free(str); @@ -219,11 +220,11 @@ int opal_info_init(int argc, char **argv, mca_base_cmd_line_process_args(opal_info_cmd_line, &app_env, &global_env); - /* set the flags */ if (opal_cmd_line_is_taken(opal_info_cmd_line, "pretty-print")) { opal_info_pretty = true; - } else if (opal_cmd_line_is_taken(opal_info_cmd_line, "parsable") || opal_cmd_line_is_taken(opal_info_cmd_line, "parseable")) { + } else if (opal_cmd_line_is_taken(opal_info_cmd_line, "parsable") + || opal_cmd_line_is_taken(opal_info_cmd_line, "parseable")) { opal_info_pretty = false; } @@ -232,7 +233,7 @@ int opal_info_init(int argc, char **argv, opal_info_register_flags = MCA_BASE_REGISTER_DEFAULT; } - if( opal_cmd_line_is_taken(opal_info_cmd_line, "show-failed") ) { + if (opal_cmd_line_is_taken(opal_info_cmd_line, "show-failed")) { mca_base_component_track_load_errors = true; } @@ -244,7 +245,8 @@ void opal_info_finalize(void) opal_finalize_util(); } -static int info_register_framework (mca_base_framework_t *framework, opal_pointer_array_t *component_map) +static int info_register_framework(mca_base_framework_t *framework, + opal_pointer_array_t *component_map) { opal_info_component_map_t *map; int rc; @@ -265,19 +267,24 @@ static int info_register_framework (mca_base_framework_t *framework, opal_pointe return rc; } -int opal_info_register_project_frameworks (const char *project_name, mca_base_framework_t **frameworks, - opal_pointer_array_t *component_map) +int opal_info_register_project_frameworks(const char *project_name, + mca_base_framework_t **frameworks, + opal_pointer_array_t *component_map) { - int i, rc=OPAL_SUCCESS; + int i, rc = OPAL_SUCCESS; - for (i=0; NULL != frameworks[i]; i++) { + for (i = 0; NULL != frameworks[i]; i++) { if (OPAL_SUCCESS != (rc = info_register_framework(frameworks[i], component_map))) { if (OPAL_ERR_BAD_PARAM == rc) { - fprintf(stderr, "\nA \"bad parameter\" error was encountered when opening the %s %s framework\n", + fprintf(stderr, + "\nA \"bad parameter\" error was encountered when opening the %s %s " + "framework\n", project_name, frameworks[i]->framework_name); - fprintf(stderr, "The output received from that framework includes the following parameters:\n\n"); + fprintf(stderr, "The output received from that framework includes the following " + "parameters:\n\n"); } else if (OPAL_ERR_NOT_AVAILABLE != rc) { - fprintf(stderr, "%s_info_register: %s failed\n", project_name, frameworks[i]->framework_name); + fprintf(stderr, "%s_info_register: %s failed\n", project_name, + frameworks[i]->framework_name); rc = OPAL_ERROR; } else { continue; @@ -299,7 +306,7 @@ void opal_info_register_types(opal_pointer_array_t *mca_types) opal_pointer_array_add(mca_types, "opal"); /* push all the types found by autogen */ - for (i=0; NULL != opal_frameworks[i]; i++) { + for (i = 0; NULL != opal_frameworks[i]; i++) { opal_pointer_array_add(mca_types, opal_frameworks[i]->framework_name); } } @@ -313,8 +320,9 @@ int opal_info_register_framework_params(opal_pointer_array_t *component_map) } /* Register mca/base parameters */ - if( OPAL_SUCCESS != mca_base_open() ) { - opal_show_help("help-opal_info.txt", "lib-call-fail", true, "mca_base_open", __FILE__, __LINE__ ); + if (OPAL_SUCCESS != mca_base_open()) { + opal_show_help("help-opal_info.txt", "lib-call-fail", true, "mca_base_open", __FILE__, + __LINE__); return OPAL_ERROR; } @@ -327,7 +335,6 @@ int opal_info_register_framework_params(opal_pointer_array_t *component_map) return opal_info_register_project_frameworks("opal", opal_frameworks, component_map); } - void opal_info_close_components(void) { int i; @@ -337,15 +344,14 @@ void opal_info_close_components(void) return; } - for (i=0; NULL != opal_frameworks[i]; i++) { + for (i = 0; NULL != opal_frameworks[i]; i++) { (void) mca_base_framework_close(opal_frameworks[i]); } /* release our reference to MCA */ - mca_base_close (); + mca_base_close(); } - void opal_info_show_path(const char *type, const char *value) { char *pretty, *path; @@ -423,7 +429,8 @@ void opal_info_do_path(bool want_all, opal_cmd_line_t *cmd_line) } else if (0 == strcmp(opal_info_path_datadir, scope)) { opal_info_show_path(opal_info_path_datadir, opal_install_dirs.datadir); } else if (0 == strcmp(opal_info_path_sharedstatedir, scope)) { - opal_info_show_path(opal_info_path_sharedstatedir, opal_install_dirs.sharedstatedir); + opal_info_show_path(opal_info_path_sharedstatedir, + opal_install_dirs.sharedstatedir); } else if (0 == strcmp(opal_info_path_localstatedir, scope)) { opal_info_show_path(opal_info_path_localstatedir, opal_install_dirs.localstatedir); } else if (0 == strcmp(opal_info_path_infodir, scope)) { @@ -442,10 +449,8 @@ void opal_info_do_path(bool want_all, opal_cmd_line_t *cmd_line) } } -void opal_info_do_params(bool want_all_in, bool want_internal, - opal_pointer_array_t *mca_types, - opal_pointer_array_t *component_map, - opal_cmd_line_t *opal_info_cmd_line) +void opal_info_do_params(bool want_all_in, bool want_internal, opal_pointer_array_t *mca_types, + opal_pointer_array_t *component_map, opal_cmd_line_t *opal_info_cmd_line) { mca_base_var_info_lvl_t max_level = OPAL_INFO_LVL_1; int count; @@ -460,15 +465,16 @@ void opal_info_do_params(bool want_all_in, bool want_internal, } else if (opal_cmd_line_is_taken(opal_info_cmd_line, "params")) { p = "params"; } else { - p = "foo"; /* should never happen, but protect against segfault */ + p = "foo"; /* should never happen, but protect against segfault */ } - if (NULL != (str = opal_cmd_line_get_param (opal_info_cmd_line, "level", 0, 0))) { + if (NULL != (str = opal_cmd_line_get_param(opal_info_cmd_line, "level", 0, 0))) { char *tmp; errno = 0; - max_level = strtol (str, &tmp, 10) + OPAL_INFO_LVL_1 - 1; - if (0 != errno || '\0' != tmp[0] || max_level < OPAL_INFO_LVL_1 || max_level > OPAL_INFO_LVL_9) { + max_level = strtol(str, &tmp, 10) + OPAL_INFO_LVL_1 - 1; + if (0 != errno || '\0' != tmp[0] || max_level < OPAL_INFO_LVL_1 + || max_level > OPAL_INFO_LVL_9) { char *usage = opal_cmd_line_get_usage_msg(opal_info_cmd_line); opal_show_help("help-opal_info.txt", "invalid-level", true, str); free(usage); @@ -487,7 +493,7 @@ void opal_info_do_params(bool want_all_in, bool want_internal, */ count = opal_cmd_line_get_ninsts(opal_info_cmd_line, p); for (i = 0; i < count; ++i) { - type = opal_cmd_line_get_param(opal_info_cmd_line, p, (int)i, 0); + type = opal_cmd_line_get_param(opal_info_cmd_line, p, (int) i, 0); if (0 == strcmp(opal_info_type_all, type)) { want_all = true; break; @@ -502,18 +508,18 @@ void opal_info_do_params(bool want_all_in, bool want_internal, opal_info_component_all, opal_info_ver_full, opal_info_ver_all); for (i = 0; i < mca_types->size; ++i) { - if (NULL == (type = (char *)opal_pointer_array_get_item(mca_types, i))) { + if (NULL == (type = (char *) opal_pointer_array_get_item(mca_types, i))) { continue; } opal_info_show_mca_params(type, opal_info_component_all, max_level, want_internal); } } else { for (i = 0; i < count; ++i) { - type = opal_cmd_line_get_param(opal_info_cmd_line, p, (int)i, 0); - component = opal_cmd_line_get_param(opal_info_cmd_line, p, (int)i, 1); + type = opal_cmd_line_get_param(opal_info_cmd_line, p, (int) i, 0); + component = opal_cmd_line_get_param(opal_info_cmd_line, p, (int) i, 1); for (found = false, i = 0; i < mca_types->size; ++i) { - if (NULL == (str = (char *)opal_pointer_array_get_item(mca_types, i))) { + if (NULL == (str = (char *) opal_pointer_array_get_item(mca_types, i))) { continue; } if (0 == strcmp(str, type)) { @@ -529,9 +535,8 @@ void opal_info_do_params(bool want_all_in, bool want_internal, exit(1); } - opal_info_show_component_version(mca_types, component_map, type, - component, opal_info_ver_full, - opal_info_ver_all); + opal_info_show_component_version(mca_types, component_map, type, component, + opal_info_ver_full, opal_info_ver_all); opal_info_show_mca_params(type, component, max_level, want_internal); } } @@ -539,14 +544,16 @@ void opal_info_do_params(bool want_all_in, bool want_internal, void opal_info_err_params(opal_pointer_array_t *component_map) { - opal_info_component_map_t *map=NULL, *mptr; + opal_info_component_map_t *map = NULL, *mptr; int i; /* all we want to do is display the LAST entry in the * component_map array as this is the one that generated the error */ - for (i=0; i < component_map->size; i++) { - if (NULL == (mptr = (opal_info_component_map_t*)opal_pointer_array_get_item(component_map, i))) { + for (i = 0; i < component_map->size; i++) { + if (NULL + == (mptr = (opal_info_component_map_t *) opal_pointer_array_get_item(component_map, + i))) { continue; } map = mptr; @@ -568,16 +575,17 @@ void opal_info_do_type(opal_cmd_line_t *opal_info_cmd_line) int i, j, k, len, ret; char *p; const mca_base_var_t *var; - char** strings, *message; + char **strings, *message; const mca_base_var_group_t *group; p = "type"; - if (NULL != (str = opal_cmd_line_get_param (opal_info_cmd_line, "level", 0, 0))) { + if (NULL != (str = opal_cmd_line_get_param(opal_info_cmd_line, "level", 0, 0))) { char *tmp; errno = 0; - max_level = strtol (str, &tmp, 10) + OPAL_INFO_LVL_1 - 1; - if (0 != errno || '\0' != tmp[0] || max_level < OPAL_INFO_LVL_1 || max_level > OPAL_INFO_LVL_9) { + max_level = strtol(str, &tmp, 10) + OPAL_INFO_LVL_1 - 1; + if (0 != errno || '\0' != tmp[0] || max_level < OPAL_INFO_LVL_1 + || max_level > OPAL_INFO_LVL_9) { char *usage = opal_cmd_line_get_usage_msg(opal_info_cmd_line); opal_show_help("help-opal_info.txt", "invalid-level", true, str); free(usage); @@ -586,24 +594,27 @@ void opal_info_do_type(opal_cmd_line_t *opal_info_cmd_line) } count = opal_cmd_line_get_ninsts(opal_info_cmd_line, p); - len = mca_base_var_get_count (); + len = mca_base_var_get_count(); for (k = 0; k < count; ++k) { type = opal_cmd_line_get_param(opal_info_cmd_line, p, k, 0); for (i = 0; i < len; ++i) { - ret = mca_base_var_get (i, &var); + ret = mca_base_var_get(i, &var); if (OPAL_SUCCESS != ret) { continue; } - if (0 == strcmp(type, ompi_var_type_names[var->mbv_type]) && (var->mbv_info_lvl <= max_level)) { - ret = mca_base_var_dump(var->mbv_index, &strings, !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE : MCA_BASE_VAR_DUMP_READABLE); + if (0 == strcmp(type, ompi_var_type_names[var->mbv_type]) + && (var->mbv_info_lvl <= max_level)) { + ret = mca_base_var_dump(var->mbv_index, &strings, + !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE + : MCA_BASE_VAR_DUMP_READABLE); if (OPAL_SUCCESS != ret) { continue; } (void) mca_base_var_group_get(var->mbv_group_index, &group); - for (j = 0 ; strings[j] ; ++j) { + for (j = 0; strings[j]; ++j) { if (0 == j && opal_info_pretty) { - opal_asprintf (&message, "MCA %s", group->group_framework); + opal_asprintf(&message, "MCA %s", group->group_framework); opal_info_out(message, message, strings[j]); free(message); } else { @@ -617,7 +628,8 @@ void opal_info_do_type(opal_cmd_line_t *opal_info_cmd_line) } } -static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, mca_base_var_info_lvl_t max_level, bool want_internal) +static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, + mca_base_var_info_lvl_t max_level, bool want_internal) { const int *variables, *groups; const mca_base_pvar_t *pvar; @@ -628,35 +640,36 @@ static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, m int ret, i, j, count; variables = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, const int); - count = opal_value_array_get_size((opal_value_array_t *)&group->group_vars); + count = opal_value_array_get_size((opal_value_array_t *) &group->group_vars); /* the default component name is "base". depending on how the * group was registered the group may or not have this set. */ group_component = group->group_component ? group->group_component : "base"; /* check if this group may be disabled due to a selection variable */ - if (0 != strcmp (group_component, "base")) { + if (0 != strcmp(group_component, "base")) { int var_id; /* read the selection parameter */ - var_id = mca_base_var_find (group->group_project, group->group_framework, NULL, NULL); + var_id = mca_base_var_find(group->group_project, group->group_framework, NULL, NULL); if (0 <= var_id) { - const mca_base_var_storage_t *value=NULL; + const mca_base_var_storage_t *value = NULL; char **requested_components; bool include_mode; - mca_base_var_get_value (var_id, &value, NULL, NULL); + mca_base_var_get_value(var_id, &value, NULL, NULL); if (NULL != value && NULL != value->stringval && '\0' != value->stringval[0]) { - mca_base_component_parse_requested (value->stringval, &include_mode, &requested_components); + mca_base_component_parse_requested(value->stringval, &include_mode, + &requested_components); - for (i = 0, requested = !include_mode ; requested_components[i] ; ++i) { - if (0 == strcmp (requested_components[i], group_component)) { + for (i = 0, requested = !include_mode; requested_components[i]; ++i) { + if (0 == strcmp(requested_components[i], group_component)) { requested = include_mode; break; } } - opal_argv_free (requested_components); + opal_argv_free(requested_components); } } } @@ -665,33 +678,32 @@ static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, m char *component_msg = NULL; opal_asprintf(&component_msg, " %s", group_component); - for (i = 0 ; i < count ; ++i) { + for (i = 0; i < count; ++i) { ret = mca_base_var_get(variables[i], &var); - if (OPAL_SUCCESS != ret || ((var->mbv_flags & MCA_BASE_VAR_FLAG_INTERNAL) && - !want_internal) || - max_level < var->mbv_info_lvl) { + if (OPAL_SUCCESS != ret || ((var->mbv_flags & MCA_BASE_VAR_FLAG_INTERNAL) && !want_internal) + || max_level < var->mbv_info_lvl) { continue; } if (opal_info_pretty && curr_group != group) { - opal_asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", - group->group_framework, - component_msg ? component_msg : ""); + opal_asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", group->group_framework, + component_msg ? component_msg : ""); opal_info_out(message, message, "---------------------------------------------------"); free(message); curr_group = group; } - ret = mca_base_var_dump(variables[i], &strings, !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE : MCA_BASE_VAR_DUMP_READABLE); + ret = mca_base_var_dump(variables[i], &strings, + !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE + : MCA_BASE_VAR_DUMP_READABLE); if (OPAL_SUCCESS != ret) { continue; } - for (j = 0 ; strings[j] ; ++j) { + for (j = 0; strings[j]; ++j) { if (0 == j && opal_info_pretty) { - opal_asprintf (&message, "MCA%s %s%s", requested ? "" : " (-)", - group->group_framework, - component_msg ? component_msg : ""); + opal_asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", + group->group_framework, component_msg ? component_msg : ""); opal_info_out(message, message, strings[j]); free(message); } else { @@ -702,42 +714,42 @@ static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, m if (!opal_info_pretty) { /* generate an entry indicating whether this variable is disabled or not. if the * format in mca_base_var/pvar.c changes this needs to be changed as well */ - opal_asprintf (&message, "mca:%s:%s:param:%s:disabled:%s", group->group_framework, - group_component, var->mbv_full_name, requested ? "false" : "true"); + opal_asprintf(&message, "mca:%s:%s:param:%s:disabled:%s", group->group_framework, + group_component, var->mbv_full_name, requested ? "false" : "true"); opal_info_out("", "", message); - free (message); + free(message); } free(strings); } variables = OPAL_VALUE_ARRAY_GET_BASE(&group->group_pvars, const int); - count = opal_value_array_get_size((opal_value_array_t *)&group->group_pvars); + count = opal_value_array_get_size((opal_value_array_t *) &group->group_pvars); - for (i = 0 ; i < count ; ++i) { + for (i = 0; i < count; ++i) { ret = mca_base_pvar_get(variables[i], &pvar); if (OPAL_SUCCESS != ret || max_level < pvar->verbosity) { continue; } if (opal_info_pretty && curr_group != group) { - opal_asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", - group->group_framework, - component_msg ? component_msg : ""); + opal_asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", group->group_framework, + component_msg ? component_msg : ""); opal_info_out(message, message, "---------------------------------------------------"); free(message); curr_group = group; } - ret = mca_base_pvar_dump (variables[i], &strings, !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE : MCA_BASE_VAR_DUMP_READABLE); + ret = mca_base_pvar_dump(variables[i], &strings, + !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE + : MCA_BASE_VAR_DUMP_READABLE); if (OPAL_SUCCESS != ret) { continue; } - for (j = 0 ; strings[j] ; ++j) { + for (j = 0; strings[j]; ++j) { if (0 == j && opal_info_pretty) { - opal_asprintf (&message, "MCA%s %s%s", requested ? "" : " (-)", - group->group_framework, - component_msg ? component_msg : ""); + opal_asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", + group->group_framework, component_msg ? component_msg : ""); opal_info_out(message, message, strings[j]); free(message); } else { @@ -748,18 +760,18 @@ static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, m if (!opal_info_pretty) { /* generate an entry indicating whether this variable is disabled or not. if the * format in mca_base_var/pvar.c changes this needs to be changed as well */ - opal_asprintf (&message, "mca:%s:%s:pvar:%s:disabled:%s", group->group_framework, - group_component, pvar->name, requested ? "false" : "true"); + opal_asprintf(&message, "mca:%s:%s:pvar:%s:disabled:%s", group->group_framework, + group_component, pvar->name, requested ? "false" : "true"); opal_info_out("", "", message); - free (message); + free(message); } free(strings); } groups = OPAL_VALUE_ARRAY_GET_BASE(&group->group_subgroups, const int); - count = opal_value_array_get_size((opal_value_array_t *)&group->group_subgroups); + count = opal_value_array_get_size((opal_value_array_t *) &group->group_subgroups); - for (i = 0 ; i < count ; ++i) { + for (i = 0; i < count; ++i) { ret = mca_base_var_group_get(groups[i], &group); if (OPAL_SUCCESS != ret) { continue; @@ -775,7 +787,7 @@ void opal_info_show_mca_params(const char *type, const char *component, const mca_base_var_group_t *group; int ret; - if (0 == strcmp (component, "all")) { + if (0 == strcmp(component, "all")) { ret = mca_base_var_group_find("*", type, NULL); if (0 > ret) { return; @@ -795,20 +807,16 @@ void opal_info_show_mca_params(const char *type, const char *component, } } - - void opal_info_do_arch() { opal_info_out("Configured architecture", "config:arch", OPAL_ARCH); } - void opal_info_do_hostname() { opal_info_out("Configure host", "config:host", OPAL_CONFIGURE_HOST); } - static char *escape_quotes(const char *value) { const char *src; @@ -845,7 +853,6 @@ static char *escape_quotes(const char *value) return quoted_value; } - /* * Private variables - set some reasonable screen size defaults */ @@ -875,7 +882,7 @@ void opal_info_out(const char *pretty_message, const char *plain_message, const #ifdef TIOCGWINSZ if (screen_width < INT_MAX) { struct winsize size; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, (char*) &size) >= 0) { + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *) &size) >= 0) { screen_width = size.ws_col; } } @@ -893,20 +900,20 @@ void opal_info_out(const char *pretty_message, const char *plain_message, const len = strlen(v); if (len > 0) { - while (len > 0 && isspace(v[len-1])) len--; + while (len > 0 && isspace(v[len - 1])) { + len--; + } v[len] = '\0'; } if (opal_info_pretty && NULL != pretty_message) { - if (centerpoint > (int)strlen(pretty_message)) { - opal_asprintf(&spaces, "%*s", centerpoint - - (int)strlen(pretty_message), " "); + if (centerpoint > (int) strlen(pretty_message)) { + opal_asprintf(&spaces, "%*s", centerpoint - (int) strlen(pretty_message), " "); } else { spaces = strdup(""); #if OPAL_ENABLE_DEBUG - if (centerpoint < (int)strlen(pretty_message)) { - opal_show_help("help-opal_info.txt", - "developer warning: field too long", false, + if (centerpoint < (int) strlen(pretty_message)) { + opal_show_help("help-opal_info.txt", "developer warning: field too long", false, pretty_message, centerpoint); } #endif @@ -932,7 +939,7 @@ void opal_info_out(const char *pretty_message, const char *plain_message, const */ savev = v[max_value_width]; v[max_value_width] = '\0'; - pos = (char*)strrchr(v, (int)' '); + pos = (char *) strrchr(v, (int) ' '); v[max_value_width] = savev; if (NULL == pos) { /* No space found < max_value_width. Look for the first @@ -1001,13 +1008,11 @@ void opal_info_out(const char *pretty_message, const char *plain_message, const /* * Prints the passed integer in a pretty or parsable format. */ -void opal_info_out_int(const char *pretty_message, - const char *plain_message, - int value) +void opal_info_out_int(const char *pretty_message, const char *plain_message, int value) { char *valstr; - opal_asprintf(&valstr, "%d", (int)value); + opal_asprintf(&valstr, "%d", (int) value); opal_info_out(pretty_message, plain_message, valstr); free(valstr); } @@ -1017,10 +1022,9 @@ void opal_info_out_int(const char *pretty_message, * a wildcard) */ void opal_info_show_component_version(opal_pointer_array_t *mca_types, - opal_pointer_array_t *component_map, - const char *type_name, - const char *component_name, - const char *scope, const char *ver_type) + opal_pointer_array_t *component_map, const char *type_name, + const char *component_name, const char *scope, + const char *ver_type) { bool want_all_components = false; bool want_all_types = false; @@ -1041,7 +1045,7 @@ void opal_info_show_component_version(opal_pointer_array_t *mca_types, /* Check to see if the type is valid */ for (found = false, j = 0; j < mca_types->size; ++j) { - if (NULL == (pos = (char*)opal_pointer_array_get_item(mca_types, j))) { + if (NULL == (pos = (char *) opal_pointer_array_get_item(mca_types, j))) { continue; } if (0 == strcmp(pos, type_name)) { @@ -1058,25 +1062,26 @@ void opal_info_show_component_version(opal_pointer_array_t *mca_types, } /* Now that we have a valid type, find the right components */ - for (j=0; j < component_map->size; j++) { - if (NULL == (map = (opal_info_component_map_t*)opal_pointer_array_get_item(component_map, j))) { + for (j = 0; j < component_map->size; j++) { + if (NULL + == (map = (opal_info_component_map_t *) opal_pointer_array_get_item(component_map, + j))) { continue; } if ((want_all_types || 0 == strcmp(type_name, map->type)) && map->components) { /* found it! */ - OPAL_LIST_FOREACH(cli, map->components, mca_base_component_list_item_t) { + OPAL_LIST_FOREACH (cli, map->components, mca_base_component_list_item_t) { const mca_base_component_t *component = cli->cli_component; - if (want_all_components || - 0 == strcmp(component->mca_component_name, component_name)) { + if (want_all_components + || 0 == strcmp(component->mca_component_name, component_name)) { opal_info_show_mca_version(component, scope, ver_type); } } /* found it! */ - OPAL_LIST_FOREACH(cli_failed, map->failed_components, mca_base_failed_component_t) { + OPAL_LIST_FOREACH (cli_failed, map->failed_components, mca_base_failed_component_t) { mca_base_component_repository_item_t *ri = cli_failed->comp; - if (want_all_components || - 0 == strcmp(component_name, ri->ri_name) ) { + if (want_all_components || 0 == strcmp(component_name, ri->ri_name)) { opal_info_show_failed_component(ri, cli_failed->error_msg); } } @@ -1088,8 +1093,7 @@ void opal_info_show_component_version(opal_pointer_array_t *mca_types, } } - -static void opal_info_show_failed_component(const mca_base_component_repository_item_t* ri, +static void opal_info_show_failed_component(const mca_base_component_repository_item_t *ri, const char *error_msg) { char *message, *content; @@ -1116,8 +1120,8 @@ static void opal_info_show_failed_component(const mca_base_component_repository_ /* * Given a component, display its relevant version(s) */ -void opal_info_show_mca_version(const mca_base_component_t* component, - const char *scope, const char *ver_type) +void opal_info_show_mca_version(const mca_base_component_t *component, const char *scope, + const char *ver_type) { bool printed; bool want_mca = false; @@ -1129,33 +1133,29 @@ void opal_info_show_mca_version(const mca_base_component_t* component, char *component_version; char *tmp; - if (0 == strcmp(ver_type, opal_info_ver_all) || - 0 == strcmp(ver_type, opal_info_ver_mca)) { + if (0 == strcmp(ver_type, opal_info_ver_all) || 0 == strcmp(ver_type, opal_info_ver_mca)) { want_mca = true; } - if (0 == strcmp(ver_type, opal_info_ver_all) || - 0 == strcmp(ver_type, opal_info_ver_type)) { + if (0 == strcmp(ver_type, opal_info_ver_all) || 0 == strcmp(ver_type, opal_info_ver_type)) { want_type = true; } - if (0 == strcmp(ver_type, opal_info_ver_all) || - 0 == strcmp(ver_type, opal_info_ver_component)) { + if (0 == strcmp(ver_type, opal_info_ver_all) + || 0 == strcmp(ver_type, opal_info_ver_component)) { want_component = true; } mca_version = opal_info_make_version_str(scope, component->mca_major_version, component->mca_minor_version, - component->mca_release_version, "", - ""); + component->mca_release_version, "", ""); api_version = opal_info_make_version_str(scope, component->mca_type_major_version, component->mca_type_minor_version, - component->mca_type_release_version, "", - ""); + component->mca_type_release_version, "", ""); component_version = opal_info_make_version_str(scope, component->mca_component_major_version, component->mca_component_minor_version, - component->mca_component_release_version, - "", ""); + component->mca_component_release_version, "", + ""); if (opal_info_pretty) { opal_asprintf(&message, "MCA %s", component->mca_type_name); printed = false; @@ -1205,7 +1205,8 @@ void opal_info_show_mca_version(const mca_base_component_t* component, } } else { - opal_asprintf(&message, "mca:%s:%s:version", component->mca_type_name, component->mca_component_name); + opal_asprintf(&message, "mca:%s:%s:version", component->mca_type_name, + component->mca_component_name); if (want_mca) { opal_asprintf(&tmp, "mca:%s", mca_version); opal_info_out(NULL, message, tmp); @@ -1235,18 +1236,14 @@ void opal_info_show_mca_version(const mca_base_component_t* component, } } - -char *opal_info_make_version_str(const char *scope, - int major, int minor, int release, - const char *greek, - const char *repo) +char *opal_info_make_version_str(const char *scope, int major, int minor, int release, + const char *greek, const char *repo) { char *str = NULL, *tmp; char temp[BUFSIZ]; temp[BUFSIZ - 1] = '\0'; - if (0 == strcmp(scope, opal_info_ver_full) || - 0 == strcmp(scope, opal_info_ver_all)) { + if (0 == strcmp(scope, opal_info_ver_full) || 0 == strcmp(scope, opal_info_ver_all)) { snprintf(temp, BUFSIZ - 1, "%d.%d.%d", major, minor, release); str = strdup(temp); if (NULL != greek) { @@ -1278,11 +1275,8 @@ void opal_info_show_opal_version(const char *scope) char *tmp, *tmp2; opal_asprintf(&tmp, "%s:version:full", opal_info_type_opal); - tmp2 = opal_info_make_version_str(scope, - OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, - OPAL_RELEASE_VERSION, - OPAL_GREEK_VERSION, - OPAL_REPO_REV); + tmp2 = opal_info_make_version_str(scope, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION, OPAL_GREEK_VERSION, OPAL_REPO_REV); opal_info_out("OPAL", tmp, tmp2); free(tmp); free(tmp2); diff --git a/opal/runtime/opal_info_support.h b/opal/runtime/opal_info_support.h index db68e6c497d..b9739b30277 100644 --- a/opal/runtime/opal_info_support.h +++ b/opal/runtime/opal_info_support.h @@ -1,9 +1,9 @@ /* * Copyright (c) 2012-2013 Los Alamos National Security, LLC. * All rights reserved. -* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. -* Copyright (c) 2017 IBM Corporation. All rights reserved. -* $COPYRIGHT$ + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. + * $COPYRIGHT$ * * Additional copyrights may follow * @@ -19,8 +19,8 @@ #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/util/cmd_line.h" #include "opal/mca/base/base.h" +#include "opal/util/cmd_line.h" BEGIN_C_DECLS @@ -43,7 +43,6 @@ extern const char *opal_info_ver_mca; extern const char *opal_info_ver_type; extern const char *opal_info_ver_component; - /* * Component-related functions */ @@ -55,9 +54,7 @@ typedef struct { } opal_info_component_map_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_component_map_t); - -OPAL_DECLSPEC int opal_info_init(int argc, char **argv, - opal_cmd_line_t *opal_info_cmd_line); +OPAL_DECLSPEC int opal_info_init(int argc, char **argv, opal_cmd_line_t *opal_info_cmd_line); OPAL_DECLSPEC void opal_info_finalize(void); @@ -77,10 +74,8 @@ OPAL_DECLSPEC void opal_info_show_path(const char *type, const char *value); OPAL_DECLSPEC void opal_info_do_path(bool want_all, opal_cmd_line_t *cmd_line); -OPAL_DECLSPEC void opal_info_show_mca_params(const char *type, - const char *component, - mca_base_var_info_lvl_t max_level, - bool want_internal); +OPAL_DECLSPEC void opal_info_show_mca_params(const char *type, const char *component, + mca_base_var_info_lvl_t max_level, bool want_internal); OPAL_DECLSPEC void opal_info_show_mca_version(const mca_base_component_t *component, const char *scope, const char *ver_type); @@ -88,13 +83,11 @@ OPAL_DECLSPEC void opal_info_show_mca_version(const mca_base_component_t *compon OPAL_DECLSPEC void opal_info_show_component_version(opal_pointer_array_t *mca_types, opal_pointer_array_t *component_map, const char *type_name, - const char *component_name, - const char *scope, const char *ver_type); + const char *component_name, const char *scope, + const char *ver_type); -OPAL_DECLSPEC char *opal_info_make_version_str(const char *scope, - int major, int minor, int release, - const char *greek, - const char *repo); +OPAL_DECLSPEC char *opal_info_make_version_str(const char *scope, int major, int minor, int release, + const char *greek, const char *repo); OPAL_DECLSPEC void opal_info_show_opal_version(const char *scope); @@ -104,15 +97,15 @@ OPAL_DECLSPEC void opal_info_do_hostname(void); OPAL_DECLSPEC void opal_info_do_type(opal_cmd_line_t *opal_info_cmd_line); -OPAL_DECLSPEC void opal_info_out(const char *pretty_message, const char *plain_message, const char *value); +OPAL_DECLSPEC void opal_info_out(const char *pretty_message, const char *plain_message, + const char *value); -OPAL_DECLSPEC void opal_info_out_int(const char *pretty_message, - const char *plain_message, +OPAL_DECLSPEC void opal_info_out_int(const char *pretty_message, const char *plain_message, int value); -OPAL_DECLSPEC int opal_info_register_project_frameworks (const char *project_name, - mca_base_framework_t **frameworks, - opal_pointer_array_t *component_map); +OPAL_DECLSPEC int opal_info_register_project_frameworks(const char *project_name, + mca_base_framework_t **frameworks, + opal_pointer_array_t *component_map); END_C_DECLS diff --git a/opal/runtime/opal_init.c b/opal/runtime/opal_init.c index 274ed6df71f..57f1ea4e062 100644 --- a/opal/runtime/opal_init.c +++ b/opal/runtime/opal_init.c @@ -36,53 +36,53 @@ /** @file **/ #ifdef HAVE_UNISTD_H -#include +# include #endif #include "opal/include/opal_config.h" -#include "opal/util/malloc.h" -#include "opal/util/arch.h" -#include "opal/util/output.h" -#include "opal/util/show_help.h" -#include "opal/util/proc.h" -#include "opal/memoryhooks/memory.h" +#include "opal/datatype/opal_datatype.h" #include "opal/mca/base/base.h" #include "opal/mca/base/mca_base_var.h" -#include "opal/runtime/opal.h" -#include "opal/util/net.h" -#include "opal/datatype/opal_datatype.h" +#include "opal/mca/hwloc/base/base.h" +#include "opal/mca/if/base/base.h" #include "opal/mca/installdirs/base/base.h" +#include "opal/mca/memchecker/base/base.h" +#include "opal/mca/memcpy/base/base.h" #include "opal/mca/memory/base/base.h" #include "opal/mca/patcher/base/base.h" #include "opal/mca/pmix/base/base.h" -#include "opal/mca/memcpy/base/base.h" -#include "opal/mca/hwloc/base/base.h" #include "opal/mca/reachable/base/base.h" -#include "opal/mca/timer/base/base.h" -#include "opal/mca/memchecker/base/base.h" -#include "opal/mca/if/base/base.h" #include "opal/mca/shmem/base/base.h" #include "opal/mca/threads/threads.h" #include "opal/mca/threads/tsd.h" +#include "opal/mca/timer/base/base.h" +#include "opal/memoryhooks/memory.h" +#include "opal/runtime/opal.h" +#include "opal/util/arch.h" +#include "opal/util/malloc.h" +#include "opal/util/net.h" +#include "opal/util/output.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" -#include "opal/runtime/opal_progress.h" -#include "opal/mca/threads/base/base.h" #include "opal/mca/backtrace/base/base.h" +#include "opal/mca/threads/base/base.h" +#include "opal/runtime/opal_progress.h" #include "opal/util/opal_environ.h" #include "opal/constants.h" #include "opal/util/error.h" #include "opal/util/event.h" -#include "opal/util/stacktrace.h" #include "opal/util/keyval_parse.h" +#include "opal/util/stacktrace.h" #include "opal/util/sys_limits.h" #include "opal/util/timings.h" #if OPAL_CC_USE_PRAGMA_IDENT -#pragma ident OPAL_IDENT_STRING +# pragma ident OPAL_IDENT_STRING #elif OPAL_CC_USE_IDENT -#ident OPAL_IDENT_STRING +# ident OPAL_IDENT_STRING #endif const char opal_version_string[] = OPAL_IDENT_STRING; @@ -98,7 +98,7 @@ bool opal_warn_on_fork = true; /* If there is a preprocessor macro that redefined the call to * gethostname, we undefine that here */ #ifdef gethostname -#undef gethostname +# undef gethostname #endif #define NUM_TRIES_FOR_NULL_HOSTNAME 8 @@ -115,26 +115,26 @@ int opal_init_gethostname(void) size_t count, length = OPAL_LOCAL_MAXHOSTNAMELEN; int ret_val, num_tries = 0; - char *buf = calloc( 1, length ); - if( NULL == buf ) { + char *buf = calloc(1, length); + if (NULL == buf) { return OPAL_ERR_OUT_OF_RESOURCE; } - while( num_tries < NUM_TRIES_FOR_NULL_HOSTNAME) { + while (num_tries < NUM_TRIES_FOR_NULL_HOSTNAME) { ++num_tries; /* * Offer all but the last byte of the buffer to gethostname. */ - ret_val = gethostname( buf, length - 1 ); + ret_val = gethostname(buf, length - 1); /* * Terminate the buffer in the last position. */ buf[length - 1] = '\0'; - if( 0 == ret_val ) { - count = strlen( buf ); + if (0 == ret_val) { + count = strlen(buf); /* The result was not truncated */ - if( count > 0 && count < length - 1 ) { + if (count > 0 && count < length - 1) { /* * If we got a good result, save it. This value may * be longer than what callers to opal_gethostname() @@ -158,7 +158,7 @@ int opal_init_gethostname(void) * If it's not one of these good cases, it's an error: * return. */ - else if( !(0 == count || count == length - 1) ) { + else if (!(0 == count || count == length - 1)) { free(buf); return OPAL_ERR_IN_ERRNO; } @@ -175,7 +175,7 @@ int opal_init_gethostname(void) * * If it's not one of these good cases, it's an error: return. */ - else if( !(EINVAL == errno || ENAMETOOLONG == errno) ) { + else if (!(EINVAL == errno || ENAMETOOLONG == errno)) { free(buf); return OPAL_ERR_IN_ERRNO; } @@ -185,8 +185,8 @@ int opal_init_gethostname(void) * the buffer and try again. */ length *= 2; - buf = realloc( buf, length ); - if( NULL == buf ) { + buf = realloc(buf, length); + if (NULL == buf) { return OPAL_ERR_OUT_OF_RESOURCE; } } /* end while */ @@ -197,8 +197,7 @@ int opal_init_gethostname(void) return OPAL_ERR_NOT_FOUND; } -static int -opal_err2str(int errnum, const char **errmsg) +static int opal_err2str(int errnum, const char **errmsg) { const char *retval; @@ -422,7 +421,6 @@ opal_err2str(int errnum, const char **errmsg) return OPAL_SUCCESS; } - int opal_init_psm(void) { /* Very early in the init sequence -- before *ANY* MCA components @@ -450,39 +448,38 @@ int opal_init_psm(void) return OPAL_SUCCESS; } -static int opal_init_error (const char *error, int ret) +static int opal_init_error(const char *error, int ret) { if (OPAL_ERR_SILENT != ret) { - opal_show_help( "help-opal-runtime.txt", - "opal_init:startup:internal-failure", true, - error, ret ); + opal_show_help("help-opal-runtime.txt", "opal_init:startup:internal-failure", true, error, + ret); } return ret; } static mca_base_framework_t *opal_init_util_frameworks[] = { - &opal_installdirs_base_framework, &opal_if_base_framework, NULL, + &opal_installdirs_base_framework, + &opal_if_base_framework, + NULL, }; -int -opal_init_util(int* pargc, char*** pargv) +int opal_init_util(int *pargc, char ***pargv) { int ret; char *error = NULL; OPAL_TIMING_ENV_INIT(otmng); - if( opal_util_initialized != 0 ) { - if( opal_util_initialized < 0 ) { + if (opal_util_initialized != 0) { + if (opal_util_initialized < 0) { return OPAL_ERROR; } ++opal_util_initialized; return OPAL_SUCCESS; } - OBJ_CONSTRUCT(&opal_init_util_domain, opal_finalize_domain_t); - (void) opal_finalize_domain_init (&opal_init_util_domain, "opal_init_util"); - opal_finalize_set_domain (&opal_init_util_domain); + (void) opal_finalize_domain_init(&opal_init_util_domain, "opal_init_util"); + opal_finalize_set_domain(&opal_init_util_domain); opal_thread_set_main(); @@ -494,7 +491,9 @@ opal_init_util(int* pargc, char*** pargv) * requests it */ ret = opal_init_gethostname(); if (OPAL_SUCCESS != ret) { - fprintf(stderr, "opal_init_gethostname() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_SUCCESS)\n", + fprintf(stderr, + "opal_init_gethostname() failed -- process will likely abort (%s:%d, returned %d " + "instead of OPAL_SUCCESS)\n", __FILE__, __LINE__, ret); return ret; } @@ -509,7 +508,9 @@ opal_init_util(int* pargc, char*** pargv) /* initialize install dirs code */ if (OPAL_SUCCESS != (ret = mca_base_framework_open(&opal_installdirs_base_framework, 0))) { - fprintf(stderr, "opal_installdirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_SUCCESS)\n", + fprintf(stderr, + "opal_installdirs_base_open() failed -- process will likely abort (%s:%d, returned " + "%d instead of OPAL_SUCCESS)\n", __FILE__, __LINE__, ret); return ret; } @@ -520,15 +521,14 @@ opal_init_util(int* pargc, char*** pargv) OPAL_TIMING_ENV_NEXT(otmng, "opal_show_help_init"); /* register handler for errnum -> string converstion */ - if (OPAL_SUCCESS != - (ret = opal_error_register("OPAL", - OPAL_ERR_BASE, OPAL_ERR_MAX, opal_err2str))) { - return opal_init_error ("opal_error_register", ret); + if (OPAL_SUCCESS + != (ret = opal_error_register("OPAL", OPAL_ERR_BASE, OPAL_ERR_MAX, opal_err2str))) { + return opal_init_error("opal_error_register", ret); } /* keyval lex-based parser */ if (OPAL_SUCCESS != (ret = opal_util_keyval_parse_init())) { - return opal_init_error ("opal_util_keyval_parse_init", ret); + return opal_init_error("opal_util_keyval_parse_init", ret); } // Disable PSM signal hijacking (see comment in function for more @@ -539,74 +539,73 @@ opal_init_util(int* pargc, char*** pargv) /* Setup the parameter system */ if (OPAL_SUCCESS != (ret = mca_base_var_init())) { - return opal_init_error ("mca_base_var_init", ret); + return opal_init_error("mca_base_var_init", ret); } OPAL_TIMING_ENV_NEXT(otmng, "opal_var_init"); /* read any param files that were provided */ if (OPAL_SUCCESS != (ret = mca_base_var_cache_files(false))) { - return opal_init_error ("failed to cache files", ret); + return opal_init_error("failed to cache files", ret); } OPAL_TIMING_ENV_NEXT(otmng, "opal_var_cache"); - /* register params for opal */ if (OPAL_SUCCESS != (ret = opal_register_params())) { - return opal_init_error ("opal_register_params", ret); + return opal_init_error("opal_register_params", ret); } if (OPAL_SUCCESS != (ret = opal_net_init())) { - return opal_init_error ("opal_net_init", ret); + return opal_init_error("opal_net_init", ret); } OPAL_TIMING_ENV_NEXT(otmng, "opal_net_init"); /* pretty-print stack handlers */ if (OPAL_SUCCESS != (ret = opal_util_register_stackhandlers())) { - return opal_init_error ("opal_util_register_stackhandlers", ret); + return opal_init_error("opal_util_register_stackhandlers", ret); } /* set system resource limits - internally protected against * doing so twice in cases where the launch agent did it for us */ if (OPAL_SUCCESS != (ret = opal_util_init_sys_limits(&error))) { - opal_show_help("help-opal-runtime.txt", - "opal_init:syslimit", false, - error); + opal_show_help("help-opal-runtime.txt", "opal_init:syslimit", false, error); return OPAL_ERR_SILENT; } /* initialize the arch string */ - if (OPAL_SUCCESS != (ret = opal_arch_init ())) { - return opal_init_error ("opal_arch_init", ret); + if (OPAL_SUCCESS != (ret = opal_arch_init())) { + return opal_init_error("opal_arch_init", ret); } OPAL_TIMING_ENV_NEXT(otmng, "opal_arch_init"); /* initialize the datatype engine */ - if (OPAL_SUCCESS != (ret = opal_datatype_init ())) { - return opal_init_error ("opal_datatype_init", ret); + if (OPAL_SUCCESS != (ret = opal_datatype_init())) { + return opal_init_error("opal_datatype_init", ret); } OPAL_TIMING_ENV_NEXT(otmng, "opal_datatype_init"); /* initialize the mca */ if (OPAL_SUCCESS != (ret = mca_base_open())) { - return opal_init_error ("mca_base_open", ret); + return opal_init_error("mca_base_open", ret); } OPAL_TIMING_ENV_NEXT(otmng, "mca_base_open"); /* initialize if framework */ if (OPAL_SUCCESS != (ret = mca_base_framework_open(&opal_if_base_framework, 0))) { - fprintf(stderr, "opal_if_base_open() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_SUCCESS)\n", + fprintf(stderr, + "opal_if_base_open() failed -- process will likely abort (%s:%d, returned %d " + "instead of OPAL_SUCCESS)\n", __FILE__, __LINE__, ret); return ret; } /* register for */ - opal_finalize_register_cleanup_arg (mca_base_framework_close_list, opal_init_util_frameworks); + opal_finalize_register_cleanup_arg(mca_base_framework_close_list, opal_init_util_frameworks); OPAL_TIMING_ENV_NEXT(otmng, "opal_if_init"); @@ -615,25 +614,24 @@ opal_init_util(int* pargc, char*** pargv) return OPAL_SUCCESS; } - /* the memcpy component should be one of the first who get * loaded in order to make sure we have all the available * versions of memcpy correctly configured. */ static mca_base_framework_t *opal_init_frameworks[] = { - &opal_threads_base_framework, &opal_hwloc_base_framework, &opal_memcpy_base_framework, &opal_memchecker_base_framework, + &opal_threads_base_framework, &opal_hwloc_base_framework, + &opal_memcpy_base_framework, &opal_memchecker_base_framework, &opal_backtrace_base_framework, &opal_timer_base_framework, - &opal_shmem_base_framework, &opal_reachable_base_framework, &opal_pmix_base_framework, - NULL, + &opal_shmem_base_framework, &opal_reachable_base_framework, + &opal_pmix_base_framework, NULL, }; -int -opal_init(int* pargc, char*** pargv) +int opal_init(int *pargc, char ***pargv) { int ret; - if( opal_initialized != 0 ) { - if( opal_initialized < 0 ) { + if (opal_initialized != 0) { + if (opal_initialized < 0) { return OPAL_ERROR; } ++opal_initialized; @@ -646,14 +644,14 @@ opal_init(int* pargc, char*** pargv) } OBJ_CONSTRUCT(&opal_init_domain, opal_finalize_domain_t); - (void) opal_finalize_domain_init (&opal_init_domain, "opal_init"); - opal_finalize_set_domain (&opal_init_domain); + (void) opal_finalize_domain_init(&opal_init_domain, "opal_init"); + opal_finalize_set_domain(&opal_init_domain); - opal_finalize_register_cleanup_arg (mca_base_framework_close_list, opal_init_frameworks); + opal_finalize_register_cleanup_arg(mca_base_framework_close_list, opal_init_frameworks); - ret = mca_base_framework_open_list (opal_init_frameworks, 0); + ret = mca_base_framework_open_list(opal_init_frameworks, 0); if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) { - return opal_init_error ("opal_init framework open", ret); + return opal_init_error("opal_init framework open", ret); } /* initialize libevent */ @@ -663,31 +661,31 @@ opal_init(int* pargc, char*** pargv) /* initialize the memory manager / tracker */ if (OPAL_SUCCESS != (ret = opal_mem_hooks_init())) { - return opal_init_error ("opal_mem_hooks_init", ret); + return opal_init_error("opal_mem_hooks_init", ret); } /* select the memory checker */ if (OPAL_SUCCESS != (ret = opal_memchecker_base_select())) { - return opal_init_error ("opal_memchecker_base_select", ret); + return opal_init_error("opal_memchecker_base_select", ret); } /* * Initialize the general progress engine */ if (OPAL_SUCCESS != (ret = opal_progress_init())) { - return opal_init_error ("opal_progress_init", ret); + return opal_init_error("opal_progress_init", ret); } /* we want to tick the event library whenever possible */ opal_progress_event_users_increment(); /* setup the shmem framework */ if (OPAL_SUCCESS != (ret = opal_shmem_base_select())) { - return opal_init_error ("opal_shmem_base_select", ret); + return opal_init_error("opal_shmem_base_select", ret); } /* Intitialize reachable framework */ if (OPAL_SUCCESS != (ret = opal_reachable_base_select())) { - return opal_init_error ("opal_reachable_base_select", ret); + return opal_init_error("opal_reachable_base_select", ret); } ++opal_initialized; diff --git a/opal/runtime/opal_params.c b/opal/runtime/opal_params.c index 84c9c4a4b1f..93896defc98 100644 --- a/opal/runtime/opal_params.c +++ b/opal/runtime/opal_params.c @@ -33,22 +33,21 @@ #include "opal_config.h" -#include #include +#include #include "opal/constants.h" -#include "opal/runtime/opal.h" #include "opal/datatype/opal_datatype.h" #include "opal/mca/base/mca_base_var.h" +#include "opal/mca/shmem/base/base.h" #include "opal/mca/threads/mutex.h" #include "opal/mca/threads/threads.h" -#include "opal/mca/shmem/base/base.h" -#include "opal/mca/base/mca_base_var.h" +#include "opal/runtime/opal.h" #include "opal/runtime/opal_params.h" #include "opal/util/opal_environ.h" +#include "opal/util/printf.h" #include "opal/util/show_help.h" #include "opal/util/timings.h" -#include "opal/util/printf.h" char *opal_signal_string = NULL; char *opal_stacktrace_output_filename = NULL; @@ -77,7 +76,7 @@ int opal_max_thread_in_progress = 1; static bool opal_register_done = false; -static void opal_deregister_params (void) +static void opal_deregister_params(void) { /* The MCA variable system will be torn down shortly so reset the registered * flag. */ @@ -113,9 +112,8 @@ int opal_register_params(void) #ifdef SIGSEGV SIGSEGV, #endif - -1 - }; - for (j = 0 ; signals[j] != -1 ; ++j) { + -1}; + for (j = 0; signals[j] != -1; ++j) { if (j == 0) { opal_asprintf(&string, "%d", signals[j]); } else { @@ -127,12 +125,17 @@ int opal_register_params(void) } opal_signal_string = string; - ret = mca_base_var_register ("opal", "opal", NULL, "signal", - "Comma-delimited list of integer signal numbers to Open MPI to attempt to intercept. Upon receipt of the intercepted signal, Open MPI will display a stack trace and abort. Open MPI will *not* replace signals if handlers are already installed by the time MPI_INIT is invoked. Optionally append \":complain\" to any signal number in the comma-delimited list to make Open MPI complain if it detects another signal handler (and therefore does not insert its own).", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_signal_string); - free (string); + ret = mca_base_var_register( + "opal", "opal", NULL, "signal", + "Comma-delimited list of integer signal numbers to Open MPI to attempt to intercept. " + "Upon receipt of the intercepted signal, Open MPI will display a stack trace and " + "abort. Open MPI will *not* replace signals if handlers are already installed by the " + "time MPI_INIT is invoked. Optionally append \":complain\" to any signal number in " + "the comma-delimited list to make Open MPI complain if it detects another signal " + "handler (and therefore does not insert its own).", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_signal_string); + free(string); if (0 > ret) { return ret; } @@ -144,49 +147,47 @@ int opal_register_params(void) */ string = strdup("stderr"); opal_stacktrace_output_filename = string; - ret = mca_base_var_register ("opal", "opal", NULL, "stacktrace_output", - "Specifies where the stack trace output stream goes. " - "Accepts one of the following: none (disabled), stderr (default), stdout, file[:filename]. " - "If 'filename' is not specified, a default filename of 'stacktrace' is used. " - "The 'filename' is appended with either '.PID' or '.RANK.PID', if RANK is available. " - "The 'filename' can be an absolute path or a relative path to the current working directory.", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - &opal_stacktrace_output_filename); - free (string); + ret = mca_base_var_register( + "opal", "opal", NULL, "stacktrace_output", + "Specifies where the stack trace output stream goes. " + "Accepts one of the following: none (disabled), stderr (default), stdout, file[:filename]. " + " " + "If 'filename' is not specified, a default filename of 'stacktrace' is used. " + "The 'filename' is appended with either '.PID' or '.RANK.PID', if RANK is available. " + "The 'filename' can be an absolute path or a relative path to the current working " + "directory.", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_stacktrace_output_filename); + free(string); if (0 > ret) { return ret; } - #if defined(HAVE_SCHED_YIELD) opal_progress_yield_when_idle = false; - ret = mca_base_var_register ("opal", "opal", "progress", "yield_when_idle", - "Yield the processor when waiting on progress", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_progress_yield_when_idle); + ret = mca_base_var_register("opal", "opal", "progress", "yield_when_idle", + "Yield the processor when waiting on progress", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, + OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, + &opal_progress_yield_when_idle); #endif #if OPAL_ENABLE_DEBUG opal_progress_debug = false; - ret = mca_base_var_register ("opal", "opal", "progress", "debug", - "Set to non-zero to debug progress engine features", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_progress_debug); + ret = mca_base_var_register("opal", "opal", "progress", "debug", + "Set to non-zero to debug progress engine features", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, + OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, &opal_progress_debug); if (0 > ret) { return ret; } opal_debug_threads = false; - ret = mca_base_var_register ("opal", "opal", "debug", "threads", - "Debug thread usage within OPAL. Reports out " - "when threads are acquired and released.", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, - &opal_debug_threads); + ret = mca_base_var_register("opal", "opal", "debug", "threads", + "Debug thread usage within OPAL. Reports out " + "when threads are acquired and released.", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, + OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL, &opal_debug_threads); if (0 > ret) { return ret; } @@ -201,22 +202,23 @@ int opal_register_params(void) - 169.254.0.0/16 for DHCP onlink iff there's no DHCP server */ opal_net_private_ipv4 = "10.0.0.0/8;172.16.0.0/12;192.168.0.0/16;169.254.0.0/16"; - ret = mca_base_var_register ("opal", "opal", "net", "private_ipv4", - "Semicolon-delimited list of CIDR notation entries specifying what networks are considered \"private\" (default value based on RFC1918 and RFC3330)", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_net_private_ipv4); + ret = mca_base_var_register( + "opal", "opal", "net", "private_ipv4", + "Semicolon-delimited list of CIDR notation entries specifying what networks are considered " + "\"private\" (default value based on RFC1918 and RFC3330)", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_net_private_ipv4); if (0 > ret) { return ret; } opal_set_max_sys_limits = NULL; - ret = mca_base_var_register ("opal", "opal", NULL, "set_max_sys_limits", - "Set the specified system-imposed limits to the specified value, including \"unlimited\"." - "Supported params: core, filesize, maxmem, openfiles, stacksize, maxchildren", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_set_max_sys_limits); + ret = mca_base_var_register( + "opal", "opal", NULL, "set_max_sys_limits", + "Set the specified system-imposed limits to the specified value, including \"unlimited\"." + "Supported params: core, filesize, maxmem, openfiles, stacksize, maxchildren", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_set_max_sys_limits); if (0 > ret) { return ret; } @@ -232,100 +234,96 @@ int opal_register_params(void) /* Current default is to enable CUDA support if it is built into library */ opal_cuda_support = opal_built_with_cuda_support; - ret = mca_base_var_register ("opal", "opal", NULL, "cuda_support", - "Whether CUDA GPU buffer support is enabled or not", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_cuda_support); + ret = mca_base_var_register("opal", "opal", NULL, "cuda_support", + "Whether CUDA GPU buffer support is enabled or not", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, + OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_cuda_support); if (0 > ret) { return ret; } opal_warn_on_missing_libcuda = true; - ret = mca_base_var_register ("opal", "opal", NULL, "warn_on_missing_libcuda", - "Whether to print a message when CUDA support is enabled but libcuda is not found", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_ALL_EQ, - &opal_warn_on_missing_libcuda); + ret = mca_base_var_register( + "opal", "opal", NULL, "warn_on_missing_libcuda", + "Whether to print a message when CUDA support is enabled but libcuda is not found", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_ALL_EQ, &opal_warn_on_missing_libcuda); if (0 > ret) { return ret; } /* Leave pinned parameter */ opal_leave_pinned = -1; - ret = mca_base_var_register("ompi", "mpi", NULL, "leave_pinned", - "Whether to use the \"leave pinned\" protocol or not. Enabling this setting can help bandwidth performance when repeatedly sending and receiving large messages with the same buffers over RDMA-based networks (false = do not use \"leave pinned\" protocol, true = use \"leave pinned\" protocol, auto = allow network to choose at runtime).", - MCA_BASE_VAR_TYPE_INT, &mca_base_var_enum_auto_bool, 0, 0, - OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY, - &opal_leave_pinned); + ret = mca_base_var_register( + "ompi", "mpi", NULL, "leave_pinned", + "Whether to use the \"leave pinned\" protocol or not. Enabling this setting can help " + "bandwidth performance when repeatedly sending and receiving large messages with the same " + "buffers over RDMA-based networks (false = do not use \"leave pinned\" protocol, true = " + "use \"leave pinned\" protocol, auto = allow network to choose at runtime).", + MCA_BASE_VAR_TYPE_INT, &mca_base_var_enum_auto_bool, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &opal_leave_pinned); mca_base_var_register_synonym(ret, "opal", "opal", NULL, "leave_pinned", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); opal_leave_pinned_pipeline = false; ret = mca_base_var_register("ompi", "mpi", NULL, "leave_pinned_pipeline", "Whether to use the \"leave pinned pipeline\" protocol or not.", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &opal_leave_pinned_pipeline); + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &opal_leave_pinned_pipeline); mca_base_var_register_synonym(ret, "opal", "opal", NULL, "leave_pinned_pipeline", MCA_BASE_VAR_SYN_FLAG_DEPRECATED); if (opal_leave_pinned > 0 && opal_leave_pinned_pipeline) { opal_leave_pinned_pipeline = 0; - opal_show_help("help-opal-runtime.txt", - "mpi-params:leave-pinned-and-pipeline-selected", + opal_show_help("help-opal-runtime.txt", "mpi-params:leave-pinned-and-pipeline-selected", true); } opal_warn_on_fork = true; (void) mca_base_var_register("ompi", "mpi", NULL, "warn_on_fork", - "If nonzero, issue a warning if program forks under conditions that could cause system errors", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, - OPAL_INFO_LVL_9, - MCA_BASE_VAR_SCOPE_READONLY, - &opal_warn_on_fork); + "If nonzero, issue a warning if program forks under conditions " + "that could cause system errors", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0, OPAL_INFO_LVL_9, + MCA_BASE_VAR_SCOPE_READONLY, &opal_warn_on_fork); opal_abort_delay = 0; - ret = mca_base_var_register("opal", "opal", NULL, "abort_delay", - "If nonzero, print out an identifying message when abort operation is invoked (hostname, PID of the process that called abort) and delay for that many seconds before exiting (a negative delay value means to never abort). This allows attaching of a debugger before quitting the job.", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, - &opal_abort_delay); + ret = mca_base_var_register( + "opal", "opal", NULL, "abort_delay", + "If nonzero, print out an identifying message when abort operation is invoked (hostname, " + "PID of the process that called abort) and delay for that many seconds before exiting (a " + "negative delay value means to never abort). This allows attaching of a debugger before " + "quitting the job.", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, + &opal_abort_delay); if (0 > ret) { return ret; } opal_abort_print_stack = false; ret = mca_base_var_register("opal", "opal", NULL, "abort_print_stack", - "If nonzero, print out a stack trace when abort is invoked", - MCA_BASE_VAR_TYPE_BOOL, NULL, 0, - /* If we do not have stack trace - capability, make this a constant - MCA variable */ + "If nonzero, print out a stack trace when abort is invoked", + MCA_BASE_VAR_TYPE_BOOL, NULL, 0, + /* If we do not have stack trace + capability, make this a constant + MCA variable */ #if OPAL_WANT_PRETTY_PRINT_STACKTRACE - 0, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, + 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, #else - MCA_BASE_VAR_FLAG_DEFAULT_ONLY, - OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_CONSTANT, + MCA_BASE_VAR_FLAG_DEFAULT_ONLY, OPAL_INFO_LVL_5, + MCA_BASE_VAR_SCOPE_CONSTANT, #endif - &opal_abort_print_stack); + &opal_abort_print_stack); if (0 > ret) { return ret; } /* register the envar-forwarding params */ - (void)mca_base_var_register ("opal", "mca", "base", "env_list", - "Set SHELL env variables", + (void) mca_base_var_register("opal", "mca", "base", "env_list", "Set SHELL env variables", MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY, &mca_base_env_list); mca_base_env_list_sep = MCA_BASE_ENV_LIST_SEP_DEFAULT; - (void)mca_base_var_register ("opal", "mca", "base", "env_list_delimiter", + (void) mca_base_var_register("opal", "mca", "base", "env_list_delimiter", "Set SHELL env variables delimiter. Default: semicolon ';'", MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0, OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY, &mca_base_env_list_sep); @@ -337,7 +335,7 @@ int opal_register_params(void) */ if (NULL != mca_base_env_list) { char *name = NULL; - (void) mca_base_var_env_name ("mca_base_env_list", &name); + (void) mca_base_var_env_name("mca_base_env_list", &name); if (NULL != name) { opal_setenv(name, mca_base_env_list, false, &environ); free(name); @@ -348,16 +346,17 @@ int opal_register_params(void) * parsing of amca conf file and contains SHELL env variables specified via -x there. * Its format is the same as for mca_base_env_list. */ - (void)mca_base_var_register ("opal", "mca", "base", "env_list_internal", - "Store SHELL env variables from amca conf file", - MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_READONLY, &mca_base_env_list_internal); + (void) mca_base_var_register("opal", "mca", "base", "env_list_internal", + "Store SHELL env variables from amca conf file", + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_INTERNAL, + OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY, + &mca_base_env_list_internal); /* Number of threads allowed in opal_progress. This might increase multithreaded performance. */ - (void)mca_base_var_register ("opal", "opal", NULL, "max_thread_in_progress", - "Number of thread allowed in opal_progress. Default: 1", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_8, - MCA_BASE_VAR_SCOPE_READONLY, &opal_max_thread_in_progress); + (void) mca_base_var_register("opal", "opal", NULL, "max_thread_in_progress", + "Number of thread allowed in opal_progress. Default: 1", + MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_8, + MCA_BASE_VAR_SCOPE_READONLY, &opal_max_thread_in_progress); /* The ddt engine has a few parameters */ ret = opal_datatype_register_params(); @@ -370,7 +369,7 @@ int opal_register_params(void) return ret; } - opal_finalize_register_cleanup (opal_deregister_params); + opal_finalize_register_cleanup(opal_deregister_params); return OPAL_SUCCESS; } diff --git a/opal/runtime/opal_params.h b/opal/runtime/opal_params.h index 24b15973487..d5d63cb933c 100644 --- a/opal/runtime/opal_params.h +++ b/opal/runtime/opal_params.h @@ -27,18 +27,18 @@ */ #if !defined(OPAL_PARAMS_H) -#define OPAL_PARAMS_H +# define OPAL_PARAMS_H extern char *opal_signal_string; extern char *opal_stacktrace_output_filename; extern char *opal_net_private_ipv4; extern char *opal_set_max_sys_limits; -#if OPAL_ENABLE_TIMING +# if OPAL_ENABLE_TIMING extern char *opal_timing_sync_file; extern char *opal_timing_output; extern bool opal_timing_overhead; -#endif +# endif OPAL_DECLSPEC extern int opal_initialized; OPAL_DECLSPEC extern bool opal_built_with_cuda_support; @@ -80,8 +80,8 @@ OPAL_DECLSPEC extern bool opal_abort_print_stack; */ OPAL_DECLSPEC extern int opal_abort_delay; -#if OPAL_ENABLE_DEBUG +# if OPAL_ENABLE_DEBUG extern bool opal_progress_debug; -#endif +# endif #endif diff --git a/opal/runtime/opal_progress.c b/opal/runtime/opal_progress.c index 0ba1e1ff007..cf50d6bb6f9 100644 --- a/opal/runtime/opal_progress.c +++ b/opal/runtime/opal_progress.c @@ -27,17 +27,17 @@ #include "opal_config.h" -#include "opal/runtime/opal_progress.h" -#include "opal/util/event.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/constants.h" +#include "opal/mca/base/mca_base_var.h" +#include "opal/mca/threads/threads.h" #include "opal/mca/timer/base/base.h" -#include "opal/util/output.h" -#include "opal/runtime/opal_params.h" #include "opal/runtime/opal.h" -#include "opal/mca/threads/threads.h" +#include "opal/runtime/opal_params.h" +#include "opal/runtime/opal_progress.h" +#include "opal/util/event.h" +#include "opal/util/output.h" -#define OPAL_PROGRESS_USE_TIMERS (OPAL_TIMER_CYCLE_SUPPORTED || OPAL_TIMER_USEC_SUPPORTED) +#define OPAL_PROGRESS_USE_TIMERS (OPAL_TIMER_CYCLE_SUPPORTED || OPAL_TIMER_USEC_SUPPORTED) #define OPAL_PROGRESS_ONLY_USEC_NATIVE (OPAL_TIMER_USEC_NATIVE && !OPAL_TIMER_CYCLE_NATIVE) #if OPAL_ENABLE_DEBUG @@ -50,7 +50,6 @@ bool opal_progress_debug = false; static int opal_progress_event_flag = OPAL_EVLOOP_ONCE | OPAL_EVLOOP_NONBLOCK; int opal_progress_spin_count = 10000; - /* * Local variables */ @@ -93,33 +92,35 @@ static int debug_output = -1; * writing a pointer is atomic, we should not have any more * problems. */ -static int fake_cb(void) { return 0; } +static int fake_cb(void) +{ + return 0; +} -static int _opal_progress_unregister (opal_progress_callback_t cb, volatile opal_progress_callback_t *callback_array, - size_t *callback_array_len); +static int _opal_progress_unregister(opal_progress_callback_t cb, + volatile opal_progress_callback_t *callback_array, + size_t *callback_array_len); -static void opal_progress_finalize (void) +static void opal_progress_finalize(void) { /* free memory associated with the callbacks */ opal_atomic_lock(&progress_lock); callbacks_len = 0; callbacks_size = 0; - free ((void *) callbacks); + free((void *) callbacks); callbacks = NULL; callbacks_lp_len = 0; callbacks_lp_size = 0; - free ((void *) callbacks_lp); + free((void *) callbacks_lp); callbacks_lp = NULL; opal_atomic_unlock(&progress_lock); } - /* init the progress engine - called from orte_init */ -int -opal_progress_init(void) +int opal_progress_init(void) { /* reentrant issues */ opal_atomic_lock_init(&progress_lock, OPAL_ATOMIC_LOCK_UNLOCKED); @@ -129,41 +130,40 @@ opal_progress_init(void) #if OPAL_ENABLE_DEBUG if (opal_progress_debug) { - debug_output = opal_output_open(NULL); + debug_output = opal_output_open(NULL); } #endif callbacks_size = callbacks_lp_size = 8; - callbacks = malloc (callbacks_size * sizeof (callbacks[0])); - callbacks_lp = malloc (callbacks_lp_size * sizeof (callbacks_lp[0])); + callbacks = malloc(callbacks_size * sizeof(callbacks[0])); + callbacks_lp = malloc(callbacks_lp_size * sizeof(callbacks_lp[0])); if (NULL == callbacks || NULL == callbacks_lp) { - free ((void *) callbacks); - free ((void *) callbacks_lp); + free((void *) callbacks); + free((void *) callbacks_lp); callbacks_size = callbacks_lp_size = 0; callbacks = callbacks_lp = NULL; return OPAL_ERR_OUT_OF_RESOURCE; } - for (size_t i = 0 ; i < callbacks_size ; ++i) { + for (size_t i = 0; i < callbacks_size; ++i) { callbacks[i] = fake_cb; } - for (size_t i = 0 ; i < callbacks_lp_size ; ++i) { + for (size_t i = 0; i < callbacks_lp_size; ++i) { callbacks_lp[i] = fake_cb; } - OPAL_OUTPUT((debug_output, "progress: initialized event flag to: %x", - opal_progress_event_flag)); + OPAL_OUTPUT( + (debug_output, "progress: initialized event flag to: %x", opal_progress_event_flag)); OPAL_OUTPUT((debug_output, "progress: initialized yield_when_idle to: %s", opal_progress_yield_when_idle ? "true" : "false")); - OPAL_OUTPUT((debug_output, "progress: initialized num users to: %d", - num_event_users)); - OPAL_OUTPUT((debug_output, "progress: initialized poll rate to: %ld", - (long) event_progress_delta)); + OPAL_OUTPUT((debug_output, "progress: initialized num users to: %d", num_event_users)); + OPAL_OUTPUT( + (debug_output, "progress: initialized poll rate to: %ld", (long) event_progress_delta)); - opal_finalize_register_cleanup (opal_progress_finalize); + opal_finalize_register_cleanup(opal_progress_finalize); return OPAL_SUCCESS; } @@ -173,29 +173,27 @@ static int opal_progress_events(void) static opal_atomic_int32_t lock = 0; int events = 0; - if( opal_progress_event_flag != 0 && !OPAL_THREAD_SWAP_32(&lock, 1) ) { + if (opal_progress_event_flag != 0 && !OPAL_THREAD_SWAP_32(&lock, 1)) { #if OPAL_PROGRESS_USE_TIMERS -#if OPAL_PROGRESS_ONLY_USEC_NATIVE +# if OPAL_PROGRESS_ONLY_USEC_NATIVE opal_timer_t now = opal_timer_base_get_usec(); -#else +# else opal_timer_t now = opal_timer_base_get_cycles(); -#endif /* OPAL_PROGRESS_ONLY_USEC_NATIVE */ - /* trip the event library if we've reached our tick rate and we are - enabled */ - if (now - event_progress_last_time > event_progress_delta ) { - event_progress_last_time = (num_event_users > 0) ? - now - event_progress_delta : now; - - events += opal_event_loop(opal_sync_event_base, opal_progress_event_flag); +# endif /* OPAL_PROGRESS_ONLY_USEC_NATIVE */ + /* trip the event library if we've reached our tick rate and we are + enabled */ + if (now - event_progress_last_time > event_progress_delta) { + event_progress_last_time = (num_event_users > 0) ? now - event_progress_delta : now; + + events += opal_event_loop(opal_sync_event_base, opal_progress_event_flag); } #else /* OPAL_PROGRESS_USE_TIMERS */ - /* trip the event library if we've reached our tick rate and we are - enabled */ - if (OPAL_THREAD_ADD_FETCH32(&event_progress_counter, -1) <= 0 ) { - event_progress_counter = - (num_event_users > 0) ? 0 : event_progress_delta; - events += opal_event_loop(opal_sync_event_base, opal_progress_event_flag); + /* trip the event library if we've reached our tick rate and we are + enabled */ + if (OPAL_THREAD_ADD_FETCH32(&event_progress_counter, -1) <= 0) { + event_progress_counter = (num_event_users > 0) ? 0 : event_progress_delta; + events += opal_event_loop(opal_sync_event_base, opal_progress_event_flag); } #endif /* OPAL_PROGRESS_USE_TIMERS */ lock = 0; @@ -215,15 +213,14 @@ static int opal_progress_events(void) * care, as the cost of that happening is far outweighed by the cost * of the if checks (they were resulting in bad pipe stalling behavior) */ -void -opal_progress(void) +void opal_progress(void) { static uint32_t num_calls = 0; size_t i; int events = 0; /* progress all registered callbacks */ - for (i = 0 ; i < callbacks_len ; ++i) { + for (i = 0; i < callbacks_len; ++i) { events += (callbacks[i])(); } @@ -234,7 +231,7 @@ opal_progress(void) * it's not a problem. */ if (((num_calls++) & 0x7) == 0) { - for (i = 0 ; i < callbacks_lp_len ; ++i) { + for (i = 0; i < callbacks_lp_len; ++i) { events += (callbacks_lp[i])(); } @@ -255,9 +252,7 @@ opal_progress(void) } } - -int -opal_progress_set_event_flag(int flag) +int opal_progress_set_event_flag(int flag) { int tmp = opal_progress_event_flag; opal_progress_event_flag = flag; @@ -267,9 +262,7 @@ opal_progress_set_event_flag(int flag) return tmp; } - -void -opal_progress_event_users_increment(void) +void opal_progress_event_users_increment(void) { #if OPAL_ENABLE_DEBUG int32_t val; @@ -277,7 +270,7 @@ opal_progress_event_users_increment(void) OPAL_OUTPUT((debug_output, "progress: event_users_increment setting count to %d", val)); #else - (void)opal_atomic_add_fetch_32(&num_event_users, 1); + (void) opal_atomic_add_fetch_32(&num_event_users, 1); #endif #if OPAL_PROGRESS_USE_TIMERS @@ -289,53 +282,47 @@ opal_progress_event_users_increment(void) #endif } - -void -opal_progress_event_users_decrement(void) +void opal_progress_event_users_decrement(void) { -#if OPAL_ENABLE_DEBUG || ! OPAL_PROGRESS_USE_TIMERS +#if OPAL_ENABLE_DEBUG || !OPAL_PROGRESS_USE_TIMERS int32_t val; val = opal_atomic_sub_fetch_32(&num_event_users, 1); OPAL_OUTPUT((debug_output, "progress: event_users_decrement setting count to %d", val)); #else - (void)opal_atomic_sub_fetch_32(&num_event_users, 1); + (void) opal_atomic_sub_fetch_32(&num_event_users, 1); #endif #if !OPAL_PROGRESS_USE_TIMERS - /* start now in delaying if it's easy */ - if (val >= 0) { - event_progress_counter = event_progress_delta; - } + /* start now in delaying if it's easy */ + if (val >= 0) { + event_progress_counter = event_progress_delta; + } #endif } - -bool -opal_progress_set_yield_when_idle(bool yieldopt) +bool opal_progress_set_yield_when_idle(bool yieldopt) { bool tmp = opal_progress_yield_when_idle; opal_progress_yield_when_idle = (yieldopt) ? 1 : 0; OPAL_OUTPUT((debug_output, "progress: progress_set_yield_when_idle to %s", - opal_progress_yield_when_idle ? "true" : "false")); + opal_progress_yield_when_idle ? "true" : "false")); return tmp; } - -void -opal_progress_set_event_poll_rate(int polltime) +void opal_progress_set_event_poll_rate(int polltime) { OPAL_OUTPUT((debug_output, "progress: progress_set_event_poll_rate(%d)", polltime)); #if OPAL_PROGRESS_USE_TIMERS event_progress_delta = 0; -# if OPAL_PROGRESS_ONLY_USEC_NATIVE +# if OPAL_PROGRESS_ONLY_USEC_NATIVE event_progress_last_time = opal_timer_base_get_usec(); -# else +# else event_progress_last_time = opal_timer_base_get_cycles(); -# endif +# endif #else event_progress_counter = event_progress_delta = 0; #endif @@ -364,10 +351,10 @@ opal_progress_set_event_poll_rate(int polltime) #endif } -static int opal_progress_find_cb (opal_progress_callback_t cb, volatile opal_progress_callback_t *cbs, - size_t cbs_len) +static int opal_progress_find_cb(opal_progress_callback_t cb, + volatile opal_progress_callback_t *cbs, size_t cbs_len) { - for (size_t i = 0 ; i < cbs_len ; ++i) { + for (size_t i = 0; i < cbs_len; ++i) { if (cbs[i] == cb) { return (int) i; } @@ -376,12 +363,13 @@ static int opal_progress_find_cb (opal_progress_callback_t cb, volatile opal_pro return OPAL_ERR_NOT_FOUND; } -static int _opal_progress_register (opal_progress_callback_t cb, volatile opal_progress_callback_t **cbs, - size_t *cbs_size, size_t *cbs_len) +static int _opal_progress_register(opal_progress_callback_t cb, + volatile opal_progress_callback_t **cbs, size_t *cbs_size, + size_t *cbs_len) { int ret = OPAL_SUCCESS; - if (OPAL_ERR_NOT_FOUND != opal_progress_find_cb (cb, *cbs, *cbs_len)) { + if (OPAL_ERR_NOT_FOUND != opal_progress_find_cb(cb, *cbs, *cbs_len)) { return OPAL_SUCCESS; } @@ -389,73 +377,75 @@ static int _opal_progress_register (opal_progress_callback_t cb, volatile opal_p if (*cbs_len + 1 > *cbs_size) { opal_progress_callback_t *tmp, *old; - tmp = (opal_progress_callback_t *) malloc (sizeof (tmp[0]) * 2 * *cbs_size); + tmp = (opal_progress_callback_t *) malloc(sizeof(tmp[0]) * 2 * *cbs_size); if (tmp == NULL) { return OPAL_ERR_TEMP_OUT_OF_RESOURCE; } if (*cbs) { /* copy old callbacks */ - memcpy (tmp, (void *) *cbs, sizeof(tmp[0]) * *cbs_size); + memcpy(tmp, (void *) *cbs, sizeof(tmp[0]) * *cbs_size); } - for (size_t i = *cbs_len ; i < 2 * *cbs_size ; ++i) { + for (size_t i = *cbs_len; i < 2 * *cbs_size; ++i) { tmp[i] = fake_cb; } - opal_atomic_wmb (); + opal_atomic_wmb(); /* swap out callback array */ - old = (opal_progress_callback_t *) opal_atomic_swap_ptr ((opal_atomic_intptr_t *) cbs, (intptr_t) tmp); + old = (opal_progress_callback_t *) opal_atomic_swap_ptr((opal_atomic_intptr_t *) cbs, + (intptr_t) tmp); - opal_atomic_wmb (); + opal_atomic_wmb(); - free (old); + free(old); *cbs_size *= 2; } cbs[0][*cbs_len] = cb; ++*cbs_len; - opal_atomic_wmb (); + opal_atomic_wmb(); return ret; } -int opal_progress_register (opal_progress_callback_t cb) +int opal_progress_register(opal_progress_callback_t cb) { int ret; opal_atomic_lock(&progress_lock); - (void) _opal_progress_unregister (cb, callbacks_lp, &callbacks_lp_len); + (void) _opal_progress_unregister(cb, callbacks_lp, &callbacks_lp_len); - ret = _opal_progress_register (cb, &callbacks, &callbacks_size, &callbacks_len); + ret = _opal_progress_register(cb, &callbacks, &callbacks_size, &callbacks_len); opal_atomic_unlock(&progress_lock); return ret; } -int opal_progress_register_lp (opal_progress_callback_t cb) +int opal_progress_register_lp(opal_progress_callback_t cb) { int ret; opal_atomic_lock(&progress_lock); - (void) _opal_progress_unregister (cb, callbacks, &callbacks_len); + (void) _opal_progress_unregister(cb, callbacks, &callbacks_len); - ret = _opal_progress_register (cb, &callbacks_lp, &callbacks_lp_size, &callbacks_lp_len); + ret = _opal_progress_register(cb, &callbacks_lp, &callbacks_lp_size, &callbacks_lp_len); opal_atomic_unlock(&progress_lock); return ret; } -static int _opal_progress_unregister (opal_progress_callback_t cb, volatile opal_progress_callback_t *callback_array, - size_t *callback_array_len) +static int _opal_progress_unregister(opal_progress_callback_t cb, + volatile opal_progress_callback_t *callback_array, + size_t *callback_array_len) { - int ret = opal_progress_find_cb (cb, callback_array, *callback_array_len); + int ret = opal_progress_find_cb(cb, callback_array, *callback_array_len); if (OPAL_ERR_NOT_FOUND == ret) { return ret; } @@ -464,10 +454,11 @@ static int _opal_progress_unregister (opal_progress_callback_t cb, volatile opal is 0, we're not goig to do anything interesting anyway, so skip. If callbacks_len is 1, it will soon be 0, so no need to do any repacking. */ - for (size_t i = (size_t) ret ; i < *callback_array_len - 1 ; ++i) { + for (size_t i = (size_t) ret; i < *callback_array_len - 1; ++i) { /* copy callbacks atomically since another thread may be in * opal_progress(). */ - (void) opal_atomic_swap_ptr ((opal_atomic_intptr_t *) (callback_array + i), (intptr_t) callback_array[i+1]); + (void) opal_atomic_swap_ptr((opal_atomic_intptr_t *) (callback_array + i), + (intptr_t) callback_array[i + 1]); } --*callback_array_len; @@ -476,18 +467,18 @@ static int _opal_progress_unregister (opal_progress_callback_t cb, volatile opal return OPAL_SUCCESS; } -int opal_progress_unregister (opal_progress_callback_t cb) +int opal_progress_unregister(opal_progress_callback_t cb) { int ret; opal_atomic_lock(&progress_lock); - ret = _opal_progress_unregister (cb, callbacks, &callbacks_len); + ret = _opal_progress_unregister(cb, callbacks, &callbacks_len); if (OPAL_SUCCESS != ret) { /* if not in the high-priority array try to remove from the lp array. * a callback will never be in both. */ - ret = _opal_progress_unregister (cb, callbacks_lp, &callbacks_lp_len); + ret = _opal_progress_unregister(cb, callbacks_lp, &callbacks_lp_len); } opal_atomic_unlock(&progress_lock); diff --git a/opal/runtime/opal_progress.h b/opal/runtime/opal_progress.h index 576532c64c0..640c7d746d6 100644 --- a/opal/runtime/opal_progress.h +++ b/opal/runtime/opal_progress.h @@ -1,26 +1,34 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- *//* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2004-2006 The University of Tennessee and The University - * of Tennessee Research Foundation. All rights - * reserved. - * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, - * University of Stuttgart. All rights reserved. - * Copyright (c) 2004-2005 The Regents of the University of California. - * All rights reserved. - * Copyright (c) 2006-2014 Los Alamos National Security, LLC. All rights - * reserved. - * Copyright (c) 2018 Triad National Security, LLC. All rights - * reserved. - * - * Copyright (c) 2020 Intel, Inc. All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* + * Copyright (c) 2004-2005 The + * Trustees of Indiana University and + * Indiana University Research and + * Technology Corporation. All + * rights reserved. Copyright (c) + * 2004-2006 The University of + * Tennessee and The University of + * Tennessee Research Foundation. All + * rights reserved. Copyright (c) + * 2004-2005 High Performance + * Computing Center Stuttgart, + * University + * of Stuttgart. All rights + * reserved. Copyright (c) 2004-2005 + * The Regents of the University of + * California. All rights reserved. + * Copyright (c) 2006-2014 Los Alamos + * National Security, LLC. All + * rights reserved. Copyright (c) + * 2018 Triad National Security, + * LLC. All rights reserved. + * + * Copyright (c) 2020 Intel, + * Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ /** * @file @@ -59,7 +67,6 @@ OPAL_DECLSPEC int opal_progress_init(void); */ OPAL_DECLSPEC void opal_progress(void); - /** * Control how the event library is called * @@ -75,7 +82,6 @@ OPAL_DECLSPEC void opal_progress(void); */ OPAL_DECLSPEC int opal_progress_set_event_flag(int flags); - /** * Increase the number of users of the event library * @@ -90,7 +96,6 @@ OPAL_DECLSPEC int opal_progress_set_event_flag(int flags); */ OPAL_DECLSPEC void opal_progress_event_users_increment(void); - /** * Decrease the number of users of the event library * @@ -101,7 +106,6 @@ OPAL_DECLSPEC void opal_progress_event_users_increment(void); */ OPAL_DECLSPEC void opal_progress_event_users_decrement(void); - /** * Set whether opal_progress() should yield when idle * @@ -117,7 +121,6 @@ OPAL_DECLSPEC void opal_progress_event_users_decrement(void); */ OPAL_DECLSPEC bool opal_progress_set_yield_when_idle(bool yieldopt); - /** * Set time between calls into the event library * @@ -131,7 +134,6 @@ OPAL_DECLSPEC bool opal_progress_set_yield_when_idle(bool yieldopt); */ OPAL_DECLSPEC void opal_progress_set_event_poll_rate(int microseconds); - /** * Progress callback function typedef * @@ -146,7 +148,6 @@ OPAL_DECLSPEC void opal_progress_set_event_poll_rate(int microseconds); */ typedef int (*opal_progress_callback_t)(void); - /** * Register an event to be progressed * @@ -155,8 +156,7 @@ typedef int (*opal_progress_callback_t)(void); */ OPAL_DECLSPEC int opal_progress_register(opal_progress_callback_t cb); -OPAL_DECLSPEC int opal_progress_register_lp (opal_progress_callback_t cb); - +OPAL_DECLSPEC int opal_progress_register_lp(opal_progress_callback_t cb); /** * Deregister previously registered event @@ -166,7 +166,6 @@ OPAL_DECLSPEC int opal_progress_register_lp (opal_progress_callback_t cb); */ OPAL_DECLSPEC int opal_progress_unregister(opal_progress_callback_t cb); - OPAL_DECLSPEC extern int opal_progress_spin_count; /* do we want to call sched_yield() if nothing happened */ @@ -175,13 +174,13 @@ OPAL_DECLSPEC extern bool opal_progress_yield_when_idle; /** * Progress until flag is true or poll iterations completed */ -static inline bool opal_progress_spin(volatile bool* complete) +static inline bool opal_progress_spin(volatile bool *complete) { int32_t c; for (c = 0; c < opal_progress_spin_count; c++) { if (true == *complete) { - return true; + return true; } opal_progress(); } @@ -189,8 +188,6 @@ static inline bool opal_progress_spin(volatile bool* complete) return false; } - END_C_DECLS #endif - diff --git a/opal/runtime/opal_progress_threads.c b/opal/runtime/opal_progress_threads.c index a8a312a883b..f927cc961ca 100644 --- a/opal/runtime/opal_progress_threads.c +++ b/opal/runtime/opal_progress_threads.c @@ -14,21 +14,20 @@ #include "opal/constants.h" #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_STRING_H -#include +# include #endif #include "opal/class/opal_list.h" -#include "opal/util/event.h" #include "opal/mca/threads/threads.h" #include "opal/util/error.h" +#include "opal/util/event.h" #include "opal/util/fd.h" #include "opal/runtime/opal_progress_threads.h" - /* create a tracking object for progress threads */ typedef struct { opal_list_item_t super; @@ -52,7 +51,7 @@ typedef struct { static void tracker_constructor(opal_progress_tracker_t *p) { - p->refcount = 1; // start at one since someone created it + p->refcount = 1; // start at one since someone created it p->name = NULL; p->ev_base = NULL; p->ev_active = false; @@ -74,17 +73,12 @@ static void tracker_destructor(opal_progress_tracker_t *p) } } -static OBJ_CLASS_INSTANCE(opal_progress_tracker_t, - opal_list_item_t, - tracker_constructor, +static OBJ_CLASS_INSTANCE(opal_progress_tracker_t, opal_list_item_t, tracker_constructor, tracker_destructor); static bool inited = false; static opal_list_t tracking; -static struct timeval long_timeout = { - .tv_sec = 3600, - .tv_usec = 0 -}; +static struct timeval long_timeout = {.tv_sec = 3600, .tv_usec = 0}; static const char *shared_thread_name = "OPAL-wide async progress thread"; /* @@ -93,7 +87,7 @@ static const char *shared_thread_name = "OPAL-wide async progress thread"; */ static void dummy_timeout_cb(int fd, short args, void *cbdata) { - opal_progress_tracker_t *trk = (opal_progress_tracker_t*)cbdata; + opal_progress_tracker_t *trk = (opal_progress_tracker_t *) cbdata; opal_event_add(&trk->block, &long_timeout); } @@ -101,10 +95,10 @@ static void dummy_timeout_cb(int fd, short args, void *cbdata) /* * Main for the progress thread */ -static void* progress_engine(opal_object_t *obj) +static void *progress_engine(opal_object_t *obj) { - opal_thread_t *t = (opal_thread_t*)obj; - opal_progress_tracker_t *trk = (opal_progress_tracker_t*)t->t_arg; + opal_thread_t *t = (opal_thread_t *) obj; + opal_progress_tracker_t *trk = (opal_progress_tracker_t *) t->t_arg; while (trk->ev_active) { opal_event_loop(trk->ev_base, OPAL_EVLOOP_ONCE); @@ -157,7 +151,7 @@ opal_event_base_t *opal_progress_thread_init(const char *name) } /* check if we already have this thread */ - OPAL_LIST_FOREACH(trk, &tracking, opal_progress_tracker_t) { + OPAL_LIST_FOREACH (trk, &tracking, opal_progress_tracker_t) { if (0 == strcmp(name, trk->name)) { /* we do, so up the refcount on it */ ++trk->refcount; @@ -187,8 +181,7 @@ opal_event_base_t *opal_progress_thread_init(const char *name) /* add an event to the new event base (if there are no events, opal_event_loop() will return immediately) */ - opal_event_set(trk->ev_base, &trk->block, -1, OPAL_EV_PERSIST, - dummy_timeout_cb, trk); + opal_event_set(trk->ev_base, &trk->block, -1, OPAL_EV_PERSIST, dummy_timeout_cb, trk); opal_event_add(&trk->block, &long_timeout); /* construct the thread object */ @@ -218,7 +211,7 @@ int opal_progress_thread_finalize(const char *name) } /* find the specified engine */ - OPAL_LIST_FOREACH(trk, &tracking, opal_progress_tracker_t) { + OPAL_LIST_FOREACH (trk, &tracking, opal_progress_tracker_t) { if (0 == strcmp(name, trk->name)) { /* decrement the refcount */ --trk->refcount; @@ -259,7 +252,7 @@ int opal_progress_thread_pause(const char *name) } /* find the specified engine */ - OPAL_LIST_FOREACH(trk, &tracking, opal_progress_tracker_t) { + OPAL_LIST_FOREACH (trk, &tracking, opal_progress_tracker_t) { if (0 == strcmp(name, trk->name)) { if (trk->ev_active) { stop_progress_engine(trk); @@ -286,7 +279,7 @@ int opal_progress_thread_resume(const char *name) } /* find the specified engine */ - OPAL_LIST_FOREACH(trk, &tracking, opal_progress_tracker_t) { + OPAL_LIST_FOREACH (trk, &tracking, opal_progress_tracker_t) { if (0 == strcmp(name, trk->name)) { if (trk->ev_active) { return OPAL_ERR_RESOURCE_BUSY; diff --git a/opal/runtime/opal_progress_threads.h b/opal/runtime/opal_progress_threads.h index 2795bc474ee..6003b72ade1 100644 --- a/opal/runtime/opal_progress_threads.h +++ b/opal/runtime/opal_progress_threads.h @@ -17,7 +17,6 @@ #include "opal/util/event.h" - /** * Initialize a progress thread name; if a progress thread is not * already associated with that name, start a progress thread. diff --git a/opal/test/reachable/reachable_netlink.c b/opal/test/reachable/reachable_netlink.c index ea270f339c8..b040fadb13f 100644 --- a/opal/test/reachable/reachable_netlink.c +++ b/opal/test/reachable/reachable_netlink.c @@ -14,17 +14,16 @@ #include "reachable_shared.h" -#include "opal/runtime/opal.h" -#include "opal/mca/reachable/reachable.h" -#include "opal/util/if.h" #include "opal/class/opal_list.h" +#include "opal/mca/reachable/reachable.h" +#include "opal/runtime/opal.h" #include "opal/util/if.h" /* * Creates list of remote interfaces for testing reachability. * Only minimum information is filled out. */ -opal_list_t* build_if_list(void) +opal_list_t *build_if_list(void) { /* Allocate memory for and create interface list */ opal_list_t *if_list = OBJ_NEW(opal_list_t); @@ -93,7 +92,6 @@ opal_list_t* build_if_list(void) return if_list; } - int main(int argc, char **argv) { opal_list_t *local_list, *remote_list; @@ -121,69 +119,67 @@ int main(int argc, char **argv) printf("Local interfaces:\n"); i = 0; - OPAL_LIST_FOREACH(local_if, local_list, opal_if_t) { + OPAL_LIST_FOREACH (local_if, local_list, opal_if_t) { char addr[128]; char *family; switch (local_if->af_family) { - case AF_INET: - family = "IPv4"; - inet_ntop(AF_INET, &(((struct sockaddr_in*) &local_if->if_addr))->sin_addr, - addr, sizeof(addr)); - break; - case AF_INET6: - family = "IPv6"; - inet_ntop(AF_INET6, &(((struct sockaddr_in6*) &local_if->if_addr))->sin6_addr, - addr, sizeof(addr)); - break; - default: - family = "Unknown"; - opal_string_copy(addr, "Unknown", sizeof(addr)); - break; + case AF_INET: + family = "IPv4"; + inet_ntop(AF_INET, &(((struct sockaddr_in *) &local_if->if_addr))->sin_addr, addr, + sizeof(addr)); + break; + case AF_INET6: + family = "IPv6"; + inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) &local_if->if_addr))->sin6_addr, addr, + sizeof(addr)); + break; + default: + family = "Unknown"; + opal_string_copy(addr, "Unknown", sizeof(addr)); + break; } - printf(" %3d: %s\t%s\t%s/%d\n", i, local_if->if_name, - family, addr, local_if->if_mask); + printf(" %3d: %s\t%s\t%s/%d\n", i, local_if->if_name, family, addr, local_if->if_mask); i++; } printf("\nRemote interfaces:\n"); i = 0; - OPAL_LIST_FOREACH(local_if, remote_list, opal_if_t) { + OPAL_LIST_FOREACH (local_if, remote_list, opal_if_t) { char addr[128]; char *family; switch (local_if->af_family) { - case AF_INET: - family = "IPv4"; - inet_ntop(AF_INET, &(((struct sockaddr_in*) &local_if->if_addr))->sin_addr, - addr, sizeof(addr)); - break; - case AF_INET6: - family = "IPv6"; - inet_ntop(AF_INET6, &(((struct sockaddr_in6*) &local_if->if_addr))->sin6_addr, - addr, sizeof(addr)); - break; - default: - family = "Unknown"; - opal_string_copy(addr, "Unknown", sizeof(addr)); - break; + case AF_INET: + family = "IPv4"; + inet_ntop(AF_INET, &(((struct sockaddr_in *) &local_if->if_addr))->sin_addr, addr, + sizeof(addr)); + break; + case AF_INET6: + family = "IPv6"; + inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) &local_if->if_addr))->sin6_addr, addr, + sizeof(addr)); + break; + default: + family = "Unknown"; + opal_string_copy(addr, "Unknown", sizeof(addr)); + break; } - printf(" %3d: %s\t%s\t%s/%d\n", i, local_if->if_name, - family, addr, local_if->if_mask); + printf(" %3d: %s\t%s\t%s/%d\n", i, local_if->if_name, family, addr, local_if->if_mask); i++; } printf("\nConnectivity Table:\n "); - for (j = 0 ; j < remote_ifs ; j++) { + for (j = 0; j < remote_ifs; j++) { printf("%3d ", j); } printf("\n"); - for (i = 0; i < local_ifs ; i++) { + for (i = 0; i < local_ifs; i++) { printf(" %3d: ", i); - for (j = 0 ; j < remote_ifs ; j++) { + for (j = 0; j < remote_ifs; j++) { printf("%3d ", results->weights[i][j]); } printf("\n"); diff --git a/opal/test/reachable/reachable_shared.h b/opal/test/reachable/reachable_shared.h index 6ac72d9a357..6523f7402f0 100644 --- a/opal/test/reachable/reachable_shared.h +++ b/opal/test/reachable/reachable_shared.h @@ -13,25 +13,29 @@ #include -#include "opal/runtime/opal.h" #include "opal/mca/reachable/reachable.h" +#include "opal/runtime/opal.h" #include "opal/util/if.h" #include "opal/util/string_copy.h" BEGIN_C_DECLS /* Create and populate opal_if_t with information required by opal_reachable */ -opal_if_t* create_if(int af_family, char *address, int mask, int bandwidth) +opal_if_t *create_if(int af_family, char *address, int mask, int bandwidth) { opal_if_t *interface = OBJ_NEW(opal_if_t); opal_string_copy(interface->if_name, "interface0", OPAL_IF_NAMESIZE); interface->af_family = af_family; - ((struct sockaddr *)&(interface->if_addr))->sa_family = af_family; - - if (AF_INET == af_family){ - assert(1 == inet_pton(af_family, address, &((struct sockaddr_in *)&(interface->if_addr))->sin_addr)); - } else if (AF_INET6 == af_family){ - assert(1 == inet_pton(af_family, address, &((struct sockaddr_in6 *)&(interface->if_addr))->sin6_addr)); + ((struct sockaddr *) &(interface->if_addr))->sa_family = af_family; + + if (AF_INET == af_family) { + assert(1 + == inet_pton(af_family, address, + &((struct sockaddr_in *) &(interface->if_addr))->sin_addr)); + } else if (AF_INET6 == af_family) { + assert(1 + == inet_pton(af_family, address, + &((struct sockaddr_in6 *) &(interface->if_addr))->sin6_addr)); } interface->if_mask = mask; @@ -40,7 +44,6 @@ opal_if_t* create_if(int af_family, char *address, int mask, int bandwidth) return interface; } - /* Run a test between a pair of interfaces * and clean up the memory afterwards. * Return the weight between the pair of diff --git a/opal/test/reachable/reachable_weighted.c b/opal/test/reachable/reachable_weighted.c index 5a6db2fc091..d2f181dbc01 100644 --- a/opal/test/reachable/reachable_weighted.c +++ b/opal/test/reachable/reachable_weighted.c @@ -23,7 +23,6 @@ enum connection_quality { CQ_PUBLIC_SAME_NETWORK = 100 }; - /* SUITE 1: * Tests IPv4 connections by * modifying ip addresses and @@ -52,8 +51,8 @@ int ipv4_test() int2 = create_if(AF_INET, "127.0.0.2", 0, 0); result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -69,8 +68,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -86,8 +85,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -103,8 +102,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -120,8 +119,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -137,8 +136,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -154,8 +153,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -171,8 +170,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -188,8 +187,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -205,8 +204,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed this test #%d", test_no); + ++failed_no; + opal_output(0, "Failed this test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -222,8 +221,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed this test #%d", test_no); + ++failed_no; + opal_output(0, "Failed this test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -239,8 +238,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -256,8 +255,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -273,8 +272,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -290,8 +289,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -302,13 +301,13 @@ int ipv4_test() */ test_no++; expected_result = CQ_NO_CONNECTION; - int1 = create_if(AF_INET, "27.27.27.27", 24 , 0); + int1 = create_if(AF_INET, "27.27.27.27", 24, 0); int2 = create_if(AF_INET, "192.168.0.1", 16, 0); result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -324,8 +323,8 @@ int ipv4_test() result = run_single_test(int1, int2); if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -339,8 +338,8 @@ int ipv4_test() result = run_single_test(int1, int2); test_no++; if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -354,22 +353,22 @@ int ipv4_test() result = run_single_test(int1, int2); test_no++; if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); - opal_output(0, "Finished Reachable IPv4 Tests. %d/%d successful", test_no-failed_no, test_no); + opal_output(0, "Finished Reachable IPv4 Tests. %d/%d successful", test_no - failed_no, + test_no); if (0 == failed_no) { - return 0; + return 0; } else { - return 1; + return 1; } } - /* SUITE 2: * Compares connections with different * bandwidths to see ensure the @@ -411,8 +410,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 > result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST2 @@ -434,8 +433,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST3 @@ -458,8 +457,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST4 @@ -482,8 +481,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST5 @@ -506,8 +505,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST6 @@ -529,8 +528,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST7 @@ -553,8 +552,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST8 @@ -577,8 +576,8 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 == result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } /* TEST9 @@ -600,19 +599,19 @@ int ranking_test() OBJ_RELEASE(int2); if (!(result1 < result2)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } - opal_output(0, "Finished Reachable Weighted Ranking Tests. %d/%d successful", test_no-failed_no, test_no); + opal_output(0, "Finished Reachable Weighted Ranking Tests. %d/%d successful", + test_no - failed_no, test_no); if (0 == failed_no) { - return 0; + return 0; } else { - return 1; + return 1; } } - /* SUITE 3: * Tests interfaces lists of various sizes * to ensure no crashes occur and results @@ -644,8 +643,8 @@ int loop_test() OBJ_RELEASE(if_list2); if (!(0 == results->num_local && 0 == results->num_remote)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -666,8 +665,8 @@ int loop_test() OBJ_RELEASE(if_list2); if (!(0 == results->num_local && 1 == results->num_remote)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -687,8 +686,8 @@ int loop_test() OBJ_RELEASE(if_list2); if (!(1 == results->num_local && 0 == results->num_remote)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -702,12 +701,12 @@ int loop_test() if_list1 = OBJ_NEW(opal_list_t); if_list2 = OBJ_NEW(opal_list_t); for (i = 0; i < 3; i++) { - intf = create_if(AF_INET, "31.14.19.92", 24, 0); - opal_list_append(if_list1, &(intf->super)); + intf = create_if(AF_INET, "31.14.19.92", 24, 0); + opal_list_append(if_list1, &(intf->super)); } for (i = 0; i < 14; i++) { - intf = create_if(AF_INET, "31.14.19.92", 24, 0); - opal_list_append(if_list2, &(intf->super)); + intf = create_if(AF_INET, "31.14.19.92", 24, 0); + opal_list_append(if_list2, &(intf->super)); } results = opal_reachable.reachable(if_list1, if_list2); @@ -715,8 +714,8 @@ int loop_test() OBJ_RELEASE(if_list2); if (!(3 == results->num_local && 14 == results->num_remote)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -730,12 +729,12 @@ int loop_test() if_list1 = OBJ_NEW(opal_list_t); if_list2 = OBJ_NEW(opal_list_t); for (i = 0; i < 14; i++) { - intf = create_if(AF_INET, "31.14.19.92", 24, 0); - opal_list_append(if_list1, &(intf->super)); + intf = create_if(AF_INET, "31.14.19.92", 24, 0); + opal_list_append(if_list1, &(intf->super)); } for (i = 0; i < 3; i++) { - intf = create_if(AF_INET, "31.14.19.92", 24, 0); - opal_list_append(if_list2, &(intf->super)); + intf = create_if(AF_INET, "31.14.19.92", 24, 0); + opal_list_append(if_list2, &(intf->super)); } results = opal_reachable.reachable(if_list1, if_list2); @@ -743,8 +742,8 @@ int loop_test() OBJ_RELEASE(if_list2); if (!(14 == results->num_local && 3 == results->num_remote)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -758,12 +757,12 @@ int loop_test() if_list1 = OBJ_NEW(opal_list_t); if_list2 = OBJ_NEW(opal_list_t); for (i = 0; i < 27; i++) { - intf = create_if(AF_INET, "31.14.19.92", 24, 0); - opal_list_append(if_list1, &(intf->super)); + intf = create_if(AF_INET, "31.14.19.92", 24, 0); + opal_list_append(if_list1, &(intf->super)); } for (i = 0; i < 27; i++) { - intf = create_if(AF_INET, "31.14.19.92", 24, 0); - opal_list_append(if_list2, &(intf->super)); + intf = create_if(AF_INET, "31.14.19.92", 24, 0); + opal_list_append(if_list2, &(intf->super)); } results = opal_reachable.reachable(if_list1, if_list2); @@ -771,8 +770,8 @@ int loop_test() OBJ_RELEASE(if_list2); if (!(27 == results->num_local && 27 == results->num_remote)) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -800,12 +799,12 @@ int loop_test() OBJ_RELEASE(if_list1); OBJ_RELEASE(if_list2); - if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] && - CQ_PUBLIC_SAME_NETWORK == results->weights[1][1])) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] + && CQ_PUBLIC_SAME_NETWORK == results->weights[1][1])) { + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -835,14 +834,14 @@ int loop_test() OBJ_RELEASE(if_list1); OBJ_RELEASE(if_list2); - if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][2] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] && - CQ_PUBLIC_SAME_NETWORK == results->weights[1][1]) && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][2]) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][2] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] + && CQ_PUBLIC_SAME_NETWORK == results->weights[1][1]) + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][2]) { + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); @@ -872,28 +871,27 @@ int loop_test() OBJ_RELEASE(if_list1); OBJ_RELEASE(if_list2); - if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] && - CQ_PUBLIC_SAME_NETWORK == results->weights[1][1] && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[2][0]) && - CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[2][1]) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + if (!(CQ_PUBLIC_SAME_NETWORK == results->weights[0][0] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[0][1] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[1][0] + && CQ_PUBLIC_SAME_NETWORK == results->weights[1][1] + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[2][0]) + && CQ_PUBLIC_DIFFERENT_NETWORK == results->weights[2][1]) { + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(results); - opal_output(0, "Finished Reachable Weighted Loop Tests. %d/%d successful", test_no-failed_no, test_no); + opal_output(0, "Finished Reachable Weighted Loop Tests. %d/%d successful", test_no - failed_no, + test_no); if (0 == failed_no) { - return 0; + return 0; } else { - return 1; + return 1; } - } - /* SUITE 4: * Test IPv6 */ @@ -918,8 +916,8 @@ int test_ipv6() result = run_single_test(int1, int2); test_no++; if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -934,8 +932,8 @@ int test_ipv6() result = run_single_test(int1, int2); test_no++; if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -946,8 +944,8 @@ int test_ipv6() result = run_single_test(int1, int2); test_no++; if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); @@ -958,18 +956,19 @@ int test_ipv6() result = run_single_test(int1, int2); test_no++; if (result != expected_result) { - ++failed_no; - opal_output(0, "Failed test #%d", test_no); + ++failed_no; + opal_output(0, "Failed test #%d", test_no); } OBJ_RELEASE(int1); OBJ_RELEASE(int2); - opal_output(0, "Finished Reachable Weighted IPv6 Tests. %d/%d successful", test_no-failed_no, test_no); + opal_output(0, "Finished Reachable Weighted IPv6 Tests. %d/%d successful", test_no - failed_no, + test_no); if (0 == failed_no) { - return 0; + return 0; } else { - return 1; + return 1; } #else opal_output(0, "No IPv6 support; skipped tests"); @@ -987,28 +986,28 @@ int main(int argc, char **argv) total++; if (ipv4_test()) { - failed++; + failed++; } total++; if (ranking_test()) { - failed++; + failed++; } total++; if (loop_test()) { - failed++; + failed++; } total++; if (test_ipv6()) { - failed++; + failed++; } if (0 != failed) { - opal_output(0, "\n\nFailed %d/%d Reachable Weighted Test Suites :(\n\n", failed, total); + opal_output(0, "\n\nFailed %d/%d Reachable Weighted Test Suites :(\n\n", failed, total); } else { - opal_output(0, "\n\nPassed %d/%d Reachable Weighted Test Suites :)\n\n", total, total); + opal_output(0, "\n\nPassed %d/%d Reachable Weighted Test Suites :)\n\n", total, total); } return failed; diff --git a/opal/tools/wrappers/opal_wrapper.c b/opal/tools/wrappers/opal_wrapper.c index f880d261498..0140a82d112 100644 --- a/opal/tools/wrappers/opal_wrapper.c +++ b/opal/tools/wrappers/opal_wrapper.c @@ -25,39 +25,39 @@ #include "opal_config.h" -#include #include +#include #include #ifdef HAVE_SYS_STAT_H -#include -#endif /* HAVE_SYS_STAT_H */ +# include +#endif /* HAVE_SYS_STAT_H */ #ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ +# include +#endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_REGEX_H -#include +# include #endif #ifdef HAVE_SYS_WAIT_H -#include -#endif /* HAVE_SYS_WAIT_H */ +# include +#endif /* HAVE_SYS_WAIT_H */ #include +#include "opal/constants.h" #include "opal/mca/installdirs/installdirs.h" #include "opal/runtime/opal.h" -#include "opal/constants.h" #include "opal/util/argv.h" +#include "opal/util/basename.h" #include "opal/util/error.h" +#include "opal/util/few.h" #include "opal/util/keyval_parse.h" #include "opal/util/opal_environ.h" -#include "opal/util/show_help.h" -#include "opal/util/path.h" -#include "opal/util/few.h" -#include "opal/util/basename.h" #include "opal/util/os_path.h" +#include "opal/util/path.h" #include "opal/util/printf.h" +#include "opal/util/show_help.h" -#define OPAL_INCLUDE_FLAG "-I" -#define OPAL_LIBDIR_FLAG "-L" +#define OPAL_INCLUDE_FLAG "-I" +#define OPAL_LIBDIR_FLAG "-L" struct options_data_t { char **compiler_args; @@ -91,20 +91,19 @@ static int user_data_idx = -1; /* index of options to use by default */ static int default_data_idx = -1; -#define COMP_DRY_RUN 0x001 -#define COMP_SHOW_ERROR 0x002 -#define COMP_WANT_COMMAND 0x004 -#define COMP_WANT_PREPROC 0x008 -#define COMP_WANT_COMPILE 0x010 -#define COMP_WANT_LINK 0x020 -#define COMP_WANT_PMPI 0x040 -#define COMP_WANT_STATIC 0x080 -#define COMP_WANT_LINKALL 0x100 - -static void -options_data_init(struct options_data_t *data) +#define COMP_DRY_RUN 0x001 +#define COMP_SHOW_ERROR 0x002 +#define COMP_WANT_COMMAND 0x004 +#define COMP_WANT_PREPROC 0x008 +#define COMP_WANT_COMPILE 0x010 +#define COMP_WANT_LINK 0x020 +#define COMP_WANT_PMPI 0x040 +#define COMP_WANT_STATIC 0x080 +#define COMP_WANT_LINKALL 0x100 + +static void options_data_init(struct options_data_t *data) { - data->compiler_args = (char **) malloc(sizeof(char*)); + data->compiler_args = (char **) malloc(sizeof(char *)); data->compiler_args[0] = NULL; data->language = NULL; data->compiler = NULL; @@ -113,17 +112,17 @@ options_data_init(struct options_data_t *data) data->version = NULL; data->compiler_env = NULL; data->compiler_flags_env = NULL; - data->preproc_flags = (char **) malloc(sizeof(char*)); + data->preproc_flags = (char **) malloc(sizeof(char *)); data->preproc_flags[0] = NULL; - data->comp_flags = (char **) malloc(sizeof(char*)); + data->comp_flags = (char **) malloc(sizeof(char *)); data->comp_flags[0] = NULL; - data->comp_flags_prefix = (char **) malloc(sizeof(char*)); + data->comp_flags_prefix = (char **) malloc(sizeof(char *)); data->comp_flags_prefix[0] = NULL; - data->link_flags = (char **) malloc(sizeof(char*)); + data->link_flags = (char **) malloc(sizeof(char *)); data->link_flags[0] = NULL; - data->libs = (char **) malloc(sizeof(char*)); + data->libs = (char **) malloc(sizeof(char *)); data->libs[0] = NULL; - data->libs_static = (char **) malloc(sizeof(char*)); + data->libs_static = (char **) malloc(sizeof(char *)); data->libs_static[0] = NULL; data->dyn_lib_file = NULL; data->static_lib_file = NULL; @@ -134,40 +133,67 @@ options_data_init(struct options_data_t *data) data->path_opallibdir = NULL; } -static void -options_data_free(struct options_data_t *data) +static void options_data_free(struct options_data_t *data) { if (NULL != data->compiler_args) { opal_argv_free(data->compiler_args); } - if (NULL != data->language) free(data->language); - if (NULL != data->compiler) free(data->compiler); - if (NULL != data->project) free(data->project); - if (NULL != data->project_short) free(data->project_short); - if (NULL != data->version) free(data->version); - if (NULL != data->compiler_env) free(data->compiler_env); - if (NULL != data->compiler_flags_env) free(data->compiler_flags_env); + if (NULL != data->language) { + free(data->language); + } + if (NULL != data->compiler) { + free(data->compiler); + } + if (NULL != data->project) { + free(data->project); + } + if (NULL != data->project_short) { + free(data->project_short); + } + if (NULL != data->version) { + free(data->version); + } + if (NULL != data->compiler_env) { + free(data->compiler_env); + } + if (NULL != data->compiler_flags_env) { + free(data->compiler_flags_env); + } opal_argv_free(data->preproc_flags); opal_argv_free(data->comp_flags); opal_argv_free(data->comp_flags_prefix); opal_argv_free(data->link_flags); opal_argv_free(data->libs); opal_argv_free(data->libs_static); - if (NULL != data->dyn_lib_file) free(data->dyn_lib_file); - if (NULL != data->static_lib_file) free(data->static_lib_file); - if (NULL != data->req_file) free(data->req_file); - if (NULL != data->path_includedir) free(data->path_includedir); - if (NULL != data->path_libdir) free(data->path_libdir); - if (NULL != data->path_opalincludedir) free(data->path_opalincludedir); - if (NULL != data->path_opallibdir) free(data->path_opallibdir); + if (NULL != data->dyn_lib_file) { + free(data->dyn_lib_file); + } + if (NULL != data->static_lib_file) { + free(data->static_lib_file); + } + if (NULL != data->req_file) { + free(data->req_file); + } + if (NULL != data->path_includedir) { + free(data->path_includedir); + } + if (NULL != data->path_libdir) { + free(data->path_libdir); + } + if (NULL != data->path_opalincludedir) { + free(data->path_opalincludedir); + } + if (NULL != data->path_opallibdir) { + free(data->path_opallibdir); + } } -static void -options_data_expand(const char *value) +static void options_data_expand(const char *value) { /* make space for the new set of args */ parse_options_idx++; - options_data = (struct options_data_t *) realloc(options_data, sizeof(struct options_data_t) * (parse_options_idx + 1)); + options_data = (struct options_data_t *) realloc(options_data, sizeof(struct options_data_t) + * (parse_options_idx + 1)); options_data_init(&(options_data[parse_options_idx])); /* if there are values, this is not the default case. @@ -175,8 +201,7 @@ options_data_expand(const char *value) if (NULL != value && 0 != strcmp(value, "")) { char **values = opal_argv_split(value, ';'); opal_argv_insert(&(options_data[parse_options_idx].compiler_args), - opal_argv_count(options_data[parse_options_idx].compiler_args), - values); + opal_argv_count(options_data[parse_options_idx].compiler_args), values); opal_argv_free(values); } else { free(options_data[parse_options_idx].compiler_args); @@ -186,9 +211,7 @@ options_data_expand(const char *value) } } - -static int -find_options_index(const char *arg) +static int find_options_index(const char *arg) { int i, j; #ifdef HAVE_REGEXEC @@ -196,14 +219,14 @@ find_options_index(const char *arg) regex_t res; #endif - for (i = 0 ; i <= parse_options_idx ; ++i) { + for (i = 0; i <= parse_options_idx; ++i) { if (NULL == options_data[i].compiler_args) { continue; } #ifdef HAVE_REGEXEC args_count = opal_argv_count(options_data[i].compiler_args); - for (j = 0 ; j < args_count ; ++j) { + for (j = 0; j < args_count; ++j) { if (0 != regcomp(&res, options_data[i].compiler_args[j], REG_NOSUB)) { return -1; } @@ -216,7 +239,7 @@ find_options_index(const char *arg) regfree(&res); } #else - for (j = 0 ; j < opal_argv_count(options_data[i].compiler_args) ; ++j) { + for (j = 0; j < opal_argv_count(options_data[i].compiler_args); ++j) { if (0 == strcmp(arg, options_data[i].compiler_args[j])) { return i; } @@ -227,14 +250,12 @@ find_options_index(const char *arg) return -1; } - -static void -expand_flags(char **argv) +static void expand_flags(char **argv) { int i; char *tmp; - for (i = 0 ; argv[i] != NULL ; ++i) { + for (i = 0; argv[i] != NULL; ++i) { tmp = opal_install_dirs_expand(argv[i]); if (tmp != argv[i]) { free(argv[i]); @@ -243,9 +264,7 @@ expand_flags(char **argv) } } - -static void -data_callback(const char *key, const char *value) +static void data_callback(const char *key, const char *value) { /* handle case where text file does not contain any special compiler options field */ @@ -256,25 +275,31 @@ data_callback(const char *key, const char *value) if (0 == strcmp(key, "compiler_args")) { options_data_expand(value); } else if (0 == strcmp(key, "language")) { - if (NULL != value) options_data[parse_options_idx].language = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].language = strdup(value); + } } else if (0 == strcmp(key, "compiler")) { - if (NULL != value) options_data[parse_options_idx].compiler = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].compiler = strdup(value); + } } else if (0 == strcmp(key, "project")) { - if (NULL != value) options_data[parse_options_idx].project = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].project = strdup(value); + } } else if (0 == strcmp(key, "version")) { - if (NULL != value) options_data[parse_options_idx].version = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].version = strdup(value); + } } else if (0 == strcmp(key, "preprocessor_flags")) { char **values = opal_argv_split(value, ' '); opal_argv_insert(&options_data[parse_options_idx].preproc_flags, - opal_argv_count(options_data[parse_options_idx].preproc_flags), - values); + opal_argv_count(options_data[parse_options_idx].preproc_flags), values); expand_flags(options_data[parse_options_idx].preproc_flags); opal_argv_free(values); } else if (0 == strcmp(key, "compiler_flags")) { char **values = opal_argv_split(value, ' '); opal_argv_insert(&options_data[parse_options_idx].comp_flags, - opal_argv_count(options_data[parse_options_idx].comp_flags), - values); + opal_argv_count(options_data[parse_options_idx].comp_flags), values); expand_flags(options_data[parse_options_idx].comp_flags); opal_argv_free(values); } else if (0 == strcmp(key, "compiler_flags_prefix")) { @@ -287,112 +312,123 @@ data_callback(const char *key, const char *value) } else if (0 == strcmp(key, "linker_flags")) { char **values = opal_argv_split(value, ' '); opal_argv_insert(&options_data[parse_options_idx].link_flags, - opal_argv_count(options_data[parse_options_idx].link_flags), - values); + opal_argv_count(options_data[parse_options_idx].link_flags), values); expand_flags(options_data[parse_options_idx].link_flags); opal_argv_free(values); } else if (0 == strcmp(key, "libs")) { char **values = opal_argv_split(value, ' '); opal_argv_insert(&options_data[parse_options_idx].libs, - opal_argv_count(options_data[parse_options_idx].libs), - values); + opal_argv_count(options_data[parse_options_idx].libs), values); opal_argv_free(values); } else if (0 == strcmp(key, "libs_static")) { char **values = opal_argv_split(value, ' '); opal_argv_insert(&options_data[parse_options_idx].libs_static, - opal_argv_count(options_data[parse_options_idx].libs_static), - values); + opal_argv_count(options_data[parse_options_idx].libs_static), values); opal_argv_free(values); } else if (0 == strcmp(key, "dyn_lib_file")) { - if (NULL != value) options_data[parse_options_idx].dyn_lib_file = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].dyn_lib_file = strdup(value); + } } else if (0 == strcmp(key, "static_lib_file")) { - if (NULL != value) options_data[parse_options_idx].static_lib_file = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].static_lib_file = strdup(value); + } } else if (0 == strcmp(key, "required_file")) { - if (NULL != value) options_data[parse_options_idx].req_file = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].req_file = strdup(value); + } } else if (0 == strcmp(key, "project_short")) { - if (NULL != value) options_data[parse_options_idx].project_short = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].project_short = strdup(value); + } } else if (0 == strcmp(key, "compiler_env")) { - if (NULL != value) options_data[parse_options_idx].compiler_env = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].compiler_env = strdup(value); + } } else if (0 == strcmp(key, "compiler_flags_env")) { - if (NULL != value) options_data[parse_options_idx].compiler_flags_env = strdup(value); + if (NULL != value) { + options_data[parse_options_idx].compiler_flags_env = strdup(value); + } } else if (0 == strcmp(key, "includedir")) { if (NULL != value) { - options_data[parse_options_idx].path_includedir = - opal_install_dirs_expand(value); - if (0 != strcmp(options_data[parse_options_idx].path_includedir, "/usr/include") || - 0 == strncmp(options_data[parse_options_idx].language, "Fortran", strlen("Fortran"))) { + options_data[parse_options_idx].path_includedir = opal_install_dirs_expand(value); + if (0 != strcmp(options_data[parse_options_idx].path_includedir, "/usr/include") + || 0 + == strncmp(options_data[parse_options_idx].language, "Fortran", + strlen("Fortran"))) { char *line; - opal_asprintf(&line, OPAL_INCLUDE_FLAG"%s", - options_data[parse_options_idx].path_includedir); + opal_asprintf(&line, OPAL_INCLUDE_FLAG "%s", + options_data[parse_options_idx].path_includedir); opal_argv_append_nosize(&options_data[parse_options_idx].preproc_flags, line); free(line); } } } else if (0 == strcmp(key, "libdir")) { - if (NULL != value) options_data[parse_options_idx].path_libdir = - opal_install_dirs_expand(value); + if (NULL != value) { + options_data[parse_options_idx].path_libdir = opal_install_dirs_expand(value); + } if (0 != strcmp(options_data[parse_options_idx].path_libdir, "/usr/lib")) { char *line; - opal_asprintf(&line, OPAL_LIBDIR_FLAG"%s", - options_data[parse_options_idx].path_libdir); + opal_asprintf(&line, OPAL_LIBDIR_FLAG "%s", + options_data[parse_options_idx].path_libdir); opal_argv_append_nosize(&options_data[parse_options_idx].link_flags, line); free(line); } } else if (0 == strcmp(key, "opalincludedir")) { printf("EXPANDING!\n"); if (NULL != value) { - options_data[parse_options_idx].path_opalincludedir = - opal_install_dirs_expand(value); - if (0 != strcmp(options_data[parse_options_idx].path_opalincludedir, "/usr/include") || - 0 == strncmp(options_data[parse_options_idx].language, "Fortran", strlen("Fortran"))) { + options_data[parse_options_idx].path_opalincludedir = opal_install_dirs_expand(value); + if (0 != strcmp(options_data[parse_options_idx].path_opalincludedir, "/usr/include") + || 0 + == strncmp(options_data[parse_options_idx].language, "Fortran", + strlen("Fortran"))) { char *line; - opal_asprintf(&line, OPAL_INCLUDE_FLAG"%s", - options_data[parse_options_idx].path_opalincludedir); + opal_asprintf(&line, OPAL_INCLUDE_FLAG "%s", + options_data[parse_options_idx].path_opalincludedir); opal_argv_append_nosize(&options_data[parse_options_idx].preproc_flags, line); free(line); } } } else if (0 == strcmp(key, "opallibdir")) { - if (NULL != value) options_data[parse_options_idx].path_opallibdir = - opal_install_dirs_expand(value); + if (NULL != value) { + options_data[parse_options_idx].path_opallibdir = opal_install_dirs_expand(value); + } if (0 != strcmp(options_data[parse_options_idx].path_opallibdir, "/usr/lib")) { char *line; - opal_asprintf(&line, OPAL_LIBDIR_FLAG"%s", - options_data[parse_options_idx].path_opallibdir); + opal_asprintf(&line, OPAL_LIBDIR_FLAG "%s", + options_data[parse_options_idx].path_opallibdir); opal_argv_append_nosize(&options_data[parse_options_idx].link_flags, line); free(line); } } } - -static int -data_init(const char *appname) +static int data_init(const char *appname) { int ret; char *datafile; /* now load the data */ - opal_asprintf(&datafile, "%s%s%s-wrapper-data.txt", - opal_install_dirs.opaldatadir, OPAL_PATH_SEP, appname); - if (NULL == datafile) return OPAL_ERR_TEMP_OUT_OF_RESOURCE; + opal_asprintf(&datafile, "%s%s%s-wrapper-data.txt", opal_install_dirs.opaldatadir, + OPAL_PATH_SEP, appname); + if (NULL == datafile) { + return OPAL_ERR_TEMP_OUT_OF_RESOURCE; + } ret = opal_util_keyval_parse(datafile, data_callback); - if( OPAL_SUCCESS != ret ) { - fprintf(stderr, "Cannot open configuration file %s\n", datafile ); + if (OPAL_SUCCESS != ret) { + fprintf(stderr, "Cannot open configuration file %s\n", datafile); } free(datafile); return ret; } - -static int -data_finalize(void) +static int data_finalize(void) { int i; - for (i = 0 ; i <= parse_options_idx ; ++i) { + for (i = 0; i <= parse_options_idx; ++i) { options_data_free(&(options_data[i])); } free(options_data); @@ -400,32 +436,34 @@ data_finalize(void) return OPAL_SUCCESS; } - -static void -print_flags(char **args, char *pattern) +static void print_flags(char **args, char *pattern) { int i; bool found = false; - for (i = 0 ; args[i] != NULL ; ++i) { + for (i = 0; args[i] != NULL; ++i) { if (0 == strncmp(args[i], pattern, strlen(pattern))) { - if (found) printf(" "); + if (found) { + printf(" "); + } printf("%s", args[i] + strlen(pattern)); found = true; } } - if (found) printf("\n"); + if (found) { + printf("\n"); + } } - -static void -load_env_data(const char *project, const char *flag, char **data) +static void load_env_data(const char *project, const char *flag, char **data) { char *envname; char *envvalue; - if (NULL == project || NULL == flag) return; + if (NULL == project || NULL == flag) { + return; + } opal_asprintf(&envname, "%s_MPI%s", project, flag); if (NULL == (envvalue = getenv(envname))) { @@ -438,18 +476,20 @@ load_env_data(const char *project, const char *flag, char **data) } free(envname); - if (NULL != *data) free(*data); + if (NULL != *data) { + free(*data); + } *data = strdup(envvalue); } - -static void -load_env_data_argv(const char *project, const char *flag, char ***data) +static void load_env_data_argv(const char *project, const char *flag, char ***data) { char *envname; char *envvalue; - if (NULL == project || NULL == flag) return; + if (NULL == project || NULL == flag) { + return; + } opal_asprintf(&envname, "%s_MPI%s", project, flag); if (NULL == (envvalue = getenv(envname))) { @@ -462,14 +502,14 @@ load_env_data_argv(const char *project, const char *flag, char ***data) } free(envname); - if (NULL != *data) opal_argv_free(*data); + if (NULL != *data) { + opal_argv_free(*data); + } *data = opal_argv_split(envvalue, ' '); } - -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int exit_status = 0, ret, flags = 0, i; int exec_argc = 0, user_argc = 0; @@ -490,27 +530,27 @@ main(int argc, char *argv[]) base_argv0 = opal_basename(argv[0]); #if defined(EXEEXT) - if( 0 != strlen(EXEEXT) ) { + if (0 != strlen(EXEEXT)) { char extension[] = EXEEXT; - char* temp = strstr( base_argv0, extension ); - char* old_match = temp; - while( NULL != temp ) { + char *temp = strstr(base_argv0, extension); + char *old_match = temp; + while (NULL != temp) { old_match = temp; - temp = strstr( temp + 1, extension ); + temp = strstr(temp + 1, extension); } /* Only if there was a match of .exe, erase the last occurence of .exe */ - if ( NULL != old_match ) { + if (NULL != old_match) { *old_match = '\0'; } } -#endif /* defined(EXEEXT) */ +#endif /* defined(EXEEXT) */ if (OPAL_SUCCESS != (ret = data_init(base_argv0))) { fprintf(stderr, "Error parsing data file %s: %s\n", base_argv0, opal_strerror(ret)); return ret; } - for (i = 1 ; i < argc && user_data_idx < 0 ; ++i) { + for (i = 1; i < argc && user_data_idx < 0; ++i) { user_data_idx = find_options_index(argv[i]); } /* if we didn't find a match, look for the NULL (base case) options */ @@ -520,28 +560,31 @@ main(int argc, char *argv[]) /* if we still didn't find a match, abort */ if (user_data_idx < 0) { char *flat = opal_argv_join(argv, ' '); - opal_show_help("help-opal-wrapper.txt", "no-options-support", true, - base_argv0, flat, NULL); + opal_show_help("help-opal-wrapper.txt", "no-options-support", true, base_argv0, flat, NULL); free(flat); exit(1); } /* compiler */ - load_env_data(options_data[user_data_idx].project_short, options_data[user_data_idx].compiler_env, &options_data[user_data_idx].compiler); + load_env_data(options_data[user_data_idx].project_short, + options_data[user_data_idx].compiler_env, &options_data[user_data_idx].compiler); /* preprocessor flags */ - load_env_data_argv(options_data[user_data_idx].project_short, "CPPFLAGS", &options_data[user_data_idx].preproc_flags); + load_env_data_argv(options_data[user_data_idx].project_short, "CPPFLAGS", + &options_data[user_data_idx].preproc_flags); /* compiler flags */ - load_env_data_argv(options_data[user_data_idx].project_short, options_data[user_data_idx].compiler_flags_env, + load_env_data_argv(options_data[user_data_idx].project_short, + options_data[user_data_idx].compiler_flags_env, &options_data[user_data_idx].comp_flags); /* linker flags */ - load_env_data_argv(options_data[user_data_idx].project_short, "LDFLAGS", &options_data[user_data_idx].link_flags); + load_env_data_argv(options_data[user_data_idx].project_short, "LDFLAGS", + &options_data[user_data_idx].link_flags); /* libs */ - load_env_data_argv(options_data[user_data_idx].project_short, "LIBS", &options_data[user_data_idx].libs); - + load_env_data_argv(options_data[user_data_idx].project_short, "LIBS", + &options_data[user_data_idx].libs); /**************************************************** * @@ -561,10 +604,12 @@ main(int argc, char *argv[]) if (options_data[user_data_idx].req_file[0] != '\0') { char *filename; struct stat buf; - filename = opal_os_path( false, options_data[user_data_idx].path_libdir, options_data[user_data_idx].req_file, NULL ); + filename = opal_os_path(false, options_data[user_data_idx].path_libdir, + options_data[user_data_idx].req_file, NULL); if (0 != stat(filename, &buf)) { - opal_show_help("help-opal-wrapper.txt", "file-not-found", true, - base_argv0, options_data[user_data_idx].req_file, options_data[user_data_idx].language, NULL); + opal_show_help("help-opal-wrapper.txt", "file-not-found", true, base_argv0, + options_data[user_data_idx].req_file, + options_data[user_data_idx].language, NULL); } } } @@ -574,68 +619,74 @@ main(int argc, char *argv[]) * Parse user flags * ****************************************************/ - flags = COMP_WANT_COMMAND|COMP_WANT_PREPROC| - COMP_WANT_COMPILE|COMP_WANT_LINK; + flags = COMP_WANT_COMMAND | COMP_WANT_PREPROC | COMP_WANT_COMPILE | COMP_WANT_LINK; user_argv = opal_argv_copy(argv + 1); user_argc = opal_argv_count(user_argv); - for (i = 0 ; i < user_argc ; ++i) { - if (0 == strncmp(user_argv[i], "-showme", strlen("-showme")) || - 0 == strncmp(user_argv[i], "--showme", strlen("--showme")) || - 0 == strncmp(user_argv[i], "-show", strlen("-show")) || - 0 == strncmp(user_argv[i], "--show", strlen("--show"))) { + for (i = 0; i < user_argc; ++i) { + if (0 == strncmp(user_argv[i], "-showme", strlen("-showme")) + || 0 == strncmp(user_argv[i], "--showme", strlen("--showme")) + || 0 == strncmp(user_argv[i], "-show", strlen("-show")) + || 0 == strncmp(user_argv[i], "--show", strlen("--show"))) { bool done_now = false; /* check for specific things we want to see. First three still invoke all the building routines. Last set want to parse out certain flags, so we don't go through the normal build routine - skip to cleanup. */ - if (0 == strncmp(user_argv[i], "-showme:command", strlen("-showme:command")) || - 0 == strncmp(user_argv[i], "--showme:command", strlen("--showme:command"))) { + if (0 == strncmp(user_argv[i], "-showme:command", strlen("-showme:command")) + || 0 == strncmp(user_argv[i], "--showme:command", strlen("--showme:command"))) { flags = COMP_WANT_COMMAND; /* we know what we want, so don't process any more args */ done_now = true; - } else if (0 == strncmp(user_argv[i], "-showme:compile", strlen("-showme:compile")) || - 0 == strncmp(user_argv[i], "--showme:compile", strlen("--showme:compile"))) { - flags = COMP_WANT_PREPROC|COMP_WANT_COMPILE; + } else if (0 == strncmp(user_argv[i], "-showme:compile", strlen("-showme:compile")) + || 0 + == strncmp(user_argv[i], "--showme:compile", + strlen("--showme:compile"))) { + flags = COMP_WANT_PREPROC | COMP_WANT_COMPILE; /* we know what we want, so don't process any more args */ done_now = true; - } else if (0 == strncmp(user_argv[i], "-showme:link", strlen("-showme:link")) || - 0 == strncmp(user_argv[i], "--showme:link", strlen("--showme:link"))) { - flags = COMP_WANT_COMPILE|COMP_WANT_LINK; + } else if (0 == strncmp(user_argv[i], "-showme:link", strlen("-showme:link")) + || 0 == strncmp(user_argv[i], "--showme:link", strlen("--showme:link"))) { + flags = COMP_WANT_COMPILE | COMP_WANT_LINK; /* we know what we want, so don't process any more args */ done_now = true; - } else if (0 == strncmp(user_argv[i], "-showme:incdirs", strlen("-showme:incdirs")) || - 0 == strncmp(user_argv[i], "--showme:incdirs", strlen("--showme:incdirs"))) { + } else if (0 == strncmp(user_argv[i], "-showme:incdirs", strlen("-showme:incdirs")) + || 0 + == strncmp(user_argv[i], "--showme:incdirs", + strlen("--showme:incdirs"))) { print_flags(options_data[user_data_idx].preproc_flags, OPAL_INCLUDE_FLAG); goto cleanup; - } else if (0 == strncmp(user_argv[i], "-showme:libdirs", strlen("-showme:libdirs")) || - 0 == strncmp(user_argv[i], "--showme:libdirs", strlen("--showme:libdirs"))) { + } else if (0 == strncmp(user_argv[i], "-showme:libdirs", strlen("-showme:libdirs")) + || 0 + == strncmp(user_argv[i], "--showme:libdirs", + strlen("--showme:libdirs"))) { print_flags(options_data[user_data_idx].link_flags, OPAL_LIBDIR_FLAG); goto cleanup; - } else if (0 == strncmp(user_argv[i], "-showme:libs", strlen("-showme:libs")) || - 0 == strncmp(user_argv[i], "--showme:libs", strlen("--showme:libs"))) { + } else if (0 == strncmp(user_argv[i], "-showme:libs", strlen("-showme:libs")) + || 0 == strncmp(user_argv[i], "--showme:libs", strlen("--showme:libs"))) { print_flags(options_data[user_data_idx].libs, "-l"); goto cleanup; - } else if (0 == strncmp(user_argv[i], "-showme:version", strlen("-showme:version")) || - 0 == strncmp(user_argv[i], "--showme:version", strlen("--showme:version"))) { - char * str; - str = opal_show_help_string("help-opal-wrapper.txt", - "version", false, - argv[0], options_data[user_data_idx].project, options_data[user_data_idx].version, options_data[user_data_idx].language, NULL); + } else if (0 == strncmp(user_argv[i], "-showme:version", strlen("-showme:version")) + || 0 + == strncmp(user_argv[i], "--showme:version", + strlen("--showme:version"))) { + char *str; + str = opal_show_help_string("help-opal-wrapper.txt", "version", false, argv[0], + options_data[user_data_idx].project, + options_data[user_data_idx].version, + options_data[user_data_idx].language, NULL); if (NULL != str) { printf("%s", str); free(str); } goto cleanup; - } else if (0 == strncmp(user_argv[i], "-showme:help", strlen("-showme:help")) || - 0 == strncmp(user_argv[i], "--showme:help", strlen("--showme:help"))) { + } else if (0 == strncmp(user_argv[i], "-showme:help", strlen("-showme:help")) + || 0 == strncmp(user_argv[i], "--showme:help", strlen("--showme:help"))) { char *str; - str = opal_show_help_string("help-opal-wrapper.txt", "usage", - false, argv[0], - options_data[user_data_idx].project, - NULL); + str = opal_show_help_string("help-opal-wrapper.txt", "usage", false, argv[0], + options_data[user_data_idx].project, NULL); if (NULL != str) { printf("%s", str); free(str); @@ -643,17 +694,15 @@ main(int argc, char *argv[]) exit_status = 0; goto cleanup; - } else if (0 == strncmp(user_argv[i], "-showme:", strlen("-showme:")) || - 0 == strncmp(user_argv[i], "--showme:", strlen("--showme:"))) { - fprintf(stderr, "%s: unrecognized option: %s\n", argv[0], - user_argv[i]); - fprintf(stderr, "Type '%s --showme:help' for usage.\n", - argv[0]); + } else if (0 == strncmp(user_argv[i], "-showme:", strlen("-showme:")) + || 0 == strncmp(user_argv[i], "--showme:", strlen("--showme:"))) { + fprintf(stderr, "%s: unrecognized option: %s\n", argv[0], user_argv[i]); + fprintf(stderr, "Type '%s --showme:help' for usage.\n", argv[0]); exit_status = 1; goto cleanup; } - flags |= (COMP_DRY_RUN|COMP_SHOW_ERROR); + flags |= (COMP_DRY_RUN | COMP_SHOW_ERROR); /* remove element from user_argv */ opal_argv_delete(&user_argc, &user_argv, i, 1); --i; @@ -666,8 +715,7 @@ main(int argc, char *argv[]) } else if (0 == strcmp(user_argv[i], "-c")) { flags &= ~COMP_WANT_LINK; real_flag = true; - } else if (0 == strcmp(user_argv[i], "-E") || - 0 == strcmp(user_argv[i], "-M")) { + } else if (0 == strcmp(user_argv[i], "-E") || 0 == strcmp(user_argv[i], "-M")) { flags &= ~(COMP_WANT_COMPILE | COMP_WANT_LINK); real_flag = true; } else if (0 == strcmp(user_argv[i], "-S")) { @@ -679,19 +727,17 @@ main(int argc, char *argv[]) /* remove element from user_argv */ opal_argv_delete(&user_argc, &user_argv, i, 1); --i; - } else if (0 == strcmp(user_argv[i], "-static") || - 0 == strcmp(user_argv[i], "--static") || - 0 == strcmp(user_argv[i], "-Bstatic") || - 0 == strcmp(user_argv[i], "-Wl,-static") || - 0 == strcmp(user_argv[i], "-Wl,--static") || - 0 == strcmp(user_argv[i], "-Wl,-Bstatic")) { + } else if (0 == strcmp(user_argv[i], "-static") || 0 == strcmp(user_argv[i], "--static") + || 0 == strcmp(user_argv[i], "-Bstatic") + || 0 == strcmp(user_argv[i], "-Wl,-static") + || 0 == strcmp(user_argv[i], "-Wl,--static") + || 0 == strcmp(user_argv[i], "-Wl,-Bstatic")) { flags |= COMP_WANT_STATIC; - } else if (0 == strcmp(user_argv[i], "-dynamic") || - 0 == strcmp(user_argv[i], "--dynamic") || - 0 == strcmp(user_argv[i], "-Bdynamic") || - 0 == strcmp(user_argv[i], "-Wl,-dynamic") || - 0 == strcmp(user_argv[i], "-Wl,--dynamic") || - 0 == strcmp(user_argv[i], "-Wl,-Bdynamic")) { + } else if (0 == strcmp(user_argv[i], "-dynamic") || 0 == strcmp(user_argv[i], "--dynamic") + || 0 == strcmp(user_argv[i], "-Bdynamic") + || 0 == strcmp(user_argv[i], "-Wl,-dynamic") + || 0 == strcmp(user_argv[i], "-Wl,--dynamic") + || 0 == strcmp(user_argv[i], "-Wl,-Bdynamic")) { flags &= ~COMP_WANT_STATIC; } else if (0 == strcmp(user_argv[i], "--openmpi:linkall")) { /* This is an intentionally undocummented wrapper compiler @@ -745,7 +791,7 @@ main(int argc, char *argv[]) opal_wrapper -showme a.c : don't clear our flags */ if (disable_flags && !((flags & COMP_DRY_RUN) && !real_flag)) { - flags &= ~(COMP_WANT_PREPROC|COMP_WANT_COMPILE|COMP_WANT_LINK); + flags &= ~(COMP_WANT_PREPROC | COMP_WANT_COMPILE | COMP_WANT_LINK); } /**************************************************** @@ -759,7 +805,7 @@ main(int argc, char *argv[]) exec_argv = opal_argv_split(options_data[user_data_idx].compiler, ' '); exec_argc = opal_argv_count(exec_argv); } else { - exec_argv = (char **) malloc(sizeof(char*)); + exec_argv = (char **) malloc(sizeof(char *)); exec_argv[0] = NULL; exec_argc = 0; } @@ -772,8 +818,7 @@ main(int argc, char *argv[]) } if (flags & COMP_WANT_COMPILE) { - opal_argv_insert(&exec_argv, exec_argc, - options_data[user_data_idx].comp_flags_prefix); + opal_argv_insert(&exec_argv, exec_argc, options_data[user_data_idx].comp_flags_prefix); exec_argc = opal_argv_count(exec_argv); } @@ -821,14 +866,16 @@ main(int argc, char *argv[]) */ - filename1 = opal_os_path( false, options_data[user_data_idx].path_libdir, options_data[user_data_idx].static_lib_file, NULL ); + filename1 = opal_os_path(false, options_data[user_data_idx].path_libdir, + options_data[user_data_idx].static_lib_file, NULL); if (0 == stat(filename1, &buf)) { have_static_lib = true; } else { have_static_lib = false; } - filename2 = opal_os_path( false, options_data[user_data_idx].path_libdir, options_data[user_data_idx].dyn_lib_file, NULL ); + filename2 = opal_os_path(false, options_data[user_data_idx].path_libdir, + options_data[user_data_idx].dyn_lib_file, NULL); if (0 == stat(filename2, &buf)) { have_dyn_lib = true; } else { @@ -844,7 +891,9 @@ main(int argc, char *argv[]) if (have_static_lib || have_dyn_lib) { use_static_libs = true; } else { - fprintf(stderr, "The linkall option has failed as we were unable to find either static or dynamic libs\n" + fprintf(stderr, + "The linkall option has failed as we were unable to find either static or " + "dynamic libs\n" "Files looked for:\n Static: %s\n Dynamic: %s\n", filename1, filename2); free(filename1); @@ -882,7 +931,6 @@ main(int argc, char *argv[]) exec_argc = opal_argv_count(exec_argv); } - /**************************************************** * * Execute the command @@ -902,24 +950,24 @@ main(int argc, char *argv[]) tmp = opal_path_findv(exec_argv[0], 0, environ, NULL); if (NULL == tmp) { - opal_show_help("help-opal-wrapper.txt", "no-compiler-found", true, - exec_argv[0], NULL); + opal_show_help("help-opal-wrapper.txt", "no-compiler-found", true, exec_argv[0], NULL); errno = 0; exit_status = 1; - } else { + } else { int status; free(exec_argv[0]); exec_argv[0] = tmp; ret = opal_few(exec_argv, &status); - exit_status = WIFEXITED(status) ? WEXITSTATUS(status) : - (WIFSIGNALED(status) ? WTERMSIG(status) : - (WIFSTOPPED(status) ? WSTOPSIG(status) : 255)); - if( (OPAL_SUCCESS != ret) || ((0 != exit_status) && (flags & COMP_SHOW_ERROR)) ) { - char* exec_command = opal_argv_join(exec_argv, ' '); - if( OPAL_SUCCESS != ret ) { - opal_show_help("help-opal-wrapper.txt", "spawn-failed", true, - exec_argv[0], strerror(status), exec_command, NULL); + exit_status = WIFEXITED(status) ? WEXITSTATUS(status) + : (WIFSIGNALED(status) + ? WTERMSIG(status) + : (WIFSTOPPED(status) ? WSTOPSIG(status) : 255)); + if ((OPAL_SUCCESS != ret) || ((0 != exit_status) && (flags & COMP_SHOW_ERROR))) { + char *exec_command = opal_argv_join(exec_argv, ' '); + if (OPAL_SUCCESS != ret) { + opal_show_help("help-opal-wrapper.txt", "spawn-failed", true, exec_argv[0], + strerror(status), exec_command, NULL); } else { #if 0 opal_show_help("help-opal-wrapper.txt", "compiler-failed", true, @@ -936,11 +984,13 @@ main(int argc, char *argv[]) * Cleanup * ****************************************************/ - cleanup: +cleanup: opal_argv_free(exec_argv); opal_argv_free(user_argv); - if (NULL != base_argv0) free(base_argv0); + if (NULL != base_argv0) { + free(base_argv0); + } if (OPAL_SUCCESS != (ret = data_finalize())) { return ret; diff --git a/opal/util/alfg.c b/opal/util/alfg.c index 2affae2cecf..40c5f7b7833 100644 --- a/opal/util/alfg.c +++ b/opal/util/alfg.c @@ -34,8 +34,7 @@ */ #define TAP1 127 #define TAP2 97 -#define CBIT 21 /* Canonical bit */ - +#define CBIT 21 /* Canonical bit */ /** * @brief Galois shift register: Used to seed the ALFG's @@ -45,13 +44,14 @@ * @param[out] uint32_t lsb: least significant bit of the Galois * register after shift */ -static uint32_t galois(unsigned int *seed){ +static uint32_t galois(unsigned int *seed) +{ uint32_t lsb; lsb = (*seed & 1) ? 1 : 0; *seed >>= 1; /* tap it with the mask */ - *seed = *seed ^ (lsb*MASK); + *seed = *seed ^ (lsb * MASK); return lsb; } @@ -65,7 +65,8 @@ static opal_rng_buff_t alfg_buffer; * @param[in] uint32_t seed * @param[out] opal_rng_buff_t *buff: handle to ALFG buffer state */ -int opal_srand(opal_rng_buff_t *buff, uint32_t seed) { +int opal_srand(opal_rng_buff_t *buff, uint32_t seed) +{ int i, j; uint32_t seed_cpy = seed; @@ -73,7 +74,7 @@ int opal_srand(opal_rng_buff_t *buff, uint32_t seed) { buff->tap2 = TAP2 - 1; /* zero out the register */ - for( i = 0; i < TAP1; i++){ + for (i = 0; i < TAP1; i++) { buff->alfg[i] = 0; } /* set the canonical bit */ @@ -81,17 +82,16 @@ int opal_srand(opal_rng_buff_t *buff, uint32_t seed) { /* seed the ALFG register by blasting * the canonical rectangle with bits - */ - for ( j = 1; j < TAP1; j++){ - for( i = 1; i < 32; i++){ - buff->alfg[j] = buff->alfg[j] ^ ((galois(&seed_cpy))<alfg[j] = buff->alfg[j] ^ ((galois(&seed_cpy)) << i); } } /* copy the ALFG to the global buffer */ memcpy(&alfg_buffer, buff, sizeof(alfg_buffer)); return 1; - } /** @@ -101,7 +101,8 @@ int opal_srand(opal_rng_buff_t *buff, uint32_t seed) { * @param[out] 32-bit unsigned random integer */ -uint32_t opal_rand(opal_rng_buff_t *buff){ +uint32_t opal_rand(opal_rng_buff_t *buff) +{ int *tap1 = &(buff->tap1); int *tap2 = &(buff->tap2); @@ -111,16 +112,15 @@ uint32_t opal_rand(opal_rng_buff_t *buff){ /* prevent overflow */ overflow = (uint64_t) buff->alfg[*tap1] + (uint64_t) buff->alfg[*tap2]; /* circular buffer arithmetic */ - temp = (*tap1 + 1) == TAP1 ? 0 : (*tap1 + 1); + temp = (*tap1 + 1) == TAP1 ? 0 : (*tap1 + 1); /* Division modulo 2^32 */ - buff->alfg[temp] = (uint32_t) ( overflow & ((1ULL<<32) -1)); + buff->alfg[temp] = (uint32_t)(overflow & ((1ULL << 32) - 1)); /* increment tap points */ - *tap1 = (*tap1 + 1)%TAP1; - *tap2 = (*tap2 + 1)%TAP1; + *tap1 = (*tap1 + 1) % TAP1; + *tap2 = (*tap2 + 1) % TAP1; return buff->alfg[temp]; - } /** @@ -129,7 +129,8 @@ uint32_t opal_rand(opal_rng_buff_t *buff){ * @param[in] none * @param[out] int, the same as normal rand(3) */ -int opal_random(void){ +int opal_random(void) +{ /* always return a positive int */ - return (int)(opal_rand(&alfg_buffer) & 0x7FFFFFFF); + return (int) (opal_rand(&alfg_buffer) & 0x7FFFFFFF); } diff --git a/opal/util/alfg.h b/opal/util/alfg.h index fe8b48c0fe1..7103ee0e7a3 100644 --- a/opal/util/alfg.h +++ b/opal/util/alfg.h @@ -17,7 +17,6 @@ #include "opal_stdint.h" - struct opal_rng_buff_t { uint32_t alfg[127]; int tap1; @@ -25,7 +24,6 @@ struct opal_rng_buff_t { }; typedef struct opal_rng_buff_t opal_rng_buff_t; - /* NOTE: UNLIKE OTHER OPAL FUNCTIONS, THIS FUNCTION RETURNS A 1 IF * SUCCESSFUL INSTEAD OF OPAL_SUCCESS */ OPAL_DECLSPEC int opal_srand(opal_rng_buff_t *buff, uint32_t seed); diff --git a/opal/util/arch.c b/opal/util/arch.c index 8c18ed5305f..8c6bd9b3872 100644 --- a/opal/util/arch.c +++ b/opal/util/arch.c @@ -23,16 +23,20 @@ uint32_t opal_local_arch = 0xFFFFFFFF; -static inline int32_t opal_arch_isbigendian ( void ) +static inline int32_t opal_arch_isbigendian(void) { const uint32_t value = 0x12345678; - const char *ptr = (char*)&value; + const char *ptr = (char *) &value; int x = 0; /* if( sizeof(int) == 8 ) x = 4; */ - if( ptr[x] == 0x12) return 1; /* big endian, true */ - if( ptr[x] == 0x78 ) return 0; /* little endian, false */ - assert( 0 ); /* unknown architecture not little nor big endian */ + if (ptr[x] == 0x12) { + return 1; /* big endian, true */ + } + if (ptr[x] == 0x78) { + return 0; /* little endian, false */ + } + assert(0); /* unknown architecture not little nor big endian */ return -1; } @@ -47,30 +51,30 @@ static inline int32_t opal_arch_isbigendian ( void ) * of the mantissa. If it's 1 then we have an intel representaion, if not * we have a sparc one. QED */ -static inline int32_t opal_arch_ldisintel( void ) +static inline int32_t opal_arch_ldisintel(void) { long double ld = 2.0; int i, j; - uint32_t* pui = (uint32_t*)(void*)&ld; + uint32_t *pui = (uint32_t *) (void *) &ld; j = LDBL_MANT_DIG / 32; i = (LDBL_MANT_DIG % 32) - 1; - if( opal_arch_isbigendian() ) { /* big endian */ + if (opal_arch_isbigendian()) { /* big endian */ j = (sizeof(long double) / sizeof(unsigned int)) - j; - if( i < 0 ) { + if (i < 0) { i = 31; - j = j+1; + j = j + 1; } } else { - if( i < 0 ) { + if (i < 0) { i = 31; - j = j-1; + j = j - 1; } } return ((pui[j] & (1u << i)) ? 1 : 0); } -static inline void opal_arch_setmask ( uint32_t *var, uint32_t mask) +static inline void opal_arch_setmask(uint32_t *var, uint32_t mask) { *var |= mask; } @@ -80,63 +84,69 @@ int opal_arch_init(void) opal_local_arch = (OPAL_ARCH_HEADERMASK | OPAL_ARCH_UNUSEDMASK); /* Handle the size of long (can hold a pointer) */ - if( 8 == sizeof(long) ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LONGIS64 ); + if (8 == sizeof(long)) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LONGIS64); + } /* sizeof bool */ - if (1 == sizeof(bool) ) { - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_BOOLIS8); + if (1 == sizeof(bool)) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_BOOLIS8); } else if (2 == sizeof(bool)) { - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_BOOLIS16); + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_BOOLIS16); } else if (4 == sizeof(bool)) { - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_BOOLIS32); + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_BOOLIS32); } /* Note that fortran logical size is set later, to make abstractions a little less painful... */ /* Initialize the information regarding the long double */ - if( 12 == sizeof(long double) ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LONGDOUBLEIS96 ); - else if( 16 == sizeof(long double) ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LONGDOUBLEIS128 ); + if (12 == sizeof(long double)) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LONGDOUBLEIS96); + } else if (16 == sizeof(long double)) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LONGDOUBLEIS128); + } /* Big endian or little endian ? That's the question */ - if( opal_arch_isbigendian() ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_ISBIGENDIAN ); + if (opal_arch_isbigendian()) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_ISBIGENDIAN); + } /* What's the maximum exponent ? */ - if ( LDBL_MAX_EXP == 16384 ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDEXPSIZEIS15 ); + if (LDBL_MAX_EXP == 16384) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDEXPSIZEIS15); + } /* How about the length in bits of the mantissa */ - if ( LDBL_MANT_DIG == 64 ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS64 ); - else if ( LDBL_MANT_DIG == 105 ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS105 ); - else if ( LDBL_MANT_DIG == 106 ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS106 ); - else if ( LDBL_MANT_DIG == 107 ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS107 ); - else if ( LDBL_MANT_DIG == 113 ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS113 ); + if (LDBL_MANT_DIG == 64) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDMANTDIGIS64); + } else if (LDBL_MANT_DIG == 105) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDMANTDIGIS105); + } else if (LDBL_MANT_DIG == 106) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDMANTDIGIS106); + } else if (LDBL_MANT_DIG == 107) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDMANTDIGIS107); + } else if (LDBL_MANT_DIG == 113) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDMANTDIGIS113); + } /* Intel data representation or Sparc ? */ - if( opal_arch_ldisintel() ) - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDISINTEL ); + if (opal_arch_ldisintel()) { + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LDISINTEL); + } return OPAL_SUCCESS; } -int32_t opal_arch_checkmask ( uint32_t *var, uint32_t mask ) +int32_t opal_arch_checkmask(uint32_t *var, uint32_t mask) { unsigned int tmpvar = *var; /* Check whether the headers are set correctly, or whether this is an erroneous integer */ - if( !((*var) & OPAL_ARCH_HEADERMASK) ) { - if( (*var) & OPAL_ARCH_HEADERMASK2 ) { - char* pcDest, *pcSrc; + if (!((*var) & OPAL_ARCH_HEADERMASK)) { + if ((*var) & OPAL_ARCH_HEADERMASK2) { + char *pcDest, *pcSrc; /* Both ends of this integer have the wrong settings, maybe its just the wrong endian-representation. Try to swap it and check again. If it looks now correct, @@ -144,33 +154,34 @@ int32_t opal_arch_checkmask ( uint32_t *var, uint32_t mask ) */ pcDest = (char *) &tmpvar; - pcSrc = (char *) var + 3; + pcSrc = (char *) var + 3; *pcDest++ = *pcSrc--; *pcDest++ = *pcSrc--; *pcDest++ = *pcSrc--; *pcDest++ = *pcSrc--; - if( (tmpvar & OPAL_ARCH_HEADERMASK) && (!(tmpvar & OPAL_ARCH_HEADERMASK2)) ) { + if ((tmpvar & OPAL_ARCH_HEADERMASK) && (!(tmpvar & OPAL_ARCH_HEADERMASK2))) { *var = tmpvar; - } else + } else { return -1; - } else + } + } else { return -1; + } } /* Here is the real evaluation of the bitmask */ - return ( ((*var) & mask) == mask ); + return (((*var) & mask) == mask); } -int -opal_arch_set_fortran_logical_size(uint32_t size) +int opal_arch_set_fortran_logical_size(uint32_t size) { if (1 == size) { - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LOGICALIS8); + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LOGICALIS8); } else if (2 == size) { - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LOGICALIS16); + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LOGICALIS16); } else if (4 == size) { - opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LOGICALIS32); + opal_arch_setmask(&opal_local_arch, OPAL_ARCH_LOGICALIS32); } return OPAL_SUCCESS; diff --git a/opal/util/arch.h b/opal/util/arch.h index a1a0446e1f3..115cd65af69 100644 --- a/opal/util/arch.h +++ b/opal/util/arch.h @@ -22,9 +22,8 @@ #include "opal_config.h" -#include #include - +#include /*************************************************** ** This file tries to classify the most relevant @@ -38,7 +37,6 @@ ** *****************************************************/ - /***************************************************************** ** Part 1: Integer representation. ** @@ -153,7 +151,6 @@ ** ? alpha supports both, big and little endian ***********************************************************************/ - /* Current conclusions: ** we need at the moment three settings: ** - big/little endian ? @@ -193,41 +190,41 @@ /* These masks implement the specification above above */ -#define OPAL_ARCH_HEADERMASK 0x03000000 /* set the fields for the header */ -#define OPAL_ARCH_HEADERMASK2 0x00000003 /* other end, needed for checks */ -#define OPAL_ARCH_UNUSEDMASK 0xfc000000 /* mark the unused fields */ +#define OPAL_ARCH_HEADERMASK 0x03000000 /* set the fields for the header */ +#define OPAL_ARCH_HEADERMASK2 0x00000003 /* other end, needed for checks */ +#define OPAL_ARCH_UNUSEDMASK 0xfc000000 /* mark the unused fields */ /* BYTE 1 */ -#define OPAL_ARCH_ISBIGENDIAN 0x00000008 +#define OPAL_ARCH_ISBIGENDIAN 0x00000008 /* BYTE 2 */ -#define OPAL_ARCH_LONGISxx 0x0000c000 /* mask for sizeof long */ -#define OPAL_ARCH_LONGIS64 0x00001000 -#define OPAL_ARCH_LONGLONGISxx 0x00003000 /* mask for sizeof long long */ +#define OPAL_ARCH_LONGISxx 0x0000c000 /* mask for sizeof long */ +#define OPAL_ARCH_LONGIS64 0x00001000 +#define OPAL_ARCH_LONGLONGISxx 0x00003000 /* mask for sizeof long long */ -#define OPAL_ARCH_BOOLISxx 0x00000c00 /* mask for sizeof bool */ -#define OPAL_ARCH_BOOLIS8 0x00000000 /* bool is 8 bits */ -#define OPAL_ARCH_BOOLIS16 0x00000400 /* bool is 16 bits */ -#define OPAL_ARCH_BOOLIS32 0x00000800 /* bool is 32 bits */ +#define OPAL_ARCH_BOOLISxx 0x00000c00 /* mask for sizeof bool */ +#define OPAL_ARCH_BOOLIS8 0x00000000 /* bool is 8 bits */ +#define OPAL_ARCH_BOOLIS16 0x00000400 /* bool is 16 bits */ +#define OPAL_ARCH_BOOLIS32 0x00000800 /* bool is 32 bits */ -#define OPAL_ARCH_LOGICALISxx 0x00000300 /* mask for sizeof Fortran logical */ -#define OPAL_ARCH_LOGICALIS8 0x00000000 /* logical is 8 bits */ -#define OPAL_ARCH_LOGICALIS16 0x00000100 /* logical is 16 bits */ -#define OPAL_ARCH_LOGICALIS32 0x00000200 /* logical is 32 bits */ +#define OPAL_ARCH_LOGICALISxx 0x00000300 /* mask for sizeof Fortran logical */ +#define OPAL_ARCH_LOGICALIS8 0x00000000 /* logical is 8 bits */ +#define OPAL_ARCH_LOGICALIS16 0x00000100 /* logical is 16 bits */ +#define OPAL_ARCH_LOGICALIS32 0x00000200 /* logical is 32 bits */ /* BYTE 3 */ #define OPAL_ARCH_LONGDOUBLEIS96 0x00020000 #define OPAL_ARCH_LONGDOUBLEIS128 0x00010000 -#define OPAL_ARCH_LDEXPSIZEIS15 0x00080000 +#define OPAL_ARCH_LDEXPSIZEIS15 0x00080000 -#define OPAL_ARCH_LDMANTDIGIS64 0x00400000 -#define OPAL_ARCH_LDMANTDIGIS105 0x00200000 -#define OPAL_ARCH_LDMANTDIGIS106 0x00600000 -#define OPAL_ARCH_LDMANTDIGIS107 0x00100000 -#define OPAL_ARCH_LDMANTDIGIS113 0x00500000 +#define OPAL_ARCH_LDMANTDIGIS64 0x00400000 +#define OPAL_ARCH_LDMANTDIGIS105 0x00200000 +#define OPAL_ARCH_LDMANTDIGIS106 0x00600000 +#define OPAL_ARCH_LDMANTDIGIS107 0x00100000 +#define OPAL_ARCH_LDMANTDIGIS113 0x00500000 -#define OPAL_ARCH_LDISINTEL 0x00800000 +#define OPAL_ARCH_LDISINTEL 0x00800000 BEGIN_C_DECLS @@ -237,12 +234,11 @@ OPAL_DECLSPEC extern uint32_t opal_local_arch; /* Initialize architecture and determine all but fortran logical fields */ OPAL_DECLSPEC int opal_arch_init(void); -OPAL_DECLSPEC int32_t opal_arch_checkmask ( uint32_t *var, uint32_t mask ); +OPAL_DECLSPEC int32_t opal_arch_checkmask(uint32_t *var, uint32_t mask); /* Set fortran logical fields after init, to keep fortran out of opal... */ OPAL_DECLSPEC int opal_arch_set_fortran_logical_size(uint32_t size); END_C_DECLS -#endif /* OPAL_ARCH_H_HAS_BEEN_INCLUDED */ - +#endif /* OPAL_ARCH_H_HAS_BEEN_INCLUDED */ diff --git a/opal/util/argv.c b/opal/util/argv.c index 2464013e46c..cc725db824b 100644 --- a/opal/util/argv.c +++ b/opal/util/argv.c @@ -25,13 +25,12 @@ #include #include +#include "opal/constants.h" #include "opal/util/argv.h" #include "opal/util/string_copy.h" -#include "opal/constants.h" #define ARGSIZE 128 - /* * Append a string to the end of a new or existing argv array. */ @@ -53,24 +52,24 @@ int opal_argv_append_nosize(char ***argv, const char *arg) { int argc; - /* Create new argv. */ + /* Create new argv. */ - if (NULL == *argv) { - *argv = (char**) malloc(2 * sizeof(char *)); if (NULL == *argv) { - return OPAL_ERR_OUT_OF_RESOURCE; + *argv = (char **) malloc(2 * sizeof(char *)); + if (NULL == *argv) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + argc = 0; + (*argv)[0] = NULL; + (*argv)[1] = NULL; } - argc = 0; - (*argv)[0] = NULL; - (*argv)[1] = NULL; - } - /* Extend existing argv. */ - else { + /* Extend existing argv. */ + else { /* count how many entries currently exist */ argc = opal_argv_count(*argv); - *argv = (char**) realloc(*argv, (argc + 2) * sizeof(char *)); + *argv = (char **) realloc(*argv, (argc + 2) * sizeof(char *)); if (NULL == *argv) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -97,7 +96,7 @@ int opal_argv_prepend_nosize(char ***argv, const char *arg) /* Create new argv. */ if (NULL == *argv) { - *argv = (char**) malloc(2 * sizeof(char *)); + *argv = (char **) malloc(2 * sizeof(char *)); if (NULL == *argv) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -107,15 +106,15 @@ int opal_argv_prepend_nosize(char ***argv, const char *arg) /* count how many entries currently exist */ argc = opal_argv_count(*argv); - *argv = (char**) realloc(*argv, (argc + 2) * sizeof(char *)); + *argv = (char **) realloc(*argv, (argc + 2) * sizeof(char *)); if (NULL == *argv) { return OPAL_ERR_OUT_OF_RESOURCE; } - (*argv)[argc+1] = NULL; + (*argv)[argc + 1] = NULL; /* shift all existing elements down 1 */ - for (i=argc; 0 < i; i--) { - (*argv)[i] = (*argv)[i-1]; + for (i = argc; 0 < i; i--) { + (*argv)[i] = (*argv)[i - 1]; } (*argv)[0] = strdup(arg); } @@ -135,7 +134,7 @@ int opal_argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite } /* see if this arg is already present in the array */ - for (i=0; NULL != (*argv)[i]; i++) { + for (i = 0; NULL != (*argv)[i]; i++) { if (0 == strcmp(arg, (*argv)[i])) { /* already exists - are we authorized to overwrite? */ if (overwrite) { @@ -155,94 +154,97 @@ int opal_argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite */ void opal_argv_free(char **argv) { - char **p; + char **p; - if (NULL == argv) - return; + if (NULL == argv) { + return; + } - for (p = argv; NULL != *p; ++p) { - free(*p); - } + for (p = argv; NULL != *p; ++p) { + free(*p); + } - free(argv); + free(argv); } - /* * Split a string into a NULL-terminated argv array. */ -static char **opal_argv_split_inter(const char *src_string, int delimiter, - int include_empty) +static char **opal_argv_split_inter(const char *src_string, int delimiter, int include_empty) { - char arg[ARGSIZE]; - char **argv = NULL; - const char *p; - char *argtemp; - int argc = 0; - size_t arglen; - - while (src_string && *src_string) { - p = src_string; - arglen = 0; + char arg[ARGSIZE]; + char **argv = NULL; + const char *p; + char *argtemp; + int argc = 0; + size_t arglen; + + while (src_string && *src_string) { + p = src_string; + arglen = 0; + + while (('\0' != *p) && (*p != delimiter)) { + ++p; + ++arglen; + } - while (('\0' != *p) && (*p != delimiter)) { - ++p; - ++arglen; - } + /* zero length argument, skip */ - /* zero length argument, skip */ + if (src_string == p) { + if (include_empty) { + arg[0] = '\0'; + if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, arg)) { + return NULL; + } + } + } - if (src_string == p) { - if (include_empty) { - arg[0] = '\0'; - if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, arg)) - return NULL; - } - } + /* tail argument, add straight from the original string */ - /* tail argument, add straight from the original string */ + else if ('\0' == *p) { + if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, src_string)) { + return NULL; + } + src_string = p; + continue; + } - else if ('\0' == *p) { - if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, src_string)) - return NULL; - src_string = p; - continue; - } + /* long argument, malloc buffer, copy and add */ - /* long argument, malloc buffer, copy and add */ + else if (arglen > (ARGSIZE - 1)) { + argtemp = (char *) malloc(arglen + 1); + if (NULL == argtemp) { + return NULL; + } - else if (arglen > (ARGSIZE - 1)) { - argtemp = (char*) malloc(arglen + 1); - if (NULL == argtemp) - return NULL; + opal_string_copy(argtemp, src_string, arglen + 1); + argtemp[arglen] = '\0'; - opal_string_copy(argtemp, src_string, arglen + 1); - argtemp[arglen] = '\0'; + if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, argtemp)) { + free(argtemp); + return NULL; + } - if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, argtemp)) { - free(argtemp); - return NULL; - } + free(argtemp); + } - free(argtemp); - } + /* short argument, copy to buffer and add */ - /* short argument, copy to buffer and add */ + else { + opal_string_copy(arg, src_string, arglen + 1); + arg[arglen] = '\0'; - else { - opal_string_copy(arg, src_string, arglen + 1); - arg[arglen] = '\0'; + if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, arg)) { + return NULL; + } + } - if (OPAL_SUCCESS != opal_argv_append(&argc, &argv, arg)) - return NULL; + src_string = p + 1; } - src_string = p + 1; - } - - /* All done */ + /* All done */ - return argv; + return argv; } char **opal_argv_split(const char *src_string, int delimiter) @@ -260,75 +262,76 @@ char **opal_argv_split_with_empty(const char *src_string, int delimiter) */ int opal_argv_count(char **argv) { - char **p; - int i; + char **p; + int i; - if (NULL == argv) - return 0; + if (NULL == argv) { + return 0; + } - for (i = 0, p = argv; *p; i++, p++) - continue; + for (i = 0, p = argv; *p; i++, p++) { + continue; + } - return i; + return i; } - /* * Join all the elements of an argv array into a single * newly-allocated string. */ char *opal_argv_join(char **argv, int delimiter) { - char **p; - char *pp; - char *str; - size_t str_len = 0; - size_t i; + char **p; + char *pp; + char *str; + size_t str_len = 0; + size_t i; - /* Bozo case */ + /* Bozo case */ - if (NULL == argv || NULL == argv[0]) { - return strdup(""); - } + if (NULL == argv || NULL == argv[0]) { + return strdup(""); + } - /* Find the total string length in argv including delimiters. The - last delimiter is replaced by the NULL character. */ + /* Find the total string length in argv including delimiters. The + last delimiter is replaced by the NULL character. */ - for (p = argv; *p; ++p) { - str_len += strlen(*p) + 1; - } + for (p = argv; *p; ++p) { + str_len += strlen(*p) + 1; + } - /* Allocate the string. */ + /* Allocate the string. */ - if (NULL == (str = (char*) malloc(str_len))) - return NULL; + if (NULL == (str = (char *) malloc(str_len))) { + return NULL; + } - /* Loop filling in the string. */ + /* Loop filling in the string. */ - str[--str_len] = '\0'; - p = argv; - pp = *p; + str[--str_len] = '\0'; + p = argv; + pp = *p; - for (i = 0; i < str_len; ++i) { - if ('\0' == *pp) { + for (i = 0; i < str_len; ++i) { + if ('\0' == *pp) { - /* End of a string, fill in a delimiter and go to the next - string. */ + /* End of a string, fill in a delimiter and go to the next + string. */ - str[i] = (char) delimiter; - ++p; - pp = *p; - } else { - str[i] = *pp++; + str[i] = (char) delimiter; + ++p; + pp = *p; + } else { + str[i] = *pp++; + } } - } - /* All done */ + /* All done */ - return str; + return str; } - /* * Join all the elements of an argv array from within a * specified range into a single newly-allocated string. @@ -343,14 +346,14 @@ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) /* Bozo case */ - if (NULL == argv || NULL == argv[0] || (int)start >= opal_argv_count(argv)) { + if (NULL == argv || NULL == argv[0] || (int) start >= opal_argv_count(argv)) { return strdup(""); } /* Find the total string length in argv including delimiters. The last delimiter is replaced by the NULL character. */ - for (p = &argv[start], i=start; *p && i < end; ++p, ++i) { + for (p = &argv[start], i = start; *p && i < end; ++p, ++i) { str_len += strlen(*p) + 1; } @@ -360,7 +363,7 @@ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) /* Allocate the string. */ - if (NULL == (str = (char*) malloc(str_len))) { + if (NULL == (str = (char *) malloc(str_len))) { return NULL; } @@ -389,59 +392,58 @@ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) return str; } - /* * Return the number of bytes consumed by an argv array. */ size_t opal_argv_len(char **argv) { - char **p; - size_t length; + char **p; + size_t length; - if (NULL == argv) - return (size_t) 0; + if (NULL == argv) { + return (size_t) 0; + } - length = sizeof(char *); + length = sizeof(char *); - for (p = argv; *p; ++p) { - length += strlen(*p) + 1 + sizeof(char *); - } + for (p = argv; *p; ++p) { + length += strlen(*p) + 1 + sizeof(char *); + } - return length; + return length; } - /* * Copy a NULL-terminated argv array. */ char **opal_argv_copy(char **argv) { - char **dupv = NULL; - int dupc = 0; + char **dupv = NULL; + int dupc = 0; - if (NULL == argv) - return NULL; + if (NULL == argv) { + return NULL; + } - /* create an "empty" list, so that we return something valid if we - were passed a valid list with no contained elements */ - dupv = (char**) malloc(sizeof(char*)); - dupv[0] = NULL; + /* create an "empty" list, so that we return something valid if we + were passed a valid list with no contained elements */ + dupv = (char **) malloc(sizeof(char *)); + dupv[0] = NULL; - while (NULL != *argv) { - if (OPAL_SUCCESS != opal_argv_append(&dupc, &dupv, *argv)) { - opal_argv_free(dupv); - return NULL; - } + while (NULL != *argv) { + if (OPAL_SUCCESS != opal_argv_append(&dupc, &dupv, *argv)) { + opal_argv_free(dupv); + return NULL; + } - ++argv; - } + ++argv; + } - /* All done */ + /* All done */ - return dupv; + return dupv; } - int opal_argv_delete(int *argc, char ***argv, int start, int num_to_delete) { int i; @@ -485,8 +487,10 @@ int opal_argv_delete(int *argc, char ***argv, int start, int num_to_delete) (*argv)[i] = NULL; /* adjust the argv array */ - tmp = (char**)realloc(*argv, sizeof(char*) * (i + 1)); - if (NULL != tmp) *argv = tmp; + tmp = (char **) realloc(*argv, sizeof(char *) * (i + 1)); + if (NULL != tmp) { + *argv = tmp; + } /* adjust the argc */ (*argc) -= num_to_delete; @@ -494,7 +498,6 @@ int opal_argv_delete(int *argc, char ***argv, int start, int num_to_delete) return OPAL_SUCCESS; } - int opal_argv_insert(char ***target, int start, char **source) { int i, source_count, target_count; @@ -524,15 +527,13 @@ int opal_argv_insert(char ***target, int start, char **source) /* Alloc out new space */ - *target = (char**) realloc(*target, - sizeof(char *) * (target_count + source_count + 1)); + *target = (char **) realloc(*target, sizeof(char *) * (target_count + source_count + 1)); /* Move suffix items down to the end */ suffix_count = target_count - start; for (i = suffix_count - 1; i >= 0; --i) { - (*target)[start + source_count + i] = - (*target)[start + i]; + (*target)[start + source_count + i] = (*target)[start + i]; } (*target)[start + suffix_count + source_count] = NULL; @@ -569,14 +570,12 @@ int opal_argv_insert_element(char ***target, int location, char *source) } /* Alloc out new space */ - *target = (char**) realloc(*target, - sizeof(char*) * (target_count + 2)); + *target = (char **) realloc(*target, sizeof(char *) * (target_count + 2)); /* Move suffix items down to the end */ suffix_count = target_count - location; for (i = suffix_count - 1; i >= 0; --i) { - (*target)[location + 1 + i] = - (*target)[location + i]; + (*target)[location + 1 + i] = (*target)[location + i]; } (*target)[location + suffix_count + 1] = NULL; diff --git a/opal/util/argv.h b/opal/util/argv.h index c119d1b0bd8..24eea933119 100644 --- a/opal/util/argv.h +++ b/opal/util/argv.h @@ -33,58 +33,59 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif BEGIN_C_DECLS - /** - * Append a string (by value) to an new or existing NULL-terminated - * argv array. - * - * @param argc Pointer to the length of the argv array. Must not be - * NULL. - * @param argv Pointer to an argv array. - * @param str Pointer to the string to append. - * - * @retval OPAL_SUCCESS On success - * @retval OPAL_ERROR On failure - * - * This function adds a string to an argv array of strings by value; - * it is permissable to pass a string on the stack as the str - * argument to this function. - * - * To add the first entry to an argv array, call this function with - * (*argv == NULL). This function will allocate an array of length - * 2; the first entry will point to a copy of the string passed in - * arg, the second entry will be set to NULL. - * - * If (*argv != NULL), it will be realloc'ed to be 1 (char*) larger, - * and the next-to-last entry will point to a copy of the string - * passed in arg. The last entry will be set to NULL. - * - * Just to reinforce what was stated above: the string is copied by - * value into the argv array; there is no need to keep the original - * string (i.e., the arg parameter) after invoking this function. - */ -OPAL_DECLSPEC int opal_argv_append(int *argc, char ***argv, const char *arg) __opal_attribute_nonnull__(1) __opal_attribute_nonnull__(3); +/** + * Append a string (by value) to an new or existing NULL-terminated + * argv array. + * + * @param argc Pointer to the length of the argv array. Must not be + * NULL. + * @param argv Pointer to an argv array. + * @param str Pointer to the string to append. + * + * @retval OPAL_SUCCESS On success + * @retval OPAL_ERROR On failure + * + * This function adds a string to an argv array of strings by value; + * it is permissable to pass a string on the stack as the str + * argument to this function. + * + * To add the first entry to an argv array, call this function with + * (*argv == NULL). This function will allocate an array of length + * 2; the first entry will point to a copy of the string passed in + * arg, the second entry will be set to NULL. + * + * If (*argv != NULL), it will be realloc'ed to be 1 (char*) larger, + * and the next-to-last entry will point to a copy of the string + * passed in arg. The last entry will be set to NULL. + * + * Just to reinforce what was stated above: the string is copied by + * value into the argv array; there is no need to keep the original + * string (i.e., the arg parameter) after invoking this function. + */ +OPAL_DECLSPEC int opal_argv_append(int *argc, char ***argv, const char *arg) + __opal_attribute_nonnull__(1) __opal_attribute_nonnull__(3); - /** - * Append to an argv-style array, but ignore the size of the array. - * - * @param argv Pointer to an argv array. - * @param str Pointer to the string to append. - * - * @retval OPAL_SUCCESS On success - * @retval OPAL_ERROR On failure - * - * This function is identical to the opal_argv_append() function - * except that it does not take a pointer to an argc (integer - * representing the size of the array). This is handy for - * argv-style arrays that do not have integers that are actively - * maintaing their sizes. - */ -OPAL_DECLSPEC int opal_argv_append_nosize(char ***argv, const char *arg); +/** + * Append to an argv-style array, but ignore the size of the array. + * + * @param argv Pointer to an argv array. + * @param str Pointer to the string to append. + * + * @retval OPAL_SUCCESS On success + * @retval OPAL_ERROR On failure + * + * This function is identical to the opal_argv_append() function + * except that it does not take a pointer to an argc (integer + * representing the size of the array). This is handy for + * argv-style arrays that do not have integers that are actively + * maintaing their sizes. + */ +OPAL_DECLSPEC int opal_argv_append_nosize(char ***argv, const char *arg); /** * Insert the provided arg at the beginning of the array @@ -112,164 +113,168 @@ OPAL_DECLSPEC int opal_argv_prepend_nosize(char ***argv, const char *arg); * except that it only appends the provided argument if it does not already * exist in the provided array, or overwrites it if it is. */ -OPAL_DECLSPEC int opal_argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite); +OPAL_DECLSPEC int opal_argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite); /** - * Free a NULL-terminated argv array. - * - * @param argv Argv array to free. - * - * This function frees an argv array and all of the strings that it - * contains. Since the argv parameter is passed by value, it is not - * set to NULL in the caller's scope upon return. - * - * It is safe to invoke this function with a NULL pointer. It is - * not safe to invoke this function with a non-NULL-terminated argv - * array. - */ -OPAL_DECLSPEC void opal_argv_free(char **argv); + * Free a NULL-terminated argv array. + * + * @param argv Argv array to free. + * + * This function frees an argv array and all of the strings that it + * contains. Since the argv parameter is passed by value, it is not + * set to NULL in the caller's scope upon return. + * + * It is safe to invoke this function with a NULL pointer. It is + * not safe to invoke this function with a non-NULL-terminated argv + * array. + */ +OPAL_DECLSPEC void opal_argv_free(char **argv); - /** - * Split a string into a NULL-terminated argv array. Do not include empty - * strings in result array. - * - * @param src_string Input string. - * @param delimiter Delimiter character. - * - * @retval argv pointer to new argv array on success - * @retval NULL on error - * - * All strings are inserted into the argv array by value; the - * newly-allocated array makes no references to the src_string - * argument (i.e., it can be freed after calling this function - * without invalidating the output argv). - */ -OPAL_DECLSPEC char **opal_argv_split(const char *src_string, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * Split a string into a NULL-terminated argv array. Do not include empty + * strings in result array. + * + * @param src_string Input string. + * @param delimiter Delimiter character. + * + * @retval argv pointer to new argv array on success + * @retval NULL on error + * + * All strings are inserted into the argv array by value; the + * newly-allocated array makes no references to the src_string + * argument (i.e., it can be freed after calling this function + * without invalidating the output argv). + */ +OPAL_DECLSPEC char **opal_argv_split(const char *src_string, int delimiter) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * Split a string into a NULL-terminated argv array. Include empty - * strings in result array. - * - * @param src_string Input string. - * @param delimiter Delimiter character. - * - * @retval argv pointer to new argv array on success - * @retval NULL on error - * - * All strings are inserted into the argv array by value; the - * newly-allocated array makes no references to the src_string - * argument (i.e., it can be freed after calling this function - * without invalidating the output argv). - */ -OPAL_DECLSPEC char **opal_argv_split_with_empty(const char *src_string, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * Split a string into a NULL-terminated argv array. Include empty + * strings in result array. + * + * @param src_string Input string. + * @param delimiter Delimiter character. + * + * @retval argv pointer to new argv array on success + * @retval NULL on error + * + * All strings are inserted into the argv array by value; the + * newly-allocated array makes no references to the src_string + * argument (i.e., it can be freed after calling this function + * without invalidating the output argv). + */ +OPAL_DECLSPEC char **opal_argv_split_with_empty(const char *src_string, int delimiter) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * Return the length of a NULL-terminated argv array. - * - * @param argv The input argv array. - * - * @retval 0 If NULL is passed as argv. - * @retval count Number of entries in the argv array. - * - * The argv array must be NULL-terminated. - */ -OPAL_DECLSPEC int opal_argv_count(char **argv); +/** + * Return the length of a NULL-terminated argv array. + * + * @param argv The input argv array. + * + * @retval 0 If NULL is passed as argv. + * @retval count Number of entries in the argv array. + * + * The argv array must be NULL-terminated. + */ +OPAL_DECLSPEC int opal_argv_count(char **argv); - /** - * Join all the elements of an argv array into a single - * newly-allocated string. - * - * @param argv The input argv array. - * @param delimiter Delimiter character placed between each argv string. - * - * @retval new_string Output string on success. - * @retval NULL On failure. - * - * Similar to the Perl join function, this function takes an input - * argv and joins them into into a single string separated by the - * delimiter character. - * - * It is the callers responsibility to free the returned string. - */ -OPAL_DECLSPEC char *opal_argv_join(char **argv, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * Join all the elements of an argv array into a single + * newly-allocated string. + * + * @param argv The input argv array. + * @param delimiter Delimiter character placed between each argv string. + * + * @retval new_string Output string on success. + * @retval NULL On failure. + * + * Similar to the Perl join function, this function takes an input + * argv and joins them into into a single string separated by the + * delimiter character. + * + * It is the callers responsibility to free the returned string. + */ +OPAL_DECLSPEC char *opal_argv_join(char **argv, int delimiter) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; -OPAL_DECLSPEC char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * Return the number of bytes consumed by an argv array. - * - * @param argv The input argv array. - * - * Count the number of bytes consumed by a NULL-terminated argv - * array. This includes the number of bytes used by each of the - * strings as well as the pointers used in the argv array. - */ -OPAL_DECLSPEC size_t opal_argv_len(char **argv); +/** + * Return the number of bytes consumed by an argv array. + * + * @param argv The input argv array. + * + * Count the number of bytes consumed by a NULL-terminated argv + * array. This includes the number of bytes used by each of the + * strings as well as the pointers used in the argv array. + */ +OPAL_DECLSPEC size_t opal_argv_len(char **argv); - /** - * Copy a NULL-terminated argv array. - * - * @param argv The input argv array. - * - * @retval argv Copied argv array on success. - * @retval NULL On failure. - * - * Copy an argv array, including copying all off its strings. - * Specifically, the output argv will be an array of the same length - * as the input argv, and strcmp(argv_in[i], argv_out[i]) will be 0. - */ -OPAL_DECLSPEC char **opal_argv_copy(char **argv) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * Copy a NULL-terminated argv array. + * + * @param argv The input argv array. + * + * @retval argv Copied argv array on success. + * @retval NULL On failure. + * + * Copy an argv array, including copying all off its strings. + * Specifically, the output argv will be an array of the same length + * as the input argv, and strcmp(argv_in[i], argv_out[i]) will be 0. + */ +OPAL_DECLSPEC char ** +opal_argv_copy(char **argv) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * Delete one or more tokens from the middle of an argv. - * - * @param argv The argv to delete from - * @param start The index of the first token to delete - * @param num_to_delete How many tokens to delete - * - * @retval OPAL_SUCCESS Always - * - * Delete some tokens from within an existing argv. The start - * parameter specifies the first token to delete, and will delete - * (num_to_delete-1) tokens following it. argv will be realloc()ed - * to *argc - num_deleted size. - * - * If start is beyond the end of the argv array, this function is - * a no-op. - * - * If num_to_delete runs beyond the end of the argv array, this - * function will delete all tokens starting with start to the end - * of the array. - * - * All deleted items in the argv array will have their contents - * free()ed (it is assumed that the argv "owns" the memory that - * the pointer points to). - */ -OPAL_DECLSPEC int opal_argv_delete(int *argc, char ***argv, - int start, int num_to_delete); +/** + * Delete one or more tokens from the middle of an argv. + * + * @param argv The argv to delete from + * @param start The index of the first token to delete + * @param num_to_delete How many tokens to delete + * + * @retval OPAL_SUCCESS Always + * + * Delete some tokens from within an existing argv. The start + * parameter specifies the first token to delete, and will delete + * (num_to_delete-1) tokens following it. argv will be realloc()ed + * to *argc - num_deleted size. + * + * If start is beyond the end of the argv array, this function is + * a no-op. + * + * If num_to_delete runs beyond the end of the argv array, this + * function will delete all tokens starting with start to the end + * of the array. + * + * All deleted items in the argv array will have their contents + * free()ed (it is assumed that the argv "owns" the memory that + * the pointer points to). + */ +OPAL_DECLSPEC int opal_argv_delete(int *argc, char ***argv, int start, int num_to_delete); - /** - * Insert one argv array into the middle of another - * - * @param target The argv to insert tokens into - * @param start Index where the first token will be placed in target - * @param source The argv to copy tokens from - * - * @retval OPAL_SUCCESS upon success - * @retval OPAL_BAD_PARAM if any parameters are non-sensical - * - * This function takes one arg and inserts it in the middle of - * another. The first token in source will be inserted at index - * start in the target argv; all other tokens will follow it. - * Similar to opal_argv_append(), the target may be realloc()'ed - * to accomodate the new storage requirements. - * - * The source array is left unaffected -- its contents are copied - * by value over to the target array (i.e., the strings that - * source points to are strdup'ed into the new locations in - * target). - */ -OPAL_DECLSPEC int opal_argv_insert(char ***target, int start, char **source); +/** + * Insert one argv array into the middle of another + * + * @param target The argv to insert tokens into + * @param start Index where the first token will be placed in target + * @param source The argv to copy tokens from + * + * @retval OPAL_SUCCESS upon success + * @retval OPAL_BAD_PARAM if any parameters are non-sensical + * + * This function takes one arg and inserts it in the middle of + * another. The first token in source will be inserted at index + * start in the target argv; all other tokens will follow it. + * Similar to opal_argv_append(), the target may be realloc()'ed + * to accomodate the new storage requirements. + * + * The source array is left unaffected -- its contents are copied + * by value over to the target array (i.e., the strings that + * source points to are strdup'ed into the new locations in + * target). + */ +OPAL_DECLSPEC int opal_argv_insert(char ***target, int start, char **source); /** * Insert one argv element in front of a specific position in an array @@ -292,7 +297,7 @@ OPAL_DECLSPEC int opal_argv_insert(char ***target, int start, char **source); * source points to is strdup'ed into the new location in * target). */ -OPAL_DECLSPEC int opal_argv_insert_element(char ***target, int location, char *source); +OPAL_DECLSPEC int opal_argv_insert_element(char ***target, int location, char *source); END_C_DECLS diff --git a/opal/util/basename.c b/opal/util/basename.c index ab63e48e427..0a57b070788 100644 --- a/opal/util/basename.c +++ b/opal/util/basename.c @@ -25,8 +25,8 @@ #include #include #ifdef HAVE_LIBGEN_H -#include -#endif /* HAVE_LIBGEN_H */ +# include +#endif /* HAVE_LIBGEN_H */ #include "opal/util/basename.h" #include "opal/util/os_path.h" @@ -38,22 +38,24 @@ * of characters. * If the last character on the string is a path separator, it will be skipped. */ -static inline char* opal_find_last_path_separator( const char* filename, size_t n ) +static inline char *opal_find_last_path_separator(const char *filename, size_t n) { - char* p = (char*)filename + n; + char *p = (char *) filename + n; /* First skip the latest separators */ - for ( ; p >= filename; p-- ) { - if( *p != OPAL_PATH_SEP[0] ) + for (; p >= filename; p--) { + if (*p != OPAL_PATH_SEP[0]) { break; + } } - for ( ; p >= filename; p-- ) { - if( *p == OPAL_PATH_SEP[0] ) + for (; p >= filename; p--) { + if (*p == OPAL_PATH_SEP[0]) { return p; + } } - return NULL; /* nothing found inside the filename */ + return NULL; /* nothing found inside the filename */ } char *opal_basename(const char *filename) @@ -88,7 +90,7 @@ char *opal_basename(const char *filename) } /* Look for the final sep */ - ret = opal_find_last_path_separator( tmp, strlen(tmp) ); + ret = opal_find_last_path_separator(tmp, strlen(tmp)); if (NULL == ret) { return tmp; } @@ -97,10 +99,10 @@ char *opal_basename(const char *filename) return ret; } -char* opal_dirname(const char* filename) +char *opal_dirname(const char *filename) { #if defined(HAVE_DIRNAME) || OPAL_HAVE_DIRNAME - char* safe_tmp = strdup(filename), *result; + char *safe_tmp = strdup(filename), *result; if (NULL == safe_tmp) { return NULL; } @@ -108,21 +110,21 @@ char* opal_dirname(const char* filename) free(safe_tmp); return result; #else - const char* p = opal_find_last_path_separator(filename, strlen(filename)); + const char *p = opal_find_last_path_separator(filename, strlen(filename)); /* NOTE: p will be NULL if no path separator was in the filename - i.e., * if filename is just a local file */ - for( ; NULL != p && p != filename; p-- ) { - if( (*p == '\\') || (*p == '/') ) { + for (; NULL != p && p != filename; p--) { + if ((*p == '\\') || (*p == '/')) { /* If there are several delimiters remove them all */ - for( --p; p != filename; p-- ) { - if( (*p != '\\') && (*p != '/') ) { + for (--p; p != filename; p--) { + if ((*p != '\\') && (*p != '/')) { p++; break; } } - if( p != filename ) { - char* ret = (char*)malloc( p - filename + 1 ); + if (p != filename) { + char *ret = (char *) malloc(p - filename + 1); if (NULL == ret) { return NULL; } @@ -130,9 +132,9 @@ char* opal_dirname(const char* filename) ret[p - filename] = '\0'; return opal_make_filename_os_friendly(ret); } - break; /* return the duplicate of "." */ + break; /* return the duplicate of "." */ } } return strdup("."); -#endif /* defined(HAVE_DIRNAME) || OPAL_HAVE_DIRNAME */ +#endif /* defined(HAVE_DIRNAME) || OPAL_HAVE_DIRNAME */ } diff --git a/opal/util/basename.h b/opal/util/basename.h index 5d0cf04b6e5..2cf22fc3bdc 100644 --- a/opal/util/basename.h +++ b/opal/util/basename.h @@ -66,7 +66,8 @@ BEGIN_C_DECLS * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_basename(const char* filename) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char * +opal_basename(const char *filename) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; /** * Return the dirname of a filename. @@ -105,7 +106,8 @@ OPAL_DECLSPEC char *opal_basename(const char* filename) __opal_attribute_malloc_ * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_dirname(const char* filename) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char * +opal_dirname(const char *filename) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; END_C_DECLS diff --git a/opal/util/bipartite_graph.c b/opal/util/bipartite_graph.c index c372d90f1ab..bb6732e59e7 100644 --- a/opal/util/bipartite_graph.c +++ b/opal/util/bipartite_graph.c @@ -11,48 +11,48 @@ #include "opal_config.h" -#include #include +#include -#include "opal_stdint.h" -#include "opal/constants.h" #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/util/output.h" +#include "opal/constants.h" #include "opal/util/error.h" +#include "opal/util/output.h" +#include "opal_stdint.h" #include "opal/util/bipartite_graph.h" #include "opal/util/bipartite_graph_internal.h" #ifndef container_of -#define container_of(ptr, type, member) ( \ - (type *)( ((char *)(ptr)) - offsetof(type,member) )) +# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member))) #endif #define GRAPH_DEBUG 0 #if GRAPH_DEBUG -# define GRAPH_DEBUG_OUT(args) printf(args) +# define GRAPH_DEBUG_OUT(args) printf(args) #else -# define GRAPH_DEBUG_OUT(args) do {} while(0) +# define GRAPH_DEBUG_OUT(args) \ + do { \ + } while (0) #endif #define MAX_COST INT64_MAX #ifndef MAX -# define MAX(a,b) ((a) > (b) ? (a) : (b)) +# define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN -# define MIN(a,b) ((a) < (b) ? (a) : (b)) +# define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif -#define f(i,j) flow[n*i + j] +#define f(i, j) flow[n * i + j] /* ensure that (a+b<=max) */ static inline void check_add64_overflow(int64_t a, int64_t b) { - assert(!((b > 0) && (a > (INT64_MAX - b))) && - !((b < 0) && (a < (INT64_MIN - b)))); + assert(!((b > 0) && (a > (INT64_MAX - b))) && !((b < 0) && (a < (INT64_MIN - b)))); } static void edge_constructor(opal_bp_graph_edge_t *e) @@ -68,11 +68,9 @@ static void edge_destructor(opal_bp_graph_edge_t *e) } OBJ_CLASS_DECLARATION(opal_bp_graph_edge_t); -OBJ_CLASS_INSTANCE(opal_bp_graph_edge_t, opal_object_t, - edge_constructor, edge_destructor); +OBJ_CLASS_INSTANCE(opal_bp_graph_edge_t, opal_object_t, edge_constructor, edge_destructor); -static void dump_vec(const char *name, int *vec, int n) - __opal_attribute_unused__; +static void dump_vec(const char *name, int *vec, int n) __opal_attribute_unused__; static void dump_vec(const char *name, int *vec, int n) { @@ -84,8 +82,7 @@ static void dump_vec(const char *name, int *vec, int n) fprintf(stderr, "}\n"); } -static void dump_vec64(const char *name, int64_t *vec, int n) - __opal_attribute_unused__; +static void dump_vec64(const char *name, int64_t *vec, int n) __opal_attribute_unused__; static void dump_vec64(const char *name, int64_t *vec, int n) { @@ -97,9 +94,7 @@ static void dump_vec64(const char *name, int64_t *vec, int n) fprintf(stderr, "}\n"); } - -static void dump_flow(int *flow, int n) - __opal_attribute_unused__; +static void dump_flow(int *flow, int n) __opal_attribute_unused__; static void dump_flow(int *flow, int n) { @@ -109,14 +104,13 @@ static void dump_flow(int *flow, int n) for (u = 0; u < n; ++u) { fprintf(stderr, "u=%d| ", u); for (v = 0; v < n; ++v) { - fprintf(stderr, "%2d,", f(u,v)); + fprintf(stderr, "%2d,", f(u, v)); } fprintf(stderr, "\n"); } fprintf(stderr, "}\n"); } - static int get_capacity(opal_bp_graph_t *g, int source, int target) { opal_bp_graph_edge_t *e; @@ -124,7 +118,8 @@ static int get_capacity(opal_bp_graph_t *g, int source, int target) CHECK_VERTEX_RANGE(g, source); CHECK_VERTEX_RANGE(g, target); - FOREACH_OUT_EDGE(g, source, e) { + FOREACH_OUT_EDGE(g, source, e) + { assert(e->source == source); if (e->target == target) { return e->capacity; @@ -134,15 +129,15 @@ static int get_capacity(opal_bp_graph_t *g, int source, int target) return 0; } -static int -set_capacity(opal_bp_graph_t *g, int source, int target, int cap) +static int set_capacity(opal_bp_graph_t *g, int source, int target, int cap) { opal_bp_graph_edge_t *e; CHECK_VERTEX_RANGE(g, source); CHECK_VERTEX_RANGE(g, target); - FOREACH_OUT_EDGE(g, source, e) { + FOREACH_OUT_EDGE(g, source, e) + { assert(e->source == source); if (e->target == target) { e->capacity = cap; @@ -153,8 +148,7 @@ set_capacity(opal_bp_graph_t *g, int source, int target, int cap) return OPAL_ERR_NOT_FOUND; } -static void free_vertex(opal_bp_graph_t *g, - opal_bp_graph_vertex_t *v) +static void free_vertex(opal_bp_graph_t *g, opal_bp_graph_vertex_t *v) { if (NULL != v) { if (NULL != g->v_data_cleanup_fn && NULL != v->v_data) { @@ -165,8 +159,7 @@ static void free_vertex(opal_bp_graph_t *g, } int opal_bp_graph_create(opal_bp_graph_cleanup_fn_t v_data_cleanup_fn, - opal_bp_graph_cleanup_fn_t e_data_cleanup_fn, - opal_bp_graph_t **g_out) + opal_bp_graph_cleanup_fn_t e_data_cleanup_fn, opal_bp_graph_t **g_out) { int err; opal_bp_graph_t *g = NULL; @@ -199,7 +192,7 @@ int opal_bp_graph_create(opal_bp_graph_cleanup_fn_t v_data_cleanup_fn, *g_out = g; return OPAL_SUCCESS; - out_free_g: +out_free_g: free(g); return err; } @@ -213,8 +206,8 @@ int opal_bp_graph_free(opal_bp_graph_t *g) /* remove all edges from all out_edges lists */ for (i = 0; i < NUM_VERTICES(g); ++i) { v = V_ID_TO_PTR(g, i); - LIST_FOREACH_SAFE_CONTAINED(e, next, &v->out_edges, - opal_bp_graph_edge_t, outbound_li) { + LIST_FOREACH_SAFE_CONTAINED(e, next, &v->out_edges, opal_bp_graph_edge_t, outbound_li) + { opal_list_remove_item(&v->out_edges, &e->outbound_li); OBJ_RELEASE(e); } @@ -222,8 +215,8 @@ int opal_bp_graph_free(opal_bp_graph_t *g) /* now remove from all in_edges lists and free the edge */ for (i = 0; i < NUM_VERTICES(g); ++i) { v = V_ID_TO_PTR(g, i); - LIST_FOREACH_SAFE_CONTAINED(e, next, &v->in_edges, - opal_bp_graph_edge_t, inbound_li) { + LIST_FOREACH_SAFE_CONTAINED(e, next, &v->in_edges, opal_bp_graph_edge_t, inbound_li) + { opal_list_remove_item(&v->in_edges, &e->inbound_li); if (NULL != g->e_data_cleanup_fn && NULL != e->e_data) { @@ -243,9 +236,8 @@ int opal_bp_graph_free(opal_bp_graph_t *g) return OPAL_SUCCESS; } -int opal_bp_graph_clone(const opal_bp_graph_t *g, - bool copy_user_data, - opal_bp_graph_t **g_clone_out) +int opal_bp_graph_clone(const opal_bp_graph_t *g, bool copy_user_data, + opal_bp_graph_t **g_clone_out) { int err; int i; @@ -259,8 +251,8 @@ int opal_bp_graph_clone(const opal_bp_graph_t *g, *g_clone_out = NULL; if (copy_user_data) { - opal_output(0, "[%s:%d:%s] user data copy requested but not yet supported", - __FILE__, __LINE__, __func__); + opal_output(0, "[%s:%d:%s] user data copy requested but not yet supported", __FILE__, + __LINE__, __func__); abort(); return OPAL_ERR_FATAL; } @@ -284,10 +276,10 @@ int opal_bp_graph_clone(const opal_bp_graph_t *g, /* now reconstruct all the edges (iterate by source vertex only to avoid * double-adding) */ for (i = 0; i < NUM_VERTICES(g); ++i) { - FOREACH_OUT_EDGE(g, i, e) { + FOREACH_OUT_EDGE(g, i, e) + { assert(i == e->source); - err = opal_bp_graph_add_edge(gx, e->source, e->target, - e->cost, e->capacity, NULL); + err = opal_bp_graph_add_edge(gx, e->source, e->target, e->cost, e->capacity, NULL); if (OPAL_SUCCESS != err) { goto out_free_gx; } @@ -297,15 +289,14 @@ int opal_bp_graph_clone(const opal_bp_graph_t *g, *g_clone_out = gx; return OPAL_SUCCESS; - out_free_gx: +out_free_gx: /* we don't reach in and manipulate gx's state directly, so it should be * safe to use the standard free function */ opal_bp_graph_free(gx); return err; } -int opal_bp_graph_indegree(const opal_bp_graph_t *g, - int vertex) +int opal_bp_graph_indegree(const opal_bp_graph_t *g, int vertex) { opal_bp_graph_vertex_t *v; @@ -313,8 +304,7 @@ int opal_bp_graph_indegree(const opal_bp_graph_t *g, return opal_list_get_size(&v->in_edges); } -int opal_bp_graph_outdegree(const opal_bp_graph_t *g, - int vertex) +int opal_bp_graph_outdegree(const opal_bp_graph_t *g, int vertex) { opal_bp_graph_vertex_t *v; @@ -322,12 +312,8 @@ int opal_bp_graph_outdegree(const opal_bp_graph_t *g, return opal_list_get_size(&v->out_edges); } -int opal_bp_graph_add_edge(opal_bp_graph_t *g, - int from, - int to, - int64_t cost, - int capacity, - void *e_data) +int opal_bp_graph_add_edge(opal_bp_graph_t *g, int from, int to, int64_t cost, int capacity, + void *e_data) { opal_bp_graph_edge_t *e; opal_bp_graph_vertex_t *v_from, *v_to; @@ -346,7 +332,8 @@ int opal_bp_graph_add_edge(opal_bp_graph_t *g, * handled appropriately */ return OPAL_ERR_BAD_PARAM; } - FOREACH_OUT_EDGE(g, from, e) { + FOREACH_OUT_EDGE(g, from, e) + { assert(e->source == from); if (e->target == to) { return OPAL_EXISTS; @@ -360,11 +347,11 @@ int opal_bp_graph_add_edge(opal_bp_graph_t *g, return OPAL_ERR_OUT_OF_RESOURCE; } - e->source = from; - e->target = to; - e->cost = cost; + e->source = from; + e->target = to; + e->cost = cost; e->capacity = capacity; - e->e_data = e_data; + e->e_data = e_data; v_from = V_ID_TO_PTR(g, from); opal_list_append(&v_from->out_edges, &e->outbound_li); @@ -376,9 +363,7 @@ int opal_bp_graph_add_edge(opal_bp_graph_t *g, return OPAL_SUCCESS; } -int opal_bp_graph_add_vertex(opal_bp_graph_t *g, - void *v_data, - int *index_out) +int opal_bp_graph_add_vertex(opal_bp_graph_t *g, void *v_data, int *index_out) { opal_bp_graph_vertex_t *v; @@ -411,11 +396,9 @@ int opal_bp_graph_add_vertex(opal_bp_graph_t *g, return OPAL_SUCCESS; } -int opal_bp_graph_get_vertex_data(opal_bp_graph_t *g, - int v_index, - void** v_data_out) +int opal_bp_graph_get_vertex_data(opal_bp_graph_t *g, int v_index, void **v_data_out) { - opal_bp_graph_vertex_t* v; + opal_bp_graph_vertex_t *v; v = V_ID_TO_PTR(g, v_index); if (NULL == v) { @@ -459,7 +442,7 @@ static void shrink_flow_matrix(int *flow, int old_n, int new_n) for (u = 0; u < new_n; ++u) { for (v = 0; v < new_n; ++v) { - flow[new_n*u + v] = flow[old_n*u + v]; + flow[new_n * u + v] = flow[old_n * u + v]; } } } @@ -468,17 +451,14 @@ static void shrink_flow_matrix(int *flow, int old_n, int new_n) * Compute the so-called "bottleneck" capacity value for a path "pred" through * graph "gx". */ -static int -bottleneck_path( - opal_bp_graph_t *gx, - int n, - int *pred) +static int bottleneck_path(opal_bp_graph_t *gx, int n, int *pred) { int u, v; int min; min = INT_MAX; - FOREACH_UV_ON_PATH(pred, gx->source_idx, gx->sink_idx, u, v) { + FOREACH_UV_ON_PATH(pred, gx->source_idx, gx->sink_idx, u, v) + { int cap_f_uv = get_capacity(gx, u, v); min = MIN(min, cap_f_uv); } @@ -486,7 +466,6 @@ bottleneck_path( return min; } - /** * This routine implements the Bellman-Ford shortest paths algorithm, slightly * specialized for our forumlation of flow networks: @@ -499,10 +478,7 @@ bottleneck_path( * * The contents of "pred" are only valid if this routine returns true. */ -bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, - int source, - int target, - int *pred) +bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, int source, int target, int *pred) { int64_t *dist; int i; @@ -549,13 +525,14 @@ bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, for (u = 0; u < NUM_VERTICES(gx); ++u) { opal_bp_graph_edge_t *e_ptr; - FOREACH_OUT_EDGE(gx, u, e_ptr) { + FOREACH_OUT_EDGE(gx, u, e_ptr) + { v = e_ptr->target; /* make sure to only construct paths from edges that actually have * non-zero capacity */ - if (e_ptr->capacity > 0 && - dist[u] != MAX_COST) { /* avoid signed overflow for "infinity" */ + if (e_ptr->capacity > 0 + && dist[u] != MAX_COST) { /* avoid signed overflow for "infinity" */ check_add64_overflow(dist[u], e_ptr->cost); if ((dist[u] + e_ptr->cost) < dist[v]) { dist[v] = dist[u] + e_ptr->cost; @@ -575,15 +552,15 @@ bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, /* check for negative-cost cycles */ for (u = 0; u < NUM_VERTICES(gx); ++u) { - opal_bp_graph_edge_t * e_ptr; + opal_bp_graph_edge_t *e_ptr; - FOREACH_OUT_EDGE(gx, u, e_ptr) { + FOREACH_OUT_EDGE(gx, u, e_ptr) + { v = e_ptr->target; - if (e_ptr->capacity > 0 && - dist[u] != MAX_COST && /* avoid signed overflow */ + if (e_ptr->capacity > 0 && dist[u] != MAX_COST && /* avoid signed overflow */ (dist[u] + e_ptr->cost) < dist[v]) { - opal_output(0, "[%s:%d:%s] negative-weight cycle detected", - __FILE__, __LINE__, __func__); + opal_output(0, "[%s:%d:%s] negative-weight cycle detected", __FILE__, __LINE__, + __func__); abort(); goto out; } @@ -594,7 +571,7 @@ bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, found_target = true; } - out: +out: #if GRAPH_DEBUG dump_vec("pred", pred, NUM_VERTICES(gx)); #endif @@ -655,29 +632,25 @@ int opal_bp_graph_bipartite_to_flow(opal_bp_graph_t *g) int outbound = opal_bp_graph_outdegree(g, u); if (inbound > 0 && outbound > 0) { - opal_output(0, "[%s:%d:%s] graph is not (unidirectionally) bipartite", - __FILE__, __LINE__, __func__); + opal_output(0, "[%s:%d:%s] graph is not (unidirectionally) bipartite", __FILE__, + __LINE__, __func__); abort(); - } - else if (inbound > 0) { + } else if (inbound > 0) { /* "right" side of the graph, create edges to the sink */ ++num_right; - err = opal_bp_graph_add_edge(g, u, g->sink_idx, - 0, /* no cost */ - /*capacity=*/1, - /*e_data=*/NULL); + err = opal_bp_graph_add_edge(g, u, g->sink_idx, 0, /* no cost */ + /*capacity=*/1, + /*e_data=*/NULL); if (OPAL_SUCCESS != err) { GRAPH_DEBUG_OUT(("add_edge failed")); return err; } - } - else if (outbound > 0) { + } else if (outbound > 0) { /* "left" side of the graph, create edges to the source */ ++num_left; - err = opal_bp_graph_add_edge(g, g->source_idx, u, - 0, /* no cost */ - /*capacity=*/1, - /*e_data=*/NULL); + err = opal_bp_graph_add_edge(g, g->source_idx, u, 0, /* no cost */ + /*capacity=*/1, + /*e_data=*/NULL); if (OPAL_SUCCESS != err) { GRAPH_DEBUG_OUT(("add_edge failed")); return err; @@ -697,19 +670,19 @@ int opal_bp_graph_bipartite_to_flow(opal_bp_graph_t *g) * exist in the original graph. */ order = opal_bp_graph_order(g); /* need residuals for newly created - source/sink edges too */ + source/sink edges too */ for (u = 0; u < order; ++u) { - opal_bp_graph_edge_t * e_ptr; - FOREACH_OUT_EDGE(g, u, e_ptr) { + opal_bp_graph_edge_t *e_ptr; + FOREACH_OUT_EDGE(g, u, e_ptr) + { v = e_ptr->target; /* (u,v) exists, add (v,u) if not already present. Cost is * negative for these edges because "giving back" flow pays us * back any cost already incurred. */ - err = opal_bp_graph_add_edge(g, v, u, - -e_ptr->cost, - /*capacity=*/0, - /*e_data=*/NULL); + err = opal_bp_graph_add_edge(g, v, u, -e_ptr->cost, + /*capacity=*/0, + /*e_data=*/NULL); if (OPAL_SUCCESS != err && OPAL_EXISTS != err) { return err; } @@ -760,8 +733,7 @@ int opal_bp_graph_bipartite_to_flow(opal_bp_graph_t *g) * the faster running time will be worth the additional implementation * complexity. */ -static int min_cost_flow_ssp(opal_bp_graph_t *gx, - int **flow_out) +static int min_cost_flow_ssp(opal_bp_graph_t *gx, int **flow_out) { int err = OPAL_SUCCESS; int n; @@ -779,7 +751,7 @@ static int min_cost_flow_ssp(opal_bp_graph_t *gx, n = opal_bp_graph_order(gx); - pred = malloc(n*sizeof(*pred)); + pred = malloc(n * sizeof(*pred)); if (NULL == pred) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); err = OPAL_ERR_OUT_OF_RESOURCE; @@ -787,7 +759,7 @@ static int min_cost_flow_ssp(opal_bp_graph_t *gx, } /* "flow" is a 2d matrix of current flow values, all initialized to zero */ - flow = calloc(n*n, sizeof(*flow)); + flow = calloc(n * n, sizeof(*flow)); if (NULL == flow) { OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE); err = OPAL_ERR_OUT_OF_RESOURCE; @@ -808,13 +780,14 @@ static int min_cost_flow_ssp(opal_bp_graph_t *gx, cap_f_path = bottleneck_path(gx, n, pred); /* augment current flow along P */ - FOREACH_UV_ON_PATH(pred, gx->source_idx, gx->sink_idx, u, v) { + FOREACH_UV_ON_PATH(pred, gx->source_idx, gx->sink_idx, u, v) + { assert(u == pred[v]); - f(u,v) = f(u,v) + cap_f_path; /* "forward" edge */ - f(v,u) = f(v,u) - cap_f_path; /* residual network edge */ + f(u, v) = f(u, v) + cap_f_path; /* "forward" edge */ + f(v, u) = f(v, u) - cap_f_path; /* residual network edge */ - assert(f(u,v) == -f(v,u)); /* skew symmetry invariant */ + assert(f(u, v) == -f(v, u)); /* skew symmetry invariant */ /* update Gx as we go along: decrease capacity by this new * augmenting flow */ @@ -822,8 +795,8 @@ static int min_cost_flow_ssp(opal_bp_graph_t *gx, assert(c >= 0); err = set_capacity(gx, u, v, c); if (OPAL_SUCCESS != err) { - opal_output(0, "[%s:%d:%s] unable to set capacity, missing edge?", - __FILE__, __LINE__, __func__); + opal_output(0, "[%s:%d:%s] unable to set capacity, missing edge?", __FILE__, + __LINE__, __func__); abort(); } @@ -831,27 +804,26 @@ static int min_cost_flow_ssp(opal_bp_graph_t *gx, assert(c >= 0); err = set_capacity(gx, v, u, c); if (OPAL_SUCCESS != err) { - opal_output(0, "[%s:%d:%s] unable to set capacity, missing edge?", - __FILE__, __LINE__, __func__); + opal_output(0, "[%s:%d:%s] unable to set capacity, missing edge?", __FILE__, + __LINE__, __func__); abort(); } } } - out: +out: *flow_out = flow; free(pred); return err; - out_error: +out_error: free(*flow_out); GRAPH_DEBUG_OUT(("returning error %d", err)); goto out; } -int opal_bp_graph_solve_bipartite_assignment(const opal_bp_graph_t *g, - int *num_match_edges_out, - int **match_edges_out) +int opal_bp_graph_solve_bipartite_assignment(const opal_bp_graph_t *g, int *num_match_edges_out, + int **match_edges_out) { int err; int i; @@ -918,7 +890,7 @@ int opal_bp_graph_solve_bipartite_assignment(const opal_bp_graph_t *g, for (u = 0; u < n; ++u) { for (v = 0; v < n; ++v) { - if (f(u,v) > 0) { + if (f(u, v) > 0) { ++(*num_match_edges_out); } } @@ -941,14 +913,14 @@ int opal_bp_graph_solve_bipartite_assignment(const opal_bp_graph_t *g, for (u = 0; u < n; ++u) { for (v = 0; v < n; ++v) { /* flow exists on this edge so include this edge in the matching */ - if (f(u,v) > 0) { + if (f(u, v) > 0) { (*match_edges_out)[i++] = u; (*match_edges_out)[i++] = v; } } } - out: +out: free(flow); opal_bp_graph_free(gx); return err; diff --git a/opal/util/bipartite_graph.h b/opal/util/bipartite_graph.h index 1df1b937c57..319bb38b104 100644 --- a/opal/util/bipartite_graph.h +++ b/opal/util/bipartite_graph.h @@ -45,8 +45,7 @@ typedef void (*opal_bp_graph_cleanup_fn_t)(void *user_data); * @returns OPAL_SUCCESS or an OMPI error code */ int opal_bp_graph_create(opal_bp_graph_cleanup_fn_t v_data_cleanup_fn, - opal_bp_graph_cleanup_fn_t e_data_cleanup_fn, - opal_bp_graph_t **g_out); + opal_bp_graph_cleanup_fn_t e_data_cleanup_fn, opal_bp_graph_t **g_out); /** * free the given graph @@ -70,9 +69,8 @@ int opal_bp_graph_free(opal_bp_graph_t *g); * @param[in] g_clone_out the resulting cloned graph * @returns OPAL_SUCCESS or an OMPI error code */ -int opal_bp_graph_clone(const opal_bp_graph_t *g, - bool copy_user_data, - opal_bp_graph_t **g_clone_out); +int opal_bp_graph_clone(const opal_bp_graph_t *g, bool copy_user_data, + opal_bp_graph_t **g_clone_out); /** * return the number of edges for which this vertex is a destination @@ -81,8 +79,7 @@ int opal_bp_graph_clone(const opal_bp_graph_t *g, * @param[in] vertex the vertex id to query * @returns the number of edges for which this vertex is a destination */ -int opal_bp_graph_indegree(const opal_bp_graph_t *g, - int vertex); +int opal_bp_graph_indegree(const opal_bp_graph_t *g, int vertex); /** * return the number of edges for which this vertex is a source @@ -91,8 +88,7 @@ int opal_bp_graph_indegree(const opal_bp_graph_t *g, * @param[in] vertex the vertex id to query * @returns the number of edges for which this vertex is a source */ -int opal_bp_graph_outdegree(const opal_bp_graph_t *g, - int vertex); +int opal_bp_graph_outdegree(const opal_bp_graph_t *g, int vertex); /** * add an edge to the given graph @@ -106,12 +102,8 @@ int opal_bp_graph_outdegree(const opal_bp_graph_t *g, * * @returns OPAL_SUCCESS or an OMPI error code */ -int opal_bp_graph_add_edge(opal_bp_graph_t *g, - int from, - int to, - int64_t cost, - int capacity, - void *e_data); +int opal_bp_graph_add_edge(opal_bp_graph_t *g, int from, int to, int64_t cost, int capacity, + void *e_data); /** * add a vertex to the given graph @@ -122,9 +114,7 @@ int opal_bp_graph_add_edge(opal_bp_graph_t *g, * * @returns OPAL_SUCCESS or an OMPI error code */ -int opal_bp_graph_add_vertex(opal_bp_graph_t *g, - void *v_data, - int *index_out); +int opal_bp_graph_add_vertex(opal_bp_graph_t *g, void *v_data, int *index_out); /** * Get a pointer to the vertex data given the graph and vertex index @@ -136,9 +126,7 @@ int opal_bp_graph_add_vertex(opal_bp_graph_t *g, * * @returns OPAL_SUCCESS or an OMPI error code */ -int opal_bp_graph_get_vertex_data(opal_bp_graph_t *g, - int v_index, - void** v_data_out); +int opal_bp_graph_get_vertex_data(opal_bp_graph_t *g, int v_index, void **v_data_out); /** * compute the order of a graph (number of vertices) @@ -171,8 +159,7 @@ int opal_bp_graph_order(const opal_bp_graph_t *g); * * @returns OPAL_SUCCESS or an OMPI error code */ -int opal_bp_graph_solve_bipartite_assignment(const opal_bp_graph_t *g, - int *num_match_edges_out, - int **match_edges_out); +int opal_bp_graph_solve_bipartite_assignment(const opal_bp_graph_t *g, int *num_match_edges_out, + int **match_edges_out); #endif /* OPAL_BP_GRAPH_H */ diff --git a/opal/util/bipartite_graph_internal.h b/opal/util/bipartite_graph_internal.h index 64582016311..1243c139973 100644 --- a/opal/util/bipartite_graph_internal.h +++ b/opal/util/bipartite_graph_internal.h @@ -77,63 +77,49 @@ struct opal_bp_graph_t { opal_bp_graph_cleanup_fn_t e_data_cleanup_fn; }; - -#define LIST_FOREACH_CONTAINED(item, list, type, member) \ - for (item = container_of( (list)->opal_list_sentinel.opal_list_next, type, member ); \ - &item->member != &(list)->opal_list_sentinel; \ - item = container_of( \ - ((opal_list_item_t *) (&item->member))->opal_list_next, type, member )) - -#define LIST_FOREACH_SAFE_CONTAINED(item, next, list, type, member) \ - for (item = container_of( (list)->opal_list_sentinel.opal_list_next, type, member ), \ - next = container_of( \ - ((opal_list_item_t *) (&item->member))->opal_list_next, type, member ); \ - &item->member != &(list)->opal_list_sentinel; \ - item = next, \ - next = container_of( \ - ((opal_list_item_t *) (&item->member))->opal_list_next, type, member )) +#define LIST_FOREACH_CONTAINED(item, list, type, member) \ + for (item = container_of((list)->opal_list_sentinel.opal_list_next, type, member); \ + &item->member != &(list)->opal_list_sentinel; \ + item = container_of(((opal_list_item_t *) (&item->member))->opal_list_next, type, \ + member)) + +#define LIST_FOREACH_SAFE_CONTAINED(item, next, list, type, member) \ + for (item = container_of((list)->opal_list_sentinel.opal_list_next, type, member), \ + next = container_of(((opal_list_item_t *) (&item->member))->opal_list_next, type, member); \ + &item->member != &(list)->opal_list_sentinel; item = next, \ + next = container_of(((opal_list_item_t *) (&item->member))->opal_list_next, type, member)) #define NUM_VERTICES(g) (g->num_vertices) -#define CHECK_VERTEX_RANGE(g,v) \ - do { \ - if ((v) < 0 || \ - (v) >= NUM_VERTICES(g)) { \ - return OPAL_ERR_BAD_PARAM; \ - } \ +#define CHECK_VERTEX_RANGE(g, v) \ + do { \ + if ((v) < 0 || (v) >= NUM_VERTICES(g)) { \ + return OPAL_ERR_BAD_PARAM; \ + } \ } while (0) /* cast away any constness of &g->vertices b/c the opal_pointer_array API is * not const-correct */ -#define V_ID_TO_PTR(g, v_id) \ - ((opal_bp_graph_vertex_t *) \ - opal_pointer_array_get_item((opal_pointer_array_t *)&g->vertices, v_id)) - -#define FOREACH_OUT_EDGE(g,v_id,e_ptr) \ - LIST_FOREACH_CONTAINED(e_ptr, \ - &(V_ID_TO_PTR(g, v_id)->out_edges), \ - opal_bp_graph_edge_t, \ +#define V_ID_TO_PTR(g, v_id) \ + ((opal_bp_graph_vertex_t *) opal_pointer_array_get_item((opal_pointer_array_t *) &g->vertices, \ + v_id)) + +#define FOREACH_OUT_EDGE(g, v_id, e_ptr) \ + LIST_FOREACH_CONTAINED(e_ptr, &(V_ID_TO_PTR(g, v_id)->out_edges), opal_bp_graph_edge_t, \ outbound_li) -#define FOREACH_IN_EDGE(g,v_id,e_ptr) \ - LIST_FOREACH_CONTAINED(e_ptr, \ - &(V_ID_TO_PTR(g, v_id)->in_edges), \ - opal_bp_graph_edge_t, \ +#define FOREACH_IN_EDGE(g, v_id, e_ptr) \ + LIST_FOREACH_CONTAINED(e_ptr, &(V_ID_TO_PTR(g, v_id)->in_edges), opal_bp_graph_edge_t, \ inbound_li) - /* Iterate over (u,v) edge pairs along the given path, where path is defined * by the predecessor array "pred". Stops when a -1 predecessor is * encountered. Note: because it is a *predecessor* array, the traversal * starts at the sink and progresses towards the source. */ -#define FOREACH_UV_ON_PATH(pred, source, sink, u, v) \ +#define FOREACH_UV_ON_PATH(pred, source, sink, u, v) \ for (u = pred[sink], v = sink; u != -1; v = u, u = pred[u]) - -bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, - int source, - int target, - int *pred); +bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx, int source, int target, int *pred); int opal_bp_graph_bipartite_to_flow(opal_bp_graph_t *g); diff --git a/opal/util/bit_ops.h b/opal/util/bit_ops.h index 34ea4418abf..e20fbb1c654 100644 --- a/opal/util/bit_ops.h +++ b/opal/util/bit_ops.h @@ -47,11 +47,11 @@ static inline int opal_hibit(int value, int start) /* Only look at the part that the caller wanted looking at */ mask = value & ((1 << start) - 1); - if (OPAL_UNLIKELY (0 == mask)) { + if (OPAL_UNLIKELY(0 == mask)) { return -1; } - start = (8*sizeof(int)-1) - __builtin_clz(mask); + start = (8 * sizeof(int) - 1) - __builtin_clz(mask); #else --start; mask = 1 << start; @@ -66,7 +66,6 @@ static inline int opal_hibit(int value, int start) return start; } - /** * Returns the cube dimension of a given value. * @@ -87,19 +86,19 @@ static inline int opal_cube_dim(int value) int dim, size; #if OPAL_C_HAVE_BUILTIN_CLZ - if (OPAL_UNLIKELY (1 >= value)) { + if (OPAL_UNLIKELY(1 >= value)) { return 0; } size = 8 * sizeof(int); - dim = size - __builtin_clz(value-1); + dim = size - __builtin_clz(value - 1); #else - for (dim = 0, size = 1; size < value; ++dim, size <<= 1) /* empty */; + for (dim = 0, size = 1; size < value; ++dim, size <<= 1) /* empty */ + ; #endif return dim; } - /** * @brief Returns next power-of-two of the given value. * @@ -117,20 +116,21 @@ static inline int opal_next_poweroftwo(int value) int power2; #if OPAL_C_HAVE_BUILTIN_CLZ - if (OPAL_UNLIKELY (0 == value)) { + if (OPAL_UNLIKELY(0 == value)) { return 1; } - power2 = 1 << (8 * sizeof (int) - __builtin_clz(value)); + power2 = 1 << (8 * sizeof(int) - __builtin_clz(value)); #else - for (power2 = 1; value > 0; value >>= 1, power2 <<= 1) /* empty */; + for (power2 = 1; value > 0; value >>= 1, power2 <<= 1) /* empty */ + ; #endif return power2; } - /** - * @brief Returns next power-of-two of the given value (and the value itselve if already power-of-two). + * @brief Returns next power-of-two of the given value (and the value itselve if already + * power-of-two). * * @param value The integer value to return power of 2 * @@ -146,17 +146,16 @@ static inline int opal_next_poweroftwo_inclusive(int value) int power2; #if OPAL_C_HAVE_BUILTIN_CLZ - if (OPAL_UNLIKELY (1 >= value)) { + if (OPAL_UNLIKELY(1 >= value)) { return 1; } - power2 = 1 << (8 * sizeof (int) - __builtin_clz(value - 1)); + power2 = 1 << (8 * sizeof(int) - __builtin_clz(value - 1)); #else - for (power2 = 1 ; power2 < value; power2 <<= 1) /* empty */; + for (power2 = 1; power2 < value; power2 <<= 1) /* empty */ + ; #endif return power2; } - #endif /* OPAL_BIT_OPS_H */ - diff --git a/opal/util/cmd_line.c b/opal/util/cmd_line.c index 39c5bf2c624..391de0de4ea 100644 --- a/opal/util/cmd_line.c +++ b/opal/util/cmd_line.c @@ -26,21 +26,20 @@ #include "opal_config.h" +#include #include #include -#include -#include "opal/class/opal_object.h" #include "opal/class/opal_list.h" +#include "opal/class/opal_object.h" #include "opal/mca/threads/mutex.h" #include "opal/util/argv.h" #include "opal/util/cmd_line.h" -#include "opal/util/output.h" #include "opal/util/opal_environ.h" +#include "opal/util/output.h" -#include "opal/mca/base/mca_base_var.h" #include "opal/constants.h" - +#include "opal/mca/base/mca_base_var.h" /* * Some usage message constants @@ -77,9 +76,7 @@ typedef struct ompi_cmd_line_option_t ompi_cmd_line_option_t; static void option_constructor(ompi_cmd_line_option_t *cmd); static void option_destructor(ompi_cmd_line_option_t *cmd); -OBJ_CLASS_INSTANCE(ompi_cmd_line_option_t, - opal_list_item_t, - option_constructor, option_destructor); +OBJ_CLASS_INSTANCE(ompi_cmd_line_option_t, opal_list_item_t, option_constructor, option_destructor); /* * An option that was used in the argv that was parsed @@ -108,50 +105,39 @@ struct ompi_cmd_line_param_t { typedef struct ompi_cmd_line_param_t ompi_cmd_line_param_t; static void param_constructor(ompi_cmd_line_param_t *cmd); static void param_destructor(ompi_cmd_line_param_t *cmd); -OBJ_CLASS_INSTANCE(ompi_cmd_line_param_t, - opal_list_item_t, - param_constructor, param_destructor); +OBJ_CLASS_INSTANCE(ompi_cmd_line_param_t, opal_list_item_t, param_constructor, param_destructor); /* * Instantiate the opal_cmd_line_t class */ static void cmd_line_constructor(opal_cmd_line_t *cmd); static void cmd_line_destructor(opal_cmd_line_t *cmd); -OBJ_CLASS_INSTANCE(opal_cmd_line_t, - opal_object_t, - cmd_line_constructor, - cmd_line_destructor); +OBJ_CLASS_INSTANCE(opal_cmd_line_t, opal_object_t, cmd_line_constructor, cmd_line_destructor); /* * Private variables */ -static char special_empty_token[] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '\0' -}; +static char special_empty_token[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '\0'}; /* * Private functions */ static int make_opt(opal_cmd_line_t *cmd, opal_cmd_line_init_t *e); static void free_parse_results(opal_cmd_line_t *cmd); -static int split_shorts(opal_cmd_line_t *cmd, - char *token, char **args, - int *output_argc, char ***output_argv, - int *num_args_used, bool ignore_unknown); -static ompi_cmd_line_option_t *find_option(opal_cmd_line_t *cmd, - const char *option_name) __opal_attribute_nonnull__(1) __opal_attribute_nonnull__(2); +static int split_shorts(opal_cmd_line_t *cmd, char *token, char **args, int *output_argc, + char ***output_argv, int *num_args_used, bool ignore_unknown); +static ompi_cmd_line_option_t *find_option(opal_cmd_line_t *cmd, const char *option_name) + __opal_attribute_nonnull__(1) __opal_attribute_nonnull__(2); static int set_dest(ompi_cmd_line_option_t *option, char *sval); static void fill(const ompi_cmd_line_option_t *a, char result[3][BUFSIZ]); static int qsort_callback(const void *a, const void *b); static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd); static char *build_parsable(ompi_cmd_line_option_t *option); - /* * Create an entire command line handle from a table */ -int opal_cmd_line_create(opal_cmd_line_t *cmd, - opal_cmd_line_init_t *table) +int opal_cmd_line_create(opal_cmd_line_t *cmd, opal_cmd_line_init_t *table) { int ret = OPAL_SUCCESS; @@ -169,8 +155,7 @@ int opal_cmd_line_create(opal_cmd_line_t *cmd, } /* Add a table to an existing cmd line object */ -int opal_cmd_line_add(opal_cmd_line_t *cmd, - opal_cmd_line_init_t *table) +int opal_cmd_line_add(opal_cmd_line_t *cmd, opal_cmd_line_init_t *table) { int i, ret; @@ -181,11 +166,10 @@ int opal_cmd_line_add(opal_cmd_line_t *cmd, /* Loop through the table */ - for (i = 0; ; ++i) { + for (i = 0;; ++i) { /* Is this the end? */ - if ('\0' == table[i].ocl_cmd_short_name && - NULL == table[i].ocl_cmd_single_dash_name && - NULL == table[i].ocl_cmd_long_name) { + if ('\0' == table[i].ocl_cmd_short_name && NULL == table[i].ocl_cmd_single_dash_name + && NULL == table[i].ocl_cmd_long_name) { break; } @@ -201,26 +185,22 @@ int opal_cmd_line_add(opal_cmd_line_t *cmd, /* * Append a command line entry to the previously constructed command line */ -int opal_cmd_line_make_opt_mca(opal_cmd_line_t *cmd, - opal_cmd_line_init_t entry) +int opal_cmd_line_make_opt_mca(opal_cmd_line_t *cmd, opal_cmd_line_init_t entry) { /* Ensure we got an entry */ - if ('\0' == entry.ocl_cmd_short_name && - NULL == entry.ocl_cmd_single_dash_name && - NULL == entry.ocl_cmd_long_name) { + if ('\0' == entry.ocl_cmd_short_name && NULL == entry.ocl_cmd_single_dash_name + && NULL == entry.ocl_cmd_long_name) { return OPAL_SUCCESS; } return make_opt(cmd, &entry); } - /* * Create a command line option, --long-name and/or -s (short name). */ -int opal_cmd_line_make_opt3(opal_cmd_line_t *cmd, char short_name, - const char *sd_name, const char *long_name, - int num_params, const char *desc) +int opal_cmd_line_make_opt3(opal_cmd_line_t *cmd, char short_name, const char *sd_name, + const char *long_name, int num_params, const char *desc) { opal_cmd_line_init_t e; @@ -242,7 +222,6 @@ int opal_cmd_line_make_opt3(opal_cmd_line_t *cmd, char short_name, return make_opt(cmd, &e); } - /* * Parse a command line according to a pre-built OPAL command line * handle. @@ -295,7 +274,7 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u param = NULL; option = NULL; - for (i = 1; i < cmd->lcl_argc; ) { + for (i = 1; i < cmd->lcl_argc;) { is_unknown_option = false; is_unknown_token = false; is_option = false; @@ -307,8 +286,7 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u if (0 == strcmp(cmd->lcl_argv[i], "--")) { ++i; while (i < cmd->lcl_argc) { - opal_argv_append(&cmd->lcl_tail_argc, &cmd->lcl_tail_argv, - cmd->lcl_argv[i]); + opal_argv_append(&cmd->lcl_tail_argc, &cmd->lcl_tail_argv, cmd->lcl_argv[i]); ++i; } @@ -345,17 +323,13 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u if (NULL == option) { shortsv = NULL; shortsc = 0; - ret = split_shorts(cmd, cmd->lcl_argv[i] + 1, - &(cmd->lcl_argv[i + 1]), - &shortsc, &shortsv, - &num_args_used, ignore_unknown); + ret = split_shorts(cmd, cmd->lcl_argv[i] + 1, &(cmd->lcl_argv[i + 1]), &shortsc, + &shortsv, &num_args_used, ignore_unknown); if (OPAL_SUCCESS == ret) { option = find_option(cmd, shortsv[0] + 1); if (NULL != option) { - opal_argv_delete(&cmd->lcl_argc, - &cmd->lcl_argv, i, - 1 + num_args_used); + opal_argv_delete(&cmd->lcl_argc, &cmd->lcl_argv, i, 1 + num_args_used); opal_argv_insert(&cmd->lcl_argv, i, shortsv); cmd->lcl_argc = opal_argv_count(cmd->lcl_argv); } else { @@ -404,37 +378,32 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u /* If we run out of parameters, error, unless its a help request which can have 0 or 1 arguments */ if (i >= cmd->lcl_argc) { - /* If this is a help request, can have no arguments */ - if((NULL != option->clo_single_dash_name && - 0 == strcmp(option->clo_single_dash_name, "h")) || - (NULL != option->clo_long_name && - 0 == strcmp(option->clo_long_name, "help"))) { + /* If this is a help request, can have no arguments */ + if ((NULL != option->clo_single_dash_name + && 0 == strcmp(option->clo_single_dash_name, "h")) + || (NULL != option->clo_long_name + && 0 == strcmp(option->clo_long_name, "help"))) { help_without_arg = true; continue; } - fprintf(stderr, "%s: Error: option \"%s\" did not " + fprintf(stderr, + "%s: Error: option \"%s\" did not " "have enough parameters (%d)\n", - cmd->lcl_argv[0], - cmd->lcl_argv[orig], - option->clo_num_params); + cmd->lcl_argv[0], cmd->lcl_argv[orig], option->clo_num_params); if (have_help_option) { - fprintf(stderr, "Type '%s --help' for usage.\n", - cmd->lcl_argv[0]); + fprintf(stderr, "Type '%s --help' for usage.\n", cmd->lcl_argv[0]); } OBJ_RELEASE(param); printed_error = true; goto error; } else { - if (0 == strcmp(cmd->lcl_argv[i], - special_empty_token)) { - fprintf(stderr, "%s: Error: option \"%s\" did not " + if (0 == strcmp(cmd->lcl_argv[i], special_empty_token)) { + fprintf(stderr, + "%s: Error: option \"%s\" did not " "have enough parameters (%d)\n", - cmd->lcl_argv[0], - cmd->lcl_argv[orig], - option->clo_num_params); + cmd->lcl_argv[0], cmd->lcl_argv[orig], option->clo_num_params); if (have_help_option) { - fprintf(stderr, "Type '%s --help' for usage.\n", - cmd->lcl_argv[0]); + fprintf(stderr, "Type '%s --help' for usage.\n", cmd->lcl_argv[0]); } if (NULL != param->clp_argv) { opal_argv_free(param->clp_argv); @@ -449,16 +418,14 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u else { /* Save in the argv on the param entry */ - opal_argv_append(¶m->clp_argc, - ¶m->clp_argv, - cmd->lcl_argv[i]); + opal_argv_append(¶m->clp_argc, ¶m->clp_argv, cmd->lcl_argv[i]); /* If it's the first, save it in the variable dest and/or MCA parameter */ - if (0 == j && - (NULL != option->clo_mca_param_env_var || - NULL != option->clo_variable_dest)) { + if (0 == j + && (NULL != option->clo_mca_param_env_var + || NULL != option->clo_variable_dest)) { if (OPAL_SUCCESS != (ret = set_dest(option, cmd->lcl_argv[i]))) { opal_mutex_unlock(&cmd->lcl_mutex); return ret; @@ -494,18 +461,16 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u an error and return. */ if (is_unknown_option || is_unknown_token) { if (!ignore_unknown || (is_unknown_option && !ignore_unknown_option)) { - fprintf(stderr, "%s: Error: unknown option \"%s\"\n", - cmd->lcl_argv[0], cmd->lcl_argv[i]); + fprintf(stderr, "%s: Error: unknown option \"%s\"\n", cmd->lcl_argv[0], + cmd->lcl_argv[i]); printed_error = true; if (have_help_option) { - fprintf(stderr, "Type '%s --help' for usage.\n", - cmd->lcl_argv[0]); + fprintf(stderr, "Type '%s --help' for usage.\n", cmd->lcl_argv[0]); } } error: while (i < cmd->lcl_argc) { - opal_argv_append(&cmd->lcl_tail_argc, &cmd->lcl_tail_argv, - cmd->lcl_argv[i]); + opal_argv_append(&cmd->lcl_tail_argc, &cmd->lcl_tail_argv, cmd->lcl_argv[i]); ++i; } @@ -525,7 +490,6 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown, bool ignore_u return OPAL_SUCCESS; } - /* * Return a consolidated "usage" message for a OPAL command line handle. */ @@ -553,17 +517,17 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) /* First, take the original list and sort it */ - sorted = (ompi_cmd_line_option_t**)malloc(sizeof(ompi_cmd_line_option_t *) * - opal_list_get_size(&cmd->lcl_options)); + sorted = (ompi_cmd_line_option_t **) malloc(sizeof(ompi_cmd_line_option_t *) + * opal_list_get_size(&cmd->lcl_options)); if (NULL == sorted) { opal_mutex_unlock(&cmd->lcl_mutex); return NULL; } i = 0; - OPAL_LIST_FOREACH(item, &cmd->lcl_options, opal_list_item_t) { + OPAL_LIST_FOREACH (item, &cmd->lcl_options, opal_list_item_t) { sorted[i++] = (ompi_cmd_line_option_t *) item; } - qsort(sorted, i, sizeof(ompi_cmd_line_option_t*), qsort_callback); + qsort(sorted, i, sizeof(ompi_cmd_line_option_t *), qsort_callback); /* Find if a help argument was passed, and return its type if it was. */ @@ -573,12 +537,12 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) for (j = 0; j < opal_list_get_size(&cmd->lcl_options); ++j) { option = sorted[j]; - if(otype == OPAL_CMD_LINE_OTYPE_PARSABLE) { + if (otype == OPAL_CMD_LINE_OTYPE_PARSABLE) { ret = build_parsable(option); opal_argv_append(&argc, &argv, ret); free(ret); ret = NULL; - } else if(otype == OPAL_CMD_LINE_OTYPE_NULL || option->clo_otype == otype) { + } else if (otype == OPAL_CMD_LINE_OTYPE_NULL || option->clo_otype == otype) { if (NULL != option->clo_description) { bool filled = false; @@ -609,9 +573,9 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) strncat(line, option->clo_long_name, sizeof(line) - 1); } strncat(line, " ", sizeof(line) - 1); - for (i = 0; (int)i < option->clo_num_params; ++i) { + for (i = 0; (int) i < option->clo_num_params; ++i) { len = sizeof(temp); - snprintf(temp, len, " ", (int)i); + snprintf(temp, len, " ", (int) i); strncat(line, temp, sizeof(line) - 1); } if (option->clo_num_params > 0) { @@ -680,8 +644,7 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) line's worth and add it to the array. Then reset and loop around to get the next line's worth. */ - for (ptr = start + (MAX_WIDTH - PARAM_WIDTH); - ptr > start; --ptr) { + for (ptr = start + (MAX_WIDTH - PARAM_WIDTH); ptr > start; --ptr) { if (isspace(*ptr)) { *ptr = '\0'; strncat(line, start, sizeof(line) - 1); @@ -699,8 +662,7 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) and break there. */ if (ptr == start) { - for (ptr = start + (MAX_WIDTH - PARAM_WIDTH); - ptr < start + len; ++ptr) { + for (ptr = start + (MAX_WIDTH - PARAM_WIDTH); ptr < start + len; ++ptr) { if (isspace(*ptr)) { *ptr = '\0'; @@ -728,8 +690,14 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) } } } - if(otype == OPAL_CMD_LINE_OTYPE_NULL || otype == OPAL_CMD_LINE_OTYPE_GENERAL) { - char *argument_line = "\nFor additional mpirun arguments, run 'mpirun --help '\n\nThe following categories exist: general (Defaults to this option), debug,\n output, input, mapping, ranking, binding, devel (arguments useful to OMPI\n Developers), compatibility (arguments supported for backwards compatibility),\n launch (arguments to modify launch options), and dvm (Distributed Virtual\n Machine arguments)."; + if (otype == OPAL_CMD_LINE_OTYPE_NULL || otype == OPAL_CMD_LINE_OTYPE_GENERAL) { + char *argument_line + = "\nFor additional mpirun arguments, run 'mpirun --help '\n\nThe following " + "categories exist: general (Defaults to this option), debug,\n output, input, " + "mapping, ranking, binding, devel (arguments useful to OMPI\n Developers), " + "compatibility (arguments supported for backwards compatibility),\n launch " + "(arguments to modify launch options), and dvm (Distributed Virtual\n Machine " + "arguments)."; opal_argv_append(&argc, &argv, argument_line); } @@ -748,7 +716,6 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) return ret; } - /* * Test if a given option was taken on the parsed command line. */ @@ -757,7 +724,6 @@ bool opal_cmd_line_is_taken(opal_cmd_line_t *cmd, const char *opt) return (opal_cmd_line_get_ninsts(cmd, opt) > 0); } - /* * Return the number of instances of an option found during parsing. */ @@ -777,7 +743,7 @@ int opal_cmd_line_get_ninsts(opal_cmd_line_t *cmd, const char *opt) ret = 0; option = find_option(cmd, opt); if (NULL != option) { - OPAL_LIST_FOREACH(param, &cmd->lcl_params, ompi_cmd_line_param_t) { + OPAL_LIST_FOREACH (param, &cmd->lcl_params, ompi_cmd_line_param_t) { if (param->clp_option == option) { ++ret; } @@ -793,13 +759,11 @@ int opal_cmd_line_get_ninsts(opal_cmd_line_t *cmd, const char *opt) return ret; } - /* * Return a specific parameter for a specific instance of a option * from the parsed command line. */ -char *opal_cmd_line_get_param(opal_cmd_line_t *cmd, const char *opt, int inst, - int idx) +char *opal_cmd_line_get_param(opal_cmd_line_t *cmd, const char *opt, int inst, int idx) { int num_found; ompi_cmd_line_param_t *param; @@ -820,7 +784,7 @@ char *opal_cmd_line_get_param(opal_cmd_line_t *cmd, const char *opt, int inst, parameter index greater than we will have */ if (idx < option->clo_num_params) { - OPAL_LIST_FOREACH(param, &cmd->lcl_params, ompi_cmd_line_param_t) { + OPAL_LIST_FOREACH (param, &cmd->lcl_params, ompi_cmd_line_param_t) { if (param->clp_argc > 0 && param->clp_option == option) { if (num_found == inst) { opal_mutex_unlock(&cmd->lcl_mutex); @@ -841,7 +805,6 @@ char *opal_cmd_line_get_param(opal_cmd_line_t *cmd, const char *opt, int inst, return NULL; } - /* * Return the number of arguments parsed on a OPAL command line handle. */ @@ -850,17 +813,16 @@ int opal_cmd_line_get_argc(opal_cmd_line_t *cmd) return (NULL != cmd) ? cmd->lcl_argc : OPAL_ERROR; } - /* * Return a string argument parsed on a OPAL command line handle. */ char *opal_cmd_line_get_argv(opal_cmd_line_t *cmd, int index) { - return (NULL == cmd) ? NULL : - (index >= cmd->lcl_argc || index < 0) ? NULL : cmd->lcl_argv[index]; + return (NULL == cmd) ? NULL + : (index >= cmd->lcl_argc || index < 0) ? NULL + : cmd->lcl_argv[index]; } - /* * Return the entire "tail" of unprocessed argv from a OPAL command * line handle. @@ -878,7 +840,6 @@ int opal_cmd_line_get_tail(opal_cmd_line_t *cmd, int *tailc, char ***tailv) } } - /************************************************************************** * Static functions **************************************************************************/ @@ -898,7 +859,6 @@ static void option_constructor(ompi_cmd_line_option_t *o) o->clo_otype = OPAL_CMD_LINE_OTYPE_NULL; } - static void option_destructor(ompi_cmd_line_option_t *o) { if (NULL != o->clo_single_dash_name) { @@ -915,7 +875,6 @@ static void option_destructor(ompi_cmd_line_option_t *o) } } - static void param_constructor(ompi_cmd_line_param_t *p) { p->clp_arg = NULL; @@ -924,7 +883,6 @@ static void param_constructor(ompi_cmd_line_param_t *p) p->clp_argv = NULL; } - static void param_destructor(ompi_cmd_line_param_t *p) { if (NULL != p->clp_argv) { @@ -932,7 +890,6 @@ static void param_destructor(ompi_cmd_line_param_t *p) } } - static void cmd_line_constructor(opal_cmd_line_t *cmd) { /* Initialize the mutex. Since we're creating (and therefore the @@ -954,7 +911,6 @@ static void cmd_line_constructor(opal_cmd_line_t *cmd) cmd->lcl_tail_argv = NULL; } - static void cmd_line_destructor(opal_cmd_line_t *cmd) { opal_list_item_t *item; @@ -962,8 +918,7 @@ static void cmd_line_destructor(opal_cmd_line_t *cmd) /* Free the contents of the options list (do not free the list itself; it was not allocated from the heap) */ - for (item = opal_list_remove_first(&cmd->lcl_options); - NULL != item; + for (item = opal_list_remove_first(&cmd->lcl_options); NULL != item; item = opal_list_remove_first(&cmd->lcl_options)) { OBJ_RELEASE(item); } @@ -982,7 +937,6 @@ static void cmd_line_destructor(opal_cmd_line_t *cmd) OBJ_DESTRUCT(&cmd->lcl_mutex); } - static int make_opt(opal_cmd_line_t *cmd, opal_cmd_line_init_t *e) { ompi_cmd_line_option_t *option; @@ -991,22 +945,20 @@ static int make_opt(opal_cmd_line_t *cmd, opal_cmd_line_init_t *e) if (NULL == cmd) { return OPAL_ERR_BAD_PARAM; - } else if ('\0' == e->ocl_cmd_short_name && - NULL == e->ocl_cmd_single_dash_name && - NULL == e->ocl_cmd_long_name) { + } else if ('\0' == e->ocl_cmd_short_name && NULL == e->ocl_cmd_single_dash_name + && NULL == e->ocl_cmd_long_name) { return OPAL_ERR_BAD_PARAM; } else if (e->ocl_num_params < 0) { return OPAL_ERR_BAD_PARAM; } /* see if the option already exists */ - if (NULL != e->ocl_cmd_single_dash_name && - NULL != find_option(cmd, e->ocl_cmd_single_dash_name)) { + if (NULL != e->ocl_cmd_single_dash_name + && NULL != find_option(cmd, e->ocl_cmd_single_dash_name)) { opal_output(0, "Duplicate cmd line entry %s", e->ocl_cmd_single_dash_name); return OPAL_ERR_BAD_PARAM; } - if (NULL != e->ocl_cmd_long_name && - NULL != find_option(cmd, e->ocl_cmd_long_name)) { + if (NULL != e->ocl_cmd_long_name && NULL != find_option(cmd, e->ocl_cmd_long_name)) { opal_output(0, "Duplicate cmd line entry %s", e->ocl_cmd_long_name); return OPAL_ERR_BAD_PARAM; } @@ -1032,8 +984,7 @@ static int make_opt(opal_cmd_line_t *cmd, opal_cmd_line_init_t *e) option->clo_type = e->ocl_variable_type; option->clo_variable_dest = e->ocl_variable_dest; if (NULL != e->ocl_mca_param_name) { - (void) mca_base_var_env_name (e->ocl_mca_param_name, - &option->clo_mca_param_env_var); + (void) mca_base_var_env_name(e->ocl_mca_param_name, &option->clo_mca_param_env_var); } option->clo_otype = e->ocl_otype; @@ -1049,7 +1000,6 @@ static int make_opt(opal_cmd_line_t *cmd, opal_cmd_line_init_t *e) return OPAL_SUCCESS; } - static void free_parse_results(opal_cmd_line_t *cmd) { opal_list_item_t *item; @@ -1057,8 +1007,7 @@ static void free_parse_results(opal_cmd_line_t *cmd) /* Free the contents of the params list (do not free the list itself; it was not allocated from the heap) */ - for (item = opal_list_remove_first(&cmd->lcl_params); - NULL != item; + for (item = opal_list_remove_first(&cmd->lcl_params); NULL != item; item = opal_list_remove_first(&cmd->lcl_params)) { OBJ_RELEASE(item); } @@ -1078,16 +1027,14 @@ static void free_parse_results(opal_cmd_line_t *cmd) cmd->lcl_tail_argc = 0; } - /* * Traverse a token and split it into individual letter options (the * token has already been certified to not be a long name and not be a * short name). Ensure to differentiate the resulting options from * "single dash" names. */ -static int split_shorts(opal_cmd_line_t *cmd, char *token, char **args, - int *output_argc, char ***output_argv, - int *num_args_used, bool ignore_unknown) +static int split_shorts(opal_cmd_line_t *cmd, char *token, char **args, int *output_argc, + char ***output_argv, int *num_args_used, bool ignore_unknown) { int i, j, len; ompi_cmd_line_option_t *option; @@ -1104,7 +1051,7 @@ static int split_shorts(opal_cmd_line_t *cmd, char *token, char **args, (argv[i] + 1), will be empty by the time it gets down here), just return that we didn't find a short option. */ - len = (int)strlen(token); + len = (int) strlen(token); if (0 == len) { return OPAL_ERR_BAD_PARAM; } @@ -1134,12 +1081,10 @@ static int split_shorts(opal_cmd_line_t *cmd, char *token, char **args, opal_argv_append(output_argc, output_argv, fake_token); for (j = 0; j < option->clo_num_params; ++j) { if (*num_args_used < num_args) { - opal_argv_append(output_argc, output_argv, - args[*num_args_used]); + opal_argv_append(output_argc, output_argv, args[*num_args_used]); ++(*num_args_used); } else { - opal_argv_append(output_argc, output_argv, - special_empty_token); + opal_argv_append(output_argc, output_argv, special_empty_token); } } } @@ -1150,9 +1095,7 @@ static int split_shorts(opal_cmd_line_t *cmd, char *token, char **args, return OPAL_SUCCESS; } - -static ompi_cmd_line_option_t *find_option(opal_cmd_line_t *cmd, - const char *option_name) +static ompi_cmd_line_option_t *find_option(opal_cmd_line_t *cmd, const char *option_name) { ompi_cmd_line_option_t *option; @@ -1160,13 +1103,11 @@ static ompi_cmd_line_option_t *find_option(opal_cmd_line_t *cmd, opal_cmd_line_t and see if we find a match in either the short or long names */ - OPAL_LIST_FOREACH(option, &cmd->lcl_options, ompi_cmd_line_option_t) { - if ((NULL != option->clo_long_name && - 0 == strcmp(option_name, option->clo_long_name)) || - (NULL != option->clo_single_dash_name && - 0 == strcmp(option_name, option->clo_single_dash_name)) || - (strlen(option_name) == 1 && - option_name[0] == option->clo_short_name)) { + OPAL_LIST_FOREACH (option, &cmd->lcl_options, ompi_cmd_line_option_t) { + if ((NULL != option->clo_long_name && 0 == strcmp(option_name, option->clo_long_name)) + || (NULL != option->clo_single_dash_name + && 0 == strcmp(option_name, option->clo_single_dash_name)) + || (strlen(option_name) == 1 && option_name[0] == option->clo_short_name)) { return option; } } @@ -1176,7 +1117,6 @@ static ompi_cmd_line_option_t *find_option(opal_cmd_line_t *cmd, return NULL; } - static int set_dest(ompi_cmd_line_option_t *option, char *sval) { int ival = atol(sval); @@ -1194,7 +1134,7 @@ static int set_dest(ompi_cmd_line_option_t *option, char *sval) during a nromal parameter lookup, and all will be well. */ if (NULL != option->clo_mca_param_env_var) { - switch(option->clo_type) { + switch (option->clo_type) { case OPAL_CMD_LINE_TYPE_STRING: case OPAL_CMD_LINE_TYPE_INT: case OPAL_CMD_LINE_TYPE_SIZE_T: @@ -1211,19 +1151,21 @@ static int set_dest(ompi_cmd_line_option_t *option, char *sval) /* Set variable */ if (NULL != option->clo_variable_dest) { - switch(option->clo_type) { + switch (option->clo_type) { case OPAL_CMD_LINE_TYPE_STRING: - *((char**) option->clo_variable_dest) = strdup(sval); + *((char **) option->clo_variable_dest) = strdup(sval); break; case OPAL_CMD_LINE_TYPE_INT: /* check to see that the value given to us truly is an int */ - for (i=0; i < strlen(sval); i++) { + for (i = 0; i < strlen(sval); i++) { if (!isdigit(sval[i]) && '-' != sval[i]) { /* show help isn't going to be available yet, so just * print the msg */ - fprintf(stderr, "----------------------------------------------------------------------------\n"); - fprintf(stderr, "Open MPI has detected that a parameter given to a command line\n"); + fprintf(stderr, "--------------------------------------------------------------" + "--------------\n"); + fprintf(stderr, + "Open MPI has detected that a parameter given to a command line\n"); fprintf(stderr, "option does not match the expected format:\n\n"); if (NULL != option->clo_long_name) { fprintf(stderr, " Option: %s\n", option->clo_long_name); @@ -1233,23 +1175,28 @@ static int set_dest(ompi_cmd_line_option_t *option, char *sval) fprintf(stderr, " Option: \n"); } fprintf(stderr, " Param: %s\n\n", sval); - fprintf(stderr, "This is frequently caused by omitting to provide the parameter\n"); - fprintf(stderr, "to an option that requires one. Please check the command line and try again.\n"); - fprintf(stderr, "----------------------------------------------------------------------------\n"); + fprintf(stderr, + "This is frequently caused by omitting to provide the parameter\n"); + fprintf(stderr, "to an option that requires one. Please check the command line " + "and try again.\n"); + fprintf(stderr, "--------------------------------------------------------------" + "--------------\n"); return OPAL_ERR_SILENT; } } - *((int*) option->clo_variable_dest) = ival; + *((int *) option->clo_variable_dest) = ival; break; case OPAL_CMD_LINE_TYPE_SIZE_T: /* check to see that the value given to us truly is a size_t */ - for (i=0; i < strlen(sval); i++) { + for (i = 0; i < strlen(sval); i++) { if (!isdigit(sval[i]) && '-' != sval[i]) { /* show help isn't going to be available yet, so just * print the msg */ - fprintf(stderr, "----------------------------------------------------------------------------\n"); - fprintf(stderr, "Open MPI has detected that a parameter given to a command line\n"); + fprintf(stderr, "--------------------------------------------------------------" + "--------------\n"); + fprintf(stderr, + "Open MPI has detected that a parameter given to a command line\n"); fprintf(stderr, "option does not match the expected format:\n\n"); if (NULL != option->clo_long_name) { fprintf(stderr, " Option: %s\n", option->clo_long_name); @@ -1259,16 +1206,19 @@ static int set_dest(ompi_cmd_line_option_t *option, char *sval) fprintf(stderr, " Option: \n"); } fprintf(stderr, " Param: %s\n\n", sval); - fprintf(stderr, "This is frequently caused by omitting to provide the parameter\n"); - fprintf(stderr, "to an option that requires one. Please check the command line and try again.\n"); - fprintf(stderr, "----------------------------------------------------------------------------\n"); + fprintf(stderr, + "This is frequently caused by omitting to provide the parameter\n"); + fprintf(stderr, "to an option that requires one. Please check the command line " + "and try again.\n"); + fprintf(stderr, "--------------------------------------------------------------" + "--------------\n"); return OPAL_ERR_SILENT; } } - *((size_t*) option->clo_variable_dest) = lval; + *((size_t *) option->clo_variable_dest) = lval; break; case OPAL_CMD_LINE_TYPE_BOOL: - *((bool*) option->clo_variable_dest) = 1; + *((bool *) option->clo_variable_dest) = 1; break; default: break; @@ -1277,7 +1227,6 @@ static int set_dest(ompi_cmd_line_option_t *option, char *sval) return OPAL_SUCCESS; } - /* * Helper function to qsort_callback */ @@ -1303,13 +1252,12 @@ static void fill(const ompi_cmd_line_option_t *a, char result[3][BUFSIZ]) } } - static int qsort_callback(const void *aa, const void *bb) { int ret, i; char str1[3][BUFSIZ], str2[3][BUFSIZ]; - const ompi_cmd_line_option_t *a = *((const ompi_cmd_line_option_t**) aa); - const ompi_cmd_line_option_t *b = *((const ompi_cmd_line_option_t**) bb); + const ompi_cmd_line_option_t *a = *((const ompi_cmd_line_option_t **) aa); + const ompi_cmd_line_option_t *b = *((const ompi_cmd_line_option_t **) bb); /* Icky comparison of command line options. There are multiple forms of each command line option, so we first have to check @@ -1330,7 +1278,6 @@ static int qsort_callback(const void *aa, const void *bb) return 0; } - /* * Helper function to find the option type specified in the help * command. @@ -1345,12 +1292,12 @@ static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd) arg = opal_cmd_line_get_param(cmd, "help", 0, 0); /* If not "help", check for "h" */ - if(NULL == arg) { + if (NULL == arg) { arg = opal_cmd_line_get_param(cmd, "h", 0, 0); } /* If arg is still NULL, give them the General info by default */ - if(NULL == arg) { + if (NULL == arg) { arg = "general"; } @@ -1387,21 +1334,24 @@ static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd) * Helper function to build a parsable string for the help * output. */ -static char *build_parsable(ompi_cmd_line_option_t *option) { +static char *build_parsable(ompi_cmd_line_option_t *option) +{ char *line; int length; - length = snprintf(NULL, 0, "%c:%s:%s:%d:%s\n", option->clo_short_name, option->clo_single_dash_name, - option->clo_long_name, option->clo_num_params, option->clo_description); + length = snprintf(NULL, 0, "%c:%s:%s:%d:%s\n", option->clo_short_name, + option->clo_single_dash_name, option->clo_long_name, option->clo_num_params, + option->clo_description); - line = (char *)malloc(length * sizeof(char)); + line = (char *) malloc(length * sizeof(char)); - if('\0' == option->clo_short_name) { - snprintf(line, length, "0:%s:%s:%d:%s\n", option->clo_single_dash_name, option->clo_long_name, - option->clo_num_params, option->clo_description); - } else { - snprintf(line, length, "%c:%s:%s:%d:%s\n", option->clo_short_name, option->clo_single_dash_name, + if ('\0' == option->clo_short_name) { + snprintf(line, length, "0:%s:%s:%d:%s\n", option->clo_single_dash_name, option->clo_long_name, option->clo_num_params, option->clo_description); + } else { + snprintf(line, length, "%c:%s:%s:%d:%s\n", option->clo_short_name, + option->clo_single_dash_name, option->clo_long_name, option->clo_num_params, + option->clo_description); } return line; diff --git a/opal/util/cmd_line.h b/opal/util/cmd_line.h index ce92259cec3..105044c2d4c 100644 --- a/opal/util/cmd_line.h +++ b/opal/util/cmd_line.h @@ -118,506 +118,494 @@ #include "opal_config.h" -#include "opal/class/opal_object.h" #include "opal/class/opal_list.h" +#include "opal/class/opal_object.h" #include "opal/mca/threads/mutex.h" BEGIN_C_DECLS - /** - * \internal - * - * Main top-level handle. This interface should not be used by users! - */ - struct opal_cmd_line_t { - /** Make this an OBJ handle */ - opal_object_t super; - - /** Thread safety */ - opal_recursive_mutex_t lcl_mutex; - - /** List of ompi_cmd_line_option_t's (defined internally) */ - opal_list_t lcl_options; - - /** Duplicate of argc from opal_cmd_line_parse() */ - int lcl_argc; - /** Duplicate of argv from opal_cmd_line_parse() */ - char **lcl_argv; - - /** Parsed output; list of ompi_cmd_line_param_t's (defined internally) */ - opal_list_t lcl_params; - - /** List of tail (unprocessed) arguments */ - int lcl_tail_argc; - /** List of tail (unprocessed) arguments */ - char **lcl_tail_argv; - }; - /** - * \internal - * - * Convenience typedef - */ - typedef struct opal_cmd_line_t opal_cmd_line_t; - - /** - * Data types supported by the parser - */ - enum opal_cmd_line_type_t { - OPAL_CMD_LINE_TYPE_NULL, - OPAL_CMD_LINE_TYPE_STRING, - OPAL_CMD_LINE_TYPE_INT, - OPAL_CMD_LINE_TYPE_SIZE_T, - OPAL_CMD_LINE_TYPE_BOOL, - - OPAL_CMD_LINE_TYPE_MAX - }; - /** - * \internal - * - * Convenience typedef - */ - typedef enum opal_cmd_line_type_t opal_cmd_line_type_t; - - /** - * Command line option type, for use in - * mpirun --help output. - */ - enum opal_cmd_line_otype_t { - OPAL_CMD_LINE_OTYPE_GENERAL, - OPAL_CMD_LINE_OTYPE_DEBUG, - OPAL_CMD_LINE_OTYPE_OUTPUT, - OPAL_CMD_LINE_OTYPE_INPUT, - OPAL_CMD_LINE_OTYPE_MAPPING, - OPAL_CMD_LINE_OTYPE_RANKING, - OPAL_CMD_LINE_OTYPE_BINDING, - OPAL_CMD_LINE_OTYPE_DEVEL, - OPAL_CMD_LINE_OTYPE_COMPAT, /* Backwards compatibility */ - OPAL_CMD_LINE_OTYPE_LAUNCH, - OPAL_CMD_LINE_OTYPE_DVM, - OPAL_CMD_LINE_OTYPE_UNSUPPORTED, - OPAL_CMD_LINE_OTYPE_PARSABLE, - OPAL_CMD_LINE_OTYPE_NULL /* include in full help only */ - }; - /** - * \internal - * - * Convenience typedef - */ - typedef enum opal_cmd_line_otype_t opal_cmd_line_otype_t; - - /** - * Datatype used to construct a command line handle; see - * opal_cmd_line_create(). - */ - struct opal_cmd_line_init_t { - /** If want to set an MCA parameter, set its parameter name - here. */ - const char *ocl_mca_param_name; - - /** "Short" name (i.e., "-X", where "X" is a single letter) */ - char ocl_cmd_short_name; - /** "Single dash" name (i.e., "-foo"). The use of these are - discouraged. */ - const char *ocl_cmd_single_dash_name; - /** Long name (i.e., "--foo"). */ - const char *ocl_cmd_long_name; - - /** Number of parameters that this option takes */ - int ocl_num_params; - - /** If this parameter is encountered, its *first* parameter it - saved here. If the parameter is encountered again, the - value is overwritten. */ - void *ocl_variable_dest; - /** If an ocl_variable_dest is given, its datatype must be - supplied as well. */ - opal_cmd_line_type_t ocl_variable_type; - - /** Description of the command line option, to be used with - opal_cmd_line_get_usage_msg(). */ - const char *ocl_description; - - /** Category for mpirun --help output */ - opal_cmd_line_otype_t ocl_otype; - }; - /** - * \internal - * - * Convenience typedef - */ - typedef struct opal_cmd_line_init_t opal_cmd_line_init_t; - - /** - * Top-level command line handle. - * - * This handle is used for accessing all command line functionality - * (i.e., all opal_cmd_line*() functions). Multiple handles can be - * created and simultaneously processed; each handle is independant - * from others. - * - * The opal_cmd_line_t handles are [simplisticly] thread safe; - * processing is guaranteed to be mutually exclusive if multiple - * threads invoke functions on the same handle at the same time -- - * access will be serialized in an unspecified order. - * - * Once finished, handles should be released with OBJ_RELEASE(). The - * destructor for opal_cmd_line_t handles will free all memory - * associated with the handle. - */ - OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_cmd_line_t); - - /** - * Make a command line handle from a table of initializers. - * - * @param cmd OPAL command line handle. - * @param table Table of opal_cmd_line_init_t instances for all - * the options to be included in the resulting command line - * handler. - * - * @retval OPAL_SUCCESS Upon success. - * - * This function takes a table of opal_cmd_line_init_t instances - * to pre-seed an OPAL command line handle. The last instance in - * the table must have '\0' for the short name and NULL for the - * single-dash and long names. The handle is expected to have - * been OBJ_NEW'ed or OBJ_CONSTRUCT'ed already. - * - * Upon return, the command line handle is just like any other. A - * sample using this syntax: - * - * \code - * opal_cmd_line_init_t cmd_line_init[] = { - * { NULL, 'h', NULL, "help", 0, - * &orterun_globals.help, OPAL_CMD_LINE_TYPE_BOOL, - * "This help message", OPAL_CMD_LINE_OTYPE_GENERAL }, - * - * { NULL, '\0', NULL, "wd", 1, - * &orterun_globals.wd, OPAL_CMD_LINE_TYPE_STRING, - * "Set the working directory of the started processes", - * OPAL_CMD_LINE_OTYPE_LAUNCH }, - * - * { NULL, '\0', NULL, NULL, 0, - * NULL, OPAL_CMD_LINE_TYPE_NULL, NULL, OPAL_CMD_LINE_OTYPE_NULL } - * }; - * \endcode - */ - OPAL_DECLSPEC int opal_cmd_line_create(opal_cmd_line_t *cmd, - opal_cmd_line_init_t *table); - - /* Add a table of opal_cmd_line_init_t instances - * to an existing OPAL command line handle. - * - * Multiple calls to opal_cmd_line_add are permitted - each - * subsequent call will simply append new options to the existing - * handle. Note that any duplicates will return an error. - */ - OPAL_DECLSPEC int opal_cmd_line_add(opal_cmd_line_t *cmd, - opal_cmd_line_init_t *table); - - /** - * Create a command line option. - * - * @param cmd OPAL command line handle. - * @param entry Command line entry to add to the command line. - * - * @retval OPAL_SUCCESS Upon success. - * - */ - OPAL_DECLSPEC int opal_cmd_line_make_opt_mca(opal_cmd_line_t *cmd, - opal_cmd_line_init_t entry); - - /** - * Create a command line option. - * - * @param cmd OPAL command line handle. - * @param short_name "Short" name of the command line option. - * @param sd_name "Single dash" name of the command line option. - * @param long_name "Long" name of the command line option. - * @param num_params How many parameters this option takes. - * @param dest Short string description of this option. - * - * @retval OPAL_ERR_OUT_OF_RESOURCE If out of memory. - * @retval OPAL_ERR_BAD_PARAM If bad parameters passed. - * @retval OPAL_SUCCESS Upon success. - * - * Adds a command line option to the list of options that an OPAL - * command line handle will accept. The short_name may take the - * special value '\0' to not have a short name. Likewise, the - * sd_name and long_name may take the special value NULL to not have - * a single dash or long name, respectively. However, one of the - * three must have a name. - * - * num_params indicates how many parameters this option takes. It - * must be greater than or equal to 0. - * - * Finally, desc is a short string description of this option. It is - * used to generate the output from opal_cmd_line_get_usage_msg(). - * - */ - OPAL_DECLSPEC int opal_cmd_line_make_opt3(opal_cmd_line_t *cmd, - char short_name, - const char *sd_name, - const char *long_name, - int num_params, - const char *desc); - - /** - * Parse a command line according to a pre-built OPAL command line - * handle. - * - * @param cmd OPAL command line handle. - * @param ignore_unknown Whether to print an error message upon - * finding an unknown token or not - * @param ignore_unknown_option Whether to print an error message upon - * finding an unknown option or not - * @param argc Length of the argv array. - * @param argv Array of strings from the command line. - * - * @retval OPAL_SUCCESS Upon success. - * @retval OPAL_ERR_SILENT If an error message was printed. This - * value will only be returned if the command line was not - * successfully parsed. - * - * Parse a series of command line tokens according to the option - * descriptions from a OPAL command line handle. The OPAL command line - * handle can then be queried to see what options were used, what - * their parameters were, etc. - * - * If an unknown token is found in the command line (i.e., a token - * that is not a parameter or a registered option), the parsing will - * stop (see below). If ignore_unknown is false, an error message - * is displayed. If ignore_unknown is true, the error message is - * not displayed. - * - * Error messages are always displayed regardless of the value - * of ignore_unknown (to stderr, and OPAL_ERR_SILENT is - * returned) if: - * - * 1. A token was encountered that required N parameters, but +# include #endif /* HAVE_STDIO_H */ #include #ifdef HAVE_STRINGS_H -#include -#endif /* HAVE_STRINGS_H */ +# include +#endif /* HAVE_STRINGS_H */ #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ #include "opal/util/crc.h" - #if (OPAL_ALIGNMENT_LONG == 8) -#define OPAL_CRC_WORD_MASK_ 0x7 +# define OPAL_CRC_WORD_MASK_ 0x7 #elif (OPAL_ALIGNMENT_LONG == 4) -#define OPAL_CRC_WORD_MASK_ 0x3 +# define OPAL_CRC_WORD_MASK_ 0x3 #else -#define OPAL_CRC_WORD_MASK_ 0xFFFF +# define OPAL_CRC_WORD_MASK_ 0xFFFF #endif +#define WORDALIGNED(v) (((intptr_t) v & OPAL_CRC_WORD_MASK_) ? false : true) -#define WORDALIGNED(v) \ - (((intptr_t)v & OPAL_CRC_WORD_MASK_) ? false : true) - - -#define INTALIGNED(v) \ - (((intptr_t)v & 3) ? false : true) +#define INTALIGNED(v) (((intptr_t) v & 3) ? false : true) /* * this version of bcopy_csum() looks a little too long, but it @@ -59,18 +53,12 @@ * of bcopy_csum() - Mitch */ -unsigned long -opal_bcopy_csum_partial ( - const void * source, - void * destination, - size_t copylen, - size_t csumlen, - unsigned long * lastPartialLong, - size_t* lastPartialLength - ) +unsigned long opal_bcopy_csum_partial(const void *source, void *destination, size_t copylen, + size_t csumlen, unsigned long *lastPartialLong, + size_t *lastPartialLength) { - unsigned long * src = (unsigned long *) source; - unsigned long * dest = (unsigned long *) destination; + unsigned long *src = (unsigned long *) source; + unsigned long *dest = (unsigned long *) destination; unsigned long csum = 0; size_t csumlenresidue; unsigned long i, temp; @@ -79,345 +67,325 @@ opal_bcopy_csum_partial ( temp = *lastPartialLong; if (WORDALIGNED(source) && WORDALIGNED(dest)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned long) - *lastPartialLength)); - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - dest = (unsigned long *)((char *)dest + sizeof(unsigned long) - *lastPartialLength); - csum += (temp - *lastPartialLong); - copylen -= sizeof(unsigned long) - *lastPartialLength; - /* now we have an unaligned source and an unaligned destination */ - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLength = 0; - *lastPartialLong = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned long *)((char *)src + copylen); - dest = (unsigned long *)((char *)dest + copylen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { /* fast path... */ - size_t numLongs = copylen/sizeof(unsigned long); - for(i = 0; i < numLongs; i++) { - csum += *src; - *dest++ = *src++; - } - *lastPartialLong = 0; - *lastPartialLength = 0; - if (WORDALIGNED(copylen) && (csumlenresidue == 0)) { - return(csum); - } - else { - copylen -= i * sizeof(unsigned long); - } - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned long) - *lastPartialLength)); + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + dest = (unsigned long *) ((char *) dest + sizeof(unsigned long) + - *lastPartialLength); + csum += (temp - *lastPartialLong); + copylen -= sizeof(unsigned long) - *lastPartialLength; + /* now we have an unaligned source and an unaligned destination */ + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLength = 0; + *lastPartialLong = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned long *) ((char *) src + copylen); + dest = (unsigned long *) ((char *) dest + copylen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { /* fast path... */ + size_t numLongs = copylen / sizeof(unsigned long); + for (i = 0; i < numLongs; i++) { + csum += *src; + *dest++ = *src++; + } + *lastPartialLong = 0; + *lastPartialLength = 0; + if (WORDALIGNED(copylen) && (csumlenresidue == 0)) { + return (csum); + } else { + copylen -= i * sizeof(unsigned long); + } + } } else if (WORDALIGNED(source)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned long) - *lastPartialLength)); - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - dest = (unsigned long *)((char *)dest + sizeof(unsigned long) - *lastPartialLength); - csum += (temp - *lastPartialLong); - copylen -= sizeof(unsigned long) - *lastPartialLength; - /* now we have an unaligned source and an unknown alignment for our destination */ - if (WORDALIGNED(dest)) { - size_t numLongs = copylen/sizeof(unsigned long); - for(i = 0; i < numLongs; i++) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - *dest++ = temp; - } - copylen -= i * sizeof(unsigned long); - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - } - *lastPartialLong = 0; - *lastPartialLength = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned long *)((char *)src + copylen); - dest = (unsigned long *)((char *)dest + copylen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - temp = *src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLong = 0; - *lastPartialLength = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned long) - *lastPartialLength)); + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + dest = (unsigned long *) ((char *) dest + sizeof(unsigned long) + - *lastPartialLength); + csum += (temp - *lastPartialLong); + copylen -= sizeof(unsigned long) - *lastPartialLength; + /* now we have an unaligned source and an unknown alignment for our destination */ + if (WORDALIGNED(dest)) { + size_t numLongs = copylen / sizeof(unsigned long); + for (i = 0; i < numLongs; i++) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + *dest++ = temp; + } + copylen -= i * sizeof(unsigned long); + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + } + *lastPartialLong = 0; + *lastPartialLength = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned long *) ((char *) src + copylen); + dest = (unsigned long *) ((char *) dest + copylen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + temp = *src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLong = 0; + *lastPartialLength = 0; + } } else if (WORDALIGNED(dest)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned long) - *lastPartialLength)); - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - dest = (unsigned long *)((char *)dest + sizeof(unsigned long) - *lastPartialLength); - csum += (temp - *lastPartialLong); - copylen -= sizeof(unsigned long) - *lastPartialLength; - /* now we have a source of unknown alignment and a unaligned destination */ - if (WORDALIGNED(src)) { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - temp = *src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLong = 0; - *lastPartialLength = 0; - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLength = 0; - *lastPartialLong = 0; - } - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned long *)((char *)src + copylen); - dest = (unsigned long *)((char *)dest + copylen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - *dest++ = temp; - } - *lastPartialLength = 0; - *lastPartialLong = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned long) - *lastPartialLength)); + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + dest = (unsigned long *) ((char *) dest + sizeof(unsigned long) + - *lastPartialLength); + csum += (temp - *lastPartialLong); + copylen -= sizeof(unsigned long) - *lastPartialLength; + /* now we have a source of unknown alignment and a unaligned destination */ + if (WORDALIGNED(src)) { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + temp = *src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLong = 0; + *lastPartialLength = 0; + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLength = 0; + *lastPartialLong = 0; + } + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned long *) ((char *) src + copylen); + dest = (unsigned long *) ((char *) dest + copylen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + *dest++ = temp; + } + *lastPartialLength = 0; + *lastPartialLong = 0; + } } else { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned long) - *lastPartialLength)); - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - dest = (unsigned long *)((char *)dest + sizeof(unsigned long) - *lastPartialLength); - csum += (temp - *lastPartialLong); - copylen -= sizeof(unsigned long) - *lastPartialLength; - /* now we have an unknown alignment for our source and destination */ - if (WORDALIGNED(src) && WORDALIGNED(dest)) { - size_t numLongs = copylen/sizeof(unsigned long); - for(i = 0; i < numLongs; i++) { - csum += *src; - *dest++ = *src++; - } - copylen -= i * sizeof(unsigned long); - } - else { /* safe but slower for all other alignments */ - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - } - *lastPartialLong = 0; - *lastPartialLength = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned long *)((char *)src + copylen); - dest = (unsigned long *)((char *)dest + copylen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLength = 0; - *lastPartialLong = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned long) - *lastPartialLength)); + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + dest = (unsigned long *) ((char *) dest + sizeof(unsigned long) + - *lastPartialLength); + csum += (temp - *lastPartialLong); + copylen -= sizeof(unsigned long) - *lastPartialLength; + /* now we have an unknown alignment for our source and destination */ + if (WORDALIGNED(src) && WORDALIGNED(dest)) { + size_t numLongs = copylen / sizeof(unsigned long); + for (i = 0; i < numLongs; i++) { + csum += *src; + *dest++ = *src++; + } + copylen -= i * sizeof(unsigned long); + } else { /* safe but slower for all other alignments */ + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + } + *lastPartialLong = 0; + *lastPartialLength = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned long *) ((char *) src + copylen); + dest = (unsigned long *) ((char *) dest + copylen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLength = 0; + *lastPartialLong = 0; + } } /* if copylen is non-zero there was a bit left, less than an unsigned long's worth */ if ((copylen != 0) && (csumlenresidue == 0)) { - temp = *lastPartialLong; - if (*lastPartialLength) { - if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { - /* copy all remaining bytes from src to dest */ - unsigned long copytemp = 0; - memcpy(©temp, src, copylen); - memcpy(dest, ©temp, copylen); - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - /* avoid unsigned arithmetic overflow by subtracting the old partial - * word from the new one before adding to the checksum... - */ - csum += (temp - *lastPartialLong); - copylen -= sizeof(unsigned long) - *lastPartialLength; - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - *lastPartialLength = copylen; - /* reset temp, and calculate next partial word */ - temp = 0; - if (copylen) { - memcpy(&temp, src, copylen); - } - /* add it to the the checksum */ - csum += temp; - *lastPartialLong = temp; - } - else { - /* copy all remaining bytes from src to dest */ - unsigned long copytemp = 0; - memcpy(©temp, src, copylen); - memcpy(dest, ©temp, copylen); - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - copylen); - /* avoid unsigned arithmetic overflow by subtracting the old partial - * word from the new one before adding to the checksum... - */ - csum += temp - *lastPartialLong; - *lastPartialLong = temp; - *lastPartialLength += copylen; - } - } - else { /* fast path... */ - /* temp and *lastPartialLong are 0 if *lastPartialLength is 0... */ - memcpy(&temp, src, copylen); - csum += temp; - memcpy(dest, &temp, copylen); - *lastPartialLong = temp; - *lastPartialLength = copylen; - /* done...return the checksum */ - } - } - else if (csumlenresidue != 0) { - if (copylen != 0) { - temp = 0; - memcpy(&temp, src, copylen); - memcpy(dest, &temp, copylen); - } - if (csumlenresidue < (sizeof(unsigned long) - copylen - *lastPartialLength)) { - temp = *lastPartialLong; - memcpy(((char *)&temp + *lastPartialLength), src, (copylen + csumlenresidue)); - /* avoid unsigned arithmetic overflow by subtracting the old partial */ - /* word from the new one before adding to the checksum... */ - csum += temp - *lastPartialLong; - src++; - *lastPartialLong = temp; - *lastPartialLength += copylen + csumlenresidue; - csumlenresidue = 0; - } - else { - /* we have enough chksum data to fill out our last partial */ - /* word */ - temp = *lastPartialLong; - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - /* avoid unsigned arithmetic overflow by subtracting the old partial */ - /* word from the new one before adding to the checksum... */ - csum += temp - *lastPartialLong; - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - csumlenresidue -= sizeof(unsigned long) - *lastPartialLength - copylen; - *lastPartialLength = 0; - *lastPartialLong = 0; - } - if (WORDALIGNED(src)) { - for (i = 0; i < csumlenresidue/sizeof(unsigned long); i++) { - csum += *src++; - } - } - else { - for (i = 0; i < csumlenresidue/sizeof(unsigned long); i++) { - memcpy(&temp, src, sizeof(temp)); - csum += temp; - src++; - } - } - csumlenresidue -= i * sizeof(unsigned long); - if (csumlenresidue) { - temp = 0; - memcpy(&temp, src, csumlenresidue); - csum += temp; - *lastPartialLong = temp; - *lastPartialLength = csumlenresidue; - } + temp = *lastPartialLong; + if (*lastPartialLength) { + if (copylen >= (sizeof(unsigned long) - *lastPartialLength)) { + /* copy all remaining bytes from src to dest */ + unsigned long copytemp = 0; + memcpy(©temp, src, copylen); + memcpy(dest, ©temp, copylen); + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + /* avoid unsigned arithmetic overflow by subtracting the old partial + * word from the new one before adding to the checksum... + */ + csum += (temp - *lastPartialLong); + copylen -= sizeof(unsigned long) - *lastPartialLength; + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + *lastPartialLength = copylen; + /* reset temp, and calculate next partial word */ + temp = 0; + if (copylen) { + memcpy(&temp, src, copylen); + } + /* add it to the the checksum */ + csum += temp; + *lastPartialLong = temp; + } else { + /* copy all remaining bytes from src to dest */ + unsigned long copytemp = 0; + memcpy(©temp, src, copylen); + memcpy(dest, ©temp, copylen); + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + /* avoid unsigned arithmetic overflow by subtracting the old partial + * word from the new one before adding to the checksum... + */ + csum += temp - *lastPartialLong; + *lastPartialLong = temp; + *lastPartialLength += copylen; + } + } else { /* fast path... */ + /* temp and *lastPartialLong are 0 if *lastPartialLength is 0... */ + memcpy(&temp, src, copylen); + csum += temp; + memcpy(dest, &temp, copylen); + *lastPartialLong = temp; + *lastPartialLength = copylen; + /* done...return the checksum */ + } + } else if (csumlenresidue != 0) { + if (copylen != 0) { + temp = 0; + memcpy(&temp, src, copylen); + memcpy(dest, &temp, copylen); + } + if (csumlenresidue < (sizeof(unsigned long) - copylen - *lastPartialLength)) { + temp = *lastPartialLong; + memcpy(((char *) &temp + *lastPartialLength), src, (copylen + csumlenresidue)); + /* avoid unsigned arithmetic overflow by subtracting the old partial */ + /* word from the new one before adding to the checksum... */ + csum += temp - *lastPartialLong; + src++; + *lastPartialLong = temp; + *lastPartialLength += copylen + csumlenresidue; + csumlenresidue = 0; + } else { + /* we have enough chksum data to fill out our last partial */ + /* word */ + temp = *lastPartialLong; + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + /* avoid unsigned arithmetic overflow by subtracting the old partial */ + /* word from the new one before adding to the checksum... */ + csum += temp - *lastPartialLong; + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + csumlenresidue -= sizeof(unsigned long) - *lastPartialLength - copylen; + *lastPartialLength = 0; + *lastPartialLong = 0; + } + if (WORDALIGNED(src)) { + for (i = 0; i < csumlenresidue / sizeof(unsigned long); i++) { + csum += *src++; + } + } else { + for (i = 0; i < csumlenresidue / sizeof(unsigned long); i++) { + memcpy(&temp, src, sizeof(temp)); + csum += temp; + src++; + } + } + csumlenresidue -= i * sizeof(unsigned long); + if (csumlenresidue) { + temp = 0; + memcpy(&temp, src, csumlenresidue); + csum += temp; + *lastPartialLong = temp; + *lastPartialLength = csumlenresidue; + } } /* end else if (csumlenresidue != 0) */ return csum; } -unsigned int -opal_bcopy_uicsum_partial ( - const void * source, - void * destination, - size_t copylen, - size_t csumlen, - unsigned int* lastPartialInt, - size_t* lastPartialLength - ) +unsigned int opal_bcopy_uicsum_partial(const void *source, void *destination, size_t copylen, + size_t csumlen, unsigned int *lastPartialInt, + size_t *lastPartialLength) { - unsigned int * src = (unsigned int *) source; - unsigned int * dest = (unsigned int *) destination; + unsigned int *src = (unsigned int *) source; + unsigned int *dest = (unsigned int *) destination; unsigned int csum = 0; size_t csumlenresidue; unsigned long i; @@ -427,637 +395,587 @@ opal_bcopy_uicsum_partial ( temp = *lastPartialInt; if (INTALIGNED(source) && INTALIGNED(dest)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned int) - *lastPartialLength)); - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - dest = (unsigned int *)((char *)dest + sizeof(unsigned int) - *lastPartialLength); - csum += (temp - *lastPartialInt); - copylen -= sizeof(unsigned int) - *lastPartialLength; - /* now we have an unaligned source and an unaligned destination */ - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLength = 0; - *lastPartialInt = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned int *)((char *)src + copylen); - dest = (unsigned int *)((char *)dest + copylen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { /* fast path... */ - size_t numLongs = copylen/sizeof(unsigned int); - for(i = 0; i < numLongs; i++) { - csum += *src; - *dest++ = *src++; - } - *lastPartialInt = 0; - *lastPartialLength = 0; - if (INTALIGNED(copylen) && (csumlenresidue == 0)) { - return(csum); - } - else { - copylen -= i * sizeof(unsigned int); - } - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned int) - *lastPartialLength)); + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + dest = (unsigned int *) ((char *) dest + sizeof(unsigned int) - *lastPartialLength); + csum += (temp - *lastPartialInt); + copylen -= sizeof(unsigned int) - *lastPartialLength; + /* now we have an unaligned source and an unaligned destination */ + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLength = 0; + *lastPartialInt = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned int *) ((char *) src + copylen); + dest = (unsigned int *) ((char *) dest + copylen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { /* fast path... */ + size_t numLongs = copylen / sizeof(unsigned int); + for (i = 0; i < numLongs; i++) { + csum += *src; + *dest++ = *src++; + } + *lastPartialInt = 0; + *lastPartialLength = 0; + if (INTALIGNED(copylen) && (csumlenresidue == 0)) { + return (csum); + } else { + copylen -= i * sizeof(unsigned int); + } + } } else if (INTALIGNED(source)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned int) - *lastPartialLength)); - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - dest = (unsigned int *)((char *)dest + sizeof(unsigned int) - *lastPartialLength); - csum += (temp - *lastPartialInt); - copylen -= sizeof(unsigned int) - *lastPartialLength; - /* now we have an unaligned source and an unknown alignment for our destination */ - if (INTALIGNED(dest)) { - size_t numLongs = copylen/sizeof(unsigned int); - for(i = 0; i < numLongs; i++) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - *dest++ = temp; - } - copylen -= i * sizeof(unsigned int); - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - } - *lastPartialInt = 0; - *lastPartialLength = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned int *)((char *)src + copylen); - dest = (unsigned int *)((char *)dest + copylen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - temp = *src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialInt = 0; - *lastPartialLength = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned int) - *lastPartialLength)); + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + dest = (unsigned int *) ((char *) dest + sizeof(unsigned int) - *lastPartialLength); + csum += (temp - *lastPartialInt); + copylen -= sizeof(unsigned int) - *lastPartialLength; + /* now we have an unaligned source and an unknown alignment for our destination */ + if (INTALIGNED(dest)) { + size_t numLongs = copylen / sizeof(unsigned int); + for (i = 0; i < numLongs; i++) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + *dest++ = temp; + } + copylen -= i * sizeof(unsigned int); + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + } + *lastPartialInt = 0; + *lastPartialLength = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned int *) ((char *) src + copylen); + dest = (unsigned int *) ((char *) dest + copylen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + temp = *src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialInt = 0; + *lastPartialLength = 0; + } } else if (INTALIGNED(dest)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned int) - *lastPartialLength)); - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - dest = (unsigned int *)((char *)dest + sizeof(unsigned int) - *lastPartialLength); - csum += (temp - *lastPartialInt); - copylen -= sizeof(unsigned int) - *lastPartialLength; - /* now we have a source of unknown alignment and a unaligned destination */ - if (INTALIGNED(src)) { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - temp = *src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialInt = 0; - *lastPartialLength = 0; - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLength = 0; - *lastPartialInt = 0; - } - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned int *)((char *)src + copylen); - dest = (unsigned int *)((char *)dest + copylen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - *dest++ = temp; - } - *lastPartialLength = 0; - *lastPartialInt = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned int) - *lastPartialLength)); + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + dest = (unsigned int *) ((char *) dest + sizeof(unsigned int) - *lastPartialLength); + csum += (temp - *lastPartialInt); + copylen -= sizeof(unsigned int) - *lastPartialLength; + /* now we have a source of unknown alignment and a unaligned destination */ + if (INTALIGNED(src)) { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + temp = *src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialInt = 0; + *lastPartialLength = 0; + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLength = 0; + *lastPartialInt = 0; + } + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned int *) ((char *) src + copylen); + dest = (unsigned int *) ((char *) dest + copylen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + *dest++ = temp; + } + *lastPartialLength = 0; + *lastPartialInt = 0; + } } else { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - memcpy(dest, ((char *)&temp + *lastPartialLength), - (sizeof(unsigned int) - *lastPartialLength)); - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - dest = (unsigned int *)((char *)dest + sizeof(unsigned int) - *lastPartialLength); - csum += (temp - *lastPartialInt); - copylen -= sizeof(unsigned int) - *lastPartialLength; - /* now we have an unknown alignment for our source and destination */ - if (INTALIGNED(src) && INTALIGNED(dest)) { - size_t numLongs = copylen/sizeof(unsigned int); - for(i = 0; i < numLongs; i++) { - csum += *src; - *dest++ = *src++; - } - copylen -= i * sizeof(unsigned int); - } - else { /* safe but slower for all other alignments */ - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - } - *lastPartialInt = 0; - *lastPartialLength = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, copylen); - memcpy(dest, ((char *)&temp + *lastPartialLength), copylen); - src = (unsigned int *)((char *)src + copylen); - dest = (unsigned int *)((char *)dest + copylen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += copylen; - copylen = 0; - } - } - else { - for( ;copylen >= sizeof(*src); copylen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - memcpy(dest, &temp, sizeof(temp)); - dest++; - } - *lastPartialLength = 0; - *lastPartialInt = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + memcpy(dest, ((char *) &temp + *lastPartialLength), + (sizeof(unsigned int) - *lastPartialLength)); + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + dest = (unsigned int *) ((char *) dest + sizeof(unsigned int) - *lastPartialLength); + csum += (temp - *lastPartialInt); + copylen -= sizeof(unsigned int) - *lastPartialLength; + /* now we have an unknown alignment for our source and destination */ + if (INTALIGNED(src) && INTALIGNED(dest)) { + size_t numLongs = copylen / sizeof(unsigned int); + for (i = 0; i < numLongs; i++) { + csum += *src; + *dest++ = *src++; + } + copylen -= i * sizeof(unsigned int); + } else { /* safe but slower for all other alignments */ + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + } + *lastPartialInt = 0; + *lastPartialLength = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + memcpy(dest, ((char *) &temp + *lastPartialLength), copylen); + src = (unsigned int *) ((char *) src + copylen); + dest = (unsigned int *) ((char *) dest + copylen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += copylen; + copylen = 0; + } + } else { + for (; copylen >= sizeof(*src); copylen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + memcpy(dest, &temp, sizeof(temp)); + dest++; + } + *lastPartialLength = 0; + *lastPartialInt = 0; + } } /* if copylen is non-zero there was a bit left, less than an unsigned int's worth */ if ((copylen != 0) && (csumlenresidue == 0)) { - temp = *lastPartialInt; - if (*lastPartialLength) { - if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { - /* copy all remaining bytes from src to dest */ - unsigned int copytemp = 0; - memcpy(©temp, src, copylen); - memcpy(dest, ©temp, copylen); - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - /* avoid unsigned arithmetic overflow by subtracting the old partial - * word from the new one before adding to the checksum... - */ - csum += (temp - *lastPartialInt); - copylen -= sizeof(unsigned int) - *lastPartialLength; - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - *lastPartialLength = copylen; - /* reset temp, and calculate next partial word */ - temp = 0; - if (copylen) { - memcpy(&temp, src, copylen); - } - /* add it to the the checksum */ - csum += temp; - *lastPartialInt = temp; - } - else { - /* copy all remaining bytes from src to dest */ - unsigned int copytemp = 0; - memcpy(©temp, src, copylen); - memcpy(dest, ©temp, copylen); - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - copylen); - /* avoid unsigned arithmetic overflow by subtracting the old partial - * word from the new one before adding to the checksum... - */ - csum += temp - *lastPartialInt; - *lastPartialInt = temp; - *lastPartialLength += copylen; - } - } - else { /* fast path... */ - /* temp and *lastPartialInt are 0 if *lastPartialLength is 0... */ - memcpy(&temp, src, copylen); - csum += temp; - memcpy(dest, &temp, copylen); - *lastPartialInt = temp; - *lastPartialLength = copylen; - /* done...return the checksum */ - } - } - else if (csumlenresidue != 0) { - if (copylen != 0) { - temp = 0; - memcpy(&temp, src, copylen); - memcpy(dest, &temp, copylen); - } - if (csumlenresidue < (sizeof(unsigned int) - copylen - *lastPartialLength)) { - temp = *lastPartialInt; - memcpy(((char *)&temp + *lastPartialLength), src, (copylen + csumlenresidue)); - /* avoid unsigned arithmetic overflow by subtracting the old partial - * word from the new one before adding to the checksum... - */ - csum += temp - *lastPartialInt; - src++; - *lastPartialInt = temp; - *lastPartialLength += copylen + csumlenresidue; - csumlenresidue = 0; - } - else { - /* we have enough chksum data to fill out our last partial - * word - */ - temp = *lastPartialInt; - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - /* avoid unsigned arithmetic overflow by subtracting the old partial - * word from the new one before adding to the checksum... - */ - csum += temp - *lastPartialInt; - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - csumlenresidue -= sizeof(unsigned int) - *lastPartialLength - copylen; - *lastPartialLength = 0; - *lastPartialInt = 0; - } - if (INTALIGNED(src)) { - for (i = 0; i < csumlenresidue/sizeof(unsigned int); i++) { - csum += *src++; - } - } - else { - for (i = 0; i < csumlenresidue/sizeof(unsigned int); i++) { - memcpy(&temp, src, sizeof(temp)); - csum += temp; - src++; - } - } - csumlenresidue -= i * sizeof(unsigned int); - if (csumlenresidue) { - temp = 0; - memcpy(&temp, src, csumlenresidue); - csum += temp; - *lastPartialInt = temp; - *lastPartialLength = csumlenresidue; - } + temp = *lastPartialInt; + if (*lastPartialLength) { + if (copylen >= (sizeof(unsigned int) - *lastPartialLength)) { + /* copy all remaining bytes from src to dest */ + unsigned int copytemp = 0; + memcpy(©temp, src, copylen); + memcpy(dest, ©temp, copylen); + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + /* avoid unsigned arithmetic overflow by subtracting the old partial + * word from the new one before adding to the checksum... + */ + csum += (temp - *lastPartialInt); + copylen -= sizeof(unsigned int) - *lastPartialLength; + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + *lastPartialLength = copylen; + /* reset temp, and calculate next partial word */ + temp = 0; + if (copylen) { + memcpy(&temp, src, copylen); + } + /* add it to the the checksum */ + csum += temp; + *lastPartialInt = temp; + } else { + /* copy all remaining bytes from src to dest */ + unsigned int copytemp = 0; + memcpy(©temp, src, copylen); + memcpy(dest, ©temp, copylen); + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, copylen); + /* avoid unsigned arithmetic overflow by subtracting the old partial + * word from the new one before adding to the checksum... + */ + csum += temp - *lastPartialInt; + *lastPartialInt = temp; + *lastPartialLength += copylen; + } + } else { /* fast path... */ + /* temp and *lastPartialInt are 0 if *lastPartialLength is 0... */ + memcpy(&temp, src, copylen); + csum += temp; + memcpy(dest, &temp, copylen); + *lastPartialInt = temp; + *lastPartialLength = copylen; + /* done...return the checksum */ + } + } else if (csumlenresidue != 0) { + if (copylen != 0) { + temp = 0; + memcpy(&temp, src, copylen); + memcpy(dest, &temp, copylen); + } + if (csumlenresidue < (sizeof(unsigned int) - copylen - *lastPartialLength)) { + temp = *lastPartialInt; + memcpy(((char *) &temp + *lastPartialLength), src, (copylen + csumlenresidue)); + /* avoid unsigned arithmetic overflow by subtracting the old partial + * word from the new one before adding to the checksum... + */ + csum += temp - *lastPartialInt; + src++; + *lastPartialInt = temp; + *lastPartialLength += copylen + csumlenresidue; + csumlenresidue = 0; + } else { + /* we have enough chksum data to fill out our last partial + * word + */ + temp = *lastPartialInt; + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + /* avoid unsigned arithmetic overflow by subtracting the old partial + * word from the new one before adding to the checksum... + */ + csum += temp - *lastPartialInt; + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + csumlenresidue -= sizeof(unsigned int) - *lastPartialLength - copylen; + *lastPartialLength = 0; + *lastPartialInt = 0; + } + if (INTALIGNED(src)) { + for (i = 0; i < csumlenresidue / sizeof(unsigned int); i++) { + csum += *src++; + } + } else { + for (i = 0; i < csumlenresidue / sizeof(unsigned int); i++) { + memcpy(&temp, src, sizeof(temp)); + csum += temp; + src++; + } + } + csumlenresidue -= i * sizeof(unsigned int); + if (csumlenresidue) { + temp = 0; + memcpy(&temp, src, csumlenresidue); + csum += temp; + *lastPartialInt = temp; + *lastPartialLength = csumlenresidue; + } } /* end else if (csumlenresidue != 0) */ return csum; } - /* * csum() generates a bcopy_csum() - compatible checksum that can be * called multiple times */ -unsigned long -opal_csum_partial ( - const void * source, - size_t csumlen, - unsigned long* lastPartialLong, - size_t* lastPartialLength - ) +unsigned long opal_csum_partial(const void *source, size_t csumlen, unsigned long *lastPartialLong, + size_t *lastPartialLength) { - unsigned long * src = (unsigned long *) source; + unsigned long *src = (unsigned long *) source; unsigned long csum = 0; unsigned long i, temp; - - temp = *lastPartialLong; - if (WORDALIGNED(source)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (csumlen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - csum += (temp - *lastPartialLong); - csumlen -= sizeof(unsigned long) - *lastPartialLength; - /* now we have an unaligned source */ - for(i = 0; i < csumlen/sizeof(unsigned long); i++) { - memcpy(&temp, src, sizeof(temp)); - csum += temp; - src++; - } - csumlen -= i * sizeof(unsigned long); - *lastPartialLong = 0; - *lastPartialLength = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, csumlen); - src = (unsigned long *)((char *)src + csumlen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += csumlen; - csumlen = 0; - } - } - else { /* fast path... */ - size_t numLongs = csumlen/sizeof(unsigned long); - for(i = 0; i < numLongs; i++) { - csum += *src++; - } - *lastPartialLong = 0; - *lastPartialLength = 0; - if (WORDALIGNED(csumlen)) { - return(csum); - } - else { - csumlen -= i * sizeof(unsigned long); - } - } + if (WORDALIGNED(source)) { + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (csumlen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + csum += (temp - *lastPartialLong); + csumlen -= sizeof(unsigned long) - *lastPartialLength; + /* now we have an unaligned source */ + for (i = 0; i < csumlen / sizeof(unsigned long); i++) { + memcpy(&temp, src, sizeof(temp)); + csum += temp; + src++; + } + csumlen -= i * sizeof(unsigned long); + *lastPartialLong = 0; + *lastPartialLength = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, csumlen); + src = (unsigned long *) ((char *) src + csumlen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += csumlen; + csumlen = 0; + } + } else { /* fast path... */ + size_t numLongs = csumlen / sizeof(unsigned long); + for (i = 0; i < numLongs; i++) { + csum += *src++; + } + *lastPartialLong = 0; + *lastPartialLength = 0; + if (WORDALIGNED(csumlen)) { + return (csum); + } else { + csumlen -= i * sizeof(unsigned long); + } + } } else { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (csumlen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - csum += (temp - *lastPartialLong); - csumlen -= sizeof(unsigned long) - *lastPartialLength; - /* now we have a source of unknown alignment */ - if (WORDALIGNED(src)) { - for(i = 0; i < csumlen/sizeof(unsigned long); i++) { - csum += *src++; - } - csumlen -= i * sizeof(unsigned long); - *lastPartialLong = 0; - *lastPartialLength = 0; - } - else { - for(i = 0; i < csumlen/sizeof(unsigned long); i++) { - memcpy(&temp, src, sizeof(temp)); - csum += temp; - src++; - } - csumlen -= i * sizeof(unsigned long); - *lastPartialLong = 0; - *lastPartialLength = 0; - } - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, csumlen); - src = (unsigned long *)((char *)src + csumlen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += csumlen; - csumlen = 0; - } - } - else { - for( ;csumlen >= sizeof(*src); csumlen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - } - *lastPartialLength = 0; - *lastPartialLong = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (csumlen >= (sizeof(unsigned long) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + csum += (temp - *lastPartialLong); + csumlen -= sizeof(unsigned long) - *lastPartialLength; + /* now we have a source of unknown alignment */ + if (WORDALIGNED(src)) { + for (i = 0; i < csumlen / sizeof(unsigned long); i++) { + csum += *src++; + } + csumlen -= i * sizeof(unsigned long); + *lastPartialLong = 0; + *lastPartialLength = 0; + } else { + for (i = 0; i < csumlen / sizeof(unsigned long); i++) { + memcpy(&temp, src, sizeof(temp)); + csum += temp; + src++; + } + csumlen -= i * sizeof(unsigned long); + *lastPartialLong = 0; + *lastPartialLength = 0; + } + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, csumlen); + src = (unsigned long *) ((char *) src + csumlen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += csumlen; + csumlen = 0; + } + } else { + for (; csumlen >= sizeof(*src); csumlen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + } + *lastPartialLength = 0; + *lastPartialLong = 0; + } } /* if csumlen is non-zero there was a bit left, less than an unsigned long's worth */ if (csumlen != 0) { - temp = *lastPartialLong; - if (*lastPartialLength) { - if (csumlen >= (sizeof(unsigned long) - *lastPartialLength)) { - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned long) - *lastPartialLength)); - csum += (temp - *lastPartialLong); - csumlen -= sizeof(unsigned long) - *lastPartialLength; - src = (unsigned long *)((char *)src + sizeof(unsigned long) - *lastPartialLength); - *lastPartialLength = csumlen; - /* reset temp, and calculate next partial word */ - temp = 0; - if (csumlen) { - memcpy(&temp, src, csumlen); - } - /* add it to the the checksum */ - csum += temp; - *lastPartialLong = temp; - } - else { - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - csumlen); - csum += (temp - *lastPartialLong); - *lastPartialLong = temp; - *lastPartialLength += csumlen; - } - } - else { /* fast path... */ - /* temp and *lastPartialLong are 0 if *lastPartialLength is 0... */ - memcpy(&temp, src, csumlen); - csum += temp; - *lastPartialLong = temp; - *lastPartialLength = csumlen; - /* done...return the checksum */ - } + temp = *lastPartialLong; + if (*lastPartialLength) { + if (csumlen >= (sizeof(unsigned long) - *lastPartialLength)) { + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned long) - *lastPartialLength)); + csum += (temp - *lastPartialLong); + csumlen -= sizeof(unsigned long) - *lastPartialLength; + src = (unsigned long *) ((char *) src + sizeof(unsigned long) - *lastPartialLength); + *lastPartialLength = csumlen; + /* reset temp, and calculate next partial word */ + temp = 0; + if (csumlen) { + memcpy(&temp, src, csumlen); + } + /* add it to the the checksum */ + csum += temp; + *lastPartialLong = temp; + } else { + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, csumlen); + csum += (temp - *lastPartialLong); + *lastPartialLong = temp; + *lastPartialLength += csumlen; + } + } else { /* fast path... */ + /* temp and *lastPartialLong are 0 if *lastPartialLength is 0... */ + memcpy(&temp, src, csumlen); + csum += temp; + *lastPartialLong = temp; + *lastPartialLength = csumlen; + /* done...return the checksum */ + } } return csum; } -unsigned int -opal_uicsum_partial ( - const void * source, - size_t csumlen, - unsigned int* lastPartialInt, - size_t* lastPartialLength - ) +unsigned int opal_uicsum_partial(const void *source, size_t csumlen, unsigned int *lastPartialInt, + size_t *lastPartialLength) { - unsigned int * src = (unsigned int *) source; + unsigned int *src = (unsigned int *) source; unsigned int csum = 0; unsigned int temp; unsigned long i; - temp = *lastPartialInt; - if (INTALIGNED(source)) { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (csumlen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - csum += (temp - *lastPartialInt); - csumlen -= sizeof(unsigned int) - *lastPartialLength; - /* now we have an unaligned source */ - for(i = 0; i < csumlen/sizeof(unsigned int); i++) { - memcpy(&temp, src, sizeof(temp)); - csum += temp; - src++; - } - csumlen -= i * sizeof(unsigned int); - *lastPartialInt = 0; - *lastPartialLength = 0; - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, csumlen); - src = (unsigned int *)((char *)src + csumlen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += csumlen; - csumlen = 0; - } - } - else { /* fast path... */ - size_t numLongs = csumlen/sizeof(unsigned int); - for(i = 0; i < numLongs; i++) { - csum += *src++; - } - *lastPartialInt = 0; - *lastPartialLength = 0; - if (INTALIGNED(csumlen)) { - return(csum); - } - else { - csumlen -= i * sizeof(unsigned int); - } - } + if (INTALIGNED(source)) { + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (csumlen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + csum += (temp - *lastPartialInt); + csumlen -= sizeof(unsigned int) - *lastPartialLength; + /* now we have an unaligned source */ + for (i = 0; i < csumlen / sizeof(unsigned int); i++) { + memcpy(&temp, src, sizeof(temp)); + csum += temp; + src++; + } + csumlen -= i * sizeof(unsigned int); + *lastPartialInt = 0; + *lastPartialLength = 0; + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, csumlen); + src = (unsigned int *) ((char *) src + csumlen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += csumlen; + csumlen = 0; + } + } else { /* fast path... */ + size_t numLongs = csumlen / sizeof(unsigned int); + for (i = 0; i < numLongs; i++) { + csum += *src++; + } + *lastPartialInt = 0; + *lastPartialLength = 0; + if (INTALIGNED(csumlen)) { + return (csum); + } else { + csumlen -= i * sizeof(unsigned int); + } + } } else { - if (*lastPartialLength) { - /* do we have enough data to fill out the partial word? */ - if (csumlen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - csum += (temp - *lastPartialInt); - csumlen -= sizeof(unsigned int) - *lastPartialLength; - /* now we have a source of unknown alignment */ - if (INTALIGNED(src)) { - for(i = 0; i < csumlen/sizeof(unsigned int); i++) { - csum += *src++; - } - csumlen -= i * sizeof(unsigned int); - *lastPartialInt = 0; - *lastPartialLength = 0; - } - else { - for(i = 0; i < csumlen/sizeof(unsigned int); i++) { - memcpy(&temp, src, sizeof(temp)); - csum += temp; - src++; - } - csumlen -= i * sizeof(unsigned int); - *lastPartialInt = 0; - *lastPartialLength = 0; - } - } - else { /* NO, we don't... */ - memcpy(((char *)&temp + *lastPartialLength), src, csumlen); - src = (unsigned int *)((char *)src + csumlen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += csumlen; - csumlen = 0; - } - } - else { - for( ;csumlen >= sizeof(*src); csumlen -= sizeof(*src)) { - memcpy(&temp, src, sizeof(temp)); - src++; - csum += temp; - } - *lastPartialLength = 0; - *lastPartialInt = 0; - } + if (*lastPartialLength) { + /* do we have enough data to fill out the partial word? */ + if (csumlen >= (sizeof(unsigned int) - *lastPartialLength)) { /* YES, we do... */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + csum += (temp - *lastPartialInt); + csumlen -= sizeof(unsigned int) - *lastPartialLength; + /* now we have a source of unknown alignment */ + if (INTALIGNED(src)) { + for (i = 0; i < csumlen / sizeof(unsigned int); i++) { + csum += *src++; + } + csumlen -= i * sizeof(unsigned int); + *lastPartialInt = 0; + *lastPartialLength = 0; + } else { + for (i = 0; i < csumlen / sizeof(unsigned int); i++) { + memcpy(&temp, src, sizeof(temp)); + csum += temp; + src++; + } + csumlen -= i * sizeof(unsigned int); + *lastPartialInt = 0; + *lastPartialLength = 0; + } + } else { /* NO, we don't... */ + memcpy(((char *) &temp + *lastPartialLength), src, csumlen); + src = (unsigned int *) ((char *) src + csumlen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += csumlen; + csumlen = 0; + } + } else { + for (; csumlen >= sizeof(*src); csumlen -= sizeof(*src)) { + memcpy(&temp, src, sizeof(temp)); + src++; + csum += temp; + } + *lastPartialLength = 0; + *lastPartialInt = 0; + } } /* if csumlen is non-zero there was a bit left, less than an unsigned int's worth */ if (csumlen != 0) { - temp = *lastPartialInt; - if (*lastPartialLength) { - if (csumlen >= (sizeof(unsigned int) - *lastPartialLength)) { - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - (sizeof(unsigned int) - *lastPartialLength)); - csum += (temp - *lastPartialInt); - csumlen -= sizeof(unsigned int) - *lastPartialLength; - src = (unsigned int *)((char *)src + sizeof(unsigned int) - *lastPartialLength); - *lastPartialLength = csumlen; - /* reset temp, and calculate next partial word */ - temp = 0; - if (csumlen) { - memcpy(&temp, src, csumlen); - } - /* add it to the the checksum */ - csum += temp; - *lastPartialInt = temp; - } - else { - /* fill out rest of partial word and add to checksum */ - memcpy(((char *)&temp + *lastPartialLength), src, - csumlen); - csum += (temp - *lastPartialInt); - *lastPartialInt = temp; - *lastPartialLength += csumlen; - } - } - else { /* fast path... */ - /* temp and *lastPartialInt are 0 if *lastPartialLength is 0... */ - memcpy(&temp, src, csumlen); - csum += temp; - *lastPartialInt = temp; - *lastPartialLength = csumlen; - /* done...return the checksum */ - } + temp = *lastPartialInt; + if (*lastPartialLength) { + if (csumlen >= (sizeof(unsigned int) - *lastPartialLength)) { + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, + (sizeof(unsigned int) - *lastPartialLength)); + csum += (temp - *lastPartialInt); + csumlen -= sizeof(unsigned int) - *lastPartialLength; + src = (unsigned int *) ((char *) src + sizeof(unsigned int) - *lastPartialLength); + *lastPartialLength = csumlen; + /* reset temp, and calculate next partial word */ + temp = 0; + if (csumlen) { + memcpy(&temp, src, csumlen); + } + /* add it to the the checksum */ + csum += temp; + *lastPartialInt = temp; + } else { + /* fill out rest of partial word and add to checksum */ + memcpy(((char *) &temp + *lastPartialLength), src, csumlen); + csum += (temp - *lastPartialInt); + *lastPartialInt = temp; + *lastPartialLength += csumlen; + } + } else { /* fast path... */ + /* temp and *lastPartialInt are 0 if *lastPartialLength is 0... */ + memcpy(&temp, src, csumlen); + csum += temp; + *lastPartialInt = temp; + *lastPartialLength = csumlen; + /* done...return the checksum */ + } } return csum; @@ -1074,16 +992,17 @@ static unsigned int _opal_crc_table[256]; void opal_initialize_crc_table(void) { - register int i,j; + register int i, j; register unsigned int crc_accum; for (i = 0; i < 256; i++) { crc_accum = (i << 24); for (j = 0; j < 8; j++) { - if (crc_accum & 0x80000000) + if (crc_accum & 0x80000000) { crc_accum = (crc_accum << 1) ^ CRC_POLYNOMIAL; - else + } else { crc_accum = (crc_accum << 1); + } } _opal_crc_table[i] = crc_accum; } @@ -1093,12 +1012,8 @@ void opal_initialize_crc_table(void) return; } -unsigned int opal_bcopy_uicrc_partial( - const void * source, - void * destination, - size_t copylen, - size_t crclen, - unsigned int partial_crc) +unsigned int opal_bcopy_uicrc_partial(const void *source, void *destination, size_t copylen, + size_t crclen, unsigned int partial_crc) { size_t crclenresidue = (crclen > copylen) ? (crclen - copylen) : 0; register int i, j; @@ -1110,22 +1025,22 @@ unsigned int opal_bcopy_uicrc_partial( } if (INTALIGNED(source) && INTALIGNED(destination)) { - register unsigned int * src = (unsigned int *)source; - register unsigned int * dst = (unsigned int *)destination; + register unsigned int *src = (unsigned int *) source; + register unsigned int *dst = (unsigned int *) destination; register unsigned char *ts, *td; /* copy whole integers */ while (copylen >= sizeof(unsigned int)) { tmp = *src++; *dst++ = tmp; - ts = (unsigned char *)&tmp; - for (j = 0; j < (int)sizeof(unsigned int); j++) { + ts = (unsigned char *) &tmp; + for (j = 0; j < (int) sizeof(unsigned int); j++) { i = ((partial_crc >> 24) ^ *ts++) & 0xff; partial_crc = (partial_crc << 8) ^ _opal_crc_table[i]; } copylen -= sizeof(unsigned int); } - ts = (unsigned char *)src; - td = (unsigned char *)dst; + ts = (unsigned char *) src; + td = (unsigned char *) dst; /* copy partial integer */ while (copylen--) { t = *ts++; @@ -1138,10 +1053,9 @@ unsigned int opal_bcopy_uicrc_partial( i = ((partial_crc >> 24) ^ *ts++) & 0xff; partial_crc = (partial_crc << 8) ^ _opal_crc_table[i]; } - } - else { - register unsigned char * src = (unsigned char *)source; - register unsigned char * dst = (unsigned char *)destination; + } else { + register unsigned char *src = (unsigned char *) source; + register unsigned char *dst = (unsigned char *) destination; while (copylen--) { t = *src++; *dst++ = t; @@ -1157,12 +1071,10 @@ unsigned int opal_bcopy_uicrc_partial( return partial_crc; } - -unsigned int opal_uicrc_partial( - const void * source, size_t crclen, unsigned int partial_crc) +unsigned int opal_uicrc_partial(const void *source, size_t crclen, unsigned int partial_crc) { register int i, j; - register unsigned char * t; + register unsigned char *t; unsigned int tmp; if (!_opal_crc_table_initialized) { @@ -1170,24 +1082,23 @@ unsigned int opal_uicrc_partial( } if (INTALIGNED(source)) { - register unsigned int * src = (unsigned int *)source; + register unsigned int *src = (unsigned int *) source; while (crclen >= sizeof(unsigned int)) { tmp = *src++; - t = (unsigned char *)&tmp; - for (j = 0; j < (int)sizeof(unsigned int); j++) { + t = (unsigned char *) &tmp; + for (j = 0; j < (int) sizeof(unsigned int); j++) { i = ((partial_crc >> 24) ^ *t++) & 0xff; partial_crc = (partial_crc << 8) ^ _opal_crc_table[i]; } crclen -= sizeof(unsigned int); } - t = (unsigned char *)src; + t = (unsigned char *) src; while (crclen--) { i = ((partial_crc >> 24) ^ *t++) & 0xff; partial_crc = (partial_crc << 8) ^ _opal_crc_table[i]; } - } - else { - register unsigned char * src = (unsigned char *)source; + } else { + register unsigned char *src = (unsigned char *) source; while (crclen--) { i = ((partial_crc >> 24) ^ *src++) & 0xff; partial_crc = (partial_crc << 8) ^ _opal_crc_table[i]; @@ -1196,4 +1107,3 @@ unsigned int opal_uicrc_partial( return partial_crc; } - diff --git a/opal/util/crc.h b/opal/util/crc.h index 22228d1a789..dd4235f4b79 100644 --- a/opal/util/crc.h +++ b/opal/util/crc.h @@ -28,75 +28,46 @@ BEGIN_C_DECLS -#define CRC_POLYNOMIAL ((unsigned int)0x04c11db7) -#define CRC_INITIAL_REGISTER ((unsigned int)0xffffffff) - - -#define OPAL_CSUM( SRC, LEN ) opal_uicsum( SRC, LEN ) -#define OPAL_CSUM_PARTIAL( SRC, LEN, UI1, UI2 ) \ - opal_uicsum_partial( SRC, LEN, UI1, UI2 ) -#define OPAL_CSUM_BCOPY_PARTIAL( SRC, DST, LEN1, LEN2, UI1, UI2 ) \ - opal_bcopy_uicsum_partial( SRC, DST, LEN1, LEN2, UI1, UI2 ) -#define OPAL_CSUM_ZERO 0 - - -OPAL_DECLSPEC unsigned long -opal_bcopy_csum_partial( - const void * source, - void * destination, - size_t copylen, - size_t csumlen, - unsigned long* lastPartialLong, - size_t* lastPartialLength - ); - -static inline unsigned long -opal_bcopy_csum ( - const void * source, - void * destination, - size_t copylen, - size_t csumlen - ) +#define CRC_POLYNOMIAL ((unsigned int) 0x04c11db7) +#define CRC_INITIAL_REGISTER ((unsigned int) 0xffffffff) + +#define OPAL_CSUM(SRC, LEN) opal_uicsum(SRC, LEN) +#define OPAL_CSUM_PARTIAL(SRC, LEN, UI1, UI2) opal_uicsum_partial(SRC, LEN, UI1, UI2) +#define OPAL_CSUM_BCOPY_PARTIAL(SRC, DST, LEN1, LEN2, UI1, UI2) \ + opal_bcopy_uicsum_partial(SRC, DST, LEN1, LEN2, UI1, UI2) +#define OPAL_CSUM_ZERO 0 + +OPAL_DECLSPEC unsigned long opal_bcopy_csum_partial(const void *source, void *destination, + size_t copylen, size_t csumlen, + unsigned long *lastPartialLong, + size_t *lastPartialLength); + +static inline unsigned long opal_bcopy_csum(const void *source, void *destination, size_t copylen, + size_t csumlen) { unsigned long plong = 0; size_t plength = 0; return opal_bcopy_csum_partial(source, destination, copylen, csumlen, &plong, &plength); } -OPAL_DECLSPEC unsigned int -opal_bcopy_uicsum_partial ( - const void * source, - void * destination, - size_t copylen, - size_t csumlen, - unsigned int* lastPartialInt, - size_t* lastPartialLength - ); - -static inline unsigned int -opal_bcopy_uicsum ( - const void * source, - void * destination, - size_t copylen, - size_t csumlen - ) +OPAL_DECLSPEC unsigned int opal_bcopy_uicsum_partial(const void *source, void *destination, + size_t copylen, size_t csumlen, + unsigned int *lastPartialInt, + size_t *lastPartialLength); + +static inline unsigned int opal_bcopy_uicsum(const void *source, void *destination, size_t copylen, + size_t csumlen) { unsigned int pint = 0; size_t plength = 0; return opal_bcopy_uicsum_partial(source, destination, copylen, csumlen, &pint, &plength); } -OPAL_DECLSPEC unsigned long -opal_csum_partial ( - const void * source, - size_t csumlen, - unsigned long* lastPartialLong, - size_t* lastPartialLength - ); - +OPAL_DECLSPEC unsigned long opal_csum_partial(const void *source, size_t csumlen, + unsigned long *lastPartialLong, + size_t *lastPartialLength); -static inline unsigned long -opal_csum(const void * source, size_t csumlen) +static inline unsigned long opal_csum(const void *source, size_t csumlen) { unsigned long lastPartialLong = 0; size_t lastPartialLength = 0; @@ -105,36 +76,30 @@ opal_csum(const void * source, size_t csumlen) /* * The buffer passed to this function is assumed to be 16-bit aligned */ -static inline uint16_t -opal_csum16 (const void * source, size_t csumlen) +static inline uint16_t opal_csum16(const void *source, size_t csumlen) { uint16_t *src = (uint16_t *) source; register uint32_t csum = 0; while (csumlen > 1) { - csum += *src++; + csum += *src++; csumlen -= 2; } /* Add leftover byte, if any */ - if(csumlen > 0) - csum += *((unsigned char*)src); + if (csumlen > 0) + csum += *((unsigned char *) src); /* Fold 32-bit checksum to 16 bits */ - while(csum >> 16) { + while (csum >> 16) { csum = (csum & 0xFFFF) + (csum >> 16); } return csum; } -OPAL_DECLSPEC unsigned int -opal_uicsum_partial ( - const void * source, - size_t csumlen, - unsigned int * lastPartialInt, - size_t* lastPartialLength - ); +OPAL_DECLSPEC unsigned int opal_uicsum_partial(const void *source, size_t csumlen, + unsigned int *lastPartialInt, + size_t *lastPartialLength); -static inline unsigned int -opal_uicsum(const void * source, size_t csumlen) +static inline unsigned int opal_uicsum(const void *source, size_t csumlen) { unsigned int lastPartialInt = 0; size_t lastPartialLength = 0; @@ -147,33 +112,20 @@ opal_uicsum(const void * source, size_t csumlen) void opal_initialize_crc_table(void); -OPAL_DECLSPEC unsigned int -opal_bcopy_uicrc_partial( - const void * source, - void * destination, - size_t copylen, - size_t crclen, - unsigned int partial_crc); - -static inline unsigned int -opal_bcopy_uicrc( - const void * source, - void * destination, - size_t copylen, - size_t crclen) +OPAL_DECLSPEC unsigned int opal_bcopy_uicrc_partial(const void *source, void *destination, + size_t copylen, size_t crclen, + unsigned int partial_crc); + +static inline unsigned int opal_bcopy_uicrc(const void *source, void *destination, size_t copylen, + size_t crclen) { return opal_bcopy_uicrc_partial(source, destination, copylen, crclen, CRC_INITIAL_REGISTER); } -OPAL_DECLSPEC unsigned int -opal_uicrc_partial( - const void * source, - size_t crclen, - unsigned int partial_crc); +OPAL_DECLSPEC unsigned int opal_uicrc_partial(const void *source, size_t crclen, + unsigned int partial_crc); - -static inline unsigned int -opal_uicrc(const void * source, size_t crclen) +static inline unsigned int opal_uicrc(const void *source, size_t crclen) { return opal_uicrc_partial(source, crclen, CRC_INITIAL_REGISTER); } @@ -181,4 +133,3 @@ opal_uicrc(const void * source, size_t crclen) END_C_DECLS #endif - diff --git a/opal/util/daemon_init.c b/opal/util/daemon_init.c index 6caae124224..55059836131 100644 --- a/opal/util/daemon_init.c +++ b/opal/util/daemon_init.c @@ -18,21 +18,19 @@ * $HEADER$ */ - #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #include -#include "opal/util/daemon_init.h" #include "opal/constants.h" - +#include "opal/util/daemon_init.h" int opal_daemon_init(char *working_dir) { @@ -43,16 +41,16 @@ int opal_daemon_init(char *working_dir) if ((pid = fork()) < 0) { return OPAL_ERROR; } else if (pid != 0) { - exit(0); /* parent goes bye-bye */ + exit(0); /* parent goes bye-bye */ } /* child continues */ -#if defined(HAVE_SETSID) - setsid(); /* become session leader */ -#endif +# if defined(HAVE_SETSID) + setsid(); /* become session leader */ +# endif if (NULL != working_dir) { - chdir(working_dir); /* change working directory */ + chdir(working_dir); /* change working directory */ } /* connect input to /dev/null */ @@ -61,12 +59,12 @@ int opal_daemon_init(char *working_dir) return OPAL_ERR_FATAL; } dup2(fd, STDIN_FILENO); - if(fd != STDIN_FILENO) { + if (fd != STDIN_FILENO) { close(fd); } /* connect outputs to /dev/null */ - fd = open("/dev/null", O_RDWR|O_CREAT|O_TRUNC, 0666); + fd = open("/dev/null", O_RDWR | O_CREAT | O_TRUNC, 0666); if (fd >= 0) { dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); @@ -76,8 +74,8 @@ int opal_daemon_init(char *working_dir) * since one of the two would still be open and * someone could attempt to use it. */ - if(fd != STDOUT_FILENO && fd != STDERR_FILENO) { - close(fd); + if (fd != STDOUT_FILENO && fd != STDERR_FILENO) { + close(fd); } } else { return OPAL_ERR_FATAL; diff --git a/opal/util/daemon_init.h b/opal/util/daemon_init.h index ebcf46074d8..74b00768502 100644 --- a/opal/util/daemon_init.h +++ b/opal/util/daemon_init.h @@ -27,15 +27,17 @@ BEGIN_C_DECLS /* * Turn a process into a daemon. * - * This function converts a process into a daemon in an orderly manner. It first forks a child process, - * then the parent exits. The child continues on to become a session leader, reset the file mode creation - * mask, and changes working directories to the one specified. + * This function converts a process into a daemon in an orderly manner. It first forks a child + * process, then the parent exits. The child continues on to become a session leader, reset the file + * mode creation mask, and changes working directories to the one specified. * - * @param working_dir Pointer to a character string containing the desired working directory. Providing - * a value of NULL will cause the function to leave the program in the current working directory. + * @param working_dir Pointer to a character string containing the desired working directory. + * Providing a value of NULL will cause the function to leave the program in the current working + * directory. * * @retval OPAL_SUCCESS Indicates that the conversion was successful - * @retval OPAL_ERROR Indicates that the conversion was not successful - a fork could not be completed. + * @retval OPAL_ERROR Indicates that the conversion was not successful - a fork could not be + * completed. */ OPAL_DECLSPEC int opal_daemon_init(char *working_dir); diff --git a/opal/util/error.c b/opal/util/error.c index 25a49faa561..efbbacf3b9e 100644 --- a/opal/util/error.c +++ b/opal/util/error.c @@ -26,20 +26,20 @@ #include "opal_config.h" -#include #include #include #include +#include #include -#include "opal/util/error.h" -#include "opal/util/string_copy.h" #include "opal/constants.h" -#include "opal/util/proc.h" -#include "opal/util/printf.h" #include "opal/runtime/opal_params.h" +#include "opal/util/error.h" +#include "opal/util/printf.h" +#include "opal/util/proc.h" +#include "opal/util/string_copy.h" -#define MAX_CONVERTERS 5 +#define MAX_CONVERTERS 5 #define MAX_CONVERTER_PROJECT_LEN 10 struct converter_info_t { @@ -54,16 +54,14 @@ typedef struct converter_info_t converter_info_t; /* all default to NULL */ static converter_info_t converters[MAX_CONVERTERS] = {{0}}; -static int -opal_strerror_int(int errnum, const char **str) +static int opal_strerror_int(int errnum, const char **str) { int i, ret = OPAL_SUCCESS; *str = NULL; - for (i = 0 ; i < MAX_CONVERTERS ; ++i) { - if (0 != converters[i].init && - errnum < converters[i].err_base && - converters[i].err_max < errnum) { + for (i = 0; i < MAX_CONVERTERS; ++i) { + if (0 != converters[i].init && errnum < converters[i].err_base + && converters[i].err_max < errnum) { ret = converters[i].converter(errnum, str); break; } @@ -72,21 +70,17 @@ opal_strerror_int(int errnum, const char **str) return ret; } - /* caller must free string */ -static int -opal_strerror_unknown(int errnum, char **str) +static int opal_strerror_unknown(int errnum, char **str) { int i; *str = NULL; - for (i = 0 ; i < MAX_CONVERTERS ; ++i) { + for (i = 0; i < MAX_CONVERTERS; ++i) { if (0 != converters[i].init) { - if (errnum < converters[i].err_base && - errnum > converters[i].err_max) { - opal_asprintf(str, "Unknown error: %d (%s error %d)", - errnum, converters[i].project, - errnum - converters[i].err_base); + if (errnum < converters[i].err_base && errnum > converters[i].err_max) { + opal_asprintf(str, "Unknown error: %d (%s error %d)", errnum, converters[i].project, + errnum - converters[i].err_base); return OPAL_SUCCESS; } } @@ -97,12 +91,10 @@ opal_strerror_unknown(int errnum, char **str) return OPAL_SUCCESS; } - -void -opal_perror(int errnum, const char *msg) +void opal_perror(int errnum, const char *msg) { int ret; - const char* errmsg; + const char *errmsg; ret = opal_strerror_int(errnum, &errmsg); if (NULL != msg && errnum != OPAL_ERR_IN_ERRNO) { @@ -129,11 +121,10 @@ opal_perror(int errnum, const char *msg) #define UNKNOWN_RETBUF_LEN 50 static char unknown_retbuf[UNKNOWN_RETBUF_LEN]; -const char * -opal_strerror(int errnum) +const char *opal_strerror(int errnum) { int ret; - const char* errmsg; + const char *errmsg; if (errnum == OPAL_ERR_IN_ERRNO) { return strerror(errno); @@ -147,17 +138,15 @@ opal_strerror(int errnum) snprintf(unknown_retbuf, UNKNOWN_RETBUF_LEN, "%s", ue_msg); free(ue_msg); errno = EINVAL; - return (const char*) unknown_retbuf; + return (const char *) unknown_retbuf; } else { return errmsg; } } - -int -opal_strerror_r(int errnum, char *strerrbuf, size_t buflen) +int opal_strerror_r(int errnum, char *strerrbuf, size_t buflen) { - const char* errmsg; + const char *errmsg; int ret, len; ret = opal_strerror_int(errnum, &errmsg); @@ -169,7 +158,7 @@ opal_strerror_r(int errnum, char *strerrbuf, size_t buflen) } else { char *ue_msg; ret = opal_strerror_unknown(errnum, &ue_msg); - len = snprintf(strerrbuf, buflen, "%s", ue_msg); + len = snprintf(strerrbuf, buflen, "%s", ue_msg); free(ue_msg); if (len > (int) buflen) { errno = ERANGE; @@ -180,7 +169,7 @@ opal_strerror_r(int errnum, char *strerrbuf, size_t buflen) } } } else { - len = snprintf(strerrbuf, buflen, "%s", errmsg); + len = snprintf(strerrbuf, buflen, "%s", errmsg); if (len > (int) buflen) { errno = ERANGE; return OPAL_ERR_OUT_OF_RESOURCE; @@ -190,25 +179,21 @@ opal_strerror_r(int errnum, char *strerrbuf, size_t buflen) } } - -int -opal_error_register(const char *project, int err_base, int err_max, - opal_err2str_fn_t converter) +int opal_error_register(const char *project, int err_base, int err_max, opal_err2str_fn_t converter) { int i; - for (i = 0 ; i < MAX_CONVERTERS ; ++i) { + for (i = 0; i < MAX_CONVERTERS; ++i) { if (0 == converters[i].init) { converters[i].init = 1; opal_string_copy(converters[i].project, project, MAX_CONVERTER_PROJECT_LEN); - converters[i].project[MAX_CONVERTER_PROJECT_LEN-1] = '\0'; + converters[i].project[MAX_CONVERTER_PROJECT_LEN - 1] = '\0'; converters[i].err_base = err_base; converters[i].err_max = err_max; converters[i].converter = converter; return OPAL_SUCCESS; - } else if (converters[i].err_base == err_base && - converters[i].err_max == err_max && - !strcmp (project, converters[i].project)) { + } else if (converters[i].err_base == err_base && converters[i].err_max == err_max + && !strcmp(project, converters[i].project)) { converters[i].converter = converter; return OPAL_SUCCESS; } @@ -217,9 +202,7 @@ opal_error_register(const char *project, int err_base, int err_max, return OPAL_ERR_OUT_OF_RESOURCE; } - -void -opal_delay_abort(void) +void opal_delay_abort(void) { // Though snprintf and strlen are not guaranteed to be async-signal-safe // in POSIX, it is async-signal-safe on many implementations probably. @@ -239,8 +222,7 @@ opal_delay_abort(void) sleep(5); } } else { - snprintf(msg, sizeof(msg), - "[%s:%05d] Delaying for %d seconds before aborting\n", + snprintf(msg, sizeof(msg), "[%s:%05d] Delaying for %d seconds before aborting\n", opal_process_info.nodename, (int) pid, delay); write(STDERR_FILENO, msg, strlen(msg)); do { diff --git a/opal/util/error.h b/opal/util/error.h index d90fe9f0807..2ffa92a48a6 100644 --- a/opal/util/error.h +++ b/opal/util/error.h @@ -27,9 +27,7 @@ BEGIN_C_DECLS #define OPAL_ERROR_LOG(r) \ - opal_output(0, "OPAL ERROR: %s in file %s at line %d", \ - opal_strerror((r)), __FILE__, __LINE__); - + opal_output(0, "OPAL ERROR: %s in file %s at line %d", opal_strerror((r)), __FILE__, __LINE__); /** * Prints error message for errnum on stderr @@ -72,7 +70,6 @@ OPAL_DECLSPEC const char *opal_strerror(int errnum); */ OPAL_DECLSPEC int opal_strerror_r(int errnum, char *strerrbuf, size_t buflen); - typedef int (*opal_err2str_fn_t)(int errnum, const char **str); /** @@ -86,8 +83,7 @@ typedef int (*opal_err2str_fn_t)(int errnum, const char **str); * \note A maximum of 5 converters can be registered. The 6th * converter registration attempt will return OPAL_ERR_OUT_OF_RESOURCE */ -OPAL_DECLSPEC int opal_error_register(const char *project, - int err_base, int err_max, +OPAL_DECLSPEC int opal_error_register(const char *project, int err_base, int err_max, opal_err2str_fn_t converter); /** diff --git a/opal/util/ethtool.c b/opal/util/ethtool.c index 84aa5c09c64..621396c8375 100644 --- a/opal/util/ethtool.c +++ b/opal/util/ethtool.c @@ -12,29 +12,29 @@ #include "opal_config.h" -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_NET_IF_H -#include +# include #endif #ifdef HAVE_LINUX_ETHTOOL_H -#include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_LINUX_SOCKIOS_H -#include +# include #endif #include "opal/util/ethtool.h" @@ -46,8 +46,7 @@ * get this via an ioctl(). Elsewhere or in the error case, we return the * speed as 0. */ -unsigned int -opal_ethtool_get_speed (const char *if_name) +unsigned int opal_ethtool_get_speed(const char *if_name) { unsigned int speed = 0; @@ -65,19 +64,19 @@ opal_ethtool_get_speed (const char *if_name) memset(&ifr, 0, sizeof(struct ifreq)); opal_string_copy(ifr.ifr_name, if_name, OPAL_IF_NAMESIZE); - ifr.ifr_data = (char *)&edata; + ifr.ifr_data = (char *) &edata; if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) { goto out; } -#if HAVE_DECL_ETHTOOL_CMD_SPEED +# if HAVE_DECL_ETHTOOL_CMD_SPEED speed = ethtool_cmd_speed(&edata); -#elif defined(HAVE_STRUCT_ETHTOOL_CMD_SPEED_HI) +# elif defined(HAVE_STRUCT_ETHTOOL_CMD_SPEED_HI) speed = (edata.speed_hi << 16) | edata.speed; -#else +# else speed = edata.speed; -#endif +# endif if (UINT_MAX == speed) { speed = 0; } diff --git a/opal/util/event.c b/opal/util/event.c index 6330ac2838d..aab045220d0 100644 --- a/opal/util/event.c +++ b/opal/util/event.c @@ -24,12 +24,12 @@ #include "opal/util/event.h" #include "opal/constants.h" +#include "opal/mca/base/mca_base_var.h" #include "opal/util/argv.h" #include "opal/util/output.h" #include "opal/util/printf.h" -#include "opal/mca/base/mca_base_var.h" -opal_event_base_t *opal_sync_event_base=NULL; +opal_event_base_t *opal_sync_event_base = NULL; static char *opal_event_module_include = NULL; static struct event_config *opal_event_config = NULL; @@ -46,25 +46,22 @@ int opal_event_register_params(void) opal_event_all_available_eventops = event_get_supported_methods(); #ifdef __APPLE__ - opal_event_module_include ="select"; + opal_event_module_include = "select"; #else opal_event_module_include = "poll"; #endif - avail = opal_argv_join((char**)opal_event_all_available_eventops, ','); - opal_asprintf( &help_msg, - "Comma-delimited list of libevent subsystems " - "to use (%s -- available on your platform)", - avail ); - - ret = mca_base_var_register("opal", "opal", "event", "include", - help_msg, - MCA_BASE_VAR_TYPE_STRING, NULL, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - &opal_event_module_include); - free(help_msg); /* release the help message */ + avail = opal_argv_join((char **) opal_event_all_available_eventops, ','); + opal_asprintf(&help_msg, + "Comma-delimited list of libevent subsystems " + "to use (%s -- available on your platform)", + avail); + + ret = mca_base_var_register("opal", "opal", "event", "include", help_msg, + MCA_BASE_VAR_TYPE_STRING, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, + OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_LOCAL, + &opal_event_module_include); + free(help_msg); /* release the help message */ free(avail); avail = NULL; @@ -72,19 +69,16 @@ int opal_event_register_params(void) return ret; } - ret = mca_base_var_register_synonym (ret, "opal", "event", "external", "include", 0); + ret = mca_base_var_register_synonym(ret, "opal", "event", "external", "include", 0); if (0 > ret) { return ret; } ret = mca_base_var_register("opal", "opal", "event", "verbose", "Verbosity level for the event framework (default: 0)", - MCA_BASE_VAR_TYPE_INT, - &mca_base_var_enum_verbose, 0, - MCA_BASE_VAR_FLAG_SETTABLE, - OPAL_INFO_LVL_3, - MCA_BASE_VAR_SCOPE_LOCAL, - &opal_event_verbose); + MCA_BASE_VAR_TYPE_INT, &mca_base_var_enum_verbose, 0, + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, + MCA_BASE_VAR_SCOPE_LOCAL, &opal_event_verbose); if (0 > ret) { return ret; } @@ -92,7 +86,7 @@ int opal_event_register_params(void) /* The event wrapper used to be a framework. Help the user out by * providing a backwards compatible verbose flag */ - ret = mca_base_var_register_synonym (ret, "opal", "event", "base", "verbose", 0); + ret = mca_base_var_register_synonym(ret, "opal", "event", "base", "verbose", 0); if (0 > ret) { return ret; } @@ -102,8 +96,8 @@ int opal_event_register_params(void) int opal_event_init(void) { - char **includes=NULL; - bool dumpit=false; + char **includes = NULL; + bool dumpit = false; int i, j; if (opal_event_verbose > 4) { @@ -114,19 +108,19 @@ int opal_event_init(void) /* Shouldn't happen, but... */ opal_event_module_include = strdup("select"); } - includes = opal_argv_split(opal_event_module_include,','); + includes = opal_argv_split(opal_event_module_include, ','); /* get a configuration object */ opal_event_config = event_config_new(); /* cycle thru the available subsystems */ - for (i = 0 ; NULL != opal_event_all_available_eventops[i] ; ++i) { + for (i = 0; NULL != opal_event_all_available_eventops[i]; ++i) { /* if this module isn't included in the given ones, * then exclude it */ dumpit = true; - for (j=0; NULL != includes[j]; j++) { - if (0 == strcmp("all", includes[j]) || - 0 == strcmp(opal_event_all_available_eventops[i], includes[j])) { + for (j = 0; NULL != includes[j]; j++) { + if (0 == strcmp("all", includes[j]) + || 0 == strcmp(opal_event_all_available_eventops[i], includes[j])) { dumpit = false; break; } @@ -158,7 +152,7 @@ int opal_event_finalize(void) return OPAL_SUCCESS; } -opal_event_base_t* opal_event_base_create(void) +opal_event_base_t *opal_event_base_create(void) { opal_event_base_t *base; @@ -170,10 +164,10 @@ opal_event_base_t* opal_event_base_create(void) return base; } -opal_event_t* opal_event_alloc(void) +opal_event_t *opal_event_alloc(void) { opal_event_t *ev; - ev = (opal_event_t*)malloc(sizeof(opal_event_t)); + ev = (opal_event_t *) malloc(sizeof(opal_event_t)); return ev; } diff --git a/opal/util/event.h b/opal/util/event.h index b66eb0344fd..01550afbe4b 100644 --- a/opal/util/event.h +++ b/opal/util/event.h @@ -18,28 +18,30 @@ #include "opal_config.h" -#include #include +#include #include BEGIN_C_DECLS /* set the number of event priority levels */ -#define OPAL_EVENT_NUM_PRI 8 - -#define OPAL_EV_ERROR_PRI 0 -#define OPAL_EV_MSG_HI_PRI 1 -#define OPAL_EV_SYS_HI_PRI 2 -#define OPAL_EV_MSG_LO_PRI 3 -#define OPAL_EV_SYS_LO_PRI 4 -#define OPAL_EV_INFO_HI_PRI 5 -#define OPAL_EV_INFO_LO_PRI 6 -#define OPAL_EV_LOWEST_PRI 7 +#define OPAL_EVENT_NUM_PRI 8 -#define OPAL_EVENT_SIGNAL(ev) opal_event_get_signal(ev) +#define OPAL_EV_ERROR_PRI 0 +#define OPAL_EV_MSG_HI_PRI 1 +#define OPAL_EV_SYS_HI_PRI 2 +#define OPAL_EV_MSG_LO_PRI 3 +#define OPAL_EV_SYS_LO_PRI 4 +#define OPAL_EV_INFO_HI_PRI 5 +#define OPAL_EV_INFO_LO_PRI 6 +#define OPAL_EV_LOWEST_PRI 7 -#define OPAL_TIMEOUT_DEFAULT {1, 0} +#define OPAL_EVENT_SIGNAL(ev) opal_event_get_signal(ev) +#define OPAL_TIMEOUT_DEFAULT \ + { \ + 1, 0 \ + } typedef event_callback_fn opal_event_cbfunc_t; @@ -57,11 +59,11 @@ OPAL_DECLSPEC extern opal_event_base_t *opal_sync_event_base; /* Persistent event: won't get removed automatically when activated. */ #define OPAL_EV_PERSIST EV_PERSIST -#define OPAL_EVLOOP_ONCE EVLOOP_ONCE /**< Block at most once. */ -#define OPAL_EVLOOP_NONBLOCK EVLOOP_NONBLOCK /**< Do not block. */ +#define OPAL_EVLOOP_ONCE EVLOOP_ONCE /**< Block at most once. */ +#define OPAL_EVLOOP_NONBLOCK EVLOOP_NONBLOCK /**< Do not block. */ /* Global function to create and release an event base */ -OPAL_DECLSPEC opal_event_base_t* opal_event_base_create(void); +OPAL_DECLSPEC opal_event_base_t *opal_event_base_create(void); #define opal_event_base_free(x) event_base_free(x) @@ -90,9 +92,11 @@ OPAL_DECLSPEC int opal_event_finalize(void); /* Basic event APIs */ #define opal_event_enable_debug_mode() event_enable_debug_mode() -#define opal_event_set(b, x, fd, fg, cb, arg) event_assign((x), (b), (fd), (fg), (event_callback_fn) (cb), (arg)) +#define opal_event_set(b, x, fd, fg, cb, arg) \ + event_assign((x), (b), (fd), (fg), (event_callback_fn)(cb), (arg)) -#define opal_event_assign(x, b, fd, fg, cb, arg) event_assign((x), (b), (fd), (fg), (event_callback_fn) (cb), (arg)) +#define opal_event_assign(x, b, fd, fg, cb, arg) \ + event_assign((x), (b), (fd), (fg), (event_callback_fn)(cb), (arg)) #define opal_event_add(ev, tv) event_add((ev), (tv)) @@ -100,9 +104,10 @@ OPAL_DECLSPEC int opal_event_finalize(void); #define opal_event_active(x, y, z) event_active((x), (y), (z)) -#define opal_event_new(b, fd, fg, cb, arg) event_new((b), (fd), (fg), (event_callback_fn) (cb), (arg)) +#define opal_event_new(b, fd, fg, cb, arg) \ + event_new((b), (fd), (fg), (event_callback_fn)(cb), (arg)) -OPAL_DECLSPEC opal_event_t* opal_event_alloc(void); +OPAL_DECLSPEC opal_event_t *opal_event_alloc(void); #define opal_event_free(x) event_free((x)) @@ -111,7 +116,8 @@ OPAL_DECLSPEC opal_event_t* opal_event_alloc(void); #define opal_event_evtimer_add(x, tv) opal_event_add((x), (tv)) -#define opal_event_evtimer_set(b, x, cb, arg) event_assign((x), (b), -1, 0, (event_callback_fn) (cb), (arg)) +#define opal_event_evtimer_set(b, x, cb, arg) \ + event_assign((x), (b), -1, 0, (event_callback_fn)(cb), (arg)) #define opal_event_evtimer_del(x) opal_event_del((x)) @@ -122,7 +128,8 @@ OPAL_DECLSPEC opal_event_t* opal_event_alloc(void); /* Signal APIs */ #define opal_event_signal_add(x, tv) event_add((x), (tv)) -#define opal_event_signal_set(b, x, fd, cb, arg) event_assign((x), (b), (fd), EV_SIGNAL|EV_PERSIST, (event_callback_fn) (cb), (arg)) +#define opal_event_signal_set(b, x, fd, cb, arg) \ + event_assign((x), (b), (fd), EV_SIGNAL | EV_PERSIST, (event_callback_fn)(cb), (arg)) #define opal_event_signal_del(x) event_del((x)) diff --git a/opal/util/fd.c b/opal/util/fd.c index 7891beb8e71..3ab95fa2391 100644 --- a/opal/util/fd.c +++ b/opal/util/fd.c @@ -13,32 +13,31 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_STAT_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #include #include #include #include +#include "opal/constants.h" #include "opal/util/fd.h" #include "opal/util/string_copy.h" -#include "opal/constants.h" - /* * Simple loop over reading from a fd @@ -64,7 +63,6 @@ int opal_fd_read(int fd, int len, void *buffer) return OPAL_SUCCESS; } - /* * Simple loop over writing to an fd */ @@ -88,7 +86,6 @@ int opal_fd_write(int fd, int len, const void *buffer) return OPAL_SUCCESS; } - int opal_fd_set_cloexec(int fd) { #ifdef FD_CLOEXEC @@ -160,7 +157,7 @@ const char *opal_fd_get_peer_name(int fd) if (sa.sa_family == AF_INET) { struct sockaddr_in *si; - si = (struct sockaddr_in*) &sa; + si = (struct sockaddr_in *) &sa; ret = inet_ntop(AF_INET, &(si->sin_addr), str, INET_ADDRSTRLEN); if (NULL == ret) { free(str); @@ -169,7 +166,7 @@ const char *opal_fd_get_peer_name(int fd) #if OPAL_ENABLE_IPV6 else if (sa.sa_family == AF_INET6) { struct sockaddr_in6 *si6; - si6 = (struct sockaddr_in6*) &sa; + si6 = (struct sockaddr_in6 *) &sa; ret = inet_ntop(AF_INET6, &(si6->sin6_addr), str, INET6_ADDRSTRLEN); if (NULL == ret) { free(str); diff --git a/opal/util/few.c b/opal/util/few.c index 45e827e8f50..94e14167f17 100644 --- a/opal/util/few.c +++ b/opal/util/few.c @@ -16,23 +16,22 @@ * $HEADER$ */ - #include "opal_config.h" -#include #include +#include #ifdef HAVE_SYS_WAIT_H -#include +# include #endif #include #ifdef HAVE_UNISTD_H -#include +# include #endif -#include "opal/util/few.h" -#include "opal/util/basename.h" -#include "opal/util/argv.h" #include "opal/constants.h" +#include "opal/util/argv.h" +#include "opal/util/basename.h" +#include "opal/util/few.h" int opal_few(char *argv[], int *status) { @@ -40,38 +39,38 @@ int opal_few(char *argv[], int *status) pid_t pid, ret; if ((pid = fork()) < 0) { - return OPAL_ERR_IN_ERRNO; + return OPAL_ERR_IN_ERRNO; } /* Child execs. If it fails to exec, exit. */ else if (0 == pid) { - execvp(argv[0], argv); - exit(errno); + execvp(argv[0], argv); + exit(errno); } /* Parent loops waiting for the child to die. */ else { - do { - /* If the child exited, return */ + do { + /* If the child exited, return */ - if (pid == (ret = waitpid(pid, status, 0))) { - break; - } + if (pid == (ret = waitpid(pid, status, 0))) { + break; + } - /* If waitpid was interrupted, loop around again */ + /* If waitpid was interrupted, loop around again */ - else if (ret < 0) { - if (EINTR == errno) { - continue; - } + else if (ret < 0) { + if (EINTR == errno) { + continue; + } - /* Otherwise, some bad juju happened -- need to quit */ + /* Otherwise, some bad juju happened -- need to quit */ - return OPAL_ERR_IN_ERRNO; - } - } while (true); + return OPAL_ERR_IN_ERRNO; + } + } while (true); } /* Return the status to the caller */ diff --git a/opal/util/if.c b/opal/util/if.c index bd73e987690..621d2e1e7ee 100644 --- a/opal/util/if.c +++ b/opal/util/if.c @@ -29,65 +29,65 @@ #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_SOCKIO_H -#include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_NET_IF_H -#include +# include #endif #ifdef HAVE_NETDB_H -#include +# include #endif #ifdef HAVE_IFADDRS_H -#include +# include #endif #include #include "opal/class/opal_list.h" +#include "opal/constants.h" +#include "opal/util/argv.h" #include "opal/util/if.h" #include "opal/util/net.h" #include "opal/util/output.h" -#include "opal/util/argv.h" #include "opal/util/show_help.h" #include "opal/util/string_copy.h" -#include "opal/constants.h" #include "opal/mca/if/base/base.h" #ifdef HAVE_STRUCT_SOCKADDR_IN -#ifndef MIN -# define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif +# ifndef MIN +# define MIN(a, b) ((a) < (b) ? (a) : (b)) +# endif /* * Look for interface by name and returns its address * as a dotted decimal formatted string. */ -int opal_ifnametoaddr(const char* if_name, struct sockaddr* addr, int length) +int opal_ifnametoaddr(const char *if_name, struct sockaddr *addr, int length) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (strcmp(intf->if_name, if_name) == 0) { memcpy(addr, &intf->if_addr, length); return OPAL_SUCCESS; @@ -96,17 +96,16 @@ int opal_ifnametoaddr(const char* if_name, struct sockaddr* addr, int length) return OPAL_ERROR; } - /* * Look for interface by name and returns its * corresponding opal_list index. */ -int opal_ifnametoindex(const char* if_name) +int opal_ifnametoindex(const char *if_name) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (strcmp(intf->if_name, if_name) == 0) { return intf->if_index; } @@ -114,17 +113,16 @@ int opal_ifnametoindex(const char* if_name) return -1; } - /* * Look for interface by name and returns its * corresponding kernel index. */ -int opal_ifnametokindex(const char* if_name) +int opal_ifnametokindex(const char *if_name) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (strcmp(intf->if_name, if_name) == 0) { return intf->if_kernel_index; } @@ -132,7 +130,6 @@ int opal_ifnametokindex(const char* if_name) return -1; } - /* * Look for interface by opal_list index and returns its * corresponding kernel index. @@ -140,9 +137,9 @@ int opal_ifnametokindex(const char* if_name) int opal_ifindextokindex(int if_index) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (if_index == intf->if_index) { return intf->if_kernel_index; } @@ -150,15 +147,14 @@ int opal_ifindextokindex(int if_index) return -1; } - /* * Attempt to resolve the adddress (given as either IPv4/IPv6 string * or hostname) and lookup corresponding interface. */ -int opal_ifaddrtoname(const char* if_addr, char* if_name, int length) +int opal_ifaddrtoname(const char *if_addr, char *if_name, int length) { - opal_if_t* intf; + opal_if_t *intf; int error; struct addrinfo hints, *res = NULL, *r; @@ -177,40 +173,40 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length) if (error) { if (NULL != res) { - freeaddrinfo (res); + freeaddrinfo(res); } return OPAL_ERR_NOT_FOUND; } for (r = res; r != NULL; r = r->ai_next) { - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (AF_INET == r->ai_family) { struct sockaddr_in ipv4; struct sockaddr_in *inaddr; - inaddr = (struct sockaddr_in*) &intf->if_addr; - memcpy (&ipv4, r->ai_addr, r->ai_addrlen); + inaddr = (struct sockaddr_in *) &intf->if_addr; + memcpy(&ipv4, r->ai_addr, r->ai_addrlen); if (inaddr->sin_addr.s_addr == ipv4.sin_addr.s_addr) { opal_string_copy(if_name, intf->if_name, length); - freeaddrinfo (res); + freeaddrinfo(res); return OPAL_SUCCESS; } } -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 else { - if (IN6_ARE_ADDR_EQUAL(&((struct sockaddr_in6*) &intf->if_addr)->sin6_addr, - &((struct sockaddr_in6*) r->ai_addr)->sin6_addr)) { + if (IN6_ARE_ADDR_EQUAL(&((struct sockaddr_in6 *) &intf->if_addr)->sin6_addr, + &((struct sockaddr_in6 *) r->ai_addr)->sin6_addr)) { opal_string_copy(if_name, intf->if_name, length); - freeaddrinfo (res); + freeaddrinfo(res); return OPAL_SUCCESS; } } -#endif +# endif } } if (NULL != res) { - freeaddrinfo (res); + freeaddrinfo(res); } /* if we get here, it wasn't found */ @@ -222,9 +218,9 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length) * or hostname) and return the kernel index of the interface * on the same network as the specified address */ -int opal_ifaddrtokindex(const char* if_addr) +int opal_ifaddrtokindex(const char *if_addr) { - opal_if_t* intf; + opal_if_t *intf; int error; struct addrinfo hints, *res = NULL, *r; int if_kernel_index; @@ -237,40 +233,44 @@ int opal_ifaddrtokindex(const char* if_addr) if (error) { if (NULL != res) { - freeaddrinfo (res); + freeaddrinfo(res); } return OPAL_ERR_NOT_FOUND; } for (r = res; r != NULL; r = r->ai_next) { - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (AF_INET == r->ai_family && AF_INET == intf->af_family) { struct sockaddr_in ipv4; - len = (r->ai_addrlen < sizeof(struct sockaddr_in)) ? r->ai_addrlen : sizeof(struct sockaddr_in); + len = (r->ai_addrlen < sizeof(struct sockaddr_in)) ? r->ai_addrlen + : sizeof(struct sockaddr_in); memcpy(&ipv4, r->ai_addr, len); - if (opal_net_samenetwork((struct sockaddr*)&ipv4, (struct sockaddr*)&intf->if_addr, intf->if_mask)) { + if (opal_net_samenetwork((struct sockaddr *) &ipv4, + (struct sockaddr *) &intf->if_addr, intf->if_mask)) { if_kernel_index = intf->if_kernel_index; - freeaddrinfo (res); + freeaddrinfo(res); return if_kernel_index; } } -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 else if (AF_INET6 == r->ai_family && AF_INET6 == intf->af_family) { struct sockaddr_in6 ipv6; - len = (r->ai_addrlen < sizeof(struct sockaddr_in6)) ? r->ai_addrlen : sizeof(struct sockaddr_in6); + len = (r->ai_addrlen < sizeof(struct sockaddr_in6)) ? r->ai_addrlen + : sizeof(struct sockaddr_in6); memcpy(&ipv6, r->ai_addr, len); - if (opal_net_samenetwork((struct sockaddr*)((struct sockaddr_in6*)&intf->if_addr), - (struct sockaddr*)&ipv6, intf->if_mask)) { + if (opal_net_samenetwork((struct sockaddr *) ((struct sockaddr_in6 *) &intf + ->if_addr), + (struct sockaddr *) &ipv6, intf->if_mask)) { if_kernel_index = intf->if_kernel_index; - freeaddrinfo (res); + freeaddrinfo(res); return if_kernel_index; } } -#endif +# endif } } if (NULL != res) { - freeaddrinfo (res); + freeaddrinfo(res); } return OPAL_ERR_NOT_FOUND; } @@ -284,7 +284,6 @@ int opal_ifcount(void) return opal_list_get_size(&opal_if_list); } - /* * Return the opal_list interface index for the first * interface in our list. @@ -294,13 +293,13 @@ int opal_ifbegin(void) { opal_if_t *intf; - intf = (opal_if_t*)opal_list_get_first(&opal_if_list); - if (NULL != intf) + intf = (opal_if_t *) opal_list_get_first(&opal_if_list); + if (NULL != intf) { return intf->if_index; + } return (-1); } - /* * Located the current position in the list by if_index and * return the interface index of the next element in our list @@ -311,70 +310,67 @@ int opal_ifnext(int if_index) { opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { do { - opal_if_t* if_next = (opal_if_t*)opal_list_get_next(intf); - opal_if_t* if_end = (opal_if_t*)opal_list_get_end(&opal_if_list); + opal_if_t *if_next = (opal_if_t *) opal_list_get_next(intf); + opal_if_t *if_end = (opal_if_t *) opal_list_get_end(&opal_if_list); if (if_next == if_end) { return -1; } intf = if_next; - } while(intf->if_index == if_index); + } while (intf->if_index == if_index); return intf->if_index; } } return (-1); } - /* * Lookup the interface by opal_list index and return the * primary address assigned to the interface. */ -int opal_ifindextoaddr(int if_index, struct sockaddr* if_addr, unsigned int length) +int opal_ifindextoaddr(int if_index, struct sockaddr *if_addr, unsigned int length) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { - memcpy(if_addr, &intf->if_addr, MIN(length, sizeof (intf->if_addr))); + memcpy(if_addr, &intf->if_addr, MIN(length, sizeof(intf->if_addr))); return OPAL_SUCCESS; } } return OPAL_ERROR; } - /* * Lookup the interface by opal_list kindex and return the * primary address assigned to the interface. */ -int opal_ifkindextoaddr(int if_kindex, struct sockaddr* if_addr, unsigned int length) +int opal_ifkindextoaddr(int if_kindex, struct sockaddr *if_addr, unsigned int length) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_kernel_index == if_kindex) { - memcpy(if_addr, &intf->if_addr, MIN(length, sizeof (intf->if_addr))); + memcpy(if_addr, &intf->if_addr, MIN(length, sizeof(intf->if_addr))); return OPAL_SUCCESS; } } return OPAL_ERROR; } - /* * Lookup the interface by opal_list index and return the * network mask assigned to the interface. */ -int opal_ifindextomask(int if_index, uint32_t* if_mask, int length) +int opal_ifindextomask(int if_index, uint32_t *if_mask, int length) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { memcpy(if_mask, &intf->if_mask, length); return OPAL_SUCCESS; @@ -390,9 +386,9 @@ int opal_ifindextomask(int if_index, uint32_t* if_mask, int length) int opal_ifindextomac(int if_index, uint8_t mac[6]) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { memcpy(mac, &intf->if_mac, 6); return OPAL_SUCCESS; @@ -408,9 +404,9 @@ int opal_ifindextomac(int if_index, uint8_t mac[6]) int opal_ifindextomtu(int if_index, int *mtu) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { *mtu = intf->ifmtu; return OPAL_SUCCESS; @@ -424,11 +420,11 @@ int opal_ifindextomtu(int if_index, int *mtu) * flags assigned to the interface. */ -int opal_ifindextoflags(int if_index, uint32_t* if_flags) +int opal_ifindextoflags(int if_index, uint32_t *if_flags) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { memcpy(if_flags, &intf->if_flags, sizeof(uint32_t)); return OPAL_SUCCESS; @@ -437,18 +433,16 @@ int opal_ifindextoflags(int if_index, uint32_t* if_flags) return OPAL_ERROR; } - - /* * Lookup the interface by opal_list index and return * the associated name. */ -int opal_ifindextoname(int if_index, char* if_name, int length) +int opal_ifindextoname(int if_index, char *if_name, int length) { opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { opal_string_copy(if_name, intf->if_name, length); return OPAL_SUCCESS; @@ -457,17 +451,16 @@ int opal_ifindextoname(int if_index, char* if_name, int length) return OPAL_ERROR; } - /* * Lookup the interface by kernel index and return * the associated name. */ -int opal_ifkindextoname(int if_kindex, char* if_name, int length) +int opal_ifkindextoname(int if_kindex, char *if_name, int length) { opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_kernel_index == if_kindex) { opal_string_copy(if_name, intf->if_name, length); return OPAL_SUCCESS; @@ -476,17 +469,15 @@ int opal_ifkindextoname(int if_kindex, char* if_name, int length) return OPAL_ERROR; } - -#define ADDRLEN 100 -bool -opal_ifislocal(const char *hostname) +# define ADDRLEN 100 +bool opal_ifislocal(const char *hostname) { -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 char addrname[NI_MAXHOST]; /* should be larger than ADDRLEN, but I think they really mean IFNAMESIZE */ -#else +# else char addrname[ADDRLEN + 1]; -#endif +# endif if (OPAL_SUCCESS == opal_ifaddrtoname(hostname, addrname, ADDRLEN)) { return true; @@ -495,16 +486,16 @@ opal_ifislocal(const char *hostname) return false; } -static int parse_ipv4_dots(const char *addr, uint32_t* net, int* dots) +static int parse_ipv4_dots(const char *addr, uint32_t *net, int *dots) { const char *start = addr, *end; - uint32_t n[]={0,0,0,0}; + uint32_t n[] = {0, 0, 0, 0}; int i; /* now assemble the address */ - for( i = 0; i < 4; i++ ) { - n[i] = strtoul(start, (char**)&end, 10); - if( end == start ) { + for (i = 0; i < 4; i++) { + n[i] = strtoul(start, (char **) &end, 10); + if (end == start) { /* this is not an error, but indicates that * we were given a partial address - e.g., * 192.168 - usually indicating an IP range @@ -513,20 +504,22 @@ static int parse_ipv4_dots(const char *addr, uint32_t* net, int* dots) break; } /* did we read something sensible? */ - if( n[i] > 255 ) { + if (n[i] > 255) { return OPAL_ERR_NETWORK_NOT_PARSEABLE; } /* skip all the . */ - for( start = end; '\0' != *start; start++ ) - if( '.' != *start ) break; + for (start = end; '\0' != *start; start++) { + if ('.' != *start) { + break; + } + } } *dots = i; *net = OPAL_IF_ASSEMBLE_NETWORK(n[0], n[1], n[2], n[3]); return OPAL_SUCCESS; } -int -opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) +int opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) { int pval, dots, rc = OPAL_SUCCESS; const char *ptr; @@ -538,7 +531,7 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) /* if entry includes mask, split that off */ if (NULL != (ptr = strchr(inaddr, '/'))) { - ptr = ptr + 1; /* skip the / */ + ptr = ptr + 1; /* skip the / */ /* is the mask a tuple? */ if (NULL != strchr(ptr, '.')) { /* yes - extract mask from it */ @@ -556,7 +549,7 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) } } else { /* use the number of dots to determine it */ - for (ptr = inaddr, pval = 0; '\0'!= *ptr; ptr++) { + for (ptr = inaddr, pval = 0; '\0' != *ptr; ptr++) { if ('.' == *ptr) { pval++; } @@ -567,11 +560,11 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) */ if (3 == pval) { *mask = 0xFFFFFFFF; - } else if (2 == pval) { /* 2 dots */ + } else if (2 == pval) { /* 2 dots */ *mask = 0xFFFFFF00; - } else if (1 == pval) { /* 1 dot */ + } else if (1 == pval) { /* 1 dot */ *mask = 0xFFFF0000; - } else if (0 == pval) { /* no dots */ + } else if (0 == pval) { /* no dots */ *mask = 0xFF000000; } else { opal_output(0, "opal_iftupletoaddr: unknown mask"); @@ -595,9 +588,9 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) bool opal_ifisloopback(int if_index) { - opal_if_t* intf; + opal_if_t *intf; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { if (intf->if_index == if_index) { if ((intf->if_flags & IFF_LOOPBACK) != 0) { return true; @@ -621,17 +614,18 @@ int opal_ifmatches(int kidx, char **nets) uint32_t addr, netaddr, netmask; /* get the address info for the given network in case we need it */ - if (OPAL_SUCCESS != (rc = opal_ifkindextoaddr(kidx, (struct sockaddr*)&inaddr, sizeof(inaddr)))) { + if (OPAL_SUCCESS + != (rc = opal_ifkindextoaddr(kidx, (struct sockaddr *) &inaddr, sizeof(inaddr)))) { return rc; } addr = ntohl(inaddr.sin_addr.s_addr); - for (i=0; NULL != nets[i]; i++) { + for (i = 0; NULL != nets[i]; i++) { /* if the specified interface contains letters in it, then it * was given as an interface name and not an IP tuple */ named_if = false; - for (j=0; j < strlen(nets[i]); j++) { + for (j = 0; j < strlen(nets[i]); j++) { if (isalpha(nets[i][j]) && '.' != nets[i][j]) { named_if = true; break; @@ -660,19 +654,19 @@ int opal_ifmatches(int kidx, char **nets) void opal_ifgetaliases(char ***aliases) { - opal_if_t* intf; + opal_if_t *intf; char ipv4[INET_ADDRSTRLEN]; struct sockaddr_in *addr; -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 char ipv6[INET6_ADDRSTRLEN]; struct sockaddr_in6 *addr6; -#endif +# endif /* set default answer */ *aliases = NULL; - OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { - addr = (struct sockaddr_in*) &intf->if_addr; + OPAL_LIST_FOREACH (intf, &opal_if_list, opal_if_t) { + addr = (struct sockaddr_in *) &intf->if_addr; /* ignore purely loopback interfaces */ if ((intf->if_flags & IFF_LOOPBACK) != 0) { continue; @@ -681,13 +675,13 @@ void opal_ifgetaliases(char ***aliases) inet_ntop(AF_INET, &(addr->sin_addr.s_addr), ipv4, INET_ADDRSTRLEN); opal_argv_append_nosize(aliases, ipv4); } -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 else { - addr6 = (struct sockaddr_in6*) &intf->if_addr; + addr6 = (struct sockaddr_in6 *) &intf->if_addr; inet_ntop(AF_INET6, &(addr6->sin6_addr), ipv6, INET6_ADDRSTRLEN); opal_argv_append_nosize(aliases, ipv6); } -#endif +# endif } } @@ -696,88 +690,72 @@ void opal_ifgetaliases(char ***aliases) /* if we don't have struct sockaddr_in, we don't have traditional ethernet devices. Just make everything a no-op error call */ -int -opal_ifnametoaddr(const char* if_name, - struct sockaddr* if_addr, int size) +int opal_ifnametoaddr(const char *if_name, struct sockaddr *if_addr, int size) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifaddrtoname(const char* if_addr, - char* if_name, int size) +int opal_ifaddrtoname(const char *if_addr, char *if_name, int size) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifnametoindex(const char* if_name) +int opal_ifnametoindex(const char *if_name) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifnametokindex(const char* if_name) +int opal_ifnametokindex(const char *if_name) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifindextokindex(int if_index) +int opal_ifindextokindex(int if_index) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifcount(void) +int opal_ifcount(void) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifbegin(void) +int opal_ifbegin(void) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifnext(int if_index) +int opal_ifnext(int if_index) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifindextoname(int if_index, char* if_name, int length) +int opal_ifindextoname(int if_index, char *if_name, int length) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifkindextoname(int kif_index, char* if_name, int length) +int opal_ifkindextoname(int kif_index, char *if_name, int length) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifindextoaddr(int if_index, struct sockaddr* if_addr, unsigned int length) +int opal_ifindextoaddr(int if_index, struct sockaddr *if_addr, unsigned int length) { return OPAL_ERR_NOT_SUPPORTED; } -int -opal_ifindextomask(int if_index, uint32_t* if_addr, int length) +int opal_ifindextomask(int if_index, uint32_t *if_addr, int length) { return OPAL_ERR_NOT_SUPPORTED; } -bool -opal_ifislocal(const char *hostname) +bool opal_ifislocal(const char *hostname) { return false; } -int -opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) +int opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) { return 0; } @@ -794,4 +772,3 @@ void opal_ifgetaliases(char ***aliases) } #endif /* HAVE_STRUCT_SOCKADDR_IN */ - diff --git a/opal/util/if.h b/opal/util/if.h index 5165abd2e6d..2fc83ecf77a 100644 --- a/opal/util/if.h +++ b/opal/util/if.h @@ -28,13 +28,13 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif /* @@ -49,15 +49,13 @@ BEGIN_C_DECLS -#define OPAL_IF_FORMAT_ADDR(n) \ - (((n) >> 24) & 0x000000FF), (((n) >> 16) & 0x000000FF), \ - (((n) >> 8) & 0x000000FF), ((n) & 0x000000FF) +#define OPAL_IF_FORMAT_ADDR(n) \ + (((n) >> 24) & 0x000000FF), (((n) >> 16) & 0x000000FF), (((n) >> 8) & 0x000000FF), \ + ((n) &0x000000FF) -#define OPAL_IF_ASSEMBLE_NETWORK(n1, n2, n3, n4) \ - (((n1) << 24) & 0xFF000000) | \ - (((n2) << 16) & 0x00FF0000) | \ - (((n3) << 8) & 0x0000FF00) | \ - ( (n4) & 0x000000FF) +#define OPAL_IF_ASSEMBLE_NETWORK(n1, n2, n3, n4) \ + (((n1) << 24) & 0xFF000000) | (((n2) << 16) & 0x00FF0000) | (((n3) << 8) & 0x0000FF00) \ + | ((n4) &0x000000FF) /** * Lookup an interface by name and return its primary address. @@ -66,9 +64,7 @@ BEGIN_C_DECLS * @param if_addr (OUT) Interface address buffer * @param size (IN) Interface address buffer size */ -OPAL_DECLSPEC int opal_ifnametoaddr(const char* if_name, - struct sockaddr* if_addr, - int size); +OPAL_DECLSPEC int opal_ifnametoaddr(const char *if_name, struct sockaddr *if_addr, int size); /** * Lookup an interface by address and return its name. @@ -77,8 +73,7 @@ OPAL_DECLSPEC int opal_ifnametoaddr(const char* if_name, * @param if_name (OUT) Interface name buffer * @param size (IN) Interface name buffer size */ -OPAL_DECLSPEC int opal_ifaddrtoname(const char* if_addr, - char* if_name, int size); +OPAL_DECLSPEC int opal_ifaddrtoname(const char *if_addr, char *if_name, int size); /** * Lookup an interface by name and return its opal_list index. @@ -86,7 +81,7 @@ OPAL_DECLSPEC int opal_ifaddrtoname(const char* if_addr, * @param if_name (IN) Interface name * @return Interface opal_list index */ -OPAL_DECLSPEC int opal_ifnametoindex(const char* if_name); +OPAL_DECLSPEC int opal_ifnametoindex(const char *if_name); /** * Lookup an interface by name and return its kernel index. @@ -94,14 +89,14 @@ OPAL_DECLSPEC int opal_ifnametoindex(const char* if_name); * @param if_name (IN) Interface name * @return Interface kernel index */ -OPAL_DECLSPEC int opal_ifnametokindex(const char* if_name); +OPAL_DECLSPEC int opal_ifnametokindex(const char *if_name); /* * Attempt to resolve an address (given as either IPv4/IPv6 string * or hostname) and return the kernel index of the interface * that is on the same network as the specified address */ -OPAL_DECLSPEC int opal_ifaddrtokindex(const char* if_addr); +OPAL_DECLSPEC int opal_ifaddrtokindex(const char *if_addr); /** * Lookup an interface by opal_list index and return its kernel index. @@ -137,7 +132,7 @@ OPAL_DECLSPEC int opal_ifnext(int if_index); * @param if_name (OUT) Interface name buffer * @param size (IN) Interface name buffer size */ -OPAL_DECLSPEC int opal_ifindextoname(int if_index, char* if_name, int); +OPAL_DECLSPEC int opal_ifindextoname(int if_index, char *if_name, int); /** * Lookup an interface by kernel index and return its name. @@ -146,7 +141,7 @@ OPAL_DECLSPEC int opal_ifindextoname(int if_index, char* if_name, int); * @param if_name (OUT) Interface name buffer * @param size (IN) Interface name buffer size */ -OPAL_DECLSPEC int opal_ifkindextoname(int if_kindex, char* if_name, int); +OPAL_DECLSPEC int opal_ifkindextoname(int if_kindex, char *if_name, int); /** * Lookup an interface by index and return its primary address. @@ -155,11 +150,8 @@ OPAL_DECLSPEC int opal_ifkindextoname(int if_kindex, char* if_name, int); * @param if_name (OUT) Interface address buffer * @param size (IN) Interface address buffer size */ -OPAL_DECLSPEC int opal_ifindextoaddr(int if_index, struct sockaddr*, - unsigned int); -OPAL_DECLSPEC int opal_ifkindextoaddr(int if_kindex, - struct sockaddr* if_addr, - unsigned int length); +OPAL_DECLSPEC int opal_ifindextoaddr(int if_index, struct sockaddr *, unsigned int); +OPAL_DECLSPEC int opal_ifkindextoaddr(int if_kindex, struct sockaddr *if_addr, unsigned int length); /** * Lookup an interface by index and return its network mask (in CIDR @@ -169,7 +161,7 @@ OPAL_DECLSPEC int opal_ifkindextoaddr(int if_kindex, * @param if_name (OUT) Interface address buffer * @param size (IN) Interface address buffer size */ -OPAL_DECLSPEC int opal_ifindextomask(int if_index, uint32_t*, int); +OPAL_DECLSPEC int opal_ifindextomask(int if_index, uint32_t *, int); /** * Lookup an interface by index and return its MAC address. @@ -193,7 +185,7 @@ OPAL_DECLSPEC int opal_ifindextomtu(int if_index, int *mtu); * @param if_index (IN) Interface index * @param if_flags (OUT) Interface flags */ -OPAL_DECLSPEC int opal_ifindextoflags(int if_index, uint32_t*); +OPAL_DECLSPEC int opal_ifindextoflags(int if_index, uint32_t *); /** * Determine if given hostname / IP address is a local address @@ -234,4 +226,3 @@ OPAL_DECLSPEC void opal_ifgetaliases(char ***aliases); END_C_DECLS #endif - diff --git a/opal/util/info.c b/opal/util/info.c index cf2379c8b32..94955a51093 100644 --- a/opal/util/info.c +++ b/opal/util/info.c @@ -25,24 +25,24 @@ * $HEADER$ */ -#include #include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif -#include #include +#include #ifdef HAVE_SYS_UTSNAME_H -#include +# include #endif #include #include "opal/util/argv.h" +#include "opal/util/info.h" #include "opal/util/opal_getcwd.h" #include "opal/util/output.h" #include "opal/util/string_copy.h" -#include "opal/util/info.h" /* * Local functions @@ -51,60 +51,52 @@ static void info_constructor(opal_info_t *info); static void info_destructor(opal_info_t *info); static void info_entry_constructor(opal_info_entry_t *entry); static void info_entry_destructor(opal_info_entry_t *entry); -static opal_info_entry_t *info_find_key (opal_info_t *info, const char *key); - +static opal_info_entry_t *info_find_key(opal_info_t *info, const char *key); /* * opal_info_t classes */ -OBJ_CLASS_INSTANCE(opal_info_t, - opal_list_t, - info_constructor, - info_destructor); +OBJ_CLASS_INSTANCE(opal_info_t, opal_list_t, info_constructor, info_destructor); /* * opal_info_entry_t classes */ -OBJ_CLASS_INSTANCE(opal_info_entry_t, - opal_list_item_t, - info_entry_constructor, +OBJ_CLASS_INSTANCE(opal_info_entry_t, opal_list_item_t, info_entry_constructor, info_entry_destructor); - - /* * Duplicate an info */ -int opal_info_dup (opal_info_t *info, opal_info_t **newinfo) +int opal_info_dup(opal_info_t *info, opal_info_t **newinfo) { opal_info_entry_t *iterator; OPAL_THREAD_LOCK(info->i_lock); - OPAL_LIST_FOREACH(iterator, &info->super, opal_info_entry_t) { + OPAL_LIST_FOREACH (iterator, &info->super, opal_info_entry_t) { /* create a new info entry and retain the string objects */ opal_info_entry_t *newentry = OBJ_NEW(opal_info_entry_t); newentry->ie_key = iterator->ie_key; OBJ_RETAIN(iterator->ie_key); newentry->ie_value = iterator->ie_value; OBJ_RETAIN(iterator->ie_value); - } + } OPAL_THREAD_UNLOCK(info->i_lock); return OPAL_SUCCESS; } -static void opal_info_get_nolock (opal_info_t *info, const char *key, - opal_cstring_t **value, int *flag) +static void opal_info_get_nolock(opal_info_t *info, const char *key, opal_cstring_t **value, + int *flag) { opal_info_entry_t *search; - search = info_find_key (info, key); - if (NULL == search){ + search = info_find_key(info, key); + if (NULL == search) { *flag = 0; } else { /* - * We have found the element, so we can return the value - * Set the flag and value - */ + * We have found the element, so we can return the value + * Set the flag and value + */ *flag = 1; if (NULL != value) { OBJ_RETAIN(search->ie_value); @@ -113,11 +105,11 @@ static void opal_info_get_nolock (opal_info_t *info, const char *key, } } -static int opal_info_set_cstring_nolock (opal_info_t *info, const char *key, opal_cstring_t *value) +static int opal_info_set_cstring_nolock(opal_info_t *info, const char *key, opal_cstring_t *value) { opal_info_entry_t *old_info; - old_info = info_find_key (info, key); + old_info = info_find_key(info, key); if (NULL != old_info) { /* * key already exists. remove the value associated with it @@ -135,17 +127,16 @@ static int opal_info_set_cstring_nolock (opal_info_t *info, const char *key, opa new_info->ie_key = key_str; OBJ_RETAIN(value); new_info->ie_value = value; - opal_list_append (&(info->super), (opal_list_item_t *) new_info); + opal_list_append(&(info->super), (opal_list_item_t *) new_info); } return OPAL_SUCCESS; } - -static int opal_info_set_nolock (opal_info_t *info, const char *key, const char *value) +static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *value) { opal_info_entry_t *old_info; - old_info = info_find_key (info, key); + old_info = info_find_key(info, key); if (NULL != old_info) { /* * key already exists, check whether it is the same @@ -174,7 +165,7 @@ static int opal_info_set_nolock (opal_info_t *info, const char *key, const char OBJ_RELEASE(new_info); return OPAL_ERR_OUT_OF_RESOURCE; } - opal_list_append (&(info->super), (opal_list_item_t *) new_info); + opal_list_append(&(info->super), (opal_list_item_t *) new_info); } return OPAL_SUCCESS; } @@ -189,11 +180,10 @@ static int opal_info_set_nolock (opal_info_t *info, const char *key, const char * omit_ignored (default 1) * show_modifications (default 0) */ -static -int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, - int include_system_extras, // (k/v with no corresponding __IN_k) - int omit_ignored, // (__IN_k with no k/v) - int show_modifications) // (pick v from k/v or __IN_k/v) +static int opal_info_dup_mode(opal_info_t *info, opal_info_t **newinfo, + int include_system_extras, // (k/v with no corresponding __IN_k) + int omit_ignored, // (__IN_k with no k/v) + int show_modifications) // (pick v from k/v or __IN_k/v) { int err, flag; opal_info_entry_t *iterator; @@ -203,7 +193,7 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, int exists_IN_key, exists_reg_key; OPAL_THREAD_LOCK(info->i_lock); - OPAL_LIST_FOREACH(iterator, &info->super, opal_info_entry_t) { + OPAL_LIST_FOREACH (iterator, &info->super, opal_info_entry_t) { // If we see an __IN_ key but no , decide what to do based on mode. // If we see an __IN_ and a , skip since it'll be handled when // we process . @@ -213,14 +203,14 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, pkey = iterator->ie_key->string; opal_cstring_t *savedval = NULL; opal_cstring_t *valstr = NULL; - if (0 == strncmp(iterator->ie_key->string, OPAL_INFO_SAVE_PREFIX, - strlen(OPAL_INFO_SAVE_PREFIX))) - { + if (0 + == strncmp(iterator->ie_key->string, OPAL_INFO_SAVE_PREFIX, + strlen(OPAL_INFO_SAVE_PREFIX))) { pkey += strlen(OPAL_INFO_SAVE_PREFIX); is_IN_key = 1; exists_IN_key = 1; - opal_info_get_nolock (info, pkey, NULL, &flag); + opal_info_get_nolock(info, pkey, NULL, &flag); if (flag) { exists_reg_key = 1; } @@ -231,9 +221,10 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, // see if there is an __IN_ for the current if (strlen(OPAL_INFO_SAVE_PREFIX) + strlen(pkey) < OPAL_MAX_INFO_KEY) { char savedkey[OPAL_MAX_INFO_KEY + 1]; // iterator->ie_key has this as its size - snprintf(savedkey, OPAL_MAX_INFO_KEY+1, OPAL_INFO_SAVE_PREFIX "%s", pkey); - // (the prefix macro is a string, so the unreadable part above is a string concatenation) - opal_info_get_nolock (info, savedkey, &savedval, &flag); + snprintf(savedkey, OPAL_MAX_INFO_KEY + 1, OPAL_INFO_SAVE_PREFIX "%s", pkey); + // (the prefix macro is a string, so the unreadable part above is a string + // concatenation) + opal_info_get_nolock(info, savedkey, &savedval, &flag); // release savedval, it remains valid as long we're holding the lock OBJ_RELEASE(savedval); exists_IN_key = 1; @@ -292,15 +283,15 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, * Implement opal_info_dup_mpistandard by using whatever mode * settings represent our interpretation of the standard */ -int opal_info_dup_mpistandard (opal_info_t *info, opal_info_t **newinfo) +int opal_info_dup_mpistandard(opal_info_t *info, opal_info_t **newinfo) { - return opal_info_dup_mode (info, newinfo, 1, 1, 0); + return opal_info_dup_mode(info, newinfo, 1, 1, 0); } /* * Set a value on the info */ -int opal_info_set (opal_info_t *info, const char *key, const char *value) +int opal_info_set(opal_info_t *info, const char *key, const char *value) { int ret; @@ -310,7 +301,7 @@ int opal_info_set (opal_info_t *info, const char *key, const char *value) return ret; } -int opal_info_set_cstring (opal_info_t *info, const char *key, opal_cstring_t *value) +int opal_info_set_cstring(opal_info_t *info, const char *key, opal_cstring_t *value) { int ret; @@ -320,27 +311,24 @@ int opal_info_set_cstring (opal_info_t *info, const char *key, opal_cstring_t *v return ret; } - -int opal_info_set_value_enum (opal_info_t *info, const char *key, int value, - mca_base_var_enum_t *var_enum) +int opal_info_set_value_enum(opal_info_t *info, const char *key, int value, + mca_base_var_enum_t *var_enum) { char *string_value; int ret; - ret = var_enum->string_from_value (var_enum, value, &string_value); + ret = var_enum->string_from_value(var_enum, value, &string_value); if (OPAL_SUCCESS != ret) { return ret; } - return opal_info_set (info, key, string_value); + return opal_info_set(info, key, string_value); } - /* * Get a value from an info */ -int opal_info_get (opal_info_t *info, const char *key, - opal_cstring_t **value, int *flag) +int opal_info_get(opal_info_t *info, const char *key, opal_cstring_t **value, int *flag) { OPAL_THREAD_LOCK(info->i_lock); opal_info_get_nolock(info, key, value, flag); @@ -348,9 +336,8 @@ int opal_info_get (opal_info_t *info, const char *key, return OPAL_SUCCESS; } -int opal_info_get_value_enum (opal_info_t *info, const char *key, int *value, - int default_value, mca_base_var_enum_t *var_enum, - int *flag) +int opal_info_get_value_enum(opal_info_t *info, const char *key, int *value, int default_value, + mca_base_var_enum_t *var_enum, int *flag) { int ret; opal_cstring_t *str; @@ -360,14 +347,13 @@ int opal_info_get_value_enum (opal_info_t *info, const char *key, int *value, ret = opal_info_get(info, key, &str, flag); if (*flag) { - ret = var_enum->value_from_string (var_enum, str->string, value); + ret = var_enum->value_from_string(var_enum, str->string, value); OBJ_RELEASE(str); } return ret; } - /* * Similar to opal_info_get(), but cast the result into a boolean * using some well-defined rules. @@ -394,54 +380,50 @@ int opal_info_delete(opal_info_t *info, const char *key) opal_info_entry_t *search; OPAL_THREAD_LOCK(info->i_lock); - search = info_find_key (info, key); - if (NULL == search){ - OPAL_THREAD_UNLOCK(info->i_lock); - return OPAL_ERR_NOT_FOUND; + search = info_find_key(info, key); + if (NULL == search) { + OPAL_THREAD_UNLOCK(info->i_lock); + return OPAL_ERR_NOT_FOUND; } else { - /* - * An entry with this key value was found. Remove the item - * and free the memory allocated to it. - * As this key *must* be available, we do not check for errors. - */ - opal_list_remove_item (&(info->super), - (opal_list_item_t *)search); - OBJ_RELEASE(search); + /* + * An entry with this key value was found. Remove the item + * and free the memory allocated to it. + * As this key *must* be available, we do not check for errors. + */ + opal_list_remove_item(&(info->super), (opal_list_item_t *) search); + OBJ_RELEASE(search); } OPAL_THREAD_UNLOCK(info->i_lock); return OPAL_SUCCESS; } - /* * Return the length of a value */ -int opal_info_get_valuelen (opal_info_t *info, const char *key, int *valuelen, - int *flag) +int opal_info_get_valuelen(opal_info_t *info, const char *key, int *valuelen, int *flag) { opal_info_entry_t *search; OPAL_THREAD_LOCK(info->i_lock); - search = info_find_key (info, key); - if (NULL == search){ + search = info_find_key(info, key); + if (NULL == search) { *flag = 0; } else { /* * We have found the element, so we can return the value * Set the flag, value_length and value */ - *flag = 1; - *valuelen = search->ie_value->length; + *flag = 1; + *valuelen = search->ie_value->length; } OPAL_THREAD_UNLOCK(info->i_lock); return OPAL_SUCCESS; } - /* * Get the nth key */ -int opal_info_get_nthkey (opal_info_t *info, int n, opal_cstring_t **key) +int opal_info_get_nthkey(opal_info_t *info, int n, opal_cstring_t **key) { opal_info_entry_t *iterator; @@ -449,15 +431,12 @@ int opal_info_get_nthkey (opal_info_t *info, int n, opal_cstring_t **key) * Iterate over and over till we get to the nth key */ OPAL_THREAD_LOCK(info->i_lock); - for (iterator = (opal_info_entry_t *)opal_list_get_first(&(info->super)); - n > 0; - --n) { - iterator = (opal_info_entry_t *)opal_list_get_next(iterator); - if (opal_list_get_end(&(info->super)) == - (opal_list_item_t *) iterator) { - OPAL_THREAD_UNLOCK(info->i_lock); - return OPAL_ERR_BAD_PARAM; - } + for (iterator = (opal_info_entry_t *) opal_list_get_first(&(info->super)); n > 0; --n) { + iterator = (opal_info_entry_t *) opal_list_get_next(iterator); + if (opal_list_get_end(&(info->super)) == (opal_list_item_t *) iterator) { + OPAL_THREAD_UNLOCK(info->i_lock); + return OPAL_ERR_BAD_PARAM; + } } OBJ_RETAIN(iterator->ie_key); *key = iterator->ie_key; @@ -465,8 +444,6 @@ int opal_info_get_nthkey (opal_info_t *info, int n, opal_cstring_t **key) return OPAL_SUCCESS; } - - /* * This function is invoked when OBJ_NEW() is called. Here, we add this * info pointer to the table and then store its index as the handle @@ -488,8 +465,7 @@ static void info_destructor(opal_info_t *info) /* Remove every key in the list */ - for (item = opal_list_remove_first(&(info->super)); - NULL != item; + for (item = opal_list_remove_first(&(info->super)); NULL != item; item = opal_list_remove_first(&(info->super))) { iterator = (opal_info_entry_t *) item; OBJ_RELEASE(iterator); @@ -500,7 +476,6 @@ static void info_destructor(opal_info_t *info) OBJ_RELEASE(info->i_lock); } - /* * opal_info_entry_t interface functions */ @@ -510,7 +485,6 @@ static void info_entry_constructor(opal_info_entry_t *entry) entry->ie_value = NULL; } - static void info_entry_destructor(opal_info_entry_t *entry) { if (NULL != entry->ie_key) { @@ -524,14 +498,13 @@ static void info_entry_destructor(opal_info_entry_t *entry) } } - /* * Find a key * * Do NOT thread lock in here -- the calling function is responsible * for that. */ -static opal_info_entry_t *info_find_key (opal_info_t *info, const char *key) +static opal_info_entry_t *info_find_key(opal_info_t *info, const char *key) { opal_info_entry_t *iterator; @@ -541,7 +514,7 @@ static opal_info_entry_t *info_find_key (opal_info_t *info, const char *key) * return immediately. Else, the loop will fall of the edge * and NULL is returned */ - OPAL_LIST_FOREACH(iterator, &info->super, opal_info_entry_t) { + OPAL_LIST_FOREACH (iterator, &info->super, opal_info_entry_t) { if (0 == strcmp(key, iterator->ie_key->string)) { return iterator; } diff --git a/opal/util/info.h b/opal/util/info.h index 53f3b7e35de..23c25984e41 100644 --- a/opal/util/info.h +++ b/opal/util/info.h @@ -31,8 +31,8 @@ #include "opal/class/opal_cstring.h" #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/mca/threads/mutex.h" #include "opal/mca/base/mca_base_var_enum.h" +#include "opal/mca/threads/mutex.h" /** * \internal @@ -40,8 +40,8 @@ */ struct opal_info_t { - opal_list_t super; - opal_mutex_t *i_lock; + opal_list_t super; + opal_mutex_t *i_lock; }; /** @@ -50,13 +50,11 @@ struct opal_info_t { */ typedef struct opal_info_t opal_info_t; - /** * Table for Fortran <-> C translation table */ extern opal_pointer_array_t ompi_info_f_to_c_table; - /** * \internal * @@ -64,7 +62,7 @@ extern opal_pointer_array_t ompi_info_f_to_c_table; * type. It contains (key,value) pairs */ struct opal_info_entry_t { - opal_list_item_t super; /**< required for opal_list_t type */ + opal_list_item_t super; /**< required for opal_list_t type */ opal_cstring_t *ie_value; /**< value part of the (key, value) pair. */ opal_cstring_t *ie_key; /**< "key" part of the (key, value) pair */ }; @@ -89,8 +87,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_t); */ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_entry_t); - -int opal_mpiinfo_init(void*); +int opal_mpiinfo_init(void *); /** * opal_info_dup - Duplicate an 'MPI_Info' object @@ -106,7 +103,7 @@ int opal_mpiinfo_init(void*); * an info object is no longer being used, it should be freed with * \c opal_info_free. */ -int opal_info_dup (opal_info_t *info, opal_info_t **newinfo); +int opal_info_dup(opal_info_t *info, opal_info_t **newinfo); // Comments might still say __IN_, but the code should be using the // below macro instead. @@ -138,7 +135,7 @@ int opal_info_dup (opal_info_t *info, opal_info_t **newinfo); * The user provided a setting that was rejected (ignored) by the system * output: nothing for this key */ -int opal_info_dup_mpistandard (opal_info_t *info, opal_info_t **newinfo); +int opal_info_dup_mpistandard(opal_info_t *info, opal_info_t **newinfo); /** * Set a new key,value pair on info. @@ -150,7 +147,7 @@ int opal_info_dup_mpistandard (opal_info_t *info, opal_info_t **newinfo); * @retval OPAL_SUCCESS upon success * @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory */ -OPAL_DECLSPEC int opal_info_set (opal_info_t *info, const char *key, const char *value); +OPAL_DECLSPEC int opal_info_set(opal_info_t *info, const char *key, const char *value); /** * Set a new key,value pair on info. @@ -165,7 +162,7 @@ OPAL_DECLSPEC int opal_info_set (opal_info_t *info, const char *key, const char * The \c value string object will be retained and can be safely released if necessary * by the caller. */ -OPAL_DECLSPEC int opal_info_set_cstring (opal_info_t *info, const char *key, opal_cstring_t *value); +OPAL_DECLSPEC int opal_info_set_cstring(opal_info_t *info, const char *key, opal_cstring_t *value); /** * Set a new key,value pair from a variable enumerator. @@ -179,8 +176,8 @@ OPAL_DECLSPEC int opal_info_set_cstring (opal_info_t *info, const char *key, opa * @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory * @retval OPAL_ERR_VALUE_OUT_OF_BOUNDS if the value is not valid in the enumerator */ -OPAL_DECLSPEC int opal_info_set_value_enum (opal_info_t *info, const char *key, int value, - mca_base_var_enum_t *var_enum); +OPAL_DECLSPEC int opal_info_set_value_enum(opal_info_t *info, const char *key, int value, + mca_base_var_enum_t *var_enum); /** * opal_info_free - Free an 'MPI_Info' object. @@ -194,33 +191,32 @@ OPAL_DECLSPEC int opal_info_set_value_enum (opal_info_t *info, const char *key, * 'MPI_INFO_NULL'. Free the info handle and all of its keys and * values. */ -int opal_info_free (opal_info_t **info); +int opal_info_free(opal_info_t **info); - /** - * Get a (key, value) pair from an 'MPI_Info' object and assign it - * into a boolen output. - * - * @param info Pointer to opal_info_t object - * @param key null-terminated character string of the index key - * @param value Boolean output value - * @param flag true (1) if 'key' defined on 'info', false (0) if not - * (logical) - * - * @retval OPAL_SUCCESS - * - * If found, the string value will be cast to the boolen output in - * the following manner: - * - * - If the string value is digits, the return value is "(bool) - * atoi(value)" - * - If the string value is (case-insensitive) "yes" or "true", the - * result is true - * - If the string value is (case-insensitive) "no" or "false", the - * result is false - * - All other values are false - */ -OPAL_DECLSPEC int opal_info_get_bool (opal_info_t *info, const char *key, bool *value, - int *flag); +/** + * Get a (key, value) pair from an 'MPI_Info' object and assign it + * into a boolen output. + * + * @param info Pointer to opal_info_t object + * @param key null-terminated character string of the index key + * @param value Boolean output value + * @param flag true (1) if 'key' defined on 'info', false (0) if not + * (logical) + * + * @retval OPAL_SUCCESS + * + * If found, the string value will be cast to the boolen output in + * the following manner: + * + * - If the string value is digits, the return value is "(bool) + * atoi(value)" + * - If the string value is (case-insensitive) "yes" or "true", the + * result is true + * - If the string value is (case-insensitive) "no" or "false", the + * result is false + * - All other values are false + */ +OPAL_DECLSPEC int opal_info_get_bool(opal_info_t *info, const char *key, bool *value, int *flag); /** * Get a (key, value) pair from an 'MPI_Info' object and assign it @@ -238,9 +234,9 @@ OPAL_DECLSPEC int opal_info_get_bool (opal_info_t *info, const char *key, bool * * @retval OPAL_SUCCESS */ -OPAL_DECLSPEC int opal_info_get_value_enum (opal_info_t *info, const char *key, - int *value, int default_value, - mca_base_var_enum_t *var_enum, int *flag); +OPAL_DECLSPEC int opal_info_get_value_enum(opal_info_t *info, const char *key, int *value, + int default_value, mca_base_var_enum_t *var_enum, + int *flag); /** * Get a (key, value) pair from an 'MPI_Info' object @@ -258,8 +254,8 @@ OPAL_DECLSPEC int opal_info_get_value_enum (opal_info_t *info, const char *key, * reference count of the \c string object by calling \c OBJ_RELEASE on it * once the object is not needed any more. */ -OPAL_DECLSPEC int opal_info_get (opal_info_t *info, const char *key, - opal_cstring_t **string, int *flag); +OPAL_DECLSPEC int opal_info_get(opal_info_t *info, const char *key, opal_cstring_t **string, + int *flag); /** * Delete a (key,value) pair from "info" @@ -288,8 +284,8 @@ int opal_info_delete(opal_info_t *info, const char *key); * character. If the 'key' is not found on 'info', 'valuelen' is left * alone. */ -OPAL_DECLSPEC int opal_info_get_valuelen (opal_info_t *info, const char *key, int *valuelen, - int *flag); +OPAL_DECLSPEC int opal_info_get_valuelen(opal_info_t *info, const char *key, int *valuelen, + int *flag); /** * opal_info_get_nthkey - Get a key indexed by integer from an info object @@ -305,7 +301,7 @@ OPAL_DECLSPEC int opal_info_get_valuelen (opal_info_t *info, const char *key, in * \c key string by calling \c OBJ_RELEASE on it once the object is not needed * any more. */ -int opal_info_get_nthkey (opal_info_t *info, int n, opal_cstring_t **key); +int opal_info_get_nthkey(opal_info_t *info, int n, opal_cstring_t **key); /** * Get the number of keys defined on on an MPI_Info object @@ -314,15 +310,12 @@ int opal_info_get_nthkey (opal_info_t *info, int n, opal_cstring_t **key); * * @retval The number of keys defined on info */ -static inline int -opal_info_get_nkeys(opal_info_t *info, int *nkeys) +static inline int opal_info_get_nkeys(opal_info_t *info, int *nkeys) { *nkeys = (int) opal_list_get_size(&(info->super)); return OPAL_SUCCESS; } - END_C_DECLS - #endif /* OPAL_INFO_H */ diff --git a/opal/util/info_subscriber.c b/opal/util/info_subscriber.c index 36fd53d67b8..eb30ec9175c 100644 --- a/opal/util/info_subscriber.c +++ b/opal/util/info_subscriber.c @@ -25,26 +25,28 @@ * $HEADER$ */ -#include #include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif -#include #include +#include #ifdef HAVE_SYS_UTSNAME_H -#include +# include #endif #include #include #include "opal/util/argv.h" +#include "opal/util/info_subscriber.h" #include "opal/util/opal_getcwd.h" #include "opal/util/output.h" -#include "opal/util/info_subscriber.h" -static const char* opal_infosubscribe_inform_subscribers(opal_infosubscriber_t * object, const char *key, const char *new_value, int *found_callback); +static const char *opal_infosubscribe_inform_subscribers(opal_infosubscriber_t *object, + const char *key, const char *new_value, + int *found_callback); static void infosubscriber_construct(opal_infosubscriber_t *obj); static void infosubscriber_destruct(opal_infosubscriber_t *obj); @@ -62,24 +64,22 @@ struct opal_callback_list_item_t { typedef struct opal_callback_list_item_t opal_callback_list_item_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_infosubscriber_t); -OBJ_CLASS_INSTANCE(opal_infosubscriber_t, - opal_object_t, - infosubscriber_construct, +OBJ_CLASS_INSTANCE(opal_infosubscriber_t, opal_object_t, infosubscriber_construct, infosubscriber_destruct); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_callback_list_item_t); static void opal_callback_list_item_destruct(opal_callback_list_item_t *obj); -OBJ_CLASS_INSTANCE(opal_callback_list_item_t, - opal_list_item_t, - NULL, +OBJ_CLASS_INSTANCE(opal_callback_list_item_t, opal_list_item_t, NULL, opal_callback_list_item_destruct); -static void infosubscriber_construct(opal_infosubscriber_t *obj) { +static void infosubscriber_construct(opal_infosubscriber_t *obj) +{ OBJ_CONSTRUCT(&obj->s_subscriber_table, opal_hash_table_t); opal_hash_table_init(&obj->s_subscriber_table, 10); } -static void infosubscriber_destruct(opal_infosubscriber_t *obj) { +static void infosubscriber_destruct(opal_infosubscriber_t *obj) +{ opal_hash_table_t *table = &obj->s_subscriber_table; void *node = NULL; int err; @@ -87,13 +87,13 @@ static void infosubscriber_destruct(opal_infosubscriber_t *obj) { size_t key_size; opal_list_t *list = NULL; - err = opal_hash_table_get_first_key_ptr(table, - (void**) &next_key, &key_size, (void**) &list, &node); + err = opal_hash_table_get_first_key_ptr(table, (void **) &next_key, &key_size, (void **) &list, + &node); while (list && err == OPAL_SUCCESS) { OPAL_LIST_RELEASE(list); - err = opal_hash_table_get_next_key_ptr(table, - (void**) &next_key, &key_size, (void**) &list, node, &node); + err = opal_hash_table_get_next_key_ptr(table, (void **) &next_key, &key_size, + (void **) &list, node, &node); } OBJ_DESTRUCT(&obj->s_subscriber_table); @@ -103,35 +103,43 @@ static void infosubscriber_destruct(opal_infosubscriber_t *obj) { } } -static void opal_callback_list_item_destruct(opal_callback_list_item_t *obj) { +static void opal_callback_list_item_destruct(opal_callback_list_item_t *obj) +{ if (obj->default_value) { OBJ_RELEASE(obj->default_value); } } -static const char* opal_infosubscribe_inform_subscribers(opal_infosubscriber_t *object, const char *key, const char *new_value, int *found_callback) +static const char *opal_infosubscribe_inform_subscribers(opal_infosubscriber_t *object, + const char *key, const char *new_value, + int *found_callback) { opal_hash_table_t *table = &object->s_subscriber_table; opal_list_t *list = NULL; opal_callback_list_item_t *item; const char *updated_value = NULL; - if (found_callback) { *found_callback = 0; } -/* - * Present the new value to each subscriber. They can decide to accept it, ignore it, or - * over-ride it with their own value (like ignore, but they specify what value they want it to have). - * - * Since multiple subscribers could set values, only the last setting is kept as the - * returned value. - */ + if (found_callback) { + *found_callback = 0; + } + /* + * Present the new value to each subscriber. They can decide to accept it, ignore it, or + * over-ride it with their own value (like ignore, but they specify what value they want it to + * have). + * + * Since multiple subscribers could set values, only the last setting is kept as the + * returned value. + */ if (table) { - opal_hash_table_get_value_ptr(table, key, strlen(key), (void**) &list); + opal_hash_table_get_value_ptr(table, key, strlen(key), (void **) &list); if (list) { updated_value = new_value; - OPAL_LIST_FOREACH(item, list, opal_callback_list_item_t) { + OPAL_LIST_FOREACH (item, list, opal_callback_list_item_t) { updated_value = item->callback(object, key, updated_value); - if (found_callback) { *found_callback = 1; } + if (found_callback) { + *found_callback = 1; + } } } } @@ -139,9 +147,6 @@ static const char* opal_infosubscribe_inform_subscribers(opal_infosubscriber_t * return updated_value; } - - - /* * Testing-only static data, all paths using this code should be * inactive in a normal run. In particular ntesting_callbacks is 0 @@ -153,15 +158,14 @@ static char *testing_keys[5]; static char *testing_initialvals[5]; // User-level call, user adds their own callback function to be subscribed // to every object: -int opal_infosubscribe_testcallback(opal_key_interest_callback_t *callback, - char *key, char *val); +int opal_infosubscribe_testcallback(opal_key_interest_callback_t *callback, char *key, char *val); -int -opal_infosubscribe_testcallback(opal_key_interest_callback_t *callback, - char *key, char *val) +int opal_infosubscribe_testcallback(opal_key_interest_callback_t *callback, char *key, char *val) { int i = ntesting_callbacks; - if (ntesting_callbacks >= 5) { return -1; } + if (ntesting_callbacks >= 5) { + return -1; + } testing_callbacks[i] = callback; testing_keys[i] = key; @@ -171,31 +175,27 @@ opal_infosubscribe_testcallback(opal_key_interest_callback_t *callback, } int opal_infosubscribe_testregister(opal_infosubscriber_t *object); -int -opal_infosubscribe_testregister(opal_infosubscriber_t *object) +int opal_infosubscribe_testregister(opal_infosubscriber_t *object) { opal_hash_table_t *table = &object->s_subscriber_table; opal_callback_list_item_t *item; opal_list_t *list = NULL; -// The testing section should only ever be activated if the testing callback -// above is used. + // The testing section should only ever be activated if the testing callback + // above is used. if (ntesting_callbacks != 0) { int i; - for (i=0; idefault_value->string, testing_initialvals[i]) - && - item->callback == testing_callbacks[i]) - { + OPAL_LIST_FOREACH (item, list, opal_callback_list_item_t) { + if (0 == strcmp(item->default_value->string, testing_initialvals[i]) + && item->callback == testing_callbacks[i]) { found = 1; } } @@ -203,15 +203,14 @@ opal_infosubscribe_testregister(opal_infosubscriber_t *object) list = NULL; if (!found) { - opal_infosubscribe_subscribe(object, - testing_keys[i], - testing_initialvals[i], testing_callbacks[i]); + opal_infosubscribe_subscribe(object, testing_keys[i], testing_initialvals[i], + testing_callbacks[i]); } } } -// For testing-mode only, while we're here, lets walk the whole list -// to see if there are any duplicates. + // For testing-mode only, while we're here, lets walk the whole list + // to see if there are any duplicates. if (ntesting_callbacks != 0) { int err; void *node = NULL; @@ -219,29 +218,26 @@ opal_infosubscribe_testregister(opal_infosubscriber_t *object) char *next_key; opal_callback_list_item_t *item1, *item2; - err = opal_hash_table_get_first_key_ptr(table, (void**) &next_key, - &key_size, (void**) &list, &node); + err = opal_hash_table_get_first_key_ptr(table, (void **) &next_key, &key_size, + (void **) &list, &node); while (list && err == OPAL_SUCCESS) { int counter = 0; - OPAL_LIST_FOREACH(item1, list, opal_callback_list_item_t) { - OPAL_LIST_FOREACH(item2, list, opal_callback_list_item_t) { - if (0 == - strcmp(item1->default_value->string, item2->default_value->string) - && - item1->callback == item2->callback) - { + OPAL_LIST_FOREACH (item1, list, opal_callback_list_item_t) { + OPAL_LIST_FOREACH (item2, list, opal_callback_list_item_t) { + if (0 == strcmp(item1->default_value->string, item2->default_value->string) + && item1->callback == item2->callback) { ++counter; } } } if (counter > 1) { printf("ERROR: duplicate info key/val subscription found " - "in hash table\n"); + "in hash table\n"); exit(-1); } - err = opal_hash_table_get_next_key_ptr(table, - (void**) &next_key, &key_size, (void**) &list, node, &node); + err = opal_hash_table_get_next_key_ptr(table, (void **) &next_key, &key_size, + (void **) &list, node, &node); } } @@ -255,8 +251,8 @@ opal_infosubscribe_testregister(opal_infosubscriber_t *object) // // The last argument indicates whether to overwrite a previous // __IN_ or not. -static int -save_original_key_val(opal_info_t *info, const char *key, opal_cstring_t *val, int overwrite) +static int save_original_key_val(opal_info_t *info, const char *key, opal_cstring_t *val, + int overwrite) { char modkey[OPAL_MAX_INFO_KEY]; int flag, err; @@ -264,9 +260,8 @@ save_original_key_val(opal_info_t *info, const char *key, opal_cstring_t *val, i // Checking strlen, even though it should be unnecessary. // This should only happen on predefined keys with short lengths. if (strlen(key) + strlen(OPAL_INFO_SAVE_PREFIX) < OPAL_MAX_INFO_KEY) { - snprintf(modkey, OPAL_MAX_INFO_KEY, - OPAL_INFO_SAVE_PREFIX "%s", key); -// (the prefix macro is a string, so the unreadable part above is a string concatenation) + snprintf(modkey, OPAL_MAX_INFO_KEY, OPAL_INFO_SAVE_PREFIX "%s", key); + // (the prefix macro is a string, so the unreadable part above is a string concatenation) flag = 0; opal_info_get(info, modkey, 0, &flag); if (!flag || overwrite) { @@ -287,8 +282,7 @@ save_original_key_val(opal_info_t *info, const char *key, opal_cstring_t *val, i return OPAL_SUCCESS; } -int -opal_infosubscribe_change_info(opal_infosubscriber_t *object, opal_info_t *new_info) +int opal_infosubscribe_change_info(opal_infosubscriber_t *object, opal_info_t *new_info) { int err; opal_info_entry_t *iterator; @@ -302,38 +296,40 @@ opal_infosubscribe_change_info(opal_infosubscriber_t *object, opal_info_t *new_i } if (NULL != new_info) { - OPAL_LIST_FOREACH(iterator, &new_info->super, opal_info_entry_t) { - opal_cstring_t *value_str, *key_str; - value_str = iterator->ie_value; - OBJ_RETAIN(value_str); - key_str = iterator->ie_key; - OBJ_RETAIN(key_str); - - updated_value = opal_infosubscribe_inform_subscribers(object, iterator->ie_key->string, - iterator->ie_value->string, &found_callback); - if (updated_value) { - err = opal_info_set(object->s_info, iterator->ie_key->string, updated_value); - } else { -// This path would happen if there was no callback for this key, -// or if there was a callback and it returned null. One way the -// setting was unrecognized the other way it was recognized and ignored, -// either way it shouldn't be set, which we'll ensure with an unset -// in case a previous value exists. - err = opal_info_delete(object->s_info, iterator->ie_key->string); - err = OPAL_SUCCESS; // we don't care if the key was found or not - } - if (OPAL_SUCCESS != err) { + OPAL_LIST_FOREACH (iterator, &new_info->super, opal_info_entry_t) { + opal_cstring_t *value_str, *key_str; + value_str = iterator->ie_value; + OBJ_RETAIN(value_str); + key_str = iterator->ie_key; + OBJ_RETAIN(key_str); + + updated_value = opal_infosubscribe_inform_subscribers(object, iterator->ie_key->string, + iterator->ie_value->string, + &found_callback); + if (updated_value) { + err = opal_info_set(object->s_info, iterator->ie_key->string, updated_value); + } else { + // This path would happen if there was no callback for this key, + // or if there was a callback and it returned null. One way the + // setting was unrecognized the other way it was recognized and ignored, + // either way it shouldn't be set, which we'll ensure with an unset + // in case a previous value exists. + err = opal_info_delete(object->s_info, iterator->ie_key->string); + err = OPAL_SUCCESS; // we don't care if the key was found or not + } + if (OPAL_SUCCESS != err) { + OBJ_RELEASE(value_str); + OBJ_RELEASE(key_str); + return err; + } + // Save the original at "__IN_":"original" + // And if multiple set-info calls happen, the last would be the most relevant + // to save, so overwrite a previously saved value if there is one. + save_original_key_val(object->s_info, key_str->string, value_str, 1); OBJ_RELEASE(value_str); OBJ_RELEASE(key_str); - return err; } -// Save the original at "__IN_":"original" -// And if multiple set-info calls happen, the last would be the most relevant -// to save, so overwrite a previously saved value if there is one. - save_original_key_val(object->s_info, key_str->string, value_str, 1); - OBJ_RELEASE(value_str); - OBJ_RELEASE(key_str); - }} + } return OPAL_SUCCESS; } @@ -356,7 +352,8 @@ opal_infosubscribe_change_info(opal_infosubscriber_t *object, opal_info_t *new_i // to me this might be required if the strings become more dynamic than the // simple true/false values seen in the current code. It'll be an easy change, // callback() is only used two places. -int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, const char *key, const char *value, opal_key_interest_callback_t *callback) +int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, const char *key, const char *value, + opal_key_interest_callback_t *callback) { opal_list_t *list = NULL; opal_hash_table_t *table = &object->s_subscriber_table; @@ -364,20 +361,25 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, const char *key, size_t max_len = OPAL_MAX_INFO_KEY - strlen(OPAL_INFO_SAVE_PREFIX); if (strlen(key) > max_len) { - opal_output(0, "DEVELOPER WARNING: Unexpected MPI info key length [%s]: " + opal_output(0, + "DEVELOPER WARNING: Unexpected MPI info key length [%s]: " "OMPI internal callback keys are limited to %" PRIsize_t " chars.", key, max_len); #if OPAL_ENABLE_DEBUG - opal_output(0, "Aborting because this is a developer / debugging build. Go fix this error."); + opal_output(0, + "Aborting because this is a developer / debugging build. Go fix this error."); // Do not assert() / dump core. Just exit un-gracefully. exit(1); #else - opal_output(0, "The \"%s\" MPI info key almost certainly will not work properly. You should inform an Open MPI developer about this.", key); + opal_output(0, + "The \"%s\" MPI info key almost certainly will not work properly. You should " + "inform an Open MPI developer about this.", + key); #endif } if (table) { - opal_hash_table_get_value_ptr(table, key, strlen(key), (void**) &list); + opal_hash_table_get_value_ptr(table, key, strlen(key), (void **) &list); if (!list) { list = OBJ_NEW(opal_list_t); @@ -388,21 +390,21 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, const char *key, callback_list_item->callback = callback; callback_list_item->default_value = value_str; - opal_list_append(list, (opal_list_item_t*) callback_list_item); + opal_list_append(list, (opal_list_item_t *) callback_list_item); -// Trigger callback() on either the default value or the info that's in the -// object if there is one. Unfortunately there's some code duplication as -// this is similar to the job of opal_infosubscribe_change_info(). -// -// The value we store for key is whatever the callback() returns. -// We also leave a backup __IN_* key with the previous value. + // Trigger callback() on either the default value or the info that's in the + // object if there is one. Unfortunately there's some code duplication as + // this is similar to the job of opal_infosubscribe_change_info(). + // + // The value we store for key is whatever the callback() returns. + // We also leave a backup __IN_* key with the previous value. -// - is there an info object yet attached to this object + // - is there an info object yet attached to this object if (NULL == object->s_info) { object->s_info = OBJ_NEW(opal_info_t); } -// - is there a value already associated with key in this obj's info: -// to use in the callback() + // - is there a value already associated with key in this obj's info: + // to use in the callback() opal_cstring_t *val; int flag = 0; const char *updated_value; @@ -412,7 +414,7 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, const char *key, val = value_str; // fall back to default string OBJ_RETAIN(val); } -// - callback() and modify the val in info + // - callback() and modify the val in info updated_value = callback(object, key, val->string); if (updated_value) { err = opal_info_set(object->s_info, key, updated_value); @@ -424,20 +426,20 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, const char *key, OBJ_RELEASE(val); return err; } -// - save the previous val under key __IN_* -// This function might be called separately for the same key multiple -// times (multiple modules might register an interest in the same key), -// so we only save __IN_ for the first. -// Note we're saving the first k/v regardless of whether it was the default -// or whether it came from info. This means system settings will show -// up if the user queries later with get_info. + // - save the previous val under key __IN_* + // This function might be called separately for the same key multiple + // times (multiple modules might register an interest in the same key), + // so we only save __IN_ for the first. + // Note we're saving the first k/v regardless of whether it was the default + // or whether it came from info. This means system settings will show + // up if the user queries later with get_info. save_original_key_val(object->s_info, key, val, 0); OBJ_RELEASE(val); } else { -/* - * TODO: This should not happen - */ + /* + * TODO: This should not happen + */ } return OPAL_SUCCESS; diff --git a/opal/util/info_subscriber.h b/opal/util/info_subscriber.h index 9f4021a9de8..a5cfd6e1591 100644 --- a/opal/util/info_subscriber.h +++ b/opal/util/info_subscriber.h @@ -27,27 +27,27 @@ #include +#include "opal/class/opal_hash_table.h" #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" -#include "opal/class/opal_hash_table.h" #include "opal/mca/threads/mutex.h" #include "opal/util/info.h" #include "opal/mca/base/mca_base_var_enum.h" - #define INFO_SUBSCRIBER_SIZE 5 struct opal_infosubscriber_t { - opal_object_t s_base; - opal_hash_table_t s_subscriber_table; - opal_info_t *s_info; + opal_object_t s_base; + opal_hash_table_t s_subscriber_table; + opal_info_t *s_info; }; typedef struct opal_infosubscriber_t opal_infosubscriber_t; OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_infosubscriber_t); -typedef const char*(opal_key_interest_callback_t)(opal_infosubscriber_t*, const char*, const char*); +typedef const char *(opal_key_interest_callback_t)(opal_infosubscriber_t *, const char *, + const char *); /** * opal_infosubscribe_change_info - Make changes to a Comm/Win/File Info @@ -61,8 +61,7 @@ typedef const char*(opal_key_interest_callback_t)(opal_infosubscriber_t*, const * * Notifies subscribers of info's that have gone away and new info settings */ -int opal_infosubscribe_change_info(opal_infosubscriber_t*, opal_info_t *); - +int opal_infosubscribe_change_info(opal_infosubscriber_t *, opal_info_t *); /** * opal_infosubscribe_subscribe - Request to be updated about info changes to a Comm/Win/File Info @@ -79,6 +78,7 @@ int opal_infosubscribe_change_info(opal_infosubscriber_t*, opal_info_t *); * Does not try to optimize settings that are the same between old and new * info's. */ -int opal_infosubscribe_subscribe(opal_infosubscriber_t*, const char *, const char *, opal_key_interest_callback_t); +int opal_infosubscribe_subscribe(opal_infosubscriber_t *, const char *, const char *, + opal_key_interest_callback_t); #endif /* OMPI_INFO_H */ diff --git a/opal/util/keyval/keyval_lex.h b/opal/util/keyval/keyval_lex.h index 95174ad9b39..004f6b82a8f 100644 --- a/opal/util/keyval/keyval_lex.h +++ b/opal/util/keyval/keyval_lex.h @@ -23,13 +23,13 @@ #include "opal_config.h" #ifdef malloc -#undef malloc +# undef malloc #endif #ifdef realloc -#undef realloc +# undef realloc #endif #ifdef free -#undef free +# undef free #endif #include @@ -47,12 +47,12 @@ extern int opal_util_keyval_yylineno; /* * Make lex-generated files not issue compiler warnings */ -#define YY_STACK_USED 0 +#define YY_STACK_USED 0 #define YY_ALWAYS_INTERACTIVE 0 -#define YY_NEVER_INTERACTIVE 0 -#define YY_MAIN 0 -#define YY_NO_UNPUT 1 -#define YY_SKIP_YYWRAP 1 +#define YY_NEVER_INTERACTIVE 0 +#define YY_MAIN 0 +#define YY_NO_UNPUT 1 +#define YY_SKIP_YYWRAP 1 enum opal_keyval_parse_state_t { OPAL_UTIL_KEYVAL_PARSE_DONE, diff --git a/opal/util/keyval_parse.c b/opal/util/keyval_parse.c index ea7e2d72f24..3a2fb2d1bbe 100644 --- a/opal/util/keyval_parse.c +++ b/opal/util/keyval_parse.c @@ -25,14 +25,14 @@ #include "opal_config.h" #include "opal/constants.h" +#include "opal/mca/threads/mutex.h" #include "opal/runtime/opal.h" -#include "opal/util/keyval_parse.h" #include "opal/util/keyval/keyval_lex.h" +#include "opal/util/keyval_parse.h" #include "opal/util/output.h" #include "opal/util/string_copy.h" -#include "opal/mca/threads/mutex.h" -#include #include +#include int opal_util_keyval_parse_lineno = 0; @@ -49,7 +49,7 @@ static void parse_error(int num); static char *env_str = NULL; static int envsize = 1024; -static void opal_util_keyval_parse_finalize (void) +static void opal_util_keyval_parse_finalize(void) { free(key_buffer); key_buffer = NULL; @@ -62,17 +62,16 @@ int opal_util_keyval_parse_init(void) { OBJ_CONSTRUCT(&keyval_mutex, opal_mutex_t); - opal_finalize_register_cleanup (opal_util_keyval_parse_finalize); + opal_finalize_register_cleanup(opal_util_keyval_parse_finalize); return OPAL_SUCCESS; } -int -opal_util_keyval_parse(const char *filename, - opal_keyval_parse_fn_t callback) +int opal_util_keyval_parse(const char *filename, opal_keyval_parse_fn_t callback) { int val; - int ret = OPAL_SUCCESS;; + int ret = OPAL_SUCCESS; + ; OPAL_THREAD_LOCK(&keyval_mutex); @@ -118,15 +117,13 @@ opal_util_keyval_parse(const char *filename, } } fclose(opal_util_keyval_yyin); - opal_util_keyval_yylex_destroy (); + opal_util_keyval_yylex_destroy(); cleanup: OPAL_THREAD_UNLOCK(&keyval_mutex); return ret; } - - static int parse_line(void) { int val; @@ -137,7 +134,7 @@ static int parse_line(void) if (key_buffer_len < strlen(opal_util_keyval_yytext) + 1) { char *tmp; key_buffer_len = strlen(opal_util_keyval_yytext) + 1; - tmp = (char*)realloc(key_buffer, key_buffer_len); + tmp = (char *) realloc(key_buffer, key_buffer_len); if (NULL == tmp) { free(key_buffer); key_buffer_len = 0; @@ -160,23 +157,20 @@ static int parse_line(void) /* Next we get the value */ val = opal_util_keyval_yylex(); - if (OPAL_UTIL_KEYVAL_PARSE_SINGLE_WORD == val || - OPAL_UTIL_KEYVAL_PARSE_VALUE == val) { + if (OPAL_UTIL_KEYVAL_PARSE_SINGLE_WORD == val || OPAL_UTIL_KEYVAL_PARSE_VALUE == val) { keyval_callback(key_buffer, opal_util_keyval_yytext); /* Now we need to see the newline */ val = opal_util_keyval_yylex(); - if (OPAL_UTIL_KEYVAL_PARSE_NEWLINE == val || - OPAL_UTIL_KEYVAL_PARSE_DONE == val) { + if (OPAL_UTIL_KEYVAL_PARSE_NEWLINE == val || OPAL_UTIL_KEYVAL_PARSE_DONE == val) { return OPAL_SUCCESS; } } /* Did we get an EOL or EOF? */ - else if (OPAL_UTIL_KEYVAL_PARSE_DONE == val || - OPAL_UTIL_KEYVAL_PARSE_NEWLINE == val) { + else if (OPAL_UTIL_KEYVAL_PARSE_DONE == val || OPAL_UTIL_KEYVAL_PARSE_NEWLINE == val) { keyval_callback(key_buffer, NULL); return OPAL_SUCCESS; } @@ -186,12 +180,11 @@ static int parse_line(void) return OPAL_ERROR; } - static void parse_error(int num) { /* JMS need better error/warning message here */ - opal_output(0, "keyval parser: error %d reading file %s at line %d:\n %s\n", - num, keyval_filename, opal_util_keyval_yynewlines, opal_util_keyval_yytext); + opal_output(0, "keyval parser: error %d reading file %s at line %d:\n %s\n", num, + keyval_filename, opal_util_keyval_yynewlines, opal_util_keyval_yytext); } int opal_util_keyval_save_internal_envars(opal_keyval_parse_fn_t callback) @@ -204,7 +197,7 @@ int opal_util_keyval_save_internal_envars(opal_keyval_parse_fn_t callback) return OPAL_SUCCESS; } -static void trim_name(char *buffer, const char* prefix, const char* suffix) +static void trim_name(char *buffer, const char *prefix, const char *suffix) { char *pchr, *echr; size_t buffer_len; @@ -213,54 +206,54 @@ static void trim_name(char *buffer, const char* prefix, const char* suffix) return; } - buffer_len = strlen (buffer); + buffer_len = strlen(buffer); pchr = buffer; if (NULL != prefix) { - size_t prefix_len = strlen (prefix); + size_t prefix_len = strlen(prefix); - if (0 == strncmp (buffer, prefix, prefix_len)) { + if (0 == strncmp(buffer, prefix, prefix_len)) { pchr += prefix_len; } } /* trim spaces at the beginning */ - while (isspace (*pchr)) { + while (isspace(*pchr)) { pchr++; } /* trim spaces at the end */ echr = buffer + buffer_len; - while (echr > buffer && isspace (*(echr - 1))) { + while (echr > buffer && isspace(*(echr - 1))) { echr--; } echr[0] = '\0'; - if (NULL != suffix && (uintptr_t) (echr - buffer) > strlen (suffix)) { - size_t suffix_len = strlen (suffix); + if (NULL != suffix && (uintptr_t)(echr - buffer) > strlen(suffix)) { + size_t suffix_len = strlen(suffix); echr -= suffix_len; - if (0 == strncmp (echr, suffix, strlen(suffix))) { + if (0 == strncmp(echr, suffix, strlen(suffix))) { do { echr--; - } while (isspace (*echr)); + } while (isspace(*echr)); echr[1] = '\0'; } } if (buffer != pchr) { /* move the trimmed string to the beginning of the buffer */ - memmove (buffer, pchr, strlen (pchr) + 1); + memmove(buffer, pchr, strlen(pchr) + 1); } } -static int save_param_name (void) +static int save_param_name(void) { if (key_buffer_len < strlen(opal_util_keyval_yytext) + 1) { char *tmp; key_buffer_len = strlen(opal_util_keyval_yytext) + 1; - tmp = (char*)realloc(key_buffer, key_buffer_len); + tmp = (char *) realloc(key_buffer, key_buffer_len); if (NULL == tmp) { free(key_buffer); key_buffer_len = 0; @@ -270,7 +263,7 @@ static int save_param_name (void) key_buffer = tmp; } - opal_string_copy (key_buffer, opal_util_keyval_yytext, key_buffer_len); + opal_string_copy(key_buffer, opal_util_keyval_yytext, key_buffer_len); return OPAL_SUCCESS; } @@ -342,22 +335,22 @@ static int parse_line_new(opal_keyval_parse_state_t first_val) val = first_val; while (OPAL_UTIL_KEYVAL_PARSE_NEWLINE != val && OPAL_UTIL_KEYVAL_PARSE_DONE != val) { - rc = save_param_name (); + rc = save_param_name(); if (OPAL_SUCCESS != rc) { return rc; } if (OPAL_UTIL_KEYVAL_PARSE_MCAVAR == val) { - trim_name (key_buffer, "-mca", NULL); - trim_name (key_buffer, "--mca", NULL); + trim_name(key_buffer, "-mca", NULL); + trim_name(key_buffer, "--mca", NULL); val = opal_util_keyval_yylex(); if (OPAL_UTIL_KEYVAL_PARSE_VALUE == val) { if (NULL != opal_util_keyval_yytext) { tmp = strdup(opal_util_keyval_yytext); if ('\'' == tmp[0] || '\"' == tmp[0]) { - trim_name (tmp, "\'", "\'"); - trim_name (tmp, "\"", "\""); + trim_name(tmp, "\'", "\'"); + trim_name(tmp, "\"", "\""); } keyval_callback(key_buffer, tmp); free(tmp); @@ -367,8 +360,8 @@ static int parse_line_new(opal_keyval_parse_state_t first_val) return OPAL_ERROR; } } else if (OPAL_UTIL_KEYVAL_PARSE_ENVEQL == val) { - trim_name (key_buffer, "-x", "="); - trim_name (key_buffer, "--x", NULL); + trim_name(key_buffer, "-x", "="); + trim_name(key_buffer, "--x", NULL); val = opal_util_keyval_yylex(); if (OPAL_UTIL_KEYVAL_PARSE_VALUE == val) { @@ -378,8 +371,8 @@ static int parse_line_new(opal_keyval_parse_state_t first_val) return OPAL_ERROR; } } else if (OPAL_UTIL_KEYVAL_PARSE_ENVVAR == val) { - trim_name (key_buffer, "-x", "="); - trim_name (key_buffer, "--x", NULL); + trim_name(key_buffer, "-x", "="); + trim_name(key_buffer, "--x", NULL); add_to_env_str(key_buffer, NULL); } else { /* we got something unexpected. Bonk! */ diff --git a/opal/util/keyval_parse.h b/opal/util/keyval_parse.h index dd4d8ec82b9..d2034bf7911 100644 --- a/opal/util/keyval_parse.h +++ b/opal/util/keyval_parse.h @@ -48,8 +48,7 @@ typedef void (*opal_keyval_parse_fn_t)(const char *key, const char *value); * called exactly once. In a multithreaded context, calls to * opal_util_keyval_parse() will serialize multiple calls. */ -OPAL_DECLSPEC int opal_util_keyval_parse(const char *filename, - opal_keyval_parse_fn_t callback); +OPAL_DECLSPEC int opal_util_keyval_parse(const char *filename, opal_keyval_parse_fn_t callback); OPAL_DECLSPEC int opal_util_keyval_parse_init(void); diff --git a/opal/util/malloc.c b/opal/util/malloc.c index be917a379d1..b10167a97a4 100644 --- a/opal/util/malloc.c +++ b/opal/util/malloc.c @@ -23,26 +23,25 @@ #include +#include "opal/runtime/opal.h" #include "opal/util/malloc.h" #include "opal/util/output.h" -#include "opal/runtime/opal.h" - /* * Undefine "malloc" and "free" */ #if defined(malloc) -#undef malloc +# undef malloc #endif #if defined(calloc) -#undef calloc +# undef calloc #endif #if defined(free) -#undef free +# undef free #endif #if defined(realloc) -#undef realloc +# undef realloc #endif /* @@ -51,8 +50,6 @@ int opal_malloc_debug_level = OPAL_MALLOC_DEBUG_LEVEL; int opal_malloc_output = -1; - - #if OPAL_ENABLE_DEBUG /* @@ -83,13 +80,13 @@ void opal_malloc_init(void) malloc_stream.lds_prefix = "malloc debug: "; malloc_stream.lds_want_stderr = true; opal_malloc_output = opal_output_open(&malloc_stream); - opal_finalize_register_cleanup (opal_malloc_finalize); + opal_finalize_register_cleanup(opal_malloc_finalize); } #else -void opal_malloc_init (void) +void opal_malloc_init(void) { } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ /* * Debug version of malloc @@ -100,8 +97,8 @@ void *opal_malloc(size_t size, const char *file, int line) #if OPAL_ENABLE_DEBUG if (opal_malloc_debug_level > 1) { if (size <= 0) { - opal_output(opal_malloc_output, "Request for %ld bytes (%s, %d)", - (long) size, file, line); + opal_output(opal_malloc_output, "Request for %ld bytes (%s, %d)", (long) size, file, + line); } } #endif /* OPAL_ENABLE_DEBUG */ @@ -111,16 +108,14 @@ void *opal_malloc(size_t size, const char *file, int line) #if OPAL_ENABLE_DEBUG if (opal_malloc_debug_level > 0) { if (NULL == addr) { - opal_output(opal_malloc_output, - "Request for %ld bytes failed (%s, %d)", - (long) size, file, line); + opal_output(opal_malloc_output, "Request for %ld bytes failed (%s, %d)", (long) size, + file, line); } } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ return addr; } - /* * Debug version of calloc */ @@ -130,12 +125,11 @@ void *opal_calloc(size_t nmembers, size_t size, const char *file, int line) #if OPAL_ENABLE_DEBUG if (opal_malloc_debug_level > 1) { if (size <= 0) { - opal_output(opal_malloc_output, - "Request for %ld zeroed elements of size %ld (%s, %d)", + opal_output(opal_malloc_output, "Request for %ld zeroed elements of size %ld (%s, %d)", (long) nmembers, (long) size, file, line); } } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ addr = calloc(nmembers, size); #if OPAL_ENABLE_DEBUG if (opal_malloc_debug_level > 0) { @@ -145,11 +139,10 @@ void *opal_calloc(size_t nmembers, size_t size, const char *file, int line) (long) nmembers, (long) size, file, line); } } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ return addr; } - /* * Debug version of realloc */ @@ -160,30 +153,27 @@ void *opal_realloc(void *ptr, size_t size, const char *file, int line) if (opal_malloc_debug_level > 1) { if (size <= 0) { if (NULL == ptr) { - opal_output(opal_malloc_output, - "Realloc NULL for %ld bytes (%s, %d)", - (long) size, file, line); + opal_output(opal_malloc_output, "Realloc NULL for %ld bytes (%s, %d)", (long) size, + file, line); } else { - opal_output(opal_malloc_output, "Realloc %p for %ld bytes (%s, %d)", - ptr, (long) size, file, line); + opal_output(opal_malloc_output, "Realloc %p for %ld bytes (%s, %d)", ptr, + (long) size, file, line); } } } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ addr = realloc(ptr, size); #if OPAL_ENABLE_DEBUG if (opal_malloc_debug_level > 0) { if (NULL == addr) { - opal_output(opal_malloc_output, - "Realloc %p for %ld bytes failed (%s, %d)", - ptr, (long) size, file, line); + opal_output(opal_malloc_output, "Realloc %p for %ld bytes failed (%s, %d)", ptr, + (long) size, file, line); } } -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ return addr; } - /* * Debug version of free */ @@ -196,5 +186,5 @@ void opal_malloc_debug(int level) { #if OPAL_ENABLE_DEBUG opal_malloc_debug_level = level; -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ } diff --git a/opal/util/malloc.h b/opal/util/malloc.h index 26f9cf5e2be..5ff79c57a32 100644 --- a/opal/util/malloc.h +++ b/opal/util/malloc.h @@ -43,87 +43,90 @@ */ #ifndef OPAL_MALLOC_DEBUG_LEVEL -#define OPAL_MALLOC_DEBUG_LEVEL 2 +# define OPAL_MALLOC_DEBUG_LEVEL 2 #endif BEGIN_C_DECLS - /** - * Initialize malloc debug output. - * - * This function is invoked to setup a dedicated output stream for - * malloc debug functions. It does \em not (currently) do anything - * other than that (i.e., no internal accounting for tracking - * malloc/free statements, etc.). - * - * It is invoked as part of opal_init(). Although this function is - * not \em necessary for OPAL_MALLOC() and OPAL_FREE(), it is strong - * recommended because no output messages -- regardless of the - * malloc debug level set by opal_malloc_debug() -- will be displayed - * unless this function is invoked first. - */ +/** + * Initialize malloc debug output. + * + * This function is invoked to setup a dedicated output stream for + * malloc debug functions. It does \em not (currently) do anything + * other than that (i.e., no internal accounting for tracking + * malloc/free statements, etc.). + * + * It is invoked as part of opal_init(). Although this function is + * not \em necessary for OPAL_MALLOC() and OPAL_FREE(), it is strong + * recommended because no output messages -- regardless of the + * malloc debug level set by opal_malloc_debug() -- will be displayed + * unless this function is invoked first. + */ void opal_malloc_init(void); - /** - * \internal - * - * Back-end error-checking malloc function for OPAL (you should use - * the normal malloc() instead of this function). - * - * @param size The number of bytes to allocate - * @param file Typically the __FILE__ macro - * @param line Typically the __LINE__ macro - * - * This function is only used when --enable-mem-debug was specified to - * configure (or by default if you're building in a SVN checkout). - */ -OPAL_DECLSPEC void *opal_malloc(size_t size, const char *file, int line) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * \internal + * + * Back-end error-checking malloc function for OPAL (you should use + * the normal malloc() instead of this function). + * + * @param size The number of bytes to allocate + * @param file Typically the __FILE__ macro + * @param line Typically the __LINE__ macro + * + * This function is only used when --enable-mem-debug was specified to + * configure (or by default if you're building in a SVN checkout). + */ +OPAL_DECLSPEC void *opal_malloc(size_t size, const char *file, int line) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * \internal - * - * Back-end error-checking calloc function for OPAL (you should use - * the normal calloc() instead of this function). - * - * @param nmembers Number of elements to malloc - * @param size Size of each elements - * @param file Typically the __FILE__ macro - * @param line Typically the __LINE__ macro - * - * This function is only used when --enable-mem-debug was specified to - * configure (or by default if you're building in a SVN checkout). - */ -OPAL_DECLSPEC void *opal_calloc(size_t nmembers, size_t size, const char *file, int line) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * \internal + * + * Back-end error-checking calloc function for OPAL (you should use + * the normal calloc() instead of this function). + * + * @param nmembers Number of elements to malloc + * @param size Size of each elements + * @param file Typically the __FILE__ macro + * @param line Typically the __LINE__ macro + * + * This function is only used when --enable-mem-debug was specified to + * configure (or by default if you're building in a SVN checkout). + */ +OPAL_DECLSPEC void *opal_calloc(size_t nmembers, size_t size, const char *file, int line) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * \internal - * - * Back-end error-checking realloc function for OPAL (you should use - * the normal realloc() instead of this function). - * - * @param ptr Pointer to reallocate - * @param size The number of bytes to allocate - * @param file Typically the __FILE__ macro - * @param line Typically the __LINE__ macro - * - * This function is only used when --enable-mem-debug was specified to - * configure (or by default if you're building in a SVN checkout). - */ -OPAL_DECLSPEC void *opal_realloc(void *ptr, size_t size, const char *file, int line) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +/** + * \internal + * + * Back-end error-checking realloc function for OPAL (you should use + * the normal realloc() instead of this function). + * + * @param ptr Pointer to reallocate + * @param size The number of bytes to allocate + * @param file Typically the __FILE__ macro + * @param line Typically the __LINE__ macro + * + * This function is only used when --enable-mem-debug was specified to + * configure (or by default if you're building in a SVN checkout). + */ +OPAL_DECLSPEC void *opal_realloc(void *ptr, size_t size, const char *file, int line) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - /** - * \internal - * - * Back-end error-checking free function for OPAL (you should use - * free() instead of this function). - * - * @param addr Address on the heap to free() - * @param file Typically the __FILE__ macro - * @param line Typically the __LINE__ macro - * - * This function is only used when --enable-mem-debug was specified - * to configure (or by default if you're building in a SVN - * checkout). - */ +/** + * \internal + * + * Back-end error-checking free function for OPAL (you should use + * free() instead of this function). + * + * @param addr Address on the heap to free() + * @param file Typically the __FILE__ macro + * @param line Typically the __LINE__ macro + * + * This function is only used when --enable-mem-debug was specified + * to configure (or by default if you're building in a SVN + * checkout). + */ OPAL_DECLSPEC void opal_free(void *addr, const char *file, int line) __opal_attribute_nonnull__(1); /** diff --git a/opal/util/minmax.h b/opal/util/minmax.h index d56a7c39311..d483cd7adbc 100644 --- a/opal/util/minmax.h +++ b/opal/util/minmax.h @@ -16,14 +16,14 @@ #ifndef OPAL_MINMAX_H #define OPAL_MINMAX_H -#define OPAL_DEFINE_MINMAX(type, suffix) \ - static inline const type opal_min_##suffix(const type a, const type b) \ - { \ - return (a < b) ? a : b; \ - } \ - static inline const type opal_max_##suffix(const type a, const type b) \ - { \ - return (a > b) ? a : b; \ +#define OPAL_DEFINE_MINMAX(type, suffix) \ + static inline const type opal_min_##suffix(const type a, const type b) \ + { \ + return (a < b) ? a : b; \ + } \ + static inline const type opal_max_##suffix(const type a, const type b) \ + { \ + return (a > b) ? a : b; \ } OPAL_DEFINE_MINMAX(int8_t, 8) @@ -41,8 +41,8 @@ OPAL_DEFINE_MINMAX(double, double) OPAL_DEFINE_MINMAX(void *, ptr) #if OPAL_C_HAVE__GENERIC -#define opal_min(a, b) \ - (_Generic((a) + (b), \ +# define opal_min(a, b) \ + (_Generic((a) + (b), \ int8_t: opal_min_8, \ uint8_t: opal_min_u8, \ int16_t: opal_min_16, \ @@ -56,8 +56,8 @@ OPAL_DEFINE_MINMAX(void *, ptr) void *: opal_min_ptr, \ default: opal_min_64)((a), (b))) -#define opal_max(a, b) \ - (_Generic((a) + (b), \ +# define opal_max(a, b) \ + (_Generic((a) + (b), \ int8_t: opal_max_8, \ uint8_t: opal_max_u8, \ int16_t: opal_max_16, \ @@ -74,8 +74,8 @@ OPAL_DEFINE_MINMAX(void *, ptr) /* these versions suffer from double-evaluation. please upgrade to a modern compiler */ -#define opal_min(a, b) (((a) < (b)) ? (a) : (b)) -#define opal_max(a, b) (((a) > (b)) ? (a) : (b)) +# define opal_min(a, b) (((a) < (b)) ? (a) : (b)) +# define opal_max(a, b) (((a) > (b)) ? (a) : (b)) #endif diff --git a/opal/util/net.c b/opal/util/net.c index 7c16d03d5d7..65b9fa30f0e 100644 --- a/opal/util/net.c +++ b/opal/util/net.c @@ -32,45 +32,45 @@ #include #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_SYS_SOCKIO_H -#include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif #ifdef HAVE_ARPA_INET_H -#include +# include #endif #ifdef HAVE_NET_IF_H -#include +# include #endif #ifdef HAVE_NETDB_H -#include +# include #endif #ifdef HAVE_IFADDRS_H -#include +# include #endif +#include "opal/constants.h" +#include "opal/mca/threads/tsd.h" #include "opal/runtime/opal.h" +#include "opal/runtime/opal_params.h" +#include "opal/util/argv.h" #include "opal/util/net.h" #include "opal/util/output.h" -#include "opal/util/argv.h" #include "opal/util/show_help.h" -#include "opal/constants.h" -#include "opal/mca/threads/tsd.h" -#include "opal/runtime/opal_params.h" /* this function doesn't depend on sockaddr_h */ bool opal_net_isaddr(const char *name) @@ -102,36 +102,34 @@ typedef struct private_ipv4_t { uint32_t netmask_bits; } private_ipv4_t; -static private_ipv4_t* private_ipv4 = NULL; +static private_ipv4_t *private_ipv4 = NULL; -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 static opal_tsd_tracked_key_t *hostname_tsd_key = NULL; - -static void -hostname_cleanup(void *value) +static void hostname_cleanup(void *value) { - if (NULL != value) free(value); + if (NULL != value) + free(value); } - -static char* -get_hostname_buffer(void) +static char *get_hostname_buffer(void) { void *buffer; int ret; ret = opal_tsd_tracked_key_get(hostname_tsd_key, &buffer); - if (OPAL_SUCCESS != ret) return NULL; + if (OPAL_SUCCESS != ret) + return NULL; if (NULL == buffer) { - buffer = (void*) malloc((NI_MAXHOST + 1) * sizeof(char)); + buffer = (void *) malloc((NI_MAXHOST + 1) * sizeof(char)); ret = opal_tsd_tracked_key_set(hostname_tsd_key, buffer); } - return (char*) buffer; + return (char *) buffer; } -#endif +# endif /** * Finalize the network helper subsystem @@ -142,45 +140,42 @@ get_hostname_buffer(void) * * @retval OPAL_SUCCESS Success */ -static void opal_net_finalize (void) +static void opal_net_finalize(void) { -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 if (NULL != hostname_tsd_key) { OBJ_RELEASE(hostname_tsd_key); hostname_tsd_key = NULL; } -#endif +# endif free(private_ipv4); private_ipv4 = NULL; } -int -opal_net_init(void) +int opal_net_init(void) { char **args, *arg; uint32_t a, b, c, d, bits, addr; int i, count, found_bad = 0; - args = opal_argv_split( opal_net_private_ipv4, ';' ); - if( NULL != args ) { + args = opal_argv_split(opal_net_private_ipv4, ';'); + if (NULL != args) { count = opal_argv_count(args); - private_ipv4 = (private_ipv4_t*)malloc( (count + 1) * sizeof(private_ipv4_t)); - if( NULL == private_ipv4 ) { - opal_output(0, "Unable to allocate memory for the private addresses array" ); + private_ipv4 = (private_ipv4_t *) malloc((count + 1) * sizeof(private_ipv4_t)); + if (NULL == private_ipv4) { + opal_output(0, "Unable to allocate memory for the private addresses array"); opal_argv_free(args); goto do_local_init; } - for( i = 0; i < count; i++ ) { + for (i = 0; i < count; i++) { arg = args[i]; - (void)sscanf( arg, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &bits ); + (void) sscanf(arg, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &bits); - if( (a > 255) || (b > 255) || (c > 255) || - (d > 255) || (bits > 32) ) { + if ((a > 255) || (b > 255) || (c > 255) || (d > 255) || (bits > 32)) { if (0 == found_bad) { - opal_show_help("help-opal-util.txt", - "malformed net_private_ipv4", - true, args[i]); + opal_show_help("help-opal-util.txt", "malformed net_private_ipv4", true, + args[i]); found_bad = 1; } continue; @@ -189,208 +184,182 @@ opal_net_init(void) private_ipv4[i].addr = htonl(addr); private_ipv4[i].netmask_bits = bits; } - private_ipv4[i].addr = 0; + private_ipv4[i].addr = 0; private_ipv4[i].netmask_bits = 0; opal_argv_free(args); } - opal_finalize_register_cleanup (opal_net_finalize); + opal_finalize_register_cleanup(opal_net_finalize); - do_local_init: -#if OPAL_ENABLE_IPV6 +do_local_init: +# if OPAL_ENABLE_IPV6 hostname_tsd_key = OBJ_NEW(opal_tsd_tracked_key_t); opal_tsd_tracked_key_set_destructor(hostname_tsd_key, hostname_cleanup); -#endif +# endif return OPAL_SUCCESS; } /* convert a CIDR prefixlen to netmask (in network byte order) */ -uint32_t -opal_net_prefix2netmask(uint32_t prefixlen) +uint32_t opal_net_prefix2netmask(uint32_t prefixlen) { - return htonl (((1u << prefixlen) - 1u) << (32 - prefixlen)); + return htonl(((1u << prefixlen) - 1u) << (32 - prefixlen)); } - -bool -opal_net_islocalhost(const struct sockaddr *addr) +bool opal_net_islocalhost(const struct sockaddr *addr) { switch (addr->sa_family) { - case AF_INET: - { - const struct sockaddr_in *inaddr = (struct sockaddr_in*) addr; - /* if it's in the 127. domain, it shouldn't be routed - (0x7f == 127) */ - if (0x7F000000 == (0x7F000000 & ntohl(inaddr->sin_addr.s_addr))) { - return true; - } - return false; + case AF_INET: { + const struct sockaddr_in *inaddr = (struct sockaddr_in *) addr; + /* if it's in the 127. domain, it shouldn't be routed + (0x7f == 127) */ + if (0x7F000000 == (0x7F000000 & ntohl(inaddr->sin_addr.s_addr))) { + return true; } - break; -#if OPAL_ENABLE_IPV6 - case AF_INET6: - { - const struct sockaddr_in6 *inaddr = (struct sockaddr_in6*) addr; - if (IN6_IS_ADDR_LOOPBACK (&inaddr->sin6_addr)) { - return true; /* Bug, FIXME: check for 127.0.0.1/8 */ - } - return false; + return false; + } break; +# if OPAL_ENABLE_IPV6 + case AF_INET6: { + const struct sockaddr_in6 *inaddr = (struct sockaddr_in6 *) addr; + if (IN6_IS_ADDR_LOOPBACK(&inaddr->sin6_addr)) { + return true; /* Bug, FIXME: check for 127.0.0.1/8 */ } - break; -#endif + return false; + } break; +# endif default: - opal_output(0, "unhandled sa_family %d passed to opal_net_islocalhost", - addr->sa_family); + opal_output(0, "unhandled sa_family %d passed to opal_net_islocalhost", addr->sa_family); return false; break; } } - -bool -opal_net_samenetwork(const struct sockaddr *addr1, - const struct sockaddr *addr2, - uint32_t plen) +bool opal_net_samenetwork(const struct sockaddr *addr1, const struct sockaddr *addr2, uint32_t plen) { uint32_t prefixlen; - if(addr1->sa_family != addr2->sa_family) { + if (addr1->sa_family != addr2->sa_family) { return false; /* address families must be equal */ } switch (addr1->sa_family) { - case AF_INET: - { - if (0 == plen) { - prefixlen = 32; - } else { - prefixlen = plen; - } - struct sockaddr_in inaddr1, inaddr2; - /* Use temporary variables and memcpy's so that we don't - run into bus errors on Solaris/SPARC */ - memcpy(&inaddr1, addr1, sizeof(inaddr1)); - memcpy(&inaddr2, addr2, sizeof(inaddr2)); - uint32_t netmask = opal_net_prefix2netmask (prefixlen); - - if((inaddr1.sin_addr.s_addr & netmask) == - (inaddr2.sin_addr.s_addr & netmask)) { + case AF_INET: { + if (0 == plen) { + prefixlen = 32; + } else { + prefixlen = plen; + } + struct sockaddr_in inaddr1, inaddr2; + /* Use temporary variables and memcpy's so that we don't + run into bus errors on Solaris/SPARC */ + memcpy(&inaddr1, addr1, sizeof(inaddr1)); + memcpy(&inaddr2, addr2, sizeof(inaddr2)); + uint32_t netmask = opal_net_prefix2netmask(prefixlen); + + if ((inaddr1.sin_addr.s_addr & netmask) == (inaddr2.sin_addr.s_addr & netmask)) { + return true; + } + return false; + } break; +# if OPAL_ENABLE_IPV6 + case AF_INET6: { + struct sockaddr_in6 inaddr1, inaddr2; + /* Use temporary variables and memcpy's so that we don't + run into bus errors on Solaris/SPARC */ + memcpy(&inaddr1, addr1, sizeof(inaddr1)); + memcpy(&inaddr2, addr2, sizeof(inaddr2)); + struct in6_addr *a6_1 = (struct in6_addr *) &inaddr1.sin6_addr; + struct in6_addr *a6_2 = (struct in6_addr *) &inaddr2.sin6_addr; + + if (0 == plen) { + prefixlen = 64; + } else { + prefixlen = plen; + } + if (64 == prefixlen) { + /* prefixlen is always /64, any other case would be routing. + Compare the first eight bytes (64 bits) and hope that + endianess is not an issue on any system as long as + addresses are always stored in network byte order. + */ + if (((const uint32_t *) (a6_1))[0] == ((const uint32_t *) (a6_2))[0] + && ((const uint32_t *) (a6_1))[1] == ((const uint32_t *) (a6_2))[1]) { return true; } - return false; } - break; -#if OPAL_ENABLE_IPV6 - case AF_INET6: - { - struct sockaddr_in6 inaddr1, inaddr2; - /* Use temporary variables and memcpy's so that we don't - run into bus errors on Solaris/SPARC */ - memcpy(&inaddr1, addr1, sizeof(inaddr1)); - memcpy(&inaddr2, addr2, sizeof(inaddr2)); - struct in6_addr *a6_1 = (struct in6_addr*) &inaddr1.sin6_addr; - struct in6_addr *a6_2 = (struct in6_addr*) &inaddr2.sin6_addr; - - if (0 == plen) { - prefixlen = 64; - } else { - prefixlen = plen; - } - if (64 == prefixlen) { - /* prefixlen is always /64, any other case would be routing. - Compare the first eight bytes (64 bits) and hope that - endianess is not an issue on any system as long as - addresses are always stored in network byte order. - */ - if (((const uint32_t *) (a6_1))[0] == - ((const uint32_t *) (a6_2))[0] && - ((const uint32_t *) (a6_1))[1] == - ((const uint32_t *) (a6_2))[1]) { - return true; - } - } - return false; - } - break; -#endif + return false; + } break; +# endif default: - opal_output(0, "unhandled sa_family %d passed to opal_samenetwork", - addr1->sa_family); + opal_output(0, "unhandled sa_family %d passed to opal_samenetwork", addr1->sa_family); } return false; } - /** * Returns true if the given address is a public IPv4 address. */ -bool -opal_net_addr_isipv4public(const struct sockaddr *addr) +bool opal_net_addr_isipv4public(const struct sockaddr *addr) { switch (addr->sa_family) { -#if OPAL_ENABLE_IPV6 - case AF_INET6: - return false; -#endif - case AF_INET: - { - const struct sockaddr_in *inaddr = (struct sockaddr_in*) addr; - int i; - - if( NULL == private_ipv4 ) { - return true; - } +# if OPAL_ENABLE_IPV6 + case AF_INET6: + return false; +# endif + case AF_INET: { + const struct sockaddr_in *inaddr = (struct sockaddr_in *) addr; + int i; - for( i = 0; private_ipv4[i].addr != 0; i++ ) { - if( private_ipv4[i].addr == (inaddr->sin_addr.s_addr & - opal_net_prefix2netmask(private_ipv4[i].netmask_bits)) ) - return false; - } + if (NULL == private_ipv4) { + return true; + } + for (i = 0; private_ipv4[i].addr != 0; i++) { + if (private_ipv4[i].addr + == (inaddr->sin_addr.s_addr + & opal_net_prefix2netmask(private_ipv4[i].netmask_bits))) { + return false; } - return true; - default: - opal_output (0, - "unhandled sa_family %d passed to opal_net_addr_isipv4public\n", - addr->sa_family); + } + } + return true; + default: + opal_output(0, "unhandled sa_family %d passed to opal_net_addr_isipv4public\n", + addr->sa_family); } return false; } -bool -opal_net_addr_isipv6linklocal(const struct sockaddr *addr) +bool opal_net_addr_isipv6linklocal(const struct sockaddr *addr) { -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 struct sockaddr_in6 if_addr; -#endif +# endif switch (addr->sa_family) { -#if OPAL_ENABLE_IPV6 - case AF_INET6: - if_addr.sin6_family = AF_INET6; - if (1 != inet_pton(AF_INET6, "fe80::0000", &if_addr.sin6_addr)) { - return false; - } - return opal_net_samenetwork(addr, (struct sockaddr*)&if_addr, 64); -#endif - case AF_INET: +# if OPAL_ENABLE_IPV6 + case AF_INET6: + if_addr.sin6_family = AF_INET6; + if (1 != inet_pton(AF_INET6, "fe80::0000", &if_addr.sin6_addr)) { return false; - default: - opal_output (0, - "unhandled sa_family %d passed to opal_net_addr_isipv6linklocal\n", - addr->sa_family); + } + return opal_net_samenetwork(addr, (struct sockaddr *) &if_addr, 64); +# endif + case AF_INET: + return false; + default: + opal_output(0, "unhandled sa_family %d passed to opal_net_addr_isipv6linklocal\n", + addr->sa_family); } return false; } -char* -opal_net_get_hostname(const struct sockaddr *addr) +char *opal_net_get_hostname(const struct sockaddr *addr) { -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 char *name = get_hostname_buffer(); int error; socklen_t addrlen; @@ -404,119 +373,98 @@ opal_net_get_hostname(const struct sockaddr *addr) switch (addr->sa_family) { case AF_INET: - addrlen = sizeof (struct sockaddr_in); + addrlen = sizeof(struct sockaddr_in); break; case AF_INET6: -#if defined( __NetBSD__) +# if defined(__NetBSD__) /* hotfix for netbsd: on my netbsd machine, getnameinfo returns an unkown error code. */ - if(NULL == inet_ntop(AF_INET6, &((struct sockaddr_in6*) addr)->sin6_addr, - name, NI_MAXHOST)) { + if (NULL + == inet_ntop(AF_INET6, &((struct sockaddr_in6 *) addr)->sin6_addr, name, NI_MAXHOST)) { opal_output(0, "opal_sockaddr2str failed with error code %d", errno); return NULL; } return name; -#else - addrlen = sizeof (struct sockaddr_in6); -#endif +# else + addrlen = sizeof(struct sockaddr_in6); +# endif break; default: return NULL; } - error = getnameinfo(addr, addrlen, - name, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); + error = getnameinfo(addr, addrlen, name, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (error) { - int err = errno; - opal_output (0, "opal_sockaddr2str failed:%s (return code %i)\n", - gai_strerror(err), error); - return NULL; + int err = errno; + opal_output(0, "opal_sockaddr2str failed:%s (return code %i)\n", gai_strerror(err), error); + return NULL; } /* strip any trailing % data as it isn't pertinent */ if (NULL != (p = strrchr(name, '%'))) { *p = '\0'; } return name; -#else - return inet_ntoa(((struct sockaddr_in*) addr)->sin_addr); -#endif +# else + return inet_ntoa(((struct sockaddr_in *) addr)->sin_addr); +# endif } - -int -opal_net_get_port(const struct sockaddr *addr) +int opal_net_get_port(const struct sockaddr *addr) { switch (addr->sa_family) { case AF_INET: - return ntohs(((struct sockaddr_in*) addr)->sin_port); + return ntohs(((struct sockaddr_in *) addr)->sin_port); break; -#if OPAL_ENABLE_IPV6 +# if OPAL_ENABLE_IPV6 case AF_INET6: - return ntohs(((struct sockaddr_in6*) addr)->sin6_port); + return ntohs(((struct sockaddr_in6 *) addr)->sin6_port); break; -#endif +# endif } return -1; } - #else /* HAVE_STRUCT_SOCKADDR_IN */ -int -opal_net_init() +int opal_net_init() { return OPAL_SUCCESS; } - -int -opal_net_finalize() +int opal_net_finalize() { return OPAL_SUCCESS; } - -uint32_t -opal_net_prefix2netmask(uint32_t prefixlen) +uint32_t opal_net_prefix2netmask(uint32_t prefixlen) { return 0; } - -bool -opal_net_islocalhost(const struct sockaddr *addr) +bool opal_net_islocalhost(const struct sockaddr *addr) { return false; } - -bool -opal_net_samenetwork(const struct sockaddr *addr1, - const struct sockaddr *addr2, - uint32_t prefixlen) +bool opal_net_samenetwork(const struct sockaddr *addr1, const struct sockaddr *addr2, + uint32_t prefixlen) { return false; } - -bool -opal_net_addr_isipv4public(const struct sockaddr *addr) +bool opal_net_addr_isipv4public(const struct sockaddr *addr) { return false; } - -char* -opal_net_get_hostname(const struct sockaddr *addr) +char *opal_net_get_hostname(const struct sockaddr *addr) { return NULL; } - -int -opal_net_get_port(const struct sockaddr *addr) +int opal_net_get_port(const struct sockaddr *addr) { return -1; } diff --git a/opal/util/net.h b/opal/util/net.h index f880b9e4da9..3d296bc0791 100644 --- a/opal/util/net.h +++ b/opal/util/net.h @@ -29,13 +29,13 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif #ifdef HAVE_NETINET_IN_H -#include +# include #endif BEGIN_C_DECLS @@ -61,7 +61,6 @@ OPAL_DECLSPEC int opal_net_init(void); */ OPAL_DECLSPEC uint32_t opal_net_prefix2netmask(uint32_t prefixlen); - /** * Determine if given IP address is in the localhost range * @@ -75,7 +74,6 @@ OPAL_DECLSPEC uint32_t opal_net_prefix2netmask(uint32_t prefixlen); */ OPAL_DECLSPEC bool opal_net_islocalhost(const struct sockaddr *addr); - /** * Are we on the same network? * @@ -88,11 +86,9 @@ OPAL_DECLSPEC bool opal_net_islocalhost(const struct sockaddr *addr); * @return true if \c addr1 and \c addr2 are on the * same net, false otherwise. */ -OPAL_DECLSPEC bool opal_net_samenetwork(const struct sockaddr *addr1, - const struct sockaddr *addr2, +OPAL_DECLSPEC bool opal_net_samenetwork(const struct sockaddr *addr1, const struct sockaddr *addr2, uint32_t prefixlen); - /** * Is the given address a public IPv4 address? Returns false for IPv6 * address. @@ -121,8 +117,7 @@ OPAL_DECLSPEC bool opal_net_addr_isipv6linklocal(const struct sockaddr *addr); * @param addr struct sockaddr of address * @return literal representation of \c addr */ -OPAL_DECLSPEC char* opal_net_get_hostname(const struct sockaddr *addr); - +OPAL_DECLSPEC char *opal_net_get_hostname(const struct sockaddr *addr); /** * Get port number from struct sockaddr diff --git a/opal/util/numtostr.c b/opal/util/numtostr.c index 349378b286a..c937b5b1fdb 100644 --- a/opal/util/numtostr.c +++ b/opal/util/numtostr.c @@ -22,17 +22,17 @@ #include #include - -char* -opal_ltostr(long num) +char *opal_ltostr(long num) { /* waste a little bit of space, but always have a big enough buffer */ int buflen = sizeof(long) * 8; char *buf = NULL; int ret = 0; - buf = (char*) malloc(sizeof(char) * buflen); - if (NULL == buf) return NULL; + buf = (char *) malloc(sizeof(char) * buflen); + if (NULL == buf) { + return NULL; + } ret = snprintf(buf, buflen, "%ld", num); if (ret < 0) { @@ -43,17 +43,17 @@ opal_ltostr(long num) return buf; } - -char* -opal_dtostr(double num) +char *opal_dtostr(double num) { /* waste a little bit of space, but always have a big enough buffer */ int buflen = sizeof(long) * 8; char *buf = NULL; int ret = 0; - buf = (char*) malloc(sizeof(char) * buflen); - if (NULL == buf) return NULL; + buf = (char *) malloc(sizeof(char) * buflen); + if (NULL == buf) { + return NULL; + } ret = snprintf(buf, buflen, "%f", num); if (ret < 0) { diff --git a/opal/util/numtostr.h b/opal/util/numtostr.h index c2e517f9fd0..5e754eaf0fb 100644 --- a/opal/util/numtostr.h +++ b/opal/util/numtostr.h @@ -30,8 +30,7 @@ * @param num (IN) Input number * @return String containing number (NULL on failure) */ -OPAL_DECLSPEC char* opal_ltostr(long num); - +OPAL_DECLSPEC char *opal_ltostr(long num); /** * Convert a double to a char* string. The returned buffer is allocated @@ -40,6 +39,6 @@ OPAL_DECLSPEC char* opal_ltostr(long num); * @param num (IN) Input number * @return String containing number (NULL on failure) */ -OPAL_DECLSPEC char* opal_dtostr(double num); +OPAL_DECLSPEC char *opal_dtostr(double num); #endif /* OPAL_NUMTOSTR_UTIL */ diff --git a/opal/util/opal_environ.c b/opal/util/opal_environ.c index 5f01756bcfb..19f556bdf8d 100644 --- a/opal/util/opal_environ.c +++ b/opal/util/opal_environ.c @@ -27,10 +27,10 @@ #include #include -#include "opal/util/printf.h" +#include "opal/constants.h" #include "opal/util/argv.h" #include "opal/util/opal_environ.h" -#include "opal/constants.h" +#include "opal/util/printf.h" #define OPAL_DEFAULT_TMPDIR "/tmp" @@ -92,8 +92,7 @@ char **opal_environ_merge(char **minor, char **major) * Portable version of setenv(), allowing editing of any environ-like * array */ -int opal_setenv(const char *name, const char *value, bool overwrite, - char ***env) +int opal_setenv(const char *name, const char *value, bool overwrite, char ***env) { int i; char *newvalue, *compare; @@ -113,7 +112,7 @@ int opal_setenv(const char *name, const char *value, bool overwrite, /* Check the bozo case */ - if( NULL == env ) { + if (NULL == env) { return OPAL_ERR_BAD_PARAM; } else if (NULL == *env) { i = 0; @@ -123,13 +122,13 @@ int opal_setenv(const char *name, const char *value, bool overwrite, } /* If this is the "environ" array, use putenv */ - if( *env == environ ) { + if (*env == environ) { /* THIS IS POTENTIALLY A MEMORY LEAK! But I am doing it so that we don't violate the law of least astonishment for OPAL developers (i.e., those that don't check the return code of opal_setenv() and notice that we returned an error if you passed in the real environ) */ -#if defined (HAVE_SETENV) +#if defined(HAVE_SETENV) setenv(name, value, overwrite); /* setenv copies the value, so we can free it here */ free(newvalue); @@ -199,7 +198,6 @@ int opal_setenv(const char *name, const char *value, bool overwrite, return OPAL_SUCCESS; } - /* * Portable version of unsetenv(), allowing editing of any * environ-like array @@ -231,13 +229,15 @@ int opal_unsetenv(const char *name, char ***env) found = false; for (i = 0; (*env)[i] != NULL; ++i) { - if (0 != strncmp((*env)[i], compare, len)) + if (0 != strncmp((*env)[i], compare, len)) { continue; + } if (environ != *env) { free((*env)[i]); } - for (; (*env)[i] != NULL; ++i) + for (; (*env)[i] != NULL; ++i) { (*env)[i] = (*env)[i + 1]; + } found = true; break; } @@ -248,21 +248,23 @@ int opal_unsetenv(const char *name, char ***env) return (found) ? OPAL_SUCCESS : OPAL_ERR_NOT_FOUND; } -const char* opal_tmp_directory( void ) +const char *opal_tmp_directory(void) { - const char* str; + const char *str; - if( NULL == (str = getenv("TMPDIR")) ) - if( NULL == (str = getenv("TEMP")) ) - if( NULL == (str = getenv("TMP")) ) + if (NULL == (str = getenv("TMPDIR"))) { + if (NULL == (str = getenv("TEMP"))) { + if (NULL == (str = getenv("TMP"))) { str = OPAL_DEFAULT_TMPDIR; + } + } + } return str; } -const char* opal_home_directory( void ) +const char *opal_home_directory(void) { - char* home = getenv("HOME"); + char *home = getenv("HOME"); return home; } - diff --git a/opal/util/opal_environ.h b/opal/util/opal_environ.h index f7dac6adfe4..69dfc09ddd8 100644 --- a/opal/util/opal_environ.h +++ b/opal/util/opal_environ.h @@ -30,7 +30,7 @@ #include "opal_config.h" #ifdef HAVE_CRT_EXTERNS_H -#include +# include #endif BEGIN_C_DECLS @@ -58,7 +58,8 @@ BEGIN_C_DECLS * one of the two is NULL, the other list is simply copied to the * output. If both are NULL, NULL is returned. */ -OPAL_DECLSPEC char **opal_environ_merge(char **minor, char **major) __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char **opal_environ_merge(char **minor, + char **major) __opal_attribute_warn_unused_result__; /** * Portable version of setenv(3), allowing editing of any @@ -106,8 +107,8 @@ OPAL_DECLSPEC char **opal_environ_merge(char **minor, char **major) __opal_attri * opal_setenv("foo", "bar", true, &my_env); * \endcode */ -OPAL_DECLSPEC int opal_setenv(const char *name, const char *value, - bool overwrite, char ***env) __opal_attribute_nonnull__(1); +OPAL_DECLSPEC int opal_setenv(const char *name, const char *value, bool overwrite, char ***env) + __opal_attribute_nonnull__(1); /** * Portable version of unsetenv(3), allowing editing of any @@ -128,13 +129,13 @@ OPAL_DECLSPEC int opal_unsetenv(const char *name, char ***env) __opal_attribute_ /* A consistent way to retrieve the home and tmp directory on all supported * platforms. */ -OPAL_DECLSPEC const char* opal_home_directory( void ); -OPAL_DECLSPEC const char* opal_tmp_directory( void ); +OPAL_DECLSPEC const char *opal_home_directory(void); +OPAL_DECLSPEC const char *opal_tmp_directory(void); /* Some care is needed with environ on OS X when dealing with shared libraries. Handle that care here... */ #ifdef HAVE__NSGETENVIRON -#define environ (*_NSGetEnviron()) +# define environ (*_NSGetEnviron()) #else OPAL_DECLSPEC extern char **environ; #endif diff --git a/opal/util/opal_getcwd.c b/opal/util/opal_getcwd.c index 4ac08300e19..da484e3eec0 100644 --- a/opal/util/opal_getcwd.c +++ b/opal/util/opal_getcwd.c @@ -12,21 +12,20 @@ #include #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_STAT_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #include +#include "opal/constants.h" #include "opal/util/basename.h" #include "opal/util/opal_getcwd.h" #include "opal/util/string_copy.h" -#include "opal/constants.h" - /* * Use $PWD instead of getcwd() a) if $PWD exists and b) is a valid diff --git a/opal/util/opal_getcwd.h b/opal/util/opal_getcwd.h index 1d5533190a5..64e4c8f01ed 100644 --- a/opal/util/opal_getcwd.h +++ b/opal/util/opal_getcwd.h @@ -44,7 +44,6 @@ BEGIN_C_DECLS */ OPAL_DECLSPEC int opal_getcwd(char *buf, size_t size); - END_C_DECLS #endif /* OPAL_GETCWD_H */ diff --git a/opal/util/opal_pty.c b/opal/util/opal_pty.c index 9c70ecc6683..608b203c62c 100644 --- a/opal/util/opal_pty.c +++ b/opal/util/opal_pty.c @@ -48,50 +48,50 @@ #include "opal_config.h" #ifdef HAVE_SYS_CDEFS_H -# include +# include #endif #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #include #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_FCNTL_H -#include +# include #endif #ifdef HAVE_TERMIOS_H -# include +# include #else -# ifdef HAVE_TERMIO_H -# include -# endif +# ifdef HAVE_TERMIO_H +# include +# endif #endif #include #ifdef HAVE_UNISTD_H -# include +# include #endif #include -# include +#include #ifdef HAVE_GRP_H -#include +# include #endif #ifdef HAVE_PTY_H -#include +# include #endif #ifdef HAVE_UTMP_H -#include +# include #endif #ifdef HAVE_PTSNAME -# include -# ifdef HAVE_STROPTS_H -# include -# endif +# include +# ifdef HAVE_STROPTS_H +# include +# endif #endif #ifdef HAVE_UTIL_H -#include +# include #endif #include "opal/util/opal_pty.h" @@ -101,16 +101,14 @@ #if OPAL_ENABLE_PTY_SUPPORT == 0 -int opal_openpty(int *amaster, int *aslave, char *name, - void *termp, void *winpp) +int opal_openpty(int *amaster, int *aslave, char *name, void *termp, void *winpp) { return -1; } #elif defined(HAVE_OPENPTY) -int opal_openpty(int *amaster, int *aslave, char *name, - struct termios *termp, struct winsize *winp) +int opal_openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) { return openpty(amaster, aslave, name, termp, winp); } @@ -122,8 +120,7 @@ int opal_openpty(int *amaster, int *aslave, char *name, static int ptym_open(char *pts_name); static int ptys_open(int fdm, char *pts_name); -int opal_openpty(int *amaster, int *aslave, char *name, - struct termios *termp, struct winsize *winp) +int opal_openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) { char line[20]; *amaster = ptym_open(line); @@ -140,52 +137,51 @@ int opal_openpty(int *amaster, int *aslave, char *name, // max length of the source, so at least use that. opal_string_copy(name, line, sizeof(line)); } -#ifndef TCSAFLUSH -#define TCSAFLUSH TCSETAF -#endif +# ifndef TCSAFLUSH +# define TCSAFLUSH TCSETAF +# endif if (termp) { (void) tcsetattr(*aslave, TCSAFLUSH, termp); } -#ifdef TIOCSWINSZ +# ifdef TIOCSWINSZ if (winp) { (void) ioctl(*aslave, TIOCSWINSZ, (char *) winp); } -#endif +# endif return 0; } - static int ptym_open(char *pts_name) { int fdm; -#ifdef HAVE_PTSNAME +# ifdef HAVE_PTSNAME char *ptr; -#ifdef _AIX +# ifdef _AIX strcpy(pts_name, "/dev/ptc"); -#else +# else strcpy(pts_name, "/dev/ptmx"); -#endif +# endif fdm = open(pts_name, O_RDWR); if (fdm < 0) { return -1; } - if (grantpt(fdm) < 0) { /* grant access to slave */ + if (grantpt(fdm) < 0) { /* grant access to slave */ close(fdm); return -2; } - if (unlockpt(fdm) < 0) { /* clear slave's lock flag */ + if (unlockpt(fdm) < 0) { /* clear slave's lock flag */ close(fdm); return -3; } ptr = ptsname(fdm); - if (ptr == NULL) { /* get slave's name */ + if (ptr == NULL) { /* get slave's name */ close(fdm); return -4; } - strcpy(pts_name, ptr); /* return name of slave */ - return fdm; /* return fd of master */ -#else + strcpy(pts_name, ptr); /* return name of slave */ + return fdm; /* return fd of master */ +# else char *ptr1, *ptr2; strcpy(pts_name, "/dev/ptyXY"); @@ -197,32 +193,31 @@ static int ptym_open(char *pts_name) /* try to open master */ fdm = open(pts_name, O_RDWR); if (fdm < 0) { - if (errno == ENOENT) { /* different from EIO */ - return -1; /* out of pty devices */ + if (errno == ENOENT) { /* different from EIO */ + return -1; /* out of pty devices */ } else { - continue; /* try next pty device */ + continue; /* try next pty device */ } } - pts_name[5] = 't'; /* chage "pty" to "tty" */ - return fdm; /* got it, return fd of master */ + pts_name[5] = 't'; /* chage "pty" to "tty" */ + return fdm; /* got it, return fd of master */ } } - return -1; /* out of pty devices */ -#endif + return -1; /* out of pty devices */ +# endif } - static int ptys_open(int fdm, char *pts_name) { int fds; -#ifdef HAVE_PTSNAME +# ifdef HAVE_PTSNAME /* following should allocate controlling terminal */ fds = open(pts_name, O_RDWR); if (fds < 0) { close(fdm); return -5; } -#if defined(__SVR4) && defined(__sun) +# if defined(__SVR4) && defined(__sun) if (ioctl(fds, I_PUSH, "ptem") < 0) { close(fdm); close(fds); @@ -233,10 +228,10 @@ static int ptys_open(int fdm, char *pts_name) close(fds); return -7; } -#endif +# endif return fds; -#else +# else int gid; struct group *grptr; @@ -244,7 +239,7 @@ static int ptys_open(int fdm, char *pts_name) if (grptr != NULL) { gid = grptr->gr_gid; } else { - gid = -1; /* group tty is not in the group file */ + gid = -1; /* group tty is not in the group file */ } /* following two functions don't work unless we're root */ chown(pts_name, getuid(), gid); @@ -255,7 +250,7 @@ static int ptys_open(int fdm, char *pts_name) return -1; } return fds; -#endif +# endif } #endif /* #ifdef HAVE_OPENPTY */ diff --git a/opal/util/opal_pty.h b/opal/util/opal_pty.h index 4bcb7a97f9d..f30cd97d5ec 100644 --- a/opal/util/opal_pty.h +++ b/opal/util/opal_pty.h @@ -22,30 +22,29 @@ #include "opal_config.h" #ifdef HAVE_UTIL_H -#include +# include #endif #ifdef HAVE_LIBUTIL_H -#include +# include #endif #ifdef HAVE_TERMIOS_H -# include +# include #else -# ifdef HAVE_TERMIO_H -# include -# endif +# ifdef HAVE_TERMIO_H +# include +# endif #endif BEGIN_C_DECLS #if OPAL_ENABLE_PTY_SUPPORT -OPAL_DECLSPEC int opal_openpty(int *amaster, int *aslave, char *name, - struct termios *termp, struct winsize *winp); +OPAL_DECLSPEC int opal_openpty(int *amaster, int *aslave, char *name, struct termios *termp, + struct winsize *winp); #else -OPAL_DECLSPEC int opal_openpty(int *amaster, int *aslave, char *name, - void *termp, void *winpp); +OPAL_DECLSPEC int opal_openpty(int *amaster, int *aslave, char *name, void *termp, void *winpp); #endif diff --git a/opal/util/os_dirpath.c b/opal/util/os_dirpath.c index 2328179d7f6..e4ab4d7b3c0 100644 --- a/opal/util/os_dirpath.c +++ b/opal/util/os_dirpath.c @@ -19,31 +19,30 @@ * $HEADER$ */ - #include "opal_config.h" #include #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ #include #if HAVE_SYS_STAT_H -#include +# include #endif /* HAVE_SYS_STAT_H */ #ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ +# include +#endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_DIRENT_H -#include -#endif /* HAVE_DIRENT_H */ +# include +#endif /* HAVE_DIRENT_H */ -#include "opal/util/output.h" -#include "opal/util/os_dirpath.h" -#include "opal/util/show_help.h" +#include "opal/constants.h" #include "opal/util/argv.h" +#include "opal/util/os_dirpath.h" #include "opal/util/os_path.h" -#include "opal/constants.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" static const char path_sep[] = OPAL_PATH_SEP; @@ -55,24 +54,23 @@ int opal_os_dirpath_create(const char *path, const mode_t mode) int ret; if (NULL == path) { /* protect ourselves from errors */ - return(OPAL_ERR_BAD_PARAM); + return (OPAL_ERR_BAD_PARAM); } - if (0 == (ret = stat(path, &buf))) { /* already exists */ + if (0 == (ret = stat(path, &buf))) { /* already exists */ if (mode == (mode & buf.st_mode)) { /* has correct mode */ - return(OPAL_SUCCESS); + return (OPAL_SUCCESS); } if (0 == (ret = chmod(path, (buf.st_mode | mode)))) { /* successfully change mode */ - return(OPAL_SUCCESS); + return (OPAL_SUCCESS); } - opal_show_help("help-opal-util.txt", "dir-mode", true, - path, mode, strerror(errno)); - return(OPAL_ERR_PERM); /* can't set correct mode */ + opal_show_help("help-opal-util.txt", "dir-mode", true, path, mode, strerror(errno)); + return (OPAL_ERR_PERM); /* can't set correct mode */ } /* quick -- try to make directory */ if (0 == mkdir(path, mode)) { - return(OPAL_SUCCESS); + return (OPAL_SUCCESS); } /* didnt work, so now have to build our way down the tree */ @@ -83,7 +81,7 @@ int opal_os_dirpath_create(const char *path, const mode_t mode) /* Ensure to allocate enough space for tmp: the strlen of the incoming path + 1 (for \0) */ - tmp = (char*)malloc(strlen(path) + 1); + tmp = (char *) malloc(strlen(path) + 1); tmp[0] = '\0'; /* Iterate through all the subdirectory names in the path, @@ -114,19 +112,18 @@ int opal_os_dirpath_create(const char *path, const mode_t mode) /* Now that we have the name, try to create it */ mkdir(tmp, mode); - ret = errno; // save the errno for an error msg, if needed + ret = errno; // save the errno for an error msg, if needed if (0 != stat(tmp, &buf)) { - opal_show_help("help-opal-util.txt", "mkdir-failed", true, - tmp, strerror(ret)); + opal_show_help("help-opal-util.txt", "mkdir-failed", true, tmp, strerror(ret)); opal_argv_free(parts); free(tmp); return OPAL_ERROR; - } else if (i == (len-1) && (mode != (mode & buf.st_mode)) && (0 > chmod(tmp, (buf.st_mode | mode)))) { - opal_show_help("help-opal-util.txt", "dir-mode", true, - tmp, mode, strerror(errno)); + } else if (i == (len - 1) && (mode != (mode & buf.st_mode)) + && (0 > chmod(tmp, (buf.st_mode | mode)))) { + opal_show_help("help-opal-util.txt", "dir-mode", true, tmp, mode, strerror(errno)); opal_argv_free(parts); free(tmp); - return(OPAL_ERR_PERM); /* can't set correct mode */ + return (OPAL_ERR_PERM); /* can't set correct mode */ } } @@ -145,8 +142,7 @@ int opal_os_dirpath_create(const char *path, const mode_t mode) * removed. If the callback returns non-zero, then no removal is * done. */ -int opal_os_dirpath_destroy(const char *path, - bool recursive, +int opal_os_dirpath_destroy(const char *path, bool recursive, opal_os_dirpath_destroy_callback_fn_t cbfunc) { int rc, exit_status = OPAL_SUCCESS; @@ -156,7 +152,7 @@ int opal_os_dirpath_destroy(const char *path, char *filenm; struct stat buf; - if (NULL == path) { /* protect against error */ + if (NULL == path) { /* protect against error */ return OPAL_ERROR; } @@ -178,8 +174,7 @@ int opal_os_dirpath_destroy(const char *path, /* skip: * - . and .. */ - if ((0 == strcmp(ep->d_name, ".")) || - (0 == strcmp(ep->d_name, ".."))) { + if ((0 == strcmp(ep->d_name, ".")) || (0 == strcmp(ep->d_name, ".."))) { continue; } @@ -251,31 +246,31 @@ int opal_os_dirpath_destroy(const char *path, /* Done with this directory */ closedir(dp); - cleanup: +cleanup: /* * If the directory is empty, them remove it */ - if(opal_os_dirpath_is_empty(path)) { + if (opal_os_dirpath_is_empty(path)) { rmdir(path); } return exit_status; } -bool opal_os_dirpath_is_empty(const char *path ) { +bool opal_os_dirpath_is_empty(const char *path) +{ DIR *dp; struct dirent *ep; - if (NULL != path) { /* protect against error */ + if (NULL != path) { /* protect against error */ dp = opendir(path); if (NULL != dp) { while ((ep = readdir(dp))) { - if ((0 != strcmp(ep->d_name, ".")) && - (0 != strcmp(ep->d_name, ".."))) { - closedir(dp); - return false; - } + if ((0 != strcmp(ep->d_name, ".")) && (0 != strcmp(ep->d_name, ".."))) { + closedir(dp); + return false; + } } closedir(dp); return true; @@ -286,9 +281,10 @@ bool opal_os_dirpath_is_empty(const char *path ) { return true; } -int opal_os_dirpath_access(const char *path, const mode_t in_mode ) { +int opal_os_dirpath_access(const char *path, const mode_t in_mode) +{ struct stat buf; - mode_t loc_mode = S_IRWXU; /* looking for full rights */ + mode_t loc_mode = S_IRWXU; /* looking for full rights */ /* * If there was no mode specified, use the default mode @@ -297,15 +293,15 @@ int opal_os_dirpath_access(const char *path, const mode_t in_mode ) { loc_mode = in_mode; } - if (0 == stat(path, &buf)) { /* exists - check access */ + if (0 == stat(path, &buf)) { /* exists - check access */ if ((buf.st_mode & loc_mode) == loc_mode) { /* okay, I can work here */ - return(OPAL_SUCCESS); + return (OPAL_SUCCESS); } else { /* Don't have access rights to the existing path */ - return(OPAL_ERROR); + return (OPAL_ERROR); } } else { /* We could not find the path */ - return( OPAL_ERR_NOT_FOUND ); + return (OPAL_ERR_NOT_FOUND); } } diff --git a/opal/util/os_dirpath.h b/opal/util/os_dirpath.h index 5564a77370a..f8238da9092 100644 --- a/opal/util/os_dirpath.h +++ b/opal/util/os_dirpath.h @@ -42,7 +42,7 @@ #include "opal_config.h" #ifdef HAVE_SYS_STAT_H -#include +# include #endif BEGIN_C_DECLS @@ -80,14 +80,16 @@ OPAL_DECLSPEC bool opal_os_dirpath_is_empty(const char *path); * @retval OPAL_ERR_NOT_FOUND If directory does not exist * @retval OPAL_ERROR If directory exists, and permissions do not match */ -OPAL_DECLSPEC int opal_os_dirpath_access(const char *path, const mode_t mode ); +OPAL_DECLSPEC int opal_os_dirpath_access(const char *path, const mode_t mode); /** * Callback for opal_os_dirpath_destroy(). Call for every file/directory before * taking action to remove/unlink it. * - * @param root A pointer to a string that contains the base path name (e.g., /tmp/foo from /tmp/foo/bar) - * @param path A pointer to a string that contains the file or directory (e.g., bar from /tmp/foo/bar) + * @param root A pointer to a string that contains the base path name (e.g., /tmp/foo from + * /tmp/foo/bar) + * @param path A pointer to a string that contains the file or directory (e.g., bar from + * /tmp/foo/bar) * * @retval true Allow the program to remove the file/directory * @retval false Do not allow the program to remove the file/directory @@ -109,8 +111,7 @@ typedef bool (*opal_os_dirpath_destroy_callback_fn_t)(const char *root, const ch * @retval OPAL_ERROR If the directory cannnot be removed, accessed properly, or contains * directories that could not be removed.. */ -OPAL_DECLSPEC int opal_os_dirpath_destroy(const char *path, - bool recursive, +OPAL_DECLSPEC int opal_os_dirpath_destroy(const char *path, bool recursive, opal_os_dirpath_destroy_callback_fn_t cbfunc); END_C_DECLS diff --git a/opal/util/os_path.c b/opal/util/os_path.c index 8eb54f43f74..6c87ca66635 100644 --- a/opal/util/os_path.c +++ b/opal/util/os_path.c @@ -21,13 +21,13 @@ #include #ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ +# include +#endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_PARAM_H -#include -#endif /* HAVE_SYS_PARAM_H */ -#include +# include +#endif /* HAVE_SYS_PARAM_H */ #include +#include #include "opal/util/os_path.h" @@ -46,37 +46,39 @@ char *opal_os_path(int relative, ...) num_elements = 0; total_length = 0; - while (NULL != (element = va_arg(ap, char*))) { + while (NULL != (element = va_arg(ap, char *))) { num_elements++; total_length = total_length + strlen(element); - if( path_sep[0] != element[0] ) total_length++; + if (path_sep[0] != element[0]) { + total_length++; + } } va_end(ap); if (0 == num_elements) { /* must be looking for a simple answer */ size_t len = 3; - path = (char *)calloc(len, sizeof(char)); - if (relative) { + path = (char *) calloc(len, sizeof(char)); + if (relative) { path[0] = '.'; } strncat(path, path_sep, len - 1); - return(path); + return (path); } /* setup path with enough room for the string terminator, the elements, and the separator between each of the elements */ total_length = total_length + num_elements * strlen(path_sep) + 1; - if(relative) { + if (relative) { total_length++; } - if (total_length > OPAL_PATH_MAX) { /* path length is too long - reject it */ - return(NULL); + if (total_length > OPAL_PATH_MAX) { /* path length is too long - reject it */ + return (NULL); } - path = (char *)calloc(total_length, sizeof(char)); + path = (char *) calloc(total_length, sizeof(char)); if (NULL == path) { - return(NULL); + return (NULL); } if (relative) { @@ -84,14 +86,14 @@ char *opal_os_path(int relative, ...) } va_start(ap, relative); - if( NULL != (element = va_arg(ap, char*)) ) { - if (path_sep[0] != element[0]) { + if (NULL != (element = va_arg(ap, char *))) { + if (path_sep[0] != element[0]) { strncat(path, path_sep, total_length); } strcat(path, element); } - while (NULL != (element=va_arg(ap, char*))) { - if (path_sep[0] != element[0]) { + while (NULL != (element = va_arg(ap, char *))) { + if (path_sep[0] != element[0]) { strncat(path, path_sep, total_length); } strncat(path, element, total_length); diff --git a/opal/util/os_path.h b/opal/util/os_path.h index db3d9dcbe72..6cb5d782072 100644 --- a/opal/util/os_path.h +++ b/opal/util/os_path.h @@ -44,8 +44,8 @@ #include "opal_config.h" -#include #include +#include BEGIN_C_DECLS @@ -69,13 +69,14 @@ BEGIN_C_DECLS * va_start() has undefined behavior (according to clang warnings on * MacOS High Sierra). */ -OPAL_DECLSPEC char *opal_os_path(int relative, ...) __opal_attribute_malloc__ __opal_attribute_sentinel__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_os_path(int relative, ...) + __opal_attribute_malloc__ __opal_attribute_sentinel__ __opal_attribute_warn_unused_result__; /** * Convert the path to be OS friendly. On UNIX this function will * be empty. */ -#define opal_make_filename_os_friendly(PATH) (PATH) +#define opal_make_filename_os_friendly(PATH) (PATH) END_C_DECLS diff --git a/opal/util/output.c b/opal/util/output.c index b09c21c87cd..378649a7b9b 100644 --- a/opal/util/output.c +++ b/opal/util/output.c @@ -31,29 +31,29 @@ #include "opal_config.h" -#include #include +#include #include #ifdef HAVE_SYSLOG_H -#include +# include #endif -#include #include +#include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif +#include "opal/constants.h" +#include "opal/mca/pmix/pmix-internal.h" +#include "opal/mca/threads/mutex.h" #include "opal/runtime/opal.h" #include "opal/util/opal_environ.h" #include "opal/util/output.h" -#include "opal/util/string_copy.h" #include "opal/util/printf.h" -#include "opal/mca/threads/mutex.h" -#include "opal/constants.h" -#include "opal/mca/pmix/pmix-internal.h" +#include "opal/util/string_copy.h" /* * Private data @@ -63,7 +63,6 @@ static opal_output_stream_t verbose; static char *output_dir = NULL; static char *output_prefix = NULL; - /* * Internal data structures and helpers for the generalized output * stream mechanism. @@ -98,20 +97,19 @@ typedef struct { */ static void construct(opal_object_t *stream); static void destruct(opal_object_t *stream); -static int do_open(int output_id, opal_output_stream_t * lds); +static int do_open(int output_id, opal_output_stream_t *lds); static int open_file(int i); static void free_descriptor(int output_id); -static int make_string(char **no_newline_string, output_desc_t *ldi, - const char *format, va_list arglist); +static int make_string(char **no_newline_string, output_desc_t *ldi, const char *format, + va_list arglist); static int output(int output_id, const char *format, va_list arglist); -static void opal_output_finalize (void); - +static void opal_output_finalize(void); #define OPAL_OUTPUT_MAX_STREAMS 64 #if defined(HAVE_SYSLOG) -#define USE_SYSLOG 1 +# define USE_SYSLOG 1 #else -#define USE_SYSLOG 0 +# define USE_SYSLOG 0 #endif /* global state */ @@ -172,7 +170,7 @@ bool opal_output_init(void) } else { opal_output_redirected_syslog_pri = LOG_ERR; } -#endif /* HAVE_SYSLOG_H */ +#endif /* HAVE_SYSLOG_H */ str = getenv("OPAL_OUTPUT_SYSLOG_IDENT"); if (NULL != str) { redirect_syslog_ident = strdup(str); @@ -191,8 +189,7 @@ bool opal_output_init(void) str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT"); if (NULL != str && str[0] == '1') { verbose.lds_want_stdout = true; - } - else { + } else { verbose.lds_want_stderr = true; } } @@ -225,30 +222,27 @@ bool opal_output_init(void) verbose_stream = opal_output_open(&verbose); /* make sure opal output is cleaned up on finalize */ - opal_finalize_register_cleanup (opal_output_finalize); + opal_finalize_register_cleanup(opal_output_finalize); return true; } - /* * Open a stream */ -int opal_output_open(opal_output_stream_t * lds) +int opal_output_open(opal_output_stream_t *lds) { return do_open(-1, lds); } - /* * Reset the parameters on a stream */ -int opal_output_reopen(int output_id, opal_output_stream_t * lds) +int opal_output_reopen(int output_id, opal_output_stream_t *lds) { return do_open(output_id, lds); } - /* * Enable and disable output streams */ @@ -270,7 +264,6 @@ bool opal_output_switch(int output_id, bool enable) return ret; } - /* * Reopen all the streams; used during checkpoint/restart. */ @@ -287,7 +280,7 @@ void opal_output_reopen_all(void) } hostname = opal_gethostname(); - if( NULL != verbose.lds_prefix ) { + if (NULL != verbose.lds_prefix) { free(verbose.lds_prefix); verbose.lds_prefix = NULL; } @@ -310,13 +303,13 @@ void opal_output_reopen_all(void) */ info[i].ldi_used = false; -#if USE_SYSLOG +# if USE_SYSLOG lds.lds_want_syslog = info[i].ldi_syslog; lds.lds_syslog_priority = info[i].ldi_syslog_priority; lds.lds_syslog_ident = info[i].ldi_syslog_ident; -#else +# else lds.lds_want_syslog = false; -#endif +# endif lds.lds_prefix = info[i].ldi_prefix; lds.lds_suffix = info[i].ldi_suffix; lds.lds_want_stdout = info[i].ldi_stdout; @@ -335,7 +328,6 @@ void opal_output_reopen_all(void) #endif } - /* * Close a stream */ @@ -353,8 +345,8 @@ void opal_output_close(int output_id) * free the resources associated with the descriptor */ OPAL_THREAD_LOCK(&mutex); - if (output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_used && info[output_id].ldi_enabled) { + if (output_id < OPAL_OUTPUT_MAX_STREAMS && info[output_id].ldi_used + && info[output_id].ldi_enabled) { free_descriptor(output_id); /* If no one has the syslog open, we should close it */ @@ -375,7 +367,6 @@ void opal_output_close(int output_id) OPAL_THREAD_UNLOCK(&mutex); } - /* * Main function to send output to a stream */ @@ -389,30 +380,26 @@ void opal_output(int output_id, const char *format, ...) } } - /* * Check whether the verbose level is high enough for the given stream */ bool opal_output_check_verbosity(int level, int output_id) { - return (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_verbose_level >= level); + return (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS + && info[output_id].ldi_verbose_level >= level); } - /* * Send a message to a stream if the verbose level is high enough */ -void opal_output_vverbose(int level, int output_id, const char *format, - va_list arglist) +void opal_output_vverbose(int level, int output_id, const char *format, va_list arglist) { - if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_verbose_level >= level) { + if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS + && info[output_id].ldi_verbose_level >= level) { output(output_id, format, arglist); } } - /* * Send a message to a string if the verbose level is high enough */ @@ -421,8 +408,8 @@ char *opal_output_string(int level, int output_id, const char *format, ...) int rc; char *ret = NULL; - if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_verbose_level >= level) { + if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS + && info[output_id].ldi_verbose_level >= level) { va_list arglist; va_start(arglist, format); rc = make_string(&ret, &info[output_id], format, arglist); @@ -435,18 +422,16 @@ char *opal_output_string(int level, int output_id, const char *format, ...) return ret; } - /* * Send a message to a string if the verbose level is high enough */ -char *opal_output_vstring(int level, int output_id, const char *format, - va_list arglist) +char *opal_output_vstring(int level, int output_id, const char *format, va_list arglist) { int rc; char *ret = NULL; - if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_verbose_level >= level) { + if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS + && info[output_id].ldi_verbose_level >= level) { rc = make_string(&ret, &info[output_id], format, arglist); if (OPAL_SUCCESS != rc) { ret = NULL; @@ -456,7 +441,6 @@ char *opal_output_vstring(int level, int output_id, const char *format, return ret; } - /* * Set the verbosity level of a stream */ @@ -467,13 +451,10 @@ void opal_output_set_verbosity(int output_id, int level) } } - /* * Control where output flies will go */ -void opal_output_set_output_file_info(const char *dir, - const char *prefix, - char **olddir, +void opal_output_set_output_file_info(const char *dir, const char *prefix, char **olddir, char **oldprefix) { if (NULL != olddir) { @@ -493,7 +474,6 @@ void opal_output_set_output_file_info(const char *dir, } } - /* * Shut down the output stream system */ @@ -508,13 +488,13 @@ static void opal_output_finalize(void) verbose_stream = -1; - free (output_prefix); + free(output_prefix); output_prefix = NULL; - free (output_dir); + free(output_dir); output_dir = NULL; - if(NULL != temp_str) { + if (NULL != temp_str) { free(temp_str); temp_str = NULL; temp_str_len = 0; @@ -533,7 +513,7 @@ static void opal_output_finalize(void) */ static void construct(opal_object_t *obj) { - opal_output_stream_t *stream = (opal_output_stream_t*) obj; + opal_output_stream_t *stream = (opal_output_stream_t *) obj; stream->lds_verbose_level = 0; stream->lds_syslog_priority = 0; @@ -550,9 +530,9 @@ static void construct(opal_object_t *obj) } static void destruct(opal_object_t *obj) { - opal_output_stream_t *stream = (opal_output_stream_t*) obj; + opal_output_stream_t *stream = (opal_output_stream_t *) obj; - if( NULL != stream->lds_file_suffix ) { + if (NULL != stream->lds_file_suffix) { free(stream->lds_file_suffix); stream->lds_file_suffix = NULL; } @@ -563,7 +543,7 @@ static void destruct(opal_object_t *obj) * back-end function so that we can do the thread locking properly * (especially upon reopen). */ -static int do_open(int output_id, opal_output_stream_t * lds) +static int do_open(int output_id, opal_output_stream_t *lds) { int i; bool redirect_to_file = false; @@ -618,12 +598,11 @@ static int do_open(int output_id, opal_output_stream_t * lds) if (-1 == output_id) { OPAL_THREAD_UNLOCK(&mutex); } - info[i].ldi_enabled = lds->lds_is_debugging ? - (bool) OPAL_ENABLE_DEBUG : true; + info[i].ldi_enabled = lds->lds_is_debugging ? (bool) OPAL_ENABLE_DEBUG : true; info[i].ldi_verbose_level = lds->lds_verbose_level; #if USE_SYSLOG -#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) +# if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) if (opal_output_redirected_to_syslog) { info[i].ldi_syslog = true; info[i].ldi_syslog_priority = opal_output_redirected_syslog_pri; @@ -636,11 +615,11 @@ static int do_open(int output_id, opal_output_stream_t * lds) } syslog_opened = true; } else { -#endif +# endif info[i].ldi_syslog = lds->lds_want_syslog; if (lds->lds_want_syslog) { -#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) +# if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) if (NULL != lds->lds_syslog_ident) { info[i].ldi_syslog_ident = strdup(lds->lds_syslog_ident); openlog(lds->lds_syslog_ident, LOG_PID, LOG_USER); @@ -648,14 +627,14 @@ static int do_open(int output_id, opal_output_stream_t * lds) info[i].ldi_syslog_ident = NULL; openlog("opal", LOG_PID, LOG_USER); } -#endif +# endif syslog_opened = true; info[i].ldi_syslog_priority = lds->lds_syslog_priority; } -#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) +# if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) } -#endif +# endif #else info[i].ldi_syslog = false; @@ -663,7 +642,7 @@ static int do_open(int output_id, opal_output_stream_t * lds) if (NULL != lds->lds_prefix) { info[i].ldi_prefix = strdup(lds->lds_prefix); - info[i].ldi_prefix_len = (int)strlen(lds->lds_prefix); + info[i].ldi_prefix_len = (int) strlen(lds->lds_prefix); } else { info[i].ldi_prefix = NULL; info[i].ldi_prefix_len = 0; @@ -671,7 +650,7 @@ static int do_open(int output_id, opal_output_stream_t * lds) if (NULL != lds->lds_suffix) { info[i].ldi_suffix = strdup(lds->lds_suffix); - info[i].ldi_suffix_len = (int)strlen(lds->lds_suffix); + info[i].ldi_suffix_len = (int) strlen(lds->lds_suffix); } else { info[i].ldi_suffix = NULL; info[i].ldi_suffix_len = 0; @@ -703,8 +682,8 @@ static int do_open(int output_id, opal_output_stream_t * lds) if (NULL != sfx) { info[i].ldi_file_suffix = strdup(sfx); } else { - info[i].ldi_file_suffix = (NULL == lds->lds_file_suffix) ? NULL : - strdup(lds->lds_file_suffix); + info[i].ldi_file_suffix = (NULL == lds->lds_file_suffix) ? NULL + : strdup(lds->lds_file_suffix); } info[i].ldi_file_want_append = lds->lds_want_file_append; info[i].ldi_file_num_lines_lost = 0; @@ -714,12 +693,12 @@ static int do_open(int output_id, opal_output_stream_t * lds) * This is the verbose stream, so update the internal 'verbose_stream' * to match the parameters set in the info[i] */ - if( verbose_stream == i ) { - verbose.lds_want_syslog = info[i].ldi_syslog; + if (verbose_stream == i) { + verbose.lds_want_syslog = info[i].ldi_syslog; verbose.lds_syslog_priority = info[i].ldi_syslog_priority; - verbose.lds_syslog_ident = info[i].ldi_syslog_ident; - verbose.lds_want_stdout = info[i].ldi_stdout; - verbose.lds_want_stderr = info[i].ldi_stderr; + verbose.lds_syslog_ident = info[i].ldi_syslog_ident; + verbose.lds_want_stdout = info[i].ldi_stdout; + verbose.lds_want_stderr = info[i].ldi_stderr; } /* Don't open a file in the session directory now -- do that lazily @@ -728,7 +707,6 @@ static int do_open(int output_id, opal_output_stream_t * lds) return i; } - static int open_file(int i) { int flags; @@ -739,7 +717,7 @@ static int open_file(int i) * on someone else's stream - if so, we don't want * to open it twice */ - for (n=0; n < OPAL_OUTPUT_MAX_STREAMS; n++) { + for (n = 0; n < OPAL_OUTPUT_MAX_STREAMS; n++) { if (i == n) { continue; } @@ -749,18 +727,15 @@ static int open_file(int i) if (!info[n].ldi_file) { continue; } - if (NULL != info[i].ldi_file_suffix && - NULL != info[n].ldi_file_suffix) { + if (NULL != info[i].ldi_file_suffix && NULL != info[n].ldi_file_suffix) { if (0 != strcmp(info[i].ldi_file_suffix, info[n].ldi_file_suffix)) { break; } } - if (NULL == info[i].ldi_file_suffix && - NULL != info[n].ldi_file_suffix) { + if (NULL == info[i].ldi_file_suffix && NULL != info[n].ldi_file_suffix) { break; } - if (NULL != info[i].ldi_file_suffix && - NULL == info[n].ldi_file_suffix) { + if (NULL != info[i].ldi_file_suffix && NULL == info[n].ldi_file_suffix) { break; } if (info[n].ldi_fd < 0) { @@ -797,20 +772,20 @@ static int open_file(int i) info[i].ldi_fd = open(filename, flags, 0644); if (-1 == info[i].ldi_fd) { info[i].ldi_used = false; - free(filename); /* release the filename in all cases */ + free(filename); /* release the filename in all cases */ return OPAL_ERR_IN_ERRNO; } /* Make the file be close-on-exec to prevent child inheritance * problems */ if (-1 == fcntl(info[i].ldi_fd, F_SETFD, 1)) { - free(filename); /* release the filename in all cases */ + free(filename); /* release the filename in all cases */ return OPAL_ERR_IN_ERRNO; } /* register it to be ignored */ opal_pmix_register_cleanup(filename, false, true, false); - free(filename); /* release the filename in all cases */ + free(filename); /* release the filename in all cases */ } /* Return successfully even if the session dir did not exist yet; @@ -819,7 +794,6 @@ static int open_file(int i) return OPAL_SUCCESS; } - /* * Free all the resources associated with a descriptor. */ @@ -827,8 +801,8 @@ static void free_descriptor(int output_id) { output_desc_t *ldi; - if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_used && info[output_id].ldi_enabled) { + if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && info[output_id].ldi_used + && info[output_id].ldi_enabled) { ldi = &info[output_id]; if (-1 != ldi->ldi_fd) { @@ -843,12 +817,12 @@ static void free_descriptor(int output_id) } ldi->ldi_prefix = NULL; - if (NULL != ldi->ldi_suffix) { - free(ldi->ldi_suffix); - } - ldi->ldi_suffix = NULL; + if (NULL != ldi->ldi_suffix) { + free(ldi->ldi_suffix); + } + ldi->ldi_suffix = NULL; - if (NULL != ldi->ldi_file_suffix) { + if (NULL != ldi->ldi_file_suffix) { free(ldi->ldi_file_suffix); } ldi->ldi_file_suffix = NULL; @@ -860,9 +834,8 @@ static void free_descriptor(int output_id) } } - -static int make_string(char **no_newline_string, output_desc_t *ldi, - const char *format, va_list arglist) +static int make_string(char **no_newline_string, output_desc_t *ldi, const char *format, + va_list arglist) { size_t len, total_len; bool want_newline = false; @@ -902,27 +875,23 @@ static int make_string(char **no_newline_string, output_desc_t *ldi, } if (NULL != ldi->ldi_prefix && NULL != ldi->ldi_suffix) { if (want_newline) { - snprintf(temp_str, temp_str_len, "%s%s%s\n", - ldi->ldi_prefix, *no_newline_string, ldi->ldi_suffix); + snprintf(temp_str, temp_str_len, "%s%s%s\n", ldi->ldi_prefix, *no_newline_string, + ldi->ldi_suffix); } else { - snprintf(temp_str, temp_str_len, "%s%s%s", ldi->ldi_prefix, - *no_newline_string, ldi->ldi_suffix); + snprintf(temp_str, temp_str_len, "%s%s%s", ldi->ldi_prefix, *no_newline_string, + ldi->ldi_suffix); } } else if (NULL != ldi->ldi_prefix) { if (want_newline) { - snprintf(temp_str, temp_str_len, "%s%s\n", - ldi->ldi_prefix, *no_newline_string); + snprintf(temp_str, temp_str_len, "%s%s\n", ldi->ldi_prefix, *no_newline_string); } else { - snprintf(temp_str, temp_str_len, "%s%s", ldi->ldi_prefix, - *no_newline_string); + snprintf(temp_str, temp_str_len, "%s%s", ldi->ldi_prefix, *no_newline_string); } } else if (NULL != ldi->ldi_suffix) { if (want_newline) { - snprintf(temp_str, temp_str_len, "%s%s\n", - *no_newline_string, ldi->ldi_suffix); + snprintf(temp_str, temp_str_len, "%s%s\n", *no_newline_string, ldi->ldi_suffix); } else { - snprintf(temp_str, temp_str_len, "%s%s", - *no_newline_string, ldi->ldi_suffix); + snprintf(temp_str, temp_str_len, "%s%s", *no_newline_string, ldi->ldi_suffix); } } else { if (want_newline) { @@ -954,8 +923,8 @@ static int output(int output_id, const char *format, va_list arglist) /* If it's valid, used, and enabled, output */ - if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && - info[output_id].ldi_used && info[output_id].ldi_enabled) { + if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && info[output_id].ldi_used + && info[output_id].ldi_enabled) { OPAL_THREAD_LOCK(&mutex); ldi = &info[output_id]; @@ -979,15 +948,14 @@ static int output(int output_id, const char *format, va_list arglist) /* stdout output */ if (ldi->ldi_stdout) { - write(fileno(stdout), out, (int)strlen(out)); + write(fileno(stdout), out, (int) strlen(out)); fflush(stdout); } /* stderr output */ if (ldi->ldi_stderr) { - write((-1 == default_stderr_fd) ? - fileno(stderr) : default_stderr_fd, - out, (int)strlen(out)); + write((-1 == default_stderr_fd) ? fileno(stderr) : default_stderr_fd, out, + (int) strlen(out)); fflush(stderr); } @@ -1005,9 +973,10 @@ static int output(int output_id, const char *format, va_list arglist) char *out = buffer; memset(buffer, 0, BUFSIZ); snprintf(buffer, BUFSIZ - 1, - "[WARNING: %d lines lost because the Open MPI process session directory did\n not exist when opal_output() was invoked]\n", + "[WARNING: %d lines lost because the Open MPI process session " + "directory did\n not exist when opal_output() was invoked]\n", ldi->ldi_file_num_lines_lost); - write(ldi->ldi_fd, buffer, (int)strlen(buffer)); + write(ldi->ldi_fd, buffer, (int) strlen(buffer)); ldi->ldi_file_num_lines_lost = 0; if (out != buffer) { free(out); @@ -1015,7 +984,7 @@ static int output(int output_id, const char *format, va_list arglist) } } if (ldi->ldi_fd != -1) { - write(ldi->ldi_fd, out, (int)strlen(out)); + write(ldi->ldi_fd, out, (int) strlen(out)); } } OPAL_THREAD_UNLOCK(&mutex); diff --git a/opal/util/output.h b/opal/util/output.h index 76424c60015..109ee791b28 100644 --- a/opal/util/output.h +++ b/opal/util/output.h @@ -152,7 +152,7 @@ struct opal_output_stream_t { char *lds_syslog_ident; #else HANDLE lds_syslog_ident; -#endif /* !defined(__WINDOWS__) */ +#endif /* !defined(__WINDOWS__) */ /** * String prefix added to all output on the stream. @@ -244,304 +244,302 @@ struct opal_output_stream_t { * for details on what happens in this situation. */ char *lds_file_suffix; - }; - /** - * Convenience typedef - */ - typedef struct opal_output_stream_t opal_output_stream_t; +/** + * Convenience typedef + */ +typedef struct opal_output_stream_t opal_output_stream_t; - /** - * Initializes the output stream system and opens a default - * "verbose" stream. - * - * @retval true Upon success. - * @retval false Upon failure. - * - * This should be the first function invoked in the output - * subsystem. After this call, the default "verbose" stream is open - * and can be written to via calls to opal_output_verbose() and - * opal_output_error(). - * - * By definition, the default verbose stream has a handle ID of 0, - * and has a verbose level of 0. - */ - OPAL_DECLSPEC bool opal_output_init(void); +/** + * Initializes the output stream system and opens a default + * "verbose" stream. + * + * @retval true Upon success. + * @retval false Upon failure. + * + * This should be the first function invoked in the output + * subsystem. After this call, the default "verbose" stream is open + * and can be written to via calls to opal_output_verbose() and + * opal_output_error(). + * + * By definition, the default verbose stream has a handle ID of 0, + * and has a verbose level of 0. + */ +OPAL_DECLSPEC bool opal_output_init(void); - /** - * Opens an output stream. - * - * @param lds A pointer to opal_output_stream_t describing what the - * characteristics of the output stream should be. - * - * This function opens an output stream and returns an integer - * handle. The caller is responsible for maintaining the handle and - * using it in successive calls to OPAL_OUTPUT(), opal_output(), - * opal_output_switch(), and opal_output_close(). - * - * If lds is NULL, the default descriptions will be used, meaning - * that output will only be sent to stderr. - * - * It is safe to have multiple threads invoke this function - * simultaneously; their execution will be serialized in an - * unspecified manner. - * - * Be sure to see opal_output() for a description of what happens - * when open_open() / opal_output() is directed to send output to a - * file but the process session directory does not yet exist. - */ - OPAL_DECLSPEC int opal_output_open(opal_output_stream_t *lds); +/** + * Opens an output stream. + * + * @param lds A pointer to opal_output_stream_t describing what the + * characteristics of the output stream should be. + * + * This function opens an output stream and returns an integer + * handle. The caller is responsible for maintaining the handle and + * using it in successive calls to OPAL_OUTPUT(), opal_output(), + * opal_output_switch(), and opal_output_close(). + * + * If lds is NULL, the default descriptions will be used, meaning + * that output will only be sent to stderr. + * + * It is safe to have multiple threads invoke this function + * simultaneously; their execution will be serialized in an + * unspecified manner. + * + * Be sure to see opal_output() for a description of what happens + * when open_open() / opal_output() is directed to send output to a + * file but the process session directory does not yet exist. + */ +OPAL_DECLSPEC int opal_output_open(opal_output_stream_t *lds); - /** - * Re-opens / redirects an output stream. - * - * @param output_id Stream handle to reopen - * @param lds A pointer to opal_output_stream_t describing what the - * characteristics of the reopened output stream should be. - * - * This function redirects an existing stream into a new [set of] - * location[s], as specified by the lds parameter. If the output_id - * passed is invalid, this call is effectively the same as opening a - * new stream with a specific stream handle. - */ - OPAL_DECLSPEC int opal_output_reopen(int output_id, opal_output_stream_t *lds); +/** + * Re-opens / redirects an output stream. + * + * @param output_id Stream handle to reopen + * @param lds A pointer to opal_output_stream_t describing what the + * characteristics of the reopened output stream should be. + * + * This function redirects an existing stream into a new [set of] + * location[s], as specified by the lds parameter. If the output_id + * passed is invalid, this call is effectively the same as opening a + * new stream with a specific stream handle. + */ +OPAL_DECLSPEC int opal_output_reopen(int output_id, opal_output_stream_t *lds); - /** - * Enables and disables output streams. - * - * @param output_id Stream handle to switch - * @param enable Boolean indicating whether to enable the stream - * output or not. - * - * @returns The previous enable state of the stream (true == enabled, - * false == disabled). - * - * The output of a stream can be temporarily disabled by passing an - * enable value to false, and later resumed by passing an enable - * value of true. This does not close the stream -- it simply tells - * the opal_output subsystem to intercept and discard any output sent - * to the stream via OPAL_OUTPUT() or opal_output() until the output - * is re-enabled. - */ - OPAL_DECLSPEC bool opal_output_switch(int output_id, bool enable); +/** + * Enables and disables output streams. + * + * @param output_id Stream handle to switch + * @param enable Boolean indicating whether to enable the stream + * output or not. + * + * @returns The previous enable state of the stream (true == enabled, + * false == disabled). + * + * The output of a stream can be temporarily disabled by passing an + * enable value to false, and later resumed by passing an enable + * value of true. This does not close the stream -- it simply tells + * the opal_output subsystem to intercept and discard any output sent + * to the stream via OPAL_OUTPUT() or opal_output() until the output + * is re-enabled. + */ +OPAL_DECLSPEC bool opal_output_switch(int output_id, bool enable); - /** - * \internal - * - * Reopens all existing output streams. - * - * This function should never be called by user applications; it is - * typically only invoked after a restart (i.e., in a new process) - * where output streams need to be re-initialized. - */ - OPAL_DECLSPEC void opal_output_reopen_all(void); +/** + * \internal + * + * Reopens all existing output streams. + * + * This function should never be called by user applications; it is + * typically only invoked after a restart (i.e., in a new process) + * where output streams need to be re-initialized. + */ +OPAL_DECLSPEC void opal_output_reopen_all(void); - /** - * Close an output stream. - * - * @param output_id Handle of the stream to close. - * - * Close an output stream. No output will be sent to the stream - * after it is closed. Be aware that output handles tend to be - * re-used; it is possible that after a stream is closed, if another - * stream is opened, it will get the same handle value. - */ - OPAL_DECLSPEC void opal_output_close(int output_id); +/** + * Close an output stream. + * + * @param output_id Handle of the stream to close. + * + * Close an output stream. No output will be sent to the stream + * after it is closed. Be aware that output handles tend to be + * re-used; it is possible that after a stream is closed, if another + * stream is opened, it will get the same handle value. + */ +OPAL_DECLSPEC void opal_output_close(int output_id); - /** - * Main function to send output to a stream. - * - * @param output_id Stream id returned from opal_output_open(). - * @param format printf-style format string. - * @param varargs printf-style varargs list to fill the string - * specified by the format parameter. - * - * This is the main function to send output to custom streams (note - * that output to the default "verbose" stream is handled through - * opal_output_verbose() and opal_output_error()). - * - * It is never necessary to send a trailing "\n" in the strings to - * this function; some streams requires newlines, others do not -- - * this function will append newlines as necessary. - * - * Verbosity levels are ignored in this function. - * - * Note that for output streams that are directed to files, the - * files are stored under the process' session directory. If the - * session directory does not exist when opal_output() is invoked, - * the output will be discarded! Once the session directory is - * created, opal_output() will automatically create the file and - * writing to it. - */ - OPAL_DECLSPEC void opal_output(int output_id, const char *format, ...) __opal_attribute_format__(__printf__, 2, 3); +/** + * Main function to send output to a stream. + * + * @param output_id Stream id returned from opal_output_open(). + * @param format printf-style format string. + * @param varargs printf-style varargs list to fill the string + * specified by the format parameter. + * + * This is the main function to send output to custom streams (note + * that output to the default "verbose" stream is handled through + * opal_output_verbose() and opal_output_error()). + * + * It is never necessary to send a trailing "\n" in the strings to + * this function; some streams requires newlines, others do not -- + * this function will append newlines as necessary. + * + * Verbosity levels are ignored in this function. + * + * Note that for output streams that are directed to files, the + * files are stored under the process' session directory. If the + * session directory does not exist when opal_output() is invoked, + * the output will be discarded! Once the session directory is + * created, opal_output() will automatically create the file and + * writing to it. + */ +OPAL_DECLSPEC void opal_output(int output_id, const char *format, ...) + __opal_attribute_format__(__printf__, 2, 3); - /** - * Send output to a stream only if the passed verbosity level is - * high enough. - * - * @param output_id Stream id returned from opal_output_open(). - * @param level Target verbosity level. - * @param format printf-style format string. - * @param varargs printf-style varargs list to fill the string - * specified by the format parameter. - * - * Output is only sent to the stream if the current verbosity level - * is greater than or equal to the level parameter. This mechanism - * can be used to send "information" kinds of output to user - * applications, but only when the user has asked for a high enough - * verbosity level. - * - * It is never necessary to send a trailing "\n" in the strings to - * this function; some streams requires newlines, others do not -- - * this function will append newlines as necessary. - * - * This function is really a convenience wrapper around checking the - * current verbosity level set on the stream, and if the passed - * level is less than or equal to the stream's verbosity level, this - * function will effectively invoke opal_output to send the output to - * the stream. - * - * @see opal_output_set_verbosity() - */ +/** + * Send output to a stream only if the passed verbosity level is + * high enough. + * + * @param output_id Stream id returned from opal_output_open(). + * @param level Target verbosity level. + * @param format printf-style format string. + * @param varargs printf-style varargs list to fill the string + * specified by the format parameter. + * + * Output is only sent to the stream if the current verbosity level + * is greater than or equal to the level parameter. This mechanism + * can be used to send "information" kinds of output to user + * applications, but only when the user has asked for a high enough + * verbosity level. + * + * It is never necessary to send a trailing "\n" in the strings to + * this function; some streams requires newlines, others do not -- + * this function will append newlines as necessary. + * + * This function is really a convenience wrapper around checking the + * current verbosity level set on the stream, and if the passed + * level is less than or equal to the stream's verbosity level, this + * function will effectively invoke opal_output to send the output to + * the stream. + * + * @see opal_output_set_verbosity() + */ #define opal_output_verbose(verbose_level, output_id, ...) \ do { \ if (opal_output_check_verbosity(verbose_level, output_id)) { \ opal_output(output_id, __VA_ARGS__); \ } \ - } while(0) + } while (0) - OPAL_DECLSPEC bool opal_output_check_verbosity(int verbose_level, int output_id); +OPAL_DECLSPEC bool opal_output_check_verbosity(int verbose_level, int output_id); - /** - * Same as opal_output_verbose(), but takes a va_list form of varargs. - */ - OPAL_DECLSPEC void opal_output_vverbose(int verbose_level, int output_id, - const char *format, va_list ap) __opal_attribute_format__(__printf__, 3, 0); +/** + * Same as opal_output_verbose(), but takes a va_list form of varargs. + */ +OPAL_DECLSPEC void opal_output_vverbose(int verbose_level, int output_id, const char *format, + va_list ap) __opal_attribute_format__(__printf__, 3, 0); - /** - * Send output to a string if the verbosity level is high enough. - * - * @param output_id Stream id returned from opal_output_open(). - * @param level Target verbosity level. - * @param format printf-style format string. - * @param varargs printf-style varargs list to fill the string - * specified by the format parameter. - * - * Exactly the same as opal_output_verbose(), except the output it - * sent to a string instead of to the stream. If the verbose - * level is not high enough, NULL is returned. The caller is - * responsible for free()'ing the returned string. - */ - OPAL_DECLSPEC char *opal_output_string(int verbose_level, int output_id, - const char *format, ...) __opal_attribute_format__(__printf__, 3, 4); +/** + * Send output to a string if the verbosity level is high enough. + * + * @param output_id Stream id returned from opal_output_open(). + * @param level Target verbosity level. + * @param format printf-style format string. + * @param varargs printf-style varargs list to fill the string + * specified by the format parameter. + * + * Exactly the same as opal_output_verbose(), except the output it + * sent to a string instead of to the stream. If the verbose + * level is not high enough, NULL is returned. The caller is + * responsible for free()'ing the returned string. + */ +OPAL_DECLSPEC char *opal_output_string(int verbose_level, int output_id, const char *format, ...) + __opal_attribute_format__(__printf__, 3, 4); - /** - * Same as opal_output_string, but accepts a va_list form of varargs. - */ - OPAL_DECLSPEC char *opal_output_vstring(int verbose_level, int output_id, - const char *format, va_list ap) __opal_attribute_format__(__printf__, 3, 0); +/** + * Same as opal_output_string, but accepts a va_list form of varargs. + */ +OPAL_DECLSPEC char *opal_output_vstring(int verbose_level, int output_id, const char *format, + va_list ap) __opal_attribute_format__(__printf__, 3, 0); - /** - * Set the verbosity level for a stream. - * - * @param output_id Stream id returned from opal_output_open(). - * @param level New verbosity level - * - * This function sets the verbosity level on a given stream. It - * will be used for all future invocations of opal_output_verbose(). - */ - OPAL_DECLSPEC void opal_output_set_verbosity(int output_id, int level); +/** + * Set the verbosity level for a stream. + * + * @param output_id Stream id returned from opal_output_open(). + * @param level New verbosity level + * + * This function sets the verbosity level on a given stream. It + * will be used for all future invocations of opal_output_verbose(). + */ +OPAL_DECLSPEC void opal_output_set_verbosity(int output_id, int level); - /** - * Get the verbosity level for a stream - * - * @param output_id Stream id returned from opal_output_open() - * @returns Verbosity of stream - */ - OPAL_DECLSPEC int opal_output_get_verbosity(int output_id); +/** + * Get the verbosity level for a stream + * + * @param output_id Stream id returned from opal_output_open() + * @returns Verbosity of stream + */ +OPAL_DECLSPEC int opal_output_get_verbosity(int output_id); - /** - * Set characteristics for output files. - * - * @param dir Directory where output files will go - * @param olddir If non-NULL, the directory where output files - * were previously opened - * @param prefix Prefix of files in the output directory - * @param oldprefix If non-NULL, the old prefix - * - * This function controls the final filename used for all new - * output streams that request output files. Specifically, when - * opal_output_stream_t::lds_want_file is true, the output - * filename will be of the form $dir/$prefix$suffix. - * - * The default value for the output directory is whatever is - * specified in the TMPDIR environment variable if it exists, or - * $HOME if it does not. The default value for the prefix is - * "output-pid-" (where "" is replaced by the PID of the - * current process). - * - * If dir or prefix are NULL, new values are not set. The strings - * represented by dir and prefix are copied into internal storage; - * it is safe to pass string constants or free() these values - * after opal_output_set_output_file_info() returns. - * - * If olddir or oldprefix are not NULL, copies of the old - * directory and prefix (respectively) are returned in these - * parameters. The caller is responsible for calling (free) on - * these values. This allows one to get the old values, output an - * output file in a specific directory and/or with a specific - * prefix, and then restore the old values. - * - * Note that this function only affects the creation of \em new - * streams -- streams that have already started writing to output - * files are not affected (i.e., their output files are not moved - * to the new directory). More specifically, the opal_output - * system only opens/creates output files lazily -- so calling - * this function affects both new streams \em and any stream that - * was previously opened but had not yet output anything. - */ - OPAL_DECLSPEC void opal_output_set_output_file_info(const char *dir, - const char *prefix, - char **olddir, - char **oldprefix); +/** + * Set characteristics for output files. + * + * @param dir Directory where output files will go + * @param olddir If non-NULL, the directory where output files + * were previously opened + * @param prefix Prefix of files in the output directory + * @param oldprefix If non-NULL, the old prefix + * + * This function controls the final filename used for all new + * output streams that request output files. Specifically, when + * opal_output_stream_t::lds_want_file is true, the output + * filename will be of the form $dir/$prefix$suffix. + * + * The default value for the output directory is whatever is + * specified in the TMPDIR environment variable if it exists, or + * $HOME if it does not. The default value for the prefix is + * "output-pid-" (where "" is replaced by the PID of the + * current process). + * + * If dir or prefix are NULL, new values are not set. The strings + * represented by dir and prefix are copied into internal storage; + * it is safe to pass string constants or free() these values + * after opal_output_set_output_file_info() returns. + * + * If olddir or oldprefix are not NULL, copies of the old + * directory and prefix (respectively) are returned in these + * parameters. The caller is responsible for calling (free) on + * these values. This allows one to get the old values, output an + * output file in a specific directory and/or with a specific + * prefix, and then restore the old values. + * + * Note that this function only affects the creation of \em new + * streams -- streams that have already started writing to output + * files are not affected (i.e., their output files are not moved + * to the new directory). More specifically, the opal_output + * system only opens/creates output files lazily -- so calling + * this function affects both new streams \em and any stream that + * was previously opened but had not yet output anything. + */ +OPAL_DECLSPEC void opal_output_set_output_file_info(const char *dir, const char *prefix, + char **olddir, char **oldprefix); #if OPAL_ENABLE_DEBUG - /** - * Main macro for use in sending debugging output to output streams; - * will be "compiled out" when OPAL is configured without - * --enable-debug. - * - * @see opal_output() - */ -#define OPAL_OUTPUT(a) opal_output a +/** + * Main macro for use in sending debugging output to output streams; + * will be "compiled out" when OPAL is configured without + * --enable-debug. + * + * @see opal_output() + */ +# define OPAL_OUTPUT(a) opal_output a - /** - * Macro for use in sending debugging output to the output - * streams. Will be "compiled out" when OPAL is configured - * without --enable-debug. - * - * @see opal_output_verbose() - */ -#define OPAL_OUTPUT_VERBOSE(a) opal_output_verbose a +/** + * Macro for use in sending debugging output to the output + * streams. Will be "compiled out" when OPAL is configured + * without --enable-debug. + * + * @see opal_output_verbose() + */ +# define OPAL_OUTPUT_VERBOSE(a) opal_output_verbose a #else - /** - * Main macro for use in sending debugging output to output streams; - * will be "compiled out" when OPAL is configured without - * --enable-debug. - * - * @see opal_output() - */ -#define OPAL_OUTPUT(a) +/** + * Main macro for use in sending debugging output to output streams; + * will be "compiled out" when OPAL is configured without + * --enable-debug. + * + * @see opal_output() + */ +# define OPAL_OUTPUT(a) - /** - * Macro for use in sending debugging output to the output - * streams. Will be "compiled out" when OPAL is configured - * without --enable-debug. - * - * @see opal_output_verbose() - */ -#define OPAL_OUTPUT_VERBOSE(a) +/** + * Macro for use in sending debugging output to the output + * streams. Will be "compiled out" when OPAL is configured + * without --enable-debug. + * + * @see opal_output_verbose() + */ +# define OPAL_OUTPUT_VERBOSE(a) #endif /** @@ -557,4 +555,3 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_output_stream_t); END_C_DECLS #endif /* OPAL_OUTPUT_H_ */ - diff --git a/opal/util/path.c b/opal/util/path.c index 8128e5dc2c1..c937eea1407 100644 --- a/opal/util/path.c +++ b/opal/util/path.c @@ -25,65 +25,64 @@ */ #include "opal_config.h" +#include #include #include -#include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SHLWAPI_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #ifdef HAVE_SYS_MOUNT_H -#include +# include #endif #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_STAT_H -#include +# include #endif #ifdef HAVE_SYS_VFS_H -#include +# include #endif #ifdef HAVE_SYS_STATFS_H -#include +# include #endif #ifdef HAVE_SYS_STATVFS_H -#include +# include #endif #ifdef HAVE_SYS_MOUNT_H -#include +# include #endif #ifdef HAVE_MNTENT_H -#include +# include #endif #ifdef HAVE_PATHS_H -#include +# include #endif #ifdef _PATH_MOUNTED -#define MOUNTED_FILE _PATH_MOUNTED +# define MOUNTED_FILE _PATH_MOUNTED #else -#define MOUNTED_FILE "/etc/mtab" +# define MOUNTED_FILE "/etc/mtab" #endif - -#include "opal_stdint.h" +#include "opal/util/argv.h" +#include "opal/util/os_path.h" #include "opal/util/output.h" #include "opal/util/path.h" -#include "opal/util/os_path.h" -#include "opal/util/argv.h" #include "opal/util/printf.h" +#include "opal_stdint.h" /* * Sanity check to ensure we have either statfs or statvfs */ #if !defined(HAVE_STATFS) && !defined(HAVE_STATVFS) -#error Must have either statfs() or statvfs() +# error Must have either statfs() or statvfs() #endif /* @@ -91,17 +90,17 @@ * no struct statfs (!). So check to make sure we have struct statfs * before allowing the use of statfs(). */ -#if defined(HAVE_STATFS) && (defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || \ - defined(HAVE_STRUCT_STATFS_F_TYPE)) -#define USE_STATFS 1 +#if defined(HAVE_STATFS) \ + && (defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATFS_F_TYPE)) +# define USE_STATFS 1 #endif static void path_env_load(char *path, int *pargc, char ***pargv); static char *list_env_get(char *var, char **list); -bool opal_path_is_absolute( const char *path ) +bool opal_path_is_absolute(const char *path) { - if( OPAL_PATH_SEP[0] == *path ) { + if (OPAL_PATH_SEP[0] == *path) { return true; } return false; @@ -119,7 +118,7 @@ char *opal_path_find(char *fname, char **pathv, int mode, char **envv) int i; /* If absolute path is given, return it without searching. */ - if( opal_path_is_absolute(fname) ) { + if (opal_path_is_absolute(fname)) { return opal_path_access(fname, NULL, mode); } @@ -139,7 +138,7 @@ char *opal_path_find(char *fname, char **pathv, int mode, char **envv) if (delimit) { *delimit = '\0'; } - env = list_env_get(pathv[i]+1, envv); + env = list_env_get(pathv[i] + 1, envv); if (delimit) { *delimit = OPAL_PATH_SEP[0]; } @@ -152,8 +151,7 @@ char *opal_path_find(char *fname, char **pathv, int mode, char **envv) free(pfix); } } - } - else { + } else { fullpath = opal_path_access(fname, pathv[i], mode); } i++; @@ -190,7 +188,7 @@ char *opal_path_findv(char *fname, int mode, char **envv, char *wrkdir) found_dot = true; free(dirv[i]); dirv[i] = strdup(wrkdir); - if (NULL == dirv[i]){ + if (NULL == dirv[i]) { return NULL; } } @@ -204,14 +202,14 @@ char *opal_path_findv(char *fname, int mode, char **envv, char *wrkdir) opal_argv_append(&dirc, &dirv, wrkdir); } - if(NULL == dirv) + if (NULL == dirv) { return NULL; + } fullpath = opal_path_find(fname, dirv, mode, envv); opal_argv_free(dirv); return fullpath; } - /** * Forms a complete pathname and checks it for existance and * permissions @@ -252,8 +250,7 @@ char *opal_path_access(char *fname, char *path, int mode) return NULL; } - if (!(S_IFREG & buf.st_mode) && - !(S_IFLNK & buf.st_mode)) { + if (!(S_IFREG & buf.st_mode) && !(S_IFLNK & buf.st_mode)) { /* this isn't a regular file or a symbolic link, so * ignore it */ @@ -288,7 +285,6 @@ char *opal_path_access(char *fname, char *path, int mode) return fullpath; } - /** * * Loads argument array with $PATH env var. @@ -337,7 +333,6 @@ static void path_env_load(char *path, int *pargc, char ***pargv) } } - /** * Gets value of variable in list or environment. Looks in the list first * @@ -376,31 +371,32 @@ static char *list_env_get(char *var, char **list) * function will return NULL. Otherwise, an newly allocated string * will be returned. */ -char* opal_find_absolute_path( char* app_name ) +char *opal_find_absolute_path(char *app_name) { - char* abs_app_name; + char *abs_app_name; char cwd[OPAL_PATH_MAX], *pcwd; - if( opal_path_is_absolute(app_name) ) { /* already absolute path */ + if (opal_path_is_absolute(app_name)) { /* already absolute path */ abs_app_name = app_name; - } else if ( '.' == app_name[0] || - NULL != strchr(app_name, OPAL_PATH_SEP[0])) { + } else if ('.' == app_name[0] || NULL != strchr(app_name, OPAL_PATH_SEP[0])) { /* the app is in the current directory or below it */ - pcwd = getcwd( cwd, OPAL_PATH_MAX ); - if( NULL == pcwd ) { + pcwd = getcwd(cwd, OPAL_PATH_MAX); + if (NULL == pcwd) { /* too bad there is no way we can get the app absolute name */ return NULL; } - abs_app_name = opal_os_path( false, pcwd, app_name, NULL ); + abs_app_name = opal_os_path(false, pcwd, app_name, NULL); } else { /* Otherwise try to search for the application in the PATH ... */ - abs_app_name = opal_path_findv( app_name, X_OK, NULL, NULL ); + abs_app_name = opal_path_findv(app_name, X_OK, NULL, NULL); } - if( NULL != abs_app_name ) { - char* resolved_path = (char*)malloc(OPAL_PATH_MAX); - realpath( abs_app_name, resolved_path ); - if( abs_app_name != app_name ) free(abs_app_name); + if (NULL != abs_app_name) { + char *resolved_path = (char *) malloc(OPAL_PATH_MAX); + realpath(abs_app_name, resolved_path); + if (abs_app_name != app_name) { + free(abs_app_name); + } return resolved_path; } return NULL; @@ -416,15 +412,13 @@ static char *opal_check_mtab(char *dev_path) { #ifdef HAVE_MNTENT_H - FILE * mtab = NULL; - struct mntent * part = NULL; + FILE *mtab = NULL; + struct mntent *part = NULL; if ((mtab = setmntent(MOUNTED_FILE, "r")) != NULL) { while (NULL != (part = getmntent(mtab))) { - if ((NULL != part->mnt_dir) && - (NULL != part->mnt_type) && - (0 == strcmp(part->mnt_dir, dev_path))) - { + if ((NULL != part->mnt_dir) && (NULL != part->mnt_type) + && (0 == strcmp(part->mnt_dir, dev_path))) { endmntent(mtab); return strdup(part->mnt_type); } @@ -435,7 +429,6 @@ static char *opal_check_mtab(char *dev_path) return NULL; } - /** * @brief Figure out, whether fname is on network file system * @@ -481,26 +474,26 @@ static char *opal_check_mtab(char *dev_path) * return 0 success, -1 on failure with errno set. */ #ifndef LL_SUPER_MAGIC -#define LL_SUPER_MAGIC 0x0BD00BD0 /* Lustre magic number */ +# define LL_SUPER_MAGIC 0x0BD00BD0 /* Lustre magic number */ #endif #ifndef NFS_SUPER_MAGIC -#define NFS_SUPER_MAGIC 0x6969 +# define NFS_SUPER_MAGIC 0x6969 #endif #ifndef PAN_KERNEL_FS_CLIENT_SUPER_MAGIC -#define PAN_KERNEL_FS_CLIENT_SUPER_MAGIC 0xAAD7AAEA /* Panasas FS */ +# define PAN_KERNEL_FS_CLIENT_SUPER_MAGIC 0xAAD7AAEA /* Panasas FS */ #endif #ifndef GPFS_SUPER_MAGIC -#define GPFS_SUPER_MAGIC 0x47504653 /* Thats GPFS in ASCII */ +# define GPFS_SUPER_MAGIC 0x47504653 /* Thats GPFS in ASCII */ #endif #ifndef AUTOFS_SUPER_MAGIC -#define AUTOFS_SUPER_MAGIC 0x0187 +# define AUTOFS_SUPER_MAGIC 0x0187 #endif #ifndef PVFS2_SUPER_MAGIC -#define PVFS2_SUPER_MAGIC 0x20030528 +# define PVFS2_SUPER_MAGIC 0x20030528 #endif -#define MASK2 0xffff -#define MASK4 0xffffffff +#define MASK2 0xffff +#define MASK4 0xffffffff bool opal_path_nfs(char *fname, char **ret_fstype) { @@ -508,7 +501,7 @@ bool opal_path_nfs(char *fname, char **ret_fstype) int fsrc = -1; int vfsrc = -1; int trials; - char * file = strdup (fname); + char *file = strdup(fname); #if defined(USE_STATFS) struct statfs fsbuf; #endif @@ -522,16 +515,14 @@ bool opal_path_nfs(char *fname, char **ret_fstype) static struct fs_types_t { unsigned long long f_fsid; unsigned long long f_mask; - const char * f_fsname; - } fs_types[] = { - {LL_SUPER_MAGIC, MASK4, "lustre"}, - {NFS_SUPER_MAGIC, MASK2, "nfs"}, - {AUTOFS_SUPER_MAGIC, MASK2, "autofs"}, - {PAN_KERNEL_FS_CLIENT_SUPER_MAGIC, MASK4, "panfs"}, - {GPFS_SUPER_MAGIC, MASK4, "gpfs"}, - {PVFS2_SUPER_MAGIC, MASK4, "pvfs2"} - }; -#define FS_TYPES_NUM (int)(sizeof (fs_types)/sizeof (fs_types[0])) + const char *f_fsname; + } fs_types[] = {{LL_SUPER_MAGIC, MASK4, "lustre"}, + {NFS_SUPER_MAGIC, MASK2, "nfs"}, + {AUTOFS_SUPER_MAGIC, MASK2, "autofs"}, + {PAN_KERNEL_FS_CLIENT_SUPER_MAGIC, MASK4, "panfs"}, + {GPFS_SUPER_MAGIC, MASK4, "gpfs"}, + {PVFS2_SUPER_MAGIC, MASK4, "pvfs2"}}; +#define FS_TYPES_NUM (int) (sizeof(fs_types) / sizeof(fs_types[0])) /* * First, get the OS-dependent struct stat(v)fs buf. This may @@ -555,13 +546,14 @@ bool opal_path_nfs(char *fname, char **ret_fstype) /* In case some error with the current filename, try the parent directory */ if (-1 == fsrc && -1 == vfsrc) { - char * last_sep; + char *last_sep; - OPAL_OUTPUT_VERBOSE((10, 0, "opal_path_nfs: stat(v)fs on file:%s failed errno:%d directory:%s\n", + OPAL_OUTPUT_VERBOSE((10, 0, + "opal_path_nfs: stat(v)fs on file:%s failed errno:%d directory:%s\n", fname, errno, file)); if (EPERM == errno) { free(file); - if ( NULL != ret_fstype ) { + if (NULL != ret_fstype) { *ret_fstype = NULL; } return false; @@ -569,11 +561,10 @@ bool opal_path_nfs(char *fname, char **ret_fstype) last_sep = strrchr(file, OPAL_PATH_SEP[0]); /* Stop the search, when we have searched past root '/' */ - if (NULL == last_sep || (1 == strlen(last_sep) && - OPAL_PATH_SEP[0] == *last_sep)) { - free (file); - if ( NULL != ret_fstype ) { - *ret_fstype=NULL; + if (NULL == last_sep || (1 == strlen(last_sep) && OPAL_PATH_SEP[0] == *last_sep)) { + free(file); + if (NULL != ret_fstype) { + *ret_fstype = NULL; } return false; } @@ -587,15 +578,15 @@ bool opal_path_nfs(char *fname, char **ret_fstype) #if defined(USE_STATFS) /* These are uses of struct statfs */ # if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) - if (0 == fsrc && - 0 == strncasecmp(fs_types[i].f_fsname, fsbuf.f_fstypename, - sizeof(fsbuf.f_fstypename))) { + if (0 == fsrc + && 0 + == strncasecmp(fs_types[i].f_fsname, fsbuf.f_fstypename, + sizeof(fsbuf.f_fstypename))) { goto found; } # endif # if defined(HAVE_STRUCT_STATFS_F_TYPE) - if (0 == fsrc && - fs_types[i].f_fsid == (fsbuf.f_type & fs_types[i].f_mask)) { + if (0 == fsrc && fs_types[i].f_fsid == (fsbuf.f_type & fs_types[i].f_mask)) { goto found; } # endif @@ -604,31 +595,33 @@ bool opal_path_nfs(char *fname, char **ret_fstype) #if defined(HAVE_STATVFS) /* These are uses of struct statvfs */ # if defined(HAVE_STRUCT_STATVFS_F_BASETYPE) - if (0 == vfsrc && - 0 == strncasecmp(fs_types[i].f_fsname, vfsbuf.f_basetype, - sizeof(vfsbuf.f_basetype))) { + if (0 == vfsrc + && 0 + == strncasecmp(fs_types[i].f_fsname, vfsbuf.f_basetype, + sizeof(vfsbuf.f_basetype))) { goto found; } # endif # if defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) - if (0 == vfsrc && - 0 == strncasecmp(fs_types[i].f_fsname, vfsbuf.f_fstypename, - sizeof(vfsbuf.f_fstypename))) { + if (0 == vfsrc + && 0 + == strncasecmp(fs_types[i].f_fsname, vfsbuf.f_fstypename, + sizeof(vfsbuf.f_fstypename))) { goto found; } # endif #endif } - free (file); - if ( NULL != ret_fstype ) { - *ret_fstype=NULL; + free(file); + if (NULL != ret_fstype) { + *ret_fstype = NULL; } return false; found: - free (file); + free(file); if (AUTOFS_SUPER_MAGIC == fs_types[i].f_fsid) { char *fs_type = opal_check_mtab(fname); int x; @@ -638,35 +631,33 @@ bool opal_path_nfs(char *fname, char **ret_fstype) continue; } if (0 == strcasecmp(fs_types[x].f_fsname, fs_type)) { - OPAL_OUTPUT_VERBOSE((10, 0, "opal_path_nfs: file:%s on fs:%s\n", fname, fs_type)); + OPAL_OUTPUT_VERBOSE( + (10, 0, "opal_path_nfs: file:%s on fs:%s\n", fname, fs_type)); free(fs_type); - if ( NULL != ret_fstype ) { + if (NULL != ret_fstype) { *ret_fstype = strdup(fs_types[x].f_fsname); } return true; } } free(fs_type); - if ( NULL != ret_fstype ) { - *ret_fstype=NULL; + if (NULL != ret_fstype) { + *ret_fstype = NULL; } return false; } } - OPAL_OUTPUT_VERBOSE((10, 0, "opal_path_nfs: file:%s on fs:%s\n", - fname, fs_types[i].f_fsname)); - if ( NULL != ret_fstype ) { - *ret_fstype = strdup (fs_types[i].f_fsname); + OPAL_OUTPUT_VERBOSE((10, 0, "opal_path_nfs: file:%s on fs:%s\n", fname, fs_types[i].f_fsname)); + if (NULL != ret_fstype) { + *ret_fstype = strdup(fs_types[i].f_fsname); } return true; #undef FS_TYPES_NUM } -int -opal_path_df(const char *path, - uint64_t *out_avail) +int opal_path_df(const char *path, uint64_t *out_avail) { int rc = -1; int trials = 5; @@ -692,18 +683,20 @@ opal_path_df(const char *path, } while (-1 == rc && ESTALE == err && (--trials > 0)); if (-1 == rc) { - OPAL_OUTPUT_VERBOSE((10, 2, "opal_path_df: stat(v)fs on " + OPAL_OUTPUT_VERBOSE((10, 2, + "opal_path_df: stat(v)fs on " "path: %s failed with errno: %d (%s)\n", path, err, strerror(err))); return OPAL_ERROR; } /* now set the amount of free space available on path */ - /* sometimes buf.f_bavail is negative */ - *out_avail = (uint64_t)buf.f_bsize * (uint64_t)((long)buf.f_bavail < 0 ? 0 : buf.f_bavail); + /* sometimes buf.f_bavail is negative */ + *out_avail = (uint64_t) buf.f_bsize * (uint64_t)((long) buf.f_bavail < 0 ? 0 : buf.f_bavail); - OPAL_OUTPUT_VERBOSE((10, 2, "opal_path_df: stat(v)fs states " - "path: %s has %"PRIu64 " B of free space.", + OPAL_OUTPUT_VERBOSE((10, 2, + "opal_path_df: stat(v)fs states " + "path: %s has %" PRIu64 " B of free space.", path, *out_avail)); return OPAL_SUCCESS; diff --git a/opal/util/path.h b/opal/util/path.h index d723545159b..64674e4e886 100644 --- a/opal/util/path.h +++ b/opal/util/path.h @@ -29,7 +29,7 @@ #include "opal/constants.h" #ifdef HAVE_UNISTD_H -#include +# include #endif BEGIN_C_DECLS @@ -53,8 +53,8 @@ BEGIN_C_DECLS * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_path_find(char *fname, char **pathv, int mode, - char **envv) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_path_find(char *fname, char **pathv, int mode, char **envv) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; /** * Locates a file with certain permissions from a list of search @@ -74,8 +74,8 @@ OPAL_DECLSPEC char *opal_path_find(char *fname, char **pathv, int mode, * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_path_findv(char *fname, int mode, - char **envv, char *wrkdir) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_path_findv(char *fname, int mode, char **envv, char *wrkdir) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; /** * Detect if the requested path is absolute or relative. * @@ -88,7 +88,7 @@ OPAL_DECLSPEC char *opal_path_findv(char *fname, int mode, * with special care as an absolute path on Windows starts * with [A-Za-z]: or \\ instead of the usual / on UNIX. */ -OPAL_DECLSPEC bool opal_path_is_absolute( const char *path ); +OPAL_DECLSPEC bool opal_path_is_absolute(const char *path); /** * Find the absolute path for an executable and return it. @@ -107,7 +107,7 @@ OPAL_DECLSPEC bool opal_path_is_absolute( const char *path ); * function will return NULL. Otherwise, an newly allocated string * will be returned. */ -OPAL_DECLSPEC char* opal_find_absolute_path( char* app_name ) __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_find_absolute_path(char *app_name) __opal_attribute_warn_unused_result__; /** * Forms a complete pathname and checks it for existance and @@ -122,8 +122,8 @@ OPAL_DECLSPEC char* opal_find_absolute_path( char* app_name ) __opal_attribute_w * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_path_access(char *fname, char *path, int mode) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; - +OPAL_DECLSPEC char *opal_path_access(char *fname, char *path, int mode) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; /** * @brief Figure out, whether fname is on network file system @@ -153,9 +153,8 @@ OPAL_DECLSPEC bool opal_path_nfs(char *fname, char **fstype) __opal_attribute_wa * @retval OPAL_SUCCESS If the operation was successful * @retval OPAL_ERROR otherwise */ -OPAL_DECLSPEC int -opal_path_df(const char *path, - uint64_t *out_avail)__opal_attribute_warn_unused_result__; +OPAL_DECLSPEC int opal_path_df(const char *path, + uint64_t *out_avail) __opal_attribute_warn_unused_result__; END_C_DECLS #endif /* OPAL_PATH_H */ diff --git a/opal/util/printf.c b/opal/util/printf.c index fad3d949157..da88c2b28d2 100644 --- a/opal/util/printf.c +++ b/opal/util/printf.c @@ -24,15 +24,14 @@ #include "opal_config.h" -#include "opal/util/printf.h" #include "opal/util/output.h" +#include "opal/util/printf.h" #include #include #include #include - #ifndef HAVE_VASPRINTF /* * Make a good guess about how long a printf-style varargs formatted @@ -42,13 +41,13 @@ */ static int guess_strlen(const char *fmt, va_list ap) { -#if HAVE_VSNPRINTF +# if HAVE_VSNPRINTF char dummy[1]; /* vsnprintf() returns the number of bytes that would have been copied if the provided buffer were infinite. */ return 1 + vsnprintf(dummy, sizeof(dummy), fmt, ap); -#else +# else char *sarg, carg; double darg; float farg; @@ -60,16 +59,16 @@ static int guess_strlen(const char *fmt, va_list ap) /* Start off with a fudge factor of 128 to handle the % escapes that we aren't calculating here */ - len = (int)strlen(fmt) + 128; + len = (int) strlen(fmt) + 128; for (i = 0; i < strlen(fmt); ++i) { - if ('%' == fmt[i] && i + 1 < strlen(fmt) - && '%' != fmt[i + 1]) { + if ('%' == fmt[i] && i + 1 < strlen(fmt) && '%' != fmt[i + 1]) { ++i; switch (fmt[i]) { case 'c': carg = va_arg(ap, int); - len += 1; /* let's suppose it's a printable char */ - (void)carg; /* prevent compiler from complaining about set but not used variables */ + len += 1; /* let's suppose it's a printable char */ + (void) + carg; /* prevent compiler from complaining about set but not used variables */ break; case 's': sarg = va_arg(ap, char *); @@ -78,11 +77,11 @@ static int guess_strlen(const char *fmt, va_list ap) * use (null) */ if (NULL != sarg) { - len += (int)strlen(sarg); + len += (int) strlen(sarg); } else { -#if OPAL_ENABLE_DEBUG +# if OPAL_ENABLE_DEBUG opal_output(0, "OPAL DEBUG WARNING: Got a NULL argument to opal_vasprintf!\n"); -#endif +# endif len += 5; } break; @@ -111,7 +110,7 @@ static int guess_strlen(const char *fmt, va_list ap) break; case 'f': - farg = (float)va_arg(ap, int); + farg = (float) va_arg(ap, int); /* Alloc for minus sign */ if (farg < 0) { ++len; @@ -192,7 +191,7 @@ static int guess_strlen(const char *fmt, va_list ap) } return len; -#endif +# endif } #endif /* #ifndef HAVE_VASPRINTF */ @@ -209,7 +208,6 @@ int opal_asprintf(char **ptr, const char *fmt, ...) return length; } - int opal_vasprintf(char **ptr, const char *fmt, va_list ap) { #ifdef HAVE_VASPRINTF @@ -228,13 +226,13 @@ int opal_vasprintf(char **ptr, const char *fmt, va_list ap) /* va_list might have pointer to internal state and using it twice is a bad idea. So make a copy for the second use. Copy order taken from Autoconf docs. */ -#if OPAL_HAVE_VA_COPY +# if OPAL_HAVE_VA_COPY va_copy(ap2, ap); -#elif OPAL_HAVE_UNDERSCORE_VA_COPY +# elif OPAL_HAVE_UNDERSCORE_VA_COPY __va_copy(ap2, ap); -#else - memcpy (&ap2, &ap, sizeof(va_list)); -#endif +# else + memcpy(&ap2, &ap, sizeof(va_list)); +# endif /* guess the size */ length = guess_strlen(fmt, ap); @@ -249,12 +247,12 @@ int opal_vasprintf(char **ptr, const char *fmt, va_list ap) /* fill the buffer */ length = vsprintf(*ptr, fmt, ap2); -#if OPAL_HAVE_VA_COPY || OPAL_HAVE_UNDERSCORE_VA_COPY +# if OPAL_HAVE_VA_COPY || OPAL_HAVE_UNDERSCORE_VA_COPY va_end(ap2); -#endif /* OPAL_HAVE_VA_COPY || OPAL_HAVE_UNDERSCORE_VA_COPY */ +# endif /* OPAL_HAVE_VA_COPY || OPAL_HAVE_UNDERSCORE_VA_COPY */ /* realloc */ - *ptr = (char*) realloc(*ptr, (size_t) length + 1); + *ptr = (char *) realloc(*ptr, (size_t) length + 1); if (NULL == *ptr) { errno = ENOMEM; return -1; @@ -264,7 +262,6 @@ int opal_vasprintf(char **ptr, const char *fmt, va_list ap) #endif } - int opal_snprintf(char *str, size_t size, const char *fmt, ...) { int length; @@ -277,7 +274,6 @@ int opal_snprintf(char *str, size_t size, const char *fmt, ...) return length; } - int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) { int length; @@ -304,7 +300,6 @@ int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) return length; } - #ifdef TEST int main(int argc, char *argv[]) diff --git a/opal/util/printf.h b/opal/util/printf.h index 1b18d036762..3f7ba0054ff 100644 --- a/opal/util/printf.h +++ b/opal/util/printf.h @@ -51,8 +51,8 @@ BEGIN_C_DECLS * * THIS IS A PORTABILITY FEATURE: USE snprintf() in CODE. */ -OPAL_DECLSPEC int opal_snprintf(char *str, size_t size, const char *fmt, ...) __opal_attribute_format__(__printf__, 3, 4); - +OPAL_DECLSPEC int opal_snprintf(char *str, size_t size, const char *fmt, ...) + __opal_attribute_format__(__printf__, 3, 4); /** * Writes to a string under the control of a format string that @@ -76,7 +76,8 @@ OPAL_DECLSPEC int opal_snprintf(char *str, size_t size, const char *fmt, ...) _ * * THIS IS A PORTABILITY FEATURE: USE vsnprintf() in CODE. */ -OPAL_DECLSPEC int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __opal_attribute_format__(__printf__, 3, 0); +OPAL_DECLSPEC int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) + __opal_attribute_format__(__printf__, 3, 0); /** * Allocates and writes to a string under the control of a format @@ -102,8 +103,8 @@ OPAL_DECLSPEC int opal_vsnprintf(char *str, size_t size, const char *fmt, va_li * such behavior. * */ -OPAL_DECLSPEC int opal_asprintf(char **ptr, const char *fmt, ...) __opal_attribute_format__(__printf__, 2, 3); - +OPAL_DECLSPEC int opal_asprintf(char **ptr, const char *fmt, ...) + __opal_attribute_format__(__printf__, 2, 3); /** * Allocates and writes to a string under the control of a format @@ -131,10 +132,9 @@ OPAL_DECLSPEC int opal_asprintf(char **ptr, const char *fmt, ...) __opal_attrib * such behavior. * */ -OPAL_DECLSPEC int opal_vasprintf(char **ptr, const char *fmt, va_list ap) __opal_attribute_format__(__printf__, 2, 0); - +OPAL_DECLSPEC int opal_vasprintf(char **ptr, const char *fmt, va_list ap) + __opal_attribute_format__(__printf__, 2, 0); END_C_DECLS #endif /* OPAL_PRINTF_H */ - diff --git a/opal/util/proc.c b/opal/util/proc.c index 06f35b8ef54..c309e1a7f98 100644 --- a/opal/util/proc.c +++ b/opal/util/proc.c @@ -20,11 +20,11 @@ #include "opal_config.h" -#include "proc.h" -#include "opal/util/proc.h" +#include "opal/mca/pmix/pmix-internal.h" #include "opal/util/arch.h" +#include "opal/util/proc.h" #include "opal/util/string_copy.h" -#include "opal/mca/pmix/pmix-internal.h" +#include "proc.h" opal_process_name_t opal_name_wildcard = {OPAL_JOBID_WILDCARD, OPAL_VPID_WILDCARD}; opal_process_name_t opal_name_invalid = {OPAL_JOBID_INVALID, OPAL_VPID_INVALID}; @@ -37,8 +37,8 @@ opal_process_info_t opal_process_info = { .top_session_dir = NULL, .job_session_dir = NULL, .proc_session_dir = NULL, - .num_local_peers = 0, /* there is nobody else but me */ - .my_local_rank = 0, /* I'm the only process around here */ + .num_local_peers = 0, /* there is nobody else but me */ + .my_local_rank = 0, /* I'm the only process around here */ .my_node_rank = 0, .cpuset = NULL, .locality = NULL, @@ -56,17 +56,14 @@ opal_process_info_t opal_process_info = { .initial_errhandler = NULL, }; -static opal_proc_t opal_local_proc = { - { .opal_list_next = NULL, - .opal_list_prev = NULL}, - .proc_name = {OPAL_JOBID_INVALID, OPAL_VPID_INVALID}, - .proc_arch = 0, - .proc_flags = 0, - .proc_convertor = NULL -}; -static opal_proc_t* opal_proc_my_name = &opal_local_proc; +static opal_proc_t opal_local_proc = {{.opal_list_next = NULL, .opal_list_prev = NULL}, + .proc_name = {OPAL_JOBID_INVALID, OPAL_VPID_INVALID}, + .proc_arch = 0, + .proc_flags = 0, + .proc_convertor = NULL}; +static opal_proc_t *opal_proc_my_name = &opal_local_proc; -static void opal_proc_construct(opal_proc_t* proc) +static void opal_proc_construct(opal_proc_t *proc) { proc->proc_arch = opal_local_arch; proc->proc_convertor = NULL; @@ -74,33 +71,29 @@ static void opal_proc_construct(opal_proc_t* proc) proc->proc_name = *OPAL_NAME_INVALID; } -static void opal_proc_destruct(opal_proc_t* proc) +static void opal_proc_destruct(opal_proc_t *proc) { - proc->proc_flags = 0; - proc->proc_name = *OPAL_NAME_INVALID; + proc->proc_flags = 0; + proc->proc_name = *OPAL_NAME_INVALID; proc->proc_convertor = NULL; } -OBJ_CLASS_INSTANCE(opal_proc_t, opal_list_item_t, - opal_proc_construct, opal_proc_destruct); +OBJ_CLASS_INSTANCE(opal_proc_t, opal_list_item_t, opal_proc_construct, opal_proc_destruct); -OBJ_CLASS_INSTANCE(opal_namelist_t, opal_list_item_t, - NULL, NULL); +OBJ_CLASS_INSTANCE(opal_namelist_t, opal_list_item_t, NULL, NULL); -static int -opal_compare_opal_procs(const opal_process_name_t p1, - const opal_process_name_t p2) +static int opal_compare_opal_procs(const opal_process_name_t p1, const opal_process_name_t p2) { - if( p1.jobid < p2.jobid ) { - return -1; + if (p1.jobid < p2.jobid) { + return -1; } - if( p1.jobid > p2.jobid ) { - return 1; + if (p1.jobid > p2.jobid) { + return 1; } - if( p1.vpid < p2.vpid ) { + if (p1.vpid < p2.vpid) { return -1; } - if( p1.vpid > p2.vpid ) { + if (p1.vpid > p2.vpid) { return 1; } return 0; @@ -108,19 +101,20 @@ opal_compare_opal_procs(const opal_process_name_t p1, opal_compare_proc_fct_t opal_compare_proc = opal_compare_opal_procs; -opal_proc_t* opal_proc_local_get(void) +opal_proc_t *opal_proc_local_get(void) { return opal_proc_my_name; } -int opal_proc_local_set(opal_proc_t* proc) +int opal_proc_local_set(opal_proc_t *proc) { - if( proc != opal_proc_my_name ) { - if( NULL != proc ) + if (proc != opal_proc_my_name) { + if (NULL != proc) OBJ_RETAIN(proc); - if( &opal_local_proc != opal_proc_my_name ) + if (&opal_local_proc != opal_proc_my_name) { OBJ_RELEASE(opal_proc_my_name); - if( NULL != proc ) { + } + if (NULL != proc) { opal_proc_my_name = proc; } else { opal_proc_my_name = &opal_local_proc; @@ -145,62 +139,68 @@ void opal_proc_set_name(opal_process_name_t *name) * before the call to opal_init, to make them point to the correct accessors based on the * underlying RTE. */ -static char* -opal_process_name_print_should_never_be_called(const opal_process_name_t procname) +static char *opal_process_name_print_should_never_be_called(const opal_process_name_t procname) { return "My Name is Nobody"; } -static char* -opal_vpid_print_should_never_be_called(const opal_vpid_t unused) +static char *opal_vpid_print_should_never_be_called(const opal_vpid_t unused) { return "My VPID"; } -static char* -opal_jobid_print_should_never_be_called(const opal_jobid_t unused) +static char *opal_jobid_print_should_never_be_called(const opal_jobid_t unused) { return "My JOBID"; } static int opal_convert_string_to_process_name_should_never_be_called(opal_process_name_t *name, - const char* name_string) + const char *name_string) { return OPAL_ERR_NOT_SUPPORTED; } -static int opal_convert_process_name_to_string_should_never_be_called(char** name_string, - const opal_process_name_t *name) +static int +opal_convert_process_name_to_string_should_never_be_called(char **name_string, + const opal_process_name_t *name) { return OPAL_ERR_NOT_SUPPORTED; } -static int opal_snprintf_jobid_should_never_be_called(char* name_string, size_t size, opal_jobid_t jobid) +static int opal_snprintf_jobid_should_never_be_called(char *name_string, size_t size, + opal_jobid_t jobid) { - (void)opal_string_copy(name_string, "My JOBID", size); + (void) opal_string_copy(name_string, "My JOBID", size); return OPAL_SUCCESS; } -static int opal_convert_string_to_jobid_should_never_be_called(opal_jobid_t *jobid, const char *jobid_string) +static int opal_convert_string_to_jobid_should_never_be_called(opal_jobid_t *jobid, + const char *jobid_string) { return OPAL_ERR_NOT_SUPPORTED; } -static struct opal_proc_t *opal_proc_for_name_should_never_be_called (opal_process_name_t name) +static struct opal_proc_t *opal_proc_for_name_should_never_be_called(opal_process_name_t name) { return NULL; } -char* (*opal_process_name_print)(const opal_process_name_t) = opal_process_name_print_should_never_be_called; -char* (*opal_vpid_print)(const opal_vpid_t) = opal_vpid_print_should_never_be_called; -char* (*opal_jobid_print)(const opal_jobid_t) = opal_jobid_print_should_never_be_called; -int (*opal_convert_string_to_process_name)(opal_process_name_t *name, const char* name_string) = opal_convert_string_to_process_name_should_never_be_called; -int (*opal_convert_process_name_to_string)(char** name_string, const opal_process_name_t *name) = opal_convert_process_name_to_string_should_never_be_called; -int (*opal_snprintf_jobid)(char* name_string, size_t size, opal_jobid_t jobid) = opal_snprintf_jobid_should_never_be_called; -int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, const char *jobid_string) = opal_convert_string_to_jobid_should_never_be_called; -struct opal_proc_t *(*opal_proc_for_name) (const opal_process_name_t name) = opal_proc_for_name_should_never_be_called; - -char* opal_get_proc_hostname(const opal_proc_t *proc) +char *(*opal_process_name_print)(const opal_process_name_t) + = opal_process_name_print_should_never_be_called; +char *(*opal_vpid_print)(const opal_vpid_t) = opal_vpid_print_should_never_be_called; +char *(*opal_jobid_print)(const opal_jobid_t) = opal_jobid_print_should_never_be_called; +int (*opal_convert_string_to_process_name)(opal_process_name_t *name, const char *name_string) + = opal_convert_string_to_process_name_should_never_be_called; +int (*opal_convert_process_name_to_string)(char **name_string, const opal_process_name_t *name) + = opal_convert_process_name_to_string_should_never_be_called; +int (*opal_snprintf_jobid)(char *name_string, size_t size, opal_jobid_t jobid) + = opal_snprintf_jobid_should_never_be_called; +int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, const char *jobid_string) + = opal_convert_string_to_jobid_should_never_be_called; +struct opal_proc_t *(*opal_proc_for_name)(const opal_process_name_t name) + = opal_proc_for_name_should_never_be_called; + +char *opal_get_proc_hostname(const opal_proc_t *proc) { int ret; char *hostname; @@ -217,10 +217,10 @@ char* opal_get_proc_hostname(const opal_proc_t *proc) } /* if we don't already have it, then try to get it */ - OPAL_MODEX_RECV_VALUE_OPTIONAL(ret, PMIX_HOSTNAME, &proc->proc_name, - (char**)&hostname, PMIX_STRING); + OPAL_MODEX_RECV_VALUE_OPTIONAL(ret, PMIX_HOSTNAME, &proc->proc_name, (char **) &hostname, + PMIX_STRING); if (OPAL_SUCCESS != ret) { - return strdup("unknown"); // return something so the caller doesn't segfault + return strdup("unknown"); // return something so the caller doesn't segfault } /* user is not allowed to release the data */ diff --git a/opal/util/proc.h b/opal/util/proc.h index 9d871edded1..433735e50f3 100644 --- a/opal/util/proc.h +++ b/opal/util/proc.h @@ -27,7 +27,7 @@ #include "opal/types.h" #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT -#include +# include #endif /** @@ -39,39 +39,40 @@ * only be used via the accessors defined below. */ #define OPAL_JOBID_T OPAL_UINT32 -#define OPAL_JOBID_MAX UINT32_MAX-2 +#define OPAL_JOBID_MAX UINT32_MAX - 2 #define OPAL_JOBID_MIN 0 #define OPAL_JOBID_INVALID (OPAL_JOBID_MAX + 2) #define OPAL_JOBID_WILDCARD (OPAL_JOBID_MAX + 1) -#define OPAL_VPID_T OPAL_UINT32 -#define OPAL_VPID_MAX UINT32_MAX-2 -#define OPAL_VPID_MIN 0 -#define OPAL_VPID_INVALID (OPAL_VPID_MAX + 2) -#define OPAL_VPID_WILDCARD (OPAL_VPID_MAX + 1) +#define OPAL_VPID_T OPAL_UINT32 +#define OPAL_VPID_MAX UINT32_MAX - 2 +#define OPAL_VPID_MIN 0 +#define OPAL_VPID_INVALID (OPAL_VPID_MAX + 2) +#define OPAL_VPID_WILDCARD (OPAL_VPID_MAX + 1) -#define OPAL_PROC_MY_NAME (opal_proc_local_get()->proc_name) -#define OPAL_PROC_MY_HOSTNAME (opal_process_info.nodename) +#define OPAL_PROC_MY_NAME (opal_proc_local_get()->proc_name) +#define OPAL_PROC_MY_HOSTNAME (opal_process_info.nodename) -#define OPAL_NAME_WILDCARD (&opal_name_wildcard) +#define OPAL_NAME_WILDCARD (&opal_name_wildcard) OPAL_DECLSPEC extern opal_process_name_t opal_name_wildcard; -#define OPAL_NAME_INVALID (&opal_name_invalid) +#define OPAL_NAME_INVALID (&opal_name_invalid) OPAL_DECLSPEC extern opal_process_name_t opal_name_invalid; - -#define OPAL_NAME_ARGS(n) \ - (unsigned long) ((NULL == n) ? (unsigned long)OPAL_JOBID_INVALID : (unsigned long)(n)->jobid), \ - (unsigned long) ((NULL == n) ? (unsigned long)OPAL_VPID_INVALID : (unsigned long)(n)->vpid) \ +#define OPAL_NAME_ARGS(n) \ + (unsigned long) ((NULL == n) ? (unsigned long) OPAL_JOBID_INVALID \ + : (unsigned long) (n)->jobid), \ + (unsigned long) ((NULL == n) ? (unsigned long) OPAL_VPID_INVALID \ + : (unsigned long) (n)->vpid) #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT && !defined(WORDS_BIGENDIAN) -#define OPAL_PROCESS_NAME_NTOH(guid) opal_process_name_ntoh_intr(&(guid)) +# define OPAL_PROCESS_NAME_NTOH(guid) opal_process_name_ntoh_intr(&(guid)) static inline __opal_attribute_always_inline__ void opal_process_name_ntoh_intr(opal_process_name_t *name) { name->jobid = ntohl(name->jobid); name->vpid = ntohl(name->vpid); } -#define OPAL_PROCESS_NAME_HTON(guid) opal_process_name_hton_intr(&(guid)) +# define OPAL_PROCESS_NAME_HTON(guid) opal_process_name_hton_intr(&(guid)) static inline __opal_attribute_always_inline__ void opal_process_name_hton_intr(opal_process_name_t *name) { @@ -79,21 +80,21 @@ opal_process_name_hton_intr(opal_process_name_t *name) name->vpid = htonl(name->vpid); } #else -#define OPAL_PROCESS_NAME_NTOH(guid) -#define OPAL_PROCESS_NAME_HTON(guid) +# define OPAL_PROCESS_NAME_NTOH(guid) +# define OPAL_PROCESS_NAME_HTON(guid) #endif typedef struct opal_proc_t { /** allow proc to be placed on a list */ - opal_list_item_t super; + opal_list_item_t super; /** this process' name */ - opal_process_name_t proc_name; + opal_process_name_t proc_name; /** architecture of this process */ - uint32_t proc_arch; + uint32_t proc_arch; /** flags for this proc */ - opal_hwloc_locality_t proc_flags; + opal_hwloc_locality_t proc_flags; /** Base convertor for the proc described by this process */ - struct opal_convertor_t* proc_convertor; + struct opal_convertor_t *proc_convertor; } opal_proc_t; OBJ_CLASS_DECLARATION(opal_proc_t); @@ -106,16 +107,16 @@ OBJ_CLASS_DECLARATION(opal_namelist_t); typedef struct opal_process_info_t { opal_process_name_t my_name; pmix_proc_t myprocid; - bool nativelaunch; /**< launched by mpirun */ - char *nodename; /**< string name for this node */ - char *top_session_dir; /**< Top-level session directory */ - char *job_session_dir; /**< Session directory for job */ - char *proc_session_dir; /**< Session directory for the process */ - uint32_t num_local_peers; /**< number of procs from my job that share my node with me */ - uint16_t my_local_rank; /**< local rank on this node within my job */ + bool nativelaunch; /**< launched by mpirun */ + char *nodename; /**< string name for this node */ + char *top_session_dir; /**< Top-level session directory */ + char *job_session_dir; /**< Session directory for job */ + char *proc_session_dir; /**< Session directory for the process */ + uint32_t num_local_peers; /**< number of procs from my job that share my node with me */ + uint16_t my_local_rank; /**< local rank on this node within my job */ uint16_t my_node_rank; - char *cpuset; /**< String-representation of bitmap where we are bound */ - char *locality; /**< String-representation of process locality */ + char *cpuset; /**< String-representation of bitmap where we are bound */ + char *locality; /**< String-representation of process locality */ pid_t pid; uint32_t num_procs; uint32_t app_num; @@ -131,8 +132,8 @@ typedef struct opal_process_info_t { } opal_process_info_t; OPAL_DECLSPEC extern opal_process_info_t opal_process_info; -OPAL_DECLSPEC extern opal_proc_t* opal_proc_local_get(void); -OPAL_DECLSPEC extern int opal_proc_local_set(opal_proc_t* proc); +OPAL_DECLSPEC extern opal_proc_t *opal_proc_local_get(void); +OPAL_DECLSPEC extern int opal_proc_local_set(opal_proc_t *proc); OPAL_DECLSPEC extern void opal_proc_set_name(opal_process_name_t *name); /** @@ -144,31 +145,32 @@ typedef int (*opal_compare_proc_fct_t)(const opal_process_name_t, const opal_pro OPAL_DECLSPEC extern opal_compare_proc_fct_t opal_compare_proc; /* Provide print functions that will be overwritten by the RTE layer */ -OPAL_DECLSPEC extern char* (*opal_process_name_print)(const opal_process_name_t); +OPAL_DECLSPEC extern char *(*opal_process_name_print)(const opal_process_name_t); OPAL_DECLSPEC extern int (*opal_convert_string_to_process_name)(opal_process_name_t *name, - const char* name_string); -OPAL_DECLSPEC extern int (*opal_convert_process_name_to_string)(char** name_string, + const char *name_string); +OPAL_DECLSPEC extern int (*opal_convert_process_name_to_string)(char **name_string, const opal_process_name_t *name); -OPAL_DECLSPEC extern char* (*opal_vpid_print)(const opal_vpid_t); -OPAL_DECLSPEC extern char* (*opal_jobid_print)(const opal_jobid_t); -OPAL_DECLSPEC extern int (*opal_snprintf_jobid)(char* name_string, size_t size, opal_jobid_t jobid); -OPAL_DECLSPEC extern int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, const char *jobid_string); +OPAL_DECLSPEC extern char *(*opal_vpid_print)(const opal_vpid_t); +OPAL_DECLSPEC extern char *(*opal_jobid_print)(const opal_jobid_t); +OPAL_DECLSPEC extern int (*opal_snprintf_jobid)(char *name_string, size_t size, opal_jobid_t jobid); +OPAL_DECLSPEC extern int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, + const char *jobid_string); /** * Lookup an opal_proc_t by name * * @param name (IN) name to lookup */ -OPAL_DECLSPEC extern struct opal_proc_t *(*opal_proc_for_name) (const opal_process_name_t name); +OPAL_DECLSPEC extern struct opal_proc_t *(*opal_proc_for_name)(const opal_process_name_t name); -#define OPAL_NAME_PRINT(OPAL_PN) opal_process_name_print(OPAL_PN) -#define OPAL_JOBID_PRINT(OPAL_PN) opal_jobid_print(OPAL_PN) -#define OPAL_VPID_PRINT(OPAL_PN) opal_vpid_print(OPAL_PN) +#define OPAL_NAME_PRINT(OPAL_PN) opal_process_name_print(OPAL_PN) +#define OPAL_JOBID_PRINT(OPAL_PN) opal_jobid_print(OPAL_PN) +#define OPAL_VPID_PRINT(OPAL_PN) opal_vpid_print(OPAL_PN) /* provide a safe way to retrieve the hostname of a proc, including * our own. This is to be used by all BTLs so we don't retrieve hostnames * unless needed. The returned value MUST NOT be free'd as it is * owned by the proc_t */ -OPAL_DECLSPEC char* opal_get_proc_hostname(const opal_proc_t *proc); +OPAL_DECLSPEC char *opal_get_proc_hostname(const opal_proc_t *proc); -#endif /* OPAL_PROC_H */ +#endif /* OPAL_PROC_H */ diff --git a/opal/util/qsort.c b/opal/util/qsort.c index 42141f44ba2..f018f6905b9 100644 --- a/opal/util/qsort.c +++ b/opal/util/qsort.c @@ -35,143 +35,138 @@ #if OPAL_HAVE_BROKEN_QSORT -#include +# include -#include "opal/util/minmix.h" -#include "opal/util/qsort.h" +# include "opal/util/minmix.h" +# include "opal/util/qsort.h" -typedef int cmp_t(const void *, const void *); -static inline char *med3(char *, char *, char *, cmp_t *, void *); -static inline void swapfunc(char *, char *, int, int); +typedef int cmp_t(const void *, const void *); +static inline char *med3(char *, char *, char *, cmp_t *, void *); +static inline void swapfunc(char *, char *, int, int); /* * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". */ -#define swapcode(TYPE, parmi, parmj, n) { \ - long i = (n) / sizeof (TYPE); \ - TYPE *pi = (TYPE *) (parmi); \ - TYPE *pj = (TYPE *) (parmj); \ - do { \ - TYPE t = *pi; \ - *pi++ = *pj; \ - *pj++ = t; \ - } while (--i > 0); \ -} - -#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; - -static inline void -swapfunc(a, b, n, swaptype) - char *a, *b; - int n, swaptype; +# define swapcode(TYPE, parmi, parmj, n) \ + { \ + long i = (n) / sizeof(TYPE); \ + TYPE *pi = (TYPE *) (parmi); \ + TYPE *pj = (TYPE *) (parmj); \ + do { \ + TYPE t = *pi; \ + *pi++ = *pj; \ + *pj++ = t; \ + } while (--i > 0); \ + } + +# define SWAPINIT(a, es) \ + swaptype = ((char *) a - (char *) 0) % sizeof(long) || es % sizeof(long) ? 2 \ + : es == sizeof(long) ? 0 \ + : 1; + +static inline void swapfunc(a, b, n, swaptype) char *a, *b; +int n, swaptype; { - if(swaptype <= 1) - swapcode(long, a, b, n) - else - swapcode(char, a, b, n) + if (swaptype <= 1) + swapcode(long, a, b, n) else swapcode(char, a, b, n) } -#define swap(a, b) \ - if (swaptype == 0) { \ - long t = *(long *)(a); \ - *(long *)(a) = *(long *)(b); \ - *(long *)(b) = t; \ - } else \ - swapfunc(a, b, es, swaptype) +# define swap(a, b) \ + if (swaptype == 0) { \ + long t = *(long *) (a); \ + *(long *) (a) = *(long *) (b); \ + *(long *) (b) = t; \ + } else \ + swapfunc(a, b, es, swaptype) -#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) +# define vecswap(a, b, n) \ + if ((n) > 0) \ + swapfunc(a, b, n, swaptype) -#define CMP(t, x, y) (cmp((x), (y))) +# define CMP(t, x, y) (cmp((x), (y))) -static inline char * -med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk) +static inline char *med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk) { - return CMP(thunk, a, b) < 0 ? - (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) - :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); + return CMP(thunk, a, b) < 0 ? (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a)) + : (CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c)); } -#define thunk NULL -void -opal_qsort(void *a, size_t n, size_t es, cmp_t *cmp) +# define thunk NULL +void opal_qsort(void *a, size_t n, size_t es, cmp_t *cmp) { - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; - -loop: SWAPINIT(a, es); - swap_cnt = 0; - if (n < 7) { - for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) - for (pl = pm; - pl > (char *)a && CMP(thunk, pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - pm = (char *)a + (n / 2) * es; - if (n > 7) { - pl = a; - pn = (char *)a + (n - 1) * es; - if (n > 40) { - d = (n / 8) * es; - pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); - pm = med3(pm - d, pm, pm + d, cmp, thunk); - pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); - } - pm = med3(pl, pm, pn, cmp, thunk); - } - swap(a, pm); - pa = pb = (char *)a + es; - - pc = pd = (char *)a + (n - 1) * es; - for (;;) { - while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pa, pb); - pa += es; - } - pb += es; - } - while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pc, pd); - pd -= es; - } - pc -= es; - } - if (pb > pc) - break; - swap(pb, pc); - swap_cnt = 1; - pb += es; - pc -= es; - } - if (swap_cnt == 0) { /* Switch to insertion sort */ - for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) - for (pl = pm; - pl > (char *)a && CMP(thunk, pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - - pn = (char *)a + n * es; - r = (int) opal_min(pa - (char *)a, pb - pa); - vecswap(a, pb - r, r); - r = (int) (opal_min((char*) (pd - pc), (char*) (pn - pd - es))); - vecswap(pb, pn - r, r); - if ((size_t) (r = pb - pa) > es) - opal_qsort(a, r / es, es, cmp); - if ((size_t) (r = pd - pc) > es) { - /* Iterate rather than recurse to save stack space */ - a = pn - r; - n = r / es; - goto loop; - } -/* qsort(pn - r, r / es, es, cmp);*/ + char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + int d, r, swaptype, swap_cnt; + +loop: + SWAPINIT(a, es); + swap_cnt = 0; + if (n < 7) { + for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) + for (pl = pm; pl > (char *) a && CMP(thunk, pl - es, pl) > 0; pl -= es) + swap(pl, pl - es); + return; + } + pm = (char *) a + (n / 2) * es; + if (n > 7) { + pl = a; + pn = (char *) a + (n - 1) * es; + if (n > 40) { + d = (n / 8) * es; + pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); + pm = med3(pm - d, pm, pm + d, cmp, thunk); + pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); + } + pm = med3(pl, pm, pn, cmp, thunk); + } + swap(a, pm); + pa = pb = (char *) a + es; + + pc = pd = (char *) a + (n - 1) * es; + for (;;) { + while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pa, pb); + pa += es; + } + pb += es; + } + while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pc, pd); + pd -= es; + } + pc -= es; + } + if (pb > pc) + break; + swap(pb, pc); + swap_cnt = 1; + pb += es; + pc -= es; + } + if (swap_cnt == 0) { /* Switch to insertion sort */ + for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) + for (pl = pm; pl > (char *) a && CMP(thunk, pl - es, pl) > 0; pl -= es) + swap(pl, pl - es); + return; + } + + pn = (char *) a + n * es; + r = (int) opal_min(pa - (char *) a, pb - pa); + vecswap(a, pb - r, r); + r = (int) (opal_min((char *) (pd - pc), (char *) (pn - pd - es))); + vecswap(pb, pn - r, r); + if ((size_t)(r = pb - pa) > es) + opal_qsort(a, r / es, es, cmp); + if ((size_t)(r = pd - pc) > es) { + /* Iterate rather than recurse to save stack space */ + a = pn - r; + n = r / es; + goto loop; + } + /* qsort(pn - r, r / es, es, cmp);*/ } #endif /* OPAL_HAVE_BROKEN_QSORT */ diff --git a/opal/util/qsort.h b/opal/util/qsort.h index cd6b77c0813..013707e5c94 100644 --- a/opal/util/qsort.h +++ b/opal/util/qsort.h @@ -21,18 +21,18 @@ #if OPAL_HAVE_BROKEN_QSORT -#ifdef HAVE_SYS_TYPES_H -#include /* for size_t */ -#endif +# ifdef HAVE_SYS_TYPES_H +# include /* for size_t */ +# endif BEGIN_C_DECLS -void opal_qsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void*)); +void opal_qsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *)); END_C_DECLS #else -#error "Don't include opal/qsort/qsort.h directly" +# error "Don't include opal/qsort/qsort.h directly" #endif /* OPAL_HAVE_BROKEN_QSORT */ #endif diff --git a/opal/util/show_help.c b/opal/util/show_help.c index d84f42d16b8..512a09b0818 100644 --- a/opal/util/show_help.c +++ b/opal/util/show_help.c @@ -25,43 +25,42 @@ #include "opal_config.h" +#include +#include #include #include -#include -#include -#include "opal/runtime/opal.h" +#include "opal/constants.h" #include "opal/mca/installdirs/installdirs.h" -#include "opal/util/show_help.h" -#include "opal/util/show_help_lex.h" -#include "opal/util/printf.h" +#include "opal/runtime/opal.h" #include "opal/util/argv.h" #include "opal/util/os_path.h" #include "opal/util/output.h" -#include "opal/constants.h" - +#include "opal/util/printf.h" +#include "opal/util/show_help.h" +#include "opal/util/show_help_lex.h" /* * Private variables */ static const char *default_filename = "help-messages"; -static const char *dash_line = "--------------------------------------------------------------------------\n"; +static const char *dash_line + = "--------------------------------------------------------------------------\n"; static int output_stream = -1; static char **search_dirs = NULL; /* * Local functions */ -static int opal_show_vhelp_internal(const char *filename, const char *topic, - int want_error_header, va_list arglist); -static int opal_show_help_internal(const char *filename, const char *topic, - int want_error_header, ...); -static void opal_show_help_finalize (void); +static int opal_show_vhelp_internal(const char *filename, const char *topic, int want_error_header, + va_list arglist); +static int opal_show_help_internal(const char *filename, const char *topic, int want_error_header, + ...); +static void opal_show_help_finalize(void); opal_show_help_fn_t opal_show_help = opal_show_help_internal; opal_show_vhelp_fn_t opal_show_vhelp = opal_show_vhelp_internal; - int opal_show_help_init(void) { opal_output_stream_t lds; @@ -72,12 +71,12 @@ int opal_show_help_init(void) opal_argv_append_nosize(&search_dirs, opal_install_dirs.opaldatadir); - opal_finalize_register_cleanup (opal_show_help_finalize); + opal_finalize_register_cleanup(opal_show_help_finalize); return OPAL_SUCCESS; } -static void opal_show_help_finalize (void) +static void opal_show_help_finalize(void) { opal_output_close(output_stream); output_stream = -1; @@ -94,8 +93,7 @@ static void opal_show_help_finalize (void) * efficient method in the world, but we're going for clarity here -- * not optimization. :-) */ -static int array2string(char **outstring, - int want_error_header, char **lines) +static int array2string(char **outstring, int want_error_header, char **lines) { int i, count; size_t len; @@ -113,7 +111,7 @@ static int array2string(char **outstring, /* Malloc it out */ - (*outstring) = (char*) malloc(len + 1); + (*outstring) = (char *) malloc(len + 1); if (NULL == *outstring) { return OPAL_ERR_OUT_OF_RESOURCE; } @@ -138,7 +136,6 @@ static int array2string(char **outstring, return OPAL_SUCCESS; } - /* * Find the right file to open */ @@ -162,8 +159,8 @@ static int open_file(const char *base, const char *topic) /* Try to open the file. If we can't find it, try it with a .txt * extension. */ - for (i=0; NULL != search_dirs[i]; i++) { - filename = opal_os_path( false, search_dirs[i], base, NULL ); + for (i = 0; NULL != search_dirs[i]; i++) { + filename = opal_os_path(false, search_dirs[i], base, NULL); opal_show_help_yyin = fopen(filename, "r"); if (NULL == opal_show_help_yyin) { opal_asprintf(&err_msg, "%s: %s", filename, strerror(errno)); @@ -183,7 +180,10 @@ static int open_file(const char *base, const char *topic) /* If we still couldn't open it, then something is wrong */ if (NULL == opal_show_help_yyin) { - opal_output(output_stream, "%sSorry! You were supposed to get help about:\n %s\nBut I couldn't open the help file:\n %s. Sorry!\n%s", dash_line, topic, err_msg, dash_line); + opal_output(output_stream, + "%sSorry! You were supposed to get help about:\n %s\nBut I couldn't open " + "the help file:\n %s. Sorry!\n%s", + dash_line, topic, err_msg, dash_line); free(err_msg); return OPAL_ERR_NOT_FOUND; } @@ -201,7 +201,6 @@ static int open_file(const char *base, const char *topic) return OPAL_SUCCESS; } - /* * In the file that has already been opened, find the topic that we're * supposed to output @@ -233,7 +232,10 @@ static int find_topic(const char *base, const char *topic) break; case OPAL_SHOW_HELP_PARSE_DONE: - opal_output(output_stream, "%sSorry! You were supposed to get help about:\n %s\nfrom the file:\n %s\nBut I couldn't find that topic in the file. Sorry!\n%s", dash_line, topic, base, dash_line); + opal_output(output_stream, + "%sSorry! You were supposed to get help about:\n %s\nfrom the file:\n " + " %s\nBut I couldn't find that topic in the file. Sorry!\n%s", + dash_line, topic, base, dash_line); return OPAL_ERR_NOT_FOUND; break; @@ -245,7 +247,6 @@ static int find_topic(const char *base, const char *topic) /* Never get here */ } - /* * We have an open file, and we're pointed at the right topic. So * read in all the lines in the topic and make a list of them. @@ -274,7 +275,6 @@ static int read_topic(char ***array) /* Never get here */ } - static int load_array(char ***array, const char *filename, const char *topic) { int ret; @@ -289,7 +289,7 @@ static int load_array(char ***array, const char *filename, const char *topic) } fclose(opal_show_help_yyin); - opal_show_help_yylex_destroy (); + opal_show_help_yylex_destroy(); if (OPAL_SUCCESS != ret) { opal_argv_free(*array); @@ -298,8 +298,8 @@ static int load_array(char ***array, const char *filename, const char *topic) return ret; } -char *opal_show_help_vstring(const char *filename, const char *topic, - int want_error_header, va_list arglist) +char *opal_show_help_vstring(const char *filename, const char *topic, int want_error_header, + va_list arglist) { int rc; char *single_string, *output, **array = NULL; @@ -322,28 +322,25 @@ char *opal_show_help_vstring(const char *filename, const char *topic, return (OPAL_SUCCESS == rc) ? output : NULL; } -char *opal_show_help_string(const char *filename, const char *topic, - int want_error_handler, ...) +char *opal_show_help_string(const char *filename, const char *topic, int want_error_handler, ...) { char *output; va_list arglist; va_start(arglist, want_error_handler); - output = opal_show_help_vstring(filename, topic, want_error_handler, - arglist); + output = opal_show_help_vstring(filename, topic, want_error_handler, arglist); va_end(arglist); return output; } -static int opal_show_vhelp_internal(const char *filename, const char *topic, - int want_error_header, va_list arglist) +static int opal_show_vhelp_internal(const char *filename, const char *topic, int want_error_header, + va_list arglist) { char *output; /* Convert it to a single string */ - output = opal_show_help_vstring(filename, topic, want_error_header, - arglist); + output = opal_show_help_vstring(filename, topic, want_error_header, arglist); /* If we got a single string, output it with formatting */ if (NULL != output) { @@ -354,8 +351,8 @@ static int opal_show_vhelp_internal(const char *filename, const char *topic, return (NULL == output) ? OPAL_ERROR : OPAL_SUCCESS; } -static int opal_show_help_internal(const char *filename, const char *topic, - int want_error_header, ...) +static int opal_show_help_internal(const char *filename, const char *topic, int want_error_header, + ...) { va_list arglist; int rc; diff --git a/opal/util/show_help.h b/opal/util/show_help.h index 27335fd10c6..cdcb6c80bcd 100644 --- a/opal/util/show_help.h +++ b/opal/util/show_help.h @@ -127,33 +127,31 @@ OPAL_DECLSPEC int opal_show_help_init(void); * promotion to va_start() has undefined behavior (according to clang * warnings on MacOS High Sierra). */ -typedef int (*opal_show_help_fn_t)(const char *filename, const char *topic, - int want_error_header, ...); +typedef int (*opal_show_help_fn_t)(const char *filename, const char *topic, int want_error_header, + ...); OPAL_DECLSPEC extern opal_show_help_fn_t opal_show_help; /** * This function does the same thing as opal_show_help(), but accepts * a va_list form of varargs. */ -typedef int (*opal_show_vhelp_fn_t)(const char *filename, const char *topic, - int want_error_header, va_list ap); +typedef int (*opal_show_vhelp_fn_t)(const char *filename, const char *topic, int want_error_header, + va_list ap); OPAL_DECLSPEC extern opal_show_vhelp_fn_t opal_show_vhelp; /** * This function does the same thing as opal_show_help(), but returns * its output in a string (that must be freed by the caller). */ -OPAL_DECLSPEC char* opal_show_help_string(const char *filename, - const char *topic, +OPAL_DECLSPEC char *opal_show_help_string(const char *filename, const char *topic, int want_error_header, ...); /** * This function does the same thing as opal_show_help_string(), but * accepts a va_list form of varargs. */ -OPAL_DECLSPEC char* opal_show_help_vstring(const char *filename, - const char *topic, - int want_error_header, va_list ap); +OPAL_DECLSPEC char *opal_show_help_vstring(const char *filename, const char *topic, + int want_error_header, va_list ap); /** * This function adds another search location for the files that diff --git a/opal/util/show_help_lex.h b/opal/util/show_help_lex.h index 864888039b9..b13f023a2c1 100644 --- a/opal/util/show_help_lex.h +++ b/opal/util/show_help_lex.h @@ -23,13 +23,13 @@ #include "opal_config.h" #ifdef malloc -#undef malloc +# undef malloc #endif #ifdef realloc -#undef realloc +# undef realloc #endif #ifdef free -#undef free +# undef free #endif #include @@ -46,12 +46,12 @@ extern int opal_show_help_yynewlines; /* * Make lex-generated files not issue compiler warnings */ -#define YY_STACK_USED 0 +#define YY_STACK_USED 0 #define YY_ALWAYS_INTERACTIVE 0 -#define YY_NEVER_INTERACTIVE 0 -#define YY_MAIN 0 -#define YY_NO_UNPUT 1 -#define YY_SKIP_YYWRAP 1 +#define YY_NEVER_INTERACTIVE 0 +#define YY_MAIN 0 +#define YY_NO_UNPUT 1 +#define YY_SKIP_YYWRAP 1 enum { OPAL_SHOW_HELP_PARSE_DONE, diff --git a/opal/util/stacktrace.c b/opal/util/stacktrace.c index 907461e0f6f..f00e54ec343 100644 --- a/opal/util/stacktrace.c +++ b/opal/util/stacktrace.c @@ -27,44 +27,44 @@ #include #ifdef HAVE_UNISTD_H -#include +# include #endif #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_STAT_H -#include +# include #endif #ifdef HAVE_FCNTL_H -#include +# include #else -#ifdef HAVE_SYS_FCNTL_H -#include -#endif +# ifdef HAVE_SYS_FCNTL_H +# include +# endif #endif -#include #include +#include -#include "opal/runtime/opal.h" -#include "opal/util/stacktrace.h" -#include "opal/mca/backtrace/backtrace.h" #include "opal/constants.h" -#include "opal/util/output.h" -#include "opal/util/show_help.h" +#include "opal/mca/backtrace/backtrace.h" +#include "opal/runtime/opal.h" +#include "opal/runtime/opal_params.h" #include "opal/util/argv.h" -#include "opal/util/proc.h" #include "opal/util/error.h" -#include "opal/runtime/opal_params.h" +#include "opal/util/output.h" +#include "opal/util/proc.h" +#include "opal/util/show_help.h" +#include "opal/util/stacktrace.h" #ifndef _NSIG -#define _NSIG 32 +# define _NSIG 32 #endif #define HOSTFORMAT "[%s:%05d] " -int opal_stacktrace_output_fileno = -1; -static char *opal_stacktrace_output_filename_base = NULL; +int opal_stacktrace_output_fileno = -1; +static char *opal_stacktrace_output_filename_base = NULL; static size_t opal_stacktrace_output_filename_max_len = 0; static char stacktrace_hostname[OPAL_MAXHOSTNAMELEN]; static const char *stacktrace_hostname_full; @@ -76,18 +76,17 @@ static char *unable_to_print_msg = "Unable to print stack trace!\n"; * -or, if VPID is available- * stacktrace.VPID.PID */ -static void set_stacktrace_filename(void) { +static void set_stacktrace_filename(void) +{ opal_proc_t *my_proc = opal_proc_local_get(); - if( NULL == my_proc ) { - snprintf(opal_stacktrace_output_filename, opal_stacktrace_output_filename_max_len, - "%s.%lu", - opal_stacktrace_output_filename_base, (unsigned long)getpid()); - } - else { + if (NULL == my_proc) { + snprintf(opal_stacktrace_output_filename, opal_stacktrace_output_filename_max_len, "%s.%lu", + opal_stacktrace_output_filename_base, (unsigned long) getpid()); + } else { snprintf(opal_stacktrace_output_filename, opal_stacktrace_output_filename_max_len, - "%s.%lu.%lu", - opal_stacktrace_output_filename_base, (unsigned long)my_proc->proc_name.vpid, (unsigned long)getpid()); + "%s.%lu.%lu", opal_stacktrace_output_filename_base, + (unsigned long) my_proc->proc_name.vpid, (unsigned long) getpid()); } return; @@ -108,16 +107,16 @@ static void set_stacktrace_filename(void) { * FIXME: Should distinguish for systems, which don't have siginfo... */ #if OPAL_WANT_PRETTY_PRINT_STACKTRACE -static void show_stackframe (int signo, siginfo_t * info, void * p) +static void show_stackframe(int signo, siginfo_t *info, void *p) { char print_buffer[1024]; - char * tmp = print_buffer; - int size = sizeof (print_buffer); + char *tmp = print_buffer; + int size = sizeof(print_buffer); int ret; char *si_code_str = ""; /* Do not print the stack trace */ - if( 0 > opal_stacktrace_output_fileno && 0 == opal_stacktrace_output_filename_max_len ) { + if (0 > opal_stacktrace_output_fileno && 0 == opal_stacktrace_output_filename_max_len) { /* Raise the signal again, so we don't accidentally mask critical signals. * For critical signals, it is preferred that we call 'raise' instead of * 'exit' or 'abort' so that the return status is set properly for this @@ -130,262 +129,334 @@ static void show_stackframe (int signo, siginfo_t * info, void * p) } /* Update the file name with the RANK, if available */ - if( 0 < opal_stacktrace_output_filename_max_len ) { + if (0 < opal_stacktrace_output_filename_max_len) { set_stacktrace_filename(); opal_stacktrace_output_fileno = open(opal_stacktrace_output_filename, - O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); - if( 0 > opal_stacktrace_output_fileno ) { - opal_output(0, "Error: Failed to open the stacktrace output file. Default: stderr\n\tFilename: %s\n\tErrno: %s", + O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); + if (0 > opal_stacktrace_output_fileno) { + opal_output(0, + "Error: Failed to open the stacktrace output file. Default: " + "stderr\n\tFilename: %s\n\tErrno: %s", opal_stacktrace_output_filename, strerror(errno)); opal_stacktrace_output_fileno = fileno(stderr); } } /* write out the footer information */ - memset (print_buffer, 0, sizeof (print_buffer)); + memset(print_buffer, 0, sizeof(print_buffer)); ret = snprintf(print_buffer, sizeof(print_buffer), - HOSTFORMAT "*** Process received signal ***\n", - stacktrace_hostname, getpid()); + HOSTFORMAT "*** Process received signal ***\n", stacktrace_hostname, getpid()); write(opal_stacktrace_output_fileno, print_buffer, ret); + memset(print_buffer, 0, sizeof(print_buffer)); - memset (print_buffer, 0, sizeof (print_buffer)); - -#ifdef HAVE_STRSIGNAL - ret = snprintf (tmp, size, HOSTFORMAT "Signal: %s (%d)\n", - stacktrace_hostname, getpid(), strsignal(signo), signo); -#else - ret = snprintf (tmp, size, HOSTFORMAT "Signal: %d\n", - stacktrace_hostname, getpid(), signo); -#endif +# ifdef HAVE_STRSIGNAL + ret = snprintf(tmp, size, HOSTFORMAT "Signal: %s (%d)\n", stacktrace_hostname, getpid(), + strsignal(signo), signo); +# else + ret = snprintf(tmp, size, HOSTFORMAT "Signal: %d\n", stacktrace_hostname, getpid(), signo); +# endif size -= ret; tmp += ret; if (NULL != info) { - switch (signo) - { + switch (signo) { case SIGILL: - switch (info->si_code) - { -#ifdef ILL_ILLOPC - case ILL_ILLOPC: si_code_str = "Illegal opcode"; break; -#endif -#ifdef ILL_ILLOPN - case ILL_ILLOPN: si_code_str = "Illegal operand"; break; -#endif -#ifdef ILL_ILLADR - case ILL_ILLADR: si_code_str = "Illegal addressing mode"; break; -#endif -#ifdef ILL_ILLTRP - case ILL_ILLTRP: si_code_str = "Illegal trap"; break; -#endif -#ifdef ILL_PRVOPC - case ILL_PRVOPC: si_code_str = "Privileged opcode"; break; -#endif -#ifdef ILL_PRVREG - case ILL_PRVREG: si_code_str = "Privileged register"; break; -#endif -#ifdef ILL_COPROC - case ILL_COPROC: si_code_str = "Coprocessor error"; break; -#endif -#ifdef ILL_BADSTK - case ILL_BADSTK: si_code_str = "Internal stack error"; break; -#endif + switch (info->si_code) { +# ifdef ILL_ILLOPC + case ILL_ILLOPC: + si_code_str = "Illegal opcode"; + break; +# endif +# ifdef ILL_ILLOPN + case ILL_ILLOPN: + si_code_str = "Illegal operand"; + break; +# endif +# ifdef ILL_ILLADR + case ILL_ILLADR: + si_code_str = "Illegal addressing mode"; + break; +# endif +# ifdef ILL_ILLTRP + case ILL_ILLTRP: + si_code_str = "Illegal trap"; + break; +# endif +# ifdef ILL_PRVOPC + case ILL_PRVOPC: + si_code_str = "Privileged opcode"; + break; +# endif +# ifdef ILL_PRVREG + case ILL_PRVREG: + si_code_str = "Privileged register"; + break; +# endif +# ifdef ILL_COPROC + case ILL_COPROC: + si_code_str = "Coprocessor error"; + break; +# endif +# ifdef ILL_BADSTK + case ILL_BADSTK: + si_code_str = "Internal stack error"; + break; +# endif } break; case SIGFPE: - switch (info->si_code) - { -#ifdef FPE_INTDIV - case FPE_INTDIV: si_code_str = "Integer divide-by-zero"; break; -#endif -#ifdef FPE_INTOVF - case FPE_INTOVF: si_code_str = "Integer overflow"; break; -#endif - case FPE_FLTDIV: si_code_str = "Floating point divide-by-zero"; break; - case FPE_FLTOVF: si_code_str = "Floating point overflow"; break; - case FPE_FLTUND: si_code_str = "Floating point underflow"; break; -#ifdef FPE_FLTRES - case FPE_FLTRES: si_code_str = "Floating point inexact result"; break; -#endif -#ifdef FPE_FLTINV - case FPE_FLTINV: si_code_str = "Invalid floating point operation"; break; -#endif -#ifdef FPE_FLTSUB - case FPE_FLTSUB: si_code_str = "Subscript out of range"; break; -#endif + switch (info->si_code) { +# ifdef FPE_INTDIV + case FPE_INTDIV: + si_code_str = "Integer divide-by-zero"; + break; +# endif +# ifdef FPE_INTOVF + case FPE_INTOVF: + si_code_str = "Integer overflow"; + break; +# endif + case FPE_FLTDIV: + si_code_str = "Floating point divide-by-zero"; + break; + case FPE_FLTOVF: + si_code_str = "Floating point overflow"; + break; + case FPE_FLTUND: + si_code_str = "Floating point underflow"; + break; +# ifdef FPE_FLTRES + case FPE_FLTRES: + si_code_str = "Floating point inexact result"; + break; +# endif +# ifdef FPE_FLTINV + case FPE_FLTINV: + si_code_str = "Invalid floating point operation"; + break; +# endif +# ifdef FPE_FLTSUB + case FPE_FLTSUB: + si_code_str = "Subscript out of range"; + break; +# endif } break; case SIGSEGV: - switch (info->si_code) - { -#ifdef SEGV_MAPERR - case SEGV_MAPERR: si_code_str = "Address not mapped"; break; -#endif -#ifdef SEGV_ACCERR - case SEGV_ACCERR: si_code_str = "Invalid permissions"; break; -#endif + switch (info->si_code) { +# ifdef SEGV_MAPERR + case SEGV_MAPERR: + si_code_str = "Address not mapped"; + break; +# endif +# ifdef SEGV_ACCERR + case SEGV_ACCERR: + si_code_str = "Invalid permissions"; + break; +# endif } break; case SIGBUS: - switch (info->si_code) - { -#ifdef BUS_ADRALN - case BUS_ADRALN: si_code_str = "Invalid address alignment"; break; -#endif -#ifdef BUS_ADRERR - case BUS_ADRERR: si_code_str = "Non-existant physical address"; break; -#endif -#ifdef BUS_OBJERR - case BUS_OBJERR: si_code_str = "Object-specific hardware error"; break; -#endif + switch (info->si_code) { +# ifdef BUS_ADRALN + case BUS_ADRALN: + si_code_str = "Invalid address alignment"; + break; +# endif +# ifdef BUS_ADRERR + case BUS_ADRERR: + si_code_str = "Non-existant physical address"; + break; +# endif +# ifdef BUS_OBJERR + case BUS_OBJERR: + si_code_str = "Object-specific hardware error"; + break; +# endif } break; case SIGTRAP: - switch (info->si_code) - { -#ifdef TRAP_BRKPT - case TRAP_BRKPT: si_code_str = "Process breakpoint"; break; -#endif -#ifdef TRAP_TRACE - case TRAP_TRACE: si_code_str = "Process trace trap"; break; -#endif + switch (info->si_code) { +# ifdef TRAP_BRKPT + case TRAP_BRKPT: + si_code_str = "Process breakpoint"; + break; +# endif +# ifdef TRAP_TRACE + case TRAP_TRACE: + si_code_str = "Process trace trap"; + break; +# endif } break; case SIGCHLD: - switch (info->si_code) - { -#ifdef CLD_EXITED - case CLD_EXITED: si_code_str = "Child has exited"; break; -#endif -#ifdef CLD_KILLED - case CLD_KILLED: si_code_str = "Child has terminated abnormally and did not create a core file"; break; -#endif -#ifdef CLD_DUMPED - case CLD_DUMPED: si_code_str = "Child has terminated abnormally and created a core file"; break; -#endif -#ifdef CLD_WTRAPPED - case CLD_TRAPPED: si_code_str = "Traced child has trapped"; break; -#endif -#ifdef CLD_STOPPED - case CLD_STOPPED: si_code_str = "Child has stopped"; break; -#endif -#ifdef CLD_CONTINUED - case CLD_CONTINUED: si_code_str = "Stopped child has continued"; break; -#endif + switch (info->si_code) { +# ifdef CLD_EXITED + case CLD_EXITED: + si_code_str = "Child has exited"; + break; +# endif +# ifdef CLD_KILLED + case CLD_KILLED: + si_code_str = "Child has terminated abnormally and did not create a core file"; + break; +# endif +# ifdef CLD_DUMPED + case CLD_DUMPED: + si_code_str = "Child has terminated abnormally and created a core file"; + break; +# endif +# ifdef CLD_WTRAPPED + case CLD_TRAPPED: + si_code_str = "Traced child has trapped"; + break; +# endif +# ifdef CLD_STOPPED + case CLD_STOPPED: + si_code_str = "Child has stopped"; + break; +# endif +# ifdef CLD_CONTINUED + case CLD_CONTINUED: + si_code_str = "Stopped child has continued"; + break; +# endif } break; -#ifdef SIGPOLL +# ifdef SIGPOLL case SIGPOLL: - switch (info->si_code) - { -#ifdef POLL_IN - case POLL_IN: si_code_str = "Data input available"; break; -#endif -#ifdef POLL_OUT - case POLL_OUT: si_code_str = "Output buffers available"; break; -#endif -#ifdef POLL_MSG - case POLL_MSG: si_code_str = "Input message available"; break; -#endif -#ifdef POLL_ERR - case POLL_ERR: si_code_str = "I/O error"; break; -#endif -#ifdef POLL_PRI - case POLL_PRI: si_code_str = "High priority input available"; break; -#endif -#ifdef POLL_HUP - case POLL_HUP: si_code_str = "Device disconnected"; break; -#endif + switch (info->si_code) { +# ifdef POLL_IN + case POLL_IN: + si_code_str = "Data input available"; + break; +# endif +# ifdef POLL_OUT + case POLL_OUT: + si_code_str = "Output buffers available"; + break; +# endif +# ifdef POLL_MSG + case POLL_MSG: + si_code_str = "Input message available"; + break; +# endif +# ifdef POLL_ERR + case POLL_ERR: + si_code_str = "I/O error"; + break; +# endif +# ifdef POLL_PRI + case POLL_PRI: + si_code_str = "High priority input available"; + break; +# endif +# ifdef POLL_HUP + case POLL_HUP: + si_code_str = "Device disconnected"; + break; +# endif } break; -#endif /* SIGPOLL */ +# endif /* SIGPOLL */ default: - switch (info->si_code) - { -#ifdef SI_ASYNCNL - case SI_ASYNCNL: si_code_str = "SI_ASYNCNL"; break; -#endif -#ifdef SI_SIGIO - case SI_SIGIO: si_code_str = "Queued SIGIO"; break; -#endif -#ifdef SI_ASYNCIO - case SI_ASYNCIO: si_code_str = "Asynchronous I/O request completed"; break; -#endif -#ifdef SI_MESGQ - case SI_MESGQ: si_code_str = "Message queue state changed"; break; -#endif - case SI_TIMER: si_code_str = "Timer expiration"; break; - case SI_QUEUE: si_code_str = "Sigqueue() signal"; break; - case SI_USER: si_code_str = "User function (kill, sigsend, abort, etc.)"; break; -#ifdef SI_KERNEL - case SI_KERNEL: si_code_str = "Kernel signal"; break; -#endif + switch (info->si_code) { +# ifdef SI_ASYNCNL + case SI_ASYNCNL: + si_code_str = "SI_ASYNCNL"; + break; +# endif +# ifdef SI_SIGIO + case SI_SIGIO: + si_code_str = "Queued SIGIO"; + break; +# endif +# ifdef SI_ASYNCIO + case SI_ASYNCIO: + si_code_str = "Asynchronous I/O request completed"; + break; +# endif +# ifdef SI_MESGQ + case SI_MESGQ: + si_code_str = "Message queue state changed"; + break; +# endif + case SI_TIMER: + si_code_str = "Timer expiration"; + break; + case SI_QUEUE: + si_code_str = "Sigqueue() signal"; + break; + case SI_USER: + si_code_str = "User function (kill, sigsend, abort, etc.)"; + break; +# ifdef SI_KERNEL + case SI_KERNEL: + si_code_str = "Kernel signal"; + break; +# endif /* Dragonfly defines SI_USER and SI_UNDEFINED both as zero: */ /* For some reason, the PGI compiler will not let us combine these two #if tests into a single statement. Sigh. */ -#if defined(SI_UNDEFINED) -#if SI_UNDEFINED != SI_USER - case SI_UNDEFINED: si_code_str = "Undefined code"; break; -#endif -#endif +# if defined(SI_UNDEFINED) +# if SI_UNDEFINED != SI_USER + case SI_UNDEFINED: + si_code_str = "Undefined code"; + break; +# endif +# endif } } /* print signal errno information */ if (0 != info->si_errno) { - ret = snprintf(tmp, size, HOSTFORMAT "Associated errno: %s (%d)\n", - stacktrace_hostname, getpid(), - strerror (info->si_errno), info->si_errno); + ret = snprintf(tmp, size, HOSTFORMAT "Associated errno: %s (%d)\n", stacktrace_hostname, + getpid(), strerror(info->si_errno), info->si_errno); size -= ret; tmp += ret; } - ret = snprintf(tmp, size, HOSTFORMAT "Signal code: %s (%d)\n", - stacktrace_hostname, getpid(), - si_code_str, info->si_code); + ret = snprintf(tmp, size, HOSTFORMAT "Signal code: %s (%d)\n", stacktrace_hostname, + getpid(), si_code_str, info->si_code); size -= ret; tmp += ret; - switch (signo) - { + switch (signo) { case SIGILL: case SIGFPE: case SIGSEGV: - case SIGBUS: - { - ret = snprintf(tmp, size, HOSTFORMAT "Failing at address: %p\n", - stacktrace_hostname, getpid(), info->si_addr); + case SIGBUS: { + ret = snprintf(tmp, size, HOSTFORMAT "Failing at address: %p\n", stacktrace_hostname, + getpid(), info->si_addr); size -= ret; tmp += ret; break; } - case SIGCHLD: - { + case SIGCHLD: { ret = snprintf(tmp, size, HOSTFORMAT "Sending PID: %d, Sending UID: %d, Status: %d\n", - stacktrace_hostname, getpid(), - info->si_pid, info->si_uid, info->si_status); + stacktrace_hostname, getpid(), info->si_pid, info->si_uid, + info->si_status); size -= ret; tmp += ret; break; } -#ifdef SIGPOLL - case SIGPOLL: - { -#ifdef HAVE_SIGINFO_T_SI_FD +# ifdef SIGPOLL + case SIGPOLL: { +# ifdef HAVE_SIGINFO_T_SI_FD ret = snprintf(tmp, size, HOSTFORMAT "Band event: %ld, File Descriptor : %d\n", - stacktrace_hostname, getpid(), (long)info->si_band, info->si_fd); -#elif HAVE_SIGINFO_T_SI_BAND - ret = snprintf(tmp, size, HOSTFORMAT "Band event: %ld\n", - stacktrace_hostname, getpid(), (long)info->si_band); -#else + stacktrace_hostname, getpid(), (long) info->si_band, info->si_fd); +# elif HAVE_SIGINFO_T_SI_BAND + ret = snprintf(tmp, size, HOSTFORMAT "Band event: %ld\n", stacktrace_hostname, getpid(), + (long) info->si_band); +# else ret = 0; -#endif +# endif size -= ret; tmp += ret; break; } -#endif +# endif } } else { ret = snprintf(tmp, size, @@ -396,20 +467,18 @@ static void show_stackframe (int signo, siginfo_t * info, void * p) } /* write out the signal information generated above */ - write(opal_stacktrace_output_fileno, print_buffer, sizeof(print_buffer)-size); + write(opal_stacktrace_output_fileno, print_buffer, sizeof(print_buffer) - size); /* print out the stack trace */ - snprintf(print_buffer, sizeof(print_buffer), HOSTFORMAT, - stacktrace_hostname, getpid()); + snprintf(print_buffer, sizeof(print_buffer), HOSTFORMAT, stacktrace_hostname, getpid()); ret = opal_backtrace_print(NULL, print_buffer, 2); if (OPAL_SUCCESS != ret) { write(opal_stacktrace_output_fileno, unable_to_print_msg, strlen(unable_to_print_msg)); } /* write out the footer information */ - memset (print_buffer, 0, sizeof (print_buffer)); - ret = snprintf(print_buffer, sizeof(print_buffer), - HOSTFORMAT "*** End of error message ***\n", + memset(print_buffer, 0, sizeof(print_buffer)); + ret = snprintf(print_buffer, sizeof(print_buffer), HOSTFORMAT "*** End of error message ***\n", stacktrace_hostname, getpid()); if (ret > 0) { write(opal_stacktrace_output_fileno, print_buffer, ret); @@ -417,8 +486,8 @@ static void show_stackframe (int signo, siginfo_t * info, void * p) write(opal_stacktrace_output_fileno, unable_to_print_msg, strlen(unable_to_print_msg)); } - if( fileno(stdout) != opal_stacktrace_output_fileno && - fileno(stderr) != opal_stacktrace_output_fileno ) { + if (fileno(stdout) != opal_stacktrace_output_fileno + && fileno(stderr) != opal_stacktrace_output_fileno) { close(opal_stacktrace_output_fileno); opal_stacktrace_output_fileno = -1; } @@ -437,7 +506,6 @@ static void show_stackframe (int signo, siginfo_t * info, void * p) #endif /* OPAL_WANT_PRETTY_PRINT_STACKTRACE */ - #if OPAL_WANT_PRETTY_PRINT_STACKTRACE void opal_stackframe_output(int stream) { @@ -455,17 +523,19 @@ void opal_stackframe_output(int stream) } } else { /* Do not print the stack trace */ - if( 0 > opal_stacktrace_output_fileno && 0 == opal_stacktrace_output_filename_max_len ) { + if (0 > opal_stacktrace_output_fileno && 0 == opal_stacktrace_output_filename_max_len) { return; } /* Update the file name with the RANK, if available */ - if( 0 < opal_stacktrace_output_filename_max_len ) { + if (0 < opal_stacktrace_output_filename_max_len) { set_stacktrace_filename(); opal_stacktrace_output_fileno = open(opal_stacktrace_output_filename, - O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); - if( 0 > opal_stacktrace_output_fileno ) { - opal_output(0, "Error: Failed to open the stacktrace output file. Default: stderr\n\tFilename: %s\n\tErrno: %s", + O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); + if (0 > opal_stacktrace_output_fileno) { + opal_output(0, + "Error: Failed to open the stacktrace output file. Default: " + "stderr\n\tFilename: %s\n\tErrno: %s", opal_stacktrace_output_filename, strerror(errno)); opal_stacktrace_output_fileno = fileno(stderr); } @@ -473,8 +543,8 @@ void opal_stackframe_output(int stream) opal_backtrace_print(NULL, NULL, 2); - if( fileno(stdout) != opal_stacktrace_output_fileno && - fileno(stderr) != opal_stacktrace_output_fileno ) { + if (fileno(stdout) != opal_stacktrace_output_fileno + && fileno(stderr) != opal_stacktrace_output_fileno) { close(opal_stacktrace_output_fileno); opal_stacktrace_output_fileno = -1; } @@ -494,7 +564,7 @@ char *opal_stackframe_output_string(void) /* Calculate the space needed for the string */ for (i = 3; i < traces_size; i++) { - if (NULL == traces[i]) { + if (NULL == traces[i]) { break; } len += strlen(traces[i]) + 1; @@ -530,12 +600,12 @@ char *opal_stackframe_output_string(void) * is not a valid signal-number * */ -int opal_util_register_stackhandlers (void) +int opal_util_register_stackhandlers(void) { #if OPAL_WANT_PRETTY_PRINT_STACKTRACE struct sigaction act, old; - char * tmp; - char * next; + char *tmp; + char *next; int i; bool complain, showed_help = false; @@ -543,7 +613,7 @@ int opal_util_register_stackhandlers (void) strncpy(stacktrace_hostname, stacktrace_hostname_full, OPAL_MAXHOSTNAMELEN - 1); stacktrace_hostname[OPAL_MAXHOSTNAMELEN - 1] = '\0'; /* to keep these somewhat readable, only print the machine name */ - for (i = 0 ; i < (int)strlen(stacktrace_hostname) ; ++i) { + for (i = 0; i < (int) strlen(stacktrace_hostname); ++i) { if (stacktrace_hostname[i] == '.') { stacktrace_hostname[i] = '\0'; break; @@ -551,28 +621,25 @@ int opal_util_register_stackhandlers (void) } /* Setup the output stream to use */ - if( NULL == opal_stacktrace_output_filename || - 0 == strcasecmp(opal_stacktrace_output_filename, "none") ) { + if (NULL == opal_stacktrace_output_filename + || 0 == strcasecmp(opal_stacktrace_output_filename, "none")) { opal_stacktrace_output_fileno = -1; - } - else if( 0 == strcasecmp(opal_stacktrace_output_filename, "stdout") ) { + } else if (0 == strcasecmp(opal_stacktrace_output_filename, "stdout")) { opal_stacktrace_output_fileno = fileno(stdout); - } - else if( 0 == strcasecmp(opal_stacktrace_output_filename, "stderr") ) { + } else if (0 == strcasecmp(opal_stacktrace_output_filename, "stderr")) { opal_stacktrace_output_fileno = fileno(stderr); - } - else if( 0 == strcasecmp(opal_stacktrace_output_filename, "file" ) || - 0 == strcasecmp(opal_stacktrace_output_filename, "file:") ) { + } else if (0 == strcasecmp(opal_stacktrace_output_filename, "file") + || 0 == strcasecmp(opal_stacktrace_output_filename, "file:")) { opal_stacktrace_output_filename_base = strdup("stacktrace"); free(opal_stacktrace_output_filename); // Magic number: 8 = space for .PID and .RANK (allow 7 digits each) opal_stacktrace_output_filename_max_len = strlen("stacktrace") + 8 + 8; - opal_stacktrace_output_filename = (char*)malloc(sizeof(char) * opal_stacktrace_output_filename_max_len); + opal_stacktrace_output_filename = (char *) malloc( + sizeof(char) * opal_stacktrace_output_filename_max_len); set_stacktrace_filename(); opal_stacktrace_output_fileno = -1; - } - else if( 0 == strncasecmp(opal_stacktrace_output_filename, "file:", 5) ) { + } else if (0 == strncasecmp(opal_stacktrace_output_filename, "file:", 5)) { char *filename_cpy = NULL; next = strchr(opal_stacktrace_output_filename, ':'); next++; // move past the ':' to the filename specified @@ -581,85 +648,78 @@ int opal_util_register_stackhandlers (void) free(opal_stacktrace_output_filename); // Magic number: 8 = space for .PID and .RANK (allow 7 digits each) - opal_stacktrace_output_filename_max_len = strlen(opal_stacktrace_output_filename_base) + 8 + 8; - opal_stacktrace_output_filename = (char*)malloc(sizeof(char) * opal_stacktrace_output_filename_max_len); + opal_stacktrace_output_filename_max_len = strlen(opal_stacktrace_output_filename_base) + 8 + + 8; + opal_stacktrace_output_filename = (char *) malloc( + sizeof(char) * opal_stacktrace_output_filename_max_len); set_stacktrace_filename(); opal_stacktrace_output_fileno = -1; free(filename_cpy); - } - else { + } else { opal_stacktrace_output_fileno = fileno(stderr); } - /* Setup the signals to catch */ memset(&act, 0, sizeof(act)); act.sa_sigaction = show_stackframe; act.sa_flags = SA_SIGINFO; -#ifdef SA_ONESHOT +# ifdef SA_ONESHOT act.sa_flags |= SA_ONESHOT; -#else +# else act.sa_flags |= SA_RESETHAND; -#endif +# endif + + for (tmp = next = opal_signal_string; next != NULL && *next != '\0'; tmp = next + 1) { + int sig; + int ret; - for (tmp = next = opal_signal_string ; - next != NULL && *next != '\0'; - tmp = next + 1) - { - int sig; - int ret; - - complain = false; - sig = strtol (tmp, &next, 10); - - /* - * If there is no sensible number in the string, exit. - * Similarly for any number which is not in the signal-number range - */ - if (((0 == sig) && (tmp == next)) || (0 > sig) || (_NSIG <= sig)) { - opal_show_help("help-opal-util.txt", - "stacktrace bad signal", true, - opal_signal_string, tmp); - return OPAL_ERR_SILENT; - } else if (next == NULL) { - return OPAL_ERR_BAD_PARAM; - } else if (':' == *next && - 0 == strncasecmp(next, ":complain", 9)) { - complain = true; - next += 9; - } else if (',' != *next && '\0' != *next) { - return OPAL_ERR_BAD_PARAM; - } - - /* Just query first */ - ret = sigaction (sig, NULL, &old); - if (0 != ret) { - return OPAL_ERR_IN_ERRNO; - } - /* Was there something already there? */ - if (SIG_IGN != old.sa_handler && SIG_DFL != old.sa_handler) { - if (!showed_help && complain) { - /* JMS This is icky; there is no error message - aggregation here so this message may be repeated for - every single MPI process... */ - opal_show_help("help-opal-util.txt", - "stacktrace signal override", - true, sig, sig, sig, opal_signal_string); - showed_help = true; - } - } - - /* Nope, nothing was there, so put in ours */ - else { - if (0 != sigaction(sig, &act, NULL)) { - return OPAL_ERR_IN_ERRNO; - } - } + complain = false; + sig = strtol(tmp, &next, 10); + + /* + * If there is no sensible number in the string, exit. + * Similarly for any number which is not in the signal-number range + */ + if (((0 == sig) && (tmp == next)) || (0 > sig) || (_NSIG <= sig)) { + opal_show_help("help-opal-util.txt", "stacktrace bad signal", true, opal_signal_string, + tmp); + return OPAL_ERR_SILENT; + } else if (next == NULL) { + return OPAL_ERR_BAD_PARAM; + } else if (':' == *next && 0 == strncasecmp(next, ":complain", 9)) { + complain = true; + next += 9; + } else if (',' != *next && '\0' != *next) { + return OPAL_ERR_BAD_PARAM; + } + + /* Just query first */ + ret = sigaction(sig, NULL, &old); + if (0 != ret) { + return OPAL_ERR_IN_ERRNO; + } + /* Was there something already there? */ + if (SIG_IGN != old.sa_handler && SIG_DFL != old.sa_handler) { + if (!showed_help && complain) { + /* JMS This is icky; there is no error message + aggregation here so this message may be repeated for + every single MPI process... */ + opal_show_help("help-opal-util.txt", "stacktrace signal override", true, sig, sig, + sig, opal_signal_string); + showed_help = true; + } + } + + /* Nope, nothing was there, so put in ours */ + else { + if (0 != sigaction(sig, &act, NULL)) { + return OPAL_ERR_IN_ERRNO; + } + } } #endif /* OPAL_WANT_PRETTY_PRINT_STACKTRACE */ return OPAL_SUCCESS; } - diff --git a/opal/util/stacktrace.h b/opal/util/stacktrace.h index c4484ae91aa..c30476eb094 100644 --- a/opal/util/stacktrace.h +++ b/opal/util/stacktrace.h @@ -53,6 +53,6 @@ OPAL_DECLSPEC char *opal_stackframe_output_string(void); * is not a valid signal-number * */ -OPAL_DECLSPEC int opal_util_register_stackhandlers (void); +OPAL_DECLSPEC int opal_util_register_stackhandlers(void); #endif /* OPAL_STACKTRACE_H */ diff --git a/opal/util/string_copy.c b/opal/util/string_copy.c index 90e8112d7a0..0935ceed2fb 100644 --- a/opal/util/string_copy.c +++ b/opal/util/string_copy.c @@ -13,7 +13,6 @@ #include "opal/util/string_copy.h" - void opal_string_copy(char *dest, const char *src, size_t dest_len) { size_t i; diff --git a/opal/util/string_copy.h b/opal/util/string_copy.h index 9d0827664c8..2945c7ffa60 100644 --- a/opal/util/string_copy.h +++ b/opal/util/string_copy.h @@ -21,7 +21,7 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif BEGIN_C_DECLS @@ -59,8 +59,7 @@ BEGIN_C_DECLS * (len-1) characters of the source string will be copied to the * destination, and dest[len-1] will be set to '\0'. */ -OPAL_DECLSPEC void opal_string_copy(char *dest, const char *src, - size_t dest_len) +OPAL_DECLSPEC void opal_string_copy(char *dest, const char *src, size_t dest_len) __opal_attribute_nonnull__(1) __opal_attribute_nonnull__(2); /** diff --git a/opal/util/sys_limits.c b/opal/util/sys_limits.c index c6b95a35334..c8464be0290 100644 --- a/opal/util/sys_limits.c +++ b/opal/util/sys_limits.c @@ -31,35 +31,34 @@ #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_TIME_H -#include +# include #endif #ifdef HAVE_SYS_RESOURCE_H -#include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #include "opal/constants.h" #include "opal/runtime/opal_params.h" -#include "opal/util/sys_limits.h" -#include "opal/util/show_help.h" -#include "opal/util/output.h" #include "opal/util/argv.h" +#include "opal/util/output.h" +#include "opal/util/show_help.h" +#include "opal/util/sys_limits.h" /* * Create and initialize storage for the system limits */ OPAL_DECLSPEC opal_sys_limits_t opal_sys_limits = { - /* initialized = */ false, - /* num_files = */ -1, - /* num_procs = */ -1, - /* file_size = */ 0 -}; + /* initialized = */ false, + /* num_files = */ -1, + /* num_procs = */ -1, + /* file_size = */ 0}; static int opal_setlimit(int resource, char *value, rlim_t *out) { @@ -69,9 +68,9 @@ static int opal_setlimit(int resource, char *value, rlim_t *out) rlim.rlim_cur = 0; if (0 == strcmp(value, "max")) { - maxlim = -1; + maxlim = -1; } else if (0 == strncmp(value, "unlimited", strlen(value))) { - maxlim = RLIM_INFINITY; + maxlim = RLIM_INFINITY; } else { maxlim = strtol(value, NULL, 10); } @@ -109,7 +108,7 @@ static int opal_setlimit(int resource, char *value, rlim_t *out) int opal_util_init_sys_limits(char **errmsg) { - char **lims, **lim=NULL, *setlim; + char **lims, **lim = NULL, *setlim; int i, rc = OPAL_ERROR; rlim_t value; @@ -125,7 +124,7 @@ int opal_util_init_sys_limits(char **errmsg) } /* each limit is expressed as a "param:value" pair */ - for (i=0; NULL != lims[i]; i++) { + for (i = 0; NULL != lims[i]; i++) { lim = opal_argv_split(lims[i], ':'); if (1 == opal_argv_count(lim)) { setlim = "max"; @@ -139,24 +138,25 @@ int opal_util_init_sys_limits(char **errmsg) */ if (0 == strcmp(lim[0], "1")) { #if HAVE_DECL_RLIMIT_NOFILE - if (OPAL_SUCCESS != - opal_setlimit(RLIMIT_NOFILE, "max", &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", "max"); + if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NOFILE, "max", &value)) { + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "openfiles", "max"); goto out; } opal_sys_limits.num_files = value; #endif #if HAVE_DECL_RLIMIT_NPROC if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NPROC, "max", &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxchildren", "max"); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "maxchildren", "max"); goto out; } opal_sys_limits.num_procs = value; #endif #if HAVE_DECL_RLIMIT_FSIZE - if (OPAL_SUCCESS != - opal_setlimit(RLIMIT_FSIZE, "max", &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "filesize", "max"); + if (OPAL_SUCCESS != opal_setlimit(RLIMIT_FSIZE, "max", &value)) { + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "filesize", "max"); goto out; } opal_sys_limits.file_size = value; @@ -171,14 +171,16 @@ int opal_util_init_sys_limits(char **errmsg) if (0 == strcmp(lim[0], "core")) { #if HAVE_DECL_RLIMIT_CORE if (OPAL_SUCCESS != opal_setlimit(RLIMIT_CORE, setlim, &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "openfiles", setlim); goto out; } #endif } else if (0 == strcmp(lim[0], "filesize")) { #if HAVE_DECL_RLIMIT_FSIZE if (OPAL_SUCCESS != opal_setlimit(RLIMIT_FSIZE, setlim, &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "filesize", setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "filesize", setlim); goto out; } opal_sys_limits.file_size = value; @@ -186,14 +188,16 @@ int opal_util_init_sys_limits(char **errmsg) } else if (0 == strcmp(lim[0], "maxmem")) { #if HAVE_DECL_RLIMIT_AS if (OPAL_SUCCESS != opal_setlimit(RLIMIT_AS, setlim, &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxmem", setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "maxmem", setlim); goto out; } #endif } else if (0 == strcmp(lim[0], "openfiles")) { #if HAVE_DECL_RLIMIT_NOFILE if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NOFILE, setlim, &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "openfiles", setlim); goto out; } opal_sys_limits.num_files = value; @@ -201,20 +205,23 @@ int opal_util_init_sys_limits(char **errmsg) } else if (0 == strcmp(lim[0], "stacksize")) { #if HAVE_DECL_RLIMIT_STACK if (OPAL_SUCCESS != opal_setlimit(RLIMIT_STACK, setlim, &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "stacksize", setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "stacksize", setlim); goto out; } #endif } else if (0 == strcmp(lim[0], "maxchildren")) { #if HAVE_DECL_RLIMIT_NPROC if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NPROC, setlim, &value)) { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxchildren", setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, + "maxchildren", setlim); goto out; } opal_sys_limits.num_procs = value; #endif } else { - *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-unrecognized", true, lim[0], setlim); + *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-unrecognized", true, + lim[0], setlim); goto out; } opal_argv_free(lim); @@ -240,13 +247,13 @@ int opal_getpagesize(void) static int page_size = -1; if (page_size != -1) { -// testing in a loop showed sysconf() took ~5 usec vs ~0.3 usec with it cached + // testing in a loop showed sysconf() took ~5 usec vs ~0.3 usec with it cached return page_size; } #ifdef HAVE_GETPAGESIZE return page_size = getpagesize(); -#elif defined(_SC_PAGESIZE ) +#elif defined(_SC_PAGESIZE) return page_size = sysconf(_SC_PAGESIZE); #elif defined(_SC_PAGE_SIZE) return page_size = sysconf(_SC_PAGE_SIZE); diff --git a/opal/util/sys_limits.h b/opal/util/sys_limits.h index 728f2d4b72d..3d1e5bb00a0 100644 --- a/opal/util/sys_limits.h +++ b/opal/util/sys_limits.h @@ -25,7 +25,7 @@ #include "opal_config.h" #ifdef HAVE_SYS_TYPES_H -#include +# include #endif BEGIN_C_DECLS @@ -55,7 +55,6 @@ OPAL_DECLSPEC int opal_util_init_sys_limits(char **errmsg); */ OPAL_DECLSPEC int opal_getpagesize(void); - END_C_DECLS #endif /* OPAL_STRNCPY_H */ diff --git a/opal/util/timings.c b/opal/util/timings.c index 7e9981fcb3c..87b2c9b83c1 100644 --- a/opal/util/timings.c +++ b/opal/util/timings.c @@ -11,34 +11,33 @@ #include "opal_config.h" -#include #include #include +#include #include #include #include #ifdef HAVE_SYS_TYPES_H -#include +# include #endif #ifdef HAVE_SYS_TIME_H -#include +# include #endif #ifdef HAVE_SYS_RESOURCE_H -#include +# include #endif #include "opal/constants.h" #include "opal/runtime/opal_params.h" - -#include "opal/class/opal_pointer_array.h" #include "opal/class/opal_list.h" -#include "opal/util/timings.h" -#include "opal/util/output.h" -#include "opal/util/basename.h" +#include "opal/class/opal_pointer_array.h" #include "opal/mca/timer/timer.h" +#include "opal/util/basename.h" +#include "opal/util/output.h" +#include "opal/util/timings.h" #include MCA_timer_IMPLEMENTATION_HEADER @@ -49,52 +48,51 @@ static double get_ts_gettimeofday(void) struct timeval tv; gettimeofday(&tv, NULL); ret = tv.tv_sec; - ret += (double)tv.tv_usec / 1000000.0; + ret += (double) tv.tv_usec / 1000000.0; return ret; } #if OPAL_TIMER_CYCLE_NATIVE static double get_ts_cycle(void) { - return ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq(); + return ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq(); } #endif #if OPAL_TIMER_USEC_NATIVE static double get_ts_usec(void) { - return ((double) opal_timer_base_get_usec()) / 1000000.0; + return ((double) opal_timer_base_get_usec()) / 1000000.0; } #endif opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type) { switch (type) { - case OPAL_TIMING_GET_TIME_OF_DAY: - return get_ts_gettimeofday; + case OPAL_TIMING_GET_TIME_OF_DAY: + return get_ts_gettimeofday; - case OPAL_TIMING_CYCLE_NATIVE: + case OPAL_TIMING_CYCLE_NATIVE: #if OPAL_TIMER_CYCLE_NATIVE - return get_ts_cycle; + return get_ts_cycle; #else - return NULL; + return NULL; #endif // OPAL_TIMER_CYCLE_NATIVE - case OPAL_TIMING_USEC_NATIVE: + case OPAL_TIMING_USEC_NATIVE: #if OPAL_TIMER_USEC_NATIVE - return get_ts_usec; + return get_ts_usec; #else - return NULL; + return NULL; #endif // OPAL_TIMER_USEC_NATIVE - default: - if( !opal_initialized ){ - return get_ts_gettimeofday; - } + default: + if (!opal_initialized) { + return get_ts_gettimeofday; + } #if OPAL_TIMER_CYCLE_NATIVE - return get_ts_cycle; + return get_ts_cycle; #elif OPAL_TIMER_USEC_NATIVE - return get_ts_usec; + return get_ts_usec; #endif - return get_ts_gettimeofday; + return get_ts_gettimeofday; } } - diff --git a/opal/util/timings.h b/opal/util/timings.h index 6d561472d77..26b56d983f4 100644 --- a/opal/util/timings.h +++ b/opal/util/timings.h @@ -28,7 +28,7 @@ typedef enum { typedef double (*opal_timing_ts_func_t)(void); -#define OPAL_TIMING_STR_LEN 256 +# define OPAL_TIMING_STR_LEN 256 typedef struct { char id[OPAL_TIMING_STR_LEN], cntr_env[OPAL_TIMING_STR_LEN]; @@ -40,179 +40,183 @@ typedef struct { opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type); -#define OPAL_TIMING_ENV_START_TYPE(func, _nm, type, prefix) \ - do { \ - char *ptr = NULL; \ - char *_prefix = prefix; \ - int n; \ - if( NULL == prefix ){ \ - _prefix = ""; \ - } \ - (_nm)->error = 0; \ - n = snprintf((_nm)->id, OPAL_TIMING_STR_LEN, "%s_%s", _prefix, func); \ - if( n > OPAL_TIMING_STR_LEN ){ \ - (_nm)->error = 1; \ - } \ - n = sprintf((_nm)->cntr_env,"OMPI_TIMING_%s_CNT", (_nm)->id); \ - if( n > OPAL_TIMING_STR_LEN ){ \ - (_nm)->error = 1; \ - } \ - ptr = getenv((_nm)->id); \ - if( NULL == ptr || strcmp(ptr, "1")){ \ - (_nm)->enabled = 0; \ - } \ - (_nm)->get_ts = opal_timing_ts_func(type); \ - ptr = getenv("OPAL_TIMING_ENABLE"); \ - if (NULL != ptr) { \ - (_nm)->enabled = atoi(ptr); \ - } \ - (_nm)->cntr = 0; \ - ptr = getenv((_nm)->id); \ - if( NULL != ptr ){ \ - (_nm)->cntr = atoi(ptr); \ - } \ - (_nm)->ts = (_nm)->get_ts(); \ - if ( 0 != (_nm)->error ){ \ - (_nm)->enabled = 0; \ - } \ - } while(0) - -/* We use function names for identification - * however this might be a problem for the private - * functions declared as static as their names may - * conflict. - * Use prefix to do a finer-grained identification if needed - */ -#define OPAL_TIMING_ENV_INIT_PREFIX(prefix, name) \ - opal_timing_env_t name ## _val, *name = &(name ## _val); \ - OPAL_TIMING_ENV_START_TYPE(__func__, name, OPAL_TIMING_AUTOMATIC_TIMER, prefix); - -#define OPAL_TIMING_ENV_INIT(name) OPAL_TIMING_ENV_INIT_PREFIX("", name) - -#define OPAL_TIMING_ENV_NEXT(h, ...) \ - do { \ - int n; \ - char buf1[OPAL_TIMING_STR_LEN], buf2[OPAL_TIMING_STR_LEN]; \ - double time; \ - char *filename; \ - if( h->enabled ){ \ - /* enabled codepath */ \ - time = h->get_ts() - h->ts; \ - n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_DESC_%d", h->id, h->cntr); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ - } \ - n = snprintf(buf2, OPAL_TIMING_STR_LEN, __VA_ARGS__ ); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ +# define OPAL_TIMING_ENV_START_TYPE(func, _nm, type, prefix) \ + do { \ + char *ptr = NULL; \ + char *_prefix = prefix; \ + int n; \ + if (NULL == prefix) { \ + _prefix = ""; \ } \ - setenv(buf1, buf2, 1); \ - n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_VAL_%d", h->id, h->cntr); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ + (_nm)->error = 0; \ + n = snprintf((_nm)->id, OPAL_TIMING_STR_LEN, "%s_%s", _prefix, func); \ + if (n > OPAL_TIMING_STR_LEN) { \ + (_nm)->error = 1; \ } \ - n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%lf", time); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ + n = sprintf((_nm)->cntr_env, "OMPI_TIMING_%s_CNT", (_nm)->id); \ + if (n > OPAL_TIMING_STR_LEN) { \ + (_nm)->error = 1; \ } \ - setenv(buf1, buf2, 1); \ - filename = strrchr(__FILE__, '/'); \ - filename = (filename == NULL) ? strdup(__FILE__) : filename+1; \ - n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_FILE_%d", h->id, h->cntr); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ + ptr = getenv((_nm)->id); \ + if (NULL == ptr || strcmp(ptr, "1")) { \ + (_nm)->enabled = 0; \ } \ - n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%s", filename); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ + (_nm)->get_ts = opal_timing_ts_func(type); \ + ptr = getenv("OPAL_TIMING_ENABLE"); \ + if (NULL != ptr) { \ + (_nm)->enabled = atoi(ptr); \ } \ - setenv(buf1, buf2, 1); \ - h->cntr++; \ - sprintf(buf1, "%d", h->cntr); \ - setenv(h->cntr_env, buf1, 1); \ - /* We don't include env operations into the consideration. - * Hopefully this will help to make measurements more accurate. - */ \ - h->ts = h->get_ts(); \ - } \ - if (h->error) { \ - n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_ERROR", h->id);\ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ + (_nm)->cntr = 0; \ + ptr = getenv((_nm)->id); \ + if (NULL != ptr) { \ + (_nm)->cntr = atoi(ptr); \ } \ - n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%d", h->error); \ - if ( n > OPAL_TIMING_STR_LEN ){ \ - h->error = 1; \ + (_nm)->ts = (_nm)->get_ts(); \ + if (0 != (_nm)->error) { \ + (_nm)->enabled = 0; \ } \ - setenv(buf1, buf2, 1); \ - } \ - } while(0) + } while (0) + +/* We use function names for identification + * however this might be a problem for the private + * functions declared as static as their names may + * conflict. + * Use prefix to do a finer-grained identification if needed + */ +# define OPAL_TIMING_ENV_INIT_PREFIX(prefix, name) \ + opal_timing_env_t name##_val, *name = &(name##_val); \ + OPAL_TIMING_ENV_START_TYPE(__func__, name, OPAL_TIMING_AUTOMATIC_TIMER, prefix); + +# define OPAL_TIMING_ENV_INIT(name) OPAL_TIMING_ENV_INIT_PREFIX("", name) + +# define OPAL_TIMING_ENV_NEXT(h, ...) \ + do { \ + int n; \ + char buf1[OPAL_TIMING_STR_LEN], buf2[OPAL_TIMING_STR_LEN]; \ + double time; \ + char *filename; \ + if (h->enabled) { \ + /* enabled codepath */ \ + time = h->get_ts() - h->ts; \ + n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_DESC_%d", h->id, h->cntr); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + n = snprintf(buf2, OPAL_TIMING_STR_LEN, __VA_ARGS__); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + setenv(buf1, buf2, 1); \ + n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_VAL_%d", h->id, h->cntr); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%lf", time); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + setenv(buf1, buf2, 1); \ + filename = strrchr(__FILE__, '/'); \ + filename = (filename == NULL) ? strdup(__FILE__) : filename + 1; \ + n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_FILE_%d", h->id, h->cntr); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%s", filename); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + setenv(buf1, buf2, 1); \ + h->cntr++; \ + sprintf(buf1, "%d", h->cntr); \ + setenv(h->cntr_env, buf1, 1); \ + /* We don't include env operations into the consideration. \ + * Hopefully this will help to make measurements more accurate. \ + */ \ + h->ts = h->get_ts(); \ + } \ + if (h->error) { \ + n = snprintf(buf1, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_ERROR", h->id); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + n = snprintf(buf2, OPAL_TIMING_STR_LEN, "%d", h->error); \ + if (n > OPAL_TIMING_STR_LEN) { \ + h->error = 1; \ + } \ + setenv(buf1, buf2, 1); \ + } \ + } while (0) /* This function supposed to be called from the code that will * do the postprocessing, i.e. OMPI timing portion that will * do the reduction of accumulated values */ -#define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func, _cnt) \ - do { \ - char ename[OPAL_TIMING_STR_LEN]; \ - char *ptr = NULL; \ - int n = snprintf(ename, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_%s_CNT", prefix, func); \ - (_cnt) = 0; \ - if ( n <= OPAL_TIMING_STR_LEN ){ \ - ptr = getenv(ename); \ - if( NULL != ptr ){ (_cnt) = atoi(ptr); }; \ - } \ - } while(0) - -#define OPAL_TIMING_ENV_ERROR_PREFIX(prefix, func, _err) \ - do { \ - char ename[OPAL_TIMING_STR_LEN]; \ - (_err) = 0; \ - char *ptr = NULL; \ - int n = snprintf(ename, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s%s_ERROR", prefix, func); \ - if ( n <= OPAL_TIMING_STR_LEN ){ \ - ptr = getenv(ename); \ - if( NULL != ptr ){ (_err) = atoi(ptr); }; \ - } \ - } while(0) - -#define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, filename, func, i, desc, _t) \ - do { \ - char vname[OPAL_TIMING_STR_LEN]; \ - (_t) = 0.0; \ - sprintf(vname, "OMPI_TIMING_%s_%s_FILE_%d", prefix, func, i); \ - *filename = getenv(vname); \ - sprintf(vname, "OMPI_TIMING_%s_%s_DESC_%d", prefix, func, i); \ - *desc = getenv(vname); \ - sprintf(vname, "OMPI_TIMING_%s_%s_VAL_%d", prefix, func, i); \ - char *ptr = getenv(vname); \ - if ( NULL != ptr ) { \ - sscanf(ptr,"%lf", &(_t)); \ - } \ - } while(0) - -#define OPAL_TIMING_ENV_GETDESC(file, func, index, desc) \ - OPAL_TIMING_ENV_GETDESC_PREFIX("", file, func, index, desc) +# define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func, _cnt) \ + do { \ + char ename[OPAL_TIMING_STR_LEN]; \ + char *ptr = NULL; \ + int n = snprintf(ename, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s_%s_CNT", prefix, func); \ + (_cnt) = 0; \ + if (n <= OPAL_TIMING_STR_LEN) { \ + ptr = getenv(ename); \ + if (NULL != ptr) { \ + (_cnt) = atoi(ptr); \ + }; \ + } \ + } while (0) + +# define OPAL_TIMING_ENV_ERROR_PREFIX(prefix, func, _err) \ + do { \ + char ename[OPAL_TIMING_STR_LEN]; \ + (_err) = 0; \ + char *ptr = NULL; \ + int n = snprintf(ename, OPAL_TIMING_STR_LEN, "OMPI_TIMING_%s%s_ERROR", prefix, func); \ + if (n <= OPAL_TIMING_STR_LEN) { \ + ptr = getenv(ename); \ + if (NULL != ptr) { \ + (_err) = atoi(ptr); \ + }; \ + } \ + } while (0) + +# define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, filename, func, i, desc, _t) \ + do { \ + char vname[OPAL_TIMING_STR_LEN]; \ + (_t) = 0.0; \ + sprintf(vname, "OMPI_TIMING_%s_%s_FILE_%d", prefix, func, i); \ + *filename = getenv(vname); \ + sprintf(vname, "OMPI_TIMING_%s_%s_DESC_%d", prefix, func, i); \ + *desc = getenv(vname); \ + sprintf(vname, "OMPI_TIMING_%s_%s_VAL_%d", prefix, func, i); \ + char *ptr = getenv(vname); \ + if (NULL != ptr) { \ + sscanf(ptr, "%lf", &(_t)); \ + } \ + } while (0) + +# define OPAL_TIMING_ENV_GETDESC(file, func, index, desc) \ + OPAL_TIMING_ENV_GETDESC_PREFIX("", file, func, index, desc) #else -#define OPAL_TIMING_ENV_START_TYPE(func, type, prefix) +# define OPAL_TIMING_ENV_START_TYPE(func, type, prefix) -#define OPAL_TIMING_ENV_INIT(name) +# define OPAL_TIMING_ENV_INIT(name) -#define OPAL_TIMING_ENV_INIT_PREFIX(prefix, name) +# define OPAL_TIMING_ENV_INIT_PREFIX(prefix, name) -#define OPAL_TIMING_ENV_NEXT(h, ... ) +# define OPAL_TIMING_ENV_NEXT(h, ...) -#define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func) +# define OPAL_TIMING_ENV_CNT_PREFIX(prefix, func) -#define OPAL_TIMING_ENV_CNT(func) +# define OPAL_TIMING_ENV_CNT(func) -#define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, func, i, desc) +# define OPAL_TIMING_ENV_GETDESC_PREFIX(prefix, func, i, desc) -#define OPAL_TIMING_ENV_GETDESC(func, index, desc) +# define OPAL_TIMING_ENV_GETDESC(func, index, desc) -#define OPAL_TIMING_ENV_ERROR_PREFIX(prefix, func) +# define OPAL_TIMING_ENV_ERROR_PREFIX(prefix, func) #endif diff --git a/opal/util/uri.c b/opal/util/uri.c index 1e1e154b972..233037ee246 100644 --- a/opal/util/uri.c +++ b/opal/util/uri.c @@ -17,17 +17,17 @@ #include #include #ifdef HAVE_UNISTD_H -#include +# include #endif #include "opal/util/output.h" #include "opal/util/path.h" -#include "opal/util/show_help.h" #include "opal/util/printf.h" +#include "opal/util/show_help.h" #include "opal/util/uri.h" -const static char *uri_reserved_path_chars="!$&'()*+,;=:@ "; +const static char *uri_reserved_path_chars = "!$&'()*+,;=:@ "; char *opal_uri_get_scheme(const char *uri) { @@ -35,8 +35,7 @@ char *opal_uri_get_scheme(const char *uri) char *ptr; if (NULL == (ptr = strchr(turi, ':'))) { - opal_show_help("help-opal-util.txt", "malformed-uri", - true, uri); + opal_show_help("help-opal-util.txt", "malformed-uri", true, uri); free(turi); return NULL; } @@ -44,16 +43,14 @@ char *opal_uri_get_scheme(const char *uri) return turi; } -char *opal_filename_to_uri(const char *filename, - const char *hostname) +char *opal_filename_to_uri(const char *filename, const char *hostname) { char *uri, *fn; size_t i, j, k, n; /* filename must be an absolute path */ if (!opal_path_is_absolute(filename)) { - opal_show_help("help-opal-util.txt", "relative-path", - true, filename); + opal_show_help("help-opal-util.txt", "relative-path", true, filename); return NULL; } @@ -68,18 +65,18 @@ char *opal_filename_to_uri(const char *filename, /* count the number of characters that require escaping * in the filename */ - n=0; - for (j=0; j < strlen(uri_reserved_path_chars)-1; j++) { + n = 0; + for (j = 0; j < strlen(uri_reserved_path_chars) - 1; j++) { if (NULL != strchr(filename, uri_reserved_path_chars[j])) { n++; } } /* escape them if necessary */ if (0 < n) { - fn = (char*)malloc(strlen(filename) + n + 1); - i=0; - for (k=0; k < strlen(filename)-1; k++) { - for (j=0; j < strlen(uri_reserved_path_chars)-1; j++) { + fn = (char *) malloc(strlen(filename) + n + 1); + i = 0; + for (k = 0; k < strlen(filename) - 1; k++) { + for (j = 0; j < strlen(uri_reserved_path_chars) - 1; j++) { if (filename[k] == uri_reserved_path_chars[j]) { fn[i] = '\\'; i++; @@ -103,8 +100,7 @@ char *opal_filename_to_uri(const char *filename, return uri; } -char *opal_filename_from_uri(const char *uri, - char **hostname) +char *opal_filename_from_uri(const char *uri, char **hostname) { char *turi; char *ptr, *fn, *sp; @@ -120,13 +116,12 @@ char *opal_filename_from_uri(const char *uri, /* extract the scheme */ if (NULL == (ptr = strchr(turi, ':'))) { - opal_show_help("help-opal-util.txt", "malformed-uri", - true, uri); + opal_show_help("help-opal-util.txt", "malformed-uri", true, uri); free(turi); return NULL; } *ptr = '\0'; - ptr++; /* step over the new NULL */ + ptr++; /* step over the new NULL */ /* if there are three '/', then there is no * hostname and the file is local @@ -140,14 +135,12 @@ char *opal_filename_from_uri(const char *uri, fn = strdup(ptr); } else if (0 != strncmp(ptr, "//", 2)) { /* error */ - opal_show_help("help-opal-util.txt", "malformed-uri", - true, uri); + opal_show_help("help-opal-util.txt", "malformed-uri", true, uri); } else { - ptr += 2; /* step to the hostname */ + ptr += 2; /* step to the hostname */ /* find the separator to the filename */ if (NULL == (sp = strchr(ptr, '/'))) { - opal_show_help("help-opal-util.txt", "malformed-uri", - true, uri); + opal_show_help("help-opal-util.txt", "malformed-uri", true, uri); } else { *sp = '\0'; if (NULL != hostname) { diff --git a/opal/util/uri.h b/opal/util/uri.h index 87cdec8849c..5747abbf401 100644 --- a/opal/util/uri.h +++ b/opal/util/uri.h @@ -53,7 +53,7 @@ #include "opal_config.h" #ifdef HAVE_UNISTD_H -#include +# include #endif BEGIN_C_DECLS @@ -63,15 +63,16 @@ BEGIN_C_DECLS * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_uri_get_scheme(const char *uri) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_uri_get_scheme(const char *uri) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; /** * Create a uri from a hostname and filename * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_filename_to_uri(const char *filename, - const char *hostname) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_filename_to_uri(const char *filename, const char *hostname) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; /** * Extract the filename (and hostname) from a uri * @@ -83,8 +84,8 @@ OPAL_DECLSPEC char *opal_filename_to_uri(const char *filename, * * The caller is responsible for freeing the returned string. */ -OPAL_DECLSPEC char *opal_filename_from_uri(const char *uri, - char **hostname) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; +OPAL_DECLSPEC char *opal_filename_from_uri(const char *uri, char **hostname) + __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; END_C_DECLS #endif /* OPAL_URI_H */ diff --git a/opal/win32/opal_inet.c b/opal/win32/opal_inet.c index 9e21a8f668f..65f4c6a5dfb 100644 --- a/opal/win32/opal_inet.c +++ b/opal/win32/opal_inet.c @@ -16,11 +16,10 @@ * $HEADER$ */ - #include "opal_config.h" -#include "opal/win32/opal_inet.h" #include "opal/util/output.h" +#include "opal/win32/opal_inet.h" /* * convert from presentation format (which usually means ASCII printable) @@ -35,10 +34,10 @@ int opal_inet_pton(int af, const char *src, void *dst) { int addr_len; struct sockaddr sa; - struct sockaddr_in *sin = (struct sockaddr_in *)&sa; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa; + struct sockaddr_in *sin = (struct sockaddr_in *) &sa; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &sa; - memset (&sa, 0, sizeof(struct sockaddr)); + memset(&sa, 0, sizeof(struct sockaddr)); switch (af) { case AF_INET: @@ -53,24 +52,24 @@ int opal_inet_pton(int af, const char *src, void *dst) return -1; } - if ( 0 == WSAStringToAddress ((LPTSTR) src, af, NULL, (LPSOCKADDR) &sa, &addr_len )) { + if (0 == WSAStringToAddress((LPTSTR) src, af, NULL, (LPSOCKADDR) &sa, &addr_len)) { switch (af) { case AF_INET: - memcpy (dst, &sin->sin_addr, sizeof(struct in_addr)); + memcpy(dst, &sin->sin_addr, sizeof(struct in_addr)); break; case AF_INET6: - memcpy (dst, &sin6->sin6_addr, sizeof(struct in6_addr)); + memcpy(dst, &sin6->sin6_addr, sizeof(struct in6_addr)); break; } return 1; } else { - opal_output(0, "WSAStringToAddress failed %s:%d. Error code: %d", __FILE__, __LINE__, GetLastError()); + opal_output(0, "WSAStringToAddress failed %s:%d. Error code: %d", __FILE__, __LINE__, + GetLastError()); return 0; } } - /* * convert a network format address to presentation format. * @@ -82,32 +81,33 @@ const char *opal_inet_ntop(int af, const void *src, char *dst, size_t size) int addr_len; struct sockaddr sa; DWORD str_len = size; - struct sockaddr_in *sin = (struct sockaddr_in *)&sa; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa; + struct sockaddr_in *sin = (struct sockaddr_in *) &sa; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &sa; - memset (&sa, 0, sizeof (struct sockaddr)); + memset(&sa, 0, sizeof(struct sockaddr)); switch (af) { case AF_INET: addr_len = sizeof(struct sockaddr_in); sin->sin_family = af; - memcpy (&sin->sin_addr, src, sizeof (struct in_addr)); + memcpy(&sin->sin_addr, src, sizeof(struct in_addr)); break; case AF_INET6: addr_len = sizeof(struct sockaddr_in6); sin6->sin6_family = af; - memcpy (&sin6->sin6_addr, src, sizeof (struct in6_addr)); + memcpy(&sin6->sin6_addr, src, sizeof(struct in6_addr)); break; default: return NULL; } - if ( 0 == WSAAddressToString ((LPSOCKADDR) &sa, addr_len, NULL, dst, &str_len )) { + if (0 == WSAAddressToString((LPSOCKADDR) &sa, addr_len, NULL, dst, &str_len)) { return dst; } else { - opal_output(0, "WSAAddressToString failed %s:%d. Error code: %d", __FILE__, __LINE__, GetLastError()); + opal_output(0, "WSAAddressToString failed %s:%d. Error code: %d", __FILE__, __LINE__, + GetLastError()); return NULL; } } diff --git a/opal/win32/opal_inet.h b/opal/win32/opal_inet.h index a3e6a71e88d..d7fee7ef7b8 100644 --- a/opal/win32/opal_inet.h +++ b/opal/win32/opal_inet.h @@ -22,8 +22,8 @@ #include "opal_config.h" #ifndef OPAL_WIN_COMPAT_H -#error This file is supposed to be included only from win_compat.h -#endif /* OPAL_WIN_COMPAT_H */ +# error This file is supposed to be included only from win_compat.h +#endif /* OPAL_WIN_COMPAT_H */ BEGIN_C_DECLS diff --git a/opal/win32/opal_misc.h b/opal/win32/opal_misc.h index 545f20ed523..3d4e0bdb50c 100644 --- a/opal/win32/opal_misc.h +++ b/opal/win32/opal_misc.h @@ -57,7 +57,8 @@ static __inline int setenv (const char *name, const char *value, int rewrite) } #endif -static __inline unsigned int sleep(unsigned int seconds) { +static __inline unsigned int sleep(unsigned int seconds) +{ /* Allow interruptions */ SleepEx(seconds * 1000, TRUE); @@ -66,43 +67,48 @@ static __inline unsigned int sleep(unsigned int seconds) { /* this function can currently ONLY return the page size. for it to do the entire sysconf range it needs to be extended */ -static __inline size_t sysconf(int option) { +static __inline size_t sysconf(int option) +{ SYSTEM_INFO sys_info; - if( _SC_OPEN_MAX == option ) { + if (_SC_OPEN_MAX == option) { return _getmaxstdio(); } GetSystemInfo(&sys_info); - if (_SC_PAGESIZE == option){ - return (size_t)sys_info.dwPageSize; + if (_SC_PAGESIZE == option) { + return (size_t) sys_info.dwPageSize; } - printf( "This functionality is not supported: line: %d\tfile: %s\n", - __LINE__, __FILE__ ); + printf("This functionality is not supported: line: %d\tfile: %s\n", __LINE__, __FILE__); abort(); return 0; } -#define F_GETFL 0 -#define F_SETFL 1 +#define F_GETFL 0 +#define F_SETFL 1 #define O_NONBLOCK 0 /* * this function is currently defined only for setting the socket to be * in the non-blocking mode. Else this function returns error not implemented. * This calls ioctlsocket in the winsock library */ -static __inline int fcntl (int fildes, int cmd, ...) { +static __inline int fcntl(int fildes, int cmd, ...) +{ int ret; int mode; switch (cmd) { - case F_SETFL: mode = 1; ret = ioctlsocket ((SOCKET)fildes, FIONBIO, (u_long FAR*) &mode); - break; - case F_GETFL: ret = 0; - break; - default: printf("Option not supported: %d %s\n", __LINE__, __FILE__); - abort(); + case F_SETFL: + mode = 1; + ret = ioctlsocket((SOCKET) fildes, FIONBIO, (u_long FAR *) &mode); + break; + case F_GETFL: + ret = 0; + break; + default: + printf("Option not supported: %d %s\n", __LINE__, __FILE__); + abort(); }; return ret; diff --git a/opal/win32/opal_process.c b/opal/win32/opal_process.c index 92d0b32a4a2..85d9530cd26 100644 --- a/opal/win32/opal_process.c +++ b/opal/win32/opal_process.c @@ -19,22 +19,24 @@ #include "opal_config.h" #include "win32/opal_process.h" -pid_t waitpid(pid_t pid, int *status, int options) { - return _cwait(status, pid, _WAIT_CHILD); +pid_t waitpid(pid_t pid, int *status, int options) +{ + return _cwait(status, pid, _WAIT_CHILD); } -int kill(pid_t pid, int sig) { - /* XXX fill this in */ - /* Need to connect to the child process - Then raise the signal since Windows doesn;t - have the ability to 'send a signal' to a - process, a la the kill command in UNIX +int kill(pid_t pid, int sig) +{ + /* XXX fill this in */ + /* Need to connect to the child process + Then raise the signal since Windows doesn;t + have the ability to 'send a signal' to a + process, a la the kill command in UNIX - MSVC functions to look at: - - OpenProcess - - TerminateProcess - - raise - */ + MSVC functions to look at: + - OpenProcess + - TerminateProcess + - raise + */ - return 0; + return 0; } diff --git a/opal/win32/opal_process.h b/opal/win32/opal_process.h index 34ffe4dc06f..86d7682cb53 100644 --- a/opal/win32/opal_process.h +++ b/opal/win32/opal_process.h @@ -22,15 +22,15 @@ #include "opal_config.h" #ifndef OPAL_WIN_COMPAT_H -#error This file is supposed to be included only from win_compat.h -#endif /* OPAL_WIN_COMPAT_H */ +# error This file is supposed to be included only from win_compat.h +#endif /* OPAL_WIN_COMPAT_H */ BEGIN_C_DECLS -OPAL_DECLSPEC pid_t waitpid (pid_t pid, int *status, int options) ; +OPAL_DECLSPEC pid_t waitpid(pid_t pid, int *status, int options); -OPAL_DECLSPEC int kill(pid_t pid, int sig) ; +OPAL_DECLSPEC int kill(pid_t pid, int sig); END_C_DECLS -#endif /* OPAL_PROCESS_H */ +#endif /* OPAL_PROCESS_H */ diff --git a/opal/win32/opal_socket.c b/opal/win32/opal_socket.c index f293b463842..c520380329d 100644 --- a/opal/win32/opal_socket.c +++ b/opal/win32/opal_socket.c @@ -10,11 +10,10 @@ #include "opal_config.h" -#include "opal/win32/opal_socket.h" #include "opal/util/output.h" +#include "opal/win32/opal_socket.h" -int -create_socketpair(int family, int type, int protocol, int fd[2]) +int create_socketpair(int family, int type, int protocol, int fd[2]) { /* This code is originally from Tor. Used with permission. */ @@ -24,9 +23,9 @@ create_socketpair(int family, int type, int protocol, int fd[2]) * have other problems too. */ #ifdef WIN32 -#define ERR(e) WSA##e +# define ERR(e) WSA##e #else -#define ERR(e) e +# define ERR(e) e #endif int listener = -1; int connector = -1; @@ -41,7 +40,7 @@ create_socketpair(int family, int type, int protocol, int fd[2]) #ifdef AF_UNIX && family != AF_UNIX #endif - )) { + )) { opal_output(0, "Protocol not support: %d", (ERR(EAFNOSUPPORT))); return -1; } @@ -56,9 +55,8 @@ create_socketpair(int family, int type, int protocol, int fd[2]) memset(&listen_addr, 0, sizeof(listen_addr)); listen_addr.sin_family = AF_INET; listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - listen_addr.sin_port = 0; /* kernel chooses port. */ - if (bind(listener, (struct sockaddr *) &listen_addr, sizeof (listen_addr)) - == -1) + listen_addr.sin_port = 0; /* kernel chooses port. */ + if (bind(listener, (struct sockaddr *) &listen_addr, sizeof(listen_addr)) == -1) goto tidy_up_and_fail; if (listen(listener, 1) == -1) goto tidy_up_and_fail; @@ -70,10 +68,9 @@ create_socketpair(int family, int type, int protocol, int fd[2]) size = sizeof(connect_addr); if (getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1) goto tidy_up_and_fail; - if (size != sizeof (connect_addr)) + if (size != sizeof(connect_addr)) goto abort_tidy_up_and_fail; - if (connect(connector, (struct sockaddr *) &connect_addr, - sizeof(connect_addr)) == -1) + if (connect(connector, (struct sockaddr *) &connect_addr, sizeof(connect_addr)) == -1) goto tidy_up_and_fail; size = sizeof(listen_addr); @@ -87,8 +84,7 @@ create_socketpair(int family, int type, int protocol, int fd[2]) two sockets. */ if (getsockname(connector, (struct sockaddr *) &connect_addr, &size) == -1) goto tidy_up_and_fail; - if (size != sizeof (connect_addr) - || listen_addr.sin_family != connect_addr.sin_family + if (size != sizeof(connect_addr) || listen_addr.sin_family != connect_addr.sin_family || listen_addr.sin_addr.s_addr != connect_addr.sin_addr.s_addr || listen_addr.sin_port != connect_addr.sin_port) goto abort_tidy_up_and_fail; @@ -97,9 +93,9 @@ create_socketpair(int family, int type, int protocol, int fd[2]) return 0; - abort_tidy_up_and_fail: +abort_tidy_up_and_fail: saved_errno = ERR(ECONNABORTED); - tidy_up_and_fail: +tidy_up_and_fail: if (saved_errno < 0) saved_errno = WSAGetLastError(); if (listener != -1) diff --git a/opal/win32/opal_socket.h b/opal/win32/opal_socket.h index dfd0f28e997..3e81841ad6c 100644 --- a/opal/win32/opal_socket.h +++ b/opal/win32/opal_socket.h @@ -14,9 +14,8 @@ #include "opal_config.h" #ifndef OPAL_WIN_COMPAT_H -#error This file is supposed to be included only from win_compat.h -#endif /* OPAL_WIN_COMPAT_H */ - +# error This file is supposed to be included only from win_compat.h +#endif /* OPAL_WIN_COMPAT_H */ BEGIN_C_DECLS diff --git a/opal/win32/opal_time.c b/opal/win32/opal_time.c index 6eb4f8b943d..f7799988d57 100644 --- a/opal/win32/opal_time.c +++ b/opal/win32/opal_time.c @@ -19,7 +19,7 @@ #include "opal_config.h" #include "opal/win32/opal_time.h" -#include +#include #define EPOCHFILETIME (116444736000000000LL) @@ -29,10 +29,9 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) LARGE_INTEGER place_holder; __int64 time; - /* returns 64 bit value which is the number of 100 nanosecond intervals since 1601(UTC) */ - GetSystemTimeAsFileTime (&file_time); + GetSystemTimeAsFileTime(&file_time); /* Windows recommends that we should copy the FILETIME returned into a ULARGE_INTEGER and then perform the arithmetic on that */ @@ -47,8 +46,8 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) /* convert 100 nanoseconds intervals into microseconds .. divide by 10 */ time /= 10; - tv->tv_sec = (long)(time / 1000000); - tv->tv_usec = (long)(time % 1000000); + tv->tv_sec = (long) (time / 1000000); + tv->tv_usec = (long) (time % 1000000); return 0; } diff --git a/opal/win32/opal_time.h b/opal/win32/opal_time.h index daa2aff5806..94aa91d05f6 100644 --- a/opal/win32/opal_time.h +++ b/opal/win32/opal_time.h @@ -22,163 +22,157 @@ #include "opal_config.h" #ifndef OPAL_WIN_COMPAT_H -#error This file is supposed to be included only from win_compat.h -#endif /* OPAL_WIN_COMPAT_H */ +# error This file is supposed to be included only from win_compat.h +#endif /* OPAL_WIN_COMPAT_H */ -#define DST_NONE 0 /* not on dst */ -#define DST_USA 1 /* USA style dst */ -#define DST_AUST 2 /* Australian style dst */ -#define DST_WET 3 /* Western European dst */ -#define DST_MET 4 /* Middle European dst */ -#define DST_EET 5 /* Eastern European dst */ -#define DST_CAN 6 /* Canada */ +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ #define TIMEVAL_TO_TIMESPEC(tv, ts) \ -(ts)->tv_sec = (tv)->tv_sec; \ -(ts)->tv_nsec = (tv)->tv_usec * 1000; + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; #define TIMESPEC_TO_TIMEVAL(tv, ts) \ -(tv)->tv_sec = (ts)->tv_sec; \ -(tv)->tv_usec = (ts)->tv_nsec / 1000; - + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; /* some more utility functions */ /* Operations on timevals. */ #ifndef timerclear -#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +# define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 #endif #ifndef timerisset -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) #endif #ifndef timercmp -#define timercmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec) ? \ - ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) +# define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp(uvp)->tv_usec) \ + : ((tvp)->tv_sec cmp(uvp)->tv_sec)) #endif #ifndef timeradd -#define timeradd(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ - if ((vvp)->tv_usec >= 1000000) { \ - (vvp)->tv_sec++; \ - (vvp)->tv_usec -= 1000000; \ - } \ - } while (0) +# define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) #endif #ifndef timersub -#define timersub(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ - } \ - } while (0) +# define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) #endif /* Operations on timespecs. */ #ifndef timespecclear -#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 +# define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 #endif #ifndef timespecisset -#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +# define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) #endif #ifndef timespeccmp -#define timespeccmp(tsp, usp, cmp) \ - (((tsp)->tv_sec == (usp)->tv_sec) ? \ - ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ - ((tsp)->tv_sec cmp (usp)->tv_sec)) +# define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? ((tsp)->tv_nsec cmp(usp)->tv_nsec) \ + : ((tsp)->tv_sec cmp(usp)->tv_sec)) #endif #ifndef timespecadd -#define timespecadd(tsp, usp, vsp) \ - do { \ - (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ - (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ - if ((vsp)->tv_nsec >= 1000000000L) { \ - (vsp)->tv_sec++; \ - (vsp)->tv_nsec -= 1000000000L; \ - } \ - } while (0) +# define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) #endif #ifndef timespecsub -#define timespecsub(tsp, usp, vsp) \ - do { \ - (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ - (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ - if ((vsp)->tv_nsec < 0) { \ - (vsp)->tv_sec--; \ - (vsp)->tv_nsec += 1000000000L; \ - } \ - } while (0) +# define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) #endif /* * Names of the interval timers, and structure - * defining a timer setting. - */ -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 struct itimerval { - struct timeval it_interval; /* timer interval */ - struct timeval it_value; /* current value */ + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ }; /* * Getkerninfo clock information structure */ struct clockinfo { - int hz; /* clock frequency */ - int tick; /* micro-seconds per hz tick */ - int tickadj; /* clock skew rate for adjtime() */ - int stathz; /* statistics clock frequency */ - int profhz; /* profiling clock frequency */ + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int tickadj; /* clock skew rate for adjtime() */ + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ }; -#define CLOCK_REALTIME 0 -#define CLOCK_VIRTUAL 1 -#define CLOCK_PROF 2 +#define CLOCK_REALTIME 0 +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 -#define TIMER_RELTIME 0x0 /* relative timer */ -#define TIMER_ABSTIME 0x1 /* absolute timer */ +#define TIMER_RELTIME 0x0 /* relative timer */ +#define TIMER_ABSTIME 0x1 /* absolute timer */ #ifndef OPAL_TIMESPEC -#define OPAL_TIMESPEC -struct timespec -{ - long tv_sec; - long tv_nsec; +# define OPAL_TIMESPEC +struct timespec { + long tv_sec; + long tv_nsec; }; #endif - /* NOTE: The use of timezone is obsolete even in linux and my gettimeofday function is not going to support it either. So, please be aware of the fact that if you expect to pass anything here, then you are DEAD :-D */ -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; +struct timezone { + int tz_minuteswest; + int tz_dsttime; }; BEGIN_C_DECLS -OPAL_DECLSPEC int gettimeofday (struct timeval *tv, struct timezone *tz); +OPAL_DECLSPEC int gettimeofday(struct timeval *tv, struct timezone *tz); END_C_DECLS -#endif /* OPAL_TIME_H */ +#endif /* OPAL_TIME_H */ diff --git a/opal/win32/opal_uio.c b/opal/win32/opal_uio.c index 221a2297417..0270e0f4f7b 100644 --- a/opal/win32/opal_uio.c +++ b/opal/win32/opal_uio.c @@ -26,31 +26,29 @@ of code to handle the windows error flags */ -int writev( int fd, struct iovec * iov, int cnt ) +int writev(int fd, struct iovec *iov, int cnt) { - int err; - DWORD sendlen; + int err; + DWORD sendlen; - err = WSASend((SOCKET) fd, &(iov->data), cnt, &sendlen, 0, NULL, NULL); + err = WSASend((SOCKET) fd, &(iov->data), cnt, &sendlen, 0, NULL, NULL); - if (err < 0) { - return err; - } - return (int) sendlen; + if (err < 0) { + return err; + } + return (int) sendlen; } - -int readv( int fd, struct iovec * iov, int cnt ) +int readv(int fd, struct iovec *iov, int cnt) { - int err; - DWORD recvlen = 0; - DWORD flags = 0; + int err; + DWORD recvlen = 0; + DWORD flags = 0; - err = WSARecv((SOCKET) fd, &(iov->data), cnt, &recvlen, &flags, NULL, NULL); + err = WSARecv((SOCKET) fd, &(iov->data), cnt, &recvlen, &flags, NULL, NULL); - if( err < 0 ) { - return err; - } - return (int) recvlen; + if (err < 0) { + return err; + } + return (int) recvlen; } - diff --git a/opal/win32/opal_uio.h b/opal/win32/opal_uio.h index b97be357a7d..2691b0bd3d4 100644 --- a/opal/win32/opal_uio.h +++ b/opal/win32/opal_uio.h @@ -22,15 +22,15 @@ #include "opal_config.h" #ifndef OPAL_WIN_COMPAT_H -#error This file is supposed to be included only from win_compat.h -#endif /* OPAL_WIN_COMPAT_H */ +# error This file is supposed to be included only from win_compat.h +#endif /* OPAL_WIN_COMPAT_H */ /* define the iovec structure */ struct iovec { - WSABUF data; + WSABUF data; }; #define iov_base data.buf -#define iov_len data.len +#define iov_len data.len BEGIN_C_DECLS /* @@ -40,7 +40,7 @@ BEGIN_C_DECLS buffers are used in the order specified. Operates just like write except that data is taken from iov instead of a contiguous buffer. */ -OPAL_DECLSPEC int writev (int fd, struct iovec *iov, int cnt); +OPAL_DECLSPEC int writev(int fd, struct iovec *iov, int cnt); /* readv reads data from file descriptor fd, and puts the result in the @@ -49,7 +49,7 @@ OPAL_DECLSPEC int writev (int fd, struct iovec *iov, int cnt); like read except that data is put in iov instead of a contiguous buffer. */ -OPAL_DECLSPEC int readv (int fd, struct iovec *iov, int cnt); +OPAL_DECLSPEC int readv(int fd, struct iovec *iov, int cnt); END_C_DECLS diff --git a/opal/win32/opal_util.h b/opal/win32/opal_util.h index 20b78dc7c79..9c63e5163eb 100644 --- a/opal/win32/opal_util.h +++ b/opal/win32/opal_util.h @@ -24,7 +24,7 @@ static __inline int getpagesize(void) SYSTEM_INFO sys_info; GetSystemInfo(&sys_info); - return (int)sys_info.dwPageSize; + return (int) sys_info.dwPageSize; } #endif diff --git a/opal/win32/opal_utsname.c b/opal/win32/opal_utsname.c index b6d06876fba..934c0af73eb 100644 --- a/opal/win32/opal_utsname.c +++ b/opal/win32/opal_utsname.c @@ -30,7 +30,7 @@ 5. machine: GetSystemInfo */ -int uname( struct utsname *un ) +int uname(struct utsname *un) { TCHAR env_variable[] = "OS=%OS%"; DWORD info_buf_count; @@ -38,15 +38,15 @@ int uname( struct utsname *un ) SYSTEM_INFO sys_info; TCHAR info_buf[OPAL_UTSNAME_LEN]; - info_buf_count = ExpandEnvironmentStrings( env_variable, info_buf, OPAL_UTSNAME_LEN); + info_buf_count = ExpandEnvironmentStrings(env_variable, info_buf, OPAL_UTSNAME_LEN); if (0 == info_buf_count) { - snprintf( un->sysname, OPAL_UTSNAME_LEN, "Unknown" ); + snprintf(un->sysname, OPAL_UTSNAME_LEN, "Unknown"); } else { /* remove the "OS=" from the beginning of the string */ - opal_string_copy( un->sysname, info_buf + 3, OPAL_UTSNAME_LEN ); + opal_string_copy(un->sysname, info_buf + 3, OPAL_UTSNAME_LEN); } info_buf_count = OPAL_UTSNAME_LEN; - if (!GetComputerName( un->nodename, &info_buf_count)) { + if (!GetComputerName(un->nodename, &info_buf_count)) { snprintf(un->nodename, OPAL_UTSNAME_LEN, "undefined"); } @@ -56,31 +56,29 @@ int uname( struct utsname *un ) snprintf(un->version, OPAL_UTSNAME_LEN, "undefined"); } else { /* fill in both release and version information */ - snprintf( un->release, OPAL_UTSNAME_LEN, "%d.%d.%d", - version_info.dwMajorVersion, - version_info.dwMinorVersion, - version_info.dwBuildNumber); - snprintf( un->version, OPAL_UTSNAME_LEN, "%s", version_info.szCSDVersion ); + snprintf(un->release, OPAL_UTSNAME_LEN, "%d.%d.%d", version_info.dwMajorVersion, + version_info.dwMinorVersion, version_info.dwBuildNumber); + snprintf(un->version, OPAL_UTSNAME_LEN, "%s", version_info.szCSDVersion); } /* get machine information */ GetSystemInfo(&sys_info); - switch( sys_info.wProcessorArchitecture ) { - case PROCESSOR_ARCHITECTURE_UNKNOWN: - snprintf( un->machine, OPAL_UTSNAME_LEN, "Unknown %d", sys_info.wProcessorLevel ); - break; - case PROCESSOR_ARCHITECTURE_INTEL: - snprintf( un->machine, OPAL_UTSNAME_LEN, "Intel %d", sys_info.wProcessorLevel ); - break; - case PROCESSOR_ARCHITECTURE_IA64: - snprintf( un->machine, OPAL_UTSNAME_LEN, "IA64 %d", sys_info.wProcessorLevel ); - break; - case PROCESSOR_ARCHITECTURE_AMD64: - snprintf( un->machine, OPAL_UTSNAME_LEN, "AMD %d", sys_info.wProcessorLevel ); - break; - default: - snprintf( un->machine, OPAL_UTSNAME_LEN, "UFO hardware %d", sys_info.wProcessorLevel ); - break; + switch (sys_info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_UNKNOWN: + snprintf(un->machine, OPAL_UTSNAME_LEN, "Unknown %d", sys_info.wProcessorLevel); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + snprintf(un->machine, OPAL_UTSNAME_LEN, "Intel %d", sys_info.wProcessorLevel); + break; + case PROCESSOR_ARCHITECTURE_IA64: + snprintf(un->machine, OPAL_UTSNAME_LEN, "IA64 %d", sys_info.wProcessorLevel); + break; + case PROCESSOR_ARCHITECTURE_AMD64: + snprintf(un->machine, OPAL_UTSNAME_LEN, "AMD %d", sys_info.wProcessorLevel); + break; + default: + snprintf(un->machine, OPAL_UTSNAME_LEN, "UFO hardware %d", sys_info.wProcessorLevel); + break; } return 0; diff --git a/opal/win32/opal_utsname.h b/opal/win32/opal_utsname.h index 11bd45c52fd..d82e2f65c8f 100644 --- a/opal/win32/opal_utsname.h +++ b/opal/win32/opal_utsname.h @@ -32,7 +32,7 @@ struct utsname { }; BEGIN_C_DECLS - OPAL_DECLSPEC int uname(struct utsname *un); +OPAL_DECLSPEC int uname(struct utsname *un); END_C_DECLS #endif /* OPAL_UTSNAME_H */ diff --git a/opal/win32/win_compat.h b/opal/win32/win_compat.h index 99072b9f9c1..9d2d7a29fda 100644 --- a/opal/win32/win_compat.h +++ b/opal/win32/win_compat.h @@ -37,10 +37,10 @@ * Redefine them to our names. * Supposedly, links are not available */ -#define S_IFLNK 0xFFFF /* identifies the file as a symbolic link */ -#define S_IXUSR _S_IEXEC /* execute/search permission, owner */ -#define S_IRUSR _S_IREAD /* read permission, owner */ -#define S_IWUSR _S_IWRITE /* write permission, owner */ +#define S_IFLNK 0xFFFF /* identifies the file as a symbolic link */ +#define S_IXUSR _S_IEXEC /* execute/search permission, owner */ +#define S_IRUSR _S_IREAD /* read permission, owner */ +#define S_IWUSR _S_IWRITE /* write permission, owner */ /** * Define it in order to get access to the "secure" version of rand. @@ -52,11 +52,11 @@ Note: this file is included only on windows */ #ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif /* WIN32_LEAN_AND_MEAN */ +# define WIN32_LEAN_AND_MEAN +#endif /* WIN32_LEAN_AND_MEAN */ #ifndef VC_EXTRALEAN -#define VC_EXTRALEAN -#endif /* VC_EXTRALEAN */ +# define VC_EXTRALEAN +#endif /* VC_EXTRALEAN */ #include /* FD_SETSIZE determines how many sockets windows can select() on. If not defined @@ -65,14 +65,14 @@ #define FD_SETSIZE 1024 /* other utility header files */ -#include -#include -#include -#include -#include #include #include +#include +#include +#include #include +#include +#include /** * For all file io operations @@ -84,38 +84,36 @@ /* for alloca */ #include - #define STDIN_FILENO 0 #define STDOUT_FILENO 1 #define STDERR_FILENO 2 typedef unsigned short mode_t; typedef long ssize_t; typedef DWORD in_port_t; -typedef char* caddr_t; +typedef char *caddr_t; typedef unsigned int uint; #ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN #endif #ifdef _MSC_VER -#if defined(OMPI_BUILDING) && OMPI_BUILDING -#include "opal/win32/opal_uio.h" -#include "opal/win32/opal_time.h" -#include "opal/win32/opal_utsname.h" -#include "opal/win32/opal_util.h" -#include "opal/win32/opal_misc.h" -#include "opal/win32/opal_inet.h" -#include "opal/win32/opal_socket.h" -#endif +# if defined(OMPI_BUILDING) && OMPI_BUILDING +# include "opal/win32/opal_inet.h" +# include "opal/win32/opal_misc.h" +# include "opal/win32/opal_socket.h" +# include "opal/win32/opal_time.h" +# include "opal/win32/opal_uio.h" +# include "opal/win32/opal_util.h" +# include "opal/win32/opal_utsname.h" +# endif /* Defines for the access functions */ -#define F_OK 0x00 -#define R_OK 0x04 -#define W_OK 0x02 -#define X_OK R_OK /* no execution right on Windows */ -#define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) - +# define F_OK 0x00 +# define R_OK 0x04 +# define W_OK 0x02 +# define X_OK R_OK /* no execution right on Windows */ +# define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) /** * Microsoft compiler complain about non conformance of the default UNIX function. @@ -123,61 +121,61 @@ typedef unsigned int uint; * starting with an _ instead. So, in order to keep cl.exe happy (and quiet) we can * use the followings defines. */ -#define getpid _getpid -#define strdup _strdup -#define putenv _putenv -#define getcwd _getcwd -#define rmdir _rmdir -#define chdir _chdir -#define chmod _chmod -#define access _access -#define open _open -#define close _close -#define unlink _unlink -#define dup2 _dup2 -#define dup _dup -#define write _write -#define read _read -#define fileno _fileno -#define isatty _isatty -#define execvp _execvp -#define S_ISDIR(STAT_MODE) ((STAT_MODE) & _S_IFDIR) -#define S_ISREG(STAT_MODE) ((STAT_MODE) & _S_IFREG) -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#define umask _umask -#define getch _getch -#define random rand -#define strtok_r strtok_s -#define srand48 srand -#define lrand48 rand -#define usleep(t) Sleep(t/1000) -#define posix_memalign(p, a, s) *p=_aligned_malloc(s,a) +# define getpid _getpid +# define strdup _strdup +# define putenv _putenv +# define getcwd _getcwd +# define rmdir _rmdir +# define chdir _chdir +# define chmod _chmod +# define access _access +# define open _open +# define close _close +# define unlink _unlink +# define dup2 _dup2 +# define dup _dup +# define write _write +# define read _read +# define fileno _fileno +# define isatty _isatty +# define execvp _execvp +# define S_ISDIR(STAT_MODE) ((STAT_MODE) &_S_IFDIR) +# define S_ISREG(STAT_MODE) ((STAT_MODE) &_S_IFREG) +# define strncasecmp _strnicmp +# define strcasecmp _stricmp +# define umask _umask +# define getch _getch +# define random rand +# define strtok_r strtok_s +# define srand48 srand +# define lrand48 rand +# define usleep(t) Sleep(t / 1000) +# define posix_memalign(p, a, s) *p = _aligned_malloc(s, a) #else -#undef WSABASEERR +# undef WSABASEERR /* in MinGW, PACKED is defined to __attribute__((packed)), will have problem for our basic types */ -#undef PACKED -#define pthread_atfork -#include -#if defined(OMPI_BUILDING) && OMPI_BUILDING -#include "opal/win32/opal_uio.h" -#include "opal/win32/opal_utsname.h" -#include "opal/win32/opal_util.h" -#include "opal/win32/opal_inet.h" -#include "opal/win32/opal_misc.h" -#include "opal/win32/opal_socket.h" -#endif - -#define strtok_r(s,d,p) *p = strtok(s,d) +# undef PACKED +# define pthread_atfork +# include +# if defined(OMPI_BUILDING) && OMPI_BUILDING +# include "opal/win32/opal_inet.h" +# include "opal/win32/opal_misc.h" +# include "opal/win32/opal_socket.h" +# include "opal/win32/opal_uio.h" +# include "opal/win32/opal_util.h" +# include "opal/win32/opal_utsname.h" +# endif + +# define strtok_r(s, d, p) *p = strtok(s, d) #endif -#define MAXPATHLEN _MAX_PATH -#define MAXHOSTNAMELEN _MAX_PATH -#define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1) -#define PATH_MAX _MAX_PATH +#define MAXPATHLEN _MAX_PATH +#define MAXHOSTNAMELEN _MAX_PATH +#define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1) +#define PATH_MAX _MAX_PATH #define WTERMSIG(EXIT_CODE) (1) #define WIFEXITED(EXIT_CODE) (1) #define WEXITSTATUS(EXIT_CODE) (EXIT_CODE) @@ -185,65 +183,65 @@ typedef unsigned int uint; #define WIFSTOPPED(EXIT_CODE) (0) #define WSTOPSIG(EXIT_CODE) (11) -#define mkdir(PATH, MODE) _mkdir((PATH)) -#define nanosleep(tp, rem) Sleep(*tp.tv_sec*1000+*tp.tv_nsec/1000000) -#define pipe(array_fd) _pipe(array_fd, 1024, O_BINARY ) -#define inet_ntop opal_inet_ntop -#define inet_pton opal_inet_pton -#define lstat stat +#define mkdir(PATH, MODE) _mkdir((PATH)) +#define nanosleep(tp, rem) Sleep(*tp.tv_sec * 1000 + *tp.tv_nsec / 1000000) +#define pipe(array_fd) _pipe(array_fd, 1024, O_BINARY) +#define inet_ntop opal_inet_ntop +#define inet_pton opal_inet_pton +#define lstat stat #ifndef UINT64_MAX -#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ +# define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ #endif #ifndef UINT64_MIN -#define UINT64_MIN 0 +# define UINT64_MIN 0 #endif #ifndef INT64_MAX -#define INT64_MAX 0x7fffffffffffffffLL /*9223372036854775807LL*/ +# define INT64_MAX 0x7fffffffffffffffLL /*9223372036854775807LL*/ #endif #ifndef INT64_MIN -#define INT64_MIN (-0x7fffffffffffffffLL - 1) /* (-9223372036854775807 - 1) */ +# define INT64_MIN (-0x7fffffffffffffffLL - 1) /* (-9223372036854775807 - 1) */ #endif #ifndef UINT32_MAX -#define UINT32_MAX 0xffffffff /* 4294967295U */ +# define UINT32_MAX 0xffffffff /* 4294967295U */ #endif #ifndef UINT32_MIN -#define UINT32_MIN 0 +# define UINT32_MIN 0 #endif #ifndef INT32_MAX -#define INT32_MAX 0x7fffffff /* 2147483647 */ +# define INT32_MAX 0x7fffffff /* 2147483647 */ #endif #ifndef INT32_MIN -#define INT32_MIN (-0x7fffffff - 1) /* (-2147483647 - 1) */ +# define INT32_MIN (-0x7fffffff - 1) /* (-2147483647 - 1) */ #endif #ifndef UINT16_MAX -#define UINT16_MAX 0xffff /* 65535U */ +# define UINT16_MAX 0xffff /* 65535U */ #endif #ifndef UINT16_MIN -#define UINT16_MIN 0 +# define UINT16_MIN 0 #endif #ifndef INT16_MAX -#define INT16_MAX 0x7fff /* 32767 */ +# define INT16_MAX 0x7fff /* 32767 */ #endif #ifndef INT16_MIN -#define INT16_MIN (-0x7fff - 1) /* (-32768) */ +# define INT16_MIN (-0x7fff - 1) /* (-32768) */ #endif #ifndef UINT8_MAX -#define UINT8_MAX 0xff /* 255U */ +# define UINT8_MAX 0xff /* 255U */ #endif #ifndef UINT8_MIN -#define UINT8_MIN 0 +# define UINT8_MIN 0 #endif #ifndef INT8_MAX -#define INT8_MAX 0x7f /* 127 */ +# define INT8_MAX 0x7f /* 127 */ #endif #ifndef INT8_MIN -#define INT8_MIN (-0x7f - 1) /* (-128) */ +# define INT8_MIN (-0x7f - 1) /* (-128) */ #endif /* Make sure we let the compiler know that we support __func__ */ #if !defined(HAVE_DECL___FUNC__) -#define HAVE_DECL___FUNC__ 1 +# define HAVE_DECL___FUNC__ 1 #endif /*#define sprintf sprintf_s*/ @@ -253,20 +251,20 @@ typedef unsigned int uint; * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_raise.asp * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/UCMGch09.asp */ -#define SIGHUP 1 +#define SIGHUP 1 /* 2 is used for SIGINT on windows */ -#define SIGQUIT 3 +#define SIGQUIT 3 /* 4 is used for SIGILL on windows */ -#define SIGTRAP 5 -#define SIGIOT 6 -#define SIGBUS 7 +#define SIGTRAP 5 +#define SIGIOT 6 +#define SIGBUS 7 /* 8 is used for SIGFPE on windows */ -#define SIGKILL 9 -#define SIGUSR1 10 +#define SIGKILL 9 +#define SIGUSR1 10 /* 11 is used for SIGSEGV on windows */ -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 /* 15 is used for SIGTERM on windows */ #define SIGSTKFLT 16 #define SIGCHLD 17 @@ -293,16 +291,16 @@ typedef unsigned int uint; #define WUNTRACED 0 #define WNOHANG 0 -#define sigset_t int +#define sigset_t int #define in_addr_t uint32_t /* Need to define _Bool here for different version of VS. The definition in opal_config_bottom.h won't help, as long as we have a mixed C and C++ projects in one solution. */ #if defined(_MSC_VER) && _MSC_VER < 1600 -#define _Bool BOOL +# define _Bool BOOL #else -#define _Bool bool +# define _Bool bool #endif /* @@ -318,13 +316,12 @@ typedef unsigned int uint; #define LOG_INFO 6 #define LOG_DEBUG 7 - /* * Mask these to Windows equivalents */ -#define bzero(p, l) memset(p, 0, l) +#define bzero(p, l) memset(p, 0, l) #define bcopy(s, t, l) memmove(t, s, l) -#define isblank(c) (c == ' ' || c == '\t')?1:0 +#define isblank(c) (c == ' ' || c == '\t') ? 1 : 0 /* * OMPI functions that need to be redefined. @@ -332,5 +329,4 @@ typedef unsigned int uint; #define ompi_debugger_notify_abort(x) #define ompi_wait_for_debugger(x) - #endif /* compat */