virtual void suspend()=0;
virtual void resume()=0;
+ virtual void post() =0; // What to do when a simcall terminates
void ref();
void unref();
dst_timeout = NULL;
}
}
+
+void simgrid::simix::Comm::post()
+{
+ /* Update synchro state */
+ if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_SRC_TIMEOUT;
+ else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_DST_TIMEOUT;
+ else if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_SRC_HOST_FAILURE;
+ else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_DST_HOST_FAILURE;
+ else if (surf_comm && surf_comm->getState() == simgrid::surf::Action::State::failed) {
+ state = SIMIX_LINK_FAILURE;
+ } else
+ state = SIMIX_DONE;
+
+ XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
+ this, (int)state, src_proc, dst_proc, detached);
+
+ /* destroy the surf actions associated with the Simix communication */
+ cleanupSurf();
+
+ /* if there are simcalls associated with the synchro, then answer them */
+ if (xbt_fifo_size(simcalls))
+ SIMIX_comm_finish(this);
+}
Comm(e_smx_comm_type_t type);
void suspend();
void resume();
+ void post() override;
void cancel();
double remains();
void cleanupSurf(); // FIXME: make me protected
#include "src/simix/SynchroExec.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/smx_host_private.h"
simgrid::simix::Exec::~Exec()
{
return 0;
}
+
+void simgrid::simix::Exec::post()
+{
+ if (host && host->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */
+ /* If the host running the synchro failed, notice it. This way, the asking
+ * process can be killed if it runs on that host itself */
+ state = SIMIX_FAILED;
+ } else if (surf_exec->getState() == simgrid::surf::Action::State::failed) {
+ /* If the host running the synchro didn't fail, then the synchro was canceled */
+ state = SIMIX_CANCELED;
+ } else {
+ state = SIMIX_DONE;
+ }
+
+ if (surf_exec) {
+ surf_exec->unref();
+ surf_exec = NULL;
+ }
+
+ /* If there are simcalls associated with the synchro, then answer them */
+ if (xbt_fifo_size(simcalls))
+ SIMIX_execution_finish(this);
+}
public:
void suspend();
void resume();
+ void post() override;
double remains();
sg_host_t host; /* The host where the execution takes place */
#include "src/simix/SynchroIo.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/popping_private.h"
+#include "src/simix/smx_private.h"
void simgrid::simix::Io::suspend()
{
if (surf_io)
surf_io->resume();
}
+
+void simgrid::simix::Io::post()
+{
+ xbt_fifo_item_t i;
+ smx_simcall_t simcall;
+
+ xbt_fifo_foreach(simcalls,i,simcall,smx_simcall_t) {
+ switch (simcall->call) {
+ case SIMCALL_FILE_OPEN: {
+ smx_file_t tmp = xbt_new(s_smx_file_t,1);
+ tmp->surf_file = surf_storage_action_get_file(surf_io);
+ simcall_file_open__set__result(simcall, tmp);
+ break;
+ }
+ case SIMCALL_FILE_CLOSE:
+ xbt_free(simcall_file_close__get__fd(simcall));
+ simcall_file_close__set__result(simcall, 0);
+ break;
+ case SIMCALL_FILE_WRITE:
+ simcall_file_write__set__result(simcall, surf_io->getCost());
+ break;
+
+ case SIMCALL_FILE_READ:
+ simcall_file_read__set__result(simcall, surf_io->getCost());
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ switch (surf_io->getState()) {
+
+ case simgrid::surf::Action::State::failed:
+ state = SIMIX_FAILED;
+ break;
+
+ case simgrid::surf::Action::State::done:
+ state = SIMIX_DONE;
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ break;
+ }
+
+ SIMIX_io_finish(this);
+}
public:
void suspend();
void resume();
+ void post() override;
sg_host_t host;
surf_action_t surf_io;
#include "src/simix/SynchroRaw.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/smx_synchro_private.h"
-void simgrid::simix::Raw::suspend() {
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_synchro);
+
+void simgrid::simix::Raw::suspend()
+{
/* The suspension of raw synchros is delayed to when the process is rescheduled. */
}
-void simgrid::simix::Raw::resume() {
+void simgrid::simix::Raw::resume()
+{
/* I cannot resume raw synchros directly. This is delayed to when the process is rescheduled at
* the end of the synchro. */
}
+void simgrid::simix::Raw::post()
+{
+ XBT_IN("(%p)",this);
+ if (sleep->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_FAILED;
+ else if(sleep->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_SRC_TIMEOUT;
+
+ SIMIX_synchro_finish(this);
+ XBT_OUT();
+}
public:
void suspend();
void resume();
+ void post() override;
surf_action_t sleep;
};
#include "src/simix/SynchroSleep.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/popping_private.h"
+#include "src/simix/smx_process_private.h"
-void simgrid::simix::Sleep::suspend() {
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
+
+void simgrid::simix::Sleep::suspend()
+{
surf_sleep->suspend();
}
-void simgrid::simix::Sleep::resume() {
+void simgrid::simix::Sleep::resume()
+{
surf_sleep->resume();
}
+
+void simgrid::simix::Sleep::post()
+{
+ smx_simcall_t simcall;
+ e_smx_state_t state;
+
+ while ((simcall = (smx_simcall_t) xbt_fifo_shift(simcalls))) {
+
+ switch (surf_sleep->getState()){
+ case simgrid::surf::Action::State::failed:
+ simcall->issuer->context->iwannadie = 1;
+ //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+ state = SIMIX_SRC_HOST_FAILURE;
+ break;
+
+ case simgrid::surf::Action::State::done:
+ state = SIMIX_DONE;
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ break;
+ }
+ if (simcall->issuer->host->isOff()) {
+ simcall->issuer->context->iwannadie = 1;
+ }
+ simcall_process_sleep__set__result(simcall, state);
+ simcall->issuer->waiting_synchro = NULL;
+ if (simcall->issuer->suspended) {
+ XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
+ simcall->issuer->suspended = 0;
+ simcall_HANDLER_process_suspend(simcall, simcall->issuer);
+ } else {
+ SIMIX_simcall_answer(simcall);
+ }
+ }
+
+ SIMIX_process_sleep_destroy(this);
+}
public:
void suspend();
void resume();
+ void post() override;
sg_host_t host; /* The host that is sleeping */
surf_action_t surf_sleep; /* The Surf sleeping action encapsulated */
void SIMIX_simcall_exit(smx_synchro_t synchro)
{
- simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec*>(synchro);
- if (exec != nullptr) {
- SIMIX_post_host_execute(exec);
- return;
- }
-
- simgrid::simix::Comm *comm = dynamic_cast<simgrid::simix::Comm*>(synchro);
- if (comm != nullptr) {
- SIMIX_post_comm(synchro);
- return;
- }
-
- simgrid::simix::Sleep *sleep = dynamic_cast<simgrid::simix::Sleep*>(synchro);
- if (sleep != nullptr) {
- SIMIX_post_process_sleep(synchro);
- return;
- }
-
- simgrid::simix::Raw *raw = dynamic_cast<simgrid::simix::Raw*>(synchro);
- if (raw != nullptr) {
- SIMIX_post_synchro(synchro);
- return;
- }
-
- simgrid::simix::Io *io = dynamic_cast<simgrid::simix::Io*>(synchro);
- if (io != nullptr) {
- SIMIX_post_io(synchro);
- return;
- }
+ synchro->post();
}
void SIMIX_run_kernel(void* code)
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
-static void SIMIX_execution_finish(simgrid::simix::Exec *exec);
-
/**
* \brief Internal function to create a SIMIX host.
* \param name name of the host to create
exec->unref();
}
-
-void SIMIX_post_host_execute(simgrid::simix::Exec *exec)
-{
- if (exec != nullptr && exec->host && /* FIMXE: handle resource failure for parallel tasks too */
- exec->host->isOff()) {
- /* If the host running the synchro failed, notice it. This way, the asking
- * process can be killed if it runs on that host itself */
- exec->state = SIMIX_FAILED;
- } else if (exec->surf_exec->getState() == simgrid::surf::Action::State::failed) {
- /* If the host running the synchro didn't fail, then the synchro was canceled */
- exec->state = SIMIX_CANCELED;
- } else {
- exec->state = SIMIX_DONE;
- }
-
- if (exec != nullptr && exec->surf_exec) {
- exec->surf_exec->unref();
- exec->surf_exec = NULL;
- }
-
- /* If there are simcalls associated with the synchro, then answer them */
- if (xbt_fifo_size(exec->simcalls))
- SIMIX_execution_finish(exec);
-}
-
-
void SIMIX_set_category(smx_synchro_t synchro, const char *category)
{
if (synchro->state != SIMIX_RUNNING) return;
XBT_PRIVATE void SIMIX_execution_suspend(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_execution_resume(smx_synchro_t synchro);
+XBT_PRIVATE void SIMIX_execution_finish(simgrid::simix::Exec *exec);
-XBT_PRIVATE void SIMIX_post_host_execute(simgrid::simix::Exec *exec);
XBT_PRIVATE void SIMIX_set_category(smx_synchro_t synchro, const char *category);
/* vm related stuff */
void SIMIX_post_io(smx_synchro_t synchro)
{
- xbt_fifo_item_t i;
- smx_simcall_t simcall;
-
- simgrid::simix::Io *io = static_cast<simgrid::simix::Io*>(synchro);
-
- xbt_fifo_foreach(synchro->simcalls,i,simcall,smx_simcall_t) {
- switch (simcall->call) {
- case SIMCALL_FILE_OPEN: {
- smx_file_t tmp = xbt_new(s_smx_file_t,1);
- tmp->surf_file = surf_storage_action_get_file(io->surf_io);
- simcall_file_open__set__result(simcall, tmp);
- break;
- }
- case SIMCALL_FILE_CLOSE:
- xbt_free(simcall_file_close__get__fd(simcall));
- simcall_file_close__set__result(simcall, 0);
- break;
- case SIMCALL_FILE_WRITE:
- simcall_file_write__set__result(simcall, io->surf_io->getCost());
- break;
-
- case SIMCALL_FILE_READ:
- simcall_file_read__set__result(simcall, io->surf_io->getCost());
- break;
-
- default:
- break;
- }
- }
-
- switch (io->surf_io->getState()) {
-
- case simgrid::surf::Action::State::failed:
- synchro->state = SIMIX_FAILED;
- break;
-
- case simgrid::surf::Action::State::done:
- synchro->state = SIMIX_DONE;
- break;
-
- default:
- THROW_IMPOSSIBLE;
- break;
- }
-
- SIMIX_io_finish(synchro);
}
void SIMIX_io_destroy(smx_synchro_t synchro)
static_cast<simgrid::simix::Comm*>(synchro)->unref();
}
-/**
- * \brief This function is called when a Surf communication synchro is finished.
- * \param synchro the corresponding Simix communication
- */
-void SIMIX_post_comm(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- /* Update synchro state */
- if (comm->src_timeout &&
- comm->src_timeout->getState() == simgrid::surf::Action::State::done)
- synchro->state = SIMIX_SRC_TIMEOUT;
- else if (comm->dst_timeout &&
- comm->dst_timeout->getState() == simgrid::surf::Action::State::done)
- synchro->state = SIMIX_DST_TIMEOUT;
- else if (comm->src_timeout &&
- comm->src_timeout->getState() == simgrid::surf::Action::State::failed)
- synchro->state = SIMIX_SRC_HOST_FAILURE;
- else if (comm->dst_timeout &&
- comm->dst_timeout->getState() == simgrid::surf::Action::State::failed)
- synchro->state = SIMIX_DST_HOST_FAILURE;
- else if (comm->surf_comm &&
- comm->surf_comm->getState() == simgrid::surf::Action::State::failed) {
- synchro->state = SIMIX_LINK_FAILURE;
- } else
- synchro->state = SIMIX_DONE;
-
- XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
- comm, (int)comm->state, comm->src_proc, comm->dst_proc, comm->detached);
-
- /* destroy the surf actions associated with the Simix communication */
- comm->cleanupSurf();
-
- /* if there are simcalls associated with the synchro, then answer them */
- if (xbt_fifo_size(synchro->simcalls))
- SIMIX_comm_finish(comm);
-}
-
/******************************************************************************/
/* SIMIX_comm_copy_data callbacks */
/******************************************************************************/
void *data, double rate);
XBT_PRIVATE smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int type, int src,
int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data);
-XBT_PRIVATE void SIMIX_post_comm(smx_synchro_t synchro);
#endif
return synchro;
}
-void SIMIX_post_process_sleep(smx_synchro_t synchro)
-{
- smx_simcall_t simcall;
- e_smx_state_t state;
- simgrid::simix::Sleep *sleep = static_cast<simgrid::simix::Sleep*>(synchro);
-
- while ((simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls))) {
-
- switch (sleep->surf_sleep->getState()){
- case simgrid::surf::Action::State::failed:
- simcall->issuer->context->iwannadie = 1;
- //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
- state = SIMIX_SRC_HOST_FAILURE;
- break;
-
- case simgrid::surf::Action::State::done:
- state = SIMIX_DONE;
- break;
-
- default:
- THROW_IMPOSSIBLE;
- break;
- }
- if (simcall->issuer->host->isOff()) {
- simcall->issuer->context->iwannadie = 1;
- }
- simcall_process_sleep__set__result(simcall, state);
- simcall->issuer->waiting_synchro = NULL;
- if (simcall->issuer->suspended) {
- XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
- simcall->issuer->suspended = 0;
- simcall_HANDLER_process_suspend(simcall, simcall->issuer);
- } else {
- SIMIX_simcall_answer(simcall);
- }
- }
-
- SIMIX_process_sleep_destroy(synchro);
-}
-
void SIMIX_process_sleep_destroy(smx_synchro_t synchro)
{
XBT_DEBUG("Destroy synchro %p", synchro);
XBT_PRIVATE xbt_dict_t SIMIX_process_get_properties(smx_process_t process);
XBT_PRIVATE smx_synchro_t SIMIX_process_join(smx_process_t issuer, smx_process_t process, double timeout);
XBT_PRIVATE smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration);
-XBT_PRIVATE void SIMIX_post_process_sleep(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart);
"SIMIX Synchronization (mutex, semaphores and conditions)");
static smx_synchro_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout);
-static void SIMIX_synchro_finish(smx_synchro_t synchro);
static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
smx_process_t issuer, smx_simcall_t simcall);
static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer,
delete raw;
}
-void SIMIX_post_synchro(smx_synchro_t synchro)
-{
- XBT_IN("(%p)",synchro);
- simgrid::simix::Raw *raw = static_cast<simgrid::simix::Raw*>(synchro);
- if (raw->sleep->getState() == simgrid::surf::Action::State::failed)
- raw->state = SIMIX_FAILED;
- else if(raw->sleep->getState() == simgrid::surf::Action::State::done)
- raw->state = SIMIX_SRC_TIMEOUT;
-
- SIMIX_synchro_finish(raw);
- XBT_OUT();
-}
-
-static void SIMIX_synchro_finish(smx_synchro_t synchro)
+void SIMIX_synchro_finish(smx_synchro_t synchro)
{
XBT_IN("(%p)",synchro);
smx_simcall_t simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls);
#include "xbt/base.h"
#include "xbt/swag.h"
#include "xbt/xbt_os_thread.h"
+#include "src/simix/popping_private.h"
typedef struct s_smx_mutex {
unsigned int locked;
XBT_PRIVATE void SIMIX_post_synchro(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall);
XBT_PRIVATE void SIMIX_synchro_destroy(smx_synchro_t synchro);
+XBT_PRIVATE void SIMIX_synchro_finish(smx_synchro_t synchro);
XBT_PRIVATE smx_mutex_t SIMIX_mutex_init(void);
XBT_PRIVATE int SIMIX_mutex_trylock(smx_mutex_t mutex, smx_process_t issuer);