Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into hypervisor
[simgrid.git] / src / simix / smx_smurf_private.h
index ac677cd..fcd229d 100644 (file)
 #define SIMCALL_ARG(i, v) SIMCALL_ARG_ v
 
 /* get the parameter initialisation field */
-#define SIMCALL_INIT_FIELD_(name, type, field) {.field = name}
-#define SIMCALL_INIT_FIELD(i, v) SIMCALL_INIT_FIELD_ v
+#define SIMCALL_INIT_FIELD_(name, type, field) .field = name
+#define SIMCALL_INIT_FIELD(i, d, v) self->simcall.args[i]SIMCALL_INIT_FIELD_ v;
 
 /* get the case of the parameter */
 #define SIMCALL_CASE_PARAM_(name, type, field) field
        (name, type, __VA_ARGS__)
 #define SIMCALL_FUNC_SIMCALL(res) SIMCALL_FUNC_SIMCALL_ res
 
-#define SIMCALL_WITH_FUNC_RETURN(name, type, field) return simcall->result.field;
+#define SIMCALL_WITH_FUNC_RETURN(name, type, field) return self->simcall.result.field;
 #define SIMCALL_WITHOUT_FUNC_RETURN(name, type, field)
 #define SIMCALL_FUNC_RETURN_(name, type, ...)\
         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_RETURN, SIMCALL_WITHOUT_FUNC_RETURN)\
 #define SIMCALL_ENUM(type, ...)\
        type
 
+/* generate the strings name from the enumeration values */
+#define SIMCALL_STRING_TYPE(type, name, answer, res, ...)\
+       [type] = STRINGIFY(type)
+
 /* generate strings from the enumeration values */
 #define SIMCALL_TYPE(type, name, answer, res, ...)\
        [type] = STRINGIFY(MAP(SIMCALL_FORMAT, __VA_ARGS__))
 
-/* generate the simcalls functions */
-#define SIMCALL_FUNC(type, name, answer, res, ...)\
-       inline static SIMCALL_FUNC_RETURN_TYPE(res) simcall_BODY_##name(MAP(SIMCALL_ARG, ##__VA_ARGS__)) { \
-      SIMCALL_FUNC_SIMCALL(res) __SIMIX_simcall(type, (u_smx_scalar_t[]){MAP(SIMCALL_INIT_FIELD, ##__VA_ARGS__)}); \
-      SIMCALL_FUNC_RETURN(res)\
-    }
-
-/* generate the simcalls prototypes functions */
-#define VOID_IF_EMPTY(...) GET_CLEAN(,##__VA_ARGS__,,,,,,,,,,,void)
-#define SIMCALL_FUNC_PROTO(type, name, answer, res, ...)\
-       inline static SIMCALL_FUNC_RETURN_TYPE(res) simcall_BODY_##name(VOID_IF_EMPTY(__VA_ARGS__) MAP(SIMCALL_ARG, ##__VA_ARGS__));
-
+/* generate the simcalls BODY functions */
+#define SIMCALL_FUNC(TYPE, NAME, ANSWER, RES, ...)\
+  inline static SIMCALL_FUNC_RETURN_TYPE(RES) simcall_BODY_##NAME(MAP(SIMCALL_ARG, ##__VA_ARGS__)) { \
+    smx_process_t self = SIMIX_process_self(); \
+    self->simcall.call = TYPE; \
+    memset(self->simcall.args, 0, sizeof(self->simcall.args));  \
+    MAP_WITH_DEFAULT_ARGS(SIMCALL_INIT_FIELD, (), ##__VA_ARGS__) \
+    if (self != simix_global->maestro_process) { \
+      XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, \
+                SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); \
+      SIMIX_process_yield(self); \
+    } else { \
+      SIMIX_simcall_pre(&self->simcall, 0); \
+    } \
+    SIMCALL_FUNC_RETURN(RES) \
+  }
 
 /* generate a comma if there is an argument*/
 #define WITHOUT_COMMA 
 #define WITH_ANSWER(...) __VA_ARGS__
 #define WITHOUT_ANSWER(...) 
 #define SIMCALL_CASE(type, name, answer, res, ...)\
-    case type:;\
+    case type:\
       SIMCALL_RESULT_BEGIN(answer, res) SIMIX_pre_ ## name(simcall MAYBE_COMMA(__VA_ARGS__) MAP(SIMCALL_CASE_PARAM, ##__VA_ARGS__));\
       SIMCALL_RESULT_END(answer, res)\
       break;
 
 /* generate the simcalls args getter/setter */
 #define SIMCALL_ARG_GETSET_(i, name, v) \
-  inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
+  static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
     return simcall->args[i].SIMCALL_FIELD_ v ;\
   }\
-  inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
+  static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
     simcall->args[i].SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
   }
 
 #define SIMCALL_ARG_GETSET(type, name, answer, res, ...)\
     MAP_WITH_DEFAULT_ARGS(SIMCALL_ARG_GETSET_, (name), ##__VA_ARGS__)
 
-/* generate the simcalls args getter/setter protos*/
-#define SIMCALL_ARG_GETSET_PROTO_(i, name, v) \
-  inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall);\
-  inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v);
-
-#define SIMCALL_ARG_GETSET_PROTO(type, name, answer, res, ...)\
-    MAP_WITH_DEFAULT_ARGS(SIMCALL_ARG_GETSET_PROTO_, (name), ##__VA_ARGS__)
-
 /* generate the simcalls result getter/setter */
 #define SIMCALL_WITH_RES_GETSET(name, v) \
-  inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
+  static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
     return simcall->result.SIMCALL_FIELD_ v ;\
   }\
