Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2f1006a9bbeff0c8c3ac33a130ad54ee53c5c795
[simgrid.git] / src / surf / host_ptask_L07.cpp
1 /* Copyright (c) 2007-2010, 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 "host_ptask_L07.hpp"
8
9 #include "cpu_interface.hpp"
10 #include "surf_routing.hpp"
11 #include "xbt/lib.h"
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host);
14
15 static int ptask_host_count = 0;
16 static xbt_dict_t ptask_parallel_task_link_set = NULL;
17 lmm_system_t ptask_maxmin_system = NULL;
18
19
20 /**************************************/
21 /*** Resource Creation & Destruction **/
22 /**************************************/
23
24 static void ptask_netlink_parse_init(sg_platf_link_cbarg_t link)
25 {
26   netlink_parse_init(link);
27   current_property_set = NULL;
28 }
29
30 void surf_host_model_init_ptask_L07(void)
31 {
32   XBT_INFO("Switching to the L07 model to handle parallel tasks.");
33   xbt_assert(!surf_cpu_model_pm, "CPU model type already defined");
34   xbt_assert(!surf_network_model, "network model type already defined");
35
36   // Define the callbacks to parse the XML
37   sg_platf_host_add_cb(cpu_parse_init);
38   sg_platf_host_add_cb(host_parse_init);
39   sg_platf_link_add_cb(ptask_netlink_parse_init);
40   sg_platf_postparse_add_cb(host_add_traces);
41
42   surf_host_model = new HostL07Model();
43   Model *model = surf_host_model;
44   xbt_dynar_push(all_existing_models, &model);
45 }
46
47
48 HostL07Model::HostL07Model() : HostModel() {
49   if (!ptask_maxmin_system)
50         ptask_maxmin_system = lmm_system_new(1);
51   surf_host_model = NULL;
52   surf_network_model = new NetworkL07Model(this);
53   surf_cpu_model_pm = new CpuL07Model(this);
54
55   routing_model_create(surf_network_model->createLink("__loopback__",
56                                                           498000000, NULL,
57                                                           0.000015, NULL,
58                                                           SURF_RESOURCE_ON, NULL,
59                                                           SURF_LINK_FATPIPE, NULL));
60 }
61
62 HostL07Model::~HostL07Model() {
63   xbt_dict_free(&ptask_parallel_task_link_set);
64
65   delete surf_cpu_model_pm;
66   delete surf_network_model;
67   ptask_host_count = 0;
68
69   if (ptask_maxmin_system) {
70     lmm_system_free(ptask_maxmin_system);
71     ptask_maxmin_system = NULL;
72   }
73 }
74
75 double HostL07Model::shareResources(double /*now*/)
76 {
77   L07Action *action;
78
79   ActionList *running_actions = getRunningActionSet();
80   double min = this->shareResourcesMaxMin(running_actions,
81                                               ptask_maxmin_system,
82                                               bottleneck_solve);
83
84   for(ActionList::iterator it(running_actions->begin()), itend(running_actions->end())
85          ; it != itend ; ++it) {
86         action = static_cast<L07Action*>(&*it);
87     if (action->m_latency > 0) {
88       if (min < 0) {
89         min = action->m_latency;
90         XBT_DEBUG("Updating min (value) with %p (start %f): %f", action,
91                action->getStartTime(), min);
92       } else if (action->m_latency < min) {
93         min = action->m_latency;
94         XBT_DEBUG("Updating min (latency) with %p (start %f): %f", action,
95                action->getStartTime(), min);
96       }
97     }
98   }
99
100   XBT_DEBUG("min value : %f", min);
101
102   return min;
103 }
104
105 void HostL07Model::updateActionsState(double /*now*/, double delta) {
106
107   L07Action *action;
108   ActionList *actionSet = getRunningActionSet();
109
110   for(ActionList::iterator it = actionSet->begin(), itNext = it
111          ; it != actionSet->end()
112          ; it =  itNext) {
113         ++itNext;
114     action = static_cast<L07Action*>(&*it);
115     if (action->m_latency > 0) {
116       if (action->m_latency > delta) {
117         double_update(&(action->m_latency), delta, sg_surf_precision);
118       } else {
119         action->m_latency = 0.0;
120       }
121       if ((action->m_latency == 0.0) && (action->isSuspended() == 0)) {
122         action->updateBound();
123         lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 1.0);
124       }
125     }
126     XBT_DEBUG("Action (%p) : remains (%g) updated by %g.",
127            action, action->getRemains(), lmm_variable_getvalue(action->getVariable()) * delta);
128     action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
129
130     if (action->getMaxDuration() != NO_MAX_DURATION)
131       action->updateMaxDuration(delta);
132
133     XBT_DEBUG("Action (%p) : remains (%g).", action, action->getRemains());
134
135     /* In the next if cascade, the action can be finished either because:
136      *  - The amount of remaining work reached 0
137      *  - The max duration was reached
138      * If it's not done, it may have failed.
139      */
140
141     if ((action->getRemains() <= 0) &&
142         (lmm_get_variable_weight(action->getVariable()) > 0)) {
143       action->finish();
144       action->setState(SURF_ACTION_DONE);
145     } else if ((action->getMaxDuration() != NO_MAX_DURATION) &&
146                (action->getMaxDuration() <= 0)) {
147       action->finish();
148       action->setState(SURF_ACTION_DONE);
149     } else {
150       /* Need to check that none of the model has failed */
151       lmm_constraint_t cnst = NULL;
152       int i = 0;
153
154       while ((cnst = lmm_get_cnst_from_var(ptask_maxmin_system, action->getVariable(), i++))) {
155         void *constraint_id = lmm_constraint_id(cnst);
156
157         if (static_cast<Host*>(constraint_id)->getState() == SURF_RESOURCE_OFF) {
158           XBT_DEBUG("Action (%p) Failed!!", action);
159           action->finish();
160           action->setState(SURF_ACTION_FAILED);
161           break;
162         }
163       }
164     }
165   }
166   return;
167 }
168
169 Action *HostL07Model::executeParallelTask(int host_nb,
170                                           sg_host_t*host_list,
171                                                                                   double *flops_amount,
172                                                                                   double *bytes_amount,
173                                                                                   double rate)
174 {
175   L07Action *action = new L07Action(this, 1, 0);
176   unsigned int cpt;
177   int nb_link = 0;
178   int nb_host = 0;
179   double latency = 0.0;
180
181   action->p_edgeList->reserve(host_nb);
182   for (int i = 0; i<host_nb; i++)
183           action->p_edgeList->push_back(sg_host_edge(host_list[i]));
184
185   if (ptask_parallel_task_link_set == NULL)
186     ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL);
187
188   xbt_dict_reset(ptask_parallel_task_link_set);
189
190   /* Compute the number of affected resources... */
191   for (int i = 0; i < host_nb; i++) {
192     for (int j = 0; j < host_nb; j++) {
193       xbt_dynar_t route=NULL;
194
195       if (bytes_amount[i * host_nb + j] > 0) {
196         double lat=0.0;
197         unsigned int cpt;
198         void *_link;
199         LinkL07 *link;
200
201         routing_platf->getRouteAndLatency((*action->p_edgeList)[i], (*action->p_edgeList)[j],
202                                                   &route, &lat);
203         latency = MAX(latency, lat);
204
205         xbt_dynar_foreach(route, cpt, _link) {
206            link = static_cast<LinkL07*>(_link);
207            xbt_dict_set(ptask_parallel_task_link_set, link->getName(), link, NULL);
208         }
209       }
210     }
211   }
212
213   nb_link = xbt_dict_length(ptask_parallel_task_link_set);
214   xbt_dict_reset(ptask_parallel_task_link_set);
215
216   for (int i = 0; i < host_nb; i++)
217     if (flops_amount[i] > 0)
218       nb_host++;
219
220   XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.",
221          action, host_nb, nb_link);
222   action->m_suspended = 0; /* valgrind seems to want it despite the calloc... */
223   action->p_computationAmount = flops_amount;
224   action->p_communicationAmount = bytes_amount;
225   action->m_latency = latency;
226   action->m_rate = rate;
227
228   action->p_variable = lmm_variable_new(ptask_maxmin_system, action, 1.0,
229                                         (rate > 0 ? rate : -1.0),
230                                                                                 host_nb + nb_link);
231
232   if (action->m_latency > 0)
233     lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 0.0);
234
235   for (int i = 0; i < host_nb; i++)
236     lmm_expand(ptask_maxmin_system,
237                sg_host_surfcpu(host_list[i])->getConstraint(),
238                action->getVariable(), flops_amount[i]);
239
240   for (int i = 0; i < host_nb; i++) {
241     for (int j = 0; j < host_nb; j++) {
242       void *_link;
243
244       xbt_dynar_t route=NULL;
245       if (bytes_amount[i * host_nb + j] == 0.0)
246         continue;
247
248       routing_platf->getRouteAndLatency((*action->p_edgeList)[i], (*action->p_edgeList)[j],
249                                             &route, NULL);
250
251       xbt_dynar_foreach(route, cpt, _link) {
252         LinkL07 *link = static_cast<LinkL07*>(_link);
253         lmm_expand_add(ptask_maxmin_system, link->getConstraint(),
254                        action->getVariable(),
255                        bytes_amount[i * host_nb + j]);
256       }
257     }
258   }
259
260   if (nb_link + nb_host == 0) {
261     action->setCost(1.0);
262     action->setRemains(0.0);
263   }
264
265   return action;
266 }
267
268 Host *HostL07Model::createHost(const char *name)
269 {
270   HostL07 *wk = NULL;
271   sg_host_t sg_host = sg_host_by_name(name);
272
273   xbt_assert(!surf_host_resource_priv(sg_host),
274               "Host '%s' declared several times in the platform file.",
275               name);
276
277   wk = new HostL07(this, name, NULL,
278                                   sg_host_edge(sg_host),
279                                                   sg_host_surfcpu(sg_host));
280   surf_callback_emit(hostCreatedCallbacks, wk);
281   xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, wk);
282
283   return wk;
284 }
285
286 Action *NetworkL07Model::communicate(RoutingEdge *src, RoutingEdge *dst,
287                                        double size, double rate)
288 {
289   sg_host_t*host_list = xbt_new0(sg_host_t, 2);
290   double *flops_amount = xbt_new0(double, 2);
291   double *bytes_amount = xbt_new0(double, 4);
292   Action *res = NULL;
293
294   host_list[0] = sg_host_by_name(src->getName());
295   host_list[1] = sg_host_by_name(dst->getName());
296   bytes_amount[1] = size;
297
298   res = p_hostModel->executeParallelTask(2, host_list,
299                                     flops_amount,
300                                     bytes_amount, rate);
301
302   return res;
303 }
304
305 xbt_dynar_t HostL07Model::getRoute(Host *src, Host *dst)
306 {
307   xbt_dynar_t route=NULL;
308   routing_platf->getRouteAndLatency(src->p_netElm, dst->p_netElm, &route, NULL);
309   return route;
310 }
311
312 Cpu *CpuL07Model::createCpu(const char *name,  xbt_dynar_t powerPeak,
313                           int pstate, double power_scale,
314                           tmgr_trace_t power_trace, int core,
315                           e_surf_resource_state_t state_initial,
316                           tmgr_trace_t state_trace,
317                           xbt_dict_t cpu_properties)
318 {
319   double power_initial = xbt_dynar_get_as(powerPeak, pstate, double);
320   xbt_dynar_free(&powerPeak);   // kill memory leak
321   sg_host_t sg_host = sg_host_by_name(name);
322
323   xbt_assert(!surf_host_resource_priv(sg_host),
324               "Host '%s' declared several times in the platform file.",
325               name);
326
327   CpuL07 *cpu = new CpuL07(this, name, cpu_properties,
328                                      power_initial, power_scale, power_trace,
329                          core, state_initial, state_trace);
330   surf_callback_emit(cpuCreatedCallbacks, cpu);
331   surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, state_initial);
332   sg_host_surfcpu_set(sg_host, cpu);
333
334   return cpu;
335 }
336
337 Link* NetworkL07Model::createLink(const char *name,
338                                  double bw_initial,
339                                  tmgr_trace_t bw_trace,
340                                  double lat_initial,
341                                  tmgr_trace_t lat_trace,
342                                  e_surf_resource_state_t state_initial,
343                                  tmgr_trace_t state_trace,
344                                  e_surf_link_sharing_policy_t policy,
345                                  xbt_dict_t properties)
346 {
347   xbt_assert(!Link::byName(name),
348                  "Link '%s' declared several times in the platform file.", name);
349
350   return new LinkL07(this, name, properties,
351                              bw_initial, bw_trace,
352                                          lat_initial, lat_trace,
353                                          state_initial, state_trace,
354                                          policy);
355 }
356
357 void HostL07Model::addTraces()
358 {
359   xbt_dict_cursor_t cursor = NULL;
360   char *trace_name, *elm;
361
362   if (!trace_connect_list_host_avail)
363     return;
364
365   /* Connect traces relative to cpu */
366   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
367     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
368     CpuL07 *host = static_cast<CpuL07*>(sg_host_surfcpu(sg_host_by_name(elm)));
369
370     xbt_assert(host, "Host %s undefined", elm);
371     xbt_assert(trace, "Trace %s undefined", trace_name);
372
373     host->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
374   }
375
376   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
377     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
378     CpuL07 *host = static_cast<CpuL07*>(sg_host_surfcpu(sg_host_by_name(elm)));
379
380     xbt_assert(host, "Host %s undefined", elm);
381     xbt_assert(trace, "Trace %s undefined", trace_name);
382
383     host->p_powerEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
384   }
385
386   /* Connect traces relative to network */
387   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
388     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
389     LinkL07 *link = static_cast<LinkL07*>(Link::byName(elm));
390
391     xbt_assert(link, "Link %s undefined", elm);
392     xbt_assert(trace, "Trace %s undefined", trace_name);
393
394     link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
395   }
396
397   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
398     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
399     LinkL07 *link = static_cast<LinkL07*>(Link::byName(elm));
400
401     xbt_assert(link, "Link %s undefined", elm);
402     xbt_assert(trace, "Trace %s undefined", trace_name);
403
404     link->p_bwEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
405   }
406
407   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
408     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
409     LinkL07 *link = static_cast<LinkL07*>(Link::byName(elm));
410
411     xbt_assert(link, "Link %s undefined", elm);
412     xbt_assert(trace, "Trace %s undefined", trace_name);
413
414     link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
415   }
416 }
417
418 /************
419  * Resource *
420  ************/
421
422 HostL07::HostL07(HostModel *model, const char* name, xbt_dict_t props, RoutingEdge *netElm, Cpu *cpu)
423   : Host(model, name, props, NULL, netElm, cpu)
424 {
425 }
426
427 double HostL07::getPowerPeakAt(int /*pstate_index*/)
428 {
429         THROW_UNIMPLEMENTED;
430 }
431
432 int HostL07::getNbPstates()
433 {
434         THROW_UNIMPLEMENTED;
435 }
436
437 void HostL07::setPstate(int /*pstate_index*/)
438 {
439         THROW_UNIMPLEMENTED;
440 }
441
442 int HostL07::getPstate()
443 {
444         THROW_UNIMPLEMENTED;
445 }
446
447 double HostL07::getConsumedEnergy()
448 {
449         THROW_UNIMPLEMENTED;
450 }
451
452 CpuL07::CpuL07(CpuL07Model *model, const char* name, xbt_dict_t props,
453                      double power_initial, double power_scale, tmgr_trace_t power_trace,
454                            int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
455  : Cpu(model, name, props, lmm_constraint_new(ptask_maxmin_system, this, power_initial * power_scale),
456            core, power_initial, power_scale, state_initial)
457 {
458   xbt_assert(m_powerScale > 0, "Power has to be >0");
459
460   if (power_trace)
461     p_powerEvent = tmgr_history_add_trace(history, power_trace, 0.0, 0, this);
462   else
463     p_powerEvent = NULL;
464
465   if (state_trace)
466         p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
467 }
468
469 LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
470                          double bw_initial,
471                          tmgr_trace_t bw_trace,
472                          double lat_initial,
473                          tmgr_trace_t lat_trace,
474                          e_surf_resource_state_t state_initial,
475                          tmgr_trace_t state_trace,
476                          e_surf_link_sharing_policy_t policy)
477  : Link(model, name, props, lmm_constraint_new(ptask_maxmin_system, this, bw_initial), history, state_trace)
478 {
479   m_bwCurrent = bw_initial;
480   if (bw_trace)
481     p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, this);
482
483   setState(state_initial);
484   m_latCurrent = lat_initial;
485
486   if (lat_trace)
487         p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, this);
488
489   if (policy == SURF_LINK_FATPIPE)
490         lmm_constraint_shared(getConstraint());
491 }
492
493 bool CpuL07::isUsed(){
494   return lmm_constraint_used(ptask_maxmin_system, getConstraint());
495 }
496
497 bool LinkL07::isUsed(){
498   return lmm_constraint_used(ptask_maxmin_system, getConstraint());
499 }
500
501 void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*date*/){
502   XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value);
503   if (event_type == p_powerEvent) {
504           m_powerScale = value;
505     lmm_update_constraint_bound(ptask_maxmin_system, getConstraint(), m_powerPeak * m_powerScale);
506     if (tmgr_trace_event_free(event_type))
507       p_powerEvent = NULL;
508   } else if (event_type == p_stateEvent) {
509     if (value > 0)
510       setState(SURF_RESOURCE_ON);
511     else
512       setState(SURF_RESOURCE_OFF);
513     if (tmgr_trace_event_free(event_type))
514       p_stateEvent = NULL;
515   } else {
516     XBT_CRITICAL("Unknown event ! \n");
517     xbt_abort();
518   }
519   return;
520 }
521
522 void LinkL07::updateState(tmgr_trace_event_t event_type, double value, double date) {
523   XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", getName(), this, value, date);
524   if (event_type == p_bwEvent) {
525     updateBandwidth(value, date);
526     if (tmgr_trace_event_free(event_type))
527       p_bwEvent = NULL;
528   } else if (event_type == p_latEvent) {
529     updateLatency(value, date);
530     if (tmgr_trace_event_free(event_type))
531       p_latEvent = NULL;
532   } else if (event_type == p_stateEvent) {
533     if (value > 0)
534       setState(SURF_RESOURCE_ON);
535     else
536       setState(SURF_RESOURCE_OFF);
537     if (tmgr_trace_event_free(event_type))
538       p_stateEvent = NULL;
539   } else {
540     XBT_CRITICAL("Unknown event ! \n");
541     xbt_abort();
542   }
543   return;
544 }
545
546 e_surf_resource_state_t HostL07::getState() {
547   return p_cpu->getState();
548 }
549
550 Action *HostL07::execute(double size)
551 {
552   sg_host_t*host_list = xbt_new0(sg_host_t, 1);
553   double *flops_amount = xbt_new0(double, 1);
554   double *bytes_amount = xbt_new0(double, 1);
555
556   host_list[0] = sg_host_by_name(getName());
557   flops_amount[0] = size;
558
559   return static_cast<HostL07Model*>(getModel())->executeParallelTask(1, host_list,
560                                               flops_amount,
561                                      bytes_amount, -1);
562 }
563
564 Action *HostL07::sleep(double duration)
565 {
566   L07Action *action = NULL;
567
568   XBT_IN("(%s,%g)", getName(), duration);
569
570   action = static_cast<L07Action*>(execute(1.0));
571   action->m_maxDuration = duration;
572   action->m_suspended = 2;
573   lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 0.0);
574
575   XBT_OUT();
576   return action;
577 }
578
579 double LinkL07::getBandwidth()
580 {
581   return m_bwCurrent;
582 }
583
584 void LinkL07::updateBandwidth(double value, double date)
585 {
586   m_bwCurrent = value;
587   lmm_update_constraint_bound(ptask_maxmin_system, getConstraint(), m_bwCurrent);
588 }
589
590 double LinkL07::getLatency()
591 {
592   return m_latCurrent;
593 }
594
595 void LinkL07::updateLatency(double value, double date)
596 {
597   lmm_variable_t var = NULL;
598   L07Action *action;
599   lmm_element_t elem = NULL;
600
601   m_latCurrent = value;
602   while ((var = lmm_get_var_from_cnst(ptask_maxmin_system, getConstraint(), &elem))) {
603     action = static_cast<L07Action*>(lmm_variable_id(var));
604     action->updateBound();
605   }
606 }
607
608
609 bool LinkL07::isShared()
610 {
611   return lmm_constraint_is_shared(getConstraint());
612 }
613
614 /**********
615  * Action *
616  **********/
617
618 L07Action::~L07Action(){
619   free(p_communicationAmount);
620   free(p_computationAmount);
621 }
622
623 void L07Action::updateBound()
624 {
625   double lat_current = 0.0;
626   double lat_bound = -1.0;
627   int i, j;
628
629   int hostNb = p_edgeList->size();
630
631   for (i = 0; i < hostNb; i++) {
632     for (j = 0; j < hostNb; j++) {
633       xbt_dynar_t route=NULL;
634
635       if (p_communicationAmount[i * hostNb + j] > 0) {
636         double lat = 0.0;
637         routing_platf->getRouteAndLatency((*p_edgeList)[i], (*p_edgeList)[j],
638                                                           &route, &lat);
639
640         lat_current = MAX(lat_current, lat * p_communicationAmount[i * hostNb + j]);
641       }
642     }
643   }
644   lat_bound = sg_tcp_gamma / (2.0 * lat_current);
645   XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
646   if ((m_latency == 0.0) && (m_suspended == 0)) {
647     if (m_rate < 0)
648       lmm_update_variable_bound(ptask_maxmin_system, getVariable(), lat_bound);
649     else
650       lmm_update_variable_bound(ptask_maxmin_system, getVariable(), min(m_rate, lat_bound));
651   }
652 }
653
654 int L07Action::unref()
655 {
656   m_refcount--;
657   if (!m_refcount) {
658     if (action_hook.is_linked())
659           p_stateSet->erase(p_stateSet->iterator_to(*this));
660     if (getVariable())
661       lmm_variable_free(ptask_maxmin_system, getVariable());
662     delete this;
663     return 1;
664   }
665   return 0;
666 }
667
668 void L07Action::cancel()
669 {
670   setState(SURF_ACTION_FAILED);
671   return;
672 }
673
674 void L07Action::suspend()
675 {
676   XBT_IN("(%p))", this);
677   if (m_suspended != 2) {
678     m_suspended = 1;
679     lmm_update_variable_weight(ptask_maxmin_system, getVariable(), 0.0);
680   }
681   XBT_OUT();
682 }
683
684 void L07Action::resume()
685 {
686   XBT_IN("(%p)", this);
687   if (m_suspended != 2) {
688     lmm_update_variable_weight(ptask_maxmin_system, getVariable(), 1.0);
689     m_suspended = 0;
690   }
691   XBT_OUT();
692 }
693
694 bool L07Action::isSuspended()
695 {
696   return m_suspended == 1;
697 }
698
699 void L07Action::setMaxDuration(double duration)
700 {                               /* FIXME: should inherit */
701   XBT_IN("(%p,%g)", this, duration);
702   m_maxDuration = duration;
703   XBT_OUT();
704 }
705
706 void L07Action::setPriority(double priority)
707 {                               /* FIXME: should inherit */
708   XBT_IN("(%p,%g)", this, priority);
709   m_priority = priority;
710   XBT_OUT();
711 }
712
713 double L07Action::getRemains()
714 {
715   XBT_IN("(%p)", this);
716   XBT_OUT();
717   return m_remains;
718 }