From c24da98fc757fe34eb3fdb29b01c80d77313a80a Mon Sep 17 00:00:00 2001 From: navarro Date: Fri, 12 Oct 2012 14:42:32 +0200 Subject: [PATCH] Finish the tutorial for new model and api --- include/simgrid/simix.h | 5 +++++ src/include/surf/surf.h | 15 ++++++++++++--- src/surf/new_model.c | 23 +++++++++++++++-------- src/surf/surf.c | 10 ++++++++++ src/surf/surf_config.c | 27 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 003500a01b..d1af9c2b70 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -464,5 +464,10 @@ XBT_PUBLIC(xbt_dict_t) SIMIX_asr_get_properties(const char *name); /************************** AS router simcalls ***************************/ XBT_PUBLIC(xbt_dict_t) simcall_asr_get_properties(const char *name); +/************************** New API simcalls **********************************/ +/* TUTORIAL: New API */ +/******************************************************************************/ +XBT_PUBLIC(int) simcall_new_api_fct(const char* param1, double param2); + SG_END_DECL() #endif /* _SIMIX_SIMIX_H */ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index d072e4bd91..2790a3da34 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -153,17 +153,16 @@ typedef struct surf_action_state { typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t; XBT_PUBLIC_DATA(routing_platf_t) routing_platf; -/** +/******************************************* * TUTORIAL: New model * New model extension public * Public functions specific to a New model. */ - typedef struct surf_new_model_extension_public { surf_action_t(*fct) (); void* (*create_resource) (); } s_surf_model_extension_new_model_t; - +/*******************************************/ /** \ingroup SURF_models * \brief Private data available on all models @@ -342,7 +341,10 @@ typedef struct surf_model { s_surf_model_extension_network_t network; s_surf_model_extension_storage_t storage; s_surf_model_extension_workstation_t workstation; + /*******************************************/ + /* TUTORIAL: New model */ s_surf_model_extension_new_model_t new_model; + /*******************************************/ } extension; } s_surf_model_t; @@ -655,6 +657,13 @@ XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(void); XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[]; +/******************************************* + * TUTORIAL: New model + */ +XBT_PUBLIC(void) surf_new_model_init_default(void); +XBT_PUBLIC_DATA(s_surf_model_description_t) surf_new_model_description[]; +/*******************************************/ + /** \ingroup SURF_models * \brief List of initialized models */ diff --git a/src/surf/new_model.c b/src/surf/new_model.c index 76a6086df0..2db0dada7d 100644 --- a/src/surf/new_model.c +++ b/src/surf/new_model.c @@ -51,18 +51,25 @@ static void* new_model_create_resource(const char* id, const char* model,const c static void new_model_finalize(void) { - THROW_UNIMPLEMENTED; + lmm_system_free(new_model_maxmin_system); + new_model_maxmin_system = NULL; + + surf_model_exit(surf_new_model); + surf_new_model = NULL; + + xbt_swag_free + (new_model_running_action_set_that_does_not_need_being_checked); + new_model_running_action_set_that_does_not_need_being_checked = NULL; } static void new_model_update_actions_state(double now, double delta) { - THROW_UNIMPLEMENTED; + return; } static double new_model_share_resources(double NOW) { - THROW_UNIMPLEMENTED; - return 0; + return -1; } static int new_model_resource_used(void *resource_id) @@ -131,7 +138,7 @@ static void new_model_define_callbacks() { } -static void surf_new_model_model_init_internal(void) +static void surf_new_model_init_internal(void) { s_surf_action_t action; @@ -141,7 +148,7 @@ static void surf_new_model_model_init_internal(void) new_model_running_action_set_that_does_not_need_being_checked = xbt_swag_new(xbt_swag_offset(action, state_hookup)); - surf_new_model->name = "Storage"; + surf_new_model->name = "New Model"; surf_new_model->action_unref = new_model_action_unref; surf_new_model->action_cancel = new_model_action_cancel; surf_new_model->action_state_set = new_model_action_state_set; @@ -167,9 +174,9 @@ static void surf_new_model_model_init_internal(void) } -void surf_new_model_model_init_default(void) +void surf_new_model_init_default(void) { - surf_new_model_model_init_internal(); + surf_new_model_init_internal(); new_model_define_callbacks(); xbt_dynar_push(model_list, &surf_new_model); diff --git a/src/surf/surf.c b/src/surf/surf.c index 5fb7317eaa..729e6c3166 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -189,6 +189,16 @@ s_surf_model_description_t surf_storage_model_description[] = { {NULL, NULL, NULL} /* this array must be NULL terminated */ }; +/* ********************************************************************* */ +/* TUTORIAL: New model */ +s_surf_model_description_t surf_new_model_description[] = { + {"default", + "Tutorial model.", + surf_new_model_init_default}, + {NULL, NULL, NULL} /* this array must be NULL terminated */ +}; +/* ********************************************************************* */ + #ifdef CONTEXT_THREADS static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */ #endif diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 8aa63e3804..6108c02fc9 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -378,6 +378,23 @@ void surf_config_init(int *argc, char **argv) &default_value, 1, 1, &_surf_cfg_cb__storage_mode, NULL); + /* ********************************************************************* */ + /* TUTORIAL: New model */ + sprintf(description, + "The model to use for the New model. Possible values: "); + p = description; + while (*(++p) != '\0'); + for (i = 0; surf_new_model_description[i].name; i++) + p += sprintf(p, "%s%s", (i == 0 ? "" : ", "), + surf_new_model_description[i].name); + sprintf(p, + ".\n (use 'help' as a value to see the long description of each model)"); + default_value = xbt_strdup("default"); + xbt_cfg_register(&_surf_cfg_set, "new_model/model", description, xbt_cfgelm_string, + &default_value, 1, 1, &_surf_cfg_cb__storage_mode, + NULL); + /* ********************************************************************* */ + sprintf(description, "The model to use for the network. Possible values: "); p = description; @@ -726,4 +743,14 @@ void surf_config_models_setup() XBT_DEBUG("Call storage_model_init"); storage_id = find_model_description(surf_storage_model_description, storage_model_name); surf_storage_model_description[storage_id].model_init_preparse(); + + /* ********************************************************************* */ + /* TUTORIAL: New model */ + int new_model_id = -1; + char *new_model_name = NULL; + new_model_name = xbt_cfg_get_string(_surf_cfg_set, "new_model/model"); + XBT_DEBUG("Call new model_init"); + new_model_id = find_model_description(surf_new_model_description, new_model_name); + surf_new_model_description[new_model_id].model_init_preparse(); + /* ********************************************************************* */ } -- 2.20.1