-/* Copyright (c) 2009-2014. The SimGrid Team.
+/* Copyright (c) 2009-2015. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "smx_private.h"
#include "xbt/log.h"
#include "mc/mc.h"
+#include "mc/mc_replay.h"
#include "xbt/dict.h"
-#include "smpi/private.h"
-
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix,
"SIMIX network-related synchronization");
/* Rendez-Vous Points */
/******************************************************************************/
-smx_rdv_t simcall_HANDLER_rdv_create(smx_simcall_t simcall, const char *name){
- return SIMIX_rdv_create(name);
-}
smx_rdv_t SIMIX_rdv_create(const char *name)
{
/* two processes may have pushed the same rdv_create simcall at the same time */
return rdv;
}
-void simcall_HANDLER_rdv_destroy(smx_simcall_t simcall, smx_rdv_t rdv){
- return SIMIX_rdv_destroy(rdv);
-}
void SIMIX_rdv_destroy(smx_rdv_t rdv)
{
if (rdv->name)
return xbt_dict_get_or_null(rdv_points, name);
}
-unsigned int simcall_HANDLER_rdv_comm_count_by_host(smx_simcall_t simcall, smx_rdv_t rdv, smx_host_t host){
- return SIMIX_rdv_comm_count_by_host(rdv, host);
-}
-int SIMIX_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
+int SIMIX_rdv_comm_count_by_host(smx_rdv_t rdv, sg_host_t host)
{
smx_synchro_t comm = NULL;
xbt_fifo_item_t item = NULL;
int count = 0;
xbt_fifo_foreach(rdv->comm_fifo, item, comm, smx_synchro_t) {
- if (comm->comm.src_proc->smx_host == host)
+ if (comm->comm.src_proc->host == host)
count++;
}
return count;
}
-smx_synchro_t simcall_HANDLER_rdv_get_head(smx_simcall_t simcall, smx_rdv_t rdv){
- return SIMIX_rdv_get_head(rdv);
-}
smx_synchro_t SIMIX_rdv_get_head(smx_rdv_t rdv)
{
return xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo));
}
-smx_process_t simcall_HANDLER_rdv_get_receiver(smx_simcall_t simcall, smx_rdv_t rdv){
- return SIMIX_rdv_get_receiver(rdv);
-}
/**
* \brief get the receiver (process associated to the mailbox)
* \param rdv The rendez-vous point
return rdv->permanent_receiver;
}
-void simcall_HANDLER_rdv_set_receiver(smx_simcall_t simcall, smx_rdv_t rdv,
- smx_process_t process){
- SIMIX_rdv_set_receiver(rdv, process);
-}
/**
* \brief set the receiver of the rendez vous point to allow eager sends
* \param rdv The rendez-vous point
synchro->latency_limited = -1;
#endif
-#ifdef HAVE_TRACING
synchro->category = NULL;
-#endif
XBT_DEBUG("Create communicate synchro %p", synchro);
++smx_total_comms;
int (*match_fun)(void *, void *,smx_synchro_t),
void (*copy_data_fun)(smx_synchro_t, void*, size_t),
void *data, double timeout){
- smx_synchro_t comm = SIMIX_comm_isend(src, rdv, task_size, rate,
+ smx_synchro_t comm = simcall_HANDLER_comm_isend(simcall, src, rdv, task_size, rate,
src_buff, src_buff_size, match_fun, NULL, copy_data_fun,
data, 0);
SIMCALL_SET_MC_VALUE(simcall, 0);
simcall_HANDLER_comm_wait(simcall, comm, timeout);
}
-smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t src, smx_rdv_t rdv,
+smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t src_proc, smx_rdv_t rdv,
double task_size, double rate,
void *src_buff, size_t src_buff_size,
int (*match_fun)(void *, void *,smx_synchro_t),
- void (*clean_fun)(void *),
- void (*copy_data_fun)(smx_synchro_t, void*, size_t),
- void *data, int detached){
- return SIMIX_comm_isend(src, rdv, task_size, rate, src_buff,
- src_buff_size, match_fun, clean_fun, copy_data_fun, data, detached);
-
-}
-smx_synchro_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
- double task_size, double rate,
- void *src_buff, size_t src_buff_size,
- int (*match_fun)(void *, void *,smx_synchro_t),
- void (*clean_fun)(void *), // used to free the synchro in case of problem after a detached send
- void (*copy_data_fun)(smx_synchro_t, void*, size_t), // used to copy data if not default one
- void *data,
- int detached)
+ void (*clean_fun)(void *), // used to free the synchro in case of problem after a detached send
+ void (*copy_data_fun)(smx_synchro_t, void*, size_t),// used to copy data if not default one
+ void *data, int detached)
{
XBT_DEBUG("send from %p", rdv);
other_synchro->comm.copy_data_fun = copy_data_fun;
- if (MC_is_active()) {
+ if (MC_is_active() || MC_record_replay_is_active()) {
other_synchro->state = SIMIX_RUNNING;
return (detached ? NULL : other_synchro);
}
return (detached ? NULL : other_synchro);
}
-void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_rdv_t rdv,
+void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_process_t receiver, smx_rdv_t rdv,
void *dst_buff, size_t *dst_buff_size,
int (*match_fun)(void *, void *, smx_synchro_t),
void (*copy_data_fun)(smx_synchro_t, void*, size_t),
void *data, double timeout, double rate)
{
- smx_synchro_t comm = SIMIX_comm_irecv(simcall->issuer, rdv, dst_buff,
+ smx_synchro_t comm = SIMIX_comm_irecv(receiver, rdv, dst_buff,
dst_buff_size, match_fun, copy_data_fun, data, rate);
SIMCALL_SET_MC_VALUE(simcall, 0);
simcall_HANDLER_comm_wait(simcall, comm, timeout);
}
-smx_synchro_t simcall_HANDLER_comm_irecv(smx_simcall_t simcall, smx_rdv_t rdv,
+smx_synchro_t simcall_HANDLER_comm_irecv(smx_simcall_t simcall, smx_process_t receiver, smx_rdv_t rdv,
void *dst_buff, size_t *dst_buff_size,
int (*match_fun)(void *, void *, smx_synchro_t),
void (*copy_data_fun)(smx_synchro_t, void*, size_t),
void *data, double rate)
{
- return SIMIX_comm_irecv(simcall->issuer, rdv, dst_buff, dst_buff_size,
+ return SIMIX_comm_irecv(receiver, rdv, dst_buff, dst_buff_size,
match_fun, copy_data_fun, data, rate);
}
SIMIX_comm_copy_data(other_synchro);*/
- if (MC_is_active()) {
+ if (MC_is_active() || MC_record_replay_is_active()) {
other_synchro->state = SIMIX_RUNNING;
return other_synchro;
}
xbt_fifo_push(synchro->simcalls, simcall);
simcall->issuer->waiting_synchro = synchro;
- if (MC_is_active()) {
+ if (MC_is_active() || MC_record_replay_is_active()) {
int idx = SIMCALL_GET_MC_VALUE(simcall);
if (idx == 0) {
synchro->state = SIMIX_DONE;
if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) {
SIMIX_comm_finish(synchro);
} else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
- sleep = surf_workstation_sleep(simcall->issuer->smx_host, timeout);
+ sleep = surf_host_sleep(simcall->issuer->host, timeout);
surf_action_set_data(sleep, synchro);
if (simcall->issuer == synchro->comm.src_proc)
void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_synchro_t synchro)
{
- if(MC_is_active()){
+ if(MC_is_active() || MC_record_replay_is_active()){
simcall_comm_test__set__result(simcall, synchro->comm.src_proc && synchro->comm.dst_proc);
if(simcall_comm_test__get__result(simcall)){
synchro->state = SIMIX_DONE;
smx_synchro_t synchro;
simcall_comm_testany__set__result(simcall, -1);
- if (MC_is_active()){
+ if (MC_is_active() || MC_record_replay_is_active()){
int idx = SIMCALL_GET_MC_VALUE(simcall);
if(idx == -1){
SIMIX_simcall_answer(simcall);
smx_synchro_t synchro;
unsigned int cursor = 0;
- if (MC_is_active()){
+ if (MC_is_active() || MC_record_replay_is_active()){
int idx = SIMCALL_GET_MC_VALUE(simcall);
synchro = xbt_dynar_get_as(synchros, idx, smx_synchro_t);
xbt_fifo_push(synchro->simcalls, simcall);
/* If both the sender and the receiver are already there, start the communication */
if (synchro->state == SIMIX_READY) {
- smx_host_t sender = synchro->comm.src_proc->smx_host;
- smx_host_t receiver = synchro->comm.dst_proc->smx_host;
+ sg_host_t sender = synchro->comm.src_proc->host;
+ sg_host_t receiver = synchro->comm.dst_proc->host;
XBT_DEBUG("Starting communication %p from '%s' to '%s'", synchro,
SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
- synchro->comm.surf_comm = surf_workstation_model_communicate(surf_workstation_model,
+ synchro->comm.surf_comm = surf_network_model_communicate(surf_network_model,
sender, receiver,
synchro->comm.task_size, synchro->comm.rate);
if (SIMIX_process_is_suspended(synchro->comm.src_proc))
XBT_DEBUG("The communication is suspended on startup because src (%s:%s) were suspended since it initiated the communication",
- SIMIX_host_get_name(synchro->comm.src_proc->smx_host), synchro->comm.src_proc->name);
+ SIMIX_host_get_name(synchro->comm.src_proc->host), synchro->comm.src_proc->name);
else
XBT_DEBUG("The communication is suspended on startup because dst (%s:%s) were suspended since it initiated the communication",
- SIMIX_host_get_name(synchro->comm.dst_proc->smx_host), synchro->comm.dst_proc->name);
+ SIMIX_host_get_name(synchro->comm.dst_proc->host), synchro->comm.dst_proc->name);
surf_action_suspend(synchro->comm.surf_comm);
unsigned int destroy_count = 0;
smx_simcall_t simcall;
-
while ((simcall = xbt_fifo_shift(synchro->simcalls))) {
/* If a waitany simcall is waiting for this synchro to finish, then remove
continue; // if process handling comm is killed
if (simcall->call == SIMCALL_COMM_WAITANY) {
SIMIX_waitany_remove_simcall_from_actions(simcall);
- if (!MC_is_active())
+ if (!MC_is_active() && !MC_record_replay_is_active())
simcall_comm_waitany__set__result(simcall, xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro));
}
XBT_DEBUG("SIMIX_comm_finish: synchro state = %d", (int)synchro->state);
/* Check out for errors */
+
+ if (surf_host_get_state(surf_host_resource_priv(
+ simcall->issuer->host)) != SURF_RESOURCE_ON) {
+ simcall->issuer->context->iwannadie = 1;
+ SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+ } else
+
switch (synchro->state) {
case SIMIX_DONE:
break;
case SIMIX_LINK_FAILURE:
+
XBT_DEBUG("Link failure in synchro %p between '%s' and '%s': posting an exception to the issuer: %s (%p) detached:%d",
synchro,
- synchro->comm.src_proc ? sg_host_name(synchro->comm.src_proc->smx_host) : NULL,
- synchro->comm.dst_proc ? sg_host_name(synchro->comm.dst_proc->smx_host) : NULL,
+ synchro->comm.src_proc ? sg_host_name(synchro->comm.src_proc->host) : NULL,
+ synchro->comm.dst_proc ? sg_host_name(synchro->comm.dst_proc->host) : NULL,
simcall->issuer->name, simcall->issuer, synchro->comm.detached);
if (synchro->comm.src_proc == simcall->issuer) {
XBT_DEBUG("I'm source");
}
}
- if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
+ if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->host)) != SURF_RESOURCE_ON) {
simcall->issuer->context->iwannadie = 1;
}
}
}
-void simcall_HANDLER_comm_cancel(smx_simcall_t simcall, smx_synchro_t synchro){
- SIMIX_comm_cancel(synchro);
-}
void SIMIX_comm_cancel(smx_synchro_t synchro)
{
/* if the synchro is a waiting state means that it is still in a rdv */
synchro->state = SIMIX_CANCELED;
}
else if (!MC_is_active() /* when running the MC there are no surf actions */
+ && !MC_record_replay_is_active()
&& (synchro->state == SIMIX_READY || synchro->state == SIMIX_RUNNING)) {
surf_action_cancel(synchro->comm.surf_comm);
/************* synchro Getters **************/
-double simcall_HANDLER_comm_get_remains(smx_simcall_t simcall, smx_synchro_t synchro){
- return SIMIX_comm_get_remains(synchro);
-}
/**
* \brief get the amount remaining from the communication
* \param synchro The communication
return remains;
}
-e_smx_state_t simcall_HANDLER_comm_get_state(smx_simcall_t simcall, smx_synchro_t synchro){
- return SIMIX_comm_get_state(synchro);
-}
e_smx_state_t SIMIX_comm_get_state(smx_synchro_t synchro)
{
return synchro->state;
}
-void* simcall_HANDLER_comm_get_src_data(smx_simcall_t simcall, smx_synchro_t synchro){
- return SIMIX_comm_get_src_data(synchro);
-}
/**
* \brief Return the user data associated to the sender of the communication
* \param synchro The communication
return synchro->comm.src_data;
}
-void* simcall_HANDLER_comm_get_dst_data(smx_simcall_t simcall, smx_synchro_t synchro){
- return SIMIX_comm_get_dst_data(synchro);
-}
/**
* \brief Return the user data associated to the receiver of the communication
* \param synchro The communication
return synchro->comm.dst_data;
}
-smx_process_t simcall_HANDLER_comm_get_src_proc(smx_simcall_t simcall, smx_synchro_t synchro){
- return SIMIX_comm_get_src_proc(synchro);
-}
smx_process_t SIMIX_comm_get_src_proc(smx_synchro_t synchro)
{
return synchro->comm.src_proc;
}
-smx_process_t simcall_HANDLER_comm_get_dst_proc(smx_simcall_t simcall, smx_synchro_t synchro){
- return SIMIX_comm_get_dst_proc(synchro);
-}
smx_process_t SIMIX_comm_get_dst_proc(smx_synchro_t synchro)
{
return synchro->comm.dst_proc;
}
#ifdef HAVE_LATENCY_BOUND_TRACKING
-int simcall_HANDLER_comm_is_latency_bounded(smx_simcall_t simcall, smx_synchro_t synchro)
-{
- return SIMIX_comm_is_latency_bounded(synchro);
-}
-
/**
* \brief verify if communication is latency bounded
* \param comm The communication
XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)",
comm,
- comm->comm.src_proc ? sg_host_name(comm->comm.src_proc->smx_host) : "a finished process",
+ comm->comm.src_proc ? sg_host_name(comm->comm.src_proc->host) : "a finished process",
comm->comm.src_buff,
- comm->comm.dst_proc ? sg_host_name(comm->comm.dst_proc->smx_host) : "a finished process",
+ comm->comm.dst_proc ? sg_host_name(comm->comm.dst_proc->host) : "a finished process",
comm->comm.dst_buff, buff_size);
/* Copy at most dst_buff_size bytes of the message to receiver's buffer */