1 /* Copyright (c) 2004-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "surf_private.h"
8 #include "surf_interface.hpp"
9 #include "network_interface.hpp"
10 #include "cpu_interface.hpp"
11 #include "host_interface.hpp"
12 #include "simix/smx_host_private.h"
13 #include "surf_routing.hpp"
14 #include "simgrid/sg_config.h"
16 #include "vm_interface.hpp"
18 XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf,
20 "Logging specific to SURF (kernel)");
26 /* This function is a pimple that we ought to fix. But it won't be easy.
28 * The surf_solve() function does properly return the set of actions that
29 * changed. Instead, each model change a global data, and then the caller of
30 * surf_solve must pick into these sets of action_failed and action_done.
32 * This was not clean but ok as long as we didn't had to restart the processes
33 * when the resource comes back up.
34 * We worked by putting sentinel actions on every resources we are interested
35 * in, so that surf informs us if/when the corresponding resource fails.
37 * But this does not work to get Simix informed of when a resource comes back
38 * up, and this is where this pimple comes. We have a set of resources that are
39 * currently down and for which simix needs to know when it comes back up.
40 * And the current function is called *at every simulation step* to sweep over
41 * that set, searching for a resource that was turned back up in the meanwhile.
42 * This is UGLY and slow.
44 * The proper solution would be to not rely on globals for the action_failed and
45 * action_done swags. They must be passed as parameter by the caller (the
46 * handling of these actions in simix may let you think that these two sets can
47 * be merged, but their handling in SimDag induce the contrary unless this
48 * simdag code can check by itself whether the action is done of failed -- seems
49 * very doable, but yet more cleanup to do).
51 * Once surf_solve() is passed the set of actions that changed, you want to add
52 * a new set of resources back up as parameter to this function. You also want
53 * to add a boolean field "restart_watched" to each resource, and make sure that
54 * whenever a resource with this field enabled comes back up, it's added to that
55 * set so that Simix sees it and react accordingly. This would kill that need
56 * for surf to call simix.
60 /*static void remove_watched_host(void *key)
62 xbt_dict_remove(watched_hosts_lib, *(char**)key);
65 /*void surf_watched_hosts(void)
69 xbt_dict_cursor_t cursor;
70 xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL);
72 XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib");
73 xbt_dict_foreach(watched_hosts_lib, cursor, key, host)
75 if(SIMIX_host_get_state((smx_host_t)host) == SURF_RESOURCE_ON){
76 XBT_INFO("Restart processes on host: %s", SIMIX_host_get_name((smx_host_t)host));
77 SIMIX_host_autorestart((smx_host_t)host);
78 xbt_dynar_push_as(hosts, char*, key);
81 XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key);
83 xbt_dynar_map(hosts, remove_watched_host);
84 xbt_dynar_free(&hosts);
87 /* model_list_invoke contains only surf_host and surf_vm.
88 * The callback functions of cpu_model and network_model will be called from
89 * those of these host models. */
90 xbt_dynar_t model_list = NULL; /* for destroying all models correctly */
91 xbt_dynar_t model_list_invoke = NULL; /* for invoking callbacks */
93 tmgr_history_t history = NULL;
94 lmm_system_t maxmin_system = NULL;
95 xbt_dynar_t surf_path = NULL;
96 xbt_dynar_t host_that_restart = NULL;
97 xbt_dict_t watched_hosts_lib;
99 surf_callback(void, void) surfExitCallbacks;
101 s_surf_model_description_t surf_plugin_description[] = {
102 {"Energy", "Cpu energy consumption.", sg_energy_plugin_init},
103 {NULL, NULL, NULL} /* this array must be NULL terminated */
106 /* Don't forget to update the option description in smx_config when you change
108 s_surf_model_description_t surf_network_model_description[] = {
110 "Realistic network analytic model (slow-start modeled by multiplying latency by 10.4, bandwidth by .92; bottleneck sharing uses a payload of S=8775 for evaluating RTT). ",
111 surf_network_model_init_LegrandVelho},
113 "Simplistic network model where all communication take a constant time (one second). This model provides the lowest realism, but is (marginally) faster.",
114 surf_network_model_init_Constant},
116 "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
117 surf_network_model_init_SMPI},
119 "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
120 surf_network_model_init_IB},
122 "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of small messages are thus poorly modeled).",
123 surf_network_model_init_CM02},
126 "Network pseudo-model using the GTNets simulator instead of an analytic model",
127 surf_network_model_init_GTNETS},
131 "Network pseudo-model using the NS3 tcp model instead of an analytic model",
132 surf_network_model_init_NS3},
135 "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
136 surf_network_model_init_Reno},
138 "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
139 surf_network_model_init_Reno2},
141 "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
142 surf_network_model_init_Vegas},
143 {NULL, NULL, NULL} /* this array must be NULL terminated */
146 s_surf_model_description_t surf_cpu_model_description[] = {
148 "Simplistic CPU model (time=size/power).",
149 surf_cpu_model_init_Cas01},
150 {NULL, NULL, NULL} /* this array must be NULL terminated */
153 s_surf_model_description_t surf_host_model_description[] = {
155 "Default host model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)",
156 surf_host_model_init_current_default},
158 "Host model that is automatically chosen if you change the network and CPU models",
159 surf_host_model_init_compound},
160 {"ptask_L07", "Host model somehow similar to Cas01+CM02 but allowing parallel tasks",
161 surf_host_model_init_ptask_L07},
162 {NULL, NULL, NULL} /* this array must be NULL terminated */
165 s_surf_model_description_t surf_vm_model_description[] = {
168 surf_vm_model_init_HL13},
169 {NULL, NULL, NULL} /* this array must be NULL terminated */
172 s_surf_model_description_t surf_optimization_mode_description[] = {
174 "Lazy action management (partial invalidation in lmm + heap in action remaining).",
177 "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).",
180 "Full update of remaining and variables. Slow but may be useful when debugging.",
182 {NULL, NULL, NULL} /* this array must be NULL terminated */
185 s_surf_model_description_t surf_storage_model_description[] = {
187 "Simplistic storage model.",
188 surf_storage_model_init_default},
189 {NULL, NULL, NULL} /* this array must be NULL terminated */
192 #ifdef CONTEXT_THREADS
193 static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
197 double *surf_mins = NULL; /* return value of share_resources for each model */
198 int surf_min_index; /* current index in surf_mins */
199 double surf_min; /* duration determined by surf_solve */
201 double surf_get_clock(void)
207 # define FILE_DELIM "\\"
209 # define FILE_DELIM "/" /* FIXME: move to better location */
212 FILE *surf_fopen(const char *name, const char *mode)
215 char *path_elm = NULL;
221 if (__surf_is_absolute_file_path(name)) /* don't mess with absolute file names */
222 return fopen(name, mode);
224 /* search relative files in the path */
225 xbt_dynar_foreach(surf_path, cpt, path_elm) {
226 buff = bprintf("%s" FILE_DELIM "%s", path_elm, name);
227 file = fopen(buff, mode);
243 static const char *disk_drives_letter_table[MAX_DRIVE] = {
274 * Returns the initial path. On Windows the initial path is
275 * the current directory for the current process in the other
276 * case the function returns "./" that represents the current
277 * directory on Unix/Linux platforms.
280 const char *__surf_get_initial_path(void)
285 char current_directory[MAX_PATH + 1] = { 0 };
286 unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory);
287 char root[4] = { 0 };
292 strncpy(root, current_directory, 3);
294 for (i = 0; i < MAX_DRIVE; i++) {
295 if (toupper(root[0]) == disk_drives_letter_table[i][0])
296 return disk_drives_letter_table[i];
305 /* The __surf_is_absolute_file_path() returns 1 if
306 * file_path is a absolute file path, in the other
307 * case the function returns 0.
309 int __surf_is_absolute_file_path(const char *file_path)
312 WIN32_FIND_DATA wfd = { 0 };
313 HANDLE hFile = FindFirstFile(file_path, &wfd);
315 if (INVALID_HANDLE_VALUE == hFile)
321 return (file_path[0] == '/');
325 /** Displays the long description of all registered models, and quit */
326 void model_help(const char *category, s_surf_model_description_t * table)
329 printf("Long description of the %s models accepted by this simulator:\n",
331 for (i = 0; table[i].name; i++)
332 printf(" %s: %s\n", table[i].name, table[i].description);
335 int find_model_description(s_surf_model_description_t * table,
339 char *name_list = NULL;
341 for (i = 0; table[i].name; i++)
342 if (!strcmp(name, table[i].name)) {
346 xbt_die("No model is valid! This is a bug.");
347 name_list = xbt_strdup(table[0].name);
348 for (i = 1; table[i].name; i++) {
349 name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
350 strcat(name_list, ", ");
351 strcat(name_list, table[i].name);
353 xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
357 static XBT_INLINE void routing_asr_host_free(void *p)
359 delete ((RoutingEdgePtr) p);
362 static XBT_INLINE void routing_asr_prop_free(void *p)
364 xbt_dict_t elm = (xbt_dict_t) p;
368 static XBT_INLINE void surf_link_free(void *r)
370 delete static_cast<NetworkLinkPtr>(r);
373 static XBT_INLINE void surf_host_free(void *r)
375 delete static_cast<HostPtr>(r);
378 static XBT_INLINE void surf_storage_free(void *r)
380 delete static_cast<StoragePtr>(r);
384 void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
385 *ver_major = SIMGRID_VERSION_MAJOR;
386 *ver_minor = SIMGRID_VERSION_MINOR;
387 *ver_patch = SIMGRID_VERSION_PATCH;
390 void surf_init(int *argc, char **argv)
392 XBT_DEBUG("Create all Libs");
393 host_lib = xbt_lib_new();
394 link_lib = xbt_lib_new();
395 as_router_lib = xbt_lib_new();
396 storage_lib = xbt_lib_new();
397 storage_type_lib = xbt_lib_new();
398 file_lib = xbt_lib_new();
399 watched_hosts_lib = xbt_dict_new_homogeneous(NULL);
403 XBT_DEBUG("Add routing levels");
404 ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
405 ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free);
406 ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
408 XBT_DEBUG("Add SURF levels");
409 SURF_HOST_LEVEL = xbt_lib_add_level(host_lib,surf_host_free);
410 SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_link_free);
411 SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_free);
413 xbt_init(argc, argv);
415 model_list = xbt_dynar_new(sizeof(ModelPtr), NULL);
416 if (!model_list_invoke)
417 model_list_invoke = xbt_dynar_new(sizeof(ModelPtr), NULL);
419 history = tmgr_history_new();
421 TRACE_add_start_function(TRACE_surf_alloc);
422 TRACE_add_end_function(TRACE_surf_release);
424 sg_config_init(argc, argv);
433 ModelPtr model = NULL;
435 TRACE_end(); /* Just in case it was not called by the upper
436 * layer (or there is no upper layer) */
438 sg_config_finalize();
440 xbt_dynar_free(&host_that_restart);
441 xbt_dynar_free(&surf_path);
443 xbt_lib_free(&host_lib);
444 xbt_lib_free(&link_lib);
445 xbt_lib_free(&as_router_lib);
446 xbt_lib_free(&storage_lib);
447 xbt_lib_free(&storage_type_lib);
448 xbt_lib_free(&file_lib);
449 xbt_dict_free(&watched_hosts_lib);
451 xbt_dynar_foreach(model_list, iter, model)
453 xbt_dynar_free(&model_list);
454 xbt_dynar_free(&model_list_invoke);
457 surf_callback_emit(surfExitCallbacks);
460 lmm_system_free(maxmin_system);
461 maxmin_system = NULL;
464 tmgr_history_free(history);
468 #ifdef CONTEXT_THREADS
469 xbt_parmap_destroy(surf_parmap);
476 surf_parse_lex_destroy();
477 surf_parse_free_callbacks();
479 NOW = 0; /* Just in case the user plans to restart the simulation afterward */
486 Model::Model(const char *name)
487 : p_maxminSystem(NULL)
490 p_readyActionSet = new ActionList();
491 p_runningActionSet = new ActionList();
492 p_failedActionSet = new ActionList();
493 p_doneActionSet = new ActionList();
495 p_modifiedSet = NULL;
497 p_updateMechanism = UM_UNDEFINED;
498 m_selectiveUpdate = 0;
502 delete p_readyActionSet;
503 delete p_runningActionSet;
504 delete p_failedActionSet;
505 delete p_doneActionSet;
508 double Model::shareResources(double now)
510 //FIXME: set the good function once and for all
511 if (p_updateMechanism == UM_LAZY)
512 return shareResourcesLazy(now);
513 else if (p_updateMechanism == UM_FULL)
514 return shareResourcesFull(now);
516 xbt_die("Invalid cpu update mechanism!");
519 double Model::shareResourcesLazy(double now)
521 ActionPtr action = NULL;
526 ("Before share resources, the size of modified actions set is %zd",
527 p_modifiedSet->size());
529 lmm_solve(p_maxminSystem);
532 ("After share resources, The size of modified actions set is %zd",
533 p_modifiedSet->size());
535 while(!p_modifiedSet->empty()) {
536 action = &(p_modifiedSet->front());
537 p_modifiedSet->pop_front();
538 int max_dur_flag = 0;
540 if (action->getStateSet() != p_runningActionSet)
543 /* bogus priority, skip it */
544 if (action->getPriority() <= 0 || action->getHat()==LATENCY)
547 action->updateRemainingLazy(now);
550 share = lmm_variable_getvalue(action->getVariable());
553 double time_to_completion;
554 if (action->getRemains() > 0) {
555 time_to_completion = action->getRemainsNoUpdate() / share;
557 time_to_completion = 0.0;
559 min = now + time_to_completion; // when the task will complete if nothing changes
562 if ((action->getMaxDuration() != NO_MAX_DURATION)
564 || action->getStartTime() +
565 action->getMaxDuration() < min)) {
566 min = action->getStartTime() +
567 action->getMaxDuration(); // when the task will complete anyway because of the deadline if any
572 XBT_DEBUG("Action(%p) corresponds to variable %d", action, action->getVariable()->id_int);
574 XBT_DEBUG("Action(%p) Start %f. May finish at %f (got a share of %f). Max_duration %f", action,
575 action->getStartTime(), min, share,
576 action->getMaxDuration());
579 action->heapUpdate(p_actionHeap, min, max_dur_flag ? MAX_DURATION : NORMAL);
580 XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min,
582 } else DIE_IMPOSSIBLE;
585 //hereafter must have already the min value for this resource model
586 if (xbt_heap_size(p_actionHeap) > 0)
587 min = xbt_heap_maxkey(p_actionHeap) - now;
591 XBT_DEBUG("The minimum with the HEAP %f", min);
596 double Model::shareResourcesFull(double /*now*/) {
600 double Model::shareResourcesMaxMin(ActionListPtr running_actions,
602 void (*solve) (lmm_system_t))
604 ActionPtr action = NULL;
610 ActionList::iterator it(running_actions->begin()), itend(running_actions->end());
611 for(; it != itend ; ++it) {
613 value = lmm_variable_getvalue(action->getVariable());
614 if ((value > 0) || (action->getMaxDuration() >= 0))
622 if (action->getRemains() > 0)
623 min = action->getRemainsNoUpdate() / value;
626 if ((action->getMaxDuration() >= 0) && (action->getMaxDuration() < min))
627 min = action->getMaxDuration();
629 min = action->getMaxDuration();
632 for (++it; it != itend; ++it) {
634 value = lmm_variable_getvalue(action->getVariable());
636 if (action->getRemains() > 0)
637 value = action->getRemainsNoUpdate() / value;
642 XBT_DEBUG("Updating min (value) with %p: %f", action, min);
645 if ((action->getMaxDuration() >= 0) && (action->getMaxDuration() < min)) {
646 min = action->getMaxDuration();
647 XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
650 XBT_DEBUG("min value : %f", min);
655 void Model::updateActionsState(double now, double delta)
657 if (p_updateMechanism == UM_FULL)
658 updateActionsStateFull(now, delta);
659 else if (p_updateMechanism == UM_LAZY)
660 updateActionsStateLazy(now, delta);
662 xbt_die("Invalid cpu update mechanism!");
665 void Model::updateActionsStateLazy(double /*now*/, double /*delta*/)
670 void Model::updateActionsStateFull(double /*now*/, double /*delta*/)
680 : p_name(NULL), p_properties(NULL), p_model(NULL)
683 Resource::Resource(ModelPtr model, const char *name, xbt_dict_t props)
684 : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
685 , m_running(true), m_stateCurrent(SURF_RESOURCE_ON)
688 Resource::Resource(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint)
689 : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
690 , m_running(true), m_stateCurrent(SURF_RESOURCE_ON), p_constraint(constraint)
693 Resource::Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit)
694 : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
695 , m_running(true), m_stateCurrent(stateInit)
698 Resource::~Resource() {
699 xbt_free((void*)p_name);
700 xbt_dict_free(&p_properties);
703 e_surf_resource_state_t Resource::getState()
705 return m_stateCurrent;
708 void Resource::setState(e_surf_resource_state_t state)
710 m_stateCurrent = state;
713 bool Resource::isOn()
718 void Resource::turnOn()
725 void Resource::turnOff()
732 ModelPtr Resource::getModel() {
736 const char *Resource::getName() {
740 xbt_dict_t Resource::getProperties() {
741 if (p_properties==NULL)
742 p_properties = xbt_dict_new();
746 lmm_constraint_t Resource::getConstraint() {
754 const char *surf_action_state_names[6] = {
756 "SURF_ACTION_RUNNING",
757 "SURF_ACTION_FAILED",
759 "SURF_ACTION_TO_FREE",
760 "SURF_ACTION_NOT_IN_THE_SYSTEM"
763 void Action::initialize(ModelPtr model, double cost, bool failed,
769 m_maxDuration = NO_MAX_DURATION;
772 m_start = surf_get_clock();
783 Action::Action(ModelPtr model, double cost, bool failed)
785 initialize(model, cost, failed);
787 p_stateHookup.prev = 0;
788 p_stateHookup.next = 0;
790 p_stateSet = getModel()->getFailedActionSet();
792 p_stateSet = getModel()->getRunningActionSet();
794 p_stateSet->push_back(*this);
797 Action::Action(ModelPtr model, double cost, bool failed, lmm_variable_t var)
799 initialize(model, cost, failed, var);
801 p_stateHookup.prev = 0;
802 p_stateHookup.next = 0;
804 p_stateSet = getModel()->getFailedActionSet();
806 p_stateSet = getModel()->getRunningActionSet();
808 p_stateSet->push_back(*this);
812 xbt_free(p_category);
815 void Action::finish() {
816 m_finish = surf_get_clock();
819 e_surf_action_state_t Action::getState()
821 if (p_stateSet == getModel()->getReadyActionSet())
822 return SURF_ACTION_READY;
823 if (p_stateSet == getModel()->getRunningActionSet())
824 return SURF_ACTION_RUNNING;
825 if (p_stateSet == getModel()->getFailedActionSet())
826 return SURF_ACTION_FAILED;
827 if (p_stateSet == getModel()->getDoneActionSet())
828 return SURF_ACTION_DONE;
829 return SURF_ACTION_NOT_IN_THE_SYSTEM;
832 void Action::setState(e_surf_action_state_t state)
834 //surf_action_state_t action_state = &(action->model_type->states);
835 XBT_IN("(%p,%s)", this, surf_action_state_names[state]);
836 p_stateSet->erase(p_stateSet->iterator_to(*this));
837 if (state == SURF_ACTION_READY)
838 p_stateSet = getModel()->getReadyActionSet();
839 else if (state == SURF_ACTION_RUNNING)
840 p_stateSet = getModel()->getRunningActionSet();
841 else if (state == SURF_ACTION_FAILED)
842 p_stateSet = getModel()->getFailedActionSet();
843 else if (state == SURF_ACTION_DONE)
844 p_stateSet = getModel()->getDoneActionSet();
849 p_stateSet->push_back(*this);
853 double Action::getBound()
855 return (p_variable) ? lmm_variable_getbound(p_variable) : 0;
858 void Action::setBound(double bound)
860 XBT_IN("(%p,%g)", this, bound);
862 lmm_update_variable_bound(getModel()->getMaxminSystem(), p_variable, bound);
864 if (getModel()->getUpdateMechanism() == UM_LAZY && getLastUpdate()!=surf_get_clock())
865 heapRemove(getModel()->getActionHeap());
869 double Action::getStartTime()
874 double Action::getFinishTime()
876 /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
877 return m_remains == 0 ? m_finish : -1;
880 void Action::setData(void* data)
885 void Action::setCategory(const char *category)
887 XBT_IN("(%p,%s)", this, category);
888 p_category = xbt_strdup(category);
896 void Action::setMaxDuration(double duration)
898 XBT_IN("(%p,%g)", this, duration);
899 m_maxDuration = duration;
900 if (getModel()->getUpdateMechanism() == UM_LAZY) // remove action from the heap
901 heapRemove(getModel()->getActionHeap());
905 void Action::gapRemove() {}
907 void Action::setPriority(double priority)
909 XBT_IN("(%p,%g)", this, priority);
910 m_priority = priority;
911 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), priority);
913 if (getModel()->getUpdateMechanism() == UM_LAZY)
914 heapRemove(getModel()->getActionHeap());
918 void Action::cancel(){
919 setState(SURF_ACTION_FAILED);
920 if (getModel()->getUpdateMechanism() == UM_LAZY) {
921 if (actionLmmHook::is_linked())
922 getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
923 heapRemove(getModel()->getActionHeap());
930 if (actionHook::is_linked())
931 p_stateSet->erase(p_stateSet->iterator_to(*this));
933 lmm_variable_free(getModel()->getMaxminSystem(), getVariable());
934 if (getModel()->getUpdateMechanism() == UM_LAZY) {
935 /* remove from heap */
936 heapRemove(getModel()->getActionHeap());
937 if (actionLmmHook::is_linked())
938 getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
946 void Action::suspend()
948 XBT_IN("(%p)", this);
949 if (m_suspended != 2) {
950 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
952 if (getModel()->getUpdateMechanism() == UM_LAZY)
953 heapRemove(getModel()->getActionHeap());
958 void Action::resume()
960 XBT_IN("(%p)", this);
961 if (m_suspended != 2) {
962 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), m_priority);
964 if (getModel()->getUpdateMechanism() == UM_LAZY)
965 heapRemove(getModel()->getActionHeap());
970 bool Action::isSuspended()
972 return m_suspended == 1;
974 /* insert action on heap using a given key and a hat (heap_action_type)
975 * a hat can be of three types for communications:
977 * NORMAL = this is a normal heap entry stating the date to finish transmitting
978 * LATENCY = this is a heap entry to warn us when the latency is payed
979 * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
981 void Action::heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat)
984 xbt_heap_push(heap, this, key);
987 void Action::heapRemove(xbt_heap_t heap)
990 if (m_indexHeap >= 0) {
991 xbt_heap_remove(heap, m_indexHeap);
995 void Action::heapUpdate(xbt_heap_t heap, double key, enum heap_action_type hat)
998 if (m_indexHeap >= 0) {
999 xbt_heap_update(heap, m_indexHeap, key);
1001 xbt_heap_push(heap, this, key);
1005 /* added to manage the communication action's heap */
1006 void surf_action_lmm_update_index_heap(void *action, int i) {
1007 ((ActionPtr)action)->updateIndexHeap(i);
1010 void Action::updateIndexHeap(int i) {
1014 double Action::getRemains()
1016 XBT_IN("(%p)", this);
1017 /* update remains before return it */
1018 if (getModel()->getUpdateMechanism() == UM_LAZY) /* update remains before return it */
1019 updateRemainingLazy(surf_get_clock());
1024 double Action::getRemainsNoUpdate()
1029 //FIXME split code in the right places
1030 void Action::updateRemainingLazy(double now)
1034 if(getModel() == surf_network_model)
1036 if (m_suspended != 0)
1041 xbt_assert(p_stateSet == getModel()->getRunningActionSet(),
1042 "You're updating an action that is not running.");
1044 /* bogus priority, skip it */
1045 xbt_assert(m_priority > 0,
1046 "You're updating an action that seems suspended.");
1049 delta = now - m_lastUpdate;
1051 if (m_remains > 0) {
1052 XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate);
1053 double_update(&m_remains, m_lastValue * delta, sg_surf_precision*sg_maxmin_precision);
1055 if (getModel() == surf_cpu_model_pm && TRACE_is_enabled()) {
1056 ResourcePtr cpu = static_cast<ResourcePtr>(lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)));
1057 TRACE_surf_host_set_utilization(cpu->getName(), getCategory(), m_lastValue, m_lastUpdate, now - m_lastUpdate);
1059 XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains);
1062 if(getModel() == surf_network_model)
1064 if (m_maxDuration != NO_MAX_DURATION)
1065 double_update(&m_maxDuration, delta, sg_surf_precision);
1067 //FIXME: duplicated code
1068 if ((m_remains <= 0) &&
1069 (lmm_get_variable_weight(getVariable()) > 0)) {
1071 setState(SURF_ACTION_DONE);
1072 heapRemove(getModel()->getActionHeap());
1073 } else if (((m_maxDuration != NO_MAX_DURATION)
1074 && (m_maxDuration <= 0))) {
1076 setState(SURF_ACTION_DONE);
1077 heapRemove(getModel()->getActionHeap());
1082 m_lastValue = lmm_variable_getvalue(getVariable());