Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #65 from fabienchaix/master
[simgrid.git] / src / surf / network_cm02.cpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <algorithm>
8
9 #include "network_cm02.hpp"
10 #include "maxmin_private.hpp"
11 #include "simgrid/sg_config.h"
12 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
13
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
15
16 double sg_sender_gap = 0.0;
17 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
18 double sg_bandwidth_factor = 1.0;       /* default value; can be set by model or from command line */
19 double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or from command line */
20
21 double sg_tcp_gamma = 0.0;
22 int sg_network_crosstraffic = 0;
23
24 /************************************************************************/
25 /* New model based on optimizations discussed during Pedro Velho's thesis*/
26 /************************************************************************/
27 /* @techreport{VELHO:2011:HAL-00646896:1, */
28 /*      url = {http://hal.inria.fr/hal-00646896/en/}, */
29 /*      title = {{Flow-level network models: have we reached the limits?}}, */
30 /*      author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
31 /*      type = {Rapport de recherche}, */
32 /*      institution = {INRIA}, */
33 /*      number = {RR-7821}, */
34 /*      year = {2011}, */
35 /*      month = Nov, */
36 /*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
37 /*  } */
38 void surf_network_model_init_LegrandVelho(void)
39 {
40   if (surf_network_model)
41     return;
42
43   simgrid::surf::on_link.connect(netlink_parse_init);
44   surf_network_model = new simgrid::surf::NetworkCm02Model();
45   xbt_dynar_push(all_existing_models, &surf_network_model);
46
47   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",      13.01);
48   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",     0.97);
49   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",         20537);
50 }
51
52 /***************************************************************************/
53 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
54 /***************************************************************************/
55 /* @TechReport{      rr-lip2002-40, */
56 /*   author        = {Henri Casanova and Loris Marchal}, */
57 /*   institution   = {LIP}, */
58 /*   title         = {A Network Model for Simulation of Grid Application}, */
59 /*   number        = {2002-40}, */
60 /*   month         = {oct}, */
61 /*   year          = {2002} */
62 /* } */
63 void surf_network_model_init_CM02(void)
64 {
65
66   if (surf_network_model)
67     return;
68
69   simgrid::surf::on_link.connect(netlink_parse_init);
70   surf_network_model = new simgrid::surf::NetworkCm02Model();
71   xbt_dynar_push(all_existing_models, &surf_network_model);
72
73   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",   1.0);
74   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 1.0);
75   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",         0.0);
76 }
77
78 /***************************************************************************/
79 /* The models from Steven H. Low                                           */
80 /***************************************************************************/
81 /* @article{Low03,                                                         */
82 /*   author={Steven H. Low},                                               */
83 /*   title={A Duality Model of {TCP} and Queue Management Algorithms},     */
84 /*   year={2003},                                                          */
85 /*   journal={{IEEE/ACM} Transactions on Networking},                      */
86 /*    volume={11}, number={4},                                             */
87 /*  }                                                                      */
88 void surf_network_model_init_Reno(void)
89 {
90   if (surf_network_model)
91     return;
92
93   simgrid::surf::on_link.connect(netlink_parse_init);
94   surf_network_model = new simgrid::surf::NetworkCm02Model();
95   xbt_dynar_push(all_existing_models, &surf_network_model);
96
97   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
98   surf_network_model->f_networkSolve = lagrange_solve;
99
100   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",     10.4);
101   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",    0.92);
102   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",         8775);
103 }
104
105
106 void surf_network_model_init_Reno2(void)
107 {
108   if (surf_network_model)
109     return;
110
111   simgrid::surf::on_link.connect(netlink_parse_init);
112   surf_network_model = new simgrid::surf::NetworkCm02Model();
113   xbt_dynar_push(all_existing_models, &surf_network_model);
114
115   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, func_reno2_fpi);
116   surf_network_model->f_networkSolve = lagrange_solve;
117
118   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",    10.4);
119   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",   0.92);
120   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",        8775);
121 }
122
123 void surf_network_model_init_Vegas(void)
124 {
125   if (surf_network_model)
126     return;
127
128   simgrid::surf::on_link.connect(netlink_parse_init);
129   surf_network_model = new simgrid::surf::NetworkCm02Model();
130   xbt_dynar_push(all_existing_models, &surf_network_model);
131
132   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
133   surf_network_model->f_networkSolve = lagrange_solve;
134
135   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",    10.4);
136   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",   0.92);
137   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",        8775);
138 }
139
140 namespace simgrid {
141 namespace surf {
142
143 NetworkCm02Model::NetworkCm02Model()
144   :NetworkModel()
145 {
146   char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
147   int select = xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
148
149   if (!strcmp(optim, "Full")) {
150     p_updateMechanism = UM_FULL;
151     m_selectiveUpdate = select;
152   } else if (!strcmp(optim, "Lazy")) {
153     p_updateMechanism = UM_LAZY;
154     m_selectiveUpdate = 1;
155     xbt_assert((select == 1) || (xbt_cfg_is_default_value(_sg_cfg_set, "network/maxmin_selective_update")),
156                "Disabling selective update while using the lazy update mechanism is dumb!");
157   } else {
158     xbt_die("Unsupported optimization (%s) for this model", optim);
159   }
160
161   if (!p_maxminSystem)
162     p_maxminSystem = lmm_system_new(m_selectiveUpdate);
163
164   routing_model_create(createLink("__loopback__",
165                                 498000000, NULL, 0.000015, NULL,
166                                 NULL,
167                                 SURF_LINK_FATPIPE, NULL));
168
169   if (p_updateMechanism == UM_LAZY) {
170   p_actionHeap = xbt_heap_new(8, NULL);
171   xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
172   p_modifiedSet = new ActionLmmList();
173   p_maxminSystem->keep_track = p_modifiedSet;
174   }
175 }
176
177 Link* NetworkCm02Model::createLink(const char *name,
178     double bw_initial, tmgr_trace_t bw_trace,
179     double lat_initial, tmgr_trace_t lat_trace,
180     tmgr_trace_t state_trace,
181     e_surf_link_sharing_policy_t policy, xbt_dict_t properties)
182 {
183   xbt_assert(NULL == Link::byName(name),
184              "Link '%s' declared several times in the platform",
185              name);
186
187   Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial,
188                      state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
189   Link::onCreation(link);
190   return link;
191 }
192
193 void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
194 {
195   NetworkCm02Action *action;
196   while ((xbt_heap_size(p_actionHeap) > 0)
197          && (double_equals(xbt_heap_maxkey(p_actionHeap), now, sg_surf_precision))) {
198     action = static_cast<NetworkCm02Action*> (xbt_heap_pop(p_actionHeap));
199     XBT_DEBUG("Something happened to action %p", action);
200     if (TRACE_is_enabled()) {
201       int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
202
203       for (int i = 0; i < n; i++){
204         lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i);
205         NetworkCm02Link *link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
206         TRACE_surf_link_set_utilization(link->getName(),
207                                         action->getCategory(),
208                                         (lmm_variable_getvalue(action->getVariable())*
209                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
210                                                 action->getVariable(),
211                                                 i)),
212                                         action->getLastUpdate(),
213                                         now - action->getLastUpdate());
214       }
215     }
216
217     // if I am wearing a latency hat
218     if (action->getHat() == LATENCY) {
219       XBT_DEBUG("Latency paid for action %p. Activating", action);
220       lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight);
221       action->heapRemove(p_actionHeap);
222       action->refreshLastUpdate();
223
224         // if I am wearing a max_duration or normal hat
225     } else if (action->getHat() == MAX_DURATION ||
226         action->getHat() == NORMAL) {
227         // no need to communicate anymore
228         // assume that flows that reached max_duration have remaining of 0
229       XBT_DEBUG("Action %p finished", action);
230       action->setRemains(0);
231       action->finish();
232       action->setState(SURF_ACTION_DONE);
233       action->heapRemove(p_actionHeap);
234
235       action->gapRemove();
236     }
237   }
238   return;
239 }
240
241
242 void NetworkCm02Model::updateActionsStateFull(double now, double delta)
243 {
244   NetworkCm02Action *action;
245   ActionList *running_actions = getRunningActionSet();
246
247   for(ActionList::iterator it(running_actions->begin()), itNext=it, itend(running_actions->end())
248      ; it != itend ; it=itNext) {
249   ++itNext;
250
251     action = static_cast<NetworkCm02Action*> (&*it);
252     XBT_DEBUG("Something happened to action %p", action);
253       double deltap = delta;
254       if (action->m_latency > 0) {
255         if (action->m_latency > deltap) {
256           double_update(&(action->m_latency), deltap, sg_surf_precision);
257           deltap = 0.0;
258         } else {
259           double_update(&(deltap), action->m_latency, sg_surf_precision);
260           action->m_latency = 0.0;
261         }
262         if (action->m_latency == 0.0 && !(action->isSuspended()))
263           lmm_update_variable_weight(p_maxminSystem, action->getVariable(),
264               action->m_weight);
265       }
266       if (TRACE_is_enabled()) {
267         int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
268         for (int i = 0; i < n; i++){
269           lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i);
270
271           NetworkCm02Link* link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
272           TRACE_surf_link_set_utilization(link->getName(),
273                                         action->getCategory(),
274                                         (lmm_variable_getvalue(action->getVariable())*
275                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
276                                                 action->getVariable(),
277                                                 i)),
278                                         action->getLastUpdate(),
279                                         now - action->getLastUpdate());
280         }
281       }
282       if (!lmm_get_number_of_cnst_from_var (p_maxminSystem, action->getVariable())) {
283         /* There is actually no link used, hence an infinite bandwidth.
284          * This happens often when using models like vivaldi.
285          * In such case, just make sure that the action completes immediately.
286          */
287         action->updateRemains(action->getRemains());
288       }
289     action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
290                   
291     if (action->getMaxDuration() != NO_MAX_DURATION)
292       action->updateMaxDuration(delta);
293       
294     if ((action->getRemains() <= 0) &&
295         (lmm_get_variable_weight(action->getVariable()) > 0)) {
296       action->finish();
297       action->setState(SURF_ACTION_DONE);
298       action->gapRemove();
299     } else if (((action->getMaxDuration() != NO_MAX_DURATION)
300         && (action->getMaxDuration() <= 0))) {
301       action->finish();
302       action->setState(SURF_ACTION_DONE);
303       action->gapRemove();
304     }
305   }
306 }
307
308 Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
309                                                 double size, double rate)
310 {
311   unsigned int i;
312   void *_link;
313   NetworkCm02Link *link;
314   int failed = 0;
315   NetworkCm02Action *action = NULL;
316   double bandwidth_bound;
317   double latency = 0.0;
318   xbt_dynar_t back_route = NULL;
319   int constraints_per_variable = 0;
320
321   xbt_dynar_t route = xbt_dynar_new(sizeof(NetCard*), NULL);
322
323   XBT_IN("(%s,%s,%g,%g)", src->name(), dst->name(), size, rate);
324
325   routing_platf->getRouteAndLatency(src, dst, &route, &latency);
326   xbt_assert(!xbt_dynar_is_empty(route) || latency,
327              "You're trying to send data from %s to %s but there is no connecting path between these two hosts.",
328              src->name(), dst->name());
329
330   xbt_dynar_foreach(route, i, _link) {
331   link = static_cast<NetworkCm02Link*>(_link);
332     if (link->isOff()) {
333       failed = 1;
334       break;
335     }
336   }
337   if (sg_network_crosstraffic == 1) {
338     routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
339     xbt_dynar_foreach(back_route, i, _link) {
340       link = static_cast<NetworkCm02Link*>(_link);
341       if (link->isOff()) {
342         failed = 1;
343         break;
344       }
345     }
346   }
347
348   action = new NetworkCm02Action(this, size, failed);
349
350 #ifdef HAVE_LATENCY_BOUND_TRACKING
351   action->m_latencyLimited = 0;
352 #endif
353   action->m_weight = action->m_latency = latency;
354
355   action->m_rate = rate;
356   if (p_updateMechanism == UM_LAZY) {
357     action->m_indexHeap = -1;
358     action->m_lastUpdate = surf_get_clock();
359   }
360
361   bandwidth_bound = -1.0;
362   if (sg_weight_S_parameter > 0) {
363     xbt_dynar_foreach(route, i, _link) {
364       link = static_cast<NetworkCm02Link*>(_link);
365       action->m_weight += sg_weight_S_parameter / link->getBandwidth();
366     }
367   }
368   xbt_dynar_foreach(route, i, _link) {
369     link = static_cast<NetworkCm02Link*>(_link);
370     double bb = bandwidthFactor(size) * link->getBandwidth();
371     bandwidth_bound =
372         (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb);
373   }
374
375   action->m_latCurrent = action->m_latency;
376   action->m_latency *= latencyFactor(size);
377   action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
378   if (m_haveGap) {
379     xbt_assert(!xbt_dynar_is_empty(route),
380                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
381
382     link = *static_cast<NetworkCm02Link **>(xbt_dynar_get_ptr(route, 0));
383     gapAppend(size, link, action);
384     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
385               action, src->name(), dst->name(), action->m_senderGap,
386               action->m_latency);
387   }
388
389   constraints_per_variable = xbt_dynar_length(route);
390   if (back_route != NULL)
391     constraints_per_variable += xbt_dynar_length(back_route);
392
393   if (action->m_latency > 0) {
394     action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
395                          constraints_per_variable);
396     if (p_updateMechanism == UM_LAZY) {
397       // add to the heap the event when the latency is payed
398       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
399                 action->m_latency + action->m_lastUpdate);
400       action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
401     }
402   } else
403     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
404
405   if (action->m_rate < 0) {
406     lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
407   } else {
408     lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? std::min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate);
409   }
410
411   xbt_dynar_foreach(route, i, _link) {
412     link = static_cast<NetworkCm02Link*>(_link);
413     lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), 1.0);
414   }
415
416   if (sg_network_crosstraffic == 1) {
417     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
418     xbt_dynar_foreach(back_route, i, _link) {
419       link = static_cast<NetworkCm02Link*>(_link);
420       lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), .05);
421     }
422     //Change concurrency_share here, if you want that cross-traffic is included in the SURF concurrency
423     //(You would also have to change lmm_element_concurrency())
424     //lmm_variable_concurrency_share_set(action->getVariable(),2);
425   }
426
427   xbt_dynar_free(&route);
428   XBT_OUT();
429
430   networkCommunicateCallbacks(action, src, dst, size, rate);
431   return action;
432 }
433
434 /************
435  * Resource *
436  ************/
437 NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props,
438     lmm_system_t system,
439     double constraint_value,
440     tmgr_trace_t state_trace,
441     double bw_peak, tmgr_trace_t bw_trace,
442     double lat_initial, tmgr_trace_t lat_trace,
443     e_surf_link_sharing_policy_t policy)
444 : Link(model, name, props, lmm_constraint_new(system, this, constraint_value), state_trace)
445 {
446   m_bandwidth.scale = 1.0;
447   m_bandwidth.peak = bw_peak;
448   if (bw_trace)
449     m_bandwidth.event = future_evt_set->add_trace(bw_trace, 0.0, this);
450   else
451     m_bandwidth.event = NULL;
452
453   m_latency.scale = 1.0;
454   m_latency.peak = lat_initial;
455   if (lat_trace)
456     m_latency.event = future_evt_set->add_trace(lat_trace, 0.0, this);
457
458   if (policy == SURF_LINK_FATPIPE)
459     lmm_constraint_shared(getConstraint());
460 }
461
462
463
464 void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value)
465 {
466
467   /* Find out which of my iterators was triggered, and react accordingly */
468   if (triggered == m_bandwidth.event) {
469     updateBandwidth(value);
470     tmgr_trace_event_unref(&m_bandwidth.event);
471
472   } else if (triggered == m_latency.event) {
473     updateLatency(value);
474     tmgr_trace_event_unref(&m_latency.event);
475
476   } else if (triggered == m_stateEvent) {
477     if (value > 0)
478       turnOn();
479     else {
480       lmm_variable_t var = NULL;
481       lmm_element_t elem = NULL;
482       double now = surf_get_clock();
483
484       turnOff();
485       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
486         Action *action = static_cast<Action*>( lmm_variable_id(var) );
487
488         if (action->getState() == SURF_ACTION_RUNNING ||
489             action->getState() == SURF_ACTION_READY) {
490           action->setFinishTime(now);
491           action->setState(SURF_ACTION_FAILED);
492         }
493       }
494     }
495     tmgr_trace_event_unref(&m_stateEvent);
496   } else {
497     xbt_die("Unknown event!\n");
498   }
499
500   XBT_DEBUG("There was a resource state event, need to update actions related to the constraint (%p)",
501        getConstraint());
502 }
503
504 void NetworkCm02Link::updateBandwidth(double value) {
505
506   m_bandwidth.peak = value;
507
508   lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(),
509       sg_bandwidth_factor * (m_bandwidth.peak * m_bandwidth.scale));
510   TRACE_surf_link_set_bandwidth(surf_get_clock(), getName(), sg_bandwidth_factor * m_bandwidth.peak * m_bandwidth.scale);
511
512   if (sg_weight_S_parameter > 0) {
513     double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (m_bandwidth.peak * m_bandwidth.scale);
514
515     lmm_variable_t var;
516     lmm_element_t elem = NULL, nextelem = NULL;
517     int numelem = 0;
518     while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
519       NetworkCm02Action *action = (NetworkCm02Action*) lmm_variable_id(var);
520       action->m_weight += delta;
521       if (!action->isSuspended())
522         lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
523     }
524   }
525 }
526
527 void NetworkCm02Link::updateLatency(double value){
528   double delta = value - m_latency.peak;
529   lmm_variable_t var = NULL;
530   lmm_element_t elem = NULL;
531   lmm_element_t nextelem = NULL;
532   int numelem = 0;
533
534   m_latency.peak = value;
535
536   while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
537     NetworkCm02Action *action = (NetworkCm02Action*) lmm_variable_id(var);
538     action->m_latCurrent += delta;
539     action->m_weight += delta;
540     if (action->m_rate < 0)
541       lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(), sg_tcp_gamma / (2.0 * action->m_latCurrent));
542     else {
543       lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(),
544                                 std::min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
545
546       if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
547         XBT_INFO("Flow is limited BYBANDWIDTH");
548       } else {
549         XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", action->m_latCurrent);
550       }
551     }
552     if (!action->isSuspended())
553       lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
554   }
555 }
556
557 /**********
558  * Action *
559  **********/
560 void NetworkCm02Action::updateRemainingLazy(double now)
561 {
562   double delta = 0.0;
563
564   if (m_suspended != 0)
565     return;
566
567   delta = now - m_lastUpdate;
568
569   if (m_remains > 0) {
570     XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate);
571     double_update(&(m_remains), m_lastValue * delta, sg_maxmin_precision*sg_surf_precision);
572
573     XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains);
574   }
575
576   if (m_maxDuration != NO_MAX_DURATION)
577     double_update(&m_maxDuration, delta, sg_surf_precision);
578
579   if (m_remains <= 0 &&
580       (lmm_get_variable_weight(getVariable()) > 0)) {
581     finish();
582     setState(SURF_ACTION_DONE);
583
584     heapRemove(getModel()->getActionHeap());
585   } else if (((m_maxDuration != NO_MAX_DURATION)
586       && (m_maxDuration <= 0))) {
587     finish();
588     setState(SURF_ACTION_DONE);
589     heapRemove(getModel()->getActionHeap());
590   }
591
592   m_lastUpdate = now;
593   m_lastValue = lmm_variable_getvalue(getVariable());
594 }
595
596 }
597 }