1 /* Copyright (c) 2004-2015. 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 "src/internal_config.h"
8 #include "surf_private.h"
9 #include "surf_interface.hpp"
10 #include "network_interface.hpp"
11 #include "cpu_interface.hpp"
12 #include "src/surf/HostImpl.hpp"
13 #include "src/simix/smx_host_private.h"
14 #include "surf_routing.hpp"
15 #include "simgrid/sg_config.h"
17 #include "virtual_machine.hpp"
18 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
19 #include "simgrid/s4u/engine.hpp"
21 XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (kernel)");
28 /* model_list_invoke contains only surf_host and surf_vm.
29 * The callback functions of cpu_model and network_model will be called from those of these host models. */
30 xbt_dynar_t all_existing_models = nullptr; /* to destroy models correctly */
31 xbt_dynar_t model_list_invoke = nullptr; /* to invoke callbacks */
33 simgrid::trace_mgr::future_evt_set *future_evt_set = nullptr;
34 xbt_dynar_t surf_path = nullptr;
35 xbt_dynar_t host_that_restart = xbt_dynar_new(sizeof(char*), nullptr);
36 xbt_dict_t watched_hosts_lib;
41 simgrid::xbt::signal<void(void)> surfExitCallbacks;
46 #include <simgrid/plugins/energy.h> // FIXME: this plugin should not be linked to the core
48 s_surf_model_description_t surf_plugin_description[] = {
49 {"Energy", "Cpu energy consumption.", sg_energy_plugin_init},
50 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
53 /* Don't forget to update the option description in smx_config when you change this */
54 s_surf_model_description_t surf_network_model_description[] = {
55 {"LV08", "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). ",
56 surf_network_model_init_LegrandVelho},
58 "Simplistic network model where all communication take a constant time (one second). This model provides the lowest realism, but is (marginally) faster.",
59 surf_network_model_init_Constant},
60 {"SMPI", "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
61 surf_network_model_init_SMPI},
62 {"IB", "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
63 surf_network_model_init_IB},
64 {"CM02", "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of small messages are thus poorly modeled).",
65 surf_network_model_init_CM02},
67 {"NS3", "Network pseudo-model using the NS3 tcp model instead of an analytic model", surf_network_model_init_NS3},
69 {"Reno", "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
70 surf_network_model_init_Reno},
71 {"Reno2", "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
72 surf_network_model_init_Reno2},
73 {"Vegas", "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
74 surf_network_model_init_Vegas},
75 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
78 s_surf_model_description_t surf_cpu_model_description[] = {
79 {"Cas01", "Simplistic CPU model (time=size/power).", surf_cpu_model_init_Cas01},
80 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
83 s_surf_model_description_t surf_host_model_description[] = {
84 {"default", "Default host model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)", surf_host_model_init_current_default},
85 {"compound", "Host model that is automatically chosen if you change the network and CPU models", surf_host_model_init_compound},
86 {"ptask_L07", "Host model somehow similar to Cas01+CM02 but allowing parallel tasks", surf_host_model_init_ptask_L07},
87 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
90 s_surf_model_description_t surf_vm_model_description[] = {
91 {"default", "Default vm model.", surf_vm_model_init_HL13},
92 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
95 s_surf_model_description_t surf_optimization_mode_description[] = {
96 {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
97 {"TI", "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).", nullptr},
98 {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
99 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
102 s_surf_model_description_t surf_storage_model_description[] = {
103 {"default", "Simplistic storage model.", surf_storage_model_init_default},
104 {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
107 #if HAVE_THREAD_CONTEXTS
108 static xbt_parmap_t surf_parmap = nullptr; /* parallel map on models */
113 double surf_get_clock()
119 # define FILE_DELIM "\\"
121 # define FILE_DELIM "/" /* FIXME: move to better location */
124 FILE *surf_fopen(const char *name, const char *mode)
127 char *path_elm = nullptr;
129 FILE *file = nullptr;
133 if (__surf_is_absolute_file_path(name)) /* don't mess with absolute file names */
134 return fopen(name, mode);
136 /* search relative files in the path */
137 xbt_dynar_foreach(surf_path, cpt, path_elm) {
138 buff = bprintf("%s" FILE_DELIM "%s", path_elm, name);
139 file = fopen(buff, mode);
151 static const char *disk_drives_letter_table[MAX_DRIVE] = {
152 "A:\\","B:\\","C:\\","D:\\","E:\\","F:\\","G:\\","H:\\","I:\\","J:\\","K:\\","L:\\","M:\\",
153 "N:\\","O:\\","P:\\","Q:\\","R:\\","S:\\","T:\\","U:\\","V:\\","W:\\","X:\\","Y:\\","Z:\\"
158 * Returns the initial path. On Windows the initial path is
159 * the current directory for the current process in the other
160 * case the function returns "./" that represents the current
161 * directory on Unix/Linux platforms.
164 const char *__surf_get_initial_path()
169 char current_directory[MAX_PATH + 1] = { 0 };
170 unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory);
171 char root[4] = { 0 };
176 strncpy(root, current_directory, 3);
178 for (i = 0; i < MAX_DRIVE; i++) {
179 if (toupper(root[0]) == disk_drives_letter_table[i][0])
180 return disk_drives_letter_table[i];
189 /* The __surf_is_absolute_file_path() returns 1 if
190 * file_path is a absolute file path, in the other
191 * case the function returns 0.
193 int __surf_is_absolute_file_path(const char *file_path)
196 WIN32_FIND_DATA wfd = { 0 };
197 HANDLE hFile = FindFirstFile(file_path, &wfd);
199 if (INVALID_HANDLE_VALUE == hFile)
205 return (file_path[0] == '/');
209 /** Displays the long description of all registered models, and quit */
210 void model_help(const char *category, s_surf_model_description_t * table)
212 printf("Long description of the %s models accepted by this simulator:\n", category);
213 for (int i = 0; table[i].name; i++)
214 printf(" %s: %s\n", table[i].name, table[i].description);
217 int find_model_description(s_surf_model_description_t * table,
221 char *name_list = nullptr;
223 for (i = 0; table[i].name; i++)
224 if (!strcmp(name, table[i].name)) {
228 xbt_die("No model is valid! This is a bug.");
229 name_list = xbt_strdup(table[0].name);
230 for (i = 1; table[i].name; i++) {
231 name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
232 strncat(name_list, ", ", 2);
233 strncat(name_list, table[i].name, strlen(table[i].name));
235 xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
239 static inline void surf_storage_free(void *r)
241 delete static_cast<simgrid::surf::Storage*>(r);
244 void sg_version_check(int lib_version_major,int lib_version_minor,int lib_version_patch) {
245 if ((lib_version_major != SIMGRID_VERSION_MAJOR) || (lib_version_minor != SIMGRID_VERSION_MINOR)) {
247 "FATAL ERROR: Your program was compiled with SimGrid version %d.%d.%d, "
248 "and then linked against SimGrid %d.%d.%d. Please fix this.\n",
249 lib_version_major,lib_version_minor,lib_version_patch,
250 SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH);
253 if (lib_version_patch != SIMGRID_VERSION_PATCH) {
254 if(SIMGRID_VERSION_PATCH >= 90 || lib_version_patch >=90){
256 "FATAL ERROR: Your program was compiled with SimGrid version %d.%d.%d, "
257 "and then linked against SimGrid %d.%d.%d. \n"
258 "One of them is a development version, and should not be mixed with the stable release. Please fix this.\n",
259 lib_version_major,lib_version_minor,lib_version_patch,
260 SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH);
264 "Warning: Your program was compiled with SimGrid version %d.%d.%d, "
265 "and then linked against SimGrid %d.%d.%d. Proceeding anyway.\n",
266 lib_version_major,lib_version_minor,lib_version_patch,
267 SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH);
271 void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
272 *ver_major = SIMGRID_VERSION_MAJOR;
273 *ver_minor = SIMGRID_VERSION_MINOR;
274 *ver_patch = SIMGRID_VERSION_PATCH;
277 void surf_init(int *argc, char **argv)
279 if (host_list != nullptr) // Already initialized
282 XBT_DEBUG("Create all Libs");
283 host_list = xbt_dict_new_homogeneous([](void*p) {
284 simgrid::s4u::Host* host = static_cast<simgrid::s4u::Host*>(p);
285 simgrid::s4u::Host::onDestruction(*host);
288 USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
290 as_router_lib = xbt_lib_new();
291 storage_lib = xbt_lib_new();
292 storage_type_lib = xbt_lib_new();
293 file_lib = xbt_lib_new();
294 watched_hosts_lib = xbt_dict_new_homogeneous(nullptr);
296 XBT_DEBUG("Add routing levels");
297 ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib, nullptr);
298 ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib, [](void* p) {
299 delete static_cast<simgrid::kernel::routing::NetCard*>(p);
302 XBT_DEBUG("Add SURF levels");
303 simgrid::surf::HostImpl::classInit();
304 SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_free);
306 xbt_init(argc, argv);
307 if (!all_existing_models)
308 all_existing_models = xbt_dynar_new(sizeof(simgrid::surf::Model*), nullptr);
309 if (!model_list_invoke)
310 model_list_invoke = xbt_dynar_new(sizeof(simgrid::surf::Model*), nullptr);
312 future_evt_set = new simgrid::trace_mgr::future_evt_set();
314 TRACE_add_start_function(TRACE_surf_alloc);
315 TRACE_add_end_function(TRACE_surf_release);
317 sg_config_init(argc, argv);
326 simgrid::surf::Model *model = nullptr;
328 TRACE_end(); /* Just in case it was not called by the upper
329 * layer (or there is no upper layer) */
331 sg_config_finalize();
333 xbt_dynar_free(&host_that_restart);
334 xbt_dynar_free(&surf_path);
336 xbt_dict_free(&host_list);
337 xbt_lib_free(&as_router_lib);
338 xbt_lib_free(&storage_lib);
340 xbt_lib_free(&storage_type_lib);
341 xbt_lib_free(&file_lib);
342 xbt_dict_free(&watched_hosts_lib);
344 xbt_dynar_foreach(all_existing_models, iter, model)
346 xbt_dynar_free(&all_existing_models);
347 xbt_dynar_free(&model_list_invoke);
350 simgrid::surf::surfExitCallbacks();
352 if (future_evt_set) {
353 delete future_evt_set;
354 future_evt_set = nullptr;
357 #if HAVE_THREAD_CONTEXTS
358 xbt_parmap_destroy(surf_parmap);
363 simgrid::s4u::Engine::shutdown();
365 NOW = 0; /* Just in case the user plans to restart the simulation afterward */
376 : maxminSystem_(nullptr)
378 readyActionSet_ = new ActionList();
379 runningActionSet_ = new ActionList();
380 failedActionSet_ = new ActionList();
381 doneActionSet_ = new ActionList();
383 modifiedSet_ = nullptr;
384 actionHeap_ = nullptr;
385 updateMechanism_ = UM_UNDEFINED;
386 selectiveUpdate_ = 0;
390 delete readyActionSet_;
391 delete runningActionSet_;
392 delete failedActionSet_;
393 delete doneActionSet_;
396 double Model::next_occuring_event(double now)
398 //FIXME: set the good function once and for all
399 if (updateMechanism_ == UM_LAZY)
400 return next_occuring_event_lazy(now);
401 else if (updateMechanism_ == UM_FULL)
402 return next_occuring_event_full(now);
404 xbt_die("Invalid cpu update mechanism!");
407 double Model::next_occuring_event_lazy(double now)
409 Action *action = nullptr;
414 ("Before share resources, the size of modified actions set is %zd",
415 modifiedSet_->size());
417 lmm_solve(maxminSystem_);
420 ("After share resources, The size of modified actions set is %zd",
421 modifiedSet_->size());
423 while(!modifiedSet_->empty()) {
424 action = &(modifiedSet_->front());
425 modifiedSet_->pop_front();
426 int max_dur_flag = 0;
428 if (action->getStateSet() != runningActionSet_)
431 /* bogus priority, skip it */
432 if (action->getPriority() <= 0 || action->getHat()==LATENCY)
435 action->updateRemainingLazy(now);
438 share = lmm_variable_getvalue(action->getVariable());
441 double time_to_completion;
442 if (action->getRemains() > 0) {
443 time_to_completion = action->getRemainsNoUpdate() / share;
445 time_to_completion = 0.0;
447 min = now + time_to_completion; // when the task will complete if nothing changes
450 if ((action->getMaxDuration() != NO_MAX_DURATION)
452 || action->getStartTime() +
453 action->getMaxDuration() < min)) {
454 min = action->getStartTime() +
455 action->getMaxDuration(); // when the task will complete anyway because of the deadline if any
460 XBT_DEBUG("Action(%p) corresponds to variable %d", action, action->getVariable()->id_int);
462 XBT_DEBUG("Action(%p) Start %f. May finish at %f (got a share of %f). Max_duration %f", action,
463 action->getStartTime(), min, share,
464 action->getMaxDuration());
467 action->heapUpdate(actionHeap_, min, max_dur_flag ? MAX_DURATION : NORMAL);
468 XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min,
470 } else DIE_IMPOSSIBLE;
473 //hereafter must have already the min value for this resource model
474 if (xbt_heap_size(actionHeap_) > 0)
475 min = xbt_heap_maxkey(actionHeap_) - now;
479 XBT_DEBUG("The minimum with the HEAP %f", min);
484 double Model::next_occuring_event_full(double /*now*/) {
489 double Model::shareResourcesMaxMin(ActionList *running_actions,
491 void (*solve) (lmm_system_t))
493 Action *action = nullptr;
499 ActionList::iterator it(running_actions->begin()), itend(running_actions->end());
500 for(; it != itend ; ++it) {
502 value = lmm_variable_getvalue(action->getVariable());
503 if ((value > 0) || (action->getMaxDuration() >= 0))
511 if (action->getRemains() > 0)
512 min = action->getRemainsNoUpdate() / value;
515 if ((action->getMaxDuration() >= 0) && (action->getMaxDuration() < min))
516 min = action->getMaxDuration();
518 min = action->getMaxDuration();
521 for (++it; it != itend; ++it) {
523 value = lmm_variable_getvalue(action->getVariable());
525 if (action->getRemains() > 0)
526 value = action->getRemainsNoUpdate() / value;
531 XBT_DEBUG("Updating min (value) with %p: %f", action, min);
534 if ((action->getMaxDuration() >= 0) && (action->getMaxDuration() < min)) {
535 min = action->getMaxDuration();
536 XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
539 XBT_DEBUG("min value : %f", min);
544 void Model::updateActionsState(double now, double delta)
546 if (updateMechanism_ == UM_FULL)
547 updateActionsStateFull(now, delta);
548 else if (updateMechanism_ == UM_LAZY)
549 updateActionsStateLazy(now, delta);
551 xbt_die("Invalid cpu update mechanism!");
554 void Model::updateActionsStateLazy(double /*now*/, double /*delta*/)
559 void Model::updateActionsStateFull(double /*now*/, double /*delta*/)
574 Resource::Resource(Model *model, const char *name)
575 : name_(xbt_strdup(name))
579 Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint)
580 : name_(xbt_strdup(name))
582 , constraint_(constraint)
585 Resource::~Resource() {
586 xbt_free((void*)name_);
589 bool Resource::isOn() const {
592 bool Resource::isOff() const {
596 void Resource::turnOn()
601 void Resource::turnOff()
606 Model *Resource::getModel() const {
610 const char *Resource::getName() const {
614 bool Resource::operator==(const Resource &other) const {
615 return strcmp(name_, other.name_);
618 lmm_constraint_t Resource::getConstraint() const {
629 const char *surf_action_state_names[6] = {
631 "SURF_ACTION_RUNNING",
632 "SURF_ACTION_FAILED",
634 "SURF_ACTION_TO_FREE",
635 "SURF_ACTION_NOT_IN_THE_SYSTEM"
638 /* added to manage the communication action's heap */
639 void surf_action_lmm_update_index_heap(void *action, int i) {
640 static_cast<simgrid::surf::Action*>(action)->updateIndexHeap(i);
646 void Action::initialize(simgrid::surf::Model *model, double cost, bool failed,
650 start_ = surf_get_clock();
655 stateSet_ = getModel()->getFailedActionSet();
657 stateSet_ = getModel()->getRunningActionSet();
659 stateSet_->push_back(*this);
662 Action::Action(simgrid::surf::Model *model, double cost, bool failed)
664 initialize(model, cost, failed);
667 Action::Action(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
669 initialize(model, cost, failed, var);
676 void Action::finish() {
677 finishTime_ = surf_get_clock();
680 Action::State Action::getState()
682 if (stateSet_ == getModel()->getReadyActionSet())
683 return Action::State::ready;
684 if (stateSet_ == getModel()->getRunningActionSet())
685 return Action::State::running;
686 if (stateSet_ == getModel()->getFailedActionSet())
687 return Action::State::failed;
688 if (stateSet_ == getModel()->getDoneActionSet())
689 return Action::State::done;
690 return Action::State::not_in_the_system;
693 void Action::setState(Action::State state)
695 stateSet_->erase(stateSet_->iterator_to(*this));
697 case Action::State::ready:
698 stateSet_ = getModel()->getReadyActionSet();
700 case Action::State::running:
701 stateSet_ = getModel()->getRunningActionSet();
703 case Action::State::failed:
704 stateSet_ = getModel()->getFailedActionSet();
706 case Action::State::done:
707 stateSet_ = getModel()->getDoneActionSet();
714 stateSet_->push_back(*this);
717 double Action::getBound()
719 return (variable_) ? lmm_variable_getbound(variable_) : 0;
722 void Action::setBound(double bound)
724 XBT_IN("(%p,%g)", this, bound);
726 lmm_update_variable_bound(getModel()->getMaxminSystem(), variable_, bound);
728 if (getModel()->getUpdateMechanism() == UM_LAZY && getLastUpdate()!=surf_get_clock())
729 heapRemove(getModel()->getActionHeap());
733 double Action::getStartTime()
738 double Action::getFinishTime()
740 /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
741 return remains_ == 0 ? finishTime_ : -1;
744 void Action::setData(void* data)
749 void Action::setCategory(const char *category)
751 XBT_IN("(%p,%s)", this, category);
752 category_ = xbt_strdup(category);
760 void Action::setMaxDuration(double duration)
762 XBT_IN("(%p,%g)", this, duration);
763 maxDuration_ = duration;
764 if (getModel()->getUpdateMechanism() == UM_LAZY) // remove action from the heap
765 heapRemove(getModel()->getActionHeap());
769 void Action::gapRemove() {}
771 void Action::setPriority(double priority)
773 XBT_IN("(%p,%g)", this, priority);
774 priority_ = priority;
775 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), priority);
777 if (getModel()->getUpdateMechanism() == UM_LAZY)
778 heapRemove(getModel()->getActionHeap());
782 void Action::cancel(){
783 setState(Action::State::failed);
784 if (getModel()->getUpdateMechanism() == UM_LAZY) {
785 if (action_lmm_hook.is_linked())
786 getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
787 heapRemove(getModel()->getActionHeap());
794 if (action_hook.is_linked())
795 stateSet_->erase(stateSet_->iterator_to(*this));
797 lmm_variable_free(getModel()->getMaxminSystem(), getVariable());
798 if (getModel()->getUpdateMechanism() == UM_LAZY) {
799 /* remove from heap */
800 heapRemove(getModel()->getActionHeap());
801 if (action_lmm_hook.is_linked())
802 getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
810 void Action::suspend()
812 XBT_IN("(%p)", this);
813 if (suspended_ != 2) {
814 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
816 if (getModel()->getUpdateMechanism() == UM_LAZY)
817 heapRemove(getModel()->getActionHeap());
822 void Action::resume()
824 XBT_IN("(%p)", this);
825 if (suspended_ != 2) {
826 lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), priority_);
828 if (getModel()->getUpdateMechanism() == UM_LAZY)
829 heapRemove(getModel()->getActionHeap());
834 bool Action::isSuspended()
836 return suspended_ == 1;
838 /* insert action on heap using a given key and a hat (heap_action_type)
839 * a hat can be of three types for communications:
841 * NORMAL = this is a normal heap entry stating the date to finish transmitting
842 * LATENCY = this is a heap entry to warn us when the latency is payed
843 * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
845 void Action::heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat)
848 xbt_heap_push(heap, this, key);
851 void Action::heapRemove(xbt_heap_t heap)
854 if (indexHeap_ >= 0) {
855 xbt_heap_remove(heap, indexHeap_);
859 void Action::heapUpdate(xbt_heap_t heap, double key, enum heap_action_type hat)
862 if (indexHeap_ >= 0) {
863 xbt_heap_update(heap, indexHeap_, key);
865 xbt_heap_push(heap, this, key);
869 void Action::updateIndexHeap(int i) {
873 double Action::getRemains()
875 XBT_IN("(%p)", this);
876 /* update remains before return it */
877 if (getModel()->getUpdateMechanism() == UM_LAZY) /* update remains before return it */
878 updateRemainingLazy(surf_get_clock());
883 double Action::getRemainsNoUpdate()
888 //FIXME split code in the right places
889 void Action::updateRemainingLazy(double now)
893 if(getModel() == surf_network_model)
900 xbt_assert(stateSet_ == getModel()->getRunningActionSet(), "You're updating an action that is not running.");
901 xbt_assert(priority_ > 0, "You're updating an action that seems suspended.");
904 delta = now - lastUpdate_;
907 XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, remains_, lastUpdate_);
908 double_update(&remains_, lastValue_ * delta, sg_surf_precision*sg_maxmin_precision);
910 if (getModel() == surf_cpu_model_pm && TRACE_is_enabled()) {
911 simgrid::surf::Resource *cpu = static_cast<simgrid::surf::Resource*>(
912 lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)));
913 TRACE_surf_host_set_utilization(cpu->getName(), getCategory(), lastValue_, lastUpdate_, now - lastUpdate_);
915 XBT_DEBUG("Updating action(%p): remains is now %f", this, remains_);
918 if(getModel() == surf_network_model)
920 if (maxDuration_ != NO_MAX_DURATION)
921 double_update(&maxDuration_, delta, sg_surf_precision);
923 //FIXME: duplicated code
924 if ((remains_ <= 0) &&
925 (lmm_get_variable_weight(getVariable()) > 0)) {
927 setState(Action::State::done);
928 heapRemove(getModel()->getActionHeap());
929 } else if (((maxDuration_ != NO_MAX_DURATION)
930 && (maxDuration_ <= 0))) {
932 setState(Action::State::done);
933 heapRemove(getModel()->getActionHeap());
938 lastValue_ = lmm_variable_getvalue(getVariable());