Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Restructure surf++ cpu and network
[simgrid.git] / src / surf / network_cm02.cpp
1 #include "network_cm02.hpp"
2 #include "maxmin_private.h"
3 #include "simgrid/sg_config.h"
4
5 extern "C" {
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
7                                 "Logging specific to the SURF network module");
8 }
9
10 double sg_sender_gap = 0.0;
11 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
12 double sg_bandwidth_factor = 1.0;       /* default value; can be set by model or from command line */
13 double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or from command line */
14
15 double sg_tcp_gamma = 0.0;
16 int sg_network_crosstraffic = 0;
17
18 /*************
19  * CallBacks *
20  *************/
21
22 static void net_parse_link_init(sg_platf_link_cbarg_t link){
23   if (link->policy == SURF_LINK_FULLDUPLEX) {
24     char *link_id;
25     link_id = bprintf("%s_UP", link->id);
26     surf_network_model->createResource(link_id,
27                       link->bandwidth,
28                       link->bandwidth_trace,
29                       link->latency,
30                       link->latency_trace,
31                       link->state,
32                       link->state_trace, link->policy, link->properties);
33     xbt_free(link_id);
34     link_id = bprintf("%s_DOWN", link->id);
35     surf_network_model->createResource(link_id,
36                       link->bandwidth,
37                       link->bandwidth_trace,
38                       link->latency,
39                       link->latency_trace,
40                       link->state,
41                       link->state_trace, link->policy, link->properties);
42     xbt_free(link_id);
43   } else {
44         surf_network_model->createResource(link->id,
45                       link->bandwidth,
46                       link->bandwidth_trace,
47                       link->latency,
48                       link->latency_trace,
49                       link->state,
50                       link->state_trace, link->policy, link->properties);
51   }
52 }
53
54 static void net_add_traces(void){
55   xbt_dict_cursor_t cursor = NULL;
56   char *trace_name, *elm;
57
58   static int called = 0;
59   if (called)
60     return;
61   called = 1;
62
63   /* connect all traces relative to network */
64   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
65     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
66     NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
67                                      static_cast<ResourcePtr>(
68                                                   xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
69
70     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
71                trace_name, elm);
72     xbt_assert(trace,
73                "Cannot connect trace %s to link %s: trace undefined",
74                trace_name, elm);
75
76     link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
77   }
78
79   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
80     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
81     NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
82                                  static_cast<ResourcePtr>(
83                                       xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
84
85     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
86                trace_name, elm);
87     xbt_assert(trace,
88                "Cannot connect trace %s to link %s: trace undefined",
89                trace_name, elm);
90
91     link->p_power.event = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
92   }
93
94   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
95     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
96     NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
97                                  static_cast<ResourcePtr>(
98                                       xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
99
100     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
101                trace_name, elm);
102     xbt_assert(trace,
103                "Cannot connect trace %s to link %s: trace undefined",
104                trace_name, elm);
105
106     link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
107   }
108 }
109
110 void net_define_callbacks(void)
111 {
112   /* Figuring out the network links */
113   sg_platf_link_add_cb(net_parse_link_init);
114   sg_platf_postparse_add_cb(net_add_traces);
115 }
116
117 /*********
118  * Model *
119  *********/
120
121 /************************************************************************/
122 /* New model based on optimizations discussed during Pedro Velho's thesis*/
123 /************************************************************************/
124 /* @techreport{VELHO:2011:HAL-00646896:1, */
125 /*      url = {http://hal.inria.fr/hal-00646896/en/}, */
126 /*      title = {{Flow-level network models: have we reached the limits?}}, */
127 /*      author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
128 /*      type = {Rapport de recherche}, */
129 /*      institution = {INRIA}, */
130 /*      number = {RR-7821}, */
131 /*      year = {2011}, */
132 /*      month = Nov, */
133 /*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
134 /*  } */
135 void surf_network_model_init_LegrandVelho(void)
136 {
137   if (surf_network_model)
138     return;
139
140   surf_network_model = new NetworkCm02Model();
141   net_define_callbacks();
142   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
143   xbt_dynar_push(model_list, &model);
144
145   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",
146                             13.01);
147   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
148                             0.97);
149   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 20537);
150 }
151
152 /***************************************************************************/
153 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
154 /***************************************************************************/
155 /* @TechReport{      rr-lip2002-40, */
156 /*   author        = {Henri Casanova and Loris Marchal}, */
157 /*   institution   = {LIP}, */
158 /*   title         = {A Network Model for Simulation of Grid Application}, */
159 /*   number        = {2002-40}, */
160 /*   month         = {oct}, */
161 /*   year          = {2002} */
162 /* } */
163 void surf_network_model_init_CM02(void)
164 {
165
166   if (surf_network_model)
167     return;
168
169   surf_network_model = new NetworkCm02Model();
170   net_define_callbacks();
171   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
172   xbt_dynar_push(model_list, &model);
173
174   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
175   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
176                             1.0);
177   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0);
178 }
179
180 /***************************************************************************/
181 /* The models from Steven H. Low                                           */
182 /***************************************************************************/
183 /* @article{Low03,                                                         */
184 /*   author={Steven H. Low},                                               */
185 /*   title={A Duality Model of {TCP} and Queue Management Algorithms},     */
186 /*   year={2003},                                                          */
187 /*   journal={{IEEE/ACM} Transactions on Networking},                      */
188 /*    volume={11}, number={4},                                             */
189 /*  }                                                                      */
190 void surf_network_model_init_Reno(void)
191 {
192   if (surf_network_model)
193     return;
194
195   surf_network_model = new NetworkCm02Model();
196   net_define_callbacks();
197   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
198   xbt_dynar_push(model_list, &model);
199   lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
200                                     func_reno_fpi);
201   surf_network_model->f_networkSolve = lagrange_solve;
202
203   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
204   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
205                             0.92);
206   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
207 }
208
209
210 void surf_network_model_init_Reno2(void)
211 {
212   if (surf_network_model)
213     return;
214
215   surf_network_model = new NetworkCm02Model();
216   net_define_callbacks();
217   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
218   xbt_dynar_push(model_list, &model);
219   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
220                                     func_reno2_fpi);
221   surf_network_model->f_networkSolve = lagrange_solve;
222
223   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
224   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
225                             0.92);
226   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S_parameter",
227                             8775);
228 }
229
230 void surf_network_model_init_Vegas(void)
231 {
232   if (surf_network_model)
233     return;
234
235   surf_network_model = new NetworkCm02Model();
236   net_define_callbacks();
237   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
238   xbt_dynar_push(model_list, &model);
239   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
240                                     func_vegas_fpi);
241   surf_network_model->f_networkSolve = lagrange_solve;
242
243   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
244   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
245                             0.92);
246   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
247 }
248
249 void NetworkCm02Model::initialize()
250 {
251   ActionLmmPtr comm = NULL;
252
253   char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
254   int select =
255       xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
256
257   if (!strcmp(optim, "Full")) {
258     p_updateMechanism = UM_FULL;
259     m_selectiveUpdate = select;
260   } else if (!strcmp(optim, "Lazy")) {
261     p_updateMechanism = UM_LAZY;
262     m_selectiveUpdate = 1;
263     xbt_assert((select == 1)
264                ||
265                (xbt_cfg_is_default_value
266                 (_sg_cfg_set, "network/maxmin_selective_update")),
267                "Disabling selective update while using the lazy update mechanism is dumb!");
268   } else {
269     xbt_die("Unsupported optimization (%s) for this model", optim);
270   }
271
272   if (!p_maxminSystem)
273         p_maxminSystem = lmm_system_new(m_selectiveUpdate);
274
275   const char* lb_name = "__loopback__";
276   routing_model_create(static_cast<ResourcePtr>(createResource(lb_name,
277                                                    498000000, NULL, 0.000015, NULL,
278                                                    SURF_RESOURCE_ON, NULL,
279                                                    SURF_LINK_FATPIPE, NULL)));
280
281   if (p_updateMechanism == UM_LAZY) {
282         p_actionHeap = xbt_heap_new(8, NULL);
283         xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
284         p_modifiedSet = xbt_swag_new(xbt_swag_offset(*comm, p_actionListHookup));
285         p_maxminSystem->keep_track = p_modifiedSet;
286   }
287
288   m_haveGap = false;
289 }
290
291 NetworkLinkPtr NetworkCm02Model::createResource(const char *name,
292                                  double bw_initial,
293                                  tmgr_trace_t bw_trace,
294                                  double lat_initial,
295                                  tmgr_trace_t lat_trace,
296                                  e_surf_resource_state_t state_initial,
297                                  tmgr_trace_t state_trace,
298                                  e_surf_link_sharing_policy_t policy,
299                                  xbt_dict_t properties)
300 {
301   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
302              "Link '%s' declared several times in the platform file.",
303              name);
304
305   NetworkCm02LinkLmmPtr nw_link =
306                   new NetworkCm02LinkLmm(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
307                                                  state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
308
309
310   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, static_cast<ResourcePtr>(nw_link));
311   XBT_DEBUG("Create link '%s'",name);
312
313   return nw_link;
314 }
315
316 void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
317 {
318   NetworkCm02ActionLmmPtr action;
319   while ((xbt_heap_size(p_actionHeap) > 0)
320          && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
321     action = (NetworkCm02ActionLmmPtr) xbt_heap_pop(p_actionHeap);
322     XBT_DEBUG("Something happened to action %p", action);
323 #ifdef HAVE_TRACING
324     if (TRACE_is_enabled()) {
325       int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->p_variable);
326       int i;
327       for (i = 0; i < n; i++){
328         lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
329                                                             action->p_variable,
330                                                             i);
331         NetworkCm02LinkLmmPtr link = static_cast<NetworkCm02LinkLmmPtr>(lmm_constraint_id(constraint));
332         TRACE_surf_link_set_utilization(link->m_name,
333                                         action->p_category,
334                                         (lmm_variable_getvalue(action->p_variable)*
335                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
336                                                 action->p_variable,
337                                                 i)),
338                                         action->m_lastUpdate,
339                                         now - action->m_lastUpdate);
340       }
341     }
342 #endif
343
344     // if I am wearing a latency hat
345     if (action->m_hat == LATENCY) {
346       XBT_DEBUG("Latency paid for action %p. Activating", action);
347       lmm_update_variable_weight(p_maxminSystem, action->p_variable, action->m_weight);
348       action->heapRemove(p_actionHeap);
349       action->m_lastUpdate = surf_get_clock();
350
351         // if I am wearing a max_duration or normal hat
352     } else if (action->m_hat == MAX_DURATION ||
353         action->m_hat == NORMAL) {
354         // no need to communicate anymore
355         // assume that flows that reached max_duration have remaining of 0
356       action->m_finish = surf_get_clock();
357       XBT_DEBUG("Action %p finished", action);
358       action->m_remains = 0;
359       action->m_finish = surf_get_clock();
360       action->setState(SURF_ACTION_DONE);
361       action->heapRemove(p_actionHeap);
362
363       action->gapRemove();
364     }
365   }
366   return;
367 }
368
369 ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
370                                                 double size, double rate)
371 {
372   unsigned int i;
373   void *_link;
374   NetworkCm02LinkLmmPtr link;
375   int failed = 0;
376   NetworkCm02ActionLmmPtr action = NULL;
377   double bandwidth_bound;
378   double latency = 0.0;
379   xbt_dynar_t back_route = NULL;
380   int constraints_per_variable = 0;
381
382   xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL);
383
384   XBT_IN("(%s,%s,%g,%g)", src->p_name, dst->p_name, size, rate);
385
386   routing_platf->getRouteAndLatency(src, dst, &route, &latency);
387   xbt_assert(!xbt_dynar_is_empty(route) || latency,
388              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
389              src->p_name, dst->p_name);
390
391   xbt_dynar_foreach(route, i, _link) {
392         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
393     if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
394       failed = 1;
395       break;
396     }
397   }
398   if (sg_network_crosstraffic == 1) {
399           routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
400     xbt_dynar_foreach(back_route, i, _link) {
401       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
402       if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
403         failed = 1;
404         break;
405       }
406     }
407   }
408
409   action = new NetworkCm02ActionLmm(this, size, failed);
410
411 #ifdef HAVE_LATENCY_BOUND_TRACKING
412   action->m_latencyLimited = 0;
413 #endif
414   action->m_weight = action->m_latency = latency;
415
416   //FIXME:REMOVxbt_swag_insert(action, action->p_stateSet);
417   action->m_rate = rate;
418   if (p_updateMechanism == UM_LAZY) {
419     action->m_indexHeap = -1;
420     action->m_lastUpdate = surf_get_clock();
421   }
422
423   bandwidth_bound = -1.0;
424   if (sg_weight_S_parameter > 0) {
425     xbt_dynar_foreach(route, i, _link) {
426       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
427       action->m_weight +=
428          sg_weight_S_parameter /
429          (link->p_power.peak * link->p_power.scale);
430     }
431   }
432   xbt_dynar_foreach(route, i, _link) {
433         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
434     double bb = bandwidthFactor(size) * (link->p_power.peak * link->p_power.scale);
435     bandwidth_bound =
436         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
437   }
438
439   action->m_latCurrent = action->m_latency;
440   action->m_latency *= latencyFactor(size);
441   action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
442   if (m_haveGap) {
443     xbt_assert(!xbt_dynar_is_empty(route),
444                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
445
446     //link = *(NetworkCm02LinkLmmPtr *) xbt_dynar_get_ptr(route, 0);
447     link = dynamic_cast<NetworkCm02LinkLmmPtr>(*static_cast<ResourcePtr *>(xbt_dynar_get_ptr(route, 0)));
448     gapAppend(size, link, action);
449     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
450               action, src->p_name, dst->p_name, action->m_senderGap,
451               action->m_latency);
452   }
453
454   constraints_per_variable = xbt_dynar_length(route);
455   if (back_route != NULL)
456     constraints_per_variable += xbt_dynar_length(back_route);
457
458   if (action->m_latency > 0) {
459     action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
460                          constraints_per_variable);
461     if (p_updateMechanism == UM_LAZY) {
462       // add to the heap the event when the latency is payed
463       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
464                 action->m_latency + action->m_lastUpdate);
465       action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
466     }
467   } else
468     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
469
470   if (action->m_rate < 0) {
471     lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
472   } else {
473     lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate);
474   }
475
476   xbt_dynar_foreach(route, i, _link) {
477         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
478     lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, 1.0);
479   }
480
481   if (sg_network_crosstraffic == 1) {
482     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
483     xbt_dynar_foreach(back_route, i, _link) {
484       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
485       lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, .05);
486     }
487   }
488
489   xbt_dynar_free(&route);
490   XBT_OUT();
491
492   return action;
493 }
494
495
496
497 /************
498  * Resource *
499  ************/
500 NetworkCm02LinkLmm::NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
501                                    lmm_system_t system,
502                                    double constraint_value,
503                                    tmgr_history_t history,
504                                    e_surf_resource_state_t state_init,
505                                    tmgr_trace_t state_trace,
506                                    double metric_peak,
507                                    tmgr_trace_t metric_trace,
508                                    double lat_initial,
509                                    tmgr_trace_t lat_trace,
510                                    e_surf_link_sharing_policy_t policy)
511 : Resource(model, name, props),
512   NetworkLinkLmm(system, constraint_value, history, state_init, state_trace, metric_peak, metric_trace)
513 {
514   m_latCurrent = lat_initial;
515   if (lat_trace)
516         p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast<ResourcePtr>(this));
517
518   if (policy == SURF_LINK_FATPIPE)
519         lmm_constraint_shared(p_constraint);
520 }
521
522
523
524 void NetworkCm02LinkLmm::updateState(tmgr_trace_event_t event_type,
525                                       double value, double date)
526 {
527   /*   printf("[" "%g" "] Asking to update network card \"%s\" with value " */
528   /*     "%g" " for event %p\n", surf_get_clock(), nw_link->name, */
529   /*     value, event_type); */
530
531   if (event_type == p_power.event) {
532     double delta =
533         sg_weight_S_parameter / value - sg_weight_S_parameter /
534         (p_power.peak * p_power.scale);
535     lmm_variable_t var = NULL;
536     lmm_element_t elem = NULL;
537     NetworkCm02ActionLmmPtr action = NULL;
538
539     p_power.peak = value;
540     lmm_update_constraint_bound(p_model->p_maxminSystem,
541                                 p_constraint,
542                                 sg_bandwidth_factor *
543                                 (p_power.peak * p_power.scale));
544 #ifdef HAVE_TRACING
545     TRACE_surf_link_set_bandwidth(date, m_name, sg_bandwidth_factor * p_power.peak * p_power.scale);
546 #endif
547     if (sg_weight_S_parameter > 0) {
548       while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
549         action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
550         action->m_weight += delta;
551         if (!action->m_suspended)
552           lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
553       }
554     }
555     if (tmgr_trace_event_free(event_type))
556       p_power.event = NULL;
557   } else if (event_type == p_latEvent) {
558     double delta = value - m_latCurrent;
559     lmm_variable_t var = NULL;
560     lmm_element_t elem = NULL;
561     NetworkCm02ActionLmmPtr action = NULL;
562
563     m_latCurrent = value;
564     while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
565       action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
566       action->m_latCurrent += delta;
567       action->m_weight += delta;
568       if (action->m_rate < 0)
569         lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable, sg_tcp_gamma / (2.0 * action->m_latCurrent));
570       else {
571         lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable,
572                                   min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
573
574         if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
575           XBT_INFO("Flow is limited BYBANDWIDTH");
576         } else {
577           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
578                    action->m_latCurrent);
579         }
580       }
581       if (!action->m_suspended)
582         lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
583
584     }
585     if (tmgr_trace_event_free(event_type))
586       p_latEvent = NULL;
587   } else if (event_type == p_stateEvent) {
588     if (value > 0)
589       p_stateCurrent = SURF_RESOURCE_ON;
590     else {
591       lmm_constraint_t cnst = p_constraint;
592       lmm_variable_t var = NULL;
593       lmm_element_t elem = NULL;
594
595       p_stateCurrent = SURF_RESOURCE_OFF;
596       while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, cnst, &elem))) {
597         ActionPtr action = (ActionPtr) lmm_variable_id(var);
598
599         if (action->getState() == SURF_ACTION_RUNNING ||
600             action->getState() == SURF_ACTION_READY) {
601           action->m_finish = date;
602           action->setState(SURF_ACTION_FAILED);
603         }
604       }
605     }
606     if (tmgr_trace_event_free(event_type))
607       p_stateEvent = NULL;
608   } else {
609     XBT_CRITICAL("Unknown event ! \n");
610     xbt_abort();
611   }
612
613   XBT_DEBUG
614       ("There were a resource state event, need to update actions related to the constraint (%p)",
615        p_constraint);
616   return;
617 }
618
619 /**********
620  * Action *
621  **********/
622 void NetworkCm02ActionLmm::updateRemainingLazy(double now)
623 {
624   double delta = 0.0;
625
626   if (m_suspended != 0)
627     return;
628
629   delta = now - m_lastUpdate;
630
631   if (m_remains > 0) {
632     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
633     double_update(&(m_remains), m_lastValue * delta);
634
635     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
636   }
637
638   if (m_maxDuration != NO_MAX_DURATION)
639     double_update(&m_maxDuration, delta);
640
641   if (m_remains <= 0 &&
642       (lmm_get_variable_weight(p_variable) > 0)) {
643     m_finish = surf_get_clock();
644     setState(SURF_ACTION_DONE);
645
646     heapRemove(p_model->p_actionHeap);
647   } else if (((m_maxDuration != NO_MAX_DURATION)
648       && (m_maxDuration <= 0))) {
649     m_finish = surf_get_clock();
650     setState(SURF_ACTION_DONE);
651     heapRemove(p_model->p_actionHeap);
652   }
653
654   m_lastUpdate = now;
655   m_lastValue = lmm_variable_getvalue(p_variable);
656 }
657 void NetworkCm02ActionLmm::recycle()
658 {
659   return;
660 }
661