#include "private.h"
+#include "mc/mc.h"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
+
+static const char* request_names[] = {
+#undef SIMIX_REQ_ENUM_ELEMENT
+#define SIMIX_REQ_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
+SIMIX_REQ_LIST
+#undef SIMIX_REQ_ENUM_ELEMENT
+};
+
/**
* \brief Returns a host given its name.
*
* \return A new SIMIX execution action
*/
smx_action_t SIMIX_req_host_execute(const char *name, smx_host_t host,
- double computation_amount)
+ double computation_amount,
+ double priority)
{
smx_req_t req = SIMIX_req_mine();
req->host_execute.name = name;
req->host_execute.host = host;
req->host_execute.computation_amount = computation_amount;
+ req->host_execute.priority = priority;
SIMIX_request_push();
return req->host_execute.result;
}
}
/**
- * \brief Waits for the completion of an execution action.
+ * \brief Waits for the completion of an execution action and destroy it.
*
* \param execution The execution action
*/
-void SIMIX_req_host_execution_wait(smx_action_t execution)
+e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution)
{
smx_req_t req = SIMIX_req_mine();
req->call = REQ_HOST_EXECUTION_WAIT;
req->host_execution_wait.execution = execution;
SIMIX_request_push();
+ return req->host_execution_wait.result;
}
/**
* \brief Creates and runs a new SIMIX process.
*
- * The structure and the corresponding threada are created and put in the list of ready processes.
+ * The structure and the corresponding thread are created and put in the list of ready processes.
*
+ * \param process the process created will be stored in this pointer
* \param name a name for the process. It is for user-level information and can be NULL.
* \param code the main function of the process
* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code
* \param properties the properties of the process
- * \return The new process
*/
-smx_process_t SIMIX_req_process_create(const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- int argc, char **argv,
- xbt_dict_t properties)
+void SIMIX_req_process_create(smx_process_t *process, const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ int argc, char **argv,
+ xbt_dict_t properties)
{
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_CREATE;
+ req->process_create.process = process;
req->process_create.name = name;
req->process_create.code = code;
req->process_create.data = data;
req->process_create.argv = argv;
req->process_create.properties = properties;
SIMIX_request_push();
- return req->process_create.result;
}
/** \brief Kills a SIMIX process.
SIMIX_request_push();
}
+/** \brief Kills all SIMIX processes.
+ */
+void SIMIX_req_process_killall(void)
+{
+ smx_req_t req = SIMIX_req_mine();
+
+ req->call = REQ_PROCESS_KILLALL;
+ SIMIX_request_push();
+}
+
+/** \brief Cleans up a SIMIX process.
+ * \param process poor victim (must have already been killed)
+ */
+void SIMIX_req_process_cleanup(smx_process_t process)
+{
+ smx_req_t req = SIMIX_req_mine();
+
+ req->call = REQ_PROCESS_CLEANUP;
+ req->process_cleanup.process = process;
+ SIMIX_request_push();
+}
+
/**
* \brief Migrates an agent to another location.
*
*/
void SIMIX_req_process_suspend(smx_process_t process)
{
+ xbt_assert0(process, "Invalid parameters");
+
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_SUSPEND;
*/
void* SIMIX_req_process_get_data(smx_process_t process)
{
+ if (process == SIMIX_process_self()) {
+ /* avoid a request if this function is called by the process itself */
+ return SIMIX_process_self_get_data();
+ }
+
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_GET_DATA;
*/
void SIMIX_req_process_set_data(smx_process_t process, void *data)
{
- smx_req_t req = SIMIX_req_mine();
+ if (process == SIMIX_process_self()) {
+ /* avoid a request if this function is called by the process itself */
+ SIMIX_process_self_set_data(data);
+ }
+ else {
- req->call = REQ_PROCESS_SET_DATA;
- req->process_set_data.process = process;
- req->process_set_data.data = data;
- SIMIX_request_push();
+ smx_req_t req = SIMIX_req_mine();
+
+ req->call = REQ_PROCESS_SET_DATA;
+ req->process_set_data.process = process;
+ req->process_set_data.data = data;
+ SIMIX_request_push();
+ }
}
/**
*/
const char* SIMIX_req_process_get_name(smx_process_t process)
{
+ if (process == SIMIX_process_self()) {
+ /* avoid a request if this function is called by the process itself */
+ return process->name;
+ }
+
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_GET_NAME;
smx_rdv_t SIMIX_req_rdv_get_by_name(const char *name)
{
- smx_req_t req = SIMIX_req_mine();
+ xbt_assert0(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)");
+ /* FIXME: this is a horrible lost of performance, so we hack it out by
+ * skipping the request (for now). It won't work on distributed but
+ * probably we will change MSG for that. */
+/*
+ smx_req_t req = SIMIX_req_mine();
req->call = REQ_RDV_GEY_BY_NAME;
req->rdv_get_by_name.name = name;
SIMIX_request_push();
- return req->rdv_get_by_name.result;
+ return req->rdv_get_by_name.result;*/
+
+ return SIMIX_rdv_get_by_name(name);
}
/**
return req->rdv_get_head.result;
}
+void SIMIX_req_comm_send(smx_rdv_t rdv, double task_size, double rate,
+ void *src_buff, size_t src_buff_size,
+ int (*match_fun)(void *, void *), void *data,
+ double timeout)
+{
+ xbt_assert0(rdv, "No rendez-vous point defined for send");
+
+ if (MC_IS_ENABLED) {
+ /* the model-checker wants two separate requests */
+ smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate,
+ src_buff, src_buff_size, match_fun, data, 0);
+ SIMIX_req_comm_wait(comm, timeout);
+ }
+ else {
+ smx_req_t req = SIMIX_req_mine();
+
+ req->call = REQ_COMM_SEND;
+ req->comm_send.rdv = rdv;
+ req->comm_send.task_size = task_size;
+ req->comm_send.rate = rate;
+ req->comm_send.src_buff = src_buff;
+ req->comm_send.src_buff_size = src_buff_size;
+ req->comm_send.match_fun = match_fun;
+ req->comm_send.data = data;
+ req->comm_send.timeout = timeout;
+
+ SIMIX_request_push();
+ }
+}
+
smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
void *src_buff, size_t src_buff_size,
- int (*match_fun)(void *, void *), void *data)
+ int (*match_fun)(void *, void *), void *data,
+ int detached)
{
- smx_req_t req = SIMIX_req_mine();
-
xbt_assert0(rdv, "No rendez-vous point defined for isend");
+ smx_req_t req = SIMIX_req_mine();
+
req->call = REQ_COMM_ISEND;
req->comm_isend.rdv = rdv;
req->comm_isend.task_size = task_size;
req->comm_isend.src_buff_size = src_buff_size;
req->comm_isend.match_fun = match_fun;
req->comm_isend.data = data;
+ req->comm_isend.detached = detached;
SIMIX_request_push();
return req->comm_isend.result;
}
+void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
+ int (*match_fun)(void *, void *), void *data, double timeout)
+{
+ xbt_assert0(rdv, "No rendez-vous point defined for recv");
+
+ if (MC_IS_ENABLED) {
+ /* the model-checker wants two separate requests */
+ smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size,
+ match_fun, data);
+ SIMIX_req_comm_wait(comm, timeout);
+ }
+ else {
+ smx_req_t req = SIMIX_req_mine();
+
+ req->call = REQ_COMM_RECV;
+ req->comm_recv.rdv = rdv;
+ req->comm_recv.dst_buff = dst_buff;
+ req->comm_recv.dst_buff_size = dst_buff_size;
+ req->comm_recv.match_fun = match_fun;
+ req->comm_recv.data = data;
+ req->comm_recv.timeout = timeout;
+
+ SIMIX_request_push();
+ }
+}
+
smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
- int (*match_fun)(void *, void *), void *data)
+ int (*match_fun)(void *, void *), void *data)
{
- smx_req_t req = SIMIX_req_mine();
+ xbt_assert0(rdv, "No rendez-vous point defined for irecv");
- xbt_assert0(rdv, "No rendez-vous point defined for isend");
+ smx_req_t req = SIMIX_req_mine();
req->call = REQ_COMM_IRECV;
req->comm_irecv.rdv = rdv;
void SIMIX_req_comm_destroy(smx_action_t comm)
{
+ xbt_assert0(comm, "Invalid parameter");
+
+ /* FIXME remove this request type: comms are auto-destroyed now,
+ * but what happens with unfinished comms? */
+
+ /*
smx_req_t req = SIMIX_req_mine();
req->call = REQ_COMM_DESTROY;
req->comm_destroy.comm = comm;
SIMIX_request_push();
+ */
}
void SIMIX_req_comm_cancel(smx_action_t comm)
return req->comm_get_dst_data.result;
}
-void *SIMIX_req_comm_get_src_buff(smx_action_t comm)
-{
- smx_req_t req = SIMIX_req_mine();
-
- req->call = REQ_COMM_GET_SRC_BUFF;
- req->comm_get_src_buff.comm = comm;
-
- SIMIX_request_push();
- return req->comm_get_src_buff.result;
-}
-
-void *SIMIX_req_comm_get_dst_buff(smx_action_t comm)
-{
- smx_req_t req = SIMIX_req_mine();
-
- req->call = REQ_COMM_GET_DST_BUFF;
- req->comm_get_dst_buff.comm = comm;
-
- SIMIX_request_push();
- return req->comm_get_dst_buff.result;
-}
-
-size_t SIMIX_req_comm_get_src_buff_size(smx_action_t comm)
-{
- smx_req_t req = SIMIX_req_mine();
-
- req->call = REQ_COMM_GET_SRC_BUFF_SIZE;
- req->comm_get_src_buff_size.comm = comm;
-
- SIMIX_request_push();
- return req->comm_get_src_buff_size.result;
-}
-
-size_t SIMIX_req_comm_get_dst_buff_size(smx_action_t comm)
-{
- smx_req_t req = SIMIX_req_mine();
-
- req->call = REQ_COMM_GET_DST_BUFF_SIZE;
- req->comm_get_dst_buff_size.comm = comm;
-
- SIMIX_request_push();
- return req->comm_get_dst_buff_size.result;
-}
-
smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm)
{
smx_req_t req = SIMIX_req_mine();
}
/* ************************************************************************** */
-/** @brief gets the result of previous syscall
- *
- * This function is only useful in state machine mechanism.
- *
- * In this case, the execution of every SIMIX_req_* function above was cut at
- * SIMIX_request_push(), which calls yield() which calls suspend(), which longjmp
- * to the point right before running the user code. When the control is passed
- * back to the user, he needs to get the result of the syscall he did.
- * That is why this function is made for.
- *
- * To extend this function, simply make sure that the end of the SIMIX_req_*
- * function matches what is written in this big switch
- */
-void *SIMIX_request_get_result(int kind) {
- smx_req_t req = SIMIX_req_mine();
- switch ((e_smx_req_t) kind) {
- case REQ_NO_REQ:
- xbt_die("There is no request waiting, cannot provide the result");
- case REQ_HOST_GET_BY_NAME:
- return req->host_get_by_name.result;
- case REQ_HOST_GET_NAME:
- return (void*)req->host_get_name.result;
- case REQ_HOST_GET_PROPERTIES:
- return req->host_get_properties.result;
- case REQ_HOST_GET_SPEED:
- return &req->host_get_speed.result; /* double */
- case REQ_HOST_GET_AVAILABLE_SPEED:
- return &req->host_get_available_speed.result; /* double */
- case REQ_HOST_GET_STATE:
- return &req->host_get_state.result; /* int */
- case REQ_HOST_GET_DATA:
- return req->host_get_data.result;
- case REQ_HOST_SET_DATA:
- return NULL; /* void */
- case REQ_HOST_EXECUTE:
- return req->host_execute.result;
- case REQ_HOST_PARALLEL_EXECUTE:
- return req->host_parallel_execute.result;
- case REQ_HOST_EXECUTION_DESTROY:
- return NULL; /* void */
- case REQ_HOST_EXECUTION_CANCEL:
- return NULL; /* void */
- case REQ_HOST_EXECUTION_GET_REMAINS:
- return &req->host_execution_get_remains.result; /* double */
- case REQ_HOST_EXECUTION_GET_STATE:
- return &req->host_execution_get_state.result; /* e_smx_state_t */
- case REQ_HOST_EXECUTION_SET_PRIORITY:
- return NULL; /* void */
- case REQ_HOST_EXECUTION_WAIT:
- return NULL; /* void */
- case REQ_PROCESS_CREATE:
- return req->process_create.result;
- case REQ_PROCESS_KILL:
- return NULL; /* void */
- case REQ_PROCESS_CHANGE_HOST:
- return NULL; /* void */
- case REQ_PROCESS_SUSPEND:
- return NULL; /* void */
- case REQ_PROCESS_RESUME:
- return NULL; /* void */
- case REQ_PROCESS_COUNT:
- return &req->process_count.result; /* int */
- case REQ_PROCESS_GET_DATA:
- return req->process_get_data.result;
- case REQ_PROCESS_SET_DATA:
- return NULL; /* void */
- case REQ_PROCESS_GET_HOST:
- return req->process_get_host.result;
- case REQ_PROCESS_GET_NAME:
- return (void*)req->process_get_name.result;
- case REQ_PROCESS_IS_SUSPENDED:
- return &req->process_is_suspended.result; /* int */
- case REQ_PROCESS_GET_PROPERTIES:
- return req->process_get_properties.result;
- case REQ_PROCESS_SLEEP:
- return &req->process_sleep.result; /* e_smx_state_t */
- case REQ_RDV_CREATE:
- return req->rdv_create.result;
- case REQ_RDV_DESTROY:
- return NULL; /* void */
- case REQ_RDV_GEY_BY_NAME:
- return req->rdv_get_by_name.result;
- case REQ_RDV_COMM_COUNT_BY_HOST:
- return &req->rdv_comm_count_by_host.result; /* int */
- case REQ_RDV_GET_HEAD:
- return req->rdv_get_head.result;
- case REQ_COMM_ISEND:
- return req->comm_isend.result;
- case REQ_COMM_IRECV:
- return req->comm_irecv.result;
- case REQ_COMM_DESTROY:
- case REQ_COMM_CANCEL:
- return NULL; /* void */
- case REQ_COMM_WAITANY:
- return &req->comm_waitany.result;
- case REQ_COMM_TESTANY:
- return &req->comm_testany.result;
- case REQ_COMM_WAIT:
- return NULL; /* void */
-
-#ifdef HAVE_TRACING
- case REQ_SET_CATEGORY:
- return NULL; /* void */
-#endif
-
- case REQ_COMM_TEST:
- return &req->comm_test.result; /* int */
- case REQ_COMM_GET_REMAINS:
- return &req->comm_get_remains.result; /* double */
- case REQ_COMM_GET_STATE:
- return &req->comm_get_state.result; /* e_smx_state_t */
- case REQ_COMM_GET_SRC_DATA:
- return req->comm_get_src_data.result;
- case REQ_COMM_GET_DST_DATA:
- return req->comm_get_dst_data.result;
- case REQ_COMM_GET_SRC_BUFF:
- return req->comm_get_src_buff.result;
- case REQ_COMM_GET_DST_BUFF:
- return req->comm_get_dst_buff.result;
- case REQ_COMM_GET_SRC_BUFF_SIZE:
- return &req->comm_get_src_buff_size.result; /* size_t */
- case REQ_COMM_GET_DST_BUFF_SIZE:
- return &req->comm_get_dst_buff_size.result; /* size_t */
- case REQ_COMM_GET_SRC_PROC:
- return req->comm_get_src_proc.result;
- case REQ_COMM_GET_DST_PROC:
- return req->comm_get_dst_proc.result;
-
- #ifdef HAVE_LATENCY_BOUND_TRACKING
- case REQ_COMM_IS_LATENCY_BOUNDED:
- return &req->comm_is_latency_bounded.result; /* int */
- #endif
-
- case REQ_MUTEX_INIT:
- return req->mutex_init.result;
- case REQ_MUTEX_DESTROY:
- case REQ_MUTEX_LOCK:
- case REQ_MUTEX_UNLOCK:
- return NULL; /* void */
-
- case REQ_MUTEX_TRYLOCK:
- return &req->mutex_trylock.result; /* int */
-
- case REQ_COND_INIT:
- return req->cond_init.result;
- case REQ_COND_DESTROY:
- case REQ_COND_SIGNAL:
- case REQ_COND_WAIT:
- case REQ_COND_WAIT_TIMEOUT:
- case REQ_COND_BROADCAST:
- return NULL; /* void */
-
- case REQ_SEM_INIT:
- return req->sem_init.result;
- case REQ_SEM_DESTROY:
- case REQ_SEM_RELEASE:
- case REQ_SEM_ACQUIRE:
- case REQ_SEM_ACQUIRE_TIMEOUT:
- return NULL; /* void */
-
- case REQ_SEM_WOULD_BLOCK:
- return &req->sem_would_block.result; /* int */
- case REQ_SEM_GET_CAPACITY:
- return &req->sem_get_capacity.result; /* int */
- }
- THROW_IMPOSSIBLE;
-}
-/** @brief returns the id of the lastly done syscall
- * Mainly (only?) useful for statemachine contextes
- */
-int SIMIX_request_last_id() {
- return SIMIX_req_mine()->call;
+/** @brief returns a printable string representing the request kind */
+const char *SIMIX_request_name(int kind) {
+ return request_names[kind];
}