-  inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
+  static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
     simcall->result.SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
   }
 #define SIMCALL_WITHOUT_RES_GETSET(name, v)
 #define SIMCALL_RES_GETSET_PROTO(type, name, answer, res, ...)\
   SIMCALL_RES_GETSET_PROTO_(name, res)
 
-
-
-
 /* stringify arguments */
 #define STRINGIFY_(...) #__VA_ARGS__
 #define STRINGIFY(...) STRINGIFY_(__VA_ARGS__)
@@ -277,14 +274,23 @@ ACTION(SIMCALL_HOST_EXECUTION_GET_REMAINS, host_execution_get_remains, WITH_ANSW
 ACTION(SIMCALL_HOST_EXECUTION_GET_STATE, host_execution_get_state, WITH_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
 ACTION(SIMCALL_HOST_EXECUTION_SET_PRIORITY, host_execution_set_priority, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t), TDOUBLE(priority)) sep \
 ACTION(SIMCALL_HOST_EXECUTION_WAIT, host_execution_wait, WITHOUT_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
+ACTION(SIMCALL_VM_WS_CREATE, vm_ws_create, WITH_ANSWER, TPTR(result), TSTRING(name), TSPEC(phys_host, smx_host_t)) sep \
+ACTION(SIMCALL_VM_START, vm_start, WITHOUT_ANSWER, TVOID(result), TSPEC(ind_phys_host, smx_host_t)) sep \
+ACTION(SIMCALL_VM_SET_STATE, vm_set_state, WITHOUT_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t), TINT(state)) sep \
+ACTION(SIMCALL_VM_GET_STATE, vm_get_state, WITH_ANSWER, TINT(result), TSPEC(ind_vm, smx_host_t)) sep \
+ACTION(SIMCALL_VM_DESTROY, vm_destroy, WITHOUT_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t)) sep \
+ACTION(SIMCALL_VM_SUSPEND, vm_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t)) sep \
+ACTION(SIMCALL_VM_SHUTDOWN, vm_shutdown, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t)) sep \
 ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t*), TSTRING(name), TSPEC(code, xbt_main_func_t), TPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TSPEC(argv, char**), TSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \
 ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
-ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result)) sep \
+ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result), TINT(reset_pid)) sep \
 ACTION(SIMCALL_PROCESS_CLEANUP, process_cleanup, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 ACTION(SIMCALL_PROCESS_CHANGE_HOST, process_change_host, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(dest, smx_host_t)) sep \
 ACTION(SIMCALL_PROCESS_SUSPEND, process_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 ACTION(SIMCALL_PROCESS_RESUME, process_resume, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 ACTION(SIMCALL_PROCESS_COUNT, process_count, WITH_ANSWER, TINT(result)) sep \
+ACTION(SIMCALL_PROCESS_GET_PID, process_get_PID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep  \
+ACTION(SIMCALL_PROCESS_GET_PPID, process_get_PPID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep  \
 ACTION(SIMCALL_PROCESS_GET_DATA, process_get_data, WITH_ANSWER, TPTR(result), TSPEC(process, smx_process_t)) sep \
 ACTION(SIMCALL_PROCESS_SET_DATA, process_set_data, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TPTR(data)) sep \
 ACTION(SIMCALL_PROCESS_GET_HOST, process_get_host, WITH_ANSWER, TSPEC(result, smx_host_t), TSPEC(process, smx_process_t)) sep \
@@ -395,12 +401,6 @@ NUM_SIMCALLS
 typedef int (*simix_match_func_t)(void *, void *, smx_action_t);
 typedef void (*simix_clean_func_t)(void *);
 
-/**
- * \brief Prototypes of SIMIX
- */
-SIMCALL_LIST(SIMCALL_FUNC_PROTO, SIMCALL_SEP_NOTHING)
-
-
 /* Pack all possible scalar types in an union */
 union u_smx_scalar {
   char            c;
@@ -426,7 +426,7 @@ typedef struct s_smx_simcall {
   e_smx_simcall_t call;
   smx_process_t issuer;
   int mc_value;
-  union u_smx_scalar *args;
+  union u_smx_scalar args[10];
   union u_smx_scalar result;
   //FIXME: union u_smx_scalar retval;
   union {
@@ -439,8 +439,8 @@ typedef struct s_smx_simcall {
   };
 } s_smx_simcall_t, *smx_simcall_t;
 
-SIMCALL_LIST(SIMCALL_RES_GETSET_PROTO, SIMCALL_SEP_NOTHING)
-SIMCALL_LIST(SIMCALL_ARG_GETSET_PROTO, SIMCALL_SEP_NOTHING)
+SIMCALL_LIST(SIMCALL_RES_GETSET, SIMCALL_SEP_NOTHING)
+SIMCALL_LIST(SIMCALL_ARG_GETSET, SIMCALL_SEP_NOTHING)
 
 /******************************** General *************************************/