Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
177c4cdb356d6fc9b6f8c1738918a6a837a3532a
[simgrid.git] / src / simix / smx_host.c
1 /* Copyright (c) 2007-2012. 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 "smx_private.h"
8 #include "xbt/sysdep.h"
9 #include "xbt/log.h"
10 #include "xbt/dict.h"
11 #include "mc/mc.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
14                                 "Logging specific to SIMIX (hosts)");
15
16 static void SIMIX_execution_finish(smx_action_t action);
17
18 /**
19  * \brief Internal function to create a SIMIX host.
20  * \param name name of the host to create
21  * \param workstation the SURF workstation to encapsulate
22  * \param data some user data (may be NULL)
23  */
24 smx_host_t SIMIX_host_create(const char *name,
25                                void *workstation, void *data)
26 {
27   smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1);
28   s_smx_process_t proc;
29
30   /* Host structure */
31   smx_host->data = data;
32   smx_host->process_list =
33       xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
34
35   /* Update global variables */
36   xbt_lib_set(host_lib,name,SIMIX_HOST_LEVEL,smx_host);
37   
38   return xbt_lib_get_elm_or_null(host_lib, name);
39 }
40
41 void SIMIX_pre_host_on(smx_simcall_t simcall, smx_host_t h)
42 {
43   SIMIX_host_on(h);
44 }
45
46 /**
47  * \brief Start the host if it is off
48  *
49  */
50 void SIMIX_host_on(smx_host_t h)
51 {
52   smx_host_priv_t host = SIMIX_host_priv(h);
53
54   xbt_assert((host != NULL), "Invalid parameters");
55
56   surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL);
57   if (ws_model->extension.workstation.get_state(h)==SURF_RESOURCE_OFF) {
58     ws_model->extension.workstation.set_state(h, SURF_RESOURCE_ON);
59     unsigned int cpt;
60     smx_process_arg_t arg;
61     xbt_dynar_foreach(host->boot_processes,cpt,arg) {
62       smx_process_t process;
63
64       XBT_DEBUG("Booting Process %s(%s) right now", arg->argv[0], arg->hostname);
65       if (simix_global->create_process_function) {
66         simix_global->create_process_function(&process,
67                                               arg->argv[0],
68                                               arg->code,
69                                               NULL,
70                                               arg->hostname,
71                                               arg->kill_time,
72                                               arg->argc,
73                                               arg->argv,
74                                               arg->properties,
75                                               arg->auto_restart);
76       }
77       else {
78         simcall_process_create(&process,
79                                               arg->argv[0],
80                                               arg->code,
81                                               NULL,
82                                               arg->hostname,
83                                               arg->kill_time,
84                                               arg->argc,
85                                               arg->argv,
86                                               arg->properties,
87                                               arg->auto_restart);
88       }
89     }
90   }
91 }
92
93 void SIMIX_pre_host_off(smx_simcall_t simcall, smx_host_t h)
94 {
95   SIMIX_host_off(h, simcall->issuer);
96 }
97
98 /**
99  * \brief Stop the host if it is on
100  *
101  */
102 void SIMIX_host_off(smx_host_t h, smx_process_t issuer)
103 {
104   smx_host_priv_t host = SIMIX_host_priv(h);
105
106   xbt_assert((host != NULL), "Invalid parameters");
107   
108   surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL);
109   if (ws_model->extension.workstation.get_state(h)==SURF_RESOURCE_ON) {
110     ws_model->extension.workstation.set_state(h, SURF_RESOURCE_OFF);
111
112     /* Clean Simulator data */
113     if (xbt_swag_size(host->process_list) != 0) {
114       smx_process_t process = NULL;
115       xbt_swag_foreach(process, host->process_list) {
116         SIMIX_process_kill(process, issuer);
117         XBT_DEBUG("Killing %s on %s by %s", process->name,  sg_host_name(process->smx_host), issuer->name);
118       }
119     }
120   }
121 }
122
123 /**
124  * \brief Internal function to destroy a SIMIX host.
125  *
126  * \param h the host to destroy (a smx_host_t)
127  */
128 void SIMIX_host_destroy(void *h)
129 {
130   smx_host_priv_t host = (smx_host_priv_t) h;
131
132   xbt_assert((host != NULL), "Invalid parameters");
133
134   /* Clean Simulator data */
135   if (xbt_swag_size(host->process_list) != 0) {
136     char *msg = xbt_strdup("Shutting down host, but it's not empty:");
137     char *tmp;
138     smx_process_t process = NULL;
139
140     xbt_swag_foreach(process, host->process_list) {
141       tmp = bprintf("%s\n\t%s", msg, process->name);
142       free(msg);
143       msg = tmp;
144     }
145     SIMIX_display_process_status();
146     THROWF(arg_error, 0, "%s", msg);
147   }
148   xbt_dynar_free(&host->auto_restart_processes);
149   xbt_dynar_free(&host->boot_processes);
150   xbt_swag_free(host->process_list);
151
152   /* Clean host structure */
153   free(host); 
154   return;
155 }
156
157 ///**
158 // * \brief Returns a dict of all hosts.
159 // *
160 // * \return List of all hosts (as a #xbt_dict_t)
161 // */
162 //xbt_dict_t SIMIX_host_get_dict(void)
163 //{
164 //  xbt_dict_t host_dict = xbt_dict_new_homogeneous(NULL);
165 //  xbt_lib_cursor_t cursor = NULL;
166 //  char *name = NULL;
167 //  void **host = NULL;
168 //
169 //  xbt_lib_foreach(host_lib, cursor, name, host){
170 //    if(host[SIMIX_HOST_LEVEL])
171 //            xbt_dict_set(host_dict,name,host[SIMIX_HOST_LEVEL], NULL);
172 //  }
173 //  return host_dict;
174 //}
175 smx_host_t SIMIX_pre_host_get_by_name(smx_simcall_t simcall, const char *name){
176    return SIMIX_host_get_by_name(name);
177 }
178 smx_host_t SIMIX_host_get_by_name(const char *name){
179   xbt_assert(((simix_global != NULL)
180                && (host_lib != NULL)),
181               "Environment not set yet");
182
183   return xbt_lib_get_elm_or_null(host_lib, name);
184 }
185
186 smx_host_t SIMIX_host_self(void)
187 {
188   smx_process_t process = SIMIX_process_self();
189   return (process == NULL) ? NULL : SIMIX_process_get_host(process);
190 }
191
192 const char* SIMIX_pre_host_self_get_name(smx_simcall_t simcall){
193    return SIMIX_host_self_get_name();
194 }
195 /* needs to be public and without simcall because it is called
196    by exceptions and logging events */
197 const char* SIMIX_host_self_get_name(void)
198 {
199   smx_host_t host = SIMIX_host_self();
200   if (host == NULL || SIMIX_process_self() == simix_global->maestro_process)
201     return "";
202
203   return SIMIX_host_get_name(host);
204 }
205
206 const char* SIMIX_pre_host_get_name(smx_simcall_t simcall, smx_host_t host){
207    return SIMIX_host_get_name(host);
208 }
209 const char* SIMIX_host_get_name(smx_host_t host){
210   xbt_assert((host != NULL), "Invalid parameters");
211
212   return sg_host_name(host);
213 }
214
215 xbt_dict_t SIMIX_pre_host_get_properties(smx_simcall_t simcall, smx_host_t host){
216   return SIMIX_host_get_properties(host);
217 }
218 xbt_dict_t SIMIX_host_get_properties(smx_host_t host){
219   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
220
221   surf_model_t ws_model = surf_resource_model(host, SURF_WKS_LEVEL);
222   return ws_model->extension.workstation.get_properties(host);
223 }
224
225 double SIMIX_pre_host_get_speed(smx_simcall_t simcall, smx_host_t host){
226   return SIMIX_host_get_speed(host);
227 }
228 double SIMIX_host_get_speed(smx_host_t host){
229   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
230
231   surf_model_t ws_model = surf_resource_model(host, SURF_WKS_LEVEL);
232   return ws_model->extension.workstation.get_speed(host, 1.0);
233 }
234
235 int SIMIX_pre_host_get_core(smx_simcall_t simcall, smx_host_t host){
236   return SIMIX_host_get_core(host);
237 }
238 int SIMIX_host_get_core(smx_host_t host){
239   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
240
241   return surf_workstation_model->extension.workstation.
242       get_core(host);
243 }
244
245
246
247 double SIMIX_pre_host_get_available_speed(smx_simcall_t simcall, smx_host_t host){
248   return SIMIX_host_get_available_speed(host);
249 }
250 double SIMIX_host_get_available_speed(smx_host_t host){
251   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
252
253   surf_model_t ws_model = surf_resource_model(host, SURF_WKS_LEVEL);
254   return ws_model->extension.workstation.get_available_speed(host);
255 }
256
257 int SIMIX_pre_host_get_state(smx_simcall_t simcall, smx_host_t host){
258   return SIMIX_host_get_state(host);
259 }
260 int SIMIX_host_get_state(smx_host_t host){
261   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
262
263   surf_model_t ws_model = surf_resource_model(host, SURF_WKS_LEVEL);
264   return ws_model->extension.workstation.get_state(host);
265 }
266
267 void* SIMIX_pre_host_self_get_data(smx_simcall_t simcall){
268   return SIMIX_host_self_get_data();
269 }
270 void* SIMIX_host_self_get_data(void)
271 {
272   smx_host_t self = SIMIX_host_self();
273   return SIMIX_host_get_data(self);
274 }
275
276 void SIMIX_host_self_set_data(void *data)
277 {
278   smx_host_t self = SIMIX_host_self();
279   SIMIX_host_set_data(self, data);
280 }
281
282 void* SIMIX_pre_host_get_data(smx_simcall_t simcall,smx_host_t host){
283   return SIMIX_host_get_data(host);
284 }
285 void* SIMIX_host_get_data(smx_host_t host){
286   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
287
288   return SIMIX_host_priv(host)->data;
289 }
290
291 void _SIMIX_host_free_process_arg(void *data)
292 {
293   smx_process_arg_t arg = *(void**)data;
294   xbt_free(arg->name);
295   xbt_free(arg);
296 }
297 /**
298  * \brief Add a process to the list of the processes that the host will restart when it comes back
299  * This function add a process to the list of the processes that will be restarted when the host comes
300  * back. It is expected that this function is called when the host is down.
301  * The processes will only be restarted once, meaning that you will have to register the process
302  * again to restart the process again.
303  */
304 void SIMIX_host_add_auto_restart_process(smx_host_t host,
305                                          const char *name,
306                                          xbt_main_func_t code,
307                                          void *data,
308                                          const char *hostname,
309                                          double kill_time,
310                                          int argc, char **argv,
311                                          xbt_dict_t properties,
312                                          int auto_restart)
313 {
314   if (!SIMIX_host_priv(host)->auto_restart_processes) {
315     SIMIX_host_priv(host)->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg);
316   }
317   smx_process_arg_t arg = xbt_new(s_smx_process_arg_t,1);
318   arg->name = xbt_strdup(name);
319   arg->code = code;
320   arg->data = data;
321   arg->hostname = hostname;
322   arg->kill_time = kill_time;
323   arg->argc = argc;
324
325   arg->argv = xbt_new(char*,argc + 1);
326
327   int i;
328   for (i = 0; i < argc; i++) {
329     arg->argv[i] = xbt_strdup(argv[i]);
330   }
331   arg->argv[argc] = NULL;
332
333   arg->properties = properties;
334   arg->auto_restart = auto_restart;
335
336   if( SIMIX_host_get_state(host) == SURF_RESOURCE_OFF
337       && !xbt_dict_get_or_null(watched_hosts_lib,sg_host_name(host))){
338     xbt_dict_set(watched_hosts_lib,sg_host_name(host),host,NULL);
339     XBT_DEBUG("Have push host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_name(host));
340   }
341   xbt_dynar_push_as(SIMIX_host_priv(host)->auto_restart_processes,smx_process_arg_t,arg);
342 }
343 /**
344  * \brief Restart the list of processes that have been registered to the host
345  */
346 void SIMIX_host_restart_processes(smx_host_t host)
347 {
348   unsigned int cpt;
349   smx_process_arg_t arg;
350   xbt_dynar_foreach(SIMIX_host_priv(host)->auto_restart_processes,cpt,arg) {
351
352     smx_process_t process;
353
354     XBT_DEBUG("Restarting Process %s(%s) right now", arg->argv[0], arg->hostname);
355     if (simix_global->create_process_function) {
356       simix_global->create_process_function(&process,
357                                             arg->argv[0],
358                                             arg->code,
359                                             NULL,
360                                             arg->hostname,
361                                             arg->kill_time,
362                                             arg->argc,
363                                             arg->argv,
364                                             arg->properties,
365                                             arg->auto_restart);
366     }
367     else {
368       simcall_process_create(&process,
369                                             arg->argv[0],
370                                             arg->code,
371                                             NULL,
372                                             arg->hostname,
373                                             arg->kill_time,
374                                             arg->argc,
375                                             arg->argv,
376                                             arg->properties,
377                                             arg->auto_restart);
378
379     }
380   }
381   xbt_dynar_reset(SIMIX_host_priv(host)->auto_restart_processes);
382 }
383
384 void SIMIX_host_autorestart(smx_host_t host)
385 {
386   if(simix_global->autorestart)
387     simix_global->autorestart(host);
388   else
389     xbt_die("No function for simix_global->autorestart");
390 }
391
392 void SIMIX_pre_host_set_data(smx_simcall_t simcall, smx_host_t host, void *data) {
393   SIMIX_host_set_data(host, data);
394 }
395 void SIMIX_host_set_data(smx_host_t host, void *data){
396   xbt_assert((host != NULL), "Invalid parameters");
397   xbt_assert((SIMIX_host_priv(host)->data == NULL), "Data already set");
398
399   SIMIX_host_priv(host)->data = data;
400 }
401
402 smx_action_t SIMIX_pre_host_execute(smx_simcall_t simcall,const char *name,
403     smx_host_t host, double computation_amount, double priority, double bound){
404   return SIMIX_host_execute(name, host, computation_amount, priority, bound);
405 }
406 smx_action_t SIMIX_host_execute(const char *name,
407     smx_host_t host, double computation_amount, double priority, double bound){
408
409   /* alloc structures and initialize */
410   smx_action_t action = xbt_mallocator_get(simix_global->action_mallocator);
411   action->type = SIMIX_ACTION_EXECUTE;
412   action->name = xbt_strdup(name);
413   action->state = SIMIX_RUNNING;
414   action->execution.host = host;
415
416 #ifdef HAVE_TRACING
417   action->category = NULL;
418 #endif
419
420   surf_model_t ws_model = surf_resource_model(host, SURF_WKS_LEVEL);
421   /* set surf's action */
422   if (!MC_is_active()) {
423     action->execution.surf_exec = ws_model->extension.workstation.execute(host, computation_amount);
424     ws_model->action_data_set(action->execution.surf_exec, action);
425     ws_model->set_priority(action->execution.surf_exec, priority);
426
427     /* Note (hypervisor): for multicore, the bound value being passed to the
428      * surf layer should not be zero (i.e., unlimited). It should be the
429      * capacity of a CPU core. */
430     if (bound == 0)
431       ws_model->set_bound(action->execution.surf_exec, SIMIX_host_get_speed(host));
432     else
433       ws_model->set_bound(action->execution.surf_exec, bound);
434   }
435
436   XBT_DEBUG("Create execute action %p", action);
437
438   return action;
439 }
440
441 smx_action_t SIMIX_pre_host_parallel_execute(smx_simcall_t simcall, const char *name,
442     int host_nb, smx_host_t *host_list,
443     double *computation_amount, double *communication_amount,
444     double amount, double rate){
445   return SIMIX_host_parallel_execute(name, host_nb, host_list, computation_amount,
446                                      communication_amount, amount, rate);
447 }
448 smx_action_t SIMIX_host_parallel_execute(const char *name,
449     int host_nb, smx_host_t *host_list,
450     double *computation_amount, double *communication_amount,
451     double amount, double rate){
452
453   void **workstation_list = NULL;
454   int i;
455
456   /* alloc structures and initialize */
457   smx_action_t action = xbt_mallocator_get(simix_global->action_mallocator);
458   action->type = SIMIX_ACTION_PARALLEL_EXECUTE;
459   action->name = xbt_strdup(name);
460   action->state = SIMIX_RUNNING;
461   action->execution.host = NULL; /* FIXME: do we need the list of hosts? */
462
463 #ifdef HAVE_TRACING
464   action->category = NULL;
465 #endif
466
467   /* set surf's action */
468   workstation_list = xbt_new0(void *, host_nb);
469   for (i = 0; i < host_nb; i++)
470     workstation_list[i] = host_list[i];
471
472
473   /* FIXME: what happens if host_list contains VMs and PMs. If
474    * execute_parallel_task() does not change the state of the model, we can mix
475    * them. */
476   surf_model_t ws_model = surf_resource_model(host_list[0], SURF_WKS_LEVEL);
477   for (i = 1; i < host_nb; i++) {
478     surf_model_t ws_model_tmp = surf_resource_model(host_list[i], SURF_WKS_LEVEL);
479     if (ws_model_tmp != ws_model) {
480       XBT_CRITICAL("mixing VMs and PMs is not supported");
481       DIE_IMPOSSIBLE;
482     }
483   }
484
485   /* set surf's action */
486   if (!MC_is_active()) {
487     action->execution.surf_exec =
488       ws_model->extension.workstation.
489       execute_parallel_task(host_nb, workstation_list, computation_amount,
490                       communication_amount, rate);
491
492     ws_model->action_data_set(action->execution.surf_exec, action);
493   }
494   XBT_DEBUG("Create parallel execute action %p", action);
495
496   return action;
497 }
498
499 static surf_model_t get_ws_model_from_action(smx_action_t action)
500 {
501   xbt_assert(action->type == SIMIX_ACTION_EXECUTE);
502   smx_host_t host = action->execution.host;
503   surf_model_t model = surf_resource_model(host, SURF_WKS_LEVEL);
504
505   xbt_assert((model == surf_workstation_model) || (model == surf_vm_workstation_model));
506
507   return model;
508 }
509
510 void SIMIX_pre_host_execution_destroy(smx_simcall_t simcall, smx_action_t action){
511   SIMIX_host_execution_destroy(action);
512 }
513 void SIMIX_host_execution_destroy(smx_action_t action){
514   XBT_DEBUG("Destroy action %p", action);
515
516   surf_model_t ws_model = get_ws_model_from_action(action);
517
518   if (action->execution.surf_exec) {
519     ws_model->action_unref(action->execution.surf_exec);
520     action->execution.surf_exec = NULL;
521   }
522   xbt_free(action->name);
523   xbt_mallocator_release(simix_global->action_mallocator, action);
524 }
525
526 void SIMIX_pre_host_execution_cancel(smx_simcall_t simcall, smx_action_t action){
527   SIMIX_host_execution_cancel(action);
528 }
529 void SIMIX_host_execution_cancel(smx_action_t action){
530   XBT_DEBUG("Cancel action %p", action);
531
532   surf_model_t ws_model = get_ws_model_from_action(action);
533
534   if (action->execution.surf_exec)
535     ws_model->action_cancel(action->execution.surf_exec);
536 }
537
538 double SIMIX_pre_host_execution_get_remains(smx_simcall_t simcall, smx_action_t action){
539   return SIMIX_host_execution_get_remains(action);
540 }
541 double SIMIX_host_execution_get_remains(smx_action_t action){
542   double result = 0.0;
543   surf_model_t ws_model = get_ws_model_from_action(action);
544
545   if (action->state == SIMIX_RUNNING)
546     result = ws_model->get_remains(action->execution.surf_exec);
547
548   return result;
549 }
550
551 e_smx_state_t SIMIX_pre_host_execution_get_state(smx_simcall_t simcall, smx_action_t action){
552   return SIMIX_host_execution_get_state(action);
553 }
554 e_smx_state_t SIMIX_host_execution_get_state(smx_action_t action){
555   return action->state;
556 }
557
558 void SIMIX_pre_host_execution_set_priority(smx_simcall_t simcall, smx_action_t action,
559                                         double priority){
560   SIMIX_host_execution_set_priority(action, priority);
561 }
562 void SIMIX_host_execution_set_priority(smx_action_t action, double priority){
563   surf_model_t ws_model = get_ws_model_from_action(action);
564
565   if(action->execution.surf_exec)
566     ws_model->set_priority(action->execution.surf_exec, priority);
567 }
568
569 void SIMIX_pre_host_execution_set_bound(smx_simcall_t simcall, smx_action_t action,
570                                         double bound){
571   SIMIX_host_execution_set_bound(action, bound);
572 }
573 void SIMIX_host_execution_set_bound(smx_action_t action, double bound){
574   surf_model_t ws_model = get_ws_model_from_action(action);
575
576   if(action->execution.surf_exec)
577     ws_model->set_bound(action->execution.surf_exec, bound);
578 }
579
580 void SIMIX_pre_host_execution_wait(smx_simcall_t simcall, smx_action_t action){
581
582   XBT_DEBUG("Wait for execution of action %p, state %d", action, (int)action->state);
583
584   /* Associate this simcall to the action */
585   xbt_fifo_push(action->simcalls, simcall);
586   simcall->issuer->waiting_action = action;
587
588   /* set surf's action */
589   if (MC_is_active()) {
590     action->state = SIMIX_DONE;
591     SIMIX_execution_finish(action);
592     return;
593   }
594
595   /* If the action is already finished then perform the error handling */
596   if (action->state != SIMIX_RUNNING)
597     SIMIX_execution_finish(action);
598 }
599
600 void SIMIX_host_execution_suspend(smx_action_t action)
601 {
602   surf_model_t ws_model = get_ws_model_from_action(action);
603
604   if(action->execution.surf_exec)
605     ws_model->suspend(action->execution.surf_exec);
606 }
607
608 void SIMIX_host_execution_resume(smx_action_t action)
609 {
610   surf_model_t ws_model = get_ws_model_from_action(action);
611
612   if(action->execution.surf_exec)
613     ws_model->resume(action->execution.surf_exec);
614 }
615
616 void SIMIX_execution_finish(smx_action_t action)
617 {
618   xbt_fifo_item_t item;
619   smx_simcall_t simcall;
620   surf_model_t ws_model = get_ws_model_from_action(action);
621
622   xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
623
624     switch (action->state) {
625
626       case SIMIX_DONE:
627         /* do nothing, action done */
628   XBT_DEBUG("SIMIX_execution_finished: execution successful");
629         break;
630
631       case SIMIX_FAILED:
632         XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", sg_host_name(simcall->issuer->smx_host));
633         simcall->issuer->context->iwannadie = 1;
634         //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
635         break;
636
637       case SIMIX_CANCELED:
638         XBT_DEBUG("SIMIX_execution_finished: execution canceled");
639         SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
640         break;
641
642       default:
643         xbt_die("Internal error in SIMIX_execution_finish: unexpected action state %d",
644             (int)action->state);
645     }
646     /* check if the host is down */
647     if (ws_model->extension.workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
648       simcall->issuer->context->iwannadie = 1;
649     }
650
651     simcall->issuer->waiting_action =    NULL;
652     simcall_host_execution_wait__set__result(simcall, action->state);
653     SIMIX_simcall_answer(simcall);
654   }
655
656   /* We no longer need it */
657   SIMIX_host_execution_destroy(action);
658 }
659
660
661 void SIMIX_post_host_execute(smx_action_t action)
662 {
663   surf_model_t ws_model = get_ws_model_from_action(action);
664
665   if (action->type == SIMIX_ACTION_EXECUTE && /* FIMXE: handle resource failure
666                                                * for parallel tasks too */
667       ws_model->extension.workstation.get_state(action->execution.host) == SURF_RESOURCE_OFF) {
668     /* If the host running the action failed, notice it so that the asking
669      * process can be killed if it runs on that host itself */
670     action->state = SIMIX_FAILED;
671   } else if (ws_model->action_state_get(action->execution.surf_exec) == SURF_ACTION_FAILED) {
672     /* If the host running the action didn't fail, then the action was
673      * canceled */
674     action->state = SIMIX_CANCELED;
675   } else {
676     action->state = SIMIX_DONE;
677   }
678
679   if (action->execution.surf_exec) {
680     ws_model->action_unref(action->execution.surf_exec);
681     action->execution.surf_exec = NULL;
682   }
683
684   /* If there are simcalls associated with the action, then answer them */
685   if (xbt_fifo_size(action->simcalls)) {
686     SIMIX_execution_finish(action);
687   }
688 }
689
690
691 #ifdef HAVE_TRACING
692 void SIMIX_pre_set_category(smx_simcall_t simcall, smx_action_t action,
693                             const char *category){
694   SIMIX_set_category(action, category);
695 }
696 void SIMIX_set_category(smx_action_t action, const char *category)
697 {
698   surf_model_t ws_model = get_ws_model_from_action(action);
699
700   if (action->state != SIMIX_RUNNING) return;
701   if (action->type == SIMIX_ACTION_EXECUTE){
702     ws_model->set_category(action->execution.surf_exec, category);
703   }else if (action->type == SIMIX_ACTION_COMMUNICATE){
704     ws_model->set_category(action->comm.surf_comm, category);
705   }
706 }
707 #endif
708
709
710 /**
711  * \brief Function to get the parameters of the given the SIMIX host.
712  *
713  * \param host the host to get_phys_host (a smx_host_t)
714  * \param param the parameter object space to be overwritten (a ws_params_t)
715  */
716 void SIMIX_host_get_params(smx_host_t ind_vm, ws_params_t params)
717 {
718   /* jump to ws_get_params(). */
719   surf_workstation_model->extension.workstation.get_params(ind_vm, params);
720 }
721
722 void SIMIX_pre_host_get_params(smx_simcall_t simcall, smx_host_t ind_vm, ws_params_t params)
723 {
724   SIMIX_host_get_params(ind_vm, params);
725   SIMIX_simcall_answer(simcall);
726 }
727
728 void SIMIX_host_set_params(smx_host_t ind_vm, ws_params_t params)
729 {
730   /* jump to ws_set_params(). */
731   surf_workstation_model->extension.workstation.set_params(ind_vm, params);
732 }
733
734 void SIMIX_pre_host_set_params(smx_simcall_t simcall, smx_host_t ind_vm, ws_params_t params)
735 {
736   SIMIX_host_set_params(ind_vm, params);
737   SIMIX_simcall_answer(simcall);
738 }