Commit 3ea82f7e authored by Fred Suter's avatar Fred Suter

e_smx_state_t is now kernel::activity::State

parent 55160521
......@@ -98,6 +98,7 @@ typedef boost::intrusive_ptr<ActorImpl> ActorImplPtr;
namespace activity {
class ActivityImpl;
enum class State;
typedef boost::intrusive_ptr<ActivityImpl> ActivityImplPtr;
XBT_PUBLIC void intrusive_ptr_add_ref(ActivityImpl* activity);
XBT_PUBLIC void intrusive_ptr_release(ActivityImpl* activity);
......@@ -198,7 +199,7 @@ typedef simgrid::kernel::activity::ConditionVariableImpl* smx_cond_t;
typedef simgrid::kernel::activity::MailboxImpl* smx_mailbox_t;
typedef simgrid::kernel::activity::MutexImpl* smx_mutex_t;
typedef simgrid::kernel::activity::SemaphoreImpl* smx_sem_t;
typedef simgrid::kernel::activity::State e_smx_state_t;
#else
typedef struct s4u_Actor s4u_Actor;
......@@ -214,6 +215,7 @@ typedef struct s4u_Storage s4u_Storage;
typedef struct s4u_NetZone s4u_NetZone;
typedef struct s4u_VM s4u_VM;
typedef struct kernel_Activity* smx_activity_t;
typedef enum kernel_activity_state e_smx_state_t;
typedef struct s_smx_timer* smx_timer_t;
typedef struct s_smx_actor* smx_actor_t;
......
......@@ -17,35 +17,6 @@
#include <vector>
#endif
/* ******************************** Host ************************************ */
/** @brief Host datatype
@ingroup simix_host_management
A <em>location</em> (or <em>host</em>) is any possible place where
a process may run. Thus it is represented as a <em>physical
resource with computing capabilities</em>, some <em>mailboxes</em>
to enable running process to communicate with remote ones, and
some <em>private data</em> that can be only accessed by local
process.
@see m_host_management
@{ */
typedef enum {
SIMIX_WAITING,
SIMIX_READY,
SIMIX_RUNNING,
SIMIX_DONE,
SIMIX_CANCELED,
SIMIX_FAILED,
SIMIX_SRC_HOST_FAILURE,
SIMIX_DST_HOST_FAILURE,
SIMIX_TIMEOUT,
SIMIX_SRC_TIMEOUT,
SIMIX_DST_TIMEOUT,
SIMIX_LINK_FAILURE
} e_smx_state_t;
/** @} */
/******************************* Networking ***********************************/
extern unsigned smx_context_stack_size;
extern unsigned smx_context_guard_size;
......
......@@ -60,7 +60,7 @@ void ActivityImpl::cancel()
XBT_VERB("Activity %p is canceled", this);
if (surf_action_ != nullptr)
surf_action_->cancel();
state_ = SIMIX_CANCELED;
state_ = State::CANCELED;
}
// boost::intrusive_ptr<Activity> support:
......
......@@ -19,13 +19,27 @@
namespace simgrid {
namespace kernel {
namespace activity {
enum class State {
WAITING = 0,
READY,
RUNNING,
DONE,
CANCELED,
FAILED,
SRC_HOST_FAILURE,
DST_HOST_FAILURE,
TIMEOUT,
SRC_TIMEOUT,
DST_TIMEOUT,
LINK_FAILURE
};
class XBT_PUBLIC ActivityImpl {
std::atomic_int_fast32_t refcount_{0};
public:
virtual ~ActivityImpl();
ActivityImpl() = default;
e_smx_state_t state_ = SIMIX_WAITING; /* State of the activity */
State state_ = State::WAITING; /* State of the activity */
std::list<smx_simcall_t> simcalls_; /* List of simcalls waiting for this activity */
resource::Action* surf_action_ = nullptr;
......
This diff is collapsed.
......@@ -26,19 +26,20 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, simgrid::kernel::acti
/* set surf's synchro */
if (MC_is_active() || MC_record_replay_is_active()) {
synchro->state_ = SIMIX_DONE;
synchro->state_ = simgrid::kernel::activity::State::DONE;
synchro->finish();
return;
}
/* If the synchro is already finished then perform the error handling */
if (synchro->state_ != SIMIX_RUNNING)
if (synchro->state_ != simgrid::kernel::activity::State::RUNNING)
synchro->finish();
}
void simcall_HANDLER_execution_test(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl* synchro)
{
bool res = (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING);
bool res = (synchro->state_ != simgrid::kernel::activity::State::WAITING &&
synchro->state_ != simgrid::kernel::activity::State::RUNNING);
if (res) {
synchro->simcalls_.push_back(simcall);
synchro->finish();
......@@ -73,7 +74,8 @@ void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, simgrid::kerne
exec->simcalls_.push_back(simcall);
/* see if the synchro is already finished */
if (exec->state_ != SIMIX_WAITING && exec->state_ != SIMIX_RUNNING) {
if (exec->state_ != simgrid::kernel::activity::State::WAITING &&
exec->state_ != simgrid::kernel::activity::State::RUNNING) {
exec->finish();
break;
}
......@@ -137,7 +139,7 @@ ExecImpl& ExecImpl::set_bytes_amounts(const std::vector<double>& bytes_amounts)
ExecImpl* ExecImpl::start()
{
state_ = SIMIX_RUNNING;
state_ = State::RUNNING;
if (not MC_is_active() && not MC_record_replay_is_active()) {
if (hosts_.size() == 1) {
surf_action_ = hosts_.front()->pimpl_cpu->execution_start(flops_amounts_.front());
......@@ -184,14 +186,14 @@ void ExecImpl::post()
if (hosts_.size() == 1 && not hosts_.front()->is_on()) { /* FIXME: 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;
state_ = State::FAILED;
} else if (surf_action_ && surf_action_->get_state() == resource::Action::State::FAILED) {
/* If the host running the synchro didn't fail, then the synchro was canceled */
state_ = SIMIX_CANCELED;
state_ = State::CANCELED;
} else if (timeout_detector_ && timeout_detector_->get_state() == resource::Action::State::FINISHED) {
state_ = SIMIX_TIMEOUT;
state_ = State::TIMEOUT;
} else {
state_ = SIMIX_DONE;
state_ = State::DONE;
}
clean_action();
......@@ -243,12 +245,12 @@ void ExecImpl::finish()
switch (state_) {
case SIMIX_DONE:
case State::DONE:
/* do nothing, synchro done */
XBT_DEBUG("ExecImpl::finish(): execution successful");
break;
case SIMIX_FAILED:
case State::FAILED:
XBT_DEBUG("ExecImpl::finish(): host '%s' failed", simcall->issuer_->get_host()->get_cname());
simcall->issuer_->context_->iwannadie = true;
if (simcall->issuer_->get_host()->is_on())
......@@ -257,13 +259,13 @@ void ExecImpl::finish()
/* else, the actor will be killed with no possibility to survive */
break;
case SIMIX_CANCELED:
case State::CANCELED:
XBT_DEBUG("ExecImpl::finish(): execution canceled");
simcall->issuer_->exception_ =
std::make_exception_ptr(simgrid::CancelException(XBT_THROW_POINT, "Execution Canceled"));
break;
case SIMIX_TIMEOUT:
case State::TIMEOUT:
XBT_DEBUG("ExecImpl::finish(): execution timeouted");
simcall->issuer_->exception_ = std::make_exception_ptr(simgrid::TimeoutException(XBT_THROW_POINT, "Timeouted"));
break;
......
......@@ -22,10 +22,10 @@ void simcall_HANDLER_io_wait(smx_simcall_t simcall, simgrid::kernel::activity::I
synchro->register_simcall(simcall);
if (MC_is_active() || MC_record_replay_is_active())
synchro->state_ = SIMIX_DONE;
synchro->state_ = simgrid::kernel::activity::State::DONE;
/* If the synchro is already finished then perform the error handling */
if (synchro->state_ != SIMIX_RUNNING)
if (synchro->state_ != simgrid::kernel::activity::State::RUNNING)
synchro->finish();
}
......@@ -59,7 +59,7 @@ IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
IoImpl* IoImpl::start()
{
state_ = SIMIX_RUNNING;
state_ = State::RUNNING;
if (storage_)
surf_action_ = storage_->io_start(size_, type_);
else
......@@ -77,11 +77,11 @@ void IoImpl::post()
performed_ioops_ = surf_action_->get_cost();
if (surf_action_->get_state() == resource::Action::State::FAILED) {
if ((storage_ && not storage_->is_on()) || (disk_ && not disk_->is_on()))
state_ = SIMIX_FAILED;
state_ = State::FAILED;
else
state_ = SIMIX_CANCELED;
state_ = State::CANCELED;
} else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
state_ = SIMIX_DONE;
state_ = State::DONE;
}
on_completion(*this);
......@@ -95,15 +95,15 @@ void IoImpl::finish()
smx_simcall_t simcall = simcalls_.front();
simcalls_.pop_front();
switch (state_) {
case SIMIX_DONE:
case State::DONE:
/* do nothing, synchro done */
break;
case SIMIX_FAILED:
case State::FAILED:
simcall->issuer_->context_->iwannadie = true;
simcall->issuer_->exception_ =
std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
break;
case SIMIX_CANCELED:
case State::CANCELED:
simcall->issuer_->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
break;
default:
......
......@@ -42,11 +42,11 @@ void SleepImpl::post()
{
if (surf_action_->get_state() == resource::Action::State::FAILED) {
if (host_ && not host_->is_on())
state_ = SIMIX_SRC_HOST_FAILURE;
state_ = State::SRC_HOST_FAILURE;
else
state_ = SIMIX_CANCELED;
state_ = State::CANCELED;
} else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
state_ = SIMIX_DONE;
state_ = State::DONE;
}
/* Answer all simcalls associated with the synchro */
finish();
......
......@@ -57,9 +57,9 @@ void RawImpl::cancel()
void RawImpl::post()
{
if (surf_action_->get_state() == resource::Action::State::FAILED) {
state_ = SIMIX_FAILED;
state_ = State::FAILED;
} else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
state_ = SIMIX_SRC_TIMEOUT;
state_ = State::SRC_TIMEOUT;
}
finish();
}
......@@ -69,11 +69,11 @@ void RawImpl::finish()
smx_simcall_t simcall = simcalls_.front();
simcalls_.pop_front();
if (state_ == SIMIX_FAILED) {
if (state_ == State::FAILED) {
XBT_DEBUG("RawImpl::finish(): host '%s' failed", simcall->issuer_->get_host()->get_cname());
simcall->issuer_->context_->iwannadie = true;
simcall->issuer_->exception_ = std::make_exception_ptr(HostFailureException(XBT_THROW_POINT, "Host failed"));
} else if (state_ != SIMIX_SRC_TIMEOUT) {
} else if (state_ != State::SRC_TIMEOUT) {
xbt_die("Internal error in RawImpl::finish() unexpected synchro state %d", static_cast<int>(state_));
}
......
......@@ -196,7 +196,7 @@ void ActorImpl::exit()
/* destroy the blocking synchro if any */
if (waiting_synchro != nullptr) {
waiting_synchro->cancel();
waiting_synchro->state_ = SIMIX_FAILED;
waiting_synchro->state_ = activity::State::FAILED;
activity::ExecImplPtr exec = boost::dynamic_pointer_cast<activity::ExecImpl>(waiting_synchro);
activity::CommImplPtr comm = boost::dynamic_pointer_cast<activity::CommImpl>(waiting_synchro);
......
......@@ -130,15 +130,14 @@ void HostLoad::update()
auto current_iter = iter;
++iter;
if (action != nullptr && action->get_finish_time() != now && activity->state_ == e_smx_state_t::SIMIX_RUNNING) {
if (action != nullptr && action->get_finish_time() != now && activity->state_ == kernel::activity::State::RUNNING) {
if (remaining_cost_after_last_update == activity_uninitialized_remaining_cost) {
remaining_cost_after_last_update = action->get_cost();
}
double computed_flops_since_last_update = remaining_cost_after_last_update - /*remaining now*/activity->get_remaining();
computed_flops_ += computed_flops_since_last_update;
remaining_cost_after_last_update = activity->get_remaining();
}
else if (activity->state_ == e_smx_state_t::SIMIX_DONE) {
} else if (activity->state_ == kernel::activity::State::DONE) {
computed_flops_ += remaining_cost_after_last_update;
current_activities.erase(current_iter);
}
......
......@@ -20,10 +20,11 @@ xbt::signal<void(Actor const&)> Comm::on_completion;
Comm::~Comm()
{
if (state_ == State::STARTED && not detached_ && (pimpl_ == nullptr || pimpl_->state_ == SIMIX_RUNNING)) {
if (state_ == State::STARTED && not detached_ &&
(pimpl_ == nullptr || pimpl_->state_ == kernel::activity::State::RUNNING)) {
XBT_INFO("Comm %p freed before its completion. Detached: %d, State: %d", this, detached_, (int)state_);
if (pimpl_ != nullptr)
XBT_INFO("pimpl_->state: %d", pimpl_->state_);
XBT_INFO("pimpl_->state: %d", static_cast<int>(pimpl_->state_));
else
XBT_INFO("pimpl_ is null");
xbt_backtrace_display_current();
......
......@@ -48,10 +48,10 @@ bool Mailbox::ready()
{
bool comm_ready = false;
if (not pimpl_->comm_queue_.empty()) {
comm_ready = pimpl_->comm_queue_.front()->state_ == SIMIX_DONE;
comm_ready = pimpl_->comm_queue_.front()->state_ == kernel::activity::State::DONE;
} else if (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty()) {
comm_ready = pimpl_->done_comm_queue_.front()->state_ == SIMIX_DONE;
comm_ready = pimpl_->done_comm_queue_.front()->state_ == kernel::activity::State::DONE;
}
return comm_ready;
}
......
......@@ -57,7 +57,7 @@ void simcall_process_suspend(smx_actor_t process) // XBT_DEPRECATED_v328
e_smx_state_t simcall_process_sleep(double duration) // XBT_DEPRECATED_v329
{
SIMIX_process_self()->sleep(duration);
return SIMIX_DONE;
return simgrid::kernel::activity::State::DONE;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment