From b9551ee0242cb5044b0ee92fba1808c4b8c816e1 Mon Sep 17 00:00:00 2001 From: Matthieu Dorier Date: Tue, 26 Mar 2024 14:59:30 +0000 Subject: [PATCH] implemented static backend --- include/flock/flock-backend.h | 79 +++++++++++++++++++++++++++++++- include/flock/flock-group-view.h | 11 ++--- src/static/static-backend.c | 33 +++++++------ 3 files changed, 103 insertions(+), 20 deletions(-) diff --git a/include/flock/flock-backend.h b/include/flock/flock-backend.h index fa864e2..85913a9 100644 --- a/include/flock/flock-backend.h +++ b/include/flock/flock-backend.h @@ -16,21 +16,98 @@ extern "C" { struct json_object; +/** + * @brief Initialization arguments. + * + * @note The backend's init_group can call json_object_get on the + * config to increase its reference count and keep it internally + * (the provider does not modify it). + * + * @note The backend's init_group can copy the initial_view internally. + * If it does it, it should memset the flock_backend_init_args's initial_view + * field to 0 so that the provider does not free it. + */ typedef struct flock_backend_init_args { margo_instance_id mid; uint16_t provider_id; ABT_pool pool; struct json_object* config; + flock_group_view_t initial_view; } flock_backend_init_args_t; -typedef flock_return_t (*flock_backend_init_fn)(const flock_backend_init_args_t* args, void**); +/** + * @brief Allocates and initializes the state of the backend. + * + * @param[in] flock_backend_init_args_t* Initialization arguments. + * @param[out] void** Pointer to the allocated state. + * + * @note This function may move some of the fields of the flock_backend_init_args_t + * (see comments about flock_backend_init_args_t above). + */ +typedef flock_return_t (*flock_backend_init_fn)(flock_backend_init_args_t* args, void**); + +/** + * @brief Finalizes and deallocate the state of the backend. + * + * @param void* Pointer to the backend's state. + */ typedef flock_return_t (*flock_backend_finalize_fn)(void*); + +/** + * @brief Get the config of the backend and pass it to the + * provided function pointer. + * + * @param void* Pointer to the backend's state. + * @param void (*)(void*, const struct json_object*) Function to call on the config. + * @param void* Context to pass to the function. + */ typedef flock_return_t (*flock_backend_get_config_fn)(void*, void (*)(void*, const struct json_object*), void*); + +/** + * @brief Get the group view held by the backend. + * + * @param void* Pointer to the backend's state. + * @param void (*)(void*, const flock_group_view_t*) Function to call on the group view. + * @param void* Context to pass to the function. + * + * @important This function should NOT lock the view using the view's mtx field. + */ typedef flock_return_t (*flock_backend_get_view_fn)(void*, void (*)(void*, const flock_group_view_t*), void*); + +/** + * @brief Add metadata to the backend. + * + * @param void* Pointer to the backend's state. + * @param const char* Key (null-terminated). + * @param const char* Value (null-terminated). + */ typedef flock_return_t (*flock_backend_add_metadata_fn)(void*, const char*, const char*); + +/** + * @brief Remove metadata from the backend. + * + * @param void* Pointer to the backend's state. + * @param const char* Key (null-terminated). + */ typedef flock_return_t (*flock_backend_remove_metadata_fn)(void*, const char*); + +/** + * @brief Add a member to the group managed by the backend. + * + * @param void* Pointer to the backend's state. + * @param uint64_t Rank of the member to add. + * @param const char* Address of the member. + * @param uint16_t Provider ID of the member. + */ typedef flock_return_t (*flock_backend_add_member_fn)(void*, uint64_t, const char*, uint16_t); + +/** + * @brief Remove a member from the group managed by the backend. + * + * @param void* Pointer to the backend's state. + * @param uint64_t Rank of the member to remove. + */ typedef flock_return_t (*flock_backend_remove_member_fn)(void*, uint64_t); /** diff --git a/include/flock/flock-group-view.h b/include/flock/flock-group-view.h index 5fa6ed9..97c06d8 100644 --- a/include/flock/flock-group-view.h +++ b/include/flock/flock-group-view.h @@ -367,15 +367,14 @@ static inline const char *flock_group_view_find_metadata(const flock_group_view_ } /** - * @brief Internal serialization function. This function is used by - * hg_proc_flock_group_view_t, which also locks the view while serializing. + * @brief Serialize/deserialize a group view. * * @param proc Mercury proc object. * @param view View to serialize/deserialize. * * @return hg_return_t code. */ -static inline hg_return_t hg_proc_flock_group_view_t_internal(hg_proc_t proc, flock_group_view_t* view) { +static inline hg_return_t hg_proc_flock_group_view_t(hg_proc_t proc, flock_group_view_t* view) { hg_return_t ret = HG_SUCCESS; ret = hg_proc_hg_size_t(proc, &view->members.size); if(ret != HG_SUCCESS) return ret; @@ -416,16 +415,16 @@ static inline hg_return_t hg_proc_flock_group_view_t_internal(hg_proc_t proc, fl } /** - * @brief Serializes/deserializes a flock_group_view_t. + * @brief Serializes/deserializes a flock_group_view_t and protect its access with a lock. * * @param proc Mercury proc object. * @param view View to serialize/deserialize. * * @return hg_return_t code. */ -static inline hg_return_t hg_proc_flock_group_view_t(hg_proc_t proc, flock_group_view_t* view) { +static inline hg_return_t hg_proc_flock_protected_group_view_t(hg_proc_t proc, flock_group_view_t* view) { FLOCK_GROUP_VIEW_LOCK(view); - hg_return_t hret = hg_proc_flock_group_view_t_internal(proc, view); + hg_return_t hret = hg_proc_flock_group_view_t(proc, view); FLOCK_GROUP_VIEW_UNLOCK(view); return hret; } diff --git a/src/static/static-backend.c b/src/static/static-backend.c index 97015c1..f29fa48 100644 --- a/src/static/static-backend.c +++ b/src/static/static-backend.c @@ -17,11 +17,20 @@ typedef struct static_context { } static_context; static flock_return_t static_create_group( - const flock_backend_init_args_t* args, + flock_backend_init_args_t* args, void** context) { static_context* ctx = (static_context*)calloc(1, sizeof(*ctx)); - json_object_deep_copy(args->config, &ctx->config, NULL); + if(!ctx) return FLOCK_ERR_ALLOCATION; + + ctx->config = args->config; + json_object_get(ctx->config); + + memcpy(&ctx->view.members, &args->initial_view.members, sizeof(ctx->view.members)); + memcpy(&ctx->view.metadata, &args->initial_view.metadata, sizeof(ctx->view.metadata)); + memset(&args->initial_view.members, 0, sizeof(ctx->view.members)); + memset(&args->initial_view.metadata, 0, sizeof(ctx->view.metadata)); + *context = ctx; return FLOCK_SUCCESS; } @@ -49,9 +58,7 @@ static flock_return_t static_get_view( void* ctx, void (*fn)(void*, const flock_group_view_t* view), void* uargs) { static_context* context = (static_context*)ctx; - FLOCK_GROUP_VIEW_LOCK(&context->view); fn(uargs, &context->view); - FLOCK_GROUP_VIEW_UNLOCK(&context->view); return FLOCK_SUCCESS; } @@ -91,15 +98,15 @@ static flock_return_t static_remove_metadata( } static flock_backend_impl static_backend = { - .name = "static", - .init_group = static_create_group, - .destroy_group = static_destroy_group, - .get_config = static_get_config, - .get_view = static_get_view, - .add_member = static_add_member, - .remove_member = static_remove_member, - .add_metadata = static_add_metadata, - .remove_metadata = static_remove_metadata + .name = "static", + .init_group = static_create_group, + .destroy_group = static_destroy_group, + .get_config = static_get_config, + .get_view = static_get_view, + .add_member = static_add_member, + .remove_member = static_remove_member, + .add_metadata = static_add_metadata, + .remove_metadata = static_remove_metadata }; flock_return_t flock_register_static_backend(void)