#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"
xbt_dict_remove(watched_hosts_lib, *(char**)key);
}
-void surf_watched_hosts(void)
+/*void surf_watched_hosts(void)
{
char *key;
void *host;
}
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[] = {
{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).",
{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
static XBT_INLINE void surf_cpu_free(void *r)
{
- delete static_cast<CpuPtr>(r);
+ delete dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(r));
}
static XBT_INLINE void surf_link_free(void *r)
{
- delete static_cast<NetworkCm02LinkPtr>(r);
+ delete dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(r));
}
static XBT_INLINE void surf_workstation_free(void *r)
{
- delete static_cast<WorkstationCLM03Ptr>(r);
+ delete dynamic_cast<WorkstationCLM03Ptr>(static_cast<ResourcePtr>(r));
}
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);
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();
sg_config_init(argc, argv);
- surf_action_init();
if (MC_is_active())
MC_memory_init();
}
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) {
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);
*********/
Model::Model(string name)
- : m_name(name), m_resOnCB(0), m_resOffCB(0), m_actSuspendCB(0), m_actCancelCB(0), m_actResumeCB(0)
+ : m_name(name), m_resOnCB(0), m_resOffCB(0),
+ m_actSuspendCB(0), m_actCancelCB(0), m_actResumeCB(0),
+ p_maxminSystem(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));
{
//FIXME: set the good function once and for all
if (p_updateMechanism == UM_LAZY)
- shareResourcesLazy(now);
+ return shareResourcesLazy(now);
else if (p_updateMechanism == UM_FULL)
- shareResourcesFull(now);
+ return shareResourcesFull(now);
else
xbt_die("Invalid cpu update mechanism!");
}
("After share resources, The size of modified actions set is %d",
xbt_swag_size(p_modifiedSet));
- while((action = (ActionLmmPtr) xbt_swag_extract(p_modifiedSet))) {
+ while((action = static_cast<ActionLmmPtr>(xbt_swag_extract(p_modifiedSet)))) {
int max_dur_flag = 0;
if (action->p_stateSet != p_runningActionSet)
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<ActionLmmPtr>(static_cast<ActionPtr>(_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) {
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<ActionPtr>(action), running_actions->offset);
+ _action;
+ _action = xbt_swag_getNext(static_cast<ActionPtr>(action), running_actions->offset)) {
+ action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
+ value = lmm_variable_getvalue(action->p_variable);
if (value > 0) {
if (action->m_remains > 0)
value = action->m_remains / value;
}
XBT_DEBUG("min value : %f", min);
-#undef VARIABLE
return min;
}
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*/)
{
}
return p_stateCurrent;
}
+void Resource::setState(e_surf_resource_state_t state)
+{
+ p_stateCurrent = state;
+}
+
bool Resource::isOn()
{
return m_running;
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<ResourcePtr>(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<ResourcePtr>(this));
}
/**********
"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):
#ifdef HAVE_TRACING
p_category = NULL;
#endif
+ p_stateHookup.prev = 0;
+ p_stateHookup.next = 0;
if (failed)
p_stateSet = p_model->p_failedActionSet;
else
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<ModelPtr>(surf_cpu_model) && TRACE_is_enabled()) {
+ if (p_model == static_cast<ModelPtr>(surf_cpu_model_pm) && TRACE_is_enabled()) {
ResourcePtr cpu = static_cast<ResourcePtr>(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<ModelPtr>(surf_network_model))