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 "workstation_interface.hpp"
12 #include "vm_workstation_interface.hpp"
13 #include "simix/smx_host_private.h"
14 #include "surf_routing.hpp"
15 #include "simgrid/sg_config.h"
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 changed.
29 * Instead, each model change a global data, and then the caller of surf_solve must
30 * 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 when the resource comes back up.
33 * We worked by putting sentinel actions on every resources we are interested in,
34 * so that surf informs us if/when the corresponding resource fails.
36 * But this does not work to get Simix informed of when a resource comes back up, and this is where this pimple comes.
37 * We have a set of resources that are currently down and for which simix needs to know when it comes back up.
38 * And the current function is called *at every simulation step* to sweep over that set, searching for a resource
39 * that was turned back up in the meanwhile. This is UGLY and slow.
41 * The proper solution would be to not rely on globals for the action_failed and action_done swags.
42 * They must be passed as parameter by the caller (the handling of these actions in simix may let you
43 * think that these two sets can be merged, but their handling in SimDag induce the contrary unless this
44 * simdag code can check by itself whether the action is done of failed -- seems very doable, but yet more
47 * Once surf_solve() is passed the set of actions that changed, you want to add a new set of resources back up
48 * as parameter to this function. You also want to add a boolean field "restart_watched" to each resource, and
49 * make sure that whenever a resource with this field enabled comes back up, it's added to that set so that Simix
50 * sees it and react accordingly. This would kill that need for surf to call simix.
54 /*static void remove_watched_host(void *key)
56 xbt_dict_remove(watched_hosts_lib, *(char**)key);
59 /*void surf_watched_hosts(void)
63 xbt_dict_cursor_t cursor;
64 xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL);
66 XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib");
67 xbt_dict_foreach(watched_hosts_lib, cursor, key, host)
69 if(SIMIX_host_get_state((smx_host_t)host) == SURF_RESOURCE_ON){
70 XBT_INFO("Restart processes on host: %s", SIMIX_host_get_name((smx_host_t)host));
71 SIMIX_host_autorestart((smx_host_t)host);
72 xbt_dynar_push_as(hosts, char*, key);
75 XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key);
77 xbt_dynar_map(hosts, remove_watched_host);
78 xbt_dynar_free(&hosts);
81 /* model_list_invoke contains only surf_workstation and surf_vm_workstation.
82 * The callback functions of cpu_model and network_model will be called from
83 * those of these workstation models. */
84 xbt_dynar_t model_list = NULL; /* for destroying all models correctly */
85 xbt_dynar_t model_list_invoke = NULL; /* for invoking callbacks */
87 tmgr_history_t history = NULL;
88 lmm_system_t maxmin_system = NULL;
89 xbt_dynar_t surf_path = NULL;
90 xbt_dynar_t host_that_restart = NULL;
91 xbt_dict_t watched_hosts_lib;
93 surf_callback(void, void) surfExitCallbacks;
95 s_surf_model_description_t surf_plugin_description[] = {
97 "Cpu energy consumption.",
98 sg_energy_plugin_init},
99 {NULL, NULL, NULL} /* this array must be NULL terminated */
102 /* Don't forget to update the option description in smx_config when you change this */
103 s_surf_model_description_t surf_network_model_description[] = {
105 "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). ",
106 surf_network_model_init_LegrandVelho},
108 "Simplistic network model where all communication take a constant time (one second). This model provides the lowest realism, but is (marginally) faster.",
109 surf_network_model_init_Constant},
111 "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
112 surf_network_model_init_SMPI},
114 "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of small messages are thus poorly modeled).",
115 surf_network_model_init_CM02},
118 "Network pseudo-model using the GTNets simulator instead of an analytic model",
119 surf_network_model_init_GTNETS},
123 "Network pseudo-model using the NS3 tcp model instead of an analytic model",
124 surf_network_model_init_NS3},
127 "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
128 surf_network_model_init_Reno},
130 "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
131 surf_network_model_init_Reno2},
133 "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
134 surf_network_model_init_Vegas},
135 {NULL, NULL, NULL} /* this array must be NULL terminated */
138 s_surf_model_description_t surf_cpu_model_description[] = {
140 "Simplistic CPU model (time=size/power).",
141 surf_cpu_model_init_Cas01},
142 {NULL, NULL, NULL} /* this array must be NULL terminated */
145 s_surf_model_description_t surf_workstation_model_description[] = {
147 "Default workstation model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)",
148 surf_workstation_model_init_current_default},
150 "Workstation model that is automatically chosen if you change the network and CPU models",
151 surf_workstation_model_init_compound},
152 {"ptask_L07", "Workstation model somehow similar to Cas01+CM02 but allowing parallel tasks",
153 surf_workstation_model_init_ptask_L07},
154 {NULL, NULL, NULL} /* this array must be NULL terminated */
157 s_surf_model_description_t surf_vm_workstation_model_description[] = {
159 "Default vm workstation model.",
160 surf_vm_workstation_model_init_current_default},
161 {NULL, NULL, NULL} /* this array must be NULL terminated */
164 s_surf_model_description_t surf_optimization_mode_description[] = {
166 "Lazy action management (partial invalidation in lmm + heap in action remaining).",
169 "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).",
172 "Full update of remaining and variables. Slow but may be useful when debugging.",
174 {NULL, NULL, NULL} /* this array must be NULL terminated */
177 s_surf_model_description_t surf_storage_model_description[] = {
179 "Simplistic storage model.",
180 surf_storage_model_init_default},
181 {NULL, NULL, NULL} /* this array must be NULL terminated */
184 #ifdef CONTEXT_THREADS
185 static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
189 double *surf_mins = NULL; /* return value of share_resources for each model */
190 int surf_min_index; /* current index in surf_mins */
191 double surf_min; /* duration determined by surf_solve */
193 double surf_get_clock(void)
199 # define FILE_DELIM "\\"
201 # define FILE_DELIM "/" /* FIXME: move to better location */
204 FILE *surf_fopen(const char *name, const char *mode)
207 char *path_elm = NULL;
213 if (__surf_is_absolute_file_path(name)) /* don't mess with absolute file names */
214 return fopen(name, mode);
216 /* search relative files in the path */
217 xbt_dynar_foreach(surf_path, cpt, path_elm) {
218 buff = bprintf("%s" FILE_DELIM "%s", path_elm, name);
219 file = fopen(buff, mode);
235 static const char *disk_drives_letter_table[MAX_DRIVE] = {
266 * Returns the initial path. On Windows the initial path is
267 * the current directory for the current process in the other
268 * case the function returns "./" that represents the current
269 * directory on Unix/Linux platforms.
272 const char *__surf_get_initial_path(void)
277 char current_directory[MAX_PATH + 1] = { 0 };
278 unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory);
279 char root[4] = { 0 };
284 strncpy(root, current_directory, 3);
286 for (i = 0; i < MAX_DRIVE; i++) {
287 if (toupper(root[0]) == disk_drives_letter_table[i][0])
288 return disk_drives_letter_table[i];
297 /* The __surf_is_absolute_file_path() returns 1 if
298 * file_path is a absolute file path, in the other
299 * case the function returns 0.
301 int __surf_is_absolute_file_path(const char *file_path)
304 WIN32_FIND_DATA wfd = { 0 };
305 HANDLE hFile = FindFirstFile(file_path, &wfd);
307 if (INVALID_HANDLE_VALUE == hFile)
313 return (file_path[0] == '/');
317 /** Displays the long description of all registered models, and quit */
318 void model_help(const char *category, s_surf_model_description_t * table)
321 printf("Long description of the %s models accepted by this simulator:\n",
323 for (i = 0; table[i].name; i++)
324 printf(" %s: %s\n", table[i].name, table[i].description);
327 int find_model_description(s_surf_model_description_t * table,
331 char *name_list = NULL;
333 for (i = 0; table[i].name; i++)
334 if (!strcmp(name, table[i].name)) {
337 name_list = strdup(table[0].name);
338 for (i = 1; table[i].name; i++) {
339 name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
340 strcat(name_list, ", ");
341 strcat(name_list, table[i].name);
343 xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
347 static XBT_INLINE void routing_asr_host_free(void *p)
349 delete ((RoutingEdgePtr) p);
352 static XBT_INLINE void routing_asr_prop_free(void *p)
354 xbt_dict_t elm = (xbt_dict_t) p;
358 static XBT_INLINE void surf_cpu_free(void *r)
360 delete static_cast<CpuPtr>(r);
363 static XBT_INLINE void surf_link_free(void *r)
365 delete static_cast<NetworkLinkPtr>(r);
368 static XBT_INLINE void surf_workstation_free(void *r)
370 delete static_cast<WorkstationPtr>(r);
374 void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
375 *ver_major = SIMGRID_VERSION_MAJOR;
376 *ver_minor = SIMGRID_VERSION_MINOR;
377 *ver_patch = SIMGRID_VERSION_PATCH;
380 void surf_init(int *argc, char **argv)
382 XBT_DEBUG("Create all Libs");
383 host_lib = xbt_lib_new();
384 link_lib = xbt_lib_new();
385 as_router_lib = xbt_lib_new();
386 storage_lib = xbt_lib_new();
387 storage_type_lib = xbt_lib_new();
388 watched_hosts_lib = xbt_dict_new_homogeneous(NULL);
390 XBT_DEBUG("Add routing levels");
391 ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
392 ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free);
393 ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
395 XBT_DEBUG("Add SURF levels");
396 SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free);
397 SURF_WKS_LEVEL = xbt_lib_add_level(host_lib,surf_workstation_free);
398 SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_link_free);
400 xbt_init(argc, argv);
402 model_list = xbt_dynar_new(sizeof(ModelPtr), NULL);
403 if (!model_list_invoke)
404 model_list_invoke = xbt_dynar_new(sizeof(ModelPtr), NULL);
406 history = tmgr_history_new();
409 TRACE_add_start_function(TRACE_surf_alloc);
410 TRACE_add_end_function(TRACE_surf_release);
413 sg_config_init(argc, argv);
422 ModelPtr model = NULL;
425 TRACE_end(); /* Just in case it was not called by the upper
426 * layer (or there is no upper layer) */
429 sg_config_finalize();
431 xbt_dynar_free(&host_that_restart);
432 xbt_dynar_free(&surf_path);
434 xbt_lib_free(&host_lib);
435 xbt_lib_free(&link_lib);
436 xbt_lib_free(&as_router_lib);
437 xbt_lib_free(&storage_lib);
438 xbt_lib_free(&storage_type_lib);
440 xbt_dict_free(&watched_hosts_lib);
442 xbt_dynar_foreach(model_list, iter, model)
444 xbt_dynar_free(&model_list);
445 xbt_dynar_free(&model_list_invoke);
448 surf_callback_emit(surfExitCallbacks);
451 lmm_system_free(maxmin_system);
452 maxmin_system = NULL;
455 tmgr_history_free(history);
459 #ifdef CONTEXT_THREADS
460 xbt_parmap_destroy(surf_parmap);
467 surf_parse_lex_destroy();
468 surf_parse_free_callbacks();
470 NOW = 0; /* Just in case the user plans to restart the simulation afterward */
477 Model::Model(const char *name)
478 : p_maxminSystem(NULL)
481 p_readyActionSet = new ActionList();
482 p_runningActionSet = new ActionList();
483 p_failedActionSet = new ActionList();
484 p_doneActionSet = new ActionList();
486 p_modifiedSet = NULL;
488 p_updateMechanism = UM_UNDEFINED;
489 m_selectiveUpdate = 0;
493 delete p_readyActionSet;
494 delete p_runningActionSet;
495 delete p_failedActionSet;
496 delete p_doneActionSet;
499 double Model::shareResources(double now)
501 //FIXME: set the good function once and for all
502 if (p_updateMechanism == UM_LAZY)
503 return shareResourcesLazy(now);
504 else if (p_updateMechanism == UM_FULL)
505 return shareResourcesFull(now);
507 xbt_die("Invalid cpu update mechanism!");
510 double Model::shareResourcesLazy(double now)
512 ActionPtr action = NULL;
517 ("Before share resources, the size of modified actions set is %zd",
518 p_modifiedSet->size());
520 lmm_solve(p_maxminSystem);
523 ("After share resources, The size of modified actions set is %zd",
524 p_modifiedSet->size());
526 while(!p_modifiedSet->empty()) {
527 action = &(p_modifiedSet->front());
528 p_modifiedSet->pop_front();
529 int max_dur_flag = 0;
531 if (action->getStateSet() != p_runningActionSet)
534 /* bogus priority, skip it */
535 if (action->getPriority() <= 0)
538 action->updateRemainingLazy(now);
541 value = lmm_variable_getvalue(action->getVariable());
543 if (action->getRemains() > 0) {
544 value = action->getRemainsNoUpdate() / value;
552 if ((action->getMaxDuration() != NO_MAX_DURATION)
554 || action->getStartTime() +
555 action->getMaxDuration() < min)) {
556 min = action->getStartTime() +
557 action->getMaxDuration();
561 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
562 action->getStartTime(), now + value,
563 action->getMaxDuration());
566 action->heapRemove(p_actionHeap);
567 action->heapInsert(p_actionHeap, min, max_dur_flag ? MAX_DURATION : NORMAL);
568 XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
570 } else DIE_IMPOSSIBLE;
573 //hereafter must have already the min value for this resource model
574 if (xbt_heap_size(p_actionHeap) > 0)
575 min = xbt_heap_maxkey(p_actionHeap) - now;
579 XBT_DEBUG("The minimum with the HEAP %lf", min);
584 double Model::shareResourcesFull(double /*now*/) {
588 double Model::shareResourcesMaxMin(ActionListPtr running_actions,
590 void (*solve) (lmm_system_t))
592 ActionPtr action = NULL;
598 ActionList::iterator it(running_actions->begin()), itend(running_actions->end());
599 for(; it != itend ; ++it) {
601 value = lmm_variable_getvalue(action->getVariable());
602 if ((value > 0) || (action->getMaxDuration() >= 0))
610 if (action->getRemains() > 0)
611 min = action->getRemainsNoUpdate() / value;
614 if ((action->getMaxDuration() >= 0) && (action->getMaxDuration() < min))
615 min = action->getMaxDuration();
617 min = action->getMaxDuration();
620 for (++it; it != itend; ++it) {
622 value = lmm_variable_getvalue(action->getVariable());
624 if (action->getRemains() > 0)
625 value = action->getRemainsNoUpdate() / value;
630 XBT_DEBUG("Updating min (value) with %p: %f", action, min);
633 if ((action->getMaxDuration() >= 0) && (action->getMaxDuration() < min)) {
634 min = action->getMaxDuration();
635 XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
638 XBT_DEBUG("min value : %f", min);
643 void Model::updateActionsState(double now, double delta)
645 if (p_updateMechanism == UM_FULL)
646 updateActionsStateFull(now, delta);
647 else if (p_updateMechanism == UM_LAZY)
648 updateActionsStateLazy(now, delta);
650 xbt_die("Invalid cpu update mechanism!");
653 void Model::updateActionsStateLazy(double /*now*/, double /*delta*/)
657 void Model::updateActionsStateFull(double /*now*/, double /*delta*/)
666 : p_name(NULL), p_properties(NULL), p_model(NULL)
669 Resource::Resource(surf_model_t model, const char *name, xbt_dict_t props)
670 : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
671 , m_running(true), m_stateCurrent(SURF_RESOURCE_ON)
674 Resource::Resource(surf_model_t model, const char *name, xbt_dict_t props, lmm_constraint_t constraint)
675 : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
676 , m_running(true), m_stateCurrent(SURF_RESOURCE_ON), p_constraint(constraint)
679 Resource::Resource(surf_model_t model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit)
680 : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
681 , m_running(true), m_stateCurrent(stateInit)
684 Resource::~Resource() {
685 xbt_free((void*)p_name);
686 xbt_dict_free(&p_properties);
689 e_surf_resource_state_t Resource::getState()
691 return m_stateCurrent;
694 void Resource::setState(e_surf_resource_state_t state)
696 m_stateCurrent = state;
699 bool Resource::isOn()
704 void Resource::turnOn()
711 void Resource::turnOff()
718 ModelPtr Resource::getModel() {
722 const char *Resource::getName() {
726 xbt_dict_t Resource::getProperties() {
730 lmm_constraint_t Resource::getConstraint() {
738 const char *surf_action_state_names[6] = {
740 "SURF_ACTION_RUNNING",
741 "SURF_ACTION_FAILED",
743 "SURF_ACTION_TO_FREE",
744 "SURF_ACTION_NOT_IN_THE_SYSTEM"
751 Action::Action(ModelPtr model, double cost, bool failed)
755 , m_maxDuration(NO_MAX_DURATION)
758 , m_start(surf_get_clock())
770 p_stateHookup.prev = 0;
771 p_stateHookup.next = 0;
773 p_stateSet = getModel()->getFailedActionSet();
775 p_stateSet = getModel()->getRunningActionSet();
777 p_stateSet->push_back(*this);
780 Action::Action(ModelPtr model, double cost, bool failed, lmm_variable_t var)
784 , m_maxDuration(NO_MAX_DURATION)
787 , m_start(surf_get_clock())
799 p_stateHookup.prev = 0;
800 p_stateHookup.next = 0;
802 p_stateSet = getModel()->getFailedActionSet();
804 p_stateSet = getModel()->getRunningActionSet();
806 p_stateSet->push_back(*this);
811 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::getStartTime()
858 double Action::getFinishTime()
860 /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
861 return m_remains == 0 ? m_finish : -1;
864 void Action::setData(void* data)
870 void Action::setCategory(const char *category)
872 XBT_IN("(%p,%s)", this, category);
873 p_category = xbt_strdup(category);
882 void Action::setMaxDuration(double duration)
884 XBT_IN("(%p,%g)", this, duration);
885 m_maxDuration = duration;
886 if (getModel()->getUpdateMechanism() == UM_LAZY) // remove action from the heap
887 heapRemove(getModel()->getActionHeap());
891 void Action::gapRemove() {}
893 void Action::setPriority(double priority)
895 XBT_IN("(%p,%g)", this, priority);
896 m_priority = priority;
897 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), priority);
899 if (getModel()->getUpdateMechanism() == UM_LAZY)
900 heapRemove(getModel()->getActionHeap());
904 void Action::cancel(){
905 setState(SURF_ACTION_FAILED);
906 if (getModel()->getUpdateMechanism() == UM_LAZY) {
907 if (actionLmmHook::is_linked())
908 getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
909 heapRemove(getModel()->getActionHeap());
916 if (actionHook::is_linked())
917 p_stateSet->erase(p_stateSet->iterator_to(*this));
919 lmm_variable_free(getModel()->getMaxminSystem(), getVariable());
920 if (getModel()->getUpdateMechanism() == UM_LAZY) {
921 /* remove from heap */
922 heapRemove(getModel()->getActionHeap());
923 if (actionLmmHook::is_linked())
924 getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
932 void Action::suspend()
934 XBT_IN("(%p)", this);
935 if (m_suspended != 2) {
936 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
938 if (getModel()->getUpdateMechanism() == UM_LAZY)
939 heapRemove(getModel()->getActionHeap());
944 void Action::resume()
946 XBT_IN("(%p)", this);
947 if (m_suspended != 2) {
948 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), m_priority);
950 if (getModel()->getUpdateMechanism() == UM_LAZY)
951 heapRemove(getModel()->getActionHeap());
956 bool Action::isSuspended()
958 return m_suspended == 1;
960 /* insert action on heap using a given key and a hat (heap_action_type)
961 * a hat can be of three types for communications:
963 * NORMAL = this is a normal heap entry stating the date to finish transmitting
964 * LATENCY = this is a heap entry to warn us when the latency is payed
965 * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
967 void Action::heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat)
970 xbt_heap_push(heap, this, key);
973 void Action::heapRemove(xbt_heap_t heap)
976 if (m_indexHeap >= 0) {
977 xbt_heap_remove(heap, m_indexHeap);
981 /* added to manage the communication action's heap */
982 void surf_action_lmm_update_index_heap(void *action, int i) {
983 ((ActionPtr)action)->updateIndexHeap(i);
986 void Action::updateIndexHeap(int i) {
990 double Action::getRemains()
992 XBT_IN("(%p)", this);
993 /* update remains before return it */
994 if (getModel()->getUpdateMechanism() == UM_LAZY) /* update remains before return it */
995 updateRemainingLazy(surf_get_clock());
1000 double Action::getRemainsNoUpdate()
1005 //FIXME split code in the right places
1006 void Action::updateRemainingLazy(double now)
1010 if(getModel() == static_cast<ModelPtr>(surf_network_model))
1012 if (m_suspended != 0)
1017 xbt_assert(p_stateSet == getModel()->getRunningActionSet(),
1018 "You're updating an action that is not running.");
1020 /* bogus priority, skip it */
1021 xbt_assert(m_priority > 0,
1022 "You're updating an action that seems suspended.");
1025 delta = now - m_lastUpdate;
1027 if (m_remains > 0) {
1028 XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate);
1029 double_update(&m_remains, m_lastValue * delta);
1032 if (getModel() == static_cast<ModelPtr>(surf_cpu_model_pm) && TRACE_is_enabled()) {
1033 ResourcePtr cpu = static_cast<ResourcePtr>(lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)));
1034 TRACE_surf_host_set_utilization(cpu->getName(), getCategory(), m_lastValue, m_lastUpdate, now - m_lastUpdate);
1037 XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains);
1040 if(getModel() == static_cast<ModelPtr>(surf_network_model))
1042 if (m_maxDuration != NO_MAX_DURATION)
1043 double_update(&m_maxDuration, delta);
1045 //FIXME: duplicated code
1046 if ((m_remains <= 0) &&
1047 (lmm_get_variable_weight(getVariable()) > 0)) {
1049 setState(SURF_ACTION_DONE);
1050 heapRemove(getModel()->getActionHeap());
1051 } else if (((m_maxDuration != NO_MAX_DURATION)
1052 && (m_maxDuration <= 0))) {
1054 setState(SURF_ACTION_DONE);
1055 heapRemove(getModel()->getActionHeap());
1060 m_lastValue = lmm_variable_getvalue(getVariable());