Logo AND Algorithmique Numérique Distribuée

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