X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/399e4077a352ec6e0ad4134e5645a29d0d241c88..0c43de62fbe4bfc243d6512296e09207e80bcd54:/src/surf/surf.cpp diff --git a/src/surf/surf.cpp b/src/surf/surf.cpp index fdfc7935e9..2d9661742c 100644 --- a/src/surf/surf.cpp +++ b/src/surf/surf.cpp @@ -3,6 +3,7 @@ #include "network.hpp" #include "cpu.hpp" #include "workstation.hpp" +#include "vm_workstation.hpp" #include "simix/smx_host_private.h" #include "surf_routing.hpp" #include "simgrid/sg_config.h" @@ -51,7 +52,7 @@ static void remove_watched_host(void *key) xbt_dict_remove(watched_hosts_lib, *(char**)key); } -void surf_watched_hosts(void) +/*void surf_watched_hosts(void) { char *key; void *host; @@ -71,13 +72,19 @@ void surf_watched_hosts(void) } xbt_dynar_map(hosts, remove_watched_host); xbt_dynar_free(&hosts); -} +}*/ +/* model_list_invoke contains only surf_workstation and surf_vm_workstation. + * The callback functions of cpu_model and network_model will be called from + * those of these workstation models. */ +xbt_dynar_t model_list = NULL; /* for destroying all models correctly */ +xbt_dynar_t model_list_invoke = NULL; /* for invoking callbacks */ -xbt_dynar_t model_list = NULL; tmgr_history_t history = NULL; lmm_system_t maxmin_system = NULL; xbt_dynar_t surf_path = NULL; +xbt_dynar_t host_that_restart = NULL; +xbt_dict_t watched_hosts_lib; /* Don't forget to update the option description in smx_config when you change this */ s_surf_model_description_t surf_network_model_description[] = { @@ -134,6 +141,13 @@ s_surf_model_description_t surf_workstation_model_description[] = { {NULL, NULL, NULL} /* this array must be NULL terminated */ }; +s_surf_model_description_t surf_vm_workstation_model_description[] = { + {"default", + "Default vm workstation model.)", + surf_vm_workstation_model_init_current_default}, + {NULL, NULL, NULL} /* this array must be NULL terminated */ +}; + s_surf_model_description_t surf_optimization_mode_description[] = { {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", @@ -154,55 +168,19 @@ 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 static double *surf_mins = NULL; /* return value of share_resources for each model */ -static int surf_min_index; /* current index in surf_mins */ -static double min; /* duration determined by surf_solve */ double NOW = 0; -XBT_INLINE double surf_get_clock(void) +double surf_get_clock(void) { return NOW; } -/*TODO: keepit void surf_watched_hosts(void) -{ - char *key; - void *_host; - smx_host_t host; - xbt_dict_cursor_t cursor; - xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL); - - XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib"); - xbt_dict_foreach(watched_hosts_lib,cursor,key,_host) - { - host = (smx_host_t) host; - if(SIMIX_host_get_state(host) == SURF_RESOURCE_ON){ - XBT_INFO("Restart processes on host: %s",SIMIX_host_get_name(host)); - SIMIX_host_autorestart(host); - xbt_dynar_push_as(hosts, char*, key); - } - else - XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key); - } - xbt_dynar_map(hosts, remove_watched_host); - xbt_dynar_free(&hosts); -}*/ - #ifdef _XBT_WIN32 # define FILE_DELIM "\\" #else @@ -333,7 +311,7 @@ static XBT_INLINE void surf_cpu_free(void *r) static XBT_INLINE void surf_link_free(void *r) { - delete static_cast(r); + delete dynamic_cast(static_cast(r)); } static XBT_INLINE void surf_workstation_free(void *r) @@ -356,7 +334,7 @@ void surf_init(int *argc, char **argv) as_router_lib = xbt_lib_new(); storage_lib = xbt_lib_new(); storage_type_lib = xbt_lib_new(); - watched_hosts_lib = xbt_dict_new(); + watched_hosts_lib = xbt_dict_new_homogeneous(NULL); XBT_DEBUG("Add routing levels"); ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free); @@ -370,7 +348,9 @@ void surf_init(int *argc, char **argv) xbt_init(argc, argv); if (!model_list) - model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL); + model_list = xbt_dynar_new(sizeof(ModelPtr), NULL); + if (!model_list_invoke) + model_list_invoke = xbt_dynar_new(sizeof(ModelPtr), NULL); if (!history) history = tmgr_history_new(); @@ -381,7 +361,6 @@ void surf_init(int *argc, char **argv) sg_config_init(argc, argv); - surf_action_init(); if (MC_is_active()) MC_memory_init(); } @@ -391,11 +370,17 @@ void surf_exit(void) unsigned int iter; ModelPtr model = NULL; +#ifdef HAVE_TRACING + TRACE_end(); /* Just in case it was not called by the upper + * layer (or there is no upper layer) */ +#endif + sg_config_finalize(); xbt_dynar_foreach(model_list, iter, model) delete model; xbt_dynar_free(&model_list); + xbt_dynar_free(&model_list_invoke); routing_exit(); if (maxmin_system) { @@ -406,14 +391,13 @@ void surf_exit(void) tmgr_history_free(history); history = NULL; } - surf_action_exit(); #ifdef CONTEXT_THREADS xbt_parmap_destroy(surf_parmap); xbt_free(surf_mins); surf_mins = NULL; #endif - + xbt_dynar_free(&host_that_restart); xbt_dynar_free(&surf_path); xbt_lib_free(&host_lib); @@ -435,9 +419,11 @@ void surf_exit(void) *********/ Model::Model(string name) - : m_name(name), m_resOnCB(0), m_resOffCB(0), m_actSuspendCB(0), m_actCancelCB(0), m_actResumeCB(0) + : p_maxminSystem(0), m_name(name), + m_resOnCB(0), m_resOffCB(0), + m_actCancelCB(0), m_actSuspendCB(0), m_actResumeCB(0) { - ActionPtr action; + ActionPtr action = NULL; p_readyActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup)); p_runningActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup)); p_failedActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup)); @@ -539,32 +525,30 @@ double Model::shareResourcesLazy(double now) return min; } -double Model::shareResourcesFull(double now) { +double Model::shareResourcesFull(double /*now*/) { THROW_UNIMPLEMENTED; } double Model::shareResourcesMaxMin(xbt_swag_t running_actions, - size_t offset, lmm_system_t sys, void (*solve) (lmm_system_t)) { void *_action = NULL; - ActionPtr action = NULL; + ActionLmmPtr action = NULL; double min = -1; double value = -1; -#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + (offset)))) solve(sys); xbt_swag_foreach(_action, running_actions) { - action = (ActionPtr)_action; - value = lmm_variable_getvalue(VARIABLE(action)); + action = dynamic_cast(static_cast(_action)); + value = lmm_variable_getvalue(action->p_variable); if ((value > 0) || (action->m_maxDuration >= 0)) break; } - if (!action) + if (!_action) return -1.0; if (value > 0) { @@ -578,10 +562,11 @@ double Model::shareResourcesMaxMin(xbt_swag_t running_actions, min = action->m_maxDuration; - for (action = (ActionPtr) xbt_swag_getNext(action, running_actions->offset); - action; - action = (ActionPtr) xbt_swag_getNext(action, running_actions->offset)) { - value = lmm_variable_getvalue(VARIABLE(action)); + for (_action = xbt_swag_getNext(static_cast(action), running_actions->offset); + _action; + _action = xbt_swag_getNext(static_cast(action), running_actions->offset)) { + action = dynamic_cast(static_cast(_action)); + value = lmm_variable_getvalue(action->p_variable); if (value > 0) { if (action->m_remains > 0) value = action->m_remains / value; @@ -599,7 +584,6 @@ double Model::shareResourcesMaxMin(xbt_swag_t running_actions, } XBT_DEBUG("min value : %f", min); -#undef VARIABLE return min; } @@ -613,12 +597,12 @@ void Model::updateActionsState(double now, double delta) xbt_die("Invalid cpu update mechanism!"); } -void Model::updateActionsStateLazy(double now, double delta) +void Model::updateActionsStateLazy(double /*now*/, double /*delta*/) { } -void Model::updateActionsStateFull(double now, double delta) +void Model::updateActionsStateFull(double /*now*/, double /*delta*/) { } @@ -680,7 +664,7 @@ void Model::notifyActionSuspend(ActionPtr a) ************/ Resource::Resource(surf_model_t model, const char *name, xbt_dict_t props) - : m_name(xbt_strdup(name)), m_running(true), p_model(model), m_properties(props) + : m_name(xbt_strdup(name)), m_properties(props), p_model(model), m_running(true) {} Resource::Resource(){ @@ -703,6 +687,11 @@ e_surf_resource_state_t Resource::getState() return p_stateCurrent; } +void Resource::setState(e_surf_resource_state_t state) +{ + p_stateCurrent = state; +} + bool Resource::isOn() { return m_running; @@ -737,11 +726,11 @@ ResourceLmm::ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props, p_constraint = lmm_constraint_new(system, this, constraint_value); p_stateCurrent = state_init; if (state_trace) - p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this); + p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast(this)); p_power.scale = 1.0; p_power.peak = metric_peak; if (metric_trace) - p_power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, this); + p_power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, static_cast(this)); } /********** @@ -757,32 +746,17 @@ const char *surf_action_state_names[6] = { "SURF_ACTION_NOT_IN_THE_SYSTEM" }; -/** - * \brief Initializes the action module of Surf. - */ -void surf_action_init(void) { - - /* the action mallocator will always provide actions of the following size, - * so this size should be set to the maximum size of the surf action structures - */ - /*FIXME:action_mallocator_allocated_size = sizeof(s_surf_action_network_CM02_t); - action_mallocator = xbt_mallocator_new(65536, surf_action_mallocator_new_f, - surf_action_mallocator_free_f, surf_action_mallocator_reset_f);*/ -} - -/** - * \brief Uninitializes the action module of Surf. - */ -void surf_action_exit(void) { - //FIXME:xbt_mallocator_free(action_mallocator); -} - Action::Action(){} Action::Action(ModelPtr model, double cost, bool failed): - m_cost(cost), p_model(model), m_failed(failed), m_remains(cost), - m_refcount(1), m_priority(1.0), m_maxDuration(NO_MAX_DURATION), - m_start(surf_get_clock()), m_finish(-1.0) + m_priority(1.0), + m_failed(failed), + m_start(surf_get_clock()), m_finish(-1.0), + m_remains(cost), + m_maxDuration(NO_MAX_DURATION), + m_cost(cost), + p_model(model), + m_refcount(1) { #ifdef HAVE_TRACING p_category = NULL; @@ -1023,16 +997,16 @@ void ActionLmm::updateRemainingLazy(double now) delta = now - m_lastUpdate; if (m_remains > 0) { - XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate); + XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate); double_update(&m_remains, m_lastValue * delta); #ifdef HAVE_TRACING - if (p_model == static_cast(surf_cpu_model) && TRACE_is_enabled()) { + if (p_model == static_cast(surf_cpu_model_pm) && TRACE_is_enabled()) { ResourcePtr cpu = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(p_model->p_maxminSystem, p_variable, 0))); TRACE_surf_host_set_utilization(cpu->m_name, p_category, m_lastValue, m_lastUpdate, now - m_lastUpdate); } #endif - XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains); + XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains); } if(p_model == static_cast(surf_network_model))