From 8cb8e7da03088da26d6f05b7ff84c412fef25a53 Mon Sep 17 00:00:00 2001 From: Cristian Rosa Date: Fri, 7 Sep 2012 10:59:04 -0300 Subject: [PATCH] Move SIMCALL_HOST_EXECUTE to the new simcall architecture for initial testing. --- src/simix/smx_host.c | 9 ++++++--- src/simix/smx_host_private.h | 3 +-- src/simix/smx_process.c | 3 ++- src/simix/smx_smurf.c | 26 ++++++++++++++++++++------ src/simix/smx_smurf_private.h | 14 +++++++++++--- src/simix/smx_user.c | 6 +++++- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 2308f27d4b..2c47e5c093 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -285,10 +285,13 @@ void SIMIX_host_set_data(smx_host_t host, void *data) host->data = data; } -smx_action_t SIMIX_host_execute(const char *name, smx_host_t host, - double computation_amount, - double priority) +smx_action_t SIMIX_host_execute(u_smx_scalar_t args[]) { + const char *name = args[0].p; + smx_host_t host = args[1].p; + double computation_amount = args[2].d; + double priority = args[3].d; + /* alloc structures and initialize */ smx_action_t action = xbt_mallocator_get(simix_global->action_mallocator); action->type = SIMIX_ACTION_EXECUTE; diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 7da4059a35..fb47a67362 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -37,8 +37,7 @@ xbt_dict_t SIMIX_host_get_properties(smx_host_t host); double SIMIX_host_get_speed(smx_host_t host); double SIMIX_host_get_available_speed(smx_host_t host); int SIMIX_host_get_state(smx_host_t host); -smx_action_t SIMIX_host_execute(const char *name, - smx_host_t host, double computation_amount, double priority); +smx_action_t SIMIX_host_execute(u_smx_scalar_t args[]); smx_action_t SIMIX_host_parallel_execute(const char *name, int host_nb, smx_host_t *host_list, double *computation_amount, double *communication_amount, diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index e9418a4082..8c26267f38 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -444,7 +444,8 @@ smx_action_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer) return NULL; } } else { - return SIMIX_host_execute("suspend", process->smx_host, 0.0, 1.0); + SIMIX_simcall(SIMCALL_HOST_EXECUTE, PTR("suspend"), PTR(process->smx_host), DOUBLE(0.0), DOUBLE(1.0)); + return process->simcall.host_execute.result; } } diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index 8118479123..91c67a4acf 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -272,11 +272,7 @@ void SIMIX_simcall_pre(smx_simcall_t simcall, int value) break; case SIMCALL_HOST_EXECUTE: - simcall->host_execute.result = SIMIX_host_execute( - simcall->host_execute.name, - simcall->host_execute.host, - simcall->host_execute.computation_amount, - simcall->host_execute.priority); + simcall->host_execute.result = simcall_table[simcall->call](simcall->args); SIMIX_simcall_answer(simcall); break; @@ -625,10 +621,28 @@ void SIMIX_simcall_post(smx_action_t action) /* New Simcal interface */ /* FIXME: add types for every simcall */ -const char *simcall_types[NUM_SIMCALLS] = {"%d", "%d%f", "%l"}; +const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p" }; + +simcall_handler_t simcall_table[NUM_SIMCALLS] = {[SIMCALL_HOST_EXECUTE] = &SIMIX_host_execute}; void SIMIX_simcall_typecheck(const char *fmt, ...) { return; } +void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args) +{ + smx_process_t self = SIMIX_process_self(); + self->simcall.call = simcall_id; + self->simcall.args = 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); + } +} diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 91af60dd20..7ba6aec295 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -147,6 +147,8 @@ SIMCALL_LIST typedef struct s_smx_simcall { e_smx_simcall_t call; smx_process_t issuer; + union u_smx_scalar *args; + //FIXME: union u_smx_scalar retval; union { @@ -648,7 +650,7 @@ const char *SIMIX_simcall_name(e_smx_simcall_t kind); /*************************** New simcall interface ****************************/ /* Pack all possible scalar types in an union */ -typedef union { +typedef union u_smx_scalar { char c; short s; int i; @@ -678,6 +680,8 @@ typedef union { #define DOUBLE(x) (d,x) #define PTR(x) (p,x) +#define MYMACRO(...) + /* * Some macro machinery to get a MAP over the arguments of a variadic macro. * It uses a FOLD to apply a macro to every argument, and because there is @@ -704,7 +708,7 @@ typedef union { /* Generate code to initialize the field 'x' with value 'y' of an structure or union */ #define INIT_FIELD_(x,y) {.x = y} -#define INIT_FIELD(t) INIT_FIELD t +#define INIT_FIELD(t) INIT_FIELD_ t /* Project the second element of a tuple */ #define SECOND_(x, y) y @@ -720,7 +724,7 @@ typedef union { */ #define SIMIX_simcall(id, ...) \ SIMIX_simcall_typecheck(simcall_types[id], MAP(SECOND, __VA_ARGS__)); \ - __SIMIX_simcall(id, (mytype_t[]){MAP(INIT_FIELD, __VA_ARGS__)}) + __SIMIX_simcall(id, (u_smx_scalar_t[]){MAP(INIT_FIELD, __VA_ARGS__)}) void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args); @@ -730,6 +734,10 @@ void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args); */ void SIMIX_simcall_typecheck(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +typedef smx_action_t (*simcall_handler_t)(u_smx_scalar_t *); + +extern const char *simcall_types[]; +extern simcall_handler_t simcall_table[]; #endif diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index cf09a36865..db657c15a5 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -204,6 +204,7 @@ void simcall_host_set_data(smx_host_t host, void *data) * \param priority computation priority * \return A new SIMIX execution action */ + smx_action_t simcall_host_execute(const char *name, smx_host_t host, double computation_amount, double priority) @@ -219,9 +220,12 @@ smx_action_t simcall_host_execute(const char *name, smx_host_t host, simcall->host_execute.host = host; simcall->host_execute.computation_amount = computation_amount; simcall->host_execute.priority = priority; + if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */ simcall->host_execute.result = NULL; - SIMIX_simcall_push(simcall->issuer); + + SIMIX_simcall(SIMCALL_HOST_EXECUTE, PTR(name), PTR(host), DOUBLE(computation_amount), DOUBLE(priority)); + return simcall->host_execute.result; } -- 2.20.1