-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from yosefe/topic/add-ucs-component
UCS/TEST: Add 'component' service for global initialization.
- Loading branch information
Showing
15 changed files
with
453 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (C) Mellanox Technologies Ltd. 2001-2012. ALL RIGHTS RESERVED. | ||
* | ||
* $COPYRIGHT$ | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "component.h" | ||
|
||
#include <ucs/datastruct/list.h> | ||
|
||
|
||
void __ucs_component_add(ucs_list_link_t *list, size_t base_size, ucs_component_t *comp) | ||
{ | ||
comp->offset = __ucs_components_total_size(list, base_size); | ||
ucs_list_add_tail(list, &comp->list); | ||
} | ||
|
||
size_t __ucs_components_total_size(ucs_list_link_t *list, size_t base_size) | ||
{ | ||
ucs_component_t *last; | ||
|
||
if (ucs_list_is_empty(list)) { | ||
return base_size; | ||
} | ||
|
||
last = ucs_list_tail(list, ucs_component_t, list); | ||
return last->offset + last->size; | ||
} | ||
|
||
void __ucs_components_cleanup(ucs_list_link_t *start, ucs_list_link_t *end, void *base_ptr) | ||
{ | ||
ucs_list_link_t *iter; | ||
|
||
iter = start; | ||
while (iter->next != end) { | ||
ucs_list_head(iter, ucs_component_t, list)->cleanup(base_ptr); | ||
iter = iter->next; | ||
} | ||
} | ||
|
||
ucs_status_t __ucs_components_init_all(ucs_list_link_t *list, void *base_ptr) | ||
{ | ||
ucs_component_t *comp; | ||
ucs_status_t status; | ||
|
||
ucs_list_for_each(comp, list, list) { | ||
status = comp->init(base_ptr); | ||
if (status != UCS_OK) { | ||
__ucs_components_cleanup(list, comp->list.next, base_ptr); | ||
return status; | ||
} | ||
} | ||
return UCS_OK; | ||
} | ||
|
||
void __ucs_components_cleanup_all(ucs_list_link_t *list, void *base_ptr) | ||
{ | ||
__ucs_components_cleanup(list, list, base_ptr); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* Copyright (C) Mellanox Technologies Ltd. 2001-2012. ALL RIGHTS RESERVED. | ||
* | ||
* $COPYRIGHT$ | ||
* $HEADER$ | ||
*/ | ||
|
||
|
||
#ifndef UCS_COMPONENT_H_ | ||
#define UCS_COMPONENT_H_ | ||
|
||
#include <ucs/sys/preprocessor.h> | ||
#include <ucs/datastruct/list.h> | ||
#include <ucs/type/status.h> | ||
|
||
|
||
/* | ||
* Component definition - used internally. | ||
*/ | ||
typedef ucs_status_t (*ucs_component_init_cb_t)(void *base_ptr); | ||
typedef void (*ucs_component_cleanup_cb_t)(void *base_ptr); | ||
typedef struct ucs_component { | ||
const char *name; | ||
ucs_component_init_cb_t init; | ||
ucs_component_cleanup_cb_t cleanup; | ||
size_t size; | ||
size_t offset; | ||
ucs_list_link_t list; | ||
} ucs_component_t; | ||
|
||
|
||
/* | ||
* Helper macros | ||
*/ | ||
#define _UCS_COMPONENT_LIST_NAME(_base_type) \ | ||
ucs ## _base_type ## _component_list | ||
#define _UCS_COMPONENT_LIST_EXTERN(_base_type) \ | ||
extern ucs_list_link_t _UCS_COMPONENT_LIST_NAME(_base_type) | ||
|
||
|
||
/** | ||
* Define a list of components for specific base type. | ||
* | ||
* @param _base_type Type to add components to. | ||
*/ | ||
#define UCS_COMPONENT_LIST_DEFINE(_base_type) \ | ||
UCS_LIST_HEAD(_UCS_COMPONENT_LIST_NAME(_base_type)) | ||
|
||
|
||
/** | ||
* Define a component for specific base type. | ||
* | ||
* @param _base_type Type to add components to. | ||
* @param _name Component name. | ||
* @param _init Initialization function. | ||
* @param _cleanup Cleanup function. | ||
* @param _type Component context type to add to base type. | ||
*/ | ||
#define UCS_COMPONENT_DEFINE(_base_type, _name, _init, _cleanup, _type) \ | ||
\ | ||
size_t ucs_##_name##_component_offset; \ | ||
\ | ||
void UCS_F_CTOR UCS_PP_APPEND_UNIQUE_ID(ucs_component_##_name##_register)() { \ | ||
static ucs_component_t comp = { \ | ||
#_name, \ | ||
(ucs_component_init_cb_t)_init, \ | ||
(ucs_component_cleanup_cb_t)_cleanup, \ | ||
sizeof(_type)}; \ | ||
\ | ||
_UCS_COMPONENT_LIST_EXTERN(_base_type); \ | ||
__ucs_component_add(&_UCS_COMPONENT_LIST_NAME(_base_type), \ | ||
sizeof(_base_type), &comp); \ | ||
ucs_##_name##_component_offset = comp.offset; \ | ||
} | ||
|
||
|
||
/** | ||
* @param _base Components base type. | ||
* @return How much room is required for all components of this base. | ||
*/ | ||
#define ucs_components_total_size(_base_type) \ | ||
({ \ | ||
_UCS_COMPONENT_LIST_EXTERN(_base_type); \ | ||
__ucs_components_total_size(&_UCS_COMPONENT_LIST_NAME(_base_type),\ | ||
sizeof(_base_type)); \ | ||
}) | ||
|
||
|
||
/** | ||
* Initialize all components of a specific base type. | ||
* | ||
* @param _base_type Base type to initialize components for. | ||
* @param _base_ptr Pointer to base type instance, to pass to components | ||
* initialization functions. | ||
* | ||
* @return UCS_OK if all components were successfully initialized, otherwise the | ||
* error from the first failed component. | ||
*/ | ||
#define ucs_components_init_all(_base_type, _base_ptr) \ | ||
({ \ | ||
_UCS_COMPONENT_LIST_EXTERN(_base_type); \ | ||
__ucs_components_init_all(&_UCS_COMPONENT_LIST_NAME(_base_type), _base_ptr); \ | ||
}) | ||
|
||
|
||
/** | ||
* Cleanup all components of a specific base type. | ||
* | ||
* @param _base_type Class whose components to cleanup. | ||
* @param _base_ptr Pointer to base type instance, to pass to components | ||
* cleanup functions. | ||
*/ | ||
#define ucs_components_cleanup_all(_base_type, _base_ptr) \ | ||
{ \ | ||
_UCS_COMPONENT_LIST_EXTERN(_base_type); \ | ||
__ucs_components_cleanup_all(&_UCS_COMPONENT_LIST_NAME(_base_type), _base_ptr); \ | ||
} | ||
|
||
|
||
/** | ||
* Get a component context from base type pointer.. | ||
* | ||
* @param _base_ptr Pointer to base type instance. | ||
* @param _type Type of component context. | ||
* | ||
* @return Pointer to component context. | ||
* | ||
* @note: Cannot be used from library constructors. | ||
*/ | ||
#define ucs_component_get(_base_ptr, _name, _type) \ | ||
({ \ | ||
extern size_t ucs_##_name##_component_offset; \ | ||
((_type*)( (char*)(_base_ptr) + ucs_##_name##_component_offset )); \ | ||
}) | ||
|
||
|
||
void __ucs_component_add(ucs_list_link_t *list, size_t base_size, ucs_component_t *comp); | ||
size_t __ucs_components_total_size(ucs_list_link_t *list, size_t base_size); | ||
ucs_status_t __ucs_components_init_all(ucs_list_link_t *list, void *base_ptr); | ||
void __ucs_components_cleanup_all(ucs_list_link_t *list, void *base_ptr); | ||
|
||
|
||
#endif /* COMPONENT_H_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (C) Mellanox Technologies Ltd. 2001-2014. ALL RIGHTS RESERVED. | ||
* | ||
* $COPYRIGHT$ | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "ib_context.h" | ||
|
||
#include <uct/tl/context.h> | ||
#include <ucs/type/component.h> | ||
|
||
|
||
ucs_status_t uct_ib_init(uct_context_t *context) | ||
{ | ||
return UCS_OK; | ||
} | ||
|
||
void uct_ib_cleanup(uct_context_t *context) | ||
{ | ||
} | ||
|
||
UCS_COMPONENT_DEFINE(uct_context_t, ib, uct_ib_init, uct_ib_cleanup, uct_ib_context_t) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (C) Mellanox Technologies Ltd. 2001-2014. ALL RIGHTS RESERVED. | ||
* | ||
* $COPYRIGHT$ | ||
* $HEADER$ | ||
*/ | ||
|
||
#ifndef UCT_IB_CONTEXT_H_ | ||
#define UCT_IB_CONTEXT_H_ | ||
|
||
|
||
typedef struct uct_ib_context { | ||
} uct_ib_context_t; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (C) Mellanox Technologies Ltd. 2001-2014. ALL RIGHTS RESERVED. | ||
* | ||
* $COPYRIGHT$ | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "context.h" | ||
|
||
#include <uct/api/uct.h> | ||
#include <ucs/debug/memtrack.h> | ||
|
||
UCS_COMPONENT_LIST_DEFINE(uct_context_t); | ||
|
||
ucs_status_t uct_init(uct_context_h *context_p) | ||
{ | ||
ucs_status_t status; | ||
uct_context_t *context; | ||
|
||
context = ucs_malloc(ucs_components_total_size(uct_context_t), "uct context"); | ||
|
||
status = ucs_components_init_all(uct_context_t, context); | ||
if (status != UCS_OK) { | ||
return status; | ||
} | ||
|
||
*context_p = context; | ||
return UCS_OK; | ||
} | ||
|
||
void uct_cleanup(uct_context_h context) | ||
{ | ||
ucs_components_cleanup_all(uct_context_t, context); | ||
ucs_free(context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (C) Mellanox Technologies Ltd. 2001-2014. ALL RIGHTS RESERVED. | ||
* | ||
* $COPYRIGHT$ | ||
* $HEADER$ | ||
*/ | ||
|
||
#ifndef UCT_CONTEXT_H | ||
#define UCT_CONTEXT_H | ||
|
||
#include <uct/api/uct.h> | ||
#include <ucs/type/component.h> | ||
#include <ucs/type/callback.h> | ||
|
||
|
||
typedef struct uct_context uct_context_t; | ||
struct uct_context { | ||
ucs_notifier_chain_t progress_chain; | ||
UCS_STATS_NODE_DECLARE(stats); | ||
}; | ||
|
||
#define uct_component_get(_context, _name) \ | ||
ucs_component_get(_context, _name, uct_context_t) \ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.